@dxos/client-services 0.3.11-main.cf6cc01 → 0.3.11-main.d46c1ca

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 (40) hide show
  1. package/dist/lib/browser/{chunk-RCTGQMFJ.mjs → chunk-AJELNBEJ.mjs} +115 -75
  2. package/dist/lib/browser/chunk-AJELNBEJ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -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 +4 -11
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-H7IU7NBT.cjs → chunk-RU6S47BV.cjs} +172 -132
  9. package/dist/lib/node/chunk-RU6S47BV.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +37 -37
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +11 -18
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +3 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -0
  18. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +28 -3
  20. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  21. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -0
  23. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  24. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  25. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  26. package/dist/types/src/version.d.ts +1 -1
  27. package/package.json +35 -35
  28. package/src/packlets/identity/identity-service.test.ts +1 -1
  29. package/src/packlets/identity/identity-service.ts +6 -3
  30. package/src/packlets/invitations/device-invitation-protocol.test.ts +14 -0
  31. package/src/packlets/invitations/device-invitation-protocol.ts +14 -0
  32. package/src/packlets/invitations/invitation-protocol.ts +44 -6
  33. package/src/packlets/invitations/invitations-handler.ts +19 -17
  34. package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
  35. package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
  36. package/src/packlets/services/service-host.ts +27 -12
  37. package/src/packlets/testing/invitation-utils.ts +2 -10
  38. package/src/version.ts +1 -1
  39. package/dist/lib/browser/chunk-RCTGQMFJ.mjs.map +0 -7
  40. package/dist/lib/node/chunk-H7IU7NBT.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_H7IU7NBT_exports = {};
30
- __export(chunk_H7IU7NBT_exports, {
29
+ var chunk_RU6S47BV_exports = {};
30
+ __export(chunk_RU6S47BV_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -60,7 +60,7 @@ __export(chunk_H7IU7NBT_exports, {
60
60
  subscribeToSpaces: () => subscribeToSpaces,
61
61
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
62
  });
63
- module.exports = __toCommonJS(chunk_H7IU7NBT_exports);
63
+ module.exports = __toCommonJS(chunk_RU6S47BV_exports);
64
64
  var import_async = require("@dxos/async");
65
65
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
66
  var import_feed_store = require("@dxos/feed-store");
@@ -108,6 +108,7 @@ var import_credentials6 = require("@dxos/credentials");
108
108
  var import_debug2 = require("@dxos/debug");
109
109
  var import_invariant3 = require("@dxos/invariant");
110
110
  var import_invariant4 = require("@dxos/invariant");
111
+ var import_protocols3 = require("@dxos/protocols");
111
112
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
112
113
  var import_async7 = require("@dxos/async");
113
114
  var import_client_protocol2 = require("@dxos/client-protocol");
@@ -117,7 +118,7 @@ var import_invariant5 = require("@dxos/invariant");
117
118
  var import_keys5 = require("@dxos/keys");
118
119
  var import_log4 = require("@dxos/log");
119
120
  var import_network_manager = require("@dxos/network-manager");
120
- var import_protocols3 = require("@dxos/protocols");
121
+ var import_protocols4 = require("@dxos/protocols");
121
122
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
122
123
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
123
124
  var import_async8 = require("@dxos/async");
@@ -125,7 +126,7 @@ var import_context5 = require("@dxos/context");
125
126
  var import_invariant6 = require("@dxos/invariant");
126
127
  var import_keys6 = require("@dxos/keys");
127
128
  var import_log5 = require("@dxos/log");
128
- var import_protocols4 = require("@dxos/protocols");
129
+ var import_protocols5 = require("@dxos/protocols");
129
130
  var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
130
131
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
131
132
  var import_teleport = require("@dxos/teleport");
@@ -138,6 +139,7 @@ var import_credentials8 = require("@dxos/credentials");
138
139
  var import_feed_store3 = require("@dxos/feed-store");
139
140
  var import_invariant8 = require("@dxos/invariant");
140
141
  var import_log7 = require("@dxos/log");
142
+ var import_protocols6 = require("@dxos/protocols");
141
143
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
142
144
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
143
145
  var import_debug3 = require("@dxos/debug");
@@ -149,7 +151,7 @@ var import_document_model = require("@dxos/document-model");
149
151
  var import_echo_db = require("@dxos/echo-db");
150
152
  var import_invariant9 = require("@dxos/invariant");
151
153
  var import_log8 = require("@dxos/log");
152
- var import_protocols5 = require("@dxos/protocols");
154
+ var import_protocols7 = require("@dxos/protocols");
153
155
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
154
156
  var import_async10 = require("@dxos/async");
155
157
  var import_client_protocol3 = require("@dxos/client-protocol");
@@ -158,7 +160,7 @@ var import_debug4 = require("@dxos/debug");
158
160
  var import_echo_pipeline = require("@dxos/echo-pipeline");
159
161
  var import_keys7 = require("@dxos/keys");
160
162
  var import_log9 = require("@dxos/log");
161
- var import_protocols6 = require("@dxos/protocols");
163
+ var import_protocols8 = require("@dxos/protocols");
162
164
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
163
165
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
164
166
  var import_timeframe2 = require("@dxos/timeframe");
@@ -170,7 +172,7 @@ var import_context7 = require("@dxos/context");
170
172
  var import_invariant10 = require("@dxos/invariant");
171
173
  var import_keys8 = require("@dxos/keys");
172
174
  var import_log10 = require("@dxos/log");
173
- var import_protocols7 = require("@dxos/protocols");
175
+ var import_protocols9 = require("@dxos/protocols");
174
176
  var import_teleport2 = require("@dxos/teleport");
175
177
  var import_util5 = require("@dxos/util");
176
178
  var import_async12 = require("@dxos/async");
@@ -179,7 +181,7 @@ var import_credentials12 = require("@dxos/credentials");
179
181
  var import_invariant11 = require("@dxos/invariant");
180
182
  var import_keys9 = require("@dxos/keys");
181
183
  var import_log11 = require("@dxos/log");
182
- var import_protocols8 = require("@dxos/protocols");
184
+ var import_protocols10 = require("@dxos/protocols");
183
185
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
184
186
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
185
187
  var import_util6 = require("@dxos/util");
@@ -192,7 +194,7 @@ var import_codec_protobuf11 = require("@dxos/codec-protobuf");
192
194
  var import_debug6 = require("@dxos/debug");
193
195
  var import_invariant12 = require("@dxos/invariant");
194
196
  var import_log12 = require("@dxos/log");
195
- var import_protocols9 = require("@dxos/protocols");
197
+ var import_protocols11 = require("@dxos/protocols");
196
198
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
197
199
  var import_async14 = require("@dxos/async");
198
200
  var import_context9 = require("@dxos/context");
@@ -204,7 +206,7 @@ var import_invariant13 = require("@dxos/invariant");
204
206
  var import_keyring = require("@dxos/keyring");
205
207
  var import_keys10 = require("@dxos/keys");
206
208
  var import_log13 = require("@dxos/log");
207
- var import_protocols10 = require("@dxos/protocols");
209
+ var import_protocols12 = require("@dxos/protocols");
208
210
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
209
211
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
210
212
  var import_tracing5 = require("@dxos/tracing");
@@ -213,7 +215,7 @@ var import_invariant14 = require("@dxos/invariant");
213
215
  var import_lock_file = require("@dxos/lock-file");
214
216
  var import_log14 = require("@dxos/log");
215
217
  var import_client_protocol4 = require("@dxos/client-protocol");
216
- var import_protocols11 = require("@dxos/protocols");
218
+ var import_protocols13 = require("@dxos/protocols");
217
219
  var import_config = require("@dxos/protocols/proto/dxos/config");
218
220
  var import_random_access_storage = require("@dxos/random-access-storage");
219
221
  var import_util8 = require("@dxos/util");
@@ -229,7 +231,7 @@ var import_log15 = require("@dxos/log");
229
231
  var import_messaging = require("@dxos/messaging");
230
232
  var import_model_factory = require("@dxos/model-factory");
231
233
  var import_network_manager2 = require("@dxos/network-manager");
232
- var import_protocols12 = require("@dxos/protocols");
234
+ var import_protocols14 = require("@dxos/protocols");
233
235
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
234
236
  var import_text_model = require("@dxos/text-model");
235
237
  var import_tracing6 = require("@dxos/tracing");
@@ -675,7 +677,7 @@ function _ts_decorate(decorators, target, key, desc) {
675
677
  return c > 3 && r && Object.defineProperty(target, key, r), r;
676
678
  }
677
679
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
678
- var Identity = class Identity2 {
680
+ var Identity = class {
679
681
  constructor({ space, signer, identityKey, deviceKey }) {
680
682
  this.stateUpdate = new import_async5.Event();
681
683
  this.space = space;
@@ -843,7 +845,7 @@ function _ts_decorate2(decorators, target, key, desc) {
843
845
  return c > 3 && r && Object.defineProperty(target, key, r), r;
844
846
  }
845
847
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
846
- var IdentityManager = class IdentityManager2 {
848
+ var IdentityManager = class {
847
849
  // TODO(burdon): IdentityManagerParams.
848
850
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
849
851
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -1197,6 +1199,7 @@ IdentityManager = _ts_decorate2([
1197
1199
  import_tracing2.trace.resource()
1198
1200
  ], IdentityManager);
1199
1201
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1202
+ var CREATE_PROFILE_WITH_AUTOMERGE_DEFAULT = true;
1200
1203
  var IdentityServiceImpl = class {
1201
1204
  constructor(_createIdentity, _identityManager, _keyring, _onProfileUpdate) {
1202
1205
  this._createIdentity = _createIdentity;
@@ -1205,7 +1208,7 @@ var IdentityServiceImpl = class {
1205
1208
  this._onProfileUpdate = _onProfileUpdate;
1206
1209
  }
1207
1210
  async createIdentity(request) {
1208
- await this._createIdentity(request);
1211
+ await this._createIdentity(request.profile ?? {}, request.useAutomerge ?? CREATE_PROFILE_WITH_AUTOMERGE_DEFAULT);
1209
1212
  return this._getIdentity();
1210
1213
  }
1211
1214
  async recoverIdentity(request) {
@@ -1233,7 +1236,7 @@ var IdentityServiceImpl = class {
1233
1236
  async updateProfile(profile) {
1234
1237
  (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1235
1238
  F: __dxlog_file4,
1236
- L: 60,
1239
+ L: 63,
1237
1240
  S: this,
1238
1241
  A: [
1239
1242
  "this._identityManager.identity",
@@ -1247,7 +1250,7 @@ var IdentityServiceImpl = class {
1247
1250
  async signPresentation({ presentation, nonce }) {
1248
1251
  (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1249
1252
  F: __dxlog_file4,
1250
- L: 67,
1253
+ L: 70,
1251
1254
  S: this,
1252
1255
  A: [
1253
1256
  "this._identityManager.identity",
@@ -1281,7 +1284,7 @@ var DeviceInvitationProtocol = class {
1281
1284
  async admit(request) {
1282
1285
  (0, import_invariant4.invariant)(request.device, void 0, {
1283
1286
  F: __dxlog_file5,
1284
- L: 35,
1287
+ L: 36,
1285
1288
  S: this,
1286
1289
  A: [
1287
1290
  "request.device",
@@ -1299,6 +1302,15 @@ var DeviceInvitationProtocol = class {
1299
1302
  }
1300
1303
  };
1301
1304
  }
1305
+ checkInvitation(invitation) {
1306
+ try {
1307
+ const identity = this._getIdentity();
1308
+ if (identity) {
1309
+ return new import_protocols3.AlreadyJoinedError("Currently only one identity per client is supported.");
1310
+ }
1311
+ } catch {
1312
+ }
1313
+ }
1302
1314
  createIntroduction() {
1303
1315
  return {};
1304
1316
  }
@@ -1317,7 +1329,7 @@ var DeviceInvitationProtocol = class {
1317
1329
  async accept(response, request) {
1318
1330
  (0, import_invariant4.invariant)(response.device, void 0, {
1319
1331
  F: __dxlog_file5,
1320
- L: 68,
1332
+ L: 80,
1321
1333
  S: this,
1322
1334
  A: [
1323
1335
  "response.device",
@@ -1327,7 +1339,7 @@ var DeviceInvitationProtocol = class {
1327
1339
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1328
1340
  (0, import_invariant4.invariant)(request.device, void 0, {
1329
1341
  F: __dxlog_file5,
1330
- L: 71,
1342
+ L: 83,
1331
1343
  S: this,
1332
1344
  A: [
1333
1345
  "request.device",
@@ -1356,10 +1368,10 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1356
1368
  constructor(_callbacks) {
1357
1369
  super({
1358
1370
  requested: {
1359
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1371
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1360
1372
  },
1361
1373
  exposed: {
1362
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1374
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1363
1375
  }
1364
1376
  });
1365
1377
  this._callbacks = _callbacks;
@@ -1392,7 +1404,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1392
1404
  introduce: async (request) => {
1393
1405
  const { profile, invitationId } = request;
1394
1406
  const traceId = import_keys6.PublicKey.random().toHex();
1395
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.begin({
1407
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.begin({
1396
1408
  id: traceId
1397
1409
  }), {
1398
1410
  F: __dxlog_file6,
@@ -1429,7 +1441,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1429
1441
  ...this.invitation,
1430
1442
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1431
1443
  });
1432
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.end({
1444
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1433
1445
  id: traceId
1434
1446
  }), {
1435
1447
  F: __dxlog_file6,
@@ -1443,7 +1455,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1443
1455
  },
1444
1456
  authenticate: async ({ authCode: code }) => {
1445
1457
  const traceId = import_keys6.PublicKey.random().toHex();
1446
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.begin({
1458
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1447
1459
  id: traceId
1448
1460
  }), {
1449
1461
  F: __dxlog_file6,
@@ -1506,7 +1518,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1506
1518
  break;
1507
1519
  }
1508
1520
  }
1509
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.end({
1521
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.end({
1510
1522
  id: traceId,
1511
1523
  data: {
1512
1524
  status
@@ -1523,7 +1535,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1523
1535
  },
1524
1536
  admit: async (request) => {
1525
1537
  const traceId = import_keys6.PublicKey.random().toHex();
1526
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.begin({
1538
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.begin({
1527
1539
  id: traceId
1528
1540
  }), {
1529
1541
  F: __dxlog_file6,
@@ -1545,7 +1557,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1545
1557
  throw new Error("Not authenticated");
1546
1558
  }
1547
1559
  const response = await this._callbacks.admit(request);
1548
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.end({
1560
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.end({
1549
1561
  id: traceId
1550
1562
  }), {
1551
1563
  F: __dxlog_file6,
@@ -1572,7 +1584,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1572
1584
  timeout: OPTIONS_TIMEOUT
1573
1585
  }));
1574
1586
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.GUEST) {
1575
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1587
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1576
1588
  expected: import_invitations2.Options.Role.GUEST,
1577
1589
  remoteOptions: this._remoteOptions
1578
1590
  });
@@ -1590,10 +1602,10 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1590
1602
  constructor(_callbacks) {
1591
1603
  super({
1592
1604
  requested: {
1593
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1605
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1594
1606
  },
1595
1607
  exposed: {
1596
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1608
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1597
1609
  }
1598
1610
  });
1599
1611
  this._callbacks = _callbacks;
@@ -1650,7 +1662,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1650
1662
  C: (f, a) => f(...a)
1651
1663
  });
1652
1664
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.HOST) {
1653
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1665
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1654
1666
  expected: import_invitations2.Options.Role.HOST,
1655
1667
  remoteOptions: this._remoteOptions
1656
1668
  });
@@ -1763,7 +1775,7 @@ var InvitationsHandler = class {
1763
1775
  (0, import_async7.scheduleTask)(ctx, async () => {
1764
1776
  const traceId = import_keys5.PublicKey.random().toHex();
1765
1777
  try {
1766
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.begin({
1778
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1767
1779
  id: traceId
1768
1780
  }), {
1769
1781
  F: __dxlog_file7,
@@ -1799,7 +1811,7 @@ var InvitationsHandler = class {
1799
1811
  ...invitation,
1800
1812
  state: import_services2.Invitation.State.SUCCESS
1801
1813
  });
1802
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.end({
1814
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1803
1815
  id: traceId
1804
1816
  }), {
1805
1817
  F: __dxlog_file7,
@@ -1830,7 +1842,7 @@ var InvitationsHandler = class {
1830
1842
  });
1831
1843
  stream.error(err);
1832
1844
  }
1833
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.error({
1845
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1834
1846
  id: traceId,
1835
1847
  error: err
1836
1848
  }), {
@@ -1848,7 +1860,7 @@ var InvitationsHandler = class {
1848
1860
  });
1849
1861
  },
1850
1862
  onError: (err) => {
1851
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
1863
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
1852
1864
  return;
1853
1865
  }
1854
1866
  if (err instanceof import_async7.TimeoutError) {
@@ -1996,7 +2008,7 @@ var InvitationsHandler = class {
1996
2008
  (0, import_async7.scheduleTask)(ctx, async () => {
1997
2009
  const traceId = import_keys5.PublicKey.random().toHex();
1998
2010
  try {
1999
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.begin({
2011
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
2000
2012
  id: traceId
2001
2013
  }), {
2002
2014
  F: __dxlog_file7,
@@ -2083,16 +2095,12 @@ var InvitationsHandler = class {
2083
2095
  }
2084
2096
  }
2085
2097
  }
2086
- } else {
2087
- setState({
2088
- state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
2089
- });
2090
2098
  }
2091
2099
  (0, import_log4.log)("request admission", {
2092
2100
  ...protocol.toJSON()
2093
2101
  }, {
2094
2102
  F: __dxlog_file7,
2095
- L: 312,
2103
+ L: 309,
2096
2104
  S: this,
2097
2105
  C: (f, a) => f(...a)
2098
2106
  });
@@ -2104,7 +2112,7 @@ var InvitationsHandler = class {
2104
2112
  ...protocol.toJSON()
2105
2113
  }, {
2106
2114
  F: __dxlog_file7,
2107
- L: 323,
2115
+ L: 320,
2108
2116
  S: this,
2109
2117
  C: (f, a) => f(...a)
2110
2118
  });
@@ -2113,11 +2121,11 @@ var InvitationsHandler = class {
2113
2121
  target: invitation.target,
2114
2122
  state: import_services2.Invitation.State.SUCCESS
2115
2123
  });
2116
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.end({
2124
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
2117
2125
  id: traceId
2118
2126
  }), {
2119
2127
  F: __dxlog_file7,
2120
- L: 325,
2128
+ L: 322,
2121
2129
  S: this,
2122
2130
  C: (f, a) => f(...a)
2123
2131
  });
@@ -2127,7 +2135,7 @@ var InvitationsHandler = class {
2127
2135
  ...protocol.toJSON()
2128
2136
  }, {
2129
2137
  F: __dxlog_file7,
2130
- L: 328,
2138
+ L: 325,
2131
2139
  S: this,
2132
2140
  C: (f, a) => f(...a)
2133
2141
  });
@@ -2137,18 +2145,18 @@ var InvitationsHandler = class {
2137
2145
  } else {
2138
2146
  (0, import_log4.log)("auth failed", err, {
2139
2147
  F: __dxlog_file7,
2140
- L: 331,
2148
+ L: 328,
2141
2149
  S: this,
2142
2150
  C: (f, a) => f(...a)
2143
2151
  });
2144
2152
  stream.error(err);
2145
2153
  }
2146
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.error({
2154
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
2147
2155
  id: traceId,
2148
2156
  error: err
2149
2157
  }), {
2150
2158
  F: __dxlog_file7,
2151
- L: 334,
2159
+ L: 331,
2152
2160
  S: this,
2153
2161
  C: (f, a) => f(...a)
2154
2162
  });
@@ -2158,7 +2166,7 @@ var InvitationsHandler = class {
2158
2166
  });
2159
2167
  },
2160
2168
  onError: (err) => {
2161
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
2169
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
2162
2170
  return;
2163
2171
  }
2164
2172
  if (err instanceof import_async7.TimeoutError) {
@@ -2166,7 +2174,7 @@ var InvitationsHandler = class {
2166
2174
  ...protocol.toJSON()
2167
2175
  }, {
2168
2176
  F: __dxlog_file7,
2169
- L: 345,
2177
+ L: 342,
2170
2178
  S: this,
2171
2179
  C: (f, a) => f(...a)
2172
2180
  });
@@ -2176,7 +2184,7 @@ var InvitationsHandler = class {
2176
2184
  } else {
2177
2185
  (0, import_log4.log)("auth failed", err, {
2178
2186
  F: __dxlog_file7,
2179
- L: 348,
2187
+ L: 345,
2180
2188
  S: this,
2181
2189
  C: (f, a) => f(...a)
2182
2190
  });
@@ -2187,29 +2195,34 @@ var InvitationsHandler = class {
2187
2195
  return extension;
2188
2196
  };
2189
2197
  (0, import_async7.scheduleTask)(ctx, async () => {
2190
- (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2191
- F: __dxlog_file7,
2192
- L: 358,
2193
- S: this,
2194
- A: [
2195
- "invitation.swarmKey",
2196
- ""
2197
- ]
2198
- });
2199
- const topic = invitation.swarmKey;
2200
- const swarmConnection = await this._networkManager.joinSwarm({
2201
- topic,
2202
- peerId: import_keys5.PublicKey.random(),
2203
- protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2204
- teleport.addExtension("dxos.halo.invitations", createExtension());
2205
- }),
2206
- topology: new import_network_manager.StarTopology(topic),
2207
- label: "invitation guest"
2208
- });
2209
- ctx.onDispose(() => swarmConnection.close());
2210
- setState({
2211
- state: import_services2.Invitation.State.CONNECTING
2212
- });
2198
+ const error = protocol.checkInvitation(invitation);
2199
+ if (error) {
2200
+ stream.error(error);
2201
+ } else {
2202
+ (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2203
+ F: __dxlog_file7,
2204
+ L: 359,
2205
+ S: this,
2206
+ A: [
2207
+ "invitation.swarmKey",
2208
+ ""
2209
+ ]
2210
+ });
2211
+ const topic = invitation.swarmKey;
2212
+ const swarmConnection = await this._networkManager.joinSwarm({
2213
+ topic,
2214
+ peerId: import_keys5.PublicKey.random(),
2215
+ protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2216
+ teleport.addExtension("dxos.halo.invitations", createExtension());
2217
+ }),
2218
+ topology: new import_network_manager.StarTopology(topic),
2219
+ label: "invitation guest"
2220
+ });
2221
+ ctx.onDispose(() => swarmConnection.close());
2222
+ setState({
2223
+ state: import_services2.Invitation.State.CONNECTING
2224
+ });
2225
+ }
2213
2226
  });
2214
2227
  const observable = new import_client_protocol2.AuthenticatingInvitation({
2215
2228
  initialInvitation: invitation,
@@ -2425,7 +2438,7 @@ var SpaceInvitationProtocol = class {
2425
2438
  async admit(request, guestProfile) {
2426
2439
  (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2427
2440
  F: __dxlog_file9,
2428
- L: 46,
2441
+ L: 47,
2429
2442
  S: this,
2430
2443
  A: [
2431
2444
  "this._spaceKey",
@@ -2435,7 +2448,7 @@ var SpaceInvitationProtocol = class {
2435
2448
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2436
2449
  (0, import_invariant8.invariant)(space, void 0, {
2437
2450
  F: __dxlog_file9,
2438
- L: 48,
2451
+ L: 49,
2439
2452
  S: this,
2440
2453
  A: [
2441
2454
  "space",
@@ -2444,7 +2457,7 @@ var SpaceInvitationProtocol = class {
2444
2457
  });
2445
2458
  (0, import_invariant8.invariant)(request.space, void 0, {
2446
2459
  F: __dxlog_file9,
2447
- L: 50,
2460
+ L: 51,
2448
2461
  S: this,
2449
2462
  A: [
2450
2463
  "request.space",
@@ -2457,14 +2470,14 @@ var SpaceInvitationProtocol = class {
2457
2470
  guest: deviceKey
2458
2471
  }, {
2459
2472
  F: __dxlog_file9,
2460
- L: 53,
2473
+ L: 54,
2461
2474
  S: this,
2462
2475
  C: (f, a) => f(...a)
2463
2476
  });
2464
2477
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2465
2478
  (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2466
2479
  F: __dxlog_file9,
2467
- L: 64,
2480
+ L: 65,
2468
2481
  S: this,
2469
2482
  A: [
2470
2483
  "credentials[0].credential",
@@ -2474,7 +2487,7 @@ var SpaceInvitationProtocol = class {
2474
2487
  const spaceMemberCredential = credentials[0].credential.credential;
2475
2488
  (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2476
2489
  F: __dxlog_file9,
2477
- L: 66,
2490
+ L: 67,
2478
2491
  S: this,
2479
2492
  A: [
2480
2493
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2490,6 +2503,11 @@ var SpaceInvitationProtocol = class {
2490
2503
  }
2491
2504
  };
2492
2505
  }
2506
+ checkInvitation(invitation) {
2507
+ if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2508
+ return new import_protocols6.AlreadyJoinedError("Already joined space.");
2509
+ }
2510
+ }
2493
2511
  createIntroduction() {
2494
2512
  return {
2495
2513
  profile: this._signingContext.getProfile()
@@ -2510,7 +2528,7 @@ var SpaceInvitationProtocol = class {
2510
2528
  async accept(response) {
2511
2529
  (0, import_invariant8.invariant)(response.space, void 0, {
2512
2530
  F: __dxlog_file9,
2513
- L: 101,
2531
+ L: 108,
2514
2532
  S: this,
2515
2533
  A: [
2516
2534
  "response.space",
@@ -2521,7 +2539,7 @@ var SpaceInvitationProtocol = class {
2521
2539
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2522
2540
  (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2523
2541
  F: __dxlog_file9,
2524
- L: 104,
2542
+ L: 111,
2525
2543
  S: this,
2526
2544
  A: [
2527
2545
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2530,13 +2548,16 @@ var SpaceInvitationProtocol = class {
2530
2548
  });
2531
2549
  (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2532
2550
  F: __dxlog_file9,
2533
- L: 105,
2551
+ L: 112,
2534
2552
  S: this,
2535
2553
  A: [
2536
2554
  "credential.subject.id.equals(this._signingContext.identityKey)",
2537
2555
  ""
2538
2556
  ]
2539
2557
  });
2558
+ if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2559
+ throw new import_protocols6.AlreadyJoinedError("Already joined space.");
2560
+ }
2540
2561
  await this._spaceManager.acceptSpace({
2541
2562
  spaceKey: assertion.spaceKey,
2542
2563
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2559,7 +2580,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2559
2580
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2560
2581
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2561
2582
  }
2562
- var ClientRpcServer = class ClientRpcServer2 {
2583
+ var ClientRpcServer = class {
2563
2584
  constructor(params) {
2564
2585
  this._handlerCache = /* @__PURE__ */ new Map();
2565
2586
  this._callMetrics = new import_tracing3.MapCounter();
@@ -2650,7 +2671,7 @@ var getPlatform = () => {
2650
2671
  };
2651
2672
  }
2652
2673
  };
2653
- var DXOS_VERSION = "0.3.11-main.cf6cc01";
2674
+ var DXOS_VERSION = "0.3.11-main.d46c1ca";
2654
2675
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2655
2676
  var DEFAULT_TIMEOUT = 1e3;
2656
2677
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2660,7 +2681,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2660
2681
  client: {
2661
2682
  version: DXOS_VERSION,
2662
2683
  storage: {
2663
- version: import_protocols5.STORAGE_VERSION
2684
+ version: import_protocols7.STORAGE_VERSION
2664
2685
  }
2665
2686
  }
2666
2687
  };
@@ -3019,10 +3040,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3019
3040
  constructor(_params) {
3020
3041
  super({
3021
3042
  requested: {
3022
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3043
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3023
3044
  },
3024
3045
  exposed: {
3025
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3046
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3026
3047
  }
3027
3048
  });
3028
3049
  this._params = _params;
@@ -3057,7 +3078,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3057
3078
  }
3058
3079
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3059
3080
  var ENABLE_FEED_PURGE = false;
3060
- var DataSpace = class DataSpace2 {
3081
+ var DataSpace = class {
3061
3082
  constructor(params) {
3062
3083
  this._ctx = new import_context6.Context();
3063
3084
  this._notarizationPlugin = new NotarizationPlugin();
@@ -3182,7 +3203,7 @@ var DataSpace = class DataSpace2 {
3182
3203
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3183
3204
  await this.initializeDataPipeline();
3184
3205
  } catch (err) {
3185
- if (err instanceof import_protocols6.CancelledError) {
3206
+ if (err instanceof import_protocols8.CancelledError) {
3186
3207
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3187
3208
  F: __dxlog_file12,
3188
3209
  L: 236,
@@ -3215,7 +3236,7 @@ var DataSpace = class DataSpace2 {
3215
3236
  }
3216
3237
  async initializeDataPipeline() {
3217
3238
  if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3218
- throw new import_protocols6.SystemError("Invalid operation");
3239
+ throw new import_protocols8.SystemError("Invalid operation");
3219
3240
  }
3220
3241
  this._state = import_services7.SpaceState.INITIALIZING;
3221
3242
  (0, import_log9.log)("new state", {
@@ -3522,7 +3543,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3522
3543
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3523
3544
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3524
3545
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3525
- var DataSpaceManager = class DataSpaceManager2 {
3546
+ var DataSpaceManager = class {
3526
3547
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore, _automergeHost) {
3527
3548
  this._spaceManager = _spaceManager;
3528
3549
  this._metadataStore = _metadataStore;
@@ -3548,7 +3569,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3548
3569
  S: this,
3549
3570
  C: (f, a) => f(...a)
3550
3571
  });
3551
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.begin({
3572
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3552
3573
  id: this._instanceId
3553
3574
  }), {
3554
3575
  F: __dxlog_file13,
@@ -3594,7 +3615,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3594
3615
  space.initializeDataPipelineAsync();
3595
3616
  }
3596
3617
  }
3597
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.end({
3618
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
3598
3619
  id: this._instanceId
3599
3620
  }), {
3600
3621
  F: __dxlog_file13,
@@ -3864,7 +3885,7 @@ var SpacesServiceImpl = class {
3864
3885
  }
3865
3886
  async updateSpace({ spaceKey, state }) {
3866
3887
  const dataSpaceManager = await this._getDataSpaceManager();
3867
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3888
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3868
3889
  if (state) {
3869
3890
  switch (state) {
3870
3891
  case import_services9.SpaceState.ACTIVE:
@@ -3874,7 +3895,7 @@ var SpacesServiceImpl = class {
3874
3895
  await space.deactivate();
3875
3896
  break;
3876
3897
  default:
3877
- throw new import_protocols9.ApiError("Invalid space state");
3898
+ throw new import_protocols11.ApiError("Invalid space state");
3878
3899
  }
3879
3900
  }
3880
3901
  }
@@ -3929,14 +3950,14 @@ var SpacesServiceImpl = class {
3929
3950
  }
3930
3951
  async postMessage({ spaceKey, channel, message }) {
3931
3952
  const dataSpaceManager = await this._getDataSpaceManager();
3932
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3953
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3933
3954
  await space.postMessage(getChannelId(channel), message);
3934
3955
  }
3935
3956
  subscribeMessages({ spaceKey, channel }) {
3936
3957
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3937
3958
  (0, import_async13.scheduleTask)(ctx, async () => {
3938
3959
  const dataSpaceManager = await this._getDataSpaceManager();
3939
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3960
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3940
3961
  const handle = space.listen(getChannelId(channel), (message) => {
3941
3962
  next(message);
3942
3963
  });
@@ -3946,7 +3967,7 @@ var SpacesServiceImpl = class {
3946
3967
  }
3947
3968
  queryCredentials({ spaceKey, noTail }) {
3948
3969
  return new import_codec_protobuf11.Stream(({ ctx, next, close }) => {
3949
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3970
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3950
3971
  const processor = {
3951
3972
  processCredential: async (credential) => {
3952
3973
  next(credential);
@@ -3962,7 +3983,7 @@ var SpacesServiceImpl = class {
3962
3983
  });
3963
3984
  }
3964
3985
  async writeCredentials({ spaceKey, credentials }) {
3965
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3986
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3966
3987
  for (const credential of credentials ?? []) {
3967
3988
  if (credential.proof) {
3968
3989
  await space.controlPipeline.writer.write({
@@ -4013,14 +4034,14 @@ var SpacesServiceImpl = class {
4013
4034
  }
4014
4035
  async createEpoch({ spaceKey }) {
4015
4036
  const dataSpaceManager = await this._getDataSpaceManager();
4016
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4037
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4017
4038
  await space.createEpoch();
4018
4039
  }
4019
4040
  _serializeSpace(space) {
4020
4041
  return {
4021
4042
  spaceKey: space.key,
4022
4043
  state: space.state,
4023
- error: space.error ? (0, import_protocols9.encodeError)(space.error) : void 0,
4044
+ error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4024
4045
  pipeline: {
4025
4046
  currentEpoch: space.dataPipeline.currentEpoch,
4026
4047
  appliedEpoch: space.dataPipeline.appliedEpoch,
@@ -4069,7 +4090,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4069
4090
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4070
4091
  }
4071
4092
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4072
- var ServiceContext = class ServiceContext2 {
4093
+ var ServiceContext = class {
4073
4094
  constructor(storage, networkManager, signalManager, modelFactory) {
4074
4095
  this.storage = storage;
4075
4096
  this.networkManager = networkManager;
@@ -4114,7 +4135,7 @@ var ServiceContext = class ServiceContext2 {
4114
4135
  S: this,
4115
4136
  C: (f, a) => f(...a)
4116
4137
  });
4117
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.begin({
4138
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4118
4139
  id: this._instanceId
4119
4140
  }), {
4120
4141
  F: __dxlog_file15,
@@ -4130,7 +4151,7 @@ var ServiceContext = class ServiceContext2 {
4130
4151
  if (this.identityManager.identity) {
4131
4152
  await this._initialize(ctx);
4132
4153
  }
4133
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.end({
4154
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4134
4155
  id: this._instanceId
4135
4156
  }), {
4136
4157
  F: __dxlog_file15,
@@ -4204,8 +4225,8 @@ var ServiceContext = class ServiceContext2 {
4204
4225
  }
4205
4226
  async _checkStorageVersion() {
4206
4227
  await this.metadataStore.load();
4207
- if (this.metadataStore.version !== import_protocols10.STORAGE_VERSION) {
4208
- throw new import_protocols10.InvalidStorageVersionError(import_protocols10.STORAGE_VERSION, this.metadataStore.version);
4228
+ if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4229
+ throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4209
4230
  }
4210
4231
  }
4211
4232
  // Called when identity is created.
@@ -4392,16 +4413,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4392
4413
  var createStorageObjects = (config) => {
4393
4414
  const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4394
4415
  if (persistent && dataStore === StorageDriver.RAM) {
4395
- throw new import_protocols11.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4416
+ throw new import_protocols13.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4396
4417
  }
4397
4418
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4398
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4419
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4399
4420
  }
4400
4421
  if (persistent && keyStore === StorageDriver.RAM) {
4401
- throw new import_protocols11.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4422
+ throw new import_protocols13.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4402
4423
  }
4403
4424
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4404
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4425
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4405
4426
  }
4406
4427
  return {
4407
4428
  storage: (0, import_random_access_storage.createStorage)({
@@ -4683,7 +4704,7 @@ var createGenesisMutationFromTypedObject = (obj) => {
4683
4704
  }
4684
4705
  };
4685
4706
  };
4686
- var ClientServicesHost = class ClientServicesHost2 {
4707
+ var ClientServicesHost = class {
4687
4708
  constructor({
4688
4709
  config,
4689
4710
  modelFactory = createDefaultModelFactory(),
@@ -4827,7 +4848,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4827
4848
  return;
4828
4849
  }
4829
4850
  const traceId = import_keys11.PublicKey.random().toHex();
4830
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.begin({
4851
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
4831
4852
  id: traceId
4832
4853
  }), {
4833
4854
  F: __dxlog_file17,
@@ -4885,7 +4906,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4885
4906
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4886
4907
  this._serviceRegistry.setServices({
4887
4908
  SystemService: this._systemService,
4888
- IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
4909
+ IdentityService: new IdentityServiceImpl((params, useAutomerge) => this._createIdentity(params, useAutomerge), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
4889
4910
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4890
4911
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4891
4912
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4926,7 +4947,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4926
4947
  S: this,
4927
4948
  C: (f, a) => f(...a)
4928
4949
  });
4929
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.end({
4950
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
4930
4951
  id: traceId
4931
4952
  }), {
4932
4953
  F: __dxlog_file17,
@@ -4967,7 +4988,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4967
4988
  }
4968
4989
  async reset() {
4969
4990
  const traceId = import_keys11.PublicKey.random().toHex();
4970
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.begin({
4991
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
4971
4992
  id: traceId
4972
4993
  }), {
4973
4994
  F: __dxlog_file17,
@@ -4989,7 +5010,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4989
5010
  S: this,
4990
5011
  C: (f, a) => f(...a)
4991
5012
  });
4992
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.end({
5013
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
4993
5014
  id: traceId
4994
5015
  }), {
4995
5016
  F: __dxlog_file17,
@@ -4999,25 +5020,44 @@ var ClientServicesHost = class ClientServicesHost2 {
4999
5020
  });
5000
5021
  await this._callbacks?.onReset?.();
5001
5022
  }
5002
- async _createIdentity(params) {
5023
+ async _createIdentity(params, useAutomerge) {
5003
5024
  const identity = await this._serviceContext.createIdentity(params);
5004
5025
  await this._serviceContext.initialized.wait();
5005
5026
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5006
5027
  const obj = new import_client_protocol5.Properties(void 0, {
5007
- automerge: false
5028
+ automerge: useAutomerge
5008
5029
  });
5009
5030
  obj[import_client_protocol5.defaultKey] = identity.identityKey.toHex();
5010
- await this._serviceRegistry.services.DataService.write({
5011
- spaceKey: space.key,
5012
- batch: {
5013
- objects: [
5014
- createGenesisMutationFromTypedObject(obj)
5031
+ if (!useAutomerge) {
5032
+ await this._serviceRegistry.services.DataService.write({
5033
+ spaceKey: space.key,
5034
+ batch: {
5035
+ objects: [
5036
+ createGenesisMutationFromTypedObject(obj)
5037
+ ]
5038
+ }
5039
+ });
5040
+ await this._serviceRegistry.services.DataService.flush({
5041
+ spaceKey: space.key
5042
+ });
5043
+ } else {
5044
+ const automergeIndex = space.automergeSpaceState.rootUrl;
5045
+ (0, import_invariant15.invariant)(automergeIndex, void 0, {
5046
+ F: __dxlog_file17,
5047
+ L: 375,
5048
+ S: this,
5049
+ A: [
5050
+ "automergeIndex",
5051
+ ""
5015
5052
  ]
5016
- }
5017
- });
5018
- await this._serviceRegistry.services.DataService.flush({
5019
- spaceKey: space.key
5020
- });
5053
+ });
5054
+ const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5055
+ await document.whenReady();
5056
+ document.change((doc) => {
5057
+ doc.objects ??= {};
5058
+ doc.objects[obj[import_echo_schema.base]._id] = (0, import_echo_schema.getRawDoc)(obj).handle.docSync();
5059
+ });
5060
+ }
5021
5061
  return identity;
5022
5062
  }
5023
5063
  };
@@ -5072,4 +5112,4 @@ ClientServicesHost = _ts_decorate8([
5072
5112
  subscribeToSpaces,
5073
5113
  subscribeToSwarmInfo
5074
5114
  });
5075
- //# sourceMappingURL=chunk-H7IU7NBT.cjs.map
5115
+ //# sourceMappingURL=chunk-RU6S47BV.cjs.map