@haatlabs-core/rate-limit
A token bucket kept in Redis, so every process shares one limit.
import { perMinutePolicy, RedisTokenBucketLimiter } from '@haatlabs-core/rate-limit';
const limiter = new RedisTokenBucketLimiter(redis, { keyPrefix: 'myapp:' });
const { allowed, retryAfterMs } = await limiter.consume('provider:search', perMinutePolicy(60));
Every limiter is given a prefix of its own, so apps that share a Redis keep their buckets apart; an empty one is refused:
new RedisTokenBucketLimiter(redis, { keyPrefix: 'myapp:' }); // keys myapp:ratelimit:…
RedisShopifyThrottle paces each Shopify shop for every process of an app (one small hash a
shop). When Redis is away (the failed call and ten seconds after it) it hands the shops to its
fallback, or, without one, lets calls through and each client's own pacing goes on:
import { processShopifyThrottle } from '@haatlabs-core/shopify';
const throttle = new RedisShopifyThrottle(redis, {
keyPrefix: 'myapp:',
logger,
fallback: processShopifyThrottle,
});
Install
pnpm add @haatlabs-core/rate-limit
It leaves one package to your app, so the app holds one copy: ioredis.