apify-client 3.0.0-beta.1 → 3.0.0-beta.100
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 +21 -5
- package/dist/apify_api_error.d.ts +64 -22
- package/dist/apify_api_error.js +100 -30
- package/dist/apify_client.d.ts +150 -35
- package/dist/apify_client.js +198 -118
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/base/api_client.d.ts +9 -9
- package/dist/base/api_client.js +41 -45
- package/dist/base/resource_client.d.ts +24 -10
- package/dist/base/resource_client.js +78 -48
- package/dist/base/resource_collection_client.d.ts +15 -6
- package/dist/base/resource_collection_client.js +40 -21
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +20 -32
- package/dist/bundle.js +47 -52
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +3363 -1185
- package/dist/generated/api.js +1 -2
- package/dist/generated/schemas.d.ts +8146 -0
- package/dist/generated/schemas.js +1866 -0
- package/dist/http_clients/axios.d.ts +61 -0
- package/dist/http_clients/axios.js +119 -0
- package/dist/http_clients/base.d.ts +391 -0
- package/dist/http_clients/base.js +650 -0
- package/dist/http_clients/index.d.ts +4 -0
- package/dist/http_clients/index.js +2 -0
- package/dist/http_compressors/base.d.ts +40 -0
- package/dist/http_compressors/base.js +9 -0
- package/dist/http_compressors/brotli.d.ts +33 -0
- package/dist/http_compressors/brotli.js +39 -0
- package/dist/http_compressors/gzip.d.ts +33 -0
- package/dist/http_compressors/gzip.js +39 -0
- package/dist/http_compressors/index.d.ts +8 -0
- package/dist/http_compressors/index.js +3 -0
- package/dist/http_compressors/resolve.d.ts +24 -0
- package/dist/http_compressors/resolve.js +30 -0
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +38 -32
- package/dist/index.js +36 -36
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +196 -278
- package/dist/models.js +14 -15
- package/dist/resource_clients/actor.d.ts +115 -45
- package/dist/resource_clients/actor.js +187 -116
- package/dist/resource_clients/actor_collection.d.ts +21 -17
- package/dist/resource_clients/actor_collection.js +26 -21
- package/dist/resource_clients/actor_env_var.d.ts +13 -6
- package/dist/resource_clients/actor_env_var.js +21 -14
- package/dist/resource_clients/actor_env_var_collection.d.ts +18 -22
- package/dist/resource_clients/actor_env_var_collection.js +23 -20
- package/dist/resource_clients/actor_server.d.ts +149 -0
- package/dist/resource_clients/actor_server.js +199 -0
- package/dist/resource_clients/actor_version.d.ts +30 -10
- package/dist/resource_clients/actor_version.js +29 -23
- package/dist/resource_clients/actor_version_collection.d.ts +20 -21
- package/dist/resource_clients/actor_version_collection.js +25 -20
- package/dist/resource_clients/build.d.ts +24 -11
- package/dist/resource_clients/build.js +43 -26
- package/dist/resource_clients/build_collection.d.ts +10 -8
- package/dist/resource_clients/build_collection.js +13 -13
- package/dist/resource_clients/dataset.d.ts +87 -40
- package/dist/resource_clients/dataset.js +159 -175
- package/dist/resource_clients/dataset_collection.d.ts +13 -9
- package/dist/resource_clients/dataset_collection.js +29 -21
- package/dist/resource_clients/key_value_store.d.ts +110 -28
- package/dist/resource_clients/key_value_store.js +177 -99
- package/dist/resource_clients/key_value_store_collection.d.ts +13 -9
- package/dist/resource_clients/key_value_store_collection.js +29 -21
- package/dist/resource_clients/log.d.ts +42 -23
- package/dist/resource_clients/log.js +156 -85
- package/dist/resource_clients/request_queue.d.ts +77 -38
- package/dist/resource_clients/request_queue.js +251 -172
- package/dist/resource_clients/request_queue_collection.d.ts +12 -8
- package/dist/resource_clients/request_queue_collection.js +23 -20
- package/dist/resource_clients/run.d.ts +134 -34
- package/dist/resource_clients/run.js +225 -84
- package/dist/resource_clients/run_collection.d.ts +8 -6
- package/dist/resource_clients/run_collection.js +18 -18
- package/dist/resource_clients/schedule.d.ts +20 -11
- package/dist/resource_clients/schedule.js +36 -30
- package/dist/resource_clients/schedule_collection.d.ts +10 -6
- package/dist/resource_clients/schedule_collection.js +20 -17
- package/dist/resource_clients/store_collection.d.ts +9 -7
- package/dist/resource_clients/store_collection.js +18 -18
- package/dist/resource_clients/task.d.ts +44 -21
- package/dist/resource_clients/task.js +116 -86
- package/dist/resource_clients/task_collection.d.ts +13 -9
- package/dist/resource_clients/task_collection.js +19 -16
- package/dist/resource_clients/user.d.ts +22 -13
- package/dist/resource_clients/user.js +46 -47
- package/dist/resource_clients/webhook.d.ts +21 -12
- package/dist/resource_clients/webhook.js +35 -30
- package/dist/resource_clients/webhook_collection.d.ts +11 -7
- package/dist/resource_clients/webhook_collection.js +20 -17
- package/dist/resource_clients/webhook_dispatch.d.ts +9 -6
- package/dist/resource_clients/webhook_dispatch.js +11 -10
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +7 -5
- package/dist/resource_clients/webhook_dispatch_collection.js +13 -13
- package/dist/response_validation_error.d.ts +27 -0
- package/dist/response_validation_error.js +38 -0
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +87 -0
- package/dist/runtime/types.d.ts +60 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +21 -0
- package/dist/schemas.d.ts +381 -0
- package/dist/schemas.js +37 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +7 -11
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +99 -70
- package/dist/utils.js +251 -229
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +48 -47
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -157
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -260
- package/dist/index.mjs +0 -42
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -110
package/dist/apify_client.js
CHANGED
|
@@ -1,51 +1,67 @@
|
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 { AxiosHttpClient } from './http_clients/axios.js';
|
|
5
|
+
import { DEFAULT_MAX_RETRIES, DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS, HttpClient, httpClientOptionsShape, } from './http_clients/base.js';
|
|
6
|
+
import { compressionSchema } from './http_compressors/resolve.js';
|
|
7
|
+
import { ActorClient } from './resource_clients/actor.js';
|
|
8
|
+
import { ActorCollectionClient } from './resource_clients/actor_collection.js';
|
|
9
|
+
import { BuildClient } from './resource_clients/build.js';
|
|
10
|
+
import { BuildCollectionClient } from './resource_clients/build_collection.js';
|
|
11
|
+
import { DatasetClient } from './resource_clients/dataset.js';
|
|
12
|
+
import { DatasetCollectionClient } from './resource_clients/dataset_collection.js';
|
|
13
|
+
import { KeyValueStoreClient } from './resource_clients/key_value_store.js';
|
|
14
|
+
import { KeyValueStoreCollectionClient } from './resource_clients/key_value_store_collection.js';
|
|
15
|
+
import { LogClient } from './resource_clients/log.js';
|
|
16
|
+
import { RequestQueueClient } from './resource_clients/request_queue.js';
|
|
17
|
+
import { RequestQueueCollectionClient } from './resource_clients/request_queue_collection.js';
|
|
18
|
+
import { RunClient } from './resource_clients/run.js';
|
|
19
|
+
import { RunCollectionClient } from './resource_clients/run_collection.js';
|
|
20
|
+
import { ScheduleClient } from './resource_clients/schedule.js';
|
|
21
|
+
import { ScheduleCollectionClient } from './resource_clients/schedule_collection.js';
|
|
22
|
+
import { StoreCollectionClient } from './resource_clients/store_collection.js';
|
|
23
|
+
import { TaskClient } from './resource_clients/task.js';
|
|
24
|
+
import { TaskCollectionClient } from './resource_clients/task_collection.js';
|
|
25
|
+
import { UserClient } from './resource_clients/user.js';
|
|
26
|
+
import { WebhookClient } from './resource_clients/webhook.js';
|
|
27
|
+
import { WebhookCollectionClient } from './resource_clients/webhook_collection.js';
|
|
28
|
+
import { WebhookDispatchClient } from './resource_clients/webhook_dispatch.js';
|
|
29
|
+
import { WebhookDispatchCollectionClient } from './resource_clients/webhook_dispatch_collection.js';
|
|
30
|
+
import { Statistics } from './statistics.js';
|
|
31
|
+
import { DEFAULT_TIMEOUT_LONG_SECS, DEFAULT_TIMEOUT_MAX_SECS, DEFAULT_TIMEOUT_MEDIUM_SECS, DEFAULT_TIMEOUT_SHORT_SECS, } from './timeouts.js';
|
|
32
|
+
import { getEnv, parseArgument } from './utils.js';
|
|
33
|
+
const DEFAULT_API_URL = 'https://api.apify.com';
|
|
34
|
+
const API_VERSION_PATH = '/v2';
|
|
35
|
+
function toApiBaseUrl(url) {
|
|
36
|
+
const parsed = new URL(url);
|
|
37
|
+
const path = parsed.pathname.replace(/\/+$/, '');
|
|
38
|
+
parsed.pathname = path.endsWith(API_VERSION_PATH) ? path : `${path}${API_VERSION_PATH}`;
|
|
39
|
+
return parsed.href;
|
|
40
|
+
}
|
|
41
|
+
const clientOptionsSchema = z.strictObject({
|
|
42
|
+
baseUrl: z.string().default(DEFAULT_API_URL),
|
|
43
|
+
compression: compressionSchema.default('brotli'),
|
|
44
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
45
|
+
publicBaseUrl: z.string().default(DEFAULT_API_URL),
|
|
46
|
+
maxRetries: httpClientOptionsShape.maxRetries.default(DEFAULT_MAX_RETRIES),
|
|
47
|
+
minDelayBetweenRetriesMillis: httpClientOptionsShape.minDelayBetweenRetriesMillis.default(DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS),
|
|
48
|
+
timeoutShortSecs: httpClientOptionsShape.timeoutShortSecs.default(DEFAULT_TIMEOUT_SHORT_SECS),
|
|
49
|
+
timeoutMediumSecs: httpClientOptionsShape.timeoutMediumSecs.default(DEFAULT_TIMEOUT_MEDIUM_SECS),
|
|
50
|
+
timeoutLongSecs: httpClientOptionsShape.timeoutLongSecs.default(DEFAULT_TIMEOUT_LONG_SECS),
|
|
51
|
+
timeoutMaxSecs: httpClientOptionsShape.timeoutMaxSecs.default(DEFAULT_TIMEOUT_MAX_SECS),
|
|
52
|
+
token: z.string().optional(),
|
|
53
|
+
userAgentSuffix: z.union([z.string(), z.array(z.string())]).optional(),
|
|
54
|
+
});
|
|
55
|
+
const customHttpClientOptionsSchema = z.strictObject({
|
|
56
|
+
baseUrl: z.string().default(DEFAULT_API_URL),
|
|
57
|
+
publicBaseUrl: z.string().default(DEFAULT_API_URL),
|
|
58
|
+
token: z.string().optional(),
|
|
59
|
+
httpClient: z.instanceof(HttpClient),
|
|
44
60
|
});
|
|
45
|
-
const resourceIdSchema =
|
|
46
|
-
const requestQueueOptionsSchema =
|
|
47
|
-
clientKey:
|
|
48
|
-
timeoutSecs:
|
|
61
|
+
const resourceIdSchema = z.string().min(1);
|
|
62
|
+
const requestQueueOptionsSchema = z.strictObject({
|
|
63
|
+
clientKey: z.string().min(1).optional(),
|
|
64
|
+
timeoutSecs: z.number().positive().optional(),
|
|
49
65
|
});
|
|
50
66
|
/**
|
|
51
67
|
* The official JavaScript client for the Apify API.
|
|
@@ -68,40 +84,105 @@ const requestQueueOptionsSchema = zod_1.z.strictObject({
|
|
|
68
84
|
*
|
|
69
85
|
* @see https://docs.apify.com/api/v2
|
|
70
86
|
*/
|
|
71
|
-
class ApifyClient {
|
|
87
|
+
export class ApifyClient {
|
|
72
88
|
baseUrl;
|
|
73
89
|
/**
|
|
74
90
|
* @since Added in 2.17.0
|
|
75
91
|
*/
|
|
76
92
|
publicBaseUrl;
|
|
77
93
|
token;
|
|
94
|
+
/**
|
|
95
|
+
* Statistics of the API calls made through the client. With a custom HTTP client, this is the client's own
|
|
96
|
+
* `stats` object, so it only reflects what that client records.
|
|
97
|
+
*/
|
|
78
98
|
stats;
|
|
79
99
|
logger;
|
|
80
|
-
httpClient;
|
|
100
|
+
#httpClient;
|
|
101
|
+
/** Configuration of the default HTTP client, applied when no custom one is set. */
|
|
102
|
+
#httpClientOptions;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a client that sends its requests through the built-in {@link AxiosHttpClient}, configured from
|
|
105
|
+
* `options`: the API token, retries, the timeout tiers, request compression and default headers. The HTTP
|
|
106
|
+
* client itself is created when {@link httpClient} is first read. To send the requests through a custom HTTP
|
|
107
|
+
* client, use {@link ApifyClient.withCustomHttpClient} instead.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Configuration of the client and of its HTTP client.
|
|
110
|
+
* @throws {ArgumentValidationError} When an option is unknown or has an invalid value.
|
|
111
|
+
*/
|
|
81
112
|
constructor(options = {}) {
|
|
82
|
-
const parsed =
|
|
83
|
-
const { baseUrl, publicBaseUrl, maxRetries, minDelayBetweenRetriesMillis,
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
const tempPublicBaseUrl = publicBaseUrl.endsWith('/')
|
|
87
|
-
? publicBaseUrl.slice(0, publicBaseUrl.length - 1)
|
|
88
|
-
: publicBaseUrl;
|
|
89
|
-
this.publicBaseUrl = `${tempPublicBaseUrl}/v2`;
|
|
113
|
+
const parsed = parseArgument(options, clientOptionsSchema, 'ApifyClientOptions');
|
|
114
|
+
const { baseUrl, compression, headers, publicBaseUrl, maxRetries, minDelayBetweenRetriesMillis, timeoutShortSecs, timeoutMediumSecs, timeoutLongSecs, timeoutMaxSecs, token, } = parsed;
|
|
115
|
+
this.baseUrl = toApiBaseUrl(baseUrl);
|
|
116
|
+
this.publicBaseUrl = toApiBaseUrl(publicBaseUrl);
|
|
90
117
|
this.token = token;
|
|
91
|
-
this.stats = new
|
|
92
|
-
this.logger =
|
|
93
|
-
this
|
|
94
|
-
|
|
118
|
+
this.stats = new Statistics();
|
|
119
|
+
this.logger = logger.child({ prefix: 'ApifyClient' });
|
|
120
|
+
this.#httpClientOptions = {
|
|
121
|
+
stats: this.stats,
|
|
95
122
|
maxRetries,
|
|
96
123
|
minDelayBetweenRetriesMillis,
|
|
97
|
-
|
|
98
|
-
|
|
124
|
+
compression,
|
|
125
|
+
headers,
|
|
126
|
+
timeoutShortSecs,
|
|
127
|
+
timeoutMediumSecs,
|
|
128
|
+
timeoutLongSecs,
|
|
129
|
+
timeoutMaxSecs,
|
|
99
130
|
logger: this.logger,
|
|
100
131
|
token: this.token,
|
|
101
132
|
userAgentSuffix: parsed.userAgentSuffix,
|
|
102
|
-
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Creates an `ApifyClient` that sends its requests through a custom HTTP client.
|
|
137
|
+
*
|
|
138
|
+
* The custom client owns its transport configuration: retries, timeouts, default headers and whatever its
|
|
139
|
+
* transport needs are set on the client itself. This is also how the built-in {@link AxiosHttpClient} is
|
|
140
|
+
* configured beyond what the constructor options offer, for example with axios request interceptors. The
|
|
141
|
+
* token is set as the client's `Authorization` header, unless the client already has one configured.
|
|
142
|
+
*
|
|
143
|
+
* @param options - The token, the API URLs and the HTTP client to use.
|
|
144
|
+
* @returns A client whose {@link httpClient} is the given one.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```javascript
|
|
148
|
+
* import { ApifyClient, HttpClient } from 'apify-client';
|
|
149
|
+
*
|
|
150
|
+
* class MyHttpClient extends HttpClient {
|
|
151
|
+
* async sendRequest({ method, url, headers, body, timeoutMillis, stream, signal }) {
|
|
152
|
+
* // Send the request with the HTTP library of your choice and return { status, headers, body }.
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* const client = ApifyClient.withCustomHttpClient({ token: 'my-token', httpClient: new MyHttpClient() });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
static withCustomHttpClient(options) {
|
|
160
|
+
const { httpClient, ...rest } = parseArgument(options, customHttpClientOptionsSchema, 'ApifyClientCustomHttpClientOptions');
|
|
161
|
+
const client = new ApifyClient(rest);
|
|
162
|
+
client.httpClient = httpClient;
|
|
163
|
+
return client;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The HTTP client the requests go through: the custom one when set through
|
|
167
|
+
* {@link ApifyClient.withCustomHttpClient}, and otherwise an {@link AxiosHttpClient} configured from the
|
|
168
|
+
* constructor options, created on first access. Assigning a client applies {@link token} to it through
|
|
169
|
+
* {@link HttpClient.setDefaultAuthorization} and points {@link stats} at its statistics, so the counters keep
|
|
170
|
+
* tracking the calls the client actually makes. Resource clients hold on to the HTTP client they were created
|
|
171
|
+
* with, so assign before reaching for them. Assigning does not close the client it replaces. A default client
|
|
172
|
+
* that already sent a request keeps its keep-alive agents open until {@link HttpClient.close} is called on it,
|
|
173
|
+
* so close it yourself, or assign before the first request.
|
|
174
|
+
*/
|
|
175
|
+
get httpClient() {
|
|
176
|
+
this.#httpClient ??= new AxiosHttpClient(this.#httpClientOptions);
|
|
177
|
+
return this.#httpClient;
|
|
178
|
+
}
|
|
179
|
+
set httpClient(httpClient) {
|
|
180
|
+
if (this.token)
|
|
181
|
+
httpClient.setDefaultAuthorization(this.token);
|
|
182
|
+
this.#httpClient = httpClient;
|
|
183
|
+
this.stats = httpClient.stats;
|
|
103
184
|
}
|
|
104
|
-
|
|
185
|
+
#subClientOptions() {
|
|
105
186
|
return {
|
|
106
187
|
baseUrl: this.baseUrl,
|
|
107
188
|
publicBaseUrl: this.publicBaseUrl,
|
|
@@ -118,7 +199,7 @@ class ApifyClient {
|
|
|
118
199
|
* @see https://docs.apify.com/api/v2/acts-get
|
|
119
200
|
*/
|
|
120
201
|
actors() {
|
|
121
|
-
return new
|
|
202
|
+
return new ActorCollectionClient(this.#subClientOptions());
|
|
122
203
|
}
|
|
123
204
|
/**
|
|
124
205
|
* Returns a client for a specific Actor.
|
|
@@ -137,10 +218,10 @@ class ApifyClient {
|
|
|
137
218
|
* ```
|
|
138
219
|
*/
|
|
139
220
|
actor(id) {
|
|
140
|
-
|
|
141
|
-
return new
|
|
221
|
+
parseArgument(id, resourceIdSchema);
|
|
222
|
+
return new ActorClient({
|
|
142
223
|
id,
|
|
143
|
-
...this
|
|
224
|
+
...this.#subClientOptions(),
|
|
144
225
|
});
|
|
145
226
|
}
|
|
146
227
|
/**
|
|
@@ -152,7 +233,7 @@ class ApifyClient {
|
|
|
152
233
|
* @see https://docs.apify.com/api/v2/actor-builds-get
|
|
153
234
|
*/
|
|
154
235
|
builds() {
|
|
155
|
-
return new
|
|
236
|
+
return new BuildCollectionClient(this.#subClientOptions());
|
|
156
237
|
}
|
|
157
238
|
/**
|
|
158
239
|
* Returns a client for a specific Actor build.
|
|
@@ -164,10 +245,10 @@ class ApifyClient {
|
|
|
164
245
|
* @see https://docs.apify.com/api/v2/actor-build-get
|
|
165
246
|
*/
|
|
166
247
|
build(id) {
|
|
167
|
-
|
|
168
|
-
return new
|
|
248
|
+
parseArgument(id, resourceIdSchema);
|
|
249
|
+
return new BuildClient({
|
|
169
250
|
id,
|
|
170
|
-
...this
|
|
251
|
+
...this.#subClientOptions(),
|
|
171
252
|
});
|
|
172
253
|
}
|
|
173
254
|
/**
|
|
@@ -179,7 +260,7 @@ class ApifyClient {
|
|
|
179
260
|
* @see https://docs.apify.com/api/v2/datasets-get
|
|
180
261
|
*/
|
|
181
262
|
datasets() {
|
|
182
|
-
return new
|
|
263
|
+
return new DatasetCollectionClient(this.#subClientOptions());
|
|
183
264
|
}
|
|
184
265
|
/**
|
|
185
266
|
* Returns a client for a specific dataset.
|
|
@@ -205,10 +286,10 @@ class ApifyClient {
|
|
|
205
286
|
* ```
|
|
206
287
|
*/
|
|
207
288
|
dataset(id) {
|
|
208
|
-
|
|
209
|
-
return new
|
|
289
|
+
parseArgument(id, resourceIdSchema);
|
|
290
|
+
return new DatasetClient({
|
|
210
291
|
id,
|
|
211
|
-
...this
|
|
292
|
+
...this.#subClientOptions(),
|
|
212
293
|
});
|
|
213
294
|
}
|
|
214
295
|
/**
|
|
@@ -220,7 +301,7 @@ class ApifyClient {
|
|
|
220
301
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
221
302
|
*/
|
|
222
303
|
keyValueStores() {
|
|
223
|
-
return new
|
|
304
|
+
return new KeyValueStoreCollectionClient(this.#subClientOptions());
|
|
224
305
|
}
|
|
225
306
|
/**
|
|
226
307
|
* Returns a client for a specific key-value store.
|
|
@@ -242,10 +323,10 @@ class ApifyClient {
|
|
|
242
323
|
* ```
|
|
243
324
|
*/
|
|
244
325
|
keyValueStore(id) {
|
|
245
|
-
|
|
246
|
-
return new
|
|
326
|
+
parseArgument(id, resourceIdSchema);
|
|
327
|
+
return new KeyValueStoreClient({
|
|
247
328
|
id,
|
|
248
|
-
...this
|
|
329
|
+
...this.#subClientOptions(),
|
|
249
330
|
});
|
|
250
331
|
}
|
|
251
332
|
/**
|
|
@@ -256,10 +337,10 @@ class ApifyClient {
|
|
|
256
337
|
* @see https://docs.apify.com/api/v2/log-get
|
|
257
338
|
*/
|
|
258
339
|
log(buildOrRunId) {
|
|
259
|
-
|
|
260
|
-
return new
|
|
340
|
+
parseArgument(buildOrRunId, resourceIdSchema);
|
|
341
|
+
return new LogClient({
|
|
261
342
|
id: buildOrRunId,
|
|
262
|
-
...this
|
|
343
|
+
...this.#subClientOptions(),
|
|
263
344
|
});
|
|
264
345
|
}
|
|
265
346
|
/**
|
|
@@ -271,7 +352,7 @@ class ApifyClient {
|
|
|
271
352
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
272
353
|
*/
|
|
273
354
|
requestQueues() {
|
|
274
|
-
return new
|
|
355
|
+
return new RequestQueueCollectionClient(this.#subClientOptions());
|
|
275
356
|
}
|
|
276
357
|
/**
|
|
277
358
|
* Returns a client for a specific request queue.
|
|
@@ -295,13 +376,13 @@ class ApifyClient {
|
|
|
295
376
|
* ```
|
|
296
377
|
*/
|
|
297
378
|
requestQueue(id, options = {}) {
|
|
298
|
-
|
|
299
|
-
const parsed =
|
|
379
|
+
parseArgument(id, resourceIdSchema);
|
|
380
|
+
const parsed = parseArgument(options, requestQueueOptionsSchema, 'RequestQueueUserOptions');
|
|
300
381
|
const apiClientOptions = {
|
|
301
382
|
id,
|
|
302
|
-
...this
|
|
383
|
+
...this.#subClientOptions(),
|
|
303
384
|
};
|
|
304
|
-
return new
|
|
385
|
+
return new RequestQueueClient(apiClientOptions, parsed);
|
|
305
386
|
}
|
|
306
387
|
/**
|
|
307
388
|
* Returns a client for managing Actor runs in your account.
|
|
@@ -312,8 +393,8 @@ class ApifyClient {
|
|
|
312
393
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
313
394
|
*/
|
|
314
395
|
runs() {
|
|
315
|
-
return new
|
|
316
|
-
...this
|
|
396
|
+
return new RunCollectionClient({
|
|
397
|
+
...this.#subClientOptions(),
|
|
317
398
|
resourcePath: 'actor-runs',
|
|
318
399
|
});
|
|
319
400
|
}
|
|
@@ -337,10 +418,10 @@ class ApifyClient {
|
|
|
337
418
|
* ```
|
|
338
419
|
*/
|
|
339
420
|
run(id) {
|
|
340
|
-
|
|
341
|
-
return new
|
|
421
|
+
parseArgument(id, resourceIdSchema);
|
|
422
|
+
return new RunClient({
|
|
342
423
|
id,
|
|
343
|
-
...this
|
|
424
|
+
...this.#subClientOptions(),
|
|
344
425
|
});
|
|
345
426
|
}
|
|
346
427
|
/**
|
|
@@ -352,7 +433,7 @@ class ApifyClient {
|
|
|
352
433
|
* @see https://docs.apify.com/api/v2/actor-tasks-get
|
|
353
434
|
*/
|
|
354
435
|
tasks() {
|
|
355
|
-
return new
|
|
436
|
+
return new TaskCollectionClient(this.#subClientOptions());
|
|
356
437
|
}
|
|
357
438
|
/**
|
|
358
439
|
* Returns a client for a specific Actor task.
|
|
@@ -370,10 +451,10 @@ class ApifyClient {
|
|
|
370
451
|
* ```
|
|
371
452
|
*/
|
|
372
453
|
task(id) {
|
|
373
|
-
|
|
374
|
-
return new
|
|
454
|
+
parseArgument(id, resourceIdSchema);
|
|
455
|
+
return new TaskClient({
|
|
375
456
|
id,
|
|
376
|
-
...this
|
|
457
|
+
...this.#subClientOptions(),
|
|
377
458
|
});
|
|
378
459
|
}
|
|
379
460
|
/**
|
|
@@ -385,7 +466,7 @@ class ApifyClient {
|
|
|
385
466
|
* @see https://docs.apify.com/api/v2/schedules-get
|
|
386
467
|
*/
|
|
387
468
|
schedules() {
|
|
388
|
-
return new
|
|
469
|
+
return new ScheduleCollectionClient(this.#subClientOptions());
|
|
389
470
|
}
|
|
390
471
|
/**
|
|
391
472
|
* Returns a client for a specific schedule.
|
|
@@ -397,10 +478,10 @@ class ApifyClient {
|
|
|
397
478
|
* @see https://docs.apify.com/api/v2/schedule-get
|
|
398
479
|
*/
|
|
399
480
|
schedule(id) {
|
|
400
|
-
|
|
401
|
-
return new
|
|
481
|
+
parseArgument(id, resourceIdSchema);
|
|
482
|
+
return new ScheduleClient({
|
|
402
483
|
id,
|
|
403
|
-
...this
|
|
484
|
+
...this.#subClientOptions(),
|
|
404
485
|
});
|
|
405
486
|
}
|
|
406
487
|
/**
|
|
@@ -412,11 +493,11 @@ class ApifyClient {
|
|
|
412
493
|
* @returns A client for the user
|
|
413
494
|
* @see https://docs.apify.com/api/v2/user-get
|
|
414
495
|
*/
|
|
415
|
-
user(id =
|
|
416
|
-
|
|
417
|
-
return new
|
|
496
|
+
user(id = ME_USER_NAME_PLACEHOLDER) {
|
|
497
|
+
parseArgument(id, resourceIdSchema);
|
|
498
|
+
return new UserClient({
|
|
418
499
|
id,
|
|
419
|
-
...this
|
|
500
|
+
...this.#subClientOptions(),
|
|
420
501
|
});
|
|
421
502
|
}
|
|
422
503
|
/**
|
|
@@ -428,7 +509,7 @@ class ApifyClient {
|
|
|
428
509
|
* @see https://docs.apify.com/api/v2/webhooks-get
|
|
429
510
|
*/
|
|
430
511
|
webhooks() {
|
|
431
|
-
return new
|
|
512
|
+
return new WebhookCollectionClient(this.#subClientOptions());
|
|
432
513
|
}
|
|
433
514
|
/**
|
|
434
515
|
* Returns a client for a specific webhook.
|
|
@@ -440,10 +521,10 @@ class ApifyClient {
|
|
|
440
521
|
* @see https://docs.apify.com/api/v2/webhook-get
|
|
441
522
|
*/
|
|
442
523
|
webhook(id) {
|
|
443
|
-
|
|
444
|
-
return new
|
|
524
|
+
parseArgument(id, resourceIdSchema);
|
|
525
|
+
return new WebhookClient({
|
|
445
526
|
id,
|
|
446
|
-
...this
|
|
527
|
+
...this.#subClientOptions(),
|
|
447
528
|
});
|
|
448
529
|
}
|
|
449
530
|
/**
|
|
@@ -455,7 +536,7 @@ class ApifyClient {
|
|
|
455
536
|
* @see https://docs.apify.com/api/v2/webhook-dispatches-get
|
|
456
537
|
*/
|
|
457
538
|
webhookDispatches() {
|
|
458
|
-
return new
|
|
539
|
+
return new WebhookDispatchCollectionClient(this.#subClientOptions());
|
|
459
540
|
}
|
|
460
541
|
/**
|
|
461
542
|
* Returns a client for a specific webhook dispatch.
|
|
@@ -465,10 +546,10 @@ class ApifyClient {
|
|
|
465
546
|
* @see https://docs.apify.com/api/v2/webhook-dispatch-get
|
|
466
547
|
*/
|
|
467
548
|
webhookDispatch(id) {
|
|
468
|
-
|
|
469
|
-
return new
|
|
549
|
+
parseArgument(id, resourceIdSchema);
|
|
550
|
+
return new WebhookDispatchClient({
|
|
470
551
|
id,
|
|
471
|
-
...this
|
|
552
|
+
...this.#subClientOptions(),
|
|
472
553
|
});
|
|
473
554
|
}
|
|
474
555
|
/**
|
|
@@ -480,7 +561,7 @@ class ApifyClient {
|
|
|
480
561
|
* @see https://docs.apify.com/api/v2/store-get
|
|
481
562
|
*/
|
|
482
563
|
store() {
|
|
483
|
-
return new
|
|
564
|
+
return new StoreCollectionClient(this.#subClientOptions());
|
|
484
565
|
}
|
|
485
566
|
/**
|
|
486
567
|
* Sets a status message for the current Actor run.
|
|
@@ -494,9 +575,9 @@ class ApifyClient {
|
|
|
494
575
|
* @since Added in 2.7.0
|
|
495
576
|
*/
|
|
496
577
|
async setStatusMessage(message, options) {
|
|
497
|
-
const runId =
|
|
578
|
+
const runId = getEnv(ACTOR_ENV_VARS.RUN_ID);
|
|
498
579
|
if (!runId) {
|
|
499
|
-
throw new Error(`Environment variable ${
|
|
580
|
+
throw new Error(`Environment variable ${ACTOR_ENV_VARS.RUN_ID} is not set!`);
|
|
500
581
|
}
|
|
501
582
|
await this.run(runId).update({
|
|
502
583
|
statusMessage: message,
|
|
@@ -504,4 +585,3 @@ class ApifyClient {
|
|
|
504
585
|
});
|
|
505
586
|
}
|
|
506
587
|
}
|
|
507
|
-
exports.ApifyClient = ApifyClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of the errors the client throws for a failed API call: {@link ApifyApiError} and its subclasses,
|
|
3
|
+
* {@link InvalidResponseBodyError} and {@link ResponseValidationError}. A single `instanceof ApifyClientError`
|
|
4
|
+
* check catches all of them.
|
|
5
|
+
*
|
|
6
|
+
* Invalid arguments throw an `ArgumentValidationError` before any request is sent, and transport errors, timeouts
|
|
7
|
+
* and aborts surface as the errors the transport raised. None of those extend this class.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ApifyClientError extends Error {
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of the errors the client throws for a failed API call: {@link ApifyApiError} and its subclasses,
|
|
3
|
+
* {@link InvalidResponseBodyError} and {@link ResponseValidationError}. A single `instanceof ApifyClientError`
|
|
4
|
+
* check catches all of them.
|
|
5
|
+
*
|
|
6
|
+
* Invalid arguments throw an `ArgumentValidationError` before any request is sent, and transport errors, timeouts
|
|
7
|
+
* and aborts surface as the errors the transport raised. None of those extend this class.
|
|
8
|
+
*/
|
|
9
|
+
export class ApifyClientError extends Error {
|
|
10
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ApifyClient } from '../apify_client';
|
|
2
|
-
import type { HttpClient } from '../
|
|
3
|
-
import type { PaginatedResponse, PaginationOptions } from '../utils';
|
|
1
|
+
import type { ApifyClient } from '../apify_client.js';
|
|
2
|
+
import type { HttpClient } from '../http_clients/index.js';
|
|
3
|
+
import type { PaginatedResponse, PaginationOptions } from '../utils.js';
|
|
4
4
|
/** @private */
|
|
5
5
|
export interface ApiClientOptions {
|
|
6
6
|
baseUrl: string;
|
|
@@ -30,15 +30,15 @@ export declare abstract class ApiClient {
|
|
|
30
30
|
httpClient: HttpClient;
|
|
31
31
|
params?: Record<string, unknown>;
|
|
32
32
|
constructor(options: ApiClientOptions);
|
|
33
|
-
protected
|
|
34
|
-
protected
|
|
35
|
-
protected
|
|
36
|
-
protected
|
|
37
|
-
protected
|
|
33
|
+
protected subResourceOptions<T>(moreOptions?: T): BaseOptions & T;
|
|
34
|
+
protected buildUrl(path?: string | string[]): string;
|
|
35
|
+
protected buildPublicUrl(path?: string | string[]): string;
|
|
36
|
+
protected buildParams<T>(endpointParams?: T): Record<string, unknown>;
|
|
37
|
+
protected toSafeId(id: string): string;
|
|
38
38
|
/**
|
|
39
39
|
* Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
|
|
40
40
|
*/
|
|
41
|
-
protected
|
|
41
|
+
protected listPaginatedFromCallback<T extends PaginationOptions, Data, R extends PaginatedResponse<Data>>(getPaginatedList: (options?: T) => Promise<R>, options?: T): AsyncIterable<Data> & Promise<R>;
|
|
42
42
|
}
|
|
43
43
|
export interface BaseOptions {
|
|
44
44
|
baseUrl: string;
|