@webdecoy/node 0.5.0 → 0.7.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 };