CreateCustomerAddress
Implements CreateCustomerAddress
Unified Method.
Source
import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sfcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sfcc/udl";
import { randomUUID } from "node:crypto";
import { KnownKeys } from "@vsf-enterprise/unified-api-sfcc";
import { CustomerCreateAddressParams } from "@vsf-enterprise/sfcc-types";
declare module "@vsf-enterprise/unified-api-sfcc" {
interface CreateCustomerAddressExtendedArgs {
/**
* The additional address object fields to be created for a customer.
* {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/customers?meta=createAddressForCustomerInCustomerList SFCC method reference}
*/
address: Omit<
KnownKeys<CustomerCreateAddressParams>,
| "title"
| "firstName"
| "lastName"
| "postalCode"
| "countryCode"
| "city"
| "address1"
| "address2"
| "phone"
| "stateCode"
| "addressId"
>;
}
}
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),
};
});