@calimero-network/mero-react 4.6.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 +23 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -50
- package/dist/index.d.ts +2 -50
- package/dist/index.js +3 -56
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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);
|
|
@@ -2665,10 +2612,30 @@ Object.defineProperty(exports, "CAPABILITIES", {
|
|
|
2665
2612
|
enumerable: true,
|
|
2666
2613
|
get: function () { return meroJs.CAPABILITIES; }
|
|
2667
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
|
+
});
|
|
2668
2623
|
Object.defineProperty(exports, "hasCap", {
|
|
2669
2624
|
enumerable: true,
|
|
2670
2625
|
get: function () { return meroJs.hasCap; }
|
|
2671
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
|
+
});
|
|
2672
2639
|
Object.defineProperty(exports, "withCap", {
|
|
2673
2640
|
enumerable: true,
|
|
2674
2641
|
get: function () { return meroJs.withCap; }
|
|
@@ -2681,7 +2648,6 @@ exports.AppMode = AppMode;
|
|
|
2681
2648
|
exports.CalimeroLogo = CalimeroLogo;
|
|
2682
2649
|
exports.ConnectButton = ConnectButton;
|
|
2683
2650
|
exports.ConnectionType = ConnectionType;
|
|
2684
|
-
exports.DEFAULT_LOCAL_NODE_PORTS = DEFAULT_LOCAL_NODE_PORTS;
|
|
2685
2651
|
exports.LoginModal = LoginModal;
|
|
2686
2652
|
exports.MERO_CSS_VARS = MERO_CSS_VARS;
|
|
2687
2653
|
exports.MeroContext = MeroContext;
|
|
@@ -2696,16 +2662,12 @@ exports.clearNodeUrl = clearNodeUrl;
|
|
|
2696
2662
|
exports.clearTokenNodeUrl = clearTokenNodeUrl;
|
|
2697
2663
|
exports.cssVar = cssVar;
|
|
2698
2664
|
exports.defaultMeroTheme = defaultMeroTheme;
|
|
2699
|
-
exports.discoverLocalNodes = discoverLocalNodes;
|
|
2700
2665
|
exports.getApplicationId = getApplicationId;
|
|
2701
2666
|
exports.getContextId = getContextId;
|
|
2702
2667
|
exports.getContextIdentity = getContextIdentity;
|
|
2703
2668
|
exports.getNodeUrl = getNodeUrl;
|
|
2704
2669
|
exports.getTokenNodeUrl = getTokenNodeUrl;
|
|
2705
|
-
exports.localNodeUrl = localNodeUrl;
|
|
2706
2670
|
exports.localStorageTokenStorage = localStorageTokenStorage;
|
|
2707
|
-
exports.nodeEndpoint = nodeEndpoint;
|
|
2708
|
-
exports.probeNodeHealth = probeNodeHealth;
|
|
2709
2671
|
exports.resolveMeroTheme = resolveMeroTheme;
|
|
2710
2672
|
exports.setApplicationId = setApplicationId;
|
|
2711
2673
|
exports.setContextId = setContextId;
|