@le-space/browser 0.6.5 → 0.6.6

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 CHANGED
@@ -17,7 +17,7 @@ UX.
17
17
 
18
18
  The preferred public entrypoint is a typed browser client factory:
19
19
 
20
- - `createAlephBrowserClient({ apiHost?, crnListUrl? })`
20
+ - `createAlephBrowserClient({ apiHost?, apiHosts?, crnListUrl? })`
21
21
 
22
22
  That client should remain small and stable. It currently owns:
23
23
 
package/index.d.ts CHANGED
@@ -281,6 +281,7 @@ interface BroadcastResult {
281
281
  }
282
282
  interface AlephBrowserClient {
283
283
  apiHost: string;
284
+ apiHosts: string[];
284
285
  crnListUrl: string;
285
286
  schedulerApiHost: string;
286
287
  fetchBalance(address: string): Promise<BalanceResponse>;
@@ -337,7 +338,8 @@ interface RootfsResolution {
337
338
 
338
339
  declare function fetchWithTimeout(input: RequestInfo | URL, init?: RequestInit, timeoutMs?: number): Promise<Response>;
339
340
 
340
- declare const DEFAULT_ALEPH_API_HOST = "https://api.aleph.im";
341
+ declare const DEFAULT_ALEPH_API_HOSTS: readonly string[];
342
+ declare const DEFAULT_ALEPH_API_HOST: string;
341
343
  declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
342
344
  declare const DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
343
345
  declare const DEFAULT_2N6_API_HOST = "https://api.2n6.me";
@@ -407,8 +409,10 @@ declare function waitForDeploymentResult(itemHash: string, rootfsRef?: string, a
407
409
  declare function broadcastInstanceMessage(message: AlephBroadcastMessage, apiHost?: string, sync?: boolean): Promise<BroadcastResult>;
408
410
  declare function broadcastAlephMessage(message: AlephBroadcastMessage, apiHost?: string, sync?: boolean): Promise<BroadcastResult>;
409
411
 
412
+ type ApiHostInput = string | readonly string[];
410
413
  interface CreateAlephBrowserClientOptions {
411
414
  apiHost?: string;
415
+ apiHosts?: ApiHostInput;
412
416
  crnListUrl?: string;
413
417
  schedulerApiHost?: string;
414
418
  twoN6ApiHost?: string;
@@ -483,4 +487,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
483
487
  declare function parseInstancePricing(payload: unknown): InstancePricing;
484
488
  declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
485
489
 
486
- export { type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephBrowserClient, type AlephMessageEnvelope, type AlephMessageType, type AlephSenderChain, type AllocationNotifyResult, BROWSER_PACKAGE_PLAN, type BalanceResponse, type BroadcastResult, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type CreateAlephBrowserClientOptions, type Crn, type CrnExecutionLookupResult, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_2N6_API_HOST, DEFAULT_ALEPH_AGGREGATE_ADDRESS, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_SCHEDULER_API_HOST, DEFAULT_CRN_LIST_URL, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_ROOTFS_MANIFEST_URL, type DeploymentInspectionResult, type EthereumProviderLike, type EthereumTransactionRequest, type EvmChainConfig, type GatewayProbeStatus, ITEM_HASH_RE, type InstanceAllocation, type InstanceAllocationNode, type InstanceAllocationPeriod, type InstanceExecution, type InstanceExecutionNetworking, type InstanceExecutionStatus, type InstanceMessage, type InstancePortMapping, type InstancePricing, type LoadRootfsManifestOptions, type MessageReference, type MessageStatus, type PaymentChain, type PaymentMode, type PrepaidReservation, type PrepaidVaultSnapshot, type Price, type PricingState, type ReferenceStatus, type RelaySetupRequest, type RelaySetupResult, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, approvePrepaidBudget, broadcastAlephMessage, broadcastInstanceMessage, configureOrbitdbRelaySetup, consumeDeploymentReservation, createAlephBrowserClient, depositPrepaidBudget, ethCall, fetch2n6WebAccessUrl, fetchBalance, fetchCrnExecutionMap, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchSchedulerAllocation, fetchWithTimeout, formatBudgetUnits, inspectDeploymentResult, loadPrepaidReservation, loadPrepaidVaultSnapshot, loadRootfsManifest, normalizeExecution, normalizeMessageStatus, notifyCrnAllocation, parseInstancePricing, paymentChainFromChainId, personalSign, refundExpiredReservation, reserveDeploymentBudget, resolveRootfsReference, sendTransaction, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
490
+ export { type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephBrowserClient, type AlephMessageEnvelope, type AlephMessageType, type AlephSenderChain, type AllocationNotifyResult, BROWSER_PACKAGE_PLAN, type BalanceResponse, type BroadcastResult, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type CreateAlephBrowserClientOptions, type Crn, type CrnExecutionLookupResult, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_2N6_API_HOST, DEFAULT_ALEPH_AGGREGATE_ADDRESS, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_API_HOSTS, DEFAULT_ALEPH_SCHEDULER_API_HOST, DEFAULT_CRN_LIST_URL, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_ROOTFS_MANIFEST_URL, type DeploymentInspectionResult, type EthereumProviderLike, type EthereumTransactionRequest, type EvmChainConfig, type GatewayProbeStatus, ITEM_HASH_RE, type InstanceAllocation, type InstanceAllocationNode, type InstanceAllocationPeriod, type InstanceExecution, type InstanceExecutionNetworking, type InstanceExecutionStatus, type InstanceMessage, type InstancePortMapping, type InstancePricing, type LoadRootfsManifestOptions, type MessageReference, type MessageStatus, type PaymentChain, type PaymentMode, type PrepaidReservation, type PrepaidVaultSnapshot, type Price, type PricingState, type ReferenceStatus, type RelaySetupRequest, type RelaySetupResult, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, approvePrepaidBudget, broadcastAlephMessage, broadcastInstanceMessage, configureOrbitdbRelaySetup, consumeDeploymentReservation, createAlephBrowserClient, depositPrepaidBudget, ethCall, fetch2n6WebAccessUrl, fetchBalance, fetchCrnExecutionMap, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchSchedulerAllocation, fetchWithTimeout, formatBudgetUnits, inspectDeploymentResult, loadPrepaidReservation, loadPrepaidVaultSnapshot, loadRootfsManifest, normalizeExecution, normalizeMessageStatus, notifyCrnAllocation, parseInstancePricing, paymentChainFromChainId, personalSign, refundExpiredReservation, reserveDeploymentBudget, resolveRootfsReference, sendTransaction, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
package/index.js CHANGED
@@ -48,7 +48,12 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15e3) {
48
48
  }
49
49
 
50
50
  // src/aleph-api.ts
51
- var DEFAULT_ALEPH_API_HOST = "https://api.aleph.im";
51
+ var DEFAULT_ALEPH_API_HOSTS = [
52
+ "https://api3.aleph.im",
53
+ "https://api2.aleph.im",
54
+ "https://api.aleph.im"
55
+ ];
56
+ var DEFAULT_ALEPH_API_HOST = DEFAULT_ALEPH_API_HOSTS[0] ?? "https://api3.aleph.im";
52
57
  var DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
53
58
  var DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
54
59
  var DEFAULT_2N6_API_HOST = "https://api.2n6.me";
@@ -471,29 +476,56 @@ async function broadcastAlephMessage(message, apiHost = DEFAULT_ALEPH_API_HOST,
471
476
  }
472
477
 
473
478
  // src/client.ts
479
+ function normalizeApiHost(value) {
480
+ const trimmed = value.trim().replace(/\/+$/u, "");
481
+ return trimmed ? trimmed : null;
482
+ }
483
+ function normalizeApiHosts(input, fallbackApiHost) {
484
+ const rawValues = Array.isArray(input) ? input : typeof input === "string" ? input.split(/[\s,]+/u) : [];
485
+ const hosts = rawValues.map((value) => normalizeApiHost(String(value))).filter((value) => Boolean(value));
486
+ if (hosts.length > 0) return Array.from(new Set(hosts));
487
+ const fallback = normalizeApiHost(fallbackApiHost);
488
+ return fallback ? [fallback] : [...DEFAULT_ALEPH_API_HOSTS];
489
+ }
490
+ async function withApiHostFallback(apiHosts, run) {
491
+ let lastError = null;
492
+ for (let index = 0; index < apiHosts.length; index += 1) {
493
+ const apiHost = apiHosts[index];
494
+ try {
495
+ return await run(apiHost);
496
+ } catch (error) {
497
+ lastError = error;
498
+ if (index >= apiHosts.length - 1) break;
499
+ }
500
+ }
501
+ if (lastError instanceof Error) throw lastError;
502
+ throw new Error(String(lastError));
503
+ }
474
504
  function createAlephBrowserClient(options = {}) {
475
- const apiHost = options.apiHost ?? DEFAULT_ALEPH_API_HOST;
505
+ const apiHosts = options.apiHosts === void 0 && options.apiHost === void 0 ? [...DEFAULT_ALEPH_API_HOSTS] : normalizeApiHosts(options.apiHosts, options.apiHost ?? DEFAULT_ALEPH_API_HOST);
506
+ const apiHost = apiHosts[0] ?? DEFAULT_ALEPH_API_HOST;
476
507
  const crnListUrl = options.crnListUrl ?? DEFAULT_CRN_LIST_URL;
477
508
  const schedulerApiHost = options.schedulerApiHost ?? DEFAULT_ALEPH_SCHEDULER_API_HOST;
478
509
  const twoN6ApiHost = options.twoN6ApiHost ?? DEFAULT_2N6_API_HOST;
479
510
  return {
480
511
  apiHost,
512
+ apiHosts,
481
513
  crnListUrl,
482
514
  schedulerApiHost,
483
515
  fetchBalance(address) {
484
- return fetchBalance(address, apiHost);
516
+ return withApiHostFallback(apiHosts, (host) => fetchBalance(address, host));
485
517
  },
486
518
  fetchCrns() {
487
519
  return fetchCrns(crnListUrl);
488
520
  },
489
521
  fetchInstances(address) {
490
- return fetchInstances(address, apiHost);
522
+ return withApiHostFallback(apiHosts, (host) => fetchInstances(address, host));
491
523
  },
492
524
  fetch2n6WebAccessUrl(itemHash) {
493
525
  return fetch2n6WebAccessUrl(itemHash, twoN6ApiHost);
494
526
  },
495
527
  fetchMessageEnvelope(itemHash) {
496
- return fetchMessageEnvelope(itemHash, apiHost);
528
+ return withApiHostFallback(apiHosts, (host) => fetchMessageEnvelope(itemHash, host));
497
529
  },
498
530
  fetchSchedulerAllocation(itemHash) {
499
531
  return fetchSchedulerAllocation(itemHash, schedulerApiHost);
@@ -508,16 +540,16 @@ function createAlephBrowserClient(options = {}) {
508
540
  return configureOrbitdbRelaySetup(args);
509
541
  },
510
542
  inspectDeploymentResult(itemHash, rootfsRef) {
511
- return inspectDeploymentResult(itemHash, rootfsRef, apiHost);
543
+ return withApiHostFallback(apiHosts, (host) => inspectDeploymentResult(itemHash, rootfsRef, host));
512
544
  },
513
545
  waitForDeploymentResult(itemHash, rootfsRef, attempts, delayMs) {
514
- return waitForDeploymentResult(itemHash, rootfsRef, apiHost, attempts, delayMs);
546
+ return withApiHostFallback(apiHosts, (host) => waitForDeploymentResult(itemHash, rootfsRef, host, attempts, delayMs));
515
547
  },
516
548
  broadcastInstanceMessage(message, sync) {
517
- return broadcastInstanceMessage(message, apiHost, sync);
549
+ return withApiHostFallback(apiHosts, (host) => broadcastInstanceMessage(message, host, sync));
518
550
  },
519
551
  broadcastAlephMessage(message, sync) {
520
- return broadcastAlephMessage(message, apiHost, sync);
552
+ return withApiHostFallback(apiHosts, (host) => broadcastAlephMessage(message, host, sync));
521
553
  }
522
554
  };
523
555
  }
@@ -944,6 +976,7 @@ export {
944
976
  DEFAULT_2N6_API_HOST,
945
977
  DEFAULT_ALEPH_AGGREGATE_ADDRESS,
946
978
  DEFAULT_ALEPH_API_HOST,
979
+ DEFAULT_ALEPH_API_HOSTS,
947
980
  DEFAULT_ALEPH_SCHEDULER_API_HOST,
948
981
  DEFAULT_CRN_LIST_URL,
949
982
  DEFAULT_IPFS_GATEWAY_BASE_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/browser",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "Shared browser-safe Aleph deployment and polling helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",