// Common types used across the application // ===================================================== // BRANDED TYPES FOR TYPE SAFETY // ===================================================== // Branded types for critical identifiers export type UserId = string & { readonly __brand: 'UserId' }; export type OrderId = string & { readonly __brand: 'OrderId' }; export type InvoiceId = string & { readonly __brand: 'InvoiceId' }; export type SubscriptionId = string & { readonly __brand: 'SubscriptionId' }; export type PaymentId = string & { readonly __brand: 'PaymentId' }; export type CaseId = string & { readonly __brand: 'CaseId' }; export type SessionId = string & { readonly __brand: 'SessionId' }; // WHMCS-specific branded types export type WhmcsClientId = number & { readonly __brand: 'WhmcsClientId' }; export type WhmcsInvoiceId = number & { readonly __brand: 'WhmcsInvoiceId' }; export type WhmcsProductId = number & { readonly __brand: 'WhmcsProductId' }; // Salesforce-specific branded types export type SalesforceContactId = string & { readonly __brand: 'SalesforceContactId' }; export type SalesforceAccountId = string & { readonly __brand: 'SalesforceAccountId' }; export type SalesforceCaseId = string & { readonly __brand: 'SalesforceCaseId' }; // Helper functions for creating branded types export const createUserId = (id: string): UserId => id as UserId; export const createOrderId = (id: string): OrderId => id as OrderId; export const createInvoiceId = (id: string): InvoiceId => id as InvoiceId; export const createSubscriptionId = (id: string): SubscriptionId => id as SubscriptionId; export const createPaymentId = (id: string): PaymentId => id as PaymentId; export const createCaseId = (id: string): CaseId => id as CaseId; export const createSessionId = (id: string): SessionId => id as SessionId; export const createWhmcsClientId = (id: number): WhmcsClientId => id as WhmcsClientId; export const createWhmcsInvoiceId = (id: number): WhmcsInvoiceId => id as WhmcsInvoiceId; export const createWhmcsProductId = (id: number): WhmcsProductId => id as WhmcsProductId; export const createSalesforceContactId = (id: string): SalesforceContactId => id as SalesforceContactId; export const createSalesforceAccountId = (id: string): SalesforceAccountId => id as SalesforceAccountId; export const createSalesforceCaseId = (id: string): SalesforceCaseId => id as SalesforceCaseId; // Type guards for branded types export const isUserId = (id: string): id is UserId => typeof id === 'string'; export const isOrderId = (id: string): id is OrderId => typeof id === 'string'; export const isInvoiceId = (id: string): id is InvoiceId => typeof id === 'string'; export const isWhmcsClientId = (id: number): id is WhmcsClientId => typeof id === 'number'; // Shared ISO8601 timestamp string type used for serialized dates export type IsoDateTimeString = string; // ===================================================== // BASE ENTITY INTERFACES // ===================================================== // Base entity interfaces for different systems // Portal entities (User, etc.) export interface BaseEntity { id: string; createdAt: string; updatedAt: string; } // WHMCS entities (Invoice, Subscription, etc.) export interface WhmcsEntity { id: number; } // Salesforce entities (SupportCase, etc.) export interface SalesforceEntity { id: string; createdDate: string; lastModifiedDate: string; } export interface Paginated { items: T[]; nextCursor: string | null; totalCount?: number; } // API types moved to contracts/api.ts export interface IdempotencyKey { key: string; userId: string; createdAt: string; } export interface UserMapping { userId: string; whmcsClientId: number; sfContactId?: string; sfAccountId?: string; createdAt?: Date; updatedAt?: Date; } // Extended mapping interfaces for V2 implementation export interface UserIdMapping extends UserMapping { createdAt?: Date; updatedAt?: Date; } export interface CreateMappingRequest { userId: string; whmcsClientId: number; sfAccountId?: string; } export interface UpdateMappingRequest { whmcsClientId?: number; sfAccountId?: string; } export interface MappingStats { totalMappings: number; whmcsMappings: number; salesforceMappings: number; completeMappings: number; orphanedMappings: number; } // Shared address type used across BFF and Portal export interface Address { street: string | null; streetLine2: string | null; city: string | null; state: string | null; postalCode: string | null; country: string | null; }