@middy/http-partial-response 4.6.5 → 5.0.0-alpha.1

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 (3) hide show
  1. package/index.js +32 -26
  2. package/package.json +5 -11
  3. package/index.cjs +0 -43
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
- 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;
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,33 +1,27 @@
1
1
  {
2
2
  "name": "@middy/http-partial-response",
3
- "version": "4.6.5",
3
+ "version": "5.0.0-alpha.1",
4
4
  "description": "Http partial response middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=16"
7
+ "node": ">=18"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "./index.cjs",
14
13
  "module": "./index.js",
15
14
  "exports": {
16
15
  ".": {
17
16
  "import": {
18
17
  "types": "./index.d.ts",
19
18
  "default": "./index.js"
20
- },
21
- "require": {
22
- "types": "./index.d.ts",
23
- "default": "./index.cjs"
24
19
  }
25
20
  }
26
21
  },
27
22
  "types": "index.d.ts",
28
23
  "files": [
29
24
  "index.js",
30
- "index.cjs",
31
25
  "index.d.ts"
32
26
  ],
33
27
  "scripts": {
@@ -67,11 +61,11 @@
67
61
  "url": "https://github.com/sponsors/willfarrell"
68
62
  },
69
63
  "dependencies": {
70
- "@middy/util": "4.6.5",
64
+ "@middy/util": "5.0.0-alpha.1",
71
65
  "json-mask": "2.0.0"
72
66
  },
73
- "gitHead": "573d7b0bb243d8c5a9bcb00cf29d031aa7a0c606",
67
+ "gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1",
74
68
  "devDependencies": {
75
- "@middy/core": "4.6.5"
69
+ "@middy/core": "5.0.0-alpha.1"
76
70
  }
77
71
  }
package/index.cjs DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(module, "exports", {
6
- enumerable: true,
7
- get: function() {
8
- return _default;
9
- }
10
- });
11
- const _jsonmask = /*#__PURE__*/ _interop_require_default(require("json-mask"));
12
- const _util = require("@middy/util");
13
- function _interop_require_default(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
16
- };
17
- }
18
- const defaults = {
19
- filteringKeyName: 'fields'
20
- };
21
- const httpPartialResponseMiddleware = (opts = {})=>{
22
- const options = {
23
- ...defaults,
24
- ...opts
25
- };
26
- const { filteringKeyName } = options;
27
- const httpPartialResponseMiddlewareAfter = async (request)=>{
28
- const fields = request.event?.queryStringParameters?.[filteringKeyName];
29
- if (!fields) return;
30
- (0, _util.normalizeHttpResponse)(request);
31
- const body = request.response.body;
32
- const bodyIsString = typeof body === 'string';
33
- const parsedBody = (0, _util.jsonSafeParse)(body);
34
- if (typeof parsedBody !== 'object') return;
35
- const filteredBody = (0, _jsonmask.default)(parsedBody, fields);
36
- request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody;
37
- };
38
- return {
39
- after: httpPartialResponseMiddlewareAfter
40
- };
41
- };
42
- const _default = httpPartialResponseMiddleware;
43
-