scrapfly-sdk 0.7.2 → 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/esm/webhookserver.d.ts +1 -0
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +1 -0
- 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
- package/script/webhookserver.d.ts +1 -0
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +2 -1
package/script/scrapeconfig.js
CHANGED
|
@@ -284,6 +284,30 @@ class ScrapeConfig {
|
|
|
284
284
|
writable: true,
|
|
285
285
|
value: void 0
|
|
286
286
|
});
|
|
287
|
+
Object.defineProperty(this, "browser_brand", {
|
|
288
|
+
enumerable: true,
|
|
289
|
+
configurable: true,
|
|
290
|
+
writable: true,
|
|
291
|
+
value: void 0
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(this, "proxified_response", {
|
|
294
|
+
enumerable: true,
|
|
295
|
+
configurable: true,
|
|
296
|
+
writable: true,
|
|
297
|
+
value: void 0
|
|
298
|
+
});
|
|
299
|
+
Object.defineProperty(this, "rendering_stage", {
|
|
300
|
+
enumerable: true,
|
|
301
|
+
configurable: true,
|
|
302
|
+
writable: true,
|
|
303
|
+
value: void 0
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(this, "geolocation", {
|
|
306
|
+
enumerable: true,
|
|
307
|
+
configurable: true,
|
|
308
|
+
writable: true,
|
|
309
|
+
value: void 0
|
|
310
|
+
});
|
|
287
311
|
this.validateOptions(options);
|
|
288
312
|
if (options.format && !Object.values(Format).includes(options.format)) {
|
|
289
313
|
throw new errors_js_1.ScrapeConfigError(`Invalid Format param value: ${options.format}`);
|
|
@@ -320,7 +344,7 @@ class ScrapeConfig {
|
|
|
320
344
|
this.cache_ttl = options.cache_ttl ?? this.cache_ttl;
|
|
321
345
|
this.proxy_pool = options.proxy_pool ?? this.proxy_pool;
|
|
322
346
|
this.session = options.session ?? this.session;
|
|
323
|
-
this.tags = new Set(options.tags)
|
|
347
|
+
this.tags = options.tags ? new Set(options.tags) : this.tags;
|
|
324
348
|
this.format = options.format ?? this.format;
|
|
325
349
|
this.format_options = options.format_options ?? this.format_options;
|
|
326
350
|
this.extraction_template = options.extraction_template ?? this.extraction_template;
|
|
@@ -344,6 +368,10 @@ class ScrapeConfig {
|
|
|
344
368
|
this.os = options.os ?? this.os;
|
|
345
369
|
this.lang = options.lang ?? this.lang;
|
|
346
370
|
this.auto_scroll = options.auto_scroll ?? this.auto_scroll;
|
|
371
|
+
this.browser_brand = options.browser_brand ?? this.browser_brand;
|
|
372
|
+
this.proxified_response = options.proxified_response ?? this.proxified_response;
|
|
373
|
+
this.rendering_stage = options.rendering_stage ?? this.rendering_stage;
|
|
374
|
+
this.geolocation = options.geolocation ?? this.geolocation;
|
|
347
375
|
this.dns = options.dns ?? this.dns;
|
|
348
376
|
this.ssl = options.ssl ?? this.ssl;
|
|
349
377
|
this.debug = options.debug ?? this.debug;
|
|
@@ -415,6 +443,12 @@ class ScrapeConfig {
|
|
|
415
443
|
if (this.timeout) {
|
|
416
444
|
params.timeout = this.timeout;
|
|
417
445
|
}
|
|
446
|
+
if (this.cost_budget !== undefined) {
|
|
447
|
+
params.cost_budget = this.cost_budget;
|
|
448
|
+
}
|
|
449
|
+
if (this.proxified_response !== undefined) {
|
|
450
|
+
params.proxified_response = this.proxified_response;
|
|
451
|
+
}
|
|
418
452
|
if (this.render_js === true) {
|
|
419
453
|
params.render_js = true;
|
|
420
454
|
if (this.wait_for_selector !== undefined) {
|
|
@@ -429,6 +463,12 @@ class ScrapeConfig {
|
|
|
429
463
|
if (this.rendering_wait !== undefined) {
|
|
430
464
|
params.rendering_wait = this.rendering_wait;
|
|
431
465
|
}
|
|
466
|
+
if (this.rendering_stage && this.rendering_stage !== 'complete') {
|
|
467
|
+
params.rendering_stage = this.rendering_stage;
|
|
468
|
+
}
|
|
469
|
+
if (this.geolocation) {
|
|
470
|
+
params.geolocation = this.geolocation;
|
|
471
|
+
}
|
|
432
472
|
if (this.screenshots !== undefined) {
|
|
433
473
|
Object.keys(this.screenshots).forEach((key) => {
|
|
434
474
|
params[`screenshots[${key}]`] = (this.screenshots || {})[key];
|
|
@@ -542,6 +582,9 @@ class ScrapeConfig {
|
|
|
542
582
|
if (this.os !== undefined) {
|
|
543
583
|
params.os = this.os;
|
|
544
584
|
}
|
|
585
|
+
if (this.browser_brand !== undefined) {
|
|
586
|
+
params.browser_brand = this.browser_brand;
|
|
587
|
+
}
|
|
545
588
|
return params;
|
|
546
589
|
}
|
|
547
590
|
}
|
|
@@ -59,7 +59,7 @@ type ScreenshotConfigOptions = {
|
|
|
59
59
|
cache?: boolean;
|
|
60
60
|
cache_ttl?: number;
|
|
61
61
|
cache_clear?: boolean;
|
|
62
|
-
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | '
|
|
62
|
+
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
63
63
|
webhook?: string;
|
|
64
64
|
};
|
|
65
65
|
export declare class ScreenshotConfig {
|
|
@@ -77,7 +77,7 @@ export declare class ScreenshotConfig {
|
|
|
77
77
|
cache?: boolean;
|
|
78
78
|
cache_ttl?: number;
|
|
79
79
|
cache_clear?: boolean;
|
|
80
|
-
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | '
|
|
80
|
+
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
81
81
|
webhook?: string;
|
|
82
82
|
constructor(options: ScreenshotConfigOptions);
|
|
83
83
|
private validateOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotconfig.d.ts","sourceRoot":"","sources":["../src/screenshotconfig.ts"],"names":[],"mappings":"AAIA,oBAAY,OAAO;IACjB;;;;;;;QAOI;IACJ,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;CAC1C;AAED,oBAAY,MAAM;IAChB;;;;;;;QAOI;IACJ,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAED,oBAAY,gBAAgB;IAC1B;;;;;;;;;OASG;IACH,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,gBAAgB,oBAAoB;IACpC,cAAc,kBAAkB;CACjC;AAED,KAAK,uBAAuB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC,aAAa,GAAG,WAAW,GAAG,eAA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AAuB;IA+B5C,OAAO,CAAC,eAAe;IASvB,WAAW,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAyE3D"}
|
package/script/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQtD;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC5B,CAAC;AAEF,wBAAsB,UAAU,CAC9B,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAa,GACxB,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQtD;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC5B,CAAC;AAEF,wBAAsB,UAAU,CAC9B,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAa,GACxB,OAAO,CAAC,QAAQ,CAAC,CA6CnB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAc5E"}
|
package/script/utils.js
CHANGED
|
@@ -19,7 +19,18 @@ async function fetchRetry(config, retries = 3, retryDelay = 1000) {
|
|
|
19
19
|
try {
|
|
20
20
|
// XXX: note that cloudflare workers don't support init options
|
|
21
21
|
const { url, ...reqInit } = config;
|
|
22
|
-
|
|
22
|
+
// The `body` field on RequestOptions is typed as string | Uint8Array for
|
|
23
|
+
// historical reasons. The dnt (deno-to-node) build does not expose the
|
|
24
|
+
// DOM `BodyInit` alias in every lib target, so we cast to `any` here to
|
|
25
|
+
// stay portable across Deno, Node, Bun and Cloudflare Workers. The
|
|
26
|
+
// runtime values (string | Uint8Array) are all valid fetch body inputs.
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
const init = {
|
|
29
|
+
method: reqInit.method,
|
|
30
|
+
headers: reqInit.headers,
|
|
31
|
+
body: reqInit.body,
|
|
32
|
+
};
|
|
33
|
+
const response = await fetch(new Request(url, init));
|
|
23
34
|
// retry 5xx status codes
|
|
24
35
|
if (response.status >= 500 && response.status < 600) {
|
|
25
36
|
const _text = await response.text(); // consume response to prevent leak
|
|
@@ -35,7 +46,10 @@ async function fetchRetry(config, retries = 3, retryDelay = 1000) {
|
|
|
35
46
|
}
|
|
36
47
|
catch (error) {
|
|
37
48
|
lastError = error;
|
|
38
|
-
|
|
49
|
+
// AbortError should never be retried: it means the caller explicitly
|
|
50
|
+
// gave up (cancel token, timeout, etc.) and we shouldn't paper over it.
|
|
51
|
+
const isAbort = error instanceof Error && error.name === 'AbortError';
|
|
52
|
+
if (attempt === retries || isAbort) {
|
|
39
53
|
throw error;
|
|
40
54
|
}
|
|
41
55
|
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhookserver.d.ts","sourceRoot":"","sources":["../src/webhookserver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhookserver.d.ts","sourceRoot":"","sources":["../src/webhookserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAM/F;AAGD,wBAAsB,YAAY,CAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,EACjE,GAAG,CAAC,EAAE,GAAG,GACR,OAAO,CAAC,GAAG,CAAC,CA4Cd"}
|
package/script/webhookserver.js
CHANGED
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.ResourceType = void 0;
|
|
30
30
|
exports.verifySignature = verifySignature;
|
|
31
31
|
exports.createServer = createServer;
|
|
32
|
+
const node_buffer_1 = require("node:buffer");
|
|
32
33
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
33
34
|
const logger_js_1 = require("./logger.js");
|
|
34
35
|
var ResourceType;
|
|
@@ -37,7 +38,7 @@ var ResourceType;
|
|
|
37
38
|
ResourceType["PING"] = "ping";
|
|
38
39
|
})(ResourceType || (exports.ResourceType = ResourceType = {}));
|
|
39
40
|
function verifySignature(body, signature, signingSecret) {
|
|
40
|
-
const secret = Buffer.from(signingSecret, 'hex');
|
|
41
|
+
const secret = node_buffer_1.Buffer.from(signingSecret, 'hex');
|
|
41
42
|
const hmac = node_crypto_1.default.createHmac('sha256', secret);
|
|
42
43
|
hmac.update(body);
|
|
43
44
|
const computed = hmac.digest('hex').toUpperCase();
|