apify-client 3.0.0-beta.1 → 3.0.0-beta.100
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 +21 -5
- package/dist/apify_api_error.d.ts +64 -22
- package/dist/apify_api_error.js +100 -30
- package/dist/apify_client.d.ts +150 -35
- package/dist/apify_client.js +198 -118
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/base/api_client.d.ts +9 -9
- package/dist/base/api_client.js +41 -45
- package/dist/base/resource_client.d.ts +24 -10
- package/dist/base/resource_client.js +78 -48
- package/dist/base/resource_collection_client.d.ts +15 -6
- package/dist/base/resource_collection_client.js +40 -21
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +20 -32
- package/dist/bundle.js +47 -52
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +3363 -1185
- package/dist/generated/api.js +1 -2
- package/dist/generated/schemas.d.ts +8146 -0
- package/dist/generated/schemas.js +1866 -0
- package/dist/http_clients/axios.d.ts +61 -0
- package/dist/http_clients/axios.js +119 -0
- package/dist/http_clients/base.d.ts +391 -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 +8 -0
- package/dist/http_compressors/index.js +3 -0
- package/dist/http_compressors/resolve.d.ts +24 -0
- package/dist/http_compressors/resolve.js +30 -0
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +38 -32
- package/dist/index.js +36 -36
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +196 -278
- package/dist/models.js +14 -15
- package/dist/resource_clients/actor.d.ts +115 -45
- package/dist/resource_clients/actor.js +187 -116
- package/dist/resource_clients/actor_collection.d.ts +21 -17
- package/dist/resource_clients/actor_collection.js +26 -21
- package/dist/resource_clients/actor_env_var.d.ts +13 -6
- package/dist/resource_clients/actor_env_var.js +21 -14
- package/dist/resource_clients/actor_env_var_collection.d.ts +18 -22
- package/dist/resource_clients/actor_env_var_collection.js +23 -20
- package/dist/resource_clients/actor_server.d.ts +149 -0
- package/dist/resource_clients/actor_server.js +199 -0
- package/dist/resource_clients/actor_version.d.ts +30 -10
- package/dist/resource_clients/actor_version.js +29 -23
- package/dist/resource_clients/actor_version_collection.d.ts +20 -21
- package/dist/resource_clients/actor_version_collection.js +25 -20
- package/dist/resource_clients/build.d.ts +24 -11
- package/dist/resource_clients/build.js +43 -26
- package/dist/resource_clients/build_collection.d.ts +10 -8
- package/dist/resource_clients/build_collection.js +13 -13
- package/dist/resource_clients/dataset.d.ts +87 -40
- package/dist/resource_clients/dataset.js +159 -175
- package/dist/resource_clients/dataset_collection.d.ts +13 -9
- package/dist/resource_clients/dataset_collection.js +29 -21
- package/dist/resource_clients/key_value_store.d.ts +110 -28
- package/dist/resource_clients/key_value_store.js +177 -99
- package/dist/resource_clients/key_value_store_collection.d.ts +13 -9
- package/dist/resource_clients/key_value_store_collection.js +29 -21
- package/dist/resource_clients/log.d.ts +42 -23
- package/dist/resource_clients/log.js +156 -85
- package/dist/resource_clients/request_queue.d.ts +77 -38
- package/dist/resource_clients/request_queue.js +251 -172
- package/dist/resource_clients/request_queue_collection.d.ts +12 -8
- package/dist/resource_clients/request_queue_collection.js +23 -20
- package/dist/resource_clients/run.d.ts +134 -34
- package/dist/resource_clients/run.js +225 -84
- package/dist/resource_clients/run_collection.d.ts +8 -6
- package/dist/resource_clients/run_collection.js +18 -18
- package/dist/resource_clients/schedule.d.ts +20 -11
- package/dist/resource_clients/schedule.js +36 -30
- package/dist/resource_clients/schedule_collection.d.ts +10 -6
- package/dist/resource_clients/schedule_collection.js +20 -17
- package/dist/resource_clients/store_collection.d.ts +9 -7
- package/dist/resource_clients/store_collection.js +18 -18
- package/dist/resource_clients/task.d.ts +44 -21
- package/dist/resource_clients/task.js +116 -86
- package/dist/resource_clients/task_collection.d.ts +13 -9
- package/dist/resource_clients/task_collection.js +19 -16
- package/dist/resource_clients/user.d.ts +22 -13
- package/dist/resource_clients/user.js +46 -47
- package/dist/resource_clients/webhook.d.ts +21 -12
- package/dist/resource_clients/webhook.js +35 -30
- package/dist/resource_clients/webhook_collection.d.ts +11 -7
- package/dist/resource_clients/webhook_collection.js +20 -17
- package/dist/resource_clients/webhook_dispatch.d.ts +9 -6
- package/dist/resource_clients/webhook_dispatch.js +11 -10
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +7 -5
- package/dist/resource_clients/webhook_dispatch_collection.js +13 -13
- package/dist/response_validation_error.d.ts +27 -0
- package/dist/response_validation_error.js +38 -0
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +87 -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 +381 -0
- package/dist/schemas.js +37 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +7 -11
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +99 -70
- package/dist/utils.js +251 -229
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +48 -47
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -157
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -260
- package/dist/index.mjs +0 -42
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -110
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ApifyClientError } from '../apify_client_error.js';
|
|
3
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
+
import { mergeHeaders } from '../http_clients/base.js';
|
|
5
|
+
import { compressionSchema, resolveCompressor } from '../http_compressors/resolve.js';
|
|
6
|
+
import * as schemas from '../schemas.js';
|
|
7
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
8
|
+
import { runtime } from '#runtime';
|
|
9
|
+
import { parseArgument, parseResponse } from '../utils.js';
|
|
10
|
+
import { BuildClient } from './build.js';
|
|
11
|
+
import { BuildCollectionClient } from './build_collection.js';
|
|
12
|
+
/**
|
|
13
|
+
* Statuses a server request is retried on. The platform answers with them when it can't pass a request to a server
|
|
14
|
+
* run, so a retry usually doesn't run the Actor's code again. An Actor that returns one itself gets the request again.
|
|
15
|
+
*/
|
|
16
|
+
const SERVER_RETRY_STATUS_CODES = [429, 503];
|
|
17
|
+
const BUILD_NUMBER_PATTERN = /^(\d+)\.(\d+)\.(\d+)$/;
|
|
18
|
+
/**
|
|
19
|
+
* Splits a build number like `0.1.23` into its version and sequence number, or returns `undefined` for anything else.
|
|
20
|
+
*/
|
|
21
|
+
function parseBuildNumber(buildNumber) {
|
|
22
|
+
const match = BUILD_NUMBER_PATTERN.exec(buildNumber ?? '');
|
|
23
|
+
if (!match)
|
|
24
|
+
return undefined;
|
|
25
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether `buildNumber` belongs to the same version as `target` and comes before it. Builds are listed newest
|
|
29
|
+
* first and the sequence numbers of a version grow over time, so meeting such a build means the target doesn't exist.
|
|
30
|
+
*/
|
|
31
|
+
function isOlderBuild(buildNumber, target) {
|
|
32
|
+
const parsed = parseBuildNumber(buildNumber);
|
|
33
|
+
return parsed !== undefined && parsed[0] === target[0] && parsed[1] === target[1] && parsed[2] < target[2];
|
|
34
|
+
}
|
|
35
|
+
const requestOptionsSchema = z.strictObject({
|
|
36
|
+
method: z
|
|
37
|
+
.enum(['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'])
|
|
38
|
+
.optional(),
|
|
39
|
+
params: z.record(z.string(), z.unknown()).optional(),
|
|
40
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
41
|
+
data: z.unknown().optional(),
|
|
42
|
+
parentRequestId: z.string().optional(),
|
|
43
|
+
compression: compressionSchema.optional(),
|
|
44
|
+
responseType: z.enum(['parsed', 'buffer', 'stream']).optional(),
|
|
45
|
+
...timeoutOptionsShape,
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Client for the server interface of a specific Actor.
|
|
49
|
+
*
|
|
50
|
+
* Provides methods to work with the web server of a Server Actor, such as sending it requests or getting its OpenAPI
|
|
51
|
+
* specification. Get an instance with {@link ActorClient.server}.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```javascript
|
|
55
|
+
* const client = new ApifyClient({ token: 'my-token' });
|
|
56
|
+
* const actorServerClient = client.actor('username/actor-name').server();
|
|
57
|
+
*
|
|
58
|
+
* const response = await actorServerClient.request('/search', { params: { q: 'apify' } });
|
|
59
|
+
* console.log(response.data);
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
63
|
+
*/
|
|
64
|
+
export class ActorServerClient extends ResourceClient {
|
|
65
|
+
/**
|
|
66
|
+
* The server URL. Getting it takes an API call for the Actor, so it's cached for {@link getUrl} and
|
|
67
|
+
* {@link request}. It's pending while the first lookup runs, so concurrent first calls share one API request.
|
|
68
|
+
*/
|
|
69
|
+
#url;
|
|
70
|
+
/**
|
|
71
|
+
* @hidden
|
|
72
|
+
*/
|
|
73
|
+
constructor(options) {
|
|
74
|
+
super({
|
|
75
|
+
resourcePath: 'actors',
|
|
76
|
+
...options,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns the URL of the Actor's server.
|
|
81
|
+
*
|
|
82
|
+
* The URL is the Actor's `standbyUrl`, fetched from the API by the first call of this method or
|
|
83
|
+
* {@link getOpenApiSpec} and reused by later calls on this client. Use it to call the server with another HTTP
|
|
84
|
+
* client, for example one generated from the server's OpenAPI specification.
|
|
85
|
+
*
|
|
86
|
+
* @param options - Request options
|
|
87
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
88
|
+
* @returns The URL of the Actor's server
|
|
89
|
+
* @throws {ApifyClientError} When the Actor is not a Server Actor.
|
|
90
|
+
* @throws {NotFoundError} When the Actor does not exist.
|
|
91
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
92
|
+
*/
|
|
93
|
+
async getUrl(options = {}) {
|
|
94
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
95
|
+
const url = (this.#url ??= this.#getServerActor(timeoutSecs, signal).then((actor) => actor.standbyUrl));
|
|
96
|
+
try {
|
|
97
|
+
return await url;
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
// A failed lookup is not kept, so the next call tries again.
|
|
101
|
+
if (this.#url === url)
|
|
102
|
+
this.#url = undefined;
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the OpenAPI specification of the Actor's server.
|
|
108
|
+
*
|
|
109
|
+
* The specification is the web server schema from the Actor's definition, taken from the build that serves the
|
|
110
|
+
* server interface: the build set in `actorStandby.build`, or `latest` if none is set. Use it to generate an HTTP
|
|
111
|
+
* client for the server, and point that client at the URL returned by {@link getUrl}.
|
|
112
|
+
*
|
|
113
|
+
* @param options - Request options
|
|
114
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'short'`.
|
|
115
|
+
* @returns The OpenAPI specification of the Actor's server, or `undefined` if the Actor's definition doesn't
|
|
116
|
+
* include one
|
|
117
|
+
* @throws {ApifyClientError} When the Actor is not a Server Actor, or the build that serves its server interface
|
|
118
|
+
* doesn't exist.
|
|
119
|
+
* @throws {NotFoundError} When the Actor does not exist.
|
|
120
|
+
* @see https://docs.apify.com/platform/actors/development/actor-definition/web-server-schema
|
|
121
|
+
*/
|
|
122
|
+
async getOpenApiSpec(options = {}) {
|
|
123
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
124
|
+
const actor = await this.#getServerActor(timeoutSecs, signal);
|
|
125
|
+
const buildRef = actor.actorStandby?.build || 'latest';
|
|
126
|
+
let buildId = actor.taggedBuilds?.[buildRef]?.buildId ?? undefined;
|
|
127
|
+
const targetBuildNumber = parseBuildNumber(buildRef);
|
|
128
|
+
if (buildId === undefined && targetBuildNumber !== undefined) {
|
|
129
|
+
// Not a tag, so look `buildRef` up as a build number, which the API can't resolve directly.
|
|
130
|
+
const builds = new BuildCollectionClient(this.subResourceOptions({ resourcePath: 'builds' }));
|
|
131
|
+
for await (const build of builds.list({ desc: true, timeoutSecs, signal })) {
|
|
132
|
+
if (build.buildNumber === buildRef) {
|
|
133
|
+
buildId = build.id;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (isOlderBuild(build.buildNumber, targetBuildNumber))
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const build = buildId === undefined
|
|
141
|
+
? undefined
|
|
142
|
+
: await new BuildClient({
|
|
143
|
+
baseUrl: this.apifyClient.baseUrl,
|
|
144
|
+
publicBaseUrl: this.apifyClient.publicBaseUrl,
|
|
145
|
+
httpClient: this.httpClient,
|
|
146
|
+
apifyClient: this.apifyClient,
|
|
147
|
+
id: buildId,
|
|
148
|
+
}).get({ timeoutSecs, signal });
|
|
149
|
+
if (build === undefined) {
|
|
150
|
+
throw new ApifyClientError(`Build ${buildRef} of Actor ${this.id} does not exist.`);
|
|
151
|
+
}
|
|
152
|
+
return build.actorDefinition?.webServerSchema;
|
|
153
|
+
}
|
|
154
|
+
async request(path = '/', options = {}) {
|
|
155
|
+
parseArgument(path, z.string());
|
|
156
|
+
const { method = 'GET', params, headers, data, parentRequestId, compression, responseType, timeoutSecs = 'long', signal, } = parseArgument(options, requestOptionsSchema, 'ActorServerRequestOptions');
|
|
157
|
+
if (responseType === 'stream' && !runtime.isNode) {
|
|
158
|
+
throw new Error("The 'stream' response type can only be used in Node.js environment.");
|
|
159
|
+
}
|
|
160
|
+
const serverUrl = await this.getUrl({ signal });
|
|
161
|
+
const serverPath = path.split('#')[0].replace(/^\/+/, '');
|
|
162
|
+
return this.httpClient.call({
|
|
163
|
+
url: `${serverUrl.replace(/\/+$/, '')}/${serverPath}`,
|
|
164
|
+
method,
|
|
165
|
+
params,
|
|
166
|
+
headers: parentRequestId === undefined
|
|
167
|
+
? headers
|
|
168
|
+
: mergeHeaders(headers ?? {}, { 'X-Actor-Request-ID': parentRequestId }),
|
|
169
|
+
data,
|
|
170
|
+
compression: compression === undefined ? false : resolveCompressor(compression),
|
|
171
|
+
authorizationHeader: 'X-Apify-Authorization',
|
|
172
|
+
throwOnErrorStatus: false,
|
|
173
|
+
retryStatusCodes: SERVER_RETRY_STATUS_CODES,
|
|
174
|
+
retryTransportErrors: false,
|
|
175
|
+
followRedirects: false,
|
|
176
|
+
responseType,
|
|
177
|
+
timeoutSecs,
|
|
178
|
+
signal,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Fetches the Actor, checks that it is a Server Actor, and caches its server URL.
|
|
183
|
+
*/
|
|
184
|
+
async #getServerActor(timeoutSecs, signal) {
|
|
185
|
+
const response = await this.httpClient.call({
|
|
186
|
+
url: this.buildUrl(),
|
|
187
|
+
method: 'GET',
|
|
188
|
+
params: this.buildParams(),
|
|
189
|
+
timeoutSecs,
|
|
190
|
+
signal,
|
|
191
|
+
});
|
|
192
|
+
const actor = parseResponse(response, schemas.ActorResource());
|
|
193
|
+
if (!actor.standbyUrl) {
|
|
194
|
+
throw new ApifyClientError(`Actor ${this.id} is not a Server Actor.`);
|
|
195
|
+
}
|
|
196
|
+
this.#url = Promise.resolve(actor.standbyUrl);
|
|
197
|
+
return actor;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
2
|
-
import { ResourceClient } from '../base/resource_client';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export {
|
|
1
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
+
import type { FinalVersion, Version } from '../models.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
5
|
+
import { ActorEnvVarClient } from './actor_env_var.js';
|
|
6
|
+
import { ActorEnvVarCollectionClient } from './actor_env_var_collection.js';
|
|
7
|
+
export type { BaseVersion, EnvVar, FinalVersion, SourceCodeFile, SourceCodeFolder, Version, VersionGitHubGist, VersionGitRepo, VersionSourceCode, VersionSourceFiles, VersionTarball, } from '../models.js';
|
|
8
|
+
export { ActorSourceType } from '../models.js';
|
|
8
9
|
/**
|
|
9
10
|
* Client for managing a specific Actor version.
|
|
10
11
|
*
|
|
@@ -34,24 +35,30 @@ export declare class ActorVersionClient extends ResourceClient {
|
|
|
34
35
|
/**
|
|
35
36
|
* Retrieves the Actor version.
|
|
36
37
|
*
|
|
38
|
+
* @param options - Request options
|
|
39
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
37
40
|
* @returns The Actor version object, or `undefined` if it does not exist.
|
|
38
41
|
* @see https://docs.apify.com/api/v2/act-version-get
|
|
39
42
|
*/
|
|
40
|
-
get(): Promise<
|
|
43
|
+
get(options?: TimeoutOptions): Promise<FinalVersion | undefined>;
|
|
41
44
|
/**
|
|
42
45
|
* Updates the Actor version with the specified fields.
|
|
43
46
|
*
|
|
44
47
|
* @param newFields - Fields to update.
|
|
48
|
+
* @param options - Request options
|
|
49
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
45
50
|
* @returns The updated Actor version object.
|
|
46
51
|
* @see https://docs.apify.com/api/v2/act-version-put
|
|
47
52
|
*/
|
|
48
|
-
update(newFields:
|
|
53
|
+
update(newFields: ActorVersionUpdateData, options?: TimeoutOptions): Promise<FinalVersion>;
|
|
49
54
|
/**
|
|
50
55
|
* Deletes the Actor version.
|
|
51
56
|
*
|
|
57
|
+
* @param options - Request options
|
|
58
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
52
59
|
* @see https://docs.apify.com/api/v2/act-version-delete
|
|
53
60
|
*/
|
|
54
|
-
delete(): Promise<void>;
|
|
61
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
55
62
|
/**
|
|
56
63
|
* Returns a client for the specified environment variable of this Actor version.
|
|
57
64
|
*
|
|
@@ -70,3 +77,16 @@ export declare class ActorVersionClient extends ResourceClient {
|
|
|
70
77
|
*/
|
|
71
78
|
envVars(): ActorEnvVarCollectionClient;
|
|
72
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Fields that can be changed on an existing Actor version.
|
|
82
|
+
*
|
|
83
|
+
* All of them are optional, because the endpoint leaves untouched whatever the payload does not
|
|
84
|
+
* mention. The version union enforces the pairing: a `sourceType` can only be sent next to the
|
|
85
|
+
* source location it implies, never next to one of the other three.
|
|
86
|
+
*
|
|
87
|
+
* On a `SOURCE_FILES` or `TARBALL` version, `actorPath: null` removes the stored path. So does an
|
|
88
|
+
* update that sends `sourceType`, `sourceFiles`, or `tarballUrl` without `actorPath`, so send it
|
|
89
|
+
* again with every upload. The API rejects an `actorPath` on a version of any other source type,
|
|
90
|
+
* also when the update leaves out `sourceType`, because it then checks the stored source type.
|
|
91
|
+
*/
|
|
92
|
+
export type ActorVersionUpdateData = Partial<Version>;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
var models_1 = require("../models");
|
|
11
|
-
Object.defineProperty(exports, "ActorSourceType", { enumerable: true, get: function () { return models_1.ActorSourceType; } });
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
5
|
+
import { anyObjectSchema, parseArgument } from '../utils.js';
|
|
6
|
+
import { ActorEnvVarClient } from './actor_env_var.js';
|
|
7
|
+
import { ActorEnvVarCollectionClient } from './actor_env_var_collection.js';
|
|
8
|
+
const envVarNameSchema = z.string().min(1);
|
|
9
|
+
export { ActorSourceType } from '../models.js';
|
|
12
10
|
/**
|
|
13
11
|
* Client for managing a specific Actor version.
|
|
14
12
|
*
|
|
@@ -30,7 +28,7 @@ Object.defineProperty(exports, "ActorSourceType", { enumerable: true, get: funct
|
|
|
30
28
|
*
|
|
31
29
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
32
30
|
*/
|
|
33
|
-
class ActorVersionClient extends
|
|
31
|
+
export class ActorVersionClient extends ResourceClient {
|
|
34
32
|
/**
|
|
35
33
|
* @hidden
|
|
36
34
|
*/
|
|
@@ -43,30 +41,39 @@ class ActorVersionClient extends resource_client_1.ResourceClient {
|
|
|
43
41
|
/**
|
|
44
42
|
* Retrieves the Actor version.
|
|
45
43
|
*
|
|
44
|
+
* @param options - Request options
|
|
45
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
46
46
|
* @returns The Actor version object, or `undefined` if it does not exist.
|
|
47
47
|
* @see https://docs.apify.com/api/v2/act-version-get
|
|
48
48
|
*/
|
|
49
|
-
async get() {
|
|
50
|
-
|
|
49
|
+
async get(options = {}) {
|
|
50
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
51
|
+
return this.getResource(schemas.Version(), {}, timeoutSecs, signal);
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Updates the Actor version with the specified fields.
|
|
54
55
|
*
|
|
55
56
|
* @param newFields - Fields to update.
|
|
57
|
+
* @param options - Request options
|
|
58
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
56
59
|
* @returns The updated Actor version object.
|
|
57
60
|
* @see https://docs.apify.com/api/v2/act-version-put
|
|
58
61
|
*/
|
|
59
|
-
async update(newFields) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
async update(newFields, options = {}) {
|
|
63
|
+
parseArgument(newFields, anyObjectSchema);
|
|
64
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
65
|
+
return this.updateResource(schemas.Version(), newFields, timeoutSecs, signal);
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
68
|
* Deletes the Actor version.
|
|
65
69
|
*
|
|
70
|
+
* @param options - Request options
|
|
71
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
66
72
|
* @see https://docs.apify.com/api/v2/act-version-delete
|
|
67
73
|
*/
|
|
68
|
-
async delete() {
|
|
69
|
-
|
|
74
|
+
async delete(options = {}) {
|
|
75
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
76
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
70
77
|
}
|
|
71
78
|
/**
|
|
72
79
|
* Returns a client for the specified environment variable of this Actor version.
|
|
@@ -77,8 +84,8 @@ class ActorVersionClient extends resource_client_1.ResourceClient {
|
|
|
77
84
|
* @since Added in 2.1.0
|
|
78
85
|
*/
|
|
79
86
|
envVar(envVarName) {
|
|
80
|
-
|
|
81
|
-
return new
|
|
87
|
+
parseArgument(envVarName, envVarNameSchema);
|
|
88
|
+
return new ActorEnvVarClient(this.subResourceOptions({
|
|
82
89
|
id: envVarName,
|
|
83
90
|
}));
|
|
84
91
|
}
|
|
@@ -90,7 +97,6 @@ class ActorVersionClient extends resource_client_1.ResourceClient {
|
|
|
90
97
|
* @since Added in 2.1.0
|
|
91
98
|
*/
|
|
92
99
|
envVars() {
|
|
93
|
-
return new
|
|
100
|
+
return new ActorEnvVarCollectionClient(this.subResourceOptions());
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
|
-
exports.ActorVersionClient = ActorVersionClient;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
2
|
-
import { ResourceCollectionClient } from '../base/resource_collection_client';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
|
+
import type { PaginatedList } from '../utils.js';
|
|
5
|
+
import type { FinalVersion, Version } from './actor_version.js';
|
|
5
6
|
/**
|
|
6
7
|
* Client for managing the collection of Actor versions.
|
|
7
8
|
*
|
|
@@ -20,6 +21,8 @@ import type { ActorVersion, FinalActorVersion } from './actor_version';
|
|
|
20
21
|
* // Create a new version
|
|
21
22
|
* const newVersion = await versionsClient.create({
|
|
22
23
|
* versionNumber: '0.2',
|
|
24
|
+
* sourceType: 'GIT_REPO',
|
|
25
|
+
* gitRepoUrl: 'https://github.com/my-account/my-actor',
|
|
23
26
|
* buildTag: 'latest'
|
|
24
27
|
* });
|
|
25
28
|
* ```
|
|
@@ -34,37 +37,33 @@ export declare class ActorVersionCollectionClient extends ResourceCollectionClie
|
|
|
34
37
|
/**
|
|
35
38
|
* Lists all Actor versions.
|
|
36
39
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
40
|
+
* The endpoint returns every version in one response, so awaiting the return value (as you would with a Promise)
|
|
41
|
+
* gets the whole list.
|
|
39
42
|
* ```javascript
|
|
40
|
-
* const
|
|
41
|
-
|
|
43
|
+
* const { items } = await client.list();
|
|
44
|
+
* ```
|
|
42
45
|
*
|
|
43
|
-
* Asynchronous iteration is also supported
|
|
44
|
-
* retrieved.
|
|
46
|
+
* Asynchronous iteration is also supported, and yields the versions one by one.
|
|
45
47
|
*
|
|
46
48
|
* ```javascript
|
|
47
49
|
* for await (const singleItem of client.list()) {...}
|
|
48
50
|
* ```
|
|
49
51
|
*
|
|
50
|
-
* @
|
|
52
|
+
* @param options - Request options
|
|
53
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
54
|
+
* @returns The Actor versions, awaitable as a whole list or iterable one by one.
|
|
51
55
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
52
56
|
*/
|
|
53
|
-
list(
|
|
57
|
+
list(options?: TimeoutOptions): Promise<ActorVersionListResult> & AsyncIterable<FinalVersion>;
|
|
54
58
|
/**
|
|
55
59
|
* Creates a new Actor version.
|
|
56
60
|
*
|
|
57
61
|
* @param actorVersion - The Actor version data.
|
|
62
|
+
* @param options - Request options
|
|
63
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
58
64
|
* @returns The created Actor version object.
|
|
59
65
|
* @see https://docs.apify.com/api/v2/act-versions-post
|
|
60
66
|
*/
|
|
61
|
-
create(actorVersion:
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @deprecated No options are used in the current API implementation.
|
|
65
|
-
* https://github.com/apify/apify-client-js/issues/799
|
|
66
|
-
*/
|
|
67
|
-
export interface ActorVersionCollectionListOptions extends PaginationOptions {
|
|
68
|
-
desc?: boolean;
|
|
67
|
+
create(actorVersion: Version, options?: TimeoutOptions): Promise<FinalVersion>;
|
|
69
68
|
}
|
|
70
|
-
export type ActorVersionListResult = Pick<PaginatedList<
|
|
69
|
+
export type ActorVersionListResult = Pick<PaginatedList<FinalVersion>, 'total' | 'items'>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const actorVersionSchema = utils_1.anyObjectSchema.optional();
|
|
1
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
4
|
+
import { anyObjectSchema, parseArgument } from '../utils.js';
|
|
5
|
+
const actorVersionSchema = anyObjectSchema.optional();
|
|
7
6
|
/**
|
|
8
7
|
* Client for managing the collection of Actor versions.
|
|
9
8
|
*
|
|
@@ -22,13 +21,15 @@ const actorVersionSchema = utils_1.anyObjectSchema.optional();
|
|
|
22
21
|
* // Create a new version
|
|
23
22
|
* const newVersion = await versionsClient.create({
|
|
24
23
|
* versionNumber: '0.2',
|
|
24
|
+
* sourceType: 'GIT_REPO',
|
|
25
|
+
* gitRepoUrl: 'https://github.com/my-account/my-actor',
|
|
25
26
|
* buildTag: 'latest'
|
|
26
27
|
* });
|
|
27
28
|
* ```
|
|
28
29
|
*
|
|
29
30
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
30
31
|
*/
|
|
31
|
-
class ActorVersionCollectionClient extends
|
|
32
|
+
export class ActorVersionCollectionClient extends ResourceCollectionClient {
|
|
32
33
|
/**
|
|
33
34
|
* @hidden
|
|
34
35
|
*/
|
|
@@ -41,35 +42,39 @@ class ActorVersionCollectionClient extends resource_collection_client_1.Resource
|
|
|
41
42
|
/**
|
|
42
43
|
* Lists all Actor versions.
|
|
43
44
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
45
|
+
* The endpoint returns every version in one response, so awaiting the return value (as you would with a Promise)
|
|
46
|
+
* gets the whole list.
|
|
46
47
|
* ```javascript
|
|
47
|
-
* const
|
|
48
|
-
|
|
48
|
+
* const { items } = await client.list();
|
|
49
|
+
* ```
|
|
49
50
|
*
|
|
50
|
-
* Asynchronous iteration is also supported
|
|
51
|
-
* retrieved.
|
|
51
|
+
* Asynchronous iteration is also supported, and yields the versions one by one.
|
|
52
52
|
*
|
|
53
53
|
* ```javascript
|
|
54
54
|
* for await (const singleItem of client.list()) {...}
|
|
55
55
|
* ```
|
|
56
56
|
*
|
|
57
|
-
* @
|
|
57
|
+
* @param options - Request options
|
|
58
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
59
|
+
* @returns The Actor versions, awaitable as a whole list or iterable one by one.
|
|
58
60
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
59
61
|
*/
|
|
60
|
-
list(
|
|
61
|
-
|
|
62
|
+
list(options = {}) {
|
|
63
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
64
|
+
return this.listUnpaginatedResources(schemas.ListOfVersions(), timeoutSecs, signal);
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
64
67
|
* Creates a new Actor version.
|
|
65
68
|
*
|
|
66
69
|
* @param actorVersion - The Actor version data.
|
|
70
|
+
* @param options - Request options
|
|
71
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
67
72
|
* @returns The created Actor version object.
|
|
68
73
|
* @see https://docs.apify.com/api/v2/act-versions-post
|
|
69
74
|
*/
|
|
70
|
-
async create(actorVersion) {
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
async create(actorVersion, options = {}) {
|
|
76
|
+
parseArgument(actorVersion, actorVersionSchema);
|
|
77
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
78
|
+
return this.createResource(schemas.Version(), actorVersion, timeoutSecs, signal);
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
|
-
exports.ActorVersionCollectionClient = ActorVersionCollectionClient;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
2
|
-
import { ResourceClient } from '../base/resource_client';
|
|
3
|
-
import type { Build } from '../models';
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
+
import type { Build } from '../models.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
5
|
+
import { LogClient } from './log.js';
|
|
6
|
+
export type { Build, BuildOptions, BuildStats, BuildUsage, BuildMeta } from '../models.js';
|
|
6
7
|
/**
|
|
7
8
|
* Client for managing a specific Actor build.
|
|
8
9
|
*
|
|
@@ -36,6 +37,8 @@ export declare class BuildClient extends ResourceClient {
|
|
|
36
37
|
*
|
|
37
38
|
* @param options - Get options
|
|
38
39
|
* @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the build to finish on the API side before returning. Default is 0 (returns immediately).
|
|
40
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
41
|
+
* when the API is asked to hold the response.
|
|
39
42
|
* @returns The Build object, or `undefined` if it does not exist
|
|
40
43
|
* @see https://docs.apify.com/api/v2/actor-build-get
|
|
41
44
|
*
|
|
@@ -55,6 +58,8 @@ export declare class BuildClient extends ResourceClient {
|
|
|
55
58
|
*
|
|
56
59
|
* Stops the build process immediately. The build will have an `ABORTED` status.
|
|
57
60
|
*
|
|
61
|
+
* @param options - Request options
|
|
62
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
58
63
|
* @returns The updated Build object with `ABORTED` status
|
|
59
64
|
* @see https://docs.apify.com/api/v2/actor-build-abort-post
|
|
60
65
|
*
|
|
@@ -63,22 +68,26 @@ export declare class BuildClient extends ResourceClient {
|
|
|
63
68
|
* await client.build('build-id').abort();
|
|
64
69
|
* ```
|
|
65
70
|
*/
|
|
66
|
-
abort(): Promise<Build>;
|
|
71
|
+
abort(options?: TimeoutOptions): Promise<Build>;
|
|
67
72
|
/**
|
|
68
73
|
* Deletes the Actor build.
|
|
69
74
|
*
|
|
75
|
+
* @param options - Request options
|
|
76
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
70
77
|
* @see https://docs.apify.com/api/v2/actor-build-delete
|
|
71
78
|
* @since Added in 2.8.1
|
|
72
79
|
*/
|
|
73
|
-
delete(): Promise<void>;
|
|
80
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
74
81
|
/**
|
|
75
82
|
* Retrieves the OpenAPI definition for the Actor build.
|
|
76
83
|
*
|
|
84
|
+
* @param options - Request options
|
|
85
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
77
86
|
* @returns The OpenAPI definition object.
|
|
78
87
|
* @see https://docs.apify.com/api/v2/actor-build-openapi-json-get
|
|
79
88
|
* @since Added in 2.11.2
|
|
80
89
|
*/
|
|
81
|
-
getOpenApiDefinition(): Promise<OpenApiDefinition>;
|
|
90
|
+
getOpenApiDefinition(options?: TimeoutOptions): Promise<OpenApiDefinition>;
|
|
82
91
|
/**
|
|
83
92
|
* Waits for the Actor build to finish and returns the finished Build object.
|
|
84
93
|
*
|
|
@@ -89,12 +98,14 @@ export declare class BuildClient extends ResourceClient {
|
|
|
89
98
|
* Unlike the `waitForFinish` parameter in {@link get}, this method can wait indefinitely
|
|
90
99
|
* by polling the build status. It uses the `waitForFinish` parameter internally (max 60s per call)
|
|
91
100
|
* and continuously polls until the build finishes or the timeout is reached.
|
|
101
|
+
* Rejects with a {@link NotFoundError} if the build keeps returning 404 for 3 seconds.
|
|
92
102
|
*
|
|
93
103
|
* This is useful when you need to immediately start a run after a build finishes.
|
|
94
104
|
*
|
|
95
105
|
* @param options - Wait options
|
|
96
106
|
* @param options.waitSecs - Maximum time to wait for the build to finish, in seconds. If omitted, waits indefinitely.
|
|
97
|
-
* @
|
|
107
|
+
* @param options.timeoutSecs - Timeout for each polling API request. Default is `'noTimeout'`.
|
|
108
|
+
* @returns The Build object (finished or still building if the timeout was reached)
|
|
98
109
|
*
|
|
99
110
|
* @example
|
|
100
111
|
* ```javascript
|
|
@@ -113,6 +124,8 @@ export declare class BuildClient extends ResourceClient {
|
|
|
113
124
|
/**
|
|
114
125
|
* Returns a client for accessing the log of this Actor build.
|
|
115
126
|
*
|
|
127
|
+
* A 404 from this client throws an `ApifyApiError`, since the build itself may be what is missing.
|
|
128
|
+
*
|
|
116
129
|
* @returns A client for accessing the build's log
|
|
117
130
|
* @see https://docs.apify.com/api/v2/actor-build-log-get
|
|
118
131
|
*
|
|
@@ -129,13 +142,13 @@ export declare class BuildClient extends ResourceClient {
|
|
|
129
142
|
/**
|
|
130
143
|
* Options for getting a Build.
|
|
131
144
|
*/
|
|
132
|
-
export interface BuildClientGetOptions {
|
|
145
|
+
export interface BuildClientGetOptions extends TimeoutOptions {
|
|
133
146
|
waitForFinish?: number;
|
|
134
147
|
}
|
|
135
148
|
/**
|
|
136
149
|
* Options for waiting for a Build to finish.
|
|
137
150
|
*/
|
|
138
|
-
export interface BuildClientWaitForFinishOptions {
|
|
151
|
+
export interface BuildClientWaitForFinishOptions extends TimeoutOptions {
|
|
139
152
|
/**
|
|
140
153
|
* Maximum time to wait for the build to finish, in seconds.
|
|
141
154
|
* If the limit is reached, the returned promise is resolved to a build object that will have
|