@middy/http-partial-response 3.0.0-alpha.3 → 3.0.0-alpha.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.
Files changed (2) hide show
  1. package/index.js +27 -25
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,32 +1,34 @@
1
- import mask from 'json-mask'
2
- import { normalizeHttpResponse, jsonSafeParse } from '@middy/util'
3
-
1
+ import mask from 'json-mask';
2
+ import { normalizeHttpResponse, jsonSafeParse } from '@middy/util';
4
3
  const defaults = {
5
4
  filteringKeyName: 'fields'
6
- }
5
+ };
7
6
 
8
7
  const httpPartialResponseMiddleware = (opts = {}) => {
9
- const options = { ...defaults, ...opts }
10
- const { filteringKeyName } = options
11
-
12
- const httpPartialResponseMiddlewareAfter = async (request) => {
13
- const fields = request.event?.queryStringParameters?.[filteringKeyName]
14
- if (!fields) return
15
-
16
- normalizeHttpResponse(request)
17
- const body = request.response.body
18
- const bodyIsString = typeof body === 'string'
19
-
20
- const parsedBody = jsonSafeParse(body)
21
- if (typeof parsedBody !== 'object') return
22
-
23
- const filteredBody = mask(parsedBody, fields)
24
-
25
- request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody
26
- }
8
+ const options = { ...defaults,
9
+ ...opts
10
+ };
11
+ const {
12
+ filteringKeyName
13
+ } = options;
14
+
15
+ const httpPartialResponseMiddlewareAfter = async request => {
16
+ var _request$event, _request$event$queryS;
17
+
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];
19
+ if (!fields) return;
20
+ normalizeHttpResponse(request);
21
+ const body = request.response.body;
22
+ const bodyIsString = typeof body === 'string';
23
+ const parsedBody = jsonSafeParse(body);
24
+ if (typeof parsedBody !== 'object') return;
25
+ const filteredBody = mask(parsedBody, fields);
26
+ request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody;
27
+ };
27
28
 
28
29
  return {
29
30
  after: httpPartialResponseMiddlewareAfter
30
- }
31
- }
32
- export default httpPartialResponseMiddleware
31
+ };
32
+ };
33
+
34
+ export default httpPartialResponseMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-partial-response",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.4",
4
4
  "description": "Http partial response middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -49,11 +49,11 @@
49
49
  },
50
50
  "homepage": "https://github.com/middyjs/middy#readme",
51
51
  "dependencies": {
52
- "@middy/util": "^3.0.0-alpha.3",
52
+ "@middy/util": "^3.0.0-alpha.4",
53
53
  "json-mask": "1.0.4"
54
54
  },
55
- "gitHead": "1441158711580313765e6d156046ef0fade0d156",
55
+ "gitHead": "d4bea7f4e21f6a9bbb1f6f6908361169598b9e53",
56
56
  "devDependencies": {
57
- "@middy/core": "^3.0.0-alpha.3"
57
+ "@middy/core": "^3.0.0-alpha.4"
58
58
  }
59
59
  }