Vue Storefront is now Alokai! Learn More
CreateCustomerAddress

CreateCustomerAddress

Implements CreateCustomerAddress Unified Method.

Source

import { getNormalizers } from "@alokai/connect/integration-kit";
import { AppError } from "@alokai/connect/middleware";

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

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

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

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

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

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