barsa b206de8dba refactor: enterprise-grade cleanup of BFF and domain packages
Comprehensive refactoring across 70 files (net -298 lines) improving
type safety, error handling, and code organization:

- Replace .passthrough()/.catchall(z.unknown()) with .strip() in all Zod schemas
- Tighten Record<string, unknown> to bounded union types where possible
- Replace throw new Error with domain-specific exceptions (OrderException,
  FulfillmentException, WhmcsOperationException, SalesforceOperationException, etc.)
- Split AuthTokenService (625 lines) into TokenGeneratorService and
  TokenRefreshService with thin orchestrator
- Deduplicate FreebitClientService with shared makeRequest() method
- Add typed interfaces to WHMCS facade, order service, and fulfillment mapper
- Externalize hardcoded config values to ConfigService with env fallbacks
- Consolidate duplicate billing cycle enums into shared billingCycleSchema
- Standardize logger usage (nestjs-pino @Inject(Logger) everywhere)
- Move shared WHMCS number coercion helpers to whmcs-utils/schema.ts
2026-02-24 19:05:30 +09:00

78 lines
2.3 KiB
TypeScript

/**
* Payments Domain - Schemas
*/
import { z } from "zod";
export const paymentMethodTypeSchema = z.enum([
"CreditCard",
"BankAccount",
"RemoteCreditCard",
"RemoteBankAccount",
"Manual",
]);
export const paymentMethodSchema = z.object({
id: z.number().int(),
type: paymentMethodTypeSchema,
description: z.string(),
gatewayName: z.string().optional(),
contactType: z.string().optional(),
contactId: z.number().int().optional(),
cardLastFour: z.string().optional(),
expiryDate: z.string().optional(),
startDate: z.string().optional(),
issueNumber: z.string().optional(),
cardType: z.string().optional(),
remoteToken: z.string().optional(),
lastUpdated: z.string().optional(),
bankName: z.string().optional(),
isDefault: z.boolean().optional(),
});
export const paymentMethodListSchema = z.object({
paymentMethods: z.array(paymentMethodSchema),
totalCount: z.number().int().min(0),
});
export const paymentGatewayTypeSchema = z.enum([
"merchant",
"thirdparty",
"tokenization",
"manual",
]);
export const paymentGatewaySchema = z.object({
name: z.string(),
displayName: z.string(),
type: paymentGatewayTypeSchema,
isActive: z.boolean(),
// Gateway configuration varies by provider; values are primitive scalars
configuration: z
.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()]))
.optional(),
});
export const paymentGatewayListSchema = z.object({
gateways: z.array(paymentGatewaySchema),
totalCount: z.number().int().min(0),
});
export const invoicePaymentLinkSchema = z.object({
url: z.string().url(),
expiresAt: z.string(),
gatewayName: z.string().optional(),
});
// ============================================================================
// Inferred Types from Schemas (Schema-First Approach)
// ============================================================================
export type PaymentMethodType = z.infer<typeof paymentMethodTypeSchema>;
export type PaymentMethod = z.infer<typeof paymentMethodSchema>;
export type PaymentMethodList = z.infer<typeof paymentMethodListSchema>;
export type PaymentGatewayType = z.infer<typeof paymentGatewayTypeSchema>;
export type PaymentGateway = z.infer<typeof paymentGatewaySchema>;
export type PaymentGatewayList = z.infer<typeof paymentGatewayListSchema>;
export type InvoicePaymentLink = z.infer<typeof invoicePaymentLinkSchema>;