@middy/http-response-serializer 7.1.2 → 7.1.4

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,10 +30,23 @@
30
30
  <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-response-serializer">https://middy.js.org/docs/middlewares/http-response-serializer</a></p>
31
31
  </div>
32
32
 
33
- ## License
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install --save @middy/http-response-serializer
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-response-serializer).
34
43
 
35
- 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).
36
44
 
37
- <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
38
- <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
39
- </a>
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
+
50
+ ## License
51
+
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
@@ -2,9 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  import type middy from "@middy/core";
4
4
 
5
- interface SerializerHandler {
5
+ export interface SerializerHandler {
6
6
  regex: RegExp;
7
- serializer: (response: any) => string | { body: any; [key: string]: any };
7
+ serializer: (
8
+ response: unknown,
9
+ ) => string | { body: string; [key: string]: unknown };
8
10
  }
9
11
 
10
12
  export interface Options {
@@ -12,6 +14,8 @@ export interface Options {
12
14
  defaultContentType?: string;
13
15
  }
14
16
 
15
- declare function httpResponseSerializer(options?: Options): middy.MiddlewareObj;
17
+ declare function httpResponseSerializer(
18
+ options?: Options,
19
+ ): middy.MiddlewareObj<unknown, unknown, Error>;
16
20
 
17
21
  export default httpResponseSerializer;
package/index.js CHANGED
@@ -9,7 +9,7 @@ const defaults = {
9
9
 
10
10
  const httpResponseSerializerMiddleware = (opts = {}) => {
11
11
  const { serializers, defaultContentType } = { ...defaults, ...opts };
12
- const httpResponseSerializerMiddlewareAfter = async (request) => {
12
+ const httpResponseSerializerMiddlewareAfter = (request) => {
13
13
  normalizeHttpResponse(request);
14
14
 
15
15
  // skip serialization when Content-Type or content-type is already set
@@ -26,8 +26,7 @@ const httpResponseSerializerMiddleware = (opts = {}) => {
26
26
  defaultContentType,
27
27
  ];
28
28
 
29
- for (const type of types) {
30
- let breakTypes;
29
+ outerLoop: for (const type of types) {
31
30
  for (const s of serializers) {
32
31
  s.regex.lastIndex = 0;
33
32
  if (!s.regex.test(type)) {
@@ -43,16 +42,14 @@ const httpResponseSerializerMiddleware = (opts = {}) => {
43
42
  request.response.body = result;
44
43
  }
45
44
 
46
- breakTypes = true;
47
- break;
45
+ break outerLoop;
48
46
  }
49
- if (breakTypes) break;
50
47
  }
51
48
  };
52
49
 
53
- const httpResponseSerializerMiddlewareOnError = async (request) => {
54
- if (request.response === undefined) return;
55
- await httpResponseSerializerMiddlewareAfter(request);
50
+ const httpResponseSerializerMiddlewareOnError = (request) => {
51
+ if (typeof request.response === "undefined") return;
52
+ httpResponseSerializerMiddlewareAfter(request);
56
53
  };
57
54
  return {
58
55
  after: httpResponseSerializerMiddlewareAfter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-response-serializer",
3
- "version": "7.1.2",
3
+ "version": "7.1.4",
4
4
  "description": "HTTP response serializer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -68,11 +68,11 @@
68
68
  "url": "https://github.com/sponsors/willfarrell"
69
69
  },
70
70
  "dependencies": {
71
- "@middy/util": "7.1.2"
71
+ "@middy/util": "7.1.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@middy/core": "7.1.2",
75
- "@types/aws-lambda": "^8.0.0"
76
- },
77
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
74
+ "@middy/core": "7.1.4",
75
+ "@types/aws-lambda": "^8.0.0",
76
+ "@types/node": "^22.0.0"
77
+ }
78
78
  }