@dxos/client-services 0.5.3-main.5a4243f → 0.5.3-main.5eb30e6

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-25A3RELK.mjs → chunk-W6NTTNM6.mjs} +281 -120
  2. package/dist/lib/browser/chunk-W6NTTNM6.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-UJ6ZJVX6.cjs → chunk-A4SFXPEF.cjs} +281 -119
  8. package/dist/lib/node/chunk-A4SFXPEF.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 +31 -8
  50. package/src/packlets/spaces/spaces-service.ts +46 -15
  51. package/src/version.ts +1 -1
  52. package/dist/lib/browser/chunk-25A3RELK.mjs.map +0 -7
  53. package/dist/lib/node/chunk-UJ6ZJVX6.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_UJ6ZJVX6_exports = {};
30
- __export(chunk_UJ6ZJVX6_exports, {
29
+ var chunk_A4SFXPEF_exports = {};
30
+ __export(chunk_A4SFXPEF_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -56,6 +56,7 @@ __export(chunk_UJ6ZJVX6_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_UJ6ZJVX6_exports, {
66
67
  subscribeToSpaces: () => subscribeToSpaces,
67
68
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
68
69
  });
69
- module.exports = __toCommonJS(chunk_UJ6ZJVX6_exports);
70
+ module.exports = __toCommonJS(chunk_A4SFXPEF_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,7 @@ var DataSpace = class {
4002
4033
  };
4003
4034
  });
4004
4035
  }
4036
+ await this._echoHost.openSpaceRoot(handle.url);
4005
4037
  } catch (err) {
4006
4038
  if (err instanceof import_context9.ContextDisposedError) {
4007
4039
  return;
@@ -4012,7 +4044,7 @@ var DataSpace = class {
4012
4044
  err
4013
4045
  }, {
4014
4046
  F: __dxlog_file13,
4015
- L: 385,
4047
+ L: 395,
4016
4048
  S: this,
4017
4049
  C: (f, a) => f(...a)
4018
4050
  });
@@ -4067,7 +4099,7 @@ var DataSpace = class {
4067
4099
  const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4068
4100
  (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4069
4101
  F: __dxlog_file13,
4070
- L: 435,
4102
+ L: 445,
4071
4103
  S: this,
4072
4104
  A: [
4073
4105
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -4086,7 +4118,7 @@ var DataSpace = class {
4086
4118
  {
4087
4119
  import_log10.log.info("Fragmenting", void 0, {
4088
4120
  F: __dxlog_file13,
4089
- L: 447,
4121
+ L: 457,
4090
4122
  S: this,
4091
4123
  C: (f, a) => f(...a)
4092
4124
  });
@@ -4094,11 +4126,11 @@ var DataSpace = class {
4094
4126
  const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4095
4127
  await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
4096
4128
  const objects = Object.entries(rootHandle.docSync().objects);
4097
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
4129
+ const properties = findPropertiesObject(rootHandle.docSync());
4098
4130
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4099
4131
  (0, import_invariant11.invariant)(properties, "Properties not found", {
4100
4132
  F: __dxlog_file13,
4101
- L: 457,
4133
+ L: 467,
4102
4134
  S: this,
4103
4135
  A: [
4104
4136
  "properties",
@@ -4114,14 +4146,14 @@ var DataSpace = class {
4114
4146
  const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4115
4147
  (0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4116
4148
  F: __dxlog_file13,
4117
- L: 462,
4149
+ L: 472,
4118
4150
  S: this,
4119
4151
  A: [
4120
4152
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4121
4153
  ""
4122
4154
  ]
4123
4155
  });
4124
- const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
4156
+ const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
4125
4157
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
4126
4158
  rootUrl: newRoot.url
4127
4159
  });
@@ -4183,7 +4215,7 @@ var DataSpace = class {
4183
4215
  state: import_services9.SpaceState[this._state]
4184
4216
  }, {
4185
4217
  F: __dxlog_file13,
4186
- L: 528,
4218
+ L: 538,
4187
4219
  S: this,
4188
4220
  C: (f, a) => f(...a)
4189
4221
  });
@@ -4235,6 +4267,18 @@ DataSpace = _ts_decorate4([
4235
4267
  (0, import_async11.trackLeaks)("open", "close"),
4236
4268
  import_tracing4.trace.resource()
4237
4269
  ], DataSpace);
4270
+ var findPropertiesObject = (spaceDoc) => {
4271
+ for (const id in spaceDoc.objects ?? {}) {
4272
+ const obj = spaceDoc.objects[id];
4273
+ if (obj.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES) {
4274
+ return [
4275
+ id,
4276
+ obj
4277
+ ];
4278
+ }
4279
+ }
4280
+ return void 0;
4281
+ };
4238
4282
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
4239
4283
  const credentials = [
4240
4284
  await (0, import_credentials15.createCredential)({
@@ -4329,6 +4373,28 @@ var DataSpaceManager = class {
4329
4373
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
4330
4374
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
4331
4375
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
4376
+ import_tracing5.trace.diagnostic({
4377
+ id: "spaces",
4378
+ name: "Spaces",
4379
+ fetch: async () => {
4380
+ return Array.from(this._spaces.values()).map((space) => {
4381
+ const rootUrl = space.automergeSpaceState.rootUrl;
4382
+ const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4383
+ const rootDoc = rootHandle?.docSync();
4384
+ const properties = rootDoc && findPropertiesObject(rootDoc);
4385
+ return {
4386
+ key: space.key.toHex(),
4387
+ state: import_services10.SpaceState[space.state],
4388
+ name: properties?.[1].data.name ?? null,
4389
+ inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4390
+ linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
4391
+ credentials: space.inner.spaceState.credentials.length,
4392
+ members: space.inner.spaceState.members.size,
4393
+ rootUrl
4394
+ };
4395
+ });
4396
+ }
4397
+ });
4332
4398
  }
4333
4399
  // TODO(burdon): Remove.
4334
4400
  get spaces() {
@@ -4337,7 +4403,7 @@ var DataSpaceManager = class {
4337
4403
  async open() {
4338
4404
  (0, import_log12.log)("open", void 0, {
4339
4405
  F: __dxlog_file14,
4340
- L: 102,
4406
+ L: 144,
4341
4407
  S: this,
4342
4408
  C: (f, a) => f(...a)
4343
4409
  });
@@ -4345,7 +4411,7 @@ var DataSpaceManager = class {
4345
4411
  id: this._instanceId
4346
4412
  }), {
4347
4413
  F: __dxlog_file14,
4348
- L: 103,
4414
+ L: 145,
4349
4415
  S: this,
4350
4416
  C: (f, a) => f(...a)
4351
4417
  });
@@ -4353,7 +4419,7 @@ var DataSpaceManager = class {
4353
4419
  spaces: this._metadataStore.spaces.length
4354
4420
  }, {
4355
4421
  F: __dxlog_file14,
4356
- L: 104,
4422
+ L: 146,
4357
4423
  S: this,
4358
4424
  C: (f, a) => f(...a)
4359
4425
  });
@@ -4363,7 +4429,7 @@ var DataSpaceManager = class {
4363
4429
  spaceMetadata
4364
4430
  }, {
4365
4431
  F: __dxlog_file14,
4366
- L: 108,
4432
+ L: 150,
4367
4433
  S: this,
4368
4434
  C: (f, a) => f(...a)
4369
4435
  });
@@ -4374,7 +4440,7 @@ var DataSpaceManager = class {
4374
4440
  err
4375
4441
  }, {
4376
4442
  F: __dxlog_file14,
4377
- L: 111,
4443
+ L: 153,
4378
4444
  S: this,
4379
4445
  C: (f, a) => f(...a)
4380
4446
  });
@@ -4391,7 +4457,7 @@ var DataSpaceManager = class {
4391
4457
  id: this._instanceId
4392
4458
  }), {
4393
4459
  F: __dxlog_file14,
4394
- L: 124,
4460
+ L: 166,
4395
4461
  S: this,
4396
4462
  C: (f, a) => f(...a)
4397
4463
  });
@@ -4399,7 +4465,7 @@ var DataSpaceManager = class {
4399
4465
  async close() {
4400
4466
  (0, import_log12.log)("close", void 0, {
4401
4467
  F: __dxlog_file14,
4402
- L: 129,
4468
+ L: 171,
4403
4469
  S: this,
4404
4470
  C: (f, a) => f(...a)
4405
4471
  });
@@ -4415,7 +4481,7 @@ var DataSpaceManager = class {
4415
4481
  async createSpace() {
4416
4482
  (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4417
4483
  F: __dxlog_file14,
4418
- L: 142,
4484
+ L: 184,
4419
4485
  S: this,
4420
4486
  A: [
4421
4487
  "this._isOpen",
@@ -4436,18 +4502,18 @@ var DataSpaceManager = class {
4436
4502
  spaceKey
4437
4503
  }, {
4438
4504
  F: __dxlog_file14,
4439
- L: 154,
4505
+ L: 196,
4440
4506
  S: this,
4441
4507
  C: (f, a) => f(...a)
4442
4508
  });
4443
- const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
4509
+ const root = await this._echoHost.createSpaceRoot(spaceKey);
4444
4510
  const space = await this._constructSpace(metadata);
4445
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4511
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
4446
4512
  await this._metadataStore.addSpace(metadata);
4447
4513
  const memberCredential = credentials[1];
4448
- (0, import_invariant13.invariant)((0, import_credentials14.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4514
+ (0, import_invariant13.invariant)((0, import_credentials13.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4449
4515
  F: __dxlog_file14,
4450
- L: 163,
4516
+ L: 205,
4451
4517
  S: this,
4452
4518
  A: [
4453
4519
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4465,13 +4531,13 @@ var DataSpaceManager = class {
4465
4531
  opts
4466
4532
  }, {
4467
4533
  F: __dxlog_file14,
4468
- L: 175,
4534
+ L: 217,
4469
4535
  S: this,
4470
4536
  C: (f, a) => f(...a)
4471
4537
  });
4472
4538
  (0, import_invariant13.invariant)(this._isOpen, "Not open.", {
4473
4539
  F: __dxlog_file14,
4474
- L: 176,
4540
+ L: 218,
4475
4541
  S: this,
4476
4542
  A: [
4477
4543
  "this._isOpen",
@@ -4480,7 +4546,7 @@ var DataSpaceManager = class {
4480
4546
  });
4481
4547
  (0, import_invariant13.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4482
4548
  F: __dxlog_file14,
4483
- L: 177,
4549
+ L: 219,
4484
4550
  S: this,
4485
4551
  A: [
4486
4552
  "!this._spaces.has(opts.spaceKey)",
@@ -4515,7 +4581,7 @@ var DataSpaceManager = class {
4515
4581
  metadata
4516
4582
  }, {
4517
4583
  F: __dxlog_file14,
4518
- L: 210,
4584
+ L: 252,
4519
4585
  S: this,
4520
4586
  C: (f, a) => f(...a)
4521
4587
  });
@@ -4553,11 +4619,16 @@ var DataSpaceManager = class {
4553
4619
  onAuthFailure: () => {
4554
4620
  import_log12.log.warn("auth failure", void 0, {
4555
4621
  F: __dxlog_file14,
4556
- L: 247,
4622
+ L: 289,
4557
4623
  S: this,
4558
4624
  C: (f, a) => f(...a)
4559
4625
  });
4560
4626
  },
4627
+ onMemberRolesChanged: async (members) => {
4628
+ if (dataSpace?.state === import_services10.SpaceState.READY) {
4629
+ this._handleMemberRoleChanges(presence, space.protocol, members);
4630
+ }
4631
+ },
4561
4632
  memberKey: this._signingContext.identityKey,
4562
4633
  onDelegatedInvitationStatusChange: (invitation, isActive) => {
4563
4634
  return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
@@ -4581,7 +4652,7 @@ var DataSpaceManager = class {
4581
4652
  space: space.key
4582
4653
  }, {
4583
4654
  F: __dxlog_file14,
4584
- L: 269,
4655
+ L: 316,
4585
4656
  S: this,
4586
4657
  C: (f, a) => f(...a)
4587
4658
  });
@@ -4592,7 +4663,7 @@ var DataSpaceManager = class {
4592
4663
  open: this._isOpen
4593
4664
  }, {
4594
4665
  F: __dxlog_file14,
4595
- L: 272,
4666
+ L: 319,
4596
4667
  S: this,
4597
4668
  C: (f, a) => f(...a)
4598
4669
  });
@@ -4600,6 +4671,9 @@ var DataSpaceManager = class {
4600
4671
  await this._createDelegatedInvitations(dataSpace, [
4601
4672
  ...space.spaceState.invitations.entries()
4602
4673
  ]);
4674
+ this._handleMemberRoleChanges(presence, space.protocol, [
4675
+ ...space.spaceState.members.values()
4676
+ ]);
4603
4677
  this.updated.emit();
4604
4678
  }
4605
4679
  },
@@ -4608,7 +4682,7 @@ var DataSpaceManager = class {
4608
4682
  space: space.key
4609
4683
  }, {
4610
4684
  F: __dxlog_file14,
4611
- L: 279,
4685
+ L: 327,
4612
4686
  S: this,
4613
4687
  C: (f, a) => f(...a)
4614
4688
  });
@@ -4616,6 +4690,11 @@ var DataSpaceManager = class {
4616
4690
  },
4617
4691
  cache: metadata.cache
4618
4692
  });
4693
+ presence.newPeer.on((peerState) => {
4694
+ if (dataSpace.state === import_services10.SpaceState.READY) {
4695
+ this._handleNewPeerConnected(space, peerState);
4696
+ }
4697
+ });
4619
4698
  if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4620
4699
  await dataSpace.open();
4621
4700
  }
@@ -4625,6 +4704,51 @@ var DataSpaceManager = class {
4625
4704
  this._spaces.set(metadata.key, dataSpace);
4626
4705
  return dataSpace;
4627
4706
  }
4707
+ _handleMemberRoleChanges(presence, spaceProtocol, memberInfo) {
4708
+ let closedSessions = 0;
4709
+ for (const member of memberInfo) {
4710
+ if (member.key.equals(presence.getLocalState().identityKey)) {
4711
+ continue;
4712
+ }
4713
+ const peers = presence.getPeersByIdentityKey(member.key);
4714
+ const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
4715
+ const sessionsToClose = sessions.filter((s) => {
4716
+ return (s && member.role === import_credentials14.SpaceMember.Role.REMOVED !== (s.authStatus === import_echo_pipeline3.AuthStatus.FAILURE)) ?? false;
4717
+ });
4718
+ sessionsToClose.forEach((session) => {
4719
+ void session.close().catch(import_log12.log.error);
4720
+ });
4721
+ closedSessions += sessionsToClose.length;
4722
+ }
4723
+ (0, import_log12.log)("processed member role changes", {
4724
+ roleChangeCount: memberInfo.length,
4725
+ peersOnline: presence.getPeersOnline().length,
4726
+ closedSessions
4727
+ }, {
4728
+ F: __dxlog_file14,
4729
+ L: 367,
4730
+ S: this,
4731
+ C: (f, a) => f(...a)
4732
+ });
4733
+ spaceProtocol.updateTopology();
4734
+ }
4735
+ _handleNewPeerConnected(space, peerState) {
4736
+ const role = space.spaceState.getMemberRole(peerState.identityKey);
4737
+ if (role === import_credentials14.SpaceMember.Role.REMOVED) {
4738
+ const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4739
+ if (session != null) {
4740
+ (0, import_log12.log)("closing a session with a removed peer", {
4741
+ peerId: peerState.peerId
4742
+ }, {
4743
+ F: __dxlog_file14,
4744
+ L: 381,
4745
+ S: this,
4746
+ C: (f, a) => f(...a)
4747
+ });
4748
+ void session.close().catch(import_log12.log.error);
4749
+ }
4750
+ }
4751
+ }
4628
4752
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4629
4753
  if (dataSpace?.state !== import_services10.SpaceState.READY) {
4630
4754
  return;
@@ -4684,9 +4808,7 @@ var SpacesServiceImpl = class {
4684
4808
  this._getDataSpaceManager = _getDataSpaceManager;
4685
4809
  }
4686
4810
  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
- }
4811
+ this._requireIdentity();
4690
4812
  const dataSpaceManager = await this._getDataSpaceManager();
4691
4813
  const space = await dataSpaceManager.createSpace();
4692
4814
  return this._serializeSpace(space);
@@ -4707,8 +4829,39 @@ var SpacesServiceImpl = class {
4707
4829
  }
4708
4830
  }
4709
4831
  }
4710
- async updateMemberRole(_) {
4711
- throw new Error("not implemented");
4832
+ async updateMemberRole(request) {
4833
+ const identity = this._requireIdentity();
4834
+ const space = this._spaceManager.spaces.get(request.spaceKey);
4835
+ if (space == null) {
4836
+ throw new import_protocols11.SpaceNotFoundError(request.spaceKey);
4837
+ }
4838
+ if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
4839
+ throw new import_protocols11.AuthorizationError("No member management permission.", {
4840
+ spaceKey: space.key,
4841
+ role: space.spaceState.getMemberRole(identity.identityKey)
4842
+ });
4843
+ }
4844
+ const credentials = await (0, import_credentials17.createAdmissionCredentials)(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
4845
+ (0, import_invariant14.invariant)(credentials[0].credential, void 0, {
4846
+ F: __dxlog_file15,
4847
+ L: 95,
4848
+ S: this,
4849
+ A: [
4850
+ "credentials[0].credential",
4851
+ ""
4852
+ ]
4853
+ });
4854
+ const spaceMemberCredential = credentials[0].credential.credential;
4855
+ (0, import_invariant14.invariant)((0, import_credentials17.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4856
+ F: __dxlog_file15,
4857
+ L: 97,
4858
+ S: this,
4859
+ A: [
4860
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
4861
+ ""
4862
+ ]
4863
+ });
4864
+ await (0, import_feed_store4.writeMessages)(space.controlPipeline.writer, credentials);
4712
4865
  }
4713
4866
  querySpaces() {
4714
4867
  return new import_codec_protobuf10.Stream(({ next, ctx }) => {
@@ -4719,7 +4872,7 @@ var SpacesServiceImpl = class {
4719
4872
  spaces
4720
4873
  }, {
4721
4874
  F: __dxlog_file15,
4722
- L: 82,
4875
+ L: 108,
4723
4876
  S: this,
4724
4877
  C: (f, a) => f(...a)
4725
4878
  });
@@ -4802,7 +4955,7 @@ var SpacesServiceImpl = class {
4802
4955
  } else {
4803
4956
  (0, import_invariant14.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4804
4957
  F: __dxlog_file15,
4805
- L: 169,
4958
+ L: 195,
4806
4959
  S: this,
4807
4960
  A: [
4808
4961
  "!credential.id",
@@ -4811,7 +4964,7 @@ var SpacesServiceImpl = class {
4811
4964
  });
4812
4965
  (0, import_invariant14.invariant)(this._identityManager.identity, "Identity is not available", {
4813
4966
  F: __dxlog_file15,
4814
- L: 170,
4967
+ L: 196,
4815
4968
  S: this,
4816
4969
  A: [
4817
4970
  "this._identityManager.identity",
@@ -4821,7 +4974,7 @@ var SpacesServiceImpl = class {
4821
4974
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4822
4975
  (0, import_invariant14.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4823
4976
  F: __dxlog_file15,
4824
- L: 172,
4977
+ L: 198,
4825
4978
  S: this,
4826
4979
  A: [
4827
4980
  "credential.issuer.equals(signer.getIssuer())",
@@ -4876,7 +5029,8 @@ var SpacesServiceImpl = class {
4876
5029
  identityKey: member.key,
4877
5030
  profile: member.profile ?? {}
4878
5031
  },
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,
5032
+ role: member.role,
5033
+ presence: peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4880
5034
  peerStates: peers
4881
5035
  };
4882
5036
  }),
@@ -4885,6 +5039,12 @@ var SpacesServiceImpl = class {
4885
5039
  metrics: space.metrics
4886
5040
  };
4887
5041
  }
5042
+ _requireIdentity() {
5043
+ if (!this._identityManager.identity) {
5044
+ throw new import_protocols11.IdentityNotInitializedError("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
5045
+ }
5046
+ return this._identityManager.identity;
5047
+ }
4888
5048
  };
4889
5049
  var getChannelId = (channel) => `user-channel/${channel}`;
4890
5050
  function _ts_decorate6(decorators, target, key, desc) {
@@ -4913,8 +5073,8 @@ var ServiceContext = class extends import_context12.Resource {
4913
5073
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4914
5074
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4915
5075
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
4916
- this.feedStore = new import_feed_store4.FeedStore({
4917
- factory: new import_feed_store4.FeedFactory({
5076
+ this.feedStore = new import_feed_store5.FeedStore({
5077
+ factory: new import_feed_store5.FeedFactory({
4918
5078
  root: storage.createDirectory("feeds"),
4919
5079
  signer: this.keyring,
4920
5080
  hypercore: {
@@ -5145,14 +5305,14 @@ var ServiceContext = class extends import_context12.Resource {
5145
5305
  }
5146
5306
  };
5147
5307
  _ts_decorate6([
5148
- import_tracing5.trace.span()
5308
+ import_tracing6.trace.span()
5149
5309
  ], ServiceContext.prototype, "_open", null);
5150
5310
  _ts_decorate6([
5151
- import_tracing5.trace.span()
5311
+ import_tracing6.trace.span()
5152
5312
  ], ServiceContext.prototype, "_initialize", null);
5153
5313
  ServiceContext = _ts_decorate6([
5154
5314
  (0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
5155
- import_tracing5.trace.resource()
5315
+ import_tracing6.trace.resource()
5156
5316
  ], ServiceContext);
5157
5317
  var ServiceRegistry = class {
5158
5318
  // prettier-ignore
@@ -5176,7 +5336,7 @@ var ServiceRegistry = class {
5176
5336
  delete this._handlers[name];
5177
5337
  }
5178
5338
  };
5179
- var DXOS_VERSION = "0.5.3-main.5a4243f";
5339
+ var DXOS_VERSION = "0.5.3-main.5eb30e6";
5180
5340
  var getPlatform = () => {
5181
5341
  if (process.browser) {
5182
5342
  if (typeof window !== "undefined") {
@@ -5216,7 +5376,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
5216
5376
  version: import_protocols13.STORAGE_VERSION
5217
5377
  }
5218
5378
  },
5219
- trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
5379
+ trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
5220
5380
  };
5221
5381
  await Promise.all([
5222
5382
  (async () => {
@@ -5279,6 +5439,7 @@ var getSpaceStats = async (space) => {
5279
5439
  id: credential.id
5280
5440
  })),
5281
5441
  members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
5442
+ role: member.role,
5282
5443
  identity: {
5283
5444
  identityKey: member.key,
5284
5445
  profile: {
@@ -5742,7 +5903,7 @@ var ClientServicesHost = class {
5742
5903
  callbacks,
5743
5904
  runtimeParams
5744
5905
  } = {}) {
5745
- this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5906
+ this._tracingService = import_tracing9.TRACE_PROCESSOR.createTraceSender();
5746
5907
  this._statusUpdate = new import_async18.Event();
5747
5908
  this._opening = false;
5748
5909
  this._open = false;
@@ -6104,21 +6265,21 @@ var ClientServicesHost = class {
6104
6265
  }
6105
6266
  };
6106
6267
  _ts_decorate8([
6107
- import_tracing8.trace.info()
6268
+ import_tracing9.trace.info()
6108
6269
  ], ClientServicesHost.prototype, "_opening", void 0);
6109
6270
  _ts_decorate8([
6110
- import_tracing8.trace.info()
6271
+ import_tracing9.trace.info()
6111
6272
  ], ClientServicesHost.prototype, "_open", void 0);
6112
6273
  _ts_decorate8([
6113
6274
  import_async18.synchronized,
6114
- import_tracing8.trace.span()
6275
+ import_tracing9.trace.span()
6115
6276
  ], ClientServicesHost.prototype, "open", null);
6116
6277
  _ts_decorate8([
6117
6278
  import_async18.synchronized,
6118
- import_tracing8.trace.span()
6279
+ import_tracing9.trace.span()
6119
6280
  ], ClientServicesHost.prototype, "close", null);
6120
6281
  ClientServicesHost = _ts_decorate8([
6121
- import_tracing8.trace.resource()
6282
+ import_tracing9.trace.resource()
6122
6283
  ], ClientServicesHost);
6123
6284
  var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
6124
6285
  var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
@@ -6134,7 +6295,7 @@ var DiagnosticsCollector = class {
6134
6295
  });
6135
6296
  const clientDiagnostics = {
6136
6297
  config,
6137
- trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
6298
+ trace: import_tracing8.TRACE_PROCESSOR.getDiagnostics()
6138
6299
  };
6139
6300
  const diagnostics = serviceDiagnostics != null ? {
6140
6301
  client: clientDiagnostics,
@@ -6147,12 +6308,12 @@ var DiagnosticsCollector = class {
6147
6308
  }
6148
6309
  };
6149
6310
  var findSystemServiceProvider = () => {
6150
- const serviceProviders = import_tracing7.TRACE_PROCESSOR.findResourcesByAnnotation(ClientServicesProviderResource);
6311
+ const serviceProviders = import_tracing8.TRACE_PROCESSOR.findResourcesByAnnotation(ClientServicesProviderResource);
6151
6312
  const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
6152
6313
  return providerResource?.instance?.deref() ?? null;
6153
6314
  };
6154
6315
  var findConfigs = () => {
6155
- const configs = import_tracing7.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
6316
+ const configs = import_tracing8.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
6156
6317
  return configs.map((r) => r.instance.deref()).filter(import_util10.nonNullable);
6157
6318
  };
6158
6319
  // Annotate the CommonJS export names for ESM import in node:
@@ -6185,6 +6346,7 @@ var findConfigs = () => {
6185
6346
  createDiagnostics,
6186
6347
  createLevel,
6187
6348
  createStorageObjects,
6349
+ findPropertiesObject,
6188
6350
  getNetworkPeers,
6189
6351
  isLocked,
6190
6352
  subscribeToFeedBlocks,
@@ -6195,4 +6357,4 @@ var findConfigs = () => {
6195
6357
  subscribeToSpaces,
6196
6358
  subscribeToSwarmInfo
6197
6359
  });
6198
- //# sourceMappingURL=chunk-UJ6ZJVX6.cjs.map
6360
+ //# sourceMappingURL=chunk-A4SFXPEF.cjs.map