apify-client 3.0.0-beta.11 → 3.0.0-beta.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/dist/apify_api_error.d.ts +13 -27
- package/dist/apify_api_error.js +33 -23
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -36
- package/dist/base/resource_client.d.ts +13 -8
- package/dist/base/resource_client.js +60 -34
- package/dist/base/resource_collection_client.d.ts +12 -4
- package/dist/base/resource_collection_client.js +34 -11
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +27 -22
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +3109 -987
- package/dist/generated/schemas.d.ts +2563 -957
- package/dist/generated/schemas.js +585 -229
- package/dist/http_clients/axios.d.ts +63 -0
- package/dist/http_clients/axios.js +129 -0
- package/dist/http_clients/base.d.ts +397 -0
- package/dist/http_clients/base.js +656 -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 +6 -1
- package/dist/index.js +5 -1
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/models.d.ts +177 -240
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +104 -34
- package/dist/resource_clients/actor.js +129 -55
- package/dist/resource_clients/actor_collection.d.ts +15 -11
- package/dist/resource_clients/actor_collection.js +9 -3
- package/dist/resource_clients/actor_env_var.d.ts +11 -4
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_server.d.ts +150 -0
- package/dist/resource_clients/actor_server.js +199 -0
- package/dist/resource_clients/actor_version.d.ts +18 -6
- package/dist/resource_clients/actor_version.js +18 -8
- package/dist/resource_clients/actor_version_collection.d.ts +9 -4
- package/dist/resource_clients/actor_version_collection.js +11 -4
- package/dist/resource_clients/build.d.ts +18 -7
- package/dist/resource_clients/build.js +33 -15
- package/dist/resource_clients/build_collection.d.ts +7 -5
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +83 -36
- package/dist/resource_clients/dataset.js +103 -109
- package/dist/resource_clients/dataset_collection.d.ts +10 -6
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +101 -27
- package/dist/resource_clients/key_value_store.js +132 -50
- package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +38 -21
- package/dist/resource_clients/log.js +139 -63
- package/dist/resource_clients/request_queue.d.ts +77 -31
- package/dist/resource_clients/request_queue.js +178 -93
- package/dist/resource_clients/request_queue_collection.d.ts +9 -5
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +124 -30
- package/dist/resource_clients/run.js +188 -51
- package/dist/resource_clients/run_collection.d.ts +5 -3
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +15 -6
- package/dist/resource_clients/schedule.js +25 -10
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +6 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +35 -12
- package/dist/resource_clients/task.js +75 -35
- package/dist/resource_clients/task_collection.d.ts +9 -5
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +16 -7
- package/dist/resource_clients/user.js +34 -16
- package/dist/resource_clients/webhook.d.ts +16 -7
- package/dist/resource_clients/webhook.js +25 -10
- package/dist/resource_clients/webhook_collection.d.ts +8 -4
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +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 +370 -4
- package/dist/schemas.js +26 -4
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/utils.d.ts +87 -61
- package/dist/utils.js +208 -162
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +41 -38
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -255
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -105
|
@@ -1,34 +1,53 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { ACT_JOB_TERMINAL_STATUSES } from '@apify/consts';
|
|
2
3
|
import { LEVELS, Log } from '@apify/log';
|
|
3
4
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
5
|
import * as schemas from '../schemas.js';
|
|
5
|
-
import {
|
|
6
|
+
import { optionalSignalSchema, optionalTimeoutSchema, timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
7
|
+
import { runtime } from '#runtime';
|
|
8
|
+
import { anyObjectSchema, paginationOptionsShape, parseArgument, parseResponse } from '../utils.js';
|
|
6
9
|
import { DatasetClient } from './dataset.js';
|
|
7
10
|
import { KeyValueStoreClient } from './key_value_store.js';
|
|
8
11
|
import { LogClient, LoggerActorRedirect, StreamedLog } from './log.js';
|
|
9
12
|
import { RequestQueueClient } from './request_queue.js';
|
|
10
13
|
const RUN_CHARGE_IDEMPOTENCY_HEADER = 'idempotency-key';
|
|
11
|
-
const getOptionsSchema = z.strictObject({ waitForFinish: z.number().optional() });
|
|
12
|
-
const abortOptionsSchema = z.strictObject({ gracefully: z.boolean().optional() });
|
|
14
|
+
const getOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
|
|
15
|
+
const abortOptionsSchema = z.strictObject({ gracefully: z.boolean().optional(), ...timeoutOptionsShape });
|
|
13
16
|
const targetActorIdSchema = z.string();
|
|
14
17
|
const metamorphOptionsSchema = z.strictObject({
|
|
15
18
|
contentType: z.string().optional(),
|
|
16
19
|
build: z.string().optional(),
|
|
20
|
+
...timeoutOptionsShape,
|
|
17
21
|
});
|
|
18
22
|
const resurrectOptionsSchema = z.strictObject({
|
|
19
23
|
build: z.string().optional(),
|
|
20
24
|
memory: z.number().optional(),
|
|
21
|
-
|
|
25
|
+
runTimeoutSecs: z.number().optional(),
|
|
22
26
|
maxItems: z.number().optional(),
|
|
23
27
|
maxTotalChargeUsd: z.number().optional(),
|
|
24
28
|
restartOnError: z.boolean().optional(),
|
|
29
|
+
...timeoutOptionsShape,
|
|
25
30
|
});
|
|
26
31
|
const chargeOptionsSchema = z.strictObject({
|
|
27
32
|
eventName: z.string(),
|
|
28
33
|
count: z.number().default(1),
|
|
29
34
|
idempotencyKey: z.string().optional(),
|
|
35
|
+
requestId: z.string().optional(),
|
|
36
|
+
...timeoutOptionsShape,
|
|
30
37
|
});
|
|
31
|
-
const waitForFinishOptionsSchema = z.strictObject({ waitSecs: z.number().optional() });
|
|
38
|
+
const waitForFinishOptionsSchema = z.strictObject({ waitSecs: z.number().optional(), ...timeoutOptionsShape });
|
|
39
|
+
const iterateDatasetItemsOptionsSchema = z.strictObject({
|
|
40
|
+
clean: z.boolean().optional(),
|
|
41
|
+
fields: z.array(z.string()).optional(),
|
|
42
|
+
omit: z.array(z.string()).optional(),
|
|
43
|
+
...paginationOptionsShape,
|
|
44
|
+
skipEmpty: z.boolean().optional(),
|
|
45
|
+
skipHidden: z.boolean().optional(),
|
|
46
|
+
unwind: z.array(z.string()).optional(),
|
|
47
|
+
pollIntervalSecs: z.number().min(0).optional(),
|
|
48
|
+
...timeoutOptionsShape,
|
|
49
|
+
});
|
|
50
|
+
const DEFAULT_ITERATE_CHUNK_SIZE = 1000;
|
|
32
51
|
/**
|
|
33
52
|
* Client for managing a specific Actor run.
|
|
34
53
|
*
|
|
@@ -67,7 +86,9 @@ export class RunClient extends ResourceClient {
|
|
|
67
86
|
*
|
|
68
87
|
* @param options - Get options
|
|
69
88
|
* @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).
|
|
70
|
-
* @
|
|
89
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
90
|
+
* when the API is asked to hold the response.
|
|
91
|
+
* @returns The Run object, or `undefined` if it does not exist
|
|
71
92
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
72
93
|
*
|
|
73
94
|
* @example
|
|
@@ -81,15 +102,16 @@ export class RunClient extends ResourceClient {
|
|
|
81
102
|
* ```
|
|
82
103
|
*/
|
|
83
104
|
async get(options = {}) {
|
|
84
|
-
const
|
|
85
|
-
return this.
|
|
105
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, getOptionsSchema, 'RunGetOptions');
|
|
106
|
+
return this.getResource(schemas.Run(), params, this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish), signal);
|
|
86
107
|
}
|
|
87
108
|
/**
|
|
88
109
|
* Aborts the Actor run.
|
|
89
110
|
*
|
|
90
111
|
* @param options - Abort options
|
|
91
112
|
* @param options.gracefully - If `true`, the Actor run will abort gracefully - it can send status messages and perform cleanup. Default is `false` (immediate abort).
|
|
92
|
-
* @
|
|
113
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
114
|
+
* @returns The updated Run object with `ABORTING` or `ABORTED` status
|
|
93
115
|
* @see https://docs.apify.com/api/v2/actor-run-abort-post
|
|
94
116
|
*
|
|
95
117
|
* @example
|
|
@@ -102,22 +124,27 @@ export class RunClient extends ResourceClient {
|
|
|
102
124
|
* ```
|
|
103
125
|
*/
|
|
104
126
|
async abort(options = {}) {
|
|
105
|
-
const
|
|
127
|
+
const { timeoutSecs = 'medium', signal, ...params } = parseArgument(options, abortOptionsSchema, 'RunAbortOptions');
|
|
106
128
|
const response = await this.httpClient.call({
|
|
107
|
-
url: this.
|
|
129
|
+
url: this.buildUrl('abort'),
|
|
108
130
|
method: 'POST',
|
|
109
|
-
params: this.
|
|
131
|
+
params: this.buildParams(params),
|
|
132
|
+
timeoutSecs,
|
|
133
|
+
signal,
|
|
110
134
|
});
|
|
111
135
|
return parseResponse(response, schemas.Run());
|
|
112
136
|
}
|
|
113
137
|
/**
|
|
114
138
|
* Deletes the Actor run.
|
|
115
139
|
*
|
|
140
|
+
* @param options - Request options
|
|
141
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
116
142
|
* @see https://docs.apify.com/api/v2/actor-run-delete
|
|
117
143
|
* @since Added in 2.8.1
|
|
118
144
|
*/
|
|
119
|
-
async delete() {
|
|
120
|
-
|
|
145
|
+
async delete(options = {}) {
|
|
146
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
147
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
121
148
|
}
|
|
122
149
|
/**
|
|
123
150
|
* Transforms the Actor run into a run of another Actor (metamorph).
|
|
@@ -126,18 +153,23 @@ export class RunClient extends ResourceClient {
|
|
|
126
153
|
* and resource allocation. The run effectively becomes a run of the target Actor with new input.
|
|
127
154
|
* This is useful for chaining Actor executions or implementing complex workflows.
|
|
128
155
|
*
|
|
156
|
+
* Only the run itself can metamorph: the client must use the run's own API token, which the run gets
|
|
157
|
+
* in the `APIFY_TOKEN` environment variable. With any other token, the API rejects the request.
|
|
158
|
+
*
|
|
129
159
|
* @param targetActorId - ID or username/name of the target Actor
|
|
130
|
-
* @param input - Input for the target Actor
|
|
160
|
+
* @param input - Input for the target Actor: an object or array serialized to JSON, or raw bytes sent as they
|
|
161
|
+
* are. Omit it to metamorph without input.
|
|
131
162
|
* @param options - Metamorph options
|
|
132
163
|
* @param options.build - Tag or number of the target Actor's build to run. Default is the target Actor's default build.
|
|
133
|
-
* @param options.
|
|
134
|
-
* @returns The metamorphed
|
|
164
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
165
|
+
* @returns The metamorphed Run object (same ID, but now running the target Actor)
|
|
135
166
|
* @see https://docs.apify.com/api/v2/actor-run-metamorph-post
|
|
136
167
|
*
|
|
137
168
|
* @example
|
|
138
169
|
* ```javascript
|
|
139
|
-
* //
|
|
140
|
-
* const
|
|
170
|
+
* // Inside the run: transform it into another Actor
|
|
171
|
+
* const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
|
|
172
|
+
* const metamorphedRun = await client.run(process.env.ACTOR_RUN_ID).metamorph(
|
|
141
173
|
* 'target-actor-id',
|
|
142
174
|
* { url: 'https://example.com' }
|
|
143
175
|
* );
|
|
@@ -146,23 +178,21 @@ export class RunClient extends ResourceClient {
|
|
|
146
178
|
*/
|
|
147
179
|
async metamorph(targetActorId, input, options = {}) {
|
|
148
180
|
parseArgument(targetActorId, targetActorIdSchema);
|
|
149
|
-
// input can be anything, pointless to validate
|
|
150
181
|
const parsed = parseArgument(options, metamorphOptionsSchema, 'RunMetamorphOptions');
|
|
151
|
-
const safeTargetActorId = this.
|
|
182
|
+
const safeTargetActorId = this.toSafeId(targetActorId);
|
|
152
183
|
const params = {
|
|
153
184
|
targetActorId: safeTargetActorId,
|
|
154
185
|
build: parsed.build,
|
|
155
186
|
};
|
|
156
187
|
const request = {
|
|
157
|
-
url: this.
|
|
188
|
+
url: this.buildUrl('metamorph'),
|
|
158
189
|
method: 'POST',
|
|
159
190
|
data: input,
|
|
160
|
-
params: this.
|
|
161
|
-
//
|
|
162
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
163
|
-
// TODO: remove this ts-expect-error once we have defined custom Apify axios configs
|
|
164
|
-
// @ts-expect-error Custom Apify property
|
|
191
|
+
params: this.buildParams(params),
|
|
192
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
165
193
|
stringifyFunctions: true,
|
|
194
|
+
timeoutSecs: parsed.timeoutSecs ?? 'medium',
|
|
195
|
+
signal: parsed.signal,
|
|
166
196
|
};
|
|
167
197
|
if (parsed.contentType) {
|
|
168
198
|
request.headers = {
|
|
@@ -179,7 +209,9 @@ export class RunClient extends ResourceClient {
|
|
|
179
209
|
* This can be useful to recover from certain errors or to force the Actor to restart
|
|
180
210
|
* with a fresh environment.
|
|
181
211
|
*
|
|
182
|
-
* @
|
|
212
|
+
* @param options - Request options
|
|
213
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
214
|
+
* @returns The updated Run object
|
|
183
215
|
* @see https://docs.apify.com/api/v2/actor-run-reboot-post
|
|
184
216
|
*
|
|
185
217
|
* @example
|
|
@@ -188,10 +220,13 @@ export class RunClient extends ResourceClient {
|
|
|
188
220
|
* ```
|
|
189
221
|
* @since Added in 2.8.0
|
|
190
222
|
*/
|
|
191
|
-
async reboot() {
|
|
223
|
+
async reboot(options = {}) {
|
|
224
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
192
225
|
const request = {
|
|
193
|
-
url: this.
|
|
226
|
+
url: this.buildUrl('reboot'),
|
|
194
227
|
method: 'POST',
|
|
228
|
+
timeoutSecs,
|
|
229
|
+
signal,
|
|
195
230
|
};
|
|
196
231
|
const response = await this.httpClient.call(request);
|
|
197
232
|
return parseResponse(response, schemas.Run());
|
|
@@ -203,7 +238,9 @@ export class RunClient extends ResourceClient {
|
|
|
203
238
|
* @param newFields.statusMessage - Custom status message to display (e.g., "Processing page 10/100")
|
|
204
239
|
* @param newFields.isStatusMessageTerminal - If `true`, the status message is final and won't be overwritten. Default is `false`.
|
|
205
240
|
* @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
|
|
206
|
-
* @
|
|
241
|
+
* @param options - Request options
|
|
242
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
243
|
+
* @returns The updated Run object
|
|
207
244
|
*
|
|
208
245
|
* @example
|
|
209
246
|
* ```javascript
|
|
@@ -214,9 +251,10 @@ export class RunClient extends ResourceClient {
|
|
|
214
251
|
* ```
|
|
215
252
|
* @since Added in 2.6.0
|
|
216
253
|
*/
|
|
217
|
-
async update(newFields) {
|
|
254
|
+
async update(newFields, options = {}) {
|
|
218
255
|
parseArgument(newFields, anyObjectSchema);
|
|
219
|
-
|
|
256
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
257
|
+
return this.updateResource(schemas.Run(), newFields, timeoutSecs, signal);
|
|
220
258
|
}
|
|
221
259
|
/**
|
|
222
260
|
* Resurrects a finished Actor run, starting it again with the same settings.
|
|
@@ -227,11 +265,12 @@ export class RunClient extends ResourceClient {
|
|
|
227
265
|
* @param options - Resurrection options (override original run settings)
|
|
228
266
|
* @param options.build - Tag or number of the build to use. If not provided, uses the original run's build.
|
|
229
267
|
* @param options.memory - Memory in megabytes. If not provided, uses the original run's memory.
|
|
230
|
-
* @param options.
|
|
268
|
+
* @param options.runTimeoutSecs - Timeout for the resurrected run in seconds. If not provided, uses the original run's timeout.
|
|
231
269
|
* @param options.maxItems - Maximum number of dataset items (pay-per-result Actors).
|
|
232
270
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (pay-per-event Actors).
|
|
233
271
|
* @param options.restartOnError - Whether to restart on error.
|
|
234
|
-
* @
|
|
272
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
273
|
+
* @returns The new (resurrected) Run object
|
|
235
274
|
* @see https://docs.apify.com/api/v2/post-resurrect-run
|
|
236
275
|
*
|
|
237
276
|
* @example
|
|
@@ -242,11 +281,14 @@ export class RunClient extends ResourceClient {
|
|
|
242
281
|
* ```
|
|
243
282
|
*/
|
|
244
283
|
async resurrect(options = {}) {
|
|
245
|
-
const
|
|
284
|
+
const { timeoutSecs = 'medium', signal, runTimeoutSecs, ...params } = parseArgument(options, resurrectOptionsSchema, 'RunResurrectOptions');
|
|
246
285
|
const response = await this.httpClient.call({
|
|
247
|
-
url: this.
|
|
286
|
+
url: this.buildUrl('resurrect'),
|
|
248
287
|
method: 'POST',
|
|
249
|
-
|
|
288
|
+
// The API's `timeout` parameter bounds the run, not the request.
|
|
289
|
+
params: this.buildParams({ ...params, timeout: runTimeoutSecs }),
|
|
290
|
+
timeoutSecs,
|
|
291
|
+
signal,
|
|
250
292
|
});
|
|
251
293
|
return parseResponse(response, schemas.Run());
|
|
252
294
|
}
|
|
@@ -257,25 +299,30 @@ export class RunClient extends ResourceClient {
|
|
|
257
299
|
* @param options.eventName - **Required.** Name of the event to charge for.
|
|
258
300
|
* @param options.count - Number of times to charge the event. Default is 1.
|
|
259
301
|
* @param options.idempotencyKey - Optional key to ensure the charge is not duplicated. If not provided, one is auto-generated.
|
|
302
|
+
* @param options.requestId - ID of the Server Actor request being charged, from the `X-Actor-Request-ID` header of the incoming request. Required for multi-tenant Server Actor runs.
|
|
303
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
260
304
|
* @returns Empty response object.
|
|
261
305
|
* @see https://docs.apify.com/api/v2/post-charge-run
|
|
262
306
|
* @since Added in 2.11.0
|
|
263
307
|
*/
|
|
264
308
|
async charge(options) {
|
|
265
|
-
const { eventName, count, idempotencyKey: providedIdempotencyKey, } = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');
|
|
309
|
+
const { eventName, count, idempotencyKey: providedIdempotencyKey, timeoutSecs = 'short', requestId, signal, } = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');
|
|
266
310
|
/** To avoid duplicates during the same milisecond, doesn't need to by crypto-secure. */
|
|
267
311
|
const randomSuffix = (Math.random() + 1).toString(36).slice(3, 8);
|
|
268
312
|
const idempotencyKey = providedIdempotencyKey ?? `${this.id}-${eventName}-${Date.now()}-${randomSuffix}`;
|
|
269
313
|
const request = {
|
|
270
|
-
url: this.
|
|
314
|
+
url: this.buildUrl('charge'),
|
|
271
315
|
method: 'POST',
|
|
272
316
|
data: {
|
|
273
317
|
eventName,
|
|
274
318
|
count,
|
|
319
|
+
requestId,
|
|
275
320
|
},
|
|
276
321
|
headers: {
|
|
277
322
|
[RUN_CHARGE_IDEMPOTENCY_HEADER]: idempotencyKey,
|
|
278
323
|
},
|
|
324
|
+
timeoutSecs,
|
|
325
|
+
signal,
|
|
279
326
|
};
|
|
280
327
|
const response = await this.httpClient.call(request);
|
|
281
328
|
return response;
|
|
@@ -290,10 +337,12 @@ export class RunClient extends ResourceClient {
|
|
|
290
337
|
* Unlike the `waitForFinish` parameter in {@link get}, this method can wait indefinitely
|
|
291
338
|
* by polling the run status. It uses the `waitForFinish` parameter internally (max 60s per call)
|
|
292
339
|
* and continuously polls until the run finishes or the timeout is reached.
|
|
340
|
+
* Rejects with a {@link NotFoundError} if the run keeps returning 404 for 3 seconds.
|
|
293
341
|
*
|
|
294
342
|
* @param options - Wait options
|
|
295
343
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If the limit is reached, the returned promise resolves to a run object that will have status `READY` or `RUNNING`. If omitted, waits indefinitely.
|
|
296
|
-
* @
|
|
344
|
+
* @param options.timeoutSecs - Timeout for each polling API request. Default is `'noTimeout'`.
|
|
345
|
+
* @returns The Run object (finished or still running if the timeout was reached)
|
|
297
346
|
*
|
|
298
347
|
* @example
|
|
299
348
|
* ```javascript
|
|
@@ -310,7 +359,7 @@ export class RunClient extends ResourceClient {
|
|
|
310
359
|
*/
|
|
311
360
|
async waitForFinish(options = {}) {
|
|
312
361
|
const parsed = parseArgument(options, waitForFinishOptionsSchema, 'RunWaitForFinishOptions');
|
|
313
|
-
return this.
|
|
362
|
+
return this.waitForJobFinish(schemas.Run(), parsed);
|
|
314
363
|
}
|
|
315
364
|
/**
|
|
316
365
|
* Returns a client for the default dataset of this Actor run.
|
|
@@ -327,7 +376,7 @@ export class RunClient extends ResourceClient {
|
|
|
327
376
|
* ```
|
|
328
377
|
*/
|
|
329
378
|
dataset() {
|
|
330
|
-
return new DatasetClient(this.
|
|
379
|
+
return new DatasetClient(this.subResourceOptions({
|
|
331
380
|
resourcePath: 'dataset',
|
|
332
381
|
}));
|
|
333
382
|
}
|
|
@@ -347,7 +396,7 @@ export class RunClient extends ResourceClient {
|
|
|
347
396
|
* ```
|
|
348
397
|
*/
|
|
349
398
|
keyValueStore() {
|
|
350
|
-
return new KeyValueStoreClient(this.
|
|
399
|
+
return new KeyValueStoreClient(this.subResourceOptions({
|
|
351
400
|
resourcePath: 'key-value-store',
|
|
352
401
|
}));
|
|
353
402
|
}
|
|
@@ -367,7 +416,7 @@ export class RunClient extends ResourceClient {
|
|
|
367
416
|
* ```
|
|
368
417
|
*/
|
|
369
418
|
requestQueue() {
|
|
370
|
-
return new RequestQueueClient(this.
|
|
419
|
+
return new RequestQueueClient(this.subResourceOptions({
|
|
371
420
|
resourcePath: 'request-queue',
|
|
372
421
|
}));
|
|
373
422
|
}
|
|
@@ -387,33 +436,121 @@ export class RunClient extends ResourceClient {
|
|
|
387
436
|
* ```
|
|
388
437
|
*/
|
|
389
438
|
log() {
|
|
390
|
-
return new LogClient(this.
|
|
439
|
+
return new LogClient(this.subResourceOptions({
|
|
391
440
|
resourcePath: 'log',
|
|
392
441
|
}));
|
|
393
442
|
}
|
|
394
443
|
/**
|
|
395
444
|
* Get StreamedLog for convenient streaming of the run log and their redirection.
|
|
445
|
+
*
|
|
446
|
+
* @param options - Streaming options
|
|
447
|
+
* @param options.toLog - Log instance to redirect the run log to. Use `'default'` for a preconfigured one, or `null` to disable the redirection.
|
|
448
|
+
* @param options.fromStart - If `true`, the log is streamed from its beginning. Default is `true`.
|
|
449
|
+
* @param options.timeoutSecs - Timeout for the API requests that fetch the run and its Actor. Default is `'long'`.
|
|
396
450
|
* @since Added in 2.20.0
|
|
397
451
|
*/
|
|
398
452
|
async getStreamedLog(options = {}) {
|
|
399
|
-
|
|
453
|
+
parseArgument(options.timeoutSecs, optionalTimeoutSchema);
|
|
454
|
+
parseArgument(options.signal, optionalSignalSchema);
|
|
455
|
+
const { fromStart = true, timeoutSecs = 'long', signal } = options;
|
|
400
456
|
let { toLog } = options;
|
|
401
|
-
if (toLog === null || !isNode
|
|
457
|
+
if (toLog === null || !runtime.isNode) {
|
|
402
458
|
// Explicitly no logging or not in Node.js
|
|
403
459
|
return undefined;
|
|
404
460
|
}
|
|
405
461
|
if (toLog === undefined || toLog === 'default') {
|
|
406
462
|
// Create default StreamedLog
|
|
407
463
|
// Get actor name and run id
|
|
408
|
-
const runData = await this.get();
|
|
464
|
+
const runData = await this.get({ timeoutSecs, signal });
|
|
409
465
|
const runId = runData?.id ?? '';
|
|
410
466
|
const actorId = runData?.actId ?? '';
|
|
411
467
|
// `apifyClient.actor()` rejects an empty ID, which is what a run that could not be read leaves here.
|
|
412
|
-
const actorData = actorId ? await this.apifyClient.actor(actorId).get() : undefined;
|
|
468
|
+
const actorData = actorId ? await this.apifyClient.actor(actorId).get({ timeoutSecs, signal }) : undefined;
|
|
413
469
|
const actorName = actorData?.name ?? '';
|
|
414
470
|
const name = [actorName, `runId:${runId}`].filter(Boolean).join(' ');
|
|
415
471
|
toLog = new Log({ level: LEVELS.DEBUG, prefix: `${name} -> `, logger: new LoggerActorRedirect() });
|
|
416
472
|
}
|
|
417
|
-
return new StreamedLog({ logClient: this.log(), toLog, fromStart });
|
|
473
|
+
return new StreamedLog({ logClient: this.log(), toLog, fromStart, signal });
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Iterates over the items of the run's default dataset while the run is still producing them.
|
|
477
|
+
*
|
|
478
|
+
* While the run has not finished, each poll yields the rows below the dataset's `itemCount` and then waits up to
|
|
479
|
+
* `pollIntervalSecs` for the run to finish, so the last rows are read as soon as it does. Each page is requested
|
|
480
|
+
* with a `limit` that ends at `itemCount`, so it covers exactly the rows it asks for, whatever the filters or
|
|
481
|
+
* `unwind` do to the items. `itemCount` lags a few seconds behind
|
|
482
|
+
* the pushed items, so once the run reaches a terminal status, the rows past it are read a page at a time until
|
|
483
|
+
* none are left, and the iterator returns. On a `lastRun()` client, the iterator sticks to the run that its first
|
|
484
|
+
* request resolves to.
|
|
485
|
+
*
|
|
486
|
+
* @param options - Iteration options
|
|
487
|
+
* @param options.offset - Number of rows to skip from the beginning. Default is 0.
|
|
488
|
+
* @param options.limit - Maximum number of dataset rows to scan. Fewer items are yielded when filters drop some,
|
|
489
|
+
* more when `unwind` splits a row into several. Default is no limit.
|
|
490
|
+
* @param options.clean - If `true`, returns only non-empty items and skips hidden fields. Default is `false`.
|
|
491
|
+
* @param options.fields - Array of field names to include in the results. Omits all other fields.
|
|
492
|
+
* @param options.omit - Array of field names to exclude from the results.
|
|
493
|
+
* @param options.unwind - Array of field names to unwind. Each array value creates a separate item.
|
|
494
|
+
* @param options.skipEmpty - If `true`, skips empty items. Default is `false`.
|
|
495
|
+
* @param options.skipHidden - If `true`, skips hidden fields (fields starting with `#`). Default is `false`.
|
|
496
|
+
* @param options.chunkSize - Maximum number of dataset rows requested per API call. Default is 1000.
|
|
497
|
+
* @param options.pollIntervalSecs - How long to wait for the run to finish between polls, in seconds. Default is 5.
|
|
498
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'long'`.
|
|
499
|
+
* @returns An async iterable of the dataset items
|
|
500
|
+
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```javascript
|
|
504
|
+
* for await (const item of client.run('run-id').iterateDatasetItems()) {
|
|
505
|
+
* console.log(item);
|
|
506
|
+
* }
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
async *iterateDatasetItems(options = {}) {
|
|
510
|
+
const { offset, limit, chunkSize, pollIntervalSecs = 5, timeoutSecs = 'long', signal, ...itemOptions } = parseArgument(options, iterateDatasetItemsOptionsSchema, 'RunIterateDatasetItemsOptions');
|
|
511
|
+
const pageSize = chunkSize || DEFAULT_ITERATE_CHUNK_SIZE;
|
|
512
|
+
let position = offset ?? 0;
|
|
513
|
+
const end = limit ? position + limit : undefined;
|
|
514
|
+
let run = await this.get({ timeoutSecs, signal });
|
|
515
|
+
// A `lastRun()` client resolves `runs/last` on each request, so a newer run would swap the dataset mid-iteration.
|
|
516
|
+
const runClient = run && run.id !== this.id ? this.apifyClient.run(run.id) : this;
|
|
517
|
+
const datasetClient = runClient.dataset();
|
|
518
|
+
const listPage = async (pageOffset, pageLimit) => datasetClient.listItems({ ...itemOptions, offset: pageOffset, limit: pageLimit, timeoutSecs, signal });
|
|
519
|
+
while (true) {
|
|
520
|
+
const isFinished = !run || ACT_JOB_TERMINAL_STATUSES.includes(run.status);
|
|
521
|
+
const dataset = await datasetClient.get({ timeoutSecs, signal });
|
|
522
|
+
let itemCount = dataset?.itemCount ?? 0;
|
|
523
|
+
if (end !== undefined)
|
|
524
|
+
itemCount = Math.min(itemCount, end);
|
|
525
|
+
while (position < itemCount) {
|
|
526
|
+
const pageLimit = Math.min(pageSize, itemCount - position);
|
|
527
|
+
const page = await listPage(position, pageLimit);
|
|
528
|
+
yield* page.items;
|
|
529
|
+
position += pageLimit;
|
|
530
|
+
}
|
|
531
|
+
if (end !== undefined && position >= end)
|
|
532
|
+
return;
|
|
533
|
+
if (isFinished)
|
|
534
|
+
break;
|
|
535
|
+
run = await runClient.waitForFinish({ waitSecs: pollIntervalSecs, timeoutSecs, signal });
|
|
536
|
+
}
|
|
537
|
+
const { clean, skipEmpty, unwind } = itemOptions;
|
|
538
|
+
while (true) {
|
|
539
|
+
const pageLimit = end !== undefined ? Math.min(pageSize, end - position) : pageSize;
|
|
540
|
+
const page = await listPage(position, pageLimit);
|
|
541
|
+
yield* page.items;
|
|
542
|
+
// Only an empty page marks the end, as filters can shorten a full one. A page that `clean`, `skipEmpty` or
|
|
543
|
+
// `unwind` emptied past a lagging `itemCount` reports no scanned rows either, so a plain read checks.
|
|
544
|
+
const isEmpty = page.count === 0;
|
|
545
|
+
if (isEmpty &&
|
|
546
|
+
(!(clean || skipEmpty || unwind?.length) ||
|
|
547
|
+
(await datasetClient.listItems({ offset: position, limit: 1, timeoutSecs, signal })).items
|
|
548
|
+
.length === 0)) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
position += pageLimit;
|
|
552
|
+
if (end !== undefined && position >= end)
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
418
555
|
}
|
|
419
556
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ACTOR_JOB_STATUSES } from '@apify/consts';
|
|
2
2
|
import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client.js';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { PaginatedIterator, PaginationOptions } from '../utils.js';
|
|
5
|
-
import type {
|
|
6
|
+
import type { RunListItem } from './actor.js';
|
|
6
7
|
/**
|
|
7
8
|
* Client for managing the collection of Actor runs.
|
|
8
9
|
*
|
|
@@ -46,12 +47,13 @@ export declare class RunCollectionClient extends ResourceCollectionClient {
|
|
|
46
47
|
* ```
|
|
47
48
|
*
|
|
48
49
|
* @param options - Pagination and filtering options.
|
|
50
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
49
51
|
* @returns A paginated iterator of Actor runs.
|
|
50
52
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
51
53
|
*/
|
|
52
|
-
list(options?: RunCollectionListOptions): PaginatedIterator<
|
|
54
|
+
list(options?: RunCollectionListOptions): PaginatedIterator<RunListItem>;
|
|
53
55
|
}
|
|
54
|
-
export interface RunCollectionListOptions extends PaginationOptions {
|
|
56
|
+
export interface RunCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
55
57
|
desc?: boolean;
|
|
56
58
|
status?: (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES] | (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES][];
|
|
57
59
|
/**
|
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { ACTOR_JOB_STATUSES } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
+
import { timeoutOptionsShape } from '../timeouts.js';
|
|
5
6
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
6
7
|
const jobStatusSchema = z.enum(ACTOR_JOB_STATUSES);
|
|
7
8
|
const listOptionsSchema = z.strictObject({
|
|
@@ -10,6 +11,7 @@ const listOptionsSchema = z.strictObject({
|
|
|
10
11
|
status: z.union([jobStatusSchema, z.array(jobStatusSchema)]).optional(),
|
|
11
12
|
startedBefore: z.union([z.date(), z.string()]).optional(),
|
|
12
13
|
startedAfter: z.union([z.date(), z.string()]).optional(),
|
|
14
|
+
...timeoutOptionsShape,
|
|
13
15
|
});
|
|
14
16
|
/**
|
|
15
17
|
* Client for managing the collection of Actor runs.
|
|
@@ -59,11 +61,12 @@ export class RunCollectionClient extends ResourceCollectionClient {
|
|
|
59
61
|
* ```
|
|
60
62
|
*
|
|
61
63
|
* @param options - Pagination and filtering options.
|
|
64
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
62
65
|
* @returns A paginated iterator of Actor runs.
|
|
63
66
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
64
67
|
*/
|
|
65
68
|
list(options = {}) {
|
|
66
69
|
const parsed = parseArgument(options, listOptionsSchema, 'RunCollectionListOptions');
|
|
67
|
-
return this.
|
|
70
|
+
return this.listResourcesPaginated(schemas.ListOfRuns(), parsed, 'medium');
|
|
68
71
|
}
|
|
69
72
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
-
import type { Schedule, ScheduleAction,
|
|
3
|
+
import type { Schedule, ScheduleAction, ScheduleLogEntry } from '../models.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { DistributiveOptional } from '../utils.js';
|
|
5
|
-
export type { Schedule, ScheduleAction, ScheduleActionRunActor, ScheduleActionRunActorTask,
|
|
6
|
+
export type { Schedule, ScheduleAction, ScheduleActionRunActor, ScheduleActionRunActorTask, ScheduleActionRunInput, ScheduleLogEntry, TaskOptions, } from '../models.js';
|
|
6
7
|
export { ScheduleActions } from '../models.js';
|
|
7
8
|
/**
|
|
8
9
|
* Client for managing a specific Schedule.
|
|
@@ -35,31 +36,39 @@ export declare class ScheduleClient extends ResourceClient {
|
|
|
35
36
|
/**
|
|
36
37
|
* Retrieves the schedule.
|
|
37
38
|
*
|
|
39
|
+
* @param options - Request options
|
|
40
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
38
41
|
* @returns The schedule object, or `undefined` if it does not exist.
|
|
39
42
|
* @see https://docs.apify.com/api/v2/schedule-get
|
|
40
43
|
*/
|
|
41
|
-
get(): Promise<Schedule | undefined>;
|
|
44
|
+
get(options?: TimeoutOptions): Promise<Schedule | undefined>;
|
|
42
45
|
/**
|
|
43
46
|
* Updates the schedule with the specified fields.
|
|
44
47
|
*
|
|
45
48
|
* @param newFields - Fields to update.
|
|
49
|
+
* @param options - Request options
|
|
50
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
46
51
|
* @returns The updated schedule object.
|
|
47
52
|
* @see https://docs.apify.com/api/v2/schedule-put
|
|
48
53
|
*/
|
|
49
|
-
update(newFields: ScheduleCreateOrUpdateData): Promise<Schedule>;
|
|
54
|
+
update(newFields: ScheduleCreateOrUpdateData, options?: TimeoutOptions): Promise<Schedule>;
|
|
50
55
|
/**
|
|
51
56
|
* Deletes the schedule.
|
|
52
57
|
*
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
53
60
|
* @see https://docs.apify.com/api/v2/schedule-delete
|
|
54
61
|
*/
|
|
55
|
-
delete(): Promise<void>;
|
|
62
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
56
63
|
/**
|
|
57
64
|
* Retrieves the schedule's log.
|
|
58
65
|
*
|
|
66
|
+
* @param options - Request options
|
|
67
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
59
68
|
* @returns The schedule log, one entry per invocation.
|
|
60
69
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
61
70
|
*/
|
|
62
|
-
getLog(): Promise<
|
|
71
|
+
getLog(options?: TimeoutOptions): Promise<ScheduleLogEntry[]>;
|
|
63
72
|
}
|
|
64
73
|
/**
|
|
65
74
|
* Data for creating or updating a Schedule.
|