@dxos/client-services 0.5.9-main.eacfffa → 0.5.9-main.f099efe

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.
Files changed (35) hide show
  1. package/dist/lib/browser/{chunk-J4DDMC6A.mjs → chunk-H3XJK6ZN.mjs} +483 -187
  2. package/dist/lib/browser/{chunk-J4DDMC6A.mjs.map → chunk-H3XJK6ZN.mjs.map} +4 -4
  3. package/dist/lib/browser/index.mjs +9 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-6HFQ2SQ5.cjs → chunk-JRDM7NQS.cjs} +502 -206
  8. package/dist/lib/node/chunk-JRDM7NQS.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +49 -41
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
  14. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
  15. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  16. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +10 -1
  18. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/spaces-service.d.ts +4 -1
  20. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  22. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  23. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  24. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  25. package/dist/types/src/version.d.ts +1 -1
  26. package/package.json +36 -36
  27. package/src/packlets/identity/contacts-service.ts +85 -0
  28. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  29. package/src/packlets/services/service-host.ts +12 -4
  30. package/src/packlets/spaces/data-space-manager.ts +55 -2
  31. package/src/packlets/spaces/spaces-service.ts +38 -0
  32. package/src/packlets/storage/index.ts +1 -0
  33. package/src/packlets/storage/profile-archive.ts +97 -0
  34. package/src/version.ts +1 -1
  35. package/dist/lib/node/chunk-6HFQ2SQ5.cjs.map +0 -7
@@ -30,6 +30,10 @@ import {
30
30
  type UpdateSpaceRequest,
31
31
  type WriteCredentialsRequest,
32
32
  type UpdateMemberRoleRequest,
33
+ type AdmitContactRequest,
34
+ type ContactAdmission,
35
+ type JoinSpaceResponse,
36
+ type JoinBySpaceKeyRequest,
33
37
  type CreateEpochResponse,
34
38
  } from '@dxos/protocols/proto/dxos/client/services';
35
39
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
@@ -226,6 +230,40 @@ export class SpacesServiceImpl implements SpacesService {
226
230
  return { epochCredential: credential ?? undefined };
227
231
  }
228
232
 
233
+ async admitContact(request: AdmitContactRequest): Promise<void> {
234
+ const dataSpaceManager = await this._getDataSpaceManager();
235
+ await dataSpaceManager.admitMember({
236
+ spaceKey: request.spaceKey,
237
+ identityKey: request.contact.identityKey,
238
+ role: request.role,
239
+ });
240
+ }
241
+
242
+ async joinBySpaceKey({ spaceKey }: JoinBySpaceKeyRequest): Promise<JoinSpaceResponse> {
243
+ const dataSpaceManager = await this._getDataSpaceManager();
244
+ const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
245
+ return this._joinByAdmission({ credential });
246
+ }
247
+
248
+ private async _joinByAdmission({ credential }: ContactAdmission): Promise<JoinSpaceResponse> {
249
+ const assertion = getCredentialAssertion(credential);
250
+ invariant(assertion['@type'] === 'dxos.halo.credentials.SpaceMember', 'Invalid credential');
251
+ const myIdentity = this._identityManager.identity;
252
+ invariant(myIdentity && credential.subject.id.equals(myIdentity.identityKey));
253
+
254
+ const dataSpaceManager = await this._getDataSpaceManager();
255
+ let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
256
+ if (!dataSpace) {
257
+ dataSpace = await dataSpaceManager.acceptSpace({
258
+ spaceKey: assertion.spaceKey,
259
+ genesisFeedKey: assertion.genesisFeedKey,
260
+ });
261
+ await myIdentity.controlPipeline.writer.write({ credential: { credential } });
262
+ }
263
+
264
+ return { space: this._serializeSpace(dataSpace) };
265
+ }
266
+
229
267
  private _serializeSpace(space: DataSpace): Space {
230
268
  return {
231
269
  id: space.id,
@@ -4,3 +4,4 @@
4
4
 
5
5
  export * from './storage';
6
6
  export * from './level';
7
+ export * from './profile-archive';
@@ -0,0 +1,97 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { cbor } from '@dxos/automerge/automerge-repo';
6
+ import { invariant } from '@dxos/invariant';
7
+ import type { LevelDB } from '@dxos/kv-store';
8
+ import { log } from '@dxos/log';
9
+ import { ProfileArchiveEntryType, type ProfileArchive } from '@dxos/protocols';
10
+ import type { Storage } from '@dxos/random-access-storage';
11
+ import { arrayToBuffer } from '@dxos/util';
12
+
13
+ export const encodeProfileArchive = (profile: ProfileArchive): Uint8Array => cbor.encode(profile);
14
+
15
+ export const decodeProfileArchive = (data: Uint8Array): ProfileArchive => cbor.decode(data);
16
+
17
+ export const exportProfileData = async ({
18
+ storage,
19
+ level,
20
+ }: {
21
+ storage: Storage;
22
+ level: LevelDB;
23
+ }): Promise<ProfileArchive> => {
24
+ const archive: ProfileArchive = { storage: [], meta: { timestamp: new Date().toISOString() } };
25
+
26
+ {
27
+ const directory = await storage.createDirectory();
28
+ const files = await directory.list();
29
+
30
+ log.info('begin exporting files', { count: files.length });
31
+ for (const filename of files) {
32
+ const file = await directory.getOrCreateFile(filename);
33
+ const { size } = await file.stat();
34
+ const data = await file.read(0, size);
35
+ archive.storage.push({
36
+ type: ProfileArchiveEntryType.FILE,
37
+ key: filename,
38
+ value: data,
39
+ });
40
+ }
41
+ log.info('done exporting files', { count: files.length });
42
+ }
43
+
44
+ {
45
+ log.info('begin exporting kv pairs');
46
+ const iter = await level.iterator<Uint8Array, Uint8Array>({ keyEncoding: 'binary', valueEncoding: 'binary' });
47
+ let count = 0;
48
+ for await (const [key, value] of iter) {
49
+ archive.storage.push({
50
+ type: ProfileArchiveEntryType.KEY_VALUE,
51
+ key,
52
+ value,
53
+ });
54
+ count++;
55
+ }
56
+ log.info('done exporting kv pairs', { count });
57
+ }
58
+
59
+ return archive;
60
+ };
61
+
62
+ export const importProfileData = async (
63
+ {
64
+ storage,
65
+ level,
66
+ }: {
67
+ storage: Storage;
68
+ level: LevelDB;
69
+ },
70
+ archive: ProfileArchive,
71
+ ): Promise<void> => {
72
+ const batch = level.batch();
73
+
74
+ for (const entry of archive.storage) {
75
+ switch (entry.type) {
76
+ case ProfileArchiveEntryType.FILE: {
77
+ const directory = await storage.createDirectory();
78
+ invariant(typeof entry.key === 'string', 'Invalid key type');
79
+ const file = await directory.getOrCreateFile(entry.key);
80
+ invariant(entry.value instanceof Uint8Array, 'Invalid value type');
81
+ await file.write(0, arrayToBuffer(entry.value));
82
+ await file.close();
83
+ break;
84
+ }
85
+ case ProfileArchiveEntryType.KEY_VALUE: {
86
+ invariant(entry.key instanceof Uint8Array, 'Invalid key type');
87
+ invariant(entry.value instanceof Uint8Array, 'Invalid value type');
88
+ batch.put(entry.key, entry.value, { keyEncoding: 'binary', valueEncoding: 'binary' });
89
+ break;
90
+ }
91
+ default:
92
+ throw new Error(`Invalid entry type: ${entry.type}`);
93
+ }
94
+ }
95
+
96
+ await batch.write();
97
+ };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.5.9-main.eacfffa";
1
+ export const DXOS_VERSION = "0.5.9-main.f099efe";