apify-client 3.0.0-beta.4 → 3.0.0-beta.5
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/base/resource_client.d.ts +4 -3
- package/dist/base/resource_client.js +7 -7
- package/dist/base/resource_collection_client.d.ts +5 -4
- package/dist/base/resource_collection_client.js +9 -9
- package/dist/bundle.js +15 -13
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +15 -40
- package/dist/resource_clients/actor.js +7 -6
- package/dist/resource_clients/actor_collection.js +3 -2
- package/dist/resource_clients/actor_env_var.js +3 -2
- package/dist/resource_clients/actor_env_var_collection.js +3 -2
- package/dist/resource_clients/actor_version.js +3 -2
- package/dist/resource_clients/actor_version_collection.js +3 -2
- package/dist/resource_clients/build.js +5 -4
- package/dist/resource_clients/build_collection.js +2 -1
- package/dist/resource_clients/dataset.js +5 -4
- package/dist/resource_clients/dataset_collection.js +3 -2
- package/dist/resource_clients/key_value_store.js +5 -4
- package/dist/resource_clients/key_value_store_collection.js +3 -2
- package/dist/resource_clients/request_queue.js +24 -16
- package/dist/resource_clients/request_queue_collection.js +3 -2
- package/dist/resource_clients/run.js +9 -8
- package/dist/resource_clients/run_collection.js +2 -1
- package/dist/resource_clients/schedule.d.ts +4 -4
- package/dist/resource_clients/schedule.js +8 -5
- package/dist/resource_clients/schedule_collection.js +3 -2
- package/dist/resource_clients/store_collection.js +2 -1
- package/dist/resource_clients/task.js +5 -4
- package/dist/resource_clients/task_collection.js +3 -2
- package/dist/resource_clients/user.js +6 -6
- package/dist/resource_clients/webhook.js +5 -4
- package/dist/resource_clients/webhook_collection.js +3 -2
- package/dist/resource_clients/webhook_dispatch.js +2 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +2 -1
- 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/utils.d.ts +11 -0
- package/dist/utils.js +23 -0
- package/package.json +3 -3
|
@@ -2,7 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
import { MAX_PAYLOAD_SIZE_BYTES, REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION } from '@apify/consts';
|
|
3
3
|
import log from '@apify/log';
|
|
4
4
|
import { MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS } from '../base/resource_client.js';
|
|
5
|
-
import {
|
|
5
|
+
import { ResponseValidationError } from '../response_validation_error.js';
|
|
6
|
+
import * as schemas from '../schemas.js';
|
|
7
|
+
import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject, mutuallyExclusive, parseArgument, parseDateFields, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
|
|
6
8
|
const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
|
|
7
9
|
const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
|
|
8
10
|
const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
|
|
@@ -101,7 +103,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
101
103
|
* @see https://docs.apify.com/api/v2/request-queue-get
|
|
102
104
|
*/
|
|
103
105
|
async get() {
|
|
104
|
-
return this._get({}, SMALL_TIMEOUT_MILLIS);
|
|
106
|
+
return this._get(schemas.RequestQueue(), {}, SMALL_TIMEOUT_MILLIS);
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
107
109
|
* Updates the Request queue with specified fields.
|
|
@@ -112,7 +114,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
112
114
|
*/
|
|
113
115
|
async update(newFields) {
|
|
114
116
|
parseArgument(newFields, anyObjectSchema);
|
|
115
|
-
return this._update(newFields, SMALL_TIMEOUT_MILLIS);
|
|
117
|
+
return this._update(schemas.RequestQueue(), newFields, SMALL_TIMEOUT_MILLIS);
|
|
116
118
|
}
|
|
117
119
|
/**
|
|
118
120
|
* Deletes the Request queue.
|
|
@@ -143,7 +145,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
143
145
|
clientKey: this.clientKey,
|
|
144
146
|
}),
|
|
145
147
|
});
|
|
146
|
-
return
|
|
148
|
+
return parseResponse(response, schemas.RequestQueueHead());
|
|
147
149
|
}
|
|
148
150
|
/**
|
|
149
151
|
* Gets and locks the next requests from the queue head for processing.
|
|
@@ -190,7 +192,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
190
192
|
clientKey: this.clientKey,
|
|
191
193
|
}),
|
|
192
194
|
});
|
|
193
|
-
return
|
|
195
|
+
return parseResponse(response, schemas.LockedRequestQueueHead());
|
|
194
196
|
}
|
|
195
197
|
/**
|
|
196
198
|
* Adds a single request to the queue.
|
|
@@ -243,7 +245,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
243
245
|
clientKey: this.clientKey,
|
|
244
246
|
}),
|
|
245
247
|
});
|
|
246
|
-
return
|
|
248
|
+
return parseResponse(response, schemas.RequestRegistration());
|
|
247
249
|
}
|
|
248
250
|
/**
|
|
249
251
|
* Writes requests to Request queue in batch.
|
|
@@ -253,7 +255,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
253
255
|
async _batchAddRequests(requests, options = {}) {
|
|
254
256
|
parseArgument(requests, batchAddRequestsSchema);
|
|
255
257
|
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
256
|
-
const
|
|
258
|
+
const response = await this.httpClient.call({
|
|
257
259
|
url: this._url('requests/batch'),
|
|
258
260
|
method: 'POST',
|
|
259
261
|
timeout: Math.min(MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
@@ -263,7 +265,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
263
265
|
clientKey: this.clientKey,
|
|
264
266
|
}),
|
|
265
267
|
});
|
|
266
|
-
return
|
|
268
|
+
return parseResponse(response, schemas.BatchAddResult());
|
|
267
269
|
}
|
|
268
270
|
async _batchAddRequestsWithRetries(requests, options = {}) {
|
|
269
271
|
const { forefront, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
@@ -296,6 +298,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
300
|
catch (err) {
|
|
301
|
+
// A response the specification does not describe is reported, as everywhere else: the server may well
|
|
302
|
+
// have added the batch, so calling it unprocessed would hide the mismatch behind a wrong answer.
|
|
303
|
+
if (err instanceof ResponseValidationError)
|
|
304
|
+
throw err;
|
|
299
305
|
log.exception(err, 'Request batch insert failed');
|
|
300
306
|
// When something fails and http client does not retry, the remaining requests are treated as unprocessed.
|
|
301
307
|
// This ensures that this method does not throw and keeps the signature.
|
|
@@ -369,10 +375,12 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
369
375
|
const requestsInBatch = sliceArrayByByteLength(slicedRequests, payloadSizeLimitBytes, i);
|
|
370
376
|
const requestPromise = this._batchAddRequestsWithRetries(requestsInBatch, options);
|
|
371
377
|
executingRequests.add(requestPromise);
|
|
378
|
+
// A rejection reaches the caller through the awaits below; this bookkeeping chain only has to avoid
|
|
379
|
+
// turning it into an unhandled one of its own.
|
|
372
380
|
void requestPromise.then((batchAddResult) => {
|
|
373
381
|
executingRequests.delete(requestPromise);
|
|
374
382
|
individualResults.push(batchAddResult);
|
|
375
|
-
});
|
|
383
|
+
}, () => undefined);
|
|
376
384
|
if (executingRequests.size >= maxParallel) {
|
|
377
385
|
await Promise.race(executingRequests);
|
|
378
386
|
}
|
|
@@ -403,7 +411,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
403
411
|
*/
|
|
404
412
|
async batchDeleteRequests(requests) {
|
|
405
413
|
parseArgument(requests, batchDeleteRequestsSchema);
|
|
406
|
-
const
|
|
414
|
+
const response = await this.httpClient.call({
|
|
407
415
|
url: this._url('requests/batch'),
|
|
408
416
|
method: 'DELETE',
|
|
409
417
|
timeout: Math.min(SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
|
|
@@ -412,7 +420,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
412
420
|
clientKey: this.clientKey,
|
|
413
421
|
}),
|
|
414
422
|
});
|
|
415
|
-
return
|
|
423
|
+
return parseResponse(response, schemas.BatchDeleteResult());
|
|
416
424
|
}
|
|
417
425
|
/**
|
|
418
426
|
* Gets a specific request from the queue by its ID.
|
|
@@ -431,7 +439,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
431
439
|
};
|
|
432
440
|
try {
|
|
433
441
|
const response = await this.httpClient.call(requestOpts);
|
|
434
|
-
return
|
|
442
|
+
return parseResponse(response, schemas.Request());
|
|
435
443
|
}
|
|
436
444
|
catch (err) {
|
|
437
445
|
catchNotFoundOrThrow(err);
|
|
@@ -459,7 +467,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
459
467
|
clientKey: this.clientKey,
|
|
460
468
|
}),
|
|
461
469
|
});
|
|
462
|
-
return
|
|
470
|
+
return parseResponse(response, schemas.RequestRegistration());
|
|
463
471
|
}
|
|
464
472
|
/**
|
|
465
473
|
* Deletes a specific request from the queue.
|
|
@@ -515,7 +523,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
515
523
|
clientKey: this.clientKey,
|
|
516
524
|
}),
|
|
517
525
|
});
|
|
518
|
-
return
|
|
526
|
+
return parseResponse(response, schemas.RequestLockInfo());
|
|
519
527
|
}
|
|
520
528
|
/**
|
|
521
529
|
* Releases the lock on a request, allowing other clients to process it.
|
|
@@ -565,7 +573,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
565
573
|
clientKey: this.clientKey,
|
|
566
574
|
}),
|
|
567
575
|
});
|
|
568
|
-
return
|
|
576
|
+
return parseResponse(response, schemas.ListOfRequests());
|
|
569
577
|
};
|
|
570
578
|
const paginatedListPromise = getPaginatedList(parsed);
|
|
571
579
|
async function* asyncGenerator() {
|
|
@@ -615,7 +623,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
615
623
|
clientKey: this.clientKey,
|
|
616
624
|
}),
|
|
617
625
|
});
|
|
618
|
-
return
|
|
626
|
+
return parseResponse(response, schemas.UnlockRequestsResult());
|
|
619
627
|
}
|
|
620
628
|
/**
|
|
621
629
|
* Returns an async iterable for paginating through all requests in the queue.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
4
5
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
6
|
const listOptionsSchema = z.strictObject({
|
|
6
7
|
unnamed: z.boolean().optional(),
|
|
@@ -61,7 +62,7 @@ export class RequestQueueCollectionClient extends ResourceCollectionClient {
|
|
|
61
62
|
*/
|
|
62
63
|
list(options = {}) {
|
|
63
64
|
const parsed = parseArgument(options, listOptionsSchema, 'RequestQueueCollectionListOptions');
|
|
64
|
-
return this._listPaginated(parsed);
|
|
65
|
+
return this._listPaginated(schemas.ListOfRequestQueues(), parsed);
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Gets or creates a Request queue with the specified name.
|
|
@@ -72,6 +73,6 @@ export class RequestQueueCollectionClient extends ResourceCollectionClient {
|
|
|
72
73
|
*/
|
|
73
74
|
async getOrCreate(name) {
|
|
74
75
|
parseArgument(name, nameSchema);
|
|
75
|
-
return this._getOrCreate(name);
|
|
76
|
+
return this._getOrCreate(schemas.RequestQueue(), name);
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { LEVELS, Log } from '@apify/log';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
-
import
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { anyObjectSchema, isNode, parseArgument, parseResponse } from '../utils.js';
|
|
5
6
|
import { DatasetClient } from './dataset.js';
|
|
6
7
|
import { KeyValueStoreClient } from './key_value_store.js';
|
|
7
8
|
import { LogClient, LoggerActorRedirect, StreamedLog } from './log.js';
|
|
@@ -81,7 +82,7 @@ export class RunClient extends ResourceClient {
|
|
|
81
82
|
*/
|
|
82
83
|
async get(options = {}) {
|
|
83
84
|
const parsed = parseArgument(options, getOptionsSchema, 'RunGetOptions');
|
|
84
|
-
return this._get(parsed);
|
|
85
|
+
return this._get(schemas.Run(), parsed);
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
88
|
* Aborts the Actor run.
|
|
@@ -107,7 +108,7 @@ export class RunClient extends ResourceClient {
|
|
|
107
108
|
method: 'POST',
|
|
108
109
|
params: this._params(parsed),
|
|
109
110
|
});
|
|
110
|
-
return
|
|
111
|
+
return parseResponse(response, schemas.Run());
|
|
111
112
|
}
|
|
112
113
|
/**
|
|
113
114
|
* Deletes the Actor run.
|
|
@@ -169,7 +170,7 @@ export class RunClient extends ResourceClient {
|
|
|
169
170
|
};
|
|
170
171
|
}
|
|
171
172
|
const response = await this.httpClient.call(request);
|
|
172
|
-
return
|
|
173
|
+
return parseResponse(response, schemas.Run());
|
|
173
174
|
}
|
|
174
175
|
/**
|
|
175
176
|
* Reboots the Actor run.
|
|
@@ -193,7 +194,7 @@ export class RunClient extends ResourceClient {
|
|
|
193
194
|
method: 'POST',
|
|
194
195
|
};
|
|
195
196
|
const response = await this.httpClient.call(request);
|
|
196
|
-
return
|
|
197
|
+
return parseResponse(response, schemas.Run());
|
|
197
198
|
}
|
|
198
199
|
/**
|
|
199
200
|
* Updates the Actor run with specified fields.
|
|
@@ -215,7 +216,7 @@ export class RunClient extends ResourceClient {
|
|
|
215
216
|
*/
|
|
216
217
|
async update(newFields) {
|
|
217
218
|
parseArgument(newFields, anyObjectSchema);
|
|
218
|
-
return this._update(newFields);
|
|
219
|
+
return this._update(schemas.Run(), newFields);
|
|
219
220
|
}
|
|
220
221
|
/**
|
|
221
222
|
* Resurrects a finished Actor run, starting it again with the same settings.
|
|
@@ -247,7 +248,7 @@ export class RunClient extends ResourceClient {
|
|
|
247
248
|
method: 'POST',
|
|
248
249
|
params: this._params(parsed),
|
|
249
250
|
});
|
|
250
|
-
return
|
|
251
|
+
return parseResponse(response, schemas.Run());
|
|
251
252
|
}
|
|
252
253
|
/**
|
|
253
254
|
* Charges the Actor run for a specific event.
|
|
@@ -309,7 +310,7 @@ export class RunClient extends ResourceClient {
|
|
|
309
310
|
*/
|
|
310
311
|
async waitForFinish(options = {}) {
|
|
311
312
|
const parsed = parseArgument(options, waitForFinishOptionsSchema, 'RunWaitForFinishOptions');
|
|
312
|
-
return this._waitForFinish(parsed);
|
|
313
|
+
return this._waitForFinish(schemas.Run(), parsed);
|
|
313
314
|
}
|
|
314
315
|
/**
|
|
315
316
|
* Returns a client for the default dataset of this Actor run.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ACTOR_JOB_STATUSES } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
4
5
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
6
|
const jobStatusSchema = z.enum(ACTOR_JOB_STATUSES);
|
|
6
7
|
const listOptionsSchema = z.strictObject({
|
|
@@ -63,6 +64,6 @@ export class RunCollectionClient extends ResourceCollectionClient {
|
|
|
63
64
|
*/
|
|
64
65
|
list(options = {}) {
|
|
65
66
|
const parsed = parseArgument(options, listOptionsSchema, 'RunCollectionListOptions');
|
|
66
|
-
return this._listPaginated(parsed);
|
|
67
|
+
return this._listPaginated(schemas.ListOfRuns(), parsed);
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
-
import type { Schedule, ScheduleAction } from '../models.js';
|
|
3
|
+
import type { Schedule, ScheduleAction, ScheduleInvoked } from '../models.js';
|
|
4
4
|
import type { DistributiveOptional } from '../utils.js';
|
|
5
|
-
export type { Schedule, ScheduleAction, ScheduleActionRunActor, ScheduleActionRunActorTask, ScheduledActorRunInput, ScheduledActorRunOptions, } from '../models.js';
|
|
5
|
+
export type { Schedule, ScheduleAction, ScheduleActionRunActor, ScheduleActionRunActorTask, ScheduledActorRunInput, ScheduledActorRunOptions, ScheduleInvoked, } from '../models.js';
|
|
6
6
|
export { ScheduleActions } from '../models.js';
|
|
7
7
|
/**
|
|
8
8
|
* Client for managing a specific Schedule.
|
|
@@ -56,10 +56,10 @@ export declare class ScheduleClient extends ResourceClient {
|
|
|
56
56
|
/**
|
|
57
57
|
* Retrieves the schedule's log.
|
|
58
58
|
*
|
|
59
|
-
* @returns The schedule log
|
|
59
|
+
* @returns The schedule log, one entry per invocation, or `undefined` if the schedule does not exist.
|
|
60
60
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
61
61
|
*/
|
|
62
|
-
getLog(): Promise<
|
|
62
|
+
getLog(): Promise<ScheduleInvoked[] | undefined>;
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Data for creating or updating a Schedule.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
-
import
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
4
|
+
import { anyObjectSchema, catchNotFoundOrThrow, parseArgument, parseResponse } from '../utils.js';
|
|
3
5
|
export { ScheduleActions } from '../models.js';
|
|
6
|
+
const scheduleLogSchema = z.array(schemas.ScheduleInvoked());
|
|
4
7
|
/**
|
|
5
8
|
* Client for managing a specific Schedule.
|
|
6
9
|
*
|
|
@@ -41,7 +44,7 @@ export class ScheduleClient extends ResourceClient {
|
|
|
41
44
|
* @see https://docs.apify.com/api/v2/schedule-get
|
|
42
45
|
*/
|
|
43
46
|
async get() {
|
|
44
|
-
return this._get();
|
|
47
|
+
return this._get(schemas.Schedule());
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
50
|
* Updates the schedule with the specified fields.
|
|
@@ -52,7 +55,7 @@ export class ScheduleClient extends ResourceClient {
|
|
|
52
55
|
*/
|
|
53
56
|
async update(newFields) {
|
|
54
57
|
parseArgument(newFields, anyObjectSchema);
|
|
55
|
-
return this._update(newFields);
|
|
58
|
+
return this._update(schemas.Schedule(), newFields);
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
58
61
|
* Deletes the schedule.
|
|
@@ -65,7 +68,7 @@ export class ScheduleClient extends ResourceClient {
|
|
|
65
68
|
/**
|
|
66
69
|
* Retrieves the schedule's log.
|
|
67
70
|
*
|
|
68
|
-
* @returns The schedule log
|
|
71
|
+
* @returns The schedule log, one entry per invocation, or `undefined` if the schedule does not exist.
|
|
69
72
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
70
73
|
*/
|
|
71
74
|
async getLog() {
|
|
@@ -76,7 +79,7 @@ export class ScheduleClient extends ResourceClient {
|
|
|
76
79
|
};
|
|
77
80
|
try {
|
|
78
81
|
const response = await this.httpClient.call(requestOpts);
|
|
79
|
-
return
|
|
82
|
+
return parseResponse(response, scheduleLogSchema);
|
|
80
83
|
}
|
|
81
84
|
catch (err) {
|
|
82
85
|
catchNotFoundOrThrow(err);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
3
4
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
5
|
const listOptionsSchema = z.strictObject({
|
|
5
6
|
...paginationOptionsShape,
|
|
@@ -62,7 +63,7 @@ export class ScheduleCollectionClient extends ResourceCollectionClient {
|
|
|
62
63
|
*/
|
|
63
64
|
list(options = {}) {
|
|
64
65
|
const parsed = parseArgument(options, listOptionsSchema, 'ScheduleCollectionListOptions');
|
|
65
|
-
return this._listPaginated(parsed);
|
|
66
|
+
return this._listPaginated(schemas.ListOfSchedules(), parsed);
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* Creates a new schedule.
|
|
@@ -73,6 +74,6 @@ export class ScheduleCollectionClient extends ResourceCollectionClient {
|
|
|
73
74
|
*/
|
|
74
75
|
async create(schedule) {
|
|
75
76
|
parseArgument(schedule, scheduleCreateSchema);
|
|
76
|
-
return this._create(schedule);
|
|
77
|
+
return this._create(schemas.Schedule(), schedule);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
3
4
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
5
|
const listOptionsSchema = z.strictObject({
|
|
5
6
|
...paginationOptionsShape,
|
|
@@ -63,6 +64,6 @@ export class StoreCollectionClient extends ResourceCollectionClient {
|
|
|
63
64
|
*/
|
|
64
65
|
list(options = {}) {
|
|
65
66
|
const parsed = parseArgument(options, listOptionsSchema, 'StoreCollectionListOptions');
|
|
66
|
-
return this._listPaginated(parsed);
|
|
67
|
+
return this._listPaginated(schemas.ListOfStoreActors(), parsed);
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ACT_JOB_STATUSES, META_ORIGINS } from '@apify/consts';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
-
import
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { anyObjectSchema, cast, catchNotFoundOrThrow, parseArgument, parseResponse, stringifyWebhooksToBase64, } from '../utils.js';
|
|
5
6
|
import { RunClient } from './run.js';
|
|
6
7
|
import { RunCollectionClient } from './run_collection.js';
|
|
7
8
|
import { WebhookCollectionClient } from './webhook_collection.js';
|
|
@@ -67,7 +68,7 @@ export class TaskClient extends ResourceClient {
|
|
|
67
68
|
* @see https://docs.apify.com/api/v2/actor-task-get
|
|
68
69
|
*/
|
|
69
70
|
async get() {
|
|
70
|
-
return this._get();
|
|
71
|
+
return this._get(schemas.Task());
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
* Updates the task with the specified fields.
|
|
@@ -78,7 +79,7 @@ export class TaskClient extends ResourceClient {
|
|
|
78
79
|
*/
|
|
79
80
|
async update(newFields) {
|
|
80
81
|
parseArgument(newFields, anyObjectSchema);
|
|
81
|
-
return this._update(newFields);
|
|
82
|
+
return this._update(schemas.Task(), newFields);
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* Publishes the task on its public landing page, by setting `isPublic` through
|
|
@@ -161,7 +162,7 @@ export class TaskClient extends ResourceClient {
|
|
|
161
162
|
},
|
|
162
163
|
};
|
|
163
164
|
const response = await this.httpClient.call(request);
|
|
164
|
-
return
|
|
165
|
+
return parseResponse(response, schemas.Run());
|
|
165
166
|
}
|
|
166
167
|
/**
|
|
167
168
|
* Starts a task and waits for it to finish before returning the Run object.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
3
4
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
5
|
const listOptionsSchema = z.strictObject({
|
|
5
6
|
...paginationOptionsShape,
|
|
@@ -61,7 +62,7 @@ export class TaskCollectionClient extends ResourceCollectionClient {
|
|
|
61
62
|
*/
|
|
62
63
|
list(options = {}) {
|
|
63
64
|
const parsed = parseArgument(options, listOptionsSchema, 'TaskCollectionListOptions');
|
|
64
|
-
return this._listPaginated(parsed);
|
|
65
|
+
return this._listPaginated(schemas.ListOfTasks(), parsed);
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Creates a new task.
|
|
@@ -72,6 +73,6 @@ export class TaskCollectionClient extends ResourceCollectionClient {
|
|
|
72
73
|
*/
|
|
73
74
|
async create(task) {
|
|
74
75
|
parseArgument(task, anyObjectSchema);
|
|
75
|
-
return this._create(task);
|
|
76
|
+
return this._create(schemas.Task(), task);
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
-
import
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
3
|
+
import { catchNotFoundOrThrow, parseResponse } from '../utils.js';
|
|
3
4
|
export { PlatformFeature } from '../models.js';
|
|
4
5
|
/**
|
|
5
6
|
* Client for managing user account information.
|
|
@@ -45,7 +46,7 @@ export class UserClient extends ResourceClient {
|
|
|
45
46
|
* @see https://docs.apify.com/api/v2/user-get
|
|
46
47
|
*/
|
|
47
48
|
async get() {
|
|
48
|
-
return this._get();
|
|
49
|
+
return this._get(schemas.UserPrivateInfo());
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Retrieves the user's monthly usage data.
|
|
@@ -62,9 +63,8 @@ export class UserClient extends ResourceClient {
|
|
|
62
63
|
};
|
|
63
64
|
try {
|
|
64
65
|
const response = await this.httpClient.call(requestOpts);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/* shouldParseField = */ (key) => key === 'date'));
|
|
66
|
+
// `dailyServiceUsages[].date` does not end in `At`, so it has to be named for `parseDateFields`.
|
|
67
|
+
return parseResponse(response, schemas.MonthlyUsage(), (key) => key === 'date');
|
|
68
68
|
}
|
|
69
69
|
catch (err) {
|
|
70
70
|
catchNotFoundOrThrow(err);
|
|
@@ -86,7 +86,7 @@ export class UserClient extends ResourceClient {
|
|
|
86
86
|
};
|
|
87
87
|
try {
|
|
88
88
|
const response = await this.httpClient.call(requestOpts);
|
|
89
|
-
return
|
|
89
|
+
return parseResponse(response, schemas.AccountLimits());
|
|
90
90
|
}
|
|
91
91
|
catch (err) {
|
|
92
92
|
catchNotFoundOrThrow(err);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
-
import
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
3
|
+
import { anyObjectSchema, catchNotFoundOrThrow, parseArgument, parseResponse } from '../utils.js';
|
|
3
4
|
import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
|
|
4
5
|
/**
|
|
5
6
|
* Client for managing a specific webhook.
|
|
@@ -46,7 +47,7 @@ export class WebhookClient extends ResourceClient {
|
|
|
46
47
|
* @see https://docs.apify.com/api/v2/webhook-get
|
|
47
48
|
*/
|
|
48
49
|
async get() {
|
|
49
|
-
return this._get();
|
|
50
|
+
return this._get(schemas.Webhook());
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
53
|
* Updates the webhook with the specified fields.
|
|
@@ -57,7 +58,7 @@ export class WebhookClient extends ResourceClient {
|
|
|
57
58
|
*/
|
|
58
59
|
async update(newFields) {
|
|
59
60
|
parseArgument(newFields, anyObjectSchema);
|
|
60
|
-
return this._update(newFields);
|
|
61
|
+
return this._update(schemas.Webhook(), newFields);
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
64
|
* Deletes the webhook.
|
|
@@ -81,7 +82,7 @@ export class WebhookClient extends ResourceClient {
|
|
|
81
82
|
};
|
|
82
83
|
try {
|
|
83
84
|
const response = await this.httpClient.call(request);
|
|
84
|
-
return
|
|
85
|
+
return parseResponse(response, schemas.WebhookDispatch());
|
|
85
86
|
}
|
|
86
87
|
catch (err) {
|
|
87
88
|
catchNotFoundOrThrow(err);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
3
4
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
5
|
const listOptionsSchema = z.strictObject({
|
|
5
6
|
...paginationOptionsShape,
|
|
@@ -61,7 +62,7 @@ export class WebhookCollectionClient extends ResourceCollectionClient {
|
|
|
61
62
|
*/
|
|
62
63
|
list(options = {}) {
|
|
63
64
|
const parsed = parseArgument(options, listOptionsSchema, 'WebhookCollectionListOptions');
|
|
64
|
-
return this._listPaginated(parsed);
|
|
65
|
+
return this._listPaginated(schemas.ListOfWebhooks(), parsed);
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Creates a new webhook.
|
|
@@ -72,6 +73,6 @@ export class WebhookCollectionClient extends ResourceCollectionClient {
|
|
|
72
73
|
*/
|
|
73
74
|
async create(webhook) {
|
|
74
75
|
parseArgument(webhook, webhookCreateSchema);
|
|
75
|
-
return this._create(webhook);
|
|
76
|
+
return this._create(schemas.Webhook(), webhook);
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
2
3
|
export { WebhookDispatchStatus } from '../models.js';
|
|
3
4
|
/**
|
|
4
5
|
* Client for managing a specific webhook dispatch.
|
|
@@ -35,6 +36,6 @@ export class WebhookDispatchClient extends ResourceClient {
|
|
|
35
36
|
* @see https://docs.apify.com/api/v2/webhook-dispatch-get
|
|
36
37
|
*/
|
|
37
38
|
async get() {
|
|
38
|
-
return this._get();
|
|
39
|
+
return this._get(schemas.WebhookDispatch());
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
3
4
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
5
|
const listOptionsSchema = z.strictObject({
|
|
5
6
|
...paginationOptionsShape,
|
|
@@ -55,6 +56,6 @@ export class WebhookDispatchCollectionClient extends ResourceCollectionClient {
|
|
|
55
56
|
*/
|
|
56
57
|
list(options = {}) {
|
|
57
58
|
const parsed = parseArgument(options, listOptionsSchema, 'WebhookDispatchCollectionListOptions');
|
|
58
|
-
return this._listPaginated(parsed);
|
|
59
|
+
return this._listPaginated(schemas.ListOfWebhookDispatches(), parsed);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when an API response does not match the schema the client expects for it.
|
|
4
|
+
*
|
|
5
|
+
* The schemas are generated from the Apify OpenAPI specification, so this error means the API returned
|
|
6
|
+
* something the specification does not describe -- a missing required field, a different type, a value
|
|
7
|
+
* outside the documented range. Unknown fields and unknown enum values are not errors: the schemas let
|
|
8
|
+
* both through, so the client keeps working when the API grows.
|
|
9
|
+
*
|
|
10
|
+
* The `message` names the request and every offending field with the value it received, and ends by asking for
|
|
11
|
+
* a bug report: the mismatch is in the API or its specification, not in the caller's code. The structured
|
|
12
|
+
* {@link https://zod.dev | zod} issues are available on `issues`, and the original `ZodError` on `cause`,
|
|
13
|
+
* for programmatic inspection.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ResponseValidationError extends Error {
|
|
16
|
+
/** Structured issues from the underlying schema check. */
|
|
17
|
+
readonly issues: z.ZodError['issues'];
|
|
18
|
+
/** HTTP method of the request whose response failed validation, upper-cased. */
|
|
19
|
+
readonly method: string;
|
|
20
|
+
/** URL of the request whose response failed validation, without its query string. */
|
|
21
|
+
readonly url: string;
|
|
22
|
+
constructor(error: z.ZodError, value: unknown, request: {
|
|
23
|
+
method: string;
|
|
24
|
+
url: string;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ArgumentValidationError } from '@apify/validations';
|
|
2
|
+
const REPORT_HINT = 'The API returned something its OpenAPI specification does not describe. ' +
|
|
3
|
+
'Please report this at https://github.com/apify/apify-client-js/issues.';
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when an API response does not match the schema the client expects for it.
|
|
6
|
+
*
|
|
7
|
+
* The schemas are generated from the Apify OpenAPI specification, so this error means the API returned
|
|
8
|
+
* something the specification does not describe -- a missing required field, a different type, a value
|
|
9
|
+
* outside the documented range. Unknown fields and unknown enum values are not errors: the schemas let
|
|
10
|
+
* both through, so the client keeps working when the API grows.
|
|
11
|
+
*
|
|
12
|
+
* The `message` names the request and every offending field with the value it received, and ends by asking for
|
|
13
|
+
* a bug report: the mismatch is in the API or its specification, not in the caller's code. The structured
|
|
14
|
+
* {@link https://zod.dev | zod} issues are available on `issues`, and the original `ZodError` on `cause`,
|
|
15
|
+
* for programmatic inspection.
|
|
16
|
+
*/
|
|
17
|
+
export class ResponseValidationError extends Error {
|
|
18
|
+
/** Structured issues from the underlying schema check. */
|
|
19
|
+
issues;
|
|
20
|
+
/** HTTP method of the request whose response failed validation, upper-cased. */
|
|
21
|
+
method;
|
|
22
|
+
/** URL of the request whose response failed validation, without its query string. */
|
|
23
|
+
url;
|
|
24
|
+
constructor(error, value, request) {
|
|
25
|
+
const method = request.method.toUpperCase();
|
|
26
|
+
// `@apify/validations` keeps its zod error formatter private, so the issue lines come from the
|
|
27
|
+
// message of the error class it does export.
|
|
28
|
+
const details = new ArgumentValidationError(error, value).message;
|
|
29
|
+
super(`Response from ${method} ${request.url} does not match the API schema:\n${details}\n${REPORT_HINT}`, {
|
|
30
|
+
cause: error,
|
|
31
|
+
});
|
|
32
|
+
this.name = 'ResponseValidationError';
|
|
33
|
+
this.issues = error.issues;
|
|
34
|
+
this.method = method;
|
|
35
|
+
this.url = request.url;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schemas the resource clients validate API responses with.
|
|
3
|
+
*
|
|
4
|
+
* Today these are exactly the generated ones. The module still exists as the one place where a generated
|
|
5
|
+
* schema is widened when the API is known to return something the specification does not describe, so a
|
|
6
|
+
* documented deviation never sends a resource client reaching into `./generated` directly. An override
|
|
7
|
+
* declared here shadows the generated export of the same name and takes the same form, a `lazySchema()` thunk
|
|
8
|
+
* built on the generated schema it replaces. Every schema that embeds an overridden one has to be rebuilt on
|
|
9
|
+
* top of it, and `spec_guards.ts` checks that each override still accepts what the specification describes,
|
|
10
|
+
* so one cannot narrow by accident.
|
|
11
|
+
*
|
|
12
|
+
* Spec gaps need no override: the generated objects are loose, so a field the specification omits passes
|
|
13
|
+
* through. Neither do client narrowings: a schema only ever accepts more than the published type.
|
|
14
|
+
*/
|
|
15
|
+
export * from './generated/schemas.js';
|