@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.22

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.
Files changed (159) hide show
  1. package/autoscaling/autoscaled_pool.d.ts +296 -0
  2. package/autoscaling/autoscaled_pool.d.ts.map +1 -0
  3. package/autoscaling/autoscaled_pool.js +673 -0
  4. package/autoscaling/autoscaled_pool.js.map +1 -0
  5. package/autoscaling/index.d.ts +4 -0
  6. package/autoscaling/index.d.ts.map +1 -0
  7. package/autoscaling/index.js +7 -0
  8. package/autoscaling/index.js.map +1 -0
  9. package/autoscaling/snapshotter.d.ts +193 -0
  10. package/autoscaling/snapshotter.d.ts.map +1 -0
  11. package/autoscaling/snapshotter.js +377 -0
  12. package/autoscaling/snapshotter.js.map +1 -0
  13. package/autoscaling/system_status.d.ts +181 -0
  14. package/autoscaling/system_status.d.ts.map +1 -0
  15. package/autoscaling/system_status.js +194 -0
  16. package/autoscaling/system_status.js.map +1 -0
  17. package/cache_container.d.ts +18 -0
  18. package/cache_container.d.ts.map +1 -0
  19. package/cache_container.js +42 -0
  20. package/cache_container.js.map +1 -0
  21. package/configuration.d.ts +150 -0
  22. package/configuration.d.ts.map +1 -0
  23. package/configuration.js +284 -0
  24. package/configuration.js.map +1 -0
  25. package/constants.d.ts +3 -0
  26. package/constants.d.ts.map +1 -0
  27. package/constants.js +6 -0
  28. package/constants.js.map +1 -0
  29. package/crawlers/crawler_commons.d.ts +25 -0
  30. package/crawlers/crawler_commons.d.ts.map +1 -0
  31. package/crawlers/crawler_commons.js +3 -0
  32. package/crawlers/crawler_commons.js.map +1 -0
  33. package/crawlers/crawler_extension.d.ts +11 -0
  34. package/crawlers/crawler_extension.d.ts.map +1 -0
  35. package/crawlers/crawler_extension.js +30 -0
  36. package/crawlers/crawler_extension.js.map +1 -0
  37. package/crawlers/crawler_utils.d.ts +20 -0
  38. package/crawlers/crawler_utils.d.ts.map +1 -0
  39. package/crawlers/crawler_utils.js +61 -0
  40. package/crawlers/crawler_utils.js.map +1 -0
  41. package/crawlers/index.d.ts +5 -0
  42. package/crawlers/index.d.ts.map +1 -0
  43. package/crawlers/index.js +8 -0
  44. package/crawlers/index.js.map +1 -0
  45. package/crawlers/statistics.d.ts +147 -0
  46. package/crawlers/statistics.d.ts.map +1 -0
  47. package/crawlers/statistics.js +360 -0
  48. package/crawlers/statistics.js.map +1 -0
  49. package/enqueue_links/enqueue_links.d.ts +151 -0
  50. package/enqueue_links/enqueue_links.d.ts.map +1 -0
  51. package/enqueue_links/enqueue_links.js +152 -0
  52. package/enqueue_links/enqueue_links.js.map +1 -0
  53. package/enqueue_links/index.d.ts +3 -0
  54. package/enqueue_links/index.d.ts.map +1 -0
  55. package/enqueue_links/index.js +6 -0
  56. package/enqueue_links/index.js.map +1 -0
  57. package/enqueue_links/shared.d.ts +60 -0
  58. package/enqueue_links/shared.d.ts.map +1 -0
  59. package/enqueue_links/shared.js +148 -0
  60. package/enqueue_links/shared.js.map +1 -0
  61. package/errors.d.ts +8 -0
  62. package/errors.d.ts.map +1 -0
  63. package/errors.js +12 -0
  64. package/errors.js.map +1 -0
  65. package/events/event_manager.d.ts +41 -0
  66. package/events/event_manager.d.ts.map +1 -0
  67. package/events/event_manager.js +103 -0
  68. package/events/event_manager.js.map +1 -0
  69. package/events/index.d.ts +3 -0
  70. package/events/index.d.ts.map +1 -0
  71. package/events/index.js +6 -0
  72. package/events/index.js.map +1 -0
  73. package/events/local_event_manager.d.ts +32 -0
  74. package/events/local_event_manager.d.ts.map +1 -0
  75. package/events/local_event_manager.js +114 -0
  76. package/events/local_event_manager.js.map +1 -0
  77. package/index.d.ts +14 -0
  78. package/index.d.ts.map +1 -0
  79. package/index.js +17 -0
  80. package/index.js.map +1 -0
  81. package/index.mjs +61 -0
  82. package/log.d.ts +3 -0
  83. package/log.d.ts.map +1 -0
  84. package/log.js +12 -0
  85. package/log.js.map +1 -0
  86. package/package.json +4 -8
  87. package/proxy_configuration.d.ts +181 -0
  88. package/proxy_configuration.d.ts.map +1 -0
  89. package/proxy_configuration.js +209 -0
  90. package/proxy_configuration.js.map +1 -0
  91. package/request.d.ts +185 -0
  92. package/request.d.ts.map +1 -0
  93. package/request.js +330 -0
  94. package/request.js.map +1 -0
  95. package/serialization.d.ts +33 -0
  96. package/serialization.d.ts.map +1 -0
  97. package/serialization.js +146 -0
  98. package/serialization.js.map +1 -0
  99. package/session_pool/errors.d.ts +8 -0
  100. package/session_pool/errors.d.ts.map +1 -0
  101. package/session_pool/errors.js +20 -0
  102. package/session_pool/errors.js.map +1 -0
  103. package/session_pool/events.d.ts +3 -0
  104. package/session_pool/events.d.ts.map +1 -0
  105. package/session_pool/events.js +6 -0
  106. package/session_pool/events.js.map +1 -0
  107. package/session_pool/index.d.ts +6 -0
  108. package/session_pool/index.d.ts.map +1 -0
  109. package/session_pool/index.js +9 -0
  110. package/session_pool/index.js.map +1 -0
  111. package/session_pool/session.d.ts +212 -0
  112. package/session_pool/session.d.ts.map +1 -0
  113. package/session_pool/session.js +360 -0
  114. package/session_pool/session.js.map +1 -0
  115. package/session_pool/session_pool.d.ts +222 -0
  116. package/session_pool/session_pool.d.ts.map +1 -0
  117. package/session_pool/session_pool.js +389 -0
  118. package/session_pool/session_pool.js.map +1 -0
  119. package/session_pool/session_utils.d.ts +9 -0
  120. package/session_pool/session_utils.d.ts.map +1 -0
  121. package/session_pool/session_utils.js +19 -0
  122. package/session_pool/session_utils.js.map +1 -0
  123. package/storages/dataset.d.ts +317 -0
  124. package/storages/dataset.d.ts.map +1 -0
  125. package/storages/dataset.js +367 -0
  126. package/storages/dataset.js.map +1 -0
  127. package/storages/index.d.ts +7 -0
  128. package/storages/index.d.ts.map +1 -0
  129. package/storages/index.js +11 -0
  130. package/storages/index.js.map +1 -0
  131. package/storages/key_value_store.d.ts +242 -0
  132. package/storages/key_value_store.d.ts.map +1 -0
  133. package/storages/key_value_store.js +320 -0
  134. package/storages/key_value_store.js.map +1 -0
  135. package/storages/request_list.d.ts +469 -0
  136. package/storages/request_list.d.ts.map +1 -0
  137. package/storages/request_list.js +724 -0
  138. package/storages/request_list.js.map +1 -0
  139. package/storages/request_queue.d.ts +315 -0
  140. package/storages/request_queue.d.ts.map +1 -0
  141. package/storages/request_queue.js +730 -0
  142. package/storages/request_queue.js.map +1 -0
  143. package/storages/storage.d.ts +260 -0
  144. package/storages/storage.d.ts.map +1 -0
  145. package/storages/storage.js +3 -0
  146. package/storages/storage.js.map +1 -0
  147. package/storages/storage_manager.d.ts +40 -0
  148. package/storages/storage_manager.d.ts.map +1 -0
  149. package/storages/storage_manager.js +119 -0
  150. package/storages/storage_manager.js.map +1 -0
  151. package/tsconfig.build.tsbuildinfo +1 -0
  152. package/typedefs.d.ts +12 -0
  153. package/typedefs.d.ts.map +1 -0
  154. package/typedefs.js +15 -0
  155. package/typedefs.js.map +1 -0
  156. package/validators.d.ts +21 -0
  157. package/validators.d.ts.map +1 -0
  158. package/validators.js +26 -0
  159. package/validators.js.map +1 -0
@@ -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":"","s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AAQ,CAAC,wBAAwB,CAAC;QACxE,eAAe,EAAE,IAAI;QACrB,oBAAoB,EAAE,IAAI;QAC1B,oBAAoB,EAAE,EAAE;QACxB,QAAQ,EAAE,OAAO;QACjB,aAAa,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"}
package/constants.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** @internal */
2
+ export declare const STATUS_CODES_BLOCKED: number[];
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -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"}
package/constants.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STATUS_CODES_BLOCKED = void 0;
4
+ /** @internal */
5
+ exports.STATUS_CODES_BLOCKED = [401, 403, 429];
6
+ //# sourceMappingURL=constants.js.map
@@ -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,25 @@
1
+ import { Log } from '../log';
2
+ import { ProxyInfo } from '../proxy_configuration';
3
+ import { Request } from '../request';
4
+ import { Session } from '../session_pool/session';
5
+ export interface CrawlingContext extends Record<PropertyKey, unknown> {
6
+ id: string;
7
+ /**
8
+ * The original {@link Request} object.
9
+ */
10
+ request: Request;
11
+ session?: Session;
12
+ /**
13
+ * An object with information about currently used proxy by the crawler
14
+ * and configured by the {@link ProxyConfiguration} class.
15
+ */
16
+ proxyInfo?: ProxyInfo;
17
+ log: Log;
18
+ }
19
+ export interface CrawlerHandleFailedRequestInput extends CrawlingContext {
20
+ /**
21
+ * The Error thrown by `handleRequestFunction`.
22
+ */
23
+ error: Error;
24
+ }
25
+ //# 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,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,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;IACtB,GAAG,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,WAAW,+BAAgC,SAAQ,eAAe;IACpE;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;CAChB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=crawler_commons.js.map
@@ -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,20 @@
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
+ * Merges multiple cookie strings. Keys are compared case-sensitively, warning will be logged
12
+ * if we see two cookies with same keys but different casing.
13
+ * @internal
14
+ */
15
+ export declare function mergeCookies(url: string, sourceCookies: string[]): string;
16
+ /**
17
+ * @internal
18
+ */
19
+ export declare function diffCookies(url: string, cookieString1?: string, cookieString2?: string): string;
20
+ //# 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;;;;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,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.diffCookies = exports.mergeCookies = 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
+ * Merges multiple cookie strings. Keys are compared case-sensitively, warning will be logged
19
+ * if we see two cookies with same keys but different casing.
20
+ * @internal
21
+ */
22
+ function mergeCookies(url, sourceCookies) {
23
+ const jar = new tough_cookie_1.CookieJar();
24
+ // ignore empty cookies
25
+ for (const sourceCookieString of sourceCookies.filter((c) => c)) {
26
+ const cookies = sourceCookieString.split(/ *; */).filter((c) => c); // ignore extra spaces
27
+ for (const cookieString of cookies) {
28
+ const cookie = tough_cookie_1.Cookie.parse(cookieString);
29
+ const similarKeyCookie = jar.getCookiesSync(url).find((c) => {
30
+ return cookie.key !== c.key && cookie.key.toLowerCase() === c.key.toLowerCase();
31
+ });
32
+ if (similarKeyCookie) {
33
+ log_1.log.deprecated(`Found cookies with similar name during cookie merging: '${cookie.key}' and '${similarKeyCookie.key}'`);
34
+ }
35
+ jar.setCookieSync(cookie, url);
36
+ }
37
+ }
38
+ return jar.getCookieStringSync(url);
39
+ }
40
+ exports.mergeCookies = mergeCookies;
41
+ /**
42
+ * @internal
43
+ */
44
+ function diffCookies(url, cookieString1 = '', cookieString2 = '') {
45
+ if (cookieString1 === cookieString2 || !cookieString2) {
46
+ return '';
47
+ }
48
+ if (!cookieString1) {
49
+ return cookieString2;
50
+ }
51
+ const cookies1 = cookieString1.split(/ *; */).filter((item) => Boolean(item)).map((cookie) => tough_cookie_1.Cookie.parse(cookie));
52
+ const cookies2 = cookieString2.split(/ *; */).filter((item) => Boolean(item)).map((cookie) => tough_cookie_1.Cookie.parse(cookie));
53
+ const added = cookies2.filter((newCookie) => {
54
+ return !cookies1.find((oldCookie) => newCookie.toString() === oldCookie.toString());
55
+ });
56
+ const jar = new tough_cookie_1.CookieJar();
57
+ added.forEach((cookie) => jar.setCookieSync(cookie, url));
58
+ return jar.getCookieStringSync(url);
59
+ }
60
+ exports.diffCookies = diffCookies;
61
+ //# 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;;;;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,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB;QAE1F,KAAK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AAE,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,5 @@
1
+ export * from './crawler_commons';
2
+ export * from './crawler_extension';
3
+ export * from './crawler_utils';
4
+ export * from './statistics';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -0,0 +1,147 @@
1
+ import { Configuration } from '../configuration';
2
+ /**
3
+ * @ignore
4
+ */
5
+ declare class Job {
6
+ private lastRunAt;
7
+ private runs;
8
+ private durationMillis?;
9
+ run(): number;
10
+ finish(): number;
11
+ retryCount(): number;
12
+ }
13
+ /**
14
+ * The statistics class provides an interface to collecting and logging run
15
+ * statistics for requests.
16
+ *
17
+ * All statistic information is saved on key value store
18
+ * under the key `SDK_CRAWLER_STATISTICS_*`, persists between
19
+ * migrations and abort/resurrect
20
+ *
21
+ * @category Crawlers
22
+ */
23
+ export declare class Statistics {
24
+ private static id;
25
+ /**
26
+ * Statistic instance id.
27
+ */
28
+ readonly id: number;
29
+ /**
30
+ * Current statistic state used for doing calculations on {@link Statistics.calculate} calls
31
+ */
32
+ state: StatisticState;
33
+ /**
34
+ * Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on
35
+ */
36
+ readonly requestRetryHistogram: number[];
37
+ private keyValueStore;
38
+ private persistStateKey;
39
+ private logIntervalMillis;
40
+ private logMessage;
41
+ private listener;
42
+ private requestsInProgress;
43
+ private readonly log;
44
+ private instanceStart;
45
+ private logInterval;
46
+ private events;
47
+ /**
48
+ * @internal
49
+ */
50
+ constructor(options?: StatisticsOptions);
51
+ /**
52
+ * Set the current statistic instance to pristine values
53
+ */
54
+ reset(): void;
55
+ /**
56
+ * Starts a job
57
+ * @ignore
58
+ */
59
+ startJob(id: number | string): void;
60
+ /**
61
+ * Mark job as finished and sets the state
62
+ * @ignore
63
+ */
64
+ finishJob(id: number | string): void;
65
+ /**
66
+ * Mark job as failed and sets the state
67
+ * @ignore
68
+ */
69
+ failJob(id: number | string): void;
70
+ /**
71
+ * Calculate the current statistics
72
+ */
73
+ calculate(): {
74
+ requestAvgFailedDurationMillis: number;
75
+ requestAvgFinishedDurationMillis: number;
76
+ requestsFinishedPerMinute: number;
77
+ requestsFailedPerMinute: number;
78
+ requestTotalDurationMillis: number;
79
+ requestsTotal: number;
80
+ crawlerRuntimeMillis: number;
81
+ };
82
+ /**
83
+ * Initializes the key value store for persisting the statistics,
84
+ * displaying the current state in predefined intervals
85
+ */
86
+ startCapturing(): Promise<void>;
87
+ /**
88
+ * Stops logging and remove event listeners, then persist
89
+ */
90
+ stopCapturing(): Promise<void>;
91
+ protected _saveRetryCountForJob(job: Job): void;
92
+ /**
93
+ * Persist internal state to the key value store
94
+ */
95
+ persistState(): Promise<void>;
96
+ /**
97
+ * Loads the current statistic from the key value store if any
98
+ */
99
+ protected _maybeLoadStatistics(): Promise<void>;
100
+ protected _teardown(): void;
101
+ /**
102
+ * Make this class serializable when called with `JSON.stringify(statsInstance)` directly
103
+ * or through `keyValueStore.setValue('KEY', statsInstance)`
104
+ */
105
+ toJSON(): StatisticPersistedState;
106
+ }
107
+ interface StatisticsOptions {
108
+ logIntervalSecs?: number;
109
+ logMessage?: string;
110
+ config?: Configuration;
111
+ }
112
+ /**
113
+ * Format of the persisted stats
114
+ */
115
+ export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt'> {
116
+ requestRetryHistogram: number[];
117
+ statsId: number;
118
+ requestAvgFailedDurationMillis: number;
119
+ requestAvgFinishedDurationMillis: number;
120
+ requestsFinishedPerMinute: number;
121
+ requestsFailedPerMinute: number;
122
+ requestTotalDurationMillis: number;
123
+ requestsTotal: number;
124
+ crawlerRuntimeMillis: number;
125
+ crawlerLastStartTimestamp: number;
126
+ statsPersistedAt: string;
127
+ }
128
+ /**
129
+ * Contains the statistics state
130
+ */
131
+ export interface StatisticState {
132
+ requestsFinished: number;
133
+ requestsFailed: number;
134
+ requestsRetries: number;
135
+ requestsFailedPerMinute: number;
136
+ requestsFinishedPerMinute: number;
137
+ requestMinDurationMillis: number;
138
+ requestMaxDurationMillis: number;
139
+ requestTotalFailedDurationMillis: number;
140
+ requestTotalFinishedDurationMillis: number;
141
+ crawlerStartedAt: Date | string | null;
142
+ crawlerFinishedAt: Date | string | null;
143
+ crawlerRuntimeMillis: number;
144
+ statsPersistedAt: Date | string | null;
145
+ }
146
+ export {};
147
+ //# sourceMappingURL=statistics.d.ts.map