apify 4.0.0-beta.31 → 4.0.0-beta.32
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/dist/actor.d.ts +6 -23
- package/dist/actor.js +55 -48
- package/dist/apify_dataset_backend.d.ts +1 -1
- package/dist/apify_dataset_backend.js +6 -6
- package/dist/apify_key_value_store_backend.d.ts +1 -1
- package/dist/apify_key_value_store_backend.js +10 -10
- package/dist/apify_request_queue_backend.d.ts +1 -1
- package/dist/apify_request_queue_backend.js +3 -3
- package/dist/apify_request_queue_shared_backend.d.ts +1 -14
- package/dist/apify_request_queue_shared_backend.js +38 -38
- package/dist/apify_request_queue_single_backend.d.ts +1 -10
- package/dist/apify_request_queue_single_backend.js +44 -44
- package/dist/apify_storage_backend.d.ts +1 -12
- package/dist/apify_storage_backend.js +43 -43
- package/dist/charging.d.ts +1 -14
- package/dist/charging.js +84 -81
- package/dist/platform_event_manager.d.ts +1 -2
- package/dist/platform_event_manager.js +7 -7
- package/dist/proxy_configuration.d.ts +7 -18
- package/dist/proxy_configuration.js +46 -57
- package/package.json +1 -1
package/dist/charging.d.ts
CHANGED
|
@@ -54,20 +54,7 @@ export declare function mergeChargeResults(a: ChargeResult, b: ChargeResult): Ch
|
|
|
54
54
|
* Handles pay-per-event charging.
|
|
55
55
|
*/
|
|
56
56
|
export declare class ChargingManager {
|
|
57
|
-
private
|
|
58
|
-
private readonly LOCAL_CHARGING_LOG_DATASET_NAME;
|
|
59
|
-
private readonly PLATFORM_CHARGING_LOG_DATASET_ID_KEY;
|
|
60
|
-
private maxTotalChargeUsd;
|
|
61
|
-
private isAtHome;
|
|
62
|
-
private actorRunId?;
|
|
63
|
-
private pricingModel?;
|
|
64
|
-
private purgeChargingLogDataset;
|
|
65
|
-
private useChargingLogDataset;
|
|
66
|
-
private notPpeWarningPrinted;
|
|
67
|
-
private pricingInfo;
|
|
68
|
-
private chargingState?;
|
|
69
|
-
private chargingLogDataset?;
|
|
70
|
-
private apifyClient;
|
|
57
|
+
#private;
|
|
71
58
|
constructor(configuration: Configuration, apifyClient: ApifyClient);
|
|
72
59
|
private get isPayPerEvent();
|
|
73
60
|
private fetchPricingInfo;
|
package/dist/charging.js
CHANGED
|
@@ -15,45 +15,45 @@ export function mergeChargeResults(a, b) {
|
|
|
15
15
|
* Handles pay-per-event charging.
|
|
16
16
|
*/
|
|
17
17
|
export class ChargingManager {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
#LOCAL_CHARGING_LOG_DATASET_NAME = 'charging_log';
|
|
19
|
+
#PLATFORM_CHARGING_LOG_DATASET_ID_KEY = 'CHARGING_LOG_DATASET_ID';
|
|
20
|
+
#maxTotalChargeUsd;
|
|
21
|
+
#isAtHome;
|
|
22
|
+
#actorRunId;
|
|
23
|
+
#pricingModel;
|
|
24
|
+
#purgeChargingLogDataset;
|
|
25
|
+
#useChargingLogDataset;
|
|
26
|
+
#notPpeWarningPrinted = false;
|
|
27
|
+
#pricingInfo = {};
|
|
28
|
+
#chargingState;
|
|
29
|
+
#chargingLogDataset;
|
|
30
|
+
#apifyClient;
|
|
31
|
+
#configuration;
|
|
32
32
|
constructor(configuration, apifyClient) {
|
|
33
|
-
this
|
|
34
|
-
this
|
|
35
|
-
this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
38
|
-
this
|
|
39
|
-
this
|
|
33
|
+
this.#configuration = configuration;
|
|
34
|
+
this.#maxTotalChargeUsd = configuration.maxTotalChargeUsd || Infinity; // convert `0` to `Infinity` in case the value is an empty string
|
|
35
|
+
this.#isAtHome = configuration.isAtHome;
|
|
36
|
+
this.#actorRunId = configuration.actorRunId;
|
|
37
|
+
this.#purgeChargingLogDataset = configuration.purgeOnStart;
|
|
38
|
+
this.#useChargingLogDataset = configuration.useChargingLogDataset;
|
|
39
|
+
this.#apifyClient = apifyClient;
|
|
40
40
|
}
|
|
41
41
|
get isPayPerEvent() {
|
|
42
|
-
return this
|
|
42
|
+
return this.#pricingModel === 'PAY_PER_EVENT';
|
|
43
43
|
}
|
|
44
44
|
async fetchPricingInfo() {
|
|
45
|
-
if (this
|
|
45
|
+
if (this.#configuration.actorPricingInfo && this.#configuration.chargedEventCounts) {
|
|
46
46
|
return {
|
|
47
|
-
pricingInfo: JSON.parse(this
|
|
48
|
-
chargedEventCounts: JSON.parse(this
|
|
49
|
-
maxTotalChargeUsd: this
|
|
47
|
+
pricingInfo: JSON.parse(this.#configuration.actorPricingInfo),
|
|
48
|
+
chargedEventCounts: JSON.parse(this.#configuration.chargedEventCounts),
|
|
49
|
+
maxTotalChargeUsd: this.#configuration.maxTotalChargeUsd || Infinity,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
if (this
|
|
53
|
-
if (this
|
|
52
|
+
if (this.#isAtHome) {
|
|
53
|
+
if (this.#actorRunId === undefined) {
|
|
54
54
|
throw new Error('Actor run ID not found even though the Actor is running on Apify');
|
|
55
55
|
}
|
|
56
|
-
const run = await this
|
|
56
|
+
const run = await this.#apifyClient.run(this.#actorRunId).get();
|
|
57
57
|
if (run === undefined) {
|
|
58
58
|
throw new Error('Actor run not found');
|
|
59
59
|
}
|
|
@@ -66,7 +66,7 @@ export class ChargingManager {
|
|
|
66
66
|
return {
|
|
67
67
|
pricingInfo: undefined,
|
|
68
68
|
chargedEventCounts: {},
|
|
69
|
-
maxTotalChargeUsd: this
|
|
69
|
+
maxTotalChargeUsd: this.#configuration.maxTotalChargeUsd || Infinity,
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
@@ -74,63 +74,63 @@ export class ChargingManager {
|
|
|
74
74
|
*/
|
|
75
75
|
async init() {
|
|
76
76
|
// Validate config - it may have changed since the instantiation
|
|
77
|
-
if (this
|
|
77
|
+
if (this.#useChargingLogDataset && this.#isAtHome) {
|
|
78
78
|
throw new Error('Using the ACTOR_USE_CHARGING_LOG_DATASET environment variable is only supported in a local development environment');
|
|
79
79
|
}
|
|
80
|
-
if (this
|
|
81
|
-
if (this
|
|
80
|
+
if (this.#configuration.testPayPerEvent) {
|
|
81
|
+
if (this.#isAtHome) {
|
|
82
82
|
throw new Error('Using the ACTOR_TEST_PAY_PER_EVENT environment variable is only supported in a local development environment');
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
// Retrieve pricing information
|
|
86
86
|
const { pricingInfo, chargedEventCounts, maxTotalChargeUsd } = await this.fetchPricingInfo();
|
|
87
|
-
if (this
|
|
88
|
-
this
|
|
87
|
+
if (this.#configuration.testPayPerEvent) {
|
|
88
|
+
this.#pricingModel = 'PAY_PER_EVENT';
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
this
|
|
91
|
+
this.#pricingModel ??= pricingInfo?.pricingModel;
|
|
92
92
|
}
|
|
93
93
|
// Load per-event pricing information
|
|
94
94
|
if (pricingInfo?.pricingModel === 'PAY_PER_EVENT') {
|
|
95
95
|
for (const [eventName, eventPricing] of Object.entries(pricingInfo.pricingPerEvent.actorChargeEvents)) {
|
|
96
|
-
this
|
|
96
|
+
this.#pricingInfo[eventName] = {
|
|
97
97
|
price: eventPricing.eventPriceUsd,
|
|
98
98
|
title: eventPricing.eventTitle,
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
this
|
|
101
|
+
this.#maxTotalChargeUsd = maxTotalChargeUsd;
|
|
102
102
|
}
|
|
103
|
-
this
|
|
103
|
+
this.#chargingState = {};
|
|
104
104
|
for (const [eventName, chargeCount] of Object.entries(chargedEventCounts ?? {})) {
|
|
105
|
-
this
|
|
105
|
+
this.#chargingState[eventName] = {
|
|
106
106
|
chargeCount,
|
|
107
|
-
totalChargedAmount: chargeCount * (this
|
|
107
|
+
totalChargedAmount: chargeCount * (this.#pricingInfo[eventName]?.price ?? 0),
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
if (!this.isPayPerEvent || !this
|
|
110
|
+
if (!this.isPayPerEvent || !this.#useChargingLogDataset) {
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
113
|
// Set up charging log dataset
|
|
114
|
-
if (this
|
|
114
|
+
if (this.#isAtHome) {
|
|
115
115
|
const datasetId = await this.ensureChargingLogDatasetOnPlatform();
|
|
116
|
-
this
|
|
116
|
+
this.#chargingLogDataset = await Dataset.open(datasetId);
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
if (this
|
|
120
|
-
const dataset = await Dataset.open(this
|
|
119
|
+
if (this.#purgeChargingLogDataset) {
|
|
120
|
+
const dataset = await Dataset.open(this.#LOCAL_CHARGING_LOG_DATASET_NAME);
|
|
121
121
|
await dataset.drop();
|
|
122
122
|
}
|
|
123
|
-
this
|
|
123
|
+
this.#chargingLogDataset = await Dataset.open(this.#LOCAL_CHARGING_LOG_DATASET_NAME);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
async ensureChargingLogDatasetOnPlatform() {
|
|
127
127
|
const defaultStore = await KeyValueStore.open();
|
|
128
|
-
const storedDatasetId = await defaultStore.getValue(this
|
|
128
|
+
const storedDatasetId = await defaultStore.getValue(this.#PLATFORM_CHARGING_LOG_DATASET_ID_KEY);
|
|
129
129
|
if (storedDatasetId !== null) {
|
|
130
130
|
return storedDatasetId;
|
|
131
131
|
}
|
|
132
|
-
const dataset = await this
|
|
133
|
-
await defaultStore.setValue(this
|
|
132
|
+
const dataset = await this.#apifyClient.datasets().getOrCreate();
|
|
133
|
+
await defaultStore.setValue(this.#PLATFORM_CHARGING_LOG_DATASET_ID_KEY, dataset.id);
|
|
134
134
|
return dataset.id;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
@@ -138,20 +138,20 @@ export class ChargingManager {
|
|
|
138
138
|
* {@link ChargingManager.getPricingInfo}) require an initialized manager.
|
|
139
139
|
*/
|
|
140
140
|
get isInitialized() {
|
|
141
|
-
return this
|
|
141
|
+
return this.#chargingState !== undefined;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Get information about the pricing for this Actor.
|
|
145
145
|
*/
|
|
146
146
|
getPricingInfo() {
|
|
147
|
-
if (this
|
|
147
|
+
if (this.#chargingState === undefined) {
|
|
148
148
|
throw new Error('ChargingManager is not initialized');
|
|
149
149
|
}
|
|
150
150
|
return {
|
|
151
|
-
pricingModel: this
|
|
151
|
+
pricingModel: this.#pricingModel,
|
|
152
152
|
isPayPerEvent: this.isPayPerEvent,
|
|
153
|
-
maxTotalChargeUsd: this
|
|
154
|
-
perEventPrices: Object.fromEntries(Object.entries(this
|
|
153
|
+
maxTotalChargeUsd: this.#maxTotalChargeUsd,
|
|
154
|
+
perEventPrices: Object.fromEntries(Object.entries(this.#pricingInfo).map(([eventName, { price }]) => [eventName, price])),
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
@@ -171,11 +171,14 @@ export class ChargingManager {
|
|
|
171
171
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
172
172
|
*/
|
|
173
173
|
async charge({ eventName, count = 1 }) {
|
|
174
|
-
const calculateChargeableWithinLimit = () => Object.fromEntries(Object.keys(this
|
|
174
|
+
const calculateChargeableWithinLimit = () => Object.fromEntries(Object.keys(this.#pricingInfo).map((name) => [
|
|
175
|
+
name,
|
|
176
|
+
this.calculateMaxEventChargeCountWithinLimit(name),
|
|
177
|
+
]));
|
|
175
178
|
if (!this.isPayPerEvent) {
|
|
176
|
-
if (!this
|
|
179
|
+
if (!this.#notPpeWarningPrinted) {
|
|
177
180
|
log.warning('Ignored attempt to charge for an event - the Actor does not use the pay-per-event pricing');
|
|
178
|
-
this
|
|
181
|
+
this.#notPpeWarningPrinted = true;
|
|
179
182
|
}
|
|
180
183
|
return {
|
|
181
184
|
eventChargeLimitReached: false,
|
|
@@ -183,7 +186,7 @@ export class ChargingManager {
|
|
|
183
186
|
chargeableWithinLimit: calculateChargeableWithinLimit(),
|
|
184
187
|
};
|
|
185
188
|
}
|
|
186
|
-
if (this
|
|
189
|
+
if (this.#chargingState === undefined) {
|
|
187
190
|
throw new Error('ChargingManager is not initialized');
|
|
188
191
|
}
|
|
189
192
|
/* START OF CRITICAL SECTION - no awaits here */
|
|
@@ -195,7 +198,7 @@ export class ChargingManager {
|
|
|
195
198
|
// If the caller tries to charge more than the budget allows, overcharge by one event
|
|
196
199
|
// so that the Actor is detected by the platform and terminated.
|
|
197
200
|
// But don't do this if already strictly over the budget - no point piling on charges.
|
|
198
|
-
if (this.calculateTotalChargedAmount() <= this
|
|
201
|
+
if (this.calculateTotalChargedAmount() <= this.#maxTotalChargeUsd) {
|
|
199
202
|
return maxEventChargeCount + 1;
|
|
200
203
|
}
|
|
201
204
|
return 0;
|
|
@@ -207,32 +210,32 @@ export class ChargingManager {
|
|
|
207
210
|
chargeableWithinLimit: calculateChargeableWithinLimit(),
|
|
208
211
|
};
|
|
209
212
|
}
|
|
210
|
-
const pricingInfo = this
|
|
211
|
-
price: this
|
|
213
|
+
const pricingInfo = this.#pricingInfo[eventName] ?? {
|
|
214
|
+
price: this.#isAtHome ? 0 : 1, // Use a nonzero price for local development so that the maximum budget can be reached
|
|
212
215
|
title: `Unknown event '${eventName}'`,
|
|
213
216
|
};
|
|
214
|
-
this
|
|
217
|
+
this.#chargingState[eventName] ??= {
|
|
215
218
|
chargeCount: 0,
|
|
216
219
|
totalChargedAmount: 0,
|
|
217
220
|
};
|
|
218
|
-
this
|
|
219
|
-
this
|
|
221
|
+
this.#chargingState[eventName].chargeCount += chargedCount;
|
|
222
|
+
this.#chargingState[eventName].totalChargedAmount += chargedCount * pricingInfo.price;
|
|
220
223
|
/* END OF CRITICAL SECTION */
|
|
221
|
-
if (this
|
|
224
|
+
if (this.#isAtHome) {
|
|
222
225
|
if (eventName.startsWith('apify-')) {
|
|
223
226
|
// Synthetic events (e.g. apify-default-dataset-item) are tracked locally only,
|
|
224
227
|
// the platform handles them automatically based on dataset writes.
|
|
225
228
|
}
|
|
226
|
-
else if (this
|
|
227
|
-
await this
|
|
229
|
+
else if (this.#pricingInfo[eventName] !== undefined) {
|
|
230
|
+
await this.#apifyClient.run(this.#actorRunId).charge({ eventName, count: chargedCount });
|
|
228
231
|
}
|
|
229
232
|
else {
|
|
230
233
|
log.warning(`Attempting to charge for an unknown event '${eventName}'`);
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
const timestamp = new Date().toISOString();
|
|
234
|
-
if (this
|
|
235
|
-
await this
|
|
237
|
+
if (this.#chargingLogDataset !== undefined) {
|
|
238
|
+
await this.#chargingLogDataset.pushData({
|
|
236
239
|
eventName,
|
|
237
240
|
eventTitle: pricingInfo.title,
|
|
238
241
|
eventPriceUsd: pricingInfo.price,
|
|
@@ -254,25 +257,25 @@ export class ChargingManager {
|
|
|
254
257
|
* Get the number of events with given name that the Actor has charged for so far.
|
|
255
258
|
*/
|
|
256
259
|
getChargedEventCount(eventName) {
|
|
257
|
-
if (this
|
|
260
|
+
if (this.#chargingState === undefined) {
|
|
258
261
|
throw new Error('ChargingManager is not initialized');
|
|
259
262
|
}
|
|
260
|
-
return this
|
|
263
|
+
return this.#chargingState[eventName]?.chargeCount ?? 0;
|
|
261
264
|
}
|
|
262
265
|
/**
|
|
263
266
|
* Get the maximum amount of money that the Actor is allowed to charge.
|
|
264
267
|
*/
|
|
265
268
|
getMaxTotalChargeUsd() {
|
|
266
|
-
if (this
|
|
269
|
+
if (this.#chargingState === undefined) {
|
|
267
270
|
throw new Error('ChargingManager is not initialized');
|
|
268
271
|
}
|
|
269
|
-
return this
|
|
272
|
+
return this.#maxTotalChargeUsd;
|
|
270
273
|
}
|
|
271
274
|
calculateTotalChargedAmount() {
|
|
272
|
-
if (this
|
|
275
|
+
if (this.#chargingState === undefined) {
|
|
273
276
|
throw new Error('ChargingManager is not initialized');
|
|
274
277
|
}
|
|
275
|
-
const result = Object.values(this
|
|
278
|
+
const result = Object.values(this.#chargingState)
|
|
276
279
|
.map(({ totalChargedAmount }) => totalChargedAmount)
|
|
277
280
|
.reduce((sum, inc) => sum + inc, 0);
|
|
278
281
|
// Keeping float precision issues at bay
|
|
@@ -283,7 +286,7 @@ export class ChargingManager {
|
|
|
283
286
|
* If the event is not registered, returns Infinity (free of charge)
|
|
284
287
|
*/
|
|
285
288
|
calculateMaxEventChargeCountWithinLimit(eventName) {
|
|
286
|
-
if (this
|
|
289
|
+
if (this.#chargingState === undefined) {
|
|
287
290
|
throw new Error('ChargingManager is not initialized');
|
|
288
291
|
}
|
|
289
292
|
const price = this.calculateEventPrice(eventName);
|
|
@@ -293,11 +296,11 @@ export class ChargingManager {
|
|
|
293
296
|
return this.calculateMaxChargesByPrice(price);
|
|
294
297
|
}
|
|
295
298
|
calculateEventPrice(eventName) {
|
|
296
|
-
return this
|
|
299
|
+
return this.#isAtHome ? this.#pricingInfo[eventName]?.price : 1; // Use a nonzero price for local development so that the maximum budget can be reached
|
|
297
300
|
}
|
|
298
301
|
calculateMaxChargesByPrice(price) {
|
|
299
302
|
// The raw number of events allowed by the budget
|
|
300
|
-
const unroundedResult = (this
|
|
303
|
+
const unroundedResult = (this.#maxTotalChargeUsd - this.calculateTotalChargedAmount()) / price;
|
|
301
304
|
// First round as Math.floor(4.9999999999999999) will incorrectly return 5
|
|
302
305
|
const roundedResult = Math.floor(Number(unroundedResult.toFixed(4)));
|
|
303
306
|
return Math.max(0, roundedResult);
|
|
@@ -307,7 +310,7 @@ export class ChargingManager {
|
|
|
307
310
|
* Returns the limited items and count to charge.
|
|
308
311
|
*/
|
|
309
312
|
calculatePushDataLimits({ items, eventName, isDefaultDataset, }) {
|
|
310
|
-
if (this
|
|
313
|
+
if (this.#chargingState === undefined) {
|
|
311
314
|
throw new Error('ChargingManager is not initialized');
|
|
312
315
|
}
|
|
313
316
|
const itemsArray = Array.isArray(items) ? items : [items];
|
|
@@ -329,7 +332,7 @@ export class ChargingManager {
|
|
|
329
332
|
// But don't do this if already strictly over the budget - no point piling on charges.
|
|
330
333
|
if (itemsArray.length > 0 &&
|
|
331
334
|
maxChargedCount === 0 &&
|
|
332
|
-
this.calculateTotalChargedAmount() <= this
|
|
335
|
+
this.calculateTotalChargedAmount() <= this.#maxTotalChargeUsd) {
|
|
333
336
|
return 1;
|
|
334
337
|
}
|
|
335
338
|
return maxChargedCount;
|
|
@@ -39,9 +39,8 @@ import { Configuration } from './configuration.js';
|
|
|
39
39
|
* you can achieve the same effect using `setInterval()` and listening for the `migrating` event.
|
|
40
40
|
*/
|
|
41
41
|
export declare class PlatformEventManager extends EventManager {
|
|
42
|
+
#private;
|
|
42
43
|
readonly configuration: Configuration;
|
|
43
|
-
/** Websocket connection to Actor events. */
|
|
44
|
-
private eventsWs?;
|
|
45
44
|
constructor(configuration?: Configuration);
|
|
46
45
|
/**
|
|
47
46
|
* Initializes `Actor.events` event emitter by creating a connection to a websocket that provides them.
|
|
@@ -44,7 +44,7 @@ import { Configuration } from './configuration.js';
|
|
|
44
44
|
export class PlatformEventManager extends EventManager {
|
|
45
45
|
configuration;
|
|
46
46
|
/** Websocket connection to Actor events. */
|
|
47
|
-
eventsWs;
|
|
47
|
+
#eventsWs;
|
|
48
48
|
constructor(configuration = Configuration.getGlobalConfiguration()) {
|
|
49
49
|
super({
|
|
50
50
|
persistStateIntervalMillis: configuration.persistStateIntervalMillis,
|
|
@@ -69,8 +69,8 @@ export class PlatformEventManager extends EventManager {
|
|
|
69
69
|
this.createWebSocketConnection(eventsWsUrl);
|
|
70
70
|
}
|
|
71
71
|
createWebSocketConnection(eventsWsUrl) {
|
|
72
|
-
this
|
|
73
|
-
this
|
|
72
|
+
this.#eventsWs = new WebSocket(eventsWsUrl);
|
|
73
|
+
this.#eventsWs.on('message', (message) => {
|
|
74
74
|
if (!message)
|
|
75
75
|
return;
|
|
76
76
|
try {
|
|
@@ -87,15 +87,15 @@ export class PlatformEventManager extends EventManager {
|
|
|
87
87
|
this.log.exception(err, 'Cannot parse Actor event');
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
this
|
|
90
|
+
this.#eventsWs.on('error', (err) => {
|
|
91
91
|
// Don't print this error as this happens in the case of very short Actor.main().
|
|
92
92
|
if (err.message === 'WebSocket was closed before the connection was established')
|
|
93
93
|
return;
|
|
94
94
|
this.log.exception(err, 'web socket connection failed');
|
|
95
95
|
});
|
|
96
|
-
this
|
|
96
|
+
this.#eventsWs.on('close', () => {
|
|
97
97
|
this.log.debug('web socket has been closed');
|
|
98
|
-
this
|
|
98
|
+
this.#eventsWs = undefined;
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
@@ -108,6 +108,6 @@ export class PlatformEventManager extends EventManager {
|
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
await super.close();
|
|
111
|
-
this
|
|
111
|
+
this.#eventsWs?.close();
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -151,14 +151,8 @@ export interface ProxyInfo extends CoreProxyInfo {
|
|
|
151
151
|
* @category Scaling
|
|
152
152
|
*/
|
|
153
153
|
export declare class ProxyConfiguration extends CoreProxyConfiguration {
|
|
154
|
+
#private;
|
|
154
155
|
readonly configuration: Configuration;
|
|
155
|
-
private groups;
|
|
156
|
-
private countryCode?;
|
|
157
|
-
private subdivisionCode?;
|
|
158
|
-
private password?;
|
|
159
|
-
private hostname;
|
|
160
|
-
private port?;
|
|
161
|
-
private usesApifyProxy?;
|
|
162
156
|
protected readonly log: import("@apify/log").Log;
|
|
163
157
|
/**
|
|
164
158
|
* @internal
|
|
@@ -190,22 +184,22 @@ export declare class ProxyConfiguration extends CoreProxyConfiguration {
|
|
|
190
184
|
/**
|
|
191
185
|
* Returns proxy username.
|
|
192
186
|
*/
|
|
193
|
-
protected
|
|
187
|
+
protected getUsername(sessionId: string): string;
|
|
194
188
|
protected composeDefaultUrl(sessionId: string): string;
|
|
195
189
|
/**
|
|
196
190
|
* Fetch & set the proxy password from Apify API if an Apify token is provided.
|
|
197
191
|
*/
|
|
198
|
-
|
|
192
|
+
private setPasswordIfToken;
|
|
199
193
|
/**
|
|
200
194
|
* Checks whether the user has access to the proxies specified in the provided ProxyConfigurationOptions.
|
|
201
195
|
* If the check can not be made, it only prints a warning and allows the program to continue. This is to
|
|
202
196
|
* prevent program crashes caused by short downtimes of Proxy.
|
|
203
197
|
*/
|
|
204
|
-
protected
|
|
198
|
+
protected checkAccess(): Promise<boolean>;
|
|
205
199
|
/**
|
|
206
200
|
* Apify Proxy can be down for a second or a minute, but this should not crash processes.
|
|
207
201
|
*/
|
|
208
|
-
protected
|
|
202
|
+
protected fetchStatus(): Promise<ProxyStatus | undefined>;
|
|
209
203
|
/**
|
|
210
204
|
* Fetches the Apify Proxy status endpoint once, *through* the proxy, so the
|
|
211
205
|
* response reports on this exact connection (auth + man-in-the-middle).
|
|
@@ -214,16 +208,11 @@ export declare class ProxyConfiguration extends CoreProxyConfiguration {
|
|
|
214
208
|
* plus a `Proxy-Authorization` header — so no proxy-agent dependency is
|
|
215
209
|
* needed. The status endpoint (`http://proxy.apify.com`) is plain HTTP.
|
|
216
210
|
*/
|
|
217
|
-
protected
|
|
211
|
+
protected requestStatus(statusUrl: string, proxyUrl: string): Promise<ProxyStatus>;
|
|
218
212
|
/**
|
|
219
213
|
* Throws cannot combine custom proxies with Apify Proxy
|
|
220
214
|
* @internal
|
|
221
215
|
*/
|
|
222
|
-
protected
|
|
223
|
-
/**
|
|
224
|
-
* Throws cannot combine custom proxies with custom generating function
|
|
225
|
-
* @internal
|
|
226
|
-
*/
|
|
227
|
-
protected _throwCannotCombineCustomMethods(): void;
|
|
216
|
+
protected throwCannotCombineCustomWithApify(): void;
|
|
228
217
|
}
|
|
229
218
|
export {};
|