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.

43 lines (42 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getApiInfo = getApiInfo; const getApiAuthType_1 = require("./getApiAuthType"); const getBodyDataType_1 = require("./getBodyDataType"); const getDataSchema_1 = require("./getDataSchema"); /** * Get body data type and schema from context. * Returns undefined if the body is not an object or if the body type could not be determined. */ function getApiInfo(context) { try { let bodyInfo; if (context.body && typeof context.body === "object" && Object.keys(context.body).length > 0 && !context.graphql) { bodyInfo = { type: (0, getBodyDataType_1.getBodyDataType)(context.headers), schema: (0, getDataSchema_1.getDataSchema)(context.body), }; } let queryInfo; if (context.query && typeof context.query === "object" && Object.keys(context.query).length > 0) { queryInfo = (0, getDataSchema_1.getDataSchema)(context.query); } const authInfo = (0, getApiAuthType_1.getApiAuthType)(context); if (!bodyInfo && !queryInfo && !authInfo) { return undefined; } return { body: bodyInfo, query: queryInfo, auth: authInfo, }; } catch { return undefined; } }