@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.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/dist/LICENSE.md +201 -0
- package/{README.md → dist/README.md} +0 -0
- package/dist/autoscaling/autoscaled_pool.d.ts +286 -0
- package/dist/autoscaling/autoscaled_pool.d.ts.map +1 -0
- package/dist/autoscaling/autoscaled_pool.js +624 -0
- package/dist/autoscaling/autoscaled_pool.js.map +1 -0
- package/dist/autoscaling/index.d.ts +4 -0
- package/dist/autoscaling/index.d.ts.map +1 -0
- package/dist/autoscaling/index.js +7 -0
- package/dist/autoscaling/index.js.map +1 -0
- package/dist/autoscaling/snapshotter.d.ts +193 -0
- package/dist/autoscaling/snapshotter.d.ts.map +1 -0
- package/dist/autoscaling/snapshotter.js +377 -0
- package/dist/autoscaling/snapshotter.js.map +1 -0
- package/dist/autoscaling/system_status.d.ts +181 -0
- package/dist/autoscaling/system_status.d.ts.map +1 -0
- package/dist/autoscaling/system_status.js +194 -0
- package/dist/autoscaling/system_status.js.map +1 -0
- package/dist/cache_container.d.ts +18 -0
- package/dist/cache_container.d.ts.map +1 -0
- package/dist/cache_container.js +42 -0
- package/dist/cache_container.js.map +1 -0
- package/dist/configuration.d.ts +150 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +284 -0
- package/dist/configuration.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/crawlers/crawler_commons.d.ts +23 -0
- package/dist/crawlers/crawler_commons.d.ts.map +1 -0
- package/dist/crawlers/crawler_commons.js +3 -0
- package/dist/crawlers/crawler_commons.js.map +1 -0
- package/dist/crawlers/crawler_extension.d.ts +11 -0
- package/dist/crawlers/crawler_extension.d.ts.map +1 -0
- package/dist/crawlers/crawler_extension.js +30 -0
- package/dist/crawlers/crawler_extension.js.map +1 -0
- package/dist/crawlers/crawler_utils.d.ts +25 -0
- package/dist/crawlers/crawler_utils.d.ts.map +1 -0
- package/dist/crawlers/crawler_utils.js +72 -0
- package/dist/crawlers/crawler_utils.js.map +1 -0
- package/dist/crawlers/index.d.ts +5 -0
- package/dist/crawlers/index.d.ts.map +1 -0
- package/dist/crawlers/index.js +8 -0
- package/dist/crawlers/index.js.map +1 -0
- package/dist/crawlers/statistics.d.ts +147 -0
- package/dist/crawlers/statistics.d.ts.map +1 -0
- package/dist/crawlers/statistics.js +360 -0
- package/dist/crawlers/statistics.js.map +1 -0
- package/dist/enqueue_links/enqueue_links.d.ts +138 -0
- package/dist/enqueue_links/enqueue_links.d.ts.map +1 -0
- package/dist/enqueue_links/enqueue_links.js +123 -0
- package/dist/enqueue_links/enqueue_links.js.map +1 -0
- package/dist/enqueue_links/index.d.ts +3 -0
- package/dist/enqueue_links/index.d.ts.map +1 -0
- package/dist/enqueue_links/index.js +6 -0
- package/dist/enqueue_links/index.js.map +1 -0
- package/dist/enqueue_links/shared.d.ts +60 -0
- package/dist/enqueue_links/shared.d.ts.map +1 -0
- package/dist/enqueue_links/shared.js +148 -0
- package/dist/enqueue_links/shared.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/event_manager.d.ts +41 -0
- package/dist/events/event_manager.d.ts.map +1 -0
- package/dist/events/event_manager.js +103 -0
- package/dist/events/event_manager.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +6 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/local_event_manager.d.ts +32 -0
- package/dist/events/local_event_manager.d.ts.map +1 -0
- package/dist/events/local_event_manager.js +114 -0
- package/dist/events/local_event_manager.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +12 -0
- package/dist/log.js.map +1 -0
- package/dist/package.json +82 -0
- package/dist/proxy_configuration.d.ts +181 -0
- package/dist/proxy_configuration.d.ts.map +1 -0
- package/dist/proxy_configuration.js +209 -0
- package/dist/proxy_configuration.js.map +1 -0
- package/dist/request.d.ts +174 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +270 -0
- package/dist/request.js.map +1 -0
- package/dist/serialization.d.ts +33 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +146 -0
- package/dist/serialization.js.map +1 -0
- package/dist/session_pool/errors.d.ts +8 -0
- package/dist/session_pool/errors.d.ts.map +1 -0
- package/dist/session_pool/errors.js +20 -0
- package/dist/session_pool/errors.js.map +1 -0
- package/dist/session_pool/events.d.ts +3 -0
- package/dist/session_pool/events.d.ts.map +1 -0
- package/dist/session_pool/events.js +6 -0
- package/dist/session_pool/events.js.map +1 -0
- package/dist/session_pool/index.d.ts +6 -0
- package/dist/session_pool/index.d.ts.map +1 -0
- package/dist/session_pool/index.js +9 -0
- package/dist/session_pool/index.js.map +1 -0
- package/dist/session_pool/session.d.ts +212 -0
- package/dist/session_pool/session.d.ts.map +1 -0
- package/dist/session_pool/session.js +360 -0
- package/dist/session_pool/session.js.map +1 -0
- package/dist/session_pool/session_pool.d.ts +222 -0
- package/dist/session_pool/session_pool.d.ts.map +1 -0
- package/dist/session_pool/session_pool.js +389 -0
- package/dist/session_pool/session_pool.js.map +1 -0
- package/dist/session_pool/session_utils.d.ts +9 -0
- package/dist/session_pool/session_utils.d.ts.map +1 -0
- package/dist/session_pool/session_utils.js +19 -0
- package/dist/session_pool/session_utils.js.map +1 -0
- package/dist/storages/dataset.d.ts +358 -0
- package/dist/storages/dataset.d.ts.map +1 -0
- package/dist/storages/dataset.js +415 -0
- package/dist/storages/dataset.js.map +1 -0
- package/dist/storages/index.d.ts +7 -0
- package/dist/storages/index.d.ts.map +1 -0
- package/dist/storages/index.js +11 -0
- package/dist/storages/index.js.map +1 -0
- package/dist/storages/key_value_store.d.ts +242 -0
- package/dist/storages/key_value_store.d.ts.map +1 -0
- package/dist/storages/key_value_store.js +319 -0
- package/dist/storages/key_value_store.js.map +1 -0
- package/dist/storages/request_list.d.ts +461 -0
- package/dist/storages/request_list.d.ts.map +1 -0
- package/dist/storages/request_list.js +715 -0
- package/dist/storages/request_list.js.map +1 -0
- package/dist/storages/request_queue.d.ts +312 -0
- package/dist/storages/request_queue.d.ts.map +1 -0
- package/dist/storages/request_queue.js +708 -0
- package/dist/storages/request_queue.js.map +1 -0
- package/dist/storages/storage.d.ts +260 -0
- package/dist/storages/storage.d.ts.map +1 -0
- package/dist/storages/storage.js +3 -0
- package/dist/storages/storage.js.map +1 -0
- package/dist/storages/storage_manager.d.ts +40 -0
- package/dist/storages/storage_manager.d.ts.map +1 -0
- package/dist/storages/storage_manager.js +119 -0
- package/dist/storages/storage_manager.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/typedefs.d.ts +12 -0
- package/dist/typedefs.d.ts.map +1 -0
- package/dist/typedefs.js +15 -0
- package/dist/typedefs.js.map +1 -0
- package/dist/validators.d.ts +21 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +26 -0
- package/dist/validators.js.map +1 -0
- package/package.json +11 -10
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Configuration = void 0;
|
|
4
|
+
const consts_1 = require("@apify/consts");
|
|
5
|
+
const storage_local_1 = require("@apify/storage-local");
|
|
6
|
+
const async_hooks_1 = require("async_hooks");
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const typedefs_1 = require("./typedefs");
|
|
9
|
+
const events_2 = require("./events");
|
|
10
|
+
/**
|
|
11
|
+
* `Configuration` is a value object holding the SDK configuration. We can use it in two ways:
|
|
12
|
+
*
|
|
13
|
+
* 1. When using `Apify` class, we can get the instance configuration via `sdk.config`
|
|
14
|
+
* ```js
|
|
15
|
+
* const { Apify } = require('apify');
|
|
16
|
+
*
|
|
17
|
+
* const sdk = new Apify({ token: '123' });
|
|
18
|
+
* console.log(sdk.config.get('token')); // '123'
|
|
19
|
+
* ```
|
|
20
|
+
* 2. To get the global configuration (singleton instance). It will respect the environment variables.
|
|
21
|
+
* ```js
|
|
22
|
+
* // returns the token from APIFY_TOKEN env var
|
|
23
|
+
* console.log(Configuration.getGlobalConfig().get('token'));
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* ## Supported Configuration Options
|
|
27
|
+
*
|
|
28
|
+
* Key | Environment Variable | Default Value
|
|
29
|
+
* ---|---|---
|
|
30
|
+
* `defaultDatasetId` | `APIFY_DEFAULT_DATASET_ID` | `'default'`
|
|
31
|
+
* `defaultKeyValueStoreId` | `APIFY_DEFAULT_KEY_VALUE_STORE_ID` | `'default'`
|
|
32
|
+
* `defaultRequestQueueId` | `APIFY_DEFAULT_REQUEST_QUEUE_ID` | `'default'`
|
|
33
|
+
* `persistStateIntervalMillis` | `APIFY_PERSIST_STATE_INTERVAL_MILLIS` | `60e3`
|
|
34
|
+
*
|
|
35
|
+
* ## Advanced Configuration Options
|
|
36
|
+
*
|
|
37
|
+
* Key | Environment Variable | Default Value
|
|
38
|
+
* ---|---|---
|
|
39
|
+
* `actorId` | `APIFY_ACTOR_ID` | -
|
|
40
|
+
* `actorRunId` | `APIFY_ACTOR_RUN_ID` | -
|
|
41
|
+
* `actorTaskId` | `APIFY_ACTOR_TASK_ID` | -
|
|
42
|
+
* `containerPort` | `APIFY_CONTAINER_PORT` | `4321`
|
|
43
|
+
* `containerUrl` | `APIFY_CONTAINER_URL` | `'http://localhost:4321'`
|
|
44
|
+
* `inputKey` | `APIFY_INPUT_KEY` | `'INPUT'`
|
|
45
|
+
* `metamorphAfterSleepMillis` | `APIFY_METAMORPH_AFTER_SLEEP_MILLIS` | `300e3`
|
|
46
|
+
* `proxyHostname` | `APIFY_PROXY_HOSTNAME` | `'proxy.apify.com'`
|
|
47
|
+
* `proxyPassword` | `APIFY_PROXY_PASSWORD` | -
|
|
48
|
+
* `proxyPort` | `APIFY_PROXY_PORT` | `8000`
|
|
49
|
+
*
|
|
50
|
+
* ## Not Supported environment variables
|
|
51
|
+
*
|
|
52
|
+
* - `MEMORY_MBYTES`
|
|
53
|
+
* - `HEADLESS`
|
|
54
|
+
* - `XVFB`
|
|
55
|
+
* - `CHROME_EXECUTABLE_PATH`
|
|
56
|
+
*/
|
|
57
|
+
class Configuration {
|
|
58
|
+
/**
|
|
59
|
+
* Creates new `Configuration` instance with provided options. Env vars will have precedence over those.
|
|
60
|
+
*/
|
|
61
|
+
constructor(options = {}) {
|
|
62
|
+
Object.defineProperty(this, "options", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "services", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: new Map()
|
|
73
|
+
});
|
|
74
|
+
this.options = new Map((0, typedefs_1.entries)(options));
|
|
75
|
+
// Increase the global limit for event emitter memory leak warnings.
|
|
76
|
+
events_1.EventEmitter.defaultMaxListeners = 50;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns configured value. First checks the environment variables, then provided configuration,
|
|
80
|
+
* fallbacks to the `defaultValue` argument if provided, otherwise uses the default value as described
|
|
81
|
+
* in the above section.
|
|
82
|
+
*/
|
|
83
|
+
get(key, defaultValue) {
|
|
84
|
+
// prefer env vars
|
|
85
|
+
const envKey = Configuration.ENV_MAP_REVERSED[key] ?? key;
|
|
86
|
+
const envValue = process.env[envKey];
|
|
87
|
+
if (envValue != null) {
|
|
88
|
+
return this._castEnvValue(key, envValue);
|
|
89
|
+
}
|
|
90
|
+
// check instance level options
|
|
91
|
+
if (this.options.has(key)) {
|
|
92
|
+
return this.options.get(key);
|
|
93
|
+
}
|
|
94
|
+
// fallback to defaults
|
|
95
|
+
return (defaultValue ?? Configuration.DEFAULTS[key] ?? envValue);
|
|
96
|
+
}
|
|
97
|
+
_castEnvValue(key, value) {
|
|
98
|
+
if (Configuration.INTEGER_VARS.includes(key)) {
|
|
99
|
+
return +value;
|
|
100
|
+
}
|
|
101
|
+
if (Configuration.BOOLEAN_VARS.includes(key)) {
|
|
102
|
+
// 0, false and empty string are considered falsy values
|
|
103
|
+
return !['0', 'false', ''].includes(String(value).toLowerCase());
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Sets value for given option. Only affects this `Configuration` instance, the value will not be propagated down to the env var.
|
|
109
|
+
* To reset a value, we can omit the `value` argument or pass `undefined` there.
|
|
110
|
+
*/
|
|
111
|
+
set(key, value) {
|
|
112
|
+
this.options.set(key, value);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns cached instance of {@link StorageClient} using options as defined in the environment variables or in
|
|
116
|
+
* this {@link Configuration} instance. Only first call of this method will create the client, following calls will
|
|
117
|
+
* return the same client instance.
|
|
118
|
+
*
|
|
119
|
+
* Caching works based on the API URL and token, so calling this method with different options will return
|
|
120
|
+
* multiple instances, one for each variant of the options.
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
getStorageClient() {
|
|
124
|
+
if (this.options.has('storageClient')) {
|
|
125
|
+
return this.options.get('storageClient');
|
|
126
|
+
}
|
|
127
|
+
const options = this.options.get('storageClientOptions');
|
|
128
|
+
return this.createStorageLocal(options);
|
|
129
|
+
}
|
|
130
|
+
getEventManager() {
|
|
131
|
+
if (this.options.has('eventManager')) {
|
|
132
|
+
return this.options.get('eventManager');
|
|
133
|
+
}
|
|
134
|
+
if (this.services.has('eventManager')) {
|
|
135
|
+
return this.services.get('eventManager');
|
|
136
|
+
}
|
|
137
|
+
const eventManager = new events_2.LocalEventManager(this);
|
|
138
|
+
this.services.set('eventManager', eventManager);
|
|
139
|
+
return eventManager;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates an instance of ApifyStorageLocal using options as defined in the environment variables or in this `Configuration` instance.
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
createStorageLocal(options = {}) {
|
|
146
|
+
const cacheKey = `StorageLocal~${JSON.stringify(options)}`;
|
|
147
|
+
if (this.services.has(cacheKey)) {
|
|
148
|
+
return this.services.get(cacheKey);
|
|
149
|
+
}
|
|
150
|
+
const storage = new storage_local_1.ApifyStorageLocal(options);
|
|
151
|
+
this.services.set(cacheKey, storage);
|
|
152
|
+
process.on('exit', () => {
|
|
153
|
+
// TODO this is not public API, need to update storage local with some teardown
|
|
154
|
+
storage.dbConnections.closeAllConnections();
|
|
155
|
+
});
|
|
156
|
+
return storage;
|
|
157
|
+
}
|
|
158
|
+
useStorageClient(client) {
|
|
159
|
+
this.options.set('storageClient', client);
|
|
160
|
+
}
|
|
161
|
+
useEventManager(events) {
|
|
162
|
+
this.options.set('eventManager', events);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns the global configuration instance. It will respect the environment variables.
|
|
166
|
+
* When used inside SDK instance (`sdk.main()`), the return value is equal to `sdk.config`.
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
static getGlobalConfig() {
|
|
170
|
+
if (Configuration.storage.getStore()) {
|
|
171
|
+
return Configuration.storage.getStore();
|
|
172
|
+
}
|
|
173
|
+
Configuration.globalConfig ?? (Configuration.globalConfig = new Configuration());
|
|
174
|
+
return Configuration.globalConfig;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Gets default {@link StorageClient} instance.
|
|
178
|
+
*/
|
|
179
|
+
static getStorageClient() {
|
|
180
|
+
return this.getGlobalConfig().getStorageClient();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Gets default {@link EventManager} instance.
|
|
184
|
+
*/
|
|
185
|
+
static getEventManager() {
|
|
186
|
+
return this.getGlobalConfig().getEventManager();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Resets global configuration instance. The default instance holds configuration based on env vars,
|
|
190
|
+
* if we want to change them, we need to first reset the global state. Used mainly for testing purposes.
|
|
191
|
+
*/
|
|
192
|
+
static resetGlobalState() {
|
|
193
|
+
delete this.globalConfig;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.Configuration = Configuration;
|
|
197
|
+
/**
|
|
198
|
+
* Maps environment variables to config keys (e.g. `APIFY_PROXY_PORT` to `proxyPort`)
|
|
199
|
+
*/
|
|
200
|
+
Object.defineProperty(Configuration, "ENV_MAP", {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
configurable: true,
|
|
203
|
+
writable: true,
|
|
204
|
+
value: {
|
|
205
|
+
// TODO prefix once we have a package name
|
|
206
|
+
AVAILABLE_MEMORY_RATIO: 'availableMemoryRatio',
|
|
207
|
+
APIFY_DEFAULT_DATASET_ID: 'defaultDatasetId',
|
|
208
|
+
APIFY_DEFAULT_KEY_VALUE_STORE_ID: 'defaultKeyValueStoreId',
|
|
209
|
+
APIFY_DEFAULT_REQUEST_QUEUE_ID: 'defaultRequestQueueId',
|
|
210
|
+
APIFY_METAMORPH_AFTER_SLEEP_MILLIS: 'metamorphAfterSleepMillis',
|
|
211
|
+
APIFY_PERSIST_STATE_INTERVAL_MILLIS: 'persistStateIntervalMillis',
|
|
212
|
+
APIFY_TEST_PERSIST_INTERVAL_MILLIS: 'persistStateIntervalMillis',
|
|
213
|
+
APIFY_INPUT_KEY: 'inputKey',
|
|
214
|
+
APIFY_ACTOR_ID: 'actorId',
|
|
215
|
+
APIFY_ACTOR_RUN_ID: 'actorRunId',
|
|
216
|
+
APIFY_ACTOR_TASK_ID: 'actorTaskId',
|
|
217
|
+
APIFY_CONTAINER_PORT: 'containerPort',
|
|
218
|
+
APIFY_CONTAINER_URL: 'containerUrl',
|
|
219
|
+
APIFY_PROXY_HOSTNAME: 'proxyHostname',
|
|
220
|
+
APIFY_PROXY_PASSWORD: 'proxyPassword',
|
|
221
|
+
APIFY_PROXY_PORT: 'proxyPort',
|
|
222
|
+
// not supported, use env vars directly:
|
|
223
|
+
// APIFY_MEMORY_MBYTES: 'memoryMbytes',
|
|
224
|
+
// APIFY_HEADLESS: 'headless',
|
|
225
|
+
// APIFY_XVFB: 'xvfb',
|
|
226
|
+
// APIFY_CHROME_EXECUTABLE_PATH: 'chromeExecutablePath',
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
/**
|
|
230
|
+
* Maps config keys to environment variables (e.g. `proxyPort` to `APIFY_PROXY_PORT`).
|
|
231
|
+
*/
|
|
232
|
+
Object.defineProperty(Configuration, "ENV_MAP_REVERSED", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
configurable: true,
|
|
235
|
+
writable: true,
|
|
236
|
+
value: (0, typedefs_1.entries)(Configuration.ENV_MAP).reduce((obj, [key, value]) => {
|
|
237
|
+
obj[value] = key;
|
|
238
|
+
return obj;
|
|
239
|
+
}, {})
|
|
240
|
+
});
|
|
241
|
+
Object.defineProperty(Configuration, "BOOLEAN_VARS", {
|
|
242
|
+
enumerable: true,
|
|
243
|
+
configurable: true,
|
|
244
|
+
writable: true,
|
|
245
|
+
value: []
|
|
246
|
+
});
|
|
247
|
+
Object.defineProperty(Configuration, "INTEGER_VARS", {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
configurable: true,
|
|
250
|
+
writable: true,
|
|
251
|
+
value: ['proxyPort', 'memoryMbytes', 'containerPort']
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(Configuration, "DEFAULTS", {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
configurable: true,
|
|
256
|
+
writable: true,
|
|
257
|
+
value: {
|
|
258
|
+
defaultKeyValueStoreId: consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID],
|
|
259
|
+
defaultDatasetId: consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.DEFAULT_DATASET_ID],
|
|
260
|
+
defaultRequestQueueId: consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.DEFAULT_REQUEST_QUEUE_ID],
|
|
261
|
+
maxUsedCpuRatio: 0.95,
|
|
262
|
+
availableMemoryRatio: 0.25,
|
|
263
|
+
storageClientOptions: {},
|
|
264
|
+
inputKey: 'INPUT',
|
|
265
|
+
proxyHostname: consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.PROXY_HOSTNAME],
|
|
266
|
+
proxyPort: +consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.PROXY_PORT],
|
|
267
|
+
containerPort: +consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.CONTAINER_PORT],
|
|
268
|
+
containerUrl: consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.CONTAINER_URL],
|
|
269
|
+
metamorphAfterSleepMillis: 300000,
|
|
270
|
+
persistStateIntervalMillis: 60000,
|
|
271
|
+
systemInfoIntervalMillis: 60000,
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
/**
|
|
275
|
+
* Provides access to the current-instance-scoped Configuration without passing it around in parameters.
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
Object.defineProperty(Configuration, "storage", {
|
|
279
|
+
enumerable: true,
|
|
280
|
+
configurable: true,
|
|
281
|
+
writable: true,
|
|
282
|
+
value: new async_hooks_1.AsyncLocalStorage()
|
|
283
|
+
});
|
|
284
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;AAAA,0CAAyD;AACzD,wDAAmF;AACnF,6CAAgD;AAChD,mCAAsC;AACtC,yCAAiD;AAEjD,qCAA2D;AA2B3D;;;;;;;;;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Aa,EAAE,uBAAc,CAAC,iBAAQ,CAAC,cAAc,CAAC;QACtD,SAAS,EAAE,CAAC,uBAAc,CAAC,iBAAQ,CAAC,UAAU,CAAC;QAC/C,aAAa,EAAE,CAAC,uBAAc,CAAC,iBAAQ,CAAC,cAAc,CAAC;QACvD,YAAY,EAAE,uBAAc,CAAC,iBAAQ,CAAC,aAAa,CAAC;QACpD,yBAAyB,EAAE,MAAO;QAClC,0BAA0B,EAAE,KAAM;QAClC,wBAAwB,EAAE,KAAM;KACnC;GAAC;AAEF;;;GAGG;AACH;;;;WAAiB,IAAI,+BAAiB,EAAiB;GAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,eAAO,MAAM,oBAAoB,UAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AACH,QAAA,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ProxyInfo } from '../proxy_configuration';
|
|
2
|
+
import { Request } from '../request';
|
|
3
|
+
import { Session } from '../session_pool/session';
|
|
4
|
+
export interface CrawlingContext extends Record<PropertyKey, unknown> {
|
|
5
|
+
id: string;
|
|
6
|
+
/**
|
|
7
|
+
* The original {@link Request} object.
|
|
8
|
+
*/
|
|
9
|
+
request: Request;
|
|
10
|
+
session?: Session;
|
|
11
|
+
/**
|
|
12
|
+
* An object with information about currently used proxy by the crawler
|
|
13
|
+
* and configured by the {@link ProxyConfiguration} class.
|
|
14
|
+
*/
|
|
15
|
+
proxyInfo?: ProxyInfo;
|
|
16
|
+
}
|
|
17
|
+
export interface CrawlerHandleFailedRequestInput extends CrawlingContext {
|
|
18
|
+
/**
|
|
19
|
+
* The Error thrown by `handleRequestFunction`.
|
|
20
|
+
*/
|
|
21
|
+
error: Error;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=crawler_commons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler_commons.d.ts","sourceRoot":"","sources":["../../src/crawlers/crawler_commons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,MAAM,WAAW,eAAgB,SAAQ,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC;IACjE,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,MAAM,WAAW,+BAAgC,SAAQ,eAAe;IACpE;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler_commons.js","sourceRoot":"","sources":["../../src/crawlers/crawler_commons.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class with pre-defined method to connect to the Crawlers class by the "use" crawler method.
|
|
3
|
+
* @category Crawlers
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class CrawlerExtension {
|
|
7
|
+
name: string;
|
|
8
|
+
log: import("@apify/log/log").Log;
|
|
9
|
+
getCrawlerOptions(): Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=crawler_extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler_extension.d.ts","sourceRoot":"","sources":["../../src/crawlers/crawler_extension.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,8BAAsB,gBAAgB;IAClC,IAAI,SAAyB;IAC7B,GAAG,+BAA2C;IAE9C,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG/C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrawlerExtension = void 0;
|
|
4
|
+
const log_1 = require("../log");
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class with pre-defined method to connect to the Crawlers class by the "use" crawler method.
|
|
7
|
+
* @category Crawlers
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
class CrawlerExtension {
|
|
11
|
+
constructor() {
|
|
12
|
+
Object.defineProperty(this, "name", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: this.constructor.name
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "log", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: log_1.log.child({ prefix: this.name })
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getCrawlerOptions() {
|
|
26
|
+
throw new Error(`${this.name} has not implemented "getCrawlerOptions" method.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.CrawlerExtension = CrawlerExtension;
|
|
30
|
+
//# sourceMappingURL=crawler_extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler_extension.js","sourceRoot":"","sources":["../../src/crawlers/crawler_extension.ts"],"names":[],"mappings":";;;AAAA,gCAA2C;AAE3C;;;;GAIG;AACH,MAAsB,gBAAgB;IAAtC;QACI;;;;mBAAO,IAAI,CAAC,WAAW,CAAC,IAAI;WAAC;QAC7B;;;;mBAAM,SAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;WAAC;IAKlD,CAAC;IAHG,iBAAiB;QACb,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,kDAAkD,CAAC,CAAC;IACpF,CAAC;CACJ;AAPD,4CAOC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Session } from '../session_pool/session';
|
|
2
|
+
/**
|
|
3
|
+
* Handles timeout request
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare function handleRequestTimeout({ session, errorMessage }: {
|
|
7
|
+
session?: Session;
|
|
8
|
+
errorMessage: string;
|
|
9
|
+
}): void;
|
|
10
|
+
/**
|
|
11
|
+
* Handles blocked request
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function throwOnBlockedRequest(session: Session, statusCode: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Merges multiple cookie strings. Keys are compared case-sensitively, warning will be logged
|
|
17
|
+
* if we see two cookies with same keys but different casing.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function mergeCookies(url: string, sourceCookies: string[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function diffCookies(url: string, cookieString1?: string, cookieString2?: string): string;
|
|
25
|
+
//# sourceMappingURL=crawler_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler_utils.d.ts","sourceRoot":"","sources":["../../src/crawlers/crawler_utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,QAK1G;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAMzE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAsBzE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,SAAK,EAAE,aAAa,SAAK,GAAG,MAAM,CAmBvF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diffCookies = exports.mergeCookies = exports.throwOnBlockedRequest = exports.handleRequestTimeout = void 0;
|
|
4
|
+
const tough_cookie_1 = require("tough-cookie");
|
|
5
|
+
const log_1 = require("../log");
|
|
6
|
+
/**
|
|
7
|
+
* Handles timeout request
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
function handleRequestTimeout({ session, errorMessage }) {
|
|
11
|
+
session?.markBad();
|
|
12
|
+
const timeoutMillis = errorMessage.match(/(\d+)\s?ms/)?.[1]; // first capturing group
|
|
13
|
+
const timeoutSecs = Number(timeoutMillis) / 1000;
|
|
14
|
+
throw new Error(`Navigation timed out after ${timeoutSecs} seconds.`);
|
|
15
|
+
}
|
|
16
|
+
exports.handleRequestTimeout = handleRequestTimeout;
|
|
17
|
+
/**
|
|
18
|
+
* Handles blocked request
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
function throwOnBlockedRequest(session, statusCode) {
|
|
22
|
+
const isBlocked = session.retireOnBlockedStatusCodes(statusCode);
|
|
23
|
+
if (isBlocked) {
|
|
24
|
+
throw new Error(`Request blocked - received ${statusCode} status code.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.throwOnBlockedRequest = throwOnBlockedRequest;
|
|
28
|
+
/**
|
|
29
|
+
* Merges multiple cookie strings. Keys are compared case-sensitively, warning will be logged
|
|
30
|
+
* if we see two cookies with same keys but different casing.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
function mergeCookies(url, sourceCookies) {
|
|
34
|
+
const jar = new tough_cookie_1.CookieJar();
|
|
35
|
+
// ignore empty cookies
|
|
36
|
+
for (const sourceCookieString of sourceCookies.filter((c) => c)) {
|
|
37
|
+
const cookies = sourceCookieString.split(/ *; */).filter((c) => c); // ignore extra spaces
|
|
38
|
+
for (const cookieString of cookies) {
|
|
39
|
+
const cookie = tough_cookie_1.Cookie.parse(cookieString);
|
|
40
|
+
const similarKeyCookie = jar.getCookiesSync(url).find((c) => {
|
|
41
|
+
return cookie.key !== c.key && cookie.key.toLowerCase() === c.key.toLowerCase();
|
|
42
|
+
});
|
|
43
|
+
if (similarKeyCookie) {
|
|
44
|
+
log_1.log.deprecated(`Found cookies with similar name during cookie merging: '${cookie.key}' and '${similarKeyCookie.key}'`);
|
|
45
|
+
}
|
|
46
|
+
jar.setCookieSync(cookie, url);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return jar.getCookieStringSync(url);
|
|
50
|
+
}
|
|
51
|
+
exports.mergeCookies = mergeCookies;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
function diffCookies(url, cookieString1 = '', cookieString2 = '') {
|
|
56
|
+
if (cookieString1 === cookieString2 || !cookieString2) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
if (!cookieString1) {
|
|
60
|
+
return cookieString2;
|
|
61
|
+
}
|
|
62
|
+
const cookies1 = cookieString1.split(/ *; */).filter((item) => Boolean(item)).map((cookie) => tough_cookie_1.Cookie.parse(cookie));
|
|
63
|
+
const cookies2 = cookieString2.split(/ *; */).filter((item) => Boolean(item)).map((cookie) => tough_cookie_1.Cookie.parse(cookie));
|
|
64
|
+
const added = cookies2.filter((newCookie) => {
|
|
65
|
+
return !cookies1.find((oldCookie) => newCookie.toString() === oldCookie.toString());
|
|
66
|
+
});
|
|
67
|
+
const jar = new tough_cookie_1.CookieJar();
|
|
68
|
+
added.forEach((cookie) => jar.setCookieSync(cookie, url));
|
|
69
|
+
return jar.getCookieStringSync(url);
|
|
70
|
+
}
|
|
71
|
+
exports.diffCookies = diffCookies;
|
|
72
|
+
//# sourceMappingURL=crawler_utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler_utils.js","sourceRoot":"","sources":["../../src/crawlers/crawler_utils.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,gCAA6B;AAG7B;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,EAAE,OAAO,EAAE,YAAY,EAA+C;IACvG,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,wBAAwB;IACrF,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IACjD,MAAM,IAAI,KAAK,CAAC,8BAA8B,WAAW,WAAW,CAAC,CAAC;AAC1E,CAAC;AALD,oDAKC;AAED;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,OAAgB,EAAE,UAAkB;IACtE,MAAM,SAAS,GAAG,OAAO,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC;IAEjE,IAAI,SAAS,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,UAAU,eAAe,CAAC,CAAC;KAC5E;AACL,CAAC;AAND,sDAMC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,aAAuB;IAC7D,MAAM,GAAG,GAAG,IAAI,wBAAS,EAAE,CAAC;IAE5B,uBAAuB;IACvB,KAAK,MAAM,kBAAkB,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;QAC7D,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAA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C,CAAC;IACrH,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAM,CAAC,KAAK,CAAC,MAAM,CAAE,CAAC,CAAC;IAErH,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,IAAI,wBAAS,EAAE,CAAC;IAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAE1D,OAAO,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC;AAnBD,kCAmBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crawlers/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./crawler_commons"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./crawler_extension"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./crawler_utils"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./statistics"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crawlers/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,8DAAoC;AACpC,0DAAgC;AAChC,uDAA6B"}
|