@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
39 lines (38 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processApiRequestWithoutMasking = exports.processApiRequest = void 0;
const app_config_1 = require("../app.config");
const mask_sensitive_info_1 = require("../plugins/mask-sensitive-info");
const activity_log_1 = require("./activity-log");
const processApiRequest = (executor) => async (req, res, next) => {
try {
let result = await executor(req.body);
// mask sensitive information before responding (only for data which the current user doesn't own):
if (!app_config_1.Config.SHARE_RESOURCE_CREDENTIAL && req.user)
result.data = (0, mask_sensitive_info_1.maskSensitiveInfo)(result.data, req.user, req.role, req.baseUrl);
// save activity log here...
(0, activity_log_1.saveActivityLog)(req, res, next);
// respond data...
res.status(200).json(result);
}
catch (e) {
console.error(e);
// forward the error to Express.js Error Handling Route
next(e);
}
};
exports.processApiRequest = processApiRequest;
const processApiRequestWithoutMasking = (executor) => async (req, res, next) => {
try {
let result = await executor(req.body);
// save activity log here...
(0, activity_log_1.saveActivityLog)(req, res, next);
// respond data...
res.status(200).json(result);
}
catch (e) {
// forward the error to Express.js Error Handling Route
next(e);
}
};
exports.processApiRequestWithoutMasking = processApiRequestWithoutMasking;