apify-client 3.0.0-rc.0 → 3.0.0-rc.1

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 (52) hide show
  1. package/README.md +6 -0
  2. package/dist/apify_api_error.d.ts +2 -1
  3. package/dist/apify_api_error.js +2 -1
  4. package/dist/apify_client_error.d.ts +10 -0
  5. package/dist/apify_client_error.js +10 -0
  6. package/dist/base/api_client.js +8 -20
  7. package/dist/base/resource_client.js +8 -8
  8. package/dist/bundle.js +13 -13
  9. package/dist/bundle.js.map +1 -1
  10. package/dist/generated/api.d.ts +2300 -690
  11. package/dist/generated/schemas.d.ts +1720 -246
  12. package/dist/generated/schemas.js +416 -75
  13. package/dist/http_clients/axios.d.ts +2 -1
  14. package/dist/http_clients/axios.js +6 -4
  15. package/dist/http_clients/base.d.ts +80 -20
  16. package/dist/http_clients/base.js +127 -40
  17. package/dist/http_compressors/index.d.ts +2 -0
  18. package/dist/http_compressors/index.js +1 -0
  19. package/dist/http_compressors/resolve.d.ts +4 -3
  20. package/dist/http_compressors/resolve.js +4 -1
  21. package/dist/http_compressors/zstd.d.ts +34 -0
  22. package/dist/http_compressors/zstd.js +43 -0
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +2 -0
  25. package/dist/invalid_response_body_error.d.ts +5 -4
  26. package/dist/invalid_response_body_error.js +5 -4
  27. package/dist/models.d.ts +30 -61
  28. package/dist/resource_clients/actor.d.ts +30 -0
  29. package/dist/resource_clients/actor.js +43 -0
  30. package/dist/resource_clients/actor_server.d.ts +149 -0
  31. package/dist/resource_clients/actor_server.js +199 -0
  32. package/dist/resource_clients/actor_version.d.ts +5 -0
  33. package/dist/resource_clients/dataset.d.ts +33 -4
  34. package/dist/resource_clients/dataset.js +16 -54
  35. package/dist/resource_clients/key_value_store.d.ts +51 -11
  36. package/dist/resource_clients/key_value_store.js +59 -15
  37. package/dist/resource_clients/log.d.ts +29 -3
  38. package/dist/resource_clients/log.js +7 -11
  39. package/dist/resource_clients/request_queue.d.ts +9 -0
  40. package/dist/resource_clients/request_queue.js +9 -6
  41. package/dist/resource_clients/run.d.ts +9 -0
  42. package/dist/resource_clients/run.js +6 -3
  43. package/dist/response_validation_error.d.ts +2 -1
  44. package/dist/response_validation_error.js +2 -1
  45. package/dist/runtime/node.js +44 -6
  46. package/dist/runtime/types.d.ts +9 -1
  47. package/dist/runtime/web.js +4 -1
  48. package/dist/schemas.d.ts +369 -3
  49. package/dist/schemas.js +25 -3
  50. package/dist/utils.d.ts +23 -26
  51. package/dist/utils.js +32 -25
  52. package/package.json +23 -23
package/README.md CHANGED
@@ -15,6 +15,7 @@ automatic retries and convenience functions that improve the experience of using
15
15
  - [Features](#features)
16
16
  - [Automatic parsing and error handling](#automatic-parsing-and-error-handling)
17
17
  - [Retries with exponential backoff](#retries-with-exponential-backoff)
18
+ - [Server Actors](#server-actors)
18
19
  - [Convenience functions and options](#convenience-functions-and-options)
19
20
  - [Usage concepts](#usage-concepts)
20
21
  - [Nested clients](#nested-clients)
@@ -65,6 +66,11 @@ The client ships with an axios-based HTTP client and accepts a custom one. Exten
65
66
  `sendRequest()` over the HTTP library of your choice and plug it in with `ApifyClient.withCustomHttpClient()`. The
66
67
  custom client inherits the retries, timeouts, compression and error handling of the built-in one.
67
68
 
69
+ ### Server Actors
70
+
71
+ `client.actor(id).server()` returns a client for a Server Actor (formerly Actor Standby). It sends HTTP requests to
72
+ the Actor's web server with your token, and returns the server's URL and OpenAPI specification.
73
+
68
74
  ### Convenience functions and options
69
75
 
70
76
  Some actions can't be performed by the API itself, such as indefinite waiting for an actor run to finish
@@ -1,4 +1,5 @@
1
1
  import type { LiteralUnion } from 'type-fest';
2
+ import { ApifyClientError } from './apify_client_error.js';
2
3
  import type { ApifyResponse } from './http_clients/base.js';
3
4
  import type { ErrorType } from './models.js';
4
5
  export type { ErrorType } from './models.js';
@@ -16,7 +17,7 @@ export type { ErrorType } from './models.js';
16
17
  * subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
17
18
  * share a status code are told apart by their `type`.
18
19
  */
19
- export declare class ApifyApiError extends Error {
20
+ export declare class ApifyApiError extends ApifyClientError {
20
21
  #private;
21
22
  name: string;
22
23
  /**
@@ -1,3 +1,4 @@
1
+ import { ApifyClientError } from './apify_client_error.js';
1
2
  import { isBuffer } from './utils.js';
2
3
  /**
3
4
  * Examples of capturing groups for "...at ActorCollectionClient.listResources (/Users/..."
@@ -30,7 +31,7 @@ const CLIENT_METHOD_REGEX = /at( async)? (?![A-Za-z]*HttpClient\.)([A-Za-z]+(Col
30
31
  * subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
31
32
  * share a status code are told apart by their `type`.
32
33
  */
33
- export class ApifyApiError extends Error {
34
+ export class ApifyApiError extends ApifyClientError {
34
35
  name;
35
36
  /**
36
37
  * The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
@@ -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,4 +1,4 @@
1
- import { SCANNED_COUNT, toPath, toPathSegment } from '../utils.js';
1
+ import { minForLimitParam, toPath, toPathSegment } from '../utils.js';
2
2
  /** @private */
3
3
  export class ApiClient {
4
4
  id;
@@ -54,32 +54,20 @@ export class ApiClient {
54
54
  * Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
55
55
  */
56
56
  listPaginatedFromCallback(getPaginatedList, options = {}) {
57
- const minForLimitParam = (a, b) => {
58
- // API treats 0 as undefined for limit parameter
59
- if (a === 0)
60
- a = undefined;
61
- if (b === 0)
62
- b = undefined;
63
- if (a === undefined)
64
- return b;
65
- if (b === undefined)
66
- return a;
67
- return Math.min(a, b);
68
- };
69
57
  // `chunkSize` only sizes this loop's requests; it is not an API parameter, so it must not reach
70
58
  // `buildParams()` and the query string. The same goes for `timeoutSecs` and `signal`, which callers take out
71
59
  // before calling this, since they also apply to every page request.
72
60
  const { chunkSize, ...listOptions } = options;
73
61
  const firstPageLimit = minForLimitParam(options.limit, chunkSize);
74
62
  const paginatedListPromise = getPaginatedList({ ...listOptions, limit: firstPageLimit });
75
- // A page can return more or fewer items than the rows it scanned (see `SCANNED_COUNT`). The next offset and
76
- // the stop condition follow the scanned rows: advancing by `items.length` would re-scan rows after a filter
77
- // dropped some and skip rows after `unwind` multiplied them, and stopping at an empty page would end the
78
- // iteration in front of rows a filter hid. The scanned number is derived from a dataset's item count, which
79
- // lags a fresh push, so the larger of it and `items.length` is taken, capped at the rows the request asked for
80
- // so that an unwound page does not advance past rows the next request would then never read.
63
+ // A page of dataset items can return more or fewer items than the rows it scanned (see `PaginatedList.count`).
64
+ // The next offset and the stop condition follow the scanned rows: advancing by `items.length` would re-scan
65
+ // rows after a filter dropped some and skip rows after `unwind` multiplied them, and stopping at an empty page
66
+ // would end the iteration in front of rows a filter hid. The step is the larger of `count` and `items.length`,
67
+ // capped at the rows the request asked for, which keeps an unwound page from advancing past rows the next
68
+ // request would then never read.
81
69
  const scannedRows = (page, requestedLimit) => {
82
- const scanned = Math.max(page[SCANNED_COUNT] ?? 0, page.items.length);
70
+ const scanned = Math.max(page.count ?? 0, page.items.length);
83
71
  return requestedLimit ? Math.min(scanned, requestedLimit) : scanned;
84
72
  };
85
73
  // `total` is not consulted, as it changes when the listed resource grows during the iteration.
@@ -102,7 +102,7 @@ export class ResourceClient extends ApiClient {
102
102
  const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
103
103
  return !hasJobEnded;
104
104
  };
105
- do {
105
+ while (true) {
106
106
  const millisSinceStart = Date.now() - startedAt;
107
107
  const remainingWaitSeconds = Math.round((waitMillis - millisSinceStart) / 1000);
108
108
  const waitForFinish = Math.max(0, remainingWaitSeconds);
@@ -124,13 +124,13 @@ export class ResourceClient extends ApiClient {
124
124
  notFoundSince ??= Date.now();
125
125
  notFoundError = err;
126
126
  }
127
- // It might take some time for database replicas to get up-to-date,
128
- // so getRun() might return null. Wait a little bit and try it again.
129
- if (!job) {
130
- await sleep(250, signal);
131
- signal?.throwIfAborted();
132
- }
133
- } while (shouldRepeat());
127
+ if (!shouldRepeat())
128
+ break;
129
+ // The API answers right away when the remaining wait rounds to 0 seconds, and database replicas may not see
130
+ // a new job for a short while, so pause before the next poll.
131
+ await sleep(250, signal);
132
+ signal?.throwIfAborted();
133
+ }
134
134
  if (!job)
135
135
  throw notFoundError;
136
136
  return job;