import { CircuitBreaker } from './circuit-breaker'; /** * Configuration for retry mechanism with exponential backoff */ export interface RetryConfig { maxRetries: number; baseDelayMs: number; maxDelayMs: number; retryableErrors?: (error: unknown) => boolean; /** Optional circuit breaker to check before each attempt */ circuitBreaker?: CircuitBreaker; } /** * Default retry configuration * - 3 retries maximum * - 1 second base delay * - 30 second max delay */ export declare const DEFAULT_RETRY_CONFIG: RetryConfig; /** * Executes a function with retry logic using exponential backoff. * * This utility provides automatic retry handling for transient failures in external API calls. * It implements exponential backoff with jitter to avoid thundering herd problems. * * @example * // Basic usage * const result = await withRetry( * () => fetch('https://api.example.com/data'), * {}, * 'API Call' * ); * * @example * // With custom retry logic * const result = await withRetry( * () => makeApiCall(), * { * maxRetries: 5, * baseDelayMs: 2000, * retryableErrors: (error) => { * if (error instanceof Error) { * return error.message.includes('rate limit'); * } * return false; * } * }, * 'Custom API' * ); * * @template T - The return type of the function being retried * @param fn - The function to execute and retry if needed. Must return a Promise. * @param config - Partial retry configuration to override defaults * @param label - Descriptive label for logging purposes (default: 'unknown') * @returns Promise - Resolves with the result of the function if successful * @throws The last error encountered if all retry attempts fail or if a non-retryable error occurs */ export declare function withRetry(fn: () => Promise, config?: Partial, label?: string): Promise;