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.

88 lines (87 loc) 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Elysia = void 0; const wrapRequestHandler_1 = require("./elysia/wrapRequestHandler"); const wrapExport_1 = require("../agent/hooks/wrapExport"); class Elysia { wrapArgs(args) { return args.map((arg) => { if (typeof arg !== "function") { return arg; } return (0, wrapRequestHandler_1.wrapRequestHandler)(arg); }); } wrapOnArgs(args) { return args.map((arg) => { if (typeof arg === "function") { return (0, wrapRequestHandler_1.wrapRequestHandler)(arg); } if (Array.isArray(arg)) { return arg.map((item) => { if (typeof item === "function") { return (0, wrapRequestHandler_1.wrapRequestHandler)(item); } return item; }); } return arg; }); } wrap(hooks) { hooks .addPackage("elysia") .withVersion("^1.4.0") .onRequire((exports, pkgInfo) => { const newExports = Object.create(exports); // Elysia's CJS bundle defines lazy getters for all exports // Accessing exports.Elysia during module initialization (which happens during // circular dependency loading) does not work. // // We define a lazy getter on newExports.Elysia so prototype wrapping is // deferred until the first time user code accesses the class. let instrumented = false; Object.defineProperty(newExports, "Elysia", { configurable: true, enumerable: true, get: () => { const ElysiaClass = exports.Elysia; if (!ElysiaClass) { return ElysiaClass; } if (!instrumented) { instrumented = true; (0, wrapExport_1.wrapExport)(ElysiaClass.prototype, "add", pkgInfo, { kind: undefined, modifyArgs: (args) => this.wrapArgs(args), }); (0, wrapExport_1.wrapExport)(ElysiaClass.prototype, "on", pkgInfo, { kind: undefined, modifyArgs: (args) => this.wrapOnArgs(args), }); } return ElysiaClass; }, }); return newExports; }) .addMultiFileInstrumentation([ "dist/index.js", // CJS "dist/index.mjs", // ESM ], [ { nodeType: "MethodDefinition", name: "add", operationKind: undefined, modifyArgs: (args) => this.wrapArgs(args), }, { nodeType: "MethodDefinition", name: "on", operationKind: undefined, modifyArgs: (args) => this.wrapOnArgs(args), }, ]); } } exports.Elysia = Elysia;