@middy/http-json-body-parser 2.5.6 → 2.5.7

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 +28 -20
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,35 +1,43 @@
1
- const mimePattern = /^application\/(.+\+)?json(;.*)?$/
1
+ "use strict";
2
2
 
3
+ const mimePattern = /^application\/(.+\+)?json(;.*)?$/;
3
4
  const defaults = {
4
5
  reviver: undefined
5
- }
6
+ };
6
7
 
7
8
  const httpJsonBodyParserMiddleware = (opts = {}) => {
8
- const options = { ...defaults, ...opts }
9
- const httpJsonBodyParserMiddlewareBefore = async (request) => {
10
- const { headers, body } = request.event
9
+ const options = { ...defaults,
10
+ ...opts
11
+ };
11
12
 
12
- const contentTypeHeader =
13
- headers?.['Content-Type'] ?? headers?.['content-type']
13
+ const httpJsonBodyParserMiddlewareBefore = async request => {
14
+ var _headers$ContentType;
15
+
16
+ const {
17
+ headers,
18
+ body
19
+ } = request.event;
20
+ const contentTypeHeader = (_headers$ContentType = headers === null || headers === void 0 ? void 0 : headers['Content-Type']) !== null && _headers$ContentType !== void 0 ? _headers$ContentType : headers === null || headers === void 0 ? void 0 : headers['content-type'];
14
21
 
15
22
  if (mimePattern.test(contentTypeHeader)) {
16
23
  try {
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
+ const data = request.event.isBase64Encoded ? Buffer.from(body, 'base64').toString() : body;
25
+ request.event.rawBody = body;
26
+ request.event.body = JSON.parse(data, options.reviver);
23
27
  } catch (err) {
24
- const { createError } = require('@middy/util')
25
- // UnprocessableEntity
26
- throw createError(422, 'Content type defined as JSON but an invalid JSON was provided')
28
+ const {
29
+ createError
30
+ } = require('@middy/util'); // UnprocessableEntity
31
+
32
+
33
+ throw createError(422, 'Content type defined as JSON but an invalid JSON was provided');
27
34
  }
28
35
  }
29
- }
36
+ };
30
37
 
31
38
  return {
32
39
  before: httpJsonBodyParserMiddlewareBefore
33
- }
34
- }
35
- module.exports = httpJsonBodyParserMiddleware
40
+ };
41
+ };
42
+
43
+ module.exports = httpJsonBodyParserMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-json-body-parser",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
4
4
  "description": "Http JSON body parser middleware for the middy framework",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -48,10 +48,10 @@
48
48
  },
49
49
  "homepage": "https://github.com/middyjs/middy#readme",
50
50
  "dependencies": {
51
- "@middy/util": "^2.5.6"
51
+ "@middy/util": "^2.5.7"
52
52
  },
53
53
  "devDependencies": {
54
- "@middy/core": "^2.5.6"
54
+ "@middy/core": "^2.5.7"
55
55
  },
56
- "gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b"
56
+ "gitHead": "3983c4b138e1a4d7fcb3ed805d3b8832fff06fc1"
57
57
  }