Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions types/akamai-edgeworkers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ with the following stubs:

export function onClientRequest(request: EW.IngressClientRequest) {}
export function onOriginRequest(request: EW.IngressOriginRequest) {}
export function onBotSegmentAvailable(request: EW.BotSegmentAvailableRequest) {}
export function responseProvider(request: EW.ResponseProviderRequest) {}
export function onOriginResponse(request: EW.EgressOriginRequest, response: EW.EgressOriginResponse) {}
export function onClientResponse(request: EW.EgressClientRequest, response: EW.EgressClientResponse) {}
Expand Down
70 changes: 70 additions & 0 deletions types/akamai-edgeworkers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,69 @@ declare namespace EW {
readonly cacheKey: CacheKey;
}

interface BotScore {
/**
* An object for interacting with features related to Bot Management
*/
readonly responseSegment: BotScoreResponseSegment;
}

interface BotScoreResponseSegment {
/**
* Indicates that this request hasn't triggered any detections, resulting in a bot score of zero.
*/
isHuman(): boolean;

/**
* Indicates that this request has a low bot score.
*
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
*/
isCautiousResponse(): boolean;

/**
* Indicates that this request has a middling bot score. You should apply a challenge to the traffic in this
* segment to prohibit bots but let humans through.
*
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
*/
isStrictResponse(): boolean;

/**
* Indicates that this request is from a special class of traffic that Bot Manager sets aside.
* There are cases where a human could get endlessly trapped by certain detections, such as a network-based
* or device-based detection like user-agent. This detection would trip every request, but the person
* could never change the trigger. Where there's this danger that a human could never overcome a detection
* and get stuck, Bot Manager sets aside requests in a special response segment called Safeguard,
* so you can handle them differently. For best results, when you set bot score, leave Safeguard Traffic
* at the preset Strict Response if it uses a challenge action to let clients prove they are
* human and get through.
*
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
*/
isSafeguardResponse(): boolean;

/**
* Indicates that this request has a high bot score, which is more likely to be from a bot.
*
* See: https://techdocs.akamai.com/bot-manager/docs/see-bot-activity-api-operation
*/
isAggressiveResponse(): boolean;

/**
* Indicates that this request has an unknown bot score. This field is left as a placeholder for
* forwards compatibility.
*/
isUnexpected(): boolean;
}

interface HasBotScore {
/**
* Object containing properties related to Bot Management.
*/
readonly botScore: BotScore;
}

interface ReadsBody {
/**
* A promise that reads the body to completion and resolves to a string containing the full
Expand Down Expand Up @@ -460,6 +523,12 @@ declare namespace EW {
{
}

// onBotSegmentAvailable
interface BotSegmentAvailableRequest
extends ReadsHeaders, ReadAllHeader, ReadsVariables, MutatesVariables, Request, HasRespondWith, HasBotScore
{
}

// onOriginRequest
interface IngressOriginRequest
extends MutatesHeaders, ReadsHeaders, ReadAllHeader, ReadsVariables, Request, HasRespondWith, MutatesVariables
Expand Down Expand Up @@ -718,6 +787,7 @@ declare namespace EW {
}

export {
BotSegmentAvailableRequest,
EgressClientRequest,
EgressClientResponse,
EgressOriginRequest,
Expand Down
16 changes: 8 additions & 8 deletions types/akamai-edgeworkers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
},
"owners": [
{
"name": "Evan Hughes",
"githubUsername": "evan-hughes"
"name": "Chris Daley",
"githubUsername": "cdaley-akamai"
},
{
"name": "Will Bain",
"githubUsername": "wabain"
},
{
"name": "Swathi Bala",
"githubUsername": "swathimr"
"name": "Yana Kadiysk",
"githubUsername": "yanakad"
},
{
"name": "Aman Nanner",
"githubUsername": "ananner"
"name": "Miranda Lim",
"githubUsername": "miliworking"
},
{
"name": "Ben Matthews",
"githubUsername": "bmatthew"
"name": "Luca Perra",
"githubUsername": "lperra"
}
]
}
22 changes: 22 additions & 0 deletions types/akamai-edgeworkers/test/akamai-edgeworkers-global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ export function onClientRequest(request: EW.IngressClientRequest) {
}
}

export function onBogSegmentAvailable(request: EW.BotSegmentAvailableRequest) {
// Exercise headers
testHeaders(request.getHeaders());

// Exercise botScore
request.botScore.responseSegment.isHuman() === true;
request.botScore.responseSegment.isCautiousResponse() === true;
request.botScore.responseSegment.isStrictResponse() === true;
request.botScore.responseSegment.isSafeguardResponse() === true;
request.botScore.responseSegment.isAggressiveResponse() === true;
request.botScore.responseSegment.isUnexpected() === true;

// Variables
request.getVariable("key");
request.setVariable("key", "value");

// Exercise respondWith

request.respondWith(505, [], "Missing get-variable-present");
request.respondWith(505, { no: "bad" }, "Expected var to be missing");
}

export function onOriginRequest(request: EW.IngressOriginRequest) {
// getHeader
const h = request.getHeader("onOriginRequest-getHeader");
Expand Down