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.

27 lines (26 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformCode = transformCode; // eslint-disable-next-line camelcase const node_code_instrumentation_1 = require("./wasm/node_code_instrumentation"); const getSourceType_1 = require("./getSourceType"); const path_1 = require("path"); const isNewInstrumentationUnitTest_1 = require("../../../helpers/isNewInstrumentationUnitTest"); const isEsmUnitTest_1 = require("../../../helpers/isEsmUnitTest"); function transformCode(pkgName, pkgVersion, path, code, pkgLoadFormat, fileInstructions) { try { const result = (0, node_code_instrumentation_1.wasm_transform_code_str)(pkgName, pkgVersion, code, JSON.stringify(fileInstructions), (0, getSourceType_1.getSourceType)(path, pkgLoadFormat)); // Rewrite import path for unit tests if environment variable is set to true if ((0, isNewInstrumentationUnitTest_1.isNewInstrumentationUnitTest)()) { return result.replace("@aikidosec/firewall/instrument/internals", (0, path_1.join)(__dirname, (0, isEsmUnitTest_1.isEsmUnitTest)() ? "injectedFunctions.js" : "injectedFunctions.ts")); } return result; } catch (error) { // Convert string errors to Error objects if (typeof error === "string") { throw new Error(`Error transforming code: ${error}`); } throw error; } }