@webdecoy/node 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,3 +1,105 @@
1
+ /**
2
+ * The edge validator's verdict, as the origin sees it (#481).
3
+ *
4
+ * WHY THIS MODULE EXISTS
5
+ *
6
+ * The Cloudflare clearance worker has set `x-wd-clearance` on every forwarded
7
+ * request since the validator shipped, and nothing has ever read it. Grepping the
8
+ * header across the monorepo, this SDK and the WordPress plugin returned only the
9
+ * worker that writes it, its own tests, and one documentation page. We shipped a
10
+ * tag no customer could act on, then documented it as "watch the header in your
11
+ * logs."
12
+ *
13
+ * That gap matters more than it sounds. On a scoped route the gate's only options
14
+ * were pass or challenge, and a challenge on public content is a 403 to every
15
+ * client that cannot run JavaScript — search crawlers included. Reading the tag
16
+ * gives the application a third option it owns: log it, meter it, skip an
17
+ * expensive query, serve something cheaper. That is the first "yes" a cautious
18
+ * operator can give.
19
+ *
20
+ * WHAT IT IS NOT
21
+ *
22
+ * These values are advisory context, not authentication. They are only meaningful
23
+ * for requests that actually passed through the edge validator, and the validator
24
+ * strips inbound copies precisely so that the origin can attribute them to us.
25
+ * A request that reaches the origin WITHOUT passing through the proxy — straight
26
+ * to the origin IP, or a route that does not match — can carry anything. Treat
27
+ * `present: false` as "no information", never as "not a bot", and keep the origin
28
+ * unreachable except through the proxy if you intend to branch on this.
29
+ */
30
+ /** Header the edge validator uses for its clearance verdict. */
31
+ declare const EDGE_CLEARANCE_HEADER = "x-wd-clearance";
32
+ /** Header the edge validator uses for the sensor's client classification. */
33
+ declare const EDGE_CLASS_HEADER = "x-wd-class";
34
+ /**
35
+ * What the edge sensor concluded the client is.
36
+ *
37
+ * - `verified` — an identity something other than the client has attested
38
+ * (Cloudflare's verified-bot signal). **Never degrade these.** This is
39
+ * Googlebot and friends, and quietly serving them less is how a customer loses
40
+ * search presence and blames you six weeks later.
41
+ * - `crawler` — self-declares as a crawler, unproven. Real-but-unverified
42
+ * crawlers and forged ones both land here.
43
+ * - `script` — an HTTP client library, a Chromium user agent sending no client
44
+ * hints, or no user agent at all. Not a browser.
45
+ * - `browser` — nothing that distinguishes a non-human fired. A statement about
46
+ * our signals, not a certificate.
47
+ */
48
+ type EdgeClass = 'verified' | 'crawler' | 'script' | 'browser';
49
+ /**
50
+ * The edge's annotations on one request, typed.
51
+ *
52
+ * Every field is optional except `present`, because the edge validator may not be
53
+ * in front of this request at all — and the difference between "the edge said
54
+ * browser" and "there is no edge here" is the difference between a safe
55
+ * optimisation and a security hole.
56
+ */
57
+ interface EdgeVerdict {
58
+ /**
59
+ * True when the edge validator annotated this request. False means no
60
+ * information — not "human", not "safe".
61
+ */
62
+ present: boolean;
63
+ /**
64
+ * The clearance verdict, e.g. `valid`, `missing`, `verified-bot`,
65
+ * `signed-agent`, `machine`, `insufficient-trust`. Free-form on purpose: the
66
+ * validator gains labels faster than an SDK release can enumerate them, and an
67
+ * unknown label must not become `undefined`.
68
+ */
69
+ clearance?: string;
70
+ /** The sensor's classification, when it classified this request. */
71
+ class?: EdgeClass;
72
+ /** `class === 'verified'`. Convenience so callers need no string literals. */
73
+ isVerified: boolean;
74
+ /** `class === 'crawler'`. */
75
+ isCrawler: boolean;
76
+ /** `class === 'script'`. */
77
+ isScript: boolean;
78
+ /** `class === 'browser'`. */
79
+ isBrowser: boolean;
80
+ /**
81
+ * True for a class that is not a browser and is not attested — `script` or
82
+ * `crawler`.
83
+ *
84
+ * This is the predicate most applications actually want, and it deliberately
85
+ * excludes `verified`: the common intent is "cheapen this response", and the one
86
+ * population you must never cheapen for is the one whose identity was proven.
87
+ */
88
+ isUnattestedNonBrowser: boolean;
89
+ }
90
+ /**
91
+ * Read the edge validator's annotations out of a request's headers.
92
+ *
93
+ * Accepts the header bag the SDK already carries on `RequestMetadata` — lowercase
94
+ * keys — and tolerates mixed case, since adapters differ on normalisation.
95
+ *
96
+ * An unrecognised class value is dropped rather than passed through. The set is
97
+ * closed and small; a value outside it means either a version skew or something
98
+ * that is not our worker, and in both cases silence beats a value a caller might
99
+ * branch on.
100
+ */
101
+ declare function readEdgeVerdict(headers: Record<string, string> | undefined): EdgeVerdict;
102
+
1
103
  /**
2
104
  * Web Bot Auth verification — public types.
3
105
  *
@@ -146,6 +248,13 @@ interface RuleContext {
146
248
  * present). Lets a synchronous rule act on cryptographic agent verification.
147
249
  */
148
250
  agent?: AgentVerdict;
251
+ /**
252
+ * The edge validator's annotations on this request (#481), parsed from
253
+ * `x-wd-clearance` and `x-wd-class`. Always populated — `present: false` when
254
+ * the edge did not front this request. Filter expressions read it as
255
+ * `edge.class`, `edge.clearance` and `edge.present`.
256
+ */
257
+ edge?: EdgeVerdict;
149
258
  }
150
259
  /**
151
260
  * Result of evaluating a single rule
@@ -448,6 +557,15 @@ interface ProtectResult {
448
557
  * `verified` agent specially (e.g. allow) without re-verifying.
449
558
  */
450
559
  agent?: AgentVerdict;
560
+ /**
561
+ * What the edge validator said about this request (#481), parsed from
562
+ * `x-wd-clearance` and `x-wd-class`.
563
+ *
564
+ * Always present. Check `edge.present` before branching: false means the edge
565
+ * did not front this request, which is no information rather than a clean bill
566
+ * of health.
567
+ */
568
+ edge?: EdgeVerdict;
451
569
  }
452
570
  /**
453
571
  * Options for the protect() method
@@ -584,6 +702,7 @@ declare class WebDecoy {
584
702
  * @returns Protection result with decision and detection details
585
703
  */
586
704
  protect(metadata: RequestMetadata, options?: ProtectOptions): Promise<ProtectResult>;
705
+ private decide;
587
706
  /**
588
707
  * Validate the API key configuration
589
708
  * Useful for testing integration during setup
@@ -1641,4 +1760,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
1641
1760
  };
1642
1761
  type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
1643
1762
 
1644
- export { type AgentCategory, type AgentRequestInput, type AgentStatus, type AgentVerdict, AgentVerifier, type AgentVerifierOptions, type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type SignedAgentDirectory, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createAgentVerifier, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret, tripwire, webBotAuth };
1763
+ export { type AgentCategory, type AgentRequestInput, type AgentStatus, type AgentVerdict, AgentVerifier, type AgentVerifierOptions, type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, EDGE_CLASS_HEADER, EDGE_CLEARANCE_HEADER, type EdgeClass, type EdgeVerdict, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type SignedAgentDirectory, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createAgentVerifier, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, readEdgeVerdict, recommend, resolveSecret, tripwire, webBotAuth };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,105 @@
1
+ /**
2
+ * The edge validator's verdict, as the origin sees it (#481).
3
+ *
4
+ * WHY THIS MODULE EXISTS
5
+ *
6
+ * The Cloudflare clearance worker has set `x-wd-clearance` on every forwarded
7
+ * request since the validator shipped, and nothing has ever read it. Grepping the
8
+ * header across the monorepo, this SDK and the WordPress plugin returned only the
9
+ * worker that writes it, its own tests, and one documentation page. We shipped a
10
+ * tag no customer could act on, then documented it as "watch the header in your
11
+ * logs."
12
+ *
13
+ * That gap matters more than it sounds. On a scoped route the gate's only options
14
+ * were pass or challenge, and a challenge on public content is a 403 to every
15
+ * client that cannot run JavaScript — search crawlers included. Reading the tag
16
+ * gives the application a third option it owns: log it, meter it, skip an
17
+ * expensive query, serve something cheaper. That is the first "yes" a cautious
18
+ * operator can give.
19
+ *
20
+ * WHAT IT IS NOT
21
+ *
22
+ * These values are advisory context, not authentication. They are only meaningful
23
+ * for requests that actually passed through the edge validator, and the validator
24
+ * strips inbound copies precisely so that the origin can attribute them to us.
25
+ * A request that reaches the origin WITHOUT passing through the proxy — straight
26
+ * to the origin IP, or a route that does not match — can carry anything. Treat
27
+ * `present: false` as "no information", never as "not a bot", and keep the origin
28
+ * unreachable except through the proxy if you intend to branch on this.
29
+ */
30
+ /** Header the edge validator uses for its clearance verdict. */
31
+ declare const EDGE_CLEARANCE_HEADER = "x-wd-clearance";
32
+ /** Header the edge validator uses for the sensor's client classification. */
33
+ declare const EDGE_CLASS_HEADER = "x-wd-class";
34
+ /**
35
+ * What the edge sensor concluded the client is.
36
+ *
37
+ * - `verified` — an identity something other than the client has attested
38
+ * (Cloudflare's verified-bot signal). **Never degrade these.** This is
39
+ * Googlebot and friends, and quietly serving them less is how a customer loses
40
+ * search presence and blames you six weeks later.
41
+ * - `crawler` — self-declares as a crawler, unproven. Real-but-unverified
42
+ * crawlers and forged ones both land here.
43
+ * - `script` — an HTTP client library, a Chromium user agent sending no client
44
+ * hints, or no user agent at all. Not a browser.
45
+ * - `browser` — nothing that distinguishes a non-human fired. A statement about
46
+ * our signals, not a certificate.
47
+ */
48
+ type EdgeClass = 'verified' | 'crawler' | 'script' | 'browser';
49
+ /**
50
+ * The edge's annotations on one request, typed.
51
+ *
52
+ * Every field is optional except `present`, because the edge validator may not be
53
+ * in front of this request at all — and the difference between "the edge said
54
+ * browser" and "there is no edge here" is the difference between a safe
55
+ * optimisation and a security hole.
56
+ */
57
+ interface EdgeVerdict {
58
+ /**
59
+ * True when the edge validator annotated this request. False means no
60
+ * information — not "human", not "safe".
61
+ */
62
+ present: boolean;
63
+ /**
64
+ * The clearance verdict, e.g. `valid`, `missing`, `verified-bot`,
65
+ * `signed-agent`, `machine`, `insufficient-trust`. Free-form on purpose: the
66
+ * validator gains labels faster than an SDK release can enumerate them, and an
67
+ * unknown label must not become `undefined`.
68
+ */
69
+ clearance?: string;
70
+ /** The sensor's classification, when it classified this request. */
71
+ class?: EdgeClass;
72
+ /** `class === 'verified'`. Convenience so callers need no string literals. */
73
+ isVerified: boolean;
74
+ /** `class === 'crawler'`. */
75
+ isCrawler: boolean;
76
+ /** `class === 'script'`. */
77
+ isScript: boolean;
78
+ /** `class === 'browser'`. */
79
+ isBrowser: boolean;
80
+ /**
81
+ * True for a class that is not a browser and is not attested — `script` or
82
+ * `crawler`.
83
+ *
84
+ * This is the predicate most applications actually want, and it deliberately
85
+ * excludes `verified`: the common intent is "cheapen this response", and the one
86
+ * population you must never cheapen for is the one whose identity was proven.
87
+ */
88
+ isUnattestedNonBrowser: boolean;
89
+ }
90
+ /**
91
+ * Read the edge validator's annotations out of a request's headers.
92
+ *
93
+ * Accepts the header bag the SDK already carries on `RequestMetadata` — lowercase
94
+ * keys — and tolerates mixed case, since adapters differ on normalisation.
95
+ *
96
+ * An unrecognised class value is dropped rather than passed through. The set is
97
+ * closed and small; a value outside it means either a version skew or something
98
+ * that is not our worker, and in both cases silence beats a value a caller might
99
+ * branch on.
100
+ */
101
+ declare function readEdgeVerdict(headers: Record<string, string> | undefined): EdgeVerdict;
102
+
1
103
  /**
2
104
  * Web Bot Auth verification — public types.
3
105
  *
@@ -146,6 +248,13 @@ interface RuleContext {
146
248
  * present). Lets a synchronous rule act on cryptographic agent verification.
147
249
  */
148
250
  agent?: AgentVerdict;
251
+ /**
252
+ * The edge validator's annotations on this request (#481), parsed from
253
+ * `x-wd-clearance` and `x-wd-class`. Always populated — `present: false` when
254
+ * the edge did not front this request. Filter expressions read it as
255
+ * `edge.class`, `edge.clearance` and `edge.present`.
256
+ */
257
+ edge?: EdgeVerdict;
149
258
  }
150
259
  /**
151
260
  * Result of evaluating a single rule
@@ -448,6 +557,15 @@ interface ProtectResult {
448
557
  * `verified` agent specially (e.g. allow) without re-verifying.
449
558
  */
450
559
  agent?: AgentVerdict;
560
+ /**
561
+ * What the edge validator said about this request (#481), parsed from
562
+ * `x-wd-clearance` and `x-wd-class`.
563
+ *
564
+ * Always present. Check `edge.present` before branching: false means the edge
565
+ * did not front this request, which is no information rather than a clean bill
566
+ * of health.
567
+ */
568
+ edge?: EdgeVerdict;
451
569
  }
452
570
  /**
453
571
  * Options for the protect() method
@@ -584,6 +702,7 @@ declare class WebDecoy {
584
702
  * @returns Protection result with decision and detection details
585
703
  */
586
704
  protect(metadata: RequestMetadata, options?: ProtectOptions): Promise<ProtectResult>;
705
+ private decide;
587
706
  /**
588
707
  * Validate the API key configuration
589
708
  * Useful for testing integration during setup
@@ -1641,4 +1760,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
1641
1760
  };
1642
1761
  type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
1643
1762
 
1644
- export { type AgentCategory, type AgentRequestInput, type AgentStatus, type AgentVerdict, AgentVerifier, type AgentVerifierOptions, type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type SignedAgentDirectory, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createAgentVerifier, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret, tripwire, webBotAuth };
1763
+ export { type AgentCategory, type AgentRequestInput, type AgentStatus, type AgentVerdict, AgentVerifier, type AgentVerifierOptions, type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, EDGE_CLASS_HEADER, EDGE_CLEARANCE_HEADER, type EdgeClass, type EdgeVerdict, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type SignedAgentDirectory, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createAgentVerifier, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, readEdgeVerdict, recommend, resolveSecret, tripwire, webBotAuth };
package/dist/index.js CHANGED
@@ -27,6 +27,8 @@ __export(index_exports, {
27
27
  DEFAULT_WEIGHTS: () => DEFAULT_WEIGHTS,
28
28
  DetectionEngine: () => DetectionEngine,
29
29
  DirectoryCache: () => DirectoryCache,
30
+ EDGE_CLASS_HEADER: () => EDGE_CLASS_HEADER,
31
+ EDGE_CLEARANCE_HEADER: () => EDGE_CLEARANCE_HEADER,
30
32
  FilterRule: () => FilterRule,
31
33
  InMemoryChallengeStore: () => InMemoryChallengeStore,
32
34
  InMemoryFingerprintStore: () => InMemoryFingerprintStore,
@@ -49,6 +51,7 @@ __export(index_exports, {
49
51
  isMobileUA: () => isMobileUA,
50
52
  parseUserAgent: () => parseUserAgent,
51
53
  rateLimit: () => rateLimit,
54
+ readEdgeVerdict: () => readEdgeVerdict,
52
55
  recommend: () => recommend,
53
56
  resolveSecret: () => resolveSecret,
54
57
  tripwire: () => tripwire,
@@ -1093,6 +1096,49 @@ function toHeaders(record) {
1093
1096
  return h;
1094
1097
  }
1095
1098
 
1099
+ // src/edge.ts
1100
+ var EDGE_CLEARANCE_HEADER = "x-wd-clearance";
1101
+ var EDGE_CLASS_HEADER = "x-wd-class";
1102
+ var EDGE_CLASSES = ["verified", "crawler", "script", "browser"];
1103
+ function absent() {
1104
+ return {
1105
+ present: false,
1106
+ isVerified: false,
1107
+ isCrawler: false,
1108
+ isScript: false,
1109
+ isBrowser: false,
1110
+ isUnattestedNonBrowser: false
1111
+ };
1112
+ }
1113
+ function normaliseClass(raw) {
1114
+ if (!raw) return void 0;
1115
+ const v = raw.trim().toLowerCase();
1116
+ return EDGE_CLASSES.includes(v) ? v : void 0;
1117
+ }
1118
+ function readEdgeVerdict(headers) {
1119
+ if (!headers) return absent();
1120
+ let clearanceRaw;
1121
+ let classRaw;
1122
+ for (const key of Object.keys(headers)) {
1123
+ const k = key.toLowerCase();
1124
+ if (k === EDGE_CLEARANCE_HEADER) clearanceRaw = headers[key];
1125
+ else if (k === EDGE_CLASS_HEADER) classRaw = headers[key];
1126
+ }
1127
+ const clearance = clearanceRaw?.trim() || void 0;
1128
+ const cls = normaliseClass(classRaw);
1129
+ if (!clearance && !cls) return absent();
1130
+ return {
1131
+ present: true,
1132
+ clearance,
1133
+ class: cls,
1134
+ isVerified: cls === "verified",
1135
+ isCrawler: cls === "crawler",
1136
+ isScript: cls === "script",
1137
+ isBrowser: cls === "browser",
1138
+ isUnattestedNonBrowser: cls === "script" || cls === "crawler"
1139
+ };
1140
+ }
1141
+
1096
1142
  // src/sdk.ts
1097
1143
  var WebDecoy = class {
1098
1144
  constructor(config) {
@@ -1190,7 +1236,11 @@ var WebDecoy = class {
1190
1236
  method: metadata.method,
1191
1237
  userAgent: metadata.user_agent,
1192
1238
  headers: metadata.headers,
1193
- timestamp: metadata.timestamp || Date.now()
1239
+ timestamp: metadata.timestamp || Date.now(),
1240
+ // Parsed synchronously and unconditionally (#481): it is two header reads,
1241
+ // it needs no network, and a rule that has to check whether the edge
1242
+ // verdict was populated is a rule people will get wrong.
1243
+ edge: readEdgeVerdict(metadata.headers)
1194
1244
  };
1195
1245
  }
1196
1246
  /**
@@ -1279,6 +1329,11 @@ var WebDecoy = class {
1279
1329
  * @returns Protection result with decision and detection details
1280
1330
  */
1281
1331
  async protect(metadata, options = {}) {
1332
+ const edge = readEdgeVerdict(metadata.headers);
1333
+ const result = await this.decide(metadata, options);
1334
+ return { ...result, edge };
1335
+ }
1336
+ async decide(metadata, options = {}) {
1282
1337
  try {
1283
1338
  if (!metadata.ip) {
1284
1339
  throw new Error("IP address is required in request metadata");
@@ -1948,6 +2003,18 @@ function resolveProperty(path, context) {
1948
2003
  if (prop === "user_agent") return context.userAgent;
1949
2004
  return void 0;
1950
2005
  }
2006
+ if (namespace === "edge") {
2007
+ const e = context.edge;
2008
+ if (!e) return void 0;
2009
+ if (prop === "present") return e.present;
2010
+ if (prop === "clearance") return e.clearance;
2011
+ if (prop === "class") return e.class;
2012
+ if (prop === "verified") return e.isVerified;
2013
+ if (prop === "crawler") return e.isCrawler;
2014
+ if (prop === "script") return e.isScript;
2015
+ if (prop === "browser") return e.isBrowser;
2016
+ return void 0;
2017
+ }
1951
2018
  if (path.length === 1) return void 0;
1952
2019
  return void 0;
1953
2020
  }
@@ -4212,6 +4279,8 @@ function createCaptchaEndpoints(options = {}) {
4212
4279
  DEFAULT_WEIGHTS,
4213
4280
  DetectionEngine,
4214
4281
  DirectoryCache,
4282
+ EDGE_CLASS_HEADER,
4283
+ EDGE_CLEARANCE_HEADER,
4215
4284
  FilterRule,
4216
4285
  InMemoryChallengeStore,
4217
4286
  InMemoryFingerprintStore,
@@ -4234,6 +4303,7 @@ function createCaptchaEndpoints(options = {}) {
4234
4303
  isMobileUA,
4235
4304
  parseUserAgent,
4236
4305
  rateLimit,
4306
+ readEdgeVerdict,
4237
4307
  recommend,
4238
4308
  resolveSecret,
4239
4309
  tripwire,
package/dist/index.mjs CHANGED
@@ -1035,6 +1035,49 @@ function toHeaders(record) {
1035
1035
  return h;
1036
1036
  }
1037
1037
 
1038
+ // src/edge.ts
1039
+ var EDGE_CLEARANCE_HEADER = "x-wd-clearance";
1040
+ var EDGE_CLASS_HEADER = "x-wd-class";
1041
+ var EDGE_CLASSES = ["verified", "crawler", "script", "browser"];
1042
+ function absent() {
1043
+ return {
1044
+ present: false,
1045
+ isVerified: false,
1046
+ isCrawler: false,
1047
+ isScript: false,
1048
+ isBrowser: false,
1049
+ isUnattestedNonBrowser: false
1050
+ };
1051
+ }
1052
+ function normaliseClass(raw) {
1053
+ if (!raw) return void 0;
1054
+ const v = raw.trim().toLowerCase();
1055
+ return EDGE_CLASSES.includes(v) ? v : void 0;
1056
+ }
1057
+ function readEdgeVerdict(headers) {
1058
+ if (!headers) return absent();
1059
+ let clearanceRaw;
1060
+ let classRaw;
1061
+ for (const key of Object.keys(headers)) {
1062
+ const k = key.toLowerCase();
1063
+ if (k === EDGE_CLEARANCE_HEADER) clearanceRaw = headers[key];
1064
+ else if (k === EDGE_CLASS_HEADER) classRaw = headers[key];
1065
+ }
1066
+ const clearance = clearanceRaw?.trim() || void 0;
1067
+ const cls = normaliseClass(classRaw);
1068
+ if (!clearance && !cls) return absent();
1069
+ return {
1070
+ present: true,
1071
+ clearance,
1072
+ class: cls,
1073
+ isVerified: cls === "verified",
1074
+ isCrawler: cls === "crawler",
1075
+ isScript: cls === "script",
1076
+ isBrowser: cls === "browser",
1077
+ isUnattestedNonBrowser: cls === "script" || cls === "crawler"
1078
+ };
1079
+ }
1080
+
1038
1081
  // src/sdk.ts
1039
1082
  var WebDecoy = class {
1040
1083
  constructor(config) {
@@ -1132,7 +1175,11 @@ var WebDecoy = class {
1132
1175
  method: metadata.method,
1133
1176
  userAgent: metadata.user_agent,
1134
1177
  headers: metadata.headers,
1135
- timestamp: metadata.timestamp || Date.now()
1178
+ timestamp: metadata.timestamp || Date.now(),
1179
+ // Parsed synchronously and unconditionally (#481): it is two header reads,
1180
+ // it needs no network, and a rule that has to check whether the edge
1181
+ // verdict was populated is a rule people will get wrong.
1182
+ edge: readEdgeVerdict(metadata.headers)
1136
1183
  };
1137
1184
  }
1138
1185
  /**
@@ -1221,6 +1268,11 @@ var WebDecoy = class {
1221
1268
  * @returns Protection result with decision and detection details
1222
1269
  */
1223
1270
  async protect(metadata, options = {}) {
1271
+ const edge = readEdgeVerdict(metadata.headers);
1272
+ const result = await this.decide(metadata, options);
1273
+ return { ...result, edge };
1274
+ }
1275
+ async decide(metadata, options = {}) {
1224
1276
  try {
1225
1277
  if (!metadata.ip) {
1226
1278
  throw new Error("IP address is required in request metadata");
@@ -1890,6 +1942,18 @@ function resolveProperty(path, context) {
1890
1942
  if (prop === "user_agent") return context.userAgent;
1891
1943
  return void 0;
1892
1944
  }
1945
+ if (namespace === "edge") {
1946
+ const e = context.edge;
1947
+ if (!e) return void 0;
1948
+ if (prop === "present") return e.present;
1949
+ if (prop === "clearance") return e.clearance;
1950
+ if (prop === "class") return e.class;
1951
+ if (prop === "verified") return e.isVerified;
1952
+ if (prop === "crawler") return e.isCrawler;
1953
+ if (prop === "script") return e.isScript;
1954
+ if (prop === "browser") return e.isBrowser;
1955
+ return void 0;
1956
+ }
1893
1957
  if (path.length === 1) return void 0;
1894
1958
  return void 0;
1895
1959
  }
@@ -4153,6 +4217,8 @@ export {
4153
4217
  DEFAULT_WEIGHTS,
4154
4218
  DetectionEngine,
4155
4219
  DirectoryCache,
4220
+ EDGE_CLASS_HEADER,
4221
+ EDGE_CLEARANCE_HEADER,
4156
4222
  FilterRule,
4157
4223
  InMemoryChallengeStore,
4158
4224
  InMemoryFingerprintStore,
@@ -4175,6 +4241,7 @@ export {
4175
4241
  isMobileUA,
4176
4242
  parseUserAgent,
4177
4243
  rateLimit,
4244
+ readEdgeVerdict,
4178
4245
  recommend,
4179
4246
  resolveSecret,
4180
4247
  tripwire,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/node",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Web Decoy SDK for Node.js - Bot detection with TLS fingerprinting",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",