Skip to content

Commit e7d5d04

Browse files
authored
🤖 Merge PR DefinitelyTyped#74171 Updating akamai-edgeworkers to add BotScore object by @aniefer
1 parent 7c0fbf8 commit e7d5d04

File tree

4 files changed

+101
-8
lines changed

4 files changed

+101
-8
lines changed

‎types/akamai-edgeworkers/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ with the following stubs:
3131

3232
export function onClientRequest(request: EW.IngressClientRequest) {}
3333
export function onOriginRequest(request: EW.IngressOriginRequest) {}
34+
export function onBotSegmentAvailable(request: EW.BotSegmentAvailableRequest) {}
3435
export function responseProvider(request: EW.ResponseProviderRequest) {}
3536
export function onOriginResponse(request: EW.EgressOriginRequest, response: EW.EgressOriginResponse) {}
3637
export function onClientResponse(request: EW.EgressClientRequest, response: EW.EgressClientResponse) {}

‎types/akamai-edgeworkers/index.d.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,69 @@ declare namespace EW {
164164
readonly cacheKey: CacheKey;
165165
}
166166

167+
interface BotScore {
168+
/**
169+
* An object for interacting with features related to Bot Management
170+
*/
171+
readonly responseSegment: BotScoreResponseSegment;
172+
}
173+
174+
interface BotScoreResponseSegment {
175+
/**
176+
* Indicates that this request hasn't triggered any detections, resulting in a bot score of zero.
177+
*/
178+
isHuman(): boolean;
179+
180+
/**
181+
* Indicates that this request has a low bot score.
182+
*
183+
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
184+
*/
185+
isCautiousResponse(): boolean;
186+
187+
/**
188+
* Indicates that this request has a middling bot score. You should apply a challenge to the traffic in this
189+
* segment to prohibit bots but let humans through.
190+
*
191+
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
192+
*/
193+
isStrictResponse(): boolean;
194+
195+
/**
196+
* Indicates that this request is from a special class of traffic that Bot Manager sets aside.
197+
* There are cases where a human could get endlessly trapped by certain detections, such as a network-based
198+
* or device-based detection like user-agent. This detection would trip every request, but the person
199+
* could never change the trigger. Where there's this danger that a human could never overcome a detection
200+
* and get stuck, Bot Manager sets aside requests in a special response segment called Safeguard,
201+
* so you can handle them differently. For best results, when you set bot score, leave Safeguard Traffic
202+
* at the preset Strict Response if it uses a challenge action to let clients prove they are
203+
* human and get through.
204+
*
205+
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
206+
*/
207+
isSafeguardResponse(): boolean;
208+
209+
/**
210+
* Indicates that this request has a high bot score, which is more likely to be from a bot.
211+
*
212+
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
213+
*/
214+
isAggressiveResponse(): boolean;
215+
216+
/**
217+
* Indicates that this request has an unknown bot score. This field is left as a placeholder for
218+
* forwards compatibility.
219+
*/
220+
isUnexpected(): boolean;
221+
}
222+
223+
interface HasBotScore {
224+
/**
225+
* Object containing properties related to Bot Management.
226+
*/
227+
readonly botScore: BotScore;
228+
}
229+
167230
interface ReadsBody {
168231
/**
169232
* A promise that reads the body to completion and resolves to a string containing the full
@@ -460,6 +523,12 @@ declare namespace EW {
460523
{
461524
}
462525

526+
// onBotSegmentAvailable
527+
interface BotSegmentAvailableRequest
528+
extends ReadsHeaders, ReadAllHeader, ReadsVariables, MutatesVariables, Request, HasRespondWith, HasBotScore
529+
{
530+
}
531+
463532
// onOriginRequest
464533
interface IngressOriginRequest
465534
extends MutatesHeaders, ReadsHeaders, ReadAllHeader, ReadsVariables, Request, HasRespondWith, MutatesVariables
@@ -718,6 +787,7 @@ declare namespace EW {
718787
}
719788

720789
export {
790+
BotSegmentAvailableRequest,
721791
EgressClientRequest,
722792
EgressClientResponse,
723793
EgressOriginRequest,

‎types/akamai-edgeworkers/package.json‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@
1212
},
1313
"owners": [
1414
{
15-
"name": "Evan Hughes",
16-
"githubUsername": "evan-hughes"
15+
"name": "Chris Daley",
16+
"githubUsername": "cdaley-akamai"
1717
},
1818
{
1919
"name": "Will Bain",
2020
"githubUsername": "wabain"
2121
},
2222
{
23-
"name": "Swathi Bala",
24-
"githubUsername": "swathimr"
23+
"name": "Yana Kadiysk",
24+
"githubUsername": "yanakad"
2525
},
2626
{
27-
"name": "Aman Nanner",
28-
"githubUsername": "ananner"
27+
"name": "Miranda Lim",
28+
"githubUsername": "miliworking"
2929
},
3030
{
31-
"name": "Ben Matthews",
32-
"githubUsername": "bmatthew"
31+
"name": "Luca Perra",
32+
"githubUsername": "lperra"
3333
}
3434
]
3535
}

‎types/akamai-edgeworkers/test/akamai-edgeworkers-global.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ export function onClientRequest(request: EW.IngressClientRequest) {
2424
}
2525
}
2626

27+
export function onBogSegmentAvailable(request: EW.BotSegmentAvailableRequest) {
28+
// Exercise headers
29+
testHeaders(request.getHeaders());
30+
31+
// Exercise botScore
32+
request.botScore.responseSegment.isHuman() === true;
33+
request.botScore.responseSegment.isCautiousResponse() === true;
34+
request.botScore.responseSegment.isStrictResponse() === true;
35+
request.botScore.responseSegment.isSafeguardResponse() === true;
36+
request.botScore.responseSegment.isAggressiveResponse() === true;
37+
request.botScore.responseSegment.isUnexpected() === true;
38+
39+
// Variables
40+
request.getVariable("key");
41+
request.setVariable("key", "value");
42+
43+
// Exercise respondWith
44+
45+
request.respondWith(505, [], "Missing get-variable-present");
46+
request.respondWith(505, { no: "bad" }, "Expected var to be missing");
47+
}
48+
2749
export function onOriginRequest(request: EW.IngressOriginRequest) {
2850
// getHeader
2951
const h = request.getHeader("onOriginRequest-getHeader");

0 commit comments

Comments
 (0)