@crawlee/core 4.0.0-beta.22 → 4.0.0-beta.221

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 (270) 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 +77 -235
  5. package/configuration.js +162 -226
  6. package/debug.d.ts +36 -0
  7. package/debug.js +70 -0
  8. package/errors.d.ts +45 -18
  9. package/errors.js +58 -27
  10. package/events/event_manager.d.ts +35 -9
  11. package/events/event_manager.js +12 -13
  12. package/events/index.d.ts +1 -1
  13. package/events/index.js +0 -1
  14. package/events/local_event_manager.d.ts +14 -9
  15. package/events/local_event_manager.js +45 -19
  16. package/events/system_info.d.ts +38 -0
  17. package/events/system_info.js +1 -0
  18. package/index.d.ts +7 -11
  19. package/index.js +8 -10
  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 +105 -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 +20 -21
  45. package/proxy_configuration.d.ts +28 -79
  46. package/proxy_configuration.js +40 -146
  47. package/recoverable_state.d.ts +106 -52
  48. package/recoverable_state.js +200 -72
  49. package/request.d.ts +48 -93
  50. package/request.js +112 -230
  51. package/serialization.d.ts +0 -1
  52. package/serialization.js +18 -18
  53. package/service_locator.d.ts +168 -0
  54. package/service_locator.js +255 -0
  55. package/storages/batched_adds.d.ts +37 -0
  56. package/storages/batched_adds.js +73 -0
  57. package/storages/dataset.d.ts +105 -58
  58. package/storages/dataset.js +291 -149
  59. package/storages/index.d.ts +8 -9
  60. package/storages/index.js +4 -9
  61. package/storages/key_value_store.d.ts +169 -72
  62. package/storages/key_value_store.js +451 -196
  63. package/storages/key_value_store_codec.d.ts +32 -0
  64. package/storages/key_value_store_codec.js +108 -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 +33 -173
  68. package/storages/request_list.js +275 -254
  69. package/storages/request_loader.d.ts +127 -0
  70. package/storages/request_loader.js +36 -0
  71. package/storages/request_manager.d.ts +119 -0
  72. package/storages/request_manager.js +1 -0
  73. package/storages/request_manager_tandem.d.ts +39 -25
  74. package/storages/request_manager_tandem.js +134 -58
  75. package/storages/request_queue.d.ts +261 -48
  76. package/storages/request_queue.js +766 -216
  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 +75 -15
  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 -300
  100. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  101. package/autoscaling/autoscaled_pool.js +0 -533
  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 -189
  108. package/autoscaling/snapshotter.d.ts.map +0 -1
  109. package/autoscaling/snapshotter.js +0 -285
  110. package/autoscaling/snapshotter.js.map +0 -1
  111. package/autoscaling/system_status.d.ts +0 -181
  112. package/autoscaling/system_status.d.ts.map +0 -1
  113. package/autoscaling/system_status.js +0 -169
  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 -194
  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 -213
  150. package/crawlers/statistics.d.ts.map +0 -1
  151. package/crawlers/statistics.js +0 -349
  152. package/crawlers/statistics.js.map +0 -1
  153. package/enqueue_links/enqueue_links.d.ts +0 -249
  154. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  155. package/enqueue_links/enqueue_links.js +0 -269
  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 -73
  162. package/enqueue_links/shared.d.ts.map +0 -1
  163. package/enqueue_links/shared.js +0 -212
  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.map +0 -1
  173. package/http_clients/base-http-client.d.ts +0 -12
  174. package/http_clients/base-http-client.d.ts.map +0 -1
  175. package/http_clients/base-http-client.js +0 -44
  176. package/http_clients/base-http-client.js.map +0 -1
  177. package/http_clients/form-data-like.d.ts +0 -67
  178. package/http_clients/form-data-like.d.ts.map +0 -1
  179. package/http_clients/form-data-like.js +0 -5
  180. package/http_clients/form-data-like.js.map +0 -1
  181. package/http_clients/got-scraping-http-client.d.ts +0 -22
  182. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  183. package/http_clients/got-scraping-http-client.js +0 -113
  184. package/http_clients/got-scraping-http-client.js.map +0 -1
  185. package/http_clients/index.d.ts +0 -3
  186. package/http_clients/index.d.ts.map +0 -1
  187. package/http_clients/index.js +0 -3
  188. package/http_clients/index.js.map +0 -1
  189. package/index.d.ts.map +0 -1
  190. package/index.js.map +0 -1
  191. package/log.d.ts.map +0 -1
  192. package/log.js.map +0 -1
  193. package/proxy_configuration.d.ts.map +0 -1
  194. package/proxy_configuration.js.map +0 -1
  195. package/recoverable_state.d.ts.map +0 -1
  196. package/recoverable_state.js.map +0 -1
  197. package/request.d.ts.map +0 -1
  198. package/request.js.map +0 -1
  199. package/router.d.ts +0 -134
  200. package/router.d.ts.map +0 -1
  201. package/router.js +0 -164
  202. package/router.js.map +0 -1
  203. package/serialization.d.ts.map +0 -1
  204. package/serialization.js.map +0 -1
  205. package/session_pool/consts.d.ts +0 -4
  206. package/session_pool/consts.d.ts.map +0 -1
  207. package/session_pool/consts.js +0 -4
  208. package/session_pool/consts.js.map +0 -1
  209. package/session_pool/errors.d.ts +0 -8
  210. package/session_pool/errors.d.ts.map +0 -1
  211. package/session_pool/errors.js +0 -12
  212. package/session_pool/errors.js.map +0 -1
  213. package/session_pool/events.d.ts +0 -3
  214. package/session_pool/events.d.ts.map +0 -1
  215. package/session_pool/events.js +0 -3
  216. package/session_pool/events.js.map +0 -1
  217. package/session_pool/index.d.ts +0 -6
  218. package/session_pool/index.d.ts.map +0 -1
  219. package/session_pool/index.js +0 -6
  220. package/session_pool/index.js.map +0 -1
  221. package/session_pool/session.d.ts +0 -186
  222. package/session_pool/session.d.ts.map +0 -1
  223. package/session_pool/session.js +0 -278
  224. package/session_pool/session.js.map +0 -1
  225. package/session_pool/session_pool.d.ts +0 -258
  226. package/session_pool/session_pool.d.ts.map +0 -1
  227. package/session_pool/session_pool.js +0 -387
  228. package/session_pool/session_pool.js.map +0 -1
  229. package/storages/access_checking.d.ts +0 -13
  230. package/storages/access_checking.d.ts.map +0 -1
  231. package/storages/access_checking.js +0 -14
  232. package/storages/access_checking.js.map +0 -1
  233. package/storages/dataset.d.ts.map +0 -1
  234. package/storages/dataset.js.map +0 -1
  235. package/storages/index.d.ts.map +0 -1
  236. package/storages/index.js.map +0 -1
  237. package/storages/key_value_store.d.ts.map +0 -1
  238. package/storages/key_value_store.js.map +0 -1
  239. package/storages/request_list.d.ts.map +0 -1
  240. package/storages/request_list.js.map +0 -1
  241. package/storages/request_list_adapter.d.ts +0 -58
  242. package/storages/request_list_adapter.d.ts.map +0 -1
  243. package/storages/request_list_adapter.js +0 -81
  244. package/storages/request_list_adapter.js.map +0 -1
  245. package/storages/request_manager_tandem.d.ts.map +0 -1
  246. package/storages/request_manager_tandem.js.map +0 -1
  247. package/storages/request_provider.d.ts +0 -372
  248. package/storages/request_provider.d.ts.map +0 -1
  249. package/storages/request_provider.js +0 -591
  250. package/storages/request_provider.js.map +0 -1
  251. package/storages/request_queue.d.ts.map +0 -1
  252. package/storages/request_queue.js.map +0 -1
  253. package/storages/request_queue_v2.d.ts +0 -87
  254. package/storages/request_queue_v2.d.ts.map +0 -1
  255. package/storages/request_queue_v2.js +0 -438
  256. package/storages/request_queue_v2.js.map +0 -1
  257. package/storages/sitemap_request_list.d.ts +0 -250
  258. package/storages/sitemap_request_list.d.ts.map +0 -1
  259. package/storages/sitemap_request_list.js +0 -431
  260. package/storages/sitemap_request_list.js.map +0 -1
  261. package/storages/storage_manager.d.ts +0 -62
  262. package/storages/storage_manager.d.ts.map +0 -1
  263. package/storages/storage_manager.js +0 -105
  264. package/storages/storage_manager.js.map +0 -1
  265. package/storages/utils.d.ts.map +0 -1
  266. package/storages/utils.js.map +0 -1
  267. package/typedefs.d.ts.map +0 -1
  268. package/typedefs.js.map +0 -1
  269. package/validators.d.ts.map +0 -1
  270. package/validators.js.map +0 -1
@@ -1,278 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import ow from 'ow';
3
- import { CookieJar } from 'tough-cookie';
4
- import { cryptoRandomObjectId } from '@apify/utilities';
5
- import { browserPoolCookieToToughCookie, getCookiesFromResponse, getDefaultCookieExpirationDate, toughCookieToBrowserPoolCookie, } from '../cookie_utils.js';
6
- import { log as defaultLog } from '../log.js';
7
- import { EVENT_SESSION_RETIRED } from './events.js';
8
- /**
9
- * Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
10
- * You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint.
11
- * Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.
12
- * @category Scaling
13
- */
14
- export class Session {
15
- id;
16
- maxAgeSecs;
17
- userData;
18
- _maxErrorScore;
19
- _errorScoreDecrement;
20
- _createdAt;
21
- _expiresAt;
22
- _usageCount;
23
- _maxUsageCount;
24
- sessionPool;
25
- _errorScore;
26
- _proxyInfo;
27
- _cookieJar;
28
- log;
29
- get errorScore() {
30
- return this._errorScore;
31
- }
32
- get usageCount() {
33
- return this._usageCount;
34
- }
35
- get maxErrorScore() {
36
- return this._maxErrorScore;
37
- }
38
- get errorScoreDecrement() {
39
- return this._errorScoreDecrement;
40
- }
41
- get expiresAt() {
42
- return this._expiresAt;
43
- }
44
- get createdAt() {
45
- return this._createdAt;
46
- }
47
- get maxUsageCount() {
48
- return this._maxUsageCount;
49
- }
50
- get cookieJar() {
51
- return this._cookieJar;
52
- }
53
- get proxyInfo() {
54
- return this._proxyInfo;
55
- }
56
- /**
57
- * Session configuration.
58
- */
59
- constructor(options) {
60
- ow(options, ow.object.exactShape({
61
- sessionPool: ow.object.instanceOf(EventEmitter),
62
- id: ow.optional.string,
63
- cookieJar: ow.optional.object,
64
- proxyInfo: ow.optional.object,
65
- maxAgeSecs: ow.optional.number,
66
- userData: ow.optional.object,
67
- maxErrorScore: ow.optional.number,
68
- errorScoreDecrement: ow.optional.number,
69
- createdAt: ow.optional.date,
70
- expiresAt: ow.optional.date,
71
- usageCount: ow.optional.number,
72
- errorScore: ow.optional.number,
73
- maxUsageCount: ow.optional.number,
74
- log: ow.optional.object,
75
- }));
76
- const { sessionPool, id = `session_${cryptoRandomObjectId(10)}`, cookieJar = new CookieJar(), proxyInfo = undefined, maxAgeSecs = 3000, userData = {}, maxErrorScore = 3, errorScoreDecrement = 0.5, createdAt = new Date(), usageCount = 0, errorScore = 0, maxUsageCount = 50, log = defaultLog, } = options;
77
- const { expiresAt = getDefaultCookieExpirationDate(maxAgeSecs) } = options;
78
- this.log = log.child({ prefix: 'Session' });
79
- this._cookieJar = cookieJar.setCookie ? cookieJar : CookieJar.fromJSON(JSON.stringify(cookieJar));
80
- this._proxyInfo = proxyInfo;
81
- this.id = id;
82
- this.maxAgeSecs = maxAgeSecs;
83
- this.userData = userData;
84
- this._maxErrorScore = maxErrorScore;
85
- this._errorScoreDecrement = errorScoreDecrement;
86
- // Internal
87
- this._expiresAt = expiresAt;
88
- this._createdAt = createdAt;
89
- this._usageCount = usageCount; // indicates how many times the session has been used
90
- this._errorScore = errorScore; // indicates number of markBaded request with the session
91
- this._maxUsageCount = maxUsageCount;
92
- this.sessionPool = sessionPool;
93
- }
94
- /**
95
- * Indicates whether the session is blocked.
96
- * Session is blocked once it reaches the `maxErrorScore`.
97
- */
98
- isBlocked() {
99
- return this.errorScore >= this.maxErrorScore;
100
- }
101
- /**
102
- * Indicates whether the session is expired.
103
- * Session expiration is determined by the `maxAgeSecs`.
104
- * Once the session is older than `createdAt + maxAgeSecs` the session is considered expired.
105
- */
106
- isExpired() {
107
- return this.expiresAt <= new Date();
108
- }
109
- /**
110
- * Indicates whether the session is used maximum number of times.
111
- * Session maximum usage count can be changed by `maxUsageCount` parameter.
112
- */
113
- isMaxUsageCountReached() {
114
- return this.usageCount >= this.maxUsageCount;
115
- }
116
- /**
117
- * Indicates whether the session can be used for next requests.
118
- * Session is usable when it is not expired, not blocked and the maximum usage count has not be reached.
119
- */
120
- isUsable() {
121
- return !this.isBlocked() && !this.isExpired() && !this.isMaxUsageCountReached();
122
- }
123
- /**
124
- * This method should be called after a successful session usage.
125
- * It increases `usageCount` and potentially lowers the `errorScore` by the `errorScoreDecrement`.
126
- */
127
- markGood() {
128
- this._usageCount += 1;
129
- if (this._errorScore > 0) {
130
- this._errorScore -= this._errorScoreDecrement;
131
- }
132
- this._maybeSelfRetire();
133
- }
134
- /**
135
- * Gets session state for persistence in KeyValueStore.
136
- * @returns Represents session internal state.
137
- */
138
- getState() {
139
- return {
140
- id: this.id,
141
- cookieJar: this.cookieJar.toJSON(),
142
- proxyInfo: this._proxyInfo,
143
- userData: this.userData,
144
- maxErrorScore: this.maxErrorScore,
145
- errorScoreDecrement: this.errorScoreDecrement,
146
- expiresAt: this.expiresAt.toISOString(),
147
- createdAt: this.createdAt.toISOString(),
148
- usageCount: this.usageCount,
149
- maxUsageCount: this.maxUsageCount,
150
- errorScore: this.errorScore,
151
- };
152
- }
153
- /**
154
- * Marks session as blocked and emits event on the `SessionPool`
155
- * This method should be used if the session usage was unsuccessful
156
- * and you are sure that it is because of the session configuration and not any external matters.
157
- * For example when server returns 403 status code.
158
- * If the session does not work due to some external factors as server error such as 5XX you probably want to use `markBad` method.
159
- */
160
- retire() {
161
- // mark it as an invalid by increasing the error score count.
162
- this._errorScore += this._maxErrorScore;
163
- this._usageCount += 1;
164
- // emit event so we can retire browser in puppeteer pool
165
- this.sessionPool.emit(EVENT_SESSION_RETIRED, this);
166
- }
167
- /**
168
- * Increases usage and error count.
169
- * Should be used when the session has been used unsuccessfully. For example because of timeouts.
170
- */
171
- markBad() {
172
- this._errorScore += 1;
173
- this._usageCount += 1;
174
- this._maybeSelfRetire();
175
- }
176
- /**
177
- * With certain status codes: `401`, `403` or `429` we can be certain
178
- * that the target website is blocking us. This function helps to do this conveniently
179
- * by retiring the session when such code is received. Optionally, the default status
180
- * codes can be extended in the second parameter.
181
- * @param statusCode HTTP status code.
182
- * @returns Whether the session was retired.
183
- */
184
- retireOnBlockedStatusCodes(statusCode) {
185
- // eslint-disable-next-line dot-notation -- accessing private property
186
- const isBlocked = this.sessionPool['blockedStatusCodes'].includes(statusCode);
187
- if (isBlocked) {
188
- this.retire();
189
- }
190
- return isBlocked;
191
- }
192
- /**
193
- * Saves cookies from an HTTP response to be used with the session.
194
- * It expects an object with a `headers` property that's either an `Object`
195
- * (typical Node.js responses) or a `Function` (Puppeteer Response).
196
- *
197
- * It then parses and saves the cookies from the `set-cookie` header, if available.
198
- */
199
- setCookiesFromResponse(response) {
200
- try {
201
- const cookies = getCookiesFromResponse(response).filter((c) => c);
202
- this._setCookies(cookies, response.url);
203
- }
204
- catch (e) {
205
- const err = e;
206
- // if invalid Cookie header is provided just log the exception.
207
- this.log.exception(err, 'Could not get cookies from response');
208
- }
209
- }
210
- /**
211
- * Saves an array with cookie objects to be used with the session.
212
- * The objects should be in the format that
213
- * [Puppeteer uses](https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-pagecookiesurls),
214
- * but you can also use this function to set cookies manually:
215
- *
216
- * ```
217
- * [
218
- * { name: 'cookie1', value: 'my-cookie' },
219
- * { name: 'cookie2', value: 'your-cookie' }
220
- * ]
221
- * ```
222
- */
223
- setCookies(cookies, url) {
224
- const normalizedCookies = cookies.map((c) => browserPoolCookieToToughCookie(c, this.maxAgeSecs));
225
- this._setCookies(normalizedCookies, url);
226
- }
227
- /**
228
- * Returns cookies in a format compatible with puppeteer/playwright and ready to be used with `page.setCookie`.
229
- * @param url website url. Only cookies stored for this url will be returned
230
- */
231
- getCookies(url) {
232
- const cookies = this.cookieJar.getCookiesSync(url);
233
- return cookies.map((c) => toughCookieToBrowserPoolCookie(c));
234
- }
235
- /**
236
- * Returns cookies saved with the session in the typical
237
- * key1=value1; key2=value2 format, ready to be used in
238
- * a cookie header or elsewhere.
239
- * @returns Represents `Cookie` header.
240
- */
241
- getCookieString(url) {
242
- return this.cookieJar.getCookieStringSync(url, {});
243
- }
244
- /**
245
- * Sets a cookie within this session for the specific URL.
246
- */
247
- setCookie(rawCookie, url) {
248
- this.cookieJar.setCookieSync(rawCookie, url);
249
- }
250
- /**
251
- * Sets cookies.
252
- */
253
- _setCookies(cookies, url) {
254
- const errorMessages = [];
255
- for (const cookie of cookies) {
256
- try {
257
- this.cookieJar.setCookieSync(cookie, url, { ignoreError: false });
258
- }
259
- catch (e) {
260
- const err = e;
261
- errorMessages.push(err.message);
262
- }
263
- }
264
- // if invalid cookies are provided just log the exception. No need to retry the request automatically.
265
- if (errorMessages.length) {
266
- this.log.debug('Could not set cookies.', { errorMessages });
267
- }
268
- }
269
- /**
270
- * Checks if session is not usable. if it is not retires the session.
271
- */
272
- _maybeSelfRetire() {
273
- if (!this.isUsable()) {
274
- this.retire();
275
- }
276
- }
277
- }
278
- //# sourceMappingURL=session.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session_pool/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EACH,8BAA8B,EAC9B,sBAAsB,EACtB,8BAA8B,EAC9B,8BAA8B,GACjC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AA4DpD;;;;;GAKG;AACH,MAAM,OAAO,OAAO;IACP,EAAE,CAAS;IACZ,UAAU,CAAS;IAC3B,QAAQ,CAAa;IACb,cAAc,CAAS;IACvB,oB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3B,IAAI,CAAC;gBACD,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;YACtE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,MAAM,GAAG,GAAG,CAAU,CAAC;gBACvB,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;QACL,CAAC;QAED,sGAAsG;QACtG,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;YACvB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC;QAChE,CAAC;IACL,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC;IACL,CAAC;CACJ"}
@@ -1,258 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import type { Log } from '@apify/log';
3
- import { Configuration } from '../configuration.js';
4
- import type { PersistenceOptions } from '../crawlers/statistics.js';
5
- import type { EventManager } from '../events/event_manager.js';
6
- import { KeyValueStore } from '../storages/key_value_store.js';
7
- import type { SessionOptions } from './session.js';
8
- import { Session } from './session.js';
9
- /**
10
- * Factory user-function which creates customized {@link Session} instances.
11
- */
12
- export interface CreateSession {
13
- /**
14
- * @param sessionPool Pool requesting the new session.
15
- * @param options
16
- */
17
- (sessionPool: SessionPool, options?: {
18
- sessionOptions?: SessionOptions;
19
- }): Session | Promise<Session>;
20
- }
21
- export interface SessionPoolOptions {
22
- /**
23
- * Maximum size of the pool. Indicates how many sessions are rotated.
24
- * @default 1000
25
- */
26
- maxPoolSize?: number;
27
- /** The configuration options for {@link Session} instances. */
28
- sessionOptions?: SessionOptions;
29
- /** Name or Id of `KeyValueStore` where is the `SessionPool` state stored. */
30
- persistStateKeyValueStoreId?: string;
31
- /**
32
- * Session pool persists it's state under this key in Key value store.
33
- * @default SESSION_POOL_STATE
34
- */
35
- persistStateKey?: string;
36
- /**
37
- * Custom function that should return a `Session` instance, or a promise resolving to such instance.
38
- * Any error thrown from this function will terminate the process.
39
- * Function receives `SessionPool` instance as a parameter
40
- */
41
- createSessionFunction?: CreateSession;
42
- /**
43
- * Specifies which response status codes are considered as blocked.
44
- * Session connected to such request will be marked as retired.
45
- * @default [401, 403, 429]
46
- */
47
- blockedStatusCodes?: number[];
48
- /** @internal */
49
- log?: Log;
50
- /**
51
- * Control how and when to persist the state of the session pool.
52
- */
53
- persistenceOptions?: PersistenceOptions;
54
- }
55
- /**
56
- * Handles the rotation, creation and persistence of user-like sessions.
57
- * Creates a pool of {@link Session} instances, that are randomly rotated.
58
- * When some session is marked as blocked, it is removed and new one is created instead (the pool never returns an unusable session).
59
- * Learn more in the {@doclink guides/session-management | Session management guide}.
60
- *
61
- * You can create one by calling the {@link SessionPool.open} function.
62
- *
63
- * Session pool is already integrated into crawlers, and it can significantly improve your scraper
64
- * performance with just 2 lines of code.
65
- *
66
- * **Example usage:**
67
- *
68
- * ```javascript
69
- * const crawler = new CheerioCrawler({
70
- * useSessionPool: true,
71
- * persistCookiesPerSession: true,
72
- * // ...
73
- * })
74
- * ```
75
- *
76
- * You can configure the pool with many options. See the {@link SessionPoolOptions}.
77
- * Session pool is by default persisted in default {@link KeyValueStore}.
78
- * If you want to have one pool for all runs you have to specify
79
- * {@link SessionPoolOptions.persistStateKeyValueStoreId}.
80
- *
81
- * **Advanced usage:**
82
- *
83
- * ```javascript
84
- * const sessionPool = await SessionPool.open({
85
- * maxPoolSize: 25,
86
- * sessionOptions:{
87
- * maxAgeSecs: 10,
88
- * maxUsageCount: 150, // for example when you know that the site blocks after 150 requests.
89
- * },
90
- * persistStateKeyValueStoreId: 'my-key-value-store-for-sessions',
91
- * persistStateKey: 'my-session-pool',
92
- * });
93
- *
94
- * // Get random session from the pool
95
- * const session1 = await sessionPool.getSession();
96
- * const session2 = await sessionPool.getSession();
97
- * const session3 = await sessionPool.getSession();
98
- *
99
- * // Now you can mark the session either failed or successful
100
- *
101
- * // Marks session as bad after unsuccessful usage -> it increases error count (soft retire)
102
- * session1.markBad()
103
- *
104
- * // Marks as successful.
105
- * session2.markGood()
106
- *
107
- * // Retires session -> session is removed from the pool
108
- * session3.retire()
109
- *
110
- * ```
111
- *
112
- * **Default session allocation flow:*
113
- * 1. Until the `SessionPool` reaches `maxPoolSize`, new sessions are created, provided to the user and added to the pool
114
- * 2. Blocked/retired sessions stay in the pool but are never provided to the user
115
- * 3. Once the pool is full (live plus blocked session count reaches `maxPoolSize`), a random session from the pool is provided.
116
- * 4. If a blocked session would be picked, instead all blocked sessions are evicted from the pool and a new session is created and provided
117
- *
118
- * @category Scaling
119
- */
120
- export declare class SessionPool extends EventEmitter {
121
- readonly config: Configuration;
122
- protected log: Log;
123
- protected maxPoolSize: number;
124
- protected createSessionFunction: CreateSession;
125
- protected keyValueStore: KeyValueStore;
126
- protected sessions: Session[];
127
- protected sessionMap: Map<string, Session>;
128
- protected sessionOptions: SessionOptions;
129
- protected persistStateKeyValueStoreId?: string;
130
- protected persistStateKey: string;
131
- protected _listener: () => Promise<void>;
132
- protected events: EventManager;
133
- protected readonly blockedStatusCodes: number[];
134
- protected persistenceOptions: PersistenceOptions;
135
- protected isInitialized: boolean;
136
- private queue;
137
- /**
138
- * @internal
139
- */
140
- constructor(options?: SessionPoolOptions, config?: Configuration);
141
- /**
142
- * Gets count of usable sessions in the pool.
143
- */
144
- get usableSessionsCount(): number;
145
- /**
146
- * Gets count of retired sessions in the pool.
147
- */
148
- get retiredSessionsCount(): number;
149
- /**
150
- * Starts periodic state persistence and potentially loads SessionPool state from {@link KeyValueStore}.
151
- * It is called automatically by the {@link SessionPool.open} function.
152
- */
153
- initialize(): Promise<void>;
154
- /**
155
- * Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
156
- * but this allows you to add more sessions once the max pool size is reached.
157
- * This also allows you to add session with overridden session options (e.g. with specific session id).
158
- * @param [options] The configuration options for the session being added to the session pool.
159
- */
160
- addSession(options?: Session | SessionOptions): Promise<void>;
161
- /**
162
- * Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
163
- * but this allows you to add more sessions once the max pool size is reached.
164
- * This also allows you to add session with overridden session options (e.g. with specific session id).
165
- * @param [options] The configuration options for the session being added to the session pool.
166
- */
167
- newSession(sessionOptions?: SessionOptions): Promise<Session>;
168
- /**
169
- * Gets session.
170
- * If there is space for new session, it creates and returns new session.
171
- * If the session pool is full, it picks a session from the pool,
172
- * If the picked session is usable it is returned, otherwise it creates and returns a new one.
173
- */
174
- getSession(): Promise<Session>;
175
- /**
176
- * Gets session based on the provided session id or `undefined.
177
- */
178
- getSession(sessionId: string): Promise<Session>;
179
- /**
180
- * @param options - Override the persistence options provided in the constructor
181
- */
182
- resetStore(options?: PersistenceOptions): Promise<void>;
183
- /**
184
- * Returns an object representing the internal state of the `SessionPool` instance.
185
- * Note that the object's fields can change in future releases.
186
- */
187
- getState(): {
188
- usableSessionsCount: number;
189
- retiredSessionsCount: number;
190
- // @ts-ignore optional peer dependency or compatibility with es2022
191
- sessions: import("@crawlee/types").SessionState[];
192
- };
193
- /**
194
- * Persists the current state of the `SessionPool` into the default {@link KeyValueStore}.
195
- * The state is persisted automatically in regular intervals.
196
- * @param options - Override the persistence options provided in the constructor
197
- */
198
- persistState(options?: PersistenceOptions): Promise<void>;
199
- /**
200
- * Removes listener from `persistState` event.
201
- * This function should be called after you are done with using the `SessionPool` instance.
202
- */
203
- teardown(): Promise<void>;
204
- /**
205
- * SessionPool should not work before initialization.
206
- */
207
- protected _throwIfNotInitialized(): void;
208
- /**
209
- * Removes retired `Session` instances from `SessionPool`.
210
- */
211
- protected _removeRetiredSessions(): void;
212
- /**
213
- * Adds `Session` instance to `SessionPool`.
214
- * @param newSession `Session` instance to be added.
215
- */
216
- protected _addSession(newSession: Session): void;
217
- /**
218
- * Gets random index.
219
- */
220
- protected _getRandomIndex(): number;
221
- /**
222
- * Creates new session without any extra behavior.
223
- * @param sessionPool
224
- * @param [options]
225
- * @param [options.sessionOptions] The configuration options for the session being created.
226
- * @returns New session.
227
- */
228
- protected _defaultCreateSessionFunction(sessionPool: SessionPool, options?: {
229
- sessionOptions?: SessionOptions;
230
- }): Promise<Session>;
231
- /**
232
- * Creates new session and adds it to the pool.
233
- * @returns Newly created `Session` instance.
234
- */
235
- protected _createSession(): Promise<Session>;
236
- /**
237
- * Decides whether there is enough space for creating new session.
238
- */
239
- protected _hasSpaceForSession(): boolean;
240
- /**
241
- * Picks random session from the `SessionPool`.
242
- * @returns Picked `Session`.
243
- */
244
- protected _pickSession(): Session;
245
- /**
246
- * Potentially loads `SessionPool`.
247
- * If the state was persisted it loads the `SessionPool` from the persisted state.
248
- */
249
- protected _maybeLoadSessionPool(): Promise<void>;
250
- /**
251
- * Opens a SessionPool and returns a promise resolving to an instance
252
- * of the {@link SessionPool} class that is already initialized.
253
- *
254
- * For more details and code examples, see the {@link SessionPool} class.
255
- */
256
- static open(options?: SessionPoolOptions, config?: Configuration): Promise<SessionPool>;
257
- }
258
- //# sourceMappingURL=session_pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session_pool.d.ts","sourceRoot":"","sources":["../../src/session_pool/session_pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EA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