Search customer by phone (Admin tool)
Context
As described in the technical refinement for the search by phone feature, the implementation consisted of creating phone lookup when a new order is committed. These lookup records enable the search in admin app.
PhoneLookupRecord
The phoneLookupRecords created to enable the search have the following structure:
{
"pk":"phoneLookupUser#{cognitoId}",
"sk":"phoneSource#{source}#phoneNumber#{phoneNumber}",
"cognitoId":"{cognitoId}",
"phoneNumber": "{phoneNumber}",
"pk2": "phoneLookupNumber#{phoneNumber}",
"sk2": "phoneSource#{source}#phoneUser#{cognitoId}",
"source": "{source}"
}
They are structured in this manner to support two access patterns:
Get phone numbers associated to a cognito id (search using primary index)
Optionally, the local sort index can be used to retrieve only records originating from a single source (eg. order phones, user phones, verified phones)
Get cognito ids associated with a phone number (search using brand-index)
Launch Darkly
The only feature toggle associated with this feature is the enable-search-by-phone, that controls if the phoneLookupRecords will be created after the order commit or not. The feature activation in an specific market can be controlled using the country parameter.
Currently, admin app uses a universal search bar, where the support agent can type a number or a word, therefore it doesn’t need a feature toggle. If the records don’t exist, the search will return the other searches (eg. phoneNumber, storeId, credit card, …) transparently.
Phone number parsing
When creating the phoneLookupRecord, the user service parses the number value, and if it doesn’t include an international code, it automatically includedes one, using the sanitizePhoneNumber function.