@fetchbrain.com/sdk 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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * FetchBrain SDK Types
3
3
  *
4
- * Type definitions for the FetchBrain AI-powered scraping optimization SDK.
4
+ * Type definitions for the FetchBrain SDK — memory for your scrapers.
5
5
  */
6
6
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
7
7
  type MemoryDepth = "fresh" | "recent" | "standard" | "deep";
@@ -9,15 +9,24 @@ type MemoryDepth = "fresh" | "recent" | "standard" | "deep";
9
9
  interface FetchBrainConfig {
10
10
  /** API key for authentication */
11
11
  apiKey: string;
12
+ /**
13
+ * Name this scraper so it gets its own memory (otherwise every scraper on
14
+ * your account outside Apify shares one default memory). Same as setting the
15
+ * FETCHBRAIN_SCRAPER_ID env var; a valid option wins, an empty or invalid one
16
+ * falls back to the env var. Lowercase letters, digits, '.', '_' and '-',
17
+ * max 64, starting with a letter or digit. Invalid names are ignored with a
18
+ * warning. On Apify a name overrides the actor id.
19
+ */
20
+ scraper?: string;
12
21
  /** Base URL for API (defaults to production) */
13
22
  baseUrl?: string;
14
23
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
15
24
  memory?: MemoryDepth;
16
- /** Whether AI should learn from new pages */
25
+ /** Teach the brain from scraped data (default: true) */
17
26
  learning?: boolean;
18
27
  /**
19
- * Control which handlers run when AI knows the page.
20
- * - false: Auto-skip all handlers when AI knows (default)
28
+ * Control which handlers run when the brain knows the request.
29
+ * - false: Auto-skip all handlers when the request is known (default)
21
30
  * - true: Always run all handlers
22
31
  * - string[]: Only run handlers with these labels (e.g., ['listing', 'category'])
23
32
  * - 'default': Only run the default handler
@@ -48,8 +57,8 @@ interface FetchBrainConfig {
48
57
  * Crawlee's context-level `enqueueLinks()` and context `addRequests()` reach the queue
49
58
  * via other paths and are not pre-recalled (they still get handler-time recall) — in a
50
59
  * handler, enqueue follow-ups with `context.crawler.addRequests([...])` instead.
51
- * Note recall usage is metered at enqueue time, so requests the queue later dedups
52
- * still count as queries. The recall result is a snapshot as of enqueue: data learned
60
+ * Note known recalls are counted at enqueue time, so known requests the queue later
61
+ * dedups still count as recalls. The recall result is a snapshot as of enqueue: data learned
53
62
  * between enqueue and execution is not picked up (the request is simply scraped and
54
63
  * re-learned). If a request skipped its fetch but its remembered data expired before
55
64
  * execution (e.g. across a process restart), it fails once without retries and lands
@@ -64,11 +73,11 @@ interface FetchBrainConfig {
64
73
  * Called whenever recalled data is delivered in place of a live scrape — the handler
65
74
  * was auto-skipped and the remembered data pushed, or your handler called
66
75
  * `context.brain.use()`. Use it for per-record bookkeeping that normally lives in your
67
- * handler — e.g. platform billing events. Errors are swallowed: a hook failure never
76
+ * handler — e.g. metrics or counters. Errors are swallowed: a hook failure never
68
77
  * breaks the crawl.
69
78
  */
70
79
  onRecalled?: (event: RecalledEvent) => void | Promise<void>;
71
- /** Custom data extractor for learning */
80
+ /** Transform each pushed record before the brain learns it */
72
81
  extractForLearning?: (data: unknown) => Record<string, unknown>;
73
82
  /**
74
83
  * If true, scope both learn and recall to the current build version.
@@ -85,8 +94,8 @@ interface FetchBrainConfig {
85
94
  /** Enable debug logging */
86
95
  debug?: boolean;
87
96
  /**
88
- * Field name to use as URL for learning
89
- * Useful when request URL is an API endpoint but data contains the actual page URL
97
+ * Field name to use as URL for learning.
98
+ * Note: accepted and stored, but not currently applied by the SDK.
90
99
  */
91
100
  learnUrlField?: string;
92
101
  /**
@@ -98,9 +107,9 @@ interface FetchBrainConfig {
98
107
  */
99
108
  circuitBreaker?: Partial<CircuitBreakerConfig>;
100
109
  /**
101
- * Telemetry configuration - opt-in anonymous data sharing
102
- * Helps improve proxy recommendations, detect blocks, optimize configs
103
- * Default: disabled
110
+ * Telemetry configuration — opt-in, pseudonymous (sent with your API key).
111
+ * Helps improve proxy recommendations, detect blocks, optimize configs.
112
+ * Default: disabled. See the README "Telemetry (opt-in)" section for every field sent.
104
113
  */
105
114
  telemetry?: TelemetryConfig;
106
115
  }
@@ -165,13 +174,13 @@ interface StatsResponse {
165
174
  learned: number;
166
175
  period: string;
167
176
  }
168
- /** Result from AI knowledge recall */
177
+ /** Result of a recall */
169
178
  interface RecallResult {
170
179
  known: boolean;
171
180
  data?: Record<string, unknown>;
172
181
  fallback?: boolean;
173
182
  }
174
- /** Response from a natural-language ask against learned knowledge */
183
+ /** Response from a natural-language ask, answered from everything the account has learned */
175
184
  interface AskResponse {
176
185
  sources: {
177
186
  score: number;
@@ -218,21 +227,23 @@ interface Logger {
218
227
  error: (message: string, ...args: unknown[]) => void;
219
228
  }
220
229
  /**
221
- * Telemetry configuration - opt-in data sharing for AI improvements
230
+ * Telemetry configuration — opt-in, pseudonymous diagnostics sent with your API key.
231
+ * When enabled, each sub-flag defaults to true.
222
232
  */
223
233
  interface TelemetryConfig {
224
- /** Enable telemetry collection (default: false — opt in to join the access-intelligence network) */
234
+ /** Enable telemetry collection (default: false — opt-in) */
225
235
  enabled: boolean;
226
- /** Share performance metrics: response times, retries, status codes */
236
+ /** Share performance metrics: timings, retries, status codes, content size (default: true) */
227
237
  sharePerformance?: boolean;
228
- /** Share proxy info: country, type (never IP addresses) */
238
+ /** Share proxy info: country, locally-derived type, success (never proxy URL/IP) (default: true) */
229
239
  shareProxyInfo?: boolean;
230
- /** Share site patterns: block rates, rate limits detected */
240
+ /** Share block indicators derived from status codes and error categories (default: true) */
231
241
  shareSitePatterns?: boolean;
232
242
  }
233
243
  /**
234
- * Telemetry data collected from Crawlee context
235
- * All data is sanitized - no PII, no credentials, no raw content
244
+ * Telemetry data collected from Crawlee context.
245
+ * No raw URLs, bodies, proxy URLs/IPs or error messages. The hostname, generalized
246
+ * path and request label are sent as-is, linked to your API key.
236
247
  */
237
248
  interface TelemetryData {
238
249
  domain: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fetchbrain.com/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "FetchBrain SDK — make your Crawlee scrapers smarter with every run; recall before you fetch, teach what you learn.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -36,8 +36,6 @@
36
36
  "scraping",
37
37
  "web-scraping",
38
38
  "crawlee",
39
- "crawlee",
40
- "apify",
41
39
  "optimization",
42
40
  "ai",
43
41
  "fetchbrain"