@dxos/client-services 0.5.3-main.f752aaa → 0.5.3-main.fffc127

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 (53) hide show
  1. package/dist/lib/browser/{chunk-3ZUGGKNX.mjs → chunk-OYIJIAJI.mjs} +293 -120
  2. package/dist/lib/browser/chunk-OYIJIAJI.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-TQQUIYBW.cjs → chunk-FIKOGQP2.cjs} +293 -119
  8. package/dist/lib/node/chunk-FIKOGQP2.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/devtools/feeds.d.ts.map +1 -1
  14. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  15. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  16. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  17. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
  19. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +1 -0
  21. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -0
  23. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -2
  26. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/service-host.d.ts +1 -1
  28. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  29. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -0
  31. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  32. package/dist/types/src/packlets/spaces/data-space.d.ts +6 -1
  33. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  34. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
  35. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  36. package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
  37. package/dist/types/src/packlets/testing/test-builder.d.ts +2 -2
  38. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  39. package/dist/types/src/version.d.ts +1 -1
  40. package/package.json +36 -36
  41. package/src/packlets/diagnostics/diagnostics.ts +1 -0
  42. package/src/packlets/identity/identity-manager.ts +1 -0
  43. package/src/packlets/identity/identity.test.ts +3 -0
  44. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  45. package/src/packlets/invitations/invitation-protocol.ts +2 -0
  46. package/src/packlets/invitations/invitations-manager.ts +5 -0
  47. package/src/packlets/invitations/space-invitation-protocol.ts +29 -2
  48. package/src/packlets/spaces/data-space-manager.ts +100 -10
  49. package/src/packlets/spaces/data-space.ts +35 -8
  50. package/src/packlets/spaces/spaces-service.ts +46 -15
  51. package/src/version.ts +1 -1
  52. package/dist/lib/browser/chunk-3ZUGGKNX.mjs.map +0 -7
  53. package/dist/lib/node/chunk-TQQUIYBW.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_TQQUIYBW_exports = {};
30
- __export(chunk_TQQUIYBW_exports, {
29
+ var chunk_FIKOGQP2_exports = {};
30
+ __export(chunk_FIKOGQP2_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -56,6 +56,7 @@ __export(chunk_TQQUIYBW_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_TQQUIYBW_exports, {
66
67
  subscribeToSpaces: () => subscribeToSpaces,
67
68
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
68
69
  });
69
- module.exports = __toCommonJS(chunk_TQQUIYBW_exports);
70
+ module.exports = __toCommonJS(chunk_FIKOGQP2_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
  });
@@ -4002,6 +4033,19 @@ var DataSpace = class {
4002
4033
  };
4003
4034
  });
4004
4035
  }
4036
+ if (!this._echoHost.roots.has(handle.documentId)) {
4037
+ await this._echoHost.openSpaceRoot(handle.url);
4038
+ } else {
4039
+ import_log10.log.warn("echo database root already exists", {
4040
+ space: this.key,
4041
+ rootUrl
4042
+ }, {
4043
+ F: __dxlog_file13,
4044
+ L: 393,
4045
+ S: this,
4046
+ C: (f, a) => f(...a)
4047
+ });
4048
+ }
4005
4049
  } catch (err) {
4006
4050
  if (err instanceof import_context9.ContextDisposedError) {
4007
4051
  return;
@@ -4012,7 +4056,7 @@ var DataSpace = class {
4012
4056
  err
4013
4057
  }, {
4014
4058
  F: __dxlog_file13,
4015
- L: 385,
4059
+ L: 399,
4016
4060
  S: this,
4017
4061
  C: (f, a) => f(...a)
4018
4062
  });
@@ -4067,7 +4111,7 @@ var DataSpace = class {
4067
4111
  const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4068
4112
  (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4069
4113
  F: __dxlog_file13,
4070
- L: 435,
4114
+ L: 449,
4071
4115
  S: this,
4072
4116
  A: [
4073
4117
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -4086,7 +4130,7 @@ var DataSpace = class {
4086
4130
  {
4087
4131
  import_log10.log.info("Fragmenting", void 0, {
4088
4132
  F: __dxlog_file13,
4089
- L: 447,
4133
+ L: 461,
4090
4134
  S: this,
4091
4135
  C: (f, a) => f(...a)
4092
4136
  });
@@ -4094,11 +4138,11 @@ var DataSpace = class {
4094
4138
  const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4095
4139
  await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
4096
4140
  const objects = Object.entries(rootHandle.docSync().objects);
4097
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
4141
+ const properties = findPropertiesObject(rootHandle.docSync());
4098
4142
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4099
4143
  (0, import_invariant11.invariant)(properties, "Properties not found", {
4100
4144
  F: __dxlog_file13,
4101
- L: 457,
4145
+ L: 471,
4102
4146
  S: this,
4103
4147
  A: [
4104
4148
  "properties",
@@ -4114,14 +4158,14 @@ var DataSpace = class {
4114
4158
  const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4115
4159
  (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4116
4160
  F: __dxlog_file13,
4117
- L: 462,
4161
+ L: 476,
4118
4162
  S: this,
4119
4163
  A: [
4120
4164
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4121
4165
  ""
4122
4166
  ]
4123
4167
  });
4124
- const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
4168
+ const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
4125
4169
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
4126
4170
  rootUrl: newRoot.url
4127
4171
  });
@@ -4183,7 +4227,7 @@ var DataSpace = class {
4183
4227
  state: import_services9.SpaceState[this._state]
4184
4228
  }, {
4185
4229
  F: __dxlog_file13,
4186
- L: 528,
4230
+ L: 542,
4187
4231
  S: this,
4188
4232
  C: (f, a) => f(...a)
4189
4233
  });
@@ -4235,6 +4279,18 @@ DataSpace = _ts_decorate4([
4235
4279
  (0, import_async11.trackLeaks)("open", "close"),
4236
4280
  import_tracing4.trace.resource()
4237
4281
  ], DataSpace);
4282
+ var findPropertiesObject = (spaceDoc) => {
4283
+ for (const id in spaceDoc.objects ?? {}) {
4284
+ const obj = spaceDoc.objects[id];
4285
+ if (obj.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES) {
4286
+ return [
4287
+ id,
4288
+ obj
4289
+ ];
4290
+ }
4291
+ }
4292
+ return void 0;
4293
+ };
4238
4294
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4239
4295
  const credentials = [
4240
4296
  await (0, import_credentials15.createCredential)({
@@ -4329,6 +4385,28 @@ var DataSpaceManager = class {
4329
4385
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
4330
4386
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
4331
4387
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
4388
+ import_tracing5.trace.diagnostic({
4389
+ id: "spaces",
4390
+ name: "Spaces",
4391
+ fetch: async () => {
4392
+ return Array.from(this._spaces.values()).map((space) => {
4393
+ const rootUrl = space.automergeSpaceState.rootUrl;
4394
+ const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4395
+ const rootDoc = rootHandle?.docSync();
4396
+ const properties = rootDoc && findPropertiesObject(rootDoc);
4397
+ return {
4398
+ key: space.key.toHex(),
4399
+ state: import_services10.SpaceState[space.state],
4400
+ name: properties?.[1].data.name ?? null,
4401
+ inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4402
+ linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
4403
+ credentials: space.inner.spaceState.credentials.length,
4404
+ members: space.inner.spaceState.members.size,
4405
+ rootUrl
4406
+ };
4407
+ });
4408
+ }
4409
+ });
4332
4410
  }
4333
4411
  // TODO(burdon): Remove.
4334
4412
  get spaces() {
@@ -4337,7 +4415,7 @@ var DataSpaceManager = class {
4337
4415
  async open() {
4338
4416
  (0, import_log12.log)("open", void 0, {
4339
4417
  F: __dxlog_file14,
4340
- L: 102,
4418
+ L: 144,
4341
4419
  S: this,
4342
4420
  C: (f, a) => f(...a)
4343
4421
  });
@@ -4345,7 +4423,7 @@ var DataSpaceManager = class {
4345
4423
  id: this._instanceId
4346
4424
  }), {
4347
4425
  F: __dxlog_file14,
4348
- L: 103,
4426
+ L: 145,
4349
4427
  S: this,
4350
4428
  C: (f, a) => f(...a)
4351
4429
  });
@@ -4353,7 +4431,7 @@ var DataSpaceManager = class {
4353
4431
  spaces: this._metadataStore.spaces.length
4354
4432
  }, {
4355
4433
  F: __dxlog_file14,
4356
- L: 104,
4434
+ L: 146,
4357
4435
  S: this,
4358
4436
  C: (f, a) => f(...a)
4359
4437
  });
@@ -4363,7 +4441,7 @@ var DataSpaceManager = class {
4363
4441
  spaceMetadata
4364
4442
  }, {
4365
4443
  F: __dxlog_file14,
4366
- L: 108,
4444
+ L: 150,
4367
4445
  S: this,
4368
4446
  C: (f, a) => f(...a)
4369
4447
  });
@@ -4374,7 +4452,7 @@ var DataSpaceManager = class {
4374
4452
  err
4375
4453
  }, {
4376
4454
  F: __dxlog_file14,
4377
- L: 111,
4455
+ L: 153,
4378
4456
  S: this,
4379
4457
  C: (f, a) => f(...a)
4380
4458
  });
@@ -4391,7 +4469,7 @@ var DataSpaceManager = class {
4391
4469
  id: this._instanceId
4392
4470
  }), {
4393
4471
  F: __dxlog_file14,
4394
- L: 124,
4472
+ L: 166,
4395
4473
  S: this,
4396
4474
  C: (f, a) => f(...a)
4397
4475
  });
@@ -4399,7 +4477,7 @@ var DataSpaceManager = class {
4399
4477
  async close() {
4400
4478
  (0, import_log12.log)("close", void 0, {
4401
4479
  F: __dxlog_file14,
4402
- L: 129,
4480
+ L: 171,
4403
4481
  S: this,
4404
4482
  C: (f, a) => f(...a)
4405
4483
  });
@@ -4415,7 +4493,7 @@ var DataSpaceManager = class {
4415
4493
  async createSpace() {
4416
4494
  (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4417
4495
  F: __dxlog_file14,
4418
- L: 142,
4496
+ L: 184,
4419
4497
  S: this,
4420
4498
  A: [
4421
4499
  "this._isOpen",
@@ -4436,18 +4514,18 @@ var DataSpaceManager = class {
4436
4514
  spaceKey
4437
4515
  }, {
4438
4516
  F: __dxlog_file14,
4439
- L: 154,
4517
+ L: 196,
4440
4518
  S: this,
4441
4519
  C: (f, a) => f(...a)
4442
4520
  });
4443
- const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
4521
+ const root = await this._echoHost.createSpaceRoot(spaceKey);
4444
4522
  const space = await this._constructSpace(metadata);
4445
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4523
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4446
4524
  await this._metadataStore.addSpace(metadata);
4447
4525
  const memberCredential = credentials[1];
4448
- (0, import_invariant13.invariant)((0, import_credentials14.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4526
+ (0, import_invariant13.invariant)((0, import_credentials13.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4449
4527
  F: __dxlog_file14,
4450
- L: 163,
4528
+ L: 205,
4451
4529
  S: this,
4452
4530
  A: [
4453
4531
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4465,13 +4543,13 @@ var DataSpaceManager = class {
4465
4543
  opts
4466
4544
  }, {
4467
4545
  F: __dxlog_file14,
4468
- L: 175,
4546
+ L: 217,
4469
4547
  S: this,
4470
4548
  C: (f, a) => f(...a)
4471
4549
  });
4472
4550
  (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4473
4551
  F: __dxlog_file14,
4474
- L: 176,
4552
+ L: 218,
4475
4553
  S: this,
4476
4554
  A: [
4477
4555
  "this._isOpen",
@@ -4480,7 +4558,7 @@ var DataSpaceManager = class {
4480
4558
  });
4481
4559
  (0, import_invariant13.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4482
4560
  F: __dxlog_file14,
4483
- L: 177,
4561
+ L: 219,
4484
4562
  S: this,
4485
4563
  A: [
4486
4564
  "!this._spaces.has(opts.spaceKey)",
@@ -4515,7 +4593,7 @@ var DataSpaceManager = class {
4515
4593
  metadata
4516
4594
  }, {
4517
4595
  F: __dxlog_file14,
4518
- L: 210,
4596
+ L: 252,
4519
4597
  S: this,
4520
4598
  C: (f, a) => f(...a)
4521
4599
  });
@@ -4553,11 +4631,16 @@ var DataSpaceManager = class {
4553
4631
  onAuthFailure: () => {
4554
4632
  import_log12.log.warn("auth failure", void 0, {
4555
4633
  F: __dxlog_file14,
4556
- L: 247,
4634
+ L: 289,
4557
4635
  S: this,
4558
4636
  C: (f, a) => f(...a)
4559
4637
  });
4560
4638
  },
4639
+ onMemberRolesChanged: async (members) => {
4640
+ if (dataSpace?.state === import_services10.SpaceState.READY) {
4641
+ this._handleMemberRoleChanges(presence, space.protocol, members);
4642
+ }
4643
+ },
4561
4644
  memberKey: this._signingContext.identityKey,
4562
4645
  onDelegatedInvitationStatusChange: (invitation, isActive) => {
4563
4646
  return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
@@ -4581,7 +4664,7 @@ var DataSpaceManager = class {
4581
4664
  space: space.key
4582
4665
  }, {
4583
4666
  F: __dxlog_file14,
4584
- L: 269,
4667
+ L: 316,
4585
4668
  S: this,
4586
4669
  C: (f, a) => f(...a)
4587
4670
  });
@@ -4592,7 +4675,7 @@ var DataSpaceManager = class {
4592
4675
  open: this._isOpen
4593
4676
  }, {
4594
4677
  F: __dxlog_file14,
4595
- L: 272,
4678
+ L: 319,
4596
4679
  S: this,
4597
4680
  C: (f, a) => f(...a)
4598
4681
  });
@@ -4600,6 +4683,9 @@ var DataSpaceManager = class {
4600
4683
  await this._createDelegatedInvitations(dataSpace, [
4601
4684
  ...space.spaceState.invitations.entries()
4602
4685
  ]);
4686
+ this._handleMemberRoleChanges(presence, space.protocol, [
4687
+ ...space.spaceState.members.values()
4688
+ ]);
4603
4689
  this.updated.emit();
4604
4690
  }
4605
4691
  },
@@ -4608,7 +4694,7 @@ var DataSpaceManager = class {
4608
4694
  space: space.key
4609
4695
  }, {
4610
4696
  F: __dxlog_file14,
4611
- L: 279,
4697
+ L: 327,
4612
4698
  S: this,
4613
4699
  C: (f, a) => f(...a)
4614
4700
  });
@@ -4616,6 +4702,11 @@ var DataSpaceManager = class {
4616
4702
  },
4617
4703
  cache: metadata.cache
4618
4704
  });
4705
+ presence.newPeer.on((peerState) => {
4706
+ if (dataSpace.state === import_services10.SpaceState.READY) {
4707
+ this._handleNewPeerConnected(space, peerState);
4708
+ }
4709
+ });
4619
4710
  if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4620
4711
  await dataSpace.open();
4621
4712
  }
@@ -4625,6 +4716,51 @@ var DataSpaceManager = class {
4625
4716
  this._spaces.set(metadata.key, dataSpace);
4626
4717
  return dataSpace;
4627
4718
  }
4719
+ _handleMemberRoleChanges(presence, spaceProtocol, memberInfo) {
4720
+ let closedSessions = 0;
4721
+ for (const member of memberInfo) {
4722
+ if (member.key.equals(presence.getLocalState().identityKey)) {
4723
+ continue;
4724
+ }
4725
+ const peers = presence.getPeersByIdentityKey(member.key);
4726
+ const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
4727
+ const sessionsToClose = sessions.filter((s) => {
4728
+ return (s && member.role === import_credentials14.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline3.AuthStatus.FAILURE)) ?? false;
4729
+ });
4730
+ sessionsToClose.forEach((session) => {
4731
+ void session.close().catch(import_log12.log.error);
4732
+ });
4733
+ closedSessions += sessionsToClose.length;
4734
+ }
4735
+ (0, import_log12.log)("processed member role changes", {
4736
+ roleChangeCount: memberInfo.length,
4737
+ peersOnline: presence.getPeersOnline().length,
4738
+ closedSessions
4739
+ }, {
4740
+ F: __dxlog_file14,
4741
+ L: 367,
4742
+ S: this,
4743
+ C: (f, a) => f(...a)
4744
+ });
4745
+ spaceProtocol.updateTopology();
4746
+ }
4747
+ _handleNewPeerConnected(space, peerState) {
4748
+ const role = space.spaceState.getMemberRole(peerState.identityKey);
4749
+ if (role === import_credentials14.SpaceMember.Role.REMOVED) {
4750
+ const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4751
+ if (session != null) {
4752
+ (0, import_log12.log)("closing a session with a removed peer", {
4753
+ peerId: peerState.peerId
4754
+ }, {
4755
+ F: __dxlog_file14,
4756
+ L: 381,
4757
+ S: this,
4758
+ C: (f, a) => f(...a)
4759
+ });
4760
+ void session.close().catch(import_log12.log.error);
4761
+ }
4762
+ }
4763
+ }
4628
4764
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4629
4765
  if (dataSpace?.state !== import_services10.SpaceState.READY) {
4630
4766
  return;
@@ -4684,9 +4820,7 @@ var SpacesServiceImpl = class {
4684
4820
  this._getDataSpaceManager = _getDataSpaceManager;
4685
4821
  }
4686
4822
  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
- }
4823
+ this._requireIdentity();
4690
4824
  const dataSpaceManager = await this._getDataSpaceManager();
4691
4825
  const space = await dataSpaceManager.createSpace();
4692
4826
  return this._serializeSpace(space);
@@ -4707,8 +4841,39 @@ var SpacesServiceImpl = class {
4707
4841
  }
4708
4842
  }
4709
4843
  }
4710
- async updateMemberRole(_) {
4711
- throw new Error("not implemented");
4844
+ async updateMemberRole(request) {
4845
+ const identity = this._requireIdentity();
4846
+ const space = this._spaceManager.spaces.get(request.spaceKey);
4847
+ if (space == null) {
4848
+ throw new import_protocols11.SpaceNotFoundError(request.spaceKey);
4849
+ }
4850
+ if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
4851
+ throw new import_protocols11.AuthorizationError("No member management permission.", {
4852
+ spaceKey: space.key,
4853
+ role: space.spaceState.getMemberRole(identity.identityKey)
4854
+ });
4855
+ }
4856
+ const credentials = await (0, import_credentials17.createAdmissionCredentials)(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
4857
+ (0, import_invariant14.invariant)(credentials[0].credential, void 0, {
4858
+ F: __dxlog_file15,
4859
+ L: 95,
4860
+ S: this,
4861
+ A: [
4862
+ "credentials[0].credential",
4863
+ ""
4864
+ ]
4865
+ });
4866
+ const spaceMemberCredential = credentials[0].credential.credential;
4867
+ (0, import_invariant14.invariant)((0, import_credentials17.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4868
+ F: __dxlog_file15,
4869
+ L: 97,
4870
+ S: this,
4871
+ A: [
4872
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
4873
+ ""
4874
+ ]
4875
+ });
4876
+ await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
4712
4877
  }
4713
4878
  querySpaces() {
4714
4879
  return new import_codec_protobuf10.Stream(({ next, ctx }) => {
@@ -4719,7 +4884,7 @@ var SpacesServiceImpl = class {
4719
4884
  spaces
4720
4885
  }, {
4721
4886
  F: __dxlog_file15,
4722
- L: 82,
4887
+ L: 108,
4723
4888
  S: this,
4724
4889
  C: (f, a) => f(...a)
4725
4890
  });
@@ -4802,7 +4967,7 @@ var SpacesServiceImpl = class {
4802
4967
  } else {
4803
4968
  (0, import_invariant14.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4804
4969
  F: __dxlog_file15,
4805
- L: 169,
4970
+ L: 195,
4806
4971
  S: this,
4807
4972
  A: [
4808
4973
  "!credential.id",
@@ -4811,7 +4976,7 @@ var SpacesServiceImpl = class {
4811
4976
  });
4812
4977
  (0, import_invariant14.invariant)(this._identityManager.identity, "Identity is not available", {
4813
4978
  F: __dxlog_file15,
4814
- L: 170,
4979
+ L: 196,
4815
4980
  S: this,
4816
4981
  A: [
4817
4982
  "this._identityManager.identity",
@@ -4821,7 +4986,7 @@ var SpacesServiceImpl = class {
4821
4986
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4822
4987
  (0, import_invariant14.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4823
4988
  F: __dxlog_file15,
4824
- L: 172,
4989
+ L: 198,
4825
4990
  S: this,
4826
4991
  A: [
4827
4992
  "credential.issuer.equals(signer.getIssuer())",
@@ -4876,7 +5041,8 @@ var SpacesServiceImpl = class {
4876
5041
  identityKey: member.key,
4877
5042
  profile: member.profile ?? {}
4878
5043
  },
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,
5044
+ role: member.role,
5045
+ presence: peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4880
5046
  peerStates: peers
4881
5047
  };
4882
5048
  }),
@@ -4885,6 +5051,12 @@ var SpacesServiceImpl = class {
4885
5051
  metrics: space.metrics
4886
5052
  };
4887
5053
  }
5054
+ _requireIdentity() {
5055
+ if (!this._identityManager.identity) {
5056
+ throw new import_protocols11.IdentityNotInitializedError("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
5057
+ }
5058
+ return this._identityManager.identity;
5059
+ }
4888
5060
  };
4889
5061
  var getChannelId = (channel) => `user-channel/${channel}`;
4890
5062
  function _ts_decorate6(decorators, target, key, desc) {
@@ -4913,8 +5085,8 @@ var ServiceContext = class extends import_context12.Resource {
4913
5085
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4914
5086
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4915
5087
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
4916
- this.feedStore = new import_feed_store4.FeedStore({
4917
- factory: new import_feed_store4.FeedFactory({
5088
+ this.feedStore = new import_feed_store5.FeedStore({
5089
+ factory: new import_feed_store5.FeedFactory({
4918
5090
  root: storage.createDirectory("feeds"),
4919
5091
  signer: this.keyring,
4920
5092
  hypercore: {
@@ -5145,14 +5317,14 @@ var ServiceContext = class extends import_context12.Resource {
5145
5317
  }
5146
5318
  };
5147
5319
  _ts_decorate6([
5148
- import_tracing5.trace.span()
5320
+ import_tracing6.trace.span()
5149
5321
  ], ServiceContext.prototype, "_open", null);
5150
5322
  _ts_decorate6([
5151
- import_tracing5.trace.span()
5323
+ import_tracing6.trace.span()
5152
5324
  ], ServiceContext.prototype, "_initialize", null);
5153
5325
  ServiceContext = _ts_decorate6([
5154
5326
  (0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
5155
- import_tracing5.trace.resource()
5327
+ import_tracing6.trace.resource()
5156
5328
  ], ServiceContext);
5157
5329
  var ServiceRegistry = class {
5158
5330
  // prettier-ignore
@@ -5176,7 +5348,7 @@ var ServiceRegistry = class {
5176
5348
  delete this._handlers[name];
5177
5349
  }
5178
5350
  };
5179
- var DXOS_VERSION = "0.5.3-main.f752aaa";
5351
+ var DXOS_VERSION = "0.5.3-main.fffc127";
5180
5352
  var getPlatform = () => {
5181
5353
  if (process.browser) {
5182
5354
  if (typeof window !== "undefined") {
@@ -5216,7 +5388,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
5216
5388
  version: import_protocols13.STORAGE_VERSION
5217
5389
  }
5218
5390
  },
5219
- trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
5391
+ trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
5220
5392
  };
5221
5393
  await Promise.all([
5222
5394
  (async () => {
@@ -5279,6 +5451,7 @@ var getSpaceStats = async (space) => {
5279
5451
  id: credential.id
5280
5452
  })),
5281
5453
  members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
5454
+ role: member.role,
5282
5455
  identity: {
5283
5456
  identityKey: member.key,
5284
5457
  profile: {
@@ -5742,7 +5915,7 @@ var ClientServicesHost = class {
5742
5915
  callbacks,
5743
5916
  runtimeParams
5744
5917
  } = {}) {
5745
- this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5918
+ this._tracingService = import_tracing9.TRACE_PROCESSOR.createTraceSender();
5746
5919
  this._statusUpdate = new import_async18.Event();
5747
5920
  this._opening = false;
5748
5921
  this._open = false;
@@ -6104,21 +6277,21 @@ var ClientServicesHost = class {
6104
6277
  }
6105
6278
  };
6106
6279
  _ts_decorate8([
6107
- import_tracing8.trace.info()
6280
+ import_tracing9.trace.info()
6108
6281
  ], ClientServicesHost.prototype, "_opening", void 0);
6109
6282
  _ts_decorate8([
6110
- import_tracing8.trace.info()
6283
+ import_tracing9.trace.info()
6111
6284
  ], ClientServicesHost.prototype, "_open", void 0);
6112
6285
  _ts_decorate8([
6113
6286
  import_async18.synchronized,
6114
- import_tracing8.trace.span()
6287
+ import_tracing9.trace.span()
6115
6288
  ], ClientServicesHost.prototype, "open", null);
6116
6289
  _ts_decorate8([
6117
6290
  import_async18.synchronized,
6118
- import_tracing8.trace.span()
6291
+ import_tracing9.trace.span()
6119
6292
  ], ClientServicesHost.prototype, "close", null);
6120
6293
  ClientServicesHost = _ts_decorate8([
6121
- import_tracing8.trace.resource()
6294
+ import_tracing9.trace.resource()
6122
6295
  ], ClientServicesHost);
6123
6296
  var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
6124
6297
  var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
@@ -6134,7 +6307,7 @@ var DiagnosticsCollector = class {
6134
6307
  });
6135
6308
  const clientDiagnostics = {
6136
6309
  config,
6137
- trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
6310
+ trace: import_tracing8.TRACE_PROCESSOR.getDiagnostics()
6138
6311
  };
6139
6312
  const diagnostics = serviceDiagnostics != null ? {
6140
6313
  client: clientDiagnostics,
@@ -6147,12 +6320,12 @@ var DiagnosticsCollector = class {
6147
6320
  }
6148
6321
  };
6149
6322
  var findSystemServiceProvider = () => {
6150
- const serviceProviders = import_tracing7.TRACE_PROCESSOR.findResourcesByAnnotation(ClientServicesProviderResource);
6323
+ const serviceProviders = import_tracing8.TRACE_PROCESSOR.findResourcesByAnnotation(ClientServicesProviderResource);
6151
6324
  const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
6152
6325
  return providerResource?.instance?.deref() ?? null;
6153
6326
  };
6154
6327
  var findConfigs = () => {
6155
- const configs = import_tracing7.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
6328
+ const configs = import_tracing8.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
6156
6329
  return configs.map((r) => r.instance.deref()).filter(import_util10.nonNullable);
6157
6330
  };
6158
6331
  // Annotate the CommonJS export names for ESM import in node:
@@ -6185,6 +6358,7 @@ var findConfigs = () => {
6185
6358
  createDiagnostics,
6186
6359
  createLevel,
6187
6360
  createStorageObjects,
6361
+ findPropertiesObject,
6188
6362
  getNetworkPeers,
6189
6363
  isLocked,
6190
6364
  subscribeToFeedBlocks,
@@ -6195,4 +6369,4 @@ var findConfigs = () => {
6195
6369
  subscribeToSpaces,
6196
6370
  subscribeToSwarmInfo
6197
6371
  });
6198
- //# sourceMappingURL=chunk-TQQUIYBW.cjs.map
6372
+ //# sourceMappingURL=chunk-FIKOGQP2.cjs.map