@middy/http-header-normalizer 5.0.0-alpha.0 → 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 (4) hide show
  1. package/README.md +3 -2
  2. package/index.js +92 -77
  3. package/package.json +3 -9
  4. package/index.cjs +0 -89
package/README.md CHANGED
@@ -19,8 +19,9 @@
19
19
  <a href="https://snyk.io/test/github/middyjs/middy">
20
20
  <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
21
21
  </a>
22
- <a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
23
- <img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
22
+ <a href="https://github.com/middyjs/middy/actions/workflows/sast.yml">
23
+ <img src="https://github.com/middyjs/middy/actions/workflows/sast.yml/badge.svg
24
+ ?branch=main&event=push" alt="CodeQL" style="max-width:100%;">
24
25
  </a>
25
26
  <a href="https://bestpractices.coreinfrastructure.org/projects/5280">
26
27
  <img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
package/index.js CHANGED
@@ -1,81 +1,96 @@
1
1
  const exceptionsList = [
2
- 'ALPN',
3
- 'C-PEP',
4
- 'C-PEP-Info',
5
- 'CalDAV-Timezones',
6
- 'Content-ID',
7
- 'Content-MD5',
8
- 'DASL',
9
- 'DAV',
10
- 'DNT',
11
- 'ETag',
12
- 'GetProfile',
13
- 'HTTP2-Settings',
14
- 'Last-Event-ID',
15
- 'MIME-Version',
16
- 'Optional-WWW-Authenticate',
17
- 'Sec-WebSocket-Accept',
18
- 'Sec-WebSocket-Extensions',
19
- 'Sec-WebSocket-Key',
20
- 'Sec-WebSocket-Protocol',
21
- 'Sec-WebSocket-Version',
22
- 'SLUG',
23
- 'TCN',
24
- 'TE',
25
- 'TTL',
26
- 'WWW-Authenticate',
27
- 'X-ATT-DeviceId',
28
- 'X-DNSPrefetch-Control',
29
- 'X-UIDH'
30
- ];
31
- const exceptions = exceptionsList.reduce((acc, curr)=>{
32
- acc[curr.toLowerCase()] = curr;
33
- return acc;
34
- }, {});
35
- const normalizeHeaderKey = (key, canonical)=>{
36
- const lowerCaseKey = key.toLowerCase();
37
- if (!canonical) {
38
- return lowerCaseKey;
2
+ 'ALPN',
3
+ 'C-PEP',
4
+ 'C-PEP-Info',
5
+ 'CalDAV-Timezones',
6
+ 'Content-ID',
7
+ 'Content-MD5',
8
+ 'DASL',
9
+ 'DAV',
10
+ 'DNT',
11
+ 'ETag',
12
+ 'GetProfile',
13
+ 'HTTP2-Settings',
14
+ 'Last-Event-ID',
15
+ 'MIME-Version',
16
+ 'Optional-WWW-Authenticate',
17
+ 'Sec-WebSocket-Accept',
18
+ 'Sec-WebSocket-Extensions',
19
+ 'Sec-WebSocket-Key',
20
+ 'Sec-WebSocket-Protocol',
21
+ 'Sec-WebSocket-Version',
22
+ 'SLUG',
23
+ 'TCN',
24
+ 'TE',
25
+ 'TTL',
26
+ 'WWW-Authenticate',
27
+ 'X-ATT-DeviceId',
28
+ 'X-DNSPrefetch-Control',
29
+ 'X-UIDH'
30
+ ]
31
+
32
+ const exceptions = exceptionsList.reduce((acc, curr) => {
33
+ acc[curr.toLowerCase()] = curr
34
+ return acc
35
+ }, {})
36
+
37
+ const normalizeHeaderKey = (key, canonical) => {
38
+ const lowerCaseKey = key.toLowerCase()
39
+ if (!canonical) {
40
+ return lowerCaseKey
41
+ }
42
+
43
+ if (exceptions[lowerCaseKey]) {
44
+ return exceptions[lowerCaseKey]
45
+ }
46
+
47
+ return lowerCaseKey
48
+ .split('-')
49
+ .map((text) => text[0].toUpperCase() + text.substr(1))
50
+ .join('-')
51
+ }
52
+
53
+ const defaults = {
54
+ canonical: false,
55
+ normalizeHeaderKey
56
+ }
57
+
58
+ const httpHeaderNormalizerMiddleware = (opts = {}) => {
59
+ const options = { ...defaults, ...opts }
60
+
61
+ const httpHeaderNormalizerMiddlewareBefore = async (request) => {
62
+ if (request.event.headers) {
63
+ const rawHeaders = {}
64
+ const headers = {}
65
+
66
+ for (const key of Object.keys(request.event.headers)) {
67
+ rawHeaders[key] = request.event.headers[key]
68
+ headers[options.normalizeHeaderKey(key, options.canonical)] =
69
+ request.event.headers[key]
70
+ }
71
+
72
+ request.event.headers = headers
73
+ request.event.rawHeaders = rawHeaders
39
74
  }
40
- if (exceptions[lowerCaseKey]) {
41
- return exceptions[lowerCaseKey];
75
+
76
+ if (request.event.multiValueHeaders) {
77
+ const rawHeaders = {}
78
+ const headers = {}
79
+
80
+ for (const key of Object.keys(request.event.multiValueHeaders)) {
81
+ rawHeaders[key] = request.event.multiValueHeaders[key]
82
+ headers[options.normalizeHeaderKey(key, options.canonical)] =
83
+ request.event.multiValueHeaders[key]
84
+ }
85
+
86
+ request.event.multiValueHeaders = headers
87
+ request.event.rawMultiValueHeaders = rawHeaders
42
88
  }
43
- return lowerCaseKey.split('-').map((text)=>text[0].toUpperCase() + text.substr(1)).join('-');
44
- };
45
- const defaults = {
46
- canonical: false,
47
- normalizeHeaderKey
48
- };
49
- const httpHeaderNormalizerMiddleware = (opts = {})=>{
50
- const options = {
51
- ...defaults,
52
- ...opts
53
- };
54
- const httpHeaderNormalizerMiddlewareBefore = async (request)=>{
55
- if (request.event.headers) {
56
- const rawHeaders = {};
57
- const headers = {};
58
- for (const key of Object.keys(request.event.headers)){
59
- rawHeaders[key] = request.event.headers[key];
60
- headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.headers[key];
61
- }
62
- request.event.headers = headers;
63
- request.event.rawHeaders = rawHeaders;
64
- }
65
- if (request.event.multiValueHeaders) {
66
- const rawHeaders = {};
67
- const headers = {};
68
- for (const key of Object.keys(request.event.multiValueHeaders)){
69
- rawHeaders[key] = request.event.multiValueHeaders[key];
70
- headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.multiValueHeaders[key];
71
- }
72
- request.event.multiValueHeaders = headers;
73
- request.event.rawMultiValueHeaders = rawHeaders;
74
- }
75
- };
76
- return {
77
- before: httpHeaderNormalizerMiddlewareBefore
78
- };
79
- };
80
- export default httpHeaderNormalizerMiddleware;
89
+ }
90
+
91
+ return {
92
+ before: httpHeaderNormalizerMiddlewareBefore
93
+ }
94
+ }
81
95
 
96
+ export default httpHeaderNormalizerMiddleware
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-header-normalizer",
3
- "version": "5.0.0-alpha.0",
3
+ "version": "5.0.0-alpha.1",
4
4
  "description": "Http header normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,24 +10,18 @@
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,8 +61,8 @@
67
61
  "type": "github",
68
62
  "url": "https://github.com/sponsors/willfarrell"
69
63
  },
70
- "gitHead": "08c35e3dba9efdad0b86666ce206ce302cc65d07",
64
+ "gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1",
71
65
  "devDependencies": {
72
- "@middy/core": "5.0.0-alpha.0"
66
+ "@middy/core": "5.0.0-alpha.1"
73
67
  }
74
68
  }
package/index.cjs DELETED
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(module, "exports", {
6
- enumerable: true,
7
- get: ()=>_default
8
- });
9
- const exceptionsList = [
10
- 'ALPN',
11
- 'C-PEP',
12
- 'C-PEP-Info',
13
- 'CalDAV-Timezones',
14
- 'Content-ID',
15
- 'Content-MD5',
16
- 'DASL',
17
- 'DAV',
18
- 'DNT',
19
- 'ETag',
20
- 'GetProfile',
21
- 'HTTP2-Settings',
22
- 'Last-Event-ID',
23
- 'MIME-Version',
24
- 'Optional-WWW-Authenticate',
25
- 'Sec-WebSocket-Accept',
26
- 'Sec-WebSocket-Extensions',
27
- 'Sec-WebSocket-Key',
28
- 'Sec-WebSocket-Protocol',
29
- 'Sec-WebSocket-Version',
30
- 'SLUG',
31
- 'TCN',
32
- 'TE',
33
- 'TTL',
34
- 'WWW-Authenticate',
35
- 'X-ATT-DeviceId',
36
- 'X-DNSPrefetch-Control',
37
- 'X-UIDH'
38
- ];
39
- const exceptions = exceptionsList.reduce((acc, curr)=>{
40
- acc[curr.toLowerCase()] = curr;
41
- return acc;
42
- }, {});
43
- const normalizeHeaderKey = (key, canonical)=>{
44
- const lowerCaseKey = key.toLowerCase();
45
- if (!canonical) {
46
- return lowerCaseKey;
47
- }
48
- if (exceptions[lowerCaseKey]) {
49
- return exceptions[lowerCaseKey];
50
- }
51
- return lowerCaseKey.split('-').map((text)=>text[0].toUpperCase() + text.substr(1)).join('-');
52
- };
53
- const defaults = {
54
- canonical: false,
55
- normalizeHeaderKey
56
- };
57
- const httpHeaderNormalizerMiddleware = (opts = {})=>{
58
- const options = {
59
- ...defaults,
60
- ...opts
61
- };
62
- const httpHeaderNormalizerMiddlewareBefore = async (request)=>{
63
- if (request.event.headers) {
64
- const rawHeaders = {};
65
- const headers = {};
66
- for (const key of Object.keys(request.event.headers)){
67
- rawHeaders[key] = request.event.headers[key];
68
- headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.headers[key];
69
- }
70
- request.event.headers = headers;
71
- request.event.rawHeaders = rawHeaders;
72
- }
73
- if (request.event.multiValueHeaders) {
74
- const rawHeaders = {};
75
- const headers = {};
76
- for (const key of Object.keys(request.event.multiValueHeaders)){
77
- rawHeaders[key] = request.event.multiValueHeaders[key];
78
- headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.multiValueHeaders[key];
79
- }
80
- request.event.multiValueHeaders = headers;
81
- request.event.rawMultiValueHeaders = rawHeaders;
82
- }
83
- };
84
- return {
85
- before: httpHeaderNormalizerMiddlewareBefore
86
- };
87
- };
88
- const _default = httpHeaderNormalizerMiddleware;
89
-