apify-client 2.25.1-beta.8 → 2.26.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/dist/apify_api_error.js +6 -4
- package/dist/base/api_client.d.ts +16 -2
- package/dist/base/api_client.js +31 -6
- package/dist/base/resource_client.js +18 -10
- package/dist/bundle.js +2231 -1042
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.d.ts +21 -1
- package/dist/http_client.js +31 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/interceptors.js +19 -3
- package/dist/resource_clients/actor.d.ts +58 -1
- package/dist/resource_clients/actor.js +45 -0
- package/dist/resource_clients/actor_server.d.ts +143 -0
- package/dist/resource_clients/actor_server.js +193 -0
- package/dist/resource_clients/actor_version.d.ts +18 -0
- package/dist/resource_clients/build.d.ts +7 -0
- package/dist/resource_clients/build.js +1 -0
- package/dist/resource_clients/dataset.d.ts +9 -2
- package/dist/resource_clients/dataset.js +5 -2
- package/dist/resource_clients/key_value_store.d.ts +2 -1
- package/dist/resource_clients/key_value_store.js +8 -7
- package/dist/resource_clients/request_queue.js +5 -5
- package/dist/resource_clients/run.d.ts +9 -0
- package/dist/resource_clients/run.js +4 -0
- package/dist/resource_clients/user.d.ts +5 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +68 -0
- package/package.json +33 -33
package/dist/http_client.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare class HttpClient {
|
|
|
59
59
|
*/
|
|
60
60
|
private _isNetworkError;
|
|
61
61
|
/**
|
|
62
|
-
* We retry 429 (rate limit) and 500
|
|
62
|
+
* We retry 429 (rate limit) and 500+, or the statuses in `config.retryStatusCodes` when it is set.
|
|
63
63
|
* For status codes 300-499 (except 429) we do not retry the request,
|
|
64
64
|
* because it's probably caused by invalid url (redirect 3xx) or invalid user input (4xx).
|
|
65
65
|
*/
|
|
@@ -70,6 +70,26 @@ export interface ApifyRequestConfig extends AxiosRequestConfig {
|
|
|
70
70
|
stringifyFunctions?: boolean;
|
|
71
71
|
forceBuffer?: boolean;
|
|
72
72
|
doNotRetryTimeouts?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Set to `false` to resolve to the error response once the retries are spent, instead of throwing `ApifyApiError`.
|
|
75
|
+
* @since Added in 2.26.0
|
|
76
|
+
*/
|
|
77
|
+
throwOnErrorStatus?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Status codes to retry, replacing the default of 429 and 500+.
|
|
80
|
+
* @since Added in 2.26.0
|
|
81
|
+
*/
|
|
82
|
+
retryStatusCodes?: number[];
|
|
83
|
+
/**
|
|
84
|
+
* Set to `false` to not retry network errors, timeouts and unparsable response bodies.
|
|
85
|
+
* @since Added in 2.26.0
|
|
86
|
+
*/
|
|
87
|
+
retryTransportErrors?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Set to `true` to send the request body uncompressed.
|
|
90
|
+
* @since Added in 2.26.0
|
|
91
|
+
*/
|
|
92
|
+
doNotCompress?: boolean;
|
|
73
93
|
}
|
|
74
94
|
export interface ApifyResponse<T = any> extends AxiosResponse<T> {
|
|
75
95
|
config: ApifyRequestConfig & InternalAxiosRequestConfig;
|
package/dist/http_client.js
CHANGED
|
@@ -9,6 +9,12 @@ const apify_api_error_1 = require("./apify_api_error");
|
|
|
9
9
|
const interceptors_1 = require("./interceptors");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const { version } = (0, utils_1.getVersionData)();
|
|
12
|
+
async function readStreamToBuffer(stream) {
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const chunk of stream)
|
|
15
|
+
chunks.push(chunk);
|
|
16
|
+
return Buffer.concat(chunks);
|
|
17
|
+
}
|
|
12
18
|
const RATE_LIMIT_EXCEEDED_STATUS_CODE = 429;
|
|
13
19
|
class HttpClient {
|
|
14
20
|
stats;
|
|
@@ -151,6 +157,7 @@ class HttpClient {
|
|
|
151
157
|
const makeRequest = async (stopTrying, attempt) => {
|
|
152
158
|
this.stats.requests++;
|
|
153
159
|
let response;
|
|
160
|
+
let returnErrorResponse = false;
|
|
154
161
|
const requestIsStream = (0, utils_1.isStream)(config.data);
|
|
155
162
|
try {
|
|
156
163
|
if (requestIsStream) {
|
|
@@ -164,15 +171,30 @@ class HttpClient {
|
|
|
164
171
|
response = await this.axios.request(config);
|
|
165
172
|
if (this._isStatusOk(response.status))
|
|
166
173
|
return response;
|
|
174
|
+
// A caller that takes error responses gets the last one, once the retries are spent, as it is.
|
|
175
|
+
returnErrorResponse =
|
|
176
|
+
config.throwOnErrorStatus === false &&
|
|
177
|
+
(requestIsStream ||
|
|
178
|
+
attempt > this.maxRetries ||
|
|
179
|
+
!this._isStatusCodeRetryable(response.status, config));
|
|
180
|
+
// A failed request with `responseType: 'stream'` carries the API error body in the stream. Read
|
|
181
|
+
// it so that `ApifyApiError` can parse it like any other error body. A body that cannot be read
|
|
182
|
+
// leaves the error without a message, which beats losing the status code to a stream error.
|
|
183
|
+
if ((0, utils_1.isStream)(response.data) && !returnErrorResponse) {
|
|
184
|
+
response.data = await readStreamToBuffer(response.data).catch(() => undefined);
|
|
185
|
+
}
|
|
167
186
|
}
|
|
168
187
|
catch (err) {
|
|
169
188
|
return (0, utils_1.cast)(this._handleRequestError(err, config, stopTrying));
|
|
170
189
|
}
|
|
171
|
-
|
|
190
|
+
// The statistics track the API's rate limits, so a call that takes error responses keeps its 429s out.
|
|
191
|
+
if (response.status === RATE_LIMIT_EXCEEDED_STATUS_CODE && config.throwOnErrorStatus !== false) {
|
|
172
192
|
this.stats.addRateLimitError(attempt);
|
|
173
193
|
}
|
|
194
|
+
if (returnErrorResponse)
|
|
195
|
+
return response;
|
|
174
196
|
const apiError = new apify_api_error_1.ApifyApiError(response, attempt);
|
|
175
|
-
if (this._isStatusCodeRetryable(response.status)) {
|
|
197
|
+
if (this._isStatusCodeRetryable(response.status, config)) {
|
|
176
198
|
if (requestIsStream) {
|
|
177
199
|
this._informAboutStreamNoRetry();
|
|
178
200
|
}
|
|
@@ -197,6 +219,9 @@ class HttpClient {
|
|
|
197
219
|
if (this._isTimeoutError(err) && config.doNotRetryTimeouts) {
|
|
198
220
|
return stopTrying(err);
|
|
199
221
|
}
|
|
222
|
+
if (config.retryTransportErrors === false) {
|
|
223
|
+
return stopTrying(err);
|
|
224
|
+
}
|
|
200
225
|
if (this._isRetryableError(err)) {
|
|
201
226
|
if ((0, utils_1.isStream)(config.data)) {
|
|
202
227
|
this._informAboutStreamNoRetry();
|
|
@@ -242,11 +267,13 @@ class HttpClient {
|
|
|
242
267
|
return hasRequest && hasConfig;
|
|
243
268
|
}
|
|
244
269
|
/**
|
|
245
|
-
* We retry 429 (rate limit) and 500
|
|
270
|
+
* We retry 429 (rate limit) and 500+, or the statuses in `config.retryStatusCodes` when it is set.
|
|
246
271
|
* For status codes 300-499 (except 429) we do not retry the request,
|
|
247
272
|
* because it's probably caused by invalid url (redirect 3xx) or invalid user input (4xx).
|
|
248
273
|
*/
|
|
249
|
-
_isStatusCodeRetryable(statusCode) {
|
|
274
|
+
_isStatusCodeRetryable(statusCode, config) {
|
|
275
|
+
if (config.retryStatusCodes)
|
|
276
|
+
return config.retryStatusCodes.includes(statusCode);
|
|
250
277
|
const isRateLimitError = statusCode === RATE_LIMIT_EXCEEDED_STATUS_CODE;
|
|
251
278
|
const isInternalError = statusCode >= 500;
|
|
252
279
|
return isRateLimitError || isInternalError;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './apify_client';
|
|
2
2
|
export * from './resource_clients/actor';
|
|
3
|
+
export * from './resource_clients/actor_server';
|
|
3
4
|
export * from './resource_clients/actor_collection';
|
|
4
5
|
export * from './resource_clients/actor_env_var';
|
|
5
6
|
export * from './resource_clients/actor_env_var_collection';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.InvalidResponseBodyError = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./apify_client"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./resource_clients/actor"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./resource_clients/actor_server"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./resource_clients/actor_collection"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./resource_clients/actor_env_var"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./resource_clients/actor_env_var_collection"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ export const ActorCollectionClient = mod.ActorCollectionClient;
|
|
|
6
6
|
export const ActorEnvVarClient = mod.ActorEnvVarClient;
|
|
7
7
|
export const ActorEnvVarCollectionClient = mod.ActorEnvVarCollectionClient;
|
|
8
8
|
export const ActorListSortBy = mod.ActorListSortBy;
|
|
9
|
+
export const ActorServerClient = mod.ActorServerClient;
|
|
9
10
|
export const ActorSourceType = mod.ActorSourceType;
|
|
10
11
|
export const ActorVersionClient = mod.ActorVersionClient;
|
|
11
12
|
export const ActorVersionCollectionClient = mod.ActorVersionCollectionClient;
|
package/dist/interceptors.js
CHANGED
|
@@ -35,9 +35,9 @@ function serializeRequest(config) {
|
|
|
35
35
|
// it's a small price to pay. The axios default transform does a lot
|
|
36
36
|
// of body type checks and we would have to copy all of them to the resource clients.
|
|
37
37
|
if (config.stringifyFunctions) {
|
|
38
|
-
const contentTypeHeader = config
|
|
38
|
+
const contentTypeHeader = getHeader(config, 'content-type');
|
|
39
39
|
try {
|
|
40
|
-
const
|
|
40
|
+
const type = contentTypeHeader ? content_type_1.default.parse(contentTypeHeader).type : undefined;
|
|
41
41
|
if (type === 'application/json' && typeof config.data === 'object') {
|
|
42
42
|
config.data = stringifyWithFunctions(config.data);
|
|
43
43
|
}
|
|
@@ -69,8 +69,21 @@ function stringifyWithFunctions(obj) {
|
|
|
69
69
|
return typeof value === 'function' ? value.toString() : value;
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Reads a request header regardless of the casing it was set with, since HTTP header names are case-insensitive
|
|
74
|
+
* while the config keeps whatever casing the caller used.
|
|
75
|
+
*/
|
|
76
|
+
function getHeader(config, name) {
|
|
77
|
+
const wanted = name.toLowerCase();
|
|
78
|
+
const key = Object.keys(config.headers ?? {}).find((candidate) => candidate.toLowerCase() === wanted);
|
|
79
|
+
const value = key === undefined ? undefined : config.headers?.[key];
|
|
80
|
+
return typeof value === 'string' ? value : undefined;
|
|
81
|
+
}
|
|
72
82
|
async function maybeCompressRequest(config) {
|
|
73
|
-
|
|
83
|
+
// A caller-supplied encoding means the body is already encoded and the header describes it, so leave both alone.
|
|
84
|
+
if (config.doNotCompress || getHeader(config, 'content-encoding'))
|
|
85
|
+
return config;
|
|
86
|
+
if (!(0, utils_1.isCompressibleContentType)(getHeader(config, 'content-type')))
|
|
74
87
|
return config;
|
|
75
88
|
const maybeCompressed = await (0, utils_1.maybeCompressValue)(config.data);
|
|
76
89
|
if (maybeCompressed) {
|
|
@@ -98,6 +111,9 @@ function parseResponseData(response) {
|
|
|
98
111
|
response.data = (0, body_parser_1.maybeParseBody)(response.data, contentTypeHeader);
|
|
99
112
|
}
|
|
100
113
|
catch (err) {
|
|
114
|
+
// A caller that takes error responses gets an unparsable error body as the raw bytes.
|
|
115
|
+
if (response.status >= 300 && response.config.throwOnErrorStatus === false)
|
|
116
|
+
return response;
|
|
101
117
|
throw new InvalidResponseBodyError(response, err);
|
|
102
118
|
}
|
|
103
119
|
return response;
|
|
@@ -3,6 +3,7 @@ import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify
|
|
|
3
3
|
import { Log } from '@apify/log';
|
|
4
4
|
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
5
5
|
import { ResourceClient } from '../base/resource_client';
|
|
6
|
+
import { ActorServerClient } from './actor_server';
|
|
6
7
|
import type { ActorVersion } from './actor_version';
|
|
7
8
|
import { ActorVersionClient } from './actor_version';
|
|
8
9
|
import { ActorVersionCollectionClient } from './actor_version_collection';
|
|
@@ -35,6 +36,7 @@ import type { ValueOf } from 'type-fest';
|
|
|
35
36
|
* @see https://docs.apify.com/platform/actors
|
|
36
37
|
*/
|
|
37
38
|
export declare class ActorClient extends ResourceClient {
|
|
39
|
+
private _serverClient?;
|
|
38
40
|
/**
|
|
39
41
|
* @hidden
|
|
40
42
|
*/
|
|
@@ -275,6 +277,36 @@ export declare class ActorClient extends ResourceClient {
|
|
|
275
277
|
* @see https://docs.apify.com/api/v2/act-webhooks-get
|
|
276
278
|
*/
|
|
277
279
|
webhooks(): WebhookCollectionClient;
|
|
280
|
+
/**
|
|
281
|
+
* Returns a client for the server interface of this Actor.
|
|
282
|
+
*
|
|
283
|
+
* A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
|
|
284
|
+
* each call. Server Actors were formerly called Actor Standby. Every call returns the same client, so the server
|
|
285
|
+
* URL it fetches is reused.
|
|
286
|
+
*
|
|
287
|
+
* @returns The client for the server interface of this Actor
|
|
288
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
289
|
+
* @since Added in 2.26.0
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```javascript
|
|
293
|
+
* const response = await client.actor('username/actor-name').server().request('/search', {
|
|
294
|
+
* params: { q: 'apify' },
|
|
295
|
+
* });
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
server(): ActorServerClient;
|
|
299
|
+
/**
|
|
300
|
+
* Returns a client for the server interface of this Actor in Standby mode.
|
|
301
|
+
*
|
|
302
|
+
* Named after Actor Standby, the former name of Server Actors.
|
|
303
|
+
*
|
|
304
|
+
* @deprecated Use {@link server} instead. Will be removed in v4.
|
|
305
|
+
* @returns The client for the server interface of this Actor
|
|
306
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
307
|
+
* @since Added in 2.26.0
|
|
308
|
+
*/
|
|
309
|
+
standby(): ActorServerClient;
|
|
278
310
|
}
|
|
279
311
|
/**
|
|
280
312
|
* Represents an Actor in the Apify platform.
|
|
@@ -347,6 +379,11 @@ export interface Actor {
|
|
|
347
379
|
actorStandby?: ActorStandby & {
|
|
348
380
|
isEnabled: boolean;
|
|
349
381
|
};
|
|
382
|
+
/**
|
|
383
|
+
* URL of the Actor's server interface, or `null` if the Actor is not a Server Actor
|
|
384
|
+
* @since Added in 2.26.0
|
|
385
|
+
*/
|
|
386
|
+
standbyUrl?: string | null;
|
|
350
387
|
/**
|
|
351
388
|
* Permission level of the Actor on Apify platform
|
|
352
389
|
* @since Added in 2.21.0
|
|
@@ -413,7 +450,7 @@ export interface ActorTaggedBuild {
|
|
|
413
450
|
/**
|
|
414
451
|
* Fields that can be updated when modifying an Actor.
|
|
415
452
|
*/
|
|
416
|
-
export type ActorUpdateOptions = Partial<Pick<Actor, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'restartOnError' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds'>>;
|
|
453
|
+
export type ActorUpdateOptions = Partial<Pick<Actor, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'restartOnError' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds' | 'pricingInfos' | 'exampleRunInput'>>;
|
|
417
454
|
/**
|
|
418
455
|
* Configuration for Actor standby mode.
|
|
419
456
|
*
|
|
@@ -616,6 +653,20 @@ export interface ActorRun extends ActorRunListItem {
|
|
|
616
653
|
* @since Added in 2.22.3
|
|
617
654
|
*/
|
|
618
655
|
storageIds?: ActorRunStorageIds;
|
|
656
|
+
/**
|
|
657
|
+
* Server Actor deployment of this run, `null` for runs not started by a Server Actor request.
|
|
658
|
+
* @since Added in 2.26.0
|
|
659
|
+
*/
|
|
660
|
+
standby?: ActorRunStandby | null;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Which pool the Server Actor run serves. `SINGLE_TENANT` is a private instance in the caller's account.
|
|
664
|
+
* The `MULTI_TENANT_*` pools run in the Actor owner's account and serve many callers;
|
|
665
|
+
* charges in them require a `requestId`.
|
|
666
|
+
* @since Added in 2.26.0
|
|
667
|
+
*/
|
|
668
|
+
export interface ActorRunStandby {
|
|
669
|
+
deployment: 'SINGLE_TENANT' | 'MULTI_TENANT_OWNER_PAID' | 'MULTI_TENANT_FREE_USERS' | 'MULTI_TENANT_PAYING_USERS';
|
|
619
670
|
}
|
|
620
671
|
/**
|
|
621
672
|
* Resource usage metrics for an Actor run.
|
|
@@ -773,6 +824,12 @@ export interface ActorDefinition {
|
|
|
773
824
|
minMemoryMbytes?: number;
|
|
774
825
|
maxMemoryMbytes?: number;
|
|
775
826
|
usesStandbyMode?: boolean;
|
|
827
|
+
/**
|
|
828
|
+
* OpenAPI specification of the Actor's web server.
|
|
829
|
+
* @see https://docs.apify.com/platform/actors/development/actor-definition/web-server-schema
|
|
830
|
+
* @since Added in 2.26.0
|
|
831
|
+
*/
|
|
832
|
+
webServerSchema?: Record<string, unknown>;
|
|
776
833
|
}
|
|
777
834
|
interface CommonActorPricingInfo {
|
|
778
835
|
/** In [0, 1], fraction of pricePerUnitUsd that goes to Apify */
|
|
@@ -7,6 +7,7 @@ const consts_1 = require("@apify/consts");
|
|
|
7
7
|
const log_1 = require("@apify/log");
|
|
8
8
|
const resource_client_1 = require("../base/resource_client");
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
|
+
const actor_server_1 = require("./actor_server");
|
|
10
11
|
const actor_version_1 = require("./actor_version");
|
|
11
12
|
const actor_version_collection_1 = require("./actor_version_collection");
|
|
12
13
|
const build_1 = require("./build");
|
|
@@ -35,6 +36,7 @@ const webhook_collection_1 = require("./webhook_collection");
|
|
|
35
36
|
* @see https://docs.apify.com/platform/actors
|
|
36
37
|
*/
|
|
37
38
|
class ActorClient extends resource_client_1.ResourceClient {
|
|
39
|
+
_serverClient;
|
|
38
40
|
/**
|
|
39
41
|
* @hidden
|
|
40
42
|
*/
|
|
@@ -441,5 +443,48 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
441
443
|
webhooks() {
|
|
442
444
|
return new webhook_collection_1.WebhookCollectionClient(this._subResourceOptions());
|
|
443
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Returns a client for the server interface of this Actor.
|
|
448
|
+
*
|
|
449
|
+
* A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
|
|
450
|
+
* each call. Server Actors were formerly called Actor Standby. Every call returns the same client, so the server
|
|
451
|
+
* URL it fetches is reused.
|
|
452
|
+
*
|
|
453
|
+
* @returns The client for the server interface of this Actor
|
|
454
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
455
|
+
* @since Added in 2.26.0
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```javascript
|
|
459
|
+
* const response = await client.actor('username/actor-name').server().request('/search', {
|
|
460
|
+
* params: { q: 'apify' },
|
|
461
|
+
* });
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
server() {
|
|
465
|
+
this._serverClient ??= new actor_server_1.ActorServerClient({
|
|
466
|
+
baseUrl: this.baseUrl,
|
|
467
|
+
publicBaseUrl: this.publicBaseUrl,
|
|
468
|
+
apifyClient: this.apifyClient,
|
|
469
|
+
httpClient: this.httpClient,
|
|
470
|
+
id: this.id,
|
|
471
|
+
params: this.params,
|
|
472
|
+
});
|
|
473
|
+
return this._serverClient;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Returns a client for the server interface of this Actor in Standby mode.
|
|
477
|
+
*
|
|
478
|
+
* Named after Actor Standby, the former name of Server Actors.
|
|
479
|
+
*
|
|
480
|
+
* @deprecated Use {@link server} instead. Will be removed in v4.
|
|
481
|
+
* @returns The client for the server interface of this Actor
|
|
482
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
483
|
+
* @since Added in 2.26.0
|
|
484
|
+
*/
|
|
485
|
+
standby() {
|
|
486
|
+
this.httpClient.logger.deprecated('`standby()` is deprecated and will be removed in v4. Use `server()` instead.');
|
|
487
|
+
return this.server();
|
|
488
|
+
}
|
|
444
489
|
}
|
|
445
490
|
exports.ActorClient = ActorClient;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
3
|
+
import { ResourceClient } from '../base/resource_client';
|
|
4
|
+
import type { ApifyResponse } from '../http_client';
|
|
5
|
+
/**
|
|
6
|
+
* Client for the server interface of a specific Actor.
|
|
7
|
+
*
|
|
8
|
+
* Provides methods to work with the web server of a Server Actor, such as sending it requests or getting its OpenAPI
|
|
9
|
+
* specification. Get an instance with {@link ActorClient.server}.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```javascript
|
|
13
|
+
* const client = new ApifyClient({ token: 'my-token' });
|
|
14
|
+
* const actorServerClient = client.actor('username/actor-name').server();
|
|
15
|
+
*
|
|
16
|
+
* const response = await actorServerClient.request('/search', { params: { q: 'apify' } });
|
|
17
|
+
* console.log(response.data);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
21
|
+
* @since Added in 2.26.0
|
|
22
|
+
*/
|
|
23
|
+
export declare class ActorServerClient extends ResourceClient {
|
|
24
|
+
/**
|
|
25
|
+
* The server URL. Getting it takes an API call for the Actor, so it's cached for {@link getUrl} and
|
|
26
|
+
* {@link request}. It's pending while the first lookup runs, so concurrent first calls share one API request.
|
|
27
|
+
*/
|
|
28
|
+
private _serverUrl?;
|
|
29
|
+
/**
|
|
30
|
+
* @hidden
|
|
31
|
+
*/
|
|
32
|
+
constructor(options: ApiClientSubResourceOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Returns the URL of the Actor's server.
|
|
35
|
+
*
|
|
36
|
+
* The URL is the Actor's `standbyUrl`, fetched from the API by the first call of this method or
|
|
37
|
+
* {@link getOpenApiSpec} and reused by later calls on this client. Use it to call the server with another HTTP
|
|
38
|
+
* client, for example one generated from the server's OpenAPI specification.
|
|
39
|
+
*
|
|
40
|
+
* @returns The URL of the Actor's server
|
|
41
|
+
* @throws When the Actor does not exist or is not a Server Actor.
|
|
42
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
43
|
+
*/
|
|
44
|
+
getUrl(): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the OpenAPI specification of the Actor's server.
|
|
47
|
+
*
|
|
48
|
+
* The specification is the web server schema from the Actor's definition, taken from the build that serves the
|
|
49
|
+
* server interface: the build set in `actorStandby.build`, or `latest` if none is set. Use it to generate an HTTP
|
|
50
|
+
* client for the server, and point that client at the URL returned by {@link getUrl}.
|
|
51
|
+
*
|
|
52
|
+
* @returns The OpenAPI specification of the Actor's server, or `undefined` if the Actor's definition doesn't
|
|
53
|
+
* include one
|
|
54
|
+
* @throws When the Actor does not exist or is not a Server Actor, or the build that serves its server interface
|
|
55
|
+
* doesn't exist.
|
|
56
|
+
* @see https://docs.apify.com/platform/actors/development/actor-definition/web-server-schema
|
|
57
|
+
*/
|
|
58
|
+
getOpenApiSpec(): Promise<Record<string, unknown> | undefined>;
|
|
59
|
+
/**
|
|
60
|
+
* Sends an HTTP request to the Actor's server.
|
|
61
|
+
*
|
|
62
|
+
* The request goes to the URL returned by {@link getUrl} and carries the client's token in the
|
|
63
|
+
* `X-Apify-Authorization` header, which the platform consumes, so it never reaches the Actor's code. Headers you
|
|
64
|
+
* pass, `Authorization` included, reach the Actor's server as they are. The first request to an idle Actor waits
|
|
65
|
+
* for the platform to start a server run, which is why the timeout defaults to the client's longest one.
|
|
66
|
+
*
|
|
67
|
+
* The method resolves to any response of the server, error statuses included. A rate-limit (429) or Service
|
|
68
|
+
* Unavailable (503) response is retried with the client's retry settings, and the last one is returned once the
|
|
69
|
+
* retries run out. The Actor's code can return these statuses too, and then it gets the request again. Network
|
|
70
|
+
* errors and timeouts are not retried, since the Actor may have already handled the request. A redirect is
|
|
71
|
+
* returned as it is, since following it would send the token to a host the Actor's code picked. A browser follows
|
|
72
|
+
* redirects itself, though, so there the token goes with a redirect. Request bodies are sent uncompressed, since
|
|
73
|
+
* the Actor's server may not decode a compressed body.
|
|
74
|
+
*
|
|
75
|
+
* @template T - Type of the parsed response body.
|
|
76
|
+
* @param path - The path on the Actor's server, for example `/search`. It is always resolved against the server
|
|
77
|
+
* URL, so the request, and the token with it, can't be sent to another host. Pass the query in `params`. A
|
|
78
|
+
* fragment (`#...`) is dropped, since it's never sent to the server.
|
|
79
|
+
* @param options - Request options
|
|
80
|
+
* @param options.method - HTTP method of the request. Default is `'GET'`.
|
|
81
|
+
* @param options.params - Query parameters of the request, converted the same way as for API calls.
|
|
82
|
+
* @param options.headers - Additional headers of the request.
|
|
83
|
+
* @param options.data - Request body, serialized the same way as for API calls: a plain object or array is sent
|
|
84
|
+
* as JSON, and a string or binary value as it is.
|
|
85
|
+
* @param options.parentRequestId - The `X-Actor-Request-ID` header of the request your Server Actor is handling,
|
|
86
|
+
* sent on as the same header so the called Actor charges at that request's pricing tier.
|
|
87
|
+
* @param options.responseType - How to return the response body: `'parsed'` by its content type, `'buffer'` as
|
|
88
|
+
* raw bytes, or `'stream'` as a Readable stream with the body unread. A stream holds its connection open until
|
|
89
|
+
* you consume it to the end or destroy it. Node.js only. Default is `'parsed'`.
|
|
90
|
+
* @param options.timeoutSecs - Timeout for the HTTP request in seconds. Default is the client's timeout.
|
|
91
|
+
* @returns The response of the Actor's server, with the body in the form `responseType` asks for. An error
|
|
92
|
+
* response whose body doesn't parse as its content type comes with the raw bytes in `data`.
|
|
93
|
+
* @throws When the Actor does not exist or is not a Server Actor, or the request fails or times out.
|
|
94
|
+
* @throws {InvalidResponseBodyError} When a success response's body doesn't parse as its content type, with
|
|
95
|
+
* `responseType: 'parsed'`.
|
|
96
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
97
|
+
*/
|
|
98
|
+
request<T = any>(path?: string, options?: ActorServerRequestOptions & {
|
|
99
|
+
responseType?: 'parsed';
|
|
100
|
+
}): Promise<ApifyResponse<T>>;
|
|
101
|
+
request(path: string, options: ActorServerRequestOptions & {
|
|
102
|
+
responseType: 'buffer';
|
|
103
|
+
}): Promise<ApifyResponse<Buffer>>;
|
|
104
|
+
request(path: string, options: ActorServerRequestOptions & {
|
|
105
|
+
responseType: 'stream';
|
|
106
|
+
}): Promise<ApifyResponse<Readable>>;
|
|
107
|
+
request(path?: string, options?: ActorServerRequestOptions): Promise<ApifyResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* Fetches the Actor, checks that it is a Server Actor, and caches its server URL.
|
|
110
|
+
*/
|
|
111
|
+
private _getServerActor;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Options of {@link ActorServerClient.request}.
|
|
115
|
+
* @since Added in 2.26.0
|
|
116
|
+
*/
|
|
117
|
+
export interface ActorServerRequestOptions {
|
|
118
|
+
/** HTTP method of the request. @default 'GET' */
|
|
119
|
+
method?: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
|
120
|
+
/** Query parameters of the request, converted the same way as for API calls. */
|
|
121
|
+
params?: Record<string, unknown>;
|
|
122
|
+
/** Additional headers of the request. */
|
|
123
|
+
headers?: Record<string, string>;
|
|
124
|
+
/**
|
|
125
|
+
* Request body, serialized the same way as for API calls: a plain object or array is sent as JSON, and a string
|
|
126
|
+
* or binary value as it is.
|
|
127
|
+
*/
|
|
128
|
+
data?: unknown;
|
|
129
|
+
/**
|
|
130
|
+
* The `X-Actor-Request-ID` header of the request your Server Actor is handling. It's sent on as the same header,
|
|
131
|
+
* so the called Actor charges at that request's pricing tier.
|
|
132
|
+
* @see https://docs.apify.com/platform/actors/development/programming-interface/standby#compose-server-actors
|
|
133
|
+
*/
|
|
134
|
+
parentRequestId?: string;
|
|
135
|
+
/**
|
|
136
|
+
* How to return the response body: `'parsed'` by its content type, `'buffer'` as raw bytes, or `'stream'` as a
|
|
137
|
+
* Readable stream with the body unread. Node.js only.
|
|
138
|
+
* @default 'parsed'
|
|
139
|
+
*/
|
|
140
|
+
responseType?: 'parsed' | 'buffer' | 'stream';
|
|
141
|
+
/** Timeout for the HTTP request in seconds. Default is the client's timeout. */
|
|
142
|
+
timeoutSecs?: number;
|
|
143
|
+
}
|