scrapfly-sdk 0.10.6 → 0.11.1

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 (47) hide show
  1. package/esm/browserconfig.d.ts +54 -0
  2. package/esm/browserconfig.d.ts.map +1 -1
  3. package/esm/browserconfig.js +106 -0
  4. package/esm/client.d.ts +110 -7
  5. package/esm/client.d.ts.map +1 -1
  6. package/esm/client.js +339 -26
  7. package/esm/crawlerconfig.d.ts +6 -2
  8. package/esm/crawlerconfig.d.ts.map +1 -1
  9. package/esm/crawlerconfig.js +33 -4
  10. package/esm/extractionconfig.js +1 -1
  11. package/esm/main.d.ts +1 -0
  12. package/esm/main.d.ts.map +1 -1
  13. package/esm/scrapeconfig.d.ts +1 -0
  14. package/esm/scrapeconfig.d.ts.map +1 -1
  15. package/esm/scrapeconfig.js +9 -5
  16. package/esm/types.d.ts +94 -0
  17. package/esm/types.d.ts.map +1 -1
  18. package/esm/utils.d.ts +1 -1
  19. package/esm/utils.d.ts.map +1 -1
  20. package/package.json +1 -1
  21. package/script/browserconfig.d.ts +54 -0
  22. package/script/browserconfig.d.ts.map +1 -1
  23. package/script/browserconfig.js +106 -0
  24. package/script/client.d.ts +110 -7
  25. package/script/client.d.ts.map +1 -1
  26. package/script/client.js +339 -26
  27. package/script/crawlerconfig.d.ts +6 -2
  28. package/script/crawlerconfig.d.ts.map +1 -1
  29. package/script/crawlerconfig.js +33 -4
  30. package/script/extractionconfig.js +1 -1
  31. package/script/main.d.ts +1 -0
  32. package/script/main.d.ts.map +1 -1
  33. package/script/scrapeconfig.d.ts +1 -0
  34. package/script/scrapeconfig.d.ts.map +1 -1
  35. package/script/scrapeconfig.js +9 -5
  36. package/script/types.d.ts +94 -0
  37. package/script/types.d.ts.map +1 -1
  38. package/script/utils.d.ts +1 -1
  39. package/script/utils.d.ts.map +1 -1
  40. package/src/browserconfig.ts +87 -0
  41. package/src/client.ts +409 -28
  42. package/src/crawlerconfig.ts +27 -6
  43. package/src/extractionconfig.ts +1 -1
  44. package/src/main.ts +1 -0
  45. package/src/scrapeconfig.ts +4 -5
  46. package/src/types.ts +115 -0
  47. package/src/utils.ts +6 -1
package/src/client.ts CHANGED
@@ -8,7 +8,7 @@ import type { ExtractionConfig } from './extractionconfig.js';
8
8
  import { BrowserConfig } from './browserconfig.js';
9
9
  import { type AccountData, type ClassifyOptions, type ClassifyResult, ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
10
10
  import { log } from './logger.js';
11
- import type { Rec } from './types.js';
11
+ import type { Rec, Vault, VaultItem, VaultItemCreate, VaultSecret } from './types.js';
12
12
  import type { CrawlerConfig, CrawlerContentFormat } from './crawlerconfig.js';
13
13
  import { CrawlerArtifact, type CrawlerArtifactType, CrawlerContents, CrawlerStatus, CrawlerUrls } from './crawlerresult.js';
14
14
  import {
@@ -935,17 +935,52 @@ export class ScrapflyClient {
935
935
  try {
936
936
  const url = new URL(this.HOST + '/crawl');
937
937
  url.search = new URLSearchParams({ key: this.key }).toString();
938
- response = await this.fetch({
939
- url: url.toString(),
940
- method: 'POST',
941
- headers: {
942
- 'user-agent': this.ua,
943
- 'content-type': 'application/json',
944
- 'accept-encoding': 'gzip, deflate, br',
945
- accept: 'application/json',
946
- },
947
- body: JSON.stringify(config.toApiParams()),
948
- });
938
+ // POST /crawl accepts two body formats:
939
+ // - application/json: the entire crawler configuration as JSON.
940
+ // Used for seed-URL crawls and remote_url_list crawls.
941
+ // - multipart/form-data: a 'config' JSON part and a 'urls' text
942
+ // part (one URL per line). Used only when the caller provides
943
+ // an in-memory url_list, so the URLs can be uploaded as a
944
+ // streamed file payload instead of inlined into the JSON body.
945
+ const params = config.toApiParams() as Rec<any>;
946
+ const urlList: string[] | undefined = Array.isArray(params.url_list) && params.url_list.length > 0
947
+ ? (params.url_list as string[])
948
+ : undefined;
949
+ if (urlList !== undefined) {
950
+ // Strip url_list from the JSON config — the URLs go through the
951
+ // 'urls' multipart part instead, which the API gateway streams
952
+ // straight through to the scrape engine.
953
+ delete params.url_list;
954
+ const form = new FormData();
955
+ const configBlob = new Blob([JSON.stringify(params)], { type: 'application/json' });
956
+ form.append('config', configBlob, 'config.json');
957
+ const urlsBlob = new Blob([urlList.join('\n')], { type: 'text/plain' });
958
+ form.append('urls', urlsBlob, 'urls.txt');
959
+ response = await this.fetch({
960
+ url: url.toString(),
961
+ method: 'POST',
962
+ headers: {
963
+ 'user-agent': this.ua,
964
+ // Intentionally omit content-type — fetch fills in the
965
+ // multipart boundary itself when given a FormData body.
966
+ 'accept-encoding': 'gzip, deflate, br',
967
+ accept: 'application/json',
968
+ },
969
+ body: form,
970
+ });
971
+ } else {
972
+ response = await this.fetch({
973
+ url: url.toString(),
974
+ method: 'POST',
975
+ headers: {
976
+ 'user-agent': this.ua,
977
+ 'content-type': 'application/json',
978
+ 'accept-encoding': 'gzip, deflate, br',
979
+ accept: 'application/json',
980
+ },
981
+ body: JSON.stringify(params),
982
+ });
983
+ }
949
984
  } catch (e) {
950
985
  log.error('error', e);
951
986
  throw e;
@@ -1309,44 +1344,53 @@ export class ScrapflyClient {
1309
1344
 
1310
1345
  /**
1311
1346
  * Get the WebSocket URL for a Cloud Browser session.
1347
+ *
1348
+ * On rejection the server sends a JSON error frame then a close frame
1349
+ * with code 1008/1011/1013 and a "ERR::BROWSER::CODE: reason" string.
1350
+ * See https://scrapfly.io/docs/cloud-browser-api/errors#websocket-close-frame
1312
1351
  */
1313
1352
  cloudBrowser(config?: BrowserConfig): string {
1314
1353
  const browserConfig = config || new BrowserConfig();
1315
1354
  return browserConfig.websocketUrl(this.key, this.cloudBrowserHost);
1316
1355
  }
1317
1356
 
1357
+ /**
1358
+ * Return the deterministic project salt for this client's api_key. Matches
1359
+ * the `X-Browser-Project-Salt` response header returned on a successful
1360
+ * Cloud Browser WebSocket upgrade.
1361
+ */
1362
+ async cloudBrowserProjectSalt(): Promise<string> {
1363
+ return BrowserConfig.projectSalt(this.key);
1364
+ }
1365
+
1318
1366
  /**
1319
1367
  * Call the Cloud Browser Unblock API.
1368
+ *
1369
+ * Unblock always uses a residential proxy (no proxy pool selection) and
1370
+ * always performs a GET — the endpoint's purpose is to harvest cookies /
1371
+ * clearance tokens via an ASP-bypass navigation, not to proxy arbitrary
1372
+ * HTTP requests.
1320
1373
  */
1321
1374
  async cloudBrowserUnblock(options: {
1322
1375
  url: string;
1323
- proxy_pool?: string;
1324
1376
  country?: string;
1325
1377
  os?: string;
1378
+ browser_brand?: string;
1379
+ session?: string;
1326
1380
  timeout?: number;
1327
1381
  browser_timeout?: number;
1328
- headers?: Record<string, string>;
1329
- body?: string;
1330
- method?: string;
1331
1382
  enable_mcp?: boolean;
1332
- solve_captcha?: boolean;
1383
+ debug?: boolean;
1333
1384
  }): Promise<{ ws_url: string; session_id: string; run_id: string; mcp_endpoint?: string }> {
1334
- const proxyPoolMap: Record<string, string> = {
1335
- datacenter: 'public_datacenter_pool',
1336
- residential: 'public_residential_pool',
1337
- };
1338
-
1339
1385
  const jsonBody: Record<string, unknown> = { url: options.url };
1340
- if (options.proxy_pool) jsonBody.proxy_pool = proxyPoolMap[options.proxy_pool] || options.proxy_pool;
1341
1386
  if (options.country) jsonBody.country = options.country;
1342
1387
  if (options.os) jsonBody.os = options.os;
1388
+ if (options.browser_brand) jsonBody.browser_brand = options.browser_brand;
1389
+ if (options.session) jsonBody.session = options.session;
1343
1390
  if (options.timeout) jsonBody.timeout = options.timeout;
1344
1391
  if (options.browser_timeout) jsonBody.browser_timeout = options.browser_timeout;
1345
- if (options.headers) jsonBody.headers = options.headers;
1346
- if (options.body) jsonBody.body = options.body;
1347
- if (options.method) jsonBody.method = options.method;
1348
1392
  if (options.enable_mcp !== undefined) jsonBody.enable_mcp = options.enable_mcp;
1349
- if (options.solve_captcha !== undefined) jsonBody.solve_captcha = options.solve_captcha;
1393
+ if (options.debug !== undefined) jsonBody.debug = options.debug;
1350
1394
 
1351
1395
  const url = new URL(this.cloudBrowserApiHost + '/unblock');
1352
1396
  url.searchParams.set('key', this.key);
@@ -1505,6 +1549,318 @@ export class ScrapflyClient {
1505
1549
  return await response.json() as { extension: Record<string, any>; is_update: boolean };
1506
1550
  }
1507
1551
 
1552
+ // ----- Cloud Browser Credential Vault -------------------------------------
1553
+ // Server contract documented at apps/scrapfly/api/scrapfly-api/pkg/vault/.
1554
+ //
1555
+ // SECURITY: the vault key is the customer-held secret that decrypts every
1556
+ // item in the vault. The server emits it ONCE on POST /vault and POST
1557
+ // /vault/{id}/rotate; never log it, never include it in error messages,
1558
+ // never put it in a breadcrumb. See agent_secret_tokenization_boundary.md.
1559
+
1560
+ /**
1561
+ * Create a new Cloud Browser Credential Vault. The response contains a
1562
+ * one-time `key` that the caller MUST save locally — the server cannot
1563
+ * recover it. Pair the key with the returned vault id when opening
1564
+ * sessions or creating items.
1565
+ */
1566
+ async cloudBrowserVaultCreate(opts: {
1567
+ name: string;
1568
+ description?: string;
1569
+ }): Promise<{ vault: Vault; key: string; message: string }> {
1570
+ const url = new URL(this.cloudBrowserApiHost + '/vault');
1571
+ url.searchParams.set('key', this.key);
1572
+
1573
+ const body: Record<string, unknown> = { name: opts.name };
1574
+ if (opts.description !== undefined) body.description = opts.description;
1575
+
1576
+ const response = await this.fetch({
1577
+ url: url.toString(),
1578
+ method: 'POST',
1579
+ headers: {
1580
+ 'content-type': 'application/json',
1581
+ 'user-agent': this.ua,
1582
+ },
1583
+ body: JSON.stringify(body),
1584
+ });
1585
+
1586
+ if (!response.ok) {
1587
+ throw new Error(`Vault create failed: ${response.status} ${await response.text()}`);
1588
+ }
1589
+ return await response.json() as { vault: Vault; key: string; message: string };
1590
+ }
1591
+
1592
+ /** List every vault on the account. */
1593
+ async cloudBrowserVaultList(): Promise<{ vaults: Vault[] }> {
1594
+ const url = new URL(this.cloudBrowserApiHost + '/vault');
1595
+ url.searchParams.set('key', this.key);
1596
+
1597
+ const response = await this.fetch({
1598
+ url: url.toString(),
1599
+ method: 'GET',
1600
+ headers: { 'user-agent': this.ua },
1601
+ });
1602
+
1603
+ if (!response.ok) {
1604
+ throw new Error(`Vault list failed: ${response.status} ${await response.text()}`);
1605
+ }
1606
+ const json = await response.json() as { vaults: Vault[] | null };
1607
+ return { vaults: json.vaults ?? [] };
1608
+ }
1609
+
1610
+ /** Get a single vault by id. Does not return any secret material. */
1611
+ async cloudBrowserVaultGet(vaultId: string): Promise<{ vault: Vault }> {
1612
+ const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId));
1613
+ url.searchParams.set('key', this.key);
1614
+
1615
+ const response = await this.fetch({
1616
+ url: url.toString(),
1617
+ method: 'GET',
1618
+ headers: { 'user-agent': this.ua },
1619
+ });
1620
+
1621
+ if (!response.ok) {
1622
+ throw new Error(`Vault get failed: ${response.status} ${await response.text()}`);
1623
+ }
1624
+ return await response.json() as { vault: Vault };
1625
+ }
1626
+
1627
+ /** Update vault metadata (name / description). Does not require the vault key. */
1628
+ async cloudBrowserVaultUpdate(
1629
+ vaultId: string,
1630
+ opts: { name?: string; description?: string },
1631
+ ): Promise<{ vault: Vault; message?: string }> {
1632
+ const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId));
1633
+ url.searchParams.set('key', this.key);
1634
+
1635
+ const body: Record<string, unknown> = {};
1636
+ if (opts.name !== undefined) body.name = opts.name;
1637
+ if (opts.description !== undefined) body.description = opts.description;
1638
+
1639
+ const response = await this.fetch({
1640
+ url: url.toString(),
1641
+ method: 'PATCH',
1642
+ headers: {
1643
+ 'content-type': 'application/json',
1644
+ 'user-agent': this.ua,
1645
+ },
1646
+ body: JSON.stringify(body),
1647
+ });
1648
+
1649
+ if (!response.ok) {
1650
+ throw new Error(`Vault update failed: ${response.status} ${await response.text()}`);
1651
+ }
1652
+ return await response.json() as { vault: Vault; message?: string };
1653
+ }
1654
+
1655
+ /** Delete a vault and every item in it. Does not require the vault key. */
1656
+ async cloudBrowserVaultDelete(vaultId: string): Promise<{ success: boolean; message: string }> {
1657
+ const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId));
1658
+ url.searchParams.set('key', this.key);
1659
+
1660
+ const response = await this.fetch({
1661
+ url: url.toString(),
1662
+ method: 'DELETE',
1663
+ headers: { 'user-agent': this.ua },
1664
+ });
1665
+
1666
+ if (!response.ok) {
1667
+ throw new Error(`Vault delete failed: ${response.status} ${await response.text()}`);
1668
+ }
1669
+ const body = await response.json() as Record<string, any>;
1670
+ return {
1671
+ success: body.success !== undefined ? Boolean(body.success) : true,
1672
+ message: typeof body.message === 'string' ? body.message : '',
1673
+ };
1674
+ }
1675
+
1676
+ /**
1677
+ * Rotate the vault key. The caller MUST pass the CURRENT key in
1678
+ * `currentVaultKey`; the server returns a fresh `key` exactly once. After
1679
+ * this call the old key cannot decrypt any row in the vault.
1680
+ */
1681
+ async cloudBrowserVaultRotate(
1682
+ vaultId: string,
1683
+ currentVaultKey: string,
1684
+ ): Promise<{ key: string; message: string }> {
1685
+ const url = new URL(
1686
+ this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/rotate',
1687
+ );
1688
+ url.searchParams.set('key', this.key);
1689
+
1690
+ const response = await this.fetch({
1691
+ url: url.toString(),
1692
+ method: 'POST',
1693
+ headers: {
1694
+ 'user-agent': this.ua,
1695
+ 'X-Vault-Key': currentVaultKey,
1696
+ },
1697
+ });
1698
+
1699
+ if (!response.ok) {
1700
+ // Body may include the X-Vault-Key error message — safe to surface
1701
+ // because the server message names the header but not its value.
1702
+ throw new Error(`Vault rotate failed: ${response.status} ${await response.text()}`);
1703
+ }
1704
+ return await response.json() as { key: string; message: string };
1705
+ }
1706
+
1707
+ /** List items in a vault. Items carry only opaque ciphertext, no plaintext. */
1708
+ async cloudBrowserVaultItemList(vaultId: string): Promise<{ items: VaultItem[] }> {
1709
+ const url = new URL(
1710
+ this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/item',
1711
+ );
1712
+ url.searchParams.set('key', this.key);
1713
+
1714
+ const response = await this.fetch({
1715
+ url: url.toString(),
1716
+ method: 'GET',
1717
+ headers: { 'user-agent': this.ua },
1718
+ });
1719
+
1720
+ if (!response.ok) {
1721
+ throw new Error(`Vault item list failed: ${response.status} ${await response.text()}`);
1722
+ }
1723
+ const json = await response.json() as { items: VaultItem[] | null };
1724
+ return { items: json.items ?? [] };
1725
+ }
1726
+
1727
+ /**
1728
+ * Add a credential to a vault. Requires the vault key in the X-Vault-Key
1729
+ * header so the server can encrypt the secret payload at rest.
1730
+ */
1731
+ async cloudBrowserVaultItemCreate(
1732
+ vaultId: string,
1733
+ vaultKey: string,
1734
+ item: VaultItemCreate,
1735
+ ): Promise<{ item: VaultItem; message: string }> {
1736
+ const url = new URL(
1737
+ this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/item',
1738
+ );
1739
+ url.searchParams.set('key', this.key);
1740
+
1741
+ const body: Record<string, unknown> = {
1742
+ type: item.type,
1743
+ label: item.label,
1744
+ origin: item.origin,
1745
+ secret: item.secret,
1746
+ };
1747
+ if (item.username !== undefined) body.username = item.username;
1748
+ if (item.metadata !== undefined) body.metadata = item.metadata;
1749
+
1750
+ const response = await this.fetch({
1751
+ url: url.toString(),
1752
+ method: 'POST',
1753
+ headers: {
1754
+ 'content-type': 'application/json',
1755
+ 'user-agent': this.ua,
1756
+ 'X-Vault-Key': vaultKey,
1757
+ },
1758
+ body: JSON.stringify(body),
1759
+ });
1760
+
1761
+ if (!response.ok) {
1762
+ throw new Error(`Vault item create failed: ${response.status} ${await response.text()}`);
1763
+ }
1764
+ return await response.json() as { item: VaultItem; message: string };
1765
+ }
1766
+
1767
+ /**
1768
+ * Patch an item's metadata or rotate its secret. The server only requires
1769
+ * X-Vault-Key when `secret` is supplied (ciphertext rotation). Passing
1770
+ * `vaultKey` without `secret` is a no-op on the server side and is allowed
1771
+ * for caller convenience.
1772
+ */
1773
+ async cloudBrowserVaultItemUpdate(
1774
+ vaultId: string,
1775
+ itemId: string,
1776
+ opts: {
1777
+ vaultKey?: string;
1778
+ type?: VaultItem['type'];
1779
+ label?: string;
1780
+ origin?: string;
1781
+ username?: string;
1782
+ secret?: VaultSecret;
1783
+ metadata?: Record<string, unknown>;
1784
+ },
1785
+ ): Promise<{ item?: VaultItem; message: string }> {
1786
+ if (opts.secret !== undefined && (opts.vaultKey === undefined || opts.vaultKey === '')) {
1787
+ throw new Error(
1788
+ 'cloudBrowserVaultItemUpdate: vaultKey is required when rotating the item secret',
1789
+ );
1790
+ }
1791
+ if (opts.secret !== undefined && opts.type === undefined) {
1792
+ throw new Error(
1793
+ 'cloudBrowserVaultItemUpdate: type is required when rotating the item secret',
1794
+ );
1795
+ }
1796
+ const url = new URL(
1797
+ this.cloudBrowserApiHost +
1798
+ '/vault/' +
1799
+ encodeURIComponent(vaultId) +
1800
+ '/item/' +
1801
+ encodeURIComponent(itemId),
1802
+ );
1803
+ url.searchParams.set('key', this.key);
1804
+
1805
+ const body: Record<string, unknown> = {};
1806
+ if (opts.type !== undefined) body.type = opts.type;
1807
+ if (opts.label !== undefined) body.label = opts.label;
1808
+ if (opts.origin !== undefined) body.origin = opts.origin;
1809
+ if (opts.username !== undefined) body.username = opts.username;
1810
+ if (opts.metadata !== undefined) body.metadata = opts.metadata;
1811
+ if (opts.secret !== undefined) body.secret = opts.secret;
1812
+
1813
+ const headers: Record<string, string> = {
1814
+ 'content-type': 'application/json',
1815
+ 'user-agent': this.ua,
1816
+ };
1817
+ if (opts.vaultKey !== undefined && opts.vaultKey !== '') {
1818
+ headers['X-Vault-Key'] = opts.vaultKey;
1819
+ }
1820
+
1821
+ const response = await this.fetch({
1822
+ url: url.toString(),
1823
+ method: 'PATCH',
1824
+ headers,
1825
+ body: JSON.stringify(body),
1826
+ });
1827
+
1828
+ if (!response.ok) {
1829
+ throw new Error(`Vault item update failed: ${response.status} ${await response.text()}`);
1830
+ }
1831
+ return await response.json() as { item?: VaultItem; message: string };
1832
+ }
1833
+
1834
+ /** Delete a single vault item. Does not require the vault key. */
1835
+ async cloudBrowserVaultItemDelete(
1836
+ vaultId: string,
1837
+ itemId: string,
1838
+ ): Promise<{ success: boolean; message: string }> {
1839
+ const url = new URL(
1840
+ this.cloudBrowserApiHost +
1841
+ '/vault/' +
1842
+ encodeURIComponent(vaultId) +
1843
+ '/item/' +
1844
+ encodeURIComponent(itemId),
1845
+ );
1846
+ url.searchParams.set('key', this.key);
1847
+
1848
+ const response = await this.fetch({
1849
+ url: url.toString(),
1850
+ method: 'DELETE',
1851
+ headers: { 'user-agent': this.ua },
1852
+ });
1853
+
1854
+ if (!response.ok) {
1855
+ throw new Error(`Vault item delete failed: ${response.status} ${await response.text()}`);
1856
+ }
1857
+ const body = await response.json() as Record<string, any>;
1858
+ return {
1859
+ success: body.success !== undefined ? Boolean(body.success) : true,
1860
+ message: typeof body.message === 'string' ? body.message : '',
1861
+ };
1862
+ }
1863
+
1508
1864
  /**
1509
1865
  * Download a debug session recording video.
1510
1866
  * Returns the video as an ArrayBuffer (stream from server).
@@ -1528,7 +1884,9 @@ export class ScrapflyClient {
1528
1884
  }
1529
1885
 
1530
1886
  /**
1531
- * Get playback info for a debug session recording.
1887
+ * Get playback info for a debug session recording. The returned object
1888
+ * carries `available`, `status` ('ready' | 'uploading' | 'unavailable' |
1889
+ * 'disabled'), `metadata`, `video_url`, and `retry_after_ms`.
1532
1890
  */
1533
1891
  async cloudBrowserPlayback(runId: string): Promise<Record<string, any>> {
1534
1892
  const url = new URL(this.cloudBrowserApiHost + '/run/' + runId + '/playback');
@@ -1546,6 +1904,29 @@ export class ScrapflyClient {
1546
1904
  return await response.json() as Record<string, any>;
1547
1905
  }
1548
1906
 
1907
+ /**
1908
+ * Poll the playback endpoint until the recording resolves to a terminal
1909
+ * state ('ready' or 'unavailable') or the timeout elapses. Honours the
1910
+ * server-side retry_after_ms hint when present.
1911
+ */
1912
+ async cloudBrowserWaitForPlayback(
1913
+ runId: string,
1914
+ opts: { timeoutMs?: number; pollIntervalFallbackMs?: number } = {},
1915
+ ): Promise<Record<string, any>> {
1916
+ const timeoutMs = opts.timeoutMs ?? 180_000;
1917
+ const fallbackMs = opts.pollIntervalFallbackMs ?? 3_000;
1918
+ const deadline = Date.now() + timeoutMs;
1919
+ while (true) {
1920
+ const playback = await this.cloudBrowserPlayback(runId);
1921
+ if (playback.status !== 'uploading') return playback;
1922
+ const remaining = deadline - Date.now();
1923
+ if (remaining <= 0) return playback;
1924
+ const retryAfter = Number(playback.retry_after_ms) || fallbackMs;
1925
+ const sleepFor = Math.min(retryAfter, remaining);
1926
+ await new Promise((resolve) => setTimeout(resolve, sleepFor));
1927
+ }
1928
+ }
1929
+
1549
1930
  /**
1550
1931
  * List all running Cloud Browser sessions.
1551
1932
  */
@@ -65,7 +65,12 @@ const VALID_WEBHOOK_EVENTS: ReadonlySet<string> = new Set([
65
65
  * which lets the server apply its documented defaults (e.g. `respect_robots_txt=true`).
66
66
  */
67
67
  export type CrawlerConfigOptions = {
68
- url: string;
68
+ // URL source — exactly one of url, url_list, remote_url_list must be set.
69
+ // url enables discovery; url_list and remote_url_list crawl an explicit set
70
+ // with discovery off.
71
+ url?: string;
72
+ url_list?: string[];
73
+ remote_url_list?: string;
69
74
 
70
75
  // Crawl limits
71
76
  page_limit?: number;
@@ -131,7 +136,9 @@ export type CrawlerConfigOptions = {
131
136
  * ```
132
137
  */
133
138
  export class CrawlerConfig {
134
- url: string;
139
+ url?: string;
140
+ url_list?: string[];
141
+ remote_url_list?: string;
135
142
 
136
143
  page_limit?: number;
137
144
  max_depth?: number;
@@ -174,10 +181,19 @@ export class CrawlerConfig {
174
181
  constructor(options: CrawlerConfigOptions) {
175
182
  this.validateOptions(options);
176
183
 
177
- if (typeof options.url !== 'string' || options.url.trim() === '') {
178
- throw new CrawlerConfigError('url is required and must be a non-empty string');
184
+ const hasSeed = typeof options.url === 'string' && options.url.trim() !== '';
185
+ const hasList = Array.isArray(options.url_list) && options.url_list.length > 0;
186
+ const hasRemote = typeof options.remote_url_list === 'string' && options.remote_url_list.trim() !== '';
187
+ const sourceCount = (hasSeed ? 1 : 0) + (hasList ? 1 : 0) + (hasRemote ? 1 : 0);
188
+ if (sourceCount === 0) {
189
+ throw new CrawlerConfigError('Provide one of: url, url_list, remote_url_list');
179
190
  }
180
- this.url = options.url;
191
+ if (sourceCount > 1) {
192
+ throw new CrawlerConfigError('Only one of url, url_list, remote_url_list can be set');
193
+ }
194
+ if (hasSeed) this.url = options.url;
195
+ if (hasList) this.url_list = options.url_list;
196
+ if (hasRemote) this.remote_url_list = options.remote_url_list;
181
197
 
182
198
  // Mutually exclusive path filters
183
199
  if (options.exclude_paths && options.include_only_paths) {
@@ -272,6 +288,8 @@ export class CrawlerConfig {
272
288
  private validateOptions(options: Partial<CrawlerConfigOptions>) {
273
289
  const validKeys = new Set<string>([
274
290
  'url',
291
+ 'url_list',
292
+ 'remote_url_list',
275
293
  'page_limit',
276
294
  'max_depth',
277
295
  'max_duration',
@@ -320,8 +338,11 @@ export class CrawlerConfig {
320
338
  * defaults (e.g. `respect_robots_txt=true`).
321
339
  */
322
340
  toApiParams(): Rec<any> {
323
- const params: Rec<any> = { url: this.url };
341
+ const params: Rec<any> = {};
324
342
  const fields: Array<keyof CrawlerConfig> = [
343
+ 'url',
344
+ 'url_list',
345
+ 'remote_url_list',
325
346
  'page_limit',
326
347
  'max_depth',
327
348
  'max_duration',
@@ -168,7 +168,7 @@ export class ExtractionConfig {
168
168
  }
169
169
 
170
170
  if (this.extraction_template) {
171
- params.extraction_template = this.extraction_template;
171
+ params.extraction_template = 'persistent:' + this.extraction_template;
172
172
  }
173
173
 
174
174
  if (this.extraction_ephemeral_template) {
package/src/main.ts CHANGED
@@ -40,6 +40,7 @@ export {
40
40
  export { ExtractionConfig } from './extractionconfig.js';
41
41
  export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
42
42
  export type { BrowserConfigOptions } from './browserconfig.js';
43
+ export type { Vault, VaultItem, VaultItemCreate, VaultItemType, VaultSecret } from './types.js';
43
44
  /** Namespace of every error class the SDK can throw. See {@link ScrapflyError}. */
44
45
  export * as errors from './errors.js';
45
46
 
@@ -113,6 +113,7 @@ type ScrapeConfigOptions = {
113
113
  export class ScrapeConfig {
114
114
  static PUBLIC_DATACENTER_POOL = 'public_datacenter_pool';
115
115
  static PUBLIC_RESIDENTIAL_POOL = 'public_residential_pool';
116
+ static PUBLIC_TOR_POOL = 'public_tor_pool';
116
117
 
117
118
  url: string;
118
119
  retry = true;
@@ -145,7 +146,7 @@ export class ScrapeConfig {
145
146
  js?: string;
146
147
  rendering_wait?: number;
147
148
  wait_for_selector?: string;
148
- session_sticky_proxy = false;
149
+ session_sticky_proxy = true;
149
150
  screenshots?: Rec<any>;
150
151
  screenshot_flags?:
151
152
  ('load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags)[];
@@ -402,7 +403,7 @@ export class ScrapeConfig {
402
403
  }
403
404
 
404
405
  if (this.extraction_template) {
405
- params.extraction_template = this.extraction_template;
406
+ params.extraction_template = 'persistent:' + this.extraction_template;
406
407
  }
407
408
 
408
409
  if (this.extraction_ephemeral_template) {
@@ -421,9 +422,7 @@ export class ScrapeConfig {
421
422
  }
422
423
  if (this.session) {
423
424
  params.session = this.session;
424
- if (this.session_sticky_proxy) {
425
- params.session_sticky_proxy = true;
426
- }
425
+ params.session_sticky_proxy = this.session_sticky_proxy;
427
426
  } else {
428
427
  if (this.session_sticky_proxy) {
429
428
  log.warn('Params "session_sticky_proxy" is ignored. Works only if session is enabled');