@middy/http-json-body-parser 7.1.1 → 7.1.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.
package/README.md CHANGED
@@ -30,6 +30,23 @@
30
30
  <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-json-body-parser">https://middy.js.org/docs/middlewares/http-json-body-parser</a></p>
31
31
  </div>
32
32
 
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install --save @middy/http-json-body-parser
37
+ ```
38
+
39
+
40
+ ## Documentation and examples
41
+
42
+ For documentation and examples, refer to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org/docs/middlewares/http-json-body-parser).
43
+
44
+
45
+ ## Contributing
46
+
47
+ Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
48
+
49
+
33
50
  ## License
34
51
 
35
52
  Licensed under [MIT License](LICENSE). Copyright (c) 2017-2026 [will Farrell](https://github.com/willfarrell), [Luciano Mammino](https://github.com/lmammino), and [Middy contributors](https://github.com/middyjs/middy/graphs/contributors).
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import type {
8
8
  } from "aws-lambda";
9
9
 
10
10
  export interface Options {
11
- reviver?: (key: string, value: any) => any;
11
+ reviver?: (key: string, value: unknown) => unknown;
12
12
  disableContentTypeCheck?: boolean;
13
13
  disableContentTypeError?: boolean;
14
14
  }
@@ -17,6 +17,6 @@ export type RequestEvent = APIGatewayEvent | APIGatewayProxyEventV2 | ALBEvent;
17
17
 
18
18
  declare function jsonBodyParser<EventType extends RequestEvent = RequestEvent>(
19
19
  options?: Options,
20
- ): middy.MiddlewareObj<EventType>;
20
+ ): middy.MiddlewareObj<EventType, unknown, Error>;
21
21
 
22
22
  export default jsonBodyParser;
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
2
2
  // SPDX-License-Identifier: MIT
3
- import { createError } from "@middy/util";
3
+ import { createError, decodeBody } from "@middy/util";
4
4
 
5
- const mimePattern = /^application\/(.+\+)?json($|;.+)/;
5
+ const jsonContentTypePattern = /^application\/([a-z0-9.+-]+\+)?json(;|$)/i;
6
6
 
7
7
  const defaults = {
8
8
  reviver: undefined,
@@ -12,11 +12,14 @@ const defaults = {
12
12
 
13
13
  const httpJsonBodyParserMiddleware = (opts = {}) => {
14
14
  const options = { ...defaults, ...opts };
15
- const httpJsonBodyParserMiddlewareBefore = async (request) => {
15
+ const httpJsonBodyParserMiddlewareBefore = (request) => {
16
16
  const { headers, body } = request.event;
17
17
  const contentType = headers?.["content-type"] ?? headers?.["Content-Type"];
18
18
 
19
- if (!options.disableContentTypeCheck && !mimePattern.test(contentType)) {
19
+ if (
20
+ !options.disableContentTypeCheck &&
21
+ !jsonContentTypePattern.test(contentType)
22
+ ) {
20
23
  if (options.disableContentTypeError) {
21
24
  return;
22
25
  }
@@ -32,9 +35,7 @@ const httpJsonBodyParserMiddleware = (opts = {}) => {
32
35
  }
33
36
 
34
37
  try {
35
- const data = request.event.isBase64Encoded
36
- ? Buffer.from(body, "base64").toString()
37
- : body;
38
+ const data = decodeBody(request.event);
38
39
 
39
40
  request.event.body = JSON.parse(data, options.reviver);
40
41
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-json-body-parser",
3
- "version": "7.1.1",
3
+ "version": "7.1.3",
4
4
  "description": "HTTP JSON body parser middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -67,12 +67,12 @@
67
67
  "url": "https://github.com/sponsors/willfarrell"
68
68
  },
69
69
  "dependencies": {
70
- "@middy/util": "7.1.1"
70
+ "@middy/util": "7.1.3"
71
71
  },
72
72
  "devDependencies": {
73
- "@middy/core": "7.1.1",
73
+ "@middy/core": "7.1.3",
74
74
  "@types/aws-lambda": "^8.0.0",
75
+ "@types/node": "^22.0.0",
75
76
  "type-fest": "^5.0.0"
76
- },
77
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
77
+ }
78
78
  }