@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.
Files changed (162) hide show
  1. package/dist/LICENSE.md +201 -0
  2. package/{README.md → dist/README.md} +0 -0
  3. package/dist/autoscaling/autoscaled_pool.d.ts +286 -0
  4. package/dist/autoscaling/autoscaled_pool.d.ts.map +1 -0
  5. package/dist/autoscaling/autoscaled_pool.js +624 -0
  6. package/dist/autoscaling/autoscaled_pool.js.map +1 -0
  7. package/dist/autoscaling/index.d.ts +4 -0
  8. package/dist/autoscaling/index.d.ts.map +1 -0
  9. package/dist/autoscaling/index.js +7 -0
  10. package/dist/autoscaling/index.js.map +1 -0
  11. package/dist/autoscaling/snapshotter.d.ts +193 -0
  12. package/dist/autoscaling/snapshotter.d.ts.map +1 -0
  13. package/dist/autoscaling/snapshotter.js +377 -0
  14. package/dist/autoscaling/snapshotter.js.map +1 -0
  15. package/dist/autoscaling/system_status.d.ts +181 -0
  16. package/dist/autoscaling/system_status.d.ts.map +1 -0
  17. package/dist/autoscaling/system_status.js +194 -0
  18. package/dist/autoscaling/system_status.js.map +1 -0
  19. package/dist/cache_container.d.ts +18 -0
  20. package/dist/cache_container.d.ts.map +1 -0
  21. package/dist/cache_container.js +42 -0
  22. package/dist/cache_container.js.map +1 -0
  23. package/dist/configuration.d.ts +150 -0
  24. package/dist/configuration.d.ts.map +1 -0
  25. package/dist/configuration.js +284 -0
  26. package/dist/configuration.js.map +1 -0
  27. package/dist/constants.d.ts +3 -0
  28. package/dist/constants.d.ts.map +1 -0
  29. package/dist/constants.js +6 -0
  30. package/dist/constants.js.map +1 -0
  31. package/dist/crawlers/crawler_commons.d.ts +23 -0
  32. package/dist/crawlers/crawler_commons.d.ts.map +1 -0
  33. package/dist/crawlers/crawler_commons.js +3 -0
  34. package/dist/crawlers/crawler_commons.js.map +1 -0
  35. package/dist/crawlers/crawler_extension.d.ts +11 -0
  36. package/dist/crawlers/crawler_extension.d.ts.map +1 -0
  37. package/dist/crawlers/crawler_extension.js +30 -0
  38. package/dist/crawlers/crawler_extension.js.map +1 -0
  39. package/dist/crawlers/crawler_utils.d.ts +25 -0
  40. package/dist/crawlers/crawler_utils.d.ts.map +1 -0
  41. package/dist/crawlers/crawler_utils.js +72 -0
  42. package/dist/crawlers/crawler_utils.js.map +1 -0
  43. package/dist/crawlers/index.d.ts +5 -0
  44. package/dist/crawlers/index.d.ts.map +1 -0
  45. package/dist/crawlers/index.js +8 -0
  46. package/dist/crawlers/index.js.map +1 -0
  47. package/dist/crawlers/statistics.d.ts +147 -0
  48. package/dist/crawlers/statistics.d.ts.map +1 -0
  49. package/dist/crawlers/statistics.js +360 -0
  50. package/dist/crawlers/statistics.js.map +1 -0
  51. package/dist/enqueue_links/enqueue_links.d.ts +138 -0
  52. package/dist/enqueue_links/enqueue_links.d.ts.map +1 -0
  53. package/dist/enqueue_links/enqueue_links.js +123 -0
  54. package/dist/enqueue_links/enqueue_links.js.map +1 -0
  55. package/dist/enqueue_links/index.d.ts +3 -0
  56. package/dist/enqueue_links/index.d.ts.map +1 -0
  57. package/dist/enqueue_links/index.js +6 -0
  58. package/dist/enqueue_links/index.js.map +1 -0
  59. package/dist/enqueue_links/shared.d.ts +60 -0
  60. package/dist/enqueue_links/shared.d.ts.map +1 -0
  61. package/dist/enqueue_links/shared.js +148 -0
  62. package/dist/enqueue_links/shared.js.map +1 -0
  63. package/dist/errors.d.ts +8 -0
  64. package/dist/errors.d.ts.map +1 -0
  65. package/dist/errors.js +12 -0
  66. package/dist/errors.js.map +1 -0
  67. package/dist/events/event_manager.d.ts +41 -0
  68. package/dist/events/event_manager.d.ts.map +1 -0
  69. package/dist/events/event_manager.js +103 -0
  70. package/dist/events/event_manager.js.map +1 -0
  71. package/dist/events/index.d.ts +3 -0
  72. package/dist/events/index.d.ts.map +1 -0
  73. package/dist/events/index.js +6 -0
  74. package/dist/events/index.js.map +1 -0
  75. package/dist/events/local_event_manager.d.ts +32 -0
  76. package/dist/events/local_event_manager.d.ts.map +1 -0
  77. package/dist/events/local_event_manager.js +114 -0
  78. package/dist/events/local_event_manager.js.map +1 -0
  79. package/dist/index.d.ts +14 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +17 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/index.mjs +63 -0
  84. package/dist/log.d.ts +3 -0
  85. package/dist/log.d.ts.map +1 -0
  86. package/dist/log.js +12 -0
  87. package/dist/log.js.map +1 -0
  88. package/dist/package.json +82 -0
  89. package/dist/proxy_configuration.d.ts +181 -0
  90. package/dist/proxy_configuration.d.ts.map +1 -0
  91. package/dist/proxy_configuration.js +209 -0
  92. package/dist/proxy_configuration.js.map +1 -0
  93. package/dist/request.d.ts +174 -0
  94. package/dist/request.d.ts.map +1 -0
  95. package/dist/request.js +270 -0
  96. package/dist/request.js.map +1 -0
  97. package/dist/serialization.d.ts +33 -0
  98. package/dist/serialization.d.ts.map +1 -0
  99. package/dist/serialization.js +146 -0
  100. package/dist/serialization.js.map +1 -0
  101. package/dist/session_pool/errors.d.ts +8 -0
  102. package/dist/session_pool/errors.d.ts.map +1 -0
  103. package/dist/session_pool/errors.js +20 -0
  104. package/dist/session_pool/errors.js.map +1 -0
  105. package/dist/session_pool/events.d.ts +3 -0
  106. package/dist/session_pool/events.d.ts.map +1 -0
  107. package/dist/session_pool/events.js +6 -0
  108. package/dist/session_pool/events.js.map +1 -0
  109. package/dist/session_pool/index.d.ts +6 -0
  110. package/dist/session_pool/index.d.ts.map +1 -0
  111. package/dist/session_pool/index.js +9 -0
  112. package/dist/session_pool/index.js.map +1 -0
  113. package/dist/session_pool/session.d.ts +212 -0
  114. package/dist/session_pool/session.d.ts.map +1 -0
  115. package/dist/session_pool/session.js +360 -0
  116. package/dist/session_pool/session.js.map +1 -0
  117. package/dist/session_pool/session_pool.d.ts +222 -0
  118. package/dist/session_pool/session_pool.d.ts.map +1 -0
  119. package/dist/session_pool/session_pool.js +389 -0
  120. package/dist/session_pool/session_pool.js.map +1 -0
  121. package/dist/session_pool/session_utils.d.ts +9 -0
  122. package/dist/session_pool/session_utils.d.ts.map +1 -0
  123. package/dist/session_pool/session_utils.js +19 -0
  124. package/dist/session_pool/session_utils.js.map +1 -0
  125. package/dist/storages/dataset.d.ts +358 -0
  126. package/dist/storages/dataset.d.ts.map +1 -0
  127. package/dist/storages/dataset.js +415 -0
  128. package/dist/storages/dataset.js.map +1 -0
  129. package/dist/storages/index.d.ts +7 -0
  130. package/dist/storages/index.d.ts.map +1 -0
  131. package/dist/storages/index.js +11 -0
  132. package/dist/storages/index.js.map +1 -0
  133. package/dist/storages/key_value_store.d.ts +242 -0
  134. package/dist/storages/key_value_store.d.ts.map +1 -0
  135. package/dist/storages/key_value_store.js +319 -0
  136. package/dist/storages/key_value_store.js.map +1 -0
  137. package/dist/storages/request_list.d.ts +461 -0
  138. package/dist/storages/request_list.d.ts.map +1 -0
  139. package/dist/storages/request_list.js +715 -0
  140. package/dist/storages/request_list.js.map +1 -0
  141. package/dist/storages/request_queue.d.ts +312 -0
  142. package/dist/storages/request_queue.d.ts.map +1 -0
  143. package/dist/storages/request_queue.js +708 -0
  144. package/dist/storages/request_queue.js.map +1 -0
  145. package/dist/storages/storage.d.ts +260 -0
  146. package/dist/storages/storage.d.ts.map +1 -0
  147. package/dist/storages/storage.js +3 -0
  148. package/dist/storages/storage.js.map +1 -0
  149. package/dist/storages/storage_manager.d.ts +40 -0
  150. package/dist/storages/storage_manager.d.ts.map +1 -0
  151. package/dist/storages/storage_manager.js +119 -0
  152. package/dist/storages/storage_manager.js.map +1 -0
  153. package/dist/tsconfig.build.tsbuildinfo +1 -0
  154. package/dist/typedefs.d.ts +12 -0
  155. package/dist/typedefs.d.ts.map +1 -0
  156. package/dist/typedefs.js +15 -0
  157. package/dist/typedefs.js.map +1 -0
  158. package/dist/validators.d.ts +21 -0
  159. package/dist/validators.d.ts.map +1 -0
  160. package/dist/validators.js +26 -0
  161. package/dist/validators.js.map +1 -0
  162. package/package.json +11 -10
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalEventManager = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // eslint-disable-next-line max-classes-per-file
6
+ const os_1 = tslib_1.__importDefault(require("os"));
7
+ const log_1 = tslib_1.__importDefault(require("@apify/log"));
8
+ const utilities_1 = require("@apify/utilities");
9
+ const utils_1 = require("@crawlee/utils");
10
+ const event_manager_1 = require("./event_manager");
11
+ class LocalEventManager extends event_manager_1.EventManager {
12
+ constructor() {
13
+ super(...arguments);
14
+ Object.defineProperty(this, "intervals", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: {}
19
+ });
20
+ Object.defineProperty(this, "previousTicks", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: { idle: 0, total: 0 }
25
+ });
26
+ }
27
+ /**
28
+ * Initializes `Actor.events` event emitter by creating a connection to a websocket that provides them.
29
+ * This is an internal function that is automatically called by `Actor.main()`.
30
+ */
31
+ async init() {
32
+ if (this.initialized) {
33
+ return;
34
+ }
35
+ await super.init();
36
+ const systemInfoIntervalMillis = this.config.get('systemInfoIntervalMillis');
37
+ this.emitSystemInfoEvent = this.emitSystemInfoEvent.bind(this);
38
+ this.intervals.systemInfo = (0, utilities_1.betterSetInterval)(this.emitSystemInfoEvent.bind(this), systemInfoIntervalMillis);
39
+ }
40
+ /**
41
+ * Closes websocket providing events from Actor infrastructure and also stops sending internal events
42
+ * of Apify package such as `persistState`.
43
+ * This is automatically called at the end of `Actor.main()`.
44
+ */
45
+ async close() {
46
+ if (!this.initialized) {
47
+ return;
48
+ }
49
+ await super.close();
50
+ (0, utilities_1.betterClearInterval)(this.intervals.systemInfo);
51
+ }
52
+ /**
53
+ * @internal
54
+ */
55
+ async emitSystemInfoEvent(intervalCallback) {
56
+ const info = await this.createSystemInfo({
57
+ maxUsedCpuRatio: this.config.get('maxUsedCpuRatio'),
58
+ });
59
+ this.events.emit("systemInfo" /* SYSTEM_INFO */, info);
60
+ intervalCallback();
61
+ }
62
+ getCurrentCpuTicks() {
63
+ const cpus = os_1.default.cpus();
64
+ return cpus.reduce((acc, cpu) => {
65
+ const cpuTimes = Object.values(cpu.times);
66
+ return {
67
+ idle: acc.idle + cpu.times.idle,
68
+ total: acc.total + cpuTimes.reduce((sum, num) => sum + num),
69
+ };
70
+ }, { idle: 0, total: 0 });
71
+ }
72
+ /**
73
+ * Creates a SystemInfo object based on local metrics.
74
+ */
75
+ async createSystemInfo(options) {
76
+ return {
77
+ createdAt: new Date(),
78
+ ...this.createCpuInfo(options),
79
+ ...await this.createMemoryInfo(),
80
+ };
81
+ }
82
+ createCpuInfo(options) {
83
+ const ticks = this.getCurrentCpuTicks();
84
+ const idleTicksDelta = ticks.idle - this.previousTicks.idle;
85
+ const totalTicksDelta = ticks.total - this.previousTicks.total;
86
+ const usedCpuRatio = totalTicksDelta ? 1 - (idleTicksDelta / totalTicksDelta) : 0;
87
+ Object.assign(this.previousTicks, ticks);
88
+ return {
89
+ cpuCurrentUsage: usedCpuRatio * 100,
90
+ isCpuOverloaded: usedCpuRatio > options.maxUsedCpuRatio,
91
+ };
92
+ }
93
+ async createMemoryInfo() {
94
+ try {
95
+ const memInfo = await this._getMemoryInfo();
96
+ const { mainProcessBytes, childProcessesBytes } = memInfo;
97
+ return {
98
+ memCurrentBytes: mainProcessBytes + childProcessesBytes,
99
+ };
100
+ }
101
+ catch (err) {
102
+ log_1.default.exception(err, 'Memory snapshot failed.');
103
+ return {};
104
+ }
105
+ }
106
+ /**
107
+ * Helper method for easier mocking.
108
+ */
109
+ async _getMemoryInfo() {
110
+ return (0, utils_1.getMemoryInfo)();
111
+ }
112
+ }
113
+ exports.LocalEventManager = LocalEventManager;
114
+ //# sourceMappingURL=local_event_manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_event_manager.js","sourceRoot":"","sources":["../../src/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AC,CAAC;QAEzC,OAAO;YACH,eAAe,EAAE,YAAY,GAAG,GAAG;YACnC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe;SAC1D,CAAC;IACN,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC1B,IAAI;YACA,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;YAC5C,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;YAE1D,OAAO;gBACH,eAAe,EAAE,gBAAgB,GAAG,mBAAmB;aAC1D,CAAC;SACL;QAAC,OAAO,GAAG,EAAE;YACV,aAAG,CAAC,SAAS,CAAC,GAAY,EAAE,yBAAyB,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC;SACb;IACL,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,cAAc;QACxB,OAAO,IAAA,qBAAa,GAAE,CAAC;IAC3B,CAAC;CACJ;AApGD,8CAoGC"}
@@ -0,0 +1,14 @@
1
+ export * from './autoscaling';
2
+ export * from './configuration';
3
+ export * from './constants';
4
+ export * from './crawlers';
5
+ export * from './enqueue_links';
6
+ export * from './events';
7
+ export * from './log';
8
+ export * from './proxy_configuration';
9
+ export * from './request';
10
+ export * from './serialization';
11
+ export * from './session_pool';
12
+ export * from './storages';
13
+ export * from './validators';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./autoscaling"), exports);
5
+ tslib_1.__exportStar(require("./configuration"), exports);
6
+ tslib_1.__exportStar(require("./constants"), exports);
7
+ tslib_1.__exportStar(require("./crawlers"), exports);
8
+ tslib_1.__exportStar(require("./enqueue_links"), exports);
9
+ tslib_1.__exportStar(require("./events"), exports);
10
+ tslib_1.__exportStar(require("./log"), exports);
11
+ tslib_1.__exportStar(require("./proxy_configuration"), exports);
12
+ tslib_1.__exportStar(require("./request"), exports);
13
+ tslib_1.__exportStar(require("./serialization"), exports);
14
+ tslib_1.__exportStar(require("./session_pool"), exports);
15
+ tslib_1.__exportStar(require("./storages"), exports);
16
+ tslib_1.__exportStar(require("./validators"), exports);
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,0DAAgC;AAChC,sDAA4B;AAC5B,qDAA2B;AAC3B,0DAAgC;AAChC,mDAAyB;AACzB,gDAAsB;AACtB,gEAAsC;AACtC,oDAA0B;AAC1B,0DAAgC;AAChC,yDAA+B;AAC/B,qDAA2B;AAC3B,uDAA6B"}
package/dist/index.mjs ADDED
@@ -0,0 +1,63 @@
1
+ import mod from "./index.js";
2
+
3
+ export default mod;
4
+ export const API_PROCESSED_REQUESTS_DELAY_MILLIS = mod.API_PROCESSED_REQUESTS_DELAY_MILLIS;
5
+ export const AutoscaledPool = mod.AutoscaledPool;
6
+ export const Configuration = mod.Configuration;
7
+ export const CookieParseError = mod.CookieParseError;
8
+ export const CrawlerExtension = mod.CrawlerExtension;
9
+ export const DATASET_ITERATORS_DEFAULT_LIMIT = mod.DATASET_ITERATORS_DEFAULT_LIMIT;
10
+ export const Dataset = mod.Dataset;
11
+ export const EVENT_SESSION_RETIRED = mod.EVENT_SESSION_RETIRED;
12
+ export const EnqueueStrategy = mod.EnqueueStrategy;
13
+ export const EventManager = mod.EventManager;
14
+ export const EventType = mod.EventType;
15
+ export const KeyValueStore = mod.KeyValueStore;
16
+ export const LocalEventManager = mod.LocalEventManager;
17
+ export const Log = mod.Log;
18
+ export const LogLevel = mod.LogLevel;
19
+ export const Logger = mod.Logger;
20
+ export const LoggerJson = mod.LoggerJson;
21
+ export const LoggerText = mod.LoggerText;
22
+ export const MAX_QUERIES_FOR_CONSISTENCY = mod.MAX_QUERIES_FOR_CONSISTENCY;
23
+ export const ProxyConfiguration = mod.ProxyConfiguration;
24
+ export const QUERY_HEAD_BUFFER = mod.QUERY_HEAD_BUFFER;
25
+ export const QUERY_HEAD_MIN_LENGTH = mod.QUERY_HEAD_MIN_LENGTH;
26
+ export const REQUESTS_PERSISTENCE_KEY = mod.REQUESTS_PERSISTENCE_KEY;
27
+ export const Request = mod.Request;
28
+ export const RequestList = mod.RequestList;
29
+ export const RequestQueue = mod.RequestQueue;
30
+ export const STATE_PERSISTENCE_KEY = mod.STATE_PERSISTENCE_KEY;
31
+ export const STATUS_CODES_BLOCKED = mod.STATUS_CODES_BLOCKED;
32
+ export const STORAGE_CONSISTENCY_DELAY_MILLIS = mod.STORAGE_CONSISTENCY_DELAY_MILLIS;
33
+ export const Session = mod.Session;
34
+ export const SessionPool = mod.SessionPool;
35
+ export const Snapshotter = mod.Snapshotter;
36
+ export const Statistics = mod.Statistics;
37
+ export const StorageManager = mod.StorageManager;
38
+ export const SystemStatus = mod.SystemStatus;
39
+ export const checkAndSerialize = mod.checkAndSerialize;
40
+ export const chunkBySize = mod.chunkBySize;
41
+ export const constructGlobObjectsFromGlobs = mod.constructGlobObjectsFromGlobs;
42
+ export const constructRegExpObjectsFromPseudoUrls = mod.constructRegExpObjectsFromPseudoUrls;
43
+ export const constructRegExpObjectsFromRegExps = mod.constructRegExpObjectsFromRegExps;
44
+ export const createDeserialize = mod.createDeserialize;
45
+ export const createRequestOptions = mod.createRequestOptions;
46
+ export const createRequests = mod.createRequests;
47
+ export const deserializeArray = mod.deserializeArray;
48
+ export const diffCookies = mod.diffCookies;
49
+ export const enqueueLinks = mod.enqueueLinks;
50
+ export const getCookiesFromResponse = mod.getCookiesFromResponse;
51
+ export const getRequestId = mod.getRequestId;
52
+ export const handleRequestTimeout = mod.handleRequestTimeout;
53
+ export const log = mod.log;
54
+ export const maybeStringify = mod.maybeStringify;
55
+ export const mergeCookies = mod.mergeCookies;
56
+ export const openDataset = mod.openDataset;
57
+ export const pushData = mod.pushData;
58
+ export const serializeArray = mod.serializeArray;
59
+ export const storage = mod.storage;
60
+ export const throwOnBlockedRequest = mod.throwOnBlockedRequest;
61
+ export const updateEnqueueLinksPatternCache = mod.updateEnqueueLinksPatternCache;
62
+ export const validateGlobPattern = mod.validateGlobPattern;
63
+ export const validators = mod.validators;
package/dist/log.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import log, { Log, LoggerOptions, LogLevel, Logger, LoggerJson, LoggerText } from '@apify/log';
2
+ export { log, Log, LoggerOptions, LogLevel, Logger, LoggerJson, LoggerText, };
3
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EACH,GAAG,EACH,GAAG,EACH,aAAa,EACb,QAAQ,EACR,MAAM,EACN,UAAU,EACV,UAAU,GACb,CAAC"}
package/dist/log.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerText = exports.LoggerJson = exports.Logger = exports.LogLevel = exports.Log = exports.log = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const log_1 = tslib_1.__importStar(require("@apify/log"));
6
+ exports.log = log_1.default;
7
+ Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return log_1.Log; } });
8
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return log_1.LogLevel; } });
9
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return log_1.Logger; } });
10
+ Object.defineProperty(exports, "LoggerJson", { enumerable: true, get: function () { return log_1.LoggerJson; } });
11
+ Object.defineProperty(exports, "LoggerText", { enumerable: true, get: function () { return log_1.LoggerText; } });
12
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;AAAA,0DAA+F;AAG3F,cAHG,aAAG,CAGH;AACH,oFAJU,SAAG,OAIV;AAEH,yFAN8B,cAAQ,OAM9B;AACR,uFAPwC,YAAM,OAOxC;AACN,2FARgD,gBAAU,OAQhD;AACV,2FAT4D,gBAAU,OAS5D"}
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@crawlee/core",
3
+ "version": "3.0.0-alpha.3",
4
+ "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
+ "engines": {
6
+ "node": ">=16.0.0"
7
+ },
8
+ "types": "index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./index.mjs",
12
+ "require": "./index.js"
13
+ }
14
+ },
15
+ "keywords": [
16
+ "apify",
17
+ "headless",
18
+ "chrome",
19
+ "puppeteer",
20
+ "crawler",
21
+ "scraper"
22
+ ],
23
+ "author": {
24
+ "name": "Apify",
25
+ "email": "support@apify.com",
26
+ "url": "https://apify.com"
27
+ },
28
+ "contributors": [
29
+ "Jan Curn <jan@apify.com>",
30
+ "Marek Trunkat <marek@apify.com>",
31
+ "Ondra Urban <ondra@apify.com>"
32
+ ],
33
+ "license": "Apache-2.0",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/apify/apify-js"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/apify/apify-js/issues"
40
+ },
41
+ "homepage": "https://sdk.apify.com/",
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "scripts": {
46
+ "build": "npm run clean && npm run compile && npm run copy",
47
+ "clean": "rimraf ./dist",
48
+ "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./index.js ./index.mjs",
49
+ "copy": "ts-node -T ../../scripts/copy.ts"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "dependencies": {
55
+ "@apify/consts": "^1.4.2",
56
+ "@apify/datastructures": "^1.0.1",
57
+ "@apify/log": "^1.1.6",
58
+ "@apify/ps-tree": "^1.1.4",
59
+ "@apify/pseudo_url": "^1.1.0",
60
+ "@apify/timeout": "^0.2.1",
61
+ "@apify/utilities": "^1.2.5",
62
+ "@apify/storage-local": "^2.0.3-beta.3",
63
+ "@crawlee/browser-pool": "^3.0.0-alpha.3",
64
+ "@crawlee/storage": "^3.0.0-alpha.3",
65
+ "@crawlee/utils": "^3.0.0-alpha.3",
66
+ "@types/mime-types": "^2.1.1",
67
+ "@types/stream-json": "^1.7.1",
68
+ "content-type": "^1.0.4",
69
+ "got-scraping": "^3.2.7",
70
+ "htmlparser2": "^7.0.0",
71
+ "iconv-lite": "^0.6.3",
72
+ "jquery": "^3.6.0",
73
+ "mime-types": "^2.1.34",
74
+ "minimatch": "^5.0.1",
75
+ "ow": "^0.28.0",
76
+ "proxy-chain": "^2.0.1-beta.0",
77
+ "stream-json": "^1.7.3",
78
+ "tldts": "^5.7.69",
79
+ "tough-cookie": "^4.0.0",
80
+ "ws": "^7.5.3"
81
+ }
82
+ }
@@ -0,0 +1,181 @@
1
+ import { Configuration } from './configuration';
2
+ export interface ProxyConfigurationFunction {
3
+ (sessionId: string | number): string;
4
+ }
5
+ export interface ProxyConfigurationOptions {
6
+ /**
7
+ * An array of custom proxy URLs to be rotated.
8
+ * Custom proxies are not compatible with Apify Proxy and an attempt to use both
9
+ * configuration options will cause an error to be thrown on initialize.
10
+ */
11
+ proxyUrls?: string[];
12
+ /**
13
+ * Custom function that allows you to generate the new proxy URL dynamically. It gets the `sessionId` as a parameter
14
+ * and should always return stringified proxy URL.
15
+ * This function is used to generate the URL when {@link ProxyConfiguration.newUrl} or {@link ProxyConfiguration.newProxyInfo} is called.
16
+ */
17
+ newUrlFunction?: ProxyConfigurationFunction;
18
+ }
19
+ /**
20
+ * The main purpose of the ProxyInfo object is to provide information
21
+ * about the current proxy connection used by the crawler for the request.
22
+ * Outside of crawlers, you can get this object by calling {@link ProxyConfiguration.newProxyInfo}.
23
+ *
24
+ * **Example usage:**
25
+ *
26
+ * ```javascript
27
+ * // TODO fix examples and jsdoc
28
+ * const proxyConfiguration = new ProxyConfiguration({
29
+ * groups: ['GROUP1', 'GROUP2'] // List of Apify Proxy groups
30
+ * countryCode: 'US',
31
+ * });
32
+ *
33
+ * // Getting proxyInfo object by calling class method directly
34
+ * const proxyInfo = proxyConfiguration.newProxyInfo();
35
+ *
36
+ * // In crawler
37
+ * const crawler = new CheerioCrawler({
38
+ * // ...
39
+ * proxyConfiguration,
40
+ * handlePageFunction: ({ proxyInfo }) => {
41
+ * // Getting used proxy URL
42
+ * const proxyUrl = proxyInfo.url;
43
+ *
44
+ * // Getting ID of used Session
45
+ * const sessionIdentifier = proxyInfo.sessionId;
46
+ * }
47
+ * })
48
+ *
49
+ * ```
50
+ */
51
+ export interface ProxyInfo {
52
+ /**
53
+ * The identifier of used {@link Session}, if used.
54
+ */
55
+ sessionId?: string;
56
+ /**
57
+ * The URL of the proxy.
58
+ */
59
+ url: string;
60
+ /**
61
+ * Username for the proxy.
62
+ */
63
+ username?: string;
64
+ /**
65
+ * User's password for the proxy.
66
+ */
67
+ password: string;
68
+ /**
69
+ * Hostname of your proxy.
70
+ */
71
+ hostname: string;
72
+ /**
73
+ * Proxy port.
74
+ */
75
+ port: number | string;
76
+ }
77
+ /**
78
+ * Configures connection to a proxy server with the provided options. Proxy servers are used to prevent target websites from blocking
79
+ * your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
80
+ * them to use the selected proxies for all connections. You can get information about the currently used proxy by inspecting
81
+ * the {@link ProxyInfo} property in your crawler's page function. There, you can inspect the proxy's URL and other attributes.
82
+ *
83
+ * If you want to use your own proxies, use the {@link ProxyConfigurationOptions.proxyUrls} option. Your list of proxy URLs will
84
+ * be rotated by the configuration if this option is provided.
85
+ *
86
+ * **Example usage:**
87
+ *
88
+ * ```javascript
89
+ *
90
+ * const proxyConfiguration = new ProxyConfiguration({
91
+ * proxyUrls: ['...', '...'],
92
+ * });
93
+ *
94
+ * const crawler = new CheerioCrawler({
95
+ * // ...
96
+ * proxyConfiguration,
97
+ * handlePageFunction: ({ proxyInfo }) => {
98
+ * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
99
+ * }
100
+ * })
101
+ *
102
+ * ```
103
+ * @category Scaling
104
+ */
105
+ export declare class ProxyConfiguration {
106
+ readonly config: Configuration;
107
+ isManInTheMiddle: boolean;
108
+ protected nextCustomUrlIndex: number;
109
+ protected proxyUrls?: string[];
110
+ protected usedProxyUrls: Map<string, string>;
111
+ protected newUrlFunction?: ProxyConfigurationFunction;
112
+ protected log: import("@apify/log").Log;
113
+ /**
114
+ * Creates a {@link ProxyConfiguration} instance based on the provided options. Proxy servers are used to prevent target websites from
115
+ * blocking your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
116
+ * them to use the selected proxies for all connections.
117
+ *
118
+ * ```javascript
119
+ * const proxyConfiguration = new ProxyConfiguration({
120
+ * proxyUrls: ['http://user:pass@proxy-1.com', 'http://user:pass@proxy-2.com'],
121
+ * });
122
+ *
123
+ * const crawler = new CheerioCrawler({
124
+ * // ...
125
+ * proxyConfiguration,
126
+ * handlePageFunction: ({ proxyInfo }) => {
127
+ * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
128
+ * }
129
+ * })
130
+ *
131
+ * ```
132
+ * @param options
133
+ * @param config
134
+ * @param validateRequired internal flag to disable validation that requires one of `proxyUrls` or `newUrlFunction`, defaults to true
135
+ */
136
+ constructor(options?: ProxyConfigurationOptions, config?: Configuration, validateRequired?: boolean);
137
+ /**
138
+ * This function creates a new {@link ProxyInfo} info object.
139
+ * It is used by CheerioCrawler and PuppeteerCrawler to generate proxy URLs and also to allow the user to inspect
140
+ * the currently used proxy via the handlePageFunction parameter: proxyInfo.
141
+ * Use it if you want to work with a rich representation of a proxy URL.
142
+ * If you need the URL string only, use {@link ProxyConfiguration.newUrl}.
143
+ * @param [sessionId]
144
+ * Represents the identifier of user {@link Session} that can be managed by the {@link SessionPool} or
145
+ * you can use the Apify Proxy [Session](https://docs.apify.com/proxy#sessions) identifier.
146
+ * When the provided sessionId is a number, it's converted to a string. Property sessionId of
147
+ * {@link ProxyInfo} is always returned as a type string.
148
+ *
149
+ * All the HTTP requests going through the proxy with the same session identifier
150
+ * will use the same target proxy server (i.e. the same IP address).
151
+ * The identifier must not be longer than 50 characters and include only the following: `0-9`, `a-z`, `A-Z`, `"."`, `"_"` and `"~"`.
152
+ * @return Represents information about used proxy and its configuration.
153
+ */
154
+ newProxyInfo(sessionId?: string | number): ProxyInfo;
155
+ /**
156
+ * Returns a new proxy URL based on provided configuration options and the `sessionId` parameter.
157
+ * @param [sessionId]
158
+ * Represents the identifier of user {@link Session} that can be managed by the {@link SessionPool} or
159
+ * you can use the Apify Proxy [Session](https://docs.apify.com/proxy#sessions) identifier.
160
+ * When the provided sessionId is a number, it's converted to a string.
161
+ *
162
+ * All the HTTP requests going through the proxy with the same session identifier
163
+ * will use the same target proxy server (i.e. the same IP address).
164
+ * The identifier must not be longer than 50 characters and include only the following: `0-9`, `a-z`, `A-Z`, `"."`, `"_"` and `"~"`.
165
+ * @return A string with a proxy URL, including authentication credentials and port number.
166
+ * For example, `http://bob:password123@proxy.example.com:8000`
167
+ */
168
+ newUrl(sessionId?: string | number): string;
169
+ /**
170
+ * Handles custom url rotation with session
171
+ */
172
+ protected _handleCustomUrl(sessionId?: string): string;
173
+ /**
174
+ * Calls the custom newUrlFunction and checks format of its return value
175
+ */
176
+ protected _callNewUrlFunction(sessionId?: string): string | undefined;
177
+ protected _throwNewUrlFunctionInvalid(err: Error): void;
178
+ protected _throwCannotCombineCustomMethods(): void;
179
+ protected _throwNoOptionsProvided(): void;
180
+ }
181
+ //# sourceMappingURL=proxy_configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy_configuration.d.ts","sourceRoot":"","sources":["../src/proxy_configuration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,WAAW,0BAA0B;IACvC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,yBAAyB;IACtC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB;;;;OAIG;IACH,cAAc,CAAC,EAAE,0BAA0B,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,kBAAkB;IA+B0B,QAAQ,CAAC,MAAM;IA9BpE,gBAAgB,UAAS;IACzB,SAAS,CAAC,kBAAkB,SAAK;IACjC,SAAS,CAAC,SAAS,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