@middy/http-json-body-parser 3.0.0-alpha.2 → 3.0.0-alpha.3

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 (2) hide show
  1. package/index.js +20 -21
  2. package/package.json +6 -5
package/index.js CHANGED
@@ -1,35 +1,34 @@
1
- import { createError } from '@middy/util';
2
- const mimePattern = /^application\/(.+\+)?json(;.*)?$/;
1
+ import { createError } from '@middy/util'
2
+ const mimePattern = /^application\/(.+\+)?json(;.*)?$/
3
+
3
4
  const defaults = {
4
5
  reviver: undefined
5
- };
6
+ }
6
7
 
7
8
  const httpJsonBodyParserMiddleware = (opts = {}) => {
8
- const options = { ...defaults,
9
- ...opts
10
- };
9
+ const options = { ...defaults, ...opts }
10
+ const httpJsonBodyParserMiddlewareBefore = async (request) => {
11
+ const { headers, body } = request.event
11
12
 
12
- const httpJsonBodyParserMiddlewareBefore = async request => {
13
- const {
14
- headers,
15
- body
16
- } = request.event;
17
- const contentTypeHeader = headers['Content-Type'] ?? headers['content-type'];
13
+ const contentTypeHeader = headers['Content-Type'] ?? headers['content-type']
18
14
 
19
15
  if (mimePattern.test(contentTypeHeader)) {
20
16
  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, options.reviver);
17
+ const data = request.event.isBase64Encoded
18
+ ? Buffer.from(body, 'base64').toString()
19
+ : body
20
+
21
+ request.event.rawBody = body
22
+ request.event.body = JSON.parse(data, options.reviver)
24
23
  } catch (e) {
25
- throw createError(422, 'Content type defined as JSON but an invalid JSON was provided');
24
+ // UnprocessableEntity
25
+ throw createError(422, 'Content type defined as JSON but an invalid JSON was provided')
26
26
  }
27
27
  }
28
- };
28
+ }
29
29
 
30
30
  return {
31
31
  before: httpJsonBodyParserMiddlewareBefore
32
- };
33
- };
34
-
35
- export default httpJsonBodyParserMiddleware;
32
+ }
33
+ }
34
+ export default httpJsonBodyParserMiddleware
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-json-body-parser",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "Http JSON body parser middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -18,7 +18,8 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "test": "npm run test:unit",
21
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
22
23
  },
23
24
  "license": "MIT",
24
25
  "keywords": [
@@ -49,10 +50,10 @@
49
50
  },
50
51
  "homepage": "https://github.com/middyjs/middy#readme",
51
52
  "dependencies": {
52
- "@middy/util": "^3.0.0-alpha.2"
53
+ "@middy/util": "^3.0.0-alpha.3"
53
54
  },
54
55
  "devDependencies": {
55
- "@middy/core": "^3.0.0-alpha.2"
56
+ "@middy/core": "^3.0.0-alpha.3"
56
57
  },
57
- "gitHead": "de30419273ecbff08f367f47c7e320ec981cf145"
58
+ "gitHead": "1441158711580313765e6d156046ef0fade0d156"
58
59
  }