@middy/http-header-normalizer 5.0.0-alpha.0 → 5.0.0-alpha.2

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/README.md +3 -2
  2. package/package.json +3 -9
  3. 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/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.2",
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.2"
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
-