apify 4.0.0-beta.12 → 4.0.0-beta.14
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 +12 -48
- package/dist/actor.d.ts +157 -61
- package/dist/actor.js +278 -91
- package/dist/apify_storage_client.d.ts +54 -0
- package/dist/apify_storage_client.js +152 -0
- package/dist/charging.d.ts +43 -2
- package/dist/charging.js +196 -54
- package/dist/configuration.d.ts +79 -132
- package/dist/configuration.js +114 -141
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/input-schemas.d.ts +7 -0
- package/dist/input-schemas.js +58 -0
- package/dist/key_value_store.d.ts +8 -4
- package/dist/key_value_store.js +19 -11
- package/dist/platform_event_manager.d.ts +0 -1
- package/dist/platform_event_manager.js +5 -5
- package/dist/proxy_configuration.d.ts +41 -44
- package/dist/proxy_configuration.js +65 -103
- package/dist/storage.d.ts +58 -0
- package/dist/storage.js +79 -0
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +2 -4
- package/package.json +123 -73
- package/.turbo/turbo-build.log +0 -26
- package/.turbo/turbo-copy.log +0 -4
- package/dist/LICENSE.md +0 -201
- package/dist/README.md +0 -98
- package/dist/actor.d.ts.map +0 -1
- package/dist/actor.js.map +0 -1
- package/dist/charging.d.ts.map +0 -1
- package/dist/charging.js.map +0 -1
- package/dist/configuration.d.ts.map +0 -1
- package/dist/configuration.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/key_value_store.d.ts.map +0 -1
- package/dist/key_value_store.js.map +0 -1
- package/dist/package.json +0 -75
- package/dist/platform_event_manager.d.ts.map +0 -1
- package/dist/platform_event_manager.js.map +0 -1
- package/dist/proxy_configuration.d.ts.map +0 -1
- package/dist/proxy_configuration.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -5,81 +5,45 @@
|
|
|
5
5
|
[](https://discord.gg/jyEM2PRvMU)
|
|
6
6
|
[](https://github.com/apify/apify-sdk-js/actions/workflows/test-and-release.yaml)
|
|
7
7
|
|
|
8
|
-
Apify SDK provides the tools required to run your own Apify Actors. The crawlers and scraping related tools, previously included in Apify SDK (v2), have been split into a brand-new module - [`crawlee`](https://npmjs.org/crawlee), while keeping the Apify specific parts in this module.
|
|
9
|
-
|
|
10
|
-
> Would you like to work with us on Crawlee, Apify SDK or similar projects? We are hiring [Node.js engineers](https://apify.com/jobs#senior-node.js-engineer).
|
|
11
|
-
|
|
12
|
-
## Upgrading from v2
|
|
13
|
-
|
|
14
|
-
A lot of things have changed since version 2 of the Apify SDK, including the split of the crawlers to the new [`crawlee`](https://npmjs.org/crawlee) module. We've written a guide to help you easily migrate from v2 to v3. Visit the [Upgrading Guide](https://docs.apify.com/sdk/js/docs/upgrading/upgrading-to-v3) to find out what changes you need to make (especially the section related to this very [Apify SDK](https://docs.apify.com/sdk/js/docs/upgrading/upgrading-to-v3#apify-sdk)), and, if you encounter any issues, join our [Discord server](https://discord.gg/jyEM2PRvMU) for help!
|
|
15
|
-
|
|
16
8
|
## Quick Start
|
|
17
9
|
|
|
18
10
|
This short tutorial will set you up to start using Apify SDK in a minute or two.
|
|
19
|
-
If you want to learn more, proceed to the [Apify Platform](https://docs.apify.com/sdk/js/docs/
|
|
11
|
+
If you want to learn more, proceed to the [Apify Platform](https://docs.apify.com/sdk/js/docs/concepts/actor-lifecycle)
|
|
20
12
|
guide that will take you step by step through running your Actor on Apify's platform.
|
|
21
13
|
|
|
22
14
|
Apify SDK requires [Node.js](https://nodejs.org/en/) 16 or later. Add Apify SDK to any Node.js project by running:
|
|
23
15
|
|
|
24
16
|
```bash
|
|
25
|
-
npm install apify
|
|
17
|
+
npm install apify
|
|
26
18
|
```
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
There are two ways to initialize your Actor: by using the `Actor.main()` function you're probably used to, or by calling `Actor.init()` and `Actor.exit()` manually. We prefer explicitly calling `init` and `exit`.
|
|
31
|
-
|
|
32
|
-
### Using `Actor.init()` and `Actor.exit()`
|
|
20
|
+
To initialize your Actor and to stop it use the `Actor.init()` and `Actor.exit()` functions. You also may use `Actor.main()` function for cases with multiple crawlers in one context.
|
|
33
21
|
|
|
34
22
|
```typescript
|
|
35
23
|
import { Actor } from 'apify';
|
|
36
|
-
import { PlaywrightCrawler } from 'crawlee';
|
|
37
24
|
|
|
38
25
|
await Actor.init();
|
|
39
26
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(`Title of ${request.url}: ${title}`);
|
|
45
|
-
|
|
46
|
-
// Add URLs that point to the same hostname.
|
|
47
|
-
await enqueueLinks();
|
|
48
|
-
},
|
|
27
|
+
const input = (await Actor.getInput()) ?? {};
|
|
28
|
+
await Actor.setValue('OUTPUT', {
|
|
29
|
+
message: 'Hello from Apify SDK!',
|
|
30
|
+
input,
|
|
49
31
|
});
|
|
50
32
|
|
|
51
|
-
await crawler.run(['https://crawlee.dev/']);
|
|
52
|
-
|
|
53
33
|
await Actor.exit();
|
|
54
34
|
```
|
|
55
35
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { Actor } from 'apify';
|
|
60
|
-
import { PlaywrightCrawler } from 'crawlee';
|
|
61
|
-
|
|
62
|
-
await Actor.main(async () => {
|
|
63
|
-
const crawler = new PlaywrightCrawler({
|
|
64
|
-
async requestHandler({ request, page, enqueueLinks }) {
|
|
65
|
-
// Extract HTML title of the page.
|
|
66
|
-
const title = await page.title();
|
|
67
|
-
console.log(`Title of ${request.url}: ${title}`);
|
|
68
|
-
|
|
69
|
-
// Add URLs that point to the same hostname.
|
|
70
|
-
await enqueueLinks();
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
await crawler.run(['https://crawlee.dev/']);
|
|
75
|
-
});
|
|
76
|
-
```
|
|
36
|
+
> You can also install the [`crawlee`](https://npmjs.org/crawlee) module, as it now provides the crawlers that were previously exported by Apify SDK. If you don't plan to use crawlers in your Actors, then you don't need to install it. Keep in mind that neither `playwright` nor `puppeteer` are bundled with `crawlee` in order to reduce install size and allow greater flexibility. That's why we manually install it with NPM. You can choose one, both, or neither. For more information and example please check [`documentation.`](https://docs.apify.com/sdk/js/docs/concepts/actor-lifecycle#running-crawlee-code-as-an-actor)
|
|
77
37
|
|
|
78
38
|
## Support
|
|
79
39
|
|
|
80
40
|
If you find any bug or issue with the Apify SDK, please [submit an issue on GitHub](https://github.com/apify/apify-sdk-js/issues).
|
|
81
41
|
For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or contact support@apify.com
|
|
82
42
|
|
|
43
|
+
## Upgrading
|
|
44
|
+
|
|
45
|
+
Visit the [Upgrading Guide](https://docs.apify.com/sdk/js/docs/upgrading/upgrading-to-v3) to find out what changes you might want to make, and, if you encounter any issues, join our [Discord server](https://discord.gg/jyEM2PRvMU) for help!
|
|
46
|
+
|
|
83
47
|
## Contributing
|
|
84
48
|
|
|
85
49
|
Your code contributions are welcome, and you'll be praised to eternity!
|
package/dist/actor.d.ts
CHANGED
|
@@ -1,17 +1,46 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EventManager, EventTypeName, RecordOptions, UseStateOptions } from '@crawlee/core';
|
|
2
2
|
import { Dataset, RequestQueue } from '@crawlee/core';
|
|
3
3
|
import type { Awaitable, Dictionary, SetStatusMessageOptions, StorageClient } from '@crawlee/types';
|
|
4
|
-
import type { ActorCallOptions, ApifyClientOptions, RunAbortOptions, TaskCallOptions, Webhook, WebhookEventType } from 'apify-client';
|
|
4
|
+
import type { ActorCallOptions, ActorStartOptions, ApifyClientOptions, RunAbortOptions, TaskCallOptions, Webhook, WebhookEventType } from 'apify-client';
|
|
5
5
|
import { ActorRun as ClientActorRun, ApifyClient } from 'apify-client';
|
|
6
|
+
import { type ACTOR_PERMISSION_LEVEL } from '@apify/consts';
|
|
6
7
|
import type { ChargeOptions, ChargeResult } from './charging.js';
|
|
7
8
|
import { ChargingManager } from './charging.js';
|
|
9
|
+
import type { ConfigurationOptions } from './configuration.js';
|
|
8
10
|
import { Configuration } from './configuration.js';
|
|
9
11
|
import { KeyValueStore } from './key_value_store.js';
|
|
10
12
|
import type { ProxyConfigurationOptions } from './proxy_configuration.js';
|
|
11
13
|
import { ProxyConfiguration } from './proxy_configuration.js';
|
|
14
|
+
import type { OpenStorageOptions, StorageIdentifier, StorageIdentifierWithoutAlias } from './storage.js';
|
|
12
15
|
export interface InitOptions {
|
|
13
16
|
storage?: StorageClient;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to automatically handle platform shutdown signals.
|
|
19
|
+
* When enabled, `Actor.exit()` is called on `aborting` events and `Actor.reboot()` on `migrating` events.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
gracefulShutdown?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Delay in milliseconds before calling `Actor.exit()`/`Actor.reboot()` on `aborting`/`migrating` events.
|
|
25
|
+
* Since both methods already wait for all event handlers to complete, this delay is usually unnecessary.
|
|
26
|
+
* @default 0
|
|
27
|
+
*/
|
|
28
|
+
gracefulShutdownDelayMillis?: number;
|
|
14
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Options accepted by the {@link Actor} constructor. Either pass field-level
|
|
32
|
+
* overrides (`token`, `inputKey`, …) — which the Actor turns into a fresh
|
|
33
|
+
* {@link Configuration} — or pass a pre-built `configuration` instance. When
|
|
34
|
+
* both are present, `configuration` wins and the field-level overrides are
|
|
35
|
+
* ignored.
|
|
36
|
+
*/
|
|
37
|
+
export type ActorOptions = ConfigurationOptions & {
|
|
38
|
+
/**
|
|
39
|
+
* Pre-built {@link Configuration} instance the Actor should use. Takes
|
|
40
|
+
* precedence over any field-level overrides also passed in `options`.
|
|
41
|
+
*/
|
|
42
|
+
configuration?: Configuration;
|
|
43
|
+
};
|
|
15
44
|
export interface ExitOptions {
|
|
16
45
|
/** Exit with given status message */
|
|
17
46
|
statusMessage?: string;
|
|
@@ -48,11 +77,19 @@ export interface ApifyEnv {
|
|
|
48
77
|
* ID of the Actor build used in the run. (ACTOR_BUILD_ID)
|
|
49
78
|
*/
|
|
50
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;
|
|
51
84
|
/**
|
|
52
85
|
* ID of the user who started the Actor - note that it might be
|
|
53
86
|
* different than the owner of the Actor (APIFY_USER_ID)
|
|
54
87
|
*/
|
|
55
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;
|
|
56
93
|
/**
|
|
57
94
|
* Authentication token representing privileges given to the Actor run,
|
|
58
95
|
* it can be passed to various Apify APIs (APIFY_TOKEN)
|
|
@@ -113,7 +150,7 @@ export interface ApifyEnv {
|
|
|
113
150
|
* Defines the path to a local directory where KeyValueStore, Dataset, and RequestQueue
|
|
114
151
|
* store their data. Typically, it is set to ./storage. If omitted, you should define the
|
|
115
152
|
* APIFY_TOKEN environment variable instead. See more info on combination of this and
|
|
116
|
-
* APIFY_TOKEN [here](https://docs.apify.com/sdk/js/docs/
|
|
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)
|
|
117
154
|
*/
|
|
118
155
|
localStorageDir: string | null;
|
|
119
156
|
/**
|
|
@@ -142,23 +179,28 @@ export interface ApifyEnv {
|
|
|
142
179
|
defaultRequestQueueId: string | null;
|
|
143
180
|
}
|
|
144
181
|
export type UserFunc<T = unknown> = () => Awaitable<T>;
|
|
145
|
-
export interface
|
|
182
|
+
export interface Token {
|
|
146
183
|
/**
|
|
147
|
-
* User API token that is used
|
|
184
|
+
* User Apify API token that is used for API calls. By default, it is taken from the `APIFY_TOKEN` environment variable.
|
|
148
185
|
*/
|
|
149
186
|
token?: string;
|
|
150
187
|
}
|
|
151
|
-
export interface
|
|
188
|
+
export interface Timeout {
|
|
152
189
|
/**
|
|
153
|
-
*
|
|
190
|
+
* Timeout for the Actor run in seconds, or `'inherit'`.
|
|
191
|
+
*
|
|
192
|
+
* Using `inherit` will set timeout of the newly started Actor run to the time
|
|
193
|
+
* remaining until this Actor run times out so that the new run does not outlive this one.
|
|
154
194
|
*/
|
|
155
|
-
|
|
195
|
+
timeout?: number | 'inherit';
|
|
156
196
|
}
|
|
157
|
-
export interface
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
197
|
+
export interface CallOptions extends Omit<ActorCallOptions, 'timeout'>, Token, Timeout {
|
|
198
|
+
}
|
|
199
|
+
export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'timeout'>, Token, Timeout {
|
|
200
|
+
}
|
|
201
|
+
export interface CallTaskOptions extends Omit<TaskCallOptions, 'timeout'>, Token, Timeout {
|
|
202
|
+
}
|
|
203
|
+
export interface AbortOptions extends RunAbortOptions, Token {
|
|
162
204
|
/** Exit with given status message */
|
|
163
205
|
statusMessage?: string;
|
|
164
206
|
}
|
|
@@ -188,6 +230,35 @@ export interface WebhookOptions {
|
|
|
188
230
|
* {@link Actor.getEnv} function.
|
|
189
231
|
*/
|
|
190
232
|
idempotencyKey?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Headers template is a JSON-like string that describes the HTTP headers to be sent with the webhook POST request.
|
|
235
|
+
* It uses JSON syntax, extended with a double curly braces syntax for injecting variables `{{variable}}`.
|
|
236
|
+
* Those variables are resolved at the time of the webhook's dispatch, and a list of available variables with their descriptions
|
|
237
|
+
* is available in the [Apify webhook documentation](https://docs.apify.com/webhooks).
|
|
238
|
+
* If `headersTemplate` is omitted, no extra headers are added
|
|
239
|
+
* ([view docs](https://docs.apify.com/platform/integrations/webhooks/actions#headers-template)).
|
|
240
|
+
*/
|
|
241
|
+
headersTemplate?: string;
|
|
242
|
+
/**
|
|
243
|
+
* A description of the webhook.
|
|
244
|
+
*/
|
|
245
|
+
description?: string;
|
|
246
|
+
/**
|
|
247
|
+
* If true, the webhook will ignore SSL errors when sending the request.
|
|
248
|
+
*/
|
|
249
|
+
ignoreSslErrors?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* If true, the webhook will not retry on failure.
|
|
252
|
+
*/
|
|
253
|
+
doNotRetry?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* If true, the webhook will interpolate strings in the payloadTemplate and headersTemplate.
|
|
256
|
+
*/
|
|
257
|
+
shouldInterpolateStrings?: boolean;
|
|
258
|
+
/**
|
|
259
|
+
* If true, indicates the webhook is an Apify integration.
|
|
260
|
+
*/
|
|
261
|
+
isApifyIntegration?: boolean;
|
|
191
262
|
}
|
|
192
263
|
export interface MetamorphOptions {
|
|
193
264
|
/**
|
|
@@ -209,14 +280,6 @@ export interface RebootOptions {
|
|
|
209
280
|
/** @internal */
|
|
210
281
|
customAfterSleepMillis?: number;
|
|
211
282
|
}
|
|
212
|
-
export interface OpenStorageOptions {
|
|
213
|
-
/**
|
|
214
|
-
* If set to `true` then the cloud storage is used even if the `CRAWLEE_STORAGE_DIR`
|
|
215
|
-
* environment variable is set. This way it is possible to combine local and cloud storage.
|
|
216
|
-
* @default false
|
|
217
|
-
*/
|
|
218
|
-
forceCloud?: boolean;
|
|
219
|
-
}
|
|
220
283
|
export { ClientActorRun as ActorRun };
|
|
221
284
|
/**
|
|
222
285
|
* Exit codes for the Actor process.
|
|
@@ -265,8 +328,22 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
265
328
|
* Set if the Actor is currently rebooting.
|
|
266
329
|
*/
|
|
267
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;
|
|
268
339
|
private chargingManager;
|
|
269
|
-
|
|
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
|
+
constructor(options?: ActorOptions);
|
|
270
347
|
/**
|
|
271
348
|
* Runs the main user function that performs the job of the Actor
|
|
272
349
|
* and terminates the process when the user function finishes.
|
|
@@ -399,7 +476,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
399
476
|
* @param [options]
|
|
400
477
|
* @ignore
|
|
401
478
|
*/
|
|
402
|
-
start(actorId: string, input?: unknown, options?:
|
|
479
|
+
start(actorId: string, input?: unknown, options?: StartOptions): Promise<ClientActorRun>;
|
|
403
480
|
/**
|
|
404
481
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
405
482
|
*
|
|
@@ -487,31 +564,6 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
487
564
|
* @ignore
|
|
488
565
|
*/
|
|
489
566
|
setStatusMessage(statusMessage: string, options?: SetStatusMessageOptions): Promise<ClientActorRun>;
|
|
490
|
-
/**
|
|
491
|
-
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
492
|
-
*
|
|
493
|
-
* This is just a convenient shortcut for {@link Dataset.pushData}.
|
|
494
|
-
* For example, calling the following code:
|
|
495
|
-
* ```js
|
|
496
|
-
* await Actor.pushData({ myValue: 123 });
|
|
497
|
-
* ```
|
|
498
|
-
*
|
|
499
|
-
* is equivalent to:
|
|
500
|
-
* ```js
|
|
501
|
-
* const dataset = await Actor.openDataset();
|
|
502
|
-
* await dataset.pushData({ myValue: 123 });
|
|
503
|
-
* ```
|
|
504
|
-
*
|
|
505
|
-
* For more information, see {@link Actor.openDataset} and {@link Dataset.pushData}
|
|
506
|
-
*
|
|
507
|
-
* **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
|
|
508
|
-
* otherwise the Actor process might finish before the data are stored!
|
|
509
|
-
*
|
|
510
|
-
* @param item Object or array of objects containing data to be stored in the default dataset.
|
|
511
|
-
* The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
|
|
512
|
-
* @ignore
|
|
513
|
-
*/
|
|
514
|
-
pushData(item: Data | Data[]): Promise<void>;
|
|
515
567
|
/**
|
|
516
568
|
* Stores an object or an array of objects to the default {@link Dataset} of the current Actor run.
|
|
517
569
|
*
|
|
@@ -537,7 +589,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
537
589
|
* @param eventName If provided, the method will attempt to charge for the event for each pushed item.
|
|
538
590
|
* @ignore
|
|
539
591
|
*/
|
|
540
|
-
pushData(item: Data | Data[], eventName
|
|
592
|
+
pushData(item: Data | Data[], eventName?: string | undefined): Promise<ChargeResult>;
|
|
541
593
|
/**
|
|
542
594
|
* Opens a dataset and returns a promise resolving to an instance of the {@link Dataset} class.
|
|
543
595
|
*
|
|
@@ -548,12 +600,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
548
600
|
* For more details and code examples, see the {@link Dataset} class.
|
|
549
601
|
*
|
|
550
602
|
* @param [datasetIdOrName]
|
|
551
|
-
* ID or
|
|
603
|
+
* ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
|
|
552
604
|
* 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.
|
|
553
607
|
* @param [options]
|
|
554
608
|
* @ignore
|
|
555
609
|
*/
|
|
556
|
-
openDataset(datasetIdOrName?:
|
|
610
|
+
openDataset(datasetIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<Dataset<Data>>;
|
|
557
611
|
/**
|
|
558
612
|
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
559
613
|
*
|
|
@@ -662,10 +716,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
662
716
|
* @param [storeIdOrName]
|
|
663
717
|
* ID or name of the key-value store to be opened. If `null` or `undefined`,
|
|
664
718
|
* 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.
|
|
665
720
|
* @param [options]
|
|
666
721
|
* @ignore
|
|
667
722
|
*/
|
|
668
|
-
openKeyValueStore(storeIdOrName?:
|
|
723
|
+
openKeyValueStore(storeIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
|
|
669
724
|
/**
|
|
670
725
|
* Opens a request queue and returns a promise resolving to an instance
|
|
671
726
|
* of the {@link RequestQueue} class.
|
|
@@ -680,10 +735,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
680
735
|
* @param [queueIdOrName]
|
|
681
736
|
* ID or name of the request queue to be opened. If `null` or `undefined`,
|
|
682
737
|
* 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.
|
|
683
739
|
* @param [options]
|
|
684
740
|
* @ignore
|
|
685
741
|
*/
|
|
686
|
-
openRequestQueue(queueIdOrName?:
|
|
742
|
+
openRequestQueue(queueIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<RequestQueue>;
|
|
687
743
|
/**
|
|
688
744
|
* Creates a proxy configuration and returns a promise resolving to an instance
|
|
689
745
|
* of the {@link ProxyConfiguration} class that is already initialized.
|
|
@@ -718,6 +774,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
718
774
|
* ```
|
|
719
775
|
* { useApifyProxy: false }
|
|
720
776
|
* ```
|
|
777
|
+
*
|
|
778
|
+
* As part of the init process, we verify the configuration by checking the proxy status endpoint.
|
|
779
|
+
* This can make the init slower, to opt-out of this, use `checkAccess: false` (defaults to `true`).
|
|
780
|
+
*
|
|
721
781
|
* @ignore
|
|
722
782
|
*/
|
|
723
783
|
createProxyConfiguration(proxyConfigurationOptions?: ProxyConfigurationOptions & {
|
|
@@ -729,6 +789,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
729
789
|
* This method attempts to charge for the specified number of events, but may charge fewer
|
|
730
790
|
* if doing so would exceed the total budget limit (`maxTotalChargeUsd`).
|
|
731
791
|
*
|
|
792
|
+
* **Important:** When using the `count` parameter to charge for multiple events at once,
|
|
793
|
+
* be aware that the charge may be partially fulfilled — i.e. `chargedCount` can be less
|
|
794
|
+
* than the requested `count`. Always check the returned `chargedCount` to know how many
|
|
795
|
+
* events were actually charged, and only perform that much work. If your work is
|
|
796
|
+
* meaningfully divisible into individual units, prefer calling `charge()` once per unit
|
|
797
|
+
* rather than batching via `count` — this gives finer control over budget consumption
|
|
798
|
+
* and avoids situations where more work is requested than the budget allows.
|
|
799
|
+
*
|
|
732
800
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
733
801
|
* @ignore
|
|
734
802
|
*/
|
|
@@ -746,7 +814,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
746
814
|
* Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
|
|
747
815
|
*
|
|
748
816
|
* For the list of the Apify environment variables, see
|
|
749
|
-
* [Actor documentation](https://docs.apify.com/
|
|
817
|
+
* [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
|
|
750
818
|
* If some variables are not defined or are invalid, the corresponding value in the resulting object will be null.
|
|
751
819
|
* @ignore
|
|
752
820
|
*/
|
|
@@ -857,6 +925,11 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
857
925
|
* Calling `Actor.exit()` is required if you use the `Actor.init()` method, since it opens websocket connection
|
|
858
926
|
* (see {@link Actor.events} for details), which needs to be terminated for the code to finish.
|
|
859
927
|
*
|
|
928
|
+
* **Graceful shutdown:** When running on the Apify platform, the Actor may receive `aborting` or `migrating`
|
|
929
|
+
* events. By default, the SDK will automatically call `Actor.exit()` on `aborting` events and `Actor.reboot()`
|
|
930
|
+
* on `migrating` events (to speed up the migration and continue the run on a new worker). You can disable this
|
|
931
|
+
* behavior by setting `options.gracefulShutdown` to `false`.
|
|
932
|
+
*
|
|
860
933
|
* ```js
|
|
861
934
|
* import { gotScraping } from 'got-scraping';
|
|
862
935
|
*
|
|
@@ -958,7 +1031,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
958
1031
|
* Otherwise the `options.contentType` parameter must be provided.
|
|
959
1032
|
* @param [options]
|
|
960
1033
|
*/
|
|
961
|
-
static start(actorId: string, input?: Dictionary, options?:
|
|
1034
|
+
static start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ClientActorRun>;
|
|
962
1035
|
/**
|
|
963
1036
|
* Aborts given Actor run on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable).
|
|
964
1037
|
*
|
|
@@ -1076,11 +1149,13 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1076
1149
|
* For more details and code examples, see the {@link Dataset} class.
|
|
1077
1150
|
*
|
|
1078
1151
|
* @param [datasetIdOrName]
|
|
1079
|
-
* ID or
|
|
1152
|
+
* ID, name, or alias of the dataset to be opened. If `null` or `undefined`,
|
|
1080
1153
|
* 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.
|
|
1081
1156
|
* @param [options]
|
|
1082
1157
|
*/
|
|
1083
|
-
static openDataset<Data extends Dictionary = Dictionary>(datasetIdOrName?:
|
|
1158
|
+
static openDataset<Data extends Dictionary = Dictionary>(datasetIdOrName?: StorageIdentifier | null, options?: OpenStorageOptions): Promise<Dataset<Data>>;
|
|
1084
1159
|
/**
|
|
1085
1160
|
* Gets a value from the default {@link KeyValueStore} associated with the current Actor run.
|
|
1086
1161
|
*
|
|
@@ -1185,9 +1260,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1185
1260
|
* @param [storeIdOrName]
|
|
1186
1261
|
* ID or name of the key-value store to be opened. If `null` or `undefined`,
|
|
1187
1262
|
* the function returns the default key-value store associated with the Actor run.
|
|
1263
|
+
* You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1188
1264
|
* @param [options]
|
|
1189
1265
|
*/
|
|
1190
|
-
static openKeyValueStore(storeIdOrName?:
|
|
1266
|
+
static openKeyValueStore(storeIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<KeyValueStore>;
|
|
1191
1267
|
/**
|
|
1192
1268
|
* Opens a request queue and returns a promise resolving to an instance
|
|
1193
1269
|
* of the {@link RequestQueue} class.
|
|
@@ -1202,9 +1278,10 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1202
1278
|
* @param [queueIdOrName]
|
|
1203
1279
|
* ID or name of the request queue to be opened. If `null` or `undefined`,
|
|
1204
1280
|
* the function returns the default request queue associated with the Actor run.
|
|
1281
|
+
* You can also pass `{ id: 'abc' }` to open by explicit ID, or `{ name: 'abc' }` to open by explicit name.
|
|
1205
1282
|
* @param [options]
|
|
1206
1283
|
*/
|
|
1207
|
-
static openRequestQueue(queueIdOrName?:
|
|
1284
|
+
static openRequestQueue(queueIdOrName?: StorageIdentifierWithoutAlias | null, options?: OpenStorageOptions): Promise<RequestQueue>;
|
|
1208
1285
|
/**
|
|
1209
1286
|
* Creates a proxy configuration and returns a promise resolving to an instance
|
|
1210
1287
|
* of the {@link ProxyConfiguration} class that is already initialized.
|
|
@@ -1239,6 +1316,9 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1239
1316
|
* ```
|
|
1240
1317
|
* { useApifyProxy: false }
|
|
1241
1318
|
* ```
|
|
1319
|
+
*
|
|
1320
|
+
* As part of the init process, we verify the configuration by checking the proxy status endpoint.
|
|
1321
|
+
* This can make the init slower, to opt-out of this, use `checkAccess: false` (defaults to `true`).
|
|
1242
1322
|
*/
|
|
1243
1323
|
static createProxyConfiguration(proxyConfigurationOptions?: ProxyConfigurationOptions & {
|
|
1244
1324
|
useApifyProxy?: boolean;
|
|
@@ -1249,6 +1329,14 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1249
1329
|
* This method attempts to charge for the specified number of events, but may charge fewer
|
|
1250
1330
|
* if doing so would exceed the total budget limit (`maxTotalChargeUsd`).
|
|
1251
1331
|
*
|
|
1332
|
+
* **Important:** When using the `count` parameter to charge for multiple events at once,
|
|
1333
|
+
* be aware that the charge may be partially fulfilled — i.e. `chargedCount` can be less
|
|
1334
|
+
* than the requested `count`. Always check the returned `chargedCount` to know how many
|
|
1335
|
+
* events were actually charged, and only perform that much work. If your work is
|
|
1336
|
+
* meaningfully divisible into individual units, prefer calling `charge()` once per unit
|
|
1337
|
+
* rather than batching via `count` — this gives finer control over budget consumption
|
|
1338
|
+
* and avoids situations where more work is requested than the budget allows.
|
|
1339
|
+
*
|
|
1252
1340
|
* @param options The name of the event to charge for and the number of events to be charged.
|
|
1253
1341
|
*/
|
|
1254
1342
|
static charge(options: ChargeOptions): Promise<ChargeResult>;
|
|
@@ -1260,7 +1348,7 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1260
1348
|
* Returns a new {@link ApifyEnv} object which contains information parsed from all the Apify environment variables.
|
|
1261
1349
|
*
|
|
1262
1350
|
* For the list of the Apify environment variables, see
|
|
1263
|
-
* [Actor documentation](https://docs.apify.com/
|
|
1351
|
+
* [Actor documentation](https://docs.apify.com/platform/actors/development/programming-interface/environment-variables).
|
|
1264
1352
|
* If some of the variables are not defined or are invalid, the corresponding value in the resulting object will be null.
|
|
1265
1353
|
*/
|
|
1266
1354
|
static getEnv(): ApifyEnv;
|
|
@@ -1282,7 +1370,15 @@ export declare class Actor<Data extends Dictionary = Dictionary> {
|
|
|
1282
1370
|
static get config(): Configuration;
|
|
1283
1371
|
/** @internal */
|
|
1284
1372
|
static getDefaultInstance(): Actor;
|
|
1373
|
+
private usesPushDataInterception;
|
|
1374
|
+
private pushDataViaInterceptedClient;
|
|
1375
|
+
private pushDataWithExplicitCharging;
|
|
1285
1376
|
private _openStorage;
|
|
1286
1377
|
private _ensureActorInit;
|
|
1378
|
+
/**
|
|
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.
|
|
1381
|
+
*/
|
|
1382
|
+
private getRemainingTime;
|
|
1383
|
+
private inferDefaultsFromInputSchema;
|
|
1287
1384
|
}
|
|
1288
|
-
//# sourceMappingURL=actor.d.ts.map
|