Vue Storefront is now Alokai! Learn More
CreateCustomerAddress

CreateCustomerAddress

Implements CreateCustomerAddress Unified Method.

Source

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

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

  const response = await context.api.createCustomerAddress(unnormalizeAddress(address));

  const createdAddress = response.data.at(0);

  if (!createdAddress) {
    throw new Error("Address not created");
  }

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