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.
Files changed (100) hide show
  1. package/esm/batch.d.ts.map +1 -1
  2. package/esm/batch.js +6 -0
  3. package/esm/browserconfig.d.ts +80 -1
  4. package/esm/browserconfig.d.ts.map +1 -1
  5. package/esm/browserconfig.js +54 -1
  6. package/esm/client.d.ts +65 -0
  7. package/esm/client.d.ts.map +1 -1
  8. package/esm/client.js +157 -5
  9. package/esm/crawl.d.ts +4 -0
  10. package/esm/crawl.d.ts.map +1 -1
  11. package/esm/crawl.js +4 -0
  12. package/esm/crawlerresult.d.ts +7 -0
  13. package/esm/crawlerresult.d.ts.map +1 -1
  14. package/esm/errors.d.ts +43 -0
  15. package/esm/errors.d.ts.map +1 -1
  16. package/esm/errors.js +43 -16
  17. package/esm/extractionconfig.d.ts +54 -9
  18. package/esm/extractionconfig.d.ts.map +1 -1
  19. package/esm/extractionconfig.js +37 -13
  20. package/esm/logger.d.ts +1 -0
  21. package/esm/logger.d.ts.map +1 -1
  22. package/esm/logger.js +1 -0
  23. package/esm/main.d.ts +29 -0
  24. package/esm/main.d.ts.map +1 -1
  25. package/esm/main.js +28 -0
  26. package/esm/monitoringconfig.d.ts +48 -11
  27. package/esm/monitoringconfig.d.ts.map +1 -1
  28. package/esm/monitoringconfig.js +14 -0
  29. package/esm/result.d.ts +2 -0
  30. package/esm/result.d.ts.map +1 -1
  31. package/esm/schedule.d.ts +93 -0
  32. package/esm/schedule.d.ts.map +1 -0
  33. package/esm/schedule.js +40 -0
  34. package/esm/scrapeconfig.d.ts +10 -8
  35. package/esm/scrapeconfig.d.ts.map +1 -1
  36. package/esm/scrapeconfig.js +10 -8
  37. package/esm/screenshotconfig.d.ts +59 -26
  38. package/esm/screenshotconfig.d.ts.map +1 -1
  39. package/esm/screenshotconfig.js +38 -26
  40. package/esm/webhookserver.d.ts +28 -0
  41. package/esm/webhookserver.d.ts.map +1 -1
  42. package/esm/webhookserver.js +34 -3
  43. package/package.json +1 -1
  44. package/script/batch.d.ts.map +1 -1
  45. package/script/batch.js +6 -0
  46. package/script/browserconfig.d.ts +80 -1
  47. package/script/browserconfig.d.ts.map +1 -1
  48. package/script/browserconfig.js +54 -1
  49. package/script/client.d.ts +65 -0
  50. package/script/client.d.ts.map +1 -1
  51. package/script/client.js +157 -5
  52. package/script/crawl.d.ts +4 -0
  53. package/script/crawl.d.ts.map +1 -1
  54. package/script/crawl.js +4 -0
  55. package/script/crawlerresult.d.ts +7 -0
  56. package/script/crawlerresult.d.ts.map +1 -1
  57. package/script/errors.d.ts +43 -0
  58. package/script/errors.d.ts.map +1 -1
  59. package/script/errors.js +43 -16
  60. package/script/extractionconfig.d.ts +54 -9
  61. package/script/extractionconfig.d.ts.map +1 -1
  62. package/script/extractionconfig.js +37 -13
  63. package/script/logger.d.ts +1 -0
  64. package/script/logger.d.ts.map +1 -1
  65. package/script/logger.js +1 -0
  66. package/script/main.d.ts +29 -0
  67. package/script/main.d.ts.map +1 -1
  68. package/script/main.js +30 -1
  69. package/script/monitoringconfig.d.ts +48 -11
  70. package/script/monitoringconfig.d.ts.map +1 -1
  71. package/script/monitoringconfig.js +14 -0
  72. package/script/result.d.ts +2 -0
  73. package/script/result.d.ts.map +1 -1
  74. package/script/schedule.d.ts +93 -0
  75. package/script/schedule.d.ts.map +1 -0
  76. package/script/schedule.js +44 -0
  77. package/script/scrapeconfig.d.ts +10 -8
  78. package/script/scrapeconfig.d.ts.map +1 -1
  79. package/script/scrapeconfig.js +10 -8
  80. package/script/screenshotconfig.d.ts +59 -26
  81. package/script/screenshotconfig.d.ts.map +1 -1
  82. package/script/screenshotconfig.js +38 -26
  83. package/script/webhookserver.d.ts +28 -0
  84. package/script/webhookserver.d.ts.map +1 -1
  85. package/script/webhookserver.js +34 -3
  86. package/src/batch.ts +7 -1
  87. package/src/browserconfig.ts +82 -1
  88. package/src/client.ts +227 -7
  89. package/src/crawl.ts +4 -0
  90. package/src/crawlerresult.ts +7 -0
  91. package/src/errors.ts +43 -16
  92. package/src/extractionconfig.ts +58 -16
  93. package/src/logger.ts +2 -0
  94. package/src/main.ts +37 -0
  95. package/src/monitoringconfig.ts +49 -11
  96. package/src/result.ts +2 -0
  97. package/src/schedule.ts +101 -0
  98. package/src/scrapeconfig.ts +10 -8
  99. package/src/screenshotconfig.ts +59 -26
  100. package/src/webhookserver.ts +34 -3
package/esm/client.js CHANGED
@@ -7,20 +7,39 @@ import { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
7
7
  import { log } from './logger.js';
8
8
  import { CrawlerArtifact, CrawlerContents, CrawlerStatus, CrawlerUrls } from './crawlerresult.js';
9
9
  import { formatMonitoringDate, } from './monitoringconfig.js';
10
+ import { ScheduleAPIError, } from './schedule.js';
11
+ /**
12
+ * Main entry point for the Scrapfly SDK.
13
+ *
14
+ * A single `ScrapflyClient` can be used to call every Scrapfly API
15
+ * (scrape, screenshot, extraction, crawler, monitoring, cloud browser).
16
+ * It is safe to share one instance across concurrent calls.
17
+ */
10
18
  export class ScrapflyClient {
19
+ /**
20
+ * Create a Scrapfly client.
21
+ *
22
+ * @param options.key Scrapfly API key.
23
+ * @param options.host Optional override for the REST API host.
24
+ * @param options.cloudBrowserHost Optional override for the Cloud Browser WS host.
25
+ * @throws {@link errors.BadApiKeyError} if `options.key` is not a non-empty string.
26
+ */
11
27
  constructor(options) {
28
+ /** Base URL of the Scrapfly REST API. */
12
29
  Object.defineProperty(this, "HOST", {
13
30
  enumerable: true,
14
31
  configurable: true,
15
32
  writable: true,
16
33
  value: 'https://api.scrapfly.io'
17
34
  });
35
+ /** Default Cloud Browser WebSocket host. */
18
36
  Object.defineProperty(this, "CLOUD_BROWSER_HOST", {
19
37
  enumerable: true,
20
38
  configurable: true,
21
39
  writable: true,
22
40
  value: 'wss://browser.scrapfly.io'
23
41
  });
42
+ /** Default Cloud Browser REST host (derived from the WS host). */
24
43
  Object.defineProperty(this, "CLOUD_BROWSER_API_HOST", {
25
44
  enumerable: true,
26
45
  configurable: true,
@@ -51,6 +70,7 @@ export class ScrapflyClient {
51
70
  writable: true,
52
71
  value: void 0
53
72
  });
73
+ /** `fetch` implementation used by the client. Override for custom retries/tracing. */
54
74
  Object.defineProperty(this, "fetch", {
55
75
  enumerable: true,
56
76
  configurable: true,
@@ -294,6 +314,7 @@ export class ScrapflyClient {
294
314
  // one shape (request-based) but live under different URL prefixes;
295
315
  // Cloud Browser is session-based and exposes a distinct shape.
296
316
  // See https://scrapfly.io/docs/monitoring#api
317
+ /** Dispatch an HTTP GET against a Monitoring API path with the given query params, parsing errors. */
297
318
  async monitoringRequest(path, params) {
298
319
  const url = new URL(this.HOST + path);
299
320
  url.search = new URLSearchParams(params).toString();
@@ -315,6 +336,7 @@ export class ScrapflyClient {
315
336
  }
316
337
  return data;
317
338
  }
339
+ /** Build the query string for a request-based Monitoring API metrics endpoint. */
318
340
  buildMetricsParams(options) {
319
341
  const params = {
320
342
  key: this.key,
@@ -329,6 +351,7 @@ export class ScrapflyClient {
329
351
  params.include_webhook = 'true';
330
352
  return params;
331
353
  }
354
+ /** Build the query string for a per-target Monitoring API endpoint. */
332
355
  buildTargetParams(options) {
333
356
  if ((options.start && !options.end) || (!options.start && options.end)) {
334
357
  throw new Error('You must provide both start and end date');
@@ -352,41 +375,47 @@ export class ScrapflyClient {
352
375
  params.include_webhook = 'true';
353
376
  return params;
354
377
  }
355
- // ── Web Scraping API (existing — kept for backward compat) ──────
378
+ /** Fetch Web Scraping API monitoring metrics (aggregate). */
356
379
  async getMonitoringMetrics(options = {}) {
357
380
  return this.monitoringRequest('/scrape/monitoring/metrics', this.buildMetricsParams(options));
358
381
  }
382
+ /** Fetch Web Scraping API monitoring metrics for a single target domain. */
359
383
  async getMonitoringTargetMetrics(options) {
360
384
  return this.monitoringRequest('/scrape/monitoring/metrics/target', this.buildTargetParams(options));
361
385
  }
362
- // ── Screenshot API ───────────────────────────────────────────────
386
+ /** Fetch Screenshot API monitoring metrics (aggregate). */
363
387
  async getScreenshotMonitoringMetrics(options = {}) {
364
388
  return this.monitoringRequest('/screenshot/monitoring/metrics', this.buildMetricsParams(options));
365
389
  }
390
+ /** Fetch Screenshot API monitoring metrics for a single target domain. */
366
391
  async getScreenshotMonitoringTargetMetrics(options) {
367
392
  return this.monitoringRequest('/screenshot/monitoring/metrics/target', this.buildTargetParams(options));
368
393
  }
369
- // ── Extraction API ───────────────────────────────────────────────
394
+ /** Fetch Extraction API monitoring metrics (aggregate). */
370
395
  async getExtractionMonitoringMetrics(options = {}) {
371
396
  return this.monitoringRequest('/extraction/monitoring/metrics', this.buildMetricsParams(options));
372
397
  }
398
+ /** Fetch Extraction API monitoring metrics for a single target domain. */
373
399
  async getExtractionMonitoringTargetMetrics(options) {
374
400
  return this.monitoringRequest('/extraction/monitoring/metrics/target', this.buildTargetParams(options));
375
401
  }
376
- // ── Crawler API ──────────────────────────────────────────────────
402
+ /** Fetch Crawler API monitoring metrics (aggregate). */
377
403
  async getCrawlerMonitoringMetrics(options = {}) {
378
404
  return this.monitoringRequest('/crawl/monitoring/metrics', this.buildMetricsParams(options));
379
405
  }
406
+ /** Fetch Crawler API monitoring metrics for a single target domain. */
380
407
  async getCrawlerMonitoringTargetMetrics(options) {
381
408
  return this.monitoringRequest('/crawl/monitoring/metrics/target', this.buildTargetParams(options));
382
409
  }
383
- // ── Cloud Browser API (session-based, distinct shape) ────────────
410
+ /** Fetch Cloud Browser monitoring metrics (session-based aggregate). */
384
411
  async getBrowserMonitoringMetrics(options = {}) {
385
412
  return this.monitoringRequest('/browser/monitoring/metrics', this.buildBrowserParams(options));
386
413
  }
414
+ /** Fetch Cloud Browser monitoring timeseries (per-minute session usage). */
387
415
  async getBrowserMonitoringTimeseries(options = {}) {
388
416
  return this.monitoringRequest('/browser/monitoring/metrics/timeseries', this.buildBrowserParams(options));
389
417
  }
418
+ /** Build the query string for the session-based Cloud Browser Monitoring endpoints. */
390
419
  buildBrowserParams(options) {
391
420
  if ((options.start && !options.end) || (!options.start && options.end)) {
392
421
  throw new Error('You must provide both start and end date');
@@ -1227,6 +1256,8 @@ export class ScrapflyClient {
1227
1256
  jsonBody.method = options.method;
1228
1257
  if (options.enable_mcp !== undefined)
1229
1258
  jsonBody.enable_mcp = options.enable_mcp;
1259
+ if (options.solve_captcha !== undefined)
1260
+ jsonBody.solve_captcha = options.solve_captcha;
1230
1261
  const url = new URL(this.cloudBrowserApiHost + '/unblock');
1231
1262
  url.searchParams.set('key', this.key);
1232
1263
  const response = await this.fetch({
@@ -1408,6 +1439,127 @@ export class ScrapflyClient {
1408
1439
  }
1409
1440
  return await response.json();
1410
1441
  }
1442
+ // -------------------------------------------------------------------------
1443
+ // Public schedule endpoints — /scrape/schedules, /screenshot/schedules,
1444
+ // /crawl/schedules, /schedules. The kind-specific config is supplied to the
1445
+ // matching `create*Schedule` method; the cross-kind list/get/update/delete/
1446
+ // pause/resume/execute methods work regardless of kind.
1447
+ // -------------------------------------------------------------------------
1448
+ /** Create a Web Scraping API schedule. `scrape_config` is the same shape
1449
+ * accepted by `/scrape` (e.g. `{ url, render_js, asp, ... }`). */
1450
+ async createScrapeSchedule(scrapeConfig, request) {
1451
+ return await this.scheduleRequest('POST', '/scrape/schedules', undefined, this.buildCreateBody('scrape_config', scrapeConfig, request));
1452
+ }
1453
+ /** Create a Screenshot API schedule. */
1454
+ async createScreenshotSchedule(screenshotConfig, request) {
1455
+ return await this.scheduleRequest('POST', '/screenshot/schedules', undefined, this.buildCreateBody('screenshot_config', screenshotConfig, request));
1456
+ }
1457
+ /** Create a Crawler API schedule. */
1458
+ async createCrawlerSchedule(crawlerConfig, request) {
1459
+ return await this.scheduleRequest('POST', '/crawl/schedules', undefined, this.buildCreateBody('crawler_config', crawlerConfig, request));
1460
+ }
1461
+ /** Return a schedule by id. Works across all kinds. */
1462
+ async getSchedule(id) {
1463
+ return await this.scheduleRequest('GET', `/schedules/${encodeURIComponent(id)}`);
1464
+ }
1465
+ /** List every schedule on the account, optionally filtered by kind/status. */
1466
+ async listSchedules(opts) {
1467
+ return await this.scheduleRequest('GET', '/schedules', opts);
1468
+ }
1469
+ async listScrapeSchedules(opts) {
1470
+ return await this.scheduleRequest('GET', '/scrape/schedules', opts);
1471
+ }
1472
+ async listScreenshotSchedules(opts) {
1473
+ return await this.scheduleRequest('GET', '/screenshot/schedules', opts);
1474
+ }
1475
+ async listCrawlerSchedules(opts) {
1476
+ return await this.scheduleRequest('GET', '/crawl/schedules', opts);
1477
+ }
1478
+ /** Patch an active schedule. Only fields set in `request` change. */
1479
+ async updateSchedule(id, request) {
1480
+ return await this.scheduleRequest('PATCH', `/schedules/${encodeURIComponent(id)}`, undefined, request);
1481
+ }
1482
+ /** Cancel a schedule. Cancellation is terminal (returns no body). */
1483
+ async cancelSchedule(id) {
1484
+ await this.scheduleRequest('DELETE', `/schedules/${encodeURIComponent(id)}`);
1485
+ }
1486
+ async pauseSchedule(id) {
1487
+ return await this.scheduleRequest('POST', `/schedules/${encodeURIComponent(id)}/pause`);
1488
+ }
1489
+ async resumeSchedule(id) {
1490
+ return await this.scheduleRequest('POST', `/schedules/${encodeURIComponent(id)}/resume`);
1491
+ }
1492
+ /** Fire a schedule immediately, regardless of next_scheduled_date. */
1493
+ async executeSchedule(id) {
1494
+ return await this.scheduleRequest('POST', `/schedules/${encodeURIComponent(id)}/execute`);
1495
+ }
1496
+ buildCreateBody(configKey, config, request) {
1497
+ const body = {
1498
+ [configKey]: config,
1499
+ webhook_name: request.webhook_name,
1500
+ allow_concurrency: request.allow_concurrency ?? false,
1501
+ retry_on_failure: request.retry_on_failure ?? false,
1502
+ };
1503
+ if (request.recurrence)
1504
+ body.recurrence = request.recurrence;
1505
+ if (request.scheduled_date)
1506
+ body.scheduled_date = request.scheduled_date;
1507
+ if (typeof request.max_retries === 'number')
1508
+ body.max_retries = request.max_retries;
1509
+ if (request.notes)
1510
+ body.notes = request.notes;
1511
+ return body;
1512
+ }
1513
+ async scheduleRequest(method, path, query, body) {
1514
+ const url = new URL(this.HOST + path);
1515
+ const params = new URLSearchParams();
1516
+ params.set('key', this.key);
1517
+ if (query) {
1518
+ for (const [k, v] of Object.entries(query)) {
1519
+ if (v !== undefined && v !== '')
1520
+ params.set(k, v);
1521
+ }
1522
+ }
1523
+ url.search = params.toString();
1524
+ const init = {
1525
+ url: url.toString(),
1526
+ method,
1527
+ headers: {
1528
+ 'user-agent': this.ua,
1529
+ accept: 'application/json',
1530
+ },
1531
+ };
1532
+ if (body !== undefined) {
1533
+ init.body = JSON.stringify(body);
1534
+ init.headers['content-type'] = 'application/json';
1535
+ }
1536
+ const response = await this.fetch(init);
1537
+ if (response.status === 204)
1538
+ return undefined;
1539
+ if (!response.ok) {
1540
+ let envelope = {};
1541
+ try {
1542
+ envelope = await response.json();
1543
+ }
1544
+ catch {
1545
+ // body wasn't JSON; fall through with the empty envelope
1546
+ }
1547
+ const code = envelope.error ?? 'ERR::SCHEDULER::BACKEND_ERROR';
1548
+ let message = envelope.message ?? '';
1549
+ if (envelope.reason) {
1550
+ message = message ? `${message} (${envelope.reason})` : envelope.reason;
1551
+ }
1552
+ if (!message)
1553
+ message = `HTTP ${response.status}`;
1554
+ throw new ScheduleAPIError({
1555
+ code,
1556
+ message,
1557
+ httpStatusCode: response.status,
1558
+ details: envelope.details,
1559
+ });
1560
+ }
1561
+ return await response.json();
1562
+ }
1411
1563
  }
1412
1564
  // ---------------------------------------------------------------------------
1413
1565
  // multipart/related parser
package/esm/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;
@@ -1 +1 @@
1
- {"version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
  */
34
34
  export class Crawl {
35
+ /**
36
+ * @param client Configured {@link ScrapflyClient} that performs the HTTP calls.
37
+ * @param config Crawler configuration to submit on {@link Crawl.start}.
38
+ */
35
39
  constructor(client, config) {
36
40
  Object.defineProperty(this, "client", {
37
41
  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,GAChB,eAAe,GACf,oBAAoB,GACpB,eAAe,CAAC;AAEpB;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC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jC,CAAC;KACH,CAAC;CACH;AAED,gDAAgD;AAChD,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,qBAAqB,CAAC;IAC7B,OAAO,EAAE,oBAAoB,GAAG;QAC9B,yDAAyD;QACzD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC9B,CAAC;CACH;AAED,mDAAmD;AACnD,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,wBAAwB,CAAC;IAChC,OAAO,EAAE,oBAAoB,GAAG;QAC9B,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,EAAE,MAAM,EAAE,CAAC;KAC3B,CAAC;CACH;AAED,+CAA+C;AAC/C,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,OAAO,EAAE,oBAAoB,GAAG;QAC9B,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnC,KAAK,EAAE;YAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAC;KAC/B,CAAC;CACH;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAC7B,uBAAuB,GACvB,wBAAwB,GACxB,wBAAwB,GACxB,2BAA2B,GAC3B,uBAAuB,CAAC;AAS5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,qBAAqB,CAyBxE"}
package/esm/errors.d.ts CHANGED
@@ -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
@@ -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,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B,SAAQ,SAAS;CAAG;AAClD,qEAAqE;AACrE,qBAAa,qBAAsB,SAAQ,SAAS;CAAG;AACvD,iFAAiF;AACjF,qBAAa,oBAAqB,SAAQ,SAAS;CAAG;AACtD,+FAA+F;AAC/F,qBAAa,oBAAqB,SAAQ,SAAS;CAAG;AACtD,8EAA8E;AAC9E,qBAAa,yBAA0B,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/esm/errors.js CHANGED
@@ -1,6 +1,18 @@
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 class ScrapflyError extends Error {
9
+ /**
10
+ * @param message Human-readable description of the failure.
11
+ * @param args Optional structured context to attach to the error.
12
+ */
2
13
  constructor(message, args = {}) {
3
14
  super(message);
15
+ /** Extra context carried alongside the error message (response body, request params, etc.). */
4
16
  Object.defineProperty(this, "args", {
5
17
  enumerable: true,
6
18
  configurable: true,
@@ -10,71 +22,86 @@ export class ScrapflyError extends Error {
10
22
  this.args = args;
11
23
  }
12
24
  }
13
- // raised when scrape config is invalid
25
+ /** Raised when a ScrapeConfig is constructed with invalid parameters. */
14
26
  export class ScrapeConfigError extends ScrapflyError {
15
27
  }
16
- // raised when screenshot config is invalid
28
+ /** Raised when a ScreenshotConfig is constructed with invalid parameters. */
17
29
  export class ScreenshotConfigError extends ScrapflyError {
18
30
  }
19
- // raised when extraction config is invalid
31
+ /** Raised when an ExtractionConfig is constructed with invalid parameters. */
20
32
  export class ExtractionConfigError extends ScrapflyError {
21
33
  }
22
- // raised when crawler config is invalid
34
+ /** Raised when a CrawlerConfig is constructed with invalid parameters. */
23
35
  export class CrawlerConfigError extends ScrapflyError {
24
36
  }
25
- // raised when scrape parameters cannot be encoded
37
+ /** Raised when scrape parameters cannot be encoded into a request. */
26
38
  export class EncodeError extends ScrapflyError {
27
39
  }
40
+ /** Raised when a response carries an unexpected or unsupported Content-Type. */
28
41
  export class ContentTypeError extends ScrapflyError {
29
42
  }
30
- // Base error for all http related operations
43
+ /** Base error for every HTTP-level failure surfaced by the SDK. */
31
44
  export class HttpError extends ScrapflyError {
32
45
  }
46
+ /** Raised when the upstream target returned an error to Scrapfly. */
33
47
  export class UpstreamHttpError extends HttpError {
34
48
  }
49
+ /** Raised when the upstream target returned a 4xx client error. */
35
50
  export class UpstreamHttpClientError extends UpstreamHttpError {
36
51
  }
52
+ /** Raised when the upstream target returned a 5xx server error. */
37
53
  export class UpstreamHttpServerError extends UpstreamHttpClientError {
38
54
  }
55
+ /** Raised when the Scrapfly API itself returned a 4xx client error. */
39
56
  export class ApiHttpClientError extends HttpError {
40
57
  }
41
- // raised when API key provided to client is not valid or not existant
58
+ /** Raised when the API key provided to the client is missing, invalid, or revoked. */
42
59
  export class BadApiKeyError extends ApiHttpClientError {
43
60
  }
61
+ /** Raised when the request is rate-limited (HTTP 429). */
44
62
  export class TooManyRequests extends HttpError {
45
63
  }
64
+ /** Raised when the Scrapfly API returned a 5xx server error. */
46
65
  export class ApiHttpServerError extends HttpError {
47
66
  }
67
+ /** Raised when a scrape call fails for a reason not captured by a more specific subclass. */
48
68
  export class ScrapflyScrapeError extends HttpError {
49
69
  }
50
- // raised when proxy settings don't match available proxies (e.g. invalid proxy pool, country setting)
70
+ /** Raised when proxy settings do not match an available proxy (invalid pool, unsupported country, ...). */
51
71
  export class ScrapflyProxyError extends HttpError {
52
72
  }
73
+ /** Raised when the request is throttled by Scrapfly (e.g. burst limits). */
53
74
  export class ScrapflyThrottleError extends HttpError {
54
75
  }
55
- // raised when ScrapFly fails to bypass anti-scraping protection
76
+ /** Raised when Scrapfly failed to bypass anti-scraping protection on the target. */
56
77
  export class ScrapflyAspError extends HttpError {
57
78
  }
79
+ /** Raised when a scheduled scrape cannot be created or fulfilled. */
58
80
  export class ScrapflyScheduleError extends HttpError {
59
81
  }
60
- // raised when Webhook is invalid or cannot be fulfilled (i.e. full queue)
82
+ /** Raised when a webhook is invalid or cannot be delivered (e.g. full queue). */
61
83
  export class ScrapflyWebhookError extends HttpError {
62
84
  }
63
- // raised when session is access concurrently
85
+ /** Raised when a session is accessed concurrently in a way that violates session semantics. */
64
86
  export class ScrapflySessionError extends HttpError {
65
87
  }
66
- // raised when concurrent requests exceed account limits
88
+ /** Raised when concurrent requests exceed the account's concurrency limit. */
67
89
  export class TooManyConcurrentRequests extends HttpError {
68
90
  }
69
- // raised when account is out of scrape credits
91
+ /** Raised when the account is out of scrape credits. */
70
92
  export class QuotaLimitReached extends HttpError {
71
93
  }
72
- // raised with Scrapfly screenshot API related errors
94
+ /** Raised for screenshot-API-specific failures. */
73
95
  export class ScreenshotApiError extends ApiHttpClientError {
74
96
  }
75
- // raised with Scrapfly extraction API related errors
97
+ /** Raised for extraction-API-specific failures. */
76
98
  export class ExtractionApiError extends ApiHttpClientError {
77
99
  }
78
- // raised with Scrapfly crawler API related errors (job lifecycle: ALREADY_STARTED, NOT_STARTED, FAILED, CANCELLED, TIMEOUT, etc.)
100
+ /**
101
+ * Raised for crawler-API-specific failures.
102
+ *
103
+ * Covers crawler job lifecycle errors such as ALREADY_STARTED,
104
+ * NOT_STARTED, FAILED, CANCELLED, TIMEOUT, etc.
105
+ */
79
106
  export class ScrapflyCrawlerError extends HttpError {
80
107
  }