@middy/http-partial-response 5.0.3 → 5.2.0
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/index.js +32 -26
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import mask from 'json-mask'
|
|
2
|
-
import { normalizeHttpResponse, jsonSafeParse } from '@middy/util'
|
|
1
|
+
import mask from 'json-mask'
|
|
2
|
+
import { normalizeHttpResponse, jsonSafeParse } from '@middy/util'
|
|
3
|
+
|
|
3
4
|
const defaults = {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
}
|
|
28
29
|
|
|
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
|
|
3
|
+
"version": "5.2.0",
|
|
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
|
|
64
|
+
"@middy/util": "5.2.0",
|
|
65
65
|
"json-mask": "2.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "2d9096a49cd8fb62359517be96d6c93609df41f0",
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@middy/core": "5.0
|
|
69
|
+
"@middy/core": "5.2.0"
|
|
70
70
|
}
|
|
71
71
|
}
|