apify-client 3.0.0-beta.1 → 3.0.0-beta.10
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 +5 -4
- package/dist/base/resource_client.js +17 -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 +5 -5
- package/dist/resource_clients/build.js +14 -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 +6 -6
- package/dist/resource_clients/dataset.js +73 -76
- 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 +2 -2
- package/dist/resource_clients/log.js +15 -22
- 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 +8 -8
- package/dist/resource_clients/run.js +50 -53
- 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 +13 -15
- 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 +9 -9
- package/dist/resource_clients/task.js +47 -50
- 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 +5 -5
- package/dist/resource_clients/user.js +11 -16
- package/dist/resource_clients/webhook.d.ts +6 -6
- package/dist/resource_clients/webhook.js +11 -14
- 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 +19 -24
- package/dist/utils.js +57 -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
package/dist/apify_client.js
CHANGED
|
@@ -1,51 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const webhook_dispatch_1 = require("./resource_clients/webhook_dispatch");
|
|
31
|
-
const webhook_dispatch_collection_1 = require("./resource_clients/webhook_dispatch_collection");
|
|
32
|
-
const statistics_1 = require("./statistics");
|
|
33
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ACTOR_ENV_VARS, ME_USER_NAME_PLACEHOLDER } from '@apify/consts';
|
|
3
|
+
import logger from '@apify/log';
|
|
4
|
+
import { HttpClient } from './http_client.js';
|
|
5
|
+
import { ActorClient } from './resource_clients/actor.js';
|
|
6
|
+
import { ActorCollectionClient } from './resource_clients/actor_collection.js';
|
|
7
|
+
import { BuildClient } from './resource_clients/build.js';
|
|
8
|
+
import { BuildCollectionClient } from './resource_clients/build_collection.js';
|
|
9
|
+
import { DatasetClient } from './resource_clients/dataset.js';
|
|
10
|
+
import { DatasetCollectionClient } from './resource_clients/dataset_collection.js';
|
|
11
|
+
import { KeyValueStoreClient } from './resource_clients/key_value_store.js';
|
|
12
|
+
import { KeyValueStoreCollectionClient } from './resource_clients/key_value_store_collection.js';
|
|
13
|
+
import { LogClient } from './resource_clients/log.js';
|
|
14
|
+
import { RequestQueueClient } from './resource_clients/request_queue.js';
|
|
15
|
+
import { RequestQueueCollectionClient } from './resource_clients/request_queue_collection.js';
|
|
16
|
+
import { RunClient } from './resource_clients/run.js';
|
|
17
|
+
import { RunCollectionClient } from './resource_clients/run_collection.js';
|
|
18
|
+
import { ScheduleClient } from './resource_clients/schedule.js';
|
|
19
|
+
import { ScheduleCollectionClient } from './resource_clients/schedule_collection.js';
|
|
20
|
+
import { StoreCollectionClient } from './resource_clients/store_collection.js';
|
|
21
|
+
import { TaskClient } from './resource_clients/task.js';
|
|
22
|
+
import { TaskCollectionClient } from './resource_clients/task_collection.js';
|
|
23
|
+
import { UserClient } from './resource_clients/user.js';
|
|
24
|
+
import { WebhookClient } from './resource_clients/webhook.js';
|
|
25
|
+
import { WebhookCollectionClient } from './resource_clients/webhook_collection.js';
|
|
26
|
+
import { WebhookDispatchClient } from './resource_clients/webhook_dispatch.js';
|
|
27
|
+
import { WebhookDispatchCollectionClient } from './resource_clients/webhook_dispatch_collection.js';
|
|
28
|
+
import { Statistics } from './statistics.js';
|
|
29
|
+
import { parseArgument } from './utils.js';
|
|
34
30
|
const DEFAULT_TIMEOUT_SECS = 360;
|
|
35
|
-
const clientOptionsSchema =
|
|
36
|
-
baseUrl:
|
|
37
|
-
publicBaseUrl:
|
|
38
|
-
maxRetries:
|
|
39
|
-
minDelayBetweenRetriesMillis:
|
|
40
|
-
requestInterceptors:
|
|
41
|
-
timeoutSecs:
|
|
42
|
-
token:
|
|
43
|
-
userAgentSuffix:
|
|
31
|
+
const clientOptionsSchema = z.strictObject({
|
|
32
|
+
baseUrl: z.string().default('https://api.apify.com'),
|
|
33
|
+
publicBaseUrl: z.string().default('https://api.apify.com'),
|
|
34
|
+
maxRetries: z.number().default(8),
|
|
35
|
+
minDelayBetweenRetriesMillis: z.number().default(500),
|
|
36
|
+
requestInterceptors: z.array(z.unknown()).default([]),
|
|
37
|
+
timeoutSecs: z.number().default(DEFAULT_TIMEOUT_SECS),
|
|
38
|
+
token: z.string().optional(),
|
|
39
|
+
userAgentSuffix: z.union([z.string(), z.array(z.string())]).optional(),
|
|
44
40
|
});
|
|
45
|
-
const resourceIdSchema =
|
|
46
|
-
const requestQueueOptionsSchema =
|
|
47
|
-
clientKey:
|
|
48
|
-
timeoutSecs:
|
|
41
|
+
const resourceIdSchema = z.string().min(1);
|
|
42
|
+
const requestQueueOptionsSchema = z.strictObject({
|
|
43
|
+
clientKey: z.string().min(1).optional(),
|
|
44
|
+
timeoutSecs: z.number().optional(),
|
|
49
45
|
});
|
|
50
46
|
/**
|
|
51
47
|
* The official JavaScript client for the Apify API.
|
|
@@ -68,7 +64,7 @@ const requestQueueOptionsSchema = zod_1.z.strictObject({
|
|
|
68
64
|
*
|
|
69
65
|
* @see https://docs.apify.com/api/v2
|
|
70
66
|
*/
|
|
71
|
-
class ApifyClient {
|
|
67
|
+
export class ApifyClient {
|
|
72
68
|
baseUrl;
|
|
73
69
|
/**
|
|
74
70
|
* @since Added in 2.17.0
|
|
@@ -79,7 +75,7 @@ class ApifyClient {
|
|
|
79
75
|
logger;
|
|
80
76
|
httpClient;
|
|
81
77
|
constructor(options = {}) {
|
|
82
|
-
const parsed =
|
|
78
|
+
const parsed = parseArgument(options, clientOptionsSchema, 'ApifyClientOptions');
|
|
83
79
|
const { baseUrl, publicBaseUrl, maxRetries, minDelayBetweenRetriesMillis, requestInterceptors, timeoutSecs, token, } = parsed;
|
|
84
80
|
const tempBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl;
|
|
85
81
|
this.baseUrl = `${tempBaseUrl}/v2`;
|
|
@@ -88,9 +84,9 @@ class ApifyClient {
|
|
|
88
84
|
: publicBaseUrl;
|
|
89
85
|
this.publicBaseUrl = `${tempPublicBaseUrl}/v2`;
|
|
90
86
|
this.token = token;
|
|
91
|
-
this.stats = new
|
|
92
|
-
this.logger =
|
|
93
|
-
this.httpClient = new
|
|
87
|
+
this.stats = new Statistics();
|
|
88
|
+
this.logger = logger.child({ prefix: 'ApifyClient' });
|
|
89
|
+
this.httpClient = new HttpClient({
|
|
94
90
|
apifyClientStats: this.stats,
|
|
95
91
|
maxRetries,
|
|
96
92
|
minDelayBetweenRetriesMillis,
|
|
@@ -118,7 +114,7 @@ class ApifyClient {
|
|
|
118
114
|
* @see https://docs.apify.com/api/v2/acts-get
|
|
119
115
|
*/
|
|
120
116
|
actors() {
|
|
121
|
-
return new
|
|
117
|
+
return new ActorCollectionClient(this._options());
|
|
122
118
|
}
|
|
123
119
|
/**
|
|
124
120
|
* Returns a client for a specific Actor.
|
|
@@ -137,8 +133,8 @@ class ApifyClient {
|
|
|
137
133
|
* ```
|
|
138
134
|
*/
|
|
139
135
|
actor(id) {
|
|
140
|
-
|
|
141
|
-
return new
|
|
136
|
+
parseArgument(id, resourceIdSchema);
|
|
137
|
+
return new ActorClient({
|
|
142
138
|
id,
|
|
143
139
|
...this._options(),
|
|
144
140
|
});
|
|
@@ -152,7 +148,7 @@ class ApifyClient {
|
|
|
152
148
|
* @see https://docs.apify.com/api/v2/actor-builds-get
|
|
153
149
|
*/
|
|
154
150
|
builds() {
|
|
155
|
-
return new
|
|
151
|
+
return new BuildCollectionClient(this._options());
|
|
156
152
|
}
|
|
157
153
|
/**
|
|
158
154
|
* Returns a client for a specific Actor build.
|
|
@@ -164,8 +160,8 @@ class ApifyClient {
|
|
|
164
160
|
* @see https://docs.apify.com/api/v2/actor-build-get
|
|
165
161
|
*/
|
|
166
162
|
build(id) {
|
|
167
|
-
|
|
168
|
-
return new
|
|
163
|
+
parseArgument(id, resourceIdSchema);
|
|
164
|
+
return new BuildClient({
|
|
169
165
|
id,
|
|
170
166
|
...this._options(),
|
|
171
167
|
});
|
|
@@ -179,7 +175,7 @@ class ApifyClient {
|
|
|
179
175
|
* @see https://docs.apify.com/api/v2/datasets-get
|
|
180
176
|
*/
|
|
181
177
|
datasets() {
|
|
182
|
-
return new
|
|
178
|
+
return new DatasetCollectionClient(this._options());
|
|
183
179
|
}
|
|
184
180
|
/**
|
|
185
181
|
* Returns a client for a specific dataset.
|
|
@@ -205,8 +201,8 @@ class ApifyClient {
|
|
|
205
201
|
* ```
|
|
206
202
|
*/
|
|
207
203
|
dataset(id) {
|
|
208
|
-
|
|
209
|
-
return new
|
|
204
|
+
parseArgument(id, resourceIdSchema);
|
|
205
|
+
return new DatasetClient({
|
|
210
206
|
id,
|
|
211
207
|
...this._options(),
|
|
212
208
|
});
|
|
@@ -220,7 +216,7 @@ class ApifyClient {
|
|
|
220
216
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
221
217
|
*/
|
|
222
218
|
keyValueStores() {
|
|
223
|
-
return new
|
|
219
|
+
return new KeyValueStoreCollectionClient(this._options());
|
|
224
220
|
}
|
|
225
221
|
/**
|
|
226
222
|
* Returns a client for a specific key-value store.
|
|
@@ -242,8 +238,8 @@ class ApifyClient {
|
|
|
242
238
|
* ```
|
|
243
239
|
*/
|
|
244
240
|
keyValueStore(id) {
|
|
245
|
-
|
|
246
|
-
return new
|
|
241
|
+
parseArgument(id, resourceIdSchema);
|
|
242
|
+
return new KeyValueStoreClient({
|
|
247
243
|
id,
|
|
248
244
|
...this._options(),
|
|
249
245
|
});
|
|
@@ -256,8 +252,8 @@ class ApifyClient {
|
|
|
256
252
|
* @see https://docs.apify.com/api/v2/log-get
|
|
257
253
|
*/
|
|
258
254
|
log(buildOrRunId) {
|
|
259
|
-
|
|
260
|
-
return new
|
|
255
|
+
parseArgument(buildOrRunId, resourceIdSchema);
|
|
256
|
+
return new LogClient({
|
|
261
257
|
id: buildOrRunId,
|
|
262
258
|
...this._options(),
|
|
263
259
|
});
|
|
@@ -271,7 +267,7 @@ class ApifyClient {
|
|
|
271
267
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
272
268
|
*/
|
|
273
269
|
requestQueues() {
|
|
274
|
-
return new
|
|
270
|
+
return new RequestQueueCollectionClient(this._options());
|
|
275
271
|
}
|
|
276
272
|
/**
|
|
277
273
|
* Returns a client for a specific request queue.
|
|
@@ -295,13 +291,13 @@ class ApifyClient {
|
|
|
295
291
|
* ```
|
|
296
292
|
*/
|
|
297
293
|
requestQueue(id, options = {}) {
|
|
298
|
-
|
|
299
|
-
const parsed =
|
|
294
|
+
parseArgument(id, resourceIdSchema);
|
|
295
|
+
const parsed = parseArgument(options, requestQueueOptionsSchema, 'RequestQueueUserOptions');
|
|
300
296
|
const apiClientOptions = {
|
|
301
297
|
id,
|
|
302
298
|
...this._options(),
|
|
303
299
|
};
|
|
304
|
-
return new
|
|
300
|
+
return new RequestQueueClient(apiClientOptions, parsed);
|
|
305
301
|
}
|
|
306
302
|
/**
|
|
307
303
|
* Returns a client for managing Actor runs in your account.
|
|
@@ -312,7 +308,7 @@ class ApifyClient {
|
|
|
312
308
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
313
309
|
*/
|
|
314
310
|
runs() {
|
|
315
|
-
return new
|
|
311
|
+
return new RunCollectionClient({
|
|
316
312
|
...this._options(),
|
|
317
313
|
resourcePath: 'actor-runs',
|
|
318
314
|
});
|
|
@@ -337,8 +333,8 @@ class ApifyClient {
|
|
|
337
333
|
* ```
|
|
338
334
|
*/
|
|
339
335
|
run(id) {
|
|
340
|
-
|
|
341
|
-
return new
|
|
336
|
+
parseArgument(id, resourceIdSchema);
|
|
337
|
+
return new RunClient({
|
|
342
338
|
id,
|
|
343
339
|
...this._options(),
|
|
344
340
|
});
|
|
@@ -352,7 +348,7 @@ class ApifyClient {
|
|
|
352
348
|
* @see https://docs.apify.com/api/v2/actor-tasks-get
|
|
353
349
|
*/
|
|
354
350
|
tasks() {
|
|
355
|
-
return new
|
|
351
|
+
return new TaskCollectionClient(this._options());
|
|
356
352
|
}
|
|
357
353
|
/**
|
|
358
354
|
* Returns a client for a specific Actor task.
|
|
@@ -370,8 +366,8 @@ class ApifyClient {
|
|
|
370
366
|
* ```
|
|
371
367
|
*/
|
|
372
368
|
task(id) {
|
|
373
|
-
|
|
374
|
-
return new
|
|
369
|
+
parseArgument(id, resourceIdSchema);
|
|
370
|
+
return new TaskClient({
|
|
375
371
|
id,
|
|
376
372
|
...this._options(),
|
|
377
373
|
});
|
|
@@ -385,7 +381,7 @@ class ApifyClient {
|
|
|
385
381
|
* @see https://docs.apify.com/api/v2/schedules-get
|
|
386
382
|
*/
|
|
387
383
|
schedules() {
|
|
388
|
-
return new
|
|
384
|
+
return new ScheduleCollectionClient(this._options());
|
|
389
385
|
}
|
|
390
386
|
/**
|
|
391
387
|
* Returns a client for a specific schedule.
|
|
@@ -397,8 +393,8 @@ class ApifyClient {
|
|
|
397
393
|
* @see https://docs.apify.com/api/v2/schedule-get
|
|
398
394
|
*/
|
|
399
395
|
schedule(id) {
|
|
400
|
-
|
|
401
|
-
return new
|
|
396
|
+
parseArgument(id, resourceIdSchema);
|
|
397
|
+
return new ScheduleClient({
|
|
402
398
|
id,
|
|
403
399
|
...this._options(),
|
|
404
400
|
});
|
|
@@ -412,9 +408,9 @@ class ApifyClient {
|
|
|
412
408
|
* @returns A client for the user
|
|
413
409
|
* @see https://docs.apify.com/api/v2/user-get
|
|
414
410
|
*/
|
|
415
|
-
user(id =
|
|
416
|
-
|
|
417
|
-
return new
|
|
411
|
+
user(id = ME_USER_NAME_PLACEHOLDER) {
|
|
412
|
+
parseArgument(id, resourceIdSchema);
|
|
413
|
+
return new UserClient({
|
|
418
414
|
id,
|
|
419
415
|
...this._options(),
|
|
420
416
|
});
|
|
@@ -428,7 +424,7 @@ class ApifyClient {
|
|
|
428
424
|
* @see https://docs.apify.com/api/v2/webhooks-get
|
|
429
425
|
*/
|
|
430
426
|
webhooks() {
|
|
431
|
-
return new
|
|
427
|
+
return new WebhookCollectionClient(this._options());
|
|
432
428
|
}
|
|
433
429
|
/**
|
|
434
430
|
* Returns a client for a specific webhook.
|
|
@@ -440,8 +436,8 @@ class ApifyClient {
|
|
|
440
436
|
* @see https://docs.apify.com/api/v2/webhook-get
|
|
441
437
|
*/
|
|
442
438
|
webhook(id) {
|
|
443
|
-
|
|
444
|
-
return new
|
|
439
|
+
parseArgument(id, resourceIdSchema);
|
|
440
|
+
return new WebhookClient({
|
|
445
441
|
id,
|
|
446
442
|
...this._options(),
|
|
447
443
|
});
|
|
@@ -455,7 +451,7 @@ class ApifyClient {
|
|
|
455
451
|
* @see https://docs.apify.com/api/v2/webhook-dispatches-get
|
|
456
452
|
*/
|
|
457
453
|
webhookDispatches() {
|
|
458
|
-
return new
|
|
454
|
+
return new WebhookDispatchCollectionClient(this._options());
|
|
459
455
|
}
|
|
460
456
|
/**
|
|
461
457
|
* Returns a client for a specific webhook dispatch.
|
|
@@ -465,8 +461,8 @@ class ApifyClient {
|
|
|
465
461
|
* @see https://docs.apify.com/api/v2/webhook-dispatch-get
|
|
466
462
|
*/
|
|
467
463
|
webhookDispatch(id) {
|
|
468
|
-
|
|
469
|
-
return new
|
|
464
|
+
parseArgument(id, resourceIdSchema);
|
|
465
|
+
return new WebhookDispatchClient({
|
|
470
466
|
id,
|
|
471
467
|
...this._options(),
|
|
472
468
|
});
|
|
@@ -480,7 +476,7 @@ class ApifyClient {
|
|
|
480
476
|
* @see https://docs.apify.com/api/v2/store-get
|
|
481
477
|
*/
|
|
482
478
|
store() {
|
|
483
|
-
return new
|
|
479
|
+
return new StoreCollectionClient(this._options());
|
|
484
480
|
}
|
|
485
481
|
/**
|
|
486
482
|
* Sets a status message for the current Actor run.
|
|
@@ -494,9 +490,9 @@ class ApifyClient {
|
|
|
494
490
|
* @since Added in 2.7.0
|
|
495
491
|
*/
|
|
496
492
|
async setStatusMessage(message, options) {
|
|
497
|
-
const runId = process.env[
|
|
493
|
+
const runId = process.env[ACTOR_ENV_VARS.RUN_ID];
|
|
498
494
|
if (!runId) {
|
|
499
|
-
throw new Error(`Environment variable ${
|
|
495
|
+
throw new Error(`Environment variable ${ACTOR_ENV_VARS.RUN_ID} is not set!`);
|
|
500
496
|
}
|
|
501
497
|
await this.run(runId).update({
|
|
502
498
|
statusMessage: message,
|
|
@@ -504,4 +500,3 @@ class ApifyClient {
|
|
|
504
500
|
});
|
|
505
501
|
}
|
|
506
502
|
}
|
|
507
|
-
exports.ApifyClient = ApifyClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ApifyClient } from '../apify_client';
|
|
2
|
-
import type { HttpClient } from '../http_client';
|
|
3
|
-
import type { PaginatedResponse, PaginationOptions } from '../utils';
|
|
1
|
+
import type { ApifyClient } from '../apify_client.js';
|
|
2
|
+
import type { HttpClient } from '../http_client.js';
|
|
3
|
+
import type { PaginatedResponse, PaginationOptions } from '../utils.js';
|
|
4
4
|
/** @private */
|
|
5
5
|
export interface ApiClientOptions {
|
|
6
6
|
baseUrl: string;
|
package/dist/base/api_client.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiClient = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { toPath, toPathSegment } from '../utils.js';
|
|
5
2
|
/** @private */
|
|
6
|
-
class ApiClient {
|
|
3
|
+
export class ApiClient {
|
|
7
4
|
id;
|
|
8
5
|
safeId;
|
|
9
6
|
baseUrl;
|
|
@@ -23,7 +20,7 @@ class ApiClient {
|
|
|
23
20
|
this.baseUrl = baseUrl;
|
|
24
21
|
this.publicBaseUrl = publicBaseUrl;
|
|
25
22
|
this.resourcePath = resourcePath;
|
|
26
|
-
this.url = id ? `${baseUrl}/${resourcePath}/${
|
|
23
|
+
this.url = id ? `${baseUrl}/${resourcePath}/${toPathSegment(this.safeId)}` : `${baseUrl}/${resourcePath}`;
|
|
27
24
|
this.apifyClient = apifyClient;
|
|
28
25
|
this.httpClient = httpClient;
|
|
29
26
|
this.params = params;
|
|
@@ -39,13 +36,13 @@ class ApiClient {
|
|
|
39
36
|
return { ...baseOptions, ...moreOptions };
|
|
40
37
|
}
|
|
41
38
|
_url(path) {
|
|
42
|
-
return path ? `${this.url}/${
|
|
39
|
+
return path ? `${this.url}/${toPath(path)}` : this.url;
|
|
43
40
|
}
|
|
44
41
|
_publicUrl(path) {
|
|
45
42
|
const url = this.id
|
|
46
|
-
? `${this.publicBaseUrl}/${this.resourcePath}/${
|
|
43
|
+
? `${this.publicBaseUrl}/${this.resourcePath}/${toPathSegment(this.safeId)}`
|
|
47
44
|
: `${this.publicBaseUrl}/${this.resourcePath}`;
|
|
48
|
-
return path ? `${url}/${
|
|
45
|
+
return path ? `${url}/${toPath(path)}` : url;
|
|
49
46
|
}
|
|
50
47
|
_params(endpointParams) {
|
|
51
48
|
return { ...this.params, ...endpointParams };
|
|
@@ -101,4 +98,3 @@ class ApiClient {
|
|
|
101
98
|
});
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
|
-
exports.ApiClient = ApiClient;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ACT_JOB_STATUSES } from '@apify/consts';
|
|
2
|
-
import {
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import { ApiClient } from './api_client.js';
|
|
3
4
|
export declare const SMALL_TIMEOUT_MILLIS: number;
|
|
4
5
|
export declare const MEDIUM_TIMEOUT_MILLIS: number;
|
|
5
6
|
export declare const DEFAULT_TIMEOUT_MILLIS: number;
|
|
@@ -8,8 +9,8 @@ export declare const DEFAULT_TIMEOUT_MILLIS: number;
|
|
|
8
9
|
* @private
|
|
9
10
|
*/
|
|
10
11
|
export declare class ResourceClient extends ApiClient {
|
|
11
|
-
protected _get<T, R>(options?: T, timeoutMillis?: number): Promise<R | undefined>;
|
|
12
|
-
protected _update<T, R>(newFields: T, timeoutMillis?: number): Promise<R>;
|
|
12
|
+
protected _get<T, R>(schema: z.ZodType, options?: T, timeoutMillis?: number): Promise<R | undefined>;
|
|
13
|
+
protected _update<T, R>(schema: z.ZodType, newFields: T, timeoutMillis?: number): Promise<R>;
|
|
13
14
|
protected _delete(timeoutMillis?: number): Promise<void>;
|
|
14
15
|
/**
|
|
15
16
|
* This function is used in Build and Run endpoints so it's kept
|
|
@@ -17,7 +18,7 @@ export declare class ResourceClient extends ApiClient {
|
|
|
17
18
|
*/
|
|
18
19
|
protected _waitForFinish<R extends {
|
|
19
20
|
status: (typeof ACT_JOB_STATUSES)[keyof typeof ACT_JOB_STATUSES];
|
|
20
|
-
}>(options?: WaitForFinishOptions): Promise<R>;
|
|
21
|
+
}>(schema: z.ZodType, options?: WaitForFinishOptions): Promise<R>;
|
|
21
22
|
}
|
|
22
23
|
export interface WaitForFinishOptions {
|
|
23
24
|
waitSecs?: number;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const consts_1 = require("@apify/consts");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const api_client_1 = require("./api_client");
|
|
1
|
+
import { ACT_JOB_TERMINAL_STATUSES } from '@apify/consts';
|
|
2
|
+
import { catchNotFoundOrThrow, parseResponse } from '../utils.js';
|
|
3
|
+
import { ApiClient } from './api_client.js';
|
|
7
4
|
/**
|
|
8
5
|
* We need to supply some number for the API,
|
|
9
6
|
* because it would not accept "Infinity".
|
|
10
7
|
* 999999 seconds is more than 10 days.
|
|
11
8
|
*/
|
|
12
9
|
const MAX_WAIT_FOR_FINISH = 999999;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export const SMALL_TIMEOUT_MILLIS = 5 * 1000; // For fast and common actions. Suitable for idempotent actions.
|
|
11
|
+
export const MEDIUM_TIMEOUT_MILLIS = 30 * 1000; // For actions that may take longer.
|
|
12
|
+
export const DEFAULT_TIMEOUT_MILLIS = 360 * 1000; // 6 minutes
|
|
16
13
|
/**
|
|
17
14
|
* Resource client.
|
|
18
15
|
* @private
|
|
19
16
|
*/
|
|
20
|
-
class ResourceClient extends
|
|
21
|
-
async _get(options = {}, timeoutMillis) {
|
|
17
|
+
export class ResourceClient extends ApiClient {
|
|
18
|
+
async _get(schema, options = {}, timeoutMillis) {
|
|
22
19
|
const requestOpts = {
|
|
23
20
|
url: this._url(),
|
|
24
21
|
method: 'GET',
|
|
@@ -27,14 +24,14 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
27
24
|
};
|
|
28
25
|
try {
|
|
29
26
|
const response = await this.httpClient.call(requestOpts);
|
|
30
|
-
return (
|
|
27
|
+
return parseResponse(response, schema);
|
|
31
28
|
}
|
|
32
29
|
catch (err) {
|
|
33
|
-
|
|
30
|
+
catchNotFoundOrThrow(err);
|
|
34
31
|
}
|
|
35
32
|
return undefined;
|
|
36
33
|
}
|
|
37
|
-
async _update(newFields, timeoutMillis) {
|
|
34
|
+
async _update(schema, newFields, timeoutMillis) {
|
|
38
35
|
const response = await this.httpClient.call({
|
|
39
36
|
url: this._url(),
|
|
40
37
|
method: 'PUT',
|
|
@@ -42,7 +39,7 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
42
39
|
data: newFields,
|
|
43
40
|
timeout: timeoutMillis,
|
|
44
41
|
});
|
|
45
|
-
return (
|
|
42
|
+
return parseResponse(response, schema);
|
|
46
43
|
}
|
|
47
44
|
async _delete(timeoutMillis) {
|
|
48
45
|
try {
|
|
@@ -54,14 +51,14 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
53
|
catch (err) {
|
|
57
|
-
|
|
54
|
+
catchNotFoundOrThrow(err);
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
61
58
|
* This function is used in Build and Run endpoints so it's kept
|
|
62
59
|
* here to stay DRY.
|
|
63
60
|
*/
|
|
64
|
-
async _waitForFinish(options = {}) {
|
|
61
|
+
async _waitForFinish(schema, options = {}) {
|
|
65
62
|
const { waitSecs = MAX_WAIT_FOR_FINISH } = options;
|
|
66
63
|
const waitMillis = waitSecs * 1000;
|
|
67
64
|
let job;
|
|
@@ -70,7 +67,7 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
70
67
|
const millisSinceStart = Date.now() - startedAt;
|
|
71
68
|
if (millisSinceStart >= waitMillis)
|
|
72
69
|
return false;
|
|
73
|
-
const hasJobEnded = job &&
|
|
70
|
+
const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
|
|
74
71
|
return !hasJobEnded;
|
|
75
72
|
};
|
|
76
73
|
do {
|
|
@@ -84,10 +81,10 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
84
81
|
};
|
|
85
82
|
try {
|
|
86
83
|
const response = await this.httpClient.call(requestOpts);
|
|
87
|
-
job = (
|
|
84
|
+
job = parseResponse(response, schema);
|
|
88
85
|
}
|
|
89
86
|
catch (err) {
|
|
90
|
-
|
|
87
|
+
catchNotFoundOrThrow(err);
|
|
91
88
|
job = undefined;
|
|
92
89
|
}
|
|
93
90
|
// It might take some time for database replicas to get up-to-date,
|
|
@@ -105,4 +102,3 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
105
102
|
return job;
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
exports.ResourceClient = ResourceClient;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { PaginatedResponse, PaginationOptions } from '../utils.js';
|
|
3
|
+
import { ApiClient } from './api_client.js';
|
|
3
4
|
/**
|
|
4
5
|
* Resource collection client.
|
|
5
6
|
* @private
|
|
@@ -8,11 +9,11 @@ export declare class ResourceCollectionClient extends ApiClient {
|
|
|
8
9
|
/**
|
|
9
10
|
* @private
|
|
10
11
|
*/
|
|
11
|
-
protected _list<T, R>(options?: T): Promise<R>;
|
|
12
|
+
protected _list<T, R>(schema: z.ZodType, options?: T): Promise<R>;
|
|
12
13
|
/**
|
|
13
14
|
* Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
|
|
14
15
|
*/
|
|
15
|
-
protected _listPaginated<T extends PaginationOptions, Data, R extends PaginatedResponse<Data>>(options?: T): AsyncIterable<Data> & Promise<R>;
|
|
16
|
-
protected _create<D, R>(resource: D): Promise<R>;
|
|
17
|
-
protected _getOrCreate<D, R>(name?: string, resource?: D): Promise<R>;
|
|
16
|
+
protected _listPaginated<T extends PaginationOptions, Data, R extends PaginatedResponse<Data>>(schema: z.ZodType, options?: T): AsyncIterable<Data> & Promise<R>;
|
|
17
|
+
protected _create<D, R>(schema: z.ZodType, resource: D): Promise<R>;
|
|
18
|
+
protected _getOrCreate<D, R>(schema: z.ZodType, name?: string, resource?: D): Promise<R>;
|
|
18
19
|
}
|
|
@@ -1,47 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ResourceCollectionClient = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const api_client_1 = require("./api_client");
|
|
1
|
+
import { parseResponse } from '../utils.js';
|
|
2
|
+
import { ApiClient } from './api_client.js';
|
|
6
3
|
/**
|
|
7
4
|
* Resource collection client.
|
|
8
5
|
* @private
|
|
9
6
|
*/
|
|
10
|
-
class ResourceCollectionClient extends
|
|
7
|
+
export class ResourceCollectionClient extends ApiClient {
|
|
11
8
|
/**
|
|
12
9
|
* @private
|
|
13
10
|
*/
|
|
14
|
-
async _list(options = {}) {
|
|
11
|
+
async _list(schema, options = {}) {
|
|
15
12
|
const response = await this.httpClient.call({
|
|
16
13
|
url: this._url(),
|
|
17
14
|
method: 'GET',
|
|
18
15
|
params: this._params(options),
|
|
19
16
|
});
|
|
20
|
-
return (
|
|
17
|
+
return parseResponse(response, schema);
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
20
|
* Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
|
|
24
21
|
*/
|
|
25
|
-
_listPaginated(options = {}) {
|
|
26
|
-
return this._listPaginatedFromCallback((this._list
|
|
22
|
+
_listPaginated(schema, options = {}) {
|
|
23
|
+
return this._listPaginatedFromCallback(async (listOptions) => this._list(schema, listOptions), options);
|
|
27
24
|
}
|
|
28
|
-
async _create(resource) {
|
|
25
|
+
async _create(schema, resource) {
|
|
29
26
|
const response = await this.httpClient.call({
|
|
30
27
|
url: this._url(),
|
|
31
28
|
method: 'POST',
|
|
32
29
|
params: this._params(),
|
|
33
30
|
data: resource,
|
|
34
31
|
});
|
|
35
|
-
return (
|
|
32
|
+
return parseResponse(response, schema);
|
|
36
33
|
}
|
|
37
|
-
async _getOrCreate(name, resource) {
|
|
34
|
+
async _getOrCreate(schema, name, resource) {
|
|
38
35
|
const response = await this.httpClient.call({
|
|
39
36
|
url: this._url(),
|
|
40
37
|
method: 'POST',
|
|
41
38
|
params: this._params({ name }),
|
|
42
39
|
data: resource,
|
|
43
40
|
});
|
|
44
|
-
return (
|
|
41
|
+
return parseResponse(response, schema);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
exports.ResourceCollectionClient = ResourceCollectionClient;
|