export type RateLimiter = { check: (key: string) => boolean }; export function createRateLimiter(opts: { windowMs: number; max: number; }): RateLimiter { const store = new Map(); return { check(key: string): boolean { const now = Date.now(); const entry = store.get(key); if (!entry || entry.resetAt <= now) { store.set(key, { count: 1, resetAt: now + opts.windowMs }); return true; } if (entry.count >= opts.max) return false; entry.count += 1; return true; } }; }