apify 3.7.3-beta.9 → 4.0.0-beta.13

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/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,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,70 +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
- const hasDefaultDatasetItemEvent = charging_js_1.DEFAULT_DATASET_ITEM_EVENT in actor.getChargingManager().getPricingInfo().perEventPrices;
59
- if (!isDefaultDataset || !hasDefaultDatasetItemEvent) {
60
- return new apify_client_1.DatasetClient(datasetOptions);
61
- }
62
- const client = new PatchedDatasetClient(datasetOptions);
63
- Object.assign(client, {
64
- [exports.USES_PUSH_DATA_INTERCEPTION]: true,
65
- });
66
- return client;
67
- }
68
- }
69
- return new PatchedApifyClient(options);
70
- }