@dxos/react-client 0.10.0 → 0.11.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 (101) hide show
  1. package/.storybook/main.mts +1 -1
  2. package/.storybook/preview.mts +2 -2
  3. package/CHANGELOG.md +77 -0
  4. package/dist/lib/chunk-ClientProvider.mjs +152 -0
  5. package/dist/lib/chunk-ClientProvider.mjs.map +1 -0
  6. package/dist/lib/chunk-context.mjs +14 -0
  7. package/dist/lib/chunk-context.mjs.map +1 -0
  8. package/dist/lib/chunk-useClient.mjs +16 -0
  9. package/dist/lib/chunk-useClient.mjs.map +1 -0
  10. package/dist/lib/devtools.mjs +37 -0
  11. package/dist/lib/devtools.mjs.map +1 -0
  12. package/dist/lib/echo.mjs +230 -0
  13. package/dist/lib/echo.mjs.map +1 -0
  14. package/dist/lib/halo.mjs +85 -0
  15. package/dist/lib/halo.mjs.map +1 -0
  16. package/dist/lib/index.mjs +108 -0
  17. package/dist/lib/index.mjs.map +1 -0
  18. package/dist/lib/invitations.mjs +130 -0
  19. package/dist/lib/invitations.mjs.map +1 -0
  20. package/dist/lib/mesh.mjs +14 -0
  21. package/dist/lib/mesh.mjs.map +1 -0
  22. package/dist/lib/testing.mjs +206 -0
  23. package/dist/lib/testing.mjs.map +1 -0
  24. package/dist/types/src/client/AgentHostingProvider.d.ts +0 -3
  25. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
  26. package/dist/types/src/client/context.d.ts +4 -1
  27. package/dist/types/src/client/context.d.ts.map +1 -1
  28. package/dist/types/src/echo/index.d.ts +1 -0
  29. package/dist/types/src/echo/index.d.ts.map +1 -1
  30. package/dist/types/src/echo/useFeedSyncState.d.ts +1 -1
  31. package/dist/types/src/echo/useFlush.d.ts +10 -0
  32. package/dist/types/src/echo/useFlush.d.ts.map +1 -0
  33. package/dist/types/src/echo/useSpaces.d.ts +0 -10
  34. package/dist/types/src/echo/useSpaces.d.ts.map +1 -1
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/moon.yml +1 -12
  37. package/package.json +32 -45
  38. package/src/client/AgentHostingProvider.tsx +5 -8
  39. package/src/client/context.ts +11 -2
  40. package/src/echo/index.ts +1 -0
  41. package/src/echo/useFeedSyncState.ts +4 -4
  42. package/src/echo/useFlush.ts +39 -0
  43. package/src/echo/useSpaces.ts +0 -14
  44. package/src/echo/useSyncState.ts +2 -2
  45. package/src/halo/Passkey.stories.tsx +1 -1
  46. package/src/testing/withClientProvider.stories.tsx +1 -1
  47. package/vite.config.ts +19 -0
  48. package/dist/lib/browser/chunk-3LVU7RNK.mjs +0 -16
  49. package/dist/lib/browser/chunk-3LVU7RNK.mjs.map +0 -7
  50. package/dist/lib/browser/chunk-CZMIVAGI.mjs +0 -8
  51. package/dist/lib/browser/chunk-CZMIVAGI.mjs.map +0 -7
  52. package/dist/lib/browser/chunk-SSDQ6NXU.mjs +0 -153
  53. package/dist/lib/browser/chunk-SSDQ6NXU.mjs.map +0 -7
  54. package/dist/lib/browser/chunk-XT352YI6.mjs +0 -134
  55. package/dist/lib/browser/chunk-XT352YI6.mjs.map +0 -7
  56. package/dist/lib/browser/devtools/index.mjs +0 -39
  57. package/dist/lib/browser/devtools/index.mjs.map +0 -7
  58. package/dist/lib/browser/echo/index.mjs +0 -239
  59. package/dist/lib/browser/echo/index.mjs.map +0 -7
  60. package/dist/lib/browser/halo/index.mjs +0 -109
  61. package/dist/lib/browser/halo/index.mjs.map +0 -7
  62. package/dist/lib/browser/index.mjs +0 -119
  63. package/dist/lib/browser/index.mjs.map +0 -7
  64. package/dist/lib/browser/invitations/index.mjs +0 -17
  65. package/dist/lib/browser/invitations/index.mjs.map +0 -7
  66. package/dist/lib/browser/mesh/index.mjs +0 -18
  67. package/dist/lib/browser/mesh/index.mjs.map +0 -7
  68. package/dist/lib/browser/meta.json +0 -1
  69. package/dist/lib/browser/testing/index.mjs +0 -204
  70. package/dist/lib/browser/testing/index.mjs.map +0 -7
  71. package/dist/lib/browser/worker.mjs +0 -3
  72. package/dist/lib/browser/worker.mjs.map +0 -7
  73. package/dist/lib/node-esm/chunk-CUDKNAMV.mjs +0 -17
  74. package/dist/lib/node-esm/chunk-CUDKNAMV.mjs.map +0 -7
  75. package/dist/lib/node-esm/chunk-JZNSBWIR.mjs +0 -155
  76. package/dist/lib/node-esm/chunk-JZNSBWIR.mjs.map +0 -7
  77. package/dist/lib/node-esm/chunk-WL3Z5HOH.mjs +0 -135
  78. package/dist/lib/node-esm/chunk-WL3Z5HOH.mjs.map +0 -7
  79. package/dist/lib/node-esm/chunk-WUTK2IJF.mjs +0 -10
  80. package/dist/lib/node-esm/chunk-WUTK2IJF.mjs.map +0 -7
  81. package/dist/lib/node-esm/devtools/index.mjs +0 -40
  82. package/dist/lib/node-esm/devtools/index.mjs.map +0 -7
  83. package/dist/lib/node-esm/echo/index.mjs +0 -240
  84. package/dist/lib/node-esm/echo/index.mjs.map +0 -7
  85. package/dist/lib/node-esm/halo/index.mjs +0 -110
  86. package/dist/lib/node-esm/halo/index.mjs.map +0 -7
  87. package/dist/lib/node-esm/index.mjs +0 -120
  88. package/dist/lib/node-esm/index.mjs.map +0 -7
  89. package/dist/lib/node-esm/invitations/index.mjs +0 -18
  90. package/dist/lib/node-esm/invitations/index.mjs.map +0 -7
  91. package/dist/lib/node-esm/mesh/index.mjs +0 -19
  92. package/dist/lib/node-esm/mesh/index.mjs.map +0 -7
  93. package/dist/lib/node-esm/meta.json +0 -1
  94. package/dist/lib/node-esm/testing/index.mjs +0 -205
  95. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  96. package/dist/lib/node-esm/worker.mjs +0 -5
  97. package/dist/lib/node-esm/worker.mjs.map +0 -7
  98. package/dist/types/src/worker.d.ts +0 -2
  99. package/dist/types/src/worker.d.ts.map +0 -1
  100. package/src/worker.ts +0 -5
  101. package/vitest.config.ts +0 -16
package/moon.yml CHANGED
@@ -1,20 +1,9 @@
1
1
  layer: library
2
2
  language: typescript
3
3
  tags:
4
- - ts-build
4
+ - ts-vite-build
5
5
  - ts-test
6
6
  - ts-test-storybook
7
7
  - typedoc
8
8
  - pack
9
9
  - storybook
10
- tasks:
11
- compile:
12
- args:
13
- - '--entryPoint=src/devtools/index.ts'
14
- - '--entryPoint=src/echo/index.ts'
15
- - '--entryPoint=src/halo/index.ts'
16
- - '--entryPoint=src/index.ts'
17
- - '--entryPoint=src/invitations/index.ts'
18
- - '--entryPoint=src/mesh/index.ts'
19
- - '--entryPoint=src/testing/index.ts'
20
- - '--entryPoint=src/worker.ts'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "React client API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,69 +16,56 @@
16
16
  "./devtools": {
17
17
  "source": "./src/devtools/index.ts",
18
18
  "types": "./dist/types/src/devtools/index.d.ts",
19
- "browser": "./dist/lib/browser/devtools/index.mjs",
20
- "node": "./dist/lib/node-esm/devtools/index.mjs"
19
+ "import": "./dist/lib/devtools.mjs"
21
20
  },
22
21
  "./echo": {
23
22
  "source": "./src/echo/index.ts",
24
23
  "types": "./dist/types/src/echo/index.d.ts",
25
- "browser": "./dist/lib/browser/echo/index.mjs",
26
- "node": "./dist/lib/node-esm/echo/index.mjs"
24
+ "import": "./dist/lib/echo.mjs"
27
25
  },
28
26
  "./halo": {
29
27
  "source": "./src/halo/index.ts",
30
28
  "types": "./dist/types/src/halo/index.d.ts",
31
- "browser": "./dist/lib/browser/halo/index.mjs",
32
- "node": "./dist/lib/node-esm/halo/index.mjs"
29
+ "import": "./dist/lib/halo.mjs"
33
30
  },
34
31
  ".": {
35
32
  "source": "./src/index.ts",
36
33
  "types": "./dist/types/src/index.d.ts",
37
- "browser": "./dist/lib/browser/index.mjs",
38
- "node": "./dist/lib/node-esm/index.mjs"
34
+ "import": "./dist/lib/index.mjs"
39
35
  },
40
36
  "./invitations": {
41
37
  "source": "./src/invitations/index.ts",
42
38
  "types": "./dist/types/src/invitations/index.d.ts",
43
- "browser": "./dist/lib/browser/invitations/index.mjs",
44
- "node": "./dist/lib/node-esm/invitations/index.mjs"
39
+ "import": "./dist/lib/invitations.mjs"
45
40
  },
46
41
  "./mesh": {
47
42
  "source": "./src/mesh/index.ts",
48
43
  "types": "./dist/types/src/mesh/index.d.ts",
49
- "browser": "./dist/lib/browser/mesh/index.mjs",
50
- "node": "./dist/lib/node-esm/mesh/index.mjs"
44
+ "import": "./dist/lib/mesh.mjs"
51
45
  },
52
46
  "./testing": {
53
47
  "source": "./src/testing/index.ts",
54
48
  "types": "./dist/types/src/testing/index.d.ts",
55
- "browser": "./dist/lib/browser/testing/index.mjs",
56
- "node": "./dist/lib/node-esm/testing/index.mjs"
57
- },
58
- "./worker": {
59
- "source": "./src/worker.ts",
60
- "types": "./dist/types/src/worker.d.ts",
61
- "browser": "./dist/lib/browser/worker.mjs",
62
- "node": "./dist/lib/node-esm/worker.mjs"
49
+ "import": "./dist/lib/testing.mjs"
63
50
  }
64
51
  },
65
52
  "types": "dist/types/src/index.d.ts",
66
53
  "dependencies": {
67
- "@dxos/async": "0.10.0",
68
- "@dxos/client": "0.10.0",
69
- "@dxos/config": "0.10.0",
70
- "@dxos/context": "0.10.0",
71
- "@dxos/codec-protobuf": "0.10.0",
72
- "@dxos/debug": "0.10.0",
73
- "@dxos/echo-protocol": "0.10.0",
74
- "@dxos/echo": "0.10.0",
75
- "@dxos/invariant": "0.10.0",
76
- "@dxos/echo-react": "0.10.0",
77
- "@dxos/keys": "0.10.0",
78
- "@dxos/log": "0.10.0",
79
- "@dxos/node-std": "0.10.0",
80
- "@dxos/react-hooks": "0.10.0",
81
- "@dxos/util": "0.10.0"
54
+ "@dxos/async": "0.11.1",
55
+ "@dxos/client": "0.11.1",
56
+ "@dxos/codec-protobuf": "0.11.1",
57
+ "@dxos/config": "0.11.1",
58
+ "@dxos/context": "0.11.1",
59
+ "@dxos/debug": "0.11.1",
60
+ "@dxos/echo": "0.11.1",
61
+ "@dxos/echo-protocol": "0.11.1",
62
+ "@dxos/echo-react": "0.11.1",
63
+ "@dxos/invariant": "0.11.1",
64
+ "@dxos/keys": "0.11.1",
65
+ "@dxos/log": "0.11.1",
66
+ "@dxos/node-std": "0.11.1",
67
+ "@dxos/react-hooks": "0.11.1",
68
+ "@dxos/util": "0.11.1"
82
69
  },
83
70
  "devDependencies": {
84
71
  "@types/react": "~19.2.17",
@@ -86,21 +73,21 @@
86
73
  "react": "~19.2.7",
87
74
  "react-dom": "~19.2.7",
88
75
  "typedoc": "0.28.1",
89
- "@dxos/random": "0.10.0",
90
- "@dxos/react-ui-syntax-highlighter": "0.10.0",
91
- "@dxos/test-utils": "0.10.0",
92
- "@dxos/storybook-utils": "0.10.0",
93
- "@dxos/react-ui": "0.10.0",
94
- "@dxos/ui-theme": "0.10.0"
76
+ "@dxos/random": "0.11.1",
77
+ "@dxos/react-ui": "0.11.1",
78
+ "@dxos/react-ui-syntax-highlighter": "0.11.1",
79
+ "@dxos/storybook-utils": "0.11.1",
80
+ "@dxos/test-utils": "0.11.1",
81
+ "@dxos/ui-theme": "0.11.1"
95
82
  },
96
83
  "peerDependencies": {
97
84
  "react": "~19.2.7",
98
85
  "react-dom": "~19.2.7"
99
86
  },
100
87
  "optionalDependencies": {
101
- "@dxos/random": "0.10.0",
102
- "@dxos/react-ui": "0.10.0",
103
- "@dxos/ui-theme": "0.10.0"
88
+ "@dxos/random": "0.11.1",
89
+ "@dxos/react-ui": "0.11.1",
90
+ "@dxos/ui-theme": "0.11.1"
104
91
  },
105
92
  "publishConfig": {
106
93
  "access": "public"
@@ -2,19 +2,20 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React, { type PropsWithChildren, createContext, useContext, useState } from 'react';
5
+ import React, { type PropsWithChildren, useState } from 'react';
6
6
 
7
7
  import { type AgentHostingProviderClient, AgentManagerClient, FakeAgentHostingProvider } from '@dxos/client';
8
8
  import { type Halo } from '@dxos/client/halo';
9
9
  import { type Config } from '@dxos/config';
10
10
  import { log } from '@dxos/log';
11
11
 
12
- import { useClient } from '../client';
12
+ // Imported from the defining module, not the directory barrel: `'../client'` is this file's own
13
+ // barrel, and that cycle made every downstream edit a full page reload.
14
+ import { AgentHostingContext } from './context';
15
+ import { useClient } from './useClient';
13
16
 
14
17
  export type AgentHostingProviderProps = { config: Config; halo: Halo };
15
18
 
16
- export const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);
17
-
18
19
  /**
19
20
  * Experimental agent hosting provider.
20
21
  * @param props
@@ -29,10 +30,6 @@ export const AgentHostingProvider = (props: PropsWithChildren) => {
29
30
  );
30
31
  };
31
32
 
32
- export const useAgentHostingClient = () => {
33
- return useContext(AgentHostingContext);
34
- };
35
-
36
33
  const makeClient = ({ config, halo }: AgentHostingProviderProps) => {
37
34
  const agentHostingConfig = config.get('runtime.services.agentHosting');
38
35
  if (!agentHostingConfig) {
@@ -2,9 +2,9 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { type Context, createContext } from 'react';
5
+ import { type Context, createContext, useContext } from 'react';
6
6
 
7
- import { type Client, type SystemStatus } from '@dxos/client';
7
+ import { type AgentHostingProviderClient, type Client, type SystemStatus } from '@dxos/client';
8
8
 
9
9
  export type ClientContextProps = {
10
10
  client: Client;
@@ -17,3 +17,12 @@ export type ClientContextProps = {
17
17
  export const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(
18
18
  undefined,
19
19
  );
20
+
21
+ // Kept out of `AgentHostingProvider.tsx`: react-refresh only fast-refreshes a module whose exports
22
+ // are all components, so a context and hook exported beside the provider make it a reload boundary
23
+ // for everything downstream of it.
24
+ export const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);
25
+
26
+ export const useAgentHostingClient = () => {
27
+ return useContext(AgentHostingContext);
28
+ };
package/src/echo/index.ts CHANGED
@@ -9,6 +9,7 @@ export * from './useMembers';
9
9
  export * from './useSpaces';
10
10
  export * from './useSpaceInvitations';
11
11
  export * from './useSpaceProperties';
12
+ export * from './useFlush';
12
13
  export * from './useSubscription';
13
14
  export * from './useSyncState';
14
15
  export * from './useFeedSyncState';
@@ -20,15 +20,15 @@ export type FeedSyncState = {
20
20
  export type FeedSyncStateMap = Record<SpaceId, FeedSyncState>;
21
21
 
22
22
  /**
23
- * Polls queue replication state per space.
23
+ * Polls feed replication state per space.
24
24
  */
25
25
  export const useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS): FeedSyncStateMap => {
26
26
  const client = useClient();
27
27
  const [feedSyncState, setFeedSyncState] = useState<FeedSyncStateMap>({});
28
28
 
29
29
  useEffect(() => {
30
- const queueService = client.services.services.QueueService;
31
- if (!queueService) {
30
+ const feedService = client.services.services.FeedService;
31
+ if (!feedService) {
32
32
  return;
33
33
  }
34
34
 
@@ -39,7 +39,7 @@ export const useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS): Fee
39
39
  const entries = await Promise.all(
40
40
  spaces.map(async (space) => {
41
41
  try {
42
- const response = await queueService.getSyncState({ spaceId: space.id });
42
+ const response = await feedService.getSyncState({ spaceId: space.id });
43
43
  const state = (response.namespaces ?? []).reduce<FeedSyncState>(
44
44
  (acc, entry) => {
45
45
  acc.pending += Number(entry.blocksToPull ?? 0) + Number(entry.blocksToPush ?? 0);
@@ -0,0 +1,39 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { useCallback, useRef, useState } from 'react';
6
+
7
+ import { type Space } from '@dxos/client/echo';
8
+
9
+ /**
10
+ * Flushes a space's database to storage, exposing a transient `idle → flushing → flushed → idle`
11
+ * state suitable for driving a toolbar affordance.
12
+ */
13
+ export const useFlush = (space?: Space) => {
14
+ const [state, setState] = useState<'idle' | 'flushing' | 'flushed'>('idle');
15
+ const resetTimer = useRef<NodeJS.Timeout | null>(null);
16
+
17
+ const handleFlush = useCallback(() => {
18
+ if (!space) {
19
+ return;
20
+ }
21
+
22
+ queueMicrotask(async () => {
23
+ if (resetTimer.current) {
24
+ clearTimeout(resetTimer.current);
25
+ }
26
+
27
+ setState('flushing');
28
+ await space.db.flush();
29
+ setState('flushed');
30
+
31
+ resetTimer.current = setTimeout(() => {
32
+ setState('idle');
33
+ resetTimer.current = null;
34
+ }, 1_000);
35
+ });
36
+ }, [space]);
37
+
38
+ return { state, handleFlush };
39
+ };
@@ -35,20 +35,6 @@ export const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {
35
35
  });
36
36
  };
37
37
 
38
- /**
39
- * Get a Space database by the id of the space.
40
- * The space is not guaranteed to be in the ready state.
41
- * Returns undefined if no id is provided.
42
- * Requires a ClientProvider somewhere in the parent tree.
43
- *
44
- * @param spaceId the id of the space to look for.
45
- * @deprecated Use useSpace.
46
- */
47
- export const useDatabase = (spaceId?: SpaceId): Space['db'] | undefined => {
48
- const space = useSpace(spaceId);
49
- return space?.db;
50
- };
51
-
52
38
  export type UseSpacesProps = {
53
39
  /**
54
40
  * Return uninitialized spaces as well.
@@ -26,7 +26,7 @@ export const useSyncState = (): SpaceSyncStateMap => {
26
26
  }
27
27
 
28
28
  ctx.onDispose(
29
- space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
29
+ space.internal.db.subscribeToAutomergeSyncState(ctx, ({ peers = [] }) => {
30
30
  const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
31
31
  if (syncState) {
32
32
  setSpaceState((spaceState) => ({ ...spaceState, [space.id]: syncState }));
@@ -58,7 +58,7 @@ export const useSpaceSyncState = (space: Space): PeerSyncState | undefined => {
58
58
 
59
59
  useEffect(() => {
60
60
  const ctx = new Context();
61
- space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
61
+ space.internal.db.subscribeToAutomergeSyncState(ctx, ({ peers = [] }) => {
62
62
  const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
63
63
  if (syncState) {
64
64
  setSpaceState(syncState);
@@ -115,7 +115,7 @@ const Test = () => {
115
115
  Authenticate with Passkey
116
116
  </Button>
117
117
  </div>
118
- <div className='flex flex-col min-w-[28rem] divide-y divide-separator border border-separator rounded-sm'>
118
+ <div className='flex flex-col min-w-[28rem] divide-y divide-subdued-separator border border-separator rounded-sm'>
119
119
  <JsonHighlighter data={{ identity, credentials: credentials.length }} />
120
120
  </div>
121
121
  </>
@@ -27,7 +27,7 @@ const DefaultStory = () => {
27
27
  }
28
28
 
29
29
  return (
30
- <div className='flex flex-col divide-y divide-separator border border-separator'>
30
+ <div className='flex flex-col divide-y divide-subdued-separator border border-separator'>
31
31
  <JsonHighlighter data={client.toJSON()} />
32
32
  {spaces.map((space) => (
33
33
  <SpaceInfo key={space.id} space={space} />
package/vite.config.ts ADDED
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { defineConfig } from '../../../vite.base.config.ts';
6
+
7
+ export default defineConfig({
8
+ entry: {
9
+ devtools: 'src/devtools/index.ts',
10
+ echo: 'src/echo/index.ts',
11
+ halo: 'src/halo/index.ts',
12
+ index: 'src/index.ts',
13
+ invitations: 'src/invitations/index.ts',
14
+ mesh: 'src/mesh/index.ts',
15
+ testing: 'src/testing/index.ts',
16
+ },
17
+ jsx: 'react',
18
+ test: { node: { environment: 'happy-dom' }, storybook: true },
19
+ });
@@ -1,16 +0,0 @@
1
- import {
2
- ClientContext
3
- } from "./chunk-CZMIVAGI.mjs";
4
-
5
- // src/client/useClient.ts
6
- import { useContext } from "react";
7
- import { raise } from "@dxos/debug";
8
- var useClient = () => {
9
- const { client } = useContext(ClientContext) ?? raise(new Error("Missing ClientContext."));
10
- return client;
11
- };
12
-
13
- export {
14
- useClient
15
- };
16
- //# sourceMappingURL=chunk-3LVU7RNK.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/client/useClient.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n"],
5
- "mappings": ";;;;;AAIA,SAASA,kBAAkB;AAE3B,SAASC,aAAa;AAQf,IAAMC,YAAY,MAAA;AACvB,QAAM,EAAEC,OAAM,IAAKC,WAAWC,aAAAA,KAAkBC,MAAM,IAAIC,MAAM,wBAAA,CAAA;AAChE,SAAOJ;AACT;",
6
- "names": ["useContext", "raise", "useClient", "client", "useContext", "ClientContext", "raise", "Error"]
7
- }
@@ -1,8 +0,0 @@
1
- // src/client/context.ts
2
- import { createContext } from "react";
3
- var ClientContext = createContext(void 0);
4
-
5
- export {
6
- ClientContext
7
- };
8
- //# sourceMappingURL=chunk-CZMIVAGI.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/client/context.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport type ClientContextProps = {\n client: Client;\n status?: SystemStatus | null;\n};\n\n/**\n * @internal Use ClientProvider to create or initialize the Client.\n */\nexport const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(\n undefined,\n);\n"],
5
- "mappings": ";AAIA,SAAuBA,qBAAqB;AAYrC,IAAMC,gBAAyDD,cACpEE,MAAAA;",
6
- "names": ["createContext", "ClientContext", "undefined"]
7
- }
@@ -1,153 +0,0 @@
1
- // src/invitations/index.ts
2
- import { AuthenticatingInvitationObservable, CancellableInvitationObservable, Invitation as Invitation2, InvitationEncoder as InvitationEncoder2, InvitationsProxy } from "@dxos/client/invitations";
3
-
4
- // src/invitations/useInvitationStatus.ts
5
- import { useCallback, useEffect, useMemo, useReducer } from "react";
6
- import { Invitation, InvitationEncoder } from "@dxos/client/invitations";
7
- import { log } from "@dxos/log";
8
- var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/invitations/useInvitationStatus.ts";
9
- var isShareableInvitation = (invitation) => invitation.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY || !!invitation.guestKeypair?.privateKey;
10
- var useInvitationStatus = (observable) => {
11
- const [state, dispatch] = useReducer((prev, action) => {
12
- log("useInvitationStatus", {
13
- action
14
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 12, S: void 0 });
15
- const invitationProps = "invitation" in action ? {
16
- id: action.invitation.invitationId,
17
- multiUse: action.invitation.multiUse,
18
- invitationCode: InvitationEncoder.encode(action.invitation),
19
- authCode: action.invitation.authCode,
20
- authMethod: action.invitation.authMethod,
21
- shareable: isShareableInvitation(action.invitation),
22
- type: action.invitation.type
23
- } : {};
24
- return {
25
- ...prev,
26
- ...invitationProps,
27
- // TODO(burdon): State.
28
- status: action.status,
29
- // `invitationObservable`, `secret`, and `result` is persisted between the status-actions that set them.
30
- result: action.status === Invitation.State.SUCCESS ? action.result : prev.result,
31
- // `error` gets set each time we enter the error state
32
- ...action.status === Invitation.State.ERROR && {
33
- error: action.error
34
- },
35
- // `haltedAt` gets set on only the first error/cancelled/timeout action and reset on any others.
36
- ...(action.status === Invitation.State.ERROR || action.status === Invitation.State.CANCELLED || action.status === Invitation.State.TIMEOUT) && {
37
- haltedAt: typeof prev.haltedAt === "undefined" ? action.haltedAt : prev.haltedAt
38
- }
39
- };
40
- }, null, (_arg) => {
41
- const invitation = observable?.get();
42
- return {
43
- status: Invitation.State.INIT,
44
- result: {
45
- spaceKey: null,
46
- identityKey: null,
47
- swarmKey: null,
48
- target: null
49
- },
50
- id: invitation?.invitationId,
51
- multiUse: invitation?.multiUse,
52
- invitationCode: invitation ? InvitationEncoder.encode(invitation) : void 0,
53
- authCode: invitation?.authCode,
54
- authMethod: invitation?.authMethod,
55
- shareable: invitation ? isShareableInvitation(invitation) : false,
56
- type: invitation?.type
57
- };
58
- });
59
- useEffect(() => {
60
- const update = (invitation) => {
61
- switch (invitation.state) {
62
- case Invitation.State.INIT:
63
- case Invitation.State.CONNECTED:
64
- case Invitation.State.READY_FOR_AUTHENTICATION:
65
- case Invitation.State.AUTHENTICATING: {
66
- dispatch({
67
- invitation,
68
- status: invitation.state
69
- });
70
- break;
71
- }
72
- case Invitation.State.SUCCESS: {
73
- dispatch({
74
- invitation,
75
- status: invitation.state,
76
- result: {
77
- spaceKey: invitation.spaceKey || null,
78
- identityKey: invitation.identityKey || null,
79
- swarmKey: invitation.swarmKey || null,
80
- target: invitation.target || null
81
- }
82
- });
83
- break;
84
- }
85
- case Invitation.State.CANCELLED:
86
- case Invitation.State.TIMEOUT: {
87
- dispatch({
88
- invitation,
89
- status: invitation.state,
90
- haltedAt: state.status
91
- });
92
- break;
93
- }
94
- }
95
- };
96
- const subscription = observable?.subscribe(update, (err) => {
97
- dispatch({
98
- status: Invitation.State.ERROR,
99
- error: err,
100
- haltedAt: state.status
101
- });
102
- });
103
- const currentState = observable?.get();
104
- if (currentState) {
105
- update(currentState);
106
- }
107
- return () => subscription?.unsubscribe();
108
- }, [
109
- observable,
110
- state.status
111
- ]);
112
- const connect = useCallback((observable2) => {
113
- dispatch({
114
- invitation: observable2.get(),
115
- status: Invitation.State.CONNECTING,
116
- observable: observable2
117
- });
118
- }, []);
119
- const authenticate = useCallback((authCode) => {
120
- log("authenticating...", {
121
- authCode
122
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 125, S: void 0 });
123
- return observable.authenticate(authCode);
124
- }, [
125
- observable
126
- ]);
127
- const cancel = useCallback(async () => observable?.cancel(), [
128
- observable
129
- ]);
130
- return useMemo(() => {
131
- return {
132
- ...state,
133
- cancel,
134
- connect,
135
- authenticate
136
- };
137
- }, [
138
- state,
139
- cancel,
140
- connect,
141
- authenticate
142
- ]);
143
- };
144
-
145
- export {
146
- useInvitationStatus,
147
- AuthenticatingInvitationObservable,
148
- CancellableInvitationObservable,
149
- Invitation2 as Invitation,
150
- InvitationEncoder2 as InvitationEncoder,
151
- InvitationsProxy
152
- };
153
- //# sourceMappingURL=chunk-SSDQ6NXU.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/invitations/index.ts", "../../../src/invitations/useInvitationStatus.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport {\n AuthenticatingInvitationObservable,\n CancellableInvitationObservable,\n Invitation,\n InvitationEncoder,\n type Invitations,\n InvitationsProxy,\n} from '@dxos/client/invitations';\n\nexport * from './useInvitationStatus';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useCallback, useEffect, useMemo, useReducer } from 'react';\n\nimport { type PublicKey } from '@dxos/client';\nimport {\n type AuthenticatingInvitationObservable,\n type CancellableInvitationObservable,\n Invitation,\n InvitationEncoder,\n} from '@dxos/client/invitations';\nimport { log } from '@dxos/log';\n\nexport type InvitationResult = {\n spaceKey: PublicKey | null;\n identityKey: PublicKey | null;\n swarmKey: PublicKey | null;\n target: string | null;\n};\n\ninterface InvitationReducerState {\n status: Invitation.State; // TODO(burdon): Rename state.\n haltedAt?: Invitation.State;\n result: InvitationResult;\n error?: Error;\n id?: string;\n multiUse?: boolean;\n shareable?: boolean;\n invitationCode?: string;\n authCode?: string;\n authMethod?: Invitation.AuthMethod;\n type?: Invitation.Type;\n}\n\ntype InvitationPayload = { invitation: Invitation };\n\nexport type InvitationAction =\n | ({\n status:\n | Invitation.State.INIT\n | Invitation.State.CONNECTED\n | Invitation.State.READY_FOR_AUTHENTICATION\n | Invitation.State.AUTHENTICATING;\n } & InvitationPayload)\n | ({\n status: Invitation.State.CONNECTING;\n observable: CancellableInvitationObservable;\n } & InvitationPayload)\n | ({\n status: Invitation.State.SUCCESS;\n result: InvitationResult;\n } & InvitationPayload)\n | ({\n status: Invitation.State.CANCELLED | Invitation.State.TIMEOUT;\n haltedAt: Invitation.State;\n } & InvitationPayload)\n | {\n status: Invitation.State.ERROR;\n error?: Error;\n haltedAt: Invitation.State;\n };\n\nexport type InvitationStatus = {\n id?: string;\n invitationCode?: string;\n authCode?: string;\n authMethod?: Invitation.AuthMethod;\n type?: Invitation.Type;\n status: Invitation.State;\n haltedAt?: Invitation.State;\n multiUse?: boolean;\n shareable?: boolean;\n result: InvitationResult;\n error?: Error;\n cancel(): void;\n // TODO(wittjosiah): Remove?\n connect(observable: CancellableInvitationObservable): void;\n authenticate(authCode: string): Promise<void>;\n};\n\n// Without private key, the invitation code cannot be created.\n// These invitations are only available to be accepted but not shared.\nconst isShareableInvitation = (invitation: Invitation) =>\n invitation.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY || !!invitation.guestKeypair?.privateKey;\n\nexport const useInvitationStatus = (observable?: CancellableInvitationObservable): InvitationStatus => {\n const [state, dispatch] = useReducer(\n (prev: InvitationReducerState, action: InvitationAction): InvitationReducerState => {\n log('useInvitationStatus', { action });\n const invitationProps =\n 'invitation' in action\n ? {\n id: action.invitation.invitationId,\n multiUse: action.invitation.multiUse,\n invitationCode: InvitationEncoder.encode(action.invitation),\n authCode: action.invitation.authCode,\n authMethod: action.invitation.authMethod,\n shareable: isShareableInvitation(action.invitation),\n type: action.invitation.type,\n }\n : {};\n return {\n ...prev,\n ...invitationProps,\n // TODO(burdon): State.\n status: action.status,\n // `invitationObservable`, `secret`, and `result` is persisted between the status-actions that set them.\n result: action.status === Invitation.State.SUCCESS ? action.result : prev.result,\n // `error` gets set each time we enter the error state\n ...(action.status === Invitation.State.ERROR && { error: action.error }),\n // `haltedAt` gets set on only the first error/cancelled/timeout action and reset on any others.\n ...((action.status === Invitation.State.ERROR ||\n action.status === Invitation.State.CANCELLED ||\n action.status === Invitation.State.TIMEOUT) && {\n haltedAt: typeof prev.haltedAt === 'undefined' ? action.haltedAt : prev.haltedAt,\n }),\n };\n },\n null,\n (_arg: null): InvitationReducerState => {\n const invitation = observable?.get();\n return {\n status: Invitation.State.INIT,\n result: { spaceKey: null, identityKey: null, swarmKey: null, target: null },\n id: invitation?.invitationId,\n multiUse: invitation?.multiUse,\n invitationCode: invitation ? InvitationEncoder.encode(invitation) : undefined,\n authCode: invitation?.authCode,\n authMethod: invitation?.authMethod,\n shareable: invitation ? isShareableInvitation(invitation) : false,\n type: invitation?.type,\n };\n },\n );\n\n // Handle unmount.\n\n useEffect(() => {\n const update = (invitation: Invitation) => {\n switch (invitation.state) {\n case Invitation.State.INIT:\n case Invitation.State.CONNECTED:\n case Invitation.State.READY_FOR_AUTHENTICATION:\n case Invitation.State.AUTHENTICATING: {\n dispatch({\n invitation,\n status: invitation.state,\n });\n break;\n }\n\n case Invitation.State.SUCCESS: {\n dispatch({\n invitation,\n status: invitation.state,\n result: {\n spaceKey: invitation.spaceKey || null,\n identityKey: invitation.identityKey || null,\n swarmKey: invitation.swarmKey || null,\n target: invitation.target || null,\n },\n });\n break;\n }\n\n case Invitation.State.CANCELLED:\n case Invitation.State.TIMEOUT: {\n dispatch({ invitation, status: invitation.state, haltedAt: state.status });\n break;\n }\n }\n };\n\n const subscription = observable?.subscribe(update, (err: Error) => {\n dispatch({ status: Invitation.State.ERROR, error: err, haltedAt: state.status });\n });\n\n const currentState = observable?.get();\n if (currentState) {\n update(currentState);\n }\n\n return () => subscription?.unsubscribe();\n }, [observable, state.status]);\n\n // Return memoized callbacks & values.\n\n const connect = useCallback((observable: CancellableInvitationObservable) => {\n dispatch({ invitation: observable.get(), status: Invitation.State.CONNECTING, observable });\n }, []);\n\n const authenticate = useCallback(\n (authCode: string) => {\n log('authenticating...', { authCode });\n return (observable as AuthenticatingInvitationObservable).authenticate(authCode);\n },\n [observable],\n );\n\n const cancel = useCallback(async () => observable?.cancel(), [observable]);\n\n return useMemo(() => {\n return {\n ...state,\n cancel,\n connect,\n authenticate,\n };\n }, [state, cancel, connect, authenticate]);\n};\n"],
5
- "mappings": ";AAKA,SAC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A;KAAW;IAGd;;QAAyE,SAAA,YAAA,YAAA,YAAA,OAAA,GAAA;IAEzE;;iBAEOC,MAAK;WACRC;MACAC,GAAAA;MACAC;MACF;MACC;IAACH;;IAAeE;IAASC;IAAa;IACzC;;;",
6
- "names": ["AuthenticatingInvitationObservable", "CancellableInvitationObservable", "Invitation", "InvitationEncoder", "InvitationsProxy", "useCallback", "useEffect", "useMemo", "useReducer", "Invitation", "InvitationEncoder", "log", "prev", "action", "invitationId", "multiUse", "invitation", "invitationCode", "authCode", "authMethod", "shareable", "isShareableInvitation", "type", "invitationProps", "status", "result", "INIT", "spaceKey", "identityKey", "swarmKey", "target", "State", "READY_FOR_AUTHENTICATION", "AUTHENTICATING", "dispatch", "haltedAt", "ERROR", "error", "update", "currentState", "subscription", "observable", "state", "cancel", "connect", "authenticate"]
7
- }