Vue Storefront is now Alokai! Learn More
GetCustomerAddresses

GetCustomerAddresses

Implements GetCustomerAddresses Unified Method.

Source

import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sapcc/udl";


declare module "@vsf-enterprise/unified-api-sapcc" {
  interface GetCustomerAddressesExtendedArgs {
    /**
     * Response configuration. List of fields returned in the response body.
     */
    fields?: "BASIC" | "DEFAULT" | "FULL" | string | string[];
  }
}


export const getCustomerAddresses = defineApi.getCustomerAddresses(async (context) => {
  assertAuthorized(context);

  const { normalizeCustomerAddress } = getNormalizers(context);
  const { data } = await context.api.getAddresses({});
  const addresses = data.addresses || [];
  return {
    addresses: addresses.map((address) => normalizeCustomerAddress(address)),
  };
});