SetCustomerEmail
Implements SetCustomerEmail
Unified Method.
Source
import { getCartId, defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sapcc/udl";
declare module "@vsf-enterprise/unified-api-sapcc" {
interface SetCustomerEmailExtendedArgs {
/**
* Response configuration. List of fields returned in the response body.
*/
fields?: "BASIC" | "DEFAULT" | "FULL" | string | string[];
}
}
export const setCustomerEmail = defineApi.setCustomerEmail(async (context, args) => {
const cartId = getCartId(context);
const { email } = args;
const { normalizeCart } = getNormalizers(context);
if (!cartId) {
throw new Error("No cartId found");
}
try {
await context.api.replaceCartGuestUser({ cartId, email });
const { data: cart } = await context.api.getCart({ cartId });
return normalizeCart(cart);
} catch {
throw new Error("Error setting customer email");
}
});