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

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 (46) hide show
  1. package/README.md +4 -2
  2. package/dist/apify_api_error.d.ts +2 -2
  3. package/dist/apify_client.d.ts +8 -8
  4. package/dist/apify_client.js +10 -10
  5. package/dist/axios.d.ts +2 -0
  6. package/dist/axios.js +1 -0
  7. package/dist/body_parser.d.ts +1 -1
  8. package/dist/bundle.js +31 -30
  9. package/dist/bundle.js.map +1 -1
  10. package/dist/generated/api.d.ts +124 -32
  11. package/dist/generated/schemas.d.ts +178 -58
  12. package/dist/generated/schemas.js +23 -6
  13. package/dist/http_clients/axios.d.ts +34 -15
  14. package/dist/http_clients/axios.js +79 -33
  15. package/dist/http_clients/base.d.ts +34 -23
  16. package/dist/http_clients/base.js +50 -20
  17. package/dist/http_clients/fetch.d.ts +53 -0
  18. package/dist/http_clients/fetch.js +219 -0
  19. package/dist/http_clients/index.d.ts +2 -2
  20. package/dist/http_clients/index.js +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/resource_clients/actor.d.ts +3 -2
  23. package/dist/resource_clients/actor.js +3 -3
  24. package/dist/resource_clients/actor_server.d.ts +11 -11
  25. package/dist/resource_clients/actor_server.js +0 -4
  26. package/dist/resource_clients/actor_version.d.ts +2 -1
  27. package/dist/resource_clients/actor_version.js +3 -2
  28. package/dist/resource_clients/actor_version_collection.d.ts +2 -1
  29. package/dist/resource_clients/actor_version_collection.js +3 -2
  30. package/dist/resource_clients/dataset.d.ts +14 -15
  31. package/dist/resource_clients/dataset.js +0 -4
  32. package/dist/resource_clients/key_value_store.d.ts +20 -19
  33. package/dist/resource_clients/key_value_store.js +10 -11
  34. package/dist/resource_clients/log.d.ts +10 -11
  35. package/dist/resource_clients/log.js +4 -3
  36. package/dist/resource_clients/run.d.ts +6 -2
  37. package/dist/resource_clients/run.js +6 -2
  38. package/dist/resource_clients/store_collection.d.ts +4 -0
  39. package/dist/resource_clients/task.js +3 -3
  40. package/dist/runtime/node.js +35 -11
  41. package/dist/runtime/types.d.ts +26 -4
  42. package/dist/runtime/web.js +39 -0
  43. package/dist/schemas.d.ts +4 -4
  44. package/dist/utils.d.ts +29 -1
  45. package/dist/utils.js +13 -0
  46. package/package.json +33 -21
package/README.md CHANGED
@@ -62,7 +62,9 @@ options of the `ApifyClient` constructor.
62
62
 
63
63
  ### Pluggable HTTP client
64
64
 
65
- The client ships with an axios-based HTTP client and accepts a custom one. Extend `HttpClient`, implement
65
+ The client sends its requests through the `fetch` of the runtime and accepts a custom HTTP client. The axios-based
66
+ client of version 2 is available from `apify-client/axios`, with `axios` installed next to the client. For a client
67
+ of your own, extend `HttpClient`, implement
66
68
  `sendRequest()` over the HTTP library of your choice and plug it in with `ApifyClient.withCustomHttpClient()`. The
67
69
  custom client inherits the retries, timeouts, compression and error handling of the built-in one.
68
70
 
@@ -163,7 +165,7 @@ The package includes a pre-built browser bundle that bundlers targeting browsers
163
165
  import { ApifyClient } from 'apify-client/browser';
164
166
  ```
165
167
 
166
- Only two parts of the client need Node.js built-ins: the HTTP agents and request compression. The `node` condition selects the Node.js implementation of those, and every other target gets one built on Web APIs. Log streaming, proxy support, and request compression are only available in Node.js.
168
+ Only two parts of the client need Node.js built-ins: Node.js streams and request compression. The `node` condition selects the Node.js implementation of those, and every other target gets one built on Web APIs. Log redirection and request compression are only available in Node.js.
167
169
 
168
170
  For details, see [Bundled environments](https://docs.apify.com/api/client/js/docs/concepts/bundled-environments).
169
171
 
@@ -1,7 +1,7 @@
1
- import type { LiteralUnion } from 'type-fest';
2
1
  import { ApifyClientError } from './apify_client_error.js';
3
2
  import type { ApifyResponse } from './http_clients/base.js';
4
3
  import type { ErrorType } from './models.js';
4
+ import type { AnyString } from './utils.js';
5
5
  export type { ErrorType } from './models.js';
6
6
  /**
7
7
  * An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
@@ -34,7 +34,7 @@ export declare class ApifyApiError extends ApifyClientError {
34
34
  * The type of the error, as returned by the API. Typed as the known {@link ErrorType}
35
35
  * values for autocompletion, while still accepting any string the API may return.
36
36
  */
37
- type?: LiteralUnion<ErrorType, string>;
37
+ type?: ErrorType | AnyString;
38
38
  /**
39
39
  * Number of the API call attempt.
40
40
  */
@@ -63,7 +63,7 @@ export declare class ApifyClient {
63
63
  stats: Statistics;
64
64
  logger: Log;
65
65
  /**
66
- * Creates a client that sends its requests through the built-in {@link AxiosHttpClient}, configured from
66
+ * Creates a client that sends its requests through the built-in {@link FetchHttpClient}, configured from
67
67
  * `options`: the API token, retries, the timeout tiers, request compression and default headers. The HTTP
68
68
  * client itself is created when {@link httpClient} is first read. To send the requests through a custom HTTP
69
69
  * client, use {@link ApifyClient.withCustomHttpClient} instead.
@@ -76,9 +76,10 @@ export declare class ApifyClient {
76
76
  * Creates an `ApifyClient` that sends its requests through a custom HTTP client.
77
77
  *
78
78
  * The custom client owns its transport configuration: retries, timeouts, default headers and whatever its
79
- * transport needs are set on the client itself. This is also how the built-in {@link AxiosHttpClient} is
80
- * configured beyond what the constructor options offer, for example with axios request interceptors. The
81
- * token is set as the client's `Authorization` header, unless the client already has one configured.
79
+ * transport needs are set on the client itself. This is also how the built-in {@link FetchHttpClient} is
80
+ * configured beyond what the constructor options offer, for example with a `fetch` function of your own, and
81
+ * how the axios-based client from `apify-client/axios` is brought back. The token is set as the client's
82
+ * `Authorization` header, unless the client already has one configured.
82
83
  *
83
84
  * @param options - The token, the API URLs and the HTTP client to use.
84
85
  * @returns A client whose {@link httpClient} is the given one.
@@ -99,13 +100,12 @@ export declare class ApifyClient {
99
100
  static withCustomHttpClient(options: ApifyClientCustomHttpClientOptions): ApifyClient;
100
101
  /**
101
102
  * The HTTP client the requests go through: the custom one when set through
102
- * {@link ApifyClient.withCustomHttpClient}, and otherwise an {@link AxiosHttpClient} configured from the
103
+ * {@link ApifyClient.withCustomHttpClient}, and otherwise a {@link FetchHttpClient} configured from the
103
104
  * constructor options, created on first access. Assigning a client applies {@link token} to it through
104
105
  * {@link HttpClient.setDefaultAuthorization} and points {@link stats} at its statistics, so the counters keep
105
106
  * tracking the calls the client actually makes. Resource clients hold on to the HTTP client they were created
106
- * with, so assign before reaching for them. Assigning does not close the client it replaces. A default client
107
- * that already sent a request keeps its keep-alive agents open until {@link HttpClient.close} is called on it,
108
- * so close it yourself, or assign before the first request.
107
+ * with, so assign before reaching for them. Assigning does not close the client it replaces, so call
108
+ * {@link HttpClient.close} on one that owns connections yourself.
109
109
  */
110
110
  get httpClient(): HttpClient;
111
111
  set httpClient(httpClient: HttpClient);
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { ACTOR_ENV_VARS, ME_USER_NAME_PLACEHOLDER } from '@apify/consts';
3
3
  import logger from '@apify/log';
4
- import { AxiosHttpClient } from './http_clients/axios.js';
4
+ import { FetchHttpClient } from './http_clients/fetch.js';
5
5
  import { DEFAULT_MAX_RETRIES, DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS, HttpClient, httpClientOptionsShape, } from './http_clients/base.js';
6
6
  import { compressionSchema } from './http_compressors/resolve.js';
7
7
  import { ActorClient } from './resource_clients/actor.js';
@@ -101,7 +101,7 @@ export class ApifyClient {
101
101
  /** Configuration of the default HTTP client, applied when no custom one is set. */
102
102
  #httpClientOptions;
103
103
  /**
104
- * Creates a client that sends its requests through the built-in {@link AxiosHttpClient}, configured from
104
+ * Creates a client that sends its requests through the built-in {@link FetchHttpClient}, configured from
105
105
  * `options`: the API token, retries, the timeout tiers, request compression and default headers. The HTTP
106
106
  * client itself is created when {@link httpClient} is first read. To send the requests through a custom HTTP
107
107
  * client, use {@link ApifyClient.withCustomHttpClient} instead.
@@ -136,9 +136,10 @@ export class ApifyClient {
136
136
  * Creates an `ApifyClient` that sends its requests through a custom HTTP client.
137
137
  *
138
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.
139
+ * transport needs are set on the client itself. This is also how the built-in {@link FetchHttpClient} is
140
+ * configured beyond what the constructor options offer, for example with a `fetch` function of your own, and
141
+ * how the axios-based client from `apify-client/axios` is brought back. The token is set as the client's
142
+ * `Authorization` header, unless the client already has one configured.
142
143
  *
143
144
  * @param options - The token, the API URLs and the HTTP client to use.
144
145
  * @returns A client whose {@link httpClient} is the given one.
@@ -164,16 +165,15 @@ export class ApifyClient {
164
165
  }
165
166
  /**
166
167
  * 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
+ * {@link ApifyClient.withCustomHttpClient}, and otherwise a {@link FetchHttpClient} configured from the
168
169
  * constructor options, created on first access. Assigning a client applies {@link token} to it through
169
170
  * {@link HttpClient.setDefaultAuthorization} and points {@link stats} at its statistics, so the counters keep
170
171
  * 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.
172
+ * with, so assign before reaching for them. Assigning does not close the client it replaces, so call
173
+ * {@link HttpClient.close} on one that owns connections yourself.
174
174
  */
175
175
  get httpClient() {
176
- this.#httpClient ??= new AxiosHttpClient(this.#httpClientOptions);
176
+ this.#httpClient ??= new FetchHttpClient(this.#httpClientOptions);
177
177
  return this.#httpClient;
178
178
  }
179
179
  set httpClient(httpClient) {
@@ -0,0 +1,2 @@
1
+ export type { AxiosHttpClientOptions, RequestInterceptorFunction } from './http_clients/axios.js';
2
+ export { AxiosHttpClient } from './http_clients/axios.js';
package/dist/axios.js ADDED
@@ -0,0 +1 @@
1
+ export { AxiosHttpClient } from './http_clients/axios.js';
@@ -1,4 +1,4 @@
1
- import type { JsonArray, JsonObject } from 'type-fest';
1
+ import type { JsonArray, JsonObject } from './utils.js';
2
2
  /**
3
3
  * Parses a binary response body using the provided content type header.
4
4
  *