apify-client 3.0.0-beta.11 → 3.0.0-beta.111
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 +16 -2
- package/dist/apify_api_error.d.ts +13 -27
- package/dist/apify_api_error.js +33 -23
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -36
- package/dist/base/resource_client.d.ts +13 -8
- package/dist/base/resource_client.js +60 -34
- package/dist/base/resource_collection_client.d.ts +12 -4
- package/dist/base/resource_collection_client.js +34 -11
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +27 -22
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +3109 -987
- package/dist/generated/schemas.d.ts +2563 -957
- package/dist/generated/schemas.js +585 -229
- package/dist/http_clients/axios.d.ts +63 -0
- package/dist/http_clients/axios.js +129 -0
- package/dist/http_clients/base.d.ts +397 -0
- package/dist/http_clients/base.js +656 -0
- package/dist/http_clients/index.d.ts +4 -0
- package/dist/http_clients/index.js +2 -0
- package/dist/http_compressors/base.d.ts +40 -0
- package/dist/http_compressors/base.js +9 -0
- package/dist/http_compressors/brotli.d.ts +33 -0
- package/dist/http_compressors/brotli.js +39 -0
- package/dist/http_compressors/gzip.d.ts +33 -0
- package/dist/http_compressors/gzip.js +39 -0
- package/dist/http_compressors/index.d.ts +8 -0
- package/dist/http_compressors/index.js +3 -0
- package/dist/http_compressors/resolve.d.ts +24 -0
- package/dist/http_compressors/resolve.js +30 -0
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/models.d.ts +177 -240
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +104 -34
- package/dist/resource_clients/actor.js +129 -55
- package/dist/resource_clients/actor_collection.d.ts +15 -11
- package/dist/resource_clients/actor_collection.js +9 -3
- package/dist/resource_clients/actor_env_var.d.ts +11 -4
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_server.d.ts +150 -0
- package/dist/resource_clients/actor_server.js +199 -0
- package/dist/resource_clients/actor_version.d.ts +18 -6
- package/dist/resource_clients/actor_version.js +18 -8
- package/dist/resource_clients/actor_version_collection.d.ts +9 -4
- package/dist/resource_clients/actor_version_collection.js +11 -4
- package/dist/resource_clients/build.d.ts +18 -7
- package/dist/resource_clients/build.js +33 -15
- package/dist/resource_clients/build_collection.d.ts +7 -5
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +83 -36
- package/dist/resource_clients/dataset.js +103 -109
- package/dist/resource_clients/dataset_collection.d.ts +10 -6
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +101 -27
- package/dist/resource_clients/key_value_store.js +132 -50
- package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +38 -21
- package/dist/resource_clients/log.js +139 -63
- package/dist/resource_clients/request_queue.d.ts +77 -31
- package/dist/resource_clients/request_queue.js +178 -93
- package/dist/resource_clients/request_queue_collection.d.ts +9 -5
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +124 -30
- package/dist/resource_clients/run.js +188 -51
- package/dist/resource_clients/run_collection.d.ts +5 -3
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +15 -6
- package/dist/resource_clients/schedule.js +25 -10
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +6 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +35 -12
- package/dist/resource_clients/task.js +75 -35
- package/dist/resource_clients/task_collection.d.ts +9 -5
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +16 -7
- package/dist/resource_clients/user.js +34 -16
- package/dist/resource_clients/webhook.d.ts +16 -7
- package/dist/resource_clients/webhook.js +25 -10
- package/dist/resource_clients/webhook_collection.d.ts +8 -4
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +87 -0
- package/dist/runtime/types.d.ts +60 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +21 -0
- package/dist/schemas.d.ts +370 -4
- package/dist/schemas.js +26 -4
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/utils.d.ts +87 -61
- package/dist/utils.js +208 -162
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +41 -38
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -255
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -105
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import c from 'ansi-colors';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import log, { Logger, LogLevel } from '@apify/log';
|
|
3
4
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
-
import {
|
|
5
|
+
import { timeoutOptionsShape } from '../timeouts.js';
|
|
6
|
+
import { cast, catchNotFoundForResourceOrThrow, concatBytes, parseArgument, sleep } from '../utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pause before the first reopen of a log stream that ended before the run logged anything. Each further reopen doubles
|
|
9
|
+
* the pause up to `EMPTY_LOG_STREAM_MAX_RETRY_MILLIS`, which bounds the request rate while a run waits long to start,
|
|
10
|
+
* for example for free memory.
|
|
11
|
+
*/
|
|
12
|
+
const EMPTY_LOG_STREAM_RETRY_MILLIS = 500;
|
|
13
|
+
/** Upper bound on the pause between reopens of an empty log stream. */
|
|
14
|
+
const EMPTY_LOG_STREAM_MAX_RETRY_MILLIS = 5_000;
|
|
15
|
+
const logOptionsSchema = z.strictObject({ raw: z.boolean().optional(), ...timeoutOptionsShape });
|
|
16
|
+
const logGetOptionsSchema = logOptionsSchema.extend({ buffer: z.boolean().optional() });
|
|
17
|
+
/** How long `StreamedLog.stop()` waits for lines already in flight before aborting the log stream request. */
|
|
18
|
+
const STOP_GRACE_MILLIS = 1000;
|
|
5
19
|
/**
|
|
6
20
|
* Client for accessing Actor run or build logs.
|
|
7
21
|
*
|
|
@@ -17,6 +31,9 @@ import { cast, catchNotFoundForResourceOrThrow } from '../utils.js';
|
|
|
17
31
|
* const log = await runClient.log().get();
|
|
18
32
|
* console.log(log);
|
|
19
33
|
*
|
|
34
|
+
* // Get the log content as raw bytes
|
|
35
|
+
* const logBuffer = await runClient.log().get({ buffer: true });
|
|
36
|
+
*
|
|
20
37
|
* // Stream the log in real-time
|
|
21
38
|
* const stream = await runClient.log().stream();
|
|
22
39
|
* stream.on('line', (line) => console.log(line));
|
|
@@ -34,21 +51,17 @@ export class LogClient extends ResourceClient {
|
|
|
34
51
|
...options,
|
|
35
52
|
});
|
|
36
53
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves the log as a string.
|
|
39
|
-
*
|
|
40
|
-
* @param options - Log retrieval options.
|
|
41
|
-
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
42
|
-
* @returns The log content as a string, or `undefined` if it does not exist. A chained client such as
|
|
43
|
-
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
44
|
-
* @see https://docs.apify.com/api/v2/log-get
|
|
45
|
-
*/
|
|
46
54
|
async get(options = {}) {
|
|
55
|
+
const { timeoutSecs = 'long', signal, buffer, ...params } = parseArgument(options, logGetOptionsSchema, 'LogGetOptions');
|
|
47
56
|
const requestOpts = {
|
|
48
|
-
url: this.
|
|
57
|
+
url: this.buildUrl(),
|
|
49
58
|
method: 'GET',
|
|
50
|
-
params: this.
|
|
59
|
+
params: this.buildParams(params),
|
|
60
|
+
timeoutSecs,
|
|
61
|
+
signal,
|
|
51
62
|
};
|
|
63
|
+
if (buffer)
|
|
64
|
+
requestOpts.responseType = 'buffer';
|
|
52
65
|
try {
|
|
53
66
|
const response = await this.httpClient.call(requestOpts);
|
|
54
67
|
return cast(response.data);
|
|
@@ -63,20 +76,24 @@ export class LogClient extends ResourceClient {
|
|
|
63
76
|
*
|
|
64
77
|
* @param options - Log retrieval options.
|
|
65
78
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
79
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
66
80
|
* @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
|
|
67
81
|
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
68
82
|
* @see https://docs.apify.com/api/v2/log-get
|
|
69
83
|
*/
|
|
70
84
|
async stream(options = {}) {
|
|
85
|
+
const { timeoutSecs = 'long', signal, raw } = parseArgument(options, logOptionsSchema, 'LogOptions');
|
|
71
86
|
const params = {
|
|
72
87
|
stream: true,
|
|
73
|
-
raw
|
|
88
|
+
raw,
|
|
74
89
|
};
|
|
75
90
|
const requestOpts = {
|
|
76
|
-
url: this.
|
|
91
|
+
url: this.buildUrl(),
|
|
77
92
|
method: 'GET',
|
|
78
|
-
params: this.
|
|
93
|
+
params: this.buildParams(params),
|
|
79
94
|
responseType: 'stream',
|
|
95
|
+
timeoutSecs,
|
|
96
|
+
signal,
|
|
80
97
|
};
|
|
81
98
|
try {
|
|
82
99
|
const response = await this.httpClient.call(requestOpts);
|
|
@@ -121,39 +138,50 @@ export class LoggerActorRedirect extends Logger {
|
|
|
121
138
|
* @since Added in 2.20.0
|
|
122
139
|
*/
|
|
123
140
|
export class StreamedLog {
|
|
124
|
-
destinationLog;
|
|
125
|
-
streamBuffer = [];
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
#destinationLog;
|
|
142
|
+
#streamBuffer = [];
|
|
143
|
+
#decoder = new TextDecoder();
|
|
144
|
+
#splitMarker = /(?:\n|^)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g;
|
|
145
|
+
#relevancyTimeLimit;
|
|
146
|
+
#logClient;
|
|
147
|
+
#signal;
|
|
148
|
+
#streamingTask = null;
|
|
149
|
+
#stopLogging = false;
|
|
150
|
+
#stopController = new AbortController();
|
|
151
|
+
#wakeController = new AbortController();
|
|
131
152
|
constructor(options) {
|
|
132
|
-
const { toLog, logClient, fromStart = true } = options;
|
|
133
|
-
this
|
|
134
|
-
this
|
|
135
|
-
this
|
|
153
|
+
const { toLog, logClient, fromStart = true, signal } = options;
|
|
154
|
+
this.#destinationLog = toLog;
|
|
155
|
+
this.#logClient = logClient;
|
|
156
|
+
this.#signal = signal;
|
|
157
|
+
this.#relevancyTimeLimit = fromStart ? null : new Date();
|
|
136
158
|
}
|
|
137
159
|
/**
|
|
138
160
|
* Start log redirection.
|
|
139
161
|
*/
|
|
140
162
|
start() {
|
|
141
|
-
if (this
|
|
163
|
+
if (this.#streamingTask) {
|
|
142
164
|
throw new Error('Streaming task already active');
|
|
143
165
|
}
|
|
144
|
-
this
|
|
145
|
-
this
|
|
166
|
+
this.#stopLogging = false;
|
|
167
|
+
this.#stopController = new AbortController();
|
|
168
|
+
this.#wakeController = new AbortController();
|
|
169
|
+
this.#streamingTask = this.#streamLog();
|
|
146
170
|
}
|
|
147
171
|
/**
|
|
148
|
-
* Stop log redirection.
|
|
172
|
+
* Stop log redirection. Waits up to one second for lines already in flight, then aborts the log stream request. If
|
|
173
|
+
* no stream has delivered anything yet, reads the whole log in one request instead.
|
|
149
174
|
*/
|
|
150
175
|
async stop() {
|
|
151
|
-
if (!this
|
|
176
|
+
if (!this.#streamingTask) {
|
|
152
177
|
throw new Error('Streaming task is not active');
|
|
153
178
|
}
|
|
154
|
-
this
|
|
179
|
+
this.#stopLogging = true;
|
|
180
|
+
this.#wakeController.abort();
|
|
181
|
+
const stopController = this.#stopController;
|
|
182
|
+
const abortTimeout = setTimeout(() => stopController.abort(), STOP_GRACE_MILLIS);
|
|
155
183
|
try {
|
|
156
|
-
await this
|
|
184
|
+
await this.#streamingTask;
|
|
157
185
|
}
|
|
158
186
|
catch (err) {
|
|
159
187
|
if (!(err instanceof Error && err.name === 'AbortError')) {
|
|
@@ -161,73 +189,121 @@ export class StreamedLog {
|
|
|
161
189
|
}
|
|
162
190
|
}
|
|
163
191
|
finally {
|
|
164
|
-
|
|
192
|
+
clearTimeout(abortTimeout);
|
|
193
|
+
this.#streamingTask = null;
|
|
165
194
|
}
|
|
166
195
|
}
|
|
167
196
|
/**
|
|
168
197
|
* Get log stream from response and redirect it to another log.
|
|
169
198
|
*/
|
|
170
|
-
async streamLog() {
|
|
199
|
+
async #streamLog() {
|
|
200
|
+
const signal = this.#signal
|
|
201
|
+
? AbortSignal.any([this.#signal, this.#stopController.signal])
|
|
202
|
+
: this.#stopController.signal;
|
|
171
203
|
try {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
let lastChunkRemainder;
|
|
205
|
+
let retryMillis = EMPTY_LOG_STREAM_RETRY_MILLIS;
|
|
206
|
+
// The API serves the log of a run that has not logged anything yet as an empty stream that ends at once,
|
|
207
|
+
// so reopen it until the first bytes arrive. If stopped before any bytes arrive, fetch it in one request.
|
|
208
|
+
while (!lastChunkRemainder) {
|
|
209
|
+
if (this.#stopLogging) {
|
|
210
|
+
// `signal` is aborted once the stop grace period ends, which would cut this read short.
|
|
211
|
+
const logContent = await this.#logClient.get({ raw: true, signal: this.#signal });
|
|
212
|
+
lastChunkRemainder = await this.#logStreamChunks([new TextEncoder().encode(logContent ?? '')], signal);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
let logStream;
|
|
216
|
+
try {
|
|
217
|
+
logStream = await this.#logClient.stream({ raw: true, signal });
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
// The stop grace period ended while the stream was connecting, so read the log in one request.
|
|
221
|
+
if (this.#stopLogging && !this.#signal?.aborted)
|
|
222
|
+
continue;
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
if (!logStream) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// A stream opened during stop() would be cut after its first chunk, so read the log in one request.
|
|
229
|
+
if (this.#stopLogging) {
|
|
230
|
+
logStream.destroy();
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
lastChunkRemainder = await this.#logStreamChunks(logStream, signal);
|
|
234
|
+
if (!lastChunkRemainder) {
|
|
235
|
+
await sleep(retryMillis, AbortSignal.any([signal, this.#wakeController.signal]));
|
|
236
|
+
retryMillis = Math.min(retryMillis * 2, EMPTY_LOG_STREAM_MAX_RETRY_MILLIS);
|
|
237
|
+
}
|
|
175
238
|
}
|
|
176
|
-
const lastChunkRemainder = await this.logStreamChunks(logStream);
|
|
177
239
|
// Process whatever is left when exiting. Maybe it is incomplete, maybe it is last log without EOL.
|
|
178
|
-
const lastMessage =
|
|
240
|
+
const lastMessage = this.#decoder.decode(lastChunkRemainder).trim();
|
|
179
241
|
if (lastMessage.length) {
|
|
180
|
-
this
|
|
242
|
+
this.#destinationLog.info(lastMessage);
|
|
181
243
|
}
|
|
182
244
|
}
|
|
183
245
|
catch (err) {
|
|
246
|
+
if (signal.aborted)
|
|
247
|
+
return;
|
|
184
248
|
log.warning(`Log redirection stopped due to error`, err);
|
|
185
249
|
}
|
|
186
250
|
}
|
|
187
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Redirect every complete message in the chunks and return the incomplete rest, or `undefined` when there were no
|
|
253
|
+
* chunks at all.
|
|
254
|
+
*/
|
|
255
|
+
async #logStreamChunks(logStream, signal) {
|
|
188
256
|
// Chunk may be incomplete. Keep remainder for next chunk.
|
|
189
|
-
let previousChunkRemainder
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
257
|
+
let previousChunkRemainder;
|
|
258
|
+
try {
|
|
259
|
+
for await (const chunk of logStream) {
|
|
260
|
+
// Handle possible leftover incomplete line from previous chunk.
|
|
261
|
+
// Everything before last end of line is complete.
|
|
262
|
+
previousChunkRemainder ??= new Uint8Array();
|
|
263
|
+
const chunkWithPreviousRemainder = new Uint8Array(previousChunkRemainder.length + chunk.length);
|
|
264
|
+
chunkWithPreviousRemainder.set(previousChunkRemainder, 0);
|
|
265
|
+
chunkWithPreviousRemainder.set(chunk, previousChunkRemainder.length);
|
|
266
|
+
const lastCompleteMessageIndex = chunkWithPreviousRemainder.lastIndexOf(0x0a);
|
|
267
|
+
previousChunkRemainder = chunkWithPreviousRemainder.slice(lastCompleteMessageIndex);
|
|
268
|
+
// Push complete part of the chunk to the buffer
|
|
269
|
+
this.#streamBuffer.push(chunkWithPreviousRemainder.slice(0, lastCompleteMessageIndex));
|
|
270
|
+
this.#logBufferContent();
|
|
271
|
+
// Keep processing the new data until stopped
|
|
272
|
+
if (this.#stopLogging) {
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
204
275
|
}
|
|
205
276
|
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
// An aborted stream still hands back its unterminated last line, so the caller can flush it.
|
|
279
|
+
if (!signal.aborted)
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
206
282
|
return previousChunkRemainder;
|
|
207
283
|
}
|
|
208
284
|
/**
|
|
209
285
|
* Parse the buffer and log complete messages.
|
|
210
286
|
*/
|
|
211
|
-
logBufferContent() {
|
|
212
|
-
const allParts =
|
|
287
|
+
#logBufferContent() {
|
|
288
|
+
const allParts = this.#decoder.decode(concatBytes(this.#streamBuffer)).split(this.#splitMarker).slice(1);
|
|
213
289
|
// Parse the buffer parts into complete messages
|
|
214
290
|
const messageMarkers = allParts.filter((_, i) => i % 2 === 0);
|
|
215
291
|
const messageContents = allParts.filter((_, i) => i % 2 !== 0);
|
|
216
|
-
this
|
|
292
|
+
this.#streamBuffer = [];
|
|
217
293
|
messageMarkers.forEach((marker, index) => {
|
|
218
294
|
const decodedMarker = marker;
|
|
219
295
|
const decodedContent = messageContents[index];
|
|
220
|
-
if (this
|
|
296
|
+
if (this.#relevancyTimeLimit) {
|
|
221
297
|
// Log only relevant messages. Ignore too old log messages.
|
|
222
298
|
const logTime = new Date(decodedMarker);
|
|
223
|
-
if (logTime < this
|
|
299
|
+
if (logTime < this.#relevancyTimeLimit) {
|
|
224
300
|
return;
|
|
225
301
|
}
|
|
226
302
|
}
|
|
227
303
|
const message = decodedMarker + decodedContent;
|
|
228
304
|
// Original log level information is not available. Log all on info level. Log level could be guessed for
|
|
229
305
|
// some logs, but for any multiline logs such guess would be probably correct only for the first line.
|
|
230
|
-
this
|
|
306
|
+
this.#destinationLog.info(message.trim());
|
|
231
307
|
});
|
|
232
308
|
}
|
|
233
309
|
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
|
|
2
2
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
4
|
+
import type { BatchAddResult, BatchDeleteResult, ListOfRequests, LockedRequestQueueHead, RequestResource, RequestLockInfo, RequestQueueResource, RequestQueueClientRequestToAdd, RequestQueueClientRequestToUpdate, RequestQueueHead, RequestRegistration, UnlockRequestsResult } from '../models.js';
|
|
5
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
6
|
+
/**
|
|
7
|
+
* A request to add, serialized once up front: `byteLength` decides which batch it goes into, `json` is what the body of
|
|
8
|
+
* that batch is assembled from, and `request` is what the result bookkeeping needs.
|
|
9
|
+
*/
|
|
10
|
+
interface SerializedRequestToAdd {
|
|
11
|
+
request: RequestQueueClientRequestToAdd;
|
|
12
|
+
json: string;
|
|
13
|
+
byteLength: number;
|
|
14
|
+
}
|
|
15
|
+
export type { HttpMethod, BatchAddResult, BatchDeleteResult, RequestQueueHeadItem, ListOfRequests, LockedRequestQueueHeadItem, LockedRequestQueueHead, RequestResource, RequestLockInfo, RequestQueueResource, RequestQueueClientRequestToAdd, RequestQueueClientRequestToUpdate, RequestQueueHead, RequestQueueStats, RequestRegistration, UnlockRequestsResult, } from '../models.js';
|
|
6
16
|
/**
|
|
7
17
|
* Client for managing a specific Request queue.
|
|
8
18
|
*
|
|
@@ -34,8 +44,7 @@ export type { AllowedHttpMethods, RequestQueue, RequestQueueClientAddRequestResu
|
|
|
34
44
|
* @see https://docs.apify.com/platform/storage/request-queue
|
|
35
45
|
*/
|
|
36
46
|
export declare class RequestQueueClient extends ResourceClient {
|
|
37
|
-
private
|
|
38
|
-
private timeoutMillis?;
|
|
47
|
+
#private;
|
|
39
48
|
/**
|
|
40
49
|
* @hidden
|
|
41
50
|
*/
|
|
@@ -43,24 +52,30 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
43
52
|
/**
|
|
44
53
|
* Gets the Request queue object from the Apify API.
|
|
45
54
|
*
|
|
55
|
+
* @param options - Request options
|
|
56
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
46
57
|
* @returns The RequestQueue object, or `undefined` if it does not exist
|
|
47
58
|
* @see https://docs.apify.com/api/v2/request-queue-get
|
|
48
59
|
*/
|
|
49
|
-
get(): Promise<
|
|
60
|
+
get(options?: TimeoutOptions): Promise<RequestQueueResource | undefined>;
|
|
50
61
|
/**
|
|
51
62
|
* Updates the Request queue with specified fields.
|
|
52
63
|
*
|
|
53
64
|
* @param newFields - Fields to update in the Request queue
|
|
65
|
+
* @param options - Request options
|
|
66
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
54
67
|
* @returns The updated RequestQueue object
|
|
55
68
|
* @see https://docs.apify.com/api/v2/request-queue-put
|
|
56
69
|
*/
|
|
57
|
-
update(newFields: RequestQueueClientUpdateOptions): Promise<
|
|
70
|
+
update(newFields: RequestQueueClientUpdateOptions, options?: TimeoutOptions): Promise<RequestQueueResource>;
|
|
58
71
|
/**
|
|
59
72
|
* Deletes the Request queue.
|
|
60
73
|
*
|
|
74
|
+
* @param options - Request options
|
|
75
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
61
76
|
* @see https://docs.apify.com/api/v2/request-queue-delete
|
|
62
77
|
*/
|
|
63
|
-
delete(): Promise<void>;
|
|
78
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
64
79
|
/**
|
|
65
80
|
* Lists requests from the beginning of the queue (head).
|
|
66
81
|
*
|
|
@@ -68,10 +83,12 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
68
83
|
* inspecting what requests are waiting to be processed.
|
|
69
84
|
*
|
|
70
85
|
* @param options - Options for listing (e.g., limit)
|
|
86
|
+
* @param options.limit - Maximum number of requests to return.
|
|
87
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
71
88
|
* @returns List of requests from the queue head
|
|
72
89
|
* @see https://docs.apify.com/api/v2/request-queue-head-get
|
|
73
90
|
*/
|
|
74
|
-
listHead(options?: RequestQueueClientListHeadOptions): Promise<
|
|
91
|
+
listHead(options?: RequestQueueClientListHeadOptions): Promise<RequestQueueHead>;
|
|
75
92
|
/**
|
|
76
93
|
* Gets and locks the next requests from the queue head for processing.
|
|
77
94
|
*
|
|
@@ -84,6 +101,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
84
101
|
* @param options - Lock configuration
|
|
85
102
|
* @param options.lockSecs - **Required.** Duration in seconds to lock the requests. After this time, the locks expire and requests can be retrieved by other clients.
|
|
86
103
|
* @param options.limit - Maximum number of requests to return. Default is 25.
|
|
104
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
87
105
|
* @returns Object containing `items` (locked requests), `queueModifiedAt`, `hadMultipleClients`, and lock information
|
|
88
106
|
* @see https://docs.apify.com/api/v2/request-queue-head-lock-post
|
|
89
107
|
*
|
|
@@ -105,7 +123,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
105
123
|
* ```
|
|
106
124
|
* @since Added in 2.4.1
|
|
107
125
|
*/
|
|
108
|
-
listAndLockHead(options: RequestQueueClientListAndLockHeadOptions): Promise<
|
|
126
|
+
listAndLockHead(options: RequestQueueClientListAndLockHeadOptions): Promise<LockedRequestQueueHead>;
|
|
109
127
|
/**
|
|
110
128
|
* Adds a single request to the queue.
|
|
111
129
|
*
|
|
@@ -122,6 +140,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
122
140
|
* @param request.payload - HTTP payload for POST/PUT requests (string).
|
|
123
141
|
* @param options - Additional options
|
|
124
142
|
* @param options.forefront - If `true`, adds the request to the beginning of the queue. Default is `false` (adds to the end).
|
|
143
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
125
144
|
* @returns Object with `requestId`, `wasAlreadyPresent`, and `wasAlreadyHandled` flags
|
|
126
145
|
* @see https://docs.apify.com/api/v2/request-queue-requests-post
|
|
127
146
|
*
|
|
@@ -144,14 +163,14 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
144
163
|
* );
|
|
145
164
|
* ```
|
|
146
165
|
*/
|
|
147
|
-
addRequest(request: RequestQueueClientRequestToAdd, options?: RequestQueueClientAddRequestOptions): Promise<
|
|
166
|
+
addRequest(request: RequestQueueClientRequestToAdd, options?: RequestQueueClientAddRequestOptions): Promise<RequestRegistration>;
|
|
148
167
|
/**
|
|
149
168
|
* Writes requests to Request queue in batch.
|
|
150
169
|
*
|
|
151
170
|
* @private
|
|
152
171
|
*/
|
|
153
|
-
protected
|
|
154
|
-
protected
|
|
172
|
+
protected addRequestBatch(requests: SerializedRequestToAdd[], options?: RequestQueueClientAddRequestOptions): Promise<BatchAddResult>;
|
|
173
|
+
protected addRequestBatchWithRetries(requests: SerializedRequestToAdd[], options?: RequestQueueClientBatchAddRequestWithRetriesOptions): Promise<BatchAddResult>;
|
|
155
174
|
/**
|
|
156
175
|
* Adds multiple requests to the queue in a single operation.
|
|
157
176
|
*
|
|
@@ -167,6 +186,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
167
186
|
* @param options.maxUnprocessedRequestsRetries - Maximum number of retry attempts for rate-limited requests. Default is 3.
|
|
168
187
|
* @param options.maxParallel - Maximum number of parallel batch API calls. Default is 5.
|
|
169
188
|
* @param options.minDelayBetweenUnprocessedRequestsRetriesMillis - Minimum delay before retrying rate-limited requests. Default is 500ms.
|
|
189
|
+
* @param options.timeoutSecs - Timeout for each batch API request. Default is `'medium'`.
|
|
170
190
|
* @returns Object with `processedRequests` (successfully added) and `unprocessedRequests` (failed after all retries)
|
|
171
191
|
* @see https://docs.apify.com/api/v2/request-queue-requests-batch-post
|
|
172
192
|
*
|
|
@@ -190,41 +210,49 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
190
210
|
* ```
|
|
191
211
|
* @since Added in 2.1.0
|
|
192
212
|
*/
|
|
193
|
-
batchAddRequests(requests: RequestQueueClientRequestToAdd[], options?: RequestQueueClientBatchAddRequestWithRetriesOptions): Promise<
|
|
213
|
+
batchAddRequests(requests: RequestQueueClientRequestToAdd[], options?: RequestQueueClientBatchAddRequestWithRetriesOptions): Promise<BatchAddResult>;
|
|
194
214
|
/**
|
|
195
215
|
* Deletes multiple requests from the queue in a single operation.
|
|
196
216
|
*
|
|
197
217
|
* Requests can be identified by either their ID or unique key.
|
|
198
218
|
*
|
|
199
219
|
* @param requests - Array of requests to delete (by id or uniqueKey)
|
|
220
|
+
* @param options - Request options
|
|
221
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
200
222
|
* @returns Result containing processed and unprocessed requests
|
|
201
223
|
* @see https://docs.apify.com/api/v2/request-queue-requests-batch-delete
|
|
202
224
|
* @since Added in 2.3.0
|
|
203
225
|
*/
|
|
204
|
-
batchDeleteRequests(requests: RequestQueueClientRequestToDelete[]): Promise<
|
|
226
|
+
batchDeleteRequests(requests: RequestQueueClientRequestToDelete[], options?: TimeoutOptions): Promise<BatchDeleteResult>;
|
|
205
227
|
/**
|
|
206
228
|
* Gets a specific request from the queue by its ID.
|
|
207
229
|
*
|
|
208
230
|
* @param id - Request ID
|
|
231
|
+
* @param options - Request options
|
|
232
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
209
233
|
* @returns The request object, or `undefined` if not found
|
|
210
234
|
* @see https://docs.apify.com/api/v2/request-queue-request-get
|
|
211
235
|
*/
|
|
212
|
-
getRequest(id: string): Promise<RequestQueueClientGetRequestResult | undefined>;
|
|
236
|
+
getRequest(id: string, options?: TimeoutOptions): Promise<RequestQueueClientGetRequestResult | undefined>;
|
|
213
237
|
/**
|
|
214
238
|
* Updates a request in the queue.
|
|
215
239
|
*
|
|
216
240
|
* @param request - The updated request object (must include id)
|
|
217
241
|
* @param options - Update options such as whether to move to front
|
|
242
|
+
* @param options.forefront - If `true`, moves the request to the beginning of the queue. Default is `false`.
|
|
243
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
218
244
|
* @returns Information about the updated request
|
|
219
245
|
* @see https://docs.apify.com/api/v2/request-queue-request-put
|
|
220
246
|
*/
|
|
221
|
-
updateRequest(request: RequestQueueClientRequestToUpdate, options?: RequestQueueClientAddRequestOptions): Promise<
|
|
247
|
+
updateRequest(request: RequestQueueClientRequestToUpdate, options?: RequestQueueClientAddRequestOptions): Promise<RequestRegistration>;
|
|
222
248
|
/**
|
|
223
249
|
* Deletes a specific request from the queue.
|
|
224
250
|
*
|
|
225
251
|
* @param id - Request ID
|
|
252
|
+
* @param options - Request options
|
|
253
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
226
254
|
*/
|
|
227
|
-
deleteRequest(id: string): Promise<void>;
|
|
255
|
+
deleteRequest(id: string, options?: TimeoutOptions): Promise<void>;
|
|
228
256
|
/**
|
|
229
257
|
* Prolongs the lock on a request to prevent it from being returned to other clients.
|
|
230
258
|
*
|
|
@@ -236,6 +264,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
236
264
|
* @param options - Lock extension options
|
|
237
265
|
* @param options.lockSecs - **Required.** New lock duration in seconds from now.
|
|
238
266
|
* @param options.forefront - If `true`, moves the request to the beginning of the queue when the lock expires. Default is `false`.
|
|
267
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
239
268
|
* @returns Object with new `lockExpiresAt` timestamp
|
|
240
269
|
* @see https://docs.apify.com/api/v2/request-queue-request-lock-put
|
|
241
270
|
*
|
|
@@ -250,7 +279,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
250
279
|
* ```
|
|
251
280
|
* @since Added in 2.4.1
|
|
252
281
|
*/
|
|
253
|
-
prolongRequestLock(id: string, options: RequestQueueClientProlongRequestLockOptions): Promise<
|
|
282
|
+
prolongRequestLock(id: string, options: RequestQueueClientProlongRequestLockOptions): Promise<RequestLockInfo>;
|
|
254
283
|
/**
|
|
255
284
|
* Releases the lock on a request, allowing other clients to process it.
|
|
256
285
|
*
|
|
@@ -259,6 +288,8 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
259
288
|
*
|
|
260
289
|
* @param id - Request ID
|
|
261
290
|
* @param options - Options such as whether to move to front
|
|
291
|
+
* @param options.forefront - If `true`, moves the request to the beginning of the queue. Default is `false`.
|
|
292
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
262
293
|
* @see https://docs.apify.com/api/v2/request-queue-request-lock-delete
|
|
263
294
|
* @since Added in 2.4.1
|
|
264
295
|
*/
|
|
@@ -270,22 +301,27 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
270
301
|
* queue contents.
|
|
271
302
|
*
|
|
272
303
|
* @param options - Pagination options
|
|
304
|
+
* @param options.chunkSize - Maximum number of requests fetched per API call when iterating across pages. `limit`
|
|
305
|
+
* then caps the total across all pages.
|
|
306
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
273
307
|
* @returns List of requests with pagination information
|
|
274
308
|
* @see https://docs.apify.com/api/v2/request-queue-requests-get
|
|
275
309
|
* @since Added in 2.5.1
|
|
276
310
|
*/
|
|
277
|
-
listRequests(options?: RequestQueueClientListRequestsOptions): Promise<
|
|
311
|
+
listRequests(options?: RequestQueueClientListRequestsOptions): Promise<ListOfRequests> & AsyncIterable<RequestResource>;
|
|
278
312
|
/**
|
|
279
313
|
* Unlocks all requests locked by this client.
|
|
280
314
|
*
|
|
281
315
|
* This is useful for releasing all locks at once, for example when shutting down
|
|
282
316
|
* a crawler gracefully.
|
|
283
317
|
*
|
|
318
|
+
* @param options - Request options
|
|
319
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
284
320
|
* @returns Number of requests that were unlocked
|
|
285
321
|
* @see https://docs.apify.com/api/v2/request-queue-requests-unlock-post
|
|
286
322
|
* @since Added in 2.12.5
|
|
287
323
|
*/
|
|
288
|
-
unlockRequests(): Promise<
|
|
324
|
+
unlockRequests(options?: TimeoutOptions): Promise<UnlockRequestsResult>;
|
|
289
325
|
/**
|
|
290
326
|
* Returns an async iterable for paginating through all requests in the queue.
|
|
291
327
|
*
|
|
@@ -293,6 +329,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
293
329
|
* automatically handling pagination behind the scenes.
|
|
294
330
|
*
|
|
295
331
|
* @param options - Pagination options
|
|
332
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
296
333
|
* @returns An async iterable of request pages
|
|
297
334
|
* @see https://docs.apify.com/api/v2/request-queue-requests-get
|
|
298
335
|
*
|
|
@@ -304,7 +341,7 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
304
341
|
* ```
|
|
305
342
|
* @since Added in 2.5.1
|
|
306
343
|
*/
|
|
307
|
-
paginateRequests(options?: RequestQueueClientPaginateRequestsOptions): RequestQueueRequestsAsyncIterable<
|
|
344
|
+
paginateRequests(options?: RequestQueueClientPaginateRequestsOptions): RequestQueueRequestsAsyncIterable<ListOfRequests>;
|
|
308
345
|
}
|
|
309
346
|
/**
|
|
310
347
|
* User-specific options for RequestQueueClient.
|
|
@@ -312,6 +349,8 @@ export declare class RequestQueueClient extends ResourceClient {
|
|
|
312
349
|
export interface RequestQueueUserOptions {
|
|
313
350
|
clientKey?: string;
|
|
314
351
|
/**
|
|
352
|
+
* Cap, in seconds, on the default timeout tier of every request this client sends. An explicit per-call
|
|
353
|
+
* `timeoutSecs` is not capped.
|
|
315
354
|
* @since Added in 2.2.0
|
|
316
355
|
*/
|
|
317
356
|
timeoutSecs?: number;
|
|
@@ -333,7 +372,7 @@ export interface RequestQueueClientUpdateOptions {
|
|
|
333
372
|
/**
|
|
334
373
|
* Options for listing requests from the queue head.
|
|
335
374
|
*/
|
|
336
|
-
export interface RequestQueueClientListHeadOptions {
|
|
375
|
+
export interface RequestQueueClientListHeadOptions extends TimeoutOptions {
|
|
337
376
|
limit?: number;
|
|
338
377
|
}
|
|
339
378
|
/**
|
|
@@ -344,8 +383,15 @@ export type RequestQueueListRequestsFilter = 'locked' | 'pending';
|
|
|
344
383
|
* Options for listing all requests in the queue.
|
|
345
384
|
* @since Added in 2.5.1
|
|
346
385
|
*/
|
|
347
|
-
export interface RequestQueueClientListRequestsOptions {
|
|
386
|
+
export interface RequestQueueClientListRequestsOptions extends TimeoutOptions {
|
|
348
387
|
limit?: number;
|
|
388
|
+
/**
|
|
389
|
+
* Maximum number of requests returned in one API response. When the call is iterated with `for await`, the iterator
|
|
390
|
+
* fetches requests in chunks of this size and yields them one by one, until `limit` is reached or the RQ is
|
|
391
|
+
* exhausted. Awaiting the call returns only the first chunk. Without it, the API's default page size
|
|
392
|
+
* applies.
|
|
393
|
+
*/
|
|
394
|
+
chunkSize?: number;
|
|
349
395
|
/**
|
|
350
396
|
* @since Added in 2.23.2
|
|
351
397
|
*/
|
|
@@ -359,7 +405,7 @@ export interface RequestQueueClientListRequestsOptions {
|
|
|
359
405
|
* Options for paginating through requests in the queue.
|
|
360
406
|
* @since Added in 2.5.1
|
|
361
407
|
*/
|
|
362
|
-
export interface RequestQueueClientPaginateRequestsOptions {
|
|
408
|
+
export interface RequestQueueClientPaginateRequestsOptions extends TimeoutOptions {
|
|
363
409
|
limit?: number;
|
|
364
410
|
maxPageLimit?: number;
|
|
365
411
|
/**
|
|
@@ -375,30 +421,30 @@ export interface RequestQueueClientPaginateRequestsOptions {
|
|
|
375
421
|
* Options for listing and locking requests from the queue head.
|
|
376
422
|
* @since Added in 2.4.1
|
|
377
423
|
*/
|
|
378
|
-
export interface RequestQueueClientListAndLockHeadOptions {
|
|
424
|
+
export interface RequestQueueClientListAndLockHeadOptions extends TimeoutOptions {
|
|
379
425
|
lockSecs: number;
|
|
380
426
|
limit?: number;
|
|
381
427
|
}
|
|
382
|
-
export interface RequestQueueClientAddRequestOptions {
|
|
428
|
+
export interface RequestQueueClientAddRequestOptions extends TimeoutOptions {
|
|
383
429
|
forefront?: boolean;
|
|
384
430
|
}
|
|
385
431
|
/**
|
|
386
432
|
* @since Added in 2.4.1
|
|
387
433
|
*/
|
|
388
|
-
export interface RequestQueueClientProlongRequestLockOptions {
|
|
434
|
+
export interface RequestQueueClientProlongRequestLockOptions extends TimeoutOptions {
|
|
389
435
|
forefront?: boolean;
|
|
390
436
|
lockSecs: number;
|
|
391
437
|
}
|
|
392
438
|
/**
|
|
393
439
|
* @since Added in 2.4.1
|
|
394
440
|
*/
|
|
395
|
-
export interface RequestQueueClientDeleteRequestLockOptions {
|
|
441
|
+
export interface RequestQueueClientDeleteRequestLockOptions extends TimeoutOptions {
|
|
396
442
|
forefront?: boolean;
|
|
397
443
|
}
|
|
398
444
|
/**
|
|
399
445
|
* @since Added in 2.3.0
|
|
400
446
|
*/
|
|
401
|
-
export interface RequestQueueClientBatchAddRequestWithRetriesOptions {
|
|
447
|
+
export interface RequestQueueClientBatchAddRequestWithRetriesOptions extends TimeoutOptions {
|
|
402
448
|
forefront?: boolean;
|
|
403
449
|
maxUnprocessedRequestsRetries?: number;
|
|
404
450
|
maxParallel?: number;
|
|
@@ -410,14 +456,14 @@ export interface RequestQueueClientBatchAddRequestWithRetriesOptions {
|
|
|
410
456
|
/**
|
|
411
457
|
* @since Added in 2.3.0
|
|
412
458
|
*/
|
|
413
|
-
export type RequestQueueClientRequestToDelete = Pick<
|
|
459
|
+
export type RequestQueueClientRequestToDelete = Pick<RequestResource, 'id'> | Pick<RequestResource, 'uniqueKey'>;
|
|
414
460
|
/**
|
|
415
461
|
* Result of getting a single request from the queue.
|
|
416
462
|
*
|
|
417
463
|
* `GET /v2/request-queues/{queueId}/requests/{requestId}` answers with the whole request rather than
|
|
418
464
|
* a queue-head projection.
|
|
419
465
|
*/
|
|
420
|
-
export type RequestQueueClientGetRequestResult =
|
|
466
|
+
export type RequestQueueClientGetRequestResult = RequestResource;
|
|
421
467
|
/**
|
|
422
468
|
* @since Added in 2.5.1
|
|
423
469
|
*/
|