apify-client 3.0.0-beta.1 → 3.0.0-beta.11
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 +5 -3
- package/dist/apify_api_error.d.ts +59 -3
- package/dist/apify_api_error.js +71 -11
- package/dist/apify_client.d.ts +27 -27
- package/dist/apify_client.js +86 -91
- package/dist/base/api_client.d.ts +3 -3
- package/dist/base/api_client.js +6 -10
- package/dist/base/resource_client.d.ts +13 -4
- package/dist/base/resource_client.js +25 -21
- package/dist/base/resource_collection_client.d.ts +7 -6
- package/dist/base/resource_collection_client.js +11 -15
- package/dist/body_parser.js +6 -11
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/api.js +1 -2
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +2 -2
- package/dist/http_client.js +23 -28
- package/dist/index.d.ts +33 -32
- package/dist/index.js +32 -36
- package/dist/interceptors.d.ts +1 -1
- package/dist/interceptors.js +14 -19
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +33 -52
- package/dist/models.js +8 -11
- package/dist/resource_clients/actor.d.ts +13 -13
- package/dist/resource_clients/actor.js +70 -73
- package/dist/resource_clients/actor_collection.d.ts +10 -10
- package/dist/resource_clients/actor_collection.js +19 -20
- package/dist/resource_clients/actor_env_var.d.ts +3 -3
- package/dist/resource_clients/actor_env_var.js +7 -10
- package/dist/resource_clients/actor_env_var_collection.d.ts +11 -20
- package/dist/resource_clients/actor_env_var_collection.js +15 -19
- package/dist/resource_clients/actor_version.d.ts +16 -8
- package/dist/resource_clients/actor_version.js +15 -19
- package/dist/resource_clients/actor_version_collection.d.ts +13 -19
- package/dist/resource_clients/actor_version_collection.js +17 -19
- package/dist/resource_clients/build.d.ts +7 -5
- package/dist/resource_clients/build.js +16 -17
- package/dist/resource_clients/build_collection.d.ts +5 -5
- package/dist/resource_clients/build_collection.js +10 -13
- package/dist/resource_clients/dataset.d.ts +8 -8
- package/dist/resource_clients/dataset.js +75 -85
- package/dist/resource_clients/dataset_collection.d.ts +4 -4
- package/dist/resource_clients/dataset_collection.js +18 -21
- package/dist/resource_clients/key_value_store.d.ts +16 -8
- package/dist/resource_clients/key_value_store.js +61 -65
- package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
- package/dist/resource_clients/key_value_store_collection.js +18 -21
- package/dist/resource_clients/log.d.ts +6 -4
- package/dist/resource_clients/log.js +23 -28
- package/dist/resource_clients/request_queue.d.ts +4 -11
- package/dist/resource_clients/request_queue.js +100 -106
- package/dist/resource_clients/request_queue_collection.d.ts +4 -4
- package/dist/resource_clients/request_queue_collection.js +16 -19
- package/dist/resource_clients/run.d.ts +18 -8
- package/dist/resource_clients/run.js +62 -54
- package/dist/resource_clients/run_collection.d.ts +4 -4
- package/dist/resource_clients/run_collection.js +15 -18
- package/dist/resource_clients/schedule.d.ts +8 -8
- package/dist/resource_clients/schedule.js +14 -23
- package/dist/resource_clients/schedule_collection.d.ts +4 -4
- package/dist/resource_clients/schedule_collection.js +13 -16
- package/dist/resource_clients/store_collection.d.ts +5 -5
- package/dist/resource_clients/store_collection.js +15 -18
- package/dist/resource_clients/task.d.ts +11 -11
- package/dist/resource_clients/task.js +49 -59
- package/dist/resource_clients/task_collection.d.ts +6 -6
- package/dist/resource_clients/task_collection.js +12 -15
- package/dist/resource_clients/user.d.ts +11 -11
- package/dist/resource_clients/user.js +16 -35
- package/dist/resource_clients/webhook.d.ts +8 -8
- package/dist/resource_clients/webhook.js +13 -23
- package/dist/resource_clients/webhook_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_collection.js +13 -16
- package/dist/resource_clients/webhook_dispatch.d.ts +5 -5
- package/dist/resource_clients/webhook_dispatch.js +5 -9
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_dispatch_collection.js +10 -13
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.js +5 -9
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +27 -24
- package/dist/utils.js +69 -93
- package/package.json +38 -40
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -157
- package/dist/index.mjs +0 -42
|
@@ -1,59 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const resource_client_1 = require("../base/resource_client");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { MAX_PAYLOAD_SIZE_BYTES, REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION } from '@apify/consts';
|
|
3
|
+
import log from '@apify/log';
|
|
4
|
+
import { MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS } from '../base/resource_client.js';
|
|
5
|
+
import { ResponseValidationError } from '../response_validation_error.js';
|
|
6
|
+
import * as schemas from '../schemas.js';
|
|
7
|
+
import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject, parseArgument, parseDateFields, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
|
|
10
8
|
const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
|
|
11
9
|
const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
|
|
12
10
|
const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
|
|
13
11
|
const DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT = 1000;
|
|
14
12
|
const SAFETY_BUFFER_PERCENT = 0.01 / 100; // 0.01%
|
|
15
|
-
const listHeadOptionsSchema =
|
|
16
|
-
const listAndLockHeadOptionsSchema =
|
|
17
|
-
lockSecs:
|
|
18
|
-
limit:
|
|
13
|
+
const listHeadOptionsSchema = z.strictObject({ limit: z.number().min(0).optional() });
|
|
14
|
+
const listAndLockHeadOptionsSchema = z.strictObject({
|
|
15
|
+
lockSecs: z.number(),
|
|
16
|
+
limit: z.number().min(0).optional(),
|
|
19
17
|
});
|
|
20
18
|
// Predicates, not `z.looseObject` arms: these run over a whole batch, and an object arm would copy
|
|
21
19
|
// every key of every request. `id` is assigned by the API, so a new request must not carry one.
|
|
22
|
-
const newRequestSchema =
|
|
23
|
-
const forefrontOptionsSchema =
|
|
24
|
-
const batchAddRequestsSchema =
|
|
25
|
-
const batchAddRequestsWithRetriesSchema =
|
|
26
|
-
const optionalBooleanSchema =
|
|
27
|
-
const optionalNumberSchema =
|
|
28
|
-
const requestToDeleteSchema =
|
|
29
|
-
const batchDeleteRequestsSchema =
|
|
20
|
+
const newRequestSchema = z.custom((value) => isNonArrayObject(value) && value.id === undefined, 'Expected a request object without an `id`');
|
|
21
|
+
const forefrontOptionsSchema = z.strictObject({ forefront: z.boolean().optional() });
|
|
22
|
+
const batchAddRequestsSchema = z.array(newRequestSchema).min(1).max(REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
23
|
+
const batchAddRequestsWithRetriesSchema = z.array(newRequestSchema).min(1);
|
|
24
|
+
const optionalBooleanSchema = z.boolean().optional();
|
|
25
|
+
const optionalNumberSchema = z.number().optional();
|
|
26
|
+
const requestToDeleteSchema = z.custom((value) => isNonArrayObject(value) && (typeof value.id === 'string' || typeof value.uniqueKey === 'string'), 'Expected a request object with an `id` or a `uniqueKey`');
|
|
27
|
+
const batchDeleteRequestsSchema = z
|
|
30
28
|
.array(requestToDeleteSchema)
|
|
31
29
|
.min(1)
|
|
32
|
-
.max(
|
|
33
|
-
const requestIdSchema =
|
|
34
|
-
const existingRequestSchema =
|
|
35
|
-
const prolongRequestLockOptionsSchema =
|
|
36
|
-
lockSecs:
|
|
37
|
-
forefront:
|
|
30
|
+
.max(REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
31
|
+
const requestIdSchema = z.string();
|
|
32
|
+
const existingRequestSchema = z.custom((value) => isNonArrayObject(value) && typeof value.id === 'string', 'Expected a request object with an `id`');
|
|
33
|
+
const prolongRequestLockOptionsSchema = z.strictObject({
|
|
34
|
+
lockSecs: z.number(),
|
|
35
|
+
forefront: z.boolean().optional(),
|
|
38
36
|
});
|
|
39
|
-
const requestFilterSchema =
|
|
40
|
-
const listRequestsOptionsSchema =
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
exclusiveStartId: zod_1.z.string().optional(),
|
|
44
|
-
cursor: zod_1.z.string().optional(),
|
|
37
|
+
const requestFilterSchema = z.array(z.enum(['locked', 'pending'])).min(1);
|
|
38
|
+
const listRequestsOptionsSchema = z.strictObject({
|
|
39
|
+
limit: z.number().min(0).optional(),
|
|
40
|
+
cursor: z.string().optional(),
|
|
45
41
|
filter: requestFilterSchema.optional(),
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
maxPageLimit: zod_1.z.number().default(DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT),
|
|
52
|
-
exclusiveStartId: zod_1.z.string().optional(),
|
|
53
|
-
cursor: zod_1.z.string().optional(),
|
|
42
|
+
});
|
|
43
|
+
const paginateRequestsOptionsSchema = z.strictObject({
|
|
44
|
+
limit: z.number().min(0).optional(),
|
|
45
|
+
maxPageLimit: z.number().default(DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT),
|
|
46
|
+
cursor: z.string().optional(),
|
|
54
47
|
filter: requestFilterSchema.optional(),
|
|
55
|
-
})
|
|
56
|
-
.refine(...(0, utils_1.mutuallyExclusive)('exclusiveStartId', 'cursor'));
|
|
48
|
+
});
|
|
57
49
|
/**
|
|
58
50
|
* Client for managing a specific Request queue.
|
|
59
51
|
*
|
|
@@ -84,7 +76,7 @@ const paginateRequestsOptionsSchema = zod_1.z
|
|
|
84
76
|
*
|
|
85
77
|
* @see https://docs.apify.com/platform/storage/request-queue
|
|
86
78
|
*/
|
|
87
|
-
class RequestQueueClient extends
|
|
79
|
+
export class RequestQueueClient extends ResourceClient {
|
|
88
80
|
clientKey;
|
|
89
81
|
timeoutMillis;
|
|
90
82
|
/**
|
|
@@ -105,7 +97,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
105
97
|
* @see https://docs.apify.com/api/v2/request-queue-get
|
|
106
98
|
*/
|
|
107
99
|
async get() {
|
|
108
|
-
return this._get({},
|
|
100
|
+
return this._get(schemas.RequestQueue(), {}, SMALL_TIMEOUT_MILLIS);
|
|
109
101
|
}
|
|
110
102
|
/**
|
|
111
103
|
* Updates the Request queue with specified fields.
|
|
@@ -115,8 +107,8 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
115
107
|
* @see https://docs.apify.com/api/v2/request-queue-put
|
|
116
108
|
*/
|
|
117
109
|
async update(newFields) {
|
|
118
|
-
|
|
119
|
-
return this._update(newFields,
|
|
110
|
+
parseArgument(newFields, anyObjectSchema);
|
|
111
|
+
return this._update(schemas.RequestQueue(), newFields, SMALL_TIMEOUT_MILLIS);
|
|
120
112
|
}
|
|
121
113
|
/**
|
|
122
114
|
* Deletes the Request queue.
|
|
@@ -124,7 +116,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
124
116
|
* @see https://docs.apify.com/api/v2/request-queue-delete
|
|
125
117
|
*/
|
|
126
118
|
async delete() {
|
|
127
|
-
return this._delete(
|
|
119
|
+
return this._delete(SMALL_TIMEOUT_MILLIS);
|
|
128
120
|
}
|
|
129
121
|
/**
|
|
130
122
|
* Lists requests from the beginning of the queue (head).
|
|
@@ -137,17 +129,17 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
137
129
|
* @see https://docs.apify.com/api/v2/request-queue-head-get
|
|
138
130
|
*/
|
|
139
131
|
async listHead(options = {}) {
|
|
140
|
-
const parsed =
|
|
132
|
+
const parsed = parseArgument(options, listHeadOptionsSchema, 'RequestQueueClientListHeadOptions');
|
|
141
133
|
const response = await this.httpClient.call({
|
|
142
134
|
url: this._url('head'),
|
|
143
135
|
method: 'GET',
|
|
144
|
-
timeout: Math.min(
|
|
136
|
+
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
145
137
|
params: this._params({
|
|
146
138
|
limit: parsed.limit,
|
|
147
139
|
clientKey: this.clientKey,
|
|
148
140
|
}),
|
|
149
141
|
});
|
|
150
|
-
return (
|
|
142
|
+
return parseResponse(response, schemas.RequestQueueHead());
|
|
151
143
|
}
|
|
152
144
|
/**
|
|
153
145
|
* Gets and locks the next requests from the queue head for processing.
|
|
@@ -183,18 +175,18 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
183
175
|
* @since Added in 2.4.1
|
|
184
176
|
*/
|
|
185
177
|
async listAndLockHead(options) {
|
|
186
|
-
const parsed =
|
|
178
|
+
const parsed = parseArgument(options, listAndLockHeadOptionsSchema, 'RequestQueueClientListAndLockHeadOptions');
|
|
187
179
|
const response = await this.httpClient.call({
|
|
188
180
|
url: this._url('head/lock'),
|
|
189
181
|
method: 'POST',
|
|
190
|
-
timeout: Math.min(
|
|
182
|
+
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
191
183
|
params: this._params({
|
|
192
184
|
limit: parsed.limit,
|
|
193
185
|
lockSecs: parsed.lockSecs,
|
|
194
186
|
clientKey: this.clientKey,
|
|
195
187
|
}),
|
|
196
188
|
});
|
|
197
|
-
return (
|
|
189
|
+
return parseResponse(response, schemas.LockedRequestQueueHead());
|
|
198
190
|
}
|
|
199
191
|
/**
|
|
200
192
|
* Adds a single request to the queue.
|
|
@@ -235,19 +227,19 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
235
227
|
* ```
|
|
236
228
|
*/
|
|
237
229
|
async addRequest(request, options = {}) {
|
|
238
|
-
|
|
239
|
-
const parsed =
|
|
230
|
+
parseArgument(request, newRequestSchema);
|
|
231
|
+
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
240
232
|
const response = await this.httpClient.call({
|
|
241
233
|
url: this._url('requests'),
|
|
242
234
|
method: 'POST',
|
|
243
|
-
timeout: Math.min(
|
|
235
|
+
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
244
236
|
data: request,
|
|
245
237
|
params: this._params({
|
|
246
238
|
forefront: parsed.forefront,
|
|
247
239
|
clientKey: this.clientKey,
|
|
248
240
|
}),
|
|
249
241
|
});
|
|
250
|
-
return (
|
|
242
|
+
return parseResponse(response, schemas.RequestRegistration());
|
|
251
243
|
}
|
|
252
244
|
/**
|
|
253
245
|
* Writes requests to Request queue in batch.
|
|
@@ -255,19 +247,19 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
255
247
|
* @private
|
|
256
248
|
*/
|
|
257
249
|
async _batchAddRequests(requests, options = {}) {
|
|
258
|
-
|
|
259
|
-
const parsed =
|
|
260
|
-
const
|
|
250
|
+
parseArgument(requests, batchAddRequestsSchema);
|
|
251
|
+
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
252
|
+
const response = await this.httpClient.call({
|
|
261
253
|
url: this._url('requests/batch'),
|
|
262
254
|
method: 'POST',
|
|
263
|
-
timeout: Math.min(
|
|
255
|
+
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
264
256
|
data: requests,
|
|
265
257
|
params: this._params({
|
|
266
258
|
forefront: parsed.forefront,
|
|
267
259
|
clientKey: this.clientKey,
|
|
268
260
|
}),
|
|
269
261
|
});
|
|
270
|
-
return (
|
|
262
|
+
return parseResponse(response, schemas.BatchAddResult());
|
|
271
263
|
}
|
|
272
264
|
async _batchAddRequestsWithRetries(requests, options = {}) {
|
|
273
265
|
const { forefront, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
@@ -300,7 +292,11 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
300
292
|
}
|
|
301
293
|
}
|
|
302
294
|
catch (err) {
|
|
303
|
-
|
|
295
|
+
// A response the specification does not describe is reported, as everywhere else: the server may well
|
|
296
|
+
// have added the batch, so calling it unprocessed would hide the mismatch behind a wrong answer.
|
|
297
|
+
if (err instanceof ResponseValidationError)
|
|
298
|
+
throw err;
|
|
299
|
+
log.exception(err, 'Request batch insert failed');
|
|
304
300
|
// When something fails and http client does not retry, the remaining requests are treated as unprocessed.
|
|
305
301
|
// This ensures that this method does not throw and keeps the signature.
|
|
306
302
|
const processedRequestsUniqueKeys = processedRequests.map(({ uniqueKey }) => uniqueKey);
|
|
@@ -316,7 +312,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
316
312
|
});
|
|
317
313
|
}
|
|
318
314
|
const result = { processedRequests, unprocessedRequests };
|
|
319
|
-
return
|
|
315
|
+
return cast(parseDateFields(result));
|
|
320
316
|
}
|
|
321
317
|
/**
|
|
322
318
|
* Adds multiple requests to the queue in a single operation.
|
|
@@ -358,25 +354,27 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
358
354
|
*/
|
|
359
355
|
async batchAddRequests(requests, options = {}) {
|
|
360
356
|
const { forefront, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, maxParallel = DEFAULT_PARALLEL_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
357
|
+
parseArgument(requests, batchAddRequestsWithRetriesSchema);
|
|
358
|
+
parseArgument(forefront, optionalBooleanSchema);
|
|
359
|
+
parseArgument(maxUnprocessedRequestsRetries, optionalNumberSchema);
|
|
360
|
+
parseArgument(maxParallel, optionalNumberSchema);
|
|
361
|
+
parseArgument(minDelayBetweenUnprocessedRequestsRetriesMillis, optionalNumberSchema);
|
|
366
362
|
const executingRequests = new Set();
|
|
367
363
|
const individualResults = [];
|
|
368
|
-
const payloadSizeLimitBytes =
|
|
364
|
+
const payloadSizeLimitBytes = MAX_PAYLOAD_SIZE_BYTES - Math.ceil(MAX_PAYLOAD_SIZE_BYTES * SAFETY_BUFFER_PERCENT);
|
|
369
365
|
// Keep a pool of up to `maxParallel` requests running at once
|
|
370
366
|
let i = 0;
|
|
371
367
|
while (i < requests.length) {
|
|
372
|
-
const slicedRequests = requests.slice(i, i +
|
|
373
|
-
const requestsInBatch =
|
|
368
|
+
const slicedRequests = requests.slice(i, i + REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
369
|
+
const requestsInBatch = sliceArrayByByteLength(slicedRequests, payloadSizeLimitBytes, i);
|
|
374
370
|
const requestPromise = this._batchAddRequestsWithRetries(requestsInBatch, options);
|
|
375
371
|
executingRequests.add(requestPromise);
|
|
372
|
+
// A rejection reaches the caller through the awaits below; this bookkeeping chain only has to avoid
|
|
373
|
+
// turning it into an unhandled one of its own.
|
|
376
374
|
void requestPromise.then((batchAddResult) => {
|
|
377
375
|
executingRequests.delete(requestPromise);
|
|
378
376
|
individualResults.push(batchAddResult);
|
|
379
|
-
});
|
|
377
|
+
}, () => undefined);
|
|
380
378
|
if (executingRequests.size >= maxParallel) {
|
|
381
379
|
await Promise.race(executingRequests);
|
|
382
380
|
}
|
|
@@ -406,17 +404,17 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
406
404
|
* @since Added in 2.3.0
|
|
407
405
|
*/
|
|
408
406
|
async batchDeleteRequests(requests) {
|
|
409
|
-
|
|
410
|
-
const
|
|
407
|
+
parseArgument(requests, batchDeleteRequestsSchema);
|
|
408
|
+
const response = await this.httpClient.call({
|
|
411
409
|
url: this._url('requests/batch'),
|
|
412
410
|
method: 'DELETE',
|
|
413
|
-
timeout: Math.min(
|
|
411
|
+
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
414
412
|
data: requests,
|
|
415
413
|
params: this._params({
|
|
416
414
|
clientKey: this.clientKey,
|
|
417
415
|
}),
|
|
418
416
|
});
|
|
419
|
-
return (
|
|
417
|
+
return parseResponse(response, schemas.BatchDeleteResult());
|
|
420
418
|
}
|
|
421
419
|
/**
|
|
422
420
|
* Gets a specific request from the queue by its ID.
|
|
@@ -426,19 +424,19 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
426
424
|
* @see https://docs.apify.com/api/v2/request-queue-request-get
|
|
427
425
|
*/
|
|
428
426
|
async getRequest(id) {
|
|
429
|
-
|
|
427
|
+
parseArgument(id, requestIdSchema);
|
|
430
428
|
const requestOpts = {
|
|
431
429
|
url: this._url(['requests', id]),
|
|
432
430
|
method: 'GET',
|
|
433
|
-
timeout: Math.min(
|
|
431
|
+
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
434
432
|
params: this._params(),
|
|
435
433
|
};
|
|
436
434
|
try {
|
|
437
435
|
const response = await this.httpClient.call(requestOpts);
|
|
438
|
-
return (
|
|
436
|
+
return parseResponse(response, schemas.Request());
|
|
439
437
|
}
|
|
440
438
|
catch (err) {
|
|
441
|
-
|
|
439
|
+
catchNotFoundOrThrow(err);
|
|
442
440
|
}
|
|
443
441
|
return undefined;
|
|
444
442
|
}
|
|
@@ -451,19 +449,19 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
451
449
|
* @see https://docs.apify.com/api/v2/request-queue-request-put
|
|
452
450
|
*/
|
|
453
451
|
async updateRequest(request, options = {}) {
|
|
454
|
-
|
|
455
|
-
const parsed =
|
|
452
|
+
parseArgument(request, existingRequestSchema);
|
|
453
|
+
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
456
454
|
const response = await this.httpClient.call({
|
|
457
455
|
url: this._url(['requests', request.id]),
|
|
458
456
|
method: 'PUT',
|
|
459
|
-
timeout: Math.min(
|
|
457
|
+
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
460
458
|
data: request,
|
|
461
459
|
params: this._params({
|
|
462
460
|
forefront: parsed.forefront,
|
|
463
461
|
clientKey: this.clientKey,
|
|
464
462
|
}),
|
|
465
463
|
});
|
|
466
|
-
return (
|
|
464
|
+
return parseResponse(response, schemas.RequestRegistration());
|
|
467
465
|
}
|
|
468
466
|
/**
|
|
469
467
|
* Deletes a specific request from the queue.
|
|
@@ -471,11 +469,11 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
471
469
|
* @param id - Request ID
|
|
472
470
|
*/
|
|
473
471
|
async deleteRequest(id) {
|
|
474
|
-
|
|
472
|
+
parseArgument(id, requestIdSchema);
|
|
475
473
|
await this.httpClient.call({
|
|
476
474
|
url: this._url(['requests', id]),
|
|
477
475
|
method: 'DELETE',
|
|
478
|
-
timeout: Math.min(
|
|
476
|
+
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
479
477
|
params: this._params({
|
|
480
478
|
clientKey: this.clientKey,
|
|
481
479
|
}),
|
|
@@ -507,19 +505,19 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
507
505
|
* @since Added in 2.4.1
|
|
508
506
|
*/
|
|
509
507
|
async prolongRequestLock(id, options) {
|
|
510
|
-
|
|
511
|
-
const parsed =
|
|
508
|
+
parseArgument(id, requestIdSchema);
|
|
509
|
+
const parsed = parseArgument(options, prolongRequestLockOptionsSchema, 'RequestQueueClientProlongRequestLockOptions');
|
|
512
510
|
const response = await this.httpClient.call({
|
|
513
511
|
url: this._url(['requests', id, 'lock']),
|
|
514
512
|
method: 'PUT',
|
|
515
|
-
timeout: Math.min(
|
|
513
|
+
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
516
514
|
params: this._params({
|
|
517
515
|
forefront: parsed.forefront,
|
|
518
516
|
lockSecs: parsed.lockSecs,
|
|
519
517
|
clientKey: this.clientKey,
|
|
520
518
|
}),
|
|
521
519
|
});
|
|
522
|
-
return (
|
|
520
|
+
return parseResponse(response, schemas.RequestLockInfo());
|
|
523
521
|
}
|
|
524
522
|
/**
|
|
525
523
|
* Releases the lock on a request, allowing other clients to process it.
|
|
@@ -533,12 +531,12 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
533
531
|
* @since Added in 2.4.1
|
|
534
532
|
*/
|
|
535
533
|
async deleteRequestLock(id, options = {}) {
|
|
536
|
-
|
|
537
|
-
const parsed =
|
|
534
|
+
parseArgument(id, requestIdSchema);
|
|
535
|
+
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientDeleteRequestLockOptions');
|
|
538
536
|
await this.httpClient.call({
|
|
539
537
|
url: this._url(['requests', id, 'lock']),
|
|
540
538
|
method: 'DELETE',
|
|
541
|
-
timeout: Math.min(
|
|
539
|
+
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
542
540
|
params: this._params({
|
|
543
541
|
forefront: parsed.forefront,
|
|
544
542
|
clientKey: this.clientKey,
|
|
@@ -557,19 +555,19 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
557
555
|
* @since Added in 2.5.1
|
|
558
556
|
*/
|
|
559
557
|
listRequests(options = {}) {
|
|
560
|
-
const parsed =
|
|
558
|
+
const parsed = parseArgument(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
|
|
561
559
|
const getPaginatedList = async (rqListOptions = {}) => {
|
|
562
560
|
const response = await this.httpClient.call({
|
|
563
561
|
url: this._url('requests'),
|
|
564
562
|
method: 'GET',
|
|
565
|
-
timeout: Math.min(
|
|
563
|
+
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
566
564
|
params: this._params({
|
|
567
565
|
...rqListOptions,
|
|
568
566
|
filter: rqListOptions.filter ? rqListOptions.filter.join(',') : undefined,
|
|
569
567
|
clientKey: this.clientKey,
|
|
570
568
|
}),
|
|
571
569
|
});
|
|
572
|
-
return (
|
|
570
|
+
return parseResponse(response, schemas.ListOfRequests());
|
|
573
571
|
};
|
|
574
572
|
const paginatedListPromise = getPaginatedList(parsed);
|
|
575
573
|
async function* asyncGenerator() {
|
|
@@ -585,8 +583,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
585
583
|
const newOptions = {
|
|
586
584
|
...parsed,
|
|
587
585
|
limit: remainingItems,
|
|
588
|
-
// remove original exclusiveStartId, if there was any, and use cursor-based pagination
|
|
589
|
-
exclusiveStartId: undefined,
|
|
590
586
|
cursor: currentPage.nextCursor,
|
|
591
587
|
};
|
|
592
588
|
currentPage = await getPaginatedList(newOptions);
|
|
@@ -614,12 +610,12 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
614
610
|
const response = await this.httpClient.call({
|
|
615
611
|
url: this._url('requests/unlock'),
|
|
616
612
|
method: 'POST',
|
|
617
|
-
timeout: Math.min(
|
|
613
|
+
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
618
614
|
params: this._params({
|
|
619
615
|
clientKey: this.clientKey,
|
|
620
616
|
}),
|
|
621
617
|
});
|
|
622
|
-
return (
|
|
618
|
+
return parseResponse(response, schemas.UnlockRequestsResult());
|
|
623
619
|
}
|
|
624
620
|
/**
|
|
625
621
|
* Returns an async iterable for paginating through all requests in the queue.
|
|
@@ -640,14 +636,12 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
640
636
|
* @since Added in 2.5.1
|
|
641
637
|
*/
|
|
642
638
|
paginateRequests(options = {}) {
|
|
643
|
-
const { limit,
|
|
644
|
-
return new
|
|
639
|
+
const { limit, cursor, filter, maxPageLimit } = parseArgument(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
|
|
640
|
+
return new RequestQueuePaginationIterator({
|
|
645
641
|
getPage: async (pageOptions) => this.listRequests({ ...pageOptions, filter }),
|
|
646
642
|
limit,
|
|
647
|
-
exclusiveStartId,
|
|
648
643
|
cursor,
|
|
649
644
|
maxPageLimit,
|
|
650
645
|
});
|
|
651
646
|
}
|
|
652
647
|
}
|
|
653
|
-
exports.RequestQueueClient = RequestQueueClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
2
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
3
|
-
import { ResourceCollectionClient } from '../base/resource_collection_client';
|
|
4
|
-
import type { PaginatedList, PaginationOptions } from '../utils';
|
|
5
|
-
import type { RequestQueue } from './request_queue';
|
|
2
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { PaginatedList, PaginationOptions } from '../utils.js';
|
|
5
|
+
import type { RequestQueue } from './request_queue.js';
|
|
6
6
|
/**
|
|
7
7
|
* Client for managing the collection of Request queues in your account.
|
|
8
8
|
*
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
desc: zod_1.z.boolean().optional(),
|
|
12
|
-
ownership: zod_1.z.enum(consts_1.STORAGE_OWNERSHIP_FILTER).optional(),
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
6
|
+
const listOptionsSchema = z.strictObject({
|
|
7
|
+
unnamed: z.boolean().optional(),
|
|
8
|
+
...paginationOptionsShape,
|
|
9
|
+
desc: z.boolean().optional(),
|
|
10
|
+
ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
|
|
13
11
|
});
|
|
14
|
-
const nameSchema =
|
|
12
|
+
const nameSchema = z.string().optional();
|
|
15
13
|
/**
|
|
16
14
|
* Client for managing the collection of Request queues in your account.
|
|
17
15
|
*
|
|
@@ -32,7 +30,7 @@ const nameSchema = zod_1.z.string().optional();
|
|
|
32
30
|
*
|
|
33
31
|
* @see https://docs.apify.com/platform/storage/request-queue
|
|
34
32
|
*/
|
|
35
|
-
class RequestQueueCollectionClient extends
|
|
33
|
+
export class RequestQueueCollectionClient extends ResourceCollectionClient {
|
|
36
34
|
/**
|
|
37
35
|
* @hidden
|
|
38
36
|
*/
|
|
@@ -63,8 +61,8 @@ class RequestQueueCollectionClient extends resource_collection_client_1.Resource
|
|
|
63
61
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
64
62
|
*/
|
|
65
63
|
list(options = {}) {
|
|
66
|
-
const parsed =
|
|
67
|
-
return this._listPaginated(parsed);
|
|
64
|
+
const parsed = parseArgument(options, listOptionsSchema, 'RequestQueueCollectionListOptions');
|
|
65
|
+
return this._listPaginated(schemas.ListOfRequestQueues(), parsed);
|
|
68
66
|
}
|
|
69
67
|
/**
|
|
70
68
|
* Gets or creates a Request queue with the specified name.
|
|
@@ -74,8 +72,7 @@ class RequestQueueCollectionClient extends resource_collection_client_1.Resource
|
|
|
74
72
|
* @see https://docs.apify.com/api/v2/request-queues-post
|
|
75
73
|
*/
|
|
76
74
|
async getOrCreate(name) {
|
|
77
|
-
|
|
78
|
-
return this._getOrCreate(name);
|
|
75
|
+
parseArgument(name, nameSchema);
|
|
76
|
+
return this._getOrCreate(schemas.RequestQueue(), name);
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
exports.RequestQueueCollectionClient = RequestQueueCollectionClient;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { RUN_GENERAL_ACCESS } from '@apify/consts';
|
|
2
2
|
import { Log } from '@apify/log';
|
|
3
|
-
import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client';
|
|
4
|
-
import { ResourceClient } from '../base/resource_client';
|
|
5
|
-
import type { ApifyResponse } from '../http_client';
|
|
6
|
-
import type { ActorRun } from './actor';
|
|
7
|
-
import { DatasetClient } from './dataset';
|
|
8
|
-
import { KeyValueStoreClient } from './key_value_store';
|
|
9
|
-
import { LogClient, StreamedLog } from './log';
|
|
10
|
-
import { RequestQueueClient } from './request_queue';
|
|
3
|
+
import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client.js';
|
|
4
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
5
|
+
import type { ApifyResponse } from '../http_client.js';
|
|
6
|
+
import type { ActorRun } from './actor.js';
|
|
7
|
+
import { DatasetClient } from './dataset.js';
|
|
8
|
+
import { KeyValueStoreClient } from './key_value_store.js';
|
|
9
|
+
import { LogClient, StreamedLog } from './log.js';
|
|
10
|
+
import { RequestQueueClient } from './request_queue.js';
|
|
11
11
|
/**
|
|
12
12
|
* Client for managing a specific Actor run.
|
|
13
13
|
*
|
|
@@ -210,6 +210,8 @@ export declare class RunClient extends ResourceClient {
|
|
|
210
210
|
/**
|
|
211
211
|
* Returns a client for the default dataset of this Actor run.
|
|
212
212
|
*
|
|
213
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
214
|
+
*
|
|
213
215
|
* @returns A client for accessing the run's default dataset
|
|
214
216
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
215
217
|
*
|
|
@@ -223,6 +225,9 @@ export declare class RunClient extends ResourceClient {
|
|
|
223
225
|
/**
|
|
224
226
|
* Returns a client for the default key-value store of this Actor run.
|
|
225
227
|
*
|
|
228
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
|
|
229
|
+
* lookups such as `getRecord()` read a 404 as a missing record.
|
|
230
|
+
*
|
|
226
231
|
* @returns A client for accessing the run's default key-value store
|
|
227
232
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
228
233
|
*
|
|
@@ -236,6 +241,9 @@ export declare class RunClient extends ResourceClient {
|
|
|
236
241
|
/**
|
|
237
242
|
* Returns a client for the default Request queue of this Actor run.
|
|
238
243
|
*
|
|
244
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
245
|
+
* `getRequest()` reads a 404 as a missing request.
|
|
246
|
+
*
|
|
239
247
|
* @returns A client for accessing the run's default Request queue
|
|
240
248
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
241
249
|
*
|
|
@@ -249,6 +257,8 @@ export declare class RunClient extends ResourceClient {
|
|
|
249
257
|
/**
|
|
250
258
|
* Returns a client for accessing the log of this Actor run.
|
|
251
259
|
*
|
|
260
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
261
|
+
*
|
|
252
262
|
* @returns A client for accessing the run's log
|
|
253
263
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
254
264
|
*
|