UNPKG

3.02 kBTypeScriptView Raw
1// Types shared between trigger/api-gateway-authorizer.d.ts and api-gateway-proxy.d.ts
2
3// Poorly documented, but API Gateway will just fail internally if
4// the context type does not match this.
5// Note that although non-string types will be accepted, they will be
6// coerced to strings on the other side.
7export interface APIGatewayAuthorizerResultContext {
8 [name: string]: string | number | boolean | null | undefined;
9}
10
11// Default authorizer type, prefer using a specific type with the "...WithAuthorizer..." variant types.
12// Note that this doesn't have to be a context from a custom lambda outhorizer, AWS also has a cognito
13// authorizer type and could add more, so the property won't always be a string.
14export type APIGatewayEventDefaultAuthorizerContext = undefined | null | {
15 [name: string]: any;
16};
17
18export type APIGatewayEventRequestContext =
19 APIGatewayEventRequestContextWithAuthorizer<APIGatewayEventDefaultAuthorizerContext>;
20
21// The requestContext property of both request authorizer and proxy integration events.
22export interface APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext> {
23 accountId: string;
24 apiId: string;
25 // This one is a bit confusing: it is not actually present in authorizer calls
26 // and proxy calls without an authorizer. We model this by allowing undefined in the type,
27 // since it ends up the same and avoids breaking users that are testing the property.
28 // This lets us allow parameterizing the authorizer for proxy events that know what authorizer
29 // context values they have.
30 authorizer: TAuthorizerContext;
31 connectedAt?: number | undefined;
32 connectionId?: string | undefined;
33 domainName?: string | undefined;
34 domainPrefix?: string | undefined;
35 eventType?: string | undefined;
36 extendedRequestId?: string | undefined;
37 protocol: string;
38 httpMethod: string;
39 identity: APIGatewayEventIdentity;
40 messageDirection?: string | undefined;
41 messageId?: string | null | undefined;
42 path: string;
43 stage: string;
44 requestId: string;
45 requestTime?: string | undefined;
46 requestTimeEpoch: number;
47 resourceId: string;
48 resourcePath: string;
49 routeKey?: string | undefined;
50}
51
52export interface APIGatewayEventClientCertificate {
53 clientCertPem: string;
54 serialNumber: string;
55 subjectDN: string;
56 issuerDN: string;
57 validity: {
58 notAfter: string;
59 notBefore: string;
60 };
61}
62
63export interface APIGatewayEventIdentity {
64 accessKey: string | null;
65 accountId: string | null;
66 apiKey: string | null;
67 apiKeyId: string | null;
68 caller: string | null;
69 clientCert: APIGatewayEventClientCertificate | null;
70 cognitoAuthenticationProvider: string | null;
71 cognitoAuthenticationType: string | null;
72 cognitoIdentityId: string | null;
73 cognitoIdentityPoolId: string | null;
74 principalOrgId: string | null;
75 sourceIp: string;
76 user: string | null;
77 userAgent: string | null;
78 userArn: string | null;
79}