@webdecoy/node 0.8.1 → 0.10.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.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * or plain traffic carrying no agent signature at all?
9
9
  *
10
10
  * The verdict taxonomy mirrors the server-side verifier in the ingest service
11
- * (WebDecoy/app#320) so the SDK, the edge validator, and the backend all speak
11
+ * so the SDK, the edge validator, and the backend all speak
12
12
  * the same language.
13
13
  */
14
14
  /** The four possible outcomes of Web Bot Auth verification. */
@@ -118,7 +118,7 @@ type AgentRequestInput = Request | {
118
118
  };
119
119
 
120
120
  /**
121
- * The edge validator's verdict, as the origin sees it (#481).
121
+ * The edge validator's verdict, as the origin sees it.
122
122
  *
123
123
  * WHY THIS MODULE EXISTS
124
124
  *
@@ -219,6 +219,119 @@ interface EdgeVerdict {
219
219
  */
220
220
  declare function readEdgeVerdict(headers: Record<string, string> | undefined): EdgeVerdict;
221
221
 
222
+ /**
223
+ * GENERATED FILE — DO NOT EDIT.
224
+ *
225
+ * Source of truth: the Go agent registry in the main application repo.
226
+ * Regenerate with `packages/webdecoy/scripts/gen-bot-registry.mjs`; see that
227
+ * script for the command.
228
+ *
229
+ * ORDER IS SIGNIFICANT. Entries are in `agents.MatchUserAgent` order — AI data
230
+ * scrapers first, then AI search crawlers, AI agents, search engines, then the
231
+ * remaining categories. `matchUserAgent()` returns the first hit, and several
232
+ * agents share User-Agent substrings, so sorting this array changes how real
233
+ * traffic is classified.
234
+ *
235
+ * 168 agents across 15 categories.
236
+ */
237
+ /**
238
+ * Classification categories, mirroring `agents.Category` in Go.
239
+ *
240
+ * Declared here rather than hand-written next door so a category added in Go
241
+ * cannot go missing in TypeScript.
242
+ */
243
+ type BotCategory = "training_crawler" | "ai_search_crawler" | "ai_agent" | "ai_assistant" | "search_crawler" | "seo_crawler" | "security_scanner" | "generic_scraper" | "archiver" | "fetcher" | "monitoring" | "headless_browser" | "feed_reader" | "commercial_scraper" | "none";
244
+ /** One entry in the registry. */
245
+ interface BotAgent {
246
+ /** Stable lowercase slug, e.g. `gptbot`. */
247
+ id: string;
248
+ /** Display name, e.g. `GPTBot`. */
249
+ name: string;
250
+ category: BotCategory;
251
+ /** Operator, e.g. `OpenAI`. */
252
+ organization: string;
253
+ /** The registry's default threat score for this agent (0-100). */
254
+ baseScore: number;
255
+ /** Whether the operator documents honouring robots.txt. */
256
+ respectsRobots: boolean;
257
+ /** Lowercase User-Agent substrings that identify it. */
258
+ uaPatterns: readonly string[];
259
+ }
260
+ /** Every declared category, including any with no agents yet. */
261
+ declare const BOT_CATEGORIES: readonly BotCategory[];
262
+ /** The agent table, in match order. */
263
+ declare const BOT_REGISTRY: readonly BotAgent[];
264
+
265
+ /**
266
+ * Local bot classification.
267
+ *
268
+ * WHY THIS IS IN THE SDK AT ALL
269
+ *
270
+ * The scoring pipeline already identifies named agents server-side, but it does
271
+ * so *after* the request is reported — which is too late to decide anything. A
272
+ * customer who wants "block AI training crawlers, allow search crawlers" needs
273
+ * the answer synchronously, in the request path, with no network call. So the Go
274
+ * registry is generated into {@link BOT_REGISTRY} and matched here.
275
+ *
276
+ * WHAT THIS IS NOT
277
+ *
278
+ * This is a User-Agent lookup. It identifies agents that say who they are, and
279
+ * nothing else. An agent that spoofs Chrome is invisible to it, and always will
280
+ * be — that is the point of the 1% User-Agent weight in the unified score, and
281
+ * nothing here changes that arithmetic.
282
+ *
283
+ * That is a feature for the use case it serves. GPTBot, ClaudeBot and Googlebot
284
+ * all self-identify honestly, and the decision a customer wants to make about
285
+ * them ("don't train on my content") is a POLICY choice about a cooperative
286
+ * agent, not a threat judgement about a hostile one. Acting on a claim is
287
+ * correct when the claim is the thing you care about.
288
+ *
289
+ * For agents that lie, the answer is the rest of the product: tripwires,
290
+ * honeytokens and the edge classifier see behaviour, which cannot be spoofed by
291
+ * editing a header.
292
+ */
293
+
294
+ /**
295
+ * What a rule sees about the agent behind a request.
296
+ *
297
+ * Always populated, never undefined: a rule that has to check whether
298
+ * classification ran is a rule people get wrong. When nothing matched,
299
+ * `known` is false and `category` is `'none'`.
300
+ */
301
+ interface BotVerdict {
302
+ /** Whether the User-Agent matched a known agent. */
303
+ known: boolean;
304
+ /** Registry slug, e.g. `gptbot`. Undefined when unknown. */
305
+ id?: string;
306
+ /** Display name, e.g. `GPTBot`. Undefined when unknown. */
307
+ name?: string;
308
+ /** Customer-facing category — the same vocabulary as the dashboard. */
309
+ category: BotCategory;
310
+ /** Operator, e.g. `OpenAI`. Undefined when unknown. */
311
+ organization?: string;
312
+ /** The registry's threat score for this agent, 0-100. 0 when unknown. */
313
+ score: number;
314
+ /**
315
+ * Whether the operator documents honouring robots.txt. Undefined when unknown.
316
+ *
317
+ * Documented behaviour, not observed behaviour — it is what the operator
318
+ * publishes, so treat it as a claim like any other.
319
+ */
320
+ respectsRobots?: boolean;
321
+ /** True for training crawlers, AI search crawlers, AI agents and assistants. */
322
+ isAI: boolean;
323
+ }
324
+ /**
325
+ * Find the agent behind a User-Agent string, or undefined.
326
+ *
327
+ * Returns the FIRST match in registry order, which is why {@link BOT_REGISTRY}
328
+ * must not be sorted: the table arrives ordered by category priority, mirroring
329
+ * `agents.MatchUserAgent` in Go so both sides classify identically.
330
+ */
331
+ declare function matchUserAgent(userAgent: string | undefined | null): BotAgent | undefined;
332
+ /** Classify a User-Agent into the verdict rules evaluate against. */
333
+ declare function classifyUserAgent(userAgent: string | undefined | null): BotVerdict;
334
+
222
335
  /**
223
336
  * Rules Engine Types
224
337
  * Core interfaces for the WebDecoy rules engine
@@ -244,17 +357,26 @@ interface RuleContext {
244
357
  enrichment?: IPEnrichmentData;
245
358
  /**
246
359
  * Web Bot Auth verdict (populated async before evaluation when a
247
- * {@link https://github.com/WebDecoy/app/issues/323 webBotAuth} rule is
360
+ * `webBotAuth` rule is
248
361
  * present). Lets a synchronous rule act on cryptographic agent verification.
249
362
  */
250
363
  agent?: AgentVerdict;
251
364
  /**
252
- * The edge validator's annotations on this request (#481), parsed from
365
+ * The edge validator's annotations on this request, parsed from
253
366
  * `x-wd-clearance` and `x-wd-class`. Always populated — `present: false` when
254
367
  * the edge did not front this request. Filter expressions read it as
255
368
  * `edge.class`, `edge.clearance` and `edge.present`.
256
369
  */
257
370
  edge?: EdgeVerdict;
371
+ /**
372
+ * Who the User-Agent says it is, matched against the generated agent
373
+ * registry. Always populated — `known: false` when nothing matched. Filter
374
+ * expressions read it as `bot.category`, `bot.name`, `bot.ai` and friends.
375
+ *
376
+ * A self-declared identity, so it is evidence about cooperative agents only.
377
+ * See {@link BotVerdict}.
378
+ */
379
+ bot?: BotVerdict;
258
380
  }
259
381
  /**
260
382
  * Result of evaluating a single rule
@@ -308,6 +430,32 @@ interface FilterConfig {
308
430
  /** Dry run mode: log violations but don't block */
309
431
  dryRun?: boolean;
310
432
  }
433
+ /**
434
+ * Configuration for bot-category rules
435
+ */
436
+ interface BotRuleConfig {
437
+ /**
438
+ * Categories to act on, e.g. `['training_crawler']`. Uses the same vocabulary
439
+ * as the dashboard's `ai_scraper_category` column.
440
+ */
441
+ categories?: BotCategory[];
442
+ /** Specific agents by registry slug or display name, e.g. `['gptbot']`. */
443
+ agents?: string[];
444
+ /**
445
+ * Act on every AI client — training crawlers, AI search crawlers, AI agents
446
+ * and AI assistants.
447
+ */
448
+ ai?: boolean;
449
+ /**
450
+ * Never act on these, whatever else matches. Applied last, so
451
+ * `{ ai: true, allow: ['perplexitybot'] }` reads the way it looks.
452
+ */
453
+ allow?: string[];
454
+ /** Action when an agent matches: 'DENY' (default) or 'THROTTLE'. */
455
+ action?: 'DENY' | 'THROTTLE';
456
+ /** Log the violation but don't block. */
457
+ dryRun?: boolean;
458
+ }
311
459
  /**
312
460
  * Configuration for tripwire (honeypot-path) rules
313
461
  */
@@ -346,7 +494,7 @@ interface ViolationEvent {
346
494
  /**
347
495
  * The request's wd_clearance token, when present. Lets the backend bind a
348
496
  * tripwire hit to the actor's device fingerprint and deny it — the same
349
- * durable lockout a decoy hit produces (enforcement issue #136). Only carried
497
+ * durable lockout a decoy hit produces. Only carried
350
498
  * for deception rules (tripwires); undefined otherwise.
351
499
  */
352
500
  clearance?: string;
@@ -558,7 +706,7 @@ interface ProtectResult {
558
706
  */
559
707
  agent?: AgentVerdict;
560
708
  /**
561
- * What the edge validator said about this request (#481), parsed from
709
+ * What the edge validator said about this request, parsed from
562
710
  * `x-wd-clearance` and `x-wd-class`.
563
711
  *
564
712
  * Always present. Check `edge.present` before branching: false means the edge
@@ -750,7 +898,7 @@ declare class RuleEngine {
750
898
  * Append a rule after construction.
751
899
  *
752
900
  * Exists for signals that cannot be known synchronously at construction —
753
- * currently the site honeytoken (#482), whose path is derived by async HMAC.
901
+ * currently the site honeytoken, whose path is derived by async HMAC.
754
902
  * Evaluation order is append order, matching the constructor.
755
903
  */
756
904
  add(rule: Rule): void;
@@ -827,7 +975,42 @@ declare class TripwireRule implements Rule {
827
975
  }
828
976
 
829
977
  /**
830
- * Web Bot Auth rule (WebDecoy/app#323).
978
+ * Bot-category rule.
979
+ *
980
+ * The one-liner for the policy this product category exists to express:
981
+ *
982
+ * ```typescript
983
+ * bots({ categories: ['training_crawler'] }) // no AI training on my content
984
+ * ```
985
+ *
986
+ * This is expressible as a filter expression too — `bot.category ==
987
+ * "training_crawler"` — and that is the right tool once the policy has
988
+ * conditions. This exists because the common case should not require learning an
989
+ * expression language, and because `allow` is fiddly to spell correctly by hand.
990
+ *
991
+ * WHAT IT CAN AND CANNOT SEE
992
+ *
993
+ * It matches on the User-Agent, so it only ever acts on agents that declare
994
+ * themselves. That is sound for this policy — GPTBot and ClaudeBot identify
995
+ * honestly, and the decision is about a cooperative agent's access, not about
996
+ * catching a liar. Anything spoofing Chrome passes straight through, and the
997
+ * tripwire and edge layers are what catch those.
998
+ */
999
+
1000
+ declare class BotRule implements Rule {
1001
+ readonly name = "bots";
1002
+ private readonly categories;
1003
+ private readonly agents;
1004
+ private readonly ai;
1005
+ private readonly allow;
1006
+ private readonly action;
1007
+ private readonly dryRun;
1008
+ constructor(config?: BotRuleConfig);
1009
+ evaluate(context: RuleContext): RuleResult;
1010
+ }
1011
+
1012
+ /**
1013
+ * Web Bot Auth rule (the main application repo).
831
1014
  *
832
1015
  * Acts on the Web Bot Auth verdict the SDK computes before rule evaluation
833
1016
  * (`context.agent`). Its headline job is to make **impersonation deny-able in
@@ -926,7 +1109,7 @@ declare function honeytoken(options?: HoneytokenOptions): Honeytoken;
926
1109
 
927
1110
  /**
928
1111
  * Site honeytoken — a stable, derivable trap the adapters can inject for you
929
- * (#482).
1112
+ *.
930
1113
  *
931
1114
  * WHY THIS EXISTS ALONGSIDE honeytoken()
932
1115
  *
@@ -946,12 +1129,14 @@ declare function honeytoken(options?: HoneytokenOptions): Honeytoken;
946
1129
  * JavaScript, no fingerprint and no IP — the client asked for a path that exists
947
1130
  * nowhere and is linked only from an element no human can see.
948
1131
  *
949
- * That is not a stylistic preference, it is arithmetic. The unified score weights
950
- * honeypot hits at 38% and user-agent at 1%, because a user agent is trivially
951
- * spoofed. Measured against production: every `sdk` detection ever recorded
952
- * scored 0, while `sdk_tripwire` averaged 52.5. And `sdk_tripwire` had FOUR rows
953
- * in total, because the SDK generated a honeytoken and then asked the developer
954
- * to place the link. WordPress injects it itself and has coverage.
1132
+ * That is not a stylistic preference, it is arithmetic. Honeypot hits carry the
1133
+ * highest weight in the threat score and a User-Agent carries nearly none,
1134
+ * because a User-Agent is trivially spoofed — so the same client scores near
1135
+ * zero on a page view and very high on a trap.
1136
+ *
1137
+ * Which only pays off if the link is on the page. Generating a token and asking
1138
+ * the developer to place it is a step most installs never take, so the adapters
1139
+ * that own the response inject it themselves.
955
1140
  */
956
1141
  /** Base path for honeytoken tripwires. Mirrors the WordPress plugin. */
957
1142
  declare const HONEYTOKEN_BASE_PATH = "/__wd";
@@ -1089,6 +1274,36 @@ declare function filter(config: FilterConfig): Rule;
1089
1274
  * ```
1090
1275
  */
1091
1276
  declare function tripwire(config?: TripwireConfig): Rule;
1277
+ /**
1278
+ * Factory function to create a bot-category rule.
1279
+ *
1280
+ * Acts on agents that identify themselves in the User-Agent, matched against the
1281
+ * registry generated from the same table the scoring pipeline uses — so
1282
+ * `'training_crawler'` here means what `ai_scraper_category` means in your
1283
+ * dashboard.
1284
+ *
1285
+ * @example
1286
+ * ```typescript
1287
+ * import { WebDecoy, bots } from '@webdecoy/node';
1288
+ *
1289
+ * const sdk = new WebDecoy({
1290
+ * rules: [
1291
+ * // Keep AI models out of your content, keep your search ranking.
1292
+ * bots({ categories: ['training_crawler'] }),
1293
+ *
1294
+ * // Or everything AI, minus the one you want referral traffic from.
1295
+ * bots({ ai: true, allow: ['perplexitybot'] }),
1296
+ *
1297
+ * // Or a specific operator.
1298
+ * bots({ agents: ['gptbot', 'ClaudeBot'], action: 'THROTTLE' }),
1299
+ * ],
1300
+ * });
1301
+ * ```
1302
+ *
1303
+ * Only catches agents that declare themselves — anything spoofing a browser
1304
+ * passes through, by design. Pair with {@link tripwire} for agents that lie.
1305
+ */
1306
+ declare function bots(config?: BotRuleConfig): Rule;
1092
1307
 
1093
1308
  /**
1094
1309
  * AgentVerifier — the public entry point for local Web Bot Auth verification.
@@ -1880,4 +2095,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
1880
2095
  };
1881
2096
  type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
1882
2097
 
1883
- 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, HONEYTOKEN_BASE_PATH, type Honeytoken, type HoneytokenLinkProps, 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 SiteHoneytoken, type SiteHoneytokenOptions, 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, injectHoneytokenLink, isDatacenterIP, isInjectableHtml, isMobileUA, parseUserAgent, rateLimit, readEdgeVerdict, recommend, resolveSecret, siteHoneytoken, tripwire, webBotAuth };
2098
+ export { type AgentCategory, type AgentRequestInput, type AgentStatus, type AgentVerdict, AgentVerifier, type AgentVerifierOptions, BOT_CATEGORIES, BOT_REGISTRY, type BehavioralSignals, type BotAgent, type BotCategory, BotRule, type BotRuleConfig, type BotVerdict, 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, HONEYTOKEN_BASE_PATH, type Honeytoken, type HoneytokenLinkProps, 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 SiteHoneytoken, type SiteHoneytokenOptions, 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, bots, calculateCategoryScores, calculateFinalScore, classifyUserAgent, createAgentVerifier, createCaptchaEndpoints, filter, honeytoken, injectHoneytokenLink, isDatacenterIP, isInjectableHtml, isMobileUA, matchUserAgent, parseUserAgent, rateLimit, readEdgeVerdict, recommend, resolveSecret, siteHoneytoken, tripwire, webBotAuth };