UNPKG

hacker-news-reel

Version:

A lightweight, typed client for the Hacker News API with validation using Zod

25 lines (24 loc) 1.11 kB
import type { RequestInfo, RequestInit, RetryOptions } from './types'; /** * Default retry options for fetch operations * - maxRetries: 3 attempts * - initialBackoff: 300ms * - maxBackoff: 10000ms (10s) * - jitter: 20% randomness to prevent request floods * - retryableStatusCodes: [429, 500, 502, 503, 504] * - retryNetworkErrors: true * - backoffFactor: 2 (exponential backoff) */ export declare const DEFAULT_RETRY_OPTIONS: Required<RetryOptions>; /** * Calculates backoff time with exponential increase and jitter * @param attempt Current attempt number (0-based) * @param options Retry configuration options * @returns Backoff time in milliseconds */ export declare const calculateBackoff: (attempt: number, { initialBackoff, backoffFactor, maxBackoff, jitter }: Required<RetryOptions>) => number; /** * Fetch with automatic exponential backoff retry for network errors and specified status codes * Also supports request cancellation via AbortSignal */ export declare const fetchWithRetry: (input: RequestInfo, init?: RequestInit, options?: RetryOptions | false) => Promise<Response>;