/** * Core HTTP client for the FedPulse SDK. * * Features: * - Native fetch (Node 18+) — zero runtime dependencies * - Configurable timeout via AbortController * - Automatic retry with exponential back-off + full jitter for transient errors * - In-memory LRU cache for GET requests with per-entry TTL * - Rate-limit header tracking (X-RateLimit-*) * - Standard API envelope parsing + typed error creation * - Array query-parameter serialisation (repeated keys) */ import type { RateLimitInfo, Pagination } from './types/common.js'; /** * Serialise a plain-object params map to a URLSearchParams instance. * * Arrays are serialised as repeated keys: `{ naics: ['11', '21'] }` → * `?naics=11&naics=21`. * * Undefined and null values are omitted. */ export declare function buildQueryParams(params: Record): URLSearchParams; export interface HttpClientOptions { /** API key. Sent as `X-Api-Key: ` on every request. */ apiKey: string; /** API base URL. Defaults to `https://api.fedpulse.dev`. */ baseUrl?: string; /** * Request timeout in milliseconds. Applies to each individual attempt (not * total retry budget). Default: 30 000 ms. */ timeoutMs?: number; /** * Maximum number of retry attempts for transient errors. * Set to 0 to disable retries. Default: 3. */ maxRetries?: number; /** * Maximum number of GET responses to cache in memory. * Set to 0 to disable caching. Default: 256. */ cacheSize?: number; /** * Default TTL for cached GET responses in milliseconds. Default: 60 000 ms. */ cacheTtlMs?: number; /** * Custom `fetch` implementation. Defaults to the global `fetch`. * Useful for testing or environments with a non-standard fetch. */ fetchFn?: typeof fetch; } export interface RequestOptions { /** * Override cache TTL for this specific request (ms). * Pass 0 to bypass cache entirely. */ cacheTtlMs?: number; /** Extra headers to merge into this request. */ headers?: Record; } export interface ParsedResponse { data: T; pagination: Pagination; meta: { requestId: string; cached?: boolean; [key: string]: unknown; }; rateLimit: RateLimitInfo | null; /** Whether the result was served from the in-memory cache. */ fromCache: boolean; } /** * Low-level HTTP client used by all domain resources. * * You should not need to instantiate this directly — use `FedPulse` instead. */ export declare class HttpClient { private readonly apiKey; private readonly baseUrl; private readonly timeoutMs; private readonly maxRetries; private readonly cache; private readonly defaultCacheTtlMs; private readonly fetchFn; /** Most recent rate-limit info observed across all requests. */ lastRateLimit: RateLimitInfo | null; constructor(options: HttpClientOptions); /** * Perform a GET request. Results are cached unless `cacheTtlMs` is 0. * * @param path API path (e.g. `/v1/opportunities`). * @param params Query parameters — arrays serialised as repeated keys. * @param options Per-request overrides. */ get(path: string, params?: Record, options?: RequestOptions): Promise>; /** * Perform a POST request (never cached). * * @param path API path. * @param body JSON-serialisable request body. * @param options Per-request overrides. */ post(path: string, body: unknown, options?: RequestOptions): Promise>; /** * Perform a PATCH request (never cached). */ patch(path: string, body: unknown, options?: RequestOptions): Promise>; /** * Perform a DELETE request (never cached). */ del(path: string, options?: RequestOptions): Promise>; /** * Clear all cached responses. */ clearCache(): void; /** * Execute a request, retrying on transient failures with exponential back-off * and full jitter. */ private executeWithRetry; /** * Execute a single HTTP request (no retry logic). * Handles timeout, response parsing, header extraction, and error creation. */ private executeOnce; /** * Perform a raw fetch that returns the full Response (for streaming downloads). * No retry, no envelope parsing. * * @param path API path. * @param params Query parameters. */ rawGet(path: string, params?: Record): Promise; } //# sourceMappingURL=http.d.ts.map