@dxos/client-services 0.1.41 → 0.1.45-next.45667d4

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 (164) hide show
  1. package/dist/lib/browser/{chunk-T73F4MV4.mjs → chunk-IHSMRQ3L.mjs} +985 -867
  2. package/dist/lib/browser/chunk-IHSMRQ3L.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -3
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +121 -297
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +589 -469
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +688 -740
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/index.d.ts +1 -0
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/packlets/devices/devices-service.d.ts +1 -1
  15. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  16. package/dist/types/src/packlets/devtools/devtools.d.ts +4 -2
  17. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  18. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  19. package/dist/types/src/packlets/devtools/network.d.ts +5 -4
  20. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  21. package/dist/types/src/packlets/identity/authenticator.d.ts +1 -1
  22. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  23. package/dist/types/src/packlets/identity/identity-manager.d.ts +2 -4
  24. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  25. package/dist/types/src/packlets/identity/identity.d.ts +1 -1
  26. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  27. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +2 -3
  28. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -3
  30. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -2
  32. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  33. package/dist/types/src/packlets/network/network-service.d.ts +6 -4
  34. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
  36. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/index.d.ts +0 -1
  38. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  39. package/dist/types/src/packlets/services/local-client-services.d.ts +1 -1
  40. package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -1
  41. package/dist/types/src/packlets/services/service-context.d.ts +4 -2
  42. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  43. package/dist/types/src/packlets/services/service-host.d.ts +16 -9
  44. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  45. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +12 -7
  46. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  47. package/dist/types/src/packlets/spaces/data-space.d.ts +15 -10
  48. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  49. package/dist/types/src/packlets/spaces/genesis.d.ts +5 -0
  50. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -0
  51. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +4 -4
  52. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  53. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
  54. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  55. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  56. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  57. package/dist/types/src/packlets/testing/credential-utils.d.ts +1 -1
  58. package/dist/types/src/packlets/testing/index.d.ts +0 -1
  59. package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
  60. package/dist/types/src/packlets/testing/invitation-utils.d.ts +13 -7
  61. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  62. package/dist/types/src/packlets/testing/test-builder.d.ts +35 -32
  63. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  64. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +1 -1
  65. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  66. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts +5 -2
  67. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  68. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +1 -1
  69. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +1 -1
  70. package/dist/types/src/packlets/vault/worker-runtime.d.ts +1 -1
  71. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  72. package/dist/types/src/packlets/vault/worker-session.d.ts +4 -7
  73. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  74. package/package.json +30 -31
  75. package/src/index.ts +1 -0
  76. package/src/packlets/devices/devices-service.ts +5 -5
  77. package/src/packlets/devtools/devtools.ts +25 -4
  78. package/src/packlets/devtools/feeds.ts +10 -10
  79. package/src/packlets/devtools/keys.ts +6 -6
  80. package/src/packlets/devtools/network.ts +14 -13
  81. package/src/packlets/devtools/spaces.ts +4 -4
  82. package/src/packlets/identity/authenticator.test.ts +1 -1
  83. package/src/packlets/identity/authenticator.ts +2 -2
  84. package/src/packlets/identity/identity-manager.test.ts +17 -13
  85. package/src/packlets/identity/identity-manager.ts +21 -22
  86. package/src/packlets/identity/identity-service.ts +3 -3
  87. package/src/packlets/identity/identity.test.ts +65 -36
  88. package/src/packlets/identity/identity.ts +17 -17
  89. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  90. package/src/packlets/invitations/device-invitation-protocol.ts +7 -7
  91. package/src/packlets/invitations/invitation-extension.ts +16 -27
  92. package/src/packlets/invitations/invitations-handler.ts +17 -25
  93. package/src/packlets/invitations/invitations-service.ts +11 -11
  94. package/src/packlets/invitations/space-invitation-protocol.test.ts +9 -9
  95. package/src/packlets/invitations/space-invitation-protocol.ts +11 -12
  96. package/src/packlets/logging/logging-service.ts +8 -3
  97. package/src/packlets/network/network-service.test.ts +8 -8
  98. package/src/packlets/network/network-service.ts +20 -8
  99. package/src/packlets/services/client-rpc-server.ts +5 -5
  100. package/src/packlets/services/index.ts +0 -1
  101. package/src/packlets/services/local-client-services.ts +1 -1
  102. package/src/packlets/services/service-context.test.ts +3 -3
  103. package/src/packlets/services/service-context.ts +26 -24
  104. package/src/packlets/services/service-host.test.ts +6 -6
  105. package/src/packlets/services/service-host.ts +57 -31
  106. package/src/packlets/services/service-registry.test.ts +20 -38
  107. package/src/packlets/spaces/data-space-manager.test.ts +17 -29
  108. package/src/packlets/spaces/data-space-manager.ts +29 -35
  109. package/src/packlets/spaces/data-space.ts +73 -47
  110. package/src/packlets/spaces/genesis.ts +81 -0
  111. package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
  112. package/src/packlets/spaces/notarization-plugin.ts +12 -12
  113. package/src/packlets/spaces/spaces-service.test.ts +2 -2
  114. package/src/packlets/spaces/spaces-service.ts +21 -10
  115. package/src/packlets/storage/storage.ts +3 -3
  116. package/src/packlets/system/system-service.test.ts +1 -1
  117. package/src/packlets/system/system-service.ts +1 -1
  118. package/src/packlets/testing/credential-utils.ts +4 -4
  119. package/src/packlets/testing/index.ts +0 -1
  120. package/src/packlets/testing/invitation-utils.ts +28 -33
  121. package/src/packlets/testing/test-builder.ts +132 -168
  122. package/src/packlets/vault/iframe-host-runtime.ts +8 -11
  123. package/src/packlets/vault/iframe-proxy-runtime.ts +25 -9
  124. package/src/packlets/vault/shell-runtime.ts +4 -4
  125. package/src/packlets/vault/vault-resource-lock.ts +2 -2
  126. package/src/packlets/vault/worker-runtime.ts +7 -9
  127. package/src/packlets/vault/worker-session.ts +24 -45
  128. package/dist/lib/browser/chunk-T73F4MV4.mjs.map +0 -7
  129. package/dist/types/src/packlets/services/utils.d.ts +0 -7
  130. package/dist/types/src/packlets/services/utils.d.ts.map +0 -1
  131. package/dist/types/src/packlets/testing/host-test-builder.d.ts +0 -43
  132. package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +0 -1
  133. package/dist/types/src/packlets/tests/client-services.test.d.ts +0 -2
  134. package/dist/types/src/packlets/tests/client-services.test.d.ts.map +0 -1
  135. package/dist/types/src/packlets/tests/client.test.d.ts +0 -2
  136. package/dist/types/src/packlets/tests/client.test.d.ts.map +0 -1
  137. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts +0 -2
  138. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts.map +0 -1
  139. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts +0 -2
  140. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts.map +0 -1
  141. package/dist/types/src/packlets/tests/halo-profile.test.d.ts +0 -2
  142. package/dist/types/src/packlets/tests/halo-profile.test.d.ts.map +0 -1
  143. package/dist/types/src/packlets/tests/invitations.test.d.ts +0 -2
  144. package/dist/types/src/packlets/tests/invitations.test.d.ts.map +0 -1
  145. package/dist/types/src/packlets/tests/shared-worker.test.d.ts +0 -2
  146. package/dist/types/src/packlets/tests/shared-worker.test.d.ts.map +0 -1
  147. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts +0 -2
  148. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts.map +0 -1
  149. package/dist/types/src/packlets/tests/spaces.test.d.ts +0 -2
  150. package/dist/types/src/packlets/tests/spaces.test.d.ts.map +0 -1
  151. package/dist/types/src/packlets/tests/text.test.d.ts +0 -2
  152. package/dist/types/src/packlets/tests/text.test.d.ts.map +0 -1
  153. package/src/packlets/services/utils.ts +0 -53
  154. package/src/packlets/testing/host-test-builder.ts +0 -163
  155. package/src/packlets/tests/client-services.test.ts +0 -222
  156. package/src/packlets/tests/client.test.ts +0 -140
  157. package/src/packlets/tests/halo-credentials.test.ts +0 -94
  158. package/src/packlets/tests/halo-persistent.test.ts +0 -53
  159. package/src/packlets/tests/halo-profile.test.ts +0 -48
  160. package/src/packlets/tests/invitations.test.ts +0 -389
  161. package/src/packlets/tests/shared-worker.test.ts +0 -92
  162. package/src/packlets/tests/spaces-invitations.test.ts +0 -46
  163. package/src/packlets/tests/spaces.test.ts +0 -147
  164. package/src/packlets/tests/text.test.ts +0 -206
@@ -1,389 +0,0 @@
1
- //
2
- // Copyright 2021 DXOS.org
3
- //
4
-
5
- import chai, { expect } from 'chai';
6
- import chaiAsPromised from 'chai-as-promised';
7
- import assert from 'node:assert';
8
- import waitForExpect from 'wait-for-expect';
9
-
10
- import { asyncChain, asyncTimeout } from '@dxos/async';
11
- import { Client, InvitationsProxy, Space, SpaceProxy } from '@dxos/client';
12
- import { ConnectionState, Invitation } from '@dxos/protocols/proto/dxos/client/services';
13
- import { afterTest, describe, test } from '@dxos/test';
14
-
15
- import { InvitationsServiceImpl } from '../invitations';
16
- import { LocalClientServices, ServiceContext } from '../services';
17
- import { DataSpace } from '../spaces';
18
- import {
19
- createIdentity,
20
- createPeers,
21
- performInvitation,
22
- PerformInvitationParams,
23
- Result,
24
- TestBuilder
25
- } from '../testing';
26
-
27
- chai.use(chaiAsPromised);
28
-
29
- const closeAfterTest = async (peer: ServiceContext) => {
30
- afterTest(() => peer.close());
31
- return peer;
32
- };
33
-
34
- const successfulInvitation = async ({
35
- host,
36
- guest,
37
- hostResult: { invitation: hostInvitation, error: hostError },
38
- guestResult: { invitation: guestInvitation, error: guestError }
39
- }: {
40
- host: ServiceContext;
41
- guest: ServiceContext;
42
- hostResult: Result;
43
- guestResult: Result;
44
- }) => {
45
- expect(hostError).to.be.undefined;
46
- expect(guestError).to.be.undefined;
47
- expect(hostInvitation?.state).to.eq(Invitation.State.SUCCESS);
48
- expect(guestInvitation?.state).to.eq(Invitation.State.SUCCESS);
49
-
50
- switch (hostInvitation!.kind) {
51
- case Invitation.Kind.SPACE:
52
- expect(guestInvitation!.spaceKey).to.exist;
53
- expect(hostInvitation!.spaceKey).to.deep.eq(guestInvitation!.spaceKey);
54
- break;
55
-
56
- case Invitation.Kind.DEVICE:
57
- expect(hostInvitation!.identityKey).not.to.exist;
58
- expect(guestInvitation!.identityKey).to.deep.eq(host.identityManager.identity!.identityKey);
59
- expect(guestInvitation!.identityKey).to.deep.eq(guest.identityManager.identity!.identityKey);
60
-
61
- // Check devices.
62
- // TODO(burdon): Incorrect number of devices.
63
- await waitForExpect(() => {
64
- expect(host.identityManager.identity!.authorizedDeviceKeys.size).to.eq(2);
65
- expect(guest.identityManager.identity!.authorizedDeviceKeys.size).to.eq(2);
66
- });
67
- // console.log(host.identityManager.identity!.authorizedDeviceKeys.size);
68
- // console.log(guest.identityManager.identity!.authorizedDeviceKeys.size);
69
- break;
70
- }
71
- };
72
-
73
- const testSuite = (getParams: () => PerformInvitationParams, getPeers: () => [ServiceContext, ServiceContext]) => {
74
- test('no auth', async () => {
75
- const [host, guest] = getPeers();
76
- const [hostResult, guestResult] = await Promise.all(performInvitation(getParams()));
77
- await successfulInvitation({ host, guest, hostResult, guestResult });
78
- });
79
-
80
- test('with shared secret', async () => {
81
- const [host, guest] = getPeers();
82
- const params = getParams();
83
- const [hostResult, guestResult] = await Promise.all(
84
- performInvitation({
85
- ...params,
86
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET }
87
- })
88
- );
89
-
90
- await successfulInvitation({ host, guest, hostResult, guestResult });
91
- });
92
-
93
- test('invalid auth code', async () => {
94
- const [host, guest] = getPeers();
95
- const params = getParams();
96
- let attempt = 1;
97
- const [hostResult, guestResult] = await Promise.all(
98
- performInvitation({
99
- ...params,
100
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET },
101
- hooks: {
102
- guest: {
103
- onReady: (invitation) => {
104
- if (attempt === 0) {
105
- // Force retry.
106
- void invitation.authenticate('000000');
107
- attempt++;
108
- return true;
109
- }
110
-
111
- return false;
112
- }
113
- }
114
- }
115
- })
116
- );
117
-
118
- expect(attempt).to.eq(1);
119
- await successfulInvitation({ host, guest, hostResult, guestResult });
120
- });
121
-
122
- test('max auth code retries', async () => {
123
- const params = getParams();
124
- let attempt = 0;
125
- const [hostPromise, guestPromise] = performInvitation({
126
- ...params,
127
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET },
128
- hooks: {
129
- guest: {
130
- onReady: (invitation) => {
131
- // Force retry.
132
- void invitation.authenticate('000000');
133
- attempt++;
134
- return true;
135
- }
136
- }
137
- }
138
- });
139
- const guestResult = await guestPromise;
140
-
141
- expect(attempt).to.eq(3);
142
- expect(guestResult.error).to.exist;
143
- await expect(asyncTimeout(hostPromise, 100)).to.be.rejected;
144
- });
145
-
146
- test('invitation timeout', async () => {
147
- const params = getParams();
148
- const [hostResult, guestResult] = await Promise.all(
149
- performInvitation({
150
- ...params,
151
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET, timeout: 1 }
152
- })
153
- );
154
-
155
- expect(hostResult.invitation?.state).to.eq(Invitation.State.TIMEOUT);
156
- expect(guestResult.invitation?.state).to.eq(Invitation.State.TIMEOUT);
157
- });
158
-
159
- test('host cancels invitation', async () => {
160
- const params = getParams();
161
- const [hostResult, guestResult] = await Promise.all(
162
- performInvitation({
163
- ...params,
164
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET },
165
- hooks: {
166
- host: {
167
- onConnected: (invitation) => {
168
- void invitation.cancel();
169
- return true;
170
- }
171
- }
172
- }
173
- })
174
- );
175
-
176
- expect(hostResult.invitation?.state).to.eq(Invitation.State.CANCELLED);
177
- expect(guestResult.error).to.exist;
178
- });
179
-
180
- test('guest cancels invitation', async () => {
181
- const params = getParams();
182
- const [hostPromise, guestPromise] = performInvitation({
183
- ...params,
184
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET },
185
- hooks: {
186
- guest: {
187
- onConnected: (invitation) => {
188
- void invitation.cancel();
189
- return true;
190
- }
191
- }
192
- }
193
- });
194
- const guestResult = await guestPromise;
195
-
196
- expect(guestResult.invitation?.state).to.eq(Invitation.State.CANCELLED);
197
- await expect(asyncTimeout(hostPromise, 100)).to.be.rejected;
198
- });
199
-
200
- test('network error', async () => {
201
- const [, guest] = getPeers();
202
- const params = getParams();
203
- const [hostPromise, guestPromise] = performInvitation({
204
- ...params,
205
- options: { ...params.options, authMethod: Invitation.AuthMethod.SHARED_SECRET },
206
- hooks: {
207
- guest: {
208
- onConnected: () => {
209
- void guest.networkManager.setConnectionState(ConnectionState.OFFLINE);
210
- return true;
211
- }
212
- }
213
- }
214
- });
215
- const guestResult = await guestPromise;
216
-
217
- expect(guestResult.error).to.exist;
218
- await expect(asyncTimeout(hostPromise, 100)).to.be.rejected;
219
-
220
- // Test cleanup fails if the guest is offline.
221
- await guest.networkManager.setConnectionState(ConnectionState.ONLINE);
222
- });
223
- };
224
-
225
- describe('Invitations', () => {
226
- describe('ServiceContext', () => {
227
- describe('space', () => {
228
- let host: ServiceContext;
229
- let guest: ServiceContext;
230
- let space: DataSpace;
231
-
232
- beforeEach(async () => {
233
- const peers = await asyncChain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
234
- host = peers[0];
235
- guest = peers[1];
236
- space = await host.dataSpaceManager!.createSpace();
237
- });
238
-
239
- testSuite(
240
- () => ({
241
- host,
242
- guest,
243
- options: { kind: Invitation.Kind.SPACE, spaceKey: space.key }
244
- }),
245
- () => [host, guest]
246
- );
247
- });
248
-
249
- describe('device', () => {
250
- let host: ServiceContext;
251
- let guest: ServiceContext;
252
-
253
- beforeEach(async () => {
254
- const peers = await asyncChain<ServiceContext>([closeAfterTest])(createPeers(2));
255
- host = peers[0];
256
- guest = peers[1];
257
- await host.createIdentity();
258
- });
259
-
260
- testSuite(
261
- () => ({ host, guest, options: { kind: Invitation.Kind.DEVICE } }),
262
- () => [host, guest]
263
- );
264
- });
265
- });
266
-
267
- describe('InvitationsProxy', () => {
268
- describe('space', () => {
269
- let hostContext: ServiceContext;
270
- let guestContext: ServiceContext;
271
- let host: InvitationsProxy;
272
- let guest: InvitationsProxy;
273
- let space: DataSpace;
274
-
275
- beforeEach(async () => {
276
- const peers = await asyncChain<ServiceContext>([createIdentity, closeAfterTest])(createPeers(2));
277
- hostContext = peers[0];
278
- guestContext = peers[1];
279
- assert(hostContext.dataSpaceManager);
280
- assert(guestContext.dataSpaceManager);
281
-
282
- const hostService = new InvitationsServiceImpl(hostContext.invitations, (invitation) =>
283
- hostContext.getInvitationHandler(invitation)
284
- );
285
- const guestService = new InvitationsServiceImpl(guestContext.invitations, (invitation) =>
286
- guestContext.getInvitationHandler(invitation)
287
- );
288
-
289
- space = await hostContext.dataSpaceManager.createSpace();
290
- host = new InvitationsProxy(hostService, () => ({ kind: Invitation.Kind.SPACE, spaceKey: space.key }));
291
- guest = new InvitationsProxy(guestService, () => ({ kind: Invitation.Kind.SPACE }));
292
-
293
- afterTest(() => space.close());
294
- });
295
-
296
- testSuite(
297
- () => ({ host, guest }),
298
- () => [hostContext, guestContext]
299
- );
300
- });
301
-
302
- describe('device', () => {
303
- let hostContext: ServiceContext;
304
- let guestContext: ServiceContext;
305
- let host: InvitationsProxy;
306
- let guest: InvitationsProxy;
307
-
308
- beforeEach(async () => {
309
- const peers = await asyncChain<ServiceContext>([closeAfterTest])(createPeers(2));
310
- hostContext = peers[0];
311
- guestContext = peers[1];
312
-
313
- await hostContext.identityManager.createIdentity();
314
-
315
- const hostService = new InvitationsServiceImpl(hostContext.invitations, (invitation) =>
316
- hostContext.getInvitationHandler(invitation)
317
- );
318
-
319
- const guestService = new InvitationsServiceImpl(guestContext.invitations, (invitation) =>
320
- guestContext.getInvitationHandler(invitation)
321
- );
322
-
323
- host = new InvitationsProxy(hostService, () => ({ kind: Invitation.Kind.DEVICE }));
324
- guest = new InvitationsProxy(guestService, () => ({ kind: Invitation.Kind.DEVICE }));
325
- });
326
-
327
- testSuite(
328
- () => ({ host, guest }),
329
- () => [hostContext, guestContext]
330
- );
331
- });
332
- });
333
-
334
- describe('HaloProxy', () => {
335
- let host: Client;
336
- let guest: Client;
337
-
338
- beforeEach(async () => {
339
- const testBuilder = new TestBuilder();
340
-
341
- host = new Client({ services: testBuilder.createLocal() });
342
- guest = new Client({ services: testBuilder.createLocal() });
343
- await host.initialize();
344
- await guest.initialize();
345
-
346
- await host.halo.createIdentity({ displayName: 'Peer' });
347
-
348
- afterTest(() => Promise.all([host.destroy()]));
349
- afterTest(() => Promise.all([guest.destroy()]));
350
- });
351
-
352
- testSuite(
353
- () => ({ host: host.halo, guest: guest.halo }),
354
- () => [
355
- (host.services as LocalClientServices).host._serviceContext,
356
- (guest.services as LocalClientServices).host._serviceContext
357
- ]
358
- );
359
- });
360
-
361
- describe('EchoProxy', () => {
362
- let host: Client;
363
- let guest: Client;
364
- let space: Space;
365
- beforeEach(async () => {
366
- const testBuilder = new TestBuilder();
367
-
368
- host = new Client({ services: testBuilder.createLocal() });
369
- guest = new Client({ services: testBuilder.createLocal() });
370
- await host.initialize();
371
- await guest.initialize();
372
- await host.halo.createIdentity({ displayName: 'Peer 1' });
373
- await guest.halo.createIdentity({ displayName: 'Peer 2' });
374
-
375
- afterTest(() => Promise.all([host.destroy()]));
376
- afterTest(() => Promise.all([guest.destroy()]));
377
-
378
- space = await host.createSpace();
379
- });
380
-
381
- testSuite(
382
- () => ({ host: space as SpaceProxy, guest }),
383
- () => [
384
- (host.services as LocalClientServices).host._serviceContext,
385
- (guest.services as LocalClientServices).host._serviceContext
386
- ]
387
- );
388
- });
389
- });
@@ -1,92 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import chai, { expect } from 'chai';
6
- import chaiAsPromised from 'chai-as-promised';
7
-
8
- import { sleep } from '@dxos/async';
9
- import { Client, ClientServicesProxy, fromIFrame } from '@dxos/client';
10
- import { Config } from '@dxos/config';
11
- import { createLinkedPorts } from '@dxos/rpc';
12
- import { describe, test, afterTest } from '@dxos/test';
13
- import { MaybePromise, Provider } from '@dxos/util';
14
-
15
- import { TestBuilder } from '../testing';
16
- import { IFrameProxyRuntime, WorkerRuntime } from '../vault';
17
-
18
- chai.use(chaiAsPromised);
19
-
20
- const setup = (getConfig: Provider<MaybePromise<Config>>) => {
21
- const workerRuntime = new WorkerRuntime(getConfig);
22
-
23
- const systemPorts = createLinkedPorts();
24
- const appPorts = createLinkedPorts();
25
- const shellPorts = createLinkedPorts();
26
- void workerRuntime.createSession({
27
- systemPort: systemPorts[1],
28
- appPort: appPorts[1],
29
- shellPort: shellPorts[1]
30
- });
31
- const clientProxy = new IFrameProxyRuntime({
32
- config: getConfig,
33
- systemPort: systemPorts[0],
34
- shellPort: shellPorts[0]
35
- });
36
- const client = new Client({
37
- services: new ClientServicesProxy(appPorts[0])
38
- });
39
-
40
- return { workerRuntime, clientProxy, client };
41
- };
42
-
43
- describe('Shared worker', () => {
44
- test('client connects to the worker', async () => {
45
- const { workerRuntime, clientProxy, client } = setup(() => new Config({}));
46
-
47
- await Promise.all([workerRuntime.start(), clientProxy.open('*'), client.initialize()]);
48
-
49
- await client.halo.createIdentity();
50
- });
51
-
52
- test('initialization errors get propagated to the client', async () => {
53
- const { workerRuntime, clientProxy, client } = setup(async () => {
54
- await sleep(1);
55
- throw new Error('Test error');
56
- });
57
-
58
- const promise = Promise.all([
59
- // This error should be propagated to client.initialize() call.
60
- workerRuntime.start().catch(() => {}),
61
- clientProxy.open('*').catch(() => {})
62
- ]);
63
-
64
- await expect(client.initialize()).to.be.rejectedWith('Test error');
65
-
66
- await promise;
67
- });
68
-
69
- test('host can be initialized after client', async () => {
70
- const { workerRuntime, clientProxy, client } = setup(async () => {
71
- await sleep(5);
72
- return new Config({});
73
- });
74
-
75
- await Promise.all([workerRuntime.start(), clientProxy.open('*'), client.initialize()]);
76
-
77
- await client.halo.createIdentity();
78
- });
79
-
80
- // TODO(burdon): Browser-only.
81
- test.skip('creates client with remote iframe', async () => {
82
- const testBuilder = new TestBuilder();
83
-
84
- const client = new Client({
85
- services: fromIFrame(testBuilder.config)
86
- });
87
-
88
- await client.initialize();
89
- afterTest(() => client.destroy());
90
- expect(client.initialized).to.be.true;
91
- });
92
- });
@@ -1,46 +0,0 @@
1
- //
2
- // Copyright 2021 DXOS.org
3
- //
4
-
5
- import { expect } from 'chai';
6
-
7
- import { Client, Invitation, SpaceProxy } from '@dxos/client';
8
- import { log } from '@dxos/log';
9
- import { afterTest, describe, test } from '@dxos/test';
10
-
11
- import { performInvitation, TestBuilder, testSpace } from '../testing';
12
-
13
- describe('Spaces/invitations', () => {
14
- test('creates a space and invites a peer', async () => {
15
- const testBuilder = new TestBuilder();
16
-
17
- const client1 = new Client({ services: testBuilder.createLocal() });
18
- const client2 = new Client({ services: testBuilder.createLocal() });
19
- await client1.initialize();
20
- await client2.initialize();
21
- await client1.halo.createIdentity({ displayName: 'Peer 1' });
22
- await client2.halo.createIdentity({ displayName: 'Peer 2' });
23
-
24
- log('initialized');
25
-
26
- afterTest(() => Promise.all([client1.destroy()]));
27
- afterTest(() => Promise.all([client2.destroy()]));
28
-
29
- const space1 = await client1.createSpace();
30
- log('createSpace', { key: space1.key });
31
- const [{ invitation: hostInvitation }, { invitation: guestInvitation }] = await Promise.all(
32
- performInvitation({
33
- host: space1 as SpaceProxy,
34
- guest: client2
35
- })
36
- );
37
- expect(guestInvitation?.spaceKey).to.deep.eq(space1.key);
38
- expect(hostInvitation?.spaceKey).to.deep.eq(guestInvitation?.spaceKey);
39
- expect(hostInvitation?.state).to.eq(Invitation.State.SUCCESS);
40
-
41
- {
42
- const space = await client2.getSpace(guestInvitation!.spaceKey!)!.waitUntilReady();
43
- await testSpace(space.internal.db);
44
- }
45
- });
46
- });
@@ -1,147 +0,0 @@
1
- //
2
- // Copyright 2021 DXOS.org
3
- //
4
-
5
- import { expect } from 'chai';
6
-
7
- import { asyncTimeout, Trigger } from '@dxos/async';
8
- import { Client, Space, SpaceProxy } from '@dxos/client';
9
- import { Config } from '@dxos/config';
10
- import { log } from '@dxos/log';
11
- import { createStorage, StorageType } from '@dxos/random-access-storage';
12
- import { describe, test, afterTest } from '@dxos/test';
13
-
14
- import { performInvitation, TestBuilder, testSpace } from '../testing';
15
-
16
- describe('Spaces', () => {
17
- test('creates a space', async () => {
18
- const testBuilder = new TestBuilder();
19
- testBuilder.storage = createStorage({ type: StorageType.RAM });
20
-
21
- const client = new Client({ services: testBuilder.createLocal() });
22
- await client.initialize();
23
- afterTest(() => client.destroy());
24
-
25
- await client.halo.createIdentity({ displayName: 'test-user' });
26
-
27
- // TODO(burdon): Extend basic queries.
28
- const space = await client.createSpace();
29
- await testSpace(space.internal.db);
30
-
31
- expect(space.members.get()).to.be.length(1);
32
- });
33
-
34
- // TODO(dmaretskyi): Test suit for different conditions/storages.
35
- test.skip('creates a space on webfs', async () => {
36
- const testBuilder = new TestBuilder();
37
- // testBuilder.storage = createStorage({ type: StorageType.WEBFS });
38
-
39
- const host = testBuilder.createClientServicesHost();
40
- await host.open();
41
- afterTest(() => host.close());
42
- const [client, server] = testBuilder.createClientServer(host);
43
- void server.open();
44
- afterTest(() => server.close());
45
- await client.initialize();
46
- afterTest(() => client.destroy());
47
-
48
- await client.halo.createIdentity({ displayName: 'test-user' });
49
-
50
- // TODO(burdon): Extend basic queries.
51
- const space = await client.createSpace();
52
- await testSpace(space.internal.db);
53
-
54
- expect(space.members.get()).to.be.length(1);
55
- });
56
-
57
- test('creates a space re-opens the client', async () => {
58
- const testBuilder = new TestBuilder(new Config({ version: 1 }));
59
- testBuilder.storage = createStorage({ type: StorageType.RAM });
60
-
61
- const client = new Client({ services: testBuilder.createLocal() });
62
- await client.initialize();
63
- await client.halo.createIdentity({ displayName: 'test-user' });
64
-
65
- let itemId: string;
66
- {
67
- // TODO(burdon): API (client.echo/client.halo).
68
- const space = await client.createSpace();
69
- const {
70
- objectsUpdated: [item]
71
- } = await testSpace(space.internal.db);
72
- itemId = item.id;
73
- expect(space.members.get()).to.be.length(1);
74
- }
75
-
76
- await client.destroy();
77
-
78
- log.break();
79
-
80
- await client.initialize();
81
-
82
- {
83
- // TODO(dmaretskyi): Replace with helper?.
84
- const spaceTrigger = new Trigger<Space>();
85
- if (client.spaces.get()[0]) {
86
- spaceTrigger.wake(client.spaces.get()[0]);
87
- }
88
- client.spaces.subscribe(() => {
89
- if (client.spaces.get()[0]) {
90
- spaceTrigger.wake(client.spaces.get()[0]);
91
- }
92
- });
93
- const space = await spaceTrigger.wait({ timeout: 500 });
94
- await space.waitUntilReady();
95
-
96
- const item = space.internal.db._itemManager.getItem(itemId)!;
97
- expect(item).to.exist;
98
- }
99
-
100
- await client.destroy();
101
- });
102
-
103
- test('post and listen to messages', async () => {
104
- const testBuilder = new TestBuilder();
105
-
106
- const client1 = new Client({ services: testBuilder.createLocal() });
107
- const client2 = new Client({ services: testBuilder.createLocal() });
108
- await client1.initialize();
109
- await client2.initialize();
110
- await client1.halo.createIdentity({ displayName: 'Peer 1' });
111
- await client2.halo.createIdentity({ displayName: 'Peer 2' });
112
-
113
- log('initialized');
114
-
115
- afterTest(() => Promise.all([client1.destroy()]));
116
- afterTest(() => Promise.all([client2.destroy()]));
117
-
118
- const space1 = await client1.createSpace();
119
- log('createSpace', { key: space1.key });
120
- const [, { invitation: guestInvitation }] = await Promise.all(
121
- performInvitation({ host: space1 as SpaceProxy, guest: client2 })
122
- );
123
- const space2 = await client2.getSpace(guestInvitation!.spaceKey!)!.waitUntilReady();
124
-
125
- const hello = new Trigger();
126
- {
127
- space2.listen('hello', (message) => {
128
- expect(message.channelId).to.include('hello');
129
- expect(message.payload).to.deep.contain({ data: 'Hello, world!' });
130
- hello.wake();
131
- });
132
- await space1.postMessage('hello', { data: 'Hello, world!' });
133
- }
134
-
135
- const goodbye = new Trigger();
136
- {
137
- space2.listen('goodbye', (message) => {
138
- expect(message.channelId).to.include('goodbye');
139
- expect(message.payload).to.deep.contain({ data: 'Goodbye' });
140
- goodbye.wake();
141
- });
142
- await space1.postMessage('goodbye', { data: 'Goodbye' });
143
- }
144
-
145
- await asyncTimeout(Promise.all([hello.wait(), goodbye.wait()]), 200);
146
- });
147
- });