/** * Retry Utility - SMI-880 * * Exponential backoff retry logic for transient network failures. * Handles ETIMEDOUT, ECONNRESET, and 5xx HTTP errors. */ /** * Configuration for retry behavior */ export interface RetryConfig { /** Maximum number of retry attempts (default: 3) */ maxRetries?: number; /** Initial delay in milliseconds (default: 1000) */ initialDelayMs?: number; /** Maximum delay in milliseconds (default: 30000) */ maxDelayMs?: number; /** Backoff multiplier (default: 2) */ backoffMultiplier?: number; /** Add jitter to prevent thundering herd (default: true) */ jitter?: boolean; /** Custom function to determine if error is retryable */ isRetryable?: (error: unknown) => boolean; /** Callback on each retry attempt */ onRetry?: (attempt: number, error: unknown, delayMs: number) => void; } /** * Default retry configuration */ export declare const DEFAULT_RETRY_CONFIG: Required>; /** * Determines if an error is a transient network error */ export declare function isTransientError(error: unknown): boolean; /** * Determines if an HTTP response status is retryable */ export declare function isRetryableStatus(status: number): boolean; /** * Error class for retry exhaustion. * * Note: This class is exported for use by external callers who may want to * wrap retry failures in a structured error type. The withRetry function * itself throws the original error when retries are exhausted, allowing * callers to handle the specific error type rather than a generic wrapper. */ export declare class RetryExhaustedError extends Error { readonly attempts: number; readonly lastError: unknown; constructor(message: string, attempts: number, lastError: unknown); } /** * Retry a function with exponential backoff * * @param fn - Async function to retry * @param config - Retry configuration * @returns Result of the function * @throws The original error when retries are exhausted or error is not retryable * * @example * ```typescript * const result = await withRetry( * () => fetch('https://api.example.com/data'), * { maxRetries: 3, initialDelayMs: 1000 } * ) * ``` */ export declare function withRetry(fn: () => Promise, config?: RetryConfig): Promise; /** * Retry a fetch request with exponential backoff * * Automatically retries on: * - Network errors (ETIMEDOUT, ECONNRESET, etc.) * - 5xx HTTP errors * - 429 Too Many Requests (with Retry-After header support) * * @param url - URL to fetch * @param options - Fetch options * @param retryConfig - Retry configuration * @returns Fetch Response * * @example * ```typescript * const response = await fetchWithRetry( * 'https://api.github.com/repos/owner/repo', * { headers: { Authorization: 'token xxx' } }, * { maxRetries: 3 } * ) * ``` */ export declare function fetchWithRetry(url: string, options?: RequestInit, retryConfig?: RetryConfig): Promise; /** * Parse Retry-After header value * @param value - Retry-After header value (seconds or HTTP-date) * @returns Delay in milliseconds, or null if invalid */ export declare function parseRetryAfter(value: string | null): number | null; //# sourceMappingURL=retry.d.ts.map