@dxos/client-services 0.5.3-main.3d65399 → 0.5.3-main.427f0a3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/lib/browser/{chunk-KNPCT2EX.mjs → chunk-7DFCTMMT.mjs} +278 -118
  2. package/dist/lib/browser/chunk-7DFCTMMT.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-2P53YFFE.cjs → chunk-JH6OUTBB.cjs} +278 -117
  8. package/dist/lib/node/chunk-JH6OUTBB.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +45 -43
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  14. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
  15. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +1 -0
  17. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -2
  20. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -0
  22. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/data-space.d.ts +6 -1
  24. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
  26. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  27. package/dist/types/src/version.d.ts +1 -1
  28. package/package.json +36 -36
  29. package/src/packlets/diagnostics/diagnostics.ts +1 -0
  30. package/src/packlets/identity/identity-manager.ts +1 -0
  31. package/src/packlets/identity/identity.test.ts +3 -0
  32. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  33. package/src/packlets/invitations/invitation-protocol.ts +2 -0
  34. package/src/packlets/invitations/invitations-manager.ts +5 -0
  35. package/src/packlets/invitations/space-invitation-protocol.ts +29 -2
  36. package/src/packlets/spaces/data-space-manager.ts +98 -8
  37. package/src/packlets/spaces/data-space.ts +27 -8
  38. package/src/packlets/spaces/spaces-service.ts +46 -15
  39. package/src/version.ts +1 -1
  40. package/dist/lib/browser/chunk-KNPCT2EX.mjs.map +0 -7
  41. package/dist/lib/node/chunk-2P53YFFE.cjs.map +0 -7
@@ -1088,6 +1088,8 @@ var IdentityManager = class {
1088
1088
  },
1089
1089
  memberKey: identityKey,
1090
1090
  onDelegatedInvitationStatusChange: async () => {
1091
+ },
1092
+ onMemberRolesChanged: async () => {
1091
1093
  }
1092
1094
  });
1093
1095
  }
@@ -1191,6 +1193,9 @@ var DeviceInvitationProtocol = class {
1191
1193
  toJSON() {
1192
1194
  return {};
1193
1195
  }
1196
+ checkCanInviteNewMembers() {
1197
+ return void 0;
1198
+ }
1194
1199
  getInvitationContext() {
1195
1200
  return {
1196
1201
  kind: Invitation.Kind.DEVICE
@@ -1205,7 +1210,7 @@ var DeviceInvitationProtocol = class {
1205
1210
  async admit(_, request) {
1206
1211
  invariant4(request.device, void 0, {
1207
1212
  F: __dxlog_file5,
1208
- L: 46,
1213
+ L: 50,
1209
1214
  S: this,
1210
1215
  A: [
1211
1216
  "request.device",
@@ -1251,7 +1256,7 @@ var DeviceInvitationProtocol = class {
1251
1256
  async accept(response, request) {
1252
1257
  invariant4(response.device, void 0, {
1253
1258
  F: __dxlog_file5,
1254
- L: 91,
1259
+ L: 95,
1255
1260
  S: this,
1256
1261
  A: [
1257
1262
  "response.device",
@@ -1261,7 +1266,7 @@ var DeviceInvitationProtocol = class {
1261
1266
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1262
1267
  invariant4(request.device, void 0, {
1263
1268
  F: __dxlog_file5,
1264
- L: 94,
1269
+ L: 98,
1265
1270
  S: this,
1266
1271
  A: [
1267
1272
  "request.device",
@@ -2561,7 +2566,7 @@ import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredent
2561
2566
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2562
2567
  import { invariant as invariant9 } from "@dxos/invariant";
2563
2568
  import { log as log8 } from "@dxos/log";
2564
- import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2569
+ import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
2565
2570
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2566
2571
  import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2567
2572
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
@@ -2578,6 +2583,19 @@ var SpaceInvitationProtocol = class {
2578
2583
  spaceKey: this._spaceKey
2579
2584
  };
2580
2585
  }
2586
+ checkCanInviteNewMembers() {
2587
+ if (this._spaceKey == null) {
2588
+ return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
2589
+ }
2590
+ const space = this._spaceManager.spaces.get(this._spaceKey);
2591
+ if (space == null) {
2592
+ return new SpaceNotFoundError(this._spaceKey);
2593
+ }
2594
+ if (!space?.inner.spaceState.hasMembershipManagementPermission(this._signingContext.identityKey)) {
2595
+ return new AuthorizationError("No member management permission.");
2596
+ }
2597
+ return void 0;
2598
+ }
2581
2599
  getInvitationContext() {
2582
2600
  return {
2583
2601
  kind: Invitation5.Kind.SPACE,
@@ -2587,7 +2605,7 @@ var SpaceInvitationProtocol = class {
2587
2605
  async admit(invitation, request, guestProfile) {
2588
2606
  invariant9(this._spaceKey, void 0, {
2589
2607
  F: __dxlog_file10,
2590
- L: 56,
2608
+ L: 76,
2591
2609
  S: this,
2592
2610
  A: [
2593
2611
  "this._spaceKey",
@@ -2597,7 +2615,7 @@ var SpaceInvitationProtocol = class {
2597
2615
  const space = this._spaceManager.spaces.get(this._spaceKey);
2598
2616
  invariant9(space, void 0, {
2599
2617
  F: __dxlog_file10,
2600
- L: 58,
2618
+ L: 78,
2601
2619
  S: this,
2602
2620
  A: [
2603
2621
  "space",
@@ -2606,7 +2624,7 @@ var SpaceInvitationProtocol = class {
2606
2624
  });
2607
2625
  invariant9(request.space, void 0, {
2608
2626
  F: __dxlog_file10,
2609
- L: 60,
2627
+ L: 80,
2610
2628
  S: this,
2611
2629
  A: [
2612
2630
  "request.space",
@@ -2614,19 +2632,22 @@ var SpaceInvitationProtocol = class {
2614
2632
  ]
2615
2633
  });
2616
2634
  const { identityKey, deviceKey } = request.space;
2635
+ if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember.Role.REMOVED) {
2636
+ throw new AlreadyJoinedError2();
2637
+ }
2617
2638
  log8("writing guest credentials", {
2618
2639
  host: this._signingContext.deviceKey,
2619
2640
  guest: deviceKey
2620
2641
  }, {
2621
2642
  F: __dxlog_file10,
2622
- L: 63,
2643
+ L: 87,
2623
2644
  S: this,
2624
2645
  C: (f, a) => f(...a)
2625
2646
  });
2626
2647
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
2627
2648
  invariant9(credentials[0].credential, void 0, {
2628
2649
  F: __dxlog_file10,
2629
- L: 77,
2650
+ L: 101,
2630
2651
  S: this,
2631
2652
  A: [
2632
2653
  "credentials[0].credential",
@@ -2636,7 +2657,7 @@ var SpaceInvitationProtocol = class {
2636
2657
  const spaceMemberCredential = credentials[0].credential.credential;
2637
2658
  invariant9(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2638
2659
  F: __dxlog_file10,
2639
- L: 79,
2660
+ L: 103,
2640
2661
  S: this,
2641
2662
  A: [
2642
2663
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2654,7 +2675,7 @@ var SpaceInvitationProtocol = class {
2654
2675
  async delegate(invitation) {
2655
2676
  invariant9(this._spaceKey, void 0, {
2656
2677
  F: __dxlog_file10,
2657
- L: 92,
2678
+ L: 116,
2658
2679
  S: this,
2659
2680
  A: [
2660
2681
  "this._spaceKey",
@@ -2664,7 +2685,7 @@ var SpaceInvitationProtocol = class {
2664
2685
  const space = this._spaceManager.spaces.get(this._spaceKey);
2665
2686
  invariant9(space, void 0, {
2666
2687
  F: __dxlog_file10,
2667
- L: 94,
2688
+ L: 118,
2668
2689
  S: this,
2669
2690
  A: [
2670
2691
  "space",
@@ -2674,7 +2695,7 @@ var SpaceInvitationProtocol = class {
2674
2695
  if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
2675
2696
  invariant9(invitation.guestKeypair?.publicKey, void 0, {
2676
2697
  F: __dxlog_file10,
2677
- L: 96,
2698
+ L: 120,
2678
2699
  S: this,
2679
2700
  A: [
2680
2701
  "invitation.guestKeypair?.publicKey",
@@ -2687,7 +2708,7 @@ var SpaceInvitationProtocol = class {
2687
2708
  id: invitation.invitationId
2688
2709
  }, {
2689
2710
  F: __dxlog_file10,
2690
- L: 99,
2711
+ L: 123,
2691
2712
  S: this,
2692
2713
  C: (f, a) => f(...a)
2693
2714
  });
@@ -2702,7 +2723,7 @@ var SpaceInvitationProtocol = class {
2702
2723
  });
2703
2724
  invariant9(credential.credential, void 0, {
2704
2725
  F: __dxlog_file10,
2705
- L: 119,
2726
+ L: 143,
2706
2727
  S: this,
2707
2728
  A: [
2708
2729
  "credential.credential",
@@ -2717,7 +2738,7 @@ var SpaceInvitationProtocol = class {
2717
2738
  async cancelDelegation(invitation) {
2718
2739
  invariant9(this._spaceKey, void 0, {
2719
2740
  F: __dxlog_file10,
2720
- L: 125,
2741
+ L: 149,
2721
2742
  S: this,
2722
2743
  A: [
2723
2744
  "this._spaceKey",
@@ -2726,7 +2747,7 @@ var SpaceInvitationProtocol = class {
2726
2747
  });
2727
2748
  invariant9(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
2728
2749
  F: __dxlog_file10,
2729
- L: 126,
2750
+ L: 150,
2730
2751
  S: this,
2731
2752
  A: [
2732
2753
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -2736,7 +2757,7 @@ var SpaceInvitationProtocol = class {
2736
2757
  const space = this._spaceManager.spaces.get(this._spaceKey);
2737
2758
  invariant9(space, void 0, {
2738
2759
  F: __dxlog_file10,
2739
- L: 128,
2760
+ L: 152,
2740
2761
  S: this,
2741
2762
  A: [
2742
2763
  "space",
@@ -2748,14 +2769,14 @@ var SpaceInvitationProtocol = class {
2748
2769
  id: invitation.invitationId
2749
2770
  }, {
2750
2771
  F: __dxlog_file10,
2751
- L: 130,
2772
+ L: 154,
2752
2773
  S: this,
2753
2774
  C: (f, a) => f(...a)
2754
2775
  });
2755
2776
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
2756
2777
  invariant9(credential.credential, void 0, {
2757
2778
  F: __dxlog_file10,
2758
- L: 137,
2779
+ L: 161,
2759
2780
  S: this,
2760
2781
  A: [
2761
2782
  "credential.credential",
@@ -2767,7 +2788,10 @@ var SpaceInvitationProtocol = class {
2767
2788
  ]);
2768
2789
  }
2769
2790
  checkInvitation(invitation) {
2770
- if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2791
+ if (invitation.spaceKey == null) {
2792
+ return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
2793
+ }
2794
+ if (this._spaceManager.spaces.has(invitation.spaceKey)) {
2771
2795
  return new AlreadyJoinedError2("Already joined space.");
2772
2796
  }
2773
2797
  }
@@ -2791,7 +2815,7 @@ var SpaceInvitationProtocol = class {
2791
2815
  async accept(response) {
2792
2816
  invariant9(response.space, void 0, {
2793
2817
  F: __dxlog_file10,
2794
- L: 169,
2818
+ L: 196,
2795
2819
  S: this,
2796
2820
  A: [
2797
2821
  "response.space",
@@ -2802,7 +2826,7 @@ var SpaceInvitationProtocol = class {
2802
2826
  const assertion = getCredentialAssertion(credential);
2803
2827
  invariant9(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2804
2828
  F: __dxlog_file10,
2805
- L: 172,
2829
+ L: 199,
2806
2830
  S: this,
2807
2831
  A: [
2808
2832
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2811,7 +2835,7 @@ var SpaceInvitationProtocol = class {
2811
2835
  });
2812
2836
  invariant9(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2813
2837
  F: __dxlog_file10,
2814
- L: 173,
2838
+ L: 200,
2815
2839
  S: this,
2816
2840
  A: [
2817
2841
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2869,6 +2893,10 @@ var InvitationsManager = class {
2869
2893
  }
2870
2894
  }
2871
2895
  const handler = this._getHandler(options);
2896
+ const invitationError = handler.checkCanInviteNewMembers();
2897
+ if (invitationError != null) {
2898
+ throw invitationError;
2899
+ }
2872
2900
  const invitation = this._createInvitation(handler, options);
2873
2901
  const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2874
2902
  this._createInvitations.set(invitation.invitationId, observableInvitation);
@@ -2885,7 +2913,7 @@ var InvitationsManager = class {
2885
2913
  } catch (err) {
2886
2914
  log9.catch(err, void 0, {
2887
2915
  F: __dxlog_file11,
2888
- L: 77,
2916
+ L: 82,
2889
2917
  S: this,
2890
2918
  C: (f, a) => f(...a)
2891
2919
  });
@@ -2908,7 +2936,7 @@ var InvitationsManager = class {
2908
2936
  const loadTasks = freshInvitations.map((persistentInvitation) => {
2909
2937
  invariant10(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2910
2938
  F: __dxlog_file11,
2911
- L: 98,
2939
+ L: 103,
2912
2940
  S: this,
2913
2941
  A: [
2914
2942
  "!this._createInvitations.get(persistentInvitation.invitationId)",
@@ -2927,7 +2955,7 @@ var InvitationsManager = class {
2927
2955
  } catch (err) {
2928
2956
  log9.catch(err, void 0, {
2929
2957
  F: __dxlog_file11,
2930
- L: 105,
2958
+ L: 110,
2931
2959
  S: this,
2932
2960
  C: (f, a) => f(...a)
2933
2961
  });
@@ -2959,13 +2987,13 @@ var InvitationsManager = class {
2959
2987
  async authenticate({ invitationId, authCode }) {
2960
2988
  log9("authenticating...", void 0, {
2961
2989
  F: __dxlog_file11,
2962
- L: 135,
2990
+ L: 140,
2963
2991
  S: this,
2964
2992
  C: (f, a) => f(...a)
2965
2993
  });
2966
2994
  invariant10(invitationId, void 0, {
2967
2995
  F: __dxlog_file11,
2968
- L: 136,
2996
+ L: 141,
2969
2997
  S: this,
2970
2998
  A: [
2971
2999
  "invitationId",
@@ -2978,7 +3006,7 @@ var InvitationsManager = class {
2978
3006
  invitationId
2979
3007
  }, {
2980
3008
  F: __dxlog_file11,
2981
- L: 139,
3009
+ L: 144,
2982
3010
  S: this,
2983
3011
  C: (f, a) => f(...a)
2984
3012
  });
@@ -2991,13 +3019,13 @@ var InvitationsManager = class {
2991
3019
  invitationId
2992
3020
  }, {
2993
3021
  F: __dxlog_file11,
2994
- L: 146,
3022
+ L: 151,
2995
3023
  S: this,
2996
3024
  C: (f, a) => f(...a)
2997
3025
  });
2998
3026
  invariant10(invitationId, void 0, {
2999
3027
  F: __dxlog_file11,
3000
- L: 147,
3028
+ L: 152,
3001
3029
  S: this,
3002
3030
  A: [
3003
3031
  "invitationId",
@@ -3076,7 +3104,7 @@ var InvitationsManager = class {
3076
3104
  ...handler.toJSON()
3077
3105
  }, {
3078
3106
  F: __dxlog_file11,
3079
- L: 236,
3107
+ L: 241,
3080
3108
  S: this,
3081
3109
  C: (f, a) => f(...a)
3082
3110
  });
@@ -3109,7 +3137,7 @@ var InvitationsManager = class {
3109
3137
  ...handler.toJSON()
3110
3138
  }, {
3111
3139
  F: __dxlog_file11,
3112
- L: 256,
3140
+ L: 261,
3113
3141
  S: this,
3114
3142
  C: (f, a) => f(...a)
3115
3143
  });
@@ -3120,7 +3148,7 @@ var InvitationsManager = class {
3120
3148
  } else {
3121
3149
  log9.warn("auth failed", err, {
3122
3150
  F: __dxlog_file11,
3123
- L: 259,
3151
+ L: 264,
3124
3152
  S: this,
3125
3153
  C: (f, a) => f(...a)
3126
3154
  });
@@ -3137,7 +3165,7 @@ var InvitationsManager = class {
3137
3165
  ...handler.toJSON()
3138
3166
  }, {
3139
3167
  F: __dxlog_file11,
3140
- L: 266,
3168
+ L: 271,
3141
3169
  S: this,
3142
3170
  C: (f, a) => f(...a)
3143
3171
  });
@@ -3182,7 +3210,7 @@ var InvitationsManager = class {
3182
3210
  } catch (err) {
3183
3211
  log9.catch(err, void 0, {
3184
3212
  F: __dxlog_file11,
3185
- L: 302,
3213
+ L: 307,
3186
3214
  S: this,
3187
3215
  C: (f, a) => f(...a)
3188
3216
  });
@@ -3279,18 +3307,16 @@ ClientRpcServer = _ts_decorate3([
3279
3307
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3280
3308
  import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
3281
3309
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3282
- import { cancelWithContext as cancelWithContext4, Context as Context8, ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
3310
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3283
3311
  import { timed, warnAfterTimeout } from "@dxos/debug";
3284
- import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3285
- import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3312
+ import { AutomergeDocumentLoaderImpl, createMappedFeedWriter } from "@dxos/echo-pipeline";
3286
3313
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3287
3314
  import { failedInvariant, invariant as invariant12 } from "@dxos/invariant";
3288
3315
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3289
3316
  import { log as log11 } from "@dxos/log";
3290
3317
  import { CancelledError, SystemError } from "@dxos/protocols";
3291
- import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3292
- import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3293
- import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3318
+ import { CreateEpochRequest, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
3319
+ import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3294
3320
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3295
3321
  import { trace as trace6 } from "@dxos/tracing";
3296
3322
  import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
@@ -3648,7 +3674,7 @@ var DataSpace = class {
3648
3674
  state: SpaceState[this._state]
3649
3675
  }, {
3650
3676
  F: __dxlog_file13,
3651
- L: 137,
3677
+ L: 141,
3652
3678
  S: this,
3653
3679
  C: (f, a) => f(...a)
3654
3680
  });
@@ -3698,7 +3724,7 @@ var DataSpace = class {
3698
3724
  state: SpaceState[this._state]
3699
3725
  }, {
3700
3726
  F: __dxlog_file13,
3701
- L: 195,
3727
+ L: 199,
3702
3728
  S: this,
3703
3729
  C: (f, a) => f(...a)
3704
3730
  });
@@ -3716,7 +3742,7 @@ var DataSpace = class {
3716
3742
  state: SpaceState[this._state]
3717
3743
  }, {
3718
3744
  F: __dxlog_file13,
3719
- L: 209,
3745
+ L: 213,
3720
3746
  S: this,
3721
3747
  C: (f, a) => f(...a)
3722
3748
  });
@@ -3748,7 +3774,7 @@ var DataSpace = class {
3748
3774
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
3749
3775
  log11("data pipeline initialization cancelled", err, {
3750
3776
  F: __dxlog_file13,
3751
- L: 242,
3777
+ L: 246,
3752
3778
  S: this,
3753
3779
  C: (f, a) => f(...a)
3754
3780
  });
@@ -3756,7 +3782,7 @@ var DataSpace = class {
3756
3782
  }
3757
3783
  log11.error("Error initializing data pipeline", err, {
3758
3784
  F: __dxlog_file13,
3759
- L: 246,
3785
+ L: 250,
3760
3786
  S: this,
3761
3787
  C: (f, a) => f(...a)
3762
3788
  });
@@ -3765,7 +3791,7 @@ var DataSpace = class {
3765
3791
  state: SpaceState[this._state]
3766
3792
  }, {
3767
3793
  F: __dxlog_file13,
3768
- L: 248,
3794
+ L: 252,
3769
3795
  S: this,
3770
3796
  C: (f, a) => f(...a)
3771
3797
  });
@@ -3785,7 +3811,7 @@ var DataSpace = class {
3785
3811
  state: SpaceState[this._state]
3786
3812
  }, {
3787
3813
  F: __dxlog_file13,
3788
- L: 264,
3814
+ L: 268,
3789
3815
  S: this,
3790
3816
  C: (f, a) => f(...a)
3791
3817
  });
@@ -3795,7 +3821,7 @@ var DataSpace = class {
3795
3821
  await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3796
3822
  log11("data pipeline ready", void 0, {
3797
3823
  F: __dxlog_file13,
3798
- L: 276,
3824
+ L: 280,
3799
3825
  S: this,
3800
3826
  C: (f, a) => f(...a)
3801
3827
  });
@@ -3805,7 +3831,7 @@ var DataSpace = class {
3805
3831
  state: SpaceState[this._state]
3806
3832
  }, {
3807
3833
  F: __dxlog_file13,
3808
- L: 280,
3834
+ L: 284,
3809
3835
  S: this,
3810
3836
  C: (f, a) => f(...a)
3811
3837
  });
@@ -3821,7 +3847,7 @@ var DataSpace = class {
3821
3847
  await this._createWritableFeeds();
3822
3848
  log11("writable feeds created", void 0, {
3823
3849
  F: __dxlog_file13,
3824
- L: 296,
3850
+ L: 300,
3825
3851
  S: this,
3826
3852
  C: (f, a) => f(...a)
3827
3853
  });
@@ -3884,7 +3910,7 @@ var DataSpace = class {
3884
3910
  rootUrl
3885
3911
  }, {
3886
3912
  F: __dxlog_file13,
3887
- L: 362,
3913
+ L: 366,
3888
3914
  S: this,
3889
3915
  C: (f, a) => f(...a)
3890
3916
  });
@@ -3916,7 +3942,7 @@ var DataSpace = class {
3916
3942
  err
3917
3943
  }, {
3918
3944
  F: __dxlog_file13,
3919
- L: 385,
3945
+ L: 391,
3920
3946
  S: this,
3921
3947
  C: (f, a) => f(...a)
3922
3948
  });
@@ -3971,7 +3997,7 @@ var DataSpace = class {
3971
3997
  const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
3972
3998
  invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3973
3999
  F: __dxlog_file13,
3974
- L: 435,
4000
+ L: 441,
3975
4001
  S: this,
3976
4002
  A: [
3977
4003
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3990,7 +4016,7 @@ var DataSpace = class {
3990
4016
  {
3991
4017
  log11.info("Fragmenting", void 0, {
3992
4018
  F: __dxlog_file13,
3993
- L: 447,
4019
+ L: 453,
3994
4020
  S: this,
3995
4021
  C: (f, a) => f(...a)
3996
4022
  });
@@ -3998,11 +4024,11 @@ var DataSpace = class {
3998
4024
  const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3999
4025
  await cancelWithContext4(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
4000
4026
  const objects = Object.entries(rootHandle.docSync().objects);
4001
- const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
4027
+ const properties = findPropertiesObject(rootHandle.docSync());
4002
4028
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4003
4029
  invariant12(properties, "Properties not found", {
4004
4030
  F: __dxlog_file13,
4005
- L: 457,
4031
+ L: 463,
4006
4032
  S: this,
4007
4033
  A: [
4008
4034
  "properties",
@@ -4018,7 +4044,7 @@ var DataSpace = class {
4018
4044
  const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4019
4045
  invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4020
4046
  F: __dxlog_file13,
4021
- L: 462,
4047
+ L: 468,
4022
4048
  S: this,
4023
4049
  A: [
4024
4050
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -4087,7 +4113,7 @@ var DataSpace = class {
4087
4113
  state: SpaceState[this._state]
4088
4114
  }, {
4089
4115
  F: __dxlog_file13,
4090
- L: 528,
4116
+ L: 534,
4091
4117
  S: this,
4092
4118
  C: (f, a) => f(...a)
4093
4119
  });
@@ -4139,17 +4165,32 @@ DataSpace = _ts_decorate4([
4139
4165
  trackLeaks("open", "close"),
4140
4166
  trace6.resource()
4141
4167
  ], DataSpace);
4168
+ var findPropertiesObject = (spaceDoc) => {
4169
+ for (const id in spaceDoc.objects ?? {}) {
4170
+ const obj = spaceDoc.objects[id];
4171
+ if (obj.system.type?.itemId === TYPE_PROPERTIES) {
4172
+ return [
4173
+ id,
4174
+ obj
4175
+ ];
4176
+ }
4177
+ }
4178
+ return void 0;
4179
+ };
4142
4180
 
4143
4181
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4144
4182
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4145
- import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
4183
+ import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
4146
4184
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
4185
+ import { AuthStatus } from "@dxos/echo-pipeline";
4147
4186
  import { invariant as invariant13 } from "@dxos/invariant";
4148
4187
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4149
4188
  import { log as log12 } from "@dxos/log";
4150
- import { trace as trace7 } from "@dxos/protocols";
4189
+ import { trace as Trace2 } from "@dxos/protocols";
4151
4190
  import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
4191
+ import { SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
4152
4192
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4193
+ import { trace as trace7 } from "@dxos/tracing";
4153
4194
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4154
4195
 
4155
4196
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
@@ -4253,6 +4294,28 @@ var DataSpaceManager = class {
4253
4294
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
4254
4295
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
4255
4296
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
4297
+ trace7.diagnostic({
4298
+ id: "spaces",
4299
+ name: "Spaces",
4300
+ fetch: async () => {
4301
+ return Array.from(this._spaces.values()).map((space) => {
4302
+ const rootUrl = space.automergeSpaceState.rootUrl;
4303
+ const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4304
+ const rootDoc = rootHandle?.docSync();
4305
+ const properties = rootDoc && findPropertiesObject(rootDoc);
4306
+ return {
4307
+ key: space.key.toHex(),
4308
+ state: SpaceState2[space.state],
4309
+ name: properties?.[1].data.name ?? null,
4310
+ inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
4311
+ linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
4312
+ credentials: space.inner.spaceState.credentials.length,
4313
+ members: space.inner.spaceState.members.size,
4314
+ rootUrl
4315
+ };
4316
+ });
4317
+ }
4318
+ });
4256
4319
  }
4257
4320
  // TODO(burdon): Remove.
4258
4321
  get spaces() {
@@ -4261,15 +4324,15 @@ var DataSpaceManager = class {
4261
4324
  async open() {
4262
4325
  log12("open", void 0, {
4263
4326
  F: __dxlog_file14,
4264
- L: 102,
4327
+ L: 144,
4265
4328
  S: this,
4266
4329
  C: (f, a) => f(...a)
4267
4330
  });
4268
- log12.trace("dxos.echo.data-space-manager.open", trace7.begin({
4331
+ log12.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4269
4332
  id: this._instanceId
4270
4333
  }), {
4271
4334
  F: __dxlog_file14,
4272
- L: 103,
4335
+ L: 145,
4273
4336
  S: this,
4274
4337
  C: (f, a) => f(...a)
4275
4338
  });
@@ -4277,7 +4340,7 @@ var DataSpaceManager = class {
4277
4340
  spaces: this._metadataStore.spaces.length
4278
4341
  }, {
4279
4342
  F: __dxlog_file14,
4280
- L: 104,
4343
+ L: 146,
4281
4344
  S: this,
4282
4345
  C: (f, a) => f(...a)
4283
4346
  });
@@ -4287,7 +4350,7 @@ var DataSpaceManager = class {
4287
4350
  spaceMetadata
4288
4351
  }, {
4289
4352
  F: __dxlog_file14,
4290
- L: 108,
4353
+ L: 150,
4291
4354
  S: this,
4292
4355
  C: (f, a) => f(...a)
4293
4356
  });
@@ -4298,7 +4361,7 @@ var DataSpaceManager = class {
4298
4361
  err
4299
4362
  }, {
4300
4363
  F: __dxlog_file14,
4301
- L: 111,
4364
+ L: 153,
4302
4365
  S: this,
4303
4366
  C: (f, a) => f(...a)
4304
4367
  });
@@ -4311,11 +4374,11 @@ var DataSpaceManager = class {
4311
4374
  space.initializeDataPipelineAsync();
4312
4375
  }
4313
4376
  }
4314
- log12.trace("dxos.echo.data-space-manager.open", trace7.end({
4377
+ log12.trace("dxos.echo.data-space-manager.open", Trace2.end({
4315
4378
  id: this._instanceId
4316
4379
  }), {
4317
4380
  F: __dxlog_file14,
4318
- L: 124,
4381
+ L: 166,
4319
4382
  S: this,
4320
4383
  C: (f, a) => f(...a)
4321
4384
  });
@@ -4323,7 +4386,7 @@ var DataSpaceManager = class {
4323
4386
  async close() {
4324
4387
  log12("close", void 0, {
4325
4388
  F: __dxlog_file14,
4326
- L: 129,
4389
+ L: 171,
4327
4390
  S: this,
4328
4391
  C: (f, a) => f(...a)
4329
4392
  });
@@ -4339,7 +4402,7 @@ var DataSpaceManager = class {
4339
4402
  async createSpace() {
4340
4403
  invariant13(this._isOpen, "Not open.", {
4341
4404
  F: __dxlog_file14,
4342
- L: 142,
4405
+ L: 184,
4343
4406
  S: this,
4344
4407
  A: [
4345
4408
  "this._isOpen",
@@ -4360,7 +4423,7 @@ var DataSpaceManager = class {
4360
4423
  spaceKey
4361
4424
  }, {
4362
4425
  F: __dxlog_file14,
4363
- L: 154,
4426
+ L: 196,
4364
4427
  S: this,
4365
4428
  C: (f, a) => f(...a)
4366
4429
  });
@@ -4371,7 +4434,7 @@ var DataSpaceManager = class {
4371
4434
  const memberCredential = credentials[1];
4372
4435
  invariant13(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4373
4436
  F: __dxlog_file14,
4374
- L: 163,
4437
+ L: 205,
4375
4438
  S: this,
4376
4439
  A: [
4377
4440
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4389,13 +4452,13 @@ var DataSpaceManager = class {
4389
4452
  opts
4390
4453
  }, {
4391
4454
  F: __dxlog_file14,
4392
- L: 175,
4455
+ L: 217,
4393
4456
  S: this,
4394
4457
  C: (f, a) => f(...a)
4395
4458
  });
4396
4459
  invariant13(this._isOpen, "Not open.", {
4397
4460
  F: __dxlog_file14,
4398
- L: 176,
4461
+ L: 218,
4399
4462
  S: this,
4400
4463
  A: [
4401
4464
  "this._isOpen",
@@ -4404,7 +4467,7 @@ var DataSpaceManager = class {
4404
4467
  });
4405
4468
  invariant13(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4406
4469
  F: __dxlog_file14,
4407
- L: 177,
4470
+ L: 219,
4408
4471
  S: this,
4409
4472
  A: [
4410
4473
  "!this._spaces.has(opts.spaceKey)",
@@ -4439,7 +4502,7 @@ var DataSpaceManager = class {
4439
4502
  metadata
4440
4503
  }, {
4441
4504
  F: __dxlog_file14,
4442
- L: 210,
4505
+ L: 252,
4443
4506
  S: this,
4444
4507
  C: (f, a) => f(...a)
4445
4508
  });
@@ -4477,11 +4540,16 @@ var DataSpaceManager = class {
4477
4540
  onAuthFailure: () => {
4478
4541
  log12.warn("auth failure", void 0, {
4479
4542
  F: __dxlog_file14,
4480
- L: 247,
4543
+ L: 289,
4481
4544
  S: this,
4482
4545
  C: (f, a) => f(...a)
4483
4546
  });
4484
4547
  },
4548
+ onMemberRolesChanged: async (members) => {
4549
+ if (dataSpace?.state === SpaceState2.READY) {
4550
+ this._handleMemberRoleChanges(presence, space.protocol, members);
4551
+ }
4552
+ },
4485
4553
  memberKey: this._signingContext.identityKey,
4486
4554
  onDelegatedInvitationStatusChange: (invitation, isActive) => {
4487
4555
  return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
@@ -4505,7 +4573,7 @@ var DataSpaceManager = class {
4505
4573
  space: space.key
4506
4574
  }, {
4507
4575
  F: __dxlog_file14,
4508
- L: 269,
4576
+ L: 316,
4509
4577
  S: this,
4510
4578
  C: (f, a) => f(...a)
4511
4579
  });
@@ -4516,7 +4584,7 @@ var DataSpaceManager = class {
4516
4584
  open: this._isOpen
4517
4585
  }, {
4518
4586
  F: __dxlog_file14,
4519
- L: 272,
4587
+ L: 319,
4520
4588
  S: this,
4521
4589
  C: (f, a) => f(...a)
4522
4590
  });
@@ -4524,6 +4592,9 @@ var DataSpaceManager = class {
4524
4592
  await this._createDelegatedInvitations(dataSpace, [
4525
4593
  ...space.spaceState.invitations.entries()
4526
4594
  ]);
4595
+ this._handleMemberRoleChanges(presence, space.protocol, [
4596
+ ...space.spaceState.members.values()
4597
+ ]);
4527
4598
  this.updated.emit();
4528
4599
  }
4529
4600
  },
@@ -4532,7 +4603,7 @@ var DataSpaceManager = class {
4532
4603
  space: space.key
4533
4604
  }, {
4534
4605
  F: __dxlog_file14,
4535
- L: 279,
4606
+ L: 327,
4536
4607
  S: this,
4537
4608
  C: (f, a) => f(...a)
4538
4609
  });
@@ -4540,6 +4611,11 @@ var DataSpaceManager = class {
4540
4611
  },
4541
4612
  cache: metadata.cache
4542
4613
  });
4614
+ presence.newPeer.on((peerState) => {
4615
+ if (dataSpace.state === SpaceState2.READY) {
4616
+ this._handleNewPeerConnected(space, peerState);
4617
+ }
4618
+ });
4543
4619
  if (metadata.state !== SpaceState2.INACTIVE) {
4544
4620
  await dataSpace.open();
4545
4621
  }
@@ -4549,6 +4625,51 @@ var DataSpaceManager = class {
4549
4625
  this._spaces.set(metadata.key, dataSpace);
4550
4626
  return dataSpace;
4551
4627
  }
4628
+ _handleMemberRoleChanges(presence, spaceProtocol, memberInfo) {
4629
+ let closedSessions = 0;
4630
+ for (const member of memberInfo) {
4631
+ if (member.key.equals(presence.getLocalState().identityKey)) {
4632
+ continue;
4633
+ }
4634
+ const peers = presence.getPeersByIdentityKey(member.key);
4635
+ const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
4636
+ const sessionsToClose = sessions.filter((s) => {
4637
+ return (s && member.role === SpaceMember5.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
4638
+ });
4639
+ sessionsToClose.forEach((session) => {
4640
+ void session.close().catch(log12.error);
4641
+ });
4642
+ closedSessions += sessionsToClose.length;
4643
+ }
4644
+ log12("processed member role changes", {
4645
+ roleChangeCount: memberInfo.length,
4646
+ peersOnline: presence.getPeersOnline().length,
4647
+ closedSessions
4648
+ }, {
4649
+ F: __dxlog_file14,
4650
+ L: 367,
4651
+ S: this,
4652
+ C: (f, a) => f(...a)
4653
+ });
4654
+ spaceProtocol.updateTopology();
4655
+ }
4656
+ _handleNewPeerConnected(space, peerState) {
4657
+ const role = space.spaceState.getMemberRole(peerState.identityKey);
4658
+ if (role === SpaceMember5.Role.REMOVED) {
4659
+ const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
4660
+ if (session != null) {
4661
+ log12("closing a session with a removed peer", {
4662
+ peerId: peerState.peerId
4663
+ }, {
4664
+ F: __dxlog_file14,
4665
+ L: 381,
4666
+ S: this,
4667
+ C: (f, a) => f(...a)
4668
+ });
4669
+ void session.close().catch(log12.error);
4670
+ }
4671
+ }
4672
+ }
4552
4673
  async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4553
4674
  if (dataSpace?.state !== SpaceState2.READY) {
4554
4675
  return;
@@ -4604,12 +4725,13 @@ DataSpaceManager = _ts_decorate5([
4604
4725
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
4605
4726
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4606
4727
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4728
+ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4607
4729
  import { raise as raise2 } from "@dxos/debug";
4730
+ import { writeMessages as writeMessages3 } from "@dxos/feed-store";
4608
4731
  import { invariant as invariant14 } from "@dxos/invariant";
4609
4732
  import { log as log13 } from "@dxos/log";
4610
- import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4611
- import { SpaceMember as SpaceMember5, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4612
- import { SpaceMember as HaloSpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
4733
+ import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
4734
+ import { SpaceMember as SpaceMember6, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4613
4735
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4614
4736
  var SpacesServiceImpl = class {
4615
4737
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
@@ -4618,16 +4740,14 @@ var SpacesServiceImpl = class {
4618
4740
  this._getDataSpaceManager = _getDataSpaceManager;
4619
4741
  }
4620
4742
  async createSpace() {
4621
- if (!this._identityManager.identity) {
4622
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
4623
- }
4743
+ this._requireIdentity();
4624
4744
  const dataSpaceManager = await this._getDataSpaceManager();
4625
4745
  const space = await dataSpaceManager.createSpace();
4626
4746
  return this._serializeSpace(space);
4627
4747
  }
4628
4748
  async updateSpace({ spaceKey, state }) {
4629
4749
  const dataSpaceManager = await this._getDataSpaceManager();
4630
- const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4750
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
4631
4751
  if (state) {
4632
4752
  switch (state) {
4633
4753
  case SpaceState3.ACTIVE:
@@ -4641,8 +4761,39 @@ var SpacesServiceImpl = class {
4641
4761
  }
4642
4762
  }
4643
4763
  }
4644
- async updateMemberRole(_) {
4645
- throw new Error("not implemented");
4764
+ async updateMemberRole(request) {
4765
+ const identity = this._requireIdentity();
4766
+ const space = this._spaceManager.spaces.get(request.spaceKey);
4767
+ if (space == null) {
4768
+ throw new SpaceNotFoundError2(request.spaceKey);
4769
+ }
4770
+ if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
4771
+ throw new AuthorizationError2("No member management permission.", {
4772
+ spaceKey: space.key,
4773
+ role: space.spaceState.getMemberRole(identity.identityKey)
4774
+ });
4775
+ }
4776
+ const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
4777
+ invariant14(credentials[0].credential, void 0, {
4778
+ F: __dxlog_file15,
4779
+ L: 95,
4780
+ S: this,
4781
+ A: [
4782
+ "credentials[0].credential",
4783
+ ""
4784
+ ]
4785
+ });
4786
+ const spaceMemberCredential = credentials[0].credential.credential;
4787
+ invariant14(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4788
+ F: __dxlog_file15,
4789
+ L: 97,
4790
+ S: this,
4791
+ A: [
4792
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
4793
+ ""
4794
+ ]
4795
+ });
4796
+ await writeMessages3(space.controlPipeline.writer, credentials);
4646
4797
  }
4647
4798
  querySpaces() {
4648
4799
  return new Stream10(({ next, ctx }) => {
@@ -4653,7 +4804,7 @@ var SpacesServiceImpl = class {
4653
4804
  spaces
4654
4805
  }, {
4655
4806
  F: __dxlog_file15,
4656
- L: 82,
4807
+ L: 108,
4657
4808
  S: this,
4658
4809
  C: (f, a) => f(...a)
4659
4810
  });
@@ -4692,14 +4843,14 @@ var SpacesServiceImpl = class {
4692
4843
  }
4693
4844
  async postMessage({ spaceKey, channel, message }) {
4694
4845
  const dataSpaceManager = await this._getDataSpaceManager();
4695
- const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4846
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
4696
4847
  await space.postMessage(getChannelId(channel), message);
4697
4848
  }
4698
4849
  subscribeMessages({ spaceKey, channel }) {
4699
4850
  return new Stream10(({ ctx, next }) => {
4700
4851
  scheduleTask6(ctx, async () => {
4701
4852
  const dataSpaceManager = await this._getDataSpaceManager();
4702
- const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4853
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
4703
4854
  const handle = space.listen(getChannelId(channel), (message) => {
4704
4855
  next(message);
4705
4856
  });
@@ -4709,7 +4860,7 @@ var SpacesServiceImpl = class {
4709
4860
  }
4710
4861
  queryCredentials({ spaceKey, noTail }) {
4711
4862
  return new Stream10(({ ctx, next, close }) => {
4712
- const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4863
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
4713
4864
  const processor = {
4714
4865
  processCredential: async (credential) => {
4715
4866
  next(credential);
@@ -4725,7 +4876,7 @@ var SpacesServiceImpl = class {
4725
4876
  });
4726
4877
  }
4727
4878
  async writeCredentials({ spaceKey, credentials }) {
4728
- const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4879
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
4729
4880
  for (const credential of credentials ?? []) {
4730
4881
  if (credential.proof) {
4731
4882
  await space.controlPipeline.writer.write({
@@ -4736,7 +4887,7 @@ var SpacesServiceImpl = class {
4736
4887
  } else {
4737
4888
  invariant14(!credential.id, "Id on unsigned credentials is not allowed", {
4738
4889
  F: __dxlog_file15,
4739
- L: 169,
4890
+ L: 195,
4740
4891
  S: this,
4741
4892
  A: [
4742
4893
  "!credential.id",
@@ -4745,7 +4896,7 @@ var SpacesServiceImpl = class {
4745
4896
  });
4746
4897
  invariant14(this._identityManager.identity, "Identity is not available", {
4747
4898
  F: __dxlog_file15,
4748
- L: 170,
4899
+ L: 196,
4749
4900
  S: this,
4750
4901
  A: [
4751
4902
  "this._identityManager.identity",
@@ -4755,7 +4906,7 @@ var SpacesServiceImpl = class {
4755
4906
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4756
4907
  invariant14(credential.issuer.equals(signer.getIssuer()), void 0, {
4757
4908
  F: __dxlog_file15,
4758
- L: 172,
4909
+ L: 198,
4759
4910
  S: this,
4760
4911
  A: [
4761
4912
  "credential.issuer.equals(signer.getIssuer())",
@@ -4776,7 +4927,7 @@ var SpacesServiceImpl = class {
4776
4927
  }
4777
4928
  async createEpoch({ spaceKey, migration }) {
4778
4929
  const dataSpaceManager = await this._getDataSpaceManager();
4779
- const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4930
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
4780
4931
  await space.createEpoch({
4781
4932
  migration
4782
4933
  });
@@ -4810,7 +4961,8 @@ var SpacesServiceImpl = class {
4810
4961
  identityKey: member.key,
4811
4962
  profile: member.profile ?? {}
4812
4963
  },
4813
- presence: member.role === HaloSpaceMember.Role.REMOVED ? SpaceMember5.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember5.PresenceState.ONLINE : SpaceMember5.PresenceState.OFFLINE,
4964
+ role: member.role,
4965
+ presence: peers.length > 0 ? SpaceMember6.PresenceState.ONLINE : SpaceMember6.PresenceState.OFFLINE,
4814
4966
  peerStates: peers
4815
4967
  };
4816
4968
  }),
@@ -4819,13 +4971,19 @@ var SpacesServiceImpl = class {
4819
4971
  metrics: space.metrics
4820
4972
  };
4821
4973
  }
4974
+ _requireIdentity() {
4975
+ if (!this._identityManager.identity) {
4976
+ throw new IdentityNotInitializedError("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
4977
+ }
4978
+ return this._identityManager.identity;
4979
+ }
4822
4980
  };
4823
4981
  var getChannelId = (channel) => `user-channel/${channel}`;
4824
4982
 
4825
4983
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4826
4984
  import { Trigger as Trigger6 } from "@dxos/async";
4827
4985
  import { Context as Context10, Resource } from "@dxos/context";
4828
- import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4986
+ import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
4829
4987
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4830
4988
  import { EchoHost } from "@dxos/echo-db";
4831
4989
  import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -4837,7 +4995,7 @@ import { log as log14 } from "@dxos/log";
4837
4995
  import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4838
4996
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
4839
4997
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4840
- import { trace as Trace2 } from "@dxos/tracing";
4998
+ import { trace as Trace3 } from "@dxos/tracing";
4841
4999
  import { safeInstanceof } from "@dxos/util";
4842
5000
  function _ts_decorate6(decorators, target, key, desc) {
4843
5001
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -5041,7 +5199,7 @@ var ServiceContext = class extends Resource {
5041
5199
  this.initialized.wake();
5042
5200
  this._deviceSpaceSync = {
5043
5201
  processCredential: async (credential) => {
5044
- const assertion = getCredentialAssertion3(credential);
5202
+ const assertion = getCredentialAssertion4(credential);
5045
5203
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
5046
5204
  return;
5047
5205
  }
@@ -5097,14 +5255,14 @@ var ServiceContext = class extends Resource {
5097
5255
  }
5098
5256
  };
5099
5257
  _ts_decorate6([
5100
- Trace2.span()
5258
+ Trace3.span()
5101
5259
  ], ServiceContext.prototype, "_open", null);
5102
5260
  _ts_decorate6([
5103
- Trace2.span()
5261
+ Trace3.span()
5104
5262
  ], ServiceContext.prototype, "_initialize", null);
5105
5263
  ServiceContext = _ts_decorate6([
5106
5264
  safeInstanceof("dxos.client-services.ServiceContext"),
5107
- Trace2.resource()
5265
+ Trace3.resource()
5108
5266
  ], ServiceContext);
5109
5267
 
5110
5268
  // packages/sdk/client-services/src/packlets/services/service-registry.ts
@@ -5137,11 +5295,11 @@ import { getFirstStreamValue } from "@dxos/codec-protobuf";
5137
5295
  import { credentialTypeFilter } from "@dxos/credentials";
5138
5296
  import { invariant as invariant16 } from "@dxos/invariant";
5139
5297
  import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
5140
- import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/client/services";
5298
+ import { SpaceMember as SpaceMember7 } from "@dxos/protocols/proto/dxos/client/services";
5141
5299
  import { TRACE_PROCESSOR } from "@dxos/tracing";
5142
5300
 
5143
5301
  // packages/sdk/client-services/src/version.ts
5144
- var DXOS_VERSION = "0.5.3-main.3d65399";
5302
+ var DXOS_VERSION = "0.5.3-main.427f0a3";
5145
5303
 
5146
5304
  // packages/sdk/client-services/src/packlets/services/platform.ts
5147
5305
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -5249,13 +5407,14 @@ var getSpaceStats = async (space) => {
5249
5407
  id: credential.id
5250
5408
  })),
5251
5409
  members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
5410
+ role: member.role,
5252
5411
  identity: {
5253
5412
  identityKey: member.key,
5254
5413
  profile: {
5255
5414
  displayName: member.assertion.profile?.displayName
5256
5415
  }
5257
5416
  },
5258
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember6.PresenceState.ONLINE : SpaceMember6.PresenceState.OFFLINE
5417
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember7.PresenceState.ONLINE : SpaceMember7.PresenceState.OFFLINE
5259
5418
  })),
5260
5419
  pipeline: {
5261
5420
  // TODO(burdon): Pick properties from credentials if needed.
@@ -5404,7 +5563,7 @@ import { WebsocketSignalManager } from "@dxos/messaging";
5404
5563
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5405
5564
  import { trace as trace9 } from "@dxos/protocols";
5406
5565
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
5407
- import { TRACE_PROCESSOR as TRACE_PROCESSOR2, trace as Trace3 } from "@dxos/tracing";
5566
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR2, trace as Trace4 } from "@dxos/tracing";
5408
5567
  import { assignDeep as assignDeep2 } from "@dxos/util";
5409
5568
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
5410
5569
 
@@ -6288,21 +6447,21 @@ var ClientServicesHost = class {
6288
6447
  }
6289
6448
  };
6290
6449
  _ts_decorate8([
6291
- Trace3.info()
6450
+ Trace4.info()
6292
6451
  ], ClientServicesHost.prototype, "_opening", void 0);
6293
6452
  _ts_decorate8([
6294
- Trace3.info()
6453
+ Trace4.info()
6295
6454
  ], ClientServicesHost.prototype, "_open", void 0);
6296
6455
  _ts_decorate8([
6297
6456
  synchronized3,
6298
- Trace3.span()
6457
+ Trace4.span()
6299
6458
  ], ClientServicesHost.prototype, "open", null);
6300
6459
  _ts_decorate8([
6301
6460
  synchronized3,
6302
- Trace3.span()
6461
+ Trace4.span()
6303
6462
  ], ClientServicesHost.prototype, "close", null);
6304
6463
  ClientServicesHost = _ts_decorate8([
6305
- Trace3.resource()
6464
+ Trace4.resource()
6306
6465
  ], ClientServicesHost);
6307
6466
 
6308
6467
  // packages/sdk/client-services/src/packlets/services/util.ts
@@ -6371,6 +6530,7 @@ export {
6371
6530
  InvitationsManager,
6372
6531
  ClientRpcServer,
6373
6532
  DataSpace,
6533
+ findPropertiesObject,
6374
6534
  DataSpaceManager,
6375
6535
  SpacesServiceImpl,
6376
6536
  ServiceContext,
@@ -6386,4 +6546,4 @@ export {
6386
6546
  ClientServicesHost,
6387
6547
  ClientServicesProviderResource
6388
6548
  };
6389
- //# sourceMappingURL=chunk-KNPCT2EX.mjs.map
6549
+ //# sourceMappingURL=chunk-7DFCTMMT.mjs.map