@terreno/syncdb 57.20.0 → 58.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/README.md +7 -7
- 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 +10 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +237 -184
- 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 +60 -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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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/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.js +1 -1
- 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/package.json +96 -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 +73 -1
- package/src/client.ts +87 -18
- 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 +2 -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/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 +1 -1
- 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
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import { betterAuthSessionSource, createSessionStore, DEFAULT_SESSION_POLL_INTERVAL_MS, SESSION_SYNC_ERROR, SIGN_OUT_FAILED_MESSAGE, } from "./session";
|
|
3
|
+
const flush = async () => {
|
|
4
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
5
|
+
};
|
|
6
|
+
const snapshot = (id, name = id) => ({ user: { id, name }, userId: id });
|
|
7
|
+
/** A controllable session source: tests set what the "server" returns and push changes. */
|
|
8
|
+
const makeSource = (initial, { withSubscribe = true } = {}) => {
|
|
9
|
+
let current = initial;
|
|
10
|
+
let readCount = 0;
|
|
11
|
+
let signOutCount = 0;
|
|
12
|
+
let shouldFailSignOut = false;
|
|
13
|
+
const listeners = new Set();
|
|
14
|
+
const source = {
|
|
15
|
+
getSession: async () => {
|
|
16
|
+
readCount += 1;
|
|
17
|
+
if (current instanceof Error) {
|
|
18
|
+
throw current;
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
},
|
|
22
|
+
signOut: async () => {
|
|
23
|
+
signOutCount += 1;
|
|
24
|
+
if (shouldFailSignOut) {
|
|
25
|
+
throw new Error("sign-out failed");
|
|
26
|
+
}
|
|
27
|
+
current = null;
|
|
28
|
+
},
|
|
29
|
+
...(withSubscribe
|
|
30
|
+
? {
|
|
31
|
+
subscribe: (listener) => {
|
|
32
|
+
listeners.add(listener);
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(listener);
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
: {}),
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
failSignOut: () => {
|
|
42
|
+
shouldFailSignOut = true;
|
|
43
|
+
},
|
|
44
|
+
push: (value) => {
|
|
45
|
+
for (const listener of listeners) {
|
|
46
|
+
listener(value);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
reads: () => readCount,
|
|
50
|
+
set: (next) => {
|
|
51
|
+
current = next;
|
|
52
|
+
},
|
|
53
|
+
signOuts: () => signOutCount,
|
|
54
|
+
source,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const makeTimers = () => {
|
|
58
|
+
const handlers = new Map();
|
|
59
|
+
let nextHandle = 1;
|
|
60
|
+
let lastMs;
|
|
61
|
+
let cleared = 0;
|
|
62
|
+
return {
|
|
63
|
+
cleared: () => cleared,
|
|
64
|
+
lastMs: () => lastMs,
|
|
65
|
+
options: {
|
|
66
|
+
clearIntervalFn: (handle) => {
|
|
67
|
+
cleared += 1;
|
|
68
|
+
handlers.delete(handle);
|
|
69
|
+
},
|
|
70
|
+
setIntervalFn: (handler, ms) => {
|
|
71
|
+
lastMs = ms;
|
|
72
|
+
const handle = nextHandle;
|
|
73
|
+
nextHandle += 1;
|
|
74
|
+
handlers.set(handle, handler);
|
|
75
|
+
return handle;
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
tick: async () => {
|
|
79
|
+
for (const handler of handlers.values()) {
|
|
80
|
+
handler();
|
|
81
|
+
}
|
|
82
|
+
await flush();
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const silenceConsole = () => {
|
|
87
|
+
const original = { debug: console.debug, error: console.error, warn: console.warn };
|
|
88
|
+
console.error = () => { };
|
|
89
|
+
console.warn = () => { };
|
|
90
|
+
console.debug = () => { };
|
|
91
|
+
return () => {
|
|
92
|
+
console.error = original.error;
|
|
93
|
+
console.warn = original.warn;
|
|
94
|
+
console.debug = original.debug;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
describe("createSessionStore", () => {
|
|
98
|
+
let restoreConsole;
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
restoreConsole = silenceConsole();
|
|
101
|
+
});
|
|
102
|
+
afterEach(() => {
|
|
103
|
+
restoreConsole();
|
|
104
|
+
});
|
|
105
|
+
it("starts loading and signed out before the first sync", () => {
|
|
106
|
+
const { source } = makeSource(snapshot("u1"));
|
|
107
|
+
const store = createSessionStore({ source });
|
|
108
|
+
expect(store.getState()).toEqual({
|
|
109
|
+
error: null,
|
|
110
|
+
isAuthenticated: false,
|
|
111
|
+
isLoading: true,
|
|
112
|
+
isSigningOut: false,
|
|
113
|
+
user: null,
|
|
114
|
+
userId: null,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it("syncs the session on start and notifies subscribers", async () => {
|
|
118
|
+
const { source } = makeSource(snapshot("u1", "Ada"));
|
|
119
|
+
const store = createSessionStore({ source });
|
|
120
|
+
let notifications = 0;
|
|
121
|
+
store.subscribe(() => {
|
|
122
|
+
notifications += 1;
|
|
123
|
+
});
|
|
124
|
+
store.start();
|
|
125
|
+
await flush();
|
|
126
|
+
expect(store.getState()).toEqual({
|
|
127
|
+
error: null,
|
|
128
|
+
isAuthenticated: true,
|
|
129
|
+
isLoading: false,
|
|
130
|
+
isSigningOut: false,
|
|
131
|
+
user: { id: "u1", name: "Ada" },
|
|
132
|
+
userId: "u1",
|
|
133
|
+
});
|
|
134
|
+
expect(notifications).toBeGreaterThan(0);
|
|
135
|
+
});
|
|
136
|
+
it("is idempotent on start and restartable after stop", async () => {
|
|
137
|
+
const fake = makeSource(snapshot("u1"));
|
|
138
|
+
const store = createSessionStore({ source: fake.source });
|
|
139
|
+
store.start();
|
|
140
|
+
store.start();
|
|
141
|
+
await flush();
|
|
142
|
+
expect(fake.reads()).toBe(1);
|
|
143
|
+
store.stop();
|
|
144
|
+
store.stop();
|
|
145
|
+
store.start();
|
|
146
|
+
await flush();
|
|
147
|
+
expect(fake.reads()).toBe(2);
|
|
148
|
+
});
|
|
149
|
+
it("applies pushed snapshots directly and skips identical ones", async () => {
|
|
150
|
+
const fake = makeSource(null);
|
|
151
|
+
const store = createSessionStore({ source: fake.source });
|
|
152
|
+
store.start();
|
|
153
|
+
await flush();
|
|
154
|
+
const signedOut = store.getState();
|
|
155
|
+
fake.push(null);
|
|
156
|
+
expect(store.getState()).toBe(signedOut);
|
|
157
|
+
fake.push(snapshot("u2"));
|
|
158
|
+
const signedIn = store.getState();
|
|
159
|
+
expect(signedIn.userId).toBe("u2");
|
|
160
|
+
fake.push(snapshot("u2"));
|
|
161
|
+
expect(store.getState()).toBe(signedIn);
|
|
162
|
+
fake.push(snapshot("u2", "Renamed"));
|
|
163
|
+
expect(store.getState().user?.name).toBe("Renamed");
|
|
164
|
+
});
|
|
165
|
+
it("re-reads the session when the source pushes an opaque change", async () => {
|
|
166
|
+
const fake = makeSource(null);
|
|
167
|
+
const store = createSessionStore({ source: fake.source });
|
|
168
|
+
store.start();
|
|
169
|
+
await flush();
|
|
170
|
+
fake.set(snapshot("u3"));
|
|
171
|
+
fake.push(undefined);
|
|
172
|
+
await flush();
|
|
173
|
+
expect(store.getState().userId).toBe("u3");
|
|
174
|
+
});
|
|
175
|
+
it("ignores pushes after stop", async () => {
|
|
176
|
+
const fake = makeSource(null);
|
|
177
|
+
const store = createSessionStore({ source: fake.source });
|
|
178
|
+
store.start();
|
|
179
|
+
await flush();
|
|
180
|
+
const unsubscribedListenerCalls = store.getState();
|
|
181
|
+
store.stop();
|
|
182
|
+
fake.push(snapshot("u1"));
|
|
183
|
+
expect(store.getState()).toBe(unsubscribedListenerCalls);
|
|
184
|
+
});
|
|
185
|
+
it("drops a read that resolves after a newer pushed snapshot", async () => {
|
|
186
|
+
let resolveRead;
|
|
187
|
+
const listeners = new Set();
|
|
188
|
+
const source = {
|
|
189
|
+
getSession: () => new Promise((resolve) => {
|
|
190
|
+
resolveRead = resolve;
|
|
191
|
+
}),
|
|
192
|
+
signOut: async () => { },
|
|
193
|
+
subscribe: (listener) => {
|
|
194
|
+
listeners.add(listener);
|
|
195
|
+
return () => { };
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
const store = createSessionStore({ source });
|
|
199
|
+
store.start();
|
|
200
|
+
for (const listener of listeners) {
|
|
201
|
+
listener(snapshot("new"));
|
|
202
|
+
}
|
|
203
|
+
resolveRead?.(snapshot("stale"));
|
|
204
|
+
await flush();
|
|
205
|
+
expect(store.getState().userId).toBe("new");
|
|
206
|
+
});
|
|
207
|
+
it("drops a read that resolves after stop", async () => {
|
|
208
|
+
let resolveRead;
|
|
209
|
+
const source = {
|
|
210
|
+
getSession: () => new Promise((resolve) => {
|
|
211
|
+
resolveRead = resolve;
|
|
212
|
+
}),
|
|
213
|
+
signOut: async () => { },
|
|
214
|
+
};
|
|
215
|
+
const store = createSessionStore({ pollIntervalMs: 0, source });
|
|
216
|
+
store.start();
|
|
217
|
+
store.stop();
|
|
218
|
+
resolveRead?.(snapshot("late"));
|
|
219
|
+
await flush();
|
|
220
|
+
expect(store.getState().isLoading).toBe(true);
|
|
221
|
+
expect(store.getState().userId).toBeNull();
|
|
222
|
+
});
|
|
223
|
+
it("records an error and clears the session when an explicit sync fails", async () => {
|
|
224
|
+
const fake = makeSource(snapshot("u1"));
|
|
225
|
+
const store = createSessionStore({ source: fake.source });
|
|
226
|
+
store.start();
|
|
227
|
+
await flush();
|
|
228
|
+
expect(store.getState().isAuthenticated).toBe(true);
|
|
229
|
+
fake.set(new Error("network down"));
|
|
230
|
+
await store.refresh();
|
|
231
|
+
expect(store.getState()).toEqual({
|
|
232
|
+
error: SESSION_SYNC_ERROR,
|
|
233
|
+
isAuthenticated: false,
|
|
234
|
+
isLoading: false,
|
|
235
|
+
isSigningOut: false,
|
|
236
|
+
user: null,
|
|
237
|
+
userId: null,
|
|
238
|
+
});
|
|
239
|
+
// A later successful sync clears the error.
|
|
240
|
+
fake.set(snapshot("u1"));
|
|
241
|
+
await store.refresh();
|
|
242
|
+
expect(store.getState().error).toBeNull();
|
|
243
|
+
expect(store.getState().userId).toBe("u1");
|
|
244
|
+
});
|
|
245
|
+
it("drops a failed read that resolves after a newer pushed snapshot", async () => {
|
|
246
|
+
let rejectRead;
|
|
247
|
+
const listeners = new Set();
|
|
248
|
+
const source = {
|
|
249
|
+
getSession: () => new Promise((_resolve, reject) => {
|
|
250
|
+
rejectRead = reject;
|
|
251
|
+
}),
|
|
252
|
+
signOut: async () => { },
|
|
253
|
+
subscribe: (listener) => {
|
|
254
|
+
listeners.add(listener);
|
|
255
|
+
return () => { };
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
const store = createSessionStore({ source });
|
|
259
|
+
store.start();
|
|
260
|
+
for (const listener of listeners) {
|
|
261
|
+
listener(snapshot("pushed"));
|
|
262
|
+
}
|
|
263
|
+
rejectRead?.(new Error("late failure"));
|
|
264
|
+
await flush();
|
|
265
|
+
expect(store.getState().userId).toBe("pushed");
|
|
266
|
+
expect(store.getState().error).toBeNull();
|
|
267
|
+
});
|
|
268
|
+
it("marks the state loading during refresh()", async () => {
|
|
269
|
+
const fake = makeSource(snapshot("u1"));
|
|
270
|
+
const store = createSessionStore({ source: fake.source });
|
|
271
|
+
store.start();
|
|
272
|
+
await flush();
|
|
273
|
+
const refreshing = store.refresh();
|
|
274
|
+
expect(store.getState().isLoading).toBe(true);
|
|
275
|
+
await refreshing;
|
|
276
|
+
expect(store.getState().isLoading).toBe(false);
|
|
277
|
+
expect(store.getState().userId).toBe("u1");
|
|
278
|
+
});
|
|
279
|
+
describe("polling fallback (source without subscribe)", () => {
|
|
280
|
+
it("polls at the default cadence and picks up a login", async () => {
|
|
281
|
+
const fake = makeSource(null, { withSubscribe: false });
|
|
282
|
+
const timers = makeTimers();
|
|
283
|
+
const store = createSessionStore({ source: fake.source, ...timers.options });
|
|
284
|
+
store.start();
|
|
285
|
+
await flush();
|
|
286
|
+
expect(timers.lastMs()).toBe(DEFAULT_SESSION_POLL_INTERVAL_MS);
|
|
287
|
+
expect(store.getState().isAuthenticated).toBe(false);
|
|
288
|
+
fake.set(snapshot("u1"));
|
|
289
|
+
await timers.tick();
|
|
290
|
+
expect(store.getState().userId).toBe("u1");
|
|
291
|
+
store.stop();
|
|
292
|
+
expect(timers.cleared()).toBe(1);
|
|
293
|
+
});
|
|
294
|
+
it("keeps the current session when a poll fails", async () => {
|
|
295
|
+
const fake = makeSource(snapshot("u1"), { withSubscribe: false });
|
|
296
|
+
const timers = makeTimers();
|
|
297
|
+
const store = createSessionStore({
|
|
298
|
+
pollIntervalMs: 50,
|
|
299
|
+
source: fake.source,
|
|
300
|
+
...timers.options,
|
|
301
|
+
});
|
|
302
|
+
store.start();
|
|
303
|
+
await flush();
|
|
304
|
+
expect(timers.lastMs()).toBe(50);
|
|
305
|
+
fake.set(new Error("network down"));
|
|
306
|
+
await timers.tick();
|
|
307
|
+
expect(store.getState().userId).toBe("u1");
|
|
308
|
+
expect(store.getState().error).toBeNull();
|
|
309
|
+
});
|
|
310
|
+
it("does not poll when pollIntervalMs is 0", async () => {
|
|
311
|
+
const fake = makeSource(null, { withSubscribe: false });
|
|
312
|
+
const timers = makeTimers();
|
|
313
|
+
const store = createSessionStore({ pollIntervalMs: 0, source: fake.source, ...timers.options });
|
|
314
|
+
store.start();
|
|
315
|
+
await flush();
|
|
316
|
+
store.stop();
|
|
317
|
+
expect(timers.lastMs()).toBeUndefined();
|
|
318
|
+
expect(timers.cleared()).toBe(0);
|
|
319
|
+
});
|
|
320
|
+
it("uses the global timers by default", async () => {
|
|
321
|
+
const fake = makeSource(snapshot("u1"), { withSubscribe: false });
|
|
322
|
+
const store = createSessionStore({ pollIntervalMs: 5, source: fake.source });
|
|
323
|
+
store.start();
|
|
324
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
325
|
+
store.stop();
|
|
326
|
+
expect(fake.reads()).toBeGreaterThan(1);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
describe("logout", () => {
|
|
330
|
+
it("signs out the source, then syncdb clients in order, runs onLogout, and clears", async () => {
|
|
331
|
+
const fake = makeSource(snapshot("u1"));
|
|
332
|
+
const events = [];
|
|
333
|
+
const source = {
|
|
334
|
+
...fake.source,
|
|
335
|
+
signOut: async () => {
|
|
336
|
+
events.push("source");
|
|
337
|
+
await fake.source.signOut();
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
const store = createSessionStore({
|
|
341
|
+
onLogout: async () => {
|
|
342
|
+
events.push("onLogout");
|
|
343
|
+
},
|
|
344
|
+
source,
|
|
345
|
+
syncDbs: [
|
|
346
|
+
{
|
|
347
|
+
signOut: async () => {
|
|
348
|
+
events.push("a");
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
signOut: async () => {
|
|
353
|
+
events.push("b");
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
});
|
|
358
|
+
store.start();
|
|
359
|
+
await flush();
|
|
360
|
+
await store.logout();
|
|
361
|
+
expect(fake.signOuts()).toBe(1);
|
|
362
|
+
expect(events).toEqual(["source", "a", "b", "onLogout"]);
|
|
363
|
+
expect(store.getState()).toEqual({
|
|
364
|
+
error: null,
|
|
365
|
+
isAuthenticated: false,
|
|
366
|
+
isLoading: false,
|
|
367
|
+
isSigningOut: false,
|
|
368
|
+
user: null,
|
|
369
|
+
userId: null,
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
it("signs syncdb clients out while the session still names the user", async () => {
|
|
373
|
+
// Better Auth pushes the signed-out session as soon as the server sign-out lands; apps
|
|
374
|
+
// stop syncdb when userId clears, which would forget the user before the wipe.
|
|
375
|
+
const fake = makeSource(snapshot("u1"));
|
|
376
|
+
const source = {
|
|
377
|
+
...fake.source,
|
|
378
|
+
signOut: async () => {
|
|
379
|
+
await fake.source.signOut();
|
|
380
|
+
fake.push(null);
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
const userIdsAtSyncSignOut = [];
|
|
384
|
+
const store = createSessionStore({
|
|
385
|
+
source,
|
|
386
|
+
syncDbs: [
|
|
387
|
+
{
|
|
388
|
+
signOut: async () => {
|
|
389
|
+
userIdsAtSyncSignOut.push(store.getState().userId);
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
});
|
|
394
|
+
store.start();
|
|
395
|
+
await flush();
|
|
396
|
+
await store.logout();
|
|
397
|
+
expect(userIdsAtSyncSignOut).toEqual(["u1"]);
|
|
398
|
+
expect(store.getState().userId).toBeNull();
|
|
399
|
+
});
|
|
400
|
+
it("still signs out of the source and runs onLogout when a syncdb client fails", async () => {
|
|
401
|
+
const fake = makeSource(snapshot("u1"));
|
|
402
|
+
const events = [];
|
|
403
|
+
const errors = [];
|
|
404
|
+
const originalError = console.error;
|
|
405
|
+
console.error = (...args) => {
|
|
406
|
+
errors.push(args);
|
|
407
|
+
};
|
|
408
|
+
const store = createSessionStore({
|
|
409
|
+
onLogout: () => {
|
|
410
|
+
events.push("onLogout");
|
|
411
|
+
},
|
|
412
|
+
source: fake.source,
|
|
413
|
+
syncDbs: [
|
|
414
|
+
{
|
|
415
|
+
signOut: async () => {
|
|
416
|
+
throw new Error("persister closed");
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
});
|
|
421
|
+
store.start();
|
|
422
|
+
await flush();
|
|
423
|
+
try {
|
|
424
|
+
await store.logout();
|
|
425
|
+
}
|
|
426
|
+
finally {
|
|
427
|
+
console.error = originalError;
|
|
428
|
+
}
|
|
429
|
+
expect(fake.signOuts()).toBe(1);
|
|
430
|
+
expect(events).toEqual(["onLogout"]);
|
|
431
|
+
expect(errors).toHaveLength(1);
|
|
432
|
+
expect(String(errors[0]?.[0])).toContain("Error signing out sync client");
|
|
433
|
+
expect(store.getState().isAuthenticated).toBe(false);
|
|
434
|
+
});
|
|
435
|
+
it("still tears down and clears when every side effect fails after the session is gone", async () => {
|
|
436
|
+
const fake = makeSource(snapshot("u1"));
|
|
437
|
+
const warn = console.warn;
|
|
438
|
+
console.warn = () => { };
|
|
439
|
+
const errors = [];
|
|
440
|
+
const originalError = console.error;
|
|
441
|
+
console.error = (...args) => {
|
|
442
|
+
errors.push(args);
|
|
443
|
+
};
|
|
444
|
+
// The sign-out call fails, but the server no longer has the session.
|
|
445
|
+
fake.failSignOut();
|
|
446
|
+
fake.set(null);
|
|
447
|
+
let secondSyncDbSignedOut = false;
|
|
448
|
+
const store = createSessionStore({
|
|
449
|
+
onLogout: () => {
|
|
450
|
+
throw new Error("onLogout failed");
|
|
451
|
+
},
|
|
452
|
+
source: fake.source,
|
|
453
|
+
syncDbs: [
|
|
454
|
+
{
|
|
455
|
+
signOut: async () => {
|
|
456
|
+
throw new Error("syncdb failed");
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
signOut: async () => {
|
|
461
|
+
secondSyncDbSignedOut = true;
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
],
|
|
465
|
+
});
|
|
466
|
+
store.start();
|
|
467
|
+
await flush();
|
|
468
|
+
try {
|
|
469
|
+
await store.logout();
|
|
470
|
+
}
|
|
471
|
+
finally {
|
|
472
|
+
console.warn = warn;
|
|
473
|
+
console.error = originalError;
|
|
474
|
+
}
|
|
475
|
+
expect(secondSyncDbSignedOut).toBe(true);
|
|
476
|
+
expect(store.getState().isAuthenticated).toBe(false);
|
|
477
|
+
expect(store.getState().userId).toBeNull();
|
|
478
|
+
expect(errors.length).toBeGreaterThanOrEqual(2);
|
|
479
|
+
});
|
|
480
|
+
describe("when the server's sign-out does not land", () => {
|
|
481
|
+
const quietly = async (run) => {
|
|
482
|
+
const warn = console.warn;
|
|
483
|
+
console.warn = () => { };
|
|
484
|
+
try {
|
|
485
|
+
await run();
|
|
486
|
+
}
|
|
487
|
+
finally {
|
|
488
|
+
console.warn = warn;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
it("keeps the session and wipes nothing when the session is still live", async () => {
|
|
492
|
+
const fake = makeSource(snapshot("u1"));
|
|
493
|
+
fake.failSignOut();
|
|
494
|
+
const events = [];
|
|
495
|
+
const store = createSessionStore({
|
|
496
|
+
onLogout: () => {
|
|
497
|
+
events.push("onLogout");
|
|
498
|
+
},
|
|
499
|
+
source: fake.source,
|
|
500
|
+
syncDbs: [
|
|
501
|
+
{
|
|
502
|
+
signOut: async () => {
|
|
503
|
+
events.push("syncdb");
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
});
|
|
508
|
+
store.start();
|
|
509
|
+
await flush();
|
|
510
|
+
await quietly(() => store.logout());
|
|
511
|
+
expect(events).toEqual([]);
|
|
512
|
+
expect(store.getState()).toEqual({
|
|
513
|
+
error: SIGN_OUT_FAILED_MESSAGE,
|
|
514
|
+
isAuthenticated: true,
|
|
515
|
+
isLoading: false,
|
|
516
|
+
isSigningOut: false,
|
|
517
|
+
user: { id: "u1", name: "u1" },
|
|
518
|
+
userId: "u1",
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
it("keeps the session when the server cannot be asked and the client may hold one", async () => {
|
|
522
|
+
const fake = makeSource(snapshot("u1"));
|
|
523
|
+
fake.failSignOut();
|
|
524
|
+
const store = createSessionStore({ pollIntervalMs: 0, source: fake.source });
|
|
525
|
+
store.start();
|
|
526
|
+
await flush();
|
|
527
|
+
fake.set(new Error("offline"));
|
|
528
|
+
await quietly(() => store.logout());
|
|
529
|
+
expect(store.getState().userId).toBe("u1");
|
|
530
|
+
expect(store.getState().error).toBe(SIGN_OUT_FAILED_MESSAGE);
|
|
531
|
+
});
|
|
532
|
+
it("clears the session when the server cannot be asked and the client holds nothing", async () => {
|
|
533
|
+
const fake = makeSource(snapshot("u1"));
|
|
534
|
+
fake.failSignOut();
|
|
535
|
+
const source = { ...fake.source, mayHoldSession: () => false };
|
|
536
|
+
const store = createSessionStore({ pollIntervalMs: 0, source });
|
|
537
|
+
store.start();
|
|
538
|
+
await flush();
|
|
539
|
+
fake.set(new Error("offline"));
|
|
540
|
+
await quietly(() => store.logout());
|
|
541
|
+
expect(store.getState().userId).toBeNull();
|
|
542
|
+
expect(store.getState().error).toBeNull();
|
|
543
|
+
});
|
|
544
|
+
it("treats a hung sign-out as unreachable once signOutTimeoutMs passes", async () => {
|
|
545
|
+
const fake = makeSource(snapshot("u1"));
|
|
546
|
+
const source = {
|
|
547
|
+
...fake.source,
|
|
548
|
+
signOut: () => new Promise(() => { }),
|
|
549
|
+
};
|
|
550
|
+
const store = createSessionStore({ pollIntervalMs: 0, signOutTimeoutMs: 10, source });
|
|
551
|
+
store.start();
|
|
552
|
+
await flush();
|
|
553
|
+
await quietly(() => store.logout());
|
|
554
|
+
// The session check answers that the session is live.
|
|
555
|
+
expect(store.getState().userId).toBe("u1");
|
|
556
|
+
expect(store.getState().error).toBe(SIGN_OUT_FAILED_MESSAGE);
|
|
557
|
+
expect(store.getState().isSigningOut).toBe(false);
|
|
558
|
+
});
|
|
559
|
+
it("clears the error on the next successful logout", async () => {
|
|
560
|
+
const fake = makeSource(snapshot("u1"));
|
|
561
|
+
fake.failSignOut();
|
|
562
|
+
const store = createSessionStore({ pollIntervalMs: 0, source: fake.source });
|
|
563
|
+
store.start();
|
|
564
|
+
await flush();
|
|
565
|
+
await quietly(() => store.logout());
|
|
566
|
+
expect(store.getState().error).toBe(SIGN_OUT_FAILED_MESSAGE);
|
|
567
|
+
const healthy = makeSource(snapshot("u1"));
|
|
568
|
+
const retry = createSessionStore({ pollIntervalMs: 0, source: healthy.source });
|
|
569
|
+
retry.start();
|
|
570
|
+
await flush();
|
|
571
|
+
await retry.logout();
|
|
572
|
+
expect(retry.getState().error).toBeNull();
|
|
573
|
+
expect(retry.getState().userId).toBeNull();
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
it("keeps the session in the state, with isSigningOut set, while the server answers", async () => {
|
|
577
|
+
const fake = makeSource(snapshot("u1"));
|
|
578
|
+
let finishSignOut;
|
|
579
|
+
const source = {
|
|
580
|
+
...fake.source,
|
|
581
|
+
signOut: () => new Promise((resolve) => {
|
|
582
|
+
finishSignOut = () => {
|
|
583
|
+
void fake.source.signOut().then(resolve);
|
|
584
|
+
};
|
|
585
|
+
}),
|
|
586
|
+
};
|
|
587
|
+
const store = createSessionStore({ pollIntervalMs: 0, source });
|
|
588
|
+
store.start();
|
|
589
|
+
await flush();
|
|
590
|
+
const loggingOut = store.logout();
|
|
591
|
+
await flush();
|
|
592
|
+
expect(store.getState().isSigningOut).toBe(true);
|
|
593
|
+
expect(store.getState().userId).toBe("u1");
|
|
594
|
+
// A push of the signed-out session during the wait does not clear it early.
|
|
595
|
+
fake.push(null);
|
|
596
|
+
expect(store.getState().userId).toBe("u1");
|
|
597
|
+
finishSignOut?.();
|
|
598
|
+
await loggingOut;
|
|
599
|
+
expect(store.getState().isSigningOut).toBe(false);
|
|
600
|
+
expect(store.getState().userId).toBeNull();
|
|
601
|
+
});
|
|
602
|
+
it("lets a different user who signed in during the logout win", async () => {
|
|
603
|
+
const fake = makeSource(snapshot("u1"));
|
|
604
|
+
const source = {
|
|
605
|
+
...fake.source,
|
|
606
|
+
signOut: async () => {
|
|
607
|
+
await fake.source.signOut();
|
|
608
|
+
fake.push(snapshot("u2"));
|
|
609
|
+
},
|
|
610
|
+
};
|
|
611
|
+
const store = createSessionStore({ pollIntervalMs: 0, source });
|
|
612
|
+
store.start();
|
|
613
|
+
await flush();
|
|
614
|
+
await store.logout();
|
|
615
|
+
expect(store.getState().userId).toBe("u2");
|
|
616
|
+
expect(store.getState().isSigningOut).toBe(false);
|
|
617
|
+
});
|
|
618
|
+
it("runs one logout for concurrent calls", async () => {
|
|
619
|
+
const fake = makeSource(snapshot("u1"));
|
|
620
|
+
const store = createSessionStore({ pollIntervalMs: 0, source: fake.source });
|
|
621
|
+
store.start();
|
|
622
|
+
await flush();
|
|
623
|
+
await Promise.all([store.logout(), store.logout()]);
|
|
624
|
+
expect(fake.signOuts()).toBe(1);
|
|
625
|
+
});
|
|
626
|
+
it("ignores a read that was in flight when logout started", async () => {
|
|
627
|
+
let resolveRead;
|
|
628
|
+
let reads = 0;
|
|
629
|
+
const source = {
|
|
630
|
+
getSession: () => {
|
|
631
|
+
reads += 1;
|
|
632
|
+
if (reads === 1) {
|
|
633
|
+
return Promise.resolve(snapshot("u1"));
|
|
634
|
+
}
|
|
635
|
+
return new Promise((resolve) => {
|
|
636
|
+
resolveRead = resolve;
|
|
637
|
+
});
|
|
638
|
+
},
|
|
639
|
+
signOut: async () => { },
|
|
640
|
+
};
|
|
641
|
+
const store = createSessionStore({ pollIntervalMs: 0, source });
|
|
642
|
+
store.start();
|
|
643
|
+
await flush();
|
|
644
|
+
const refreshing = store.refresh();
|
|
645
|
+
await store.logout();
|
|
646
|
+
resolveRead?.(snapshot("u1"));
|
|
647
|
+
await refreshing;
|
|
648
|
+
expect(store.getState().isAuthenticated).toBe(false);
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
it("wraps a Better Auth authClient when no source is given", async () => {
|
|
652
|
+
const authClient = {
|
|
653
|
+
getSession: async () => ({ data: { session: { token: "t" }, user: { id: "ba-1" } }, error: null }),
|
|
654
|
+
signOut: async () => ({ data: { success: true }, error: null }),
|
|
655
|
+
};
|
|
656
|
+
const store = createSessionStore({ authClient, pollIntervalMs: 0 });
|
|
657
|
+
store.start();
|
|
658
|
+
await flush();
|
|
659
|
+
expect(store.getState().userId).toBe("ba-1");
|
|
660
|
+
});
|
|
661
|
+
it("throws when neither a source nor an authClient is given", () => {
|
|
662
|
+
expect(() => createSessionStore({})).toThrow("createSessionStore requires a `source` or an `authClient`");
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
describe("betterAuthSessionSource", () => {
|
|
666
|
+
const atomClient = (getSession = async () => null) => {
|
|
667
|
+
const listeners = new Set();
|
|
668
|
+
let unsubscribed = 0;
|
|
669
|
+
return {
|
|
670
|
+
client: {
|
|
671
|
+
$store: {
|
|
672
|
+
atoms: {
|
|
673
|
+
session: {
|
|
674
|
+
subscribe: (listener) => {
|
|
675
|
+
listeners.add(listener);
|
|
676
|
+
return () => {
|
|
677
|
+
unsubscribed += 1;
|
|
678
|
+
listeners.delete(listener);
|
|
679
|
+
};
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
getSession,
|
|
685
|
+
signOut: async () => ({ data: { success: true }, error: null }),
|
|
686
|
+
useSession: () => { },
|
|
687
|
+
},
|
|
688
|
+
emit: (value) => {
|
|
689
|
+
for (const listener of listeners) {
|
|
690
|
+
listener(value);
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
unsubscribed: () => unsubscribed,
|
|
694
|
+
};
|
|
695
|
+
};
|
|
696
|
+
it("reads the {data} envelope and the direct payload shapes", async () => {
|
|
697
|
+
const enveloped = betterAuthSessionSource({
|
|
698
|
+
getSession: async () => ({ data: { session: {}, user: { email: "a@x", id: "u1" } }, error: null }),
|
|
699
|
+
signOut: async () => undefined,
|
|
700
|
+
});
|
|
701
|
+
expect((await enveloped.getSession())).toEqual({
|
|
702
|
+
user: { email: "a@x", id: "u1" },
|
|
703
|
+
userId: "u1",
|
|
704
|
+
});
|
|
705
|
+
const direct = betterAuthSessionSource({
|
|
706
|
+
getSession: async () => ({ session: {}, user: { id: "u2" } }),
|
|
707
|
+
signOut: async () => undefined,
|
|
708
|
+
});
|
|
709
|
+
expect((await direct.getSession())?.userId).toBe("u2");
|
|
710
|
+
});
|
|
711
|
+
it("reports signed out for empty, partial, and non-object results", async () => {
|
|
712
|
+
for (const result of [
|
|
713
|
+
null,
|
|
714
|
+
undefined,
|
|
715
|
+
"nonsense",
|
|
716
|
+
{ data: null, error: null },
|
|
717
|
+
{ data: "nonsense" },
|
|
718
|
+
{ data: { session: null, user: null } },
|
|
719
|
+
{ data: { session: {}, user: {} } },
|
|
720
|
+
{ data: { session: {}, user: { id: "" } } },
|
|
721
|
+
{ data: { user: { id: "u1" } } },
|
|
722
|
+
]) {
|
|
723
|
+
const source = betterAuthSessionSource({
|
|
724
|
+
getSession: async () => result,
|
|
725
|
+
signOut: async () => undefined,
|
|
726
|
+
});
|
|
727
|
+
expect(await source.getSession()).toBeNull();
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
it("throws when Better Auth reports a get-session error, so it is never read as a sign-out", async () => {
|
|
731
|
+
const withMessage = betterAuthSessionSource({
|
|
732
|
+
getSession: async () => ({ data: null, error: { message: "Failed to fetch", status: 0 } }),
|
|
733
|
+
signOut: async () => undefined,
|
|
734
|
+
});
|
|
735
|
+
await expect(withMessage.getSession()).rejects.toThrow("Failed to fetch");
|
|
736
|
+
const asString = betterAuthSessionSource({
|
|
737
|
+
getSession: async () => ({ data: null, error: "boom" }),
|
|
738
|
+
signOut: async () => undefined,
|
|
739
|
+
});
|
|
740
|
+
await expect(asString.getSession()).rejects.toThrow("boom");
|
|
741
|
+
const noMessage = betterAuthSessionSource({
|
|
742
|
+
getSession: async () => ({ data: null, error: { status: 500 } }),
|
|
743
|
+
signOut: async () => undefined,
|
|
744
|
+
});
|
|
745
|
+
await expect(noMessage.getSession()).rejects.toThrow("Unknown error");
|
|
746
|
+
});
|
|
747
|
+
it("throws when Better Auth reports a sign-out error", async () => {
|
|
748
|
+
const source = betterAuthSessionSource({
|
|
749
|
+
getSession: async () => null,
|
|
750
|
+
signOut: async () => ({ data: null, error: { message: "nope" } }),
|
|
751
|
+
});
|
|
752
|
+
await expect(source.signOut()).rejects.toThrow("nope");
|
|
753
|
+
const ok = betterAuthSessionSource({
|
|
754
|
+
getSession: async () => null,
|
|
755
|
+
signOut: async () => ({ data: { success: true }, error: null }),
|
|
756
|
+
});
|
|
757
|
+
await expect(ok.signOut()).resolves.toBeUndefined();
|
|
758
|
+
});
|
|
759
|
+
it("has no subscribe when the client exposes no session atom", () => {
|
|
760
|
+
const source = betterAuthSessionSource({
|
|
761
|
+
getSession: async () => null,
|
|
762
|
+
signOut: async () => undefined,
|
|
763
|
+
useSession: () => { },
|
|
764
|
+
});
|
|
765
|
+
expect(source.subscribe).toBeUndefined();
|
|
766
|
+
});
|
|
767
|
+
it("subscribes to the React client's $store session atom", () => {
|
|
768
|
+
const fake = atomClient();
|
|
769
|
+
const source = betterAuthSessionSource(fake.client);
|
|
770
|
+
const received = [];
|
|
771
|
+
const unsubscribe = source.subscribe?.((value) => {
|
|
772
|
+
received.push(value);
|
|
773
|
+
});
|
|
774
|
+
fake.emit({ data: null, error: null, isPending: true });
|
|
775
|
+
fake.emit({ data: null, error: { message: "Failed to fetch" }, isPending: false });
|
|
776
|
+
fake.emit({ data: { session: { token: "t" }, user: { id: "u1" } }, error: null, isPending: false });
|
|
777
|
+
fake.emit({ data: null, error: null, isPending: false });
|
|
778
|
+
fake.emit(true);
|
|
779
|
+
fake.emit({ unexpected: "shape" });
|
|
780
|
+
expect(received).toEqual([
|
|
781
|
+
{ user: { id: "u1" }, userId: "u1" },
|
|
782
|
+
null,
|
|
783
|
+
undefined,
|
|
784
|
+
undefined,
|
|
785
|
+
]);
|
|
786
|
+
unsubscribe?.();
|
|
787
|
+
expect(fake.unsubscribed()).toBe(1);
|
|
788
|
+
});
|
|
789
|
+
it("skips refetch emissions that still carry the previous user's session", () => {
|
|
790
|
+
const fake = atomClient();
|
|
791
|
+
const source = betterAuthSessionSource(fake.client);
|
|
792
|
+
const received = [];
|
|
793
|
+
source.subscribe?.((value) => {
|
|
794
|
+
received.push(value);
|
|
795
|
+
});
|
|
796
|
+
const signedIn = { session: { token: "t" }, user: { id: "u1" } };
|
|
797
|
+
fake.emit({ data: signedIn, error: null, isPending: false, isRefetching: false });
|
|
798
|
+
// Sign-out triggers a refetch: Better Auth re-emits the old data while it is in flight.
|
|
799
|
+
fake.emit({ data: signedIn, error: null, isPending: false, isRefetching: true });
|
|
800
|
+
fake.emit({ data: null, error: null, isPending: false, isRefetching: false });
|
|
801
|
+
expect(received).toEqual([{ user: { id: "u1" }, userId: "u1" }, null]);
|
|
802
|
+
});
|
|
803
|
+
it("subscribes through useSession.subscribe on nanostore-style clients", () => {
|
|
804
|
+
let listener;
|
|
805
|
+
const source = betterAuthSessionSource({
|
|
806
|
+
getSession: async () => null,
|
|
807
|
+
signOut: async () => undefined,
|
|
808
|
+
useSession: {
|
|
809
|
+
subscribe: (next) => {
|
|
810
|
+
listener = next;
|
|
811
|
+
return undefined;
|
|
812
|
+
},
|
|
813
|
+
},
|
|
814
|
+
});
|
|
815
|
+
const received = [];
|
|
816
|
+
const unsubscribe = source.subscribe?.((value) => {
|
|
817
|
+
received.push(value);
|
|
818
|
+
});
|
|
819
|
+
listener?.({ data: { session: {}, user: { id: "u9" } } });
|
|
820
|
+
expect(received).toEqual([{ user: { id: "u9" }, userId: "u9" }]);
|
|
821
|
+
// A subscribe that returns no unsubscribe is tolerated.
|
|
822
|
+
expect(() => unsubscribe?.()).not.toThrow();
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
//# sourceMappingURL=session.test.js.map
|