UNPKG

@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.

33 lines (32 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pollForChanges = pollForChanges; const getConfig_1 = require("./getConfig"); const getConfigLastUpdatedAt_1 = require("./getConfigLastUpdatedAt"); let interval = null; let currentLastUpdatedAt = null; function pollForChanges({ onConfigUpdate, token, logger, lastUpdatedAt, }) { if (!token) { logger.log("No token provided, not polling for config updates"); return; } currentLastUpdatedAt = lastUpdatedAt; if (interval) { clearInterval(interval); } interval = setInterval(() => { check(token, onConfigUpdate).catch((error) => { logger.log(`Failed to check for config updates: ${error.message}`); }); }, 60 * 1000); interval.unref(); } async function check(token, onConfigUpdate) { const configLastUpdatedAt = await (0, getConfigLastUpdatedAt_1.getConfigLastUpdatedAt)(token); if (typeof currentLastUpdatedAt === "number" && configLastUpdatedAt > currentLastUpdatedAt) { const config = await (0, getConfig_1.getConfig)(token); currentLastUpdatedAt = config.configUpdatedAt; onConfigUpdate(config); } }