@middy/http-partial-response 2.5.6 → 3.0.0-alpha.3

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -97,7 +97,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
97
97
 
98
98
  ## License
99
99
 
100
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
100
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
101
101
 
102
102
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
103
103
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- const mask = require('json-mask')
2
- const { jsonSafeParse } = require('@middy/util')
1
+ import mask from 'json-mask'
2
+ import { normalizeHttpResponse, jsonSafeParse } from '@middy/util'
3
3
 
4
4
  const defaults = {
5
5
  filteringKeyName: 'fields'
@@ -10,22 +10,23 @@ const httpPartialResponseMiddleware = (opts = {}) => {
10
10
  const { filteringKeyName } = options
11
11
 
12
12
  const httpPartialResponseMiddlewareAfter = async (request) => {
13
- const body = request.response?.body
14
- if (!body) return
15
-
16
13
  const fields = request.event?.queryStringParameters?.[filteringKeyName]
17
14
  if (!fields) return
18
15
 
16
+ normalizeHttpResponse(request)
17
+ const body = request.response.body
18
+ const bodyIsString = typeof body === 'string'
19
+
19
20
  const parsedBody = jsonSafeParse(body)
20
21
  if (typeof parsedBody !== 'object') return
21
22
 
22
23
  const filteredBody = mask(parsedBody, fields)
23
24
 
24
- request.response.body =
25
- typeof body === 'object' ? filteredBody : JSON.stringify(filteredBody)
25
+ request.response.body = bodyIsString ? JSON.stringify(filteredBody) : filteredBody
26
26
  }
27
+
27
28
  return {
28
29
  after: httpPartialResponseMiddlewareAfter
29
30
  }
30
31
  }
31
- module.exports = httpPartialResponseMiddleware
32
+ export default httpPartialResponseMiddleware
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@middy/http-partial-response",
3
- "version": "2.5.6",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "Http partial response middleware for the middy framework",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
+ "index.js",
16
17
  "index.d.ts"
17
18
  ],
18
19
  "scripts": {
19
20
  "test": "npm run test:unit",
20
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
21
23
  },
22
24
  "license": "MIT",
23
25
  "keywords": [
@@ -47,11 +49,11 @@
47
49
  },
48
50
  "homepage": "https://github.com/middyjs/middy#readme",
49
51
  "dependencies": {
50
- "@middy/util": "^2.5.6",
52
+ "@middy/util": "^3.0.0-alpha.3",
51
53
  "json-mask": "1.0.4"
52
54
  },
53
- "gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b",
55
+ "gitHead": "1441158711580313765e6d156046ef0fade0d156",
54
56
  "devDependencies": {
55
- "@middy/core": "^2.5.6"
57
+ "@middy/core": "^3.0.0-alpha.3"
56
58
  }
57
59
  }