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