scrapfly-sdk 0.11.1 → 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 +72 -5
- package/esm/browserconfig.d.ts +57 -9
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +63 -5
- 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 +224 -8
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +646 -62
- package/esm/crawl.d.ts +83 -1
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +73 -0
- package/esm/crawlerconfig.d.ts +54 -3
- package/esm/crawlerconfig.d.ts.map +1 -1
- package/esm/crawlerconfig.js +96 -2
- package/esm/crawlerresult.d.ts +374 -2
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/crawlerresult.js +367 -1
- package/esm/errors.d.ts +12 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +11 -0
- package/esm/main.d.ts +12 -7
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +10 -5
- 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 +65 -1
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +88 -4
- 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/esm/webhookserver.d.ts +33 -15
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +197 -38
- package/package.json +1 -1
- package/script/browserconfig.d.ts +57 -9
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +63 -5
- 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 +224 -8
- package/script/client.d.ts.map +1 -1
- package/script/client.js +645 -61
- package/script/crawl.d.ts +83 -1
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +73 -0
- package/script/crawlerconfig.d.ts +54 -3
- package/script/crawlerconfig.d.ts.map +1 -1
- package/script/crawlerconfig.js +97 -3
- package/script/crawlerresult.d.ts +374 -2
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/crawlerresult.js +374 -2
- package/script/errors.d.ts +12 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +12 -1
- package/script/main.d.ts +12 -7
- package/script/main.d.ts.map +1 -1
- package/script/main.js +20 -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 +65 -1
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +88 -4
- 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/script/webhookserver.d.ts +33 -15
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +197 -38
- package/src/browserconfig.ts +74 -8
- package/src/browserdownloads.ts +266 -0
- package/src/client.ts +796 -65
- package/src/crawl.ts +106 -0
- package/src/crawlerconfig.ts +128 -5
- package/src/crawlerresult.ts +607 -3
- package/src/errors.ts +12 -0
- package/src/main.ts +55 -5
- package/src/monitoringconfig.ts +2 -2
- package/src/result.ts +17 -5
- package/src/scrapeconfig.ts +92 -3
- package/src/screenshotconfig.ts +14 -1
- package/src/types.ts +159 -1
- package/src/utils.ts +16 -2
- package/src/webhookserver.ts +235 -39
package/script/crawlerresult.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CrawlerArtifact = exports.CrawlerContents = exports.CrawlerUrls = exports.CrawlerStatus = void 0;
|
|
3
|
+
exports.CrawlerArtifact = exports.CrawlerContents = exports.CrawlerUrls = exports.CrawlerSearchResponse = exports.CrawlerStatus = void 0;
|
|
4
|
+
exports.refreshChanged = refreshChanged;
|
|
5
|
+
exports.parseCrawlerRefreshState = parseCrawlerRefreshState;
|
|
6
|
+
exports.isSearchable = isSearchable;
|
|
7
|
+
exports.parseCrawlerSearchState = parseCrawlerSearchState;
|
|
8
|
+
exports.parseCrawlerPromptStream = parseCrawlerPromptStream;
|
|
4
9
|
exports.parseCrawlerWebhook = parseCrawlerWebhook;
|
|
10
|
+
const errors_js_1 = require("./errors.js");
|
|
5
11
|
const polyfill_js_1 = require("./polyfill.js");
|
|
6
12
|
/**
|
|
7
13
|
* Pull a required field out of an API response body and fail loud if it's
|
|
@@ -80,6 +86,23 @@ class CrawlerStatus {
|
|
|
80
86
|
writable: true,
|
|
81
87
|
value: void 0
|
|
82
88
|
});
|
|
89
|
+
/**
|
|
90
|
+
* `null` unless the crawl was started with `search: true`. Polling this is
|
|
91
|
+
* the webhook-free way to learn when the index became queryable.
|
|
92
|
+
*/
|
|
93
|
+
Object.defineProperty(this, "search", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: void 0
|
|
98
|
+
});
|
|
99
|
+
/** `null` unless the crawl re-scrapes itself on a period. */
|
|
100
|
+
Object.defineProperty(this, "refresh", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: void 0
|
|
105
|
+
});
|
|
83
106
|
// Canonical API field name is `crawler_uuid`; accept short `uuid` as a
|
|
84
107
|
// legacy fallback but throw if neither is present.
|
|
85
108
|
if ('crawler_uuid' in data && typeof data.crawler_uuid === 'string' && data.crawler_uuid) {
|
|
@@ -115,6 +138,14 @@ class CrawlerStatus {
|
|
|
115
138
|
stop_time: optionalField(state, 'stop_time', 'number', 'CrawlerStatus.state'),
|
|
116
139
|
stop_reason: optionalField(state, 'stop_reason', 'string', 'CrawlerStatus.state'),
|
|
117
140
|
};
|
|
141
|
+
// Both blocks go through their field whitelist rather than a cast to the
|
|
142
|
+
// interface. A cast is a compile-time claim only: raw JSON rides through
|
|
143
|
+
// it, so a field the model never declared still reaches the caller and a
|
|
144
|
+
// field the model lost still looks decoded.
|
|
145
|
+
const search = optionalField(data, 'search', 'object', 'CrawlerStatus');
|
|
146
|
+
this.search = search ? parseCrawlerSearchState(search) : null;
|
|
147
|
+
const refresh = optionalField(data, 'refresh', 'object', 'CrawlerStatus');
|
|
148
|
+
this.refresh = refresh ? parseCrawlerRefreshState(refresh) : null;
|
|
118
149
|
}
|
|
119
150
|
/** True while the crawler is still working (PENDING or RUNNING). */
|
|
120
151
|
get isRunning() {
|
|
@@ -141,6 +172,344 @@ class CrawlerStatus {
|
|
|
141
172
|
}
|
|
142
173
|
}
|
|
143
174
|
exports.CrawlerStatus = CrawlerStatus;
|
|
175
|
+
/** Pages a run actually touched. Zero means the site stood still. */
|
|
176
|
+
function refreshChanged(entry) {
|
|
177
|
+
return (entry?.added ?? 0) + (entry?.updated ?? 0) + (entry?.removed ?? 0);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Normalize a refresh envelope.
|
|
181
|
+
*
|
|
182
|
+
* The three refresh endpoints answer with the state at the top level;
|
|
183
|
+
* `GET /status` nests it under `refresh`. Accepting both means the SDK never
|
|
184
|
+
* has to guess which call produced the payload.
|
|
185
|
+
*
|
|
186
|
+
* This is a field whitelist, not a spread: a key that is not named here never
|
|
187
|
+
* reaches the caller, whatever the interface declares.
|
|
188
|
+
*/
|
|
189
|
+
function parseCrawlerRefreshState(data) {
|
|
190
|
+
const block = data && typeof data.refresh === 'object' && data.refresh !== null ? data.refresh : data;
|
|
191
|
+
return {
|
|
192
|
+
enabled: block.enabled === true,
|
|
193
|
+
interval_seconds: typeof block.interval_seconds === 'number' ? block.interval_seconds : 0,
|
|
194
|
+
status: block.status ?? 'DISABLED',
|
|
195
|
+
generation: block.generation,
|
|
196
|
+
last_run_at: block.last_run_at ?? undefined,
|
|
197
|
+
next_run_at: block.next_run_at ?? undefined,
|
|
198
|
+
error: block.error ?? undefined,
|
|
199
|
+
started_at: block.started_at ?? undefined,
|
|
200
|
+
consecutive_failures: block.consecutive_failures ?? undefined,
|
|
201
|
+
history: Array.isArray(block.history) ? block.history : [],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** True when the index can answer a query right now. */
|
|
205
|
+
function isSearchable(state) {
|
|
206
|
+
return state?.status === 'READY' || state?.status === 'PARTIAL';
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Normalize a search envelope.
|
|
210
|
+
*
|
|
211
|
+
* `GET /status` nests the block under `search` and so do the two search
|
|
212
|
+
* webhooks; taking the block on its own as well means a caller holding either
|
|
213
|
+
* envelope decodes the same way.
|
|
214
|
+
*
|
|
215
|
+
* This is a field whitelist, not a spread: a key that is not named here never
|
|
216
|
+
* reaches the caller, whatever the interface declares. `status` is the one
|
|
217
|
+
* field with no sane absent value, so a block without it reads as DISABLED.
|
|
218
|
+
*/
|
|
219
|
+
function parseCrawlerSearchState(data) {
|
|
220
|
+
const block = data && typeof data.search === 'object' && data.search !== null ? data.search : data;
|
|
221
|
+
return {
|
|
222
|
+
status: block.status ?? 'DISABLED',
|
|
223
|
+
manifest: block.manifest ?? undefined,
|
|
224
|
+
documents: block.documents ?? undefined,
|
|
225
|
+
vectors: block.vectors ?? undefined,
|
|
226
|
+
dropped: block.dropped ?? undefined,
|
|
227
|
+
queue_depth: block.queue_depth ?? undefined,
|
|
228
|
+
fragments: block.fragments ?? undefined,
|
|
229
|
+
error: block.error ?? undefined,
|
|
230
|
+
built_at: block.built_at ?? undefined,
|
|
231
|
+
index: block.index ?? undefined,
|
|
232
|
+
generation: block.generation ?? undefined,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Wraps the JSON response of `POST /crawl/search`.
|
|
237
|
+
*
|
|
238
|
+
* The envelope states its own completeness: `exact` with most crawls unopened
|
|
239
|
+
* is the normal outcome, because the fan-out proves via an admissible bound
|
|
240
|
+
* that the unopened crawls held nothing better. `partial` means the deadline
|
|
241
|
+
* cut the fan-out short.
|
|
242
|
+
*
|
|
243
|
+
* Strict on the fields the contract always carries, lenient on the rest, so
|
|
244
|
+
* drift in the ranking envelope surfaces at parse time rather than as an
|
|
245
|
+
* empty result list.
|
|
246
|
+
*/
|
|
247
|
+
class CrawlerSearchResponse {
|
|
248
|
+
constructor(data) {
|
|
249
|
+
Object.defineProperty(this, "query", {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
configurable: true,
|
|
252
|
+
writable: true,
|
|
253
|
+
value: void 0
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(this, "mode", {
|
|
256
|
+
enumerable: true,
|
|
257
|
+
configurable: true,
|
|
258
|
+
writable: true,
|
|
259
|
+
value: void 0
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(this, "limit", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
configurable: true,
|
|
264
|
+
writable: true,
|
|
265
|
+
value: void 0
|
|
266
|
+
});
|
|
267
|
+
Object.defineProperty(this, "completeness", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
configurable: true,
|
|
270
|
+
writable: true,
|
|
271
|
+
value: void 0
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(this, "results", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
configurable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
value: void 0
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(this, "crawls", {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
configurable: true,
|
|
282
|
+
writable: true,
|
|
283
|
+
value: void 0
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(this, "skipped", {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
configurable: true,
|
|
288
|
+
writable: true,
|
|
289
|
+
value: void 0
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(this, "stats", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
configurable: true,
|
|
294
|
+
writable: true,
|
|
295
|
+
value: void 0
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(this, "crawls_requested", {
|
|
298
|
+
enumerable: true,
|
|
299
|
+
configurable: true,
|
|
300
|
+
writable: true,
|
|
301
|
+
value: void 0
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(this, "crawls_searched", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
configurable: true,
|
|
306
|
+
writable: true,
|
|
307
|
+
value: void 0
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(this, "crawls_pruned_exact", {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
configurable: true,
|
|
312
|
+
writable: true,
|
|
313
|
+
value: void 0
|
|
314
|
+
});
|
|
315
|
+
/**
|
|
316
|
+
* The crawls the deadline cut, and the crawls whose index could not be read,
|
|
317
|
+
* named rather than counted: a caller told "3 failed" cannot retry them.
|
|
318
|
+
*/
|
|
319
|
+
Object.defineProperty(this, "crawls_skipped_deadline", {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
configurable: true,
|
|
322
|
+
writable: true,
|
|
323
|
+
value: void 0
|
|
324
|
+
});
|
|
325
|
+
Object.defineProperty(this, "crawls_failed", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
configurable: true,
|
|
328
|
+
writable: true,
|
|
329
|
+
value: void 0
|
|
330
|
+
});
|
|
331
|
+
/**
|
|
332
|
+
* `null` until a crawl has actually been opened. Zero is a different claim:
|
|
333
|
+
* it says the best unsearched score was 0, not that no bound exists.
|
|
334
|
+
*/
|
|
335
|
+
Object.defineProperty(this, "theta", {
|
|
336
|
+
enumerable: true,
|
|
337
|
+
configurable: true,
|
|
338
|
+
writable: true,
|
|
339
|
+
value: void 0
|
|
340
|
+
});
|
|
341
|
+
Object.defineProperty(this, "max_ub_unsearched", {
|
|
342
|
+
enumerable: true,
|
|
343
|
+
configurable: true,
|
|
344
|
+
writable: true,
|
|
345
|
+
value: void 0
|
|
346
|
+
});
|
|
347
|
+
/**
|
|
348
|
+
* Opaque token for the next page, `null` on the last one. Paging is
|
|
349
|
+
* cursor-based: an offset over a partial fan-out would re-run the legs and
|
|
350
|
+
* shift ranks.
|
|
351
|
+
*/
|
|
352
|
+
Object.defineProperty(this, "cursor", {
|
|
353
|
+
enumerable: true,
|
|
354
|
+
configurable: true,
|
|
355
|
+
writable: true,
|
|
356
|
+
value: void 0
|
|
357
|
+
});
|
|
358
|
+
this.query = requireField(data, 'query', 'string', 'CrawlerSearchResponse');
|
|
359
|
+
this.mode = requireField(data, 'mode', 'string', 'CrawlerSearchResponse');
|
|
360
|
+
this.limit = requireField(data, 'limit', 'number', 'CrawlerSearchResponse');
|
|
361
|
+
this.completeness = requireField(data, 'completeness', 'string', 'CrawlerSearchResponse');
|
|
362
|
+
const results = requireField(data, 'results', 'array', 'CrawlerSearchResponse');
|
|
363
|
+
this.results = results.map((r, i) => {
|
|
364
|
+
const context = `CrawlerSearchResponse.results[${i}]`;
|
|
365
|
+
return {
|
|
366
|
+
rank: requireField(r, 'rank', 'number', context),
|
|
367
|
+
score: requireField(r, 'score', 'number', context),
|
|
368
|
+
scores: optionalField(r, 'scores', 'object', context) ?? {},
|
|
369
|
+
crawler_uuid: requireField(r, 'crawler_uuid', 'string', context),
|
|
370
|
+
url: requireField(r, 'url', 'string', context),
|
|
371
|
+
title: optionalField(r, 'title', 'string', context),
|
|
372
|
+
source_format: optionalField(r, 'source_format', 'string', context),
|
|
373
|
+
content_type: optionalField(r, 'content_type', 'string', context),
|
|
374
|
+
chunk_id: requireField(r, 'chunk_id', 'number', context),
|
|
375
|
+
text: requireField(r, 'text', 'string', context),
|
|
376
|
+
warc_offset: optionalField(r, 'warc_offset', 'number', context),
|
|
377
|
+
warc_end: optionalField(r, 'warc_end', 'number', context),
|
|
378
|
+
contents_url: optionalField(r, 'contents_url', 'string', context),
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
this.crawls = optionalField(data, 'crawls', 'array', 'CrawlerSearchResponse') ?? [];
|
|
382
|
+
this.skipped = optionalField(data, 'skipped', 'array', 'CrawlerSearchResponse') ?? [];
|
|
383
|
+
this.stats = optionalField(data, 'stats', 'object', 'CrawlerSearchResponse') ?? {};
|
|
384
|
+
this.crawls_requested = optionalField(data, 'crawls_requested', 'number', 'CrawlerSearchResponse');
|
|
385
|
+
this.crawls_searched = optionalField(data, 'crawls_searched', 'number', 'CrawlerSearchResponse');
|
|
386
|
+
this.crawls_pruned_exact = optionalField(data, 'crawls_pruned_exact', 'number', 'CrawlerSearchResponse');
|
|
387
|
+
this.crawls_skipped_deadline = optionalField(data, 'crawls_skipped_deadline', 'array', 'CrawlerSearchResponse');
|
|
388
|
+
this.crawls_failed = optionalField(data, 'crawls_failed', 'array', 'CrawlerSearchResponse');
|
|
389
|
+
this.theta = optionalField(data, 'theta', 'number', 'CrawlerSearchResponse');
|
|
390
|
+
this.max_ub_unsearched = optionalField(data, 'max_ub_unsearched', 'number', 'CrawlerSearchResponse');
|
|
391
|
+
this.cursor = optionalField(data, 'cursor', 'string', 'CrawlerSearchResponse');
|
|
392
|
+
}
|
|
393
|
+
/** True when the ranking is provably complete for the requested crawls. */
|
|
394
|
+
get isExact() {
|
|
395
|
+
return this.completeness === 'exact';
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
exports.CrawlerSearchResponse = CrawlerSearchResponse;
|
|
399
|
+
/**
|
|
400
|
+
* Decode the `POST /crawl/prompt` SSE body into typed frames.
|
|
401
|
+
*
|
|
402
|
+
* Only `event:` and `data:` lines matter; `:keepalive` comment frames exist
|
|
403
|
+
* to keep intermediaries from closing an idle connection and carry nothing.
|
|
404
|
+
* Token payloads are JSON strings; every other frame is a JSON object.
|
|
405
|
+
*
|
|
406
|
+
* An `event: error` frame throws rather than yields: the caller is already
|
|
407
|
+
* inside a `for await` and a yielded error object is too easy to ignore after
|
|
408
|
+
* tokens have started arriving.
|
|
409
|
+
*
|
|
410
|
+
* Decoding is explicitly UTF-8 with `stream: true`, because a multi-byte
|
|
411
|
+
* character can straddle two chunks of the body.
|
|
412
|
+
* EOF before a complete `done` frame throws, even after tokens were delivered.
|
|
413
|
+
*/
|
|
414
|
+
async function* parseCrawlerPromptStream(body) {
|
|
415
|
+
const reader = body.getReader();
|
|
416
|
+
const decoder = new TextDecoder('utf-8');
|
|
417
|
+
let buffer = '';
|
|
418
|
+
let eventName = '';
|
|
419
|
+
let data = [];
|
|
420
|
+
const decodeFrame = (name, raw) => {
|
|
421
|
+
if (name === 'token') {
|
|
422
|
+
let token;
|
|
423
|
+
try {
|
|
424
|
+
token = JSON.parse(raw);
|
|
425
|
+
}
|
|
426
|
+
catch {
|
|
427
|
+
// A server sending bare text instead of a JSON string is still
|
|
428
|
+
// sending a token; do not drop the answer over the quoting.
|
|
429
|
+
token = raw;
|
|
430
|
+
}
|
|
431
|
+
return { event: 'token', data: token };
|
|
432
|
+
}
|
|
433
|
+
if (name === 'source') {
|
|
434
|
+
return { event: 'source', data: JSON.parse(raw) };
|
|
435
|
+
}
|
|
436
|
+
if (name === 'done') {
|
|
437
|
+
const payload = JSON.parse(raw);
|
|
438
|
+
// Build the public result explicitly: a TypeScript cast does not remove
|
|
439
|
+
// legacy model, token or provider-cost fields from the runtime object.
|
|
440
|
+
return {
|
|
441
|
+
event: 'done',
|
|
442
|
+
data: {
|
|
443
|
+
sources_used: optionalField(payload, 'sources_used', 'array', 'CrawlerPromptDone') ?? undefined,
|
|
444
|
+
sources_dropped: optionalField(payload, 'sources_dropped', 'number', 'CrawlerPromptDone') ?? undefined,
|
|
445
|
+
truncated: optionalField(payload, 'truncated', 'boolean', 'CrawlerPromptDone') ?? undefined,
|
|
446
|
+
api_credit: optionalField(payload, 'api_credit', 'number', 'CrawlerPromptDone') ?? undefined,
|
|
447
|
+
},
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
if (name === 'error') {
|
|
451
|
+
let payload = {};
|
|
452
|
+
try {
|
|
453
|
+
payload = JSON.parse(raw);
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
payload = { message: raw };
|
|
457
|
+
}
|
|
458
|
+
throw new errors_js_1.ScrapflyCrawlerError(payload.message ?? raw, {
|
|
459
|
+
code: (payload.code ?? 'ERR::CRAWLER::UNKNOWN'),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return null;
|
|
463
|
+
};
|
|
464
|
+
try {
|
|
465
|
+
for (;;) {
|
|
466
|
+
const { done, value } = await reader.read();
|
|
467
|
+
if (value !== undefined) {
|
|
468
|
+
buffer += decoder.decode(value, { stream: true });
|
|
469
|
+
}
|
|
470
|
+
if (done) {
|
|
471
|
+
buffer += decoder.decode();
|
|
472
|
+
}
|
|
473
|
+
let newline = buffer.indexOf('\n');
|
|
474
|
+
while (newline !== -1) {
|
|
475
|
+
const line = buffer.slice(0, newline).replace(/\r$/, '');
|
|
476
|
+
buffer = buffer.slice(newline + 1);
|
|
477
|
+
newline = buffer.indexOf('\n');
|
|
478
|
+
if (line.startsWith(':'))
|
|
479
|
+
continue;
|
|
480
|
+
// A blank line terminates a frame.
|
|
481
|
+
if (line === '') {
|
|
482
|
+
if (eventName !== '' && data.length > 0) {
|
|
483
|
+
const event = decodeFrame(eventName, data.join('\n'));
|
|
484
|
+
if (event !== null) {
|
|
485
|
+
yield event;
|
|
486
|
+
if (event.event === 'done')
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
eventName = '';
|
|
491
|
+
data = [];
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
if (line.startsWith('event:')) {
|
|
495
|
+
eventName = line.slice('event:'.length).trim();
|
|
496
|
+
}
|
|
497
|
+
else if (line.startsWith('data:')) {
|
|
498
|
+
data.push(line.slice('data:'.length).replace(/^ /, ''));
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (done) {
|
|
502
|
+
throw new errors_js_1.ScrapflyCrawlerError('Prompt stream ended before the done frame', {
|
|
503
|
+
code: 'ERR::CRAWLER::PROMPT_GENERATION_FAILED',
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
finally {
|
|
509
|
+
// Covers both exhaustion and an early `break` out of the caller's loop.
|
|
510
|
+
await reader.cancel().catch(() => { });
|
|
511
|
+
}
|
|
512
|
+
}
|
|
144
513
|
/**
|
|
145
514
|
* Wraps the streaming text response of `GET /crawl/{uuid}/urls`.
|
|
146
515
|
*
|
|
@@ -325,7 +694,10 @@ function parseCrawlerWebhook(body) {
|
|
|
325
694
|
event === 'crawler_url_visited' ||
|
|
326
695
|
event === 'crawler_url_skipped' ||
|
|
327
696
|
event === 'crawler_url_discovered' ||
|
|
328
|
-
event === 'crawler_url_failed'
|
|
697
|
+
event === 'crawler_url_failed' ||
|
|
698
|
+
event === 'crawler_search_ready' ||
|
|
699
|
+
event === 'crawler_search_failed' ||
|
|
700
|
+
event === 'crawler_updated') {
|
|
329
701
|
// The body has already been validated to have an `event` and `payload`. The
|
|
330
702
|
// narrower per-event field shapes are runtime-checked by the discriminated union
|
|
331
703
|
// — TypeScript users get the typed view; runtime users get a permissive bag.
|
package/script/errors.d.ts
CHANGED
|
@@ -68,6 +68,18 @@ export declare class ScrapflyThrottleError extends HttpError {
|
|
|
68
68
|
/** Raised when Scrapfly failed to bypass anti-scraping protection on the target. */
|
|
69
69
|
export declare class ScrapflyAspError extends HttpError {
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Raised when the unblocker (formerly "ASP") could not get through the target's
|
|
73
|
+
* anti-bot protection.
|
|
74
|
+
*
|
|
75
|
+
* This is the SAME class as {@link ScrapflyAspError}, not a subclass and not a
|
|
76
|
+
* second class, so `instanceof ScrapflyUnblockerError` and `instanceof
|
|
77
|
+
* ScrapflyAspError` are interchangeable and customer code written against
|
|
78
|
+
* either name keeps working. The class is still selected by the literal `ASP`
|
|
79
|
+
* segment of the `ERR::ASP::*` codes the API sends.
|
|
80
|
+
*/
|
|
81
|
+
export declare const ScrapflyUnblockerError: typeof ScrapflyAspError;
|
|
82
|
+
export type ScrapflyUnblockerError = ScrapflyAspError;
|
|
71
83
|
/** Raised when a scheduled scrape cannot be created or fulfilled. */
|
|
72
84
|
export declare class ScrapflyScheduleError extends HttpError {
|
|
73
85
|
}
|
package/script/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,+FAA+F;IAC/F,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE1B;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;CAI5D;AAED,yEAAyE;AACzE,qBAAa,iBAAkB,SAAQ,aAAa;CAAG;AACvD,6EAA6E;AAC7E,qBAAa,qBAAsB,SAAQ,aAAa;CAAG;AAC3D,8EAA8E;AAC9E,qBAAa,qBAAsB,SAAQ,aAAa;CAAG;AAC3D,0EAA0E;AAC1E,qBAAa,kBAAmB,SAAQ,aAAa;CAAG;AAExD,sEAAsE;AACtE,qBAAa,WAAY,SAAQ,aAAa;CAAG;AACjD,gFAAgF;AAChF,qBAAa,gBAAiB,SAAQ,aAAa;CAAG;AAEtD,mEAAmE;AACnE,qBAAa,SAAU,SAAQ,aAAa;CAAG;AAC/C,qEAAqE;AACrE,qBA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AG,gBAAgB,CAAC;AACtD,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/script/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ScrapflyCrawlerError = exports.ExtractionApiError = exports.ScreenshotApiError = exports.QuotaLimitReached = exports.TooManyConcurrentRequests = exports.ScrapflySessionError = exports.ScrapflyWebhookError = exports.ScrapflyScheduleError = exports.ScrapflyAspError = exports.ScrapflyThrottleError = exports.ScrapflyProxyError = exports.ScrapflyScrapeError = exports.ApiHttpServerError = exports.TooManyRequests = exports.BadApiKeyError = exports.ApiHttpClientError = exports.UpstreamHttpServerError = exports.UpstreamHttpClientError = exports.UpstreamHttpError = exports.HttpError = exports.ContentTypeError = exports.EncodeError = exports.CrawlerConfigError = exports.ExtractionConfigError = exports.ScreenshotConfigError = exports.ScrapeConfigError = exports.ScrapflyError = void 0;
|
|
3
|
+
exports.ScrapflyCrawlerError = exports.ExtractionApiError = exports.ScreenshotApiError = exports.QuotaLimitReached = exports.TooManyConcurrentRequests = exports.ScrapflySessionError = exports.ScrapflyWebhookError = exports.ScrapflyScheduleError = exports.ScrapflyUnblockerError = exports.ScrapflyAspError = exports.ScrapflyThrottleError = exports.ScrapflyProxyError = exports.ScrapflyScrapeError = exports.ApiHttpServerError = exports.TooManyRequests = exports.BadApiKeyError = exports.ApiHttpClientError = exports.UpstreamHttpServerError = exports.UpstreamHttpClientError = exports.UpstreamHttpError = exports.HttpError = exports.ContentTypeError = exports.EncodeError = exports.CrawlerConfigError = exports.ExtractionConfigError = exports.ScreenshotConfigError = exports.ScrapeConfigError = exports.ScrapflyError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Base class for every error thrown by the Scrapfly SDK.
|
|
6
6
|
*
|
|
@@ -98,6 +98,17 @@ exports.ScrapflyThrottleError = ScrapflyThrottleError;
|
|
|
98
98
|
class ScrapflyAspError extends HttpError {
|
|
99
99
|
}
|
|
100
100
|
exports.ScrapflyAspError = ScrapflyAspError;
|
|
101
|
+
/**
|
|
102
|
+
* Raised when the unblocker (formerly "ASP") could not get through the target's
|
|
103
|
+
* anti-bot protection.
|
|
104
|
+
*
|
|
105
|
+
* This is the SAME class as {@link ScrapflyAspError}, not a subclass and not a
|
|
106
|
+
* second class, so `instanceof ScrapflyUnblockerError` and `instanceof
|
|
107
|
+
* ScrapflyAspError` are interchangeable and customer code written against
|
|
108
|
+
* either name keeps working. The class is still selected by the literal `ASP`
|
|
109
|
+
* segment of the `ERR::ASP::*` codes the API sends.
|
|
110
|
+
*/
|
|
111
|
+
exports.ScrapflyUnblockerError = ScrapflyAspError;
|
|
101
112
|
/** Raised when a scheduled scrape cannot be created or fulfilled. */
|
|
102
113
|
class ScrapflyScheduleError extends HttpError {
|
|
103
114
|
}
|
package/script/main.d.ts
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* const client = new ScrapflyClient({ key: 'your-api-key' });
|
|
14
14
|
* const result = await client.scrape(new ScrapeConfig({
|
|
15
15
|
* url: 'https://web-scraping.dev/products',
|
|
16
|
-
*
|
|
17
|
-
* asp: true,
|
|
16
|
+
* proxy_pool: ScrapeConfig.UNBLOCKER,
|
|
18
17
|
* }));
|
|
19
18
|
* console.log(result.content);
|
|
20
19
|
* ```
|
|
@@ -30,19 +29,25 @@ export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotCon
|
|
|
30
29
|
export { ExtractionConfig } from './extractionconfig.js';
|
|
31
30
|
export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
|
|
32
31
|
export type { BrowserConfigOptions } from './browserconfig.js';
|
|
33
|
-
export
|
|
34
|
-
|
|
32
|
+
export { BrowserDownloadError, CloudBrowserDownloads, parseDownloads } from './browserdownloads.js';
|
|
33
|
+
export type { BrowserDownload, CdpSend, CdpSession, CloudBrowserDownloadsOptions, WaitForOptions } from './browserdownloads.js';
|
|
34
|
+
export { VaultLinkedService } from './types.js';
|
|
35
|
+
export type { Vault, VaultItem, VaultItemCreate, VaultLinkedServiceValue, VaultItemSource, VaultItemType, VaultOnePasswordData, VaultProbeResult, VaultProbeVault, VaultSecret, VaultServiceLink, VaultServiceUpdate, VaultSyncCounts, VaultSyncMode, VaultSyncReport, VaultSyncStatus, VaultType, } from './types.js';
|
|
36
|
+
/**
|
|
37
|
+
* Namespace of the API error classes, {@link ScrapflyError} and its subclasses: `errors.ScrapflyAspError`.
|
|
38
|
+
* `BrowserDownloadError` and `ScheduleAPIError` are exported at the root.
|
|
39
|
+
*/
|
|
35
40
|
export * as errors from './errors.js';
|
|
36
41
|
export { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
|
|
37
42
|
export type { AccountData, ClassifyOptions, ClassifyResult, ConfigData, ContextData, ResultData, ScreenshotMetadata } from './result.js';
|
|
38
43
|
export { CrawlerConfig } from './crawlerconfig.js';
|
|
39
44
|
export type { CrawlerConfigOptions, CrawlerContentFormat, CrawlerWebhookEventName } from './crawlerconfig.js';
|
|
40
45
|
export { Crawl } from './crawl.js';
|
|
41
|
-
export { CrawlerArtifact, CrawlerContents, CrawlerStatus, CrawlerUrls, parseCrawlerWebhook, } from './crawlerresult.js';
|
|
42
|
-
export type { CrawlerArtifactType, CrawlerLifecycleWebhook, CrawlerState, CrawlerStatusValue, CrawlerStopReason, CrawlerUrlDiscoveredWebhook, CrawlerUrlEntry, CrawlerUrlFailedWebhook, CrawlerUrlSkippedWebhook, CrawlerUrlVisitedWebhook, CrawlerWebhookCommon, CrawlerWebhookPayload, } from './crawlerresult.js';
|
|
46
|
+
export { CrawlerArtifact, CrawlerContents, CrawlerSearchResponse, CrawlerStatus, CrawlerUrls, isSearchable, parseCrawlerPromptStream, parseCrawlerRefreshState, parseCrawlerSearchState, parseCrawlerWebhook, refreshChanged, } from './crawlerresult.js';
|
|
47
|
+
export type { CrawlerArtifactType, CrawlerExtractResponse, CrawlerLifecycleWebhook, CrawlerPromptAnswer, CrawlerPromptDone, CrawlerPromptEvent, CrawlerPromptSearch, CrawlerPromptSource, CrawlerRefreshEntry, CrawlerRefreshState, CrawlerRefreshStatus, CrawlerSearchCrawl, CrawlerSearchMode, CrawlerSearchResult, CrawlerSearchScores, CrawlerSearchSkipped, CrawlerSearchState, CrawlerSearchStats, CrawlerSearchStatus, CrawlerSearchWebhook, CrawlerSkipReason, CrawlerState, CrawlerStatusValue, CrawlerStopReason, CrawlerUpdatedWebhook, CrawlerUrlDiscoveredWebhook, CrawlerUrlEntry, CrawlerUrlFailedWebhook, CrawlerUrlSkippedWebhook, CrawlerUrlVisitedWebhook, CrawlerWebhookCommon, CrawlerWebhookPayload, } from './crawlerresult.js';
|
|
43
48
|
export type { CloudBrowserMonitoringOptions, MonitoringAggregation, MonitoringDataFormat, MonitoringMetricsOptions, MonitoringPeriod, MonitoringTargetMetricsOptions, } from './monitoringconfig.js';
|
|
44
49
|
export { ScheduleAPIError } from './schedule.js';
|
|
45
50
|
export type { CreateScheduleRequest, ListSchedulesOptions, Schedule, ScheduleEnd, ScheduleRecurrence, UpdateScheduleRequest, } from './schedule.js';
|
|
46
51
|
export { log } from './logger.js';
|
|
47
|
-
export { createServer, verifySignature } from './webhookserver.js';
|
|
52
|
+
export { createServer, ResourceType, verifySignature } from './webhookserver.js';
|
|
48
53
|
//# sourceMappingURL=main.d.ts.map
|
package/script/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,MAAM,IAAI,YAAY,EACtB,YAAY,IAAI,mBAAmB,EACnC,YAAY,EACZ,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,MAAM,IAAI,gBAAgB,EAC1B,OAAO,IAAI,iBAAiB,EAC5B,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/E,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpG,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEhI,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,YAAY,EACV,KAAK,EACL,SAAS,EACT,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,SAAS,GACV,MAAM,YAAY,CAAC;AACpB;;;GAGG;AACH,OAAO,KAAK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AgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/script/main.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.verifySignature = exports.createServer = exports.log = exports.ScheduleAPIError = exports.parseCrawlerWebhook = exports.CrawlerUrls = exports.CrawlerStatus = exports.CrawlerContents = exports.CrawlerArtifact = exports.Crawl = exports.CrawlerConfig = exports.ScreenshotResult = exports.ScrapeResult = exports.ExtractionResult = exports.errors = exports.OperatingSystem = exports.ProxyPool = exports.BrowserConfig = exports.ExtractionConfig = exports.VisionDeficiency = exports.ScreenshotConfig = exports.ScreenshotOptions = exports.ScreenshotFormat = exports.ScreenshotFlags = exports.ScrapeConfig = exports.ScrapeFormatOptions = exports.ScrapeFormat = exports.ScrapflyClient = void 0;
|
|
26
|
+
exports.verifySignature = exports.ResourceType = exports.createServer = exports.log = exports.ScheduleAPIError = exports.refreshChanged = exports.parseCrawlerWebhook = exports.parseCrawlerSearchState = exports.parseCrawlerRefreshState = exports.parseCrawlerPromptStream = exports.isSearchable = exports.CrawlerUrls = exports.CrawlerStatus = exports.CrawlerSearchResponse = exports.CrawlerContents = exports.CrawlerArtifact = exports.Crawl = exports.CrawlerConfig = exports.ScreenshotResult = exports.ScrapeResult = exports.ExtractionResult = exports.errors = exports.VaultLinkedService = exports.parseDownloads = exports.CloudBrowserDownloads = exports.BrowserDownloadError = exports.OperatingSystem = exports.ProxyPool = exports.BrowserConfig = exports.ExtractionConfig = exports.VisionDeficiency = exports.ScreenshotConfig = exports.ScreenshotOptions = exports.ScreenshotFormat = exports.ScreenshotFlags = exports.ScrapeConfig = exports.ScrapeFormatOptions = exports.ScrapeFormat = exports.ScrapflyClient = void 0;
|
|
27
27
|
/**
|
|
28
28
|
* # Scrapfly SDK for TypeScript / JavaScript
|
|
29
29
|
*
|
|
@@ -39,8 +39,7 @@ exports.verifySignature = exports.createServer = exports.log = exports.ScheduleA
|
|
|
39
39
|
* const client = new ScrapflyClient({ key: 'your-api-key' });
|
|
40
40
|
* const result = await client.scrape(new ScrapeConfig({
|
|
41
41
|
* url: 'https://web-scraping.dev/products',
|
|
42
|
-
*
|
|
43
|
-
* asp: true,
|
|
42
|
+
* proxy_pool: ScrapeConfig.UNBLOCKER,
|
|
44
43
|
* }));
|
|
45
44
|
* console.log(result.content);
|
|
46
45
|
* ```
|
|
@@ -68,7 +67,17 @@ var browserconfig_js_1 = require("./browserconfig.js");
|
|
|
68
67
|
Object.defineProperty(exports, "BrowserConfig", { enumerable: true, get: function () { return browserconfig_js_1.BrowserConfig; } });
|
|
69
68
|
Object.defineProperty(exports, "ProxyPool", { enumerable: true, get: function () { return browserconfig_js_1.ProxyPool; } });
|
|
70
69
|
Object.defineProperty(exports, "OperatingSystem", { enumerable: true, get: function () { return browserconfig_js_1.OperatingSystem; } });
|
|
71
|
-
|
|
70
|
+
var browserdownloads_js_1 = require("./browserdownloads.js");
|
|
71
|
+
Object.defineProperty(exports, "BrowserDownloadError", { enumerable: true, get: function () { return browserdownloads_js_1.BrowserDownloadError; } });
|
|
72
|
+
Object.defineProperty(exports, "CloudBrowserDownloads", { enumerable: true, get: function () { return browserdownloads_js_1.CloudBrowserDownloads; } });
|
|
73
|
+
Object.defineProperty(exports, "parseDownloads", { enumerable: true, get: function () { return browserdownloads_js_1.parseDownloads; } });
|
|
74
|
+
// Enum, hence a value export: callers name VaultLinkedService.ONE_PASSWORD.
|
|
75
|
+
var types_js_1 = require("./types.js");
|
|
76
|
+
Object.defineProperty(exports, "VaultLinkedService", { enumerable: true, get: function () { return types_js_1.VaultLinkedService; } });
|
|
77
|
+
/**
|
|
78
|
+
* Namespace of the API error classes, {@link ScrapflyError} and its subclasses: `errors.ScrapflyAspError`.
|
|
79
|
+
* `BrowserDownloadError` and `ScheduleAPIError` are exported at the root.
|
|
80
|
+
*/
|
|
72
81
|
exports.errors = __importStar(require("./errors.js"));
|
|
73
82
|
var result_js_1 = require("./result.js");
|
|
74
83
|
Object.defineProperty(exports, "ExtractionResult", { enumerable: true, get: function () { return result_js_1.ExtractionResult; } });
|
|
@@ -82,13 +91,20 @@ Object.defineProperty(exports, "Crawl", { enumerable: true, get: function () { r
|
|
|
82
91
|
var crawlerresult_js_1 = require("./crawlerresult.js");
|
|
83
92
|
Object.defineProperty(exports, "CrawlerArtifact", { enumerable: true, get: function () { return crawlerresult_js_1.CrawlerArtifact; } });
|
|
84
93
|
Object.defineProperty(exports, "CrawlerContents", { enumerable: true, get: function () { return crawlerresult_js_1.CrawlerContents; } });
|
|
94
|
+
Object.defineProperty(exports, "CrawlerSearchResponse", { enumerable: true, get: function () { return crawlerresult_js_1.CrawlerSearchResponse; } });
|
|
85
95
|
Object.defineProperty(exports, "CrawlerStatus", { enumerable: true, get: function () { return crawlerresult_js_1.CrawlerStatus; } });
|
|
86
96
|
Object.defineProperty(exports, "CrawlerUrls", { enumerable: true, get: function () { return crawlerresult_js_1.CrawlerUrls; } });
|
|
97
|
+
Object.defineProperty(exports, "isSearchable", { enumerable: true, get: function () { return crawlerresult_js_1.isSearchable; } });
|
|
98
|
+
Object.defineProperty(exports, "parseCrawlerPromptStream", { enumerable: true, get: function () { return crawlerresult_js_1.parseCrawlerPromptStream; } });
|
|
99
|
+
Object.defineProperty(exports, "parseCrawlerRefreshState", { enumerable: true, get: function () { return crawlerresult_js_1.parseCrawlerRefreshState; } });
|
|
100
|
+
Object.defineProperty(exports, "parseCrawlerSearchState", { enumerable: true, get: function () { return crawlerresult_js_1.parseCrawlerSearchState; } });
|
|
87
101
|
Object.defineProperty(exports, "parseCrawlerWebhook", { enumerable: true, get: function () { return crawlerresult_js_1.parseCrawlerWebhook; } });
|
|
102
|
+
Object.defineProperty(exports, "refreshChanged", { enumerable: true, get: function () { return crawlerresult_js_1.refreshChanged; } });
|
|
88
103
|
var schedule_js_1 = require("./schedule.js");
|
|
89
104
|
Object.defineProperty(exports, "ScheduleAPIError", { enumerable: true, get: function () { return schedule_js_1.ScheduleAPIError; } });
|
|
90
105
|
var logger_js_1 = require("./logger.js");
|
|
91
106
|
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logger_js_1.log; } });
|
|
92
107
|
var webhookserver_js_1 = require("./webhookserver.js");
|
|
93
108
|
Object.defineProperty(exports, "createServer", { enumerable: true, get: function () { return webhookserver_js_1.createServer; } });
|
|
109
|
+
Object.defineProperty(exports, "ResourceType", { enumerable: true, get: function () { return webhookserver_js_1.ResourceType; } });
|
|
94
110
|
Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return webhookserver_js_1.verifySignature; } });
|
|
@@ -53,8 +53,8 @@ export interface CloudBrowserMonitoringOptions {
|
|
|
53
53
|
/** Time window to aggregate over. */
|
|
54
54
|
period?: MonitoringPeriod;
|
|
55
55
|
/**
|
|
56
|
-
* Optional filter to a single proxy pool
|
|
57
|
-
*
|
|
56
|
+
* Optional filter to a single proxy pool, as the runs record it:
|
|
57
|
+
* `datacenter`, `residential`, `tor` or `byop`.
|
|
58
58
|
*/
|
|
59
59
|
proxyPool?: string;
|
|
60
60
|
/** Window start. */
|
package/script/result.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export type ConfigData = {
|
|
|
14
14
|
debug: boolean;
|
|
15
15
|
raise_on_upstream_error: boolean;
|
|
16
16
|
cache_ttl: number;
|
|
17
|
+
/**
|
|
18
|
+
* The pool the request asked for, the way the account reads it: Tor reads `public_tor_pool` and one of the
|
|
19
|
+
* account's own pools its name. Otherwise, when the Unblocker ran (asked, or forced by a target that requires
|
|
20
|
+
* it), `basic` and `unblocker` read `unblocker` and any other pool `unblocker_ultra`. Without the Unblocker a
|
|
21
|
+
* Scrapfly pool reads by its network (`basic`, `unblocker`, `mobile`, `isp`) and any other name as sent.
|
|
22
|
+
* `context.proxy.pool` reads the same.
|
|
23
|
+
*/
|
|
17
24
|
proxy_pool: string;
|
|
18
25
|
session?: string;
|
|
19
26
|
tags: Set<string>;
|
|
@@ -74,6 +81,7 @@ export type ContextData = {
|
|
|
74
81
|
country: string;
|
|
75
82
|
identity: string;
|
|
76
83
|
network: string;
|
|
84
|
+
/** The same name as {@link ConfigData.proxy_pool}. */
|
|
77
85
|
pool: string;
|
|
78
86
|
};
|
|
79
87
|
redirects: Array<string>;
|
|
@@ -293,7 +301,9 @@ export declare class ScreenshotResult {
|
|
|
293
301
|
image: ArrayBuffer;
|
|
294
302
|
metadata: ScreenshotMetadata;
|
|
295
303
|
result: object | null;
|
|
296
|
-
|
|
304
|
+
/** The job of a screenshot with a webhook: the image is delivered to the webhook, `image` and `metadata` are empty. */
|
|
305
|
+
job_uuid: string | null;
|
|
306
|
+
constructor(response: Response, data: ArrayBuffer, job_uuid?: string | null);
|
|
297
307
|
private defineMetadata;
|
|
298
308
|
private decodeResponse;
|
|
299
309
|
}
|