-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Support multiple of same query string for LambdaProxyIntegration…
…EventV2 (#1525)
- Loading branch information
1 parent
70e989f
commit 7416c1c
Showing
5 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/utils/__tests__/parseQueryStringParametersForPayloadV2.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import assert from 'node:assert' | ||
|
||
// uses the same tests as parseMultiValueQueryStringParameters | ||
import tests from './parseMultiValueQueryStringParameters.test.js' | ||
import parseQueryStringParametersForPayloadV2 from '../parseQueryStringParametersForPayloadV2.js' | ||
import { BASE_URL_PLACEHOLDER } from '../../config/index.js' | ||
|
||
describe('parseQueryStringParametersForPayloadV2', () => { | ||
tests.forEach(({ description, expected, expectedV2, param }) => { | ||
const url = `/foo?${param}` | ||
const { searchParams } = new URL(url, BASE_URL_PLACEHOLDER) | ||
|
||
it(`should return ${description}`, () => { | ||
const result = parseQueryStringParametersForPayloadV2(searchParams) | ||
if (expectedV2) { | ||
assert.deepEqual(result, expectedV2) | ||
} else { | ||
assert.deepEqual(result, expected) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* | ||
* @description Instead of using `multiValueQueryStringParameters` API Gateway HTTP API combines | ||
* duplicate query string keys with commas in the `queryStringParameters` field. | ||
* https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | ||
* | ||
* @param { URLSearchParams } searchParams | ||
*/ | ||
export default function parseQueryStringParametersForPayloadV2(searchParams) { | ||
const keyValuePairs = Array.from(searchParams) | ||
|
||
if (keyValuePairs.length === 0) { | ||
return null | ||
} | ||
|
||
return keyValuePairs.reduce((previousValue, [key, value]) => { | ||
if (!previousValue[key]) { | ||
return { ...previousValue, [key]: value } | ||
} | ||
return { ...previousValue, [key]: [previousValue[key], value].join(',') } | ||
}, {}) | ||
} |