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