@middy/http-multipart-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-multipart-body-parser">https://middy.js.org/docs/middlewares/http-multipart-body-parser</a></p>
31
31
  </div>
32
32
 
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install --save @middy/http-multipart-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-multipart-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
@@ -6,7 +6,7 @@ import type { JsonValue } from "type-fest";
6
6
 
7
7
  export interface Options {
8
8
  busboy?: {
9
- headers?: any;
9
+ headers?: Record<string, string>;
10
10
  highWaterMark?: number;
11
11
  fileHwm?: number;
12
12
  defCharset?: string;
@@ -22,6 +22,7 @@ export interface Options {
22
22
  };
23
23
  };
24
24
  charset?: string;
25
+ disableContentTypeCheck?: boolean;
25
26
  disableContentTypeError?: boolean;
26
27
  }
27
28
 
@@ -31,6 +32,6 @@ export type Event = Omit<APIGatewayEvent, "body"> & {
31
32
 
32
33
  declare function multipartBodyParser(
33
34
  options?: Options,
34
- ): middy.MiddlewareObj<Event>;
35
+ ): middy.MiddlewareObj<Event, unknown, Error>;
35
36
 
36
37
  export default multipartBodyParser;
package/index.js CHANGED
@@ -4,25 +4,26 @@ import BusBoy from "@fastify/busboy";
4
4
  import { createError } from "@middy/util";
5
5
 
6
6
  const mimePattern =
7
- /^multipart\/form-data; boundary=[a-zA-Z0-9-]{1,70}(; ?[cC]harset=[\w-]+)?$/;
7
+ /^multipart\/form-data; boundary=[a-zA-Z0-9-]{1,70}(; ?charset=[\w-]+)?$/i;
8
8
  const fieldnamePattern = /(.+)\[(.*)]$/;
9
9
 
10
10
  const defaults = {
11
11
  // busboy options as per documentation: https://www.npmjs.com/package/busboy#busboy-methods
12
12
  busboy: {},
13
13
  charset: "utf8",
14
+ disableContentTypeCheck: false,
14
15
  disableContentTypeError: false,
15
16
  };
16
17
 
17
18
  const httpMultipartBodyParserMiddleware = (opts = {}) => {
18
19
  const options = { ...defaults, ...opts };
19
20
 
20
- const httpMultipartBodyParserMiddlewareBefore = async (request) => {
21
+ const httpMultipartBodyParserMiddlewareBefore = (request) => {
21
22
  const { headers, body } = request.event;
22
23
 
23
24
  const contentType = headers?.["content-type"] ?? headers?.["Content-Type"];
24
25
 
25
- if (!mimePattern.test(contentType)) {
26
+ if (!options.disableContentTypeCheck && !mimePattern.test(contentType)) {
26
27
  if (options.disableContentTypeError) {
27
28
  return;
28
29
  }
@@ -36,7 +37,7 @@ const httpMultipartBodyParserMiddleware = (opts = {}) => {
36
37
 
37
38
  if (typeof body === "undefined") {
38
39
  throw createError(
39
- 415,
40
+ 422,
40
41
  "Invalid or malformed multipart/form-data was provided",
41
42
  { cause: { package: "@middy/http-multipart-body-parser", data: body } },
42
43
  );
@@ -44,13 +45,12 @@ const httpMultipartBodyParserMiddleware = (opts = {}) => {
44
45
 
45
46
  return parseMultipartData(request.event, options)
46
47
  .then((multipartData) => {
47
- // request.event.rawBody = body
48
48
  request.event.body = multipartData;
49
49
  })
50
50
  .catch((err) => {
51
51
  // UnprocessableEntity
52
52
  throw createError(
53
- 415,
53
+ 422,
54
54
  "Invalid or malformed multipart/form-data was provided",
55
55
  {
56
56
  cause: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-multipart-body-parser",
3
- "version": "7.1.1",
3
+ "version": "7.1.3",
4
4
  "description": "HTTP multipart body parser middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -66,12 +66,12 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@fastify/busboy": "3.2.0",
69
- "@middy/util": "7.1.1"
69
+ "@middy/util": "7.1.3"
70
70
  },
71
71
  "devDependencies": {
72
- "@middy/core": "7.1.1",
72
+ "@middy/core": "7.1.3",
73
73
  "@types/aws-lambda": "^8.0.0",
74
+ "@types/node": "^22.0.0",
74
75
  "type-fest": "^5.0.0"
75
- },
76
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
76
+ }
77
77
  }