npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pingpong-js/plugin-retry

v1.0.1

Published

Advanced retry plugin for @pingpong-js/fetch with circuit breaker, rate limiting, and backoff strategies

Readme

@pingpong-js/plugin-retry

Advanced retry strategies and resilience patterns for @pingpong-js/fetch.

Installation

npm install @pingpong-js/plugin-retry
# peer dependency
npm install @pingpong-js/fetch

Features

  • 🔄 Advanced Retry: Exponential, linear, fibonacci, decorrelated backoff
  • Circuit Breaker: Prevent cascading failures
  • 🚦 Rate Limiting: Client-side request throttling
  • ⏱️ Configurable Timeout: Per-method timeout settings
  • 🎯 Fallback Handler: Return fallback data on failure
  • 🛡️ Jitter Support: Prevent thundering herd

Usage

Advanced Retry

import pingpong from '@pingpong-js/fetch';
import { withAdvancedRetry } from '@pingpong-js/plugin-retry';

pingpong.onRetry(withAdvancedRetry({
  maxRetries: 5,
  backoff: 'exponential',
  jitter: 'full',
  onRetry: (attempt, delay, response) => {
    console.log(`Retry ${attempt}, waiting ${delay}ms`);
  },
}));

Circuit Breaker

import pingpong from '@pingpong-js/fetch';
import { createCircuitBreaker, CircuitOpenError } from '@pingpong-js/plugin-retry';

const breaker = createCircuitBreaker({
  failureThreshold: 5, // Open after 5 failures
  timeout: 30000, // Try again after 30s
  onStateChange: (state, prev) => {
    console.log(`Circuit: ${prev} -> ${state}`);
  },
});

pingpong.onRequest(breaker.request);
pingpong.onResponse(breaker.response);
pingpong.onError(breaker.error);

try {
  await pingpong.get('/api/unreliable');
} catch (error) {
  if (error instanceof CircuitOpenError) {
    console.log('Circuit is open, try again later');
  }
}

Rate Limiting

import pingpong from '@pingpong-js/fetch';
import { withRateLimit } from '@pingpong-js/plugin-retry';

// 10 requests per second
pingpong.onRequest(withRateLimit({
  maxRequests: 10,
  window: 1000,
  strategy: 'delay', // 'delay' | 'reject' | 'queue'
}));

Fallback Handler

import pingpong from '@pingpong-js/fetch';
import { withFallback } from '@pingpong-js/plugin-retry';

// Static fallback
pingpong.onError(withFallback({
  fallbackData: { users: [], error: true },
  onFallback: (error) => console.warn('Using fallback:', error.message),
}));

// Dynamic fallback
pingpong.onError(withFallback({
  fallbackFn: async (error, request) => {
    return getCachedData(request.url);
  },
}));

Configurable Timeout

import pingpong from '@pingpong-js/fetch';
import { withTimeoutPlugin } from '@pingpong-js/plugin-retry';

pingpong.onRequest(withTimeoutPlugin({
  timeout: 5000,
  methodTimeouts: {
    POST: 30000, // POST gets 30s
    GET: 5000,   // GET gets 5s
  },
}));

API Reference

withAdvancedRetry(options?)

Advanced retry with configurable backoff strategies.

Options:

  • maxRetries: Maximum retry attempts (default: 3)
  • baseDelay: Base delay in ms (default: 1000)
  • maxDelay: Maximum delay in ms (default: 30000)
  • backoff: 'exponential' | 'linear' | 'constant' | 'fibonacci' | 'decorrelated'
  • jitter: 'full' | 'equal' | 'none'
  • retryStatusCodes: Status codes to retry (default: [408, 429, 500, 502, 503, 504])
  • respectRetryAfter: Honor Retry-After header (default: true)

createCircuitBreaker(options?)

Circuit breaker pattern implementation.

Options:

  • failureThreshold: Failures before opening (default: 5)
  • successThreshold: Successes to close from half-open (default: 2)
  • timeout: Time before trying half-open (default: 30000)
  • failureStatusCodes: Status codes considered failures
  • onStateChange: Callback when state changes

withRateLimit(options?)

Client-side rate limiting.

Options:

  • maxRequests: Requests per window (default: 10)
  • window: Window size in ms (default: 1000)
  • strategy: 'delay' | 'reject' | 'queue'

withFallback(options)

Return fallback data on failure.

withTimeoutPlugin(options?)

Add configurable timeout to requests.

License

MIT