@dxos/react-client 0.7.4 → 0.7.5-labs.071a3e2
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/dist/lib/browser/{chunk-U4MCIYKN.mjs → chunk-LVTCEDI2.mjs} +68 -49
- package/dist/lib/browser/chunk-LVTCEDI2.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +1 -1
- package/dist/lib/browser/devtools/index.mjs.map +1 -1
- package/dist/lib/browser/echo/index.mjs +1 -1
- package/dist/lib/browser/halo/index.mjs +15 -7
- package/dist/lib/browser/halo/index.mjs.map +4 -4
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/mesh/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +32 -33
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-UJLDNXPC.cjs → chunk-Y2HFUT7P.cjs} +71 -52
- package/dist/lib/node/chunk-Y2HFUT7P.cjs.map +7 -0
- package/dist/lib/node/devtools/index.cjs +2 -2
- package/dist/lib/node/devtools/index.cjs.map +1 -1
- package/dist/lib/node/echo/index.cjs +3 -3
- package/dist/lib/node/halo/index.cjs +16 -9
- package/dist/lib/node/halo/index.cjs.map +4 -4
- package/dist/lib/node/index.cjs +12 -12
- package/dist/lib/node/mesh/index.cjs +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +61 -63
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/{chunk-4J4SI7XJ.mjs → chunk-MXY3GJGN.mjs} +68 -49
- package/dist/lib/node-esm/chunk-MXY3GJGN.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +1 -1
- package/dist/lib/node-esm/devtools/index.mjs.map +1 -1
- package/dist/lib/node-esm/echo/index.mjs +1 -1
- package/dist/lib/node-esm/halo/index.mjs +15 -7
- package/dist/lib/node-esm/halo/index.mjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/mesh/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +32 -33
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/devtools/useStream.d.ts +1 -1
- package/dist/types/src/devtools/useStream.d.ts.map +1 -1
- package/dist/types/src/halo/Passkey.stories.d.ts +11 -0
- package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -0
- package/dist/types/src/halo/index.d.ts +1 -0
- package/dist/types/src/halo/index.d.ts.map +1 -1
- package/dist/types/src/halo/useCredentials.d.ts +3 -0
- package/dist/types/src/halo/useCredentials.d.ts.map +1 -0
- package/dist/types/src/testing/ClientRepeater.d.ts +2 -2
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/context.d.ts +7 -0
- package/dist/types/src/testing/context.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts +4 -8
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +23 -23
- package/src/client/ClientProvider.test.tsx +3 -2
- package/src/client/ClientProvider.tsx +35 -20
- package/src/devtools/useStream.ts +1 -1
- package/src/halo/Passkey.stories.tsx +151 -0
- package/src/halo/index.ts +1 -0
- package/src/halo/useCredentials.ts +13 -0
- package/src/testing/ClientRepeater.tsx +3 -3
- package/src/testing/context.tsx +19 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/withClientProvider.tsx +37 -39
- package/tsconfig.json +61 -2
- package/dist/lib/browser/chunk-U4MCIYKN.mjs.map +0 -7
- package/dist/lib/node/chunk-UJLDNXPC.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-4J4SI7XJ.mjs.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/testing/index.ts", "../../../../src/testing/ClientRepeater.tsx", "../../../../src/testing/withClientProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/testing';\n\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, { useState, type FC, useEffect, useRef } from 'react';\n\nimport { Client, type PublicKey } from '@dxos/client';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { type AbstractTypedObject } from '@dxos/echo-schema';\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { faker } from '@dxos/random';\n\nimport { type WithClientProviderProps } from './withClientProvider';\nimport { ClientProvider } from '../client';\n\nexport type ClientRepeatedComponentProps = { id: number; count: number; spaceKey?: PublicKey };\n\nexport type ClientRepeaterControlsProps = { clients: Client[] };\n\n// TODO(burdon): Reconcile with ClientProviderProps.\nexport type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {\n className?: string;\n component: FC<ClientRepeatedComponentProps>;\n controls?: FC<ClientRepeaterControlsProps>;\n count?: number;\n clients?: Client[];\n types?: AbstractTypedObject[];\n args?: Omit<P, 'id' | 'count'>;\n} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;\n\n/**\n * Utility component for Storybook stories which sets up clients for n peers.\n * The `Component` property is rendered n times, once for each peer.\n * @deprecated use `withClientProvider`.\n */\n// TODO(burdon): To discuss: evolve ClientRepeater with optional decorator that uses it.\n// NOTE: This is specifically not a storybook decorator because it broke stories as a decorator.\n// This seems primarily due to the fact that it required top-level await for the clients to initialize.\n// Storybook seemed to handle it alright, but Chromatic had a lot of trouble with it.\n// There was also a question of whether or not calling the story function multiple times was a good idea.\nexport const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => {\n const {\n component: Component,\n controls: Controls,\n count = 1,\n types,\n createIdentity,\n createSpace,\n onSpaceCreated,\n } = props;\n useEffect(() => {\n registerSignalsRuntime();\n }, []);\n\n const [clients, setClients] = useState(props.clients ?? []);\n const [spaceKey, setSpaceKey] = useState<PublicKey>();\n\n const testBuilder = useRef(new TestBuilder());\n useEffect(() => {\n const timeout = setTimeout(async () => {\n const clients = [...Array(count)].map(\n (_) => new Client({ services: testBuilder.current.createLocalClientServices(), types }),\n );\n\n await Promise.all(clients.map((client) => client.initialize()));\n if (createIdentity || createSpace) {\n await Promise.all(clients.map((client) => client.halo.createIdentity()));\n }\n\n if (createSpace) {\n const client = clients[0];\n const space = await client.spaces.create({ name: faker.commerce.productName() });\n setSpaceKey(space.key);\n await onSpaceCreated?.({ client, space });\n await Promise.all(\n clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })),\n );\n }\n\n setClients(clients);\n });\n\n return () => clearTimeout(timeout);\n }, []);\n\n if (clients.length === 0) {\n return null;\n }\n\n return (\n <>\n {Controls && <Controls clients={clients} />}\n {clients.map((client, index) => (\n <ClientProvider key={index} client={client}>\n <Component id={index} count={clients.length} spaceKey={spaceKey} {...{ ...props.args }} />\n </ClientProvider>\n ))}\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport React, { createContext, type PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';\nimport { type FallbackProps, ErrorBoundary as NativeErrorBoundary } from 'react-error-boundary';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { performInvitation, TestBuilder } from '@dxos/client/testing';\nimport { raise } from '@dxos/debug';\nimport { log } from '@dxos/log';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientProvider, type ClientProviderProps } from '../client';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<Record<string, any> | void>;\n onIdentityCreated?: (props: { client: Client }) => MaybePromise<Record<string, any> | void>;\n onSpaceCreated?: (props: { client: Client; space: Space }) => MaybePromise<Record<string, any> | void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onSpaceCreated, onIdentityCreated, onInitialized }: InitializeProps,\n): Promise<StoryClientProps> => {\n const clientData = await onInitialized?.(client);\n\n let identityData: Record<string, any> | void = {};\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n identityData = await onIdentityCreated?.({ client });\n }\n }\n\n let space: Space | undefined;\n let spaceData: Record<string, any> | void = {};\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n spaceData = await onSpaceCreated?.({ client, space });\n }\n\n return { space, ...clientData, ...identityData, ...spaceData };\n};\n\ntype StoryClientProps<T extends Record<string, any> = Record<string, unknown>> = T & { space?: Space };\n\n// TODO(wittjosiah): Add to multi-client as well.\nconst StoryClientContext = createContext<StoryClientProps | undefined>(undefined);\n\nexport const useStoryClientData = <T extends Record<string, any> = Record<string, unknown>>() => {\n const data = useContext(StoryClientContext) ?? raise(new Error('Missing withClientProvider decorator.'));\n return data as StoryClientProps<T>;\n};\n\nexport type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;\n\n/**\n * Decorator that provides the client context.\n */\nexport const withClientProvider = ({\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story) => {\n const [data, setData] = useState<StoryClientProps>({});\n\n const handleInitialized = async (client: Client) => {\n setData(\n await initializeClient(client, {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n }),\n );\n };\n\n return (\n <ErrorBoundary>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <StoryClientContext.Provider value={data}>\n <Story />\n </StoryClientContext.Provider>\n </ClientProvider>\n </ErrorBoundary>\n );\n };\n};\n\n// TODO(burdon): Implement context per client for context.\n// TODO(burdon): Callback once all invitations have completed.\n// TODO(burdon): Delay/jitter for creation of other clients.\nexport type WithMultiClientProviderProps = InitializeProps &\n Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };\n\nconst MultiClientContext = createContext<{ id: number }>({ id: 0 });\n\nexport const useMultiClient = () => useContext(MultiClientContext);\n\n/**\n * Decorator that creates a scaffold for multiple clients.\n * Orchestrates invitations between a randomly selected host and the remaining clients.\n * NOTE: Should come before withLayout.\n */\nexport const withMultiClientProvider = ({\n numClients = 2,\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story) => {\n const builder = useRef(new TestBuilder());\n const hostRef = useRef<Client>();\n const spaceReady = useRef(new Trigger<Space | undefined>());\n\n // Handle invitations.\n // NOTE: The zeroth client isn't necessarily the first to be initialized.\n const handleInitialized = async (client: Client, index: number) => {\n log.info('initialized', { index });\n if (createSpace) {\n if (!hostRef.current) {\n hostRef.current = client;\n const { space } = await initializeClient(client, {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n });\n spaceReady.current.wake(space);\n log.info('inviting', { index });\n } else {\n await initializeClient(client, { createIdentity, onInitialized });\n const space = await spaceReady.current.wait();\n if (space) {\n log.info('joining', { index });\n await Promise.all(performInvitation({ host: space, guest: client.spaces }));\n }\n }\n }\n };\n\n return (\n <ErrorBoundary>\n {Array.from({ length: numClients }).map((_, index) => (\n <MultiClientContext.Provider key={index} value={{ id: index }}>\n <ClientProvider\n services={builder.current.createLocalClientServices()}\n onInitialized={(client) => handleInitialized(client, index)}\n {...props}\n >\n <Story />\n </ClientProvider>\n </MultiClientContext.Provider>\n ))}\n </ErrorBoundary>\n );\n };\n};\n\nconst ErrorBoundary = ({ children }: PropsWithChildren) => {\n const [error, setError] = useState<Error>();\n useEffect(() => {\n const handleError = (event: PromiseRejectionEvent) => {\n setError(event.reason);\n };\n\n window.addEventListener('unhandledrejection', handleError);\n return () => window.removeEventListener('unhandledrejection', handleError);\n }, []);\n\n if (error) {\n return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;\n }\n\n return <NativeErrorBoundary FallbackComponent={ErrorFallback}>{children}</NativeErrorBoundary>;\n};\n\nconst ErrorFallback = ({ error }: FallbackProps) => {\n const { name, message, stack } =\n error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };\n return (\n <div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>\n <h1 className='text-xl text-red-500'>{name}</h1>\n <div className='text-lg'>{message}</div>\n {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,cAAc;;;ACAd,
|
|
6
|
-
"names": ["React", "useState", "useEffect", "useRef", "Client", "TestBuilder", "performInvitation", "registerSignalsRuntime", "faker", "ClientRepeater", "props", "component", "Component", "controls", "Controls", "count", "types", "createIdentity", "createSpace", "onSpaceCreated", "useEffect", "registerSignalsRuntime", "clients", "setClients", "useState", "spaceKey", "setSpaceKey", "testBuilder", "useRef", "TestBuilder", "timeout", "setTimeout", "Array", "map", "_", "Client", "services", "current", "createLocalClientServices", "Promise", "all", "client", "initialize", "halo", "space", "spaces", "create", "name", "faker", "commerce", "productName", "key", "slice", "flatMap", "performInvitation", "host", "guest", "clearTimeout", "length", "index", "ClientProvider", "id", "args", "React", "createContext", "useContext", "useEffect", "useRef", "useState", "ErrorBoundary", "NativeErrorBoundary", "Trigger", "performInvitation", "TestBuilder", "
|
|
3
|
+
"sources": ["../../../../src/testing/index.ts", "../../../../src/testing/context.tsx", "../../../../src/testing/ClientRepeater.tsx", "../../../../src/testing/withClientProvider.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/testing';\n\nexport * from './context';\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext, useContext } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\n\nexport type ClientStory = {\n space?: Space;\n};\n\n// TODO(wittjosiah): Add to multi-client as well.\nexport const ClientStory = createContext<ClientStory | undefined>(undefined);\n\nexport const useClientProvider = (): ClientStory => {\n return useContext(ClientStory) ?? raise(new Error('Missing ClientStory'));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, { useState, type FC, useEffect, useRef } from 'react';\n\nimport { Client, type PublicKey } from '@dxos/client';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { type TypedObject } from '@dxos/echo-schema';\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { faker } from '@dxos/random';\n\nimport { type WithClientProviderProps } from './withClientProvider';\nimport { ClientProvider } from '../client';\n\nexport type ClientRepeatedComponentProps = { id: number; count: number; spaceKey?: PublicKey };\n\nexport type ClientRepeaterControlsProps = { clients: Client[] };\n\n// TODO(burdon): Reconcile with ClientProviderProps.\nexport type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {\n className?: string;\n component: FC<ClientRepeatedComponentProps>;\n controls?: FC<ClientRepeaterControlsProps>;\n count?: number;\n clients?: Client[];\n types?: TypedObject[];\n args?: Omit<P, 'id' | 'count'>;\n} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;\n\n/**\n * Utility component for Storybook stories which sets up clients for n peers.\n * The `Component` property is rendered n times, once for each peer.\n * @deprecated use `withClientProvider`.\n */\n// TODO(burdon): To discuss: evolve ClientRepeater with optional decorator that uses it.\n// NOTE: This is specifically not a storybook decorator because it broke stories as a decorator.\n// This seems primarily due to the fact that it required top-level await for the clients to initialize.\n// Storybook seemed to handle it alright, but Chromatic had a lot of trouble with it.\n// There was also a question of whether or not calling the story function multiple times was a good idea.\nexport const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => {\n const {\n component: Component,\n controls: Controls,\n count = 1,\n types,\n createIdentity,\n createSpace,\n onSpaceCreated,\n } = props;\n useEffect(() => {\n registerSignalsRuntime();\n }, []);\n\n const [clients, setClients] = useState(props.clients ?? []);\n const [spaceKey, setSpaceKey] = useState<PublicKey>();\n\n const testBuilder = useRef(new TestBuilder());\n useEffect(() => {\n const timeout = setTimeout(async () => {\n const clients = [...Array(count)].map(\n (_) => new Client({ services: testBuilder.current.createLocalClientServices(), types }),\n );\n\n await Promise.all(clients.map((client) => client.initialize()));\n if (createIdentity || createSpace) {\n await Promise.all(clients.map((client) => client.halo.createIdentity()));\n }\n\n if (createSpace) {\n const client = clients[0];\n const space = await client.spaces.create({ name: faker.commerce.productName() });\n setSpaceKey(space.key);\n await onSpaceCreated?.({ client, space }, {});\n await Promise.all(\n clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })),\n );\n }\n\n setClients(clients);\n });\n\n return () => clearTimeout(timeout);\n }, []);\n\n if (clients.length === 0) {\n return null;\n }\n\n return (\n <>\n {Controls && <Controls clients={clients} />}\n {clients.map((client, index) => (\n <ClientProvider key={index} client={client}>\n <Component id={index} count={clients.length} spaceKey={spaceKey} {...{ ...props.args }} />\n </ClientProvider>\n ))}\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type StoryContext, type Decorator } from '@storybook/react';\nimport React, { createContext, type PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';\nimport { type FallbackProps, ErrorBoundary as NativeErrorBoundary } from 'react-error-boundary';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { performInvitation, TestBuilder } from '@dxos/client/testing';\nimport { log } from '@dxos/log';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientStory } from './context';\nimport { ClientProvider, type ClientProviderProps } from '../client';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<void>;\n onIdentityCreated?: (props: { client: Client }) => MaybePromise<void>;\n // NOTE: context must be untyped until ClientRepeater is removed.\n onSpaceCreated?: (props: { client: Client; space: Space }, context: StoryContext | any) => MaybePromise<void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onSpaceCreated, onIdentityCreated, onInitialized }: InitializeProps,\n context: StoryContext,\n): Promise<ClientStory> => {\n await onInitialized?.(client);\n\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n await onIdentityCreated?.({ client });\n }\n }\n\n let space: Space | undefined;\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n await onSpaceCreated?.({ client, space }, context);\n }\n\n return { space };\n};\n\nexport type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;\n\n/**\n * Decorator that provides the client context.\n */\nexport const withClientProvider = ({\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story, context) => {\n const [data, setData] = useState<ClientStory>({});\n const handleInitialized = async (client: Client) => {\n const data = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n },\n context,\n );\n\n setData(data);\n };\n\n return (\n <ErrorBoundary>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <ClientStory.Provider value={data}>\n <Story />\n </ClientStory.Provider>\n </ClientProvider>\n </ErrorBoundary>\n );\n };\n};\n\n// TODO(burdon): Implement context per client for context.\n// TODO(burdon): Callback once all invitations have completed.\n// TODO(burdon): Delay/jitter for creation of other clients.\nexport type WithMultiClientProviderProps = InitializeProps &\n Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };\n\nconst MultiClientContext = createContext<{ id: number }>({ id: 0 });\n\nexport const useMultiClient = () => useContext(MultiClientContext);\n\n/**\n * Decorator that creates a scaffold for multiple clients.\n * Orchestrates invitations between a randomly selected host and the remaining clients.\n * NOTE: Should come before withLayout.\n */\nexport const withMultiClientProvider = ({\n numClients = 2,\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story, context) => {\n const builder = useRef(new TestBuilder());\n const hostRef = useRef<Client>();\n const spaceReady = useRef(new Trigger<Space | undefined>());\n\n // Handle invitations.\n // NOTE: The zeroth client isn't necessarily the first to be initialized.\n const handleInitialized = async (client: Client, index: number) => {\n log.info('initialized', { index });\n if (createSpace) {\n if (!hostRef.current) {\n hostRef.current = client;\n const { space } = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n },\n context,\n );\n\n spaceReady.current.wake(space);\n log.info('inviting', { index });\n } else {\n await initializeClient(client, { createIdentity, onInitialized }, context);\n const space = await spaceReady.current.wait();\n if (space) {\n log.info('joining', { index });\n await Promise.all(performInvitation({ host: space, guest: client.spaces }));\n }\n }\n }\n };\n\n return (\n <ErrorBoundary>\n {Array.from({ length: numClients }).map((_, index) => (\n <MultiClientContext.Provider key={index} value={{ id: index }}>\n <ClientProvider\n services={builder.current.createLocalClientServices()}\n onInitialized={(client) => handleInitialized(client, index)}\n {...props}\n >\n <Story />\n </ClientProvider>\n </MultiClientContext.Provider>\n ))}\n </ErrorBoundary>\n );\n };\n};\n\nconst ErrorBoundary = ({ children }: PropsWithChildren) => {\n const [error, setError] = useState<Error>();\n useEffect(() => {\n const handleError = (event: PromiseRejectionEvent) => {\n setError(event.reason);\n };\n\n window.addEventListener('unhandledrejection', handleError);\n return () => window.removeEventListener('unhandledrejection', handleError);\n }, []);\n\n if (error) {\n return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;\n }\n\n return <NativeErrorBoundary FallbackComponent={ErrorFallback}>{children}</NativeErrorBoundary>;\n};\n\nconst ErrorFallback = ({ error }: FallbackProps) => {\n const { name, message, stack } =\n error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };\n return (\n <div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>\n <h1 className='text-xl text-red-500'>{name}</h1>\n <div className='text-lg'>{message}</div>\n {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,cAAc;;;ACAd,SAASA,eAAeC,kBAAkB;AAG1C,SAASC,aAAa;AAOf,IAAMC,cAAcC,8BAAuCC,MAAAA;AAE3D,IAAMC,oBAAoB,MAAA;AAC/B,SAAOC,WAAWJ,WAAAA,KAAgBK,MAAM,IAAIC,MAAM,qBAAA,CAAA;AACpD;;;ACdA,OAAOC,SAASC,UAAmBC,WAAWC,cAAc;AAE5D,SAASC,cAA8B;AACvC,SAASC,aAAaC,yBAAyB;AAE/C,SAASC,8BAA8B;AACvC,SAASC,aAAa;AA8Bf,IAAMC,iBAAiB,CAAyCC,UAAAA;AACrE,QAAM,EACJC,WAAWC,WACXC,UAAUC,UACVC,QAAQ,GACRC,OACAC,gBACAC,aACAC,eAAc,IACZT;AACJU,YAAU,MAAA;AACRC,2BAAAA;EACF,GAAG,CAAA,CAAE;AAEL,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAASd,MAAMY,WAAW,CAAA,CAAE;AAC1D,QAAM,CAACG,UAAUC,WAAAA,IAAeF,SAAAA;AAEhC,QAAMG,cAAcC,OAAO,IAAIC,YAAAA,CAAAA;AAC/BT,YAAU,MAAA;AACR,UAAMU,UAAUC,WAAW,YAAA;AACzB,YAAMT,WAAU;WAAIU,MAAMjB,KAAAA;QAAQkB,IAChC,CAACC,MAAM,IAAIC,OAAO;QAAEC,UAAUT,YAAYU,QAAQC,0BAAyB;QAAItB;MAAM,CAAA,CAAA;AAGvF,YAAMuB,QAAQC,IAAIlB,SAAQW,IAAI,CAACQ,WAAWA,OAAOC,WAAU,CAAA,CAAA;AAC3D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AAAA,CAAAA,CAAAA,CAAAA;EAMb;AACF;AAEA,IAAMM,gBAAgB,CAAC,EAAEqC,SAAQ,MAAqB;AACpD,QAAM,CAACC,OAAOC,QAAAA,IAAY1C,UAAAA;AAC1B2C,EAAAA,WAAU,MAAA;AACR,UAAMC,cAAc,CAACC,UAAAA;AACnBH,eAASG,MAAMC,MAAM;IACvB;AAEAC,WAAOC,iBAAiB,sBAAsBJ,WAAAA;AAC9C,WAAO,MAAMG,OAAOE,oBAAoB,sBAAsBL,WAAAA;EAChE,GAAG,CAAA,CAAE;AAEL,MAAIH,OAAO;AACT,WAAO,gBAAAvC,OAAA,cAACgD,eAAAA;MAAcT;MAAcU,oBAAoB,MAAMT,SAASU,MAAAA;;EACzE;AAEA,SAAO,gBAAAlD,OAAA,cAACmD,qBAAAA;IAAoBC,mBAAmBJ;KAAgBV,QAAAA;AACjE;AAEA,IAAMU,gBAAgB,CAAC,EAAET,MAAK,MAAiB;AAC7C,QAAM,EAAE/C,MAAM6D,SAASC,MAAK,IAC1Bf,iBAAiBgB,QAAQhB,QAAQ;IAAE/C,MAAM;IAAS6D,SAASG,OAAOjB,KAAAA;IAAQe,OAAOJ;EAAU;AAC7F,SACE,gBAAAlD,OAAA,cAACyD,OAAAA;IAAIC,MAAK;IAAQC,WAAU;KAC1B,gBAAA3D,OAAA,cAAC4D,MAAAA;IAAGD,WAAU;KAAwBnE,IAAAA,GACtC,gBAAAQ,OAAA,cAACyD,OAAAA;IAAIE,WAAU;KAAWN,OAAAA,GACzBC,SAAS,gBAAAtD,OAAA,cAAC6D,OAAAA;IAAIF,WAAU;KAA4CL,KAAAA,CAAAA;AAG3E;",
|
|
6
|
+
"names": ["createContext", "useContext", "raise", "ClientStory", "createContext", "undefined", "useClientProvider", "useContext", "raise", "Error", "React", "useState", "useEffect", "useRef", "Client", "TestBuilder", "performInvitation", "registerSignalsRuntime", "faker", "ClientRepeater", "props", "component", "Component", "controls", "Controls", "count", "types", "createIdentity", "createSpace", "onSpaceCreated", "useEffect", "registerSignalsRuntime", "clients", "setClients", "useState", "spaceKey", "setSpaceKey", "testBuilder", "useRef", "TestBuilder", "timeout", "setTimeout", "Array", "map", "_", "Client", "services", "current", "createLocalClientServices", "Promise", "all", "client", "initialize", "halo", "space", "spaces", "create", "name", "faker", "commerce", "productName", "key", "slice", "flatMap", "performInvitation", "host", "guest", "clearTimeout", "length", "index", "ClientProvider", "id", "args", "React", "createContext", "useContext", "useEffect", "useRef", "useState", "ErrorBoundary", "NativeErrorBoundary", "Trigger", "performInvitation", "TestBuilder", "log", "initializeClient", "client", "createIdentity", "createSpace", "onSpaceCreated", "onIdentityCreated", "onInitialized", "context", "halo", "identity", "get", "space", "spaces", "create", "name", "withClientProvider", "props", "Story", "data", "setData", "useState", "handleInitialized", "React", "ErrorBoundary", "ClientProvider", "ClientStory", "Provider", "value", "MultiClientContext", "createContext", "id", "useMultiClient", "useContext", "withMultiClientProvider", "numClients", "builder", "useRef", "TestBuilder", "hostRef", "spaceReady", "Trigger", "index", "log", "info", "current", "wake", "wait", "Promise", "all", "performInvitation", "host", "guest", "Array", "from", "length", "map", "_", "key", "services", "createLocalClientServices", "children", "error", "setError", "useEffect", "handleError", "event", "reason", "window", "addEventListener", "removeEventListener", "ErrorFallback", "resetErrorBoundary", "undefined", "NativeErrorBoundary", "FallbackComponent", "message", "stack", "Error", "String", "div", "role", "className", "h1", "pre"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/ClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAEZ,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAIvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,sBAAsB,EAAgB,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,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,kBAAkB,CAAC,CAAC,CAAC;IAE1D;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,cAAc;IAjDvB;;;;OAIG;aACM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;;OAIG;aAEM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;;OAIG;eAEQ,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,YAAY,CAAC,sBAAsB,CAAC,CAAC;IAE/F;;OAEG;eACQ,iBAAiB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEzD;;;OAGG;qBACc,OAAO;IAExB;;OAEG;eACQ,OAAO;IAElB;;OAEG;oBACa,CAAC,MAAM,EAAE,MAAM,KAAK,YAAY,CAAC,IAAI,CAAC;;;4CA2HzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStream.d.ts","sourceRoot":"","sources":["../../../../src/devtools/useStream.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useStream.d.ts","sourceRoot":"","sources":["../../../../src/devtools/useStream.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAG1D;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,iBAAiB,MAAM,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,SAAQ,cAAc,KAAQ,CAmBzG,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '@dxos-theme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
title: string;
|
|
5
|
+
render: () => React.JSX.Element;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare const Default: {
|
|
9
|
+
decorators: import("@storybook/react/*").Decorator[];
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=Passkey.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Passkey.stories.d.ts","sourceRoot":"","sources":["../../../../src/halo/Passkey.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAsB,MAAM,OAAO,CAAC;;;;;AAqH3C,wBAGE;AAsBF,eAAO,MAAM,OAAO;;CAEnB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { type Credential, type Contact, type Identity, type Halo, Device, DeviceKind, DeviceType, } from '@dxos/client/halo';
|
|
2
2
|
export * from './useContacts';
|
|
3
|
+
export * from './useCredentials';
|
|
3
4
|
export * from './useDevices';
|
|
4
5
|
export * from './useHaloInvitations';
|
|
5
6
|
export * from './useIdentity';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/halo/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,IAAI,EACT,MAAM,EACN,UAAU,EACV,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/halo/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,IAAI,EACT,MAAM,EACN,UAAU,EACV,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCredentials.d.ts","sourceRoot":"","sources":["../../../../src/halo/useCredentials.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,eAAO,MAAM,cAAc,QAAO,UAAU,EAG3C,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { type FC } from 'react';
|
|
2
2
|
import { Client, type PublicKey } from '@dxos/client';
|
|
3
|
-
import { type
|
|
3
|
+
import { type TypedObject } from '@dxos/echo-schema';
|
|
4
4
|
import { type WithClientProviderProps } from './withClientProvider';
|
|
5
5
|
export type ClientRepeatedComponentProps = {
|
|
6
6
|
id: number;
|
|
@@ -16,7 +16,7 @@ export type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {
|
|
|
16
16
|
controls?: FC<ClientRepeaterControlsProps>;
|
|
17
17
|
count?: number;
|
|
18
18
|
clients?: Client[];
|
|
19
|
-
types?:
|
|
19
|
+
types?: TypedObject[];
|
|
20
20
|
args?: Omit<P, 'id' | 'count'>;
|
|
21
21
|
} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;
|
|
22
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientRepeater.d.ts","sourceRoot":"","sources":["../../../../src/testing/ClientRepeater.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AAC,CAAC;AAEvF;;;;GAIG;AAMH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,4BAA4B,SAAS,mBAAmB,CAAC,CAAC,CAAC,6BA2DnG,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Space } from '@dxos/client/echo';
|
|
2
|
+
export type ClientStory = {
|
|
3
|
+
space?: Space;
|
|
4
|
+
};
|
|
5
|
+
export declare const ClientStory: import("react").Context<ClientStory | undefined>;
|
|
6
|
+
export declare const useClientProvider: () => ClientStory;
|
|
7
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/testing/context.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAGF,eAAO,MAAM,WAAW,kDAAoD,CAAC;AAE7E,eAAO,MAAM,iBAAiB,QAAO,WAEpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AAErC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AAErC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Decorator } from '@storybook/react';
|
|
1
|
+
import { type StoryContext, type Decorator } from '@storybook/react';
|
|
2
2
|
import { type Client } from '@dxos/client';
|
|
3
3
|
import { type Space } from '@dxos/client/echo';
|
|
4
4
|
import { type MaybePromise } from '@dxos/util';
|
|
@@ -6,19 +6,15 @@ import { type ClientProviderProps } from '../client';
|
|
|
6
6
|
type InitializeProps = {
|
|
7
7
|
createIdentity?: boolean;
|
|
8
8
|
createSpace?: boolean;
|
|
9
|
-
onInitialized?: (client: Client) => MaybePromise<
|
|
9
|
+
onInitialized?: (client: Client) => MaybePromise<void>;
|
|
10
10
|
onIdentityCreated?: (props: {
|
|
11
11
|
client: Client;
|
|
12
|
-
}) => MaybePromise<
|
|
12
|
+
}) => MaybePromise<void>;
|
|
13
13
|
onSpaceCreated?: (props: {
|
|
14
14
|
client: Client;
|
|
15
15
|
space: Space;
|
|
16
|
-
}) => MaybePromise<
|
|
16
|
+
}, context: StoryContext | any) => MaybePromise<void>;
|
|
17
17
|
};
|
|
18
|
-
type StoryClientProps<T extends Record<string, any> = Record<string, unknown>> = T & {
|
|
19
|
-
space?: Space;
|
|
20
|
-
};
|
|
21
|
-
export declare const useStoryClientData: <T extends Record<string, any> = Record<string, unknown>>() => StoryClientProps<T>;
|
|
22
18
|
export type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;
|
|
23
19
|
/**
|
|
24
20
|
* Decorator that provides the client context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"withClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKrE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,EAAE,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"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -77,40 +77,40 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"react-error-boundary": "^4.0.13",
|
|
80
|
-
"@dxos/
|
|
81
|
-
"@dxos/
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/debug": "0.7.
|
|
84
|
-
"@dxos/echo-schema": "0.7.
|
|
85
|
-
"@dxos/
|
|
86
|
-
"@dxos/echo-signals": "0.7.
|
|
87
|
-
"@dxos/
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/
|
|
90
|
-
"@dxos/
|
|
91
|
-
"@dxos/
|
|
92
|
-
"@dxos/
|
|
80
|
+
"@dxos/client": "0.7.5-labs.071a3e2",
|
|
81
|
+
"@dxos/async": "0.7.5-labs.071a3e2",
|
|
82
|
+
"@dxos/config": "0.7.5-labs.071a3e2",
|
|
83
|
+
"@dxos/debug": "0.7.5-labs.071a3e2",
|
|
84
|
+
"@dxos/echo-schema": "0.7.5-labs.071a3e2",
|
|
85
|
+
"@dxos/codec-protobuf": "0.7.5-labs.071a3e2",
|
|
86
|
+
"@dxos/echo-signals": "0.7.5-labs.071a3e2",
|
|
87
|
+
"@dxos/log": "0.7.5-labs.071a3e2",
|
|
88
|
+
"@dxos/invariant": "0.7.5-labs.071a3e2",
|
|
89
|
+
"@dxos/protocols": "0.7.5-labs.071a3e2",
|
|
90
|
+
"@dxos/react-hooks": "0.7.5-labs.071a3e2",
|
|
91
|
+
"@dxos/util": "0.7.5-labs.071a3e2",
|
|
92
|
+
"@dxos/node-std": "0.7.5-labs.071a3e2"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@types/react": "~18.2.0",
|
|
96
96
|
"@types/react-dom": "~18.2.0",
|
|
97
97
|
"react": "~18.2.0",
|
|
98
98
|
"react-dom": "~18.2.0",
|
|
99
|
-
"@dxos/react-ui": "0.7.
|
|
100
|
-
"@dxos/
|
|
101
|
-
"@dxos/
|
|
102
|
-
"@dxos/react-ui-
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/
|
|
99
|
+
"@dxos/react-ui": "0.7.5-labs.071a3e2",
|
|
100
|
+
"@dxos/react-ui-syntax-highlighter": "0.7.5-labs.071a3e2",
|
|
101
|
+
"@dxos/random": "0.7.5-labs.071a3e2",
|
|
102
|
+
"@dxos/react-ui-theme": "0.7.5-labs.071a3e2",
|
|
103
|
+
"@dxos/storybook-utils": "0.7.5-labs.071a3e2",
|
|
104
|
+
"@dxos/test-utils": "0.7.5-labs.071a3e2"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
107
|
"react": "~18.2.0",
|
|
108
108
|
"react-dom": "~18.2.0"
|
|
109
109
|
},
|
|
110
110
|
"optionalDependencies": {
|
|
111
|
-
"@dxos/
|
|
112
|
-
"@dxos/
|
|
113
|
-
"@dxos/react-ui-theme": "0.7.
|
|
111
|
+
"@dxos/react-ui": "0.7.5-labs.071a3e2",
|
|
112
|
+
"@dxos/random": "0.7.5-labs.071a3e2",
|
|
113
|
+
"@dxos/react-ui-theme": "0.7.5-labs.071a3e2"
|
|
114
114
|
},
|
|
115
115
|
"publishConfig": {
|
|
116
116
|
"access": "public"
|
|
@@ -151,10 +151,11 @@ describe('ClientProvider', () => {
|
|
|
151
151
|
|
|
152
152
|
await act(async () => {
|
|
153
153
|
await waitForCondition({
|
|
154
|
-
condition: () =>
|
|
154
|
+
condition: () => newClient.status.get() === SystemStatus.ACTIVE,
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
|
-
|
|
157
|
+
// If client is provided externally, the provider will not destroy it.
|
|
158
|
+
expect(client.initialized).toBe(true);
|
|
158
159
|
expect(() => screen.getByText('Identity is NOT there')).not.toThrow();
|
|
159
160
|
});
|
|
160
161
|
});
|
|
@@ -126,9 +126,14 @@ export const ClientProvider = forwardRef<Client | undefined, ClientProviderProps
|
|
|
126
126
|
|
|
127
127
|
// Create and/or initialize client.
|
|
128
128
|
useEffect(() => {
|
|
129
|
+
let disposed = false;
|
|
129
130
|
const initialize = async (client: Client) => {
|
|
130
131
|
if (!client.initialized) {
|
|
131
|
-
await client.initialize().catch(
|
|
132
|
+
await client.initialize().catch((err) => {
|
|
133
|
+
if (!disposed) {
|
|
134
|
+
setError(err);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
132
137
|
log('client ready');
|
|
133
138
|
await onInitialized?.(client);
|
|
134
139
|
log('initialization complete');
|
|
@@ -143,31 +148,41 @@ export const ClientProvider = forwardRef<Client | undefined, ClientProviderProps
|
|
|
143
148
|
|
|
144
149
|
let client: Client;
|
|
145
150
|
const t = setTimeout(async () => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
try {
|
|
152
|
+
if (clientProvider) {
|
|
153
|
+
// Asynchronously request client.
|
|
154
|
+
client = await getAsyncProviderValue(clientProvider);
|
|
155
|
+
await initialize(client);
|
|
156
|
+
} else {
|
|
157
|
+
// Asynchronously construct client (config may be undefined).
|
|
158
|
+
const config = await getAsyncProviderValue(configProvider);
|
|
159
|
+
log('resolved config', { config });
|
|
160
|
+
const services = await getAsyncProviderValue(servicesProvider, config);
|
|
161
|
+
log('created services', { services });
|
|
162
|
+
client = new Client({ config, services, ...options });
|
|
163
|
+
log('created client');
|
|
164
|
+
await initialize(client);
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (!disposed) {
|
|
168
|
+
log.catch(err);
|
|
169
|
+
}
|
|
159
170
|
}
|
|
160
171
|
});
|
|
161
172
|
|
|
162
173
|
return () => {
|
|
163
174
|
log('clean up');
|
|
175
|
+
disposed = true;
|
|
164
176
|
clearTimeout(t);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
// Only destroy if the client is not provided by the parent.
|
|
178
|
+
if (!clientProvider) {
|
|
179
|
+
void client
|
|
180
|
+
?.destroy()
|
|
181
|
+
.then(() => {
|
|
182
|
+
log('destroyed');
|
|
183
|
+
})
|
|
184
|
+
.catch((err) => log.catch(err));
|
|
185
|
+
}
|
|
171
186
|
};
|
|
172
187
|
}, [configProvider, clientProvider, servicesProvider, noBanner]);
|
|
173
188
|
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import React, { useCallback } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Config, PublicKey } from '@dxos/client';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
import { Button } from '@dxos/react-ui';
|
|
13
|
+
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
14
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
15
|
+
|
|
16
|
+
import { useCredentials } from './useCredentials';
|
|
17
|
+
import { useIdentity } from './useIdentity';
|
|
18
|
+
import { useClient } from '../client';
|
|
19
|
+
import { withClientProvider } from '../testing';
|
|
20
|
+
|
|
21
|
+
const getNewChallenge = () => Math.random().toString(36).substring(2);
|
|
22
|
+
|
|
23
|
+
const Test = () => {
|
|
24
|
+
const client = useClient();
|
|
25
|
+
const identity = useIdentity();
|
|
26
|
+
const credentials = useCredentials();
|
|
27
|
+
|
|
28
|
+
const handleCreateIdentity = useCallback(async () => {
|
|
29
|
+
await client.halo.createIdentity();
|
|
30
|
+
invariant(client.services.services.EdgeAgentService, 'Missing EdgeAgentService');
|
|
31
|
+
await client.services.services.EdgeAgentService.createAgent(null as any, { timeout: 10_000 });
|
|
32
|
+
}, [client]);
|
|
33
|
+
|
|
34
|
+
// TODO(wittjosiah): Consider factoring out passkey creation to the halo api.
|
|
35
|
+
const handleCreatePassKey = useCallback(async () => {
|
|
36
|
+
invariant(identity, 'Identity not available');
|
|
37
|
+
const challenge = getNewChallenge();
|
|
38
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions
|
|
39
|
+
const credential = await navigator.credentials
|
|
40
|
+
.create({
|
|
41
|
+
publicKey: {
|
|
42
|
+
challenge: new TextEncoder().encode(challenge),
|
|
43
|
+
rp: { id: location.hostname, name: 'Test' },
|
|
44
|
+
user: {
|
|
45
|
+
id: new TextEncoder().encode(identity.did),
|
|
46
|
+
name: identity.did,
|
|
47
|
+
displayName: identity.profile?.displayName ?? '',
|
|
48
|
+
},
|
|
49
|
+
pubKeyCredParams: [
|
|
50
|
+
{ type: 'public-key', alg: -8 }, // Ed25519 (not yet supported across all browsers)
|
|
51
|
+
{ type: 'public-key', alg: -7 }, // ES256
|
|
52
|
+
],
|
|
53
|
+
// https://web.dev/articles/webauthn-discoverable-credentials#resident-key
|
|
54
|
+
authenticatorSelection: {
|
|
55
|
+
residentKey: 'required',
|
|
56
|
+
requireResidentKey: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
.catch(log.error);
|
|
61
|
+
|
|
62
|
+
invariant(credential, 'Credential not available');
|
|
63
|
+
const recoveryKey = PublicKey.from(new Uint8Array((credential as any).response.getPublicKey()));
|
|
64
|
+
const algorithm: number = (credential as any).response.getPublicKeyAlgorithm();
|
|
65
|
+
|
|
66
|
+
invariant(client.services.services.IdentityService, 'IdentityService not available');
|
|
67
|
+
// TODO(wittjosiah): This needs a proper api.
|
|
68
|
+
await client.services.services.IdentityService.createRecoveryCredential({
|
|
69
|
+
recoveryKey,
|
|
70
|
+
algorithm,
|
|
71
|
+
});
|
|
72
|
+
}, [client, identity]);
|
|
73
|
+
|
|
74
|
+
const handleAuthenticate = useCallback(async () => {
|
|
75
|
+
invariant(client.services.services.IdentityService, 'IdentityService not available');
|
|
76
|
+
const { deviceKey, controlFeedKey, challenge } =
|
|
77
|
+
await client.services.services.IdentityService.requestRecoveryChallenge();
|
|
78
|
+
const credential = await navigator.credentials
|
|
79
|
+
.get({
|
|
80
|
+
publicKey: {
|
|
81
|
+
challenge: new TextEncoder().encode(challenge),
|
|
82
|
+
rpId: location.hostname,
|
|
83
|
+
// NOTE: Don't prompt for password in storybook for test purposes.
|
|
84
|
+
// In practice, this should be set to 'required' for identity recovery.
|
|
85
|
+
userVerification: 'discouraged',
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
.catch(log.error);
|
|
89
|
+
const identityDid = new TextDecoder().decode((credential as any).response.userHandle);
|
|
90
|
+
await client.services.services.IdentityService.recoverIdentity({
|
|
91
|
+
external: {
|
|
92
|
+
identityDid,
|
|
93
|
+
deviceKey,
|
|
94
|
+
controlFeedKey,
|
|
95
|
+
signature: Buffer.from((credential as any).response.signature),
|
|
96
|
+
clientDataJson: Buffer.from((credential as any).response.clientDataJSON),
|
|
97
|
+
authenticatorData: Buffer.from((credential as any).response.authenticatorData),
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
<div className='mbe-4 flex gap-2'>
|
|
105
|
+
<Button disabled={!!identity} onClick={handleCreateIdentity}>
|
|
106
|
+
Create Identity
|
|
107
|
+
</Button>
|
|
108
|
+
<Button disabled={!identity} onClick={handleCreatePassKey}>
|
|
109
|
+
Create Passkey
|
|
110
|
+
</Button>
|
|
111
|
+
<Button disabled={!!identity} onClick={handleAuthenticate}>
|
|
112
|
+
Authenticate with Passkey
|
|
113
|
+
</Button>
|
|
114
|
+
</div>
|
|
115
|
+
<div className='flex flex-col min-w-[28rem] divide-y divide-separator border border-separator rounded'>
|
|
116
|
+
<SyntaxHighlighter language='json'>
|
|
117
|
+
{JSON.stringify({ identity, credentials: credentials.length }, null, 2)}
|
|
118
|
+
</SyntaxHighlighter>
|
|
119
|
+
</div>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default {
|
|
125
|
+
title: 'sdk/react-client/Passkeys',
|
|
126
|
+
render: Test,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const config = new Config({
|
|
130
|
+
runtime: {
|
|
131
|
+
client: {
|
|
132
|
+
edgeFeatures: {
|
|
133
|
+
agents: true,
|
|
134
|
+
echoReplicator: true,
|
|
135
|
+
feedReplicator: true,
|
|
136
|
+
signaling: true,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
services: {
|
|
140
|
+
edge: {
|
|
141
|
+
// url: 'wss://edge.dxos.workers.dev/',
|
|
142
|
+
url: 'ws://localhost:8787',
|
|
143
|
+
},
|
|
144
|
+
iceProviders: [{ urls: 'https://edge-production.dxos.workers.dev/ice' }],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export const Default = {
|
|
150
|
+
decorators: [withClientProvider({ config }), withTheme],
|
|
151
|
+
};
|
package/src/halo/index.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { Credential } from '@dxos/client/halo';
|
|
6
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
7
|
+
|
|
8
|
+
import { useClient } from '../client';
|
|
9
|
+
|
|
10
|
+
export const useCredentials = (): Credential[] => {
|
|
11
|
+
const client = useClient();
|
|
12
|
+
return useMulticastObservable(client.halo.credentials);
|
|
13
|
+
};
|