@aikidosec/firewall
Version:
Zen by Aikido is an embedded Web Application Firewall that autonomously protects Node.js apps against common and critical attacks
54 lines (53 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hono = void 0;
const wrapRequestHandler_1 = require("./hono/wrapRequestHandler");
const wrapExport_1 = require("../agent/hooks/wrapExport");
const wrapNewInstance_1 = require("../agent/hooks/wrapNewInstance");
const METHODS = [
"get",
"post",
"put",
"delete",
"options",
"patch",
"all",
"on",
"use",
];
class Hono {
// Wrap all the functions passed to hono.METHOD(...)
// Examples:
// hono.METHOD(path, handler)
// hono.METHOD(path, middleware, handler)
// hono.METHOD(path, middleware, middleware, ..., handler)
// hono.use(middleware)
// hono.use(middleware, middleware, ...)
wrapArgs(args) {
return args.map((arg) => {
// Ignore non-function arguments
if (typeof arg !== "function") {
return arg;
}
return (0, wrapRequestHandler_1.wrapRequestHandler)(arg);
});
}
wrap(hooks) {
hooks
.addPackage("hono")
.withVersion("^4.0.0")
.onRequire((exports, pkgInfo) => {
const newExports = Object.create(exports);
(0, wrapNewInstance_1.wrapNewInstance)(newExports, "Hono", pkgInfo, (instance) => {
METHODS.forEach((method) => {
(0, wrapExport_1.wrapExport)(instance, method, pkgInfo, {
kind: undefined,
modifyArgs: this.wrapArgs,
});
});
});
return newExports;
});
}
}
exports.Hono = Hono;