apify-client 3.0.0-beta.1 → 3.0.0-beta.3
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 +2 -2
- package/dist/apify_api_error.js +5 -9
- 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 +1 -1
- package/dist/base/resource_client.js +14 -18
- package/dist/base/resource_collection_client.d.ts +2 -2
- package/dist/base/resource_collection_client.js +6 -10
- package/dist/body_parser.js +6 -11
- package/dist/bundle.js +35 -47
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.js +1 -2
- package/dist/http_client.d.ts +2 -2
- package/dist/http_client.js +23 -28
- package/dist/index.d.ts +32 -32
- package/dist/index.js +31 -36
- package/dist/interceptors.d.ts +1 -1
- package/dist/interceptors.js +14 -19
- package/dist/models.d.ts +3 -3
- package/dist/models.js +8 -11
- package/dist/resource_clients/actor.d.ts +13 -13
- package/dist/resource_clients/actor.js +67 -71
- package/dist/resource_clients/actor_collection.d.ts +7 -7
- package/dist/resource_clients/actor_collection.js +14 -18
- package/dist/resource_clients/actor_env_var.d.ts +3 -3
- package/dist/resource_clients/actor_env_var.js +4 -8
- package/dist/resource_clients/actor_env_var_collection.d.ts +4 -4
- package/dist/resource_clients/actor_env_var_collection.js +5 -9
- package/dist/resource_clients/actor_version.d.ts +7 -7
- package/dist/resource_clients/actor_version.js +12 -17
- package/dist/resource_clients/actor_version_collection.d.ts +4 -4
- package/dist/resource_clients/actor_version_collection.js +5 -9
- package/dist/resource_clients/build.d.ts +5 -5
- package/dist/resource_clients/build.js +11 -15
- package/dist/resource_clients/build_collection.d.ts +5 -5
- package/dist/resource_clients/build_collection.js +8 -12
- package/dist/resource_clients/dataset.d.ts +5 -5
- package/dist/resource_clients/dataset.js +72 -76
- package/dist/resource_clients/dataset_collection.d.ts +4 -4
- package/dist/resource_clients/dataset_collection.js +15 -19
- package/dist/resource_clients/key_value_store.d.ts +4 -4
- package/dist/resource_clients/key_value_store.js +57 -62
- package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
- package/dist/resource_clients/key_value_store_collection.js +15 -19
- 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 -4
- package/dist/resource_clients/request_queue.js +91 -96
- package/dist/resource_clients/request_queue_collection.d.ts +4 -4
- package/dist/resource_clients/request_queue_collection.js +13 -17
- package/dist/resource_clients/run.d.ts +8 -8
- package/dist/resource_clients/run.js +46 -50
- package/dist/resource_clients/run_collection.d.ts +4 -4
- package/dist/resource_clients/run_collection.js +13 -17
- package/dist/resource_clients/schedule.d.ts +6 -6
- package/dist/resource_clients/schedule.js +7 -12
- package/dist/resource_clients/schedule_collection.d.ts +4 -4
- package/dist/resource_clients/schedule_collection.js +10 -14
- package/dist/resource_clients/store_collection.d.ts +5 -5
- package/dist/resource_clients/store_collection.js +13 -17
- package/dist/resource_clients/task.d.ts +9 -9
- package/dist/resource_clients/task.js +44 -48
- package/dist/resource_clients/task_collection.d.ts +6 -6
- package/dist/resource_clients/task_collection.js +9 -13
- package/dist/resource_clients/user.d.ts +5 -5
- package/dist/resource_clients/user.js +8 -13
- package/dist/resource_clients/webhook.d.ts +6 -6
- package/dist/resource_clients/webhook.js +8 -12
- package/dist/resource_clients/webhook_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_collection.js +10 -14
- package/dist/resource_clients/webhook_dispatch.d.ts +5 -5
- package/dist/resource_clients/webhook_dispatch.js +3 -8
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_dispatch_collection.js +8 -12
- package/dist/statistics.js +5 -9
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +5 -13
- package/dist/utils.js +30 -69
- package/package.json +10 -12
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -157
- package/dist/index.mjs +0 -42
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ automatic retries and convenience functions that improve the experience of using
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
|
-
|
|
29
|
+
import { ApifyClient } from 'apify-client';
|
|
30
30
|
|
|
31
31
|
const client = new ApifyClient({
|
|
32
32
|
token: 'MY-APIFY-TOKEN',
|
|
@@ -72,7 +72,7 @@ resources are created. There are two types of those clients. A client for manage
|
|
|
72
72
|
resource and a client for a collection of resources.
|
|
73
73
|
|
|
74
74
|
```js
|
|
75
|
-
|
|
75
|
+
import { ApifyClient } from 'apify-client';
|
|
76
76
|
const apifyClient = new ApifyClient({ token: 'my-token' });
|
|
77
77
|
|
|
78
78
|
// Collection clients do not require a parameter.
|
package/dist/apify_api_error.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ApifyApiError = void 0;
|
|
4
|
-
const body_parser_1 = require("./body_parser");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { isomorphicBufferToString } from './body_parser.js';
|
|
2
|
+
import { isBuffer } from './utils.js';
|
|
6
3
|
/**
|
|
7
4
|
* Examples of capturing groups for "...at ActorCollectionClient._list (/Users/..."
|
|
8
5
|
* 0: "at ActorCollectionClient._list ("
|
|
@@ -20,7 +17,7 @@ const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\._?([A-Z
|
|
|
20
17
|
* errors, which are thrown immediately, because a correction by the user is
|
|
21
18
|
* needed.
|
|
22
19
|
*/
|
|
23
|
-
class ApifyApiError extends Error {
|
|
20
|
+
export class ApifyApiError extends Error {
|
|
24
21
|
name;
|
|
25
22
|
/**
|
|
26
23
|
* The invoked resource client and the method. Known issue: Sometimes it displays
|
|
@@ -66,9 +63,9 @@ class ApifyApiError extends Error {
|
|
|
66
63
|
let errorData;
|
|
67
64
|
// Some methods (e.g. downloadItems) set up forceBuffer on request response. If this request failed
|
|
68
65
|
// the body buffer needs to parse to get the correct error.
|
|
69
|
-
if (
|
|
66
|
+
if (isBuffer(responseData)) {
|
|
70
67
|
try {
|
|
71
|
-
responseData = JSON.parse(
|
|
68
|
+
responseData = JSON.parse(isomorphicBufferToString(response.data, 'utf-8'));
|
|
72
69
|
}
|
|
73
70
|
catch {
|
|
74
71
|
// This can happen. The data in the response body are malformed.
|
|
@@ -148,4 +145,3 @@ class ApifyApiError extends Error {
|
|
|
148
145
|
return `${name}: ${this.message}\n${stack}`;
|
|
149
146
|
}
|
|
150
147
|
}
|
|
151
|
-
exports.ApifyApiError = ApifyApiError;
|
package/dist/apify_client.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import type { SetStatusMessageOptions } from '@crawlee/types';
|
|
2
2
|
import type { Log } from '@apify/log';
|
|
3
|
-
import { HttpClient } from './http_client';
|
|
4
|
-
import type { RequestInterceptorFunction } from './interceptors';
|
|
5
|
-
import { ActorClient } from './resource_clients/actor';
|
|
6
|
-
import { ActorCollectionClient } from './resource_clients/actor_collection';
|
|
7
|
-
import { BuildClient } from './resource_clients/build';
|
|
8
|
-
import { BuildCollectionClient } from './resource_clients/build_collection';
|
|
9
|
-
import { DatasetClient } from './resource_clients/dataset';
|
|
10
|
-
import { DatasetCollectionClient } from './resource_clients/dataset_collection';
|
|
11
|
-
import { KeyValueStoreClient } from './resource_clients/key_value_store';
|
|
12
|
-
import { KeyValueStoreCollectionClient } from './resource_clients/key_value_store_collection';
|
|
13
|
-
import { LogClient } from './resource_clients/log';
|
|
14
|
-
import type { RequestQueueUserOptions } from './resource_clients/request_queue';
|
|
15
|
-
import { RequestQueueClient } from './resource_clients/request_queue';
|
|
16
|
-
import { RequestQueueCollectionClient } from './resource_clients/request_queue_collection';
|
|
17
|
-
import { RunClient } from './resource_clients/run';
|
|
18
|
-
import { RunCollectionClient } from './resource_clients/run_collection';
|
|
19
|
-
import { ScheduleClient } from './resource_clients/schedule';
|
|
20
|
-
import { ScheduleCollectionClient } from './resource_clients/schedule_collection';
|
|
21
|
-
import { StoreCollectionClient } from './resource_clients/store_collection';
|
|
22
|
-
import { TaskClient } from './resource_clients/task';
|
|
23
|
-
import { TaskCollectionClient } from './resource_clients/task_collection';
|
|
24
|
-
import { UserClient } from './resource_clients/user';
|
|
25
|
-
import { WebhookClient } from './resource_clients/webhook';
|
|
26
|
-
import { WebhookCollectionClient } from './resource_clients/webhook_collection';
|
|
27
|
-
import { WebhookDispatchClient } from './resource_clients/webhook_dispatch';
|
|
28
|
-
import { WebhookDispatchCollectionClient } from './resource_clients/webhook_dispatch_collection';
|
|
29
|
-
import { Statistics } from './statistics';
|
|
3
|
+
import { HttpClient } from './http_client.js';
|
|
4
|
+
import type { RequestInterceptorFunction } from './interceptors.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 type { RequestQueueUserOptions } from './resource_clients/request_queue.js';
|
|
15
|
+
import { RequestQueueClient } from './resource_clients/request_queue.js';
|
|
16
|
+
import { RequestQueueCollectionClient } from './resource_clients/request_queue_collection.js';
|
|
17
|
+
import { RunClient } from './resource_clients/run.js';
|
|
18
|
+
import { RunCollectionClient } from './resource_clients/run_collection.js';
|
|
19
|
+
import { ScheduleClient } from './resource_clients/schedule.js';
|
|
20
|
+
import { ScheduleCollectionClient } from './resource_clients/schedule_collection.js';
|
|
21
|
+
import { StoreCollectionClient } from './resource_clients/store_collection.js';
|
|
22
|
+
import { TaskClient } from './resource_clients/task.js';
|
|
23
|
+
import { TaskCollectionClient } from './resource_clients/task_collection.js';
|
|
24
|
+
import { UserClient } from './resource_clients/user.js';
|
|
25
|
+
import { WebhookClient } from './resource_clients/webhook.js';
|
|
26
|
+
import { WebhookCollectionClient } from './resource_clients/webhook_collection.js';
|
|
27
|
+
import { WebhookDispatchClient } from './resource_clients/webhook_dispatch.js';
|
|
28
|
+
import { WebhookDispatchCollectionClient } from './resource_clients/webhook_dispatch_collection.js';
|
|
29
|
+
import { Statistics } from './statistics.js';
|
|
30
30
|
/**
|
|
31
31
|
* The official JavaScript client for the Apify API.
|
|
32
32
|
*
|
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,5 @@
|
|
|
1
1
|
import type { ACT_JOB_STATUSES } from '@apify/consts';
|
|
2
|
-
import { ApiClient } from './api_client';
|
|
2
|
+
import { ApiClient } from './api_client.js';
|
|
3
3
|
export declare const SMALL_TIMEOUT_MILLIS: number;
|
|
4
4
|
export declare const MEDIUM_TIMEOUT_MILLIS: number;
|
|
5
5
|
export declare const DEFAULT_TIMEOUT_MILLIS: number;
|
|
@@ -1,23 +1,20 @@
|
|
|
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, parseDateFields, pluckData } 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
|
|
17
|
+
export class ResourceClient extends ApiClient {
|
|
21
18
|
async _get(options = {}, timeoutMillis) {
|
|
22
19
|
const requestOpts = {
|
|
23
20
|
url: this._url(),
|
|
@@ -27,10 +24,10 @@ 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 parseDateFields(pluckData(response.data));
|
|
31
28
|
}
|
|
32
29
|
catch (err) {
|
|
33
|
-
|
|
30
|
+
catchNotFoundOrThrow(err);
|
|
34
31
|
}
|
|
35
32
|
return undefined;
|
|
36
33
|
}
|
|
@@ -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 parseDateFields(pluckData(response.data));
|
|
46
43
|
}
|
|
47
44
|
async _delete(timeoutMillis) {
|
|
48
45
|
try {
|
|
@@ -54,7 +51,7 @@ 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
|
/**
|
|
@@ -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 = parseDateFields(pluckData(response.data));
|
|
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,5 @@
|
|
|
1
|
-
import type { PaginatedResponse, PaginationOptions } from '../utils';
|
|
2
|
-
import { ApiClient } from './api_client';
|
|
1
|
+
import type { PaginatedResponse, PaginationOptions } from '../utils.js';
|
|
2
|
+
import { ApiClient } from './api_client.js';
|
|
3
3
|
/**
|
|
4
4
|
* Resource collection client.
|
|
5
5
|
* @private
|