@aura-stack/rate-limiter
v0.1.1
Published
Rate limiting utilities for TypeScript and JavaScript applications with support for authentication flows powered by Aura Auth.
Maintainers
Readme
Rate limiting utilities for the Aura Stack ecosystem
Overview
@aura-stack/rate-limiter provides flexible and performant rate limiting solutions designed for the Aura Stack ecosystem but usable in any TypeScript project.
It offers pluggable storage backends and algorithms to protect your APIs and authentication endpoints from brute-force attacks and abuse.
Features
- Token Bucket Algorithm — Precise control over request rates with burst support.
- In-Memory Store — Fast, built-in memory storage for single-instance applications.
- Framework Agnostic — Works in Node.js, Bun, Deno, and Edge runtimes.
- Type-Safe — Comprehensive TypeScript definitions for all algorithms and stores.
- Extensible — Easily implement custom storage backends (Redis, Database, etc.).
Installation
pnpm add @aura-stack/rate-limiterQuick Start
Basic Usage with Token Bucket
import { createRateLimiter } from "@aura-stack/rate-limiter"
import { TokenBucket } from "@aura-stack/rate-limiter/algorithms"
const limiter = createRateLimiter({
algorithm: new TokenBucket({
capacity: 10,
refillRate: 1, // 1 token per second
}),
})
async function handleRequest(userId: string) {
const result = await limiter.consume(userId)
if (!result.success) {
throw new Error("Too many requests. Try again later.")
}
// Proceed with request
}Documentation
Visit the official documentation website for more detailed guides and API references.
License
Licensed under the MIT License. © Aura Stack
