scrapfly-sdk 0.12.0 → 0.12.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.
- package/README.md +47 -13
- package/esm/browserconfig.d.ts +20 -4
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +12 -2
- package/esm/browserdownloads.d.ts +70 -0
- package/esm/browserdownloads.d.ts.map +1 -0
- package/esm/browserdownloads.js +215 -0
- package/esm/client.d.ts +107 -4
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +307 -24
- package/esm/crawl.d.ts +26 -1
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +18 -0
- package/esm/crawlerconfig.d.ts +19 -6
- package/esm/crawlerconfig.d.ts.map +1 -1
- package/esm/crawlerconfig.js +5 -2
- package/esm/crawlerresult.d.ts +39 -0
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/main.d.ts +10 -5
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +8 -3
- package/esm/monitoringconfig.d.ts +2 -2
- package/esm/result.d.ts +11 -1
- package/esm/result.d.ts.map +1 -1
- package/esm/result.js +14 -5
- package/esm/scrapeconfig.d.ts +38 -10
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +48 -6
- package/esm/screenshotconfig.d.ts +9 -1
- package/esm/screenshotconfig.d.ts.map +1 -1
- package/esm/screenshotconfig.js +12 -1
- package/esm/types.d.ts +128 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +22 -1
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +16 -2
- package/package.json +1 -1
- package/script/browserconfig.d.ts +20 -4
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +12 -2
- package/script/browserdownloads.d.ts +70 -0
- package/script/browserdownloads.d.ts.map +1 -0
- package/script/browserdownloads.js +221 -0
- package/script/client.d.ts +107 -4
- package/script/client.d.ts.map +1 -1
- package/script/client.js +307 -24
- package/script/crawl.d.ts +26 -1
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +18 -0
- package/script/crawlerconfig.d.ts +19 -6
- package/script/crawlerconfig.d.ts.map +1 -1
- package/script/crawlerconfig.js +5 -2
- package/script/crawlerresult.d.ts +39 -0
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/main.d.ts +10 -5
- package/script/main.d.ts.map +1 -1
- package/script/main.js +13 -4
- package/script/monitoringconfig.d.ts +2 -2
- package/script/result.d.ts +11 -1
- package/script/result.d.ts.map +1 -1
- package/script/result.js +14 -5
- package/script/scrapeconfig.d.ts +38 -10
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +48 -6
- package/script/screenshotconfig.d.ts +9 -1
- package/script/screenshotconfig.d.ts.map +1 -1
- package/script/screenshotconfig.js +12 -1
- package/script/types.d.ts +128 -0
- package/script/types.d.ts.map +1 -1
- package/script/types.js +23 -0
- package/script/utils.d.ts.map +1 -1
- package/script/utils.js +16 -2
- package/src/browserconfig.ts +22 -4
- package/src/browserdownloads.ts +266 -0
- package/src/client.ts +390 -27
- package/src/crawl.ts +32 -0
- package/src/crawlerconfig.ts +19 -6
- package/src/crawlerresult.ts +41 -0
- package/src/main.ts +31 -4
- package/src/monitoringconfig.ts +2 -2
- package/src/result.ts +17 -5
- package/src/scrapeconfig.ts +47 -10
- package/src/screenshotconfig.ts +14 -1
- package/src/types.ts +159 -0
- package/src/utils.ts +16 -2
package/script/client.js
CHANGED
|
@@ -226,8 +226,7 @@ class ScrapflyClient {
|
|
|
226
226
|
let response;
|
|
227
227
|
try {
|
|
228
228
|
const url = new URL(result.content);
|
|
229
|
-
|
|
230
|
-
url.search = new URLSearchParams(params).toString();
|
|
229
|
+
url.searchParams.set('key', this.key);
|
|
231
230
|
response = await this.fetch({
|
|
232
231
|
url: url.toString(),
|
|
233
232
|
method: 'GET',
|
|
@@ -242,6 +241,20 @@ class ScrapflyClient {
|
|
|
242
241
|
logger_js_1.log.error('error', e);
|
|
243
242
|
throw e;
|
|
244
243
|
}
|
|
244
|
+
if (!response.ok) {
|
|
245
|
+
const body = await response.text();
|
|
246
|
+
let parsed = null;
|
|
247
|
+
try {
|
|
248
|
+
parsed = JSON.parse(body);
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// Not an API error: a proxy's page, say.
|
|
252
|
+
}
|
|
253
|
+
const envelope = parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
254
|
+
? parsed
|
|
255
|
+
: { message: body.slice(0, 500) || response.statusText };
|
|
256
|
+
throw this.batchApiErrorPartToError(envelope, { 'x-scrapfly-scrape-status': String(response.status) });
|
|
257
|
+
}
|
|
245
258
|
let content;
|
|
246
259
|
if (format === 'clob') {
|
|
247
260
|
content = await response.text();
|
|
@@ -260,7 +273,8 @@ class ScrapflyClient {
|
|
|
260
273
|
handleResponse(response, result) {
|
|
261
274
|
// success
|
|
262
275
|
logger_js_1.log.debug('scrape log url: ', result.result.log_url);
|
|
263
|
-
|
|
276
|
+
// QUEUED: a scrape with a webhook, delivered to it later.
|
|
277
|
+
if (result.result.status === 'QUEUED' || (result.result.status === 'DONE' && result.result.success === true)) {
|
|
264
278
|
return result;
|
|
265
279
|
}
|
|
266
280
|
// something went wrong
|
|
@@ -680,6 +694,12 @@ class ScrapflyClient {
|
|
|
680
694
|
// Drop `key` (batch key is in the URL).
|
|
681
695
|
const params = cfg.toApiParams({ key: this.key });
|
|
682
696
|
delete params.key;
|
|
697
|
+
// What a single scrape sends as the request itself: the API reads
|
|
698
|
+
// both keys of a batch entry and runs a GET without them.
|
|
699
|
+
params.method = cfg.method;
|
|
700
|
+
if (cfg.body !== undefined) {
|
|
701
|
+
params.body = cfg.body;
|
|
702
|
+
}
|
|
683
703
|
bodyConfigs.push(params);
|
|
684
704
|
}
|
|
685
705
|
const url = new URL(this.HOST + '/scrape/batch');
|
|
@@ -752,11 +772,13 @@ class ScrapflyClient {
|
|
|
752
772
|
continue;
|
|
753
773
|
}
|
|
754
774
|
try {
|
|
775
|
+
// A config with a webhook is answered by its enqueue ack, the scrape's answer under `result`.
|
|
776
|
+
const envelope = parsed.enqueued === true && parsed.result ? parsed.result : parsed;
|
|
755
777
|
const result = new result_js_1.ScrapeResult({
|
|
756
|
-
config:
|
|
757
|
-
context:
|
|
758
|
-
result:
|
|
759
|
-
uuid:
|
|
778
|
+
config: envelope.config,
|
|
779
|
+
context: envelope.context,
|
|
780
|
+
result: envelope.result,
|
|
781
|
+
uuid: envelope.uuid,
|
|
760
782
|
});
|
|
761
783
|
yield [correlationId, result];
|
|
762
784
|
}
|
|
@@ -774,7 +796,7 @@ class ScrapflyClient {
|
|
|
774
796
|
* Save screenshot response to a file
|
|
775
797
|
*/
|
|
776
798
|
async saveScreenshot(result, name, savePath) {
|
|
777
|
-
if (!result.image) {
|
|
799
|
+
if (!result.image || result.image.byteLength === 0) {
|
|
778
800
|
throw new Error('Screenshot binary does not exist');
|
|
779
801
|
}
|
|
780
802
|
const extension_name = result.metadata.extension_name;
|
|
@@ -794,23 +816,39 @@ class ScrapflyClient {
|
|
|
794
816
|
* Turn scrapfly screenshot API response to ScreenshotResult or raise one of ScrapflyError
|
|
795
817
|
*/
|
|
796
818
|
async handleScreenshotResponse(response) {
|
|
797
|
-
// A
|
|
798
|
-
//
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
819
|
+
// A JSON answer is never an image: an error, or the 201 of a screenshot with a webhook.
|
|
820
|
+
// A Response body can only be consumed once, so it is read as text and parsed from that.
|
|
821
|
+
const isJson = (response.headers.get('content-type') ?? '').startsWith('application/json');
|
|
822
|
+
if (isJson || response.status === 201) {
|
|
823
|
+
const text = await response.text();
|
|
824
|
+
let jsonData = null;
|
|
825
|
+
try {
|
|
826
|
+
const parsed = JSON.parse(text);
|
|
827
|
+
if (parsed !== null && typeof parsed === 'object') {
|
|
828
|
+
jsonData = parsed;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
catch {
|
|
832
|
+
jsonData = null;
|
|
806
833
|
}
|
|
807
|
-
|
|
808
|
-
|
|
834
|
+
const message = jsonData ? JSON.stringify(jsonData) : text || `API returned status ${response.status}`;
|
|
835
|
+
if (response.status == 401 || jsonData?.http_code == 401) {
|
|
836
|
+
throw new errors.BadApiKeyError(message);
|
|
809
837
|
}
|
|
838
|
+
if (jsonData) {
|
|
839
|
+
if ('error_id' in jsonData) {
|
|
840
|
+
throw new errors.ScreenshotApiError(JSON.stringify(jsonData));
|
|
841
|
+
}
|
|
842
|
+
// 201: a screenshot with a webhook, delivered to it later.
|
|
843
|
+
const job = jsonData.job_uuid;
|
|
844
|
+
if (response.status === 201 && jsonData.webhook_enqueued === true && typeof job === 'string' && job !== '') {
|
|
845
|
+
return new result_js_1.ScreenshotResult(response, new ArrayBuffer(0), job);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
throw new errors.ScreenshotApiError(message);
|
|
810
849
|
}
|
|
811
850
|
if (!response.ok) {
|
|
812
|
-
|
|
813
|
-
throw new errors.ScreenshotApiError(typeof body === 'string' ? body : JSON.stringify(body));
|
|
851
|
+
throw new errors.ScreenshotApiError((await response.text()) || `API returned status ${response.status}`);
|
|
814
852
|
}
|
|
815
853
|
const data = await response.arrayBuffer();
|
|
816
854
|
const result = new result_js_1.ScreenshotResult(response, data);
|
|
@@ -912,7 +950,8 @@ class ScrapflyClient {
|
|
|
912
950
|
throwCrawlerError(response, data) {
|
|
913
951
|
const httpCode = data.http_code ?? response.status;
|
|
914
952
|
const code = (data.code ?? '');
|
|
915
|
-
|
|
953
|
+
// The engine relays its own failures as `{error, code}`.
|
|
954
|
+
const message = data.message ?? (typeof data.error === 'string' ? data.error : JSON.stringify(data));
|
|
916
955
|
if (httpCode === 401) {
|
|
917
956
|
throw new errors.BadApiKeyError(message, { http_status_code: httpCode, code, api_response: data });
|
|
918
957
|
}
|
|
@@ -1564,6 +1603,73 @@ class ScrapflyClient {
|
|
|
1564
1603
|
}
|
|
1565
1604
|
yield* (0, crawlerresult_js_1.parseCrawlerPromptStream)(response.body);
|
|
1566
1605
|
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Ask a question answered from the content of one or more crawls, and get
|
|
1608
|
+
* the whole answer in one object once generation completes.
|
|
1609
|
+
*
|
|
1610
|
+
* `POST /crawl/prompt` with `generation.stream: false`: the same facts as
|
|
1611
|
+
* the frames of {@link crawlPrompt}. {@link crawl.Crawl.promptAnswer} is
|
|
1612
|
+
* sugar over a one-element list.
|
|
1613
|
+
*/
|
|
1614
|
+
async crawlPromptAnswer(crawlIds, prompt, opts) {
|
|
1615
|
+
if (!Array.isArray(crawlIds) || crawlIds.length === 0) {
|
|
1616
|
+
throw new errors.ScrapflyCrawlerError('crawl_ids must contain at least one crawler UUID');
|
|
1617
|
+
}
|
|
1618
|
+
if (!prompt) {
|
|
1619
|
+
throw new errors.ScrapflyCrawlerError('prompt must be a non-empty string');
|
|
1620
|
+
}
|
|
1621
|
+
const generation = { stream: false };
|
|
1622
|
+
if (opts?.model !== undefined)
|
|
1623
|
+
generation.model = opts.model;
|
|
1624
|
+
const payload = { prompt, crawl_ids: crawlIds, generation };
|
|
1625
|
+
if (opts?.search !== undefined)
|
|
1626
|
+
payload.search = opts.search;
|
|
1627
|
+
return (await this.postCrawlerJson('/crawl/prompt', payload));
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Extract a structured object from the content of one or more crawls.
|
|
1631
|
+
*
|
|
1632
|
+
* `POST /crawl/extract` retrieves like {@link crawlPromptAnswer} and answers
|
|
1633
|
+
* with `data` shaped by `schema`, a JSON Schema handed to the model as its
|
|
1634
|
+
* response schema. There is no streaming variant. {@link crawl.Crawl.extract}
|
|
1635
|
+
* is sugar over a one-element list.
|
|
1636
|
+
*/
|
|
1637
|
+
async crawlExtract(crawlIds, prompt, schema, opts) {
|
|
1638
|
+
if (!Array.isArray(crawlIds) || crawlIds.length === 0) {
|
|
1639
|
+
throw new errors.ScrapflyCrawlerError('crawl_ids must contain at least one crawler UUID');
|
|
1640
|
+
}
|
|
1641
|
+
if (!prompt) {
|
|
1642
|
+
throw new errors.ScrapflyCrawlerError('prompt must be a non-empty string');
|
|
1643
|
+
}
|
|
1644
|
+
if (typeof schema !== 'object' || schema === null || Array.isArray(schema) || Object.keys(schema).length === 0) {
|
|
1645
|
+
throw new errors.ScrapflyCrawlerError('schema must be a non-empty JSON Schema object');
|
|
1646
|
+
}
|
|
1647
|
+
const payload = { prompt, crawl_ids: crawlIds, schema };
|
|
1648
|
+
if (opts?.search !== undefined)
|
|
1649
|
+
payload.search = opts.search;
|
|
1650
|
+
return (await this.postCrawlerJson('/crawl/extract', payload));
|
|
1651
|
+
}
|
|
1652
|
+
/** POST a JSON body to a crawler endpoint that generates, once, and return its JSON answer. */
|
|
1653
|
+
async postCrawlerJson(path, payload) {
|
|
1654
|
+
const url = new URL(`${this.HOST}${path}`);
|
|
1655
|
+
url.search = new URLSearchParams({ key: this.key }).toString();
|
|
1656
|
+
// One attempt only: a retry re-runs the fan-out and the generation.
|
|
1657
|
+
const response = await this.fetch({
|
|
1658
|
+
url: url.toString(),
|
|
1659
|
+
method: 'POST',
|
|
1660
|
+
headers: {
|
|
1661
|
+
'user-agent': this.ua,
|
|
1662
|
+
'content-type': 'application/json',
|
|
1663
|
+
accept: 'application/json',
|
|
1664
|
+
},
|
|
1665
|
+
body: JSON.stringify(payload),
|
|
1666
|
+
}, 1);
|
|
1667
|
+
if (!response.ok) {
|
|
1668
|
+
const data = (await response.json().catch(() => ({})));
|
|
1669
|
+
this.throwCrawlerError(response, data);
|
|
1670
|
+
}
|
|
1671
|
+
return (await response.json());
|
|
1672
|
+
}
|
|
1567
1673
|
// --- Cloud Browser ---
|
|
1568
1674
|
/**
|
|
1569
1675
|
* Get the WebSocket URL for a Cloud Browser session.
|
|
@@ -1600,7 +1706,7 @@ class ScrapflyClient {
|
|
|
1600
1706
|
*
|
|
1601
1707
|
* Unblock always uses a residential proxy (no proxy pool selection) and
|
|
1602
1708
|
* always performs a GET — the endpoint's purpose is to harvest cookies /
|
|
1603
|
-
* clearance tokens via an
|
|
1709
|
+
* clearance tokens via an Unblocker navigation, not to proxy arbitrary
|
|
1604
1710
|
* HTTP requests.
|
|
1605
1711
|
*/
|
|
1606
1712
|
async cloudBrowserUnblock(options) {
|
|
@@ -1997,6 +2103,183 @@ class ScrapflyClient {
|
|
|
1997
2103
|
message: typeof body.message === 'string' ? body.message : '',
|
|
1998
2104
|
};
|
|
1999
2105
|
}
|
|
2106
|
+
// ----- Vault ↔ linked secret manager (1Password) ---------------------------
|
|
2107
|
+
// A linked vault mirrors an upstream secret manager instead of holding
|
|
2108
|
+
// operator-entered items. The provider's service-account token is sealed
|
|
2109
|
+
// under the vault key like any other secret, so every endpoint that carries
|
|
2110
|
+
// a token also carries X-Vault-Key: the server verifies the key BEFORE
|
|
2111
|
+
// sealing, because a well-formed wrong key would link the vault and leave a
|
|
2112
|
+
// token every later sync fails to open.
|
|
2113
|
+
/**
|
|
2114
|
+
* Link a vault to a secret manager. The token is sealed under `vaultKey`, so
|
|
2115
|
+
* the key is mandatory here. The vault must not already be linked and must
|
|
2116
|
+
* hold no rows owned by a previous service (the server answers 409).
|
|
2117
|
+
*/
|
|
2118
|
+
async cloudBrowserVaultServiceLink(vaultId, vaultKey, link) {
|
|
2119
|
+
if (!link.token) {
|
|
2120
|
+
throw new Error('cloudBrowserVaultServiceLink: token is required when linking a service');
|
|
2121
|
+
}
|
|
2122
|
+
// Same rule as the server's linked_service_data validation; caught here so a
|
|
2123
|
+
// malformed link does not cost a round trip.
|
|
2124
|
+
if (!link.linked_service_data?.vault_id && !link.linked_service_data?.vault_name) {
|
|
2125
|
+
throw new Error('cloudBrowserVaultServiceLink: linked_service_data requires vault_id or vault_name');
|
|
2126
|
+
}
|
|
2127
|
+
const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/service');
|
|
2128
|
+
url.searchParams.set('key', this.key);
|
|
2129
|
+
const response = await this.fetch({
|
|
2130
|
+
url: url.toString(),
|
|
2131
|
+
method: 'POST',
|
|
2132
|
+
headers: {
|
|
2133
|
+
'content-type': 'application/json',
|
|
2134
|
+
'user-agent': this.ua,
|
|
2135
|
+
'X-Vault-Key': vaultKey,
|
|
2136
|
+
},
|
|
2137
|
+
body: JSON.stringify({
|
|
2138
|
+
linked_service: link.linked_service,
|
|
2139
|
+
token: link.token,
|
|
2140
|
+
linked_service_data: link.linked_service_data,
|
|
2141
|
+
}),
|
|
2142
|
+
});
|
|
2143
|
+
if (!response.ok) {
|
|
2144
|
+
throw new Error(`Vault service link failed: ${response.status} ${await response.text()}`);
|
|
2145
|
+
}
|
|
2146
|
+
return await response.json();
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* Update a link: edit the non-secret selection rules, rotate the token, or
|
|
2150
|
+
* both. `vaultKey` is required only when `token` is supplied, mirroring
|
|
2151
|
+
* `cloudBrowserVaultItemUpdate`; a config-only edit needs no key.
|
|
2152
|
+
*
|
|
2153
|
+
* A token rotation also clears the server's one-hour auth back-off, so a link
|
|
2154
|
+
* broken by a dead token syncs again on the next round.
|
|
2155
|
+
*/
|
|
2156
|
+
async cloudBrowserVaultServiceUpdate(vaultId, opts) {
|
|
2157
|
+
if (opts.token !== undefined && opts.token !== '' && (opts.vaultKey === undefined || opts.vaultKey === '')) {
|
|
2158
|
+
throw new Error('cloudBrowserVaultServiceUpdate: vaultKey is required when rotating the service token');
|
|
2159
|
+
}
|
|
2160
|
+
const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/service');
|
|
2161
|
+
url.searchParams.set('key', this.key);
|
|
2162
|
+
const body = {};
|
|
2163
|
+
if (opts.token !== undefined)
|
|
2164
|
+
body.token = opts.token;
|
|
2165
|
+
if (opts.linked_service_data !== undefined)
|
|
2166
|
+
body.linked_service_data = opts.linked_service_data;
|
|
2167
|
+
const headers = {
|
|
2168
|
+
'content-type': 'application/json',
|
|
2169
|
+
'user-agent': this.ua,
|
|
2170
|
+
};
|
|
2171
|
+
if (opts.vaultKey !== undefined && opts.vaultKey !== '') {
|
|
2172
|
+
headers['X-Vault-Key'] = opts.vaultKey;
|
|
2173
|
+
}
|
|
2174
|
+
const response = await this.fetch({
|
|
2175
|
+
url: url.toString(),
|
|
2176
|
+
method: 'PATCH',
|
|
2177
|
+
headers,
|
|
2178
|
+
body: JSON.stringify(body),
|
|
2179
|
+
});
|
|
2180
|
+
if (!response.ok) {
|
|
2181
|
+
throw new Error(`Vault service update failed: ${response.status} ${await response.text()}`);
|
|
2182
|
+
}
|
|
2183
|
+
return await response.json();
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Unlink the provider. `keepItems` governs only the mirrored rows — kept as
|
|
2187
|
+
* plain manual items, or deleted — while the sealed token is removed either
|
|
2188
|
+
* way, so no vault key is needed.
|
|
2189
|
+
*
|
|
2190
|
+
* Dropping the rows is irreversible, so the default is to keep them and the
|
|
2191
|
+
* flag always goes on the wire explicitly rather than relying on a default at
|
|
2192
|
+
* either end.
|
|
2193
|
+
*/
|
|
2194
|
+
async cloudBrowserVaultServiceUnlink(vaultId, opts = {}) {
|
|
2195
|
+
const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/service');
|
|
2196
|
+
url.searchParams.set('key', this.key);
|
|
2197
|
+
url.searchParams.set('keep_items', (opts.keepItems ?? true) ? 'true' : 'false');
|
|
2198
|
+
const response = await this.fetch({
|
|
2199
|
+
url: url.toString(),
|
|
2200
|
+
method: 'DELETE',
|
|
2201
|
+
headers: { 'user-agent': this.ua },
|
|
2202
|
+
});
|
|
2203
|
+
if (!response.ok) {
|
|
2204
|
+
throw new Error(`Vault service unlink failed: ${response.status} ${await response.text()}`);
|
|
2205
|
+
}
|
|
2206
|
+
const body = await response.json();
|
|
2207
|
+
return {
|
|
2208
|
+
success: body.success !== undefined ? Boolean(body.success) : true,
|
|
2209
|
+
message: typeof body.message === 'string' ? body.message : '',
|
|
2210
|
+
};
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Force a reconcile against the provider now, bypassing the sync TTL and the
|
|
2214
|
+
* back-off a failed round leaves behind. Requires the vault key: the server
|
|
2215
|
+
* opens the sealed token with it and re-seals every mirrored row.
|
|
2216
|
+
*
|
|
2217
|
+
* The server budget is 25s; the SDK pins no per-call timeout, so the runtime's
|
|
2218
|
+
* own fetch default applies.
|
|
2219
|
+
*/
|
|
2220
|
+
async cloudBrowserVaultServiceSync(vaultId, vaultKey) {
|
|
2221
|
+
const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/service/sync');
|
|
2222
|
+
url.searchParams.set('key', this.key);
|
|
2223
|
+
const response = await this.fetch({
|
|
2224
|
+
url: url.toString(),
|
|
2225
|
+
method: 'POST',
|
|
2226
|
+
headers: {
|
|
2227
|
+
'user-agent': this.ua,
|
|
2228
|
+
'X-Vault-Key': vaultKey,
|
|
2229
|
+
},
|
|
2230
|
+
});
|
|
2231
|
+
if (!response.ok) {
|
|
2232
|
+
throw new Error(`Vault service sync failed: ${response.status} ${await response.text()}`);
|
|
2233
|
+
}
|
|
2234
|
+
return await response.json();
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* Probe the provider: proves a token is live and lists the upstream vaults it
|
|
2238
|
+
* can read. Writes nothing, so it never moves the vault's sync state.
|
|
2239
|
+
*
|
|
2240
|
+
* With no `token` the sealed token of an existing link is probed (the vault
|
|
2241
|
+
* key opens it). Passing an unsaved `token` instead enumerates the upstream
|
|
2242
|
+
* vaults BEFORE a link exists, which is how a caller picks `vault_id`.
|
|
2243
|
+
*
|
|
2244
|
+
* `linkedService` stays optional and undefaulted here: this is the one endpoint
|
|
2245
|
+
* whose empty discriminator the server itself resolves to 1Password, and a
|
|
2246
|
+
* client-side default would send a field the bodyless stored-token path must
|
|
2247
|
+
* not carry.
|
|
2248
|
+
*
|
|
2249
|
+
* The server budget is 10s; the SDK pins no per-call timeout, so the runtime's
|
|
2250
|
+
* own fetch default applies.
|
|
2251
|
+
*/
|
|
2252
|
+
async cloudBrowserVaultServiceTest(vaultId, vaultKey, opts = {}) {
|
|
2253
|
+
const url = new URL(this.cloudBrowserApiHost + '/vault/' + encodeURIComponent(vaultId) + '/service/test');
|
|
2254
|
+
url.searchParams.set('key', this.key);
|
|
2255
|
+
const headers = {
|
|
2256
|
+
'user-agent': this.ua,
|
|
2257
|
+
'X-Vault-Key': vaultKey,
|
|
2258
|
+
};
|
|
2259
|
+
// A bodyless request is what selects the stored-token path server-side, so
|
|
2260
|
+
// send a body only when the caller supplied something to probe with.
|
|
2261
|
+
let body;
|
|
2262
|
+
if (opts.token !== undefined || opts.linkedService !== undefined) {
|
|
2263
|
+
const payload = {};
|
|
2264
|
+
if (opts.linkedService !== undefined)
|
|
2265
|
+
payload.linked_service = opts.linkedService;
|
|
2266
|
+
if (opts.token !== undefined)
|
|
2267
|
+
payload.token = opts.token;
|
|
2268
|
+
body = JSON.stringify(payload);
|
|
2269
|
+
headers['content-type'] = 'application/json';
|
|
2270
|
+
}
|
|
2271
|
+
const response = await this.fetch({
|
|
2272
|
+
url: url.toString(),
|
|
2273
|
+
method: 'POST',
|
|
2274
|
+
headers,
|
|
2275
|
+
body,
|
|
2276
|
+
});
|
|
2277
|
+
if (!response.ok) {
|
|
2278
|
+
throw new Error(`Vault service test failed: ${response.status} ${await response.text()}`);
|
|
2279
|
+
}
|
|
2280
|
+
const json = await response.json();
|
|
2281
|
+
return { ...json, vaults_visible: json.vaults_visible ?? [] };
|
|
2282
|
+
}
|
|
2000
2283
|
/**
|
|
2001
2284
|
* Download a debug session recording video.
|
|
2002
2285
|
* Returns the video as an ArrayBuffer (stream from server).
|
|
@@ -2102,7 +2385,7 @@ class ScrapflyClient {
|
|
|
2102
2385
|
async getSchedule(id) {
|
|
2103
2386
|
return await this.scheduleRequest('GET', `/schedules/${encodeURIComponent(id)}`);
|
|
2104
2387
|
}
|
|
2105
|
-
/** List
|
|
2388
|
+
/** List the schedules of the API key's project and environment, optionally filtered by kind/status. */
|
|
2106
2389
|
async listSchedules(opts) {
|
|
2107
2390
|
return await this.scheduleRequest('GET', '/schedules', opts);
|
|
2108
2391
|
}
|
package/script/crawl.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ScrapflyClient } from './client.js';
|
|
2
2
|
import type { CrawlerConfig, CrawlerContentFormat } from './crawlerconfig.js';
|
|
3
|
-
import type { CrawlerArtifact, CrawlerPromptEvent, CrawlerRefreshEntry, CrawlerRefreshState, CrawlerSearchMode, CrawlerSearchResponse, CrawlerStatus, CrawlerUrls } from './crawlerresult.js';
|
|
3
|
+
import type { CrawlerArtifact, CrawlerExtractResponse, CrawlerPromptAnswer, CrawlerPromptEvent, CrawlerRefreshEntry, CrawlerRefreshState, CrawlerSearchMode, CrawlerSearchResponse, CrawlerStatus, CrawlerUrls } from './crawlerresult.js';
|
|
4
4
|
/**
|
|
5
5
|
* High-level fluent wrapper around a single crawler job lifecycle.
|
|
6
6
|
*
|
|
@@ -127,6 +127,31 @@ export declare class Crawl {
|
|
|
127
127
|
};
|
|
128
128
|
model?: string;
|
|
129
129
|
}): AsyncGenerator<CrawlerPromptEvent, void, undefined>;
|
|
130
|
+
/**
|
|
131
|
+
* Ask a question answered from this crawl's content, the whole answer at once.
|
|
132
|
+
*
|
|
133
|
+
* Sugar over `client.crawlPromptAnswer([uuid], ...)`.
|
|
134
|
+
*/
|
|
135
|
+
promptAnswer(prompt: string, opts?: {
|
|
136
|
+
search?: {
|
|
137
|
+
limit?: number;
|
|
138
|
+
mode?: CrawlerSearchMode;
|
|
139
|
+
filters?: Record<string, any>;
|
|
140
|
+
};
|
|
141
|
+
model?: string;
|
|
142
|
+
}): Promise<CrawlerPromptAnswer>;
|
|
143
|
+
/**
|
|
144
|
+
* Extract a structured object from this crawl's content, shaped by `schema`.
|
|
145
|
+
*
|
|
146
|
+
* Sugar over `client.crawlExtract([uuid], ...)`.
|
|
147
|
+
*/
|
|
148
|
+
extract<T = any>(prompt: string, schema: Record<string, any>, opts?: {
|
|
149
|
+
search?: {
|
|
150
|
+
limit?: number;
|
|
151
|
+
mode?: CrawlerSearchMode;
|
|
152
|
+
filters?: Record<string, any>;
|
|
153
|
+
};
|
|
154
|
+
}): Promise<CrawlerExtractResponse<T>>;
|
|
130
155
|
/**
|
|
131
156
|
* Re-scrape this crawl's URLs in place, right now.
|
|
132
157
|
*
|
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,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,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,GAAG,SAAS,CAE7B;IAED,sEAAsE;IACtE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,OA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AMG;IACG,UAAU,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAKhD;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAK/G;;;;OAIG;IACG,cAAc,CAAC,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAK/E;;;;;;OAMG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,oBAA6B,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAetF;;;;OAIG;IACG,SAAS,CACb,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE,oBAAoB,EAAa,GACzC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAKlD;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC;IAStC;;OAEG;IACG,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC;CAQtC"}
|
package/script/crawl.js
CHANGED
|
@@ -227,6 +227,24 @@ class Crawl {
|
|
|
227
227
|
const uuid = this.requireUuid();
|
|
228
228
|
return this.client.crawlPrompt([uuid], prompt, opts);
|
|
229
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Ask a question answered from this crawl's content, the whole answer at once.
|
|
232
|
+
*
|
|
233
|
+
* Sugar over `client.crawlPromptAnswer([uuid], ...)`.
|
|
234
|
+
*/
|
|
235
|
+
async promptAnswer(prompt, opts) {
|
|
236
|
+
const uuid = this.requireUuid();
|
|
237
|
+
return this.client.crawlPromptAnswer([uuid], prompt, opts);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Extract a structured object from this crawl's content, shaped by `schema`.
|
|
241
|
+
*
|
|
242
|
+
* Sugar over `client.crawlExtract([uuid], ...)`.
|
|
243
|
+
*/
|
|
244
|
+
async extract(prompt, schema, opts) {
|
|
245
|
+
const uuid = this.requireUuid();
|
|
246
|
+
return this.client.crawlExtract([uuid], prompt, schema, opts);
|
|
247
|
+
}
|
|
230
248
|
/**
|
|
231
249
|
* Re-scrape this crawl's URLs in place, right now.
|
|
232
250
|
*
|
|
@@ -61,17 +61,27 @@ export type CrawlerConfigOptions = {
|
|
|
61
61
|
refresh?: boolean;
|
|
62
62
|
refresh_interval?: number;
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
65
|
-
* Sent in the `POST /crawl` body as `asp`; only the SDK-facing
|
|
64
|
+
* The Unblocker (anti-bot bypass), the current name for what used to be
|
|
65
|
+
* called `asp`. Sent in the `POST /crawl` body as `asp`; only the SDK-facing
|
|
66
|
+
* name changed.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Use `proxy_pool` (`'unblocker_ultra'` for the Unblocker). The
|
|
69
|
+
* migration guide covers requests written before the proxy pools:
|
|
70
|
+
* https://scrapfly.io/new-pricing#legacy-spellings
|
|
66
71
|
*/
|
|
67
72
|
unblocker?: boolean;
|
|
68
73
|
/**
|
|
69
|
-
* @deprecated
|
|
70
|
-
*
|
|
74
|
+
* @deprecated Alias of {@link CrawlerConfigOptions.unblocker}: use
|
|
75
|
+
* `proxy_pool` (`'unblocker_ultra'` for the Unblocker). When both are
|
|
71
76
|
* supplied `asp` wins, so existing code cannot have its meaning changed by a
|
|
72
77
|
* later `unblocker`.
|
|
73
78
|
*/
|
|
74
79
|
asp?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Proxy pool for every crawled page: `basic`, `unblocker`, `unblocker_ultra`
|
|
82
|
+
* or `auto` (see ScrapeConfig.BASIC), each of which sets the Unblocker
|
|
83
|
+
* itself.
|
|
84
|
+
*/
|
|
75
85
|
proxy_pool?: string;
|
|
76
86
|
country?: string;
|
|
77
87
|
webhook_name?: string;
|
|
@@ -127,7 +137,7 @@ export declare class CrawlerConfig {
|
|
|
127
137
|
* Storage for the anti-bot bypass toggle, under its deprecated name.
|
|
128
138
|
* `unblocker` is an accessor over this same field — see below.
|
|
129
139
|
*
|
|
130
|
-
* @deprecated Use
|
|
140
|
+
* @deprecated Use `proxy_pool` (`'unblocker_ultra'` for the Unblocker).
|
|
131
141
|
*/
|
|
132
142
|
asp?: boolean;
|
|
133
143
|
proxy_pool?: string;
|
|
@@ -136,7 +146,10 @@ export declare class CrawlerConfig {
|
|
|
136
146
|
webhook_events?: CrawlerWebhookEventName[];
|
|
137
147
|
constructor(options: CrawlerConfigOptions);
|
|
138
148
|
/**
|
|
139
|
-
*
|
|
149
|
+
* The Unblocker toggle, the current name for what used to be `asp`.
|
|
150
|
+
* Deprecated: use `proxy_pool` (`'unblocker_ultra'` for the Unblocker). The
|
|
151
|
+
* migration guide covers requests written before the proxy pools:
|
|
152
|
+
* https://scrapfly.io/new-pricing#legacy-spellings
|
|
140
153
|
*
|
|
141
154
|
* An accessor over the single `asp` field rather than a second stored
|
|
142
155
|
* property: one storage slot means the two names can never disagree, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crawlerconfig.d.ts","sourceRoot":"","sources":["../src/crawlerconfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,oBAAoB,GAC5B,MAAM,GACN,YAAY,GACZ,UAAU,GACV,MAAM,GACN,MAAM,GACN,gBAAgB,GAChB,eAAe,CAAC;AAYpB;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAC/B,iBAAiB,GACjB,qBAAqB,GACrB,qBAAqB,GACrB,wBAAwB,GACxB,oBAAoB,GACpB,iBAAiB,GACjB,mBAAmB,GACnB,kBAAkB,GAClB,sBAAsB,GACtB,uBAAuB,GACvB,iBAAiB,CAAC;AAEtB;;GAEG;AACH,eAAO,MAAM,oBAAoB,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IAAI,OAAO,GAAG,SAAS,CAEnC;IAED,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAEvC;IAED,OAAO,CAAC,eAAe;IA8CvB;;;;;;;;;OASG;IACH,WAAW,IAAI,GAAG,CAAC,GAAG,CAAC;CAqExB"}
|
package/script/crawlerconfig.js
CHANGED
|
@@ -230,7 +230,7 @@ class CrawlerConfig {
|
|
|
230
230
|
* Storage for the anti-bot bypass toggle, under its deprecated name.
|
|
231
231
|
* `unblocker` is an accessor over this same field — see below.
|
|
232
232
|
*
|
|
233
|
-
* @deprecated Use
|
|
233
|
+
* @deprecated Use `proxy_pool` (`'unblocker_ultra'` for the Unblocker).
|
|
234
234
|
*/
|
|
235
235
|
Object.defineProperty(this, "asp", {
|
|
236
236
|
enumerable: true,
|
|
@@ -383,7 +383,10 @@ class CrawlerConfig {
|
|
|
383
383
|
this.webhook_events = options.webhook_events;
|
|
384
384
|
}
|
|
385
385
|
/**
|
|
386
|
-
*
|
|
386
|
+
* The Unblocker toggle, the current name for what used to be `asp`.
|
|
387
|
+
* Deprecated: use `proxy_pool` (`'unblocker_ultra'` for the Unblocker). The
|
|
388
|
+
* migration guide covers requests written before the proxy pools:
|
|
389
|
+
* https://scrapfly.io/new-pricing#legacy-spellings
|
|
387
390
|
*
|
|
388
391
|
* An accessor over the single `asp` field rather than a second stored
|
|
389
392
|
* property: one storage slot means the two names can never disagree, and
|
|
@@ -305,6 +305,45 @@ export interface CrawlerPromptSource {
|
|
|
305
305
|
title?: string;
|
|
306
306
|
score?: number;
|
|
307
307
|
}
|
|
308
|
+
/** How much of the corpus a prompt answer or an extraction covers. */
|
|
309
|
+
export interface CrawlerPromptSearch {
|
|
310
|
+
completeness: 'exact' | 'partial';
|
|
311
|
+
crawls_requested?: number;
|
|
312
|
+
crawls_searched?: number;
|
|
313
|
+
crawls_pruned_exact?: number;
|
|
314
|
+
/** Requested crawls that contributed nothing, with a reason. Never fatal. */
|
|
315
|
+
skipped: CrawlerSearchSkipped[];
|
|
316
|
+
}
|
|
317
|
+
/** The answer of `POST /crawl/prompt` with `generation.stream: false`: the facts of the stream, in one object. */
|
|
318
|
+
export interface CrawlerPromptAnswer {
|
|
319
|
+
prompt: string;
|
|
320
|
+
answer: string;
|
|
321
|
+
sources: CrawlerPromptSource[];
|
|
322
|
+
sources_used: number[];
|
|
323
|
+
/** Retrieved chunks that did not fit the context and never reached the model. */
|
|
324
|
+
sources_dropped: number;
|
|
325
|
+
/** True when the model hit its output cap. The answer is still delivered. */
|
|
326
|
+
truncated: boolean;
|
|
327
|
+
search: CrawlerPromptSearch;
|
|
328
|
+
/** Actual charge, including zero. Undefined when the server does not report it. */
|
|
329
|
+
api_credit?: number;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* The response of `POST /crawl/extract`. `data` is shaped by the request's JSON
|
|
333
|
+
* Schema, which constrains the model as it generates; it is not validated again
|
|
334
|
+
* afterwards, so validate on your side anything you act on.
|
|
335
|
+
*/
|
|
336
|
+
export interface CrawlerExtractResponse<T = any> {
|
|
337
|
+
prompt: string;
|
|
338
|
+
data: T;
|
|
339
|
+
/** The retrieved chunks `data` was built from. */
|
|
340
|
+
sources: CrawlerPromptSource[];
|
|
341
|
+
/** Retrieved chunks that did not fit the context and never reached the model. */
|
|
342
|
+
sources_dropped: number;
|
|
343
|
+
/** True when the model hit its output cap. */
|
|
344
|
+
truncated: boolean;
|
|
345
|
+
search: CrawlerPromptSearch;
|
|
346
|
+
}
|
|
308
347
|
/** Payload of the terminal `done` frame. */
|
|
309
348
|
export interface CrawlerPromptDone {
|
|
310
349
|
sources_used?: number[];
|