@dxos/client-services 0.4.7-main.85d9ee7 → 0.4.7-main.b1ae49b

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 (46) hide show
  1. package/dist/lib/browser/{chunk-KESTWAZ5.mjs → chunk-XXUWZUVG.mjs} +324 -150
  2. package/dist/lib/browser/chunk-XXUWZUVG.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -3
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +4 -2
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-RG6HMYQS.cjs → chunk-65WPTUZO.cjs} +297 -122
  9. package/dist/lib/node/chunk-65WPTUZO.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +43 -39
  11. package/dist/lib/node/index.cjs.map +2 -2
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +11 -9
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -0
  16. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-service.d.ts +9 -1
  18. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  19. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -0
  20. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/service-context.d.ts +2 -0
  22. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  23. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  25. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  28. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  29. package/dist/types/src/packlets/vault/shared-worker-connection.d.ts.map +1 -1
  30. package/dist/types/src/version.d.ts +1 -1
  31. package/package.json +35 -35
  32. package/src/packlets/identity/identity-manager.ts +1 -1
  33. package/src/packlets/invitations/invitations-handler.ts +37 -2
  34. package/src/packlets/invitations/invitations-service.ts +83 -5
  35. package/src/packlets/logging/logging-service.ts +9 -2
  36. package/src/packlets/services/automerge-host.test.ts +1 -1
  37. package/src/packlets/services/service-context.ts +7 -1
  38. package/src/packlets/services/service-host.ts +9 -2
  39. package/src/packlets/spaces/automerge-space-state.ts +15 -0
  40. package/src/packlets/spaces/data-space.ts +33 -11
  41. package/src/packlets/spaces/spaces-service.ts +2 -2
  42. package/src/packlets/testing/test-builder.ts +1 -1
  43. package/src/packlets/vault/shared-worker-connection.ts +3 -1
  44. package/src/version.ts +1 -1
  45. package/dist/lib/browser/chunk-KESTWAZ5.mjs.map +0 -7
  46. package/dist/lib/node/chunk-RG6HMYQS.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_RG6HMYQS_exports = {};
30
- __export(chunk_RG6HMYQS_exports, {
29
+ var chunk_65WPTUZO_exports = {};
30
+ __export(chunk_65WPTUZO_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -51,6 +51,7 @@ __export(chunk_RG6HMYQS_exports, {
51
51
  createDiagnostics: () => createDiagnostics,
52
52
  createStorageObjects: () => createStorageObjects,
53
53
  getNetworkPeers: () => getNetworkPeers,
54
+ invitationExpired: () => invitationExpired,
54
55
  isLocked: () => isLocked,
55
56
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
56
57
  subscribeToFeeds: () => subscribeToFeeds,
@@ -60,7 +61,7 @@ __export(chunk_RG6HMYQS_exports, {
60
61
  subscribeToSpaces: () => subscribeToSpaces,
61
62
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
63
  });
63
- module.exports = __toCommonJS(chunk_RG6HMYQS_exports);
64
+ module.exports = __toCommonJS(chunk_65WPTUZO_exports);
64
65
  var import_async = require("@dxos/async");
65
66
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
67
  var import_feed_store = require("@dxos/feed-store");
@@ -133,6 +134,7 @@ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations")
133
134
  var import_teleport = require("@dxos/teleport");
134
135
  var import_async9 = require("@dxos/async");
135
136
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
137
+ var import_context6 = require("@dxos/context");
136
138
  var import_invariant7 = require("@dxos/invariant");
137
139
  var import_log6 = require("@dxos/log");
138
140
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
@@ -158,7 +160,7 @@ var import_tracing4 = require("@dxos/tracing");
158
160
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
159
161
  var import_async10 = require("@dxos/async");
160
162
  var import_client_protocol3 = require("@dxos/client-protocol");
161
- var import_context6 = require("@dxos/context");
163
+ var import_context7 = require("@dxos/context");
162
164
  var import_debug3 = require("@dxos/debug");
163
165
  var import_echo_pipeline = require("@dxos/echo-pipeline");
164
166
  var import_invariant10 = require("@dxos/invariant");
@@ -172,7 +174,7 @@ var import_tracing5 = require("@dxos/tracing");
172
174
  var import_util4 = require("@dxos/util");
173
175
  var import_credentials11 = require("@dxos/credentials");
174
176
  var import_async11 = require("@dxos/async");
175
- var import_context7 = require("@dxos/context");
177
+ var import_context8 = require("@dxos/context");
176
178
  var import_invariant11 = require("@dxos/invariant");
177
179
  var import_keys8 = require("@dxos/keys");
178
180
  var import_log10 = require("@dxos/log");
@@ -180,7 +182,7 @@ var import_protocols9 = require("@dxos/protocols");
180
182
  var import_teleport2 = require("@dxos/teleport");
181
183
  var import_util5 = require("@dxos/util");
182
184
  var import_async12 = require("@dxos/async");
183
- var import_context8 = require("@dxos/context");
185
+ var import_context9 = require("@dxos/context");
184
186
  var import_credentials12 = require("@dxos/credentials");
185
187
  var import_invariant12 = require("@dxos/invariant");
186
188
  var import_keys9 = require("@dxos/keys");
@@ -201,10 +203,11 @@ var import_log12 = require("@dxos/log");
201
203
  var import_protocols11 = require("@dxos/protocols");
202
204
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
203
205
  var import_async14 = require("@dxos/async");
204
- var import_context9 = require("@dxos/context");
206
+ var import_context10 = require("@dxos/context");
205
207
  var import_credentials15 = require("@dxos/credentials");
206
208
  var import_debug6 = require("@dxos/debug");
207
209
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
210
+ var import_echo_schema = require("@dxos/echo-schema");
208
211
  var import_feed_store4 = require("@dxos/feed-store");
209
212
  var import_invariant14 = require("@dxos/invariant");
210
213
  var import_keyring = require("@dxos/keyring");
@@ -225,10 +228,10 @@ var import_random_access_storage = require("@dxos/random-access-storage");
225
228
  var import_util8 = require("@dxos/util");
226
229
  var import_async15 = require("@dxos/async");
227
230
  var import_client_protocol5 = require("@dxos/client-protocol");
228
- var import_context10 = require("@dxos/context");
231
+ var import_context11 = require("@dxos/context");
229
232
  var import_document_model2 = require("@dxos/document-model");
230
233
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
231
- var import_echo_schema = require("@dxos/echo-schema");
234
+ var import_echo_schema2 = require("@dxos/echo-schema");
232
235
  var import_invariant16 = require("@dxos/invariant");
233
236
  var import_keys11 = require("@dxos/keys");
234
237
  var import_log15 = require("@dxos/log");
@@ -247,6 +250,7 @@ var import_invariant17 = require("@dxos/invariant");
247
250
  var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
248
251
  var import_async17 = require("@dxos/async");
249
252
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
253
+ var import_keys12 = require("@dxos/keys");
250
254
  var import_log16 = require("@dxos/log");
251
255
  var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
252
256
  var import_util10 = require("@dxos/util");
@@ -1228,7 +1232,7 @@ var IdentityManager = class {
1228
1232
  identityKey: identityRecord.identityKey
1229
1233
  });
1230
1234
  await space.setControlFeed(controlFeed);
1231
- void space.setDataFeed(dataFeed);
1235
+ await space.setDataFeed(dataFeed);
1232
1236
  const identity = new Identity({
1233
1237
  space,
1234
1238
  presence,
@@ -1786,11 +1790,11 @@ var InvitationsHandler = class {
1786
1790
  this._networkManager = _networkManager;
1787
1791
  }
1788
1792
  createInvitation(protocol, options) {
1789
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random() } = options ?? {};
1793
+ const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
1790
1794
  const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1791
1795
  (0, import_invariant5.invariant)(protocol, void 0, {
1792
1796
  F: __dxlog_file7,
1793
- L: 81,
1797
+ L: 84,
1794
1798
  S: this,
1795
1799
  A: [
1796
1800
  "protocol",
@@ -1805,13 +1809,16 @@ var InvitationsHandler = class {
1805
1809
  swarmKey,
1806
1810
  authCode,
1807
1811
  timeout,
1812
+ persistent,
1813
+ created,
1814
+ lifetime,
1808
1815
  ...protocol.getInvitationContext()
1809
1816
  };
1810
1817
  const stream = new import_async7.PushStream();
1811
1818
  const ctx = new import_context4.Context({
1812
1819
  onError: (err) => {
1813
- void ctx.dispose();
1814
1820
  stream.error(err);
1821
+ void ctx.dispose();
1815
1822
  }
1816
1823
  });
1817
1824
  ctx.onDispose(() => {
@@ -1819,7 +1826,7 @@ var InvitationsHandler = class {
1819
1826
  ...protocol.toJSON()
1820
1827
  }, {
1821
1828
  F: __dxlog_file7,
1822
- L: 103,
1829
+ L: 109,
1823
1830
  S: this,
1824
1831
  C: (f, a) => f(...a)
1825
1832
  });
@@ -1844,7 +1851,7 @@ var InvitationsHandler = class {
1844
1851
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1845
1852
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1846
1853
  F: __dxlog_file7,
1847
- L: 124,
1854
+ L: 130,
1848
1855
  S: this,
1849
1856
  A: [
1850
1857
  "deviceKey",
@@ -1867,7 +1874,7 @@ var InvitationsHandler = class {
1867
1874
  id: traceId
1868
1875
  }), {
1869
1876
  F: __dxlog_file7,
1870
- L: 142,
1877
+ L: 148,
1871
1878
  S: this,
1872
1879
  C: (f, a) => f(...a)
1873
1880
  });
@@ -1875,7 +1882,7 @@ var InvitationsHandler = class {
1875
1882
  ...protocol.toJSON()
1876
1883
  }, {
1877
1884
  F: __dxlog_file7,
1878
- L: 143,
1885
+ L: 149,
1879
1886
  S: this,
1880
1887
  C: (f, a) => f(...a)
1881
1888
  });
@@ -1891,7 +1898,7 @@ var InvitationsHandler = class {
1891
1898
  ...protocol.toJSON()
1892
1899
  }, {
1893
1900
  F: __dxlog_file7,
1894
- L: 146,
1901
+ L: 152,
1895
1902
  S: this,
1896
1903
  C: (f, a) => f(...a)
1897
1904
  });
@@ -1903,7 +1910,7 @@ var InvitationsHandler = class {
1903
1910
  id: traceId
1904
1911
  }), {
1905
1912
  F: __dxlog_file7,
1906
- L: 148,
1913
+ L: 154,
1907
1914
  S: this,
1908
1915
  C: (f, a) => f(...a)
1909
1916
  });
@@ -1913,7 +1920,7 @@ var InvitationsHandler = class {
1913
1920
  ...protocol.toJSON()
1914
1921
  }, {
1915
1922
  F: __dxlog_file7,
1916
- L: 151,
1923
+ L: 157,
1917
1924
  S: this,
1918
1925
  C: (f, a) => f(...a)
1919
1926
  });
@@ -1924,7 +1931,7 @@ var InvitationsHandler = class {
1924
1931
  } else {
1925
1932
  import_log4.log.error("failed", err, {
1926
1933
  F: __dxlog_file7,
1927
- L: 154,
1934
+ L: 160,
1928
1935
  S: this,
1929
1936
  C: (f, a) => f(...a)
1930
1937
  });
@@ -1935,7 +1942,7 @@ var InvitationsHandler = class {
1935
1942
  error: err
1936
1943
  }), {
1937
1944
  F: __dxlog_file7,
1938
- L: 157,
1945
+ L: 163,
1939
1946
  S: this,
1940
1947
  C: (f, a) => f(...a)
1941
1948
  });
@@ -1956,7 +1963,7 @@ var InvitationsHandler = class {
1956
1963
  ...protocol.toJSON()
1957
1964
  }, {
1958
1965
  F: __dxlog_file7,
1959
- L: 172,
1966
+ L: 178,
1960
1967
  S: this,
1961
1968
  C: (f, a) => f(...a)
1962
1969
  });
@@ -1967,7 +1974,7 @@ var InvitationsHandler = class {
1967
1974
  } else {
1968
1975
  import_log4.log.error("failed", err, {
1969
1976
  F: __dxlog_file7,
1970
- L: 175,
1977
+ L: 181,
1971
1978
  S: this,
1972
1979
  C: (f, a) => f(...a)
1973
1980
  });
@@ -1977,7 +1984,27 @@ var InvitationsHandler = class {
1977
1984
  });
1978
1985
  return extension;
1979
1986
  };
1987
+ if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1988
+ if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1989
+ import_log4.log.warn("invitation has already expired", void 0, {
1990
+ F: __dxlog_file7,
1991
+ L: 192,
1992
+ S: this,
1993
+ C: (f, a) => f(...a)
1994
+ });
1995
+ } else {
1996
+ (0, import_async7.scheduleTask)(ctx, async () => {
1997
+ await swarmConnection.close();
1998
+ stream.next({
1999
+ ...invitation,
2000
+ state: import_services3.Invitation.State.EXPIRED
2001
+ });
2002
+ await ctx.dispose();
2003
+ }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
2004
+ }
2005
+ }
1980
2006
  let swarmConnection;
2007
+ const invitationLabel = "invitation host for " + (invitation.kind === import_services3.Invitation.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
1981
2008
  (0, import_async7.scheduleTask)(ctx, async () => {
1982
2009
  const topic = invitation.swarmKey;
1983
2010
  swarmConnection = await this._networkManager.joinSwarm({
@@ -1987,7 +2014,7 @@ var InvitationsHandler = class {
1987
2014
  teleport.addExtension("dxos.halo.invitations", createExtension());
1988
2015
  }),
1989
2016
  topology: new import_network_manager.StarTopology(topic),
1990
- label: "invitation host"
2017
+ label: invitationLabel
1991
2018
  });
1992
2019
  ctx.onDispose(() => swarmConnection.close());
1993
2020
  stream.next({
@@ -2012,7 +2039,7 @@ var InvitationsHandler = class {
2012
2039
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2013
2040
  (0, import_invariant5.invariant)(protocol, void 0, {
2014
2041
  F: __dxlog_file7,
2015
- L: 220,
2042
+ L: 246,
2016
2043
  S: this,
2017
2044
  A: [
2018
2045
  "protocol",
@@ -2022,7 +2049,7 @@ var InvitationsHandler = class {
2022
2049
  if (deviceProfile) {
2023
2050
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2024
2051
  F: __dxlog_file7,
2025
- L: 224,
2052
+ L: 250,
2026
2053
  S: this,
2027
2054
  A: [
2028
2055
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2037,7 +2064,7 @@ var InvitationsHandler = class {
2037
2064
  const setState = (newData) => {
2038
2065
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2039
2066
  F: __dxlog_file7,
2040
- L: 235,
2067
+ L: 261,
2041
2068
  S: this,
2042
2069
  A: [
2043
2070
  "newData.state !== undefined",
@@ -2057,7 +2084,7 @@ var InvitationsHandler = class {
2057
2084
  ...protocol.toJSON()
2058
2085
  }, {
2059
2086
  F: __dxlog_file7,
2060
- L: 243,
2087
+ L: 269,
2061
2088
  S: this,
2062
2089
  C: (f, a) => f(...a)
2063
2090
  });
@@ -2067,7 +2094,7 @@ var InvitationsHandler = class {
2067
2094
  } else {
2068
2095
  import_log4.log.warn("auth failed", err, {
2069
2096
  F: __dxlog_file7,
2070
- L: 246,
2097
+ L: 272,
2071
2098
  S: this,
2072
2099
  C: (f, a) => f(...a)
2073
2100
  });
@@ -2081,7 +2108,7 @@ var InvitationsHandler = class {
2081
2108
  ...protocol.toJSON()
2082
2109
  }, {
2083
2110
  F: __dxlog_file7,
2084
- L: 254,
2111
+ L: 280,
2085
2112
  S: this,
2086
2113
  C: (f, a) => f(...a)
2087
2114
  });
@@ -2096,7 +2123,7 @@ var InvitationsHandler = class {
2096
2123
  currentState
2097
2124
  }, {
2098
2125
  F: __dxlog_file7,
2099
- L: 264,
2126
+ L: 290,
2100
2127
  S: this,
2101
2128
  C: (f, a) => f(...a)
2102
2129
  });
@@ -2111,7 +2138,7 @@ var InvitationsHandler = class {
2111
2138
  id: traceId
2112
2139
  }), {
2113
2140
  F: __dxlog_file7,
2114
- L: 273,
2141
+ L: 299,
2115
2142
  S: this,
2116
2143
  C: (f, a) => f(...a)
2117
2144
  });
@@ -2123,7 +2150,7 @@ var InvitationsHandler = class {
2123
2150
  ...protocol.toJSON()
2124
2151
  }, {
2125
2152
  F: __dxlog_file7,
2126
- L: 281,
2153
+ L: 307,
2127
2154
  S: this,
2128
2155
  C: (f, a) => f(...a)
2129
2156
  });
@@ -2134,7 +2161,7 @@ var InvitationsHandler = class {
2134
2161
  ...protocol.toJSON()
2135
2162
  }, {
2136
2163
  F: __dxlog_file7,
2137
- L: 285,
2164
+ L: 311,
2138
2165
  S: this,
2139
2166
  C: (f, a) => f(...a)
2140
2167
  });
@@ -2144,7 +2171,7 @@ var InvitationsHandler = class {
2144
2171
  response: introductionResponse
2145
2172
  }, {
2146
2173
  F: __dxlog_file7,
2147
- L: 289,
2174
+ L: 315,
2148
2175
  S: this,
2149
2176
  C: (f, a) => f(...a)
2150
2177
  });
@@ -2153,7 +2180,7 @@ var InvitationsHandler = class {
2153
2180
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2154
2181
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2155
2182
  F: __dxlog_file7,
2156
- L: 295,
2183
+ L: 321,
2157
2184
  S: this,
2158
2185
  C: (f, a) => f(...a)
2159
2186
  });
@@ -2165,7 +2192,7 @@ var InvitationsHandler = class {
2165
2192
  });
2166
2193
  (0, import_log4.log)("sending authentication request", void 0, {
2167
2194
  F: __dxlog_file7,
2168
- L: 299,
2195
+ L: 325,
2169
2196
  S: this,
2170
2197
  C: (f, a) => f(...a)
2171
2198
  });
@@ -2186,7 +2213,7 @@ var InvitationsHandler = class {
2186
2213
  attempt
2187
2214
  }, {
2188
2215
  F: __dxlog_file7,
2189
- L: 310,
2216
+ L: 336,
2190
2217
  S: this,
2191
2218
  C: (f, a) => f(...a)
2192
2219
  });
@@ -2199,7 +2226,7 @@ var InvitationsHandler = class {
2199
2226
  ...protocol.toJSON()
2200
2227
  }, {
2201
2228
  F: __dxlog_file7,
2202
- L: 318,
2229
+ L: 344,
2203
2230
  S: this,
2204
2231
  C: (f, a) => f(...a)
2205
2232
  });
@@ -2211,7 +2238,7 @@ var InvitationsHandler = class {
2211
2238
  ...protocol.toJSON()
2212
2239
  }, {
2213
2240
  F: __dxlog_file7,
2214
- L: 329,
2241
+ L: 355,
2215
2242
  S: this,
2216
2243
  C: (f, a) => f(...a)
2217
2244
  });
@@ -2224,7 +2251,7 @@ var InvitationsHandler = class {
2224
2251
  id: traceId
2225
2252
  }), {
2226
2253
  F: __dxlog_file7,
2227
- L: 331,
2254
+ L: 357,
2228
2255
  S: this,
2229
2256
  C: (f, a) => f(...a)
2230
2257
  });
@@ -2234,7 +2261,7 @@ var InvitationsHandler = class {
2234
2261
  ...protocol.toJSON()
2235
2262
  }, {
2236
2263
  F: __dxlog_file7,
2237
- L: 334,
2264
+ L: 360,
2238
2265
  S: this,
2239
2266
  C: (f, a) => f(...a)
2240
2267
  });
@@ -2244,7 +2271,7 @@ var InvitationsHandler = class {
2244
2271
  } else {
2245
2272
  (0, import_log4.log)("auth failed", err, {
2246
2273
  F: __dxlog_file7,
2247
- L: 337,
2274
+ L: 363,
2248
2275
  S: this,
2249
2276
  C: (f, a) => f(...a)
2250
2277
  });
@@ -2255,7 +2282,7 @@ var InvitationsHandler = class {
2255
2282
  error: err
2256
2283
  }), {
2257
2284
  F: __dxlog_file7,
2258
- L: 340,
2285
+ L: 366,
2259
2286
  S: this,
2260
2287
  C: (f, a) => f(...a)
2261
2288
  });
@@ -2273,7 +2300,7 @@ var InvitationsHandler = class {
2273
2300
  ...protocol.toJSON()
2274
2301
  }, {
2275
2302
  F: __dxlog_file7,
2276
- L: 351,
2303
+ L: 377,
2277
2304
  S: this,
2278
2305
  C: (f, a) => f(...a)
2279
2306
  });
@@ -2283,7 +2310,7 @@ var InvitationsHandler = class {
2283
2310
  } else {
2284
2311
  (0, import_log4.log)("auth failed", err, {
2285
2312
  F: __dxlog_file7,
2286
- L: 354,
2313
+ L: 380,
2287
2314
  S: this,
2288
2315
  C: (f, a) => f(...a)
2289
2316
  });
@@ -2300,7 +2327,7 @@ var InvitationsHandler = class {
2300
2327
  } else {
2301
2328
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2302
2329
  F: __dxlog_file7,
2303
- L: 368,
2330
+ L: 394,
2304
2331
  S: this,
2305
2332
  A: [
2306
2333
  "invitation.swarmKey",
@@ -2339,17 +2366,24 @@ var InvitationsHandler = class {
2339
2366
  return observable;
2340
2367
  }
2341
2368
  };
2369
+ var invitationExpired = (invitation) => {
2370
+ return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2371
+ };
2342
2372
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2343
2373
  var InvitationsServiceImpl = class {
2344
- constructor(_invitationsHandler, _getHandler) {
2374
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2345
2375
  this._invitationsHandler = _invitationsHandler;
2346
2376
  this._getHandler = _getHandler;
2377
+ this._metadataStore = _metadataStore;
2347
2378
  this._createInvitations = /* @__PURE__ */ new Map();
2348
2379
  this._acceptInvitations = /* @__PURE__ */ new Map();
2349
2380
  this._invitationCreated = new import_async9.Event();
2350
2381
  this._invitationAccepted = new import_async9.Event();
2351
2382
  this._removedCreated = new import_async9.Event();
2352
2383
  this._removedAccepted = new import_async9.Event();
2384
+ this._saved = new import_async9.Event();
2385
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2386
+ this._persistentInvitationsLoaded = false;
2353
2387
  }
2354
2388
  // TODO(burdon): Guest/host label.
2355
2389
  getLoggingContext() {
@@ -2357,6 +2391,7 @@ var InvitationsServiceImpl = class {
2357
2391
  }
2358
2392
  createInvitation(options) {
2359
2393
  let invitation;
2394
+ const savePersistentInvitationCtx = new import_context6.Context();
2360
2395
  const existingInvitation = this._createInvitations.get(options.invitationId);
2361
2396
  if (existingInvitation) {
2362
2397
  invitation = existingInvitation;
@@ -2367,12 +2402,27 @@ var InvitationsServiceImpl = class {
2367
2402
  this._invitationCreated.emit(invitation.get());
2368
2403
  }
2369
2404
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2405
+ if (invitation.get().persistent) {
2406
+ (0, import_async9.scheduleTask)(savePersistentInvitationCtx, async () => {
2407
+ try {
2408
+ await this._metadataStore.addInvitation(invitation.get());
2409
+ this._saved.emit(invitation.get());
2410
+ } catch (err) {
2411
+ close(err);
2412
+ }
2413
+ });
2414
+ }
2370
2415
  invitation.subscribe((invitation2) => {
2371
2416
  next(invitation2);
2372
- }, (err) => {
2417
+ }, async (err) => {
2418
+ await savePersistentInvitationCtx.dispose();
2373
2419
  close(err);
2374
- }, () => {
2420
+ }, async () => {
2375
2421
  close();
2422
+ if (invitation.get().persistent) {
2423
+ await savePersistentInvitationCtx.dispose();
2424
+ await this._metadataStore.removeInvitation(invitation.get().invitationId);
2425
+ }
2376
2426
  this._createInvitations.delete(invitation.get().invitationId);
2377
2427
  if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2378
2428
  this._removedCreated.emit(invitation.get());
@@ -2380,12 +2430,37 @@ var InvitationsServiceImpl = class {
2380
2430
  });
2381
2431
  });
2382
2432
  }
2433
+ async loadPersistentInvitations() {
2434
+ const persistentInvitations = this._metadataStore.getInvitations();
2435
+ const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2436
+ const cInvitations = freshInvitations.map((persistentInvitation) => {
2437
+ (0, import_invariant7.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2438
+ F: __dxlog_file8,
2439
+ L: 109,
2440
+ S: this,
2441
+ A: [
2442
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2443
+ "'invitation already exists'"
2444
+ ]
2445
+ });
2446
+ const handler = this._getHandler(persistentInvitation);
2447
+ const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2448
+ this._createInvitations.set(invitation.get().invitationId, invitation);
2449
+ this._invitationCreated.emit(invitation.get());
2450
+ return persistentInvitation;
2451
+ });
2452
+ this._persistentInvitationsLoadedEvent.emit();
2453
+ this._persistentInvitationsLoaded = true;
2454
+ return {
2455
+ invitations: cInvitations
2456
+ };
2457
+ }
2383
2458
  acceptInvitation({ invitation: options, deviceProfile }) {
2384
2459
  let invitation;
2385
2460
  if (deviceProfile) {
2386
2461
  (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2387
2462
  F: __dxlog_file8,
2388
- L: 81,
2463
+ L: 127,
2389
2464
  S: this,
2390
2465
  A: [
2391
2466
  "options.kind === Invitation.Kind.DEVICE",
@@ -2419,13 +2494,13 @@ var InvitationsServiceImpl = class {
2419
2494
  async authenticate({ invitationId, authCode }) {
2420
2495
  (0, import_log6.log)("authenticating...", void 0, {
2421
2496
  F: __dxlog_file8,
2422
- L: 114,
2497
+ L: 160,
2423
2498
  S: this,
2424
2499
  C: (f, a) => f(...a)
2425
2500
  });
2426
2501
  (0, import_invariant7.invariant)(invitationId, void 0, {
2427
2502
  F: __dxlog_file8,
2428
- L: 115,
2503
+ L: 161,
2429
2504
  S: this,
2430
2505
  A: [
2431
2506
  "invitationId",
@@ -2438,7 +2513,7 @@ var InvitationsServiceImpl = class {
2438
2513
  invitationId
2439
2514
  }, {
2440
2515
  F: __dxlog_file8,
2441
- L: 118,
2516
+ L: 164,
2442
2517
  S: this,
2443
2518
  C: (f, a) => f(...a)
2444
2519
  });
@@ -2447,15 +2522,17 @@ var InvitationsServiceImpl = class {
2447
2522
  }
2448
2523
  }
2449
2524
  async cancelInvitation({ invitationId }) {
2450
- (0, import_log6.log)("deleting...", void 0, {
2525
+ (0, import_log6.log)("cancelInvitation...", {
2526
+ invitationId
2527
+ }, {
2451
2528
  F: __dxlog_file8,
2452
- L: 125,
2529
+ L: 171,
2453
2530
  S: this,
2454
2531
  C: (f, a) => f(...a)
2455
2532
  });
2456
2533
  (0, import_invariant7.invariant)(invitationId, void 0, {
2457
2534
  F: __dxlog_file8,
2458
- L: 126,
2535
+ L: 172,
2459
2536
  S: this,
2460
2537
  A: [
2461
2538
  "invitationId",
@@ -2468,6 +2545,9 @@ var InvitationsServiceImpl = class {
2468
2545
  await created.cancel();
2469
2546
  this._createInvitations.delete(invitationId);
2470
2547
  this._removedCreated.emit(created.get());
2548
+ if (created.get().persistent) {
2549
+ await this._metadataStore.removeInvitation(created.get().invitationId);
2550
+ }
2471
2551
  } else if (accepted) {
2472
2552
  await accepted.cancel();
2473
2553
  this._acceptInvitations.delete(invitationId);
@@ -2512,16 +2592,40 @@ var InvitationsServiceImpl = class {
2512
2592
  ]
2513
2593
  });
2514
2594
  });
2595
+ this._saved.on(ctx, (invitation) => {
2596
+ next({
2597
+ action: import_services5.QueryInvitationsResponse.Action.SAVED,
2598
+ type: import_services5.QueryInvitationsResponse.Type.CREATED,
2599
+ invitations: [
2600
+ invitation
2601
+ ]
2602
+ });
2603
+ });
2515
2604
  next({
2516
2605
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2517
2606
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2518
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
2607
+ invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2608
+ existing: true
2519
2609
  });
2520
2610
  next({
2521
2611
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2522
2612
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2523
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
2613
+ invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2614
+ existing: true
2524
2615
  });
2616
+ if (this._persistentInvitationsLoaded) {
2617
+ next({
2618
+ action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2619
+ type: import_services5.QueryInvitationsResponse.Type.CREATED
2620
+ });
2621
+ } else {
2622
+ this._persistentInvitationsLoadedEvent.on(ctx, () => {
2623
+ next({
2624
+ action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2625
+ type: import_services5.QueryInvitationsResponse.Type.CREATED
2626
+ });
2627
+ });
2628
+ }
2525
2629
  });
2526
2630
  }
2527
2631
  };
@@ -2782,7 +2886,7 @@ var getPlatform = () => {
2782
2886
  };
2783
2887
  }
2784
2888
  };
2785
- var DXOS_VERSION = "0.4.7-main.85d9ee7";
2889
+ var DXOS_VERSION = "0.4.7-main.b1ae49b";
2786
2890
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2787
2891
  var DEFAULT_TIMEOUT = 1e3;
2788
2892
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2925,6 +3029,7 @@ var AutomergeSpaceState = class {
2925
3029
  this._onNewRoot = _onNewRoot;
2926
3030
  this.rootUrl = void 0;
2927
3031
  this.lastEpoch = void 0;
3032
+ this._isProcessingRootDocs = false;
2928
3033
  }
2929
3034
  async processCredential(credential) {
2930
3035
  if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
@@ -2933,8 +3038,19 @@ var AutomergeSpaceState = class {
2933
3038
  this.lastEpoch = credential;
2934
3039
  if (credential.subject.assertion.automergeRoot) {
2935
3040
  this.rootUrl = credential.subject.assertion.automergeRoot;
3041
+ if (this._isProcessingRootDocs) {
3042
+ this._onNewRoot(this.rootUrl);
3043
+ }
3044
+ }
3045
+ }
3046
+ startProcessingRootDocs() {
3047
+ if (this._isProcessingRootDocs) {
3048
+ return;
3049
+ }
3050
+ if (this.rootUrl) {
2936
3051
  this._onNewRoot(this.rootUrl);
2937
3052
  }
3053
+ this._isProcessingRootDocs = true;
2938
3054
  }
2939
3055
  };
2940
3056
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
@@ -2944,7 +3060,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2944
3060
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2945
3061
  var NotarizationPlugin = class {
2946
3062
  constructor() {
2947
- this._ctx = new import_context7.Context();
3063
+ this._ctx = new import_context8.Context();
2948
3064
  this._extensionOpened = new import_async11.Event();
2949
3065
  this._extensions = /* @__PURE__ */ new Set();
2950
3066
  this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
@@ -3069,7 +3185,7 @@ var NotarizationPlugin = class {
3069
3185
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3070
3186
  try {
3071
3187
  await Promise.race([
3072
- (0, import_context7.rejectOnDispose)(ctx),
3188
+ (0, import_context8.rejectOnDispose)(ctx),
3073
3189
  allNotarized,
3074
3190
  errors.wait()
3075
3191
  ]);
@@ -3209,7 +3325,7 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3209
3325
  var ENABLE_FEED_PURGE = false;
3210
3326
  var DataSpace = class {
3211
3327
  constructor(params) {
3212
- this._ctx = new import_context6.Context();
3328
+ this._ctx = new import_context7.Context();
3213
3329
  this._notarizationPlugin = new NotarizationPlugin();
3214
3330
  this._cache = void 0;
3215
3331
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
@@ -3285,7 +3401,7 @@ var DataSpace = class {
3285
3401
  await this._notarizationPlugin.open();
3286
3402
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3287
3403
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3288
- await this._inner.open(new import_context6.Context());
3404
+ await this._inner.open(new import_context7.Context());
3289
3405
  this._state = import_services9.SpaceState.CONTROL_ONLY;
3290
3406
  (0, import_log9.log)("new state", {
3291
3407
  state: import_services9.SpaceState[this._state]
@@ -3314,7 +3430,7 @@ var DataSpace = class {
3314
3430
  C: (f, a) => f(...a)
3315
3431
  });
3316
3432
  await this._ctx.dispose();
3317
- this._ctx = new import_context6.Context();
3433
+ this._ctx = new import_context7.Context();
3318
3434
  await this.authVerifier.close();
3319
3435
  await this._inner.close();
3320
3436
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3338,7 +3454,7 @@ var DataSpace = class {
3338
3454
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3339
3455
  await this.initializeDataPipeline();
3340
3456
  } catch (err) {
3341
- if (err instanceof import_protocols8.CancelledError || err instanceof import_context6.ContextDisposedError) {
3457
+ if (err instanceof import_protocols8.CancelledError || err instanceof import_context7.ContextDisposedError) {
3342
3458
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3343
3459
  F: __dxlog_file12,
3344
3460
  L: 250,
@@ -3384,12 +3500,13 @@ var DataSpace = class {
3384
3500
  });
3385
3501
  await this._initializeAndReadControlPipeline();
3386
3502
  await (0, import_async10.sleep)(1);
3503
+ this._automergeSpaceState.startProcessingRootDocs();
3387
3504
  await this._inner.initializeDataPipeline();
3388
3505
  this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3389
- await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3506
+ await (0, import_context7.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3390
3507
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
3391
3508
  F: __dxlog_file12,
3392
- L: 286,
3509
+ L: 288,
3393
3510
  S: this,
3394
3511
  C: (f, a) => f(...a)
3395
3512
  });
@@ -3400,7 +3517,7 @@ var DataSpace = class {
3400
3517
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3401
3518
  (0, import_log9.log)("data pipeline ready", void 0, {
3402
3519
  F: __dxlog_file12,
3403
- L: 294,
3520
+ L: 296,
3404
3521
  S: this,
3405
3522
  C: (f, a) => f(...a)
3406
3523
  });
@@ -3410,7 +3527,7 @@ var DataSpace = class {
3410
3527
  state: import_services9.SpaceState[this._state]
3411
3528
  }, {
3412
3529
  F: __dxlog_file12,
3413
- L: 298,
3530
+ L: 300,
3414
3531
  S: this,
3415
3532
  C: (f, a) => f(...a)
3416
3533
  });
@@ -3426,7 +3543,7 @@ var DataSpace = class {
3426
3543
  await this._createWritableFeeds();
3427
3544
  (0, import_log9.log)("writable feeds created", void 0, {
3428
3545
  F: __dxlog_file12,
3429
- L: 314,
3546
+ L: 316,
3430
3547
  S: this,
3431
3548
  C: (f, a) => f(...a)
3432
3549
  });
@@ -3489,7 +3606,7 @@ var DataSpace = class {
3489
3606
  rootUrl
3490
3607
  }, {
3491
3608
  F: __dxlog_file12,
3492
- L: 380,
3609
+ L: 382,
3493
3610
  S: this,
3494
3611
  C: (f, a) => f(...a)
3495
3612
  });
@@ -3498,7 +3615,7 @@ var DataSpace = class {
3498
3615
  queueMicrotask(async () => {
3499
3616
  try {
3500
3617
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3501
- await (0, import_context6.cancelWithContext)(this._ctx, handle.whenReady());
3618
+ await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3502
3619
  });
3503
3620
  if (this._ctx.disposed) {
3504
3621
  return;
@@ -3512,7 +3629,7 @@ var DataSpace = class {
3512
3629
  });
3513
3630
  }
3514
3631
  } catch (err) {
3515
- if (err instanceof import_context6.ContextDisposedError) {
3632
+ if (err instanceof import_context7.ContextDisposedError) {
3516
3633
  return;
3517
3634
  }
3518
3635
  import_log9.log.warn("error loading automerge root doc", {
@@ -3521,7 +3638,7 @@ var DataSpace = class {
3521
3638
  err
3522
3639
  }, {
3523
3640
  F: __dxlog_file12,
3524
- L: 403,
3641
+ L: 405,
3525
3642
  S: this,
3526
3643
  C: (f, a) => f(...a)
3527
3644
  });
@@ -3552,15 +3669,40 @@ var DataSpace = class {
3552
3669
  epoch = await this.dataPipeline.createEpoch();
3553
3670
  }
3554
3671
  break;
3555
- case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3556
- const document = this._automergeHost.repo.create();
3557
- epoch = {
3558
- previousId: this._automergeSpaceState.lastEpoch?.id,
3559
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3560
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3561
- automergeRoot: document.url
3562
- };
3563
- }
3672
+ case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3673
+ {
3674
+ const document = this._automergeHost.repo.create();
3675
+ epoch = {
3676
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3677
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3678
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3679
+ automergeRoot: document.url
3680
+ };
3681
+ }
3682
+ break;
3683
+ case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3684
+ {
3685
+ const currentRootUrl = this._automergeSpaceState.rootUrl;
3686
+ const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3687
+ await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3688
+ const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3689
+ (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3690
+ F: __dxlog_file12,
3691
+ L: 450,
3692
+ S: this,
3693
+ A: [
3694
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3695
+ ""
3696
+ ]
3697
+ });
3698
+ epoch = {
3699
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3700
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3701
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3702
+ automergeRoot: newRoot.url
3703
+ };
3704
+ }
3705
+ break;
3564
3706
  }
3565
3707
  if (!epoch) {
3566
3708
  return;
@@ -3611,7 +3753,7 @@ var DataSpace = class {
3611
3753
  state: import_services9.SpaceState[this._state]
3612
3754
  }, {
3613
3755
  F: __dxlog_file12,
3614
- L: 492,
3756
+ L: 514,
3615
3757
  S: this,
3616
3758
  C: (f, a) => f(...a)
3617
3759
  });
@@ -3749,7 +3891,7 @@ var DataSpaceManager = class {
3749
3891
  this._signingContext = _signingContext;
3750
3892
  this._feedStore = _feedStore;
3751
3893
  this._automergeHost = _automergeHost;
3752
- this._ctx = new import_context8.Context();
3894
+ this._ctx = new import_context9.Context();
3753
3895
  this.updated = new import_async12.Event();
3754
3896
  this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3755
3897
  this._isOpen = false;
@@ -3938,7 +4080,7 @@ var DataSpaceManager = class {
3938
4080
  * TODO(dmaretskyi): Consider removing.
3939
4081
  */
3940
4082
  async waitUntilSpaceReady(spaceKey) {
3941
- await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4083
+ await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3942
4084
  const space = this._spaces.get(spaceKey);
3943
4085
  return !!space && space.state === import_services10.SpaceState.READY;
3944
4086
  }));
@@ -4238,10 +4380,12 @@ var SpacesServiceImpl = class {
4238
4380
  }
4239
4381
  }
4240
4382
  }
4241
- async createEpoch({ spaceKey }) {
4383
+ async createEpoch({ spaceKey, migration }) {
4242
4384
  const dataSpaceManager = await this._getDataSpaceManager();
4243
4385
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4244
- await space.createEpoch();
4386
+ await space.createEpoch({
4387
+ migration
4388
+ });
4245
4389
  }
4246
4390
  _serializeSpace(space) {
4247
4391
  return {
@@ -4306,6 +4450,9 @@ var ServiceContext = class {
4306
4450
  this._handlerFactories = /* @__PURE__ */ new Map();
4307
4451
  this._instanceId = import_keys10.PublicKey.random().toHex();
4308
4452
  this.metadataStore = new import_echo_pipeline2.MetadataStore(storage.createDirectory("metadata"));
4453
+ this.indexMetadata = new import_echo_schema.IndexMetadataStore({
4454
+ directory: storage.createDirectory("index-metadata")
4455
+ });
4309
4456
  this.snapshotStore = new import_echo_pipeline2.SnapshotStore(storage.createDirectory("snapshots"));
4310
4457
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4311
4458
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
@@ -4328,7 +4475,10 @@ var ServiceContext = class {
4328
4475
  snapshotStore: this.snapshotStore
4329
4476
  });
4330
4477
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4331
- this.automergeHost = new import_echo_pipeline2.AutomergeHost(storage.createDirectory("automerge"));
4478
+ this.automergeHost = new import_echo_pipeline2.AutomergeHost({
4479
+ directory: storage.createDirectory("automerge"),
4480
+ metadata: this.indexMetadata
4481
+ });
4332
4482
  this.invitations = new InvitationsHandler(this.networkManager);
4333
4483
  this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4334
4484
  }
@@ -4336,7 +4486,7 @@ var ServiceContext = class {
4336
4486
  await this._checkStorageVersion();
4337
4487
  (0, import_log13.log)("opening...", void 0, {
4338
4488
  F: __dxlog_file15,
4339
- L: 146,
4489
+ L: 152,
4340
4490
  S: this,
4341
4491
  C: (f, a) => f(...a)
4342
4492
  });
@@ -4344,7 +4494,7 @@ var ServiceContext = class {
4344
4494
  id: this._instanceId
4345
4495
  }), {
4346
4496
  F: __dxlog_file15,
4347
- L: 147,
4497
+ L: 153,
4348
4498
  S: this,
4349
4499
  C: (f, a) => f(...a)
4350
4500
  });
@@ -4360,13 +4510,13 @@ var ServiceContext = class {
4360
4510
  id: this._instanceId
4361
4511
  }), {
4362
4512
  F: __dxlog_file15,
4363
- L: 157,
4513
+ L: 163,
4364
4514
  S: this,
4365
4515
  C: (f, a) => f(...a)
4366
4516
  });
4367
4517
  (0, import_log13.log)("opened", void 0, {
4368
4518
  F: __dxlog_file15,
4369
- L: 158,
4519
+ L: 164,
4370
4520
  S: this,
4371
4521
  C: (f, a) => f(...a)
4372
4522
  });
@@ -4374,7 +4524,7 @@ var ServiceContext = class {
4374
4524
  async close() {
4375
4525
  (0, import_log13.log)("closing...", void 0, {
4376
4526
  F: __dxlog_file15,
4377
- L: 162,
4527
+ L: 168,
4378
4528
  S: this,
4379
4529
  C: (f, a) => f(...a)
4380
4530
  });
@@ -4392,21 +4542,21 @@ var ServiceContext = class {
4392
4542
  await this.metadataStore.close();
4393
4543
  (0, import_log13.log)("closed", void 0, {
4394
4544
  F: __dxlog_file15,
4395
- L: 175,
4545
+ L: 181,
4396
4546
  S: this,
4397
4547
  C: (f, a) => f(...a)
4398
4548
  });
4399
4549
  }
4400
4550
  async createIdentity(params = {}) {
4401
4551
  const identity = await this.identityManager.createIdentity(params);
4402
- await this._initialize(new import_context9.Context());
4552
+ await this._initialize(new import_context10.Context());
4403
4553
  return identity;
4404
4554
  }
4405
4555
  getInvitationHandler(invitation) {
4406
4556
  const factory = this._handlerFactories.get(invitation.kind);
4407
4557
  (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4408
4558
  F: __dxlog_file15,
4409
- L: 186,
4559
+ L: 192,
4410
4560
  S: this,
4411
4561
  A: [
4412
4562
  "factory",
@@ -4425,7 +4575,7 @@ var ServiceContext = class {
4425
4575
  }
4426
4576
  async _acceptIdentity(params) {
4427
4577
  const identity = await this.identityManager.acceptIdentity(params);
4428
- await this._initialize(new import_context9.Context());
4578
+ await this._initialize(new import_context10.Context());
4429
4579
  return identity;
4430
4580
  }
4431
4581
  async _checkStorageVersion() {
@@ -4438,7 +4588,7 @@ var ServiceContext = class {
4438
4588
  async _initialize(ctx) {
4439
4589
  (0, import_log13.log)("initializing spaces...", void 0, {
4440
4590
  F: __dxlog_file15,
4441
- L: 217,
4591
+ L: 223,
4442
4592
  S: this,
4443
4593
  C: (f, a) => f(...a)
4444
4594
  });
@@ -4461,7 +4611,7 @@ var ServiceContext = class {
4461
4611
  this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4462
4612
  (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4463
4613
  F: __dxlog_file15,
4464
- L: 242,
4614
+ L: 248,
4465
4615
  S: this,
4466
4616
  A: [
4467
4617
  "this.dataSpaceManager",
@@ -4485,7 +4635,7 @@ var ServiceContext = class {
4485
4635
  details: assertion
4486
4636
  }, {
4487
4637
  F: __dxlog_file15,
4488
- L: 258,
4638
+ L: 264,
4489
4639
  S: this,
4490
4640
  C: (f, a) => f(...a)
4491
4641
  });
@@ -4496,7 +4646,7 @@ var ServiceContext = class {
4496
4646
  details: assertion
4497
4647
  }, {
4498
4648
  F: __dxlog_file15,
4499
- L: 262,
4649
+ L: 268,
4500
4650
  S: this,
4501
4651
  C: (f, a) => f(...a)
4502
4652
  });
@@ -4507,7 +4657,7 @@ var ServiceContext = class {
4507
4657
  details: assertion
4508
4658
  }, {
4509
4659
  F: __dxlog_file15,
4510
- L: 267,
4660
+ L: 273,
4511
4661
  S: this,
4512
4662
  C: (f, a) => f(...a)
4513
4663
  });
@@ -4518,7 +4668,7 @@ var ServiceContext = class {
4518
4668
  } catch (err) {
4519
4669
  import_log13.log.catch(err, void 0, {
4520
4670
  F: __dxlog_file15,
4521
- L: 273,
4671
+ L: 279,
4522
4672
  S: this,
4523
4673
  C: (f, a) => f(...a)
4524
4674
  });
@@ -4735,7 +4885,8 @@ var DevicesServiceImpl = class {
4735
4885
  var LoggingServiceImpl = class {
4736
4886
  constructor() {
4737
4887
  this._logs = new import_async17.Event();
4738
- this._started = /* @__PURE__ */ new Date();
4888
+ this._started = Date.now();
4889
+ this._sessionId = import_keys12.PublicKey.random().toHex();
4739
4890
  this._logProcessor = (_config, entry2) => {
4740
4891
  this._logs.emit(entry2);
4741
4892
  };
@@ -4811,7 +4962,12 @@ var LoggingServiceImpl = class {
4811
4962
  meta: {
4812
4963
  // TODO(dmaretskyi): Fix proto.
4813
4964
  file: entry2.meta?.F ?? "",
4814
- line: entry2.meta?.L ?? 0
4965
+ line: entry2.meta?.L ?? 0,
4966
+ scope: {
4967
+ hostSessionId: this._sessionId,
4968
+ uptimeSeconds: (Date.now() - this._started) / 1e3,
4969
+ name: (0, import_util10.getDebugName)(entry2.meta?.S)
4970
+ }
4815
4971
  }
4816
4972
  };
4817
4973
  try {
@@ -4970,7 +5126,7 @@ var ClientServicesHost = class {
4970
5126
  lockKey,
4971
5127
  onAcquire: () => {
4972
5128
  if (!this._opening) {
4973
- void this.open(new import_context10.Context());
5129
+ void this.open(new import_context11.Context());
4974
5130
  }
4975
5131
  },
4976
5132
  onRelease: () => this.close()
@@ -5143,7 +5299,7 @@ var ClientServicesHost = class {
5143
5299
  this._serviceRegistry.setServices({
5144
5300
  SystemService: this._systemService,
5145
5301
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5146
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
5302
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5147
5303
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5148
5304
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
5149
5305
  await this._serviceContext.initialized.wait();
@@ -5161,6 +5317,24 @@ var ClientServicesHost = class {
5161
5317
  })
5162
5318
  });
5163
5319
  await this._serviceContext.open(ctx);
5320
+ (0, import_invariant16.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5321
+ F: __dxlog_file18,
5322
+ L: 297,
5323
+ S: this,
5324
+ A: [
5325
+ "this.serviceRegistry.services.InvitationsService",
5326
+ ""
5327
+ ]
5328
+ });
5329
+ const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5330
+ (0, import_log15.log)("loaded persistent invitations", {
5331
+ count: loadedInvitations.invitations?.length
5332
+ }, {
5333
+ F: __dxlog_file18,
5334
+ L: 300,
5335
+ S: this,
5336
+ C: (f, a) => f(...a)
5337
+ });
5164
5338
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5165
5339
  if (devtoolsProxy) {
5166
5340
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
@@ -5179,7 +5353,7 @@ var ClientServicesHost = class {
5179
5353
  deviceKey
5180
5354
  }, {
5181
5355
  F: __dxlog_file18,
5182
- L: 310,
5356
+ L: 317,
5183
5357
  S: this,
5184
5358
  C: (f, a) => f(...a)
5185
5359
  });
@@ -5187,7 +5361,7 @@ var ClientServicesHost = class {
5187
5361
  id: traceId
5188
5362
  }), {
5189
5363
  F: __dxlog_file18,
5190
- L: 311,
5364
+ L: 318,
5191
5365
  S: this,
5192
5366
  C: (f, a) => f(...a)
5193
5367
  });
@@ -5201,7 +5375,7 @@ var ClientServicesHost = class {
5201
5375
  deviceKey
5202
5376
  }, {
5203
5377
  F: __dxlog_file18,
5204
- L: 322,
5378
+ L: 329,
5205
5379
  S: this,
5206
5380
  C: (f, a) => f(...a)
5207
5381
  });
@@ -5217,7 +5391,7 @@ var ClientServicesHost = class {
5217
5391
  deviceKey
5218
5392
  }, {
5219
5393
  F: __dxlog_file18,
5220
- L: 329,
5394
+ L: 336,
5221
5395
  S: this,
5222
5396
  C: (f, a) => f(...a)
5223
5397
  });
@@ -5228,13 +5402,13 @@ var ClientServicesHost = class {
5228
5402
  id: traceId
5229
5403
  }), {
5230
5404
  F: __dxlog_file18,
5231
- L: 334,
5405
+ L: 341,
5232
5406
  S: this,
5233
5407
  C: (f, a) => f(...a)
5234
5408
  });
5235
5409
  (0, import_log15.log)("resetting...", void 0, {
5236
5410
  F: __dxlog_file18,
5237
- L: 336,
5411
+ L: 343,
5238
5412
  S: this,
5239
5413
  C: (f, a) => f(...a)
5240
5414
  });
@@ -5242,7 +5416,7 @@ var ClientServicesHost = class {
5242
5416
  await this._storage.reset();
5243
5417
  (0, import_log15.log)("reset", void 0, {
5244
5418
  F: __dxlog_file18,
5245
- L: 339,
5419
+ L: 346,
5246
5420
  S: this,
5247
5421
  C: (f, a) => f(...a)
5248
5422
  });
@@ -5250,7 +5424,7 @@ var ClientServicesHost = class {
5250
5424
  id: traceId
5251
5425
  }), {
5252
5426
  F: __dxlog_file18,
5253
- L: 340,
5427
+ L: 347,
5254
5428
  S: this,
5255
5429
  C: (f, a) => f(...a)
5256
5430
  });
@@ -5265,7 +5439,7 @@ var ClientServicesHost = class {
5265
5439
  const automergeIndex = space.automergeSpaceState.rootUrl;
5266
5440
  (0, import_invariant16.invariant)(automergeIndex, void 0, {
5267
5441
  F: __dxlog_file18,
5268
- L: 355,
5442
+ L: 362,
5269
5443
  S: this,
5270
5444
  A: [
5271
5445
  "automergeIndex",
@@ -5277,8 +5451,8 @@ var ClientServicesHost = class {
5277
5451
  document.change((doc) => {
5278
5452
  (0, import_util9.assignDeep)(doc, [
5279
5453
  "objects",
5280
- (0, import_echo_schema.getAutomergeObjectCore)(obj).id
5281
- ], (0, import_echo_schema.getRawDoc)(obj).handle.docSync());
5454
+ (0, import_echo_schema2.getAutomergeObjectCore)(obj).id
5455
+ ], (0, import_echo_schema2.getRawDoc)(obj).handle.docSync());
5282
5456
  });
5283
5457
  return identity;
5284
5458
  }
@@ -5325,6 +5499,7 @@ ClientServicesHost = _ts_decorate8([
5325
5499
  createDiagnostics,
5326
5500
  createStorageObjects,
5327
5501
  getNetworkPeers,
5502
+ invitationExpired,
5328
5503
  isLocked,
5329
5504
  subscribeToFeedBlocks,
5330
5505
  subscribeToFeeds,
@@ -5334,4 +5509,4 @@ ClientServicesHost = _ts_decorate8([
5334
5509
  subscribeToSpaces,
5335
5510
  subscribeToSwarmInfo
5336
5511
  });
5337
- //# sourceMappingURL=chunk-RG6HMYQS.cjs.map
5512
+ //# sourceMappingURL=chunk-65WPTUZO.cjs.map