@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.d.cts CHANGED
@@ -1085,9 +1085,9 @@ declare function foundDelegatedNamespace(s: DelegatedSession, req?: {
1085
1085
  * namespace.
1086
1086
  *
1087
1087
  * A group op goes to the group it acts on; a root op (create, delete, move a
1088
- * subgroup; join an open one) goes to the NAMESPACE. An account cannot read a
1089
- * group's details, so the namespace of a subgroup is known only if this
1090
- * account created it or was told it — remembered here per account.
1088
+ * subgroup; join an open one) goes to the NAMESPACE. The namespace of a
1089
+ * subgroup is remembered here per account: when this account created it, and
1090
+ * when the account admin asked the relay for it (`getGroupInfo`).
1091
1091
  */
1092
1092
 
1093
1093
  /** A group op (member, role, capabilities, metadata, visibility, detach) on `groupId`. */
package/dist/index.d.ts CHANGED
@@ -1085,9 +1085,9 @@ declare function foundDelegatedNamespace(s: DelegatedSession, req?: {
1085
1085
  * namespace.
1086
1086
  *
1087
1087
  * A group op goes to the group it acts on; a root op (create, delete, move a
1088
- * subgroup; join an open one) goes to the NAMESPACE. An account cannot read a
1089
- * group's details, so the namespace of a subgroup is known only if this
1090
- * account created it or was told it — remembered here per account.
1088
+ * subgroup; join an open one) goes to the NAMESPACE. The namespace of a
1089
+ * subgroup is remembered here per account: when this account created it, and
1090
+ * when the account admin asked the relay for it (`getGroupInfo`).
1091
1091
  */
1092
1092
 
1093
1093
  /** A group op (member, role, capabilities, metadata, visibility, detach) on `groupId`. */
package/dist/index.js 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
- return JSON.parse(localStorage.getItem(GROUP_NAMESPACE_PREFIX + account) ?? "{}");
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 group = deps.govern?.group ?? governGroup;
583
- const root = deps.govern?.root ?? governRoot;
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, 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 = knownGroupId ?? String(await relay().getContextGroup(contextId));
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, 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), 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
- const groupId = String(await relay().getContextGroup(contextId));
680
- if (await isMemberOfContextGroup(contextId, groupId)) {
681
- return { contextId, memberPublicKey: s.account };
682
- }
683
- await root(s, groupId, 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
- const { members } = await relay().listGroupMembers(groupId);
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, 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, 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",