@fetchbrain.com/sdk 0.4.0 → 0.5.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.
@@ -35,6 +35,39 @@ interface FetchBrainConfig {
35
35
  * excluded from telemetry.
36
36
  */
37
37
  skipLabels?: string[];
38
+ /**
39
+ * Recall requests in bulk as they are enqueued (default: true).
40
+ *
41
+ * In HttpCrawler/CheerioCrawler the HTTP fetch happens BEFORE the request handler runs,
42
+ * so a recall inside the handler is too late to save the fetch. With preRecall the SDK
43
+ * wraps `crawler.addRequests()` (which `run(requests)` also goes through), recalls the
44
+ * whole batch in one API call, marks known requests with `skipNavigation` so Crawlee
45
+ * never fetches them, and stashes the result so the handler does no second recall.
46
+ *
47
+ * Scope: applies to ARRAY input passed to `crawler.addRequests()` / `run(requests)`.
48
+ * Crawlee's context-level `enqueueLinks()` and context `addRequests()` reach the queue
49
+ * via other paths and are not pre-recalled (they still get handler-time recall) — in a
50
+ * 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
53
+ * between enqueue and execution is not picked up (the request is simply scraped and
54
+ * re-learned). If a request skipped its fetch but its remembered data expired before
55
+ * execution (e.g. across a process restart), it fails once without retries and lands
56
+ * in your `failedRequestHandler`; it will be re-scraped on a future run. A transient
57
+ * API outage during that restore is retried normally instead.
58
+ * On crawlers with `retryOnBlocked` the fetch is never skipped (Crawlee's blocked-check
59
+ * needs a response); recalled data still replaces the handler.
60
+ * Set to false to restore handler-time recall only.
61
+ */
62
+ preRecall?: boolean;
63
+ /**
64
+ * Called whenever recalled data is delivered in place of a live scrape — the handler
65
+ * was auto-skipped and the remembered data pushed, or your handler called
66
+ * `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
68
+ * breaks the crawl.
69
+ */
70
+ onRecalled?: (event: RecalledEvent) => void | Promise<void>;
38
71
  /** Custom data extractor for learning */
39
72
  extractForLearning?: (data: unknown) => Record<string, unknown>;
40
73
  /**
@@ -71,6 +104,13 @@ interface FetchBrainConfig {
71
104
  */
72
105
  telemetry?: TelemetryConfig;
73
106
  }
107
+ /** Info passed to `onRecalled` when remembered data is delivered in place of a live scrape */
108
+ interface RecalledEvent {
109
+ url: string;
110
+ label?: string;
111
+ userData?: Record<string, unknown>;
112
+ data: Record<string, unknown>;
113
+ }
74
114
  /** The raw request the SDK forwards; the API derives identity from a subset. */
75
115
  interface RawRequest {
76
116
  url: string;
@@ -229,4 +269,4 @@ interface TelemetryResponse {
229
269
  status: "success" | "partial" | "error";
230
270
  }
231
271
 
232
- export type { AskResponse as A, BatchConfig as B, CircuitState as C, FetchBrainConfig as F, LearnResponse as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, TelemetryConfig as b, CircuitBreakerConfig as c, Logger as d, LogLevel as e, RecallRequest as f, RecallResponse as g, RecallResultItem as h, LearnRequest as i, TelemetryRequest as j, TelemetryResponse as k };
272
+ export type { AskResponse as A, BatchConfig as B, CircuitState as C, FetchBrainConfig as F, LearnResponse as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, TelemetryConfig as b, CircuitBreakerConfig as c, Logger as d, LogLevel as e, RecallRequest as f, RecallResponse as g, RecallResultItem as h, LearnRequest as i, RecalledEvent as j, TelemetryRequest as k, TelemetryResponse as l };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fetchbrain.com/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.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",