@middy/http-event-normalizer 3.0.0-alpha.3 → 3.0.0-alpha.7
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/README.md +24 -16
- package/index.js +2 -28
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
# Middy http-event-normalizer middleware
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.png"/>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
1
|
<div align="center">
|
|
2
|
+
<h1>Middy http-event-normalizer middleware</h1>
|
|
3
|
+
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
|
|
8
4
|
<p><strong>HTTP error handler middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
|
|
9
|
-
</div>
|
|
10
|
-
|
|
11
|
-
<div align="center">
|
|
12
5
|
<p>
|
|
13
|
-
<a href="
|
|
6
|
+
<a href="https://www.npmjs.com/package/@middy/http-event-normalizer?activeTab=versions">
|
|
14
7
|
<img src="https://badge.fury.io/js/%40middy%2Fhttp-event-normalizer.svg" alt="npm version" style="max-width:100%;">
|
|
15
8
|
</a>
|
|
9
|
+
<a href="https://packagephobia.com/result?p=@middy/http-event-normalizer">
|
|
10
|
+
<img src="https://packagephobia.com/badge?p=@middy/http-event-normalizer" alt="npm install size" style="max-width:100%;">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/middyjs/middy/actions">
|
|
13
|
+
<img src="https://github.com/middyjs/middy/workflows/Tests/badge.svg" alt="GitHub Actions test status badge" style="max-width:100%;">
|
|
14
|
+
</a>
|
|
15
|
+
<br/>
|
|
16
|
+
<a href="https://standardjs.com/">
|
|
17
|
+
<img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
|
|
18
|
+
</a>
|
|
16
19
|
<a href="https://snyk.io/test/github/middyjs/middy">
|
|
17
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%;">
|
|
18
21
|
</a>
|
|
19
|
-
<a href="https://
|
|
20
|
-
<img src="https://img.shields.io/
|
|
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%;">
|
|
21
24
|
</a>
|
|
25
|
+
<a href="https://bestpractices.coreinfrastructure.org/projects/5280">
|
|
26
|
+
<img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
|
|
27
|
+
</a>
|
|
28
|
+
<br/>
|
|
22
29
|
<a href="https://gitter.im/middyjs/Lobby">
|
|
23
|
-
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter"
|
|
30
|
+
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052">
|
|
33
|
+
<img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
|
|
24
34
|
</a>
|
|
25
35
|
</p>
|
|
26
36
|
</div>
|
|
@@ -53,9 +63,7 @@ npm install --save @middy/http-event-normalizer
|
|
|
53
63
|
|
|
54
64
|
|
|
55
65
|
## Options
|
|
56
|
-
|
|
57
|
-
- payloadFormatVersion (number) (optional): Defaults to `1 ` for API Gateway REST API v1 or Application Load Balancer (ALB) event payload. Set it to `2` to use API Gateway HTTP API v2 event payload.
|
|
58
|
-
|
|
66
|
+
None
|
|
59
67
|
|
|
60
68
|
## Sample usage
|
|
61
69
|
|
package/index.js
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
const httpEventNormalizerMiddleware = () =>
|
|
2
|
-
const httpEventNormalizerMiddlewareBefore = async (request) => {
|
|
3
|
-
const { event } = request
|
|
1
|
+
var _event,_event1,_event2;const httpEventNormalizerMiddleware=()=>{const httpEventNormalizerMiddlewareBefore=async request=>{const{event}=request;const version=event.version??'1.0';const isHttpEvent=isVersionHttpEvent[version]?.(event);if(!isHttpEvent){throw new Error('[http-event-normalizer] Unknown http event format')}(_event=event).queryStringParameters??(_event.queryStringParameters={});(_event1=event).pathParameters??(_event1.pathParameters={});if(version==='1.0'){(_event2=event).multiValueQueryStringParameters??(_event2.multiValueQueryStringParameters={})}};return{before:httpEventNormalizerMiddlewareBefore}};const isVersionHttpEvent={'1.0':event=>event.httpMethod!==undefined,'2.0':event=>event.requestContext.http.method!==undefined};export default httpEventNormalizerMiddleware
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
const isHttpEvent = isVersionHttpEvent[version]?.(event)
|
|
7
|
-
if (!isHttpEvent) {
|
|
8
|
-
throw new Error('Unknown API Gateway Payload format')
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// event.headers ??= {} // Will always have at least one header
|
|
12
|
-
event.queryStringParameters ??= {}
|
|
13
|
-
event.pathParameters ??= {}
|
|
14
|
-
if (version === '1.0') {
|
|
15
|
-
event.multiValueQueryStringParameters ??= {}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
before: httpEventNormalizerMiddlewareBefore
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const isVersionHttpEvent = {
|
|
25
|
-
'1.0': (event) => event.httpMethod !== undefined,
|
|
26
|
-
'2.0': (event) => event.requestContext.http.method !== undefined
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default httpEventNormalizerMiddleware
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-event-normalizer",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
4
|
"description": "Http event normalizer middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"url": "https://github.com/middyjs/middy/issues"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5cef39ebe49c201f97d71bb0680004de4b82cb91",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@middy/core": "^3.0.0-alpha.
|
|
52
|
+
"@middy/core": "^3.0.0-alpha.7"
|
|
53
53
|
}
|
|
54
54
|
}
|