@middy/http-json-body-parser 2.5.3 → 3.0.0-alpha.2
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 +5 -2
- package/index.js +4 -12
- package/package.json +8 -8
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
|
@@ -53,13 +53,16 @@ npm install --save @middy/http-json-body-parser
|
|
|
53
53
|
|
|
54
54
|
```javascript
|
|
55
55
|
import middy from '@middy/core'
|
|
56
|
+
import httpHeaderNormalizer from '@middy/http-header-normalizer'
|
|
56
57
|
import httpJsonBodyParser from '@middy/http-json-body-parser'
|
|
57
58
|
|
|
58
59
|
const handler = middy((event, context) => {
|
|
59
60
|
return {}
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
handler
|
|
63
|
+
handler
|
|
64
|
+
.use(httpHeaderNormalizer())
|
|
65
|
+
.use(httpJsonBodyParser())
|
|
63
66
|
|
|
64
67
|
// invokes the handler
|
|
65
68
|
const event = {
|
|
@@ -86,7 +89,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
86
89
|
|
|
87
90
|
## License
|
|
88
91
|
|
|
89
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
92
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
90
93
|
|
|
91
94
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
92
95
|
<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.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createError } from '@middy/util';
|
|
3
2
|
const mimePattern = /^application\/(.+\+)?json(;.*)?$/;
|
|
4
3
|
const defaults = {
|
|
5
4
|
reviver: undefined
|
|
@@ -11,25 +10,18 @@ const httpJsonBodyParserMiddleware = (opts = {}) => {
|
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
const httpJsonBodyParserMiddlewareBefore = async request => {
|
|
14
|
-
var _headers$ContentType;
|
|
15
|
-
|
|
16
13
|
const {
|
|
17
14
|
headers,
|
|
18
15
|
body
|
|
19
16
|
} = request.event;
|
|
20
|
-
const contentTypeHeader =
|
|
17
|
+
const contentTypeHeader = headers['Content-Type'] ?? headers['content-type'];
|
|
21
18
|
|
|
22
19
|
if (mimePattern.test(contentTypeHeader)) {
|
|
23
20
|
try {
|
|
24
21
|
const data = request.event.isBase64Encoded ? Buffer.from(body, 'base64').toString() : body;
|
|
25
22
|
request.event.rawBody = body;
|
|
26
23
|
request.event.body = JSON.parse(data, options.reviver);
|
|
27
|
-
} catch (
|
|
28
|
-
const {
|
|
29
|
-
createError
|
|
30
|
-
} = require('@middy/util'); // UnprocessableEntity
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
} catch (e) {
|
|
33
25
|
throw createError(422, 'Content type defined as JSON but an invalid JSON was provided');
|
|
34
26
|
}
|
|
35
27
|
}
|
|
@@ -40,4 +32,4 @@ const httpJsonBodyParserMiddleware = (opts = {}) => {
|
|
|
40
32
|
};
|
|
41
33
|
};
|
|
42
34
|
|
|
43
|
-
|
|
35
|
+
export default httpJsonBodyParserMiddleware;
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-json-body-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"description": "Http JSON body parser 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
|
+
"index.js",
|
|
16
17
|
"index.d.ts"
|
|
17
18
|
],
|
|
18
19
|
"scripts": {
|
|
@@ -48,11 +49,10 @@
|
|
|
48
49
|
},
|
|
49
50
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@middy/util": "^
|
|
52
|
+
"@middy/util": "^3.0.0-alpha.2"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@middy/core": "^
|
|
55
|
-
"http-errors": "^1.8.0"
|
|
55
|
+
"@middy/core": "^3.0.0-alpha.2"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "de30419273ecbff08f367f47c7e320ec981cf145"
|
|
58
58
|
}
|