Vue Storefront is now Alokai! Learn More
CreateCustomerAddress

CreateCustomerAddress

Implements CreateCustomerAddress Unified Method.

Source

import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sfcc";
import { getNormalizers } from "@vue-storefront/unified-data-model";
import { randomUUID } from "node:crypto";
import "./extended.d";

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

  const createdAddress = await context.api.createAddress({
    ...unnormalizeAddress(address),
    addressId: randomUUID(),
    ...rest,
  });

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