@middy/http-partial-response 2.5.3 → 3.0.0-alpha.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -97,7 +97,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
97
97
 
98
98
  ## License
99
99
 
100
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
100
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
101
101
 
102
102
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
103
103
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.js CHANGED
@@ -1,11 +1,5 @@
1
- "use strict";
2
-
3
- const mask = require('json-mask');
4
-
5
- const {
6
- jsonSafeParse
7
- } = require('@middy/util');
8
-
1
+ import mask from 'json-mask';
2
+ import { normalizeHttpResponse, jsonSafeParse } from '@middy/util';
9
3
  const defaults = {
10
4
  filteringKeyName: 'fields'
11
5
  };
@@ -19,16 +13,17 @@ const httpPartialResponseMiddleware = (opts = {}) => {
19
13
  } = options;
20
14
 
21
15
  const httpPartialResponseMiddlewareAfter = async request => {
22
- var _request$response, _request$event, _request$event$queryS;
16
+ var _request$event, _request$event$queryS;
23
17
 
24
- const body = (_request$response = request.response) === null || _request$response === void 0 ? void 0 : _request$response.body;
25
- if (!body) return;
26
18
  const fields = (_request$event = request.event) === null || _request$event === void 0 ? void 0 : (_request$event$queryS = _request$event.queryStringParameters) === null || _request$event$queryS === void 0 ? void 0 : _request$event$queryS[filteringKeyName];
27
19
  if (!fields) return;
20
+ normalizeHttpResponse(request);
21
+ const body = request.response.body;
22
+ const bodyIsString = typeof body === 'string';
28
23
  const parsedBody = jsonSafeParse(body);
29
24
  if (typeof parsedBody !== 'object') return;
30
25
  const filteredBody = mask(parsedBody, fields);
31
- request.response.body = typeof body === 'object' ? filteredBody : JSON.stringify(filteredBody);
26
+ request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody;
32
27
  };
33
28
 
34
29
  return {
@@ -36,4 +31,4 @@ const httpPartialResponseMiddleware = (opts = {}) => {
36
31
  };
37
32
  };
38
33
 
39
- module.exports = httpPartialResponseMiddleware;
34
+ export default httpPartialResponseMiddleware;
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@middy/http-partial-response",
3
- "version": "2.5.3",
3
+ "version": "3.0.0-alpha.2",
4
4
  "description": "Http partial response middleware for the middy framework",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
+ "index.js",
16
17
  "index.d.ts"
17
18
  ],
18
19
  "scripts": {
@@ -47,11 +48,11 @@
47
48
  },
48
49
  "homepage": "https://github.com/middyjs/middy#readme",
49
50
  "dependencies": {
50
- "@middy/util": "^2.5.3",
51
+ "@middy/util": "^3.0.0-alpha.2",
51
52
  "json-mask": "1.0.4"
52
53
  },
53
- "gitHead": "690884d43b9cd632aeca9a5eba1612160b987cd4",
54
+ "gitHead": "de30419273ecbff08f367f47c7e320ec981cf145",
54
55
  "devDependencies": {
55
- "@middy/core": "^2.5.3"
56
+ "@middy/core": "^3.0.0-alpha.2"
56
57
  }
57
58
  }