@middy/http-partial-response 5.0.0-alpha.1 → 5.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.
Files changed (2) hide show
  1. package/index.js +26 -32
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,34 +1,28 @@
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
- filteringKeyName: 'fields'
6
- }
7
-
8
- 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
26
- ? JSON.stringify(filteredBody)
27
- : filteredBody
28
- }
4
+ filteringKeyName: 'fields'
5
+ };
6
+ const httpPartialResponseMiddleware = (opts = {})=>{
7
+ const options = {
8
+ ...defaults,
9
+ ...opts
10
+ };
11
+ const { filteringKeyName } = options;
12
+ const httpPartialResponseMiddlewareAfter = async (request)=>{
13
+ const fields = request.event?.queryStringParameters?.[filteringKeyName];
14
+ if (!fields) return;
15
+ normalizeHttpResponse(request);
16
+ const body = request.response.body;
17
+ const bodyIsString = typeof body === 'string';
18
+ const parsedBody = jsonSafeParse(body);
19
+ if (typeof parsedBody !== 'object') return;
20
+ const filteredBody = mask(parsedBody, fields);
21
+ request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody;
22
+ };
23
+ return {
24
+ after: httpPartialResponseMiddlewareAfter
25
+ };
26
+ };
27
+ export default httpPartialResponseMiddleware;
29
28
 
30
- return {
31
- after: httpPartialResponseMiddlewareAfter
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": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.2",
4
4
  "description": "Http partial response middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -61,11 +61,11 @@
61
61
  "url": "https://github.com/sponsors/willfarrell"
62
62
  },
63
63
  "dependencies": {
64
- "@middy/util": "5.0.0-alpha.1",
64
+ "@middy/util": "5.0.0-alpha.2",
65
65
  "json-mask": "2.0.0"
66
66
  },
67
67
  "gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1",
68
68
  "devDependencies": {
69
- "@middy/core": "5.0.0-alpha.1"
69
+ "@middy/core": "5.0.0-alpha.2"
70
70
  }
71
71
  }