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.

36 lines (35 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setTenantId = setTenantId; const AgentSingleton_1 = require("../AgentSingleton"); const ContextStorage_1 = require("./ContextStorage"); function setTenantId(id) { const agent = (0, AgentSingleton_1.getInstance)(); if (!agent) { return; } const context = ContextStorage_1.ContextStorage.getStore(); if (!context) { logWarningSetTenantIdCalledWithoutContext(); return; } const rawId = id; if (typeof rawId !== "string" && typeof rawId !== "number") { agent.log(`setTenantId(...) expects a string or number, found ${typeof rawId} instead.`); return; } if (typeof rawId === "string" && rawId.length === 0) { agent.log(`setTenantId(...) expects a non-empty string.`); return; } context.tenantId = rawId.toString(); } let loggedWarning = false; function logWarningSetTenantIdCalledWithoutContext() { if (loggedWarning) { return; } // eslint-disable-next-line no-console console.warn("setTenantId(...) was called without a context. Make sure to call setTenantId(...) within an HTTP request. If you're using serverless functions, make sure to use the handler wrapper provided by Zen. Also ensure you import Zen at the top of your main app file (before any other imports)."); loggedWarning = true; }