@dxos/react-client 2.17.2 → 2.18.1

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 (79) hide show
  1. package/.rush/temp/package-deps_build:test.json +9 -8
  2. package/.rush/temp/shrinkwrap-deps.json +3 -3
  3. package/dist/src/components/ErrorBoundary.js +1 -1
  4. package/dist/src/components/ErrorBoundary.js.map +1 -1
  5. package/dist/src/containers/ClientInitializer.js +4 -4
  6. package/dist/src/containers/ClientInitializer.js.map +1 -1
  7. package/dist/src/containers/ClientProvider.js +1 -1
  8. package/dist/src/containers/ClientProvider.js.map +1 -1
  9. package/dist/src/containers/ClientProvider.test.js +6 -6
  10. package/dist/src/containers/ClientProvider.test.js.map +1 -1
  11. package/dist/src/containers/ProfileInitializer.js +3 -3
  12. package/dist/src/containers/ProfileInitializer.js.map +1 -1
  13. package/dist/src/hooks/client/client.test.js +6 -6
  14. package/dist/src/hooks/client/client.test.js.map +1 -1
  15. package/dist/src/hooks/client/config.test.js +9 -9
  16. package/dist/src/hooks/client/config.test.js.map +1 -1
  17. package/dist/src/hooks/client/context.js +1 -1
  18. package/dist/src/hooks/client/context.js.map +1 -1
  19. package/dist/src/hooks/client/useClient.js +1 -1
  20. package/dist/src/hooks/client/useClient.js.map +1 -1
  21. package/dist/src/hooks/client/useConfig.js +1 -1
  22. package/dist/src/hooks/client/useConfig.js.map +1 -1
  23. package/dist/src/hooks/client/useProfile.js +3 -3
  24. package/dist/src/hooks/client/useProfile.js.map +1 -1
  25. package/dist/src/hooks/echo-queries/index.d.ts +1 -0
  26. package/dist/src/hooks/echo-queries/index.d.ts.map +1 -1
  27. package/dist/src/hooks/echo-queries/index.js +1 -0
  28. package/dist/src/hooks/echo-queries/index.js.map +1 -1
  29. package/dist/src/hooks/echo-queries/useContacts.js +3 -3
  30. package/dist/src/hooks/echo-queries/useContacts.js.map +1 -1
  31. package/dist/src/hooks/echo-queries/useMembers.js +2 -2
  32. package/dist/src/hooks/echo-queries/useMembers.js.map +1 -1
  33. package/dist/src/hooks/echo-queries/useParties.js +5 -5
  34. package/dist/src/hooks/echo-queries/useParties.js.map +1 -1
  35. package/dist/src/hooks/echo-queries/useRemoteParties.d.ts +8 -0
  36. package/dist/src/hooks/echo-queries/useRemoteParties.d.ts.map +1 -0
  37. package/dist/src/hooks/echo-queries/useRemoteParties.js +24 -0
  38. package/dist/src/hooks/echo-queries/useRemoteParties.js.map +1 -0
  39. package/dist/src/hooks/echo-selections/useSelection.js +2 -2
  40. package/dist/src/hooks/echo-selections/useSelection.js.map +1 -1
  41. package/dist/src/hooks/invitations/useSecretGenerator.js +2 -2
  42. package/dist/src/hooks/invitations/useSecretGenerator.js.map +1 -1
  43. package/dist/src/hooks/invitations/useSecretProvider.js +1 -1
  44. package/dist/src/hooks/invitations/useSecretProvider.js.map +1 -1
  45. package/dist/src/hooks/util/useResultSet.js +1 -1
  46. package/dist/src/hooks/util/useResultSet.js.map +1 -1
  47. package/dist/src/hooks/wns/registryBotFactories.js +4 -4
  48. package/dist/src/hooks/wns/registryBotFactories.js.map +1 -1
  49. package/dist/src/hooks/wns/registryBots.js +4 -4
  50. package/dist/src/hooks/wns/registryBots.js.map +1 -1
  51. package/dist/src/index.d.ts +1 -0
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/dist/src/index.js +1 -0
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/stories/client.stories.js +2 -2
  56. package/dist/stories/client.stories.js.map +1 -1
  57. package/dist/stories/halo-invitations.stories.d.ts.map +1 -1
  58. package/dist/stories/halo-invitations.stories.js +23 -22
  59. package/dist/stories/halo-invitations.stories.js.map +1 -1
  60. package/dist/stories/helpers/Container.js +1 -1
  61. package/dist/stories/helpers/Container.js.map +1 -1
  62. package/dist/stories/helpers/PartyJoinPanel.js +3 -3
  63. package/dist/stories/helpers/PartyJoinPanel.js.map +1 -1
  64. package/dist/stories/helpers/ThemeProvider.js +1 -1
  65. package/dist/stories/helpers/ThemeProvider.js.map +1 -1
  66. package/dist/stories/party-invitations.stories.js +14 -14
  67. package/dist/stories/party-invitations.stories.js.map +1 -1
  68. package/dist/tests/config.test.js +3 -3
  69. package/dist/tests/config.test.js.map +1 -1
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +11 -11
  72. package/react-client.build.log +5 -5
  73. package/src/hooks/echo-queries/index.ts +1 -0
  74. package/src/hooks/echo-queries/useRemoteParties.ts +25 -0
  75. package/src/hooks/wns/registryBotFactories.ts +1 -1
  76. package/src/hooks/wns/registryBots.ts +1 -1
  77. package/src/index.ts +1 -0
  78. package/stories/halo-invitations.stories.tsx +27 -24
  79. package/stories/party-invitations.stories.tsx +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.17.2",
3
+ "version": "2.18.1",
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.2",
18
- "@dxos/client": "2.17.2",
19
- "@dxos/config": "2.17.2",
20
- "@dxos/credentials": "2.17.2",
21
- "@dxos/crypto": "2.17.2",
22
- "@dxos/debug": "2.17.2",
23
- "@dxos/echo-db": "2.17.2",
24
- "@dxos/util": "2.17.2",
17
+ "@dxos/async": "2.18.1",
18
+ "@dxos/client": "2.18.1",
19
+ "@dxos/config": "2.18.1",
20
+ "@dxos/credentials": "2.18.1",
21
+ "@dxos/crypto": "2.18.1",
22
+ "@dxos/debug": "2.18.1",
23
+ "@dxos/echo-db": "2.18.1",
24
+ "@dxos/util": "2.18.1",
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.1",
33
33
  "@mui/material": "^5.0.1",
34
34
  "@testing-library/react": "^11.0.4",
35
35
  "@testing-library/react-hooks": "5.1.2",
@@ -46,7 +46,7 @@
46
46
  "react-docgen-typescript-loader": "^3.7.2",
47
47
  "react-dom": "^17.0.2",
48
48
  "react-test-renderer": "^17.0.2",
49
- "typescript": "^4.3.5",
49
+ "typescript": "^4.5.2",
50
50
  "webpack": "4.44.2"
51
51
  },
52
52
  "peerDependencies": {
@@ -2,10 +2,10 @@ Invoking: toolchain build:test
2
2
 
3
3
 
4
4
  typescript
5
- OK in 6712 ms
5
+ OK in 9465 ms
6
6
 
7
7
  eslint
8
- OK in 6818 ms
8
+ OK in 9863 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 (414ms)
29
+ 7 passing (526ms)
30
30
 
31
- OK in 8545 ms
31
+ OK in 11932 ms
32
32
 
33
- CHECK COMPLETE in 22082 ms
33
+ CHECK COMPLETE in 31268 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
+ };
@@ -34,7 +34,7 @@ export const useRegistryBotFactories = () => {
34
34
  let factoriesResult: QueryRecord[];
35
35
  try {
36
36
  factoriesResult = await registry.queryRecords({ type: WRN_TYPE_BOT_FACTORY });
37
- } catch (e) {
37
+ } catch (e: any) {
38
38
  log('Querying bot factories unsuccessful.');
39
39
  log(e);
40
40
  return;
@@ -42,7 +42,7 @@ export const useRegistryBots = (props: UseRegistryBotsProps = {}) => {
42
42
  let botsResult: QueryRecord[];
43
43
  try {
44
44
  botsResult = await registry.queryRecords({ type: WRN_TYPE_BOT });
45
- } catch (e) {
45
+ } catch (e: any) {
46
46
  log('Querying bots unsuccessful.');
47
47
  log(e);
48
48
  return;
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,31 +87,36 @@ 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
- } catch (err) {
112
+ } catch (err: any) {
110
113
  // TODO(burdon): Doesn't support retry. Provide hint (eg, should retry/cancel).
111
114
  setStatus({ error: err });
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 (
@@ -142,7 +142,7 @@ const PartyJoinContainer = () => {
142
142
  await party.open();
143
143
 
144
144
  setStatus({ party: party.key.toHex() });
145
- } catch (error) {
145
+ } catch (error: any) {
146
146
  setStatus({ error });
147
147
  }
148
148
  };