apify 4.0.0-rc.0 → 4.0.0-rc.2
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/dist/actor.d.ts +249 -164
- package/dist/actor.js +361 -179
- package/dist/apify_key_value_store_backend.js +1 -0
- package/dist/apify_request_queue_backend.d.ts +1 -1
- package/dist/apify_request_queue_backend.js +1 -1
- package/dist/apify_request_queue_shared_backend.d.ts +2 -2
- package/dist/apify_request_queue_shared_backend.js +4 -4
- package/dist/apify_storage_backend.js +7 -14
- package/dist/charging.d.ts +27 -6
- package/dist/charging.js +168 -62
- package/dist/charging_storage_backend.js +6 -2
- package/dist/child_run_tracker.d.ts +88 -0
- package/dist/child_run_tracker.js +239 -0
- package/dist/configuration.d.ts +20 -2
- package/dist/configuration.js +39 -2
- package/dist/errors.d.ts +2 -2
- package/dist/google_sheets.d.ts +12 -0
- package/dist/google_sheets.js +26 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/platform_event_manager.d.ts +22 -6
- package/dist/platform_event_manager.js +206 -36
- package/dist/proxy_configuration.js +6 -2
- package/dist/utils.d.ts +5 -3
- package/dist/utils.js +14 -13
- package/package.json +33 -35
package/dist/actor.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { EventManager, EventTypeName, RecordOptions, UseStateOptions } from '@crawlee/core';
|
|
2
2
|
import { Dataset, KeyValueStore, RequestQueue } from '@crawlee/core';
|
|
3
3
|
import type { Awaitable, Dictionary, StorageBackend } from '@crawlee/types';
|
|
4
|
-
import type { ActorCallOptions, ActorInput, ActorStartOptions, ApifyClientOptions, RunAbortOptions, TaskCallOptions, WebhookResource, WebhookEventType } from 'apify-client';
|
|
4
|
+
import type { ActorCallOptions, ActorInput, ActorStartOptions, ApifyClientOptions, RunAbortOptions, RunClient, RunResurrectOptions, TaskCallOptions, TaskStartOptions, WebhookResource, WebhookEventType } from 'apify-client';
|
|
5
5
|
import { ApifyClient, Run as ClientActorRun } from 'apify-client';
|
|
6
|
-
import { type ACTOR_PERMISSION_LEVEL } from '@apify/consts';
|
|
7
6
|
import type { RequestQueueAccessMode } from './apify_request_queue_backend.js';
|
|
8
7
|
import type { ChargeOptions, ChargeResult } from './charging.js';
|
|
9
8
|
import { ChargingManager } from './charging.js';
|
|
@@ -84,128 +83,6 @@ export interface SetStatusMessageOptions {
|
|
|
84
83
|
/** Log level used when the status message is also logged locally. Defaults to `INFO`. */
|
|
85
84
|
level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
86
85
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Parsed representation of the Apify environment variables.
|
|
89
|
-
* This object is returned by the {@link Actor.getEnv} function.
|
|
90
|
-
*/
|
|
91
|
-
export interface ApifyEnv {
|
|
92
|
-
/**
|
|
93
|
-
* ID of the Actor (ACTOR_ID)
|
|
94
|
-
*/
|
|
95
|
-
actorId: string | null;
|
|
96
|
-
/**
|
|
97
|
-
* ID of the Actor run (ACTOR_RUN_ID)
|
|
98
|
-
*/
|
|
99
|
-
actorRunId: string | null;
|
|
100
|
-
/**
|
|
101
|
-
* ID of the Actor task (ACTOR_TASK_ID)
|
|
102
|
-
*/
|
|
103
|
-
actorTaskId: string | null;
|
|
104
|
-
/**
|
|
105
|
-
* ID of the Actor build used in the run. (ACTOR_BUILD_ID)
|
|
106
|
-
*/
|
|
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;
|
|
112
|
-
/**
|
|
113
|
-
* ID of the user who started the Actor - note that it might be
|
|
114
|
-
* different than the owner of the Actor (APIFY_USER_ID)
|
|
115
|
-
*/
|
|
116
|
-
userId: string | null;
|
|
117
|
-
/**
|
|
118
|
-
* If it is `1`, it means that the user who started the Actor is a paying user. (APIFY_USER_IS_PAYING)
|
|
119
|
-
*/
|
|
120
|
-
userIsPaying: string | null;
|
|
121
|
-
/**
|
|
122
|
-
* Authentication token representing privileges given to the Actor run,
|
|
123
|
-
* it can be passed to various Apify APIs (APIFY_TOKEN)
|
|
124
|
-
*/
|
|
125
|
-
token: string | null;
|
|
126
|
-
/**
|
|
127
|
-
* Date when the Actor was started (ACTOR_STARTED_AT)
|
|
128
|
-
*/
|
|
129
|
-
startedAt: Date | null;
|
|
130
|
-
/**
|
|
131
|
-
* Date when the Actor will time out (ACTOR_TIMEOUT_AT)
|
|
132
|
-
*/
|
|
133
|
-
timeoutAt: Date | null;
|
|
134
|
-
/**
|
|
135
|
-
* ID of the key-value store where input and output data of this
|
|
136
|
-
* Actor is stored (ACTOR_DEFAULT_KEY_VALUE_STORE_ID)
|
|
137
|
-
*/
|
|
138
|
-
defaultKeyValueStoreId: string | null;
|
|
139
|
-
/**
|
|
140
|
-
* ID of the dataset where input and output data of this
|
|
141
|
-
* Actor is stored (ACTOR_DEFAULT_DATASET_ID)
|
|
142
|
-
*/
|
|
143
|
-
defaultDatasetId: string | null;
|
|
144
|
-
/**
|
|
145
|
-
* Amount of memory allocated for the Actor,
|
|
146
|
-
* in megabytes (ACTOR_MEMORY_MBYTES)
|
|
147
|
-
*/
|
|
148
|
-
memoryMbytes: number | null;
|
|
149
|
-
/**
|
|
150
|
-
* If set to "1", the web browsers inside the Actor should run in headless
|
|
151
|
-
* mode because there is no windowing system available. (APIFY_HEADLESS)
|
|
152
|
-
*/
|
|
153
|
-
headless: string | null;
|
|
154
|
-
/**
|
|
155
|
-
* Is set to "1" if the Actor is running on Apify servers.
|
|
156
|
-
* (APIFY_IS_AT_HOME)
|
|
157
|
-
*/
|
|
158
|
-
isAtHome: string | null;
|
|
159
|
-
/**
|
|
160
|
-
* The Apify Proxy password of the user who started the Actor. (APIFY_PROXY_PASSWORD)
|
|
161
|
-
*/
|
|
162
|
-
proxyPassword: string | null;
|
|
163
|
-
proxyHostname: string | null;
|
|
164
|
-
proxyPort: string | null;
|
|
165
|
-
/**
|
|
166
|
-
* You can visit this page to troubleshoot your proxy connection. (APIFY_PROXY_STATUS_URL)
|
|
167
|
-
*/
|
|
168
|
-
proxyStatusUrl: string | null;
|
|
169
|
-
apiBaseUrl: string | null;
|
|
170
|
-
apiPublicBaseUrl: string | null;
|
|
171
|
-
chromeExecutablePath: string | null;
|
|
172
|
-
dedicatedCpus: string | null;
|
|
173
|
-
disableOutdatedWarning: 1 | null;
|
|
174
|
-
fact: string | null;
|
|
175
|
-
inputSecretsPrivateKeyFile: string | null;
|
|
176
|
-
inputSecretsPrivateKeyPassphrase: string | null;
|
|
177
|
-
/**
|
|
178
|
-
* Defines the path to a local directory where KeyValueStore, Dataset, and RequestQueue
|
|
179
|
-
* store their data. Typically, it is set to ./storage. If omitted, you should define the
|
|
180
|
-
* APIFY_TOKEN environment variable instead. See more info on combination of this and
|
|
181
|
-
* APIFY_TOKEN [here](https://docs.apify.com/sdk/js/docs/concepts/environment-variables#combinations-of-apify_local_storage_dir-and-apify_token)(CRAWLEE_STORAGE_DIR)
|
|
182
|
-
*/
|
|
183
|
-
localStorageDir: string | null;
|
|
184
|
-
/**
|
|
185
|
-
* Specifies the minimum log level, which can be one of the following values (in order of severity): DEBUG, INFO, WARNING and ERROR
|
|
186
|
-
* (APIFY_LOG_LEVEL)
|
|
187
|
-
*/
|
|
188
|
-
logLevel: string | null;
|
|
189
|
-
logFormat: string | null;
|
|
190
|
-
/**
|
|
191
|
-
* Origin for the Actor run, i.e. how it was started. See [here](https://docs.apify.com/platform/actors/running/runs-and-builds#origin)
|
|
192
|
-
* for more details. (APIFY_META_ORIGIN)
|
|
193
|
-
*/
|
|
194
|
-
metaOrigin: string | null;
|
|
195
|
-
/**
|
|
196
|
-
* The key of the input record in the Actor’s default key-value store (ACTOR_INPUT_KEY)
|
|
197
|
-
*/
|
|
198
|
-
inputKey: string | null;
|
|
199
|
-
sdkLatestVersion: string | null;
|
|
200
|
-
systemInfoIntervalMillis: string | null;
|
|
201
|
-
workflowKey: string | null;
|
|
202
|
-
actorBuildNumber: string | null;
|
|
203
|
-
actorEventsWsUrl: string | null;
|
|
204
|
-
actorMaxPaidDatasetItems: number | null;
|
|
205
|
-
containerPort: number | null;
|
|
206
|
-
containerUrl: string | null;
|
|
207
|
-
defaultRequestQueueId: string | null;
|
|
208
|
-
}
|
|
209
86
|
export type UserFunc<T = unknown> = () => Awaitable<T>;
|
|
210
87
|
export interface Token {
|
|
211
88
|
/**
|
|
@@ -222,11 +99,38 @@ export interface Timeout {
|
|
|
222
99
|
*/
|
|
223
100
|
timeout?: number | 'inherit';
|
|
224
101
|
}
|
|
225
|
-
export interface
|
|
102
|
+
export interface ChildRunOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Local name for the child run, unique across all Actors and tasks started by this run.
|
|
105
|
+
*
|
|
106
|
+
* If a `READY`, `RUNNING` or `SUCCEEDED` run is already tracked under this name, it is returned instead of
|
|
107
|
+
* starting a new one, including after a migration or resurrection of this run. A run that was aborted or timed out
|
|
108
|
+
* is resurrected with the given options, once it finishes aborting or timing out. A run that failed is replaced
|
|
109
|
+
* by a new one. Reusing the name for a different Actor, task or input throws, unless the tracked run is replaced.
|
|
110
|
+
*/
|
|
111
|
+
runName?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Gracefully abort the child run when this run is gracefully aborted. Requires `runName`.
|
|
114
|
+
*
|
|
115
|
+
* The latest call under the same `runName` sets the value. Once this run is being aborted, a call with this option
|
|
116
|
+
* throws instead of starting, resurrecting or returning a run. A hard abort, timeout or crash of this run leaves
|
|
117
|
+
* the child run running.
|
|
118
|
+
*
|
|
119
|
+
* A run started with a custom `token` is aborted with that token, except for a run started before a migration or
|
|
120
|
+
* resurrection of this run, which is aborted with the default client.
|
|
121
|
+
* @default false
|
|
122
|
+
*/
|
|
123
|
+
abortWithParent?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface CallOptions extends Omit<ActorCallOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
126
|
+
}
|
|
127
|
+
export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
128
|
+
}
|
|
129
|
+
export interface CallTaskOptions extends Omit<TaskCallOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
226
130
|
}
|
|
227
|
-
export interface
|
|
131
|
+
export interface ResurrectOptions extends Omit<RunResurrectOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout {
|
|
228
132
|
}
|
|
229
|
-
export interface
|
|
133
|
+
export interface StartTaskOptions extends Omit<TaskStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
230
134
|
}
|
|
231
135
|
export interface AbortOptions extends RunAbortOptions, Token {
|
|
232
136
|
/** Exit with given status message */
|
|
@@ -254,8 +158,7 @@ export interface WebhookOptions {
|
|
|
254
158
|
/**
|
|
255
159
|
* Idempotency key enables you to ensure that a webhook will not be added multiple times in case of
|
|
256
160
|
* an Actor restart or other situation that would cause the `addWebhook()` function to be called again.
|
|
257
|
-
* We suggest using the Actor run ID as the idempotency key
|
|
258
|
-
* {@link Actor.getEnv} function.
|
|
161
|
+
* We suggest using the Actor run ID as the idempotency key, available as `Actor.configuration.actorRunId`.
|
|
259
162
|
*/
|
|
260
163
|
idempotencyKey?: string;
|
|
261
164
|
/**
|
|
@@ -305,6 +208,11 @@ export interface MetamorphOptions {
|
|
|
305
208
|
customAfterSleepMillis?: number;
|
|
306
209
|
}
|
|
307
210
|
export interface RebootOptions {
|
|
211
|
+
/**
|
|
212
|
+
* Amount of time, in seconds, to wait for the `persistState` and `migrating` event handlers before rebooting.
|
|
213
|
+
* @default 30
|
|
214
|
+
*/
|
|
215
|
+
timeoutSecs?: number;
|
|
308
216
|
/** @internal */
|
|
309
217
|
customAfterSleepMillis?: number;
|
|
310
218
|
}
|
|
@@ -492,6 +400,25 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
492
400
|
* @ignore
|
|
493
401
|
*/
|
|
494
402
|
abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
|
|
403
|
+
/**
|
|
404
|
+
* Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
405
|
+
*
|
|
406
|
+
* Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
|
|
407
|
+
* status and keeps its default storages. Options you leave out keep the values of the original run.
|
|
408
|
+
*
|
|
409
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
410
|
+
*
|
|
411
|
+
* For more information about Actors, read the
|
|
412
|
+
* [documentation](https://docs.apify.com/actor).
|
|
413
|
+
*
|
|
414
|
+
* **Example usage:**
|
|
415
|
+
*
|
|
416
|
+
* ```js
|
|
417
|
+
* const run = await Actor.resurrect(runId);
|
|
418
|
+
* ```
|
|
419
|
+
* @ignore
|
|
420
|
+
*/
|
|
421
|
+
resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
|
|
495
422
|
/**
|
|
496
423
|
* Runs an actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
497
424
|
*
|
|
@@ -519,6 +446,43 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
519
446
|
* @ignore
|
|
520
447
|
*/
|
|
521
448
|
callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
|
|
449
|
+
/**
|
|
450
|
+
* Clients for the child runs started with the `runName` option, keyed by that name, including the runs started
|
|
451
|
+
* before a migration or resurrection of this run. Each client points to the current run under its name.
|
|
452
|
+
*
|
|
453
|
+
* ```js
|
|
454
|
+
* await Actor.childRuns['my-child'].waitForFinish();
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* A run started with a custom `token` uses that token, except for a run started before a migration or
|
|
458
|
+
* resurrection, which uses the default client. The tracked runs, including the earlier runs replaced
|
|
459
|
+
* under the same name, are stored in the default key-value store under the `APIFY_ACTOR_CHILD_RUNS` key.
|
|
460
|
+
*/
|
|
461
|
+
get childRuns(): Record<string, RunClient>;
|
|
462
|
+
/**
|
|
463
|
+
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
464
|
+
* unlike `Actor.callTask`, this method just starts the run without waiting for finish.
|
|
465
|
+
*
|
|
466
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
467
|
+
*
|
|
468
|
+
* For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
|
|
469
|
+
*
|
|
470
|
+
* **Example usage:**
|
|
471
|
+
*
|
|
472
|
+
* ```js
|
|
473
|
+
* const run = await Actor.startTask('bob/some-task');
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @param taskId
|
|
477
|
+
* Allowed formats are `username/task-name`, `userId/task-name` or task ID.
|
|
478
|
+
* @param [input]
|
|
479
|
+
* Input overrides for the Actor task. If it is an object, it will be stringified to
|
|
480
|
+
* JSON and its content type set to `application/json; charset=utf-8`.
|
|
481
|
+
* Provided input will be merged with Actor task input.
|
|
482
|
+
* @param [options]
|
|
483
|
+
* @ignore
|
|
484
|
+
*/
|
|
485
|
+
startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
|
|
522
486
|
/**
|
|
523
487
|
* Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
|
|
524
488
|
* the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
|
|
@@ -557,11 +521,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
557
521
|
/**
|
|
558
522
|
* Sets the status message for the current Actor run.
|
|
559
523
|
*
|
|
560
|
-
* @returns The
|
|
524
|
+
* @returns The updated Run object, or `undefined` when no run was updated: when run locally,
|
|
525
|
+
* or when the update failed or timed out (a warning is logged in that case).
|
|
561
526
|
* For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
|
|
562
527
|
* @ignore
|
|
563
528
|
*/
|
|
564
|
-
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
529
|
+
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
|
|
565
530
|
/**
|
|
566
531
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
567
532
|
*
|
|
@@ -588,6 +553,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
588
553
|
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
589
554
|
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
590
555
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
556
|
+
* Not supported in multi-tenant Server Actor runs, which charge per request with `Actor.charge()`.
|
|
591
557
|
* @ignore
|
|
592
558
|
*/
|
|
593
559
|
pushData(item: Data | Data[], eventName?: string | undefined): Promise<ChargeResult>;
|
|
@@ -638,6 +604,35 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
638
604
|
* @ignore
|
|
639
605
|
*/
|
|
640
606
|
getValue<T = unknown>(key: string): Promise<T | null>;
|
|
607
|
+
/**
|
|
608
|
+
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
609
|
+
*
|
|
610
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getValue}.
|
|
611
|
+
* For example, calling the following code:
|
|
612
|
+
* ```js
|
|
613
|
+
* const value = await Actor.getValue('my-key');
|
|
614
|
+
* ```
|
|
615
|
+
*
|
|
616
|
+
* is equivalent to:
|
|
617
|
+
* ```js
|
|
618
|
+
* const store = await Actor.openKeyValueStore();
|
|
619
|
+
* const value = await store.getValue('my-key');
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
|
|
623
|
+
*
|
|
624
|
+
* For more information, see {@link Actor.openKeyValueStore}
|
|
625
|
+
* and {@link KeyValueStore.getValue}.
|
|
626
|
+
*
|
|
627
|
+
* @param key Unique record key.
|
|
628
|
+
* @param defaultValue Fallback that will be returned if no value if present in the storage.
|
|
629
|
+
* @returns
|
|
630
|
+
* Returns a promise that resolves to an object, string
|
|
631
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
632
|
+
* on the MIME content type of the record, or the provided default value.
|
|
633
|
+
* @ignore
|
|
634
|
+
*/
|
|
635
|
+
getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
641
636
|
/**
|
|
642
637
|
* Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
|
|
643
638
|
*
|
|
@@ -677,11 +672,15 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
677
672
|
* A record stored as `application/octet-stream` — which is what a local input file without an
|
|
678
673
|
* extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
|
|
679
674
|
*
|
|
680
|
-
* When running locally
|
|
681
|
-
*
|
|
675
|
+
* When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
|
|
676
|
+
* working directory. A storage backend that doesn't read the default key-value store's directory under
|
|
677
|
+
* the storage directory (e.g. in-memory storage) also gets the file `apify run` writes there.
|
|
678
|
+
*
|
|
679
|
+
* Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
|
|
680
|
+
* replaced with the links of their CSV exports.
|
|
682
681
|
*
|
|
683
|
-
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when
|
|
684
|
-
*
|
|
682
|
+
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
|
|
683
|
+
* found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
|
|
685
684
|
* (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
|
|
686
685
|
* Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest.
|
|
687
686
|
*
|
|
@@ -701,14 +700,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
701
700
|
*/
|
|
702
701
|
getInput<T = Dictionary | string | Buffer>(): Promise<T>;
|
|
703
702
|
/**
|
|
704
|
-
* Reads the input from a `<inputKey>` or `<inputKey>.json` file in the
|
|
703
|
+
* Reads the input from a `<inputKey>` or `<inputKey>.json` file in the given directory, for local runs
|
|
705
704
|
* whose default key-value store holds no input record. Mirrors how `ApifyFileSystemStorageBackend` adopts
|
|
706
705
|
* such files inside the store directory: the `.json` file is JSON, the bare one is bytes that
|
|
707
706
|
* {@link parseInputValue} tries as JSON5. Both files present is an error rather than a guess.
|
|
708
707
|
*
|
|
709
708
|
* @returns `undefined` when running on the platform or when neither file exists.
|
|
710
709
|
*/
|
|
711
|
-
private
|
|
710
|
+
private readInputFromDirectory;
|
|
712
711
|
/**
|
|
713
712
|
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
714
713
|
*
|
|
@@ -804,6 +803,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
804
803
|
* rather than batching via `count` — this gives finer control over budget consumption
|
|
805
804
|
* and avoids situations where more work is requested than the budget allows.
|
|
806
805
|
*
|
|
806
|
+
* **Note:** `idempotencyKey` is scoped to the whole run, not to `requestId`. In a multi-tenant
|
|
807
|
+
* Server Actor run, a key reused across requests charges only the first caller, so it must
|
|
808
|
+
* be globally unique (e.g. derived from `requestId`).
|
|
809
|
+
*
|
|
807
810
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
808
811
|
* @ignore
|
|
809
812
|
*/
|
|
@@ -814,18 +817,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
814
817
|
*/
|
|
815
818
|
getChargingManager(): ChargingManager;
|
|
816
819
|
/**
|
|
817
|
-
*
|
|
820
|
+
* Fetches the current Actor run from the Apify API. The result is cached for the lifetime of the Actor,
|
|
821
|
+
* so use `Actor.apifyClient.run(runId).get()` instead when you need fresh data such as the run status.
|
|
822
|
+
* Resolves to `undefined` when not running on the Apify platform.
|
|
818
823
|
*/
|
|
819
|
-
|
|
820
|
-
/**
|
|
821
|
-
* Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
|
|
822
|
-
*
|
|
823
|
-
* For the list of the Apify environment variables, see
|
|
824
|
-
* [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
|
|
825
|
-
* If some variables are not defined or are invalid, the corresponding value in the resulting object will be null.
|
|
826
|
-
* @ignore
|
|
827
|
-
*/
|
|
828
|
-
getEnv(): ApifyEnv;
|
|
824
|
+
getCurrentRun(): Promise<ClientActorRun | undefined>;
|
|
829
825
|
/**
|
|
830
826
|
* Returns a new instance of the Apify API client. The `ApifyClient` class is provided
|
|
831
827
|
* by the [apify-client](https://www.npmjs.com/package/apify-client)
|
|
@@ -845,7 +841,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
845
841
|
*
|
|
846
842
|
* Values can be modified by simply using the assignment operator.
|
|
847
843
|
*
|
|
848
|
-
* @param name The
|
|
844
|
+
* @param name The key of the record that holds the state. Defaults to `APIFY_GLOBAL_STATE`.
|
|
849
845
|
* @param defaultValue If the store does not yet have a value in it, the value will be initialized with the `defaultValue` you provide.
|
|
850
846
|
* @param options An optional object parameter where a custom `keyValueStoreName` and `config` can be passed in.
|
|
851
847
|
*/
|
|
@@ -855,7 +851,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
855
851
|
*
|
|
856
852
|
* Values can be modified by simply using the assignment operator.
|
|
857
853
|
*
|
|
858
|
-
* @param name The
|
|
854
|
+
* @param name The key of the record that holds the state. Defaults to `APIFY_GLOBAL_STATE`.
|
|
859
855
|
* @param defaultValue If the store does not yet have a value in it, the value will be initialized with the `defaultValue` you provide.
|
|
860
856
|
* @param options An optional object parameter where a custom `keyValueStoreName` and `config` can be passed in.
|
|
861
857
|
*/
|
|
@@ -1010,6 +1006,29 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1010
1006
|
* @param [options]
|
|
1011
1007
|
*/
|
|
1012
1008
|
static callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
1011
|
+
* unlike `Actor.callTask`, this method just starts the run without waiting for finish.
|
|
1012
|
+
*
|
|
1013
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
1014
|
+
*
|
|
1015
|
+
* For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
|
|
1016
|
+
*
|
|
1017
|
+
* **Example usage:**
|
|
1018
|
+
*
|
|
1019
|
+
* ```js
|
|
1020
|
+
* const run = await Actor.startTask('bob/some-task');
|
|
1021
|
+
* ```
|
|
1022
|
+
*
|
|
1023
|
+
* @param taskId
|
|
1024
|
+
* Allowed formats are `username/task-name`, `userId/task-name` or task ID.
|
|
1025
|
+
* @param [input]
|
|
1026
|
+
* Input overrides for the Actor task. If it is an object, it will be stringified to
|
|
1027
|
+
* JSON and its content type set to `application/json; charset=utf-8`.
|
|
1028
|
+
* Provided input will be merged with Actor task input.
|
|
1029
|
+
* @param [options]
|
|
1030
|
+
*/
|
|
1031
|
+
static startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
|
|
1013
1032
|
/**
|
|
1014
1033
|
* Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
1015
1034
|
* unlike `Actor.call`, this method just starts the run without waiting for finish.
|
|
@@ -1033,6 +1052,19 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1033
1052
|
* @param [options]
|
|
1034
1053
|
*/
|
|
1035
1054
|
static start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ClientActorRun>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Clients for the child runs started with the `runName` option, keyed by that name, including the runs started
|
|
1057
|
+
* before a migration or resurrection of this run. Each client points to the current run under its name.
|
|
1058
|
+
*
|
|
1059
|
+
* ```js
|
|
1060
|
+
* await Actor.childRuns['my-child'].waitForFinish();
|
|
1061
|
+
* ```
|
|
1062
|
+
*
|
|
1063
|
+
* A run started with a custom `token` uses that token, except for a run started before a migration or
|
|
1064
|
+
* resurrection, which uses the default client. The tracked runs, including the earlier runs replaced
|
|
1065
|
+
* under the same name, are stored in the default key-value store under the `APIFY_ACTOR_CHILD_RUNS` key.
|
|
1066
|
+
*/
|
|
1067
|
+
static get childRuns(): Record<string, RunClient>;
|
|
1036
1068
|
/**
|
|
1037
1069
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
1038
1070
|
*
|
|
@@ -1048,6 +1080,24 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1048
1080
|
* ```
|
|
1049
1081
|
*/
|
|
1050
1082
|
static abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
|
|
1083
|
+
/**
|
|
1084
|
+
* Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
1085
|
+
*
|
|
1086
|
+
* Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
|
|
1087
|
+
* status and keeps its default storages. Options you leave out keep the values of the original run.
|
|
1088
|
+
*
|
|
1089
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
1090
|
+
*
|
|
1091
|
+
* For more information about Actors, read the
|
|
1092
|
+
* [documentation](https://docs.apify.com/actor).
|
|
1093
|
+
*
|
|
1094
|
+
* **Example usage:**
|
|
1095
|
+
*
|
|
1096
|
+
* ```js
|
|
1097
|
+
* const run = await Actor.resurrect(runId);
|
|
1098
|
+
* ```
|
|
1099
|
+
*/
|
|
1100
|
+
static resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
|
|
1051
1101
|
/**
|
|
1052
1102
|
* Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
|
|
1053
1103
|
* the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
|
|
@@ -1086,10 +1136,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1086
1136
|
* @param [options]
|
|
1087
1137
|
* @param [options.isStatusMessageTerminal] If `true`, the status message will be marked as terminal.
|
|
1088
1138
|
* This is required for the last status message of the run. Default value is `false`.
|
|
1089
|
-
* @returns The
|
|
1139
|
+
* @returns The updated Run object, or `undefined` when no run was updated: when run locally,
|
|
1140
|
+
* or when the update failed or timed out (a warning is logged in that case).
|
|
1090
1141
|
* For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
|
|
1091
1142
|
*/
|
|
1092
|
-
static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
1143
|
+
static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
|
|
1093
1144
|
/**
|
|
1094
1145
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
1095
1146
|
*
|
|
@@ -1141,6 +1192,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1141
1192
|
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
1142
1193
|
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
1143
1194
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
1195
|
+
* Not supported in multi-tenant Server Actor runs, which charge per request with `Actor.charge()`.
|
|
1144
1196
|
*/
|
|
1145
1197
|
static pushData<Data extends Dictionary = Dictionary>(item: Data | Data[], eventName: string): Promise<ChargeResult>;
|
|
1146
1198
|
/**
|
|
@@ -1188,6 +1240,34 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1188
1240
|
* if the record is missing.
|
|
1189
1241
|
*/
|
|
1190
1242
|
static getValue<T = unknown>(key: string): Promise<T | null>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1245
|
+
*
|
|
1246
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getValue}.
|
|
1247
|
+
* For example, calling the following code:
|
|
1248
|
+
* ```js
|
|
1249
|
+
* const value = await Actor.getValue('my-key');
|
|
1250
|
+
* ```
|
|
1251
|
+
*
|
|
1252
|
+
* is equivalent to:
|
|
1253
|
+
* ```js
|
|
1254
|
+
* const store = await Actor.openKeyValueStore();
|
|
1255
|
+
* const value = await store.getValue('my-key');
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
|
|
1259
|
+
*
|
|
1260
|
+
* For more information, see {@link Actor.openKeyValueStore}
|
|
1261
|
+
* and {@link KeyValueStore.getValue}.
|
|
1262
|
+
*
|
|
1263
|
+
* @param key Unique record key.
|
|
1264
|
+
* @param defaultValue Fallback that will be returned if no value if present in the storage.
|
|
1265
|
+
* @returns
|
|
1266
|
+
* Returns a promise that resolves to an object, string
|
|
1267
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
1268
|
+
* on the MIME content type of the record, or the provided default value.
|
|
1269
|
+
*/
|
|
1270
|
+
static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
1191
1271
|
/**
|
|
1192
1272
|
* Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
|
|
1193
1273
|
*
|
|
@@ -1230,11 +1310,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1230
1310
|
* A record stored as `application/octet-stream` — which is what a local input file without an
|
|
1231
1311
|
* extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
|
|
1232
1312
|
*
|
|
1233
|
-
* When running locally
|
|
1234
|
-
*
|
|
1313
|
+
* When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
|
|
1314
|
+
* working directory.
|
|
1315
|
+
*
|
|
1316
|
+
* Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
|
|
1317
|
+
* replaced with the links of their CSV exports.
|
|
1235
1318
|
*
|
|
1236
|
-
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when
|
|
1237
|
-
*
|
|
1319
|
+
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
|
|
1320
|
+
* found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
|
|
1238
1321
|
* (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
|
|
1239
1322
|
* Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest:
|
|
1240
1323
|
* ```js
|
|
@@ -1348,6 +1431,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1348
1431
|
* rather than batching via `count` — this gives finer control over budget consumption
|
|
1349
1432
|
* and avoids situations where more work is requested than the budget allows.
|
|
1350
1433
|
*
|
|
1434
|
+
* **Note:** `idempotencyKey` is scoped to the whole run, not to `requestId`. In a multi-tenant
|
|
1435
|
+
* Server Actor run, a key reused across requests charges only the first caller, so it must
|
|
1436
|
+
* be globally unique (e.g. derived from `requestId`).
|
|
1437
|
+
*
|
|
1351
1438
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
1352
1439
|
*/
|
|
1353
1440
|
static charge(options: ChargeOptions): Promise<ChargeResult>;
|
|
@@ -1355,14 +1442,6 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1355
1442
|
* Retrieve the charging manager to access granular pricing information.
|
|
1356
1443
|
*/
|
|
1357
1444
|
static getChargingManager(): ChargingManager;
|
|
1358
|
-
/**
|
|
1359
|
-
* Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
|
|
1360
|
-
*
|
|
1361
|
-
* For the list of the Apify environment variables, see
|
|
1362
|
-
* [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
|
|
1363
|
-
* If some of the variables are not defined or are invalid, the corresponding value in the resulting object will be null.
|
|
1364
|
-
*/
|
|
1365
|
-
static getEnv(): ApifyEnv;
|
|
1366
1445
|
/**
|
|
1367
1446
|
* Returns a new instance of the Apify API client. The `ApifyClient` class is provided
|
|
1368
1447
|
* by the [apify-client](https://www.npmjs.com/package/apify-client)
|
|
@@ -1375,6 +1454,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1375
1454
|
* Returns `true` when code is running on Apify platform and `false` otherwise (for example locally).
|
|
1376
1455
|
*/
|
|
1377
1456
|
static isAtHome(): boolean;
|
|
1457
|
+
/**
|
|
1458
|
+
* Fetches the current Actor run from the Apify API. The result is cached for the lifetime of the Actor,
|
|
1459
|
+
* so use `Actor.apifyClient.run(runId).get()` instead when you need fresh data such as the run status.
|
|
1460
|
+
* Resolves to `undefined` when not running on the Apify platform.
|
|
1461
|
+
*/
|
|
1462
|
+
static getCurrentRun(): Promise<ClientActorRun | undefined>;
|
|
1378
1463
|
/** Default {@link ApifyClient} instance. */
|
|
1379
1464
|
static get apifyClient(): ApifyClient;
|
|
1380
1465
|
/** Default {@link Configuration} instance. */
|