barsa 03eccd1db2 Enhance Error Handling and Logging Consistency Across Services
- Replaced instances of `getErrorMessage` with `extractErrorMessage` in various services to ensure consistent error handling and improve clarity in logging.
- Updated error logging in the Whmcs, Salesforce, and subscription services to utilize the new error extraction method, enhancing maintainability and debugging capabilities.
- Adjusted ESLint configuration to prevent the use of `console.log` in production code, promoting the use of a centralized logging solution.
- Refactored error handling in the Agentforce widget and other components to align with the updated logging practices, ensuring a consistent approach to error management across the application.
- Cleaned up unused imports and optimized code structure for better maintainability.
2025-12-29 15:07:11 +09:00

80 lines
2.6 KiB
TypeScript

/**
* Checkout Domain - Schemas
*
* Zod validation schemas for checkout flow.
* Supports authenticated checkout.
*/
import { z } from "zod";
// ============================================================================
// Order Type Schema
// ============================================================================
/**
* Checkout order types - uses PascalCase to match Salesforce/BFF contracts
* @see packages/domain/orders/contract.ts ORDER_TYPE for canonical values
*/
export const checkoutOrderTypeSchema = z.enum(["Internet", "SIM", "VPN"]);
// ============================================================================
// Order Type Helpers
// ============================================================================
/**
* Convert legacy uppercase order type to PascalCase
* Used for migrating old localStorage data
*/
export function normalizeOrderType(value: unknown): z.infer<typeof checkoutOrderTypeSchema> | null {
if (typeof value !== "string") return null;
const upper = value.trim().toUpperCase();
switch (upper) {
case "INTERNET":
return "Internet";
case "SIM":
return "SIM";
case "VPN":
return "VPN";
default:
return null;
}
}
// ============================================================================
// 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({
orderType: checkoutOrderTypeSchema,
planSku: z.string().min(1, "Plan SKU is required"),
planName: z.string().min(1, "Plan name is required"),
addonSkus: z.array(z.string()).default([]),
configuration: z.record(z.string(), z.unknown()).default({}),
pricing: z.object({
monthlyTotal: z.number().nonnegative(),
oneTimeTotal: z.number().nonnegative(),
breakdown: z.array(priceBreakdownItemSchema).default([]),
}),
});
// ============================================================================
// Inferred Types
// ============================================================================
export type OrderType = z.infer<typeof checkoutOrderTypeSchema>;
export type PriceBreakdownItem = z.infer<typeof priceBreakdownItemSchema>;
export type CartItem = z.infer<typeof cartItemSchema>;