auto-claude: subtask-1-3 - Add JSDoc to rateLimiting.ts (RateLimiter class and methods)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-25 06:33:46 +01:00
co-authored by Claude Sonnet 4.5
parent d1b8665652
commit baa3ad0571
+16
View File
@@ -1,3 +1,6 @@
/**
* Rate limit entry tracking request count and timestamp
*/
interface RateLimitEntry { interface RateLimitEntry {
count: number; count: number;
timestamp: number; timestamp: number;
@@ -6,6 +9,10 @@ interface RateLimitEntry {
const WINDOW_SIZE_MS = 3600000; // 1 hour const WINDOW_SIZE_MS = 3600000; // 1 hour
const MAX_REQUESTS = 5; // Maximum requests per hour const MAX_REQUESTS = 5; // Maximum requests per hour
/**
* Rate Limiter for API request throttling
* Manages rate limiting based on IP addresses with sliding window
*/
class RateLimiter { class RateLimiter {
private cache: Map<string, RateLimitEntry>; private cache: Map<string, RateLimitEntry>;
@@ -13,6 +20,9 @@ class RateLimiter {
this.cache = new Map(); this.cache = new Map();
} }
/**
* Check if an IP address is currently rate limited
*/
isRateLimited(ip: string): boolean { isRateLimited(ip: string): boolean {
const now = Date.now(); const now = Date.now();
const entry = this.cache.get(ip); const entry = this.cache.get(ip);
@@ -35,6 +45,9 @@ class RateLimiter {
return false; return false;
} }
/**
* Get remaining attempts for an IP address
*/
getRemainingAttempts(ip: string): number { getRemainingAttempts(ip: string): number {
const entry = this.cache.get(ip); const entry = this.cache.get(ip);
if (!entry) { if (!entry) {
@@ -43,6 +56,9 @@ class RateLimiter {
return Math.max(0, MAX_REQUESTS - entry.count); return Math.max(0, MAX_REQUESTS - entry.count);
} }
/**
* Get time in milliseconds until rate limit resets for an IP
*/
getTimeToReset(ip: string): number { getTimeToReset(ip: string): number {
const entry = this.cache.get(ip); const entry = this.cache.get(ip);
if (!entry) { if (!entry) {