apify 3.7.3-beta.96 → 4.0.0-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/actor.d.ts +379 -139
- package/dist/actor.js +764 -500
- package/dist/apify_dataset_backend.d.ts +19 -0
- package/dist/apify_dataset_backend.js +77 -0
- package/dist/apify_file_system_storage_backend.d.ts +34 -0
- package/dist/apify_file_system_storage_backend.js +41 -0
- package/dist/apify_key_value_store_backend.d.ts +23 -0
- package/dist/apify_key_value_store_backend.js +56 -0
- package/dist/apify_request_queue_backend.d.ts +78 -0
- package/dist/apify_request_queue_backend.js +114 -0
- package/dist/apify_request_queue_shared_backend.d.ts +31 -0
- package/dist/apify_request_queue_shared_backend.js +193 -0
- package/dist/apify_request_queue_single_backend.d.ts +43 -0
- package/dist/apify_request_queue_single_backend.js +256 -0
- package/dist/apify_storage_backend.d.ts +90 -0
- package/dist/apify_storage_backend.js +210 -0
- package/dist/charging.d.ts +39 -44
- package/dist/charging.js +245 -292
- package/dist/charging_storage_backend.d.ts +53 -0
- package/dist/charging_storage_backend.js +105 -0
- package/dist/child_run_tracker.d.ts +88 -0
- package/dist/child_run_tracker.js +239 -0
- package/dist/configuration.d.ts +85 -144
- package/dist/configuration.js +138 -174
- package/dist/enqueue_links_filters.d.ts +29 -0
- package/dist/enqueue_links_filters.js +52 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +22 -0
- package/dist/google_sheets.d.ts +12 -0
- package/dist/google_sheets.js +26 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +12 -22
- package/dist/input-schemas.d.ts +1 -1
- package/dist/input-schemas.js +12 -18
- package/dist/platform_event_manager.d.ts +15 -10
- package/dist/platform_event_manager.js +193 -63
- package/dist/proxy_configuration.d.ts +52 -72
- package/dist/proxy_configuration.js +176 -221
- package/dist/smart_apify_storage_backend.d.ts +52 -0
- package/dist/smart_apify_storage_backend.js +73 -0
- package/dist/storage.d.ts +6 -24
- package/dist/storage.js +1 -79
- package/dist/utils.d.ts +30 -0
- package/dist/utils.js +81 -23
- package/package.json +38 -43
- package/dist/index.mjs +0 -19
- package/dist/key_value_store.d.ts +0 -16
- package/dist/key_value_store.js +0 -40
- package/dist/patched_apify_client.d.ts +0 -25
- package/dist/patched_apify_client.js +0 -75
package/dist/actor.d.ts
CHANGED
|
@@ -1,18 +1,41 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Dataset, RequestQueue } from '@crawlee/core';
|
|
3
|
-
import type { Awaitable, Dictionary,
|
|
4
|
-
import type { ActorCallOptions,
|
|
5
|
-
import {
|
|
1
|
+
import type { EventManager, EventTypeName, RecordOptions, UseStateOptions } from '@crawlee/core';
|
|
2
|
+
import { Dataset, KeyValueStore, RequestQueue } from '@crawlee/core';
|
|
3
|
+
import type { Awaitable, Dictionary, StorageBackend } from '@crawlee/types';
|
|
4
|
+
import type { ActorCallOptions, ActorInput, ActorStartOptions, ApifyClientOptions, RunAbortOptions, RunClient, RunResurrectOptions, TaskCallOptions, TaskStartOptions, WebhookResource, WebhookEventType } from 'apify-client';
|
|
5
|
+
import { ApifyClient, Run as ClientActorRun } from 'apify-client';
|
|
6
6
|
import { type ACTOR_PERMISSION_LEVEL } from '@apify/consts';
|
|
7
|
+
import type { RequestQueueAccessMode } from './apify_request_queue_backend.js';
|
|
7
8
|
import type { ChargeOptions, ChargeResult } from './charging.js';
|
|
8
9
|
import { ChargingManager } from './charging.js';
|
|
10
|
+
import type { ConfigurationOptions } from './configuration.js';
|
|
9
11
|
import { Configuration } from './configuration.js';
|
|
10
|
-
import { KeyValueStore } from './key_value_store.js';
|
|
11
12
|
import type { ProxyConfigurationOptions } from './proxy_configuration.js';
|
|
12
13
|
import { ProxyConfiguration } from './proxy_configuration.js';
|
|
13
|
-
import type { OpenStorageOptions, StorageIdentifier
|
|
14
|
+
import type { OpenStorageOptions, StorageIdentifier } from './storage.js';
|
|
14
15
|
export interface InitOptions {
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Storage backend to use, in place of the Apify platform storage (on the platform) or crawlee's
|
|
18
|
+
* local storage (outside of it).
|
|
19
|
+
*
|
|
20
|
+
* Items pushed to the default dataset are then not charged for under the pay-per-event pricing
|
|
21
|
+
* model: the platform counts an `apify-default-dataset-item` per item it stores itself, and a
|
|
22
|
+
* backend of your own stores them elsewhere.
|
|
23
|
+
*/
|
|
24
|
+
storage?: StorageBackend;
|
|
25
|
+
/**
|
|
26
|
+
* Determines how request queues opened on the Apify platform are consumed.
|
|
27
|
+
*
|
|
28
|
+
* - `'single'` (default) assumes this run is the only consumer of its request queues. Requests
|
|
29
|
+
* are not locked server-side and the queue head is estimated locally, which means fewer
|
|
30
|
+
* (paid) API calls and better performance.
|
|
31
|
+
* - `'shared'` locks every fetched request server-side, so any number of concurrent consumers
|
|
32
|
+
* (e.g. several Actor runs) can safely process the same queue, at the cost of roughly one
|
|
33
|
+
* extra API call per processed request.
|
|
34
|
+
*
|
|
35
|
+
* Only applies on the Apify platform (or with `forceCloud`); local storage ignores it.
|
|
36
|
+
* @default 'single'
|
|
37
|
+
*/
|
|
38
|
+
requestQueueAccess?: RequestQueueAccessMode;
|
|
16
39
|
/**
|
|
17
40
|
* Whether to automatically handle platform shutdown signals.
|
|
18
41
|
* When enabled, `Actor.exit()` is called on `aborting` events and `Actor.reboot()` on `migrating` events.
|
|
@@ -26,6 +49,20 @@ export interface InitOptions {
|
|
|
26
49
|
*/
|
|
27
50
|
gracefulShutdownDelayMillis?: number;
|
|
28
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Options accepted by the {@link Actor} constructor. Either pass field-level
|
|
54
|
+
* overrides (`token`, `inputKey`, …) — which the Actor turns into a fresh
|
|
55
|
+
* {@link Configuration} — or pass a pre-built `configuration` instance. When
|
|
56
|
+
* both are present, `configuration` wins and the field-level overrides are
|
|
57
|
+
* ignored.
|
|
58
|
+
*/
|
|
59
|
+
export type ActorOptions = ConfigurationOptions & {
|
|
60
|
+
/**
|
|
61
|
+
* Pre-built {@link Configuration} instance the Actor should use. Takes
|
|
62
|
+
* precedence over any field-level overrides also passed in `options`.
|
|
63
|
+
*/
|
|
64
|
+
configuration?: Configuration;
|
|
65
|
+
};
|
|
29
66
|
export interface ExitOptions {
|
|
30
67
|
/** Exit with given status message */
|
|
31
68
|
statusMessage?: string;
|
|
@@ -41,6 +78,12 @@ export interface ExitOptions {
|
|
|
41
78
|
}
|
|
42
79
|
export interface MainOptions extends ExitOptions, InitOptions {
|
|
43
80
|
}
|
|
81
|
+
export interface SetStatusMessageOptions {
|
|
82
|
+
/** If `true`, the status message is treated as final and won't be overwritten by the platform. */
|
|
83
|
+
isStatusMessageTerminal?: boolean;
|
|
84
|
+
/** Log level used when the status message is also logged locally. Defaults to `INFO`. */
|
|
85
|
+
level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
86
|
+
}
|
|
44
87
|
/**
|
|
45
88
|
* Parsed representation of the Apify environment variables.
|
|
46
89
|
* This object is returned by the {@link Actor.getEnv} function.
|
|
@@ -72,9 +115,9 @@ export interface ApifyEnv {
|
|
|
72
115
|
*/
|
|
73
116
|
userId: string | null;
|
|
74
117
|
/**
|
|
75
|
-
*
|
|
118
|
+
* Whether the user who started the Actor is a paying user. `false` when not set. (APIFY_USER_IS_PAYING)
|
|
76
119
|
*/
|
|
77
|
-
userIsPaying:
|
|
120
|
+
userIsPaying: boolean;
|
|
78
121
|
/**
|
|
79
122
|
* Authentication token representing privileges given to the Actor run,
|
|
80
123
|
* it can be passed to various Apify APIs (APIFY_TOKEN)
|
|
@@ -127,7 +170,6 @@ export interface ApifyEnv {
|
|
|
127
170
|
apiPublicBaseUrl: string | null;
|
|
128
171
|
chromeExecutablePath: string | null;
|
|
129
172
|
dedicatedCpus: string | null;
|
|
130
|
-
disableOutdatedWarning: 1 | null;
|
|
131
173
|
fact: string | null;
|
|
132
174
|
inputSecretsPrivateKeyFile: string | null;
|
|
133
175
|
inputSecretsPrivateKeyPassphrase: string | null;
|
|
@@ -153,7 +195,6 @@ export interface ApifyEnv {
|
|
|
153
195
|
* The key of the input record in the Actor’s default key-value store (ACTOR_INPUT_KEY)
|
|
154
196
|
*/
|
|
155
197
|
inputKey: string | null;
|
|
156
|
-
sdkLatestVersion: string | null;
|
|
157
198
|
systemInfoIntervalMillis: string | null;
|
|
158
199
|
workflowKey: string | null;
|
|
159
200
|
actorBuildNumber: string | null;
|
|
@@ -179,11 +220,38 @@ export interface Timeout {
|
|
|
179
220
|
*/
|
|
180
221
|
timeout?: number | 'inherit';
|
|
181
222
|
}
|
|
182
|
-
export interface
|
|
223
|
+
export interface ChildRunOptions {
|
|
224
|
+
/**
|
|
225
|
+
* Local name for the child run, unique across all Actors and tasks started by this run.
|
|
226
|
+
*
|
|
227
|
+
* If a `READY`, `RUNNING` or `SUCCEEDED` run is already tracked under this name, it is returned instead of
|
|
228
|
+
* starting a new one, including after a migration or resurrection of this run. A run that was aborted or timed out
|
|
229
|
+
* is resurrected with the given options, once it finishes aborting or timing out. A run that failed is replaced
|
|
230
|
+
* by a new one. Reusing the name for a different Actor, task or input throws, unless the tracked run is replaced.
|
|
231
|
+
*/
|
|
232
|
+
runName?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Gracefully abort the child run when this run is gracefully aborted. Requires `runName`.
|
|
235
|
+
*
|
|
236
|
+
* The latest call under the same `runName` sets the value. Once this run is being aborted, a call with this option
|
|
237
|
+
* throws instead of starting, resurrecting or returning a run. A hard abort, timeout or crash of this run leaves
|
|
238
|
+
* the child run running.
|
|
239
|
+
*
|
|
240
|
+
* A run started with a custom `token` is aborted with that token, except for a run started before a migration or
|
|
241
|
+
* resurrection of this run, which is aborted with the default client.
|
|
242
|
+
* @default false
|
|
243
|
+
*/
|
|
244
|
+
abortWithParent?: boolean;
|
|
245
|
+
}
|
|
246
|
+
export interface CallOptions extends Omit<ActorCallOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
183
247
|
}
|
|
184
|
-
export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | '
|
|
248
|
+
export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
185
249
|
}
|
|
186
|
-
export interface CallTaskOptions extends Omit<TaskCallOptions, '
|
|
250
|
+
export interface CallTaskOptions extends Omit<TaskCallOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
251
|
+
}
|
|
252
|
+
export interface ResurrectOptions extends Omit<RunResurrectOptions, 'runTimeoutSecs' | 'maxItems'>, Token, Timeout {
|
|
253
|
+
}
|
|
254
|
+
export interface StartTaskOptions extends Omit<TaskStartOptions, 'waitForFinish' | 'runTimeoutSecs' | 'maxItems'>, Token, Timeout, ChildRunOptions {
|
|
187
255
|
}
|
|
188
256
|
export interface AbortOptions extends RunAbortOptions, Token {
|
|
189
257
|
/** Exit with given status message */
|
|
@@ -250,7 +318,7 @@ export interface MetamorphOptions {
|
|
|
250
318
|
* Content type for the `input`. If not specified,
|
|
251
319
|
* `input` is expected to be an object that will be stringified to JSON and content type set to
|
|
252
320
|
* `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
|
|
253
|
-
* `
|
|
321
|
+
* `Buffer`.
|
|
254
322
|
*/
|
|
255
323
|
contentType?: string;
|
|
256
324
|
/**
|
|
@@ -283,13 +351,12 @@ export declare const EXIT_CODES: {
|
|
|
283
351
|
* See {@link Configuration} for details about what can be configured and what are the default values.
|
|
284
352
|
*/
|
|
285
353
|
export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
286
|
-
|
|
287
|
-
static _instance: Actor;
|
|
354
|
+
#private;
|
|
288
355
|
/**
|
|
289
356
|
* Configuration of this SDK instance (provided to its constructor). See {@link Configuration} for details.
|
|
290
357
|
* @internal
|
|
291
358
|
*/
|
|
292
|
-
readonly
|
|
359
|
+
readonly configuration: Configuration;
|
|
293
360
|
/**
|
|
294
361
|
* Default {@link ApifyClient} instance.
|
|
295
362
|
* @internal
|
|
@@ -304,31 +371,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
304
371
|
* Whether the Actor instance was initialized. This is set by calling {@link Actor.init}.
|
|
305
372
|
*/
|
|
306
373
|
initialized: boolean;
|
|
307
|
-
|
|
308
|
-
* Set if the Actor called a method that requires the instance to be initialized, but did not do so.
|
|
309
|
-
* A call to `init` after this warning is emitted is considered an invalid state and will throw an error.
|
|
310
|
-
*/
|
|
311
|
-
private warnedAboutMissingInitCall;
|
|
312
|
-
/**
|
|
313
|
-
* Set if the Actor is currently rebooting.
|
|
314
|
-
*/
|
|
315
|
-
private isRebooting;
|
|
316
|
-
/**
|
|
317
|
-
* Set if the Actor is currently exiting. Prevents double-exit from graceful shutdown handlers.
|
|
318
|
-
*/
|
|
319
|
-
private isExiting;
|
|
320
|
-
/**
|
|
321
|
-
* References to graceful shutdown handlers so they can be removed during cleanup.
|
|
322
|
-
*/
|
|
323
|
-
private gracefulShutdownHandlers;
|
|
324
|
-
private chargingManager;
|
|
325
|
-
/**
|
|
326
|
-
* Tracks which aliased storages have been purged during this session,
|
|
327
|
-
* so we only purge them once (on first open) when running locally.
|
|
328
|
-
* @internal
|
|
329
|
-
*/
|
|
330
|
-
purgedStorageAliases: Set<string>;
|
|
331
|
-
constructor(options?: ConfigurationOptions);
|
|
374
|
+
constructor(options?: ActorOptions);
|
|
332
375
|
/**
|
|
333
376
|
* Runs the main user function that performs the job of the Actor
|
|
334
377
|
* and terminates the process when the user function finishes.
|
|
@@ -364,24 +407,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
364
407
|
*
|
|
365
408
|
* If the user function returns a promise, it is considered asynchronous:
|
|
366
409
|
* ```js
|
|
367
|
-
* import { gotScraping } from 'got-scraping';
|
|
368
|
-
*
|
|
369
410
|
* await Actor.main(() => {
|
|
370
411
|
* // My asynchronous function that returns a promise
|
|
371
|
-
* return
|
|
372
|
-
*
|
|
373
|
-
*
|
|
412
|
+
* return fetch('http://www.example.com')
|
|
413
|
+
* .then((response) => response.text())
|
|
414
|
+
* .then((html) => {
|
|
415
|
+
* console.log(html);
|
|
416
|
+
* });
|
|
374
417
|
* });
|
|
375
418
|
* ```
|
|
376
419
|
*
|
|
377
420
|
* To simplify your code, you can take advantage of the `async`/`await` keywords:
|
|
378
421
|
*
|
|
379
422
|
* ```js
|
|
380
|
-
* import { gotScraping } from 'got-scraping';
|
|
381
|
-
*
|
|
382
423
|
* await Actor.main(async () => {
|
|
383
424
|
* // My asynchronous function
|
|
384
|
-
* const html = await
|
|
425
|
+
* const html = await fetch('http://www.example.com').then((response) => response.text());
|
|
385
426
|
* console.log(html);
|
|
386
427
|
* });
|
|
387
428
|
* ```
|
|
@@ -430,13 +471,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
430
471
|
* @param actorId
|
|
431
472
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
432
473
|
* @param [input]
|
|
433
|
-
* Input for the Actor.
|
|
434
|
-
*
|
|
435
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
474
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
475
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
436
476
|
* @param [options]
|
|
437
477
|
* @ignore
|
|
438
478
|
*/
|
|
439
|
-
call(actorId: string, input?:
|
|
479
|
+
call(actorId: string, input?: ActorInput, options?: CallOptions): Promise<ClientActorRun>;
|
|
440
480
|
/**
|
|
441
481
|
* Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
442
482
|
* unlike `Actor.call`, this method just starts the run without waiting for finish.
|
|
@@ -455,13 +495,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
455
495
|
* @param actorId
|
|
456
496
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
457
497
|
* @param [input]
|
|
458
|
-
* Input for the Actor.
|
|
459
|
-
*
|
|
460
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
498
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
499
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
461
500
|
* @param [options]
|
|
462
501
|
* @ignore
|
|
463
502
|
*/
|
|
464
|
-
start(actorId: string, input?:
|
|
503
|
+
start(actorId: string, input?: ActorInput, options?: StartOptions): Promise<ClientActorRun>;
|
|
465
504
|
/**
|
|
466
505
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
467
506
|
*
|
|
@@ -478,6 +517,25 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
478
517
|
* @ignore
|
|
479
518
|
*/
|
|
480
519
|
abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
|
|
520
|
+
/**
|
|
521
|
+
* Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
522
|
+
*
|
|
523
|
+
* Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
|
|
524
|
+
* status and keeps its default storages. Options you leave out keep the values of the original run.
|
|
525
|
+
*
|
|
526
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
527
|
+
*
|
|
528
|
+
* For more information about Actors, read the
|
|
529
|
+
* [documentation](https://docs.apify.com/actor).
|
|
530
|
+
*
|
|
531
|
+
* **Example usage:**
|
|
532
|
+
*
|
|
533
|
+
* ```js
|
|
534
|
+
* const run = await Actor.resurrect(runId);
|
|
535
|
+
* ```
|
|
536
|
+
* @ignore
|
|
537
|
+
*/
|
|
538
|
+
resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
|
|
481
539
|
/**
|
|
482
540
|
* Runs an actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
483
541
|
*
|
|
@@ -505,6 +563,43 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
505
563
|
* @ignore
|
|
506
564
|
*/
|
|
507
565
|
callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
|
|
566
|
+
/**
|
|
567
|
+
* Clients for the child runs started with the `runName` option, keyed by that name, including the runs started
|
|
568
|
+
* before a migration or resurrection of this run. Each client points to the current run under its name.
|
|
569
|
+
*
|
|
570
|
+
* ```js
|
|
571
|
+
* await Actor.childRuns['my-child'].waitForFinish();
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* A run started with a custom `token` uses that token, except for a run started before a migration or
|
|
575
|
+
* resurrection, which uses the default client. The tracked runs, including the earlier runs replaced
|
|
576
|
+
* under the same name, are stored in the default key-value store under the `__ACTOR_CHILD_RUNS` key.
|
|
577
|
+
*/
|
|
578
|
+
get childRuns(): Record<string, RunClient>;
|
|
579
|
+
/**
|
|
580
|
+
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
581
|
+
* unlike `Actor.callTask`, this method just starts the run without waiting for finish.
|
|
582
|
+
*
|
|
583
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
584
|
+
*
|
|
585
|
+
* For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
|
|
586
|
+
*
|
|
587
|
+
* **Example usage:**
|
|
588
|
+
*
|
|
589
|
+
* ```js
|
|
590
|
+
* const run = await Actor.startTask('bob/some-task');
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* @param taskId
|
|
594
|
+
* Allowed formats are `username/task-name`, `userId/task-name` or task ID.
|
|
595
|
+
* @param [input]
|
|
596
|
+
* Input overrides for the Actor task. If it is an object, it will be stringified to
|
|
597
|
+
* JSON and its content type set to `application/json; charset=utf-8`.
|
|
598
|
+
* Provided input will be merged with Actor task input.
|
|
599
|
+
* @param [options]
|
|
600
|
+
* @ignore
|
|
601
|
+
*/
|
|
602
|
+
startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
|
|
508
603
|
/**
|
|
509
604
|
* Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
|
|
510
605
|
* the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
|
|
@@ -513,13 +608,12 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
513
608
|
* @param targetActorId
|
|
514
609
|
* Either `username/actor-name` or Actor ID of an Actor to which we want to metamorph.
|
|
515
610
|
* @param [input]
|
|
516
|
-
* Input for the Actor.
|
|
517
|
-
*
|
|
518
|
-
* Otherwise, the `options.contentType` parameter must be provided.
|
|
611
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
612
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
519
613
|
* @param [options]
|
|
520
614
|
* @ignore
|
|
521
615
|
*/
|
|
522
|
-
metamorph(targetActorId: string, input?:
|
|
616
|
+
metamorph(targetActorId: string, input?: ActorInput, options?: MetamorphOptions): Promise<void>;
|
|
523
617
|
/**
|
|
524
618
|
* Internally reboots this Actor. The system stops the current container and starts
|
|
525
619
|
* a new container with the same run ID.
|
|
@@ -540,15 +634,16 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
540
634
|
* For more information, see the [Get webhook](https://apify.com/docs/api/v2#/reference/webhooks/webhook-object/get-webhook) API endpoint.
|
|
541
635
|
* @ignore
|
|
542
636
|
*/
|
|
543
|
-
addWebhook(options: WebhookOptions): Promise<
|
|
637
|
+
addWebhook(options: WebhookOptions): Promise<WebhookResource | undefined>;
|
|
544
638
|
/**
|
|
545
639
|
* Sets the status message for the current Actor run.
|
|
546
640
|
*
|
|
547
|
-
* @returns The
|
|
641
|
+
* @returns The updated Run object, or `undefined` when no run was updated: when run locally,
|
|
642
|
+
* or when the update failed or timed out (a warning is logged in that case).
|
|
548
643
|
* For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
|
|
549
644
|
* @ignore
|
|
550
645
|
*/
|
|
551
|
-
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
646
|
+
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
|
|
552
647
|
/**
|
|
553
648
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
554
649
|
*
|
|
@@ -569,6 +664,9 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
569
664
|
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
570
665
|
* otherwise the Actor process might finish before the data are stored!
|
|
571
666
|
*
|
|
667
|
+
* Inside a crawlee storage transaction, the items are stored - and charged for - at commit time,
|
|
668
|
+
* so the returned counts are zero and charging for an explicit `eventName` is rejected outright.
|
|
669
|
+
*
|
|
572
670
|
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
573
671
|
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
574
672
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
@@ -587,8 +685,8 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
587
685
|
* @param [datasetIdOrName]
|
|
588
686
|
* ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
|
|
589
687
|
* the function returns the default dataset associated with the Actor run.
|
|
590
|
-
* You can also pass `{ alias: '
|
|
591
|
-
*
|
|
688
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
689
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
592
690
|
* @param [options]
|
|
593
691
|
* @ignore
|
|
594
692
|
*/
|
|
@@ -622,6 +720,35 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
622
720
|
* @ignore
|
|
623
721
|
*/
|
|
624
722
|
getValue<T = unknown>(key: string): Promise<T | null>;
|
|
723
|
+
/**
|
|
724
|
+
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
725
|
+
*
|
|
726
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getValue}.
|
|
727
|
+
* For example, calling the following code:
|
|
728
|
+
* ```js
|
|
729
|
+
* const value = await Actor.getValue('my-key');
|
|
730
|
+
* ```
|
|
731
|
+
*
|
|
732
|
+
* is equivalent to:
|
|
733
|
+
* ```js
|
|
734
|
+
* const store = await Actor.openKeyValueStore();
|
|
735
|
+
* const value = await store.getValue('my-key');
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
|
|
739
|
+
*
|
|
740
|
+
* For more information, see {@link Actor.openKeyValueStore}
|
|
741
|
+
* and {@link KeyValueStore.getValue}.
|
|
742
|
+
*
|
|
743
|
+
* @param key Unique record key.
|
|
744
|
+
* @param defaultValue Fallback that will be returned if no value if present in the storage.
|
|
745
|
+
* @returns
|
|
746
|
+
* Returns a promise that resolves to an object, string
|
|
747
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
748
|
+
* on the MIME content type of the record, or the provided default value.
|
|
749
|
+
* @ignore
|
|
750
|
+
*/
|
|
751
|
+
getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
625
752
|
/**
|
|
626
753
|
* Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
|
|
627
754
|
*
|
|
@@ -657,17 +784,21 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
657
784
|
/**
|
|
658
785
|
* Gets the Actor input value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
659
786
|
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
* const input = await Actor.getInput();
|
|
664
|
-
* ```
|
|
787
|
+
* The input is the record stored under the configured input key (`ACTOR_INPUT_KEY`, default `INPUT`).
|
|
788
|
+
* A record stored as `application/octet-stream` — which is what a local input file without an
|
|
789
|
+
* extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
|
|
665
790
|
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
791
|
+
* When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
|
|
792
|
+
* working directory. A storage backend that doesn't read the default key-value store's directory under
|
|
793
|
+
* the storage directory (e.g. in-memory storage) also gets the file `apify run` writes there.
|
|
794
|
+
*
|
|
795
|
+
* Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
|
|
796
|
+
* replaced with the links of their CSV exports.
|
|
797
|
+
*
|
|
798
|
+
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
|
|
799
|
+
* found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
|
|
800
|
+
* (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
|
|
801
|
+
* Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest.
|
|
671
802
|
*
|
|
672
803
|
* Note that the `getInput()` function does not cache the value read from the key-value store.
|
|
673
804
|
* If you need to use the input multiple times in your Actor,
|
|
@@ -679,16 +810,20 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
679
810
|
* @returns
|
|
680
811
|
* Returns a promise that resolves to an object, string
|
|
681
812
|
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
682
|
-
* on the MIME content type of the record
|
|
683
|
-
*
|
|
813
|
+
* on the MIME content type of the record.
|
|
814
|
+
* @throws {ActorInputError} When the input cannot be produced; see `code`.
|
|
684
815
|
* @ignore
|
|
685
816
|
*/
|
|
686
|
-
getInput<T = Dictionary | string | Buffer>(): Promise<T
|
|
817
|
+
getInput<T = Dictionary | string | Buffer>(): Promise<T>;
|
|
687
818
|
/**
|
|
688
|
-
*
|
|
689
|
-
*
|
|
819
|
+
* Reads the input from a `<inputKey>` or `<inputKey>.json` file in the given directory, for local runs
|
|
820
|
+
* whose default key-value store holds no input record. Mirrors how `ApifyFileSystemStorageBackend` adopts
|
|
821
|
+
* such files inside the store directory: the `.json` file is JSON, the bare one is bytes that
|
|
822
|
+
* {@link parseInputValue} tries as JSON5. Both files present is an error rather than a guess.
|
|
823
|
+
*
|
|
824
|
+
* @returns `undefined` when running on the platform or when neither file exists.
|
|
690
825
|
*/
|
|
691
|
-
|
|
826
|
+
private readInputFromDirectory;
|
|
692
827
|
/**
|
|
693
828
|
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
694
829
|
*
|
|
@@ -699,13 +834,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
699
834
|
* For more details and code examples, see the {@link KeyValueStore} class.
|
|
700
835
|
*
|
|
701
836
|
* @param [storeIdOrName]
|
|
702
|
-
* ID or
|
|
837
|
+
* ID, name, or alias of the key-value store to be opened. If `null` or `undefined`,
|
|
703
838
|
* the function returns the default key-value store associated with the Actor run.
|
|
704
|
-
* You can also pass `{
|
|
839
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
840
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
705
841
|
* @param [options]
|
|
706
842
|
* @ignore
|
|
707
843
|
*/
|
|
708
|
-
openKeyValueStore(storeIdOrName?:
|
|
844
|
+
openKeyValueStore(storeIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
|
|
709
845
|
/**
|
|
710
846
|
* Opens a request queue and returns a promise resolving to an instance
|
|
711
847
|
* of the {@link RequestQueue} class.
|
|
@@ -718,13 +854,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
718
854
|
* For more details and code examples, see the {@link RequestQueue} class.
|
|
719
855
|
*
|
|
720
856
|
* @param [queueIdOrName]
|
|
721
|
-
* ID or
|
|
857
|
+
* ID, name, or alias of the request queue to be opened. If `null` or `undefined`,
|
|
722
858
|
* the function returns the default request queue associated with the Actor run.
|
|
723
|
-
* You can also pass `{
|
|
859
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
860
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
724
861
|
* @param [options]
|
|
725
862
|
* @ignore
|
|
726
863
|
*/
|
|
727
|
-
openRequestQueue(queueIdOrName?:
|
|
864
|
+
openRequestQueue(queueIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<RequestQueue>;
|
|
728
865
|
/**
|
|
729
866
|
* Creates a proxy configuration and returns a promise resolving to an instance
|
|
730
867
|
* of the {@link ProxyConfiguration} class that is already initialized.
|
|
@@ -873,24 +1010,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
873
1010
|
*
|
|
874
1011
|
* If the user function returns a promise, it is considered asynchronous:
|
|
875
1012
|
* ```js
|
|
876
|
-
* import { gotScraping } from 'got-scraping';
|
|
877
|
-
*
|
|
878
1013
|
* await Actor.main(() => {
|
|
879
1014
|
* // My asynchronous function that returns a promise
|
|
880
|
-
* return
|
|
881
|
-
*
|
|
882
|
-
*
|
|
1015
|
+
* return fetch('http://www.example.com')
|
|
1016
|
+
* .then((response) => response.text())
|
|
1017
|
+
* .then((html) => {
|
|
1018
|
+
* console.log(html);
|
|
1019
|
+
* });
|
|
883
1020
|
* });
|
|
884
1021
|
* ```
|
|
885
1022
|
*
|
|
886
1023
|
* To simplify your code, you can take advantage of the `async`/`await` keywords:
|
|
887
1024
|
*
|
|
888
1025
|
* ```js
|
|
889
|
-
* import { gotScraping } from 'got-scraping';
|
|
890
|
-
*
|
|
891
1026
|
* await Actor.main(async () => {
|
|
892
1027
|
* // My asynchronous function
|
|
893
|
-
* const html = await
|
|
1028
|
+
* const html = await fetch('http://www.example.com').then((response) => response.text());
|
|
894
1029
|
* console.log(html);
|
|
895
1030
|
* });
|
|
896
1031
|
* ```
|
|
@@ -916,11 +1051,9 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
916
1051
|
* behavior by setting `options.gracefulShutdown` to `false`.
|
|
917
1052
|
*
|
|
918
1053
|
* ```js
|
|
919
|
-
* import { gotScraping } from 'got-scraping';
|
|
920
|
-
*
|
|
921
1054
|
* await Actor.init();
|
|
922
1055
|
*
|
|
923
|
-
* const html = await
|
|
1056
|
+
* const html = await fetch('http://www.example.com').then((response) => response.text());
|
|
924
1057
|
* console.log(html);
|
|
925
1058
|
*
|
|
926
1059
|
* await Actor.exit();
|
|
@@ -961,12 +1094,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
961
1094
|
* @param actorId
|
|
962
1095
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
963
1096
|
* @param [input]
|
|
964
|
-
* Input for the Actor.
|
|
965
|
-
*
|
|
966
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
1097
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
1098
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
967
1099
|
* @param [options]
|
|
968
1100
|
*/
|
|
969
|
-
static call(actorId: string, input?:
|
|
1101
|
+
static call(actorId: string, input?: ActorInput, options?: CallOptions): Promise<ClientActorRun>;
|
|
970
1102
|
/**
|
|
971
1103
|
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
972
1104
|
*
|
|
@@ -993,6 +1125,29 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
993
1125
|
* @param [options]
|
|
994
1126
|
*/
|
|
995
1127
|
static callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ClientActorRun>;
|
|
1128
|
+
/**
|
|
1129
|
+
* Runs an Actor task on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
1130
|
+
* unlike `Actor.callTask`, this method just starts the run without waiting for finish.
|
|
1131
|
+
*
|
|
1132
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
1133
|
+
*
|
|
1134
|
+
* For more information about Actor tasks, read the [documentation](https://docs.apify.com/tasks).
|
|
1135
|
+
*
|
|
1136
|
+
* **Example usage:**
|
|
1137
|
+
*
|
|
1138
|
+
* ```js
|
|
1139
|
+
* const run = await Actor.startTask('bob/some-task');
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* @param taskId
|
|
1143
|
+
* Allowed formats are `username/task-name`, `userId/task-name` or task ID.
|
|
1144
|
+
* @param [input]
|
|
1145
|
+
* Input overrides for the Actor task. If it is an object, it will be stringified to
|
|
1146
|
+
* JSON and its content type set to `application/json; charset=utf-8`.
|
|
1147
|
+
* Provided input will be merged with Actor task input.
|
|
1148
|
+
* @param [options]
|
|
1149
|
+
*/
|
|
1150
|
+
static startTask(taskId: string, input?: Dictionary, options?: StartTaskOptions): Promise<ClientActorRun>;
|
|
996
1151
|
/**
|
|
997
1152
|
* Runs an Actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
|
|
998
1153
|
* unlike `Actor.call`, this method just starts the run without waiting for finish.
|
|
@@ -1011,12 +1166,24 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1011
1166
|
* @param actorId
|
|
1012
1167
|
* Allowed formats are `username/actor-name`, `userId/actor-name` or Actor ID.
|
|
1013
1168
|
* @param [input]
|
|
1014
|
-
* Input for the Actor.
|
|
1015
|
-
*
|
|
1016
|
-
* Otherwise the `options.contentType` parameter must be provided.
|
|
1169
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
1170
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
1017
1171
|
* @param [options]
|
|
1018
1172
|
*/
|
|
1019
1173
|
static start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ClientActorRun>;
|
|
1174
|
+
/**
|
|
1175
|
+
* Clients for the child runs started with the `runName` option, keyed by that name, including the runs started
|
|
1176
|
+
* before a migration or resurrection of this run. Each client points to the current run under its name.
|
|
1177
|
+
*
|
|
1178
|
+
* ```js
|
|
1179
|
+
* await Actor.childRuns['my-child'].waitForFinish();
|
|
1180
|
+
* ```
|
|
1181
|
+
*
|
|
1182
|
+
* A run started with a custom `token` uses that token, except for a run started before a migration or
|
|
1183
|
+
* resurrection, which uses the default client. The tracked runs, including the earlier runs replaced
|
|
1184
|
+
* under the same name, are stored in the default key-value store under the `__ACTOR_CHILD_RUNS` key.
|
|
1185
|
+
*/
|
|
1186
|
+
static get childRuns(): Record<string, RunClient>;
|
|
1020
1187
|
/**
|
|
1021
1188
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
1022
1189
|
*
|
|
@@ -1032,6 +1199,24 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1032
1199
|
* ```
|
|
1033
1200
|
*/
|
|
1034
1201
|
static abort(runId: string, options?: AbortOptions): Promise<ClientActorRun>;
|
|
1202
|
+
/**
|
|
1203
|
+
* Resurrects a finished Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
1204
|
+
*
|
|
1205
|
+
* Only finished runs (SUCCEEDED, FAILED, ABORTED or TIMED-OUT) can be resurrected. The run goes back to the RUNNING
|
|
1206
|
+
* status and keeps its default storages. Options you leave out keep the values of the original run.
|
|
1207
|
+
*
|
|
1208
|
+
* The result of the function is an {@link ActorRun} object that contains details about the Actor run.
|
|
1209
|
+
*
|
|
1210
|
+
* For more information about Actors, read the
|
|
1211
|
+
* [documentation](https://docs.apify.com/actor).
|
|
1212
|
+
*
|
|
1213
|
+
* **Example usage:**
|
|
1214
|
+
*
|
|
1215
|
+
* ```js
|
|
1216
|
+
* const run = await Actor.resurrect(runId);
|
|
1217
|
+
* ```
|
|
1218
|
+
*/
|
|
1219
|
+
static resurrect(runId: string, options?: ResurrectOptions): Promise<ClientActorRun>;
|
|
1035
1220
|
/**
|
|
1036
1221
|
* Transforms this Actor run to an Actor run of a given Actor. The system stops the current container and starts
|
|
1037
1222
|
* the new container instead. All the default storages are preserved and the new input is stored under the `INPUT-METAMORPH-1` key
|
|
@@ -1040,12 +1225,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1040
1225
|
* @param targetActorId
|
|
1041
1226
|
* Either `username/actor-name` or Actor ID of an Actor to which we want to metamorph.
|
|
1042
1227
|
* @param [input]
|
|
1043
|
-
* Input for the Actor.
|
|
1044
|
-
*
|
|
1045
|
-
* Otherwise, the `options.contentType` parameter must be provided.
|
|
1228
|
+
* Input for the Actor. A plain object is stringified to JSON with content type
|
|
1229
|
+
* `application/json; charset=utf-8`. A `Buffer` is sent as-is and needs `options.contentType`.
|
|
1046
1230
|
* @param [options]
|
|
1047
1231
|
*/
|
|
1048
|
-
static metamorph(targetActorId: string, input?:
|
|
1232
|
+
static metamorph(targetActorId: string, input?: ActorInput, options?: MetamorphOptions): Promise<void>;
|
|
1049
1233
|
/**
|
|
1050
1234
|
* Internally reboots this Actor run. The system stops the current container and starts
|
|
1051
1235
|
* a new container with the same run id.
|
|
@@ -1063,7 +1247,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1063
1247
|
* @returns The return value is the Webhook object.
|
|
1064
1248
|
* For more information, see the [Get webhook](https://apify.com/docs/api/v2#/reference/webhooks/webhook-object/get-webhook) API endpoint.
|
|
1065
1249
|
*/
|
|
1066
|
-
static addWebhook(options: WebhookOptions): Promise<
|
|
1250
|
+
static addWebhook(options: WebhookOptions): Promise<WebhookResource | undefined>;
|
|
1067
1251
|
/**
|
|
1068
1252
|
* Sets the status message for the current Actor run.
|
|
1069
1253
|
*
|
|
@@ -1071,10 +1255,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1071
1255
|
* @param [options]
|
|
1072
1256
|
* @param [options.isStatusMessageTerminal] If `true`, the status message will be marked as terminal.
|
|
1073
1257
|
* This is required for the last status message of the run. Default value is `false`.
|
|
1074
|
-
* @returns The
|
|
1258
|
+
* @returns The updated Run object, or `undefined` when no run was updated: when run locally,
|
|
1259
|
+
* or when the update failed or timed out (a warning is logged in that case).
|
|
1075
1260
|
* For more information, see the [Actor Runs](https://docs.apify.com/api/v2#/reference/actor-runs/) API endpoints.
|
|
1076
1261
|
*/
|
|
1077
|
-
static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
1262
|
+
static setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun | undefined>;
|
|
1078
1263
|
/**
|
|
1079
1264
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
1080
1265
|
*
|
|
@@ -1119,6 +1304,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1119
1304
|
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
1120
1305
|
* otherwise the Actor process might finish before the data are stored!
|
|
1121
1306
|
*
|
|
1307
|
+
* Charging is rejected inside a crawlee storage transaction, where the items would only be stored
|
|
1308
|
+
* at commit while the charge happens immediately - use `withDirectStorageAccess()` to opt out of
|
|
1309
|
+
* the transaction, or push without an event name and charge separately.
|
|
1310
|
+
*
|
|
1122
1311
|
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
1123
1312
|
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
1124
1313
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
@@ -1136,8 +1325,8 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1136
1325
|
* @param [datasetIdOrName]
|
|
1137
1326
|
* ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
|
|
1138
1327
|
* the function returns the default dataset associated with the Actor run.
|
|
1139
|
-
* You can also pass `{ alias: '
|
|
1140
|
-
*
|
|
1328
|
+
* You can also pass `{ alias: 'abc' }` to open a run-scoped storage, `{ id: 'abc' }` to open by
|
|
1329
|
+
* explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1141
1330
|
* @param [options]
|
|
1142
1331
|
*/
|
|
1143
1332
|
static openDataset<Data extends Dictionary = Dictionary>(datasetIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<Dataset<Data>>;
|
|
@@ -1169,6 +1358,34 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1169
1358
|
* if the record is missing.
|
|
1170
1359
|
*/
|
|
1171
1360
|
static getValue<T = unknown>(key: string): Promise<T | null>;
|
|
1361
|
+
/**
|
|
1362
|
+
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1363
|
+
*
|
|
1364
|
+
* This is just a convenient shortcut for {@link KeyValueStore.getValue}.
|
|
1365
|
+
* For example, calling the following code:
|
|
1366
|
+
* ```js
|
|
1367
|
+
* const value = await Actor.getValue('my-key');
|
|
1368
|
+
* ```
|
|
1369
|
+
*
|
|
1370
|
+
* is equivalent to:
|
|
1371
|
+
* ```js
|
|
1372
|
+
* const store = await Actor.openKeyValueStore();
|
|
1373
|
+
* const value = await store.getValue('my-key');
|
|
1374
|
+
* ```
|
|
1375
|
+
*
|
|
1376
|
+
* To store the value to the default key-value store, you can use the {@link Actor.setValue} function.
|
|
1377
|
+
*
|
|
1378
|
+
* For more information, see {@link Actor.openKeyValueStore}
|
|
1379
|
+
* and {@link KeyValueStore.getValue}.
|
|
1380
|
+
*
|
|
1381
|
+
* @param key Unique record key.
|
|
1382
|
+
* @param defaultValue Fallback that will be returned if no value if present in the storage.
|
|
1383
|
+
* @returns
|
|
1384
|
+
* Returns a promise that resolves to an object, string
|
|
1385
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
1386
|
+
* on the MIME content type of the record, or the provided default value.
|
|
1387
|
+
*/
|
|
1388
|
+
static getValue<T = unknown>(key: string, defaultValue: T): Promise<T>;
|
|
1172
1389
|
/**
|
|
1173
1390
|
* Stores or deletes a value in the default {@link KeyValueStore} associated with the current Actor run.
|
|
1174
1391
|
*
|
|
@@ -1203,16 +1420,31 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1203
1420
|
/**
|
|
1204
1421
|
* Gets the Actor input value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1205
1422
|
*
|
|
1206
|
-
*
|
|
1207
|
-
* For example, calling the following code:
|
|
1423
|
+
* The input is the record stored under the configured input key (`ACTOR_INPUT_KEY`, default `INPUT`):
|
|
1208
1424
|
* ```js
|
|
1209
1425
|
* const input = await Actor.getInput();
|
|
1210
1426
|
* ```
|
|
1211
1427
|
*
|
|
1212
|
-
* is
|
|
1428
|
+
* A record stored as `application/octet-stream` — which is what a local input file without an
|
|
1429
|
+
* extension is read as — is parsed with JSON5 when it parses, and returned as a `Buffer` otherwise.
|
|
1430
|
+
*
|
|
1431
|
+
* When running locally, the input may instead be a `<inputKey>` or `<inputKey>.json` file in the current
|
|
1432
|
+
* working directory.
|
|
1433
|
+
*
|
|
1434
|
+
* Google Sheets sharing links in `requestsFromUrl` entries (from the "Link remote text file" option) are
|
|
1435
|
+
* replaced with the links of their CSV exports.
|
|
1436
|
+
*
|
|
1437
|
+
* Throws an {@link ActorInputError} when no input is found (`code: 'NOT_FOUND'`), when the input is
|
|
1438
|
+
* found in more than one place (`'MULTIPLE_FILES'`), when a JSON input does not parse
|
|
1439
|
+
* (`'PARSE_FAILED'`) or when its secret fields cannot be decrypted (`'DECRYPTION_FAILED'`). If your
|
|
1440
|
+
* Actor can run without input, catch the `'NOT_FOUND'` case and rethrow the rest:
|
|
1213
1441
|
* ```js
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1442
|
+
* let input = {};
|
|
1443
|
+
* try {
|
|
1444
|
+
* input = await Actor.getInput();
|
|
1445
|
+
* } catch (error) {
|
|
1446
|
+
* if (!(error instanceof ActorInputError) || error.code !== 'NOT_FOUND') throw error;
|
|
1447
|
+
* }
|
|
1216
1448
|
* ```
|
|
1217
1449
|
*
|
|
1218
1450
|
* Note that the `getInput()` function does not cache the value read from the key-value store.
|
|
@@ -1224,15 +1456,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1224
1456
|
* @returns
|
|
1225
1457
|
* Returns a promise that resolves to an object, string
|
|
1226
1458
|
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
1227
|
-
* on the MIME content type of the record
|
|
1228
|
-
*
|
|
1459
|
+
* on the MIME content type of the record.
|
|
1460
|
+
* @throws {ActorInputError} When the input cannot be produced; see `code`.
|
|
1229
1461
|
*/
|
|
1230
|
-
static getInput<T = Dictionary | string | Buffer>(): Promise<T
|
|
1231
|
-
/**
|
|
1232
|
-
* Gets the Actor input value just like the {@link Actor.getInput} method,
|
|
1233
|
-
* but throws if it is not found.
|
|
1234
|
-
*/
|
|
1235
|
-
static getInputOrThrow<T = Dictionary | string | Buffer>(): Promise<T>;
|
|
1462
|
+
static getInput<T = Dictionary | string | Buffer>(): Promise<T>;
|
|
1236
1463
|
/**
|
|
1237
1464
|
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
1238
1465
|
*
|
|
@@ -1248,7 +1475,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1248
1475
|
* You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1249
1476
|
* @param [options]
|
|
1250
1477
|
*/
|
|
1251
|
-
static openKeyValueStore(storeIdOrName?:
|
|
1478
|
+
static openKeyValueStore(storeIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
|
|
1252
1479
|
/**
|
|
1253
1480
|
* Opens a request queue and returns a promise resolving to an instance
|
|
1254
1481
|
* of the {@link RequestQueue} class.
|
|
@@ -1266,7 +1493,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1266
1493
|
* You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1267
1494
|
* @param [options]
|
|
1268
1495
|
*/
|
|
1269
|
-
static openRequestQueue(queueIdOrName?:
|
|
1496
|
+
static openRequestQueue(queueIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<RequestQueue>;
|
|
1270
1497
|
/**
|
|
1271
1498
|
* Creates a proxy configuration and returns a promise resolving to an instance
|
|
1272
1499
|
* of the {@link ProxyConfiguration} class that is already initialized.
|
|
@@ -1352,14 +1579,27 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1352
1579
|
/** Default {@link ApifyClient} instance. */
|
|
1353
1580
|
static get apifyClient(): ApifyClient;
|
|
1354
1581
|
/** Default {@link Configuration} instance. */
|
|
1355
|
-
static get
|
|
1582
|
+
static get configuration(): Configuration;
|
|
1356
1583
|
/** @internal */
|
|
1357
1584
|
static getDefaultInstance(): Actor;
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1585
|
+
/**
|
|
1586
|
+
* Replaces or clears the cached default instance returned by {@link Actor.getDefaultInstance}.
|
|
1587
|
+
* @internal
|
|
1588
|
+
*/
|
|
1589
|
+
static setDefaultInstance(instance?: Actor): void;
|
|
1590
|
+
/**
|
|
1591
|
+
* The same choice crawlee's `ServiceLocator` makes for its implicit default backend, with the
|
|
1592
|
+
* input-aware {@link ApifyFileSystemStorageBackend} in place of crawlee's — crawlee has no
|
|
1593
|
+
* notion of a run input.
|
|
1594
|
+
*/
|
|
1595
|
+
private createLocalStorageBackend;
|
|
1596
|
+
/**
|
|
1597
|
+
* crawlee's service locator is set-once, so a backend registered before `init()` wins and the
|
|
1598
|
+
* Actor cannot install its own over it. Replaces the resulting `ServiceConflictError` with the
|
|
1599
|
+
* way out.
|
|
1600
|
+
*/
|
|
1601
|
+
private installStorageBackend;
|
|
1602
|
+
private ensureActorInit;
|
|
1363
1603
|
/**
|
|
1364
1604
|
* Get time remaining from the Actor run timeout in seconds, rounded up to whole seconds with minimum value of 1 second.
|
|
1365
1605
|
*
|