UNPKG

2.91 kBTypeScriptView Raw
1import {
2 APIGatewayEventDefaultAuthorizerContext,
3 APIGatewayEventRequestContextWithAuthorizer,
4} from "../common/api-gateway";
5import { Callback, Handler } from "../handler";
6
7export type APIGatewayProxyHandler = Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
8export type APIGatewayProxyCallback = Callback<APIGatewayProxyResult>;
9
10export type APIGatewayProxyEvent = APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
11
12export type APIGatewayProxyWithLambdaAuthorizerHandler<TAuthorizerContext> =
13 Handler<APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext>, APIGatewayProxyResult>;
14
15export type APIGatewayProxyWithCognitoAuthorizerHandler =
16 Handler<APIGatewayProxyWithCognitoAuthorizerEvent, APIGatewayProxyResult>;
17
18export type APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext> =
19 APIGatewayProxyEventBase<APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>>;
20
21export type APIGatewayProxyWithLambdaAuthorizerEventRequestContext<TAuthorizerContext> =
22 APIGatewayEventRequestContextWithAuthorizer<APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>>;
23
24// API Gateway proxy integration mangles the context from a custom authorizer,
25// converting all number or boolean properties to string, and adding some extra properties.
26export type APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext> = {
27 [P in keyof TAuthorizerContext]: TAuthorizerContext[P] extends null ? null : string;
28} & {
29 principalId: string;
30 integrationLatency: number;
31};
32
33export type APIGatewayProxyWithCognitoAuthorizerEvent = APIGatewayProxyEventBase<APIGatewayProxyCognitoAuthorizer>;
34
35// All claims are coerced into strings.
36export interface APIGatewayProxyCognitoAuthorizer {
37 claims: {
38 [name: string]: string;
39 };
40}
41
42export interface APIGatewayProxyEventBase<TAuthorizerContext> {
43 body: string | null;
44 headers: { [name: string]: string };
45 multiValueHeaders: { [name: string]: string[] };
46 httpMethod: string;
47 isBase64Encoded: boolean;
48 path: string;
49 pathParameters: { [name: string]: string } | null;
50 queryStringParameters: { [name: string]: string } | null;
51 multiValueQueryStringParameters: { [name: string]: string[] } | null;
52 stageVariables: { [name: string]: string } | null;
53 requestContext: APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext>;
54 resource: string;
55}
56
57export interface APIGatewayProxyResult {
58 statusCode: number;
59 headers?: {
60 [header: string]: boolean | number | string;
61 };
62 multiValueHeaders?: {
63 [header: string]: Array<boolean | number | string>;
64 };
65 body: string;
66 isBase64Encoded?: boolean;
67}
68
69// Legacy names
70export type ProxyHandler = APIGatewayProxyHandler;
71export type ProxyCallback = APIGatewayProxyCallback;
72export type APIGatewayEvent = APIGatewayProxyEvent;
73export type ProxyResult = APIGatewayProxyResult;