@crawlee/core 3.13.6-beta.1 → 4.0.0-beta.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/autoscaling/autoscaled_pool.d.ts +3 -3
- package/autoscaling/autoscaled_pool.d.ts.map +1 -1
- package/autoscaling/autoscaled_pool.js +76 -225
- package/autoscaling/autoscaled_pool.js.map +1 -1
- package/autoscaling/index.d.ts +3 -3
- package/autoscaling/index.d.ts.map +1 -1
- package/autoscaling/index.js +3 -6
- package/autoscaling/index.js.map +1 -1
- package/autoscaling/snapshotter.d.ts +3 -3
- package/autoscaling/snapshotter.d.ts.map +1 -1
- package/autoscaling/snapshotter.js +42 -137
- package/autoscaling/snapshotter.js.map +1 -1
- package/autoscaling/system_status.d.ts +2 -2
- package/autoscaling/system_status.d.ts.map +1 -1
- package/autoscaling/system_status.js +20 -55
- package/autoscaling/system_status.js.map +1 -1
- package/configuration.d.ts +4 -4
- package/configuration.d.ts.map +1 -1
- package/configuration.js +79 -126
- package/configuration.js.map +1 -1
- package/cookie_utils.js +17 -25
- package/cookie_utils.js.map +1 -1
- package/crawlers/crawler_commons.d.ts +9 -8
- package/crawlers/crawler_commons.d.ts.map +1 -1
- package/crawlers/crawler_commons.js +47 -121
- package/crawlers/crawler_commons.js.map +1 -1
- package/crawlers/crawler_extension.d.ts +1 -1
- package/crawlers/crawler_extension.d.ts.map +1 -1
- package/crawlers/crawler_extension.js +4 -20
- package/crawlers/crawler_extension.js.map +1 -1
- package/crawlers/crawler_utils.d.ts +1 -1
- package/crawlers/crawler_utils.d.ts.map +1 -1
- package/crawlers/crawler_utils.js +3 -6
- package/crawlers/crawler_utils.js.map +1 -1
- package/crawlers/error_snapshotter.d.ts +3 -3
- package/crawlers/error_snapshotter.d.ts.map +1 -1
- package/crawlers/error_snapshotter.js +8 -38
- package/crawlers/error_snapshotter.js.map +1 -1
- package/crawlers/error_tracker.d.ts +2 -2
- package/crawlers/error_tracker.d.ts.map +1 -1
- package/crawlers/error_tracker.js +18 -40
- package/crawlers/error_tracker.js.map +1 -1
- package/crawlers/index.d.ts +6 -6
- package/crawlers/index.d.ts.map +1 -1
- package/crawlers/index.js +6 -9
- package/crawlers/index.js.map +1 -1
- package/crawlers/statistics.d.ts +3 -3
- package/crawlers/statistics.d.ts.map +1 -1
- package/crawlers/statistics.js +59 -167
- package/crawlers/statistics.js.map +1 -1
- package/enqueue_links/enqueue_links.d.ts +2 -2
- package/enqueue_links/enqueue_links.d.ts.map +1 -1
- package/enqueue_links/enqueue_links.js +41 -47
- package/enqueue_links/enqueue_links.js.map +1 -1
- package/enqueue_links/index.d.ts +2 -2
- package/enqueue_links/index.d.ts.map +1 -1
- package/enqueue_links/index.js +2 -5
- package/enqueue_links/index.js.map +1 -1
- package/enqueue_links/shared.d.ts +4 -4
- package/enqueue_links/shared.d.ts.map +1 -1
- package/enqueue_links/shared.js +23 -35
- package/enqueue_links/shared.js.map +1 -1
- package/errors.js +5 -13
- package/errors.js.map +1 -1
- package/events/event_manager.d.ts +1 -1
- package/events/event_manager.d.ts.map +1 -1
- package/events/event_manager.js +16 -45
- package/events/event_manager.js.map +1 -1
- package/events/index.d.ts +2 -2
- package/events/index.d.ts.map +1 -1
- package/events/index.js +2 -5
- package/events/index.js.map +1 -1
- package/events/local_event_manager.d.ts +1 -1
- package/events/local_event_manager.d.ts.map +1 -1
- package/events/local_event_manager.js +15 -28
- package/events/local_event_manager.js.map +1 -1
- package/http_clients/base-http-client.d.ts +1 -1
- package/http_clients/base-http-client.d.ts.map +1 -1
- package/http_clients/base-http-client.js +5 -8
- package/http_clients/base-http-client.js.map +1 -1
- package/http_clients/form-data-like.js +1 -2
- package/http_clients/form-data-like.js.map +1 -1
- package/http_clients/got-scraping-http-client.d.ts +1 -1
- package/http_clients/got-scraping-http-client.d.ts.map +1 -1
- package/http_clients/got-scraping-http-client.js +6 -11
- package/http_clients/got-scraping-http-client.js.map +1 -1
- package/http_clients/index.d.ts +2 -2
- package/http_clients/index.d.ts.map +1 -1
- package/http_clients/index.js +2 -5
- package/http_clients/index.js.map +1 -1
- package/index.d.ts +16 -16
- package/index.d.ts.map +1 -1
- package/index.js +17 -22
- package/index.js.map +1 -1
- package/log.js +2 -11
- package/log.js.map +1 -1
- package/package.json +27 -33
- package/proxy_configuration.d.ts +1 -1
- package/proxy_configuration.d.ts.map +1 -1
- package/proxy_configuration.js +22 -78
- package/proxy_configuration.js.map +1 -1
- package/request.d.ts +2 -2
- package/request.d.ts.map +1 -1
- package/request.js +76 -147
- package/request.js.map +1 -1
- package/router.d.ts +3 -3
- package/router.d.ts.map +1 -1
- package/router.js +6 -21
- package/router.js.map +1 -1
- package/serialization.d.ts.map +1 -1
- package/serialization.js +22 -44
- package/serialization.js.map +1 -1
- package/session_pool/consts.js +3 -6
- package/session_pool/consts.js.map +1 -1
- package/session_pool/errors.js +3 -11
- package/session_pool/errors.js.map +1 -1
- package/session_pool/events.js +1 -4
- package/session_pool/events.js.map +1 -1
- package/session_pool/index.d.ts +5 -5
- package/session_pool/index.d.ts.map +1 -1
- package/session_pool/index.js +5 -8
- package/session_pool/index.js.map +1 -1
- package/session_pool/session.d.ts +3 -17
- package/session_pool/session.d.ts.map +1 -1
- package/session_pool/session.js +52 -116
- package/session_pool/session.js.map +1 -1
- package/session_pool/session_pool.d.ts +7 -7
- package/session_pool/session_pool.d.ts.map +1 -1
- package/session_pool/session_pool.js +42 -126
- package/session_pool/session_pool.js.map +1 -1
- package/storages/access_checking.d.ts +1 -1
- package/storages/access_checking.d.ts.map +1 -1
- package/storages/access_checking.js +4 -9
- package/storages/access_checking.js.map +1 -1
- package/storages/dataset.d.ts +4 -4
- package/storages/dataset.d.ts.map +1 -1
- package/storages/dataset.js +45 -76
- package/storages/dataset.js.map +1 -1
- package/storages/index.d.ts +11 -11
- package/storages/index.d.ts.map +1 -1
- package/storages/index.js +11 -18
- package/storages/index.js.map +1 -1
- package/storages/key_value_store.d.ts +3 -3
- package/storages/key_value_store.d.ts.map +1 -1
- package/storages/key_value_store.js +62 -102
- package/storages/key_value_store.js.map +1 -1
- package/storages/request_list.d.ts +3 -3
- package/storages/request_list.d.ts.map +1 -1
- package/storages/request_list.js +83 -183
- package/storages/request_list.js.map +1 -1
- package/storages/request_provider.d.ts +5 -5
- package/storages/request_provider.d.ts.map +1 -1
- package/storages/request_provider.js +97 -201
- package/storages/request_provider.js.map +1 -1
- package/storages/request_queue.d.ts +4 -4
- package/storages/request_queue.d.ts.map +1 -1
- package/storages/request_queue.js +27 -40
- package/storages/request_queue.js.map +1 -1
- package/storages/request_queue_v2.d.ts +4 -4
- package/storages/request_queue_v2.d.ts.map +1 -1
- package/storages/request_queue_v2.js +18 -42
- package/storages/request_queue_v2.js.map +1 -1
- package/storages/sitemap_request_list.d.ts +4 -4
- package/storages/sitemap_request_list.d.ts.map +1 -1
- package/storages/sitemap_request_list.js +96 -181
- package/storages/sitemap_request_list.js.map +1 -1
- package/storages/storage_manager.d.ts +3 -3
- package/storages/storage_manager.d.ts.map +1 -1
- package/storages/storage_manager.js +14 -42
- package/storages/storage_manager.js.map +1 -1
- package/storages/utils.d.ts +1 -1
- package/storages/utils.d.ts.map +1 -1
- package/storages/utils.js +16 -23
- package/storages/utils.js.map +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/typedefs.js +2 -6
- package/typedefs.js.map +1 -1
- package/validators.js +6 -10
- package/validators.js.map +1 -1
- package/index.mjs +0 -88
package/configuration.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const log_1 = tslib_1.__importStar(require("@apify/log"));
|
|
11
|
-
const events_1 = require("./events");
|
|
12
|
-
const typedefs_1 = require("./typedefs");
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { MemoryStorage } from '@crawlee/memory-storage';
|
|
6
|
+
import { pathExistsSync } from 'fs-extra/esm';
|
|
7
|
+
import log, { LogLevel } from '@apify/log';
|
|
8
|
+
import { LocalEventManager } from './events/local_event_manager.js';
|
|
9
|
+
import { entries } from './typedefs.js';
|
|
13
10
|
/**
|
|
14
11
|
* `Configuration` is a value object holding Crawlee configuration. By default, there is a
|
|
15
12
|
* global singleton instance of this class available via `Configuration.getGlobalConfig()`.
|
|
@@ -76,39 +73,79 @@ const typedefs_1 = require("./typedefs");
|
|
|
76
73
|
* `systemInfoV2` | `CRAWLEE_SYSTEM_INFO_V2` | false
|
|
77
74
|
* `containerized | `CRAWLEE_CONTAINERIZED | -
|
|
78
75
|
*/
|
|
79
|
-
class Configuration {
|
|
76
|
+
export class Configuration {
|
|
77
|
+
/**
|
|
78
|
+
* Maps environment variables to config keys (e.g. `CRAWLEE_MEMORY_MBYTES` to `memoryMbytes`)
|
|
79
|
+
*/
|
|
80
|
+
static ENV_MAP = {
|
|
81
|
+
CRAWLEE_AVAILABLE_MEMORY_RATIO: 'availableMemoryRatio',
|
|
82
|
+
CRAWLEE_PURGE_ON_START: 'purgeOnStart',
|
|
83
|
+
CRAWLEE_MEMORY_MBYTES: 'memoryMbytes',
|
|
84
|
+
CRAWLEE_DEFAULT_DATASET_ID: 'defaultDatasetId',
|
|
85
|
+
CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID: 'defaultKeyValueStoreId',
|
|
86
|
+
CRAWLEE_DEFAULT_REQUEST_QUEUE_ID: 'defaultRequestQueueId',
|
|
87
|
+
CRAWLEE_INPUT_KEY: 'inputKey',
|
|
88
|
+
CRAWLEE_PERSIST_STATE_INTERVAL_MILLIS: 'persistStateIntervalMillis',
|
|
89
|
+
CRAWLEE_HEADLESS: 'headless',
|
|
90
|
+
CRAWLEE_XVFB: 'xvfb',
|
|
91
|
+
CRAWLEE_CHROME_EXECUTABLE_PATH: 'chromeExecutablePath',
|
|
92
|
+
CRAWLEE_DEFAULT_BROWSER_PATH: 'defaultBrowserPath',
|
|
93
|
+
CRAWLEE_DISABLE_BROWSER_SANDBOX: 'disableBrowserSandbox',
|
|
94
|
+
CRAWLEE_LOG_LEVEL: 'logLevel',
|
|
95
|
+
CRAWLEE_PERSIST_STORAGE: 'persistStorage',
|
|
96
|
+
CRAWLEE_SYSTEM_INFO_V2: 'systemInfoV2',
|
|
97
|
+
CRAWLEE_CONTAINERIZED: 'containerized',
|
|
98
|
+
};
|
|
99
|
+
static BOOLEAN_VARS = [
|
|
100
|
+
'purgeOnStart',
|
|
101
|
+
'headless',
|
|
102
|
+
'xvfb',
|
|
103
|
+
'disableBrowserSandbox',
|
|
104
|
+
'persistStorage',
|
|
105
|
+
'systemInfoV2',
|
|
106
|
+
'containerized',
|
|
107
|
+
];
|
|
108
|
+
static INTEGER_VARS = ['memoryMbytes', 'persistStateIntervalMillis', 'systemInfoIntervalMillis'];
|
|
109
|
+
static COMMA_SEPARATED_LIST_VARS = [];
|
|
110
|
+
static DEFAULTS = {
|
|
111
|
+
defaultKeyValueStoreId: 'default',
|
|
112
|
+
defaultDatasetId: 'default',
|
|
113
|
+
defaultRequestQueueId: 'default',
|
|
114
|
+
inputKey: 'INPUT',
|
|
115
|
+
maxUsedCpuRatio: 0.95,
|
|
116
|
+
availableMemoryRatio: 0.25,
|
|
117
|
+
storageClientOptions: {},
|
|
118
|
+
purgeOnStart: true,
|
|
119
|
+
headless: true,
|
|
120
|
+
persistStateIntervalMillis: 60_000,
|
|
121
|
+
systemInfoIntervalMillis: 1_000,
|
|
122
|
+
persistStorage: true,
|
|
123
|
+
systemInfoV2: false,
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Provides access to the current-instance-scoped Configuration without passing it around in parameters.
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
static storage = new AsyncLocalStorage();
|
|
130
|
+
options;
|
|
131
|
+
services = new Map();
|
|
132
|
+
/** @internal */
|
|
133
|
+
static globalConfig;
|
|
134
|
+
storageManagers = new Map();
|
|
80
135
|
/**
|
|
81
136
|
* Creates new `Configuration` instance with provided options. Env vars will have precedence over those.
|
|
82
137
|
*/
|
|
83
138
|
constructor(options = {}) {
|
|
84
|
-
Object.defineProperty(this, "options", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
configurable: true,
|
|
87
|
-
writable: true,
|
|
88
|
-
value: void 0
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(this, "services", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
value: new Map()
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(this, "storageManagers", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
configurable: true,
|
|
99
|
-
writable: true,
|
|
100
|
-
value: new Map()
|
|
101
|
-
});
|
|
102
139
|
this.buildOptions(options);
|
|
103
140
|
// Increase the global limit for event emitter memory leak warnings.
|
|
104
|
-
|
|
141
|
+
EventEmitter.defaultMaxListeners = 50;
|
|
105
142
|
// set the log level to support CRAWLEE_ prefixed env var too
|
|
106
143
|
const logLevel = this.get('logLevel');
|
|
107
144
|
if (logLevel) {
|
|
108
145
|
const level = Number.isFinite(+logLevel)
|
|
109
146
|
? +logLevel
|
|
110
|
-
:
|
|
111
|
-
|
|
147
|
+
: LogLevel[String(logLevel).toUpperCase()];
|
|
148
|
+
log.setLevel(level);
|
|
112
149
|
}
|
|
113
150
|
}
|
|
114
151
|
/**
|
|
@@ -119,7 +156,7 @@ class Configuration {
|
|
|
119
156
|
get(key, defaultValue) {
|
|
120
157
|
// prefer env vars, always iterate through the whole map as there might be duplicate env vars for the same option
|
|
121
158
|
let envValue;
|
|
122
|
-
for (const [k, v] of
|
|
159
|
+
for (const [k, v] of entries(Configuration.ENV_MAP)) {
|
|
123
160
|
if (key === v) {
|
|
124
161
|
envValue = process.env[k];
|
|
125
162
|
if (envValue) {
|
|
@@ -191,7 +228,7 @@ class Configuration {
|
|
|
191
228
|
if (this.services.has('eventManager')) {
|
|
192
229
|
return this.services.get('eventManager');
|
|
193
230
|
}
|
|
194
|
-
const eventManager = new
|
|
231
|
+
const eventManager = new LocalEventManager(this);
|
|
195
232
|
this.services.set('eventManager', eventManager);
|
|
196
233
|
return eventManager;
|
|
197
234
|
}
|
|
@@ -204,7 +241,7 @@ class Configuration {
|
|
|
204
241
|
if (this.services.has(cacheKey)) {
|
|
205
242
|
return this.services.get(cacheKey);
|
|
206
243
|
}
|
|
207
|
-
const storage = new
|
|
244
|
+
const storage = new MemoryStorage({
|
|
208
245
|
persistStorage: this.get('persistStorage'),
|
|
209
246
|
// Override persistStorage if user provides it via storageClientOptions
|
|
210
247
|
...options,
|
|
@@ -228,7 +265,7 @@ class Configuration {
|
|
|
228
265
|
if (Configuration.storage.getStore()) {
|
|
229
266
|
return Configuration.storage.getStore();
|
|
230
267
|
}
|
|
231
|
-
Configuration.globalConfig
|
|
268
|
+
Configuration.globalConfig ??= new Configuration();
|
|
232
269
|
return Configuration.globalConfig;
|
|
233
270
|
}
|
|
234
271
|
/**
|
|
@@ -252,10 +289,10 @@ class Configuration {
|
|
|
252
289
|
}
|
|
253
290
|
buildOptions(options) {
|
|
254
291
|
// try to load configuration from crawlee.json as the baseline
|
|
255
|
-
const path =
|
|
256
|
-
if (
|
|
292
|
+
const path = join(process.cwd(), 'crawlee.json');
|
|
293
|
+
if (pathExistsSync(path)) {
|
|
257
294
|
try {
|
|
258
|
-
const file =
|
|
295
|
+
const file = readFileSync(path);
|
|
259
296
|
const optionsFromFileConfig = JSON.parse(file.toString());
|
|
260
297
|
Object.assign(options, optionsFromFileConfig);
|
|
261
298
|
}
|
|
@@ -263,91 +300,7 @@ class Configuration {
|
|
|
263
300
|
// ignore
|
|
264
301
|
}
|
|
265
302
|
}
|
|
266
|
-
this.options = new Map(
|
|
303
|
+
this.options = new Map(entries(options));
|
|
267
304
|
}
|
|
268
305
|
}
|
|
269
|
-
exports.Configuration = Configuration;
|
|
270
|
-
/**
|
|
271
|
-
* Maps environment variables to config keys (e.g. `CRAWLEE_MEMORY_MBYTES` to `memoryMbytes`)
|
|
272
|
-
*/
|
|
273
|
-
Object.defineProperty(Configuration, "ENV_MAP", {
|
|
274
|
-
enumerable: true,
|
|
275
|
-
configurable: true,
|
|
276
|
-
writable: true,
|
|
277
|
-
value: {
|
|
278
|
-
CRAWLEE_AVAILABLE_MEMORY_RATIO: 'availableMemoryRatio',
|
|
279
|
-
CRAWLEE_PURGE_ON_START: 'purgeOnStart',
|
|
280
|
-
CRAWLEE_MEMORY_MBYTES: 'memoryMbytes',
|
|
281
|
-
CRAWLEE_DEFAULT_DATASET_ID: 'defaultDatasetId',
|
|
282
|
-
CRAWLEE_DEFAULT_KEY_VALUE_STORE_ID: 'defaultKeyValueStoreId',
|
|
283
|
-
CRAWLEE_DEFAULT_REQUEST_QUEUE_ID: 'defaultRequestQueueId',
|
|
284
|
-
CRAWLEE_INPUT_KEY: 'inputKey',
|
|
285
|
-
CRAWLEE_PERSIST_STATE_INTERVAL_MILLIS: 'persistStateIntervalMillis',
|
|
286
|
-
CRAWLEE_HEADLESS: 'headless',
|
|
287
|
-
CRAWLEE_XVFB: 'xvfb',
|
|
288
|
-
CRAWLEE_CHROME_EXECUTABLE_PATH: 'chromeExecutablePath',
|
|
289
|
-
CRAWLEE_DEFAULT_BROWSER_PATH: 'defaultBrowserPath',
|
|
290
|
-
CRAWLEE_DISABLE_BROWSER_SANDBOX: 'disableBrowserSandbox',
|
|
291
|
-
CRAWLEE_LOG_LEVEL: 'logLevel',
|
|
292
|
-
CRAWLEE_PERSIST_STORAGE: 'persistStorage',
|
|
293
|
-
CRAWLEE_SYSTEM_INFO_V2: 'systemInfoV2',
|
|
294
|
-
CRAWLEE_CONTAINERIZED: 'containerized',
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
Object.defineProperty(Configuration, "BOOLEAN_VARS", {
|
|
298
|
-
enumerable: true,
|
|
299
|
-
configurable: true,
|
|
300
|
-
writable: true,
|
|
301
|
-
value: [
|
|
302
|
-
'purgeOnStart',
|
|
303
|
-
'headless',
|
|
304
|
-
'xvfb',
|
|
305
|
-
'disableBrowserSandbox',
|
|
306
|
-
'persistStorage',
|
|
307
|
-
'systemInfoV2',
|
|
308
|
-
'containerized',
|
|
309
|
-
]
|
|
310
|
-
});
|
|
311
|
-
Object.defineProperty(Configuration, "INTEGER_VARS", {
|
|
312
|
-
enumerable: true,
|
|
313
|
-
configurable: true,
|
|
314
|
-
writable: true,
|
|
315
|
-
value: ['memoryMbytes', 'persistStateIntervalMillis', 'systemInfoIntervalMillis']
|
|
316
|
-
});
|
|
317
|
-
Object.defineProperty(Configuration, "COMMA_SEPARATED_LIST_VARS", {
|
|
318
|
-
enumerable: true,
|
|
319
|
-
configurable: true,
|
|
320
|
-
writable: true,
|
|
321
|
-
value: []
|
|
322
|
-
});
|
|
323
|
-
Object.defineProperty(Configuration, "DEFAULTS", {
|
|
324
|
-
enumerable: true,
|
|
325
|
-
configurable: true,
|
|
326
|
-
writable: true,
|
|
327
|
-
value: {
|
|
328
|
-
defaultKeyValueStoreId: 'default',
|
|
329
|
-
defaultDatasetId: 'default',
|
|
330
|
-
defaultRequestQueueId: 'default',
|
|
331
|
-
inputKey: 'INPUT',
|
|
332
|
-
maxUsedCpuRatio: 0.95,
|
|
333
|
-
availableMemoryRatio: 0.25,
|
|
334
|
-
storageClientOptions: {},
|
|
335
|
-
purgeOnStart: true,
|
|
336
|
-
headless: true,
|
|
337
|
-
persistStateIntervalMillis: 60000,
|
|
338
|
-
systemInfoIntervalMillis: 1000,
|
|
339
|
-
persistStorage: true,
|
|
340
|
-
systemInfoV2: false,
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
/**
|
|
344
|
-
* Provides access to the current-instance-scoped Configuration without passing it around in parameters.
|
|
345
|
-
* @internal
|
|
346
|
-
*/
|
|
347
|
-
Object.defineProperty(Configuration, "storage", {
|
|
348
|
-
enumerable: true,
|
|
349
|
-
configurable: true,
|
|
350
|
-
writable: true,
|
|
351
|
-
value: new node_async_hooks_1.AsyncLocalStorage()
|
|
352
|
-
});
|
|
353
306
|
//# sourceMappingURL=configuration.js.map
|
package/configuration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAoB,OAAO,EAAE,MAAM,eAAe,CAAC;AAuK1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,OAAO,aAAa;IACtB;;OAEG;IACO,MAAM,CAAC,OAAO,GAAe;QACnC,8BAA8B,EAAE,sBAAsB;QACtD,sBAAsB,EAAE,cAAc;QACtC,qBAAqB,EAAE,cAAc;QACrC,0BAA0B,EAAE,kBAAkB;QAC9C,kCAAkC,EAAE,wBAAwB;QAC5D,gCAAgC,EAAE,uBAAuB;QACzD,iBAAiB,EAAE,UAAU;QAC7B,qCAAqC,EAAE,4BAA4B;QACnE,gBAAgB,EAAE,UAAU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AI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC"}
|
package/cookie_utils.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getDefaultCookieExpirationDate = getDefaultCookieExpirationDate;
|
|
5
|
-
exports.toughCookieToBrowserPoolCookie = toughCookieToBrowserPoolCookie;
|
|
6
|
-
exports.browserPoolCookieToToughCookie = browserPoolCookieToToughCookie;
|
|
7
|
-
exports.cookieStringToToughCookie = cookieStringToToughCookie;
|
|
8
|
-
exports.mergeCookies = mergeCookies;
|
|
9
|
-
const tough_cookie_1 = require("tough-cookie");
|
|
10
|
-
const log_1 = require("./log");
|
|
11
|
-
const errors_1 = require("./session_pool/errors");
|
|
1
|
+
import { Cookie, CookieJar } from 'tough-cookie';
|
|
2
|
+
import { log } from './log.js';
|
|
3
|
+
import { CookieParseError } from './session_pool/errors.js';
|
|
12
4
|
/**
|
|
13
5
|
* @internal
|
|
14
6
|
*/
|
|
15
|
-
function getCookiesFromResponse(response) {
|
|
7
|
+
export function getCookiesFromResponse(response) {
|
|
16
8
|
const headers = typeof response.headers === 'function' ? response.headers() : response.headers;
|
|
17
9
|
const cookieHeader = headers?.['set-cookie'] || '';
|
|
18
10
|
try {
|
|
19
11
|
return Array.isArray(cookieHeader)
|
|
20
|
-
? cookieHeader.map((cookie) =>
|
|
21
|
-
: [
|
|
12
|
+
? cookieHeader.map((cookie) => Cookie.parse(cookie))
|
|
13
|
+
: [Cookie.parse(cookieHeader)];
|
|
22
14
|
}
|
|
23
15
|
catch (e) {
|
|
24
|
-
throw new
|
|
16
|
+
throw new CookieParseError(cookieHeader);
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
19
|
/**
|
|
@@ -30,7 +22,7 @@ function getCookiesFromResponse(response) {
|
|
|
30
22
|
* @returns Calculated date by session max age seconds.
|
|
31
23
|
* @internal
|
|
32
24
|
*/
|
|
33
|
-
function getDefaultCookieExpirationDate(maxAgeSecs) {
|
|
25
|
+
export function getDefaultCookieExpirationDate(maxAgeSecs) {
|
|
34
26
|
return new Date(Date.now() + maxAgeSecs * 1000);
|
|
35
27
|
}
|
|
36
28
|
/**
|
|
@@ -39,7 +31,7 @@ function getDefaultCookieExpirationDate(maxAgeSecs) {
|
|
|
39
31
|
* @return Cookie compatible with browser pool
|
|
40
32
|
* @internal
|
|
41
33
|
*/
|
|
42
|
-
function toughCookieToBrowserPoolCookie(toughCookie) {
|
|
34
|
+
export function toughCookieToBrowserPoolCookie(toughCookie) {
|
|
43
35
|
return {
|
|
44
36
|
name: toughCookie.key,
|
|
45
37
|
value: toughCookie.value,
|
|
@@ -59,14 +51,14 @@ function toughCookieToBrowserPoolCookie(toughCookie) {
|
|
|
59
51
|
* @param cookieObject Cookie object (for instance from the `page.cookies` method).
|
|
60
52
|
* @internal
|
|
61
53
|
*/
|
|
62
|
-
function browserPoolCookieToToughCookie(cookieObject, maxAgeSecs) {
|
|
54
|
+
export function browserPoolCookieToToughCookie(cookieObject, maxAgeSecs) {
|
|
63
55
|
const isExpiresValid = cookieObject.expires && typeof cookieObject.expires === 'number' && cookieObject.expires > 0;
|
|
64
56
|
const expires = isExpiresValid
|
|
65
57
|
? new Date(cookieObject.expires * 1000)
|
|
66
58
|
: getDefaultCookieExpirationDate(maxAgeSecs);
|
|
67
59
|
const domainHasLeadingDot = cookieObject.domain?.startsWith?.('.');
|
|
68
60
|
const domain = domainHasLeadingDot ? cookieObject.domain?.slice?.(1) : cookieObject.domain;
|
|
69
|
-
return new
|
|
61
|
+
return new Cookie({
|
|
70
62
|
key: cookieObject.name,
|
|
71
63
|
value: cookieObject.value,
|
|
72
64
|
expires,
|
|
@@ -82,8 +74,8 @@ function browserPoolCookieToToughCookie(cookieObject, maxAgeSecs) {
|
|
|
82
74
|
* @param cookieString The cookie string to attempt parsing
|
|
83
75
|
* @returns Browser pool compatible cookie, or null if cookie cannot be parsed
|
|
84
76
|
*/
|
|
85
|
-
function cookieStringToToughCookie(cookieString) {
|
|
86
|
-
const parsed =
|
|
77
|
+
export function cookieStringToToughCookie(cookieString) {
|
|
78
|
+
const parsed = Cookie.parse(cookieString);
|
|
87
79
|
if (parsed) {
|
|
88
80
|
return toughCookieToBrowserPoolCookie(parsed);
|
|
89
81
|
}
|
|
@@ -94,8 +86,8 @@ function cookieStringToToughCookie(cookieString) {
|
|
|
94
86
|
* if we see two cookies with same keys but different casing.
|
|
95
87
|
* @internal
|
|
96
88
|
*/
|
|
97
|
-
function mergeCookies(url, sourceCookies) {
|
|
98
|
-
const jar = new
|
|
89
|
+
export function mergeCookies(url, sourceCookies) {
|
|
90
|
+
const jar = new CookieJar();
|
|
99
91
|
// ignore empty cookies
|
|
100
92
|
for (const sourceCookieString of sourceCookies) {
|
|
101
93
|
// ignore empty cookies
|
|
@@ -106,12 +98,12 @@ function mergeCookies(url, sourceCookies) {
|
|
|
106
98
|
// ignore extra spaces
|
|
107
99
|
if (!cookieString)
|
|
108
100
|
continue;
|
|
109
|
-
const cookie =
|
|
101
|
+
const cookie = Cookie.parse(cookieString);
|
|
110
102
|
const similarKeyCookie = jar.getCookiesSync(url).find((c) => {
|
|
111
103
|
return cookie.key !== c.key && cookie.key.toLowerCase() === c.key.toLowerCase();
|
|
112
104
|
});
|
|
113
105
|
if (similarKeyCookie) {
|
|
114
|
-
|
|
106
|
+
log.warningOnce(`Found cookies with similar name during cookie merging: '${cookie.key}' and '${similarKeyCookie.key}'`);
|
|
115
107
|
}
|
|
116
108
|
jar.setCookieSync(cookie, url);
|
|
117
109
|
}
|
package/cookie_utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie_utils.js","sourceRoot":"","sources":["../src/cookie_utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cookie_utils.js","sourceRoot":"","sources":["../src/cookie_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,M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AC;IACL,CAAC;IAED,OAAO,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -2,14 +2,15 @@ import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
|
|
|
2
2
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
3
3
|
import type { OptionsInit, Response as GotResponse } from 'got-scraping';
|
|
4
4
|
import type { ReadonlyDeep } from 'type-fest';
|
|
5
|
-
import type { Configuration } from '../configuration';
|
|
6
|
-
import type { EnqueueLinksOptions } from '../enqueue_links/enqueue_links';
|
|
7
|
-
import type { Log } from '../log';
|
|
8
|
-
import type { ProxyInfo } from '../proxy_configuration';
|
|
9
|
-
import type { Request, Source } from '../request';
|
|
10
|
-
import type { Session } from '../session_pool/session';
|
|
11
|
-
import type { Dataset
|
|
12
|
-
import { KeyValueStore } from '../storages';
|
|
5
|
+
import type { Configuration } from '../configuration.js';
|
|
6
|
+
import type { EnqueueLinksOptions } from '../enqueue_links/enqueue_links.js';
|
|
7
|
+
import type { Log } from '../log.js';
|
|
8
|
+
import type { ProxyInfo } from '../proxy_configuration.js';
|
|
9
|
+
import type { Request, Source } from '../request.js';
|
|
10
|
+
import type { Session } from '../session_pool/session.js';
|
|
11
|
+
import type { Dataset } from '../storages/dataset.js';
|
|
12
|
+
import { KeyValueStore, type RecordOptions } from '../storages/key_value_store.js';
|
|
13
|
+
import type { RequestQueueOperationOptions } from '../storages/request_provider.js';
|
|
13
14
|
/** @internal */
|
|
14
15
|
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
15
16
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crawler_commons.d.ts","sourceRoot":"","sources":["../../src/crawlers/crawler_commons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"crawler_commons.d.ts","sourceRoot":"","sources":["../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perty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestHandlerResult = void 0;
|
|
4
|
-
const storages_1 = require("../storages");
|
|
1
|
+
import { KeyValueStore } from '../storages/key_value_store.js';
|
|
5
2
|
/**
|
|
6
3
|
* A partial implementation of {@link RestrictedCrawlingContext} that stores parameters of calls to context methods for later inspection.
|
|
7
4
|
*
|
|
8
5
|
* @experimental
|
|
9
6
|
*/
|
|
10
|
-
class RequestHandlerResult {
|
|
7
|
+
export class RequestHandlerResult {
|
|
8
|
+
config;
|
|
9
|
+
crawleeStateKey;
|
|
10
|
+
_keyValueStoreChanges = {};
|
|
11
|
+
pushDataCalls = [];
|
|
12
|
+
addRequestsCalls = [];
|
|
13
|
+
enqueueLinksCalls = [];
|
|
11
14
|
constructor(config, crawleeStateKey) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: config
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "crawleeStateKey", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: crawleeStateKey
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "_keyValueStoreChanges", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: {}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "pushDataCalls", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: []
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "addRequestsCalls", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: []
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, "enqueueLinksCalls", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: []
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(this, "pushData", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: async (data, datasetIdOrName) => {
|
|
53
|
-
this.pushDataCalls.push([data, datasetIdOrName]);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(this, "enqueueLinks", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: async (options) => {
|
|
61
|
-
this.enqueueLinksCalls.push([options]);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(this, "addRequests", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: async (requests, options = {}) => {
|
|
69
|
-
this.addRequestsCalls.push([requests, options]);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(this, "useState", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: async (defaultValue) => {
|
|
77
|
-
const store = await this.getKeyValueStore(undefined);
|
|
78
|
-
return await store.getAutoSavedValue(this.crawleeStateKey, defaultValue);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(this, "getKeyValueStore", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: async (idOrName) => {
|
|
86
|
-
const store = await storages_1.KeyValueStore.open(idOrName, { config: this.config });
|
|
87
|
-
return {
|
|
88
|
-
id: this.idOrDefault(idOrName),
|
|
89
|
-
name: idOrName,
|
|
90
|
-
getValue: async (key) => this.getKeyValueStoreChangedValue(idOrName, key) ?? (await store.getValue(key)),
|
|
91
|
-
setValue: async (key, value, options) => {
|
|
92
|
-
this.setKeyValueStoreChangedValue(idOrName, key, value, options);
|
|
93
|
-
},
|
|
94
|
-
getAutoSavedValue: store.getAutoSavedValue.bind(store),
|
|
95
|
-
getPublicUrl: store.getPublicUrl.bind(store),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(this, "idOrDefault", {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
configurable: true,
|
|
102
|
-
writable: true,
|
|
103
|
-
value: (idOrName) => idOrName ?? this.config.get('defaultKeyValueStoreId')
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(this, "getKeyValueStoreChangedValue", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
value: (idOrName, key) => {
|
|
110
|
-
var _a;
|
|
111
|
-
const id = this.idOrDefault(idOrName);
|
|
112
|
-
(_a = this._keyValueStoreChanges)[id] ?? (_a[id] = {});
|
|
113
|
-
return this.keyValueStoreChanges[id][key]?.changedValue ?? null;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
Object.defineProperty(this, "setKeyValueStoreChangedValue", {
|
|
117
|
-
enumerable: true,
|
|
118
|
-
configurable: true,
|
|
119
|
-
writable: true,
|
|
120
|
-
value: (idOrName, key, changedValue, options) => {
|
|
121
|
-
var _a;
|
|
122
|
-
const id = this.idOrDefault(idOrName);
|
|
123
|
-
(_a = this._keyValueStoreChanges)[id] ?? (_a[id] = {});
|
|
124
|
-
this._keyValueStoreChanges[id][key] = { changedValue, options };
|
|
125
|
-
}
|
|
126
|
-
});
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.crawleeStateKey = crawleeStateKey;
|
|
127
17
|
}
|
|
128
18
|
/**
|
|
129
19
|
* A record of calls to {@link RestrictedCrawlingContext.pushData}, {@link RestrictedCrawlingContext.addRequests}, {@link RestrictedCrawlingContext.enqueueLinks} made by a request handler.
|
|
@@ -185,6 +75,42 @@ class RequestHandlerResult {
|
|
|
185
75
|
}
|
|
186
76
|
return result;
|
|
187
77
|
}
|
|
78
|
+
pushData = async (data, datasetIdOrName) => {
|
|
79
|
+
this.pushDataCalls.push([data, datasetIdOrName]);
|
|
80
|
+
};
|
|
81
|
+
enqueueLinks = async (options) => {
|
|
82
|
+
this.enqueueLinksCalls.push([options]);
|
|
83
|
+
};
|
|
84
|
+
addRequests = async (requests, options = {}) => {
|
|
85
|
+
this.addRequestsCalls.push([requests, options]);
|
|
86
|
+
};
|
|
87
|
+
useState = async (defaultValue) => {
|
|
88
|
+
const store = await this.getKeyValueStore(undefined);
|
|
89
|
+
return await store.getAutoSavedValue(this.crawleeStateKey, defaultValue);
|
|
90
|
+
};
|
|
91
|
+
getKeyValueStore = async (idOrName) => {
|
|
92
|
+
const store = await KeyValueStore.open(idOrName, { config: this.config });
|
|
93
|
+
return {
|
|
94
|
+
id: this.idOrDefault(idOrName),
|
|
95
|
+
name: idOrName,
|
|
96
|
+
getValue: async (key) => this.getKeyValueStoreChangedValue(idOrName, key) ?? (await store.getValue(key)),
|
|
97
|
+
setValue: async (key, value, options) => {
|
|
98
|
+
this.setKeyValueStoreChangedValue(idOrName, key, value, options);
|
|
99
|
+
},
|
|
100
|
+
getAutoSavedValue: store.getAutoSavedValue.bind(store),
|
|
101
|
+
getPublicUrl: store.getPublicUrl.bind(store),
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
idOrDefault = (idOrName) => idOrName ?? this.config.get('defaultKeyValueStoreId');
|
|
105
|
+
getKeyValueStoreChangedValue = (idOrName, key) => {
|
|
106
|
+
const id = this.idOrDefault(idOrName);
|
|
107
|
+
this._keyValueStoreChanges[id] ??= {};
|
|
108
|
+
return this.keyValueStoreChanges[id][key]?.changedValue ?? null;
|
|
109
|
+
};
|
|
110
|
+
setKeyValueStoreChangedValue = (idOrName, key, changedValue, options) => {
|
|
111
|
+
const id = this.idOrDefault(idOrName);
|
|
112
|
+
this._keyValueStoreChanges[id] ??= {};
|
|
113
|
+
this._keyValueStoreChanges[id][key] = { changedValue, options };
|
|
114
|
+
};
|
|
188
115
|
}
|
|
189
|
-
exports.RequestHandlerResult = RequestHandlerResult;
|
|
190
116
|
//# sourceMappingURL=crawler_commons.js.map
|