UNPKG

lago-javascript-client

Version:
32 lines (31 loc) 1.28 kB
import { type RateLimitInfo } from "./rate_limit_headers.js"; /** * Callback invoked after every successful response with parsed rate limit * headers. Use this to build observability around the rate limit (warn at * thresholds, emit metrics, etc.). * * Errors thrown by the callback are caught and logged so they cannot break * the underlying request flow. */ export type RateLimitInfoCallback = (info: RateLimitInfo) => void; /** * Configuration for rate limit fetch behavior */ export interface RateLimitFetchConfig { /** Maximum number of retries on 429 (default: 3) */ maxRetries?: number; /** Whether to automatically retry on rate limit (default: true) */ retryOnRateLimit?: boolean; /** Maximum delay in milliseconds before a retry (default: 20000) */ maxRetryDelay?: number; /** * Optional callback invoked after every successful (non-429) response * with parsed rate limit headers. See `RateLimitInfoCallback`. */ onRateLimitInfo?: RateLimitInfoCallback; } /** * Creates a fetch wrapper that handles rate limiting with automatic retry * Compatible with both Node.js fetch and browser fetch APIs */ export declare function createRateLimitFetch(baseFetch: typeof fetch, config?: RateLimitFetchConfig): typeof fetch;