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
|
@@ -1,57 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify/consts';
|
|
3
|
+
import { Log } from '@apify/log';
|
|
4
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
5
|
+
import * as schemas from '../schemas.js';
|
|
6
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
7
|
+
import { anyObjectSchema, isStream, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
|
|
8
|
+
import { startWaitingForResources } from '../wait_for_resources.js';
|
|
9
|
+
import { ActorServerClient } from './actor_server.js';
|
|
10
|
+
import { ActorVersionClient } from './actor_version.js';
|
|
11
|
+
import { ActorVersionCollectionClient } from './actor_version_collection.js';
|
|
12
|
+
import { BuildClient } from './build.js';
|
|
13
|
+
import { BuildCollectionClient } from './build_collection.js';
|
|
14
|
+
import { RunClient } from './run.js';
|
|
15
|
+
import { RunCollectionClient } from './run_collection.js';
|
|
16
|
+
import { WebhookCollectionClient } from './webhook_collection.js';
|
|
17
|
+
const startOptionsSchema = z.strictObject({
|
|
18
|
+
build: z.string().optional(),
|
|
19
|
+
contentType: z.string().optional(),
|
|
20
|
+
memory: z.number().optional(),
|
|
21
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
22
|
+
waitForFinish: z.number().optional(),
|
|
23
|
+
webhooks: z.array(anyObjectSchema).optional(),
|
|
24
|
+
maxItems: z.number().min(0).optional(),
|
|
25
|
+
maxTotalChargeUsd: z.number().min(0).optional(),
|
|
26
|
+
restartOnError: z.boolean().optional(),
|
|
27
|
+
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
28
|
+
waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
|
|
29
|
+
...timeoutOptionsShape,
|
|
27
30
|
});
|
|
28
|
-
const callOptionsSchema =
|
|
29
|
-
build:
|
|
30
|
-
contentType:
|
|
31
|
-
memory:
|
|
32
|
-
|
|
33
|
-
waitSecs:
|
|
34
|
-
webhooks:
|
|
35
|
-
maxItems:
|
|
36
|
-
maxTotalChargeUsd:
|
|
37
|
-
log:
|
|
38
|
-
restartOnError:
|
|
39
|
-
forcePermissionLevel:
|
|
31
|
+
const callOptionsSchema = z.strictObject({
|
|
32
|
+
build: z.string().optional(),
|
|
33
|
+
contentType: z.string().optional(),
|
|
34
|
+
memory: z.number().optional(),
|
|
35
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
36
|
+
waitSecs: z.number().min(0).optional(),
|
|
37
|
+
webhooks: z.array(anyObjectSchema).optional(),
|
|
38
|
+
maxItems: z.number().min(0).optional(),
|
|
39
|
+
maxTotalChargeUsd: z.number().min(0).optional(),
|
|
40
|
+
log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
|
|
41
|
+
restartOnError: z.boolean().optional(),
|
|
42
|
+
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
43
|
+
waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
|
|
44
|
+
...timeoutOptionsShape,
|
|
40
45
|
});
|
|
41
|
-
const validateInputOptionsSchema =
|
|
42
|
-
build:
|
|
43
|
-
contentType:
|
|
46
|
+
const validateInputOptionsSchema = z.strictObject({
|
|
47
|
+
build: z.string().optional(),
|
|
48
|
+
contentType: z.string().optional(),
|
|
49
|
+
...timeoutOptionsShape,
|
|
44
50
|
});
|
|
45
|
-
const versionNumberSchema =
|
|
46
|
-
const buildOptionsSchema =
|
|
47
|
-
betaPackages:
|
|
48
|
-
tag:
|
|
49
|
-
useCache:
|
|
50
|
-
waitForFinish:
|
|
51
|
+
const versionNumberSchema = z.string().min(1);
|
|
52
|
+
const buildOptionsSchema = z.strictObject({
|
|
53
|
+
betaPackages: z.boolean().optional(),
|
|
54
|
+
tag: z.string().optional(),
|
|
55
|
+
useCache: z.boolean().optional(),
|
|
56
|
+
waitForFinish: z.number().optional(),
|
|
57
|
+
...timeoutOptionsShape,
|
|
51
58
|
});
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
|
|
60
|
+
const lastRunOptionsSchema = z.strictObject({
|
|
61
|
+
status: z.enum(ACTOR_JOB_STATUSES).optional(),
|
|
62
|
+
origin: z.enum(META_ORIGINS).optional(),
|
|
55
63
|
});
|
|
56
64
|
/**
|
|
57
65
|
* Client for managing a specific Actor.
|
|
@@ -73,7 +81,8 @@ const lastRunOptionsSchema = zod_1.z.strictObject({
|
|
|
73
81
|
*
|
|
74
82
|
* @see https://docs.apify.com/platform/actors
|
|
75
83
|
*/
|
|
76
|
-
class ActorClient extends
|
|
84
|
+
export class ActorClient extends ResourceClient {
|
|
85
|
+
#serverClient;
|
|
77
86
|
/**
|
|
78
87
|
* @hidden
|
|
79
88
|
*/
|
|
@@ -86,30 +95,39 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
86
95
|
/**
|
|
87
96
|
* Gets the Actor object from the Apify API.
|
|
88
97
|
*
|
|
98
|
+
* @param options - Request options
|
|
99
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
89
100
|
* @returns The Actor object, or `undefined` if it does not exist
|
|
90
101
|
* @see https://docs.apify.com/api/v2/act-get
|
|
91
102
|
*/
|
|
92
|
-
async get() {
|
|
93
|
-
|
|
103
|
+
async get(options = {}) {
|
|
104
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
105
|
+
return this.getResource(schemas.ActorResource(), {}, timeoutSecs, signal);
|
|
94
106
|
}
|
|
95
107
|
/**
|
|
96
108
|
* Updates the Actor with specified fields.
|
|
97
109
|
*
|
|
98
110
|
* @param newFields - Fields to update in the Actor
|
|
111
|
+
* @param options - Request options
|
|
112
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
99
113
|
* @returns The updated Actor object
|
|
100
114
|
* @see https://docs.apify.com/api/v2/act-put
|
|
101
115
|
*/
|
|
102
|
-
async update(newFields) {
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
async update(newFields, options = {}) {
|
|
117
|
+
parseArgument(newFields, anyObjectSchema);
|
|
118
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
119
|
+
return this.updateResource(schemas.ActorResource(), newFields, timeoutSecs, signal);
|
|
105
120
|
}
|
|
106
121
|
/**
|
|
107
122
|
* Deletes the Actor.
|
|
108
123
|
*
|
|
124
|
+
* @param options - Request options
|
|
125
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
109
126
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
110
127
|
*/
|
|
111
|
-
async delete() {
|
|
112
|
-
|
|
128
|
+
async delete(options = {}) {
|
|
129
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
130
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
113
131
|
}
|
|
114
132
|
/**
|
|
115
133
|
* Starts the Actor and immediately returns the Run object.
|
|
@@ -118,17 +136,20 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
118
136
|
* asynchronously and this method returns immediately without waiting for completion.
|
|
119
137
|
* Use the {@link call} method if you want to wait for the Actor to finish.
|
|
120
138
|
*
|
|
121
|
-
* @param input - Input for the Actor
|
|
122
|
-
*
|
|
139
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
140
|
+
* Omit it to run the Actor without input.
|
|
123
141
|
* @param options - Run configuration options
|
|
124
142
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`). If not provided, uses the default build.
|
|
125
143
|
* @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
|
|
126
|
-
* @param options.
|
|
144
|
+
* @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
|
|
127
145
|
* @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the run to finish on the API side before returning. Default is 0 (returns immediately).
|
|
128
146
|
* @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
|
|
129
147
|
* @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
|
|
130
148
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
|
|
131
|
-
* @param options.
|
|
149
|
+
* @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
|
|
150
|
+
* the run. `true` retries until the run starts, a number stops retrying after that many seconds.
|
|
151
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
152
|
+
* when the API is asked to hold the response.
|
|
132
153
|
* @returns The Actor run object with status, usage, and storage IDs
|
|
133
154
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
134
155
|
*
|
|
@@ -141,42 +162,43 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
141
162
|
* // Start Actor with specific build and memory
|
|
142
163
|
* const run = await client.actor('my-actor').start(
|
|
143
164
|
* { url: 'https://example.com' },
|
|
144
|
-
* { build: '0.1.2', memory: 512,
|
|
165
|
+
* { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
|
|
145
166
|
* );
|
|
146
167
|
* ```
|
|
147
168
|
*/
|
|
148
169
|
async start(input, options = {}) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, } = parsed;
|
|
170
|
+
const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
|
|
171
|
+
const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, waitForResources, timeoutSecs, signal, } = parsed;
|
|
172
|
+
// The API's `timeout` parameter bounds the run, not the request.
|
|
153
173
|
const params = {
|
|
154
174
|
waitForFinish,
|
|
155
|
-
timeout,
|
|
175
|
+
timeout: runTimeoutSecs,
|
|
156
176
|
memory,
|
|
157
177
|
build,
|
|
158
|
-
webhooks:
|
|
178
|
+
webhooks: stringifyWebhooksToBase64(parsed.webhooks),
|
|
159
179
|
maxItems,
|
|
160
180
|
maxTotalChargeUsd,
|
|
161
181
|
restartOnError,
|
|
162
182
|
forcePermissionLevel,
|
|
163
183
|
};
|
|
164
184
|
const request = {
|
|
165
|
-
url: this.
|
|
185
|
+
url: this.buildUrl('runs'),
|
|
166
186
|
method: 'POST',
|
|
167
187
|
data: input,
|
|
168
|
-
params: this.
|
|
169
|
-
//
|
|
170
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
188
|
+
params: this.buildParams(params),
|
|
189
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
171
190
|
stringifyFunctions: true,
|
|
191
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
|
|
192
|
+
signal,
|
|
172
193
|
};
|
|
173
194
|
if (parsed.contentType) {
|
|
174
195
|
request.headers = {
|
|
175
196
|
'content-type': parsed.contentType,
|
|
176
197
|
};
|
|
177
198
|
}
|
|
178
|
-
|
|
179
|
-
|
|
199
|
+
// A `Readable` input is consumed by the first attempt, so a retry would start the run with an empty input.
|
|
200
|
+
const response = await startWaitingForResources(async () => this.httpClient.call(request), isStream(input) ? false : waitForResources, this.httpClient.logger, signal);
|
|
201
|
+
return parseResponse(response, schemas.Run());
|
|
180
202
|
}
|
|
181
203
|
/**
|
|
182
204
|
* Starts the Actor and waits for it to finish before returning the Run object.
|
|
@@ -185,14 +207,18 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
185
207
|
* by polling the run status. It optionally streams logs to the console or a custom Log instance.
|
|
186
208
|
* By default, it waits indefinitely unless the `waitSecs` option is provided.
|
|
187
209
|
*
|
|
188
|
-
* @param input - Input for the Actor
|
|
189
|
-
*
|
|
210
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
211
|
+
* Omit it to run the Actor without input.
|
|
190
212
|
* @param options - Run configuration options (extends all options from {@link start})
|
|
191
213
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
|
|
192
214
|
* @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
|
|
193
215
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
|
|
194
216
|
* @param options.memory - Memory in megabytes allocated for the run.
|
|
195
|
-
* @param options.
|
|
217
|
+
* @param options.runTimeoutSecs - Maximum run duration in seconds.
|
|
218
|
+
* @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
|
|
219
|
+
* the run. `true` retries until the run starts, a number stops retrying after that many seconds. The time spent
|
|
220
|
+
* retrying doesn't count toward `waitSecs`.
|
|
221
|
+
* @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
|
|
196
222
|
* @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
|
|
197
223
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
198
224
|
*
|
|
@@ -216,20 +242,18 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
216
242
|
* ```
|
|
217
243
|
*/
|
|
218
244
|
async call(input, options = {}) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
const { waitSecs, log, ...startOptions } = parsed;
|
|
223
|
-
const { id } = await this.start(input, startOptions);
|
|
245
|
+
const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
|
|
246
|
+
const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
|
|
247
|
+
const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
|
|
224
248
|
// Calling root client because we need access to top level API.
|
|
225
249
|
// Creating a new instance of RunClient here would only allow
|
|
226
250
|
// setting it up as a nested route under actor API.
|
|
227
251
|
const newRunClient = this.apifyClient.run(id);
|
|
228
|
-
const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
|
|
252
|
+
const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
|
|
229
253
|
streamedLog?.start();
|
|
230
254
|
return this.apifyClient
|
|
231
255
|
.run(id)
|
|
232
|
-
.waitForFinish({ waitSecs })
|
|
256
|
+
.waitForFinish({ waitSecs, timeoutSecs, signal })
|
|
233
257
|
.finally(async () => {
|
|
234
258
|
await streamedLog?.stop();
|
|
235
259
|
});
|
|
@@ -242,13 +266,12 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
242
266
|
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
243
267
|
* validation problem.
|
|
244
268
|
*
|
|
245
|
-
* @param input - Input to validate against the Actor's input schema
|
|
246
|
-
*
|
|
247
|
-
* input should be a string or Buffer.
|
|
269
|
+
* @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
|
|
270
|
+
* raw bytes sent as they are.
|
|
248
271
|
* @param options - Validation options
|
|
249
272
|
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
250
273
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
251
|
-
* @param options.
|
|
274
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
252
275
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
253
276
|
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
254
277
|
*
|
|
@@ -266,17 +289,16 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
266
289
|
* @since Added in 2.24.0
|
|
267
290
|
*/
|
|
268
291
|
async validateInput(input, options = {}) {
|
|
269
|
-
|
|
270
|
-
// then it will process input as a buffer.
|
|
271
|
-
const parsed = (0, utils_1.parseArgument)(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
|
|
292
|
+
const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
|
|
272
293
|
const request = {
|
|
273
|
-
url: this.
|
|
294
|
+
url: this.buildUrl('validate-input'),
|
|
274
295
|
method: 'POST',
|
|
275
296
|
data: input,
|
|
276
|
-
params: this.
|
|
277
|
-
//
|
|
278
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
297
|
+
params: this.buildParams({ build: parsed.build }),
|
|
298
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
279
299
|
stringifyFunctions: true,
|
|
300
|
+
timeoutSecs: parsed.timeoutSecs ?? 'short',
|
|
301
|
+
signal: parsed.signal,
|
|
280
302
|
};
|
|
281
303
|
if (parsed.contentType) {
|
|
282
304
|
request.headers = {
|
|
@@ -298,6 +320,8 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
298
320
|
* @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
|
|
299
321
|
* @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
|
|
300
322
|
* @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).
|
|
323
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
324
|
+
* when the API is asked to hold the response.
|
|
301
325
|
* @returns The Build object with status and build details
|
|
302
326
|
* @see https://docs.apify.com/api/v2/act-builds-post
|
|
303
327
|
*
|
|
@@ -316,17 +340,19 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
316
340
|
* ```
|
|
317
341
|
*/
|
|
318
342
|
async build(versionNumber, options = {}) {
|
|
319
|
-
|
|
320
|
-
const
|
|
343
|
+
parseArgument(versionNumber, versionNumberSchema);
|
|
344
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
|
|
321
345
|
const response = await this.httpClient.call({
|
|
322
|
-
url: this.
|
|
346
|
+
url: this.buildUrl('builds'),
|
|
323
347
|
method: 'POST',
|
|
324
|
-
params: this.
|
|
348
|
+
params: this.buildParams({
|
|
325
349
|
version: versionNumber,
|
|
326
|
-
...
|
|
350
|
+
...params,
|
|
327
351
|
}),
|
|
352
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
|
|
353
|
+
signal,
|
|
328
354
|
});
|
|
329
|
-
return (
|
|
355
|
+
return parseResponse(response, schemas.Build());
|
|
330
356
|
}
|
|
331
357
|
/**
|
|
332
358
|
* Returns a client for the default build of this Actor.
|
|
@@ -337,6 +363,8 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
337
363
|
*
|
|
338
364
|
* @param options - Options for getting the default build
|
|
339
365
|
* @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).
|
|
366
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
367
|
+
* when the API is asked to hold the response.
|
|
340
368
|
* @returns A client for the default build
|
|
341
369
|
* @see https://docs.apify.com/api/v2/act-build-default-get
|
|
342
370
|
*
|
|
@@ -354,13 +382,16 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
354
382
|
* @since Added in 2.12.2
|
|
355
383
|
*/
|
|
356
384
|
async defaultBuild(options = {}) {
|
|
385
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
|
|
357
386
|
const response = await this.httpClient.call({
|
|
358
|
-
url: this.
|
|
387
|
+
url: this.buildUrl('builds/default'),
|
|
359
388
|
method: 'GET',
|
|
360
|
-
params: this.
|
|
389
|
+
params: this.buildParams(params),
|
|
390
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
|
|
391
|
+
signal,
|
|
361
392
|
});
|
|
362
|
-
const { id } = (
|
|
363
|
-
return new
|
|
393
|
+
const { id } = parseResponse(response, schemas.Build());
|
|
394
|
+
return new BuildClient({
|
|
364
395
|
baseUrl: this.apifyClient.baseUrl,
|
|
365
396
|
publicBaseUrl: this.apifyClient.publicBaseUrl,
|
|
366
397
|
httpClient: this.httpClient,
|
|
@@ -386,10 +417,10 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
386
417
|
* ```
|
|
387
418
|
*/
|
|
388
419
|
lastRun(options = {}) {
|
|
389
|
-
const parsed =
|
|
390
|
-
return new
|
|
420
|
+
const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
|
|
421
|
+
return new RunClient(this.subResourceOptions({
|
|
391
422
|
id: 'last',
|
|
392
|
-
params: this.
|
|
423
|
+
params: this.buildParams(parsed),
|
|
393
424
|
resourcePath: 'runs',
|
|
394
425
|
}));
|
|
395
426
|
}
|
|
@@ -400,7 +431,7 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
400
431
|
* @see https://docs.apify.com/api/v2/act-builds-get
|
|
401
432
|
*/
|
|
402
433
|
builds() {
|
|
403
|
-
return new
|
|
434
|
+
return new BuildCollectionClient(this.subResourceOptions({
|
|
404
435
|
resourcePath: 'builds',
|
|
405
436
|
}));
|
|
406
437
|
}
|
|
@@ -411,7 +442,7 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
411
442
|
* @see https://docs.apify.com/api/v2/act-runs-get
|
|
412
443
|
*/
|
|
413
444
|
runs() {
|
|
414
|
-
return new
|
|
445
|
+
return new RunCollectionClient(this.subResourceOptions({
|
|
415
446
|
resourcePath: 'runs',
|
|
416
447
|
}));
|
|
417
448
|
}
|
|
@@ -423,8 +454,8 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
423
454
|
* @see https://docs.apify.com/api/v2/act-version-get
|
|
424
455
|
*/
|
|
425
456
|
version(versionNumber) {
|
|
426
|
-
|
|
427
|
-
return new
|
|
457
|
+
parseArgument(versionNumber, versionNumberSchema);
|
|
458
|
+
return new ActorVersionClient(this.subResourceOptions({
|
|
428
459
|
id: versionNumber,
|
|
429
460
|
}));
|
|
430
461
|
}
|
|
@@ -435,7 +466,7 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
435
466
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
436
467
|
*/
|
|
437
468
|
versions() {
|
|
438
|
-
return new
|
|
469
|
+
return new ActorVersionCollectionClient(this.subResourceOptions());
|
|
439
470
|
}
|
|
440
471
|
/**
|
|
441
472
|
* Returns a client for managing webhooks associated with this Actor.
|
|
@@ -444,7 +475,47 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
444
475
|
* @see https://docs.apify.com/api/v2/act-webhooks-get
|
|
445
476
|
*/
|
|
446
477
|
webhooks() {
|
|
447
|
-
return new
|
|
478
|
+
return new WebhookCollectionClient(this.subResourceOptions());
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Returns a client for the server interface of this Actor.
|
|
482
|
+
*
|
|
483
|
+
* A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
|
|
484
|
+
* each call. Server Actors were formerly called Actor Standby, and {@link standby} is a deprecated alias of this
|
|
485
|
+
* method. Every call returns the same client, so the server URL it fetches is reused.
|
|
486
|
+
*
|
|
487
|
+
* @returns The client for the server interface of this Actor
|
|
488
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```javascript
|
|
492
|
+
* const response = await client.actor('username/actor-name').server().request('/search', {
|
|
493
|
+
* params: { q: 'apify' },
|
|
494
|
+
* });
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
server() {
|
|
498
|
+
this.#serverClient ??= new ActorServerClient({
|
|
499
|
+
baseUrl: this.baseUrl,
|
|
500
|
+
publicBaseUrl: this.publicBaseUrl,
|
|
501
|
+
apifyClient: this.apifyClient,
|
|
502
|
+
httpClient: this.httpClient,
|
|
503
|
+
id: this.id,
|
|
504
|
+
params: this.params,
|
|
505
|
+
});
|
|
506
|
+
return this.#serverClient;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Returns a client for the server interface of this Actor in Standby mode.
|
|
510
|
+
*
|
|
511
|
+
* Named after Actor Standby, the former name of Server Actors.
|
|
512
|
+
*
|
|
513
|
+
* @deprecated Use {@link server} instead. Will be removed in v4.
|
|
514
|
+
* @returns The client for the server interface of this Actor
|
|
515
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
516
|
+
*/
|
|
517
|
+
standby() {
|
|
518
|
+
this.httpClient.logger.deprecated('`standby()` is deprecated and will be removed in v4. Use `server()` instead.');
|
|
519
|
+
return this.server();
|
|
448
520
|
}
|
|
449
521
|
}
|
|
450
|
-
exports.ActorClient = ActorClient;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ACTOR_PERMISSION_LEVEL } from '@apify/consts';
|
|
2
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
3
|
-
import { ResourceCollectionClient } from '../base/resource_collection_client';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
|
|
2
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { ActorListItem } from '../models.js';
|
|
5
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
6
|
+
import type { PaginatedIterator, PaginatedList, PaginationOptions } from '../utils.js';
|
|
7
|
+
import type { ActorResource, ActorStandby, DefaultRunOptions, ExampleRunInput } from './actor.js';
|
|
8
|
+
import type { Version } from './actor_version.js';
|
|
9
|
+
export type { ActorListItem } from '../models.js';
|
|
9
10
|
/**
|
|
10
11
|
* Client for managing the collection of Actors in your account.
|
|
11
12
|
*
|
|
@@ -51,35 +52,40 @@ export declare class ActorCollectionClient extends ResourceCollectionClient {
|
|
|
51
52
|
* ```
|
|
52
53
|
*
|
|
53
54
|
* @param options - Pagination options.
|
|
55
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
54
56
|
* @returns A paginated iterator of Actors.
|
|
55
57
|
* @see https://docs.apify.com/api/v2/acts-get
|
|
56
58
|
*/
|
|
57
|
-
list(options?: ActorCollectionListOptions): PaginatedIterator<
|
|
59
|
+
list(options?: ActorCollectionListOptions): PaginatedIterator<ActorListItem>;
|
|
58
60
|
/**
|
|
59
61
|
* Creates a new Actor.
|
|
60
62
|
*
|
|
61
63
|
* @param actor - The Actor data.
|
|
64
|
+
* @param options - Request options
|
|
65
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
62
66
|
* @returns The created Actor object.
|
|
63
67
|
* @see https://docs.apify.com/api/v2/acts-post
|
|
64
68
|
*/
|
|
65
|
-
create(actor: ActorCollectionCreateOptions): Promise<
|
|
69
|
+
create(actor: ActorCollectionCreateOptions, options?: TimeoutOptions): Promise<ActorResource>;
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
72
|
+
* Field to order a list of Actors by.
|
|
73
|
+
*
|
|
68
74
|
* @since Added in 2.12.6
|
|
69
75
|
*/
|
|
70
76
|
export declare enum ActorListSortBy {
|
|
71
77
|
CREATED_AT = "createdAt",
|
|
72
78
|
LAST_RUN_STARTED_AT = "stats.lastRunStartedAt"
|
|
73
79
|
}
|
|
74
|
-
export interface ActorCollectionListOptions extends PaginationOptions {
|
|
80
|
+
export interface ActorCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
75
81
|
my?: boolean;
|
|
76
82
|
desc?: boolean;
|
|
77
83
|
/**
|
|
78
84
|
* @since Added in 2.12.6
|
|
79
85
|
*/
|
|
80
|
-
sortBy?: ActorListSortBy
|
|
86
|
+
sortBy?: `${ActorListSortBy}`;
|
|
81
87
|
}
|
|
82
|
-
export type ActorCollectionListResult = PaginatedList<
|
|
88
|
+
export type ActorCollectionListResult = PaginatedList<ActorListItem>;
|
|
83
89
|
export interface ActorCollectionCreateOptions {
|
|
84
90
|
/**
|
|
85
91
|
* @since Added in 2.8.6
|
|
@@ -88,20 +94,18 @@ export interface ActorCollectionCreateOptions {
|
|
|
88
94
|
/**
|
|
89
95
|
* @since Added in 2.8.6
|
|
90
96
|
*/
|
|
91
|
-
defaultRunOptions?:
|
|
97
|
+
defaultRunOptions?: DefaultRunOptions;
|
|
92
98
|
description?: string;
|
|
93
99
|
/**
|
|
94
100
|
* @since Added in 2.8.6
|
|
95
101
|
*/
|
|
96
|
-
exampleRunInput?:
|
|
102
|
+
exampleRunInput?: ExampleRunInput;
|
|
97
103
|
/**
|
|
98
104
|
* @since Added in 2.8.6
|
|
99
105
|
*/
|
|
100
106
|
isDeprecated?: boolean;
|
|
101
107
|
isPublic?: boolean;
|
|
102
108
|
name?: string;
|
|
103
|
-
/** @deprecated Use defaultRunOptions.restartOnError instead */
|
|
104
|
-
restartOnError?: boolean;
|
|
105
109
|
/**
|
|
106
110
|
* @since Added in 2.8.6
|
|
107
111
|
*/
|
|
@@ -111,7 +115,7 @@ export interface ActorCollectionCreateOptions {
|
|
|
111
115
|
*/
|
|
112
116
|
seoDescription?: string;
|
|
113
117
|
title?: string;
|
|
114
|
-
versions?:
|
|
118
|
+
versions?: Version[];
|
|
115
119
|
/**
|
|
116
120
|
* @since Added in 2.9.5
|
|
117
121
|
*/
|