UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

45 lines (44 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.filterResponseForLogging = void 0; const isPlainObject_1 = require("./isPlainObject"); const config_1 = require("../config"); const dotProp = require("dot-prop"); /** * Prepares acton response for logging. * Hides any sensitive data as defined by `api.config.general.filteredResponse` * Truncates long strings via `api.config.logger.maxLogStringLength` */ function filterResponseForLogging(response) { var _a; response = Object.assign({}, response); const sanitizedResponse = {}; for (const i in response) { if (isPlainObject_1.isPlainObject(response[i])) { sanitizedResponse[i] = response[i]; } else if (typeof response[i] === "string") { sanitizedResponse[i] = response[i].substring(0, config_1.config.logger.maxLogStringLength); } else if (response[i] instanceof Error) { sanitizedResponse[i] = (_a = response[i].message) !== null && _a !== void 0 ? _a : String(response[i]); } else { sanitizedResponse[i] = response[i]; } } let filteredResponse; if (typeof config_1.config.general.filteredResponse === "function") { filteredResponse = config_1.config.general.filteredResponse(); } else { filteredResponse = config_1.config.general.filteredResponse; } filteredResponse.forEach((configParam) => { if (dotProp.get(response, configParam) !== undefined) { dotProp.set(sanitizedResponse, configParam, "[FILTERED]"); } }); return sanitizedResponse; } exports.filterResponseForLogging = filterResponseForLogging;