@calimero-network/mero-react 9.6.0 → 9.6.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/dist/index.cjs +42 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +42 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -494,14 +494,17 @@ function createNodeAdmin(input, deps = {}) {
|
|
|
494
494
|
|
|
495
495
|
// src/delegated/govern.ts
|
|
496
496
|
var GROUP_NAMESPACE_PREFIX = "calimero.delegated.group-namespace.";
|
|
497
|
+
var learned = /* @__PURE__ */ new Map();
|
|
497
498
|
function readGroupNamespaces(account) {
|
|
499
|
+
let stored = {};
|
|
498
500
|
try {
|
|
499
|
-
|
|
501
|
+
stored = JSON.parse(localStorage.getItem(GROUP_NAMESPACE_PREFIX + account) ?? "{}");
|
|
500
502
|
} catch {
|
|
501
|
-
return {};
|
|
502
503
|
}
|
|
504
|
+
return { ...stored, ...learned.get(account) };
|
|
503
505
|
}
|
|
504
506
|
function rememberGroupNamespace(account, groupId, namespaceId) {
|
|
507
|
+
learned.set(account, { ...learned.get(account), [groupId]: namespaceId });
|
|
505
508
|
try {
|
|
506
509
|
const all = readGroupNamespaces(account);
|
|
507
510
|
all[groupId] = namespaceId;
|
|
@@ -559,6 +562,10 @@ var NODE_ONLY = /* @__PURE__ */ new Set([
|
|
|
559
562
|
"uninstallApplication",
|
|
560
563
|
"generateContextIdentity",
|
|
561
564
|
"deleteContext",
|
|
565
|
+
// A node's leaveContext is a local opt-out (a tombstone, its own identity rows)
|
|
566
|
+
// and publishes nothing; an account has nothing local to opt out of, and
|
|
567
|
+
// leaving the context's group instead is leaveGroup.
|
|
568
|
+
"leaveContext",
|
|
562
569
|
"createContextAlias",
|
|
563
570
|
"createApplicationAlias",
|
|
564
571
|
"createDeviceAlias",
|
|
@@ -577,10 +584,15 @@ var NODE_ONLY = /* @__PURE__ */ new Set([
|
|
|
577
584
|
"getMigrationStatus",
|
|
578
585
|
"getCascadeStatus"
|
|
579
586
|
]);
|
|
587
|
+
function isAlreadyDirectMember(e) {
|
|
588
|
+
if (!(e instanceof Error)) return false;
|
|
589
|
+
const status = e.status;
|
|
590
|
+
return (status === void 0 || status === 409) && /signer [0-9a-f]+ is a direct member/i.test(e.message);
|
|
591
|
+
}
|
|
580
592
|
function createAccountAdmin(input, deps = {}) {
|
|
581
593
|
const { session: s, read, app } = input;
|
|
582
|
-
const
|
|
583
|
-
const
|
|
594
|
+
const governGroupOp = deps.govern?.group ?? governGroup;
|
|
595
|
+
const governRootOp = deps.govern?.root ?? governRoot;
|
|
584
596
|
const createContext2 = deps.createContext ?? createDelegatedContext;
|
|
585
597
|
const found = deps.found ?? foundDelegatedNamespace;
|
|
586
598
|
const latestVersion = deps.latestVersion ?? latestPublishedVersion;
|
|
@@ -594,8 +606,30 @@ function createAccountAdmin(input, deps = {}) {
|
|
|
594
606
|
if (read === null) throw new NoRelayError("this call");
|
|
595
607
|
return read;
|
|
596
608
|
};
|
|
609
|
+
async function knowNamespaceOf(groupId) {
|
|
610
|
+
if (namespaceOfGroup(s, groupId)) return;
|
|
611
|
+
const info = await relay().getGroupInfo(groupId);
|
|
612
|
+
rememberGroupNamespace(s.account, groupId, info.namespaceId ?? groupId);
|
|
613
|
+
}
|
|
614
|
+
const group = async (session, groupId, op) => {
|
|
615
|
+
await knowNamespaceOf(groupId);
|
|
616
|
+
return governGroupOp(session, groupId, op);
|
|
617
|
+
};
|
|
618
|
+
const root = async (session, groupId, op) => {
|
|
619
|
+
await knowNamespaceOf(groupId);
|
|
620
|
+
return governRootOp(session, groupId, op);
|
|
621
|
+
};
|
|
622
|
+
async function joinOpen(groupId) {
|
|
623
|
+
try {
|
|
624
|
+
await root(s, groupId, meroJs.memberJoinedOpenOp({ member: s.account, groupId, credential: s.credential }));
|
|
625
|
+
return true;
|
|
626
|
+
} catch (e) {
|
|
627
|
+
if (isAlreadyDirectMember(e)) return false;
|
|
628
|
+
throw e;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
597
631
|
async function isMemberOfContextGroup(contextId, knownGroupId) {
|
|
598
|
-
const groupId =
|
|
632
|
+
const groupId = String(await relay().getContextGroup(contextId));
|
|
599
633
|
const { members } = await relay().listGroupMembers(groupId);
|
|
600
634
|
return members.some((m) => m.identity.toLowerCase() === s.account.toLowerCase());
|
|
601
635
|
}
|
|
@@ -663,11 +697,6 @@ function createAccountAdmin(input, deps = {}) {
|
|
|
663
697
|
async leaveNamespace(namespaceId) {
|
|
664
698
|
await group(s, namespaceId, meroJs.memberLeftOp(s.account));
|
|
665
699
|
},
|
|
666
|
-
// An account holds no context identity: leaving a context is leaving its group.
|
|
667
|
-
async leaveContext(contextId) {
|
|
668
|
-
const groupId = await relay().getContextGroup(contextId);
|
|
669
|
-
await group(s, String(groupId), meroJs.memberLeftOp(s.account));
|
|
670
|
-
},
|
|
671
700
|
// An account runs as itself in every context it can reach (the relay
|
|
672
701
|
// executes as the account), so its identity there is the account. Owned
|
|
673
702
|
// when its account is a member of the context's group, as on a node a
|
|
@@ -676,11 +705,7 @@ function createAccountAdmin(input, deps = {}) {
|
|
|
676
705
|
return { identities: await isMemberOfContextGroup(contextId) ? [s.account] : [] };
|
|
677
706
|
},
|
|
678
707
|
async joinContext(contextId) {
|
|
679
|
-
|
|
680
|
-
if (await isMemberOfContextGroup(contextId, groupId)) {
|
|
681
|
-
return { contextId, memberPublicKey: s.account };
|
|
682
|
-
}
|
|
683
|
-
await root(s, groupId, meroJs.memberJoinedOpenOp({ member: s.account, groupId, credential: s.credential }));
|
|
708
|
+
await joinOpen(String(await relay().getContextGroup(contextId)));
|
|
684
709
|
return { contextId, memberPublicKey: s.account };
|
|
685
710
|
},
|
|
686
711
|
async createContext(req) {
|
|
@@ -722,12 +747,7 @@ function createAccountAdmin(input, deps = {}) {
|
|
|
722
747
|
// An open subgroup is joined the way `joinContext` joins one: MemberJoinedOpen
|
|
723
748
|
// on the subgroup, and nothing to do for a member already in it.
|
|
724
749
|
async joinSubgroupInheritance(groupId) {
|
|
725
|
-
|
|
726
|
-
if (members.some((m) => m.identity.toLowerCase() === s.account.toLowerCase())) {
|
|
727
|
-
return { groupId, memberPublicKey: s.account, wasInherited: false };
|
|
728
|
-
}
|
|
729
|
-
await root(s, groupId, meroJs.memberJoinedOpenOp({ member: s.account, groupId, credential: s.credential }));
|
|
730
|
-
return { groupId, memberPublicKey: s.account, wasInherited: true };
|
|
750
|
+
return { groupId, memberPublicKey: s.account, wasInherited: await joinOpen(groupId) };
|
|
731
751
|
},
|
|
732
752
|
async detachContextFromGroup(groupId, contextId) {
|
|
733
753
|
await group(s, groupId, meroJs.contextDetachedOp(contextId));
|
|
@@ -1221,6 +1241,7 @@ function getPermissionsForMode(mode) {
|
|
|
1221
1241
|
case "multi-context" /* MultiContext */:
|
|
1222
1242
|
return [
|
|
1223
1243
|
"context:create",
|
|
1244
|
+
"context:delete",
|
|
1224
1245
|
"context:list",
|
|
1225
1246
|
"context:execute",
|
|
1226
1247
|
"context:subscribe",
|