/** * =============================================================================== * RETRY POLICY * =============================================================================== * * Reusable retry logic with exponential backoff and jitter. * Extracts common retry patterns from across the codebase. * * Usage: * const policy = createRetryPolicy({ maxRetries: 3 }); * const result = await policy.execute(() => fetch(url)); * * =============================================================================== */ /** * Configuration for retry behavior. */ export interface RetryConfig { /** Maximum number of retry attempts (default: 3) */ maxRetries: number; /** Initial backoff delay in milliseconds (default: 1000) */ initialDelayMs: number; /** Maximum backoff delay in milliseconds (default: 30000) */ maxDelayMs: number; /** Backoff multiplier for exponential growth (default: 2) */ backoffMultiplier: number; /** Whether to add jitter to prevent thundering herd (default: true) */ jitter: boolean; /** Jitter factor (0-1, default: 0.1 = ±10%) */ jitterFactor: number; } /** * Default retry configuration. */ export declare const DEFAULT_RETRY_CONFIG: RetryConfig; /** * Determines if an error should be retried. */ export type ShouldRetryFn = (error: Error, attempt: number) => boolean; /** * Called before each retry attempt. */ export type OnRetryFn = (error: Error, attempt: number, delayMs: number) => void; /** * Retry policy options. */ export interface RetryPolicyOptions extends Partial { /** Custom function to determine if error is retryable */ shouldRetry?: ShouldRetryFn; /** Callback before each retry */ onRetry?: OnRetryFn; } /** * Retry policy for executing operations with automatic retries. */ export declare class RetryPolicy { private readonly config; private readonly shouldRetry; private readonly onRetry?; constructor(options?: RetryPolicyOptions); /** * Execute an operation with retry logic. * * @param operation - Async function to execute * @returns Result of the operation * @throws Last error if all retries exhausted */ execute(operation: () => Promise): Promise; /** * Calculate delay for a given attempt using exponential backoff. */ calculateDelay(attempt: number): number; } /** * Create a retry policy with the given options. */ export declare function createRetryPolicy(options?: RetryPolicyOptions): RetryPolicy; /** * Create a retry policy that never retries. */ export declare function noRetry(): RetryPolicy; /** * Create a retry policy for transient failures only. */ export declare function retryTransient(maxRetries?: number): RetryPolicy; /** * Sleep for a specified duration. */ export declare function sleep(ms: number): Promise; /** * Execute an operation with a simple retry loop. * Convenience function for one-off retry needs. * * @param operation - Async function to execute * @param options - Retry options * @returns Result of the operation */ export declare function withRetry(operation: () => Promise, options?: RetryPolicyOptions): Promise; //# sourceMappingURL=retry-policy.d.ts.map