Skip to content

Commit c5ffd2e

Browse files
authored
🤖 Merge PR DefinitelyTyped#74556 feat(aws-cloudfront-function): add helper function and metadata prop by @ssssota
1 parent d168428 commit c5ffd2e

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

‎types/aws-cloudfront-function/aws-cloudfront-function-tests.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ const cloudFrontFunctionEvent: AWSCloudFrontFunction.Event = {
8383
version: "1.0",
8484
context: cloudFrontFunctionContext,
8585
viewer: cloudFrontFunctionViewer,
86-
request: cloudFrontFunctionRequest,
86+
request: {
87+
...cloudFrontFunctionRequest,
88+
rawQueryString() {
89+
return undefined;
90+
},
91+
},
8792
response: cloudFrontResponse,
8893
};
8994

@@ -199,3 +204,11 @@ function testCreateRequestOriginGroup() {
199204
};
200205
cf.createRequestOriginGroup(params);
201206
}
207+
208+
function testEdgeLocation() {
209+
cf.edgeLocation = {
210+
name: "SEA",
211+
serverIp: "1.2.3.4",
212+
region: "us-west-2",
213+
};
214+
}

‎types/aws-cloudfront-function/index.d.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare namespace AWSCloudFrontFunction {
33
version: "1.0";
44
context: Context;
55
viewer: Viewer;
6-
request: Request;
6+
request: Request & RequestMethods;
77
response: Response;
88
}
99

@@ -26,6 +26,17 @@ declare namespace AWSCloudFrontFunction {
2626
cookies: ValueObject;
2727
}
2828

29+
interface RequestMethods {
30+
/**
31+
* Use the rawQueryString() method to retrieve the unparsed and unaltered query string as a string.
32+
* @returns Returns the full query string of the incoming request as a string value without the leading ?.
33+
* - If there isn't a query string, but the ? is present, the functions returns an empty string.
34+
* - If there isn't a query string and the ? isn't present, the function returns undefined.
35+
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/general-helper-methods.html#raw-query-string-method
36+
*/
37+
rawQueryString(): string | undefined;
38+
}
39+
2940
interface Response {
3041
statusCode: number;
3142
statusDescription?: string;
@@ -225,11 +236,35 @@ declare module "cloudfront" {
225236
*/
226237
function createRequestOriginGroup(params: CreateRequestOriginGroupParams): void;
227238

239+
/**
240+
* Use this JavaScript object to obtain the edge location airport code,
241+
* expected Regional Edge Cache region or the CloudFront server IP address used to handle the request.
242+
* This metadata is available only the viewer request event trigger.
243+
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/general-helper-methods.html#edge-location-metadata
244+
*/
245+
interface EdgeLocation {
246+
/**
247+
* The three-letter IATA code of the edge location that handled the request.
248+
*/
249+
name: string;
250+
/**
251+
* The IPv4 or IPv6 address of the server that handled the request.
252+
*/
253+
serverIp: string;
254+
/**
255+
* The CloudFront Regional Edge Cache (REC) that the request is expected to use if there is a cache miss.
256+
* This value is not updated in the event that the expected REC is unavailable and a backup REC is used for the request.
257+
* This doesn't include the Origin Shield location being used, except in cases when the primary REC and the Origin Shield are the same location.
258+
*/
259+
region: string;
260+
}
261+
228262
const cf: {
229263
kvs: typeof kvs;
230264
updateRequestOrigin: typeof updateRequestOrigin;
231265
selectRequestOriginById: typeof selectRequestOriginById;
232266
createRequestOriginGroup: typeof createRequestOriginGroup;
267+
edgeLocation: EdgeLocation;
233268
};
234269

235270
export default cf;

0 commit comments

Comments
 (0)