scrapfly-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 +36 -3
- package/esm/browserconfig.d.ts +37 -5
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +51 -3
- package/esm/client.d.ts +124 -9
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +346 -50
- package/esm/crawl.d.ts +58 -1
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +55 -0
- package/esm/crawlerconfig.d.ts +41 -3
- package/esm/crawlerconfig.d.ts.map +1 -1
- package/esm/crawlerconfig.js +93 -2
- package/esm/crawlerresult.d.ts +335 -2
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/crawlerresult.js +367 -1
- package/esm/errors.d.ts +12 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +11 -0
- package/esm/main.d.ts +4 -4
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +3 -3
- package/esm/scrapeconfig.d.ts +36 -0
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +44 -2
- package/esm/types.d.ts.map +1 -1
- package/esm/webhookserver.d.ts +33 -15
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +197 -38
- package/package.json +1 -1
- package/script/browserconfig.d.ts +37 -5
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +51 -3
- package/script/client.d.ts +124 -9
- package/script/client.d.ts.map +1 -1
- package/script/client.js +345 -49
- package/script/crawl.d.ts +58 -1
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +55 -0
- package/script/crawlerconfig.d.ts +41 -3
- package/script/crawlerconfig.d.ts.map +1 -1
- package/script/crawlerconfig.js +94 -3
- package/script/crawlerresult.d.ts +335 -2
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/crawlerresult.js +374 -2
- package/script/errors.d.ts +12 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +12 -1
- package/script/main.d.ts +4 -4
- package/script/main.d.ts.map +1 -1
- package/script/main.js +9 -2
- package/script/scrapeconfig.d.ts +36 -0
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +44 -2
- package/script/types.d.ts.map +1 -1
- package/script/webhookserver.d.ts +33 -15
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +197 -38
- package/src/browserconfig.ts +52 -4
- package/src/client.ts +413 -51
- package/src/crawl.ts +74 -0
- package/src/crawlerconfig.ts +115 -5
- package/src/crawlerresult.ts +566 -3
- package/src/errors.ts +12 -0
- package/src/main.ts +25 -2
- package/src/scrapeconfig.ts +54 -2
- package/src/types.ts +0 -1
- package/src/webhookserver.ts +235 -39
package/src/crawlerconfig.ts
CHANGED
|
@@ -34,8 +34,8 @@ const VALID_CONTENT_FORMATS: ReadonlySet<string> = new Set([
|
|
|
34
34
|
/**
|
|
35
35
|
* Webhook event names emitted by the crawler.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Event names match the wire format documented in the Crawler API webhook reference.
|
|
38
|
+
* Verified against the public docs and the JSON example payloads.
|
|
39
39
|
*/
|
|
40
40
|
export type CrawlerWebhookEventName =
|
|
41
41
|
| 'crawler_started'
|
|
@@ -45,7 +45,16 @@ export type CrawlerWebhookEventName =
|
|
|
45
45
|
| 'crawler_url_failed'
|
|
46
46
|
| 'crawler_stopped'
|
|
47
47
|
| 'crawler_cancelled'
|
|
48
|
-
| 'crawler_finished'
|
|
48
|
+
| 'crawler_finished'
|
|
49
|
+
| 'crawler_search_ready'
|
|
50
|
+
| 'crawler_search_failed'
|
|
51
|
+
| 'crawler_updated';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Auto-refresh interval bounds, in seconds (1 hour to 90 days).
|
|
55
|
+
*/
|
|
56
|
+
export const REFRESH_MIN_INTERVAL = 3600;
|
|
57
|
+
export const REFRESH_MAX_INTERVAL = 90 * 24 * 3600;
|
|
49
58
|
|
|
50
59
|
const VALID_WEBHOOK_EVENTS: ReadonlySet<string> = new Set([
|
|
51
60
|
'crawler_started',
|
|
@@ -56,6 +65,9 @@ const VALID_WEBHOOK_EVENTS: ReadonlySet<string> = new Set([
|
|
|
56
65
|
'crawler_stopped',
|
|
57
66
|
'crawler_cancelled',
|
|
58
67
|
'crawler_finished',
|
|
68
|
+
'crawler_search_ready',
|
|
69
|
+
'crawler_search_failed',
|
|
70
|
+
'crawler_updated',
|
|
59
71
|
]);
|
|
60
72
|
|
|
61
73
|
/**
|
|
@@ -110,7 +122,27 @@ export type CrawlerConfigOptions = {
|
|
|
110
122
|
content_formats?: CrawlerContentFormat[];
|
|
111
123
|
extraction_rules?: Rec<any>;
|
|
112
124
|
|
|
125
|
+
// Search index built while the crawl runs. Query it with
|
|
126
|
+
// ScrapflyClient.crawlSearch / crawlPrompt once the index is READY.
|
|
127
|
+
search?: boolean;
|
|
128
|
+
|
|
129
|
+
// Auto-refresh: re-scrape this crawl's own URLs in place, on a period. Same
|
|
130
|
+
// crawler_uuid, same artifacts, only changed pages re-indexed.
|
|
131
|
+
refresh?: boolean;
|
|
132
|
+
refresh_interval?: number;
|
|
133
|
+
|
|
113
134
|
// Web scraping features
|
|
135
|
+
/**
|
|
136
|
+
* Anti-bot bypass. The current name for what used to be called `asp`.
|
|
137
|
+
* Sent in the `POST /crawl` body as `asp`; only the SDK-facing name changed.
|
|
138
|
+
*/
|
|
139
|
+
unblocker?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* @deprecated Use {@link CrawlerConfigOptions.unblocker}. `asp` is a
|
|
142
|
+
* permanently supported alias and keeps working forever. When both are
|
|
143
|
+
* supplied `asp` wins, so existing code cannot have its meaning changed by a
|
|
144
|
+
* later `unblocker`.
|
|
145
|
+
*/
|
|
114
146
|
asp?: boolean;
|
|
115
147
|
proxy_pool?: string;
|
|
116
148
|
country?: string;
|
|
@@ -171,6 +203,17 @@ export class CrawlerConfig {
|
|
|
171
203
|
content_formats?: CrawlerContentFormat[];
|
|
172
204
|
extraction_rules?: Rec<any>;
|
|
173
205
|
|
|
206
|
+
search?: boolean;
|
|
207
|
+
|
|
208
|
+
refresh?: boolean;
|
|
209
|
+
refresh_interval?: number;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Storage for the anti-bot bypass toggle, under its deprecated name.
|
|
213
|
+
* `unblocker` is an accessor over this same field — see below.
|
|
214
|
+
*
|
|
215
|
+
* @deprecated Use {@link CrawlerConfig.unblocker}. `asp` keeps working forever.
|
|
216
|
+
*/
|
|
174
217
|
asp?: boolean;
|
|
175
218
|
proxy_pool?: string;
|
|
176
219
|
country?: string;
|
|
@@ -234,6 +277,20 @@ export class CrawlerConfig {
|
|
|
234
277
|
if (options.allowed_internal_subdomains && options.allowed_internal_subdomains.length > 250) {
|
|
235
278
|
throw new CrawlerConfigError('allowed_internal_subdomains is limited to 250 entries');
|
|
236
279
|
}
|
|
280
|
+
// The floor decides the cost: a crawl refreshing every minute re-scrapes
|
|
281
|
+
// the whole site 1,440 times a day.
|
|
282
|
+
if (
|
|
283
|
+
options.refresh_interval !== undefined &&
|
|
284
|
+
(options.refresh_interval < REFRESH_MIN_INTERVAL || options.refresh_interval > REFRESH_MAX_INTERVAL)
|
|
285
|
+
) {
|
|
286
|
+
throw new CrawlerConfigError(
|
|
287
|
+
`refresh_interval must be between ${REFRESH_MIN_INTERVAL} and ${REFRESH_MAX_INTERVAL} (seconds, 1 hour to 90 days)`,
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
// A period with the feature off would silently never run.
|
|
291
|
+
if (options.refresh_interval !== undefined && !options.refresh) {
|
|
292
|
+
throw new CrawlerConfigError('refresh_interval requires refresh: true');
|
|
293
|
+
}
|
|
237
294
|
|
|
238
295
|
// Validate content_formats values
|
|
239
296
|
if (options.content_formats) {
|
|
@@ -278,13 +335,37 @@ export class CrawlerConfig {
|
|
|
278
335
|
this.cache_clear = options.cache_clear;
|
|
279
336
|
this.content_formats = options.content_formats;
|
|
280
337
|
this.extraction_rules = options.extraction_rules;
|
|
281
|
-
this.
|
|
338
|
+
this.search = options.search;
|
|
339
|
+
this.refresh = options.refresh;
|
|
340
|
+
this.refresh_interval = options.refresh_interval;
|
|
341
|
+
// An explicitly supplied `asp` always wins; the deprecated alias is only
|
|
342
|
+
// superseded by `unblocker` when it was not supplied at all. `??` and not
|
|
343
|
+
// `||`, so an explicit `false` on either name still reaches the server.
|
|
344
|
+
// Both unset stays `undefined`, which toApiParams drops so the server
|
|
345
|
+
// applies its own default.
|
|
346
|
+
this.asp = options.asp ?? options.unblocker;
|
|
282
347
|
this.proxy_pool = options.proxy_pool;
|
|
283
348
|
this.country = options.country;
|
|
284
349
|
this.webhook_name = options.webhook_name;
|
|
285
350
|
this.webhook_events = options.webhook_events;
|
|
286
351
|
}
|
|
287
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Anti-bot bypass toggle — the current name for what used to be `asp`.
|
|
355
|
+
*
|
|
356
|
+
* An accessor over the single `asp` field rather than a second stored
|
|
357
|
+
* property: one storage slot means the two names can never disagree, and
|
|
358
|
+
* `toApiParams` keeps serializing the one field under the wire key `asp`.
|
|
359
|
+
* `undefined` propagates in both directions, so "unset" stays unset.
|
|
360
|
+
*/
|
|
361
|
+
get unblocker(): boolean | undefined {
|
|
362
|
+
return this.asp;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
set unblocker(value: boolean | undefined) {
|
|
366
|
+
this.asp = value;
|
|
367
|
+
}
|
|
368
|
+
|
|
288
369
|
private validateOptions(options: Partial<CrawlerConfigOptions>) {
|
|
289
370
|
const validKeys = new Set<string>([
|
|
290
371
|
'url',
|
|
@@ -314,6 +395,10 @@ export class CrawlerConfig {
|
|
|
314
395
|
'cache_clear',
|
|
315
396
|
'content_formats',
|
|
316
397
|
'extraction_rules',
|
|
398
|
+
'search',
|
|
399
|
+
'refresh',
|
|
400
|
+
'refresh_interval',
|
|
401
|
+
'unblocker',
|
|
317
402
|
'asp',
|
|
318
403
|
'proxy_pool',
|
|
319
404
|
'country',
|
|
@@ -367,7 +452,9 @@ export class CrawlerConfig {
|
|
|
367
452
|
'cache_clear',
|
|
368
453
|
'content_formats',
|
|
369
454
|
'extraction_rules',
|
|
370
|
-
'
|
|
455
|
+
'search',
|
|
456
|
+
'refresh',
|
|
457
|
+
'refresh_interval',
|
|
371
458
|
'proxy_pool',
|
|
372
459
|
'country',
|
|
373
460
|
'webhook_name',
|
|
@@ -379,6 +466,29 @@ export class CrawlerConfig {
|
|
|
379
466
|
params[key] = v;
|
|
380
467
|
}
|
|
381
468
|
}
|
|
469
|
+
|
|
470
|
+
// The anti-bot toggle is serialized apart from the loop above because it is
|
|
471
|
+
// the one field where `false` and "not supplied" must collapse.
|
|
472
|
+
//
|
|
473
|
+
// The key is `asp` and never `unblocker`: the wire key is unchanged for
|
|
474
|
+
// both names. A published package version is immutable and upgraded per
|
|
475
|
+
// installation, so emitting `unblocker` against an API deployment that has
|
|
476
|
+
// not learned that name yet would silently drop a paid feature — the crawl
|
|
477
|
+
// runs, is billed, and comes back blocked. Renaming the emitted key is a
|
|
478
|
+
// separate, later release.
|
|
479
|
+
//
|
|
480
|
+
// Only `true` is emitted. CROSS-SDK SHAPE: the Python, Go and Rust SDKs all
|
|
481
|
+
// omit the key when the feature is off (Python's `asp` is a plain `bool`,
|
|
482
|
+
// Go's is a `bool`, Rust's carries `skip_serializing_if = "is_false"`), so
|
|
483
|
+
// carrying an explicit `asp: false` here would make the same customer
|
|
484
|
+
// intent produce two different POST /crawl bodies depending on which SDK
|
|
485
|
+
// they picked. The API cannot tell the two apart either: it resolves a
|
|
486
|
+
// present-false and an absent pair to the same `false`, so an explicit
|
|
487
|
+
// `asp: false` on the wire buys nothing. One shape, all four SDKs.
|
|
488
|
+
if (this.asp === true) {
|
|
489
|
+
params.asp = true;
|
|
490
|
+
}
|
|
491
|
+
|
|
382
492
|
return params;
|
|
383
493
|
}
|
|
384
494
|
}
|