@calimero-network/mero-js 7.1.1 → 7.3.0

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.cjs CHANGED
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  AuthRevokedError: () => AuthRevokedError,
25
25
  CAPABILITIES: () => CAPABILITIES,
26
26
  CloudClient: () => CloudClient,
27
+ DEFAULT_LOCAL_NODE_PORTS: () => DEFAULT_LOCAL_NODE_PORTS,
27
28
  HTTPError: () => HTTPError,
28
29
  LocalStorageTokenStore: () => LocalStorageTokenStore,
29
30
  MemoryTokenStore: () => MemoryTokenStore,
@@ -51,8 +52,12 @@ __export(index_exports, {
51
52
  createRetryableMethod: () => createRetryableMethod,
52
53
  createTimeoutSignal: () => createTimeoutSignal,
53
54
  createUniversalHttpClient: () => createUniversalHttpClient,
55
+ discoverLocalNodes: () => discoverLocalNodes,
54
56
  hasCap: () => hasCap,
57
+ localNodeUrl: () => localNodeUrl,
58
+ nodeEndpoint: () => nodeEndpoint,
55
59
  parseAuthCallback: () => parseAuthCallback,
60
+ probeNodeHealth: () => probeNodeHealth,
56
61
  withCap: () => withCap,
57
62
  withRetry: () => withRetry,
58
63
  withoutCap: () => withoutCap
@@ -882,6 +887,18 @@ var AdminApiClient = class {
882
887
  await this.httpClient.get(`/admin-api/applications/${applicationId}/versions`)
883
888
  );
884
889
  }
890
+ /**
891
+ * The application's embedded `wasm-abi/1` manifest. Omit `serviceName` for
892
+ * single-service apps; core 400s if the ABI is absent or the name is ambiguous.
893
+ */
894
+ async getApplicationAbi(applicationId, serviceName) {
895
+ const query = serviceName ? `?service_name=${encodeURIComponent(serviceName)}` : "";
896
+ return unwrap(
897
+ await this.httpClient.get(
898
+ `/admin-api/applications/${applicationId}/abi${query}`
899
+ )
900
+ );
901
+ }
885
902
  // ---- Package Management ----
886
903
  async listPackages() {
887
904
  const r = await this.httpClient.get(
@@ -2431,4 +2448,57 @@ function withCap(mask, cap) {
2431
2448
  function withoutCap(mask, cap) {
2432
2449
  return (mask & ~cap) >>> 0;
2433
2450
  }
2451
+
2452
+ // src/nodeDiscovery.ts
2453
+ var DEFAULT_LOCAL_NODE_PORTS = [2428, 2429, 2528, 2529];
2454
+ var LOCAL_HOST = "localhost";
2455
+ var DEFAULT_PROBE_TIMEOUT_MS = 2e3;
2456
+ function localNodeUrl(port) {
2457
+ return `http://${LOCAL_HOST}:${port}`;
2458
+ }
2459
+ function nodeEndpoint(baseUrl, path) {
2460
+ const base = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
2461
+ return new URL(path, base).toString();
2462
+ }
2463
+ async function probeNodeHealth(baseUrl, options = {}) {
2464
+ const { timeoutMs = DEFAULT_PROBE_TIMEOUT_MS, signal } = options;
2465
+ if (signal?.aborted) return false;
2466
+ const controller = new AbortController();
2467
+ const onAbort = () => controller.abort();
2468
+ const abortSignal = signal;
2469
+ if (abortSignal) abortSignal.addEventListener("abort", onAbort, { once: true });
2470
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
2471
+ try {
2472
+ const url = nodeEndpoint(baseUrl, "admin-api/health");
2473
+ const res = await fetch(url, {
2474
+ method: "GET",
2475
+ signal: controller.signal
2476
+ });
2477
+ if (!res.ok) return false;
2478
+ try {
2479
+ const body = await res.json();
2480
+ const status = body?.data?.status !== void 0 ? body?.data?.status : body?.status;
2481
+ if (status === void 0) return true;
2482
+ return typeof status === "string" && status.toLowerCase() === "alive";
2483
+ } catch {
2484
+ return true;
2485
+ }
2486
+ } catch {
2487
+ return false;
2488
+ } finally {
2489
+ clearTimeout(timer);
2490
+ if (abortSignal) abortSignal.removeEventListener("abort", onAbort);
2491
+ }
2492
+ }
2493
+ async function discoverLocalNodes(options = {}) {
2494
+ const { ports = DEFAULT_LOCAL_NODE_PORTS, timeoutMs, signal } = options;
2495
+ const results = await Promise.all(
2496
+ ports.map(async (port) => {
2497
+ const url = localNodeUrl(port);
2498
+ const ok = await probeNodeHealth(url, { timeoutMs, signal });
2499
+ return ok ? url : null;
2500
+ })
2501
+ );
2502
+ return results.filter((url) => url !== null);
2503
+ }
2434
2504
  //# sourceMappingURL=index.cjs.map