@middy/http-partial-response 3.0.3 → 3.0.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/index.cjs +39 -1
- package/index.js +28 -1
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
module.exports = void 0;
|
|
6
|
+
var _jsonMask = _interopRequireDefault(require("json-mask"));
|
|
7
|
+
var _util = require("@middy/util");
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const defaults = {
|
|
14
|
+
filteringKeyName: 'fields'
|
|
15
|
+
};
|
|
16
|
+
const httpPartialResponseMiddleware = (opts = {})=>{
|
|
17
|
+
const options = {
|
|
18
|
+
...defaults,
|
|
19
|
+
...opts
|
|
20
|
+
};
|
|
21
|
+
const { filteringKeyName } = options;
|
|
22
|
+
const httpPartialResponseMiddlewareAfter = async (request)=>{
|
|
23
|
+
const fields = request.event?.queryStringParameters?.[filteringKeyName];
|
|
24
|
+
if (!fields) return;
|
|
25
|
+
(0, _util).normalizeHttpResponse(request);
|
|
26
|
+
const body = request.response.body;
|
|
27
|
+
const bodyIsString = typeof body === 'string';
|
|
28
|
+
const parsedBody = (0, _util).jsonSafeParse(body);
|
|
29
|
+
if (typeof parsedBody !== 'object') return;
|
|
30
|
+
const filteredBody = (0, _jsonMask).default(parsedBody, fields);
|
|
31
|
+
request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody;
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
after: httpPartialResponseMiddlewareAfter
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var _default = httpPartialResponseMiddleware;
|
|
38
|
+
module.exports = _default;
|
|
39
|
+
|
|
2
40
|
|
|
3
41
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
import mask from
|
|
1
|
+
import mask from 'json-mask';
|
|
2
|
+
import { normalizeHttpResponse, jsonSafeParse } from '@middy/util';
|
|
3
|
+
const defaults = {
|
|
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;
|
|
28
|
+
|
|
2
29
|
|
|
3
30
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-partial-response",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "Http partial response middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
},
|
|
57
57
|
"homepage": "https://middy.js.org",
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@middy/util": "3.0.
|
|
59
|
+
"@middy/util": "3.0.4",
|
|
60
60
|
"json-mask": "2.0.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "3e9bc83e791f943c71cd7003fc27f0a3692d83a1",
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@middy/core": "3.0.
|
|
64
|
+
"@middy/core": "3.0.4"
|
|
65
65
|
}
|
|
66
66
|
}
|