Vue Storefront is now Alokai! Learn More
UpdateCustomerAddress

UpdateCustomerAddress

Implements UpdateCustomerAddress Unified Method.

Source

import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sfcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sfcc/udl";
import { KnownKeys } from "@vsf-enterprise/unified-api-sfcc";
import { CustomerUpdateAddressParams } from "@vsf-enterprise/sfcc-types";


declare module "@vsf-enterprise/unified-api-sfcc" {
  interface UpdateCustomerAddressExtendedArgs {
    /**
     * The additional address object fields to be updated for a customer.
     * {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/customers?meta=updateAddressForCustomerInCustomerList SFCC method reference}
     */
    address?: Omit<
      KnownKeys<CustomerUpdateAddressParams>,
      | "title"
      | "firstName"
      | "lastName"
      | "postalCode"
      | "countryCode"
      | "city"
      | "address1"
      | "address2"
      | "phone"
      | "stateCode"
      | "addressId"
    >;
  }
}


export const updateCustomerAddress = defineApi.updateCustomerAddress(async (context, args) => {
  await assertAuthorized(context);
  const { address, id } = args;
  const { unnormalizeAddress, normalizeCustomerAddress } = getNormalizers(context);

  const updatedAddress = await context.api.updateAddress({
    addressId: id,
    ...unnormalizeAddress(address),
  });

  return {
    address: normalizeCustomerAddress(updatedAddress),
  };
});