@calimero-network/mero-react 4.5.0 → 4.6.1

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
@@ -569,59 +569,6 @@ function CalimeroLogo({
569
569
  );
570
570
  }
571
571
 
572
- // src/utils/nodeDiscovery.ts
573
- var DEFAULT_LOCAL_NODE_PORTS = [2428, 2429, 2528, 2529];
574
- var LOCAL_HOST = "localhost";
575
- var DEFAULT_PROBE_TIMEOUT_MS = 2e3;
576
- function localNodeUrl(port) {
577
- return `http://${LOCAL_HOST}:${port}`;
578
- }
579
- function nodeEndpoint(baseUrl, path) {
580
- const base = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
581
- return new URL(path, base).toString();
582
- }
583
- async function probeNodeHealth(baseUrl, options = {}) {
584
- const { timeoutMs = DEFAULT_PROBE_TIMEOUT_MS, signal } = options;
585
- if (signal?.aborted) return false;
586
- const controller = new AbortController();
587
- const onAbort = () => controller.abort();
588
- const listenerAdded = !!signal;
589
- if (listenerAdded) signal.addEventListener("abort", onAbort, { once: true });
590
- const timer = setTimeout(() => controller.abort(), timeoutMs);
591
- try {
592
- const url = nodeEndpoint(baseUrl, "admin-api/health");
593
- const res = await fetch(url, {
594
- method: "GET",
595
- signal: controller.signal
596
- });
597
- if (!res.ok) return false;
598
- try {
599
- const body = await res.json();
600
- const status = body?.data?.status !== void 0 ? body?.data?.status : body?.status;
601
- if (status === void 0) return true;
602
- return typeof status === "string" && status.toLowerCase() === "alive";
603
- } catch {
604
- return true;
605
- }
606
- } catch {
607
- return false;
608
- } finally {
609
- clearTimeout(timer);
610
- if (listenerAdded) signal.removeEventListener("abort", onAbort);
611
- }
612
- }
613
- async function discoverLocalNodes(options = {}) {
614
- const { ports = DEFAULT_LOCAL_NODE_PORTS, timeoutMs, signal } = options;
615
- const results = await Promise.all(
616
- ports.map(async (port) => {
617
- const url = localNodeUrl(port);
618
- const ok = await probeNodeHealth(url, { timeoutMs, signal });
619
- return ok ? url : null;
620
- })
621
- );
622
- return results.filter((url) => url !== null);
623
- }
624
-
625
572
  // src/theme.ts
626
573
  var defaultMeroTheme = Object.freeze({
627
574
  primary: "#a5ff11",
@@ -921,7 +868,7 @@ function LoginModal({
921
868
  onClose,
922
869
  isOpen,
923
870
  theme,
924
- localNodePorts = DEFAULT_LOCAL_NODE_PORTS
871
+ localNodePorts = meroJs.DEFAULT_LOCAL_NODE_PORTS
925
872
  }) {
926
873
  const [selected, setSelected] = react.useState(CUSTOM_SELECTION);
927
874
  const [discovered, setDiscovered] = react.useState([]);
@@ -952,7 +899,7 @@ function LoginModal({
952
899
  setDiscovering(true);
953
900
  setDiscovered([]);
954
901
  setError(null);
955
- discoverLocalNodes({ ports: localNodePorts, signal: controller.signal }).then((nodes) => {
902
+ meroJs.discoverLocalNodes({ ports: localNodePorts, signal: controller.signal }).then((nodes) => {
956
903
  if (!active) return;
957
904
  setDiscovered(nodes);
958
905
  setSelected(nodes.length > 0 ? nodes[0] : CUSTOM_SELECTION);
@@ -986,7 +933,7 @@ function LoginModal({
986
933
  setError(null);
987
934
  try {
988
935
  const response = await fetch(
989
- nodeEndpoint(normalizedUrl, "admin-api/is-authed")
936
+ meroJs.nodeEndpoint(normalizedUrl, "admin-api/is-authed")
990
937
  );
991
938
  if (response.ok || response.status === 401) {
992
939
  setLoading(false);
@@ -1470,13 +1417,15 @@ function useExecute(contextId, executorId) {
1470
1417
  );
1471
1418
  return { execute, loading, error };
1472
1419
  }
1473
- function useSubscription(contextIds, callback) {
1420
+ function useSubscription(input, callback) {
1474
1421
  const { mero } = useMero();
1475
1422
  const callbackRef = react.useRef(callback);
1476
1423
  callbackRef.current = callback;
1424
+ const { contextIds = [], groupIds = [] } = Array.isArray(input) ? { contextIds: input, groupIds: [] } : input;
1477
1425
  const contextIdsKey = JSON.stringify(contextIds);
1426
+ const groupIdsKey = JSON.stringify(groupIds);
1478
1427
  react.useEffect(() => {
1479
- if (!mero || contextIds.length === 0) return;
1428
+ if (!mero || contextIds.length === 0 && groupIds.length === 0) return;
1480
1429
  const sse = mero.events;
1481
1430
  const handler = (event) => {
1482
1431
  callbackRef.current(event);
@@ -1484,12 +1433,12 @@ function useSubscription(contextIds, callback) {
1484
1433
  sse.on("event", handler);
1485
1434
  sse.connect().catch(() => {
1486
1435
  });
1487
- sse.subscribe(contextIds).catch(() => {
1436
+ sse.subscribe({ contextIds, groupIds }).catch(() => {
1488
1437
  });
1489
1438
  return () => {
1490
1439
  sse.off("event", handler);
1491
1440
  };
1492
- }, [mero, contextIdsKey]);
1441
+ }, [mero, contextIdsKey, groupIdsKey]);
1493
1442
  }
1494
1443
  function useContexts(applicationId) {
1495
1444
  const { mero } = useMero();
@@ -2663,10 +2612,30 @@ Object.defineProperty(exports, "CAPABILITIES", {
2663
2612
  enumerable: true,
2664
2613
  get: function () { return meroJs.CAPABILITIES; }
2665
2614
  });
2615
+ Object.defineProperty(exports, "DEFAULT_LOCAL_NODE_PORTS", {
2616
+ enumerable: true,
2617
+ get: function () { return meroJs.DEFAULT_LOCAL_NODE_PORTS; }
2618
+ });
2619
+ Object.defineProperty(exports, "discoverLocalNodes", {
2620
+ enumerable: true,
2621
+ get: function () { return meroJs.discoverLocalNodes; }
2622
+ });
2666
2623
  Object.defineProperty(exports, "hasCap", {
2667
2624
  enumerable: true,
2668
2625
  get: function () { return meroJs.hasCap; }
2669
2626
  });
2627
+ Object.defineProperty(exports, "localNodeUrl", {
2628
+ enumerable: true,
2629
+ get: function () { return meroJs.localNodeUrl; }
2630
+ });
2631
+ Object.defineProperty(exports, "nodeEndpoint", {
2632
+ enumerable: true,
2633
+ get: function () { return meroJs.nodeEndpoint; }
2634
+ });
2635
+ Object.defineProperty(exports, "probeNodeHealth", {
2636
+ enumerable: true,
2637
+ get: function () { return meroJs.probeNodeHealth; }
2638
+ });
2670
2639
  Object.defineProperty(exports, "withCap", {
2671
2640
  enumerable: true,
2672
2641
  get: function () { return meroJs.withCap; }
@@ -2679,7 +2648,6 @@ exports.AppMode = AppMode;
2679
2648
  exports.CalimeroLogo = CalimeroLogo;
2680
2649
  exports.ConnectButton = ConnectButton;
2681
2650
  exports.ConnectionType = ConnectionType;
2682
- exports.DEFAULT_LOCAL_NODE_PORTS = DEFAULT_LOCAL_NODE_PORTS;
2683
2651
  exports.LoginModal = LoginModal;
2684
2652
  exports.MERO_CSS_VARS = MERO_CSS_VARS;
2685
2653
  exports.MeroContext = MeroContext;
@@ -2694,16 +2662,12 @@ exports.clearNodeUrl = clearNodeUrl;
2694
2662
  exports.clearTokenNodeUrl = clearTokenNodeUrl;
2695
2663
  exports.cssVar = cssVar;
2696
2664
  exports.defaultMeroTheme = defaultMeroTheme;
2697
- exports.discoverLocalNodes = discoverLocalNodes;
2698
2665
  exports.getApplicationId = getApplicationId;
2699
2666
  exports.getContextId = getContextId;
2700
2667
  exports.getContextIdentity = getContextIdentity;
2701
2668
  exports.getNodeUrl = getNodeUrl;
2702
2669
  exports.getTokenNodeUrl = getTokenNodeUrl;
2703
- exports.localNodeUrl = localNodeUrl;
2704
2670
  exports.localStorageTokenStorage = localStorageTokenStorage;
2705
- exports.nodeEndpoint = nodeEndpoint;
2706
- exports.probeNodeHealth = probeNodeHealth;
2707
2671
  exports.resolveMeroTheme = resolveMeroTheme;
2708
2672
  exports.setApplicationId = setApplicationId;
2709
2673
  exports.setContextId = setContextId;