@dxos/client-services 0.3.11-main.c8e9429 → 0.3.11-main.c95bc86

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 (45) hide show
  1. package/dist/lib/browser/{chunk-OZ4IMR73.mjs → chunk-4ZZIUZXZ.mjs} +153 -77
  2. package/dist/lib/browser/chunk-4ZZIUZXZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +4 -11
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-46ZYQFO5.cjs → chunk-KA7FPK35.cjs} +240 -164
  8. package/dist/lib/node/chunk-KA7FPK35.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +37 -37
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +11 -18
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -0
  14. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +28 -3
  16. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -0
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/diagnostics.d.ts +4 -0
  21. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  23. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/data-space.d.ts +1 -0
  26. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  27. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  28. package/dist/types/src/version.d.ts +1 -1
  29. package/package.json +35 -35
  30. package/src/packlets/identity/identity-manager.ts +1 -1
  31. package/src/packlets/invitations/device-invitation-protocol.test.ts +14 -0
  32. package/src/packlets/invitations/device-invitation-protocol.ts +14 -0
  33. package/src/packlets/invitations/invitation-protocol.ts +44 -6
  34. package/src/packlets/invitations/invitations-handler.ts +19 -17
  35. package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
  36. package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
  37. package/src/packlets/services/diagnostics.ts +18 -0
  38. package/src/packlets/spaces/automerge-space-state.ts +4 -0
  39. package/src/packlets/spaces/data-space-manager.ts +5 -1
  40. package/src/packlets/spaces/data-space.ts +21 -1
  41. package/src/packlets/spaces/spaces-service.ts +1 -1
  42. package/src/packlets/testing/invitation-utils.ts +2 -10
  43. package/src/version.ts +1 -1
  44. package/dist/lib/browser/chunk-OZ4IMR73.mjs.map +0 -7
  45. package/dist/lib/node/chunk-46ZYQFO5.cjs.map +0 -7
@@ -996,7 +996,7 @@ var IdentityManager = class {
996
996
  genesisFeedKey: spaceRecord.genesisFeedKey
997
997
  },
998
998
  swarmIdentity,
999
- onNetworkConnection: () => {
999
+ onAuthorizedConnection: () => {
1000
1000
  },
1001
1001
  onAuthFailure: () => {
1002
1002
  log3.warn("auth failure", void 0, {
@@ -1095,6 +1095,7 @@ var IdentityServiceImpl = class {
1095
1095
 
1096
1096
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
1097
1097
  import { invariant as invariant4 } from "@dxos/invariant";
1098
+ import { AlreadyJoinedError } from "@dxos/protocols";
1098
1099
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
1099
1100
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1100
1101
  var DeviceInvitationProtocol = class {
@@ -1114,7 +1115,7 @@ var DeviceInvitationProtocol = class {
1114
1115
  async admit(request) {
1115
1116
  invariant4(request.device, void 0, {
1116
1117
  F: __dxlog_file5,
1117
- L: 35,
1118
+ L: 36,
1118
1119
  S: this,
1119
1120
  A: [
1120
1121
  "request.device",
@@ -1132,6 +1133,15 @@ var DeviceInvitationProtocol = class {
1132
1133
  }
1133
1134
  };
1134
1135
  }
1136
+ checkInvitation(invitation) {
1137
+ try {
1138
+ const identity = this._getIdentity();
1139
+ if (identity) {
1140
+ return new AlreadyJoinedError("Currently only one identity per client is supported.");
1141
+ }
1142
+ } catch {
1143
+ }
1144
+ }
1135
1145
  createIntroduction() {
1136
1146
  return {};
1137
1147
  }
@@ -1150,7 +1160,7 @@ var DeviceInvitationProtocol = class {
1150
1160
  async accept(response, request) {
1151
1161
  invariant4(response.device, void 0, {
1152
1162
  F: __dxlog_file5,
1153
- L: 68,
1163
+ L: 80,
1154
1164
  S: this,
1155
1165
  A: [
1156
1166
  "response.device",
@@ -1160,7 +1170,7 @@ var DeviceInvitationProtocol = class {
1160
1170
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1161
1171
  invariant4(request.device, void 0, {
1162
1172
  F: __dxlog_file5,
1163
- L: 71,
1173
+ L: 83,
1164
1174
  S: this,
1165
1175
  A: [
1166
1176
  "request.device",
@@ -1942,16 +1952,12 @@ var InvitationsHandler = class {
1942
1952
  }
1943
1953
  }
1944
1954
  }
1945
- } else {
1946
- setState({
1947
- state: Invitation3.State.READY_FOR_AUTHENTICATION
1948
- });
1949
1955
  }
1950
1956
  log5("request admission", {
1951
1957
  ...protocol.toJSON()
1952
1958
  }, {
1953
1959
  F: __dxlog_file7,
1954
- L: 312,
1960
+ L: 309,
1955
1961
  S: this,
1956
1962
  C: (f, a) => f(...a)
1957
1963
  });
@@ -1963,7 +1969,7 @@ var InvitationsHandler = class {
1963
1969
  ...protocol.toJSON()
1964
1970
  }, {
1965
1971
  F: __dxlog_file7,
1966
- L: 323,
1972
+ L: 320,
1967
1973
  S: this,
1968
1974
  C: (f, a) => f(...a)
1969
1975
  });
@@ -1976,7 +1982,7 @@ var InvitationsHandler = class {
1976
1982
  id: traceId
1977
1983
  }), {
1978
1984
  F: __dxlog_file7,
1979
- L: 325,
1985
+ L: 322,
1980
1986
  S: this,
1981
1987
  C: (f, a) => f(...a)
1982
1988
  });
@@ -1986,7 +1992,7 @@ var InvitationsHandler = class {
1986
1992
  ...protocol.toJSON()
1987
1993
  }, {
1988
1994
  F: __dxlog_file7,
1989
- L: 328,
1995
+ L: 325,
1990
1996
  S: this,
1991
1997
  C: (f, a) => f(...a)
1992
1998
  });
@@ -1996,7 +2002,7 @@ var InvitationsHandler = class {
1996
2002
  } else {
1997
2003
  log5("auth failed", err, {
1998
2004
  F: __dxlog_file7,
1999
- L: 331,
2005
+ L: 328,
2000
2006
  S: this,
2001
2007
  C: (f, a) => f(...a)
2002
2008
  });
@@ -2007,7 +2013,7 @@ var InvitationsHandler = class {
2007
2013
  error: err
2008
2014
  }), {
2009
2015
  F: __dxlog_file7,
2010
- L: 334,
2016
+ L: 331,
2011
2017
  S: this,
2012
2018
  C: (f, a) => f(...a)
2013
2019
  });
@@ -2025,7 +2031,7 @@ var InvitationsHandler = class {
2025
2031
  ...protocol.toJSON()
2026
2032
  }, {
2027
2033
  F: __dxlog_file7,
2028
- L: 345,
2034
+ L: 342,
2029
2035
  S: this,
2030
2036
  C: (f, a) => f(...a)
2031
2037
  });
@@ -2035,7 +2041,7 @@ var InvitationsHandler = class {
2035
2041
  } else {
2036
2042
  log5("auth failed", err, {
2037
2043
  F: __dxlog_file7,
2038
- L: 348,
2044
+ L: 345,
2039
2045
  S: this,
2040
2046
  C: (f, a) => f(...a)
2041
2047
  });
@@ -2046,29 +2052,34 @@ var InvitationsHandler = class {
2046
2052
  return extension;
2047
2053
  };
2048
2054
  scheduleTask2(ctx, async () => {
2049
- invariant6(invitation.swarmKey, void 0, {
2050
- F: __dxlog_file7,
2051
- L: 358,
2052
- S: this,
2053
- A: [
2054
- "invitation.swarmKey",
2055
- ""
2056
- ]
2057
- });
2058
- const topic = invitation.swarmKey;
2059
- const swarmConnection = await this._networkManager.joinSwarm({
2060
- topic,
2061
- peerId: PublicKey6.random(),
2062
- protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2063
- teleport.addExtension("dxos.halo.invitations", createExtension());
2064
- }),
2065
- topology: new StarTopology(topic),
2066
- label: "invitation guest"
2067
- });
2068
- ctx.onDispose(() => swarmConnection.close());
2069
- setState({
2070
- state: Invitation3.State.CONNECTING
2071
- });
2055
+ const error = protocol.checkInvitation(invitation);
2056
+ if (error) {
2057
+ stream.error(error);
2058
+ } else {
2059
+ invariant6(invitation.swarmKey, void 0, {
2060
+ F: __dxlog_file7,
2061
+ L: 359,
2062
+ S: this,
2063
+ A: [
2064
+ "invitation.swarmKey",
2065
+ ""
2066
+ ]
2067
+ });
2068
+ const topic = invitation.swarmKey;
2069
+ const swarmConnection = await this._networkManager.joinSwarm({
2070
+ topic,
2071
+ peerId: PublicKey6.random(),
2072
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2073
+ teleport.addExtension("dxos.halo.invitations", createExtension());
2074
+ }),
2075
+ topology: new StarTopology(topic),
2076
+ label: "invitation guest"
2077
+ });
2078
+ ctx.onDispose(() => swarmConnection.close());
2079
+ setState({
2080
+ state: Invitation3.State.CONNECTING
2081
+ });
2082
+ }
2072
2083
  });
2073
2084
  const observable = new AuthenticatingInvitation({
2074
2085
  initialInvitation: invitation,
@@ -2274,6 +2285,7 @@ import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/creden
2274
2285
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2275
2286
  import { invariant as invariant8 } from "@dxos/invariant";
2276
2287
  import { log as log7 } from "@dxos/log";
2288
+ import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2277
2289
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2278
2290
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2279
2291
  var SpaceInvitationProtocol = class {
@@ -2298,7 +2310,7 @@ var SpaceInvitationProtocol = class {
2298
2310
  async admit(request, guestProfile) {
2299
2311
  invariant8(this._spaceKey, void 0, {
2300
2312
  F: __dxlog_file9,
2301
- L: 46,
2313
+ L: 47,
2302
2314
  S: this,
2303
2315
  A: [
2304
2316
  "this._spaceKey",
@@ -2308,7 +2320,7 @@ var SpaceInvitationProtocol = class {
2308
2320
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2309
2321
  invariant8(space, void 0, {
2310
2322
  F: __dxlog_file9,
2311
- L: 48,
2323
+ L: 49,
2312
2324
  S: this,
2313
2325
  A: [
2314
2326
  "space",
@@ -2317,7 +2329,7 @@ var SpaceInvitationProtocol = class {
2317
2329
  });
2318
2330
  invariant8(request.space, void 0, {
2319
2331
  F: __dxlog_file9,
2320
- L: 50,
2332
+ L: 51,
2321
2333
  S: this,
2322
2334
  A: [
2323
2335
  "request.space",
@@ -2330,14 +2342,14 @@ var SpaceInvitationProtocol = class {
2330
2342
  guest: deviceKey
2331
2343
  }, {
2332
2344
  F: __dxlog_file9,
2333
- L: 53,
2345
+ L: 54,
2334
2346
  S: this,
2335
2347
  C: (f, a) => f(...a)
2336
2348
  });
2337
2349
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2338
2350
  invariant8(credentials[0].credential, void 0, {
2339
2351
  F: __dxlog_file9,
2340
- L: 64,
2352
+ L: 65,
2341
2353
  S: this,
2342
2354
  A: [
2343
2355
  "credentials[0].credential",
@@ -2347,7 +2359,7 @@ var SpaceInvitationProtocol = class {
2347
2359
  const spaceMemberCredential = credentials[0].credential.credential;
2348
2360
  invariant8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2349
2361
  F: __dxlog_file9,
2350
- L: 66,
2362
+ L: 67,
2351
2363
  S: this,
2352
2364
  A: [
2353
2365
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2363,6 +2375,11 @@ var SpaceInvitationProtocol = class {
2363
2375
  }
2364
2376
  };
2365
2377
  }
2378
+ checkInvitation(invitation) {
2379
+ if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2380
+ return new AlreadyJoinedError2("Already joined space.");
2381
+ }
2382
+ }
2366
2383
  createIntroduction() {
2367
2384
  return {
2368
2385
  profile: this._signingContext.getProfile()
@@ -2383,7 +2400,7 @@ var SpaceInvitationProtocol = class {
2383
2400
  async accept(response) {
2384
2401
  invariant8(response.space, void 0, {
2385
2402
  F: __dxlog_file9,
2386
- L: 101,
2403
+ L: 108,
2387
2404
  S: this,
2388
2405
  A: [
2389
2406
  "response.space",
@@ -2394,7 +2411,7 @@ var SpaceInvitationProtocol = class {
2394
2411
  const assertion = getCredentialAssertion(credential);
2395
2412
  invariant8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2396
2413
  F: __dxlog_file9,
2397
- L: 104,
2414
+ L: 111,
2398
2415
  S: this,
2399
2416
  A: [
2400
2417
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2403,13 +2420,16 @@ var SpaceInvitationProtocol = class {
2403
2420
  });
2404
2421
  invariant8(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2405
2422
  F: __dxlog_file9,
2406
- L: 105,
2423
+ L: 112,
2407
2424
  S: this,
2408
2425
  A: [
2409
2426
  "credential.subject.id.equals(this._signingContext.identityKey)",
2410
2427
  ""
2411
2428
  ]
2412
2429
  });
2430
+ if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2431
+ throw new AlreadyJoinedError2("Already joined space.");
2432
+ }
2413
2433
  await this._spaceManager.acceptSpace({
2414
2434
  spaceKey: assertion.spaceKey,
2415
2435
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2543,7 +2563,7 @@ var getPlatform = () => {
2543
2563
  };
2544
2564
 
2545
2565
  // packages/sdk/client-services/src/version.ts
2546
- var DXOS_VERSION = "0.3.11-main.c8e9429";
2566
+ var DXOS_VERSION = "0.3.11-main.c95bc86";
2547
2567
 
2548
2568
  // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2549
2569
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
@@ -2562,7 +2582,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2562
2582
  {
2563
2583
  invariant9(clientServices.LoggingService, "SystemService is not available.", {
2564
2584
  F: __dxlog_file10,
2565
- L: 92,
2585
+ L: 93,
2566
2586
  S: void 0,
2567
2587
  A: [
2568
2588
  "clientServices.LoggingService",
@@ -2573,6 +2593,21 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2573
2593
  timeout: DEFAULT_TIMEOUT
2574
2594
  }).catch(() => void 0);
2575
2595
  }
2596
+ if (typeof navigator !== "undefined" && navigator.storage) {
2597
+ const map = /* @__PURE__ */ new Map();
2598
+ const dir = await navigator.storage.getDirectory();
2599
+ for await (const filename of dir?.keys()) {
2600
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2601
+ if (idx === -1) {
2602
+ continue;
2603
+ }
2604
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2605
+ }
2606
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2607
+ file,
2608
+ count
2609
+ }));
2610
+ }
2576
2611
  const identity = serviceContext.identityManager.identity;
2577
2612
  if (identity) {
2578
2613
  diagnostics.identity = {
@@ -2613,7 +2648,7 @@ var getProperties = (space) => {
2613
2648
  } catch (err) {
2614
2649
  log8.warn(err.message, void 0, {
2615
2650
  F: __dxlog_file10,
2616
- L: 160,
2651
+ L: 178,
2617
2652
  S: void 0,
2618
2653
  C: (f, a) => f(...a)
2619
2654
  });
@@ -2674,6 +2709,7 @@ import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2674
2709
  import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2675
2710
  import { timed } from "@dxos/debug";
2676
2711
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2712
+ import { failedInvariant } from "@dxos/invariant";
2677
2713
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2678
2714
  import { log as log10 } from "@dxos/log";
2679
2715
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2686,7 +2722,8 @@ import { ComplexSet as ComplexSet3 } from "@dxos/util";
2686
2722
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
2687
2723
  import { checkCredentialType } from "@dxos/credentials";
2688
2724
  var AutomergeSpaceState = class {
2689
- constructor() {
2725
+ constructor(_onNewRoot) {
2726
+ this._onNewRoot = _onNewRoot;
2690
2727
  this.rootUrl = void 0;
2691
2728
  this.lastEpoch = void 0;
2692
2729
  }
@@ -2697,6 +2734,7 @@ var AutomergeSpaceState = class {
2697
2734
  this.lastEpoch = credential;
2698
2735
  if (credential.subject.assertion.automergeRoot) {
2699
2736
  this.rootUrl = credential.subject.assertion.automergeRoot;
2737
+ this._onNewRoot(this.rootUrl);
2700
2738
  }
2701
2739
  }
2702
2740
  };
@@ -2988,7 +3026,7 @@ var DataSpace = class {
2988
3026
  this._notarizationPlugin = new NotarizationPlugin();
2989
3027
  this._cache = void 0;
2990
3028
  // TODO(dmaretskyi): Move into Space?
2991
- this._automergeSpaceState = new AutomergeSpaceState();
3029
+ this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
2992
3030
  this._state = SpaceState.CLOSED;
2993
3031
  /**
2994
3032
  * Error for _state === SpaceState.ERROR.
@@ -3017,7 +3055,7 @@ var DataSpace = class {
3017
3055
  state: SpaceState[this._state]
3018
3056
  }, {
3019
3057
  F: __dxlog_file12,
3020
- L: 137,
3058
+ L: 138,
3021
3059
  S: this,
3022
3060
  C: (f, a) => f(...a)
3023
3061
  });
@@ -3064,7 +3102,7 @@ var DataSpace = class {
3064
3102
  state: SpaceState[this._state]
3065
3103
  }, {
3066
3104
  F: __dxlog_file12,
3067
- L: 189,
3105
+ L: 190,
3068
3106
  S: this,
3069
3107
  C: (f, a) => f(...a)
3070
3108
  });
@@ -3082,7 +3120,7 @@ var DataSpace = class {
3082
3120
  state: SpaceState[this._state]
3083
3121
  }, {
3084
3122
  F: __dxlog_file12,
3085
- L: 203,
3123
+ L: 204,
3086
3124
  S: this,
3087
3125
  C: (f, a) => f(...a)
3088
3126
  });
@@ -3114,7 +3152,7 @@ var DataSpace = class {
3114
3152
  if (err instanceof CancelledError) {
3115
3153
  log10("data pipeline initialization cancelled", err, {
3116
3154
  F: __dxlog_file12,
3117
- L: 236,
3155
+ L: 237,
3118
3156
  S: this,
3119
3157
  C: (f, a) => f(...a)
3120
3158
  });
@@ -3122,7 +3160,7 @@ var DataSpace = class {
3122
3160
  }
3123
3161
  log10.error("Error initializing data pipeline", err, {
3124
3162
  F: __dxlog_file12,
3125
- L: 240,
3163
+ L: 241,
3126
3164
  S: this,
3127
3165
  C: (f, a) => f(...a)
3128
3166
  });
@@ -3131,7 +3169,7 @@ var DataSpace = class {
3131
3169
  state: SpaceState[this._state]
3132
3170
  }, {
3133
3171
  F: __dxlog_file12,
3134
- L: 242,
3172
+ L: 243,
3135
3173
  S: this,
3136
3174
  C: (f, a) => f(...a)
3137
3175
  });
@@ -3151,7 +3189,7 @@ var DataSpace = class {
3151
3189
  state: SpaceState[this._state]
3152
3190
  }, {
3153
3191
  F: __dxlog_file12,
3154
- L: 258,
3192
+ L: 259,
3155
3193
  S: this,
3156
3194
  C: (f, a) => f(...a)
3157
3195
  });
@@ -3162,7 +3200,7 @@ var DataSpace = class {
3162
3200
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3163
3201
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3164
3202
  F: __dxlog_file12,
3165
- L: 272,
3203
+ L: 273,
3166
3204
  S: this,
3167
3205
  C: (f, a) => f(...a)
3168
3206
  });
@@ -3173,7 +3211,7 @@ var DataSpace = class {
3173
3211
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3174
3212
  log10("data pipeline ready", void 0, {
3175
3213
  F: __dxlog_file12,
3176
- L: 281,
3214
+ L: 282,
3177
3215
  S: this,
3178
3216
  C: (f, a) => f(...a)
3179
3217
  });
@@ -3183,7 +3221,7 @@ var DataSpace = class {
3183
3221
  state: SpaceState[this._state]
3184
3222
  }, {
3185
3223
  F: __dxlog_file12,
3186
- L: 285,
3224
+ L: 286,
3187
3225
  S: this,
3188
3226
  C: (f, a) => f(...a)
3189
3227
  });
@@ -3199,7 +3237,7 @@ var DataSpace = class {
3199
3237
  await this._createWritableFeeds();
3200
3238
  log10("writable feeds created", void 0, {
3201
3239
  F: __dxlog_file12,
3202
- L: 301,
3240
+ L: 302,
3203
3241
  S: this,
3204
3242
  C: (f, a) => f(...a)
3205
3243
  });
@@ -3256,6 +3294,40 @@ var DataSpace = class {
3256
3294
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3257
3295
  }
3258
3296
  }
3297
+ _onNewAutomergeRoot(rootUrl) {
3298
+ log10.info("loading automerge root doc for space", {
3299
+ space: this.key,
3300
+ rootUrl
3301
+ }, {
3302
+ F: __dxlog_file12,
3303
+ L: 368,
3304
+ S: this,
3305
+ C: (f, a) => f(...a)
3306
+ });
3307
+ const handle = this._automergeHost.repo.find(rootUrl);
3308
+ queueMicrotask(async () => {
3309
+ try {
3310
+ await handle.whenReady();
3311
+ const doc = handle.docSync() ?? failedInvariant();
3312
+ if (!doc.experimental_spaceKey) {
3313
+ handle.change((doc2) => {
3314
+ doc2.experimental_spaceKey = this.key.toHex();
3315
+ });
3316
+ }
3317
+ } catch (err) {
3318
+ log10.warn("error loading automerge root doc", {
3319
+ space: this.key,
3320
+ rootUrl,
3321
+ err
3322
+ }, {
3323
+ F: __dxlog_file12,
3324
+ L: 381,
3325
+ S: this,
3326
+ C: (f, a) => f(...a)
3327
+ });
3328
+ }
3329
+ });
3330
+ }
3259
3331
  // TODO(dmaretskyi): Use profile from signing context.
3260
3332
  async updateOwnProfile(profile) {
3261
3333
  const credential = await this._signingContext.credentialSigner.createCredential({
@@ -3339,7 +3411,7 @@ var DataSpace = class {
3339
3411
  state: SpaceState[this._state]
3340
3412
  }, {
3341
3413
  F: __dxlog_file12,
3342
- L: 450,
3414
+ L: 470,
3343
3415
  S: this,
3344
3416
  C: (f, a) => f(...a)
3345
3417
  });
@@ -3598,12 +3670,15 @@ var DataSpaceManager = class {
3598
3670
  });
3599
3671
  const space = await this._constructSpace(metadata);
3600
3672
  const automergeRoot = this._automergeHost.repo.create();
3673
+ automergeRoot.change((doc) => {
3674
+ doc.experimental_spaceKey = spaceKey.toHex();
3675
+ });
3601
3676
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3602
3677
  await this._metadataStore.addSpace(metadata);
3603
3678
  const memberCredential = credentials[1];
3604
3679
  invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3605
3680
  F: __dxlog_file13,
3606
- L: 151,
3681
+ L: 154,
3607
3682
  S: this,
3608
3683
  A: [
3609
3684
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3621,13 +3696,13 @@ var DataSpaceManager = class {
3621
3696
  opts
3622
3697
  }, {
3623
3698
  F: __dxlog_file13,
3624
- L: 163,
3699
+ L: 166,
3625
3700
  S: this,
3626
3701
  C: (f, a) => f(...a)
3627
3702
  });
3628
3703
  invariant11(this._isOpen, "Not open.", {
3629
3704
  F: __dxlog_file13,
3630
- L: 164,
3705
+ L: 167,
3631
3706
  S: this,
3632
3707
  A: [
3633
3708
  "this._isOpen",
@@ -3636,7 +3711,7 @@ var DataSpaceManager = class {
3636
3711
  });
3637
3712
  invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3638
3713
  F: __dxlog_file13,
3639
- L: 165,
3714
+ L: 168,
3640
3715
  S: this,
3641
3716
  A: [
3642
3717
  "!this._spaces.has(opts.spaceKey)",
@@ -3671,7 +3746,7 @@ var DataSpaceManager = class {
3671
3746
  metadata
3672
3747
  }, {
3673
3748
  F: __dxlog_file13,
3674
- L: 198,
3749
+ L: 201,
3675
3750
  S: this,
3676
3751
  C: (f, a) => f(...a)
3677
3752
  });
@@ -3698,17 +3773,18 @@ var DataSpaceManager = class {
3698
3773
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
3699
3774
  credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
3700
3775
  },
3701
- onNetworkConnection: (session) => {
3776
+ onAuthorizedConnection: (session) => {
3702
3777
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
3703
3778
  remotePeerId: session.remotePeerId
3704
3779
  }));
3705
3780
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3781
+ this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
3706
3782
  session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
3707
3783
  },
3708
3784
  onAuthFailure: () => {
3709
3785
  log11.warn("auth failure", void 0, {
3710
3786
  F: __dxlog_file13,
3711
- L: 234,
3787
+ L: 238,
3712
3788
  S: this,
3713
3789
  C: (f, a) => f(...a)
3714
3790
  });
@@ -3732,7 +3808,7 @@ var DataSpaceManager = class {
3732
3808
  space: space.key
3733
3809
  }, {
3734
3810
  F: __dxlog_file13,
3735
- L: 252,
3811
+ L: 256,
3736
3812
  S: this,
3737
3813
  C: (f, a) => f(...a)
3738
3814
  });
@@ -3744,7 +3820,7 @@ var DataSpaceManager = class {
3744
3820
  open: this._isOpen
3745
3821
  }, {
3746
3822
  F: __dxlog_file13,
3747
- L: 259,
3823
+ L: 263,
3748
3824
  S: this,
3749
3825
  C: (f, a) => f(...a)
3750
3826
  });
@@ -3757,7 +3833,7 @@ var DataSpaceManager = class {
3757
3833
  space: space.key
3758
3834
  }, {
3759
3835
  F: __dxlog_file13,
3760
- L: 265,
3836
+ L: 269,
3761
3837
  S: this,
3762
3838
  C: (f, a) => f(...a)
3763
3839
  });
@@ -3814,7 +3890,7 @@ var SpacesServiceImpl = class {
3814
3890
  }
3815
3891
  async createSpace() {
3816
3892
  if (!this._identityManager.identity) {
3817
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
3893
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
3818
3894
  }
3819
3895
  const dataSpaceManager = await this._getDataSpaceManager();
3820
3896
  const space = await dataSpaceManager.createSpace();
@@ -5187,4 +5263,4 @@ export {
5187
5263
  createDefaultModelFactory,
5188
5264
  ClientServicesHost
5189
5265
  };
5190
- //# sourceMappingURL=chunk-OZ4IMR73.mjs.map
5266
+ //# sourceMappingURL=chunk-4ZZIUZXZ.mjs.map