@dxos/client-services 0.3.11-main.d7d4c52 → 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-CKB4252E.mjs → chunk-BF2EZUZV.mjs} +116 -75
- package/dist/lib/browser/chunk-BF2EZUZV.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -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 +4 -11
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-5EUWM7NI.cjs → chunk-H5EXDUBC.cjs} +173 -132
- package/dist/lib/node/chunk-H5EXDUBC.cjs.map +7 -0
- package/dist/lib/node/index.cjs +37 -37
- 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 +11 -18
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/identity/identity-service.d.ts +3 -3
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- 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/services/service-host.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/identity/identity-service.test.ts +1 -1
- package/src/packlets/identity/identity-service.ts +6 -3
- 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 +20 -18
- package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
- package/src/packlets/services/service-host.ts +27 -12
- package/src/packlets/testing/invitation-utils.ts +2 -10
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-CKB4252E.mjs.map +0 -7
- package/dist/lib/node/chunk-5EUWM7NI.cjs.map +0 -7
|
@@ -303,9 +303,6 @@ export class InvitationsHandler {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
|
-
} else {
|
|
307
|
-
// Notify that introduction is complete even if auth is not required.
|
|
308
|
-
setState({ state: Invitation.State.READY_FOR_AUTHENTICATION });
|
|
309
306
|
}
|
|
310
307
|
|
|
311
308
|
// 3. Send admission credentials to host (with local space keys).
|
|
@@ -321,7 +318,7 @@ export class InvitationsHandler {
|
|
|
321
318
|
|
|
322
319
|
// 5. Success.
|
|
323
320
|
log('admitted by host', { ...protocol.toJSON() });
|
|
324
|
-
setState({ ...result, state: Invitation.State.SUCCESS });
|
|
321
|
+
setState({ ...result, target: invitation.target, state: Invitation.State.SUCCESS });
|
|
325
322
|
log.trace('dxos.sdk.invitations-handler.guest.onOpen', trace.end({ id: traceId }));
|
|
326
323
|
} catch (err: any) {
|
|
327
324
|
if (err instanceof TimeoutError) {
|
|
@@ -355,20 +352,25 @@ export class InvitationsHandler {
|
|
|
355
352
|
};
|
|
356
353
|
|
|
357
354
|
scheduleTask(ctx, async () => {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
355
|
+
const error = protocol.checkInvitation(invitation);
|
|
356
|
+
if (error) {
|
|
357
|
+
stream.error(error);
|
|
358
|
+
} else {
|
|
359
|
+
invariant(invitation.swarmKey);
|
|
360
|
+
const topic = invitation.swarmKey;
|
|
361
|
+
const swarmConnection = await this._networkManager.joinSwarm({
|
|
362
|
+
topic,
|
|
363
|
+
peerId: PublicKey.random(),
|
|
364
|
+
protocolProvider: createTeleportProtocolFactory(async (teleport) => {
|
|
365
|
+
teleport.addExtension('dxos.halo.invitations', createExtension());
|
|
366
|
+
}),
|
|
367
|
+
topology: new StarTopology(topic),
|
|
368
|
+
label: 'invitation guest',
|
|
369
|
+
});
|
|
370
|
+
ctx.onDispose(() => swarmConnection.close());
|
|
371
|
+
|
|
372
|
+
setState({ state: Invitation.State.CONNECTING });
|
|
373
|
+
}
|
|
372
374
|
});
|
|
373
375
|
|
|
374
376
|
const observable = new AuthenticatingInvitation({
|
|
@@ -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,
|
|
@@ -8,7 +8,7 @@ import { type Config } from '@dxos/config';
|
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
9
|
import { DocumentModel } from '@dxos/document-model';
|
|
10
10
|
import { DataServiceImpl } from '@dxos/echo-pipeline';
|
|
11
|
-
import { type TypedObject, base } from '@dxos/echo-schema';
|
|
11
|
+
import { type TypedObject, base, getRawDoc } from '@dxos/echo-schema';
|
|
12
12
|
import { invariant } from '@dxos/invariant';
|
|
13
13
|
import { PublicKey } from '@dxos/keys';
|
|
14
14
|
import { log } from '@dxos/log';
|
|
@@ -28,7 +28,7 @@ import { ServiceContext } from './service-context';
|
|
|
28
28
|
import { ServiceRegistry } from './service-registry';
|
|
29
29
|
import { DevicesServiceImpl } from '../devices';
|
|
30
30
|
import { DevtoolsServiceImpl, DevtoolsHostEvents } from '../devtools';
|
|
31
|
-
import { type CreateIdentityOptions
|
|
31
|
+
import { IdentityServiceImpl, type CreateIdentityOptions } from '../identity';
|
|
32
32
|
import { InvitationsServiceImpl } from '../invitations';
|
|
33
33
|
import { Lock, type ResourceLock } from '../locks';
|
|
34
34
|
import { LoggingServiceImpl } from '../logging';
|
|
@@ -260,7 +260,7 @@ export class ClientServicesHost {
|
|
|
260
260
|
SystemService: this._systemService,
|
|
261
261
|
|
|
262
262
|
IdentityService: new IdentityServiceImpl(
|
|
263
|
-
(params) => this._createIdentity(params),
|
|
263
|
+
(params, useAutomerge) => this._createIdentity(params, useAutomerge),
|
|
264
264
|
this._serviceContext.identityManager,
|
|
265
265
|
this._serviceContext.keyring,
|
|
266
266
|
(profile) => this._serviceContext.broadcastProfileUpdate(profile),
|
|
@@ -351,21 +351,36 @@ export class ClientServicesHost {
|
|
|
351
351
|
await this._callbacks?.onReset?.();
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
private async _createIdentity(params
|
|
354
|
+
private async _createIdentity(params: CreateIdentityOptions, useAutomerge: boolean) {
|
|
355
355
|
const identity = await this._serviceContext.createIdentity(params);
|
|
356
356
|
|
|
357
357
|
// Setup default space.
|
|
358
358
|
await this._serviceContext.initialized.wait();
|
|
359
359
|
const space = await this._serviceContext.dataSpaceManager!.createSpace();
|
|
360
|
-
|
|
360
|
+
|
|
361
|
+
const obj: TypedObject = new Properties(undefined, { automerge: useAutomerge });
|
|
361
362
|
obj[defaultKey] = identity.identityKey.toHex();
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
363
|
+
|
|
364
|
+
if (!useAutomerge) {
|
|
365
|
+
await this._serviceRegistry.services.DataService!.write({
|
|
366
|
+
spaceKey: space.key,
|
|
367
|
+
batch: {
|
|
368
|
+
objects: [createGenesisMutationFromTypedObject(obj)],
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
await this._serviceRegistry.services.DataService!.flush({ spaceKey: space.key });
|
|
372
|
+
} else {
|
|
373
|
+
// TODO(dmaretskyi): Refactor this.
|
|
374
|
+
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
375
|
+
invariant(automergeIndex);
|
|
376
|
+
const document = await this._serviceContext.automergeHost.repo.find(automergeIndex as any);
|
|
377
|
+
await document.whenReady();
|
|
378
|
+
|
|
379
|
+
document.change((doc: any) => {
|
|
380
|
+
doc.objects ??= {};
|
|
381
|
+
doc.objects[obj[base]._id] = getRawDoc(obj).handle.docSync();
|
|
382
|
+
});
|
|
383
|
+
}
|
|
369
384
|
|
|
370
385
|
return identity;
|
|
371
386
|
}
|
|
@@ -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";
|