scrapfly-sdk 0.10.4 → 0.10.6
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/esm/batch.d.ts.map +1 -1
- package/esm/batch.js +6 -0
- package/esm/browserconfig.d.ts +80 -1
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +54 -1
- package/esm/client.d.ts +65 -0
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +157 -5
- package/esm/crawl.d.ts +4 -0
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +4 -0
- package/esm/crawlerresult.d.ts +7 -0
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/errors.d.ts +43 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +43 -16
- package/esm/extractionconfig.d.ts +54 -9
- package/esm/extractionconfig.d.ts.map +1 -1
- package/esm/extractionconfig.js +37 -13
- package/esm/logger.d.ts +1 -0
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +1 -0
- package/esm/main.d.ts +29 -0
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +28 -0
- package/esm/monitoringconfig.d.ts +48 -11
- package/esm/monitoringconfig.d.ts.map +1 -1
- package/esm/monitoringconfig.js +14 -0
- package/esm/result.d.ts +2 -0
- package/esm/result.d.ts.map +1 -1
- package/esm/schedule.d.ts +93 -0
- package/esm/schedule.d.ts.map +1 -0
- package/esm/schedule.js +40 -0
- package/esm/scrapeconfig.d.ts +10 -8
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +10 -8
- package/esm/screenshotconfig.d.ts +59 -26
- package/esm/screenshotconfig.d.ts.map +1 -1
- package/esm/screenshotconfig.js +38 -26
- package/esm/webhookserver.d.ts +28 -0
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +34 -3
- package/package.json +1 -1
- package/script/batch.d.ts.map +1 -1
- package/script/batch.js +6 -0
- package/script/browserconfig.d.ts +80 -1
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +54 -1
- package/script/client.d.ts +65 -0
- package/script/client.d.ts.map +1 -1
- package/script/client.js +157 -5
- package/script/crawl.d.ts +4 -0
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +4 -0
- package/script/crawlerresult.d.ts +7 -0
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/errors.d.ts +43 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +43 -16
- package/script/extractionconfig.d.ts +54 -9
- package/script/extractionconfig.d.ts.map +1 -1
- package/script/extractionconfig.js +37 -13
- package/script/logger.d.ts +1 -0
- package/script/logger.d.ts.map +1 -1
- package/script/logger.js +1 -0
- package/script/main.d.ts +29 -0
- package/script/main.d.ts.map +1 -1
- package/script/main.js +30 -1
- package/script/monitoringconfig.d.ts +48 -11
- package/script/monitoringconfig.d.ts.map +1 -1
- package/script/monitoringconfig.js +14 -0
- package/script/result.d.ts +2 -0
- package/script/result.d.ts.map +1 -1
- package/script/schedule.d.ts +93 -0
- package/script/schedule.d.ts.map +1 -0
- package/script/schedule.js +44 -0
- package/script/scrapeconfig.d.ts +10 -8
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +10 -8
- package/script/screenshotconfig.d.ts +59 -26
- package/script/screenshotconfig.d.ts.map +1 -1
- package/script/screenshotconfig.js +38 -26
- package/script/webhookserver.d.ts +28 -0
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +34 -3
- package/src/batch.ts +7 -1
- package/src/browserconfig.ts +82 -1
- package/src/client.ts +227 -7
- package/src/crawl.ts +4 -0
- package/src/crawlerresult.ts +7 -0
- package/src/errors.ts +43 -16
- package/src/extractionconfig.ts +58 -16
- package/src/logger.ts +2 -0
- package/src/main.ts +37 -0
- package/src/monitoringconfig.ts +49 -11
- package/src/result.ts +2 -0
- package/src/schedule.ts +101 -0
- package/src/scrapeconfig.ts +10 -8
- package/src/screenshotconfig.ts +59 -26
- package/src/webhookserver.ts +34 -3
package/script/client.js
CHANGED
|
@@ -33,20 +33,39 @@ const result_js_1 = require("./result.js");
|
|
|
33
33
|
const logger_js_1 = require("./logger.js");
|
|
34
34
|
const crawlerresult_js_1 = require("./crawlerresult.js");
|
|
35
35
|
const monitoringconfig_js_1 = require("./monitoringconfig.js");
|
|
36
|
+
const schedule_js_1 = require("./schedule.js");
|
|
37
|
+
/**
|
|
38
|
+
* Main entry point for the Scrapfly SDK.
|
|
39
|
+
*
|
|
40
|
+
* A single `ScrapflyClient` can be used to call every Scrapfly API
|
|
41
|
+
* (scrape, screenshot, extraction, crawler, monitoring, cloud browser).
|
|
42
|
+
* It is safe to share one instance across concurrent calls.
|
|
43
|
+
*/
|
|
36
44
|
class ScrapflyClient {
|
|
45
|
+
/**
|
|
46
|
+
* Create a Scrapfly client.
|
|
47
|
+
*
|
|
48
|
+
* @param options.key Scrapfly API key.
|
|
49
|
+
* @param options.host Optional override for the REST API host.
|
|
50
|
+
* @param options.cloudBrowserHost Optional override for the Cloud Browser WS host.
|
|
51
|
+
* @throws {@link errors.BadApiKeyError} if `options.key` is not a non-empty string.
|
|
52
|
+
*/
|
|
37
53
|
constructor(options) {
|
|
54
|
+
/** Base URL of the Scrapfly REST API. */
|
|
38
55
|
Object.defineProperty(this, "HOST", {
|
|
39
56
|
enumerable: true,
|
|
40
57
|
configurable: true,
|
|
41
58
|
writable: true,
|
|
42
59
|
value: 'https://api.scrapfly.io'
|
|
43
60
|
});
|
|
61
|
+
/** Default Cloud Browser WebSocket host. */
|
|
44
62
|
Object.defineProperty(this, "CLOUD_BROWSER_HOST", {
|
|
45
63
|
enumerable: true,
|
|
46
64
|
configurable: true,
|
|
47
65
|
writable: true,
|
|
48
66
|
value: 'wss://browser.scrapfly.io'
|
|
49
67
|
});
|
|
68
|
+
/** Default Cloud Browser REST host (derived from the WS host). */
|
|
50
69
|
Object.defineProperty(this, "CLOUD_BROWSER_API_HOST", {
|
|
51
70
|
enumerable: true,
|
|
52
71
|
configurable: true,
|
|
@@ -77,6 +96,7 @@ class ScrapflyClient {
|
|
|
77
96
|
writable: true,
|
|
78
97
|
value: void 0
|
|
79
98
|
});
|
|
99
|
+
/** `fetch` implementation used by the client. Override for custom retries/tracing. */
|
|
80
100
|
Object.defineProperty(this, "fetch", {
|
|
81
101
|
enumerable: true,
|
|
82
102
|
configurable: true,
|
|
@@ -320,6 +340,7 @@ class ScrapflyClient {
|
|
|
320
340
|
// one shape (request-based) but live under different URL prefixes;
|
|
321
341
|
// Cloud Browser is session-based and exposes a distinct shape.
|
|
322
342
|
// See https://scrapfly.io/docs/monitoring#api
|
|
343
|
+
/** Dispatch an HTTP GET against a Monitoring API path with the given query params, parsing errors. */
|
|
323
344
|
async monitoringRequest(path, params) {
|
|
324
345
|
const url = new URL(this.HOST + path);
|
|
325
346
|
url.search = new URLSearchParams(params).toString();
|
|
@@ -341,6 +362,7 @@ class ScrapflyClient {
|
|
|
341
362
|
}
|
|
342
363
|
return data;
|
|
343
364
|
}
|
|
365
|
+
/** Build the query string for a request-based Monitoring API metrics endpoint. */
|
|
344
366
|
buildMetricsParams(options) {
|
|
345
367
|
const params = {
|
|
346
368
|
key: this.key,
|
|
@@ -355,6 +377,7 @@ class ScrapflyClient {
|
|
|
355
377
|
params.include_webhook = 'true';
|
|
356
378
|
return params;
|
|
357
379
|
}
|
|
380
|
+
/** Build the query string for a per-target Monitoring API endpoint. */
|
|
358
381
|
buildTargetParams(options) {
|
|
359
382
|
if ((options.start && !options.end) || (!options.start && options.end)) {
|
|
360
383
|
throw new Error('You must provide both start and end date');
|
|
@@ -378,41 +401,47 @@ class ScrapflyClient {
|
|
|
378
401
|
params.include_webhook = 'true';
|
|
379
402
|
return params;
|
|
380
403
|
}
|
|
381
|
-
|
|
404
|
+
/** Fetch Web Scraping API monitoring metrics (aggregate). */
|
|
382
405
|
async getMonitoringMetrics(options = {}) {
|
|
383
406
|
return this.monitoringRequest('/scrape/monitoring/metrics', this.buildMetricsParams(options));
|
|
384
407
|
}
|
|
408
|
+
/** Fetch Web Scraping API monitoring metrics for a single target domain. */
|
|
385
409
|
async getMonitoringTargetMetrics(options) {
|
|
386
410
|
return this.monitoringRequest('/scrape/monitoring/metrics/target', this.buildTargetParams(options));
|
|
387
411
|
}
|
|
388
|
-
|
|
412
|
+
/** Fetch Screenshot API monitoring metrics (aggregate). */
|
|
389
413
|
async getScreenshotMonitoringMetrics(options = {}) {
|
|
390
414
|
return this.monitoringRequest('/screenshot/monitoring/metrics', this.buildMetricsParams(options));
|
|
391
415
|
}
|
|
416
|
+
/** Fetch Screenshot API monitoring metrics for a single target domain. */
|
|
392
417
|
async getScreenshotMonitoringTargetMetrics(options) {
|
|
393
418
|
return this.monitoringRequest('/screenshot/monitoring/metrics/target', this.buildTargetParams(options));
|
|
394
419
|
}
|
|
395
|
-
|
|
420
|
+
/** Fetch Extraction API monitoring metrics (aggregate). */
|
|
396
421
|
async getExtractionMonitoringMetrics(options = {}) {
|
|
397
422
|
return this.monitoringRequest('/extraction/monitoring/metrics', this.buildMetricsParams(options));
|
|
398
423
|
}
|
|
424
|
+
/** Fetch Extraction API monitoring metrics for a single target domain. */
|
|
399
425
|
async getExtractionMonitoringTargetMetrics(options) {
|
|
400
426
|
return this.monitoringRequest('/extraction/monitoring/metrics/target', this.buildTargetParams(options));
|
|
401
427
|
}
|
|
402
|
-
|
|
428
|
+
/** Fetch Crawler API monitoring metrics (aggregate). */
|
|
403
429
|
async getCrawlerMonitoringMetrics(options = {}) {
|
|
404
430
|
return this.monitoringRequest('/crawl/monitoring/metrics', this.buildMetricsParams(options));
|
|
405
431
|
}
|
|
432
|
+
/** Fetch Crawler API monitoring metrics for a single target domain. */
|
|
406
433
|
async getCrawlerMonitoringTargetMetrics(options) {
|
|
407
434
|
return this.monitoringRequest('/crawl/monitoring/metrics/target', this.buildTargetParams(options));
|
|
408
435
|
}
|
|
409
|
-
|
|
436
|
+
/** Fetch Cloud Browser monitoring metrics (session-based aggregate). */
|
|
410
437
|
async getBrowserMonitoringMetrics(options = {}) {
|
|
411
438
|
return this.monitoringRequest('/browser/monitoring/metrics', this.buildBrowserParams(options));
|
|
412
439
|
}
|
|
440
|
+
/** Fetch Cloud Browser monitoring timeseries (per-minute session usage). */
|
|
413
441
|
async getBrowserMonitoringTimeseries(options = {}) {
|
|
414
442
|
return this.monitoringRequest('/browser/monitoring/metrics/timeseries', this.buildBrowserParams(options));
|
|
415
443
|
}
|
|
444
|
+
/** Build the query string for the session-based Cloud Browser Monitoring endpoints. */
|
|
416
445
|
buildBrowserParams(options) {
|
|
417
446
|
if ((options.start && !options.end) || (!options.start && options.end)) {
|
|
418
447
|
throw new Error('You must provide both start and end date');
|
|
@@ -1253,6 +1282,8 @@ class ScrapflyClient {
|
|
|
1253
1282
|
jsonBody.method = options.method;
|
|
1254
1283
|
if (options.enable_mcp !== undefined)
|
|
1255
1284
|
jsonBody.enable_mcp = options.enable_mcp;
|
|
1285
|
+
if (options.solve_captcha !== undefined)
|
|
1286
|
+
jsonBody.solve_captcha = options.solve_captcha;
|
|
1256
1287
|
const url = new URL(this.cloudBrowserApiHost + '/unblock');
|
|
1257
1288
|
url.searchParams.set('key', this.key);
|
|
1258
1289
|
const response = await this.fetch({
|
|
@@ -1434,6 +1465,127 @@ class ScrapflyClient {
|
|
|
1434
1465
|
}
|
|
1435
1466
|
return await response.json();
|
|
1436
1467
|
}
|
|
1468
|
+
// -------------------------------------------------------------------------
|
|
1469
|
+
// Public schedule endpoints — /scrape/schedules, /screenshot/schedules,
|
|
1470
|
+
// /crawl/schedules, /schedules. The kind-specific config is supplied to the
|
|
1471
|
+
// matching `create*Schedule` method; the cross-kind list/get/update/delete/
|
|
1472
|
+
// pause/resume/execute methods work regardless of kind.
|
|
1473
|
+
// -------------------------------------------------------------------------
|
|
1474
|
+
/** Create a Web Scraping API schedule. `scrape_config` is the same shape
|
|
1475
|
+
* accepted by `/scrape` (e.g. `{ url, render_js, asp, ... }`). */
|
|
1476
|
+
async createScrapeSchedule(scrapeConfig, request) {
|
|
1477
|
+
return await this.scheduleRequest('POST', '/scrape/schedules', undefined, this.buildCreateBody('scrape_config', scrapeConfig, request));
|
|
1478
|
+
}
|
|
1479
|
+
/** Create a Screenshot API schedule. */
|
|
1480
|
+
async createScreenshotSchedule(screenshotConfig, request) {
|
|
1481
|
+
return await this.scheduleRequest('POST', '/screenshot/schedules', undefined, this.buildCreateBody('screenshot_config', screenshotConfig, request));
|
|
1482
|
+
}
|
|
1483
|
+
/** Create a Crawler API schedule. */
|
|
1484
|
+
async createCrawlerSchedule(crawlerConfig, request) {
|
|
1485
|
+
return await this.scheduleRequest('POST', '/crawl/schedules', undefined, this.buildCreateBody('crawler_config', crawlerConfig, request));
|
|
1486
|
+
}
|
|
1487
|
+
/** Return a schedule by id. Works across all kinds. */
|
|
1488
|
+
async getSchedule(id) {
|
|
1489
|
+
return await this.scheduleRequest('GET', `/schedules/${encodeURIComponent(id)}`);
|
|
1490
|
+
}
|
|
1491
|
+
/** List every schedule on the account, optionally filtered by kind/status. */
|
|
1492
|
+
async listSchedules(opts) {
|
|
1493
|
+
return await this.scheduleRequest('GET', '/schedules', opts);
|
|
1494
|
+
}
|
|
1495
|
+
async listScrapeSchedules(opts) {
|
|
1496
|
+
return await this.scheduleRequest('GET', '/scrape/schedules', opts);
|
|
1497
|
+
}
|
|
1498
|
+
async listScreenshotSchedules(opts) {
|
|
1499
|
+
return await this.scheduleRequest('GET', '/screenshot/schedules', opts);
|
|
1500
|
+
}
|
|
1501
|
+
async listCrawlerSchedules(opts) {
|
|
1502
|
+
return await this.scheduleRequest('GET', '/crawl/schedules', opts);
|
|
1503
|
+
}
|
|
1504
|
+
/** Patch an active schedule. Only fields set in `request` change. */
|
|
1505
|
+
async updateSchedule(id, request) {
|
|
1506
|
+
return await this.scheduleRequest('PATCH', `/schedules/${encodeURIComponent(id)}`, undefined, request);
|
|
1507
|
+
}
|
|
1508
|
+
/** Cancel a schedule. Cancellation is terminal (returns no body). */
|
|
1509
|
+
async cancelSchedule(id) {
|
|
1510
|
+
await this.scheduleRequest('DELETE', `/schedules/${encodeURIComponent(id)}`);
|
|
1511
|
+
}
|
|
1512
|
+
async pauseSchedule(id) {
|
|
1513
|
+
return await this.scheduleRequest('POST', `/schedules/${encodeURIComponent(id)}/pause`);
|
|
1514
|
+
}
|
|
1515
|
+
async resumeSchedule(id) {
|
|
1516
|
+
return await this.scheduleRequest('POST', `/schedules/${encodeURIComponent(id)}/resume`);
|
|
1517
|
+
}
|
|
1518
|
+
/** Fire a schedule immediately, regardless of next_scheduled_date. */
|
|
1519
|
+
async executeSchedule(id) {
|
|
1520
|
+
return await this.scheduleRequest('POST', `/schedules/${encodeURIComponent(id)}/execute`);
|
|
1521
|
+
}
|
|
1522
|
+
buildCreateBody(configKey, config, request) {
|
|
1523
|
+
const body = {
|
|
1524
|
+
[configKey]: config,
|
|
1525
|
+
webhook_name: request.webhook_name,
|
|
1526
|
+
allow_concurrency: request.allow_concurrency ?? false,
|
|
1527
|
+
retry_on_failure: request.retry_on_failure ?? false,
|
|
1528
|
+
};
|
|
1529
|
+
if (request.recurrence)
|
|
1530
|
+
body.recurrence = request.recurrence;
|
|
1531
|
+
if (request.scheduled_date)
|
|
1532
|
+
body.scheduled_date = request.scheduled_date;
|
|
1533
|
+
if (typeof request.max_retries === 'number')
|
|
1534
|
+
body.max_retries = request.max_retries;
|
|
1535
|
+
if (request.notes)
|
|
1536
|
+
body.notes = request.notes;
|
|
1537
|
+
return body;
|
|
1538
|
+
}
|
|
1539
|
+
async scheduleRequest(method, path, query, body) {
|
|
1540
|
+
const url = new URL(this.HOST + path);
|
|
1541
|
+
const params = new URLSearchParams();
|
|
1542
|
+
params.set('key', this.key);
|
|
1543
|
+
if (query) {
|
|
1544
|
+
for (const [k, v] of Object.entries(query)) {
|
|
1545
|
+
if (v !== undefined && v !== '')
|
|
1546
|
+
params.set(k, v);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
url.search = params.toString();
|
|
1550
|
+
const init = {
|
|
1551
|
+
url: url.toString(),
|
|
1552
|
+
method,
|
|
1553
|
+
headers: {
|
|
1554
|
+
'user-agent': this.ua,
|
|
1555
|
+
accept: 'application/json',
|
|
1556
|
+
},
|
|
1557
|
+
};
|
|
1558
|
+
if (body !== undefined) {
|
|
1559
|
+
init.body = JSON.stringify(body);
|
|
1560
|
+
init.headers['content-type'] = 'application/json';
|
|
1561
|
+
}
|
|
1562
|
+
const response = await this.fetch(init);
|
|
1563
|
+
if (response.status === 204)
|
|
1564
|
+
return undefined;
|
|
1565
|
+
if (!response.ok) {
|
|
1566
|
+
let envelope = {};
|
|
1567
|
+
try {
|
|
1568
|
+
envelope = await response.json();
|
|
1569
|
+
}
|
|
1570
|
+
catch {
|
|
1571
|
+
// body wasn't JSON; fall through with the empty envelope
|
|
1572
|
+
}
|
|
1573
|
+
const code = envelope.error ?? 'ERR::SCHEDULER::BACKEND_ERROR';
|
|
1574
|
+
let message = envelope.message ?? '';
|
|
1575
|
+
if (envelope.reason) {
|
|
1576
|
+
message = message ? `${message} (${envelope.reason})` : envelope.reason;
|
|
1577
|
+
}
|
|
1578
|
+
if (!message)
|
|
1579
|
+
message = `HTTP ${response.status}`;
|
|
1580
|
+
throw new schedule_js_1.ScheduleAPIError({
|
|
1581
|
+
code,
|
|
1582
|
+
message,
|
|
1583
|
+
httpStatusCode: response.status,
|
|
1584
|
+
details: envelope.details,
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
return await response.json();
|
|
1588
|
+
}
|
|
1437
1589
|
}
|
|
1438
1590
|
exports.ScrapflyClient = ScrapflyClient;
|
|
1439
1591
|
// ---------------------------------------------------------------------------
|
package/script/crawl.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ export declare class Crawl {
|
|
|
38
38
|
private _uuid?;
|
|
39
39
|
private _status?;
|
|
40
40
|
private readonly _artifactCache;
|
|
41
|
+
/**
|
|
42
|
+
* @param client Configured {@link ScrapflyClient} that performs the HTTP calls.
|
|
43
|
+
* @param config Crawler configuration to submit on {@link Crawl.start}.
|
|
44
|
+
*/
|
|
41
45
|
constructor(client: ScrapflyClient, config: CrawlerConfig);
|
|
42
46
|
/** The crawler UUID returned by the API after `start()`, or undefined before. */
|
|
43
47
|
get uuid(): string | undefined;
|
package/script/crawl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crawl.d.ts","sourceRoot":"","sources":["../src/crawl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EACV,eAAe,EAGf,aAAa,EACb,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,KAAK;
|
|
1
|
+
{"version":3,"file":"crawl.d.ts","sourceRoot":"","sources":["../src/crawl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EACV,eAAe,EAGf,aAAa,EACb,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,KAAK;IASJ,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAkB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAR5E,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAgB;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAwD;IAEvF;;;OAGG;gBAC0B,MAAM,EAAE,cAAc,EAAmB,MAAM,EAAE,aAAa;IAE3F,iFAAiF;IACjF,IAAI,IAAI,IAAI,MAAM,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./logger.js");
|
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
60
|
class Crawl {
|
|
61
|
+
/**
|
|
62
|
+
* @param client Configured {@link ScrapflyClient} that performs the HTTP calls.
|
|
63
|
+
* @param config Crawler configuration to submit on {@link Crawl.start}.
|
|
64
|
+
*/
|
|
61
65
|
constructor(client, config) {
|
|
62
66
|
Object.defineProperty(this, "client", {
|
|
63
67
|
enumerable: true,
|
|
@@ -19,12 +19,19 @@ export type CrawlerStopReason = 'no_more_urls' | 'page_limit' | 'max_duration' |
|
|
|
19
19
|
* `duration` is always a number (0 when nothing has happened yet).
|
|
20
20
|
*/
|
|
21
21
|
export interface CrawlerState {
|
|
22
|
+
/** Number of URLs the crawler has fetched. */
|
|
22
23
|
urls_visited: number;
|
|
24
|
+
/** Number of URLs from which content or links were extracted. */
|
|
23
25
|
urls_extracted: number;
|
|
26
|
+
/** Number of URLs that failed to fetch. */
|
|
24
27
|
urls_failed: number;
|
|
28
|
+
/** Number of URLs skipped (filtered out, duplicate, limit hit, ...). */
|
|
25
29
|
urls_skipped: number;
|
|
30
|
+
/** Number of URLs queued for future fetch. */
|
|
26
31
|
urls_to_crawl: number;
|
|
32
|
+
/** API credits consumed so far. */
|
|
27
33
|
api_credit_used: number;
|
|
34
|
+
/** Elapsed time in seconds since the crawl started (0 while PENDING). */
|
|
28
35
|
duration: number;
|
|
29
36
|
/** `null` until the crawler stops. */
|
|
30
37
|
stop_reason: CrawlerStopReason | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crawlerresult.d.ts","sourceRoot":"","sources":["../src/crawlerresult.ts"],"names":[],"mappings":"AAoDA;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,cAAc,GACd,YAAY,GACZ,cAAc,GACd,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB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@ -1,57 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for every error thrown by the Scrapfly SDK.
|
|
3
|
+
*
|
|
4
|
+
* Concrete subclasses distinguish config-level, HTTP-level, and
|
|
5
|
+
* API-specific failures so callers can catch the exact category they
|
|
6
|
+
* care about without string-matching on error messages.
|
|
7
|
+
*/
|
|
1
8
|
export declare class ScrapflyError extends Error {
|
|
9
|
+
/** Extra context carried alongside the error message (response body, request params, etc.). */
|
|
2
10
|
args: Record<string, any>;
|
|
11
|
+
/**
|
|
12
|
+
* @param message Human-readable description of the failure.
|
|
13
|
+
* @param args Optional structured context to attach to the error.
|
|
14
|
+
*/
|
|
3
15
|
constructor(message: string, args?: Record<string, any>);
|
|
4
16
|
}
|
|
17
|
+
/** Raised when a ScrapeConfig is constructed with invalid parameters. */
|
|
5
18
|
export declare class ScrapeConfigError extends ScrapflyError {
|
|
6
19
|
}
|
|
20
|
+
/** Raised when a ScreenshotConfig is constructed with invalid parameters. */
|
|
7
21
|
export declare class ScreenshotConfigError extends ScrapflyError {
|
|
8
22
|
}
|
|
23
|
+
/** Raised when an ExtractionConfig is constructed with invalid parameters. */
|
|
9
24
|
export declare class ExtractionConfigError extends ScrapflyError {
|
|
10
25
|
}
|
|
26
|
+
/** Raised when a CrawlerConfig is constructed with invalid parameters. */
|
|
11
27
|
export declare class CrawlerConfigError extends ScrapflyError {
|
|
12
28
|
}
|
|
29
|
+
/** Raised when scrape parameters cannot be encoded into a request. */
|
|
13
30
|
export declare class EncodeError extends ScrapflyError {
|
|
14
31
|
}
|
|
32
|
+
/** Raised when a response carries an unexpected or unsupported Content-Type. */
|
|
15
33
|
export declare class ContentTypeError extends ScrapflyError {
|
|
16
34
|
}
|
|
35
|
+
/** Base error for every HTTP-level failure surfaced by the SDK. */
|
|
17
36
|
export declare class HttpError extends ScrapflyError {
|
|
18
37
|
}
|
|
38
|
+
/** Raised when the upstream target returned an error to Scrapfly. */
|
|
19
39
|
export declare class UpstreamHttpError extends HttpError {
|
|
20
40
|
}
|
|
41
|
+
/** Raised when the upstream target returned a 4xx client error. */
|
|
21
42
|
export declare class UpstreamHttpClientError extends UpstreamHttpError {
|
|
22
43
|
}
|
|
44
|
+
/** Raised when the upstream target returned a 5xx server error. */
|
|
23
45
|
export declare class UpstreamHttpServerError extends UpstreamHttpClientError {
|
|
24
46
|
}
|
|
47
|
+
/** Raised when the Scrapfly API itself returned a 4xx client error. */
|
|
25
48
|
export declare class ApiHttpClientError extends HttpError {
|
|
26
49
|
}
|
|
50
|
+
/** Raised when the API key provided to the client is missing, invalid, or revoked. */
|
|
27
51
|
export declare class BadApiKeyError extends ApiHttpClientError {
|
|
28
52
|
}
|
|
53
|
+
/** Raised when the request is rate-limited (HTTP 429). */
|
|
29
54
|
export declare class TooManyRequests extends HttpError {
|
|
30
55
|
}
|
|
56
|
+
/** Raised when the Scrapfly API returned a 5xx server error. */
|
|
31
57
|
export declare class ApiHttpServerError extends HttpError {
|
|
32
58
|
}
|
|
59
|
+
/** Raised when a scrape call fails for a reason not captured by a more specific subclass. */
|
|
33
60
|
export declare class ScrapflyScrapeError extends HttpError {
|
|
34
61
|
}
|
|
62
|
+
/** Raised when proxy settings do not match an available proxy (invalid pool, unsupported country, ...). */
|
|
35
63
|
export declare class ScrapflyProxyError extends HttpError {
|
|
36
64
|
}
|
|
65
|
+
/** Raised when the request is throttled by Scrapfly (e.g. burst limits). */
|
|
37
66
|
export declare class ScrapflyThrottleError extends HttpError {
|
|
38
67
|
}
|
|
68
|
+
/** Raised when Scrapfly failed to bypass anti-scraping protection on the target. */
|
|
39
69
|
export declare class ScrapflyAspError extends HttpError {
|
|
40
70
|
}
|
|
71
|
+
/** Raised when a scheduled scrape cannot be created or fulfilled. */
|
|
41
72
|
export declare class ScrapflyScheduleError extends HttpError {
|
|
42
73
|
}
|
|
74
|
+
/** Raised when a webhook is invalid or cannot be delivered (e.g. full queue). */
|
|
43
75
|
export declare class ScrapflyWebhookError extends HttpError {
|
|
44
76
|
}
|
|
77
|
+
/** Raised when a session is accessed concurrently in a way that violates session semantics. */
|
|
45
78
|
export declare class ScrapflySessionError extends HttpError {
|
|
46
79
|
}
|
|
80
|
+
/** Raised when concurrent requests exceed the account's concurrency limit. */
|
|
47
81
|
export declare class TooManyConcurrentRequests extends HttpError {
|
|
48
82
|
}
|
|
83
|
+
/** Raised when the account is out of scrape credits. */
|
|
49
84
|
export declare class QuotaLimitReached extends HttpError {
|
|
50
85
|
}
|
|
86
|
+
/** Raised for screenshot-API-specific failures. */
|
|
51
87
|
export declare class ScreenshotApiError extends ApiHttpClientError {
|
|
52
88
|
}
|
|
89
|
+
/** Raised for extraction-API-specific failures. */
|
|
53
90
|
export declare class ExtractionApiError extends ApiHttpClientError {
|
|
54
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Raised for crawler-API-specific failures.
|
|
94
|
+
*
|
|
95
|
+
* Covers crawler job lifecycle errors such as ALREADY_STARTED,
|
|
96
|
+
* NOT_STARTED, FAILED, CANCELLED, TIMEOUT, etc.
|
|
97
|
+
*/
|
|
55
98
|
export declare class ScrapflyCrawlerError extends HttpError {
|
|
56
99
|
}
|
|
57
100
|
//# sourceMappingURL=errors.d.ts.map
|
package/script/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,+FAA+F;IAC/F,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE1B;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,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BAA0B,SAAQ,SAAS;CAAG;AAC3D,wDAAwD;AACxD,qBAAa,iBAAkB,SAAQ,SAAS;CAAG;AACnD,mDAAmD;AACnD,qBAAa,kBAAmB,SAAQ,kBAAkB;CAAG;AAC7D,mDAAmD;AACnD,qBAAa,kBAAmB,SAAQ,kBAAkB;CAAG;AAC7D;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;CAAG"}
|
package/script/errors.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScrapflyCrawlerError = exports.ExtractionApiError = exports.ScreenshotApiError = exports.QuotaLimitReached = exports.TooManyConcurrentRequests = exports.ScrapflySessionError = exports.ScrapflyWebhookError = exports.ScrapflyScheduleError = exports.ScrapflyAspError = exports.ScrapflyThrottleError = exports.ScrapflyProxyError = exports.ScrapflyScrapeError = exports.ApiHttpServerError = exports.TooManyRequests = exports.BadApiKeyError = exports.ApiHttpClientError = exports.UpstreamHttpServerError = exports.UpstreamHttpClientError = exports.UpstreamHttpError = exports.HttpError = exports.ContentTypeError = exports.EncodeError = exports.CrawlerConfigError = exports.ExtractionConfigError = exports.ScreenshotConfigError = exports.ScrapeConfigError = exports.ScrapflyError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base class for every error thrown by the Scrapfly SDK.
|
|
6
|
+
*
|
|
7
|
+
* Concrete subclasses distinguish config-level, HTTP-level, and
|
|
8
|
+
* API-specific failures so callers can catch the exact category they
|
|
9
|
+
* care about without string-matching on error messages.
|
|
10
|
+
*/
|
|
4
11
|
class ScrapflyError extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* @param message Human-readable description of the failure.
|
|
14
|
+
* @param args Optional structured context to attach to the error.
|
|
15
|
+
*/
|
|
5
16
|
constructor(message, args = {}) {
|
|
6
17
|
super(message);
|
|
18
|
+
/** Extra context carried alongside the error message (response body, request params, etc.). */
|
|
7
19
|
Object.defineProperty(this, "args", {
|
|
8
20
|
enumerable: true,
|
|
9
21
|
configurable: true,
|
|
@@ -14,97 +26,112 @@ class ScrapflyError extends Error {
|
|
|
14
26
|
}
|
|
15
27
|
}
|
|
16
28
|
exports.ScrapflyError = ScrapflyError;
|
|
17
|
-
|
|
29
|
+
/** Raised when a ScrapeConfig is constructed with invalid parameters. */
|
|
18
30
|
class ScrapeConfigError extends ScrapflyError {
|
|
19
31
|
}
|
|
20
32
|
exports.ScrapeConfigError = ScrapeConfigError;
|
|
21
|
-
|
|
33
|
+
/** Raised when a ScreenshotConfig is constructed with invalid parameters. */
|
|
22
34
|
class ScreenshotConfigError extends ScrapflyError {
|
|
23
35
|
}
|
|
24
36
|
exports.ScreenshotConfigError = ScreenshotConfigError;
|
|
25
|
-
|
|
37
|
+
/** Raised when an ExtractionConfig is constructed with invalid parameters. */
|
|
26
38
|
class ExtractionConfigError extends ScrapflyError {
|
|
27
39
|
}
|
|
28
40
|
exports.ExtractionConfigError = ExtractionConfigError;
|
|
29
|
-
|
|
41
|
+
/** Raised when a CrawlerConfig is constructed with invalid parameters. */
|
|
30
42
|
class CrawlerConfigError extends ScrapflyError {
|
|
31
43
|
}
|
|
32
44
|
exports.CrawlerConfigError = CrawlerConfigError;
|
|
33
|
-
|
|
45
|
+
/** Raised when scrape parameters cannot be encoded into a request. */
|
|
34
46
|
class EncodeError extends ScrapflyError {
|
|
35
47
|
}
|
|
36
48
|
exports.EncodeError = EncodeError;
|
|
49
|
+
/** Raised when a response carries an unexpected or unsupported Content-Type. */
|
|
37
50
|
class ContentTypeError extends ScrapflyError {
|
|
38
51
|
}
|
|
39
52
|
exports.ContentTypeError = ContentTypeError;
|
|
40
|
-
|
|
53
|
+
/** Base error for every HTTP-level failure surfaced by the SDK. */
|
|
41
54
|
class HttpError extends ScrapflyError {
|
|
42
55
|
}
|
|
43
56
|
exports.HttpError = HttpError;
|
|
57
|
+
/** Raised when the upstream target returned an error to Scrapfly. */
|
|
44
58
|
class UpstreamHttpError extends HttpError {
|
|
45
59
|
}
|
|
46
60
|
exports.UpstreamHttpError = UpstreamHttpError;
|
|
61
|
+
/** Raised when the upstream target returned a 4xx client error. */
|
|
47
62
|
class UpstreamHttpClientError extends UpstreamHttpError {
|
|
48
63
|
}
|
|
49
64
|
exports.UpstreamHttpClientError = UpstreamHttpClientError;
|
|
65
|
+
/** Raised when the upstream target returned a 5xx server error. */
|
|
50
66
|
class UpstreamHttpServerError extends UpstreamHttpClientError {
|
|
51
67
|
}
|
|
52
68
|
exports.UpstreamHttpServerError = UpstreamHttpServerError;
|
|
69
|
+
/** Raised when the Scrapfly API itself returned a 4xx client error. */
|
|
53
70
|
class ApiHttpClientError extends HttpError {
|
|
54
71
|
}
|
|
55
72
|
exports.ApiHttpClientError = ApiHttpClientError;
|
|
56
|
-
|
|
73
|
+
/** Raised when the API key provided to the client is missing, invalid, or revoked. */
|
|
57
74
|
class BadApiKeyError extends ApiHttpClientError {
|
|
58
75
|
}
|
|
59
76
|
exports.BadApiKeyError = BadApiKeyError;
|
|
77
|
+
/** Raised when the request is rate-limited (HTTP 429). */
|
|
60
78
|
class TooManyRequests extends HttpError {
|
|
61
79
|
}
|
|
62
80
|
exports.TooManyRequests = TooManyRequests;
|
|
81
|
+
/** Raised when the Scrapfly API returned a 5xx server error. */
|
|
63
82
|
class ApiHttpServerError extends HttpError {
|
|
64
83
|
}
|
|
65
84
|
exports.ApiHttpServerError = ApiHttpServerError;
|
|
85
|
+
/** Raised when a scrape call fails for a reason not captured by a more specific subclass. */
|
|
66
86
|
class ScrapflyScrapeError extends HttpError {
|
|
67
87
|
}
|
|
68
88
|
exports.ScrapflyScrapeError = ScrapflyScrapeError;
|
|
69
|
-
|
|
89
|
+
/** Raised when proxy settings do not match an available proxy (invalid pool, unsupported country, ...). */
|
|
70
90
|
class ScrapflyProxyError extends HttpError {
|
|
71
91
|
}
|
|
72
92
|
exports.ScrapflyProxyError = ScrapflyProxyError;
|
|
93
|
+
/** Raised when the request is throttled by Scrapfly (e.g. burst limits). */
|
|
73
94
|
class ScrapflyThrottleError extends HttpError {
|
|
74
95
|
}
|
|
75
96
|
exports.ScrapflyThrottleError = ScrapflyThrottleError;
|
|
76
|
-
|
|
97
|
+
/** Raised when Scrapfly failed to bypass anti-scraping protection on the target. */
|
|
77
98
|
class ScrapflyAspError extends HttpError {
|
|
78
99
|
}
|
|
79
100
|
exports.ScrapflyAspError = ScrapflyAspError;
|
|
101
|
+
/** Raised when a scheduled scrape cannot be created or fulfilled. */
|
|
80
102
|
class ScrapflyScheduleError extends HttpError {
|
|
81
103
|
}
|
|
82
104
|
exports.ScrapflyScheduleError = ScrapflyScheduleError;
|
|
83
|
-
|
|
105
|
+
/** Raised when a webhook is invalid or cannot be delivered (e.g. full queue). */
|
|
84
106
|
class ScrapflyWebhookError extends HttpError {
|
|
85
107
|
}
|
|
86
108
|
exports.ScrapflyWebhookError = ScrapflyWebhookError;
|
|
87
|
-
|
|
109
|
+
/** Raised when a session is accessed concurrently in a way that violates session semantics. */
|
|
88
110
|
class ScrapflySessionError extends HttpError {
|
|
89
111
|
}
|
|
90
112
|
exports.ScrapflySessionError = ScrapflySessionError;
|
|
91
|
-
|
|
113
|
+
/** Raised when concurrent requests exceed the account's concurrency limit. */
|
|
92
114
|
class TooManyConcurrentRequests extends HttpError {
|
|
93
115
|
}
|
|
94
116
|
exports.TooManyConcurrentRequests = TooManyConcurrentRequests;
|
|
95
|
-
|
|
117
|
+
/** Raised when the account is out of scrape credits. */
|
|
96
118
|
class QuotaLimitReached extends HttpError {
|
|
97
119
|
}
|
|
98
120
|
exports.QuotaLimitReached = QuotaLimitReached;
|
|
99
|
-
|
|
121
|
+
/** Raised for screenshot-API-specific failures. */
|
|
100
122
|
class ScreenshotApiError extends ApiHttpClientError {
|
|
101
123
|
}
|
|
102
124
|
exports.ScreenshotApiError = ScreenshotApiError;
|
|
103
|
-
|
|
125
|
+
/** Raised for extraction-API-specific failures. */
|
|
104
126
|
class ExtractionApiError extends ApiHttpClientError {
|
|
105
127
|
}
|
|
106
128
|
exports.ExtractionApiError = ExtractionApiError;
|
|
107
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Raised for crawler-API-specific failures.
|
|
131
|
+
*
|
|
132
|
+
* Covers crawler job lifecycle errors such as ALREADY_STARTED,
|
|
133
|
+
* NOT_STARTED, FAILED, CANCELLED, TIMEOUT, etc.
|
|
134
|
+
*/
|
|
108
135
|
class ScrapflyCrawlerError extends HttpError {
|
|
109
136
|
}
|
|
110
137
|
exports.ScrapflyCrawlerError = ScrapflyCrawlerError;
|