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/utils.js
CHANGED
|
@@ -1,19 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
3
|
import { createRequire } from 'node:module';
|
|
3
4
|
import { type } from 'node:os';
|
|
4
5
|
import { normalize } from 'node:path';
|
|
6
|
+
import { parseValue } from '@crawlee/core';
|
|
5
7
|
// @ts-ignore if we enable resolveJsonModule, we end up with `src` folder in `dist`
|
|
6
8
|
import crawleePkgJson from '@crawlee/core/package.json' with { type: 'json' };
|
|
7
9
|
// @ts-ignore if we enable resolveJsonModule, we end up with `src` folder in `dist`
|
|
8
10
|
import apifyClientPkgJson from 'apify-client/package.json' with { type: 'json' };
|
|
9
|
-
// eslint-disable-next-line import/extensions
|
|
10
|
-
import { readJSONSync } from 'fs-extra/esm';
|
|
11
|
-
import semver from 'semver';
|
|
12
|
-
import { APIFY_ENV_VARS } from '@apify/consts';
|
|
13
|
-
import log from '@apify/log';
|
|
14
11
|
// @ts-ignore if we enable resolveJsonModule, we end up with `src` folder in `dist`
|
|
15
12
|
import apifyPkgJson from '../package.json' with { type: 'json' };
|
|
13
|
+
export { ArgumentValidationError } from '@apify/validations';
|
|
16
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
|
+
}
|
|
17
56
|
/**
|
|
18
57
|
* Gets info about system, node version and apify package version.
|
|
19
58
|
* @internal
|
|
@@ -55,7 +94,7 @@ export function checkCrawleeVersion() {
|
|
|
55
94
|
}
|
|
56
95
|
let version;
|
|
57
96
|
try {
|
|
58
|
-
version =
|
|
97
|
+
version = JSON.parse(readFileSync(path, 'utf8')).version;
|
|
59
98
|
}
|
|
60
99
|
catch {
|
|
61
100
|
//
|
|
@@ -67,15 +106,18 @@ export function checkCrawleeVersion() {
|
|
|
67
106
|
}
|
|
68
107
|
}
|
|
69
108
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @ignore
|
|
109
|
+
* A FIFO mutex that a critical section may re-enter from a nested call without deadlocking.
|
|
72
110
|
*/
|
|
73
|
-
export
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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();
|
|
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;
|
|
122
|
+
}
|
|
81
123
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.140",
|
|
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": ">=22.
|
|
6
|
+
"node": ">=22.13.0"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.js",
|
|
@@ -53,55 +53,49 @@
|
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@apify/consts": "^
|
|
57
|
-
"@apify/
|
|
58
|
-
"@apify/
|
|
59
|
-
"@apify/
|
|
60
|
-
"@apify/
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"
|
|
65
|
-
"fs-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
56
|
+
"@apify/consts": "^3.1.0",
|
|
57
|
+
"@apify/datastructures": "^3.0.1",
|
|
58
|
+
"@apify/input_secrets": "^2.0.9",
|
|
59
|
+
"@apify/log": "^3.0.2",
|
|
60
|
+
"@apify/pseudo_url": "^3.0.2",
|
|
61
|
+
"@apify/timeout": "^1.1.0",
|
|
62
|
+
"@apify/utilities": "^3.1.1",
|
|
63
|
+
"@apify/validations": "^1.1.4",
|
|
64
|
+
"@crawlee/core": "4.0.0-rc.3",
|
|
65
|
+
"@crawlee/fs-storage": "4.0.0-rc.3",
|
|
66
|
+
"@crawlee/types": "4.0.0-rc.3",
|
|
67
|
+
"@crawlee/utils": "4.0.0-rc.3",
|
|
68
|
+
"apify-client": "^3.0.0-rc.2",
|
|
69
|
+
"minimatch": "^11.0.9",
|
|
70
|
+
"tslib": "^2.9.1",
|
|
71
|
+
"ws": "^8.23.0",
|
|
72
|
+
"zod": "^4.6.7"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
|
-
"@apify/oxlint-config": "^0.
|
|
75
|
-
"@apify/tsconfig": "^0.
|
|
76
|
-
"@commitlint/config-conventional": "^21.
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@types/
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"@types/semver": "^7.5.8",
|
|
83
|
-
"@types/tough-cookie": "^4.0.5",
|
|
84
|
-
"@types/ws": "^8.5.12",
|
|
85
|
-
"commitlint": "^21.0.0",
|
|
86
|
-
"crawlee": "^4.0.0-beta.61",
|
|
87
|
-
"globby": "^16.0.0",
|
|
75
|
+
"@apify/oxlint-config": "^0.4.0",
|
|
76
|
+
"@apify/tsconfig": "^0.2.0",
|
|
77
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
78
|
+
"@playwright/browser-chromium": "^1.65.1",
|
|
79
|
+
"@types/node": "^26.6.6",
|
|
80
|
+
"@types/ws": "^8.18.2",
|
|
81
|
+
"commitlint": "^21.2.4",
|
|
82
|
+
"crawlee": "4.0.0-rc.3",
|
|
88
83
|
"husky": "^9.1.7",
|
|
89
|
-
"lint-staged": "^17.
|
|
90
|
-
"oxfmt": "0.
|
|
91
|
-
"oxlint": "1.
|
|
92
|
-
"oxlint-tsgolint": "0.
|
|
93
|
-
"playwright": "^1.
|
|
94
|
-
"puppeteer": "^25.
|
|
95
|
-
"rimraf": "^6.
|
|
96
|
-
"tsx": "^4.
|
|
97
|
-
"typescript": "~
|
|
98
|
-
"
|
|
99
|
-
"vitest": "^4.0.0"
|
|
84
|
+
"lint-staged": "^17.6.1",
|
|
85
|
+
"oxfmt": "0.80.0",
|
|
86
|
+
"oxlint": "1.95.0",
|
|
87
|
+
"oxlint-tsgolint": "7.0.2009",
|
|
88
|
+
"playwright": "^1.65.1",
|
|
89
|
+
"puppeteer": "^25.18.1",
|
|
90
|
+
"rimraf": "^6.1.4",
|
|
91
|
+
"tsx": "^4.23.15",
|
|
92
|
+
"typescript": "~7.0.2",
|
|
93
|
+
"vitest": "^5.1.1"
|
|
100
94
|
},
|
|
101
95
|
"devEngines": {
|
|
102
96
|
"packageManager": {
|
|
103
97
|
"name": "pnpm",
|
|
104
|
-
"version": "
|
|
98
|
+
"version": "12.25.1",
|
|
105
99
|
"onFail": "warn"
|
|
106
100
|
}
|
|
107
101
|
},
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import type { CreateDatasetClientOptions, CreateKeyValueStoreClientOptions, CreateRequestQueueClientOptions, DatasetClient, KeyValueStoreClient, RequestQueueClient, StorageClient } from '@crawlee/types';
|
|
3
|
-
import type { ApifyClient } from 'apify-client';
|
|
4
|
-
import { type ChargeResult, type ChargingManager } from './charging.js';
|
|
5
|
-
import type { Configuration } from './configuration.js';
|
|
6
|
-
type StorageType = 'Dataset' | 'KeyValueStore' | 'RequestQueue';
|
|
7
|
-
/** Marks a dataset client whose `pushItems` charges for pay-per-event. @internal */
|
|
8
|
-
export declare const USES_PUSH_DATA_INTERCEPTION: unique symbol;
|
|
9
|
-
/**
|
|
10
|
-
* Context of a single `Actor.pushData()` call, shared with the intercepted
|
|
11
|
-
* `pushItems()` calls so they can (1) know which event to charge and
|
|
12
|
-
* (2) aggregate the {@link ChargeResult} across the multiple `pushItems()`
|
|
13
|
-
* calls a single `pushData()` may trigger (Crawlee batches large pushes).
|
|
14
|
-
*/
|
|
15
|
-
export interface PpeAwarePushDataContext {
|
|
16
|
-
eventName: string | undefined;
|
|
17
|
-
chargeResult?: ChargeResult;
|
|
18
|
-
}
|
|
19
|
-
export declare const pushDataChargingContext: AsyncLocalStorage<PpeAwarePushDataContext>;
|
|
20
|
-
/**
|
|
21
|
-
* Bridges `apify-client`'s synchronous resource accessors (`dataset(id)`,
|
|
22
|
-
* `keyValueStore(id)`, `requestQueue(id, options?)`) to crawlee v4's
|
|
23
|
-
* `StorageClient` interface (async factory methods accepting either an `id`
|
|
24
|
-
* or a `name`).
|
|
25
|
-
*
|
|
26
|
-
* For the run's default dataset it transparently swaps in a charging-aware
|
|
27
|
-
* dataset client (pay-per-event on `Actor.pushData()`), provided a charging
|
|
28
|
-
* manager is supplied and a default-dataset-item price is configured.
|
|
29
|
-
*
|
|
30
|
-
* `storageExists()` lets `Dataset.open(idOrName)` resolve a string to an id
|
|
31
|
-
* first (when one exists on the platform) and fall back to a name otherwise —
|
|
32
|
-
* otherwise crawlee's `resolveStorageIdentifier` treats every string as a name
|
|
33
|
-
* and the SDK would silently create a new storage named like the passed id.
|
|
34
|
-
*/
|
|
35
|
-
export declare class ApifyStorageClient implements StorageClient {
|
|
36
|
-
private readonly client;
|
|
37
|
-
private readonly config?;
|
|
38
|
-
private readonly getChargingManager?;
|
|
39
|
-
constructor(client: ApifyClient, config?: Configuration | undefined, getChargingManager?: (() => ChargingManager) | undefined);
|
|
40
|
-
storageExists(id: string, type: StorageType): Promise<boolean>;
|
|
41
|
-
createDatasetClient(options?: CreateDatasetClientOptions): Promise<DatasetClient>;
|
|
42
|
-
createKeyValueStoreClient(options?: CreateKeyValueStoreClientOptions): Promise<KeyValueStoreClient>;
|
|
43
|
-
createRequestQueueClient(options?: CreateRequestQueueClientOptions): Promise<RequestQueueClient>;
|
|
44
|
-
/**
|
|
45
|
-
* Returns a charging-aware dataset client when `id` is the run's default
|
|
46
|
-
* dataset and a default-dataset-item price is configured; otherwise
|
|
47
|
-
* `undefined` (caller uses the plain client).
|
|
48
|
-
*/
|
|
49
|
-
private chargingDatasetClient;
|
|
50
|
-
private resolveId;
|
|
51
|
-
private resourceClient;
|
|
52
|
-
private collectionClient;
|
|
53
|
-
}
|
|
54
|
-
export {};
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
-
import { DatasetClient as ApifyDatasetClient } from 'apify-client';
|
|
4
|
-
import { DEFAULT_DATASET_ITEM_EVENT, mergeChargeResults, pushDataAndCharge, } from './charging.js';
|
|
5
|
-
const DEFAULT_ID_CONFIG_KEY = {
|
|
6
|
-
Dataset: 'defaultDatasetId',
|
|
7
|
-
KeyValueStore: 'defaultKeyValueStoreId',
|
|
8
|
-
RequestQueue: 'defaultRequestQueueId',
|
|
9
|
-
};
|
|
10
|
-
/** Marks a dataset client whose `pushItems` charges for pay-per-event. @internal */
|
|
11
|
-
export const USES_PUSH_DATA_INTERCEPTION = Symbol('apify:uses-push-data-interception');
|
|
12
|
-
export const pushDataChargingContext = new AsyncLocalStorage();
|
|
13
|
-
/**
|
|
14
|
-
* Default `DatasetClient` that charges for pushed items (pay-per-event). Used
|
|
15
|
-
* only for the run's default dataset when a `apify-default-dataset-item` price
|
|
16
|
-
* is configured; for everything else the plain `apify-client` dataset client is
|
|
17
|
-
* used.
|
|
18
|
-
*/
|
|
19
|
-
class PpeAwareDatasetClient extends ApifyDatasetClient {
|
|
20
|
-
getChargingManager;
|
|
21
|
-
constructor(options, getChargingManager) {
|
|
22
|
-
super(options);
|
|
23
|
-
this.getChargingManager = getChargingManager;
|
|
24
|
-
}
|
|
25
|
-
normalizeItems(items) {
|
|
26
|
-
if (typeof items === 'string') {
|
|
27
|
-
const parsed = JSON.parse(items);
|
|
28
|
-
return Array.isArray(parsed) ? parsed : [parsed];
|
|
29
|
-
}
|
|
30
|
-
if (Array.isArray(items)) {
|
|
31
|
-
return items.flatMap((item) => typeof item === 'string' ? JSON.parse(item) : item);
|
|
32
|
-
}
|
|
33
|
-
return [items];
|
|
34
|
-
}
|
|
35
|
-
async pushItems(items) {
|
|
36
|
-
const context = pushDataChargingContext.getStore();
|
|
37
|
-
// A single JSON string may encode multiple items (e.g. '[{...},{...}]'),
|
|
38
|
-
// which the charging logic would miscount — parse strings into arrays so
|
|
39
|
-
// each logical item is counted individually.
|
|
40
|
-
const normalizedItems = this.normalizeItems(items);
|
|
41
|
-
const result = await pushDataAndCharge({
|
|
42
|
-
chargingManager: this.getChargingManager(),
|
|
43
|
-
items: normalizedItems,
|
|
44
|
-
eventName: context?.eventName,
|
|
45
|
-
isDefaultDataset: true,
|
|
46
|
-
// stringify for faster validation in the Apify client
|
|
47
|
-
pushFn: async (limitedItems) => super.pushItems(JSON.stringify(limitedItems)),
|
|
48
|
-
});
|
|
49
|
-
if (!context)
|
|
50
|
-
return;
|
|
51
|
-
// One `Actor.pushData()` may map to several `pushItems()` calls — aggregate.
|
|
52
|
-
context.chargeResult =
|
|
53
|
-
context.chargeResult === undefined ? result : mergeChargeResults(context.chargeResult, result);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Bridges `apify-client`'s synchronous resource accessors (`dataset(id)`,
|
|
58
|
-
* `keyValueStore(id)`, `requestQueue(id, options?)`) to crawlee v4's
|
|
59
|
-
* `StorageClient` interface (async factory methods accepting either an `id`
|
|
60
|
-
* or a `name`).
|
|
61
|
-
*
|
|
62
|
-
* For the run's default dataset it transparently swaps in a charging-aware
|
|
63
|
-
* dataset client (pay-per-event on `Actor.pushData()`), provided a charging
|
|
64
|
-
* manager is supplied and a default-dataset-item price is configured.
|
|
65
|
-
*
|
|
66
|
-
* `storageExists()` lets `Dataset.open(idOrName)` resolve a string to an id
|
|
67
|
-
* first (when one exists on the platform) and fall back to a name otherwise —
|
|
68
|
-
* otherwise crawlee's `resolveStorageIdentifier` treats every string as a name
|
|
69
|
-
* and the SDK would silently create a new storage named like the passed id.
|
|
70
|
-
*/
|
|
71
|
-
export class ApifyStorageClient {
|
|
72
|
-
client;
|
|
73
|
-
config;
|
|
74
|
-
getChargingManager;
|
|
75
|
-
constructor(client, config, getChargingManager) {
|
|
76
|
-
this.client = client;
|
|
77
|
-
this.config = config;
|
|
78
|
-
this.getChargingManager = getChargingManager;
|
|
79
|
-
}
|
|
80
|
-
async storageExists(id, type) {
|
|
81
|
-
// Apify's `GET /v2/{kind}/{idOrName}` matches by either id or name;
|
|
82
|
-
// confirm it was an *id* match so crawlee can fall through to `{ name }`.
|
|
83
|
-
const info = await this.resourceClient(id, type).get();
|
|
84
|
-
return info?.id === id;
|
|
85
|
-
}
|
|
86
|
-
async createDatasetClient(options) {
|
|
87
|
-
const id = await this.resolveId(options, 'Dataset');
|
|
88
|
-
const datasetClient = this.chargingDatasetClient(id) ?? this.client.dataset(id);
|
|
89
|
-
// apify-client's resource clients overlap with `@crawlee/types`' shapes
|
|
90
|
-
// but don't implement the v4-added members (`getMetadata`,
|
|
91
|
-
// `getRecordPublicUrl`), so cast through.
|
|
92
|
-
return datasetClient;
|
|
93
|
-
}
|
|
94
|
-
async createKeyValueStoreClient(options) {
|
|
95
|
-
const id = await this.resolveId(options, 'KeyValueStore');
|
|
96
|
-
return this.client.keyValueStore(id);
|
|
97
|
-
}
|
|
98
|
-
async createRequestQueueClient(options) {
|
|
99
|
-
const id = await this.resolveId(options, 'RequestQueue');
|
|
100
|
-
return this.client.requestQueue(id, options?.clientKey ? { clientKey: options.clientKey } : undefined);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns a charging-aware dataset client when `id` is the run's default
|
|
104
|
-
* dataset and a default-dataset-item price is configured; otherwise
|
|
105
|
-
* `undefined` (caller uses the plain client).
|
|
106
|
-
*/
|
|
107
|
-
chargingDatasetClient(id) {
|
|
108
|
-
const { getChargingManager } = this;
|
|
109
|
-
if (!getChargingManager)
|
|
110
|
-
return undefined;
|
|
111
|
-
if (id !== this.config?.defaultDatasetId)
|
|
112
|
-
return undefined;
|
|
113
|
-
const hasDefaultDatasetItemEvent = DEFAULT_DATASET_ITEM_EVENT in getChargingManager().getPricingInfo().perEventPrices;
|
|
114
|
-
if (!hasDefaultDatasetItemEvent)
|
|
115
|
-
return undefined;
|
|
116
|
-
const datasetClient = new PpeAwareDatasetClient({
|
|
117
|
-
id,
|
|
118
|
-
baseUrl: this.client.baseUrl,
|
|
119
|
-
publicBaseUrl: this.client.publicBaseUrl,
|
|
120
|
-
apifyClient: this.client,
|
|
121
|
-
httpClient: this.client.httpClient,
|
|
122
|
-
}, getChargingManager);
|
|
123
|
-
Object.assign(datasetClient, {
|
|
124
|
-
[USES_PUSH_DATA_INTERCEPTION]: true,
|
|
125
|
-
});
|
|
126
|
-
return datasetClient;
|
|
127
|
-
}
|
|
128
|
-
async resolveId(options, type) {
|
|
129
|
-
if (options?.id)
|
|
130
|
-
return options.id;
|
|
131
|
-
if (options?.name) {
|
|
132
|
-
return (await this.collectionClient(type).getOrCreate(options.name)).id;
|
|
133
|
-
}
|
|
134
|
-
// No id/name (crawlee's `__default__` alias): use the default storage
|
|
135
|
-
// id from the run's environment. apify-client rejects an empty id.
|
|
136
|
-
return this.config?.[DEFAULT_ID_CONFIG_KEY[type]] ?? '';
|
|
137
|
-
}
|
|
138
|
-
resourceClient(id, type) {
|
|
139
|
-
if (type === 'Dataset')
|
|
140
|
-
return this.client.dataset(id);
|
|
141
|
-
if (type === 'KeyValueStore')
|
|
142
|
-
return this.client.keyValueStore(id);
|
|
143
|
-
return this.client.requestQueue(id);
|
|
144
|
-
}
|
|
145
|
-
collectionClient(type) {
|
|
146
|
-
if (type === 'Dataset')
|
|
147
|
-
return this.client.datasets();
|
|
148
|
-
if (type === 'KeyValueStore')
|
|
149
|
-
return this.client.keyValueStores();
|
|
150
|
-
return this.client.requestQueues();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { StorageOpenOptions } 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
|
-
* On the Apify platform the URL is signed with the store's
|
|
12
|
-
* `urlSigningSecretKey` so that anyone with the URL can read the record
|
|
13
|
-
* without authentication. Locally we delegate to crawlee's default
|
|
14
|
-
* implementation (which produces a `file://` URL or returns `undefined`).
|
|
15
|
-
*/
|
|
16
|
-
getPublicUrl(key: string): Promise<string | undefined>;
|
|
17
|
-
/**
|
|
18
|
-
* @inheritDoc
|
|
19
|
-
*/
|
|
20
|
-
static open(storeIdOrName?: string | null, options?: StorageOpenOptions): Promise<KeyValueStore>;
|
|
21
|
-
}
|
package/dist/key_value_store.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { KeyValueStore as CoreKeyValueStore } from '@crawlee/core';
|
|
2
|
-
import { KeyValueStoreClient as RemoteKeyValueStoreClient } from 'apify-client';
|
|
3
|
-
import { createHmacSignature } from '@apify/utilities';
|
|
4
|
-
/**
|
|
5
|
-
* @inheritDoc
|
|
6
|
-
*/
|
|
7
|
-
export class KeyValueStore extends CoreKeyValueStore {
|
|
8
|
-
/**
|
|
9
|
-
* Returns a URL for the given key that may be used to publicly
|
|
10
|
-
* access the value in the remote key-value store.
|
|
11
|
-
*
|
|
12
|
-
* On the Apify platform the URL is signed with the store's
|
|
13
|
-
* `urlSigningSecretKey` so that anyone with the URL can read the record
|
|
14
|
-
* without authentication. Locally we delegate to crawlee's default
|
|
15
|
-
* implementation (which produces a `file://` URL or returns `undefined`).
|
|
16
|
-
*/
|
|
17
|
-
async getPublicUrl(key) {
|
|
18
|
-
const config = this.config;
|
|
19
|
-
// Detect a remote (Apify) store by its client type rather than by
|
|
20
|
-
// `isAtHome`, so that a `forceCloud` store opened locally still gets a
|
|
21
|
-
// signed Apify URL (matching the platform behaviour). `client` is
|
|
22
|
-
// `private` on `CoreKeyValueStore`, so bypass the visibility check.
|
|
23
|
-
const { client } = this;
|
|
24
|
-
const isLocalStore = !(client instanceof RemoteKeyValueStoreClient);
|
|
25
|
-
if (isLocalStore) {
|
|
26
|
-
return super.getPublicUrl(key);
|
|
27
|
-
}
|
|
28
|
-
const publicUrl = new URL(`${config.apiPublicBaseUrl}/v2/key-value-stores/${this.id}/records/${key}`);
|
|
29
|
-
const metadata = (await client.getMetadata());
|
|
30
|
-
if (metadata?.urlSigningSecretKey) {
|
|
31
|
-
publicUrl.searchParams.append('signature', createHmacSignature(metadata.urlSigningSecretKey, key));
|
|
32
|
-
}
|
|
33
|
-
return publicUrl.toString();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @inheritDoc
|
|
37
|
-
*/
|
|
38
|
-
static async open(storeIdOrName, options = {}) {
|
|
39
|
-
return super.open(storeIdOrName, options);
|
|
40
|
-
}
|
|
41
|
-
}
|