@middy/input-output-logger 3.0.0 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell) and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  <a href="https://packagephobia.com/result?p=@middy/input-output-logger">
10
10
  <img src="https://packagephobia.com/badge?p=@middy/input-output-logger" alt="npm install size" style="max-width:100%;">
11
11
  </a>
12
- <a href="https://github.com/middyjs/middy/actions">
13
- <img src="https://github.com/middyjs/middy/workflows/Tests/badge.svg" alt="GitHub Actions test status badge" style="max-width:100%;">
12
+ <a href="https://github.com/middyjs/middy/actions/workflows/tests.yml">
13
+ <img src="https://github.com/middyjs/middy/actions/workflows/tests.yml/badge.svg?branch=main&event=push" alt="GitHub Actions CI status badge" style="max-width:100%;">
14
14
  </a>
15
15
  <br/>
16
16
  <a href="https://standardjs.com/">
@@ -33,6 +33,7 @@
33
33
  <img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
34
34
  </a>
35
35
  </p>
36
+ <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/input-output-logger">https://middy.js.org/docs/middlewares/input-output-logger</a></p>
36
37
  </div>
37
38
 
38
39
  Logs the incoming request (input) and the response (output).
@@ -54,7 +55,7 @@ npm install --save @middy/input-output-logger
54
55
  - `logger` (function) (default `console.log`): logging function that accepts an object
55
56
  - `awsContext` (boolean) (default `false`): Include [AWS Lambda context object](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html) to the logger
56
57
  - `omitPaths` (string[]) (default `[]`): property accepts an array of paths that will be used to remove particular fields import the logged objects. This could serve as a simple way to redact sensitive data from logs (default []).
57
- - `mask` (string) (default `undefined`): When set to a truthy value (i.e. `*** redacted ***`) a path is replaced instead of ommitted.
58
+ - `mask` (string) (default `undefined`): When set to a truthy value (i.e. `*** redacted ***`) a path is replaced instead of omitted.
58
59
  - `replacer` (function) (default `undefined`): A [replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters) parameter may be passed which will be used `JSON.stringify`ing the request during cloning.
59
60
 
60
61
  ## Sample usage
@@ -109,7 +110,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
109
110
 
110
111
  ## License
111
112
 
112
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
113
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
113
114
 
114
115
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
115
116
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _util=require("@middy/util");var _a,_b;const defaults={logger:console.log,awsContext:false,omitPaths:[],mask:undefined,replacer:undefined};const inputOutputLoggerMiddleware=(opts={})=>{const{logger,awsContext,omitPaths,mask,replacer}={...defaults,...opts};if(typeof logger!=="function"){throw new Error("[input-output-logger-middleware]: logger must be a function")}const omitPathTree=buildPathOmitTree(omitPaths);const omitAndLog=(param,request)=>{const message={[param]:request[param]};if(awsContext){message.context=pick(request.context,awsContextKeys)}const cloneMessage=(0,_util).jsonSafeParse((0,_util).jsonSafeStringify(message,replacer));omit(cloneMessage,{[param]:omitPathTree[param]});logger(cloneMessage)};const omit=(obj,pathTree={})=>{if(Array.isArray(obj)&&pathTree["[]"]){for(const value of obj){omit(value,pathTree["[]"])}}else if(isObject(obj)){for(const key in pathTree){if(pathTree[key]===true){if(mask){obj[key]=mask}else{delete obj[key]}}else{omit(obj[key],pathTree[key])}}}};const inputOutputLoggerMiddlewareBefore=async request=>omitAndLog("event",request);const inputOutputLoggerMiddlewareAfter=async request=>omitAndLog("response",request);const inputOutputLoggerMiddlewareOnError=async request=>{if(request.response===undefined)return;return omitAndLog("response",request)};return{before:inputOutputLoggerMiddlewareBefore,after:inputOutputLoggerMiddlewareAfter,onError:inputOutputLoggerMiddlewareOnError}};const awsContextKeys=["functionName","functionVersion","invokedFunctionArn","memoryLimitInMB","awsRequestId","logGroupName","logStreamName","identity","clientContext","callbackWaitsForEmptyEventLoop"];const pick=(originalObject={},keysToPick=[])=>{const newObject={};for(const path of keysToPick){if(originalObject[path]!==undefined){newObject[path]=originalObject[path]}}return newObject};const buildPathOmitTree=paths=>{const tree={};for(let path of paths.sort().reverse()){if(!Array.isArray(path))path=path.split(".");if(path.includes("__proto__"))continue;path.slice(0).reduce((a,b,idx)=>{if(idx<path.length-1){(_a=a)[_b=b]??(_a[_b]={});return a[b]}a[b]=true;return true},tree)}return tree};const isObject=value=>value&& typeof value==="object"&&value.constructor===Object;var _default=inputOutputLoggerMiddleware;exports.default=_default
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});module.exports=void 0;var _util=require("@middy/util");var _a,_b;const defaults={logger:console.log,awsContext:false,omitPaths:[],mask:undefined,replacer:undefined};const inputOutputLoggerMiddleware=(opts={})=>{const{logger,awsContext,omitPaths,mask,replacer}={...defaults,...opts};if(typeof logger!=="function"){throw new Error("[input-output-logger-middleware]: logger must be a function")}const omitPathTree=buildPathOmitTree(omitPaths);const omitAndLog=(param,request)=>{const message={[param]:request[param]};if(awsContext){message.context=pick(request.context,awsContextKeys)}const cloneMessage=(0,_util).jsonSafeParse((0,_util).jsonSafeStringify(message,replacer));omit(cloneMessage,{[param]:omitPathTree[param]});logger(cloneMessage)};const omit=(obj,pathTree={})=>{if(Array.isArray(obj)&&pathTree["[]"]){for(const value of obj){omit(value,pathTree["[]"])}}else if(isObject(obj)){for(const key in pathTree){if(pathTree[key]===true){if(mask){obj[key]=mask}else{delete obj[key]}}else{omit(obj[key],pathTree[key])}}}};const inputOutputLoggerMiddlewareBefore=async request=>omitAndLog("event",request);const inputOutputLoggerMiddlewareAfter=async request=>omitAndLog("response",request);const inputOutputLoggerMiddlewareOnError=async request=>{if(request.response===undefined)return;return omitAndLog("response",request)};return{before:inputOutputLoggerMiddlewareBefore,after:inputOutputLoggerMiddlewareAfter,onError:inputOutputLoggerMiddlewareOnError}};const awsContextKeys=["functionName","functionVersion","invokedFunctionArn","memoryLimitInMB","awsRequestId","logGroupName","logStreamName","identity","clientContext","callbackWaitsForEmptyEventLoop"];const pick=(originalObject={},keysToPick=[])=>{const newObject={};for(const path of keysToPick){if(originalObject[path]!==undefined){newObject[path]=originalObject[path]}}return newObject};const buildPathOmitTree=paths=>{const tree={};for(let path of paths.sort().reverse()){if(!Array.isArray(path))path=path.split(".");if(path.includes("__proto__"))continue;path.slice(0).reduce((a,b,idx)=>{if(idx<path.length-1){(_a=a)[_b=b]??(_a[_b]={});return a[b]}a[b]=true;return true},tree)}return tree};const isObject=value=>value&& typeof value==="object"&&value.constructor===Object;var _default=inputOutputLoggerMiddleware;module.exports=_default
2
2
 
3
3
  //# sourceMappingURL=index.cjs.map
package/index.d.ts CHANGED
@@ -4,6 +4,8 @@ interface Options {
4
4
  logger?: (message: any) => void
5
5
  awsContext?: boolean
6
6
  omitPaths?: string[]
7
+ mask?: string
8
+ replacer?: (this: any, key: string, value: any) => any | Array<number | string>
7
9
  }
8
10
 
9
11
  declare function inputOutputLogger (options?: Options): middy.MiddlewareObj
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/input-output-logger",
3
- "version": "3.0.0",
3
+ "version": "3.0.3",
4
4
  "description": "Input and output logger middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -55,11 +55,11 @@
55
55
  },
56
56
  "homepage": "https://middy.js.org",
57
57
  "dependencies": {
58
- "@middy/util": "^3.0.0"
58
+ "@middy/util": "3.0.3"
59
59
  },
60
60
  "devDependencies": {
61
- "@middy/core": "^3.0.0",
61
+ "@middy/core": "3.0.3",
62
62
  "@types/node": "^17.0.0"
63
63
  },
64
- "gitHead": "01520fa8628a36c2f89e126cad656a16547ea0d6"
64
+ "gitHead": "ea9e5e8cce754d0c467c7dd3ac9a7601149efea2"
65
65
  }