@middy/http-event-normalizer 2.5.1 → 3.0.0-alpha.0

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
@@ -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 `. Set it to `2` to use API Gateway HTTP API v2.0 event payload (https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
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-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
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
- interface Options {
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/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@middy/http-event-normalizer",
3
- "version": "2.5.1",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "Http event normalizer 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
16
  "index.d.ts"
@@ -45,8 +45,8 @@
45
45
  "url": "https://github.com/middyjs/middy/issues"
46
46
  },
47
47
  "homepage": "https://github.com/middyjs/middy#readme",
48
- "gitHead": "df18e5eff7d73492a96a2ca4780a2eae45d1cedb",
48
+ "gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db",
49
49
  "devDependencies": {
50
- "@middy/core": "^2.5.1"
50
+ "@middy/core": "^3.0.0-alpha.0"
51
51
  }
52
52
  }
package/index.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- const defaults = {
4
- payloadFormatVersion: 1
5
- };
6
-
7
- const httpEventNormalizerMiddleware = (opts = {}) => {
8
- const options = { ...defaults,
9
- ...opts
10
- };
11
-
12
- const httpEventNormalizerMiddlewareBefore = async request => {
13
- const {
14
- event
15
- } = request;
16
-
17
- if (isHttpEvent(options.payloadFormatVersion, event)) {
18
- var _event$queryStringPar, _event$pathParameters;
19
-
20
- event.queryStringParameters = (_event$queryStringPar = event.queryStringParameters) !== null && _event$queryStringPar !== void 0 ? _event$queryStringPar : {};
21
- event.pathParameters = (_event$pathParameters = event.pathParameters) !== null && _event$pathParameters !== void 0 ? _event$pathParameters : {};
22
-
23
- if (options.payloadFormatVersion === 1) {
24
- var _event$multiValueQuer;
25
-
26
- event.multiValueQueryStringParameters = (_event$multiValueQuer = event.multiValueQueryStringParameters) !== null && _event$multiValueQuer !== void 0 ? _event$multiValueQuer : {};
27
- }
28
- }
29
- };
30
-
31
- return {
32
- before: httpEventNormalizerMiddlewareBefore
33
- };
34
- };
35
-
36
- const isHttpEvent = (payloadFormatVersion, event) => {
37
- if (payloadFormatVersion === 1) {
38
- return Object.prototype.hasOwnProperty.call(event, 'httpMethod');
39
- } else if (payloadFormatVersion === 2) {
40
- return Object.prototype.hasOwnProperty.call(event, 'requestContext') && Object.prototype.hasOwnProperty.call(event.requestContext, 'http') && Object.prototype.hasOwnProperty.call(event.requestContext.http, 'method');
41
- }
42
-
43
- throw new Error('Unknown API Gateway Payload format. Please use value 1 or 2.');
44
- };
45
-
46
- module.exports = httpEventNormalizerMiddleware;