/** * Retry Logic with Exponential Backoff * * Handles transient failures common with government websites */ /** * Options for retry behavior */ export interface RetryOptions { /** * Maximum number of total attempts (not retries). * * Note: This is TOTAL ATTEMPTS, not retry count. * - maxAttempts: 1 = no retries (just the initial attempt) * - maxAttempts: 3 = 1 initial attempt + up to 2 retries * * @default 3 (1 initial + 2 retries) */ maxAttempts?: number; /** * Initial delay before first retry in milliseconds. * @default 1000 */ initialDelayMs?: number; /** * Maximum delay between retries in milliseconds. * Caps the exponential backoff. * @default 30000 */ maxDelayMs?: number; /** * Multiplier for exponential backoff between retries. * delay = min(initialDelayMs * backoffMultiplier^retryCount, maxDelayMs) * @default 2 */ backoffMultiplier?: number; /** * Function to determine if an error should trigger a retry. * Return true to retry, false to throw immediately. * @default Retries on network errors, timeouts, and 502/503/504 status codes */ retryOn?: (error: Error) => boolean; /** * Callback invoked before each retry attempt. * Useful for logging or cleanup between attempts. */ onRetry?: (attempt: number, error: Error, delayMs: number) => void; } /** * Execute an async function with automatic retry on failure. * * Uses exponential backoff between retries. The delay doubles after each * retry until it reaches maxDelayMs. * * @param fn - Async function to execute * @param options - Retry configuration options * @returns Result of the function if successful * @throws Last error if all attempts fail * * @example * ```typescript * const result = await withRetry( * () => fetchData(url), * { * maxAttempts: 3, // 1 initial + 2 retries * initialDelayMs: 1000, // 1s before first retry * backoffMultiplier: 2, // 1s, 2s, 4s... between retries * maxDelayMs: 10000, // Cap at 10s * } * ); * ``` */ export declare function withRetry(fn: () => Promise, options?: RetryOptions): Promise; //# sourceMappingURL=retry.d.ts.map