@dxos/client-services 0.4.10-main.fe71b4c → 0.4.10-next.169e4e3
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-7S34JE6M.mjs → chunk-KCCL73B5.mjs} +625 -508
- package/dist/lib/browser/chunk-KCCL73B5.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 +125 -112
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-DQMGKBOV.cjs → chunk-2EUUFY7P.cjs} +694 -578
- package/dist/lib/node/chunk-2EUUFY7P.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 +125 -115
- 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 +0 -5
- 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 +1 -0
- 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 +3 -0
- 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 +7 -64
- 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 +14 -2
- package/src/packlets/services/service-host.ts +11 -15
- 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 +19 -1
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-7S34JE6M.mjs.map +0 -7
- package/dist/lib/node/chunk-DQMGKBOV.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
|
}),
|
|
@@ -4303,17 +4474,16 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
|
4303
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"));
|
|
@@ -4447,21 +4568,22 @@ var ServiceContext = class extends Resource {
|
|
|
4447
4568
|
})
|
|
4448
4569
|
});
|
|
4449
4570
|
this.indexer = new Indexer({
|
|
4571
|
+
db: this.level,
|
|
4450
4572
|
indexStore: new IndexStore({
|
|
4451
4573
|
db: level.sublevel("index-storage")
|
|
4452
4574
|
}),
|
|
4453
4575
|
metadataStore: this.indexMetadata,
|
|
4454
|
-
loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
|
|
4455
|
-
getAllDocuments: createDocumentsIterator(this.automergeHost)
|
|
4576
|
+
loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
|
|
4456
4577
|
});
|
|
4457
4578
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
4458
|
-
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)));
|
|
4459
4581
|
}
|
|
4460
4582
|
async _open(ctx) {
|
|
4461
4583
|
await this._checkStorageVersion();
|
|
4462
4584
|
log12("opening...", void 0, {
|
|
4463
4585
|
F: __dxlog_file14,
|
|
4464
|
-
L:
|
|
4586
|
+
L: 164,
|
|
4465
4587
|
S: this,
|
|
4466
4588
|
C: (f, a) => f(...a)
|
|
4467
4589
|
});
|
|
@@ -4469,7 +4591,7 @@ var ServiceContext = class extends Resource {
|
|
|
4469
4591
|
id: this._instanceId
|
|
4470
4592
|
}), {
|
|
4471
4593
|
F: __dxlog_file14,
|
|
4472
|
-
L:
|
|
4594
|
+
L: 165,
|
|
4473
4595
|
S: this,
|
|
4474
4596
|
C: (f, a) => f(...a)
|
|
4475
4597
|
});
|
|
@@ -4482,17 +4604,26 @@ var ServiceContext = class extends Resource {
|
|
|
4482
4604
|
if (this.identityManager.identity) {
|
|
4483
4605
|
await this._initialize(ctx);
|
|
4484
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
|
+
});
|
|
4485
4616
|
log12.trace("dxos.sdk.service-context.open", trace8.end({
|
|
4486
4617
|
id: this._instanceId
|
|
4487
4618
|
}), {
|
|
4488
4619
|
F: __dxlog_file14,
|
|
4489
|
-
L:
|
|
4620
|
+
L: 180,
|
|
4490
4621
|
S: this,
|
|
4491
4622
|
C: (f, a) => f(...a)
|
|
4492
4623
|
});
|
|
4493
4624
|
log12("opened", void 0, {
|
|
4494
4625
|
F: __dxlog_file14,
|
|
4495
|
-
L:
|
|
4626
|
+
L: 181,
|
|
4496
4627
|
S: this,
|
|
4497
4628
|
C: (f, a) => f(...a)
|
|
4498
4629
|
});
|
|
@@ -4500,7 +4631,7 @@ var ServiceContext = class extends Resource {
|
|
|
4500
4631
|
async _close() {
|
|
4501
4632
|
log12("closing...", void 0, {
|
|
4502
4633
|
F: __dxlog_file14,
|
|
4503
|
-
L:
|
|
4634
|
+
L: 185,
|
|
4504
4635
|
S: this,
|
|
4505
4636
|
C: (f, a) => f(...a)
|
|
4506
4637
|
});
|
|
@@ -4518,7 +4649,7 @@ var ServiceContext = class extends Resource {
|
|
|
4518
4649
|
await this.indexer.destroy();
|
|
4519
4650
|
log12("closed", void 0, {
|
|
4520
4651
|
F: __dxlog_file14,
|
|
4521
|
-
L:
|
|
4652
|
+
L: 198,
|
|
4522
4653
|
S: this,
|
|
4523
4654
|
C: (f, a) => f(...a)
|
|
4524
4655
|
});
|
|
@@ -4532,7 +4663,7 @@ var ServiceContext = class extends Resource {
|
|
|
4532
4663
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
4533
4664
|
invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
4534
4665
|
F: __dxlog_file14,
|
|
4535
|
-
L:
|
|
4666
|
+
L: 209,
|
|
4536
4667
|
S: this,
|
|
4537
4668
|
A: [
|
|
4538
4669
|
"factory",
|
|
@@ -4564,7 +4695,7 @@ var ServiceContext = class extends Resource {
|
|
|
4564
4695
|
async _initialize(ctx) {
|
|
4565
4696
|
log12("initializing spaces...", void 0, {
|
|
4566
4697
|
F: __dxlog_file14,
|
|
4567
|
-
L:
|
|
4698
|
+
L: 240,
|
|
4568
4699
|
S: this,
|
|
4569
4700
|
C: (f, a) => f(...a)
|
|
4570
4701
|
});
|
|
@@ -4582,12 +4713,12 @@ var ServiceContext = class extends Resource {
|
|
|
4582
4713
|
});
|
|
4583
4714
|
}
|
|
4584
4715
|
};
|
|
4585
|
-
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);
|
|
4586
4717
|
await this.dataSpaceManager.open();
|
|
4587
|
-
this._handlerFactories.set(
|
|
4718
|
+
this._handlerFactories.set(Invitation7.Kind.SPACE, (invitation) => {
|
|
4588
4719
|
invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
4589
4720
|
F: __dxlog_file14,
|
|
4590
|
-
L:
|
|
4721
|
+
L: 265,
|
|
4591
4722
|
S: this,
|
|
4592
4723
|
A: [
|
|
4593
4724
|
"this.dataSpaceManager",
|
|
@@ -4611,7 +4742,7 @@ var ServiceContext = class extends Resource {
|
|
|
4611
4742
|
details: assertion
|
|
4612
4743
|
}, {
|
|
4613
4744
|
F: __dxlog_file14,
|
|
4614
|
-
L:
|
|
4745
|
+
L: 281,
|
|
4615
4746
|
S: this,
|
|
4616
4747
|
C: (f, a) => f(...a)
|
|
4617
4748
|
});
|
|
@@ -4622,7 +4753,7 @@ var ServiceContext = class extends Resource {
|
|
|
4622
4753
|
details: assertion
|
|
4623
4754
|
}, {
|
|
4624
4755
|
F: __dxlog_file14,
|
|
4625
|
-
L:
|
|
4756
|
+
L: 285,
|
|
4626
4757
|
S: this,
|
|
4627
4758
|
C: (f, a) => f(...a)
|
|
4628
4759
|
});
|
|
@@ -4633,7 +4764,7 @@ var ServiceContext = class extends Resource {
|
|
|
4633
4764
|
details: assertion
|
|
4634
4765
|
}, {
|
|
4635
4766
|
F: __dxlog_file14,
|
|
4636
|
-
L:
|
|
4767
|
+
L: 290,
|
|
4637
4768
|
S: this,
|
|
4638
4769
|
C: (f, a) => f(...a)
|
|
4639
4770
|
});
|
|
@@ -4644,7 +4775,7 @@ var ServiceContext = class extends Resource {
|
|
|
4644
4775
|
} catch (err) {
|
|
4645
4776
|
log12.catch(err, void 0, {
|
|
4646
4777
|
F: __dxlog_file14,
|
|
4647
|
-
L:
|
|
4778
|
+
L: 296,
|
|
4648
4779
|
S: this,
|
|
4649
4780
|
C: (f, a) => f(...a)
|
|
4650
4781
|
});
|
|
@@ -4694,11 +4825,11 @@ import { getFirstStreamValue } from "@dxos/codec-protobuf";
|
|
|
4694
4825
|
import { credentialTypeFilter } from "@dxos/credentials";
|
|
4695
4826
|
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4696
4827
|
import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
|
|
4697
|
-
import { SpaceMember as
|
|
4828
|
+
import { SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4698
4829
|
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
4699
4830
|
|
|
4700
4831
|
// packages/sdk/client-services/src/version.ts
|
|
4701
|
-
var DXOS_VERSION = "0.4.10-
|
|
4832
|
+
var DXOS_VERSION = "0.4.10-next.169e4e3";
|
|
4702
4833
|
|
|
4703
4834
|
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
4704
4835
|
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -4820,7 +4951,7 @@ var getSpaceStats = async (space) => {
|
|
|
4820
4951
|
displayName: member.assertion.profile?.displayName
|
|
4821
4952
|
}
|
|
4822
4953
|
},
|
|
4823
|
-
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
|
|
4824
4955
|
})),
|
|
4825
4956
|
pipeline: {
|
|
4826
4957
|
// TODO(burdon): Pick properties from credentials if needed.
|
|
@@ -4944,9 +5075,9 @@ import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protoc
|
|
|
4944
5075
|
import { Context as Context11 } from "@dxos/context";
|
|
4945
5076
|
import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
|
|
4946
5077
|
import { getTypeReference } from "@dxos/echo-schema";
|
|
4947
|
-
import {
|
|
5078
|
+
import { QueryServiceImpl } from "@dxos/indexing";
|
|
4948
5079
|
import { invariant as invariant16 } from "@dxos/invariant";
|
|
4949
|
-
import { PublicKey as
|
|
5080
|
+
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
4950
5081
|
import { log as log16 } from "@dxos/log";
|
|
4951
5082
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
4952
5083
|
import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
@@ -5165,7 +5296,7 @@ var isLocked = (lockPath) => {
|
|
|
5165
5296
|
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
5166
5297
|
import { Event as Event8 } from "@dxos/async";
|
|
5167
5298
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5168
|
-
import { PublicKey as
|
|
5299
|
+
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5169
5300
|
import { getContextFromEntry, log as log15 } from "@dxos/log";
|
|
5170
5301
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5171
5302
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
@@ -5173,7 +5304,7 @@ var LoggingServiceImpl = class {
|
|
|
5173
5304
|
constructor() {
|
|
5174
5305
|
this._logs = new Event8();
|
|
5175
5306
|
this._started = Date.now();
|
|
5176
|
-
this._sessionId =
|
|
5307
|
+
this._sessionId = PublicKey12.random().toHex();
|
|
5177
5308
|
this._logProcessor = (_config, entry2) => {
|
|
5178
5309
|
this._logs.emit(entry2);
|
|
5179
5310
|
};
|
|
@@ -5384,10 +5515,10 @@ var toStorageType = (type) => {
|
|
|
5384
5515
|
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
5385
5516
|
import { Level } from "level";
|
|
5386
5517
|
import path from "@dxos/node-std/path";
|
|
5387
|
-
import { PublicKey as
|
|
5518
|
+
import { PublicKey as PublicKey13 } from "@dxos/keys";
|
|
5388
5519
|
var createLevel = async (config) => {
|
|
5389
5520
|
const persistent = isPersistent(config);
|
|
5390
|
-
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${
|
|
5521
|
+
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
|
|
5391
5522
|
const level = new Level(storagePath);
|
|
5392
5523
|
await level.open();
|
|
5393
5524
|
return level;
|
|
@@ -5551,7 +5682,7 @@ var ClientServicesHost = class {
|
|
|
5551
5682
|
initialize({ config, ...options }) {
|
|
5552
5683
|
invariant16(!this._open, "service host is open", {
|
|
5553
5684
|
F: __dxlog_file19,
|
|
5554
|
-
L:
|
|
5685
|
+
L: 198,
|
|
5555
5686
|
S: this,
|
|
5556
5687
|
A: [
|
|
5557
5688
|
"!this._open",
|
|
@@ -5560,14 +5691,14 @@ var ClientServicesHost = class {
|
|
|
5560
5691
|
});
|
|
5561
5692
|
log16("initializing...", void 0, {
|
|
5562
5693
|
F: __dxlog_file19,
|
|
5563
|
-
L:
|
|
5694
|
+
L: 199,
|
|
5564
5695
|
S: this,
|
|
5565
5696
|
C: (f, a) => f(...a)
|
|
5566
5697
|
});
|
|
5567
5698
|
if (config) {
|
|
5568
5699
|
invariant16(!this._config, "config already set", {
|
|
5569
5700
|
F: __dxlog_file19,
|
|
5570
|
-
L:
|
|
5701
|
+
L: 202,
|
|
5571
5702
|
S: this,
|
|
5572
5703
|
A: [
|
|
5573
5704
|
"!this._config",
|
|
@@ -5582,7 +5713,7 @@ var ClientServicesHost = class {
|
|
|
5582
5713
|
if (!options.signalManager) {
|
|
5583
5714
|
log16.warn("running signaling without telemetry metadata.", void 0, {
|
|
5584
5715
|
F: __dxlog_file19,
|
|
5585
|
-
L:
|
|
5716
|
+
L: 210,
|
|
5586
5717
|
S: this,
|
|
5587
5718
|
C: (f, a) => f(...a)
|
|
5588
5719
|
});
|
|
@@ -5593,7 +5724,7 @@ var ClientServicesHost = class {
|
|
|
5593
5724
|
this._signalManager = signalManager;
|
|
5594
5725
|
invariant16(!this._networkManager, "network manager already set", {
|
|
5595
5726
|
F: __dxlog_file19,
|
|
5596
|
-
L:
|
|
5727
|
+
L: 221,
|
|
5597
5728
|
S: this,
|
|
5598
5729
|
A: [
|
|
5599
5730
|
"!this._networkManager",
|
|
@@ -5607,7 +5738,7 @@ var ClientServicesHost = class {
|
|
|
5607
5738
|
});
|
|
5608
5739
|
log16("initialized", void 0, {
|
|
5609
5740
|
F: __dxlog_file19,
|
|
5610
|
-
L:
|
|
5741
|
+
L: 228,
|
|
5611
5742
|
S: this,
|
|
5612
5743
|
C: (f, a) => f(...a)
|
|
5613
5744
|
});
|
|
@@ -5616,18 +5747,18 @@ var ClientServicesHost = class {
|
|
|
5616
5747
|
if (this._open) {
|
|
5617
5748
|
return;
|
|
5618
5749
|
}
|
|
5619
|
-
const traceId =
|
|
5750
|
+
const traceId = PublicKey14.random().toHex();
|
|
5620
5751
|
log16.trace("dxos.client-services.host.open", trace9.begin({
|
|
5621
5752
|
id: traceId
|
|
5622
5753
|
}), {
|
|
5623
5754
|
F: __dxlog_file19,
|
|
5624
|
-
L:
|
|
5755
|
+
L: 239,
|
|
5625
5756
|
S: this,
|
|
5626
5757
|
C: (f, a) => f(...a)
|
|
5627
5758
|
});
|
|
5628
5759
|
invariant16(this._config, "config not set", {
|
|
5629
5760
|
F: __dxlog_file19,
|
|
5630
|
-
L:
|
|
5761
|
+
L: 241,
|
|
5631
5762
|
S: this,
|
|
5632
5763
|
A: [
|
|
5633
5764
|
"this._config",
|
|
@@ -5636,7 +5767,7 @@ var ClientServicesHost = class {
|
|
|
5636
5767
|
});
|
|
5637
5768
|
invariant16(this._storage, "storage not set", {
|
|
5638
5769
|
F: __dxlog_file19,
|
|
5639
|
-
L:
|
|
5770
|
+
L: 242,
|
|
5640
5771
|
S: this,
|
|
5641
5772
|
A: [
|
|
5642
5773
|
"this._storage",
|
|
@@ -5645,7 +5776,7 @@ var ClientServicesHost = class {
|
|
|
5645
5776
|
});
|
|
5646
5777
|
invariant16(this._signalManager, "signal manager not set", {
|
|
5647
5778
|
F: __dxlog_file19,
|
|
5648
|
-
L:
|
|
5779
|
+
L: 243,
|
|
5649
5780
|
S: this,
|
|
5650
5781
|
A: [
|
|
5651
5782
|
"this._signalManager",
|
|
@@ -5654,7 +5785,7 @@ var ClientServicesHost = class {
|
|
|
5654
5785
|
});
|
|
5655
5786
|
invariant16(this._networkManager, "network manager not set", {
|
|
5656
5787
|
F: __dxlog_file19,
|
|
5657
|
-
L:
|
|
5788
|
+
L: 244,
|
|
5658
5789
|
S: this,
|
|
5659
5790
|
A: [
|
|
5660
5791
|
"this._networkManager",
|
|
@@ -5666,7 +5797,7 @@ var ClientServicesHost = class {
|
|
|
5666
5797
|
lockKey: this._resourceLock?.lockKey
|
|
5667
5798
|
}, {
|
|
5668
5799
|
F: __dxlog_file19,
|
|
5669
|
-
L:
|
|
5800
|
+
L: 247,
|
|
5670
5801
|
S: this,
|
|
5671
5802
|
C: (f, a) => f(...a)
|
|
5672
5803
|
});
|
|
@@ -5677,20 +5808,22 @@ var ClientServicesHost = class {
|
|
|
5677
5808
|
await this._resourceLock?.acquire();
|
|
5678
5809
|
await this._loggingService.open();
|
|
5679
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);
|
|
5680
5816
|
this._serviceRegistry.setServices({
|
|
5681
5817
|
SystemService: this._systemService,
|
|
5682
5818
|
IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
|
|
5683
|
-
InvitationsService: new InvitationsServiceImpl(this._serviceContext.
|
|
5819
|
+
InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
|
|
5684
5820
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
5685
5821
|
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
|
|
5686
5822
|
await this._serviceContext.initialized.wait();
|
|
5687
5823
|
return this._serviceContext.dataSpaceManager;
|
|
5688
5824
|
}),
|
|
5689
5825
|
DataService: new DataServiceImpl(this._serviceContext.automergeHost),
|
|
5690
|
-
|
|
5691
|
-
indexer: this._serviceContext.indexer,
|
|
5692
|
-
automergeHost: this._serviceContext.automergeHost
|
|
5693
|
-
}),
|
|
5826
|
+
QueryService: this._queryService,
|
|
5694
5827
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
5695
5828
|
LoggingService: this._loggingService,
|
|
5696
5829
|
TracingService: this._tracingService,
|
|
@@ -5702,24 +5835,6 @@ var ClientServicesHost = class {
|
|
|
5702
5835
|
})
|
|
5703
5836
|
});
|
|
5704
5837
|
await this._serviceContext.open(ctx);
|
|
5705
|
-
invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
|
|
5706
|
-
F: __dxlog_file19,
|
|
5707
|
-
L: 314,
|
|
5708
|
-
S: this,
|
|
5709
|
-
A: [
|
|
5710
|
-
"this.serviceRegistry.services.InvitationsService",
|
|
5711
|
-
""
|
|
5712
|
-
]
|
|
5713
|
-
});
|
|
5714
|
-
const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
|
|
5715
|
-
log16("loaded persistent invitations", {
|
|
5716
|
-
count: loadedInvitations.invitations?.length
|
|
5717
|
-
}, {
|
|
5718
|
-
F: __dxlog_file19,
|
|
5719
|
-
L: 317,
|
|
5720
|
-
S: this,
|
|
5721
|
-
C: (f, a) => f(...a)
|
|
5722
|
-
});
|
|
5723
5838
|
const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
|
|
5724
5839
|
if (devtoolsProxy) {
|
|
5725
5840
|
this._devtoolsProxy = new WebsocketRpcClient({
|
|
@@ -5739,7 +5854,7 @@ var ClientServicesHost = class {
|
|
|
5739
5854
|
deviceKey
|
|
5740
5855
|
}, {
|
|
5741
5856
|
F: __dxlog_file19,
|
|
5742
|
-
L:
|
|
5857
|
+
L: 330,
|
|
5743
5858
|
S: this,
|
|
5744
5859
|
C: (f, a) => f(...a)
|
|
5745
5860
|
});
|
|
@@ -5747,7 +5862,7 @@ var ClientServicesHost = class {
|
|
|
5747
5862
|
id: traceId
|
|
5748
5863
|
}), {
|
|
5749
5864
|
F: __dxlog_file19,
|
|
5750
|
-
L:
|
|
5865
|
+
L: 331,
|
|
5751
5866
|
S: this,
|
|
5752
5867
|
C: (f, a) => f(...a)
|
|
5753
5868
|
});
|
|
@@ -5761,7 +5876,7 @@ var ClientServicesHost = class {
|
|
|
5761
5876
|
deviceKey
|
|
5762
5877
|
}, {
|
|
5763
5878
|
F: __dxlog_file19,
|
|
5764
|
-
L:
|
|
5879
|
+
L: 342,
|
|
5765
5880
|
S: this,
|
|
5766
5881
|
C: (f, a) => f(...a)
|
|
5767
5882
|
});
|
|
@@ -5771,6 +5886,7 @@ var ClientServicesHost = class {
|
|
|
5771
5886
|
SystemService: this._systemService
|
|
5772
5887
|
});
|
|
5773
5888
|
await this._loggingService.close();
|
|
5889
|
+
await this._queryService.close();
|
|
5774
5890
|
await this._serviceContext.close();
|
|
5775
5891
|
await this._level?.close();
|
|
5776
5892
|
this._open = false;
|
|
@@ -5779,24 +5895,24 @@ var ClientServicesHost = class {
|
|
|
5779
5895
|
deviceKey
|
|
5780
5896
|
}, {
|
|
5781
5897
|
F: __dxlog_file19,
|
|
5782
|
-
L:
|
|
5898
|
+
L: 352,
|
|
5783
5899
|
S: this,
|
|
5784
5900
|
C: (f, a) => f(...a)
|
|
5785
5901
|
});
|
|
5786
5902
|
}
|
|
5787
5903
|
async reset() {
|
|
5788
|
-
const traceId =
|
|
5904
|
+
const traceId = PublicKey14.random().toHex();
|
|
5789
5905
|
log16.trace("dxos.sdk.client-services-host.reset", trace9.begin({
|
|
5790
5906
|
id: traceId
|
|
5791
5907
|
}), {
|
|
5792
5908
|
F: __dxlog_file19,
|
|
5793
|
-
L:
|
|
5909
|
+
L: 357,
|
|
5794
5910
|
S: this,
|
|
5795
5911
|
C: (f, a) => f(...a)
|
|
5796
5912
|
});
|
|
5797
5913
|
log16("resetting...", void 0, {
|
|
5798
5914
|
F: __dxlog_file19,
|
|
5799
|
-
L:
|
|
5915
|
+
L: 359,
|
|
5800
5916
|
S: this,
|
|
5801
5917
|
C: (f, a) => f(...a)
|
|
5802
5918
|
});
|
|
@@ -5804,7 +5920,7 @@ var ClientServicesHost = class {
|
|
|
5804
5920
|
await this._storage.reset();
|
|
5805
5921
|
log16("reset", void 0, {
|
|
5806
5922
|
F: __dxlog_file19,
|
|
5807
|
-
L:
|
|
5923
|
+
L: 362,
|
|
5808
5924
|
S: this,
|
|
5809
5925
|
C: (f, a) => f(...a)
|
|
5810
5926
|
});
|
|
@@ -5812,7 +5928,7 @@ var ClientServicesHost = class {
|
|
|
5812
5928
|
id: traceId
|
|
5813
5929
|
}), {
|
|
5814
5930
|
F: __dxlog_file19,
|
|
5815
|
-
L:
|
|
5931
|
+
L: 363,
|
|
5816
5932
|
S: this,
|
|
5817
5933
|
C: (f, a) => f(...a)
|
|
5818
5934
|
});
|
|
@@ -5825,7 +5941,7 @@ var ClientServicesHost = class {
|
|
|
5825
5941
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5826
5942
|
invariant16(automergeIndex, void 0, {
|
|
5827
5943
|
F: __dxlog_file19,
|
|
5828
|
-
L:
|
|
5944
|
+
L: 375,
|
|
5829
5945
|
S: this,
|
|
5830
5946
|
A: [
|
|
5831
5947
|
"automergeIndex",
|
|
@@ -5845,7 +5961,7 @@ var ClientServicesHost = class {
|
|
|
5845
5961
|
keys: []
|
|
5846
5962
|
}
|
|
5847
5963
|
};
|
|
5848
|
-
const propertiesId =
|
|
5964
|
+
const propertiesId = PublicKey14.random().toHex();
|
|
5849
5965
|
document.change((doc) => {
|
|
5850
5966
|
assignDeep2(doc, [
|
|
5851
5967
|
"objects",
|
|
@@ -5875,7 +5991,7 @@ ClientServicesHost = _ts_decorate8([
|
|
|
5875
5991
|
], ClientServicesHost);
|
|
5876
5992
|
|
|
5877
5993
|
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
5878
|
-
import { PublicKey as
|
|
5994
|
+
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5879
5995
|
import { humanize } from "@dxos/util";
|
|
5880
5996
|
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
5881
5997
|
|
|
@@ -5934,6 +6050,7 @@ export {
|
|
|
5934
6050
|
createAdmissionKeypair,
|
|
5935
6051
|
InvitationsServiceImpl,
|
|
5936
6052
|
SpaceInvitationProtocol,
|
|
6053
|
+
InvitationsManager,
|
|
5937
6054
|
ClientRpcServer,
|
|
5938
6055
|
DataSpace,
|
|
5939
6056
|
DataSpaceManager,
|
|
@@ -5951,4 +6068,4 @@ export {
|
|
|
5951
6068
|
ClientServicesHost,
|
|
5952
6069
|
ClientServicesProviderResource
|
|
5953
6070
|
};
|
|
5954
|
-
//# sourceMappingURL=chunk-
|
|
6071
|
+
//# sourceMappingURL=chunk-KCCL73B5.mjs.map
|