@fetchbrain.com/sdk 0.1.7 → 0.3.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 +261 -120
- package/dist/index.d.mts +33 -222
- package/dist/index.d.ts +33 -222
- package/dist/index.js +188 -140
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +189 -140
- package/dist/index.mjs.map +1 -1
- package/dist/mock/index.d.mts +70 -0
- package/dist/mock/index.d.ts +70 -0
- package/dist/mock/index.js +168 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/mock/index.mjs +165 -0
- package/dist/mock/index.mjs.map +1 -0
- package/dist/types-CSX4KGoU.d.mts +209 -0
- package/dist/types-CSX4KGoU.d.ts +209 -0
- package/package.json +7 -2
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FetchBrain SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the FetchBrain AI-powered scraping optimization SDK.
|
|
5
|
+
*/
|
|
6
|
+
/** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
|
|
7
|
+
type MemoryDepth = "fresh" | "recent" | "standard" | "deep";
|
|
8
|
+
/** Configuration for FetchBrain SDK */
|
|
9
|
+
interface FetchBrainConfig {
|
|
10
|
+
/** API key for authentication */
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** Base URL for API (defaults to production) */
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
|
|
15
|
+
memory?: MemoryDepth;
|
|
16
|
+
/** Whether AI should learn from new pages */
|
|
17
|
+
learning?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Control which handlers run when AI knows the page.
|
|
20
|
+
* - false: Auto-skip all handlers when AI knows (default)
|
|
21
|
+
* - true: Always run all handlers
|
|
22
|
+
* - string[]: Only run handlers with these labels (e.g., ['listing', 'category'])
|
|
23
|
+
* - 'default': Only run the default handler
|
|
24
|
+
*
|
|
25
|
+
* Recalled data always available via context.brain
|
|
26
|
+
*/
|
|
27
|
+
alwaysRun?: boolean | string | string[];
|
|
28
|
+
/** Custom data extractor for learning */
|
|
29
|
+
extractForLearning?: (data: unknown) => Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* If true, only return known data from the same build version.
|
|
32
|
+
* When a scraper updates, it will re-scrape instead of using stale data.
|
|
33
|
+
* Uses the platform's native build identifier, auto-detected from the environment.
|
|
34
|
+
* Default: false
|
|
35
|
+
*/
|
|
36
|
+
refreshOnRebuild?: boolean;
|
|
37
|
+
/** Request timeout in ms (default: 500ms for fast degradation) */
|
|
38
|
+
timeout?: number;
|
|
39
|
+
/** Enable debug logging */
|
|
40
|
+
debug?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Field name to use as URL for learning
|
|
43
|
+
* Useful when request URL is an API endpoint but data contains the actual page URL
|
|
44
|
+
*/
|
|
45
|
+
learnUrlField?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Batching configuration for high-performance crawling
|
|
48
|
+
*/
|
|
49
|
+
batch?: Partial<BatchConfig>;
|
|
50
|
+
/**
|
|
51
|
+
* Circuit breaker configuration for stability
|
|
52
|
+
*/
|
|
53
|
+
circuitBreaker?: Partial<CircuitBreakerConfig>;
|
|
54
|
+
/**
|
|
55
|
+
* Telemetry configuration - opt-in anonymous data sharing
|
|
56
|
+
* Helps improve proxy recommendations, detect blocks, optimize configs
|
|
57
|
+
* Default: disabled
|
|
58
|
+
*/
|
|
59
|
+
telemetry?: TelemetryConfig;
|
|
60
|
+
}
|
|
61
|
+
/** The raw request the SDK forwards; the API derives identity from a subset. */
|
|
62
|
+
interface RawRequest {
|
|
63
|
+
url: string;
|
|
64
|
+
method?: string;
|
|
65
|
+
uniqueKey?: string;
|
|
66
|
+
body?: string;
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
userData?: Record<string, unknown>;
|
|
69
|
+
label?: string;
|
|
70
|
+
}
|
|
71
|
+
/** Recall request to the API */
|
|
72
|
+
interface RecallRequest {
|
|
73
|
+
items: {
|
|
74
|
+
ref: string;
|
|
75
|
+
request: RawRequest;
|
|
76
|
+
}[];
|
|
77
|
+
memory: MemoryDepth;
|
|
78
|
+
build?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Single recall result (matched by ref) */
|
|
81
|
+
interface RecallResultItem {
|
|
82
|
+
ref: string;
|
|
83
|
+
data?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
/** Recall response from the API */
|
|
86
|
+
interface RecallResponse {
|
|
87
|
+
known: {
|
|
88
|
+
ref: string;
|
|
89
|
+
data: Record<string, unknown>;
|
|
90
|
+
}[];
|
|
91
|
+
unknown: string[];
|
|
92
|
+
}
|
|
93
|
+
/** Learn request to the API */
|
|
94
|
+
interface LearnRequest {
|
|
95
|
+
entries: {
|
|
96
|
+
request: RawRequest;
|
|
97
|
+
data: Record<string, unknown>;
|
|
98
|
+
}[];
|
|
99
|
+
}
|
|
100
|
+
/** Learn response from the API */
|
|
101
|
+
interface LearnResponse {
|
|
102
|
+
learned: number;
|
|
103
|
+
status: "success" | "partial" | "rejected";
|
|
104
|
+
errors?: string[];
|
|
105
|
+
}
|
|
106
|
+
/** Stats response from the API */
|
|
107
|
+
interface StatsResponse {
|
|
108
|
+
queries: number;
|
|
109
|
+
known: number;
|
|
110
|
+
recallRate: number;
|
|
111
|
+
learned: number;
|
|
112
|
+
period: string;
|
|
113
|
+
}
|
|
114
|
+
/** Result from AI knowledge recall */
|
|
115
|
+
interface RecallResult {
|
|
116
|
+
known: boolean;
|
|
117
|
+
data?: Record<string, unknown>;
|
|
118
|
+
fallback?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** Response from a natural-language ask against learned knowledge */
|
|
121
|
+
interface AskResponse {
|
|
122
|
+
sources: {
|
|
123
|
+
score: number;
|
|
124
|
+
url?: string;
|
|
125
|
+
data: unknown;
|
|
126
|
+
}[];
|
|
127
|
+
answer?: string;
|
|
128
|
+
status: "ok" | "unavailable";
|
|
129
|
+
}
|
|
130
|
+
/** Circuit breaker states */
|
|
131
|
+
type CircuitState = "closed" | "open" | "half-open";
|
|
132
|
+
/** Circuit breaker configuration */
|
|
133
|
+
interface CircuitBreakerConfig {
|
|
134
|
+
/** Number of failures before opening circuit */
|
|
135
|
+
failureThreshold: number;
|
|
136
|
+
/** Time to wait before trying half-open state (ms) */
|
|
137
|
+
resetTimeout: number;
|
|
138
|
+
/** Number of successful calls to close circuit from half-open */
|
|
139
|
+
successThreshold: number;
|
|
140
|
+
}
|
|
141
|
+
/** Batch configuration */
|
|
142
|
+
interface BatchConfig {
|
|
143
|
+
/** Max items per batch */
|
|
144
|
+
maxSize: number;
|
|
145
|
+
/** Max wait time before flushing (ms) */
|
|
146
|
+
maxWait: number;
|
|
147
|
+
}
|
|
148
|
+
/** Log levels */
|
|
149
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
150
|
+
/** Logger interface */
|
|
151
|
+
interface Logger {
|
|
152
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
153
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
154
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
155
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Telemetry configuration - opt-in data sharing for AI improvements
|
|
159
|
+
*/
|
|
160
|
+
interface TelemetryConfig {
|
|
161
|
+
/** Enable telemetry collection (default: false — opt in to join the access-intelligence network) */
|
|
162
|
+
enabled: boolean;
|
|
163
|
+
/** Share performance metrics: response times, retries, status codes */
|
|
164
|
+
sharePerformance?: boolean;
|
|
165
|
+
/** Share proxy info: country, type (never IP addresses) */
|
|
166
|
+
shareProxyInfo?: boolean;
|
|
167
|
+
/** Share site patterns: block rates, rate limits detected */
|
|
168
|
+
shareSitePatterns?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Telemetry data collected from Crawlee context
|
|
172
|
+
* All data is sanitized - no PII, no credentials, no raw content
|
|
173
|
+
*/
|
|
174
|
+
interface TelemetryData {
|
|
175
|
+
domain: string;
|
|
176
|
+
urlHash: string;
|
|
177
|
+
urlPattern?: string;
|
|
178
|
+
responseTimeMs?: number;
|
|
179
|
+
totalTimeMs?: number;
|
|
180
|
+
statusCode?: number;
|
|
181
|
+
contentSize?: number;
|
|
182
|
+
retryCount?: number;
|
|
183
|
+
proxyCountry?: string;
|
|
184
|
+
proxyType?: string;
|
|
185
|
+
proxySuccess?: boolean;
|
|
186
|
+
sessionAge?: number;
|
|
187
|
+
sessionErrorScore?: number;
|
|
188
|
+
cookieCount?: number;
|
|
189
|
+
blocked?: boolean;
|
|
190
|
+
blockType?: string;
|
|
191
|
+
crawlerType?: string;
|
|
192
|
+
requestLabel?: string;
|
|
193
|
+
timestamp: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Telemetry request to the API
|
|
197
|
+
*/
|
|
198
|
+
interface TelemetryRequest {
|
|
199
|
+
entries: TelemetryData[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Telemetry response from the API
|
|
203
|
+
*/
|
|
204
|
+
interface TelemetryResponse {
|
|
205
|
+
received: number;
|
|
206
|
+
status: "success" | "partial" | "error";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fetchbrain.com/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./mock": {
|
|
15
|
+
"types": "./dist/mock/index.d.ts",
|
|
16
|
+
"import": "./dist/mock/index.mjs",
|
|
17
|
+
"require": "./dist/mock/index.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"files": [
|