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/esm/result.js
CHANGED
|
@@ -41,9 +41,9 @@ export class ScrapeResult {
|
|
|
41
41
|
}
|
|
42
42
|
get selector() {
|
|
43
43
|
if (!this._selector) {
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
46
|
-
throw new errors.ContentTypeError(`Cannot use selector on non-html content-type, received: ${
|
|
44
|
+
const contentType = normalizeHeaders(this.result.response_headers)['content-type'] ?? '';
|
|
45
|
+
if (!contentType.includes('text/html')) {
|
|
46
|
+
throw new errors.ContentTypeError(`Cannot use selector on non-html content-type, received: ${contentType}`);
|
|
47
47
|
}
|
|
48
48
|
this._selector = cheerio.load(this.result.content);
|
|
49
49
|
}
|
|
@@ -51,7 +51,7 @@ export class ScrapeResult {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
export class ScreenshotResult {
|
|
54
|
-
constructor(response, data) {
|
|
54
|
+
constructor(response, data, job_uuid = null) {
|
|
55
55
|
Object.defineProperty(this, "image", {
|
|
56
56
|
enumerable: true,
|
|
57
57
|
configurable: true,
|
|
@@ -70,9 +70,18 @@ export class ScreenshotResult {
|
|
|
70
70
|
writable: true,
|
|
71
71
|
value: void 0
|
|
72
72
|
});
|
|
73
|
+
/** The job of a screenshot with a webhook: the image is delivered to the webhook, `image` and `metadata` are empty. */
|
|
74
|
+
Object.defineProperty(this, "job_uuid", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
73
80
|
this.image = data;
|
|
74
|
-
this.metadata =
|
|
81
|
+
this.metadata =
|
|
82
|
+
job_uuid === null ? this.defineMetadata(response) : { extension_name: '', upstream_status_code: 0, upstream_url: '' };
|
|
75
83
|
this.result = this.decodeResponse(response, data); // raw result
|
|
84
|
+
this.job_uuid = job_uuid;
|
|
76
85
|
}
|
|
77
86
|
defineMetadata(response) {
|
|
78
87
|
const headers = normalizeHeaders(response.headers);
|
package/esm/scrapeconfig.d.ts
CHANGED
|
@@ -47,10 +47,35 @@ type ScrapeConfigOptions = {
|
|
|
47
47
|
cost_budget?: number;
|
|
48
48
|
ssl?: boolean;
|
|
49
49
|
dns?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The Unblocker (anti-bot bypass), the current name for what used to be
|
|
52
|
+
* called `asp`. Sent to the API as the `asp` query parameter; only the
|
|
53
|
+
* SDK-facing name changed.
|
|
54
|
+
*
|
|
55
|
+
* @deprecated Use `proxy_pool` (`ScrapeConfig.UNBLOCKER_ULTRA` for the
|
|
56
|
+
* Unblocker). The migration guide covers requests written before the proxy
|
|
57
|
+
* pools: https://scrapfly.io/new-pricing#legacy-spellings
|
|
58
|
+
*/
|
|
59
|
+
unblocker?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Alias of {@link unblocker}: use `proxy_pool`
|
|
62
|
+
* (`ScrapeConfig.UNBLOCKER_ULTRA` for the Unblocker). When both are supplied
|
|
63
|
+
* `asp` wins, so existing code cannot have its meaning changed by a later
|
|
64
|
+
* `unblocker`.
|
|
65
|
+
*/
|
|
50
66
|
asp?: boolean;
|
|
51
67
|
debug?: boolean;
|
|
52
68
|
raise_on_upstream_error?: boolean;
|
|
53
69
|
cache_ttl?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Proxy pool: `basic` (datacenter proxies, Unblocker off), `unblocker`
|
|
72
|
+
* (residential proxies and the Unblocker), `unblocker_ultra` (residential
|
|
73
|
+
* proxies and the Unblocker, the only pool accepted by the targets and
|
|
74
|
+
* anti-bot protections that have a price of their own: they refuse `basic`
|
|
75
|
+
* and `unblocker` with `ERR::PROXY::UNBLOCKER_ULTRA_REQUIRED`) or `auto`
|
|
76
|
+
* (the API picks the pool from the target's profile), see
|
|
77
|
+
* {@link ScrapeConfig.BASIC}. Each sets the Unblocker itself.
|
|
78
|
+
*/
|
|
54
79
|
proxy_pool?: string;
|
|
55
80
|
session?: string;
|
|
56
81
|
tags?: string[];
|
|
@@ -102,9 +127,13 @@ type ScrapeConfigOptions = {
|
|
|
102
127
|
geolocation?: string;
|
|
103
128
|
};
|
|
104
129
|
export declare class ScrapeConfig {
|
|
130
|
+
static BASIC: string;
|
|
131
|
+
static UNBLOCKER: string;
|
|
132
|
+
static UNBLOCKER_ULTRA: string;
|
|
133
|
+
static AUTO: string;
|
|
134
|
+
static PUBLIC_TOR_POOL: string;
|
|
105
135
|
static PUBLIC_DATACENTER_POOL: string;
|
|
106
136
|
static PUBLIC_RESIDENTIAL_POOL: string;
|
|
107
|
-
static PUBLIC_TOR_POOL: string;
|
|
108
137
|
url: string;
|
|
109
138
|
retry: boolean;
|
|
110
139
|
method: HttpMethod;
|
|
@@ -115,10 +144,24 @@ export declare class ScrapeConfig {
|
|
|
115
144
|
cost_budget?: number;
|
|
116
145
|
ssl: boolean;
|
|
117
146
|
dns: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Storage for the anti-bot bypass toggle, under its deprecated name.
|
|
149
|
+
* `unblocker` is an accessor over this same field — see below.
|
|
150
|
+
*
|
|
151
|
+
* @deprecated Use `proxy_pool` (`ScrapeConfig.UNBLOCKER_ULTRA` for the Unblocker).
|
|
152
|
+
*/
|
|
118
153
|
asp: boolean;
|
|
119
154
|
debug: boolean;
|
|
120
155
|
raise_on_upstream_error: boolean;
|
|
121
156
|
cache_ttl?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Proxy pool: `basic` (datacenter proxies, Unblocker off), `unblocker`
|
|
159
|
+
* (residential proxies and the Unblocker), `unblocker_ultra` (residential
|
|
160
|
+
* proxies and the Unblocker, the only pool accepted by the targets and
|
|
161
|
+
* anti-bot protections that have a price of their own) or `auto` (the API
|
|
162
|
+
* picks the pool from the target's profile), see {@link ScrapeConfig.BASIC}.
|
|
163
|
+
* Each sets the Unblocker itself.
|
|
164
|
+
*/
|
|
122
165
|
proxy_pool?: string;
|
|
123
166
|
session?: string;
|
|
124
167
|
tags: Set<string>;
|
|
@@ -150,6 +193,27 @@ export declare class ScrapeConfig {
|
|
|
150
193
|
rendering_stage?: 'complete' | 'domcontentloaded';
|
|
151
194
|
geolocation?: string;
|
|
152
195
|
constructor(options: ScrapeConfigOptions);
|
|
196
|
+
/**
|
|
197
|
+
* The Unblocker toggle, the current name for what used to be `asp`.
|
|
198
|
+
* Deprecated: use `proxy_pool` (`ScrapeConfig.UNBLOCKER_ULTRA` for the
|
|
199
|
+
* Unblocker). The migration guide covers requests written before the proxy
|
|
200
|
+
* pools: https://scrapfly.io/new-pricing#legacy-spellings
|
|
201
|
+
*
|
|
202
|
+
* An accessor over the single `asp` field rather than a second stored
|
|
203
|
+
* property: one storage slot means the two names can never disagree, so
|
|
204
|
+
* `config.unblocker = true` after construction is exactly `config.asp = true`
|
|
205
|
+
* and `toApiParams` has one value to read. It also keeps `unblocker` out of
|
|
206
|
+
* the instance's own keys, so serializers that iterate them do not sprout a
|
|
207
|
+
* duplicate of `asp`.
|
|
208
|
+
*/
|
|
209
|
+
get unblocker(): boolean;
|
|
210
|
+
set unblocker(value: boolean);
|
|
211
|
+
/**
|
|
212
|
+
* Option names the constructor accepts that are not own properties of the
|
|
213
|
+
* instance. `unblocker` is an accessor, so it lives on the prototype and the
|
|
214
|
+
* `Object.keys(this)` allow-list below never sees it.
|
|
215
|
+
*/
|
|
216
|
+
private static readonly ALIAS_OPTION_KEYS;
|
|
153
217
|
private validateOptions;
|
|
154
218
|
toApiParams(options: {
|
|
155
219
|
key: string;
|
|
@@ -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;CA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AAiB,CAA+C;IAExF,OAAO,CAAC,eAAe;IASvB,WAAW,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CA0L3D"}
|
package/esm/scrapeconfig.js
CHANGED
|
@@ -103,6 +103,12 @@ export class ScrapeConfig {
|
|
|
103
103
|
writable: true,
|
|
104
104
|
value: false
|
|
105
105
|
});
|
|
106
|
+
/**
|
|
107
|
+
* Storage for the anti-bot bypass toggle, under its deprecated name.
|
|
108
|
+
* `unblocker` is an accessor over this same field — see below.
|
|
109
|
+
*
|
|
110
|
+
* @deprecated Use `proxy_pool` (`ScrapeConfig.UNBLOCKER_ULTRA` for the Unblocker).
|
|
111
|
+
*/
|
|
106
112
|
Object.defineProperty(this, "asp", {
|
|
107
113
|
enumerable: true,
|
|
108
114
|
configurable: true,
|
|
@@ -127,6 +133,14 @@ export class ScrapeConfig {
|
|
|
127
133
|
writable: true,
|
|
128
134
|
value: void 0
|
|
129
135
|
});
|
|
136
|
+
/**
|
|
137
|
+
* Proxy pool: `basic` (datacenter proxies, Unblocker off), `unblocker`
|
|
138
|
+
* (residential proxies and the Unblocker), `unblocker_ultra` (residential
|
|
139
|
+
* proxies and the Unblocker, the only pool accepted by the targets and
|
|
140
|
+
* anti-bot protections that have a price of their own) or `auto` (the API
|
|
141
|
+
* picks the pool from the target's profile), see {@link ScrapeConfig.BASIC}.
|
|
142
|
+
* Each sets the Unblocker itself.
|
|
143
|
+
*/
|
|
130
144
|
Object.defineProperty(this, "proxy_pool", {
|
|
131
145
|
enumerable: true,
|
|
132
146
|
configurable: true,
|
|
@@ -335,7 +349,11 @@ export class ScrapeConfig {
|
|
|
335
349
|
this.cache = options.cache ?? this.cache;
|
|
336
350
|
this.cache_clear = options.cache_clear ?? this.cache_clear;
|
|
337
351
|
this.cost_budget = options.cost_budget ?? this.cost_budget;
|
|
338
|
-
|
|
352
|
+
// `asp` is the deprecated alias of `unblocker` and an explicitly supplied
|
|
353
|
+
// `asp` always wins; `unblocker` applies only when `asp` was not supplied.
|
|
354
|
+
// `??` and not `||`, so an explicit `false` on either name turns the
|
|
355
|
+
// feature off instead of falling through to the other name.
|
|
356
|
+
this.asp = options.asp ?? options.unblocker ?? this.asp;
|
|
339
357
|
this.headers = options.headers
|
|
340
358
|
? Object.fromEntries(Object.entries(options.headers).map(([k, v]) => [k.toLowerCase(), v]))
|
|
341
359
|
: {};
|
|
@@ -400,10 +418,29 @@ export class ScrapeConfig {
|
|
|
400
418
|
}
|
|
401
419
|
}
|
|
402
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* The Unblocker toggle, the current name for what used to be `asp`.
|
|
423
|
+
* Deprecated: use `proxy_pool` (`ScrapeConfig.UNBLOCKER_ULTRA` for the
|
|
424
|
+
* Unblocker). The migration guide covers requests written before the proxy
|
|
425
|
+
* pools: https://scrapfly.io/new-pricing#legacy-spellings
|
|
426
|
+
*
|
|
427
|
+
* An accessor over the single `asp` field rather than a second stored
|
|
428
|
+
* property: one storage slot means the two names can never disagree, so
|
|
429
|
+
* `config.unblocker = true` after construction is exactly `config.asp = true`
|
|
430
|
+
* and `toApiParams` has one value to read. It also keeps `unblocker` out of
|
|
431
|
+
* the instance's own keys, so serializers that iterate them do not sprout a
|
|
432
|
+
* duplicate of `asp`.
|
|
433
|
+
*/
|
|
434
|
+
get unblocker() {
|
|
435
|
+
return this.asp;
|
|
436
|
+
}
|
|
437
|
+
set unblocker(value) {
|
|
438
|
+
this.asp = value;
|
|
439
|
+
}
|
|
403
440
|
validateOptions(options) {
|
|
404
441
|
const validKeys = new Set(Object.keys(this));
|
|
405
442
|
for (const key in options) {
|
|
406
|
-
if (!validKeys.has(key)) {
|
|
443
|
+
if (!validKeys.has(key) && !ScrapeConfig.ALIAS_OPTION_KEYS.has(key)) {
|
|
407
444
|
throw new ScrapeConfigError(`Invalid option provided: ${key}`);
|
|
408
445
|
}
|
|
409
446
|
}
|
|
@@ -502,6 +539,11 @@ export class ScrapeConfig {
|
|
|
502
539
|
log.warn('Params "rendering_wait" is ignored. Works only if render_js is enabled');
|
|
503
540
|
}
|
|
504
541
|
}
|
|
542
|
+
// The wire key stays `asp` for both names. A published package version is
|
|
543
|
+
// immutable and upgraded per installation, so emitting `unblocker` against
|
|
544
|
+
// an API deployment that has not learned that name yet would silently drop
|
|
545
|
+
// a paid feature: the scrape succeeds, is billed, and returns a blocked
|
|
546
|
+
// page. Renaming the emitted key is a separate, later release.
|
|
505
547
|
if (this.asp === true) {
|
|
506
548
|
params.asp = true;
|
|
507
549
|
}
|
|
@@ -585,6 +627,43 @@ export class ScrapeConfig {
|
|
|
585
627
|
return params;
|
|
586
628
|
}
|
|
587
629
|
}
|
|
630
|
+
// Proxy pools, sent as `proxy_pool`. Each sets both the proxies and the
|
|
631
|
+
// Unblocker. AUTO lets the API pick the pool before the request, from the
|
|
632
|
+
// target's profile: the Unblocker on datacenter proxies, or the pool the
|
|
633
|
+
// target needs, priced as the pool it runs on.
|
|
634
|
+
Object.defineProperty(ScrapeConfig, "BASIC", {
|
|
635
|
+
enumerable: true,
|
|
636
|
+
configurable: true,
|
|
637
|
+
writable: true,
|
|
638
|
+
value: 'basic'
|
|
639
|
+
});
|
|
640
|
+
Object.defineProperty(ScrapeConfig, "UNBLOCKER", {
|
|
641
|
+
enumerable: true,
|
|
642
|
+
configurable: true,
|
|
643
|
+
writable: true,
|
|
644
|
+
value: 'unblocker'
|
|
645
|
+
});
|
|
646
|
+
Object.defineProperty(ScrapeConfig, "UNBLOCKER_ULTRA", {
|
|
647
|
+
enumerable: true,
|
|
648
|
+
configurable: true,
|
|
649
|
+
writable: true,
|
|
650
|
+
value: 'unblocker_ultra'
|
|
651
|
+
});
|
|
652
|
+
Object.defineProperty(ScrapeConfig, "AUTO", {
|
|
653
|
+
enumerable: true,
|
|
654
|
+
configurable: true,
|
|
655
|
+
writable: true,
|
|
656
|
+
value: 'auto'
|
|
657
|
+
});
|
|
658
|
+
// The Tor network, the only pool that reaches .onion hidden services.
|
|
659
|
+
Object.defineProperty(ScrapeConfig, "PUBLIC_TOR_POOL", {
|
|
660
|
+
enumerable: true,
|
|
661
|
+
configurable: true,
|
|
662
|
+
writable: true,
|
|
663
|
+
value: 'public_tor_pool'
|
|
664
|
+
});
|
|
665
|
+
// Pool names written before the proxy pools, still accepted. The migration
|
|
666
|
+
// guide covers them: https://scrapfly.io/new-pricing#legacy-spellings
|
|
588
667
|
Object.defineProperty(ScrapeConfig, "PUBLIC_DATACENTER_POOL", {
|
|
589
668
|
enumerable: true,
|
|
590
669
|
configurable: true,
|
|
@@ -597,9 +676,14 @@ Object.defineProperty(ScrapeConfig, "PUBLIC_RESIDENTIAL_POOL", {
|
|
|
597
676
|
writable: true,
|
|
598
677
|
value: 'public_residential_pool'
|
|
599
678
|
});
|
|
600
|
-
|
|
679
|
+
/**
|
|
680
|
+
* Option names the constructor accepts that are not own properties of the
|
|
681
|
+
* instance. `unblocker` is an accessor, so it lives on the prototype and the
|
|
682
|
+
* `Object.keys(this)` allow-list below never sees it.
|
|
683
|
+
*/
|
|
684
|
+
Object.defineProperty(ScrapeConfig, "ALIAS_OPTION_KEYS", {
|
|
601
685
|
enumerable: true,
|
|
602
686
|
configurable: true,
|
|
603
687
|
writable: true,
|
|
604
|
-
value: '
|
|
688
|
+
value: new Set(['unblocker'])
|
|
605
689
|
});
|
|
@@ -17,7 +17,7 @@ export declare enum Format {
|
|
|
17
17
|
PNG = "png",
|
|
18
18
|
/** WebP encoding. */
|
|
19
19
|
WEBP = "webp",
|
|
20
|
-
/**
|
|
20
|
+
/** GIF encoding, single frame. */
|
|
21
21
|
GIF = "gif"
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -76,6 +76,12 @@ type ScreenshotConfigOptions = {
|
|
|
76
76
|
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
77
77
|
/** Webhook name to notify when the screenshot completes. */
|
|
78
78
|
webhook?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Proxy pool: `basic`, `unblocker`, `unblocker_ultra` or `auto` (see
|
|
81
|
+
* `ScrapeConfig.BASIC`); any other value is ignored here. Unset, the API's
|
|
82
|
+
* screenshot defaults apply. The screenshot price is the same on every pool.
|
|
83
|
+
*/
|
|
84
|
+
proxy_pool?: string;
|
|
79
85
|
};
|
|
80
86
|
/**
|
|
81
87
|
* Configuration for a single screenshot request. Instances are passed
|
|
@@ -105,6 +111,8 @@ export declare class ScreenshotConfig {
|
|
|
105
111
|
cache_clear?: boolean;
|
|
106
112
|
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
107
113
|
webhook?: string;
|
|
114
|
+
/** Proxy pool: `basic`, `unblocker`, `unblocker_ultra` or `auto`; any other value is ignored here. */
|
|
115
|
+
proxy_pool?: string;
|
|
108
116
|
constructor(options: ScreenshotConfigOptions);
|
|
109
117
|
private validateOptions;
|
|
110
118
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotconfig.d.ts","sourceRoot":"","sources":["../src/screenshotconfig.ts"],"names":[],"mappings":"AAIA,6DAA6D;AAC7D,oBAAY,OAAO;IACjB,qEAAqE;IACrE,WAAW,gBAAgB;IAC3B,oCAAoC;IACpC,SAAS,cAAc;IACvB,+EAA+E;IAC/E,aAAa,kBAAkB;IAC/B,qDAAqD;IACrD,kBAAkB,uBAAuB;CAC1C;AAED,6CAA6C;AAC7C,oBAAY,MAAM;IAChB,qBAAqB;IACrB,GAAG,QAAQ;IACX,oBAAoB;IACpB,GAAG,QAAQ;IACX,qBAAqB;IACrB,IAAI,SAAS;IACb,
|
|
1
|
+
{"version":3,"file":"screenshotconfig.d.ts","sourceRoot":"","sources":["../src/screenshotconfig.ts"],"names":[],"mappings":"AAIA,6DAA6D;AAC7D,oBAAY,OAAO;IACjB,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AAG,YAAY,GAAG,eAAe,GAAG,eAAe,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;IAC5I,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sGAAsG;IACtG,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,OAAO,EAAE,uBAAuB;IAgC5C,OAAO,CAAC,eAAe;IASvB;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CA6E3D"}
|
package/esm/screenshotconfig.js
CHANGED
|
@@ -22,7 +22,7 @@ export var Format;
|
|
|
22
22
|
Format["PNG"] = "png";
|
|
23
23
|
/** WebP encoding. */
|
|
24
24
|
Format["WEBP"] = "webp";
|
|
25
|
-
/**
|
|
25
|
+
/** GIF encoding, single frame. */
|
|
26
26
|
Format["GIF"] = "gif";
|
|
27
27
|
})(Format || (Format = {}));
|
|
28
28
|
/**
|
|
@@ -153,6 +153,13 @@ export class ScreenshotConfig {
|
|
|
153
153
|
writable: true,
|
|
154
154
|
value: void 0
|
|
155
155
|
});
|
|
156
|
+
/** Proxy pool: `basic`, `unblocker`, `unblocker_ultra` or `auto`; any other value is ignored here. */
|
|
157
|
+
Object.defineProperty(this, "proxy_pool", {
|
|
158
|
+
enumerable: true,
|
|
159
|
+
configurable: true,
|
|
160
|
+
writable: true,
|
|
161
|
+
value: void 0
|
|
162
|
+
});
|
|
156
163
|
this.validateOptions(options);
|
|
157
164
|
if (options.format && !Object.values(Format).includes(options.format)) {
|
|
158
165
|
throw new ScreenshotConfigError(`Invalid Format param value: ${options.format}`);
|
|
@@ -181,6 +188,7 @@ export class ScreenshotConfig {
|
|
|
181
188
|
this.cache_clear = options.cache_clear ?? this.cache_clear;
|
|
182
189
|
this.vision_deficiency = options.vision_deficiency ?? this.vision_deficiency;
|
|
183
190
|
this.webhook = options.webhook;
|
|
191
|
+
this.proxy_pool = options.proxy_pool;
|
|
184
192
|
}
|
|
185
193
|
validateOptions(options) {
|
|
186
194
|
const validKeys = new Set(Object.keys(this));
|
|
@@ -255,6 +263,9 @@ export class ScreenshotConfig {
|
|
|
255
263
|
if (this.webhook) {
|
|
256
264
|
params.webhook_name = this.webhook;
|
|
257
265
|
}
|
|
266
|
+
if (this.proxy_pool) {
|
|
267
|
+
params.proxy_pool = this.proxy_pool;
|
|
268
|
+
}
|
|
258
269
|
return params;
|
|
259
270
|
}
|
|
260
271
|
}
|
package/esm/types.d.ts
CHANGED
|
@@ -9,10 +9,25 @@ export type Vault = {
|
|
|
9
9
|
name: string;
|
|
10
10
|
description?: string;
|
|
11
11
|
item_count?: number;
|
|
12
|
+
/** Number of mirrored rows. Populated by `cloudBrowserVaultGet` only. */
|
|
13
|
+
linked_item_count?: number;
|
|
14
|
+
vault_type?: VaultType;
|
|
15
|
+
linked_service?: VaultLinkedService;
|
|
16
|
+
/** Stored `linked_service_data`, which carries the server-owned `token_item_id`. */
|
|
17
|
+
linked_service_data?: VaultOnePasswordData & {
|
|
18
|
+
token_item_id?: string;
|
|
19
|
+
};
|
|
20
|
+
linked_sync_at?: string;
|
|
21
|
+
linked_sync_started_at?: string;
|
|
22
|
+
linked_sync_status?: VaultSyncStatus;
|
|
23
|
+
linked_sync_error?: string;
|
|
24
|
+
linked_sync_counts?: VaultSyncCounts;
|
|
12
25
|
created_at?: string;
|
|
13
26
|
updated_at?: string;
|
|
14
27
|
[k: string]: unknown;
|
|
15
28
|
};
|
|
29
|
+
/** Whether a vault's items are operator-entered or mirrored from a provider. */
|
|
30
|
+
export type VaultType = 'manual' | 'linked_service';
|
|
16
31
|
/** Discriminator for the secret payload of a {@link VaultItem}. */
|
|
17
32
|
export type VaultItemType = 'password' | 'passkey' | 'cookie' | 'totp';
|
|
18
33
|
/**
|
|
@@ -81,10 +96,30 @@ export type VaultItem = {
|
|
|
81
96
|
secret_blob?: string;
|
|
82
97
|
master_key_version?: number;
|
|
83
98
|
metadata?: Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* Provenance. Anything other than `manual` is owned by the linked-service
|
|
101
|
+
* syncer: the item endpoints refuse to mutate such a row, and the next sync
|
|
102
|
+
* overwrites or deletes it.
|
|
103
|
+
*/
|
|
104
|
+
source?: VaultItemSource;
|
|
105
|
+
/** Upstream diff key; set on mirrored rows only. */
|
|
106
|
+
source_ref?: string;
|
|
107
|
+
/** Opaque upstream revision the sync diff compares without decrypting. */
|
|
108
|
+
source_version?: string;
|
|
109
|
+
source_synced_at?: string;
|
|
84
110
|
created_at?: string;
|
|
85
111
|
updated_at?: string;
|
|
86
112
|
[k: string]: unknown;
|
|
87
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* `source` of a {@link VaultItem}. The sealed provider token is never listed.
|
|
116
|
+
*
|
|
117
|
+
* Server-written. The server's own domain is wider, reserving `service_token`,
|
|
118
|
+
* but that row is never returned to a caller so it is not listed here. Kept as
|
|
119
|
+
* literals so a mirrored row reads as plain data; comparing it against
|
|
120
|
+
* `VaultLinkedService.ONE_PASSWORD` still type-checks.
|
|
121
|
+
*/
|
|
122
|
+
export type VaultItemSource = 'manual' | `${VaultLinkedService}`;
|
|
88
123
|
/** Payload accepted by `cloudBrowserVaultItemCreate`. */
|
|
89
124
|
export type VaultItemCreate = {
|
|
90
125
|
type: VaultItemType;
|
|
@@ -94,4 +129,97 @@ export type VaultItemCreate = {
|
|
|
94
129
|
secret: VaultSecret;
|
|
95
130
|
metadata?: Record<string, unknown>;
|
|
96
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Linked-service discriminator, and the only closed value set a caller has to
|
|
134
|
+
* name when linking. 1Password is the sole entry in the server's linked-service
|
|
135
|
+
* registry; anything else is a 400, not a typed provider error.
|
|
136
|
+
*/
|
|
137
|
+
export declare enum VaultLinkedService {
|
|
138
|
+
/**
|
|
139
|
+
* 1Password service account. Also the `source` written on every row its
|
|
140
|
+
* syncer mirrors.
|
|
141
|
+
*/
|
|
142
|
+
ONE_PASSWORD = "1password"
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Accepted on the wire: the enum member or its own string value. Derived from
|
|
146
|
+
* {@link VaultLinkedService} so the literal is declared once; the server
|
|
147
|
+
* registry, not this type, is the authority on what links.
|
|
148
|
+
*/
|
|
149
|
+
export type VaultLinkedServiceValue = `${VaultLinkedService}`;
|
|
150
|
+
/**
|
|
151
|
+
* When the mirror is refreshed. `on_session` refreshes at most once per
|
|
152
|
+
* `sync_ttl_s` when a Cloud Browser session opens the vault; `manual` only
|
|
153
|
+
* syncs on `cloudBrowserVaultServiceSync`. (`live` is rejected by the server.)
|
|
154
|
+
*/
|
|
155
|
+
export type VaultSyncMode = 'manual' | 'on_session';
|
|
156
|
+
/** Outcome of the last sync round, as stored on the vault row. */
|
|
157
|
+
export type VaultSyncStatus = 'running' | 'ok' | 'partial' | 'auth_failed' | 'rate_limited' | 'scope_error' | 'unavailable' | 'error';
|
|
158
|
+
/**
|
|
159
|
+
* Non-secret selection rules of a 1Password link (`linked_service_data`).
|
|
160
|
+
*
|
|
161
|
+
* `vault_id` or `vault_name` is required — the server rejects a document with
|
|
162
|
+
* neither. `token_item_id` is deliberately absent: the server binds it when the
|
|
163
|
+
* token is sealed, and a PATCH body cannot redirect the token lookup because
|
|
164
|
+
* the stored id always wins.
|
|
165
|
+
*/
|
|
166
|
+
export type VaultOnePasswordData = {
|
|
167
|
+
/** Upstream vault id. Survives an upstream rename, unlike `vault_name`. */
|
|
168
|
+
vault_id?: string;
|
|
169
|
+
vault_name?: string;
|
|
170
|
+
/** Glob over upstream item titles, 128 characters max. */
|
|
171
|
+
title_filter?: string;
|
|
172
|
+
/** At most 16 tags. */
|
|
173
|
+
tags?: string[];
|
|
174
|
+
sync_mode?: VaultSyncMode;
|
|
175
|
+
/** Refresh TTL in seconds, 60 .. 86400. Defaults to 900 server-side. */
|
|
176
|
+
sync_ttl_s?: number;
|
|
177
|
+
};
|
|
178
|
+
/** Payload accepted by `cloudBrowserVaultServiceLink`. */
|
|
179
|
+
export type VaultServiceLink = {
|
|
180
|
+
/**
|
|
181
|
+
* Required: `POST /vault/{id}/service` has no server-side default. The raw
|
|
182
|
+
* wire value stays assignable so untyped JavaScript callers keep working.
|
|
183
|
+
*/
|
|
184
|
+
linked_service: VaultLinkedServiceValue;
|
|
185
|
+
/** Provider service-account token. Sealed under the vault key on arrival. */
|
|
186
|
+
token: string;
|
|
187
|
+
linked_service_data: VaultOnePasswordData;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Payload accepted by `cloudBrowserVaultServiceUpdate`. `linked_service` is not
|
|
191
|
+
* settable: the stored discriminator is what the server updates against.
|
|
192
|
+
*/
|
|
193
|
+
export type VaultServiceUpdate = {
|
|
194
|
+
/** Rotates the sealed token. Requires the vault key; omit for a config-only edit. */
|
|
195
|
+
token?: string;
|
|
196
|
+
linked_service_data?: VaultOnePasswordData;
|
|
197
|
+
};
|
|
198
|
+
/** Per-round reconcile counts, also stored as `linked_sync_counts`. */
|
|
199
|
+
export type VaultSyncCounts = {
|
|
200
|
+
imported: number;
|
|
201
|
+
updated: number;
|
|
202
|
+
deleted: number;
|
|
203
|
+
/** Rows the reconcile refused, which is what makes a round `partial`. */
|
|
204
|
+
skipped: number;
|
|
205
|
+
/** Upstream items the provider could not map. Does not make a round partial. */
|
|
206
|
+
unmirrored: number;
|
|
207
|
+
};
|
|
208
|
+
/** Body of `cloudBrowserVaultServiceSync`. */
|
|
209
|
+
export type VaultSyncReport = VaultSyncCounts & {
|
|
210
|
+
status: VaultSyncStatus;
|
|
211
|
+
warnings?: string[];
|
|
212
|
+
};
|
|
213
|
+
/** One upstream vault the service account can read. */
|
|
214
|
+
export type VaultProbeVault = {
|
|
215
|
+
id: string;
|
|
216
|
+
title: string;
|
|
217
|
+
};
|
|
218
|
+
/** Body of `cloudBrowserVaultServiceTest`. Reads nothing and writes nothing. */
|
|
219
|
+
export type VaultProbeResult = {
|
|
220
|
+
vaults_visible: VaultProbeVault[];
|
|
221
|
+
/** Active items in the selected upstream vault; 0 when none is selected yet. */
|
|
222
|
+
item_count: number;
|
|
223
|
+
warnings?: string[];
|
|
224
|
+
};
|
|
97
225
|
//# sourceMappingURL=types.d.ts.map
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACvC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACvC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAWnE,kEAAkE;AAClE,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAG3B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACpC,oFAAoF;IACpF,mBAAmB,CAAC,EAAE,oBAAoB,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sBA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types.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Linked secret managers (1Password).
|
|
3
|
+
//
|
|
4
|
+
// A linked vault mirrors an upstream secret manager: the provider's
|
|
5
|
+
// service-account token is sealed under the vault key as a reserved item, and
|
|
6
|
+
// the syncer owns every row it imports. The token travels in the request body
|
|
7
|
+
// of link / update / test and is NEVER stored by the caller, logged, or echoed
|
|
8
|
+
// back by the server.
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/**
|
|
11
|
+
* Linked-service discriminator, and the only closed value set a caller has to
|
|
12
|
+
* name when linking. 1Password is the sole entry in the server's linked-service
|
|
13
|
+
* registry; anything else is a 400, not a typed provider error.
|
|
14
|
+
*/
|
|
15
|
+
export var VaultLinkedService;
|
|
16
|
+
(function (VaultLinkedService) {
|
|
17
|
+
/**
|
|
18
|
+
* 1Password service account. Also the `source` written on every row its
|
|
19
|
+
* syncer mirrors.
|
|
20
|
+
*/
|
|
21
|
+
VaultLinkedService["ONE_PASSWORD"] = "1password";
|
|
22
|
+
})(VaultLinkedService || (VaultLinkedService = {}));
|
package/esm/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;IAMd,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC;CAClC,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;IAMd,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC;CAClC,CAAC;AAcF,wBAAsB,UAAU,CAC9B,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAa,GACxB,OAAO,CAAC,QAAQ,CAAC,CA+CnB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAc5E"}
|
package/esm/utils.js
CHANGED
|
@@ -8,6 +8,18 @@ export function urlsafe_b64encode(data) {
|
|
|
8
8
|
.replace(/=+$/, '');
|
|
9
9
|
return base64;
|
|
10
10
|
}
|
|
11
|
+
const KEY_IN_URL = /(?<=[?&]key=)[^&\s)'"]+/g;
|
|
12
|
+
/**
|
|
13
|
+
* Mask the API key in a fetch error, in place: Deno prints the request URL,
|
|
14
|
+
* query and key included, in the message and in the stack it captured.
|
|
15
|
+
*/
|
|
16
|
+
function maskKey(error) {
|
|
17
|
+
if (!(error instanceof Error))
|
|
18
|
+
return;
|
|
19
|
+
error.message = error.message.replace(KEY_IN_URL, 'REDACTED');
|
|
20
|
+
if (error.stack !== undefined)
|
|
21
|
+
error.stack = error.stack.replace(KEY_IN_URL, 'REDACTED');
|
|
22
|
+
}
|
|
11
23
|
export async function fetchRetry(config, retries = 3, retryDelay = 1000) {
|
|
12
24
|
let lastError = null;
|
|
13
25
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
@@ -26,8 +38,9 @@ export async function fetchRetry(config, retries = 3, retryDelay = 1000) {
|
|
|
26
38
|
body: reqInit.body,
|
|
27
39
|
};
|
|
28
40
|
const response = await fetch(new Request(url, init));
|
|
29
|
-
//
|
|
30
|
-
|
|
41
|
+
// Retry 5xx status codes. A single-attempt caller reads the 5xx body
|
|
42
|
+
// itself: it carries the typed error.
|
|
43
|
+
if (response.status >= 500 && response.status < 600 && retries > 1) {
|
|
31
44
|
const _text = await response.text(); // consume response to prevent leak
|
|
32
45
|
lastError = new Error(`Fetch failed with status: ${response.status}`);
|
|
33
46
|
if (attempt < retries) {
|
|
@@ -40,6 +53,7 @@ export async function fetchRetry(config, retries = 3, retryDelay = 1000) {
|
|
|
40
53
|
}
|
|
41
54
|
}
|
|
42
55
|
catch (error) {
|
|
56
|
+
maskKey(error);
|
|
43
57
|
lastError = error;
|
|
44
58
|
// AbortError should never be retried: it means the caller explicitly
|
|
45
59
|
// gave up (cancel token, timeout, etc.) and we shouldn't paper over it.
|