@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,614 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from the pre-58 rtk package's `authSlice*.test.ts` and `isolated/emptyApi*.isolated.ts`:
|
|
3
|
+
* login, refresh before expiry, 401 refresh-retry, the shared refresh mutex, and logout on
|
|
4
|
+
* refresh failure — now against `jwtAuthAdapter` and the syncdb request client.
|
|
5
|
+
*
|
|
6
|
+
* `@terreno/api` dev-depends on `@terreno/syncdb`, so syncdb cannot start a real api test
|
|
7
|
+
* server without a workspace cycle. The fake below reproduces the JWT routes of
|
|
8
|
+
* `api/src/auth.ts` + `authRecovery.ts` (paths, bodies, `{data}` envelopes, `{message}` 401s,
|
|
9
|
+
* refresh responses without `userId`, token epochs) behind an in-memory `fetch`.
|
|
10
|
+
*/
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
|
|
12
|
+
import { DateTime } from "luxon";
|
|
13
|
+
import { ApiError } from "../api/apiError";
|
|
14
|
+
import { createApiClient } from "../api/client";
|
|
15
|
+
import { DEFAULT_JWT_AUTH_PATHS, DEFAULT_REFRESH_BEFORE_EXPIRY_SECS, jwtAuthAdapter, } from "./jwtAuthAdapter";
|
|
16
|
+
import { createSessionStore } from "./session";
|
|
17
|
+
import { AUTH_TOKEN_KEY, REFRESH_TOKEN_KEY } from "./tokenExpiry";
|
|
18
|
+
const BASE_URL = "http://api.test";
|
|
19
|
+
const base64Url = (value) => Buffer.from(value).toString("base64url");
|
|
20
|
+
/** A JWT-shaped token (the fake server checks signatures by remembering what it issued). */
|
|
21
|
+
const mintJwt = (claims, signature) => `${base64Url(JSON.stringify({ alg: "HS256", typ: "JWT" }))}.${base64Url(JSON.stringify(claims))}.${base64Url(signature)}`;
|
|
22
|
+
const nowSecs = () => Math.floor(DateTime.now().toSeconds());
|
|
23
|
+
const json = (status, body) => new Response(JSON.stringify(body), {
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
status,
|
|
26
|
+
});
|
|
27
|
+
const createFakeJwtServer = () => {
|
|
28
|
+
const users = new Map([
|
|
29
|
+
["ada@example.com", { email: "ada@example.com", id: "user-ada", password: "pw", tokenEpoch: 0 }],
|
|
30
|
+
]);
|
|
31
|
+
const issued = { access: new Set(), refresh: new Set() };
|
|
32
|
+
const requests = [];
|
|
33
|
+
let refreshCount = 0;
|
|
34
|
+
let signatureCounter = 0;
|
|
35
|
+
let gate;
|
|
36
|
+
let release;
|
|
37
|
+
const mint = ({ expiresInSecs, kind, user }) => {
|
|
38
|
+
signatureCounter += 1;
|
|
39
|
+
const token = mintJwt({
|
|
40
|
+
exp: nowSecs() + expiresInSecs,
|
|
41
|
+
iat: nowSecs(),
|
|
42
|
+
id: user.id,
|
|
43
|
+
sid: "session-1",
|
|
44
|
+
te: user.tokenEpoch,
|
|
45
|
+
}, `${kind}-${signatureCounter}`);
|
|
46
|
+
issued[kind].add(token);
|
|
47
|
+
return token;
|
|
48
|
+
};
|
|
49
|
+
const server = {
|
|
50
|
+
bumpTokenEpoch: (email) => {
|
|
51
|
+
const user = users.get(email);
|
|
52
|
+
if (user) {
|
|
53
|
+
user.tokenEpoch += 1;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
fetchImpl: async (input, init) => {
|
|
57
|
+
const url = new URL(input);
|
|
58
|
+
const body = init?.body ? JSON.parse(String(init.body)) : undefined;
|
|
59
|
+
const headers = new Headers(init?.headers);
|
|
60
|
+
requests.push({ body, headers, path: url.pathname });
|
|
61
|
+
const tokensFor = (user) => ({
|
|
62
|
+
refreshToken: mint({ expiresInSecs: server.ttl.refresh, kind: "refresh", user }),
|
|
63
|
+
token: mint({ expiresInSecs: server.ttl.access, kind: "access", user }),
|
|
64
|
+
});
|
|
65
|
+
const verify = (kind, token) => {
|
|
66
|
+
if (!token || !issued[kind].has(token)) {
|
|
67
|
+
return "invalid signature";
|
|
68
|
+
}
|
|
69
|
+
const claims = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString());
|
|
70
|
+
if (claims.exp <= nowSecs()) {
|
|
71
|
+
return "jwt expired";
|
|
72
|
+
}
|
|
73
|
+
const user = [...users.values()].find((candidate) => candidate.id === claims.id);
|
|
74
|
+
if (!user || user.tokenEpoch !== claims.te) {
|
|
75
|
+
return "Invalid refresh token";
|
|
76
|
+
}
|
|
77
|
+
return user;
|
|
78
|
+
};
|
|
79
|
+
if (url.pathname === "/auth/login") {
|
|
80
|
+
const user = users.get(body.email ?? body.username);
|
|
81
|
+
if (!user || user.password !== body.password) {
|
|
82
|
+
return json(401, { message: "Password or username is incorrect" });
|
|
83
|
+
}
|
|
84
|
+
return json(200, { data: { ...tokensFor(user), userId: user.id } });
|
|
85
|
+
}
|
|
86
|
+
if (url.pathname === "/auth/signup") {
|
|
87
|
+
if (users.has(body.email)) {
|
|
88
|
+
return json(400, { title: "A user with the given username is already registered" });
|
|
89
|
+
}
|
|
90
|
+
const user = {
|
|
91
|
+
email: body.email,
|
|
92
|
+
id: `user-${users.size + 1}`,
|
|
93
|
+
password: body.password,
|
|
94
|
+
tokenEpoch: 0,
|
|
95
|
+
};
|
|
96
|
+
users.set(body.email, user);
|
|
97
|
+
return json(200, { data: { ...tokensFor(user), userId: user.id } });
|
|
98
|
+
}
|
|
99
|
+
if (url.pathname === "/auth/google") {
|
|
100
|
+
if (body.idToken !== "google-id-token") {
|
|
101
|
+
return json(401, { message: "Invalid Google token" });
|
|
102
|
+
}
|
|
103
|
+
const user = users.get("ada@example.com");
|
|
104
|
+
return json(200, { data: { ...tokensFor(user), userId: user.id } });
|
|
105
|
+
}
|
|
106
|
+
if (url.pathname === "/resetPassword") {
|
|
107
|
+
if (body.token !== "reset-token" || !(body.password ?? body.newPassword)) {
|
|
108
|
+
return json(400, { status: 400, title: "Invalid or expired reset token" });
|
|
109
|
+
}
|
|
110
|
+
const user = users.get("ada@example.com");
|
|
111
|
+
user.tokenEpoch += 1;
|
|
112
|
+
return json(200, { data: { ...tokensFor(user), userId: user.id } });
|
|
113
|
+
}
|
|
114
|
+
if (url.pathname === "/auth/refresh_token") {
|
|
115
|
+
refreshCount += 1;
|
|
116
|
+
// Resolves immediately unless a test is holding refreshes.
|
|
117
|
+
await gate;
|
|
118
|
+
const failure = server.refreshFailure;
|
|
119
|
+
if (failure === "network") {
|
|
120
|
+
throw new TypeError("Failed to fetch");
|
|
121
|
+
}
|
|
122
|
+
if (failure === "garbage") {
|
|
123
|
+
return json(200, { data: { token: "only-an-access-token" } });
|
|
124
|
+
}
|
|
125
|
+
if (failure) {
|
|
126
|
+
return json(failure.status, failure.body);
|
|
127
|
+
}
|
|
128
|
+
if (!body?.refreshToken) {
|
|
129
|
+
return json(401, {
|
|
130
|
+
message: "No refresh token provided, must provide refreshToken in body",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const user = verify("refresh", body.refreshToken);
|
|
134
|
+
if (typeof user === "string") {
|
|
135
|
+
return json(401, { message: user });
|
|
136
|
+
}
|
|
137
|
+
// Like the API: a refresh returns a new pair but no userId.
|
|
138
|
+
return json(200, { data: tokensFor(user) });
|
|
139
|
+
}
|
|
140
|
+
if (url.pathname === "/auth/me") {
|
|
141
|
+
const token = headers.get("Authorization")?.replace(/^Bearer /, "");
|
|
142
|
+
const user = verify("access", token);
|
|
143
|
+
if (typeof user === "string") {
|
|
144
|
+
return json(401, { details: `[jwt] Error decoding token: ${user}`, message: user });
|
|
145
|
+
}
|
|
146
|
+
return json(200, { data: { _id: user.id, email: user.email } });
|
|
147
|
+
}
|
|
148
|
+
return json(404, { title: "Not found" });
|
|
149
|
+
},
|
|
150
|
+
holdRefresh: () => {
|
|
151
|
+
gate = new Promise((resolve) => {
|
|
152
|
+
release = resolve;
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
mint,
|
|
156
|
+
refreshCalls: () => refreshCount,
|
|
157
|
+
refreshFailure: null,
|
|
158
|
+
releaseRefresh: () => {
|
|
159
|
+
gate = undefined;
|
|
160
|
+
release?.();
|
|
161
|
+
},
|
|
162
|
+
requests,
|
|
163
|
+
revokeAccessTokens: () => {
|
|
164
|
+
issued.access.clear();
|
|
165
|
+
},
|
|
166
|
+
ttl: { access: 15 * 60, refresh: 30 * 24 * 60 * 60 },
|
|
167
|
+
users,
|
|
168
|
+
};
|
|
169
|
+
return server;
|
|
170
|
+
};
|
|
171
|
+
const createMemoryStorage = () => {
|
|
172
|
+
const items = new Map();
|
|
173
|
+
return {
|
|
174
|
+
getItem: async (key) => items.get(key) ?? null,
|
|
175
|
+
items,
|
|
176
|
+
removeItem: async (key) => {
|
|
177
|
+
items.delete(key);
|
|
178
|
+
},
|
|
179
|
+
setItem: async (key, value) => {
|
|
180
|
+
items.set(key, value);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
const ada = (server) => server.users.get("ada@example.com");
|
|
185
|
+
describe("jwtAuthAdapter", () => {
|
|
186
|
+
let server;
|
|
187
|
+
let storage;
|
|
188
|
+
let auth;
|
|
189
|
+
let warnSpy;
|
|
190
|
+
let debugSpy;
|
|
191
|
+
let errorSpy;
|
|
192
|
+
const makeAdapter = (options = {}) => jwtAuthAdapter({ baseUrl: BASE_URL, fetchImpl: server.fetchImpl, storage, ...options });
|
|
193
|
+
/** Store a token pair for ada directly, as if a previous app session had logged in. */
|
|
194
|
+
const seedTokens = ({ access, refresh }) => {
|
|
195
|
+
storage.items.set(AUTH_TOKEN_KEY, server.mint({ expiresInSecs: access, kind: "access", user: ada(server) }));
|
|
196
|
+
storage.items.set(REFRESH_TOKEN_KEY, server.mint({ expiresInSecs: refresh, kind: "refresh", user: ada(server) }));
|
|
197
|
+
};
|
|
198
|
+
beforeEach(() => {
|
|
199
|
+
server = createFakeJwtServer();
|
|
200
|
+
storage = createMemoryStorage();
|
|
201
|
+
auth = makeAdapter();
|
|
202
|
+
warnSpy = spyOn(console, "warn").mockImplementation(() => { });
|
|
203
|
+
debugSpy = spyOn(console, "debug").mockImplementation(() => { });
|
|
204
|
+
errorSpy = spyOn(console, "error").mockImplementation(() => { });
|
|
205
|
+
});
|
|
206
|
+
afterEach(() => {
|
|
207
|
+
warnSpy.mockRestore();
|
|
208
|
+
debugSpy.mockRestore();
|
|
209
|
+
errorSpy.mockRestore();
|
|
210
|
+
});
|
|
211
|
+
describe("login", () => {
|
|
212
|
+
it("stores both tokens, signs the session in, and notifies listeners", async () => {
|
|
213
|
+
const authChanges = [];
|
|
214
|
+
const snapshots = [];
|
|
215
|
+
auth.onAuthChange(() => authChanges.push(1));
|
|
216
|
+
auth.subscribe((snapshot) => snapshots.push(snapshot));
|
|
217
|
+
const result = await auth.login({ email: "ada@example.com", password: "pw" });
|
|
218
|
+
expect(result.userId).toBe("user-ada");
|
|
219
|
+
expect(storage.items.get(AUTH_TOKEN_KEY)).toBe(result.token);
|
|
220
|
+
expect(storage.items.get(REFRESH_TOKEN_KEY)).toBe(result.refreshToken);
|
|
221
|
+
expect(authChanges).toHaveLength(1);
|
|
222
|
+
expect(snapshots).toEqual([{ user: { id: "user-ada" }, userId: "user-ada" }]);
|
|
223
|
+
expect(await auth.getToken()).toBe(result.token);
|
|
224
|
+
expect(await auth.getUserId()).toBe("user-ada");
|
|
225
|
+
expect(await auth.getSession()).toEqual({ user: { id: "user-ada" }, userId: "user-ada" });
|
|
226
|
+
});
|
|
227
|
+
it("posts email, password, and username to /auth/login as JSON", async () => {
|
|
228
|
+
await auth.login({ password: "pw", username: "ada@example.com" });
|
|
229
|
+
const [request] = server.requests;
|
|
230
|
+
expect(request?.path).toBe("/auth/login");
|
|
231
|
+
expect(request?.body).toEqual({ password: "pw", username: "ada@example.com" });
|
|
232
|
+
expect(request?.headers.get("Content-Type")).toBe("application/json");
|
|
233
|
+
});
|
|
234
|
+
it("rejects with the API's message and stores nothing on bad credentials", async () => {
|
|
235
|
+
const error = await auth.login({ email: "ada@example.com", password: "nope" }).catch((e) => e);
|
|
236
|
+
expect(error).toBeInstanceOf(ApiError);
|
|
237
|
+
expect(error.status).toBe(401);
|
|
238
|
+
expect(error.message).toBe("Password or username is incorrect");
|
|
239
|
+
expect(storage.items.size).toBe(0);
|
|
240
|
+
expect(await auth.getToken()).toBeNull();
|
|
241
|
+
});
|
|
242
|
+
it("throws when the response has no token", async () => {
|
|
243
|
+
auth = makeAdapter({
|
|
244
|
+
fetchImpl: async () => json(200, { data: { userId: "user-ada" } }),
|
|
245
|
+
});
|
|
246
|
+
await expect(auth.login({ email: "ada@example.com", password: "pw" })).rejects.toThrow("Auth response did not include a token");
|
|
247
|
+
});
|
|
248
|
+
it("reads the user id from the token when the response omits it", async () => {
|
|
249
|
+
auth = makeAdapter({
|
|
250
|
+
fetchImpl: async () => json(200, {
|
|
251
|
+
data: { token: server.mint({ expiresInSecs: 900, kind: "access", user: ada(server) }) },
|
|
252
|
+
}),
|
|
253
|
+
});
|
|
254
|
+
const result = await auth.login({ email: "ada@example.com", password: "pw" });
|
|
255
|
+
expect(result.userId).toBe("user-ada");
|
|
256
|
+
expect(result.refreshToken).toBe("");
|
|
257
|
+
expect(storage.items.get(REFRESH_TOKEN_KEY)).toBe("");
|
|
258
|
+
});
|
|
259
|
+
it("sends configured extra headers", async () => {
|
|
260
|
+
auth = makeAdapter({ headers: async () => ({ "App-Platform": "web" }) });
|
|
261
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
262
|
+
expect(server.requests[0]?.headers.get("App-Platform")).toBe("web");
|
|
263
|
+
auth = makeAdapter({ headers: { "App-Version": "1.2.3" } });
|
|
264
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
265
|
+
expect(server.requests[1]?.headers.get("App-Version")).toBe("1.2.3");
|
|
266
|
+
});
|
|
267
|
+
it("uses overridden paths", async () => {
|
|
268
|
+
auth = makeAdapter({
|
|
269
|
+
fetchImpl: async (input, init) => server.fetchImpl(input.replace("/custom/login", "/auth/login"), init),
|
|
270
|
+
paths: { login: "/custom/login" },
|
|
271
|
+
});
|
|
272
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
273
|
+
expect(await auth.getUserId()).toBe("user-ada");
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
describe("signup, Google login, and password reset", () => {
|
|
277
|
+
it("signs up with extra fields and signs the session in", async () => {
|
|
278
|
+
const result = await auth.signup({ email: "grace@example.com", name: "Grace", password: "pw" });
|
|
279
|
+
expect(server.requests[0]).toMatchObject({
|
|
280
|
+
body: { email: "grace@example.com", name: "Grace", password: "pw" },
|
|
281
|
+
path: "/auth/signup",
|
|
282
|
+
});
|
|
283
|
+
expect(result.userId).toBe("user-2");
|
|
284
|
+
expect(await auth.getUserId()).toBe("user-2");
|
|
285
|
+
});
|
|
286
|
+
it("surfaces a JSON:API error title from signup", async () => {
|
|
287
|
+
await expect(auth.signup({ email: "ada@example.com", password: "pw" })).rejects.toThrow("A user with the given username is already registered");
|
|
288
|
+
});
|
|
289
|
+
it("signs in with a Google ID token", async () => {
|
|
290
|
+
await auth.googleLogin({ idToken: "google-id-token" });
|
|
291
|
+
expect(server.requests[0]?.path).toBe(DEFAULT_JWT_AUTH_PATHS.googleLogin);
|
|
292
|
+
expect(await auth.getUserId()).toBe("user-ada");
|
|
293
|
+
});
|
|
294
|
+
it("rejects a bad Google token", async () => {
|
|
295
|
+
await expect(auth.googleLogin({ idToken: "bad" })).rejects.toThrow("Invalid Google token");
|
|
296
|
+
});
|
|
297
|
+
it("resets a password without signing in", async () => {
|
|
298
|
+
const result = await auth.resetPassword({ password: "new", token: "reset-token" });
|
|
299
|
+
expect(server.requests[0]?.path).toBe("/resetPassword");
|
|
300
|
+
expect(result.userId).toBe("user-ada");
|
|
301
|
+
expect(result.token).toBeTruthy();
|
|
302
|
+
expect(storage.items.size).toBe(0);
|
|
303
|
+
});
|
|
304
|
+
it("rejects an invalid reset token with the API title", async () => {
|
|
305
|
+
await expect(auth.resetPassword({ password: "new", token: "nope" })).rejects.toThrow("Invalid or expired reset token");
|
|
306
|
+
});
|
|
307
|
+
it("setTokens stores a pair from a custom route and signs in", async () => {
|
|
308
|
+
const token = server.mint({ expiresInSecs: 900, kind: "access", user: ada(server) });
|
|
309
|
+
const snapshots = [];
|
|
310
|
+
auth.subscribe((snapshot) => snapshots.push(snapshot));
|
|
311
|
+
expect(await auth.setTokens({ token })).toBe("user-ada");
|
|
312
|
+
expect(storage.items.get(REFRESH_TOKEN_KEY)).toBe("");
|
|
313
|
+
expect(snapshots).toEqual([{ user: { id: "user-ada" }, userId: "user-ada" }]);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe("getToken", () => {
|
|
317
|
+
it("returns null without a stored token", async () => {
|
|
318
|
+
expect(await auth.getToken()).toBeNull();
|
|
319
|
+
expect(server.refreshCalls()).toBe(0);
|
|
320
|
+
});
|
|
321
|
+
it("returns the stored token when it is not close to expiring", async () => {
|
|
322
|
+
seedTokens({ access: 900, refresh: 3600 });
|
|
323
|
+
expect(await auth.getToken()).toBe(storage.items.get(AUTH_TOKEN_KEY));
|
|
324
|
+
expect(server.refreshCalls()).toBe(0);
|
|
325
|
+
});
|
|
326
|
+
it("refreshes the token before the request when it is about to expire", async () => {
|
|
327
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
328
|
+
const oldToken = storage.items.get(AUTH_TOKEN_KEY);
|
|
329
|
+
const authChanges = [];
|
|
330
|
+
auth.onAuthChange(() => authChanges.push(1));
|
|
331
|
+
const token = await auth.getToken();
|
|
332
|
+
expect(server.refreshCalls()).toBe(1);
|
|
333
|
+
expect(token).not.toBe(oldToken);
|
|
334
|
+
expect(token).toBe(storage.items.get(AUTH_TOKEN_KEY));
|
|
335
|
+
expect(authChanges).toHaveLength(1);
|
|
336
|
+
expect(DEFAULT_REFRESH_BEFORE_EXPIRY_SECS).toBe(130);
|
|
337
|
+
});
|
|
338
|
+
it("refreshes an expired access token while the refresh token is valid", async () => {
|
|
339
|
+
seedTokens({ access: -10, refresh: 3600 });
|
|
340
|
+
expect(await auth.getToken()).toBeTruthy();
|
|
341
|
+
expect(server.refreshCalls()).toBe(1);
|
|
342
|
+
});
|
|
343
|
+
it("honours a custom refresh threshold", async () => {
|
|
344
|
+
auth = makeAdapter({ refreshBeforeExpirySecs: 30 });
|
|
345
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
346
|
+
await auth.getToken();
|
|
347
|
+
expect(server.refreshCalls()).toBe(0);
|
|
348
|
+
});
|
|
349
|
+
it("shares one refresh between concurrent requests (mutex)", async () => {
|
|
350
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
351
|
+
server.holdRefresh();
|
|
352
|
+
const pending = Promise.all([auth.getToken(), auth.getToken(), auth.getToken()]);
|
|
353
|
+
await Bun.sleep(5);
|
|
354
|
+
// A request that starts while the refresh is in flight waits for it.
|
|
355
|
+
const late = auth.getToken();
|
|
356
|
+
server.releaseRefresh();
|
|
357
|
+
const tokens = [...(await pending), await late];
|
|
358
|
+
expect(server.refreshCalls()).toBe(1);
|
|
359
|
+
expect(new Set(tokens).size).toBe(1);
|
|
360
|
+
expect(tokens[0]).toBe(storage.items.get(AUTH_TOKEN_KEY));
|
|
361
|
+
});
|
|
362
|
+
it("keeps the current token when the refresh hits a network error", async () => {
|
|
363
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
364
|
+
const current = storage.items.get(AUTH_TOKEN_KEY);
|
|
365
|
+
server.refreshFailure = "network";
|
|
366
|
+
expect(await auth.getToken()).toBe(current);
|
|
367
|
+
expect(storage.items.get(AUTH_TOKEN_KEY)).toBe(current);
|
|
368
|
+
expect(await auth.getUserId()).toBe("user-ada");
|
|
369
|
+
});
|
|
370
|
+
it("keeps the session when the refresh request times out", async () => {
|
|
371
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
372
|
+
auth = makeAdapter({
|
|
373
|
+
fetchImpl: (_input, init) => new Promise((_resolve, reject) => {
|
|
374
|
+
init?.signal?.addEventListener("abort", () => reject(new Error("aborted")));
|
|
375
|
+
}),
|
|
376
|
+
timeoutMs: 5,
|
|
377
|
+
});
|
|
378
|
+
expect(await auth.refresh()).toBe(false);
|
|
379
|
+
expect(storage.items.has(AUTH_TOKEN_KEY)).toBe(true);
|
|
380
|
+
});
|
|
381
|
+
it("logs out when the refresh is rejected with a 401", async () => {
|
|
382
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
383
|
+
server.refreshFailure = { body: { message: "jwt expired" }, status: 401 };
|
|
384
|
+
const snapshots = [];
|
|
385
|
+
auth.subscribe((snapshot) => snapshots.push(snapshot));
|
|
386
|
+
expect(await auth.getToken()).toBeNull();
|
|
387
|
+
expect(storage.items.has(AUTH_TOKEN_KEY)).toBe(false);
|
|
388
|
+
expect(storage.items.has(REFRESH_TOKEN_KEY)).toBe(false);
|
|
389
|
+
expect(snapshots).toEqual([null]);
|
|
390
|
+
expect(await auth.getUserId()).toBeNull();
|
|
391
|
+
});
|
|
392
|
+
it("logs out when the refresh fails for another reason", async () => {
|
|
393
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
394
|
+
server.refreshFailure = { body: "<html>oops</html>", status: 500 };
|
|
395
|
+
expect(await auth.getToken()).toBeNull();
|
|
396
|
+
expect(storage.items.size).toBe(0);
|
|
397
|
+
});
|
|
398
|
+
it("logs out when the refresh response is missing a token", async () => {
|
|
399
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
400
|
+
server.refreshFailure = "garbage";
|
|
401
|
+
expect(await auth.getToken()).toBeNull();
|
|
402
|
+
expect(storage.items.size).toBe(0);
|
|
403
|
+
});
|
|
404
|
+
it("logs out when both tokens are expired", async () => {
|
|
405
|
+
seedTokens({ access: -10, refresh: -5 });
|
|
406
|
+
const snapshots = [];
|
|
407
|
+
auth.subscribe((snapshot) => snapshots.push(snapshot));
|
|
408
|
+
expect(await auth.getToken()).toBeNull();
|
|
409
|
+
expect(server.refreshCalls()).toBe(0);
|
|
410
|
+
expect(storage.items.size).toBe(0);
|
|
411
|
+
expect(snapshots).toEqual([null]);
|
|
412
|
+
});
|
|
413
|
+
it("passes a token without an exp claim through untouched", async () => {
|
|
414
|
+
storage.items.set(AUTH_TOKEN_KEY, "opaque-token");
|
|
415
|
+
storage.items.set(REFRESH_TOKEN_KEY, "opaque-refresh");
|
|
416
|
+
expect(await auth.getToken()).toBe("opaque-token");
|
|
417
|
+
expect(await auth.getUserId()).toBeNull();
|
|
418
|
+
});
|
|
419
|
+
it("signs out when saving refreshed tokens fails", async () => {
|
|
420
|
+
seedTokens({ access: 60, refresh: 3600 });
|
|
421
|
+
const setItem = storage.setItem;
|
|
422
|
+
storage.setItem = async () => {
|
|
423
|
+
throw new Error("disk full");
|
|
424
|
+
};
|
|
425
|
+
expect(await auth.getToken()).toBeNull();
|
|
426
|
+
storage.setItem = setItem;
|
|
427
|
+
expect(storage.items.size).toBe(0);
|
|
428
|
+
});
|
|
429
|
+
it("still notifies listeners when clearing tokens fails", async () => {
|
|
430
|
+
seedTokens({ access: -10, refresh: -5 });
|
|
431
|
+
storage.removeItem = async () => {
|
|
432
|
+
throw new Error("locked");
|
|
433
|
+
};
|
|
434
|
+
const snapshots = [];
|
|
435
|
+
auth.subscribe((snapshot) => snapshots.push(snapshot));
|
|
436
|
+
expect(await auth.getToken()).toBeNull();
|
|
437
|
+
expect(snapshots).toEqual([null]);
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
describe("refresh", () => {
|
|
441
|
+
it("rotates the token pair and reports success", async () => {
|
|
442
|
+
seedTokens({ access: 900, refresh: 3600 });
|
|
443
|
+
const before = storage.items.get(REFRESH_TOKEN_KEY);
|
|
444
|
+
expect(await auth.refresh()).toBe(true);
|
|
445
|
+
expect(storage.items.get(REFRESH_TOKEN_KEY)).not.toBe(before);
|
|
446
|
+
expect(server.requests.at(-1)?.body).toEqual({ refreshToken: before });
|
|
447
|
+
});
|
|
448
|
+
it("signs out and reports failure when no refresh token is stored", async () => {
|
|
449
|
+
storage.items.set(AUTH_TOKEN_KEY, "token-only");
|
|
450
|
+
storage.items.set(REFRESH_TOKEN_KEY, "");
|
|
451
|
+
expect(await auth.refresh()).toBe(false);
|
|
452
|
+
expect(server.refreshCalls()).toBe(0);
|
|
453
|
+
expect(storage.items.size).toBe(0);
|
|
454
|
+
});
|
|
455
|
+
it("signs out when the user's token epoch changed", async () => {
|
|
456
|
+
seedTokens({ access: 900, refresh: 3600 });
|
|
457
|
+
server.bumpTokenEpoch("ada@example.com");
|
|
458
|
+
expect(await auth.refresh()).toBe(false);
|
|
459
|
+
expect(storage.items.size).toBe(0);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
describe("with the syncdb request client", () => {
|
|
463
|
+
it("refreshes and retries once after a 401 response", async () => {
|
|
464
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
465
|
+
server.revokeAccessTokens();
|
|
466
|
+
const client = createApiClient({
|
|
467
|
+
authProvider: auth,
|
|
468
|
+
baseUrl: BASE_URL,
|
|
469
|
+
fetchImpl: server.fetchImpl,
|
|
470
|
+
});
|
|
471
|
+
const me = await client.request({ url: "/auth/me" });
|
|
472
|
+
expect(me._id).toBe("user-ada");
|
|
473
|
+
expect(server.refreshCalls()).toBe(1);
|
|
474
|
+
const meRequests = server.requests.filter((request) => request.path === "/auth/me");
|
|
475
|
+
expect(meRequests).toHaveLength(2);
|
|
476
|
+
expect(meRequests[1]?.headers.get("Authorization")).toBe(`Bearer ${storage.items.get(AUTH_TOKEN_KEY)}`);
|
|
477
|
+
});
|
|
478
|
+
it("refreshes once for a burst of concurrent 401s", async () => {
|
|
479
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
480
|
+
server.revokeAccessTokens();
|
|
481
|
+
const client = createApiClient({
|
|
482
|
+
authProvider: auth,
|
|
483
|
+
baseUrl: BASE_URL,
|
|
484
|
+
fetchImpl: server.fetchImpl,
|
|
485
|
+
});
|
|
486
|
+
const results = await Promise.all([
|
|
487
|
+
client.request({ url: "/auth/me" }),
|
|
488
|
+
client.request({ url: "/auth/me" }),
|
|
489
|
+
client.request({ url: "/auth/me" }),
|
|
490
|
+
]);
|
|
491
|
+
expect(results.map((result) => result._id)).toEqual(["user-ada", "user-ada", "user-ada"]);
|
|
492
|
+
expect(server.refreshCalls()).toBe(1);
|
|
493
|
+
});
|
|
494
|
+
it("logs out when the refresh after a 401 fails", async () => {
|
|
495
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
496
|
+
server.revokeAccessTokens();
|
|
497
|
+
server.bumpTokenEpoch("ada@example.com");
|
|
498
|
+
const client = createApiClient({
|
|
499
|
+
authProvider: auth,
|
|
500
|
+
baseUrl: BASE_URL,
|
|
501
|
+
fetchImpl: server.fetchImpl,
|
|
502
|
+
});
|
|
503
|
+
const error = await client.request({ url: "/auth/me" }).catch((e) => e);
|
|
504
|
+
expect(error).toBeInstanceOf(ApiError);
|
|
505
|
+
expect(error.status).toBe(401);
|
|
506
|
+
expect(storage.items.size).toBe(0);
|
|
507
|
+
expect(await auth.getUserId()).toBeNull();
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
describe("session source", () => {
|
|
511
|
+
it("drives a session store through login, refresh failure, and logout", async () => {
|
|
512
|
+
const store = createSessionStore({ pollIntervalMs: 0, source: auth });
|
|
513
|
+
store.start();
|
|
514
|
+
await Bun.sleep(0);
|
|
515
|
+
expect(store.getState()).toMatchObject({ isAuthenticated: false, isLoading: false });
|
|
516
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
517
|
+
expect(store.getState()).toMatchObject({ isAuthenticated: true, userId: "user-ada" });
|
|
518
|
+
server.refreshFailure = { body: { message: "Invalid refresh token" }, status: 401 };
|
|
519
|
+
expect(await auth.refresh()).toBe(false);
|
|
520
|
+
expect(store.getState()).toMatchObject({ isAuthenticated: false, userId: null });
|
|
521
|
+
server.refreshFailure = null;
|
|
522
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
523
|
+
await store.logout();
|
|
524
|
+
expect(store.getState().isAuthenticated).toBe(false);
|
|
525
|
+
expect(storage.items.size).toBe(0);
|
|
526
|
+
store.stop();
|
|
527
|
+
});
|
|
528
|
+
it("restores a stored session on startup", async () => {
|
|
529
|
+
seedTokens({ access: 900, refresh: 3600 });
|
|
530
|
+
const store = createSessionStore({ pollIntervalMs: 0, source: auth });
|
|
531
|
+
store.start();
|
|
532
|
+
await store.refresh();
|
|
533
|
+
expect(store.getState()).toMatchObject({ isAuthenticated: true, userId: "user-ada" });
|
|
534
|
+
store.stop();
|
|
535
|
+
});
|
|
536
|
+
it("reports no session and clears tokens when both are expired", async () => {
|
|
537
|
+
seedTokens({ access: -10, refresh: -5 });
|
|
538
|
+
expect(await auth.getSession()).toBeNull();
|
|
539
|
+
expect(storage.items.size).toBe(0);
|
|
540
|
+
expect(await auth.getSession()).toBeNull();
|
|
541
|
+
});
|
|
542
|
+
it("stops notifying unsubscribed listeners", async () => {
|
|
543
|
+
const authChanges = [];
|
|
544
|
+
const snapshots = [];
|
|
545
|
+
const offAuth = auth.onAuthChange(() => authChanges.push(1));
|
|
546
|
+
const offSession = auth.subscribe((snapshot) => snapshots.push(snapshot));
|
|
547
|
+
offAuth();
|
|
548
|
+
offSession();
|
|
549
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
550
|
+
await auth.signOut();
|
|
551
|
+
expect(authChanges).toEqual([]);
|
|
552
|
+
expect(snapshots).toEqual([]);
|
|
553
|
+
});
|
|
554
|
+
it("signOut clears the tokens and notifies listeners", async () => {
|
|
555
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
556
|
+
const authChanges = [];
|
|
557
|
+
auth.onAuthChange(() => authChanges.push(1));
|
|
558
|
+
await auth.signOut();
|
|
559
|
+
expect(storage.items.size).toBe(0);
|
|
560
|
+
expect(authChanges).toHaveLength(1);
|
|
561
|
+
expect(await auth.getToken()).toBeNull();
|
|
562
|
+
});
|
|
563
|
+
it("getUserId degrades to null when storage cannot be read", async () => {
|
|
564
|
+
storage.getItem = async () => {
|
|
565
|
+
throw new Error("keychain locked");
|
|
566
|
+
};
|
|
567
|
+
expect(await auth.getUserId()).toBeNull();
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
describe("error mapping", () => {
|
|
571
|
+
it("falls back to the status when the error body is not JSON", async () => {
|
|
572
|
+
auth = makeAdapter({
|
|
573
|
+
fetchImpl: async () => new Response("oops", { status: 502 }),
|
|
574
|
+
});
|
|
575
|
+
const error = await auth.login({ email: "a", password: "b" }).catch((e) => e);
|
|
576
|
+
expect(error).toBeInstanceOf(ApiError);
|
|
577
|
+
expect(error.status).toBe(502);
|
|
578
|
+
expect(error.message).toBe("Request failed (502)");
|
|
579
|
+
});
|
|
580
|
+
it("keeps detail and code from JSON:API error bodies", async () => {
|
|
581
|
+
auth = makeAdapter({
|
|
582
|
+
fetchImpl: async () => json(403, {
|
|
583
|
+
code: "email-not-verified",
|
|
584
|
+
detail: "Check your inbox",
|
|
585
|
+
title: "Email is not verified",
|
|
586
|
+
}),
|
|
587
|
+
});
|
|
588
|
+
const error = await auth.login({ email: "a", password: "b" }).catch((e) => e);
|
|
589
|
+
expect(error.data).toEqual({
|
|
590
|
+
code: "email-not-verified",
|
|
591
|
+
detail: "Check your inbox",
|
|
592
|
+
title: "Email is not verified",
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
it("maps a failed fetch to a network ApiError", async () => {
|
|
596
|
+
auth = makeAdapter({
|
|
597
|
+
fetchImpl: async () => {
|
|
598
|
+
throw new TypeError("Failed to fetch");
|
|
599
|
+
},
|
|
600
|
+
});
|
|
601
|
+
const error = await auth.login({ email: "a", password: "b" }).catch((e) => e);
|
|
602
|
+
expect(error.status).toBe(0);
|
|
603
|
+
expect(error.data.code).toBe("network-error");
|
|
604
|
+
});
|
|
605
|
+
it("uses the global fetch by default", async () => {
|
|
606
|
+
const fetchSpy = spyOn(globalThis, "fetch").mockImplementation(((input, init) => server.fetchImpl(input, init)));
|
|
607
|
+
auth = jwtAuthAdapter({ baseUrl: BASE_URL, storage });
|
|
608
|
+
await auth.login({ email: "ada@example.com", password: "pw" });
|
|
609
|
+
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
610
|
+
fetchSpy.mockRestore();
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
//# sourceMappingURL=jwtAuthAdapter.test.js.map
|