@dxos/react-client 2.19.7 → 2.19.8-dev.1dd2f6c4

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.19.7",
3
+ "version": "2.19.8-dev.1dd2f6c4",
4
4
  "description": "React client API",
5
5
  "keywords": [],
6
6
  "license": "AGPL-3.0",
@@ -8,22 +8,22 @@
8
8
  "main": "dist/src/index.js",
9
9
  "types": "dist/src/index.d.ts",
10
10
  "dependencies": {
11
- "@dxos/async": "2.19.7",
12
- "@dxos/bot-factory-client": "2.19.7",
13
- "@dxos/client": "2.19.7",
14
- "@dxos/config": "2.19.7",
15
- "@dxos/credentials": "2.19.7",
16
- "@dxos/crypto": "2.19.7",
17
- "@dxos/debug": "2.19.7",
18
- "@dxos/echo-db": "2.19.7",
19
- "@dxos/util": "2.19.7",
11
+ "@dxos/async": "2.19.8-dev.1dd2f6c4",
12
+ "@dxos/bot-factory-client": "2.19.8-dev.1dd2f6c4",
13
+ "@dxos/client": "2.19.8-dev.1dd2f6c4",
14
+ "@dxos/config": "2.19.8-dev.1dd2f6c4",
15
+ "@dxos/credentials": "2.19.8-dev.1dd2f6c4",
16
+ "@dxos/crypto": "2.19.8-dev.1dd2f6c4",
17
+ "@dxos/debug": "2.19.8-dev.1dd2f6c4",
18
+ "@dxos/echo-db": "2.19.8-dev.1dd2f6c4",
19
+ "@dxos/util": "2.19.8-dev.1dd2f6c4",
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.19.7",
26
+ "@dxos/esbuild-plugins": "2.19.8-dev.1dd2f6c4",
27
27
  "@dxos/esbuild-server": "~1.7.2",
28
28
  "@dxos/toolchain-node-library": "2.19.7",
29
29
  "@mui/material": "^5.0.1",
@@ -1,34 +0,0 @@
1
- Invoking: toolchain build:test
2
-
3
- ENOENT: no such file or directory, stat '/home/github/_work/protocols/protocols/packages/sdk/react-client/src/proto/gen'
4
-
5
- typescript
6
- OK in 4296 ms
7
-
8
- eslint
9
- OK in 7438 ms
10
-
11
- mocha
12
- This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills
13
- This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills
14
-
15
-
16
- ClientProvider
17
- ✓ Renders with children
18
- ✓ Provides the client
19
-
20
- Client hook
21
- ✓ should throw when used outside a context
22
- ✓ should return client when used properly in a context
23
-
24
- Config hook
25
- ✓ should throw when used outside a context
26
- ✓ should return default client config when no config is passed in a context
27
- ✓ should return custom client config when used properly in a context
28
-
29
-
30
- 7 passing (355ms)
31
-
32
- OK in 2511 ms
33
-
34
- CHECK COMPLETE in 14253 ms
@@ -6,7 +6,7 @@ import { useState } from 'react';
6
6
 
7
7
  import { trigger } from '@dxos/async';
8
8
 
9
- export const useSecretProvider = <T extends any> (): [() => Promise<T>, (value: T) => void] => {
9
+ export const useSecretProvider = <T> (): [() => Promise<T>, (value: T) => void] => {
10
10
  const [[provider, resolver]] = useState(() => trigger<T>());
11
11
 
12
12
  return [provider, resolver];
@@ -8,7 +8,7 @@ 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 { decodeInvitation, encodeInvitation, Invitation } from '@dxos/client';
12
12
  import { PublicKey } from '@dxos/crypto';
13
13
  import { InvitationDescriptorType } from '@dxos/echo-db';
14
14
 
@@ -18,9 +18,7 @@ import {
18
18
  useClient,
19
19
  useContacts,
20
20
  useParties,
21
- useProfile,
22
- useSecretGenerator,
23
- useSecretProvider
21
+ useProfile
24
22
  } from '../src';
25
23
  import {
26
24
  ClientPanel,
@@ -42,31 +40,47 @@ const PartyInvitationContainer = () => {
42
40
  const client = useClient();
43
41
  const [partyKey, setPartyKey] = useState<PublicKey>();
44
42
  const [invitationCode, setInvitationCode] = useState<string>();
45
- const [secretProvider, pin, resetPin] = useSecretGenerator();
46
43
  const [contact, setContact] = useState<string>();
47
44
  const [contacts] = useContacts();
45
+ const [pin, setPin] = useState('');
46
+
47
+ const resetInvitations = () => {
48
+ setInvitationCode('');
49
+ setPin('');
50
+ };
48
51
 
49
52
  const handleCreateParty = () => {
50
53
  setImmediate(async () => {
51
54
  const party = await client.echo.createParty();
52
55
  setPartyKey(party.key);
53
- setInvitationCode('');
54
- resetPin();
56
+ resetInvitations();
55
57
  });
56
58
  };
57
59
 
60
+ // const handleCreateInvitation = async () => {
61
+ // const invitation = await client.createHaloInvitation({
62
+ // onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
63
+ // setInvitation(undefined);
64
+ // setPin('');
65
+ // },
66
+ // onPinGenerated: setPin
67
+ // });
68
+
69
+ // setInvitation(invitation);
70
+ // };
71
+
58
72
  const handleCreateInvitation = () => {
59
73
  setImmediate(async () => {
60
- const invitation = (contact)
61
- ? await client.echo.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!))
62
- : await client.echo.createInvitation(partyKey!, { secretProvider }, {
63
- onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
64
- setInvitationCode(undefined);
65
- resetPin();
66
- }
67
- });
68
-
69
- setInvitationCode(encodeInvitation(invitation));
74
+ resetInvitations();
75
+ if (contact) {
76
+ const invitation = await client.echo.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!));
77
+ setInvitationCode(encodeInvitation(invitation));
78
+ } else {
79
+ const invitation = await client.echo.createInvitation(partyKey!);
80
+ invitation.connected.on(() => setPin(invitation.secret.toString()));
81
+ invitation.finshed.on(() => resetInvitations());
82
+ setInvitationCode(encodeInvitation(invitation.descriptor));
83
+ }
70
84
  });
71
85
  };
72
86
 
@@ -124,31 +138,39 @@ const PartyInvitationContainer = () => {
124
138
  );
125
139
  };
126
140
 
141
+ interface Status {
142
+ error?: any,
143
+ party?: string,
144
+ invitation?: Invitation
145
+ }
146
+
127
147
  /**
128
148
  * Processes party invitations.
129
149
  */
130
150
  const PartyJoinContainer = () => {
131
151
  const client = useClient();
132
- const [status, setStatus] = useState({});
133
- const [secretProvider, secretResolver] = useSecretProvider<Buffer>();
152
+ const [status, setStatus] = useState<Status>({});
134
153
 
135
154
  const handleSubmit = async (invitationCode: string) => {
136
155
  setStatus({});
137
156
 
138
157
  try {
139
158
  const invitation = decodeInvitation(invitationCode);
140
- const offline = invitation.type === InvitationDescriptorType.OFFLINE_KEY;
141
- const party = await client.echo.joinParty(invitation, offline ? undefined : secretProvider);
142
- await party.open();
143
-
144
- setStatus({ party: party.key.toHex() });
159
+ if (invitation.type === InvitationDescriptorType.OFFLINE_KEY) {
160
+ const party = await client.echo.joinParty(invitation);
161
+ await party.open();
162
+ setStatus({ party: party.key.toHex() });
163
+ } else {
164
+ const redeemingInvitation = client.echo.acceptInvitation(invitation);
165
+ setStatus({ invitation: redeemingInvitation });
166
+ }
145
167
  } catch (error: any) {
146
168
  setStatus({ error });
147
169
  }
148
170
  };
149
171
 
150
- const handleAuthenticate = (pin: string) => {
151
- secretResolver(Buffer.from(pin));
172
+ const handleAuthenticate = async (pin: string) => {
173
+ await status.invitation?.authenticate(Buffer.from(pin));
152
174
  };
153
175
 
154
176
  return (