Skip to content

Commit 70d69fa

Browse files
author
Sam Der
authored
🤖 Merge PR DefinitelyTyped#72971 feat: Add exported type for CloudFront response records by @samderanova
1 parent a784917 commit 70d69fa

File tree

2 files changed

+136
-6
lines changed

2 files changed

+136
-6
lines changed

‎types/aws-lambda/test/cloudfront-tests.ts‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
CloudFrontRequestHandler,
88
CloudFrontRequestResult,
99
CloudFrontResponseEvent,
10+
CloudFrontResponseEventRecord,
1011
CloudFrontResponseHandler,
1112
CloudFrontResponseResult,
1213
CloudFrontS3Origin,
@@ -554,6 +555,133 @@ const originResponseEvent: CloudFrontResponseEvent = {
554555
],
555556
};
556557

558+
const originResponseEventRecord: CloudFrontResponseEventRecord = {
559+
cf: {
560+
config: {
561+
distributionDomainName: "d111111abcdef8.cloudfront.net",
562+
distributionId: "EDFDVBD6EXAMPLE",
563+
eventType: "origin-response",
564+
requestId: "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==",
565+
},
566+
request: {
567+
clientIp: "203.0.113.178",
568+
headers: {
569+
"x-forwarded-for": [
570+
{
571+
key: "X-Forwarded-For",
572+
value: "203.0.113.178",
573+
},
574+
],
575+
"user-agent": [
576+
{
577+
key: "User-Agent",
578+
value: "Amazon CloudFront",
579+
},
580+
],
581+
via: [
582+
{
583+
key: "Via",
584+
value: "2.0 8f22423015641505b8c857a37450d6c0.cloudfront.net (CloudFront)",
585+
},
586+
],
587+
host: [
588+
{
589+
key: "Host",
590+
value: "example.org",
591+
},
592+
],
593+
"cache-control": [
594+
{
595+
key: "Cache-Control",
596+
value: "no-cache, cf-no-cache",
597+
},
598+
],
599+
},
600+
method: "GET",
601+
origin: {
602+
custom: {
603+
customHeaders: {},
604+
domainName: "example.org",
605+
keepaliveTimeout: 5,
606+
path: "",
607+
port: 443,
608+
protocol: "https",
609+
readTimeout: 30,
610+
sslProtocols: ["TLSv1", "TLSv1.1", "TLSv1.2"],
611+
},
612+
},
613+
querystring: "",
614+
uri: "/",
615+
},
616+
response: {
617+
headers: {
618+
"access-control-allow-credentials": [
619+
{
620+
key: "Access-Control-Allow-Credentials",
621+
value: "true",
622+
},
623+
],
624+
"access-control-allow-origin": [
625+
{
626+
key: "Access-Control-Allow-Origin",
627+
value: "*",
628+
},
629+
],
630+
date: [
631+
{
632+
key: "Date",
633+
value: "Mon, 13 Jan 2020 20:12:38 GMT",
634+
},
635+
],
636+
"referrer-policy": [
637+
{
638+
key: "Referrer-Policy",
639+
value: "no-referrer-when-downgrade",
640+
},
641+
],
642+
server: [
643+
{
644+
key: "Server",
645+
value: "ExampleCustomOriginServer",
646+
},
647+
],
648+
"x-content-type-options": [
649+
{
650+
key: "X-Content-Type-Options",
651+
value: "nosniff",
652+
},
653+
],
654+
"x-frame-options": [
655+
{
656+
key: "X-Frame-Options",
657+
value: "DENY",
658+
},
659+
],
660+
"x-xss-protection": [
661+
{
662+
key: "X-XSS-Protection",
663+
value: "1; mode=block",
664+
},
665+
],
666+
"content-type": [
667+
{
668+
key: "Content-Type",
669+
value: "text/html; charset=utf-8",
670+
},
671+
],
672+
"content-length": [
673+
{
674+
key: "Content-Length",
675+
value: "9593",
676+
},
677+
],
678+
},
679+
status: "200",
680+
statusDescription: "OK",
681+
},
682+
},
683+
};
684+
557685
const cloudFrontFunctionsEvent: CloudFrontFunctionsEvent = {
558686
version: "1.0",
559687
context: {

‎types/aws-lambda/trigger/cloudfront-response.d.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import { Callback, Handler } from "../handler";
44
export type CloudFrontResponseHandler = Handler<CloudFrontResponseEvent, CloudFrontResponseResult>;
55
export type CloudFrontResponseCallback = Callback<CloudFrontResponseResult>;
66

7+
export interface CloudFrontResponseEventRecord {
8+
cf: CloudFrontEvent & {
9+
readonly request: Pick<CloudFrontRequest, Exclude<keyof CloudFrontRequest, "body">>;
10+
response: CloudFrontResponse;
11+
};
12+
}
13+
714
/**
815
* CloudFront viewer response or origin response event
916
*
1017
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-response
1118
*/
1219
export interface CloudFrontResponseEvent {
13-
Records: Array<{
14-
cf: CloudFrontEvent & {
15-
readonly request: Pick<CloudFrontRequest, Exclude<keyof CloudFrontRequest, "body">>;
16-
response: CloudFrontResponse;
17-
};
18-
}>;
20+
Records: CloudFrontResponseEventRecord[];
1921
}
2022

2123
export type CloudFrontResponseResult = undefined | null | CloudFrontResultResponse;

0 commit comments

Comments
 (0)