@bmz_1/graphql-rate-limiter
v1.1.0
Published
[ [](https://opensource.org/licenses/MIT)
Readme
Shopify Rate Limiter

- 🚀 Atomic operations with Lua scripts
Shopify Rate Limiter
🔖 A distributed rate limiter for Shopify Admin GraphQL API with Redis backend
📦 Installation
npm install @bmz_1/graphql-rate-limiter ioredis🚀 Quick Start
import Redis from 'ioredis';
import { RateLimiter, Plan } from '@bmz_1/graphql-rate-limiter';
// Initialize
const redis = new Redis();
const limiter = new RateLimiter(redis);
// Usage pattern
async function makeShopifyRequest(storeId: string) {
const limit = await limiter.checkRateLimit(storeId, Plan.STANDARD);
if (!limit.allowed) {
throw new Error(`Rate limited. Retry in ${limit.retryAfter}ms`);
}
try {
const response = await fetchShopifyData();
// Update with actual API cost
await limiter.updateThrottleStatus(storeId, response.extensions.cost.throttleStatus, Plan.STANDARD);
return response;
} catch (error) {
// Handle failed request costs
await limiter.updateThrottleStatus(
storeId,
{
maximumAvailable: 1000,
currentlyAvailable: limit.remainingPoints,
restoreRate: 100,
},
Plan.STANDARD,
);
throw error;
}
}⚙️ Configuration
| Plan | Max Points | Restore Rate |
|-------------|------------|--------------|
| Standard | 1000 | 100/s |
| Advanced | 2000 | 200/s |
| Plus | 5000 | 1000/s |
| Enterprise | 10000 | 2000/s |🧪 Testing Setup
# Start Redis
docker-compose up -d
# Run tests
npm test🛠️ Development Commands
# Build project
npm run build
# Watch mode
npm run dev
# Test coverage
npm test📜 License
MIT © BMZ
