import { ApiClientConfig, ApiError, ApiResponse, ErrorCategory, ErrorInterceptor, ErrorSeverity, RequestConfig, RequestInterceptor, ResponseInterceptor, RetryConfig, TokenProvider } from './types'; import { RATE_LIMIT_PRESETS, RateLimitConfig, RateLimiter, RateLimitError } from './advanced/rate-limiter'; /** * Map HTTP status codes to error categories */ declare function getErrorCategory(status: number): ErrorCategory; /** * Map error categories to severity levels */ declare function getErrorSeverity(category: ErrorCategory): ErrorSeverity; /** * Check if an error is retryable */ declare function isRetryable(status: number, retryConfig: RetryConfig): boolean; /** * Create a normalized API error from various error sources */ declare function createApiError(status: number, message: string, options?: { code?: string; response?: unknown; request?: RequestConfig; requestId?: string; correlationId?: string; cause?: Error; fieldErrors?: Array<{ field: string; message: string; }>; }): ApiError; /** * Enterprise API Client with comprehensive features */ export declare class ApiClient { private config; private readonly requestInterceptors; private readonly responseInterceptors; private readonly errorInterceptors; private tokenRefreshFn; private tokenProvider; private abortControllers; /** * Rate limiter instance for client-side rate limiting. * Null if rate limiting is disabled. */ private rateLimiter; constructor(config: ApiClientConfig); /** * Perform a GET request */ get(url: string, options?: Omit): Promise>; /** * Perform a POST request */ post(url: string, body?: TBody, options?: Omit): Promise>; /** * Perform a PUT request */ put(url: string, body?: TBody, options?: Omit): Promise>; /** * Perform a PATCH request */ patch(url: string, body?: TBody, options?: Omit): Promise>; /** * Perform a DELETE request */ delete(url: string, options?: Omit): Promise>; /** * Perform a HEAD request */ head(url: string, options?: Omit): Promise>; /** * Generic request method */ request(config: RequestConfig): Promise>; /** * Add a request interceptor */ addRequestInterceptor(interceptor: RequestInterceptor): () => void; /** * Add a response interceptor */ addResponseInterceptor(interceptor: ResponseInterceptor): () => void; /** * Add an error interceptor */ addErrorInterceptor(interceptor: ErrorInterceptor): () => void; /** * Set custom token refresh function */ setTokenRefresh(fn: () => Promise): void; /** * Get the current token provider */ getTokenProvider(): TokenProvider; /** * Set a new token provider * * This also updates the token refresh function to use the new provider. */ setTokenProvider(provider: TokenProvider): void; /** * Get the rate limiter instance. * Returns null if rate limiting is not enabled. */ getRateLimiter(): RateLimiter | null; /** * Enable or update rate limiting. * * @param config - Rate limit configuration or preset name * * @example * ```typescript * // Use a preset * client.setRateLimit('standard'); * * // Use custom config * client.setRateLimit({ * maxRequests: 100, * windowMs: 60000, * strategy: 'queue', * }); * ``` */ setRateLimit(config: RateLimitConfig | keyof typeof RATE_LIMIT_PRESETS): void; /** * Disable rate limiting. */ disableRateLimit(): void; /** * Check if a request would be rate limited. * * @param endpoint - Endpoint URL to check * @returns Whether the request would be limited */ wouldBeRateLimited(endpoint: string): boolean; /** * Cancel a specific request by ID */ cancelRequest(requestId: string): void; /** * Cancel all pending requests */ cancelAllRequests(): void; /** * Execute request with deduplication logic */ private executeRequestWithDedup; /** * Perform token refresh with request queuing */ private refreshToken; /** * Execute the actual HTTP request with retry logic */ private executeRequest; /** * Build the full URL with path params and query string */ private buildUrl; /** * Build query string from params object */ private buildQueryString; /** * Build request headers */ private buildHeaders; /** * Serialize request body based on content type */ private serializeBody; /** * Parse response based on content type and config */ private parseResponse; /** * Parse error response body */ private parseErrorResponse; /** * Parse response headers into a plain object */ private parseHeaders; /** * Run request interceptors in sequence */ private runRequestInterceptors; /** * Run response interceptors in sequence */ private runResponseInterceptors; /** * Run error interceptors in sequence */ private runErrorInterceptors; /** * Generate a unique request ID */ private generateRequestId; /** * Type guard for API errors */ private isApiError; /** * Promise-based delay utility */ private delay; } /** * Create a new API client instance * * @param config - Client configuration * @returns Configured ApiClient instance * * @example * ```typescript * const client = createApiClient({ * baseUrl: 'https://api.example.com', * timeout: 30000, * autoRefreshToken: true, * }); * * // Add global request logging * client.addRequestInterceptor((config) => { * console.log(`[API] ${config.method} ${config.url}`); * return config; * }); * * // Make requests * const users = await client.get('/users'); * ``` */ export declare function createApiClient(config: ApiClientConfig): ApiClient; /** * Default API client instance configured with application defaults */ export declare const apiClient: ApiClient; export { createApiError, isRetryable, getErrorCategory, getErrorSeverity }; export { RateLimiter, RateLimitError, RATE_LIMIT_PRESETS, type RateLimitConfig };