@dxos/plugin-client 0.7.2 → 0.7.3-staging.0905f03

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 (37) hide show
  1. package/dist/lib/browser/{chunk-VCPHSTE7.mjs → chunk-FGUXUNOK.mjs} +3 -1
  2. package/dist/lib/browser/{chunk-VCPHSTE7.mjs.map → chunk-FGUXUNOK.mjs.map} +2 -2
  3. package/dist/lib/browser/index.mjs +112 -25
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/meta.mjs +1 -1
  7. package/dist/lib/node/{chunk-JYQZCE2U.cjs → chunk-XYLDQWFV.cjs} +6 -4
  8. package/dist/lib/node/{chunk-JYQZCE2U.cjs.map → chunk-XYLDQWFV.cjs.map} +2 -2
  9. package/dist/lib/node/index.cjs +124 -40
  10. package/dist/lib/node/index.cjs.map +4 -4
  11. package/dist/lib/node/meta.cjs +5 -5
  12. package/dist/lib/node/meta.cjs.map +1 -1
  13. package/dist/lib/node/meta.json +1 -1
  14. package/dist/lib/node-esm/{chunk-4FDLD5H4.mjs → chunk-C6X363FK.mjs} +3 -1
  15. package/dist/lib/node-esm/{chunk-4FDLD5H4.mjs.map → chunk-C6X363FK.mjs.map} +2 -2
  16. package/dist/lib/node-esm/index.mjs +112 -25
  17. package/dist/lib/node-esm/index.mjs.map +4 -4
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/meta.mjs +1 -1
  20. package/dist/types/src/ClientPlugin.d.ts +0 -7
  21. package/dist/types/src/ClientPlugin.d.ts.map +1 -1
  22. package/dist/types/src/components/IdentityDialog.d.ts.map +1 -1
  23. package/dist/types/src/components/RecoveryCodeDialog.d.ts +6 -0
  24. package/dist/types/src/components/RecoveryCodeDialog.d.ts.map +1 -0
  25. package/dist/types/src/components/index.d.ts +1 -0
  26. package/dist/types/src/components/index.d.ts.map +1 -1
  27. package/dist/types/src/meta.d.ts +3 -1
  28. package/dist/types/src/meta.d.ts.map +1 -1
  29. package/dist/types/src/translations.d.ts +5 -0
  30. package/dist/types/src/translations.d.ts.map +1 -1
  31. package/package.json +13 -13
  32. package/src/ClientPlugin.tsx +34 -18
  33. package/src/components/IdentityDialog.tsx +4 -4
  34. package/src/components/RecoveryCodeDialog.tsx +58 -0
  35. package/src/components/index.ts +1 -0
  36. package/src/meta.ts +2 -0
  37. package/src/translations.ts +7 -0
@@ -5,7 +5,6 @@
5
5
  import React from 'react';
6
6
 
7
7
  import {
8
- filterPlugins,
9
8
  LayoutAction,
10
9
  parseIntentPlugin,
11
10
  resolvePlugin,
@@ -17,14 +16,13 @@ import {
17
16
  type TranslationsProvides,
18
17
  } from '@dxos/app-framework';
19
18
  import { Config, Defaults, Envs, Local, Storage } from '@dxos/config';
20
- import { type AbstractTypedObject } from '@dxos/echo-schema';
21
19
  import { registerSignalsRuntime } from '@dxos/echo-signals/react';
22
- import { log } from '@dxos/log';
20
+ import { invariant } from '@dxos/invariant';
23
21
  import { createExtension, type Node } from '@dxos/plugin-graph';
24
22
  import { Client, type ClientOptions, ClientProvider } from '@dxos/react-client';
25
23
  import { type IdentityPanelProps, type JoinPanelProps } from '@dxos/shell/react';
26
24
 
27
- import { IdentityDialog, JoinDialog } from './components';
25
+ import { IdentityDialog, JoinDialog, RecoveryCodeDialog, type RecoveryCodeDialogProps } from './components';
28
26
  import meta, { CLIENT_PLUGIN, ClientAction, OBSERVABILITY_ACTION } from './meta';
29
27
  import translations from './translations';
30
28
 
@@ -71,15 +69,6 @@ export type ClientPluginProvides = IntentResolverProvides &
71
69
  export const parseClientPlugin = (plugin?: Plugin) =>
72
70
  (plugin?.provides as any).client instanceof Client ? (plugin as Plugin<ClientPluginProvides>) : undefined;
73
71
 
74
- export type SchemaProvides = {
75
- echo: {
76
- schema: AbstractTypedObject[];
77
- };
78
- };
79
-
80
- export const parseSchemaPlugin = (plugin?: Plugin) =>
81
- Array.isArray((plugin?.provides as any).echo?.schema) ? (plugin as Plugin<SchemaProvides>) : undefined;
82
-
83
72
  export const ClientPlugin = ({
84
73
  appKey,
85
74
  invitationUrl = window.location.origin,
@@ -136,11 +125,6 @@ export const ClientPlugin = ({
136
125
  }
137
126
 
138
127
  await onReady?.(client, plugins);
139
-
140
- filterPlugins(plugins, parseSchemaPlugin).forEach((plugin) => {
141
- log('ready', { id: plugin.meta.id });
142
- client.addTypes(plugin.provides.echo.schema);
143
- });
144
128
  },
145
129
  unload: async () => {
146
130
  await client.destroy();
@@ -160,6 +144,8 @@ export const ClientPlugin = ({
160
144
  );
161
145
  } else if (data.component === 'dxos.org/plugin/client/JoinDialog') {
162
146
  return <JoinDialog {...(data.subject as JoinPanelProps)} />;
147
+ } else if (data.component === 'dxos.org/plugin/client/RecoveryCodeDialog') {
148
+ return <RecoveryCodeDialog {...(data.subject as RecoveryCodeDialogProps)} />;
163
149
  }
164
150
  break;
165
151
  }
@@ -292,6 +278,36 @@ export const ClientPlugin = ({
292
278
  await onReset?.({ target: intent.data?.target });
293
279
  return { data: true };
294
280
  }
281
+
282
+ case ClientAction.CREATE_AGENT: {
283
+ invariant(client.services.services.EdgeAgentService, 'Missing EdgeAgentService');
284
+ await client.services.services.EdgeAgentService.createAgent(null as any, { timeout: 10_000 });
285
+ return { data: true };
286
+ }
287
+
288
+ case ClientAction.CREATE_RECOVERY_CODE: {
289
+ invariant(client.services.services.IdentityService, 'IdentityService not available');
290
+ // TODO(wittjosiah): This needs a proper api. Rename property.
291
+ const { seedphrase } = await client.services.services.IdentityService.createRecoveryPhrase();
292
+ return {
293
+ data: true,
294
+ intents: [
295
+ [
296
+ {
297
+ action: LayoutAction.SET_LAYOUT,
298
+ data: {
299
+ element: 'dialog',
300
+ dialogBlockAlign: 'start',
301
+ dialogType: 'alert',
302
+ state: true,
303
+ component: 'dxos.org/plugin/client/RecoveryCodeDialog',
304
+ subject: { code: seedphrase },
305
+ },
306
+ },
307
+ ],
308
+ ],
309
+ };
310
+ }
295
311
  }
296
312
  },
297
313
  },
@@ -6,8 +6,8 @@ import React, { useCallback } from 'react';
6
6
 
7
7
  import { LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
8
8
  import { useClient } from '@dxos/react-client';
9
- import { Dialog } from '@dxos/react-ui';
10
- import { ClipboardProvider, IdentityPanel, type IdentityPanelProps } from '@dxos/shell/react';
9
+ import { Clipboard, Dialog } from '@dxos/react-ui';
10
+ import { IdentityPanel, type IdentityPanelProps } from '@dxos/shell/react';
11
11
 
12
12
  import { ClientAction } from '../meta';
13
13
 
@@ -44,7 +44,7 @@ export const IdentityDialog = (props: IdentityPanelProps) => {
44
44
 
45
45
  return (
46
46
  <Dialog.Content>
47
- <ClipboardProvider>
47
+ <Clipboard.Provider>
48
48
  <IdentityPanel
49
49
  {...props}
50
50
  doneActionParent={<Dialog.Close asChild />}
@@ -53,7 +53,7 @@ export const IdentityDialog = (props: IdentityPanelProps) => {
53
53
  onRecover={handleRecover}
54
54
  onJoinNewIdentity={handleJoinNewIdentity}
55
55
  />
56
- </ClipboardProvider>
56
+ </Clipboard.Provider>
57
57
  </Dialog.Content>
58
58
  );
59
59
  };
@@ -0,0 +1,58 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useState } from 'react';
6
+
7
+ import { AlertDialog, Button, Clipboard, Input, useTranslation } from '@dxos/react-ui';
8
+
9
+ import { CLIENT_PLUGIN } from '../meta';
10
+
11
+ export type RecoveryCodeDialogProps = {
12
+ code: string;
13
+ };
14
+
15
+ export const RecoveryCodeDialog = ({ code }: RecoveryCodeDialogProps) => {
16
+ const { t } = useTranslation(CLIENT_PLUGIN);
17
+ const [confirmation, setConfirmation] = useState(false);
18
+
19
+ const handleConfirmation = useCallback((checked: boolean) => setConfirmation(checked), []);
20
+
21
+ return (
22
+ <AlertDialog.Content classNames='bs-content min-bs-[15rem] max-bs-full md:max-is-[40rem] overflow-hidden'>
23
+ <AlertDialog.Title classNames=''>{t('recovery code dialog title')}</AlertDialog.Title>
24
+ <p className='py-4'>{t('recovery code dialog description')}</p>
25
+ <Clipboard.Provider>
26
+ <Code value={code} />
27
+ </Clipboard.Provider>
28
+ <p className='py-4'>{t('recovery code dialog warning')}</p>
29
+ <div className='flex items-center gap-2 pbe-4'>
30
+ <Input.Root>
31
+ <Input.Checkbox
32
+ data-testid='recoveryCode.confirm'
33
+ checked={confirmation}
34
+ onCheckedChange={handleConfirmation}
35
+ />
36
+ <Input.Label>{t('recovery code confirmation label')}</Input.Label>
37
+ </Input.Root>
38
+ </div>
39
+ <div className='flex justify-end'>
40
+ <AlertDialog.Action asChild>
41
+ <Button data-testid='recoveryCode.continue' variant='primary' disabled={!confirmation}>
42
+ {t('continue label')}
43
+ </Button>
44
+ </AlertDialog.Action>
45
+ </div>
46
+ </AlertDialog.Content>
47
+ );
48
+ };
49
+
50
+ // TODO(wittjosiah): Factor out.
51
+ const Code = ({ value }: { value: string }) => {
52
+ return (
53
+ <div className='relative p-2 border border-separator rounded group'>
54
+ <Clipboard.IconButton value={value} classNames='absolute top-2 right-2 invisible group-hover:visible' />
55
+ <code className='whitespace-pre-wrap'>{value}</code>
56
+ </div>
57
+ );
58
+ };
@@ -4,3 +4,4 @@
4
4
 
5
5
  export * from './IdentityDialog';
6
6
  export * from './JoinDialog';
7
+ export * from './RecoveryCodeDialog';
package/src/meta.ts CHANGED
@@ -18,6 +18,8 @@ export enum ClientAction {
18
18
  SHARE_IDENTITY = `${CLIENT_ACTION}/SHARE_IDENTITY`,
19
19
  RECOVER_IDENTITY = `${CLIENT_ACTION}/RECOVER_IDENTITY`,
20
20
  RESET_STORAGE = `${CLIENT_ACTION}/RESET_STORAGE`,
21
+ CREATE_AGENT = `${CLIENT_ACTION}/CREATE_AGENT`,
22
+ CREATE_RECOVERY_CODE = `${CLIENT_ACTION}/CREATE_RECOVERY_CODE`,
21
23
  }
22
24
 
23
25
  // NOTE: This action is hardcoded to avoid circular dependency with observability plugin.
@@ -9,6 +9,13 @@ export default [
9
9
  'en-US': {
10
10
  [CLIENT_PLUGIN]: {
11
11
  'open shell label': 'Open HALO',
12
+ 'recovery code dialog title': 'Recovery Code',
13
+ 'recovery code dialog description':
14
+ 'This is your identity recovery code, store it in a safe place. You can use it to recover your identity if you ever lose access to your devices.',
15
+ 'recovery code dialog warning':
16
+ 'Please note: This code will not be displayed again and cannot be replaced. It is your private key for recovering DXOS data. Anyone with this key will also be able to gain access to your account.',
17
+ 'recovery code confirmation label': 'Confirm the code has been saved',
18
+ 'continue label': 'Continue',
12
19
  },
13
20
  },
14
21
  },