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