scrapfly-sdk 0.7.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/browserconfig.d.ts +59 -0
- package/esm/browserconfig.d.ts.map +1 -0
- package/esm/browserconfig.js +207 -0
- package/esm/client.d.ts +193 -1
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +786 -5
- package/esm/crawl.d.ts +118 -0
- package/esm/crawl.d.ts.map +1 -0
- package/esm/crawl.js +230 -0
- package/esm/crawlerconfig.d.ts +119 -0
- package/esm/crawlerconfig.d.ts.map +1 -0
- package/esm/crawlerconfig.js +398 -0
- package/esm/crawlerresult.d.ts +253 -0
- package/esm/crawlerresult.d.ts.map +1 -0
- package/esm/crawlerresult.js +327 -0
- package/esm/errors.d.ts +4 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +6 -0
- package/esm/extractionconfig.d.ts +2 -0
- package/esm/extractionconfig.d.ts.map +1 -1
- package/esm/extractionconfig.js +10 -0
- package/esm/main.d.ts +8 -1
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +6 -1
- package/esm/polyfill.d.ts +2 -0
- package/esm/polyfill.d.ts.map +1 -1
- package/esm/polyfill.js +12 -0
- package/esm/scrapeconfig.d.ts +27 -0
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +44 -1
- package/esm/screenshotconfig.d.ts +2 -2
- package/esm/screenshotconfig.d.ts.map +1 -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 +59 -0
- package/script/browserconfig.d.ts.map +1 -0
- package/script/browserconfig.js +211 -0
- package/script/client.d.ts +193 -1
- package/script/client.d.ts.map +1 -1
- package/script/client.js +785 -4
- package/script/crawl.d.ts +118 -0
- package/script/crawl.d.ts.map +1 -0
- package/script/crawl.js +257 -0
- package/script/crawlerconfig.d.ts +119 -0
- package/script/crawlerconfig.d.ts.map +1 -0
- package/script/crawlerconfig.js +402 -0
- package/script/crawlerresult.d.ts +253 -0
- package/script/crawlerresult.d.ts.map +1 -0
- package/script/crawlerresult.js +335 -0
- package/script/errors.d.ts +4 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +9 -1
- package/script/extractionconfig.d.ts +2 -0
- package/script/extractionconfig.d.ts.map +1 -1
- package/script/extractionconfig.js +10 -0
- package/script/main.d.ts +8 -1
- package/script/main.d.ts.map +1 -1
- package/script/main.js +17 -1
- package/script/polyfill.d.ts +2 -0
- package/script/polyfill.d.ts.map +1 -1
- package/script/polyfill.js +14 -1
- package/script/scrapeconfig.d.ts +27 -0
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +44 -1
- package/script/screenshotconfig.d.ts +2 -2
- package/script/screenshotconfig.d.ts.map +1 -1
- package/script/utils.d.ts.map +1 -1
- package/script/utils.js +16 -2
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { writeFile } from './polyfill.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pull a required field out of an API response body and fail loud if it's
|
|
4
|
+
* missing or the wrong type. Using this consistently across the response
|
|
5
|
+
* classes means a server-side contract change surfaces as a clear error at
|
|
6
|
+
* parse time instead of a silent fallback to 0/null/empty later.
|
|
7
|
+
*/
|
|
8
|
+
function requireField(data, key, typeName, contextClass) {
|
|
9
|
+
if (!(key in data)) {
|
|
10
|
+
throw new Error(`${contextClass}: required field '${key}' is missing from API response`);
|
|
11
|
+
}
|
|
12
|
+
const value = data[key];
|
|
13
|
+
if (value === null || value === undefined) {
|
|
14
|
+
throw new Error(`${contextClass}: required field '${key}' is null/undefined`);
|
|
15
|
+
}
|
|
16
|
+
const actual = Array.isArray(value) ? 'array' : typeof value;
|
|
17
|
+
if (typeName === 'array' ? actual !== 'array' : actual !== typeName) {
|
|
18
|
+
throw new Error(`${contextClass}: field '${key}' must be ${typeName}, got ${actual} (${JSON.stringify(value).slice(0, 100)})`);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Like `requireField` but for optional fields that the server may legitimately
|
|
24
|
+
* omit or send as `null`. Returns `null` when absent; validates type otherwise.
|
|
25
|
+
*/
|
|
26
|
+
function optionalField(data, key, typeName, contextClass) {
|
|
27
|
+
if (!(key in data))
|
|
28
|
+
return null;
|
|
29
|
+
const value = data[key];
|
|
30
|
+
if (value === null || value === undefined)
|
|
31
|
+
return null;
|
|
32
|
+
const actual = Array.isArray(value) ? 'array' : typeof value;
|
|
33
|
+
if (typeName === 'array' ? actual !== 'array' : actual !== typeName) {
|
|
34
|
+
throw new Error(`${contextClass}: field '${key}' must be ${typeName} or null, got ${actual}`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Wraps the JSON response of `GET /crawl/{uuid}/status`.
|
|
40
|
+
*
|
|
41
|
+
* Strict parsing: every field documented in the public API contract is
|
|
42
|
+
* required. A missing or wrong-typed field throws a clear error at parse
|
|
43
|
+
* time so API contract drift surfaces loud and early instead of silently
|
|
44
|
+
* producing zero-valued metrics.
|
|
45
|
+
*/
|
|
46
|
+
export class CrawlerStatus {
|
|
47
|
+
constructor(data) {
|
|
48
|
+
Object.defineProperty(this, "crawler_uuid", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: void 0
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(this, "status", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
value: void 0
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(this, "is_finished", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: void 0
|
|
65
|
+
});
|
|
66
|
+
/** `null` while the crawler is still running; bool once terminal. */
|
|
67
|
+
Object.defineProperty(this, "is_success", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(this, "state", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
// Canonical API field name is `crawler_uuid`; accept short `uuid` as a
|
|
80
|
+
// legacy fallback but throw if neither is present.
|
|
81
|
+
if ('crawler_uuid' in data && typeof data.crawler_uuid === 'string' && data.crawler_uuid) {
|
|
82
|
+
this.crawler_uuid = data.crawler_uuid;
|
|
83
|
+
}
|
|
84
|
+
else if ('uuid' in data && typeof data.uuid === 'string' && data.uuid) {
|
|
85
|
+
this.crawler_uuid = data.uuid;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error("CrawlerStatus: required field 'crawler_uuid' (or legacy 'uuid') is missing from API response");
|
|
89
|
+
}
|
|
90
|
+
this.status = requireField(data, 'status', 'string', 'CrawlerStatus');
|
|
91
|
+
this.is_finished = requireField(data, 'is_finished', 'boolean', 'CrawlerStatus');
|
|
92
|
+
// `is_success` is documented as nullable while the crawler is running.
|
|
93
|
+
const isSuccessRaw = 'is_success' in data ? data.is_success : null;
|
|
94
|
+
if (isSuccessRaw !== null && typeof isSuccessRaw !== 'boolean') {
|
|
95
|
+
throw new Error(`CrawlerStatus: field 'is_success' must be bool or null, got ${typeof isSuccessRaw}`);
|
|
96
|
+
}
|
|
97
|
+
this.is_success = isSuccessRaw;
|
|
98
|
+
const state = requireField(data, 'state', 'object', 'CrawlerStatus');
|
|
99
|
+
this.state = {
|
|
100
|
+
// URL counters and `duration` are always present and numeric (0 during PENDING).
|
|
101
|
+
urls_visited: requireField(state, 'urls_visited', 'number', 'CrawlerStatus.state'),
|
|
102
|
+
urls_extracted: requireField(state, 'urls_extracted', 'number', 'CrawlerStatus.state'),
|
|
103
|
+
urls_failed: requireField(state, 'urls_failed', 'number', 'CrawlerStatus.state'),
|
|
104
|
+
urls_skipped: requireField(state, 'urls_skipped', 'number', 'CrawlerStatus.state'),
|
|
105
|
+
urls_to_crawl: requireField(state, 'urls_to_crawl', 'number', 'CrawlerStatus.state'),
|
|
106
|
+
api_credit_used: requireField(state, 'api_credit_used', 'number', 'CrawlerStatus.state'),
|
|
107
|
+
duration: requireField(state, 'duration', 'number', 'CrawlerStatus.state'),
|
|
108
|
+
// `start_time` / `stop_time` / `stop_reason` are null until the crawler
|
|
109
|
+
// actually starts / stops — verified against the live server behavior.
|
|
110
|
+
start_time: optionalField(state, 'start_time', 'number', 'CrawlerStatus.state'),
|
|
111
|
+
stop_time: optionalField(state, 'stop_time', 'number', 'CrawlerStatus.state'),
|
|
112
|
+
stop_reason: optionalField(state, 'stop_reason', 'string', 'CrawlerStatus.state'),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** True while the crawler is still working (PENDING or RUNNING). */
|
|
116
|
+
get isRunning() {
|
|
117
|
+
return this.status === 'PENDING' || this.status === 'RUNNING';
|
|
118
|
+
}
|
|
119
|
+
/** True if the crawler reached a terminal state successfully. */
|
|
120
|
+
get isComplete() {
|
|
121
|
+
return this.status === 'DONE' && this.is_success === true;
|
|
122
|
+
}
|
|
123
|
+
/** True if the crawler reached a terminal state but failed. */
|
|
124
|
+
get isFailed() {
|
|
125
|
+
return this.status === 'DONE' && this.is_success === false;
|
|
126
|
+
}
|
|
127
|
+
/** True if the crawler was cancelled by the user. */
|
|
128
|
+
get isCancelled() {
|
|
129
|
+
return this.status === 'CANCELLED';
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Rough progress estimate based on visited vs. extracted URLs (0–100).
|
|
133
|
+
* Returns 0 when nothing has been extracted yet.
|
|
134
|
+
*/
|
|
135
|
+
get progressPct() {
|
|
136
|
+
return this.state.urls_extracted > 0 ? (this.state.urls_visited / this.state.urls_extracted) * 100 : 0;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Wraps the streaming text response of `GET /crawl/{uuid}/urls`.
|
|
141
|
+
*
|
|
142
|
+
* The server returns one record per line with `Content-Type: text/plain`;
|
|
143
|
+
* this class parses that stream into a materialised list for caller
|
|
144
|
+
* convenience. For very large jobs, prefer {@link ScrapflyClient.crawlUrlsStream}
|
|
145
|
+
* (if provided) or call the endpoint via `client.fetch` directly and iterate
|
|
146
|
+
* the body as a stream.
|
|
147
|
+
*
|
|
148
|
+
* Pagination metadata fields (`page`, `per_page`) are echoes of the caller's
|
|
149
|
+
* request parameters — the wire protocol carries no global `total`, only the
|
|
150
|
+
* records in the current page. Use `urls.length` for the page size and
|
|
151
|
+
* request further pages by incrementing `page` until an empty response.
|
|
152
|
+
*/
|
|
153
|
+
export class CrawlerUrls {
|
|
154
|
+
constructor(urls, page, perPage) {
|
|
155
|
+
Object.defineProperty(this, "urls", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true,
|
|
159
|
+
value: void 0
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(this, "page", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
configurable: true,
|
|
164
|
+
writable: true,
|
|
165
|
+
value: void 0
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(this, "per_page", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
configurable: true,
|
|
170
|
+
writable: true,
|
|
171
|
+
value: void 0
|
|
172
|
+
});
|
|
173
|
+
this.urls = urls;
|
|
174
|
+
this.page = page;
|
|
175
|
+
this.per_page = perPage;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Parse the raw text body returned by `GET /crawl/{uuid}/urls`.
|
|
179
|
+
*
|
|
180
|
+
* - Empty lines are ignored (trailing newlines, blank records).
|
|
181
|
+
* - `visited` status → one URL per line, record has `{url, status: 'visited'}`.
|
|
182
|
+
* - `failed`/`skipped` status → `url,reason`, record includes `reason`.
|
|
183
|
+
* - When the caller didn't pass a `status` filter, the server defaults to
|
|
184
|
+
* `visited`; we pass that as the `statusHint` so every parsed record gets
|
|
185
|
+
* the right status tag.
|
|
186
|
+
*
|
|
187
|
+
* @param body Raw text body of the response.
|
|
188
|
+
* @param statusHint The status filter passed on the request (for tagging).
|
|
189
|
+
* @param page Caller-provided page (echoed on the response object).
|
|
190
|
+
* @param perPage Caller-provided per_page (echoed on the response object).
|
|
191
|
+
*/
|
|
192
|
+
static fromText(body, statusHint, page, perPage) {
|
|
193
|
+
const urls = [];
|
|
194
|
+
for (const rawLine of body.split(/\r?\n/)) {
|
|
195
|
+
const line = rawLine.trim();
|
|
196
|
+
if (!line)
|
|
197
|
+
continue;
|
|
198
|
+
if (statusHint === 'visited' || statusHint === 'pending') {
|
|
199
|
+
// Plain URL per line.
|
|
200
|
+
urls.push({ url: line, status: statusHint });
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// `url,reason` — split on the first comma.
|
|
204
|
+
const commaIdx = line.indexOf(',');
|
|
205
|
+
if (commaIdx === -1) {
|
|
206
|
+
urls.push({ url: line, status: statusHint });
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
urls.push({
|
|
210
|
+
url: line.slice(0, commaIdx),
|
|
211
|
+
status: statusHint,
|
|
212
|
+
reason: line.slice(commaIdx + 1),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return new CrawlerUrls(urls, page, perPage);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Wraps the JSON-mode response of `GET /crawl/{uuid}/contents` (i.e. `plain=false`).
|
|
222
|
+
*
|
|
223
|
+
* The `contents` field maps each URL to a map of format → content. When
|
|
224
|
+
* `plain=true` is used instead, {@link ScrapflyClient.crawlContents} returns
|
|
225
|
+
* a raw `string` directly rather than this class.
|
|
226
|
+
*
|
|
227
|
+
* Strict parsing: `contents` and `links` are both required per the documented
|
|
228
|
+
* contract. A response missing either field indicates an API contract change
|
|
229
|
+
* and throws at parse time rather than producing an empty envelope that looks
|
|
230
|
+
* valid.
|
|
231
|
+
*/
|
|
232
|
+
export class CrawlerContents {
|
|
233
|
+
constructor(data) {
|
|
234
|
+
Object.defineProperty(this, "contents", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
configurable: true,
|
|
237
|
+
writable: true,
|
|
238
|
+
value: void 0
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(this, "links", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
configurable: true,
|
|
243
|
+
writable: true,
|
|
244
|
+
value: void 0
|
|
245
|
+
});
|
|
246
|
+
this.contents = requireField(data, 'contents', 'object', 'CrawlerContents');
|
|
247
|
+
this.links = requireField(data, 'links', 'object', 'CrawlerContents');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Holds the raw bytes of a downloaded WARC or HAR artifact.
|
|
252
|
+
*
|
|
253
|
+
* **Note on parsing:** the SDK does NOT bundle WARC or HAR parsers. Use a dedicated
|
|
254
|
+
* library (e.g. `warcio` on npm for WARC) if you need to walk the records. The
|
|
255
|
+
* `save()` method is provided for the common case of writing the artifact to disk.
|
|
256
|
+
*/
|
|
257
|
+
export class CrawlerArtifact {
|
|
258
|
+
constructor(type, data) {
|
|
259
|
+
Object.defineProperty(this, "type", {
|
|
260
|
+
enumerable: true,
|
|
261
|
+
configurable: true,
|
|
262
|
+
writable: true,
|
|
263
|
+
value: void 0
|
|
264
|
+
});
|
|
265
|
+
Object.defineProperty(this, "data", {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
configurable: true,
|
|
268
|
+
writable: true,
|
|
269
|
+
value: void 0
|
|
270
|
+
});
|
|
271
|
+
this.type = type;
|
|
272
|
+
this.data = data;
|
|
273
|
+
}
|
|
274
|
+
/** Write the artifact to a file on disk. */
|
|
275
|
+
async save(filepath) {
|
|
276
|
+
await writeFile(filepath, this.data);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const LIFECYCLE_EVENTS = new Set([
|
|
280
|
+
'crawler_started',
|
|
281
|
+
'crawler_stopped',
|
|
282
|
+
'crawler_cancelled',
|
|
283
|
+
'crawler_finished',
|
|
284
|
+
]);
|
|
285
|
+
/**
|
|
286
|
+
* Parse a raw webhook body (JSON-decoded object) into a typed crawler webhook payload.
|
|
287
|
+
*
|
|
288
|
+
* Throws `Error` if the body is not an object, has no `event` field, or carries an
|
|
289
|
+
* unknown event name. Use this in your webhook handler after `JSON.parse()`.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* import { parseCrawlerWebhook } from '@scrapfly/scrapfly-sdk';
|
|
294
|
+
*
|
|
295
|
+
* app.post('/webhook', async (req, res) => {
|
|
296
|
+
* const body = await req.json();
|
|
297
|
+
* const webhook = parseCrawlerWebhook(body);
|
|
298
|
+
* if (webhook.event === 'crawler_finished') {
|
|
299
|
+
* console.log('done', webhook.payload.state.urls_visited);
|
|
300
|
+
* }
|
|
301
|
+
* });
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
export function parseCrawlerWebhook(body) {
|
|
305
|
+
if (typeof body !== 'object' || body === null) {
|
|
306
|
+
throw new Error('Crawler webhook body must be a JSON object');
|
|
307
|
+
}
|
|
308
|
+
const obj = body;
|
|
309
|
+
const event = obj.event;
|
|
310
|
+
if (typeof event !== 'string') {
|
|
311
|
+
throw new Error('Crawler webhook body is missing required `event` string field');
|
|
312
|
+
}
|
|
313
|
+
if (typeof obj.payload !== 'object' || obj.payload === null) {
|
|
314
|
+
throw new Error('Crawler webhook body is missing required `payload` object field');
|
|
315
|
+
}
|
|
316
|
+
if (LIFECYCLE_EVENTS.has(event) ||
|
|
317
|
+
event === 'crawler_url_visited' ||
|
|
318
|
+
event === 'crawler_url_skipped' ||
|
|
319
|
+
event === 'crawler_url_discovered' ||
|
|
320
|
+
event === 'crawler_url_failed') {
|
|
321
|
+
// The body has already been validated to have an `event` and `payload`. The
|
|
322
|
+
// narrower per-event field shapes are runtime-checked by the discriminated union
|
|
323
|
+
// — TypeScript users get the typed view; runtime users get a permissive bag.
|
|
324
|
+
return obj;
|
|
325
|
+
}
|
|
326
|
+
throw new Error(`Unknown crawler webhook event: ${event}`);
|
|
327
|
+
}
|
package/esm/errors.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare class ScreenshotConfigError extends ScrapflyError {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class ExtractionConfigError extends ScrapflyError {
|
|
10
10
|
}
|
|
11
|
+
export declare class CrawlerConfigError extends ScrapflyError {
|
|
12
|
+
}
|
|
11
13
|
export declare class EncodeError extends ScrapflyError {
|
|
12
14
|
}
|
|
13
15
|
export declare class ContentTypeError extends ScrapflyError {
|
|
@@ -50,4 +52,6 @@ export declare class ScreenshotApiError extends ApiHttpClientError {
|
|
|
50
52
|
}
|
|
51
53
|
export declare class ExtractionApiError extends ApiHttpClientError {
|
|
52
54
|
}
|
|
55
|
+
export declare class ScrapflyCrawlerError extends HttpError {
|
|
56
|
+
}
|
|
53
57
|
//# sourceMappingURL=errors.d.ts.map
|
package/esm/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;CAI5D;AAGD,qBAAa,iBAAkB,SAAQ,aAAa;CAAG;AAEvD,qBAAa,qBAAsB,SAAQ,aAAa;CAAG;AAE3D,qBAAa,qBAAsB,SAAQ,aAAa;CAAG;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,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B,SAAQ,SAAS;CAAG"}
|
package/esm/errors.js
CHANGED
|
@@ -19,6 +19,9 @@ export class ScreenshotConfigError extends ScrapflyError {
|
|
|
19
19
|
// raised when extraction config is invalid
|
|
20
20
|
export class ExtractionConfigError extends ScrapflyError {
|
|
21
21
|
}
|
|
22
|
+
// raised when crawler config is invalid
|
|
23
|
+
export class CrawlerConfigError extends ScrapflyError {
|
|
24
|
+
}
|
|
22
25
|
// raised when scrape parameters cannot be encoded
|
|
23
26
|
export class EncodeError extends ScrapflyError {
|
|
24
27
|
}
|
|
@@ -72,3 +75,6 @@ export class ScreenshotApiError extends ApiHttpClientError {
|
|
|
72
75
|
// raised with Scrapfly extraction API related errors
|
|
73
76
|
export class ExtractionApiError extends ApiHttpClientError {
|
|
74
77
|
}
|
|
78
|
+
// raised with Scrapfly crawler API related errors (job lifecycle: ALREADY_STARTED, NOT_STARTED, FAILED, CANCELLED, TIMEOUT, etc.)
|
|
79
|
+
export class ScrapflyCrawlerError extends HttpError {
|
|
80
|
+
}
|
|
@@ -24,6 +24,7 @@ type ExtractionConfigOptions = {
|
|
|
24
24
|
is_document_compressed?: boolean;
|
|
25
25
|
document_compression_format?: 'gzip' | 'zstd' | 'deflate' | CompressionFormat;
|
|
26
26
|
webhook?: string;
|
|
27
|
+
timeout?: number;
|
|
27
28
|
template?: string;
|
|
28
29
|
ephemeral_template?: object;
|
|
29
30
|
};
|
|
@@ -39,6 +40,7 @@ export declare class ExtractionConfig {
|
|
|
39
40
|
is_document_compressed?: boolean;
|
|
40
41
|
document_compression_format?: 'gzip' | 'zstd' | 'deflate' | CompressionFormat;
|
|
41
42
|
webhook?: string;
|
|
43
|
+
timeout?: number;
|
|
42
44
|
template?: string;
|
|
43
45
|
ephemeral_template?: object;
|
|
44
46
|
constructor(options: ExtractionConfigOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractionconfig.d.ts","sourceRoot":"","sources":["../src/extractionconfig.ts"],"names":[],"mappings":"AAIA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AO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,uBAAuB;IAyC5C,OAAO,CAAC,eAAe;IASvB,WAAW,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAoE3D"}
|
package/esm/extractionconfig.js
CHANGED
|
@@ -84,6 +84,12 @@ export class ExtractionConfig {
|
|
|
84
84
|
writable: true,
|
|
85
85
|
value: void 0
|
|
86
86
|
});
|
|
87
|
+
Object.defineProperty(this, "timeout", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: void 0
|
|
92
|
+
});
|
|
87
93
|
// // deprecated options
|
|
88
94
|
Object.defineProperty(this, "template", {
|
|
89
95
|
enumerable: true,
|
|
@@ -127,6 +133,7 @@ export class ExtractionConfig {
|
|
|
127
133
|
this.is_document_compressed = options.is_document_compressed ?? this.is_document_compressed;
|
|
128
134
|
this.document_compression_format = options.document_compression_format ?? this.document_compression_format;
|
|
129
135
|
this.webhook = options.webhook ?? this.webhook;
|
|
136
|
+
this.timeout = options.timeout ?? this.timeout;
|
|
130
137
|
}
|
|
131
138
|
validateOptions(options) {
|
|
132
139
|
const validKeys = new Set(Object.keys(this));
|
|
@@ -183,6 +190,9 @@ export class ExtractionConfig {
|
|
|
183
190
|
if (this.webhook) {
|
|
184
191
|
params.webhook_name = this.webhook;
|
|
185
192
|
}
|
|
193
|
+
if (this.timeout) {
|
|
194
|
+
params.timeout = this.timeout;
|
|
195
|
+
}
|
|
186
196
|
return params;
|
|
187
197
|
}
|
|
188
198
|
}
|
package/esm/main.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
export { ScrapflyClient } from './client.js';
|
|
2
2
|
export { Format as ScrapeFormat, FormatOption as ScrapeFormatOptions, ScrapeConfig, ScreenshotFlags, } from './scrapeconfig.js';
|
|
3
|
-
export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig } from './screenshotconfig.js';
|
|
3
|
+
export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig, VisionDeficiency, } from './screenshotconfig.js';
|
|
4
4
|
export { ExtractionConfig } from './extractionconfig.js';
|
|
5
|
+
export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
|
|
6
|
+
export type { BrowserConfigOptions } from './browserconfig.js';
|
|
5
7
|
export * as errors from './errors.js';
|
|
6
8
|
export { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
|
|
7
9
|
export type { AccountData, ConfigData, ContextData, ResultData, ScreenshotMetadata } from './result.js';
|
|
10
|
+
export { CrawlerConfig } from './crawlerconfig.js';
|
|
11
|
+
export type { CrawlerConfigOptions, CrawlerContentFormat, CrawlerWebhookEventName } from './crawlerconfig.js';
|
|
12
|
+
export { Crawl } from './crawl.js';
|
|
13
|
+
export { CrawlerArtifact, CrawlerContents, CrawlerStatus, CrawlerUrls, parseCrawlerWebhook, } from './crawlerresult.js';
|
|
14
|
+
export type { CrawlerArtifactType, CrawlerLifecycleWebhook, CrawlerState, CrawlerStatusValue, CrawlerStopReason, CrawlerUrlDiscoveredWebhook, CrawlerUrlEntry, CrawlerUrlFailedWebhook, CrawlerUrlSkippedWebhook, CrawlerUrlVisitedWebhook, CrawlerWebhookCommon, CrawlerWebhookPayload, } from './crawlerresult.js';
|
|
8
15
|
export { log } from './logger.js';
|
|
9
16
|
export { createServer, verifySignature } from './webhookserver.js';
|
|
10
17
|
//# sourceMappingURL=main.d.ts.map
|
package/esm/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EA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B,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/esm/main.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { ScrapflyClient } from './client.js';
|
|
2
2
|
export { Format as ScrapeFormat, FormatOption as ScrapeFormatOptions, ScrapeConfig, ScreenshotFlags, } from './scrapeconfig.js';
|
|
3
|
-
export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig } from './screenshotconfig.js';
|
|
3
|
+
export { Format as ScreenshotFormat, Options as ScreenshotOptions, ScreenshotConfig, VisionDeficiency, } from './screenshotconfig.js';
|
|
4
4
|
export { ExtractionConfig } from './extractionconfig.js';
|
|
5
|
+
export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
|
|
5
6
|
export * as errors from './errors.js';
|
|
6
7
|
export { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
|
|
8
|
+
// Crawler API
|
|
9
|
+
export { CrawlerConfig } from './crawlerconfig.js';
|
|
10
|
+
export { Crawl } from './crawl.js';
|
|
11
|
+
export { CrawlerArtifact, CrawlerContents, CrawlerStatus, CrawlerUrls, parseCrawlerWebhook, } from './crawlerresult.js';
|
|
7
12
|
export { log } from './logger.js';
|
|
8
13
|
export { createServer, verifySignature } from './webhookserver.js';
|
package/esm/polyfill.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as dntShim from "./_dnt.shims.js";
|
|
2
2
|
export declare const isDeno: boolean;
|
|
3
|
+
export declare const isBun: boolean;
|
|
4
|
+
export declare function readFileSync(path: string): Uint8Array;
|
|
3
5
|
export declare function mkdir(path: string | URL, options: dntShim.Deno.MkdirOptions): Promise<void>;
|
|
4
6
|
export declare function writeFile(path: string | URL, data: Uint8Array, options?: dntShim.Deno.WriteFileOptions): Promise<void>;
|
|
5
7
|
//# sourceMappingURL=polyfill.d.ts.map
|
package/esm/polyfill.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,eAAO,MAAM,MAAM,SAAsC,CAAC;AAE1D,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjG;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,GAAG,GAAG,EAClB,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,gBAAqB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,eAAO,MAAM,MAAM,SAAsC,CAAC;AAE1D,eAAO,MAAM,KAAK,SAA6B,CAAC;AAEhD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CASrD;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjG;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,GAAG,GAAG,EAClB,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,gBAAqB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
package/esm/polyfill.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import * as dntShim from "./_dnt.shims.js";
|
|
2
2
|
export const isDeno = typeof dntShim.Deno !== 'undefined';
|
|
3
|
+
// @ts-ignore: Bun global
|
|
4
|
+
export const isBun = typeof Bun !== 'undefined';
|
|
5
|
+
export function readFileSync(path) {
|
|
6
|
+
if (isDeno) {
|
|
7
|
+
return dntShim.Deno.readFileSync(path);
|
|
8
|
+
}
|
|
9
|
+
// Node.js / Bun — both support require('fs')
|
|
10
|
+
// deno-lint-ignore no-var
|
|
11
|
+
// @ts-ignore: dynamic require for Node/Bun
|
|
12
|
+
var fs = require('fs');
|
|
13
|
+
return new Uint8Array(fs.readFileSync(path));
|
|
14
|
+
}
|
|
3
15
|
export async function mkdir(path, options) {
|
|
4
16
|
if (isDeno) {
|
|
5
17
|
await dntShim.Deno.mkdir(path, options);
|
package/esm/scrapeconfig.d.ts
CHANGED
|
@@ -75,6 +75,29 @@ type ScrapeConfigOptions = {
|
|
|
75
75
|
os?: string;
|
|
76
76
|
lang?: string[];
|
|
77
77
|
auto_scroll?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Chromium-based browser brand used for fingerprint generation.
|
|
80
|
+
* One of "chrome" | "edge" | "brave" | "opera". Defaults to "chrome"
|
|
81
|
+
* when omitted. Invalid values are silently dropped by the server.
|
|
82
|
+
*/
|
|
83
|
+
browser_brand?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Return the raw upstream response (target's status, headers, body)
|
|
86
|
+
* instead of the JSON envelope. When true, ScrapflyClient.scrape()
|
|
87
|
+
* returns the raw fetch Response so callers can drive it like any
|
|
88
|
+
* HTTP response. Scrapfly metadata is on the X-Scrapfly-* headers.
|
|
89
|
+
*/
|
|
90
|
+
proxified_response?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Controls when the browser considers the page loaded.
|
|
93
|
+
* "complete" (default) or "domcontentloaded" for faster scrapes.
|
|
94
|
+
*/
|
|
95
|
+
rendering_stage?: 'complete' | 'domcontentloaded';
|
|
96
|
+
/**
|
|
97
|
+
* Spoof browser geolocation. Format: "latitude,longitude"
|
|
98
|
+
* e.g. "48.856614,2.3522219" for Paris.
|
|
99
|
+
*/
|
|
100
|
+
geolocation?: string;
|
|
78
101
|
};
|
|
79
102
|
export declare class ScrapeConfig {
|
|
80
103
|
static PUBLIC_DATACENTER_POOL: string;
|
|
@@ -119,6 +142,10 @@ export declare class ScrapeConfig {
|
|
|
119
142
|
lang?: string[];
|
|
120
143
|
os?: string;
|
|
121
144
|
auto_scroll?: boolean;
|
|
145
|
+
browser_brand?: string;
|
|
146
|
+
proxified_response?: boolean;
|
|
147
|
+
rendering_stage?: 'complete' | 'domcontentloaded';
|
|
148
|
+
geolocation?: string;
|
|
122
149
|
constructor(options: ScrapeConfigOptions);
|
|
123
150
|
private validateOptions;
|
|
124
151
|
toApiParams(options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeconfig.d.ts","sourceRoot":"","sources":["../src/scrapeconfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGlD,oBAAY,eAAe;IACzB;;;;;;;QAOI;IACJ,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,YAAY,iBAAiB;CAC9B;AAED,oBAAY,MAAM;IAChB;;;;;;;QAOI;IACJ,IAAI,SAAS;IACb,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,GAAG,QAAQ;CACZ;AAED,oBAAY,YAAY;IACtB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,YAAY,iBAAiB;CAC9B;AAED,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,M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EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAuL3D"}
|
package/esm/scrapeconfig.js
CHANGED
|
@@ -281,6 +281,30 @@ export class ScrapeConfig {
|
|
|
281
281
|
writable: true,
|
|
282
282
|
value: void 0
|
|
283
283
|
});
|
|
284
|
+
Object.defineProperty(this, "browser_brand", {
|
|
285
|
+
enumerable: true,
|
|
286
|
+
configurable: true,
|
|
287
|
+
writable: true,
|
|
288
|
+
value: void 0
|
|
289
|
+
});
|
|
290
|
+
Object.defineProperty(this, "proxified_response", {
|
|
291
|
+
enumerable: true,
|
|
292
|
+
configurable: true,
|
|
293
|
+
writable: true,
|
|
294
|
+
value: void 0
|
|
295
|
+
});
|
|
296
|
+
Object.defineProperty(this, "rendering_stage", {
|
|
297
|
+
enumerable: true,
|
|
298
|
+
configurable: true,
|
|
299
|
+
writable: true,
|
|
300
|
+
value: void 0
|
|
301
|
+
});
|
|
302
|
+
Object.defineProperty(this, "geolocation", {
|
|
303
|
+
enumerable: true,
|
|
304
|
+
configurable: true,
|
|
305
|
+
writable: true,
|
|
306
|
+
value: void 0
|
|
307
|
+
});
|
|
284
308
|
this.validateOptions(options);
|
|
285
309
|
if (options.format && !Object.values(Format).includes(options.format)) {
|
|
286
310
|
throw new ScrapeConfigError(`Invalid Format param value: ${options.format}`);
|
|
@@ -317,7 +341,7 @@ export class ScrapeConfig {
|
|
|
317
341
|
this.cache_ttl = options.cache_ttl ?? this.cache_ttl;
|
|
318
342
|
this.proxy_pool = options.proxy_pool ?? this.proxy_pool;
|
|
319
343
|
this.session = options.session ?? this.session;
|
|
320
|
-
this.tags = new Set(options.tags)
|
|
344
|
+
this.tags = options.tags ? new Set(options.tags) : this.tags;
|
|
321
345
|
this.format = options.format ?? this.format;
|
|
322
346
|
this.format_options = options.format_options ?? this.format_options;
|
|
323
347
|
this.extraction_template = options.extraction_template ?? this.extraction_template;
|
|
@@ -341,6 +365,10 @@ export class ScrapeConfig {
|
|
|
341
365
|
this.os = options.os ?? this.os;
|
|
342
366
|
this.lang = options.lang ?? this.lang;
|
|
343
367
|
this.auto_scroll = options.auto_scroll ?? this.auto_scroll;
|
|
368
|
+
this.browser_brand = options.browser_brand ?? this.browser_brand;
|
|
369
|
+
this.proxified_response = options.proxified_response ?? this.proxified_response;
|
|
370
|
+
this.rendering_stage = options.rendering_stage ?? this.rendering_stage;
|
|
371
|
+
this.geolocation = options.geolocation ?? this.geolocation;
|
|
344
372
|
this.dns = options.dns ?? this.dns;
|
|
345
373
|
this.ssl = options.ssl ?? this.ssl;
|
|
346
374
|
this.debug = options.debug ?? this.debug;
|
|
@@ -412,6 +440,12 @@ export class ScrapeConfig {
|
|
|
412
440
|
if (this.timeout) {
|
|
413
441
|
params.timeout = this.timeout;
|
|
414
442
|
}
|
|
443
|
+
if (this.cost_budget !== undefined) {
|
|
444
|
+
params.cost_budget = this.cost_budget;
|
|
445
|
+
}
|
|
446
|
+
if (this.proxified_response !== undefined) {
|
|
447
|
+
params.proxified_response = this.proxified_response;
|
|
448
|
+
}
|
|
415
449
|
if (this.render_js === true) {
|
|
416
450
|
params.render_js = true;
|
|
417
451
|
if (this.wait_for_selector !== undefined) {
|
|
@@ -426,6 +460,12 @@ export class ScrapeConfig {
|
|
|
426
460
|
if (this.rendering_wait !== undefined) {
|
|
427
461
|
params.rendering_wait = this.rendering_wait;
|
|
428
462
|
}
|
|
463
|
+
if (this.rendering_stage && this.rendering_stage !== 'complete') {
|
|
464
|
+
params.rendering_stage = this.rendering_stage;
|
|
465
|
+
}
|
|
466
|
+
if (this.geolocation) {
|
|
467
|
+
params.geolocation = this.geolocation;
|
|
468
|
+
}
|
|
429
469
|
if (this.screenshots !== undefined) {
|
|
430
470
|
Object.keys(this.screenshots).forEach((key) => {
|
|
431
471
|
params[`screenshots[${key}]`] = (this.screenshots || {})[key];
|
|
@@ -539,6 +579,9 @@ export class ScrapeConfig {
|
|
|
539
579
|
if (this.os !== undefined) {
|
|
540
580
|
params.os = this.os;
|
|
541
581
|
}
|
|
582
|
+
if (this.browser_brand !== undefined) {
|
|
583
|
+
params.browser_brand = this.browser_brand;
|
|
584
|
+
}
|
|
542
585
|
return params;
|
|
543
586
|
}
|
|
544
587
|
}
|