apify-client 3.0.0-beta.9 → 3.0.0-beta.90
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 +16 -2
- package/dist/apify_api_error.d.ts +13 -27
- package/dist/apify_api_error.js +33 -23
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -36
- package/dist/base/resource_client.d.ts +21 -8
- package/dist/base/resource_client.js +70 -36
- 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 +3040 -971
- package/dist/generated/schemas.d.ts +2369 -934
- package/dist/generated/schemas.js +570 -229
- package/dist/http_clients/axios.d.ts +61 -0
- package/dist/http_clients/axios.js +119 -0
- package/dist/http_clients/base.d.ts +386 -0
- package/dist/http_clients/base.js +650 -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 +6 -1
- package/dist/index.js +5 -1
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/models.d.ts +166 -243
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +104 -34
- package/dist/resource_clients/actor.js +130 -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_server.d.ts +141 -0
- package/dist/resource_clients/actor_server.js +195 -0
- 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 +83 -37
- package/dist/resource_clients/dataset.js +107 -121
- 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 +108 -26
- package/dist/resource_clients/key_value_store.js +134 -52
- 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 +40 -21
- package/dist/resource_clients/log.js +144 -66
- package/dist/resource_clients/request_queue.d.ts +76 -31
- package/dist/resource_clients/request_queue.js +178 -93
- 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 +126 -28
- package/dist/resource_clients/run.js +193 -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/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +80 -0
- package/dist/runtime/types.d.ts +60 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +21 -0
- package/dist/schemas.d.ts +368 -4
- package/dist/schemas.js +26 -4
- 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 +89 -59
- package/dist/utils.js +216 -158
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +37 -34
- 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
|
@@ -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)
|
|
@@ -59,6 +60,17 @@ By default, it will retry up to 8 times. First retry will be attempted after ~50
|
|
|
59
60
|
and so on. You can configure those parameters using the `maxRetries` and `minDelayBetweenRetriesMillis`
|
|
60
61
|
options of the `ApifyClient` constructor.
|
|
61
62
|
|
|
63
|
+
### Pluggable HTTP client
|
|
64
|
+
|
|
65
|
+
The client ships with an axios-based HTTP client and accepts a custom one. Extend `HttpClient`, implement
|
|
66
|
+
`sendRequest()` over the HTTP library of your choice and plug it in with `ApifyClient.withCustomHttpClient()`. The
|
|
67
|
+
custom client inherits the retries, timeouts, compression and error handling of the built-in one.
|
|
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
|
+
|
|
62
74
|
### Convenience functions and options
|
|
63
75
|
|
|
64
76
|
Some actions can't be performed by the API itself, such as indefinite waiting for an actor run to finish
|
|
@@ -145,13 +157,15 @@ property to get only a subset of results. Other props are also available, depend
|
|
|
145
157
|
|
|
146
158
|
## Bundled environments
|
|
147
159
|
|
|
148
|
-
The package includes a pre-built browser bundle that
|
|
160
|
+
The package includes a pre-built browser bundle that bundlers targeting browsers resolve automatically. You can also import it explicitly:
|
|
149
161
|
|
|
150
162
|
```typescript
|
|
151
163
|
import { ApifyClient } from 'apify-client/browser';
|
|
152
164
|
```
|
|
153
165
|
|
|
154
|
-
|
|
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.
|
|
167
|
+
|
|
168
|
+
For details, see [Bundled environments](https://docs.apify.com/api/client/js/docs/concepts/bundled-environments).
|
|
155
169
|
|
|
156
170
|
## API Reference
|
|
157
171
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { AxiosResponse } from 'axios';
|
|
2
1
|
import type { LiteralUnion } from 'type-fest';
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { ApifyClientError } from './apify_client_error.js';
|
|
3
|
+
import type { ApifyResponse } from './http_clients/base.js';
|
|
4
|
+
import type { ErrorType } from './models.js';
|
|
5
|
+
export type { ErrorType } from './models.js';
|
|
5
6
|
/**
|
|
6
7
|
* An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
|
|
7
8
|
* but the API responds with an error response. Typically, those are rate limit
|
|
@@ -16,11 +17,13 @@ export type { ApifyApiErrorType } 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
|
|
20
|
+
export declare class ApifyApiError extends ApifyClientError {
|
|
21
|
+
#private;
|
|
20
22
|
name: string;
|
|
21
23
|
/**
|
|
22
|
-
* The
|
|
23
|
-
*
|
|
24
|
+
* The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
|
|
25
|
+
* method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
|
|
26
|
+
* when the stack trace cannot be parsed.
|
|
24
27
|
*/
|
|
25
28
|
clientMethod: string;
|
|
26
29
|
/**
|
|
@@ -28,10 +31,10 @@ export declare class ApifyApiError extends Error {
|
|
|
28
31
|
*/
|
|
29
32
|
statusCode: number;
|
|
30
33
|
/**
|
|
31
|
-
* The type of the error, as returned by the API. Typed as the known {@link
|
|
34
|
+
* The type of the error, as returned by the API. Typed as the known {@link ErrorType}
|
|
32
35
|
* values for autocompletion, while still accepting any string the API may return.
|
|
33
36
|
*/
|
|
34
|
-
type?: LiteralUnion<
|
|
37
|
+
type?: LiteralUnion<ErrorType, string>;
|
|
35
38
|
/**
|
|
36
39
|
* Number of the API call attempt.
|
|
37
40
|
*/
|
|
@@ -56,29 +59,12 @@ export declare class ApifyApiError extends Error {
|
|
|
56
59
|
/**
|
|
57
60
|
* @hidden
|
|
58
61
|
*/
|
|
59
|
-
constructor(response:
|
|
62
|
+
constructor(response: ApifyResponse, attempt: number);
|
|
60
63
|
/**
|
|
61
64
|
* Creates the error for a failed response as an instance of the subclass matching its HTTP status code.
|
|
62
65
|
* @hidden
|
|
63
66
|
*/
|
|
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;
|
|
67
|
+
static fromResponse(response: ApifyResponse, attempt: number): ApifyApiError;
|
|
82
68
|
}
|
|
83
69
|
/**
|
|
84
70
|
* 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,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApifyClientError } from './apify_client_error.js';
|
|
2
2
|
import { isBuffer } from './utils.js';
|
|
3
3
|
/**
|
|
4
|
-
* Examples of capturing groups for "...at ActorCollectionClient.
|
|
5
|
-
* 0: "at ActorCollectionClient.
|
|
4
|
+
* Examples of capturing groups for "...at ActorCollectionClient.listResources (/Users/..."
|
|
5
|
+
* 0: "at ActorCollectionClient.listResources ("
|
|
6
6
|
* 1: undefined
|
|
7
7
|
* 2: "ActorCollectionClient"
|
|
8
8
|
* 3: undefined
|
|
9
|
-
* 4: "
|
|
9
|
+
* 4: "listResources"
|
|
10
|
+
*
|
|
11
|
+
* The error is created inside the HTTP client's pipeline, whose frames sit above the resource client's. The
|
|
12
|
+
* pipeline's own methods are private, so V8 prints them with a `#` that no method name can match. Its public
|
|
13
|
+
* `call()` prints under the name of the transport's class, which can be anything, so the lookaheads skip a class
|
|
14
|
+
* named after `HttpClient` and the method `call`. A transport named `SomethingClient` whose `call()` override
|
|
15
|
+
* awaits a helper of its own is reported under that helper. `ActorClient.call()` and `TaskClient.call()` reach the
|
|
16
|
+
* pipeline through `start()`, whose frame sits closer to the error and matches first.
|
|
10
17
|
* @private
|
|
11
18
|
*/
|
|
12
|
-
const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\.
|
|
19
|
+
const CLIENT_METHOD_REGEX = /at( async)? (?![A-Za-z]*HttpClient\.)([A-Za-z]+(Collection)?Client)\.(?!call \()([A-Za-z]+) \(/;
|
|
13
20
|
/**
|
|
14
21
|
* An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
|
|
15
22
|
* but the API responds with an error response. Typically, those are rate limit
|
|
@@ -24,11 +31,12 @@ const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\._?([A-Z
|
|
|
24
31
|
* subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
|
|
25
32
|
* share a status code are told apart by their `type`.
|
|
26
33
|
*/
|
|
27
|
-
export class ApifyApiError extends
|
|
34
|
+
export class ApifyApiError extends ApifyClientError {
|
|
28
35
|
name;
|
|
29
36
|
/**
|
|
30
|
-
* The
|
|
31
|
-
*
|
|
37
|
+
* The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
|
|
38
|
+
* method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
|
|
39
|
+
* when the stack trace cannot be parsed.
|
|
32
40
|
*/
|
|
33
41
|
clientMethod;
|
|
34
42
|
/**
|
|
@@ -36,7 +44,7 @@ export class ApifyApiError extends Error {
|
|
|
36
44
|
*/
|
|
37
45
|
statusCode;
|
|
38
46
|
/**
|
|
39
|
-
* The type of the error, as returned by the API. Typed as the known {@link
|
|
47
|
+
* The type of the error, as returned by the API. Typed as the known {@link ErrorType}
|
|
40
48
|
* values for autocompletion, while still accepting any string the API may return.
|
|
41
49
|
*/
|
|
42
50
|
type;
|
|
@@ -69,14 +77,16 @@ export class ApifyApiError extends Error {
|
|
|
69
77
|
let type;
|
|
70
78
|
let responseData = response.data;
|
|
71
79
|
let errorData;
|
|
72
|
-
//
|
|
73
|
-
//
|
|
80
|
+
// A `responseType: 'buffer'` request (e.g. `downloadItems()`) and a failed streaming request, whose body
|
|
81
|
+
// `HttpClient` has read into a buffer, both arrive unparsed. Parse the body here to get at the error.
|
|
74
82
|
if (isBuffer(responseData)) {
|
|
83
|
+
const body = new TextDecoder().decode(response.data);
|
|
75
84
|
try {
|
|
76
|
-
responseData = JSON.parse(
|
|
85
|
+
responseData = JSON.parse(body);
|
|
77
86
|
}
|
|
78
87
|
catch {
|
|
79
|
-
//
|
|
88
|
+
// A body that is not JSON at all, such as an HTML error page from a proxy, is kept as text.
|
|
89
|
+
responseData = body;
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
92
|
if (responseData && responseData.error) {
|
|
@@ -97,15 +107,15 @@ export class ApifyApiError extends Error {
|
|
|
97
107
|
}
|
|
98
108
|
super(message);
|
|
99
109
|
this.name = this.constructor.name;
|
|
100
|
-
this.clientMethod = this
|
|
110
|
+
this.clientMethod = this.#extractClientAndMethodFromStack();
|
|
101
111
|
this.statusCode = response.status;
|
|
102
112
|
this.type = type;
|
|
103
113
|
this.attempt = attempt;
|
|
104
114
|
this.httpMethod = response.config?.method;
|
|
105
|
-
this.path = this
|
|
115
|
+
this.path = this.#safelyParsePathFromResponse(response);
|
|
106
116
|
const stack = this.stack;
|
|
107
117
|
this.originalStack = stack.slice(stack.indexOf('\n'));
|
|
108
|
-
this.stack = this
|
|
118
|
+
this.stack = this.#createApiStack();
|
|
109
119
|
this.data = errorData;
|
|
110
120
|
}
|
|
111
121
|
/**
|
|
@@ -116,7 +126,7 @@ export class ApifyApiError extends Error {
|
|
|
116
126
|
const ErrorClass = ERROR_CLASS_BY_STATUS[response.status] ?? (response.status >= 500 ? ServerError : ApifyApiError);
|
|
117
127
|
return new ErrorClass(response, attempt);
|
|
118
128
|
}
|
|
119
|
-
|
|
129
|
+
#safelyParsePathFromResponse(response) {
|
|
120
130
|
const urlString = response.config?.url;
|
|
121
131
|
let url;
|
|
122
132
|
try {
|
|
@@ -127,11 +137,11 @@ export class ApifyApiError extends Error {
|
|
|
127
137
|
}
|
|
128
138
|
return url.pathname + url.search;
|
|
129
139
|
}
|
|
130
|
-
|
|
140
|
+
#extractClientAndMethodFromStack() {
|
|
131
141
|
const match = this.stack.match(CLIENT_METHOD_REGEX);
|
|
132
|
-
if (match)
|
|
133
|
-
return
|
|
134
|
-
return
|
|
142
|
+
if (!match)
|
|
143
|
+
return 'unknown';
|
|
144
|
+
return `${match[2]}.${match[4]}`;
|
|
135
145
|
}
|
|
136
146
|
/**
|
|
137
147
|
* Creates a better looking and more informative stack that will be printed
|
|
@@ -144,10 +154,10 @@ export class ApifyApiError extends Error {
|
|
|
144
154
|
* statusCode: 404
|
|
145
155
|
* type: record-not-found
|
|
146
156
|
* attempt: 1
|
|
147
|
-
* httpMethod:
|
|
157
|
+
* httpMethod: POST
|
|
148
158
|
* path: /v2/actor-tasks/user~my-task/runs
|
|
149
159
|
*/
|
|
150
|
-
|
|
160
|
+
#createApiStack() {
|
|
151
161
|
const { name, ...props } = this;
|
|
152
162
|
const stack = Object.entries(props)
|
|
153
163
|
.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
|
+
}
|