apify-client 2.25.1-beta.7 → 3.0.0-beta.0
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_client.js +34 -30
- package/dist/argument_validation_error.d.ts +17 -0
- package/dist/argument_validation_error.js +157 -0
- package/dist/base/api_client.d.ts +2 -2
- package/dist/base/api_client.js +13 -10
- package/dist/bundle.js +66 -28147
- package/dist/bundle.js.LICENSE.txt +33 -0
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/resource_clients/actor.js +60 -55
- package/dist/resource_clients/actor_collection.js +13 -11
- package/dist/resource_clients/actor_env_var.js +2 -3
- package/dist/resource_clients/actor_env_var_collection.js +3 -3
- package/dist/resource_clients/actor_version.js +5 -4
- package/dist/resource_clients/actor_version_collection.js +3 -3
- package/dist/resource_clients/build.js +7 -10
- package/dist/resource_clients/build_collection.js +8 -8
- package/dist/resource_clients/dataset.d.ts +6 -4
- package/dist/resource_clients/dataset.js +66 -57
- package/dist/resource_clients/dataset_collection.js +14 -12
- package/dist/resource_clients/key_value_store.d.ts +3 -2
- package/dist/resource_clients/key_value_store.js +66 -50
- package/dist/resource_clients/key_value_store_collection.js +14 -12
- package/dist/resource_clients/request_queue.js +83 -89
- package/dist/resource_clients/request_queue_collection.js +12 -11
- package/dist/resource_clients/run.js +39 -40
- package/dist/resource_clients/run_collection.js +12 -11
- package/dist/resource_clients/schedule.js +1 -3
- package/dist/resource_clients/schedule_collection.js +10 -9
- package/dist/resource_clients/store_collection.js +13 -13
- package/dist/resource_clients/task.js +36 -33
- package/dist/resource_clients/task_collection.js +9 -9
- package/dist/resource_clients/webhook.js +1 -3
- package/dist/resource_clients/webhook_collection.js +10 -9
- package/dist/resource_clients/webhook_dispatch_collection.js +8 -8
- package/dist/statistics.js +4 -3
- package/dist/utils.d.ts +51 -5
- package/dist/utils.js +94 -12
- package/package.json +9 -4
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequestQueueClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
6
|
const consts_1 = require("@apify/consts");
|
|
7
7
|
const log_1 = tslib_1.__importDefault(require("@apify/log"));
|
|
8
8
|
const resource_client_1 = require("../base/resource_client");
|
|
@@ -12,6 +12,48 @@ const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
|
|
|
12
12
|
const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
|
|
13
13
|
const DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT = 1000;
|
|
14
14
|
const SAFETY_BUFFER_PERCENT = 0.01 / 100; // 0.01%
|
|
15
|
+
const listHeadOptionsSchema = zod_1.z.strictObject({ limit: zod_1.z.number().min(0).optional() });
|
|
16
|
+
const listAndLockHeadOptionsSchema = zod_1.z.strictObject({
|
|
17
|
+
lockSecs: zod_1.z.number(),
|
|
18
|
+
limit: zod_1.z.number().min(0).optional(),
|
|
19
|
+
});
|
|
20
|
+
// Predicates, not `z.looseObject` arms: these run over a whole batch, and an object arm would copy
|
|
21
|
+
// every key of every request. `id` is assigned by the API, so a new request must not carry one.
|
|
22
|
+
const newRequestSchema = zod_1.z.custom((value) => (0, utils_1.isNonArrayObject)(value) && value.id === undefined, 'Expected a request object without an `id`');
|
|
23
|
+
const forefrontOptionsSchema = zod_1.z.strictObject({ forefront: zod_1.z.boolean().optional() });
|
|
24
|
+
const batchAddRequestsSchema = zod_1.z.array(newRequestSchema).min(1).max(consts_1.REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
25
|
+
const batchAddRequestsWithRetriesSchema = zod_1.z.array(newRequestSchema).min(1);
|
|
26
|
+
const optionalBooleanSchema = zod_1.z.boolean().optional();
|
|
27
|
+
const optionalNumberSchema = zod_1.z.number().optional();
|
|
28
|
+
const requestToDeleteSchema = zod_1.z.custom((value) => (0, utils_1.isNonArrayObject)(value) && (typeof value.id === 'string' || typeof value.uniqueKey === 'string'), 'Expected a request object with an `id` or a `uniqueKey`');
|
|
29
|
+
const batchDeleteRequestsSchema = zod_1.z
|
|
30
|
+
.array(requestToDeleteSchema)
|
|
31
|
+
.min(1)
|
|
32
|
+
.max(consts_1.REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
33
|
+
const requestIdSchema = zod_1.z.string();
|
|
34
|
+
const existingRequestSchema = zod_1.z.custom((value) => (0, utils_1.isNonArrayObject)(value) && typeof value.id === 'string', 'Expected a request object with an `id`');
|
|
35
|
+
const prolongRequestLockOptionsSchema = zod_1.z.strictObject({
|
|
36
|
+
lockSecs: zod_1.z.number(),
|
|
37
|
+
forefront: zod_1.z.boolean().optional(),
|
|
38
|
+
});
|
|
39
|
+
const requestFilterSchema = zod_1.z.array(zod_1.z.enum(['locked', 'pending'])).min(1);
|
|
40
|
+
const listRequestsOptionsSchema = zod_1.z
|
|
41
|
+
.strictObject({
|
|
42
|
+
limit: zod_1.z.number().min(0).optional(),
|
|
43
|
+
exclusiveStartId: zod_1.z.string().optional(),
|
|
44
|
+
cursor: zod_1.z.string().optional(),
|
|
45
|
+
filter: requestFilterSchema.optional(),
|
|
46
|
+
})
|
|
47
|
+
.refine(...(0, utils_1.mutuallyExclusive)('exclusiveStartId', 'cursor'));
|
|
48
|
+
const paginateRequestsOptionsSchema = zod_1.z
|
|
49
|
+
.strictObject({
|
|
50
|
+
limit: zod_1.z.number().min(0).optional(),
|
|
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(),
|
|
54
|
+
filter: requestFilterSchema.optional(),
|
|
55
|
+
})
|
|
56
|
+
.refine(...(0, utils_1.mutuallyExclusive)('exclusiveStartId', 'cursor'));
|
|
15
57
|
/**
|
|
16
58
|
* Client for managing a specific Request queue.
|
|
17
59
|
*
|
|
@@ -73,7 +115,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
73
115
|
* @see https://docs.apify.com/api/v2/request-queue-put
|
|
74
116
|
*/
|
|
75
117
|
async update(newFields) {
|
|
76
|
-
(0,
|
|
118
|
+
(0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
|
|
77
119
|
return this._update(newFields, resource_client_1.SMALL_TIMEOUT_MILLIS);
|
|
78
120
|
}
|
|
79
121
|
/**
|
|
@@ -95,15 +137,13 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
95
137
|
* @see https://docs.apify.com/api/v2/request-queue-head-get
|
|
96
138
|
*/
|
|
97
139
|
async listHead(options = {}) {
|
|
98
|
-
(0,
|
|
99
|
-
limit: ow_1.default.optional.number.not.negative,
|
|
100
|
-
}));
|
|
140
|
+
const parsed = (0, utils_1.parseArgument)(options, listHeadOptionsSchema, 'RequestQueueClientListHeadOptions');
|
|
101
141
|
const response = await this.httpClient.call({
|
|
102
142
|
url: this._url('head'),
|
|
103
143
|
method: 'GET',
|
|
104
144
|
timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
105
145
|
params: this._params({
|
|
106
|
-
limit:
|
|
146
|
+
limit: parsed.limit,
|
|
107
147
|
clientKey: this.clientKey,
|
|
108
148
|
}),
|
|
109
149
|
});
|
|
@@ -143,17 +183,14 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
143
183
|
* @since Added in 2.4.1
|
|
144
184
|
*/
|
|
145
185
|
async listAndLockHead(options) {
|
|
146
|
-
(0,
|
|
147
|
-
lockSecs: ow_1.default.number,
|
|
148
|
-
limit: ow_1.default.optional.number.not.negative,
|
|
149
|
-
}));
|
|
186
|
+
const parsed = (0, utils_1.parseArgument)(options, listAndLockHeadOptionsSchema, 'RequestQueueClientListAndLockHeadOptions');
|
|
150
187
|
const response = await this.httpClient.call({
|
|
151
188
|
url: this._url('head/lock'),
|
|
152
189
|
method: 'POST',
|
|
153
190
|
timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
154
191
|
params: this._params({
|
|
155
|
-
limit:
|
|
156
|
-
lockSecs:
|
|
192
|
+
limit: parsed.limit,
|
|
193
|
+
lockSecs: parsed.lockSecs,
|
|
157
194
|
clientKey: this.clientKey,
|
|
158
195
|
}),
|
|
159
196
|
});
|
|
@@ -198,19 +235,15 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
198
235
|
* ```
|
|
199
236
|
*/
|
|
200
237
|
async addRequest(request, options = {}) {
|
|
201
|
-
(0,
|
|
202
|
-
|
|
203
|
-
}));
|
|
204
|
-
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
205
|
-
forefront: ow_1.default.optional.boolean,
|
|
206
|
-
}));
|
|
238
|
+
(0, utils_1.parseArgument)(request, newRequestSchema);
|
|
239
|
+
const parsed = (0, utils_1.parseArgument)(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
207
240
|
const response = await this.httpClient.call({
|
|
208
241
|
url: this._url('requests'),
|
|
209
242
|
method: 'POST',
|
|
210
243
|
timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
211
244
|
data: request,
|
|
212
245
|
params: this._params({
|
|
213
|
-
forefront:
|
|
246
|
+
forefront: parsed.forefront,
|
|
214
247
|
clientKey: this.clientKey,
|
|
215
248
|
}),
|
|
216
249
|
});
|
|
@@ -222,22 +255,15 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
222
255
|
* @private
|
|
223
256
|
*/
|
|
224
257
|
async _batchAddRequests(requests, options = {}) {
|
|
225
|
-
(0,
|
|
226
|
-
|
|
227
|
-
id: ow_1.default.undefined,
|
|
228
|
-
}))
|
|
229
|
-
.minLength(1)
|
|
230
|
-
.maxLength(consts_1.REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION));
|
|
231
|
-
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
232
|
-
forefront: ow_1.default.optional.boolean,
|
|
233
|
-
}));
|
|
258
|
+
(0, utils_1.parseArgument)(requests, batchAddRequestsSchema);
|
|
259
|
+
const parsed = (0, utils_1.parseArgument)(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
234
260
|
const { data } = await this.httpClient.call({
|
|
235
261
|
url: this._url('requests/batch'),
|
|
236
262
|
method: 'POST',
|
|
237
263
|
timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
238
264
|
data: requests,
|
|
239
265
|
params: this._params({
|
|
240
|
-
forefront:
|
|
266
|
+
forefront: parsed.forefront,
|
|
241
267
|
clientKey: this.clientKey,
|
|
242
268
|
}),
|
|
243
269
|
});
|
|
@@ -332,15 +358,11 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
332
358
|
*/
|
|
333
359
|
async batchAddRequests(requests, options = {}) {
|
|
334
360
|
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;
|
|
335
|
-
(0,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
(0, ow_1.default)(forefront, ow_1.default.optional.boolean);
|
|
341
|
-
(0, ow_1.default)(maxUnprocessedRequestsRetries, ow_1.default.optional.number);
|
|
342
|
-
(0, ow_1.default)(maxParallel, ow_1.default.optional.number);
|
|
343
|
-
(0, ow_1.default)(minDelayBetweenUnprocessedRequestsRetriesMillis, ow_1.default.optional.number);
|
|
361
|
+
(0, utils_1.parseArgument)(requests, batchAddRequestsWithRetriesSchema);
|
|
362
|
+
(0, utils_1.parseArgument)(forefront, optionalBooleanSchema);
|
|
363
|
+
(0, utils_1.parseArgument)(maxUnprocessedRequestsRetries, optionalNumberSchema);
|
|
364
|
+
(0, utils_1.parseArgument)(maxParallel, optionalNumberSchema);
|
|
365
|
+
(0, utils_1.parseArgument)(minDelayBetweenUnprocessedRequestsRetriesMillis, optionalNumberSchema);
|
|
344
366
|
const executingRequests = new Set();
|
|
345
367
|
const individualResults = [];
|
|
346
368
|
const payloadSizeLimitBytes = consts_1.MAX_PAYLOAD_SIZE_BYTES - Math.ceil(consts_1.MAX_PAYLOAD_SIZE_BYTES * SAFETY_BUFFER_PERCENT);
|
|
@@ -384,10 +406,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
384
406
|
* @since Added in 2.3.0
|
|
385
407
|
*/
|
|
386
408
|
async batchDeleteRequests(requests) {
|
|
387
|
-
(0,
|
|
388
|
-
.ofType(ow_1.default.any(ow_1.default.object.partialShape({ id: ow_1.default.string }), ow_1.default.object.partialShape({ uniqueKey: ow_1.default.string })))
|
|
389
|
-
.minLength(1)
|
|
390
|
-
.maxLength(consts_1.REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION));
|
|
409
|
+
(0, utils_1.parseArgument)(requests, batchDeleteRequestsSchema);
|
|
391
410
|
const { data } = await this.httpClient.call({
|
|
392
411
|
url: this._url('requests/batch'),
|
|
393
412
|
method: 'DELETE',
|
|
@@ -407,9 +426,9 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
407
426
|
* @see https://docs.apify.com/api/v2/request-queue-request-get
|
|
408
427
|
*/
|
|
409
428
|
async getRequest(id) {
|
|
410
|
-
(0,
|
|
429
|
+
(0, utils_1.parseArgument)(id, requestIdSchema);
|
|
411
430
|
const requestOpts = {
|
|
412
|
-
url: this._url(
|
|
431
|
+
url: this._url(['requests', id]),
|
|
413
432
|
method: 'GET',
|
|
414
433
|
timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
415
434
|
params: this._params(),
|
|
@@ -432,19 +451,15 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
432
451
|
* @see https://docs.apify.com/api/v2/request-queue-request-put
|
|
433
452
|
*/
|
|
434
453
|
async updateRequest(request, options = {}) {
|
|
435
|
-
(0,
|
|
436
|
-
|
|
437
|
-
}));
|
|
438
|
-
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
439
|
-
forefront: ow_1.default.optional.boolean,
|
|
440
|
-
}));
|
|
454
|
+
(0, utils_1.parseArgument)(request, existingRequestSchema);
|
|
455
|
+
const parsed = (0, utils_1.parseArgument)(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
441
456
|
const response = await this.httpClient.call({
|
|
442
|
-
url: this._url(
|
|
457
|
+
url: this._url(['requests', request.id]),
|
|
443
458
|
method: 'PUT',
|
|
444
459
|
timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
445
460
|
data: request,
|
|
446
461
|
params: this._params({
|
|
447
|
-
forefront:
|
|
462
|
+
forefront: parsed.forefront,
|
|
448
463
|
clientKey: this.clientKey,
|
|
449
464
|
}),
|
|
450
465
|
});
|
|
@@ -456,9 +471,9 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
456
471
|
* @param id - Request ID
|
|
457
472
|
*/
|
|
458
473
|
async deleteRequest(id) {
|
|
459
|
-
(0,
|
|
474
|
+
(0, utils_1.parseArgument)(id, requestIdSchema);
|
|
460
475
|
await this.httpClient.call({
|
|
461
|
-
url: this._url(
|
|
476
|
+
url: this._url(['requests', id]),
|
|
462
477
|
method: 'DELETE',
|
|
463
478
|
timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
464
479
|
params: this._params({
|
|
@@ -492,18 +507,15 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
492
507
|
* @since Added in 2.4.1
|
|
493
508
|
*/
|
|
494
509
|
async prolongRequestLock(id, options) {
|
|
495
|
-
(0,
|
|
496
|
-
(0,
|
|
497
|
-
lockSecs: ow_1.default.number,
|
|
498
|
-
forefront: ow_1.default.optional.boolean,
|
|
499
|
-
}));
|
|
510
|
+
(0, utils_1.parseArgument)(id, requestIdSchema);
|
|
511
|
+
const parsed = (0, utils_1.parseArgument)(options, prolongRequestLockOptionsSchema, 'RequestQueueClientProlongRequestLockOptions');
|
|
500
512
|
const response = await this.httpClient.call({
|
|
501
|
-
url: this._url(
|
|
513
|
+
url: this._url(['requests', id, 'lock']),
|
|
502
514
|
method: 'PUT',
|
|
503
515
|
timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
504
516
|
params: this._params({
|
|
505
|
-
forefront:
|
|
506
|
-
lockSecs:
|
|
517
|
+
forefront: parsed.forefront,
|
|
518
|
+
lockSecs: parsed.lockSecs,
|
|
507
519
|
clientKey: this.clientKey,
|
|
508
520
|
}),
|
|
509
521
|
});
|
|
@@ -521,16 +533,14 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
521
533
|
* @since Added in 2.4.1
|
|
522
534
|
*/
|
|
523
535
|
async deleteRequestLock(id, options = {}) {
|
|
524
|
-
(0,
|
|
525
|
-
(0,
|
|
526
|
-
forefront: ow_1.default.optional.boolean,
|
|
527
|
-
}));
|
|
536
|
+
(0, utils_1.parseArgument)(id, requestIdSchema);
|
|
537
|
+
const parsed = (0, utils_1.parseArgument)(options, forefrontOptionsSchema, 'RequestQueueClientDeleteRequestLockOptions');
|
|
528
538
|
await this.httpClient.call({
|
|
529
|
-
url: this._url(
|
|
539
|
+
url: this._url(['requests', id, 'lock']),
|
|
530
540
|
method: 'DELETE',
|
|
531
541
|
timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
532
542
|
params: this._params({
|
|
533
|
-
forefront:
|
|
543
|
+
forefront: parsed.forefront,
|
|
534
544
|
clientKey: this.clientKey,
|
|
535
545
|
}),
|
|
536
546
|
});
|
|
@@ -547,14 +557,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
547
557
|
* @since Added in 2.5.1
|
|
548
558
|
*/
|
|
549
559
|
listRequests(options = {}) {
|
|
550
|
-
(0,
|
|
551
|
-
.exactShape({
|
|
552
|
-
limit: ow_1.default.optional.number.not.negative,
|
|
553
|
-
exclusiveStartId: ow_1.default.optional.string,
|
|
554
|
-
cursor: ow_1.default.optional.string,
|
|
555
|
-
filter: ow_1.default.optional.array.ofType(ow_1.default.string.oneOf(['locked', 'pending'])).minLength(1),
|
|
556
|
-
})
|
|
557
|
-
.validate((0, utils_1.mutuallyExclusive)('exclusiveStartId', 'cursor')));
|
|
560
|
+
const parsed = (0, utils_1.parseArgument)(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
|
|
558
561
|
const getPaginatedList = async (rqListOptions = {}) => {
|
|
559
562
|
const response = await this.httpClient.call({
|
|
560
563
|
url: this._url('requests'),
|
|
@@ -568,11 +571,11 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
568
571
|
});
|
|
569
572
|
return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
|
|
570
573
|
};
|
|
571
|
-
const paginatedListPromise = getPaginatedList(
|
|
574
|
+
const paginatedListPromise = getPaginatedList(parsed);
|
|
572
575
|
async function* asyncGenerator() {
|
|
573
576
|
let currentPage = await paginatedListPromise;
|
|
574
577
|
yield* currentPage.items;
|
|
575
|
-
let remainingItems =
|
|
578
|
+
let remainingItems = parsed.limit ? parsed.limit - currentPage.items.length : undefined;
|
|
576
579
|
// RQ API response does not indicate whether there are more requests left, so we have to try and in case
|
|
577
580
|
// of exhausting all requests we get response with empty items which ends the loop.
|
|
578
581
|
while (currentPage.items.length > 0 && // Continue only if at least some items were returned in the last page.
|
|
@@ -580,7 +583,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
580
583
|
(remainingItems === undefined || remainingItems > 0) // Continue only if the limit was not exceeded.
|
|
581
584
|
) {
|
|
582
585
|
const newOptions = {
|
|
583
|
-
...
|
|
586
|
+
...parsed,
|
|
584
587
|
limit: remainingItems,
|
|
585
588
|
// remove original exclusiveStartId, if there was any, and use cursor-based pagination
|
|
586
589
|
exclusiveStartId: undefined,
|
|
@@ -637,16 +640,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
|
|
|
637
640
|
* @since Added in 2.5.1
|
|
638
641
|
*/
|
|
639
642
|
paginateRequests(options = {}) {
|
|
640
|
-
(0,
|
|
641
|
-
.exactShape({
|
|
642
|
-
limit: ow_1.default.optional.number.not.negative,
|
|
643
|
-
maxPageLimit: ow_1.default.optional.number,
|
|
644
|
-
exclusiveStartId: ow_1.default.optional.string,
|
|
645
|
-
cursor: ow_1.default.optional.string,
|
|
646
|
-
filter: ow_1.default.optional.array.ofType(ow_1.default.string.oneOf(['locked', 'pending'])).minLength(1),
|
|
647
|
-
})
|
|
648
|
-
.validate((0, utils_1.mutuallyExclusive)('exclusiveStartId', 'cursor')));
|
|
649
|
-
const { limit, exclusiveStartId, cursor, filter, maxPageLimit = DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT, } = options;
|
|
643
|
+
const { limit, exclusiveStartId, cursor, filter, maxPageLimit } = (0, utils_1.parseArgument)(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
|
|
650
644
|
return new utils_1.RequestQueuePaginationIterator({
|
|
651
645
|
getPage: async (pageOptions) => this.listRequests({ ...pageOptions, filter }),
|
|
652
646
|
limit,
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequestQueueCollectionClient = void 0;
|
|
4
|
-
const
|
|
5
|
-
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
4
|
+
const zod_1 = require("zod");
|
|
6
5
|
const consts_1 = require("@apify/consts");
|
|
7
6
|
const resource_collection_client_1 = require("../base/resource_collection_client");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const listOptionsSchema = zod_1.z.strictObject({
|
|
9
|
+
unnamed: zod_1.z.boolean().optional(),
|
|
10
|
+
...utils_1.paginationOptionsShape,
|
|
11
|
+
desc: zod_1.z.boolean().optional(),
|
|
12
|
+
ownership: zod_1.z.enum(consts_1.STORAGE_OWNERSHIP_FILTER).optional(),
|
|
13
|
+
});
|
|
14
|
+
const nameSchema = zod_1.z.string().optional();
|
|
8
15
|
/**
|
|
9
16
|
* Client for managing the collection of Request queues in your account.
|
|
10
17
|
*
|
|
@@ -56,14 +63,8 @@ class RequestQueueCollectionClient extends resource_collection_client_1.Resource
|
|
|
56
63
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
57
64
|
*/
|
|
58
65
|
list(options = {}) {
|
|
59
|
-
(0,
|
|
60
|
-
|
|
61
|
-
limit: ow_1.default.optional.number.not.negative,
|
|
62
|
-
offset: ow_1.default.optional.number.not.negative,
|
|
63
|
-
desc: ow_1.default.optional.boolean,
|
|
64
|
-
ownership: ow_1.default.optional.string.oneOf(Object.values(consts_1.STORAGE_OWNERSHIP_FILTER)),
|
|
65
|
-
}));
|
|
66
|
-
return this._listPaginated(options);
|
|
66
|
+
const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'RequestQueueCollectionListOptions');
|
|
67
|
+
return this._listPaginated(parsed);
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Gets or creates a Request queue with the specified name.
|
|
@@ -73,7 +74,7 @@ class RequestQueueCollectionClient extends resource_collection_client_1.Resource
|
|
|
73
74
|
* @see https://docs.apify.com/api/v2/request-queues-post
|
|
74
75
|
*/
|
|
75
76
|
async getOrCreate(name) {
|
|
76
|
-
(0,
|
|
77
|
+
(0, utils_1.parseArgument)(name, nameSchema);
|
|
77
78
|
return this._getOrCreate(name);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunClient = void 0;
|
|
4
|
-
const
|
|
5
|
-
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
4
|
+
const zod_1 = require("zod");
|
|
6
5
|
const log_1 = require("@apify/log");
|
|
7
6
|
const resource_client_1 = require("../base/resource_client");
|
|
8
7
|
const utils_1 = require("../utils");
|
|
@@ -11,6 +10,27 @@ const key_value_store_1 = require("./key_value_store");
|
|
|
11
10
|
const log_2 = require("./log");
|
|
12
11
|
const request_queue_1 = require("./request_queue");
|
|
13
12
|
const RUN_CHARGE_IDEMPOTENCY_HEADER = 'idempotency-key';
|
|
13
|
+
const getOptionsSchema = zod_1.z.strictObject({ waitForFinish: zod_1.z.number().optional() });
|
|
14
|
+
const abortOptionsSchema = zod_1.z.strictObject({ gracefully: zod_1.z.boolean().optional() });
|
|
15
|
+
const targetActorIdSchema = zod_1.z.string();
|
|
16
|
+
const metamorphOptionsSchema = zod_1.z.strictObject({
|
|
17
|
+
contentType: zod_1.z.string().optional(),
|
|
18
|
+
build: zod_1.z.string().optional(),
|
|
19
|
+
});
|
|
20
|
+
const resurrectOptionsSchema = zod_1.z.strictObject({
|
|
21
|
+
build: zod_1.z.string().optional(),
|
|
22
|
+
memory: zod_1.z.number().optional(),
|
|
23
|
+
timeout: zod_1.z.number().optional(),
|
|
24
|
+
maxItems: zod_1.z.number().optional(),
|
|
25
|
+
maxTotalChargeUsd: zod_1.z.number().optional(),
|
|
26
|
+
restartOnError: zod_1.z.boolean().optional(),
|
|
27
|
+
});
|
|
28
|
+
const chargeOptionsSchema = zod_1.z.strictObject({
|
|
29
|
+
eventName: zod_1.z.string(),
|
|
30
|
+
count: zod_1.z.number().default(1),
|
|
31
|
+
idempotencyKey: zod_1.z.string().optional(),
|
|
32
|
+
});
|
|
33
|
+
const waitForFinishOptionsSchema = zod_1.z.strictObject({ waitSecs: zod_1.z.number().optional() });
|
|
14
34
|
/**
|
|
15
35
|
* Client for managing a specific Actor run.
|
|
16
36
|
*
|
|
@@ -63,10 +83,8 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
63
83
|
* ```
|
|
64
84
|
*/
|
|
65
85
|
async get(options = {}) {
|
|
66
|
-
(0,
|
|
67
|
-
|
|
68
|
-
}));
|
|
69
|
-
return this._get(options);
|
|
86
|
+
const parsed = (0, utils_1.parseArgument)(options, getOptionsSchema, 'RunGetOptions');
|
|
87
|
+
return this._get(parsed);
|
|
70
88
|
}
|
|
71
89
|
/**
|
|
72
90
|
* Aborts the Actor run.
|
|
@@ -86,13 +104,11 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
86
104
|
* ```
|
|
87
105
|
*/
|
|
88
106
|
async abort(options = {}) {
|
|
89
|
-
(0,
|
|
90
|
-
gracefully: ow_1.default.optional.boolean,
|
|
91
|
-
}));
|
|
107
|
+
const parsed = (0, utils_1.parseArgument)(options, abortOptionsSchema, 'RunAbortOptions');
|
|
92
108
|
const response = await this.httpClient.call({
|
|
93
109
|
url: this._url('abort'),
|
|
94
110
|
method: 'POST',
|
|
95
|
-
params: this._params(
|
|
111
|
+
params: this._params(parsed),
|
|
96
112
|
});
|
|
97
113
|
return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
|
|
98
114
|
}
|
|
@@ -131,16 +147,13 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
131
147
|
* ```
|
|
132
148
|
*/
|
|
133
149
|
async metamorph(targetActorId, input, options = {}) {
|
|
134
|
-
(0,
|
|
150
|
+
(0, utils_1.parseArgument)(targetActorId, targetActorIdSchema);
|
|
135
151
|
// input can be anything, pointless to validate
|
|
136
|
-
(0,
|
|
137
|
-
contentType: ow_1.default.optional.string,
|
|
138
|
-
build: ow_1.default.optional.string,
|
|
139
|
-
}));
|
|
152
|
+
const parsed = (0, utils_1.parseArgument)(options, metamorphOptionsSchema, 'RunMetamorphOptions');
|
|
140
153
|
const safeTargetActorId = this._toSafeId(targetActorId);
|
|
141
154
|
const params = {
|
|
142
155
|
targetActorId: safeTargetActorId,
|
|
143
|
-
build:
|
|
156
|
+
build: parsed.build,
|
|
144
157
|
};
|
|
145
158
|
const request = {
|
|
146
159
|
url: this._url('metamorph'),
|
|
@@ -153,9 +166,9 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
153
166
|
// @ts-expect-error Custom Apify property
|
|
154
167
|
stringifyFunctions: true,
|
|
155
168
|
};
|
|
156
|
-
if (
|
|
169
|
+
if (parsed.contentType) {
|
|
157
170
|
request.headers = {
|
|
158
|
-
'content-type':
|
|
171
|
+
'content-type': parsed.contentType,
|
|
159
172
|
};
|
|
160
173
|
}
|
|
161
174
|
const response = await this.httpClient.call(request);
|
|
@@ -204,7 +217,7 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
204
217
|
* @since Added in 2.6.0
|
|
205
218
|
*/
|
|
206
219
|
async update(newFields) {
|
|
207
|
-
(0,
|
|
220
|
+
(0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
|
|
208
221
|
return this._update(newFields);
|
|
209
222
|
}
|
|
210
223
|
/**
|
|
@@ -231,18 +244,11 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
231
244
|
* ```
|
|
232
245
|
*/
|
|
233
246
|
async resurrect(options = {}) {
|
|
234
|
-
(0,
|
|
235
|
-
build: ow_1.default.optional.string,
|
|
236
|
-
memory: ow_1.default.optional.number,
|
|
237
|
-
timeout: ow_1.default.optional.number,
|
|
238
|
-
maxItems: ow_1.default.optional.number,
|
|
239
|
-
maxTotalChargeUsd: ow_1.default.optional.number,
|
|
240
|
-
restartOnError: ow_1.default.optional.boolean,
|
|
241
|
-
}));
|
|
247
|
+
const parsed = (0, utils_1.parseArgument)(options, resurrectOptionsSchema, 'RunResurrectOptions');
|
|
242
248
|
const response = await this.httpClient.call({
|
|
243
249
|
url: this._url('resurrect'),
|
|
244
250
|
method: 'POST',
|
|
245
|
-
params: this._params(
|
|
251
|
+
params: this._params(parsed),
|
|
246
252
|
});
|
|
247
253
|
return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
|
|
248
254
|
}
|
|
@@ -258,20 +264,15 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
258
264
|
* @since Added in 2.11.0
|
|
259
265
|
*/
|
|
260
266
|
async charge(options) {
|
|
261
|
-
(0,
|
|
262
|
-
eventName: ow_1.default.string,
|
|
263
|
-
count: ow_1.default.optional.number,
|
|
264
|
-
idempotencyKey: ow_1.default.optional.string,
|
|
265
|
-
}));
|
|
266
|
-
const count = options.count ?? 1;
|
|
267
|
+
const { eventName, count, idempotencyKey: providedIdempotencyKey, } = (0, utils_1.parseArgument)(options, chargeOptionsSchema, 'RunChargeOptions');
|
|
267
268
|
/** To avoid duplicates during the same milisecond, doesn't need to by crypto-secure. */
|
|
268
269
|
const randomSuffix = (Math.random() + 1).toString(36).slice(3, 8);
|
|
269
|
-
const idempotencyKey =
|
|
270
|
+
const idempotencyKey = providedIdempotencyKey ?? `${this.id}-${eventName}-${Date.now()}-${randomSuffix}`;
|
|
270
271
|
const request = {
|
|
271
272
|
url: this._url('charge'),
|
|
272
273
|
method: 'POST',
|
|
273
274
|
data: {
|
|
274
|
-
eventName
|
|
275
|
+
eventName,
|
|
275
276
|
count,
|
|
276
277
|
},
|
|
277
278
|
headers: {
|
|
@@ -310,10 +311,8 @@ class RunClient extends resource_client_1.ResourceClient {
|
|
|
310
311
|
* ```
|
|
311
312
|
*/
|
|
312
313
|
async waitForFinish(options = {}) {
|
|
313
|
-
(0,
|
|
314
|
-
|
|
315
|
-
}));
|
|
316
|
-
return this._waitForFinish(options);
|
|
314
|
+
const parsed = (0, utils_1.parseArgument)(options, waitForFinishOptionsSchema, 'RunWaitForFinishOptions');
|
|
315
|
+
return this._waitForFinish(parsed);
|
|
317
316
|
}
|
|
318
317
|
/**
|
|
319
318
|
* Returns a client for the default dataset of this Actor run.
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunCollectionClient = void 0;
|
|
4
|
-
const
|
|
5
|
-
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
4
|
+
const zod_1 = require("zod");
|
|
6
5
|
const consts_1 = require("@apify/consts");
|
|
7
6
|
const resource_collection_client_1 = require("../base/resource_collection_client");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const jobStatusSchema = zod_1.z.enum(consts_1.ACTOR_JOB_STATUSES);
|
|
9
|
+
const listOptionsSchema = zod_1.z.strictObject({
|
|
10
|
+
...utils_1.paginationOptionsShape,
|
|
11
|
+
desc: zod_1.z.boolean().optional(),
|
|
12
|
+
status: zod_1.z.union([jobStatusSchema, zod_1.z.array(jobStatusSchema)]).optional(),
|
|
13
|
+
startedBefore: zod_1.z.union([zod_1.z.date(), zod_1.z.string()]).optional(),
|
|
14
|
+
startedAfter: zod_1.z.union([zod_1.z.date(), zod_1.z.string()]).optional(),
|
|
15
|
+
});
|
|
8
16
|
/**
|
|
9
17
|
* Client for managing the collection of Actor runs.
|
|
10
18
|
*
|
|
@@ -57,15 +65,8 @@ class RunCollectionClient extends resource_collection_client_1.ResourceCollectio
|
|
|
57
65
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
58
66
|
*/
|
|
59
67
|
list(options = {}) {
|
|
60
|
-
(0,
|
|
61
|
-
|
|
62
|
-
offset: ow_1.default.optional.number.not.negative,
|
|
63
|
-
desc: ow_1.default.optional.boolean,
|
|
64
|
-
status: ow_1.default.optional.any(ow_1.default.string.oneOf(Object.values(consts_1.ACTOR_JOB_STATUSES)), ow_1.default.array.ofType(ow_1.default.string.oneOf(Object.values(consts_1.ACTOR_JOB_STATUSES)))),
|
|
65
|
-
startedBefore: ow_1.default.optional.any(ow_1.default.optional.date, ow_1.default.optional.string),
|
|
66
|
-
startedAfter: ow_1.default.optional.any(ow_1.default.optional.date, ow_1.default.optional.string),
|
|
67
|
-
}));
|
|
68
|
-
return this._listPaginated(options);
|
|
68
|
+
const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'RunCollectionListOptions');
|
|
69
|
+
return this._listPaginated(parsed);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
exports.RunCollectionClient = RunCollectionClient;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScheduleActions = exports.ScheduleClient = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
6
4
|
const resource_client_1 = require("../base/resource_client");
|
|
7
5
|
const utils_1 = require("../utils");
|
|
8
6
|
/**
|
|
@@ -55,7 +53,7 @@ class ScheduleClient extends resource_client_1.ResourceClient {
|
|
|
55
53
|
* @see https://docs.apify.com/api/v2/schedule-put
|
|
56
54
|
*/
|
|
57
55
|
async update(newFields) {
|
|
58
|
-
(0,
|
|
56
|
+
(0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
|
|
59
57
|
return this._update(newFields);
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScheduleCollectionClient = void 0;
|
|
4
|
-
const
|
|
5
|
-
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
4
|
+
const zod_1 = require("zod");
|
|
6
5
|
const resource_collection_client_1 = require("../base/resource_collection_client");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const listOptionsSchema = zod_1.z.strictObject({
|
|
8
|
+
...utils_1.paginationOptionsShape,
|
|
9
|
+
desc: zod_1.z.boolean().optional(),
|
|
10
|
+
});
|
|
11
|
+
const scheduleCreateSchema = utils_1.anyObjectSchema.optional();
|
|
7
12
|
/**
|
|
8
13
|
* Client for managing the collection of Schedules in your account.
|
|
9
14
|
*
|
|
@@ -59,12 +64,8 @@ class ScheduleCollectionClient extends resource_collection_client_1.ResourceColl
|
|
|
59
64
|
* @see https://docs.apify.com/api/v2/schedules-get
|
|
60
65
|
*/
|
|
61
66
|
list(options = {}) {
|
|
62
|
-
(0,
|
|
63
|
-
|
|
64
|
-
offset: ow_1.default.optional.number.not.negative,
|
|
65
|
-
desc: ow_1.default.optional.boolean,
|
|
66
|
-
}));
|
|
67
|
-
return this._listPaginated(options);
|
|
67
|
+
const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'ScheduleCollectionListOptions');
|
|
68
|
+
return this._listPaginated(parsed);
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* Creates a new schedule.
|
|
@@ -74,7 +75,7 @@ class ScheduleCollectionClient extends resource_collection_client_1.ResourceColl
|
|
|
74
75
|
* @see https://docs.apify.com/api/v2/schedules-post
|
|
75
76
|
*/
|
|
76
77
|
async create(schedule) {
|
|
77
|
-
(0,
|
|
78
|
+
(0, utils_1.parseArgument)(schedule, scheduleCreateSchema);
|
|
78
79
|
return this._create(schedule);
|
|
79
80
|
}
|
|
80
81
|
}
|