/** * Bounded retry policy for idempotent HTTP requests. * * A rolling deploy restarts one API instance at a time, so a request can fail * with `502`/`503`/`504` or a reset connection for a few seconds even though * the platform is healthy. Retrying those — and ONLY those, and only when the * request is safe to repeat — turns a user-visible error into a short wait. * * The rules the policy enforces: * * - **Idempotent methods only.** `GET`, `HEAD`, `PUT`, `DELETE` and `OPTIONS` * may be repeated. `POST` and `PATCH` are retried ONLY when the caller sent * an `Idempotency-Key` header, which tells the server to collapse the repeat * (a retried POST without one can create two records). * - **Transient failures only.** Statuses `502`/`503`/`504`, and connection * errors (reset/refused/timeout). A `500` is a server bug, not a rolling * restart, and is not retried. * - **Bounded.** Two retries by default, exponential backoff with jitter, and * `Retry-After` from the server is honored when present. * - **Never on an abort.** A cancelled request (effect cleanup, navigation) is * not retried. * * @module */ import type { HttpMethod } from './types.js'; /** * Tuning for the retry policy. */ export interface RetryOptions { /** * Maximum retries AFTER the first attempt. Defaults to `2` (three attempts * in total). */ maxRetries?: number; /** Base backoff in milliseconds. Defaults to `300`. */ baseDelayMs?: number; /** Maximum backoff (before `Retry-After` can extend it). Defaults to `5000`. */ maxDelayMs?: number; /** Statuses treated as transient. Defaults to `[502, 503, 504]`. */ retryStatuses?: number[]; } /** The resolved policy used when a caller passes no options. */ export declare const DEFAULT_RETRY_OPTIONS: Required; /** The request fields the policy decides from. */ export interface RetryDecisionInput { /** The request method. */ method: HttpMethod; /** The request headers (lower-cased lookup is done here). */ headers: Record; /** The HTTP status, or `0` when no response arrived. */ status: number; /** How many retries have already been made (0 for the first failure). */ attempt: number; /** The error message, used to recognize a connection reset/refusal. */ errorMessage?: string; /** `true` when the request was aborted before a response. */ aborted?: boolean; /** Overrides layered over {@link DEFAULT_RETRY_OPTIONS}. */ options?: RetryOptions | false; } /** * Whether a request may be repeated at all. * * @param method - The HTTP method. * @param headers - The request headers (an `Idempotency-Key` makes POST/PATCH repeatable). * @returns `true` when repeating the request cannot duplicate a side effect. */ export declare function isIdempotentRequest(method: HttpMethod, headers: Record): boolean; /** * Whether a connection-level error is transient (a restarted process refuses * or resets connections; a DNS or TLS configuration error does not). * * @param message - The error message. * @returns `true` for reset/refused/closed-early/timeout shapes. */ export declare function isTransientConnectionError(message: string | undefined): boolean; /** * Parse a `Retry-After` header into milliseconds from now. * * @param value - The header value (`seconds` or an HTTP date). * @param now - The clock, injected for tests. * @returns Milliseconds to wait, or undefined when absent/unparseable. */ export declare function parseRetryAfter(value: string | undefined, now?: number): number | undefined; /** * Decide whether one failed request should be retried. * * @param input - The method, headers, status/error and attempt count. * @returns `true` when the request may be repeated. */ export declare function shouldRetryRequest(input: RetryDecisionInput): boolean; /** * Compute the wait before the next attempt. * * `Retry-After` wins when the server sent one (it knows when the instance will * be back); otherwise exponential backoff with full jitter. * * @param retryAfter - The raw `Retry-After` header value, when present. * @param attempt - How many retries have already been made (0 for the first). * @param options - Policy overrides. * @param random - Jitter source, injected for tests (defaults to `Math.random`). * @returns Milliseconds to wait before retrying. */ export declare function retryDelayMs(retryAfter: string | undefined, attempt: number, options?: RetryOptions | false, random?: () => number): number; //# sourceMappingURL=retry.d.ts.map