@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.
- package/README.md +15 -15
- package/byte-utils.d.ts +17 -0
- package/byte-utils.js +42 -0
- package/configuration.d.ts +75 -167
- package/configuration.js +164 -140
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +40 -19
- package/errors.js +52 -30
- package/events/{event_manager.d.ts → event-manager.d.ts} +29 -6
- package/events/{event_manager.js → event-manager.js} +10 -9
- package/events/index.d.ts +3 -3
- package/events/index.js +2 -3
- package/events/{local_event_manager.d.ts → local-event-manager.d.ts} +3 -10
- package/events/local-event-manager.js +101 -0
- package/events/system-info.d.ts +38 -0
- package/events/system-info.js +1 -0
- package/index.d.ts +9 -13
- package/index.js +10 -12
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +134 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +43 -0
- package/memory-storage/memory-storage.js +158 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +35 -0
- package/memory-storage/resource-clients/dataset.js +108 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
- package/memory-storage/resource-clients/key-value-store.js +179 -0
- package/memory-storage/resource-clients/request-queue.d.ts +55 -0
- package/memory-storage/resource-clients/request-queue.js +413 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned-or-injected.d.ts +58 -0
- package/owned-or-injected.js +98 -0
- package/package.json +23 -23
- package/proxy-configuration.d.ts +118 -0
- package/proxy-configuration.js +141 -0
- package/recoverable-state.d.ts +177 -0
- package/recoverable-state.js +268 -0
- package/request.d.ts +48 -101
- package/request.js +139 -249
- package/serialization.d.ts +0 -1
- package/serialization.js +18 -18
- package/{service_locator.d.ts → service-locator.d.ts} +66 -37
- package/service-locator.js +255 -0
- package/storages/batched-adds.d.ts +39 -0
- package/storages/batched-adds.js +81 -0
- package/storages/dataset.d.ts +105 -58
- package/storages/dataset.js +292 -151
- package/storages/index.d.ts +11 -12
- package/storages/index.js +7 -12
- package/storages/key-value-store-codec.d.ts +32 -0
- package/storages/key-value-store-codec.js +108 -0
- package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
- package/storages/key-value-store.js +767 -0
- package/storages/request-dedup-cache.d.ts +20 -0
- package/storages/request-dedup-cache.js +48 -0
- package/storages/{request_list.d.ts → request-list.d.ts} +32 -171
- package/storages/{request_list.js → request-list.js} +276 -253
- package/storages/request-loader.d.ts +127 -0
- package/storages/request-loader.js +34 -0
- package/storages/request-manager-tandem.d.ts +82 -0
- package/storages/request-manager-tandem.js +200 -0
- package/storages/request-manager.d.ts +119 -0
- package/storages/request-manager.js +1 -0
- package/storages/{request_provider.d.ts → request-queue.d.ts} +127 -161
- package/storages/request-queue.js +871 -0
- package/storages/storage-instance-manager.d.ts +86 -0
- package/storages/storage-instance-manager.js +256 -0
- package/storages/storage-stats.d.ts +48 -0
- package/storages/storage-stats.js +29 -0
- package/storages/transaction.d.ts +270 -0
- package/storages/transaction.js +296 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +76 -17
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +23 -18
- package/validators.js +14 -18
- package/autoscaling/autoscaled_pool.d.ts +0 -298
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js +0 -527
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts +0 -4
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js +0 -4
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts +0 -179
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js +0 -279
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts +0 -178
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js +0 -168
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts +0 -43
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js +0 -111
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts +0 -61
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js +0 -99
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts +0 -191
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js +0 -108
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts +0 -60
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js +0 -118
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts +0 -55
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js +0 -309
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts +0 -7
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js +0 -7
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts +0 -8
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js +0 -2
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts +0 -204
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -350
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts +0 -254
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js +0 -268
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts +0 -3
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js +0 -3
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts +0 -84
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js +0 -219
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js +0 -93
- package/events/local_event_manager.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts +0 -169
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js +0 -247
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts +0 -122
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js +0 -138
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts +0 -134
- package/router.d.ts.map +0 -1
- package/router.js +0 -164
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/service_locator.d.ts.map +0 -1
- package/service_locator.js +0 -252
- package/service_locator.js.map +0 -1
- package/session_pool/consts.d.ts +0 -4
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js +0 -4
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts +0 -8
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js +0 -12
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts +0 -6
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js +0 -6
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts +0 -186
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js +0 -278
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts +0 -256
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js +0 -386
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js +0 -513
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts +0 -68
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js +0 -124
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -592
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts +0 -128
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js +0 -320
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -437
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts +0 -245
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -431
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -60
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -95
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
package/service_locator.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { MemoryStorage } from '@crawlee/memory-storage';
|
|
3
|
-
import log from '@apify/log';
|
|
4
|
-
import { Configuration } from './configuration.js';
|
|
5
|
-
import { ServiceConflictError } from './errors.js';
|
|
6
|
-
import { LocalEventManager } from './events/local_event_manager.js';
|
|
7
|
-
/**
|
|
8
|
-
* Service locator for managing the services used by Crawlee.
|
|
9
|
-
*
|
|
10
|
-
* All services are initialized to their default value lazily.
|
|
11
|
-
*
|
|
12
|
-
* There are two primary usage patterns:
|
|
13
|
-
*
|
|
14
|
-
* **1. Global service locator (for default services):**
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { serviceLocator, BasicCrawler } from 'crawlee';
|
|
17
|
-
*
|
|
18
|
-
* // Optionally configure global services before creating crawlers
|
|
19
|
-
* serviceLocator.setStorageClient(myCustomClient);
|
|
20
|
-
*
|
|
21
|
-
* // Crawler uses global services
|
|
22
|
-
* const crawler = new BasicCrawler({ ... });
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* **2. Per-crawler services (recommended for isolation):**
|
|
26
|
-
* ```typescript
|
|
27
|
-
* import { BasicCrawler, Configuration, LocalEventManager } from 'crawlee';
|
|
28
|
-
* import { MemoryStorage } from '@crawlee/memory-storage';
|
|
29
|
-
*
|
|
30
|
-
* const crawler = new BasicCrawler({
|
|
31
|
-
* requestHandler: async ({ request }) => { ... },
|
|
32
|
-
* configuration: new Configuration({ ... }), // custom config
|
|
33
|
-
* storageClient: new MemoryStorage(), // custom storage
|
|
34
|
-
* eventManager: LocalEventManager.fromConfig(), // custom events
|
|
35
|
-
* });
|
|
36
|
-
* // Crawler has its own isolated ServiceLocator instance
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export class ServiceLocator {
|
|
40
|
-
configuration;
|
|
41
|
-
eventManager;
|
|
42
|
-
storageClient;
|
|
43
|
-
/**
|
|
44
|
-
* Storage managers for Dataset, KeyValueStore, and RequestQueue.
|
|
45
|
-
* Manages caching and lifecycle of storage instances.
|
|
46
|
-
*/
|
|
47
|
-
storageManagers = new Map();
|
|
48
|
-
/**
|
|
49
|
-
* Creates a new ServiceLocator instance.
|
|
50
|
-
*
|
|
51
|
-
* @param configuration Optional configuration instance to use
|
|
52
|
-
* @param eventManager Optional event manager instance to use
|
|
53
|
-
* @param storageClient Optional storage client instance to use
|
|
54
|
-
*/
|
|
55
|
-
constructor(configuration, eventManager, storageClient) {
|
|
56
|
-
this.configuration = configuration;
|
|
57
|
-
this.eventManager = eventManager;
|
|
58
|
-
this.storageClient = storageClient;
|
|
59
|
-
}
|
|
60
|
-
getConfiguration() {
|
|
61
|
-
if (!this.configuration) {
|
|
62
|
-
log.debug('No configuration set, implicitly creating and using default Configuration.');
|
|
63
|
-
this.configuration = new Configuration();
|
|
64
|
-
}
|
|
65
|
-
return this.configuration;
|
|
66
|
-
}
|
|
67
|
-
setConfiguration(configuration) {
|
|
68
|
-
// Same instance, no need to do anything
|
|
69
|
-
if (this.configuration === configuration) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
// Already have a different configuration that was retrieved
|
|
73
|
-
if (this.configuration) {
|
|
74
|
-
throw new ServiceConflictError('Configuration', configuration, this.configuration);
|
|
75
|
-
}
|
|
76
|
-
this.configuration = configuration;
|
|
77
|
-
}
|
|
78
|
-
getEventManager() {
|
|
79
|
-
if (!this.eventManager) {
|
|
80
|
-
log.debug('No event manager set, implicitly creating and using default LocalEventManager.');
|
|
81
|
-
if (!this.configuration) {
|
|
82
|
-
log.warning('Implicit creation of event manager will implicitly set configuration as side effect. ' +
|
|
83
|
-
'It is advised to explicitly first set the configuration instead.');
|
|
84
|
-
}
|
|
85
|
-
this.eventManager = LocalEventManager.fromConfig(this.getConfiguration());
|
|
86
|
-
}
|
|
87
|
-
return this.eventManager;
|
|
88
|
-
}
|
|
89
|
-
setEventManager(eventManager) {
|
|
90
|
-
// Same instance, no need to do anything
|
|
91
|
-
if (this.eventManager === eventManager) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// Already have a different event manager that was retrieved
|
|
95
|
-
if (this.eventManager) {
|
|
96
|
-
throw new ServiceConflictError('EventManager', eventManager, this.eventManager);
|
|
97
|
-
}
|
|
98
|
-
this.eventManager = eventManager;
|
|
99
|
-
}
|
|
100
|
-
getStorageClient() {
|
|
101
|
-
if (!this.storageClient) {
|
|
102
|
-
log.debug('No storage client set, implicitly creating and using default MemoryStorage.');
|
|
103
|
-
if (!this.configuration) {
|
|
104
|
-
log.warning('Implicit creation of storage client will implicitly set configuration as side effect. ' +
|
|
105
|
-
'It is advised to explicitly first set the configuration instead.');
|
|
106
|
-
}
|
|
107
|
-
const config = this.getConfiguration();
|
|
108
|
-
this.storageClient = new MemoryStorage({
|
|
109
|
-
persistStorage: config.get('persistStorage'),
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return this.storageClient;
|
|
113
|
-
}
|
|
114
|
-
setStorageClient(storageClient) {
|
|
115
|
-
// Same instance, no need to do anything
|
|
116
|
-
if (this.storageClient === storageClient) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// Already have a different storage client that was retrieved
|
|
120
|
-
if (this.storageClient) {
|
|
121
|
-
throw new ServiceConflictError('StorageClient', storageClient, this.storageClient);
|
|
122
|
-
}
|
|
123
|
-
this.storageClient = storageClient;
|
|
124
|
-
}
|
|
125
|
-
getStorageManager(constructor) {
|
|
126
|
-
return this.storageManagers.get(constructor);
|
|
127
|
-
}
|
|
128
|
-
setStorageManager(constructor, storageManager) {
|
|
129
|
-
if (this.storageManagers.has(constructor)) {
|
|
130
|
-
throw new ServiceConflictError(`StorageManager(${constructor.name})`, storageManager, this.storageManagers.get(constructor));
|
|
131
|
-
}
|
|
132
|
-
this.storageManagers.set(constructor, storageManager);
|
|
133
|
-
}
|
|
134
|
-
clearStorageManagerCache() {
|
|
135
|
-
this.storageManagers.forEach((manager) => {
|
|
136
|
-
// KeyValueStore has a clearCache method on its instances
|
|
137
|
-
// TODO this uses fragile string matching and `any` casts into private fields - remove as part of
|
|
138
|
-
// https://github.com/apify/crawlee/issues/3075 (Storage instance management will be reworked significantly)
|
|
139
|
-
if (manager.name === 'KeyValueStore') {
|
|
140
|
-
manager.cache?.forEach((item) => {
|
|
141
|
-
item.clearCache?.();
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
this.storageManagers.clear();
|
|
146
|
-
}
|
|
147
|
-
reset() {
|
|
148
|
-
this.configuration = undefined;
|
|
149
|
-
this.eventManager = undefined;
|
|
150
|
-
this.storageClient = undefined;
|
|
151
|
-
this.clearStorageManagerCache();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Used as the default service provider when crawlers don't specify custom services.
|
|
156
|
-
*/
|
|
157
|
-
const globalServiceLocator = new ServiceLocator();
|
|
158
|
-
const serviceLocatorStorage = new AsyncLocalStorage();
|
|
159
|
-
/**
|
|
160
|
-
* Wraps all methods on `target` so that any code they invoke will see the given
|
|
161
|
-
* `serviceLocator` via `AsyncLocalStorage`, rather than the global one.
|
|
162
|
-
*
|
|
163
|
-
* Walks the prototype chain and replaces each method on the *instance* (not the prototype)
|
|
164
|
-
* with a wrapper that calls `serviceLocatorStorage.run(serviceLocator, originalMethod)`.
|
|
165
|
-
*
|
|
166
|
-
* The `AsyncLocalStorage` context propagates through the entire sync/async call tree of each
|
|
167
|
-
* wrapped method — including `super` calls, since the prototype methods execute within the
|
|
168
|
-
* context established by the instance-level wrapper.
|
|
169
|
-
*
|
|
170
|
-
* @internal
|
|
171
|
-
* @returns Scope control functions: `run` executes a callback within the scoped context,
|
|
172
|
-
* `enterScope`/`exitScope` allow entering/leaving the scope imperatively (e.g., for constructor bodies).
|
|
173
|
-
*/
|
|
174
|
-
export function bindMethodsToServiceLocator(serviceLocator, target) {
|
|
175
|
-
let proto = Object.getPrototypeOf(target);
|
|
176
|
-
while (proto !== null && proto !== Object.prototype) {
|
|
177
|
-
const propertyKeys = [...Object.getOwnPropertyNames(proto), ...Object.getOwnPropertySymbols(proto)];
|
|
178
|
-
for (const propertyKey of propertyKeys) {
|
|
179
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, propertyKey);
|
|
180
|
-
// We use property descriptors rather than accessing target[propertyKey] directly,
|
|
181
|
-
// because that would trigger getters and cause unwanted side effects.
|
|
182
|
-
// Skip getters, setters, and constructors — only wrap regular methods.
|
|
183
|
-
if (propertyKey === 'constructor' ||
|
|
184
|
-
!descriptor ||
|
|
185
|
-
descriptor.get ||
|
|
186
|
-
descriptor.set ||
|
|
187
|
-
typeof descriptor.value !== 'function')
|
|
188
|
-
continue;
|
|
189
|
-
const original = descriptor.value;
|
|
190
|
-
target[propertyKey] = (...args) => {
|
|
191
|
-
return serviceLocatorStorage.run(serviceLocator, () => {
|
|
192
|
-
return original.apply(target, args);
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
proto = Object.getPrototypeOf(proto);
|
|
197
|
-
}
|
|
198
|
-
let previousStore;
|
|
199
|
-
return {
|
|
200
|
-
run: (fn) => serviceLocatorStorage.run(serviceLocator, fn),
|
|
201
|
-
enterScope: () => {
|
|
202
|
-
previousStore = serviceLocatorStorage.getStore();
|
|
203
|
-
serviceLocatorStorage.enterWith(serviceLocator);
|
|
204
|
-
},
|
|
205
|
-
exitScope: () => {
|
|
206
|
-
serviceLocatorStorage.enterWith(previousStore); // casting to any so that `undefined` is accepted - this "unsets" the AsyncLocalStorage
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
export const serviceLocator = {
|
|
211
|
-
getConfiguration() {
|
|
212
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
213
|
-
return currentServiceLocator.getConfiguration();
|
|
214
|
-
},
|
|
215
|
-
setConfiguration(configuration) {
|
|
216
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
217
|
-
currentServiceLocator.setConfiguration(configuration);
|
|
218
|
-
},
|
|
219
|
-
getEventManager() {
|
|
220
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
221
|
-
return currentServiceLocator.getEventManager();
|
|
222
|
-
},
|
|
223
|
-
setEventManager(eventManager) {
|
|
224
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
225
|
-
currentServiceLocator.setEventManager(eventManager);
|
|
226
|
-
},
|
|
227
|
-
getStorageClient() {
|
|
228
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
229
|
-
return currentServiceLocator.getStorageClient();
|
|
230
|
-
},
|
|
231
|
-
setStorageClient(storageClient) {
|
|
232
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
233
|
-
currentServiceLocator.setStorageClient(storageClient);
|
|
234
|
-
},
|
|
235
|
-
getStorageManager(constructor) {
|
|
236
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
237
|
-
return currentServiceLocator.getStorageManager(constructor);
|
|
238
|
-
},
|
|
239
|
-
setStorageManager(constructor, storageManager) {
|
|
240
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
241
|
-
currentServiceLocator.setStorageManager(constructor, storageManager);
|
|
242
|
-
},
|
|
243
|
-
clearStorageManagerCache() {
|
|
244
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
245
|
-
currentServiceLocator.clearStorageManagerCache();
|
|
246
|
-
},
|
|
247
|
-
reset() {
|
|
248
|
-
const currentServiceLocator = serviceLocatorStorage.getStore() ?? globalServiceLocator;
|
|
249
|
-
currentServiceLocator.reset();
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
//# sourceMappingURL=service_locator.js.map
|
package/service_locator.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service_locator.js","sourceRoot":"","sources":["../src/service_locator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAiEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,cAAc;IACf,aAAa,CAAiB;IAC9B,YAAY,CAAgB;IAC5B,aAAa,CAAiB;IAEtC;;;OAGG;IACK,eAAe,GAAG,IAAI,GAAG,EAAyC,CAAC;IAE3E;;;;;;OA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QACvF,qBAAqB,CAAC,iBAAiB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IACzE,CAAC;IACD,wBAAwB;QACpB,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,IAAI,oBAAoB,CAAC;QACvF,qBAAqB,CAAC,wBAAwB,EAAE,CAAC;IACrD,CAAC;IACD,KAAK;QACD,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,IAAI,oBAAoB,CAAC;QACvF,qBAAqB,CAAC,KAAK,EAAE,CAAC;IAClC,CAAC;CACJ,CAAC"}
|
package/session_pool/consts.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/session_pool/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,UAAkB,CAAC;AACpD,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAC1D,eAAO,MAAM,aAAa,OAAO,CAAC"}
|
package/session_pool/consts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/session_pool/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC"}
|
package/session_pool/errors.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/session_pool/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAC3B,QAAQ,CAAC,kBAAkB,EAAE,OAAO;gBAA3B,kBAAkB,EAAE,OAAO;CAInD"}
|
package/session_pool/errors.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @ignore
|
|
3
|
-
*/
|
|
4
|
-
export class CookieParseError extends Error {
|
|
5
|
-
cookieHeaderString;
|
|
6
|
-
constructor(cookieHeaderString) {
|
|
7
|
-
super(`Could not parse cookie header string: ${cookieHeaderString}`);
|
|
8
|
-
this.cookieHeaderString = cookieHeaderString;
|
|
9
|
-
Error.captureStackTrace(this, CookieParseError);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/session_pool/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAClB;IAArB,YAAqB,kBAA2B;QAC5C,KAAK,CAAC,yCAAyC,kBAAkB,EAAE,CAAC,CAAC;QADpD,uBAAkB,GAAlB,kBAAkB,CAAS;QAE5C,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACpD,CAAC;CACJ"}
|
package/session_pool/events.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/session_pool/events.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,eAAO,MAAM,qBAAqB,mBAAmB,CAAC"}
|
package/session_pool/events.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/session_pool/events.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,CAAC,MAAM,qBAAqB,GAAG,gBAAgB,CAAC"}
|
package/session_pool/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session_pool/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
package/session_pool/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/session_pool/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import type { Cookie as CookieObject, Dictionary, ISession, ProxyInfo, SessionState } from '@crawlee/types';
|
|
2
|
-
import type { Cookie } from 'tough-cookie';
|
|
3
|
-
import { CookieJar } from 'tough-cookie';
|
|
4
|
-
import type { Log } from '@apify/log';
|
|
5
|
-
export interface SessionOptions {
|
|
6
|
-
/** Id of session used for generating fingerprints. It is used as proxy session name. */
|
|
7
|
-
id?: string;
|
|
8
|
-
/**
|
|
9
|
-
* Number of seconds after which the session is considered as expired.
|
|
10
|
-
* @default 3000
|
|
11
|
-
*/
|
|
12
|
-
maxAgeSecs?: number;
|
|
13
|
-
/** Object where custom user data can be stored. For example custom headers. */
|
|
14
|
-
userData?: Dictionary;
|
|
15
|
-
/**
|
|
16
|
-
* Maximum number of marking session as blocked usage.
|
|
17
|
-
* If the `errorScore` reaches the `maxErrorScore` session is marked as block and it is thrown away.
|
|
18
|
-
* It starts at 0. Calling the `markBad` function increases the `errorScore` by 1.
|
|
19
|
-
* Calling the `markGood` will decrease the `errorScore` by `errorScoreDecrement`
|
|
20
|
-
* @default 3
|
|
21
|
-
*/
|
|
22
|
-
maxErrorScore?: number;
|
|
23
|
-
/**
|
|
24
|
-
* It is used for healing the session.
|
|
25
|
-
* For example: if your session is marked bad two times, but it is successful on the third attempt it's errorScore
|
|
26
|
-
* is decremented by this number.
|
|
27
|
-
* @default 0.5
|
|
28
|
-
*/
|
|
29
|
-
errorScoreDecrement?: number;
|
|
30
|
-
/** Date of creation. */
|
|
31
|
-
createdAt?: Date;
|
|
32
|
-
/** Date of expiration. */
|
|
33
|
-
expiresAt?: Date;
|
|
34
|
-
/**
|
|
35
|
-
* Indicates how many times the session has been used.
|
|
36
|
-
* @default 0
|
|
37
|
-
*/
|
|
38
|
-
usageCount?: number;
|
|
39
|
-
/**
|
|
40
|
-
* Session should be used only a limited amount of times.
|
|
41
|
-
* This number indicates how many times the session is going to be used, before it is thrown away.
|
|
42
|
-
* @default 50
|
|
43
|
-
*/
|
|
44
|
-
maxUsageCount?: number;
|
|
45
|
-
/** SessionPool instance. Session will emit the `sessionRetired` event on this instance. */
|
|
46
|
-
sessionPool?: import('./session_pool.js').SessionPool;
|
|
47
|
-
log?: Log;
|
|
48
|
-
errorScore?: number;
|
|
49
|
-
cookieJar?: CookieJar;
|
|
50
|
-
proxyInfo?: ProxyInfo;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
|
|
54
|
-
* You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint.
|
|
55
|
-
* Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.
|
|
56
|
-
* @category Scaling
|
|
57
|
-
*/
|
|
58
|
-
export declare class Session implements ISession {
|
|
59
|
-
readonly id: string;
|
|
60
|
-
private maxAgeSecs;
|
|
61
|
-
userData: Dictionary;
|
|
62
|
-
private _maxErrorScore;
|
|
63
|
-
private _errorScoreDecrement;
|
|
64
|
-
private _createdAt;
|
|
65
|
-
private _expiresAt;
|
|
66
|
-
private _usageCount;
|
|
67
|
-
private _maxUsageCount;
|
|
68
|
-
private sessionPool;
|
|
69
|
-
private _errorScore;
|
|
70
|
-
private _proxyInfo?;
|
|
71
|
-
private _cookieJar;
|
|
72
|
-
private log;
|
|
73
|
-
get errorScore(): number;
|
|
74
|
-
get usageCount(): number;
|
|
75
|
-
get maxErrorScore(): number;
|
|
76
|
-
get errorScoreDecrement(): number;
|
|
77
|
-
get expiresAt(): Date;
|
|
78
|
-
get createdAt(): Date;
|
|
79
|
-
get maxUsageCount(): number;
|
|
80
|
-
get cookieJar(): CookieJar;
|
|
81
|
-
get proxyInfo(): ProxyInfo | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* Session configuration.
|
|
84
|
-
*/
|
|
85
|
-
constructor(options: SessionOptions);
|
|
86
|
-
/**
|
|
87
|
-
* Indicates whether the session is blocked.
|
|
88
|
-
* Session is blocked once it reaches the `maxErrorScore`.
|
|
89
|
-
*/
|
|
90
|
-
isBlocked(): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Indicates whether the session is expired.
|
|
93
|
-
* Session expiration is determined by the `maxAgeSecs`.
|
|
94
|
-
* Once the session is older than `createdAt + maxAgeSecs` the session is considered expired.
|
|
95
|
-
*/
|
|
96
|
-
isExpired(): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Indicates whether the session is used maximum number of times.
|
|
99
|
-
* Session maximum usage count can be changed by `maxUsageCount` parameter.
|
|
100
|
-
*/
|
|
101
|
-
isMaxUsageCountReached(): boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Indicates whether the session can be used for next requests.
|
|
104
|
-
* Session is usable when it is not expired, not blocked and the maximum usage count has not be reached.
|
|
105
|
-
*/
|
|
106
|
-
isUsable(): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* This method should be called after a successful session usage.
|
|
109
|
-
* It increases `usageCount` and potentially lowers the `errorScore` by the `errorScoreDecrement`.
|
|
110
|
-
*/
|
|
111
|
-
markGood(): void;
|
|
112
|
-
/**
|
|
113
|
-
* Gets session state for persistence in KeyValueStore.
|
|
114
|
-
* @returns Represents session internal state.
|
|
115
|
-
*/
|
|
116
|
-
getState(): SessionState;
|
|
117
|
-
/**
|
|
118
|
-
* Marks session as blocked and emits event on the `SessionPool`
|
|
119
|
-
* This method should be used if the session usage was unsuccessful
|
|
120
|
-
* and you are sure that it is because of the session configuration and not any external matters.
|
|
121
|
-
* For example when server returns 403 status code.
|
|
122
|
-
* If the session does not work due to some external factors as server error such as 5XX you probably want to use `markBad` method.
|
|
123
|
-
*/
|
|
124
|
-
retire(): void;
|
|
125
|
-
/**
|
|
126
|
-
* Increases usage and error count.
|
|
127
|
-
* Should be used when the session has been used unsuccessfully. For example because of timeouts.
|
|
128
|
-
*/
|
|
129
|
-
markBad(): void;
|
|
130
|
-
/**
|
|
131
|
-
* With certain status codes: `401`, `403` or `429` we can be certain
|
|
132
|
-
* that the target website is blocking us. This function helps to do this conveniently
|
|
133
|
-
* by retiring the session when such code is received. Optionally, the default status
|
|
134
|
-
* codes can be extended in the second parameter.
|
|
135
|
-
* @param statusCode HTTP status code.
|
|
136
|
-
* @returns Whether the session was retired.
|
|
137
|
-
*/
|
|
138
|
-
retireOnBlockedStatusCodes(statusCode: number): boolean;
|
|
139
|
-
/**
|
|
140
|
-
* Saves cookies from an HTTP response to be used with the session.
|
|
141
|
-
* It expects an object with a `headers` property that's either an `Object`
|
|
142
|
-
* (typical Node.js responses) or a `Function` (Puppeteer Response).
|
|
143
|
-
*
|
|
144
|
-
* It then parses and saves the cookies from the `set-cookie` header, if available.
|
|
145
|
-
*/
|
|
146
|
-
setCookiesFromResponse(response: Response): void;
|
|
147
|
-
/**
|
|
148
|
-
* Saves an array with cookie objects to be used with the session.
|
|
149
|
-
* The objects should be in the format that
|
|
150
|
-
* [Puppeteer uses](https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-pagecookiesurls),
|
|
151
|
-
* but you can also use this function to set cookies manually:
|
|
152
|
-
*
|
|
153
|
-
* ```
|
|
154
|
-
* [
|
|
155
|
-
* { name: 'cookie1', value: 'my-cookie' },
|
|
156
|
-
* { name: 'cookie2', value: 'your-cookie' }
|
|
157
|
-
* ]
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
setCookies(cookies: CookieObject[], url: string): void;
|
|
161
|
-
/**
|
|
162
|
-
* Returns cookies in a format compatible with puppeteer/playwright and ready to be used with `page.setCookie`.
|
|
163
|
-
* @param url website url. Only cookies stored for this url will be returned
|
|
164
|
-
*/
|
|
165
|
-
getCookies(url: string): CookieObject[];
|
|
166
|
-
/**
|
|
167
|
-
* Returns cookies saved with the session in the typical
|
|
168
|
-
* key1=value1; key2=value2 format, ready to be used in
|
|
169
|
-
* a cookie header or elsewhere.
|
|
170
|
-
* @returns Represents `Cookie` header.
|
|
171
|
-
*/
|
|
172
|
-
getCookieString(url: string): string;
|
|
173
|
-
/**
|
|
174
|
-
* Sets a cookie within this session for the specific URL.
|
|
175
|
-
*/
|
|
176
|
-
setCookie(rawCookie: string, url: string): void;
|
|
177
|
-
/**
|
|
178
|
-
* Sets cookies.
|
|
179
|
-
*/
|
|
180
|
-
protected _setCookies(cookies: Cookie[], url: string): void;
|
|
181
|
-
/**
|
|
182
|
-
* Checks if session is not usable. if it is not retires the session.
|
|
183
|
-
*/
|
|
184
|
-
protected _maybeSelfRetire(): void;
|
|
185
|
-
}
|
|
186
|
-
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session_pool/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE5G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAYtC,MAAM,WAAW,cAAc;IAC3B,wFAAwF;IACxF,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,UAAU,CAAC;IAEtB;;;;;;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