@dxos/client-services 0.4.10-main.e2d2318 → 0.4.10-main.e3078ed
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-HAFART26.mjs → chunk-IYPYLH4D.mjs} +631 -511
- package/dist/lib/browser/chunk-IYPYLH4D.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -1
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +127 -113
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-5YDVC6TU.cjs → chunk-PZOCMCLY.cjs} +699 -580
- package/dist/lib/node/chunk-PZOCMCLY.cjs.map +7 -0
- package/dist/lib/node/index.cjs +44 -42
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +127 -116
- 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 +2 -6
- package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/index.d.ts +1 -0
- package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +44 -0
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +2 -0
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +3 -2
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.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 +6 -4
- 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 +1 -0
- package/src/packlets/identity/identity.test.ts +3 -0
- package/src/packlets/indexing/util.ts +9 -66
- package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
- package/src/packlets/invitations/index.ts +1 -0
- package/src/packlets/invitations/invitation-protocol.ts +7 -1
- package/src/packlets/invitations/invitations-handler.ts +11 -73
- package/src/packlets/invitations/invitations-manager.ts +271 -0
- package/src/packlets/invitations/invitations-service.ts +23 -168
- package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
- package/src/packlets/services/automerge-host.test.ts +1 -1
- package/src/packlets/services/service-context.ts +17 -5
- package/src/packlets/services/service-host.ts +13 -17
- package/src/packlets/spaces/data-space-manager.ts +48 -2
- package/src/packlets/spaces/data-space.ts +1 -1
- package/src/packlets/testing/invitation-utils.ts +100 -97
- package/src/packlets/testing/test-builder.ts +23 -5
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-HAFART26.mjs.map +0 -7
- package/dist/lib/node/chunk-5YDVC6TU.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
|
|
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:
|
|
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:
|
|
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:
|
|
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,
|
|
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
|
-
|
|
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
|
|
1713
|
-
if (
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
1806
|
+
L: 138,
|
|
1847
1807
|
S: this,
|
|
1848
1808
|
C: (f, a) => f(...a)
|
|
1849
1809
|
});
|
|
@@ -1853,11 +1813,11 @@ var InvitationsHandler = class {
|
|
|
1853
1813
|
});
|
|
1854
1814
|
return extension;
|
|
1855
1815
|
};
|
|
1856
|
-
if (invitation.lifetime && invitation.created
|
|
1816
|
+
if (invitation.lifetime && invitation.created) {
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
2204
|
+
L: 399,
|
|
2257
2205
|
S: this,
|
|
2258
2206
|
C: (f, a) => f(...a)
|
|
2259
2207
|
});
|
|
@@ -2278,201 +2226,36 @@ var createAdmissionKeypair = () => {
|
|
|
2278
2226
|
};
|
|
2279
2227
|
|
|
2280
2228
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
2281
|
-
import { Event as Event3, scheduleTask as scheduleTask3 } from "@dxos/async";
|
|
2282
2229
|
import { Stream as Stream8 } from "@dxos/codec-protobuf";
|
|
2283
|
-
import {
|
|
2284
|
-
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2285
|
-
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2286
|
-
import { log as log6 } from "@dxos/log";
|
|
2287
|
-
import { Invitation as Invitation4, QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
2288
|
-
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
|
|
2230
|
+
import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
2289
2231
|
var InvitationsServiceImpl = class {
|
|
2290
|
-
constructor(
|
|
2291
|
-
this.
|
|
2292
|
-
this._getHandler = _getHandler;
|
|
2293
|
-
this._metadataStore = _metadataStore;
|
|
2294
|
-
this._createInvitations = /* @__PURE__ */ new Map();
|
|
2295
|
-
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
2296
|
-
this._invitationCreated = new Event3();
|
|
2297
|
-
this._invitationAccepted = new Event3();
|
|
2298
|
-
this._removedCreated = new Event3();
|
|
2299
|
-
this._removedAccepted = new Event3();
|
|
2300
|
-
this._saved = new Event3();
|
|
2301
|
-
this._persistentInvitationsLoadedEvent = new Event3();
|
|
2302
|
-
this._persistentInvitationsLoaded = false;
|
|
2232
|
+
constructor(_invitationsManager) {
|
|
2233
|
+
this._invitationsManager = _invitationsManager;
|
|
2303
2234
|
}
|
|
2304
2235
|
// TODO(burdon): Guest/host label.
|
|
2305
2236
|
getLoggingContext() {
|
|
2306
2237
|
return {};
|
|
2307
2238
|
}
|
|
2308
2239
|
createInvitation(options) {
|
|
2309
|
-
let invitation;
|
|
2310
|
-
const savePersistentInvitationCtx = new Context6();
|
|
2311
|
-
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
2312
|
-
if (existingInvitation) {
|
|
2313
|
-
invitation = existingInvitation;
|
|
2314
|
-
} else {
|
|
2315
|
-
const handler = this._getHandler(options);
|
|
2316
|
-
invitation = this._invitationsHandler.createInvitation(handler, options);
|
|
2317
|
-
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
2318
|
-
this._invitationCreated.emit(invitation.get());
|
|
2319
|
-
}
|
|
2320
2240
|
return new Stream8(({ next, close }) => {
|
|
2321
|
-
|
|
2322
|
-
scheduleTask3(savePersistentInvitationCtx, async () => {
|
|
2323
|
-
try {
|
|
2324
|
-
await this._metadataStore.addInvitation(invitation.get());
|
|
2325
|
-
this._saved.emit(invitation.get());
|
|
2326
|
-
} catch (err) {
|
|
2327
|
-
close(err);
|
|
2328
|
-
}
|
|
2329
|
-
});
|
|
2330
|
-
}
|
|
2331
|
-
invitation.subscribe((invitation2) => {
|
|
2332
|
-
next(invitation2);
|
|
2333
|
-
}, async (err) => {
|
|
2334
|
-
await savePersistentInvitationCtx.dispose();
|
|
2335
|
-
close(err);
|
|
2336
|
-
}, async () => {
|
|
2337
|
-
close();
|
|
2338
|
-
if (invitation.get().persistent) {
|
|
2339
|
-
await savePersistentInvitationCtx.dispose();
|
|
2340
|
-
await this._metadataStore.removeInvitation(invitation.get().invitationId);
|
|
2341
|
-
}
|
|
2342
|
-
this._createInvitations.delete(invitation.get().invitationId);
|
|
2343
|
-
if (!invitation.get().multiUse) {
|
|
2344
|
-
this._removedCreated.emit(invitation.get());
|
|
2345
|
-
}
|
|
2346
|
-
});
|
|
2241
|
+
void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
|
|
2347
2242
|
});
|
|
2348
2243
|
}
|
|
2349
|
-
|
|
2350
|
-
const
|
|
2351
|
-
const freshInvitations = persistentInvitations.filter(async (invitation) => !hasInvitationExpired(invitation));
|
|
2352
|
-
const cInvitations = freshInvitations.map((persistentInvitation) => {
|
|
2353
|
-
invariant7(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
2354
|
-
F: __dxlog_file8,
|
|
2355
|
-
L: 109,
|
|
2356
|
-
S: this,
|
|
2357
|
-
A: [
|
|
2358
|
-
"!this._createInvitations.get(persistentInvitation.invitationId)",
|
|
2359
|
-
"'invitation already exists'"
|
|
2360
|
-
]
|
|
2361
|
-
});
|
|
2362
|
-
const handler = this._getHandler(persistentInvitation);
|
|
2363
|
-
const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
|
|
2364
|
-
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
2365
|
-
this._invitationCreated.emit(invitation.get());
|
|
2366
|
-
return persistentInvitation;
|
|
2367
|
-
});
|
|
2368
|
-
this._persistentInvitationsLoadedEvent.emit();
|
|
2369
|
-
this._persistentInvitationsLoaded = true;
|
|
2370
|
-
return {
|
|
2371
|
-
invitations: cInvitations
|
|
2372
|
-
};
|
|
2373
|
-
}
|
|
2374
|
-
acceptInvitation({ invitation: options, deviceProfile }) {
|
|
2375
|
-
let invitation;
|
|
2376
|
-
if (deviceProfile) {
|
|
2377
|
-
invariant7(options.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2378
|
-
F: __dxlog_file8,
|
|
2379
|
-
L: 127,
|
|
2380
|
-
S: this,
|
|
2381
|
-
A: [
|
|
2382
|
-
"options.kind === Invitation.Kind.DEVICE",
|
|
2383
|
-
"'deviceProfile provided for non-device invitation'"
|
|
2384
|
-
]
|
|
2385
|
-
});
|
|
2386
|
-
}
|
|
2387
|
-
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
2388
|
-
if (existingInvitation) {
|
|
2389
|
-
invitation = existingInvitation;
|
|
2390
|
-
} else {
|
|
2391
|
-
const handler = this._getHandler(options);
|
|
2392
|
-
invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
|
|
2393
|
-
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
2394
|
-
this._invitationAccepted.emit(invitation.get());
|
|
2395
|
-
}
|
|
2244
|
+
acceptInvitation(request) {
|
|
2245
|
+
const invitation = this._invitationsManager.acceptInvitation(request);
|
|
2396
2246
|
return new Stream8(({ next, close }) => {
|
|
2397
|
-
invitation.subscribe(
|
|
2398
|
-
next(invitation2);
|
|
2399
|
-
}, (err) => {
|
|
2400
|
-
close(err);
|
|
2401
|
-
}, () => {
|
|
2402
|
-
close();
|
|
2403
|
-
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
2404
|
-
if (!invitation.get().multiUse) {
|
|
2405
|
-
this._removedAccepted.emit(invitation.get());
|
|
2406
|
-
}
|
|
2407
|
-
});
|
|
2247
|
+
invitation.subscribe(next, close, close);
|
|
2408
2248
|
});
|
|
2409
2249
|
}
|
|
2410
|
-
async authenticate(
|
|
2411
|
-
|
|
2412
|
-
F: __dxlog_file8,
|
|
2413
|
-
L: 160,
|
|
2414
|
-
S: this,
|
|
2415
|
-
C: (f, a) => f(...a)
|
|
2416
|
-
});
|
|
2417
|
-
invariant7(invitationId, void 0, {
|
|
2418
|
-
F: __dxlog_file8,
|
|
2419
|
-
L: 161,
|
|
2420
|
-
S: this,
|
|
2421
|
-
A: [
|
|
2422
|
-
"invitationId",
|
|
2423
|
-
""
|
|
2424
|
-
]
|
|
2425
|
-
});
|
|
2426
|
-
const observable = this._acceptInvitations.get(invitationId);
|
|
2427
|
-
if (!observable) {
|
|
2428
|
-
log6.warn("invalid invitation", {
|
|
2429
|
-
invitationId
|
|
2430
|
-
}, {
|
|
2431
|
-
F: __dxlog_file8,
|
|
2432
|
-
L: 164,
|
|
2433
|
-
S: this,
|
|
2434
|
-
C: (f, a) => f(...a)
|
|
2435
|
-
});
|
|
2436
|
-
} else {
|
|
2437
|
-
await observable.authenticate(authCode);
|
|
2438
|
-
}
|
|
2250
|
+
async authenticate(request) {
|
|
2251
|
+
return this._invitationsManager.authenticate(request);
|
|
2439
2252
|
}
|
|
2440
|
-
async cancelInvitation(
|
|
2441
|
-
|
|
2442
|
-
invitationId
|
|
2443
|
-
}, {
|
|
2444
|
-
F: __dxlog_file8,
|
|
2445
|
-
L: 171,
|
|
2446
|
-
S: this,
|
|
2447
|
-
C: (f, a) => f(...a)
|
|
2448
|
-
});
|
|
2449
|
-
invariant7(invitationId, void 0, {
|
|
2450
|
-
F: __dxlog_file8,
|
|
2451
|
-
L: 172,
|
|
2452
|
-
S: this,
|
|
2453
|
-
A: [
|
|
2454
|
-
"invitationId",
|
|
2455
|
-
""
|
|
2456
|
-
]
|
|
2457
|
-
});
|
|
2458
|
-
const created = this._createInvitations.get(invitationId);
|
|
2459
|
-
const accepted = this._acceptInvitations.get(invitationId);
|
|
2460
|
-
if (created) {
|
|
2461
|
-
await created.cancel();
|
|
2462
|
-
this._createInvitations.delete(invitationId);
|
|
2463
|
-
this._removedCreated.emit(created.get());
|
|
2464
|
-
if (created.get().persistent) {
|
|
2465
|
-
await this._metadataStore.removeInvitation(created.get().invitationId);
|
|
2466
|
-
}
|
|
2467
|
-
} else if (accepted) {
|
|
2468
|
-
await accepted.cancel();
|
|
2469
|
-
this._acceptInvitations.delete(invitationId);
|
|
2470
|
-
this._removedAccepted.emit(accepted.get());
|
|
2471
|
-
}
|
|
2253
|
+
async cancelInvitation(request) {
|
|
2254
|
+
return this._invitationsManager.cancelInvitation(request);
|
|
2472
2255
|
}
|
|
2473
2256
|
queryInvitations() {
|
|
2474
2257
|
return new Stream8(({ next, ctx }) => {
|
|
2475
|
-
this.
|
|
2258
|
+
this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
|
|
2476
2259
|
next({
|
|
2477
2260
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2478
2261
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
@@ -2481,7 +2264,7 @@ var InvitationsServiceImpl = class {
|
|
|
2481
2264
|
]
|
|
2482
2265
|
});
|
|
2483
2266
|
});
|
|
2484
|
-
this.
|
|
2267
|
+
this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
|
|
2485
2268
|
next({
|
|
2486
2269
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2487
2270
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
@@ -2490,7 +2273,7 @@ var InvitationsServiceImpl = class {
|
|
|
2490
2273
|
]
|
|
2491
2274
|
});
|
|
2492
2275
|
});
|
|
2493
|
-
this.
|
|
2276
|
+
this._invitationsManager.removedCreated.on(ctx, (invitation) => {
|
|
2494
2277
|
next({
|
|
2495
2278
|
action: QueryInvitationsResponse.Action.REMOVED,
|
|
2496
2279
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
@@ -2499,7 +2282,7 @@ var InvitationsServiceImpl = class {
|
|
|
2499
2282
|
]
|
|
2500
2283
|
});
|
|
2501
2284
|
});
|
|
2502
|
-
this.
|
|
2285
|
+
this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
|
|
2503
2286
|
next({
|
|
2504
2287
|
action: QueryInvitationsResponse.Action.REMOVED,
|
|
2505
2288
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
@@ -2508,7 +2291,7 @@ var InvitationsServiceImpl = class {
|
|
|
2508
2291
|
]
|
|
2509
2292
|
});
|
|
2510
2293
|
});
|
|
2511
|
-
this.
|
|
2294
|
+
this._invitationsManager.saved.on(ctx, (invitation) => {
|
|
2512
2295
|
next({
|
|
2513
2296
|
action: QueryInvitationsResponse.Action.SAVED,
|
|
2514
2297
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
@@ -2520,40 +2303,34 @@ var InvitationsServiceImpl = class {
|
|
|
2520
2303
|
next({
|
|
2521
2304
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2522
2305
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
2523
|
-
invitations:
|
|
2306
|
+
invitations: this._invitationsManager.getCreatedInvitations(),
|
|
2524
2307
|
existing: true
|
|
2525
2308
|
});
|
|
2526
2309
|
next({
|
|
2527
2310
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2528
2311
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
2529
|
-
invitations:
|
|
2312
|
+
invitations: this._invitationsManager.getAcceptedInvitations(),
|
|
2530
2313
|
existing: true
|
|
2531
2314
|
});
|
|
2532
|
-
|
|
2315
|
+
this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
|
|
2533
2316
|
next({
|
|
2534
2317
|
action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
|
|
2535
2318
|
type: QueryInvitationsResponse.Type.CREATED
|
|
2536
2319
|
});
|
|
2537
|
-
}
|
|
2538
|
-
this._persistentInvitationsLoadedEvent.on(ctx, () => {
|
|
2539
|
-
next({
|
|
2540
|
-
action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
|
|
2541
|
-
type: QueryInvitationsResponse.Type.CREATED
|
|
2542
|
-
});
|
|
2543
|
-
});
|
|
2544
|
-
}
|
|
2320
|
+
});
|
|
2545
2321
|
});
|
|
2546
2322
|
}
|
|
2547
2323
|
};
|
|
2548
2324
|
|
|
2549
2325
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2550
|
-
import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
|
|
2326
|
+
import { createAdmissionCredentials, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
|
|
2551
2327
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
2552
|
-
import { invariant as
|
|
2553
|
-
import { log as
|
|
2328
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2329
|
+
import { log as log6 } from "@dxos/log";
|
|
2554
2330
|
import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
|
|
2555
|
-
import { Invitation as
|
|
2556
|
-
|
|
2331
|
+
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2332
|
+
import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2333
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2557
2334
|
var SpaceInvitationProtocol = class {
|
|
2558
2335
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2559
2336
|
this._spaceManager = _spaceManager;
|
|
@@ -2569,14 +2346,14 @@ var SpaceInvitationProtocol = class {
|
|
|
2569
2346
|
}
|
|
2570
2347
|
getInvitationContext() {
|
|
2571
2348
|
return {
|
|
2572
|
-
kind:
|
|
2349
|
+
kind: Invitation4.Kind.SPACE,
|
|
2573
2350
|
spaceKey: this._spaceKey
|
|
2574
2351
|
};
|
|
2575
2352
|
}
|
|
2576
|
-
async admit(request, guestProfile) {
|
|
2577
|
-
|
|
2578
|
-
F:
|
|
2579
|
-
L:
|
|
2353
|
+
async admit(invitation, request, guestProfile) {
|
|
2354
|
+
invariant7(this._spaceKey, void 0, {
|
|
2355
|
+
F: __dxlog_file8,
|
|
2356
|
+
L: 55,
|
|
2580
2357
|
S: this,
|
|
2581
2358
|
A: [
|
|
2582
2359
|
"this._spaceKey",
|
|
@@ -2584,18 +2361,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2584
2361
|
]
|
|
2585
2362
|
});
|
|
2586
2363
|
const space = await this._spaceManager.spaces.get(this._spaceKey);
|
|
2587
|
-
|
|
2588
|
-
F:
|
|
2589
|
-
L:
|
|
2364
|
+
invariant7(space, void 0, {
|
|
2365
|
+
F: __dxlog_file8,
|
|
2366
|
+
L: 57,
|
|
2590
2367
|
S: this,
|
|
2591
2368
|
A: [
|
|
2592
2369
|
"space",
|
|
2593
2370
|
""
|
|
2594
2371
|
]
|
|
2595
2372
|
});
|
|
2596
|
-
|
|
2597
|
-
F:
|
|
2598
|
-
L:
|
|
2373
|
+
invariant7(request.space, void 0, {
|
|
2374
|
+
F: __dxlog_file8,
|
|
2375
|
+
L: 59,
|
|
2599
2376
|
S: this,
|
|
2600
2377
|
A: [
|
|
2601
2378
|
"request.space",
|
|
@@ -2603,19 +2380,19 @@ var SpaceInvitationProtocol = class {
|
|
|
2603
2380
|
]
|
|
2604
2381
|
});
|
|
2605
2382
|
const { identityKey, deviceKey } = request.space;
|
|
2606
|
-
|
|
2383
|
+
log6("writing guest credentials", {
|
|
2607
2384
|
host: this._signingContext.deviceKey,
|
|
2608
2385
|
guest: deviceKey
|
|
2609
2386
|
}, {
|
|
2610
|
-
F:
|
|
2611
|
-
L:
|
|
2387
|
+
F: __dxlog_file8,
|
|
2388
|
+
L: 62,
|
|
2612
2389
|
S: this,
|
|
2613
2390
|
C: (f, a) => f(...a)
|
|
2614
2391
|
});
|
|
2615
|
-
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
|
|
2616
|
-
|
|
2617
|
-
F:
|
|
2618
|
-
L:
|
|
2392
|
+
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
|
|
2393
|
+
invariant7(credentials[0].credential, void 0, {
|
|
2394
|
+
F: __dxlog_file8,
|
|
2395
|
+
L: 74,
|
|
2619
2396
|
S: this,
|
|
2620
2397
|
A: [
|
|
2621
2398
|
"credentials[0].credential",
|
|
@@ -2623,9 +2400,9 @@ var SpaceInvitationProtocol = class {
|
|
|
2623
2400
|
]
|
|
2624
2401
|
});
|
|
2625
2402
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2626
|
-
|
|
2627
|
-
F:
|
|
2628
|
-
L:
|
|
2403
|
+
invariant7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2404
|
+
F: __dxlog_file8,
|
|
2405
|
+
L: 76,
|
|
2629
2406
|
S: this,
|
|
2630
2407
|
A: [
|
|
2631
2408
|
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -2640,6 +2417,69 @@ var SpaceInvitationProtocol = class {
|
|
|
2640
2417
|
}
|
|
2641
2418
|
};
|
|
2642
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
|
+
}
|
|
2643
2483
|
checkInvitation(invitation) {
|
|
2644
2484
|
if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
|
|
2645
2485
|
return new AlreadyJoinedError2("Already joined space.");
|
|
@@ -2663,9 +2503,9 @@ var SpaceInvitationProtocol = class {
|
|
|
2663
2503
|
};
|
|
2664
2504
|
}
|
|
2665
2505
|
async accept(response) {
|
|
2666
|
-
|
|
2667
|
-
F:
|
|
2668
|
-
L:
|
|
2506
|
+
invariant7(response.space, void 0, {
|
|
2507
|
+
F: __dxlog_file8,
|
|
2508
|
+
L: 149,
|
|
2669
2509
|
S: this,
|
|
2670
2510
|
A: [
|
|
2671
2511
|
"response.space",
|
|
@@ -2674,18 +2514,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2674
2514
|
});
|
|
2675
2515
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
2676
2516
|
const assertion = getCredentialAssertion(credential);
|
|
2677
|
-
|
|
2678
|
-
F:
|
|
2679
|
-
L:
|
|
2517
|
+
invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
2518
|
+
F: __dxlog_file8,
|
|
2519
|
+
L: 152,
|
|
2680
2520
|
S: this,
|
|
2681
2521
|
A: [
|
|
2682
2522
|
"assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
2683
2523
|
"'Invalid credential'"
|
|
2684
2524
|
]
|
|
2685
2525
|
});
|
|
2686
|
-
|
|
2687
|
-
F:
|
|
2688
|
-
L:
|
|
2526
|
+
invariant7(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
2527
|
+
F: __dxlog_file8,
|
|
2528
|
+
L: 153,
|
|
2689
2529
|
S: this,
|
|
2690
2530
|
A: [
|
|
2691
2531
|
"credential.subject.id.equals(this._signingContext.identityKey)",
|
|
@@ -2708,6 +2548,295 @@ var SpaceInvitationProtocol = class {
|
|
|
2708
2548
|
}
|
|
2709
2549
|
};
|
|
2710
2550
|
|
|
2551
|
+
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
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";
|
|
2556
|
+
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2557
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2558
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2559
|
+
import { log as log7 } from "@dxos/log";
|
|
2560
|
+
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2561
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
2562
|
+
var InvitationsManager = class {
|
|
2563
|
+
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
2564
|
+
this._invitationsHandler = _invitationsHandler;
|
|
2565
|
+
this._getHandler = _getHandler;
|
|
2566
|
+
this._metadataStore = _metadataStore;
|
|
2567
|
+
this._createInvitations = /* @__PURE__ */ new Map();
|
|
2568
|
+
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
2569
|
+
this.invitationCreated = new Event3();
|
|
2570
|
+
this.invitationAccepted = new Event3();
|
|
2571
|
+
this.removedCreated = new Event3();
|
|
2572
|
+
this.removedAccepted = new Event3();
|
|
2573
|
+
this.saved = new Event3();
|
|
2574
|
+
this._persistentInvitationsLoadedEvent = new Event3();
|
|
2575
|
+
this._persistentInvitationsLoaded = false;
|
|
2576
|
+
}
|
|
2577
|
+
async createInvitation(options) {
|
|
2578
|
+
if (options.invitationId) {
|
|
2579
|
+
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
2580
|
+
if (existingInvitation) {
|
|
2581
|
+
return existingInvitation;
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
const handler = this._getHandler(options);
|
|
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());
|
|
2594
|
+
}
|
|
2595
|
+
});
|
|
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;
|
|
2610
|
+
}
|
|
2611
|
+
async loadPersistentInvitations() {
|
|
2612
|
+
if (this._persistentInvitationsLoaded) {
|
|
2613
|
+
const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
|
|
2614
|
+
return {
|
|
2615
|
+
invitations
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
try {
|
|
2619
|
+
const persistentInvitations = this._metadataStore.getInvitations();
|
|
2620
|
+
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
2621
|
+
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
2622
|
+
invariant8(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
2623
|
+
F: __dxlog_file9,
|
|
2624
|
+
L: 97,
|
|
2625
|
+
S: this,
|
|
2626
|
+
A: [
|
|
2627
|
+
"!this._createInvitations.get(persistentInvitation.invitationId)",
|
|
2628
|
+
"'invitation already exists'"
|
|
2629
|
+
]
|
|
2630
|
+
});
|
|
2631
|
+
return this.createInvitation({
|
|
2632
|
+
...persistentInvitation,
|
|
2633
|
+
persistent: false
|
|
2634
|
+
});
|
|
2635
|
+
});
|
|
2636
|
+
const cInvitations = await Promise.all(loadTasks);
|
|
2637
|
+
return {
|
|
2638
|
+
invitations: cInvitations.map((invitation) => invitation.get())
|
|
2639
|
+
};
|
|
2640
|
+
} catch (err) {
|
|
2641
|
+
log7.catch(err, void 0, {
|
|
2642
|
+
F: __dxlog_file9,
|
|
2643
|
+
L: 104,
|
|
2644
|
+
S: this,
|
|
2645
|
+
C: (f, a) => f(...a)
|
|
2646
|
+
});
|
|
2647
|
+
return {
|
|
2648
|
+
invitations: []
|
|
2649
|
+
};
|
|
2650
|
+
} finally {
|
|
2651
|
+
this._persistentInvitationsLoadedEvent.emit();
|
|
2652
|
+
this._persistentInvitationsLoaded = true;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
acceptInvitation(request) {
|
|
2656
|
+
const options = request.invitation;
|
|
2657
|
+
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
2658
|
+
if (existingInvitation) {
|
|
2659
|
+
return existingInvitation;
|
|
2660
|
+
}
|
|
2661
|
+
const handler = this._getHandler(options);
|
|
2662
|
+
const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
|
|
2663
|
+
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
2664
|
+
this.invitationAccepted.emit(invitation.get());
|
|
2665
|
+
this._onInvitationComplete(invitation, () => {
|
|
2666
|
+
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
2667
|
+
this.removedAccepted.emit(invitation.get());
|
|
2668
|
+
});
|
|
2669
|
+
return invitation;
|
|
2670
|
+
}
|
|
2671
|
+
async authenticate({ invitationId, authCode }) {
|
|
2672
|
+
log7("authenticating...", void 0, {
|
|
2673
|
+
F: __dxlog_file9,
|
|
2674
|
+
L: 133,
|
|
2675
|
+
S: this,
|
|
2676
|
+
C: (f, a) => f(...a)
|
|
2677
|
+
});
|
|
2678
|
+
invariant8(invitationId, void 0, {
|
|
2679
|
+
F: __dxlog_file9,
|
|
2680
|
+
L: 134,
|
|
2681
|
+
S: this,
|
|
2682
|
+
A: [
|
|
2683
|
+
"invitationId",
|
|
2684
|
+
""
|
|
2685
|
+
]
|
|
2686
|
+
});
|
|
2687
|
+
const observable = this._acceptInvitations.get(invitationId);
|
|
2688
|
+
if (!observable) {
|
|
2689
|
+
log7.warn("invalid invitation", {
|
|
2690
|
+
invitationId
|
|
2691
|
+
}, {
|
|
2692
|
+
F: __dxlog_file9,
|
|
2693
|
+
L: 137,
|
|
2694
|
+
S: this,
|
|
2695
|
+
C: (f, a) => f(...a)
|
|
2696
|
+
});
|
|
2697
|
+
} else {
|
|
2698
|
+
await observable.authenticate(authCode);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
async cancelInvitation({ invitationId }) {
|
|
2702
|
+
log7("cancelInvitation...", {
|
|
2703
|
+
invitationId
|
|
2704
|
+
}, {
|
|
2705
|
+
F: __dxlog_file9,
|
|
2706
|
+
L: 144,
|
|
2707
|
+
S: this,
|
|
2708
|
+
C: (f, a) => f(...a)
|
|
2709
|
+
});
|
|
2710
|
+
invariant8(invitationId, void 0, {
|
|
2711
|
+
F: __dxlog_file9,
|
|
2712
|
+
L: 145,
|
|
2713
|
+
S: this,
|
|
2714
|
+
A: [
|
|
2715
|
+
"invitationId",
|
|
2716
|
+
""
|
|
2717
|
+
]
|
|
2718
|
+
});
|
|
2719
|
+
const created = this._createInvitations.get(invitationId);
|
|
2720
|
+
if (created) {
|
|
2721
|
+
if (created.get().persistent) {
|
|
2722
|
+
await this._metadataStore.removeInvitation(invitationId);
|
|
2723
|
+
}
|
|
2724
|
+
await created.cancel();
|
|
2725
|
+
this._createInvitations.delete(invitationId);
|
|
2726
|
+
this.removedCreated.emit(created.get());
|
|
2727
|
+
return;
|
|
2728
|
+
}
|
|
2729
|
+
const accepted = this._acceptInvitations.get(invitationId);
|
|
2730
|
+
if (accepted) {
|
|
2731
|
+
await accepted.cancel();
|
|
2732
|
+
this._acceptInvitations.delete(invitationId);
|
|
2733
|
+
this.removedAccepted.emit(accepted.get());
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
getCreatedInvitations() {
|
|
2737
|
+
return [
|
|
2738
|
+
...this._createInvitations.values()
|
|
2739
|
+
].map((i) => i.get());
|
|
2740
|
+
}
|
|
2741
|
+
getAcceptedInvitations() {
|
|
2742
|
+
return [
|
|
2743
|
+
...this._acceptInvitations.values()
|
|
2744
|
+
].map((i) => i.get());
|
|
2745
|
+
}
|
|
2746
|
+
onPersistentInvitationsLoaded(ctx, callback) {
|
|
2747
|
+
if (this._persistentInvitationsLoaded) {
|
|
2748
|
+
callback();
|
|
2749
|
+
} else {
|
|
2750
|
+
this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
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)
|
|
2789
|
+
});
|
|
2790
|
+
stream.complete();
|
|
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
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
async _safeDeleteInvitation(invitation) {
|
|
2822
|
+
try {
|
|
2823
|
+
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
2824
|
+
} catch (err) {
|
|
2825
|
+
log7.catch(err, void 0, {
|
|
2826
|
+
F: __dxlog_file9,
|
|
2827
|
+
L: 260,
|
|
2828
|
+
S: this,
|
|
2829
|
+
C: (f, a) => f(...a)
|
|
2830
|
+
});
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
_onInvitationComplete(invitation, callback) {
|
|
2834
|
+
invitation.subscribe(() => {
|
|
2835
|
+
}, () => {
|
|
2836
|
+
}, callback);
|
|
2837
|
+
}
|
|
2838
|
+
};
|
|
2839
|
+
|
|
2711
2840
|
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
2712
2841
|
import { Stream as Stream9 } from "@dxos/codec-protobuf";
|
|
2713
2842
|
import { raise } from "@dxos/debug";
|
|
@@ -2790,15 +2919,15 @@ ClientRpcServer = _ts_decorate3([
|
|
|
2790
2919
|
], ClientRpcServer);
|
|
2791
2920
|
|
|
2792
2921
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2793
|
-
import { Event as Event6, asyncTimeout, scheduleTask as
|
|
2922
|
+
import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
2794
2923
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2795
2924
|
import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
|
|
2796
2925
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
2797
|
-
import { TYPE_PROPERTIES } from "@dxos/echo-db";
|
|
2798
2926
|
import { createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
2799
2927
|
import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
|
|
2928
|
+
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
2800
2929
|
import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
|
|
2801
|
-
import { PublicKey as
|
|
2930
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2802
2931
|
import { log as log9 } from "@dxos/log";
|
|
2803
2932
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
2804
2933
|
import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -2846,10 +2975,10 @@ var AutomergeSpaceState = class {
|
|
|
2846
2975
|
};
|
|
2847
2976
|
|
|
2848
2977
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
2849
|
-
import { DeferredTask, Event as Event5, scheduleTask as
|
|
2978
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
|
|
2850
2979
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
2851
2980
|
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2852
|
-
import { PublicKey as
|
|
2981
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2853
2982
|
import { log as log8 } from "@dxos/log";
|
|
2854
2983
|
import { schema as schema3 } from "@dxos/protocols";
|
|
2855
2984
|
import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
|
|
@@ -2864,8 +2993,8 @@ var NotarizationPlugin = class {
|
|
|
2864
2993
|
this._ctx = new Context7();
|
|
2865
2994
|
this._extensionOpened = new Event5();
|
|
2866
2995
|
this._extensions = /* @__PURE__ */ new Set();
|
|
2867
|
-
this._processedCredentials = new ComplexSet2(
|
|
2868
|
-
this._processCredentialsTriggers = new ComplexMap2(
|
|
2996
|
+
this._processedCredentials = new ComplexSet2(PublicKey8.hash);
|
|
2997
|
+
this._processCredentialsTriggers = new ComplexMap2(PublicKey8.hash);
|
|
2869
2998
|
}
|
|
2870
2999
|
get hasWriter() {
|
|
2871
3000
|
return !!this._writer;
|
|
@@ -2913,7 +3042,7 @@ var NotarizationPlugin = class {
|
|
|
2913
3042
|
});
|
|
2914
3043
|
opCtx?.onDispose(() => ctx.dispose());
|
|
2915
3044
|
if (timeout !== 0) {
|
|
2916
|
-
|
|
3045
|
+
scheduleTask3(ctx, () => {
|
|
2917
3046
|
log8.warn("Notarization timeout", {
|
|
2918
3047
|
timeout,
|
|
2919
3048
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
@@ -2947,7 +3076,7 @@ var NotarizationPlugin = class {
|
|
|
2947
3076
|
C: (f, a) => f(...a)
|
|
2948
3077
|
});
|
|
2949
3078
|
peersTried.clear();
|
|
2950
|
-
|
|
3079
|
+
scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
|
|
2951
3080
|
return;
|
|
2952
3081
|
}
|
|
2953
3082
|
peersTried.add(peer);
|
|
@@ -3150,7 +3279,7 @@ var DataSpace = class {
|
|
|
3150
3279
|
this._callbacks = params.callbacks ?? {};
|
|
3151
3280
|
this._automergeHost = params.automergeHost;
|
|
3152
3281
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
3153
|
-
trustedKeysProvider: () => new ComplexSet3(
|
|
3282
|
+
trustedKeysProvider: () => new ComplexSet3(PublicKey9.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
|
|
3154
3283
|
update: this._inner.stateUpdate,
|
|
3155
3284
|
authTimeout: AUTH_TIMEOUT2
|
|
3156
3285
|
});
|
|
@@ -3252,7 +3381,7 @@ var DataSpace = class {
|
|
|
3252
3381
|
* Initialize the data pipeline in a separate task.
|
|
3253
3382
|
*/
|
|
3254
3383
|
initializeDataPipelineAsync() {
|
|
3255
|
-
|
|
3384
|
+
scheduleTask4(this._ctx, async () => {
|
|
3256
3385
|
try {
|
|
3257
3386
|
this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
|
|
3258
3387
|
await this.initializeDataPipeline();
|
|
@@ -3657,17 +3786,17 @@ import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeak
|
|
|
3657
3786
|
import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
|
|
3658
3787
|
import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
3659
3788
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3660
|
-
import { PublicKey as
|
|
3789
|
+
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3661
3790
|
import { log as log10 } from "@dxos/log";
|
|
3662
3791
|
import { trace as trace7 } from "@dxos/protocols";
|
|
3663
|
-
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";
|
|
3664
3793
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
3665
3794
|
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
3666
3795
|
|
|
3667
3796
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
3668
3797
|
import { createCredential } from "@dxos/credentials";
|
|
3669
3798
|
import { failUndefined } from "@dxos/debug";
|
|
3670
|
-
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";
|
|
3671
3800
|
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
3672
3801
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
3673
3802
|
const credentials = [
|
|
@@ -3687,7 +3816,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
|
3687
3816
|
assertion: {
|
|
3688
3817
|
"@type": "dxos.halo.credentials.SpaceMember",
|
|
3689
3818
|
spaceKey: space.key,
|
|
3690
|
-
role:
|
|
3819
|
+
role: SpaceMember2.Role.ADMIN,
|
|
3691
3820
|
profile: signingContext.getProfile(),
|
|
3692
3821
|
genesisFeedKey: space.controlFeedKey ?? failUndefined()
|
|
3693
3822
|
}
|
|
@@ -3749,18 +3878,19 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
|
|
|
3749
3878
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
3750
3879
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
3751
3880
|
var DataSpaceManager = class {
|
|
3752
|
-
constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
|
|
3881
|
+
constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, _invitationsManager, params) {
|
|
3753
3882
|
this._spaceManager = _spaceManager;
|
|
3754
3883
|
this._metadataStore = _metadataStore;
|
|
3755
3884
|
this._keyring = _keyring;
|
|
3756
3885
|
this._signingContext = _signingContext;
|
|
3757
3886
|
this._feedStore = _feedStore;
|
|
3758
3887
|
this._automergeHost = _automergeHost;
|
|
3888
|
+
this._invitationsManager = _invitationsManager;
|
|
3759
3889
|
this._ctx = new Context9();
|
|
3760
3890
|
this.updated = new Event7();
|
|
3761
|
-
this._spaces = new ComplexMap3(
|
|
3891
|
+
this._spaces = new ComplexMap3(PublicKey10.hash);
|
|
3762
3892
|
this._isOpen = false;
|
|
3763
|
-
this._instanceId =
|
|
3893
|
+
this._instanceId = PublicKey10.random().toHex();
|
|
3764
3894
|
const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
|
|
3765
3895
|
this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
|
|
3766
3896
|
this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
|
|
@@ -3772,7 +3902,7 @@ var DataSpaceManager = class {
|
|
|
3772
3902
|
async open() {
|
|
3773
3903
|
log10("open", void 0, {
|
|
3774
3904
|
F: __dxlog_file12,
|
|
3775
|
-
L:
|
|
3905
|
+
L: 101,
|
|
3776
3906
|
S: this,
|
|
3777
3907
|
C: (f, a) => f(...a)
|
|
3778
3908
|
});
|
|
@@ -3780,7 +3910,7 @@ var DataSpaceManager = class {
|
|
|
3780
3910
|
id: this._instanceId
|
|
3781
3911
|
}), {
|
|
3782
3912
|
F: __dxlog_file12,
|
|
3783
|
-
L:
|
|
3913
|
+
L: 102,
|
|
3784
3914
|
S: this,
|
|
3785
3915
|
C: (f, a) => f(...a)
|
|
3786
3916
|
});
|
|
@@ -3788,7 +3918,7 @@ var DataSpaceManager = class {
|
|
|
3788
3918
|
spaces: this._metadataStore.spaces.length
|
|
3789
3919
|
}, {
|
|
3790
3920
|
F: __dxlog_file12,
|
|
3791
|
-
L:
|
|
3921
|
+
L: 103,
|
|
3792
3922
|
S: this,
|
|
3793
3923
|
C: (f, a) => f(...a)
|
|
3794
3924
|
});
|
|
@@ -3798,7 +3928,7 @@ var DataSpaceManager = class {
|
|
|
3798
3928
|
spaceMetadata
|
|
3799
3929
|
}, {
|
|
3800
3930
|
F: __dxlog_file12,
|
|
3801
|
-
L:
|
|
3931
|
+
L: 107,
|
|
3802
3932
|
S: this,
|
|
3803
3933
|
C: (f, a) => f(...a)
|
|
3804
3934
|
});
|
|
@@ -3809,7 +3939,7 @@ var DataSpaceManager = class {
|
|
|
3809
3939
|
err
|
|
3810
3940
|
}, {
|
|
3811
3941
|
F: __dxlog_file12,
|
|
3812
|
-
L:
|
|
3942
|
+
L: 110,
|
|
3813
3943
|
S: this,
|
|
3814
3944
|
C: (f, a) => f(...a)
|
|
3815
3945
|
});
|
|
@@ -3826,7 +3956,7 @@ var DataSpaceManager = class {
|
|
|
3826
3956
|
id: this._instanceId
|
|
3827
3957
|
}), {
|
|
3828
3958
|
F: __dxlog_file12,
|
|
3829
|
-
L:
|
|
3959
|
+
L: 123,
|
|
3830
3960
|
S: this,
|
|
3831
3961
|
C: (f, a) => f(...a)
|
|
3832
3962
|
});
|
|
@@ -3834,7 +3964,7 @@ var DataSpaceManager = class {
|
|
|
3834
3964
|
async close() {
|
|
3835
3965
|
log10("close", void 0, {
|
|
3836
3966
|
F: __dxlog_file12,
|
|
3837
|
-
L:
|
|
3967
|
+
L: 128,
|
|
3838
3968
|
S: this,
|
|
3839
3969
|
C: (f, a) => f(...a)
|
|
3840
3970
|
});
|
|
@@ -3850,7 +3980,7 @@ var DataSpaceManager = class {
|
|
|
3850
3980
|
async createSpace() {
|
|
3851
3981
|
invariant11(this._isOpen, "Not open.", {
|
|
3852
3982
|
F: __dxlog_file12,
|
|
3853
|
-
L:
|
|
3983
|
+
L: 141,
|
|
3854
3984
|
S: this,
|
|
3855
3985
|
A: [
|
|
3856
3986
|
"this._isOpen",
|
|
@@ -3871,7 +4001,7 @@ var DataSpaceManager = class {
|
|
|
3871
4001
|
spaceKey
|
|
3872
4002
|
}, {
|
|
3873
4003
|
F: __dxlog_file12,
|
|
3874
|
-
L:
|
|
4004
|
+
L: 153,
|
|
3875
4005
|
S: this,
|
|
3876
4006
|
C: (f, a) => f(...a)
|
|
3877
4007
|
});
|
|
@@ -3887,7 +4017,7 @@ var DataSpaceManager = class {
|
|
|
3887
4017
|
const memberCredential = credentials[1];
|
|
3888
4018
|
invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
3889
4019
|
F: __dxlog_file12,
|
|
3890
|
-
L:
|
|
4020
|
+
L: 166,
|
|
3891
4021
|
S: this,
|
|
3892
4022
|
A: [
|
|
3893
4023
|
"getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -3905,13 +4035,13 @@ var DataSpaceManager = class {
|
|
|
3905
4035
|
opts
|
|
3906
4036
|
}, {
|
|
3907
4037
|
F: __dxlog_file12,
|
|
3908
|
-
L:
|
|
4038
|
+
L: 178,
|
|
3909
4039
|
S: this,
|
|
3910
4040
|
C: (f, a) => f(...a)
|
|
3911
4041
|
});
|
|
3912
4042
|
invariant11(this._isOpen, "Not open.", {
|
|
3913
4043
|
F: __dxlog_file12,
|
|
3914
|
-
L:
|
|
4044
|
+
L: 179,
|
|
3915
4045
|
S: this,
|
|
3916
4046
|
A: [
|
|
3917
4047
|
"this._isOpen",
|
|
@@ -3920,7 +4050,7 @@ var DataSpaceManager = class {
|
|
|
3920
4050
|
});
|
|
3921
4051
|
invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
3922
4052
|
F: __dxlog_file12,
|
|
3923
|
-
L:
|
|
4053
|
+
L: 180,
|
|
3924
4054
|
S: this,
|
|
3925
4055
|
A: [
|
|
3926
4056
|
"!this._spaces.has(opts.spaceKey)",
|
|
@@ -3955,7 +4085,7 @@ var DataSpaceManager = class {
|
|
|
3955
4085
|
metadata
|
|
3956
4086
|
}, {
|
|
3957
4087
|
F: __dxlog_file12,
|
|
3958
|
-
L:
|
|
4088
|
+
L: 213,
|
|
3959
4089
|
S: this,
|
|
3960
4090
|
C: (f, a) => f(...a)
|
|
3961
4091
|
});
|
|
@@ -3993,12 +4123,15 @@ var DataSpaceManager = class {
|
|
|
3993
4123
|
onAuthFailure: () => {
|
|
3994
4124
|
log10.warn("auth failure", void 0, {
|
|
3995
4125
|
F: __dxlog_file12,
|
|
3996
|
-
L:
|
|
4126
|
+
L: 250,
|
|
3997
4127
|
S: this,
|
|
3998
4128
|
C: (f, a) => f(...a)
|
|
3999
4129
|
});
|
|
4000
4130
|
},
|
|
4001
|
-
memberKey: this._signingContext.identityKey
|
|
4131
|
+
memberKey: this._signingContext.identityKey,
|
|
4132
|
+
onDelegatedInvitationStatusChange: (invitation, isActive) => {
|
|
4133
|
+
return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
|
|
4134
|
+
}
|
|
4002
4135
|
});
|
|
4003
4136
|
controlFeed && await space.setControlFeed(controlFeed);
|
|
4004
4137
|
dataFeed && await space.setDataFeed(dataFeed);
|
|
@@ -4017,7 +4150,7 @@ var DataSpaceManager = class {
|
|
|
4017
4150
|
space: space.key
|
|
4018
4151
|
}, {
|
|
4019
4152
|
F: __dxlog_file12,
|
|
4020
|
-
L:
|
|
4153
|
+
L: 271,
|
|
4021
4154
|
S: this,
|
|
4022
4155
|
C: (f, a) => f(...a)
|
|
4023
4156
|
});
|
|
@@ -4028,11 +4161,14 @@ var DataSpaceManager = class {
|
|
|
4028
4161
|
open: this._isOpen
|
|
4029
4162
|
}, {
|
|
4030
4163
|
F: __dxlog_file12,
|
|
4031
|
-
L:
|
|
4164
|
+
L: 274,
|
|
4032
4165
|
S: this,
|
|
4033
4166
|
C: (f, a) => f(...a)
|
|
4034
4167
|
});
|
|
4035
4168
|
if (this._isOpen) {
|
|
4169
|
+
await this._createDelegatedInvitations(dataSpace, [
|
|
4170
|
+
...space.spaceState.invitations.entries()
|
|
4171
|
+
]);
|
|
4036
4172
|
this.updated.emit();
|
|
4037
4173
|
}
|
|
4038
4174
|
},
|
|
@@ -4041,7 +4177,7 @@ var DataSpaceManager = class {
|
|
|
4041
4177
|
space: space.key
|
|
4042
4178
|
}, {
|
|
4043
4179
|
F: __dxlog_file12,
|
|
4044
|
-
L:
|
|
4180
|
+
L: 281,
|
|
4045
4181
|
S: this,
|
|
4046
4182
|
C: (f, a) => f(...a)
|
|
4047
4183
|
});
|
|
@@ -4059,6 +4195,41 @@ var DataSpaceManager = class {
|
|
|
4059
4195
|
this._spaces.set(metadata.key, dataSpace);
|
|
4060
4196
|
return dataSpace;
|
|
4061
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
|
+
}
|
|
4062
4233
|
};
|
|
4063
4234
|
_ts_decorate5([
|
|
4064
4235
|
synchronized2
|
|
@@ -4077,13 +4248,13 @@ DataSpaceManager = _ts_decorate5([
|
|
|
4077
4248
|
], DataSpaceManager);
|
|
4078
4249
|
|
|
4079
4250
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
4080
|
-
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as
|
|
4251
|
+
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
|
|
4081
4252
|
import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
4082
4253
|
import { raise as raise2 } from "@dxos/debug";
|
|
4083
4254
|
import { invariant as invariant12 } from "@dxos/invariant";
|
|
4084
4255
|
import { log as log11 } from "@dxos/log";
|
|
4085
4256
|
import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
|
|
4086
|
-
import { SpaceMember as
|
|
4257
|
+
import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4087
4258
|
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
4088
4259
|
var SpacesServiceImpl = class {
|
|
4089
4260
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
@@ -4134,7 +4305,7 @@ var SpacesServiceImpl = class {
|
|
|
4134
4305
|
}, {
|
|
4135
4306
|
maxFrequency: false ? void 0 : 2
|
|
4136
4307
|
});
|
|
4137
|
-
|
|
4308
|
+
scheduleTask5(ctx, async () => {
|
|
4138
4309
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4139
4310
|
const subscriptions = new EventSubscriptions2();
|
|
4140
4311
|
ctx.onDispose(() => subscriptions.clear());
|
|
@@ -4168,7 +4339,7 @@ var SpacesServiceImpl = class {
|
|
|
4168
4339
|
}
|
|
4169
4340
|
subscribeMessages({ spaceKey, channel }) {
|
|
4170
4341
|
return new Stream10(({ ctx, next }) => {
|
|
4171
|
-
|
|
4342
|
+
scheduleTask5(ctx, async () => {
|
|
4172
4343
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4173
4344
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
|
|
4174
4345
|
const handle = space.listen(getChannelId(channel), (message) => {
|
|
@@ -4187,7 +4358,7 @@ var SpacesServiceImpl = class {
|
|
|
4187
4358
|
}
|
|
4188
4359
|
};
|
|
4189
4360
|
ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
|
|
4190
|
-
|
|
4361
|
+
scheduleTask5(ctx, async () => {
|
|
4191
4362
|
await space.spaceState.addCredentialProcessor(processor);
|
|
4192
4363
|
if (noTail) {
|
|
4193
4364
|
close();
|
|
@@ -4281,7 +4452,7 @@ var SpacesServiceImpl = class {
|
|
|
4281
4452
|
identityKey: member.key,
|
|
4282
4453
|
profile: member.profile ?? {}
|
|
4283
4454
|
},
|
|
4284
|
-
presence: member.removed ?
|
|
4455
|
+
presence: member.removed ? SpaceMember3.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
|
|
4285
4456
|
peerStates: peers
|
|
4286
4457
|
};
|
|
4287
4458
|
}),
|
|
@@ -4300,20 +4471,19 @@ import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credent
|
|
|
4300
4471
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
4301
4472
|
import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
4302
4473
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
4303
|
-
import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
|
|
4474
|
+
import { IndexMetadataStore, IndexStore, Indexer, createStorageCallbacks } from "@dxos/indexing";
|
|
4304
4475
|
import { invariant as invariant13 } from "@dxos/invariant";
|
|
4305
4476
|
import { Keyring } from "@dxos/keyring";
|
|
4306
|
-
import { PublicKey as
|
|
4477
|
+
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4307
4478
|
import { log as log12 } from "@dxos/log";
|
|
4308
4479
|
import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
|
|
4309
|
-
import { Invitation as
|
|
4480
|
+
import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4310
4481
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
4311
4482
|
import { trace as Trace2 } from "@dxos/tracing";
|
|
4312
4483
|
import { safeInstanceof } from "@dxos/util";
|
|
4313
4484
|
|
|
4314
4485
|
// packages/sdk/client-services/src/packlets/indexing/util.ts
|
|
4315
4486
|
import { getHeads } from "@dxos/automerge/automerge";
|
|
4316
|
-
import { warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
|
|
4317
4487
|
import { idCodec } from "@dxos/protocols";
|
|
4318
4488
|
var createSelectedDocumentsIterator = (automergeHost) => (
|
|
4319
4489
|
/**
|
|
@@ -4324,8 +4494,10 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
4324
4494
|
async function* loadDocuments(ids) {
|
|
4325
4495
|
for (const id of ids) {
|
|
4326
4496
|
const { documentId, objectId } = idCodec.decode(id);
|
|
4327
|
-
const handle = automergeHost.repo.find(documentId);
|
|
4328
|
-
|
|
4497
|
+
const handle = automergeHost.repo.handles[documentId] ?? automergeHost.repo.find(documentId);
|
|
4498
|
+
if (!handle.isReady()) {
|
|
4499
|
+
await handle.whenReady();
|
|
4500
|
+
}
|
|
4329
4501
|
const doc = handle.docSync();
|
|
4330
4502
|
const hash = getHeads(doc).join("");
|
|
4331
4503
|
yield doc.objects?.[objectId] ? [
|
|
@@ -4338,57 +4510,6 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
4338
4510
|
}
|
|
4339
4511
|
}
|
|
4340
4512
|
);
|
|
4341
|
-
var createDocumentsIterator = (automergeHost) => (
|
|
4342
|
-
/**
|
|
4343
|
-
* Recursively get all object data blobs from Automerge Repo.
|
|
4344
|
-
* @param ids
|
|
4345
|
-
*/
|
|
4346
|
-
// TODO(mykola): Unload automerge handles after usage.
|
|
4347
|
-
async function* getAllDocuments() {
|
|
4348
|
-
const visited = /* @__PURE__ */ new Set();
|
|
4349
|
-
async function* getObjectsFromHandle(handle) {
|
|
4350
|
-
if (visited.has(handle.documentId)) {
|
|
4351
|
-
return;
|
|
4352
|
-
}
|
|
4353
|
-
await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
|
|
4354
|
-
const doc = handle.docSync();
|
|
4355
|
-
const heads = getHeads(doc);
|
|
4356
|
-
if (doc.objects) {
|
|
4357
|
-
yield Object.entries(doc.objects).map(([objectId, object]) => {
|
|
4358
|
-
return {
|
|
4359
|
-
id: idCodec.encode({
|
|
4360
|
-
documentId: handle.documentId,
|
|
4361
|
-
objectId
|
|
4362
|
-
}),
|
|
4363
|
-
object,
|
|
4364
|
-
currentHash: heads.join("")
|
|
4365
|
-
};
|
|
4366
|
-
});
|
|
4367
|
-
}
|
|
4368
|
-
if (doc.links) {
|
|
4369
|
-
for (const id of Object.values(doc.links)) {
|
|
4370
|
-
if (visited.has(id)) {
|
|
4371
|
-
continue;
|
|
4372
|
-
}
|
|
4373
|
-
const linkHandle = automergeHost.repo.find(id);
|
|
4374
|
-
for await (const result of getObjectsFromHandle(linkHandle)) {
|
|
4375
|
-
yield result;
|
|
4376
|
-
}
|
|
4377
|
-
}
|
|
4378
|
-
}
|
|
4379
|
-
visited.add(handle.documentId);
|
|
4380
|
-
}
|
|
4381
|
-
for (const handle of Object.values(automergeHost.repo.handles)) {
|
|
4382
|
-
if (visited.has(handle.documentId)) {
|
|
4383
|
-
continue;
|
|
4384
|
-
}
|
|
4385
|
-
for await (const result of getObjectsFromHandle(handle)) {
|
|
4386
|
-
yield result;
|
|
4387
|
-
}
|
|
4388
|
-
visited.add(handle.documentId);
|
|
4389
|
-
}
|
|
4390
|
-
}
|
|
4391
|
-
);
|
|
4392
4513
|
|
|
4393
4514
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
4394
4515
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
@@ -4412,7 +4533,7 @@ var ServiceContext = class extends Resource {
|
|
|
4412
4533
|
this._runtimeParams = _runtimeParams;
|
|
4413
4534
|
this.initialized = new Trigger5();
|
|
4414
4535
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
4415
|
-
this._instanceId =
|
|
4536
|
+
this._instanceId = PublicKey11.random().toHex();
|
|
4416
4537
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
4417
4538
|
this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
|
|
4418
4539
|
this.blobStore = new BlobStore(storage.createDirectory("blobs"));
|
|
@@ -4441,24 +4562,28 @@ var ServiceContext = class extends Resource {
|
|
|
4441
4562
|
this.automergeHost = new AutomergeHost({
|
|
4442
4563
|
directory: storage.createDirectory("automerge"),
|
|
4443
4564
|
db: level.sublevel("automerge"),
|
|
4444
|
-
|
|
4565
|
+
storageCallbacks: createStorageCallbacks({
|
|
4566
|
+
host: () => this.automergeHost,
|
|
4567
|
+
metadata: this.indexMetadata
|
|
4568
|
+
})
|
|
4445
4569
|
});
|
|
4446
4570
|
this.indexer = new Indexer({
|
|
4571
|
+
db: this.level,
|
|
4447
4572
|
indexStore: new IndexStore({
|
|
4448
|
-
|
|
4573
|
+
db: level.sublevel("index-storage")
|
|
4449
4574
|
}),
|
|
4450
4575
|
metadataStore: this.indexMetadata,
|
|
4451
|
-
loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
|
|
4452
|
-
getAllDocuments: createDocumentsIterator(this.automergeHost)
|
|
4576
|
+
loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
|
|
4453
4577
|
});
|
|
4454
4578
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
4455
|
-
this.
|
|
4579
|
+
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
4580
|
+
this._handlerFactories.set(Invitation7.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
|
|
4456
4581
|
}
|
|
4457
4582
|
async _open(ctx) {
|
|
4458
4583
|
await this._checkStorageVersion();
|
|
4459
4584
|
log12("opening...", void 0, {
|
|
4460
4585
|
F: __dxlog_file14,
|
|
4461
|
-
L:
|
|
4586
|
+
L: 164,
|
|
4462
4587
|
S: this,
|
|
4463
4588
|
C: (f, a) => f(...a)
|
|
4464
4589
|
});
|
|
@@ -4466,7 +4591,7 @@ var ServiceContext = class extends Resource {
|
|
|
4466
4591
|
id: this._instanceId
|
|
4467
4592
|
}), {
|
|
4468
4593
|
F: __dxlog_file14,
|
|
4469
|
-
L:
|
|
4594
|
+
L: 165,
|
|
4470
4595
|
S: this,
|
|
4471
4596
|
C: (f, a) => f(...a)
|
|
4472
4597
|
});
|
|
@@ -4479,17 +4604,26 @@ var ServiceContext = class extends Resource {
|
|
|
4479
4604
|
if (this.identityManager.identity) {
|
|
4480
4605
|
await this._initialize(ctx);
|
|
4481
4606
|
}
|
|
4607
|
+
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
4608
|
+
log12("loaded persistent invitations", {
|
|
4609
|
+
count: loadedInvitations.invitations?.length
|
|
4610
|
+
}, {
|
|
4611
|
+
F: __dxlog_file14,
|
|
4612
|
+
L: 178,
|
|
4613
|
+
S: this,
|
|
4614
|
+
C: (f, a) => f(...a)
|
|
4615
|
+
});
|
|
4482
4616
|
log12.trace("dxos.sdk.service-context.open", trace8.end({
|
|
4483
4617
|
id: this._instanceId
|
|
4484
4618
|
}), {
|
|
4485
4619
|
F: __dxlog_file14,
|
|
4486
|
-
L:
|
|
4620
|
+
L: 180,
|
|
4487
4621
|
S: this,
|
|
4488
4622
|
C: (f, a) => f(...a)
|
|
4489
4623
|
});
|
|
4490
4624
|
log12("opened", void 0, {
|
|
4491
4625
|
F: __dxlog_file14,
|
|
4492
|
-
L:
|
|
4626
|
+
L: 181,
|
|
4493
4627
|
S: this,
|
|
4494
4628
|
C: (f, a) => f(...a)
|
|
4495
4629
|
});
|
|
@@ -4497,7 +4631,7 @@ var ServiceContext = class extends Resource {
|
|
|
4497
4631
|
async _close() {
|
|
4498
4632
|
log12("closing...", void 0, {
|
|
4499
4633
|
F: __dxlog_file14,
|
|
4500
|
-
L:
|
|
4634
|
+
L: 185,
|
|
4501
4635
|
S: this,
|
|
4502
4636
|
C: (f, a) => f(...a)
|
|
4503
4637
|
});
|
|
@@ -4515,7 +4649,7 @@ var ServiceContext = class extends Resource {
|
|
|
4515
4649
|
await this.indexer.destroy();
|
|
4516
4650
|
log12("closed", void 0, {
|
|
4517
4651
|
F: __dxlog_file14,
|
|
4518
|
-
L:
|
|
4652
|
+
L: 198,
|
|
4519
4653
|
S: this,
|
|
4520
4654
|
C: (f, a) => f(...a)
|
|
4521
4655
|
});
|
|
@@ -4529,7 +4663,7 @@ var ServiceContext = class extends Resource {
|
|
|
4529
4663
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
4530
4664
|
invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
4531
4665
|
F: __dxlog_file14,
|
|
4532
|
-
L:
|
|
4666
|
+
L: 209,
|
|
4533
4667
|
S: this,
|
|
4534
4668
|
A: [
|
|
4535
4669
|
"factory",
|
|
@@ -4561,7 +4695,7 @@ var ServiceContext = class extends Resource {
|
|
|
4561
4695
|
async _initialize(ctx) {
|
|
4562
4696
|
log12("initializing spaces...", void 0, {
|
|
4563
4697
|
F: __dxlog_file14,
|
|
4564
|
-
L:
|
|
4698
|
+
L: 240,
|
|
4565
4699
|
S: this,
|
|
4566
4700
|
C: (f, a) => f(...a)
|
|
4567
4701
|
});
|
|
@@ -4579,12 +4713,12 @@ var ServiceContext = class extends Resource {
|
|
|
4579
4713
|
});
|
|
4580
4714
|
}
|
|
4581
4715
|
};
|
|
4582
|
-
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);
|
|
4583
4717
|
await this.dataSpaceManager.open();
|
|
4584
|
-
this._handlerFactories.set(
|
|
4718
|
+
this._handlerFactories.set(Invitation7.Kind.SPACE, (invitation) => {
|
|
4585
4719
|
invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
4586
4720
|
F: __dxlog_file14,
|
|
4587
|
-
L:
|
|
4721
|
+
L: 265,
|
|
4588
4722
|
S: this,
|
|
4589
4723
|
A: [
|
|
4590
4724
|
"this.dataSpaceManager",
|
|
@@ -4608,7 +4742,7 @@ var ServiceContext = class extends Resource {
|
|
|
4608
4742
|
details: assertion
|
|
4609
4743
|
}, {
|
|
4610
4744
|
F: __dxlog_file14,
|
|
4611
|
-
L:
|
|
4745
|
+
L: 281,
|
|
4612
4746
|
S: this,
|
|
4613
4747
|
C: (f, a) => f(...a)
|
|
4614
4748
|
});
|
|
@@ -4619,7 +4753,7 @@ var ServiceContext = class extends Resource {
|
|
|
4619
4753
|
details: assertion
|
|
4620
4754
|
}, {
|
|
4621
4755
|
F: __dxlog_file14,
|
|
4622
|
-
L:
|
|
4756
|
+
L: 285,
|
|
4623
4757
|
S: this,
|
|
4624
4758
|
C: (f, a) => f(...a)
|
|
4625
4759
|
});
|
|
@@ -4630,7 +4764,7 @@ var ServiceContext = class extends Resource {
|
|
|
4630
4764
|
details: assertion
|
|
4631
4765
|
}, {
|
|
4632
4766
|
F: __dxlog_file14,
|
|
4633
|
-
L:
|
|
4767
|
+
L: 290,
|
|
4634
4768
|
S: this,
|
|
4635
4769
|
C: (f, a) => f(...a)
|
|
4636
4770
|
});
|
|
@@ -4641,7 +4775,7 @@ var ServiceContext = class extends Resource {
|
|
|
4641
4775
|
} catch (err) {
|
|
4642
4776
|
log12.catch(err, void 0, {
|
|
4643
4777
|
F: __dxlog_file14,
|
|
4644
|
-
L:
|
|
4778
|
+
L: 296,
|
|
4645
4779
|
S: this,
|
|
4646
4780
|
C: (f, a) => f(...a)
|
|
4647
4781
|
});
|
|
@@ -4691,11 +4825,11 @@ import { getFirstStreamValue } from "@dxos/codec-protobuf";
|
|
|
4691
4825
|
import { credentialTypeFilter } from "@dxos/credentials";
|
|
4692
4826
|
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4693
4827
|
import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
|
|
4694
|
-
import { SpaceMember as
|
|
4828
|
+
import { SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4695
4829
|
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
4696
4830
|
|
|
4697
4831
|
// packages/sdk/client-services/src/version.ts
|
|
4698
|
-
var DXOS_VERSION = "0.4.10-main.
|
|
4832
|
+
var DXOS_VERSION = "0.4.10-main.e3078ed";
|
|
4699
4833
|
|
|
4700
4834
|
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
4701
4835
|
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -4817,7 +4951,7 @@ var getSpaceStats = async (space) => {
|
|
|
4817
4951
|
displayName: member.assertion.profile?.displayName
|
|
4818
4952
|
}
|
|
4819
4953
|
},
|
|
4820
|
-
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ?
|
|
4954
|
+
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember4.PresenceState.ONLINE : SpaceMember4.PresenceState.OFFLINE
|
|
4821
4955
|
})),
|
|
4822
4956
|
pipeline: {
|
|
4823
4957
|
// TODO(burdon): Pick properties from credentials if needed.
|
|
@@ -4941,9 +5075,9 @@ import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protoc
|
|
|
4941
5075
|
import { Context as Context11 } from "@dxos/context";
|
|
4942
5076
|
import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
|
|
4943
5077
|
import { getTypeReference } from "@dxos/echo-schema";
|
|
4944
|
-
import {
|
|
5078
|
+
import { QueryServiceImpl } from "@dxos/indexing";
|
|
4945
5079
|
import { invariant as invariant16 } from "@dxos/invariant";
|
|
4946
|
-
import { PublicKey as
|
|
5080
|
+
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
4947
5081
|
import { log as log16 } from "@dxos/log";
|
|
4948
5082
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
4949
5083
|
import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
@@ -5162,7 +5296,7 @@ var isLocked = (lockPath) => {
|
|
|
5162
5296
|
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
5163
5297
|
import { Event as Event8 } from "@dxos/async";
|
|
5164
5298
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5165
|
-
import { PublicKey as
|
|
5299
|
+
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5166
5300
|
import { getContextFromEntry, log as log15 } from "@dxos/log";
|
|
5167
5301
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5168
5302
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
@@ -5170,7 +5304,7 @@ var LoggingServiceImpl = class {
|
|
|
5170
5304
|
constructor() {
|
|
5171
5305
|
this._logs = new Event8();
|
|
5172
5306
|
this._started = Date.now();
|
|
5173
|
-
this._sessionId =
|
|
5307
|
+
this._sessionId = PublicKey12.random().toHex();
|
|
5174
5308
|
this._logProcessor = (_config, entry2) => {
|
|
5175
5309
|
this._logs.emit(entry2);
|
|
5176
5310
|
};
|
|
@@ -5381,10 +5515,10 @@ var toStorageType = (type) => {
|
|
|
5381
5515
|
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
5382
5516
|
import { Level } from "level";
|
|
5383
5517
|
import path from "@dxos/node-std/path";
|
|
5384
|
-
import { PublicKey as
|
|
5518
|
+
import { PublicKey as PublicKey13 } from "@dxos/keys";
|
|
5385
5519
|
var createLevel = async (config) => {
|
|
5386
5520
|
const persistent = isPersistent(config);
|
|
5387
|
-
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${
|
|
5521
|
+
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
|
|
5388
5522
|
const level = new Level(storagePath);
|
|
5389
5523
|
await level.open();
|
|
5390
5524
|
return level;
|
|
@@ -5548,7 +5682,7 @@ var ClientServicesHost = class {
|
|
|
5548
5682
|
initialize({ config, ...options }) {
|
|
5549
5683
|
invariant16(!this._open, "service host is open", {
|
|
5550
5684
|
F: __dxlog_file19,
|
|
5551
|
-
L:
|
|
5685
|
+
L: 198,
|
|
5552
5686
|
S: this,
|
|
5553
5687
|
A: [
|
|
5554
5688
|
"!this._open",
|
|
@@ -5557,14 +5691,14 @@ var ClientServicesHost = class {
|
|
|
5557
5691
|
});
|
|
5558
5692
|
log16("initializing...", void 0, {
|
|
5559
5693
|
F: __dxlog_file19,
|
|
5560
|
-
L:
|
|
5694
|
+
L: 199,
|
|
5561
5695
|
S: this,
|
|
5562
5696
|
C: (f, a) => f(...a)
|
|
5563
5697
|
});
|
|
5564
5698
|
if (config) {
|
|
5565
5699
|
invariant16(!this._config, "config already set", {
|
|
5566
5700
|
F: __dxlog_file19,
|
|
5567
|
-
L:
|
|
5701
|
+
L: 202,
|
|
5568
5702
|
S: this,
|
|
5569
5703
|
A: [
|
|
5570
5704
|
"!this._config",
|
|
@@ -5579,7 +5713,7 @@ var ClientServicesHost = class {
|
|
|
5579
5713
|
if (!options.signalManager) {
|
|
5580
5714
|
log16.warn("running signaling without telemetry metadata.", void 0, {
|
|
5581
5715
|
F: __dxlog_file19,
|
|
5582
|
-
L:
|
|
5716
|
+
L: 210,
|
|
5583
5717
|
S: this,
|
|
5584
5718
|
C: (f, a) => f(...a)
|
|
5585
5719
|
});
|
|
@@ -5590,7 +5724,7 @@ var ClientServicesHost = class {
|
|
|
5590
5724
|
this._signalManager = signalManager;
|
|
5591
5725
|
invariant16(!this._networkManager, "network manager already set", {
|
|
5592
5726
|
F: __dxlog_file19,
|
|
5593
|
-
L:
|
|
5727
|
+
L: 221,
|
|
5594
5728
|
S: this,
|
|
5595
5729
|
A: [
|
|
5596
5730
|
"!this._networkManager",
|
|
@@ -5604,7 +5738,7 @@ var ClientServicesHost = class {
|
|
|
5604
5738
|
});
|
|
5605
5739
|
log16("initialized", void 0, {
|
|
5606
5740
|
F: __dxlog_file19,
|
|
5607
|
-
L:
|
|
5741
|
+
L: 228,
|
|
5608
5742
|
S: this,
|
|
5609
5743
|
C: (f, a) => f(...a)
|
|
5610
5744
|
});
|
|
@@ -5613,18 +5747,18 @@ var ClientServicesHost = class {
|
|
|
5613
5747
|
if (this._open) {
|
|
5614
5748
|
return;
|
|
5615
5749
|
}
|
|
5616
|
-
const traceId =
|
|
5750
|
+
const traceId = PublicKey14.random().toHex();
|
|
5617
5751
|
log16.trace("dxos.client-services.host.open", trace9.begin({
|
|
5618
5752
|
id: traceId
|
|
5619
5753
|
}), {
|
|
5620
5754
|
F: __dxlog_file19,
|
|
5621
|
-
L:
|
|
5755
|
+
L: 239,
|
|
5622
5756
|
S: this,
|
|
5623
5757
|
C: (f, a) => f(...a)
|
|
5624
5758
|
});
|
|
5625
5759
|
invariant16(this._config, "config not set", {
|
|
5626
5760
|
F: __dxlog_file19,
|
|
5627
|
-
L:
|
|
5761
|
+
L: 241,
|
|
5628
5762
|
S: this,
|
|
5629
5763
|
A: [
|
|
5630
5764
|
"this._config",
|
|
@@ -5633,7 +5767,7 @@ var ClientServicesHost = class {
|
|
|
5633
5767
|
});
|
|
5634
5768
|
invariant16(this._storage, "storage not set", {
|
|
5635
5769
|
F: __dxlog_file19,
|
|
5636
|
-
L:
|
|
5770
|
+
L: 242,
|
|
5637
5771
|
S: this,
|
|
5638
5772
|
A: [
|
|
5639
5773
|
"this._storage",
|
|
@@ -5642,7 +5776,7 @@ var ClientServicesHost = class {
|
|
|
5642
5776
|
});
|
|
5643
5777
|
invariant16(this._signalManager, "signal manager not set", {
|
|
5644
5778
|
F: __dxlog_file19,
|
|
5645
|
-
L:
|
|
5779
|
+
L: 243,
|
|
5646
5780
|
S: this,
|
|
5647
5781
|
A: [
|
|
5648
5782
|
"this._signalManager",
|
|
@@ -5651,7 +5785,7 @@ var ClientServicesHost = class {
|
|
|
5651
5785
|
});
|
|
5652
5786
|
invariant16(this._networkManager, "network manager not set", {
|
|
5653
5787
|
F: __dxlog_file19,
|
|
5654
|
-
L:
|
|
5788
|
+
L: 244,
|
|
5655
5789
|
S: this,
|
|
5656
5790
|
A: [
|
|
5657
5791
|
"this._networkManager",
|
|
@@ -5663,7 +5797,7 @@ var ClientServicesHost = class {
|
|
|
5663
5797
|
lockKey: this._resourceLock?.lockKey
|
|
5664
5798
|
}, {
|
|
5665
5799
|
F: __dxlog_file19,
|
|
5666
|
-
L:
|
|
5800
|
+
L: 247,
|
|
5667
5801
|
S: this,
|
|
5668
5802
|
C: (f, a) => f(...a)
|
|
5669
5803
|
});
|
|
@@ -5674,20 +5808,22 @@ var ClientServicesHost = class {
|
|
|
5674
5808
|
await this._resourceLock?.acquire();
|
|
5675
5809
|
await this._loggingService.open();
|
|
5676
5810
|
this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
|
|
5811
|
+
this._queryService = new QueryServiceImpl({
|
|
5812
|
+
indexer: this._serviceContext.indexer,
|
|
5813
|
+
automergeHost: this._serviceContext.automergeHost
|
|
5814
|
+
});
|
|
5815
|
+
await this._queryService.open(ctx);
|
|
5677
5816
|
this._serviceRegistry.setServices({
|
|
5678
5817
|
SystemService: this._systemService,
|
|
5679
5818
|
IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
|
|
5680
|
-
InvitationsService: new InvitationsServiceImpl(this._serviceContext.
|
|
5819
|
+
InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
|
|
5681
5820
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
5682
5821
|
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
|
|
5683
5822
|
await this._serviceContext.initialized.wait();
|
|
5684
5823
|
return this._serviceContext.dataSpaceManager;
|
|
5685
5824
|
}),
|
|
5686
5825
|
DataService: new DataServiceImpl(this._serviceContext.automergeHost),
|
|
5687
|
-
|
|
5688
|
-
indexer: this._serviceContext.indexer,
|
|
5689
|
-
automergeHost: this._serviceContext.automergeHost
|
|
5690
|
-
}),
|
|
5826
|
+
QueryService: this._queryService,
|
|
5691
5827
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
5692
5828
|
LoggingService: this._loggingService,
|
|
5693
5829
|
TracingService: this._tracingService,
|
|
@@ -5699,24 +5835,6 @@ var ClientServicesHost = class {
|
|
|
5699
5835
|
})
|
|
5700
5836
|
});
|
|
5701
5837
|
await this._serviceContext.open(ctx);
|
|
5702
|
-
invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
|
|
5703
|
-
F: __dxlog_file19,
|
|
5704
|
-
L: 314,
|
|
5705
|
-
S: this,
|
|
5706
|
-
A: [
|
|
5707
|
-
"this.serviceRegistry.services.InvitationsService",
|
|
5708
|
-
""
|
|
5709
|
-
]
|
|
5710
|
-
});
|
|
5711
|
-
const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
|
|
5712
|
-
log16("loaded persistent invitations", {
|
|
5713
|
-
count: loadedInvitations.invitations?.length
|
|
5714
|
-
}, {
|
|
5715
|
-
F: __dxlog_file19,
|
|
5716
|
-
L: 317,
|
|
5717
|
-
S: this,
|
|
5718
|
-
C: (f, a) => f(...a)
|
|
5719
|
-
});
|
|
5720
5838
|
const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
|
|
5721
5839
|
if (devtoolsProxy) {
|
|
5722
5840
|
this._devtoolsProxy = new WebsocketRpcClient({
|
|
@@ -5736,7 +5854,7 @@ var ClientServicesHost = class {
|
|
|
5736
5854
|
deviceKey
|
|
5737
5855
|
}, {
|
|
5738
5856
|
F: __dxlog_file19,
|
|
5739
|
-
L:
|
|
5857
|
+
L: 330,
|
|
5740
5858
|
S: this,
|
|
5741
5859
|
C: (f, a) => f(...a)
|
|
5742
5860
|
});
|
|
@@ -5744,7 +5862,7 @@ var ClientServicesHost = class {
|
|
|
5744
5862
|
id: traceId
|
|
5745
5863
|
}), {
|
|
5746
5864
|
F: __dxlog_file19,
|
|
5747
|
-
L:
|
|
5865
|
+
L: 331,
|
|
5748
5866
|
S: this,
|
|
5749
5867
|
C: (f, a) => f(...a)
|
|
5750
5868
|
});
|
|
@@ -5758,7 +5876,7 @@ var ClientServicesHost = class {
|
|
|
5758
5876
|
deviceKey
|
|
5759
5877
|
}, {
|
|
5760
5878
|
F: __dxlog_file19,
|
|
5761
|
-
L:
|
|
5879
|
+
L: 342,
|
|
5762
5880
|
S: this,
|
|
5763
5881
|
C: (f, a) => f(...a)
|
|
5764
5882
|
});
|
|
@@ -5768,6 +5886,7 @@ var ClientServicesHost = class {
|
|
|
5768
5886
|
SystemService: this._systemService
|
|
5769
5887
|
});
|
|
5770
5888
|
await this._loggingService.close();
|
|
5889
|
+
await this._queryService.close();
|
|
5771
5890
|
await this._serviceContext.close();
|
|
5772
5891
|
await this._level?.close();
|
|
5773
5892
|
this._open = false;
|
|
@@ -5776,24 +5895,24 @@ var ClientServicesHost = class {
|
|
|
5776
5895
|
deviceKey
|
|
5777
5896
|
}, {
|
|
5778
5897
|
F: __dxlog_file19,
|
|
5779
|
-
L:
|
|
5898
|
+
L: 352,
|
|
5780
5899
|
S: this,
|
|
5781
5900
|
C: (f, a) => f(...a)
|
|
5782
5901
|
});
|
|
5783
5902
|
}
|
|
5784
5903
|
async reset() {
|
|
5785
|
-
const traceId =
|
|
5904
|
+
const traceId = PublicKey14.random().toHex();
|
|
5786
5905
|
log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
|
|
5787
5906
|
id: traceId
|
|
5788
5907
|
}), {
|
|
5789
5908
|
F: __dxlog_file19,
|
|
5790
|
-
L:
|
|
5909
|
+
L: 357,
|
|
5791
5910
|
S: this,
|
|
5792
5911
|
C: (f, a) => f(...a)
|
|
5793
5912
|
});
|
|
5794
5913
|
log16("resetting...", void 0, {
|
|
5795
5914
|
F: __dxlog_file19,
|
|
5796
|
-
L:
|
|
5915
|
+
L: 359,
|
|
5797
5916
|
S: this,
|
|
5798
5917
|
C: (f, a) => f(...a)
|
|
5799
5918
|
});
|
|
@@ -5801,7 +5920,7 @@ var ClientServicesHost = class {
|
|
|
5801
5920
|
await this._storage.reset();
|
|
5802
5921
|
log16("reset", void 0, {
|
|
5803
5922
|
F: __dxlog_file19,
|
|
5804
|
-
L:
|
|
5923
|
+
L: 362,
|
|
5805
5924
|
S: this,
|
|
5806
5925
|
C: (f, a) => f(...a)
|
|
5807
5926
|
});
|
|
@@ -5809,7 +5928,7 @@ var ClientServicesHost = class {
|
|
|
5809
5928
|
id: traceId
|
|
5810
5929
|
}), {
|
|
5811
5930
|
F: __dxlog_file19,
|
|
5812
|
-
L:
|
|
5931
|
+
L: 363,
|
|
5813
5932
|
S: this,
|
|
5814
5933
|
C: (f, a) => f(...a)
|
|
5815
5934
|
});
|
|
@@ -5822,7 +5941,7 @@ var ClientServicesHost = class {
|
|
|
5822
5941
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5823
5942
|
invariant16(automergeIndex, void 0, {
|
|
5824
5943
|
F: __dxlog_file19,
|
|
5825
|
-
L:
|
|
5944
|
+
L: 375,
|
|
5826
5945
|
S: this,
|
|
5827
5946
|
A: [
|
|
5828
5947
|
"automergeIndex",
|
|
@@ -5842,7 +5961,7 @@ var ClientServicesHost = class {
|
|
|
5842
5961
|
keys: []
|
|
5843
5962
|
}
|
|
5844
5963
|
};
|
|
5845
|
-
const propertiesId =
|
|
5964
|
+
const propertiesId = PublicKey14.random().toHex();
|
|
5846
5965
|
document.change((doc) => {
|
|
5847
5966
|
assignDeep2(doc, [
|
|
5848
5967
|
"objects",
|
|
@@ -5872,7 +5991,7 @@ ClientServicesHost = _ts_decorate8([
|
|
|
5872
5991
|
], ClientServicesHost);
|
|
5873
5992
|
|
|
5874
5993
|
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
5875
|
-
import { PublicKey as
|
|
5994
|
+
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5876
5995
|
import { humanize } from "@dxos/util";
|
|
5877
5996
|
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
5878
5997
|
|
|
@@ -5931,6 +6050,7 @@ export {
|
|
|
5931
6050
|
createAdmissionKeypair,
|
|
5932
6051
|
InvitationsServiceImpl,
|
|
5933
6052
|
SpaceInvitationProtocol,
|
|
6053
|
+
InvitationsManager,
|
|
5934
6054
|
ClientRpcServer,
|
|
5935
6055
|
DataSpace,
|
|
5936
6056
|
DataSpaceManager,
|
|
@@ -5948,4 +6068,4 @@ export {
|
|
|
5948
6068
|
ClientServicesHost,
|
|
5949
6069
|
ClientServicesProviderResource
|
|
5950
6070
|
};
|
|
5951
|
-
//# sourceMappingURL=chunk-
|
|
6071
|
+
//# sourceMappingURL=chunk-IYPYLH4D.mjs.map
|