Skip to content

Commit b68448f

Browse files
committed
add missing response
1 parent 9907139 commit b68448f

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [4.3.0]  (2020-11-13)
8+
9+
### Added
10+
11+
- Added rawQueryString as parsed param to http api wrapper
12+
713
## [4.2.0]  (2020-11-13)
814

915
### Added
@@ -323,6 +329,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
323329
- Update older libraries
324330
- Now publish from Git tags instead of master pushes
325331

332+
[4.3.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.2.0...v4.3.0
326333
[4.2.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.1.1...v4.2.0
327334
[4.1.1]: https://github.com/manwaring/lambda-wrapper/compare/v4.1.0...v4.1.1
328335
[4.1.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.0.6...v4.1.0

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ export interface HttpApiSignature<T = any> {
735735
rawPath: string; // the endpoint path used to invoke this Lambda
736736
path: { [name: string]: string }; // path params as key-value pairs
737737
query: { [name: string]: string }; // query params as key-value pairs
738+
rawQueryString: string // the raw query string from the request
738739
headers: { [name: string]: string }; // headers as key-value pairs
739740
testRequest: boolean; // indicates if this is a test request - looks for a header matching process.env.TEST_REQUEST_HEADER (dynamic from application) or 'Test-Request' (default)
740741
auth: any; // auth context from JWT authorizer

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@manwaring/lambda-wrapper",
33
"description": "A lambda handler wrapper to abstract common functionality and provide useful defaults",
4-
"version": "4.2.0",
4+
"version": "4.3.0",
55
"scripts": {
66
"publish-please-dry-run": "publish-please --dry-run",
77
"publish-please": "publish-please",

src/api/v2-http/parser.test.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ describe('Http API request parsing', () => {
5959
body: JSON.stringify({ hello: 'world' }),
6060
rawPath: '/api/v1/nouns/id124',
6161
pathParameters: { proxy: 'not today' },
62-
queryStringParameters: { name: 'a test' },
62+
rawQueryString: 'name=atest',
63+
queryStringParameters: { name: 'atest' },
6364
headers: { 'content-type': 'application/json', 'Test-Request': 'true' },
6465
});
65-
const { body, path, rawPath, query, auth, headers, testRequest } = new Request(event).getProperties();
66+
const { body, path, rawPath, query, rawQueryString, auth, headers, testRequest } = new Request(
67+
event
68+
).getProperties();
6669

6770
expect(body).toEqual({ hello: 'world' });
6871
expect(path['proxy']).toEqual(event.pathParameters.proxy);
6972
expect(rawPath).toEqual(event.rawPath);
7073
expect(query['name']).toEqual(event.queryStringParameters.name);
74+
expect(rawQueryString).toEqual(event.rawQueryString);
7175
expect(headers['content-type']).toEqual('application/json');
7276
expect(testRequest).toEqual(true);
7377
expect(auth).toBeTruthy();
@@ -79,13 +83,17 @@ describe('Http API request parsing', () => {
7983
delete event.rawPath;
8084
delete event.headers;
8185
delete event.pathParameters;
86+
delete event.rawQueryString;
8287
delete event.queryStringParameters;
83-
const { body, path, rawPath, query, auth, headers, testRequest } = new Request(event).getProperties();
88+
const { body, path, rawPath, query, rawQueryString, auth, headers, testRequest } = new Request(
89+
event
90+
).getProperties();
8491

8592
expect(body).toBeFalsy();
8693
expect(path).toBeFalsy();
8794
expect(rawPath).toBeFalsy();
8895
expect(query).toBeFalsy();
96+
expect(rawQueryString).toBeFalsy();
8997
expect(auth).toBeTruthy();
9098
expect(headers).toBeFalsy();
9199
expect(testRequest).toBeFalsy();

src/api/v2-http/parser.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@ const metrics = new Metrics('API Gateway');
77
export class Request {
88
constructor(private event: HttpApiEvent) {}
99

10-
getProperties(): any {
10+
getProperties(): {
11+
body: any;
12+
path: { [name: string]: string };
13+
rawPath: string;
14+
query: { [name: string]: string };
15+
rawQueryString: string;
16+
headers: { [name: string]: string };
17+
testRequest: boolean;
18+
auth: any;
19+
} {
1120
const event = this.event;
1221
const path = event.pathParameters || undefined;
1322
const rawPath = event.rawPath || undefined;
1423
const query = event.queryStringParameters || undefined;
24+
const rawQueryString = event.rawQueryString || undefined;
1525
const auth = this.getAuth();
1626
const headers = event.headers || undefined;
1727
const body = new Body(event.body, headers).getParsedBody();
1828
const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || 'Test-Request';
1929
const testRequest = headers && headers[TEST_REQUEST_HEADER] ? JSON.parse(headers[TEST_REQUEST_HEADER]) : false;
20-
const parsed = { body, path, rawPath, query, auth, headers, testRequest };
30+
const parsed = { body, path, rawPath, query, rawQueryString, auth, headers, testRequest };
2131
metrics.common(parsed, event);
2232
return parsed;
2333
}

src/api/v2-http/wrapper.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ export function httpApi<T = any>(
2020
customHandler: (props: HttpApiSignature<T>) => any
2121
): (event: HttpApiEvent, context: Context, callback: Callback) => any {
2222
return function handler(event: HttpApiEvent) {
23-
const { body, path, rawPath, query, auth, headers, testRequest } = new Request(event).getProperties();
23+
const { body, path, rawPath, query, rawQueryString, auth, headers, testRequest } = new Request(
24+
event
25+
).getProperties();
2426
const signature: HttpApiSignature<T> = {
2527
event,
2628
body,
2729
path,
2830
rawPath,
2931
query,
32+
rawQueryString,
3033
headers,
3134
testRequest,
3235
auth,
@@ -48,6 +51,7 @@ export interface HttpApiSignature<T = any> {
4851
path: { [name: string]: string };
4952
rawPath: string;
5053
query: { [name: string]: string };
54+
rawQueryString: string;
5155
headers: { [name: string]: string };
5256
testRequest: boolean;
5357
auth: any;

0 commit comments

Comments
 (0)