@dxos/react-client 2.17.4 → 2.18.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.17.4",
3
+ "version": "2.18.3",
4
4
  "description": "React client API",
5
5
  "keywords": [],
6
6
  "license": "AGPL-3.0",
@@ -14,14 +14,14 @@
14
14
  "test": "toolchain test"
15
15
  },
16
16
  "dependencies": {
17
- "@dxos/async": "2.17.4",
18
- "@dxos/client": "2.17.4",
19
- "@dxos/config": "2.17.4",
20
- "@dxos/credentials": "2.17.4",
21
- "@dxos/crypto": "2.17.4",
22
- "@dxos/debug": "2.17.4",
23
- "@dxos/echo-db": "2.17.4",
24
- "@dxos/util": "2.17.4",
17
+ "@dxos/async": "2.18.3",
18
+ "@dxos/client": "2.18.3",
19
+ "@dxos/config": "2.18.3",
20
+ "@dxos/credentials": "2.18.3",
21
+ "@dxos/crypto": "2.18.3",
22
+ "@dxos/debug": "2.18.3",
23
+ "@dxos/echo-db": "2.18.3",
24
+ "@dxos/util": "2.18.3",
25
25
  "@types/debug": "^4.1.1",
26
26
  "assert": "^2.0.0",
27
27
  "debug": "^4.1.1",
@@ -29,7 +29,7 @@
29
29
  "use-subscription": "^1.4.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@dxos/toolchain-node-library": "2.10.10",
32
+ "@dxos/toolchain-node-library": "2.18.3",
33
33
  "@mui/material": "^5.0.1",
34
34
  "@testing-library/react": "^11.0.4",
35
35
  "@testing-library/react-hooks": "5.1.2",
@@ -2,10 +2,10 @@ Invoking: toolchain build:test
2
2
 
3
3
 
4
4
  typescript
5
- OK in 7556 ms
5
+ OK in 9552 ms
6
6
 
7
7
  eslint
8
- OK in 7986 ms
8
+ OK in 8241 ms
9
9
 
10
10
  mocha
11
11
  This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills
@@ -26,8 +26,8 @@ This browser doesn't support cancelAnimationFrame. Make sure that you load a pol
26
26
  ✓ should return custom client config when used properly in a context
27
27
 
28
28
 
29
- 7 passing (444ms)
29
+ 7 passing (386ms)
30
30
 
31
- OK in 11694 ms
31
+ OK in 10970 ms
32
32
 
33
- CHECK COMPLETE in 27246 ms
33
+ CHECK COMPLETE in 28770 ms
@@ -5,3 +5,4 @@
5
5
  export * from './useContacts';
6
6
  export * from './useMembers';
7
7
  export * from './useParties';
8
+ export * from './useRemoteParties';
@@ -0,0 +1,25 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ import { useEffect, useState } from 'react';
6
+
7
+ import { useClient } from '../client';
8
+
9
+ /**
10
+ * Get all Parties available to current user.
11
+ * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
12
+ */
13
+ export const useRemoteParties = () => {
14
+ const client = useClient();
15
+ const [parties, setParties] = useState<{key?: Uint8Array}[]>([]);
16
+
17
+ useEffect(() => {
18
+ const stream = client.services.PartyService.SubscribeParties();
19
+ stream.subscribe(result => setParties(result.parties ?? []), console.error);
20
+
21
+ return () => stream.close();
22
+ }, []);
23
+
24
+ return parties;
25
+ };
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@
5
5
  export * from './components';
6
6
  export * from './containers';
7
7
  export * from './hooks';
8
+ export * from './config';
@@ -8,21 +8,18 @@ import {
8
8
  Box, Button, Divider, Paper, TextField, Toolbar
9
9
  } from '@mui/material';
10
10
 
11
- import { encodeInvitation, decodeInvitation } from '@dxos/client';
11
+ import { Awaited } from '@dxos/async';
12
+ import { Client, decodeInvitation, PendingInvitation } from '@dxos/client';
12
13
 
13
14
  import {
14
15
  ClientInitializer,
15
16
  ProfileInitializer,
16
17
  useClient,
17
18
  useParties,
18
- useProfile,
19
- useSecretGenerator,
20
- useSecretProvider
19
+ useProfile
21
20
  } from '../src';
22
21
  import {
23
- ClientPanel,
24
- PartyJoinPanel,
25
- Container
22
+ ClientPanel, Container, PartyJoinPanel
26
23
  } from './helpers';
27
24
 
28
25
  export default {
@@ -36,18 +33,19 @@ export default {
36
33
  */
37
34
  const HaloInvitationContainer = () => {
38
35
  const client = useClient();
39
- const [invitationCode, setInvitationCode] = useState<string>();
40
- const [secretProvider, pin, resetPin] = useSecretGenerator();
36
+ const [invitation, setInvitation] = useState<PendingInvitation | undefined>();
37
+ const [pin, setPin] = useState('');
41
38
 
42
39
  const handleCreateInvitation = async () => {
43
- const invitation = await client.createHaloInvitation(secretProvider, {
40
+ const invitation = await client.createHaloInvitation({
44
41
  onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
45
- setInvitationCode(undefined);
46
- resetPin();
47
- }
42
+ setInvitation(undefined);
43
+ setPin('');
44
+ },
45
+ onPinGenerated: setPin
48
46
  });
49
47
 
50
- setInvitationCode(encodeInvitation(invitation));
48
+ setInvitation(invitation);
51
49
  };
52
50
 
53
51
  if (!client.halo.hasProfile()) {
@@ -64,13 +62,13 @@ const HaloInvitationContainer = () => {
64
62
  </Button>
65
63
  </Toolbar>
66
64
 
67
- {invitationCode && (
65
+ {invitation && (
68
66
  <Box sx={{ marginTop: 1 }}>
69
67
  <TextField
70
68
  disabled
71
69
  multiline
72
70
  fullWidth
73
- value={invitationCode}
71
+ value={invitation.invitationCode}
74
72
  maxRows={3}
75
73
  />
76
74
  </Box>
@@ -89,22 +87,27 @@ const HaloInvitationContainer = () => {
89
87
  );
90
88
  };
91
89
 
90
+ interface Status {
91
+ error?: any,
92
+ identity?: string,
93
+ finishAuthentication?: Awaited<ReturnType<Client['joinHaloInvitation']>>
94
+ }
95
+
92
96
  /**
93
97
  * Processes device invitations/authentication.
94
98
  */
95
99
  const HaloAuthenticationContainer = () => {
96
100
  const client = useClient();
97
- const [status, setStatus] = useState<any>({});
98
- const [secretProvider, secretResolver] = useSecretProvider<Buffer>();
101
+ const [status, setStatus] = useState<Status>({});
99
102
 
100
103
  const handleSubmit = async (invitationCode: string) => {
101
104
  try {
102
105
  const invitation = decodeInvitation(invitationCode);
103
106
 
104
- // Create an invitation for this device to join an existing Halo.
107
+ // Claim an invitation for this device to join an existing Halo.
105
108
  if (invitation.identityKey) {
106
- await client.echo.halo.join(invitation, secretProvider);
107
- setStatus({ identity: invitation.identityKey.toString() });
109
+ const finishAuthentication = await client.joinHaloInvitation(invitation);
110
+ setStatus({ identity: invitation.identityKey.toString(), finishAuthentication });
108
111
  }
109
112
  } catch (err: any) {
110
113
  // TODO(burdon): Doesn't support retry. Provide hint (eg, should retry/cancel).
@@ -112,8 +115,8 @@ const HaloAuthenticationContainer = () => {
112
115
  }
113
116
  };
114
117
 
115
- const handleAuthenticate = (pin: string) => {
116
- secretResolver(Buffer.from(pin));
118
+ const handleAuthenticate = async (pin: string) => {
119
+ await status.finishAuthentication?.(pin);
117
120
  };
118
121
 
119
122
  return (