@dxos/react-client 2.21.2-dev.d6874be7 → 2.22.0
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.json +8 -6
- package/.rush/temp/package-deps_build:test.json +8 -6
- package/dist/src/hooks/invitations/index.d.ts +1 -0
- package/dist/src/hooks/invitations/index.d.ts.map +1 -1
- package/dist/src/hooks/invitations/index.js +1 -0
- package/dist/src/hooks/invitations/index.js.map +1 -1
- package/dist/src/hooks/invitations/useHaloInvitations.d.ts +3 -0
- package/dist/src/hooks/invitations/useHaloInvitations.d.ts.map +1 -0
- package/dist/src/hooks/invitations/useHaloInvitations.js +12 -0
- package/dist/src/hooks/invitations/useHaloInvitations.js.map +1 -0
- package/dist/src/hooks/invitations/useInvitations.d.ts +3 -0
- package/dist/src/hooks/invitations/useInvitations.d.ts.map +1 -0
- package/dist/src/hooks/invitations/useInvitations.js +21 -0
- package/dist/src/hooks/invitations/useInvitations.js.map +1 -0
- package/dist/src/hooks/invitations/usePartyInvitations.d.ts +1 -2
- package/dist/src/hooks/invitations/usePartyInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/usePartyInvitations.js +2 -12
- package/dist/src/hooks/invitations/usePartyInvitations.js.map +1 -1
- package/dist/src/hooks/invitations/useSecretProvider.d.ts +5 -1
- package/dist/src/hooks/invitations/useSecretProvider.d.ts.map +1 -1
- package/dist/src/hooks/invitations/useSecretProvider.js +3 -2
- package/dist/src/hooks/invitations/useSecretProvider.js.map +1 -1
- package/dist/stories/halo-invitations.stories.d.ts.map +1 -1
- package/dist/stories/halo-invitations.stories.js +18 -17
- package/dist/stories/halo-invitations.stories.js.map +1 -1
- package/dist/stories/party-invitations.stories.d.ts.map +1 -1
- package/dist/stories/party-invitations.stories.js +6 -18
- package/dist/stories/party-invitations.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/react-client.build.log +6 -6
- package/src/hooks/invitations/index.ts +1 -0
- package/src/hooks/invitations/useHaloInvitations.ts +11 -0
- package/src/hooks/invitations/useInvitations.ts +21 -0
- package/src/hooks/invitations/usePartyInvitations.ts +2 -16
- package/src/hooks/invitations/useSecretProvider.ts +9 -3
- package/stories/halo-invitations.stories.tsx +21 -21
- package/stories/party-invitations.stories.tsx +11 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -8,24 +8,24 @@
|
|
|
8
8
|
"main": "dist/src/index.js",
|
|
9
9
|
"types": "dist/src/index.d.ts",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@dxos/async": "2.
|
|
12
|
-
"@dxos/bot-factory-client": "2.
|
|
13
|
-
"@dxos/client": "2.
|
|
14
|
-
"@dxos/config": "2.
|
|
15
|
-
"@dxos/credentials": "2.
|
|
16
|
-
"@dxos/crypto": "2.
|
|
17
|
-
"@dxos/debug": "2.
|
|
18
|
-
"@dxos/echo-db": "2.
|
|
19
|
-
"@dxos/util": "2.
|
|
11
|
+
"@dxos/async": "2.22.0",
|
|
12
|
+
"@dxos/bot-factory-client": "2.22.0",
|
|
13
|
+
"@dxos/client": "2.22.0",
|
|
14
|
+
"@dxos/config": "2.22.0",
|
|
15
|
+
"@dxos/credentials": "2.22.0",
|
|
16
|
+
"@dxos/crypto": "2.22.0",
|
|
17
|
+
"@dxos/debug": "2.22.0",
|
|
18
|
+
"@dxos/echo-db": "2.22.0",
|
|
19
|
+
"@dxos/util": "2.22.0",
|
|
20
20
|
"assert": "^2.0.0",
|
|
21
21
|
"debug": "^4.3.3",
|
|
22
22
|
"react-display-name": "^0.2.5",
|
|
23
23
|
"use-subscription": "^1.4.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@dxos/esbuild-plugins": "2.
|
|
26
|
+
"@dxos/esbuild-plugins": "2.22.0",
|
|
27
27
|
"@dxos/esbuild-server": "~1.7.4",
|
|
28
|
-
"@dxos/toolchain-node-library": "2.
|
|
28
|
+
"@dxos/toolchain-node-library": "2.22.0",
|
|
29
29
|
"@mui/material": "^5.0.1",
|
|
30
30
|
"@testing-library/react": "^11.0.4",
|
|
31
31
|
"@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 8243 ms
|
|
6
6
|
|
|
7
7
|
eslint
|
|
8
|
-
OK in
|
|
8
|
+
OK in 7364 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
|
|
@@ -13,7 +13,7 @@ This browser doesn't support cancelAnimationFrame. Make sure that you load a pol
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
ClientProvider
|
|
16
|
-
✓ Renders with children
|
|
16
|
+
✓ Renders with children
|
|
17
17
|
✓ Provides the client
|
|
18
18
|
|
|
19
19
|
Client hook
|
|
@@ -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 (275ms)
|
|
30
30
|
|
|
31
|
-
OK in
|
|
31
|
+
OK in 2953 ms
|
|
32
32
|
|
|
33
|
-
CHECK COMPLETE in
|
|
33
|
+
CHECK COMPLETE in 18583 ms
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { InvitationProxy, InvitationRequest } from '@dxos/client';
|
|
8
|
+
|
|
9
|
+
export const useInvitations = (invitationProxy: InvitationProxy | undefined) => {
|
|
10
|
+
const [invitations, setInvitations] = useState<InvitationRequest[]>(invitationProxy?.activeInvitations ?? []);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setInvitations(invitationProxy?.activeInvitations ?? []);
|
|
14
|
+
|
|
15
|
+
return invitationProxy?.invitationsUpdate.on(() => {
|
|
16
|
+
setInvitations([...invitationProxy.activeInvitations]);
|
|
17
|
+
});
|
|
18
|
+
}, [invitationProxy]);
|
|
19
|
+
|
|
20
|
+
return invitations;
|
|
21
|
+
};
|
|
@@ -2,26 +2,12 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useEffect, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { InvitationRequest } from '@dxos/client';
|
|
8
5
|
import { PublicKey } from '@dxos/crypto';
|
|
9
6
|
|
|
10
7
|
import { useParty } from '../echo-queries';
|
|
8
|
+
import { useInvitations } from './useInvitations';
|
|
11
9
|
|
|
12
10
|
export const usePartyInvitations = (partyKey?: PublicKey) => {
|
|
13
11
|
const party = useParty(partyKey);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
return party?.invitationsUpdate.on(() => {
|
|
18
|
-
setInvitations([...party.activeInvitations]);
|
|
19
|
-
});
|
|
20
|
-
}, [party]);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
setInvitations([]);
|
|
24
|
-
}, [party?.key.toHex()]);
|
|
25
|
-
|
|
26
|
-
return invitations;
|
|
12
|
+
return useInvitations(party);
|
|
27
13
|
};
|
|
@@ -6,8 +6,14 @@ import { useState } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { trigger } from '@dxos/async';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type Provider<T> = () => Promise<T>;
|
|
10
|
+
type Resolver<T> = (value: T) => void;
|
|
11
|
+
type Reset = () => void;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
export const useSecretProvider = <T> (): [Provider<T>, Resolver<T>, Reset] => {
|
|
14
|
+
const [[provider, resolver], setState] = useState(() => trigger<T>());
|
|
15
|
+
|
|
16
|
+
const reset = () => setState(() => trigger<T>());
|
|
17
|
+
|
|
18
|
+
return [provider, resolver, reset];
|
|
13
19
|
};
|
|
@@ -8,8 +8,7 @@ import {
|
|
|
8
8
|
Box, Button, Divider, Paper, TextField, Toolbar
|
|
9
9
|
} from '@mui/material';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import { Client, decodeInvitation, PendingInvitation } from '@dxos/client';
|
|
11
|
+
import { decodeInvitation, encodeInvitation, Invitation } from '@dxos/client';
|
|
13
12
|
|
|
14
13
|
import {
|
|
15
14
|
ClientProvider,
|
|
@@ -33,19 +32,24 @@ export default {
|
|
|
33
32
|
*/
|
|
34
33
|
const HaloInvitationContainer = () => {
|
|
35
34
|
const client = useClient();
|
|
36
|
-
const [
|
|
35
|
+
const [invitationCode, setInvitationCode] = useState<string>();
|
|
37
36
|
const [pin, setPin] = useState('');
|
|
38
37
|
|
|
38
|
+
const resetInvitations = () => {
|
|
39
|
+
setInvitationCode('');
|
|
40
|
+
setPin('');
|
|
41
|
+
};
|
|
42
|
+
|
|
39
43
|
const handleCreateInvitation = async () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
resetInvitations();
|
|
45
|
+
|
|
46
|
+
const invitation = await client.halo.createInvitation();
|
|
47
|
+
invitation.finished.on(() => resetInvitations());
|
|
48
|
+
invitation.connected.on(() => {
|
|
49
|
+
setPin(invitation.secret.toString());
|
|
46
50
|
});
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
setInvitationCode(encodeInvitation(invitation.descriptor));
|
|
49
53
|
};
|
|
50
54
|
|
|
51
55
|
if (!client.halo.hasProfile()) {
|
|
@@ -62,13 +66,13 @@ const HaloInvitationContainer = () => {
|
|
|
62
66
|
</Button>
|
|
63
67
|
</Toolbar>
|
|
64
68
|
|
|
65
|
-
{
|
|
69
|
+
{invitationCode && (
|
|
66
70
|
<Box sx={{ marginTop: 1 }}>
|
|
67
71
|
<TextField
|
|
68
72
|
disabled
|
|
69
73
|
multiline
|
|
70
74
|
fullWidth
|
|
71
|
-
value={
|
|
75
|
+
value={invitationCode}
|
|
72
76
|
maxRows={3}
|
|
73
77
|
/>
|
|
74
78
|
</Box>
|
|
@@ -90,7 +94,7 @@ const HaloInvitationContainer = () => {
|
|
|
90
94
|
interface Status {
|
|
91
95
|
error?: any,
|
|
92
96
|
identity?: string,
|
|
93
|
-
|
|
97
|
+
invitation?: Invitation
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
/**
|
|
@@ -102,13 +106,9 @@ const HaloAuthenticationContainer = () => {
|
|
|
102
106
|
|
|
103
107
|
const handleSubmit = async (invitationCode: string) => {
|
|
104
108
|
try {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (invitation.identityKey) {
|
|
109
|
-
const finishAuthentication = await client.joinHaloInvitation(invitation);
|
|
110
|
-
setStatus({ identity: invitation.identityKey.toString(), finishAuthentication });
|
|
111
|
-
}
|
|
109
|
+
const invitationDescriptor = decodeInvitation(invitationCode);
|
|
110
|
+
const invitation = await client.halo.acceptInvitation(invitationDescriptor);
|
|
111
|
+
setStatus({ identity: invitationDescriptor.identityKey?.toString(), invitation });
|
|
112
112
|
} catch (err: any) {
|
|
113
113
|
// TODO(burdon): Doesn't support retry. Provide hint (eg, should retry/cancel).
|
|
114
114
|
setStatus({ error: err });
|
|
@@ -116,7 +116,7 @@ const HaloAuthenticationContainer = () => {
|
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
const handleAuthenticate = async (pin: string) => {
|
|
119
|
-
await status.
|
|
119
|
+
await status.invitation?.authenticate(Buffer.from(pin));
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
return (
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Box, Button, Divider, Paper, TextField, Toolbar
|
|
9
9
|
} from '@mui/material';
|
|
10
10
|
|
|
11
|
-
import { decodeInvitation, encodeInvitation,
|
|
11
|
+
import { decodeInvitation, encodeInvitation, PartyInvitation } from '@dxos/client';
|
|
12
12
|
import { PublicKey } from '@dxos/crypto';
|
|
13
13
|
|
|
14
14
|
import {
|
|
@@ -56,30 +56,20 @@ const PartyInvitationContainer = () => {
|
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
// const handleCreateInvitation = async () => {
|
|
60
|
-
// const invitation = await client.createHaloInvitation({
|
|
61
|
-
// onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
|
|
62
|
-
// setInvitation(undefined);
|
|
63
|
-
// setPin('');
|
|
64
|
-
// },
|
|
65
|
-
// onPinGenerated: setPin
|
|
66
|
-
// });
|
|
67
|
-
|
|
68
|
-
// setInvitation(invitation);
|
|
69
|
-
// };
|
|
70
|
-
|
|
71
59
|
const handleCreateInvitation = () => {
|
|
72
60
|
setImmediate(async () => {
|
|
73
61
|
resetInvitations();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
62
|
+
|
|
63
|
+
const invitation = await client.echo.getParty(partyKey!)!.createInvitation({
|
|
64
|
+
inviteeKey: contact ? PublicKey.fromHex(contact!) : undefined
|
|
65
|
+
});
|
|
66
|
+
invitation.finished.on(() => resetInvitations());
|
|
67
|
+
|
|
68
|
+
if (!contact) {
|
|
79
69
|
invitation.connected.on(() => setPin(invitation.secret.toString()));
|
|
80
|
-
invitation.finished.on(() => resetInvitations());
|
|
81
|
-
setInvitationCode(encodeInvitation(invitation.descriptor));
|
|
82
70
|
}
|
|
71
|
+
|
|
72
|
+
setInvitationCode(encodeInvitation(invitation.descriptor));
|
|
83
73
|
});
|
|
84
74
|
};
|
|
85
75
|
|
|
@@ -140,7 +130,7 @@ const PartyInvitationContainer = () => {
|
|
|
140
130
|
interface Status {
|
|
141
131
|
error?: any,
|
|
142
132
|
party?: string,
|
|
143
|
-
invitation?:
|
|
133
|
+
invitation?: PartyInvitation
|
|
144
134
|
}
|
|
145
135
|
|
|
146
136
|
/**
|