/** * @file HTTP Client (Legacy) * @description Centralized HTTP client with interceptors and error handling * * @deprecated This module is deprecated in favor of the more feature-rich API client * from `@/lib/api`. The `@/lib/api` module provides: * - Automatic retry with exponential backoff * - Request deduplication * - Token refresh with request queuing * - Configurable token provider * - Request/response interceptor chains * - Comprehensive error normalization * * Migration guide: * ```typescript * // Before (deprecated) * import { httpClient } from '@/lib/services'; * const response = await httpClient.get('/users'); * * // After (recommended) * import { apiClient } from '@/lib/api'; * const response = await apiClient.get('/users'); * ``` * * @see {@link @/lib/api} for the recommended API client */ /** * HTTP request configuration */ export interface HttpRequestConfig { /** Request URL */ url: string; /** HTTP method */ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** Request headers */ headers?: Record; /** Query parameters */ params?: Record; /** Request body */ body?: unknown; /** Request timeout (ms) */ timeout?: number; /** Abort signal */ signal?: AbortSignal; /** Skip authentication */ skipAuth?: boolean; /** Skip error handling */ skipErrorHandling?: boolean; /** Response type */ responseType?: 'json' | 'text' | 'blob' | 'arrayBuffer'; /** Custom metadata */ meta?: Record; } /** * HTTP response wrapper */ export interface HttpResponse { /** Response data */ data: T; /** HTTP status code */ status: number; /** Status text */ statusText: string; /** Response headers */ headers: Headers; /** Original request config */ config: HttpRequestConfig; } /** * Error category types (compatible with ApiError from @/lib/api) */ export type HttpErrorCategory = 'network' | 'authentication' | 'authorization' | 'validation' | 'not_found' | 'conflict' | 'rate_limit' | 'server' | 'timeout' | 'cancelled' | 'unknown'; /** * Error severity levels (compatible with ApiError from @/lib/api) */ export type HttpErrorSeverity = 'critical' | 'error' | 'warning' | 'info'; /** * HTTP error * * @deprecated Use error handling from `@/lib/api` instead. * The `ApiError` type from `@/lib/api/types` provides more detailed * error information including category, severity, and field-level errors. * * This class implements partial compatibility with `ApiError` for migration purposes. * The following properties are compatible with `ApiError`: * - `status` - HTTP status code * - `code` - Error code (e.g., 'HTTP_404') * - `category` - Error category for classification * - `severity` - Error severity level * - `response` - Response data (alias for `data`) * - `timestamp` - Error creation timestamp * - `retryable` - Whether the error is retryable * * @see {@link ApiError} from `@/lib/api/types` for the recommended error type */ export declare class HttpError extends Error { readonly status: number; readonly statusText: string; readonly data: unknown; readonly config: HttpRequestConfig; readonly isHttpError = true; /** Error code compatible with ApiError */ readonly code: string; /** Error category compatible with ApiError */ readonly category: HttpErrorCategory; /** Error severity compatible with ApiError */ readonly severity: HttpErrorSeverity; /** Response data alias (compatible with ApiError.response) */ readonly response: unknown; /** Error creation timestamp (compatible with ApiError.timestamp) */ readonly timestamp: number; /** Whether error is retryable (compatible with ApiError.retryable) */ readonly retryable: boolean; constructor(message: string, status: number, statusText: string, data: unknown, config: HttpRequestConfig); /** * Convert to a plain object compatible with ApiError structure * * @returns Object with properties matching ApiError interface */ toApiError(): { name: string; status: number; code: string; message: string; category: HttpErrorCategory; severity: HttpErrorSeverity; response: unknown; timestamp: number; retryable: boolean; }; } /** * Request interceptor */ export type RequestInterceptor = (config: HttpRequestConfig) => HttpRequestConfig | Promise; /** * Response interceptor */ export type ResponseInterceptor = (response: HttpResponse) => HttpResponse | Promise>; /** * Error interceptor */ export type ErrorInterceptor = (error: HttpError) => HttpError | Promise; /** * Error interceptor with recovery support * * This type allows error interceptors to recover from errors by retrying * the request and returning a successful response. The response is returned * as an HttpError for type compatibility with the interceptor chain, but * the HTTP client will extract the successful response when processing. * * @remarks * When an interceptor successfully recovers (e.g., retry succeeds, token refresh works), * it can return the HttpResponse. The type uses a discriminated approach where * HttpError has status >= 400 and HttpResponse has status < 400. */ export type RecoveryErrorInterceptor = (error: HttpError) => HttpError | HttpResponse | Promise>; /** * HTTP client configuration */ export interface HttpClientConfig { /** Base URL for all requests */ baseUrl?: string; /** Default timeout (ms) */ timeout?: number; /** Default headers */ headers?: Record; } /** * HTTP client class * * @deprecated Use `ApiClient` from `@/lib/api` instead. * The `ApiClient` provides more features including retry logic, * request deduplication, and configurable token management. * * @example Migration * ```typescript * // Before * import { HttpClient } from '@/lib/services'; * const client = new HttpClient({ baseUrl: 'https://api.example.com' }); * * // After * import { createApiClient } from '@/lib/api'; * const client = createApiClient({ baseUrl: 'https://api.example.com' }); * ``` */ export declare class HttpClient { private config; private requestInterceptors; private responseInterceptors; private errorInterceptors; constructor(config?: HttpClientConfig); /** * Add request interceptor */ addRequestInterceptor(interceptor: RequestInterceptor): () => void; /** * Add response interceptor */ addResponseInterceptor(interceptor: ResponseInterceptor): () => void; /** * Add error interceptor */ addErrorInterceptor(interceptor: ErrorInterceptor): () => void; /** * Execute request */ request(config: HttpRequestConfig): Promise>; /** * GET request */ get(url: string, config?: Omit): Promise>; /** * POST request */ post(url: string, body?: unknown, config?: Omit): Promise>; /** * PUT request */ put(url: string, body?: unknown, config?: Omit): Promise>; /** * PATCH request */ patch(url: string, body?: unknown, config?: Omit): Promise>; /** * DELETE request */ delete(url: string, config?: Omit): Promise>; /** * Build URL with query parameters */ private buildUrl; } /** * Default HTTP client instance * * @deprecated Use `apiClient` from `@/lib/api` instead. * * @example Migration * ```typescript * // Before (deprecated) * import { httpClient } from '@/lib/services'; * const response = await httpClient.get('/users'); * * // After (recommended) * import { apiClient } from '@/lib/api'; * const response = await apiClient.get('/users'); * ``` */ export declare const httpClient: HttpClient;