@calimero-network/mero-react 4.4.1 → 4.6.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 +133 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -4
- package/dist/index.d.ts +52 -4
- package/dist/index.js +132 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1296,6 +1296,29 @@ function ConnectButton({
|
|
|
1296
1296
|
}
|
|
1297
1297
|
);
|
|
1298
1298
|
}
|
|
1299
|
+
|
|
1300
|
+
// src/utils/base58.ts
|
|
1301
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1302
|
+
function base58ToHex(input) {
|
|
1303
|
+
const bytes = [];
|
|
1304
|
+
for (const char of input) {
|
|
1305
|
+
let carry = ALPHABET.indexOf(char);
|
|
1306
|
+
if (carry === -1) throw new Error(`invalid base58 character: ${char}`);
|
|
1307
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
1308
|
+
carry += bytes[i] * 58;
|
|
1309
|
+
bytes[i] = carry & 255;
|
|
1310
|
+
carry >>= 8;
|
|
1311
|
+
}
|
|
1312
|
+
while (carry > 0) {
|
|
1313
|
+
bytes.push(carry & 255);
|
|
1314
|
+
carry >>= 8;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
for (let k = 0; k < input.length && input[k] === "1"; k++) bytes.push(0);
|
|
1318
|
+
return bytes.reverse().map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// src/hooks/index.ts
|
|
1299
1322
|
function toError(err) {
|
|
1300
1323
|
return err instanceof Error ? err : new Error(String(err));
|
|
1301
1324
|
}
|
|
@@ -1447,13 +1470,15 @@ function useExecute(contextId, executorId) {
|
|
|
1447
1470
|
);
|
|
1448
1471
|
return { execute, loading, error };
|
|
1449
1472
|
}
|
|
1450
|
-
function useSubscription(
|
|
1473
|
+
function useSubscription(input, callback) {
|
|
1451
1474
|
const { mero } = useMero();
|
|
1452
1475
|
const callbackRef = react.useRef(callback);
|
|
1453
1476
|
callbackRef.current = callback;
|
|
1477
|
+
const { contextIds = [], groupIds = [] } = Array.isArray(input) ? { contextIds: input, groupIds: [] } : input;
|
|
1454
1478
|
const contextIdsKey = JSON.stringify(contextIds);
|
|
1479
|
+
const groupIdsKey = JSON.stringify(groupIds);
|
|
1455
1480
|
react.useEffect(() => {
|
|
1456
|
-
if (!mero || contextIds.length === 0) return;
|
|
1481
|
+
if (!mero || contextIds.length === 0 && groupIds.length === 0) return;
|
|
1457
1482
|
const sse = mero.events;
|
|
1458
1483
|
const handler = (event) => {
|
|
1459
1484
|
callbackRef.current(event);
|
|
@@ -1461,12 +1486,12 @@ function useSubscription(contextIds, callback) {
|
|
|
1461
1486
|
sse.on("event", handler);
|
|
1462
1487
|
sse.connect().catch(() => {
|
|
1463
1488
|
});
|
|
1464
|
-
sse.subscribe(contextIds).catch(() => {
|
|
1489
|
+
sse.subscribe({ contextIds, groupIds }).catch(() => {
|
|
1465
1490
|
});
|
|
1466
1491
|
return () => {
|
|
1467
1492
|
sse.off("event", handler);
|
|
1468
1493
|
};
|
|
1469
|
-
}, [mero, contextIdsKey]);
|
|
1494
|
+
}, [mero, contextIdsKey, groupIdsKey]);
|
|
1470
1495
|
}
|
|
1471
1496
|
function useContexts(applicationId) {
|
|
1472
1497
|
const { mero } = useMero();
|
|
@@ -2117,6 +2142,18 @@ function useUpgradeGroup() {
|
|
|
2117
2142
|
);
|
|
2118
2143
|
return { upgradeGroup, loading, error };
|
|
2119
2144
|
}
|
|
2145
|
+
function useInstallFromRegistry() {
|
|
2146
|
+
const { mero } = useMero();
|
|
2147
|
+
const { loading, error, run } = useAsyncMutation();
|
|
2148
|
+
const installFromRegistry = react.useCallback(
|
|
2149
|
+
async (registryUrl, packageName, version) => {
|
|
2150
|
+
if (!mero) return null;
|
|
2151
|
+
return run(() => mero.admin.installFromRegistry(registryUrl, packageName, version));
|
|
2152
|
+
},
|
|
2153
|
+
[mero, run]
|
|
2154
|
+
);
|
|
2155
|
+
return { installFromRegistry, loading, error };
|
|
2156
|
+
}
|
|
2120
2157
|
function useResyncContext() {
|
|
2121
2158
|
const { mero } = useMero();
|
|
2122
2159
|
const { loading, error, run } = useAsyncMutation();
|
|
@@ -2393,6 +2430,96 @@ function useLatestVersion(registryUrl, packageName, currentVersion) {
|
|
|
2393
2430
|
const updateAvailable = latestVersion != null && currentVersion != null && meroJs.compareSemver(latestVersion, currentVersion) > 0;
|
|
2394
2431
|
return { versions, latestVersion, currentVersion, updateAvailable, loading, error, refetch };
|
|
2395
2432
|
}
|
|
2433
|
+
var EMPTY_GROUP_APP_VERSION = {
|
|
2434
|
+
version: null,
|
|
2435
|
+
applicationId: null,
|
|
2436
|
+
pendingApply: false,
|
|
2437
|
+
upgradePolicy: null,
|
|
2438
|
+
activeUpgrade: null
|
|
2439
|
+
};
|
|
2440
|
+
function isZeroAppKey(appKey) {
|
|
2441
|
+
return !appKey || /^0+$/.test(appKey);
|
|
2442
|
+
}
|
|
2443
|
+
function useGroupAppVersion(groupId) {
|
|
2444
|
+
const { mero } = useMero();
|
|
2445
|
+
const [data, setData] = react.useState(EMPTY_GROUP_APP_VERSION);
|
|
2446
|
+
const [loading, setLoading] = react.useState(false);
|
|
2447
|
+
const [error, setError] = react.useState(null);
|
|
2448
|
+
const mountedRef = useMountedRef();
|
|
2449
|
+
const reqRef = react.useRef(0);
|
|
2450
|
+
const refetch = react.useCallback(async () => {
|
|
2451
|
+
const seq = ++reqRef.current;
|
|
2452
|
+
if (!mero || !groupId) {
|
|
2453
|
+
if (mountedRef.current) {
|
|
2454
|
+
setData(EMPTY_GROUP_APP_VERSION);
|
|
2455
|
+
setError(null);
|
|
2456
|
+
setLoading(false);
|
|
2457
|
+
}
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2460
|
+
if (mountedRef.current) {
|
|
2461
|
+
setLoading(true);
|
|
2462
|
+
setError(null);
|
|
2463
|
+
}
|
|
2464
|
+
try {
|
|
2465
|
+
const namespaces = await mero.admin.listNamespaces();
|
|
2466
|
+
const namespace = namespaces.find((entry) => entry.namespaceId === groupId);
|
|
2467
|
+
let appKey;
|
|
2468
|
+
let applicationId;
|
|
2469
|
+
let upgradePolicy;
|
|
2470
|
+
let activeUpgrade = null;
|
|
2471
|
+
if (namespace) {
|
|
2472
|
+
appKey = namespace.appKey;
|
|
2473
|
+
applicationId = namespace.targetApplicationId;
|
|
2474
|
+
upgradePolicy = namespace.upgradePolicy;
|
|
2475
|
+
} else {
|
|
2476
|
+
const info = await mero.admin.getGroupInfo(groupId);
|
|
2477
|
+
appKey = info.appKey;
|
|
2478
|
+
applicationId = info.targetApplicationId;
|
|
2479
|
+
upgradePolicy = info.upgradePolicy;
|
|
2480
|
+
activeUpgrade = info.activeUpgrade ?? null;
|
|
2481
|
+
}
|
|
2482
|
+
let version = null;
|
|
2483
|
+
let pendingApply = false;
|
|
2484
|
+
if (applicationId) {
|
|
2485
|
+
const { application } = await mero.admin.getApplication(applicationId);
|
|
2486
|
+
version = application?.version ?? null;
|
|
2487
|
+
if (application && !isZeroAppKey(appKey)) {
|
|
2488
|
+
const installedHex = base58ToHex(application.blob.bytecode).toLowerCase();
|
|
2489
|
+
pendingApply = appKey.toLowerCase() !== installedHex;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
if (mountedRef.current && seq === reqRef.current) {
|
|
2493
|
+
setData({ version, applicationId, pendingApply, upgradePolicy, activeUpgrade });
|
|
2494
|
+
}
|
|
2495
|
+
} catch (err) {
|
|
2496
|
+
const errorValue = toError(err);
|
|
2497
|
+
if (mountedRef.current && seq === reqRef.current) {
|
|
2498
|
+
setError(errorValue);
|
|
2499
|
+
}
|
|
2500
|
+
} finally {
|
|
2501
|
+
if (mountedRef.current && seq === reqRef.current) {
|
|
2502
|
+
setLoading(false);
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
}, [groupId, mero, mountedRef]);
|
|
2506
|
+
react.useEffect(() => {
|
|
2507
|
+
reqRef.current += 1;
|
|
2508
|
+
setData(EMPTY_GROUP_APP_VERSION);
|
|
2509
|
+
setError(null);
|
|
2510
|
+
}, [groupId]);
|
|
2511
|
+
react.useEffect(() => {
|
|
2512
|
+
void refetch();
|
|
2513
|
+
}, [refetch]);
|
|
2514
|
+
react.useEffect(() => {
|
|
2515
|
+
if (!mero?.events || !groupId) return;
|
|
2516
|
+
const off = mero.events.onAppVersionChanged(() => {
|
|
2517
|
+
if (mountedRef.current) void refetch();
|
|
2518
|
+
});
|
|
2519
|
+
return off;
|
|
2520
|
+
}, [mero, groupId, refetch, mountedRef]);
|
|
2521
|
+
return { ...data, loading, error, refetch };
|
|
2522
|
+
}
|
|
2396
2523
|
function useMyAuthoredMigration(contextId) {
|
|
2397
2524
|
const { mero } = useMero();
|
|
2398
2525
|
const [summary, setSummary] = react.useState(null);
|
|
@@ -2602,6 +2729,7 @@ exports.useDeleteGroup = useDeleteGroup;
|
|
|
2602
2729
|
exports.useDeleteNamespace = useDeleteNamespace;
|
|
2603
2730
|
exports.useDetachContextFromGroup = useDetachContextFromGroup;
|
|
2604
2731
|
exports.useExecute = useExecute;
|
|
2732
|
+
exports.useGroupAppVersion = useGroupAppVersion;
|
|
2605
2733
|
exports.useGroupCapabilities = useGroupCapabilities;
|
|
2606
2734
|
exports.useGroupContexts = useGroupContexts;
|
|
2607
2735
|
exports.useGroupInfo = useGroupInfo;
|
|
@@ -2609,6 +2737,7 @@ exports.useGroupInvitations = useGroupInvitations;
|
|
|
2609
2737
|
exports.useGroupMembers = useGroupMembers;
|
|
2610
2738
|
exports.useGroupMetadata = useGroupMetadata;
|
|
2611
2739
|
exports.useGroupUpgradeStatus = useGroupUpgradeStatus;
|
|
2740
|
+
exports.useInstallFromRegistry = useInstallFromRegistry;
|
|
2612
2741
|
exports.useJoinContext = useJoinContext;
|
|
2613
2742
|
exports.useJoinGroup = useJoinGroup;
|
|
2614
2743
|
exports.useJoinNamespace = useJoinNamespace;
|