actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
46 lines (45 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterObjectForLogging = filterObjectForLogging;
const isPlainObject_1 = require("./isPlainObject");
const deepCopy_1 = require("./deepCopy");
const config_1 = require("../config");
const dotProp = require("dot-prop");
/**
* Prepares acton params for logging.
* Hides any sensitive data as defined by `api.config.general.filteredParams`
* Truncates long strings via `api.config.logger.maxLogStringLength`
*/
function filterObjectForLogging(params) {
var _a, _b;
params = (0, deepCopy_1.deepCopy)(params);
const sanitizedParams = {};
for (const i in params) {
if (Array.isArray(params[i]) &&
params[i].length > ((_b = (_a = config_1.config.logger) === null || _a === void 0 ? void 0 : _a.maxLogArrayLength) !== null && _b !== void 0 ? _b : 10)) {
params[i] = `${params[i].length} items`;
}
if ((0, isPlainObject_1.isPlainObject)(params[i])) {
sanitizedParams[i] = params[i];
}
else if (typeof params[i] === "string") {
sanitizedParams[i] = params[i].substring(0, config_1.config.logger.maxLogStringLength);
}
else {
sanitizedParams[i] = params[i];
}
}
let filteredParams;
if (typeof config_1.config.general.filteredParams === "function") {
filteredParams = config_1.config.general.filteredParams();
}
else {
filteredParams = config_1.config.general.filteredParams;
}
filteredParams.forEach((configParam) => {
if (dotProp.get(params, configParam) !== undefined) {
dotProp.set(sanitizedParams, configParam, "[FILTERED]");
}
});
return sanitizedParams;
}