Skip to content

Commit

Permalink
Merge pull request #90 from silvermine/lambda-types-upgrade
Browse files Browse the repository at this point in the history
build: bump @types/aws-lambda
  • Loading branch information
onebytegone authored Jun 20, 2024
2 parents 42c404d + 64e527b commit d47be8a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@silvermine/eslint-config": "3.2.0",
"@silvermine/standardization": "2.0.0",
"@silvermine/typescript-config": "1.0.0",
"@types/aws-lambda": "8.10.17",
"@types/aws-lambda": "8.10.140",
"@types/chai": "4.1.7",
"@types/cookie": "0.3.2",
"@types/mocha": "5.2.5",
Expand Down
14 changes: 11 additions & 3 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import qs from 'qs';
import cookie from 'cookie';
import Application from './Application';
import { RequestEvent, HandlerContext, RequestEventRequestContext, LambdaEventSourceType } from './request-response-types';
import { StringMap, KeyValueStringObject, StringArrayOfStringsMap, StringUnknownMap } from '@silvermine/toolbox';
import { StringMap, KeyValueStringObject, StringArrayOfStringsMap, StringUnknownMap, isUndefined } from '@silvermine/toolbox';
import ConsoleLogger from './logging/ConsoleLogger';

function safeDecode(s: string): string {
Expand Down Expand Up @@ -479,6 +479,10 @@ export default class Request {
const headers = evt.multiValueHeaders || _.mapObject(evt.headers, (v) => { return [ v ]; });

return _.reduce(headers, (memo: StringArrayOfStringsMap, v, k) => {
if (isUndefined(v)) {
return memo;
}

const key = k.toLowerCase();

memo[key] = v;
Expand Down Expand Up @@ -554,7 +558,7 @@ export default class Request {
}
}

private _parseQuery(multiValQuery: StringArrayOfStringsMap, query: StringMap): { raw: string; parsed: KeyValueStringObject } {
private _parseQuery(multiValQuery: Partial<StringArrayOfStringsMap>, query: Partial<StringMap>): { raw: string; parsed: KeyValueStringObject } {
let queryString;

// It may seem strange to encode the URI components immediately after decoding them.
Expand All @@ -566,11 +570,15 @@ export default class Request {
// values that were not correct.
if (_.isEmpty(multiValQuery)) {
queryString = _.reduce(query, (memo, v, k) => {
if (isUndefined(v)) {
return memo;
}

return memo + `&${k}=${encodeURIComponent(safeDecode(v))}`;
}, '');
} else {
queryString = _.reduce(multiValQuery, (memo, vals, k) => {
_.each(vals, (v) => {
_.each(vals || [], (v) => {
memo += `&${k}=${encodeURIComponent(safeDecode(v))}`;
});
return memo;
Expand Down
27 changes: 9 additions & 18 deletions src/request-response-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
APIGatewayProxyEvent,
Context,
APIGatewayProxyResult,
ALBEvent,
ALBEventRequestContext,
} from 'aws-lambda';
import { StringMap, StringArrayOfStringsMap } from '@silvermine/toolbox';
import { StringArrayOfStringsMap } from '@silvermine/toolbox';

/* COMBO TYPES */

Expand Down Expand Up @@ -54,25 +56,14 @@ export interface APIGatewayRequestEvent extends APIGatewayProxyEvent {}
export interface APIGatewayEventRequestContext extends OrigAPIGatewayEventRequestContext {}


/* APPLICATION LOAD BALANCER TYPES (these are not yet included in aws-lambda) */
/* APPLICATION LOAD BALANCER TYPES (we export these with our own names to make it easier
to modify them if needed at a later time) */

export interface ApplicationLoadBalancerRequestEvent {
body: string | null;
httpMethod: string;
isBase64Encoded: boolean;
path: string;
headers?: StringMap;
multiValueHeaders?: StringArrayOfStringsMap;
queryStringParameters?: StringMap;
multiValueQueryStringParameters?: StringArrayOfStringsMap;
requestContext: ApplicationLoadBalancerEventRequestContext;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ApplicationLoadBalancerRequestEvent extends ALBEvent {}

export interface ApplicationLoadBalancerEventRequestContext {
elb: {
targetGroupArn: string;
};
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ApplicationLoadBalancerEventRequestContext extends ALBEventRequestContext {}


/* OTHER TYPES RELATED TO REQUESTS AND RESPONSES */
Expand Down
5 changes: 4 additions & 1 deletion tests/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const handlerContext = (fillAllFields: boolean = false): Context => {
logGroupName: '/aws/lambda/echo-api-prd-echo',
logStreamName: '2019/01/31/[$LATEST]bb001267fb004ffa8e1710bba30b4ae7',
functionName: 'echo-api-prd-echo',
memoryLimitInMB: 1024,
memoryLimitInMB: '1024',
functionVersion: '$LATEST',
awsRequestId: 'ed6cac60-bb31-4c1f-840d-dd34c80eb9a3',
invokedFunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:echo-api-prd-echo',
Expand Down Expand Up @@ -63,16 +63,19 @@ export const apiGatewayRequestContext = (): APIGatewayEventRequestContext => {
apiKey: null,
apiKeyId: null,
caller: null,
clientCert: null,
cognitoAuthenticationProvider: null,
cognitoAuthenticationType: null,
cognitoIdentityId: null,
cognitoIdentityPoolId: null,
principalOrgId: null,
sourceIp: '12.12.12.12',
user: null,
userAgent: 'curl/7.54.0',
userArn: null,
},
path: '/prd',
protocol: 'HTTP/1.1',
stage: 'prd',
requestId: 'a507736b-259e-11e9-8fcf-4f1f08c4591e',
requestTimeEpoch: 1548969891530,
Expand Down

0 comments on commit d47be8a

Please sign in to comment.