// Tiny in-memory sliding-window rate limiter. // Acceptable for single-instance Nitro on Netlify; swap to Mongo/Upstash if // we move to multi-instance. const buckets = new Map() export function rateLimit(key, { max, windowMs }) { const now = Date.now() const arr = (buckets.get(key) || []).filter((t) => now - t < windowMs) if (arr.length >= max) return false arr.push(now) buckets.set(key, arr) return true } // Test helper — clears all buckets so each test starts clean. export function resetRateLimit() { buckets.clear() }