@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
23 lines (22 loc) • 878 B
JavaScript
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;
;