apify-client 3.0.0-beta.16 → 3.0.0-beta.18
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/apify_api_error.d.ts +4 -19
- package/dist/apify_api_error.js +10 -25
- package/dist/apify_client.d.ts +1 -1
- package/dist/apify_client.js +24 -24
- package/dist/bundle.js +12 -12
- package/dist/bundle.js.map +1 -1
- package/dist/generated/schemas.d.ts +374 -374
- package/dist/generated/schemas.js +64 -64
- package/dist/http_client.d.ts +1 -55
- package/dist/http_client.js +32 -33
- package/dist/models.d.ts +2 -3
- package/dist/resource_clients/dataset.d.ts +1 -1
- package/dist/resource_clients/dataset.js +2 -2
- package/dist/resource_clients/log.d.ts +1 -16
- package/dist/resource_clients/log.js +31 -31
- package/dist/resource_clients/request_queue.d.ts +1 -7
- package/dist/resource_clients/request_queue.js +35 -36
- package/dist/resource_clients/user.js +1 -2
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +1 -1
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/utils.d.ts +8 -27
- package/dist/utils.js +21 -68
- package/package.json +1 -1
|
@@ -74,13 +74,7 @@ export declare class LoggerActorRedirect extends Logger {
|
|
|
74
74
|
* @since Added in 2.20.0
|
|
75
75
|
*/
|
|
76
76
|
export declare class StreamedLog {
|
|
77
|
-
private
|
|
78
|
-
private streamBuffer;
|
|
79
|
-
private splitMarker;
|
|
80
|
-
private relevancyTimeLimit;
|
|
81
|
-
private logClient;
|
|
82
|
-
private streamingTask;
|
|
83
|
-
private stopLogging;
|
|
77
|
+
#private;
|
|
84
78
|
constructor(options: StreamedLogOptions);
|
|
85
79
|
/**
|
|
86
80
|
* Start log redirection.
|
|
@@ -90,15 +84,6 @@ export declare class StreamedLog {
|
|
|
90
84
|
* Stop log redirection.
|
|
91
85
|
*/
|
|
92
86
|
stop(): Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Get log stream from response and redirect it to another log.
|
|
95
|
-
*/
|
|
96
|
-
private streamLog;
|
|
97
|
-
private logStreamChunks;
|
|
98
|
-
/**
|
|
99
|
-
* Parse the buffer and log complete messages.
|
|
100
|
-
*/
|
|
101
|
-
private logBufferContent;
|
|
102
87
|
}
|
|
103
88
|
/**
|
|
104
89
|
* @since Added in 2.20.0
|
|
@@ -130,39 +130,39 @@ export class LoggerActorRedirect extends Logger {
|
|
|
130
130
|
* @since Added in 2.20.0
|
|
131
131
|
*/
|
|
132
132
|
export class StreamedLog {
|
|
133
|
-
destinationLog;
|
|
134
|
-
streamBuffer = [];
|
|
135
|
-
splitMarker = /(?:\n|^)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g;
|
|
136
|
-
relevancyTimeLimit;
|
|
137
|
-
logClient;
|
|
138
|
-
streamingTask = null;
|
|
139
|
-
stopLogging = false;
|
|
133
|
+
#destinationLog;
|
|
134
|
+
#streamBuffer = [];
|
|
135
|
+
#splitMarker = /(?:\n|^)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g;
|
|
136
|
+
#relevancyTimeLimit;
|
|
137
|
+
#logClient;
|
|
138
|
+
#streamingTask = null;
|
|
139
|
+
#stopLogging = false;
|
|
140
140
|
constructor(options) {
|
|
141
141
|
const { toLog, logClient, fromStart = true } = options;
|
|
142
|
-
this
|
|
143
|
-
this
|
|
144
|
-
this
|
|
142
|
+
this.#destinationLog = toLog;
|
|
143
|
+
this.#logClient = logClient;
|
|
144
|
+
this.#relevancyTimeLimit = fromStart ? null : new Date();
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Start log redirection.
|
|
148
148
|
*/
|
|
149
149
|
start() {
|
|
150
|
-
if (this
|
|
150
|
+
if (this.#streamingTask) {
|
|
151
151
|
throw new Error('Streaming task already active');
|
|
152
152
|
}
|
|
153
|
-
this
|
|
154
|
-
this
|
|
153
|
+
this.#stopLogging = false;
|
|
154
|
+
this.#streamingTask = this.#streamLog();
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Stop log redirection.
|
|
158
158
|
*/
|
|
159
159
|
async stop() {
|
|
160
|
-
if (!this
|
|
160
|
+
if (!this.#streamingTask) {
|
|
161
161
|
throw new Error('Streaming task is not active');
|
|
162
162
|
}
|
|
163
|
-
this
|
|
163
|
+
this.#stopLogging = true;
|
|
164
164
|
try {
|
|
165
|
-
await this
|
|
165
|
+
await this.#streamingTask;
|
|
166
166
|
}
|
|
167
167
|
catch (err) {
|
|
168
168
|
if (!(err instanceof Error && err.name === 'AbortError')) {
|
|
@@ -170,30 +170,30 @@ export class StreamedLog {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
finally {
|
|
173
|
-
this
|
|
173
|
+
this.#streamingTask = null;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
177
177
|
* Get log stream from response and redirect it to another log.
|
|
178
178
|
*/
|
|
179
|
-
async streamLog() {
|
|
179
|
+
async #streamLog() {
|
|
180
180
|
try {
|
|
181
|
-
const logStream = await this
|
|
181
|
+
const logStream = await this.#logClient.stream({ raw: true });
|
|
182
182
|
if (!logStream) {
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
|
-
const lastChunkRemainder = await this
|
|
185
|
+
const lastChunkRemainder = await this.#logStreamChunks(logStream);
|
|
186
186
|
// Process whatever is left when exiting. Maybe it is incomplete, maybe it is last log without EOL.
|
|
187
187
|
const lastMessage = Buffer.from(lastChunkRemainder).toString().trim();
|
|
188
188
|
if (lastMessage.length) {
|
|
189
|
-
this
|
|
189
|
+
this.#destinationLog.info(lastMessage);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
catch (err) {
|
|
193
193
|
log.warning(`Log redirection stopped due to error`, err);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
async logStreamChunks(logStream) {
|
|
196
|
+
async #logStreamChunks(logStream) {
|
|
197
197
|
// Chunk may be incomplete. Keep remainder for next chunk.
|
|
198
198
|
let previousChunkRemainder = new Uint8Array();
|
|
199
199
|
for await (const chunk of logStream) {
|
|
@@ -205,10 +205,10 @@ export class StreamedLog {
|
|
|
205
205
|
const lastCompleteMessageIndex = chunkWithPreviousRemainder.lastIndexOf(0x0a);
|
|
206
206
|
previousChunkRemainder = chunkWithPreviousRemainder.slice(lastCompleteMessageIndex);
|
|
207
207
|
// Push complete part of the chunk to the buffer
|
|
208
|
-
this
|
|
209
|
-
this
|
|
208
|
+
this.#streamBuffer.push(Buffer.from(chunkWithPreviousRemainder.slice(0, lastCompleteMessageIndex)));
|
|
209
|
+
this.#logBufferContent();
|
|
210
210
|
// Keep processing the new data until stopped
|
|
211
|
-
if (this
|
|
211
|
+
if (this.#stopLogging) {
|
|
212
212
|
break;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -217,26 +217,26 @@ export class StreamedLog {
|
|
|
217
217
|
/**
|
|
218
218
|
* Parse the buffer and log complete messages.
|
|
219
219
|
*/
|
|
220
|
-
logBufferContent() {
|
|
221
|
-
const allParts = Buffer.concat(this
|
|
220
|
+
#logBufferContent() {
|
|
221
|
+
const allParts = Buffer.concat(this.#streamBuffer).toString().split(this.#splitMarker).slice(1);
|
|
222
222
|
// Parse the buffer parts into complete messages
|
|
223
223
|
const messageMarkers = allParts.filter((_, i) => i % 2 === 0);
|
|
224
224
|
const messageContents = allParts.filter((_, i) => i % 2 !== 0);
|
|
225
|
-
this
|
|
225
|
+
this.#streamBuffer = [];
|
|
226
226
|
messageMarkers.forEach((marker, index) => {
|
|
227
227
|
const decodedMarker = marker;
|
|
228
228
|
const decodedContent = messageContents[index];
|
|
229
|
-
if (this
|
|
229
|
+
if (this.#relevancyTimeLimit) {
|
|
230
230
|
// Log only relevant messages. Ignore too old log messages.
|
|
231
231
|
const logTime = new Date(decodedMarker);
|
|
232
|
-
if (logTime < this
|
|
232
|
+
if (logTime < this.#relevancyTimeLimit) {
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
const message = decodedMarker + decodedContent;
|
|
237
237
|
// Original log level information is not available. Log all on info level. Log level could be guessed for
|
|
238
238
|
// some logs, but for any multiline logs such guess would be probably correct only for the first line.
|
|
239
|
-
this
|
|
239
|
+
this.#destinationLog.info(message.trim());
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
}
|
|
@@ -35,17 +35,11 @@ export type { AllowedHttpMethods, RequestQueue, RequestQueueClientAddRequestResu
|
|
|
35
35
|
* @see https://docs.apify.com/platform/storage/request-queue
|
|
36
36
|
*/
|
|
37
37
|
export declare class RequestQueueClient extends ResourceClient {
|
|
38
|
-
private
|
|
39
|
-
private timeoutSecs?;
|
|
38
|
+
#private;
|
|
40
39
|
/**
|
|
41
40
|
* @hidden
|
|
42
41
|
*/
|
|
43
42
|
constructor(options: ApiClientSubResourceOptions, userOptions?: RequestQueueUserOptions);
|
|
44
|
-
/**
|
|
45
|
-
* Picks the timeout of a request: an explicit per-call `timeoutSecs` as is, otherwise the method's default
|
|
46
|
-
* tier, capped at the queue-wide `timeoutSecs` when one was given.
|
|
47
|
-
*/
|
|
48
|
-
private resolveTimeout;
|
|
49
43
|
/**
|
|
50
44
|
* Gets the Request queue object from the Apify API.
|
|
51
45
|
*
|
|
@@ -5,7 +5,7 @@ import { ResourceClient } from '../base/resource_client.js';
|
|
|
5
5
|
import { ResponseValidationError } from '../response_validation_error.js';
|
|
6
6
|
import * as schemas from '../schemas.js';
|
|
7
7
|
import { optionalTimeoutSchema, timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
8
|
-
import { anyObjectSchema,
|
|
8
|
+
import { anyObjectSchema, catchNotFoundOrThrow, isNonArrayObject, parseArgument, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
|
|
9
9
|
const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
|
|
10
10
|
const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
|
|
11
11
|
const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
|
|
@@ -82,8 +82,8 @@ const paginateRequestsOptionsSchema = z.strictObject({
|
|
|
82
82
|
* @see https://docs.apify.com/platform/storage/request-queue
|
|
83
83
|
*/
|
|
84
84
|
export class RequestQueueClient extends ResourceClient {
|
|
85
|
-
clientKey;
|
|
86
|
-
timeoutSecs;
|
|
85
|
+
#clientKey;
|
|
86
|
+
#timeoutSecs;
|
|
87
87
|
/**
|
|
88
88
|
* @hidden
|
|
89
89
|
*/
|
|
@@ -92,20 +92,20 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
92
92
|
resourcePath: 'request-queues',
|
|
93
93
|
...options,
|
|
94
94
|
});
|
|
95
|
-
this
|
|
96
|
-
this
|
|
95
|
+
this.#clientKey = userOptions.clientKey;
|
|
96
|
+
this.#timeoutSecs = userOptions.timeoutSecs;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Picks the timeout of a request: an explicit per-call `timeoutSecs` as is, otherwise the method's default
|
|
100
100
|
* tier, capped at the queue-wide `timeoutSecs` when one was given.
|
|
101
101
|
*/
|
|
102
|
-
resolveTimeout(timeoutSecs, defaultTier) {
|
|
102
|
+
#resolveTimeout(timeoutSecs, defaultTier) {
|
|
103
103
|
if (timeoutSecs !== undefined)
|
|
104
104
|
return timeoutSecs;
|
|
105
|
-
if (this
|
|
105
|
+
if (this.#timeoutSecs === undefined)
|
|
106
106
|
return defaultTier;
|
|
107
107
|
const tierSecs = this.httpClient.timeoutMillis[defaultTier] / 1000;
|
|
108
|
-
return tierSecs <= this
|
|
108
|
+
return tierSecs <= this.#timeoutSecs ? defaultTier : this.#timeoutSecs;
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* Gets the Request queue object from the Apify API.
|
|
@@ -117,7 +117,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
117
117
|
*/
|
|
118
118
|
async get(options = {}) {
|
|
119
119
|
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
120
|
-
return this.getResource(schemas.RequestQueue(), {}, this
|
|
120
|
+
return this.getResource(schemas.RequestQueue(), {}, this.#resolveTimeout(timeoutSecs, 'short'));
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* Updates the Request queue with specified fields.
|
|
@@ -131,7 +131,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
131
131
|
async update(newFields, options = {}) {
|
|
132
132
|
parseArgument(newFields, anyObjectSchema);
|
|
133
133
|
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
134
|
-
return this.updateResource(schemas.RequestQueue(), newFields, this
|
|
134
|
+
return this.updateResource(schemas.RequestQueue(), newFields, this.#resolveTimeout(timeoutSecs, 'short'));
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Deletes the Request queue.
|
|
@@ -142,7 +142,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
142
142
|
*/
|
|
143
143
|
async delete(options = {}) {
|
|
144
144
|
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
145
|
-
return this.deleteResource(this
|
|
145
|
+
return this.deleteResource(this.#resolveTimeout(timeoutSecs, 'short'));
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Lists requests from the beginning of the queue (head).
|
|
@@ -161,10 +161,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
161
161
|
const response = await this.httpClient.call({
|
|
162
162
|
url: this.buildUrl('head'),
|
|
163
163
|
method: 'GET',
|
|
164
|
-
timeoutSecs: this
|
|
164
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
165
165
|
params: this.buildParams({
|
|
166
166
|
limit: parsed.limit,
|
|
167
|
-
clientKey: this
|
|
167
|
+
clientKey: this.#clientKey,
|
|
168
168
|
}),
|
|
169
169
|
});
|
|
170
170
|
return parseResponse(response, schemas.RequestQueueHead());
|
|
@@ -208,11 +208,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
208
208
|
const response = await this.httpClient.call({
|
|
209
209
|
url: this.buildUrl('head/lock'),
|
|
210
210
|
method: 'POST',
|
|
211
|
-
timeoutSecs: this
|
|
211
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
212
212
|
params: this.buildParams({
|
|
213
213
|
limit: parsed.limit,
|
|
214
214
|
lockSecs: parsed.lockSecs,
|
|
215
|
-
clientKey: this
|
|
215
|
+
clientKey: this.#clientKey,
|
|
216
216
|
}),
|
|
217
217
|
});
|
|
218
218
|
return parseResponse(response, schemas.LockedRequestQueueHead());
|
|
@@ -262,11 +262,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
262
262
|
const response = await this.httpClient.call({
|
|
263
263
|
url: this.buildUrl('requests'),
|
|
264
264
|
method: 'POST',
|
|
265
|
-
timeoutSecs: this
|
|
265
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
266
266
|
data: request,
|
|
267
267
|
params: this.buildParams({
|
|
268
268
|
forefront: parsed.forefront,
|
|
269
|
-
clientKey: this
|
|
269
|
+
clientKey: this.#clientKey,
|
|
270
270
|
}),
|
|
271
271
|
});
|
|
272
272
|
return parseResponse(response, schemas.RequestRegistration());
|
|
@@ -282,11 +282,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
282
282
|
const response = await this.httpClient.call({
|
|
283
283
|
url: this.buildUrl('requests/batch'),
|
|
284
284
|
method: 'POST',
|
|
285
|
-
timeoutSecs: this
|
|
285
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
286
286
|
data: requests,
|
|
287
287
|
params: this.buildParams({
|
|
288
288
|
forefront: parsed.forefront,
|
|
289
|
-
clientKey: this
|
|
289
|
+
clientKey: this.#clientKey,
|
|
290
290
|
}),
|
|
291
291
|
});
|
|
292
292
|
return parseResponse(response, schemas.BatchAddResult());
|
|
@@ -342,8 +342,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
342
342
|
setTimeout(resolve, delayMillis);
|
|
343
343
|
});
|
|
344
344
|
}
|
|
345
|
-
|
|
346
|
-
return cast(parseDateFields(result));
|
|
345
|
+
return { processedRequests, unprocessedRequests };
|
|
347
346
|
}
|
|
348
347
|
/**
|
|
349
348
|
* Adds multiple requests to the queue in a single operation.
|
|
@@ -444,10 +443,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
444
443
|
const response = await this.httpClient.call({
|
|
445
444
|
url: this.buildUrl('requests/batch'),
|
|
446
445
|
method: 'DELETE',
|
|
447
|
-
timeoutSecs: this
|
|
446
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'short'),
|
|
448
447
|
data: requests,
|
|
449
448
|
params: this.buildParams({
|
|
450
|
-
clientKey: this
|
|
449
|
+
clientKey: this.#clientKey,
|
|
451
450
|
}),
|
|
452
451
|
});
|
|
453
452
|
return parseResponse(response, schemas.BatchDeleteResult());
|
|
@@ -467,7 +466,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
467
466
|
const requestOpts = {
|
|
468
467
|
url: this.buildUrl(['requests', id]),
|
|
469
468
|
method: 'GET',
|
|
470
|
-
timeoutSecs: this
|
|
469
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'short'),
|
|
471
470
|
params: this.buildParams(),
|
|
472
471
|
};
|
|
473
472
|
try {
|
|
@@ -495,11 +494,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
495
494
|
const response = await this.httpClient.call({
|
|
496
495
|
url: this.buildUrl(['requests', request.id]),
|
|
497
496
|
method: 'PUT',
|
|
498
|
-
timeoutSecs: this
|
|
497
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
499
498
|
data: request,
|
|
500
499
|
params: this.buildParams({
|
|
501
500
|
forefront: parsed.forefront,
|
|
502
|
-
clientKey: this
|
|
501
|
+
clientKey: this.#clientKey,
|
|
503
502
|
}),
|
|
504
503
|
});
|
|
505
504
|
return parseResponse(response, schemas.RequestRegistration());
|
|
@@ -517,9 +516,9 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
517
516
|
await this.httpClient.call({
|
|
518
517
|
url: this.buildUrl(['requests', id]),
|
|
519
518
|
method: 'DELETE',
|
|
520
|
-
timeoutSecs: this
|
|
519
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'short'),
|
|
521
520
|
params: this.buildParams({
|
|
522
|
-
clientKey: this
|
|
521
|
+
clientKey: this.#clientKey,
|
|
523
522
|
}),
|
|
524
523
|
});
|
|
525
524
|
}
|
|
@@ -555,11 +554,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
555
554
|
const response = await this.httpClient.call({
|
|
556
555
|
url: this.buildUrl(['requests', id, 'lock']),
|
|
557
556
|
method: 'PUT',
|
|
558
|
-
timeoutSecs: this
|
|
557
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
559
558
|
params: this.buildParams({
|
|
560
559
|
forefront: parsed.forefront,
|
|
561
560
|
lockSecs: parsed.lockSecs,
|
|
562
|
-
clientKey: this
|
|
561
|
+
clientKey: this.#clientKey,
|
|
563
562
|
}),
|
|
564
563
|
});
|
|
565
564
|
return parseResponse(response, schemas.RequestLockInfo());
|
|
@@ -583,10 +582,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
583
582
|
await this.httpClient.call({
|
|
584
583
|
url: this.buildUrl(['requests', id, 'lock']),
|
|
585
584
|
method: 'DELETE',
|
|
586
|
-
timeoutSecs: this
|
|
585
|
+
timeoutSecs: this.#resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
587
586
|
params: this.buildParams({
|
|
588
587
|
forefront: parsed.forefront,
|
|
589
|
-
clientKey: this
|
|
588
|
+
clientKey: this.#clientKey,
|
|
590
589
|
}),
|
|
591
590
|
});
|
|
592
591
|
}
|
|
@@ -605,7 +604,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
605
604
|
listRequests(options = {}) {
|
|
606
605
|
// `timeoutSecs` times every page request; it is not an API parameter, so it must not reach the query string.
|
|
607
606
|
const { timeoutSecs, ...parsed } = parseArgument(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
|
|
608
|
-
const pageTimeout = this
|
|
607
|
+
const pageTimeout = this.#resolveTimeout(timeoutSecs, 'medium');
|
|
609
608
|
const getPaginatedList = async (rqListOptions = {}) => {
|
|
610
609
|
const response = await this.httpClient.call({
|
|
611
610
|
url: this.buildUrl('requests'),
|
|
@@ -614,7 +613,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
614
613
|
params: this.buildParams({
|
|
615
614
|
...rqListOptions,
|
|
616
615
|
filter: rqListOptions.filter ? rqListOptions.filter.join(',') : undefined,
|
|
617
|
-
clientKey: this
|
|
616
|
+
clientKey: this.#clientKey,
|
|
618
617
|
}),
|
|
619
618
|
});
|
|
620
619
|
return parseResponse(response, schemas.ListOfRequests());
|
|
@@ -663,9 +662,9 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
663
662
|
const response = await this.httpClient.call({
|
|
664
663
|
url: this.buildUrl('requests/unlock'),
|
|
665
664
|
method: 'POST',
|
|
666
|
-
timeoutSecs: this
|
|
665
|
+
timeoutSecs: this.#resolveTimeout(timeoutSecs, 'long'),
|
|
667
666
|
params: this.buildParams({
|
|
668
|
-
clientKey: this
|
|
667
|
+
clientKey: this.#clientKey,
|
|
669
668
|
}),
|
|
670
669
|
});
|
|
671
670
|
return parseResponse(response, schemas.UnlockRequestsResult());
|
|
@@ -69,8 +69,7 @@ export class UserClient extends ResourceClient {
|
|
|
69
69
|
params: this.buildParams(),
|
|
70
70
|
timeoutSecs,
|
|
71
71
|
});
|
|
72
|
-
|
|
73
|
-
return parseResponse(response, schemas.MonthlyUsage(), (key) => key === 'date');
|
|
72
|
+
return parseResponse(response, schemas.MonthlyUsage());
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
76
75
|
* Retrieves the user's account and usage limits.
|
package/dist/schemas.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* documented deviation never sends a resource client reaching into `./generated` directly. An override
|
|
7
7
|
* declared here shadows the generated export of the same name and takes the same form, a `lazySchema()` thunk
|
|
8
8
|
* built on the generated schema it replaces. Every schema that embeds an overridden one has to be rebuilt on
|
|
9
|
-
* top of it, and `spec_guards.ts` checks that each override still
|
|
9
|
+
* top of it, and `spec_guards.ts` checks that each override still produces what the specification describes,
|
|
10
10
|
* so one cannot narrow by accident.
|
|
11
11
|
*
|
|
12
12
|
* Spec gaps need no override: the generated objects are loose, so a field the specification omits passes
|
package/dist/schemas.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* documented deviation never sends a resource client reaching into `./generated` directly. An override
|
|
7
7
|
* declared here shadows the generated export of the same name and takes the same form, a `lazySchema()` thunk
|
|
8
8
|
* built on the generated schema it replaces. Every schema that embeds an overridden one has to be rebuilt on
|
|
9
|
-
* top of it, and `spec_guards.ts` checks that each override still
|
|
9
|
+
* top of it, and `spec_guards.ts` checks that each override still produces what the specification describes,
|
|
10
10
|
* so one cannot narrow by accident.
|
|
11
11
|
*
|
|
12
12
|
* Spec gaps need no override: the generated objects are loose, so a field the specification omits passes
|
package/dist/statistics.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare class Statistics {
|
|
2
|
+
#private;
|
|
2
3
|
/**
|
|
3
4
|
* Number of Apify client function calls
|
|
4
5
|
*/
|
|
@@ -13,10 +14,4 @@ export declare class Statistics {
|
|
|
13
14
|
*/
|
|
14
15
|
rateLimitErrors: number[];
|
|
15
16
|
addRateLimitError(attempt: number): void;
|
|
16
|
-
/**
|
|
17
|
-
* Removes the necessity to pre-initialize array with correct
|
|
18
|
-
* number of zeroes by dynamically filling the empty indexes
|
|
19
|
-
* when necessary.
|
|
20
|
-
*/
|
|
21
|
-
private _fillBlanksWithZeroes;
|
|
22
17
|
}
|
package/dist/statistics.js
CHANGED
|
@@ -20,7 +20,7 @@ export class Statistics {
|
|
|
20
20
|
// attempt is never 0,
|
|
21
21
|
// but we don't want index 0 empty
|
|
22
22
|
const index = attempt - 1;
|
|
23
|
-
this
|
|
23
|
+
this.#fillBlanksWithZeroes(index);
|
|
24
24
|
this.rateLimitErrors[index]++;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -28,7 +28,7 @@ export class Statistics {
|
|
|
28
28
|
* number of zeroes by dynamically filling the empty indexes
|
|
29
29
|
* when necessary.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
#fillBlanksWithZeroes(inclusiveIndex) {
|
|
32
32
|
if (this.rateLimitErrors.length <= inclusiveIndex) {
|
|
33
33
|
for (let k = 0; k <= inclusiveIndex; k++) {
|
|
34
34
|
if (typeof this.rateLimitErrors[k] !== 'number') {
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TypedArray } from 'type-fest';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import type { ApifyApiError } from './apify_api_error.js';
|
|
5
5
|
import { parseArgument } from '@apify/validations';
|
|
@@ -28,16 +28,16 @@ export interface MaybeData<R> {
|
|
|
28
28
|
data?: R;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
31
|
+
* Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope and validates the
|
|
32
|
+
* result against `schema`, one of the schemas generated from the OpenAPI specification. The validated copy is what
|
|
33
|
+
* callers get, so it is the schema's output -- unknown fields and unknown enum values included, since the schemas let
|
|
34
|
+
* both through, date-time fields turned into `Date` objects, and URL fields normalized, since `z.url()` hands back the
|
|
35
|
+
* parsed URL's serialization.
|
|
36
36
|
*
|
|
37
37
|
* Throws {@link ResponseValidationError} when the response does not match the specification.
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
|
40
|
-
export declare function parseResponse<R>(response: ApifyResponse, schema: z.ZodType
|
|
40
|
+
export declare function parseResponse<R>(response: ApifyResponse, schema: z.ZodType): R;
|
|
41
41
|
/**
|
|
42
42
|
* Returns object's 'data' property or throws if parameter is not an object,
|
|
43
43
|
* or an object without a 'data' property.
|
|
@@ -55,22 +55,6 @@ export declare function catchNotFoundOrThrow(err: ApifyApiError): void;
|
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
57
|
export declare function catchNotFoundForResourceOrThrow(err: ApifyApiError, resourceId: string | undefined): void;
|
|
58
|
-
type ReturnJsonValue = string | number | boolean | null | Date | ReturnJsonObject | ReturnJsonArray;
|
|
59
|
-
type ReturnJsonObject = {
|
|
60
|
-
[Key in string]?: ReturnJsonValue;
|
|
61
|
-
};
|
|
62
|
-
type ReturnJsonArray = ReturnJsonValue[];
|
|
63
|
-
/**
|
|
64
|
-
* Traverses JSON structure and converts fields that end with "At" to a Date object (fields such as "modifiedAt" or
|
|
65
|
-
* "createdAt").
|
|
66
|
-
*
|
|
67
|
-
* If you want parse other fields as well, you can provide a custom matcher function shouldParseField(). This
|
|
68
|
-
* admittedly awkward approach allows this function to be reused for various purposes without introducing potential
|
|
69
|
-
* breaking changes.
|
|
70
|
-
*
|
|
71
|
-
* If the field cannot be converted to Date, it is left as is.
|
|
72
|
-
*/
|
|
73
|
-
export declare function parseDateFields(input: JsonValue, shouldParseField?: ((key: string) => boolean) | null, depth?: number): ReturnJsonValue;
|
|
74
58
|
/**
|
|
75
59
|
* Helper function that converts array of webhooks to base64 string
|
|
76
60
|
*/
|
|
@@ -108,10 +92,7 @@ export declare function getVersionData(): {
|
|
|
108
92
|
* Helper class to create async iterators from paginated list endpoints.
|
|
109
93
|
*/
|
|
110
94
|
export declare class RequestQueuePaginationIterator {
|
|
111
|
-
private
|
|
112
|
-
private readonly getPage;
|
|
113
|
-
private readonly limit?;
|
|
114
|
-
private readonly cursor?;
|
|
95
|
+
#private;
|
|
115
96
|
constructor(options: RequestQueuePaginationIteratorOptions);
|
|
116
97
|
[Symbol.asyncIterator](): AsyncIterator<RequestQueueClientListRequestsResult>;
|
|
117
98
|
}
|