-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add support for APIGWv2 protocol (#64) #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,35 @@ | |
|
||
import { | ||
APIGatewayEventRequestContext as OrigAPIGatewayEventRequestContext, | ||
APIGatewayEventRequestContextV2 as OrigAPIGatewayEventRequestContextV2, | ||
APIGatewayProxyEvent, | ||
APIGatewayProxyEventV2, | ||
Context, | ||
APIGatewayProxyResult, | ||
APIGatewayProxyStructuredResultV2, | ||
ALBEvent, | ||
ALBEventRequestContext, | ||
ALBResult, | ||
} from 'aws-lambda'; | ||
import { StringMap, StringArrayOfStringsMap } from '@silvermine/toolbox'; | ||
|
||
/* COMBO TYPES */ | ||
|
||
/** | ||
* The `evt` argument passed to a Lambda handler that represents the request (from API | ||
* Gateway or ALB). | ||
*/ | ||
export type RequestEvent = ApplicationLoadBalancerRequestEvent | APIGatewayRequestEvent; | ||
export type RequestEvent = ApplicationLoadBalancerRequestEvent | APIGatewayRequestEvent | APIGatewayRequestEventV2; | ||
|
||
/** | ||
* The "request context", which is accessible at `evt.requestContext`. | ||
*/ | ||
export type RequestEventRequestContext = APIGatewayEventRequestContext | ApplicationLoadBalancerEventRequestContext; | ||
|
||
export interface ResponseResult extends APIGatewayProxyResult { | ||
multiValueHeaders: StringArrayOfStringsMap; | ||
statusDescription?: string; | ||
export type ResponseResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2 | ALBResult; | ||
|
||
export function isALBResult(evt: ResponseResult, test: boolean): evt is ALBResult { | ||
// TODO - this type gaurd doesn't do any useful checking | ||
return test && 'statusCode' in evt; | ||
} | ||
Comment on lines
+31
to
34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flagging this TODO for feedback on this approach to using a type guard. Doesn't seem to be any attributes that can consistently be used to differentiate between the types. So seems like we can either: |
||
|
||
/** | ||
|
@@ -51,29 +58,23 @@ if needed at a later time) */ | |
export interface APIGatewayRequestEvent extends APIGatewayProxyEvent {} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface APIGatewayEventRequestContext extends OrigAPIGatewayEventRequestContext {} | ||
export interface APIGatewayRequestEventV2 extends APIGatewayProxyEventV2 {} | ||
|
||
export function isAPIGatewayRequestEventV2(evt: RequestEvent): evt is APIGatewayRequestEventV2 { | ||
return ('apiId' in evt.requestContext && 'version' in evt && evt.version === '2.0'); | ||
} | ||
|
||
/* APPLICATION LOAD BALANCER TYPES (these are not yet included in aws-lambda) */ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface APIGatewayEventRequestContext extends OrigAPIGatewayEventRequestContext {} | ||
|
||
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 APIGatewayEventRequestContextV2 extends OrigAPIGatewayEventRequestContextV2 {} | ||
|
||
export interface ApplicationLoadBalancerEventRequestContext { | ||
elb: { | ||
targetGroupArn: string; | ||
}; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ApplicationLoadBalancerRequestEvent extends ALBEvent {} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ApplicationLoadBalancerEventRequestContext extends ALBEventRequestContext {} | ||
|
||
/* OTHER TYPES RELATED TO REQUESTS AND RESPONSES */ | ||
export interface CookieOpts { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flagging TODO for feedback.