apify-client 3.0.0-beta.16 → 3.0.0-beta.18

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.
@@ -17,10 +17,12 @@ export type { ApifyApiErrorType } from './models.js';
17
17
  * share a status code are told apart by their `type`.
18
18
  */
19
19
  export declare class ApifyApiError extends Error {
20
+ #private;
20
21
  name: string;
21
22
  /**
22
- * The invoked resource client and the method. Known issue: Sometimes it displays
23
- * as `unknown` because it can't be parsed from a stack trace.
23
+ * The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
24
+ * method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
25
+ * when the stack trace cannot be parsed.
24
26
  */
25
27
  clientMethod: string;
26
28
  /**
@@ -62,23 +64,6 @@ export declare class ApifyApiError extends Error {
62
64
  * @hidden
63
65
  */
64
66
  static fromResponse(response: AxiosResponse, attempt: number): ApifyApiError;
65
- private _safelyParsePathFromResponse;
66
- private _extractClientAndMethodFromStack;
67
- /**
68
- * Creates a better looking and more informative stack that will be printed
69
- * out when API errors are thrown.
70
- *
71
- * Example:
72
- *
73
- * NotFoundError: Actor task was not found
74
- * clientMethod: TaskClient.start
75
- * statusCode: 404
76
- * type: record-not-found
77
- * attempt: 1
78
- * httpMethod: post
79
- * path: /v2/actor-tasks/user~my-task/runs
80
- */
81
- private _createApiStack;
82
67
  }
83
68
  /**
84
69
  * Thrown when the Apify API responds with HTTP 400 Bad Request, typically because the request
@@ -10,22 +10,6 @@ import { isBuffer } from './utils.js';
10
10
  * @private
11
11
  */
12
12
  const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\.([A-Za-z]+) \(/;
13
- /**
14
- * A public method that returns the promise of a shared helper without awaiting it leaves only the helper on
15
- * the stack, so the helper is reported under the method the caller invoked.
16
- * @private
17
- */
18
- const PUBLIC_METHOD_BY_HELPER = {
19
- getResource: 'get',
20
- updateResource: 'update',
21
- deleteResource: 'delete',
22
- waitForJobFinish: 'waitForFinish',
23
- listResources: 'list',
24
- createResource: 'create',
25
- getOrCreateResource: 'getOrCreate',
26
- addRequestBatch: 'batchAddRequests',
27
- addRequestBatchWithRetries: 'batchAddRequests',
28
- };
29
13
  /**
30
14
  * An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
31
15
  * but the API responds with an error response. Typically, those are rate limit
@@ -43,8 +27,9 @@ const PUBLIC_METHOD_BY_HELPER = {
43
27
  export class ApifyApiError extends Error {
44
28
  name;
45
29
  /**
46
- * The invoked resource client and the method. Known issue: Sometimes it displays
47
- * as `unknown` because it can't be parsed from a stack trace.
30
+ * The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
31
+ * method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
32
+ * when the stack trace cannot be parsed.
48
33
  */
49
34
  clientMethod;
50
35
  /**
@@ -113,15 +98,15 @@ export class ApifyApiError extends Error {
113
98
  }
114
99
  super(message);
115
100
  this.name = this.constructor.name;
116
- this.clientMethod = this._extractClientAndMethodFromStack();
101
+ this.clientMethod = this.#extractClientAndMethodFromStack();
117
102
  this.statusCode = response.status;
118
103
  this.type = type;
119
104
  this.attempt = attempt;
120
105
  this.httpMethod = response.config?.method;
121
- this.path = this._safelyParsePathFromResponse(response);
106
+ this.path = this.#safelyParsePathFromResponse(response);
122
107
  const stack = this.stack;
123
108
  this.originalStack = stack.slice(stack.indexOf('\n'));
124
- this.stack = this._createApiStack();
109
+ this.stack = this.#createApiStack();
125
110
  this.data = errorData;
126
111
  }
127
112
  /**
@@ -132,7 +117,7 @@ export class ApifyApiError extends Error {
132
117
  const ErrorClass = ERROR_CLASS_BY_STATUS[response.status] ?? (response.status >= 500 ? ServerError : ApifyApiError);
133
118
  return new ErrorClass(response, attempt);
134
119
  }
135
- _safelyParsePathFromResponse(response) {
120
+ #safelyParsePathFromResponse(response) {
136
121
  const urlString = response.config?.url;
137
122
  let url;
138
123
  try {
@@ -143,11 +128,11 @@ export class ApifyApiError extends Error {
143
128
  }
144
129
  return url.pathname + url.search;
145
130
  }
146
- _extractClientAndMethodFromStack() {
131
+ #extractClientAndMethodFromStack() {
147
132
  const match = this.stack.match(CLIENT_METHOD_REGEX);
148
133
  if (!match)
149
134
  return 'unknown';
150
- return `${match[2]}.${PUBLIC_METHOD_BY_HELPER[match[4]] ?? match[4]}`;
135
+ return `${match[2]}.${match[4]}`;
151
136
  }
152
137
  /**
153
138
  * Creates a better looking and more informative stack that will be printed
@@ -163,7 +148,7 @@ export class ApifyApiError extends Error {
163
148
  * httpMethod: post
164
149
  * path: /v2/actor-tasks/user~my-task/runs
165
150
  */
166
- _createApiStack() {
151
+ #createApiStack() {
167
152
  const { name, ...props } = this;
168
153
  const stack = Object.entries(props)
169
154
  .map(([k, v]) => {
@@ -49,6 +49,7 @@ import { Statistics } from './statistics.js';
49
49
  * @see https://docs.apify.com/api/v2
50
50
  */
51
51
  export declare class ApifyClient {
52
+ #private;
52
53
  baseUrl: string;
53
54
  /**
54
55
  * @since Added in 2.17.0
@@ -59,7 +60,6 @@ export declare class ApifyClient {
59
60
  logger: Log;
60
61
  httpClient: HttpClient;
61
62
  constructor(options?: ApifyClientOptions);
62
- private subClientOptions;
63
63
  /**
64
64
  * Returns a client for managing Actors in your account.
65
65
  *
@@ -103,7 +103,7 @@ export class ApifyClient {
103
103
  userAgentSuffix: parsed.userAgentSuffix,
104
104
  });
105
105
  }
106
- subClientOptions() {
106
+ #subClientOptions() {
107
107
  return {
108
108
  baseUrl: this.baseUrl,
109
109
  publicBaseUrl: this.publicBaseUrl,
@@ -120,7 +120,7 @@ export class ApifyClient {
120
120
  * @see https://docs.apify.com/api/v2/acts-get
121
121
  */
122
122
  actors() {
123
- return new ActorCollectionClient(this.subClientOptions());
123
+ return new ActorCollectionClient(this.#subClientOptions());
124
124
  }
125
125
  /**
126
126
  * Returns a client for a specific Actor.
@@ -142,7 +142,7 @@ export class ApifyClient {
142
142
  parseArgument(id, resourceIdSchema);
143
143
  return new ActorClient({
144
144
  id,
145
- ...this.subClientOptions(),
145
+ ...this.#subClientOptions(),
146
146
  });
147
147
  }
148
148
  /**
@@ -154,7 +154,7 @@ export class ApifyClient {
154
154
  * @see https://docs.apify.com/api/v2/actor-builds-get
155
155
  */
156
156
  builds() {
157
- return new BuildCollectionClient(this.subClientOptions());
157
+ return new BuildCollectionClient(this.#subClientOptions());
158
158
  }
159
159
  /**
160
160
  * Returns a client for a specific Actor build.
@@ -169,7 +169,7 @@ export class ApifyClient {
169
169
  parseArgument(id, resourceIdSchema);
170
170
  return new BuildClient({
171
171
  id,
172
- ...this.subClientOptions(),
172
+ ...this.#subClientOptions(),
173
173
  });
174
174
  }
175
175
  /**
@@ -181,7 +181,7 @@ export class ApifyClient {
181
181
  * @see https://docs.apify.com/api/v2/datasets-get
182
182
  */
183
183
  datasets() {
184
- return new DatasetCollectionClient(this.subClientOptions());
184
+ return new DatasetCollectionClient(this.#subClientOptions());
185
185
  }
186
186
  /**
187
187
  * Returns a client for a specific dataset.
@@ -210,7 +210,7 @@ export class ApifyClient {
210
210
  parseArgument(id, resourceIdSchema);
211
211
  return new DatasetClient({
212
212
  id,
213
- ...this.subClientOptions(),
213
+ ...this.#subClientOptions(),
214
214
  });
215
215
  }
216
216
  /**
@@ -222,7 +222,7 @@ export class ApifyClient {
222
222
  * @see https://docs.apify.com/api/v2/key-value-stores-get
223
223
  */
224
224
  keyValueStores() {
225
- return new KeyValueStoreCollectionClient(this.subClientOptions());
225
+ return new KeyValueStoreCollectionClient(this.#subClientOptions());
226
226
  }
227
227
  /**
228
228
  * Returns a client for a specific key-value store.
@@ -247,7 +247,7 @@ export class ApifyClient {
247
247
  parseArgument(id, resourceIdSchema);
248
248
  return new KeyValueStoreClient({
249
249
  id,
250
- ...this.subClientOptions(),
250
+ ...this.#subClientOptions(),
251
251
  });
252
252
  }
253
253
  /**
@@ -261,7 +261,7 @@ export class ApifyClient {
261
261
  parseArgument(buildOrRunId, resourceIdSchema);
262
262
  return new LogClient({
263
263
  id: buildOrRunId,
264
- ...this.subClientOptions(),
264
+ ...this.#subClientOptions(),
265
265
  });
266
266
  }
267
267
  /**
@@ -273,7 +273,7 @@ export class ApifyClient {
273
273
  * @see https://docs.apify.com/api/v2/request-queues-get
274
274
  */
275
275
  requestQueues() {
276
- return new RequestQueueCollectionClient(this.subClientOptions());
276
+ return new RequestQueueCollectionClient(this.#subClientOptions());
277
277
  }
278
278
  /**
279
279
  * Returns a client for a specific request queue.
@@ -301,7 +301,7 @@ export class ApifyClient {
301
301
  const parsed = parseArgument(options, requestQueueOptionsSchema, 'RequestQueueUserOptions');
302
302
  const apiClientOptions = {
303
303
  id,
304
- ...this.subClientOptions(),
304
+ ...this.#subClientOptions(),
305
305
  };
306
306
  return new RequestQueueClient(apiClientOptions, parsed);
307
307
  }
@@ -315,7 +315,7 @@ export class ApifyClient {
315
315
  */
316
316
  runs() {
317
317
  return new RunCollectionClient({
318
- ...this.subClientOptions(),
318
+ ...this.#subClientOptions(),
319
319
  resourcePath: 'actor-runs',
320
320
  });
321
321
  }
@@ -342,7 +342,7 @@ export class ApifyClient {
342
342
  parseArgument(id, resourceIdSchema);
343
343
  return new RunClient({
344
344
  id,
345
- ...this.subClientOptions(),
345
+ ...this.#subClientOptions(),
346
346
  });
347
347
  }
348
348
  /**
@@ -354,7 +354,7 @@ export class ApifyClient {
354
354
  * @see https://docs.apify.com/api/v2/actor-tasks-get
355
355
  */
356
356
  tasks() {
357
- return new TaskCollectionClient(this.subClientOptions());
357
+ return new TaskCollectionClient(this.#subClientOptions());
358
358
  }
359
359
  /**
360
360
  * Returns a client for a specific Actor task.
@@ -375,7 +375,7 @@ export class ApifyClient {
375
375
  parseArgument(id, resourceIdSchema);
376
376
  return new TaskClient({
377
377
  id,
378
- ...this.subClientOptions(),
378
+ ...this.#subClientOptions(),
379
379
  });
380
380
  }
381
381
  /**
@@ -387,7 +387,7 @@ export class ApifyClient {
387
387
  * @see https://docs.apify.com/api/v2/schedules-get
388
388
  */
389
389
  schedules() {
390
- return new ScheduleCollectionClient(this.subClientOptions());
390
+ return new ScheduleCollectionClient(this.#subClientOptions());
391
391
  }
392
392
  /**
393
393
  * Returns a client for a specific schedule.
@@ -402,7 +402,7 @@ export class ApifyClient {
402
402
  parseArgument(id, resourceIdSchema);
403
403
  return new ScheduleClient({
404
404
  id,
405
- ...this.subClientOptions(),
405
+ ...this.#subClientOptions(),
406
406
  });
407
407
  }
408
408
  /**
@@ -418,7 +418,7 @@ export class ApifyClient {
418
418
  parseArgument(id, resourceIdSchema);
419
419
  return new UserClient({
420
420
  id,
421
- ...this.subClientOptions(),
421
+ ...this.#subClientOptions(),
422
422
  });
423
423
  }
424
424
  /**
@@ -430,7 +430,7 @@ export class ApifyClient {
430
430
  * @see https://docs.apify.com/api/v2/webhooks-get
431
431
  */
432
432
  webhooks() {
433
- return new WebhookCollectionClient(this.subClientOptions());
433
+ return new WebhookCollectionClient(this.#subClientOptions());
434
434
  }
435
435
  /**
436
436
  * Returns a client for a specific webhook.
@@ -445,7 +445,7 @@ export class ApifyClient {
445
445
  parseArgument(id, resourceIdSchema);
446
446
  return new WebhookClient({
447
447
  id,
448
- ...this.subClientOptions(),
448
+ ...this.#subClientOptions(),
449
449
  });
450
450
  }
451
451
  /**
@@ -457,7 +457,7 @@ export class ApifyClient {
457
457
  * @see https://docs.apify.com/api/v2/webhook-dispatches-get
458
458
  */
459
459
  webhookDispatches() {
460
- return new WebhookDispatchCollectionClient(this.subClientOptions());
460
+ return new WebhookDispatchCollectionClient(this.#subClientOptions());
461
461
  }
462
462
  /**
463
463
  * Returns a client for a specific webhook dispatch.
@@ -470,7 +470,7 @@ export class ApifyClient {
470
470
  parseArgument(id, resourceIdSchema);
471
471
  return new WebhookDispatchClient({
472
472
  id,
473
- ...this.subClientOptions(),
473
+ ...this.#subClientOptions(),
474
474
  });
475
475
  }
476
476
  /**
@@ -482,7 +482,7 @@ export class ApifyClient {
482
482
  * @see https://docs.apify.com/api/v2/store-get
483
483
  */
484
484
  store() {
485
- return new StoreCollectionClient(this.subClientOptions());
485
+ return new StoreCollectionClient(this.#subClientOptions());
486
486
  }
487
487
  /**
488
488
  * Sets a status message for the current Actor run.