apify 4.0.0-beta.12 → 4.0.0-beta.121

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 (69) hide show
  1. package/README.md +29 -43
  2. package/dist/actor.d.ts +511 -167
  3. package/dist/actor.js +895 -322
  4. package/dist/apify_dataset_backend.d.ts +19 -0
  5. package/dist/apify_dataset_backend.js +77 -0
  6. package/dist/apify_file_system_storage_backend.d.ts +34 -0
  7. package/dist/apify_file_system_storage_backend.js +41 -0
  8. package/dist/apify_key_value_store_backend.d.ts +23 -0
  9. package/dist/apify_key_value_store_backend.js +56 -0
  10. package/dist/apify_request_queue_backend.d.ts +78 -0
  11. package/dist/apify_request_queue_backend.js +114 -0
  12. package/dist/apify_request_queue_shared_backend.d.ts +31 -0
  13. package/dist/apify_request_queue_shared_backend.js +193 -0
  14. package/dist/apify_request_queue_single_backend.d.ts +43 -0
  15. package/dist/apify_request_queue_single_backend.js +256 -0
  16. package/dist/apify_storage_backend.d.ts +90 -0
  17. package/dist/apify_storage_backend.js +210 -0
  18. package/dist/charging.d.ts +82 -18
  19. package/dist/charging.js +388 -128
  20. package/dist/charging_storage_backend.d.ts +53 -0
  21. package/dist/charging_storage_backend.js +109 -0
  22. package/dist/child_run_tracker.d.ts +88 -0
  23. package/dist/child_run_tracker.js +239 -0
  24. package/dist/configuration.d.ts +86 -136
  25. package/dist/configuration.js +136 -145
  26. package/dist/enqueue_links_filters.d.ts +29 -0
  27. package/dist/enqueue_links_filters.js +52 -0
  28. package/dist/errors.d.ts +31 -0
  29. package/dist/errors.js +22 -0
  30. package/dist/google_sheets.d.ts +12 -0
  31. package/dist/google_sheets.js +26 -0
  32. package/dist/index.d.ts +11 -5
  33. package/dist/index.js +8 -5
  34. package/dist/input-schemas.d.ts +7 -0
  35. package/dist/input-schemas.js +58 -0
  36. package/dist/platform_event_manager.d.ts +15 -6
  37. package/dist/platform_event_manager.js +187 -41
  38. package/dist/proxy_configuration.d.ts +66 -59
  39. package/dist/proxy_configuration.js +172 -154
  40. package/dist/smart_apify_storage_backend.d.ts +52 -0
  41. package/dist/smart_apify_storage_backend.js +73 -0
  42. package/dist/storage.d.ts +38 -0
  43. package/dist/storage.js +1 -0
  44. package/dist/utils.d.ts +28 -4
  45. package/dist/utils.js +60 -20
  46. package/package.json +117 -73
  47. package/.turbo/turbo-build.log +0 -26
  48. package/.turbo/turbo-copy.log +0 -4
  49. package/dist/LICENSE.md +0 -201
  50. package/dist/README.md +0 -98
  51. package/dist/actor.d.ts.map +0 -1
  52. package/dist/actor.js.map +0 -1
  53. package/dist/charging.d.ts.map +0 -1
  54. package/dist/charging.js.map +0 -1
  55. package/dist/configuration.d.ts.map +0 -1
  56. package/dist/configuration.js.map +0 -1
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/key_value_store.d.ts +0 -17
  60. package/dist/key_value_store.d.ts.map +0 -1
  61. package/dist/key_value_store.js +0 -33
  62. package/dist/key_value_store.js.map +0 -1
  63. package/dist/package.json +0 -75
  64. package/dist/platform_event_manager.d.ts.map +0 -1
  65. package/dist/platform_event_manager.js.map +0 -1
  66. package/dist/proxy_configuration.d.ts.map +0 -1
  67. package/dist/proxy_configuration.js.map +0 -1
  68. package/dist/utils.d.ts.map +0 -1
  69. package/dist/utils.js.map +0 -1
@@ -1,74 +1,100 @@
1
- import type { ConfigurationOptions as CoreConfigurationOptions } from '@crawlee/core';
1
+ import type { ConfigField, FieldsInput, FieldsOutput } from '@crawlee/core';
2
2
  import { Configuration as CoreConfiguration } from '@crawlee/core';
3
- import type { META_ORIGINS } from '@apify/consts';
4
- export interface ConfigurationOptions extends CoreConfigurationOptions {
5
- metamorphAfterSleepMillis?: number;
6
- actorEventsWsUrl?: string;
7
- token?: string;
8
- actorId?: string;
9
- actorRunId?: string;
10
- actorTaskId?: string;
11
- apiBaseUrl?: string;
12
- apiPublicBaseUrl?: string;
13
- containerPort?: number;
14
- containerUrl?: string;
15
- proxyHostname?: string;
16
- proxyPassword?: string;
17
- proxyPort?: number;
18
- proxyStatusUrl?: string;
19
- /**
20
- * @deprecated use `containerPort` instead
21
- */
22
- standbyPort?: number;
23
- standbyUrl?: string;
24
- isAtHome?: boolean;
25
- userId?: string;
26
- inputSecretsPrivateKeyPassphrase?: string;
27
- inputSecretsPrivateKeyFile?: string;
28
- maxTotalChargeUsd?: number;
29
- metaOrigin?: (typeof META_ORIGINS)[keyof typeof META_ORIGINS];
30
- testPayPerEvent?: boolean;
31
- useChargingLogDataset?: boolean;
3
+ import { z } from 'zod';
4
+ export declare const apifyConfigFields: {
5
+ maxUsedCpuRatio: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
6
+ internalTimeoutMillis: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodNumber, unknown>>>;
7
+ systemInfoIntervalMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
8
+ logLevel: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodEnum<typeof import("@crawlee/core").LogLevel>, unknown>>>;
9
+ persistStorage: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
10
+ storageDir: ConfigField<z.ZodDefault<z.ZodString>>;
11
+ containerized: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
12
+ memoryMbytes: ConfigField<z.ZodOptional<z.ZodPreprocess<z.ZodNumber, unknown>>>;
13
+ availableMemoryRatio: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
14
+ disableBrowserSandbox: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
15
+ persistStateIntervalMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
16
+ headless: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
17
+ xvfb: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
18
+ chromeExecutablePath: ConfigField<z.ZodOptional<z.ZodString>>;
19
+ defaultBrowserPath: ConfigField<z.ZodOptional<z.ZodString>>;
20
+ purgeOnStart: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
21
+ defaultDatasetId: ConfigField<z.ZodDefault<z.ZodString>>;
22
+ defaultKeyValueStoreId: ConfigField<z.ZodDefault<z.ZodString>>;
23
+ defaultRequestQueueId: ConfigField<z.ZodDefault<z.ZodString>>;
24
+ inputKey: ConfigField<z.ZodDefault<z.ZodString>>;
25
+ metamorphAfterSleepMillis: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
26
+ actorEventsWsUrl: ConfigField<z.ZodOptional<z.ZodString>>;
27
+ token: ConfigField<z.ZodOptional<z.ZodString>>;
28
+ actorId: ConfigField<z.ZodOptional<z.ZodString>>;
29
+ actorRunId: ConfigField<z.ZodOptional<z.ZodString>>;
30
+ actorTaskId: ConfigField<z.ZodOptional<z.ZodString>>;
31
+ apiBaseUrl: ConfigField<z.ZodDefault<z.ZodString>>;
32
+ apiPublicBaseUrl: ConfigField<z.ZodDefault<z.ZodString>>;
33
+ containerPort: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
34
+ containerUrl: ConfigField<z.ZodDefault<z.ZodString>>;
35
+ proxyHostname: ConfigField<z.ZodDefault<z.ZodString>>;
36
+ proxyPassword: ConfigField<z.ZodOptional<z.ZodString>>;
37
+ proxyPort: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
38
+ proxyStatusUrl: ConfigField<z.ZodDefault<z.ZodString>>;
39
+ /** @deprecated use `containerPort` instead */
40
+ standbyPort: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodNumber, unknown>>>;
41
+ standbyUrl: ConfigField<z.ZodOptional<z.ZodString>>;
42
+ isAtHome: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
43
+ userId: ConfigField<z.ZodOptional<z.ZodString>>;
44
+ userIsPaying: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
45
+ actorPermissionLevel: ConfigField<z.ZodOptional<z.ZodString>>;
46
+ inputSecretsPrivateKeyPassphrase: ConfigField<z.ZodOptional<z.ZodString>>;
47
+ inputSecretsPrivateKeyFile: ConfigField<z.ZodOptional<z.ZodString>>;
48
+ maxTotalChargeUsd: ConfigField<z.ZodDefault<z.ZodPipe<z.ZodPreprocess<z.ZodNumber, unknown>, z.ZodTransform<number, number>>>>;
49
+ metaOrigin: ConfigField<z.ZodOptional<z.ZodString>>;
50
+ testPayPerEvent: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
51
+ useChargingLogDataset: ConfigField<z.ZodDefault<z.ZodPreprocess<z.ZodBoolean, unknown>>>;
52
+ actorPricingInfo: ConfigField<z.ZodOptional<z.ZodString>>;
53
+ chargedEventCounts: ConfigField<z.ZodOptional<z.ZodString>>;
54
+ actorStoragesJson: ConfigField<z.ZodOptional<z.ZodString>>;
55
+ storageClientOptions: ConfigField<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
56
+ };
57
+ export type ApifyConfigurationInput = FieldsInput<typeof apifyConfigFields>;
58
+ export type ApifyResolvedConfigValues = FieldsOutput<typeof apifyConfigFields>;
59
+ /** @deprecated Use {@link ApifyConfigurationInput} instead. */
60
+ export type ConfigurationOptions = ApifyConfigurationInput;
61
+ export interface Configuration extends ApifyResolvedConfigValues {
32
62
  }
33
63
  /**
34
64
  * `Configuration` is a value object holding the SDK configuration. We can use it in two ways:
35
65
  *
36
- * 1. When using `Actor` class, we can get the instance configuration via `sdk.config`
66
+ * 1. When using `Actor` class, we can get the instance configuration via `sdk.configuration`
37
67
  *
38
68
  * ```javascript
39
69
  * import { Actor } from 'apify';
40
- * import { BasicCrawler } from 'crawlee';
41
70
  *
42
71
  * const sdk = new Actor({ token: '123' });
43
- * console.log(sdk.config.get('token')); // '123'
44
- *
45
- * const crawler = new BasicCrawler({
46
- * // ... crawler options
47
- * }, sdk.config);
72
+ * console.log(sdk.configuration.token); // '123'
48
73
  * ```
49
74
  *
50
75
  * 2. To get the global configuration (singleton instance). It will respect the environment variables.
51
76
  *
52
77
  * ```javascript
53
- * import { BasicCrawler, Configuration } from 'crawlee';
54
- *
55
- * // Get the global configuration
56
- * const config = Configuration.getGlobalConfig();
57
- * // Set the 'persistStateIntervalMillis' option
58
- * // of global configuration to 30 seconds
59
- * config.set('persistStateIntervalMillis', 30_000);
78
+ * import { Configuration } from 'apify';
60
79
  *
61
- * // No need to pass the configuration to the crawler,
62
- * // as it's using the global configuration by default
63
- * const crawler = new BasicCrawler();
80
+ * const config = Configuration.getGlobalConfiguration();
81
+ * console.log(config.headless);
82
+ * console.log(config.persistStateIntervalMillis);
64
83
  * ```
65
84
  *
85
+ * Configuration is immutable — values are set via the constructor and cannot be changed afterwards.
86
+ * The priority order for resolving values is (highest to lowest):
87
+ *
88
+ * ```text
89
+ * constructor options > environment variables > crawlee.json > schema defaults
90
+ * ```
91
+ *
66
92
  * ## Supported Configuration Options
67
93
  *
68
94
  * Key | Environment Variable | Default Value
69
95
  * ---|---|---
70
96
  * `memoryMbytes` | `ACTOR_MEMORY_MBYTES` | -
71
- * `headless` | `APIFY_HEADLESS` | -
97
+ * `headless` | `APIFY_HEADLESS` | `true`
72
98
  * `persistStateIntervalMillis` | `APIFY_PERSIST_STATE_INTERVAL_MILLIS` | `60e3`
73
99
  * `token` | `APIFY_TOKEN` | -
74
100
  * `isAtHome` | `APIFY_IS_AT_HOME` | -
@@ -84,7 +110,7 @@ export interface ConfigurationOptions extends CoreConfigurationOptions {
84
110
  * `actorId` | `ACTOR_ID` | -
85
111
  * `actorRunId` | `ACTOR_RUN_ID` | -
86
112
  * `actorTaskId` | `ACTOR_TASK_ID` | -
87
- * `apiBaseUrl` | `APIFY_API_BASE_URL` | `'https://api.apify.com'`
113
+ * `apiBaseUrl` | `APIFY_API_BASE_URL` | `'https://api.apify.com/'`
88
114
  * `containerPort` | `ACTOR_WEB_SERVER_PORT` | `4321`
89
115
  * `containerUrl` | `ACTOR_WEB_SERVER_URL` | `'http://localhost:4321'`
90
116
  * `inputKey` | `ACTOR_INPUT_KEY` | `'INPUT'`
@@ -95,6 +121,7 @@ export interface ConfigurationOptions extends CoreConfigurationOptions {
95
121
  * `proxyPort` | `APIFY_PROXY_PORT` | `8000`
96
122
  * `proxyStatusUrl` | `APIFY_PROXY_STATUS_URL` | `'http://proxy.apify.com'`
97
123
  * `userId` | `APIFY_USER_ID` | -
124
+ * `userIsPaying` | `APIFY_USER_IS_PAYING` | `false`
98
125
  * `xvfb` | `APIFY_XVFB` | -
99
126
  * `standbyPort` | `ACTOR_STANDBY_PORT` | `4321`
100
127
  * `standbyUrl` | `ACTOR_STANDBY_URL` | -
@@ -102,95 +129,18 @@ export interface ConfigurationOptions extends CoreConfigurationOptions {
102
129
  * `defaultBrowserPath` | `APIFY_DEFAULT_BROWSER_PATH` | -
103
130
  */
104
131
  export declare class Configuration extends CoreConfiguration {
105
- /** @inheritDoc */
132
+ /** @internal */
106
133
  static globalConfig?: Configuration;
107
- protected static ENV_MAP: {
108
- APIFY_AVAILABLE_MEMORY_RATIO: string;
109
- APIFY_PURGE_ON_START: string;
110
- APIFY_MEMORY_MBYTES: string;
111
- APIFY_DEFAULT_DATASET_ID: string;
112
- APIFY_DEFAULT_KEY_VALUE_STORE_ID: string;
113
- APIFY_DEFAULT_REQUEST_QUEUE_ID: string;
114
- APIFY_INPUT_KEY: string;
115
- APIFY_PERSIST_STATE_INTERVAL_MILLIS: string;
116
- APIFY_HEADLESS: string;
117
- APIFY_XVFB: string;
118
- APIFY_CHROME_EXECUTABLE_PATH: string;
119
- APIFY_DEFAULT_BROWSER_PATH: string;
120
- APIFY_DISABLE_BROWSER_SANDBOX: string;
121
- APIFY_TOKEN: string;
122
- APIFY_METAMORPH_AFTER_SLEEP_MILLIS: string;
123
- APIFY_TEST_PERSIST_INTERVAL_MILLIS: string;
124
- APIFY_ACTOR_EVENTS_WS_URL: string;
125
- APIFY_ACTOR_ID: string;
126
- APIFY_API_BASE_URL: string;
127
- APIFY_API_PUBLIC_BASE_URL: string;
128
- APIFY_IS_AT_HOME: string;
129
- APIFY_ACTOR_RUN_ID: string;
130
- APIFY_ACTOR_TASK_ID: string;
131
- APIFY_CONTAINER_PORT: string;
132
- APIFY_CONTAINER_URL: string;
133
- APIFY_USER_ID: string;
134
- APIFY_PROXY_HOSTNAME: string;
135
- APIFY_PROXY_PASSWORD: string;
136
- APIFY_PROXY_STATUS_URL: string;
137
- APIFY_PROXY_PORT: string;
138
- APIFY_INPUT_SECRETS_PRIVATE_KEY_FILE: string;
139
- APIFY_INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE: string;
140
- APIFY_META_ORIGIN: string;
141
- ACTOR_DEFAULT_DATASET_ID: string;
142
- ACTOR_DEFAULT_KEY_VALUE_STORE_ID: string;
143
- ACTOR_DEFAULT_REQUEST_QUEUE_ID: string;
144
- ACTOR_EVENTS_WEBSOCKET_URL: string;
145
- ACTOR_ID: string;
146
- ACTOR_INPUT_KEY: string;
147
- ACTOR_MEMORY_MBYTES: string;
148
- ACTOR_RUN_ID: string;
149
- ACTOR_STANDBY_PORT: string;
150
- ACTOR_STANDBY_URL: string;
151
- ACTOR_TASK_ID: string;
152
- ACTOR_WEB_SERVER_PORT: string;
153
- ACTOR_WEB_SERVER_URL: string;
154
- ACTOR_MAX_TOTAL_CHARGE_USD: string;
155
- ACTOR_TEST_PAY_PER_EVENT: string;
156
- ACTOR_USE_CHARGING_LOG_DATASET: string;
157
- };
158
- protected static INTEGER_VARS: string[];
159
- protected static BOOLEAN_VARS: string[];
160
- protected static DEFAULTS: {
161
- defaultKeyValueStoreId: string;
162
- defaultDatasetId: string;
163
- defaultRequestQueueId: string;
164
- inputKey: string;
165
- apiBaseUrl: string;
166
- apiPublicBaseUrl: string;
167
- proxyStatusUrl: string;
168
- proxyHostname: string;
169
- proxyPort: number;
170
- containerPort: number;
171
- containerUrl: string;
172
- standbyPort: number;
173
- metamorphAfterSleepMillis: number;
174
- persistStateIntervalMillis: number;
175
- testPayPerEvent: boolean;
176
- useChargingLogDataset: boolean;
177
- };
178
- /**
179
- * @inheritDoc
180
- */
181
- get<T extends keyof ConfigurationOptions, U extends ConfigurationOptions[T]>(key: T, defaultValue?: U): U;
134
+ protected static fields: Record<string, ConfigField>;
135
+ constructor(options?: ApifyConfigurationInput);
182
136
  /**
183
137
  * @inheritDoc
138
+ *
139
+ * Returns the SDK's global {@link Configuration} singleton (an
140
+ * Apify-typed default that parses `APIFY_*` env vars). During an Actor run
141
+ * the active configuration is held by crawlee's `serviceLocator`, which is
142
+ * what crawlee internals resolve against; this singleton is only the
143
+ * fallback for code reaching for a configuration without an explicit one.
184
144
  */
185
- set(key: keyof ConfigurationOptions, value?: any): void;
186
- /**
187
- * @inheritDoc
188
- */
189
- static getGlobalConfig(): Configuration;
190
- /**
191
- * Resets global configuration instance. The default instance holds configuration based on env vars,
192
- * if we want to change them, we need to first reset the global state. Used mainly for testing purposes.
193
- */
194
- static resetGlobalState(): void;
145
+ static getGlobalConfiguration(): Configuration;
195
146
  }
196
- //# sourceMappingURL=configuration.d.ts.map
@@ -1,44 +1,143 @@
1
- import { Configuration as CoreConfiguration } from '@crawlee/core';
2
- import { ACTOR_ENV_VARS, APIFY_ENV_VARS, LOCAL_ACTOR_ENV_VARS, LOCAL_APIFY_ENV_VARS, } from '@apify/consts';
1
+ /* eslint-disable no-use-before-define */
2
+ import { coerceBoolean, coerceNumber, Configuration as CoreConfiguration, crawleeConfigFields, field, } from '@crawlee/core';
3
+ import { z } from 'zod';
4
+ import { ACTOR_ENV_VARS, APIFY_ENV_VARS, LOCAL_ACTOR_ENV_VARS, LOCAL_APIFY_ENV_VARS } from '@apify/consts';
5
+ // Evaluated lazily (per Configuration construction, not at import) so the
6
+ // at-home defaults for `availableMemoryRatio` / `disableBrowserSandbox` below
7
+ // react to `APIFY_IS_AT_HOME` even if it changes after import (tests, embedding).
8
+ // Reads the env var, not the resolved `isAtHome` field, so an explicit
9
+ // `new Configuration({ isAtHome: true })` won't flip these — env is the source.
10
+ const isAtHome = () => !!process.env[APIFY_ENV_VARS.IS_AT_HOME];
11
+ function withApifyEnv(base, apifyEnvVars, schema) {
12
+ const crawleeVars = base.envVar == null ? [] : [base.envVar].flat();
13
+ return field((schema ?? base.schema), [...[apifyEnvVars].flat(), ...crawleeVars]);
14
+ }
15
+ // --- Apify config field definitions ---
16
+ export const apifyConfigFields = {
17
+ // Inherit all crawlee fields as-is.
18
+ ...crawleeConfigFields,
19
+ // Crawlee fields the SDK extends with ACTOR_/APIFY_ env-var aliases (which
20
+ // take precedence; crawlee's own CRAWLEE_* var is reused as the fallback,
21
+ // never re-typed). A schema is passed only where the SDK needs a different
22
+ // default than crawlee's.
23
+ memoryMbytes: withApifyEnv(crawleeConfigFields.memoryMbytes, [
24
+ ACTOR_ENV_VARS.MEMORY_MBYTES,
25
+ APIFY_ENV_VARS.MEMORY_MBYTES,
26
+ ]),
27
+ availableMemoryRatio: withApifyEnv(crawleeConfigFields.availableMemoryRatio, 'APIFY_AVAILABLE_MEMORY_RATIO', coerceNumber.default(() => (isAtHome() ? 1 : 0.25))),
28
+ disableBrowserSandbox: withApifyEnv(crawleeConfigFields.disableBrowserSandbox, 'APIFY_DISABLE_BROWSER_SANDBOX', coerceBoolean.default(() => isAtHome())),
29
+ persistStateIntervalMillis: withApifyEnv(crawleeConfigFields.persistStateIntervalMillis, [
30
+ APIFY_ENV_VARS.PERSIST_STATE_INTERVAL_MILLIS,
31
+ 'APIFY_TEST_PERSIST_INTERVAL_MILLIS',
32
+ ]),
33
+ headless: withApifyEnv(crawleeConfigFields.headless, APIFY_ENV_VARS.HEADLESS),
34
+ xvfb: withApifyEnv(crawleeConfigFields.xvfb, APIFY_ENV_VARS.XVFB),
35
+ chromeExecutablePath: withApifyEnv(crawleeConfigFields.chromeExecutablePath, APIFY_ENV_VARS.CHROME_EXECUTABLE_PATH),
36
+ defaultBrowserPath: withApifyEnv(crawleeConfigFields.defaultBrowserPath, 'APIFY_DEFAULT_BROWSER_PATH'),
37
+ purgeOnStart: withApifyEnv(crawleeConfigFields.purgeOnStart, APIFY_ENV_VARS.PURGE_ON_START),
38
+ // Crawlee addresses the default storage by a reserved alias; on the platform
39
+ // each run gets real storage IDs, which the API calls need.
40
+ defaultDatasetId: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_DATASET_ID]), [
41
+ ACTOR_ENV_VARS.DEFAULT_DATASET_ID,
42
+ APIFY_ENV_VARS.DEFAULT_DATASET_ID,
43
+ ]),
44
+ defaultKeyValueStoreId: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID]), [
45
+ ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID,
46
+ APIFY_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID,
47
+ ]),
48
+ defaultRequestQueueId: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID]), [
49
+ ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID,
50
+ APIFY_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID,
51
+ ]),
52
+ // Apify-specific fields
53
+ // Crawlee has no notion of a run input; `CRAWLEE_INPUT_KEY` stays as the
54
+ // lowest-priority alias because the Apify CLI sets all three variables.
55
+ inputKey: field(z.string().default('INPUT'), [
56
+ ACTOR_ENV_VARS.INPUT_KEY,
57
+ APIFY_ENV_VARS.INPUT_KEY,
58
+ 'CRAWLEE_INPUT_KEY',
59
+ ]),
60
+ metamorphAfterSleepMillis: field(coerceNumber.default(300_000), APIFY_ENV_VARS.METAMORPH_AFTER_SLEEP_MILLIS),
61
+ actorEventsWsUrl: field(z.string().optional(), [
62
+ ACTOR_ENV_VARS.EVENTS_WEBSOCKET_URL,
63
+ APIFY_ENV_VARS.ACTOR_EVENTS_WS_URL,
64
+ ]),
65
+ token: field(z.string().optional(), APIFY_ENV_VARS.TOKEN),
66
+ actorId: field(z.string().optional(), [ACTOR_ENV_VARS.ID, APIFY_ENV_VARS.ACTOR_ID]),
67
+ actorRunId: field(z.string().optional(), [ACTOR_ENV_VARS.RUN_ID, APIFY_ENV_VARS.ACTOR_RUN_ID]),
68
+ actorTaskId: field(z.string().optional(), [ACTOR_ENV_VARS.TASK_ID, APIFY_ENV_VARS.ACTOR_TASK_ID]),
69
+ apiBaseUrl: field(z.string().default('https://api.apify.com/'), APIFY_ENV_VARS.API_BASE_URL),
70
+ apiPublicBaseUrl: field(z.string().default('https://api.apify.com'), APIFY_ENV_VARS.API_PUBLIC_BASE_URL),
71
+ containerPort: field(coerceNumber.default(+LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.WEB_SERVER_PORT]), [
72
+ ACTOR_ENV_VARS.WEB_SERVER_PORT,
73
+ APIFY_ENV_VARS.CONTAINER_PORT,
74
+ ]),
75
+ containerUrl: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.WEB_SERVER_URL]), [
76
+ ACTOR_ENV_VARS.WEB_SERVER_URL,
77
+ APIFY_ENV_VARS.CONTAINER_URL,
78
+ ]),
79
+ proxyHostname: field(z.string().default(LOCAL_APIFY_ENV_VARS[APIFY_ENV_VARS.PROXY_HOSTNAME]), APIFY_ENV_VARS.PROXY_HOSTNAME),
80
+ proxyPassword: field(z.string().optional(), APIFY_ENV_VARS.PROXY_PASSWORD),
81
+ proxyPort: field(coerceNumber.default(+LOCAL_APIFY_ENV_VARS[APIFY_ENV_VARS.PROXY_PORT]), APIFY_ENV_VARS.PROXY_PORT),
82
+ proxyStatusUrl: field(z.string().default('http://proxy.apify.com'), APIFY_ENV_VARS.PROXY_STATUS_URL),
83
+ /** @deprecated use `containerPort` instead */
84
+ standbyPort: field(coerceNumber.default(+LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.STANDBY_PORT]), ACTOR_ENV_VARS.STANDBY_PORT),
85
+ standbyUrl: field(z.string().optional(), ACTOR_ENV_VARS.STANDBY_URL),
86
+ isAtHome: field(coerceBoolean.default(false), APIFY_ENV_VARS.IS_AT_HOME),
87
+ userId: field(z.string().optional(), APIFY_ENV_VARS.USER_ID),
88
+ userIsPaying: field(coerceBoolean.default(false), APIFY_ENV_VARS.USER_IS_PAYING),
89
+ actorPermissionLevel: field(z.string().optional(), ACTOR_ENV_VARS.PERMISSION_LEVEL),
90
+ inputSecretsPrivateKeyPassphrase: field(z.string().optional(), APIFY_ENV_VARS.INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE),
91
+ inputSecretsPrivateKeyFile: field(z.string().optional(), APIFY_ENV_VARS.INPUT_SECRETS_PRIVATE_KEY_FILE),
92
+ // `0` is treated as "no limit" (mirrors the Apify platform contract).
93
+ maxTotalChargeUsd: field(coerceNumber.transform((val) => (val === 0 ? Infinity : val)).default(Infinity), ACTOR_ENV_VARS.MAX_TOTAL_CHARGE_USD),
94
+ metaOrigin: field(z.string().optional(), APIFY_ENV_VARS.META_ORIGIN),
95
+ testPayPerEvent: field(coerceBoolean.default(false), 'ACTOR_TEST_PAY_PER_EVENT'),
96
+ useChargingLogDataset: field(coerceBoolean.default(false), 'ACTOR_USE_CHARGING_LOG_DATASET'),
97
+ // Pay-per-event charging metadata injected by the platform (JSON strings).
98
+ actorPricingInfo: field(z.string().optional(), 'APIFY_ACTOR_PRICING_INFO'),
99
+ chargedEventCounts: field(z.string().optional(), 'APIFY_CHARGED_ACTOR_EVENT_COUNTS'),
100
+ actorStoragesJson: field(z.string().optional(), 'ACTOR_STORAGES_JSON'),
101
+ // Grab-bag of ApifyClient constructor options; the `storageDir` key is
102
+ // pulled out separately for local storage emulation, the rest is spread
103
+ // into `new ApifyClient({...})` in `Actor.newClient()`. No env var alias.
104
+ storageClientOptions: field(z.record(z.string(), z.unknown()).optional()),
105
+ };
3
106
  /**
4
107
  * `Configuration` is a value object holding the SDK configuration. We can use it in two ways:
5
108
  *
6
- * 1. When using `Actor` class, we can get the instance configuration via `sdk.config`
109
+ * 1. When using `Actor` class, we can get the instance configuration via `sdk.configuration`
7
110
  *
8
111
  * ```javascript
9
112
  * import { Actor } from 'apify';
10
- * import { BasicCrawler } from 'crawlee';
11
113
  *
12
114
  * const sdk = new Actor({ token: '123' });
13
- * console.log(sdk.config.get('token')); // '123'
14
- *
15
- * const crawler = new BasicCrawler({
16
- * // ... crawler options
17
- * }, sdk.config);
115
+ * console.log(sdk.configuration.token); // '123'
18
116
  * ```
19
117
  *
20
118
  * 2. To get the global configuration (singleton instance). It will respect the environment variables.
21
119
  *
22
120
  * ```javascript
23
- * import { BasicCrawler, Configuration } from 'crawlee';
121
+ * import { Configuration } from 'apify';
24
122
  *
25
- * // Get the global configuration
26
- * const config = Configuration.getGlobalConfig();
27
- * // Set the 'persistStateIntervalMillis' option
28
- * // of global configuration to 30 seconds
29
- * config.set('persistStateIntervalMillis', 30_000);
30
- *
31
- * // No need to pass the configuration to the crawler,
32
- * // as it's using the global configuration by default
33
- * const crawler = new BasicCrawler();
123
+ * const config = Configuration.getGlobalConfiguration();
124
+ * console.log(config.headless);
125
+ * console.log(config.persistStateIntervalMillis);
34
126
  * ```
35
127
  *
128
+ * Configuration is immutable — values are set via the constructor and cannot be changed afterwards.
129
+ * The priority order for resolving values is (highest to lowest):
130
+ *
131
+ * ```text
132
+ * constructor options > environment variables > crawlee.json > schema defaults
133
+ * ```
134
+ *
36
135
  * ## Supported Configuration Options
37
136
  *
38
137
  * Key | Environment Variable | Default Value
39
138
  * ---|---|---
40
139
  * `memoryMbytes` | `ACTOR_MEMORY_MBYTES` | -
41
- * `headless` | `APIFY_HEADLESS` | -
140
+ * `headless` | `APIFY_HEADLESS` | `true`
42
141
  * `persistStateIntervalMillis` | `APIFY_PERSIST_STATE_INTERVAL_MILLIS` | `60e3`
43
142
  * `token` | `APIFY_TOKEN` | -
44
143
  * `isAtHome` | `APIFY_IS_AT_HOME` | -
@@ -54,7 +153,7 @@ import { ACTOR_ENV_VARS, APIFY_ENV_VARS, LOCAL_ACTOR_ENV_VARS, LOCAL_APIFY_ENV_V
54
153
  * `actorId` | `ACTOR_ID` | -
55
154
  * `actorRunId` | `ACTOR_RUN_ID` | -
56
155
  * `actorTaskId` | `ACTOR_TASK_ID` | -
57
- * `apiBaseUrl` | `APIFY_API_BASE_URL` | `'https://api.apify.com'`
156
+ * `apiBaseUrl` | `APIFY_API_BASE_URL` | `'https://api.apify.com/'`
58
157
  * `containerPort` | `ACTOR_WEB_SERVER_PORT` | `4321`
59
158
  * `containerUrl` | `ACTOR_WEB_SERVER_URL` | `'http://localhost:4321'`
60
159
  * `inputKey` | `ACTOR_INPUT_KEY` | `'INPUT'`
@@ -65,143 +164,35 @@ import { ACTOR_ENV_VARS, APIFY_ENV_VARS, LOCAL_ACTOR_ENV_VARS, LOCAL_APIFY_ENV_V
65
164
  * `proxyPort` | `APIFY_PROXY_PORT` | `8000`
66
165
  * `proxyStatusUrl` | `APIFY_PROXY_STATUS_URL` | `'http://proxy.apify.com'`
67
166
  * `userId` | `APIFY_USER_ID` | -
167
+ * `userIsPaying` | `APIFY_USER_IS_PAYING` | `false`
68
168
  * `xvfb` | `APIFY_XVFB` | -
69
169
  * `standbyPort` | `ACTOR_STANDBY_PORT` | `4321`
70
170
  * `standbyUrl` | `ACTOR_STANDBY_URL` | -
71
171
  * `chromeExecutablePath` | `APIFY_CHROME_EXECUTABLE_PATH` | -
72
172
  * `defaultBrowserPath` | `APIFY_DEFAULT_BROWSER_PATH` | -
73
173
  */
174
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
74
175
  export class Configuration extends CoreConfiguration {
75
- /** @inheritDoc */
76
- // eslint-disable-next-line no-use-before-define -- Self-reference
176
+ /** @internal */
77
177
  static globalConfig;
78
- // maps environment variables to config keys (e.g. `APIFY_MEMORY_MBYTES` to `memoryMbytes`)
79
- static ENV_MAP = {
80
- // regular crawlee env vars are also supported
81
- ...CoreConfiguration.ENV_MAP,
82
- // support crawlee env vars prefixed with `APIFY_` too
83
- APIFY_AVAILABLE_MEMORY_RATIO: 'availableMemoryRatio',
84
- APIFY_PURGE_ON_START: 'purgeOnStart',
85
- APIFY_MEMORY_MBYTES: 'memoryMbytes',
86
- APIFY_DEFAULT_DATASET_ID: 'defaultDatasetId',
87
- APIFY_DEFAULT_KEY_VALUE_STORE_ID: 'defaultKeyValueStoreId',
88
- APIFY_DEFAULT_REQUEST_QUEUE_ID: 'defaultRequestQueueId',
89
- APIFY_INPUT_KEY: 'inputKey',
90
- APIFY_PERSIST_STATE_INTERVAL_MILLIS: 'persistStateIntervalMillis',
91
- APIFY_HEADLESS: 'headless',
92
- APIFY_XVFB: 'xvfb',
93
- APIFY_CHROME_EXECUTABLE_PATH: 'chromeExecutablePath',
94
- APIFY_DEFAULT_BROWSER_PATH: 'defaultBrowserPath',
95
- APIFY_DISABLE_BROWSER_SANDBOX: 'disableBrowserSandbox',
96
- // as well as apify specific ones
97
- APIFY_TOKEN: 'token',
98
- APIFY_METAMORPH_AFTER_SLEEP_MILLIS: 'metamorphAfterSleepMillis',
99
- APIFY_TEST_PERSIST_INTERVAL_MILLIS: 'persistStateIntervalMillis', // for BC, seems to be unused
100
- APIFY_ACTOR_EVENTS_WS_URL: 'actorEventsWsUrl',
101
- APIFY_ACTOR_ID: 'actorId',
102
- APIFY_API_BASE_URL: 'apiBaseUrl',
103
- APIFY_API_PUBLIC_BASE_URL: 'apiPublicBaseUrl',
104
- APIFY_IS_AT_HOME: 'isAtHome',
105
- APIFY_ACTOR_RUN_ID: 'actorRunId',
106
- APIFY_ACTOR_TASK_ID: 'actorTaskId',
107
- APIFY_CONTAINER_PORT: 'containerPort',
108
- APIFY_CONTAINER_URL: 'containerUrl',
109
- APIFY_USER_ID: 'userId',
110
- APIFY_PROXY_HOSTNAME: 'proxyHostname',
111
- APIFY_PROXY_PASSWORD: 'proxyPassword',
112
- APIFY_PROXY_STATUS_URL: 'proxyStatusUrl',
113
- APIFY_PROXY_PORT: 'proxyPort',
114
- APIFY_INPUT_SECRETS_PRIVATE_KEY_FILE: 'inputSecretsPrivateKeyFile',
115
- APIFY_INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE: 'inputSecretsPrivateKeyPassphrase',
116
- APIFY_META_ORIGIN: 'metaOrigin',
117
- // Actor env vars
118
- ACTOR_DEFAULT_DATASET_ID: 'defaultDatasetId',
119
- ACTOR_DEFAULT_KEY_VALUE_STORE_ID: 'defaultKeyValueStoreId',
120
- ACTOR_DEFAULT_REQUEST_QUEUE_ID: 'defaultRequestQueueId',
121
- ACTOR_EVENTS_WEBSOCKET_URL: 'actorEventsWsUrl',
122
- ACTOR_ID: 'actorId',
123
- ACTOR_INPUT_KEY: 'inputKey',
124
- ACTOR_MEMORY_MBYTES: 'memoryMbytes',
125
- ACTOR_RUN_ID: 'actorRunId',
126
- ACTOR_STANDBY_PORT: 'standbyPort',
127
- ACTOR_STANDBY_URL: 'standbyUrl',
128
- ACTOR_TASK_ID: 'actorTaskId',
129
- ACTOR_WEB_SERVER_PORT: 'containerPort',
130
- ACTOR_WEB_SERVER_URL: 'containerUrl',
131
- ACTOR_MAX_TOTAL_CHARGE_USD: 'maxTotalChargeUsd',
132
- ACTOR_TEST_PAY_PER_EVENT: 'testPayPerEvent',
133
- ACTOR_USE_CHARGING_LOG_DATASET: 'useChargingLogDataset',
134
- };
135
- static INTEGER_VARS = [
136
- ...CoreConfiguration.INTEGER_VARS,
137
- 'proxyPort',
138
- 'containerPort',
139
- 'metamorphAfterSleepMillis',
140
- 'maxTotalChargeUsd',
141
- ];
142
- static BOOLEAN_VARS = [
143
- ...CoreConfiguration.BOOLEAN_VARS,
144
- 'isAtHome',
145
- 'testPayPerEvent',
146
- 'useChargingLogDataset',
147
- ];
148
- static DEFAULTS = {
149
- ...CoreConfiguration.DEFAULTS,
150
- defaultKeyValueStoreId: LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID],
151
- defaultDatasetId: LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_DATASET_ID],
152
- defaultRequestQueueId: LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID],
153
- inputKey: 'INPUT',
154
- apiBaseUrl: 'https://api.apify.com',
155
- apiPublicBaseUrl: 'https://api.apify.com',
156
- proxyStatusUrl: 'http://proxy.apify.com',
157
- proxyHostname: LOCAL_APIFY_ENV_VARS[APIFY_ENV_VARS.PROXY_HOSTNAME],
158
- proxyPort: +LOCAL_APIFY_ENV_VARS[APIFY_ENV_VARS.PROXY_PORT],
159
- containerPort: +LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.WEB_SERVER_PORT],
160
- containerUrl: LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.WEB_SERVER_URL],
161
- standbyPort: +LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.STANDBY_PORT],
162
- metamorphAfterSleepMillis: 300e3,
163
- persistStateIntervalMillis: 60e3, // This value is mentioned in jsdoc in `events.js`, if you update it here, update it there too.
164
- testPayPerEvent: false,
165
- useChargingLogDataset: false,
166
- };
167
- /**
168
- * @inheritDoc
169
- */
170
- get(key, defaultValue) {
171
- return super.get(key, defaultValue);
178
+ static fields = apifyConfigFields;
179
+ constructor(options = {}) {
180
+ // `super` types its options against crawlee's field set; ours is a
181
+ // superset (apifyConfigFields spreads crawleeConfigFields), so the
182
+ // shapes are runtime-compatible but not TS-assignable — hence the cast.
183
+ super(options);
172
184
  }
173
185
  /**
174
186
  * @inheritDoc
187
+ *
188
+ * Returns the SDK's global {@link Configuration} singleton (an
189
+ * Apify-typed default that parses `APIFY_*` env vars). During an Actor run
190
+ * the active configuration is held by crawlee's `serviceLocator`, which is
191
+ * what crawlee internals resolve against; this singleton is only the
192
+ * fallback for code reaching for a configuration without an explicit one.
175
193
  */
176
- set(key, value) {
177
- super.set(key, value);
178
- }
179
- /**
180
- * @inheritDoc
181
- */
182
- static getGlobalConfig() {
183
- if (Configuration.storage.getStore()) {
184
- return Configuration.storage.getStore();
185
- }
194
+ static getGlobalConfiguration() {
186
195
  Configuration.globalConfig ??= new Configuration();
187
196
  return Configuration.globalConfig;
188
197
  }
189
- /**
190
- * Resets global configuration instance. The default instance holds configuration based on env vars,
191
- * if we want to change them, we need to first reset the global state. Used mainly for testing purposes.
192
- */
193
- static resetGlobalState() {
194
- delete this.globalConfig;
195
- }
196
198
  }
197
- // monkey patch the core class so it respects the new options too
198
- CoreConfiguration.getGlobalConfig = Configuration.getGlobalConfig;
199
- // @ts-expect-error protected property
200
- CoreConfiguration.ENV_MAP = Configuration.ENV_MAP;
201
- // @ts-expect-error protected property
202
- CoreConfiguration.INTEGER_VARS = Configuration.INTEGER_VARS;
203
- // @ts-expect-error protected property
204
- CoreConfiguration.BOOLEAN_VARS = Configuration.BOOLEAN_VARS;
205
- // @ts-expect-error protected property
206
- CoreConfiguration.DEFAULTS = Configuration.DEFAULTS;
207
- //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,29 @@
1
+ import type { RequestOptions } from '@crawlee/core';
2
+ /** Request options that the `globs` and `pseudoUrls` input editors can attach to a single URL pattern. */
3
+ export interface UrlPatternRequestOptions extends Pick<RequestOptions, 'method' | 'payload' | 'label' | 'userData' | 'headers'> {
4
+ }
5
+ /** A single item of an input schema array field using the `globs` editor. */
6
+ export interface GlobInput extends UrlPatternRequestOptions {
7
+ glob: string;
8
+ }
9
+ /** A single item of an input schema array field using the `pseudoUrls` editor. */
10
+ export interface PseudoUrlInput extends UrlPatternRequestOptions {
11
+ purl: string;
12
+ }
13
+ export interface UrlPatternFilters {
14
+ /** Value of an input schema field using the `globs` editor. */
15
+ globs?: readonly (string | GlobInput)[];
16
+ /** Value of an input schema field using the `pseudoUrls` editor. */
17
+ pseudoUrls?: readonly (string | PseudoUrlInput)[];
18
+ }
19
+ /**
20
+ * Turns the `globs` and `pseudoUrls` input editor values into a `transformRequestFunction` that skips requests
21
+ * matching no pattern (all requests pass when no pattern is given) and applies the options of the matched pattern.
22
+ * When a URL matches multiple patterns, the first one wins, with globs checked before pseudo-URLs. The matched
23
+ * pattern's options shallowly override the request's fields, including `userData` (no deep merge, like in v3).
24
+ *
25
+ * ```ts
26
+ * await enqueueLinks({ transformRequestFunction: createTransformRequestFunction({ globs: input.globs }) });
27
+ * ```
28
+ */
29
+ export declare function createTransformRequestFunction({ globs, pseudoUrls, }: UrlPatternFilters): (request: RequestOptions) => RequestOptions | false | 'unchanged';