apify-client 3.0.0-beta.2 → 3.0.0-beta.20
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 +3 -1
- package/dist/apify_api_error.d.ts +60 -19
- package/dist/apify_api_error.js +88 -21
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +35 -29
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +23 -9
- package/dist/base/resource_client.js +49 -25
- package/dist/base/resource_collection_client.d.ts +7 -4
- package/dist/base/resource_collection_client.js +21 -15
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +18 -51
- package/dist/http_client.js +79 -42
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/interceptors.js +22 -4
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +32 -52
- package/dist/resource_clients/actor.d.ts +46 -31
- package/dist/resource_clients/actor.js +71 -53
- package/dist/resource_clients/actor_collection.d.ts +9 -5
- package/dist/resource_clients/actor_collection.js +12 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +17 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
- package/dist/resource_clients/actor_env_var_collection.js +18 -11
- package/dist/resource_clients/actor_version.d.ts +18 -3
- package/dist/resource_clients/actor_version.js +20 -9
- package/dist/resource_clients/actor_version_collection.d.ts +16 -17
- package/dist/resource_clients/actor_version_collection.js +20 -11
- package/dist/resource_clients/build.d.ts +18 -6
- package/dist/resource_clients/build.js +35 -17
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +5 -1
- package/dist/resource_clients/dataset.d.ts +23 -9
- package/dist/resource_clients/dataset.js +70 -48
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +48 -15
- package/dist/resource_clients/key_value_store.js +69 -39
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +9 -19
- package/dist/resource_clients/log.js +55 -44
- package/dist/resource_clients/request_queue.d.ts +56 -26
- package/dist/resource_clients/request_queue.js +178 -113
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +10 -3
- package/dist/resource_clients/run.d.ts +51 -17
- package/dist/resource_clients/run.js +83 -43
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +5 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +31 -21
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +10 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +5 -1
- package/dist/resource_clients/task.d.ts +28 -10
- package/dist/resource_clients/task.js +67 -44
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +10 -3
- package/dist/resource_clients/user.d.ts +17 -8
- package/dist/resource_clients/user.js +40 -39
- package/dist/resource_clients/webhook.d.ts +14 -5
- package/dist/resource_clients/webhook.js +30 -22
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +10 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +8 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +57 -41
- package/dist/utils.js +155 -121
- package/package.json +36 -35
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -153
package/README.md
CHANGED
|
@@ -47,7 +47,9 @@ Besides greatly simplifying the process of querying the Apify API, the client pr
|
|
|
47
47
|
Based on the endpoint, the client automatically extracts the relevant data and returns it in the
|
|
48
48
|
expected format. Date strings are automatically converted to `Date` objects. For exceptions,
|
|
49
49
|
we throw an `ApifyApiError`, which wraps the plain JSON errors returned by API and enriches
|
|
50
|
-
them with other context for easier debugging.
|
|
50
|
+
them with other context for easier debugging. The error is an instance of the subclass matching the
|
|
51
|
+
HTTP status code, such as `NotFoundError` or `RateLimitError`, so a `catch` block can tell them apart
|
|
52
|
+
with `instanceof`.
|
|
51
53
|
|
|
52
54
|
### Retries with exponential backoff
|
|
53
55
|
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import type { AxiosResponse } from 'axios';
|
|
2
|
+
import type { LiteralUnion } from 'type-fest';
|
|
3
|
+
import type { ApifyApiErrorType } from './models.js';
|
|
4
|
+
export type { ApifyApiErrorType } from './models.js';
|
|
2
5
|
/**
|
|
3
6
|
* An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
|
|
4
7
|
* but the API responds with an error response. Typically, those are rate limit
|
|
5
8
|
* errors and internal errors, which are automatically retried, or validation
|
|
6
9
|
* errors, which are thrown immediately, because a correction by the user is
|
|
7
10
|
* needed.
|
|
11
|
+
*
|
|
12
|
+
* The thrown error is an instance of the subclass matching the HTTP status code of the response:
|
|
13
|
+
* {@link InvalidRequestError} (400), {@link UnauthorizedError} (401), {@link ForbiddenError} (403),
|
|
14
|
+
* {@link NotFoundError} (404), {@link ConflictError} (409), {@link RateLimitError} (429) or
|
|
15
|
+
* {@link ServerError} (5xx). Any other status code is thrown as a plain `ApifyApiError`. Every
|
|
16
|
+
* subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
|
|
17
|
+
* share a status code are told apart by their `type`.
|
|
8
18
|
*/
|
|
9
19
|
export declare class ApifyApiError extends Error {
|
|
20
|
+
#private;
|
|
10
21
|
name: string;
|
|
11
22
|
/**
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
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.
|
|
14
26
|
*/
|
|
15
27
|
clientMethod: string;
|
|
16
28
|
/**
|
|
@@ -18,9 +30,10 @@ export declare class ApifyApiError extends Error {
|
|
|
18
30
|
*/
|
|
19
31
|
statusCode: number;
|
|
20
32
|
/**
|
|
21
|
-
* The type of the error, as returned by the API.
|
|
33
|
+
* The type of the error, as returned by the API. Typed as the known {@link ApifyApiErrorType}
|
|
34
|
+
* values for autocompletion, while still accepting any string the API may return.
|
|
22
35
|
*/
|
|
23
|
-
type?: string
|
|
36
|
+
type?: LiteralUnion<ApifyApiErrorType, string>;
|
|
24
37
|
/**
|
|
25
38
|
* Number of the API call attempt.
|
|
26
39
|
*/
|
|
@@ -46,21 +59,49 @@ export declare class ApifyApiError extends Error {
|
|
|
46
59
|
* @hidden
|
|
47
60
|
*/
|
|
48
61
|
constructor(response: AxiosResponse, attempt: number);
|
|
49
|
-
private _safelyParsePathFromResponse;
|
|
50
|
-
private _extractClientAndMethodFromStack;
|
|
51
62
|
/**
|
|
52
|
-
* Creates a
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* Example:
|
|
56
|
-
*
|
|
57
|
-
* ApifyApiError: Actor task was not found
|
|
58
|
-
* clientMethod: TaskClient.start
|
|
59
|
-
* statusCode: 404
|
|
60
|
-
* type: record-not-found
|
|
61
|
-
* attempt: 1
|
|
62
|
-
* httpMethod: post
|
|
63
|
-
* path: /v2/actor-tasks/user~my-task/runs
|
|
63
|
+
* Creates the error for a failed response as an instance of the subclass matching its HTTP status code.
|
|
64
|
+
* @hidden
|
|
64
65
|
*/
|
|
65
|
-
|
|
66
|
+
static fromResponse(response: AxiosResponse, attempt: number): ApifyApiError;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Thrown when the Apify API responds with HTTP 400 Bad Request, typically because the request
|
|
70
|
+
* failed validation.
|
|
71
|
+
*/
|
|
72
|
+
export declare class InvalidRequestError extends ApifyApiError {
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Thrown when the Apify API responds with HTTP 401 Unauthorized, because the token is missing
|
|
76
|
+
* or invalid.
|
|
77
|
+
*/
|
|
78
|
+
export declare class UnauthorizedError extends ApifyApiError {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when the Apify API responds with HTTP 403 Forbidden, because the token lacks the
|
|
82
|
+
* permission for the operation.
|
|
83
|
+
*/
|
|
84
|
+
export declare class ForbiddenError extends ApifyApiError {
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Thrown when the Apify API responds with HTTP 404 Not Found.
|
|
88
|
+
*/
|
|
89
|
+
export declare class NotFoundError extends ApifyApiError {
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Thrown when the Apify API responds with HTTP 409 Conflict.
|
|
93
|
+
*/
|
|
94
|
+
export declare class ConflictError extends ApifyApiError {
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Thrown when the Apify API responds with HTTP 429 Too Many Requests. The client retries such
|
|
98
|
+
* requests, so the error surfaces once the retries are exhausted.
|
|
99
|
+
*/
|
|
100
|
+
export declare class RateLimitError extends ApifyApiError {
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Thrown when the Apify API responds with an HTTP 5xx status. The client retries such requests,
|
|
104
|
+
* so the error surfaces once the retries are exhausted.
|
|
105
|
+
*/
|
|
106
|
+
export declare class ServerError extends ApifyApiError {
|
|
66
107
|
}
|
package/dist/apify_api_error.js
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import { isomorphicBufferToString } from './body_parser.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
10
|
* @private
|
|
11
11
|
*/
|
|
12
|
-
const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\.
|
|
12
|
+
const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\.([A-Za-z]+) \(/;
|
|
13
13
|
/**
|
|
14
14
|
* An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
|
|
15
15
|
* but the API responds with an error response. Typically, those are rate limit
|
|
16
16
|
* errors and internal errors, which are automatically retried, or validation
|
|
17
17
|
* errors, which are thrown immediately, because a correction by the user is
|
|
18
18
|
* needed.
|
|
19
|
+
*
|
|
20
|
+
* The thrown error is an instance of the subclass matching the HTTP status code of the response:
|
|
21
|
+
* {@link InvalidRequestError} (400), {@link UnauthorizedError} (401), {@link ForbiddenError} (403),
|
|
22
|
+
* {@link NotFoundError} (404), {@link ConflictError} (409), {@link RateLimitError} (429) or
|
|
23
|
+
* {@link ServerError} (5xx). Any other status code is thrown as a plain `ApifyApiError`. Every
|
|
24
|
+
* subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
|
|
25
|
+
* share a status code are told apart by their `type`.
|
|
19
26
|
*/
|
|
20
27
|
export class ApifyApiError extends Error {
|
|
21
28
|
name;
|
|
22
29
|
/**
|
|
23
|
-
* The
|
|
24
|
-
*
|
|
30
|
+
* The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
|
|
31
|
+
* method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
|
|
32
|
+
* when the stack trace cannot be parsed.
|
|
25
33
|
*/
|
|
26
34
|
clientMethod;
|
|
27
35
|
/**
|
|
@@ -29,7 +37,8 @@ export class ApifyApiError extends Error {
|
|
|
29
37
|
*/
|
|
30
38
|
statusCode;
|
|
31
39
|
/**
|
|
32
|
-
* The type of the error, as returned by the API.
|
|
40
|
+
* The type of the error, as returned by the API. Typed as the known {@link ApifyApiErrorType}
|
|
41
|
+
* values for autocompletion, while still accepting any string the API may return.
|
|
33
42
|
*/
|
|
34
43
|
type;
|
|
35
44
|
/**
|
|
@@ -61,14 +70,16 @@ export class ApifyApiError extends Error {
|
|
|
61
70
|
let type;
|
|
62
71
|
let responseData = response.data;
|
|
63
72
|
let errorData;
|
|
64
|
-
//
|
|
65
|
-
//
|
|
73
|
+
// A `forceBuffer` request (e.g. `downloadItems()`) and a failed streaming request, whose body `HttpClient`
|
|
74
|
+
// has read into a buffer, both arrive unparsed. Parse the body here to get at the error.
|
|
66
75
|
if (isBuffer(responseData)) {
|
|
76
|
+
const body = isomorphicBufferToString(response.data, 'utf-8');
|
|
67
77
|
try {
|
|
68
|
-
responseData = JSON.parse(
|
|
78
|
+
responseData = JSON.parse(body);
|
|
69
79
|
}
|
|
70
80
|
catch {
|
|
71
|
-
//
|
|
81
|
+
// A body that is not JSON at all, such as an HTML error page from a proxy, is kept as text.
|
|
82
|
+
responseData = body;
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
if (responseData && responseData.error) {
|
|
@@ -89,18 +100,26 @@ export class ApifyApiError extends Error {
|
|
|
89
100
|
}
|
|
90
101
|
super(message);
|
|
91
102
|
this.name = this.constructor.name;
|
|
92
|
-
this.clientMethod = this
|
|
103
|
+
this.clientMethod = this.#extractClientAndMethodFromStack();
|
|
93
104
|
this.statusCode = response.status;
|
|
94
105
|
this.type = type;
|
|
95
106
|
this.attempt = attempt;
|
|
96
107
|
this.httpMethod = response.config?.method;
|
|
97
|
-
this.path = this
|
|
108
|
+
this.path = this.#safelyParsePathFromResponse(response);
|
|
98
109
|
const stack = this.stack;
|
|
99
110
|
this.originalStack = stack.slice(stack.indexOf('\n'));
|
|
100
|
-
this.stack = this
|
|
111
|
+
this.stack = this.#createApiStack();
|
|
101
112
|
this.data = errorData;
|
|
102
113
|
}
|
|
103
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Creates the error for a failed response as an instance of the subclass matching its HTTP status code.
|
|
116
|
+
* @hidden
|
|
117
|
+
*/
|
|
118
|
+
static fromResponse(response, attempt) {
|
|
119
|
+
const ErrorClass = ERROR_CLASS_BY_STATUS[response.status] ?? (response.status >= 500 ? ServerError : ApifyApiError);
|
|
120
|
+
return new ErrorClass(response, attempt);
|
|
121
|
+
}
|
|
122
|
+
#safelyParsePathFromResponse(response) {
|
|
104
123
|
const urlString = response.config?.url;
|
|
105
124
|
let url;
|
|
106
125
|
try {
|
|
@@ -111,11 +130,11 @@ export class ApifyApiError extends Error {
|
|
|
111
130
|
}
|
|
112
131
|
return url.pathname + url.search;
|
|
113
132
|
}
|
|
114
|
-
|
|
133
|
+
#extractClientAndMethodFromStack() {
|
|
115
134
|
const match = this.stack.match(CLIENT_METHOD_REGEX);
|
|
116
|
-
if (match)
|
|
117
|
-
return
|
|
118
|
-
return
|
|
135
|
+
if (!match)
|
|
136
|
+
return 'unknown';
|
|
137
|
+
return `${match[2]}.${match[4]}`;
|
|
119
138
|
}
|
|
120
139
|
/**
|
|
121
140
|
* Creates a better looking and more informative stack that will be printed
|
|
@@ -123,7 +142,7 @@ export class ApifyApiError extends Error {
|
|
|
123
142
|
*
|
|
124
143
|
* Example:
|
|
125
144
|
*
|
|
126
|
-
*
|
|
145
|
+
* NotFoundError: Actor task was not found
|
|
127
146
|
* clientMethod: TaskClient.start
|
|
128
147
|
* statusCode: 404
|
|
129
148
|
* type: record-not-found
|
|
@@ -131,7 +150,7 @@ export class ApifyApiError extends Error {
|
|
|
131
150
|
* httpMethod: post
|
|
132
151
|
* path: /v2/actor-tasks/user~my-task/runs
|
|
133
152
|
*/
|
|
134
|
-
|
|
153
|
+
#createApiStack() {
|
|
135
154
|
const { name, ...props } = this;
|
|
136
155
|
const stack = Object.entries(props)
|
|
137
156
|
.map(([k, v]) => {
|
|
@@ -145,3 +164,51 @@ export class ApifyApiError extends Error {
|
|
|
145
164
|
return `${name}: ${this.message}\n${stack}`;
|
|
146
165
|
}
|
|
147
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Thrown when the Apify API responds with HTTP 400 Bad Request, typically because the request
|
|
169
|
+
* failed validation.
|
|
170
|
+
*/
|
|
171
|
+
export class InvalidRequestError extends ApifyApiError {
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Thrown when the Apify API responds with HTTP 401 Unauthorized, because the token is missing
|
|
175
|
+
* or invalid.
|
|
176
|
+
*/
|
|
177
|
+
export class UnauthorizedError extends ApifyApiError {
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Thrown when the Apify API responds with HTTP 403 Forbidden, because the token lacks the
|
|
181
|
+
* permission for the operation.
|
|
182
|
+
*/
|
|
183
|
+
export class ForbiddenError extends ApifyApiError {
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Thrown when the Apify API responds with HTTP 404 Not Found.
|
|
187
|
+
*/
|
|
188
|
+
export class NotFoundError extends ApifyApiError {
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Thrown when the Apify API responds with HTTP 409 Conflict.
|
|
192
|
+
*/
|
|
193
|
+
export class ConflictError extends ApifyApiError {
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Thrown when the Apify API responds with HTTP 429 Too Many Requests. The client retries such
|
|
197
|
+
* requests, so the error surfaces once the retries are exhausted.
|
|
198
|
+
*/
|
|
199
|
+
export class RateLimitError extends ApifyApiError {
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Thrown when the Apify API responds with an HTTP 5xx status. The client retries such requests,
|
|
203
|
+
* so the error surfaces once the retries are exhausted.
|
|
204
|
+
*/
|
|
205
|
+
export class ServerError extends ApifyApiError {
|
|
206
|
+
}
|
|
207
|
+
const ERROR_CLASS_BY_STATUS = {
|
|
208
|
+
400: InvalidRequestError,
|
|
209
|
+
401: UnauthorizedError,
|
|
210
|
+
403: ForbiddenError,
|
|
211
|
+
404: NotFoundError,
|
|
212
|
+
409: ConflictError,
|
|
213
|
+
429: RateLimitError,
|
|
214
|
+
};
|
package/dist/apify_client.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ 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
|
|
@@ -59,7 +60,6 @@ export declare class ApifyClient {
|
|
|
59
60
|
logger: Log;
|
|
60
61
|
httpClient: HttpClient;
|
|
61
62
|
constructor(options?: ApifyClientOptions);
|
|
62
|
-
private _options;
|
|
63
63
|
/**
|
|
64
64
|
* Returns a client for managing Actors in your account.
|
|
65
65
|
*
|
|
@@ -364,8 +364,27 @@ export interface ApifyClientOptions {
|
|
|
364
364
|
minDelayBetweenRetriesMillis?: number;
|
|
365
365
|
/** @default [] */
|
|
366
366
|
requestInterceptors?: RequestInterceptorFunction[];
|
|
367
|
-
/**
|
|
368
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Duration of the `short` timeout tier, in seconds: simple metadata reads and writes.
|
|
369
|
+
* @default 5
|
|
370
|
+
*/
|
|
371
|
+
timeoutShortSecs?: number;
|
|
372
|
+
/**
|
|
373
|
+
* Duration of the `medium` timeout tier, in seconds: listing, batch and trigger operations.
|
|
374
|
+
* @default 30
|
|
375
|
+
*/
|
|
376
|
+
timeoutMediumSecs?: number;
|
|
377
|
+
/**
|
|
378
|
+
* Duration of the `long` timeout tier, in seconds: downloads, uploads and streaming.
|
|
379
|
+
* @default 360
|
|
380
|
+
*/
|
|
381
|
+
timeoutLongSecs?: number;
|
|
382
|
+
/**
|
|
383
|
+
* Cap on the timeout of a single request attempt, in seconds. It bounds the doubling of the timeout across
|
|
384
|
+
* retries, and caps tier and per-call timeouts alike, so raise it to allow a request timeout above 360 s.
|
|
385
|
+
* @default 360
|
|
386
|
+
*/
|
|
387
|
+
timeoutMaxSecs?: number;
|
|
369
388
|
token?: string;
|
|
370
389
|
/**
|
|
371
390
|
* @since Added in 2.10.0
|
package/dist/apify_client.js
CHANGED
|
@@ -26,22 +26,25 @@ import { WebhookCollectionClient } from './resource_clients/webhook_collection.j
|
|
|
26
26
|
import { WebhookDispatchClient } from './resource_clients/webhook_dispatch.js';
|
|
27
27
|
import { WebhookDispatchCollectionClient } from './resource_clients/webhook_dispatch_collection.js';
|
|
28
28
|
import { Statistics } from './statistics.js';
|
|
29
|
+
import { DEFAULT_TIMEOUT_LONG_SECS, DEFAULT_TIMEOUT_MAX_SECS, DEFAULT_TIMEOUT_MEDIUM_SECS, DEFAULT_TIMEOUT_SHORT_SECS, } from './timeouts.js';
|
|
29
30
|
import { parseArgument } from './utils.js';
|
|
30
|
-
const DEFAULT_TIMEOUT_SECS = 360;
|
|
31
31
|
const clientOptionsSchema = z.strictObject({
|
|
32
32
|
baseUrl: z.string().default('https://api.apify.com'),
|
|
33
33
|
publicBaseUrl: z.string().default('https://api.apify.com'),
|
|
34
34
|
maxRetries: z.number().default(8),
|
|
35
35
|
minDelayBetweenRetriesMillis: z.number().default(500),
|
|
36
36
|
requestInterceptors: z.array(z.unknown()).default([]),
|
|
37
|
-
|
|
37
|
+
timeoutShortSecs: z.number().positive().default(DEFAULT_TIMEOUT_SHORT_SECS),
|
|
38
|
+
timeoutMediumSecs: z.number().positive().default(DEFAULT_TIMEOUT_MEDIUM_SECS),
|
|
39
|
+
timeoutLongSecs: z.number().positive().default(DEFAULT_TIMEOUT_LONG_SECS),
|
|
40
|
+
timeoutMaxSecs: z.number().positive().default(DEFAULT_TIMEOUT_MAX_SECS),
|
|
38
41
|
token: z.string().optional(),
|
|
39
42
|
userAgentSuffix: z.union([z.string(), z.array(z.string())]).optional(),
|
|
40
43
|
});
|
|
41
44
|
const resourceIdSchema = z.string().min(1);
|
|
42
45
|
const requestQueueOptionsSchema = z.strictObject({
|
|
43
46
|
clientKey: z.string().min(1).optional(),
|
|
44
|
-
timeoutSecs: z.number().optional(),
|
|
47
|
+
timeoutSecs: z.number().positive().optional(),
|
|
45
48
|
});
|
|
46
49
|
/**
|
|
47
50
|
* The official JavaScript client for the Apify API.
|
|
@@ -76,7 +79,7 @@ export class ApifyClient {
|
|
|
76
79
|
httpClient;
|
|
77
80
|
constructor(options = {}) {
|
|
78
81
|
const parsed = parseArgument(options, clientOptionsSchema, 'ApifyClientOptions');
|
|
79
|
-
const { baseUrl, publicBaseUrl, maxRetries, minDelayBetweenRetriesMillis, requestInterceptors,
|
|
82
|
+
const { baseUrl, publicBaseUrl, maxRetries, minDelayBetweenRetriesMillis, requestInterceptors, timeoutShortSecs, timeoutMediumSecs, timeoutLongSecs, timeoutMaxSecs, token, } = parsed;
|
|
80
83
|
const tempBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl;
|
|
81
84
|
this.baseUrl = `${tempBaseUrl}/v2`;
|
|
82
85
|
const tempPublicBaseUrl = publicBaseUrl.endsWith('/')
|
|
@@ -91,13 +94,16 @@ export class ApifyClient {
|
|
|
91
94
|
maxRetries,
|
|
92
95
|
minDelayBetweenRetriesMillis,
|
|
93
96
|
requestInterceptors,
|
|
94
|
-
|
|
97
|
+
timeoutShortSecs,
|
|
98
|
+
timeoutMediumSecs,
|
|
99
|
+
timeoutLongSecs,
|
|
100
|
+
timeoutMaxSecs,
|
|
95
101
|
logger: this.logger,
|
|
96
102
|
token: this.token,
|
|
97
103
|
userAgentSuffix: parsed.userAgentSuffix,
|
|
98
104
|
});
|
|
99
105
|
}
|
|
100
|
-
|
|
106
|
+
#subClientOptions() {
|
|
101
107
|
return {
|
|
102
108
|
baseUrl: this.baseUrl,
|
|
103
109
|
publicBaseUrl: this.publicBaseUrl,
|
|
@@ -114,7 +120,7 @@ export class ApifyClient {
|
|
|
114
120
|
* @see https://docs.apify.com/api/v2/acts-get
|
|
115
121
|
*/
|
|
116
122
|
actors() {
|
|
117
|
-
return new ActorCollectionClient(this
|
|
123
|
+
return new ActorCollectionClient(this.#subClientOptions());
|
|
118
124
|
}
|
|
119
125
|
/**
|
|
120
126
|
* Returns a client for a specific Actor.
|
|
@@ -136,7 +142,7 @@ export class ApifyClient {
|
|
|
136
142
|
parseArgument(id, resourceIdSchema);
|
|
137
143
|
return new ActorClient({
|
|
138
144
|
id,
|
|
139
|
-
...this
|
|
145
|
+
...this.#subClientOptions(),
|
|
140
146
|
});
|
|
141
147
|
}
|
|
142
148
|
/**
|
|
@@ -148,7 +154,7 @@ export class ApifyClient {
|
|
|
148
154
|
* @see https://docs.apify.com/api/v2/actor-builds-get
|
|
149
155
|
*/
|
|
150
156
|
builds() {
|
|
151
|
-
return new BuildCollectionClient(this
|
|
157
|
+
return new BuildCollectionClient(this.#subClientOptions());
|
|
152
158
|
}
|
|
153
159
|
/**
|
|
154
160
|
* Returns a client for a specific Actor build.
|
|
@@ -163,7 +169,7 @@ export class ApifyClient {
|
|
|
163
169
|
parseArgument(id, resourceIdSchema);
|
|
164
170
|
return new BuildClient({
|
|
165
171
|
id,
|
|
166
|
-
...this
|
|
172
|
+
...this.#subClientOptions(),
|
|
167
173
|
});
|
|
168
174
|
}
|
|
169
175
|
/**
|
|
@@ -175,7 +181,7 @@ export class ApifyClient {
|
|
|
175
181
|
* @see https://docs.apify.com/api/v2/datasets-get
|
|
176
182
|
*/
|
|
177
183
|
datasets() {
|
|
178
|
-
return new DatasetCollectionClient(this
|
|
184
|
+
return new DatasetCollectionClient(this.#subClientOptions());
|
|
179
185
|
}
|
|
180
186
|
/**
|
|
181
187
|
* Returns a client for a specific dataset.
|
|
@@ -204,7 +210,7 @@ export class ApifyClient {
|
|
|
204
210
|
parseArgument(id, resourceIdSchema);
|
|
205
211
|
return new DatasetClient({
|
|
206
212
|
id,
|
|
207
|
-
...this
|
|
213
|
+
...this.#subClientOptions(),
|
|
208
214
|
});
|
|
209
215
|
}
|
|
210
216
|
/**
|
|
@@ -216,7 +222,7 @@ export class ApifyClient {
|
|
|
216
222
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
217
223
|
*/
|
|
218
224
|
keyValueStores() {
|
|
219
|
-
return new KeyValueStoreCollectionClient(this
|
|
225
|
+
return new KeyValueStoreCollectionClient(this.#subClientOptions());
|
|
220
226
|
}
|
|
221
227
|
/**
|
|
222
228
|
* Returns a client for a specific key-value store.
|
|
@@ -241,7 +247,7 @@ export class ApifyClient {
|
|
|
241
247
|
parseArgument(id, resourceIdSchema);
|
|
242
248
|
return new KeyValueStoreClient({
|
|
243
249
|
id,
|
|
244
|
-
...this
|
|
250
|
+
...this.#subClientOptions(),
|
|
245
251
|
});
|
|
246
252
|
}
|
|
247
253
|
/**
|
|
@@ -255,7 +261,7 @@ export class ApifyClient {
|
|
|
255
261
|
parseArgument(buildOrRunId, resourceIdSchema);
|
|
256
262
|
return new LogClient({
|
|
257
263
|
id: buildOrRunId,
|
|
258
|
-
...this
|
|
264
|
+
...this.#subClientOptions(),
|
|
259
265
|
});
|
|
260
266
|
}
|
|
261
267
|
/**
|
|
@@ -267,7 +273,7 @@ export class ApifyClient {
|
|
|
267
273
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
268
274
|
*/
|
|
269
275
|
requestQueues() {
|
|
270
|
-
return new RequestQueueCollectionClient(this
|
|
276
|
+
return new RequestQueueCollectionClient(this.#subClientOptions());
|
|
271
277
|
}
|
|
272
278
|
/**
|
|
273
279
|
* Returns a client for a specific request queue.
|
|
@@ -295,7 +301,7 @@ export class ApifyClient {
|
|
|
295
301
|
const parsed = parseArgument(options, requestQueueOptionsSchema, 'RequestQueueUserOptions');
|
|
296
302
|
const apiClientOptions = {
|
|
297
303
|
id,
|
|
298
|
-
...this
|
|
304
|
+
...this.#subClientOptions(),
|
|
299
305
|
};
|
|
300
306
|
return new RequestQueueClient(apiClientOptions, parsed);
|
|
301
307
|
}
|
|
@@ -309,7 +315,7 @@ export class ApifyClient {
|
|
|
309
315
|
*/
|
|
310
316
|
runs() {
|
|
311
317
|
return new RunCollectionClient({
|
|
312
|
-
...this
|
|
318
|
+
...this.#subClientOptions(),
|
|
313
319
|
resourcePath: 'actor-runs',
|
|
314
320
|
});
|
|
315
321
|
}
|
|
@@ -336,7 +342,7 @@ export class ApifyClient {
|
|
|
336
342
|
parseArgument(id, resourceIdSchema);
|
|
337
343
|
return new RunClient({
|
|
338
344
|
id,
|
|
339
|
-
...this
|
|
345
|
+
...this.#subClientOptions(),
|
|
340
346
|
});
|
|
341
347
|
}
|
|
342
348
|
/**
|
|
@@ -348,7 +354,7 @@ export class ApifyClient {
|
|
|
348
354
|
* @see https://docs.apify.com/api/v2/actor-tasks-get
|
|
349
355
|
*/
|
|
350
356
|
tasks() {
|
|
351
|
-
return new TaskCollectionClient(this
|
|
357
|
+
return new TaskCollectionClient(this.#subClientOptions());
|
|
352
358
|
}
|
|
353
359
|
/**
|
|
354
360
|
* Returns a client for a specific Actor task.
|
|
@@ -369,7 +375,7 @@ export class ApifyClient {
|
|
|
369
375
|
parseArgument(id, resourceIdSchema);
|
|
370
376
|
return new TaskClient({
|
|
371
377
|
id,
|
|
372
|
-
...this
|
|
378
|
+
...this.#subClientOptions(),
|
|
373
379
|
});
|
|
374
380
|
}
|
|
375
381
|
/**
|
|
@@ -381,7 +387,7 @@ export class ApifyClient {
|
|
|
381
387
|
* @see https://docs.apify.com/api/v2/schedules-get
|
|
382
388
|
*/
|
|
383
389
|
schedules() {
|
|
384
|
-
return new ScheduleCollectionClient(this
|
|
390
|
+
return new ScheduleCollectionClient(this.#subClientOptions());
|
|
385
391
|
}
|
|
386
392
|
/**
|
|
387
393
|
* Returns a client for a specific schedule.
|
|
@@ -396,7 +402,7 @@ export class ApifyClient {
|
|
|
396
402
|
parseArgument(id, resourceIdSchema);
|
|
397
403
|
return new ScheduleClient({
|
|
398
404
|
id,
|
|
399
|
-
...this
|
|
405
|
+
...this.#subClientOptions(),
|
|
400
406
|
});
|
|
401
407
|
}
|
|
402
408
|
/**
|
|
@@ -412,7 +418,7 @@ export class ApifyClient {
|
|
|
412
418
|
parseArgument(id, resourceIdSchema);
|
|
413
419
|
return new UserClient({
|
|
414
420
|
id,
|
|
415
|
-
...this
|
|
421
|
+
...this.#subClientOptions(),
|
|
416
422
|
});
|
|
417
423
|
}
|
|
418
424
|
/**
|
|
@@ -424,7 +430,7 @@ export class ApifyClient {
|
|
|
424
430
|
* @see https://docs.apify.com/api/v2/webhooks-get
|
|
425
431
|
*/
|
|
426
432
|
webhooks() {
|
|
427
|
-
return new WebhookCollectionClient(this
|
|
433
|
+
return new WebhookCollectionClient(this.#subClientOptions());
|
|
428
434
|
}
|
|
429
435
|
/**
|
|
430
436
|
* Returns a client for a specific webhook.
|
|
@@ -439,7 +445,7 @@ export class ApifyClient {
|
|
|
439
445
|
parseArgument(id, resourceIdSchema);
|
|
440
446
|
return new WebhookClient({
|
|
441
447
|
id,
|
|
442
|
-
...this
|
|
448
|
+
...this.#subClientOptions(),
|
|
443
449
|
});
|
|
444
450
|
}
|
|
445
451
|
/**
|
|
@@ -451,7 +457,7 @@ export class ApifyClient {
|
|
|
451
457
|
* @see https://docs.apify.com/api/v2/webhook-dispatches-get
|
|
452
458
|
*/
|
|
453
459
|
webhookDispatches() {
|
|
454
|
-
return new WebhookDispatchCollectionClient(this
|
|
460
|
+
return new WebhookDispatchCollectionClient(this.#subClientOptions());
|
|
455
461
|
}
|
|
456
462
|
/**
|
|
457
463
|
* Returns a client for a specific webhook dispatch.
|
|
@@ -464,7 +470,7 @@ export class ApifyClient {
|
|
|
464
470
|
parseArgument(id, resourceIdSchema);
|
|
465
471
|
return new WebhookDispatchClient({
|
|
466
472
|
id,
|
|
467
|
-
...this
|
|
473
|
+
...this.#subClientOptions(),
|
|
468
474
|
});
|
|
469
475
|
}
|
|
470
476
|
/**
|
|
@@ -476,7 +482,7 @@ export class ApifyClient {
|
|
|
476
482
|
* @see https://docs.apify.com/api/v2/store-get
|
|
477
483
|
*/
|
|
478
484
|
store() {
|
|
479
|
-
return new StoreCollectionClient(this
|
|
485
|
+
return new StoreCollectionClient(this.#subClientOptions());
|
|
480
486
|
}
|
|
481
487
|
/**
|
|
482
488
|
* Sets a status message for the current Actor run.
|
|
@@ -30,15 +30,15 @@ export declare abstract class ApiClient {
|
|
|
30
30
|
httpClient: HttpClient;
|
|
31
31
|
params?: Record<string, unknown>;
|
|
32
32
|
constructor(options: ApiClientOptions);
|
|
33
|
-
protected
|
|
34
|
-
protected
|
|
35
|
-
protected
|
|
36
|
-
protected
|
|
37
|
-
protected
|
|
33
|
+
protected subResourceOptions<T>(moreOptions?: T): BaseOptions & T;
|
|
34
|
+
protected buildUrl(path?: string | string[]): string;
|
|
35
|
+
protected buildPublicUrl(path?: string | string[]): string;
|
|
36
|
+
protected buildParams<T>(endpointParams?: T): Record<string, unknown>;
|
|
37
|
+
protected toSafeId(id: string): string;
|
|
38
38
|
/**
|
|
39
39
|
* Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
|
|
40
40
|
*/
|
|
41
|
-
protected
|
|
41
|
+
protected listPaginatedFromCallback<T extends PaginationOptions, Data, R extends PaginatedResponse<Data>>(getPaginatedList: (options?: T) => Promise<R>, options?: T): AsyncIterable<Data> & Promise<R>;
|
|
42
42
|
}
|
|
43
43
|
export interface BaseOptions {
|
|
44
44
|
baseUrl: string;
|