UNPKG

3.04 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 =
15 | undefined
16 | null
17 | {
18 [name: string]: any;
19 };
20
21export type APIGatewayEventRequestContext = APIGatewayEventRequestContextWithAuthorizer<
22 APIGatewayEventDefaultAuthorizerContext
23>;
24
25// The requestContext property of both request authorizer and proxy integration events.
26export interface APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext> {
27 accountId: string;
28 apiId: string;
29 // This one is a bit confusing: it is not actually present in authorizer calls
30 // and proxy calls without an authorizer. We model this by allowing undefined in the type,
31 // since it ends up the same and avoids breaking users that are testing the property.
32 // This lets us allow parameterizing the authorizer for proxy events that know what authorizer
33 // context values they have.
34 authorizer: TAuthorizerContext;
35 connectedAt?: number | undefined;
36 connectionId?: string | undefined;
37 domainName?: string | undefined;
38 domainPrefix?: string | undefined;
39 eventType?: string | undefined;
40 extendedRequestId?: string | undefined;
41 protocol: string;
42 httpMethod: string;
43 identity: APIGatewayEventIdentity;
44 messageDirection?: string | undefined;
45 messageId?: string | null | undefined;
46 path: string;
47 stage: string;
48 requestId: string;
49 requestTime?: string | undefined;
50 requestTimeEpoch: number;
51 resourceId: string;
52 resourcePath: string;
53 routeKey?: string | undefined;
54}
55
56export interface APIGatewayEventClientCertificate {
57 clientCertPem: string;
58 serialNumber: string;
59 subjectDN: string;
60 issuerDN: string;
61 validity: {
62 notAfter: string;
63 notBefore: string;
64 };
65}
66
67export interface APIGatewayEventIdentity {
68 accessKey: string | null;
69 accountId: string | null;
70 apiKey: string | null;
71 apiKeyId: string | null;
72 caller: string | null;
73 clientCert: APIGatewayEventClientCertificate | null;
74 cognitoAuthenticationProvider: string | null;
75 cognitoAuthenticationType: string | null;
76 cognitoIdentityId: string | null;
77 cognitoIdentityPoolId: string | null;
78 principalOrgId: string | null;
79 sourceIp: string;
80 user: string | null;
81 userAgent: string | null;
82 userArn: string | null;
83}