- Refactor various mappers in billing, payments, services, and subscriptions to ensure IDs are consistently converted to numbers. - Update raw types schemas to utilize whmcsNumberLike and whmcsString for improved validation and type safety. - Enhance the whmcs-utils to include schema exports for better modularity.
29 lines
989 B
TypeScript
29 lines
989 B
TypeScript
/**
|
|
* WHMCS Zod Schema Primitives (domain-internal)
|
|
*
|
|
* Coercing schema helpers for WHMCS API responses.
|
|
* WHMCS (PHP) is loosely typed — fields documented as strings may arrive
|
|
* as numbers (and vice-versa). These primitives absorb that inconsistency
|
|
* at the parsing boundary so the rest of the codebase sees clean types.
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
/**
|
|
* Coercing string — accepts string or number, always outputs string.
|
|
* Use for any WHMCS response field that should be a string.
|
|
*/
|
|
export const whmcsString = z.coerce.string();
|
|
|
|
/**
|
|
* Accepts number or string (e.g. "123"), keeps the raw union type.
|
|
* Use when downstream code handles both types (e.g. IDs you'll parse later).
|
|
*/
|
|
export const whmcsNumberLike = z.union([z.number(), z.string()]);
|
|
|
|
/**
|
|
* Accepts boolean, number (0/1), or string ("true"/"false"/etc).
|
|
* Use for WHMCS boolean flags that arrive in varying formats.
|
|
*/
|
|
export const whmcsBooleanLike = z.union([z.boolean(), z.number(), z.string()]);
|