@dxos/client-services 0.3.11-main.d56f337 → 0.3.11-main.d8b8a39
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-DUTSCN4V.mjs → chunk-BF2EZUZV.mjs} +69 -49
- package/dist/lib/browser/chunk-BF2EZUZV.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +4 -11
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-IRXK4VWQ.cjs → chunk-H5EXDUBC.cjs} +129 -109
- package/dist/lib/node/chunk-H5EXDUBC.cjs.map +7 -0
- package/dist/lib/node/index.cjs +37 -37
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +11 -18
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -0
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +28 -3
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -0
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +35 -35
- package/src/packlets/invitations/device-invitation-protocol.test.ts +14 -0
- package/src/packlets/invitations/device-invitation-protocol.ts +14 -0
- package/src/packlets/invitations/invitation-protocol.ts +44 -6
- package/src/packlets/invitations/invitations-handler.ts +19 -17
- package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
- package/src/packlets/testing/invitation-utils.ts +2 -10
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-DUTSCN4V.mjs.map +0 -7
- package/dist/lib/node/chunk-IRXK4VWQ.cjs.map +0 -7
|
@@ -7,6 +7,7 @@ import { expect } from 'chai';
|
|
|
7
7
|
import { asyncChain, Trigger } from '@dxos/async';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
9
|
import { testLocalDatabase } from '@dxos/echo-pipeline/testing';
|
|
10
|
+
import { AlreadyJoinedError } from '@dxos/protocols';
|
|
10
11
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
12
|
import { afterTest, describe, test } from '@dxos/test';
|
|
12
13
|
|
|
@@ -71,6 +72,33 @@ describe('services/space-invitations-protocol', () => {
|
|
|
71
72
|
}
|
|
72
73
|
});
|
|
73
74
|
|
|
75
|
+
test('invitation when already joined', async () => {
|
|
76
|
+
const [host, guest] = await asyncChain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
|
|
77
|
+
|
|
78
|
+
const space1 = await host.dataSpaceManager!.createSpace();
|
|
79
|
+
const spaceKey = space1.key;
|
|
80
|
+
|
|
81
|
+
await Promise.all(performInvitation({ host, guest, options: { kind: Invitation.Kind.SPACE, spaceKey } }));
|
|
82
|
+
|
|
83
|
+
{
|
|
84
|
+
const space1 = host.dataSpaceManager!.spaces.get(spaceKey)!;
|
|
85
|
+
const space2 = guest.dataSpaceManager!.spaces.get(spaceKey)!;
|
|
86
|
+
expect(space1).not.to.be.undefined;
|
|
87
|
+
expect(space2).not.to.be.undefined;
|
|
88
|
+
|
|
89
|
+
await host.dataSpaceManager?.waitUntilSpaceReady(space1.key);
|
|
90
|
+
await guest.dataSpaceManager?.waitUntilSpaceReady(space2.key);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const [_, guestResult] = performInvitation({
|
|
94
|
+
host,
|
|
95
|
+
guest,
|
|
96
|
+
options: { kind: Invitation.Kind.SPACE, spaceKey },
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect((await guestResult).error).to.be.instanceOf(AlreadyJoinedError);
|
|
100
|
+
});
|
|
101
|
+
|
|
74
102
|
test('creates and accepts invitation with retry', async () => {
|
|
75
103
|
const [host, guest] = await asyncChain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
|
|
76
104
|
|
|
@@ -8,6 +8,7 @@ import { invariant } from '@dxos/invariant';
|
|
|
8
8
|
import { type Keyring } from '@dxos/keyring';
|
|
9
9
|
import { type PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
|
+
import { AlreadyJoinedError } from '@dxos/protocols';
|
|
11
12
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
12
13
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
13
14
|
import { type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
@@ -76,6 +77,12 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
checkInvitation(invitation: Partial<Invitation>) {
|
|
81
|
+
if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
|
|
82
|
+
return new AlreadyJoinedError('Already joined space.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
createIntroduction(): IntroductionRequest {
|
|
80
87
|
return {
|
|
81
88
|
profile: this._signingContext.getProfile(),
|
|
@@ -104,6 +111,10 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
104
111
|
invariant(assertion['@type'] === 'dxos.halo.credentials.SpaceMember', 'Invalid credential');
|
|
105
112
|
invariant(credential.subject.id.equals(this._signingContext.identityKey));
|
|
106
113
|
|
|
114
|
+
if (this._spaceManager.spaces.has(assertion.spaceKey)) {
|
|
115
|
+
throw new AlreadyJoinedError('Already joined space.');
|
|
116
|
+
}
|
|
117
|
+
|
|
107
118
|
// Create local space.
|
|
108
119
|
await this._spaceManager.acceptSpace({
|
|
109
120
|
spaceKey: assertion.spaceKey,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Trigger } from '@dxos/async';
|
|
6
|
-
import { type AuthenticatingInvitation, type CancellableInvitation } from '@dxos/client-protocol';
|
|
6
|
+
import { InvitationEncoder, type AuthenticatingInvitation, type CancellableInvitation } from '@dxos/client-protocol';
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
9
|
|
|
@@ -13,15 +13,7 @@ import { ServiceContext } from '../services';
|
|
|
13
13
|
* Strip secrets from invitation before giving it to the peer.
|
|
14
14
|
*/
|
|
15
15
|
export const sanitizeInvitation = (invitation: Invitation): Invitation => {
|
|
16
|
-
return
|
|
17
|
-
invitationId: invitation.invitationId,
|
|
18
|
-
type: invitation.type,
|
|
19
|
-
kind: invitation.kind,
|
|
20
|
-
authMethod: invitation.authMethod,
|
|
21
|
-
swarmKey: invitation.swarmKey,
|
|
22
|
-
state: invitation.state,
|
|
23
|
-
timeout: invitation.timeout,
|
|
24
|
-
};
|
|
16
|
+
return InvitationEncoder.decode(InvitationEncoder.encode(invitation));
|
|
25
17
|
};
|
|
26
18
|
|
|
27
19
|
export type InvitationHost = {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "0.3.11-main.
|
|
1
|
+
export const DXOS_VERSION = "0.3.11-main.d8b8a39";
|