@fetchbrain.com/sdk 0.11.0 → 0.12.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/README.md CHANGED
@@ -94,7 +94,7 @@ That's it. Your handler only runs when there's something new to learn.
94
94
  - **Never breaks your crawl** — the circuit breaker degrades gracefully; an outage costs you optimization, not your crawl (one deliberate exception: [expired memory](#recall-at-enqueue-time-prerecall))
95
95
  - **Built for scale** — request batching and deduping for high-concurrency crawlers
96
96
  - **Crawlee-native** — CheerioCrawler, PlaywrightCrawler, and friends (browser crawlers — Playwright, Puppeteer — from 0.7.1; earlier versions did not apply FetchBrain to them. `AdaptivePlaywrightCrawler` is not supported yet)
97
- - **Transparent** — see exactly [what leaves your process](#what-leaves-your-process). Telemetry is **opt-in** and pseudonymous ([details](#telemetry-opt-in))
97
+ - **Transparent** — see exactly [what leaves your process](#what-leaves-your-process).
98
98
  - **TypeScript-first** — full types, ESM + CJS; an API key is the only required option
99
99
 
100
100
  ## Who is it for?
@@ -243,6 +243,7 @@ interface FetchBrainConfig {
243
243
  scraper?: string; // Name this scraper so it gets its own memory (or set FETCHBRAIN_SCRAPER_ID)
244
244
  baseUrl?: string; // API URL (default: https://api.fetchbrain.com)
245
245
  memory?: MemoryDepth; // How far back the brain recalls (default: "recent")
246
+ recall?: boolean; // Recall known pages and skip their fetches; false = fetch and learn everything (default: true)
246
247
  learning?: boolean; // Teach the brain from scraped data (default: true)
247
248
  alwaysRun?: boolean | string | string[]; // Handlers that still run when a request is known (default: false)
248
249
  skipLabels?: string[]; // Labels that bypass FetchBrain entirely (default: none)
@@ -250,7 +251,7 @@ interface FetchBrainConfig {
250
251
  onRecalled?: (event: RecalledEvent) => void | Promise<void>; // Per-record hook when recalled data is delivered
251
252
  extractForLearning?: (data: unknown) => Record<string, unknown>; // Transform each record before it is learned
252
253
  refreshOnRebuild?: boolean; // Scope learn, recall and ask to the current build (*_BUILD_ID env var) (default: false)
253
- timeout?: number; // Handler-time recall, stats and telemetry timeout in ms, 1-2147483647 (default: 1500)
254
+ timeout?: number; // Handler-time recall and stats timeout in ms, 1-2147483647 (default: 1500)
254
255
  askTimeout?: number; // ask() timeout in ms, 1-2147483647 (default: 60000); a per-call `timeout` wins
255
256
  batch?: { maxSize?: number; maxWait?: number }; // Request batching (default: 50 items / 50ms)
256
257
  circuitBreaker?: {
@@ -258,7 +259,6 @@ interface FetchBrainConfig {
258
259
  resetTimeout?: number; // ms before a retry is allowed (default: 30000)
259
260
  successThreshold?: number; // Successes to close it again (default: 1)
260
261
  };
261
- telemetry?: TelemetryConfig; // Opt-in telemetry (default: { enabled: false })
262
262
  changeDetection?: { enabled?: boolean; ignoreFields?: string[] }; // Relearn known alwaysRun pages and report changes (default: off)
263
263
  reportRuns?: boolean; // Send the end-of-run report: run id, timestamps, counts per label (default: true)
264
264
  learnUrlField?: string; // Accepted but not currently applied
@@ -405,7 +405,7 @@ FetchBrain.enhance(crawler, {
405
405
  For dynamic requests that must always run live and aren't worth remembering
406
406
  (search results, pagination), use `skipLabels` instead: where `alwaysRun`
407
407
  still recalls (and can learn), `skipLabels` bypasses FetchBrain entirely —
408
- no recall round-trip, no learn, no telemetry — so those requests run at
408
+ no recall round-trip, no learn — so those requests run at
409
409
  native speed:
410
410
 
411
411
  ```typescript
@@ -571,7 +571,7 @@ Timeouts per call type:
571
571
  | Recall at enqueue (`preRecall`, bulk) | 3s per chunk of up to 100 requests |
572
572
  | Learn (batched, sent in the background) | 5s |
573
573
  | `ask()` | `askTimeout` option (default 60s), or `timeout` per call |
574
- | `stats()` and telemetry | `timeout` option, default 1.5s |
574
+ | `stats()` | `timeout` option, default 1.5s |
575
575
 
576
576
  A FetchBrain outage costs you *optimization*, not your crawl: SDK calls
577
577
  degrade gracefully instead of throwing into it. The one deliberate
@@ -667,8 +667,8 @@ the fetch, so those pages can't skip it) or when `preRecall` is `false`. A page
667
667
  through `context.pushData` or the SDK's `pushData` export (pages written
668
668
  straight to Crawlee's static `Dataset.pushData` are counted that way too), and
669
669
  retries count once per attempt. The report is sent with the same standard
670
- headers as every other call (see [What leaves your process](#what-leaves-your-process)). It is what powers the unhealthy-run warnings above. It is not
671
- [telemetry](#telemetry-opt-in) and is on by default; set `reportRuns: false` to
670
+ headers as every other call (see [What leaves your process](#what-leaves-your-process)). It is what powers the unhealthy-run warnings above. It is on by
671
+ default; set `reportRuns: false` to
672
672
  turn it off. It is bounded to a few seconds at the end of a run and can never
673
673
  fail your crawl.
674
674
 
@@ -677,7 +677,7 @@ You can browse what changed in the FetchBrain dashboard, or fetch it from
677
677
 
678
678
  ## What leaves your process
679
679
 
680
- Every API call (recall, learn, ask, stats, telemetry, run report) sends these headers:
680
+ Every API call (recall, learn, ask, stats, run report) sends these headers:
681
681
 
682
682
  | Header | Value |
683
683
  | --- | --- |
@@ -717,86 +717,11 @@ Other headers (for example
717
717
  forwarded as-is — keep secrets out of them on requests FetchBrain handles,
718
718
  or route those requests through `skipLabels`, which sends nothing for them.
719
719
 
720
- `ask()` sends your question and options. Telemetry sends nothing unless you
721
- [opt in](#telemetry-opt-in). At the end of a run the SDK also sends a small
720
+ `ask()` sends your question and options. At the end of a run the SDK also sends a small
722
721
  [run report](#run-report): run id, start/end timestamps, scraped/learned/recalled
723
722
  counts, requests skipped, late recalls and bypassed counts, per-label page counts, and a build id only with `refreshOnRebuild`
724
723
  (`reportRuns: false` turns it off).
725
724
 
726
- ## Telemetry (opt-in)
727
-
728
- Telemetry is **off by default.** Nothing in this section is collected or
729
- sent unless you opt in:
730
-
731
- ```typescript
732
- FetchBrain.enhance(crawler, {
733
- apiKey: process.env.FETCHBRAIN_API_KEY,
734
- telemetry: { enabled: true },
735
- });
736
- ```
737
-
738
- **It's pseudonymous, not anonymous.** Entries are sent to the FetchBrain
739
- API with your API key and the [headers above](#what-leaves-your-process),
740
- so they're linked to your account. They're used to improve FetchBrain's
741
- recommendations (proxy recommendations, block detection, configuration
742
- tuning); aggregated statistics may inform recommendations for other users.
743
-
744
- **How long it's kept:** raw entries are deleted about 30 days after they're
745
- received (a daily cleanup), and all of your entries are deleted when you
746
- delete your account (a very large history may take the daily cleanup a few
747
- days to finish, never longer than the 30 days above).
748
- Per-domain aggregate counts (requests, successes, blocks and block rate for a
749
- hostname, with no URLs and no account link) are kept. Per-domain statistics
750
- are aggregated per domain, not per account: entries from every account that
751
- scraped a hostname add to the same counts, and they are not deleted with your
752
- account.
753
-
754
- **When it's collected:** one entry per request FetchBrain handles
755
- (`skipLabels` requests are excluded), after your handler finishes — or
756
- whenever the request fails inside the SDK's wrapper, including failures
757
- before your handler runs (e.g. [expired memory](#recall-at-enqueue-time-prerecall))
758
- and on known requests. Known requests that are skipped successfully produce
759
- no entry. A failure entry carries only the "always" fields (minus session),
760
- `retryCount`, timing, and `blocked: true` with a `blockType` if one matches.
761
- Entries are buffered in your process and sent in batches (every 50 entries,
762
- every 30 seconds, and when the crawl finishes); send failures are ignored and
763
- never affect your crawl.
764
-
765
- **What's sent:**
766
-
767
- | Field | Sent when | What it is |
768
- | --- | --- | --- |
769
- | `domain` | always | the URL's hostname, in plain text (e.g. `shop.example.com`) |
770
- | `urlHash` | always | first 16 hex characters of an **unsalted** SHA-256 of the full URL, including the query string. Anyone with a candidate URL can compute the same hash, so it identifies URLs that are guessable. |
771
- | `urlPattern` | always | the URL path with numeric segments, UUIDs and alphanumeric tokens of 20+ characters replaced by `*`; the query string is dropped. Everything else — slugs, usernames, words — is sent as-is (e.g. `/users/jane-doe/orders/*`). |
772
- | `timestamp` | always | when the entry was collected |
773
- | `crawlerType` | always | crawler class name, lowercased, without `Crawler` (e.g. `cheerio`) |
774
- | `requestLabel` | always | the request's Crawlee label, if set |
775
- | `sessionAge`, `sessionErrorScore` | on success, if the request has a Crawlee session | the session's usage count and error score |
776
- | `statusCode` | `sharePerformance`, on success | HTTP status |
777
- | `retryCount` | `sharePerformance` | Crawlee retry count |
778
- | `responseTimeMs`, `totalTimeMs` | `sharePerformance` | time in ms from when the SDK starts handling the request (including recall) until your handler finishes or the request fails |
779
- | `contentSize` | `sharePerformance`, on success | response body length, when the crawler exposes it |
780
- | `blocked`, `blockType` | `shareSitePatterns` | `blocked` is true for status 403, 429 or 5xx, or when the request failed inside the SDK wrapper for any reason; `blockType` is the status code (4xx/5xx) or a category matched in the error message (`captcha`, `timeout`, `blocked`, `429` for "rate limit") — the message itself isn't sent |
781
- | `proxyCountry`, `proxyType`, `proxySuccess` | `shareProxyInfo`, on success, if the request used a Crawlee proxy | the proxy's country code; `residential`, `mobile` or `datacenter`, guessed in your process from the proxy URL; and whether the status was below 400. The proxy URL, hostname, IP and credentials are not sent. |
782
-
783
- **Sub-flags** — each defaults to `true` once telemetry is enabled; set one
784
- to `false` to stop sending its fields. The "always" fields above are sent
785
- whenever telemetry is enabled.
786
-
787
- ```typescript
788
- telemetry: {
789
- enabled: true, // default: false
790
- sharePerformance: false, // default: true
791
- shareSitePatterns: true, // default: true
792
- shareProxyInfo: false, // default: true
793
- }
794
- ```
795
-
796
- **Never sent by telemetry:** the raw URL or query string, request or response
797
- bodies, your scraped requests' headers or cookies, error messages, or proxy
798
- URLs and IPs.
799
-
800
725
  ## Testing
801
726
 
802
727
  `MockFetchBrain` ships with the SDK — seed it, run your tests, no network:
@@ -856,8 +781,7 @@ Your requests (minus `Authorization`, `Cookie` and `Set-Cookie` headers),
856
781
  the data you choose to learn, your API key, and a small set of `X-FB-*`
857
782
  headers including platform identifiers (env vars ending in `_ID`, plus
858
783
  `NODE_ENV`/`REGION`/`CI`). The full list is in
859
- [What leaves your process](#what-leaves-your-process). If you opt into
860
- telemetry, the fields in [Telemetry](#telemetry-opt-in) too.
784
+ [What leaves your process](#what-leaves-your-process).
861
785
 
862
786
  **What does learning cost?**
863
787
  Nothing. Learning is never billed — you pay only for known recalls.