@dxos/client-services 0.5.3-main.3d65399 → 0.5.3-main.423e628

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.
Files changed (41) hide show
  1. package/dist/lib/browser/{chunk-KNPCT2EX.mjs → chunk-LBPDQKJC.mjs} +278 -118
  2. package/dist/lib/browser/chunk-LBPDQKJC.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-2P53YFFE.cjs → chunk-F5PNMVIG.cjs} +278 -117
  8. package/dist/lib/node/chunk-F5PNMVIG.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +45 -43
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  14. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
  15. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +1 -0
  17. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -2
  20. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -0
  22. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/data-space.d.ts +6 -1
  24. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
  26. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  27. package/dist/types/src/version.d.ts +1 -1
  28. package/package.json +36 -36
  29. package/src/packlets/diagnostics/diagnostics.ts +1 -0
  30. package/src/packlets/identity/identity-manager.ts +1 -0
  31. package/src/packlets/identity/identity.test.ts +3 -0
  32. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  33. package/src/packlets/invitations/invitation-protocol.ts +2 -0
  34. package/src/packlets/invitations/invitations-manager.ts +5 -0
  35. package/src/packlets/invitations/space-invitation-protocol.ts +29 -2
  36. package/src/packlets/spaces/data-space-manager.ts +98 -8
  37. package/src/packlets/spaces/data-space.ts +27 -8
  38. package/src/packlets/spaces/spaces-service.ts +46 -15
  39. package/src/version.ts +1 -1
  40. package/dist/lib/browser/chunk-KNPCT2EX.mjs.map +0 -7
  41. package/dist/lib/node/chunk-2P53YFFE.cjs.map +0 -7
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_2P53YFFE_exports = {};
30
- __export(chunk_2P53YFFE_exports, {
29
+ var chunk_F5PNMVIG_exports = {};
30
+ __export(chunk_F5PNMVIG_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -56,6 +56,7 @@ __export(chunk_2P53YFFE_exports, {
56
56
  createDiagnostics: () => createDiagnostics,
57
57
  createLevel: () => createLevel,
58
58
  createStorageObjects: () => createStorageObjects,
59
+ findPropertiesObject: () => findPropertiesObject,
59
60
  getNetworkPeers: () => getNetworkPeers,
60
61
  isLocked: () => isLocked,
61
62
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
@@ -66,7 +67,7 @@ __export(chunk_2P53YFFE_exports, {
66
67
  subscribeToSpaces: () => subscribeToSpaces,
67
68
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
68
69
  });
69
- module.exports = __toCommonJS(chunk_2P53YFFE_exports);
70
+ module.exports = __toCommonJS(chunk_F5PNMVIG_exports);
70
71
  var import_async = require("@dxos/async");
71
72
  var import_codec_protobuf = require("@dxos/codec-protobuf");
72
73
  var import_feed_store = require("@dxos/feed-store");
@@ -182,7 +183,6 @@ var import_client_protocol4 = require("@dxos/client-protocol");
182
183
  var import_context9 = require("@dxos/context");
183
184
  var import_debug3 = require("@dxos/debug");
184
185
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
185
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
186
186
  var import_echo_schema = require("@dxos/echo-schema");
187
187
  var import_invariant11 = require("@dxos/invariant");
188
188
  var import_keys9 = require("@dxos/keys");
@@ -190,12 +190,11 @@ var import_log10 = require("@dxos/log");
190
190
  var import_protocols8 = require("@dxos/protocols");
191
191
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
192
192
  var import_credentials11 = require("@dxos/protocols/proto/dxos/halo/credentials");
193
- var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
194
193
  var import_timeframe2 = require("@dxos/timeframe");
195
194
  var import_tracing4 = require("@dxos/tracing");
196
195
  var import_util6 = require("@dxos/util");
197
196
  var import_async12 = require("@dxos/async");
198
- var import_credentials13 = require("@dxos/credentials");
197
+ var import_credentials12 = require("@dxos/credentials");
199
198
  var import_async13 = require("@dxos/async");
200
199
  var import_context10 = require("@dxos/context");
201
200
  var import_invariant12 = require("@dxos/invariant");
@@ -206,13 +205,16 @@ var import_teleport3 = require("@dxos/teleport");
206
205
  var import_util7 = require("@dxos/util");
207
206
  var import_async14 = require("@dxos/async");
208
207
  var import_context11 = require("@dxos/context");
209
- var import_credentials14 = require("@dxos/credentials");
208
+ var import_credentials13 = require("@dxos/credentials");
209
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
210
210
  var import_invariant13 = require("@dxos/invariant");
211
211
  var import_keys11 = require("@dxos/keys");
212
212
  var import_log12 = require("@dxos/log");
213
213
  var import_protocols10 = require("@dxos/protocols");
214
214
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
215
+ var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
215
216
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
217
+ var import_tracing5 = require("@dxos/tracing");
216
218
  var import_util8 = require("@dxos/util");
217
219
  var import_credentials15 = require("@dxos/credentials");
218
220
  var import_debug4 = require("@dxos/debug");
@@ -220,19 +222,20 @@ var import_credentials16 = require("@dxos/protocols/proto/dxos/halo/credentials"
220
222
  var import_timeframe3 = require("@dxos/timeframe");
221
223
  var import_async15 = require("@dxos/async");
222
224
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
225
+ var import_credentials17 = require("@dxos/credentials");
223
226
  var import_debug5 = require("@dxos/debug");
227
+ var import_feed_store4 = require("@dxos/feed-store");
224
228
  var import_invariant14 = require("@dxos/invariant");
225
229
  var import_log13 = require("@dxos/log");
226
230
  var import_protocols11 = require("@dxos/protocols");
227
231
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
228
- var import_credentials17 = require("@dxos/protocols/proto/dxos/halo/credentials");
229
232
  var import_async16 = require("@dxos/async");
230
233
  var import_context12 = require("@dxos/context");
231
234
  var import_credentials18 = require("@dxos/credentials");
232
235
  var import_debug6 = require("@dxos/debug");
233
236
  var import_echo_db = require("@dxos/echo-db");
234
237
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
235
- var import_feed_store4 = require("@dxos/feed-store");
238
+ var import_feed_store5 = require("@dxos/feed-store");
236
239
  var import_invariant15 = require("@dxos/invariant");
237
240
  var import_keyring = require("@dxos/keyring");
238
241
  var import_keys12 = require("@dxos/keys");
@@ -240,7 +243,7 @@ var import_log14 = require("@dxos/log");
240
243
  var import_protocols12 = require("@dxos/protocols");
241
244
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
242
245
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
243
- var import_tracing5 = require("@dxos/tracing");
246
+ var import_tracing6 = require("@dxos/tracing");
244
247
  var import_util9 = require("@dxos/util");
245
248
  var import_async17 = require("@dxos/async");
246
249
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
@@ -248,11 +251,11 @@ var import_credentials19 = require("@dxos/credentials");
248
251
  var import_invariant16 = require("@dxos/invariant");
249
252
  var import_protocols13 = require("@dxos/protocols");
250
253
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
251
- var import_tracing6 = require("@dxos/tracing");
254
+ var import_tracing7 = require("@dxos/tracing");
252
255
  var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
253
256
  var import_config = require("@dxos/config");
254
257
  var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
255
- var import_tracing7 = require("@dxos/tracing");
258
+ var import_tracing8 = require("@dxos/tracing");
256
259
  var import_util10 = require("@dxos/util");
257
260
  var import_async18 = require("@dxos/async");
258
261
  var import_client_protocol5 = require("@dxos/client-protocol");
@@ -266,7 +269,7 @@ var import_messaging = require("@dxos/messaging");
266
269
  var import_network_manager2 = require("@dxos/network-manager");
267
270
  var import_protocols14 = require("@dxos/protocols");
268
271
  var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
269
- var import_tracing8 = require("@dxos/tracing");
272
+ var import_tracing9 = require("@dxos/tracing");
270
273
  var import_util11 = require("@dxos/util");
271
274
  var import_websocket_rpc = require("@dxos/websocket-rpc");
272
275
  var import_async19 = require("@dxos/async");
@@ -1316,6 +1319,8 @@ var IdentityManager = class {
1316
1319
  },
1317
1320
  memberKey: identityKey,
1318
1321
  onDelegatedInvitationStatusChange: async () => {
1322
+ },
1323
+ onMemberRolesChanged: async () => {
1319
1324
  }
1320
1325
  });
1321
1326
  }
@@ -1408,6 +1413,9 @@ var DeviceInvitationProtocol = class {
1408
1413
  toJSON() {
1409
1414
  return {};
1410
1415
  }
1416
+ checkCanInviteNewMembers() {
1417
+ return void 0;
1418
+ }
1411
1419
  getInvitationContext() {
1412
1420
  return {
1413
1421
  kind: import_services2.Invitation.Kind.DEVICE
@@ -1422,7 +1430,7 @@ var DeviceInvitationProtocol = class {
1422
1430
  async admit(_, request) {
1423
1431
  (0, import_invariant4.invariant)(request.device, void 0, {
1424
1432
  F: __dxlog_file5,
1425
- L: 46,
1433
+ L: 50,
1426
1434
  S: this,
1427
1435
  A: [
1428
1436
  "request.device",
@@ -1468,7 +1476,7 @@ var DeviceInvitationProtocol = class {
1468
1476
  async accept(response, request) {
1469
1477
  (0, import_invariant4.invariant)(response.device, void 0, {
1470
1478
  F: __dxlog_file5,
1471
- L: 91,
1479
+ L: 95,
1472
1480
  S: this,
1473
1481
  A: [
1474
1482
  "response.device",
@@ -1478,7 +1486,7 @@ var DeviceInvitationProtocol = class {
1478
1486
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1479
1487
  (0, import_invariant4.invariant)(request.device, void 0, {
1480
1488
  F: __dxlog_file5,
1481
- L: 94,
1489
+ L: 98,
1482
1490
  S: this,
1483
1491
  A: [
1484
1492
  "request.device",
@@ -2731,6 +2739,19 @@ var SpaceInvitationProtocol = class {
2731
2739
  spaceKey: this._spaceKey
2732
2740
  };
2733
2741
  }
2742
+ checkCanInviteNewMembers() {
2743
+ if (this._spaceKey == null) {
2744
+ return new import_protocols7.InvalidInvitationError("No spaceKey was provided for a space invitation.");
2745
+ }
2746
+ const space = this._spaceManager.spaces.get(this._spaceKey);
2747
+ if (space == null) {
2748
+ return new import_protocols7.SpaceNotFoundError(this._spaceKey);
2749
+ }
2750
+ if (!space?.inner.spaceState.hasMembershipManagementPermission(this._signingContext.identityKey)) {
2751
+ return new import_protocols7.AuthorizationError("No member management permission.");
2752
+ }
2753
+ return void 0;
2754
+ }
2734
2755
  getInvitationContext() {
2735
2756
  return {
2736
2757
  kind: import_services7.Invitation.Kind.SPACE,
@@ -2740,7 +2761,7 @@ var SpaceInvitationProtocol = class {
2740
2761
  async admit(invitation, request, guestProfile) {
2741
2762
  (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2742
2763
  F: __dxlog_file10,
2743
- L: 56,
2764
+ L: 76,
2744
2765
  S: this,
2745
2766
  A: [
2746
2767
  "this._spaceKey",
@@ -2750,7 +2771,7 @@ var SpaceInvitationProtocol = class {
2750
2771
  const space = this._spaceManager.spaces.get(this._spaceKey);
2751
2772
  (0, import_invariant9.invariant)(space, void 0, {
2752
2773
  F: __dxlog_file10,
2753
- L: 58,
2774
+ L: 78,
2754
2775
  S: this,
2755
2776
  A: [
2756
2777
  "space",
@@ -2759,7 +2780,7 @@ var SpaceInvitationProtocol = class {
2759
2780
  });
2760
2781
  (0, import_invariant9.invariant)(request.space, void 0, {
2761
2782
  F: __dxlog_file10,
2762
- L: 60,
2783
+ L: 80,
2763
2784
  S: this,
2764
2785
  A: [
2765
2786
  "request.space",
@@ -2767,19 +2788,22 @@ var SpaceInvitationProtocol = class {
2767
2788
  ]
2768
2789
  });
2769
2790
  const { identityKey, deviceKey } = request.space;
2791
+ if (space.inner.spaceState.getMemberRole(identityKey) !== import_credentials8.SpaceMember.Role.REMOVED) {
2792
+ throw new import_protocols7.AlreadyJoinedError();
2793
+ }
2770
2794
  (0, import_log8.log)("writing guest credentials", {
2771
2795
  host: this._signingContext.deviceKey,
2772
2796
  guest: deviceKey
2773
2797
  }, {
2774
2798
  F: __dxlog_file10,
2775
- L: 63,
2799
+ L: 87,
2776
2800
  S: this,
2777
2801
  C: (f, a) => f(...a)
2778
2802
  });
2779
2803
  const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? import_credentials8.SpaceMember.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
2780
2804
  (0, import_invariant9.invariant)(credentials[0].credential, void 0, {
2781
2805
  F: __dxlog_file10,
2782
- L: 77,
2806
+ L: 101,
2783
2807
  S: this,
2784
2808
  A: [
2785
2809
  "credentials[0].credential",
@@ -2789,7 +2813,7 @@ var SpaceInvitationProtocol = class {
2789
2813
  const spaceMemberCredential = credentials[0].credential.credential;
2790
2814
  (0, import_invariant9.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2791
2815
  F: __dxlog_file10,
2792
- L: 79,
2816
+ L: 103,
2793
2817
  S: this,
2794
2818
  A: [
2795
2819
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2807,7 +2831,7 @@ var SpaceInvitationProtocol = class {
2807
2831
  async delegate(invitation) {
2808
2832
  (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2809
2833
  F: __dxlog_file10,
2810
- L: 92,
2834
+ L: 116,
2811
2835
  S: this,
2812
2836
  A: [
2813
2837
  "this._spaceKey",
@@ -2817,7 +2841,7 @@ var SpaceInvitationProtocol = class {
2817
2841
  const space = this._spaceManager.spaces.get(this._spaceKey);
2818
2842
  (0, import_invariant9.invariant)(space, void 0, {
2819
2843
  F: __dxlog_file10,
2820
- L: 94,
2844
+ L: 118,
2821
2845
  S: this,
2822
2846
  A: [
2823
2847
  "space",
@@ -2827,7 +2851,7 @@ var SpaceInvitationProtocol = class {
2827
2851
  if (invitation.authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2828
2852
  (0, import_invariant9.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2829
2853
  F: __dxlog_file10,
2830
- L: 96,
2854
+ L: 120,
2831
2855
  S: this,
2832
2856
  A: [
2833
2857
  "invitation.guestKeypair?.publicKey",
@@ -2840,7 +2864,7 @@ var SpaceInvitationProtocol = class {
2840
2864
  id: invitation.invitationId
2841
2865
  }, {
2842
2866
  F: __dxlog_file10,
2843
- L: 99,
2867
+ L: 123,
2844
2868
  S: this,
2845
2869
  C: (f, a) => f(...a)
2846
2870
  });
@@ -2855,7 +2879,7 @@ var SpaceInvitationProtocol = class {
2855
2879
  });
2856
2880
  (0, import_invariant9.invariant)(credential.credential, void 0, {
2857
2881
  F: __dxlog_file10,
2858
- L: 119,
2882
+ L: 143,
2859
2883
  S: this,
2860
2884
  A: [
2861
2885
  "credential.credential",
@@ -2870,7 +2894,7 @@ var SpaceInvitationProtocol = class {
2870
2894
  async cancelDelegation(invitation) {
2871
2895
  (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2872
2896
  F: __dxlog_file10,
2873
- L: 125,
2897
+ L: 149,
2874
2898
  S: this,
2875
2899
  A: [
2876
2900
  "this._spaceKey",
@@ -2879,7 +2903,7 @@ var SpaceInvitationProtocol = class {
2879
2903
  });
2880
2904
  (0, import_invariant9.invariant)(invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
2881
2905
  F: __dxlog_file10,
2882
- L: 126,
2906
+ L: 150,
2883
2907
  S: this,
2884
2908
  A: [
2885
2909
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -2889,7 +2913,7 @@ var SpaceInvitationProtocol = class {
2889
2913
  const space = this._spaceManager.spaces.get(this._spaceKey);
2890
2914
  (0, import_invariant9.invariant)(space, void 0, {
2891
2915
  F: __dxlog_file10,
2892
- L: 128,
2916
+ L: 152,
2893
2917
  S: this,
2894
2918
  A: [
2895
2919
  "space",
@@ -2901,14 +2925,14 @@ var SpaceInvitationProtocol = class {
2901
2925
  id: invitation.invitationId
2902
2926
  }, {
2903
2927
  F: __dxlog_file10,
2904
- L: 130,
2928
+ L: 154,
2905
2929
  S: this,
2906
2930
  C: (f, a) => f(...a)
2907
2931
  });
2908
2932
  const credential = await (0, import_credentials7.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
2909
2933
  (0, import_invariant9.invariant)(credential.credential, void 0, {
2910
2934
  F: __dxlog_file10,
2911
- L: 137,
2935
+ L: 161,
2912
2936
  S: this,
2913
2937
  A: [
2914
2938
  "credential.credential",
@@ -2920,7 +2944,10 @@ var SpaceInvitationProtocol = class {
2920
2944
  ]);
2921
2945
  }
2922
2946
  checkInvitation(invitation) {
2923
- if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2947
+ if (invitation.spaceKey == null) {
2948
+ return new import_protocols7.InvalidInvitationError("No spaceKey was provided for a space invitation.");
2949
+ }
2950
+ if (this._spaceManager.spaces.has(invitation.spaceKey)) {
2924
2951
  return new import_protocols7.AlreadyJoinedError("Already joined space.");
2925
2952
  }
2926
2953
  }
@@ -2944,7 +2971,7 @@ var SpaceInvitationProtocol = class {
2944
2971
  async accept(response) {
2945
2972
  (0, import_invariant9.invariant)(response.space, void 0, {
2946
2973
  F: __dxlog_file10,
2947
- L: 169,
2974
+ L: 196,
2948
2975
  S: this,
2949
2976
  A: [
2950
2977
  "response.space",
@@ -2955,7 +2982,7 @@ var SpaceInvitationProtocol = class {
2955
2982
  const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2956
2983
  (0, import_invariant9.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2957
2984
  F: __dxlog_file10,
2958
- L: 172,
2985
+ L: 199,
2959
2986
  S: this,
2960
2987
  A: [
2961
2988
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2964,7 +2991,7 @@ var SpaceInvitationProtocol = class {
2964
2991
  });
2965
2992
  (0, import_invariant9.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2966
2993
  F: __dxlog_file10,
2967
- L: 173,
2994
+ L: 200,
2968
2995
  S: this,
2969
2996
  A: [
2970
2997
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -3010,6 +3037,10 @@ var InvitationsManager = class {
3010
3037
  }
3011
3038
  }
3012
3039
  const handler = this._getHandler(options);
3040
+ const invitationError = handler.checkCanInviteNewMembers();
3041
+ if (invitationError != null) {
3042
+ throw invitationError;
3043
+ }
3013
3044
  const invitation = this._createInvitation(handler, options);
3014
3045
  const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
3015
3046
  this._createInvitations.set(invitation.invitationId, observableInvitation);
@@ -3026,7 +3057,7 @@ var InvitationsManager = class {
3026
3057
  } catch (err) {
3027
3058
  import_log9.log.catch(err, void 0, {
3028
3059
  F: __dxlog_file11,
3029
- L: 77,
3060
+ L: 82,
3030
3061
  S: this,
3031
3062
  C: (f, a) => f(...a)
3032
3063
  });
@@ -3049,7 +3080,7 @@ var InvitationsManager = class {
3049
3080
  const loadTasks = freshInvitations.map((persistentInvitation) => {
3050
3081
  (0, import_invariant10.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
3051
3082
  F: __dxlog_file11,
3052
- L: 98,
3083
+ L: 103,
3053
3084
  S: this,
3054
3085
  A: [
3055
3086
  "!this._createInvitations.get(persistentInvitation.invitationId)",
@@ -3068,7 +3099,7 @@ var InvitationsManager = class {
3068
3099
  } catch (err) {
3069
3100
  import_log9.log.catch(err, void 0, {
3070
3101
  F: __dxlog_file11,
3071
- L: 105,
3102
+ L: 110,
3072
3103
  S: this,
3073
3104
  C: (f, a) => f(...a)
3074
3105
  });
@@ -3100,13 +3131,13 @@ var InvitationsManager = class {
3100
3131
  async authenticate({ invitationId, authCode }) {
3101
3132
  (0, import_log9.log)("authenticating...", void 0, {
3102
3133
  F: __dxlog_file11,
3103
- L: 135,
3134
+ L: 140,
3104
3135
  S: this,
3105
3136
  C: (f, a) => f(...a)
3106
3137
  });
3107
3138
  (0, import_invariant10.invariant)(invitationId, void 0, {
3108
3139
  F: __dxlog_file11,
3109
- L: 136,
3140
+ L: 141,
3110
3141
  S: this,
3111
3142
  A: [
3112
3143
  "invitationId",
@@ -3119,7 +3150,7 @@ var InvitationsManager = class {
3119
3150
  invitationId
3120
3151
  }, {
3121
3152
  F: __dxlog_file11,
3122
- L: 139,
3153
+ L: 144,
3123
3154
  S: this,
3124
3155
  C: (f, a) => f(...a)
3125
3156
  });
@@ -3132,13 +3163,13 @@ var InvitationsManager = class {
3132
3163
  invitationId
3133
3164
  }, {
3134
3165
  F: __dxlog_file11,
3135
- L: 146,
3166
+ L: 151,
3136
3167
  S: this,
3137
3168
  C: (f, a) => f(...a)
3138
3169
  });
3139
3170
  (0, import_invariant10.invariant)(invitationId, void 0, {
3140
3171
  F: __dxlog_file11,
3141
- L: 147,
3172
+ L: 152,
3142
3173
  S: this,
3143
3174
  A: [
3144
3175
  "invitationId",
@@ -3217,7 +3248,7 @@ var InvitationsManager = class {
3217
3248
  ...handler.toJSON()
3218
3249
  }, {
3219
3250
  F: __dxlog_file11,
3220
- L: 236,
3251
+ L: 241,
3221
3252
  S: this,
3222
3253
  C: (f, a) => f(...a)
3223
3254
  });
@@ -3250,7 +3281,7 @@ var InvitationsManager = class {
3250
3281
  ...handler.toJSON()
3251
3282
  }, {
3252
3283
  F: __dxlog_file11,
3253
- L: 256,
3284
+ L: 261,
3254
3285
  S: this,
3255
3286
  C: (f, a) => f(...a)
3256
3287
  });
@@ -3261,7 +3292,7 @@ var InvitationsManager = class {
3261
3292
  } else {
3262
3293
  import_log9.log.warn("auth failed", err, {
3263
3294
  F: __dxlog_file11,
3264
- L: 259,
3295
+ L: 264,
3265
3296
  S: this,
3266
3297
  C: (f, a) => f(...a)
3267
3298
  });
@@ -3278,7 +3309,7 @@ var InvitationsManager = class {
3278
3309
  ...handler.toJSON()
3279
3310
  }, {
3280
3311
  F: __dxlog_file11,
3281
- L: 266,
3312
+ L: 271,
3282
3313
  S: this,
3283
3314
  C: (f, a) => f(...a)
3284
3315
  });
@@ -3323,7 +3354,7 @@ var InvitationsManager = class {
3323
3354
  } catch (err) {
3324
3355
  import_log9.log.catch(err, void 0, {
3325
3356
  F: __dxlog_file11,
3326
- L: 302,
3357
+ L: 307,
3327
3358
  S: this,
3328
3359
  C: (f, a) => f(...a)
3329
3360
  });
@@ -3419,7 +3450,7 @@ var AutomergeSpaceState = class {
3419
3450
  this._isProcessingRootDocs = false;
3420
3451
  }
3421
3452
  async processCredential(credential) {
3422
- if (!(0, import_credentials13.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3453
+ if (!(0, import_credentials12.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3423
3454
  return;
3424
3455
  }
3425
3456
  this.lastEpoch = credential;
@@ -3744,7 +3775,7 @@ var DataSpace = class {
3744
3775
  state: import_services9.SpaceState[this._state]
3745
3776
  }, {
3746
3777
  F: __dxlog_file13,
3747
- L: 137,
3778
+ L: 141,
3748
3779
  S: this,
3749
3780
  C: (f, a) => f(...a)
3750
3781
  });
@@ -3794,7 +3825,7 @@ var DataSpace = class {
3794
3825
  state: import_services9.SpaceState[this._state]
3795
3826
  }, {
3796
3827
  F: __dxlog_file13,
3797
- L: 195,
3828
+ L: 199,
3798
3829
  S: this,
3799
3830
  C: (f, a) => f(...a)
3800
3831
  });
@@ -3812,7 +3843,7 @@ var DataSpace = class {
3812
3843
  state: import_services9.SpaceState[this._state]
3813
3844
  }, {
3814
3845
  F: __dxlog_file13,
3815
- L: 209,
3846
+ L: 213,
3816
3847
  S: this,
3817
3848
  C: (f, a) => f(...a)
3818
3849
  });
@@ -3844,7 +3875,7 @@ var DataSpace = class {
3844
3875
  if (err instanceof import_protocols8.CancelledError || err instanceof import_context9.ContextDisposedError) {
3845
3876
  (0, import_log10.log)("data pipeline initialization cancelled", err, {
3846
3877
  F: __dxlog_file13,
3847
- L: 242,
3878
+ L: 246,
3848
3879
  S: this,
3849
3880
  C: (f, a) => f(...a)
3850
3881
  });
@@ -3852,7 +3883,7 @@ var DataSpace = class {
3852
3883
  }
3853
3884
  import_log10.log.error("Error initializing data pipeline", err, {
3854
3885
  F: __dxlog_file13,
3855
- L: 246,
3886
+ L: 250,
3856
3887
  S: this,
3857
3888
  C: (f, a) => f(...a)
3858
3889
  });
@@ -3861,7 +3892,7 @@ var DataSpace = class {
3861
3892
  state: import_services9.SpaceState[this._state]
3862
3893
  }, {
3863
3894
  F: __dxlog_file13,
3864
- L: 248,
3895
+ L: 252,
3865
3896
  S: this,
3866
3897
  C: (f, a) => f(...a)
3867
3898
  });
@@ -3881,7 +3912,7 @@ var DataSpace = class {
3881
3912
  state: import_services9.SpaceState[this._state]
3882
3913
  }, {
3883
3914
  F: __dxlog_file13,
3884
- L: 264,
3915
+ L: 268,
3885
3916
  S: this,
3886
3917
  C: (f, a) => f(...a)
3887
3918
  });
@@ -3891,7 +3922,7 @@ var DataSpace = class {
3891
3922
  await (0, import_context9.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3892
3923
  (0, import_log10.log)("data pipeline ready", void 0, {
3893
3924
  F: __dxlog_file13,
3894
- L: 276,
3925
+ L: 280,
3895
3926
  S: this,
3896
3927
  C: (f, a) => f(...a)
3897
3928
  });
@@ -3901,7 +3932,7 @@ var DataSpace = class {
3901
3932
  state: import_services9.SpaceState[this._state]
3902
3933
  }, {
3903
3934
  F: __dxlog_file13,
3904
- L: 280,
3935
+ L: 284,
3905
3936
  S: this,
3906
3937
  C: (f, a) => f(...a)
3907
3938
  });
@@ -3917,7 +3948,7 @@ var DataSpace = class {
3917
3948
  await this._createWritableFeeds();
3918
3949
  (0, import_log10.log)("writable feeds created", void 0, {
3919
3950
  F: __dxlog_file13,
3920
- L: 296,
3951
+ L: 300,
3921
3952
  S: this,
3922
3953
  C: (f, a) => f(...a)
3923
3954
  });
@@ -3944,7 +3975,7 @@ var DataSpace = class {
3944
3975
  spaceKey: this.key,
3945
3976
  deviceKey: this._signingContext.deviceKey,
3946
3977
  identityKey: this._signingContext.identityKey,
3947
- designation: import_credentials12.AdmittedFeed.Designation.CONTROL
3978
+ designation: import_credentials11.AdmittedFeed.Designation.CONTROL
3948
3979
  }
3949
3980
  }));
3950
3981
  }
@@ -3961,7 +3992,7 @@ var DataSpace = class {
3961
3992
  spaceKey: this.key,
3962
3993
  deviceKey: this._signingContext.deviceKey,
3963
3994
  identityKey: this._signingContext.identityKey,
3964
- designation: import_credentials12.AdmittedFeed.Designation.DATA
3995
+ designation: import_credentials11.AdmittedFeed.Designation.DATA
3965
3996
  }
3966
3997
  }));
3967
3998
  }
@@ -3980,7 +4011,7 @@ var DataSpace = class {
3980
4011
  rootUrl
3981
4012
  }, {
3982
4013
  F: __dxlog_file13,
3983
- L: 362,
4014
+ L: 366,
3984
4015
  S: this,
3985
4016
  C: (f, a) => f(...a)
3986
4017
  });
@@ -4012,7 +4043,7 @@ var DataSpace = class {
4012
4043
  err
4013
4044
  }, {
4014
4045
  F: __dxlog_file13,
4015
- L: 385,
4046
+ L: 391,
4016
4047
  S: this,
4017
4048
  C: (f, a) => f(...a)
4018
4049
  });
@@ -4067,7 +4098,7 @@ var DataSpace = class {
4067
4098
  const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4068
4099
  (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4069
4100
  F: __dxlog_file13,
4070
- L: 435,
4101
+ L: 441,
4071
4102
  S: this,
4072
4103
  A: [
4073
4104
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -4086,7 +4117,7 @@ var DataSpace = class {
4086
4117
  {
4087
4118
  import_log10.log.info("Fragmenting", void 0, {
4088
4119
  F: __dxlog_file13,
4089
- L: 447,
4120
+ L: 453,
4090
4121
  S: this,
4091
4122
  C: (f, a) => f(...a)
4092
4123
  });
@@ -4094,11 +4125,11 @@ var DataSpace = class {
4094
4125
  const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4095
4126
  await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
4096
4127
  const objects = Object.entries(rootHandle.docSync().objects);
4097
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
4128
+ const properties = findPropertiesObject(rootHandle.docSync());
4098
4129
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4099
4130
  (0, import_invariant11.invariant)(properties, "Properties not found", {
4100
4131
  F: __dxlog_file13,
4101
- L: 457,
4132
+ L: 463,
4102
4133
  S: this,
4103
4134
  A: [
4104
4135
  "properties",
@@ -4114,14 +4145,14 @@ var DataSpace = class {
4114
4145
  const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4115
4146
  (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4116
4147
  F: __dxlog_file13,
4117
- L: 462,
4148
+ L: 468,
4118
4149
  S: this,
4119
4150
  A: [
4120
4151
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4121
4152
  ""
4122
4153
  ]
4123
4154
  });
4124
- const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
4155
+ const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
4125
4156
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
4126
4157
  rootUrl: newRoot.url
4127
4158
  });
@@ -4183,7 +4214,7 @@ var DataSpace = class {
4183
4214
  state: import_services9.SpaceState[this._state]
4184
4215
  }, {
4185
4216
  F: __dxlog_file13,
4186
- L: 528,
4217
+ L: 534,
4187
4218
  S: this,
4188
4219
  C: (f, a) => f(...a)
4189
4220
  });
@@ -4235,6 +4266,18 @@ DataSpace = _ts_decorate4([
4235
4266
  (0, import_async11.trackLeaks)("open", "close"),
4236
4267
  import_tracing4.trace.resource()
4237
4268
  ], DataSpace);
4269
+ var findPropertiesObject = (spaceDoc) => {
4270
+ for (const id in spaceDoc.objects ?? {}) {
4271
+ const obj = spaceDoc.objects[id];
4272
+ if (obj.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES) {
4273
+ return [
4274
+ id,
4275
+ obj
4276
+ ];
4277
+ }
4278
+ }
4279
+ return void 0;
4280
+ };
4238
4281
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4239
4282
  const credentials = [
4240
4283
  await (0, import_credentials15.createCredential)({
@@ -4329,6 +4372,28 @@ var DataSpaceManager = class {
4329
4372
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
4330
4373
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
4331
4374
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
4375
+ import_tracing5.trace.diagnostic({
4376
+ id: "spaces",
4377
+ name: "Spaces",
4378
+ fetch: async () => {
4379
+ return Array.from(this._spaces.values()).map((space) => {
4380
+ const rootUrl = space.automergeSpaceState.rootUrl;
4381
+ const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4382
+ const rootDoc = rootHandle?.docSync();
4383
+ const properties = rootDoc && findPropertiesObject(rootDoc);
4384
+ return {
4385
+ key: space.key.toHex(),
4386
+ state: import_services10.SpaceState[space.state],
4387
+ name: properties?.[1].data.name ?? null,
4388
+ inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4389
+ linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
4390
+ credentials: space.inner.spaceState.credentials.length,
4391
+ members: space.inner.spaceState.members.size,
4392
+ rootUrl
4393
+ };
4394
+ });
4395
+ }
4396
+ });
4332
4397
  }
4333
4398
  // TODO(burdon): Remove.
4334
4399
  get spaces() {
@@ -4337,7 +4402,7 @@ var DataSpaceManager = class {
4337
4402
  async open() {
4338
4403
  (0, import_log12.log)("open", void 0, {
4339
4404
  F: __dxlog_file14,
4340
- L: 102,
4405
+ L: 144,
4341
4406
  S: this,
4342
4407
  C: (f, a) => f(...a)
4343
4408
  });
@@ -4345,7 +4410,7 @@ var DataSpaceManager = class {
4345
4410
  id: this._instanceId
4346
4411
  }), {
4347
4412
  F: __dxlog_file14,
4348
- L: 103,
4413
+ L: 145,
4349
4414
  S: this,
4350
4415
  C: (f, a) => f(...a)
4351
4416
  });
@@ -4353,7 +4418,7 @@ var DataSpaceManager = class {
4353
4418
  spaces: this._metadataStore.spaces.length
4354
4419
  }, {
4355
4420
  F: __dxlog_file14,
4356
- L: 104,
4421
+ L: 146,
4357
4422
  S: this,
4358
4423
  C: (f, a) => f(...a)
4359
4424
  });
@@ -4363,7 +4428,7 @@ var DataSpaceManager = class {
4363
4428
  spaceMetadata
4364
4429
  }, {
4365
4430
  F: __dxlog_file14,
4366
- L: 108,
4431
+ L: 150,
4367
4432
  S: this,
4368
4433
  C: (f, a) => f(...a)
4369
4434
  });
@@ -4374,7 +4439,7 @@ var DataSpaceManager = class {
4374
4439
  err
4375
4440
  }, {
4376
4441
  F: __dxlog_file14,
4377
- L: 111,
4442
+ L: 153,
4378
4443
  S: this,
4379
4444
  C: (f, a) => f(...a)
4380
4445
  });
@@ -4391,7 +4456,7 @@ var DataSpaceManager = class {
4391
4456
  id: this._instanceId
4392
4457
  }), {
4393
4458
  F: __dxlog_file14,
4394
- L: 124,
4459
+ L: 166,
4395
4460
  S: this,
4396
4461
  C: (f, a) => f(...a)
4397
4462
  });
@@ -4399,7 +4464,7 @@ var DataSpaceManager = class {
4399
4464
  async close() {
4400
4465
  (0, import_log12.log)("close", void 0, {
4401
4466
  F: __dxlog_file14,
4402
- L: 129,
4467
+ L: 171,
4403
4468
  S: this,
4404
4469
  C: (f, a) => f(...a)
4405
4470
  });
@@ -4415,7 +4480,7 @@ var DataSpaceManager = class {
4415
4480
  async createSpace() {
4416
4481
  (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4417
4482
  F: __dxlog_file14,
4418
- L: 142,
4483
+ L: 184,
4419
4484
  S: this,
4420
4485
  A: [
4421
4486
  "this._isOpen",
@@ -4436,7 +4501,7 @@ var DataSpaceManager = class {
4436
4501
  spaceKey
4437
4502
  }, {
4438
4503
  F: __dxlog_file14,
4439
- L: 154,
4504
+ L: 196,
4440
4505
  S: this,
4441
4506
  C: (f, a) => f(...a)
4442
4507
  });
@@ -4445,9 +4510,9 @@ var DataSpaceManager = class {
4445
4510
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4446
4511
  await this._metadataStore.addSpace(metadata);
4447
4512
  const memberCredential = credentials[1];
4448
- (0, import_invariant13.invariant)((0, import_credentials14.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4513
+ (0, import_invariant13.invariant)((0, import_credentials13.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4449
4514
  F: __dxlog_file14,
4450
- L: 163,
4515
+ L: 205,
4451
4516
  S: this,
4452
4517
  A: [
4453
4518
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4465,13 +4530,13 @@ var DataSpaceManager = class {
4465
4530
  opts
4466
4531
  }, {
4467
4532
  F: __dxlog_file14,
4468
- L: 175,
4533
+ L: 217,
4469
4534
  S: this,
4470
4535
  C: (f, a) => f(...a)
4471
4536
  });
4472
4537
  (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4473
4538
  F: __dxlog_file14,
4474
- L: 176,
4539
+ L: 218,
4475
4540
  S: this,
4476
4541
  A: [
4477
4542
  "this._isOpen",
@@ -4480,7 +4545,7 @@ var DataSpaceManager = class {
4480
4545
  });
4481
4546
  (0, import_invariant13.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4482
4547
  F: __dxlog_file14,
4483
- L: 177,
4548
+ L: 219,
4484
4549
  S: this,
4485
4550
  A: [
4486
4551
  "!this._spaces.has(opts.spaceKey)",
@@ -4515,7 +4580,7 @@ var DataSpaceManager = class {
4515
4580
  metadata
4516
4581
  }, {
4517
4582
  F: __dxlog_file14,
4518
- L: 210,
4583
+ L: 252,
4519
4584
  S: this,
4520
4585
  C: (f, a) => f(...a)
4521
4586
  });
@@ -4553,11 +4618,16 @@ var DataSpaceManager = class {
4553
4618
  onAuthFailure: () => {
4554
4619
  import_log12.log.warn("auth failure", void 0, {
4555
4620
  F: __dxlog_file14,
4556
- L: 247,
4621
+ L: 289,
4557
4622
  S: this,
4558
4623
  C: (f, a) => f(...a)
4559
4624
  });
4560
4625
  },
4626
+ onMemberRolesChanged: async (members) => {
4627
+ if (dataSpace?.state === import_services10.SpaceState.READY) {
4628
+ this._handleMemberRoleChanges(presence, space.protocol, members);
4629
+ }
4630
+ },
4561
4631
  memberKey: this._signingContext.identityKey,
4562
4632
  onDelegatedInvitationStatusChange: (invitation, isActive) => {
4563
4633
  return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
@@ -4581,7 +4651,7 @@ var DataSpaceManager = class {
4581
4651
  space: space.key
4582
4652
  }, {
4583
4653
  F: __dxlog_file14,
4584
- L: 269,
4654
+ L: 316,
4585
4655
  S: this,
4586
4656
  C: (f, a) => f(...a)
4587
4657
  });
@@ -4592,7 +4662,7 @@ var DataSpaceManager = class {
4592
4662
  open: this._isOpen
4593
4663
  }, {
4594
4664
  F: __dxlog_file14,
4595
- L: 272,
4665
+ L: 319,
4596
4666
  S: this,
4597
4667
  C: (f, a) => f(...a)
4598
4668
  });
@@ -4600,6 +4670,9 @@ var DataSpaceManager = class {
4600
4670
  await this._createDelegatedInvitations(dataSpace, [
4601
4671
  ...space.spaceState.invitations.entries()
4602
4672
  ]);
4673
+ this._handleMemberRoleChanges(presence, space.protocol, [
4674
+ ...space.spaceState.members.values()
4675
+ ]);
4603
4676
  this.updated.emit();
4604
4677
  }
4605
4678
  },
@@ -4608,7 +4681,7 @@ var DataSpaceManager = class {
4608
4681
  space: space.key
4609
4682
  }, {
4610
4683
  F: __dxlog_file14,
4611
- L: 279,
4684
+ L: 327,
4612
4685
  S: this,
4613
4686
  C: (f, a) => f(...a)
4614
4687
  });
@@ -4616,6 +4689,11 @@ var DataSpaceManager = class {
4616
4689
  },
4617
4690
  cache: metadata.cache
4618
4691
  });
4692
+ presence.newPeer.on((peerState) => {
4693
+ if (dataSpace.state === import_services10.SpaceState.READY) {
4694
+ this._handleNewPeerConnected(space, peerState);
4695
+ }
4696
+ });
4619
4697
  if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4620
4698
  await dataSpace.open();
4621
4699
  }
@@ -4625,6 +4703,51 @@ var DataSpaceManager = class {
4625
4703
  this._spaces.set(metadata.key, dataSpace);
4626
4704
  return dataSpace;
4627
4705
  }
4706
+ _handleMemberRoleChanges(presence, spaceProtocol, memberInfo) {
4707
+ let closedSessions = 0;
4708
+ for (const member of memberInfo) {
4709
+ if (member.key.equals(presence.getLocalState().identityKey)) {
4710
+ continue;
4711
+ }
4712
+ const peers = presence.getPeersByIdentityKey(member.key);
4713
+ const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
4714
+ const sessionsToClose = sessions.filter((s) => {
4715
+ return (s && member.role === import_credentials14.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline3.AuthStatus.FAILURE)) ?? false;
4716
+ });
4717
+ sessionsToClose.forEach((session) => {
4718
+ void session.close().catch(import_log12.log.error);
4719
+ });
4720
+ closedSessions += sessionsToClose.length;
4721
+ }
4722
+ (0, import_log12.log)("processed member role changes", {
4723
+ roleChangeCount: memberInfo.length,
4724
+ peersOnline: presence.getPeersOnline().length,
4725
+ closedSessions
4726
+ }, {
4727
+ F: __dxlog_file14,
4728
+ L: 367,
4729
+ S: this,
4730
+ C: (f, a) => f(...a)
4731
+ });
4732
+ spaceProtocol.updateTopology();
4733
+ }
4734
+ _handleNewPeerConnected(space, peerState) {
4735
+ const role = space.spaceState.getMemberRole(peerState.identityKey);
4736
+ if (role === import_credentials14.SpaceMember.Role.REMOVED) {
4737
+ const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4738
+ if (session != null) {
4739
+ (0, import_log12.log)("closing a session with a removed peer", {
4740
+ peerId: peerState.peerId
4741
+ }, {
4742
+ F: __dxlog_file14,
4743
+ L: 381,
4744
+ S: this,
4745
+ C: (f, a) => f(...a)
4746
+ });
4747
+ void session.close().catch(import_log12.log.error);
4748
+ }
4749
+ }
4750
+ }
4628
4751
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4629
4752
  if (dataSpace?.state !== import_services10.SpaceState.READY) {
4630
4753
  return;
@@ -4684,9 +4807,7 @@ var SpacesServiceImpl = class {
4684
4807
  this._getDataSpaceManager = _getDataSpaceManager;
4685
4808
  }
4686
4809
  async createSpace() {
4687
- if (!this._identityManager.identity) {
4688
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
4689
- }
4810
+ this._requireIdentity();
4690
4811
  const dataSpaceManager = await this._getDataSpaceManager();
4691
4812
  const space = await dataSpaceManager.createSpace();
4692
4813
  return this._serializeSpace(space);
@@ -4707,8 +4828,39 @@ var SpacesServiceImpl = class {
4707
4828
  }
4708
4829
  }
4709
4830
  }
4710
- async updateMemberRole(_) {
4711
- throw new Error("not implemented");
4831
+ async updateMemberRole(request) {
4832
+ const identity = this._requireIdentity();
4833
+ const space = this._spaceManager.spaces.get(request.spaceKey);
4834
+ if (space == null) {
4835
+ throw new import_protocols11.SpaceNotFoundError(request.spaceKey);
4836
+ }
4837
+ if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
4838
+ throw new import_protocols11.AuthorizationError("No member management permission.", {
4839
+ spaceKey: space.key,
4840
+ role: space.spaceState.getMemberRole(identity.identityKey)
4841
+ });
4842
+ }
4843
+ const credentials = await (0, import_credentials17.createAdmissionCredentials)(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
4844
+ (0, import_invariant14.invariant)(credentials[0].credential, void 0, {
4845
+ F: __dxlog_file15,
4846
+ L: 95,
4847
+ S: this,
4848
+ A: [
4849
+ "credentials[0].credential",
4850
+ ""
4851
+ ]
4852
+ });
4853
+ const spaceMemberCredential = credentials[0].credential.credential;
4854
+ (0, import_invariant14.invariant)((0, import_credentials17.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4855
+ F: __dxlog_file15,
4856
+ L: 97,
4857
+ S: this,
4858
+ A: [
4859
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
4860
+ ""
4861
+ ]
4862
+ });
4863
+ await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
4712
4864
  }
4713
4865
  querySpaces() {
4714
4866
  return new import_codec_protobuf10.Stream(({ next, ctx }) => {
@@ -4719,7 +4871,7 @@ var SpacesServiceImpl = class {
4719
4871
  spaces
4720
4872
  }, {
4721
4873
  F: __dxlog_file15,
4722
- L: 82,
4874
+ L: 108,
4723
4875
  S: this,
4724
4876
  C: (f, a) => f(...a)
4725
4877
  });
@@ -4802,7 +4954,7 @@ var SpacesServiceImpl = class {
4802
4954
  } else {
4803
4955
  (0, import_invariant14.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4804
4956
  F: __dxlog_file15,
4805
- L: 169,
4957
+ L: 195,
4806
4958
  S: this,
4807
4959
  A: [
4808
4960
  "!credential.id",
@@ -4811,7 +4963,7 @@ var SpacesServiceImpl = class {
4811
4963
  });
4812
4964
  (0, import_invariant14.invariant)(this._identityManager.identity, "Identity is not available", {
4813
4965
  F: __dxlog_file15,
4814
- L: 170,
4966
+ L: 196,
4815
4967
  S: this,
4816
4968
  A: [
4817
4969
  "this._identityManager.identity",
@@ -4821,7 +4973,7 @@ var SpacesServiceImpl = class {
4821
4973
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4822
4974
  (0, import_invariant14.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4823
4975
  F: __dxlog_file15,
4824
- L: 172,
4976
+ L: 198,
4825
4977
  S: this,
4826
4978
  A: [
4827
4979
  "credential.issuer.equals(signer.getIssuer())",
@@ -4876,7 +5028,8 @@ var SpacesServiceImpl = class {
4876
5028
  identityKey: member.key,
4877
5029
  profile: member.profile ?? {}
4878
5030
  },
4879
- presence: member.role === import_credentials17.SpaceMember.Role.REMOVED ? import_services11.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
5031
+ role: member.role,
5032
+ presence: peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4880
5033
  peerStates: peers
4881
5034
  };
4882
5035
  }),
@@ -4885,6 +5038,12 @@ var SpacesServiceImpl = class {
4885
5038
  metrics: space.metrics
4886
5039
  };
4887
5040
  }
5041
+ _requireIdentity() {
5042
+ if (!this._identityManager.identity) {
5043
+ throw new import_protocols11.IdentityNotInitializedError("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
5044
+ }
5045
+ return this._identityManager.identity;
5046
+ }
4888
5047
  };
4889
5048
  var getChannelId = (channel) => `user-channel/${channel}`;
4890
5049
  function _ts_decorate6(decorators, target, key, desc) {
@@ -4913,8 +5072,8 @@ var ServiceContext = class extends import_context12.Resource {
4913
5072
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4914
5073
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4915
5074
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
4916
- this.feedStore = new import_feed_store4.FeedStore({
4917
- factory: new import_feed_store4.FeedFactory({
5075
+ this.feedStore = new import_feed_store5.FeedStore({
5076
+ factory: new import_feed_store5.FeedFactory({
4918
5077
  root: storage.createDirectory("feeds"),
4919
5078
  signer: this.keyring,
4920
5079
  hypercore: {
@@ -5145,14 +5304,14 @@ var ServiceContext = class extends import_context12.Resource {
5145
5304
  }
5146
5305
  };
5147
5306
  _ts_decorate6([
5148
- import_tracing5.trace.span()
5307
+ import_tracing6.trace.span()
5149
5308
  ], ServiceContext.prototype, "_open", null);
5150
5309
  _ts_decorate6([
5151
- import_tracing5.trace.span()
5310
+ import_tracing6.trace.span()
5152
5311
  ], ServiceContext.prototype, "_initialize", null);
5153
5312
  ServiceContext = _ts_decorate6([
5154
5313
  (0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
5155
- import_tracing5.trace.resource()
5314
+ import_tracing6.trace.resource()
5156
5315
  ], ServiceContext);
5157
5316
  var ServiceRegistry = class {
5158
5317
  // prettier-ignore
@@ -5176,7 +5335,7 @@ var ServiceRegistry = class {
5176
5335
  delete this._handlers[name];
5177
5336
  }
5178
5337
  };
5179
- var DXOS_VERSION = "0.5.3-main.3d65399";
5338
+ var DXOS_VERSION = "0.5.3-main.423e628";
5180
5339
  var getPlatform = () => {
5181
5340
  if (process.browser) {
5182
5341
  if (typeof window !== "undefined") {
@@ -5216,7 +5375,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
5216
5375
  version: import_protocols13.STORAGE_VERSION
5217
5376
  }
5218
5377
  },
5219
- trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
5378
+ trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
5220
5379
  };
5221
5380
  await Promise.all([
5222
5381
  (async () => {
@@ -5279,6 +5438,7 @@ var getSpaceStats = async (space) => {
5279
5438
  id: credential.id
5280
5439
  })),
5281
5440
  members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
5441
+ role: member.role,
5282
5442
  identity: {
5283
5443
  identityKey: member.key,
5284
5444
  profile: {
@@ -5742,7 +5902,7 @@ var ClientServicesHost = class {
5742
5902
  callbacks,
5743
5903
  runtimeParams
5744
5904
  } = {}) {
5745
- this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5905
+ this._tracingService = import_tracing9.TRACE_PROCESSOR.createTraceSender();
5746
5906
  this._statusUpdate = new import_async18.Event();
5747
5907
  this._opening = false;
5748
5908
  this._open = false;
@@ -6104,21 +6264,21 @@ var ClientServicesHost = class {
6104
6264
  }
6105
6265
  };
6106
6266
  _ts_decorate8([
6107
- import_tracing8.trace.info()
6267
+ import_tracing9.trace.info()
6108
6268
  ], ClientServicesHost.prototype, "_opening", void 0);
6109
6269
  _ts_decorate8([
6110
- import_tracing8.trace.info()
6270
+ import_tracing9.trace.info()
6111
6271
  ], ClientServicesHost.prototype, "_open", void 0);
6112
6272
  _ts_decorate8([
6113
6273
  import_async18.synchronized,
6114
- import_tracing8.trace.span()
6274
+ import_tracing9.trace.span()
6115
6275
  ], ClientServicesHost.prototype, "open", null);
6116
6276
  _ts_decorate8([
6117
6277
  import_async18.synchronized,
6118
- import_tracing8.trace.span()
6278
+ import_tracing9.trace.span()
6119
6279
  ], ClientServicesHost.prototype, "close", null);
6120
6280
  ClientServicesHost = _ts_decorate8([
6121
- import_tracing8.trace.resource()
6281
+ import_tracing9.trace.resource()
6122
6282
  ], ClientServicesHost);
6123
6283
  var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
6124
6284
  var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
@@ -6134,7 +6294,7 @@ var DiagnosticsCollector = class {
6134
6294
  });
6135
6295
  const clientDiagnostics = {
6136
6296
  config,
6137
- trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
6297
+ trace: import_tracing8.TRACE_PROCESSOR.getDiagnostics()
6138
6298
  };
6139
6299
  const diagnostics = serviceDiagnostics != null ? {
6140
6300
  client: clientDiagnostics,
@@ -6147,12 +6307,12 @@ var DiagnosticsCollector = class {
6147
6307
  }
6148
6308
  };
6149
6309
  var findSystemServiceProvider = () => {
6150
- const serviceProviders = import_tracing7.TRACE_PROCESSOR.findResourcesByAnnotation(ClientServicesProviderResource);
6310
+ const serviceProviders = import_tracing8.TRACE_PROCESSOR.findResourcesByAnnotation(ClientServicesProviderResource);
6151
6311
  const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
6152
6312
  return providerResource?.instance?.deref() ?? null;
6153
6313
  };
6154
6314
  var findConfigs = () => {
6155
- const configs = import_tracing7.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
6315
+ const configs = import_tracing8.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
6156
6316
  return configs.map((r) => r.instance.deref()).filter(import_util10.nonNullable);
6157
6317
  };
6158
6318
  // Annotate the CommonJS export names for ESM import in node:
@@ -6185,6 +6345,7 @@ var findConfigs = () => {
6185
6345
  createDiagnostics,
6186
6346
  createLevel,
6187
6347
  createStorageObjects,
6348
+ findPropertiesObject,
6188
6349
  getNetworkPeers,
6189
6350
  isLocked,
6190
6351
  subscribeToFeedBlocks,
@@ -6195,4 +6356,4 @@ var findConfigs = () => {
6195
6356
  subscribeToSpaces,
6196
6357
  subscribeToSwarmInfo
6197
6358
  });
6198
- //# sourceMappingURL=chunk-2P53YFFE.cjs.map
6359
+ //# sourceMappingURL=chunk-F5PNMVIG.cjs.map