apify 4.0.0-beta.14 → 4.0.0-beta.140
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 +28 -2
- package/dist/actor.d.ts +393 -281
- package/dist/actor.js +734 -417
- package/dist/apify_dataset_backend.d.ts +22 -0
- package/dist/apify_dataset_backend.js +77 -0
- package/dist/apify_file_system_storage_backend.d.ts +34 -0
- package/dist/apify_file_system_storage_backend.js +41 -0
- package/dist/apify_key_value_store_backend.d.ts +26 -0
- package/dist/apify_key_value_store_backend.js +57 -0
- package/dist/apify_request_queue_backend.d.ts +81 -0
- package/dist/apify_request_queue_backend.js +110 -0
- package/dist/apify_request_queue_shared_backend.d.ts +31 -0
- package/dist/apify_request_queue_shared_backend.js +193 -0
- package/dist/apify_request_queue_single_backend.d.ts +43 -0
- package/dist/apify_request_queue_single_backend.js +256 -0
- package/dist/apify_storage_backend.d.ts +90 -0
- package/dist/apify_storage_backend.js +210 -0
- package/dist/charging.d.ts +69 -47
- package/dist/charging.js +321 -223
- package/dist/charging_storage_backend.d.ts +53 -0
- package/dist/charging_storage_backend.js +109 -0
- package/dist/child_run_tracker.d.ts +88 -0
- package/dist/child_run_tracker.js +239 -0
- package/dist/configuration.d.ts +48 -28
- package/dist/configuration.js +67 -13
- package/dist/enqueue_links_filters.d.ts +29 -0
- package/dist/enqueue_links_filters.js +52 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +22 -0
- package/dist/google_sheets.d.ts +12 -0
- package/dist/google_sheets.js +26 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +8 -3
- package/dist/input-schemas.d.ts +1 -1
- package/dist/platform_event_manager.d.ts +24 -9
- package/dist/platform_event_manager.js +213 -43
- package/dist/proxy_configuration.d.ts +31 -21
- package/dist/proxy_configuration.js +136 -79
- package/dist/smart_apify_storage_backend.d.ts +52 -0
- package/dist/smart_apify_storage_backend.js +73 -0
- package/dist/storage.d.ts +6 -26
- package/dist/storage.js +1 -79
- package/dist/utils.d.ts +28 -3
- package/dist/utils.js +59 -17
- package/package.json +38 -44
- package/dist/apify_storage_client.d.ts +0 -54
- package/dist/apify_storage_client.js +0 -152
- package/dist/key_value_store.d.ts +0 -21
- package/dist/key_value_store.js +0 -41
package/dist/configuration.js
CHANGED
|
@@ -8,6 +8,22 @@ import { ACTOR_ENV_VARS, APIFY_ENV_VARS, LOCAL_ACTOR_ENV_VARS, LOCAL_APIFY_ENV_V
|
|
|
8
8
|
// Reads the env var, not the resolved `isAtHome` field, so an explicit
|
|
9
9
|
// `new Configuration({ isAtHome: true })` won't flip these — env is the source.
|
|
10
10
|
const isAtHome = () => !!process.env[APIFY_ENV_VARS.IS_AT_HOME];
|
|
11
|
+
// Zod preprocessors for the Apify-specific field types; crawlee's
|
|
12
|
+
// `coerceBoolean` / `coerceNumber` cover the rest.
|
|
13
|
+
const coerceDate = z.preprocess((val) => {
|
|
14
|
+
if (typeof val === 'string')
|
|
15
|
+
return new Date(Date.parse(val));
|
|
16
|
+
return val;
|
|
17
|
+
}, z.date());
|
|
18
|
+
const coerceStringList = z.preprocess((val) => {
|
|
19
|
+
if (typeof val === 'string') {
|
|
20
|
+
return val
|
|
21
|
+
.split(',')
|
|
22
|
+
.map((item) => item.trim())
|
|
23
|
+
.filter(Boolean);
|
|
24
|
+
}
|
|
25
|
+
return val;
|
|
26
|
+
}, z.array(z.string()));
|
|
11
27
|
function withApifyEnv(base, apifyEnvVars, schema) {
|
|
12
28
|
const crawleeVars = base.envVar == null ? [] : [base.envVar].flat();
|
|
13
29
|
return field((schema ?? base.schema), [...[apifyEnvVars].flat(), ...crawleeVars]);
|
|
@@ -20,16 +36,12 @@ export const apifyConfigFields = {
|
|
|
20
36
|
// take precedence; crawlee's own CRAWLEE_* var is reused as the fallback,
|
|
21
37
|
// never re-typed). A schema is passed only where the SDK needs a different
|
|
22
38
|
// default than crawlee's.
|
|
23
|
-
defaultDatasetId: withApifyEnv(crawleeConfigFields.defaultDatasetId, [ACTOR_ENV_VARS.DEFAULT_DATASET_ID, APIFY_ENV_VARS.DEFAULT_DATASET_ID], z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_DATASET_ID])),
|
|
24
|
-
defaultKeyValueStoreId: withApifyEnv(crawleeConfigFields.defaultKeyValueStoreId, [ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID, APIFY_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID], z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID])),
|
|
25
|
-
defaultRequestQueueId: withApifyEnv(crawleeConfigFields.defaultRequestQueueId, [ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID, APIFY_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID], z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID])),
|
|
26
|
-
inputKey: withApifyEnv(crawleeConfigFields.inputKey, [ACTOR_ENV_VARS.INPUT_KEY, APIFY_ENV_VARS.INPUT_KEY]),
|
|
27
39
|
memoryMbytes: withApifyEnv(crawleeConfigFields.memoryMbytes, [
|
|
28
40
|
ACTOR_ENV_VARS.MEMORY_MBYTES,
|
|
29
41
|
APIFY_ENV_VARS.MEMORY_MBYTES,
|
|
30
42
|
]),
|
|
31
43
|
availableMemoryRatio: withApifyEnv(crawleeConfigFields.availableMemoryRatio, 'APIFY_AVAILABLE_MEMORY_RATIO', coerceNumber.default(() => (isAtHome() ? 1 : 0.25))),
|
|
32
|
-
disableBrowserSandbox: withApifyEnv(crawleeConfigFields.disableBrowserSandbox, 'APIFY_DISABLE_BROWSER_SANDBOX', coerceBoolean.
|
|
44
|
+
disableBrowserSandbox: withApifyEnv(crawleeConfigFields.disableBrowserSandbox, 'APIFY_DISABLE_BROWSER_SANDBOX', coerceBoolean.default(() => isAtHome())),
|
|
33
45
|
persistStateIntervalMillis: withApifyEnv(crawleeConfigFields.persistStateIntervalMillis, [
|
|
34
46
|
APIFY_ENV_VARS.PERSIST_STATE_INTERVAL_MILLIS,
|
|
35
47
|
'APIFY_TEST_PERSIST_INTERVAL_MILLIS',
|
|
@@ -39,7 +51,28 @@ export const apifyConfigFields = {
|
|
|
39
51
|
chromeExecutablePath: withApifyEnv(crawleeConfigFields.chromeExecutablePath, APIFY_ENV_VARS.CHROME_EXECUTABLE_PATH),
|
|
40
52
|
defaultBrowserPath: withApifyEnv(crawleeConfigFields.defaultBrowserPath, 'APIFY_DEFAULT_BROWSER_PATH'),
|
|
41
53
|
purgeOnStart: withApifyEnv(crawleeConfigFields.purgeOnStart, APIFY_ENV_VARS.PURGE_ON_START),
|
|
54
|
+
// Crawlee addresses the default storage by a reserved alias; on the platform
|
|
55
|
+
// each run gets real storage IDs, which the API calls need.
|
|
56
|
+
defaultDatasetId: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_DATASET_ID]), [
|
|
57
|
+
ACTOR_ENV_VARS.DEFAULT_DATASET_ID,
|
|
58
|
+
APIFY_ENV_VARS.DEFAULT_DATASET_ID,
|
|
59
|
+
]),
|
|
60
|
+
defaultKeyValueStoreId: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID]), [
|
|
61
|
+
ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID,
|
|
62
|
+
APIFY_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID,
|
|
63
|
+
]),
|
|
64
|
+
defaultRequestQueueId: field(z.string().default(LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID]), [
|
|
65
|
+
ACTOR_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID,
|
|
66
|
+
APIFY_ENV_VARS.DEFAULT_REQUEST_QUEUE_ID,
|
|
67
|
+
]),
|
|
42
68
|
// Apify-specific fields
|
|
69
|
+
// Crawlee has no notion of a run input; `CRAWLEE_INPUT_KEY` stays as the
|
|
70
|
+
// lowest-priority alias because the Apify CLI sets all three variables.
|
|
71
|
+
inputKey: field(z.string().default('INPUT'), [
|
|
72
|
+
ACTOR_ENV_VARS.INPUT_KEY,
|
|
73
|
+
APIFY_ENV_VARS.INPUT_KEY,
|
|
74
|
+
'CRAWLEE_INPUT_KEY',
|
|
75
|
+
]),
|
|
43
76
|
metamorphAfterSleepMillis: field(coerceNumber.default(300_000), APIFY_ENV_VARS.METAMORPH_AFTER_SLEEP_MILLIS),
|
|
44
77
|
actorEventsWsUrl: field(z.string().optional(), [
|
|
45
78
|
ACTOR_ENV_VARS.EVENTS_WEBSOCKET_URL,
|
|
@@ -49,7 +82,19 @@ export const apifyConfigFields = {
|
|
|
49
82
|
actorId: field(z.string().optional(), [ACTOR_ENV_VARS.ID, APIFY_ENV_VARS.ACTOR_ID]),
|
|
50
83
|
actorRunId: field(z.string().optional(), [ACTOR_ENV_VARS.RUN_ID, APIFY_ENV_VARS.ACTOR_RUN_ID]),
|
|
51
84
|
actorTaskId: field(z.string().optional(), [ACTOR_ENV_VARS.TASK_ID, APIFY_ENV_VARS.ACTOR_TASK_ID]),
|
|
52
|
-
|
|
85
|
+
actorBuildId: field(z.string().optional(), [ACTOR_ENV_VARS.BUILD_ID, APIFY_ENV_VARS.ACTOR_BUILD_ID]),
|
|
86
|
+
actorBuildNumber: field(z.string().optional(), [ACTOR_ENV_VARS.BUILD_NUMBER, APIFY_ENV_VARS.ACTOR_BUILD_NUMBER]),
|
|
87
|
+
actorBuildTags: field(coerceStringList.optional(), ACTOR_ENV_VARS.BUILD_TAGS),
|
|
88
|
+
actorFullName: field(z.string().optional(), ACTOR_ENV_VARS.FULL_NAME),
|
|
89
|
+
workflowKey: field(z.string().optional(), APIFY_ENV_VARS.WORKFLOW_KEY),
|
|
90
|
+
startedAt: field(coerceDate.optional(), [ACTOR_ENV_VARS.STARTED_AT, APIFY_ENV_VARS.STARTED_AT]),
|
|
91
|
+
timeoutAt: field(coerceDate.optional(), [ACTOR_ENV_VARS.TIMEOUT_AT, APIFY_ENV_VARS.TIMEOUT_AT]),
|
|
92
|
+
maxPaidDatasetItems: field(coerceNumber.optional(), [
|
|
93
|
+
ACTOR_ENV_VARS.MAX_PAID_DATASET_ITEMS,
|
|
94
|
+
APIFY_ENV_VARS.ACTOR_MAX_PAID_DATASET_ITEMS,
|
|
95
|
+
]),
|
|
96
|
+
dedicatedCpus: field(coerceNumber.optional(), APIFY_ENV_VARS.DEDICATED_CPUS),
|
|
97
|
+
apiBaseUrl: field(z.string().default('https://api.apify.com/'), APIFY_ENV_VARS.API_BASE_URL),
|
|
53
98
|
apiPublicBaseUrl: field(z.string().default('https://api.apify.com'), APIFY_ENV_VARS.API_PUBLIC_BASE_URL),
|
|
54
99
|
containerPort: field(coerceNumber.default(+LOCAL_ACTOR_ENV_VARS[ACTOR_ENV_VARS.WEB_SERVER_PORT]), [
|
|
55
100
|
ACTOR_ENV_VARS.WEB_SERVER_PORT,
|
|
@@ -68,7 +113,7 @@ export const apifyConfigFields = {
|
|
|
68
113
|
standbyUrl: field(z.string().optional(), ACTOR_ENV_VARS.STANDBY_URL),
|
|
69
114
|
isAtHome: field(coerceBoolean.default(false), APIFY_ENV_VARS.IS_AT_HOME),
|
|
70
115
|
userId: field(z.string().optional(), APIFY_ENV_VARS.USER_ID),
|
|
71
|
-
userIsPaying: field(
|
|
116
|
+
userIsPaying: field(coerceBoolean.default(false), APIFY_ENV_VARS.USER_IS_PAYING),
|
|
72
117
|
actorPermissionLevel: field(z.string().optional(), ACTOR_ENV_VARS.PERMISSION_LEVEL),
|
|
73
118
|
inputSecretsPrivateKeyPassphrase: field(z.string().optional(), APIFY_ENV_VARS.INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE),
|
|
74
119
|
inputSecretsPrivateKeyFile: field(z.string().optional(), APIFY_ENV_VARS.INPUT_SECRETS_PRIVATE_KEY_FILE),
|
|
@@ -76,7 +121,6 @@ export const apifyConfigFields = {
|
|
|
76
121
|
maxTotalChargeUsd: field(coerceNumber.transform((val) => (val === 0 ? Infinity : val)).default(Infinity), ACTOR_ENV_VARS.MAX_TOTAL_CHARGE_USD),
|
|
77
122
|
metaOrigin: field(z.string().optional(), APIFY_ENV_VARS.META_ORIGIN),
|
|
78
123
|
testPayPerEvent: field(coerceBoolean.default(false), 'ACTOR_TEST_PAY_PER_EVENT'),
|
|
79
|
-
useChargingLogDataset: field(coerceBoolean.default(false), 'ACTOR_USE_CHARGING_LOG_DATASET'),
|
|
80
124
|
// Pay-per-event charging metadata injected by the platform (JSON strings).
|
|
81
125
|
actorPricingInfo: field(z.string().optional(), 'APIFY_ACTOR_PRICING_INFO'),
|
|
82
126
|
chargedEventCounts: field(z.string().optional(), 'APIFY_CHARGED_ACTOR_EVENT_COUNTS'),
|
|
@@ -89,13 +133,13 @@ export const apifyConfigFields = {
|
|
|
89
133
|
/**
|
|
90
134
|
* `Configuration` is a value object holding the SDK configuration. We can use it in two ways:
|
|
91
135
|
*
|
|
92
|
-
* 1. When using `Actor` class, we can get the instance configuration via `sdk.
|
|
136
|
+
* 1. When using `Actor` class, we can get the instance configuration via `sdk.configuration`
|
|
93
137
|
*
|
|
94
138
|
* ```javascript
|
|
95
139
|
* import { Actor } from 'apify';
|
|
96
140
|
*
|
|
97
141
|
* const sdk = new Actor({ token: '123' });
|
|
98
|
-
* console.log(sdk.
|
|
142
|
+
* console.log(sdk.configuration.token); // '123'
|
|
99
143
|
* ```
|
|
100
144
|
*
|
|
101
145
|
* 2. To get the global configuration (singleton instance). It will respect the environment variables.
|
|
@@ -103,7 +147,7 @@ export const apifyConfigFields = {
|
|
|
103
147
|
* ```javascript
|
|
104
148
|
* import { Configuration } from 'apify';
|
|
105
149
|
*
|
|
106
|
-
* const config = Configuration.
|
|
150
|
+
* const config = Configuration.getGlobalConfiguration();
|
|
107
151
|
* console.log(config.headless);
|
|
108
152
|
* console.log(config.persistStateIntervalMillis);
|
|
109
153
|
* ```
|
|
@@ -136,7 +180,16 @@ export const apifyConfigFields = {
|
|
|
136
180
|
* `actorId` | `ACTOR_ID` | -
|
|
137
181
|
* `actorRunId` | `ACTOR_RUN_ID` | -
|
|
138
182
|
* `actorTaskId` | `ACTOR_TASK_ID` | -
|
|
139
|
-
* `
|
|
183
|
+
* `actorBuildId` | `ACTOR_BUILD_ID` | -
|
|
184
|
+
* `actorBuildNumber` | `ACTOR_BUILD_NUMBER` | -
|
|
185
|
+
* `actorBuildTags` | `ACTOR_BUILD_TAGS` | -
|
|
186
|
+
* `actorFullName` | `ACTOR_FULL_NAME` | -
|
|
187
|
+
* `workflowKey` | `APIFY_WORKFLOW_KEY` | -
|
|
188
|
+
* `startedAt` | `ACTOR_STARTED_AT` | -
|
|
189
|
+
* `timeoutAt` | `ACTOR_TIMEOUT_AT` | -
|
|
190
|
+
* `maxPaidDatasetItems` | `ACTOR_MAX_PAID_DATASET_ITEMS` | -
|
|
191
|
+
* `dedicatedCpus` | `APIFY_DEDICATED_CPUS` | -
|
|
192
|
+
* `apiBaseUrl` | `APIFY_API_BASE_URL` | `'https://api.apify.com/'`
|
|
140
193
|
* `containerPort` | `ACTOR_WEB_SERVER_PORT` | `4321`
|
|
141
194
|
* `containerUrl` | `ACTOR_WEB_SERVER_URL` | `'http://localhost:4321'`
|
|
142
195
|
* `inputKey` | `ACTOR_INPUT_KEY` | `'INPUT'`
|
|
@@ -147,6 +200,7 @@ export const apifyConfigFields = {
|
|
|
147
200
|
* `proxyPort` | `APIFY_PROXY_PORT` | `8000`
|
|
148
201
|
* `proxyStatusUrl` | `APIFY_PROXY_STATUS_URL` | `'http://proxy.apify.com'`
|
|
149
202
|
* `userId` | `APIFY_USER_ID` | -
|
|
203
|
+
* `userIsPaying` | `APIFY_USER_IS_PAYING` | `false`
|
|
150
204
|
* `xvfb` | `APIFY_XVFB` | -
|
|
151
205
|
* `standbyPort` | `ACTOR_STANDBY_PORT` | `4321`
|
|
152
206
|
* `standbyUrl` | `ACTOR_STANDBY_URL` | -
|
|
@@ -173,7 +227,7 @@ export class Configuration extends CoreConfiguration {
|
|
|
173
227
|
* what crawlee internals resolve against; this singleton is only the
|
|
174
228
|
* fallback for code reaching for a configuration without an explicit one.
|
|
175
229
|
*/
|
|
176
|
-
static
|
|
230
|
+
static getGlobalConfiguration() {
|
|
177
231
|
Configuration.globalConfig ??= new Configuration();
|
|
178
232
|
return Configuration.globalConfig;
|
|
179
233
|
}
|
|
@@ -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';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Minimatch } from 'minimatch';
|
|
2
|
+
import { purlToRegExp } from '@apify/pseudo_url';
|
|
3
|
+
/**
|
|
4
|
+
* Turns the `globs` and `pseudoUrls` input editor values into a `transformRequestFunction` that skips requests
|
|
5
|
+
* matching no pattern (all requests pass when no pattern is given) and applies the options of the matched pattern.
|
|
6
|
+
* When a URL matches multiple patterns, the first one wins, with globs checked before pseudo-URLs. The matched
|
|
7
|
+
* pattern's options shallowly override the request's fields, including `userData` (no deep merge, like in v3).
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* await enqueueLinks({ transformRequestFunction: createTransformRequestFunction({ globs: input.globs }) });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function createTransformRequestFunction({ globs = [], pseudoUrls = [], }) {
|
|
14
|
+
const patterns = [
|
|
15
|
+
...globs.flatMap((item) => {
|
|
16
|
+
if (item == null) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const { glob, ...options } = typeof item === 'string' ? { glob: item } : item;
|
|
20
|
+
const trimmedGlob = typeof glob === 'string' ? glob.trim() : '';
|
|
21
|
+
if (trimmedGlob.length === 0) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const minimatch = new Minimatch(trimmedGlob, { nocase: true });
|
|
25
|
+
return [{ matches: (url) => minimatch.match(url), options }];
|
|
26
|
+
}),
|
|
27
|
+
...pseudoUrls.flatMap((item) => {
|
|
28
|
+
if (item == null) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const { purl, ...options } = typeof item === 'string' ? { purl: item } : item;
|
|
32
|
+
if (typeof purl !== 'string' || purl.trim().length === 0) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
let regexp;
|
|
36
|
+
try {
|
|
37
|
+
regexp = purlToRegExp(purl);
|
|
38
|
+
}
|
|
39
|
+
catch (cause) {
|
|
40
|
+
throw new Error(`Invalid pseudoUrl pattern '${purl}': ${cause.message}`, { cause });
|
|
41
|
+
}
|
|
42
|
+
return [{ matches: (url) => regexp.test(url), options }];
|
|
43
|
+
}),
|
|
44
|
+
];
|
|
45
|
+
if (patterns.length === 0) {
|
|
46
|
+
return () => 'unchanged';
|
|
47
|
+
}
|
|
48
|
+
return (request) => {
|
|
49
|
+
const matched = patterns.find(({ matches }) => matches(request.url));
|
|
50
|
+
return matched ? { ...request, ...matched.options } : false;
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Why {@link Actor.getInput} could not produce the input. */
|
|
2
|
+
export type ActorInputErrorCode =
|
|
3
|
+
/** No input record in the default key-value store, and locally no input file either. */
|
|
4
|
+
'NOT_FOUND'
|
|
5
|
+
/** The input is in more than one place — both `<inputKey>` and `<inputKey>.json` in one directory, or in the store and in the working directory — so none is picked. */
|
|
6
|
+
| 'MULTIPLE_FILES'
|
|
7
|
+
/** The secret fields of the input could not be decrypted; `cause` holds the underlying error. */
|
|
8
|
+
| 'DECRYPTION_FAILED'
|
|
9
|
+
/** A JSON input record or file does not parse; `cause` holds the parser error. */
|
|
10
|
+
| 'PARSE_FAILED';
|
|
11
|
+
/**
|
|
12
|
+
* Thrown by {@link Actor.getInput} when the Actor input cannot be produced. `code` says why, and
|
|
13
|
+
* `cause` carries the underlying error where there is one. Anything else thrown by `getInput()`, such as
|
|
14
|
+
* an Apify API error, is not an input problem and is passed through as is.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* try {
|
|
18
|
+
* input = await Actor.getInput();
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* if (!(error instanceof ActorInputError) || error.code !== 'NOT_FOUND') throw error;
|
|
21
|
+
* input = {};
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class ActorInputError extends Error {
|
|
26
|
+
readonly name = "ActorInputError";
|
|
27
|
+
readonly code: ActorInputErrorCode;
|
|
28
|
+
constructor(code: ActorInputErrorCode, message: string, options?: {
|
|
29
|
+
cause?: unknown;
|
|
30
|
+
});
|
|
31
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown by {@link Actor.getInput} when the Actor input cannot be produced. `code` says why, and
|
|
3
|
+
* `cause` carries the underlying error where there is one. Anything else thrown by `getInput()`, such as
|
|
4
|
+
* an Apify API error, is not an input problem and is passed through as is.
|
|
5
|
+
*
|
|
6
|
+
* ```js
|
|
7
|
+
* try {
|
|
8
|
+
* input = await Actor.getInput();
|
|
9
|
+
* } catch (error) {
|
|
10
|
+
* if (!(error instanceof ActorInputError) || error.code !== 'NOT_FOUND') throw error;
|
|
11
|
+
* input = {};
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class ActorInputError extends Error {
|
|
16
|
+
name = 'ActorInputError';
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message, options) {
|
|
19
|
+
super(message, options);
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Dictionary } from '@crawlee/types';
|
|
2
|
+
/**
|
|
3
|
+
* Turns a Google Sheets sharing link into the link of its CSV export, other URLs are returned unchanged.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare function toGoogleSheetsCsvUrl(url: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Replaces Google Sheets sharing links in the `requestsFromUrl` entries of the input's array fields (as produced by
|
|
9
|
+
* the "Link remote text file" option of the `requestListSources` editor) with the links of their CSV exports.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function fixGoogleSheetsUrls<T extends Dictionary>(input: T): T;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Links published to the web (`/spreadsheets/d/e/<id>/pub?output=csv`) and links that already point at an export
|
|
2
|
+
// (`/gviz/...`, `/export...`) are downloadable as they are, so they're left alone.
|
|
3
|
+
const GOOGLE_SHEETS_URL_REGEX = /^(https:\/\/docs\.google\.com\/spreadsheets\/d\/(?!e\/)(?:\w|-)+)(\/(?:gviz|export)\b)?/;
|
|
4
|
+
/**
|
|
5
|
+
* Turns a Google Sheets sharing link into the link of its CSV export, other URLs are returned unchanged.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function toGoogleSheetsCsvUrl(url) {
|
|
9
|
+
const match = GOOGLE_SHEETS_URL_REGEX.exec(url);
|
|
10
|
+
return match && !match[2] ? `${match[1]}/gviz/tq?tqx=out:csv` : url;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Replaces Google Sheets sharing links in the `requestsFromUrl` entries of the input's array fields (as produced by
|
|
14
|
+
* the "Link remote text file" option of the `requestListSources` editor) with the links of their CSV exports.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function fixGoogleSheetsUrls(input) {
|
|
18
|
+
return Object.fromEntries(Object.entries(input).map(([key, value]) => [
|
|
19
|
+
key,
|
|
20
|
+
Array.isArray(value)
|
|
21
|
+
? value.map((item) => typeof item?.requestsFromUrl === 'string'
|
|
22
|
+
? { ...item, requestsFromUrl: toGoogleSheetsCsvUrl(item.requestsFromUrl) }
|
|
23
|
+
: item)
|
|
24
|
+
: value,
|
|
25
|
+
]));
|
|
26
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export * from './actor.js';
|
|
2
|
-
export
|
|
2
|
+
export { ApifyStorageBackend, type ApifyStorageBackendOptions } from './apify_storage_backend.js';
|
|
3
|
+
export { ApifyFileSystemStorageBackend, type ApifyFileSystemStorageOptions, } from './apify_file_system_storage_backend.js';
|
|
4
|
+
export type { ApifyDatasetInfo } from './apify_dataset_backend.js';
|
|
5
|
+
export type { ApifyKeyValueStoreInfo } from './apify_key_value_store_backend.js';
|
|
6
|
+
export type { ApifyRequestQueueInfo, RequestQueueAccessMode } from './apify_request_queue_backend.js';
|
|
7
|
+
export { ArgumentValidationError } from './utils.js';
|
|
8
|
+
export { ActorInputError, type ActorInputErrorCode } from './errors.js';
|
|
9
|
+
export { createTransformRequestFunction, type GlobInput, type PseudoUrlInput, type UrlPatternFilters, type UrlPatternRequestOptions, } from './enqueue_links_filters.js';
|
|
10
|
+
export type { OpenStorageOptions, StorageAlias, StorageId, StorageName, StorageIdentifier } from './storage.js';
|
|
3
11
|
export { ChargeOptions, ChargeResult, ActorPricingInfo, ChargingManager } from './charging.js';
|
|
4
12
|
export * from './configuration.js';
|
|
5
13
|
export * from './proxy_configuration.js';
|
|
6
14
|
export * from './platform_event_manager.js';
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
15
|
+
export { Dataset, DatasetDataOptions, DatasetIteratorOptions, DatasetConsumer, DatasetMapper, DatasetReducer, DatasetOptions, DatasetContent, RequestQueue, RequestQueueOperationOptions, RequestQueueOptions, KeyValueStore, KeyConsumer, KeyValueStoreOptions, RecordOptions, KeyValueStoreIteratorOptions, log, Log, LoggerOptions, LogLevel, Logger, LoggerJson, LoggerText, } from '@crawlee/core';
|
|
16
|
+
export type { QueueOperationInfo } from '@crawlee/types';
|
|
17
|
+
export { ACTOR_ENV_VARS, APIFY_ENV_VARS } from '@apify/consts';
|
|
18
|
+
export { ApifyClient, ApifyClientOptions, ApifyClientError, ApifyApiError, InvalidRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, RateLimitError, ServerError, InvalidResponseBodyError, ResponseValidationError, } from 'apify-client';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export * from './actor.js';
|
|
2
|
+
export { ApifyStorageBackend } from './apify_storage_backend.js';
|
|
3
|
+
export { ApifyFileSystemStorageBackend, } from './apify_file_system_storage_backend.js';
|
|
4
|
+
export { ArgumentValidationError } from './utils.js';
|
|
5
|
+
export { ActorInputError } from './errors.js';
|
|
6
|
+
export { createTransformRequestFunction, } from './enqueue_links_filters.js';
|
|
2
7
|
export { ChargingManager } from './charging.js';
|
|
3
8
|
export * from './configuration.js';
|
|
4
9
|
export * from './proxy_configuration.js';
|
|
5
10
|
export * from './platform_event_manager.js';
|
|
6
|
-
export
|
|
7
|
-
export {
|
|
8
|
-
export { ApifyClient } from 'apify-client';
|
|
11
|
+
export { Dataset, RequestQueue, KeyValueStore, log, Log, LogLevel, Logger, LoggerJson, LoggerText, } from '@crawlee/core';
|
|
12
|
+
export { ACTOR_ENV_VARS, APIFY_ENV_VARS } from '@apify/consts';
|
|
13
|
+
export { ApifyClient, ApifyClientError, ApifyApiError, InvalidRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, RateLimitError, ServerError, InvalidResponseBodyError, ResponseValidationError, } from 'apify-client';
|
package/dist/input-schemas.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EventTypeName } from '@crawlee/core';
|
|
1
2
|
import { EventManager } from '@crawlee/core';
|
|
2
3
|
import { Configuration } from './configuration.js';
|
|
3
4
|
/**
|
|
@@ -9,16 +10,16 @@ import { Configuration } from './configuration.js';
|
|
|
9
10
|
* **Example usage:**
|
|
10
11
|
*
|
|
11
12
|
* ```javascript
|
|
12
|
-
* Actor.on('
|
|
13
|
+
* Actor.on('systemInfo', (data) => {
|
|
13
14
|
* if (data.isCpuOverloaded) console.log('Oh no, the CPU is overloaded!');
|
|
14
15
|
* });
|
|
15
16
|
* ```
|
|
16
17
|
*
|
|
17
18
|
* The following events are emitted:
|
|
18
19
|
*
|
|
19
|
-
* - `
|
|
20
|
-
* The event is emitted approximately every second
|
|
21
|
-
*
|
|
20
|
+
* - `systemInfo`: `{ "cpuCurrentUsage": Number, "isCpuOverloaded": Boolean, "memCurrentBytes": Number, ... }`
|
|
21
|
+
* The event is emitted approximately every second and it describes the CPU and memory usage of the Actor.
|
|
22
|
+
* `isCpuOverloaded` indicates whether the Actor is using the maximum of available CPU resources.
|
|
22
23
|
* If that's the case, the Actor should not add more workload.
|
|
23
24
|
* For example, this event is used by the {@link AutoscaledPool} class.
|
|
24
25
|
* - `migrating`: `void`
|
|
@@ -37,18 +38,32 @@ import { Configuration } from './configuration.js';
|
|
|
37
38
|
* in which case the `isMigrating` flag is set to `true`. Otherwise the flag is `false`.
|
|
38
39
|
* Note that the `persistState` event is provided merely for user convenience,
|
|
39
40
|
* you can achieve the same effect using `setInterval()` and listening for the `migrating` event.
|
|
41
|
+
*
|
|
42
|
+
* Messages with any other name are not emitted. This includes the deprecated `cpuInfo` event, which the platform
|
|
43
|
+
* sends next to `systemInfo` for backward compatibility. Registering a `cpuInfo` listener logs a warning.
|
|
44
|
+
* Unknown names are logged at the debug level.
|
|
45
|
+
*
|
|
46
|
+
* The connection to the platform events websocket is re-established after it drops, unless it was closed
|
|
47
|
+
* with a code signalling a permanent condition (e.g. `1008` for an unknown run ID).
|
|
40
48
|
*/
|
|
41
49
|
export declare class PlatformEventManager extends EventManager {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
#private;
|
|
51
|
+
readonly configuration: Configuration;
|
|
52
|
+
/**
|
|
53
|
+
* @param internalListeners Listeners of the SDK itself, kept apart from the ones registered with `on()`, so that
|
|
54
|
+
* user code can neither remove them with `off()` nor see them in `listeners()`.
|
|
55
|
+
*/
|
|
56
|
+
constructor(configuration?: Configuration, internalListeners?: Partial<Record<EventTypeName, (...args: any[]) => unknown>>);
|
|
57
|
+
on(event: EventTypeName, listener: (...args: any[]) => any): void;
|
|
58
|
+
emit(event: EventTypeName, ...args: unknown[]): void;
|
|
59
|
+
waitForAllListenersToComplete(): Promise<boolean>;
|
|
46
60
|
/**
|
|
47
61
|
* Initializes `Actor.events` event emitter by creating a connection to a websocket that provides them.
|
|
48
62
|
* This is an internal function that is automatically called by `Actor.main()`.
|
|
63
|
+
*
|
|
64
|
+
* Rejects if the first connection cannot be established. Later drops are handled by reconnecting.
|
|
49
65
|
*/
|
|
50
66
|
init(): Promise<void>;
|
|
51
|
-
private createWebSocketConnection;
|
|
52
67
|
/**
|
|
53
68
|
* Closes websocket providing events from Actor infrastructure and also stops sending internal events
|
|
54
69
|
* of Apify package such as `persistState`.
|