@dxos/client-services 0.7.5-main.9d26e3a → 0.7.5-main.e9bb01b
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-27A4ATQX.mjs → chunk-O46EJ5BJ.mjs} +172 -123
- package/dist/lib/browser/chunk-O46EJ5BJ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-7FKXMJDD.cjs → chunk-WFDMSV4I.cjs} +202 -153
- package/dist/lib/node/chunk-WFDMSV4I.cjs.map +7 -0
- package/dist/lib/node/index.cjs +47 -47
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +8 -8
- package/dist/lib/node-esm/{chunk-HGN7FHFK.mjs → chunk-UWR5XM7L.mjs} +172 -123
- package/dist/lib/node-esm/chunk-UWR5XM7L.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/keys.d.ts +1 -1
- package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/metadata.d.ts +1 -1
- package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/spaces.d.ts +1 -1
- package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/utils.d.ts +1 -0
- package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +9 -2
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +3 -0
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -38
- package/src/packlets/agents/edge-agent-service.ts +1 -1
- package/src/packlets/devices/devices-service.ts +1 -1
- package/src/packlets/devtools/devtools.ts +1 -1
- package/src/packlets/devtools/feeds.ts +1 -1
- package/src/packlets/devtools/keys.ts +1 -1
- package/src/packlets/devtools/metadata.ts +1 -1
- package/src/packlets/devtools/network.ts +1 -1
- package/src/packlets/devtools/spaces.ts +1 -1
- package/src/packlets/identity/contacts-service.ts +1 -1
- package/src/packlets/identity/identity-service.ts +1 -1
- package/src/packlets/invitations/invitations-handler.ts +15 -6
- package/src/packlets/invitations/invitations-manager.ts +1 -1
- package/src/packlets/invitations/invitations-service.ts +1 -1
- package/src/packlets/invitations/space-invitation-protocol.ts +2 -3
- package/src/packlets/invitations/utils.ts +7 -0
- package/src/packlets/logging/logging-service.ts +1 -1
- package/src/packlets/network/network-service.ts +39 -1
- package/src/packlets/services/service-context.ts +1 -0
- package/src/packlets/spaces/data-space-manager.ts +1 -1
- package/src/packlets/spaces/notarization-plugin.ts +32 -17
- package/src/packlets/spaces/spaces-service.ts +1 -1
- package/src/packlets/system/system-service.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-27A4ATQX.mjs.map +0 -7
- package/dist/lib/node/chunk-7FKXMJDD.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HGN7FHFK.mjs.map +0 -7
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PushStream, scheduleTask, TimeoutError, type Trigger } from '@dxos/async';
|
|
6
|
-
import { INVITATION_TIMEOUT } from '@dxos/client-protocol';
|
|
6
|
+
import { INVITATION_TIMEOUT, getExpirationTime } from '@dxos/client-protocol';
|
|
7
7
|
import { type Context, ContextDisposedError } from '@dxos/context';
|
|
8
8
|
import { createKeyPair, sign } from '@dxos/crypto';
|
|
9
9
|
import { type EdgeHttpClient } from '@dxos/edge-client';
|
|
@@ -11,7 +11,7 @@ import { invariant } from '@dxos/invariant';
|
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { createTeleportProtocolFactory, type SwarmNetworkManager, type SwarmConnection } from '@dxos/network-manager';
|
|
14
|
-
import { InvalidInvitationExtensionRoleError, trace } from '@dxos/protocols';
|
|
14
|
+
import { InvalidInvitationError, InvalidInvitationExtensionRoleError, trace } from '@dxos/protocols';
|
|
15
15
|
import { type AdmissionKeypair, Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
16
16
|
import { type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
17
17
|
import { AuthenticationResponse, type IntroductionResponse } from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
@@ -188,8 +188,9 @@ export class InvitationsHandler {
|
|
|
188
188
|
return extension;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const expiresOn = getExpirationTime(invitation);
|
|
192
|
+
if (expiresOn) {
|
|
193
|
+
if (expiresOn.getTime() < Date.now()) {
|
|
193
194
|
log.warn('invitation has already expired');
|
|
194
195
|
guardedState.set(null, Invitation.State.EXPIRED);
|
|
195
196
|
void ctx.dispose().catch((err) => log.catch(err));
|
|
@@ -204,7 +205,7 @@ export class InvitationsHandler {
|
|
|
204
205
|
metrics.increment('dxos.invitation.expired');
|
|
205
206
|
await ctx.dispose();
|
|
206
207
|
},
|
|
207
|
-
|
|
208
|
+
expiresOn.getTime() - Date.now(),
|
|
208
209
|
);
|
|
209
210
|
}
|
|
210
211
|
|
|
@@ -397,7 +398,7 @@ export class InvitationsHandler {
|
|
|
397
398
|
edgeInvitationHandler.handle(ctx, guardedState, protocol, deviceProfile);
|
|
398
399
|
|
|
399
400
|
scheduleTask(ctx, async () => {
|
|
400
|
-
const error =
|
|
401
|
+
const error = checkInvitation(protocol, invitation);
|
|
401
402
|
if (error) {
|
|
402
403
|
stream.error(error);
|
|
403
404
|
await ctx.dispose();
|
|
@@ -499,6 +500,14 @@ export class InvitationsHandler {
|
|
|
499
500
|
}
|
|
500
501
|
}
|
|
501
502
|
|
|
503
|
+
const checkInvitation = (protocol: InvitationProtocol, invitation: Partial<Invitation>) => {
|
|
504
|
+
const expiresOn = getExpirationTime(invitation);
|
|
505
|
+
if (expiresOn && expiresOn.getTime() < Date.now()) {
|
|
506
|
+
return new InvalidInvitationError('Invitation already expired.');
|
|
507
|
+
}
|
|
508
|
+
return protocol.checkInvitation(invitation);
|
|
509
|
+
};
|
|
510
|
+
|
|
502
511
|
export const createAdmissionKeypair = (): AdmissionKeypair => {
|
|
503
512
|
const keypair = createKeyPair();
|
|
504
513
|
return { publicKey: PublicKey.from(keypair.publicKey), privateKey: keypair.secretKey };
|
|
@@ -202,7 +202,7 @@ export class InvitationsManager {
|
|
|
202
202
|
created = new Date(),
|
|
203
203
|
guestKeypair = undefined,
|
|
204
204
|
role = SpaceMember.Role.ADMIN,
|
|
205
|
-
lifetime = 86400, //
|
|
205
|
+
lifetime = 86400 * 7, // 7 days,
|
|
206
206
|
multiUse = false,
|
|
207
207
|
...options
|
|
208
208
|
} = _options ?? {};
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
29
29
|
|
|
30
30
|
import { type InvitationProtocol } from './invitation-protocol';
|
|
31
|
+
import { computeExpirationTime } from './utils';
|
|
31
32
|
import { type DataSpaceManager, type SigningContext } from '../spaces';
|
|
32
33
|
|
|
33
34
|
export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
@@ -113,9 +114,7 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
113
114
|
authMethod: invitation.authMethod,
|
|
114
115
|
swarmKey: invitation.swarmKey,
|
|
115
116
|
role: invitation.role ?? SpaceMember.Role.ADMIN,
|
|
116
|
-
expiresOn: invitation
|
|
117
|
-
? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime)
|
|
118
|
-
: undefined,
|
|
117
|
+
expiresOn: computeExpirationTime(invitation),
|
|
119
118
|
multiUse: invitation.multiUse ?? false,
|
|
120
119
|
guestKey:
|
|
121
120
|
invitation.authMethod === Invitation.AuthMethod.KNOWN_PUBLIC_KEY
|
|
@@ -10,6 +10,13 @@ export const stateToString = (state: Invitation.State): string => {
|
|
|
10
10
|
return Object.entries(Invitation.State).find(([key, val]) => val === state)?.[0] ?? 'unknown';
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
export const computeExpirationTime = (invitation: Partial<Invitation>): Date | undefined => {
|
|
14
|
+
if (!invitation.lifetime) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime * 1000);
|
|
18
|
+
};
|
|
19
|
+
|
|
13
20
|
export const tryAcquireBeforeContextDisposed = async (ctx: Context, mutex: Mutex): Promise<MutexGuard> => {
|
|
14
21
|
let guard: MutexGuard | undefined;
|
|
15
22
|
return cancelWithContext(
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Stream } from '@dxos/codec-protobuf';
|
|
5
|
+
import { Stream } from '@dxos/codec-protobuf/stream';
|
|
6
6
|
import { type SignalManager } from '@dxos/messaging';
|
|
7
7
|
import { type SwarmNetworkManager } from '@dxos/network-manager';
|
|
8
8
|
import {
|
|
9
|
+
type SubscribeSwarmStateRequest,
|
|
9
10
|
type NetworkService,
|
|
10
11
|
type NetworkStatus,
|
|
11
12
|
type UpdateConfigRequest,
|
|
12
13
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
14
|
+
import { type Peer, type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
15
|
+
import { type LeaveRequest, type JoinRequest, type Message } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
13
16
|
|
|
14
17
|
export class NetworkServiceImpl implements NetworkService {
|
|
15
18
|
constructor(
|
|
@@ -41,4 +44,39 @@ export class NetworkServiceImpl implements NetworkService {
|
|
|
41
44
|
async updateConfig(request: UpdateConfigRequest) {
|
|
42
45
|
await this.networkManager.setConnectionState(request.swarm);
|
|
43
46
|
}
|
|
47
|
+
|
|
48
|
+
async joinSwarm(request: JoinRequest): Promise<void> {
|
|
49
|
+
return this.signalManager.join(request);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async leaveSwarm(request: LeaveRequest): Promise<void> {
|
|
53
|
+
return this.signalManager.leave(request);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
subscribeSwarmState(request: SubscribeSwarmStateRequest): Stream<SwarmResponse> {
|
|
57
|
+
return new Stream<SwarmResponse>(({ next }) => {
|
|
58
|
+
const unsubscribe = this.signalManager.swarmState?.on((state) => {
|
|
59
|
+
if (request.topic.equals(state.swarmKey)) {
|
|
60
|
+
next(state);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return unsubscribe;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async sendMessage(message: Message): Promise<void> {
|
|
68
|
+
return this.signalManager.sendMessage(message);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
subscribeMessages(peer: Peer): Stream<Message> {
|
|
72
|
+
return new Stream<Message>(({ next }) => {
|
|
73
|
+
const unsubscribe = this.signalManager.onMessage.on((message) => {
|
|
74
|
+
if (message.recipient.peerKey === peer.peerKey) {
|
|
75
|
+
next(message);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return unsubscribe;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
44
82
|
}
|
|
@@ -154,6 +154,7 @@ export class ServiceContext extends Resource {
|
|
|
154
154
|
this.echoHost = new EchoHost({
|
|
155
155
|
kv: this.level,
|
|
156
156
|
peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
|
|
157
|
+
getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
|
|
157
158
|
});
|
|
158
159
|
|
|
159
160
|
this._meshReplicator = new MeshEchoReplicator();
|
|
@@ -609,7 +609,7 @@ export class DataSpaceManager extends Resource {
|
|
|
609
609
|
invitationId: invitation.invitationId,
|
|
610
610
|
swarmKey: invitation.swarmKey,
|
|
611
611
|
guestKeypair: invitation.guestKey ? { publicKey: invitation.guestKey } : undefined,
|
|
612
|
-
lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : undefined,
|
|
612
|
+
lifetime: invitation.expiresOn ? (invitation.expiresOn.getTime() - Date.now()) / 1000 : undefined,
|
|
613
613
|
multiUse: invitation.multiUse,
|
|
614
614
|
delegationCredentialId: credentialId,
|
|
615
615
|
persistent: false,
|
|
@@ -90,6 +90,7 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
90
90
|
|
|
91
91
|
private _activeEdgePollingIntervalHandle: any | undefined = undefined;
|
|
92
92
|
private readonly _activeEdgePollingInterval: number;
|
|
93
|
+
private _activeEdgePollingEnabled = false;
|
|
93
94
|
|
|
94
95
|
@logInfo
|
|
95
96
|
private readonly _spaceId: SpaceId;
|
|
@@ -106,18 +107,15 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
setActiveEdgePollingEnabled(enabled: boolean) {
|
|
109
|
-
invariant(this.isOpen);
|
|
110
110
|
const client = this._edgeClient;
|
|
111
111
|
invariant(client);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
clearInterval(this._activeEdgePollingIntervalHandle);
|
|
120
|
-
this._activeEdgePollingIntervalHandle = undefined;
|
|
112
|
+
this._activeEdgePollingEnabled = enabled;
|
|
113
|
+
if (this.isOpen) {
|
|
114
|
+
if (enabled && !this._activeEdgePollingIntervalHandle) {
|
|
115
|
+
this._startPeriodicEdgePolling(client);
|
|
116
|
+
} else if (!enabled && this._activeEdgePollingIntervalHandle) {
|
|
117
|
+
this._stopPeriodicEdgePolling();
|
|
118
|
+
}
|
|
121
119
|
}
|
|
122
120
|
}
|
|
123
121
|
|
|
@@ -126,16 +124,18 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
protected override async _open() {
|
|
129
|
-
if (this._edgeClient
|
|
130
|
-
|
|
127
|
+
if (this._edgeClient) {
|
|
128
|
+
if (this._activeEdgePollingEnabled) {
|
|
129
|
+
this._startPeriodicEdgePolling(this._edgeClient);
|
|
130
|
+
}
|
|
131
|
+
if (this._writer) {
|
|
132
|
+
this._notarizePendingEdgeCredentials(this._edgeClient, this._writer);
|
|
133
|
+
}
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
protected override async _close() {
|
|
135
|
-
|
|
136
|
-
clearInterval(this._activeEdgePollingIntervalHandle);
|
|
137
|
-
this._activeEdgePollingIntervalHandle = undefined;
|
|
138
|
-
}
|
|
138
|
+
this._stopPeriodicEdgePolling();
|
|
139
139
|
await this._ctx.dispose();
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -273,11 +273,26 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
273
273
|
setWriter(writer: FeedWriter<Credential>) {
|
|
274
274
|
invariant(!this._writer, 'Writer already set.');
|
|
275
275
|
this._writer = writer;
|
|
276
|
-
if (this._edgeClient) {
|
|
276
|
+
if (this._edgeClient && this.isOpen) {
|
|
277
277
|
this._notarizePendingEdgeCredentials(this._edgeClient, writer);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
+
private _startPeriodicEdgePolling(client: EdgeHttpClient) {
|
|
282
|
+
this._activeEdgePollingIntervalHandle = setInterval(() => {
|
|
283
|
+
if (this._writer) {
|
|
284
|
+
this._notarizePendingEdgeCredentials(client, this._writer);
|
|
285
|
+
}
|
|
286
|
+
}, this._activeEdgePollingInterval);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private _stopPeriodicEdgePolling() {
|
|
290
|
+
if (this._activeEdgePollingIntervalHandle) {
|
|
291
|
+
clearInterval(this._activeEdgePollingIntervalHandle);
|
|
292
|
+
this._activeEdgePollingIntervalHandle = undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
281
296
|
/**
|
|
282
297
|
* The method is used only for adding agent feeds to spaces.
|
|
283
298
|
* When an agent is created we can admit them into all the existing spaces. In case the operation fails
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { EventSubscriptions, UpdateScheduler, scheduleTask } from '@dxos/async';
|
|
6
|
-
import { Stream } from '@dxos/codec-protobuf';
|
|
6
|
+
import { Stream } from '@dxos/codec-protobuf/stream';
|
|
7
7
|
import { createAdmissionCredentials, type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
9
|
import { type SpaceManager } from '@dxos/echo-pipeline';
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "0.7.5-main.
|
|
1
|
+
export const DXOS_VERSION = "0.7.5-main.e9bb01b";
|