@middy/input-output-logger 7.2.3 → 7.3.1

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.
Files changed (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +28 -11
  3. package/package.json +4 -7
package/index.d.ts CHANGED
@@ -14,4 +14,8 @@ declare function inputOutputLogger(
14
14
  options?: Options,
15
15
  ): middy.MiddlewareObj<unknown, unknown, Error>;
16
16
 
17
+ export declare function inputOutputLoggerValidateOptions(
18
+ options?: Record<string, unknown>,
19
+ ): void;
20
+
17
21
  export default inputOutputLogger;
package/index.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  executionContextKeys,
8
8
  isExecutionModeDurable,
9
9
  lambdaContextKeys,
10
+ validateOptions,
10
11
  } from "@middy/util";
11
12
 
12
13
  const defaults = {
@@ -19,20 +20,27 @@ const defaults = {
19
20
  mask: undefined,
20
21
  };
21
22
 
23
+ const optionSchema = {
24
+ type: "object",
25
+ properties: {
26
+ logger: { oneOf: [{ instanceof: "Function" }, { const: false }] },
27
+ executionContext: { type: "boolean" },
28
+ lambdaContext: { type: "boolean" },
29
+ omitPaths: { type: "array", items: { type: "string" } },
30
+ mask: { type: "string" },
31
+ },
32
+ additionalProperties: false,
33
+ };
34
+
35
+ export const inputOutputLoggerValidateOptions = (options) =>
36
+ validateOptions("@middy/input-output-logger", optionSchema, options);
37
+
22
38
  const inputOutputLoggerMiddleware = (opts = {}) => {
23
39
  const { logger, executionContext, lambdaContext, omitPaths, mask } = {
24
40
  ...defaults,
25
41
  ...opts,
26
42
  };
27
43
 
28
- if (typeof logger !== "function") {
29
- throw new Error("logger must be a function", {
30
- cause: {
31
- package: "@middy/input-output-logger",
32
- },
33
- });
34
- }
35
-
36
44
  const omitPathTree = buildPathTree(omitPaths);
37
45
  // needs `omitPathTree`, `logger`
38
46
  const omitAndLog = (param, request) => {
@@ -119,9 +127,18 @@ const inputOutputLoggerMiddleware = (opts = {}) => {
119
127
  };
120
128
 
121
129
  return {
122
- before: inputOutputLoggerMiddlewareBefore,
123
- after: inputOutputLoggerMiddlewareAfter,
124
- onError: inputOutputLoggerMiddlewareOnError,
130
+ before:
131
+ typeof logger === "function"
132
+ ? inputOutputLoggerMiddlewareBefore
133
+ : undefined,
134
+ after:
135
+ typeof logger === "function"
136
+ ? inputOutputLoggerMiddlewareAfter
137
+ : undefined,
138
+ onError:
139
+ typeof logger === "function"
140
+ ? inputOutputLoggerMiddlewareOnError
141
+ : undefined,
125
142
  };
126
143
  };
127
144
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/input-output-logger",
3
- "version": "7.2.3",
3
+ "version": "7.3.1",
4
4
  "description": "Input and output logger middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -17,9 +17,6 @@
17
17
  "import": {
18
18
  "types": "./index.d.ts",
19
19
  "default": "./index.js"
20
- },
21
- "require": {
22
- "default": "./index.js"
23
20
  }
24
21
  }
25
22
  },
@@ -65,11 +62,11 @@
65
62
  "url": "https://github.com/sponsors/willfarrell"
66
63
  },
67
64
  "dependencies": {
68
- "@middy/util": "7.2.3"
65
+ "@middy/util": "7.3.1"
69
66
  },
70
67
  "devDependencies": {
71
- "@datastream/core": "0.1.6",
72
- "@middy/core": "7.2.3",
68
+ "@datastream/core": "0.4.0",
69
+ "@middy/core": "7.3.1",
73
70
  "@types/aws-lambda": "^8.0.0",
74
71
  "@types/node": "^22.0.0"
75
72
  }