jazz-tools 0.18.8 → 0.18.10
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/.turbo/turbo-build.log +42 -42
- package/CHANGELOG.md +20 -0
- package/dist/better-auth/auth/client.d.ts +1 -1
- package/dist/better-auth/auth/client.d.ts.map +1 -1
- package/dist/better-auth/auth/client.js.map +1 -1
- package/dist/{chunk-QF3R3C4N.js → chunk-RQHJFPIB.js} +56 -25
- package/dist/{chunk-QF3R3C4N.js.map → chunk-RQHJFPIB.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +3 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +56 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +20 -0
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts +2 -0
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +3 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/implementation/ContextManager.d.ts +2 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/better-auth/auth/client.ts +1 -1
- package/src/better-auth/auth/tests/client.test.ts +229 -0
- package/src/react/hooks.tsx +1 -0
- package/src/react/index.ts +1 -0
- package/src/react-core/hooks.ts +84 -0
- package/src/react-core/tests/useAccountWithSelector.test.ts +411 -0
- package/src/react-native-core/hooks.tsx +1 -0
- package/src/tools/implementation/ContextManager.ts +75 -32
- package/src/tools/tests/ContextManager.test.ts +252 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useAccountWithSelector.test.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/useAccountWithSelector.test.ts"],"names":[],"mappings":""}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { CoValueClassOrSchema } from "jazz-tools";
|
2
|
-
export { useCoState, experimental_useInboxSender, useDemoAuth, usePassphraseAuth, useJazzContext, useAuthSecretStorage, useIsAuthenticated, useAccount, useCoStateWithSelector, } from "jazz-tools/react-core";
|
2
|
+
export { useCoState, experimental_useInboxSender, useDemoAuth, usePassphraseAuth, useJazzContext, useAuthSecretStorage, useIsAuthenticated, useAccount, useCoStateWithSelector, useAccountWithSelector, } from "jazz-tools/react-core";
|
3
3
|
export declare function useAcceptInviteNative<S extends CoValueClassOrSchema>({ invitedObjectSchema, onAccept, forValueHint, }: {
|
4
4
|
invitedObjectSchema: S;
|
5
5
|
onAccept: (projectID: string) => void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react-native-core/hooks.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAmB,MAAM,YAAY,CAAC;AAInE,OAAO,EACL,UAAU,EACV,2BAA2B,EAC3B,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,oBAAoB,EAAE,EACpE,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACb,EAAE;IACD,mBAAmB,EAAE,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAsCP"}
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react-native-core/hooks.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAmB,MAAM,YAAY,CAAC;AAInE,OAAO,EACL,UAAU,EACV,2BAA2B,EAC3B,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,oBAAoB,EAAE,EACpE,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACb,EAAE;IACD,mBAAmB,EAAE,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAsCP"}
|
@@ -246,7 +246,8 @@ import {
|
|
246
246
|
useAuthSecretStorage,
|
247
247
|
useIsAuthenticated,
|
248
248
|
useAccount,
|
249
|
-
useCoStateWithSelector
|
249
|
+
useCoStateWithSelector,
|
250
|
+
useAccountWithSelector
|
250
251
|
} from "jazz-tools/react-core";
|
251
252
|
function useAcceptInviteNative({
|
252
253
|
invitedObjectSchema,
|
@@ -646,6 +647,7 @@ export {
|
|
646
647
|
setupKvStore,
|
647
648
|
useAcceptInviteNative,
|
648
649
|
useAccount,
|
650
|
+
useAccountWithSelector,
|
649
651
|
useAuthSecretStorage,
|
650
652
|
useCoState,
|
651
653
|
useCoStateWithSelector,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/react-native-core/storage/kv-store-context.ts","../../src/react-native-core/auth/DemoAuthUI.tsx","../../src/react-native-core/auth/auth.ts","../../src/react-native-core/hooks.tsx","../../src/react-native-core/provider.tsx","../../src/react-native-core/ReactNativeContextManager.ts","../../src/react-native-core/platform.ts","../../src/react-native-core/media/image.tsx","../../src/react-native-core/index.ts"],"sourcesContent":["export interface KvStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n delete(key: string): Promise<void>;\n clearAll(): Promise<void>;\n}\n\nexport class KvStoreContext {\n private static instance: KvStoreContext;\n private storageInstance: KvStore | null = null;\n\n private constructor() {}\n\n public static getInstance(): KvStoreContext {\n if (!KvStoreContext.instance) {\n KvStoreContext.instance = new KvStoreContext();\n }\n return KvStoreContext.instance;\n }\n\n public isInitialized(): boolean {\n return this.storageInstance !== null;\n }\n\n public initialize(store: KvStore): void {\n if (!this.storageInstance) {\n this.storageInstance = store;\n }\n }\n\n public getStorage(): KvStore {\n if (!this.storageInstance) {\n throw new Error(\"Storage instance is not initialized.\");\n }\n return this.storageInstance;\n }\n}\n\nexport default KvStoreContext;\n","import { useDemoAuth } from \"jazz-tools/react-core\";\nimport React, { useState } from \"react\";\nimport {\n StyleSheet,\n Text,\n TextInput,\n TouchableOpacity,\n View,\n useColorScheme,\n} from \"react-native\";\n\nexport const DemoAuthBasicUI = ({\n appName,\n auth,\n children,\n}: {\n appName: string;\n auth: ReturnType<typeof useDemoAuth>;\n children: React.ReactNode;\n}) => {\n const colorScheme = useColorScheme();\n const darkMode = colorScheme === \"dark\";\n const [username, setUsername] = useState<string>(\"\");\n const [errorMessage, setErrorMessage] = useState<string | null>(null);\n\n const handleSignUp = () => {\n setErrorMessage(null);\n\n auth.signUp(username).catch((error) => {\n setErrorMessage(error.message);\n });\n };\n\n const handleLogIn = (username: string) => {\n setErrorMessage(null);\n\n auth.logIn(username).catch((error) => {\n setErrorMessage(error.message);\n });\n };\n\n if (auth.state === \"signedIn\") {\n return children;\n }\n\n return (\n <View\n style={[\n styles.container,\n darkMode ? styles.darkBackground : styles.lightBackground,\n ]}\n >\n <View style={styles.formContainer}>\n <Text\n style={[\n styles.headerText,\n darkMode ? styles.darkText : styles.lightText,\n ]}\n >\n {appName}\n </Text>\n\n {errorMessage && <Text style={styles.errorText}>{errorMessage}</Text>}\n\n <TextInput\n placeholder=\"Display name\"\n value={username}\n onChangeText={setUsername}\n placeholderTextColor={darkMode ? \"#fff\" : \"#000\"}\n style={[\n styles.textInput,\n darkMode ? styles.darkInput : styles.lightInput,\n ]}\n />\n\n <TouchableOpacity\n onPress={handleSignUp}\n style={[\n styles.button,\n darkMode ? styles.darkButton : styles.lightButton,\n ]}\n >\n <Text\n style={darkMode ? styles.darkButtonText : styles.lightButtonText}\n >\n Sign Up as new account\n </Text>\n </TouchableOpacity>\n\n <View style={styles.existingUsersContainer}>\n {auth.existingUsers.map((user) => (\n <TouchableOpacity\n key={user}\n onPress={() => handleLogIn(user)}\n style={[\n styles.existingUserButton,\n darkMode ? styles.darkUserButton : styles.lightUserButton,\n ]}\n >\n <Text style={darkMode ? styles.darkText : styles.lightText}>\n Log In as \"{user}\"\n </Text>\n </TouchableOpacity>\n ))}\n </View>\n </View>\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: \"center\",\n alignItems: \"center\",\n padding: 20,\n },\n formContainer: {\n width: \"80%\",\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n headerText: {\n fontSize: 24,\n marginBottom: 20,\n },\n errorText: {\n color: \"red\",\n marginVertical: 5,\n textAlign: \"center\",\n },\n textInput: {\n borderWidth: 1,\n padding: 10,\n marginVertical: 10,\n width: \"100%\",\n borderRadius: 6,\n },\n darkInput: {\n borderColor: \"#444\",\n backgroundColor: \"#000\",\n color: \"#fff\",\n },\n lightInput: {\n borderColor: \"#ddd\",\n backgroundColor: \"#fff\",\n color: \"#000\",\n },\n button: {\n paddingVertical: 15,\n paddingHorizontal: 10,\n borderRadius: 6,\n width: \"100%\",\n marginVertical: 10,\n },\n darkButton: {\n backgroundColor: \"#444\",\n },\n lightButton: {\n backgroundColor: \"#ddd\",\n },\n darkButtonText: {\n color: \"#fff\",\n textAlign: \"center\",\n },\n lightButtonText: {\n color: \"#000\",\n textAlign: \"center\",\n },\n existingUsersContainer: {\n width: \"100%\",\n marginTop: 20,\n },\n existingUserButton: {\n paddingVertical: 15,\n paddingHorizontal: 10,\n borderRadius: 6,\n marginVertical: 5,\n },\n darkUserButton: {\n backgroundColor: \"#222\",\n },\n lightUserButton: {\n backgroundColor: \"#eee\",\n },\n loadingText: {\n fontSize: 18,\n color: \"#888\",\n },\n darkText: {\n color: \"#fff\",\n },\n lightText: {\n color: \"#000\",\n },\n darkBackground: {\n backgroundColor: \"#000\",\n },\n lightBackground: {\n backgroundColor: \"#fff\",\n },\n});\n","import { KvStoreContext } from \"../storage/kv-store-context.js\";\n\nexport * from \"./DemoAuthUI.js\";\n\nexport function clearUserCredentials() {\n const kvStore = KvStoreContext.getInstance().getStorage();\n\n // TODO: Migrate the Auth methods to use the same storage key/interface\n return Promise.all([\n kvStore.delete(\"demo-auth-logged-in-secret\"),\n kvStore.delete(\"jazz-clerk-auth\"),\n kvStore.delete(\"jazz-logged-in-secret\"),\n ]);\n}\n","import { useEffect } from \"react\";\n\nimport { CoValueClassOrSchema, parseInviteLink } from \"jazz-tools\";\nimport { useJazzContext } from \"jazz-tools/react-core\";\nimport { Linking } from \"react-native\";\n\nexport {\n useCoState,\n experimental_useInboxSender,\n useDemoAuth,\n usePassphraseAuth,\n useJazzContext,\n useAuthSecretStorage,\n useIsAuthenticated,\n useAccount,\n useCoStateWithSelector,\n} from \"jazz-tools/react-core\";\n\nexport function useAcceptInviteNative<S extends CoValueClassOrSchema>({\n invitedObjectSchema,\n onAccept,\n forValueHint,\n}: {\n invitedObjectSchema: S;\n onAccept: (projectID: string) => void;\n forValueHint?: string;\n}): void {\n const context = useJazzContext();\n\n if (!(\"me\" in context)) {\n throw new Error(\n \"useAcceptInviteNative can't be used in a JazzProvider with auth === 'guest'.\",\n );\n }\n\n useEffect(() => {\n const handleDeepLink = ({ url }: { url: string }) => {\n const result = parseInviteLink(url);\n if (result && result.valueHint === forValueHint) {\n context.me\n .acceptInvite(\n result.valueID,\n result.inviteSecret,\n invitedObjectSchema,\n )\n .then(() => {\n onAccept(result.valueID);\n })\n .catch((e) => {\n console.error(\"Failed to accept invite\", e);\n });\n }\n };\n\n const linkingListener = Linking.addEventListener(\"url\", handleDeepLink);\n\n void Linking.getInitialURL().then((url) => {\n if (url) handleDeepLink({ url });\n });\n\n return () => {\n linkingListener.remove();\n };\n }, [context, onAccept, invitedObjectSchema, forValueHint]);\n}\n","import {\n Account,\n AccountClass,\n AnyAccountSchema,\n CoValueFromRaw,\n InstanceOfSchema,\n JazzContextType,\n KvStore,\n} from \"jazz-tools\";\nimport { JazzContext, JazzContextManagerContext } from \"jazz-tools/react-core\";\nimport React, { useEffect, useRef } from \"react\";\nimport type { JazzContextManagerProps } from \"./ReactNativeContextManager.js\";\nimport { ReactNativeContextManager } from \"./ReactNativeContextManager.js\";\nimport { setupKvStore } from \"./platform.js\";\n\nexport type JazzProviderProps<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n children: React.ReactNode;\n kvStore?: KvStore;\n} & JazzContextManagerProps<S>;\n\n/** @category Context & Hooks */\nexport function JazzProviderCore<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n>({\n children,\n guestMode,\n sync,\n storage,\n AccountSchema,\n defaultProfileName,\n onLogOut,\n logOutReplacement,\n onAnonymousAccountDiscarded,\n kvStore,\n CryptoProvider,\n}: JazzProviderProps<S>) {\n setupKvStore(kvStore);\n\n const [contextManager] = React.useState(\n () => new ReactNativeContextManager<S>(),\n );\n\n const onLogOutRefCallback = useRefCallback(onLogOut);\n const logOutReplacementRefCallback = useRefCallback(logOutReplacement);\n const onAnonymousAccountDiscardedRefCallback = useRefCallback(\n onAnonymousAccountDiscarded,\n );\n const logoutReplacementActiveRef = useRef(false);\n logoutReplacementActiveRef.current = Boolean(logOutReplacement);\n\n const value = React.useSyncExternalStore<\n JazzContextType<InstanceOfSchema<S>> | undefined\n >(\n React.useCallback(\n (callback) => {\n const props = {\n AccountSchema,\n guestMode,\n sync,\n storage,\n defaultProfileName,\n onLogOut: onLogOutRefCallback,\n logOutReplacement: logoutReplacementActiveRef.current\n ? logOutReplacementRefCallback\n : undefined,\n onAnonymousAccountDiscarded: onAnonymousAccountDiscardedRefCallback,\n CryptoProvider,\n } satisfies JazzContextManagerProps<S>;\n\n if (contextManager.propsChanged(props)) {\n contextManager.createContext(props).catch((error) => {\n console.log(error.stack);\n console.error(\"Error creating Jazz React Native context:\", error);\n });\n }\n\n return contextManager.subscribe(callback);\n },\n [sync, guestMode].concat(storage as any),\n ),\n () => contextManager.getCurrentValue(),\n () => contextManager.getCurrentValue(),\n );\n\n useEffect(() => {\n // In development mode we don't return a cleanup function because otherwise\n // the double effect execution would mark the context as done immediately.\n if (process.env.NODE_ENV === \"development\") return;\n\n return () => {\n contextManager.done();\n };\n }, []);\n\n return (\n <JazzContext.Provider value={value}>\n <JazzContextManagerContext.Provider value={contextManager}>\n {value && children}\n </JazzContextManagerContext.Provider>\n </JazzContext.Provider>\n );\n}\n\nfunction useRefCallback<T extends (...args: any[]) => any>(callback?: T) {\n const callbackRef = React.useRef(callback);\n callbackRef.current = callback;\n return useRef(\n (...args: Parameters<T>): ReturnType<T> => callbackRef.current?.(...args),\n ).current;\n}\n","import {\n Account,\n AccountClass,\n CoValueFromRaw,\n JazzContextManager,\n KvStore,\n SyncConfig,\n} from \"jazz-tools\";\nimport type {\n AnyAccountSchema,\n InstanceOfSchema,\n JazzContextManagerAuthProps,\n} from \"jazz-tools\";\nimport {\n BaseReactNativeContextOptions,\n createJazzReactNativeContext,\n createJazzReactNativeGuestContext,\n} from \"./platform.js\";\nimport { KvStoreContext } from \"./storage/kv-store-context.js\";\n\nexport type JazzContextManagerProps<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n guestMode?: boolean;\n sync: SyncConfig;\n onLogOut?: () => void;\n logOutReplacement?: () => void;\n storage?: BaseReactNativeContextOptions[\"storage\"];\n AccountSchema?: S;\n defaultProfileName?: string;\n onAnonymousAccountDiscarded?: (\n anonymousAccount: InstanceOfSchema<S>,\n ) => Promise<void>;\n CryptoProvider?: BaseReactNativeContextOptions[\"CryptoProvider\"];\n};\n\nexport class ReactNativeContextManager<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> extends JazzContextManager<InstanceOfSchema<S>, JazzContextManagerProps<S>> {\n async getNewContext(\n props: JazzContextManagerProps<S>,\n authProps?: JazzContextManagerAuthProps,\n ) {\n if (props.guestMode) {\n return createJazzReactNativeGuestContext({\n sync: props.sync,\n storage: props.storage,\n authSecretStorage: this.authSecretStorage,\n CryptoProvider: props.CryptoProvider,\n });\n } else {\n return createJazzReactNativeContext<S>({\n sync: props.sync,\n storage: props.storage,\n AccountSchema: props.AccountSchema,\n credentials: authProps?.credentials,\n newAccountProps: authProps?.newAccountProps,\n defaultProfileName: props.defaultProfileName,\n authSecretStorage: this.authSecretStorage,\n CryptoProvider: props.CryptoProvider,\n });\n }\n }\n\n getKvStore(): KvStore {\n return KvStoreContext.getInstance().getStorage();\n }\n\n propsChanged(props: JazzContextManagerProps<S>) {\n if (!this.props) {\n return true;\n }\n\n return (\n this.props.sync.when !== props.sync.when ||\n this.props.sync.peer !== props.sync.peer ||\n this.props.guestMode !== props.guestMode\n );\n }\n}\n","import NetInfo from \"@react-native-community/netinfo\";\nimport { LocalNode, Peer, RawAccountID, getSqliteStorageAsync } from \"cojson\";\nimport { PureJSCrypto } from \"cojson/dist/crypto/PureJSCrypto\"; // Importing from dist to not rely on the exports field\nimport {\n Account,\n AccountClass,\n AgentID,\n AnyAccountSchema,\n AuthCredentials,\n AuthSecretStorage,\n CoValue,\n CoValueFromRaw,\n CryptoProvider,\n ID,\n NewAccountProps,\n SessionID,\n SyncConfig,\n createInviteLink as baseCreateInviteLink,\n createAnonymousJazzContext,\n createJazzContext,\n} from \"jazz-tools\";\nimport { KvStore, KvStoreContext } from \"./storage/kv-store-context.js\";\n\nimport { SQLiteDatabaseDriverAsync } from \"cojson\";\nimport { WebSocketPeerWithReconnection } from \"cojson-transport-ws\";\nimport type { RNQuickCrypto } from \"jazz-tools/react-native-core/crypto\";\n\nexport type BaseReactNativeContextOptions = {\n sync: SyncConfig;\n reconnectionTimeout?: number;\n storage?: SQLiteDatabaseDriverAsync | \"disabled\";\n CryptoProvider?: typeof PureJSCrypto | typeof RNQuickCrypto;\n authSecretStorage: AuthSecretStorage;\n};\n\nclass ReactNativeWebSocketPeerWithReconnection extends WebSocketPeerWithReconnection {\n onNetworkChange(callback: (connected: boolean) => void): () => void {\n return NetInfo.addEventListener((state) =>\n callback(state.isConnected ?? false),\n );\n }\n}\n\nasync function setupPeers(options: BaseReactNativeContextOptions) {\n const CryptoProvider = options.CryptoProvider || PureJSCrypto;\n const crypto = await CryptoProvider.create();\n let node: LocalNode | undefined = undefined;\n\n const peersToLoadFrom: Peer[] = [];\n\n const storage =\n options.storage && options.storage !== \"disabled\"\n ? await getSqliteStorageAsync(options.storage)\n : undefined;\n\n if (options.sync.when === \"never\") {\n return {\n toggleNetwork: () => {},\n peersToLoadFrom,\n setNode: () => {},\n crypto,\n storage,\n };\n }\n\n const wsPeer = new ReactNativeWebSocketPeerWithReconnection({\n peer: options.sync.peer,\n reconnectionTimeout: options.reconnectionTimeout,\n addPeer: (peer) => {\n if (node) {\n node.syncManager.addPeer(peer);\n } else {\n peersToLoadFrom.push(peer);\n }\n },\n removePeer: (peer) => {\n peersToLoadFrom.splice(peersToLoadFrom.indexOf(peer), 1);\n },\n });\n\n function toggleNetwork(enabled: boolean) {\n if (enabled) {\n wsPeer.enable();\n } else {\n wsPeer.disable();\n }\n }\n\n function setNode(value: LocalNode) {\n node = value;\n }\n\n if (options.sync.when === \"always\" || !options.sync.when) {\n toggleNetwork(true);\n }\n\n return {\n toggleNetwork,\n peersToLoadFrom,\n setNode,\n crypto,\n storage,\n };\n}\n\nexport async function createJazzReactNativeGuestContext(\n options: BaseReactNativeContextOptions,\n) {\n const { toggleNetwork, peersToLoadFrom, setNode, crypto, storage } =\n await setupPeers(options);\n\n const context = createAnonymousJazzContext({\n crypto,\n peersToLoadFrom,\n storage,\n });\n\n setNode(context.agent.node);\n\n options.authSecretStorage.emitUpdate(null);\n\n return {\n guest: context.agent,\n node: context.agent.node,\n done: () => {\n // TODO: Sync all the covalues before closing the connection & context\n toggleNetwork(false);\n context.done();\n },\n logOut: () => {\n return context.logOut();\n },\n };\n}\n\nexport type ReactNativeContextOptions<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n credentials?: AuthCredentials;\n AccountSchema?: S;\n newAccountProps?: NewAccountProps;\n defaultProfileName?: string;\n} & BaseReactNativeContextOptions;\n\nexport async function createJazzReactNativeContext<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n>(options: ReactNativeContextOptions<S>) {\n const { toggleNetwork, peersToLoadFrom, setNode, crypto, storage } =\n await setupPeers(options);\n\n let unsubscribeAuthUpdate = () => {};\n\n if (options.sync.when === \"signedUp\") {\n const authSecretStorage = options.authSecretStorage;\n const credentials = options.credentials ?? (await authSecretStorage.get());\n\n // To update the internal state with the current credentials\n authSecretStorage.emitUpdate(credentials);\n\n function handleAuthUpdate(isAuthenticated: boolean) {\n if (isAuthenticated) {\n toggleNetwork(true);\n } else {\n toggleNetwork(false);\n }\n }\n\n unsubscribeAuthUpdate = authSecretStorage.onUpdate(handleAuthUpdate);\n handleAuthUpdate(authSecretStorage.isAuthenticated);\n }\n\n const context = await createJazzContext({\n credentials: options.credentials,\n newAccountProps: options.newAccountProps,\n peersToLoadFrom,\n crypto,\n defaultProfileName: options.defaultProfileName,\n AccountSchema: options.AccountSchema,\n sessionProvider: provideLockSession,\n authSecretStorage: options.authSecretStorage,\n storage,\n });\n\n setNode(context.node);\n\n return {\n me: context.account,\n node: context.node,\n authSecretStorage: context.authSecretStorage,\n done: () => {\n // TODO: Sync all the covalues before closing the connection & context\n toggleNetwork(false);\n unsubscribeAuthUpdate();\n context.done();\n },\n logOut: () => {\n unsubscribeAuthUpdate();\n return context.logOut();\n },\n };\n}\n\n/** @category Auth Providers */\nexport type SessionProvider = (\n accountID: ID<Account> | AgentID,\n) => Promise<SessionID>;\n\nexport async function provideLockSession(\n accountID: ID<Account> | AgentID,\n crypto: CryptoProvider,\n) {\n const sessionDone = () => {};\n\n const kvStore = KvStoreContext.getInstance().getStorage();\n\n const sessionID =\n ((await kvStore.get(accountID)) as SessionID) ||\n crypto.newRandomSessionID(accountID as RawAccountID | AgentID);\n await kvStore.set(accountID, sessionID);\n\n return Promise.resolve({\n sessionID,\n sessionDone,\n });\n}\n\n/** @category Invite Links */\nexport function createInviteLink<C extends CoValue>(\n value: C,\n role: \"reader\" | \"writer\" | \"admin\",\n { baseURL, valueHint }: { baseURL?: string; valueHint?: string } = {},\n): string {\n return baseCreateInviteLink(value, role, baseURL ?? \"\", valueHint);\n}\n\nexport function setupKvStore(\n kvStore: KvStore | undefined,\n): KvStore | undefined {\n if (!kvStore) {\n return undefined;\n }\n KvStoreContext.getInstance().initialize(kvStore);\n return kvStore;\n}\n","import { FileStream, ImageDefinition } from \"jazz-tools\";\nimport { highestResAvailable } from \"jazz-tools/media\";\nimport { forwardRef, useEffect, useMemo, useState } from \"react\";\nimport { Image as RNImage, ImageProps as RNImageProps } from \"react-native\";\nimport { useCoState } from \"../hooks.js\";\n\nexport type ImageProps = Omit<RNImageProps, \"width\" | \"height\" | \"source\"> & {\n /** The ID of the ImageDefinition to display */\n imageId: string;\n /**\n * Width of the image. Can be a number or \"original\" to use the original image width.\n * When set to \"original\", the component will calculate the appropriate height to maintain aspect ratio.\n *\n * @example\n * ```tsx\n * // Fixed width, auto-calculated height\n * <Image imageId=\"123\" width={600} />\n *\n * // Original width\n * <Image imageId=\"123\" width=\"original\" />\n * ```\n */\n width?: number | \"original\";\n /**\n * Height of the image. Can be a number or \"original\" to use the original image height.\n * When set to \"original\", the component will calculate the appropriate width to maintain aspect ratio.\n *\n * @example\n * ```tsx\n * // Fixed height, auto-calculated width\n * <Image imageId=\"123\" height={400} />\n *\n * // Original height\n * <Image imageId=\"123\" height=\"original\" />\n * ```\n */\n height?: number | \"original\";\n};\n\n/**\n * A React Native Image component that integrates with Jazz's ImageDefinition system.\n *\n * @example\n * ```tsx\n * import { Image } from \"jazz-tools/react-native\";\n * import { StyleSheet } from \"react-native\";\n *\n * function ProfilePicture({ imageId }) {\n * return (\n * <Image\n * imageId={imageId}\n * style={styles.profilePic}\n * width={100}\n * height={100}\n * resizeMode=\"cover\"\n * />\n * );\n * }\n *\n * const styles = StyleSheet.create({\n * profilePic: {\n * borderRadius: 50,\n * }\n * });\n * ```\n */\nexport const Image = forwardRef<RNImage, ImageProps>(function Image(\n { imageId, width, height, ...props },\n ref,\n) {\n const image = useCoState(ImageDefinition, imageId);\n const [src, setSrc] = useState<string | undefined>(image?.placeholderDataURL);\n\n const dimensions: { width: number | undefined; height: number | undefined } =\n useMemo(() => {\n const originalWidth = image?.originalSize?.[0];\n const originalHeight = image?.originalSize?.[1];\n\n // Both width and height are \"original\"\n if (width === \"original\" && height === \"original\") {\n return { width: originalWidth, height: originalHeight };\n }\n\n // Width is \"original\", height is a number\n if (width === \"original\" && typeof height === \"number\") {\n if (originalWidth && originalHeight) {\n return {\n width: Math.round((height * originalWidth) / originalHeight),\n height,\n };\n }\n return { width: undefined, height };\n }\n\n // Height is \"original\", width is a number\n if (height === \"original\" && typeof width === \"number\") {\n if (originalWidth && originalHeight) {\n return {\n width,\n height: Math.round((width * originalHeight) / originalWidth),\n };\n }\n return { width, height: undefined };\n }\n\n // In all other cases, use the property value:\n return {\n width: width === \"original\" ? originalWidth : width,\n height: height === \"original\" ? originalHeight : height,\n };\n }, [image?.originalSize, width, height]);\n\n useEffect(() => {\n if (!image) return;\n\n let lastBestImage: FileStream | string | undefined =\n image.placeholderDataURL;\n\n const unsub = image.$jazz.subscribe({}, (update) => {\n if (lastBestImage === undefined && update.placeholderDataURL) {\n setSrc(update.placeholderDataURL);\n lastBestImage = update.placeholderDataURL;\n }\n\n const bestImage = highestResAvailable(\n update,\n dimensions.width || dimensions.height || 9999,\n dimensions.height || dimensions.width || 9999,\n );\n\n if (!bestImage) return;\n\n if (lastBestImage === bestImage.image) return;\n\n const url = bestImage.image.asBase64({ dataURL: true });\n\n if (url) {\n setSrc(url);\n lastBestImage = bestImage.image;\n }\n });\n\n return unsub;\n }, [image]);\n\n if (!image) {\n return null;\n }\n\n return (\n <RNImage\n ref={ref}\n source={{ uri: src }}\n width={dimensions.width}\n height={dimensions.height}\n {...props}\n />\n );\n});\n","export * from \"./auth/auth.js\";\nexport * from \"./hooks.js\";\nexport * from \"./provider.js\";\nexport * from \"./storage/kv-store-context.js\";\nexport * from \"./media/image.js\";\n\nexport { SQLiteDatabaseDriverAsync } from \"cojson\";\nexport { parseInviteLink } from \"jazz-tools\";\nexport { createInviteLink, setupKvStore } from \"./platform.js\";\n"],"mappings":";AAOO,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAIlB,cAAc;AAFtB,SAAQ,kBAAkC;AAAA,EAEnB;AAAA,EAEvB,OAAc,cAA8B;AAC1C,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW,IAAI,gBAAe;AAAA,IAC/C;AACA,WAAO,gBAAe;AAAA,EACxB;AAAA,EAEO,gBAAyB;AAC9B,WAAO,KAAK,oBAAoB;AAAA,EAClC;AAAA,EAEO,WAAW,OAAsB;AACtC,QAAI,CAAC,KAAK,iBAAiB;AACzB,WAAK,kBAAkB;AAAA,IACzB;AAAA,EACF;AAAA,EAEO,aAAsB;AAC3B,QAAI,CAAC,KAAK,iBAAiB;AACzB,YAAM,IAAI,MAAM,sCAAsC;AAAA,IACxD;AACA,WAAO,KAAK;AAAA,EACd;AACF;;;ACnCA,SAAgB,gBAAgB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4CC,cA8CM,YA9CN;AA1CD,IAAM,kBAAkB,CAAC;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACJ,QAAM,cAAc,eAAe;AACnC,Q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,SAAS,mBAAAI,wBAAuB;","names":["username","useJazzContext","React","useEffect","CryptoProvider","handleAuthUpdate","jsx","CryptoProvider","React","useEffect","useEffect","useState","jsx","Image","useState","useEffect","parseInviteLink"]}
|
1
|
+
{"version":3,"sources":["../../src/react-native-core/storage/kv-store-context.ts","../../src/react-native-core/auth/DemoAuthUI.tsx","../../src/react-native-core/auth/auth.ts","../../src/react-native-core/hooks.tsx","../../src/react-native-core/provider.tsx","../../src/react-native-core/ReactNativeContextManager.ts","../../src/react-native-core/platform.ts","../../src/react-native-core/media/image.tsx","../../src/react-native-core/index.ts"],"sourcesContent":["export interface KvStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n delete(key: string): Promise<void>;\n clearAll(): Promise<void>;\n}\n\nexport class KvStoreContext {\n private static instance: KvStoreContext;\n private storageInstance: KvStore | null = null;\n\n private constructor() {}\n\n public static getInstance(): KvStoreContext {\n if (!KvStoreContext.instance) {\n KvStoreContext.instance = new KvStoreContext();\n }\n return KvStoreContext.instance;\n }\n\n public isInitialized(): boolean {\n return this.storageInstance !== null;\n }\n\n public initialize(store: KvStore): void {\n if (!this.storageInstance) {\n this.storageInstance = store;\n }\n }\n\n public getStorage(): KvStore {\n if (!this.storageInstance) {\n throw new Error(\"Storage instance is not initialized.\");\n }\n return this.storageInstance;\n }\n}\n\nexport default KvStoreContext;\n","import { useDemoAuth } from \"jazz-tools/react-core\";\nimport React, { useState } from \"react\";\nimport {\n StyleSheet,\n Text,\n TextInput,\n TouchableOpacity,\n View,\n useColorScheme,\n} from \"react-native\";\n\nexport const DemoAuthBasicUI = ({\n appName,\n auth,\n children,\n}: {\n appName: string;\n auth: ReturnType<typeof useDemoAuth>;\n children: React.ReactNode;\n}) => {\n const colorScheme = useColorScheme();\n const darkMode = colorScheme === \"dark\";\n const [username, setUsername] = useState<string>(\"\");\n const [errorMessage, setErrorMessage] = useState<string | null>(null);\n\n const handleSignUp = () => {\n setErrorMessage(null);\n\n auth.signUp(username).catch((error) => {\n setErrorMessage(error.message);\n });\n };\n\n const handleLogIn = (username: string) => {\n setErrorMessage(null);\n\n auth.logIn(username).catch((error) => {\n setErrorMessage(error.message);\n });\n };\n\n if (auth.state === \"signedIn\") {\n return children;\n }\n\n return (\n <View\n style={[\n styles.container,\n darkMode ? styles.darkBackground : styles.lightBackground,\n ]}\n >\n <View style={styles.formContainer}>\n <Text\n style={[\n styles.headerText,\n darkMode ? styles.darkText : styles.lightText,\n ]}\n >\n {appName}\n </Text>\n\n {errorMessage && <Text style={styles.errorText}>{errorMessage}</Text>}\n\n <TextInput\n placeholder=\"Display name\"\n value={username}\n onChangeText={setUsername}\n placeholderTextColor={darkMode ? \"#fff\" : \"#000\"}\n style={[\n styles.textInput,\n darkMode ? styles.darkInput : styles.lightInput,\n ]}\n />\n\n <TouchableOpacity\n onPress={handleSignUp}\n style={[\n styles.button,\n darkMode ? styles.darkButton : styles.lightButton,\n ]}\n >\n <Text\n style={darkMode ? styles.darkButtonText : styles.lightButtonText}\n >\n Sign Up as new account\n </Text>\n </TouchableOpacity>\n\n <View style={styles.existingUsersContainer}>\n {auth.existingUsers.map((user) => (\n <TouchableOpacity\n key={user}\n onPress={() => handleLogIn(user)}\n style={[\n styles.existingUserButton,\n darkMode ? styles.darkUserButton : styles.lightUserButton,\n ]}\n >\n <Text style={darkMode ? styles.darkText : styles.lightText}>\n Log In as \"{user}\"\n </Text>\n </TouchableOpacity>\n ))}\n </View>\n </View>\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: \"center\",\n alignItems: \"center\",\n padding: 20,\n },\n formContainer: {\n width: \"80%\",\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n headerText: {\n fontSize: 24,\n marginBottom: 20,\n },\n errorText: {\n color: \"red\",\n marginVertical: 5,\n textAlign: \"center\",\n },\n textInput: {\n borderWidth: 1,\n padding: 10,\n marginVertical: 10,\n width: \"100%\",\n borderRadius: 6,\n },\n darkInput: {\n borderColor: \"#444\",\n backgroundColor: \"#000\",\n color: \"#fff\",\n },\n lightInput: {\n borderColor: \"#ddd\",\n backgroundColor: \"#fff\",\n color: \"#000\",\n },\n button: {\n paddingVertical: 15,\n paddingHorizontal: 10,\n borderRadius: 6,\n width: \"100%\",\n marginVertical: 10,\n },\n darkButton: {\n backgroundColor: \"#444\",\n },\n lightButton: {\n backgroundColor: \"#ddd\",\n },\n darkButtonText: {\n color: \"#fff\",\n textAlign: \"center\",\n },\n lightButtonText: {\n color: \"#000\",\n textAlign: \"center\",\n },\n existingUsersContainer: {\n width: \"100%\",\n marginTop: 20,\n },\n existingUserButton: {\n paddingVertical: 15,\n paddingHorizontal: 10,\n borderRadius: 6,\n marginVertical: 5,\n },\n darkUserButton: {\n backgroundColor: \"#222\",\n },\n lightUserButton: {\n backgroundColor: \"#eee\",\n },\n loadingText: {\n fontSize: 18,\n color: \"#888\",\n },\n darkText: {\n color: \"#fff\",\n },\n lightText: {\n color: \"#000\",\n },\n darkBackground: {\n backgroundColor: \"#000\",\n },\n lightBackground: {\n backgroundColor: \"#fff\",\n },\n});\n","import { KvStoreContext } from \"../storage/kv-store-context.js\";\n\nexport * from \"./DemoAuthUI.js\";\n\nexport function clearUserCredentials() {\n const kvStore = KvStoreContext.getInstance().getStorage();\n\n // TODO: Migrate the Auth methods to use the same storage key/interface\n return Promise.all([\n kvStore.delete(\"demo-auth-logged-in-secret\"),\n kvStore.delete(\"jazz-clerk-auth\"),\n kvStore.delete(\"jazz-logged-in-secret\"),\n ]);\n}\n","import { useEffect } from \"react\";\n\nimport { CoValueClassOrSchema, parseInviteLink } from \"jazz-tools\";\nimport { useJazzContext } from \"jazz-tools/react-core\";\nimport { Linking } from \"react-native\";\n\nexport {\n useCoState,\n experimental_useInboxSender,\n useDemoAuth,\n usePassphraseAuth,\n useJazzContext,\n useAuthSecretStorage,\n useIsAuthenticated,\n useAccount,\n useCoStateWithSelector,\n useAccountWithSelector,\n} from \"jazz-tools/react-core\";\n\nexport function useAcceptInviteNative<S extends CoValueClassOrSchema>({\n invitedObjectSchema,\n onAccept,\n forValueHint,\n}: {\n invitedObjectSchema: S;\n onAccept: (projectID: string) => void;\n forValueHint?: string;\n}): void {\n const context = useJazzContext();\n\n if (!(\"me\" in context)) {\n throw new Error(\n \"useAcceptInviteNative can't be used in a JazzProvider with auth === 'guest'.\",\n );\n }\n\n useEffect(() => {\n const handleDeepLink = ({ url }: { url: string }) => {\n const result = parseInviteLink(url);\n if (result && result.valueHint === forValueHint) {\n context.me\n .acceptInvite(\n result.valueID,\n result.inviteSecret,\n invitedObjectSchema,\n )\n .then(() => {\n onAccept(result.valueID);\n })\n .catch((e) => {\n console.error(\"Failed to accept invite\", e);\n });\n }\n };\n\n const linkingListener = Linking.addEventListener(\"url\", handleDeepLink);\n\n void Linking.getInitialURL().then((url) => {\n if (url) handleDeepLink({ url });\n });\n\n return () => {\n linkingListener.remove();\n };\n }, [context, onAccept, invitedObjectSchema, forValueHint]);\n}\n","import {\n Account,\n AccountClass,\n AnyAccountSchema,\n CoValueFromRaw,\n InstanceOfSchema,\n JazzContextType,\n KvStore,\n} from \"jazz-tools\";\nimport { JazzContext, JazzContextManagerContext } from \"jazz-tools/react-core\";\nimport React, { useEffect, useRef } from \"react\";\nimport type { JazzContextManagerProps } from \"./ReactNativeContextManager.js\";\nimport { ReactNativeContextManager } from \"./ReactNativeContextManager.js\";\nimport { setupKvStore } from \"./platform.js\";\n\nexport type JazzProviderProps<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n children: React.ReactNode;\n kvStore?: KvStore;\n} & JazzContextManagerProps<S>;\n\n/** @category Context & Hooks */\nexport function JazzProviderCore<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n>({\n children,\n guestMode,\n sync,\n storage,\n AccountSchema,\n defaultProfileName,\n onLogOut,\n logOutReplacement,\n onAnonymousAccountDiscarded,\n kvStore,\n CryptoProvider,\n}: JazzProviderProps<S>) {\n setupKvStore(kvStore);\n\n const [contextManager] = React.useState(\n () => new ReactNativeContextManager<S>(),\n );\n\n const onLogOutRefCallback = useRefCallback(onLogOut);\n const logOutReplacementRefCallback = useRefCallback(logOutReplacement);\n const onAnonymousAccountDiscardedRefCallback = useRefCallback(\n onAnonymousAccountDiscarded,\n );\n const logoutReplacementActiveRef = useRef(false);\n logoutReplacementActiveRef.current = Boolean(logOutReplacement);\n\n const value = React.useSyncExternalStore<\n JazzContextType<InstanceOfSchema<S>> | undefined\n >(\n React.useCallback(\n (callback) => {\n const props = {\n AccountSchema,\n guestMode,\n sync,\n storage,\n defaultProfileName,\n onLogOut: onLogOutRefCallback,\n logOutReplacement: logoutReplacementActiveRef.current\n ? logOutReplacementRefCallback\n : undefined,\n onAnonymousAccountDiscarded: onAnonymousAccountDiscardedRefCallback,\n CryptoProvider,\n } satisfies JazzContextManagerProps<S>;\n\n if (contextManager.propsChanged(props)) {\n contextManager.createContext(props).catch((error) => {\n console.log(error.stack);\n console.error(\"Error creating Jazz React Native context:\", error);\n });\n }\n\n return contextManager.subscribe(callback);\n },\n [sync, guestMode].concat(storage as any),\n ),\n () => contextManager.getCurrentValue(),\n () => contextManager.getCurrentValue(),\n );\n\n useEffect(() => {\n // In development mode we don't return a cleanup function because otherwise\n // the double effect execution would mark the context as done immediately.\n if (process.env.NODE_ENV === \"development\") return;\n\n return () => {\n contextManager.done();\n };\n }, []);\n\n return (\n <JazzContext.Provider value={value}>\n <JazzContextManagerContext.Provider value={contextManager}>\n {value && children}\n </JazzContextManagerContext.Provider>\n </JazzContext.Provider>\n );\n}\n\nfunction useRefCallback<T extends (...args: any[]) => any>(callback?: T) {\n const callbackRef = React.useRef(callback);\n callbackRef.current = callback;\n return useRef(\n (...args: Parameters<T>): ReturnType<T> => callbackRef.current?.(...args),\n ).current;\n}\n","import {\n Account,\n AccountClass,\n CoValueFromRaw,\n JazzContextManager,\n KvStore,\n SyncConfig,\n} from \"jazz-tools\";\nimport type {\n AnyAccountSchema,\n InstanceOfSchema,\n JazzContextManagerAuthProps,\n} from \"jazz-tools\";\nimport {\n BaseReactNativeContextOptions,\n createJazzReactNativeContext,\n createJazzReactNativeGuestContext,\n} from \"./platform.js\";\nimport { KvStoreContext } from \"./storage/kv-store-context.js\";\n\nexport type JazzContextManagerProps<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n guestMode?: boolean;\n sync: SyncConfig;\n onLogOut?: () => void;\n logOutReplacement?: () => void;\n storage?: BaseReactNativeContextOptions[\"storage\"];\n AccountSchema?: S;\n defaultProfileName?: string;\n onAnonymousAccountDiscarded?: (\n anonymousAccount: InstanceOfSchema<S>,\n ) => Promise<void>;\n CryptoProvider?: BaseReactNativeContextOptions[\"CryptoProvider\"];\n};\n\nexport class ReactNativeContextManager<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> extends JazzContextManager<InstanceOfSchema<S>, JazzContextManagerProps<S>> {\n async getNewContext(\n props: JazzContextManagerProps<S>,\n authProps?: JazzContextManagerAuthProps,\n ) {\n if (props.guestMode) {\n return createJazzReactNativeGuestContext({\n sync: props.sync,\n storage: props.storage,\n authSecretStorage: this.authSecretStorage,\n CryptoProvider: props.CryptoProvider,\n });\n } else {\n return createJazzReactNativeContext<S>({\n sync: props.sync,\n storage: props.storage,\n AccountSchema: props.AccountSchema,\n credentials: authProps?.credentials,\n newAccountProps: authProps?.newAccountProps,\n defaultProfileName: props.defaultProfileName,\n authSecretStorage: this.authSecretStorage,\n CryptoProvider: props.CryptoProvider,\n });\n }\n }\n\n getKvStore(): KvStore {\n return KvStoreContext.getInstance().getStorage();\n }\n\n propsChanged(props: JazzContextManagerProps<S>) {\n if (!this.props) {\n return true;\n }\n\n return (\n this.props.sync.when !== props.sync.when ||\n this.props.sync.peer !== props.sync.peer ||\n this.props.guestMode !== props.guestMode\n );\n }\n}\n","import NetInfo from \"@react-native-community/netinfo\";\nimport { LocalNode, Peer, RawAccountID, getSqliteStorageAsync } from \"cojson\";\nimport { PureJSCrypto } from \"cojson/dist/crypto/PureJSCrypto\"; // Importing from dist to not rely on the exports field\nimport {\n Account,\n AccountClass,\n AgentID,\n AnyAccountSchema,\n AuthCredentials,\n AuthSecretStorage,\n CoValue,\n CoValueFromRaw,\n CryptoProvider,\n ID,\n NewAccountProps,\n SessionID,\n SyncConfig,\n createInviteLink as baseCreateInviteLink,\n createAnonymousJazzContext,\n createJazzContext,\n} from \"jazz-tools\";\nimport { KvStore, KvStoreContext } from \"./storage/kv-store-context.js\";\n\nimport { SQLiteDatabaseDriverAsync } from \"cojson\";\nimport { WebSocketPeerWithReconnection } from \"cojson-transport-ws\";\nimport type { RNQuickCrypto } from \"jazz-tools/react-native-core/crypto\";\n\nexport type BaseReactNativeContextOptions = {\n sync: SyncConfig;\n reconnectionTimeout?: number;\n storage?: SQLiteDatabaseDriverAsync | \"disabled\";\n CryptoProvider?: typeof PureJSCrypto | typeof RNQuickCrypto;\n authSecretStorage: AuthSecretStorage;\n};\n\nclass ReactNativeWebSocketPeerWithReconnection extends WebSocketPeerWithReconnection {\n onNetworkChange(callback: (connected: boolean) => void): () => void {\n return NetInfo.addEventListener((state) =>\n callback(state.isConnected ?? false),\n );\n }\n}\n\nasync function setupPeers(options: BaseReactNativeContextOptions) {\n const CryptoProvider = options.CryptoProvider || PureJSCrypto;\n const crypto = await CryptoProvider.create();\n let node: LocalNode | undefined = undefined;\n\n const peersToLoadFrom: Peer[] = [];\n\n const storage =\n options.storage && options.storage !== \"disabled\"\n ? await getSqliteStorageAsync(options.storage)\n : undefined;\n\n if (options.sync.when === \"never\") {\n return {\n toggleNetwork: () => {},\n peersToLoadFrom,\n setNode: () => {},\n crypto,\n storage,\n };\n }\n\n const wsPeer = new ReactNativeWebSocketPeerWithReconnection({\n peer: options.sync.peer,\n reconnectionTimeout: options.reconnectionTimeout,\n addPeer: (peer) => {\n if (node) {\n node.syncManager.addPeer(peer);\n } else {\n peersToLoadFrom.push(peer);\n }\n },\n removePeer: (peer) => {\n peersToLoadFrom.splice(peersToLoadFrom.indexOf(peer), 1);\n },\n });\n\n function toggleNetwork(enabled: boolean) {\n if (enabled) {\n wsPeer.enable();\n } else {\n wsPeer.disable();\n }\n }\n\n function setNode(value: LocalNode) {\n node = value;\n }\n\n if (options.sync.when === \"always\" || !options.sync.when) {\n toggleNetwork(true);\n }\n\n return {\n toggleNetwork,\n peersToLoadFrom,\n setNode,\n crypto,\n storage,\n };\n}\n\nexport async function createJazzReactNativeGuestContext(\n options: BaseReactNativeContextOptions,\n) {\n const { toggleNetwork, peersToLoadFrom, setNode, crypto, storage } =\n await setupPeers(options);\n\n const context = createAnonymousJazzContext({\n crypto,\n peersToLoadFrom,\n storage,\n });\n\n setNode(context.agent.node);\n\n options.authSecretStorage.emitUpdate(null);\n\n return {\n guest: context.agent,\n node: context.agent.node,\n done: () => {\n // TODO: Sync all the covalues before closing the connection & context\n toggleNetwork(false);\n context.done();\n },\n logOut: () => {\n return context.logOut();\n },\n };\n}\n\nexport type ReactNativeContextOptions<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n credentials?: AuthCredentials;\n AccountSchema?: S;\n newAccountProps?: NewAccountProps;\n defaultProfileName?: string;\n} & BaseReactNativeContextOptions;\n\nexport async function createJazzReactNativeContext<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n>(options: ReactNativeContextOptions<S>) {\n const { toggleNetwork, peersToLoadFrom, setNode, crypto, storage } =\n await setupPeers(options);\n\n let unsubscribeAuthUpdate = () => {};\n\n if (options.sync.when === \"signedUp\") {\n const authSecretStorage = options.authSecretStorage;\n const credentials = options.credentials ?? (await authSecretStorage.get());\n\n // To update the internal state with the current credentials\n authSecretStorage.emitUpdate(credentials);\n\n function handleAuthUpdate(isAuthenticated: boolean) {\n if (isAuthenticated) {\n toggleNetwork(true);\n } else {\n toggleNetwork(false);\n }\n }\n\n unsubscribeAuthUpdate = authSecretStorage.onUpdate(handleAuthUpdate);\n handleAuthUpdate(authSecretStorage.isAuthenticated);\n }\n\n const context = await createJazzContext({\n credentials: options.credentials,\n newAccountProps: options.newAccountProps,\n peersToLoadFrom,\n crypto,\n defaultProfileName: options.defaultProfileName,\n AccountSchema: options.AccountSchema,\n sessionProvider: provideLockSession,\n authSecretStorage: options.authSecretStorage,\n storage,\n });\n\n setNode(context.node);\n\n return {\n me: context.account,\n node: context.node,\n authSecretStorage: context.authSecretStorage,\n done: () => {\n // TODO: Sync all the covalues before closing the connection & context\n toggleNetwork(false);\n unsubscribeAuthUpdate();\n context.done();\n },\n logOut: () => {\n unsubscribeAuthUpdate();\n return context.logOut();\n },\n };\n}\n\n/** @category Auth Providers */\nexport type SessionProvider = (\n accountID: ID<Account> | AgentID,\n) => Promise<SessionID>;\n\nexport async function provideLockSession(\n accountID: ID<Account> | AgentID,\n crypto: CryptoProvider,\n) {\n const sessionDone = () => {};\n\n const kvStore = KvStoreContext.getInstance().getStorage();\n\n const sessionID =\n ((await kvStore.get(accountID)) as SessionID) ||\n crypto.newRandomSessionID(accountID as RawAccountID | AgentID);\n await kvStore.set(accountID, sessionID);\n\n return Promise.resolve({\n sessionID,\n sessionDone,\n });\n}\n\n/** @category Invite Links */\nexport function createInviteLink<C extends CoValue>(\n value: C,\n role: \"reader\" | \"writer\" | \"admin\",\n { baseURL, valueHint }: { baseURL?: string; valueHint?: string } = {},\n): string {\n return baseCreateInviteLink(value, role, baseURL ?? \"\", valueHint);\n}\n\nexport function setupKvStore(\n kvStore: KvStore | undefined,\n): KvStore | undefined {\n if (!kvStore) {\n return undefined;\n }\n KvStoreContext.getInstance().initialize(kvStore);\n return kvStore;\n}\n","import { FileStream, ImageDefinition } from \"jazz-tools\";\nimport { highestResAvailable } from \"jazz-tools/media\";\nimport { forwardRef, useEffect, useMemo, useState } from \"react\";\nimport { Image as RNImage, ImageProps as RNImageProps } from \"react-native\";\nimport { useCoState } from \"../hooks.js\";\n\nexport type ImageProps = Omit<RNImageProps, \"width\" | \"height\" | \"source\"> & {\n /** The ID of the ImageDefinition to display */\n imageId: string;\n /**\n * Width of the image. Can be a number or \"original\" to use the original image width.\n * When set to \"original\", the component will calculate the appropriate height to maintain aspect ratio.\n *\n * @example\n * ```tsx\n * // Fixed width, auto-calculated height\n * <Image imageId=\"123\" width={600} />\n *\n * // Original width\n * <Image imageId=\"123\" width=\"original\" />\n * ```\n */\n width?: number | \"original\";\n /**\n * Height of the image. Can be a number or \"original\" to use the original image height.\n * When set to \"original\", the component will calculate the appropriate width to maintain aspect ratio.\n *\n * @example\n * ```tsx\n * // Fixed height, auto-calculated width\n * <Image imageId=\"123\" height={400} />\n *\n * // Original height\n * <Image imageId=\"123\" height=\"original\" />\n * ```\n */\n height?: number | \"original\";\n};\n\n/**\n * A React Native Image component that integrates with Jazz's ImageDefinition system.\n *\n * @example\n * ```tsx\n * import { Image } from \"jazz-tools/react-native\";\n * import { StyleSheet } from \"react-native\";\n *\n * function ProfilePicture({ imageId }) {\n * return (\n * <Image\n * imageId={imageId}\n * style={styles.profilePic}\n * width={100}\n * height={100}\n * resizeMode=\"cover\"\n * />\n * );\n * }\n *\n * const styles = StyleSheet.create({\n * profilePic: {\n * borderRadius: 50,\n * }\n * });\n * ```\n */\nexport const Image = forwardRef<RNImage, ImageProps>(function Image(\n { imageId, width, height, ...props },\n ref,\n) {\n const image = useCoState(ImageDefinition, imageId);\n const [src, setSrc] = useState<string | undefined>(image?.placeholderDataURL);\n\n const dimensions: { width: number | undefined; height: number | undefined } =\n useMemo(() => {\n const originalWidth = image?.originalSize?.[0];\n const originalHeight = image?.originalSize?.[1];\n\n // Both width and height are \"original\"\n if (width === \"original\" && height === \"original\") {\n return { width: originalWidth, height: originalHeight };\n }\n\n // Width is \"original\", height is a number\n if (width === \"original\" && typeof height === \"number\") {\n if (originalWidth && originalHeight) {\n return {\n width: Math.round((height * originalWidth) / originalHeight),\n height,\n };\n }\n return { width: undefined, height };\n }\n\n // Height is \"original\", width is a number\n if (height === \"original\" && typeof width === \"number\") {\n if (originalWidth && originalHeight) {\n return {\n width,\n height: Math.round((width * originalHeight) / originalWidth),\n };\n }\n return { width, height: undefined };\n }\n\n // In all other cases, use the property value:\n return {\n width: width === \"original\" ? originalWidth : width,\n height: height === \"original\" ? originalHeight : height,\n };\n }, [image?.originalSize, width, height]);\n\n useEffect(() => {\n if (!image) return;\n\n let lastBestImage: FileStream | string | undefined =\n image.placeholderDataURL;\n\n const unsub = image.$jazz.subscribe({}, (update) => {\n if (lastBestImage === undefined && update.placeholderDataURL) {\n setSrc(update.placeholderDataURL);\n lastBestImage = update.placeholderDataURL;\n }\n\n const bestImage = highestResAvailable(\n update,\n dimensions.width || dimensions.height || 9999,\n dimensions.height || dimensions.width || 9999,\n );\n\n if (!bestImage) return;\n\n if (lastBestImage === bestImage.image) return;\n\n const url = bestImage.image.asBase64({ dataURL: true });\n\n if (url) {\n setSrc(url);\n lastBestImage = bestImage.image;\n }\n });\n\n return unsub;\n }, [image]);\n\n if (!image) {\n return null;\n }\n\n return (\n <RNImage\n ref={ref}\n source={{ uri: src }}\n width={dimensions.width}\n height={dimensions.height}\n {...props}\n />\n );\n});\n","export * from \"./auth/auth.js\";\nexport * from \"./hooks.js\";\nexport * from \"./provider.js\";\nexport * from \"./storage/kv-store-context.js\";\nexport * from \"./media/image.js\";\n\nexport { SQLiteDatabaseDriverAsync } from \"cojson\";\nexport { parseInviteLink } from \"jazz-tools\";\nexport { createInviteLink, setupKvStore } from \"./platform.js\";\n"],"mappings":";AAOO,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAIlB,cAAc;AAFtB,SAAQ,kBAAkC;AAAA,EAEnB;AAAA,EAEvB,OAAc,cAA8B;AAC1C,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW,IAAI,gBAAe;AAAA,IAC/C;AACA,WAAO,gBAAe;AAAA,EACxB;AAAA,EAEO,gBAAyB;AAC9B,WAAO,KAA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I,CAAC,UAAW;AAEhB,UAAI,kBAAkB,UAAU,MAAO;AAEvC,YAAM,MAAM,UAAU,MAAM,SAAS,EAAE,SAAS,KAAK,CAAC;AAEtD,UAAI,KAAK;AACP,eAAO,GAAG;AACV,wBAAgB,UAAU;AAAA,MAC5B;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,KAAK,CAAC;AAEV,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,SACE,gBAAAH;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,QAAQ,EAAE,KAAK,IAAI;AAAA,MACnB,OAAO,WAAW;AAAA,MAClB,QAAQ,WAAW;AAAA,MAClB,GAAG;AAAA;AAAA,EACN;AAEJ,CAAC;;;ACxJD,SAAS,iCAAiC;AAC1C,SAAS,mBAAAI,wBAAuB;","names":["username","useJazzContext","React","useEffect","CryptoProvider","handleAuthUpdate","jsx","CryptoProvider","React","useEffect","useEffect","useState","jsx","Image","useState","useEffect","parseInviteLink"]}
|
package/dist/testing.js
CHANGED
@@ -39,6 +39,7 @@ export declare class JazzContextManager<Acc extends Account, P extends JazzConte
|
|
39
39
|
protected authSecretStorage: AuthSecretStorage;
|
40
40
|
protected keepContextOpen: boolean;
|
41
41
|
contextPromise: Promise<void> | undefined;
|
42
|
+
protected authenticatingAccountID: string | null;
|
42
43
|
constructor(opts?: {
|
43
44
|
useAnonymousFallback?: boolean;
|
44
45
|
});
|
@@ -50,6 +51,7 @@ export declare class JazzContextManager<Acc extends Account, P extends JazzConte
|
|
50
51
|
getCurrentValue(): JazzContextType<Acc> | undefined;
|
51
52
|
setCurrentValue(value: JazzContextType<Acc>): void;
|
52
53
|
getAuthSecretStorage(): AuthSecretStorage;
|
54
|
+
getAuthenticatingAccountID(): string | null;
|
53
55
|
logOut: () => Promise<void>;
|
54
56
|
done: () => void;
|
55
57
|
shouldMigrateAnonymousAccount: () => Promise<boolean>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file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iB,oBAA2B;IACtD,SAAS,CAAC,eAAe,UAAS;IAClC,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1C,SAAS,CAAC,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAQ;gBAE5C,IAAI,CAAC,EAAE;QAAE,oBAAoB,CAAC,EAAE,OAAO,CAAA;KAAE;IAQrD,UAAU,IAAI,OAAO;IAIf,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,2BAA2B;IAwB/D,aAAa,CACjB,KAAK,EAAE,CAAC,EACR,SAAS,CAAC,EAAE,2BAA2B,GACtC,OAAO,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC;IAMlC,aAAa,CACjB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,uBAAuB,CAAC,GAAG,CAAC,EACrC,SAAS,CAAC,EAAE,2BAA2B;IA2BzC,YAAY,CAAC,KAAK,EAAE,CAAC;IAKrB,eAAe;IAIf,eAAe,CAAC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC;IAI3C,oBAAoB;IAIpB,0BAA0B;IAI1B,MAAM,sBAeJ;IAEF,IAAI,aAMF;IAEF,6BAA6B,yBAU3B;IAEF;;OAEG;IACH,YAAY,gBAAuB,eAAe,mBA4ChD;IAEF,QAAQ,kBACS,WAAW,iBACX;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,qBAwC/B;YAEY,+BAA+B;IA+C7C,SAAS,YAAiB,IAAI,EAAI;IAClC,SAAS,aAAc,MAAM,IAAI,gBAM/B;IAEF,MAAM;CAKP"}
|
package/package.json
CHANGED
@@ -167,7 +167,7 @@
|
|
167
167
|
},
|
168
168
|
"type": "module",
|
169
169
|
"license": "MIT",
|
170
|
-
"version": "0.18.
|
170
|
+
"version": "0.18.10",
|
171
171
|
"dependencies": {
|
172
172
|
"@manuscripts/prosemirror-recreate-steps": "^0.1.4",
|
173
173
|
"@scure/base": "1.2.1",
|
@@ -184,9 +184,9 @@
|
|
184
184
|
"prosemirror-transform": "^1.9.0",
|
185
185
|
"use-sync-external-store": "^1.5.0",
|
186
186
|
"zod": "3.25.76",
|
187
|
-
"cojson": "0.18.
|
188
|
-
"cojson-storage-indexeddb": "0.18.
|
189
|
-
"cojson-transport-ws": "0.18.
|
187
|
+
"cojson": "0.18.10",
|
188
|
+
"cojson-storage-indexeddb": "0.18.10",
|
189
|
+
"cojson-transport-ws": "0.18.10"
|
190
190
|
},
|
191
191
|
"devDependencies": {
|
192
192
|
"@scure/bip39": "^1.3.0",
|
@@ -2,6 +2,7 @@ import { createAuthClient } from "better-auth/client";
|
|
2
2
|
import type { Account, AuthSecretStorage } from "jazz-tools";
|
3
3
|
import {
|
4
4
|
TestJazzContextManager,
|
5
|
+
createJazzTestAccount,
|
5
6
|
setActiveAccount,
|
6
7
|
setupJazzTestSync,
|
7
8
|
} from "jazz-tools/testing";
|
@@ -334,4 +335,232 @@ describe("Better-Auth client plugin", () => {
|
|
334
335
|
}),
|
335
336
|
);
|
336
337
|
});
|
338
|
+
|
339
|
+
describe("Race condition handling", () => {
|
340
|
+
it("should handle multiple concurrent get-session calls without errors", async () => {
|
341
|
+
const credentials = await authSecretStorage.get();
|
342
|
+
assert(credentials, "Jazz credentials are not available");
|
343
|
+
|
344
|
+
// Mock multiple get-session responses with fresh Response objects
|
345
|
+
customFetchImpl.mockImplementation(() =>
|
346
|
+
Promise.resolve(
|
347
|
+
new Response(
|
348
|
+
JSON.stringify({
|
349
|
+
user: {
|
350
|
+
id: "YW5kcmVpYnVkb2k",
|
351
|
+
email: "test@jazz.dev",
|
352
|
+
name: "andreibudoi",
|
353
|
+
accountID: credentials.accountID,
|
354
|
+
},
|
355
|
+
jazzAuth: {
|
356
|
+
accountID: credentials.accountID,
|
357
|
+
secretSeed: credentials.secretSeed,
|
358
|
+
accountSecret: credentials.accountSecret,
|
359
|
+
provider: "better-auth",
|
360
|
+
},
|
361
|
+
}),
|
362
|
+
),
|
363
|
+
),
|
364
|
+
);
|
365
|
+
|
366
|
+
// Simulate multiple concurrent get-session calls (like during OAuth)
|
367
|
+
const promises = [];
|
368
|
+
for (let i = 0; i < 5; i++) {
|
369
|
+
promises.push(authClient.$fetch("/get-session", { method: "GET" }));
|
370
|
+
}
|
371
|
+
|
372
|
+
// Should complete without errors due to race condition handling
|
373
|
+
await expect(Promise.all(promises)).resolves.toBeDefined();
|
374
|
+
|
375
|
+
// Should have been called multiple times by better-auth
|
376
|
+
expect(customFetchImpl).toHaveBeenCalledTimes(5);
|
377
|
+
|
378
|
+
// User should be authenticated
|
379
|
+
expect(authSecretStorage.isAuthenticated).toBe(true);
|
380
|
+
});
|
381
|
+
|
382
|
+
it("should handle credentials mismatch scenario without errors", async () => {
|
383
|
+
const originalCredentials = await authSecretStorage.get();
|
384
|
+
assert(originalCredentials, "Jazz credentials are not available");
|
385
|
+
|
386
|
+
// Create a test account for the mismatch scenario
|
387
|
+
const testAccount = await createJazzTestAccount();
|
388
|
+
|
389
|
+
// Mock get-session response with different account using fresh Response objects
|
390
|
+
customFetchImpl.mockImplementation(() =>
|
391
|
+
Promise.resolve(
|
392
|
+
new Response(
|
393
|
+
JSON.stringify({
|
394
|
+
user: {
|
395
|
+
id: "RGlmZmVyZW50IFVzZXI",
|
396
|
+
email: "different@jazz.dev",
|
397
|
+
name: "Different User",
|
398
|
+
accountID: testAccount.$jazz.id,
|
399
|
+
},
|
400
|
+
jazzAuth: {
|
401
|
+
accountID: testAccount.$jazz.id,
|
402
|
+
secretSeed: new Uint8Array([4, 5, 6]),
|
403
|
+
accountSecret:
|
404
|
+
testAccount.$jazz.localNode.getCurrentAgent().agentSecret,
|
405
|
+
provider: "better-auth",
|
406
|
+
},
|
407
|
+
}),
|
408
|
+
),
|
409
|
+
),
|
410
|
+
);
|
411
|
+
|
412
|
+
// Simulate multiple concurrent get-session calls with mismatched credentials
|
413
|
+
const promises = [];
|
414
|
+
for (let i = 0; i < 3; i++) {
|
415
|
+
promises.push(authClient.$fetch("/get-session", { method: "GET" }));
|
416
|
+
}
|
417
|
+
|
418
|
+
// Should complete without errors despite credential mismatch
|
419
|
+
await expect(Promise.all(promises)).resolves.toBeDefined();
|
420
|
+
|
421
|
+
// Should have been called multiple times by better-auth
|
422
|
+
expect(customFetchImpl).toHaveBeenCalledTimes(3);
|
423
|
+
|
424
|
+
// Should be authenticated with the new account
|
425
|
+
expect(authSecretStorage.isAuthenticated).toBe(true);
|
426
|
+
const currentCredentials = await authSecretStorage.get();
|
427
|
+
expect(currentCredentials?.accountID).toBe(testAccount.$jazz.id);
|
428
|
+
});
|
429
|
+
|
430
|
+
it("should allow authentication after sign out without being blocked", async () => {
|
431
|
+
const credentials = await authSecretStorage.get();
|
432
|
+
assert(credentials, "Jazz credentials are not available");
|
433
|
+
|
434
|
+
const getSessionResponseData = {
|
435
|
+
user: {
|
436
|
+
id: "123",
|
437
|
+
accountID: credentials.accountID,
|
438
|
+
},
|
439
|
+
jazzAuth: {
|
440
|
+
accountID: credentials.accountID,
|
441
|
+
secretSeed: credentials.secretSeed,
|
442
|
+
accountSecret: credentials.accountSecret,
|
443
|
+
provider: "better-auth",
|
444
|
+
},
|
445
|
+
};
|
446
|
+
|
447
|
+
// First authenticate
|
448
|
+
customFetchImpl.mockResolvedValueOnce(
|
449
|
+
new Response(JSON.stringify(getSessionResponseData)),
|
450
|
+
);
|
451
|
+
|
452
|
+
await authClient.$fetch("/get-session", { method: "GET" });
|
453
|
+
expect(authSecretStorage.isAuthenticated).toBe(true);
|
454
|
+
|
455
|
+
// Then sign out
|
456
|
+
customFetchImpl.mockResolvedValueOnce(
|
457
|
+
new Response(JSON.stringify({ success: true })),
|
458
|
+
);
|
459
|
+
|
460
|
+
await authClient.signOut();
|
461
|
+
expect(authSecretStorage.isAuthenticated).toBe(false);
|
462
|
+
|
463
|
+
// Authenticating again should work without being blocked
|
464
|
+
customFetchImpl.mockResolvedValueOnce(
|
465
|
+
new Response(JSON.stringify(getSessionResponseData)),
|
466
|
+
);
|
467
|
+
|
468
|
+
// Should complete without hanging or errors
|
469
|
+
await expect(
|
470
|
+
authClient.$fetch("/get-session", { method: "GET" }),
|
471
|
+
).resolves.toBeDefined();
|
472
|
+
|
473
|
+
expect(authSecretStorage.isAuthenticated).toBe(true);
|
474
|
+
});
|
475
|
+
|
476
|
+
it("should fail fast when trying to authenticate different accounts concurrently", async () => {
|
477
|
+
const originalCredentials = await authSecretStorage.get();
|
478
|
+
assert(originalCredentials, "Jazz credentials are not available");
|
479
|
+
|
480
|
+
const testAccount1 = await createJazzTestAccount();
|
481
|
+
const testAccount2 = await createJazzTestAccount();
|
482
|
+
const testAccount3 = await createJazzTestAccount();
|
483
|
+
|
484
|
+
const accounts = [testAccount1, testAccount2, testAccount3];
|
485
|
+
let callCount = 0;
|
486
|
+
|
487
|
+
customFetchImpl.mockImplementation(() => {
|
488
|
+
const accountIndex = callCount % 3;
|
489
|
+
const account = accounts[accountIndex]!;
|
490
|
+
callCount++;
|
491
|
+
|
492
|
+
return Promise.resolve(
|
493
|
+
new Response(
|
494
|
+
JSON.stringify({
|
495
|
+
user: {
|
496
|
+
id: `user-${accountIndex + 1}`,
|
497
|
+
email: `user${accountIndex + 1}@jazz.dev`,
|
498
|
+
name: `User ${accountIndex + 1}`,
|
499
|
+
accountID: account.$jazz.id,
|
500
|
+
},
|
501
|
+
jazzAuth: {
|
502
|
+
accountID: account.$jazz.id,
|
503
|
+
secretSeed: new Uint8Array([
|
504
|
+
accountIndex + 1,
|
505
|
+
accountIndex + 2,
|
506
|
+
accountIndex + 3,
|
507
|
+
]),
|
508
|
+
accountSecret:
|
509
|
+
account.$jazz.localNode.getCurrentAgent().agentSecret,
|
510
|
+
provider: "better-auth",
|
511
|
+
},
|
512
|
+
}),
|
513
|
+
),
|
514
|
+
);
|
515
|
+
});
|
516
|
+
|
517
|
+
const promises = [];
|
518
|
+
for (let i = 0; i < 3; i++) {
|
519
|
+
promises.push(authClient.$fetch("/get-session", { method: "GET" }));
|
520
|
+
}
|
521
|
+
|
522
|
+
await expect(Promise.all(promises)).rejects.toThrow();
|
523
|
+
|
524
|
+
expect(customFetchImpl).toHaveBeenCalledTimes(3);
|
525
|
+
});
|
526
|
+
|
527
|
+
it("should deduplicate auth requests for the same account", async () => {
|
528
|
+
const credentials = await authSecretStorage.get();
|
529
|
+
assert(credentials, "Jazz credentials are not available");
|
530
|
+
|
531
|
+
customFetchImpl.mockImplementation(() =>
|
532
|
+
Promise.resolve(
|
533
|
+
new Response(
|
534
|
+
JSON.stringify({
|
535
|
+
user: {
|
536
|
+
id: "test-user",
|
537
|
+
email: "test@jazz.dev",
|
538
|
+
name: "Test User",
|
539
|
+
accountID: credentials.accountID,
|
540
|
+
},
|
541
|
+
jazzAuth: {
|
542
|
+
accountID: credentials.accountID,
|
543
|
+
secretSeed: credentials.secretSeed,
|
544
|
+
accountSecret: credentials.accountSecret,
|
545
|
+
provider: "better-auth",
|
546
|
+
},
|
547
|
+
}),
|
548
|
+
),
|
549
|
+
),
|
550
|
+
);
|
551
|
+
|
552
|
+
const promises = [];
|
553
|
+
for (let i = 0; i < 3; i++) {
|
554
|
+
promises.push(authClient.$fetch("/get-session", { method: "GET" }));
|
555
|
+
}
|
556
|
+
|
557
|
+
await expect(Promise.all(promises)).resolves.toBeDefined();
|
558
|
+
|
559
|
+
expect(customFetchImpl).toHaveBeenCalledTimes(3);
|
560
|
+
|
561
|
+
expect(authSecretStorage.isAuthenticated).toBe(true);
|
562
|
+
const finalCredentials = await authSecretStorage.get();
|
563
|
+
expect(finalCredentials?.accountID).toBe(credentials.accountID);
|
564
|
+
});
|
565
|
+
});
|
337
566
|
});
|
package/src/react/hooks.tsx
CHANGED