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.
Files changed (131) hide show
  1. package/README.md +21 -5
  2. package/dist/apify_api_error.d.ts +64 -22
  3. package/dist/apify_api_error.js +100 -30
  4. package/dist/apify_client.d.ts +150 -35
  5. package/dist/apify_client.js +198 -118
  6. package/dist/apify_client_error.d.ts +10 -0
  7. package/dist/apify_client_error.js +10 -0
  8. package/dist/base/api_client.d.ts +9 -9
  9. package/dist/base/api_client.js +41 -45
  10. package/dist/base/resource_client.d.ts +24 -10
  11. package/dist/base/resource_client.js +78 -48
  12. package/dist/base/resource_collection_client.d.ts +15 -6
  13. package/dist/base/resource_collection_client.js +40 -21
  14. package/dist/body_parser.d.ts +3 -4
  15. package/dist/body_parser.js +20 -32
  16. package/dist/bundle.js +47 -52
  17. package/dist/bundle.js.map +1 -1
  18. package/dist/generated/api.d.ts +3363 -1185
  19. package/dist/generated/api.js +1 -2
  20. package/dist/generated/schemas.d.ts +8146 -0
  21. package/dist/generated/schemas.js +1866 -0
  22. package/dist/http_clients/axios.d.ts +61 -0
  23. package/dist/http_clients/axios.js +119 -0
  24. package/dist/http_clients/base.d.ts +391 -0
  25. package/dist/http_clients/base.js +650 -0
  26. package/dist/http_clients/index.d.ts +4 -0
  27. package/dist/http_clients/index.js +2 -0
  28. package/dist/http_compressors/base.d.ts +40 -0
  29. package/dist/http_compressors/base.js +9 -0
  30. package/dist/http_compressors/brotli.d.ts +33 -0
  31. package/dist/http_compressors/brotli.js +39 -0
  32. package/dist/http_compressors/gzip.d.ts +33 -0
  33. package/dist/http_compressors/gzip.js +39 -0
  34. package/dist/http_compressors/index.d.ts +8 -0
  35. package/dist/http_compressors/index.js +3 -0
  36. package/dist/http_compressors/resolve.d.ts +24 -0
  37. package/dist/http_compressors/resolve.js +30 -0
  38. package/dist/http_compressors/zstd.d.ts +34 -0
  39. package/dist/http_compressors/zstd.js +43 -0
  40. package/dist/index.d.ts +38 -32
  41. package/dist/index.js +36 -36
  42. package/dist/invalid_response_body_error.d.ts +14 -0
  43. package/dist/invalid_response_body_error.js +18 -0
  44. package/dist/lazy_schema.d.ts +8 -0
  45. package/dist/lazy_schema.js +11 -0
  46. package/dist/models.d.ts +196 -278
  47. package/dist/models.js +14 -15
  48. package/dist/resource_clients/actor.d.ts +115 -45
  49. package/dist/resource_clients/actor.js +187 -116
  50. package/dist/resource_clients/actor_collection.d.ts +21 -17
  51. package/dist/resource_clients/actor_collection.js +26 -21
  52. package/dist/resource_clients/actor_env_var.d.ts +13 -6
  53. package/dist/resource_clients/actor_env_var.js +21 -14
  54. package/dist/resource_clients/actor_env_var_collection.d.ts +18 -22
  55. package/dist/resource_clients/actor_env_var_collection.js +23 -20
  56. package/dist/resource_clients/actor_server.d.ts +149 -0
  57. package/dist/resource_clients/actor_server.js +199 -0
  58. package/dist/resource_clients/actor_version.d.ts +30 -10
  59. package/dist/resource_clients/actor_version.js +29 -23
  60. package/dist/resource_clients/actor_version_collection.d.ts +20 -21
  61. package/dist/resource_clients/actor_version_collection.js +25 -20
  62. package/dist/resource_clients/build.d.ts +24 -11
  63. package/dist/resource_clients/build.js +43 -26
  64. package/dist/resource_clients/build_collection.d.ts +10 -8
  65. package/dist/resource_clients/build_collection.js +13 -13
  66. package/dist/resource_clients/dataset.d.ts +87 -40
  67. package/dist/resource_clients/dataset.js +159 -175
  68. package/dist/resource_clients/dataset_collection.d.ts +13 -9
  69. package/dist/resource_clients/dataset_collection.js +29 -21
  70. package/dist/resource_clients/key_value_store.d.ts +110 -28
  71. package/dist/resource_clients/key_value_store.js +177 -99
  72. package/dist/resource_clients/key_value_store_collection.d.ts +13 -9
  73. package/dist/resource_clients/key_value_store_collection.js +29 -21
  74. package/dist/resource_clients/log.d.ts +42 -23
  75. package/dist/resource_clients/log.js +156 -85
  76. package/dist/resource_clients/request_queue.d.ts +77 -38
  77. package/dist/resource_clients/request_queue.js +251 -172
  78. package/dist/resource_clients/request_queue_collection.d.ts +12 -8
  79. package/dist/resource_clients/request_queue_collection.js +23 -20
  80. package/dist/resource_clients/run.d.ts +134 -34
  81. package/dist/resource_clients/run.js +225 -84
  82. package/dist/resource_clients/run_collection.d.ts +8 -6
  83. package/dist/resource_clients/run_collection.js +18 -18
  84. package/dist/resource_clients/schedule.d.ts +20 -11
  85. package/dist/resource_clients/schedule.js +36 -30
  86. package/dist/resource_clients/schedule_collection.d.ts +10 -6
  87. package/dist/resource_clients/schedule_collection.js +20 -17
  88. package/dist/resource_clients/store_collection.d.ts +9 -7
  89. package/dist/resource_clients/store_collection.js +18 -18
  90. package/dist/resource_clients/task.d.ts +44 -21
  91. package/dist/resource_clients/task.js +116 -86
  92. package/dist/resource_clients/task_collection.d.ts +13 -9
  93. package/dist/resource_clients/task_collection.js +19 -16
  94. package/dist/resource_clients/user.d.ts +22 -13
  95. package/dist/resource_clients/user.js +46 -47
  96. package/dist/resource_clients/webhook.d.ts +21 -12
  97. package/dist/resource_clients/webhook.js +35 -30
  98. package/dist/resource_clients/webhook_collection.d.ts +11 -7
  99. package/dist/resource_clients/webhook_collection.js +20 -17
  100. package/dist/resource_clients/webhook_dispatch.d.ts +9 -6
  101. package/dist/resource_clients/webhook_dispatch.js +11 -10
  102. package/dist/resource_clients/webhook_dispatch_collection.d.ts +7 -5
  103. package/dist/resource_clients/webhook_dispatch_collection.js +13 -13
  104. package/dist/response_validation_error.d.ts +27 -0
  105. package/dist/response_validation_error.js +38 -0
  106. package/dist/runtime/node.d.ts +6 -0
  107. package/dist/runtime/node.js +87 -0
  108. package/dist/runtime/types.d.ts +60 -0
  109. package/dist/runtime/types.js +1 -0
  110. package/dist/runtime/web.d.ts +5 -0
  111. package/dist/runtime/web.js +21 -0
  112. package/dist/schemas.d.ts +381 -0
  113. package/dist/schemas.js +37 -0
  114. package/dist/statistics.d.ts +1 -6
  115. package/dist/statistics.js +7 -11
  116. package/dist/timeouts.d.ts +84 -0
  117. package/dist/timeouts.js +37 -0
  118. package/dist/timezones.d.ts +1 -1
  119. package/dist/timezones.js +1 -2
  120. package/dist/utils.d.ts +99 -70
  121. package/dist/utils.js +251 -229
  122. package/dist/wait_for_resources.d.ts +8 -0
  123. package/dist/wait_for_resources.js +39 -0
  124. package/package.json +48 -47
  125. package/dist/argument_validation_error.d.ts +0 -17
  126. package/dist/argument_validation_error.js +0 -157
  127. package/dist/http_client.d.ts +0 -88
  128. package/dist/http_client.js +0 -260
  129. package/dist/index.mjs +0 -42
  130. package/dist/interceptors.d.ts +0 -19
  131. package/dist/interceptors.js +0 -110
@@ -1,51 +1,67 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApifyClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const zod_1 = require("zod");
6
- const consts_1 = require("@apify/consts");
7
- const log_1 = tslib_1.__importDefault(require("@apify/log"));
8
- const http_client_1 = require("./http_client");
9
- const actor_1 = require("./resource_clients/actor");
10
- const actor_collection_1 = require("./resource_clients/actor_collection");
11
- const build_1 = require("./resource_clients/build");
12
- const build_collection_1 = require("./resource_clients/build_collection");
13
- const dataset_1 = require("./resource_clients/dataset");
14
- const dataset_collection_1 = require("./resource_clients/dataset_collection");
15
- const key_value_store_1 = require("./resource_clients/key_value_store");
16
- const key_value_store_collection_1 = require("./resource_clients/key_value_store_collection");
17
- const log_2 = require("./resource_clients/log");
18
- const request_queue_1 = require("./resource_clients/request_queue");
19
- const request_queue_collection_1 = require("./resource_clients/request_queue_collection");
20
- const run_1 = require("./resource_clients/run");
21
- const run_collection_1 = require("./resource_clients/run_collection");
22
- const schedule_1 = require("./resource_clients/schedule");
23
- const schedule_collection_1 = require("./resource_clients/schedule_collection");
24
- const store_collection_1 = require("./resource_clients/store_collection");
25
- const task_1 = require("./resource_clients/task");
26
- const task_collection_1 = require("./resource_clients/task_collection");
27
- const user_1 = require("./resource_clients/user");
28
- const webhook_1 = require("./resource_clients/webhook");
29
- const webhook_collection_1 = require("./resource_clients/webhook_collection");
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");
34
- const DEFAULT_TIMEOUT_SECS = 360;
35
- const clientOptionsSchema = zod_1.z.strictObject({
36
- baseUrl: zod_1.z.string().default('https://api.apify.com'),
37
- publicBaseUrl: zod_1.z.string().default('https://api.apify.com'),
38
- maxRetries: zod_1.z.number().default(8),
39
- minDelayBetweenRetriesMillis: zod_1.z.number().default(500),
40
- requestInterceptors: zod_1.z.array(zod_1.z.unknown()).default([]),
41
- timeoutSecs: zod_1.z.number().default(DEFAULT_TIMEOUT_SECS),
42
- token: zod_1.z.string().optional(),
43
- userAgentSuffix: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
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 = zod_1.z.string().min(1);
46
- const requestQueueOptionsSchema = zod_1.z.strictObject({
47
- clientKey: zod_1.z.string().min(1).optional(),
48
- timeoutSecs: zod_1.z.number().optional(),
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 = (0, utils_1.parseArgument)(options, clientOptionsSchema, 'ApifyClientOptions');
83
- const { baseUrl, publicBaseUrl, maxRetries, minDelayBetweenRetriesMillis, requestInterceptors, timeoutSecs, token, } = parsed;
84
- const tempBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl;
85
- this.baseUrl = `${tempBaseUrl}/v2`;
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 statistics_1.Statistics();
92
- this.logger = log_1.default.child({ prefix: 'ApifyClient' });
93
- this.httpClient = new http_client_1.HttpClient({
94
- apifyClientStats: this.stats,
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
- requestInterceptors,
98
- timeoutSecs,
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
- _options() {
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 actor_collection_1.ActorCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
141
- return new actor_1.ActorClient({
221
+ parseArgument(id, resourceIdSchema);
222
+ return new ActorClient({
142
223
  id,
143
- ...this._options(),
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 build_collection_1.BuildCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
168
- return new build_1.BuildClient({
248
+ parseArgument(id, resourceIdSchema);
249
+ return new BuildClient({
169
250
  id,
170
- ...this._options(),
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 dataset_collection_1.DatasetCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
209
- return new dataset_1.DatasetClient({
289
+ parseArgument(id, resourceIdSchema);
290
+ return new DatasetClient({
210
291
  id,
211
- ...this._options(),
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 key_value_store_collection_1.KeyValueStoreCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
246
- return new key_value_store_1.KeyValueStoreClient({
326
+ parseArgument(id, resourceIdSchema);
327
+ return new KeyValueStoreClient({
247
328
  id,
248
- ...this._options(),
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
- (0, utils_1.parseArgument)(buildOrRunId, resourceIdSchema);
260
- return new log_2.LogClient({
340
+ parseArgument(buildOrRunId, resourceIdSchema);
341
+ return new LogClient({
261
342
  id: buildOrRunId,
262
- ...this._options(),
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 request_queue_collection_1.RequestQueueCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
299
- const parsed = (0, utils_1.parseArgument)(options, requestQueueOptionsSchema, 'RequestQueueUserOptions');
379
+ parseArgument(id, resourceIdSchema);
380
+ const parsed = parseArgument(options, requestQueueOptionsSchema, 'RequestQueueUserOptions');
300
381
  const apiClientOptions = {
301
382
  id,
302
- ...this._options(),
383
+ ...this.#subClientOptions(),
303
384
  };
304
- return new request_queue_1.RequestQueueClient(apiClientOptions, parsed);
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 run_collection_1.RunCollectionClient({
316
- ...this._options(),
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
341
- return new run_1.RunClient({
421
+ parseArgument(id, resourceIdSchema);
422
+ return new RunClient({
342
423
  id,
343
- ...this._options(),
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 task_collection_1.TaskCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
374
- return new task_1.TaskClient({
454
+ parseArgument(id, resourceIdSchema);
455
+ return new TaskClient({
375
456
  id,
376
- ...this._options(),
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 schedule_collection_1.ScheduleCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
401
- return new schedule_1.ScheduleClient({
481
+ parseArgument(id, resourceIdSchema);
482
+ return new ScheduleClient({
402
483
  id,
403
- ...this._options(),
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 = consts_1.ME_USER_NAME_PLACEHOLDER) {
416
- (0, utils_1.parseArgument)(id, resourceIdSchema);
417
- return new user_1.UserClient({
496
+ user(id = ME_USER_NAME_PLACEHOLDER) {
497
+ parseArgument(id, resourceIdSchema);
498
+ return new UserClient({
418
499
  id,
419
- ...this._options(),
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 webhook_collection_1.WebhookCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
444
- return new webhook_1.WebhookClient({
524
+ parseArgument(id, resourceIdSchema);
525
+ return new WebhookClient({
445
526
  id,
446
- ...this._options(),
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 webhook_dispatch_collection_1.WebhookDispatchCollectionClient(this._options());
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
- (0, utils_1.parseArgument)(id, resourceIdSchema);
469
- return new webhook_dispatch_1.WebhookDispatchClient({
549
+ parseArgument(id, resourceIdSchema);
550
+ return new WebhookDispatchClient({
470
551
  id,
471
- ...this._options(),
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 store_collection_1.StoreCollectionClient(this._options());
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 = process.env[consts_1.ACTOR_ENV_VARS.RUN_ID];
578
+ const runId = getEnv(ACTOR_ENV_VARS.RUN_ID);
498
579
  if (!runId) {
499
- throw new Error(`Environment variable ${consts_1.ACTOR_ENV_VARS.RUN_ID} is not set!`);
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 '../http_client';
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 _subResourceOptions<T>(moreOptions?: T): BaseOptions & T;
34
- protected _url(path?: string | string[]): string;
35
- protected _publicUrl(path?: string | string[]): string;
36
- protected _params<T>(endpointParams?: T): Record<string, unknown>;
37
- protected _toSafeId(id: string): string;
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 _listPaginatedFromCallback<T extends PaginationOptions, Data, R extends PaginatedResponse<Data>>(getPaginatedList: (options?: T) => Promise<R>, options?: T): AsyncIterable<Data> & Promise<R>;
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;