/** * Retry utility with exponential backoff and jitter. * * Features: * - Exponential backoff with random jitter * - Configurable max retries * - Retry on specific status codes and network errors * - Respect Retry-After header from 429 responses * - Progress callback for logging * * Qué se reintenta (#222): * - Respuestas con status en `retryableStatusCodes` (por defecto 429, 503 y * 504), para cualquier operación. * - Fallos SIN respuesta (`isTransientNetworkError`: conexión rechazada o * cortada, DNS, timeout), solo si `retryOnNoResponse` no es `false`. Un fallo * sin respuesta garantiza que no hubo respuesta, no que el servidor no * recibió la petición: repetir una escritura puede duplicarla. Por eso * `FetchClient` lo apaga en POST/PUT/PATCH/DELETE y los llamadores que * envuelven escrituras también. * * Qué no se reintenta: cualquier otro status (400, 401, 404, 409, 422…, salvo * que el llamador los incluya), y cualquier error que no tenga la forma de un * fallo de red. */ /** * Códigos de error de red transitorios, en `error.code` o en * `error.cause.code`. Además, cualquier código de undici (`UND_ERR_*`). */ export declare const NETWORK_ERROR_CODES: ReadonlySet; /** * ¿El error es un fallo de red sin respuesta? Se decide por la forma del * error, no solo por `error.code`. * * Formas medidas con el `fetch` nativo de Node 22 (undici) el 2026-10-23 * (#222), contra servidores locales: * * | Caso | error | error.code | error.cause.code | * |---------------------|-----------------------------|------------|------------------| * | Conexión rechazada | TypeError: fetch failed | undefined | ECONNREFUSED | * | Conexión cortada | TypeError: fetch failed | undefined | UND_ERR_SOCKET | * | DNS inexistente | TypeError: fetch failed | undefined | ENOTFOUND | * | Timeout del abort | AbortError | 20 (número)| — | * * Reglas (basta una): * 1. `code` o `cause.code` está en `NETWORK_ERROR_CODES` o empieza por * `UND_ERR_`. Incluye `code` en la raíz por compatibilidad. * 2. `TypeError` con mensaje "fetch failed": la forma de undici cuando el * fallo es previo a la respuesta. Existe porque la issue midió causas SIN * código (conexión rechazada con `cause.code` undefined). * 3. `name === "AbortError"`: el timeout del `AbortController`. Su `code` es * el 20 numérico del DOMException y no se usa. */ export declare function isTransientNetworkError(error: unknown): boolean; export interface RetryOptions { /** * Maximum number of retry attempts (default: 3) */ maxRetries?: number; /** * Initial delay in milliseconds before first retry (default: 1000) */ initialDelayMs?: number; /** * Maximum delay in milliseconds (default: 30000) */ maxDelayMs?: number; /** * HTTP status codes that should trigger a retry (default: [429, 503, 504]) */ retryableStatusCodes?: number[]; /** * Reintentar fallos sin respuesta (red caída, conexión cortada, DNS, * timeout). Default: true. Debe ser `false` para escrituras: sin respuesta * no se sabe si el servidor aplicó la petición, y repetirla puede duplicarla. */ retryOnNoResponse?: boolean; /** * Callback invoked before each retry attempt * @param attempt - Current attempt number (1-indexed) * @param error - The error that triggered the retry * @param delayMs - Calculated delay before retry in milliseconds */ onRetry?: (attempt: number, error: Error, delayMs: number) => void; } /** * Retry an async operation with exponential backoff. * * @param operation - Async function to retry * @param options - Retry configuration options * @returns Promise resolving to operation result * @throws Last error if all retries exhausted * * @example * ```typescript * const result = await retryWithBackoff( * () => fetchClient.get('/api/resource'), * { * maxRetries: 3, * onRetry: (attempt, error, delay) => { * console.log(`Retry ${attempt} after ${delay}ms: ${error.message}`); * } * } * ); * ``` */ export declare function retryWithBackoff(operation: () => Promise, options?: RetryOptions): Promise; //# sourceMappingURL=retryWithBackoff.d.ts.map