1 | import {
|
2 | APIGatewayEventClientCertificate,
|
3 | APIGatewayEventDefaultAuthorizerContext,
|
4 | APIGatewayEventRequestContextWithAuthorizer,
|
5 | } from "../common/api-gateway";
|
6 | import { Callback, CognitoIdentity, 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 |
|
30 | export type APIGatewayProxyWebsocketHandlerV2<T = never> = Handler<
|
31 | APIGatewayProxyWebsocketEventV2,
|
32 | APIGatewayProxyResultV2<T>
|
33 | >;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export type APIGatewayProxyHandlerV2WithJWTAuthorizer<T = never> = Handler<
|
40 | APIGatewayProxyEventV2WithJWTAuthorizer,
|
41 | APIGatewayProxyResultV2<T>
|
42 | >;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | export type APIGatewayProxyHandlerV2WithLambdaAuthorizer<TAuthorizerContext, T = never> = Handler<
|
49 | APIGatewayProxyEventV2WithLambdaAuthorizer<TAuthorizerContext>,
|
50 | APIGatewayProxyResultV2<T>
|
51 | >;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | export type APIGatewayProxyHandlerV2WithIAMAuthorizer<T = never> = Handler<
|
58 | APIGatewayProxyEventV2WithIAMAuthorizer,
|
59 | APIGatewayProxyResultV2<T>
|
60 | >;
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | export type APIGatewayProxyCallbackV2 = Callback<APIGatewayProxyResultV2>;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export type APIGatewayProxyEvent = APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
73 |
|
74 | export type APIGatewayProxyWithLambdaAuthorizerHandler<TAuthorizerContext> = Handler<
|
75 | APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext>,
|
76 | APIGatewayProxyResult
|
77 | >;
|
78 |
|
79 | export type APIGatewayProxyWithCognitoAuthorizerHandler = Handler<
|
80 | APIGatewayProxyWithCognitoAuthorizerEvent,
|
81 | APIGatewayProxyResult
|
82 | >;
|
83 |
|
84 | export type APIGatewayProxyWithLambdaAuthorizerEvent<TAuthorizerContext> = APIGatewayProxyEventBase<
|
85 | APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>
|
86 | >;
|
87 |
|
88 | export type APIGatewayProxyWithLambdaAuthorizerEventRequestContext<TAuthorizerContext> =
|
89 | APIGatewayEventRequestContextWithAuthorizer<APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext>>;
|
90 |
|
91 |
|
92 |
|
93 | export type APIGatewayEventLambdaAuthorizerContext<TAuthorizerContext> =
|
94 | & {
|
95 | [P in keyof TAuthorizerContext]: TAuthorizerContext[P] extends null ? null : string;
|
96 | }
|
97 | & {
|
98 | principalId: string;
|
99 | integrationLatency: number;
|
100 | };
|
101 |
|
102 | export type APIGatewayProxyWithCognitoAuthorizerEvent = APIGatewayProxyEventBase<APIGatewayProxyCognitoAuthorizer>;
|
103 |
|
104 |
|
105 | export interface APIGatewayProxyCognitoAuthorizer {
|
106 | claims: {
|
107 | [name: string]: string;
|
108 | };
|
109 | }
|
110 |
|
111 | export interface APIGatewayProxyEventHeaders {
|
112 | [name: string]: string | undefined;
|
113 | }
|
114 |
|
115 | export interface APIGatewayProxyEventMultiValueHeaders {
|
116 | [name: string]: string[] | undefined;
|
117 | }
|
118 |
|
119 | export interface APIGatewayProxyEventPathParameters {
|
120 | [name: string]: string | undefined;
|
121 | }
|
122 |
|
123 | export interface APIGatewayProxyEventQueryStringParameters {
|
124 | [name: string]: string | undefined;
|
125 | }
|
126 |
|
127 | export interface APIGatewayProxyEventMultiValueQueryStringParameters {
|
128 | [name: string]: string[] | undefined;
|
129 | }
|
130 |
|
131 | export interface APIGatewayProxyEventStageVariables {
|
132 | [name: string]: string | undefined;
|
133 | }
|
134 |
|
135 | export interface APIGatewayProxyEventBase<TAuthorizerContext> {
|
136 | body: string | null;
|
137 | headers: APIGatewayProxyEventHeaders;
|
138 | multiValueHeaders: APIGatewayProxyEventMultiValueHeaders;
|
139 | httpMethod: string;
|
140 | isBase64Encoded: boolean;
|
141 | path: string;
|
142 | pathParameters: APIGatewayProxyEventPathParameters | null;
|
143 | queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
|
144 | multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
|
145 | stageVariables: APIGatewayProxyEventStageVariables | null;
|
146 | requestContext: APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext>;
|
147 | resource: string;
|
148 | }
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | export interface APIGatewayProxyResult {
|
155 | statusCode: number;
|
156 | headers?:
|
157 | | {
|
158 | [header: string]: boolean | number | string;
|
159 | }
|
160 | | undefined;
|
161 | multiValueHeaders?:
|
162 | | {
|
163 | [header: string]: Array<boolean | number | string>;
|
164 | }
|
165 | | undefined;
|
166 | body: string;
|
167 | isBase64Encoded?: boolean | undefined;
|
168 | }
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | export interface APIGatewayEventRequestContextV2 {
|
175 | accountId: string;
|
176 | apiId: string;
|
177 | authentication?: {
|
178 | clientCert: APIGatewayEventClientCertificate;
|
179 | };
|
180 | domainName: string;
|
181 | domainPrefix: string;
|
182 | http: {
|
183 | method: string;
|
184 | path: string;
|
185 | protocol: string;
|
186 | sourceIp: string;
|
187 | userAgent: string;
|
188 | };
|
189 | requestId: string;
|
190 | routeKey: string;
|
191 | stage: string;
|
192 | time: string;
|
193 | timeEpoch: number;
|
194 | }
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | export interface APIGatewayEventWebsocketRequestContextV2 {
|
201 | routeKey: string;
|
202 | messageId: string;
|
203 | eventType: "CONNECT" | "MESSAGE" | "DISCONNECT";
|
204 | extendedRequestId: string;
|
205 | requestTime: string;
|
206 | messageDirection: "IN";
|
207 | stage: string;
|
208 | connectedAt: number;
|
209 | requestTimeEpoch: number;
|
210 | requestId: string;
|
211 | domainName: string;
|
212 | connectionId: string;
|
213 | apiId: string;
|
214 | }
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | export interface APIGatewayProxyEventV2WithRequestContext<TRequestContext> {
|
220 | version: string;
|
221 | routeKey: string;
|
222 | rawPath: string;
|
223 | rawQueryString: string;
|
224 | cookies?: string[];
|
225 | headers: APIGatewayProxyEventHeaders;
|
226 | queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
227 | requestContext: TRequestContext;
|
228 | body?: string;
|
229 | pathParameters?: APIGatewayProxyEventPathParameters;
|
230 | isBase64Encoded: boolean;
|
231 | stageVariables?: APIGatewayProxyEventStageVariables;
|
232 | }
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | export interface APIGatewayProxyWebsocketEventV2WithRequestContext<TRequestContext> {
|
238 | requestContext: TRequestContext;
|
239 | body?: string;
|
240 | isBase64Encoded: boolean;
|
241 | stageVariables?: APIGatewayProxyEventStageVariables;
|
242 | }
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | export interface APIGatewayEventRequestContextLambdaAuthorizer<TAuthorizerContext> {
|
248 | lambda: TAuthorizerContext;
|
249 | }
|
250 |
|
251 |
|
252 |
|
253 |
|
254 | export interface APIGatewayEventRequestContextJWTAuthorizer {
|
255 | principalId: string;
|
256 | integrationLatency: number;
|
257 | jwt: {
|
258 | claims: { [name: string]: string | number | boolean | string[] };
|
259 | scopes: string[];
|
260 | };
|
261 | }
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | export interface APIGatewayEventRequestContextIAMAuthorizer {
|
267 | iam: {
|
268 | accessKey: string;
|
269 | accountId: string;
|
270 | callerId: string;
|
271 | cognitoIdentity: null;
|
272 | principalOrgId: string;
|
273 | userArn: string;
|
274 | userId: string;
|
275 | };
|
276 | }
|
277 |
|
278 | export type APIGatewayProxyEventV2WithJWTAuthorizer = APIGatewayProxyEventV2WithRequestContext<
|
279 | APIGatewayEventRequestContextV2WithAuthorizer<APIGatewayEventRequestContextJWTAuthorizer>
|
280 | >;
|
281 |
|
282 | export type APIGatewayProxyEventV2WithLambdaAuthorizer<TAuthorizerContext> = APIGatewayProxyEventV2WithRequestContext<
|
283 | APIGatewayEventRequestContextV2WithAuthorizer<APIGatewayEventRequestContextLambdaAuthorizer<TAuthorizerContext>>
|
284 | >;
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | export type APIGatewayProxyEventV2WithIAMAuthorizer = APIGatewayProxyEventV2WithRequestContext<
|
290 | APIGatewayEventRequestContextV2WithAuthorizer<APIGatewayEventRequestContextIAMAuthorizer>
|
291 | >;
|
292 |
|
293 | export interface APIGatewayEventRequestContextV2WithAuthorizer<TAuthorizer> extends APIGatewayEventRequestContextV2 {
|
294 | authorizer: TAuthorizer;
|
295 | }
|
296 |
|
297 |
|
298 |
|
299 |
|
300 | export type APIGatewayProxyEventV2 = APIGatewayProxyEventV2WithRequestContext<APIGatewayEventRequestContextV2>;
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | export type APIGatewayProxyWebsocketEventV2 = APIGatewayProxyWebsocketEventV2WithRequestContext<
|
306 | APIGatewayEventWebsocketRequestContextV2
|
307 | >;
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 | export type APIGatewayProxyResultV2<T = never> = APIGatewayProxyStructuredResultV2 | string | T;
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | export interface APIGatewayProxyStructuredResultV2 {
|
321 | statusCode?: number | undefined;
|
322 | headers?:
|
323 | | {
|
324 | [header: string]: boolean | number | string;
|
325 | }
|
326 | | undefined;
|
327 | body?: string | undefined;
|
328 | isBase64Encoded?: boolean | undefined;
|
329 | cookies?: string[] | undefined;
|
330 | }
|
331 |
|
332 |
|
333 | export type ProxyHandler = APIGatewayProxyHandler;
|
334 | export type ProxyCallback = APIGatewayProxyCallback;
|
335 | export type APIGatewayEvent = APIGatewayProxyEvent;
|
336 | export type ProxyResult = APIGatewayProxyResult;
|