@crawlee/core 4.0.0-beta.28 → 4.0.0-beta.280

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 (266) hide show
  1. package/README.md +15 -15
  2. package/byte-utils.d.ts +17 -0
  3. package/byte-utils.js +42 -0
  4. package/configuration.d.ts +75 -167
  5. package/configuration.js +164 -140
  6. package/debug.d.ts +36 -0
  7. package/debug.js +70 -0
  8. package/errors.d.ts +40 -19
  9. package/errors.js +52 -30
  10. package/events/{event_manager.d.ts → event-manager.d.ts} +29 -6
  11. package/events/{event_manager.js → event-manager.js} +10 -9
  12. package/events/index.d.ts +3 -3
  13. package/events/index.js +2 -3
  14. package/events/{local_event_manager.d.ts → local-event-manager.d.ts} +3 -10
  15. package/events/local-event-manager.js +101 -0
  16. package/events/system-info.d.ts +38 -0
  17. package/events/system-info.js +1 -0
  18. package/index.d.ts +9 -13
  19. package/index.js +10 -12
  20. package/internal.d.ts +8 -0
  21. package/internal.js +9 -0
  22. package/iterables.d.ts +79 -0
  23. package/iterables.js +134 -0
  24. package/log.d.ts +77 -1
  25. package/log.js +134 -1
  26. package/memory-storage/consts.d.ts +4 -0
  27. package/memory-storage/consts.js +4 -0
  28. package/memory-storage/index.d.ts +1 -0
  29. package/memory-storage/index.js +1 -0
  30. package/memory-storage/memory-storage.d.ts +43 -0
  31. package/memory-storage/memory-storage.js +158 -0
  32. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  33. package/memory-storage/resource-clients/common/base-client.js +6 -0
  34. package/memory-storage/resource-clients/dataset.d.ts +35 -0
  35. package/memory-storage/resource-clients/dataset.js +108 -0
  36. package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
  37. package/memory-storage/resource-clients/key-value-store.js +179 -0
  38. package/memory-storage/resource-clients/request-queue.d.ts +55 -0
  39. package/memory-storage/resource-clients/request-queue.js +413 -0
  40. package/memory-storage/utils.d.ts +16 -0
  41. package/memory-storage/utils.js +41 -0
  42. package/owned-or-injected.d.ts +58 -0
  43. package/owned-or-injected.js +98 -0
  44. package/package.json +23 -23
  45. package/proxy-configuration.d.ts +118 -0
  46. package/proxy-configuration.js +141 -0
  47. package/recoverable-state.d.ts +177 -0
  48. package/recoverable-state.js +268 -0
  49. package/request.d.ts +48 -101
  50. package/request.js +139 -249
  51. package/serialization.d.ts +0 -1
  52. package/serialization.js +18 -18
  53. package/{service_locator.d.ts → service-locator.d.ts} +66 -37
  54. package/service-locator.js +255 -0
  55. package/storages/batched-adds.d.ts +39 -0
  56. package/storages/batched-adds.js +81 -0
  57. package/storages/dataset.d.ts +105 -58
  58. package/storages/dataset.js +292 -151
  59. package/storages/index.d.ts +11 -12
  60. package/storages/index.js +7 -12
  61. package/storages/key-value-store-codec.d.ts +32 -0
  62. package/storages/key-value-store-codec.js +108 -0
  63. package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
  64. package/storages/key-value-store.js +767 -0
  65. package/storages/request-dedup-cache.d.ts +20 -0
  66. package/storages/request-dedup-cache.js +48 -0
  67. package/storages/{request_list.d.ts → request-list.d.ts} +32 -171
  68. package/storages/{request_list.js → request-list.js} +276 -253
  69. package/storages/request-loader.d.ts +127 -0
  70. package/storages/request-loader.js +34 -0
  71. package/storages/request-manager-tandem.d.ts +82 -0
  72. package/storages/request-manager-tandem.js +200 -0
  73. package/storages/request-manager.d.ts +119 -0
  74. package/storages/request-manager.js +1 -0
  75. package/storages/{request_provider.d.ts → request-queue.d.ts} +127 -161
  76. package/storages/request-queue.js +871 -0
  77. package/storages/storage-instance-manager.d.ts +86 -0
  78. package/storages/storage-instance-manager.js +256 -0
  79. package/storages/storage-stats.d.ts +48 -0
  80. package/storages/storage-stats.js +29 -0
  81. package/storages/transaction.d.ts +270 -0
  82. package/storages/transaction.js +296 -0
  83. package/storages/utils.d.ts +59 -11
  84. package/storages/utils.js +76 -17
  85. package/system-info/cpu-info.d.ts +67 -0
  86. package/system-info/cpu-info.js +216 -0
  87. package/system-info/memory-info.d.ts +31 -0
  88. package/system-info/memory-info.js +115 -0
  89. package/system-info/ps-tree.d.ts +17 -0
  90. package/system-info/ps-tree.js +144 -0
  91. package/system-info/runtime.d.ts +14 -0
  92. package/system-info/runtime.js +80 -0
  93. package/typedefs.d.ts +0 -6
  94. package/typedefs.js +0 -1
  95. package/url.d.ts +9 -0
  96. package/url.js +11 -0
  97. package/validators.d.ts +23 -18
  98. package/validators.js +14 -18
  99. package/autoscaling/autoscaled_pool.d.ts +0 -298
  100. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  101. package/autoscaling/autoscaled_pool.js +0 -527
  102. package/autoscaling/autoscaled_pool.js.map +0 -1
  103. package/autoscaling/index.d.ts +0 -4
  104. package/autoscaling/index.d.ts.map +0 -1
  105. package/autoscaling/index.js +0 -4
  106. package/autoscaling/index.js.map +0 -1
  107. package/autoscaling/snapshotter.d.ts +0 -179
  108. package/autoscaling/snapshotter.d.ts.map +0 -1
  109. package/autoscaling/snapshotter.js +0 -279
  110. package/autoscaling/snapshotter.js.map +0 -1
  111. package/autoscaling/system_status.d.ts +0 -178
  112. package/autoscaling/system_status.d.ts.map +0 -1
  113. package/autoscaling/system_status.js +0 -168
  114. package/autoscaling/system_status.js.map +0 -1
  115. package/configuration.d.ts.map +0 -1
  116. package/configuration.js.map +0 -1
  117. package/cookie_utils.d.ts +0 -43
  118. package/cookie_utils.d.ts.map +0 -1
  119. package/cookie_utils.js +0 -111
  120. package/cookie_utils.js.map +0 -1
  121. package/crawlers/context_pipeline.d.ts +0 -61
  122. package/crawlers/context_pipeline.d.ts.map +0 -1
  123. package/crawlers/context_pipeline.js +0 -99
  124. package/crawlers/context_pipeline.js.map +0 -1
  125. package/crawlers/crawler_commons.d.ts +0 -191
  126. package/crawlers/crawler_commons.d.ts.map +0 -1
  127. package/crawlers/crawler_commons.js +0 -108
  128. package/crawlers/crawler_commons.js.map +0 -1
  129. package/crawlers/crawler_utils.d.ts +0 -10
  130. package/crawlers/crawler_utils.d.ts.map +0 -1
  131. package/crawlers/crawler_utils.js +0 -12
  132. package/crawlers/crawler_utils.js.map +0 -1
  133. package/crawlers/error_snapshotter.d.ts +0 -60
  134. package/crawlers/error_snapshotter.d.ts.map +0 -1
  135. package/crawlers/error_snapshotter.js +0 -118
  136. package/crawlers/error_snapshotter.js.map +0 -1
  137. package/crawlers/error_tracker.d.ts +0 -55
  138. package/crawlers/error_tracker.d.ts.map +0 -1
  139. package/crawlers/error_tracker.js +0 -309
  140. package/crawlers/error_tracker.js.map +0 -1
  141. package/crawlers/index.d.ts +0 -7
  142. package/crawlers/index.d.ts.map +0 -1
  143. package/crawlers/index.js +0 -7
  144. package/crawlers/index.js.map +0 -1
  145. package/crawlers/internals/types.d.ts +0 -8
  146. package/crawlers/internals/types.d.ts.map +0 -1
  147. package/crawlers/internals/types.js +0 -2
  148. package/crawlers/internals/types.js.map +0 -1
  149. package/crawlers/statistics.d.ts +0 -204
  150. package/crawlers/statistics.d.ts.map +0 -1
  151. package/crawlers/statistics.js +0 -350
  152. package/crawlers/statistics.js.map +0 -1
  153. package/enqueue_links/enqueue_links.d.ts +0 -254
  154. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  155. package/enqueue_links/enqueue_links.js +0 -268
  156. package/enqueue_links/enqueue_links.js.map +0 -1
  157. package/enqueue_links/index.d.ts +0 -3
  158. package/enqueue_links/index.d.ts.map +0 -1
  159. package/enqueue_links/index.js +0 -3
  160. package/enqueue_links/index.js.map +0 -1
  161. package/enqueue_links/shared.d.ts +0 -84
  162. package/enqueue_links/shared.d.ts.map +0 -1
  163. package/enqueue_links/shared.js +0 -219
  164. package/enqueue_links/shared.js.map +0 -1
  165. package/errors.d.ts.map +0 -1
  166. package/errors.js.map +0 -1
  167. package/events/event_manager.d.ts.map +0 -1
  168. package/events/event_manager.js.map +0 -1
  169. package/events/index.d.ts.map +0 -1
  170. package/events/index.js.map +0 -1
  171. package/events/local_event_manager.d.ts.map +0 -1
  172. package/events/local_event_manager.js +0 -93
  173. package/events/local_event_manager.js.map +0 -1
  174. package/index.d.ts.map +0 -1
  175. package/index.js.map +0 -1
  176. package/log.d.ts.map +0 -1
  177. package/log.js.map +0 -1
  178. package/proxy_configuration.d.ts +0 -169
  179. package/proxy_configuration.d.ts.map +0 -1
  180. package/proxy_configuration.js +0 -247
  181. package/proxy_configuration.js.map +0 -1
  182. package/recoverable_state.d.ts +0 -122
  183. package/recoverable_state.d.ts.map +0 -1
  184. package/recoverable_state.js +0 -138
  185. package/recoverable_state.js.map +0 -1
  186. package/request.d.ts.map +0 -1
  187. package/request.js.map +0 -1
  188. package/router.d.ts +0 -134
  189. package/router.d.ts.map +0 -1
  190. package/router.js +0 -164
  191. package/router.js.map +0 -1
  192. package/serialization.d.ts.map +0 -1
  193. package/serialization.js.map +0 -1
  194. package/service_locator.d.ts.map +0 -1
  195. package/service_locator.js +0 -252
  196. package/service_locator.js.map +0 -1
  197. package/session_pool/consts.d.ts +0 -4
  198. package/session_pool/consts.d.ts.map +0 -1
  199. package/session_pool/consts.js +0 -4
  200. package/session_pool/consts.js.map +0 -1
  201. package/session_pool/errors.d.ts +0 -8
  202. package/session_pool/errors.d.ts.map +0 -1
  203. package/session_pool/errors.js +0 -12
  204. package/session_pool/errors.js.map +0 -1
  205. package/session_pool/events.d.ts +0 -3
  206. package/session_pool/events.d.ts.map +0 -1
  207. package/session_pool/events.js +0 -3
  208. package/session_pool/events.js.map +0 -1
  209. package/session_pool/index.d.ts +0 -6
  210. package/session_pool/index.d.ts.map +0 -1
  211. package/session_pool/index.js +0 -6
  212. package/session_pool/index.js.map +0 -1
  213. package/session_pool/session.d.ts +0 -186
  214. package/session_pool/session.d.ts.map +0 -1
  215. package/session_pool/session.js +0 -278
  216. package/session_pool/session.js.map +0 -1
  217. package/session_pool/session_pool.d.ts +0 -256
  218. package/session_pool/session_pool.d.ts.map +0 -1
  219. package/session_pool/session_pool.js +0 -386
  220. package/session_pool/session_pool.js.map +0 -1
  221. package/storages/access_checking.d.ts +0 -13
  222. package/storages/access_checking.d.ts.map +0 -1
  223. package/storages/access_checking.js +0 -14
  224. package/storages/access_checking.js.map +0 -1
  225. package/storages/dataset.d.ts.map +0 -1
  226. package/storages/dataset.js.map +0 -1
  227. package/storages/index.d.ts.map +0 -1
  228. package/storages/index.js.map +0 -1
  229. package/storages/key_value_store.d.ts.map +0 -1
  230. package/storages/key_value_store.js +0 -513
  231. package/storages/key_value_store.js.map +0 -1
  232. package/storages/request_list.d.ts.map +0 -1
  233. package/storages/request_list.js.map +0 -1
  234. package/storages/request_list_adapter.d.ts +0 -58
  235. package/storages/request_list_adapter.d.ts.map +0 -1
  236. package/storages/request_list_adapter.js +0 -81
  237. package/storages/request_list_adapter.js.map +0 -1
  238. package/storages/request_manager_tandem.d.ts +0 -68
  239. package/storages/request_manager_tandem.d.ts.map +0 -1
  240. package/storages/request_manager_tandem.js +0 -124
  241. package/storages/request_manager_tandem.js.map +0 -1
  242. package/storages/request_provider.d.ts.map +0 -1
  243. package/storages/request_provider.js +0 -592
  244. package/storages/request_provider.js.map +0 -1
  245. package/storages/request_queue.d.ts +0 -128
  246. package/storages/request_queue.d.ts.map +0 -1
  247. package/storages/request_queue.js +0 -320
  248. package/storages/request_queue.js.map +0 -1
  249. package/storages/request_queue_v2.d.ts +0 -87
  250. package/storages/request_queue_v2.d.ts.map +0 -1
  251. package/storages/request_queue_v2.js +0 -437
  252. package/storages/request_queue_v2.js.map +0 -1
  253. package/storages/sitemap_request_list.d.ts +0 -245
  254. package/storages/sitemap_request_list.d.ts.map +0 -1
  255. package/storages/sitemap_request_list.js +0 -431
  256. package/storages/sitemap_request_list.js.map +0 -1
  257. package/storages/storage_manager.d.ts +0 -60
  258. package/storages/storage_manager.d.ts.map +0 -1
  259. package/storages/storage_manager.js +0 -95
  260. package/storages/storage_manager.js.map +0 -1
  261. package/storages/utils.d.ts.map +0 -1
  262. package/storages/utils.js.map +0 -1
  263. package/typedefs.d.ts.map +0 -1
  264. package/typedefs.js.map +0 -1
  265. package/validators.d.ts.map +0 -1
  266. package/validators.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"local_event_manager.d.ts","sourceRoot":"","sources":["../../src/events/local_event_manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAa,MAAM,oBAAoB,CAAC;AAEvF,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB;IACjE,oEAAoE;IACpE,wBAAwB,EAAE,MAAM,CAAC;CACpC;AAED,qBAAa,iBAAkB,SAAQ,YAAY;IAC/C,OAAO,CAAC,wBAAwB,CAAS;gBAE7B,OAAO,EAAE,wBAAwB;IAK7C;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,iBAAiB;IAS5D;;;OAGG;IACY,IAAI;IAcnB;;OAEG;IACY,KAAK;IASpB;;OAEG;IACG,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,OAAO;IAQzD;;OAEG;IACG,sBAAsB;IAK5B;;OAEG;YACW,gBAAgB;YAQhB,aAAa;YASb,gBAAgB;CAYjC"}
@@ -1,93 +0,0 @@
1
- import log from '@apify/log';
2
- import { betterClearInterval, betterSetInterval } from '@apify/utilities';
3
- import { serviceLocator } from '../service_locator.js';
4
- import { EventManager } from './event_manager.js';
5
- export class LocalEventManager extends EventManager {
6
- systemInfoIntervalMillis;
7
- constructor(options) {
8
- super(options);
9
- this.systemInfoIntervalMillis = options.systemInfoIntervalMillis;
10
- }
11
- /**
12
- * Creates a new `LocalEventManager` based on the provided `Configuration`.
13
- * Uses the global configuration from the service locator if none is provided.
14
- */
15
- static fromConfig(config) {
16
- const resolvedConfig = config ?? serviceLocator.getConfiguration();
17
- return new LocalEventManager({
18
- persistStateIntervalMillis: resolvedConfig.get('persistStateIntervalMillis'),
19
- systemInfoIntervalMillis: resolvedConfig.get('systemInfoIntervalMillis'),
20
- });
21
- }
22
- /**
23
- * Initializes the EventManager and sets up periodic `systemInfo` events.
24
- * This is automatically called at the beginning of `crawler.run()`.
25
- */
26
- async init() {
27
- if (this.initialized) {
28
- return;
29
- }
30
- await super.init();
31
- this.emitSystemInfoEvent = this.emitSystemInfoEvent.bind(this);
32
- this.intervals.systemInfo = betterSetInterval(this.emitSystemInfoEvent.bind(this), this.systemInfoIntervalMillis);
33
- }
34
- /**
35
- * @inheritDoc
36
- */
37
- async close() {
38
- if (!this.initialized) {
39
- return;
40
- }
41
- await super.close();
42
- betterClearInterval(this.intervals.systemInfo);
43
- }
44
- /**
45
- * @internal
46
- */
47
- async emitSystemInfoEvent(intervalCallback) {
48
- const info = await this.createSystemInfo({
49
- maxUsedCpuRatio: serviceLocator.getConfiguration().get('maxUsedCpuRatio'),
50
- });
51
- this.events.emit("systemInfo" /* EventType.SYSTEM_INFO */, info);
52
- intervalCallback();
53
- }
54
- /**
55
- * @internal
56
- */
57
- async isContainerizedWrapper() {
58
- const { isContainerized } = await import('@crawlee/utils');
59
- return serviceLocator.getConfiguration().get('containerized', await isContainerized());
60
- }
61
- /**
62
- * Creates a SystemInfo object based on local metrics.
63
- */
64
- async createSystemInfo(options) {
65
- return {
66
- createdAt: new Date(),
67
- ...(await this.createCpuInfo(options)),
68
- ...(await this.createMemoryInfo()),
69
- };
70
- }
71
- async createCpuInfo(options) {
72
- const { getCurrentCpuTicksV2 } = await import('@crawlee/utils');
73
- const usedCpuRatio = await getCurrentCpuTicksV2(await this.isContainerizedWrapper());
74
- return {
75
- cpuCurrentUsage: usedCpuRatio * 100,
76
- isCpuOverloaded: usedCpuRatio > options.maxUsedCpuRatio,
77
- };
78
- }
79
- async createMemoryInfo() {
80
- try {
81
- const { getMemoryInfo } = await import('@crawlee/utils');
82
- const memInfo = await getMemoryInfo(await this.isContainerizedWrapper());
83
- return {
84
- memCurrentBytes: memInfo.mainProcessBytes + memInfo.childProcessesBytes,
85
- };
86
- }
87
- catch (err) {
88
- log.exception(err, 'Memory snapshot failed.');
89
- return {};
90
- }
91
- }
92
- }
93
- //# sourceMappingURL=local_event_manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local_event_manager.js","sourceRoot":"","sources":["../../src/events/local_event_manager.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAI1E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AAOvF,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IACvC,wBAAwB,CAAS;IAEzC,YAAY,OAAiC;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IACrE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,MAAsB;QACpC,MAAM,cAAc,GAAG,MAAM,IAAI,cAAc,CAAC,gBAAgB,EAAE,CAAC;QAEnE,OAAO,IAAI,iBAAiB,CAAC;YACzB,0BAA0B,EAAE,cAAc,CAAC,GAAG,CAAC,4BAA4B,CAAC;YAC5E,wBAAwB,EAAE,cAAc,CAAC,GAAG,CAAC,0BAA0B,CAAC;SAC3E,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACM,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QAED,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/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AAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
package/log.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AAC9D,YAAY,EAAE,aAAa,EAAE,CAAC"}
package/log.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
@@ -1,169 +0,0 @@
1
- import type { ProxyInfo } from '@crawlee/types';
2
- import type { Request } from './request.js';
3
- export interface ProxyConfigurationFunction {
4
- (options?: {
5
- request?: Request;
6
- }): string | null | Promise<string | null>;
7
- }
8
- type UrlList = (string | null)[];
9
- export interface ProxyConfigurationOptions {
10
- /**
11
- * An array of custom proxy URLs to be rotated.
12
- * Custom proxies are not compatible with Apify Proxy and an attempt to use both
13
- * configuration options will cause an error to be thrown on initialize.
14
- */
15
- proxyUrls?: UrlList;
16
- /**
17
- * Custom function that allows you to generate the new proxy URL dynamically. It gets an optional parameter with the `Request` object when applicable.
18
- * Can return either stringified proxy URL or `null` if the proxy should not be used. Can be asynchronous.
19
- *
20
- * This function is used to generate the URL when {@link ProxyConfiguration.newUrl} or {@link ProxyConfiguration.newProxyInfo} is called.
21
- */
22
- newUrlFunction?: ProxyConfigurationFunction;
23
- /**
24
- * An array of custom proxy URLs to be rotated stratified in tiers.
25
- * This is a more advanced version of `proxyUrls` that allows you to define a hierarchy of proxy URLs
26
- * If everything goes well, all the requests will be sent through the first proxy URL in the list.
27
- * Whenever the crawler encounters a problem with the current proxy on the given domain, it will switch to the higher tier for this domain.
28
- * The crawler probes lower-level proxies at intervals to check if it can make the tier downshift.
29
- *
30
- * This feature is useful when you have a set of proxies with different performance characteristics (speed, price, antibot performance etc.) and you want to use the best one for each domain.
31
- *
32
- * Use `null` as a proxy URL to disable the proxy for the given tier.
33
- */
34
- tieredProxyUrls?: UrlList[];
35
- }
36
- export interface TieredProxy {
37
- proxyUrl: string | null;
38
- proxyTier?: number;
39
- }
40
- interface TieredProxyOptions {
41
- request?: Request;
42
- proxyTier?: number;
43
- }
44
- /**
45
- * Internal class for tracking the proxy tier history for a specific domain.
46
- *
47
- * Predicts the best proxy tier for the next request based on the error history for different proxy tiers.
48
- */
49
- declare class ProxyTierTracker {
50
- private histogram;
51
- private currentTier;
52
- constructor(tieredProxyUrls: (string | null)[][]);
53
- /**
54
- * Processes a single step of the algorithm and updates the current tier prediction based on the error history.
55
- */
56
- private processStep;
57
- /**
58
- * Increases the error score for the given proxy tier. This raises the chance of picking a different proxy tier for the subsequent requests.
59
- *
60
- * The error score is increased by 10 for the given tier. This means that this tier will be disadvantaged for the next 10 requests (every new request prediction decreases the error score by 1).
61
- * @param tier The proxy tier to mark as problematic.
62
- */
63
- addError(tier: number): void;
64
- /**
65
- * Returns the best proxy tier for the next request based on the error history for different proxy tiers.
66
- * @returns The proxy tier prediction
67
- */
68
- predictTier(): number;
69
- }
70
- /**
71
- * Configures connection to a proxy server with the provided options. Proxy servers are used to prevent target websites from blocking
72
- * your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
73
- * them to use the selected proxies for all connections. You can get information about the currently used proxy by inspecting
74
- * the {@link ProxyInfo} property in your crawler's page function. There, you can inspect the proxy's URL and other attributes.
75
- *
76
- * If you want to use your own proxies, use the {@link ProxyConfigurationOptions.proxyUrls} option. Your list of proxy URLs will
77
- * be rotated by the configuration if this option is provided.
78
- *
79
- * **Example usage:**
80
- *
81
- * ```javascript
82
- *
83
- * const proxyConfiguration = new ProxyConfiguration({
84
- * proxyUrls: ['...', '...'],
85
- * });
86
- *
87
- * const crawler = new CheerioCrawler({
88
- * // ...
89
- * proxyConfiguration,
90
- * requestHandler({ proxyInfo }) {
91
- * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
92
- * }
93
- * })
94
- *
95
- * ```
96
- * @category Scaling
97
- */
98
- export declare class ProxyConfiguration {
99
- isManInTheMiddle: boolean;
100
- protected nextCustomUrlIndex: number;
101
- protected proxyUrls?: UrlList;
102
- protected tieredProxyUrls?: UrlList[];
103
- protected usedProxyUrls: Map<string, string | null>;
104
- protected newUrlFunction?: ProxyConfigurationFunction;
105
- // @ts-ignore optional peer dependency or compatibility with es2022
106
- protected log: import("@apify/log").Log;
107
- protected domainTiers: Map<string, ProxyTierTracker>;
108
- /**
109
- * Creates a {@link ProxyConfiguration} instance based on the provided options. Proxy servers are used to prevent target websites from
110
- * blocking your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
111
- * them to use the selected proxies for all connections.
112
- *
113
- * ```javascript
114
- * const proxyConfiguration = new ProxyConfiguration({
115
- * proxyUrls: ['http://user:pass@proxy-1.com', 'http://user:pass@proxy-2.com'],
116
- * });
117
- *
118
- * const crawler = new CheerioCrawler({
119
- * // ...
120
- * proxyConfiguration,
121
- * requestHandler({ proxyInfo }) {
122
- * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
123
- * }
124
- * })
125
- *
126
- * ```
127
- */
128
- constructor(options?: ProxyConfigurationOptions);
129
- /**
130
- * This function creates a new {@link ProxyInfo} info object.
131
- * It is used by CheerioCrawler and PuppeteerCrawler to generate proxy URLs and also to allow the user to inspect
132
- * the currently used proxy via the requestHandler parameter `proxyInfo`.
133
- * Use it if you want to work with a rich representation of a proxy URL.
134
- * If you need the URL string only, use {@link ProxyConfiguration.newUrl}.
135
- *
136
- * @return Represents information about used proxy and its configuration.
137
- */
138
- newProxyInfo(options?: TieredProxyOptions): Promise<ProxyInfo | undefined>;
139
- /**
140
- * Given a request / proxy tier, this function returns a new proxy URL based on the provided configuration options.
141
- * @param options Options for the tiered proxy rotation
142
- * @returns An object with the proxy URL and the proxy tier used.
143
- */
144
- protected _handleTieredUrl(options?: TieredProxyOptions): TieredProxy;
145
- /**
146
- * Given a `Request` object, this function returns the tier of the proxy that should be used for the request.
147
- *
148
- * This returns `null` if `tieredProxyUrls` option is not set.
149
- */
150
- protected predictProxyTier(request: Request): number | null;
151
- /**
152
- * Returns a new proxy URL based on provided configuration options.
153
- *
154
- * @return A string with a proxy URL, including authentication credentials and port number.
155
- * For example, `http://bob:password123@proxy.example.com:8000`
156
- */
157
- newUrl(options?: TieredProxyOptions): Promise<string | undefined>;
158
- protected _handleProxyUrlsList(): string | null;
159
- /**
160
- * Calls the custom newUrlFunction and checks format of its return value
161
- */
162
- protected _callNewUrlFunction(options?: {
163
- request?: Request;
164
- }): Promise<string | null>;
165
- protected _throwCannotCombineCustomMethods(): never;
166
- protected _throwNoOptionsProvided(): never;
167
- }
168
- export {};
169
- //# sourceMappingURL=proxy_configuration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxy_configuration.d.ts","sourceRoot":"","sources":["../src/proxy_configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,0BAA0B;IACvC,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC7E;AAED,KAAK,OAAO,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;AAEjC,MAAM,WAAW,yBAAyB;IACtC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,0BAA0B,CAAC;IAE5C;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,kBAAkB;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,cA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IAcnE,SAAS,CAAC,gCAAgC,IAAI,KAAK;IAMnD,SAAS,CAAC,uBAAuB,IAAI,KAAK;CAG7C"}
@@ -1,247 +0,0 @@
1
- import ow from 'ow';
2
- import log from '@apify/log';
3
- /**
4
- * Internal class for tracking the proxy tier history for a specific domain.
5
- *
6
- * Predicts the best proxy tier for the next request based on the error history for different proxy tiers.
7
- */
8
- class ProxyTierTracker {
9
- histogram;
10
- currentTier;
11
- constructor(tieredProxyUrls) {
12
- this.histogram = tieredProxyUrls.map(() => 0);
13
- this.currentTier = 0;
14
- }
15
- /**
16
- * Processes a single step of the algorithm and updates the current tier prediction based on the error history.
17
- */
18
- processStep() {
19
- this.histogram.forEach((x, i) => {
20
- if (this.currentTier === i)
21
- return;
22
- if (x > 0)
23
- this.histogram[i]--;
24
- });
25
- const left = this.currentTier > 0 ? this.histogram[this.currentTier - 1] : Infinity;
26
- const right = this.currentTier < this.histogram.length - 1 ? this.histogram[this.currentTier + 1] : Infinity;
27
- if (this.histogram[this.currentTier] > Math.min(left, right)) {
28
- this.currentTier = left <= right ? this.currentTier - 1 : this.currentTier + 1;
29
- }
30
- else if (this.histogram[this.currentTier] === left) {
31
- this.currentTier--;
32
- }
33
- }
34
- /**
35
- * Increases the error score for the given proxy tier. This raises the chance of picking a different proxy tier for the subsequent requests.
36
- *
37
- * The error score is increased by 10 for the given tier. This means that this tier will be disadvantaged for the next 10 requests (every new request prediction decreases the error score by 1).
38
- * @param tier The proxy tier to mark as problematic.
39
- */
40
- addError(tier) {
41
- this.histogram[tier] += 10;
42
- }
43
- /**
44
- * Returns the best proxy tier for the next request based on the error history for different proxy tiers.
45
- * @returns The proxy tier prediction
46
- */
47
- predictTier() {
48
- this.processStep();
49
- return this.currentTier;
50
- }
51
- }
52
- /**
53
- * Configures connection to a proxy server with the provided options. Proxy servers are used to prevent target websites from blocking
54
- * your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
55
- * them to use the selected proxies for all connections. You can get information about the currently used proxy by inspecting
56
- * the {@link ProxyInfo} property in your crawler's page function. There, you can inspect the proxy's URL and other attributes.
57
- *
58
- * If you want to use your own proxies, use the {@link ProxyConfigurationOptions.proxyUrls} option. Your list of proxy URLs will
59
- * be rotated by the configuration if this option is provided.
60
- *
61
- * **Example usage:**
62
- *
63
- * ```javascript
64
- *
65
- * const proxyConfiguration = new ProxyConfiguration({
66
- * proxyUrls: ['...', '...'],
67
- * });
68
- *
69
- * const crawler = new CheerioCrawler({
70
- * // ...
71
- * proxyConfiguration,
72
- * requestHandler({ proxyInfo }) {
73
- * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
74
- * }
75
- * })
76
- *
77
- * ```
78
- * @category Scaling
79
- */
80
- export class ProxyConfiguration {
81
- isManInTheMiddle = false;
82
- nextCustomUrlIndex = 0;
83
- proxyUrls;
84
- tieredProxyUrls;
85
- usedProxyUrls = new Map();
86
- newUrlFunction;
87
- log = log.child({ prefix: 'ProxyConfiguration' });
88
- domainTiers = new Map();
89
- /**
90
- * Creates a {@link ProxyConfiguration} instance based on the provided options. Proxy servers are used to prevent target websites from
91
- * blocking your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
92
- * them to use the selected proxies for all connections.
93
- *
94
- * ```javascript
95
- * const proxyConfiguration = new ProxyConfiguration({
96
- * proxyUrls: ['http://user:pass@proxy-1.com', 'http://user:pass@proxy-2.com'],
97
- * });
98
- *
99
- * const crawler = new CheerioCrawler({
100
- * // ...
101
- * proxyConfiguration,
102
- * requestHandler({ proxyInfo }) {
103
- * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
104
- * }
105
- * })
106
- *
107
- * ```
108
- */
109
- constructor(options = {}) {
110
- const { validateRequired, ...rest } = options;
111
- ow(rest, ow.object.exactShape({
112
- proxyUrls: ow.optional.array.nonEmpty.ofType(ow.any(ow.string.url, ow.null)),
113
- newUrlFunction: ow.optional.function,
114
- tieredProxyUrls: ow.optional.array.nonEmpty.ofType(ow.array.nonEmpty.ofType(ow.any(ow.string.url, ow.null))),
115
- }));
116
- const { proxyUrls, newUrlFunction, tieredProxyUrls } = options;
117
- if ([proxyUrls, newUrlFunction, tieredProxyUrls].filter((x) => x).length > 1)
118
- this._throwCannotCombineCustomMethods();
119
- if (!proxyUrls && !newUrlFunction && validateRequired)
120
- this._throwNoOptionsProvided();
121
- this.proxyUrls = proxyUrls;
122
- this.newUrlFunction = newUrlFunction;
123
- this.tieredProxyUrls = tieredProxyUrls;
124
- }
125
- /**
126
- * This function creates a new {@link ProxyInfo} info object.
127
- * It is used by CheerioCrawler and PuppeteerCrawler to generate proxy URLs and also to allow the user to inspect
128
- * the currently used proxy via the requestHandler parameter `proxyInfo`.
129
- * Use it if you want to work with a rich representation of a proxy URL.
130
- * If you need the URL string only, use {@link ProxyConfiguration.newUrl}.
131
- *
132
- * @return Represents information about used proxy and its configuration.
133
- */
134
- async newProxyInfo(options) {
135
- let url;
136
- let tier;
137
- if (this.tieredProxyUrls) {
138
- const { proxyUrl, proxyTier } = this._handleTieredUrl(options);
139
- url = proxyUrl ?? undefined;
140
- tier = proxyTier;
141
- }
142
- else {
143
- url = await this.newUrl(options);
144
- }
145
- if (!url)
146
- return undefined;
147
- const { username, password, port, hostname } = new URL(url);
148
- return {
149
- url,
150
- username: decodeURIComponent(username),
151
- password: decodeURIComponent(password),
152
- hostname,
153
- port: port,
154
- proxyTier: tier,
155
- };
156
- }
157
- /**
158
- * Given a request / proxy tier, this function returns a new proxy URL based on the provided configuration options.
159
- * @param options Options for the tiered proxy rotation
160
- * @returns An object with the proxy URL and the proxy tier used.
161
- */
162
- _handleTieredUrl(options) {
163
- if (!this.tieredProxyUrls)
164
- throw new Error('Tiered proxy URLs are not set');
165
- if (!options || (!options?.request && options?.proxyTier === undefined)) {
166
- const allProxyUrls = this.tieredProxyUrls.flat();
167
- return {
168
- proxyUrl: allProxyUrls[this.nextCustomUrlIndex++ % allProxyUrls.length],
169
- };
170
- }
171
- let tierPrediction = options.proxyTier;
172
- if (typeof tierPrediction !== 'number') {
173
- tierPrediction = this.predictProxyTier(options.request);
174
- }
175
- const proxyTier = this.tieredProxyUrls[tierPrediction];
176
- return {
177
- proxyUrl: proxyTier[this.nextCustomUrlIndex++ % proxyTier.length],
178
- proxyTier: tierPrediction,
179
- };
180
- }
181
- /**
182
- * Given a `Request` object, this function returns the tier of the proxy that should be used for the request.
183
- *
184
- * This returns `null` if `tieredProxyUrls` option is not set.
185
- */
186
- predictProxyTier(request) {
187
- if (!this.tieredProxyUrls)
188
- return null;
189
- const domain = new URL(request.url).hostname;
190
- if (!this.domainTiers.has(domain)) {
191
- this.domainTiers.set(domain, new ProxyTierTracker(this.tieredProxyUrls));
192
- }
193
- request.userData.__crawlee ??= {};
194
- const tracker = this.domainTiers.get(domain);
195
- if (typeof request.userData.__crawlee.lastProxyTier === 'number') {
196
- tracker.addError(request.userData.__crawlee.lastProxyTier);
197
- }
198
- const tierPrediction = tracker.predictTier();
199
- if (typeof request.userData.__crawlee.lastProxyTier === 'number' &&
200
- request.userData.__crawlee.lastProxyTier !== tierPrediction) {
201
- log.debug(`Changing proxy tier for domain "${domain}" from ${request.userData.__crawlee.lastProxyTier} to ${tierPrediction}.`);
202
- }
203
- request.userData.__crawlee.lastProxyTier = tierPrediction;
204
- request.userData.__crawlee.forefront = true;
205
- return tierPrediction;
206
- }
207
- /**
208
- * Returns a new proxy URL based on provided configuration options.
209
- *
210
- * @return A string with a proxy URL, including authentication credentials and port number.
211
- * For example, `http://bob:password123@proxy.example.com:8000`
212
- */
213
- async newUrl(options) {
214
- if (this.newUrlFunction) {
215
- return (await this._callNewUrlFunction({ request: options?.request })) ?? undefined;
216
- }
217
- if (this.tieredProxyUrls) {
218
- return this._handleTieredUrl(options).proxyUrl ?? undefined;
219
- }
220
- return this._handleProxyUrlsList() ?? undefined;
221
- }
222
- _handleProxyUrlsList() {
223
- return this.proxyUrls[this.nextCustomUrlIndex++ % this.proxyUrls.length];
224
- }
225
- /**
226
- * Calls the custom newUrlFunction and checks format of its return value
227
- */
228
- async _callNewUrlFunction(options) {
229
- const proxyUrl = await this.newUrlFunction(options);
230
- try {
231
- if (proxyUrl) {
232
- new URL(proxyUrl); // eslint-disable-line no-new
233
- }
234
- return proxyUrl;
235
- }
236
- catch (err) {
237
- throw new Error(`The provided newUrlFunction did not return a valid URL.\nCause: ${err.message}`);
238
- }
239
- }
240
- _throwCannotCombineCustomMethods() {
241
- throw new Error('Cannot combine custom proxies "options.proxyUrls" with custom generating function "options.newUrlFunction".');
242
- }
243
- _throwNoOptionsProvided() {
244
- throw new Error('One of "options.proxyUrls" or "options.newUrlFunction" needs to be provided.');
245
- }
246
- }
247
- //# sourceMappingURL=proxy_configuration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxy_configuration.js","sourceRoot":"","sources":["../src/proxy_configuration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,GAAG,MAAM,YAAY,CAAC;AAkD7B;;;;GAIG;AACH,MAAM,gBAAgB;IACV,SAAS,CAAW;IACpB,WAAW,CAAS;IAE5B,YAAY,eAAoC;QAC5C,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,WAAW;QACf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5B,IAAI,IAAI,CAAC,WAAW,KAAK,CAAC;gBAAE,OAAO;YACnC,IAAI,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC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