@middy/http-json-body-parser 3.1.0 → 3.1.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.
- package/index.cjs +11 -12
- package/index.js +11 -12
- package/package.json +5 -4
package/index.cjs
CHANGED
|
@@ -9,23 +9,22 @@ const defaults = {
|
|
|
9
9
|
reviver: undefined
|
|
10
10
|
};
|
|
11
11
|
const httpJsonBodyParserMiddleware = (opts = {})=>{
|
|
12
|
-
const
|
|
12
|
+
const { reviver } = {
|
|
13
13
|
...defaults,
|
|
14
14
|
...opts
|
|
15
15
|
};
|
|
16
16
|
const httpJsonBodyParserMiddlewareBefore = async (request)=>{
|
|
17
17
|
const { headers , body } = request.event;
|
|
18
|
-
const
|
|
19
|
-
if (mimePattern.test(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
18
|
+
const contentType = headers['Content-Type'] ?? headers['content-type'];
|
|
19
|
+
if (!mimePattern.test(contentType)) return;
|
|
20
|
+
try {
|
|
21
|
+
const data = request.event.isBase64Encoded ? Buffer.from(body, 'base64').toString() : body;
|
|
22
|
+
request.event.rawBody = body;
|
|
23
|
+
request.event.body = JSON.parse(data, reviver);
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
const error = (0, _util).createError(422, 'Invalid or malformed JSON was provided');
|
|
26
|
+
error.cause = cause;
|
|
27
|
+
throw error;
|
|
29
28
|
}
|
|
30
29
|
};
|
|
31
30
|
return {
|
package/index.js
CHANGED
|
@@ -4,23 +4,22 @@ const defaults = {
|
|
|
4
4
|
reviver: undefined
|
|
5
5
|
};
|
|
6
6
|
const httpJsonBodyParserMiddleware = (opts = {})=>{
|
|
7
|
-
const
|
|
7
|
+
const { reviver } = {
|
|
8
8
|
...defaults,
|
|
9
9
|
...opts
|
|
10
10
|
};
|
|
11
11
|
const httpJsonBodyParserMiddlewareBefore = async (request)=>{
|
|
12
12
|
const { headers , body } = request.event;
|
|
13
|
-
const
|
|
14
|
-
if (mimePattern.test(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
13
|
+
const contentType = headers['Content-Type'] ?? headers['content-type'];
|
|
14
|
+
if (!mimePattern.test(contentType)) return;
|
|
15
|
+
try {
|
|
16
|
+
const data = request.event.isBase64Encoded ? Buffer.from(body, 'base64').toString() : body;
|
|
17
|
+
request.event.rawBody = body;
|
|
18
|
+
request.event.body = JSON.parse(data, reviver);
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
const error = createError(422, 'Invalid or malformed JSON was provided');
|
|
21
|
+
error.cause = cause;
|
|
22
|
+
throw error;
|
|
24
23
|
}
|
|
25
24
|
};
|
|
26
25
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-json-body-parser",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Http JSON body parser middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"main": "./index.cjs",
|
|
14
|
+
"module": "./index.js",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": {
|
|
@@ -63,10 +64,10 @@
|
|
|
63
64
|
},
|
|
64
65
|
"homepage": "https://middy.js.org",
|
|
65
66
|
"dependencies": {
|
|
66
|
-
"@middy/util": "3.1.
|
|
67
|
+
"@middy/util": "3.1.1"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@middy/core": "3.1.
|
|
70
|
+
"@middy/core": "3.1.1"
|
|
70
71
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "d53fc91d035b01d3fd296cb6c7d0acd8305e9f76"
|
|
72
73
|
}
|