scrapely 1.2.3 → 1.2.5
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 +119 -1
- package/dist/actor.d.ts +703 -0
- package/dist/actor.js +1441 -0
- package/dist/browser-configuration.d.ts +58 -0
- package/dist/browser-configuration.js +128 -0
- package/dist/browser-locations.d.ts +5 -0
- package/dist/browser-locations.js +5469 -0
- package/dist/charging.d.ts +153 -0
- package/dist/charging.js +782 -0
- package/dist/charging_client.d.ts +18 -0
- package/dist/charging_client.js +49 -0
- package/dist/configuration.d.ts +121 -0
- package/dist/configuration.js +128 -0
- package/dist/crypto/secrets.d.ts +44 -0
- package/dist/crypto/secrets.js +164 -0
- package/dist/events/events-client.d.ts +59 -0
- package/dist/events/events-client.js +120 -0
- package/dist/events/scrapely-event-manager.d.ts +13 -0
- package/dist/events/scrapely-event-manager.js +61 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +95 -0
- package/dist/log-env.d.ts +1 -0
- package/dist/log-env.js +12 -0
- package/dist/manifest.d.ts +30 -0
- package/dist/manifest.js +47 -0
- package/dist/patch-browser-pool.d.ts +66 -0
- package/dist/patch-browser-pool.js +827 -0
- package/dist/proxy-configuration.d.ts +118 -0
- package/dist/proxy-configuration.js +88 -0
- package/dist/request-list.d.ts +57 -0
- package/dist/request-list.js +79 -0
- package/dist/runner/docker-manager.d.ts +88 -0
- package/dist/runner/docker-manager.js +283 -0
- package/dist/runner/index.d.ts +2 -0
- package/dist/runner/index.js +7 -0
- package/dist/runner/timeout-manager.d.ts +43 -0
- package/dist/runner/timeout-manager.js +90 -0
- package/dist/scrapely-proxy-configuration.d.ts +99 -0
- package/dist/scrapely-proxy-configuration.js +559 -0
- package/dist/storage/api-storage-client.d.ts +199 -0
- package/dist/storage/api-storage-client.js +910 -0
- package/dist/storage/billing-tracker.d.ts +163 -0
- package/dist/storage/billing-tracker.js +260 -0
- package/dist/storage/dataset-client.d.ts +43 -0
- package/dist/storage/dataset-client.js +232 -0
- package/dist/storage/dataset-collection-client.d.ts +8 -0
- package/dist/storage/dataset-collection-client.js +75 -0
- package/dist/storage/dataset-push-script.d.ts +18 -0
- package/dist/storage/dataset-push-script.js +38 -0
- package/dist/storage/dragonfly-client.d.ts +94 -0
- package/dist/storage/dragonfly-client.js +167 -0
- package/dist/storage/index.d.ts +11 -0
- package/dist/storage/index.js +25 -0
- package/dist/storage/key-value-store-client.d.ts +61 -0
- package/dist/storage/key-value-store-client.js +306 -0
- package/dist/storage/kv-store-collection-client.d.ts +8 -0
- package/dist/storage/kv-store-collection-client.js +76 -0
- package/dist/storage/kvs-iteration.d.ts +17 -0
- package/dist/storage/kvs-iteration.js +126 -0
- package/dist/storage/log-manager.d.ts +114 -0
- package/dist/storage/log-manager.js +244 -0
- package/dist/storage/patch-storage.d.ts +11 -0
- package/dist/storage/patch-storage.js +177 -0
- package/dist/storage/request-queue-client.d.ts +93 -0
- package/dist/storage/request-queue-client.js +522 -0
- package/dist/storage/rq-collection-client.d.ts +8 -0
- package/dist/storage/rq-collection-client.js +89 -0
- package/dist/storage/rq-list-requests.d.ts +59 -0
- package/dist/storage/rq-list-requests.js +114 -0
- package/dist/storage/rq-lock-script.d.ts +56 -0
- package/dist/storage/rq-lock-script.js +127 -0
- package/dist/storage/run-metadata.d.ts +98 -0
- package/dist/storage/run-metadata.js +256 -0
- package/dist/storage/s3-client.d.ts +103 -0
- package/dist/storage/s3-client.js +302 -0
- package/dist/storage/ttl-manager.d.ts +70 -0
- package/dist/storage/ttl-manager.js +115 -0
- package/dist/storage/utils.d.ts +3 -0
- package/dist/storage/utils.js +19 -0
- package/dist/storage-identifiers.d.ts +20 -0
- package/dist/storage-identifiers.js +6 -0
- package/dist/utils.d.ts +54 -0
- package/dist/utils.js +63 -0
- package/dist/validator.d.ts +24 -0
- package/dist/validator.js +158 -0
- package/package.json +90 -9
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ApifyClient } from 'scrapely-client';
|
|
2
|
+
import type { ActorRunPricingInfo } from 'scrapely-client';
|
|
3
|
+
import type { Configuration } from './configuration.js';
|
|
4
|
+
/** Client safe-replay window; server TTL is longer (35d). */
|
|
5
|
+
export declare const CHARGE_IDEMPOTENCY_SAFE_AGE_MS: number;
|
|
6
|
+
export declare class ChargeUncertainError extends Error {
|
|
7
|
+
readonly operationId: string;
|
|
8
|
+
readonly eventName: string;
|
|
9
|
+
readonly count: number;
|
|
10
|
+
constructor(message: string, opts: {
|
|
11
|
+
operationId: string;
|
|
12
|
+
eventName: string;
|
|
13
|
+
count: number;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Apify-compatible synthetic event for default-dataset items in pay-per-event actors. */
|
|
17
|
+
/** Definitive platform rejection (402/400/409). Do not retry with the same key. */
|
|
18
|
+
export declare class ChargeRejectedError extends Error {
|
|
19
|
+
readonly operationId: string;
|
|
20
|
+
readonly eventName: string;
|
|
21
|
+
readonly count: number;
|
|
22
|
+
readonly statusCode?: number;
|
|
23
|
+
readonly reason: string;
|
|
24
|
+
constructor(message: string, opts: {
|
|
25
|
+
operationId: string;
|
|
26
|
+
eventName: string;
|
|
27
|
+
count: number;
|
|
28
|
+
statusCode?: number;
|
|
29
|
+
reason: string;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export declare const APIFY_DEFAULT_DATASET_ITEM_EVENT = "apify-default-dataset-item";
|
|
33
|
+
/** Scrapely-native synthetic event for default-dataset items. */
|
|
34
|
+
export declare const SCRAPELY_DEFAULT_DATASET_ITEM_EVENT = "scrapely-default-dataset-item";
|
|
35
|
+
/** Apify-compatible alias — imported actors expect this constant name. */
|
|
36
|
+
export declare const DEFAULT_DATASET_ITEM_EVENT = "apify-default-dataset-item";
|
|
37
|
+
export declare function isDefaultDatasetItemEvent(eventName: string): boolean;
|
|
38
|
+
export declare function resolveDefaultDatasetItemEventName(pricingInfo: Record<string, unknown>): string;
|
|
39
|
+
export declare function hasDefaultDatasetItemEventInPricing(perEventPrices: Record<string, number>): boolean;
|
|
40
|
+
export interface ChargeOptions {
|
|
41
|
+
eventName: string;
|
|
42
|
+
count?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ChargeResult {
|
|
45
|
+
eventChargeLimitReached: boolean;
|
|
46
|
+
chargedCount: number;
|
|
47
|
+
chargeableWithinLimit: Record<string, number>;
|
|
48
|
+
}
|
|
49
|
+
export interface ActorPricingInfo {
|
|
50
|
+
pricingModel?: ActorRunPricingInfo['pricingModel'];
|
|
51
|
+
maxTotalChargeUsd: number;
|
|
52
|
+
isPayPerEvent: boolean;
|
|
53
|
+
perEventPrices: Record<string, number>;
|
|
54
|
+
}
|
|
55
|
+
export declare function mergeChargeResults(a: ChargeResult, b: ChargeResult): ChargeResult;
|
|
56
|
+
/**
|
|
57
|
+
* Pay-per-event charging for platform runs.
|
|
58
|
+
* Reports charges via POST /v2/actor-runs/:runId/charge (Redis → worker billing).
|
|
59
|
+
*/
|
|
60
|
+
export declare class ChargingManager {
|
|
61
|
+
private readonly configuration;
|
|
62
|
+
private readonly apifyClient;
|
|
63
|
+
/** Set during actor shutdown; rejects new charge operations after the final flush. */
|
|
64
|
+
private _closed;
|
|
65
|
+
/** @internal Called by Actor shutdown before the final flush. */
|
|
66
|
+
close(): void;
|
|
67
|
+
/** @internal Whether shutdown has closed this manager to new charges. */
|
|
68
|
+
isClosed(): boolean;
|
|
69
|
+
private readonly LOCAL_CHARGING_LOG_DATASET_NAME;
|
|
70
|
+
private readonly PLATFORM_CHARGING_LOG_DATASET_ID_KEY;
|
|
71
|
+
private maxTotalChargeUsd;
|
|
72
|
+
private readonly isAtHome;
|
|
73
|
+
private readonly actorRunId;
|
|
74
|
+
private pricingModel?;
|
|
75
|
+
private pricingInfo;
|
|
76
|
+
private chargingState?;
|
|
77
|
+
private chargingLogDataset?;
|
|
78
|
+
private notPpeWarningPrinted;
|
|
79
|
+
/** Unresolved platform POSTs: key = idempotency UUID (never event name). */
|
|
80
|
+
private readonly pendingCharges;
|
|
81
|
+
private flushInFlight;
|
|
82
|
+
private operationTail;
|
|
83
|
+
private readonly postAttempts;
|
|
84
|
+
private readonly pendingMaxEntries;
|
|
85
|
+
private readonly idempotencySafeAgeMs;
|
|
86
|
+
constructor(configuration: Configuration, apifyClient: ApifyClient);
|
|
87
|
+
/** @internal Serialize allowance calculation, side effects, and local reservation. */
|
|
88
|
+
_withOperationLock<T>(operation: () => Promise<T>): Promise<T>;
|
|
89
|
+
private get isPayPerEvent();
|
|
90
|
+
private ensureInitialized;
|
|
91
|
+
private fetchPricingInfo;
|
|
92
|
+
/**
|
|
93
|
+
* Initialize the ChargingManager by loading pricing information and charging state via platform API.
|
|
94
|
+
*/
|
|
95
|
+
init(): Promise<void>;
|
|
96
|
+
getPricingInfo(): ActorPricingInfo;
|
|
97
|
+
getChargedEventCount(eventName: string): number;
|
|
98
|
+
getMaxTotalChargeUsd(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Helper to calculate how many items can be pushed within charging limits.
|
|
101
|
+
* Returns the limited items and count to charge.
|
|
102
|
+
*/
|
|
103
|
+
calculatePushDataLimits<T>(params: {
|
|
104
|
+
eventName: undefined | string;
|
|
105
|
+
isDefaultDataset: boolean;
|
|
106
|
+
items: T | T[];
|
|
107
|
+
}): {
|
|
108
|
+
eventsToCharge: Record<string, number>;
|
|
109
|
+
limitedItems: T[];
|
|
110
|
+
};
|
|
111
|
+
private calculateTotalChargedAmount;
|
|
112
|
+
/**
|
|
113
|
+
* How many events of a given type can still be charged for before reaching the limit;
|
|
114
|
+
* If the event is not registered, returns Infinity (free of charge)
|
|
115
|
+
*/
|
|
116
|
+
calculateMaxEventChargeCountWithinLimit(eventName: string): number;
|
|
117
|
+
private calculateEventPrice;
|
|
118
|
+
private getEventPricing;
|
|
119
|
+
private normalizeChargingEventName;
|
|
120
|
+
private calculateMaxChargesByPrice;
|
|
121
|
+
private getChargeableWithinLimit;
|
|
122
|
+
private quarantineStalePending;
|
|
123
|
+
/**
|
|
124
|
+
* POST a charge intent. Returns acceptedCount on success.
|
|
125
|
+
* Throws ChargeRejectedError for definitive platform rejections (no retry).
|
|
126
|
+
* Returns null when the outcome is uncertain after retries.
|
|
127
|
+
*/
|
|
128
|
+
private postChargeWithRetries;
|
|
129
|
+
/** Clamp local reservation down when the server accepted fewer events. */
|
|
130
|
+
/** @internal Used by pushDataAndCharge dual-event reconciliation. */
|
|
131
|
+
applyAcceptedCount(eventName: string, reservedCount: number, acceptedCount: number, eventPrice?: number): number;
|
|
132
|
+
/**
|
|
133
|
+
* Best-effort flush of open charge intents (same keys, no local counter bump).
|
|
134
|
+
* @returns number of intents confirmed
|
|
135
|
+
*/
|
|
136
|
+
/**
|
|
137
|
+
* Best-effort flush of open charge intents under the operation lock.
|
|
138
|
+
* Drains in batches until empty or deadlineMs elapses.
|
|
139
|
+
*/
|
|
140
|
+
flushPending(maxIntents?: number, deadlineMs?: number): Promise<number>;
|
|
141
|
+
/** @internal Caller must hold the operation lock. */
|
|
142
|
+
_flushPendingExclusive(maxIntents?: number, deadlineMs?: number): Promise<number>;
|
|
143
|
+
charge({ eventName, count }: ChargeOptions): Promise<ChargeResult>;
|
|
144
|
+
/** @internal Caller must hold the operation lock. */
|
|
145
|
+
_chargeExclusive({ eventName, count }: ChargeOptions): Promise<ChargeResult>;
|
|
146
|
+
}
|
|
147
|
+
export declare function pushDataAndCharge<T>({ chargingManager, items, eventName, isDefaultDataset, pushFn, }: {
|
|
148
|
+
chargingManager: ChargingManager;
|
|
149
|
+
items: T | T[];
|
|
150
|
+
eventName: string | undefined;
|
|
151
|
+
isDefaultDataset: boolean;
|
|
152
|
+
pushFn: (limitedItems: T | T[]) => Promise<void>;
|
|
153
|
+
}): Promise<ChargeResult>;
|