Customer normalizer
The normalizeCustomer
function is used to map a SFCC Customer
into the unified SfCustomer
data model.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
context | NormalizerContext | Context needed for the normalizer. | |
user | Customer | SFCC Customer |
Extending
The SfCustomer
model is returned from Unified Methods such as RegisterCustomer
, LoginCustomer
and GetCustomer
. If the SfCustomer
structure doesn't contain the information you need for your Storefront, you can extend its logic using the addCustomFields
API. The following example demonstrates how to extend SfCustomer
with a job_title
field.
export const unifiedApiExtension = createUnifiedExtension({
normalizers: {
addCustomFields: [
{
normalizeCustomer: (context, user) => ({
job_title: user.jobTitle,
}),
},
],
},
config: {
...
},
});
Source
SFCC Customer
have some fields optional on the interface, but in the reality a valid Customer
should contain a customerId
, email
, firstName
, and lastName
, so if any of these information is missing, normalizer returns an error.
customer.ts
import { defineNormalizer } from "../defineNormalizer";
export const normalizeCustomer = defineNormalizer.normalizeCustomer((_context, customer) => {
if (!customer.customerId || !customer.firstName || !customer.lastName || !customer.email) {
throw new Error("Customer must have an id, firstName, lastName and email");
}
return {
id: customer.customerId,
firstName: customer.firstName,
lastName: customer.lastName,
email: customer.email,
};
});