@dxos/react-client 2.17.3 → 2.18.2
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/.rush/temp/package-deps_build:test.json +5 -4
- package/dist/src/hooks/echo-queries/index.d.ts +1 -0
- package/dist/src/hooks/echo-queries/index.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/index.js +1 -0
- package/dist/src/hooks/echo-queries/index.js.map +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.d.ts +8 -0
- package/dist/src/hooks/echo-queries/useRemoteParties.d.ts.map +1 -0
- package/dist/src/hooks/echo-queries/useRemoteParties.js +24 -0
- package/dist/src/hooks/echo-queries/useRemoteParties.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/stories/halo-invitations.stories.d.ts.map +1 -1
- package/dist/stories/halo-invitations.stories.js +16 -15
- package/dist/stories/halo-invitations.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/react-client.build.log +5 -5
- package/src/hooks/echo-queries/index.ts +1 -0
- package/src/hooks/echo-queries/useRemoteParties.ts +25 -0
- package/src/index.ts +1 -0
- package/stories/halo-invitations.stories.tsx +26 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.2",
|
|
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.
|
|
18
|
-
"@dxos/client": "2.
|
|
19
|
-
"@dxos/config": "2.
|
|
20
|
-
"@dxos/credentials": "2.
|
|
21
|
-
"@dxos/crypto": "2.
|
|
22
|
-
"@dxos/debug": "2.
|
|
23
|
-
"@dxos/echo-db": "2.
|
|
24
|
-
"@dxos/util": "2.
|
|
17
|
+
"@dxos/async": "2.18.2",
|
|
18
|
+
"@dxos/client": "2.18.2",
|
|
19
|
+
"@dxos/config": "2.18.2",
|
|
20
|
+
"@dxos/credentials": "2.18.2",
|
|
21
|
+
"@dxos/crypto": "2.18.2",
|
|
22
|
+
"@dxos/debug": "2.18.2",
|
|
23
|
+
"@dxos/echo-db": "2.18.2",
|
|
24
|
+
"@dxos/util": "2.18.2",
|
|
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.
|
|
32
|
+
"@dxos/toolchain-node-library": "2.18.2",
|
|
33
33
|
"@mui/material": "^5.0.1",
|
|
34
34
|
"@testing-library/react": "^11.0.4",
|
|
35
35
|
"@testing-library/react-hooks": "5.1.2",
|
package/react-client.build.log
CHANGED
|
@@ -2,10 +2,10 @@ Invoking: toolchain build:test
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
typescript
|
|
5
|
-
OK in
|
|
5
|
+
OK in 5520 ms
|
|
6
6
|
|
|
7
7
|
eslint
|
|
8
|
-
OK in
|
|
8
|
+
OK in 6202 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 (
|
|
29
|
+
7 passing (329ms)
|
|
30
30
|
|
|
31
|
-
OK in
|
|
31
|
+
OK in 10276 ms
|
|
32
32
|
|
|
33
|
-
CHECK COMPLETE in
|
|
33
|
+
CHECK COMPLETE in 22004 ms
|
|
@@ -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
|
@@ -8,21 +8,18 @@ import {
|
|
|
8
8
|
Box, Button, Divider, Paper, TextField, Toolbar
|
|
9
9
|
} from '@mui/material';
|
|
10
10
|
|
|
11
|
-
import {
|
|
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 [
|
|
40
|
-
const [
|
|
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(
|
|
40
|
+
const invitation = await client.createHaloInvitation({
|
|
44
41
|
onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
42
|
+
setInvitation(undefined);
|
|
43
|
+
setPin('');
|
|
44
|
+
},
|
|
45
|
+
onPinGenerated: setPin
|
|
48
46
|
});
|
|
49
47
|
|
|
50
|
-
|
|
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
|
-
{
|
|
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<
|
|
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
|
-
//
|
|
107
|
+
// Claim an invitation for this device to join an existing Halo.
|
|
105
108
|
if (invitation.identityKey) {
|
|
106
|
-
await client.
|
|
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
|
-
|
|
118
|
+
const handleAuthenticate = async (pin: string) => {
|
|
119
|
+
await status.finishAuthentication?.(pin);
|
|
117
120
|
};
|
|
118
121
|
|
|
119
122
|
return (
|