apify-client 3.0.0-beta.51 → 3.0.0-beta.53

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 (49) hide show
  1. package/dist/apify_api_error.d.ts +4 -4
  2. package/dist/apify_api_error.js +1 -1
  3. package/dist/base/resource_client.js +13 -7
  4. package/dist/bundle.js +2 -2
  5. package/dist/bundle.js.map +1 -1
  6. package/dist/generated/api.d.ts +173 -177
  7. package/dist/generated/schemas.d.ts +51 -101
  8. package/dist/generated/schemas.js +91 -94
  9. package/dist/http_clients/base.d.ts +2 -4
  10. package/dist/models.d.ts +157 -180
  11. package/dist/models.js +6 -4
  12. package/dist/resource_clients/actor.d.ts +7 -7
  13. package/dist/resource_clients/actor.js +2 -2
  14. package/dist/resource_clients/actor_collection.d.ts +10 -10
  15. package/dist/resource_clients/actor_collection.js +1 -1
  16. package/dist/resource_clients/actor_env_var.d.ts +3 -3
  17. package/dist/resource_clients/actor_env_var_collection.d.ts +4 -4
  18. package/dist/resource_clients/actor_version.d.ts +5 -5
  19. package/dist/resource_clients/actor_version_collection.d.ts +4 -4
  20. package/dist/resource_clients/build.d.ts +2 -1
  21. package/dist/resource_clients/build.js +1 -0
  22. package/dist/resource_clients/build_collection.d.ts +4 -4
  23. package/dist/resource_clients/dataset.d.ts +4 -4
  24. package/dist/resource_clients/dataset.js +2 -2
  25. package/dist/resource_clients/dataset_collection.d.ts +4 -4
  26. package/dist/resource_clients/dataset_collection.js +1 -1
  27. package/dist/resource_clients/key_value_store.d.ts +6 -6
  28. package/dist/resource_clients/key_value_store.js +2 -2
  29. package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
  30. package/dist/resource_clients/key_value_store_collection.js +1 -1
  31. package/dist/resource_clients/request_queue.d.ts +18 -18
  32. package/dist/resource_clients/request_queue.js +3 -3
  33. package/dist/resource_clients/request_queue_collection.d.ts +4 -4
  34. package/dist/resource_clients/request_queue_collection.js +1 -1
  35. package/dist/resource_clients/run.d.ts +16 -15
  36. package/dist/resource_clients/run.js +8 -7
  37. package/dist/resource_clients/run_collection.d.ts +2 -2
  38. package/dist/resource_clients/schedule.d.ts +3 -3
  39. package/dist/resource_clients/schedule.js +1 -1
  40. package/dist/resource_clients/store_collection.d.ts +3 -3
  41. package/dist/resource_clients/task.d.ts +3 -3
  42. package/dist/resource_clients/task_collection.d.ts +3 -3
  43. package/dist/resource_clients/user.d.ts +4 -4
  44. package/dist/resource_clients/webhook.d.ts +5 -5
  45. package/dist/resource_clients/webhook.js +2 -2
  46. package/dist/resource_clients/webhook_collection.d.ts +3 -3
  47. package/dist/resource_clients/webhook_collection.js +1 -1
  48. package/dist/utils.d.ts +3 -3
  49. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import type { LiteralUnion } from 'type-fest';
2
2
  import type { ApifyResponse } from './http_clients/base.js';
3
- import type { ApifyApiErrorType } from './models.js';
4
- export type { ApifyApiErrorType } from './models.js';
3
+ import type { ErrorType } from './models.js';
4
+ export type { ErrorType } from './models.js';
5
5
  /**
6
6
  * An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
7
7
  * but the API responds with an error response. Typically, those are rate limit
@@ -30,10 +30,10 @@ export declare class ApifyApiError extends Error {
30
30
  */
31
31
  statusCode: number;
32
32
  /**
33
- * The type of the error, as returned by the API. Typed as the known {@link ApifyApiErrorType}
33
+ * The type of the error, as returned by the API. Typed as the known {@link ErrorType}
34
34
  * values for autocompletion, while still accepting any string the API may return.
35
35
  */
36
- type?: LiteralUnion<ApifyApiErrorType, string>;
36
+ type?: LiteralUnion<ErrorType, string>;
37
37
  /**
38
38
  * Number of the API call attempt.
39
39
  */
@@ -43,7 +43,7 @@ export class ApifyApiError extends Error {
43
43
  */
44
44
  statusCode;
45
45
  /**
46
- * The type of the error, as returned by the API. Typed as the known {@link ApifyApiErrorType}
46
+ * The type of the error, as returned by the API. Typed as the known {@link ErrorType}
47
47
  * values for autocompletion, while still accepting any string the API may return.
48
48
  */
49
49
  type;
@@ -9,6 +9,8 @@ import { ApiClient } from './api_client.js';
9
9
  const MAX_WAIT_FOR_FINISH = 999999;
10
10
  /** The API holds a `waitForFinish` response for at most a minute, however long the parameter asks for. */
11
11
  const MAX_WAIT_FOR_FINISH_HOLD_SECS = 60;
12
+ /** How long `waitForFinish()` keeps polling a job that returns 404, to ride out replica lag, before it gives up. */
13
+ const MAX_WAIT_WHEN_JOB_NOT_EXIST_MILLIS = 3000;
12
14
  /**
13
15
  * Resource client.
14
16
  * @private
@@ -88,10 +90,14 @@ export class ResourceClient extends ApiClient {
88
90
  const { waitSecs = MAX_WAIT_FOR_FINISH, timeoutSecs = 'noTimeout', signal } = options;
89
91
  const waitMillis = waitSecs * 1000;
90
92
  let job;
93
+ let notFoundSince;
94
+ let notFoundError;
91
95
  const startedAt = Date.now();
92
96
  const shouldRepeat = () => {
93
- const millisSinceStart = Date.now() - startedAt;
94
- if (millisSinceStart >= waitMillis)
97
+ const now = Date.now();
98
+ if (now - startedAt >= waitMillis)
99
+ return false;
100
+ if (notFoundSince !== undefined && now - notFoundSince >= MAX_WAIT_WHEN_JOB_NOT_EXIST_MILLIS)
95
101
  return false;
96
102
  const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
97
103
  return !hasJobEnded;
@@ -110,10 +116,13 @@ export class ResourceClient extends ApiClient {
110
116
  try {
111
117
  const response = await this.httpClient.call(requestOpts);
112
118
  job = parseResponse(response, schema);
119
+ notFoundSince = undefined;
113
120
  }
114
121
  catch (err) {
115
122
  catchNotFoundOrThrow(err);
116
123
  job = undefined;
124
+ notFoundSince ??= Date.now();
125
+ notFoundError = err;
117
126
  }
118
127
  // It might take some time for database replicas to get up-to-date,
119
128
  // so getRun() might return null. Wait a little bit and try it again.
@@ -122,11 +131,8 @@ export class ResourceClient extends ApiClient {
122
131
  signal?.throwIfAborted();
123
132
  }
124
133
  } while (shouldRepeat());
125
- if (!job) {
126
- const constructorName = this.constructor.name;
127
- const jobName = constructorName.match(/(\w+)Client/)[1].toLowerCase();
128
- throw new Error(`Waiting for ${jobName} to finish failed. Cannot fetch actor ${jobName} details from the server.`);
129
- }
134
+ if (!job)
135
+ throw notFoundError;
130
136
  return job;
131
137
  }
132
138
  }