diff --git a/types/akamai-edgeworkers/README.md b/types/akamai-edgeworkers/README.md index 42d77eb72cc338..6671cb0a1c12ea 100644 --- a/types/akamai-edgeworkers/README.md +++ b/types/akamai-edgeworkers/README.md @@ -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) {} diff --git a/types/akamai-edgeworkers/index.d.ts b/types/akamai-edgeworkers/index.d.ts index 41461b2a12ff0d..15113bce95bc3d 100644 --- a/types/akamai-edgeworkers/index.d.ts +++ b/types/akamai-edgeworkers/index.d.ts @@ -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 @@ -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 @@ -718,6 +787,7 @@ declare namespace EW { } export { + BotSegmentAvailableRequest, EgressClientRequest, EgressClientResponse, EgressOriginRequest, diff --git a/types/akamai-edgeworkers/package.json b/types/akamai-edgeworkers/package.json index 9908edeca7f552..346458f984bef1 100644 --- a/types/akamai-edgeworkers/package.json +++ b/types/akamai-edgeworkers/package.json @@ -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" } ] } diff --git a/types/akamai-edgeworkers/test/akamai-edgeworkers-global.test.ts b/types/akamai-edgeworkers/test/akamai-edgeworkers-global.test.ts index b25e64e19b8a9e..80f8d0a7b6fc42 100644 --- a/types/akamai-edgeworkers/test/akamai-edgeworkers-global.test.ts +++ b/types/akamai-edgeworkers/test/akamai-edgeworkers-global.test.ts @@ -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");