scrapfly-sdk 0.10.0 → 0.10.3
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/batch.d.ts +40 -0
- package/esm/batch.d.ts.map +1 -0
- package/esm/batch.js +255 -0
- package/esm/browserconfig.d.ts +2 -0
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +9 -0
- package/esm/client.d.ts +31 -1
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +201 -8
- package/esm/main.d.ts +1 -1
- package/esm/main.d.ts.map +1 -1
- package/esm/result.d.ts +12 -0
- package/esm/result.d.ts.map +1 -1
- package/package.json +2 -1
- package/script/batch.d.ts +40 -0
- package/script/batch.d.ts.map +1 -0
- package/script/batch.js +260 -0
- package/script/browserconfig.d.ts +2 -0
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +9 -0
- package/script/client.d.ts +31 -1
- package/script/client.d.ts.map +1 -1
- package/script/client.js +201 -8
- package/script/main.d.ts +1 -1
- package/script/main.d.ts.map +1 -1
- package/script/result.d.ts +12 -0
- package/script/result.d.ts.map +1 -1
package/esm/client.js
CHANGED
|
@@ -230,6 +230,64 @@ export class ScrapflyClient {
|
|
|
230
230
|
}
|
|
231
231
|
return data;
|
|
232
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Classify an already-fetched HTTP response for anti-bot blocking.
|
|
235
|
+
*
|
|
236
|
+
* Runs the same anti-bot detection pipeline used by live Scrapfly
|
|
237
|
+
* scrapes against a response you already have (from your own proxy,
|
|
238
|
+
* cache, etc). 1 API credit per call. See
|
|
239
|
+
* https://scrapfly.io/docs/scrape-api/classify for the full contract.
|
|
240
|
+
*/
|
|
241
|
+
async classify(options) {
|
|
242
|
+
if (!options || !options.url) {
|
|
243
|
+
throw new errors.ScrapflyError('classify: url is required');
|
|
244
|
+
}
|
|
245
|
+
if (typeof options.statusCode !== 'number' ||
|
|
246
|
+
options.statusCode < 100 ||
|
|
247
|
+
options.statusCode > 599) {
|
|
248
|
+
throw new errors.ScrapflyError('classify: status_code must be a valid HTTP status in [100, 599]');
|
|
249
|
+
}
|
|
250
|
+
const body = {
|
|
251
|
+
url: options.url,
|
|
252
|
+
status_code: options.statusCode,
|
|
253
|
+
method: options.method ?? 'GET',
|
|
254
|
+
};
|
|
255
|
+
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
256
|
+
const hdrs = {};
|
|
257
|
+
for (const [k, v] of Object.entries(options.headers)) {
|
|
258
|
+
hdrs[String(k)] = String(v);
|
|
259
|
+
}
|
|
260
|
+
body.headers = hdrs;
|
|
261
|
+
}
|
|
262
|
+
if (options.body !== undefined && options.body !== null) {
|
|
263
|
+
body.body = options.body;
|
|
264
|
+
}
|
|
265
|
+
const url = new URL(this.HOST + '/classify');
|
|
266
|
+
url.search = new URLSearchParams({ key: this.key }).toString();
|
|
267
|
+
const response = await this.fetch({
|
|
268
|
+
url: url.toString(),
|
|
269
|
+
method: 'POST',
|
|
270
|
+
headers: {
|
|
271
|
+
'user-agent': this.ua,
|
|
272
|
+
'accept-encoding': 'gzip, deflate, br',
|
|
273
|
+
accept: 'application/json',
|
|
274
|
+
'content-type': 'application/json',
|
|
275
|
+
},
|
|
276
|
+
body: JSON.stringify(body),
|
|
277
|
+
});
|
|
278
|
+
const data = (await response.json());
|
|
279
|
+
if (response.status >= 400 || 'error_id' in data) {
|
|
280
|
+
if (response.status == 401) {
|
|
281
|
+
throw new errors.BadApiKeyError(JSON.stringify(data));
|
|
282
|
+
}
|
|
283
|
+
throw new errors.ApiHttpClientError(JSON.stringify(data));
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
blocked: Boolean(data.blocked),
|
|
287
|
+
antibot: (data.antibot ?? null),
|
|
288
|
+
cost: Number(data.cost ?? 0),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
233
291
|
// ── Monitoring API (Enterprise+ plan only) ──────────────────────
|
|
234
292
|
// The Monitoring API exposes per-product aggregates and per-target
|
|
235
293
|
// timeseries. Web Scraping / Screenshot / Extraction / Crawler share
|
|
@@ -498,6 +556,130 @@ export class ScrapflyClient {
|
|
|
498
556
|
yield resultOrError;
|
|
499
557
|
}
|
|
500
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Issue a single batch request against POST /scrape/batch and
|
|
561
|
+
* stream results back as each scrape completes.
|
|
562
|
+
*
|
|
563
|
+
* Yields `[correlation_id, resultOrError]` tuples. Results arrive
|
|
564
|
+
* OUT OF ORDER — whichever scrape finishes first is yielded first.
|
|
565
|
+
* Every ScrapeConfig MUST carry a unique `correlation_id`; missing
|
|
566
|
+
* or duplicate values are caught client-side before the batch is
|
|
567
|
+
* sent (so callers fail fast on misconfiguration).
|
|
568
|
+
*
|
|
569
|
+
* Usage:
|
|
570
|
+
* for await (const [id, result] of client.scrapeBatch(configs)) {
|
|
571
|
+
* if (result instanceof errors.ScrapflyError) { ... }
|
|
572
|
+
* else { ... }
|
|
573
|
+
* }
|
|
574
|
+
*/
|
|
575
|
+
async *scrapeBatch(configs, options = {}) {
|
|
576
|
+
const wireFormat = options.format ?? 'json';
|
|
577
|
+
const acceptHeader = wireFormat === 'msgpack' ? 'application/msgpack' : 'application/json';
|
|
578
|
+
// Lazy-load the parser to avoid pulling Web Streams polyfills
|
|
579
|
+
// into the module graph for users who never call scrapeBatch.
|
|
580
|
+
const { iterBatchParts, decodePartBody, buildProxifiedResponseFromPart } = await import('./batch.js');
|
|
581
|
+
if (!configs || configs.length === 0) {
|
|
582
|
+
throw new errors.ScrapflyError('scrapeBatch: configs list is empty');
|
|
583
|
+
}
|
|
584
|
+
if (configs.length > 100) {
|
|
585
|
+
throw new errors.ScrapflyError(`scrapeBatch: max 100 configs per batch (got ${configs.length})`);
|
|
586
|
+
}
|
|
587
|
+
const seen = new Map();
|
|
588
|
+
const configByCorrelation = new Map();
|
|
589
|
+
const bodyConfigs = [];
|
|
590
|
+
for (let i = 0; i < configs.length; i++) {
|
|
591
|
+
const cfg = configs[i];
|
|
592
|
+
const correlationId = cfg.correlation_id;
|
|
593
|
+
if (!correlationId) {
|
|
594
|
+
throw new errors.ScrapflyError(`scrapeBatch: configs[${i}] is missing correlation_id (required for matching streamed parts)`);
|
|
595
|
+
}
|
|
596
|
+
if (seen.has(correlationId)) {
|
|
597
|
+
throw new errors.ScrapflyError(`scrapeBatch: correlation_id ${JSON.stringify(correlationId)} reused by configs[${seen.get(correlationId)}] and configs[${i}]`);
|
|
598
|
+
}
|
|
599
|
+
seen.set(correlationId, i);
|
|
600
|
+
configByCorrelation.set(correlationId, cfg);
|
|
601
|
+
// Reuse toApiParams to guarantee wire parity with /scrape.
|
|
602
|
+
// Drop `key` (batch key is in the URL).
|
|
603
|
+
const params = cfg.toApiParams({ key: this.key });
|
|
604
|
+
delete params.key;
|
|
605
|
+
bodyConfigs.push(params);
|
|
606
|
+
}
|
|
607
|
+
const url = new URL(this.HOST + '/scrape/batch');
|
|
608
|
+
url.search = new URLSearchParams({ key: this.key }).toString();
|
|
609
|
+
const response = await this.fetch({
|
|
610
|
+
url: url.toString(),
|
|
611
|
+
method: 'POST',
|
|
612
|
+
headers: {
|
|
613
|
+
'user-agent': this.ua,
|
|
614
|
+
'content-type': 'application/json',
|
|
615
|
+
// gzip is universally supported in fetch runtimes; skip zstd
|
|
616
|
+
// for streaming compatibility (Node < 22 / browsers don't
|
|
617
|
+
// auto-decompress zstd yet).
|
|
618
|
+
'accept-encoding': 'gzip',
|
|
619
|
+
accept: acceptHeader,
|
|
620
|
+
},
|
|
621
|
+
body: JSON.stringify({ configs: bodyConfigs }),
|
|
622
|
+
});
|
|
623
|
+
if (response.status !== 200) {
|
|
624
|
+
const body = await response.text();
|
|
625
|
+
let parsed;
|
|
626
|
+
try {
|
|
627
|
+
parsed = JSON.parse(body);
|
|
628
|
+
}
|
|
629
|
+
catch {
|
|
630
|
+
parsed = { message: body, code: 'ERR::API::INTERNAL_ERROR' };
|
|
631
|
+
}
|
|
632
|
+
throw new errors.ApiHttpServerError(`scrapeBatch: ${parsed.code ?? 'error'} (HTTP ${response.status}): ${parsed.message ?? body}`);
|
|
633
|
+
}
|
|
634
|
+
for await (const part of iterBatchParts(response)) {
|
|
635
|
+
const correlationId = part.headers['x-scrapfly-correlation-id'] ?? '';
|
|
636
|
+
// Proxified-response parts: the part body is the raw upstream
|
|
637
|
+
// bytes, not a JSON envelope. Surface a native fetch Response
|
|
638
|
+
// so callers get the same shape as a single proxified scrape
|
|
639
|
+
// (which returns Response from .scrape()).
|
|
640
|
+
if (part.headers['x-scrapfly-proxified'] === 'true') {
|
|
641
|
+
try {
|
|
642
|
+
const proxResponse = buildProxifiedResponseFromPart(part);
|
|
643
|
+
yield [correlationId, proxResponse];
|
|
644
|
+
}
|
|
645
|
+
catch (proxErr) {
|
|
646
|
+
yield [
|
|
647
|
+
correlationId,
|
|
648
|
+
new errors.ScrapflyError(`scrapeBatch: failed to build proxified response for correlation_id=${JSON.stringify(correlationId)}: ${proxErr}`),
|
|
649
|
+
];
|
|
650
|
+
}
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
let parsed;
|
|
654
|
+
try {
|
|
655
|
+
parsed = decodePartBody(part);
|
|
656
|
+
}
|
|
657
|
+
catch (decodeErr) {
|
|
658
|
+
yield [
|
|
659
|
+
correlationId,
|
|
660
|
+
new errors.ScrapflyError(`scrapeBatch: failed to decode part for correlation_id=${JSON.stringify(correlationId)}: ${decodeErr}`),
|
|
661
|
+
];
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
try {
|
|
665
|
+
const result = new ScrapeResult({
|
|
666
|
+
config: parsed.config,
|
|
667
|
+
context: parsed.context,
|
|
668
|
+
result: parsed.result,
|
|
669
|
+
uuid: parsed.uuid,
|
|
670
|
+
});
|
|
671
|
+
yield [correlationId, result];
|
|
672
|
+
}
|
|
673
|
+
catch (resultErr) {
|
|
674
|
+
yield [
|
|
675
|
+
correlationId,
|
|
676
|
+
resultErr instanceof errors.ScrapflyError
|
|
677
|
+
? resultErr
|
|
678
|
+
: new errors.ScrapflyError(`scrapeBatch: ${resultErr}`),
|
|
679
|
+
];
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
501
683
|
/**
|
|
502
684
|
* Save screenshot response to a file
|
|
503
685
|
*/
|
|
@@ -522,17 +704,23 @@ export class ScrapflyClient {
|
|
|
522
704
|
* Turn scrapfly screenshot API response to ScreenshotResult or raise one of ScrapflyError
|
|
523
705
|
*/
|
|
524
706
|
async handleScreenshotResponse(response) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
707
|
+
// A Response body can only be consumed once. If the server returned
|
|
708
|
+
// JSON, parse it up front and reuse it on the error path — re-reading
|
|
709
|
+
// would yield "body stream already read" and mask the real error.
|
|
710
|
+
const isJson = response.headers.get('content-type') === 'application/json';
|
|
711
|
+
let jsonData = null;
|
|
712
|
+
if (isJson) {
|
|
713
|
+
jsonData = (await response.json());
|
|
714
|
+
if (jsonData.http_code == 401 || response.status == 401) {
|
|
715
|
+
throw new errors.BadApiKeyError(JSON.stringify(jsonData));
|
|
529
716
|
}
|
|
530
|
-
if ('error_id' in
|
|
531
|
-
throw new errors.ScreenshotApiError(JSON.stringify(
|
|
717
|
+
if ('error_id' in jsonData) {
|
|
718
|
+
throw new errors.ScreenshotApiError(JSON.stringify(jsonData));
|
|
532
719
|
}
|
|
533
720
|
}
|
|
534
721
|
if (!response.ok) {
|
|
535
|
-
|
|
722
|
+
const body = jsonData ?? (await response.text());
|
|
723
|
+
throw new errors.ScreenshotApiError(typeof body === 'string' ? body : JSON.stringify(body));
|
|
536
724
|
}
|
|
537
725
|
const data = await response.arrayBuffer();
|
|
538
726
|
const result = new ScreenshotResult(response, data);
|
|
@@ -568,6 +756,9 @@ export class ScrapflyClient {
|
|
|
568
756
|
* Turn scrapfly Extraction API response to ExtractionResult or raise one of ScrapflyError
|
|
569
757
|
*/
|
|
570
758
|
async handleExtractionResponse(response) {
|
|
759
|
+
// Body can only be consumed once — reuse the parsed JSON on the
|
|
760
|
+
// error path instead of re-reading, which would fail with
|
|
761
|
+
// "body stream already read".
|
|
571
762
|
const data = (await response.json());
|
|
572
763
|
if ('error_id' in data) {
|
|
573
764
|
if (data.http_code == 401 || response.status == 401) {
|
|
@@ -576,7 +767,7 @@ export class ScrapflyClient {
|
|
|
576
767
|
throw new errors.ExtractionApiError(JSON.stringify(data));
|
|
577
768
|
}
|
|
578
769
|
if (!response.ok) {
|
|
579
|
-
throw new errors.ApiHttpClientError(JSON.stringify(
|
|
770
|
+
throw new errors.ApiHttpClientError(JSON.stringify(data));
|
|
580
771
|
}
|
|
581
772
|
const result = new ExtractionResult({
|
|
582
773
|
data: data.data,
|
|
@@ -1034,6 +1225,8 @@ export class ScrapflyClient {
|
|
|
1034
1225
|
jsonBody.body = options.body;
|
|
1035
1226
|
if (options.method)
|
|
1036
1227
|
jsonBody.method = options.method;
|
|
1228
|
+
if (options.enable_mcp !== undefined)
|
|
1229
|
+
jsonBody.enable_mcp = options.enable_mcp;
|
|
1037
1230
|
const url = new URL(this.cloudBrowserApiHost + '/unblock');
|
|
1038
1231
|
url.searchParams.set('key', this.key);
|
|
1039
1232
|
const response = await this.fetch({
|
package/esm/main.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { BrowserConfig, ProxyPool, OperatingSystem } from './browserconfig.js';
|
|
|
6
6
|
export type { BrowserConfigOptions } from './browserconfig.js';
|
|
7
7
|
export * as errors from './errors.js';
|
|
8
8
|
export { ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
|
|
9
|
-
export type { AccountData, ConfigData, ContextData, ResultData, ScreenshotMetadata } from './result.js';
|
|
9
|
+
export type { AccountData, ClassifyOptions, ClassifyResult, ConfigData, ContextData, ResultData, ScreenshotMetadata } from './result.js';
|
|
10
10
|
export { CrawlerConfig } from './crawlerconfig.js';
|
|
11
11
|
export type { CrawlerConfigOptions, CrawlerContentFormat, CrawlerWebhookEventName } from './crawlerconfig.js';
|
|
12
12
|
export { Crawl } from './crawl.js';
|
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,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,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,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,uBAA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
|
export type ScrapeResultData = Record<string | number | symbol, never>;
|
|
208
|
+
export type ClassifyOptions = {
|
|
209
|
+
url: string;
|
|
210
|
+
statusCode: number;
|
|
211
|
+
headers?: Record<string, string>;
|
|
212
|
+
body?: string | null;
|
|
213
|
+
method?: string;
|
|
214
|
+
};
|
|
215
|
+
export type ClassifyResult = {
|
|
216
|
+
blocked: boolean;
|
|
217
|
+
antibot: string | null;
|
|
218
|
+
cost: number;
|
|
219
|
+
};
|
|
208
220
|
export type AccountData = {
|
|
209
221
|
account: {
|
|
210
222
|
account_id: string;
|
package/esm/result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,uBAAuB,EAAE,OAAO,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CA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EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEV,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE;CAKpF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scrapfly-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "SDK for Scrapfly.io API for web scraping, screenshotting and data extraction",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web scraping",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@msgpack/msgpack": "3.0.0",
|
|
31
32
|
"cheerio": "1.0.0-rc.12",
|
|
32
33
|
"@deno/shim-deno": "~0.18.0"
|
|
33
34
|
},
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming multipart/mixed parser for POST /scrape/batch.
|
|
3
|
+
*
|
|
4
|
+
* The API emits one part per scrape as each completes. This module
|
|
5
|
+
* reads the response body as a ReadableStream and yields
|
|
6
|
+
* `(headers, body)` pairs as each part lands.
|
|
7
|
+
*
|
|
8
|
+
* No external dependencies — uses Web Streams (native in Node 18+
|
|
9
|
+
* and all modern browsers).
|
|
10
|
+
*/
|
|
11
|
+
export interface BatchPart {
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
body: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Async iterator over multipart/mixed parts from a fetch Response.
|
|
17
|
+
*
|
|
18
|
+
* Yields one `BatchPart` per multipart section as it arrives on the
|
|
19
|
+
* wire. Throws if the response Content-Type is not multipart/mixed
|
|
20
|
+
* or the boundary is missing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function iterBatchParts(response: Response): AsyncGenerator<BatchPart>;
|
|
23
|
+
/**
|
|
24
|
+
* Decode a part body according to its content-type header. Supports
|
|
25
|
+
* both application/json (default) and application/msgpack.
|
|
26
|
+
*/
|
|
27
|
+
export declare function decodePartBody<T = unknown>(part: BatchPart): T;
|
|
28
|
+
/**
|
|
29
|
+
* Synthesize a native fetch `Response` from a proxified batch part.
|
|
30
|
+
* The part body is the raw upstream bytes and the part carries:
|
|
31
|
+
* * `Content-Type` — the upstream's content-type
|
|
32
|
+
* * `X-Scrapfly-Scrape-Status` — the upstream's HTTP status
|
|
33
|
+
* * `X-Scrapfly-Upstream-<Name>` — upstream response headers
|
|
34
|
+
* * `X-Scrapfly-Log-Uuid`, `X-Scrapfly-Content-Format` — scrapfly metadata
|
|
35
|
+
*
|
|
36
|
+
* We return a Response with those values restored so the caller
|
|
37
|
+
* gets the same shape as a single proxified scrape.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildProxifiedResponseFromPart(part: BatchPart): Response;
|
|
40
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAuB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CA4HnF;AAoBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,CAS9D;AAOD;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAiCxE"}
|
package/script/batch.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Streaming multipart/mixed parser for POST /scrape/batch.
|
|
4
|
+
*
|
|
5
|
+
* The API emits one part per scrape as each completes. This module
|
|
6
|
+
* reads the response body as a ReadableStream and yields
|
|
7
|
+
* `(headers, body)` pairs as each part lands.
|
|
8
|
+
*
|
|
9
|
+
* No external dependencies — uses Web Streams (native in Node 18+
|
|
10
|
+
* and all modern browsers).
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.iterBatchParts = iterBatchParts;
|
|
14
|
+
exports.decodePartBody = decodePartBody;
|
|
15
|
+
exports.buildProxifiedResponseFromPart = buildProxifiedResponseFromPart;
|
|
16
|
+
const CR = 0x0d;
|
|
17
|
+
const LF = 0x0a;
|
|
18
|
+
const CRLF = new Uint8Array([CR, LF]);
|
|
19
|
+
const DOUBLE_CRLF = new Uint8Array([CR, LF, CR, LF]);
|
|
20
|
+
function indexOf(buf, needle, start = 0) {
|
|
21
|
+
if (needle.length === 0)
|
|
22
|
+
return start;
|
|
23
|
+
const last = buf.length - needle.length;
|
|
24
|
+
outer: for (let i = start; i <= last; i++) {
|
|
25
|
+
for (let j = 0; j < needle.length; j++) {
|
|
26
|
+
if (buf[i + j] !== needle[j])
|
|
27
|
+
continue outer;
|
|
28
|
+
}
|
|
29
|
+
return i;
|
|
30
|
+
}
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
function concat(a, b) {
|
|
34
|
+
const out = new Uint8Array(a.length + b.length);
|
|
35
|
+
out.set(a, 0);
|
|
36
|
+
out.set(b, a.length);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function parseContentType(value) {
|
|
40
|
+
const semi = value.indexOf(';');
|
|
41
|
+
if (semi < 0)
|
|
42
|
+
return { mime: value.trim().toLowerCase(), params: {} };
|
|
43
|
+
const mime = value.slice(0, semi).trim().toLowerCase();
|
|
44
|
+
const params = {};
|
|
45
|
+
for (const piece of value.slice(semi + 1).split(';')) {
|
|
46
|
+
const eq = piece.indexOf('=');
|
|
47
|
+
if (eq < 0)
|
|
48
|
+
continue;
|
|
49
|
+
const k = piece.slice(0, eq).trim().toLowerCase();
|
|
50
|
+
let v = piece.slice(eq + 1).trim();
|
|
51
|
+
if (v.startsWith('"') && v.endsWith('"'))
|
|
52
|
+
v = v.slice(1, -1);
|
|
53
|
+
params[k] = v;
|
|
54
|
+
}
|
|
55
|
+
return { mime, params };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Async iterator over multipart/mixed parts from a fetch Response.
|
|
59
|
+
*
|
|
60
|
+
* Yields one `BatchPart` per multipart section as it arrives on the
|
|
61
|
+
* wire. Throws if the response Content-Type is not multipart/mixed
|
|
62
|
+
* or the boundary is missing.
|
|
63
|
+
*/
|
|
64
|
+
async function* iterBatchParts(response) {
|
|
65
|
+
const ct = response.headers.get('content-type') ?? '';
|
|
66
|
+
const { mime, params } = parseContentType(ct);
|
|
67
|
+
if (mime !== 'multipart/mixed') {
|
|
68
|
+
throw new Error(`scrapeBatch: expected Content-Type multipart/mixed, got ${JSON.stringify(ct)}`);
|
|
69
|
+
}
|
|
70
|
+
const boundaryStr = params['boundary'];
|
|
71
|
+
if (!boundaryStr) {
|
|
72
|
+
throw new Error(`scrapeBatch: Content-Type multipart/mixed is missing boundary parameter: ${JSON.stringify(ct)}`);
|
|
73
|
+
}
|
|
74
|
+
if (!response.body) {
|
|
75
|
+
throw new Error('scrapeBatch: response has no body stream');
|
|
76
|
+
}
|
|
77
|
+
const boundary = new TextEncoder().encode('--' + boundaryStr);
|
|
78
|
+
const nextBoundarySep = new TextEncoder().encode('\r\n--' + boundaryStr);
|
|
79
|
+
const reader = response.body.getReader();
|
|
80
|
+
let buf = new Uint8Array(0);
|
|
81
|
+
let eof = false;
|
|
82
|
+
let pastPrefix = false;
|
|
83
|
+
const pump = async () => {
|
|
84
|
+
if (eof)
|
|
85
|
+
return false;
|
|
86
|
+
const { done, value } = await reader.read();
|
|
87
|
+
if (done) {
|
|
88
|
+
eof = true;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (value && value.length > 0) {
|
|
92
|
+
// reader.read() returns Uint8Array<ArrayBufferLike> on newer Deno/TS
|
|
93
|
+
// lib types while dnt's Node target still sees Uint8Array as
|
|
94
|
+
// non-generic. Cast to the non-generic form so the same source
|
|
95
|
+
// type-checks on both targets.
|
|
96
|
+
buf = concat(buf, value);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
101
|
+
const readUntil = async (needle) => {
|
|
102
|
+
while (true) {
|
|
103
|
+
const idx = indexOf(buf, needle);
|
|
104
|
+
if (idx !== -1) {
|
|
105
|
+
const out = buf.subarray(0, idx);
|
|
106
|
+
buf = buf.subarray(idx + needle.length);
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
if (eof) {
|
|
110
|
+
const out = buf;
|
|
111
|
+
buf = new Uint8Array(0);
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
if (!(await pump())) {
|
|
115
|
+
const out = buf;
|
|
116
|
+
buf = new Uint8Array(0);
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const readExact = async (n) => {
|
|
122
|
+
while (buf.length < n && !eof) {
|
|
123
|
+
await pump();
|
|
124
|
+
}
|
|
125
|
+
const out = buf.subarray(0, Math.min(n, buf.length));
|
|
126
|
+
buf = buf.subarray(out.length);
|
|
127
|
+
return out;
|
|
128
|
+
};
|
|
129
|
+
while (true) {
|
|
130
|
+
if (!pastPrefix) {
|
|
131
|
+
await readUntil(boundary);
|
|
132
|
+
pastPrefix = true;
|
|
133
|
+
}
|
|
134
|
+
// After each --boundary, expect CRLF (more parts) or `--` (terminator).
|
|
135
|
+
// RFC 2046 mandates CRLF; any server deviating from that is broken —
|
|
136
|
+
// return cleanly rather than try to guess.
|
|
137
|
+
const suffix = await readExact(2);
|
|
138
|
+
if (suffix.length < 2)
|
|
139
|
+
return;
|
|
140
|
+
if (suffix[0] === 0x2d && suffix[1] === 0x2d) {
|
|
141
|
+
// Final boundary marker "--"
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!(suffix[0] === CR && suffix[1] === LF)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Read headers up to blank line (CRLF CRLF).
|
|
148
|
+
const headerBlock = await readUntil(DOUBLE_CRLF);
|
|
149
|
+
const headers = {};
|
|
150
|
+
for (const lineBytes of splitByCRLF(headerBlock)) {
|
|
151
|
+
const line = new TextDecoder('utf-8').decode(lineBytes);
|
|
152
|
+
const colon = line.indexOf(':');
|
|
153
|
+
if (colon <= 0)
|
|
154
|
+
continue;
|
|
155
|
+
headers[line.slice(0, colon).trim().toLowerCase()] = line.slice(colon + 1).trim();
|
|
156
|
+
}
|
|
157
|
+
// Body framing: prefer Content-Length (server always emits it).
|
|
158
|
+
// When Content-Length is known, yield the part IMMEDIATELY after
|
|
159
|
+
// reading the body bytes — don't wait for the next boundary
|
|
160
|
+
// separator to arrive. Otherwise the caller is blocked until
|
|
161
|
+
// part N+1 starts streaming, which defeats the whole point of
|
|
162
|
+
// per-part streaming (especially when scrape N+1 is a slow one).
|
|
163
|
+
let body;
|
|
164
|
+
const cl = headers['content-length'];
|
|
165
|
+
let readSeparatorAfterYield = false;
|
|
166
|
+
if (cl && /^\d+$/.test(cl)) {
|
|
167
|
+
body = await readExact(parseInt(cl, 10));
|
|
168
|
+
readSeparatorAfterYield = true;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
body = await readUntil(nextBoundarySep);
|
|
172
|
+
}
|
|
173
|
+
yield { headers, body };
|
|
174
|
+
// With Content-Length framing, the "\r\n--<boundary>" separator
|
|
175
|
+
// follows the body but is not part of it. Consume it now — any
|
|
176
|
+
// blocking that happens here blocks the NEXT iteration, not this
|
|
177
|
+
// part's delivery.
|
|
178
|
+
if (readSeparatorAfterYield) {
|
|
179
|
+
await readUntil(nextBoundarySep);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function splitByCRLF(buf) {
|
|
184
|
+
const out = [];
|
|
185
|
+
let start = 0;
|
|
186
|
+
for (let i = 0; i < buf.length - 1; i++) {
|
|
187
|
+
if (buf[i] === CR && buf[i + 1] === LF) {
|
|
188
|
+
out.push(buf.subarray(start, i));
|
|
189
|
+
start = i + 2;
|
|
190
|
+
i++;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (start < buf.length)
|
|
194
|
+
out.push(buf.subarray(start));
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
// msgpack decoder. The module is npm:@msgpack/msgpack — dnt rewrites
|
|
198
|
+
// this to a regular npm import in the published package.
|
|
199
|
+
const msgpack_1 = require("@msgpack/msgpack");
|
|
200
|
+
/**
|
|
201
|
+
* Decode a part body according to its content-type header. Supports
|
|
202
|
+
* both application/json (default) and application/msgpack.
|
|
203
|
+
*/
|
|
204
|
+
function decodePartBody(part) {
|
|
205
|
+
const ct = part.headers['content-type'] ?? 'application/json';
|
|
206
|
+
if (ct.startsWith('application/json')) {
|
|
207
|
+
return JSON.parse(new TextDecoder('utf-8').decode(part.body));
|
|
208
|
+
}
|
|
209
|
+
if (ct.startsWith('application/msgpack') || ct.startsWith('application/x-msgpack')) {
|
|
210
|
+
return (0, msgpack_1.decode)(part.body);
|
|
211
|
+
}
|
|
212
|
+
throw new Error(`scrapeBatch: unsupported part Content-Type: ${ct}`);
|
|
213
|
+
}
|
|
214
|
+
// Header prefix used by the server to forward upstream response
|
|
215
|
+
// headers on proxified batch parts (avoids collision with the
|
|
216
|
+
// multipart envelope's own headers).
|
|
217
|
+
const UPSTREAM_PREFIX = 'x-scrapfly-upstream-';
|
|
218
|
+
/**
|
|
219
|
+
* Synthesize a native fetch `Response` from a proxified batch part.
|
|
220
|
+
* The part body is the raw upstream bytes and the part carries:
|
|
221
|
+
* * `Content-Type` — the upstream's content-type
|
|
222
|
+
* * `X-Scrapfly-Scrape-Status` — the upstream's HTTP status
|
|
223
|
+
* * `X-Scrapfly-Upstream-<Name>` — upstream response headers
|
|
224
|
+
* * `X-Scrapfly-Log-Uuid`, `X-Scrapfly-Content-Format` — scrapfly metadata
|
|
225
|
+
*
|
|
226
|
+
* We return a Response with those values restored so the caller
|
|
227
|
+
* gets the same shape as a single proxified scrape.
|
|
228
|
+
*/
|
|
229
|
+
function buildProxifiedResponseFromPart(part) {
|
|
230
|
+
const statusHeader = part.headers['x-scrapfly-scrape-status'];
|
|
231
|
+
const status = statusHeader ? parseInt(statusHeader, 10) || 200 : 200;
|
|
232
|
+
const headers = new Headers();
|
|
233
|
+
for (const [key, value] of Object.entries(part.headers)) {
|
|
234
|
+
const lower = key.toLowerCase();
|
|
235
|
+
if (lower === 'content-type') {
|
|
236
|
+
headers.set('Content-Type', value);
|
|
237
|
+
}
|
|
238
|
+
else if (lower.startsWith(UPSTREAM_PREFIX)) {
|
|
239
|
+
headers.set(key.slice(UPSTREAM_PREFIX.length), value);
|
|
240
|
+
}
|
|
241
|
+
else if (lower.startsWith('x-scrapfly-')) {
|
|
242
|
+
headers.set(key, value);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// Normalize X-Scrapfly-Log-Uuid → X-Scrapfly-Log for parity with
|
|
246
|
+
// the single-scrape proxified response headers.
|
|
247
|
+
if (!headers.has('X-Scrapfly-Log') && headers.has('X-Scrapfly-Log-Uuid')) {
|
|
248
|
+
headers.set('X-Scrapfly-Log', headers.get('X-Scrapfly-Log-Uuid') ?? '');
|
|
249
|
+
}
|
|
250
|
+
// Wrap the Uint8Array in an ArrayBuffer so fetch Response accepts
|
|
251
|
+
// it (Node's fetch is picky about BodyInit).
|
|
252
|
+
// Copy into a fresh ArrayBuffer to avoid SharedArrayBuffer edge
|
|
253
|
+
// cases when the underlying bytes came from a larger buffer.
|
|
254
|
+
const bodyBuffer = new Uint8Array(part.body.length);
|
|
255
|
+
bodyBuffer.set(part.body);
|
|
256
|
+
return new Response(bodyBuffer, {
|
|
257
|
+
status,
|
|
258
|
+
headers,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
@@ -28,6 +28,7 @@ export type BrowserConfigOptions = {
|
|
|
28
28
|
unblock?: boolean;
|
|
29
29
|
unblock_timeout?: number;
|
|
30
30
|
browser_brand?: string;
|
|
31
|
+
enable_mcp?: boolean;
|
|
31
32
|
};
|
|
32
33
|
export declare class BrowserConfig {
|
|
33
34
|
proxy_pool?: string;
|
|
@@ -50,6 +51,7 @@ export declare class BrowserConfig {
|
|
|
50
51
|
unblock?: boolean;
|
|
51
52
|
unblock_timeout?: number;
|
|
52
53
|
browser_brand?: string;
|
|
54
|
+
enable_mcp?: boolean;
|
|
53
55
|
constructor(options?: BrowserConfigOptions);
|
|
54
56
|
/**
|
|
55
57
|
* Generate the WebSocket URL for a Cloud Browser session.
|