@terreno/syncdb 57.21.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 +43 -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 +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 +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,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy `@terreno/api` JWT auth for frontends, without Redux. Ported from the pre-58 rtk package's
|
|
3
|
+
* `generateAuthSlice` + `emptyApi` base query.
|
|
4
|
+
*
|
|
5
|
+
* One `jwtAuthAdapter` object is both:
|
|
6
|
+
* - an {@link AuthProvider} for `createSyncDb` / `createApiClient` (`getToken` refreshes the
|
|
7
|
+
* access token when it is under two minutes from expiry; `refresh` runs on a 401), and
|
|
8
|
+
* - a {@link SessionSource} for `SessionProvider` / `createSessionStore`.
|
|
9
|
+
*
|
|
10
|
+
* Concurrent refreshes share one `/auth/refresh_token` call. A refresh the server rejects
|
|
11
|
+
* signs the user out; a network failure keeps the session and the current token.
|
|
12
|
+
*/
|
|
13
|
+
import {API_ERROR_CODES, ApiError} from "../api/apiError";
|
|
14
|
+
import {type FetchLike, resolveApiUrl, unwrapEnvelope} from "../api/apiFetch";
|
|
15
|
+
import type {AuthProvider} from "../types";
|
|
16
|
+
import type {SessionChangeListener, SessionSnapshot, SessionSource} from "./session";
|
|
17
|
+
import {
|
|
18
|
+
AUTH_TOKEN_KEY,
|
|
19
|
+
decodeJwtClaims,
|
|
20
|
+
getDefaultJwtTokenStorage,
|
|
21
|
+
type JwtTokenStorage,
|
|
22
|
+
type JwtTokens,
|
|
23
|
+
REFRESH_TOKEN_KEY,
|
|
24
|
+
readJwtTokens,
|
|
25
|
+
tokenExpirationTimesFor,
|
|
26
|
+
} from "./tokenExpiry";
|
|
27
|
+
|
|
28
|
+
/** Refresh the access token when it has fewer seconds than this left (about two minutes). */
|
|
29
|
+
export const DEFAULT_REFRESH_BEFORE_EXPIRY_SECS = 130;
|
|
30
|
+
|
|
31
|
+
/** Default timeout for auth requests. */
|
|
32
|
+
export const DEFAULT_JWT_AUTH_TIMEOUT_MS = 30_000;
|
|
33
|
+
|
|
34
|
+
/** Auth routes, relative to `baseUrl`. Defaults match `@terreno/api`. */
|
|
35
|
+
export interface JwtAuthPaths {
|
|
36
|
+
login: string;
|
|
37
|
+
signup: string;
|
|
38
|
+
refreshToken: string;
|
|
39
|
+
googleLogin: string;
|
|
40
|
+
resetPassword: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const DEFAULT_JWT_AUTH_PATHS: JwtAuthPaths = {
|
|
44
|
+
googleLogin: "/auth/google",
|
|
45
|
+
login: "/auth/login",
|
|
46
|
+
refreshToken: "/auth/refresh_token",
|
|
47
|
+
resetPassword: "/resetPassword",
|
|
48
|
+
signup: "/auth/signup",
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** The user a JWT session reports: the `id` claim the API signs into every token. */
|
|
52
|
+
export interface JwtSessionUser {
|
|
53
|
+
id: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type EmailLoginRequest =
|
|
57
|
+
| {email: string; username?: never; password: string}
|
|
58
|
+
| {username: string; email?: never; password: string};
|
|
59
|
+
|
|
60
|
+
export interface EmailSignupRequest {
|
|
61
|
+
email: string;
|
|
62
|
+
password: string;
|
|
63
|
+
/** Extra fields the API's signup strategy stores on the user. */
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface GoogleLoginRequest {
|
|
68
|
+
idToken: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ResetPasswordRequest {
|
|
72
|
+
/** One-time token from the emailed reset link. */
|
|
73
|
+
token?: string;
|
|
74
|
+
password?: string;
|
|
75
|
+
newPassword?: string;
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** What `/auth/login`, `/auth/signup`, `/auth/google`, and `/resetPassword` return in `data`. */
|
|
80
|
+
export interface JwtAuthResponse {
|
|
81
|
+
token: string;
|
|
82
|
+
refreshToken: string;
|
|
83
|
+
userId: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Result of a refresh attempt. */
|
|
87
|
+
type RefreshOutcome = "refreshed" | "transient" | "failed";
|
|
88
|
+
|
|
89
|
+
export interface JwtAuthAdapterOptions {
|
|
90
|
+
/** API origin, e.g. `baseUrl` from `@terreno/syncdb/config`. */
|
|
91
|
+
baseUrl: string;
|
|
92
|
+
/** Token storage (default: SecureStore on native, AsyncStorage on web). */
|
|
93
|
+
storage?: JwtTokenStorage;
|
|
94
|
+
/** Override individual auth routes. */
|
|
95
|
+
paths?: Partial<JwtAuthPaths>;
|
|
96
|
+
/** Extra headers on auth requests (e.g. `appHeaders` from `@terreno/syncdb/config`). */
|
|
97
|
+
headers?:
|
|
98
|
+
| Record<string, string>
|
|
99
|
+
| (() => Record<string, string> | Promise<Record<string, string>>);
|
|
100
|
+
/** Refresh when the access token has fewer seconds left (default 130). */
|
|
101
|
+
refreshBeforeExpirySecs?: number;
|
|
102
|
+
fetchImpl?: FetchLike;
|
|
103
|
+
timeoutMs?: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface JwtAuthAdapter
|
|
107
|
+
extends Required<AuthProvider>,
|
|
108
|
+
Required<Omit<SessionSource<JwtSessionUser>, "mayHoldSession">> {
|
|
109
|
+
/** `POST /auth/login`; stores the tokens and signs the session in. */
|
|
110
|
+
login: (body: EmailLoginRequest) => Promise<JwtAuthResponse>;
|
|
111
|
+
/** `POST /auth/signup`; stores the tokens and signs the session in. */
|
|
112
|
+
signup: (body: EmailSignupRequest) => Promise<JwtAuthResponse>;
|
|
113
|
+
/** `POST /auth/google` with a Google ID token; stores the tokens and signs the session in. */
|
|
114
|
+
googleLogin: (body: GoogleLoginRequest) => Promise<JwtAuthResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* `POST /resetPassword`. Returns the API response without signing in (rtk behaviour); call
|
|
117
|
+
* `login` afterwards, or `setTokens` with the returned pair to sign straight in.
|
|
118
|
+
*/
|
|
119
|
+
resetPassword: (body: ResetPasswordRequest) => Promise<JwtAuthResponse>;
|
|
120
|
+
/** Store a token pair (e.g. from a custom auth route) and sign the session in. */
|
|
121
|
+
setTokens: (tokens: {token: string; refreshToken?: string | null}) => Promise<string | null>;
|
|
122
|
+
/** Clear stored tokens and notify listeners. JWTs are stateless, so no server call is made. */
|
|
123
|
+
logout: () => Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const errorMessage = (error: unknown): string =>
|
|
127
|
+
error instanceof Error ? error.message : String(error);
|
|
128
|
+
|
|
129
|
+
/** Read the user id from a token pair: the access token's `id` claim, else the refresh token's. */
|
|
130
|
+
const userIdFromTokens = (tokens: JwtTokens): string | null => {
|
|
131
|
+
const id = decodeJwtClaims(tokens.token)?.id ?? decodeJwtClaims(tokens.refreshToken)?.id;
|
|
132
|
+
return typeof id === "string" && id ? id : null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const isBothExpired = (tokens: JwtTokens): boolean => {
|
|
136
|
+
const {authRemainingSecs, refreshRemainingSecs} = tokenExpirationTimesFor({tokens});
|
|
137
|
+
return (
|
|
138
|
+
authRemainingSecs !== undefined &&
|
|
139
|
+
authRemainingSecs < 0 &&
|
|
140
|
+
refreshRemainingSecs !== undefined &&
|
|
141
|
+
refreshRemainingSecs < 0
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** Build a JSON:API-style {@link ApiError} from an auth error body (`{message}` or `{title}`). */
|
|
146
|
+
const toApiError = (response: Response, body: unknown): ApiError => {
|
|
147
|
+
const payload = (body && typeof body === "object" ? body : {}) as {
|
|
148
|
+
code?: unknown;
|
|
149
|
+
detail?: unknown;
|
|
150
|
+
message?: unknown;
|
|
151
|
+
title?: unknown;
|
|
152
|
+
};
|
|
153
|
+
const title =
|
|
154
|
+
(typeof payload.title === "string" && payload.title) ||
|
|
155
|
+
(typeof payload.message === "string" && payload.message) ||
|
|
156
|
+
response.statusText.trim() ||
|
|
157
|
+
`Request failed (${response.status})`;
|
|
158
|
+
return new ApiError({
|
|
159
|
+
data: {
|
|
160
|
+
title,
|
|
161
|
+
...(typeof payload.detail === "string" ? {detail: payload.detail} : {}),
|
|
162
|
+
...(typeof payload.code === "string" ? {code: payload.code} : {}),
|
|
163
|
+
},
|
|
164
|
+
status: response.status,
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Create the JWT auth adapter. Pass it as `authProvider` to `createSyncDb` and
|
|
170
|
+
* `createApiClient`, and as `source` to `SessionProvider`.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import {baseUrl} from "@terreno/syncdb/config";
|
|
175
|
+
* import {jwtAuthAdapter} from "@terreno/syncdb/auth";
|
|
176
|
+
*
|
|
177
|
+
* export const jwtAuth = jwtAuthAdapter({baseUrl});
|
|
178
|
+
* export const apiClient = createApiClient({authProvider: jwtAuth, baseUrl});
|
|
179
|
+
* // <SessionProvider source={jwtAuth} syncDbs={[syncDb]}>
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export const jwtAuthAdapter = (options: JwtAuthAdapterOptions): JwtAuthAdapter => {
|
|
183
|
+
const storage = options.storage ?? getDefaultJwtTokenStorage();
|
|
184
|
+
const paths = {...DEFAULT_JWT_AUTH_PATHS, ...options.paths};
|
|
185
|
+
const refreshBeforeExpirySecs =
|
|
186
|
+
options.refreshBeforeExpirySecs ?? DEFAULT_REFRESH_BEFORE_EXPIRY_SECS;
|
|
187
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_JWT_AUTH_TIMEOUT_MS;
|
|
188
|
+
const fetcher: FetchLike =
|
|
189
|
+
options.fetchImpl ?? ((input, init): Promise<Response> => globalThis.fetch(input, init));
|
|
190
|
+
|
|
191
|
+
const authListeners = new Set<() => void>();
|
|
192
|
+
const sessionListeners = new Set<SessionChangeListener<JwtSessionUser>>();
|
|
193
|
+
let refreshing: Promise<RefreshOutcome> | undefined;
|
|
194
|
+
|
|
195
|
+
const snapshotFor = (userId: string | null): SessionSnapshot<JwtSessionUser> | null =>
|
|
196
|
+
userId ? {user: {id: userId}, userId} : null;
|
|
197
|
+
|
|
198
|
+
const notify = (userId: string | null): void => {
|
|
199
|
+
const snapshot = snapshotFor(userId);
|
|
200
|
+
for (const listener of [...sessionListeners]) {
|
|
201
|
+
listener(snapshot);
|
|
202
|
+
}
|
|
203
|
+
for (const listener of [...authListeners]) {
|
|
204
|
+
listener();
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const postJson = async (path: string, body: unknown): Promise<unknown> => {
|
|
209
|
+
const extra = typeof options.headers === "function" ? await options.headers() : options.headers;
|
|
210
|
+
const controller = new AbortController();
|
|
211
|
+
let timedOut = false;
|
|
212
|
+
const timeoutId = setTimeout(() => {
|
|
213
|
+
timedOut = true;
|
|
214
|
+
controller.abort();
|
|
215
|
+
}, timeoutMs);
|
|
216
|
+
let response: Response;
|
|
217
|
+
try {
|
|
218
|
+
response = await fetcher(resolveApiUrl({baseUrl: options.baseUrl, url: path}), {
|
|
219
|
+
body: JSON.stringify(body),
|
|
220
|
+
headers: {Accept: "application/json", "Content-Type": "application/json", ...extra},
|
|
221
|
+
method: "POST",
|
|
222
|
+
signal: controller.signal,
|
|
223
|
+
});
|
|
224
|
+
} catch (error) {
|
|
225
|
+
throw new ApiError({
|
|
226
|
+
cause: error,
|
|
227
|
+
data: timedOut
|
|
228
|
+
? {code: API_ERROR_CODES.timeout, title: "Request timed out"}
|
|
229
|
+
: {code: API_ERROR_CODES.network, title: "Network request failed"},
|
|
230
|
+
status: 0,
|
|
231
|
+
});
|
|
232
|
+
} finally {
|
|
233
|
+
clearTimeout(timeoutId);
|
|
234
|
+
}
|
|
235
|
+
const parsed: unknown = await response.json().catch(() => null);
|
|
236
|
+
if (!response.ok) {
|
|
237
|
+
throw toApiError(response, parsed);
|
|
238
|
+
}
|
|
239
|
+
return unwrapEnvelope(parsed);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const clearTokens = async (): Promise<void> => {
|
|
243
|
+
await Promise.all([storage.removeItem(AUTH_TOKEN_KEY), storage.removeItem(REFRESH_TOKEN_KEY)]);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/** Clear tokens and tell listeners the session ended. */
|
|
247
|
+
const endSession = async (reason: string): Promise<void> => {
|
|
248
|
+
console.warn(`[terreno/syncdb] Signing out: ${reason}`);
|
|
249
|
+
try {
|
|
250
|
+
await clearTokens();
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error("[terreno/syncdb] Error clearing auth tokens:", error);
|
|
253
|
+
}
|
|
254
|
+
notify(null);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const storeTokens = async ({
|
|
258
|
+
refreshToken,
|
|
259
|
+
token,
|
|
260
|
+
}: {
|
|
261
|
+
token: string;
|
|
262
|
+
refreshToken?: string | null;
|
|
263
|
+
}): Promise<void> => {
|
|
264
|
+
await storage.setItem(AUTH_TOKEN_KEY, token);
|
|
265
|
+
await storage.setItem(REFRESH_TOKEN_KEY, refreshToken ?? "");
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const setTokens = async (tokens: {
|
|
269
|
+
token: string;
|
|
270
|
+
refreshToken?: string | null;
|
|
271
|
+
}): Promise<string | null> => {
|
|
272
|
+
await storeTokens(tokens);
|
|
273
|
+
const userId = userIdFromTokens({
|
|
274
|
+
refreshToken: tokens.refreshToken ?? null,
|
|
275
|
+
token: tokens.token,
|
|
276
|
+
});
|
|
277
|
+
notify(userId);
|
|
278
|
+
return userId;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/** POST credentials, store the returned tokens, and sign the session in. */
|
|
282
|
+
const signIn = async (path: string, body: unknown): Promise<JwtAuthResponse> => {
|
|
283
|
+
const data = (await postJson(path, body)) as Partial<JwtAuthResponse> | null;
|
|
284
|
+
if (!data?.token) {
|
|
285
|
+
throw new Error("Auth response did not include a token");
|
|
286
|
+
}
|
|
287
|
+
await storeTokens({refreshToken: data.refreshToken, token: data.token});
|
|
288
|
+
const userId =
|
|
289
|
+
(typeof data.userId === "string" && data.userId) ||
|
|
290
|
+
userIdFromTokens({refreshToken: data.refreshToken ?? null, token: data.token});
|
|
291
|
+
notify(userId);
|
|
292
|
+
return {refreshToken: data.refreshToken ?? "", token: data.token, userId: userId ?? ""};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const runRefresh = async (): Promise<RefreshOutcome> => {
|
|
296
|
+
const {refreshToken} = await readJwtTokens(storage);
|
|
297
|
+
if (!refreshToken) {
|
|
298
|
+
await endSession("no refresh token found");
|
|
299
|
+
return "failed";
|
|
300
|
+
}
|
|
301
|
+
let data: Partial<JwtAuthResponse> | null;
|
|
302
|
+
try {
|
|
303
|
+
data = (await postJson(paths.refreshToken, {refreshToken})) as Partial<JwtAuthResponse>;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
if (error instanceof ApiError && error.status === 0) {
|
|
306
|
+
// Offline or timed out: keep the session; the next request tries again.
|
|
307
|
+
console.warn(`[terreno/syncdb] Network error refreshing token: ${error.message}`);
|
|
308
|
+
return "transient";
|
|
309
|
+
}
|
|
310
|
+
await endSession(`token refresh failed: ${errorMessage(error)}`);
|
|
311
|
+
return "failed";
|
|
312
|
+
}
|
|
313
|
+
if (!data?.token || !data.refreshToken) {
|
|
314
|
+
await endSession("refresh token response did not include tokens");
|
|
315
|
+
return "failed";
|
|
316
|
+
}
|
|
317
|
+
await storeTokens({refreshToken: data.refreshToken, token: data.token});
|
|
318
|
+
notify(userIdFromTokens({refreshToken: data.refreshToken, token: data.token}));
|
|
319
|
+
return "refreshed";
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
/** Concurrent callers share one refresh request. */
|
|
323
|
+
const refreshOnce = (): Promise<RefreshOutcome> => {
|
|
324
|
+
refreshing ??= runRefresh()
|
|
325
|
+
.catch(async (error: unknown): Promise<RefreshOutcome> => {
|
|
326
|
+
// Storage failures while saving new tokens leave the session unusable.
|
|
327
|
+
await endSession(`token refresh failed: ${errorMessage(error)}`);
|
|
328
|
+
return "failed";
|
|
329
|
+
})
|
|
330
|
+
.finally(() => {
|
|
331
|
+
refreshing = undefined;
|
|
332
|
+
});
|
|
333
|
+
return refreshing;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const refresh = async (): Promise<boolean> => (await refreshOnce()) === "refreshed";
|
|
337
|
+
|
|
338
|
+
const getToken = async (): Promise<string | null> => {
|
|
339
|
+
// A request that starts mid-refresh waits for it (resolves at once when none is running).
|
|
340
|
+
await refreshing;
|
|
341
|
+
const tokens = await readJwtTokens(storage);
|
|
342
|
+
if (!tokens.token) {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
if (isBothExpired(tokens)) {
|
|
346
|
+
await endSession("auth and refresh tokens are expired");
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
const {authRemainingSecs} = tokenExpirationTimesFor({tokens});
|
|
350
|
+
if (authRemainingSecs === undefined || authRemainingSecs >= refreshBeforeExpirySecs) {
|
|
351
|
+
return tokens.token;
|
|
352
|
+
}
|
|
353
|
+
const outcome = await refreshOnce();
|
|
354
|
+
if (outcome === "failed") {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
return (await readJwtTokens(storage)).token;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const getUserId = async (): Promise<string | null> => {
|
|
361
|
+
try {
|
|
362
|
+
const tokens = await readJwtTokens(storage);
|
|
363
|
+
if (!tokens.token || isBothExpired(tokens)) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
return userIdFromTokens(tokens);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.warn("[terreno/syncdb] Could not read auth tokens:", error);
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const getSession = async (): Promise<SessionSnapshot<JwtSessionUser> | null> => {
|
|
374
|
+
const tokens = await readJwtTokens(storage);
|
|
375
|
+
if (!tokens.token) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
if (isBothExpired(tokens)) {
|
|
379
|
+
await endSession("auth and refresh tokens are expired");
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
return snapshotFor(userIdFromTokens(tokens));
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
const onAuthChange = (callback: () => void): (() => void) => {
|
|
386
|
+
authListeners.add(callback);
|
|
387
|
+
return (): void => {
|
|
388
|
+
authListeners.delete(callback);
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const subscribe = (listener: SessionChangeListener<JwtSessionUser>): (() => void) => {
|
|
393
|
+
sessionListeners.add(listener);
|
|
394
|
+
return (): void => {
|
|
395
|
+
sessionListeners.delete(listener);
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const logout = async (): Promise<void> => {
|
|
400
|
+
await clearTokens();
|
|
401
|
+
console.debug("[terreno/syncdb] Cleared auth tokens as part of logout");
|
|
402
|
+
notify(null);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
return {
|
|
406
|
+
getSession,
|
|
407
|
+
getToken,
|
|
408
|
+
getUserId,
|
|
409
|
+
googleLogin: (body) => signIn(paths.googleLogin, body),
|
|
410
|
+
login: ({email, password, username}) => signIn(paths.login, {email, password, username}),
|
|
411
|
+
logout,
|
|
412
|
+
onAuthChange,
|
|
413
|
+
refresh,
|
|
414
|
+
resetPassword: async (body) => (await postJson(paths.resetPassword, body)) as JwtAuthResponse,
|
|
415
|
+
setTokens,
|
|
416
|
+
signOut: logout,
|
|
417
|
+
signup: (body) => signIn(paths.signup, body),
|
|
418
|
+
subscribe,
|
|
419
|
+
};
|
|
420
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getAccountNotLinkedText,
|
|
5
|
+
getLoginFeedback,
|
|
6
|
+
LOGIN_FAILED_MESSAGE,
|
|
7
|
+
PASSWORD_MISMATCH_MESSAGE,
|
|
8
|
+
SIGN_UP_CLOSED_NOTICE_TEXT,
|
|
9
|
+
VERIFY_EMAIL_NOTICE_TEXT,
|
|
10
|
+
} from "./loginErrors";
|
|
11
|
+
|
|
12
|
+
describe("getLoginFeedback", () => {
|
|
13
|
+
it("shows nothing without a failure", () => {
|
|
14
|
+
expect(getLoginFeedback({failure: undefined})).toEqual({isSignUpClosed: false});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("maps every spelling of account_not_linked to the linking guidance", () => {
|
|
18
|
+
const expected = getAccountNotLinkedText({mode: "explicit", originalMethod: "GitHub"});
|
|
19
|
+
for (const failure of [
|
|
20
|
+
{code: "account_not_linked", source: "url" as const},
|
|
21
|
+
{code: "OAUTH_LINK_ERROR", source: "response" as const},
|
|
22
|
+
{code: "OAUTH_LINK_ERROR", message: "account not linked", source: "response" as const},
|
|
23
|
+
{message: "Account not linked", source: "response" as const},
|
|
24
|
+
]) {
|
|
25
|
+
expect(getLoginFeedback({failure, mode: "explicit", originalMethod: "GitHub"})).toEqual({
|
|
26
|
+
isSignUpClosed: false,
|
|
27
|
+
notice: {
|
|
28
|
+
actionLabel: "Sign in with GitHub",
|
|
29
|
+
text: expected,
|
|
30
|
+
title: "You already have an account",
|
|
31
|
+
tone: "warning",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("uses the verified-email wording when the mode is not known yet", () => {
|
|
38
|
+
expect(getAccountNotLinkedText({})).toBe(getAccountNotLinkedText({mode: "verified-email"}));
|
|
39
|
+
expect(getAccountNotLinkedText({mode: "explicit"})).toContain("Sign in the way you did before");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("asks for email verification for the server's and Better Auth's codes", () => {
|
|
43
|
+
for (const failure of [
|
|
44
|
+
{code: "VERIFY_EMAIL_TO_USE_ACCOUNT", source: "url" as const},
|
|
45
|
+
{code: "EMAIL_NOT_VERIFIED", message: "Email not verified", source: "response" as const},
|
|
46
|
+
{message: "Verify your email to use this account", source: "response" as const},
|
|
47
|
+
]) {
|
|
48
|
+
expect(getLoginFeedback({failure}).notice?.text).toBe(VERIFY_EMAIL_NOTICE_TEXT);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("reports closed sign-up from the redirect code and the email sign-up code", () => {
|
|
53
|
+
for (const code of ["signup_disabled", "EMAIL_PASSWORD_SIGN_UP_DISABLED"]) {
|
|
54
|
+
expect(getLoginFeedback({failure: {code, source: "url"}})).toEqual({
|
|
55
|
+
isSignUpClosed: true,
|
|
56
|
+
notice: {text: SIGN_UP_CLOSED_NOTICE_TEXT, title: "Sign-up is closed", tone: "warning"},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("reads the ID-token refusal 'signup disabled' as closed sign-up, not as linking", () => {
|
|
62
|
+
expect(
|
|
63
|
+
getLoginFeedback({
|
|
64
|
+
failure: {code: "OAUTH_LINK_ERROR", message: "signup disabled", source: "response"},
|
|
65
|
+
mode: "explicit",
|
|
66
|
+
})
|
|
67
|
+
).toEqual({
|
|
68
|
+
isSignUpClosed: true,
|
|
69
|
+
notice: {text: SIGN_UP_CLOSED_NOTICE_TEXT, title: "Sign-up is closed", tone: "warning"},
|
|
70
|
+
});
|
|
71
|
+
// Any other OAUTH_LINK_ERROR message is shown as it is.
|
|
72
|
+
expect(
|
|
73
|
+
getLoginFeedback({
|
|
74
|
+
failure: {code: "OAUTH_LINK_ERROR", message: "unable to create user", source: "response"},
|
|
75
|
+
})
|
|
76
|
+
).toEqual({error: "unable to create user", isSignUpClosed: false});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("explains LINKING_DISABLED and provider_not_found", () => {
|
|
80
|
+
expect(
|
|
81
|
+
getLoginFeedback({failure: {code: "LINKING_DISABLED", source: "response"}}).notice?.text
|
|
82
|
+
).toContain("does not link sign-in methods");
|
|
83
|
+
expect(getLoginFeedback({failure: {code: "provider_not_found", source: "url"}}).error).toBe(
|
|
84
|
+
"That sign-in provider is not available."
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("shows a response's own message but never text from a URL", () => {
|
|
89
|
+
expect(
|
|
90
|
+
getLoginFeedback({failure: {message: "Invalid email or password", source: "response"}})
|
|
91
|
+
).toEqual({isSignUpClosed: false, passwordError: PASSWORD_MISMATCH_MESSAGE});
|
|
92
|
+
expect(
|
|
93
|
+
getLoginFeedback({failure: {code: "sign_in_failed", message: "evil", source: "url"}}).error
|
|
94
|
+
).toBe(LOGIN_FAILED_MESSAGE);
|
|
95
|
+
expect(getLoginFeedback({failure: {source: "response"}}).error).toBe(LOGIN_FAILED_MESSAGE);
|
|
96
|
+
});
|
|
97
|
+
});
|