Vue Storefront is now Alokai! Learn More
UpdateCustomerAddress

UpdateCustomerAddress

Implements UpdateCustomerAddress 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 updateCustomerAddress = defineApi.updateCustomerAddress(async (context, args) => {
  await assertAuthorized(context);
  const { address, id } = args;
  const { normalizeCustomerAddress, unnormalizeAddress } = getNormalizers(context);

  const body = {
    id: Number(id),
    ...unnormalizeAddress(address),
  };

  const { api } = await context.getApiClient();
  const { data } = await api.updateCustomerAddress(body);
  const updatedAddress = data.at(0);

  if (!updatedAddress) {
    throw new AppError("Address not updated");
  }

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