@middy/input-output-logger 2.5.1 → 3.0.0-alpha.0
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 +1 -1
- package/README.md +1 -1
- package/package.json +7 -7
- package/index.js +0 -85
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
3
|
+
Copyright (c) 2017-2022 Luciano Mammino, will Farrell 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
|
@@ -98,7 +98,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
98
98
|
|
|
99
99
|
## License
|
|
100
100
|
|
|
101
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
101
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
102
102
|
|
|
103
103
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
104
104
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/input-output-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "Input and output logger middleware for the middy framework",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=14"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"exports": "./index.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"index.d.ts"
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@middy/core": "^
|
|
50
|
-
"@types/node": "^
|
|
49
|
+
"@middy/core": "^3.0.0-alpha.0",
|
|
50
|
+
"@types/node": "^17.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db"
|
|
53
53
|
}
|
package/index.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const defaults = {
|
|
4
|
-
logger: data => console.log(JSON.stringify(data, null, 2)),
|
|
5
|
-
awsContext: false,
|
|
6
|
-
omitPaths: []
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const inputOutputLoggerMiddleware = (opts = {}) => {
|
|
10
|
-
let {
|
|
11
|
-
logger,
|
|
12
|
-
awsContext,
|
|
13
|
-
omitPaths
|
|
14
|
-
} = { ...defaults,
|
|
15
|
-
...opts
|
|
16
|
-
};
|
|
17
|
-
if (typeof logger !== 'function') logger = null;
|
|
18
|
-
|
|
19
|
-
const omitAndLog = (param, request) => {
|
|
20
|
-
const message = {
|
|
21
|
-
[param]: request[param]
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (awsContext) {
|
|
25
|
-
message.context = pick(request.context, awsContextKeys);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const redactedMessage = omit(JSON.parse(JSON.stringify(message)), omitPaths); // Full clone to prevent nested mutations
|
|
29
|
-
|
|
30
|
-
logger(redactedMessage);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const inputOutputLoggerMiddlewareBefore = async request => omitAndLog('event', request);
|
|
34
|
-
|
|
35
|
-
const inputOutputLoggerMiddlewareAfter = async request => omitAndLog('response', request);
|
|
36
|
-
|
|
37
|
-
const inputOutputLoggerMiddlewareOnError = inputOutputLoggerMiddlewareAfter;
|
|
38
|
-
return {
|
|
39
|
-
before: logger ? inputOutputLoggerMiddlewareBefore : undefined,
|
|
40
|
-
after: logger ? inputOutputLoggerMiddlewareAfter : undefined,
|
|
41
|
-
onError: logger ? inputOutputLoggerMiddlewareOnError : undefined
|
|
42
|
-
};
|
|
43
|
-
}; // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const awsContextKeys = ['functionName', 'functionVersion', 'invokedFunctionArn', 'memoryLimitInMB', 'awsRequestId', 'logGroupName', 'logStreamName', 'identity', 'clientContext', 'callbackWaitsForEmptyEventLoop']; // move to util, if ever used elsewhere
|
|
47
|
-
|
|
48
|
-
const pick = (originalObject = {}, keysToPick = []) => {
|
|
49
|
-
const newObject = {};
|
|
50
|
-
|
|
51
|
-
for (const path of keysToPick) {
|
|
52
|
-
// only supports first level
|
|
53
|
-
if (originalObject[path] !== undefined) {
|
|
54
|
-
newObject[path] = originalObject[path];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return newObject;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const omit = (originalObject = {}, keysToOmit = []) => {
|
|
62
|
-
const clonedObject = { ...originalObject
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
for (const path of keysToOmit) {
|
|
66
|
-
deleteKey(clonedObject, path);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return clonedObject;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const deleteKey = (obj, key) => {
|
|
73
|
-
if (!Array.isArray(key)) key = key.split('.');
|
|
74
|
-
const rootKey = key.shift();
|
|
75
|
-
|
|
76
|
-
if (key.length && obj[rootKey]) {
|
|
77
|
-
deleteKey(obj[rootKey], key);
|
|
78
|
-
} else {
|
|
79
|
-
delete obj[rootKey];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return obj;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
module.exports = inputOutputLoggerMiddleware;
|