@middy/input-output-logger 7.0.0-alpha.2 → 7.0.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/index.d.ts +2 -1
- package/index.js +29 -18
- package/package.json +6 -3
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { Transform } from "node:stream";
|
|
2
2
|
import { TransformStream } from "node:stream/web";
|
|
3
|
+
import {
|
|
4
|
+
executionContextKeys,
|
|
5
|
+
isExecutionModeDurable,
|
|
6
|
+
lambdaContextKeys,
|
|
7
|
+
} from "@middy/util";
|
|
3
8
|
|
|
4
9
|
const defaults = {
|
|
5
10
|
logger: (message) => {
|
|
6
11
|
console.log(JSON.stringify(message));
|
|
7
12
|
},
|
|
8
|
-
|
|
13
|
+
executionContext: false,
|
|
14
|
+
lambdaContext: false,
|
|
9
15
|
omitPaths: [],
|
|
10
16
|
mask: undefined,
|
|
11
17
|
};
|
|
12
18
|
|
|
13
19
|
const inputOutputLoggerMiddleware = (opts = {}) => {
|
|
14
|
-
const { logger,
|
|
20
|
+
const { logger, executionContext, lambdaContext, omitPaths, mask } = {
|
|
15
21
|
...defaults,
|
|
16
22
|
...opts,
|
|
17
23
|
};
|
|
@@ -29,8 +35,27 @@ const inputOutputLoggerMiddleware = (opts = {}) => {
|
|
|
29
35
|
const omitAndLog = (param, request) => {
|
|
30
36
|
const message = { [param]: request[param] };
|
|
31
37
|
|
|
32
|
-
if (
|
|
33
|
-
|
|
38
|
+
if (executionContext) {
|
|
39
|
+
if (isExecutionModeDurable(request.context)) {
|
|
40
|
+
message.context ??= {};
|
|
41
|
+
message.context.executionContext = pick(
|
|
42
|
+
request.context.executionContext,
|
|
43
|
+
executionContextKeys,
|
|
44
|
+
);
|
|
45
|
+
} else {
|
|
46
|
+
message.context = pick(request.context, executionContextKeys);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (lambdaContext) {
|
|
50
|
+
if (isExecutionModeDurable(request.context)) {
|
|
51
|
+
message.context ??= {};
|
|
52
|
+
message.context.lambdaContext = pick(
|
|
53
|
+
request.context.lambdaContext,
|
|
54
|
+
lambdaContextKeys,
|
|
55
|
+
);
|
|
56
|
+
} else {
|
|
57
|
+
message.context = pick(request.context, lambdaContextKeys);
|
|
58
|
+
}
|
|
34
59
|
}
|
|
35
60
|
|
|
36
61
|
let cloneMessage = message;
|
|
@@ -95,20 +120,6 @@ const inputOutputLoggerMiddleware = (opts = {}) => {
|
|
|
95
120
|
};
|
|
96
121
|
};
|
|
97
122
|
|
|
98
|
-
// https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
|
|
99
|
-
const awsContextKeys = [
|
|
100
|
-
"functionName",
|
|
101
|
-
"functionVersion",
|
|
102
|
-
"invokedFunctionArn",
|
|
103
|
-
"memoryLimitInMB",
|
|
104
|
-
"awsRequestId",
|
|
105
|
-
"logGroupName",
|
|
106
|
-
"logStreamName",
|
|
107
|
-
"identity",
|
|
108
|
-
"clientContext",
|
|
109
|
-
"callbackWaitsForEmptyEventLoop",
|
|
110
|
-
];
|
|
111
|
-
|
|
112
123
|
// move to util, if ever used elsewhere
|
|
113
124
|
const pick = (originalObject = {}, keysToPick = []) => {
|
|
114
125
|
const newObject = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/input-output-logger",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Input and output logger middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -63,9 +63,12 @@
|
|
|
63
63
|
"type": "github",
|
|
64
64
|
"url": "https://github.com/sponsors/willfarrell"
|
|
65
65
|
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@middy/util": "7.0.0"
|
|
68
|
+
},
|
|
66
69
|
"devDependencies": {
|
|
67
|
-
"@datastream/core": "0.0.
|
|
68
|
-
"@middy/core": "7.0.0
|
|
70
|
+
"@datastream/core": "0.0.42",
|
|
71
|
+
"@middy/core": "7.0.0",
|
|
69
72
|
"@types/node": "^22.0.0"
|
|
70
73
|
},
|
|
71
74
|
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|