apify 3.7.3-beta.97 → 4.0.0-beta.101

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/actor.d.ts +379 -139
  3. package/dist/actor.js +764 -500
  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 +39 -44
  19. package/dist/charging.js +237 -293
  20. package/dist/charging_storage_backend.d.ts +53 -0
  21. package/dist/charging_storage_backend.js +105 -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 +85 -144
  25. package/dist/configuration.js +138 -174
  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 +10 -4
  33. package/dist/index.js +12 -22
  34. package/dist/input-schemas.d.ts +1 -1
  35. package/dist/input-schemas.js +12 -18
  36. package/dist/platform_event_manager.d.ts +15 -10
  37. package/dist/platform_event_manager.js +193 -63
  38. package/dist/proxy_configuration.d.ts +52 -72
  39. package/dist/proxy_configuration.js +176 -221
  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 +6 -24
  43. package/dist/storage.js +1 -79
  44. package/dist/utils.d.ts +30 -0
  45. package/dist/utils.js +81 -23
  46. package/package.json +38 -43
  47. package/dist/index.mjs +0 -19
  48. package/dist/key_value_store.d.ts +0 -16
  49. package/dist/key_value_store.js +0 -40
  50. package/dist/patched_apify_client.d.ts +0 -25
  51. package/dist/patched_apify_client.js +0 -75
package/dist/storage.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import type { IStorage } from '@crawlee/core';
2
- import type { Constructor, StorageClient } from '@crawlee/types';
3
- import type { Configuration } from './configuration.js';
4
1
  export interface OpenStorageOptions {
5
2
  /**
6
3
  * If set to `true` then the cloud storage is used even if the `CRAWLEE_STORAGE_DIR`
@@ -10,8 +7,11 @@ export interface OpenStorageOptions {
10
7
  forceCloud?: boolean;
11
8
  }
12
9
  /**
13
- * Identifies a storage by its alias from the Actor's schema storages
14
- * (resolved via the `ACTOR_STORAGES_JSON` environment variable).
10
+ * Identifies a run-scoped storage by its alias.
11
+ *
12
+ * An alias declared in the Actor's schema storages (the `ACTOR_STORAGES_JSON` environment variable)
13
+ * resolves to the storage the platform created for it; any other alias gets an unnamed storage of
14
+ * its own, for this run only.
15
15
  */
16
16
  export interface StorageAlias {
17
17
  alias: string;
@@ -31,26 +31,8 @@ export interface StorageName {
31
31
  /**
32
32
  * Identifies a storage to open. Can be:
33
33
  * - A plain `string` for backward compatibility (treated as ID or name)
34
- * - `{ alias: string }` to resolve from the Actor's schema storages (`ACTOR_STORAGES_JSON`)
34
+ * - `{ alias: string }` to open a run-scoped storage — see {@link StorageAlias}
35
35
  * - `{ id: string }` to open by explicit platform ID
36
36
  * - `{ name: string }` to open by explicit name
37
37
  */
38
38
  export type StorageIdentifier = string | StorageAlias | StorageId | StorageName;
39
- /**
40
- * Identifies a storage to open, without alias support.
41
- * Used for key-value stores and request queues, which do not support aliases.
42
- * Can be:
43
- * - A plain `string` for backward compatibility (treated as ID or name)
44
- * - `{ id: string }` to open by explicit platform ID
45
- * - `{ name: string }` to open by explicit name
46
- */
47
- export type StorageIdentifierWithoutAlias = string | StorageId | StorageName;
48
- export interface OpenStorageContext {
49
- config: Configuration;
50
- client?: StorageClient;
51
- purgedStorageAliases: Set<string>;
52
- }
53
- /**
54
- * Opens a storage by its identifier, handling alias resolution and local purging.
55
- */
56
- export declare function openStorage<T extends IStorage>(storageClass: Constructor<T>, identifier: StorageIdentifier | null | undefined, context: OpenStorageContext): Promise<T>;
package/dist/storage.js CHANGED
@@ -1,79 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.openStorage = openStorage;
4
- const core_1 = require("@crawlee/core");
5
- const apify_client_1 = require("apify-client");
6
- const STORAGE_TYPE_KEYS = {
7
- Dataset: 'datasets',
8
- KeyValueStore: 'keyValueStores',
9
- RequestQueue: 'requestQueues',
10
- };
11
- const parsedStoragesJson = new Map();
12
- /**
13
- * Resolves a {@link StorageIdentifier} to a plain string ID or name
14
- * that can be passed to Crawlee's `StorageManager.openStorage()`.
15
- */
16
- function resolveStorageIdentifier(storageType, identifier, config) {
17
- if (identifier === null || identifier === undefined) {
18
- return undefined;
19
- }
20
- if (typeof identifier === 'string') {
21
- return identifier;
22
- }
23
- if ('id' in identifier) {
24
- return identifier.id;
25
- }
26
- if ('name' in identifier) {
27
- return identifier.name;
28
- }
29
- // { alias: string }
30
- const storagesJson = config.get('actorStoragesJson');
31
- if (config.get('isAtHome') && storagesJson) {
32
- let storages;
33
- try {
34
- if (!parsedStoragesJson.has(storagesJson)) {
35
- parsedStoragesJson.set(storagesJson, JSON.parse(storagesJson));
36
- }
37
- storages = parsedStoragesJson.get(storagesJson);
38
- }
39
- catch {
40
- throw new Error(`Failed to parse ACTOR_STORAGES_JSON environment variable: ${storagesJson}`);
41
- }
42
- const typeKey = STORAGE_TYPE_KEYS[storageType];
43
- const resolvedId = storages[typeKey]?.[identifier.alias];
44
- if (resolvedId) {
45
- return resolvedId;
46
- }
47
- throw new Error(`Storage alias "${identifier.alias}" not found in ACTOR_STORAGES_JSON for storage type "${storageType}". ` +
48
- `Available aliases: ${Object.keys(storages[typeKey] ?? {}).join(', ') || '(none)'}`);
49
- }
50
- // When using local storage, just use the alias as a name.
51
- // When using platform storage, we can't just make up a name — the alias must be
52
- // in ACTOR_STORAGES_JSON.
53
- if (config.get('isAtHome')) {
54
- throw new Error(`Storage alias "${identifier.alias}" cannot be resolved because ACTOR_STORAGES_JSON is not set. ` +
55
- `Aliases are only available for storages declared in the Actor's schema.`);
56
- }
57
- return identifier.alias;
58
- }
59
- /**
60
- * Opens a storage by its identifier, handling alias resolution and local purging.
61
- */
62
- async function openStorage(storageClass, identifier, context) {
63
- const isAlias = identifier !== null && identifier !== undefined && typeof identifier === 'object' && 'alias' in identifier;
64
- if (isAlias && !context.config.get('isAtHome') && context.client instanceof apify_client_1.ApifyClient) {
65
- throw new Error('The `alias` option is not allowed for Apify-based storages running outside of Apify');
66
- }
67
- const resolvedIdOrName = resolveStorageIdentifier(storageClass.name, identifier, context.config);
68
- // When running locally, purge aliased storages on first open
69
- // (similar to how Crawlee purges default storages on start)
70
- if (isAlias &&
71
- !context.config.get('isAtHome') &&
72
- context.config.get('purgeOnStart') &&
73
- !context.purgedStorageAliases.has(identifier.alias)) {
74
- context.purgedStorageAliases.add(identifier.alias);
75
- const existingStorage = await core_1.StorageManager.openStorage(storageClass, resolvedIdOrName, context.client, context.config);
76
- await existingStorage.drop();
77
- }
78
- return core_1.StorageManager.openStorage(storageClass, resolvedIdOrName, context.client, context.config);
79
- }
1
+ export {};
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,26 @@
1
+ export { ArgumentValidationError } from '@apify/validations';
2
+ /**
3
+ * Returns `true` for a plain, non-empty object (not `null`, not an array).
4
+ * Mirrors the `ow.object.nonEmpty` predicate the SDK used previously.
5
+ * @internal
6
+ */
7
+ export declare function isNonEmptyObject(value: unknown): value is Record<string, unknown>;
8
+ /** Content type of a JSON record, as `KeyValueStore` and the file-system adoption write it. */
9
+ export declare const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
10
+ /** Content type of raw bytes, which is what a local input file without an extension is adopted as. */
11
+ export declare const BINARY_CONTENT_TYPE = "application/octet-stream";
12
+ /**
13
+ * Parses a raw input record the way `KeyValueStore.getValue` would, with one exception:
14
+ * `application/octet-stream` — the type a local input file without an extension is adopted as — is
15
+ * tried as JSON5 first, so such a file still yields an object. Bytes that do not parse come back as they are.
16
+ * @internal
17
+ */
18
+ export declare function parseInputValue(value: Buffer | ArrayBuffer, contentType: string | null): unknown;
19
+ /**
20
+ * Converts a `SNAKE_CASE` string to `camelCase` (previously provided by `@crawlee/utils`).
21
+ * @internal
22
+ */
23
+ export declare function snakeCaseToCamelCase(snakeCaseStr: string): string;
1
24
  /**
2
25
  * Gets info about system, node version and apify package version.
3
26
  * @internal
@@ -13,3 +36,10 @@ export declare function getSystemInfo(): {
13
36
  * @internal
14
37
  */
15
38
  export declare function checkCrawleeVersion(): void;
39
+ /**
40
+ * A FIFO mutex that a critical section may re-enter from a nested call without deadlocking.
41
+ */
42
+ export declare class ReentrantAsyncLock {
43
+ #private;
44
+ runExclusive<T>(fn: () => Promise<T>): Promise<T>;
45
+ }
package/dist/utils.js CHANGED
@@ -1,33 +1,75 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSystemInfo = getSystemInfo;
4
- exports.checkCrawleeVersion = checkCrawleeVersion;
5
- const node_os_1 = require("node:os");
6
- const node_path_1 = require("node:path");
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import { type } from 'node:os';
5
+ import { normalize } from 'node:path';
6
+ import { parseValue } from '@crawlee/core';
7
7
  // @ts-ignore if we enable resolveJsonModule, we end up with `src` folder in `dist`
8
- const package_json_1 = require("@crawlee/core/package.json");
8
+ import crawleePkgJson from '@crawlee/core/package.json' with { type: 'json' };
9
9
  // @ts-ignore if we enable resolveJsonModule, we end up with `src` folder in `dist`
10
- const package_json_2 = require("apify-client/package.json");
11
- const fs_extra_1 = require("fs-extra");
10
+ import apifyClientPkgJson from 'apify-client/package.json' with { type: 'json' };
12
11
  // @ts-ignore if we enable resolveJsonModule, we end up with `src` folder in `dist`
13
- const package_json_3 = require("../package.json");
12
+ import apifyPkgJson from '../package.json' with { type: 'json' };
13
+ export { ArgumentValidationError } from '@apify/validations';
14
+ const require = createRequire(import.meta.url);
15
+ /**
16
+ * Returns `true` for a plain, non-empty object (not `null`, not an array).
17
+ * Mirrors the `ow.object.nonEmpty` predicate the SDK used previously.
18
+ * @internal
19
+ */
20
+ export function isNonEmptyObject(value) {
21
+ return typeof value === 'object' && value !== null && !Array.isArray(value) && Object.keys(value).length > 0;
22
+ }
23
+ /** Content type of a JSON record, as `KeyValueStore` and the file-system adoption write it. */
24
+ export const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
25
+ /** Content type of raw bytes, which is what a local input file without an extension is adopted as. */
26
+ export const BINARY_CONTENT_TYPE = 'application/octet-stream';
27
+ /**
28
+ * Parses a raw input record the way `KeyValueStore.getValue` would, with one exception:
29
+ * `application/octet-stream` — the type a local input file without an extension is adopted as — is
30
+ * tried as JSON5 first, so such a file still yields an object. Bytes that do not parse come back as they are.
31
+ * @internal
32
+ */
33
+ export function parseInputValue(value, contentType) {
34
+ const mediaType = contentType?.split(';')[0].trim().toLowerCase();
35
+ if (mediaType === BINARY_CONTENT_TYPE) {
36
+ try {
37
+ return parseValue(value, JSON_CONTENT_TYPE);
38
+ }
39
+ catch {
40
+ return value;
41
+ }
42
+ }
43
+ return parseValue(value, contentType);
44
+ }
45
+ /**
46
+ * Converts a `SNAKE_CASE` string to `camelCase` (previously provided by `@crawlee/utils`).
47
+ * @internal
48
+ */
49
+ export function snakeCaseToCamelCase(snakeCaseStr) {
50
+ return snakeCaseStr
51
+ .toLowerCase()
52
+ .split('_')
53
+ .map((part, index) => (index > 0 ? part.charAt(0).toUpperCase() + part.slice(1) : part))
54
+ .join('');
55
+ }
14
56
  /**
15
57
  * Gets info about system, node version and apify package version.
16
58
  * @internal
17
59
  */
18
- function getSystemInfo() {
60
+ export function getSystemInfo() {
19
61
  return {
20
- apifyVersion: package_json_3.version,
21
- apifyClientVersion: package_json_2.version,
22
- crawleeVersion: package_json_1.version,
23
- osType: (0, node_os_1.type)(),
62
+ apifyVersion: apifyPkgJson.version,
63
+ apifyClientVersion: apifyClientPkgJson.version,
64
+ crawleeVersion: crawleePkgJson.version,
65
+ osType: type(),
24
66
  nodeVersion: process.version,
25
67
  };
26
68
  }
27
69
  /**
28
70
  * @internal
29
71
  */
30
- function checkCrawleeVersion() {
72
+ export function checkCrawleeVersion() {
31
73
  const resolve = (name) => {
32
74
  try {
33
75
  return require.resolve(name);
@@ -38,28 +80,44 @@ function checkCrawleeVersion() {
38
80
  };
39
81
  const paths = [
40
82
  // when users install `crawlee` package, we need to check its core dependency
41
- (0, node_path_1.normalize)(`${process.cwd()}/node_modules/crawlee/node_modules/@crawlee/core/package.json`),
83
+ normalize(`${process.cwd()}/node_modules/crawlee/node_modules/@crawlee/core/package.json`),
42
84
  // when users install `@crawlee/cheerio` or other crawler package, we need to check the dependency under basic crawler package
43
- (0, node_path_1.normalize)(`${process.cwd()}/node_modules/@crawlee/basic/node_modules/@crawlee/core/package.json`),
85
+ normalize(`${process.cwd()}/node_modules/@crawlee/basic/node_modules/@crawlee/core/package.json`),
44
86
  // also check paths via `require.resolve` to support pnpm
45
87
  resolve('crawlee/package.json'),
46
88
  resolve('@crawlee/basic/package.json'),
47
89
  ];
48
90
  for (const path of paths) {
49
91
  // ignore unresolved paths or paths that are not in the project directory
50
- if (!(0, fs_extra_1.pathExistsSync)(path) || !path.startsWith(process.cwd())) {
92
+ if (!existsSync(path) || !path.startsWith(process.cwd())) {
51
93
  continue;
52
94
  }
53
95
  let version;
54
96
  try {
55
- version = (0, fs_extra_1.readJSONSync)(path).version;
97
+ version = JSON.parse(readFileSync(path, 'utf8')).version;
56
98
  }
57
99
  catch {
58
100
  //
59
101
  }
60
- if (version != null && version !== package_json_1.version) {
61
- const details = `User installed version (${version}) found in ${path}.\nSDK uses ${package_json_1.version} from ${require.resolve('@crawlee/core')}`;
62
- throw new Error(`Detected incompatible Crawlee version used by the SDK. User installed ${version} but the SDK uses ${package_json_1.version}.\n\n${details}`);
102
+ if (version != null && version !== crawleePkgJson.version) {
103
+ const details = `User installed version (${version}) found in ${path}.\nSDK uses ${crawleePkgJson.version} from ${require.resolve('@crawlee/core')}`;
104
+ throw new Error(`Detected incompatible Crawlee version used by the SDK. User installed ${version} but the SDK uses ${crawleePkgJson.version}.\n\n${details}`);
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * A FIFO mutex that a critical section may re-enter from a nested call without deadlocking.
110
+ */
111
+ export class ReentrantAsyncLock {
112
+ #tail = Promise.resolve();
113
+ #held = new AsyncLocalStorage();
114
+ async runExclusive(fn) {
115
+ if (this.#held.getStore()) {
116
+ return await fn();
63
117
  }
118
+ const run = this.#tail.then(async () => this.#held.run(true, fn));
119
+ // Keep the chain alive even when the critical section throws.
120
+ this.#tail = run.catch(() => { });
121
+ return await run;
64
122
  }
65
123
  }
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "apify",
3
- "version": "3.7.3-beta.97",
3
+ "version": "4.0.0-beta.101",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
- "node": ">=16.0.0"
6
+ "node": ">=22.13.0"
7
7
  },
8
+ "type": "module",
8
9
  "main": "./dist/index.js",
9
- "module": "./dist/index.mjs",
10
10
  "types": "./dist/index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
16
15
  },
17
16
  "./package.json": "./package.json"
18
17
  },
@@ -54,59 +53,55 @@
54
53
  ]
55
54
  },
56
55
  "dependencies": {
57
- "@apify/consts": "^2.58.1",
58
- "@apify/input_secrets": "^1.2.60",
59
- "@apify/log": "^2.5.54",
60
- "@apify/timeout": "^0.4.14",
61
- "@apify/utilities": "^2.35.11",
62
- "@crawlee/core": "^3.18.2",
63
- "@crawlee/types": "^3.18.2",
64
- "@crawlee/utils": "^3.18.2",
65
- "apify-client": "^2.25.0",
66
- "fs-extra": "^11.4.1",
67
- "ow": "^0.28.2",
68
- "semver": "^7.8.5",
69
- "tslib": "^2.8.1",
70
- "ws": "^8.22.0"
56
+ "@apify/consts": "^3.0.1",
57
+ "@apify/datastructures": "^3.0.1",
58
+ "@apify/input_secrets": "^2.0.8",
59
+ "@apify/log": "^3.0.1",
60
+ "@apify/pseudo_url": "^3.0.1",
61
+ "@apify/timeout": "^1.0.1",
62
+ "@apify/utilities": "^3.1.0",
63
+ "@apify/validations": "^1.1.4",
64
+ "@crawlee/core": "4.0.0-rc.2",
65
+ "@crawlee/fs-storage": "4.0.0-rc.2",
66
+ "@crawlee/types": "4.0.0-rc.2",
67
+ "@crawlee/utils": "4.0.0-rc.2",
68
+ "apify-client": "^3.0.0-rc.0",
69
+ "minimatch": "^11.0.5",
70
+ "tslib": "^2.9.1",
71
+ "ws": "^8.22.2",
72
+ "zod": "^4.6.7"
71
73
  },
72
74
  "devDependencies": {
73
75
  "@apify/oxlint-config": "^0.3.0",
74
76
  "@apify/tsconfig": "^0.2.0",
75
- "@commitlint/config-conventional": "^21.2.3",
76
- "@playwright/browser-chromium": "^1.63.0",
77
- "@types/content-type": "^1.1.9",
78
- "@types/fs-extra": "^11.0.4",
79
- "@types/node": "^24.19.0",
80
- "@types/semver": "^7.8.0",
81
- "@types/tough-cookie": "^4.0.5",
82
- "@types/ws": "^8.18.1",
83
- "commitlint": "^21.2.3",
84
- "crawlee": "^3.18.2",
85
- "gen-esm-wrapper": "^1.1.3",
86
- "globby": "^16.2.4",
77
+ "@commitlint/config-conventional": "^21.2.4",
78
+ "@playwright/browser-chromium": "^1.65.0",
79
+ "@types/node": "^26.6.6",
80
+ "@types/ws": "^8.18.2",
81
+ "commitlint": "^21.2.4",
82
+ "crawlee": "4.0.0-rc.2",
87
83
  "husky": "^9.1.7",
88
84
  "lint-staged": "^17.6.0",
89
- "oxfmt": "0.71.0",
90
- "oxlint": "1.86.0",
91
- "oxlint-tsgolint": "0.22.0",
92
- "playwright": "^1.63.0",
93
- "puppeteer": "^25.12.0",
94
- "rimraf": "^6.1.3",
85
+ "oxfmt": "0.78.0",
86
+ "oxlint": "1.93.0",
87
+ "oxlint-tsgolint": "7.0.2006",
88
+ "playwright": "^1.65.0",
89
+ "puppeteer": "^25.16.0",
90
+ "rimraf": "^6.1.4",
95
91
  "tsx": "^4.23.15",
96
- "typescript": "~6.0.3",
97
- "vite-tsconfig-paths": "^6.1.1",
98
- "vitest": "^5.0.2"
92
+ "typescript": "~7.0.2",
93
+ "vitest": "^5.1.0"
99
94
  },
100
95
  "devEngines": {
101
96
  "packageManager": {
102
97
  "name": "pnpm",
103
- "version": "10.33.4",
98
+ "version": "12.18.0",
104
99
  "onFail": "warn"
105
100
  }
106
101
  },
107
102
  "scripts": {
108
103
  "clean": "rimraf ./dist ./tsconfig.build.tsbuildinfo",
109
- "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./dist/index.js ./dist/index.mjs",
104
+ "compile": "tsc -p tsconfig.build.json",
110
105
  "fixApifyExport": "node ./scripts/temp_fix_apify_exports.mjs",
111
106
  "build": "pnpm clean && pnpm compile && pnpm fixApifyExport",
112
107
  "ci:build": "pnpm build",
package/dist/index.mjs DELETED
@@ -1,19 +0,0 @@
1
- import mod from "./index.js";
2
-
3
- export default mod;
4
- export const Actor = mod.Actor;
5
- export const ApifyClient = mod.ApifyClient;
6
- export const ChargingManager = mod.ChargingManager;
7
- export const Configuration = mod.Configuration;
8
- export const Dataset = mod.Dataset;
9
- export const EXIT_CODES = mod.EXIT_CODES;
10
- export const KeyValueStore = mod.KeyValueStore;
11
- export const Log = mod.Log;
12
- export const LogLevel = mod.LogLevel;
13
- export const Logger = mod.Logger;
14
- export const LoggerJson = mod.LoggerJson;
15
- export const LoggerText = mod.LoggerText;
16
- export const PlatformEventManager = mod.PlatformEventManager;
17
- export const ProxyConfiguration = mod.ProxyConfiguration;
18
- export const RequestQueue = mod.RequestQueue;
19
- export const log = mod.log;
@@ -1,16 +0,0 @@
1
- import type { StorageManagerOptions } from '@crawlee/core';
2
- import { KeyValueStore as CoreKeyValueStore } from '@crawlee/core';
3
- /**
4
- * @inheritDoc
5
- */
6
- export declare class KeyValueStore extends CoreKeyValueStore {
7
- /**
8
- * Returns a URL for the given key that may be used to publicly
9
- * access the value in the remote key-value store.
10
- */
11
- getPublicUrl(key: string): string;
12
- /**
13
- * @inheritDoc
14
- */
15
- static open(storeIdOrName?: string | null, options?: StorageManagerOptions): Promise<KeyValueStore>;
16
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyValueStore = void 0;
4
- const core_1 = require("@crawlee/core");
5
- const apify_client_1 = require("apify-client");
6
- const utilities_1 = require("@apify/utilities");
7
- // @ts-ignore newer crawlee versions already declare this method in core
8
- const { getPublicUrl } = core_1.KeyValueStore.prototype;
9
- /**
10
- * @inheritDoc
11
- */
12
- class KeyValueStore extends core_1.KeyValueStore {
13
- /**
14
- * Returns a URL for the given key that may be used to publicly
15
- * access the value in the remote key-value store.
16
- */
17
- getPublicUrl(key) {
18
- const config = this.config;
19
- const isLocalStore = !(
20
- // eslint-disable-next-line dot-notation
21
- this['client'] instanceof apify_client_1.KeyValueStoreClient);
22
- if (isLocalStore && getPublicUrl) {
23
- return getPublicUrl.call(this, key);
24
- }
25
- const publicUrl = new URL(`${config.get('apiPublicBaseUrl')}/v2/key-value-stores/${this.id}/records/${key}`);
26
- if (this.storageObject?.urlSigningSecretKey) {
27
- publicUrl.searchParams.append('signature', (0, utilities_1.createHmacSignature)(this.storageObject.urlSigningSecretKey, key));
28
- }
29
- return publicUrl.toString();
30
- }
31
- /**
32
- * @inheritDoc
33
- */
34
- static async open(storeIdOrName, options = {}) {
35
- return super.open(storeIdOrName, options);
36
- }
37
- }
38
- exports.KeyValueStore = KeyValueStore;
39
- // @ts-ignore newer crawlee versions already declare this method in core
40
- core_1.KeyValueStore.prototype.getPublicUrl = KeyValueStore.prototype.getPublicUrl;
@@ -1,25 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- import type { ApifyClientOptions } from 'apify-client';
3
- import { ApifyClient } from 'apify-client';
4
- import { type ChargeResult, type ChargingManager } from './charging.js';
5
- import type { Configuration } from './configuration.js';
6
- export declare const USES_PUSH_DATA_INTERCEPTION: unique symbol;
7
- /**
8
- * Context of a single Actor.pushData() call that is shared with the PatchedDatasetClient.pushItems() method calls.
9
- *
10
- * Purpose:
11
- * 1. Propagate eventName: When Actor.pushData() is called with an eventName,
12
- * this context allows the intercepted pushItems() to know which event to charge.
13
- * 2. Aggregate ChargeResults: A single Actor.pushData() call may trigger multiple
14
- * DatasetClient.pushItems() calls (due to batching in Crawlee). This context
15
- * aggregates the ChargeResult from all those calls into a single result.
16
- */
17
- export interface PpeAwarePushDataContext {
18
- eventName: string | undefined;
19
- chargeResult?: ChargeResult;
20
- }
21
- export declare const pushDataChargingContext: AsyncLocalStorage<PpeAwarePushDataContext>;
22
- export declare function createPatchedApifyClient(options: ApifyClientOptions, actor: {
23
- config: Configuration;
24
- getChargingManager: () => ChargingManager;
25
- }): ApifyClient;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pushDataChargingContext = exports.USES_PUSH_DATA_INTERCEPTION = void 0;
4
- exports.createPatchedApifyClient = createPatchedApifyClient;
5
- /* eslint-disable max-classes-per-file */
6
- const node_async_hooks_1 = require("node:async_hooks");
7
- const apify_client_1 = require("apify-client");
8
- const charging_js_1 = require("./charging.js");
9
- exports.USES_PUSH_DATA_INTERCEPTION = Symbol('apify:uses-push-data-interception');
10
- exports.pushDataChargingContext = new node_async_hooks_1.AsyncLocalStorage();
11
- function createPatchedApifyClient(options, actor) {
12
- class PatchedDatasetClient extends apify_client_1.DatasetClient {
13
- normalizeItems(items) {
14
- if (typeof items === 'string') {
15
- const parsed = JSON.parse(items);
16
- return Array.isArray(parsed) ? parsed : [parsed];
17
- }
18
- if (Array.isArray(items)) {
19
- return items.flatMap((item) => typeof item === 'string' ? JSON.parse(item) : item);
20
- }
21
- return [items];
22
- }
23
- async pushItems(items) {
24
- const context = exports.pushDataChargingContext.getStore();
25
- // Normalize string inputs: a single JSON string may encode multiple items
26
- // (e.g. '[{"a":1},{"b":2}]'), which would be miscounted by the charging logic.
27
- // Parse strings into arrays so each logical item is counted individually.
28
- const normalizedItems = this.normalizeItems(items);
29
- const result = await (0, charging_js_1.pushDataAndCharge)({
30
- chargingManager: actor.getChargingManager(),
31
- items: normalizedItems,
32
- eventName: context?.eventName,
33
- isDefaultDataset: true,
34
- pushFn: async (limitedItems) => super.pushItems(JSON.stringify(limitedItems)), // stringify the items for faster validation in Apify client
35
- });
36
- if (!context)
37
- return;
38
- // For a single invocation of Dataset.pushData, there may be more than one call to DatasetClient.pushItems.
39
- // Aggregate `ChargeResult` objects across such calls.
40
- if (context.chargeResult === undefined) {
41
- context.chargeResult = result;
42
- }
43
- else {
44
- context.chargeResult = (0, charging_js_1.mergeChargeResults)(context.chargeResult, result);
45
- }
46
- }
47
- }
48
- class PatchedApifyClient extends apify_client_1.ApifyClient {
49
- dataset(id) {
50
- const isDefaultDataset = id === actor.config.get('defaultDatasetId');
51
- const datasetOptions = {
52
- id,
53
- baseUrl: this.baseUrl,
54
- publicBaseUrl: this.publicBaseUrl,
55
- apifyClient: this,
56
- httpClient: this.httpClient,
57
- };
58
- // Charging is only configured for an initialized Actor (a platform run). A
59
- // standalone client from `Actor.newClient()` without `Actor.init()` has no
60
- // charging state, so skip interception rather than letting getPricingInfo() throw.
61
- const chargingManager = actor.getChargingManager();
62
- const hasDefaultDatasetItemEvent = chargingManager.isInitialized &&
63
- charging_js_1.DEFAULT_DATASET_ITEM_EVENT in chargingManager.getPricingInfo().perEventPrices;
64
- if (!isDefaultDataset || !hasDefaultDatasetItemEvent) {
65
- return new apify_client_1.DatasetClient(datasetOptions);
66
- }
67
- const client = new PatchedDatasetClient(datasetOptions);
68
- Object.assign(client, {
69
- [exports.USES_PUSH_DATA_INTERCEPTION]: true,
70
- });
71
- return client;
72
- }
73
- }
74
- return new PatchedApifyClient(options);
75
- }