@calimero-network/mero-react 9.11.0 → 9.11.2
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 +4 -1
- package/dist/index.cjs +238 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -31
- package/dist/index.d.ts +11 -31
- package/dist/index.js +239 -338
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1599,26 +1599,29 @@ function MeroProvider({
|
|
|
1599
1599
|
setIsLoading(false);
|
|
1600
1600
|
if (!nodeKey) return;
|
|
1601
1601
|
}
|
|
1602
|
+
if (packageName) {
|
|
1603
|
+
try {
|
|
1604
|
+
const { applicationId: derived } = await resolveApplicationIdFromRegistry(
|
|
1605
|
+
registryUrl ?? DEFAULT_REGISTRY_URL,
|
|
1606
|
+
packageName
|
|
1607
|
+
);
|
|
1608
|
+
if (!active) return;
|
|
1609
|
+
setApplicationIdState(derived);
|
|
1610
|
+
return;
|
|
1611
|
+
} catch (e) {
|
|
1612
|
+
console.warn(`[mero-react] could not learn the application id of ${packageName} from the registry`, e);
|
|
1613
|
+
if (!active) return;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1602
1616
|
try {
|
|
1603
1617
|
const contexts = await listDelegatedContexts(delegated);
|
|
1618
|
+
if (!active) return;
|
|
1604
1619
|
const apps = [
|
|
1605
1620
|
...new Set((contexts ?? []).map((c) => c.applicationId).filter(Boolean))
|
|
1606
1621
|
];
|
|
1607
|
-
if (!active) return;
|
|
1608
1622
|
if (apps.length === 1) {
|
|
1609
1623
|
setApplicationIdState(apps[0]);
|
|
1610
1624
|
}
|
|
1611
|
-
if (apps.length === 0 && packageName) {
|
|
1612
|
-
try {
|
|
1613
|
-
const { applicationId: derived } = await resolveApplicationIdFromRegistry(
|
|
1614
|
-
registryUrl ?? DEFAULT_REGISTRY_URL,
|
|
1615
|
-
packageName
|
|
1616
|
-
);
|
|
1617
|
-
if (active) setApplicationIdState(derived);
|
|
1618
|
-
} catch (e) {
|
|
1619
|
-
console.warn(`[mero-react] could not learn the application id of ${packageName} from the registry`, e);
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
1625
|
} catch {
|
|
1623
1626
|
}
|
|
1624
1627
|
})();
|
|
@@ -3130,6 +3133,8 @@ function base58ToHex(input) {
|
|
|
3130
3133
|
for (let k = 0; k < input.length && input[k] === "1"; k++) bytes.push(0);
|
|
3131
3134
|
return bytes.reverse().map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3132
3135
|
}
|
|
3136
|
+
|
|
3137
|
+
// src/hooks/index.ts
|
|
3133
3138
|
var NO_EPHEMERAL_SURFACE_MESSAGE = "useEphemeral: this client has no `mero.ephemeral` surface. Ephemeral presence requires @calimero-network/mero-js >= 9.1.0; upgrade the installed @calimero-network/mero-js (and any lockfile pin) to use it.";
|
|
3134
3139
|
var COULD_NOT_RESOLVE_IDENTITY_MESSAGE = "useEphemeral: could not resolve a local context identity, so your own presence cannot be filtered out. Pass includeSelf: true to accept this.";
|
|
3135
3140
|
var REPLAY_RECONCILE_MS = 50;
|
|
@@ -3495,9 +3500,9 @@ function useSubscription(input, callback) {
|
|
|
3495
3500
|
}, [mero, contextIdsKey, groupIdsKey]);
|
|
3496
3501
|
}
|
|
3497
3502
|
function useContexts(applicationId) {
|
|
3498
|
-
const {
|
|
3503
|
+
const { admin, isDelegated } = useMero();
|
|
3499
3504
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3500
|
-
|
|
3505
|
+
admin ? async () => {
|
|
3501
3506
|
if (isDelegated) {
|
|
3502
3507
|
const session = readDelegatedSession();
|
|
3503
3508
|
const listed = session ? await listDelegatedContexts(session) : [];
|
|
@@ -3506,11 +3511,11 @@ function useContexts(applicationId) {
|
|
|
3506
3511
|
);
|
|
3507
3512
|
return mapApplicationContexts(own);
|
|
3508
3513
|
}
|
|
3509
|
-
const response = applicationId ? await
|
|
3514
|
+
const response = applicationId ? await admin.getContextsForApplication(applicationId) : await admin.getContexts();
|
|
3510
3515
|
return mapApplicationContexts(response.contexts ?? []);
|
|
3511
3516
|
} : null,
|
|
3512
3517
|
[],
|
|
3513
|
-
[
|
|
3518
|
+
[admin, applicationId, isDelegated]
|
|
3514
3519
|
);
|
|
3515
3520
|
return { contexts: data, loading, error, refetch };
|
|
3516
3521
|
}
|
|
@@ -3518,11 +3523,11 @@ function useApplicationContexts(applicationId) {
|
|
|
3518
3523
|
return useContexts(applicationId);
|
|
3519
3524
|
}
|
|
3520
3525
|
function useGroupMembers(groupId) {
|
|
3521
|
-
const {
|
|
3526
|
+
const { admin } = useMero();
|
|
3522
3527
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3523
|
-
|
|
3528
|
+
admin && groupId ? () => admin.listGroupMembers(groupId) : null,
|
|
3524
3529
|
null,
|
|
3525
|
-
[
|
|
3530
|
+
[admin, groupId]
|
|
3526
3531
|
);
|
|
3527
3532
|
return {
|
|
3528
3533
|
members: data?.members ?? [],
|
|
@@ -3532,44 +3537,44 @@ function useGroupMembers(groupId) {
|
|
|
3532
3537
|
};
|
|
3533
3538
|
}
|
|
3534
3539
|
function useGroupContexts(groupId) {
|
|
3535
|
-
const {
|
|
3540
|
+
const { admin } = useMero();
|
|
3536
3541
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3537
|
-
|
|
3542
|
+
admin && groupId ? () => admin.listGroupContexts(groupId) : null,
|
|
3538
3543
|
[],
|
|
3539
|
-
[
|
|
3544
|
+
[admin, groupId]
|
|
3540
3545
|
);
|
|
3541
3546
|
return { contexts: data, loading, error, refetch };
|
|
3542
3547
|
}
|
|
3543
3548
|
function useGroupInvitations() {
|
|
3544
|
-
const {
|
|
3549
|
+
const { admin } = useMero();
|
|
3545
3550
|
const { loading, error, run } = useAsyncMutation();
|
|
3546
3551
|
const createInvitation = react.useCallback(
|
|
3547
3552
|
async (groupId, request) => {
|
|
3548
|
-
if (!
|
|
3553
|
+
if (!admin) {
|
|
3549
3554
|
return null;
|
|
3550
3555
|
}
|
|
3551
|
-
return run(() =>
|
|
3556
|
+
return run(() => admin.createGroupInvitation(groupId, request));
|
|
3552
3557
|
},
|
|
3553
|
-
[
|
|
3558
|
+
[admin, run]
|
|
3554
3559
|
);
|
|
3555
3560
|
return { createInvitation, loading, error };
|
|
3556
3561
|
}
|
|
3557
3562
|
function useJoinGroup() {
|
|
3558
|
-
const {
|
|
3563
|
+
const { admin } = useMero();
|
|
3559
3564
|
const { loading, error, run } = useAsyncMutation();
|
|
3560
3565
|
const joinGroup = react.useCallback(
|
|
3561
3566
|
async (request) => {
|
|
3562
|
-
if (!
|
|
3567
|
+
if (!admin) {
|
|
3563
3568
|
return null;
|
|
3564
3569
|
}
|
|
3565
|
-
return run(() =>
|
|
3570
|
+
return run(() => admin.joinGroup(request));
|
|
3566
3571
|
},
|
|
3567
|
-
[
|
|
3572
|
+
[admin, run]
|
|
3568
3573
|
);
|
|
3569
3574
|
return { joinGroup, loading, error };
|
|
3570
3575
|
}
|
|
3571
3576
|
function useGroupCapabilities(groupId, memberId) {
|
|
3572
|
-
const {
|
|
3577
|
+
const { admin } = useMero();
|
|
3573
3578
|
const [capabilities, setCapabilitiesState] = react.useState(null);
|
|
3574
3579
|
const [loading, setLoading] = react.useState(false);
|
|
3575
3580
|
const [error, setError] = react.useState(null);
|
|
@@ -3577,7 +3582,7 @@ function useGroupCapabilities(groupId, memberId) {
|
|
|
3577
3582
|
const reqRef = react.useRef(0);
|
|
3578
3583
|
const refetch = react.useCallback(async () => {
|
|
3579
3584
|
const seq = ++reqRef.current;
|
|
3580
|
-
if (!
|
|
3585
|
+
if (!admin || !groupId || !memberId) {
|
|
3581
3586
|
if (mountedRef.current && seq === reqRef.current) {
|
|
3582
3587
|
setCapabilitiesState(null);
|
|
3583
3588
|
setError(null);
|
|
@@ -3590,7 +3595,7 @@ function useGroupCapabilities(groupId, memberId) {
|
|
|
3590
3595
|
setError(null);
|
|
3591
3596
|
}
|
|
3592
3597
|
try {
|
|
3593
|
-
const response = await
|
|
3598
|
+
const response = await admin.getMemberCapabilities(groupId, memberId);
|
|
3594
3599
|
if (mountedRef.current && seq === reqRef.current) {
|
|
3595
3600
|
setCapabilitiesState(response.capabilities);
|
|
3596
3601
|
}
|
|
@@ -3606,7 +3611,7 @@ function useGroupCapabilities(groupId, memberId) {
|
|
|
3606
3611
|
setLoading(false);
|
|
3607
3612
|
}
|
|
3608
3613
|
}
|
|
3609
|
-
}, [groupId, memberId,
|
|
3614
|
+
}, [groupId, memberId, admin, mountedRef]);
|
|
3610
3615
|
react.useEffect(() => {
|
|
3611
3616
|
reqRef.current += 1;
|
|
3612
3617
|
setCapabilitiesState(null);
|
|
@@ -3617,7 +3622,7 @@ function useGroupCapabilities(groupId, memberId) {
|
|
|
3617
3622
|
}, [refetch]);
|
|
3618
3623
|
const setCapabilities = react.useCallback(
|
|
3619
3624
|
async (nextCapabilities) => {
|
|
3620
|
-
if (!
|
|
3625
|
+
if (!admin || !groupId || !memberId) {
|
|
3621
3626
|
return null;
|
|
3622
3627
|
}
|
|
3623
3628
|
if (mountedRef.current) {
|
|
@@ -3625,7 +3630,7 @@ function useGroupCapabilities(groupId, memberId) {
|
|
|
3625
3630
|
setError(null);
|
|
3626
3631
|
}
|
|
3627
3632
|
try {
|
|
3628
|
-
await
|
|
3633
|
+
await admin.setMemberCapabilities(groupId, memberId, { capabilities: nextCapabilities });
|
|
3629
3634
|
if (mountedRef.current) {
|
|
3630
3635
|
setCapabilitiesState(nextCapabilities);
|
|
3631
3636
|
}
|
|
@@ -3642,19 +3647,19 @@ function useGroupCapabilities(groupId, memberId) {
|
|
|
3642
3647
|
}
|
|
3643
3648
|
}
|
|
3644
3649
|
},
|
|
3645
|
-
[groupId, memberId,
|
|
3650
|
+
[groupId, memberId, admin, mountedRef]
|
|
3646
3651
|
);
|
|
3647
3652
|
return { capabilities, loading, error, refetch, setCapabilities };
|
|
3648
3653
|
}
|
|
3649
3654
|
function useContextDiscovery(options) {
|
|
3650
|
-
const {
|
|
3655
|
+
const { admin } = useMero();
|
|
3651
3656
|
const [context, setContext] = react.useState(null);
|
|
3652
3657
|
const [loading, setLoading] = react.useState(false);
|
|
3653
3658
|
const [error, setError] = react.useState(null);
|
|
3654
3659
|
const mountedRef = useMountedRef();
|
|
3655
3660
|
const knownContextIdsKey = JSON.stringify(options.knownContextIds ?? []);
|
|
3656
3661
|
const discover = react.useCallback(async () => {
|
|
3657
|
-
if (!
|
|
3662
|
+
if (!admin) {
|
|
3658
3663
|
const notConnectedError = new Error("Not connected");
|
|
3659
3664
|
if (mountedRef.current) {
|
|
3660
3665
|
setError(notConnectedError);
|
|
@@ -3673,7 +3678,7 @@ function useContextDiscovery(options) {
|
|
|
3673
3678
|
while (Date.now() <= deadline) {
|
|
3674
3679
|
if (options.targetAlias) {
|
|
3675
3680
|
const aliasMatch = extractAliasContextId(
|
|
3676
|
-
await
|
|
3681
|
+
await admin.lookupContextAlias(options.targetAlias)
|
|
3677
3682
|
);
|
|
3678
3683
|
if (aliasMatch && !knownContextIds.has(aliasMatch)) {
|
|
3679
3684
|
const discoveredFromAlias = {
|
|
@@ -3686,7 +3691,7 @@ function useContextDiscovery(options) {
|
|
|
3686
3691
|
return discoveredFromAlias;
|
|
3687
3692
|
}
|
|
3688
3693
|
}
|
|
3689
|
-
const response = await
|
|
3694
|
+
const response = await admin.getContextsForApplication(options.applicationId);
|
|
3690
3695
|
const contexts = mapApplicationContexts(response.contexts ?? []);
|
|
3691
3696
|
const discovered = contexts.find(
|
|
3692
3697
|
(applicationContext) => !knownContextIds.has(applicationContext.contextId)
|
|
@@ -3724,7 +3729,7 @@ function useContextDiscovery(options) {
|
|
|
3724
3729
|
}
|
|
3725
3730
|
}, [
|
|
3726
3731
|
knownContextIdsKey,
|
|
3727
|
-
|
|
3732
|
+
admin,
|
|
3728
3733
|
mountedRef,
|
|
3729
3734
|
options.applicationId,
|
|
3730
3735
|
options.knownContextIds,
|
|
@@ -3742,7 +3747,7 @@ function useContextDiscovery(options) {
|
|
|
3742
3747
|
return { context, loading, error, discover, reset };
|
|
3743
3748
|
}
|
|
3744
3749
|
function useCreateContext() {
|
|
3745
|
-
const {
|
|
3750
|
+
const { admin, isDelegated } = useMero();
|
|
3746
3751
|
const { loading, error, run } = useAsyncMutation();
|
|
3747
3752
|
const createContext2 = react.useCallback(
|
|
3748
3753
|
async (request) => {
|
|
@@ -3757,15 +3762,15 @@ function useCreateContext() {
|
|
|
3757
3762
|
})
|
|
3758
3763
|
);
|
|
3759
3764
|
}
|
|
3760
|
-
if (!
|
|
3761
|
-
return run(() =>
|
|
3765
|
+
if (!admin) return null;
|
|
3766
|
+
return run(() => admin.createContext(request));
|
|
3762
3767
|
},
|
|
3763
|
-
[
|
|
3768
|
+
[admin, run, isDelegated]
|
|
3764
3769
|
);
|
|
3765
3770
|
return { createContext: createContext2, loading, error };
|
|
3766
3771
|
}
|
|
3767
3772
|
function useCreatePrivateContext() {
|
|
3768
|
-
const {
|
|
3773
|
+
const { admin, isDelegated } = useMero();
|
|
3769
3774
|
const { loading, error, run } = useAsyncMutation();
|
|
3770
3775
|
const createPrivateContext = react.useCallback(
|
|
3771
3776
|
async (request) => {
|
|
@@ -3774,15 +3779,15 @@ function useCreatePrivateContext() {
|
|
|
3774
3779
|
if (!session) return null;
|
|
3775
3780
|
return run(() => createDelegatedPrivateContext(session, request));
|
|
3776
3781
|
}
|
|
3777
|
-
if (!
|
|
3782
|
+
if (!admin) return null;
|
|
3778
3783
|
return run(async () => {
|
|
3779
|
-
const { groupId } = await
|
|
3784
|
+
const { groupId } = await admin.createGroupInNamespace(request.namespaceId, {
|
|
3780
3785
|
visibility: "restricted"
|
|
3781
3786
|
});
|
|
3782
|
-
await
|
|
3787
|
+
await admin.addGroupMembers(groupId, {
|
|
3783
3788
|
members: request.members.map((identity) => ({ identity, role: "Member" }))
|
|
3784
3789
|
});
|
|
3785
|
-
const { contextId } = await
|
|
3790
|
+
const { contextId } = await admin.createContext({
|
|
3786
3791
|
applicationId: request.applicationId,
|
|
3787
3792
|
groupId,
|
|
3788
3793
|
initializationParams: request.initializationParams
|
|
@@ -3790,36 +3795,36 @@ function useCreatePrivateContext() {
|
|
|
3790
3795
|
return { contextId };
|
|
3791
3796
|
});
|
|
3792
3797
|
},
|
|
3793
|
-
[
|
|
3798
|
+
[admin, run, isDelegated]
|
|
3794
3799
|
);
|
|
3795
3800
|
return { createPrivateContext, loading, error };
|
|
3796
3801
|
}
|
|
3797
3802
|
function useDeleteContext() {
|
|
3798
|
-
const {
|
|
3803
|
+
const { admin } = useMero();
|
|
3799
3804
|
const { loading, error, run } = useAsyncMutation();
|
|
3800
3805
|
const deleteContext = react.useCallback(
|
|
3801
3806
|
async (contextId) => {
|
|
3802
|
-
if (!
|
|
3803
|
-
return run(() =>
|
|
3807
|
+
if (!admin) return null;
|
|
3808
|
+
return run(() => admin.deleteContext(contextId));
|
|
3804
3809
|
},
|
|
3805
|
-
[
|
|
3810
|
+
[admin, run]
|
|
3806
3811
|
);
|
|
3807
3812
|
return { deleteContext, loading, error };
|
|
3808
3813
|
}
|
|
3809
3814
|
function useJoinContext(options = {}) {
|
|
3810
|
-
const {
|
|
3815
|
+
const { admin } = useMero();
|
|
3811
3816
|
const { loading, error, failure, run } = useAsyncMutation(options);
|
|
3812
3817
|
const joinContext = react.useCallback(
|
|
3813
3818
|
async (contextId) => {
|
|
3814
|
-
if (!
|
|
3815
|
-
return run(() =>
|
|
3819
|
+
if (!admin) return null;
|
|
3820
|
+
return run(() => admin.joinContext(contextId));
|
|
3816
3821
|
},
|
|
3817
|
-
[
|
|
3822
|
+
[admin, run]
|
|
3818
3823
|
);
|
|
3819
3824
|
return { joinContext, loading, error, failure };
|
|
3820
3825
|
}
|
|
3821
3826
|
function useJoinSubgroupInheritance() {
|
|
3822
|
-
const {
|
|
3827
|
+
const { admin, isDelegated } = useMero();
|
|
3823
3828
|
const { loading, error, run } = useAsyncMutation();
|
|
3824
3829
|
const joinSubgroupInheritance = react.useCallback(
|
|
3825
3830
|
async (groupId) => {
|
|
@@ -3832,425 +3837,334 @@ function useJoinSubgroupInheritance() {
|
|
|
3832
3837
|
return { groupId, memberPublicKey: publicKey, wasInherited: false };
|
|
3833
3838
|
});
|
|
3834
3839
|
}
|
|
3835
|
-
if (!
|
|
3836
|
-
return run(() =>
|
|
3840
|
+
if (!admin) return null;
|
|
3841
|
+
return run(() => admin.joinSubgroupInheritance(groupId));
|
|
3837
3842
|
},
|
|
3838
|
-
[
|
|
3843
|
+
[admin, run, isDelegated]
|
|
3839
3844
|
);
|
|
3840
3845
|
return { joinSubgroupInheritance, loading, error };
|
|
3841
3846
|
}
|
|
3842
3847
|
function useContextGroup(contextId) {
|
|
3843
|
-
const {
|
|
3848
|
+
const { admin } = useMero();
|
|
3844
3849
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3845
|
-
|
|
3850
|
+
admin && contextId ? () => admin.getContextGroup(contextId) : null,
|
|
3846
3851
|
null,
|
|
3847
|
-
[
|
|
3852
|
+
[admin, contextId]
|
|
3848
3853
|
);
|
|
3849
3854
|
return { groupId: data, loading, error, refetch };
|
|
3850
3855
|
}
|
|
3851
3856
|
function useGroupInfo(groupId) {
|
|
3852
|
-
const {
|
|
3857
|
+
const { admin } = useMero();
|
|
3853
3858
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3854
|
-
|
|
3859
|
+
admin && groupId ? () => admin.getGroupInfo(groupId) : null,
|
|
3855
3860
|
null,
|
|
3856
|
-
[
|
|
3861
|
+
[admin, groupId]
|
|
3857
3862
|
);
|
|
3858
3863
|
return { groupInfo: data, loading, error, refetch };
|
|
3859
3864
|
}
|
|
3860
3865
|
function useDeleteGroup() {
|
|
3861
|
-
const {
|
|
3866
|
+
const { admin } = useMero();
|
|
3862
3867
|
const { loading, error, run } = useAsyncMutation();
|
|
3863
3868
|
const deleteGroup = react.useCallback(
|
|
3864
3869
|
async (groupId) => {
|
|
3865
|
-
if (
|
|
3866
|
-
|
|
3867
|
-
if (!session) return null;
|
|
3868
|
-
return run(() => governRoot(session, groupId, meroJs.groupDeletedOp(groupId)));
|
|
3869
|
-
}
|
|
3870
|
-
if (!mero) return null;
|
|
3871
|
-
return run(() => mero.admin.deleteGroup(groupId));
|
|
3870
|
+
if (!admin) return null;
|
|
3871
|
+
return run(() => admin.deleteGroup(groupId));
|
|
3872
3872
|
},
|
|
3873
|
-
[
|
|
3873
|
+
[admin, run]
|
|
3874
3874
|
);
|
|
3875
3875
|
return { deleteGroup, loading, error };
|
|
3876
3876
|
}
|
|
3877
3877
|
function useSyncGroup() {
|
|
3878
|
-
const {
|
|
3878
|
+
const { admin } = useMero();
|
|
3879
3879
|
const { loading, error, run } = useAsyncMutation();
|
|
3880
3880
|
const syncGroup = react.useCallback(
|
|
3881
3881
|
async (groupId) => {
|
|
3882
|
-
if (!
|
|
3883
|
-
return run(() =>
|
|
3882
|
+
if (!admin) return null;
|
|
3883
|
+
return run(() => admin.syncGroup(groupId));
|
|
3884
3884
|
},
|
|
3885
|
-
[
|
|
3885
|
+
[admin, run]
|
|
3886
3886
|
);
|
|
3887
3887
|
return { syncGroup, loading, error };
|
|
3888
3888
|
}
|
|
3889
3889
|
function useAddGroupMembers() {
|
|
3890
|
-
const {
|
|
3890
|
+
const { admin } = useMero();
|
|
3891
3891
|
const { loading, error, run } = useAsyncMutation();
|
|
3892
3892
|
const addGroupMembers = react.useCallback(
|
|
3893
3893
|
async (groupId, request) => {
|
|
3894
|
-
if (
|
|
3895
|
-
|
|
3896
|
-
if (!session) return null;
|
|
3897
|
-
return run(async () => {
|
|
3898
|
-
for (const m of request.members) {
|
|
3899
|
-
await governGroup(session, groupId, meroJs.memberAddedOp(m.identity, m.role));
|
|
3900
|
-
}
|
|
3901
|
-
});
|
|
3902
|
-
}
|
|
3903
|
-
if (!mero) return null;
|
|
3904
|
-
return run(() => mero.admin.addGroupMembers(groupId, request));
|
|
3894
|
+
if (!admin) return null;
|
|
3895
|
+
return run(() => admin.addGroupMembers(groupId, request));
|
|
3905
3896
|
},
|
|
3906
|
-
[
|
|
3897
|
+
[admin, run]
|
|
3907
3898
|
);
|
|
3908
3899
|
return { addGroupMembers, loading, error };
|
|
3909
3900
|
}
|
|
3910
3901
|
function useRemoveGroupMembers() {
|
|
3911
|
-
const {
|
|
3902
|
+
const { admin } = useMero();
|
|
3912
3903
|
const { loading, error, run } = useAsyncMutation();
|
|
3913
3904
|
const removeGroupMembers = react.useCallback(
|
|
3914
3905
|
async (groupId, request) => {
|
|
3915
|
-
if (
|
|
3916
|
-
|
|
3917
|
-
if (!session) return null;
|
|
3918
|
-
return run(async () => {
|
|
3919
|
-
for (const member of request.members) await governGroup(session, groupId, meroJs.memberRemovedOp(member));
|
|
3920
|
-
});
|
|
3921
|
-
}
|
|
3922
|
-
if (!mero) return null;
|
|
3923
|
-
return run(() => mero.admin.removeGroupMembers(groupId, request));
|
|
3906
|
+
if (!admin) return null;
|
|
3907
|
+
return run(() => admin.removeGroupMembers(groupId, request));
|
|
3924
3908
|
},
|
|
3925
|
-
[
|
|
3909
|
+
[admin, run]
|
|
3926
3910
|
);
|
|
3927
3911
|
return { removeGroupMembers, loading, error };
|
|
3928
3912
|
}
|
|
3929
3913
|
function useNamespaces() {
|
|
3930
|
-
const {
|
|
3914
|
+
const { admin } = useMero();
|
|
3931
3915
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3932
|
-
|
|
3916
|
+
admin ? () => admin.listNamespaces() : null,
|
|
3933
3917
|
[],
|
|
3934
|
-
[
|
|
3918
|
+
[admin]
|
|
3935
3919
|
);
|
|
3936
3920
|
return { namespaces: data, loading, error, refetch };
|
|
3937
3921
|
}
|
|
3938
3922
|
function useNamespace(namespaceId) {
|
|
3939
|
-
const {
|
|
3923
|
+
const { admin } = useMero();
|
|
3940
3924
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3941
|
-
|
|
3925
|
+
admin && namespaceId ? () => admin.getNamespace(namespaceId) : null,
|
|
3942
3926
|
null,
|
|
3943
|
-
[
|
|
3927
|
+
[admin, namespaceId]
|
|
3944
3928
|
);
|
|
3945
3929
|
return { namespace: data, loading, error, refetch };
|
|
3946
3930
|
}
|
|
3947
3931
|
function useNodeIdentity() {
|
|
3948
|
-
const {
|
|
3932
|
+
const { admin } = useMero();
|
|
3949
3933
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3950
|
-
|
|
3934
|
+
admin ? () => admin.getNodeIdentity() : null,
|
|
3951
3935
|
null,
|
|
3952
|
-
[
|
|
3936
|
+
[admin]
|
|
3953
3937
|
);
|
|
3954
3938
|
return { identity: data, loading, error, refetch };
|
|
3955
3939
|
}
|
|
3956
3940
|
function useNamespaceIdentity(namespaceId) {
|
|
3957
|
-
const {
|
|
3941
|
+
const { admin } = useMero();
|
|
3958
3942
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3959
|
-
|
|
3943
|
+
admin && namespaceId ? () => admin.getNamespaceIdentity(namespaceId) : null,
|
|
3960
3944
|
null,
|
|
3961
|
-
[
|
|
3945
|
+
[admin, namespaceId]
|
|
3962
3946
|
);
|
|
3963
3947
|
return { identity: data, loading, error, refetch };
|
|
3964
3948
|
}
|
|
3965
3949
|
function useNamespacesForApplication(applicationId) {
|
|
3966
|
-
const {
|
|
3950
|
+
const { admin, isDelegated } = useMero();
|
|
3967
3951
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
3968
|
-
|
|
3952
|
+
admin && applicationId ? isDelegated ? async () => {
|
|
3969
3953
|
const session = readDelegatedSession();
|
|
3970
3954
|
const listed = session ? await listDelegatedNamespaces(session) : [];
|
|
3971
3955
|
return listed.filter((ns) => ns.targetApplicationId === applicationId);
|
|
3972
|
-
} : () =>
|
|
3956
|
+
} : () => admin.listNamespacesForApplication(applicationId) : null,
|
|
3973
3957
|
[],
|
|
3974
|
-
[
|
|
3958
|
+
[admin, applicationId, isDelegated]
|
|
3975
3959
|
);
|
|
3976
3960
|
return { namespaces: data, loading, error, refetch };
|
|
3977
3961
|
}
|
|
3978
|
-
var DEFAULT_REGISTRY_URL2 = "https://apps.calimero.network";
|
|
3979
3962
|
function useCreateNamespace() {
|
|
3980
|
-
const {
|
|
3963
|
+
const { admin } = useMero();
|
|
3981
3964
|
const { loading, error, run } = useAsyncMutation();
|
|
3982
3965
|
const createNamespace = react.useCallback(
|
|
3983
3966
|
async (request) => {
|
|
3984
|
-
if (
|
|
3985
|
-
|
|
3986
|
-
if (!session) return null;
|
|
3987
|
-
const pkg = app.packageName;
|
|
3988
|
-
return run(async () => {
|
|
3989
|
-
if (!pkg) {
|
|
3990
|
-
throw new Error("this app names no registry package, so a founded namespace could not be given its application");
|
|
3991
|
-
}
|
|
3992
|
-
const version = app.packageVersion ?? await latestPublishedVersion(app.registryUrl ?? DEFAULT_REGISTRY_URL2, pkg);
|
|
3993
|
-
return foundDelegatedNamespace(
|
|
3994
|
-
session,
|
|
3995
|
-
{
|
|
3996
|
-
defaultCapabilities: 231,
|
|
3997
|
-
application: { applicationId: request.applicationId, package: pkg, version }
|
|
3998
|
-
},
|
|
3999
|
-
{ cloudBaseUrl }
|
|
4000
|
-
);
|
|
4001
|
-
});
|
|
4002
|
-
}
|
|
4003
|
-
if (!mero) return null;
|
|
4004
|
-
return run(() => mero.admin.createNamespace(request));
|
|
3967
|
+
if (!admin) return null;
|
|
3968
|
+
return run(() => admin.createNamespace(request));
|
|
4005
3969
|
},
|
|
4006
|
-
[
|
|
3970
|
+
[admin, run]
|
|
4007
3971
|
);
|
|
4008
3972
|
return { createNamespace, loading, error };
|
|
4009
3973
|
}
|
|
4010
3974
|
function useDeleteNamespace() {
|
|
4011
|
-
const {
|
|
3975
|
+
const { admin } = useMero();
|
|
4012
3976
|
const { loading, error, run } = useAsyncMutation();
|
|
4013
3977
|
const deleteNamespace = react.useCallback(
|
|
4014
3978
|
async (namespaceId) => {
|
|
4015
|
-
if (!
|
|
4016
|
-
return run(() =>
|
|
3979
|
+
if (!admin) return null;
|
|
3980
|
+
return run(() => admin.deleteNamespace(namespaceId));
|
|
4017
3981
|
},
|
|
4018
|
-
[
|
|
3982
|
+
[admin, run]
|
|
4019
3983
|
);
|
|
4020
3984
|
return { deleteNamespace, loading, error };
|
|
4021
3985
|
}
|
|
4022
3986
|
function useCreateNamespaceInvitation() {
|
|
4023
|
-
const {
|
|
3987
|
+
const { admin } = useMero();
|
|
4024
3988
|
const { loading, error, run } = useAsyncMutation();
|
|
4025
3989
|
const createNamespaceInvitation = react.useCallback(
|
|
4026
3990
|
async (namespaceId, request) => {
|
|
4027
|
-
if (!
|
|
4028
|
-
return run(() =>
|
|
3991
|
+
if (!admin) return null;
|
|
3992
|
+
return run(() => admin.createNamespaceInvitation(namespaceId, request));
|
|
4029
3993
|
},
|
|
4030
|
-
[
|
|
3994
|
+
[admin, run]
|
|
4031
3995
|
);
|
|
4032
3996
|
return { createNamespaceInvitation, loading, error };
|
|
4033
3997
|
}
|
|
4034
3998
|
function useJoinNamespace(options = {}) {
|
|
4035
|
-
const {
|
|
3999
|
+
const { admin } = useMero();
|
|
4036
4000
|
const { loading, error, failure, run } = useAsyncMutation(options);
|
|
4037
4001
|
const joinNamespace = react.useCallback(
|
|
4038
4002
|
async (namespaceId, request) => {
|
|
4039
|
-
if (!
|
|
4040
|
-
return run(() =>
|
|
4003
|
+
if (!admin) return null;
|
|
4004
|
+
return run(() => admin.joinNamespace(namespaceId, request));
|
|
4041
4005
|
},
|
|
4042
|
-
[
|
|
4006
|
+
[admin, run]
|
|
4043
4007
|
);
|
|
4044
4008
|
return { joinNamespace, loading, error, failure };
|
|
4045
4009
|
}
|
|
4046
4010
|
function useRedeemInvitation() {
|
|
4047
|
-
const {
|
|
4011
|
+
const { admin } = useMero();
|
|
4048
4012
|
const mountedRef = useMountedRef();
|
|
4049
4013
|
const [loading, setLoading] = react.useState(false);
|
|
4050
4014
|
const [outcome, setOutcome] = react.useState(null);
|
|
4051
4015
|
const redeem = react.useCallback(
|
|
4052
4016
|
async (namespaceId, invitation, options = {}) => {
|
|
4053
|
-
if (!
|
|
4017
|
+
if (!admin) return null;
|
|
4054
4018
|
if (mountedRef.current) {
|
|
4055
4019
|
setLoading(true);
|
|
4056
4020
|
setOutcome(null);
|
|
4057
4021
|
}
|
|
4058
4022
|
try {
|
|
4059
|
-
const result = await
|
|
4023
|
+
const result = await admin.redeemInvitation(namespaceId, invitation, options);
|
|
4060
4024
|
if (mountedRef.current) setOutcome(result);
|
|
4061
4025
|
return result;
|
|
4062
4026
|
} finally {
|
|
4063
4027
|
if (mountedRef.current) setLoading(false);
|
|
4064
4028
|
}
|
|
4065
4029
|
},
|
|
4066
|
-
[
|
|
4030
|
+
[admin, mountedRef]
|
|
4067
4031
|
);
|
|
4068
4032
|
return { redeem, outcome, loading };
|
|
4069
4033
|
}
|
|
4070
4034
|
function useCreateGroupInNamespace() {
|
|
4071
|
-
const {
|
|
4035
|
+
const { admin } = useMero();
|
|
4072
4036
|
const { loading, error, run } = useAsyncMutation();
|
|
4073
4037
|
const createGroupInNamespace = react.useCallback(
|
|
4074
4038
|
async (namespaceId, request) => {
|
|
4075
|
-
if (
|
|
4076
|
-
|
|
4077
|
-
if (!session) return null;
|
|
4078
|
-
return run(async () => {
|
|
4079
|
-
const { groupId } = await governRoot(
|
|
4080
|
-
session,
|
|
4081
|
-
namespaceId,
|
|
4082
|
-
// The id is derived from a fresh salt (core#4244); a node refuses any other.
|
|
4083
|
-
(await meroJs.subgroupCreation({
|
|
4084
|
-
parentId: namespaceId,
|
|
4085
|
-
restricted: request?.visibility !== "open",
|
|
4086
|
-
admin: session.account
|
|
4087
|
-
})).op
|
|
4088
|
-
);
|
|
4089
|
-
rememberGroupNamespace(session.account, groupId, namespaceId);
|
|
4090
|
-
return { groupId };
|
|
4091
|
-
});
|
|
4092
|
-
}
|
|
4093
|
-
if (!mero) return null;
|
|
4094
|
-
return run(() => mero.admin.createGroupInNamespace(namespaceId, request));
|
|
4039
|
+
if (!admin) return null;
|
|
4040
|
+
return run(() => admin.createGroupInNamespace(namespaceId, request));
|
|
4095
4041
|
},
|
|
4096
|
-
[
|
|
4042
|
+
[admin, run]
|
|
4097
4043
|
);
|
|
4098
4044
|
return { createGroupInNamespace, loading, error };
|
|
4099
4045
|
}
|
|
4100
4046
|
function useNamespaceGroups(namespaceId) {
|
|
4101
|
-
const {
|
|
4047
|
+
const { admin } = useMero();
|
|
4102
4048
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
4103
|
-
|
|
4049
|
+
admin && namespaceId ? () => admin.listNamespaceGroups(namespaceId) : null,
|
|
4104
4050
|
[],
|
|
4105
|
-
[
|
|
4051
|
+
[admin, namespaceId]
|
|
4106
4052
|
);
|
|
4107
4053
|
return { groups: data, loading, error, refetch };
|
|
4108
4054
|
}
|
|
4109
4055
|
function useUpdateMemberRole() {
|
|
4110
|
-
const {
|
|
4056
|
+
const { admin } = useMero();
|
|
4111
4057
|
const { loading, error, run } = useAsyncMutation();
|
|
4112
4058
|
const updateMemberRole = react.useCallback(
|
|
4113
4059
|
async (groupId, identity, request) => {
|
|
4114
|
-
if (
|
|
4115
|
-
|
|
4116
|
-
if (!session) return null;
|
|
4117
|
-
return run(() => governGroup(session, groupId, meroJs.memberRoleSetOp(identity, request.role)));
|
|
4118
|
-
}
|
|
4119
|
-
if (!mero) return null;
|
|
4120
|
-
return run(() => mero.admin.updateMemberRole(groupId, identity, request));
|
|
4060
|
+
if (!admin) return null;
|
|
4061
|
+
return run(() => admin.updateMemberRole(groupId, identity, request));
|
|
4121
4062
|
},
|
|
4122
|
-
[
|
|
4063
|
+
[admin, run]
|
|
4123
4064
|
);
|
|
4124
4065
|
return { updateMemberRole, loading, error };
|
|
4125
4066
|
}
|
|
4126
4067
|
function useSetDefaultCapabilities() {
|
|
4127
|
-
const {
|
|
4068
|
+
const { admin } = useMero();
|
|
4128
4069
|
const { loading, error, run } = useAsyncMutation();
|
|
4129
4070
|
const setDefaultCapabilities = react.useCallback(
|
|
4130
4071
|
async (groupId, request) => {
|
|
4131
|
-
if (
|
|
4132
|
-
|
|
4133
|
-
if (!session) return null;
|
|
4134
|
-
return run(() => governGroup(session, groupId, meroJs.defaultCapabilitiesSetOp(request.defaultCapabilities)));
|
|
4135
|
-
}
|
|
4136
|
-
if (!mero) return null;
|
|
4137
|
-
return run(() => mero.admin.setDefaultCapabilities(groupId, request));
|
|
4072
|
+
if (!admin) return null;
|
|
4073
|
+
return run(() => admin.setDefaultCapabilities(groupId, request));
|
|
4138
4074
|
},
|
|
4139
|
-
[
|
|
4075
|
+
[admin, run]
|
|
4140
4076
|
);
|
|
4141
4077
|
return { setDefaultCapabilities, loading, error };
|
|
4142
4078
|
}
|
|
4143
4079
|
function useSetSubgroupVisibility() {
|
|
4144
|
-
const {
|
|
4080
|
+
const { admin } = useMero();
|
|
4145
4081
|
const { loading, error, run } = useAsyncMutation();
|
|
4146
4082
|
const setSubgroupVisibility = react.useCallback(
|
|
4147
4083
|
async (groupId, request) => {
|
|
4148
|
-
if (
|
|
4149
|
-
|
|
4150
|
-
if (!session) return null;
|
|
4151
|
-
return run(
|
|
4152
|
-
() => governGroup(session, groupId, meroJs.subgroupVisibilitySetOp(request.subgroupVisibility === "open" ? "open" : "restricted"))
|
|
4153
|
-
);
|
|
4154
|
-
}
|
|
4155
|
-
if (!mero) return null;
|
|
4156
|
-
return run(() => mero.admin.setSubgroupVisibility(groupId, request));
|
|
4084
|
+
if (!admin) return null;
|
|
4085
|
+
return run(() => admin.setSubgroupVisibility(groupId, request));
|
|
4157
4086
|
},
|
|
4158
|
-
[
|
|
4087
|
+
[admin, run]
|
|
4159
4088
|
);
|
|
4160
4089
|
return { setSubgroupVisibility, loading, error };
|
|
4161
4090
|
}
|
|
4162
4091
|
function useDefaultCapabilities(groupId) {
|
|
4163
|
-
const {
|
|
4092
|
+
const { admin } = useMero();
|
|
4164
4093
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
4165
|
-
|
|
4094
|
+
admin && groupId ? () => admin.getDefaultCapabilities(groupId) : null,
|
|
4166
4095
|
null,
|
|
4167
|
-
[
|
|
4096
|
+
[admin, groupId]
|
|
4168
4097
|
);
|
|
4169
4098
|
return { defaultCapabilities: data, loading, error, refetch };
|
|
4170
4099
|
}
|
|
4171
4100
|
function useSubgroupVisibility(groupId) {
|
|
4172
|
-
const {
|
|
4101
|
+
const { admin } = useMero();
|
|
4173
4102
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
4174
|
-
|
|
4103
|
+
admin && groupId ? () => admin.getSubgroupVisibility(groupId) : null,
|
|
4175
4104
|
null,
|
|
4176
|
-
[
|
|
4105
|
+
[admin, groupId]
|
|
4177
4106
|
);
|
|
4178
4107
|
return { subgroupVisibility: data, loading, error, refetch };
|
|
4179
4108
|
}
|
|
4180
4109
|
function useSetTeeAdmissionPolicy() {
|
|
4181
|
-
const {
|
|
4110
|
+
const { admin } = useMero();
|
|
4182
4111
|
const { loading, error, run } = useAsyncMutation();
|
|
4183
4112
|
const setTeeAdmissionPolicy = react.useCallback(
|
|
4184
4113
|
async (groupId, request) => {
|
|
4185
|
-
if (!
|
|
4186
|
-
return run(() =>
|
|
4114
|
+
if (!admin) return null;
|
|
4115
|
+
return run(() => admin.setTeeAdmissionPolicy(groupId, request));
|
|
4187
4116
|
},
|
|
4188
|
-
[
|
|
4117
|
+
[admin, run]
|
|
4189
4118
|
);
|
|
4190
4119
|
return { setTeeAdmissionPolicy, loading, error };
|
|
4191
4120
|
}
|
|
4192
4121
|
function useSetGroupMetadata() {
|
|
4193
|
-
const {
|
|
4122
|
+
const { admin } = useMero();
|
|
4194
4123
|
const { loading, error, run } = useAsyncMutation();
|
|
4195
4124
|
const setGroupMetadata = react.useCallback(
|
|
4196
4125
|
async (groupId, request) => {
|
|
4197
|
-
if (
|
|
4198
|
-
|
|
4199
|
-
if (!session) return null;
|
|
4200
|
-
return run(() => governGroup(session, groupId, meroJs.groupMetadataSetOp(request)));
|
|
4201
|
-
}
|
|
4202
|
-
if (!mero) return null;
|
|
4203
|
-
return run(() => mero.admin.setGroupMetadata(groupId, request));
|
|
4126
|
+
if (!admin) return null;
|
|
4127
|
+
return run(() => admin.setGroupMetadata(groupId, request));
|
|
4204
4128
|
},
|
|
4205
|
-
[
|
|
4129
|
+
[admin, run]
|
|
4206
4130
|
);
|
|
4207
4131
|
return { setGroupMetadata, loading, error };
|
|
4208
4132
|
}
|
|
4209
4133
|
function useSetMemberMetadata() {
|
|
4210
|
-
const {
|
|
4134
|
+
const { admin } = useMero();
|
|
4211
4135
|
const { loading, error, run } = useAsyncMutation();
|
|
4212
4136
|
const setMemberMetadata = react.useCallback(
|
|
4213
4137
|
async (groupId, identity, request) => {
|
|
4214
|
-
if (
|
|
4215
|
-
|
|
4216
|
-
if (!session) return null;
|
|
4217
|
-
return run(() => governGroup(session, groupId, meroJs.memberMetadataSetOp(identity, request)));
|
|
4218
|
-
}
|
|
4219
|
-
if (!mero) return null;
|
|
4220
|
-
return run(() => mero.admin.setMemberMetadata(groupId, identity, request));
|
|
4138
|
+
if (!admin) return null;
|
|
4139
|
+
return run(() => admin.setMemberMetadata(groupId, identity, request));
|
|
4221
4140
|
},
|
|
4222
|
-
[
|
|
4141
|
+
[admin, run]
|
|
4223
4142
|
);
|
|
4224
4143
|
return { setMemberMetadata, loading, error };
|
|
4225
4144
|
}
|
|
4226
4145
|
function useSetContextMetadata() {
|
|
4227
|
-
const {
|
|
4146
|
+
const { admin } = useMero();
|
|
4228
4147
|
const { loading, error, run } = useAsyncMutation();
|
|
4229
4148
|
const setContextMetadata = react.useCallback(
|
|
4230
4149
|
async (groupId, contextId, request) => {
|
|
4231
|
-
if (
|
|
4232
|
-
|
|
4233
|
-
if (!session) return null;
|
|
4234
|
-
return run(() => governGroup(session, groupId, meroJs.contextMetadataSetOp(contextId, request)));
|
|
4235
|
-
}
|
|
4236
|
-
if (!mero) return null;
|
|
4237
|
-
return run(() => mero.admin.setContextMetadata(groupId, contextId, request));
|
|
4150
|
+
if (!admin) return null;
|
|
4151
|
+
return run(() => admin.setContextMetadata(groupId, contextId, request));
|
|
4238
4152
|
},
|
|
4239
|
-
[
|
|
4153
|
+
[admin, run]
|
|
4240
4154
|
);
|
|
4241
4155
|
return { setContextMetadata, loading, error };
|
|
4242
4156
|
}
|
|
4243
4157
|
function useGroupMetadata(groupId) {
|
|
4244
|
-
const {
|
|
4158
|
+
const { admin } = useMero();
|
|
4245
4159
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
4246
|
-
|
|
4160
|
+
admin && groupId ? () => admin.getGroupMetadata(groupId) : null,
|
|
4247
4161
|
null,
|
|
4248
|
-
[
|
|
4162
|
+
[admin, groupId]
|
|
4249
4163
|
);
|
|
4250
4164
|
return { metadata: data, loading, error, refetch };
|
|
4251
4165
|
}
|
|
4252
4166
|
function useMemberMetadata(groupId, identity) {
|
|
4253
|
-
const {
|
|
4167
|
+
const { admin } = useMero();
|
|
4254
4168
|
const [metadata, setMetadata] = react.useState(null);
|
|
4255
4169
|
const [loading, setLoading] = react.useState(false);
|
|
4256
4170
|
const [error, setError] = react.useState(null);
|
|
@@ -4263,7 +4177,7 @@ function useMemberMetadata(groupId, identity) {
|
|
|
4263
4177
|
prevKey.current = key;
|
|
4264
4178
|
const run = react.useCallback(
|
|
4265
4179
|
async (signal) => {
|
|
4266
|
-
if (!
|
|
4180
|
+
if (!admin || !groupId || !identity) {
|
|
4267
4181
|
if (!signal.aborted) {
|
|
4268
4182
|
setMetadata(null);
|
|
4269
4183
|
setError(null);
|
|
@@ -4276,7 +4190,7 @@ function useMemberMetadata(groupId, identity) {
|
|
|
4276
4190
|
setError(null);
|
|
4277
4191
|
}
|
|
4278
4192
|
try {
|
|
4279
|
-
const result = await
|
|
4193
|
+
const result = await admin.getMemberMetadata(groupId, identity);
|
|
4280
4194
|
if (!signal.aborted) setMetadata(result);
|
|
4281
4195
|
} catch (err) {
|
|
4282
4196
|
if (!signal.aborted) setError(toError(err));
|
|
@@ -4284,7 +4198,7 @@ function useMemberMetadata(groupId, identity) {
|
|
|
4284
4198
|
if (!signal.aborted) setLoading(false);
|
|
4285
4199
|
}
|
|
4286
4200
|
},
|
|
4287
|
-
[
|
|
4201
|
+
[admin, groupId, identity]
|
|
4288
4202
|
);
|
|
4289
4203
|
react.useEffect(() => {
|
|
4290
4204
|
const signal = { aborted: false };
|
|
@@ -4300,43 +4214,43 @@ function useMemberMetadata(groupId, identity) {
|
|
|
4300
4214
|
return { metadata, loading, error, refetch };
|
|
4301
4215
|
}
|
|
4302
4216
|
function useUpgradeGroup() {
|
|
4303
|
-
const {
|
|
4217
|
+
const { admin } = useMero();
|
|
4304
4218
|
const { loading, error, run } = useAsyncMutation();
|
|
4305
4219
|
const upgradeGroup = react.useCallback(
|
|
4306
4220
|
async (groupId, request) => {
|
|
4307
|
-
if (!
|
|
4308
|
-
return run(() =>
|
|
4221
|
+
if (!admin) return null;
|
|
4222
|
+
return run(() => admin.upgradeGroup(groupId, request));
|
|
4309
4223
|
},
|
|
4310
|
-
[
|
|
4224
|
+
[admin, run]
|
|
4311
4225
|
);
|
|
4312
4226
|
return { upgradeGroup, loading, error };
|
|
4313
4227
|
}
|
|
4314
4228
|
function useInstallFromRegistry() {
|
|
4315
|
-
const {
|
|
4229
|
+
const { admin } = useMero();
|
|
4316
4230
|
const { loading, error, run } = useAsyncMutation();
|
|
4317
4231
|
const installFromRegistry = react.useCallback(
|
|
4318
4232
|
async (packageName, version) => {
|
|
4319
|
-
if (!
|
|
4320
|
-
return run(() =>
|
|
4233
|
+
if (!admin) return null;
|
|
4234
|
+
return run(() => admin.installApplication({ package: packageName, version }));
|
|
4321
4235
|
},
|
|
4322
|
-
[
|
|
4236
|
+
[admin, run]
|
|
4323
4237
|
);
|
|
4324
4238
|
return { installFromRegistry, loading, error };
|
|
4325
4239
|
}
|
|
4326
4240
|
function useResyncContext() {
|
|
4327
|
-
const {
|
|
4241
|
+
const { admin } = useMero();
|
|
4328
4242
|
const { loading, error, run } = useAsyncMutation();
|
|
4329
4243
|
const resyncContext = react.useCallback(
|
|
4330
4244
|
async (contextId, request = {}) => {
|
|
4331
|
-
if (!
|
|
4332
|
-
return run(() =>
|
|
4245
|
+
if (!admin) return null;
|
|
4246
|
+
return run(() => admin.resyncContext(contextId, request));
|
|
4333
4247
|
},
|
|
4334
|
-
[
|
|
4248
|
+
[admin, run]
|
|
4335
4249
|
);
|
|
4336
4250
|
return { resyncContext, loading, error };
|
|
4337
4251
|
}
|
|
4338
4252
|
function useGroupUpgradeStatus(groupId) {
|
|
4339
|
-
const {
|
|
4253
|
+
const { admin } = useMero();
|
|
4340
4254
|
const [upgradeStatus, setUpgradeStatus] = react.useState(null);
|
|
4341
4255
|
const [loading, setLoading] = react.useState(false);
|
|
4342
4256
|
const [error, setError] = react.useState(null);
|
|
@@ -4344,7 +4258,7 @@ function useGroupUpgradeStatus(groupId) {
|
|
|
4344
4258
|
const reqRef = react.useRef(0);
|
|
4345
4259
|
const refetch = react.useCallback(async () => {
|
|
4346
4260
|
const seq = ++reqRef.current;
|
|
4347
|
-
if (!
|
|
4261
|
+
if (!admin || !groupId) {
|
|
4348
4262
|
if (mountedRef.current) {
|
|
4349
4263
|
setUpgradeStatus(null);
|
|
4350
4264
|
setError(null);
|
|
@@ -4357,7 +4271,7 @@ function useGroupUpgradeStatus(groupId) {
|
|
|
4357
4271
|
setError(null);
|
|
4358
4272
|
}
|
|
4359
4273
|
try {
|
|
4360
|
-
const result = await
|
|
4274
|
+
const result = await admin.getGroupUpgradeStatus(groupId);
|
|
4361
4275
|
if (mountedRef.current && seq === reqRef.current) {
|
|
4362
4276
|
setUpgradeStatus(result);
|
|
4363
4277
|
}
|
|
@@ -4371,7 +4285,7 @@ function useGroupUpgradeStatus(groupId) {
|
|
|
4371
4285
|
setLoading(false);
|
|
4372
4286
|
}
|
|
4373
4287
|
}
|
|
4374
|
-
}, [groupId,
|
|
4288
|
+
}, [groupId, admin, mountedRef]);
|
|
4375
4289
|
react.useEffect(() => {
|
|
4376
4290
|
reqRef.current += 1;
|
|
4377
4291
|
setUpgradeStatus(null);
|
|
@@ -4383,60 +4297,47 @@ function useGroupUpgradeStatus(groupId) {
|
|
|
4383
4297
|
return { upgradeStatus, loading, error, refetch };
|
|
4384
4298
|
}
|
|
4385
4299
|
function useRetryGroupUpgrade() {
|
|
4386
|
-
const {
|
|
4300
|
+
const { admin } = useMero();
|
|
4387
4301
|
const { loading, error, run } = useAsyncMutation();
|
|
4388
4302
|
const retryGroupUpgrade = react.useCallback(
|
|
4389
4303
|
async (groupId) => {
|
|
4390
|
-
if (!
|
|
4391
|
-
return run(() =>
|
|
4304
|
+
if (!admin) return null;
|
|
4305
|
+
return run(() => admin.retryGroupUpgrade(groupId));
|
|
4392
4306
|
},
|
|
4393
|
-
[
|
|
4307
|
+
[admin, run]
|
|
4394
4308
|
);
|
|
4395
4309
|
return { retryGroupUpgrade, loading, error };
|
|
4396
4310
|
}
|
|
4397
4311
|
function useReparentGroup() {
|
|
4398
|
-
const {
|
|
4312
|
+
const { admin } = useMero();
|
|
4399
4313
|
const { loading, error, run } = useAsyncMutation();
|
|
4400
4314
|
const reparentGroup = react.useCallback(
|
|
4401
4315
|
async (childGroupId, request) => {
|
|
4402
|
-
if (
|
|
4403
|
-
|
|
4404
|
-
if (!session) return null;
|
|
4405
|
-
return run(async () => {
|
|
4406
|
-
await governRoot(session, childGroupId, meroJs.groupReparentedOp(childGroupId, request.newParentId));
|
|
4407
|
-
return { reparented: true };
|
|
4408
|
-
});
|
|
4409
|
-
}
|
|
4410
|
-
if (!mero) return null;
|
|
4411
|
-
return run(() => mero.admin.reparentGroup(childGroupId, request));
|
|
4316
|
+
if (!admin) return null;
|
|
4317
|
+
return run(() => admin.reparentGroup(childGroupId, request));
|
|
4412
4318
|
},
|
|
4413
|
-
[
|
|
4319
|
+
[admin, run]
|
|
4414
4320
|
);
|
|
4415
4321
|
return { reparentGroup, loading, error };
|
|
4416
4322
|
}
|
|
4417
4323
|
function useSubgroups(groupId) {
|
|
4418
|
-
const {
|
|
4324
|
+
const { admin } = useMero();
|
|
4419
4325
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
4420
|
-
|
|
4326
|
+
admin && groupId ? () => admin.listSubgroups(groupId) : null,
|
|
4421
4327
|
[],
|
|
4422
|
-
[
|
|
4328
|
+
[admin, groupId]
|
|
4423
4329
|
);
|
|
4424
4330
|
return { subgroups: data, loading, error, refetch };
|
|
4425
4331
|
}
|
|
4426
4332
|
function useDetachContextFromGroup() {
|
|
4427
|
-
const {
|
|
4333
|
+
const { admin } = useMero();
|
|
4428
4334
|
const { loading, error, run } = useAsyncMutation();
|
|
4429
4335
|
const detachContextFromGroup = react.useCallback(
|
|
4430
4336
|
async (groupId, contextId) => {
|
|
4431
|
-
if (
|
|
4432
|
-
|
|
4433
|
-
if (!session) return null;
|
|
4434
|
-
return run(() => governGroup(session, groupId, meroJs.contextDetachedOp(contextId)));
|
|
4435
|
-
}
|
|
4436
|
-
if (!mero) return null;
|
|
4437
|
-
return run(() => mero.admin.detachContextFromGroup(groupId, contextId));
|
|
4337
|
+
if (!admin) return null;
|
|
4338
|
+
return run(() => admin.detachContextFromGroup(groupId, contextId));
|
|
4438
4339
|
},
|
|
4439
|
-
[
|
|
4340
|
+
[admin, run]
|
|
4440
4341
|
);
|
|
4441
4342
|
return { detachContextFromGroup, loading, error };
|
|
4442
4343
|
}
|
|
@@ -4470,14 +4371,14 @@ function useMigrationEvents(namespaceId, onEvent) {
|
|
|
4470
4371
|
return live;
|
|
4471
4372
|
}
|
|
4472
4373
|
function useMigrationStatus(namespaceId, options) {
|
|
4473
|
-
const {
|
|
4374
|
+
const { admin } = useMero();
|
|
4474
4375
|
const [status, setStatus] = react.useState(null);
|
|
4475
4376
|
const [loading, setLoading] = react.useState(false);
|
|
4476
4377
|
const [error, setError] = react.useState(null);
|
|
4477
4378
|
const mountedRef = useMountedRef();
|
|
4478
4379
|
const reqRef = react.useRef(0);
|
|
4479
4380
|
const refetch = react.useCallback(async () => {
|
|
4480
|
-
if (!
|
|
4381
|
+
if (!admin || !namespaceId) {
|
|
4481
4382
|
if (mountedRef.current) {
|
|
4482
4383
|
setStatus(null);
|
|
4483
4384
|
setError(null);
|
|
@@ -4491,7 +4392,7 @@ function useMigrationStatus(namespaceId, options) {
|
|
|
4491
4392
|
setError(null);
|
|
4492
4393
|
}
|
|
4493
4394
|
try {
|
|
4494
|
-
const result = await
|
|
4395
|
+
const result = await admin.getMigrationStatus(namespaceId);
|
|
4495
4396
|
if (mountedRef.current && seq === reqRef.current) {
|
|
4496
4397
|
setStatus(result);
|
|
4497
4398
|
}
|
|
@@ -4505,7 +4406,7 @@ function useMigrationStatus(namespaceId, options) {
|
|
|
4505
4406
|
setLoading(false);
|
|
4506
4407
|
}
|
|
4507
4408
|
}
|
|
4508
|
-
}, [namespaceId,
|
|
4409
|
+
}, [namespaceId, admin, mountedRef]);
|
|
4509
4410
|
react.useEffect(() => {
|
|
4510
4411
|
setStatus(null);
|
|
4511
4412
|
setError(null);
|
|
@@ -4516,10 +4417,10 @@ function useMigrationStatus(namespaceId, options) {
|
|
|
4516
4417
|
const sseLive = useMigrationEvents(namespaceId, () => void refetch());
|
|
4517
4418
|
const pollIntervalMs = options?.pollIntervalMs ?? (sseLive ? void 0 : DEFAULT_MIGRATION_POLL_INTERVAL_MS);
|
|
4518
4419
|
react.useEffect(() => {
|
|
4519
|
-
if (!pollIntervalMs || !
|
|
4420
|
+
if (!pollIntervalMs || !admin || !namespaceId) return;
|
|
4520
4421
|
const handle = setInterval(() => void refetch(), pollIntervalMs);
|
|
4521
4422
|
return () => clearInterval(handle);
|
|
4522
|
-
}, [pollIntervalMs,
|
|
4423
|
+
}, [pollIntervalMs, admin, namespaceId, refetch]);
|
|
4523
4424
|
const rollup = status?.rollup ?? null;
|
|
4524
4425
|
const members = status?.members ?? [];
|
|
4525
4426
|
return {
|
|
@@ -4542,14 +4443,14 @@ function useMigrationStatus(namespaceId, options) {
|
|
|
4542
4443
|
};
|
|
4543
4444
|
}
|
|
4544
4445
|
function useAppVersion(contextId, expected) {
|
|
4545
|
-
const { mero } = useMero();
|
|
4446
|
+
const { mero, admin } = useMero();
|
|
4546
4447
|
const [appVersion, setAppVersion] = react.useState(void 0);
|
|
4547
4448
|
const [loading, setLoading] = react.useState(false);
|
|
4548
4449
|
const [error, setError] = react.useState(null);
|
|
4549
4450
|
const mountedRef = useMountedRef();
|
|
4550
4451
|
const reqRef = react.useRef(0);
|
|
4551
4452
|
const refetch = react.useCallback(async () => {
|
|
4552
|
-
if (!
|
|
4453
|
+
if (!admin || !contextId) {
|
|
4553
4454
|
if (mountedRef.current) {
|
|
4554
4455
|
setAppVersion(void 0);
|
|
4555
4456
|
setError(null);
|
|
@@ -4563,7 +4464,7 @@ function useAppVersion(contextId, expected) {
|
|
|
4563
4464
|
setError(null);
|
|
4564
4465
|
}
|
|
4565
4466
|
try {
|
|
4566
|
-
const context = await
|
|
4467
|
+
const context = await admin.getContext(contextId);
|
|
4567
4468
|
if (mountedRef.current && seq === reqRef.current) {
|
|
4568
4469
|
setAppVersion(context.applicationVersion);
|
|
4569
4470
|
}
|
|
@@ -4577,7 +4478,7 @@ function useAppVersion(contextId, expected) {
|
|
|
4577
4478
|
setLoading(false);
|
|
4578
4479
|
}
|
|
4579
4480
|
}
|
|
4580
|
-
}, [contextId,
|
|
4481
|
+
}, [contextId, admin, mountedRef]);
|
|
4581
4482
|
react.useEffect(() => {
|
|
4582
4483
|
setAppVersion(void 0);
|
|
4583
4484
|
setError(null);
|
|
@@ -4600,14 +4501,14 @@ function useAppVersion(contextId, expected) {
|
|
|
4600
4501
|
return { appVersion, expected, isStale, loading, error, refetch };
|
|
4601
4502
|
}
|
|
4602
4503
|
function useLatestVersion(registryUrl, packageName, currentVersion) {
|
|
4603
|
-
const {
|
|
4504
|
+
const { admin } = useMero();
|
|
4604
4505
|
const [versions, setVersions] = react.useState([]);
|
|
4605
4506
|
const [loading, setLoading] = react.useState(false);
|
|
4606
4507
|
const [error, setError] = react.useState(null);
|
|
4607
4508
|
const mountedRef = useMountedRef();
|
|
4608
4509
|
const reqRef = react.useRef(0);
|
|
4609
4510
|
const refetch = react.useCallback(async () => {
|
|
4610
|
-
if (!
|
|
4511
|
+
if (!admin || !registryUrl || !packageName) {
|
|
4611
4512
|
reqRef.current += 1;
|
|
4612
4513
|
if (mountedRef.current) {
|
|
4613
4514
|
setVersions([]);
|
|
@@ -4622,7 +4523,7 @@ function useLatestVersion(registryUrl, packageName, currentVersion) {
|
|
|
4622
4523
|
setError(null);
|
|
4623
4524
|
}
|
|
4624
4525
|
try {
|
|
4625
|
-
const result = await
|
|
4526
|
+
const result = await admin.getRegistryVersions(registryUrl, packageName);
|
|
4626
4527
|
if (mountedRef.current && seq === reqRef.current) {
|
|
4627
4528
|
setVersions(result);
|
|
4628
4529
|
}
|
|
@@ -4636,7 +4537,7 @@ function useLatestVersion(registryUrl, packageName, currentVersion) {
|
|
|
4636
4537
|
setLoading(false);
|
|
4637
4538
|
}
|
|
4638
4539
|
}
|
|
4639
|
-
}, [
|
|
4540
|
+
}, [admin, registryUrl, packageName, mountedRef]);
|
|
4640
4541
|
react.useEffect(() => {
|
|
4641
4542
|
setVersions([]);
|
|
4642
4543
|
setError(null);
|
|
@@ -4658,7 +4559,7 @@ function isZeroAppKey(appKey) {
|
|
|
4658
4559
|
return !appKey || /^0+$/.test(appKey);
|
|
4659
4560
|
}
|
|
4660
4561
|
function useGroupAppVersion(groupId) {
|
|
4661
|
-
const { mero } = useMero();
|
|
4562
|
+
const { mero, admin } = useMero();
|
|
4662
4563
|
const [data, setData] = react.useState(EMPTY_GROUP_APP_VERSION);
|
|
4663
4564
|
const [loading, setLoading] = react.useState(false);
|
|
4664
4565
|
const [error, setError] = react.useState(null);
|
|
@@ -4666,7 +4567,7 @@ function useGroupAppVersion(groupId) {
|
|
|
4666
4567
|
const reqRef = react.useRef(0);
|
|
4667
4568
|
const refetch = react.useCallback(async () => {
|
|
4668
4569
|
const seq = ++reqRef.current;
|
|
4669
|
-
if (!
|
|
4570
|
+
if (!admin || !groupId) {
|
|
4670
4571
|
if (mountedRef.current) {
|
|
4671
4572
|
setData(EMPTY_GROUP_APP_VERSION);
|
|
4672
4573
|
setError(null);
|
|
@@ -4679,7 +4580,7 @@ function useGroupAppVersion(groupId) {
|
|
|
4679
4580
|
setError(null);
|
|
4680
4581
|
}
|
|
4681
4582
|
try {
|
|
4682
|
-
const namespaces = await
|
|
4583
|
+
const namespaces = await admin.listNamespaces();
|
|
4683
4584
|
const namespace = namespaces.find((entry) => entry.namespaceId === groupId);
|
|
4684
4585
|
let appKey;
|
|
4685
4586
|
let applicationId;
|
|
@@ -4688,7 +4589,7 @@ function useGroupAppVersion(groupId) {
|
|
|
4688
4589
|
appKey = namespace.appKey;
|
|
4689
4590
|
applicationId = namespace.targetApplicationId;
|
|
4690
4591
|
} else {
|
|
4691
|
-
const info = await
|
|
4592
|
+
const info = await admin.getGroupInfo(groupId);
|
|
4692
4593
|
appKey = info.appKey;
|
|
4693
4594
|
applicationId = info.targetApplicationId;
|
|
4694
4595
|
activeUpgrade = info.activeUpgrade ?? null;
|
|
@@ -4696,7 +4597,7 @@ function useGroupAppVersion(groupId) {
|
|
|
4696
4597
|
let version = null;
|
|
4697
4598
|
let pendingApply = false;
|
|
4698
4599
|
if (applicationId) {
|
|
4699
|
-
const { application } = await
|
|
4600
|
+
const { application } = await admin.getApplication(applicationId);
|
|
4700
4601
|
version = application?.version ?? null;
|
|
4701
4602
|
if (application && !isZeroAppKey(appKey)) {
|
|
4702
4603
|
const installedHex = base58ToHex(application.blob.bytecode).toLowerCase();
|
|
@@ -4716,7 +4617,7 @@ function useGroupAppVersion(groupId) {
|
|
|
4716
4617
|
setLoading(false);
|
|
4717
4618
|
}
|
|
4718
4619
|
}
|
|
4719
|
-
}, [groupId,
|
|
4620
|
+
}, [groupId, admin, mountedRef]);
|
|
4720
4621
|
react.useEffect(() => {
|
|
4721
4622
|
reqRef.current += 1;
|
|
4722
4623
|
setData(EMPTY_GROUP_APP_VERSION);
|
|
@@ -4785,17 +4686,17 @@ function isBlobNotFound(error) {
|
|
|
4785
4686
|
return !!error && error.status === 404;
|
|
4786
4687
|
}
|
|
4787
4688
|
function useBlobInfo(blobId, options) {
|
|
4788
|
-
const {
|
|
4689
|
+
const { admin } = useMero();
|
|
4789
4690
|
const contextId = options?.contextId;
|
|
4790
4691
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
4791
|
-
|
|
4692
|
+
admin && blobId ? () => admin.getBlobInfo(blobId, contextId ? { contextId } : void 0) : null,
|
|
4792
4693
|
null,
|
|
4793
|
-
[
|
|
4694
|
+
[admin, blobId, contextId]
|
|
4794
4695
|
);
|
|
4795
4696
|
return { info: data, notFound: isBlobNotFound(error), loading, error, refetch };
|
|
4796
4697
|
}
|
|
4797
4698
|
function useBlobUrl(blobId, options) {
|
|
4798
|
-
const {
|
|
4699
|
+
const { admin } = useMero();
|
|
4799
4700
|
const contextId = options?.contextId;
|
|
4800
4701
|
const type = options?.type;
|
|
4801
4702
|
const mountedRef = useMountedRef();
|
|
@@ -4812,13 +4713,13 @@ function useBlobUrl(blobId, options) {
|
|
|
4812
4713
|
}, []);
|
|
4813
4714
|
const refetch = react.useCallback(async () => {
|
|
4814
4715
|
const seq = ++reqRef.current;
|
|
4815
|
-
if (!
|
|
4716
|
+
if (!admin || !blobId) return;
|
|
4816
4717
|
if (mountedRef.current) {
|
|
4817
4718
|
setLoading(true);
|
|
4818
4719
|
setError(null);
|
|
4819
4720
|
}
|
|
4820
4721
|
try {
|
|
4821
|
-
const bytes = await
|
|
4722
|
+
const bytes = await admin.getBlob(blobId, contextId ? { contextId } : void 0);
|
|
4822
4723
|
if (!mountedRef.current || seq !== reqRef.current) return;
|
|
4823
4724
|
revoke();
|
|
4824
4725
|
const objectUrl = URL.createObjectURL(new Blob([bytes], type ? { type } : void 0));
|
|
@@ -4829,14 +4730,14 @@ function useBlobUrl(blobId, options) {
|
|
|
4829
4730
|
} finally {
|
|
4830
4731
|
if (mountedRef.current && seq === reqRef.current) setLoading(false);
|
|
4831
4732
|
}
|
|
4832
|
-
}, [
|
|
4733
|
+
}, [admin, blobId, contextId, type, revoke, mountedRef]);
|
|
4833
4734
|
react.useEffect(() => {
|
|
4834
4735
|
reqRef.current += 1;
|
|
4835
4736
|
revoke();
|
|
4836
4737
|
setUrl(null);
|
|
4837
4738
|
setError(null);
|
|
4838
4739
|
setLoading(false);
|
|
4839
|
-
}, [
|
|
4740
|
+
}, [admin, blobId, contextId, type, revoke]);
|
|
4840
4741
|
react.useEffect(() => {
|
|
4841
4742
|
void refetch();
|
|
4842
4743
|
}, [refetch]);
|
|
@@ -4844,14 +4745,14 @@ function useBlobUrl(blobId, options) {
|
|
|
4844
4745
|
return { url, notFound: isBlobNotFound(error), loading, error, refetch };
|
|
4845
4746
|
}
|
|
4846
4747
|
function useUploadBlob() {
|
|
4847
|
-
const {
|
|
4748
|
+
const { admin } = useMero();
|
|
4848
4749
|
const { loading, error, run } = useAsyncMutation();
|
|
4849
4750
|
const uploadBlob = react.useCallback(
|
|
4850
4751
|
async (request) => {
|
|
4851
|
-
if (!
|
|
4852
|
-
return run(() =>
|
|
4752
|
+
if (!admin) return null;
|
|
4753
|
+
return run(() => admin.uploadBlob(request));
|
|
4853
4754
|
},
|
|
4854
|
-
[
|
|
4755
|
+
[admin, run]
|
|
4855
4756
|
);
|
|
4856
4757
|
return { uploadBlob, loading, error };
|
|
4857
4758
|
}
|