Vue Storefront is now Alokai! Learn More
CreateCustomerAddress

CreateCustomerAddress

Implements CreateCustomerAddress Unified Method.

Source

import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vue-storefront/unified-data-model";
import "./extended.d";
import type { Address, RequiredAddressProps } from "@vsf-enterprise/sapcc-types";

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

  const createdAddress = await context.api.createAddress({
    address: unnormalizeAddress(address) as Address & RequiredAddressProps,
  });

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