/************************************************************************* * * Troven CONFIDENTIAL * __________________ * * (c) 2017-2020 Troven Ventures Pty Ltd * All Rights Reserved. * * NOTICE: All information contained herein is, and remains * the property of Troven Pty Ltd and its licensors, * if any. The intellectual and technical concepts contained * herein are proprietary to Troven Pty Ltd * and its suppliers and may be covered by International and Regional Patents, * patents in process, and are protected by trade secret or copyright law. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from Troven Pty Ltd. */ import { IOperation, IChassisPolicy } from "../interfaces"; import { Request, Response } from "express"; import { NextFunction } from "connect"; import * as _ from "lodash"; const IGNORED_HEADERS = ["authorization"]; export default class debug implements IChassisPolicy { name = "api.debug"; title = "Audit-only debug policy"; fn(operation: IOperation, _options: any): Function { let options = _options as any; let pkg = operation.context.pkg; operation.context.log({ code: "api:debug", options: options }); return function (req: Request, _res: Response, next: NextFunction) { let log = { uuid: operation.context.uuid, name: pkg.name, version: pkg.version, method: req.method, path: req.path, params: req.params, query: req.query, headers: _.omit(req.headers, IGNORED_HEADERS), body: options.body ? req.body : "-disabled-", code: "api:request:debug", message: operation.actionId, }; operation.context.log(log); if (options.echo) { _res.send(log); } else { next(); } }; } }