@dxos/client-services 0.4.7-next.f4b92be → 0.4.8-main.27faba7

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 (37) hide show
  1. package/dist/lib/browser/{chunk-NTKD4OQC.mjs → chunk-5HE3KN6U.mjs} +303 -136
  2. package/dist/lib/browser/chunk-5HE3KN6U.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-GCIW4VHF.cjs → chunk-7CW4ADHU.cjs} +273 -105
  8. package/dist/lib/node/chunk-7CW4ADHU.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +39 -37
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -0
  14. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-service.d.ts +9 -1
  16. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -0
  18. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  20. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  21. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  24. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  25. package/dist/types/src/version.d.ts +1 -1
  26. package/package.json +35 -35
  27. package/src/packlets/identity/identity-manager.ts +1 -1
  28. package/src/packlets/invitations/invitations-handler.ts +37 -2
  29. package/src/packlets/invitations/invitations-service.ts +83 -5
  30. package/src/packlets/logging/logging-service.ts +9 -2
  31. package/src/packlets/services/service-host.ts +9 -2
  32. package/src/packlets/spaces/automerge-space-state.ts +15 -0
  33. package/src/packlets/spaces/data-space.ts +33 -11
  34. package/src/packlets/spaces/spaces-service.ts +2 -2
  35. package/src/version.ts +1 -1
  36. package/dist/lib/browser/chunk-NTKD4OQC.mjs.map +0 -7
  37. package/dist/lib/node/chunk-GCIW4VHF.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_GCIW4VHF_exports = {};
30
- __export(chunk_GCIW4VHF_exports, {
29
+ var chunk_7CW4ADHU_exports = {};
30
+ __export(chunk_7CW4ADHU_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -51,6 +51,7 @@ __export(chunk_GCIW4VHF_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_GCIW4VHF_exports, {
60
61
  subscribeToSpaces: () => subscribeToSpaces,
61
62
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
63
  });
63
- module.exports = __toCommonJS(chunk_GCIW4VHF_exports);
64
+ module.exports = __toCommonJS(chunk_7CW4ADHU_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,7 +203,7 @@ 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");
@@ -226,7 +228,7 @@ var import_random_access_storage = require("@dxos/random-access-storage");
226
228
  var import_util8 = require("@dxos/util");
227
229
  var import_async15 = require("@dxos/async");
228
230
  var import_client_protocol5 = require("@dxos/client-protocol");
229
- var import_context10 = require("@dxos/context");
231
+ var import_context11 = require("@dxos/context");
230
232
  var import_document_model2 = require("@dxos/document-model");
231
233
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
232
234
  var import_echo_schema2 = require("@dxos/echo-schema");
@@ -248,6 +250,7 @@ var import_invariant17 = require("@dxos/invariant");
248
250
  var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
249
251
  var import_async17 = require("@dxos/async");
250
252
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
253
+ var import_keys12 = require("@dxos/keys");
251
254
  var import_log16 = require("@dxos/log");
252
255
  var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
253
256
  var import_util10 = require("@dxos/util");
@@ -1229,7 +1232,7 @@ var IdentityManager = class {
1229
1232
  identityKey: identityRecord.identityKey
1230
1233
  });
1231
1234
  await space.setControlFeed(controlFeed);
1232
- void space.setDataFeed(dataFeed);
1235
+ await space.setDataFeed(dataFeed);
1233
1236
  const identity = new Identity({
1234
1237
  space,
1235
1238
  presence,
@@ -1787,11 +1790,11 @@ var InvitationsHandler = class {
1787
1790
  this._networkManager = _networkManager;
1788
1791
  }
1789
1792
  createInvitation(protocol, options) {
1790
- 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 ?? {};
1791
1794
  const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1792
1795
  (0, import_invariant5.invariant)(protocol, void 0, {
1793
1796
  F: __dxlog_file7,
1794
- L: 81,
1797
+ L: 84,
1795
1798
  S: this,
1796
1799
  A: [
1797
1800
  "protocol",
@@ -1806,13 +1809,16 @@ var InvitationsHandler = class {
1806
1809
  swarmKey,
1807
1810
  authCode,
1808
1811
  timeout,
1812
+ persistent,
1813
+ created,
1814
+ lifetime,
1809
1815
  ...protocol.getInvitationContext()
1810
1816
  };
1811
1817
  const stream = new import_async7.PushStream();
1812
1818
  const ctx = new import_context4.Context({
1813
1819
  onError: (err) => {
1814
- void ctx.dispose();
1815
1820
  stream.error(err);
1821
+ void ctx.dispose();
1816
1822
  }
1817
1823
  });
1818
1824
  ctx.onDispose(() => {
@@ -1820,7 +1826,7 @@ var InvitationsHandler = class {
1820
1826
  ...protocol.toJSON()
1821
1827
  }, {
1822
1828
  F: __dxlog_file7,
1823
- L: 103,
1829
+ L: 109,
1824
1830
  S: this,
1825
1831
  C: (f, a) => f(...a)
1826
1832
  });
@@ -1845,7 +1851,7 @@ var InvitationsHandler = class {
1845
1851
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1846
1852
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1847
1853
  F: __dxlog_file7,
1848
- L: 124,
1854
+ L: 130,
1849
1855
  S: this,
1850
1856
  A: [
1851
1857
  "deviceKey",
@@ -1868,7 +1874,7 @@ var InvitationsHandler = class {
1868
1874
  id: traceId
1869
1875
  }), {
1870
1876
  F: __dxlog_file7,
1871
- L: 142,
1877
+ L: 148,
1872
1878
  S: this,
1873
1879
  C: (f, a) => f(...a)
1874
1880
  });
@@ -1876,7 +1882,7 @@ var InvitationsHandler = class {
1876
1882
  ...protocol.toJSON()
1877
1883
  }, {
1878
1884
  F: __dxlog_file7,
1879
- L: 143,
1885
+ L: 149,
1880
1886
  S: this,
1881
1887
  C: (f, a) => f(...a)
1882
1888
  });
@@ -1892,7 +1898,7 @@ var InvitationsHandler = class {
1892
1898
  ...protocol.toJSON()
1893
1899
  }, {
1894
1900
  F: __dxlog_file7,
1895
- L: 146,
1901
+ L: 152,
1896
1902
  S: this,
1897
1903
  C: (f, a) => f(...a)
1898
1904
  });
@@ -1904,7 +1910,7 @@ var InvitationsHandler = class {
1904
1910
  id: traceId
1905
1911
  }), {
1906
1912
  F: __dxlog_file7,
1907
- L: 148,
1913
+ L: 154,
1908
1914
  S: this,
1909
1915
  C: (f, a) => f(...a)
1910
1916
  });
@@ -1914,7 +1920,7 @@ var InvitationsHandler = class {
1914
1920
  ...protocol.toJSON()
1915
1921
  }, {
1916
1922
  F: __dxlog_file7,
1917
- L: 151,
1923
+ L: 157,
1918
1924
  S: this,
1919
1925
  C: (f, a) => f(...a)
1920
1926
  });
@@ -1925,7 +1931,7 @@ var InvitationsHandler = class {
1925
1931
  } else {
1926
1932
  import_log4.log.error("failed", err, {
1927
1933
  F: __dxlog_file7,
1928
- L: 154,
1934
+ L: 160,
1929
1935
  S: this,
1930
1936
  C: (f, a) => f(...a)
1931
1937
  });
@@ -1936,7 +1942,7 @@ var InvitationsHandler = class {
1936
1942
  error: err
1937
1943
  }), {
1938
1944
  F: __dxlog_file7,
1939
- L: 157,
1945
+ L: 163,
1940
1946
  S: this,
1941
1947
  C: (f, a) => f(...a)
1942
1948
  });
@@ -1957,7 +1963,7 @@ var InvitationsHandler = class {
1957
1963
  ...protocol.toJSON()
1958
1964
  }, {
1959
1965
  F: __dxlog_file7,
1960
- L: 172,
1966
+ L: 178,
1961
1967
  S: this,
1962
1968
  C: (f, a) => f(...a)
1963
1969
  });
@@ -1968,7 +1974,7 @@ var InvitationsHandler = class {
1968
1974
  } else {
1969
1975
  import_log4.log.error("failed", err, {
1970
1976
  F: __dxlog_file7,
1971
- L: 175,
1977
+ L: 181,
1972
1978
  S: this,
1973
1979
  C: (f, a) => f(...a)
1974
1980
  });
@@ -1978,7 +1984,27 @@ var InvitationsHandler = class {
1978
1984
  });
1979
1985
  return extension;
1980
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
+ }
1981
2006
  let swarmConnection;
2007
+ const invitationLabel = "invitation host for " + (invitation.kind === import_services3.Invitation.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
1982
2008
  (0, import_async7.scheduleTask)(ctx, async () => {
1983
2009
  const topic = invitation.swarmKey;
1984
2010
  swarmConnection = await this._networkManager.joinSwarm({
@@ -1988,7 +2014,7 @@ var InvitationsHandler = class {
1988
2014
  teleport.addExtension("dxos.halo.invitations", createExtension());
1989
2015
  }),
1990
2016
  topology: new import_network_manager.StarTopology(topic),
1991
- label: "invitation host"
2017
+ label: invitationLabel
1992
2018
  });
1993
2019
  ctx.onDispose(() => swarmConnection.close());
1994
2020
  stream.next({
@@ -2013,7 +2039,7 @@ var InvitationsHandler = class {
2013
2039
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2014
2040
  (0, import_invariant5.invariant)(protocol, void 0, {
2015
2041
  F: __dxlog_file7,
2016
- L: 220,
2042
+ L: 246,
2017
2043
  S: this,
2018
2044
  A: [
2019
2045
  "protocol",
@@ -2023,7 +2049,7 @@ var InvitationsHandler = class {
2023
2049
  if (deviceProfile) {
2024
2050
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2025
2051
  F: __dxlog_file7,
2026
- L: 224,
2052
+ L: 250,
2027
2053
  S: this,
2028
2054
  A: [
2029
2055
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2038,7 +2064,7 @@ var InvitationsHandler = class {
2038
2064
  const setState = (newData) => {
2039
2065
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2040
2066
  F: __dxlog_file7,
2041
- L: 235,
2067
+ L: 261,
2042
2068
  S: this,
2043
2069
  A: [
2044
2070
  "newData.state !== undefined",
@@ -2058,7 +2084,7 @@ var InvitationsHandler = class {
2058
2084
  ...protocol.toJSON()
2059
2085
  }, {
2060
2086
  F: __dxlog_file7,
2061
- L: 243,
2087
+ L: 269,
2062
2088
  S: this,
2063
2089
  C: (f, a) => f(...a)
2064
2090
  });
@@ -2068,7 +2094,7 @@ var InvitationsHandler = class {
2068
2094
  } else {
2069
2095
  import_log4.log.warn("auth failed", err, {
2070
2096
  F: __dxlog_file7,
2071
- L: 246,
2097
+ L: 272,
2072
2098
  S: this,
2073
2099
  C: (f, a) => f(...a)
2074
2100
  });
@@ -2082,7 +2108,7 @@ var InvitationsHandler = class {
2082
2108
  ...protocol.toJSON()
2083
2109
  }, {
2084
2110
  F: __dxlog_file7,
2085
- L: 254,
2111
+ L: 280,
2086
2112
  S: this,
2087
2113
  C: (f, a) => f(...a)
2088
2114
  });
@@ -2097,7 +2123,7 @@ var InvitationsHandler = class {
2097
2123
  currentState
2098
2124
  }, {
2099
2125
  F: __dxlog_file7,
2100
- L: 264,
2126
+ L: 290,
2101
2127
  S: this,
2102
2128
  C: (f, a) => f(...a)
2103
2129
  });
@@ -2112,7 +2138,7 @@ var InvitationsHandler = class {
2112
2138
  id: traceId
2113
2139
  }), {
2114
2140
  F: __dxlog_file7,
2115
- L: 273,
2141
+ L: 299,
2116
2142
  S: this,
2117
2143
  C: (f, a) => f(...a)
2118
2144
  });
@@ -2124,7 +2150,7 @@ var InvitationsHandler = class {
2124
2150
  ...protocol.toJSON()
2125
2151
  }, {
2126
2152
  F: __dxlog_file7,
2127
- L: 281,
2153
+ L: 307,
2128
2154
  S: this,
2129
2155
  C: (f, a) => f(...a)
2130
2156
  });
@@ -2135,7 +2161,7 @@ var InvitationsHandler = class {
2135
2161
  ...protocol.toJSON()
2136
2162
  }, {
2137
2163
  F: __dxlog_file7,
2138
- L: 285,
2164
+ L: 311,
2139
2165
  S: this,
2140
2166
  C: (f, a) => f(...a)
2141
2167
  });
@@ -2145,7 +2171,7 @@ var InvitationsHandler = class {
2145
2171
  response: introductionResponse
2146
2172
  }, {
2147
2173
  F: __dxlog_file7,
2148
- L: 289,
2174
+ L: 315,
2149
2175
  S: this,
2150
2176
  C: (f, a) => f(...a)
2151
2177
  });
@@ -2154,7 +2180,7 @@ var InvitationsHandler = class {
2154
2180
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2155
2181
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2156
2182
  F: __dxlog_file7,
2157
- L: 295,
2183
+ L: 321,
2158
2184
  S: this,
2159
2185
  C: (f, a) => f(...a)
2160
2186
  });
@@ -2166,7 +2192,7 @@ var InvitationsHandler = class {
2166
2192
  });
2167
2193
  (0, import_log4.log)("sending authentication request", void 0, {
2168
2194
  F: __dxlog_file7,
2169
- L: 299,
2195
+ L: 325,
2170
2196
  S: this,
2171
2197
  C: (f, a) => f(...a)
2172
2198
  });
@@ -2187,7 +2213,7 @@ var InvitationsHandler = class {
2187
2213
  attempt
2188
2214
  }, {
2189
2215
  F: __dxlog_file7,
2190
- L: 310,
2216
+ L: 336,
2191
2217
  S: this,
2192
2218
  C: (f, a) => f(...a)
2193
2219
  });
@@ -2200,7 +2226,7 @@ var InvitationsHandler = class {
2200
2226
  ...protocol.toJSON()
2201
2227
  }, {
2202
2228
  F: __dxlog_file7,
2203
- L: 318,
2229
+ L: 344,
2204
2230
  S: this,
2205
2231
  C: (f, a) => f(...a)
2206
2232
  });
@@ -2212,7 +2238,7 @@ var InvitationsHandler = class {
2212
2238
  ...protocol.toJSON()
2213
2239
  }, {
2214
2240
  F: __dxlog_file7,
2215
- L: 329,
2241
+ L: 355,
2216
2242
  S: this,
2217
2243
  C: (f, a) => f(...a)
2218
2244
  });
@@ -2225,7 +2251,7 @@ var InvitationsHandler = class {
2225
2251
  id: traceId
2226
2252
  }), {
2227
2253
  F: __dxlog_file7,
2228
- L: 331,
2254
+ L: 357,
2229
2255
  S: this,
2230
2256
  C: (f, a) => f(...a)
2231
2257
  });
@@ -2235,7 +2261,7 @@ var InvitationsHandler = class {
2235
2261
  ...protocol.toJSON()
2236
2262
  }, {
2237
2263
  F: __dxlog_file7,
2238
- L: 334,
2264
+ L: 360,
2239
2265
  S: this,
2240
2266
  C: (f, a) => f(...a)
2241
2267
  });
@@ -2245,7 +2271,7 @@ var InvitationsHandler = class {
2245
2271
  } else {
2246
2272
  (0, import_log4.log)("auth failed", err, {
2247
2273
  F: __dxlog_file7,
2248
- L: 337,
2274
+ L: 363,
2249
2275
  S: this,
2250
2276
  C: (f, a) => f(...a)
2251
2277
  });
@@ -2256,7 +2282,7 @@ var InvitationsHandler = class {
2256
2282
  error: err
2257
2283
  }), {
2258
2284
  F: __dxlog_file7,
2259
- L: 340,
2285
+ L: 366,
2260
2286
  S: this,
2261
2287
  C: (f, a) => f(...a)
2262
2288
  });
@@ -2274,7 +2300,7 @@ var InvitationsHandler = class {
2274
2300
  ...protocol.toJSON()
2275
2301
  }, {
2276
2302
  F: __dxlog_file7,
2277
- L: 351,
2303
+ L: 377,
2278
2304
  S: this,
2279
2305
  C: (f, a) => f(...a)
2280
2306
  });
@@ -2284,7 +2310,7 @@ var InvitationsHandler = class {
2284
2310
  } else {
2285
2311
  (0, import_log4.log)("auth failed", err, {
2286
2312
  F: __dxlog_file7,
2287
- L: 354,
2313
+ L: 380,
2288
2314
  S: this,
2289
2315
  C: (f, a) => f(...a)
2290
2316
  });
@@ -2301,7 +2327,7 @@ var InvitationsHandler = class {
2301
2327
  } else {
2302
2328
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2303
2329
  F: __dxlog_file7,
2304
- L: 368,
2330
+ L: 394,
2305
2331
  S: this,
2306
2332
  A: [
2307
2333
  "invitation.swarmKey",
@@ -2340,17 +2366,24 @@ var InvitationsHandler = class {
2340
2366
  return observable;
2341
2367
  }
2342
2368
  };
2369
+ var invitationExpired = (invitation) => {
2370
+ return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2371
+ };
2343
2372
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2344
2373
  var InvitationsServiceImpl = class {
2345
- constructor(_invitationsHandler, _getHandler) {
2374
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2346
2375
  this._invitationsHandler = _invitationsHandler;
2347
2376
  this._getHandler = _getHandler;
2377
+ this._metadataStore = _metadataStore;
2348
2378
  this._createInvitations = /* @__PURE__ */ new Map();
2349
2379
  this._acceptInvitations = /* @__PURE__ */ new Map();
2350
2380
  this._invitationCreated = new import_async9.Event();
2351
2381
  this._invitationAccepted = new import_async9.Event();
2352
2382
  this._removedCreated = new import_async9.Event();
2353
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;
2354
2387
  }
2355
2388
  // TODO(burdon): Guest/host label.
2356
2389
  getLoggingContext() {
@@ -2358,6 +2391,7 @@ var InvitationsServiceImpl = class {
2358
2391
  }
2359
2392
  createInvitation(options) {
2360
2393
  let invitation;
2394
+ const savePersistentInvitationCtx = new import_context6.Context();
2361
2395
  const existingInvitation = this._createInvitations.get(options.invitationId);
2362
2396
  if (existingInvitation) {
2363
2397
  invitation = existingInvitation;
@@ -2368,12 +2402,27 @@ var InvitationsServiceImpl = class {
2368
2402
  this._invitationCreated.emit(invitation.get());
2369
2403
  }
2370
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
+ }
2371
2415
  invitation.subscribe((invitation2) => {
2372
2416
  next(invitation2);
2373
- }, (err) => {
2417
+ }, async (err) => {
2418
+ await savePersistentInvitationCtx.dispose();
2374
2419
  close(err);
2375
- }, () => {
2420
+ }, async () => {
2376
2421
  close();
2422
+ if (invitation.get().persistent) {
2423
+ await savePersistentInvitationCtx.dispose();
2424
+ await this._metadataStore.removeInvitation(invitation.get().invitationId);
2425
+ }
2377
2426
  this._createInvitations.delete(invitation.get().invitationId);
2378
2427
  if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2379
2428
  this._removedCreated.emit(invitation.get());
@@ -2381,12 +2430,37 @@ var InvitationsServiceImpl = class {
2381
2430
  });
2382
2431
  });
2383
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
+ }
2384
2458
  acceptInvitation({ invitation: options, deviceProfile }) {
2385
2459
  let invitation;
2386
2460
  if (deviceProfile) {
2387
2461
  (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2388
2462
  F: __dxlog_file8,
2389
- L: 81,
2463
+ L: 127,
2390
2464
  S: this,
2391
2465
  A: [
2392
2466
  "options.kind === Invitation.Kind.DEVICE",
@@ -2420,13 +2494,13 @@ var InvitationsServiceImpl = class {
2420
2494
  async authenticate({ invitationId, authCode }) {
2421
2495
  (0, import_log6.log)("authenticating...", void 0, {
2422
2496
  F: __dxlog_file8,
2423
- L: 114,
2497
+ L: 160,
2424
2498
  S: this,
2425
2499
  C: (f, a) => f(...a)
2426
2500
  });
2427
2501
  (0, import_invariant7.invariant)(invitationId, void 0, {
2428
2502
  F: __dxlog_file8,
2429
- L: 115,
2503
+ L: 161,
2430
2504
  S: this,
2431
2505
  A: [
2432
2506
  "invitationId",
@@ -2439,7 +2513,7 @@ var InvitationsServiceImpl = class {
2439
2513
  invitationId
2440
2514
  }, {
2441
2515
  F: __dxlog_file8,
2442
- L: 118,
2516
+ L: 164,
2443
2517
  S: this,
2444
2518
  C: (f, a) => f(...a)
2445
2519
  });
@@ -2448,15 +2522,17 @@ var InvitationsServiceImpl = class {
2448
2522
  }
2449
2523
  }
2450
2524
  async cancelInvitation({ invitationId }) {
2451
- (0, import_log6.log)("deleting...", void 0, {
2525
+ (0, import_log6.log)("cancelInvitation...", {
2526
+ invitationId
2527
+ }, {
2452
2528
  F: __dxlog_file8,
2453
- L: 125,
2529
+ L: 171,
2454
2530
  S: this,
2455
2531
  C: (f, a) => f(...a)
2456
2532
  });
2457
2533
  (0, import_invariant7.invariant)(invitationId, void 0, {
2458
2534
  F: __dxlog_file8,
2459
- L: 126,
2535
+ L: 172,
2460
2536
  S: this,
2461
2537
  A: [
2462
2538
  "invitationId",
@@ -2469,6 +2545,9 @@ var InvitationsServiceImpl = class {
2469
2545
  await created.cancel();
2470
2546
  this._createInvitations.delete(invitationId);
2471
2547
  this._removedCreated.emit(created.get());
2548
+ if (created.get().persistent) {
2549
+ await this._metadataStore.removeInvitation(created.get().invitationId);
2550
+ }
2472
2551
  } else if (accepted) {
2473
2552
  await accepted.cancel();
2474
2553
  this._acceptInvitations.delete(invitationId);
@@ -2513,16 +2592,40 @@ var InvitationsServiceImpl = class {
2513
2592
  ]
2514
2593
  });
2515
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
+ });
2516
2604
  next({
2517
2605
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2518
2606
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2519
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
2607
+ invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2608
+ existing: true
2520
2609
  });
2521
2610
  next({
2522
2611
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2523
2612
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2524
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
2613
+ invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2614
+ existing: true
2525
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
+ }
2526
2629
  });
2527
2630
  }
2528
2631
  };
@@ -2783,7 +2886,7 @@ var getPlatform = () => {
2783
2886
  };
2784
2887
  }
2785
2888
  };
2786
- var DXOS_VERSION = "0.4.7-next.f4b92be";
2889
+ var DXOS_VERSION = "0.4.8-main.27faba7";
2787
2890
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2788
2891
  var DEFAULT_TIMEOUT = 1e3;
2789
2892
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2926,6 +3029,7 @@ var AutomergeSpaceState = class {
2926
3029
  this._onNewRoot = _onNewRoot;
2927
3030
  this.rootUrl = void 0;
2928
3031
  this.lastEpoch = void 0;
3032
+ this._isProcessingRootDocs = false;
2929
3033
  }
2930
3034
  async processCredential(credential) {
2931
3035
  if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
@@ -2934,8 +3038,19 @@ var AutomergeSpaceState = class {
2934
3038
  this.lastEpoch = credential;
2935
3039
  if (credential.subject.assertion.automergeRoot) {
2936
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) {
2937
3051
  this._onNewRoot(this.rootUrl);
2938
3052
  }
3053
+ this._isProcessingRootDocs = true;
2939
3054
  }
2940
3055
  };
2941
3056
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
@@ -2945,7 +3060,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2945
3060
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2946
3061
  var NotarizationPlugin = class {
2947
3062
  constructor() {
2948
- this._ctx = new import_context7.Context();
3063
+ this._ctx = new import_context8.Context();
2949
3064
  this._extensionOpened = new import_async11.Event();
2950
3065
  this._extensions = /* @__PURE__ */ new Set();
2951
3066
  this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
@@ -3070,7 +3185,7 @@ var NotarizationPlugin = class {
3070
3185
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3071
3186
  try {
3072
3187
  await Promise.race([
3073
- (0, import_context7.rejectOnDispose)(ctx),
3188
+ (0, import_context8.rejectOnDispose)(ctx),
3074
3189
  allNotarized,
3075
3190
  errors.wait()
3076
3191
  ]);
@@ -3210,7 +3325,7 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3210
3325
  var ENABLE_FEED_PURGE = false;
3211
3326
  var DataSpace = class {
3212
3327
  constructor(params) {
3213
- this._ctx = new import_context6.Context();
3328
+ this._ctx = new import_context7.Context();
3214
3329
  this._notarizationPlugin = new NotarizationPlugin();
3215
3330
  this._cache = void 0;
3216
3331
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
@@ -3286,7 +3401,7 @@ var DataSpace = class {
3286
3401
  await this._notarizationPlugin.open();
3287
3402
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3288
3403
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3289
- await this._inner.open(new import_context6.Context());
3404
+ await this._inner.open(new import_context7.Context());
3290
3405
  this._state = import_services9.SpaceState.CONTROL_ONLY;
3291
3406
  (0, import_log9.log)("new state", {
3292
3407
  state: import_services9.SpaceState[this._state]
@@ -3315,7 +3430,7 @@ var DataSpace = class {
3315
3430
  C: (f, a) => f(...a)
3316
3431
  });
3317
3432
  await this._ctx.dispose();
3318
- this._ctx = new import_context6.Context();
3433
+ this._ctx = new import_context7.Context();
3319
3434
  await this.authVerifier.close();
3320
3435
  await this._inner.close();
3321
3436
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3339,7 +3454,7 @@ var DataSpace = class {
3339
3454
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3340
3455
  await this.initializeDataPipeline();
3341
3456
  } catch (err) {
3342
- if (err instanceof import_protocols8.CancelledError || err instanceof import_context6.ContextDisposedError) {
3457
+ if (err instanceof import_protocols8.CancelledError || err instanceof import_context7.ContextDisposedError) {
3343
3458
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3344
3459
  F: __dxlog_file12,
3345
3460
  L: 250,
@@ -3385,12 +3500,13 @@ var DataSpace = class {
3385
3500
  });
3386
3501
  await this._initializeAndReadControlPipeline();
3387
3502
  await (0, import_async10.sleep)(1);
3503
+ this._automergeSpaceState.startProcessingRootDocs();
3388
3504
  await this._inner.initializeDataPipeline();
3389
3505
  this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3390
- await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3506
+ await (0, import_context7.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3391
3507
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
3392
3508
  F: __dxlog_file12,
3393
- L: 286,
3509
+ L: 288,
3394
3510
  S: this,
3395
3511
  C: (f, a) => f(...a)
3396
3512
  });
@@ -3401,7 +3517,7 @@ var DataSpace = class {
3401
3517
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3402
3518
  (0, import_log9.log)("data pipeline ready", void 0, {
3403
3519
  F: __dxlog_file12,
3404
- L: 294,
3520
+ L: 296,
3405
3521
  S: this,
3406
3522
  C: (f, a) => f(...a)
3407
3523
  });
@@ -3411,7 +3527,7 @@ var DataSpace = class {
3411
3527
  state: import_services9.SpaceState[this._state]
3412
3528
  }, {
3413
3529
  F: __dxlog_file12,
3414
- L: 298,
3530
+ L: 300,
3415
3531
  S: this,
3416
3532
  C: (f, a) => f(...a)
3417
3533
  });
@@ -3427,7 +3543,7 @@ var DataSpace = class {
3427
3543
  await this._createWritableFeeds();
3428
3544
  (0, import_log9.log)("writable feeds created", void 0, {
3429
3545
  F: __dxlog_file12,
3430
- L: 314,
3546
+ L: 316,
3431
3547
  S: this,
3432
3548
  C: (f, a) => f(...a)
3433
3549
  });
@@ -3490,7 +3606,7 @@ var DataSpace = class {
3490
3606
  rootUrl
3491
3607
  }, {
3492
3608
  F: __dxlog_file12,
3493
- L: 380,
3609
+ L: 382,
3494
3610
  S: this,
3495
3611
  C: (f, a) => f(...a)
3496
3612
  });
@@ -3499,7 +3615,7 @@ var DataSpace = class {
3499
3615
  queueMicrotask(async () => {
3500
3616
  try {
3501
3617
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3502
- await (0, import_context6.cancelWithContext)(this._ctx, handle.whenReady());
3618
+ await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3503
3619
  });
3504
3620
  if (this._ctx.disposed) {
3505
3621
  return;
@@ -3513,7 +3629,7 @@ var DataSpace = class {
3513
3629
  });
3514
3630
  }
3515
3631
  } catch (err) {
3516
- if (err instanceof import_context6.ContextDisposedError) {
3632
+ if (err instanceof import_context7.ContextDisposedError) {
3517
3633
  return;
3518
3634
  }
3519
3635
  import_log9.log.warn("error loading automerge root doc", {
@@ -3522,7 +3638,7 @@ var DataSpace = class {
3522
3638
  err
3523
3639
  }, {
3524
3640
  F: __dxlog_file12,
3525
- L: 403,
3641
+ L: 405,
3526
3642
  S: this,
3527
3643
  C: (f, a) => f(...a)
3528
3644
  });
@@ -3553,15 +3669,40 @@ var DataSpace = class {
3553
3669
  epoch = await this.dataPipeline.createEpoch();
3554
3670
  }
3555
3671
  break;
3556
- case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3557
- const document = this._automergeHost.repo.create();
3558
- epoch = {
3559
- previousId: this._automergeSpaceState.lastEpoch?.id,
3560
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3561
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3562
- automergeRoot: document.url
3563
- };
3564
- }
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;
3565
3706
  }
3566
3707
  if (!epoch) {
3567
3708
  return;
@@ -3612,7 +3753,7 @@ var DataSpace = class {
3612
3753
  state: import_services9.SpaceState[this._state]
3613
3754
  }, {
3614
3755
  F: __dxlog_file12,
3615
- L: 492,
3756
+ L: 514,
3616
3757
  S: this,
3617
3758
  C: (f, a) => f(...a)
3618
3759
  });
@@ -3750,7 +3891,7 @@ var DataSpaceManager = class {
3750
3891
  this._signingContext = _signingContext;
3751
3892
  this._feedStore = _feedStore;
3752
3893
  this._automergeHost = _automergeHost;
3753
- this._ctx = new import_context8.Context();
3894
+ this._ctx = new import_context9.Context();
3754
3895
  this.updated = new import_async12.Event();
3755
3896
  this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3756
3897
  this._isOpen = false;
@@ -3939,7 +4080,7 @@ var DataSpaceManager = class {
3939
4080
  * TODO(dmaretskyi): Consider removing.
3940
4081
  */
3941
4082
  async waitUntilSpaceReady(spaceKey) {
3942
- await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4083
+ await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3943
4084
  const space = this._spaces.get(spaceKey);
3944
4085
  return !!space && space.state === import_services10.SpaceState.READY;
3945
4086
  }));
@@ -4239,10 +4380,12 @@ var SpacesServiceImpl = class {
4239
4380
  }
4240
4381
  }
4241
4382
  }
4242
- async createEpoch({ spaceKey }) {
4383
+ async createEpoch({ spaceKey, migration }) {
4243
4384
  const dataSpaceManager = await this._getDataSpaceManager();
4244
4385
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4245
- await space.createEpoch();
4386
+ await space.createEpoch({
4387
+ migration
4388
+ });
4246
4389
  }
4247
4390
  _serializeSpace(space) {
4248
4391
  return {
@@ -4406,7 +4549,7 @@ var ServiceContext = class {
4406
4549
  }
4407
4550
  async createIdentity(params = {}) {
4408
4551
  const identity = await this.identityManager.createIdentity(params);
4409
- await this._initialize(new import_context9.Context());
4552
+ await this._initialize(new import_context10.Context());
4410
4553
  return identity;
4411
4554
  }
4412
4555
  getInvitationHandler(invitation) {
@@ -4432,7 +4575,7 @@ var ServiceContext = class {
4432
4575
  }
4433
4576
  async _acceptIdentity(params) {
4434
4577
  const identity = await this.identityManager.acceptIdentity(params);
4435
- await this._initialize(new import_context9.Context());
4578
+ await this._initialize(new import_context10.Context());
4436
4579
  return identity;
4437
4580
  }
4438
4581
  async _checkStorageVersion() {
@@ -4742,7 +4885,8 @@ var DevicesServiceImpl = class {
4742
4885
  var LoggingServiceImpl = class {
4743
4886
  constructor() {
4744
4887
  this._logs = new import_async17.Event();
4745
- this._started = /* @__PURE__ */ new Date();
4888
+ this._started = Date.now();
4889
+ this._sessionId = import_keys12.PublicKey.random().toHex();
4746
4890
  this._logProcessor = (_config, entry2) => {
4747
4891
  this._logs.emit(entry2);
4748
4892
  };
@@ -4818,7 +4962,12 @@ var LoggingServiceImpl = class {
4818
4962
  meta: {
4819
4963
  // TODO(dmaretskyi): Fix proto.
4820
4964
  file: entry2.meta?.F ?? "",
4821
- 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
+ }
4822
4971
  }
4823
4972
  };
4824
4973
  try {
@@ -4977,7 +5126,7 @@ var ClientServicesHost = class {
4977
5126
  lockKey,
4978
5127
  onAcquire: () => {
4979
5128
  if (!this._opening) {
4980
- void this.open(new import_context10.Context());
5129
+ void this.open(new import_context11.Context());
4981
5130
  }
4982
5131
  },
4983
5132
  onRelease: () => this.close()
@@ -5150,7 +5299,7 @@ var ClientServicesHost = class {
5150
5299
  this._serviceRegistry.setServices({
5151
5300
  SystemService: this._systemService,
5152
5301
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5153
- 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),
5154
5303
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5155
5304
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
5156
5305
  await this._serviceContext.initialized.wait();
@@ -5168,6 +5317,24 @@ var ClientServicesHost = class {
5168
5317
  })
5169
5318
  });
5170
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
+ });
5171
5338
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5172
5339
  if (devtoolsProxy) {
5173
5340
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
@@ -5186,7 +5353,7 @@ var ClientServicesHost = class {
5186
5353
  deviceKey
5187
5354
  }, {
5188
5355
  F: __dxlog_file18,
5189
- L: 310,
5356
+ L: 317,
5190
5357
  S: this,
5191
5358
  C: (f, a) => f(...a)
5192
5359
  });
@@ -5194,7 +5361,7 @@ var ClientServicesHost = class {
5194
5361
  id: traceId
5195
5362
  }), {
5196
5363
  F: __dxlog_file18,
5197
- L: 311,
5364
+ L: 318,
5198
5365
  S: this,
5199
5366
  C: (f, a) => f(...a)
5200
5367
  });
@@ -5208,7 +5375,7 @@ var ClientServicesHost = class {
5208
5375
  deviceKey
5209
5376
  }, {
5210
5377
  F: __dxlog_file18,
5211
- L: 322,
5378
+ L: 329,
5212
5379
  S: this,
5213
5380
  C: (f, a) => f(...a)
5214
5381
  });
@@ -5224,7 +5391,7 @@ var ClientServicesHost = class {
5224
5391
  deviceKey
5225
5392
  }, {
5226
5393
  F: __dxlog_file18,
5227
- L: 329,
5394
+ L: 336,
5228
5395
  S: this,
5229
5396
  C: (f, a) => f(...a)
5230
5397
  });
@@ -5235,13 +5402,13 @@ var ClientServicesHost = class {
5235
5402
  id: traceId
5236
5403
  }), {
5237
5404
  F: __dxlog_file18,
5238
- L: 334,
5405
+ L: 341,
5239
5406
  S: this,
5240
5407
  C: (f, a) => f(...a)
5241
5408
  });
5242
5409
  (0, import_log15.log)("resetting...", void 0, {
5243
5410
  F: __dxlog_file18,
5244
- L: 336,
5411
+ L: 343,
5245
5412
  S: this,
5246
5413
  C: (f, a) => f(...a)
5247
5414
  });
@@ -5249,7 +5416,7 @@ var ClientServicesHost = class {
5249
5416
  await this._storage.reset();
5250
5417
  (0, import_log15.log)("reset", void 0, {
5251
5418
  F: __dxlog_file18,
5252
- L: 339,
5419
+ L: 346,
5253
5420
  S: this,
5254
5421
  C: (f, a) => f(...a)
5255
5422
  });
@@ -5257,7 +5424,7 @@ var ClientServicesHost = class {
5257
5424
  id: traceId
5258
5425
  }), {
5259
5426
  F: __dxlog_file18,
5260
- L: 340,
5427
+ L: 347,
5261
5428
  S: this,
5262
5429
  C: (f, a) => f(...a)
5263
5430
  });
@@ -5272,7 +5439,7 @@ var ClientServicesHost = class {
5272
5439
  const automergeIndex = space.automergeSpaceState.rootUrl;
5273
5440
  (0, import_invariant16.invariant)(automergeIndex, void 0, {
5274
5441
  F: __dxlog_file18,
5275
- L: 355,
5442
+ L: 362,
5276
5443
  S: this,
5277
5444
  A: [
5278
5445
  "automergeIndex",
@@ -5332,6 +5499,7 @@ ClientServicesHost = _ts_decorate8([
5332
5499
  createDiagnostics,
5333
5500
  createStorageObjects,
5334
5501
  getNetworkPeers,
5502
+ invitationExpired,
5335
5503
  isLocked,
5336
5504
  subscribeToFeedBlocks,
5337
5505
  subscribeToFeeds,
@@ -5341,4 +5509,4 @@ ClientServicesHost = _ts_decorate8([
5341
5509
  subscribeToSpaces,
5342
5510
  subscribeToSwarmInfo
5343
5511
  });
5344
- //# sourceMappingURL=chunk-GCIW4VHF.cjs.map
5512
+ //# sourceMappingURL=chunk-7CW4ADHU.cjs.map