apify 4.0.0-beta.12 → 4.0.0-beta.121
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 +29 -43
- package/dist/actor.d.ts +511 -167
- package/dist/actor.js +895 -322
- package/dist/apify_dataset_backend.d.ts +19 -0
- package/dist/apify_dataset_backend.js +77 -0
- package/dist/apify_file_system_storage_backend.d.ts +34 -0
- package/dist/apify_file_system_storage_backend.js +41 -0
- package/dist/apify_key_value_store_backend.d.ts +23 -0
- package/dist/apify_key_value_store_backend.js +56 -0
- package/dist/apify_request_queue_backend.d.ts +78 -0
- package/dist/apify_request_queue_backend.js +114 -0
- package/dist/apify_request_queue_shared_backend.d.ts +31 -0
- package/dist/apify_request_queue_shared_backend.js +193 -0
- package/dist/apify_request_queue_single_backend.d.ts +43 -0
- package/dist/apify_request_queue_single_backend.js +256 -0
- package/dist/apify_storage_backend.d.ts +90 -0
- package/dist/apify_storage_backend.js +210 -0
- package/dist/charging.d.ts +82 -18
- package/dist/charging.js +388 -128
- package/dist/charging_storage_backend.d.ts +53 -0
- package/dist/charging_storage_backend.js +109 -0
- package/dist/child_run_tracker.d.ts +88 -0
- package/dist/child_run_tracker.js +239 -0
- package/dist/configuration.d.ts +86 -136
- package/dist/configuration.js +136 -145
- package/dist/enqueue_links_filters.d.ts +29 -0
- package/dist/enqueue_links_filters.js +52 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +22 -0
- package/dist/google_sheets.d.ts +12 -0
- package/dist/google_sheets.js +26 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +8 -5
- package/dist/input-schemas.d.ts +7 -0
- package/dist/input-schemas.js +58 -0
- package/dist/platform_event_manager.d.ts +15 -6
- package/dist/platform_event_manager.js +187 -41
- package/dist/proxy_configuration.d.ts +66 -59
- package/dist/proxy_configuration.js +172 -154
- package/dist/smart_apify_storage_backend.d.ts +52 -0
- package/dist/smart_apify_storage_backend.js +73 -0
- package/dist/storage.d.ts +38 -0
- package/dist/storage.js +1 -0
- package/dist/utils.d.ts +28 -4
- package/dist/utils.js +60 -20
- package/package.json +117 -73
- package/.turbo/turbo-build.log +0 -26
- package/.turbo/turbo-copy.log +0 -4
- package/dist/LICENSE.md +0 -201
- package/dist/README.md +0 -98
- package/dist/actor.d.ts.map +0 -1
- package/dist/actor.js.map +0 -1
- package/dist/charging.d.ts.map +0 -1
- package/dist/charging.js.map +0 -1
- package/dist/configuration.d.ts.map +0 -1
- package/dist/configuration.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/key_value_store.d.ts +0 -17
- package/dist/key_value_store.d.ts.map +0 -1
- package/dist/key_value_store.js +0 -33
- package/dist/key_value_store.js.map +0 -1
- package/dist/package.json +0 -75
- package/dist/platform_event_manager.d.ts.map +0 -1
- package/dist/platform_event_manager.js.map +0 -1
- package/dist/proxy_configuration.d.ts.map +0 -1
- package/dist/proxy_configuration.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/actor.d.ts
CHANGED
|
@@ -1,17 +1,68 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Dataset, RequestQueue } from '@crawlee/core';
|
|
3
|
-
import type { Awaitable, Dictionary,
|
|
4
|
-
import type { ActorCallOptions, ApifyClientOptions, RunAbortOptions, TaskCallOptions,
|
|
5
|
-
import {
|
|
1
|
+
import type { EventManager, EventTypeName, RecordOptions, UseStateOptions } from '@crawlee/core';
|
|
2
|
+
import { Dataset, KeyValueStore, RequestQueue } from '@crawlee/core';
|
|
3
|
+
import type { Awaitable, Dictionary, StorageBackend } from '@crawlee/types';
|
|
4
|
+
import type { ActorCallOptions, ActorInput, ActorStartOptions, ApifyClientOptions, RunAbortOptions, RunClient, RunResurrectOptions, TaskCallOptions, TaskStartOptions, WebhookResource, WebhookEventType } from 'apify-client';
|
|
5
|
+
import { ApifyClient, Run as ClientActorRun } from 'apify-client';
|
|
6
|
+
import { type ACTOR_PERMISSION_LEVEL } from '@apify/consts';
|
|
7
|
+
import type { RequestQueueAccessMode } from './apify_request_queue_backend.js';
|
|
6
8
|
import type { ChargeOptions, ChargeResult } from './charging.js';
|
|
7
9
|
import { ChargingManager } from './charging.js';
|
|
10
|
+
import type { ConfigurationOptions } from './configuration.js';
|
|
8
11
|
import { Configuration } from './configuration.js';
|
|
9
|
-
import { KeyValueStore } from './key_value_store.js';
|
|
10
12
|
import type { ProxyConfigurationOptions } from './proxy_configuration.js';
|
|
11
13
|
import { ProxyConfiguration } from './proxy_configuration.js';
|
|
14
|
+
import type { OpenStorageOptions, StorageIdentifier } from './storage.js';
|
|
12
15
|
export interface InitOptions {
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Storage backend to use, in place of the Apify platform storage (on the platform) or crawlee's
|
|
18
|
+
* local storage (outside of it).
|
|
19
|
+
*
|
|
20
|
+
* Items pushed to the default dataset are then not charged for under the pay-per-event pricing
|
|
21
|
+
* model: the platform counts an `apify-default-dataset-item` per item it stores itself, and a
|
|
22
|
+
* backend of your own stores them elsewhere.
|
|
23
|
+
*/
|
|
24
|
+
storage?: StorageBackend;
|
|
25
|
+
/**
|
|
26
|
+
* Determines how request queues opened on the Apify platform are consumed.
|
|
27
|
+
*
|
|
28
|
+
* - `'single'` (default) assumes this run is the only consumer of its request queues. Requests
|
|
29
|
+
* are not locked server-side and the queue head is estimated locally, which means fewer
|
|
30
|
+
* (paid) API calls and better performance.
|
|
31
|
+
* - `'shared'` locks every fetched request server-side, so any number of concurrent consumers
|
|
32
|
+
* (e.g. several Actor runs) can safely process the same queue, at the cost of roughly one
|
|
33
|
+
* extra API call per processed request.
|
|
34
|
+
*
|
|
35
|
+
* Only applies on the Apify platform (or with `forceCloud`); local storage ignores it.
|
|
36
|
+
* @default 'single'
|
|
37
|
+
*/
|
|
38
|
+
requestQueueAccess?: RequestQueueAccessMode;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to automatically handle platform shutdown signals.
|
|
41
|
+
* When enabled, `Actor.exit()` is called on `aborting` events and `Actor.reboot()` on `migrating` events.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
gracefulShutdown?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Delay in milliseconds before calling `Actor.exit()`/`Actor.reboot()` on `aborting`/`migrating` events.
|
|
47
|
+
* Since both methods already wait for all event handlers to complete, this delay is usually unnecessary.
|
|
48
|
+
* @default 0
|
|
49
|
+
*/
|
|
50
|
+
gracefulShutdownDelayMillis?: number;
|
|
14
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Options accepted by the {@link Actor} constructor. Either pass field-level
|
|
54
|
+
* overrides (`token`, `inputKey`, …) — which the Actor turns into a fresh
|
|
55
|
+
* {@link Configuration} — or pass a pre-built `configuration` instance. When
|
|
56
|
+
* both are present, `configuration` wins and the field-level overrides are
|
|
57
|
+
* ignored.
|
|
58
|
+
*/
|
|
59
|
+
export type ActorOptions = ConfigurationOptions & {
|
|
60
|
+
/**
|
|
61
|
+
* Pre-built {@link Configuration} instance the Actor should use. Takes
|
|
62
|
+
* precedence over any field-level overrides also passed in `options`.
|
|
63
|
+
*/
|
|
64
|
+
configuration?: Configuration;
|
|
65
|
+
};
|
|
15
66
|
export interface ExitOptions {
|
|
16
67
|
/** Exit with given status message */
|
|
17
68
|
statusMessage?: string;
|
|
@@ -27,6 +78,12 @@ export interface ExitOptions {
|
|
|
27
78
|
}
|
|
28
79
|
export interface MainOptions extends ExitOptions, InitOptions {
|
|
29
80
|
}
|
|
81
|
+
export interface SetStatusMessageOptions {
|
|
82
|
+
/** If `true`, the status message is treated as final and won't be overwritten by the platform. */
|
|
83
|
+
isStatusMessageTerminal?: boolean;
|
|
84
|
+
/** Log level used when the status message is also logged locally. Defaults to `INFO`. */
|
|
85
|
+
level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
86
|
+
}
|
|
30
87
|
/**
|
|
31
88
|
* Parsed representation of the Apify environment variables.
|
|
32
89
|
* This object is returned by the {@link Actor.getEnv} function.
|
|
@@ -48,11 +105,19 @@ export interface ApifyEnv {
|
|
|
48
105
|
* ID of the Actor build used in the run. (ACTOR_BUILD_ID)
|
|
49
106
|
*/
|
|
50
107
|
actorBuildId: string | null;
|
|
108
|
+
/**
|
|
109
|
+
* [Permission level](https://docs.apify.com/platform/actors/development/permissions) the Actor is run under. (ACTOR_PERMISSION_LEVEL)
|
|
110
|
+
*/
|
|
111
|
+
actorPermissionLevel: ACTOR_PERMISSION_LEVEL | null;
|
|
51
112
|
/**
|
|
52
113
|
* ID of the user who started the Actor - note that it might be
|
|
53
114
|
* different than the owner of the Actor (APIFY_USER_ID)
|
|
54
115
|
*/
|
|
55
116
|
userId: string | null;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the user who started the Actor is a paying user. `false` when not set. (APIFY_USER_IS_PAYING)
|
|
119
|
+
*/
|
|
120
|
+
userIsPaying: boolean;
|
|
56
121
|
/**
|
|
57
122
|
* Authentication token representing privileges given to the Actor run,
|
|
58
123
|
* it can be passed to various Apify APIs (APIFY_TOKEN)
|
|
@@ -105,17 +170,9 @@ export interface ApifyEnv {
|
|
|
105
170
|
apiPublicBaseUrl: string | null;
|
|
106
171
|
chromeExecutablePath: string | null;
|
|
107
172
|
dedicatedCpus: string | null;
|
|
108
|
-
disableOutdatedWarning: 1 | null;
|
|
109
173
|
fact: string | null;
|
|
110
174
|
inputSecretsPrivateKeyFile: string | null;
|
|
111
175
|
inputSecretsPrivateKeyPassphrase: string | null;
|
|
112
|
-
/**
|
|
113
|
-
* Defines the path to a local directory where KeyValueStore, Dataset, and RequestQueue
|
|
114
|
-
* store their data. Typically, it is set to ./storage. If omitted, you should define the
|
|
115
|
-
* APIFY_TOKEN environment variable instead. See more info on combination of this and
|
|
116
|
-
* APIFY_TOKEN [here](https://docs.apify.com/sdk/js/docs/guides/environment-variables#combinations-of-apify_local_storage_dir-and-apify_token)(CRAWLEE_STORAGE_DIR)
|
|
117
|
-
*/
|
|
118
|
-
localStorageDir: string | null;
|
|
119
176
|
/**
|
|
120
177
|
* Specifies the minimum log level, which can be one of the following values (in order of severity): DEBUG, INFO, WARNING and ERROR
|
|
121
178
|
* (APIFY_LOG_LEVEL)
|
|
@@ -123,7 +180,7 @@ export interface ApifyEnv {
|
|
|
123
180
|
logLevel: string | null;
|
|
124
181
|
logFormat: string | null;
|
|
125
182
|
/**
|
|
126
|
-
* Origin for the Actor run, i.e. how it was started. See [here](https://docs.apify.com/
|
|
183
|
+
* Origin for the Actor run, i.e. how it was started. See [here](https://docs.apify.com/platform/actors/running/runs-and-builds#origin)
|
|
127
184
|
* for more details. (APIFY_META_ORIGIN)
|
|
128
185
|
*/
|
|
129
186
|
metaOrigin: string | null;
|
|
@@ -131,7 +188,6 @@ export interface ApifyEnv {
|
|
|
131
188
|
* The key of the input record in the Actor’s default key-value store (ACTOR_INPUT_KEY)
|
|
132
189
|
*/
|
|
133
190
|
inputKey: string | null;
|
|
134
|
-
sdkLatestVersion: string | null;
|
|
135
191
|
systemInfoIntervalMillis: string | null;
|
|
136
192
|
workflowKey: string | null;
|
|
137
193
|
actorBuildNumber: string | null;
|
|
@@ -142,23 +198,55 @@ export interface ApifyEnv {
|
|
|
142
198
|
defaultRequestQueueId: string | null;
|
|
143
199
|
}
|
|
144
200
|
export type UserFunc<T = unknown> = () => Awaitable<T>;
|
|
145
|
-
export interface
|
|
201
|
+
export interface Token {
|
|
146
202
|
/**
|
|
147
|
-
* User API token that is used
|
|
203
|
+
* User Apify API token that is used for API calls. By default, it is taken from the `APIFY_TOKEN` environment variable.
|
|
148
204
|
*/
|
|
149
205
|
token?: string;
|
|
150
206
|
}
|
|
151
|
-
export interface
|
|
207
|
+
export interface Timeout {
|
|
152
208
|
/**
|
|
153
|
-
*
|
|
209
|
+
* Timeout for the Actor run in seconds, or `'inherit'`.
|
|
210
|
+
*
|
|
211
|
+
* Using `inherit` will set timeout of the newly started Actor run to the time
|
|
212
|
+
* remaining until this Actor run times out so that the new run does not outlive this one.
|
|
154
213
|
*/
|
|
155
|
-
|
|
214
|
+
timeout?: number | 'inherit';
|
|
156
215
|
}
|
|
157
|
-
export interface
|
|
216
|
+
export interface ChildRunOptions {
|
|
158
217
|
/**
|
|
159
|
-
*
|
|
218
|
+
* Local name for the child run, unique across all Actors and tasks started by this run.
|
|
219
|
+
*
|
|
220
|
+
* If a `READY`, `RUNNING` or `SUCCEEDED` run is already tracked under this name, it is returned instead of
|
|
221
|
+
* starting a new one, including after a migration or resurrection of this run. A run that was aborted or timed out
|
|
222
|
+
* is resurrected with the given options, once it finishes aborting or timing out. A run that failed is replaced
|
|
223
|
+
* by a new one. Reusing the name for a different Actor, task or input throws, unless the tracked run is replaced.
|
|
160
224
|
*/
|
|
161
|
-
|
|
225
|
+
runName?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Gracefully abort the child run when this run is gracefully aborted. Requires `runName`.
|
|
228
|
+
*
|
|
229
|
+
* The latest call under the same `runName` sets the value. Once this run is being aborted, a call with this option
|
|
230
|
+
* throws instead of starting, resurrecting or returning a run. A hard abort, timeout or crash of this run leaves
|
|
231
|
+
* the child run running.
|
|
232
|
+
*
|
|
233
|
+
* A run started with a custom `token` is aborted with that token, except for a run started before a migration or
|
|
234
|
+
* resurrection of this run, which is aborted with the default client.
|
|
235
|
+
* @default false
|
|
236
|
+
*/
|
|
237
|
+
abortWithParent?: boolean;
|
|
238
|
+
}
|
|
239
|
+
export interface CallOptions extends Omit<ActorCallOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
240
|
+
}
|
|
241
|
+
export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
242
|
+
}
|
|
243
|
+
export interface CallTaskOptions extends Omit<TaskCallOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
244
|
+
}
|
|
245
|
+
export interface ResurrectOptions extends Omit<RunResurrectOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout {
|
|
246
|
+
}
|
|
247
|
+
export interface StartTaskOptions extends Omit<TaskStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
248
|
+
}
|
|
249
|
+
export interface AbortOptions extends RunAbortOptions, Token {
|
|
162
250
|
/** Exit with given status message */
|
|
163
251
|
statusMessage?: string;
|
|
164
252
|
}
|
|
@@ -188,13 +276,42 @@ export interface WebhookOptions {
|
|
|
188
276
|
* {@link Actor.getEnv} function.
|
|
189
277
|
*/
|
|
190
278
|
idempotencyKey?: string;
|
|
279
|
+
/**
|
|
280
|
+
* Headers template is a JSON-like string that describes the HTTP headers to be sent with the webhook POST request.
|
|
281
|
+
* It uses JSON syntax, extended with a double curly braces syntax for injecting variables `{{variable}}`.
|
|
282
|
+
* Those variables are resolved at the time of the webhook's dispatch, and a list of available variables with their descriptions
|
|
283
|
+
* is available in the [Apify webhook documentation](https://docs.apify.com/webhooks).
|
|
284
|
+
* If `headersTemplate` is omitted, no extra headers are added
|
|
285
|
+
* ([view docs](https://docs.apify.com/platform/integrations/webhooks/actions#headers-template)).
|
|
286
|
+
*/
|
|
287
|
+
headersTemplate?: string;
|
|
288
|
+
/**
|
|
289
|
+
* A description of the webhook.
|
|
290
|
+
*/
|
|
291
|
+
description?: string;
|
|
292
|
+
/**
|
|
293
|
+
* If true, the webhook will ignore SSL errors when sending the request.
|
|
294
|
+
*/
|
|
295
|
+
ignoreSslErrors?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* If true, the webhook will not retry on failure.
|
|
298
|
+
*/
|
|
299
|
+
doNotRetry?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* If true, the webhook will interpolate strings in the payloadTemplate and headersTemplate.
|
|
302
|
+
*/
|
|
303
|
+
shouldInterpolateStrings?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* If true, indicates the webhook is an Apify integration.
|
|
306
|
+
*/
|
|
307
|
+
isApifyIntegration?: boolean;
|
|
191
308
|
}
|
|
192
309
|
export interface MetamorphOptions {
|
|
193
310
|
/**
|
|
194
311
|
* Content type for the `input`. If not specified,
|
|
195
312
|
* `input` is expected to be an object that will be stringified to JSON and content type set to
|
|
196
313
|
* `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
|
|
197
|
-
* `
|
|
314
|
+
* `Buffer`.
|
|
198
315
|
*/
|
|
199
316
|
contentType?: string;
|
|
200
317
|
/**
|
|
@@ -206,16 +323,13 @@ export interface MetamorphOptions {
|
|
|
206
323
|
customAfterSleepMillis?: number;
|
|
207
324
|
}
|
|
208
325
|
export interface RebootOptions {
|
|
209
|
-
/** @internal */
|
|
210
|
-
customAfterSleepMillis?: number;
|
|
211
|
-
}
|
|
212
|
-
export interface OpenStorageOptions {
|
|
213
326
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* @default false
|
|
327
|
+
* Amount of time, in seconds, to wait for the `persistState` and `migrating` event handlers before rebooting.
|
|
328
|
+
* @default 30
|
|
217
329
|
*/
|
|
218
|
-
|
|
330
|
+
timeoutSecs?: number;
|
|
331
|
+
/** @internal */
|
|
332
|
+
customAfterSleepMillis?: number;
|
|
219
333
|
}
|
|
220
334
|
export { ClientActorRun as ActorRun };
|
|
221
335
|
/**
|
|
@@ -235,13 +349,12 @@ export declare const EXIT_CODES: {
|
|
|
235
349
|
* See {@link Configuration} for details about what can be configured and what are the default values.
|
|
236
350
|
*/
|
|
237
351
|
export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
238
|
-
|
|
239
|
-
static _instance: Actor;
|
|
352
|
+
#private;
|
|
240
353
|
/**
|
|
241
354
|
* Configuration of this SDK instance (provided to its constructor). See {@link Configuration} for details.
|
|
242
355
|
* @internal
|
|
243
356
|
*/
|
|
244
|
-
readonly
|
|
357
|
+
readonly configuration: Configuration;
|
|
245
358
|
/**
|
|
246
359
|
* Default {@link ApifyClient} instance.
|
|
247
360
|
* @internal
|
|
@@ -256,17 +369,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
256
369
|
* Whether the Actor instance was initialized. This is set by calling {@link Actor.init}.
|
|
257
370
|
*/
|
|
258
371
|
initialized: boolean;
|
|
259
|
-
|
|
260
|
-
* Set if the Actor called a method that requires the instance to be initialized, but did not do so.
|
|
261
|
-
* A call to `init` after this warning is emitted is considered an invalid state and will throw an error.
|
|
262
|
-
*/
|
|
263
|
-
private warnedAboutMissingInitCall;
|
|
264
|
-
/**
|
|
265
|
-
* Set if the Actor is currently rebooting.
|
|
266
|
-
*/
|
|
267
|
-
private isRebooting;
|
|
268
|
-
private chargingManager;
|
|
269
|
-
constructor(options?: ConfigurationOptions);
|
|
372
|
+
constructor(options?: ActorOptions);
|
|
270
373
|
/**
|
|
271
374
|
* Runs the main user function that performs the job of the Actor
|
|
272
375
|
* and terminates the process when the user function finishes.
|
|
@@ -302,24 +405,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
302
405
|
*
|
|
303
406
|
* If the user function returns a promise, it is considered asynchronous:
|
|
304
407
|
* ```js
|
|
305
|
-
* import { gotScraping } from 'got-scraping';
|
|
306
|
-
*
|
|
307
408
|
* await Actor.main(() => {
|
|
308
409
|
* // My asynchronous function that returns a promise
|
|
309
|
-
* return
|
|
310
|
-
*
|
|
311
|
-
*
|
|
410
|
+
* return fetch('http://www.example.com')
|
|
411
|
+
* .then((response) => response.text())
|
|
412
|
+
* .then((html) => {
|
|
413
|
+
* console.log(html);
|
|
414
|
+
* });
|
|
312
415
|
* });
|
|
313
416
|
* ```
|
|
314
417
|
*
|
|
315
418
|
* To simplify your code, you can take advantage of the `async`/`await` keywords:
|
|
316
419
|
*
|
|
317
420
|
* ```js
|
|
318
|
-
* import { gotScraping } from 'got-scraping';
|
|
319
|
-
*
|
|
320
421
|
* await Actor.main(async () => {
|
|
321
422
|
* // My asynchronous function
|
|
322
|
-
* const html = await
|
|
423
|
+
* const html = await fetch('http://www.example.com').then((response) => response.text());
|
|
323
424
|
* console.log(html);
|
|
324
425
|
* });
|
|
325
426
|
* ```
|
|
@@ -368,13 +469,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
368
469
|
* @param actorId
|
|
369
470
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
370
471
|
* @param [input]
|
|
371
|
-
* Input for the Actor.
|
|
372
|
-
*
|
|
373
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
472
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
473
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
374
474
|
* @param [options]
|
|
375
475
|
* @ignore
|
|
376
476
|
*/
|
|
377
|
-
call(actorId: string, input?:
|
|
477
|
+
call(actorId: string, input?: ActorInput, options?: CallOptions): Promise<ClientActorRun>;
|
|
378
478
|
/**
|
|
379
479
|
* Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
380
480
|
* unlike `Actor.call`, this method just starts the run without waiting for finish.
|
|
@@ -393,13 +493,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
393
493
|
* @param actorId
|
|
394
494
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
395
495
|
* @param [input]
|
|
396
|
-
* Input for the Actor.
|
|
397
|
-
*
|
|
398
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
496
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
497
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
399
498
|
* @param [options]
|
|
400
499
|
* @ignore
|
|
401
500
|
*/
|
|
402
|
-
start(actorId: string, input?:
|
|
501
|
+
start(actorId: string, input?: ActorInput, options?: StartOptions): Promise<ClientActorRun>;
|
|
403
502
|
/**
|
|
404
503
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
405
504
|
*
|
|
@@ -416,6 +515,25 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
416
515
|
* @ignore
|
|
417
516
|
*/
|
|
418
517
|
abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
|
|
518
|
+
/**
|
|
519
|
+
* Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
520
|
+
*
|
|
521
|
+
* Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
|
|
522
|
+
* status and keeps its default storages. Options you leave out keep the values of the original run.
|
|
523
|
+
*
|
|
524
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
525
|
+
*
|
|
526
|
+
* For more information about Actors, read the
|
|
527
|
+
* [documentation](https://docs.apify.com/actor).
|
|
528
|
+
*
|
|
529
|
+
* **Example usage:**
|
|
530
|
+
*
|
|
531
|
+
* ```js
|
|
532
|
+
* const run = await Actor.resurrect(runId);
|
|
533
|
+
* ```
|
|
534
|
+
* @ignore
|
|
535
|
+
*/
|
|
536
|
+
resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
|
|
419
537
|
/**
|
|
420
538
|
* Runs an actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
421
539
|
*
|
|
@@ -443,6 +561,43 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
443
561
|
* @ignore
|
|
444
562
|
*/
|
|
445
563
|
callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
|
|
564
|
+
/**
|
|
565
|
+
* Clients for the child runs started with the `runName` option, keyed by that name, including the runs started
|
|
566
|
+
* before a migration or resurrection of this run. Each client points to the current run under its name.
|
|
567
|
+
*
|
|
568
|
+
* ```js
|
|
569
|
+
* await Actor.childRuns['my-child'].waitForFinish();
|
|
570
|
+
* ```
|
|
571
|
+
*
|
|
572
|
+
* A run started with a custom `token` uses that token, except for a run started before a migration or
|
|
573
|
+
* resurrection, which uses the default client. The tracked runs, including the earlier runs replaced
|
|
574
|
+
* under the same name, are stored in the default key-value store under the `__ACTOR_CHILD_RUNS` key.
|
|
575
|
+
*/
|
|
576
|
+
get childRuns(): Record<string, RunClient>;
|
|
577
|
+
/**
|
|
578
|
+
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
579
|
+
* unlike `Actor.callTask`, this method just starts the run without waiting for finish.
|
|
580
|
+
*
|
|
581
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
582
|
+
*
|
|
583
|
+
* For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
|
|
584
|
+
*
|
|
585
|
+
* **Example usage:**
|
|
586
|
+
*
|
|
587
|
+
* ```js
|
|
588
|
+
* const run = await Actor.startTask('bob/some-task');
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @param taskId
|
|
592
|
+
* Allowed formats are `username/task-name`, `userId/task-name` or task ID.
|
|
593
|
+
* @param [input]
|
|
594
|
+
* Input overrides for the Actor task. If it is an object, it will be stringified to
|
|
595
|
+
* JSON and its content type set to `application/json; charset=utf-8`.
|
|
596
|
+
* Provided input will be merged with Actor task input.
|
|
597
|
+
* @param [options]
|
|
598
|
+
* @ignore
|
|
599
|
+
*/
|
|
600
|
+
startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
|
|
446
601
|
/**
|
|
447
602
|
* Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
|
|
448
603
|
* the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
|
|
@@ -451,13 +606,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
451
606
|
* @param targetActorId
|
|
452
607
|
* Either `username/actor-name` or Actor ID of an Actor to which we want to metamorph.
|
|
453
608
|
* @param [input]
|
|
454
|
-
* Input for the Actor.
|
|
455
|
-
*
|
|
456
|
-
* Otherwise, the `options.contentType` parameter must be provided.
|
|
609
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
610
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
457
611
|
* @param [options]
|
|
458
612
|
* @ignore
|
|
459
613
|
*/
|
|
460
|
-
metamorph(targetActorId: string, input?:
|
|
614
|
+
metamorph(targetActorId: string, input?: ActorInput, options?: MetamorphOptions): Promise<void>;
|
|
461
615
|
/**
|
|
462
616
|
* Internally reboots this Actor. The system stops the current container and starts
|
|
463
617
|
* a new container with the same run ID.
|
|
@@ -478,15 +632,16 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
478
632
|
* For more information, see the [Get webhook](https://apify.com/docs/api/v2#/reference/webhooks/webhook-object/get-webhook) API endpoint.
|
|
479
633
|
* @ignore
|
|
480
634
|
*/
|
|
481
|
-
addWebhook(options: WebhookOptions): Promise<
|
|
635
|
+
addWebhook(options: WebhookOptions): Promise<WebhookResource | undefined>;
|
|
482
636
|
/**
|
|
483
637
|
* Sets the status message for the current Actor run.
|
|
484
638
|
*
|
|
485
|
-
* @returns The
|
|
639
|
+
* @returns The updated Run object, or `undefined` when no run was updated: when run locally,
|
|
640
|
+
* or when the update failed or timed out (a warning is logged in that case).
|
|
486
641
|
* For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
|
|
487
642
|
* @ignore
|
|
488
643
|
*/
|
|
489
|
-
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
644
|
+
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
|
|
490
645
|
/**
|
|
491
646
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
492
647
|
*
|
|
@@ -507,37 +662,16 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
507
662
|
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
508
663
|
* otherwise the Actor process might finish before the data are stored!
|
|
509
664
|
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* @ignore
|
|
513
|
-
*/
|
|
514
|
-
pushData(item: Data | Data[]): Promise<void>;
|
|
515
|
-
/**
|
|
516
|
-
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
517
|
-
*
|
|
518
|
-
* This is just a convenient shortcut for {@link Dataset.pushData}.
|
|
519
|
-
* For example, calling the following code:
|
|
520
|
-
* ```js
|
|
521
|
-
* await Actor.pushData({ myValue: 123 });
|
|
522
|
-
* ```
|
|
523
|
-
*
|
|
524
|
-
* is equivalent to:
|
|
525
|
-
* ```js
|
|
526
|
-
* const dataset = await Actor.openDataset();
|
|
527
|
-
* await dataset.pushData({ myValue: 123 });
|
|
528
|
-
* ```
|
|
529
|
-
*
|
|
530
|
-
* For more information, see {@link Actor.openDataset} and {@link Dataset.pushData}
|
|
531
|
-
*
|
|
532
|
-
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
533
|
-
* otherwise the Actor process might finish before the data are stored!
|
|
665
|
+
* Inside a crawlee storage transaction, the items are stored - and charged for - at commit time,
|
|
666
|
+
* so the returned counts are zero and charging for an explicit `eventName` is rejected outright.
|
|
534
667
|
*
|
|
535
668
|
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
536
669
|
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
537
670
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
671
|
+
* Not supported in multi-tenant Server Actor runs, which charge per request with `Actor.charge()`.
|
|
538
672
|
* @ignore
|
|
539
673
|
*/
|
|
540
|
-
pushData(item: Data | Data[], eventName
|
|
674
|
+
pushData(item: Data | Data[], eventName?: string | undefined): Promise<ChargeResult>;
|
|
541
675
|
/**
|
|
542
676
|
* Opens a dataset and returns a promise resolving to an instance of the {@link Dataset} class.
|
|
543
677
|
*
|
|
@@ -548,12 +682,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
548
682
|
* For more details and code examples, see the {@link Dataset} class.
|
|
549
683
|
*
|
|
550
684
|
* @param [datasetIdOrName]
|
|
551
|
-
* ID or
|
|
685
|
+
* ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
|
|
552
686
|
* the function returns the default dataset associated with the Actor run.
|
|
687
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
688
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
553
689
|
* @param [options]
|
|
554
690
|
* @ignore
|
|
555
691
|
*/
|
|
556
|
-
openDataset(datasetIdOrName?:
|
|
692
|
+
openDataset(datasetIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<Dataset<Data>>;
|
|
557
693
|
/**
|
|
558
694
|
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
559
695
|
*
|
|
@@ -583,6 +719,35 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
583
719
|
* @ignore
|
|
584
720
|
*/
|
|
585
721
|
getValue<T = unknown>(key: string): Promise<T | null>;
|
|
722
|
+
/**
|
|
723
|
+
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
724
|
+
*
|
|
725
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getValue}.
|
|
726
|
+
* For example, calling the following code:
|
|
727
|
+
* ```js
|
|
728
|
+
* const value = await Actor.getValue('my-key');
|
|
729
|
+
* ```
|
|
730
|
+
*
|
|
731
|
+
* is equivalent to:
|
|
732
|
+
* ```js
|
|
733
|
+
* const store = await Actor.openKeyValueStore();
|
|
734
|
+
* const value = await store.getValue('my-key');
|
|
735
|
+
* ```
|
|
736
|
+
*
|
|
737
|
+
* To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
|
|
738
|
+
*
|
|
739
|
+
* For more information, see {@link Actor.openKeyValueStore}
|
|
740
|
+
* and {@link KeyValueStore.getValue}.
|
|
741
|
+
*
|
|
742
|
+
* @param key Unique record key.
|
|
743
|
+
* @param defaultValue Fallback that will be returned if no value if present in the storage.
|
|
744
|
+
* @returns
|
|
745
|
+
* Returns a promise that resolves to an object, string
|
|
746
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
747
|
+
* on the MIME content type of the record, or the provided default value.
|
|
748
|
+
* @ignore
|
|
749
|
+
*/
|
|
750
|
+
getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
586
751
|
/**
|
|
587
752
|
* Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
|
|
588
753
|
*
|
|
@@ -618,17 +783,21 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
618
783
|
/**
|
|
619
784
|
* Gets the Actor input value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
620
785
|
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* const input = await Actor.getInput();
|
|
625
|
-
* ```
|
|
786
|
+
* The input is the record stored under the configured input key (`ACTOR_INPUT_KEY`, default `INPUT`).
|
|
787
|
+
* A record stored as `application/octet-stream` — which is what a local input file without an
|
|
788
|
+
* extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
|
|
626
789
|
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
790
|
+
* When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
|
|
791
|
+
* working directory. A storage backend that doesn't read the default key-value store's directory under
|
|
792
|
+
* the storage directory (e.g. in-memory storage) also gets the file `apify run` writes there.
|
|
793
|
+
*
|
|
794
|
+
* Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
|
|
795
|
+
* replaced with the links of their CSV exports.
|
|
796
|
+
*
|
|
797
|
+
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
|
|
798
|
+
* found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
|
|
799
|
+
* (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
|
|
800
|
+
* Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest.
|
|
632
801
|
*
|
|
633
802
|
* Note that the `getInput()` function does not cache the value read from the key-value store.
|
|
634
803
|
* If you need to use the input multiple times in your Actor,
|
|
@@ -640,16 +809,20 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
640
809
|
* @returns
|
|
641
810
|
* Returns a promise that resolves to an object, string
|
|
642
811
|
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
643
|
-
* on the MIME content type of the record
|
|
644
|
-
*
|
|
812
|
+
* on the MIME content type of the record.
|
|
813
|
+
* @throws {ActorInputError} When the input cannot be produced; see `code`.
|
|
645
814
|
* @ignore
|
|
646
815
|
*/
|
|
647
|
-
getInput<T = Dictionary | string | Buffer>(): Promise<T
|
|
816
|
+
getInput<T = Dictionary | string | Buffer>(): Promise<T>;
|
|
648
817
|
/**
|
|
649
|
-
*
|
|
650
|
-
*
|
|
818
|
+
* Reads the input from a `<inputKey>` or `<inputKey>.json` file in the given directory, for local runs
|
|
819
|
+
* whose default key-value store holds no input record. Mirrors how `ApifyFileSystemStorageBackend` adopts
|
|
820
|
+
* such files inside the store directory: the `.json` file is JSON, the bare one is bytes that
|
|
821
|
+
* {@link parseInputValue} tries as JSON5. Both files present is an error rather than a guess.
|
|
822
|
+
*
|
|
823
|
+
* @returns `undefined` when running on the platform or when neither file exists.
|
|
651
824
|
*/
|
|
652
|
-
|
|
825
|
+
private readInputFromDirectory;
|
|
653
826
|
/**
|
|
654
827
|
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
655
828
|
*
|
|
@@ -660,12 +833,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
660
833
|
* For more details and code examples, see the {@link KeyValueStore} class.
|
|
661
834
|
*
|
|
662
835
|
* @param [storeIdOrName]
|
|
663
|
-
* ID or
|
|
836
|
+
* ID, name, or alias of the key-value store to be opened. If `null` or `undefined`,
|
|
664
837
|
* the function returns the default key-value store associated with the Actor run.
|
|
838
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
839
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
665
840
|
* @param [options]
|
|
666
841
|
* @ignore
|
|
667
842
|
*/
|
|
668
|
-
openKeyValueStore(storeIdOrName?:
|
|
843
|
+
openKeyValueStore(storeIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
|
|
669
844
|
/**
|
|
670
845
|
* Opens a request queue and returns a promise resolving to an instance
|
|
671
846
|
* of the {@link RequestQueue} class.
|
|
@@ -678,12 +853,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
678
853
|
* For more details and code examples, see the {@link RequestQueue} class.
|
|
679
854
|
*
|
|
680
855
|
* @param [queueIdOrName]
|
|
681
|
-
* ID or
|
|
856
|
+
* ID, name, or alias of the request queue to be opened. If `null` or `undefined`,
|
|
682
857
|
* the function returns the default request queue associated with the Actor run.
|
|
858
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
859
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
683
860
|
* @param [options]
|
|
684
861
|
* @ignore
|
|
685
862
|
*/
|
|
686
|
-
openRequestQueue(queueIdOrName?:
|
|
863
|
+
openRequestQueue(queueIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<RequestQueue>;
|
|
687
864
|
/**
|
|
688
865
|
* Creates a proxy configuration and returns a promise resolving to an instance
|
|
689
866
|
* of the {@link ProxyConfiguration} class that is already initialized.
|
|
@@ -718,6 +895,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
718
895
|
* ```
|
|
719
896
|
* { useApifyProxy: false }
|
|
720
897
|
* ```
|
|
898
|
+
*
|
|
899
|
+
* As part of the init process, we verify the configuration by checking the proxy status endpoint.
|
|
900
|
+
* This can make the init slower, to opt-out of this, use `checkAccess: false` (defaults to `true`).
|
|
901
|
+
*
|
|
721
902
|
* @ignore
|
|
722
903
|
*/
|
|
723
904
|
createProxyConfiguration(proxyConfigurationOptions?: ProxyConfigurationOptions & {
|
|
@@ -729,6 +910,18 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
729
910
|
* This method attempts to charge for the specified number of events, but may charge fewer
|
|
730
911
|
* if doing so would exceed the total budget limit (`maxTotalChargeUsd`).
|
|
731
912
|
*
|
|
913
|
+
* **Important:** When using the `count` parameter to charge for multiple events at once,
|
|
914
|
+
* be aware that the charge may be partially fulfilled — i.e. `chargedCount` can be less
|
|
915
|
+
* than the requested `count`. Always check the returned `chargedCount` to know how many
|
|
916
|
+
* events were actually charged, and only perform that much work. If your work is
|
|
917
|
+
* meaningfully divisible into individual units, prefer calling `charge()` once per unit
|
|
918
|
+
* rather than batching via `count` — this gives finer control over budget consumption
|
|
919
|
+
* and avoids situations where more work is requested than the budget allows.
|
|
920
|
+
*
|
|
921
|
+
* **Note:** `idempotencyKey` is scoped to the whole run, not to `requestId`. In a multi-tenant
|
|
922
|
+
* Server Actor run, a key reused across requests charges only the first caller, so it must
|
|
923
|
+
* be globally unique (e.g. derived from `requestId`).
|
|
924
|
+
*
|
|
732
925
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
733
926
|
* @ignore
|
|
734
927
|
*/
|
|
@@ -738,6 +931,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
738
931
|
* @ignore
|
|
739
932
|
*/
|
|
740
933
|
getChargingManager(): ChargingManager;
|
|
934
|
+
/**
|
|
935
|
+
* Fetches the current Actor run from the Apify API. The result is cached for the lifetime of the Actor,
|
|
936
|
+
* so use `Actor.apifyClient.run(runId).get()` instead when you need fresh data such as the run status.
|
|
937
|
+
* Resolves to `undefined` when not running on the Apify platform.
|
|
938
|
+
*/
|
|
939
|
+
getCurrentRun(): Promise<ClientActorRun | undefined>;
|
|
741
940
|
/**
|
|
742
941
|
* Modifies Actor env vars so parsing respects the structure of {@link ApifyEnv} interface.
|
|
743
942
|
*/
|
|
@@ -746,7 +945,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
746
945
|
* Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
|
|
747
946
|
*
|
|
748
947
|
* For the list of the Apify environment variables, see
|
|
749
|
-
* [Actor documentation](https://docs.apify.com/
|
|
948
|
+
* [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
|
|
750
949
|
* If some variables are not defined or are invalid, the corresponding value in the resulting object will be null.
|
|
751
950
|
* @ignore
|
|
752
951
|
*/
|
|
@@ -820,24 +1019,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
820
1019
|
*
|
|
821
1020
|
* If the user function returns a promise, it is considered asynchronous:
|
|
822
1021
|
* ```js
|
|
823
|
-
* import { gotScraping } from 'got-scraping';
|
|
824
|
-
*
|
|
825
1022
|
* await Actor.main(() => {
|
|
826
1023
|
* // My asynchronous function that returns a promise
|
|
827
|
-
* return
|
|
828
|
-
*
|
|
829
|
-
*
|
|
1024
|
+
* return fetch('http://www.example.com')
|
|
1025
|
+
* .then((response) => response.text())
|
|
1026
|
+
* .then((html) => {
|
|
1027
|
+
* console.log(html);
|
|
1028
|
+
* });
|
|
830
1029
|
* });
|
|
831
1030
|
* ```
|
|
832
1031
|
*
|
|
833
1032
|
* To simplify your code, you can take advantage of the `async`/`await` keywords:
|
|
834
1033
|
*
|
|
835
1034
|
* ```js
|
|
836
|
-
* import { gotScraping } from 'got-scraping';
|
|
837
|
-
*
|
|
838
1035
|
* await Actor.main(async () => {
|
|
839
1036
|
* // My asynchronous function
|
|
840
|
-
* const html = await
|
|
1037
|
+
* const html = await fetch('http://www.example.com').then((response) => response.text());
|
|
841
1038
|
* console.log(html);
|
|
842
1039
|
* });
|
|
843
1040
|
* ```
|
|
@@ -857,12 +1054,15 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
857
1054
|
* Calling `Actor.exit()` is required if you use the `Actor.init()` method, since it opens websocket connection
|
|
858
1055
|
* (see {@link Actor.events} for details), which needs to be terminated for the code to finish.
|
|
859
1056
|
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
1057
|
+
* **Graceful shutdown:** When running on the Apify platform, the Actor may receive `aborting` or `migrating`
|
|
1058
|
+
* events. By default, the SDK will automatically call `Actor.exit()` on `aborting` events and `Actor.reboot()`
|
|
1059
|
+
* on `migrating` events (to speed up the migration and continue the run on a new worker). You can disable this
|
|
1060
|
+
* behavior by setting `options.gracefulShutdown` to `false`.
|
|
862
1061
|
*
|
|
1062
|
+
* ```js
|
|
863
1063
|
* await Actor.init();
|
|
864
1064
|
*
|
|
865
|
-
* const html = await
|
|
1065
|
+
* const html = await fetch('http://www.example.com').then((response) => response.text());
|
|
866
1066
|
* console.log(html);
|
|
867
1067
|
*
|
|
868
1068
|
* await Actor.exit();
|
|
@@ -903,12 +1103,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
903
1103
|
* @param actorId
|
|
904
1104
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
905
1105
|
* @param [input]
|
|
906
|
-
* Input for the Actor.
|
|
907
|
-
*
|
|
908
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
1106
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
1107
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
909
1108
|
* @param [options]
|
|
910
1109
|
*/
|
|
911
|
-
static call(actorId: string, input?:
|
|
1110
|
+
static call(actorId: string, input?: ActorInput, options?: CallOptions): Promise<ClientActorRun>;
|
|
912
1111
|
/**
|
|
913
1112
|
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
914
1113
|
*
|
|
@@ -935,6 +1134,29 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
935
1134
|
* @param [options]
|
|
936
1135
|
*/
|
|
937
1136
|
static callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
1139
|
+
* unlike `Actor.callTask`, this method just starts the run without waiting for finish.
|
|
1140
|
+
*
|
|
1141
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
1142
|
+
*
|
|
1143
|
+
* For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
|
|
1144
|
+
*
|
|
1145
|
+
* **Example usage:**
|
|
1146
|
+
*
|
|
1147
|
+
* ```js
|
|
1148
|
+
* const run = await Actor.startTask('bob/some-task');
|
|
1149
|
+
* ```
|
|
1150
|
+
*
|
|
1151
|
+
* @param taskId
|
|
1152
|
+
* Allowed formats are `username/task-name`, `userId/task-name` or task ID.
|
|
1153
|
+
* @param [input]
|
|
1154
|
+
* Input overrides for the Actor task. If it is an object, it will be stringified to
|
|
1155
|
+
* JSON and its content type set to `application/json; charset=utf-8`.
|
|
1156
|
+
* Provided input will be merged with Actor task input.
|
|
1157
|
+
* @param [options]
|
|
1158
|
+
*/
|
|
1159
|
+
static startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
|
|
938
1160
|
/**
|
|
939
1161
|
* Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
940
1162
|
* unlike `Actor.call`, this method just starts the run without waiting for finish.
|
|
@@ -953,12 +1175,24 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
953
1175
|
* @param actorId
|
|
954
1176
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
955
1177
|
* @param [input]
|
|
956
|
-
* Input for the Actor.
|
|
957
|
-
*
|
|
958
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
1178
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
1179
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
959
1180
|
* @param [options]
|
|
960
1181
|
*/
|
|
961
|
-
static start(actorId: string, input?: Dictionary, options?:
|
|
1182
|
+
static start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ClientActorRun>;
|
|
1183
|
+
/**
|
|
1184
|
+
* Clients for the child runs started with the `runName` option, keyed by that name, including the runs started
|
|
1185
|
+
* before a migration or resurrection of this run. Each client points to the current run under its name.
|
|
1186
|
+
*
|
|
1187
|
+
* ```js
|
|
1188
|
+
* await Actor.childRuns['my-child'].waitForFinish();
|
|
1189
|
+
* ```
|
|
1190
|
+
*
|
|
1191
|
+
* A run started with a custom `token` uses that token, except for a run started before a migration or
|
|
1192
|
+
* resurrection, which uses the default client. The tracked runs, including the earlier runs replaced
|
|
1193
|
+
* under the same name, are stored in the default key-value store under the `__ACTOR_CHILD_RUNS` key.
|
|
1194
|
+
*/
|
|
1195
|
+
static get childRuns(): Record<string, RunClient>;
|
|
962
1196
|
/**
|
|
963
1197
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
964
1198
|
*
|
|
@@ -974,6 +1208,24 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
974
1208
|
* ```
|
|
975
1209
|
*/
|
|
976
1210
|
static abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
|
|
1211
|
+
/**
|
|
1212
|
+
* Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
1213
|
+
*
|
|
1214
|
+
* Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
|
|
1215
|
+
* status and keeps its default storages. Options you leave out keep the values of the original run.
|
|
1216
|
+
*
|
|
1217
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
1218
|
+
*
|
|
1219
|
+
* For more information about Actors, read the
|
|
1220
|
+
* [documentation](https://docs.apify.com/actor).
|
|
1221
|
+
*
|
|
1222
|
+
* **Example usage:**
|
|
1223
|
+
*
|
|
1224
|
+
* ```js
|
|
1225
|
+
* const run = await Actor.resurrect(runId);
|
|
1226
|
+
* ```
|
|
1227
|
+
*/
|
|
1228
|
+
static resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
|
|
977
1229
|
/**
|
|
978
1230
|
* Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
|
|
979
1231
|
* the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
|
|
@@ -982,12 +1234,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
982
1234
|
* @param targetActorId
|
|
983
1235
|
* Either `username/actor-name` or Actor ID of an Actor to which we want to metamorph.
|
|
984
1236
|
* @param [input]
|
|
985
|
-
* Input for the Actor.
|
|
986
|
-
*
|
|
987
|
-
* Otherwise, the `options.contentType` parameter must be provided.
|
|
1237
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
1238
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
988
1239
|
* @param [options]
|
|
989
1240
|
*/
|
|
990
|
-
static metamorph(targetActorId: string, input?:
|
|
1241
|
+
static metamorph(targetActorId: string, input?: ActorInput, options?: MetamorphOptions): Promise<void>;
|
|
991
1242
|
/**
|
|
992
1243
|
* Internally reboots this Actor run. The system stops the current container and starts
|
|
993
1244
|
* a new container with the same run id.
|
|
@@ -1005,7 +1256,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1005
1256
|
* @returns The return value is the Webhook object.
|
|
1006
1257
|
* For more information, see the [Get webhook](https://apify.com/docs/api/v2#/reference/webhooks/webhook-object/get-webhook) API endpoint.
|
|
1007
1258
|
*/
|
|
1008
|
-
static addWebhook(options: WebhookOptions): Promise<
|
|
1259
|
+
static addWebhook(options: WebhookOptions): Promise<WebhookResource | undefined>;
|
|
1009
1260
|
/**
|
|
1010
1261
|
* Sets the status message for the current Actor run.
|
|
1011
1262
|
*
|
|
@@ -1013,10 +1264,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1013
1264
|
* @param [options]
|
|
1014
1265
|
* @param [options.isStatusMessageTerminal] If `true`, the status message will be marked as terminal.
|
|
1015
1266
|
* This is required for the last status message of the run. Default value is `false`.
|
|
1016
|
-
* @returns The
|
|
1267
|
+
* @returns The updated Run object, or `undefined` when no run was updated: when run locally,
|
|
1268
|
+
* or when the update failed or timed out (a warning is logged in that case).
|
|
1017
1269
|
* For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
|
|
1018
1270
|
*/
|
|
1019
|
-
static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
1271
|
+
static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
|
|
1020
1272
|
/**
|
|
1021
1273
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
1022
1274
|
*
|
|
@@ -1061,9 +1313,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1061
1313
|
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
1062
1314
|
* otherwise the Actor process might finish before the data are stored!
|
|
1063
1315
|
*
|
|
1316
|
+
* Charging is rejected inside a crawlee storage transaction, where the items would only be stored
|
|
1317
|
+
* at commit while the charge happens immediately - use `withDirectStorageAccess()` to opt out of
|
|
1318
|
+
* the transaction, or push without an event name and charge separately.
|
|
1319
|
+
*
|
|
1064
1320
|
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
1065
1321
|
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
1066
1322
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
1323
|
+
* Not supported in multi-tenant Server Actor runs, which charge per request with `Actor.charge()`.
|
|
1067
1324
|
*/
|
|
1068
1325
|
static pushData<Data extends Dictionary = Dictionary>(item: Data | Data[], eventName: string): Promise<ChargeResult>;
|
|
1069
1326
|
/**
|
|
@@ -1076,11 +1333,13 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1076
1333
|
* For more details and code examples, see the {@link Dataset} class.
|
|
1077
1334
|
*
|
|
1078
1335
|
* @param [datasetIdOrName]
|
|
1079
|
-
* ID or
|
|
1336
|
+
* ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
|
|
1080
1337
|
* the function returns the default dataset associated with the Actor run.
|
|
1338
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
1339
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1081
1340
|
* @param [options]
|
|
1082
1341
|
*/
|
|
1083
|
-
static openDataset<Data extends Dictionary = Dictionary>(datasetIdOrName?:
|
|
1342
|
+
static openDataset<Data extends Dictionary = Dictionary>(datasetIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<Dataset<Data>>;
|
|
1084
1343
|
/**
|
|
1085
1344
|
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1086
1345
|
*
|
|
@@ -1109,6 +1368,34 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1109
1368
|
* if the record is missing.
|
|
1110
1369
|
*/
|
|
1111
1370
|
static getValue<T = unknown>(key: string): Promise<T | null>;
|
|
1371
|
+
/**
|
|
1372
|
+
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1373
|
+
*
|
|
1374
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getValue}.
|
|
1375
|
+
* For example, calling the following code:
|
|
1376
|
+
* ```js
|
|
1377
|
+
* const value = await Actor.getValue('my-key');
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* is equivalent to:
|
|
1381
|
+
* ```js
|
|
1382
|
+
* const store = await Actor.openKeyValueStore();
|
|
1383
|
+
* const value = await store.getValue('my-key');
|
|
1384
|
+
* ```
|
|
1385
|
+
*
|
|
1386
|
+
* To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
|
|
1387
|
+
*
|
|
1388
|
+
* For more information, see {@link Actor.openKeyValueStore}
|
|
1389
|
+
* and {@link KeyValueStore.getValue}.
|
|
1390
|
+
*
|
|
1391
|
+
* @param key Unique record key.
|
|
1392
|
+
* @param defaultValue Fallback that will be returned if no value if present in the storage.
|
|
1393
|
+
* @returns
|
|
1394
|
+
* Returns a promise that resolves to an object, string
|
|
1395
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
1396
|
+
* on the MIME content type of the record, or the provided default value.
|
|
1397
|
+
*/
|
|
1398
|
+
static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
1112
1399
|
/**
|
|
1113
1400
|
* Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
|
|
1114
1401
|
*
|
|
@@ -1143,16 +1430,31 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1143
1430
|
/**
|
|
1144
1431
|
* Gets the Actor input value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1145
1432
|
*
|
|
1146
|
-
*
|
|
1147
|
-
* For example, calling the following code:
|
|
1433
|
+
* The input is the record stored under the configured input key (`ACTOR_INPUT_KEY`, default `INPUT`):
|
|
1148
1434
|
* ```js
|
|
1149
1435
|
* const input = await Actor.getInput();
|
|
1150
1436
|
* ```
|
|
1151
1437
|
*
|
|
1152
|
-
* is
|
|
1438
|
+
* A record stored as `application/octet-stream` — which is what a local input file without an
|
|
1439
|
+
* extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
|
|
1440
|
+
*
|
|
1441
|
+
* When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
|
|
1442
|
+
* working directory.
|
|
1443
|
+
*
|
|
1444
|
+
* Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
|
|
1445
|
+
* replaced with the links of their CSV exports.
|
|
1446
|
+
*
|
|
1447
|
+
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
|
|
1448
|
+
* found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
|
|
1449
|
+
* (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
|
|
1450
|
+
* Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest:
|
|
1153
1451
|
* ```js
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1452
|
+
* let input = {};
|
|
1453
|
+
* try {
|
|
1454
|
+
* input = await Actor.getInput();
|
|
1455
|
+
* } catch (error) {
|
|
1456
|
+
* if (!(error instanceof ActorInputError) || error.code !== 'NOT_FOUND') throw error;
|
|
1457
|
+
* }
|
|
1156
1458
|
* ```
|
|
1157
1459
|
*
|
|
1158
1460
|
* Note that the `getInput()` function does not cache the value read from the key-value store.
|
|
@@ -1164,15 +1466,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1164
1466
|
* @returns
|
|
1165
1467
|
* Returns a promise that resolves to an object, string
|
|
1166
1468
|
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
1167
|
-
* on the MIME content type of the record
|
|
1168
|
-
*
|
|
1169
|
-
*/
|
|
1170
|
-
static getInput<T = Dictionary | string | Buffer>(): Promise<T | null>;
|
|
1171
|
-
/**
|
|
1172
|
-
* Gets the Actor input value just like the {@link Actor.getInput} method,
|
|
1173
|
-
* but throws if it is not found.
|
|
1469
|
+
* on the MIME content type of the record.
|
|
1470
|
+
* @throws {ActorInputError} When the input cannot be produced; see `code`.
|
|
1174
1471
|
*/
|
|
1175
|
-
static
|
|
1472
|
+
static getInput<T = Dictionary | string | Buffer>(): Promise<T>;
|
|
1176
1473
|
/**
|
|
1177
1474
|
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
1178
1475
|
*
|
|
@@ -1185,9 +1482,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1185
1482
|
* @param [storeIdOrName]
|
|
1186
1483
|
* ID or name of the key-value store to be opened. If `null` or `undefined`,
|
|
1187
1484
|
* the function returns the default key-value store associated with the Actor run.
|
|
1485
|
+
* You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1188
1486
|
* @param [options]
|
|
1189
1487
|
*/
|
|
1190
|
-
static openKeyValueStore(storeIdOrName?:
|
|
1488
|
+
static openKeyValueStore(storeIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
|
|
1191
1489
|
/**
|
|
1192
1490
|
* Opens a request queue and returns a promise resolving to an instance
|
|
1193
1491
|
* of the {@link RequestQueue} class.
|
|
@@ -1202,9 +1500,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1202
1500
|
* @param [queueIdOrName]
|
|
1203
1501
|
* ID or name of the request queue to be opened. If `null` or `undefined`,
|
|
1204
1502
|
* the function returns the default request queue associated with the Actor run.
|
|
1503
|
+
* You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1205
1504
|
* @param [options]
|
|
1206
1505
|
*/
|
|
1207
|
-
static openRequestQueue(queueIdOrName?:
|
|
1506
|
+
static openRequestQueue(queueIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<RequestQueue>;
|
|
1208
1507
|
/**
|
|
1209
1508
|
* Creates a proxy configuration and returns a promise resolving to an instance
|
|
1210
1509
|
* of the {@link ProxyConfiguration} class that is already initialized.
|
|
@@ -1239,6 +1538,9 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1239
1538
|
* ```
|
|
1240
1539
|
* { useApifyProxy: false }
|
|
1241
1540
|
* ```
|
|
1541
|
+
*
|
|
1542
|
+
* As part of the init process, we verify the configuration by checking the proxy status endpoint.
|
|
1543
|
+
* This can make the init slower, to opt-out of this, use `checkAccess: false` (defaults to `true`).
|
|
1242
1544
|
*/
|
|
1243
1545
|
static createProxyConfiguration(proxyConfigurationOptions?: ProxyConfigurationOptions & {
|
|
1244
1546
|
useApifyProxy?: boolean;
|
|
@@ -1249,6 +1551,18 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1249
1551
|
* This method attempts to charge for the specified number of events, but may charge fewer
|
|
1250
1552
|
* if doing so would exceed the total budget limit (`maxTotalChargeUsd`).
|
|
1251
1553
|
*
|
|
1554
|
+
* **Important:** When using the `count` parameter to charge for multiple events at once,
|
|
1555
|
+
* be aware that the charge may be partially fulfilled — i.e. `chargedCount` can be less
|
|
1556
|
+
* than the requested `count`. Always check the returned `chargedCount` to know how many
|
|
1557
|
+
* events were actually charged, and only perform that much work. If your work is
|
|
1558
|
+
* meaningfully divisible into individual units, prefer calling `charge()` once per unit
|
|
1559
|
+
* rather than batching via `count` — this gives finer control over budget consumption
|
|
1560
|
+
* and avoids situations where more work is requested than the budget allows.
|
|
1561
|
+
*
|
|
1562
|
+
* **Note:** `idempotencyKey` is scoped to the whole run, not to `requestId`. In a multi-tenant
|
|
1563
|
+
* Server Actor run, a key reused across requests charges only the first caller, so it must
|
|
1564
|
+
* be globally unique (e.g. derived from `requestId`).
|
|
1565
|
+
*
|
|
1252
1566
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
1253
1567
|
*/
|
|
1254
1568
|
static charge(options: ChargeOptions): Promise<ChargeResult>;
|
|
@@ -1260,7 +1574,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1260
1574
|
* Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
|
|
1261
1575
|
*
|
|
1262
1576
|
* For the list of the Apify environment variables, see
|
|
1263
|
-
* [Actor documentation](https://docs.apify.com/
|
|
1577
|
+
* [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
|
|
1264
1578
|
* If some of the variables are not defined or are invalid, the corresponding value in the resulting object will be null.
|
|
1265
1579
|
*/
|
|
1266
1580
|
static getEnv(): ApifyEnv;
|
|
@@ -1276,13 +1590,43 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1276
1590
|
* Returns `true` when code is running on Apify platform and `false` otherwise (for example locally).
|
|
1277
1591
|
*/
|
|
1278
1592
|
static isAtHome(): boolean;
|
|
1593
|
+
/**
|
|
1594
|
+
* Fetches the current Actor run from the Apify API. The result is cached for the lifetime of the Actor,
|
|
1595
|
+
* so use `Actor.apifyClient.run(runId).get()` instead when you need fresh data such as the run status.
|
|
1596
|
+
* Resolves to `undefined` when not running on the Apify platform.
|
|
1597
|
+
*/
|
|
1598
|
+
static getCurrentRun(): Promise<ClientActorRun | undefined>;
|
|
1279
1599
|
/** Default {@link ApifyClient} instance. */
|
|
1280
1600
|
static get apifyClient(): ApifyClient;
|
|
1281
1601
|
/** Default {@link Configuration} instance. */
|
|
1282
|
-
static get
|
|
1602
|
+
static get configuration(): Configuration;
|
|
1283
1603
|
/** @internal */
|
|
1284
1604
|
static getDefaultInstance(): Actor;
|
|
1285
|
-
|
|
1286
|
-
|
|
1605
|
+
/**
|
|
1606
|
+
* Replaces or clears the cached default instance returned by {@link Actor.getDefaultInstance}.
|
|
1607
|
+
* @internal
|
|
1608
|
+
*/
|
|
1609
|
+
static setDefaultInstance(instance?: Actor): void;
|
|
1610
|
+
/**
|
|
1611
|
+
* The same choice crawlee's `ServiceLocator` makes for its implicit default backend, with the
|
|
1612
|
+
* input-aware {@link ApifyFileSystemStorageBackend} in place of crawlee's — crawlee has no
|
|
1613
|
+
* notion of a run input.
|
|
1614
|
+
*/
|
|
1615
|
+
private createLocalStorageBackend;
|
|
1616
|
+
/**
|
|
1617
|
+
* crawlee's service locator is set-once, so a backend registered before `init()` wins and the
|
|
1618
|
+
* Actor cannot install its own over it. Replaces the resulting `ServiceConflictError` with the
|
|
1619
|
+
* way out.
|
|
1620
|
+
*/
|
|
1621
|
+
private installStorageBackend;
|
|
1622
|
+
private ensureActorInit;
|
|
1623
|
+
/**
|
|
1624
|
+
* Get time remaining from the Actor run timeout in seconds, rounded up to whole seconds with minimum value of 1 second.
|
|
1625
|
+
*
|
|
1626
|
+
* The API treats a 0 second timeout as no timeout, the minimum acceptable timeout is 1 second.
|
|
1627
|
+
*
|
|
1628
|
+
* Returns `undefined` if not on the Apify platform or the current run was started without a timeout.
|
|
1629
|
+
*/
|
|
1630
|
+
private getRemainingTimeSecs;
|
|
1631
|
+
private inferDefaultsFromInputSchema;
|
|
1287
1632
|
}
|
|
1288
|
-
//# sourceMappingURL=actor.d.ts.map
|