@dxos/react-client 2.21.2 → 2.22.1-dev.0f4c1bdc

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 (42) hide show
  1. package/.rush/temp/package-deps_build.json +9 -7
  2. package/.rush/temp/package-deps_build:test.json +9 -7
  3. package/dist/src/hooks/echo-queries/useParties.d.ts.map +1 -1
  4. package/dist/src/hooks/echo-queries/useParties.js +2 -4
  5. package/dist/src/hooks/echo-queries/useParties.js.map +1 -1
  6. package/dist/src/hooks/invitations/index.d.ts +1 -0
  7. package/dist/src/hooks/invitations/index.d.ts.map +1 -1
  8. package/dist/src/hooks/invitations/index.js +1 -0
  9. package/dist/src/hooks/invitations/index.js.map +1 -1
  10. package/dist/src/hooks/invitations/useHaloInvitations.d.ts +3 -0
  11. package/dist/src/hooks/invitations/useHaloInvitations.d.ts.map +1 -0
  12. package/dist/src/hooks/invitations/useHaloInvitations.js +12 -0
  13. package/dist/src/hooks/invitations/useHaloInvitations.js.map +1 -0
  14. package/dist/src/hooks/invitations/useInvitations.d.ts +3 -0
  15. package/dist/src/hooks/invitations/useInvitations.d.ts.map +1 -0
  16. package/dist/src/hooks/invitations/useInvitations.js +21 -0
  17. package/dist/src/hooks/invitations/useInvitations.js.map +1 -0
  18. package/dist/src/hooks/invitations/usePartyInvitations.d.ts +1 -2
  19. package/dist/src/hooks/invitations/usePartyInvitations.d.ts.map +1 -1
  20. package/dist/src/hooks/invitations/usePartyInvitations.js +2 -11
  21. package/dist/src/hooks/invitations/usePartyInvitations.js.map +1 -1
  22. package/dist/src/hooks/invitations/useSecretProvider.d.ts +5 -1
  23. package/dist/src/hooks/invitations/useSecretProvider.d.ts.map +1 -1
  24. package/dist/src/hooks/invitations/useSecretProvider.js +3 -2
  25. package/dist/src/hooks/invitations/useSecretProvider.js.map +1 -1
  26. package/dist/stories/halo-invitations.stories.d.ts.map +1 -1
  27. package/dist/stories/halo-invitations.stories.js +19 -18
  28. package/dist/stories/halo-invitations.stories.js.map +1 -1
  29. package/dist/stories/party-invitations.stories.d.ts.map +1 -1
  30. package/dist/stories/party-invitations.stories.js +8 -20
  31. package/dist/stories/party-invitations.stories.js.map +1 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +12 -12
  34. package/react-client.build.log +5 -5
  35. package/src/hooks/echo-queries/useParties.ts +3 -4
  36. package/src/hooks/invitations/index.ts +1 -0
  37. package/src/hooks/invitations/useHaloInvitations.ts +11 -0
  38. package/src/hooks/invitations/useInvitations.ts +21 -0
  39. package/src/hooks/invitations/usePartyInvitations.ts +2 -14
  40. package/src/hooks/invitations/useSecretProvider.ts +9 -3
  41. package/stories/halo-invitations.stories.tsx +22 -21
  42. package/stories/party-invitations.stories.tsx +13 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.21.2",
3
+ "version": "2.22.1-dev.0f4c1bdc",
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.21.2",
12
- "@dxos/bot-factory-client": "2.21.2",
13
- "@dxos/client": "2.21.2",
14
- "@dxos/config": "2.21.2",
15
- "@dxos/credentials": "2.21.2",
16
- "@dxos/crypto": "2.21.2",
17
- "@dxos/debug": "2.21.2",
18
- "@dxos/echo-db": "2.21.2",
19
- "@dxos/util": "2.21.2",
11
+ "@dxos/async": "2.22.1-dev.0f4c1bdc",
12
+ "@dxos/bot-factory-client": "2.22.1-dev.0f4c1bdc",
13
+ "@dxos/client": "2.22.1-dev.0f4c1bdc",
14
+ "@dxos/config": "2.22.1-dev.0f4c1bdc",
15
+ "@dxos/credentials": "2.22.1-dev.0f4c1bdc",
16
+ "@dxos/crypto": "2.22.1-dev.0f4c1bdc",
17
+ "@dxos/debug": "2.22.1-dev.0f4c1bdc",
18
+ "@dxos/echo-db": "2.22.1-dev.0f4c1bdc",
19
+ "@dxos/util": "2.22.1-dev.0f4c1bdc",
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.21.2",
26
+ "@dxos/esbuild-plugins": "2.22.1-dev.0f4c1bdc",
27
27
  "@dxos/esbuild-server": "~1.7.4",
28
- "@dxos/toolchain-node-library": "2.21.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",
@@ -2,10 +2,10 @@ Invoking: toolchain build:test
2
2
 
3
3
 
4
4
  typescript
5
- OK in 7666 ms
5
+ OK in 7821 ms
6
6
 
7
7
  eslint
8
- OK in 7255 ms
8
+ OK in 7662 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 (351ms)
29
+ 7 passing (293ms)
30
30
 
31
- OK in 2896 ms
31
+ OK in 2430 ms
32
32
 
33
- CHECK COMPLETE in 17838 ms
33
+ CHECK COMPLETE in 17937 ms
@@ -5,7 +5,7 @@
5
5
  import { useEffect, useState } from 'react';
6
6
 
7
7
  import { PartyProxy } from '@dxos/client';
8
- import { PublicKey, PublicKeyLike } from '@dxos/crypto';
8
+ import { PublicKeyLike } from '@dxos/crypto';
9
9
 
10
10
  import { useClient } from '../client';
11
11
 
@@ -14,9 +14,8 @@ import { useClient } from '../client';
14
14
  * Requires ClientContext to be set via ClientProvider.
15
15
  */
16
16
  export const useParty = (partyKey?: PublicKeyLike): PartyProxy | undefined => {
17
- const client = useClient();
18
- // TODO(wittjosiah): Not responsive to party updates?
19
- return partyKey ? client.echo.getParty(PublicKey.from(partyKey)) : undefined;
17
+ const parties = useParties();
18
+ return parties.find(party => partyKey && party.key.equals(partyKey));
20
19
  };
21
20
 
22
21
  /**
@@ -2,5 +2,6 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
+ export * from './useHaloInvitations';
5
6
  export * from './usePartyInvitations';
6
7
  export * from './useSecretProvider';
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { Client } from '@dxos/client';
6
+
7
+ import { useInvitations } from './useInvitations';
8
+
9
+ export const useHaloInvitations = (client: Client) => {
10
+ return useInvitations(client.halo);
11
+ };
@@ -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,24 +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
- const [invitations, setInvitations] = useState<InvitationRequest[]>(party?.activeInvitations ?? []);
15
-
16
- useEffect(() => {
17
- setInvitations(party?.activeInvitations ?? []);
18
-
19
- return party?.invitationsUpdate.on(() => {
20
- setInvitations([...party.activeInvitations]);
21
- });
22
- }, [party]);
23
-
24
- return invitations;
12
+ return useInvitations(party);
25
13
  };
@@ -6,8 +6,14 @@ import { useState } from 'react';
6
6
 
7
7
  import { trigger } from '@dxos/async';
8
8
 
9
- export const useSecretProvider = <T> (): [() => Promise<T>, (value: T) => void] => {
10
- const [[provider, resolver]] = useState(() => trigger<T>());
9
+ type Provider<T> = () => Promise<T>;
10
+ type Resolver<T> = (value: T) => void;
11
+ type Reset = () => void;
11
12
 
12
- return [provider, resolver];
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,8 @@ import {
8
8
  Box, Button, Divider, Paper, TextField, Toolbar
9
9
  } from '@mui/material';
10
10
 
11
- import { Awaited } from '@dxos/async';
12
- import { Client, decodeInvitation, PendingInvitation } from '@dxos/client';
11
+ import { Invitation } from '@dxos/client';
12
+ import { InvitationDescriptor } from '@dxos/echo-db';
13
13
 
14
14
  import {
15
15
  ClientProvider,
@@ -33,19 +33,24 @@ export default {
33
33
  */
34
34
  const HaloInvitationContainer = () => {
35
35
  const client = useClient();
36
- const [invitation, setInvitation] = useState<PendingInvitation | undefined>();
36
+ const [invitationCode, setInvitationCode] = useState<string>();
37
37
  const [pin, setPin] = useState('');
38
38
 
39
+ const resetInvitations = () => {
40
+ setInvitationCode('');
41
+ setPin('');
42
+ };
43
+
39
44
  const handleCreateInvitation = async () => {
40
- const invitation = await client.createHaloInvitation({
41
- onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
42
- setInvitation(undefined);
43
- setPin('');
44
- },
45
- onPinGenerated: setPin
45
+ resetInvitations();
46
+
47
+ const invitation = await client.halo.createInvitation();
48
+ invitation.finished.on(() => resetInvitations());
49
+ invitation.connected.on(() => {
50
+ setPin(invitation.secret.toString());
46
51
  });
47
52
 
48
- setInvitation(invitation);
53
+ setInvitationCode(invitation.descriptor.encode());
49
54
  };
50
55
 
51
56
  if (!client.halo.hasProfile()) {
@@ -62,13 +67,13 @@ const HaloInvitationContainer = () => {
62
67
  </Button>
63
68
  </Toolbar>
64
69
 
65
- {invitation && (
70
+ {invitationCode && (
66
71
  <Box sx={{ marginTop: 1 }}>
67
72
  <TextField
68
73
  disabled
69
74
  multiline
70
75
  fullWidth
71
- value={invitation.invitationCode}
76
+ value={invitationCode}
72
77
  maxRows={3}
73
78
  />
74
79
  </Box>
@@ -90,7 +95,7 @@ const HaloInvitationContainer = () => {
90
95
  interface Status {
91
96
  error?: any,
92
97
  identity?: string,
93
- finishAuthentication?: Awaited<ReturnType<Client['joinHaloInvitation']>>
98
+ invitation?: Invitation
94
99
  }
95
100
 
96
101
  /**
@@ -102,13 +107,9 @@ const HaloAuthenticationContainer = () => {
102
107
 
103
108
  const handleSubmit = async (invitationCode: string) => {
104
109
  try {
105
- const invitation = decodeInvitation(invitationCode);
106
-
107
- // Claim an invitation for this device to join an existing Halo.
108
- if (invitation.identityKey) {
109
- const finishAuthentication = await client.joinHaloInvitation(invitation);
110
- setStatus({ identity: invitation.identityKey.toString(), finishAuthentication });
111
- }
110
+ const invitationDescriptor = InvitationDescriptor.decode(invitationCode);
111
+ const invitation = await client.halo.acceptInvitation(invitationDescriptor);
112
+ setStatus({ identity: invitationDescriptor.identityKey?.toString(), invitation });
112
113
  } catch (err: any) {
113
114
  // TODO(burdon): Doesn't support retry. Provide hint (eg, should retry/cancel).
114
115
  setStatus({ error: err });
@@ -116,7 +117,7 @@ const HaloAuthenticationContainer = () => {
116
117
  };
117
118
 
118
119
  const handleAuthenticate = async (pin: string) => {
119
- await status.finishAuthentication?.(pin);
120
+ await status.invitation?.authenticate(Buffer.from(pin));
120
121
  };
121
122
 
122
123
  return (
@@ -8,8 +8,9 @@ import {
8
8
  Box, Button, Divider, Paper, TextField, Toolbar
9
9
  } from '@mui/material';
10
10
 
11
- import { decodeInvitation, encodeInvitation, Invitation } from '@dxos/client';
11
+ import { PartyInvitation } from '@dxos/client';
12
12
  import { PublicKey } from '@dxos/crypto';
13
+ import { InvitationDescriptor } from '@dxos/echo-db';
13
14
 
14
15
  import {
15
16
  ClientProvider,
@@ -56,30 +57,20 @@ const PartyInvitationContainer = () => {
56
57
  });
57
58
  };
58
59
 
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
60
  const handleCreateInvitation = () => {
72
61
  setImmediate(async () => {
73
62
  resetInvitations();
74
- if (contact) {
75
- const invitation = await client.echo.getParty(partyKey!)!.createInvitation({ inviteeKey: PublicKey.fromHex(contact!) });
76
- setInvitationCode(encodeInvitation(invitation.descriptor));
77
- } else {
78
- const invitation = await client.echo.createInvitation(partyKey!);
63
+
64
+ const invitation = await client.echo.getParty(partyKey!)!.createInvitation({
65
+ inviteeKey: contact ? PublicKey.fromHex(contact!) : undefined
66
+ });
67
+ invitation.finished.on(() => resetInvitations());
68
+
69
+ if (!contact) {
79
70
  invitation.connected.on(() => setPin(invitation.secret.toString()));
80
- invitation.finished.on(() => resetInvitations());
81
- setInvitationCode(encodeInvitation(invitation.descriptor));
82
71
  }
72
+
73
+ setInvitationCode(invitation.descriptor.encode());
83
74
  });
84
75
  };
85
76
 
@@ -140,7 +131,7 @@ const PartyInvitationContainer = () => {
140
131
  interface Status {
141
132
  error?: any,
142
133
  party?: string,
143
- invitation?: Invitation
134
+ invitation?: PartyInvitation
144
135
  }
145
136
 
146
137
  /**
@@ -154,7 +145,7 @@ const PartyJoinContainer = () => {
154
145
  setStatus({});
155
146
 
156
147
  try {
157
- const invitation = await client.echo.acceptInvitation(decodeInvitation(invitationCode));
148
+ const invitation = await client.echo.acceptInvitation(InvitationDescriptor.decode(invitationCode));
158
149
  setStatus({ invitation });
159
150
 
160
151
  const party = await invitation.getParty();