/** * Circuit breaker pattern for resilient HTTP requests. * * States: closed (normal) -> open (failing) -> half-open (testing) -> closed */ type CircuitBreakerState = 'closed' | 'open' | 'half-open'; interface CircuitBreakerConfig { /** Number of consecutive failures before opening the circuit (default: 5) */ failureThreshold?: number; /** Time in ms to wait before transitioning from open to half-open (default: 30000) */ resetTimeout?: number; /** Number of successes in half-open state before closing (default: 1) */ successThreshold?: number; } interface CircuitBreakerStatus { state: CircuitBreakerState; failures: number; successes: number; lastFailureTime: number | null; nextRetryTime: number | null; } declare class CircuitBreaker { private state; private failures; private successes; private lastFailureTime; private readonly failureThreshold; private readonly resetTimeout; private readonly successThreshold; constructor(config?: CircuitBreakerConfig); /** * Check if a request can proceed through the circuit breaker. */ canExecute(): boolean; /** * Record a successful request. */ onSuccess(): void; /** * Record a failed request. */ onFailure(): void; /** * Get current circuit breaker status. */ getStatus(): CircuitBreakerStatus; /** * Reset the circuit breaker to its initial closed state. */ reset(): void; } /** * Configuration types for Vesant SDK clients */ interface Logger { debug(message: string, meta?: Record): void; info(message: string, meta?: Record): void; warn(message: string, meta?: Record): void; error(message: string, meta?: Record): void; } interface RequestOptions { signal?: AbortSignal; /** Idempotency key for POST/PUT/PATCH requests */ idempotencyKey?: string; /** Response type — defaults to 'json'. Use 'arraybuffer' for binary downloads (PDF, etc.) */ responseType?: 'json' | 'arraybuffer'; } interface RequestInterceptor { /** Called before each request. Can modify headers or options. */ onRequest?: (url: string, options: RequestInit) => RequestInit | Promise; /** Called after a successful response. Can inspect or transform data. */ onResponse?: (url: string, data: unknown) => unknown | Promise; /** Called when a request fails. Can handle or re-throw. */ onError?: (url: string, error: Error) => void | Promise; } interface BaseClientConfig { /** Base URL for the service */ baseURL: string; /** Tenant ID for multi-tenancy */ tenantId: string; /** Optional API key for authentication */ apiKey?: string; /** Custom headers to include in all requests */ headers?: Record; /** Request timeout in milliseconds (default: 10000) */ timeout?: number; /** Number of retry attempts (default: 3) */ retries?: number; /** Enable debug logging (default: false) */ debug?: boolean; /** Request/response interceptors */ interceptors?: RequestInterceptor[]; /** Custom logger instance */ logger?: Logger; /** Environment mode (default: 'production'). When 'sandbox', adds X-Sandbox header to all requests for data isolation. */ environment?: 'production' | 'sandbox'; /** Circuit breaker configuration */ circuitBreaker?: CircuitBreakerConfig; /** Enable rate limit header tracking (default: false) */ enableRateLimitTracking?: boolean; } interface VesantConfig { /** Base URL for the Vesant API */ baseURL: string; /** Tenant ID for multi-tenancy */ tenantId: string; /** Optional API key for authentication */ apiKey?: string; /** Custom headers to include in all requests */ headers?: Record; /** Request timeout in milliseconds (default: 10000) */ timeout?: number; /** Number of retry attempts for failed requests (default: 3) */ retries?: number; /** Enable debug logging (default: false) */ debug?: boolean; /** Automatically create customer profiles on geolocation verification (default: true) */ autoCreateProfiles?: boolean; /** Sync mode: 'async' uses events, 'sync' uses direct API calls (default: 'sync') */ syncMode?: 'async' | 'sync'; /** Request/response interceptors */ interceptors?: RequestInterceptor[]; /** Custom logger instance */ logger?: Logger; /** Environment mode (default: 'production'). When 'sandbox', adds X-Sandbox header to all requests for data isolation. */ environment?: 'production' | 'sandbox'; /** Circuit breaker configuration */ circuitBreaker?: CircuitBreakerConfig; /** Enable rate limit header tracking (default: false) */ enableRateLimitTracking?: boolean; } /** VesantConfig with core fields required, enterprise features remain optional */ type RequiredVesantConfig = Required> & Pick; /** @deprecated Use VesantConfig instead */ type CGSConfig = VesantConfig; /** @deprecated Use RequiredVesantConfig instead */ type RequiredCGSConfig = RequiredVesantConfig; /** BaseClientConfig with core fields required, enterprise features remain optional */ type RequiredBaseClientConfig = Required> & Pick; /** * Rate limit tracking from API response headers. * * Tracks X-RateLimit-* headers to enable pre-flight checks * before making requests. */ interface RateLimitStatus { /** Maximum requests allowed in the window */ limit: number | null; /** Remaining requests in the current window */ remaining: number | null; /** Unix timestamp (seconds) when the rate limit resets */ reset: number | null; /** Seconds until the rate limit resets */ retryAfter: number | null; } declare class RateLimitTracker { private limit; private remaining; private reset; private retryAfter; /** * Extract rate limit information from response headers. */ updateFromHeaders(headers: Headers): void; /** * Check if the rate limit has been exceeded based on tracked headers. */ isLimitExceeded(): boolean; /** * Get current rate limit status. */ getStatus(): RateLimitStatus; } /** * Base HTTP client for all Vesant SDK clients * * Provides common functionality: * - Request/response handling * - Error handling * - Retry logic with exponential backoff * - Timeout management * - Debug logging */ declare abstract class BaseClient { protected config: BaseClientConfig & { timeout: number; retries: number; }; protected logger: Logger; private interceptors; private circuitBreaker; private rateLimitTracker; constructor(config: BaseClientConfig); /** * Make an HTTP request with timeout and error handling */ protected request(endpoint: string, options?: RequestInit, serviceURL?: string, requestOptions?: RequestOptions): Promise; /** * Make an HTTP request with retry logic */ protected requestWithRetry(endpoint: string, options?: RequestInit, serviceURL?: string, retries?: number, requestOptions?: RequestOptions): Promise; /** * Handle error responses from API */ protected handleErrorResponse(status: number, data: Record, requestId?: string): never; /** * Build query string from parameters */ protected buildQueryString(params: Record): string; /** * Update client configuration */ updateConfig(config: Partial): void; /** * Get current configuration (readonly) */ getConfig(): Readonly; /** * Get rate limit status from tracked response headers. */ getRateLimitStatus(): RateLimitStatus | null; /** * Get circuit breaker status. */ getCircuitBreakerStatus(): CircuitBreakerStatus | null; /** * Health check endpoint */ healthCheck(): Promise<{ status: string; timestamp: string; }>; } export { BaseClient as B, type CircuitBreakerConfig as C, type Logger as L, type RequestOptions as R, type VesantConfig as V, type BaseClientConfig as a, type RequestInterceptor as b, type RequiredVesantConfig as c, type CGSConfig as d, type RequiredCGSConfig as e, type RequiredBaseClientConfig as f, type CircuitBreakerState as g, type CircuitBreakerStatus as h, CircuitBreaker as i, type RateLimitStatus as j, RateLimitTracker as k };