Vue Storefront is now Alokai! Learn More
Customer normalizer

Customer normalizer

The normalizeCustomer function is used to map a BigCommerce Customer into the unified SfCustomer data model.

Parametersri:link

NameTypeDefault valueDescription
customerCustomerBigCommerce Customer

Extendingri:link

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 defineNormalizers function. The following example demonstrates how to extend SfCustomer with a company field.

import { normalizers as normalizersBC, defineNormalizers } from "@vsf-enterprise/unified-api-bigcommerce";

const normalizers = defineNormalizers<typeof normalizersBC>()({
  ...normalizersBC,
  normalizeCustomer: (customer) => ({
    ...normalizersBC.normalizeCustomer(customer),
    company: customer.company,
  }),
});

Sourceri:link

customer.ts
import { defineNormalizer } from "../defineNormalizer";

export const normalizeCustomer = defineNormalizer.normalizeCustomer((user) => {
  if (!user.id) {
    throw new Error("User id is required");
  }

  return {
    id: user.id.toString(),
    firstName: user.first_name,
    lastName: user.last_name,
    email: user.email,
  };
});