Vue Storefront is now Alokai! Learn More
GetCustomerAddresses

GetCustomerAddresses

Implements GetCustomerAddresses Unified Method.

Source

import { assertAuthorized, defineApi, query } from "@vsf-enterprise/unified-api-magento";
import type { CustomerAddressInput } from "@vue-storefront/magento-types";
import { getNormalizers } from "@vue-storefront/unified-data-model";

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

  const addresses = await query(context.api.getCustomerAddresses());

  const { normalizeCustomerAddress } = getNormalizers(context);

  return {
    addresses:
      addresses.customer?.addresses
        ?.filter(Boolean)
        .map((address) => normalizeCustomerAddress(address as CustomerAddressInput)) || [],
  };
});