@terreno/syncdb 57.21.0 → 58.0.0-beta.2
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/CHANGELOG.md +89 -0
- package/README.md +8 -8
- package/dist/api/apiError.d.ts +43 -0
- package/dist/api/apiError.d.ts.map +1 -0
- package/dist/api/apiError.js +28 -0
- package/dist/api/apiError.js.map +1 -0
- package/dist/api/apiFetch.d.ts +44 -0
- package/dist/api/apiFetch.d.ts.map +1 -0
- package/dist/api/apiFetch.js +203 -0
- package/dist/api/apiFetch.js.map +1 -0
- package/dist/api/client.d.ts +70 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +240 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/client.test.d.ts +2 -0
- package/dist/api/client.test.d.ts.map +1 -0
- package/dist/api/client.test.js +588 -0
- package/dist/api/client.test.js.map +1 -0
- package/dist/app/app.d.ts +13 -0
- package/dist/app/app.d.ts.map +1 -0
- package/dist/app/app.js +13 -0
- package/dist/app/app.js.map +1 -0
- package/dist/app/devConsoleLogger.d.ts +18 -0
- package/dist/app/devConsoleLogger.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.js +147 -0
- package/dist/app/devConsoleLogger.js.map +1 -0
- package/dist/app/devConsoleLogger.test.d.ts +2 -0
- package/dist/app/devConsoleLogger.test.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.test.js +202 -0
- package/dist/app/devConsoleLogger.test.js.map +1 -0
- package/dist/app/mcpTools.d.ts +32 -0
- package/dist/app/mcpTools.d.ts.map +1 -0
- package/dist/app/mcpTools.js +61 -0
- package/dist/app/mcpTools.js.map +1 -0
- package/dist/app/permissions.d.ts +26 -0
- package/dist/app/permissions.d.ts.map +1 -0
- package/dist/app/permissions.js +37 -0
- package/dist/app/permissions.js.map +1 -0
- package/dist/app/permissions.test.d.ts +2 -0
- package/dist/app/permissions.test.d.ts.map +1 -0
- package/dist/app/permissions.test.js +36 -0
- package/dist/app/permissions.test.js.map +1 -0
- package/dist/app/upgradeCheck.d.ts +46 -0
- package/dist/app/upgradeCheck.d.ts.map +1 -0
- package/dist/app/upgradeCheck.js +121 -0
- package/dist/app/upgradeCheck.js.map +1 -0
- package/dist/auth/SessionProvider.d.ts +40 -0
- package/dist/auth/SessionProvider.d.ts.map +1 -0
- package/dist/auth/SessionProvider.js +44 -0
- package/dist/auth/SessionProvider.js.map +1 -0
- package/dist/auth/SessionProvider.test.d.ts +2 -0
- package/dist/auth/SessionProvider.test.d.ts.map +1 -0
- package/dist/auth/SessionProvider.test.js +240 -0
- package/dist/auth/SessionProvider.test.js.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts +25 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js +21 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js.map +1 -0
- package/dist/auth/TerrenoLoginScreen.d.ts +62 -0
- package/dist/auth/TerrenoLoginScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoLoginScreen.js +45 -0
- package/dist/auth/TerrenoLoginScreen.js.map +1 -0
- package/dist/auth/auth.d.ts +36 -0
- package/dist/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth.js +35 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/betterAuthAdapter.d.ts +1 -1
- package/dist/auth/betterAuthClient.d.ts +276 -0
- package/dist/auth/betterAuthClient.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.js +744 -0
- package/dist/auth/betterAuthClient.js.map +1 -0
- package/dist/auth/betterAuthClient.types.test.d.ts +2 -0
- package/dist/auth/betterAuthClient.types.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.types.test.js +151 -0
- package/dist/auth/betterAuthClient.types.test.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.d.ts +51 -0
- package/dist/auth/betterAuthClientRegistry.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.js +69 -0
- package/dist/auth/betterAuthClientRegistry.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts +2 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.js +91 -0
- package/dist/auth/betterAuthClientRegistry.test.js.map +1 -0
- package/dist/auth/betterAuthTypes.d.ts +172 -0
- package/dist/auth/betterAuthTypes.d.ts.map +1 -0
- package/dist/auth/betterAuthTypes.js +7 -0
- package/dist/auth/betterAuthTypes.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.d.ts +102 -0
- package/dist/auth/jwtAuthAdapter.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.js +282 -0
- package/dist/auth/jwtAuthAdapter.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts +2 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.js +614 -0
- package/dist/auth/jwtAuthAdapter.test.js.map +1 -0
- package/dist/auth/loginErrors.d.ts +75 -0
- package/dist/auth/loginErrors.d.ts.map +1 -0
- package/dist/auth/loginErrors.js +154 -0
- package/dist/auth/loginErrors.js.map +1 -0
- package/dist/auth/loginErrors.test.d.ts +2 -0
- package/dist/auth/loginErrors.test.d.ts.map +1 -0
- package/dist/auth/loginErrors.test.js +70 -0
- package/dist/auth/loginErrors.test.js.map +1 -0
- package/dist/auth/ownEntry.d.ts +8 -0
- package/dist/auth/ownEntry.d.ts.map +1 -0
- package/dist/auth/ownEntry.js +13 -0
- package/dist/auth/ownEntry.js.map +1 -0
- package/dist/auth/ownEntry.test.d.ts +2 -0
- package/dist/auth/ownEntry.test.d.ts.map +1 -0
- package/dist/auth/ownEntry.test.js +18 -0
- package/dist/auth/ownEntry.test.js.map +1 -0
- package/dist/auth/platform.d.ts +3 -0
- package/dist/auth/platform.d.ts.map +1 -0
- package/dist/auth/platform.js +4 -0
- package/dist/auth/platform.js.map +1 -0
- package/dist/auth/rememberedAccounts.d.ts +126 -0
- package/dist/auth/rememberedAccounts.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.js +399 -0
- package/dist/auth/rememberedAccounts.js.map +1 -0
- package/dist/auth/rememberedAccounts.test.d.ts +2 -0
- package/dist/auth/rememberedAccounts.test.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.test.js +676 -0
- package/dist/auth/rememberedAccounts.test.js.map +1 -0
- package/dist/auth/session.d.ts +118 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +370 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/session.test.d.ts +2 -0
- package/dist/auth/session.test.d.ts.map +1 -0
- package/dist/auth/session.test.js +825 -0
- package/dist/auth/session.test.js.map +1 -0
- package/dist/auth/tokenExpiry.d.ts +70 -0
- package/dist/auth/tokenExpiry.d.ts.map +1 -0
- package/dist/auth/tokenExpiry.js +123 -0
- package/dist/auth/tokenExpiry.js.map +1 -0
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.js +1 -1
- package/dist/auth/useAccountSecurity.d.ts +183 -0
- package/dist/auth/useAccountSecurity.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.js +399 -0
- package/dist/auth/useAccountSecurity.js.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts +2 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.js +21 -0
- package/dist/auth/useAccountSecurity.types.test.js.map +1 -0
- package/dist/auth/useAuthMethods.d.ts +67 -0
- package/dist/auth/useAuthMethods.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.js +77 -0
- package/dist/auth/useAuthMethods.js.map +1 -0
- package/dist/auth/useAuthMethods.test.d.ts +2 -0
- package/dist/auth/useAuthMethods.test.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.test.js +145 -0
- package/dist/auth/useAuthMethods.test.js.map +1 -0
- package/dist/auth/useJwtAuth.d.ts +31 -0
- package/dist/auth/useJwtAuth.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.js +58 -0
- package/dist/auth/useJwtAuth.js.map +1 -0
- package/dist/auth/useJwtAuth.test.d.ts +2 -0
- package/dist/auth/useJwtAuth.test.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.test.js +165 -0
- package/dist/auth/useJwtAuth.test.js.map +1 -0
- package/dist/auth/useLoginController.d.ts +248 -0
- package/dist/auth/useLoginController.d.ts.map +1 -0
- package/dist/auth/useLoginController.js +671 -0
- package/dist/auth/useLoginController.js.map +1 -0
- package/dist/auth/useLoginController.types.test.d.ts +2 -0
- package/dist/auth/useLoginController.types.test.d.ts.map +1 -0
- package/dist/auth/useLoginController.types.test.js +19 -0
- package/dist/auth/useLoginController.types.test.js.map +1 -0
- package/dist/buildNumber.d.ts +34 -0
- package/dist/buildNumber.d.ts.map +1 -0
- package/dist/buildNumber.js +62 -0
- package/dist/buildNumber.js.map +1 -0
- package/dist/buildNumber.test.d.ts +2 -0
- package/dist/buildNumber.test.d.ts.map +1 -0
- package/dist/buildNumber.test.js +114 -0
- package/dist/buildNumber.test.js.map +1 -0
- package/dist/client.d.ts +18 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +245 -185
- package/dist/client.js.map +1 -1
- package/dist/client.socketEvents.test.d.ts +2 -0
- package/dist/client.socketEvents.test.d.ts.map +1 -0
- package/dist/client.socketEvents.test.js +64 -0
- package/dist/client.socketEvents.test.js.map +1 -0
- package/dist/client.test.js +87 -1
- package/dist/client.test.js.map +1 -1
- package/dist/codegen/cli.js +23 -12
- package/dist/codegen/cli.js.map +1 -1
- package/dist/codegen/cli.test.js +57 -0
- package/dist/codegen/cli.test.js.map +1 -1
- package/dist/codegen/discoverCollections.d.ts.map +1 -1
- package/dist/codegen/discoverCollections.js +4 -0
- package/dist/codegen/discoverCollections.js.map +1 -1
- package/dist/codegen/discoverOperations.d.ts +11 -0
- package/dist/codegen/discoverOperations.d.ts.map +1 -0
- package/dist/codegen/discoverOperations.js +135 -0
- package/dist/codegen/discoverOperations.js.map +1 -0
- package/dist/codegen/emitApi.d.ts +8 -0
- package/dist/codegen/emitApi.d.ts.map +1 -0
- package/dist/codegen/emitApi.js +312 -0
- package/dist/codegen/emitApi.js.map +1 -0
- package/dist/codegen/emitApi.test.d.ts +2 -0
- package/dist/codegen/emitApi.test.d.ts.map +1 -0
- package/dist/codegen/emitApi.test.js +360 -0
- package/dist/codegen/emitApi.test.js.map +1 -0
- package/dist/codegen/emitSdk.js +2 -2
- package/dist/codegen/generate.d.ts +6 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/generate.js +18 -0
- package/dist/codegen/generate.js.map +1 -1
- package/dist/codegen/generate.test.js +53 -1
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/hookNames.d.ts +11 -0
- package/dist/codegen/hookNames.d.ts.map +1 -1
- package/dist/codegen/hookNames.js +23 -0
- package/dist/codegen/hookNames.js.map +1 -1
- package/dist/codegen/safeIdentifiers.d.ts +5 -1
- package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
- package/dist/codegen/safeIdentifiers.js +7 -2
- package/dist/codegen/safeIdentifiers.js.map +1 -1
- package/dist/codegen/safeIdentifiers.test.js +9 -0
- package/dist/codegen/safeIdentifiers.test.js.map +1 -1
- package/dist/codegen/types.d.ts +46 -1
- package/dist/codegen/types.d.ts.map +1 -1
- package/dist/config/baseUrl.d.ts +13 -0
- package/dist/config/baseUrl.d.ts.map +1 -0
- package/dist/config/baseUrl.js +49 -0
- package/dist/config/baseUrl.js.map +1 -0
- package/dist/config/baseUrl.test.d.ts +2 -0
- package/dist/config/baseUrl.test.d.ts.map +1 -0
- package/dist/config/baseUrl.test.js +42 -0
- package/dist/config/baseUrl.test.js.map +1 -0
- package/dist/config/resolveBaseUrls.d.ts +53 -0
- package/dist/config/resolveBaseUrls.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.js +80 -0
- package/dist/config/resolveBaseUrls.js.map +1 -0
- package/dist/config/resolveBaseUrls.test.d.ts +2 -0
- package/dist/config/resolveBaseUrls.test.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.test.js +265 -0
- package/dist/config/resolveBaseUrls.test.js.map +1 -0
- package/dist/crypto/keyProviders.d.ts +2 -2
- package/dist/crypto/keyProviders.d.ts.map +1 -1
- package/dist/crypto/keyProviders.js +15 -4
- package/dist/crypto/keyProviders.js.map +1 -1
- package/dist/crypto/keyProviders.test.js +19 -0
- package/dist/crypto/keyProviders.test.js.map +1 -1
- package/dist/crypto/types.d.ts +5 -0
- package/dist/crypto/types.d.ts.map +1 -1
- package/dist/flags/flagTestServer.d.ts +19 -0
- package/dist/flags/flagTestServer.d.ts.map +1 -0
- package/dist/flags/flagTestServer.js +58 -0
- package/dist/flags/flagTestServer.js.map +1 -0
- package/dist/flags/useFeatureFlags.d.ts +30 -0
- package/dist/flags/useFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.js +83 -0
- package/dist/flags/useFeatureFlags.js.map +1 -0
- package/dist/flags/useFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.test.js +116 -0
- package/dist/flags/useFeatureFlags.test.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts +50 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.js +125 -0
- package/dist/flags/useTerrenoFeatureFlags.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js +259 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js +94 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js +183 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.js +1734 -0
- package/dist/isolated/betterAuthClient.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.js +153 -0
- package/dist/isolated/betterAuthClient.native.isolated.js.map +1 -0
- package/dist/isolated/mcpTools.isolated.d.ts +2 -0
- package/dist/isolated/mcpTools.isolated.d.ts.map +1 -0
- package/dist/isolated/mcpTools.isolated.js +197 -0
- package/dist/isolated/mcpTools.isolated.js.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts +2 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js +50 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js.map +1 -0
- package/dist/isolated/sessionLogout.isolated.d.ts +2 -0
- package/dist/isolated/sessionLogout.isolated.d.ts.map +1 -0
- package/dist/isolated/sessionLogout.isolated.js +133 -0
- package/dist/isolated/sessionLogout.isolated.js.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts +2 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.js +232 -0
- package/dist/isolated/tokenExpiry.isolated.js.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts +2 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.js +241 -0
- package/dist/isolated/upgradeCheck.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.js +851 -0
- package/dist/isolated/useAccountSecurity.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js +52 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js.map +1 -0
- package/dist/isolated/useLoginController.isolated.d.ts +2 -0
- package/dist/isolated/useLoginController.isolated.d.ts.map +1 -0
- package/dist/isolated/useLoginController.isolated.js +1116 -0
- package/dist/isolated/useLoginController.isolated.js.map +1 -0
- package/dist/mutations/entityIds.d.ts +23 -0
- package/dist/mutations/entityIds.d.ts.map +1 -0
- package/dist/mutations/entityIds.js +31 -0
- package/dist/mutations/entityIds.js.map +1 -0
- package/dist/mutations/entityIds.test.d.ts +2 -0
- package/dist/mutations/entityIds.test.d.ts.map +1 -0
- package/dist/mutations/entityIds.test.js +48 -0
- package/dist/mutations/entityIds.test.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -1
- package/dist/persisters/defaultPersisterFactory.native.js +2 -0
- package/dist/persisters/defaultPersisterFactory.native.js.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.js +3 -0
- package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -1
- package/dist/persisters/types.d.ts +6 -0
- package/dist/persisters/types.d.ts.map +1 -1
- package/dist/query/queryWindows.js +2 -2
- package/dist/query/queryWindows.js.map +1 -1
- package/dist/react/apiHooks.d.ts +87 -0
- package/dist/react/apiHooks.d.ts.map +1 -0
- package/dist/react/apiHooks.js +195 -0
- package/dist/react/apiHooks.js.map +1 -0
- package/dist/react/apiHooks.test.d.ts +2 -0
- package/dist/react/apiHooks.test.d.ts.map +1 -0
- package/dist/react/apiHooks.test.js +366 -0
- package/dist/react/apiHooks.test.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +2 -0
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +2 -0
- package/dist/react/provider.js.map +1 -1
- package/dist/react/useSocketEvent.d.ts +27 -0
- package/dist/react/useSocketEvent.d.ts.map +1 -0
- package/dist/react/useSocketEvent.js +36 -0
- package/dist/react/useSocketEvent.js.map +1 -0
- package/dist/react/useSocketEvent.test.d.ts +2 -0
- package/dist/react/useSocketEvent.test.d.ts.map +1 -0
- package/dist/react/useSocketEvent.test.js +76 -0
- package/dist/react/useSocketEvent.test.js.map +1 -0
- package/dist/sync/replayCoordinator.d.ts.map +1 -1
- package/dist/sync/replayCoordinator.js +5 -4
- package/dist/sync/replayCoordinator.js.map +1 -1
- package/dist/sync/socketTransport.d.ts.map +1 -1
- package/dist/sync/socketTransport.js +14 -1
- package/dist/sync/socketTransport.js.map +1 -1
- package/dist/sync/socketTransport.test.js +42 -0
- package/dist/sync/socketTransport.test.js.map +1 -1
- package/dist/sync/transport.d.ts +9 -0
- package/dist/sync/transport.d.ts.map +1 -1
- package/dist/sync/transport.js +13 -0
- package/dist/sync/transport.js.map +1 -1
- package/dist/testing/fakeTransport.d.ts +5 -1
- package/dist/testing/fakeTransport.d.ts.map +1 -1
- package/dist/testing/fakeTransport.js +26 -0
- package/dist/testing/fakeTransport.js.map +1 -1
- package/dist/testing/fakeTransport.test.js +15 -0
- package/dist/testing/fakeTransport.test.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +93 -8
- package/src/api/apiError.ts +47 -0
- package/src/api/apiFetch.ts +245 -0
- package/src/api/client.test.ts +711 -0
- package/src/api/client.ts +367 -0
- package/src/app/app.ts +30 -0
- package/src/app/devConsoleLogger.test.ts +246 -0
- package/src/app/devConsoleLogger.ts +173 -0
- package/src/app/mcpTools.ts +101 -0
- package/src/app/permissions.test.ts +44 -0
- package/src/app/permissions.ts +58 -0
- package/src/app/upgradeCheck.ts +177 -0
- package/src/auth/SessionProvider.test.tsx +286 -0
- package/src/auth/SessionProvider.tsx +87 -0
- package/src/auth/TerrenoAccountSecurityScreen.tsx +56 -0
- package/src/auth/TerrenoLoginScreen.tsx +131 -0
- package/src/auth/auth.ts +117 -0
- package/src/auth/betterAuthAdapter.ts +1 -1
- package/src/auth/betterAuthClient.ts +997 -0
- package/src/auth/betterAuthClient.types.test.ts +197 -0
- package/src/auth/betterAuthClientRegistry.test.ts +114 -0
- package/src/auth/betterAuthClientRegistry.ts +99 -0
- package/src/auth/betterAuthTypes.ts +189 -0
- package/src/auth/jwtAuthAdapter.test.ts +754 -0
- package/src/auth/jwtAuthAdapter.ts +420 -0
- package/src/auth/loginErrors.test.ts +97 -0
- package/src/auth/loginErrors.ts +249 -0
- package/src/auth/ownEntry.test.ts +22 -0
- package/src/auth/ownEntry.ts +15 -0
- package/src/auth/platform.ts +4 -0
- package/src/auth/rememberedAccounts.test.ts +844 -0
- package/src/auth/rememberedAccounts.ts +568 -0
- package/src/auth/session.test.ts +976 -0
- package/src/auth/session.ts +509 -0
- package/src/auth/tokenExpiry.ts +185 -0
- package/src/auth/types.ts +1 -1
- package/src/auth/useAccountSecurity.ts +678 -0
- package/src/auth/useAccountSecurity.types.test.ts +28 -0
- package/src/auth/useAuthMethods.test.ts +181 -0
- package/src/auth/useAuthMethods.ts +137 -0
- package/src/auth/useJwtAuth.test.tsx +202 -0
- package/src/auth/useJwtAuth.ts +102 -0
- package/src/auth/useLoginController.ts +1038 -0
- package/src/auth/useLoginController.types.test.ts +26 -0
- package/src/buildNumber.test.ts +139 -0
- package/src/buildNumber.ts +75 -0
- package/src/client.socketEvents.test.ts +77 -0
- package/src/client.test.ts +109 -1
- package/src/client.ts +104 -19
- package/src/codegen/cli.test.ts +66 -0
- package/src/codegen/cli.ts +23 -12
- package/src/codegen/discoverCollections.ts +4 -0
- package/src/codegen/discoverOperations.ts +172 -0
- package/src/codegen/emitApi.test.tsx +445 -0
- package/src/codegen/emitApi.ts +396 -0
- package/src/codegen/emitSdk.ts +2 -2
- package/src/codegen/fixtures/openapi.api.json +840 -0
- package/src/codegen/generate.test.ts +54 -1
- package/src/codegen/generate.ts +20 -1
- package/src/codegen/hookNames.ts +35 -0
- package/src/codegen/safeIdentifiers.test.ts +20 -0
- package/src/codegen/safeIdentifiers.ts +7 -2
- package/src/codegen/types.ts +45 -1
- package/src/config/baseUrl.test.ts +53 -0
- package/src/config/baseUrl.ts +68 -0
- package/src/config/resolveBaseUrls.test.ts +308 -0
- package/src/config/resolveBaseUrls.ts +118 -0
- package/src/crypto/keyProviders.test.ts +23 -0
- package/src/crypto/keyProviders.ts +15 -4
- package/src/crypto/types.ts +5 -0
- package/src/flags/flagTestServer.ts +77 -0
- package/src/flags/useFeatureFlags.test.tsx +146 -0
- package/src/flags/useFeatureFlags.ts +130 -0
- package/src/flags/useTerrenoFeatureFlags.test.tsx +329 -0
- package/src/flags/useTerrenoFeatureFlags.ts +188 -0
- package/src/index.ts +4 -1
- package/src/isolated/TerrenoAccountSecurityScreen.isolated.tsx +123 -0
- package/src/isolated/TerrenoLoginScreen.isolated.tsx +256 -0
- package/src/isolated/betterAuthClient.isolated.ts +2198 -0
- package/src/isolated/betterAuthClient.native.isolated.ts +173 -0
- package/src/isolated/mcpTools.isolated.ts +259 -0
- package/src/isolated/rememberedAccounts.native.isolated.ts +63 -0
- package/src/isolated/sessionLogout.isolated.ts +152 -0
- package/src/isolated/tokenExpiry.isolated.ts +271 -0
- package/src/isolated/upgradeCheck.isolated.tsx +321 -0
- package/src/isolated/useAccountSecurity.isolated.ts +1089 -0
- package/src/isolated/useAccountSecurity.native.isolated.ts +61 -0
- package/src/isolated/useLoginController.isolated.ts +1384 -0
- package/src/mutations/entityIds.test.ts +55 -0
- package/src/mutations/entityIds.ts +50 -0
- package/src/persisters/defaultPersisterFactory.native.ts +7 -1
- package/src/persisters/encryptedIndexedDbPersister.ts +3 -0
- package/src/persisters/types.ts +6 -0
- package/src/query/queryWindows.ts +2 -2
- package/src/react/apiHooks.test.tsx +473 -0
- package/src/react/apiHooks.tsx +336 -0
- package/src/react/index.ts +2 -0
- package/src/react/provider.tsx +3 -0
- package/src/react/useSocketEvent.test.tsx +96 -0
- package/src/react/useSocketEvent.ts +59 -0
- package/src/sync/replayCoordinator.ts +5 -4
- package/src/sync/socketTransport.test.ts +49 -0
- package/src/sync/socketTransport.ts +15 -0
- package/src/sync/transport.ts +25 -0
- package/src/testing/fakeTransport.test.ts +18 -0
- package/src/testing/fakeTransport.ts +36 -5
- package/src/types.ts +9 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import {afterAll, beforeAll, describe, expect, it} from "bun:test";
|
|
2
|
+
import {act, renderHook, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {createAuthClient} from "better-auth/client";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
6
|
+
import {SessionProvider, useSession} from "./SessionProvider";
|
|
7
|
+
import {
|
|
8
|
+
createSessionStore,
|
|
9
|
+
SESSION_SYNC_ERROR,
|
|
10
|
+
type SessionSource,
|
|
11
|
+
type SessionStoreConfig,
|
|
12
|
+
} from "./session";
|
|
13
|
+
|
|
14
|
+
interface FakeAuthServer {
|
|
15
|
+
/** Better Auth client (real) talking to the in-memory server through its fetch hook. */
|
|
16
|
+
client: ReturnType<typeof createAuthClient>;
|
|
17
|
+
requests: string[];
|
|
18
|
+
/** Make the next get-session request fail at the network layer. */
|
|
19
|
+
failNextGetSession: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const json = (body: unknown): Response =>
|
|
23
|
+
new Response(JSON.stringify(body), {headers: {"content-type": "application/json"}});
|
|
24
|
+
|
|
25
|
+
const requestUrl = (input: unknown): URL => {
|
|
26
|
+
if (input instanceof Request) {
|
|
27
|
+
return new URL(input.url);
|
|
28
|
+
}
|
|
29
|
+
return new URL(String(input));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* In-memory Better Auth server reached through the real Better Auth client's fetch hook, so
|
|
34
|
+
* the tests exercise the real session atom and its sign-in / sign-out session signal.
|
|
35
|
+
*/
|
|
36
|
+
const fakeAuthServer = ({signedInAs}: {signedInAs?: string} = {}): FakeAuthServer => {
|
|
37
|
+
const sessionFor = (userId: string): Record<string, unknown> => ({
|
|
38
|
+
session: {id: `s-${userId}`, token: `tok-${userId}`, userId},
|
|
39
|
+
user: {email: `${userId}@example.com`, id: userId, name: userId},
|
|
40
|
+
});
|
|
41
|
+
let current: Record<string, unknown> | null = signedInAs ? sessionFor(signedInAs) : null;
|
|
42
|
+
let failGetSession = false;
|
|
43
|
+
const requests: string[] = [];
|
|
44
|
+
const customFetchImpl = async (input: unknown, init?: RequestInit): Promise<Response> => {
|
|
45
|
+
const url = requestUrl(input);
|
|
46
|
+
const method = init?.method ?? (input instanceof Request ? input.method : "GET");
|
|
47
|
+
requests.push(`${method} ${url.pathname}`);
|
|
48
|
+
if (url.pathname.endsWith("/get-session")) {
|
|
49
|
+
if (failGetSession) {
|
|
50
|
+
failGetSession = false;
|
|
51
|
+
throw new TypeError("Failed to fetch");
|
|
52
|
+
}
|
|
53
|
+
return json(current);
|
|
54
|
+
}
|
|
55
|
+
if (url.pathname.endsWith("/sign-in/email")) {
|
|
56
|
+
const body = JSON.parse(String(init?.body ?? "{}")) as {email: string};
|
|
57
|
+
const userId = body.email.split("@")[0] ?? "user";
|
|
58
|
+
current = sessionFor(userId);
|
|
59
|
+
return json({token: `tok-${userId}`, user: current.user});
|
|
60
|
+
}
|
|
61
|
+
if (url.pathname.endsWith("/sign-out")) {
|
|
62
|
+
current = null;
|
|
63
|
+
return json({success: true});
|
|
64
|
+
}
|
|
65
|
+
return new Response("{}", {status: 404});
|
|
66
|
+
};
|
|
67
|
+
const client = createAuthClient({
|
|
68
|
+
baseURL: "http://auth.test",
|
|
69
|
+
fetchOptions: {customFetchImpl: customFetchImpl as typeof fetch},
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
client,
|
|
73
|
+
failNextGetSession: (): void => {
|
|
74
|
+
failGetSession = true;
|
|
75
|
+
},
|
|
76
|
+
requests,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const wrapperFor =
|
|
81
|
+
(config: SessionStoreConfig): React.FC<{children: React.ReactNode}> =>
|
|
82
|
+
({children}) => <SessionProvider {...config}>{children}</SessionProvider>;
|
|
83
|
+
|
|
84
|
+
// The Better Auth session atom only fetches in a browser-like environment (`window` defined).
|
|
85
|
+
const globalWithWindow = globalThis as {window?: unknown};
|
|
86
|
+
const hadWindow = "window" in globalWithWindow;
|
|
87
|
+
const originalWindow = globalWithWindow.window;
|
|
88
|
+
|
|
89
|
+
beforeAll(() => {
|
|
90
|
+
globalWithWindow.window = {addEventListener: (): void => {}, removeEventListener: (): void => {}};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
afterAll(async () => {
|
|
94
|
+
// The session atom tears down its window listeners STORE_UNMOUNT_DELAY (1s) after the last
|
|
95
|
+
// subscriber leaves; keep the stub until then so the teardown never runs without `window`.
|
|
96
|
+
await new Promise((resolve) => setTimeout(resolve, 1_100));
|
|
97
|
+
if (hadWindow) {
|
|
98
|
+
globalWithWindow.window = originalWindow;
|
|
99
|
+
} else {
|
|
100
|
+
delete globalWithWindow.window;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("useSession with a Better Auth client", () => {
|
|
105
|
+
it("syncs an existing session on start", async () => {
|
|
106
|
+
const server = fakeAuthServer({signedInAs: "ada"});
|
|
107
|
+
const {result} = renderHook(() => useSession(), {
|
|
108
|
+
wrapper: wrapperFor({authClient: server.client}),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(result.current.isLoading).toBe(true);
|
|
112
|
+
expect(result.current.isAuthenticated).toBe(false);
|
|
113
|
+
|
|
114
|
+
await waitFor(() => expect(result.current.isAuthenticated).toBe(true));
|
|
115
|
+
expect(result.current.userId).toBe("ada");
|
|
116
|
+
expect(result.current.user?.email).toBe("ada@example.com");
|
|
117
|
+
expect(result.current.isLoading).toBe(false);
|
|
118
|
+
expect(result.current.error).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("settles signed out when there is no session", async () => {
|
|
122
|
+
const server = fakeAuthServer();
|
|
123
|
+
const {result} = renderHook(() => useSession(), {
|
|
124
|
+
wrapper: wrapperFor({authClient: server.client}),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
128
|
+
expect(result.current.isAuthenticated).toBe(false);
|
|
129
|
+
expect(result.current.userId).toBeNull();
|
|
130
|
+
expect(result.current.user).toBeNull();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("picks up a sign-in through Better Auth's session signal without a manual refresh", async () => {
|
|
134
|
+
const server = fakeAuthServer();
|
|
135
|
+
const {result} = renderHook(() => useSession(), {
|
|
136
|
+
wrapper: wrapperFor({authClient: server.client}),
|
|
137
|
+
});
|
|
138
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
139
|
+
|
|
140
|
+
await act(async () => {
|
|
141
|
+
await server.client.signIn.email({email: "grace@example.com", password: "pw"});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await waitFor(() => expect(result.current.userId).toBe("grace"));
|
|
145
|
+
expect(result.current.isAuthenticated).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("resolves the new user immediately when refresh() runs after sign-in", async () => {
|
|
149
|
+
const server = fakeAuthServer();
|
|
150
|
+
const {result} = renderHook(() => useSession(), {
|
|
151
|
+
wrapper: wrapperFor({authClient: server.client}),
|
|
152
|
+
});
|
|
153
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
154
|
+
|
|
155
|
+
await act(async () => {
|
|
156
|
+
await server.client.signIn.email({email: "linus@example.com", password: "pw"});
|
|
157
|
+
await result.current.refresh();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
expect(result.current.userId).toBe("linus");
|
|
161
|
+
expect(result.current.isAuthenticated).toBe(true);
|
|
162
|
+
expect(result.current.isLoading).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("logout signs out the auth server, then every syncdb client while the session still names the user, runs onLogout, and clears the session", async () => {
|
|
166
|
+
const server = fakeAuthServer({signedInAs: "ada"});
|
|
167
|
+
const events: string[] = [];
|
|
168
|
+
const isSignedOutOfServer = (): boolean => server.requests.includes("POST /api/auth/sign-out");
|
|
169
|
+
const syncDb = {
|
|
170
|
+
signOut: async (): Promise<void> => {
|
|
171
|
+
events.push(`syncDb.signOut serverSignedOut=${isSignedOutOfServer()}`);
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const adminSyncDb = {
|
|
175
|
+
signOut: async (): Promise<void> => {
|
|
176
|
+
events.push(`adminSyncDb.signOut serverSignedOut=${isSignedOutOfServer()}`);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
const {result} = renderHook(() => useSession(), {
|
|
180
|
+
wrapper: wrapperFor({
|
|
181
|
+
authClient: server.client,
|
|
182
|
+
onLogout: (): void => {
|
|
183
|
+
events.push("onLogout");
|
|
184
|
+
},
|
|
185
|
+
syncDbs: [syncDb, adminSyncDb],
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
await waitFor(() => expect(result.current.userId).toBe("ada"));
|
|
189
|
+
|
|
190
|
+
await act(async () => {
|
|
191
|
+
await result.current.logout();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(server.requests).toContain("POST /api/auth/sign-out");
|
|
195
|
+
expect(events).toEqual([
|
|
196
|
+
"syncDb.signOut serverSignedOut=true",
|
|
197
|
+
"adminSyncDb.signOut serverSignedOut=true",
|
|
198
|
+
"onLogout",
|
|
199
|
+
]);
|
|
200
|
+
expect(result.current.isAuthenticated).toBe(false);
|
|
201
|
+
expect(result.current.userId).toBeNull();
|
|
202
|
+
expect(result.current.user).toBeNull();
|
|
203
|
+
expect(result.current.isLoading).toBe(false);
|
|
204
|
+
expect(result.current.error).toBeNull();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("keeps the session when a background get-session fetch fails (no phantom logout)", async () => {
|
|
208
|
+
const server = fakeAuthServer({signedInAs: "ada"});
|
|
209
|
+
const {result} = renderHook(() => useSession(), {
|
|
210
|
+
wrapper: wrapperFor({authClient: server.client}),
|
|
211
|
+
});
|
|
212
|
+
await waitFor(() => expect(result.current.userId).toBe("ada"));
|
|
213
|
+
|
|
214
|
+
server.failNextGetSession();
|
|
215
|
+
const atom = (
|
|
216
|
+
server.client as unknown as {$store: {atoms: {session: {get: () => {refetch: () => void}}}}}
|
|
217
|
+
).$store.atoms.session;
|
|
218
|
+
await act(async () => {
|
|
219
|
+
atom.get().refetch();
|
|
220
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
expect(result.current.userId).toBe("ada");
|
|
224
|
+
expect(result.current.isAuthenticated).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("SessionProvider", () => {
|
|
229
|
+
it("throws a clear error when useSession runs outside a provider", () => {
|
|
230
|
+
const originalError = console.error;
|
|
231
|
+
console.error = (): void => {};
|
|
232
|
+
try {
|
|
233
|
+
expect(() => renderHook(() => useSession())).toThrow(
|
|
234
|
+
"useSession must be used inside a <SessionProvider>"
|
|
235
|
+
);
|
|
236
|
+
} finally {
|
|
237
|
+
console.error = originalError;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("accepts a pre-built store and starts and stops it with the provider", async () => {
|
|
242
|
+
let subscribed = 0;
|
|
243
|
+
let unsubscribed = 0;
|
|
244
|
+
const source: SessionSource<{id: string}> = {
|
|
245
|
+
getSession: async () => ({user: {id: "u1"}, userId: "u1"}),
|
|
246
|
+
signOut: async (): Promise<void> => {},
|
|
247
|
+
subscribe: () => {
|
|
248
|
+
subscribed += 1;
|
|
249
|
+
return (): void => {
|
|
250
|
+
unsubscribed += 1;
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
const store = createSessionStore({source});
|
|
255
|
+
const {result, unmount} = renderHook(() => useSession<{id: string}>(), {
|
|
256
|
+
wrapper: ({children}) => <SessionProvider store={store}>{children}</SessionProvider>,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await waitFor(() => expect(result.current.userId).toBe("u1"));
|
|
260
|
+
expect(subscribed).toBe(1);
|
|
261
|
+
unmount();
|
|
262
|
+
expect(unsubscribed).toBe(1);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("surfaces a startup sync failure as an error with no session", async () => {
|
|
266
|
+
const originalError = console.error;
|
|
267
|
+
console.error = (): void => {};
|
|
268
|
+
try {
|
|
269
|
+
const source: SessionSource = {
|
|
270
|
+
getSession: async () => {
|
|
271
|
+
throw new Error("network down");
|
|
272
|
+
},
|
|
273
|
+
signOut: async (): Promise<void> => {},
|
|
274
|
+
};
|
|
275
|
+
const {result} = renderHook(() => useSession(), {
|
|
276
|
+
wrapper: wrapperFor({pollIntervalMs: 0, source}),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
280
|
+
expect(result.current.error).toBe(SESSION_SYNC_ERROR);
|
|
281
|
+
expect(result.current.isAuthenticated).toBe(false);
|
|
282
|
+
} finally {
|
|
283
|
+
console.error = originalError;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React binding for {@link createSessionStore}: `SessionProvider` owns (or receives) a session
|
|
3
|
+
* store, starts it on mount, and `useSession()` reads it with `useSyncExternalStore`. No Redux.
|
|
4
|
+
*/
|
|
5
|
+
import type React from "react";
|
|
6
|
+
import {createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore} from "react";
|
|
7
|
+
|
|
8
|
+
import type {BetterAuthUser} from "./betterAuthTypes";
|
|
9
|
+
import {
|
|
10
|
+
createSessionStore,
|
|
11
|
+
type SessionState,
|
|
12
|
+
type SessionStore,
|
|
13
|
+
type SessionStoreConfig,
|
|
14
|
+
} from "./session";
|
|
15
|
+
|
|
16
|
+
/** What `useSession()` returns. */
|
|
17
|
+
export interface UseSessionResult<TUser = BetterAuthUser> extends SessionState<TUser> {
|
|
18
|
+
/** Sign out of the auth server, sign out syncdb clients, run `onLogout`, and clear the session. */
|
|
19
|
+
logout: () => Promise<void>;
|
|
20
|
+
/** Re-read the session now — call after a sign-in to resolve the new user immediately. */
|
|
21
|
+
refresh: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type SessionProviderProps<TUser = BetterAuthUser> = {
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
} & (
|
|
27
|
+
| {
|
|
28
|
+
/** A store created with {@link createSessionStore} (share it with non-React code). */
|
|
29
|
+
store: SessionStore<TUser>;
|
|
30
|
+
}
|
|
31
|
+
| (SessionStoreConfig<TUser> & {store?: undefined})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const SessionContext = createContext<SessionStore<unknown> | null>(null);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Provide session state to the tree. Pass a Better Auth `authClient` (or any `source`), plus
|
|
38
|
+
* optional `syncDbs` / `onLogout` for logout side effects — or a pre-built `store`. The config
|
|
39
|
+
* is read once on mount. The store starts on mount (startup session sync) and stops on unmount.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <SessionProvider authClient={betterAuthClient} syncDbs={[syncDb]}>
|
|
44
|
+
* <App />
|
|
45
|
+
* </SessionProvider>
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export const SessionProvider = <TUser = BetterAuthUser>(
|
|
49
|
+
props: SessionProviderProps<TUser>
|
|
50
|
+
): React.ReactElement => {
|
|
51
|
+
const {children} = props;
|
|
52
|
+
// The config is captured once: rebuilding the store on every render would drop state.
|
|
53
|
+
const [store] = useState((): SessionStore<TUser> => props.store ?? createSessionStore(props));
|
|
54
|
+
|
|
55
|
+
// Watch the session source for the provider's lifetime (startup sync + push updates).
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
store.start();
|
|
58
|
+
return (): void => {
|
|
59
|
+
store.stop();
|
|
60
|
+
};
|
|
61
|
+
}, [store]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<SessionContext.Provider value={store as SessionStore<unknown>}>
|
|
65
|
+
{children}
|
|
66
|
+
</SessionContext.Provider>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** The session store from the nearest `SessionProvider`. Throws outside one. */
|
|
71
|
+
export const useSessionStore = <TUser = BetterAuthUser>(): SessionStore<TUser> => {
|
|
72
|
+
const store = useContext(SessionContext);
|
|
73
|
+
if (!store) {
|
|
74
|
+
throw new Error("useSession must be used inside a <SessionProvider>");
|
|
75
|
+
}
|
|
76
|
+
return store as SessionStore<TUser>;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Current session: `{userId, user, isLoading, isAuthenticated, error, logout, refresh}`. */
|
|
80
|
+
export const useSession = <TUser = BetterAuthUser>(): UseSessionResult<TUser> => {
|
|
81
|
+
const store = useSessionStore<TUser>();
|
|
82
|
+
const state = useSyncExternalStore(store.subscribe, store.getState, store.getState);
|
|
83
|
+
return useMemo(
|
|
84
|
+
(): UseSessionResult<TUser> => ({...state, logout: store.logout, refresh: store.refresh}),
|
|
85
|
+
[state, store]
|
|
86
|
+
);
|
|
87
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A drop-in account security screen connected to a Better Auth client: `@terreno/ui`'s
|
|
3
|
+
* `AccountSecurityScreen` driven by `useAccountSecurity`. Each card shows only when the server
|
|
4
|
+
* has its feature on (`GET {basePath}/terreno/methods`).
|
|
5
|
+
*/
|
|
6
|
+
import type {AccountSecurityScreenProps} from "@terreno/ui";
|
|
7
|
+
import {AccountSecurityScreen} from "@terreno/ui";
|
|
8
|
+
import type {FC} from "react";
|
|
9
|
+
|
|
10
|
+
import {type UseAccountSecurityOptions, useAccountSecurity} from "./useAccountSecurity";
|
|
11
|
+
|
|
12
|
+
export interface TerrenoAccountSecurityScreenProps
|
|
13
|
+
extends UseAccountSecurityOptions,
|
|
14
|
+
Pick<
|
|
15
|
+
AccountSecurityScreenProps,
|
|
16
|
+
"title" | "description" | "header" | "children" | "withPage" | "maxWidth" | "testID"
|
|
17
|
+
> {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Renders the security screen for the signed-in user. See "Drop-in security screen" in
|
|
21
|
+
* docs/how-to/configure-better-auth.md.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <TerrenoAccountSecurityScreen
|
|
26
|
+
* callbackURL="/security"
|
|
27
|
+
* client={authClient}
|
|
28
|
+
* linkError={useLocalSearchParams<{error?: string}>().error}
|
|
29
|
+
* />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const TerrenoAccountSecurityScreen: FC<TerrenoAccountSecurityScreenProps> = ({
|
|
33
|
+
title,
|
|
34
|
+
description,
|
|
35
|
+
header,
|
|
36
|
+
children,
|
|
37
|
+
withPage,
|
|
38
|
+
maxWidth,
|
|
39
|
+
testID,
|
|
40
|
+
...options
|
|
41
|
+
}) => {
|
|
42
|
+
const security = useAccountSecurity(options);
|
|
43
|
+
return (
|
|
44
|
+
<AccountSecurityScreen
|
|
45
|
+
description={description}
|
|
46
|
+
header={header}
|
|
47
|
+
maxWidth={maxWidth}
|
|
48
|
+
testID={testID}
|
|
49
|
+
title={title}
|
|
50
|
+
withPage={withPage}
|
|
51
|
+
{...security.screenProps}
|
|
52
|
+
>
|
|
53
|
+
{children}
|
|
54
|
+
</AccountSecurityScreen>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A drop-in login screen connected to a Better Auth client: `@terreno/ui`'s `LoginScreen` driven
|
|
3
|
+
* by `useLoginController`, with the two-factor challenge inline unless the app routes to its own.
|
|
4
|
+
*/
|
|
5
|
+
import type {LoginFieldConfig, LoginScreenProps} from "@terreno/ui";
|
|
6
|
+
import {Box, LoginScreen, Spinner, TwoFactorChallengeScreen} from "@terreno/ui";
|
|
7
|
+
import {type FC, type ReactNode, useEffect, useRef} from "react";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type LoginControllerStep,
|
|
11
|
+
type UseLoginControllerOptions,
|
|
12
|
+
useLoginController,
|
|
13
|
+
} from "./useLoginController";
|
|
14
|
+
|
|
15
|
+
/** The email and password fields the screen shows unless `fields` is passed. */
|
|
16
|
+
export const DEFAULT_LOGIN_FIELDS: LoginFieldConfig[] = [
|
|
17
|
+
{autoComplete: "username", label: "Email", name: "email", required: true, type: "email"},
|
|
18
|
+
{label: "Password", name: "password", required: true, type: "password"},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export interface TerrenoLoginScreenProps extends UseLoginControllerOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Form fields; their values reach `signIn.email` as `email` and `password`. Left out when the
|
|
24
|
+
* server has email and password sign-in off.
|
|
25
|
+
*/
|
|
26
|
+
fields?: LoginFieldConfig[];
|
|
27
|
+
/** Heading of the login form. */
|
|
28
|
+
title?: string;
|
|
29
|
+
/** Logo shown above the login form and the two-factor challenge. */
|
|
30
|
+
logo?: ReactNode;
|
|
31
|
+
signUpLinkText?: LoginScreenProps["signUpLinkText"];
|
|
32
|
+
forgotPasswordText?: LoginScreenProps["forgotPasswordText"];
|
|
33
|
+
passkeyButtonText?: LoginScreenProps["passkeyButtonText"];
|
|
34
|
+
lastUsedLabel?: LoginScreenProps["lastUsedLabel"];
|
|
35
|
+
/**
|
|
36
|
+
* Shows "Don't ask again on this device for N days" on the inline two-factor challenge. Match
|
|
37
|
+
* the server's `twoFactor.trustDeviceDays`; leave unset to hide it.
|
|
38
|
+
*/
|
|
39
|
+
trustDeviceDays?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Called with each step the screen moves to (`checking`, `login`, `twoFactor`, `signedIn`).
|
|
42
|
+
* An app that already holds a session can use `login` to leave the route, for example when
|
|
43
|
+
* the live-session check failed.
|
|
44
|
+
*/
|
|
45
|
+
onStepChange?: (step: LoginControllerStep) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Root testID of the login screen. The checking spinner is `${testID}-checking`; the inline
|
|
48
|
+
* challenge keeps `TwoFactorChallengeScreen`'s own `two-factor-challenge`.
|
|
49
|
+
* @default "login-screen"
|
|
50
|
+
*/
|
|
51
|
+
testID?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Renders the right step: a spinner while a live session is checked (a valid one calls
|
|
56
|
+
* `onSignedIn` and never shows the form), the login screen, or the inline two-factor challenge.
|
|
57
|
+
* See "Drop-in login screen" in docs/how-to/configure-better-auth.md.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* <TerrenoLoginScreen
|
|
62
|
+
* client={authClient}
|
|
63
|
+
* error={useLocalSearchParams<{error?: string}>().error}
|
|
64
|
+
* onSignUpPress={() => router.push("/signup")}
|
|
65
|
+
* onSignedIn={async () => {
|
|
66
|
+
* await betterAuth.syncSession(store.dispatch);
|
|
67
|
+
* router.replace("/");
|
|
68
|
+
* }}
|
|
69
|
+
* rememberedAccounts={rememberedAccounts}
|
|
70
|
+
* />
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const TerrenoLoginScreen: FC<TerrenoLoginScreenProps> = ({
|
|
74
|
+
fields = DEFAULT_LOGIN_FIELDS,
|
|
75
|
+
title,
|
|
76
|
+
logo,
|
|
77
|
+
signUpLinkText,
|
|
78
|
+
forgotPasswordText,
|
|
79
|
+
passkeyButtonText,
|
|
80
|
+
lastUsedLabel,
|
|
81
|
+
trustDeviceDays,
|
|
82
|
+
onStepChange,
|
|
83
|
+
testID = "login-screen",
|
|
84
|
+
...options
|
|
85
|
+
}) => {
|
|
86
|
+
const controller = useLoginController(options);
|
|
87
|
+
|
|
88
|
+
// Reports each new step; the latest callback is read so a new function does not re-report.
|
|
89
|
+
const onStepChangeRef = useRef(onStepChange);
|
|
90
|
+
onStepChangeRef.current = onStepChange;
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
onStepChangeRef.current?.(controller.step);
|
|
93
|
+
}, [controller.step]);
|
|
94
|
+
|
|
95
|
+
if (controller.step === "checking" || controller.step === "signedIn") {
|
|
96
|
+
return (
|
|
97
|
+
<Box alignItems="center" flex="grow" justifyContent="center" testID={`${testID}-checking`}>
|
|
98
|
+
<Spinner />
|
|
99
|
+
</Box>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (controller.step === "twoFactor") {
|
|
104
|
+
return (
|
|
105
|
+
<TwoFactorChallengeScreen
|
|
106
|
+
accountLabel={controller.twoFactor.accountLabel}
|
|
107
|
+
error={controller.twoFactor.error}
|
|
108
|
+
initialTrustDevice={controller.twoFactor.initialTrustDevice}
|
|
109
|
+
loading={controller.twoFactor.loading}
|
|
110
|
+
logo={logo}
|
|
111
|
+
onCancel={controller.twoFactor.onCancel}
|
|
112
|
+
onSubmit={controller.twoFactor.onSubmit}
|
|
113
|
+
trustDeviceDays={trustDeviceDays}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<LoginScreen
|
|
120
|
+
fields={controller.isEmailPasswordEnabled ? fields : []}
|
|
121
|
+
forgotPasswordText={forgotPasswordText}
|
|
122
|
+
lastUsedLabel={lastUsedLabel}
|
|
123
|
+
logo={logo}
|
|
124
|
+
passkeyButtonText={passkeyButtonText}
|
|
125
|
+
signUpLinkText={signUpLinkText}
|
|
126
|
+
testID={testID}
|
|
127
|
+
title={title}
|
|
128
|
+
{...controller.screenProps}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
};
|
package/src/auth/auth.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@terreno/syncdb/auth` — Better Auth client and session state without Redux.
|
|
3
|
+
*
|
|
4
|
+
* - `createBetterAuthClient` builds the Expo-ready Better Auth client (SecureStore on native,
|
|
5
|
+
* AsyncStorage on web, cookie-jar repair).
|
|
6
|
+
* - `SessionProvider` / `useSession()` expose `{userId, user, isLoading, isAuthenticated,
|
|
7
|
+
* error, logout, refresh}`; `createSessionStore` is the framework-agnostic core.
|
|
8
|
+
* - `betterAuthAdapter` / `bridgeBetterAuthReactClient` feed the same client to `createSyncDb`
|
|
9
|
+
* and `createApiClient` as their `AuthProvider`.
|
|
10
|
+
* - `useLoginController` / `TerrenoLoginScreen` / `useAccountSecurity` /
|
|
11
|
+
* `TerrenoAccountSecurityScreen` drive social login, account linking, two-factor, passkeys, and
|
|
12
|
+
* remembered accounts; `useAuthMethods` reads the server's enabled sign-in methods.
|
|
13
|
+
* - `jwtAuthAdapter` / `useJwtAuth` are the legacy `@terreno/api` JWT equivalent (token
|
|
14
|
+
* storage, refresh before expiry and on 401, logout on refresh failure), and
|
|
15
|
+
* `getTokenExpirationTimes` / `shouldShowStillThereModal` read its stored tokens.
|
|
16
|
+
*
|
|
17
|
+
* Requires the optional peers `better-auth`, `@better-auth/expo`, `expo-secure-store`,
|
|
18
|
+
* `@react-native-async-storage/async-storage`, and `react`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
type BetterAuthAdapterOptions,
|
|
23
|
+
betterAuthAdapter,
|
|
24
|
+
DEFAULT_AUTH_POLL_INTERVAL_MS,
|
|
25
|
+
} from "./betterAuthAdapter";
|
|
26
|
+
export {
|
|
27
|
+
type BetterAuthClient,
|
|
28
|
+
type BetterAuthClientFor,
|
|
29
|
+
type BetterAuthClientWithFeatures,
|
|
30
|
+
type BetterAuthFeaturePlugins,
|
|
31
|
+
type BetterAuthHandoffClient,
|
|
32
|
+
completeBetterAuthOAuthHandoff,
|
|
33
|
+
createBetterAuthClient,
|
|
34
|
+
createStorageAdapter,
|
|
35
|
+
type ExpoAuthClientPlugin,
|
|
36
|
+
getBetterAuthBearerToken,
|
|
37
|
+
getBetterAuthClientWebAuth,
|
|
38
|
+
repairCookieJar,
|
|
39
|
+
type StorageAdapter,
|
|
40
|
+
signInSocialWithHandoff,
|
|
41
|
+
withCookieJarRepair,
|
|
42
|
+
} from "./betterAuthClient";
|
|
43
|
+
export {type BetterAuthReactClientLike, bridgeBetterAuthReactClient} from "./betterAuthReactClient";
|
|
44
|
+
export type {
|
|
45
|
+
BetterAuthBearerStorage,
|
|
46
|
+
BetterAuthClientConfig,
|
|
47
|
+
BetterAuthClientFeatures,
|
|
48
|
+
BetterAuthOAuthProvider,
|
|
49
|
+
BetterAuthSession,
|
|
50
|
+
BetterAuthSessionClientLike,
|
|
51
|
+
BetterAuthSessionData,
|
|
52
|
+
BetterAuthTwoFactorFeature,
|
|
53
|
+
BetterAuthTwoFactorRedirectContext,
|
|
54
|
+
BetterAuthUser,
|
|
55
|
+
BetterAuthWebAuth,
|
|
56
|
+
} from "./betterAuthTypes";
|
|
57
|
+
export {
|
|
58
|
+
DEFAULT_JWT_AUTH_PATHS,
|
|
59
|
+
DEFAULT_JWT_AUTH_TIMEOUT_MS,
|
|
60
|
+
DEFAULT_REFRESH_BEFORE_EXPIRY_SECS,
|
|
61
|
+
type EmailLoginRequest,
|
|
62
|
+
type EmailSignupRequest,
|
|
63
|
+
type GoogleLoginRequest,
|
|
64
|
+
type JwtAuthAdapter,
|
|
65
|
+
type JwtAuthAdapterOptions,
|
|
66
|
+
type JwtAuthPaths,
|
|
67
|
+
type JwtAuthResponse,
|
|
68
|
+
type JwtSessionUser,
|
|
69
|
+
jwtAuthAdapter,
|
|
70
|
+
type ResetPasswordRequest,
|
|
71
|
+
} from "./jwtAuthAdapter";
|
|
72
|
+
export * from "./loginErrors";
|
|
73
|
+
export * from "./rememberedAccounts";
|
|
74
|
+
export {
|
|
75
|
+
SessionProvider,
|
|
76
|
+
type SessionProviderProps,
|
|
77
|
+
type UseSessionResult,
|
|
78
|
+
useSession,
|
|
79
|
+
useSessionStore,
|
|
80
|
+
} from "./SessionProvider";
|
|
81
|
+
export {
|
|
82
|
+
betterAuthSessionSource,
|
|
83
|
+
createSessionStore,
|
|
84
|
+
DEFAULT_SESSION_POLL_INTERVAL_MS,
|
|
85
|
+
DEFAULT_SIGN_OUT_TIMEOUT_MS,
|
|
86
|
+
SESSION_SYNC_ERROR,
|
|
87
|
+
type SessionChangeListener,
|
|
88
|
+
type SessionSnapshot,
|
|
89
|
+
type SessionSource,
|
|
90
|
+
type SessionState,
|
|
91
|
+
type SessionStore,
|
|
92
|
+
type SessionStoreConfig,
|
|
93
|
+
type SessionSyncDb,
|
|
94
|
+
SIGN_OUT_FAILED_MESSAGE,
|
|
95
|
+
} from "./session";
|
|
96
|
+
export * from "./TerrenoAccountSecurityScreen";
|
|
97
|
+
export * from "./TerrenoLoginScreen";
|
|
98
|
+
export {
|
|
99
|
+
AUTH_TOKEN_KEY,
|
|
100
|
+
createJwtTokenStorage,
|
|
101
|
+
decodeJwtClaims,
|
|
102
|
+
getDefaultJwtTokenStorage,
|
|
103
|
+
getTokenExpirationTimes,
|
|
104
|
+
type JwtClaims,
|
|
105
|
+
type JwtTokenStorage,
|
|
106
|
+
type JwtTokens,
|
|
107
|
+
REFRESH_TOKEN_KEY,
|
|
108
|
+
readJwtTokens,
|
|
109
|
+
STILL_THERE_THRESHOLD_SECS,
|
|
110
|
+
shouldShowStillThereModal,
|
|
111
|
+
type TokenExpirationTimes,
|
|
112
|
+
tokenExpirationTimesFor,
|
|
113
|
+
} from "./tokenExpiry";
|
|
114
|
+
export * from "./useAccountSecurity";
|
|
115
|
+
export * from "./useAuthMethods";
|
|
116
|
+
export {type UseJwtAuthResult, useJwtAuth} from "./useJwtAuth";
|
|
117
|
+
export * from "./useLoginController";
|
|
@@ -17,7 +17,7 @@ export interface BetterAuthAdapterOptions {
|
|
|
17
17
|
clearIntervalFn?: (handle: unknown) => void;
|
|
18
18
|
/**
|
|
19
19
|
* Synchronous bearer-token reader, for clients that keep the session token locally
|
|
20
|
-
* (for example
|
|
20
|
+
* (for example `getBetterAuthBearerToken` from `@terreno/syncdb/auth` in web bearer mode). When it returns a
|
|
21
21
|
* token, `getToken` uses it without calling `getSession()`. A null or empty result, or a
|
|
22
22
|
* throw, falls back to reading `getSession()`. `getUserId`, `onAuthChange` and `refresh`
|
|
23
23
|
* always read the session.
|