@dxos/client-services 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0
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-HJH6BNTN.mjs → chunk-3LSLNVKQ.mjs} +2102 -1870
- package/dist/lib/browser/chunk-3LSLNVKQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs +22 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs.map +7 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +451 -67
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/browser.mjs +126 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +66 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +36 -17
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ONQM6RQH.mjs → chunk-5S7PIHLS.mjs} +1942 -1579
- package/dist/lib/node-esm/chunk-5S7PIHLS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs +22 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +451 -67
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs +126 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +66 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +36 -17
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +2 -2
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +6 -6
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +7 -6
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +1 -6
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +8 -11
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +4 -4
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +2 -3
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -2
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/index.d.ts +1 -1
- package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
- package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +13 -8
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +20 -6
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +6 -0
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +27 -15
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +24 -8
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -6
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +6 -5
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +31 -4
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-session.d.ts +2 -2
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +70 -48
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +8 -5
- package/src/packlets/agents/edge-agent-service.ts +2 -1
- package/src/packlets/devices/devices-service.test.ts +0 -1
- package/src/packlets/devtools/devtools.ts +2 -3
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.ts +2 -2
- package/src/packlets/identity/contacts-service.ts +0 -1
- package/src/packlets/identity/identity-manager.test.ts +5 -5
- package/src/packlets/identity/identity-manager.ts +21 -18
- package/src/packlets/identity/identity-recovery-manager.ts +22 -18
- package/src/packlets/identity/identity-service.test.ts +6 -27
- package/src/packlets/identity/identity-service.ts +5 -76
- package/src/packlets/identity/identity.test.ts +2 -2
- package/src/packlets/identity/identity.ts +9 -32
- package/src/packlets/invitations/device-invitation-protocol.ts +5 -6
- package/src/packlets/invitations/edge-invitation-handler.ts +4 -3
- package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
- package/src/packlets/invitations/invitation-host-extension.ts +6 -4
- package/src/packlets/invitations/invitation-protocol.ts +2 -3
- package/src/packlets/invitations/invitations-handler.test.ts +4 -5
- package/src/packlets/invitations/invitations-handler.ts +10 -10
- package/src/packlets/invitations/invitations-manager.ts +37 -14
- package/src/packlets/invitations/invitations-service.ts +4 -4
- package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
- package/src/packlets/invitations/space-invitation-protocol.ts +10 -15
- package/src/packlets/locks/index.ts +1 -1
- package/src/packlets/logging/logging-service.ts +4 -0
- package/src/packlets/network/network-service.test.ts +0 -1
- package/src/packlets/network/network-service.ts +5 -4
- package/src/packlets/services/client-rpc-server.ts +4 -4
- package/src/packlets/services/feed-syncer.test.ts +340 -0
- package/src/packlets/services/feed-syncer.ts +337 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +3 -2
- package/src/packlets/services/service-context.ts +129 -44
- package/src/packlets/services/service-host.test.ts +8 -8
- package/src/packlets/services/service-host.ts +63 -22
- package/src/packlets/services/service-registry.test.ts +0 -1
- package/src/packlets/space-export/space-archive-reader.ts +64 -3
- package/src/packlets/space-export/space-archive-writer.ts +39 -2
- package/src/packlets/space-export/space-archive.test.ts +287 -0
- package/src/packlets/spaces/data-space-manager.test.ts +79 -13
- package/src/packlets/spaces/data-space-manager.ts +97 -107
- package/src/packlets/spaces/data-space.ts +52 -29
- package/src/packlets/spaces/edge-feed-replicator.test.ts +1 -1
- package/src/packlets/spaces/edge-feed-replicator.ts +10 -9
- package/src/packlets/spaces/epoch-migrations.ts +5 -5
- package/src/packlets/spaces/genesis.ts +6 -1
- package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.ts +10 -9
- package/src/packlets/spaces/spaces-service.test.ts +9 -7
- package/src/packlets/spaces/spaces-service.ts +40 -16
- package/src/packlets/storage/storage.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +10 -6
- package/src/packlets/testing/test-builder.ts +36 -10
- package/src/packlets/worker/worker-runtime.ts +150 -13
- package/src/packlets/worker/worker-session.ts +8 -8
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-HJH6BNTN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ONQM6RQH.mjs.map +0 -7
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
- package/src/packlets/identity/default-space-state-machine.ts +0 -44
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
Invitation,
|
|
22
22
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
23
23
|
import { SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
24
|
+
import { trace } from '@dxos/tracing';
|
|
24
25
|
|
|
25
26
|
import type { InvitationProtocol } from './invitation-protocol';
|
|
26
27
|
import { type InvitationsHandler, createAdmissionKeypair } from './invitations-handler';
|
|
@@ -29,6 +30,7 @@ import { type InvitationsHandler, createAdmissionKeypair } from './invitations-h
|
|
|
29
30
|
* Entry point for creating and accepting invitations, keeps track of existing invitation set and
|
|
30
31
|
* emits events when the set changes.
|
|
31
32
|
*/
|
|
33
|
+
@trace.resource()
|
|
32
34
|
export class InvitationsManager {
|
|
33
35
|
private readonly _createInvitations = new Map<string, CancellableInvitation>();
|
|
34
36
|
private readonly _acceptInvitations = new Map<string, AuthenticatingInvitation>();
|
|
@@ -48,7 +50,11 @@ export class InvitationsManager {
|
|
|
48
50
|
private readonly _metadataStore: MetadataStore,
|
|
49
51
|
) {}
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
@trace.span({ showInBrowserTimeline: true })
|
|
54
|
+
async createInvitation(
|
|
55
|
+
ctx: Context,
|
|
56
|
+
options: Partial<Invitation> & Pick<Invitation, 'kind'>,
|
|
57
|
+
): Promise<CancellableInvitation> {
|
|
52
58
|
if (options.invitationId) {
|
|
53
59
|
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
54
60
|
if (existingInvitation) {
|
|
@@ -63,7 +69,11 @@ export class InvitationsManager {
|
|
|
63
69
|
}
|
|
64
70
|
const invitation = this._createInvitation(handler, options);
|
|
65
71
|
|
|
66
|
-
const {
|
|
72
|
+
const {
|
|
73
|
+
ctx: invitationCtx,
|
|
74
|
+
stream,
|
|
75
|
+
observableInvitation,
|
|
76
|
+
} = this._createObservableInvitation(ctx, handler, invitation);
|
|
67
77
|
|
|
68
78
|
this._createInvitations.set(invitation.invitationId, observableInvitation);
|
|
69
79
|
this.invitationCreated.emit(invitation);
|
|
@@ -84,12 +94,12 @@ export class InvitationsManager {
|
|
|
84
94
|
return observableInvitation;
|
|
85
95
|
}
|
|
86
96
|
|
|
87
|
-
this._invitationsHandler.handleInvitationFlow(
|
|
97
|
+
this._invitationsHandler.handleInvitationFlow(invitationCtx, stream, handler, observableInvitation.get());
|
|
88
98
|
|
|
89
99
|
return observableInvitation;
|
|
90
100
|
}
|
|
91
101
|
|
|
92
|
-
async loadPersistentInvitations(): Promise<{ invitations: Invitation[] }> {
|
|
102
|
+
async loadPersistentInvitations(ctx: Context): Promise<{ invitations: Invitation[] }> {
|
|
93
103
|
if (this._persistentInvitationsLoaded) {
|
|
94
104
|
const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
|
|
95
105
|
return { invitations };
|
|
@@ -101,7 +111,7 @@ export class InvitationsManager {
|
|
|
101
111
|
|
|
102
112
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
103
113
|
invariant(!this._createInvitations.get(persistentInvitation.invitationId), 'invitation already exists');
|
|
104
|
-
return this.createInvitation({ ...persistentInvitation, persistent: false });
|
|
114
|
+
return this.createInvitation(ctx, { ...persistentInvitation, persistent: false });
|
|
105
115
|
});
|
|
106
116
|
const cInvitations = await Promise.all(loadTasks);
|
|
107
117
|
|
|
@@ -115,7 +125,7 @@ export class InvitationsManager {
|
|
|
115
125
|
}
|
|
116
126
|
}
|
|
117
127
|
|
|
118
|
-
acceptInvitation(request: AcceptInvitationRequest): AuthenticatingInvitation {
|
|
128
|
+
acceptInvitation(_ctx: Context, request: AcceptInvitationRequest): AuthenticatingInvitation {
|
|
119
129
|
const options = request.invitation;
|
|
120
130
|
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
121
131
|
if (existingInvitation) {
|
|
@@ -123,8 +133,20 @@ export class InvitationsManager {
|
|
|
123
133
|
}
|
|
124
134
|
|
|
125
135
|
const handler = this._getHandler(options);
|
|
126
|
-
const {
|
|
127
|
-
|
|
136
|
+
const {
|
|
137
|
+
ctx: invitationCtx,
|
|
138
|
+
invitation,
|
|
139
|
+
stream,
|
|
140
|
+
otpEnteredTrigger,
|
|
141
|
+
} = this._createObservableAcceptingInvitation(handler, options);
|
|
142
|
+
this._invitationsHandler.acceptInvitation(
|
|
143
|
+
invitationCtx,
|
|
144
|
+
stream,
|
|
145
|
+
handler,
|
|
146
|
+
options,
|
|
147
|
+
otpEnteredTrigger,
|
|
148
|
+
request.deviceProfile,
|
|
149
|
+
);
|
|
128
150
|
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
129
151
|
this.invitationAccepted.emit(invitation.get());
|
|
130
152
|
|
|
@@ -198,7 +220,7 @@ export class InvitationsManager {
|
|
|
198
220
|
state = Invitation.State.INIT,
|
|
199
221
|
timeout = INVITATION_TIMEOUT,
|
|
200
222
|
swarmKey = PublicKey.random(),
|
|
201
|
-
persistent = _options?.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY,
|
|
223
|
+
persistent = _options?.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY,
|
|
202
224
|
created = new Date(),
|
|
203
225
|
guestKeypair = undefined,
|
|
204
226
|
role = SpaceMember.Role.ADMIN,
|
|
@@ -232,17 +254,18 @@ export class InvitationsManager {
|
|
|
232
254
|
}
|
|
233
255
|
|
|
234
256
|
private _createObservableInvitation(
|
|
257
|
+
ctx: Context,
|
|
235
258
|
handler: InvitationProtocol,
|
|
236
259
|
invitation: Invitation,
|
|
237
260
|
): { ctx: Context; stream: PushStream<Invitation>; observableInvitation: CancellableInvitation } {
|
|
238
261
|
const stream = new PushStream<Invitation>();
|
|
239
|
-
const
|
|
262
|
+
const invitationCtx = ctx.derive({
|
|
240
263
|
onError: (err) => {
|
|
241
264
|
stream.error(err);
|
|
242
|
-
void
|
|
265
|
+
void invitationCtx.dispose();
|
|
243
266
|
},
|
|
244
267
|
});
|
|
245
|
-
|
|
268
|
+
invitationCtx.onDispose(() => {
|
|
246
269
|
log('complete', { ...handler.toJSON() });
|
|
247
270
|
stream.complete();
|
|
248
271
|
});
|
|
@@ -251,10 +274,10 @@ export class InvitationsManager {
|
|
|
251
274
|
subscriber: stream.observable,
|
|
252
275
|
onCancel: async () => {
|
|
253
276
|
stream.next({ ...invitation, state: Invitation.State.CANCELLED });
|
|
254
|
-
await
|
|
277
|
+
await invitationCtx.dispose();
|
|
255
278
|
},
|
|
256
279
|
});
|
|
257
|
-
return { ctx, stream, observableInvitation };
|
|
280
|
+
return { ctx: invitationCtx, stream, observableInvitation };
|
|
258
281
|
}
|
|
259
282
|
|
|
260
283
|
private _createObservableAcceptingInvitation(
|
|
@@ -28,9 +28,9 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
createInvitation(options: Invitation): Stream<Invitation> {
|
|
31
|
-
return new Stream<Invitation>(({ next, close }) => {
|
|
31
|
+
return new Stream<Invitation>(({ ctx, next, close }) => {
|
|
32
32
|
void this._invitationsManager
|
|
33
|
-
.createInvitation(options)
|
|
33
|
+
.createInvitation(ctx, options)
|
|
34
34
|
.then((invitation) => {
|
|
35
35
|
trace.metrics.increment('dxos.invitation.created');
|
|
36
36
|
invitation.subscribe(next, close, close);
|
|
@@ -40,8 +40,8 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
acceptInvitation(request: AcceptInvitationRequest): Stream<Invitation> {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
return new Stream<Invitation>(({ ctx, next, close }) => {
|
|
44
|
+
const invitation = this._invitationsManager.acceptInvitation(ctx, request);
|
|
45
45
|
invitation.subscribe(next, close, close);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Trigger, chain } from '@dxos/async';
|
|
8
|
+
import { Context } from '@dxos/context';
|
|
8
9
|
import { raise } from '@dxos/debug';
|
|
9
10
|
import { AlreadyJoinedError } from '@dxos/protocols';
|
|
10
11
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
@@ -24,26 +25,26 @@ describe('services/space-invitations-protocol', () => {
|
|
|
24
25
|
test('genesis', async () => {
|
|
25
26
|
const [peer] = await chain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(1));
|
|
26
27
|
|
|
27
|
-
const space = await peer.dataSpaceManager!.createSpace();
|
|
28
|
+
const space = await peer.dataSpaceManager!.createSpace(new Context());
|
|
28
29
|
expect(peer.dataSpaceManager!.spaces.has(space.key)).to.be.true;
|
|
29
30
|
|
|
30
|
-
await space.close();
|
|
31
|
+
await space.close(new Context());
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
test('genesis & ready', async () => {
|
|
34
35
|
const [peer] = await chain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(1));
|
|
35
36
|
|
|
36
|
-
const space = await peer.dataSpaceManager!.createSpace();
|
|
37
|
+
const space = await peer.dataSpaceManager!.createSpace(new Context());
|
|
37
38
|
expect(peer.dataSpaceManager!.spaces.has(space.key)).to.be.true;
|
|
38
39
|
|
|
39
40
|
await peer.dataSpaceManager?.waitUntilSpaceReady(space.key);
|
|
40
|
-
await space.close();
|
|
41
|
+
await space.close(new Context());
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
test('invitation with no auth', async () => {
|
|
44
45
|
const [host, guest] = await chain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
|
|
45
46
|
|
|
46
|
-
const space1 = await host.dataSpaceManager!.createSpace();
|
|
47
|
+
const space1 = await host.dataSpaceManager!.createSpace(new Context());
|
|
47
48
|
const spaceKey = space1.key;
|
|
48
49
|
|
|
49
50
|
await Promise.all(performInvitation({ host, guest, options: { kind: Invitation.Kind.SPACE, spaceKey } }));
|
|
@@ -59,15 +60,15 @@ describe('services/space-invitations-protocol', () => {
|
|
|
59
60
|
|
|
60
61
|
await space2.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.timeframe);
|
|
61
62
|
|
|
62
|
-
await space1.close();
|
|
63
|
-
await space2.close();
|
|
63
|
+
await space1.close(new Context());
|
|
64
|
+
await space2.close(new Context());
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
test('invitation when already joined', async () => {
|
|
68
69
|
const [host, guest] = await chain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
|
|
69
70
|
|
|
70
|
-
const space1 = await host.dataSpaceManager!.createSpace();
|
|
71
|
+
const space1 = await host.dataSpaceManager!.createSpace(new Context());
|
|
71
72
|
const spaceKey = space1.key;
|
|
72
73
|
|
|
73
74
|
await Promise.all(performInvitation({ host, guest, options: { kind: Invitation.Kind.SPACE, spaceKey } }));
|
|
@@ -96,7 +97,7 @@ describe('services/space-invitations-protocol', () => {
|
|
|
96
97
|
|
|
97
98
|
let attempt = 0;
|
|
98
99
|
|
|
99
|
-
const space1 = await host.dataSpaceManager!.createSpace();
|
|
100
|
+
const space1 = await host.dataSpaceManager!.createSpace(new Context());
|
|
100
101
|
|
|
101
102
|
const [{ invitation: invitation1, error: error1 }, { invitation: invitation2, error: error2 }] = await Promise.all(
|
|
102
103
|
performInvitation({
|
|
@@ -143,8 +144,8 @@ describe('services/space-invitations-protocol', () => {
|
|
|
143
144
|
|
|
144
145
|
await space2.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.timeframe);
|
|
145
146
|
|
|
146
|
-
await space1.close();
|
|
147
|
-
await space2.close();
|
|
147
|
+
await space1.close(new Context());
|
|
148
|
+
await space2.close(new Context());
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
expect(
|
|
@@ -154,14 +155,14 @@ describe('services/space-invitations-protocol', () => {
|
|
|
154
155
|
|
|
155
156
|
test('timeout', async () => {
|
|
156
157
|
const [host, guest] = await chain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
|
|
157
|
-
const space = await host.dataSpaceManager!.createSpace();
|
|
158
|
+
const space = await host.dataSpaceManager!.createSpace(new Context());
|
|
158
159
|
const hostInvitation = await createInvitation(host, {
|
|
159
160
|
kind: Invitation.Kind.SPACE,
|
|
160
161
|
spaceKey: space.key,
|
|
161
162
|
timeout: 100,
|
|
162
163
|
});
|
|
163
164
|
const invitation = hostInvitation.get();
|
|
164
|
-
await host.close();
|
|
165
|
+
await host.close(Context.default());
|
|
165
166
|
|
|
166
167
|
const guestTimeout = new Trigger();
|
|
167
168
|
const guestInvitation = await acceptInvitation(guest, invitation);
|
|
@@ -180,7 +181,7 @@ describe('services/space-invitations-protocol', () => {
|
|
|
180
181
|
const hostConnected = new Trigger<Invitation>();
|
|
181
182
|
const guestConnected = new Trigger<Invitation>();
|
|
182
183
|
|
|
183
|
-
const space1 = await host.dataSpaceManager!.createSpace();
|
|
184
|
+
const space1 = await host.dataSpaceManager!.createSpace(new Context());
|
|
184
185
|
|
|
185
186
|
const invitationPromises = performInvitation({
|
|
186
187
|
host,
|
|
@@ -213,7 +214,7 @@ describe('services/space-invitations-protocol', () => {
|
|
|
213
214
|
expect(invitation1?.state).to.eq(Invitation.State.CANCELLED);
|
|
214
215
|
expect(error).to.exist;
|
|
215
216
|
|
|
216
|
-
await space1.close();
|
|
217
|
+
await space1.close(new Context());
|
|
217
218
|
});
|
|
218
219
|
|
|
219
220
|
// TODO(burdon): Flaky.
|
|
@@ -223,7 +224,7 @@ describe('services/space-invitations-protocol', () => {
|
|
|
223
224
|
// createPeers(GUEST_COUNT + 1)
|
|
224
225
|
// );
|
|
225
226
|
|
|
226
|
-
// const hostSpace = await host.dataSpaceManager!.createSpace();
|
|
227
|
+
// const hostSpace = await host.dataSpaceManager!.createSpace(new Context());
|
|
227
228
|
// const swarmKey = PublicKey.random();
|
|
228
229
|
// const hostObservable = await host.spaceInvitations!.createInvitation(hostSpace, {
|
|
229
230
|
// swarmKey,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Context } from '@dxos/context';
|
|
5
6
|
import {
|
|
6
7
|
createCancelDelegatedSpaceInvitationCredential,
|
|
7
8
|
createDelegatedSpaceInvitationCredential,
|
|
@@ -12,13 +13,7 @@ import { invariant } from '@dxos/invariant';
|
|
|
12
13
|
import { type Keyring } from '@dxos/keyring';
|
|
13
14
|
import { type PublicKey } from '@dxos/keys';
|
|
14
15
|
import { log } from '@dxos/log';
|
|
15
|
-
import {
|
|
16
|
-
AlreadyJoinedError,
|
|
17
|
-
type ApiError,
|
|
18
|
-
AuthorizationError,
|
|
19
|
-
InvalidInvitationError,
|
|
20
|
-
SpaceNotFoundError,
|
|
21
|
-
} from '@dxos/protocols';
|
|
16
|
+
import { AlreadyJoinedError, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from '@dxos/protocols';
|
|
22
17
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
23
18
|
import { type ProfileDocument, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
24
19
|
import {
|
|
@@ -28,7 +23,6 @@ import {
|
|
|
28
23
|
} from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
29
24
|
|
|
30
25
|
import { type DataSpaceManager, type SigningContext } from '../spaces';
|
|
31
|
-
|
|
32
26
|
import { type InvitationProtocol } from './invitation-protocol';
|
|
33
27
|
import { computeExpirationTime } from './utils';
|
|
34
28
|
|
|
@@ -48,16 +42,16 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
48
42
|
};
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
checkCanInviteNewMembers():
|
|
45
|
+
checkCanInviteNewMembers(): Error | undefined {
|
|
52
46
|
if (this._spaceKey == null) {
|
|
53
|
-
return new InvalidInvitationError('No spaceKey was provided for a space invitation.');
|
|
47
|
+
return new InvalidInvitationError({ message: 'No spaceKey was provided for a space invitation.' });
|
|
54
48
|
}
|
|
55
49
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
56
50
|
if (space == null) {
|
|
57
51
|
return new SpaceNotFoundError(this._spaceKey);
|
|
58
52
|
}
|
|
59
53
|
if (!space?.inner.spaceState.hasMembershipManagementPermission(this._signingContext.identityKey)) {
|
|
60
|
-
return new AuthorizationError('No member management permission.');
|
|
54
|
+
return new AuthorizationError({ message: 'No member management permission.' });
|
|
61
55
|
}
|
|
62
56
|
return undefined;
|
|
63
57
|
}
|
|
@@ -148,10 +142,10 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
148
142
|
|
|
149
143
|
checkInvitation(invitation: Partial<Invitation>): InvalidInvitationError | AlreadyJoinedError | undefined {
|
|
150
144
|
if (invitation.spaceKey == null) {
|
|
151
|
-
return new InvalidInvitationError('No spaceKey was provided for a space invitation.');
|
|
145
|
+
return new InvalidInvitationError({ message: 'No spaceKey was provided for a space invitation.' });
|
|
152
146
|
}
|
|
153
147
|
if (this._spaceManager.spaces.has(invitation.spaceKey)) {
|
|
154
|
-
return new AlreadyJoinedError('Already joined space.');
|
|
148
|
+
return new AlreadyJoinedError({ message: 'Already joined space.' });
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
|
|
@@ -184,15 +178,16 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
184
178
|
invariant(credential.subject.id.equals(this._signingContext.identityKey));
|
|
185
179
|
|
|
186
180
|
if (this._spaceManager.spaces.has(assertion.spaceKey)) {
|
|
187
|
-
throw new AlreadyJoinedError('Already joined space.');
|
|
181
|
+
throw new AlreadyJoinedError({ message: 'Already joined space.' });
|
|
188
182
|
}
|
|
189
183
|
|
|
190
184
|
// Create local space.
|
|
191
|
-
await this._spaceManager.acceptSpace({
|
|
185
|
+
await this._spaceManager.acceptSpace(Context.default(), {
|
|
192
186
|
spaceKey: assertion.spaceKey,
|
|
193
187
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
194
188
|
controlTimeframe,
|
|
195
189
|
dataTimeframe,
|
|
190
|
+
tags: assertion.tags,
|
|
196
191
|
});
|
|
197
192
|
|
|
198
193
|
await this._signingContext.recordCredential(credential);
|
|
@@ -26,6 +26,10 @@ import { getDebugName, jsonify, numericalValues, tracer } from '@dxos/util';
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Logging service used to spy on logs of the host.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated This was created so that logs from the shared worker (WorkerClientServices) could be
|
|
31
|
+
* seen in the main window console without opening the shared worker DevTools. Shared worker client
|
|
32
|
+
* services is deprecated; dedicated worker logs already show in the main window console.
|
|
29
33
|
*/
|
|
30
34
|
export class LoggingServiceImpl implements LoggingService {
|
|
31
35
|
private readonly _logs = new Event<NaturalLogEntry>();
|
|
@@ -10,7 +10,6 @@ import { ConnectionState, type NetworkService } from '@dxos/protocols/proto/dxos
|
|
|
10
10
|
|
|
11
11
|
import { type ServiceContext } from '../services';
|
|
12
12
|
import { createServiceContext } from '../testing';
|
|
13
|
-
|
|
14
13
|
import { NetworkServiceImpl } from './network-service';
|
|
15
14
|
|
|
16
15
|
describe('NetworkService', () => {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Stream } from '@dxos/codec-protobuf/stream';
|
|
6
|
+
import { Context } from '@dxos/context';
|
|
6
7
|
import { type EdgeConnection } from '@dxos/edge-client';
|
|
7
8
|
import { type SignalManager } from '@dxos/messaging';
|
|
8
9
|
import { type SwarmNetworkManager } from '@dxos/network-manager';
|
|
@@ -48,15 +49,15 @@ export class NetworkServiceImpl implements NetworkService {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
async joinSwarm(request: JoinRequest): Promise<void> {
|
|
51
|
-
return this.signalManager.join(request);
|
|
52
|
+
return this.signalManager.join(Context.default(), request);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
async leaveSwarm(request: LeaveRequest): Promise<void> {
|
|
55
|
-
return this.signalManager.leave(request);
|
|
56
|
+
return this.signalManager.leave(Context.default(), request);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
async querySwarm(request: QueryRequest): Promise<SwarmResponse> {
|
|
59
|
-
return this.signalManager.query(request);
|
|
60
|
+
return this.signalManager.query(Context.default(), request);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
subscribeSwarmState(request: SubscribeSwarmStateRequest): Stream<SwarmResponse> {
|
|
@@ -70,7 +71,7 @@ export class NetworkServiceImpl implements NetworkService {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
async sendMessage(message: Message): Promise<void> {
|
|
73
|
-
return this.signalManager.sendMessage(message);
|
|
74
|
+
return this.signalManager.sendMessage(Context.default(), message);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
subscribeMessages(peer: Peer): Stream<Message> {
|
|
@@ -11,7 +11,7 @@ import { type MaybePromise } from '@dxos/util';
|
|
|
11
11
|
|
|
12
12
|
import { type ServiceRegistry } from './service-registry';
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type ClientRpcServerProps = {
|
|
15
15
|
serviceRegistry: ServiceRegistry<ClientServices>;
|
|
16
16
|
handleCall?: (
|
|
17
17
|
method: string,
|
|
@@ -30,8 +30,8 @@ export class ClientRpcServer {
|
|
|
30
30
|
private readonly _serviceRegistry: ServiceRegistry<ClientServices>;
|
|
31
31
|
private readonly _rpcPeer: RpcPeer;
|
|
32
32
|
private readonly _handlerCache = new Map<string, ServiceHandler<any>>();
|
|
33
|
-
private readonly _handleCall:
|
|
34
|
-
private readonly _handleStream:
|
|
33
|
+
private readonly _handleCall: ClientRpcServerProps['handleCall'];
|
|
34
|
+
private readonly _handleStream: ClientRpcServerProps['handleStream'];
|
|
35
35
|
|
|
36
36
|
@trace.metricsCounter()
|
|
37
37
|
private readonly _callMetrics = new MapCounter();
|
|
@@ -41,7 +41,7 @@ export class ClientRpcServer {
|
|
|
41
41
|
return Object.keys(this._serviceRegistry.services);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
constructor(params:
|
|
44
|
+
constructor(params: ClientRpcServerProps) {
|
|
45
45
|
const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
|
|
46
46
|
this._handleCall = handleCall;
|
|
47
47
|
this._handleStream = handleStream;
|