apify 4.0.0-beta.15 → 4.0.0-beta.150

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.
Files changed (49) hide show
  1. package/README.md +28 -2
  2. package/dist/actor.d.ts +416 -281
  3. package/dist/actor.js +743 -417
  4. package/dist/apify_dataset_backend.d.ts +22 -0
  5. package/dist/apify_dataset_backend.js +77 -0
  6. package/dist/apify_file_system_storage_backend.d.ts +34 -0
  7. package/dist/apify_file_system_storage_backend.js +41 -0
  8. package/dist/apify_key_value_store_backend.d.ts +26 -0
  9. package/dist/apify_key_value_store_backend.js +57 -0
  10. package/dist/apify_request_queue_backend.d.ts +88 -0
  11. package/dist/apify_request_queue_backend.js +123 -0
  12. package/dist/apify_request_queue_shared_backend.d.ts +31 -0
  13. package/dist/apify_request_queue_shared_backend.js +201 -0
  14. package/dist/apify_request_queue_single_backend.d.ts +43 -0
  15. package/dist/apify_request_queue_single_backend.js +265 -0
  16. package/dist/apify_storage_backend.d.ts +95 -0
  17. package/dist/apify_storage_backend.js +219 -0
  18. package/dist/charging.d.ts +77 -47
  19. package/dist/charging.js +348 -226
  20. package/dist/charging_storage_backend.d.ts +53 -0
  21. package/dist/charging_storage_backend.js +109 -0
  22. package/dist/child_run_tracker.d.ts +110 -0
  23. package/dist/child_run_tracker.js +333 -0
  24. package/dist/configuration.d.ts +48 -28
  25. package/dist/configuration.js +66 -12
  26. package/dist/enqueue_links_filters.d.ts +29 -0
  27. package/dist/enqueue_links_filters.js +52 -0
  28. package/dist/errors.d.ts +31 -0
  29. package/dist/errors.js +22 -0
  30. package/dist/google_sheets.d.ts +12 -0
  31. package/dist/google_sheets.js +26 -0
  32. package/dist/index.d.ts +13 -4
  33. package/dist/index.js +8 -3
  34. package/dist/input-schemas.d.ts +1 -1
  35. package/dist/platform_event_manager.d.ts +24 -9
  36. package/dist/platform_event_manager.js +213 -43
  37. package/dist/proxy_configuration.d.ts +32 -21
  38. package/dist/proxy_configuration.js +137 -79
  39. package/dist/smart_apify_storage_backend.d.ts +52 -0
  40. package/dist/smart_apify_storage_backend.js +73 -0
  41. package/dist/storage.d.ts +6 -26
  42. package/dist/storage.js +1 -79
  43. package/dist/utils.d.ts +28 -3
  44. package/dist/utils.js +59 -17
  45. package/package.json +38 -44
  46. package/dist/apify_storage_client.d.ts +0 -54
  47. package/dist/apify_storage_client.js +0 -152
  48. package/dist/key_value_store.d.ts +0 -21
  49. package/dist/key_value_store.js +0 -41
package/dist/actor.d.ts CHANGED
@@ -1,19 +1,40 @@
1
1
  import type { EventManager, EventTypeName, RecordOptions, UseStateOptions } from '@crawlee/core';
2
- import { Dataset, RequestQueue } from '@crawlee/core';
3
- import type { Awaitable, Dictionary, SetStatusMessageOptions, StorageClient } from '@crawlee/types';
4
- import type { ActorCallOptions, ActorStartOptions, ApifyClientOptions, RunAbortOptions, TaskCallOptions, Webhook, WebhookEventType } from 'apify-client';
5
- import { ActorRun as ClientActorRun, ApifyClient } from 'apify-client';
6
- import { type ACTOR_PERMISSION_LEVEL } from '@apify/consts';
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 { RequestQueueAccessMode } from './apify_request_queue_backend.js';
7
7
  import type { ChargeOptions, ChargeResult } from './charging.js';
8
8
  import { ChargingManager } from './charging.js';
9
9
  import type { ConfigurationOptions } from './configuration.js';
10
10
  import { Configuration } from './configuration.js';
11
- import { KeyValueStore } from './key_value_store.js';
12
11
  import type { ProxyConfigurationOptions } from './proxy_configuration.js';
13
12
  import { ProxyConfiguration } from './proxy_configuration.js';
14
- import type { OpenStorageOptions, StorageIdentifier, StorageIdentifierWithoutAlias } from './storage.js';
13
+ import type { OpenStorageOptions, StorageIdentifier } from './storage.js';
15
14
  export interface InitOptions {
16
- storage?: StorageClient;
15
+ /**
16
+ * Storage backend to use, in place of the Apify platform storage (on the platform) or crawlee's
17
+ * local storage (outside of it).
18
+ *
19
+ * Items pushed to the default dataset are then not charged for under the pay-per-event pricing
20
+ * model: the platform counts an `apify-default-dataset-item` per item it stores itself, and a
21
+ * backend of your own stores them elsewhere.
22
+ */
23
+ storage?: StorageBackend;
24
+ /**
25
+ * Determines how request queues opened on the Apify platform are consumed.
26
+ *
27
+ * - `'single'` (default) assumes this run is the only consumer of its request queues. Requests
28
+ * are not locked server-side and the queue head is estimated locally, which means fewer
29
+ * (paid) API calls and better performance.
30
+ * - `'shared'` locks every fetched request server-side, so any number of concurrent consumers
31
+ * (e.g. several Actor runs) can safely process the same queue, at the cost of roughly one
32
+ * extra API call per processed request.
33
+ *
34
+ * Only applies on the Apify platform (or with `forceCloud`); local storage ignores it.
35
+ * @default 'single'
36
+ */
37
+ requestQueueAccess?: RequestQueueAccessMode;
17
38
  /**
18
39
  * Whether to automatically handle platform shutdown signals.
19
40
  * When enabled, `Actor.exit()` is called on `aborting` events and `Actor.reboot()` on `migrating` events.
@@ -26,6 +47,27 @@ export interface InitOptions {
26
47
  * @default 0
27
48
  */
28
49
  gracefulShutdownDelayMillis?: number;
50
+ /**
51
+ * Whether to record the child runs started by `Actor.start()`, `Actor.call()`, `Actor.startTask()` and
52
+ * `Actor.callTask()` in the default key-value store. `Actor.childRuns()`, `abortWithParent` and
53
+ * `maxConcurrentChildRuns` need it.
54
+ *
55
+ * Tracking costs resources, so it may be worth turning off for a run that starts many child runs.
56
+ * @default true
57
+ */
58
+ trackChildRuns?: boolean;
59
+ /**
60
+ * Whether to mute the warning logged once this run records more than 50 child runs.
61
+ * @default false
62
+ */
63
+ disableExcessiveChildRunWarning?: boolean;
64
+ /**
65
+ * Maximum number of child runs that can be active (`READY`, `RUNNING`, `ABORTING` or `TIMING-OUT`) at once. A call
66
+ * of `Actor.start()`, `Actor.call()`, `Actor.startTask()` or `Actor.callTask()` that would start one more waits
67
+ * until another one finishes, and throws instead once this run is being aborted or is exiting. A finished child
68
+ * run that is resurrected, e.g. with `resurrect()` on its client from `Actor.childRuns()`, is not counted.
69
+ */
70
+ maxConcurrentChildRuns?: number;
29
71
  }
30
72
  /**
31
73
  * Options accepted by the {@link Actor} constructor. Either pass field-level
@@ -56,127 +98,11 @@ export interface ExitOptions {
56
98
  }
57
99
  export interface MainOptions extends ExitOptions, InitOptions {
58
100
  }
59
- /**
60
- * Parsed representation of the Apify environment variables.
61
- * This object is returned by the {@link Actor.getEnv} function.
62
- */
63
- export interface ApifyEnv {
64
- /**
65
- * ID of the Actor (ACTOR_ID)
66
- */
67
- actorId: string | null;
68
- /**
69
- * ID of the Actor run (ACTOR_RUN_ID)
70
- */
71
- actorRunId: string | null;
72
- /**
73
- * ID of the Actor task (ACTOR_TASK_ID)
74
- */
75
- actorTaskId: string | null;
76
- /**
77
- * ID of the Actor build used in the run. (ACTOR_BUILD_ID)
78
- */
79
- actorBuildId: string | null;
80
- /**
81
- * [Permission level](https://docs.apify.com/platform/actors/development/permissions) the Actor is run under. (ACTOR_PERMISSION_LEVEL)
82
- */
83
- actorPermissionLevel: ACTOR_PERMISSION_LEVEL | null;
84
- /**
85
- * ID of the user who started the Actor - note that it might be
86
- * different than the owner of the Actor (APIFY_USER_ID)
87
- */
88
- userId: string | null;
89
- /**
90
- * If it is `1`, it means that the user who started the Actor is a paying user. (APIFY_USER_IS_PAYING)
91
- */
92
- userIsPaying: string | null;
93
- /**
94
- * Authentication token representing privileges given to the Actor run,
95
- * it can be passed to various Apify APIs (APIFY_TOKEN)
96
- */
97
- token: string | null;
98
- /**
99
- * Date when the Actor was started (ACTOR_STARTED_AT)
100
- */
101
- startedAt: Date | null;
102
- /**
103
- * Date when the Actor will time out (ACTOR_TIMEOUT_AT)
104
- */
105
- timeoutAt: Date | null;
106
- /**
107
- * ID of the key-value store where input and output data of this
108
- * Actor is stored (ACTOR_DEFAULT_KEY_VALUE_STORE_ID)
109
- */
110
- defaultKeyValueStoreId: string | null;
111
- /**
112
- * ID of the dataset where input and output data of this
113
- * Actor is stored (ACTOR_DEFAULT_DATASET_ID)
114
- */
115
- defaultDatasetId: string | null;
116
- /**
117
- * Amount of memory allocated for the Actor,
118
- * in megabytes (ACTOR_MEMORY_MBYTES)
119
- */
120
- memoryMbytes: number | null;
121
- /**
122
- * If set to "1", the web browsers inside the Actor should run in headless
123
- * mode because there is no windowing system available. (APIFY_HEADLESS)
124
- */
125
- headless: string | null;
126
- /**
127
- * Is set to "1" if the Actor is running on Apify servers.
128
- * (APIFY_IS_AT_HOME)
129
- */
130
- isAtHome: string | null;
131
- /**
132
- * The Apify Proxy password of the user who started the Actor. (APIFY_PROXY_PASSWORD)
133
- */
134
- proxyPassword: string | null;
135
- proxyHostname: string | null;
136
- proxyPort: string | null;
137
- /**
138
- * You can visit this page to troubleshoot your proxy connection. (APIFY_PROXY_STATUS_URL)
139
- */
140
- proxyStatusUrl: string | null;
141
- apiBaseUrl: string | null;
142
- apiPublicBaseUrl: string | null;
143
- chromeExecutablePath: string | null;
144
- dedicatedCpus: string | null;
145
- disableOutdatedWarning: 1 | null;
146
- fact: string | null;
147
- inputSecretsPrivateKeyFile: string | null;
148
- inputSecretsPrivateKeyPassphrase: string | null;
149
- /**
150
- * Defines the path to a local directory where KeyValueStore, Dataset, and RequestQueue
151
- * store their data. Typically, it is set to ./storage. If omitted, you should define the
152
- * APIFY_TOKEN environment variable instead. See more info on combination of this and
153
- * 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)
154
- */
155
- localStorageDir: string | null;
156
- /**
157
- * Specifies the minimum log level, which can be one of the following values (in order of severity): DEBUG, INFO, WARNING and ERROR
158
- * (APIFY_LOG_LEVEL)
159
- */
160
- logLevel: string | null;
161
- logFormat: string | null;
162
- /**
163
- * Origin for the Actor run, i.e. how it was started. See [here](https://docs.apify.com/sdk/python/reference/enum/MetaOrigin)
164
- * for more details. (APIFY_META_ORIGIN)
165
- */
166
- metaOrigin: string | null;
167
- /**
168
- * The key of the input record in the Actor’s default key-value store (ACTOR_INPUT_KEY)
169
- */
170
- inputKey: string | null;
171
- sdkLatestVersion: string | null;
172
- systemInfoIntervalMillis: string | null;
173
- workflowKey: string | null;
174
- actorBuildNumber: string | null;
175
- actorEventsWsUrl: string | null;
176
- actorMaxPaidDatasetItems: number | null;
177
- containerPort: number | null;
178
- containerUrl: string | null;
179
- defaultRequestQueueId: string | null;
101
+ export interface SetStatusMessageOptions {
102
+ /** If `true`, the status message is treated as final and won't be overwritten by the platform. */
103
+ isStatusMessageTerminal?: boolean;
104
+ /** Log level used when the status message is also logged locally. Defaults to `INFO`. */
105
+ level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
180
106
  }
181
107
  export type UserFunc<T = unknown> = () => Awaitable<T>;
182
108
  export interface Token {
@@ -194,11 +120,36 @@ export interface Timeout {
194
120
  */
195
121
  timeout?: number | 'inherit';
196
122
  }
197
- export interface CallOptions extends Omit<ActorCallOptions, 'timeout'>, Token, Timeout {
123
+ export interface ChildRunOptions {
124
+ /**
125
+ * Gracefully abort the child run when this run is gracefully aborted, or when it exits through `Actor.exit()`,
126
+ * `Actor.fail()` or `Actor.main()`, whatever the exit code. A hard abort, timeout or crash of this run leaves the
127
+ * child run running, and so does ending this run without `Actor.exit()`.
128
+ *
129
+ * Once this run is being aborted or is exiting, a call with this option throws instead of starting a run. A
130
+ * finished child run that is resurrected, e.g. with `resurrect()` on its client from `Actor.childRuns()`, keeps its
131
+ * finished status in the record and is not aborted. It cannot be combined with `token`, since the token is not
132
+ * stored.
133
+ * @default false
134
+ */
135
+ abortWithParent?: boolean;
136
+ }
137
+ /**
138
+ * Client for a child run, as returned by {@link Actor.childRuns}.
139
+ */
140
+ export type ChildRunClient = RunClient & {
141
+ /** Whether the run is aborted together with this run, as recorded at the time of the call. */
142
+ readonly abortWithParent: boolean;
143
+ };
144
+ export interface CallOptions extends Omit<ActorCallOptions, 'runTimeoutSecs' | 'maxItems' | 'timeout'>, Token, Timeout, ChildRunOptions {
145
+ }
146
+ export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems' | 'timeout'>, Token, Timeout, ChildRunOptions {
198
147
  }
199
- export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'timeout'>, Token, Timeout {
148
+ export interface CallTaskOptions extends Omit<TaskCallOptions, 'runTimeoutSecs' | 'maxItems' | 'timeout'>, Token, Timeout, ChildRunOptions {
200
149
  }
201
- export interface CallTaskOptions extends Omit<TaskCallOptions, 'timeout'>, Token, Timeout {
150
+ export interface ResurrectOptions extends Omit<RunResurrectOptions, 'runTimeoutSecs' | 'maxItems' | 'timeout'>, Token, Timeout {
151
+ }
152
+ export interface StartTaskOptions extends Omit<TaskStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems' | 'timeout'>, Token, Timeout, ChildRunOptions {
202
153
  }
203
154
  export interface AbortOptions extends RunAbortOptions, Token {
204
155
  /** Exit with given status message */
@@ -226,8 +177,7 @@ export interface WebhookOptions {
226
177
  /**
227
178
  * Idempotency key enables you to ensure that a webhook will not be added multiple times in case of
228
179
  * an Actor restart or other situation that would cause the `addWebhook()` function to be called again.
229
- * We suggest using the Actor run ID as the idempotency key. You can get the run ID by calling
230
- * {@link Actor.getEnv} function.
180
+ * We suggest using the Actor run ID as the idempotency key, available as `Actor.configuration.actorRunId`.
231
181
  */
232
182
  idempotencyKey?: string;
233
183
  /**
@@ -265,7 +215,7 @@ export interface MetamorphOptions {
265
215
  * Content type for the `input`. If not specified,
266
216
  * `input` is expected to be an object that will be stringified to JSON and content type set to
267
217
  * `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
268
- * `String` or `Buffer`.
218
+ * `Buffer`.
269
219
  */
270
220
  contentType?: string;
271
221
  /**
@@ -277,6 +227,11 @@ export interface MetamorphOptions {
277
227
  customAfterSleepMillis?: number;
278
228
  }
279
229
  export interface RebootOptions {
230
+ /**
231
+ * Amount of time, in seconds, to wait for the `persistState` and `migrating` event handlers before rebooting.
232
+ * @default 30
233
+ */
234
+ timeoutSecs?: number;
280
235
  /** @internal */
281
236
  customAfterSleepMillis?: number;
282
237
  }
@@ -298,13 +253,12 @@ export declare const EXIT_CODES: {
298
253
  * See {@link Configuration} for details about what can be configured and what are the default values.
299
254
  */
300
255
  export declare class Actor<Data extends Dictionary = Dictionary> {
301
- /** @internal */
302
- static _instance: Actor;
256
+ #private;
303
257
  /**
304
258
  * Configuration of this SDK instance (provided to its constructor). See {@link Configuration} for details.
305
259
  * @internal
306
260
  */
307
- readonly config: Configuration;
261
+ readonly configuration: Configuration;
308
262
  /**
309
263
  * Default {@link ApifyClient} instance.
310
264
  * @internal
@@ -319,30 +273,6 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
319
273
  * Whether the Actor instance was initialized. This is set by calling {@link Actor.init}.
320
274
  */
321
275
  initialized: boolean;
322
- /**
323
- * Set if the Actor called a method that requires the instance to be initialized, but did not do so.
324
- * A call to `init` after this warning is emitted is considered an invalid state and will throw an error.
325
- */
326
- private warnedAboutMissingInitCall;
327
- /**
328
- * Set if the Actor is currently rebooting.
329
- */
330
- private isRebooting;
331
- /**
332
- * Set if the Actor is currently exiting. Prevents double-exit from graceful shutdown handlers.
333
- */
334
- private isExiting;
335
- /**
336
- * References to graceful shutdown handlers so they can be removed during cleanup.
337
- */
338
- private gracefulShutdownHandlers;
339
- private chargingManager;
340
- /**
341
- * Tracks which aliased storages have been purged during this session,
342
- * so we only purge them once (on first open) when running locally.
343
- * @internal
344
- */
345
- purgedStorageAliases: Set<string>;
346
276
  constructor(options?: ActorOptions);
347
277
  /**
348
278
  * Runs the main user function that performs the job of the Actor
@@ -379,24 +309,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
379
309
  *
380
310
  * If the user function returns a promise, it is considered asynchronous:
381
311
  * ```js
382
- * import { gotScraping } from 'got-scraping';
383
- *
384
312
  * await Actor.main(() => {
385
313
  * // My asynchronous function that returns a promise
386
- * return gotScraping('http://www.example.com').then((html) => {
387
- * console.log(html);
388
- * });
314
+ * return fetch('http://www.example.com')
315
+ * .then((response) => response.text())
316
+ * .then((html) => {
317
+ * console.log(html);
318
+ * });
389
319
  * });
390
320
  * ```
391
321
  *
392
322
  * To simplify your code, you can take advantage of the `async`/`await` keywords:
393
323
  *
394
324
  * ```js
395
- * import { gotScraping } from 'got-scraping';
396
- *
397
325
  * await Actor.main(async () => {
398
326
  * // My asynchronous function
399
- * const html = await request('http://www.example.com');
327
+ * const html = await fetch('http://www.example.com').then((response) => response.text());
400
328
  * console.log(html);
401
329
  * });
402
330
  * ```
@@ -445,13 +373,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
445
373
  * @param actorId
446
374
  * Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
447
375
  * @param [input]
448
- * Input for the Actor. If it is an object, it will be stringified to
449
- * JSON and its content type set to `application/json; charset=utf-8`.
450
- * Otherwise the `options.contentType` parameter must be provided.
376
+ * Input for the Actor. A plain object is stringified to JSON with content type
377
+ * `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
451
378
  * @param [options]
452
379
  * @ignore
453
380
  */
454
- call(actorId: string, input?: unknown, options?: CallOptions): Promise<ClientActorRun>;
381
+ call(actorId: string, input?: ActorInput, options?: CallOptions): Promise<ClientActorRun>;
455
382
  /**
456
383
  * Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
457
384
  * unlike `Actor.call`, this method just starts the run without waiting for finish.
@@ -470,13 +397,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
470
397
  * @param actorId
471
398
  * Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
472
399
  * @param [input]
473
- * Input for the Actor. If it is an object, it will be stringified to
474
- * JSON and its content type set to `application/json; charset=utf-8`.
475
- * Otherwise the `options.contentType` parameter must be provided.
400
+ * Input for the Actor. A plain object is stringified to JSON with content type
401
+ * `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
476
402
  * @param [options]
477
403
  * @ignore
478
404
  */
479
- start(actorId: string, input?: unknown, options?: StartOptions): Promise<ClientActorRun>;
405
+ start(actorId: string, input?: ActorInput, options?: StartOptions): Promise<ClientActorRun>;
480
406
  /**
481
407
  * Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
482
408
  *
@@ -493,6 +419,25 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
493
419
  * @ignore
494
420
  */
495
421
  abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
422
+ /**
423
+ * Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
424
+ *
425
+ * Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
426
+ * status and keeps its default storages. Options you leave out keep the values of the original run.
427
+ *
428
+ * The result of the function is an {@link ActorRun} object that contains details about the Actor run.
429
+ *
430
+ * For more information about Actors, read the
431
+ * [documentation](https://docs.apify.com/actor).
432
+ *
433
+ * **Example usage:**
434
+ *
435
+ * ```js
436
+ * const run = await Actor.resurrect(runId);
437
+ * ```
438
+ * @ignore
439
+ */
440
+ resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
496
441
  /**
497
442
  * Runs an actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
498
443
  *
@@ -520,6 +465,45 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
520
465
  * @ignore
521
466
  */
522
467
  callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
468
+ /**
469
+ * Returns a client for each child run started by `Actor.start()`, `Actor.call()`, `Actor.startTask()` or
470
+ * `Actor.callTask()` after `Actor.init()`, in the order they were recorded, including the runs started before a
471
+ * migration, reboot or resurrection of this run.
472
+ *
473
+ * ```js
474
+ * const childRuns = await Actor.childRuns();
475
+ * await Promise.all(childRuns.filter((c) => c.abortWithParent).map((c) => c.waitForFinish()));
476
+ * ```
477
+ *
478
+ * The child runs are recorded in the default key-value store under the `APIFY_ACTOR_CHILD_RUNS` key. A run
479
+ * started with a custom `token` uses that token, except for a run started before a migration, reboot or
480
+ * resurrection of this run, which uses the default client.
481
+ */
482
+ childRuns(): Promise<ChildRunClient[]>;
483
+ /**
484
+ * Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
485
+ * unlike `Actor.callTask`, this method just starts the run without waiting for finish.
486
+ *
487
+ * The result of the function is an {@link ActorRun} object that contains details about the Actor run.
488
+ *
489
+ * For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
490
+ *
491
+ * **Example usage:**
492
+ *
493
+ * ```js
494
+ * const run = await Actor.startTask('bob/some-task');
495
+ * ```
496
+ *
497
+ * @param taskId
498
+ * Allowed formats are `username/task-name`, `userId/task-name` or task ID.
499
+ * @param [input]
500
+ * Input overrides for the Actor task. If it is an object, it will be stringified to
501
+ * JSON and its content type set to `application/json; charset=utf-8`.
502
+ * Provided input will be merged with Actor task input.
503
+ * @param [options]
504
+ * @ignore
505
+ */
506
+ startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
523
507
  /**
524
508
  * Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
525
509
  * the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
@@ -528,13 +512,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
528
512
  * @param targetActorId
529
513
  * Either `username/actor-name` or Actor ID of an Actor to which we want to metamorph.
530
514
  * @param [input]
531
- * Input for the Actor. If it is an object, it will be stringified to
532
- * JSON and its content type set to `application/json; charset=utf-8`.
533
- * Otherwise, the `options.contentType` parameter must be provided.
515
+ * Input for the Actor. A plain object is stringified to JSON with content type
516
+ * `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
534
517
  * @param [options]
535
518
  * @ignore
536
519
  */
537
- metamorph(targetActorId: string, input?: unknown, options?: MetamorphOptions): Promise<void>;
520
+ metamorph(targetActorId: string, input?: ActorInput, options?: MetamorphOptions): Promise<void>;
538
521
  /**
539
522
  * Internally reboots this Actor. The system stops the current container and starts
540
523
  * a new container with the same run ID.
@@ -555,15 +538,16 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
555
538
  * For more information, see the [Get webhook](https://apify.com/docs/api/v2#/reference/webhooks/webhook-object/get-webhook) API endpoint.
556
539
  * @ignore
557
540
  */
558
- addWebhook(options: WebhookOptions): Promise<Webhook | undefined>;
541
+ addWebhook(options: WebhookOptions): Promise<WebhookResource | undefined>;
559
542
  /**
560
543
  * Sets the status message for the current Actor run.
561
544
  *
562
- * @returns The return value is the Run object.
545
+ * @returns The updated Run object, or `undefined` when no run was updated: when run locally,
546
+ * or when the update failed or timed out (a warning is logged in that case).
563
547
  * For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
564
548
  * @ignore
565
549
  */
566
- setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
550
+ setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
567
551
  /**
568
552
  * Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
569
553
  *
@@ -584,9 +568,13 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
584
568
  * **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
585
569
  * otherwise the Actor process might finish before the data are stored!
586
570
  *
571
+ * Inside a crawlee storage transaction, the items are stored - and charged for - at commit time,
572
+ * so the returned counts are zero and charging for an explicit `eventName` is rejected outright.
573
+ *
587
574
  * @param item Object or array of objects containing data to be stored in the default dataset.
588
575
  * The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
589
576
  * @param eventName If provided, the method will attempt to charge for the event for each pushed item.
577
+ * Not supported in multi-tenant Server Actor runs, which charge per request with `Actor.charge()`.
590
578
  * @ignore
591
579
  */
592
580
  pushData(item: Data | Data[], eventName?: string | undefined): Promise<ChargeResult>;
@@ -602,8 +590,8 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
602
590
  * @param [datasetIdOrName]
603
591
  * ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
604
592
  * the function returns the default dataset associated with the Actor run.
605
- * You can also pass `{ alias: 'name' }` to open a dataset defined in the Actor's schema storages,
606
- * `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
593
+ * You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
594
+ * explicit ID, or `{ name: 'abc' }` to open by explicit name.
607
595
  * @param [options]
608
596
  * @ignore
609
597
  */
@@ -637,6 +625,35 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
637
625
  * @ignore
638
626
  */
639
627
  getValue<T = unknown>(key: string): Promise<T | null>;
628
+ /**
629
+ * Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
630
+ *
631
+ * This is just a convenient shortcut for {@link KeyValueStore.getValue}.
632
+ * For example, calling the following code:
633
+ * ```js
634
+ * const value = await Actor.getValue('my-key');
635
+ * ```
636
+ *
637
+ * is equivalent to:
638
+ * ```js
639
+ * const store = await Actor.openKeyValueStore();
640
+ * const value = await store.getValue('my-key');
641
+ * ```
642
+ *
643
+ * To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
644
+ *
645
+ * For more information, see {@link Actor.openKeyValueStore}
646
+ * and {@link KeyValueStore.getValue}.
647
+ *
648
+ * @param key Unique record key.
649
+ * @param defaultValue Fallback that will be returned if no value if present in the storage.
650
+ * @returns
651
+ * Returns a promise that resolves to an object, string
652
+ * or [`Buffer`](https://nodejs.org/api/buffer.html), depending
653
+ * on the MIME content type of the record, or the provided default value.
654
+ * @ignore
655
+ */
656
+ getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
640
657
  /**
641
658
  * Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
642
659
  *
@@ -672,17 +689,21 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
672
689
  /**
673
690
  * Gets the Actor input value from the default {@link KeyValueStore} associated with the current Actor run.
674
691
  *
675
- * This is just a convenient shortcut for [`keyValueStore.getValue('INPUT')`](core/class/KeyValueStore#getValue).
676
- * For example, calling the following code:
677
- * ```js
678
- * const input = await Actor.getInput();
679
- * ```
692
+ * The input is the record stored under the configured input key (`ACTOR_INPUT_KEY`, default `INPUT`).
693
+ * A record stored as `application/octet-stream` — which is what a local input file without an
694
+ * extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
680
695
  *
681
- * is equivalent to:
682
- * ```js
683
- * const store = await Actor.openKeyValueStore();
684
- * await store.getValue('INPUT');
685
- * ```
696
+ * When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
697
+ * working directory. A storage backend that doesn't read the default key-value store's directory under
698
+ * the storage directory (e.g. in-memory storage) also gets the file `apify run` writes there.
699
+ *
700
+ * Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
701
+ * replaced with the links of their CSV exports.
702
+ *
703
+ * Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
704
+ * found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
705
+ * (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
706
+ * Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest.
686
707
  *
687
708
  * Note that the `getInput()` function does not cache the value read from the key-value store.
688
709
  * If you need to use the input multiple times in your Actor,
@@ -694,16 +715,20 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
694
715
  * @returns
695
716
  * Returns a promise that resolves to an object, string
696
717
  * or [`Buffer`](https://nodejs.org/api/buffer.html), depending
697
- * on the MIME content type of the record, or `null`
698
- * if the record is missing.
718
+ * on the MIME content type of the record.
719
+ * @throws {ActorInputError} When the input cannot be produced; see `code`.
699
720
  * @ignore
700
721
  */
701
- getInput<T = Dictionary | string | Buffer>(): Promise<T | null>;
722
+ getInput<T = Dictionary | string | Buffer>(): Promise<T>;
702
723
  /**
703
- * Gets the Actor input value just like the {@link Actor.getInput} method,
704
- * but throws if it is not found.
724
+ * Reads the input from a `<inputKey>` or `<inputKey>.json` file in the given directory, for local runs
725
+ * whose default key-value store holds no input record. Mirrors how `ApifyFileSystemStorageBackend` adopts
726
+ * such files inside the store directory: the `.json` file is JSON, the bare one is bytes that
727
+ * {@link parseInputValue} tries as JSON5. Both files present is an error rather than a guess.
728
+ *
729
+ * @returns `undefined` when running on the platform or when neither file exists.
705
730
  */
706
- getInputOrThrow<T = Dictionary | string | Buffer>(): Promise<T>;
731
+ private readInputFromDirectory;
707
732
  /**
708
733
  * Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
709
734
  *
@@ -714,13 +739,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
714
739
  * For more details and code examples, see the {@link KeyValueStore} class.
715
740
  *
716
741
  * @param [storeIdOrName]
717
- * ID or name of the key-value store to be opened. If `null` or `undefined`,
742
+ * ID, name, or alias of the key-value store to be opened. If `null` or `undefined`,
718
743
  * the function returns the default key-value store associated with the Actor run.
719
- * You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
744
+ * You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
745
+ * explicit ID, or `{ name: 'abc' }` to open by explicit name.
720
746
  * @param [options]
721
747
  * @ignore
722
748
  */
723
- openKeyValueStore(storeIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
749
+ openKeyValueStore(storeIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
724
750
  /**
725
751
  * Opens a request queue and returns a promise resolving to an instance
726
752
  * of the {@link RequestQueue} class.
@@ -733,13 +759,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
733
759
  * For more details and code examples, see the {@link RequestQueue} class.
734
760
  *
735
761
  * @param [queueIdOrName]
736
- * ID or name of the request queue to be opened. If `null` or `undefined`,
762
+ * ID, name, or alias of the request queue to be opened. If `null` or `undefined`,
737
763
  * the function returns the default request queue associated with the Actor run.
738
- * You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
764
+ * You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
765
+ * explicit ID, or `{ name: 'abc' }` to open by explicit name.
739
766
  * @param [options]
740
767
  * @ignore
741
768
  */
742
- openRequestQueue(queueIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<RequestQueue>;
769
+ openRequestQueue(queueIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<RequestQueue>;
743
770
  /**
744
771
  * Creates a proxy configuration and returns a promise resolving to an instance
745
772
  * of the {@link ProxyConfiguration} class that is already initialized.
@@ -797,6 +824,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
797
824
  * rather than batching via `count` — this gives finer control over budget consumption
798
825
  * and avoids situations where more work is requested than the budget allows.
799
826
  *
827
+ * **Note:** `idempotencyKey` is scoped to the whole run, not to `requestId`. In a multi-tenant
828
+ * Server Actor run, a key reused across requests charges only the first caller, so it must
829
+ * be globally unique (e.g. derived from `requestId`).
830
+ *
800
831
  * @param options The name of the event to charge for and the number of events to be charged.
801
832
  * @ignore
802
833
  */
@@ -807,18 +838,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
807
838
  */
808
839
  getChargingManager(): ChargingManager;
809
840
  /**
810
- * Modifies Actor env vars so parsing respects the structure of {@link ApifyEnv} interface.
841
+ * Fetches the current Actor run from the Apify API. The result is cached for the lifetime of the Actor,
842
+ * so use `Actor.apifyClient.run(runId).get()` instead when you need fresh data such as the run status.
843
+ * Resolves to `undefined` when not running on the Apify platform.
811
844
  */
812
- private getModifiedActorEnvVars;
813
- /**
814
- * Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
815
- *
816
- * For the list of the Apify environment variables, see
817
- * [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
818
- * If some variables are not defined or are invalid, the corresponding value in the resulting object will be null.
819
- * @ignore
820
- */
821
- getEnv(): ApifyEnv;
845
+ getCurrentRun(): Promise<ClientActorRun | undefined>;
822
846
  /**
823
847
  * Returns a new instance of the Apify API client. The `ApifyClient` class is provided
824
848
  * by the [apify-client](https://www.npmjs.com/package/apify-client)
@@ -838,7 +862,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
838
862
  *
839
863
  * Values can be modified by simply using the assignment operator.
840
864
  *
841
- * @param name The name of the store to use.
865
+ * @param name The key of the record that holds the state. Defaults to `APIFY_GLOBAL_STATE`.
842
866
  * @param defaultValue If the store does not yet have a value in it, the value will be initialized with the `defaultValue` you provide.
843
867
  * @param options An optional object parameter where a custom `keyValueStoreName` and `config` can be passed in.
844
868
  */
@@ -848,7 +872,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
848
872
  *
849
873
  * Values can be modified by simply using the assignment operator.
850
874
  *
851
- * @param name The name of the store to use.
875
+ * @param name The key of the record that holds the state. Defaults to `APIFY_GLOBAL_STATE`.
852
876
  * @param defaultValue If the store does not yet have a value in it, the value will be initialized with the `defaultValue` you provide.
853
877
  * @param options An optional object parameter where a custom `keyValueStoreName` and `config` can be passed in.
854
878
  */
@@ -888,24 +912,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
888
912
  *
889
913
  * If the user function returns a promise, it is considered asynchronous:
890
914
  * ```js
891
- * import { gotScraping } from 'got-scraping';
892
- *
893
915
  * await Actor.main(() => {
894
916
  * // My asynchronous function that returns a promise
895
- * return gotScraping('http://www.example.com').then((html) => {
896
- * console.log(html);
897
- * });
917
+ * return fetch('http://www.example.com')
918
+ * .then((response) => response.text())
919
+ * .then((html) => {
920
+ * console.log(html);
921
+ * });
898
922
  * });
899
923
  * ```
900
924
  *
901
925
  * To simplify your code, you can take advantage of the `async`/`await` keywords:
902
926
  *
903
927
  * ```js
904
- * import { gotScraping } from 'got-scraping';
905
- *
906
928
  * await Actor.main(async () => {
907
929
  * // My asynchronous function
908
- * const html = await gotScraping('http://www.example.com');
930
+ * const html = await fetch('http://www.example.com').then((response) => response.text());
909
931
  * console.log(html);
910
932
  * });
911
933
  * ```
@@ -931,11 +953,9 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
931
953
  * behavior by setting `options.gracefulShutdown` to `false`.
932
954
  *
933
955
  * ```js
934
- * import { gotScraping } from 'got-scraping';
935
- *
936
956
  * await Actor.init();
937
957
  *
938
- * const html = await gotScraping('http://www.example.com');
958
+ * const html = await fetch('http://www.example.com').then((response) => response.text());
939
959
  * console.log(html);
940
960
  *
941
961
  * await Actor.exit();
@@ -976,12 +996,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
976
996
  * @param actorId
977
997
  * Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
978
998
  * @param [input]
979
- * Input for the Actor. If it is an object, it will be stringified to
980
- * JSON and its content type set to `application/json; charset=utf-8`.
981
- * Otherwise the `options.contentType` parameter must be provided.
999
+ * Input for the Actor. A plain object is stringified to JSON with content type
1000
+ * `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
982
1001
  * @param [options]
983
1002
  */
984
- static call(actorId: string, input?: unknown, options?: CallOptions): Promise<ClientActorRun>;
1003
+ static call(actorId: string, input?: ActorInput, options?: CallOptions): Promise<ClientActorRun>;
985
1004
  /**
986
1005
  * Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
987
1006
  *
@@ -1008,6 +1027,29 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1008
1027
  * @param [options]
1009
1028
  */
1010
1029
  static callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
1030
+ /**
1031
+ * Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
1032
+ * unlike `Actor.callTask`, this method just starts the run without waiting for finish.
1033
+ *
1034
+ * The result of the function is an {@link ActorRun} object that contains details about the Actor run.
1035
+ *
1036
+ * For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
1037
+ *
1038
+ * **Example usage:**
1039
+ *
1040
+ * ```js
1041
+ * const run = await Actor.startTask('bob/some-task');
1042
+ * ```
1043
+ *
1044
+ * @param taskId
1045
+ * Allowed formats are `username/task-name`, `userId/task-name` or task ID.
1046
+ * @param [input]
1047
+ * Input overrides for the Actor task. If it is an object, it will be stringified to
1048
+ * JSON and its content type set to `application/json; charset=utf-8`.
1049
+ * Provided input will be merged with Actor task input.
1050
+ * @param [options]
1051
+ */
1052
+ static startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
1011
1053
  /**
1012
1054
  * Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
1013
1055
  * unlike `Actor.call`, this method just starts the run without waiting for finish.
@@ -1026,12 +1068,26 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1026
1068
  * @param actorId
1027
1069
  * Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
1028
1070
  * @param [input]
1029
- * Input for the Actor. If it is an object, it will be stringified to
1030
- * JSON and its content type set to `application/json; charset=utf-8`.
1031
- * Otherwise the `options.contentType` parameter must be provided.
1071
+ * Input for the Actor. A plain object is stringified to JSON with content type
1072
+ * `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
1032
1073
  * @param [options]
1033
1074
  */
1034
1075
  static start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ClientActorRun>;
1076
+ /**
1077
+ * Returns a client for each child run started by `Actor.start()`, `Actor.call()`, `Actor.startTask()` or
1078
+ * `Actor.callTask()` after `Actor.init()`, in the order they were recorded, including the runs started before a
1079
+ * migration, reboot or resurrection of this run.
1080
+ *
1081
+ * ```js
1082
+ * const childRuns = await Actor.childRuns();
1083
+ * await Promise.all(childRuns.filter((c) => c.abortWithParent).map((c) => c.waitForFinish()));
1084
+ * ```
1085
+ *
1086
+ * The child runs are recorded in the default key-value store under the `APIFY_ACTOR_CHILD_RUNS` key. A run
1087
+ * started with a custom `token` uses that token, except for a run started before a migration, reboot or
1088
+ * resurrection of this run, which uses the default client.
1089
+ */
1090
+ static childRuns(): Promise<ChildRunClient[]>;
1035
1091
  /**
1036
1092
  * Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
1037
1093
  *
@@ -1047,6 +1103,24 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1047
1103
  * ```
1048
1104
  */
1049
1105
  static abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
1106
+ /**
1107
+ * Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
1108
+ *
1109
+ * Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
1110
+ * status and keeps its default storages. Options you leave out keep the values of the original run.
1111
+ *
1112
+ * The result of the function is an {@link ActorRun} object that contains details about the Actor run.
1113
+ *
1114
+ * For more information about Actors, read the
1115
+ * [documentation](https://docs.apify.com/actor).
1116
+ *
1117
+ * **Example usage:**
1118
+ *
1119
+ * ```js
1120
+ * const run = await Actor.resurrect(runId);
1121
+ * ```
1122
+ */
1123
+ static resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
1050
1124
  /**
1051
1125
  * Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
1052
1126
  * the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
@@ -1055,12 +1129,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1055
1129
  * @param targetActorId
1056
1130
  * Either `username/actor-name` or Actor ID of an Actor to which we want to metamorph.
1057
1131
  * @param [input]
1058
- * Input for the Actor. If it is an object, it will be stringified to
1059
- * JSON and its content type set to `application/json; charset=utf-8`.
1060
- * Otherwise, the `options.contentType` parameter must be provided.
1132
+ * Input for the Actor. A plain object is stringified to JSON with content type
1133
+ * `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
1061
1134
  * @param [options]
1062
1135
  */
1063
- static metamorph(targetActorId: string, input?: unknown, options?: MetamorphOptions): Promise<void>;
1136
+ static metamorph(targetActorId: string, input?: ActorInput, options?: MetamorphOptions): Promise<void>;
1064
1137
  /**
1065
1138
  * Internally reboots this Actor run. The system stops the current container and starts
1066
1139
  * a new container with the same run id.
@@ -1078,7 +1151,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1078
1151
  * @returns The return value is the Webhook object.
1079
1152
  * For more information, see the [Get webhook](https://apify.com/docs/api/v2#/reference/webhooks/webhook-object/get-webhook) API endpoint.
1080
1153
  */
1081
- static addWebhook(options: WebhookOptions): Promise<Webhook | undefined>;
1154
+ static addWebhook(options: WebhookOptions): Promise<WebhookResource | undefined>;
1082
1155
  /**
1083
1156
  * Sets the status message for the current Actor run.
1084
1157
  *
@@ -1086,10 +1159,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1086
1159
  * @param [options]
1087
1160
  * @param [options.isStatusMessageTerminal] If `true`, the status message will be marked as terminal.
1088
1161
  * This is required for the last status message of the run. Default value is `false`.
1089
- * @returns The return value is the Run object. When run locally, this method returns empty object (`{}`).
1162
+ * @returns The updated Run object, or `undefined` when no run was updated: when run locally,
1163
+ * or when the update failed or timed out (a warning is logged in that case).
1090
1164
  * For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
1091
1165
  */
1092
- static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
1166
+ static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
1093
1167
  /**
1094
1168
  * Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
1095
1169
  *
@@ -1134,9 +1208,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1134
1208
  * **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
1135
1209
  * otherwise the Actor process might finish before the data are stored!
1136
1210
  *
1211
+ * Charging is rejected inside a crawlee storage transaction, where the items would only be stored
1212
+ * at commit while the charge happens immediately - use `withDirectStorageAccess()` to opt out of
1213
+ * the transaction, or push without an event name and charge separately.
1214
+ *
1137
1215
  * @param item Object or array of objects containing data to be stored in the default dataset.
1138
1216
  * The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
1139
1217
  * @param eventName If provided, the method will attempt to charge for the event for each pushed item.
1218
+ * Not supported in multi-tenant Server Actor runs, which charge per request with `Actor.charge()`.
1140
1219
  */
1141
1220
  static pushData<Data extends Dictionary = Dictionary>(item: Data | Data[], eventName: string): Promise<ChargeResult>;
1142
1221
  /**
@@ -1151,8 +1230,8 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1151
1230
  * @param [datasetIdOrName]
1152
1231
  * ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
1153
1232
  * the function returns the default dataset associated with the Actor run.
1154
- * You can also pass `{ alias: 'name' }` to open a dataset defined in the Actor's schema storages,
1155
- * `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
1233
+ * You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
1234
+ * explicit ID, or `{ name: 'abc' }` to open by explicit name.
1156
1235
  * @param [options]
1157
1236
  */
1158
1237
  static openDataset<Data extends Dictionary = Dictionary>(datasetIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<Dataset<Data>>;
@@ -1184,6 +1263,34 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1184
1263
  * if the record is missing.
1185
1264
  */
1186
1265
  static getValue<T = unknown>(key: string): Promise<T | null>;
1266
+ /**
1267
+ * Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
1268
+ *
1269
+ * This is just a convenient shortcut for {@link KeyValueStore.getValue}.
1270
+ * For example, calling the following code:
1271
+ * ```js
1272
+ * const value = await Actor.getValue('my-key');
1273
+ * ```
1274
+ *
1275
+ * is equivalent to:
1276
+ * ```js
1277
+ * const store = await Actor.openKeyValueStore();
1278
+ * const value = await store.getValue('my-key');
1279
+ * ```
1280
+ *
1281
+ * To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
1282
+ *
1283
+ * For more information, see {@link Actor.openKeyValueStore}
1284
+ * and {@link KeyValueStore.getValue}.
1285
+ *
1286
+ * @param key Unique record key.
1287
+ * @param defaultValue Fallback that will be returned if no value if present in the storage.
1288
+ * @returns
1289
+ * Returns a promise that resolves to an object, string
1290
+ * or [`Buffer`](https://nodejs.org/api/buffer.html), depending
1291
+ * on the MIME content type of the record, or the provided default value.
1292
+ */
1293
+ static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
1187
1294
  /**
1188
1295
  * Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
1189
1296
  *
@@ -1218,16 +1325,31 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1218
1325
  /**
1219
1326
  * Gets the Actor input value from the default {@link KeyValueStore} associated with the current Actor run.
1220
1327
  *
1221
- * This is just a convenient shortcut for {@link KeyValueStore.getValue | `keyValueStore.getValue('INPUT')`}.
1222
- * For example, calling the following code:
1328
+ * The input is the record stored under the configured input key (`ACTOR_INPUT_KEY`, default `INPUT`):
1223
1329
  * ```js
1224
1330
  * const input = await Actor.getInput();
1225
1331
  * ```
1226
1332
  *
1227
- * is equivalent to:
1333
+ * A record stored as `application/octet-stream` — which is what a local input file without an
1334
+ * extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
1335
+ *
1336
+ * When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
1337
+ * working directory.
1338
+ *
1339
+ * Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
1340
+ * replaced with the links of their CSV exports.
1341
+ *
1342
+ * Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
1343
+ * found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
1344
+ * (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
1345
+ * Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest:
1228
1346
  * ```js
1229
- * const store = await Actor.openKeyValueStore();
1230
- * await store.getValue('INPUT');
1347
+ * let input = {};
1348
+ * try {
1349
+ * input = await Actor.getInput();
1350
+ * } catch (error) {
1351
+ * if (!(error instanceof ActorInputError) || error.code !== 'NOT_FOUND') throw error;
1352
+ * }
1231
1353
  * ```
1232
1354
  *
1233
1355
  * Note that the `getInput()` function does not cache the value read from the key-value store.
@@ -1239,15 +1361,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1239
1361
  * @returns
1240
1362
  * Returns a promise that resolves to an object, string
1241
1363
  * or [`Buffer`](https://nodejs.org/api/buffer.html), depending
1242
- * on the MIME content type of the record, or `null`
1243
- * if the record is missing.
1364
+ * on the MIME content type of the record.
1365
+ * @throws {ActorInputError} When the input cannot be produced; see `code`.
1244
1366
  */
1245
- static getInput<T = Dictionary | string | Buffer>(): Promise<T | null>;
1246
- /**
1247
- * Gets the Actor input value just like the {@link Actor.getInput} method,
1248
- * but throws if it is not found.
1249
- */
1250
- static getInputOrThrow<T = Dictionary | string | Buffer>(): Promise<T>;
1367
+ static getInput<T = Dictionary | string | Buffer>(): Promise<T>;
1251
1368
  /**
1252
1369
  * Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
1253
1370
  *
@@ -1263,7 +1380,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1263
1380
  * You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
1264
1381
  * @param [options]
1265
1382
  */
1266
- static openKeyValueStore(storeIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
1383
+ static openKeyValueStore(storeIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
1267
1384
  /**
1268
1385
  * Opens a request queue and returns a promise resolving to an instance
1269
1386
  * of the {@link RequestQueue} class.
@@ -1281,7 +1398,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1281
1398
  * You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
1282
1399
  * @param [options]
1283
1400
  */
1284
- static openRequestQueue(queueIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<RequestQueue>;
1401
+ static openRequestQueue(queueIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<RequestQueue>;
1285
1402
  /**
1286
1403
  * Creates a proxy configuration and returns a promise resolving to an instance
1287
1404
  * of the {@link ProxyConfiguration} class that is already initialized.
@@ -1337,6 +1454,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1337
1454
  * rather than batching via `count` — this gives finer control over budget consumption
1338
1455
  * and avoids situations where more work is requested than the budget allows.
1339
1456
  *
1457
+ * **Note:** `idempotencyKey` is scoped to the whole run, not to `requestId`. In a multi-tenant
1458
+ * Server Actor run, a key reused across requests charges only the first caller, so it must
1459
+ * be globally unique (e.g. derived from `requestId`).
1460
+ *
1340
1461
  * @param options The name of the event to charge for and the number of events to be charged.
1341
1462
  */
1342
1463
  static charge(options: ChargeOptions): Promise<ChargeResult>;
@@ -1344,14 +1465,6 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1344
1465
  * Retrieve the charging manager to access granular pricing information.
1345
1466
  */
1346
1467
  static getChargingManager(): ChargingManager;
1347
- /**
1348
- * Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
1349
- *
1350
- * For the list of the Apify environment variables, see
1351
- * [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
1352
- * If some of the variables are not defined or are invalid, the corresponding value in the resulting object will be null.
1353
- */
1354
- static getEnv(): ApifyEnv;
1355
1468
  /**
1356
1469
  * Returns a new instance of the Apify API client. The `ApifyClient` class is provided
1357
1470
  * by the [apify-client](https://www.npmjs.com/package/apify-client)
@@ -1364,21 +1477,43 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
1364
1477
  * Returns `true` when code is running on Apify platform and `false` otherwise (for example locally).
1365
1478
  */
1366
1479
  static isAtHome(): boolean;
1480
+ /**
1481
+ * Fetches the current Actor run from the Apify API. The result is cached for the lifetime of the Actor,
1482
+ * so use `Actor.apifyClient.run(runId).get()` instead when you need fresh data such as the run status.
1483
+ * Resolves to `undefined` when not running on the Apify platform.
1484
+ */
1485
+ static getCurrentRun(): Promise<ClientActorRun | undefined>;
1367
1486
  /** Default {@link ApifyClient} instance. */
1368
1487
  static get apifyClient(): ApifyClient;
1369
1488
  /** Default {@link Configuration} instance. */
1370
- static get config(): Configuration;
1489
+ static get configuration(): Configuration;
1371
1490
  /** @internal */
1372
1491
  static getDefaultInstance(): Actor;
1373
- private usesPushDataInterception;
1374
- private pushDataViaInterceptedClient;
1375
- private pushDataWithExplicitCharging;
1376
- private _openStorage;
1377
- private _ensureActorInit;
1378
1492
  /**
1379
- * Get time remaining from the Actor run timeout. Returns `undefined` if not on an Apify platform or the current
1380
- * run was started without a timeout.
1493
+ * Replaces or clears the cached default instance returned by {@link Actor.getDefaultInstance}.
1494
+ * @internal
1495
+ */
1496
+ static setDefaultInstance(instance?: Actor): void;
1497
+ /**
1498
+ * The same choice crawlee's `ServiceLocator` makes for its implicit default backend, with the
1499
+ * input-aware {@link ApifyFileSystemStorageBackend} in place of crawlee's — crawlee has no
1500
+ * notion of a run input.
1501
+ */
1502
+ private createLocalStorageBackend;
1503
+ /**
1504
+ * crawlee's service locator is set-once, so a backend registered before `init()` wins and the
1505
+ * Actor cannot install its own over it. Replaces the resulting `ServiceConflictError` with the
1506
+ * way out.
1507
+ */
1508
+ private installStorageBackend;
1509
+ private ensureActorInit;
1510
+ /**
1511
+ * Get time remaining from the Actor run timeout in seconds, rounded up to whole seconds with minimum value of 1 second.
1512
+ *
1513
+ * The API treats a 0 second timeout as no timeout, the minimum acceptable timeout is 1 second.
1514
+ *
1515
+ * Returns `undefined` if not on the Apify platform or the current run was started without a timeout.
1381
1516
  */
1382
- private getRemainingTime;
1517
+ private getRemainingTimeSecs;
1383
1518
  private inferDefaultsFromInputSchema;
1384
1519
  }