@middy/http-partial-response 6.1.6 → 6.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.d.ts +4 -4
- package/index.js +24 -24
- package/package.json +70 -73
package/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import middy from
|
|
1
|
+
import type middy from "@middy/core";
|
|
2
2
|
|
|
3
3
|
interface Options {
|
|
4
|
-
|
|
4
|
+
filteringKeyName?: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
declare function httpPartialResponse
|
|
7
|
+
declare function httpPartialResponse(options?: Options): middy.MiddlewareObj;
|
|
8
8
|
|
|
9
|
-
export default httpPartialResponse
|
|
9
|
+
export default httpPartialResponse;
|
package/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { jsonSafeParse, normalizeHttpResponse } from "@middy/util";
|
|
2
|
+
import mask from "json-mask";
|
|
3
3
|
|
|
4
4
|
const defaults = {
|
|
5
|
-
|
|
6
|
-
}
|
|
5
|
+
filteringKeyName: "fields",
|
|
6
|
+
};
|
|
7
7
|
|
|
8
8
|
const httpPartialResponseMiddleware = (opts = {}) => {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const options = { ...defaults, ...opts };
|
|
10
|
+
const { filteringKeyName } = options;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const httpPartialResponseMiddlewareAfter = async (request) => {
|
|
13
|
+
const fields = request.event?.queryStringParameters?.[filteringKeyName];
|
|
14
|
+
if (!fields) return;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
normalizeHttpResponse(request);
|
|
17
|
+
const body = request.response.body;
|
|
18
|
+
const bodyIsString = typeof body === "string";
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const parsedBody = jsonSafeParse(body);
|
|
21
|
+
if (typeof parsedBody !== "object") return;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const filteredBody = mask(parsedBody, fields);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
request.response.body = bodyIsString
|
|
26
|
+
? JSON.stringify(filteredBody)
|
|
27
|
+
: filteredBody;
|
|
28
|
+
};
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
export default httpPartialResponseMiddleware
|
|
30
|
+
return {
|
|
31
|
+
after: httpPartialResponseMiddlewareAfter,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export default httpPartialResponseMiddleware;
|
package/package.json
CHANGED
|
@@ -1,75 +1,72 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"devDependencies": {
|
|
73
|
-
"@middy/core": "6.1.6"
|
|
74
|
-
}
|
|
2
|
+
"name": "@middy/http-partial-response",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"description": "Http partial response middleware for the middy framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
9
|
+
"engineStrict": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"module": "./index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"files": ["index.js", "index.d.ts"],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "npm run test:unit && npm run test:fuzz",
|
|
29
|
+
"test:unit": "node --test",
|
|
30
|
+
"test:fuzz": "node --test index.fuzz.js",
|
|
31
|
+
"test:perf": "node --test index.perf.js"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"Lambda",
|
|
36
|
+
"Middleware",
|
|
37
|
+
"Serverless",
|
|
38
|
+
"Framework",
|
|
39
|
+
"AWS",
|
|
40
|
+
"AWS Lambda",
|
|
41
|
+
"Middy",
|
|
42
|
+
"HTTP",
|
|
43
|
+
"API",
|
|
44
|
+
"Partial",
|
|
45
|
+
"Partial Response"
|
|
46
|
+
],
|
|
47
|
+
"author": {
|
|
48
|
+
"name": "Middy contributors",
|
|
49
|
+
"url": "https://github.com/middyjs/middy/graphs/contributors"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/middyjs/middy.git",
|
|
54
|
+
"directory": "packages/http-partial-response"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/middyjs/middy/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://middy.js.org",
|
|
60
|
+
"funding": {
|
|
61
|
+
"type": "github",
|
|
62
|
+
"url": "https://github.com/sponsors/willfarrell"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@middy/util": "6.2.0",
|
|
66
|
+
"json-mask": "2.0.0"
|
|
67
|
+
},
|
|
68
|
+
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@middy/core": "6.2.0"
|
|
71
|
+
}
|
|
75
72
|
}
|