/** * =============================================================================== * HTTP CLIENT * =============================================================================== * * Reusable HTTP client with built-in: * - Timeout handling (AbortController) * - Retry with exponential backoff * - Error classification using PromptSpeak error types * - Request/response logging hooks * * Consolidates duplicate HTTP patterns from: * - government/adapters/base-adapter.ts * - swarm/ebay/client.ts * - notifications/webhook-dispatcher.ts * * =============================================================================== */ import { type RetryPolicyOptions } from './retry-policy.js'; /** * HTTP client configuration. */ export interface HttpClientConfig { /** Base URL for all requests (optional) */ baseUrl?: string; /** Default request timeout in milliseconds (default: 30000) */ timeoutMs: number; /** Default headers to include in all requests */ defaultHeaders?: Record; /** Retry configuration (optional, disables retry if not provided) */ retry?: RetryPolicyOptions; /** HTTP status codes that should trigger a retry */ retryableStatusCodes?: number[]; } /** * Default HTTP client configuration. */ export declare const DEFAULT_HTTP_CONFIG: HttpClientConfig; /** * HTTP request options. */ export interface HttpRequestOptions { /** HTTP method (default: GET) */ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; /** Request headers (merged with defaults) */ headers?: Record; /** Request body (will be JSON stringified for objects) */ body?: unknown; /** Override timeout for this request */ timeoutMs?: number; /** Skip retry for this request */ skipRetry?: boolean; /** Parse response as JSON (default: true) */ parseJson?: boolean; } /** * HTTP response wrapper. */ export interface HttpResponse { /** HTTP status code */ status: number; /** HTTP status text */ statusText: string; /** Response headers */ headers: Headers; /** Parsed response data */ data: T; /** Whether the response was successful (2xx) */ ok: boolean; } /** * Classifies HTTP errors into PromptSpeak error types. */ export declare function classifyHttpError(status: number, statusText: string, url: string, retryableStatusCodes?: number[]): Error; /** * Wraps fetch errors in PromptSpeak error types. */ export declare function wrapFetchError(error: Error, url: string, timeoutMs: number): Error; /** * Reusable HTTP client with retry, timeout, and error handling. */ export declare class HttpClient { private readonly config; private readonly retryPolicy?; constructor(config?: Partial); /** * Make an HTTP request. * * @param endpoint - URL or path (appended to baseUrl if relative) * @param options - Request options * @returns Response wrapper with parsed data * @throws Classified PromptSpeak errors on failure */ request(endpoint: string, options?: HttpRequestOptions): Promise>; /** * GET request. */ get(endpoint: string, options?: Omit): Promise>; /** * POST request. */ post(endpoint: string, body?: unknown, options?: Omit): Promise>; /** * PUT request. */ put(endpoint: string, body?: unknown, options?: Omit): Promise>; /** * PATCH request. */ patch(endpoint: string, body?: unknown, options?: Omit): Promise>; /** * DELETE request. */ delete(endpoint: string, options?: Omit): Promise>; /** * Resolve URL from endpoint and baseUrl. */ private resolveUrl; /** * Merge request headers with defaults. */ private mergeHeaders; /** * Serialize request body. */ private serializeBody; } /** * Create an HTTP client with the given configuration. */ export declare function createHttpClient(config?: Partial): HttpClient; /** * Create an HTTP client configured for JSON APIs. */ export declare function createJsonClient(baseUrl: string, options?: Partial>): HttpClient; /** * Create an HTTP client with authentication. */ export declare function createAuthenticatedClient(baseUrl: string, authHeader: string, authValue: string, options?: Partial): HttpClient; //# sourceMappingURL=http-client.d.ts.map