scrapely 1.2.3 → 1.2.5
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 +119 -1
- package/dist/actor.d.ts +703 -0
- package/dist/actor.js +1441 -0
- package/dist/browser-configuration.d.ts +58 -0
- package/dist/browser-configuration.js +128 -0
- package/dist/browser-locations.d.ts +5 -0
- package/dist/browser-locations.js +5469 -0
- package/dist/charging.d.ts +153 -0
- package/dist/charging.js +782 -0
- package/dist/charging_client.d.ts +18 -0
- package/dist/charging_client.js +49 -0
- package/dist/configuration.d.ts +121 -0
- package/dist/configuration.js +128 -0
- package/dist/crypto/secrets.d.ts +44 -0
- package/dist/crypto/secrets.js +164 -0
- package/dist/events/events-client.d.ts +59 -0
- package/dist/events/events-client.js +120 -0
- package/dist/events/scrapely-event-manager.d.ts +13 -0
- package/dist/events/scrapely-event-manager.js +61 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +95 -0
- package/dist/log-env.d.ts +1 -0
- package/dist/log-env.js +12 -0
- package/dist/manifest.d.ts +30 -0
- package/dist/manifest.js +47 -0
- package/dist/patch-browser-pool.d.ts +66 -0
- package/dist/patch-browser-pool.js +827 -0
- package/dist/proxy-configuration.d.ts +118 -0
- package/dist/proxy-configuration.js +88 -0
- package/dist/request-list.d.ts +57 -0
- package/dist/request-list.js +79 -0
- package/dist/runner/docker-manager.d.ts +88 -0
- package/dist/runner/docker-manager.js +283 -0
- package/dist/runner/index.d.ts +2 -0
- package/dist/runner/index.js +7 -0
- package/dist/runner/timeout-manager.d.ts +43 -0
- package/dist/runner/timeout-manager.js +90 -0
- package/dist/scrapely-proxy-configuration.d.ts +99 -0
- package/dist/scrapely-proxy-configuration.js +559 -0
- package/dist/storage/api-storage-client.d.ts +199 -0
- package/dist/storage/api-storage-client.js +910 -0
- package/dist/storage/billing-tracker.d.ts +163 -0
- package/dist/storage/billing-tracker.js +260 -0
- package/dist/storage/dataset-client.d.ts +43 -0
- package/dist/storage/dataset-client.js +232 -0
- package/dist/storage/dataset-collection-client.d.ts +8 -0
- package/dist/storage/dataset-collection-client.js +75 -0
- package/dist/storage/dataset-push-script.d.ts +18 -0
- package/dist/storage/dataset-push-script.js +38 -0
- package/dist/storage/dragonfly-client.d.ts +94 -0
- package/dist/storage/dragonfly-client.js +167 -0
- package/dist/storage/index.d.ts +11 -0
- package/dist/storage/index.js +25 -0
- package/dist/storage/key-value-store-client.d.ts +61 -0
- package/dist/storage/key-value-store-client.js +306 -0
- package/dist/storage/kv-store-collection-client.d.ts +8 -0
- package/dist/storage/kv-store-collection-client.js +76 -0
- package/dist/storage/kvs-iteration.d.ts +17 -0
- package/dist/storage/kvs-iteration.js +126 -0
- package/dist/storage/log-manager.d.ts +114 -0
- package/dist/storage/log-manager.js +244 -0
- package/dist/storage/patch-storage.d.ts +11 -0
- package/dist/storage/patch-storage.js +177 -0
- package/dist/storage/request-queue-client.d.ts +93 -0
- package/dist/storage/request-queue-client.js +522 -0
- package/dist/storage/rq-collection-client.d.ts +8 -0
- package/dist/storage/rq-collection-client.js +89 -0
- package/dist/storage/rq-list-requests.d.ts +59 -0
- package/dist/storage/rq-list-requests.js +114 -0
- package/dist/storage/rq-lock-script.d.ts +56 -0
- package/dist/storage/rq-lock-script.js +127 -0
- package/dist/storage/run-metadata.d.ts +98 -0
- package/dist/storage/run-metadata.js +256 -0
- package/dist/storage/s3-client.d.ts +103 -0
- package/dist/storage/s3-client.js +302 -0
- package/dist/storage/ttl-manager.d.ts +70 -0
- package/dist/storage/ttl-manager.js +115 -0
- package/dist/storage/utils.d.ts +3 -0
- package/dist/storage/utils.js +19 -0
- package/dist/storage-identifiers.d.ts +20 -0
- package/dist/storage-identifiers.js +6 -0
- package/dist/utils.d.ts +54 -0
- package/dist/utils.js +63 -0
- package/dist/validator.d.ts +24 -0
- package/dist/validator.js +158 -0
- package/package.json +90 -9
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options of the Scrapely remote browser (Evomi websocket parameters).
|
|
3
|
+
* Passed to browser crawlers as `browserConfiguration`, next to
|
|
4
|
+
* `proxyConfiguration`, or to a raw `chromium.launch({ browserConfiguration })`.
|
|
5
|
+
*/
|
|
6
|
+
export interface BrowserConfigurationOptions {
|
|
7
|
+
/** Exit country, ISO 3166-1 alpha-2 (e.g. `US`). Sent as `proxy_country`. */
|
|
8
|
+
countryCode?: string;
|
|
9
|
+
/** Region name, not an ISO code (e.g. `California`). Sent as `proxy_state`. */
|
|
10
|
+
state?: string;
|
|
11
|
+
/** City name (e.g. `San Jose`). Sent as `proxy_city`. */
|
|
12
|
+
city?: string;
|
|
13
|
+
/** Fingerprint operating system. Sent as `os`. */
|
|
14
|
+
os?: 'windows' | 'macos' | 'android';
|
|
15
|
+
/** IANA timezone (e.g. `Asia/Tokyo`). Defaults to the exit country's primary zone. */
|
|
16
|
+
timezone?: string;
|
|
17
|
+
/** Comma-separated language tags without q-values (e.g. `de-CH,de`). */
|
|
18
|
+
language?: string;
|
|
19
|
+
/** Built-in ad/tracker blocking. Browser default: off. */
|
|
20
|
+
adblock?: boolean;
|
|
21
|
+
/** Automatic Cloudflare Turnstile solving. Browser default: on. */
|
|
22
|
+
solveCloudflare?: boolean;
|
|
23
|
+
/** Actor-input alias for `countryCode`. */
|
|
24
|
+
browserCountry?: string;
|
|
25
|
+
/** Actor-input alias for `state`. */
|
|
26
|
+
browserState?: string;
|
|
27
|
+
/** Actor-input alias for `city`. */
|
|
28
|
+
browserCity?: string;
|
|
29
|
+
}
|
|
30
|
+
type NormalizedOptions = Omit<BrowserConfigurationOptions, 'browserCountry' | 'browserState' | 'browserCity'>;
|
|
31
|
+
/**
|
|
32
|
+
* Scrapely remote browser configuration: location and fingerprint options
|
|
33
|
+
* applied to the browser connection (the remote browser brings its own
|
|
34
|
+
* proxy — custom proxies are not supported for browsers).
|
|
35
|
+
*
|
|
36
|
+
* ```javascript
|
|
37
|
+
* const browserConfiguration = await Actor.createBrowserConfiguration({ countryCode: 'US', state: 'California' });
|
|
38
|
+
* const crawler = new PlaywrightCrawler({ browserConfiguration, requestHandler });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Outside the Scrapely remote browser (local runs, unpatched builds) the
|
|
42
|
+
* option is accepted and ignored, so the same code runs everywhere.
|
|
43
|
+
*/
|
|
44
|
+
export declare class BrowserConfiguration {
|
|
45
|
+
readonly options: Readonly<NormalizedOptions>;
|
|
46
|
+
constructor(options?: BrowserConfigurationOptions);
|
|
47
|
+
/** Remote browser websocket parameters set by this configuration. */
|
|
48
|
+
toCdpParams(): Record<string, string>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a {@link BrowserConfiguration} (async for parity with
|
|
52
|
+
* `createProxyConfiguration`). Actor input fields `browserCountry` /
|
|
53
|
+
* `browserState` / `browserCity` can be spread straight in.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createBrowserConfiguration(options?: BrowserConfigurationOptions): Promise<BrowserConfiguration>;
|
|
56
|
+
/** @internal Whether a value can be applied as a browser configuration. */
|
|
57
|
+
export declare function isBrowserConfiguration(value: unknown): value is Pick<BrowserConfiguration, 'toCdpParams'>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserConfiguration = void 0;
|
|
4
|
+
exports.createBrowserConfiguration = createBrowserConfiguration;
|
|
5
|
+
exports.isBrowserConfiguration = isBrowserConfiguration;
|
|
6
|
+
const BROWSER_OS_VALUES = ['windows', 'macos', 'android'];
|
|
7
|
+
const MAX_TIMEZONE_LENGTH = 64;
|
|
8
|
+
const MAX_LANGUAGE_LENGTH = 128;
|
|
9
|
+
function fail(field, message) {
|
|
10
|
+
throw new Error(`BrowserConfiguration: "${field}" ${message}`);
|
|
11
|
+
}
|
|
12
|
+
function requireString(field, value) {
|
|
13
|
+
if (typeof value !== 'string')
|
|
14
|
+
fail(field, `must be a string (got ${typeof value}).`);
|
|
15
|
+
const trimmed = value.trim();
|
|
16
|
+
if (!trimmed)
|
|
17
|
+
fail(field, 'must not be empty.');
|
|
18
|
+
return trimmed;
|
|
19
|
+
}
|
|
20
|
+
/** Evomi location format: lowercase, dots for spaces (`New York` → `new.york`). */
|
|
21
|
+
function normalizeLocationName(field, value) {
|
|
22
|
+
return requireString(field, value).toLowerCase().replace(/\s+/g, '.');
|
|
23
|
+
}
|
|
24
|
+
function requireBoolean(field, value) {
|
|
25
|
+
if (typeof value !== 'boolean')
|
|
26
|
+
fail(field, `must be a boolean (got ${typeof value}).`);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function normalizeOptions(input) {
|
|
30
|
+
const out = {};
|
|
31
|
+
const countryCode = input.countryCode ?? input.browserCountry;
|
|
32
|
+
if (countryCode != null) {
|
|
33
|
+
const code = requireString('countryCode', countryCode).toUpperCase();
|
|
34
|
+
if (!/^[A-Z]{2}$/.test(code)) {
|
|
35
|
+
fail('countryCode', `must be a two-letter ISO 3166-1 country code (got "${countryCode}").`);
|
|
36
|
+
}
|
|
37
|
+
out.countryCode = code;
|
|
38
|
+
}
|
|
39
|
+
const state = input.state ?? input.browserState;
|
|
40
|
+
if (state != null)
|
|
41
|
+
out.state = normalizeLocationName('state', state);
|
|
42
|
+
const city = input.city ?? input.browserCity;
|
|
43
|
+
if (city != null)
|
|
44
|
+
out.city = normalizeLocationName('city', city);
|
|
45
|
+
if (input.os != null) {
|
|
46
|
+
const os = requireString('os', input.os).toLowerCase();
|
|
47
|
+
if (!BROWSER_OS_VALUES.includes(os)) {
|
|
48
|
+
fail('os', `must be one of ${BROWSER_OS_VALUES.join(', ')} (got "${input.os}").`);
|
|
49
|
+
}
|
|
50
|
+
out.os = os;
|
|
51
|
+
}
|
|
52
|
+
if (input.timezone != null) {
|
|
53
|
+
const timezone = requireString('timezone', input.timezone);
|
|
54
|
+
if (timezone.length > MAX_TIMEZONE_LENGTH) {
|
|
55
|
+
fail('timezone', `must be at most ${MAX_TIMEZONE_LENGTH} characters.`);
|
|
56
|
+
}
|
|
57
|
+
out.timezone = timezone;
|
|
58
|
+
}
|
|
59
|
+
if (input.language != null) {
|
|
60
|
+
const language = requireString('language', input.language);
|
|
61
|
+
if (language.length > MAX_LANGUAGE_LENGTH) {
|
|
62
|
+
fail('language', `must be at most ${MAX_LANGUAGE_LENGTH} characters.`);
|
|
63
|
+
}
|
|
64
|
+
if (/;\s*q=/i.test(language)) {
|
|
65
|
+
fail('language', 'must be a plain tag list without q-values (e.g. "de-CH,de").');
|
|
66
|
+
}
|
|
67
|
+
out.language = language;
|
|
68
|
+
}
|
|
69
|
+
if (input.adblock != null)
|
|
70
|
+
out.adblock = requireBoolean('adblock', input.adblock);
|
|
71
|
+
if (input.solveCloudflare != null)
|
|
72
|
+
out.solveCloudflare = requireBoolean('solveCloudflare', input.solveCloudflare);
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Scrapely remote browser configuration: location and fingerprint options
|
|
77
|
+
* applied to the browser connection (the remote browser brings its own
|
|
78
|
+
* proxy — custom proxies are not supported for browsers).
|
|
79
|
+
*
|
|
80
|
+
* ```javascript
|
|
81
|
+
* const browserConfiguration = await Actor.createBrowserConfiguration({ countryCode: 'US', state: 'California' });
|
|
82
|
+
* const crawler = new PlaywrightCrawler({ browserConfiguration, requestHandler });
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* Outside the Scrapely remote browser (local runs, unpatched builds) the
|
|
86
|
+
* option is accepted and ignored, so the same code runs everywhere.
|
|
87
|
+
*/
|
|
88
|
+
class BrowserConfiguration {
|
|
89
|
+
options;
|
|
90
|
+
constructor(options = {}) {
|
|
91
|
+
this.options = Object.freeze(normalizeOptions(options ?? {}));
|
|
92
|
+
}
|
|
93
|
+
/** Remote browser websocket parameters set by this configuration. */
|
|
94
|
+
toCdpParams() {
|
|
95
|
+
const { countryCode, state, city, os, timezone, language, adblock, solveCloudflare } = this.options;
|
|
96
|
+
const params = {};
|
|
97
|
+
if (countryCode)
|
|
98
|
+
params.proxy_country = countryCode;
|
|
99
|
+
if (state)
|
|
100
|
+
params.proxy_state = state;
|
|
101
|
+
if (city)
|
|
102
|
+
params.proxy_city = city;
|
|
103
|
+
if (os)
|
|
104
|
+
params.os = os;
|
|
105
|
+
if (timezone)
|
|
106
|
+
params.timezone = timezone;
|
|
107
|
+
if (language)
|
|
108
|
+
params.language = language;
|
|
109
|
+
if (adblock !== undefined)
|
|
110
|
+
params.adblock = String(adblock);
|
|
111
|
+
if (solveCloudflare !== undefined)
|
|
112
|
+
params.solve_cloudflare = String(solveCloudflare);
|
|
113
|
+
return params;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.BrowserConfiguration = BrowserConfiguration;
|
|
117
|
+
/**
|
|
118
|
+
* Create a {@link BrowserConfiguration} (async for parity with
|
|
119
|
+
* `createProxyConfiguration`). Actor input fields `browserCountry` /
|
|
120
|
+
* `browserState` / `browserCity` can be spread straight in.
|
|
121
|
+
*/
|
|
122
|
+
async function createBrowserConfiguration(options = {}) {
|
|
123
|
+
return new BrowserConfiguration(options);
|
|
124
|
+
}
|
|
125
|
+
/** @internal Whether a value can be applied as a browser configuration. */
|
|
126
|
+
function isBrowserConfiguration(value) {
|
|
127
|
+
return !!value && typeof value.toCdpParams === 'function';
|
|
128
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map an ISO 3166-2 subdivision code (e.g. `US` + `CA`) to the browser's
|
|
3
|
+
* `proxy_state` name (`california`). Returns undefined for unmapped codes.
|
|
4
|
+
*/
|
|
5
|
+
export declare function subdivisionToStateName(country: string | undefined, code: string | undefined): string | undefined;
|