2025-12-17 14:07:22 +09:00
|
|
|
/**
|
|
|
|
|
* Checkout Domain - Schemas
|
|
|
|
|
*
|
2025-12-23 13:21:29 +09:00
|
|
|
* Zod validation schemas for checkout flow.
|
|
|
|
|
* Supports authenticated checkout.
|
2025-12-17 14:07:22 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { z } from "zod";
|
2026-01-13 14:25:14 +09:00
|
|
|
import { CHECKOUT_ORDER_TYPE } from "./contract.js";
|
2025-12-17 14:07:22 +09:00
|
|
|
|
|
|
|
|
// ============================================================================
|
2025-12-23 13:21:29 +09:00
|
|
|
// Order Type Schema
|
2025-12-17 14:07:22 +09:00
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-01-13 14:25:14 +09:00
|
|
|
const CHECKOUT_ORDER_TYPE_VALUES = Object.values(CHECKOUT_ORDER_TYPE) as [string, ...string[]];
|
|
|
|
|
|
2025-12-23 13:21:29 +09:00
|
|
|
/**
|
|
|
|
|
* Checkout order types - uses PascalCase to match Salesforce/BFF contracts
|
|
|
|
|
* @see packages/domain/orders/contract.ts ORDER_TYPE for canonical values
|
|
|
|
|
*/
|
2026-01-13 14:25:14 +09:00
|
|
|
export const checkoutOrderTypeSchema = z.enum(CHECKOUT_ORDER_TYPE_VALUES);
|
2025-12-17 14:07:22 +09:00
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Price Breakdown Schema
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export const priceBreakdownItemSchema = z.object({
|
|
|
|
|
label: z.string(),
|
|
|
|
|
sku: z.string().optional(),
|
|
|
|
|
monthlyPrice: z.number().optional(),
|
|
|
|
|
oneTimePrice: z.number().optional(),
|
|
|
|
|
quantity: z.number().optional().default(1),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Cart Item Schema
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export const cartItemSchema = z.object({
|
2025-12-29 15:07:11 +09:00
|
|
|
orderType: checkoutOrderTypeSchema,
|
2025-12-17 14:07:22 +09:00
|
|
|
planSku: z.string().min(1, "Plan SKU is required"),
|
|
|
|
|
planName: z.string().min(1, "Plan name is required"),
|
|
|
|
|
addonSkus: z.array(z.string()).default([]),
|
2026-02-24 19:05:30 +09:00
|
|
|
// Checkout configuration values are user-supplied key-value pairs (strings, numbers, booleans)
|
|
|
|
|
configuration: z
|
|
|
|
|
.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
|
|
|
.default({}),
|
2025-12-17 14:07:22 +09:00
|
|
|
pricing: z.object({
|
|
|
|
|
monthlyTotal: z.number().nonnegative(),
|
|
|
|
|
oneTimeTotal: z.number().nonnegative(),
|
|
|
|
|
breakdown: z.array(priceBreakdownItemSchema).default([]),
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Inferred Types
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2025-12-29 15:07:11 +09:00
|
|
|
export type OrderType = z.infer<typeof checkoutOrderTypeSchema>;
|
2025-12-17 14:07:22 +09:00
|
|
|
export type PriceBreakdownItem = z.infer<typeof priceBreakdownItemSchema>;
|
|
|
|
|
export type CartItem = z.infer<typeof cartItemSchema>;
|