1 | import {
|
2 | APIGatewayEventClientCertificate,
|
3 | APIGatewayEventDefaultAuthorizerContext,
|
4 | APIGatewayEventRequestContextWithAuthorizer,
|
5 | } from '../common/api-gateway';
|
6 | import { Callback, Handler } from '../handler';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export type APIGatewayProxyHandler = Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export type APIGatewayProxyCallback = Callback<APIGatewayProxyResult>;
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export type APIGatewayProxyHandlerV2<T = never> = Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2<T>>;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export type APIGatewayProxyHandlerV2WithJWTAuthorizer<T = never> = Handler<
|
30 | APIGatewayProxyEventV2WithJWTAuthorizer,
|
31 | APIGatewayProxyResultV2<T>
|
32 | >;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | export type APIGatewayProxyHandlerV2WithLambdaAuthorizer<TAuthorizerContext, T = never> = Handler<
|
39 | APIGatewayProxyEventV2WithLambdaAuthorizer<TAuthorizerContext>,
|
40 | APIGatewayProxyResultV2<T>
|
41 | >;
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export type APIGatewayProxyCallbackV2 = Callback<APIGatewayProxyResultV2>;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | export type APIGatewayProxyEvent = APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
54 |
|
55 | export type APIGatewayProxyWithLambdaAuthorizerHandler<TAuthorizerContext> =
|
56 | Handler<APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext>, APIGatewayProxyResult>;
|
57 |
|
58 | export type APIGatewayProxyWithCognitoAuthorizerHandler =
|
59 | Handler<APIGatewayProxyWithCognitoAuthorizerEvent, APIGatewayProxyResult>;
|
60 |
|
61 | export type APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext> =
|
62 | APIGatewayProxyEventBase<APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>>;
|
63 |
|
64 | export type APIGatewayProxyWithLambdaAuthorizerEventRequestContext<TAuthorizerContext> =
|
65 | APIGatewayEventRequestContextWithAuthorizer<APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>>;
|
66 |
|
67 |
|
68 |
|
69 | export type APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext> = {
|
70 | [P in keyof TAuthorizerContext]: TAuthorizerContext[P] extends null ? null : string;
|
71 | } & {
|
72 | principalId: string;
|
73 | integrationLatency: number;
|
74 | };
|
75 |
|
76 | export type APIGatewayProxyWithCognitoAuthorizerEvent = APIGatewayProxyEventBase<APIGatewayProxyCognitoAuthorizer>;
|
77 |
|
78 |
|
79 | export interface APIGatewayProxyCognitoAuthorizer {
|
80 | claims: {
|
81 | [name: string]: string;
|
82 | };
|
83 | }
|
84 |
|
85 | export interface APIGatewayProxyEventHeaders {
|
86 | [name: string]: string | undefined;
|
87 | }
|
88 |
|
89 | export interface APIGatewayProxyEventMultiValueHeaders {
|
90 | [name: string]: string[] | undefined;
|
91 | }
|
92 |
|
93 | export interface APIGatewayProxyEventPathParameters {
|
94 | [name: string]: string | undefined;
|
95 | }
|
96 |
|
97 | export interface APIGatewayProxyEventQueryStringParameters {
|
98 | [name: string]: string | undefined;
|
99 | }
|
100 |
|
101 | export interface APIGatewayProxyEventMultiValueQueryStringParameters {
|
102 | [name: string]: string[] | undefined;
|
103 | }
|
104 |
|
105 | export interface APIGatewayProxyEventStageVariables {
|
106 | [name: string]: string | undefined;
|
107 | }
|
108 |
|
109 | export interface APIGatewayProxyEventBase<TAuthorizerContext> {
|
110 | body: string | null;
|
111 | headers: APIGatewayProxyEventHeaders;
|
112 | multiValueHeaders: APIGatewayProxyEventMultiValueHeaders;
|
113 | httpMethod: string;
|
114 | isBase64Encoded: boolean;
|
115 | path: string;
|
116 | pathParameters: APIGatewayProxyEventPathParameters | null;
|
117 | queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
|
118 | multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
|
119 | stageVariables: APIGatewayProxyEventStageVariables | null;
|
120 | requestContext: APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext>;
|
121 | resource: string;
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | export interface APIGatewayProxyResult {
|
129 | statusCode: number;
|
130 | headers?: {
|
131 | [header: string]: boolean | number | string;
|
132 | } | undefined;
|
133 | multiValueHeaders?: {
|
134 | [header: string]: Array<boolean | number | string>;
|
135 | } | undefined;
|
136 | body: string;
|
137 | isBase64Encoded?: boolean | undefined;
|
138 | }
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | export interface APIGatewayEventRequestContextV2 {
|
145 | accountId: string;
|
146 | apiId: string;
|
147 | authentication?: {
|
148 | clientCert: APIGatewayEventClientCertificate;
|
149 | };
|
150 | domainName: string;
|
151 | domainPrefix: string;
|
152 | http: {
|
153 | method: string;
|
154 | path: string;
|
155 | protocol: string;
|
156 | sourceIp: string;
|
157 | userAgent: string;
|
158 | };
|
159 | requestId: string;
|
160 | routeKey: string;
|
161 | stage: string;
|
162 | time: string;
|
163 | timeEpoch: number;
|
164 | }
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | export interface APIGatewayProxyEventV2WithRequestContext<TRequestContext> {
|
170 | version: string;
|
171 | routeKey: string;
|
172 | rawPath: string;
|
173 | rawQueryString: string;
|
174 | cookies?: string[];
|
175 | headers: APIGatewayProxyEventHeaders;
|
176 | queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
177 | requestContext: TRequestContext;
|
178 | body?: string;
|
179 | pathParameters?: APIGatewayProxyEventPathParameters;
|
180 | isBase64Encoded: boolean;
|
181 | stageVariables?: APIGatewayProxyEventStageVariables;
|
182 | }
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | export interface APIGatewayEventRequestContextLambdaAuthorizer<TAuthorizerContext> {
|
188 | lambda: TAuthorizerContext;
|
189 | }
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | export interface APIGatewayEventRequestContextJWTAuthorizer {
|
195 | principalId: string;
|
196 | integrationLatency: number;
|
197 | jwt: {
|
198 | claims: { [name: string]: string | number | boolean | string[] };
|
199 | scopes: string[];
|
200 | };
|
201 | }
|
202 |
|
203 | export type APIGatewayProxyEventV2WithJWTAuthorizer = APIGatewayProxyEventV2WithRequestContext<
|
204 | APIGatewayEventRequestContextV2WithAuthorizer<APIGatewayEventRequestContextJWTAuthorizer>
|
205 | >;
|
206 |
|
207 | export type APIGatewayProxyEventV2WithLambdaAuthorizer<TAuthorizerContext> = APIGatewayProxyEventV2WithRequestContext<
|
208 | APIGatewayEventRequestContextV2WithAuthorizer<APIGatewayEventRequestContextLambdaAuthorizer<TAuthorizerContext>>
|
209 | >;
|
210 |
|
211 | export interface APIGatewayEventRequestContextV2WithAuthorizer<TAuthorizer> extends APIGatewayEventRequestContextV2 {
|
212 | authorizer: TAuthorizer;
|
213 | }
|
214 |
|
215 |
|
216 |
|
217 |
|
218 | export type APIGatewayProxyEventV2 = APIGatewayProxyEventV2WithRequestContext<APIGatewayEventRequestContextV2>;
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | export type APIGatewayProxyResultV2<T = never> = APIGatewayProxyStructuredResultV2 | string | T;
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | export interface APIGatewayProxyStructuredResultV2 {
|
232 | statusCode?: number | undefined;
|
233 | headers?: {
|
234 | [header: string]: boolean | number | string;
|
235 | } | undefined;
|
236 | body?: string | undefined;
|
237 | isBase64Encoded?: boolean | undefined;
|
238 | cookies?: string[] | undefined;
|
239 | }
|
240 |
|
241 |
|
242 | export type ProxyHandler = APIGatewayProxyHandler;
|
243 | export type ProxyCallback = APIGatewayProxyCallback;
|
244 | export type APIGatewayEvent = APIGatewayProxyEvent;
|
245 | export type ProxyResult = APIGatewayProxyResult;
|