apify-client 3.0.0-beta.8 → 3.0.0-rc.0
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.
- package/README.md +10 -2
- package/dist/apify_api_error.d.ts +11 -26
- package/dist/apify_api_error.js +31 -22
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -24
- package/dist/base/resource_client.d.ts +21 -8
- package/dist/base/resource_client.js +67 -33
- package/dist/base/resource_collection_client.d.ts +12 -4
- package/dist/base/resource_collection_client.js +34 -11
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +27 -22
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +785 -290
- package/dist/generated/schemas.d.ts +720 -747
- package/dist/generated/schemas.js +166 -162
- package/dist/http_clients/axios.d.ts +60 -0
- package/dist/http_clients/axios.js +117 -0
- package/dist/http_clients/base.d.ts +331 -0
- package/dist/http_clients/base.js +563 -0
- package/dist/http_clients/index.d.ts +4 -0
- package/dist/http_clients/index.js +2 -0
- package/dist/http_compressors/base.d.ts +40 -0
- package/dist/http_compressors/base.js +9 -0
- package/dist/http_compressors/brotli.d.ts +33 -0
- package/dist/http_compressors/brotli.js +39 -0
- package/dist/http_compressors/gzip.d.ts +33 -0
- package/dist/http_compressors/gzip.js +39 -0
- package/dist/http_compressors/index.d.ts +6 -0
- package/dist/http_compressors/index.js +2 -0
- package/dist/http_compressors/resolve.d.ts +23 -0
- package/dist/http_compressors/resolve.js +27 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/invalid_response_body_error.d.ts +13 -0
- package/dist/invalid_response_body_error.js +17 -0
- package/dist/models.d.ts +162 -194
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +74 -34
- package/dist/resource_clients/actor.js +87 -56
- package/dist/resource_clients/actor_collection.d.ts +18 -12
- package/dist/resource_clients/actor_collection.js +11 -3
- package/dist/resource_clients/actor_env_var.d.ts +11 -4
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_version.d.ts +20 -5
- package/dist/resource_clients/actor_version.js +19 -9
- package/dist/resource_clients/actor_version_collection.d.ts +11 -4
- package/dist/resource_clients/actor_version_collection.js +13 -4
- package/dist/resource_clients/build.d.ts +20 -7
- package/dist/resource_clients/build.js +35 -15
- package/dist/resource_clients/build_collection.d.ts +7 -5
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +53 -35
- package/dist/resource_clients/dataset.js +105 -80
- package/dist/resource_clients/dataset_collection.d.ts +10 -6
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +62 -20
- package/dist/resource_clients/key_value_store.js +78 -40
- package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +13 -20
- package/dist/resource_clients/log.js +141 -59
- package/dist/resource_clients/request_queue.d.ts +68 -31
- package/dist/resource_clients/request_queue.js +173 -91
- package/dist/resource_clients/request_queue_collection.d.ts +9 -5
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +119 -28
- package/dist/resource_clients/run.js +190 -49
- package/dist/resource_clients/run_collection.d.ts +5 -3
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +30 -22
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +6 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +36 -13
- package/dist/resource_clients/task.js +79 -46
- package/dist/resource_clients/task_collection.d.ts +9 -5
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +19 -10
- package/dist/resource_clients/user.js +42 -38
- package/dist/resource_clients/webhook.d.ts +17 -8
- package/dist/resource_clients/webhook.js +30 -22
- package/dist/resource_clients/webhook_collection.d.ts +8 -4
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +49 -0
- package/dist/runtime/types.d.ts +52 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +18 -0
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +1 -1
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/utils.d.ts +82 -45
- package/dist/utils.js +197 -146
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +32 -29
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -255
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -105
package/README.md
CHANGED
|
@@ -59,6 +59,12 @@ By default, it will retry up to 8 times. First retry will be attempted after ~50
|
|
|
59
59
|
and so on. You can configure those parameters using the `maxRetries` and `minDelayBetweenRetriesMillis`
|
|
60
60
|
options of the `ApifyClient` constructor.
|
|
61
61
|
|
|
62
|
+
### Pluggable HTTP client
|
|
63
|
+
|
|
64
|
+
The client ships with an axios-based HTTP client and accepts a custom one. Extend `HttpClient`, implement
|
|
65
|
+
`sendRequest()` over the HTTP library of your choice and plug it in with `ApifyClient.withCustomHttpClient()`. The
|
|
66
|
+
custom client inherits the retries, timeouts, compression and error handling of the built-in one.
|
|
67
|
+
|
|
62
68
|
### Convenience functions and options
|
|
63
69
|
|
|
64
70
|
Some actions can't be performed by the API itself, such as indefinite waiting for an actor run to finish
|
|
@@ -145,13 +151,15 @@ property to get only a subset of results. Other props are also available, depend
|
|
|
145
151
|
|
|
146
152
|
## Bundled environments
|
|
147
153
|
|
|
148
|
-
The package includes a pre-built browser bundle that
|
|
154
|
+
The package includes a pre-built browser bundle that bundlers targeting browsers resolve automatically. You can also import it explicitly:
|
|
149
155
|
|
|
150
156
|
```typescript
|
|
151
157
|
import { ApifyClient } from 'apify-client/browser';
|
|
152
158
|
```
|
|
153
159
|
|
|
154
|
-
|
|
160
|
+
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.
|
|
161
|
+
|
|
162
|
+
For details, see [Bundled environments](https://docs.apify.com/api/client/js/docs/concepts/bundled-environments).
|
|
155
163
|
|
|
156
164
|
## API Reference
|
|
157
165
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AxiosResponse } from 'axios';
|
|
2
1
|
import type { LiteralUnion } from 'type-fest';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
2
|
+
import type { ApifyResponse } from './http_clients/base.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
|
|
@@ -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
|
|
23
|
-
*
|
|
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
|
/**
|
|
@@ -28,10 +30,10 @@ export declare class ApifyApiError extends Error {
|
|
|
28
30
|
*/
|
|
29
31
|
statusCode: number;
|
|
30
32
|
/**
|
|
31
|
-
* The type of the error, as returned by the API. Typed as the known {@link
|
|
33
|
+
* The type of the error, as returned by the API. Typed as the known {@link ErrorType}
|
|
32
34
|
* values for autocompletion, while still accepting any string the API may return.
|
|
33
35
|
*/
|
|
34
|
-
type?: LiteralUnion<
|
|
36
|
+
type?: LiteralUnion<ErrorType, string>;
|
|
35
37
|
/**
|
|
36
38
|
* Number of the API call attempt.
|
|
37
39
|
*/
|
|
@@ -56,29 +58,12 @@ export declare class ApifyApiError extends Error {
|
|
|
56
58
|
/**
|
|
57
59
|
* @hidden
|
|
58
60
|
*/
|
|
59
|
-
constructor(response:
|
|
61
|
+
constructor(response: ApifyResponse, attempt: number);
|
|
60
62
|
/**
|
|
61
63
|
* Creates the error for a failed response as an instance of the subclass matching its HTTP status code.
|
|
62
64
|
* @hidden
|
|
63
65
|
*/
|
|
64
|
-
static fromResponse(response:
|
|
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;
|
|
66
|
+
static fromResponse(response: ApifyResponse, attempt: number): ApifyApiError;
|
|
82
67
|
}
|
|
83
68
|
/**
|
|
84
69
|
* Thrown when the Apify API responds with HTTP 400 Bad Request, typically because the request
|
package/dist/apify_api_error.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { isomorphicBufferToString } from './body_parser.js';
|
|
2
1
|
import { isBuffer } from './utils.js';
|
|
3
2
|
/**
|
|
4
|
-
* Examples of capturing groups for "...at ActorCollectionClient.
|
|
5
|
-
* 0: "at ActorCollectionClient.
|
|
3
|
+
* Examples of capturing groups for "...at ActorCollectionClient.listResources (/Users/..."
|
|
4
|
+
* 0: "at ActorCollectionClient.listResources ("
|
|
6
5
|
* 1: undefined
|
|
7
6
|
* 2: "ActorCollectionClient"
|
|
8
7
|
* 3: undefined
|
|
9
|
-
* 4: "
|
|
8
|
+
* 4: "listResources"
|
|
9
|
+
*
|
|
10
|
+
* The error is created inside the HTTP client's pipeline, whose frames sit above the resource client's. The
|
|
11
|
+
* pipeline's own methods are private, so V8 prints them with a `#` that no method name can match. Its public
|
|
12
|
+
* `call()` prints under the name of the transport's class, which can be anything, so the lookaheads skip a class
|
|
13
|
+
* named after `HttpClient` and the method `call`. A transport named `SomethingClient` whose `call()` override
|
|
14
|
+
* awaits a helper of its own is reported under that helper. `ActorClient.call()` and `TaskClient.call()` reach the
|
|
15
|
+
* pipeline through `start()`, whose frame sits closer to the error and matches first.
|
|
10
16
|
* @private
|
|
11
17
|
*/
|
|
12
|
-
const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\.
|
|
18
|
+
const CLIENT_METHOD_REGEX = /at( async)? (?![A-Za-z]*HttpClient\.)([A-Za-z]+(Collection)?Client)\.(?!call \()([A-Za-z]+) \(/;
|
|
13
19
|
/**
|
|
14
20
|
* An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
|
|
15
21
|
* but the API responds with an error response. Typically, those are rate limit
|
|
@@ -27,8 +33,9 @@ const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\._?([A-Z
|
|
|
27
33
|
export class ApifyApiError extends Error {
|
|
28
34
|
name;
|
|
29
35
|
/**
|
|
30
|
-
* The
|
|
31
|
-
*
|
|
36
|
+
* The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
|
|
37
|
+
* method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
|
|
38
|
+
* when the stack trace cannot be parsed.
|
|
32
39
|
*/
|
|
33
40
|
clientMethod;
|
|
34
41
|
/**
|
|
@@ -36,7 +43,7 @@ export class ApifyApiError extends Error {
|
|
|
36
43
|
*/
|
|
37
44
|
statusCode;
|
|
38
45
|
/**
|
|
39
|
-
* The type of the error, as returned by the API. Typed as the known {@link
|
|
46
|
+
* The type of the error, as returned by the API. Typed as the known {@link ErrorType}
|
|
40
47
|
* values for autocompletion, while still accepting any string the API may return.
|
|
41
48
|
*/
|
|
42
49
|
type;
|
|
@@ -69,14 +76,16 @@ export class ApifyApiError extends Error {
|
|
|
69
76
|
let type;
|
|
70
77
|
let responseData = response.data;
|
|
71
78
|
let errorData;
|
|
72
|
-
//
|
|
73
|
-
//
|
|
79
|
+
// A `responseType: 'buffer'` request (e.g. `downloadItems()`) and a failed streaming request, whose body
|
|
80
|
+
// `HttpClient` has read into a buffer, both arrive unparsed. Parse the body here to get at the error.
|
|
74
81
|
if (isBuffer(responseData)) {
|
|
82
|
+
const body = new TextDecoder().decode(response.data);
|
|
75
83
|
try {
|
|
76
|
-
responseData = JSON.parse(
|
|
84
|
+
responseData = JSON.parse(body);
|
|
77
85
|
}
|
|
78
86
|
catch {
|
|
79
|
-
//
|
|
87
|
+
// A body that is not JSON at all, such as an HTML error page from a proxy, is kept as text.
|
|
88
|
+
responseData = body;
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
if (responseData && responseData.error) {
|
|
@@ -97,15 +106,15 @@ export class ApifyApiError extends Error {
|
|
|
97
106
|
}
|
|
98
107
|
super(message);
|
|
99
108
|
this.name = this.constructor.name;
|
|
100
|
-
this.clientMethod = this
|
|
109
|
+
this.clientMethod = this.#extractClientAndMethodFromStack();
|
|
101
110
|
this.statusCode = response.status;
|
|
102
111
|
this.type = type;
|
|
103
112
|
this.attempt = attempt;
|
|
104
113
|
this.httpMethod = response.config?.method;
|
|
105
|
-
this.path = this
|
|
114
|
+
this.path = this.#safelyParsePathFromResponse(response);
|
|
106
115
|
const stack = this.stack;
|
|
107
116
|
this.originalStack = stack.slice(stack.indexOf('\n'));
|
|
108
|
-
this.stack = this
|
|
117
|
+
this.stack = this.#createApiStack();
|
|
109
118
|
this.data = errorData;
|
|
110
119
|
}
|
|
111
120
|
/**
|
|
@@ -116,7 +125,7 @@ export class ApifyApiError extends Error {
|
|
|
116
125
|
const ErrorClass = ERROR_CLASS_BY_STATUS[response.status] ?? (response.status >= 500 ? ServerError : ApifyApiError);
|
|
117
126
|
return new ErrorClass(response, attempt);
|
|
118
127
|
}
|
|
119
|
-
|
|
128
|
+
#safelyParsePathFromResponse(response) {
|
|
120
129
|
const urlString = response.config?.url;
|
|
121
130
|
let url;
|
|
122
131
|
try {
|
|
@@ -127,11 +136,11 @@ export class ApifyApiError extends Error {
|
|
|
127
136
|
}
|
|
128
137
|
return url.pathname + url.search;
|
|
129
138
|
}
|
|
130
|
-
|
|
139
|
+
#extractClientAndMethodFromStack() {
|
|
131
140
|
const match = this.stack.match(CLIENT_METHOD_REGEX);
|
|
132
|
-
if (match)
|
|
133
|
-
return
|
|
134
|
-
return
|
|
141
|
+
if (!match)
|
|
142
|
+
return 'unknown';
|
|
143
|
+
return `${match[2]}.${match[4]}`;
|
|
135
144
|
}
|
|
136
145
|
/**
|
|
137
146
|
* Creates a better looking and more informative stack that will be printed
|
|
@@ -144,10 +153,10 @@ export class ApifyApiError extends Error {
|
|
|
144
153
|
* statusCode: 404
|
|
145
154
|
* type: record-not-found
|
|
146
155
|
* attempt: 1
|
|
147
|
-
* httpMethod:
|
|
156
|
+
* httpMethod: POST
|
|
148
157
|
* path: /v2/actor-tasks/user~my-task/runs
|
|
149
158
|
*/
|
|
150
|
-
|
|
159
|
+
#createApiStack() {
|
|
151
160
|
const { name, ...props } = this;
|
|
152
161
|
const stack = Object.entries(props)
|
|
153
162
|
.map(([k, v]) => {
|
package/dist/apify_client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SetStatusMessageOptions } from '@crawlee/types';
|
|
2
1
|
import type { Log } from '@apify/log';
|
|
3
|
-
import { HttpClient } from './
|
|
4
|
-
import type {
|
|
2
|
+
import { HttpClient } from './http_clients/base.js';
|
|
3
|
+
import type { HttpCompressor } from './http_compressors/base.js';
|
|
4
|
+
import type { HttpCompressionAlgorithm } from './http_compressors/resolve.js';
|
|
5
5
|
import { ActorClient } from './resource_clients/actor.js';
|
|
6
6
|
import { ActorCollectionClient } from './resource_clients/actor_collection.js';
|
|
7
7
|
import { BuildClient } from './resource_clients/build.js';
|
|
@@ -49,17 +49,66 @@ 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
|
|
55
56
|
*/
|
|
56
57
|
publicBaseUrl: string;
|
|
57
58
|
token?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Statistics of the API calls made through the client. With a custom HTTP client, this is the client's own
|
|
61
|
+
* `stats` object, so it only reflects what that client records.
|
|
62
|
+
*/
|
|
58
63
|
stats: Statistics;
|
|
59
64
|
logger: Log;
|
|
60
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Creates a client that sends its requests through the built-in {@link AxiosHttpClient}, configured from
|
|
67
|
+
* `options`: the API token, retries, the timeout tiers, request compression and default headers. The HTTP
|
|
68
|
+
* client itself is created when {@link httpClient} is first read. To send the requests through a custom HTTP
|
|
69
|
+
* client, use {@link ApifyClient.withCustomHttpClient} instead.
|
|
70
|
+
*
|
|
71
|
+
* @param options - Configuration of the client and of its HTTP client.
|
|
72
|
+
* @throws {ArgumentValidationError} When an option is unknown or has an invalid value.
|
|
73
|
+
*/
|
|
61
74
|
constructor(options?: ApifyClientOptions);
|
|
62
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Creates an `ApifyClient` that sends its requests through a custom HTTP client.
|
|
77
|
+
*
|
|
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.
|
|
82
|
+
*
|
|
83
|
+
* @param options - The token, the API URLs and the HTTP client to use.
|
|
84
|
+
* @returns A client whose {@link httpClient} is the given one.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```javascript
|
|
88
|
+
* import { ApifyClient, HttpClient } from 'apify-client';
|
|
89
|
+
*
|
|
90
|
+
* class MyHttpClient extends HttpClient {
|
|
91
|
+
* async sendRequest({ method, url, headers, body, timeoutMillis, stream, signal }) {
|
|
92
|
+
* // Send the request with the HTTP library of your choice and return { status, headers, body }.
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* const client = ApifyClient.withCustomHttpClient({ token: 'my-token', httpClient: new MyHttpClient() });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
static withCustomHttpClient(options: ApifyClientCustomHttpClientOptions): ApifyClient;
|
|
100
|
+
/**
|
|
101
|
+
* 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
|
+
* constructor options, created on first access. Assigning a client applies {@link token} to it through
|
|
104
|
+
* {@link HttpClient.setDefaultAuthorization} and points {@link stats} at its statistics, so the counters keep
|
|
105
|
+
* 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.
|
|
109
|
+
*/
|
|
110
|
+
get httpClient(): HttpClient;
|
|
111
|
+
set httpClient(httpClient: HttpClient);
|
|
63
112
|
/**
|
|
64
113
|
* Returns a client for managing Actors in your account.
|
|
65
114
|
*
|
|
@@ -347,13 +396,41 @@ export declare class ApifyClient {
|
|
|
347
396
|
*/
|
|
348
397
|
setStatusMessage(message: string, options?: SetStatusMessageOptions): Promise<void>;
|
|
349
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Options for {@apilink ApifyClient.setStatusMessage}. Structurally identical to crawlee's
|
|
401
|
+
* `SetStatusMessageOptions`, so the client stays a drop-in `StorageClient` implementation
|
|
402
|
+
* without a dependency on the crawlee packages.
|
|
403
|
+
*/
|
|
404
|
+
export interface SetStatusMessageOptions {
|
|
405
|
+
/** If true, the status message is marked as the final one for the run. */
|
|
406
|
+
isStatusMessageTerminal?: boolean;
|
|
407
|
+
/** The log level for the status message. */
|
|
408
|
+
level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
409
|
+
}
|
|
350
410
|
/**
|
|
351
411
|
* Configuration options for ApifyClient.
|
|
352
412
|
*/
|
|
353
413
|
export interface ApifyClientOptions {
|
|
354
|
-
/**
|
|
414
|
+
/**
|
|
415
|
+
* URL of the Apify API, with or without the `/v2` version path, which is appended when missing.
|
|
416
|
+
* @default https://api.apify.com
|
|
417
|
+
*/
|
|
355
418
|
baseUrl?: string;
|
|
356
419
|
/**
|
|
420
|
+
* Compression of request bodies: the name of a built-in algorithm, or an {@link HttpCompressor} for a custom
|
|
421
|
+
* quality or algorithm. Bodies are compressed only in Node.js, and only when they are large enough to benefit
|
|
422
|
+
* and their content type does not already carry its own compression.
|
|
423
|
+
* @default 'brotli'
|
|
424
|
+
*/
|
|
425
|
+
compression?: HttpCompressionAlgorithm | HttpCompressor;
|
|
426
|
+
/**
|
|
427
|
+
* Additional headers sent with every request, such as an integration platform marker. They win over the
|
|
428
|
+
* built-in defaults, and a header set on a single call wins over them.
|
|
429
|
+
*/
|
|
430
|
+
headers?: Record<string, string>;
|
|
431
|
+
/**
|
|
432
|
+
* Publicly accessible URL of the Apify API, used in the URLs the client generates. Like `baseUrl`, with or
|
|
433
|
+
* without the `/v2` version path.
|
|
357
434
|
* @default https://api.apify.com
|
|
358
435
|
* @since Added in 2.17.0
|
|
359
436
|
*/
|
|
@@ -362,13 +439,51 @@ export interface ApifyClientOptions {
|
|
|
362
439
|
maxRetries?: number;
|
|
363
440
|
/** @default 500 */
|
|
364
441
|
minDelayBetweenRetriesMillis?: number;
|
|
365
|
-
/**
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
442
|
+
/**
|
|
443
|
+
* Duration of the `short` timeout tier, in seconds: simple metadata reads and writes.
|
|
444
|
+
* @default 5
|
|
445
|
+
*/
|
|
446
|
+
timeoutShortSecs?: number;
|
|
447
|
+
/**
|
|
448
|
+
* Duration of the `medium` timeout tier, in seconds: listing, batch and trigger operations.
|
|
449
|
+
* @default 30
|
|
450
|
+
*/
|
|
451
|
+
timeoutMediumSecs?: number;
|
|
452
|
+
/**
|
|
453
|
+
* Duration of the `long` timeout tier, in seconds: downloads, uploads and streaming.
|
|
454
|
+
* @default 360
|
|
455
|
+
*/
|
|
456
|
+
timeoutLongSecs?: number;
|
|
457
|
+
/**
|
|
458
|
+
* Cap on the timeout of a single request attempt, in seconds. It bounds the doubling of the timeout across
|
|
459
|
+
* retries, and caps tier and per-call timeouts alike, so raise it to allow a request timeout above 360 s.
|
|
460
|
+
* @default 360
|
|
461
|
+
*/
|
|
462
|
+
timeoutMaxSecs?: number;
|
|
369
463
|
token?: string;
|
|
370
464
|
/**
|
|
371
465
|
* @since Added in 2.10.0
|
|
372
466
|
*/
|
|
373
467
|
userAgentSuffix?: string | string[];
|
|
374
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* Configuration options for {@link ApifyClient.withCustomHttpClient}. Retries, timeouts and headers are configured
|
|
471
|
+
* on the HTTP client itself.
|
|
472
|
+
*/
|
|
473
|
+
export interface ApifyClientCustomHttpClientOptions {
|
|
474
|
+
/**
|
|
475
|
+
* URL of the Apify API, with or without the `/v2` version path, which is appended when missing.
|
|
476
|
+
* @default https://api.apify.com
|
|
477
|
+
*/
|
|
478
|
+
baseUrl?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Publicly accessible URL of the Apify API, used in the URLs the client generates. Like `baseUrl`, with or
|
|
481
|
+
* without the `/v2` version path.
|
|
482
|
+
* @default https://api.apify.com
|
|
483
|
+
*/
|
|
484
|
+
publicBaseUrl?: string;
|
|
485
|
+
/** Set as the HTTP client's `Authorization` header, unless it already has one. */
|
|
486
|
+
token?: string;
|
|
487
|
+
/** The HTTP client to send the requests through. */
|
|
488
|
+
httpClient: HttpClient;
|
|
489
|
+
}
|