export class RateLimitingModule { private counters: Map = new Map(); private limit: number = 1000; private window: number = 60000; // 1 min constructor() {} setRules(rules: any[]) { // Find Rate Limit rule const rateRule = rules.find(r => r.type === 'RATE_LIMIT' && r.enabled); if (rateRule && rateRule.config) { this.limit = rateRule.config.limit || 1000; this.window = rateRule.config.window || 60000; } } check(key: string): boolean { const now = Date.now(); const record = this.counters.get(key); if (!record || (now - record.start > this.window)) { this.counters.set(key, { count: 1, start: now }); return true; } if (record.count >= this.limit) { return false; } record.count++; return true; } }