@terreno/syncdb 57.21.0 → 58.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -0
- package/README.md +8 -8
- package/dist/api/apiError.d.ts +43 -0
- package/dist/api/apiError.d.ts.map +1 -0
- package/dist/api/apiError.js +28 -0
- package/dist/api/apiError.js.map +1 -0
- package/dist/api/apiFetch.d.ts +44 -0
- package/dist/api/apiFetch.d.ts.map +1 -0
- package/dist/api/apiFetch.js +203 -0
- package/dist/api/apiFetch.js.map +1 -0
- package/dist/api/client.d.ts +70 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +240 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/client.test.d.ts +2 -0
- package/dist/api/client.test.d.ts.map +1 -0
- package/dist/api/client.test.js +588 -0
- package/dist/api/client.test.js.map +1 -0
- package/dist/app/app.d.ts +13 -0
- package/dist/app/app.d.ts.map +1 -0
- package/dist/app/app.js +13 -0
- package/dist/app/app.js.map +1 -0
- package/dist/app/devConsoleLogger.d.ts +18 -0
- package/dist/app/devConsoleLogger.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.js +147 -0
- package/dist/app/devConsoleLogger.js.map +1 -0
- package/dist/app/devConsoleLogger.test.d.ts +2 -0
- package/dist/app/devConsoleLogger.test.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.test.js +202 -0
- package/dist/app/devConsoleLogger.test.js.map +1 -0
- package/dist/app/mcpTools.d.ts +32 -0
- package/dist/app/mcpTools.d.ts.map +1 -0
- package/dist/app/mcpTools.js +61 -0
- package/dist/app/mcpTools.js.map +1 -0
- package/dist/app/permissions.d.ts +26 -0
- package/dist/app/permissions.d.ts.map +1 -0
- package/dist/app/permissions.js +37 -0
- package/dist/app/permissions.js.map +1 -0
- package/dist/app/permissions.test.d.ts +2 -0
- package/dist/app/permissions.test.d.ts.map +1 -0
- package/dist/app/permissions.test.js +36 -0
- package/dist/app/permissions.test.js.map +1 -0
- package/dist/app/upgradeCheck.d.ts +46 -0
- package/dist/app/upgradeCheck.d.ts.map +1 -0
- package/dist/app/upgradeCheck.js +121 -0
- package/dist/app/upgradeCheck.js.map +1 -0
- package/dist/auth/SessionProvider.d.ts +40 -0
- package/dist/auth/SessionProvider.d.ts.map +1 -0
- package/dist/auth/SessionProvider.js +44 -0
- package/dist/auth/SessionProvider.js.map +1 -0
- package/dist/auth/SessionProvider.test.d.ts +2 -0
- package/dist/auth/SessionProvider.test.d.ts.map +1 -0
- package/dist/auth/SessionProvider.test.js +240 -0
- package/dist/auth/SessionProvider.test.js.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts +25 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js +21 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js.map +1 -0
- package/dist/auth/TerrenoLoginScreen.d.ts +62 -0
- package/dist/auth/TerrenoLoginScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoLoginScreen.js +45 -0
- package/dist/auth/TerrenoLoginScreen.js.map +1 -0
- package/dist/auth/auth.d.ts +36 -0
- package/dist/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth.js +35 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/betterAuthAdapter.d.ts +1 -1
- package/dist/auth/betterAuthClient.d.ts +276 -0
- package/dist/auth/betterAuthClient.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.js +744 -0
- package/dist/auth/betterAuthClient.js.map +1 -0
- package/dist/auth/betterAuthClient.types.test.d.ts +2 -0
- package/dist/auth/betterAuthClient.types.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.types.test.js +151 -0
- package/dist/auth/betterAuthClient.types.test.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.d.ts +51 -0
- package/dist/auth/betterAuthClientRegistry.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.js +69 -0
- package/dist/auth/betterAuthClientRegistry.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts +2 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.js +91 -0
- package/dist/auth/betterAuthClientRegistry.test.js.map +1 -0
- package/dist/auth/betterAuthTypes.d.ts +172 -0
- package/dist/auth/betterAuthTypes.d.ts.map +1 -0
- package/dist/auth/betterAuthTypes.js +7 -0
- package/dist/auth/betterAuthTypes.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.d.ts +102 -0
- package/dist/auth/jwtAuthAdapter.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.js +282 -0
- package/dist/auth/jwtAuthAdapter.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts +2 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.js +614 -0
- package/dist/auth/jwtAuthAdapter.test.js.map +1 -0
- package/dist/auth/loginErrors.d.ts +75 -0
- package/dist/auth/loginErrors.d.ts.map +1 -0
- package/dist/auth/loginErrors.js +154 -0
- package/dist/auth/loginErrors.js.map +1 -0
- package/dist/auth/loginErrors.test.d.ts +2 -0
- package/dist/auth/loginErrors.test.d.ts.map +1 -0
- package/dist/auth/loginErrors.test.js +70 -0
- package/dist/auth/loginErrors.test.js.map +1 -0
- package/dist/auth/ownEntry.d.ts +8 -0
- package/dist/auth/ownEntry.d.ts.map +1 -0
- package/dist/auth/ownEntry.js +13 -0
- package/dist/auth/ownEntry.js.map +1 -0
- package/dist/auth/ownEntry.test.d.ts +2 -0
- package/dist/auth/ownEntry.test.d.ts.map +1 -0
- package/dist/auth/ownEntry.test.js +18 -0
- package/dist/auth/ownEntry.test.js.map +1 -0
- package/dist/auth/platform.d.ts +3 -0
- package/dist/auth/platform.d.ts.map +1 -0
- package/dist/auth/platform.js +4 -0
- package/dist/auth/platform.js.map +1 -0
- package/dist/auth/rememberedAccounts.d.ts +126 -0
- package/dist/auth/rememberedAccounts.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.js +399 -0
- package/dist/auth/rememberedAccounts.js.map +1 -0
- package/dist/auth/rememberedAccounts.test.d.ts +2 -0
- package/dist/auth/rememberedAccounts.test.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.test.js +676 -0
- package/dist/auth/rememberedAccounts.test.js.map +1 -0
- package/dist/auth/session.d.ts +118 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +370 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/session.test.d.ts +2 -0
- package/dist/auth/session.test.d.ts.map +1 -0
- package/dist/auth/session.test.js +825 -0
- package/dist/auth/session.test.js.map +1 -0
- package/dist/auth/tokenExpiry.d.ts +70 -0
- package/dist/auth/tokenExpiry.d.ts.map +1 -0
- package/dist/auth/tokenExpiry.js +123 -0
- package/dist/auth/tokenExpiry.js.map +1 -0
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.js +1 -1
- package/dist/auth/useAccountSecurity.d.ts +183 -0
- package/dist/auth/useAccountSecurity.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.js +399 -0
- package/dist/auth/useAccountSecurity.js.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts +2 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.js +21 -0
- package/dist/auth/useAccountSecurity.types.test.js.map +1 -0
- package/dist/auth/useAuthMethods.d.ts +67 -0
- package/dist/auth/useAuthMethods.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.js +77 -0
- package/dist/auth/useAuthMethods.js.map +1 -0
- package/dist/auth/useAuthMethods.test.d.ts +2 -0
- package/dist/auth/useAuthMethods.test.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.test.js +145 -0
- package/dist/auth/useAuthMethods.test.js.map +1 -0
- package/dist/auth/useJwtAuth.d.ts +31 -0
- package/dist/auth/useJwtAuth.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.js +58 -0
- package/dist/auth/useJwtAuth.js.map +1 -0
- package/dist/auth/useJwtAuth.test.d.ts +2 -0
- package/dist/auth/useJwtAuth.test.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.test.js +165 -0
- package/dist/auth/useJwtAuth.test.js.map +1 -0
- package/dist/auth/useLoginController.d.ts +248 -0
- package/dist/auth/useLoginController.d.ts.map +1 -0
- package/dist/auth/useLoginController.js +671 -0
- package/dist/auth/useLoginController.js.map +1 -0
- package/dist/auth/useLoginController.types.test.d.ts +2 -0
- package/dist/auth/useLoginController.types.test.d.ts.map +1 -0
- package/dist/auth/useLoginController.types.test.js +19 -0
- package/dist/auth/useLoginController.types.test.js.map +1 -0
- package/dist/buildNumber.d.ts +34 -0
- package/dist/buildNumber.d.ts.map +1 -0
- package/dist/buildNumber.js +62 -0
- package/dist/buildNumber.js.map +1 -0
- package/dist/buildNumber.test.d.ts +2 -0
- package/dist/buildNumber.test.d.ts.map +1 -0
- package/dist/buildNumber.test.js +114 -0
- package/dist/buildNumber.test.js.map +1 -0
- package/dist/client.d.ts +18 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +245 -185
- package/dist/client.js.map +1 -1
- package/dist/client.socketEvents.test.d.ts +2 -0
- package/dist/client.socketEvents.test.d.ts.map +1 -0
- package/dist/client.socketEvents.test.js +64 -0
- package/dist/client.socketEvents.test.js.map +1 -0
- package/dist/client.test.js +87 -1
- package/dist/client.test.js.map +1 -1
- package/dist/codegen/cli.js +23 -12
- package/dist/codegen/cli.js.map +1 -1
- package/dist/codegen/cli.test.js +57 -0
- package/dist/codegen/cli.test.js.map +1 -1
- package/dist/codegen/discoverCollections.d.ts.map +1 -1
- package/dist/codegen/discoverCollections.js +4 -0
- package/dist/codegen/discoverCollections.js.map +1 -1
- package/dist/codegen/discoverOperations.d.ts +11 -0
- package/dist/codegen/discoverOperations.d.ts.map +1 -0
- package/dist/codegen/discoverOperations.js +135 -0
- package/dist/codegen/discoverOperations.js.map +1 -0
- package/dist/codegen/emitApi.d.ts +8 -0
- package/dist/codegen/emitApi.d.ts.map +1 -0
- package/dist/codegen/emitApi.js +312 -0
- package/dist/codegen/emitApi.js.map +1 -0
- package/dist/codegen/emitApi.test.d.ts +2 -0
- package/dist/codegen/emitApi.test.d.ts.map +1 -0
- package/dist/codegen/emitApi.test.js +360 -0
- package/dist/codegen/emitApi.test.js.map +1 -0
- package/dist/codegen/emitSdk.js +2 -2
- package/dist/codegen/generate.d.ts +6 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/generate.js +18 -0
- package/dist/codegen/generate.js.map +1 -1
- package/dist/codegen/generate.test.js +53 -1
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/hookNames.d.ts +11 -0
- package/dist/codegen/hookNames.d.ts.map +1 -1
- package/dist/codegen/hookNames.js +23 -0
- package/dist/codegen/hookNames.js.map +1 -1
- package/dist/codegen/safeIdentifiers.d.ts +5 -1
- package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
- package/dist/codegen/safeIdentifiers.js +7 -2
- package/dist/codegen/safeIdentifiers.js.map +1 -1
- package/dist/codegen/safeIdentifiers.test.js +9 -0
- package/dist/codegen/safeIdentifiers.test.js.map +1 -1
- package/dist/codegen/types.d.ts +46 -1
- package/dist/codegen/types.d.ts.map +1 -1
- package/dist/config/baseUrl.d.ts +13 -0
- package/dist/config/baseUrl.d.ts.map +1 -0
- package/dist/config/baseUrl.js +49 -0
- package/dist/config/baseUrl.js.map +1 -0
- package/dist/config/baseUrl.test.d.ts +2 -0
- package/dist/config/baseUrl.test.d.ts.map +1 -0
- package/dist/config/baseUrl.test.js +42 -0
- package/dist/config/baseUrl.test.js.map +1 -0
- package/dist/config/resolveBaseUrls.d.ts +53 -0
- package/dist/config/resolveBaseUrls.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.js +80 -0
- package/dist/config/resolveBaseUrls.js.map +1 -0
- package/dist/config/resolveBaseUrls.test.d.ts +2 -0
- package/dist/config/resolveBaseUrls.test.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.test.js +265 -0
- package/dist/config/resolveBaseUrls.test.js.map +1 -0
- package/dist/crypto/keyProviders.d.ts +2 -2
- package/dist/crypto/keyProviders.d.ts.map +1 -1
- package/dist/crypto/keyProviders.js +15 -4
- package/dist/crypto/keyProviders.js.map +1 -1
- package/dist/crypto/keyProviders.test.js +19 -0
- package/dist/crypto/keyProviders.test.js.map +1 -1
- package/dist/crypto/types.d.ts +5 -0
- package/dist/crypto/types.d.ts.map +1 -1
- package/dist/flags/flagTestServer.d.ts +19 -0
- package/dist/flags/flagTestServer.d.ts.map +1 -0
- package/dist/flags/flagTestServer.js +58 -0
- package/dist/flags/flagTestServer.js.map +1 -0
- package/dist/flags/useFeatureFlags.d.ts +30 -0
- package/dist/flags/useFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.js +83 -0
- package/dist/flags/useFeatureFlags.js.map +1 -0
- package/dist/flags/useFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.test.js +116 -0
- package/dist/flags/useFeatureFlags.test.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts +50 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.js +125 -0
- package/dist/flags/useTerrenoFeatureFlags.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js +259 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js +94 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js +183 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.js +1734 -0
- package/dist/isolated/betterAuthClient.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.js +153 -0
- package/dist/isolated/betterAuthClient.native.isolated.js.map +1 -0
- package/dist/isolated/mcpTools.isolated.d.ts +2 -0
- package/dist/isolated/mcpTools.isolated.d.ts.map +1 -0
- package/dist/isolated/mcpTools.isolated.js +197 -0
- package/dist/isolated/mcpTools.isolated.js.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts +2 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js +50 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js.map +1 -0
- package/dist/isolated/sessionLogout.isolated.d.ts +2 -0
- package/dist/isolated/sessionLogout.isolated.d.ts.map +1 -0
- package/dist/isolated/sessionLogout.isolated.js +133 -0
- package/dist/isolated/sessionLogout.isolated.js.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts +2 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.js +232 -0
- package/dist/isolated/tokenExpiry.isolated.js.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts +2 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.js +241 -0
- package/dist/isolated/upgradeCheck.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.js +851 -0
- package/dist/isolated/useAccountSecurity.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js +52 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js.map +1 -0
- package/dist/isolated/useLoginController.isolated.d.ts +2 -0
- package/dist/isolated/useLoginController.isolated.d.ts.map +1 -0
- package/dist/isolated/useLoginController.isolated.js +1116 -0
- package/dist/isolated/useLoginController.isolated.js.map +1 -0
- package/dist/mutations/entityIds.d.ts +23 -0
- package/dist/mutations/entityIds.d.ts.map +1 -0
- package/dist/mutations/entityIds.js +31 -0
- package/dist/mutations/entityIds.js.map +1 -0
- package/dist/mutations/entityIds.test.d.ts +2 -0
- package/dist/mutations/entityIds.test.d.ts.map +1 -0
- package/dist/mutations/entityIds.test.js +48 -0
- package/dist/mutations/entityIds.test.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -1
- package/dist/persisters/defaultPersisterFactory.native.js +2 -0
- package/dist/persisters/defaultPersisterFactory.native.js.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.js +3 -0
- package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -1
- package/dist/persisters/types.d.ts +6 -0
- package/dist/persisters/types.d.ts.map +1 -1
- package/dist/query/queryWindows.js +2 -2
- package/dist/query/queryWindows.js.map +1 -1
- package/dist/react/apiHooks.d.ts +87 -0
- package/dist/react/apiHooks.d.ts.map +1 -0
- package/dist/react/apiHooks.js +195 -0
- package/dist/react/apiHooks.js.map +1 -0
- package/dist/react/apiHooks.test.d.ts +2 -0
- package/dist/react/apiHooks.test.d.ts.map +1 -0
- package/dist/react/apiHooks.test.js +366 -0
- package/dist/react/apiHooks.test.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +2 -0
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +2 -0
- package/dist/react/provider.js.map +1 -1
- package/dist/react/useSocketEvent.d.ts +27 -0
- package/dist/react/useSocketEvent.d.ts.map +1 -0
- package/dist/react/useSocketEvent.js +36 -0
- package/dist/react/useSocketEvent.js.map +1 -0
- package/dist/react/useSocketEvent.test.d.ts +2 -0
- package/dist/react/useSocketEvent.test.d.ts.map +1 -0
- package/dist/react/useSocketEvent.test.js +76 -0
- package/dist/react/useSocketEvent.test.js.map +1 -0
- package/dist/sync/replayCoordinator.d.ts.map +1 -1
- package/dist/sync/replayCoordinator.js +5 -4
- package/dist/sync/replayCoordinator.js.map +1 -1
- package/dist/sync/socketTransport.d.ts.map +1 -1
- package/dist/sync/socketTransport.js +14 -1
- package/dist/sync/socketTransport.js.map +1 -1
- package/dist/sync/socketTransport.test.js +42 -0
- package/dist/sync/socketTransport.test.js.map +1 -1
- package/dist/sync/transport.d.ts +9 -0
- package/dist/sync/transport.d.ts.map +1 -1
- package/dist/sync/transport.js +13 -0
- package/dist/sync/transport.js.map +1 -1
- package/dist/testing/fakeTransport.d.ts +5 -1
- package/dist/testing/fakeTransport.d.ts.map +1 -1
- package/dist/testing/fakeTransport.js +26 -0
- package/dist/testing/fakeTransport.js.map +1 -1
- package/dist/testing/fakeTransport.test.js +15 -0
- package/dist/testing/fakeTransport.test.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +93 -8
- package/src/api/apiError.ts +47 -0
- package/src/api/apiFetch.ts +245 -0
- package/src/api/client.test.ts +711 -0
- package/src/api/client.ts +367 -0
- package/src/app/app.ts +30 -0
- package/src/app/devConsoleLogger.test.ts +246 -0
- package/src/app/devConsoleLogger.ts +173 -0
- package/src/app/mcpTools.ts +101 -0
- package/src/app/permissions.test.ts +44 -0
- package/src/app/permissions.ts +58 -0
- package/src/app/upgradeCheck.ts +177 -0
- package/src/auth/SessionProvider.test.tsx +286 -0
- package/src/auth/SessionProvider.tsx +87 -0
- package/src/auth/TerrenoAccountSecurityScreen.tsx +56 -0
- package/src/auth/TerrenoLoginScreen.tsx +131 -0
- package/src/auth/auth.ts +117 -0
- package/src/auth/betterAuthAdapter.ts +1 -1
- package/src/auth/betterAuthClient.ts +997 -0
- package/src/auth/betterAuthClient.types.test.ts +197 -0
- package/src/auth/betterAuthClientRegistry.test.ts +114 -0
- package/src/auth/betterAuthClientRegistry.ts +99 -0
- package/src/auth/betterAuthTypes.ts +189 -0
- package/src/auth/jwtAuthAdapter.test.ts +754 -0
- package/src/auth/jwtAuthAdapter.ts +420 -0
- package/src/auth/loginErrors.test.ts +97 -0
- package/src/auth/loginErrors.ts +249 -0
- package/src/auth/ownEntry.test.ts +22 -0
- package/src/auth/ownEntry.ts +15 -0
- package/src/auth/platform.ts +4 -0
- package/src/auth/rememberedAccounts.test.ts +844 -0
- package/src/auth/rememberedAccounts.ts +568 -0
- package/src/auth/session.test.ts +976 -0
- package/src/auth/session.ts +509 -0
- package/src/auth/tokenExpiry.ts +185 -0
- package/src/auth/types.ts +1 -1
- package/src/auth/useAccountSecurity.ts +678 -0
- package/src/auth/useAccountSecurity.types.test.ts +28 -0
- package/src/auth/useAuthMethods.test.ts +181 -0
- package/src/auth/useAuthMethods.ts +137 -0
- package/src/auth/useJwtAuth.test.tsx +202 -0
- package/src/auth/useJwtAuth.ts +102 -0
- package/src/auth/useLoginController.ts +1038 -0
- package/src/auth/useLoginController.types.test.ts +26 -0
- package/src/buildNumber.test.ts +139 -0
- package/src/buildNumber.ts +75 -0
- package/src/client.socketEvents.test.ts +77 -0
- package/src/client.test.ts +109 -1
- package/src/client.ts +104 -19
- package/src/codegen/cli.test.ts +66 -0
- package/src/codegen/cli.ts +23 -12
- package/src/codegen/discoverCollections.ts +4 -0
- package/src/codegen/discoverOperations.ts +172 -0
- package/src/codegen/emitApi.test.tsx +445 -0
- package/src/codegen/emitApi.ts +396 -0
- package/src/codegen/emitSdk.ts +2 -2
- package/src/codegen/fixtures/openapi.api.json +840 -0
- package/src/codegen/generate.test.ts +54 -1
- package/src/codegen/generate.ts +20 -1
- package/src/codegen/hookNames.ts +35 -0
- package/src/codegen/safeIdentifiers.test.ts +20 -0
- package/src/codegen/safeIdentifiers.ts +7 -2
- package/src/codegen/types.ts +45 -1
- package/src/config/baseUrl.test.ts +53 -0
- package/src/config/baseUrl.ts +68 -0
- package/src/config/resolveBaseUrls.test.ts +308 -0
- package/src/config/resolveBaseUrls.ts +118 -0
- package/src/crypto/keyProviders.test.ts +23 -0
- package/src/crypto/keyProviders.ts +15 -4
- package/src/crypto/types.ts +5 -0
- package/src/flags/flagTestServer.ts +77 -0
- package/src/flags/useFeatureFlags.test.tsx +146 -0
- package/src/flags/useFeatureFlags.ts +130 -0
- package/src/flags/useTerrenoFeatureFlags.test.tsx +329 -0
- package/src/flags/useTerrenoFeatureFlags.ts +188 -0
- package/src/index.ts +4 -1
- package/src/isolated/TerrenoAccountSecurityScreen.isolated.tsx +123 -0
- package/src/isolated/TerrenoLoginScreen.isolated.tsx +256 -0
- package/src/isolated/betterAuthClient.isolated.ts +2198 -0
- package/src/isolated/betterAuthClient.native.isolated.ts +173 -0
- package/src/isolated/mcpTools.isolated.ts +259 -0
- package/src/isolated/rememberedAccounts.native.isolated.ts +63 -0
- package/src/isolated/sessionLogout.isolated.ts +152 -0
- package/src/isolated/tokenExpiry.isolated.ts +271 -0
- package/src/isolated/upgradeCheck.isolated.tsx +321 -0
- package/src/isolated/useAccountSecurity.isolated.ts +1089 -0
- package/src/isolated/useAccountSecurity.native.isolated.ts +61 -0
- package/src/isolated/useLoginController.isolated.ts +1384 -0
- package/src/mutations/entityIds.test.ts +55 -0
- package/src/mutations/entityIds.ts +50 -0
- package/src/persisters/defaultPersisterFactory.native.ts +7 -1
- package/src/persisters/encryptedIndexedDbPersister.ts +3 -0
- package/src/persisters/types.ts +6 -0
- package/src/query/queryWindows.ts +2 -2
- package/src/react/apiHooks.test.tsx +473 -0
- package/src/react/apiHooks.tsx +336 -0
- package/src/react/index.ts +2 -0
- package/src/react/provider.tsx +3 -0
- package/src/react/useSocketEvent.test.tsx +96 -0
- package/src/react/useSocketEvent.ts +59 -0
- package/src/sync/replayCoordinator.ts +5 -4
- package/src/sync/socketTransport.test.ts +49 -0
- package/src/sync/socketTransport.ts +15 -0
- package/src/sync/transport.ts +25 -0
- package/src/testing/fakeTransport.test.ts +18 -0
- package/src/testing/fakeTransport.ts +36 -5
- package/src/types.ts +9 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {afterEach, describe, expect, it, spyOn} from "bun:test";
|
|
2
|
+
import {act, renderHook, waitFor} from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import {type AuthMethodsClient, type BetterAuthMethods, useAuthMethods} from "./useAuthMethods";
|
|
5
|
+
|
|
6
|
+
const METHODS: BetterAuthMethods = {
|
|
7
|
+
accountLinking: {mode: "verified-email"},
|
|
8
|
+
emailPassword: true,
|
|
9
|
+
multiSession: false,
|
|
10
|
+
passkey: false,
|
|
11
|
+
providers: ["github", "mock-oidc"],
|
|
12
|
+
signUp: true,
|
|
13
|
+
twoFactor: false,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
interface FakeClient extends AuthMethodsClient {
|
|
17
|
+
calls: Array<{options?: {method?: string}; path: string}>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fakeClient = (respond: () => Promise<{data: unknown; error: unknown}>): FakeClient => {
|
|
21
|
+
const calls: FakeClient["calls"] = [];
|
|
22
|
+
return {
|
|
23
|
+
$fetch: (path, options) => {
|
|
24
|
+
calls.push({options, path});
|
|
25
|
+
return respond();
|
|
26
|
+
},
|
|
27
|
+
calls,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe("useAuthMethods", () => {
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
// Restores console.warn after a test spies on it.
|
|
34
|
+
(console.warn as unknown as {mockRestore?: () => void}).mockRestore?.();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("loads the server's sign-in methods through the client's $fetch", async () => {
|
|
38
|
+
const client = fakeClient(async () => ({data: METHODS, error: null}));
|
|
39
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
40
|
+
|
|
41
|
+
expect(result.current.isLoading).toBe(true);
|
|
42
|
+
expect(result.current.methods).toBeUndefined();
|
|
43
|
+
|
|
44
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
45
|
+
expect(result.current.methods).toEqual(METHODS);
|
|
46
|
+
expect(result.current.error).toBeUndefined();
|
|
47
|
+
expect(client.calls).toEqual([{options: {method: "GET"}, path: "/terreno/methods"}]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("reports the error message when the server answers with an error", async () => {
|
|
51
|
+
const client = fakeClient(async () => ({
|
|
52
|
+
data: null,
|
|
53
|
+
error: {message: "Not found", status: 404, statusText: "Not Found"},
|
|
54
|
+
}));
|
|
55
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
56
|
+
|
|
57
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
58
|
+
expect(result.current.methods).toBeUndefined();
|
|
59
|
+
expect(result.current.error).toBe("Not found");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("falls back to the status text when the error has no message", async () => {
|
|
63
|
+
const client = fakeClient(async () => ({
|
|
64
|
+
data: null,
|
|
65
|
+
error: {status: 500, statusText: "Internal Server Error"},
|
|
66
|
+
}));
|
|
67
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
68
|
+
|
|
69
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
70
|
+
expect(result.current.error).toBe("Internal Server Error");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("reports a generic error for an error without a message or status text", async () => {
|
|
74
|
+
const client = fakeClient(async () => ({data: null, error: {}}));
|
|
75
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
76
|
+
|
|
77
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
78
|
+
expect(result.current.error).toBe("Could not load sign-in methods");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("reports a thrown network error", async () => {
|
|
82
|
+
const client = fakeClient(async () => {
|
|
83
|
+
throw new Error("Network request failed");
|
|
84
|
+
});
|
|
85
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
86
|
+
|
|
87
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
88
|
+
expect(result.current.methods).toBeUndefined();
|
|
89
|
+
expect(result.current.error).toBe("Network request failed");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("reports a generic error when something other than an Error is thrown", async () => {
|
|
93
|
+
const client = fakeClient(async () => {
|
|
94
|
+
throw "offline";
|
|
95
|
+
});
|
|
96
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
97
|
+
|
|
98
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
99
|
+
expect(result.current.error).toBe("Could not load sign-in methods");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("ignores a response that arrives after unmount", async () => {
|
|
103
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
104
|
+
let resolve: (value: {data: unknown; error: unknown}) => void = () => {};
|
|
105
|
+
const client = fakeClient(
|
|
106
|
+
() =>
|
|
107
|
+
new Promise((done) => {
|
|
108
|
+
resolve = done;
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
const {unmount} = renderHook(() => useAuthMethods(client));
|
|
112
|
+
unmount();
|
|
113
|
+
resolve({data: null, error: {message: "Too late"}});
|
|
114
|
+
await new Promise((done) => setTimeout(done, 0));
|
|
115
|
+
expect(warn).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("refetches when the client changes", async () => {
|
|
119
|
+
const first = fakeClient(async () => ({data: METHODS, error: null}));
|
|
120
|
+
const secondMethods = {...METHODS, providers: ["google"]};
|
|
121
|
+
const second = fakeClient(async () => ({data: secondMethods, error: null}));
|
|
122
|
+
const {result, rerender} = renderHook(
|
|
123
|
+
({client}: {client: AuthMethodsClient}) => useAuthMethods(client),
|
|
124
|
+
{initialProps: {client: first as AuthMethodsClient}}
|
|
125
|
+
);
|
|
126
|
+
await waitFor(() => expect(result.current.methods).toEqual(METHODS));
|
|
127
|
+
|
|
128
|
+
rerender({client: second});
|
|
129
|
+
await waitFor(() => expect(result.current.methods).toEqual(secondMethods));
|
|
130
|
+
expect(first.calls).toHaveLength(1);
|
|
131
|
+
expect(second.calls).toHaveLength(1);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("requests the methods again on refetch after an error, showing a loading state", async () => {
|
|
135
|
+
spyOn(console, "warn").mockImplementation(() => {});
|
|
136
|
+
let release: (value: {data: unknown; error: unknown}) => void = () => {};
|
|
137
|
+
let answer: () => Promise<{data: unknown; error: unknown}> = async () => ({
|
|
138
|
+
data: null,
|
|
139
|
+
error: {message: "Offline"},
|
|
140
|
+
});
|
|
141
|
+
const client = fakeClient(() => answer());
|
|
142
|
+
const {result} = renderHook(() => useAuthMethods(client));
|
|
143
|
+
await waitFor(() => expect(result.current.error).toBe("Offline"));
|
|
144
|
+
|
|
145
|
+
// The retry is held, so the state in between can be seen.
|
|
146
|
+
answer = (): Promise<{data: unknown; error: unknown}> =>
|
|
147
|
+
new Promise((done) => {
|
|
148
|
+
release = done;
|
|
149
|
+
});
|
|
150
|
+
act(() => {
|
|
151
|
+
result.current.refetch();
|
|
152
|
+
});
|
|
153
|
+
await waitFor(() => expect(result.current.isLoading).toBe(true));
|
|
154
|
+
expect(result.current.error).toBeUndefined();
|
|
155
|
+
expect(result.current.methods).toBeUndefined();
|
|
156
|
+
|
|
157
|
+
await act(async () => {
|
|
158
|
+
release({data: METHODS, error: null});
|
|
159
|
+
});
|
|
160
|
+
await waitFor(() => expect(result.current.methods).toEqual(METHODS));
|
|
161
|
+
expect(result.current.isLoading).toBe(false);
|
|
162
|
+
expect(client.calls).toHaveLength(2);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("makes no request when skipped", async () => {
|
|
166
|
+
const client = fakeClient(async () => ({data: METHODS, error: null}));
|
|
167
|
+
const {result} = renderHook(() => useAuthMethods(client, {skip: true}));
|
|
168
|
+
|
|
169
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
170
|
+
expect(result.current.methods).toBeUndefined();
|
|
171
|
+
expect(client.calls).toHaveLength(0);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("fetches once per client across re-renders", async () => {
|
|
175
|
+
const client = fakeClient(async () => ({data: METHODS, error: null}));
|
|
176
|
+
const {result, rerender} = renderHook(() => useAuthMethods(client));
|
|
177
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
178
|
+
rerender({});
|
|
179
|
+
expect(client.calls).toHaveLength(1);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads which sign-in methods a Better Auth server has enabled, so a login screen renders only
|
|
3
|
+
* those. The server side is `GET {basePath}/terreno/methods` from `@terreno/api`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {useCallback, useEffect, useState} from "react";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* How a sign-in with a new method relates to an existing account with the same email.
|
|
10
|
+
* - `verified-email`: linked when the provider reports a verified email (Better Auth default).
|
|
11
|
+
* - `explicit`: no implicit linking at sign-in; a signed-in user links the method themselves.
|
|
12
|
+
* - `never`: account linking is off.
|
|
13
|
+
*/
|
|
14
|
+
export type BetterAuthAccountLinkingMode = "verified-email" | "explicit" | "never";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The body of `GET {basePath}/terreno/methods`.
|
|
18
|
+
*/
|
|
19
|
+
export interface BetterAuthMethods {
|
|
20
|
+
accountLinking: {mode: BetterAuthAccountLinkingMode};
|
|
21
|
+
emailPassword: boolean;
|
|
22
|
+
multiSession: boolean;
|
|
23
|
+
passkey: boolean;
|
|
24
|
+
/** Sorted OAuth provider ids, such as `["github", "google", "mock-oidc"]`. */
|
|
25
|
+
providers: string[];
|
|
26
|
+
signUp: boolean;
|
|
27
|
+
twoFactor: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The part of a Better Auth client `useAuthMethods` calls. The client from
|
|
32
|
+
* `createBetterAuthClient` satisfies it, so the request carries the client's bearer token or
|
|
33
|
+
* cookies and resolves against its base URL and base path.
|
|
34
|
+
*/
|
|
35
|
+
export interface AuthMethodsClient {
|
|
36
|
+
$fetch: (path: string, options?: {method?: "GET"}) => Promise<{data: unknown; error: unknown}>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface UseAuthMethodsResult {
|
|
40
|
+
/** Set once the server answers; `undefined` while loading and after an error. */
|
|
41
|
+
methods: BetterAuthMethods | undefined;
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
/** A readable message when the request failed. */
|
|
44
|
+
error: string | undefined;
|
|
45
|
+
/** Requests the methods again, for a Try again button after an error. */
|
|
46
|
+
refetch: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface UseAuthMethodsOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Skip the request, for a caller that already has the methods. The result then stays
|
|
52
|
+
* `{methods: undefined, isLoading: false}`.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
skip?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type AuthMethodsState = Omit<UseAuthMethodsResult, "refetch">;
|
|
59
|
+
|
|
60
|
+
const METHODS_PATH = "/terreno/methods";
|
|
61
|
+
const FALLBACK_ERROR = "Could not load sign-in methods";
|
|
62
|
+
|
|
63
|
+
const errorMessage = (error: unknown): string => {
|
|
64
|
+
if (error instanceof Error && error.message) {
|
|
65
|
+
return error.message;
|
|
66
|
+
}
|
|
67
|
+
const {message, statusText} = (error ?? {}) as {message?: unknown; statusText?: unknown};
|
|
68
|
+
if (typeof message === "string" && message) {
|
|
69
|
+
return message;
|
|
70
|
+
}
|
|
71
|
+
if (typeof statusText === "string" && statusText) {
|
|
72
|
+
return statusText;
|
|
73
|
+
}
|
|
74
|
+
return FALLBACK_ERROR;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Loads the server's enabled sign-in methods once per client.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* const {methods, isLoading} = useAuthMethods(authClient);
|
|
83
|
+
* const providers = isLoading ? [] : (methods?.providers ?? []);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export const useAuthMethods = (
|
|
87
|
+
authClient: AuthMethodsClient,
|
|
88
|
+
{skip = false}: UseAuthMethodsOptions = {}
|
|
89
|
+
): UseAuthMethodsResult => {
|
|
90
|
+
const [result, setResult] = useState<AuthMethodsState>({
|
|
91
|
+
error: undefined,
|
|
92
|
+
isLoading: !skip,
|
|
93
|
+
methods: undefined,
|
|
94
|
+
});
|
|
95
|
+
const [attempt, setAttempt] = useState(0);
|
|
96
|
+
|
|
97
|
+
const refetch = useCallback((): void => {
|
|
98
|
+
setAttempt((count) => count + 1);
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
// Fetch the methods when the client changes or on refetch; a response after unmount is dropped.
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (skip) {
|
|
104
|
+
setResult({error: undefined, isLoading: false, methods: undefined});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
let isCancelled = false;
|
|
108
|
+
// Every attempt after the first starts from a loading state, so a Try again shows progress.
|
|
109
|
+
if (attempt > 0) {
|
|
110
|
+
setResult({error: undefined, isLoading: true, methods: undefined});
|
|
111
|
+
}
|
|
112
|
+
const load = async (): Promise<void> => {
|
|
113
|
+
let next: AuthMethodsState;
|
|
114
|
+
try {
|
|
115
|
+
const {data, error} = await authClient.$fetch(METHODS_PATH, {method: "GET"});
|
|
116
|
+
next = error
|
|
117
|
+
? {error: errorMessage(error), isLoading: false, methods: undefined}
|
|
118
|
+
: {error: undefined, isLoading: false, methods: data as BetterAuthMethods};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
next = {error: errorMessage(error), isLoading: false, methods: undefined};
|
|
121
|
+
}
|
|
122
|
+
if (isCancelled) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (next.error) {
|
|
126
|
+
console.warn(`[terreno/syncdb] ${next.error} from ${METHODS_PATH}`);
|
|
127
|
+
}
|
|
128
|
+
setResult(next);
|
|
129
|
+
};
|
|
130
|
+
void load();
|
|
131
|
+
return (): void => {
|
|
132
|
+
isCancelled = true;
|
|
133
|
+
};
|
|
134
|
+
}, [attempt, authClient, skip]);
|
|
135
|
+
|
|
136
|
+
return {...result, refetch};
|
|
137
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from the pre-58 rtk package's `authSlice.test.ts` matcher tests: login / signup / Google
|
|
3
|
+
* login set `isAuthenticating` while pending, record the API error on rejection, clear a stale
|
|
4
|
+
* error on the next attempt, and feed the session that `useSession()` reads.
|
|
5
|
+
*/
|
|
6
|
+
import {afterEach, beforeEach, describe, expect, it, spyOn} from "bun:test";
|
|
7
|
+
import {act, renderHook, waitFor} from "@testing-library/react-native";
|
|
8
|
+
import {DateTime} from "luxon";
|
|
9
|
+
import type React from "react";
|
|
10
|
+
|
|
11
|
+
import {type JwtAuthAdapter, jwtAuthAdapter} from "./jwtAuthAdapter";
|
|
12
|
+
import {SessionProvider, useSession} from "./SessionProvider";
|
|
13
|
+
import type {JwtTokenStorage} from "./tokenExpiry";
|
|
14
|
+
import {useJwtAuth} from "./useJwtAuth";
|
|
15
|
+
|
|
16
|
+
const base64Url = (value: string): string => Buffer.from(value).toString("base64url");
|
|
17
|
+
const tokenFor = (id: string): string =>
|
|
18
|
+
`${base64Url("{}")}.${base64Url(JSON.stringify({exp: Math.floor(DateTime.now().toSeconds()) + 900, id}))}.sig`;
|
|
19
|
+
|
|
20
|
+
const json = (status: number, body: unknown): Response =>
|
|
21
|
+
new Response(JSON.stringify(body), {headers: {"Content-Type": "application/json"}, status});
|
|
22
|
+
|
|
23
|
+
interface Harness {
|
|
24
|
+
adapter: JwtAuthAdapter;
|
|
25
|
+
items: Map<string, string>;
|
|
26
|
+
paths: string[];
|
|
27
|
+
/** Resolve the next held response. */
|
|
28
|
+
release: () => void;
|
|
29
|
+
hold: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A minimal `/auth/*` server: `pw` logs in, anything else is a 401 with a message. */
|
|
33
|
+
const createHarness = (): Harness => {
|
|
34
|
+
const items = new Map<string, string>();
|
|
35
|
+
const storage: JwtTokenStorage = {
|
|
36
|
+
getItem: async (key) => items.get(key) ?? null,
|
|
37
|
+
removeItem: async (key) => {
|
|
38
|
+
items.delete(key);
|
|
39
|
+
},
|
|
40
|
+
setItem: async (key, value) => {
|
|
41
|
+
items.set(key, value);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const paths: string[] = [];
|
|
45
|
+
let gate: Promise<void> | undefined;
|
|
46
|
+
let releaseGate: (() => void) | undefined;
|
|
47
|
+
const fetchImpl = async (input: string, init?: RequestInit): Promise<Response> => {
|
|
48
|
+
const path = new URL(input).pathname;
|
|
49
|
+
paths.push(path);
|
|
50
|
+
// Resolves immediately unless a test is holding responses.
|
|
51
|
+
await gate;
|
|
52
|
+
const body = JSON.parse(String(init?.body ?? "{}"));
|
|
53
|
+
const ok = body.password === "pw" || body.idToken === "google-id-token";
|
|
54
|
+
if (!ok) {
|
|
55
|
+
return json(401, {message: "Password or username is incorrect"});
|
|
56
|
+
}
|
|
57
|
+
const userId = path === "/auth/signup" ? "user-new" : "user-ada";
|
|
58
|
+
return json(200, {data: {refreshToken: tokenFor(userId), token: tokenFor(userId), userId}});
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
adapter: jwtAuthAdapter({baseUrl: "http://api.test", fetchImpl, storage}),
|
|
62
|
+
hold: (): void => {
|
|
63
|
+
gate = new Promise((resolve) => {
|
|
64
|
+
releaseGate = resolve;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
items,
|
|
68
|
+
paths,
|
|
69
|
+
release: (): void => {
|
|
70
|
+
gate = undefined;
|
|
71
|
+
releaseGate?.();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const renderAuth = (harness: Harness) => {
|
|
77
|
+
const wrapper = ({children}: {children: React.ReactNode}): React.ReactElement => (
|
|
78
|
+
<SessionProvider pollIntervalMs={0} source={harness.adapter}>
|
|
79
|
+
{children}
|
|
80
|
+
</SessionProvider>
|
|
81
|
+
);
|
|
82
|
+
return renderHook(() => ({auth: useJwtAuth({adapter: harness.adapter}), session: useSession()}), {
|
|
83
|
+
wrapper,
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe("useJwtAuth", () => {
|
|
88
|
+
let harness: Harness;
|
|
89
|
+
let debugSpy: ReturnType<typeof spyOn>;
|
|
90
|
+
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
harness = createHarness();
|
|
93
|
+
debugSpy = spyOn(console, "debug").mockImplementation(() => {});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
afterEach(() => {
|
|
97
|
+
debugSpy.mockRestore();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("starts idle and signed out", async () => {
|
|
101
|
+
const {result} = renderAuth(harness);
|
|
102
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
103
|
+
expect(result.current.auth.isAuthenticating).toBe(false);
|
|
104
|
+
expect(result.current.auth.error).toBeNull();
|
|
105
|
+
expect(result.current.session.isAuthenticated).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("sets isAuthenticating while a login is pending, then signs the session in", async () => {
|
|
109
|
+
const {result} = renderAuth(harness);
|
|
110
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
111
|
+
harness.hold();
|
|
112
|
+
|
|
113
|
+
let pending: Promise<unknown> = Promise.resolve();
|
|
114
|
+
act(() => {
|
|
115
|
+
pending = result.current.auth.login({email: "ada@example.com", password: "pw"});
|
|
116
|
+
});
|
|
117
|
+
await waitFor(() => expect(result.current.auth.isAuthenticating).toBe(true));
|
|
118
|
+
|
|
119
|
+
await act(async () => {
|
|
120
|
+
harness.release();
|
|
121
|
+
await pending;
|
|
122
|
+
});
|
|
123
|
+
expect(result.current.auth.isAuthenticating).toBe(false);
|
|
124
|
+
expect(result.current.session).toMatchObject({isAuthenticated: true, userId: "user-ada"});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("records the API error on a rejected login and clears it on the next attempt", async () => {
|
|
128
|
+
const {result} = renderAuth(harness);
|
|
129
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
130
|
+
|
|
131
|
+
await act(async () => {
|
|
132
|
+
await expect(
|
|
133
|
+
result.current.auth.login({email: "ada@example.com", password: "wrong"})
|
|
134
|
+
).rejects.toThrow("Password or username is incorrect");
|
|
135
|
+
});
|
|
136
|
+
expect(result.current.auth.error).toBe("Password or username is incorrect");
|
|
137
|
+
expect(result.current.auth.isAuthenticating).toBe(false);
|
|
138
|
+
|
|
139
|
+
harness.hold();
|
|
140
|
+
let pending: Promise<unknown> = Promise.resolve();
|
|
141
|
+
act(() => {
|
|
142
|
+
pending = result.current.auth.googleLogin({idToken: "google-id-token"});
|
|
143
|
+
});
|
|
144
|
+
await waitFor(() => expect(result.current.auth.error).toBeNull());
|
|
145
|
+
await act(async () => {
|
|
146
|
+
harness.release();
|
|
147
|
+
await pending;
|
|
148
|
+
});
|
|
149
|
+
expect(harness.paths.at(-1)).toBe("/auth/google");
|
|
150
|
+
expect(result.current.session.userId).toBe("user-ada");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("signs up and signs the session in", async () => {
|
|
154
|
+
const {result} = renderAuth(harness);
|
|
155
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
156
|
+
await act(async () => {
|
|
157
|
+
await result.current.auth.signup({email: "new@example.com", password: "pw"});
|
|
158
|
+
});
|
|
159
|
+
expect(result.current.session.userId).toBe("user-new");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("resets a password without changing the session", async () => {
|
|
163
|
+
const {result} = renderAuth(harness);
|
|
164
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
165
|
+
await act(async () => {
|
|
166
|
+
await result.current.auth.resetPassword({password: "pw", token: "reset-token"});
|
|
167
|
+
});
|
|
168
|
+
expect(harness.paths).toEqual(["/resetPassword"]);
|
|
169
|
+
expect(result.current.session.isAuthenticated).toBe(false);
|
|
170
|
+
expect(harness.items.size).toBe(0);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("logs out through the SessionProvider and clears the tokens", async () => {
|
|
174
|
+
const {result} = renderAuth(harness);
|
|
175
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
176
|
+
await act(async () => {
|
|
177
|
+
await result.current.auth.login({email: "ada@example.com", password: "pw"});
|
|
178
|
+
});
|
|
179
|
+
expect(harness.items.size).toBe(2);
|
|
180
|
+
|
|
181
|
+
await act(async () => {
|
|
182
|
+
await result.current.auth.logout();
|
|
183
|
+
});
|
|
184
|
+
expect(result.current.session.isAuthenticated).toBe(false);
|
|
185
|
+
expect(harness.items.size).toBe(0);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("records non-Error rejections as strings", async () => {
|
|
189
|
+
const adapter = {
|
|
190
|
+
...harness.adapter,
|
|
191
|
+
login: async (): Promise<never> => {
|
|
192
|
+
throw "offline";
|
|
193
|
+
},
|
|
194
|
+
} as JwtAuthAdapter;
|
|
195
|
+
const {result} = renderAuth({...harness, adapter});
|
|
196
|
+
await waitFor(() => expect(result.current.session.isLoading).toBe(false));
|
|
197
|
+
await act(async () => {
|
|
198
|
+
await expect(result.current.auth.login({email: "a", password: "b"})).rejects.toBe("offline");
|
|
199
|
+
});
|
|
200
|
+
expect(result.current.auth.error).toBe("offline");
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React actions for legacy JWT auth: `login`, `signup`, `googleLogin`, `resetPassword`, and
|
|
3
|
+
* `logout`, with the `isAuthenticating` / `error` state rtk's auth slice tracked. Session
|
|
4
|
+
* state itself comes from `useSession()`: the adapter pushes every sign-in and sign-out to the
|
|
5
|
+
* `SessionProvider` it is the `source` of.
|
|
6
|
+
*/
|
|
7
|
+
import {useCallback, useMemo, useState} from "react";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
EmailLoginRequest,
|
|
11
|
+
EmailSignupRequest,
|
|
12
|
+
GoogleLoginRequest,
|
|
13
|
+
JwtAuthAdapter,
|
|
14
|
+
JwtAuthResponse,
|
|
15
|
+
ResetPasswordRequest,
|
|
16
|
+
} from "./jwtAuthAdapter";
|
|
17
|
+
import {useSessionStore} from "./SessionProvider";
|
|
18
|
+
|
|
19
|
+
export interface UseJwtAuthResult {
|
|
20
|
+
/** Email (or username) + password login. Rejects with the API error. */
|
|
21
|
+
login: (body: EmailLoginRequest) => Promise<JwtAuthResponse>;
|
|
22
|
+
/** Create an account and sign in. Rejects with the API error. */
|
|
23
|
+
signup: (body: EmailSignupRequest) => Promise<JwtAuthResponse>;
|
|
24
|
+
/** Sign in with a Google ID token. Rejects with the API error. */
|
|
25
|
+
googleLogin: (body: GoogleLoginRequest) => Promise<JwtAuthResponse>;
|
|
26
|
+
/** Reset a password with an emailed token. Does not sign in. Rejects with the API error. */
|
|
27
|
+
resetPassword: (body: ResetPasswordRequest) => Promise<JwtAuthResponse>;
|
|
28
|
+
/** Clear tokens and run the `SessionProvider` logout (syncdb sign-out, `onLogout`). */
|
|
29
|
+
logout: () => Promise<void>;
|
|
30
|
+
/** True while a login, signup, Google login, or password reset request is in flight. */
|
|
31
|
+
isAuthenticating: boolean;
|
|
32
|
+
/** Message from the last failed request; cleared when the next one starts. */
|
|
33
|
+
error: string | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const messageOf = (error: unknown): string => {
|
|
37
|
+
if (error instanceof Error && error.message) {
|
|
38
|
+
return error.message;
|
|
39
|
+
}
|
|
40
|
+
return String(error);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* JWT auth actions for screens. Must render inside the `SessionProvider` whose `source` is
|
|
45
|
+
* `adapter`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* const {login, isAuthenticating, error} = useJwtAuth({adapter: jwtAuth});
|
|
50
|
+
* await login({email, password});
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export const useJwtAuth = ({adapter}: {adapter: JwtAuthAdapter}): UseJwtAuthResult => {
|
|
54
|
+
const store = useSessionStore();
|
|
55
|
+
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
|
56
|
+
const [error, setError] = useState<string | null>(null);
|
|
57
|
+
|
|
58
|
+
const track = useCallback(async <TResult>(action: () => Promise<TResult>): Promise<TResult> => {
|
|
59
|
+
setError(null);
|
|
60
|
+
setIsAuthenticating(true);
|
|
61
|
+
try {
|
|
62
|
+
return await action();
|
|
63
|
+
} catch (caught) {
|
|
64
|
+
setError(messageOf(caught));
|
|
65
|
+
throw caught;
|
|
66
|
+
} finally {
|
|
67
|
+
setIsAuthenticating(false);
|
|
68
|
+
}
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
const login = useCallback(
|
|
72
|
+
(body: EmailLoginRequest): Promise<JwtAuthResponse> => track(() => adapter.login(body)),
|
|
73
|
+
[adapter, track]
|
|
74
|
+
);
|
|
75
|
+
const signup = useCallback(
|
|
76
|
+
(body: EmailSignupRequest): Promise<JwtAuthResponse> => track(() => adapter.signup(body)),
|
|
77
|
+
[adapter, track]
|
|
78
|
+
);
|
|
79
|
+
const googleLogin = useCallback(
|
|
80
|
+
(body: GoogleLoginRequest): Promise<JwtAuthResponse> => track(() => adapter.googleLogin(body)),
|
|
81
|
+
[adapter, track]
|
|
82
|
+
);
|
|
83
|
+
const resetPassword = useCallback(
|
|
84
|
+
(body: ResetPasswordRequest): Promise<JwtAuthResponse> =>
|
|
85
|
+
track(() => adapter.resetPassword(body)),
|
|
86
|
+
[adapter, track]
|
|
87
|
+
);
|
|
88
|
+
const logout = useCallback((): Promise<void> => store.logout(), [store]);
|
|
89
|
+
|
|
90
|
+
return useMemo(
|
|
91
|
+
(): UseJwtAuthResult => ({
|
|
92
|
+
error,
|
|
93
|
+
googleLogin,
|
|
94
|
+
isAuthenticating,
|
|
95
|
+
login,
|
|
96
|
+
logout,
|
|
97
|
+
resetPassword,
|
|
98
|
+
signup,
|
|
99
|
+
}),
|
|
100
|
+
[error, googleLogin, isAuthenticating, login, logout, resetPassword, signup]
|
|
101
|
+
);
|
|
102
|
+
};
|