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
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
/**
|
|
* Common Salesforce Provider Types
|
|
*
|
|
* Generic Salesforce API response structures used across multiple domains.
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
// ============================================================================
|
|
// Salesforce Query Response (Generic SOQL Response)
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Base schema for Salesforce SOQL query result
|
|
*/
|
|
// Base schema uses z.unknown() for records because it is always overridden by
|
|
// salesforceResponseSchema() which extends records with the caller's typed schema.
|
|
const salesforceResponseBaseSchema = z.object({
|
|
totalSize: z.number(),
|
|
done: z.boolean(),
|
|
records: z.array(z.unknown()),
|
|
});
|
|
|
|
type SalesforceResponseBase = z.infer<typeof salesforceResponseBaseSchema>;
|
|
|
|
/**
|
|
* Generic type for Salesforce query results derived from schema
|
|
* All SOQL queries return this structure regardless of SObject type
|
|
*
|
|
* Usage: SalesforceResponse<SalesforceOrderRecord>
|
|
*/
|
|
export type SalesforceResponse<TRecord> = Omit<SalesforceResponseBase, "records"> & {
|
|
records: TRecord[];
|
|
};
|
|
|
|
/**
|
|
* Schema factory for validating Salesforce query responses
|
|
* Usage: salesforceResponseSchema(salesforceOrderRecordSchema)
|
|
*/
|
|
export const salesforceResponseSchema = <TRecord extends z.ZodTypeAny>(recordSchema: TRecord) =>
|
|
salesforceResponseBaseSchema.extend({
|
|
records: z.array(recordSchema),
|
|
});
|