Vue Storefront is now Alokai! Learn More
SetCustomerEmail

SetCustomerEmail

Implements SetCustomerEmail Unified Method.

Source

import "./extended";
import { z } from "zod";

import { defineApi, getNormalizedCart } from "@vsf-enterprise/unified-api-sfcc";

// SFCC does not validate the email, so for the consistency with other integrations, we do it ourselves
const argsSchema = z.object({
  email: z.email("Email does not match the RFC 5322 specification."),
});

export const setCustomerEmail = defineApi.setCustomerEmail(async (context, args) => {
  argsSchema.parse(args);

  const { api } = await context.getApiClient();
  const { email } = args;

  const cart = await api.setBasketCustomerInfo({
    email,
  });

  return await getNormalizedCart(context, cart);
});