@le-space/browser 0.1.24 → 0.1.25

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 (3) hide show
  1. package/index.d.ts +33 -2
  2. package/index.js +30 -2
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -12,6 +12,35 @@ interface BalanceResponse {
12
12
  details?: Record<string, string>;
13
13
  credit_balance: number;
14
14
  }
15
+ interface Price {
16
+ payg?: string | number | null;
17
+ holding?: string | number | null;
18
+ fixed?: string | number | null;
19
+ credit?: string | number | null;
20
+ }
21
+ interface ComputeUnit {
22
+ vcpus: number;
23
+ memory_mib: number;
24
+ disk_mib: number;
25
+ }
26
+ interface Tier {
27
+ id: string;
28
+ compute_units: number;
29
+ vram?: number | null;
30
+ model?: string | null;
31
+ }
32
+ interface InstancePricing {
33
+ price: {
34
+ storage?: Price;
35
+ compute_unit?: Price;
36
+ };
37
+ compute_unit: ComputeUnit;
38
+ tiers: Tier[];
39
+ }
40
+ interface PricingState {
41
+ pricing: InstancePricing | null;
42
+ fetchedAt: number | null;
43
+ }
15
44
  interface CrnUsage {
16
45
  cpu?: {
17
46
  count?: number;
@@ -144,6 +173,8 @@ declare function loadRootfsManifest(url?: string | URL, options?: LoadRootfsMani
144
173
  declare function verifyRootfsExists(itemHash: string, apiHost?: string): Promise<boolean>;
145
174
  declare function resolveRootfsReference(itemHash: string, apiHost?: string, gatewayBaseUrl?: string): Promise<RootfsResolution | null>;
146
175
 
147
- declare const BROWSER_PRICING_MODULE = "planned";
176
+ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e7142701ae2A";
177
+ declare function parseInstancePricing(payload: unknown): InstancePricing;
178
+ declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
148
179
 
149
- export { BROWSER_PACKAGE_PLAN, BROWSER_PRICING_MODULE, type BalanceResponse, type BrowserExtractionPhase, type BrowserPackagePlan, type Crn, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_ALEPH_API_HOST, DEFAULT_CRN_LIST_URL, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_ROOTFS_MANIFEST_URL, type GatewayProbeStatus, ITEM_HASH_RE, type InstanceMessage, type LoadRootfsManifestOptions, type MessageStatus, type PaymentMode, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, fetchBalance, fetchCrns, fetchInstances, fetchWithTimeout, loadRootfsManifest, normalizeMessageStatus, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists };
180
+ export { BROWSER_PACKAGE_PLAN, type BalanceResponse, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type Crn, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_ALEPH_AGGREGATE_ADDRESS, DEFAULT_ALEPH_API_HOST, DEFAULT_CRN_LIST_URL, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_ROOTFS_MANIFEST_URL, type GatewayProbeStatus, ITEM_HASH_RE, type InstanceMessage, type InstancePricing, type LoadRootfsManifestOptions, type MessageStatus, type PaymentMode, type Price, type PricingState, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, fetchBalance, fetchCrns, fetchInstancePricing, fetchInstances, fetchWithTimeout, loadRootfsManifest, normalizeMessageStatus, parseInstancePricing, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists };
package/index.js CHANGED
@@ -272,10 +272,36 @@ async function resolveRootfsReference(itemHash, apiHost = DEFAULT_ALEPH_API_HOST
272
272
  }
273
273
 
274
274
  // src/pricing.ts
275
- var BROWSER_PRICING_MODULE = "planned";
275
+ var DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e7142701ae2A";
276
+ function parseInstancePricing(payload) {
277
+ const data = payload;
278
+ const pricing = data.data?.pricing ?? data.pricing;
279
+ const instance = pricing?.instance;
280
+ if (!instance?.price?.compute_unit || !instance.compute_unit || !Array.isArray(instance.tiers)) {
281
+ throw new Error("Aleph pricing aggregate does not contain instance pricing.");
282
+ }
283
+ return instance;
284
+ }
285
+ async function fetchInstancePricing(apiHost = DEFAULT_ALEPH_API_HOST, aggregateAddress = DEFAULT_ALEPH_AGGREGATE_ADDRESS) {
286
+ const response = await fetchWithTimeout(`${apiHost}/api/v0/aggregates/${aggregateAddress}.json?keys=pricing`, {
287
+ cache: "no-cache"
288
+ });
289
+ if (!response.ok) {
290
+ throw new Error(`Pricing aggregate request failed: ${response.status}`);
291
+ }
292
+ const payload = await response.json();
293
+ const pricingAggregate = payload.data?.pricing;
294
+ if (!pricingAggregate) {
295
+ throw new Error("Pricing aggregate response did not include a pricing key.");
296
+ }
297
+ return {
298
+ pricing: parseInstancePricing({ pricing: pricingAggregate }),
299
+ fetchedAt: Date.now()
300
+ };
301
+ }
276
302
  export {
277
303
  BROWSER_PACKAGE_PLAN,
278
- BROWSER_PRICING_MODULE,
304
+ DEFAULT_ALEPH_AGGREGATE_ADDRESS,
279
305
  DEFAULT_ALEPH_API_HOST,
280
306
  DEFAULT_CRN_LIST_URL,
281
307
  DEFAULT_IPFS_GATEWAY_BASE_URL,
@@ -283,10 +309,12 @@ export {
283
309
  ITEM_HASH_RE,
284
310
  fetchBalance,
285
311
  fetchCrns,
312
+ fetchInstancePricing,
286
313
  fetchInstances,
287
314
  fetchWithTimeout,
288
315
  loadRootfsManifest,
289
316
  normalizeMessageStatus,
317
+ parseInstancePricing,
290
318
  resolveRootfsReference,
291
319
  validateRootfsManifest,
292
320
  verifyRootfsExists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/browser",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "Shared browser-safe Aleph deployment and polling helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",