Skip to content

Commit fc8e96e

Browse files
authoredAug 10, 2021
🤖 Merge PR DefinitelyTyped#54699 Add definitions for AWS CloudFront Functions by @bukka
1 parent d3fcd43 commit fc8e96e

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import {
2+
CloudFrontFunctionEvent,
3+
CloudFrontFunctionContext,
4+
CloudFrontFunctionViewer,
5+
CloudFrontFunctionRequest,
6+
CloudFrontFunctionResponse,
7+
CloudFrontFunctionValueObject,
8+
CloudFrontFunctionResponseCookie,
9+
} from 'aws-cloudfront-function';
10+
11+
const cloudFrontFunctionValue: CloudFrontFunctionValueObject = {
12+
key1: { value: 'text/plain' },
13+
key2: {
14+
value: 't1',
15+
multiValue: [
16+
{ value: 't1' },
17+
{ value: 't2' },
18+
]
19+
},
20+
};
21+
22+
const cloudFrontFunctionResponseCookie: CloudFrontFunctionResponseCookie = {
23+
id: {
24+
value: 'text/plain',
25+
attributes: "Expires=Wed, 05 Apr 2021 07:28:00 GMT",
26+
},
27+
cookie1: {
28+
value: 'val1',
29+
attributes: "Secure; Domain=example.com; Expires=Wed, 05 Apr 2021 07:28:00 GMT",
30+
multiValue: [
31+
{
32+
value: 'val1',
33+
attributes: "Secure; Domain=example.com; Expires=Wed, 05 Apr 2021 07:28:00 GMT",
34+
},
35+
{
36+
value: "val2",
37+
attributes: "Path=/cat; Domain=example.com; Expires=Wed, 10 Jan 2021 07:28:00 GMT",
38+
}
39+
]
40+
},
41+
};
42+
43+
const cloudFrontFunctionRequest: CloudFrontFunctionRequest = {
44+
method: 'GET',
45+
uri: '/test',
46+
querystring: cloudFrontFunctionValue,
47+
headers: cloudFrontFunctionValue,
48+
cookies: cloudFrontFunctionValue,
49+
};
50+
51+
const cloudFrontResponse: CloudFrontFunctionResponse = {
52+
statusCode: 200,
53+
statusDescription: 'OK',
54+
headers: cloudFrontFunctionValue,
55+
cookies: cloudFrontFunctionResponseCookie,
56+
};
57+
58+
const cloudFrontFunctionViewer: CloudFrontFunctionViewer = {
59+
ip: '192.168.0.1',
60+
};
61+
62+
const cloudFrontFunctionContext: CloudFrontFunctionContext = {
63+
distributionDomainName: 'd111111abcdef8.cloudfront.net',
64+
distributionID: 'EDFDVBD6EXAMPLE',
65+
eventType: 'viewer-response',
66+
requestId: 'EXAMPLEntjQpEXAMPLE_SG5Z-EXAMPLEPmPfEXAMPLEu3EqEXAMPLE==',
67+
};
68+
69+
const cloudFrontFunctionEvent: CloudFrontFunctionEvent = {
70+
version: '1.0',
71+
context: cloudFrontFunctionContext,
72+
viewer: cloudFrontFunctionViewer,
73+
request: cloudFrontFunctionRequest,
74+
response: cloudFrontResponse,
75+
};
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Type definitions for non-npm package AWS CloudFront Functions 1.0
2+
// Project: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html
3+
// Definitions by: Jakub Zelenka <https://github.com/bukka>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
// TypeScript Version: 3.0
6+
7+
export interface CloudFrontFunctionEvent {
8+
version: "1.0";
9+
context: CloudFrontFunctionContext;
10+
viewer: CloudFrontFunctionViewer;
11+
request: CloudFrontFunctionRequest;
12+
response: CloudFrontFunctionResponse;
13+
}
14+
15+
export interface CloudFrontFunctionContext {
16+
distributionDomainName: string;
17+
distributionID: string;
18+
eventType: "viewer-request" | "viewer-response";
19+
requestId: string;
20+
}
21+
22+
export interface CloudFrontFunctionViewer {
23+
ip: string;
24+
}
25+
26+
export interface CloudFrontFunctionRequest {
27+
method: string;
28+
uri: string;
29+
querystring: CloudFrontFunctionValueObject;
30+
headers: CloudFrontFunctionValueObject;
31+
cookies: CloudFrontFunctionValueObject;
32+
}
33+
34+
export interface CloudFrontFunctionResponse {
35+
statusCode: number;
36+
statusDescription?: string;
37+
headers: CloudFrontFunctionValueObject;
38+
cookies: CloudFrontFunctionResponseCookie;
39+
}
40+
41+
export interface CloudFrontFunctionValueObject {
42+
[name: string]: {
43+
value: string;
44+
multiValue?: Array<{
45+
value: string;
46+
}>;
47+
};
48+
}
49+
50+
export interface CloudFrontFunctionResponseCookie {
51+
[name: string]: {
52+
value: string;
53+
attributes: string;
54+
multiValue?: Array<{
55+
value: string;
56+
attributes: string;
57+
}>;
58+
};
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictNullChecks": true,
10+
"strictFunctionTypes": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"aws-cloudfront-function-tests.ts"
22+
]
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "dtslint/dt.json"
3+
}

0 commit comments

Comments
 (0)
Please sign in to comment.