scrapely 1.2.3 → 1.2.5

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 (86) hide show
  1. package/README.md +119 -1
  2. package/dist/actor.d.ts +703 -0
  3. package/dist/actor.js +1441 -0
  4. package/dist/browser-configuration.d.ts +58 -0
  5. package/dist/browser-configuration.js +128 -0
  6. package/dist/browser-locations.d.ts +5 -0
  7. package/dist/browser-locations.js +5469 -0
  8. package/dist/charging.d.ts +153 -0
  9. package/dist/charging.js +782 -0
  10. package/dist/charging_client.d.ts +18 -0
  11. package/dist/charging_client.js +49 -0
  12. package/dist/configuration.d.ts +121 -0
  13. package/dist/configuration.js +128 -0
  14. package/dist/crypto/secrets.d.ts +44 -0
  15. package/dist/crypto/secrets.js +164 -0
  16. package/dist/events/events-client.d.ts +59 -0
  17. package/dist/events/events-client.js +120 -0
  18. package/dist/events/scrapely-event-manager.d.ts +13 -0
  19. package/dist/events/scrapely-event-manager.js +61 -0
  20. package/dist/index.d.ts +29 -0
  21. package/dist/index.js +95 -0
  22. package/dist/log-env.d.ts +1 -0
  23. package/dist/log-env.js +12 -0
  24. package/dist/manifest.d.ts +30 -0
  25. package/dist/manifest.js +47 -0
  26. package/dist/patch-browser-pool.d.ts +66 -0
  27. package/dist/patch-browser-pool.js +827 -0
  28. package/dist/proxy-configuration.d.ts +118 -0
  29. package/dist/proxy-configuration.js +88 -0
  30. package/dist/request-list.d.ts +57 -0
  31. package/dist/request-list.js +79 -0
  32. package/dist/runner/docker-manager.d.ts +88 -0
  33. package/dist/runner/docker-manager.js +283 -0
  34. package/dist/runner/index.d.ts +2 -0
  35. package/dist/runner/index.js +7 -0
  36. package/dist/runner/timeout-manager.d.ts +43 -0
  37. package/dist/runner/timeout-manager.js +90 -0
  38. package/dist/scrapely-proxy-configuration.d.ts +99 -0
  39. package/dist/scrapely-proxy-configuration.js +559 -0
  40. package/dist/storage/api-storage-client.d.ts +199 -0
  41. package/dist/storage/api-storage-client.js +910 -0
  42. package/dist/storage/billing-tracker.d.ts +163 -0
  43. package/dist/storage/billing-tracker.js +260 -0
  44. package/dist/storage/dataset-client.d.ts +43 -0
  45. package/dist/storage/dataset-client.js +232 -0
  46. package/dist/storage/dataset-collection-client.d.ts +8 -0
  47. package/dist/storage/dataset-collection-client.js +75 -0
  48. package/dist/storage/dataset-push-script.d.ts +18 -0
  49. package/dist/storage/dataset-push-script.js +38 -0
  50. package/dist/storage/dragonfly-client.d.ts +94 -0
  51. package/dist/storage/dragonfly-client.js +167 -0
  52. package/dist/storage/index.d.ts +11 -0
  53. package/dist/storage/index.js +25 -0
  54. package/dist/storage/key-value-store-client.d.ts +61 -0
  55. package/dist/storage/key-value-store-client.js +306 -0
  56. package/dist/storage/kv-store-collection-client.d.ts +8 -0
  57. package/dist/storage/kv-store-collection-client.js +76 -0
  58. package/dist/storage/kvs-iteration.d.ts +17 -0
  59. package/dist/storage/kvs-iteration.js +126 -0
  60. package/dist/storage/log-manager.d.ts +114 -0
  61. package/dist/storage/log-manager.js +244 -0
  62. package/dist/storage/patch-storage.d.ts +11 -0
  63. package/dist/storage/patch-storage.js +177 -0
  64. package/dist/storage/request-queue-client.d.ts +93 -0
  65. package/dist/storage/request-queue-client.js +522 -0
  66. package/dist/storage/rq-collection-client.d.ts +8 -0
  67. package/dist/storage/rq-collection-client.js +89 -0
  68. package/dist/storage/rq-list-requests.d.ts +59 -0
  69. package/dist/storage/rq-list-requests.js +114 -0
  70. package/dist/storage/rq-lock-script.d.ts +56 -0
  71. package/dist/storage/rq-lock-script.js +127 -0
  72. package/dist/storage/run-metadata.d.ts +98 -0
  73. package/dist/storage/run-metadata.js +256 -0
  74. package/dist/storage/s3-client.d.ts +103 -0
  75. package/dist/storage/s3-client.js +302 -0
  76. package/dist/storage/ttl-manager.d.ts +70 -0
  77. package/dist/storage/ttl-manager.js +115 -0
  78. package/dist/storage/utils.d.ts +3 -0
  79. package/dist/storage/utils.js +19 -0
  80. package/dist/storage-identifiers.d.ts +20 -0
  81. package/dist/storage-identifiers.js +6 -0
  82. package/dist/utils.d.ts +54 -0
  83. package/dist/utils.js +63 -0
  84. package/dist/validator.d.ts +24 -0
  85. package/dist/validator.js +158 -0
  86. package/package.json +90 -9
@@ -0,0 +1,703 @@
1
+ import './log-env.js';
2
+ import { EventEmitter } from 'node:events';
3
+ /** Actor permission level - matches Apify's ACTOR_PERMISSION_LEVEL enum */
4
+ export declare enum ACTOR_PERMISSION_LEVEL {
5
+ /** User has no special permissions */
6
+ NONE = "NONE",
7
+ /** User can run the actor */
8
+ RUN = "RUN",
9
+ /** User can modify the actor */
10
+ WRITE = "WRITE",
11
+ /** User has full administrative access */
12
+ ADMIN = "ADMIN"
13
+ }
14
+ import { ApifyClient } from 'scrapely-client';
15
+ import type { ActorRun, Webhook } from 'scrapely-client';
16
+ import type { ActorCallOptions, ActorStartOptions, RunAbortOptions, TaskCallOptions } from 'scrapely-client';
17
+ import { type EventTypeName } from '@crawlee/core';
18
+ import { Configuration, type ConfigurationOptions } from './configuration.js';
19
+ import type { StorageClient } from '@crawlee/types';
20
+ import { type ApiStorageConfig } from './storage/api-storage-client.js';
21
+ import { ChargingManager, type ChargeOptions as ChargingChargeOptions, type ChargeResult as ChargingChargeResult } from './charging.js';
22
+ import { createProxyConfiguration, type CreateProxyConfigurationOptions } from './proxy-configuration.js';
23
+ import { type BrowserConfiguration, type BrowserConfigurationOptions } from './browser-configuration.js';
24
+ import type { Dataset, KeyValueStore, RequestQueue } from 'crawlee';
25
+ /** User function passed to {@link Actor.main} (Apify-compatible). */
26
+ export type UserFunc<T = unknown> = () => T | Promise<T>;
27
+ type Dictionary = Record<string, any>;
28
+ /** Value types returned by {@link Actor.getInput} (Apify-compatible). */
29
+ export type ActorInput = Dictionary | string | Buffer;
30
+ export interface Token {
31
+ token?: string;
32
+ }
33
+ /** Apify-compatible: run timeout in seconds, or 'inherit' (the time remaining in this run). */
34
+ export interface Timeout {
35
+ timeout?: TimeoutOption;
36
+ }
37
+ /**
38
+ * Exit codes for the Actor process (Apify-compatible).
39
+ * Must be in the range 1-128 to avoid collision with signal exits.
40
+ */
41
+ export declare const EXIT_CODES: {
42
+ SUCCESS: number;
43
+ ERROR_USER_FUNCTION_THREW: number;
44
+ ERROR_UNKNOWN: number;
45
+ };
46
+ export interface CallOptions extends Omit<ActorCallOptions, 'timeout'>, Token {
47
+ timeout?: TimeoutOption;
48
+ }
49
+ export interface StartOptions extends Omit<ActorStartOptions, 'waitForFinish' | 'timeout'>, Token {
50
+ timeout?: TimeoutOption;
51
+ }
52
+ export interface CallTaskOptions extends Omit<TaskCallOptions, 'timeout'>, Token {
53
+ timeout?: TimeoutOption;
54
+ }
55
+ export interface AbortOptions extends RunAbortOptions, Token {
56
+ statusMessage?: string;
57
+ }
58
+ /** Billing context for storage operations */
59
+ export interface BillingContext {
60
+ runId: string;
61
+ userId: string;
62
+ }
63
+ export type { ConfigurationOptions } from './configuration.js';
64
+ /**
65
+ * Options for Actor.init()
66
+ */
67
+ export interface InitOptions {
68
+ /** Crawlee configuration overrides (env vars still take precedence). */
69
+ configuration?: ConfigurationOptions;
70
+ /** API storage config or custom {@link StorageClient} for local/testing. */
71
+ storage?: ApiStorageConfig | StorageClient;
72
+ /**
73
+ * Whether to automatically handle platform shutdown signals.
74
+ * When enabled, `Actor.exit()` is called on `aborting` events and `Actor.reboot()` on `migrating` events.
75
+ * @default true
76
+ */
77
+ gracefulShutdown?: boolean;
78
+ /**
79
+ * Delay in milliseconds before calling `Actor.exit()`/`Actor.reboot()` on `aborting`/`migrating` events.
80
+ * @default 0
81
+ */
82
+ gracefulShutdownDelayMillis?: number;
83
+ }
84
+ /**
85
+ * Options for Actor.exit()
86
+ */
87
+ export interface ExitOptions {
88
+ /** Exit with given status message */
89
+ statusMessage?: string;
90
+ /**
91
+ * Amount of time, in seconds, to wait for all event handlers to finish before exiting the process.
92
+ * @default 30
93
+ */
94
+ timeoutSecs?: number;
95
+ /** Exit code, defaults to 0 */
96
+ exitCode?: number;
97
+ /** Call `process.exit()`? Defaults to true */
98
+ exit?: boolean;
99
+ }
100
+ /**
101
+ * Options for Actor.setValue() / KeyValueStore.setValue()
102
+ */
103
+ export interface RecordOptions {
104
+ /** Content type of the value. If specified, value must be a String or Buffer. */
105
+ contentType?: string;
106
+ /** If set to true, the set-record API call will not be retried if it times out. */
107
+ doNotRetryTimeouts?: boolean;
108
+ /** Specifies a custom timeout for the set-record API call, in seconds. */
109
+ timeoutSecs?: number;
110
+ }
111
+ /**
112
+ * Options for Actor.setStatusMessage()
113
+ */
114
+ export interface SetStatusMessageOptions {
115
+ /** If true, the status message will be marked as terminal (final status of the run) */
116
+ isStatusMessageTerminal?: boolean;
117
+ /** Log level for the status message: 'DEBUG', 'INFO', 'WARNING', 'ERROR' */
118
+ level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
119
+ }
120
+ /**
121
+ * Options for Actor.addWebhook()
122
+ */
123
+ export interface WebhookOptions {
124
+ /** Array of event types to trigger the webhook */
125
+ eventTypes: string[];
126
+ /** URL to receive the webhook POST request */
127
+ requestUrl: string;
128
+ /** Payload template for the webhook body */
129
+ payloadTemplate?: string;
130
+ /** Idempotency key to prevent duplicate webhooks on actor restart */
131
+ idempotencyKey?: string;
132
+ /** Headers template for the webhook request */
133
+ headersTemplate?: string;
134
+ /** Description of the webhook */
135
+ description?: string;
136
+ /** If true, ignore SSL errors when sending the webhook */
137
+ ignoreSslErrors?: boolean;
138
+ /** If true, the webhook will not retry on failure */
139
+ doNotRetry?: boolean;
140
+ /** If true, the webhook will interpolate strings in the payloadTemplate and headersTemplate */
141
+ shouldInterpolateStrings?: boolean;
142
+ /** If true, indicates the webhook is an Apify integration */
143
+ isApifyIntegration?: boolean;
144
+ }
145
+ /**
146
+ * Options for timeout in call/start methods.
147
+ * Can be a number in seconds, or 'inherit' to use the remaining time of the current run.
148
+ */
149
+ export type TimeoutOption = number | 'inherit';
150
+ /**
151
+ * Options for Actor.main()
152
+ */
153
+ export interface MainOptions extends ExitOptions, InitOptions {
154
+ }
155
+ /**
156
+ * Options for Actor.useState()
157
+ */
158
+ export interface UseStateOptions {
159
+ /** Name of the key-value store to use for state persistence */
160
+ keyValueStoreName?: string;
161
+ /** Configuration object (for advanced use) */
162
+ config?: any;
163
+ }
164
+ /**
165
+ * Options for Actor.openDataset(), openKeyValueStore(), and openRequestQueue() (Apify-compatible).
166
+ */
167
+ export interface OpenStorageOptions {
168
+ /**
169
+ * If set to `true`, cloud storage is used even when `CRAWLEE_STORAGE_DIR` / `APIFY_LOCAL_STORAGE_DIR` is set.
170
+ */
171
+ forceCloud?: boolean;
172
+ /** SDK configuration instance (advanced use). */
173
+ config?: Configuration;
174
+ }
175
+ type StorageIdentifierArg = string | null | {
176
+ id: string;
177
+ } | {
178
+ name: string;
179
+ } | {
180
+ alias: string;
181
+ };
182
+ /**
183
+ * Options for Actor.metamorph()
184
+ */
185
+ export interface MetamorphOptions {
186
+ /** Content type for the input. If not specified, input is expected to be JSON */
187
+ contentType?: string;
188
+ /** Tag or number of the target Actor build to metamorph into */
189
+ build?: string;
190
+ }
191
+ /**
192
+ * Options for Actor.reboot()
193
+ */
194
+ export interface RebootOptions {
195
+ /** @internal */
196
+ customAfterSleepMillis?: number;
197
+ }
198
+ /** Result of a charge operation (Apify-compatible). */
199
+ export type ChargeResult = ChargingChargeResult;
200
+ /**
201
+ * Parsed representation of the environment variables.
202
+ * This object is returned by the {@apilink Actor.getEnv} function.
203
+ * Fully compatible with Apify's ApifyEnv interface.
204
+ */
205
+ export interface ApifyEnv {
206
+ /** ID of the Actor (ACTOR_ID) */
207
+ actorId: string | null;
208
+ /** ID of the Actor build used in the run (ACTOR_BUILD_ID) */
209
+ actorBuildId: string | null;
210
+ /** Build number of the Actor build (ACTOR_BUILD_NUMBER) */
211
+ actorBuildNumber: string | null;
212
+ /** Comma-separated list of build tags (ACTOR_BUILD_TAGS) */
213
+ actorBuildTags: string | null;
214
+ /** WebSocket URL for Actor events (ACTOR_EVENTS_WS_URL) */
215
+ actorEventsWsUrl: string | null;
216
+ /** Full name of the actor (owner/actor-name) (ACTOR_FULL_NAME) */
217
+ actorFullName: string | null;
218
+ /** Maximum paid dataset items (ACTOR_MAX_PAID_DATASET_ITEMS) */
219
+ actorMaxPaidDatasetItems: number | null;
220
+ /** Permission level the Actor is run under (ACTOR_PERMISSION_LEVEL) */
221
+ actorPermissionLevel: ACTOR_PERMISSION_LEVEL | null;
222
+ /** ID of the Actor run (ACTOR_RUN_ID) */
223
+ actorRunId: string | null;
224
+ /** ID of the Actor task (ACTOR_TASK_ID) */
225
+ actorTaskId: string | null;
226
+ /** Base URL for the API (APIFY_API_BASE_URL) */
227
+ apiBaseUrl: string | null;
228
+ /** Public base URL of the API (APIFY_API_PUBLIC_BASE_URL) */
229
+ apiPublicBaseUrl: string | null;
230
+ /** Chrome executable path (APIFY_CHROME_EXECUTABLE_PATH) */
231
+ chromeExecutablePath: string | null;
232
+ /** Container port (ACTOR_WEB_SERVER_PORT) */
233
+ containerPort: number | null;
234
+ /** Container URL (ACTOR_WEB_SERVER_URL) */
235
+ containerUrl: string | null;
236
+ /** Dedicated CPUs (ACTOR_DEDICATED_CPUS) */
237
+ dedicatedCpus: string | null;
238
+ /** ID of the default dataset (ACTOR_DEFAULT_DATASET_ID) */
239
+ defaultDatasetId: string | null;
240
+ /** ID of the default key-value store (ACTOR_DEFAULT_KEY_VALUE_STORE_ID) */
241
+ defaultKeyValueStoreId: string | null;
242
+ /** ID of the default request queue (ACTOR_DEFAULT_REQUEST_QUEUE_ID) */
243
+ defaultRequestQueueId: string | null;
244
+ /** Disable outdated warning (APIFY_DISABLE_OUTDATED_WARNING) */
245
+ disableOutdatedWarning: 1 | null;
246
+ /** Fact (APIFY_FACT) */
247
+ fact: string | null;
248
+ /** If "1", run in headless mode (APIFY_HEADLESS) */
249
+ headless: string | null;
250
+ /** Input key (ACTOR_INPUT_KEY) */
251
+ inputKey: string | null;
252
+ /** Input secrets private key file (APIFY_INPUT_SECRETS_PRIVATE_KEY_FILE) */
253
+ inputSecretsPrivateKeyFile: string | null;
254
+ /** Input secrets private key passphrase (APIFY_INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE) */
255
+ inputSecretsPrivateKeyPassphrase: string | null;
256
+ /** If set to "1", running on Apify servers (APIFY_IS_AT_HOME) */
257
+ isAtHome: string | null;
258
+ /** Local storage directory (CRAWLEE_STORAGE_DIR) */
259
+ localStorageDir: string | null;
260
+ /** Log format (APIFY_LOG_FORMAT) */
261
+ logFormat: string | null;
262
+ /** Log level - DEBUG, INFO, WARNING, ERROR (APIFY_LOG_LEVEL) */
263
+ logLevel: string | null;
264
+ /** Amount of memory allocated for the Actor, in megabytes (ACTOR_MEMORY_MBYTES) */
265
+ memoryMbytes: number | null;
266
+ /** Origin for the Actor run - how it was started (APIFY_META_ORIGIN) */
267
+ metaOrigin: string | null;
268
+ /** Proxy hostname (APIFY_PROXY_HOSTNAME) */
269
+ proxyHostname: string | null;
270
+ /** Proxy password (APIFY_PROXY_PASSWORD) */
271
+ proxyPassword: string | null;
272
+ /** Proxy port (APIFY_PROXY_PORT) */
273
+ proxyPort: string | null;
274
+ /** Proxy status URL (APIFY_PROXY_STATUS_URL) */
275
+ proxyStatusUrl: string | null;
276
+ /** SDK latest version */
277
+ sdkLatestVersion: string | null;
278
+ /** Date when the Actor was started (ACTOR_STARTED_AT) */
279
+ startedAt: Date | null;
280
+ /** System info interval in millis (APIFY_SYSTEM_INFO_INTERVAL_MILLIS) */
281
+ systemInfoIntervalMillis: string | null;
282
+ /** Date when the Actor will time out (ACTOR_TIMEOUT_AT) */
283
+ timeoutAt: Date | null;
284
+ /** Authentication token (APIFY_TOKEN or SCRAPELY_TOKEN) */
285
+ token: string | null;
286
+ /** ID of the user who started the Actor (APIFY_USER_ID) */
287
+ userId: string | null;
288
+ /** If "1", the user is a paying user (APIFY_USER_IS_PAYING) */
289
+ userIsPaying: string | null;
290
+ /** Workflow key (ACTOR_WORKFLOW_KEY) */
291
+ workflowKey: string | null;
292
+ /** Maximum total charge in USD (ACTOR_MAX_TOTAL_CHARGE_USD) - Scrapely extension */
293
+ maxTotalChargeUsd: number | null;
294
+ /** User's plan (SCRAPELY_USER_PLAN) - Scrapely extension */
295
+ userPlan: string | null;
296
+ /** Restart on error flag (ACTOR_RESTART_ON_ERROR) - Scrapely extension */
297
+ restartOnError: string | null;
298
+ }
299
+ export declare class Actor {
300
+ /** Configuration for this Actor instance (pass to crawlers as second argument). */
301
+ readonly config: Configuration;
302
+ /** Whether this Actor instance was initialized. Set by {@link Actor.init}. */
303
+ initialized: boolean;
304
+ /**
305
+ * Tracks that init() has started installing process-global lifecycle state
306
+ * (storage factory with run credentials, events WebSocket, event manager,
307
+ * graceful-shutdown/signal handlers, charging). Deliberately separate from
308
+ * the public {@link initialized} flag: `_shutdownActor` must tear down
309
+ * partial state from a FAILED init (so it stays retryable), while
310
+ * `initialized` — used by `_ensureActorInit` — flips only after init fully
311
+ * succeeds.
312
+ */
313
+ private _lifecycleStarted;
314
+ private readonly _apifyClient;
315
+ private readonly chargingManager;
316
+ /**
317
+ * Creates an Actor instance (Apify SDK-compatible alternative to static helpers).
318
+ */
319
+ constructor(options?: ConfigurationOptions);
320
+ /** Default ApifyClient instance for this Actor (Apify-compatible instance accessor). */
321
+ get apifyClient(): ApifyClient;
322
+ private _ensureInit;
323
+ private static _actorConfig;
324
+ /**
325
+ * Event emitter for Actor events (same instance as the platform EventManager).
326
+ * Supports events: 'persistState', 'migrating', 'aborting', 'cpuInfo'.
327
+ *
328
+ * Usage:
329
+ * ```typescript
330
+ * Actor.events.on('persistState', () => {
331
+ * // Save state before migration
332
+ * });
333
+ * ```
334
+ */
335
+ static get events(): EventEmitter;
336
+ /**
337
+ * Throws an error if the Actor was not initialized.
338
+ * Used internally to ensure methods are called after init().
339
+ */
340
+ private static _ensureActorInit;
341
+ /**
342
+ * Returns the remaining time in milliseconds until the Actor run times out.
343
+ * Uses the ACTOR_TIMEOUT_AT environment variable set by the platform.
344
+ *
345
+ * @returns Milliseconds remaining, or undefined if no timeout is set (not running on platform)
346
+ */
347
+ static getRemainingTime(): number | undefined;
348
+ /**
349
+ * Initializes this Actor instance.
350
+ *
351
+ * @param options - Initialization options
352
+ */
353
+ init(options?: InitOptions): Promise<void>;
354
+ static init(options?: InitOptions): Promise<void>;
355
+ /**
356
+ * Runs the main user function that performs the job of the Actor
357
+ * and terminates the process when the user function finishes.
358
+ *
359
+ * @param userFunc - User function to be executed
360
+ * @param options - Main options (exit, init, gracefulShutdown, etc.)
361
+ */
362
+ static main<T>(userFunc: UserFunc<T>, options?: MainOptions): Promise<T>;
363
+ /**
364
+ * Gracefully exits the Actor run.
365
+ *
366
+ * @param options - Exit options
367
+ */
368
+ static exit(messageOrOptions?: string | ExitOptions, options?: ExitOptions): Promise<void>;
369
+ static fail(messageOrOptions?: string | ExitOptions, options?: ExitOptions): Promise<void>;
370
+ static getInput<T = ActorInput>(): Promise<T | null>;
371
+ static getInputOrThrow<T = ActorInput>(): Promise<T>;
372
+ /**
373
+ * Synchronously get the actor input (cached from first access).
374
+ * This matches Apify's Actor.input behavior.
375
+ */
376
+ static get input(): Record<string, any> | undefined;
377
+ /**
378
+ * Stores an object or an array of objects to the default {@apilink Dataset} of the current Actor run.
379
+ *
380
+ * This is just a convenient shortcut for {@apilink Dataset.pushData}.
381
+ *
382
+ * **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
383
+ * otherwise the Actor process might finish before the data are stored!
384
+ *
385
+ * @param item - Object or array of objects containing data to be stored in the default dataset.
386
+ * The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
387
+ * @returns Promise that resolves when the data has been stored
388
+ */
389
+ static pushData<Data extends Record<string, any>>(item: Data | Data[]): Promise<void>;
390
+ /**
391
+ * Stores an object or an array of objects to the default {@apilink Dataset} of the current Actor run.
392
+ *
393
+ * This is just a convenient shortcut for {@apilink Dataset.pushData}.
394
+ *
395
+ * **IMPORTANT**: Make sure to use the `await` keyword when calling `pushData()`,
396
+ * otherwise the Actor process might finish before the data are stored!
397
+ *
398
+ * @param item - Object or array of objects containing data to be stored in the default dataset.
399
+ * The objects must be serializable to JSON and the JSON representation of each object must be smaller than 9MB.
400
+ * @param eventName - Event name for pay-per-event pricing. If provided, the method will
401
+ * attempt to charge for each pushed item.
402
+ * @returns ChargeResult indicating if the user's spending limit was reached
403
+ */
404
+ static pushData<Data extends Record<string, any>>(item: Data | Data[], eventName: string): Promise<ChargeResult>;
405
+ pushData<Data extends Record<string, any>>(item: Data | Data[], eventName?: string): Promise<void | ChargeResult>;
406
+ private usesPushDataInterception;
407
+ private pushDataViaInterceptedClient;
408
+ private pushDataWithExplicitCharging;
409
+ static getValue<T>(key: string): Promise<T | null>;
410
+ /**
411
+ * Stores or deletes a value in the default KeyValueStore associated with the current Actor run.
412
+ *
413
+ * This is just a convenient shortcut for KeyValueStore.setValue.
414
+ *
415
+ * **Example:**
416
+ * ```typescript
417
+ * // Store an object (serialized to JSON)
418
+ * await Actor.setValue('OUTPUT', { foo: 'bar' });
419
+ *
420
+ * // Delete a record
421
+ * await Actor.setValue('my-key', null);
422
+ * ```
423
+ *
424
+ * @param key - Unique record key
425
+ * @param value - Record data. If null, the record is deleted. If no contentType is specified,
426
+ * value can be any JSON-serializable object. If contentType is set, value must be String or Buffer.
427
+ * @param options - Record options
428
+ */
429
+ static setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
430
+ /**
431
+ * Helper to resolve storage identifier to a string ID or name.
432
+ * Supports: string, { id: '...' }, { name: '...' }, { alias: '...' }
433
+ */
434
+ private static _resolveStorageIdentifier;
435
+ private static _buildStorageOpenOptions;
436
+ private static _openDataset;
437
+ private static _openKeyValueStore;
438
+ private static _openRequestQueue;
439
+ static openDataset<T extends Record<string, any>>(nameOrIdOrOptions?: string | null | StorageIdentifierArg, openOptions?: OpenStorageOptions): Promise<Dataset<T>>;
440
+ static openKeyValueStore(nameOrIdOrOptions?: string | null | StorageIdentifierArg, openOptions?: OpenStorageOptions): Promise<KeyValueStore>;
441
+ static openRequestQueue(nameOrIdOrOptions?: string | null | StorageIdentifierArg, openOptions?: OpenStorageOptions): Promise<RequestQueue>;
442
+ static isAtHome(): boolean;
443
+ /**
444
+ * Returns true when the Actor run was started in standby mode
445
+ * (Python SDK `Actor.is_standby` parity; detected via `metaOrigin === 'STANDBY'`).
446
+ */
447
+ static isStandby(): boolean;
448
+ /**
449
+ * Returns a new {@apilink ApifyEnv} object which contains information parsed from all the environment variables.
450
+ *
451
+ * For the list of the environment variables, see the Actor documentation.
452
+ * If some variables are not defined or are invalid, the corresponding value in the resulting object will be null.
453
+ *
454
+ * @returns Parsed environment variables with proper types
455
+ */
456
+ static getEnv(): ApifyEnv;
457
+ /**
458
+ * Full technical name of the actor (owner-username/actor-name).
459
+ */
460
+ static get fullName(): string | undefined;
461
+ /**
462
+ * ID of the Actor task, or undefined if running outside a task.
463
+ */
464
+ static get taskId(): string | undefined;
465
+ /**
466
+ * ID of the Actor build used in the run.
467
+ */
468
+ static get buildId(): string | undefined;
469
+ /**
470
+ * Build number of the Actor build used in the run.
471
+ */
472
+ static get buildNumber(): string | undefined;
473
+ /**
474
+ * Comma-separated list of tags of the Actor build used in the run.
475
+ */
476
+ static get buildTags(): string[];
477
+ /**
478
+ * Date when the Actor was started (ISO 8601 UTC).
479
+ */
480
+ static get startedAt(): string | undefined;
481
+ /**
482
+ * Date when the Actor will time out (ISO 8601 UTC).
483
+ */
484
+ static get timeoutAt(): string | undefined;
485
+ /**
486
+ * API token of the user who started the Actor.
487
+ */
488
+ static get token(): string | undefined;
489
+ /**
490
+ * ID of the user who started the Actor.
491
+ */
492
+ static get userId(): string | undefined;
493
+ /**
494
+ * Whether the user who started the Actor is a paying user.
495
+ */
496
+ static get isPaying(): boolean;
497
+ /**
498
+ * Public URL of the Apify API. May be used to interact with the platform programmatically.
499
+ */
500
+ static get apiPublicBaseUrl(): string | undefined;
501
+ /**
502
+ * Get a single environment variable value by name.
503
+ * This is an Apify SDK-compatible alias for process.env[key].
504
+ */
505
+ static getenv(key: string): string | undefined;
506
+ on(event: EventTypeName | 'cpuInfo', listener: (...args: any[]) => void): void;
507
+ off(event: EventTypeName | 'cpuInfo', listener?: (...args: any[]) => void): void;
508
+ static on(event: EventTypeName | 'cpuInfo', listener: (...args: any[]) => void): void;
509
+ static off(event: EventTypeName | 'cpuInfo', listener?: (...args: any[]) => void): void;
510
+ /**
511
+ * Closes the event manager, disconnects platform events, and flushes storage.
512
+ * Called automatically at the end of {@link Actor.main} and {@link Actor.exit}.
513
+ */
514
+ private static _fatalShutdownStarted;
515
+ /** One-shot bounded reconciliation on fatal process errors. */
516
+ private static installFatalChargeHandlers;
517
+ private static _shutdownActor;
518
+ /**
519
+ * Sets the status message for the current Actor run.
520
+ *
521
+ * @param message - The status message to set
522
+ * @param options - Optional settings for the status message
523
+ * @returns The updated ActorRun object, or an empty object if running locally
524
+ */
525
+ static setStatusMessage(message: string, options?: SetStatusMessageOptions): Promise<ActorRun>;
526
+ /**
527
+ * Creates a proxy configuration and returns a promise resolving to an instance
528
+ * of the ProxyConfiguration class that is already initialized.
529
+ *
530
+ * Configures connection to a proxy server with the provided options. Proxy servers
531
+ * are used to prevent target websites from blocking your crawlers based on IP address
532
+ * rate limits or blacklists. Setting proxy configuration in your crawlers automatically
533
+ * configures them to use the selected proxies for all connections.
534
+ *
535
+ * **Example usage:**
536
+ * ```javascript
537
+ * const proxyConfiguration = await Actor.createProxyConfiguration({
538
+ * proxyUrls: ['http://user:pass@proxy1.example.com:8080'],
539
+ * });
540
+ *
541
+ * const crawler = new CheerioCrawler({
542
+ * proxyConfiguration,
543
+ * requestHandler({ proxyInfo }) {
544
+ * const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
545
+ * },
546
+ * });
547
+ * ```
548
+ *
549
+ * For compatibility with existing Actor Input UI (Input Schema), this function returns
550
+ * `undefined` when `{ useApifyProxy: false }` is passed.
551
+ *
552
+ * @param options - Proxy configuration options
553
+ * @returns Promise resolving to ProxyConfiguration instance, or undefined
554
+ */
555
+ static createProxyConfiguration(options?: CreateProxyConfigurationOptions): Promise<ReturnType<typeof createProxyConfiguration>>;
556
+ /**
557
+ * Creates a Scrapely remote browser configuration (location and
558
+ * fingerprint options). Pass it to browser crawlers next to
559
+ * `proxyConfiguration`:
560
+ *
561
+ * ```javascript
562
+ * const browserConfiguration = await Actor.createBrowserConfiguration({ countryCode: 'US', os: 'windows' });
563
+ * const crawler = new PlaywrightCrawler({ browserConfiguration, requestHandler });
564
+ * ```
565
+ *
566
+ * Ignored outside the Scrapely remote browser (local runs), so the same
567
+ * code runs locally and on the platform.
568
+ */
569
+ static createBrowserConfiguration(options?: BrowserConfigurationOptions): Promise<BrowserConfiguration>;
570
+ /** @internal */
571
+ private static _instance;
572
+ /**
573
+ * Get the default Actor instance (singleton pattern for Apify SDK compatibility).
574
+ * @returns The default Actor instance
575
+ */
576
+ static getDefaultInstance(): Actor;
577
+ /**
578
+ * Default Configuration instance (Apify-compatible static accessor).
579
+ * Used after Actor.init() without new Actor(), e.g. Actor.config.get('standbyPort').
580
+ */
581
+ static get config(): Configuration;
582
+ /**
583
+ * Default API client instance for the Scrapely platform.
584
+ */
585
+ static get apifyClient(): ApifyClient;
586
+ /**
587
+ * Returns a new Apify API client pointed at the Scrapely platform.
588
+ */
589
+ newClient(options?: {
590
+ token?: string;
591
+ baseUrl?: string;
592
+ }): ApifyClient;
593
+ static newClient(options?: {
594
+ token?: string;
595
+ baseUrl?: string;
596
+ }): ApifyClient;
597
+ /** Apify-compatible instance API — delegates to {@link Actor.charge}. */
598
+ charge(options: ChargingChargeOptions | string, count?: number): Promise<ChargeResult>;
599
+ /**
600
+ * Charge for a custom pricing event (pay-per-event Actors).
601
+ */
602
+ static charge(options: ChargingChargeOptions | string, count?: number): Promise<ChargeResult>;
603
+ static getChargingManager(): ChargingManager;
604
+ getChargingManager(): ChargingManager;
605
+ /**
606
+ * Metamorph the current actor run into a run of another actor.
607
+ * This follows Apify's metamorph behavior:
608
+ * 1. Stores new input under INPUT-METAMORPH-{n} key in the default KVS
609
+ * 2. Signals the server to swap the container to the target actor's image
610
+ * 3. Exits the current process (the container will be replaced)
611
+ *
612
+ * @param targetActorId - The ID or username/actorName of the target actor
613
+ * @param input - Optional input for the target actor (uses current input if not provided)
614
+ * @param options - Optional build tag and content type for the target actor
615
+ */
616
+ static metamorph(targetActorId: string, input?: Record<string, any> | string | Buffer, options?: MetamorphOptions): Promise<void>;
617
+ /**
618
+ * Persist runtime state across server migrations.
619
+ *
620
+ * Long-running Actor jobs may need to migrate between servers.
621
+ * Without state persistence, your job's progress is lost during
622
+ * migration, causing it to restart from the beginning on the new server.
623
+ *
624
+ * This method automatically saves your state to the key-value store
625
+ * whenever a `persistState` event occurs (every 60 seconds and on exit),
626
+ * and restores it when the Actor restarts after a migration.
627
+ *
628
+ * The state must be JSON-serializable (values must survive JSON.stringify/parse).
629
+ * For short-running Actors (less than a few minutes), state persistence is
630
+ * typically unnecessary.
631
+ *
632
+ * @param nameOrInitialState - Either the state key name (string) or default state object
633
+ * @param defaultValue - Default state used when no previously persisted state exists (when first param is string)
634
+ * @param options - Options for state persistence
635
+ * @returns The current state object (mutate it directly; it saves on persistState events)
636
+ */
637
+ static useState<State extends Dictionary = Dictionary>(nameOrInitialState?: string | State, defaultValue?: State, options?: UseStateOptions): Promise<State>;
638
+ /**
639
+ * Reboot the Actor run.
640
+ *
641
+ * This method is designed to be called in the `migrating` event handler
642
+ * to speed up the migration process and ensure state consistency.
643
+ *
644
+ * After calling this, the Actor container will be stopped and restarted
645
+ * on a new server. Any state persisted via Actor.useState() will be
646
+ * automatically restored.
647
+ *
648
+ * This is an Apify-compatible method.
649
+ *
650
+ * @param options - Reboot options
651
+ */
652
+ static reboot(options?: RebootOptions): Promise<void>;
653
+ /**
654
+ * Abort an Actor run on the Scrapely platform.
655
+ *
656
+ * @param runId - The ID of the run to abort. Defaults to the current run.
657
+ * @param options - Abort options
658
+ * @returns The ActorRun object with details about the aborted run
659
+ */
660
+ static abort(runId?: string, options?: AbortOptions): Promise<ActorRun>;
661
+ static addWebhook(options: WebhookOptions): Promise<Webhook | undefined>;
662
+ /**
663
+ * Runs an Actor on the platform and waits for it to finish (Apify-compatible instance API).
664
+ */
665
+ call(actorId: string, input?: unknown, options?: CallOptions): Promise<ActorRun>;
666
+ static call(actorId: string, input?: unknown, options?: CallOptions): Promise<ActorRun>;
667
+ /**
668
+ * Runs an Actor task on the platform and waits for it to finish (Apify-compatible instance API).
669
+ */
670
+ callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ActorRun>;
671
+ static callTask(taskId: string, input?: Dictionary, options?: CallTaskOptions): Promise<ActorRun>;
672
+ static start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ActorRun>;
673
+ main<T>(userFunc: UserFunc<T>, options?: MainOptions): Promise<T>;
674
+ exit(messageOrOptions?: string | ExitOptions, options?: ExitOptions): Promise<void>;
675
+ fail(messageOrOptions?: string | ExitOptions, options?: ExitOptions): Promise<void>;
676
+ getInput<T = ActorInput>(): Promise<T | null>;
677
+ getInputOrThrow<T = ActorInput>(): Promise<T>;
678
+ getValue<T>(key: string): Promise<T | null>;
679
+ setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
680
+ openDataset<T extends Record<string, any>>(nameOrIdOrOptions?: string | null | StorageIdentifierArg, openOptions?: OpenStorageOptions): Promise<Dataset<T>>;
681
+ openKeyValueStore(nameOrIdOrOptions?: string | null | StorageIdentifierArg, openOptions?: OpenStorageOptions): Promise<KeyValueStore>;
682
+ openRequestQueue(nameOrIdOrOptions?: string | null | StorageIdentifierArg, openOptions?: OpenStorageOptions): Promise<RequestQueue>;
683
+ isAtHome(): boolean;
684
+ /** Instance mirror of {@link Actor.isStandby} (Python SDK `Actor.is_standby` parity). */
685
+ isStandby(): boolean;
686
+ getEnv(): ApifyEnv;
687
+ setStatusMessage(message: string, options?: SetStatusMessageOptions): Promise<ActorRun>;
688
+ createProxyConfiguration(options?: CreateProxyConfigurationOptions): Promise<ReturnType<typeof createProxyConfiguration>>;
689
+ createBrowserConfiguration(options?: BrowserConfigurationOptions): Promise<BrowserConfiguration>;
690
+ metamorph(targetActorId: string, input?: Record<string, any> | string | Buffer, options?: MetamorphOptions): Promise<void>;
691
+ reboot(options?: RebootOptions): Promise<void>;
692
+ abort(runId?: string, options?: AbortOptions): Promise<ActorRun>;
693
+ addWebhook(options: WebhookOptions): Promise<Webhook | undefined>;
694
+ start(actorId: string, input?: Dictionary, options?: StartOptions): Promise<ActorRun>;
695
+ useState<State extends Dictionary = Dictionary>(nameOrInitialState?: string | State, defaultValue?: State, options?: UseStateOptions): Promise<State>;
696
+ /**
697
+ * Apify v2-compatible utility namespace.
698
+ * Provides helper functions like enqueueLinks that accept the Apify v2 API signature.
699
+ */
700
+ static readonly utils: {
701
+ enqueueLinks: typeof import("./utils.js").enqueueLinks;
702
+ };
703
+ }