/** * API Request/Response Types * CRESyncFlow - Commercial Real Estate CRM * * Generic types for API communication */ // ============================================================================= // Generic API Response Types // ============================================================================= export interface APIResponse { success: boolean; data?: T; error?: string; message?: string; statusCode?: number; } export interface APIErrorResponse { success: false; error: string; message?: string; statusCode: number; details?: Record; } export interface APISuccessResponse { success: true; data: T; message?: string; } // ============================================================================= // Pagination Types // ============================================================================= export interface PaginationParams { page?: number; limit?: number; search?: string; sortBy?: string; sortOrder?: 'asc' | 'desc'; } export interface PaginatedResponse { items: T[]; total: number; page: number; limit: number; totalPages: number; hasNextPage: boolean; hasPrevPage: boolean; } export interface CursorPaginationParams { cursor?: string; limit?: number; direction?: 'forward' | 'backward'; } export interface CursorPaginatedResponse { items: T[]; nextCursor?: string; prevCursor?: string; hasMore: boolean; } // ============================================================================= // Filter and Search Types // ============================================================================= export type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin' | 'contains' | 'startsWith' | 'endsWith'; export interface FilterCondition { field: string; operator: FilterOperator; value: any; } export interface SearchParams extends PaginationParams { filters?: FilterCondition[]; dateFrom?: string; dateTo?: string; } // ============================================================================= // Batch Operation Types // ============================================================================= export interface BatchOperationResult { successful: T[]; failed: Array<{ item: any; error: string; }>; totalProcessed: number; totalSuccessful: number; totalFailed: number; } export interface BulkDeleteRequest { ids: string[]; } export interface BulkUpdateRequest { ids: string[]; updates: Partial; } // ============================================================================= // File Upload Types // ============================================================================= export interface FileUploadResponse { url: string; filename: string; size: number; mimeType: string; uploadedAt: string; } export interface FileUploadProgress { loaded: number; total: number; percentage: number; } // ============================================================================= // Webhook Types // ============================================================================= export interface WebhookPayload { event: string; timestamp: string; data: T; signature?: string; } export interface WebhookRegistration { id: string; url: string; events: string[]; secret: string; isActive: boolean; createdAt: string; } // ============================================================================= // Rate Limiting Types // ============================================================================= export interface RateLimitInfo { limit: number; remaining: number; reset: number; retryAfter?: number; } // ============================================================================= // Health Check Types // ============================================================================= export interface HealthCheckResponse { status: 'healthy' | 'degraded' | 'unhealthy'; timestamp: string; version: string; services: { database: ServiceStatus; ghl: ServiceStatus; redis?: ServiceStatus; stripe?: ServiceStatus; }; } export interface ServiceStatus { status: 'up' | 'down' | 'degraded'; latency?: number; message?: string; }