@dxos/client-services 0.4.10-next.71cec10 → 0.5.0

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 (51) hide show
  1. package/dist/lib/browser/{chunk-5U7G5S73.mjs → chunk-ESEYLOPB.mjs} +355 -287
  2. package/dist/lib/browser/chunk-ESEYLOPB.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +125 -112
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-Y3ADPF24.cjs → chunk-GA7JFIXK.cjs} +445 -377
  8. package/dist/lib/node/chunk-GA7JFIXK.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +43 -43
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +125 -115
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  14. package/dist/types/src/packlets/indexing/util.d.ts +0 -5
  15. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  19. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  21. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +9 -7
  23. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  26. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -1
  29. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  30. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  31. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -0
  32. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  33. package/dist/types/src/version.d.ts +1 -1
  34. package/dist/types/src/version.d.ts.map +1 -1
  35. package/package.json +34 -34
  36. package/src/packlets/identity/identity-manager.ts +1 -0
  37. package/src/packlets/identity/identity.test.ts +3 -0
  38. package/src/packlets/indexing/util.ts +1 -65
  39. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  40. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  41. package/src/packlets/invitations/invitations-handler.ts +10 -71
  42. package/src/packlets/invitations/invitations-manager.ts +114 -40
  43. package/src/packlets/invitations/invitations-service.ts +4 -2
  44. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  45. package/src/packlets/services/service-context.ts +3 -2
  46. package/src/packlets/spaces/data-space-manager.ts +48 -2
  47. package/src/packlets/testing/invitation-utils.ts +100 -97
  48. package/src/packlets/testing/test-builder.ts +19 -1
  49. package/src/version.ts +5 -1
  50. package/dist/lib/browser/chunk-5U7G5S73.mjs.map +0 -7
  51. package/dist/lib/node/chunk-Y3ADPF24.cjs.map +0 -7
@@ -1086,7 +1086,9 @@ var IdentityManager = class {
1086
1086
  C: (f, a) => f(...a)
1087
1087
  });
1088
1088
  },
1089
- memberKey: identityKey
1089
+ memberKey: identityKey,
1090
+ onDelegatedInvitationStatusChange: async () => {
1091
+ }
1090
1092
  });
1091
1093
  }
1092
1094
  };
@@ -1194,10 +1196,13 @@ var DeviceInvitationProtocol = class {
1194
1196
  kind: Invitation.Kind.DEVICE
1195
1197
  };
1196
1198
  }
1197
- async admit(request) {
1199
+ async delegate(invitation) {
1200
+ throw new Error("delegation not supported");
1201
+ }
1202
+ async admit(_, request) {
1198
1203
  invariant4(request.device, void 0, {
1199
1204
  F: __dxlog_file5,
1200
- L: 37,
1205
+ L: 42,
1201
1206
  S: this,
1202
1207
  A: [
1203
1208
  "request.device",
@@ -1243,7 +1248,7 @@ var DeviceInvitationProtocol = class {
1243
1248
  async accept(response, request) {
1244
1249
  invariant4(response.device, void 0, {
1245
1250
  F: __dxlog_file5,
1246
- L: 82,
1251
+ L: 87,
1247
1252
  S: this,
1248
1253
  A: [
1249
1254
  "response.device",
@@ -1253,7 +1258,7 @@ var DeviceInvitationProtocol = class {
1253
1258
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1254
1259
  invariant4(request.device, void 0, {
1255
1260
  F: __dxlog_file5,
1256
- L: 85,
1261
+ L: 90,
1257
1262
  S: this,
1258
1263
  A: [
1259
1264
  "request.device",
@@ -1279,9 +1284,8 @@ var DeviceInvitationProtocol = class {
1279
1284
 
1280
1285
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1281
1286
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1282
- import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1287
+ import { AuthenticatingInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
1283
1288
  import { Context as Context5 } from "@dxos/context";
1284
- import { generatePasscode } from "@dxos/credentials";
1285
1289
  import { createKeyPair, sign } from "@dxos/crypto";
1286
1290
  import { invariant as invariant6 } from "@dxos/invariant";
1287
1291
  import { PublicKey as PublicKey6 } from "@dxos/keys";
@@ -1656,51 +1660,7 @@ var InvitationsHandler = class {
1656
1660
  constructor(_networkManager) {
1657
1661
  this._networkManager = _networkManager;
1658
1662
  }
1659
- createInvitation(protocol, options) {
1660
- const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random(), persistent = options?.authMethod !== Invitation3.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
1661
- const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1662
- invariant6(protocol, void 0, {
1663
- F: __dxlog_file7,
1664
- L: 87,
1665
- S: this,
1666
- A: [
1667
- "protocol",
1668
- ""
1669
- ]
1670
- });
1671
- const invitation = {
1672
- invitationId,
1673
- type,
1674
- authMethod,
1675
- state,
1676
- swarmKey,
1677
- authCode,
1678
- timeout,
1679
- persistent: persistent && type !== Invitation3.Type.DELEGATED,
1680
- guestKeypair: guestKeypair ?? (authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
1681
- created,
1682
- lifetime,
1683
- multiUse,
1684
- ...protocol.getInvitationContext()
1685
- };
1686
- const stream = new PushStream();
1687
- const ctx = new Context5({
1688
- onError: (err) => {
1689
- stream.error(err);
1690
- void ctx.dispose();
1691
- }
1692
- });
1693
- ctx.onDispose(() => {
1694
- log5("complete", {
1695
- ...protocol.toJSON()
1696
- }, {
1697
- F: __dxlog_file7,
1698
- L: 115,
1699
- S: this,
1700
- C: (f, a) => f(...a)
1701
- });
1702
- stream.complete();
1703
- });
1663
+ handleInvitationFlow(ctx, stream, protocol, invitation) {
1704
1664
  const createExtension = () => {
1705
1665
  const extension = new InvitationHostExtension({
1706
1666
  onStateUpdate: (invitation2) => {
@@ -1709,8 +1669,8 @@ var InvitationsHandler = class {
1709
1669
  state: Invitation3.State.READY_FOR_AUTHENTICATION
1710
1670
  });
1711
1671
  },
1712
- resolveInvitation: async ({ invitationId: invitationId2 }) => {
1713
- if (invitationId2 && invitationId2 !== invitation.invitationId) {
1672
+ resolveInvitation: async ({ invitationId }) => {
1673
+ if (invitationId && invitationId !== invitation.invitationId) {
1714
1674
  return void 0;
1715
1675
  }
1716
1676
  return invitation;
@@ -1720,14 +1680,14 @@ var InvitationsHandler = class {
1720
1680
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1721
1681
  invariant6(deviceKey, void 0, {
1722
1682
  F: __dxlog_file7,
1723
- L: 136,
1683
+ L: 87,
1724
1684
  S: this,
1725
1685
  A: [
1726
1686
  "deviceKey",
1727
1687
  ""
1728
1688
  ]
1729
1689
  });
1730
- const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1690
+ const admissionResponse = await protocol.admit(invitation, admissionRequest, extension.guestProfile);
1731
1691
  extension.completedTrigger.wake(deviceKey);
1732
1692
  return admissionResponse;
1733
1693
  } catch (err) {
@@ -1743,7 +1703,7 @@ var InvitationsHandler = class {
1743
1703
  id: traceId
1744
1704
  }), {
1745
1705
  F: __dxlog_file7,
1746
- L: 154,
1706
+ L: 105,
1747
1707
  S: this,
1748
1708
  C: (f, a) => f(...a)
1749
1709
  });
@@ -1751,7 +1711,7 @@ var InvitationsHandler = class {
1751
1711
  ...protocol.toJSON()
1752
1712
  }, {
1753
1713
  F: __dxlog_file7,
1754
- L: 155,
1714
+ L: 106,
1755
1715
  S: this,
1756
1716
  C: (f, a) => f(...a)
1757
1717
  });
@@ -1760,14 +1720,14 @@ var InvitationsHandler = class {
1760
1720
  state: Invitation3.State.CONNECTED
1761
1721
  });
1762
1722
  const deviceKey = await extension.completedTrigger.wait({
1763
- timeout
1723
+ timeout: invitation.timeout
1764
1724
  });
1765
1725
  log5("admitted guest", {
1766
1726
  guest: deviceKey,
1767
1727
  ...protocol.toJSON()
1768
1728
  }, {
1769
1729
  F: __dxlog_file7,
1770
- L: 158,
1730
+ L: 109,
1771
1731
  S: this,
1772
1732
  C: (f, a) => f(...a)
1773
1733
  });
@@ -1779,7 +1739,7 @@ var InvitationsHandler = class {
1779
1739
  id: traceId
1780
1740
  }), {
1781
1741
  F: __dxlog_file7,
1782
- L: 160,
1742
+ L: 111,
1783
1743
  S: this,
1784
1744
  C: (f, a) => f(...a)
1785
1745
  });
@@ -1789,7 +1749,7 @@ var InvitationsHandler = class {
1789
1749
  ...protocol.toJSON()
1790
1750
  }, {
1791
1751
  F: __dxlog_file7,
1792
- L: 163,
1752
+ L: 114,
1793
1753
  S: this,
1794
1754
  C: (f, a) => f(...a)
1795
1755
  });
@@ -1800,7 +1760,7 @@ var InvitationsHandler = class {
1800
1760
  } else {
1801
1761
  log5.error("failed", err, {
1802
1762
  F: __dxlog_file7,
1803
- L: 166,
1763
+ L: 117,
1804
1764
  S: this,
1805
1765
  C: (f, a) => f(...a)
1806
1766
  });
@@ -1811,12 +1771,12 @@ var InvitationsHandler = class {
1811
1771
  error: err
1812
1772
  }), {
1813
1773
  F: __dxlog_file7,
1814
- L: 169,
1774
+ L: 120,
1815
1775
  S: this,
1816
1776
  C: (f, a) => f(...a)
1817
1777
  });
1818
1778
  } finally {
1819
- if (!multiUse) {
1779
+ if (!invitation.multiUse) {
1820
1780
  await swarmConnection.close();
1821
1781
  await ctx.dispose();
1822
1782
  }
@@ -1832,7 +1792,7 @@ var InvitationsHandler = class {
1832
1792
  ...protocol.toJSON()
1833
1793
  }, {
1834
1794
  F: __dxlog_file7,
1835
- L: 184,
1795
+ L: 135,
1836
1796
  S: this,
1837
1797
  C: (f, a) => f(...a)
1838
1798
  });
@@ -1843,7 +1803,7 @@ var InvitationsHandler = class {
1843
1803
  } else {
1844
1804
  log5.error("failed", err, {
1845
1805
  F: __dxlog_file7,
1846
- L: 187,
1806
+ L: 138,
1847
1807
  S: this,
1848
1808
  C: (f, a) => f(...a)
1849
1809
  });
@@ -1857,7 +1817,7 @@ var InvitationsHandler = class {
1857
1817
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1858
1818
  log5.warn("invitation has already expired", void 0, {
1859
1819
  F: __dxlog_file7,
1860
- L: 198,
1820
+ L: 149,
1861
1821
  S: this,
1862
1822
  C: (f, a) => f(...a)
1863
1823
  });
@@ -1891,24 +1851,12 @@ var InvitationsHandler = class {
1891
1851
  state: Invitation3.State.CONNECTING
1892
1852
  });
1893
1853
  });
1894
- const observable = new CancellableInvitation({
1895
- initialInvitation: invitation,
1896
- subscriber: stream.observable,
1897
- onCancel: async () => {
1898
- stream.next({
1899
- ...invitation,
1900
- state: Invitation3.State.CANCELLED
1901
- });
1902
- await ctx.dispose();
1903
- }
1904
- });
1905
- return observable;
1906
1854
  }
1907
1855
  acceptInvitation(protocol, invitation, deviceProfile) {
1908
1856
  const { timeout = INVITATION_TIMEOUT } = invitation;
1909
1857
  invariant6(protocol, void 0, {
1910
1858
  F: __dxlog_file7,
1911
- L: 252,
1859
+ L: 191,
1912
1860
  S: this,
1913
1861
  A: [
1914
1862
  "protocol",
@@ -1918,7 +1866,7 @@ var InvitationsHandler = class {
1918
1866
  if (deviceProfile) {
1919
1867
  invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1920
1868
  F: __dxlog_file7,
1921
- L: 255,
1869
+ L: 194,
1922
1870
  S: this,
1923
1871
  A: [
1924
1872
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1933,7 +1881,7 @@ var InvitationsHandler = class {
1933
1881
  const setState = (newData) => {
1934
1882
  invariant6(newData.state !== void 0, void 0, {
1935
1883
  F: __dxlog_file7,
1936
- L: 266,
1884
+ L: 205,
1937
1885
  S: this,
1938
1886
  A: [
1939
1887
  "newData.state !== undefined",
@@ -1953,7 +1901,7 @@ var InvitationsHandler = class {
1953
1901
  ...protocol.toJSON()
1954
1902
  }, {
1955
1903
  F: __dxlog_file7,
1956
- L: 274,
1904
+ L: 213,
1957
1905
  S: this,
1958
1906
  C: (f, a) => f(...a)
1959
1907
  });
@@ -1963,7 +1911,7 @@ var InvitationsHandler = class {
1963
1911
  } else {
1964
1912
  log5.warn("auth failed", err, {
1965
1913
  F: __dxlog_file7,
1966
- L: 277,
1914
+ L: 216,
1967
1915
  S: this,
1968
1916
  C: (f, a) => f(...a)
1969
1917
  });
@@ -1977,7 +1925,7 @@ var InvitationsHandler = class {
1977
1925
  ...protocol.toJSON()
1978
1926
  }, {
1979
1927
  F: __dxlog_file7,
1980
- L: 285,
1928
+ L: 224,
1981
1929
  S: this,
1982
1930
  C: (f, a) => f(...a)
1983
1931
  });
@@ -1992,7 +1940,7 @@ var InvitationsHandler = class {
1992
1940
  currentState
1993
1941
  }, {
1994
1942
  F: __dxlog_file7,
1995
- L: 295,
1943
+ L: 234,
1996
1944
  S: this,
1997
1945
  C: (f, a) => f(...a)
1998
1946
  });
@@ -2007,7 +1955,7 @@ var InvitationsHandler = class {
2007
1955
  id: traceId
2008
1956
  }), {
2009
1957
  F: __dxlog_file7,
2010
- L: 304,
1958
+ L: 243,
2011
1959
  S: this,
2012
1960
  C: (f, a) => f(...a)
2013
1961
  });
@@ -2019,7 +1967,7 @@ var InvitationsHandler = class {
2019
1967
  ...protocol.toJSON()
2020
1968
  }, {
2021
1969
  F: __dxlog_file7,
2022
- L: 312,
1970
+ L: 251,
2023
1971
  S: this,
2024
1972
  C: (f, a) => f(...a)
2025
1973
  });
@@ -2030,7 +1978,7 @@ var InvitationsHandler = class {
2030
1978
  ...protocol.toJSON()
2031
1979
  }, {
2032
1980
  F: __dxlog_file7,
2033
- L: 316,
1981
+ L: 255,
2034
1982
  S: this,
2035
1983
  C: (f, a) => f(...a)
2036
1984
  });
@@ -2040,7 +1988,7 @@ var InvitationsHandler = class {
2040
1988
  response: introductionResponse
2041
1989
  }, {
2042
1990
  F: __dxlog_file7,
2043
- L: 320,
1991
+ L: 259,
2044
1992
  S: this,
2045
1993
  C: (f, a) => f(...a)
2046
1994
  });
@@ -2061,7 +2009,7 @@ var InvitationsHandler = class {
2061
2009
  ...protocol.toJSON()
2062
2010
  }, {
2063
2011
  F: __dxlog_file7,
2064
- L: 336,
2012
+ L: 275,
2065
2013
  S: this,
2066
2014
  C: (f, a) => f(...a)
2067
2015
  });
@@ -2073,7 +2021,7 @@ var InvitationsHandler = class {
2073
2021
  ...protocol.toJSON()
2074
2022
  }, {
2075
2023
  F: __dxlog_file7,
2076
- L: 347,
2024
+ L: 286,
2077
2025
  S: this,
2078
2026
  C: (f, a) => f(...a)
2079
2027
  });
@@ -2086,7 +2034,7 @@ var InvitationsHandler = class {
2086
2034
  id: traceId
2087
2035
  }), {
2088
2036
  F: __dxlog_file7,
2089
- L: 349,
2037
+ L: 288,
2090
2038
  S: this,
2091
2039
  C: (f, a) => f(...a)
2092
2040
  });
@@ -2096,7 +2044,7 @@ var InvitationsHandler = class {
2096
2044
  ...protocol.toJSON()
2097
2045
  }, {
2098
2046
  F: __dxlog_file7,
2099
- L: 352,
2047
+ L: 291,
2100
2048
  S: this,
2101
2049
  C: (f, a) => f(...a)
2102
2050
  });
@@ -2106,7 +2054,7 @@ var InvitationsHandler = class {
2106
2054
  } else {
2107
2055
  log5("auth failed", err, {
2108
2056
  F: __dxlog_file7,
2109
- L: 355,
2057
+ L: 294,
2110
2058
  S: this,
2111
2059
  C: (f, a) => f(...a)
2112
2060
  });
@@ -2117,7 +2065,7 @@ var InvitationsHandler = class {
2117
2065
  error: err
2118
2066
  }), {
2119
2067
  F: __dxlog_file7,
2120
- L: 358,
2068
+ L: 297,
2121
2069
  S: this,
2122
2070
  C: (f, a) => f(...a)
2123
2071
  });
@@ -2135,7 +2083,7 @@ var InvitationsHandler = class {
2135
2083
  ...protocol.toJSON()
2136
2084
  }, {
2137
2085
  F: __dxlog_file7,
2138
- L: 369,
2086
+ L: 308,
2139
2087
  S: this,
2140
2088
  C: (f, a) => f(...a)
2141
2089
  });
@@ -2145,7 +2093,7 @@ var InvitationsHandler = class {
2145
2093
  } else {
2146
2094
  log5("auth failed", err, {
2147
2095
  F: __dxlog_file7,
2148
- L: 372,
2096
+ L: 311,
2149
2097
  S: this,
2150
2098
  C: (f, a) => f(...a)
2151
2099
  });
@@ -2162,7 +2110,7 @@ var InvitationsHandler = class {
2162
2110
  } else {
2163
2111
  invariant6(invitation.swarmKey, void 0, {
2164
2112
  F: __dxlog_file7,
2165
- L: 386,
2113
+ L: 325,
2166
2114
  S: this,
2167
2115
  A: [
2168
2116
  "invitation.swarmKey",
@@ -2204,7 +2152,7 @@ var InvitationsHandler = class {
2204
2152
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2205
2153
  log5("guest waiting for authentication code...", void 0, {
2206
2154
  F: __dxlog_file7,
2207
- L: 426,
2155
+ L: 365,
2208
2156
  S: this,
2209
2157
  C: (f, a) => f(...a)
2210
2158
  });
@@ -2214,7 +2162,7 @@ var InvitationsHandler = class {
2214
2162
  const authCode = await authenticated.wait(options);
2215
2163
  log5("sending authentication request", void 0, {
2216
2164
  F: __dxlog_file7,
2217
- L: 430,
2165
+ L: 369,
2218
2166
  S: this,
2219
2167
  C: (f, a) => f(...a)
2220
2168
  });
@@ -2235,7 +2183,7 @@ var InvitationsHandler = class {
2235
2183
  attempt
2236
2184
  }, {
2237
2185
  F: __dxlog_file7,
2238
- L: 441,
2186
+ L: 380,
2239
2187
  S: this,
2240
2188
  C: (f, a) => f(...a)
2241
2189
  });
@@ -2253,7 +2201,7 @@ var InvitationsHandler = class {
2253
2201
  }
2254
2202
  log5("sending authentication request", void 0, {
2255
2203
  F: __dxlog_file7,
2256
- L: 460,
2204
+ L: 399,
2257
2205
  S: this,
2258
2206
  C: (f, a) => f(...a)
2259
2207
  });
@@ -2289,9 +2237,8 @@ var InvitationsServiceImpl = class {
2289
2237
  return {};
2290
2238
  }
2291
2239
  createInvitation(options) {
2292
- const invitation = this._invitationsManager.createInvitation(options);
2293
2240
  return new Stream8(({ next, close }) => {
2294
- invitation.subscribe(next, close, close);
2241
+ void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
2295
2242
  });
2296
2243
  }
2297
2244
  acceptInvitation(request) {
@@ -2376,12 +2323,13 @@ var InvitationsServiceImpl = class {
2376
2323
  };
2377
2324
 
2378
2325
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2379
- import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
2326
+ import { createAdmissionCredentials, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
2380
2327
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2381
2328
  import { invariant as invariant7 } from "@dxos/invariant";
2382
2329
  import { log as log6 } from "@dxos/log";
2383
2330
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2384
2331
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
2332
+ import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2385
2333
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2386
2334
  var SpaceInvitationProtocol = class {
2387
2335
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
@@ -2402,10 +2350,10 @@ var SpaceInvitationProtocol = class {
2402
2350
  spaceKey: this._spaceKey
2403
2351
  };
2404
2352
  }
2405
- async admit(request, guestProfile) {
2353
+ async admit(invitation, request, guestProfile) {
2406
2354
  invariant7(this._spaceKey, void 0, {
2407
2355
  F: __dxlog_file8,
2408
- L: 47,
2356
+ L: 55,
2409
2357
  S: this,
2410
2358
  A: [
2411
2359
  "this._spaceKey",
@@ -2415,7 +2363,7 @@ var SpaceInvitationProtocol = class {
2415
2363
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2416
2364
  invariant7(space, void 0, {
2417
2365
  F: __dxlog_file8,
2418
- L: 49,
2366
+ L: 57,
2419
2367
  S: this,
2420
2368
  A: [
2421
2369
  "space",
@@ -2424,7 +2372,7 @@ var SpaceInvitationProtocol = class {
2424
2372
  });
2425
2373
  invariant7(request.space, void 0, {
2426
2374
  F: __dxlog_file8,
2427
- L: 51,
2375
+ L: 59,
2428
2376
  S: this,
2429
2377
  A: [
2430
2378
  "request.space",
@@ -2437,14 +2385,14 @@ var SpaceInvitationProtocol = class {
2437
2385
  guest: deviceKey
2438
2386
  }, {
2439
2387
  F: __dxlog_file8,
2440
- L: 54,
2388
+ L: 62,
2441
2389
  S: this,
2442
2390
  C: (f, a) => f(...a)
2443
2391
  });
2444
- const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2392
+ const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2445
2393
  invariant7(credentials[0].credential, void 0, {
2446
2394
  F: __dxlog_file8,
2447
- L: 65,
2395
+ L: 74,
2448
2396
  S: this,
2449
2397
  A: [
2450
2398
  "credentials[0].credential",
@@ -2454,7 +2402,7 @@ var SpaceInvitationProtocol = class {
2454
2402
  const spaceMemberCredential = credentials[0].credential.credential;
2455
2403
  invariant7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2456
2404
  F: __dxlog_file8,
2457
- L: 67,
2405
+ L: 76,
2458
2406
  S: this,
2459
2407
  A: [
2460
2408
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2469,6 +2417,69 @@ var SpaceInvitationProtocol = class {
2469
2417
  }
2470
2418
  };
2471
2419
  }
2420
+ async delegate(invitation) {
2421
+ invariant7(this._spaceKey, void 0, {
2422
+ F: __dxlog_file8,
2423
+ L: 89,
2424
+ S: this,
2425
+ A: [
2426
+ "this._spaceKey",
2427
+ ""
2428
+ ]
2429
+ });
2430
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
2431
+ invariant7(space, void 0, {
2432
+ F: __dxlog_file8,
2433
+ L: 91,
2434
+ S: this,
2435
+ A: [
2436
+ "space",
2437
+ ""
2438
+ ]
2439
+ });
2440
+ if (invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY) {
2441
+ invariant7(invitation.guestKeypair?.publicKey, void 0, {
2442
+ F: __dxlog_file8,
2443
+ L: 93,
2444
+ S: this,
2445
+ A: [
2446
+ "invitation.guestKeypair?.publicKey",
2447
+ ""
2448
+ ]
2449
+ });
2450
+ }
2451
+ log6("writing delegate space invitation", {
2452
+ host: this._signingContext.deviceKey,
2453
+ id: invitation.invitationId
2454
+ }, {
2455
+ F: __dxlog_file8,
2456
+ L: 96,
2457
+ S: this,
2458
+ C: (f, a) => f(...a)
2459
+ });
2460
+ const credential = await createDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, {
2461
+ invitationId: invitation.invitationId,
2462
+ authMethod: invitation.authMethod,
2463
+ swarmKey: invitation.swarmKey,
2464
+ role: SpaceMember.Role.ADMIN,
2465
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2466
+ multiUse: invitation.multiUse ?? false,
2467
+ guestKey: invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2468
+ });
2469
+ invariant7(credential.credential, void 0, {
2470
+ F: __dxlog_file8,
2471
+ L: 116,
2472
+ S: this,
2473
+ A: [
2474
+ "credential.credential",
2475
+ ""
2476
+ ]
2477
+ });
2478
+ await writeMessages2(space.inner.controlPipeline.writer, [
2479
+ credential
2480
+ ]);
2481
+ return credential.credential.credential.id;
2482
+ }
2472
2483
  checkInvitation(invitation) {
2473
2484
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2474
2485
  return new AlreadyJoinedError2("Already joined space.");
@@ -2494,7 +2505,7 @@ var SpaceInvitationProtocol = class {
2494
2505
  async accept(response) {
2495
2506
  invariant7(response.space, void 0, {
2496
2507
  F: __dxlog_file8,
2497
- L: 107,
2508
+ L: 149,
2498
2509
  S: this,
2499
2510
  A: [
2500
2511
  "response.space",
@@ -2505,7 +2516,7 @@ var SpaceInvitationProtocol = class {
2505
2516
  const assertion = getCredentialAssertion(credential);
2506
2517
  invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2507
2518
  F: __dxlog_file8,
2508
- L: 110,
2519
+ L: 152,
2509
2520
  S: this,
2510
2521
  A: [
2511
2522
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2514,7 +2525,7 @@ var SpaceInvitationProtocol = class {
2514
2525
  });
2515
2526
  invariant7(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2516
2527
  F: __dxlog_file8,
2517
- L: 111,
2528
+ L: 153,
2518
2529
  S: this,
2519
2530
  A: [
2520
2531
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2538,10 +2549,15 @@ var SpaceInvitationProtocol = class {
2538
2549
  };
2539
2550
 
2540
2551
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
2541
- import { Event as Event3 } from "@dxos/async";
2552
+ import { Event as Event3, PushStream as PushStream2 } from "@dxos/async";
2553
+ import { AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
2554
+ import { Context as Context6 } from "@dxos/context";
2555
+ import { generatePasscode } from "@dxos/credentials";
2542
2556
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
2543
2557
  import { invariant as invariant8 } from "@dxos/invariant";
2558
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
2544
2559
  import { log as log7 } from "@dxos/log";
2560
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2545
2561
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2546
2562
  var InvitationsManager = class {
2547
2563
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
@@ -2558,25 +2574,39 @@ var InvitationsManager = class {
2558
2574
  this._persistentInvitationsLoadedEvent = new Event3();
2559
2575
  this._persistentInvitationsLoaded = false;
2560
2576
  }
2561
- createInvitation(options) {
2562
- const existingInvitation = this._createInvitations.get(options.invitationId);
2563
- if (existingInvitation) {
2564
- return existingInvitation;
2577
+ async createInvitation(options) {
2578
+ if (options.invitationId) {
2579
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2580
+ if (existingInvitation) {
2581
+ return existingInvitation;
2582
+ }
2565
2583
  }
2566
2584
  const handler = this._getHandler(options);
2567
- const invitation = this._invitationsHandler.createInvitation(handler, options);
2568
- this._createInvitations.set(invitation.get().invitationId, invitation);
2569
- this.invitationCreated.emit(invitation.get());
2570
- const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
2571
- this._onInvitationComplete(invitation, async () => {
2572
- this._createInvitations.delete(invitation.get().invitationId);
2573
- this.removedCreated.emit(invitation.get());
2574
- if (invitation.get().persistent) {
2575
- await saveInvitationTask;
2576
- await this._safeDeleteInvitation(invitation.get());
2585
+ const invitation = this._createInvitation(handler, options);
2586
+ const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2587
+ this._createInvitations.set(invitation.invitationId, observableInvitation);
2588
+ this.invitationCreated.emit(invitation);
2589
+ this._onInvitationComplete(observableInvitation, async () => {
2590
+ this._createInvitations.delete(observableInvitation.get().invitationId);
2591
+ this.removedCreated.emit(observableInvitation.get());
2592
+ if (observableInvitation.get().persistent) {
2593
+ await this._safeDeleteInvitation(observableInvitation.get());
2577
2594
  }
2578
2595
  });
2579
- return invitation;
2596
+ try {
2597
+ await this._persistIfRequired(handler, stream, invitation);
2598
+ } catch (err) {
2599
+ log7.catch(err, void 0, {
2600
+ F: __dxlog_file9,
2601
+ L: 76,
2602
+ S: this,
2603
+ C: (f, a) => f(...a)
2604
+ });
2605
+ await observableInvitation.cancel();
2606
+ return observableInvitation;
2607
+ }
2608
+ this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
2609
+ return observableInvitation;
2580
2610
  }
2581
2611
  async loadPersistentInvitations() {
2582
2612
  if (this._persistentInvitationsLoaded) {
@@ -2588,10 +2618,10 @@ var InvitationsManager = class {
2588
2618
  try {
2589
2619
  const persistentInvitations = this._metadataStore.getInvitations();
2590
2620
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
2591
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2621
+ const loadTasks = freshInvitations.map((persistentInvitation) => {
2592
2622
  invariant8(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2593
2623
  F: __dxlog_file9,
2594
- L: 82,
2624
+ L: 97,
2595
2625
  S: this,
2596
2626
  A: [
2597
2627
  "!this._createInvitations.get(persistentInvitation.invitationId)",
@@ -2601,15 +2631,16 @@ var InvitationsManager = class {
2601
2631
  return this.createInvitation({
2602
2632
  ...persistentInvitation,
2603
2633
  persistent: false
2604
- }).get();
2634
+ });
2605
2635
  });
2636
+ const cInvitations = await Promise.all(loadTasks);
2606
2637
  return {
2607
- invitations: cInvitations
2638
+ invitations: cInvitations.map((invitation) => invitation.get())
2608
2639
  };
2609
2640
  } catch (err) {
2610
2641
  log7.catch(err, void 0, {
2611
2642
  F: __dxlog_file9,
2612
- L: 88,
2643
+ L: 104,
2613
2644
  S: this,
2614
2645
  C: (f, a) => f(...a)
2615
2646
  });
@@ -2640,13 +2671,13 @@ var InvitationsManager = class {
2640
2671
  async authenticate({ invitationId, authCode }) {
2641
2672
  log7("authenticating...", void 0, {
2642
2673
  F: __dxlog_file9,
2643
- L: 117,
2674
+ L: 133,
2644
2675
  S: this,
2645
2676
  C: (f, a) => f(...a)
2646
2677
  });
2647
2678
  invariant8(invitationId, void 0, {
2648
2679
  F: __dxlog_file9,
2649
- L: 118,
2680
+ L: 134,
2650
2681
  S: this,
2651
2682
  A: [
2652
2683
  "invitationId",
@@ -2659,7 +2690,7 @@ var InvitationsManager = class {
2659
2690
  invitationId
2660
2691
  }, {
2661
2692
  F: __dxlog_file9,
2662
- L: 121,
2693
+ L: 137,
2663
2694
  S: this,
2664
2695
  C: (f, a) => f(...a)
2665
2696
  });
@@ -2672,13 +2703,13 @@ var InvitationsManager = class {
2672
2703
  invitationId
2673
2704
  }, {
2674
2705
  F: __dxlog_file9,
2675
- L: 128,
2706
+ L: 144,
2676
2707
  S: this,
2677
2708
  C: (f, a) => f(...a)
2678
2709
  });
2679
2710
  invariant8(invitationId, void 0, {
2680
2711
  F: __dxlog_file9,
2681
- L: 129,
2712
+ L: 145,
2682
2713
  S: this,
2683
2714
  A: [
2684
2715
  "invitationId",
@@ -2719,25 +2750,73 @@ var InvitationsManager = class {
2719
2750
  this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2720
2751
  }
2721
2752
  }
2722
- _safePersistInBackground(invitation) {
2723
- return new Promise((resolve) => {
2724
- setTimeout(async () => {
2725
- try {
2726
- await this._metadataStore.addInvitation(invitation.get());
2727
- this.saved.emit(invitation.get());
2728
- } catch (err) {
2729
- log7.catch(err, void 0, {
2730
- F: __dxlog_file9,
2731
- L: 173,
2732
- S: this,
2733
- C: (f, a) => f(...a)
2734
- });
2735
- await invitation.cancel();
2736
- } finally {
2737
- resolve();
2738
- }
2753
+ _createInvitation(protocol, options) {
2754
+ const { invitationId = PublicKey7.random().toHex(), type = Invitation5.Type.INTERACTIVE, authMethod = Invitation5.AuthMethod.SHARED_SECRET, state = Invitation5.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey7.random(), persistent = options?.authMethod !== Invitation5.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2755
+ const authCode = options?.authCode ?? (authMethod === Invitation5.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
2756
+ return {
2757
+ invitationId,
2758
+ type,
2759
+ authMethod,
2760
+ state,
2761
+ swarmKey,
2762
+ authCode,
2763
+ timeout,
2764
+ persistent: persistent && type !== Invitation5.Type.DELEGATED,
2765
+ guestKeypair: guestKeypair ?? (authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2766
+ created,
2767
+ lifetime,
2768
+ multiUse,
2769
+ delegationCredentialId: options?.delegationCredentialId,
2770
+ ...protocol.getInvitationContext()
2771
+ };
2772
+ }
2773
+ _createObservableInvitation(handler, invitation) {
2774
+ const stream = new PushStream2();
2775
+ const ctx = new Context6({
2776
+ onError: (err) => {
2777
+ stream.error(err);
2778
+ void ctx.dispose();
2779
+ }
2780
+ });
2781
+ ctx.onDispose(() => {
2782
+ log7("complete", {
2783
+ ...handler.toJSON()
2784
+ }, {
2785
+ F: __dxlog_file9,
2786
+ L: 228,
2787
+ S: this,
2788
+ C: (f, a) => f(...a)
2739
2789
  });
2790
+ stream.complete();
2740
2791
  });
2792
+ const observableInvitation = new CancellableInvitation({
2793
+ initialInvitation: invitation,
2794
+ subscriber: stream.observable,
2795
+ onCancel: async () => {
2796
+ stream.next({
2797
+ ...invitation,
2798
+ state: Invitation5.State.CANCELLED
2799
+ });
2800
+ await ctx.dispose();
2801
+ }
2802
+ });
2803
+ return {
2804
+ ctx,
2805
+ stream,
2806
+ observableInvitation
2807
+ };
2808
+ }
2809
+ async _persistIfRequired(handler, changeStream, invitation) {
2810
+ if (invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId == null) {
2811
+ const delegationCredentialId = await handler.delegate(invitation);
2812
+ changeStream.next({
2813
+ ...invitation,
2814
+ delegationCredentialId
2815
+ });
2816
+ } else if (invitation.persistent) {
2817
+ await this._metadataStore.addInvitation(invitation);
2818
+ this.saved.emit(invitation);
2819
+ }
2741
2820
  }
2742
2821
  async _safeDeleteInvitation(invitation) {
2743
2822
  try {
@@ -2745,7 +2824,7 @@ var InvitationsManager = class {
2745
2824
  } catch (err) {
2746
2825
  log7.catch(err, void 0, {
2747
2826
  F: __dxlog_file9,
2748
- L: 186,
2827
+ L: 260,
2749
2828
  S: this,
2750
2829
  C: (f, a) => f(...a)
2751
2830
  });
@@ -2842,13 +2921,13 @@ ClientRpcServer = _ts_decorate3([
2842
2921
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2843
2922
  import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2844
2923
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2845
- import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
2924
+ import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
2846
2925
  import { timed, warnAfterTimeout } from "@dxos/debug";
2847
2926
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2848
2927
  import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2849
2928
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
2850
2929
  import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
2851
- import { PublicKey as PublicKey8 } from "@dxos/keys";
2930
+ import { PublicKey as PublicKey9 } from "@dxos/keys";
2852
2931
  import { log as log9 } from "@dxos/log";
2853
2932
  import { CancelledError, SystemError } from "@dxos/protocols";
2854
2933
  import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -2897,9 +2976,9 @@ var AutomergeSpaceState = class {
2897
2976
 
2898
2977
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2899
2978
  import { DeferredTask, Event as Event5, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2900
- import { Context as Context6, rejectOnDispose } from "@dxos/context";
2979
+ import { Context as Context7, rejectOnDispose } from "@dxos/context";
2901
2980
  import { invariant as invariant9 } from "@dxos/invariant";
2902
- import { PublicKey as PublicKey7 } from "@dxos/keys";
2981
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
2903
2982
  import { log as log8 } from "@dxos/log";
2904
2983
  import { schema as schema3 } from "@dxos/protocols";
2905
2984
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
@@ -2911,11 +2990,11 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2911
2990
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2912
2991
  var NotarizationPlugin = class {
2913
2992
  constructor() {
2914
- this._ctx = new Context6();
2993
+ this._ctx = new Context7();
2915
2994
  this._extensionOpened = new Event5();
2916
2995
  this._extensions = /* @__PURE__ */ new Set();
2917
- this._processedCredentials = new ComplexSet2(PublicKey7.hash);
2918
- this._processCredentialsTriggers = new ComplexMap2(PublicKey7.hash);
2996
+ this._processedCredentials = new ComplexSet2(PublicKey8.hash);
2997
+ this._processCredentialsTriggers = new ComplexMap2(PublicKey8.hash);
2919
2998
  }
2920
2999
  get hasWriter() {
2921
3000
  return !!this._writer;
@@ -3177,7 +3256,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3177
3256
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3178
3257
  var DataSpace = class {
3179
3258
  constructor(params) {
3180
- this._ctx = new Context7();
3259
+ this._ctx = new Context8();
3181
3260
  this._notarizationPlugin = new NotarizationPlugin();
3182
3261
  this._cache = void 0;
3183
3262
  // TODO(dmaretskyi): Move into Space?
@@ -3200,7 +3279,7 @@ var DataSpace = class {
3200
3279
  this._callbacks = params.callbacks ?? {};
3201
3280
  this._automergeHost = params.automergeHost;
3202
3281
  this.authVerifier = new TrustedKeySetAuthVerifier({
3203
- trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3282
+ trustedKeysProvider: () => new ComplexSet3(PublicKey9.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3204
3283
  update: this._inner.stateUpdate,
3205
3284
  authTimeout: AUTH_TIMEOUT2
3206
3285
  });
@@ -3254,7 +3333,7 @@ var DataSpace = class {
3254
3333
  await this._notarizationPlugin.open();
3255
3334
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3256
3335
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3257
- await this._inner.open(new Context7());
3336
+ await this._inner.open(new Context8());
3258
3337
  this._state = SpaceState.CONTROL_ONLY;
3259
3338
  log9("new state", {
3260
3339
  state: SpaceState[this._state]
@@ -3283,7 +3362,7 @@ var DataSpace = class {
3283
3362
  C: (f, a) => f(...a)
3284
3363
  });
3285
3364
  await this._ctx.dispose();
3286
- this._ctx = new Context7();
3365
+ this._ctx = new Context8();
3287
3366
  await this.authVerifier.close();
3288
3367
  await this._inner.close();
3289
3368
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3704,20 +3783,20 @@ DataSpace = _ts_decorate4([
3704
3783
 
3705
3784
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3706
3785
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3707
- import { Context as Context8, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3786
+ import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3708
3787
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3709
3788
  import { invariant as invariant11 } from "@dxos/invariant";
3710
- import { PublicKey as PublicKey9 } from "@dxos/keys";
3789
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
3711
3790
  import { log as log10 } from "@dxos/log";
3712
3791
  import { trace as trace7 } from "@dxos/protocols";
3713
- import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3792
+ import { Invitation as Invitation6, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3714
3793
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
3715
3794
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
3716
3795
 
3717
3796
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
3718
3797
  import { createCredential } from "@dxos/credentials";
3719
3798
  import { failUndefined } from "@dxos/debug";
3720
- import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
3799
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3721
3800
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3722
3801
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3723
3802
  const credentials = [
@@ -3737,7 +3816,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3737
3816
  assertion: {
3738
3817
  "@type": "dxos.halo.credentials.SpaceMember",
3739
3818
  spaceKey: space.key,
3740
- role: SpaceMember.Role.ADMIN,
3819
+ role: SpaceMember2.Role.ADMIN,
3741
3820
  profile: signingContext.getProfile(),
3742
3821
  genesisFeedKey: space.controlFeedKey ?? failUndefined()
3743
3822
  }
@@ -3799,18 +3878,19 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3799
3878
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3800
3879
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3801
3880
  var DataSpaceManager = class {
3802
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
3881
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, _invitationsManager, params) {
3803
3882
  this._spaceManager = _spaceManager;
3804
3883
  this._metadataStore = _metadataStore;
3805
3884
  this._keyring = _keyring;
3806
3885
  this._signingContext = _signingContext;
3807
3886
  this._feedStore = _feedStore;
3808
3887
  this._automergeHost = _automergeHost;
3809
- this._ctx = new Context8();
3888
+ this._invitationsManager = _invitationsManager;
3889
+ this._ctx = new Context9();
3810
3890
  this.updated = new Event7();
3811
- this._spaces = new ComplexMap3(PublicKey9.hash);
3891
+ this._spaces = new ComplexMap3(PublicKey10.hash);
3812
3892
  this._isOpen = false;
3813
- this._instanceId = PublicKey9.random().toHex();
3893
+ this._instanceId = PublicKey10.random().toHex();
3814
3894
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3815
3895
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3816
3896
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3822,7 +3902,7 @@ var DataSpaceManager = class {
3822
3902
  async open() {
3823
3903
  log10("open", void 0, {
3824
3904
  F: __dxlog_file12,
3825
- L: 98,
3905
+ L: 101,
3826
3906
  S: this,
3827
3907
  C: (f, a) => f(...a)
3828
3908
  });
@@ -3830,7 +3910,7 @@ var DataSpaceManager = class {
3830
3910
  id: this._instanceId
3831
3911
  }), {
3832
3912
  F: __dxlog_file12,
3833
- L: 99,
3913
+ L: 102,
3834
3914
  S: this,
3835
3915
  C: (f, a) => f(...a)
3836
3916
  });
@@ -3838,7 +3918,7 @@ var DataSpaceManager = class {
3838
3918
  spaces: this._metadataStore.spaces.length
3839
3919
  }, {
3840
3920
  F: __dxlog_file12,
3841
- L: 100,
3921
+ L: 103,
3842
3922
  S: this,
3843
3923
  C: (f, a) => f(...a)
3844
3924
  });
@@ -3848,7 +3928,7 @@ var DataSpaceManager = class {
3848
3928
  spaceMetadata
3849
3929
  }, {
3850
3930
  F: __dxlog_file12,
3851
- L: 104,
3931
+ L: 107,
3852
3932
  S: this,
3853
3933
  C: (f, a) => f(...a)
3854
3934
  });
@@ -3859,7 +3939,7 @@ var DataSpaceManager = class {
3859
3939
  err
3860
3940
  }, {
3861
3941
  F: __dxlog_file12,
3862
- L: 107,
3942
+ L: 110,
3863
3943
  S: this,
3864
3944
  C: (f, a) => f(...a)
3865
3945
  });
@@ -3876,7 +3956,7 @@ var DataSpaceManager = class {
3876
3956
  id: this._instanceId
3877
3957
  }), {
3878
3958
  F: __dxlog_file12,
3879
- L: 120,
3959
+ L: 123,
3880
3960
  S: this,
3881
3961
  C: (f, a) => f(...a)
3882
3962
  });
@@ -3884,7 +3964,7 @@ var DataSpaceManager = class {
3884
3964
  async close() {
3885
3965
  log10("close", void 0, {
3886
3966
  F: __dxlog_file12,
3887
- L: 125,
3967
+ L: 128,
3888
3968
  S: this,
3889
3969
  C: (f, a) => f(...a)
3890
3970
  });
@@ -3900,7 +3980,7 @@ var DataSpaceManager = class {
3900
3980
  async createSpace() {
3901
3981
  invariant11(this._isOpen, "Not open.", {
3902
3982
  F: __dxlog_file12,
3903
- L: 138,
3983
+ L: 141,
3904
3984
  S: this,
3905
3985
  A: [
3906
3986
  "this._isOpen",
@@ -3921,7 +4001,7 @@ var DataSpaceManager = class {
3921
4001
  spaceKey
3922
4002
  }, {
3923
4003
  F: __dxlog_file12,
3924
- L: 150,
4004
+ L: 153,
3925
4005
  S: this,
3926
4006
  C: (f, a) => f(...a)
3927
4007
  });
@@ -3937,7 +4017,7 @@ var DataSpaceManager = class {
3937
4017
  const memberCredential = credentials[1];
3938
4018
  invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3939
4019
  F: __dxlog_file12,
3940
- L: 163,
4020
+ L: 166,
3941
4021
  S: this,
3942
4022
  A: [
3943
4023
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3955,13 +4035,13 @@ var DataSpaceManager = class {
3955
4035
  opts
3956
4036
  }, {
3957
4037
  F: __dxlog_file12,
3958
- L: 175,
4038
+ L: 178,
3959
4039
  S: this,
3960
4040
  C: (f, a) => f(...a)
3961
4041
  });
3962
4042
  invariant11(this._isOpen, "Not open.", {
3963
4043
  F: __dxlog_file12,
3964
- L: 176,
4044
+ L: 179,
3965
4045
  S: this,
3966
4046
  A: [
3967
4047
  "this._isOpen",
@@ -3970,7 +4050,7 @@ var DataSpaceManager = class {
3970
4050
  });
3971
4051
  invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3972
4052
  F: __dxlog_file12,
3973
- L: 177,
4053
+ L: 180,
3974
4054
  S: this,
3975
4055
  A: [
3976
4056
  "!this._spaces.has(opts.spaceKey)",
@@ -4005,7 +4085,7 @@ var DataSpaceManager = class {
4005
4085
  metadata
4006
4086
  }, {
4007
4087
  F: __dxlog_file12,
4008
- L: 210,
4088
+ L: 213,
4009
4089
  S: this,
4010
4090
  C: (f, a) => f(...a)
4011
4091
  });
@@ -4043,12 +4123,15 @@ var DataSpaceManager = class {
4043
4123
  onAuthFailure: () => {
4044
4124
  log10.warn("auth failure", void 0, {
4045
4125
  F: __dxlog_file12,
4046
- L: 247,
4126
+ L: 250,
4047
4127
  S: this,
4048
4128
  C: (f, a) => f(...a)
4049
4129
  });
4050
4130
  },
4051
- memberKey: this._signingContext.identityKey
4131
+ memberKey: this._signingContext.identityKey,
4132
+ onDelegatedInvitationStatusChange: (invitation, isActive) => {
4133
+ return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
4134
+ }
4052
4135
  });
4053
4136
  controlFeed && await space.setControlFeed(controlFeed);
4054
4137
  dataFeed && await space.setDataFeed(dataFeed);
@@ -4067,7 +4150,7 @@ var DataSpaceManager = class {
4067
4150
  space: space.key
4068
4151
  }, {
4069
4152
  F: __dxlog_file12,
4070
- L: 265,
4153
+ L: 271,
4071
4154
  S: this,
4072
4155
  C: (f, a) => f(...a)
4073
4156
  });
@@ -4078,11 +4161,14 @@ var DataSpaceManager = class {
4078
4161
  open: this._isOpen
4079
4162
  }, {
4080
4163
  F: __dxlog_file12,
4081
- L: 268,
4164
+ L: 274,
4082
4165
  S: this,
4083
4166
  C: (f, a) => f(...a)
4084
4167
  });
4085
4168
  if (this._isOpen) {
4169
+ await this._createDelegatedInvitations(dataSpace, [
4170
+ ...space.spaceState.invitations.entries()
4171
+ ]);
4086
4172
  this.updated.emit();
4087
4173
  }
4088
4174
  },
@@ -4091,7 +4177,7 @@ var DataSpaceManager = class {
4091
4177
  space: space.key
4092
4178
  }, {
4093
4179
  F: __dxlog_file12,
4094
- L: 274,
4180
+ L: 281,
4095
4181
  S: this,
4096
4182
  C: (f, a) => f(...a)
4097
4183
  });
@@ -4109,6 +4195,41 @@ var DataSpaceManager = class {
4109
4195
  this._spaces.set(metadata.key, dataSpace);
4110
4196
  return dataSpace;
4111
4197
  }
4198
+ async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4199
+ if (dataSpace?.state !== SpaceState2.READY) {
4200
+ return;
4201
+ }
4202
+ if (isActive) {
4203
+ await this._createDelegatedInvitations(dataSpace, [
4204
+ [
4205
+ delegatedInvitation.credentialId,
4206
+ delegatedInvitation.invitation
4207
+ ]
4208
+ ]);
4209
+ } else {
4210
+ await this._invitationsManager.cancelInvitation(delegatedInvitation.invitation);
4211
+ }
4212
+ }
4213
+ async _createDelegatedInvitations(space, invitations) {
4214
+ const tasks = invitations.map(([credentialId, invitation]) => {
4215
+ return this._invitationsManager.createInvitation({
4216
+ type: Invitation6.Type.DELEGATED,
4217
+ kind: Invitation6.Kind.SPACE,
4218
+ spaceKey: space.key,
4219
+ authMethod: invitation.authMethod,
4220
+ invitationId: invitation.invitationId,
4221
+ swarmKey: invitation.swarmKey,
4222
+ guestKeypair: invitation.guestKey ? {
4223
+ publicKey: invitation.guestKey
4224
+ } : void 0,
4225
+ lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
4226
+ multiUse: invitation.multiUse,
4227
+ delegationCredentialId: credentialId,
4228
+ persistent: false
4229
+ });
4230
+ });
4231
+ await Promise.all(tasks);
4232
+ }
4112
4233
  };
4113
4234
  _ts_decorate5([
4114
4235
  synchronized2
@@ -4133,7 +4254,7 @@ import { raise as raise2 } from "@dxos/debug";
4133
4254
  import { invariant as invariant12 } from "@dxos/invariant";
4134
4255
  import { log as log11 } from "@dxos/log";
4135
4256
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4136
- import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4257
+ import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4137
4258
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4138
4259
  var SpacesServiceImpl = class {
4139
4260
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
@@ -4331,7 +4452,7 @@ var SpacesServiceImpl = class {
4331
4452
  identityKey: member.key,
4332
4453
  profile: member.profile ?? {}
4333
4454
  },
4334
- presence: member.removed ? SpaceMember2.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE,
4455
+ presence: member.removed ? SpaceMember3.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
4335
4456
  peerStates: peers
4336
4457
  };
4337
4458
  }),
@@ -4345,7 +4466,7 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4345
4466
 
4346
4467
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4347
4468
  import { Trigger as Trigger5 } from "@dxos/async";
4348
- import { Context as Context9, Resource } from "@dxos/context";
4469
+ import { Context as Context10, Resource } from "@dxos/context";
4349
4470
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4350
4471
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4351
4472
  import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -4353,10 +4474,10 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
4353
4474
  import { IndexMetadataStore, IndexStore, Indexer, createStorageCallbacks } from "@dxos/indexing";
4354
4475
  import { invariant as invariant13 } from "@dxos/invariant";
4355
4476
  import { Keyring } from "@dxos/keyring";
4356
- import { PublicKey as PublicKey10 } from "@dxos/keys";
4477
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
4357
4478
  import { log as log12 } from "@dxos/log";
4358
4479
  import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4359
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4480
+ import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4360
4481
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4361
4482
  import { trace as Trace2 } from "@dxos/tracing";
4362
4483
  import { safeInstanceof } from "@dxos/util";
@@ -4389,59 +4510,6 @@ var createSelectedDocumentsIterator = (automergeHost) => (
4389
4510
  }
4390
4511
  }
4391
4512
  );
4392
- var createDocumentsIterator = (automergeHost) => (
4393
- /**
4394
- * Recursively get all object data blobs from Automerge Repo.
4395
- * @param ids
4396
- */
4397
- // TODO(mykola): Unload automerge handles after usage.
4398
- async function* getAllDocuments() {
4399
- const visited = /* @__PURE__ */ new Set();
4400
- async function* getObjectsFromHandle(handle) {
4401
- if (visited.has(handle.documentId)) {
4402
- return;
4403
- }
4404
- if (!handle.isReady()) {
4405
- await handle.whenReady();
4406
- }
4407
- const doc = handle.docSync();
4408
- const heads = getHeads(doc);
4409
- if (doc.objects) {
4410
- yield Object.entries(doc.objects).map(([objectId, object]) => {
4411
- return {
4412
- id: idCodec.encode({
4413
- documentId: handle.documentId,
4414
- objectId
4415
- }),
4416
- object,
4417
- currentHash: heads.join("")
4418
- };
4419
- });
4420
- }
4421
- if (doc.links) {
4422
- for (const id of Object.values(doc.links)) {
4423
- if (visited.has(id)) {
4424
- continue;
4425
- }
4426
- const linkHandle = automergeHost.repo.handles[id] ?? automergeHost.repo.find(id);
4427
- for await (const result of getObjectsFromHandle(linkHandle)) {
4428
- yield result;
4429
- }
4430
- }
4431
- }
4432
- visited.add(handle.documentId);
4433
- }
4434
- for (const handle of Object.values(automergeHost.repo.handles)) {
4435
- if (visited.has(handle.documentId)) {
4436
- continue;
4437
- }
4438
- for await (const result of getObjectsFromHandle(handle)) {
4439
- yield result;
4440
- }
4441
- visited.add(handle.documentId);
4442
- }
4443
- }
4444
- );
4445
4513
 
4446
4514
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4447
4515
  function _ts_decorate6(decorators, target, key, desc) {
@@ -4465,7 +4533,7 @@ var ServiceContext = class extends Resource {
4465
4533
  this._runtimeParams = _runtimeParams;
4466
4534
  this.initialized = new Trigger5();
4467
4535
  this._handlerFactories = /* @__PURE__ */ new Map();
4468
- this._instanceId = PublicKey10.random().toHex();
4536
+ this._instanceId = PublicKey11.random().toHex();
4469
4537
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
4470
4538
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
4471
4539
  this.blobStore = new BlobStore(storage.createDirectory("blobs"));
@@ -4500,16 +4568,16 @@ var ServiceContext = class extends Resource {
4500
4568
  })
4501
4569
  });
4502
4570
  this.indexer = new Indexer({
4571
+ db: this.level,
4503
4572
  indexStore: new IndexStore({
4504
4573
  db: level.sublevel("index-storage")
4505
4574
  }),
4506
4575
  metadataStore: this.indexMetadata,
4507
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4508
- getAllDocuments: createDocumentsIterator(this.automergeHost)
4576
+ loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
4509
4577
  });
4510
4578
  this.invitations = new InvitationsHandler(this.networkManager);
4511
4579
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4512
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4580
+ this._handlerFactories.set(Invitation7.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4513
4581
  }
4514
4582
  async _open(ctx) {
4515
4583
  await this._checkStorageVersion();
@@ -4588,7 +4656,7 @@ var ServiceContext = class extends Resource {
4588
4656
  }
4589
4657
  async createIdentity(params = {}) {
4590
4658
  const identity = await this.identityManager.createIdentity(params);
4591
- await this._initialize(new Context9());
4659
+ await this._initialize(new Context10());
4592
4660
  return identity;
4593
4661
  }
4594
4662
  getInvitationHandler(invitation) {
@@ -4614,7 +4682,7 @@ var ServiceContext = class extends Resource {
4614
4682
  }
4615
4683
  async _acceptIdentity(params) {
4616
4684
  const identity = await this.identityManager.acceptIdentity(params);
4617
- await this._initialize(new Context9());
4685
+ await this._initialize(new Context10());
4618
4686
  return identity;
4619
4687
  }
4620
4688
  async _checkStorageVersion() {
@@ -4645,12 +4713,12 @@ var ServiceContext = class extends Resource {
4645
4713
  });
4646
4714
  }
4647
4715
  };
4648
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4716
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this.invitationsManager, this._runtimeParams);
4649
4717
  await this.dataSpaceManager.open();
4650
- this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
4718
+ this._handlerFactories.set(Invitation7.Kind.SPACE, (invitation) => {
4651
4719
  invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4652
4720
  F: __dxlog_file14,
4653
- L: 264,
4721
+ L: 265,
4654
4722
  S: this,
4655
4723
  A: [
4656
4724
  "this.dataSpaceManager",
@@ -4674,7 +4742,7 @@ var ServiceContext = class extends Resource {
4674
4742
  details: assertion
4675
4743
  }, {
4676
4744
  F: __dxlog_file14,
4677
- L: 280,
4745
+ L: 281,
4678
4746
  S: this,
4679
4747
  C: (f, a) => f(...a)
4680
4748
  });
@@ -4685,7 +4753,7 @@ var ServiceContext = class extends Resource {
4685
4753
  details: assertion
4686
4754
  }, {
4687
4755
  F: __dxlog_file14,
4688
- L: 284,
4756
+ L: 285,
4689
4757
  S: this,
4690
4758
  C: (f, a) => f(...a)
4691
4759
  });
@@ -4696,7 +4764,7 @@ var ServiceContext = class extends Resource {
4696
4764
  details: assertion
4697
4765
  }, {
4698
4766
  F: __dxlog_file14,
4699
- L: 289,
4767
+ L: 290,
4700
4768
  S: this,
4701
4769
  C: (f, a) => f(...a)
4702
4770
  });
@@ -4707,7 +4775,7 @@ var ServiceContext = class extends Resource {
4707
4775
  } catch (err) {
4708
4776
  log12.catch(err, void 0, {
4709
4777
  F: __dxlog_file14,
4710
- L: 295,
4778
+ L: 296,
4711
4779
  S: this,
4712
4780
  C: (f, a) => f(...a)
4713
4781
  });
@@ -4757,11 +4825,11 @@ import { getFirstStreamValue } from "@dxos/codec-protobuf";
4757
4825
  import { credentialTypeFilter } from "@dxos/credentials";
4758
4826
  import { invariant as invariant14 } from "@dxos/invariant";
4759
4827
  import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
4760
- import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/services";
4828
+ import { SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/client/services";
4761
4829
  import { TRACE_PROCESSOR } from "@dxos/tracing";
4762
4830
 
4763
4831
  // packages/sdk/client-services/src/version.ts
4764
- var DXOS_VERSION = "0.4.10-next.71cec10";
4832
+ var DXOS_VERSION = "0.5.0";
4765
4833
 
4766
4834
  // packages/sdk/client-services/src/packlets/services/platform.ts
4767
4835
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -4883,7 +4951,7 @@ var getSpaceStats = async (space) => {
4883
4951
  displayName: member.assertion.profile?.displayName
4884
4952
  }
4885
4953
  },
4886
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE
4954
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember4.PresenceState.ONLINE : SpaceMember4.PresenceState.OFFLINE
4887
4955
  })),
4888
4956
  pipeline: {
4889
4957
  // TODO(burdon): Pick properties from credentials if needed.
@@ -5004,12 +5072,12 @@ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
5004
5072
  // packages/sdk/client-services/src/packlets/services/service-host.ts
5005
5073
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
5006
5074
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
5007
- import { Context as Context10 } from "@dxos/context";
5075
+ import { Context as Context11 } from "@dxos/context";
5008
5076
  import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
5009
5077
  import { getTypeReference } from "@dxos/echo-schema";
5010
5078
  import { QueryServiceImpl } from "@dxos/indexing";
5011
5079
  import { invariant as invariant16 } from "@dxos/invariant";
5012
- import { PublicKey as PublicKey13 } from "@dxos/keys";
5080
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
5013
5081
  import { log as log16 } from "@dxos/log";
5014
5082
  import { WebsocketSignalManager } from "@dxos/messaging";
5015
5083
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
@@ -5228,7 +5296,7 @@ var isLocked = (lockPath) => {
5228
5296
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
5229
5297
  import { Event as Event8 } from "@dxos/async";
5230
5298
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
5231
- import { PublicKey as PublicKey11 } from "@dxos/keys";
5299
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5232
5300
  import { getContextFromEntry, log as log15 } from "@dxos/log";
5233
5301
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
5234
5302
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
@@ -5236,7 +5304,7 @@ var LoggingServiceImpl = class {
5236
5304
  constructor() {
5237
5305
  this._logs = new Event8();
5238
5306
  this._started = Date.now();
5239
- this._sessionId = PublicKey11.random().toHex();
5307
+ this._sessionId = PublicKey12.random().toHex();
5240
5308
  this._logProcessor = (_config, entry2) => {
5241
5309
  this._logs.emit(entry2);
5242
5310
  };
@@ -5447,10 +5515,10 @@ var toStorageType = (type) => {
5447
5515
  // packages/sdk/client-services/src/packlets/storage/level.ts
5448
5516
  import { Level } from "level";
5449
5517
  import path from "@dxos/node-std/path";
5450
- import { PublicKey as PublicKey12 } from "@dxos/keys";
5518
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
5451
5519
  var createLevel = async (config) => {
5452
5520
  const persistent = isPersistent(config);
5453
- const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey12.random().toHex()}`;
5521
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
5454
5522
  const level = new Level(storagePath);
5455
5523
  await level.open();
5456
5524
  return level;
@@ -5557,7 +5625,7 @@ var ClientServicesHost = class {
5557
5625
  lockKey,
5558
5626
  onAcquire: () => {
5559
5627
  if (!this._opening) {
5560
- void this.open(new Context10());
5628
+ void this.open(new Context11());
5561
5629
  }
5562
5630
  },
5563
5631
  onRelease: () => this.close()
@@ -5679,7 +5747,7 @@ var ClientServicesHost = class {
5679
5747
  if (this._open) {
5680
5748
  return;
5681
5749
  }
5682
- const traceId = PublicKey13.random().toHex();
5750
+ const traceId = PublicKey14.random().toHex();
5683
5751
  log16.trace("dxos.client-services.host.open", trace9.begin({
5684
5752
  id: traceId
5685
5753
  }), {
@@ -5833,7 +5901,7 @@ var ClientServicesHost = class {
5833
5901
  });
5834
5902
  }
5835
5903
  async reset() {
5836
- const traceId = PublicKey13.random().toHex();
5904
+ const traceId = PublicKey14.random().toHex();
5837
5905
  log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5838
5906
  id: traceId
5839
5907
  }), {
@@ -5893,7 +5961,7 @@ var ClientServicesHost = class {
5893
5961
  keys: []
5894
5962
  }
5895
5963
  };
5896
- const propertiesId = PublicKey13.random().toHex();
5964
+ const propertiesId = PublicKey14.random().toHex();
5897
5965
  document.change((doc) => {
5898
5966
  assignDeep2(doc, [
5899
5967
  "objects",
@@ -5923,7 +5991,7 @@ ClientServicesHost = _ts_decorate8([
5923
5991
  ], ClientServicesHost);
5924
5992
 
5925
5993
  // packages/sdk/client-services/src/packlets/services/util.ts
5926
- import { PublicKey as PublicKey14 } from "@dxos/keys";
5994
+ import { PublicKey as PublicKey15 } from "@dxos/keys";
5927
5995
  import { humanize } from "@dxos/util";
5928
5996
  var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5929
5997
 
@@ -6000,4 +6068,4 @@ export {
6000
6068
  ClientServicesHost,
6001
6069
  ClientServicesProviderResource
6002
6070
  };
6003
- //# sourceMappingURL=chunk-5U7G5S73.mjs.map
6071
+ //# sourceMappingURL=chunk-ESEYLOPB.mjs.map