UNPKG

@aikidosec/firewall

Version:

Zen by Aikido is an embedded Web Application Firewall that autonomously protects Node.js apps against common and critical attacks

23 lines (22 loc) 878 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReportingAPIRateLimitedServerSide = void 0; class ReportingAPIRateLimitedServerSide { constructor(api) { this.api = api; this.stopSendingForInMilliseconds = 30 * 60 * 1000; this.rateLimitedAt = null; } async report(token, event, timeoutInMS) { if (typeof this.rateLimitedAt === "number" && Date.now() - this.rateLimitedAt < this.stopSendingForInMilliseconds) { return { success: false, error: "rate_limited" }; } const result = await this.api.report(token, event, timeoutInMS); if (!result.success && result.error === "rate_limited") { this.rateLimitedAt = Date.now(); } return result; } } exports.ReportingAPIRateLimitedServerSide = ReportingAPIRateLimitedServerSide;