From baa3ad05715ab664ef0b9d813898802b4527ac8b Mon Sep 17 00:00:00 2001 From: Damjan Savic Date: Sun, 25 Jan 2026 06:33:46 +0100 Subject: [PATCH] auto-claude: subtask-1-3 - Add JSDoc to rateLimiting.ts (RateLimiter class and methods) Co-Authored-By: Claude Sonnet 4.5 --- src/utils/rateLimiting.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/utils/rateLimiting.ts b/src/utils/rateLimiting.ts index f1a77b7..7ce2248 100644 --- a/src/utils/rateLimiting.ts +++ b/src/utils/rateLimiting.ts @@ -1,3 +1,6 @@ +/** + * Rate limit entry tracking request count and timestamp + */ interface RateLimitEntry { count: number; timestamp: number; @@ -6,6 +9,10 @@ interface RateLimitEntry { const WINDOW_SIZE_MS = 3600000; // 1 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 { private cache: Map; @@ -13,6 +20,9 @@ class RateLimiter { this.cache = new Map(); } + /** + * Check if an IP address is currently rate limited + */ isRateLimited(ip: string): boolean { const now = Date.now(); const entry = this.cache.get(ip); @@ -35,6 +45,9 @@ class RateLimiter { return false; } + /** + * Get remaining attempts for an IP address + */ getRemainingAttempts(ip: string): number { const entry = this.cache.get(ip); if (!entry) { @@ -43,6 +56,9 @@ class RateLimiter { return Math.max(0, MAX_REQUESTS - entry.count); } + /** + * Get time in milliseconds until rate limit resets for an IP + */ getTimeToReset(ip: string): number { const entry = this.cache.get(ip); if (!entry) {