@middy/http-event-normalizer 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 +1 -1
- package/README.md +2 -2
- package/index.d.ts +1 -5
- package/index.js +16 -28
- package/package.json +9 -7
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
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
|
@@ -54,7 +54,7 @@ npm install --save @middy/http-event-normalizer
|
|
|
54
54
|
|
|
55
55
|
## Options
|
|
56
56
|
|
|
57
|
-
- payloadFormatVersion (number) (optional): Defaults to `1
|
|
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
58
|
|
|
59
59
|
|
|
60
60
|
## Sample usage
|
|
@@ -84,7 +84,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
84
84
|
|
|
85
85
|
## License
|
|
86
86
|
|
|
87
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
87
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
88
88
|
|
|
89
89
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
90
90
|
<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.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import middy from '@middy/core'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
payloadFormatVersion?: 1 | 2
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
declare function httpEventNormalizer (options?: Options): middy.MiddlewareObj
|
|
3
|
+
declare function httpEventNormalizer (): middy.MiddlewareObj
|
|
8
4
|
|
|
9
5
|
export default httpEventNormalizer
|
package/index.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
const
|
|
2
|
-
payloadFormatVersion: 1
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
const httpEventNormalizerMiddleware = (opts = {}) => {
|
|
6
|
-
const options = { ...defaults, ...opts }
|
|
7
|
-
|
|
1
|
+
const httpEventNormalizerMiddleware = () => {
|
|
8
2
|
const httpEventNormalizerMiddlewareBefore = async (request) => {
|
|
9
3
|
const { event } = request
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
const version = event.version ?? '1.0'
|
|
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 ??= {}
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
|
|
@@ -23,19 +21,9 @@ const httpEventNormalizerMiddleware = (opts = {}) => {
|
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} else if (payloadFormatVersion === 2) {
|
|
30
|
-
return (
|
|
31
|
-
Object.prototype.hasOwnProperty.call(event, 'requestContext') &&
|
|
32
|
-
Object.prototype.hasOwnProperty.call(event.requestContext, 'http') &&
|
|
33
|
-
Object.prototype.hasOwnProperty.call(event.requestContext.http, 'method')
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
throw new Error(
|
|
37
|
-
'Unknown API Gateway Payload format. Please use value 1 or 2.'
|
|
38
|
-
)
|
|
24
|
+
const isVersionHttpEvent = {
|
|
25
|
+
'1.0': (event) => event.httpMethod !== undefined,
|
|
26
|
+
'2.0': (event) => event.requestContext.http.method !== undefined
|
|
39
27
|
}
|
|
40
28
|
|
|
41
|
-
|
|
29
|
+
export default httpEventNormalizerMiddleware
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-event-normalizer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"description": "Http event normalizer middleware for the middy framework",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=14"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
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": [
|
|
@@ -45,8 +47,8 @@
|
|
|
45
47
|
"url": "https://github.com/middyjs/middy/issues"
|
|
46
48
|
},
|
|
47
49
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
48
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1441158711580313765e6d156046ef0fade0d156",
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@middy/core": "^
|
|
52
|
+
"@middy/core": "^3.0.0-alpha.3"
|
|
51
53
|
}
|
|
52
54
|
}
|