Registry / devops / fetch-rate-limit-util

fetch-rate-limit-util

JSON →
library4.6.2jsnpmunverified

A utility library (v4.6.2) that handles fetch errors, rate limits, and caching for HTTP requests. It automatically waits and retries when rate limits are encountered for APIs like Auth0, GitHub, and Zalando. Ships TypeScript types. Small bundle size. Active development with regular releases. Differentiators: supports ETag caching, configurable retry logic, and handlers for redirects, errors, and state action. ESM-only.

npm install fetch-rate-limit-util
INSTALL
IMPORT
SIG · FETCH-RATE-LIMIT-U
F
fetch-rate-limit-util
devopsjavascriptv4.6.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stateActionHandler
import { stateActionHandler } from 'fetch-rate-limit-util'
const { stateActionHandler } = require('fetch-rate-limit-util')
ESM-only package, CJS require will fail or require special setup.
rateLimitHandler
import { rateLimitHandler } from 'fetch-rate-limit-util'
import rateLimitHandler from 'fetch-rate-limit-util'
Named export, not default. This package exports only named exports.
defaultOptions
import { defaultOptions } from 'fetch-rate-limit-util'
import { Options } from 'fetch-rate-limit-util'
defaultOptions is an object, not a type. Types are not exported explicitly. Use typeof defaultOptions for type inference.

Demonstrates basic usage of stateActionHandler with retry and caching, including TypeScript types.

import { stateActionHandler, cacheHandler, DEFAULT_MAX_RETRIES, DEFAULT_MIN_WAIT_MSECS } from 'fetch-rate-limit-util'; async function fetchWithRetry(url: string, options?: RequestInit): Promise<Response> { const response = await stateActionHandler(url, { ...options, maxRetries: DEFAULT_MAX_RETRIES, minWait: DEFAULT_MIN_WAIT_MSECS, }); return response; } // Example usage with caching async function cachedFetch(url: string): Promise<Response> { const cacheOptions = { cache: new Map<string, Response>(), maxAge: 60000 }; return await cacheHandler(url, {}, cacheOptions); } console.log(await fetchWithRetry('https://api.example.com/data'));
Debug
Known issues
breakingRemoved Node.js 10 support in v4. Requires Node.js 12+ or ESM-compatible environment.
fix
Upgrade Node.js to version 12 or higher, or use an older version (v3.x).
affects: >=4.0.0 <5.0.0
breakingSwitched to ESM-only in v4. CommonJS require() will not work.
fix
Use import statements or configure your project for ESM (e.g., type: module in package.json).
affects: >=4.0.0
gotchaThe default export does not exist. All exports are named.
fix
Use named imports like import { stateActionHandler } from 'fetch-rate-limit-util'.
affects: >=4.0.0
gotcharateLimitHandler only handles rate limit responses (429/Retry-After). For other errors, use errorHandler or combine handlers.
fix
Chain multiple handlers or use stateActionHandler which integrates them.
affects: >=4.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use ESM import in a CommonJS project without proper configuration.
fix
Add 'type': 'module' to package.json or use .mjs extension.
TypeError: stateActionHandler is not a function
Incorrect import: trying to use default import or destructure from an object that doesn't exist.
fix
Use correct named import: import { stateActionHandler } from 'fetch-rate-limit-util'.
Upgrade
Version history
4.6.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-rate-limit-util — npm install fetch-rate-limit-util · libregistry