@oxyhq/services 5.16.44 → 5.17.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/README.md +29 -10
- package/lib/commonjs/core/OxyServices.js +1 -1
- package/lib/commonjs/core/index.js +20 -15
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.auth.js +36 -53
- package/lib/commonjs/core/mixins/OxyServices.auth.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.user.js +10 -17
- package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -1
- package/lib/commonjs/core/services/TokenService.js +27 -13
- package/lib/commonjs/core/services/TokenService.js.map +1 -1
- package/lib/commonjs/crypto/index.js +0 -16
- package/lib/commonjs/crypto/index.js.map +1 -1
- package/lib/commonjs/crypto/keyManager.js +21 -22
- package/lib/commonjs/crypto/keyManager.js.map +1 -1
- package/lib/commonjs/crypto/polyfill.js +1 -10
- package/lib/commonjs/crypto/polyfill.js.map +1 -1
- package/lib/commonjs/crypto/signatureService.js +18 -32
- package/lib/commonjs/crypto/signatureService.js.map +1 -1
- package/lib/commonjs/index.js +13 -134
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/interfaces.js +0 -7
- package/lib/commonjs/models/interfaces.js.map +1 -1
- package/lib/commonjs/node/index.js +1 -10
- package/lib/commonjs/node/index.js.map +1 -1
- package/lib/commonjs/ui/components/BottomSheetRouter.js +1 -9
- package/lib/commonjs/ui/components/BottomSheetRouter.js.map +1 -1
- package/lib/commonjs/ui/components/OxyProvider.js +9 -20
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +779 -450
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js +551 -0
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -0
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js +73 -0
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js.map +1 -0
- package/lib/commonjs/ui/context/hooks/useStorage.js +79 -0
- package/lib/commonjs/ui/context/hooks/useStorage.js.map +1 -0
- package/lib/commonjs/ui/hooks/index.js +0 -20
- package/lib/commonjs/ui/hooks/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/index.js +0 -12
- package/lib/commonjs/ui/hooks/mutations/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +23 -74
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/index.js +0 -12
- package/lib/commonjs/ui/hooks/queries/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/queryKeys.js +1 -3
- package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +28 -64
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +6 -4
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/useDeviceManagement.js +73 -0
- package/lib/commonjs/ui/hooks/useDeviceManagement.js.map +1 -0
- package/lib/commonjs/ui/hooks/useProfileEditing.js +5 -3
- package/lib/commonjs/ui/hooks/useProfileEditing.js.map +1 -1
- package/lib/commonjs/ui/hooks/useSessionManagement.js +284 -0
- package/lib/commonjs/ui/hooks/useSessionManagement.js.map +1 -0
- package/lib/commonjs/ui/index.js +2 -10
- package/lib/commonjs/ui/index.js.map +1 -1
- package/lib/commonjs/ui/navigation/routes.js +1 -5
- package/lib/commonjs/ui/navigation/routes.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +4 -9
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js +19 -37
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +5 -5
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/OxyAuthScreen.js +15 -2
- package/lib/commonjs/ui/screens/OxyAuthScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +97 -76
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ProfileScreen.js +6 -6
- package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/commonjs/ui/stores/authStore.js +6 -54
- package/lib/commonjs/ui/stores/authStore.js.map +1 -1
- package/lib/commonjs/ui/styles/spacing.js +2 -54
- package/lib/commonjs/ui/styles/spacing.js.map +1 -1
- package/lib/commonjs/ui/utils/avatarUtils.js +12 -9
- package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -1
- package/lib/commonjs/ui/utils/sessionHelpers.js +1 -7
- package/lib/commonjs/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/commonjs/utils/deviceManager.js +177 -0
- package/lib/commonjs/utils/deviceManager.js.map +1 -0
- package/lib/commonjs/utils/errorUtils.js +0 -13
- package/lib/commonjs/utils/errorUtils.js.map +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/sessionUtils.js +1 -8
- package/lib/commonjs/utils/sessionUtils.js.map +1 -1
- package/lib/commonjs/utils/validationUtils.js +1 -15
- package/lib/commonjs/utils/validationUtils.js.map +1 -1
- package/lib/module/core/OxyServices.js +1 -1
- package/lib/module/core/index.js +4 -6
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.auth.js +36 -53
- package/lib/module/core/mixins/OxyServices.auth.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.user.js +10 -17
- package/lib/module/core/mixins/OxyServices.user.js.map +1 -1
- package/lib/module/core/services/TokenService.js +27 -13
- package/lib/module/core/services/TokenService.js.map +1 -1
- package/lib/module/crypto/index.js +0 -3
- package/lib/module/crypto/index.js.map +1 -1
- package/lib/module/crypto/keyManager.js +21 -22
- package/lib/module/crypto/keyManager.js.map +1 -1
- package/lib/module/crypto/polyfill.js +1 -2
- package/lib/module/crypto/polyfill.js.map +1 -1
- package/lib/module/crypto/signatureService.js +18 -32
- package/lib/module/crypto/signatureService.js.map +1 -1
- package/lib/module/index.js +7 -19
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/interfaces.js +0 -7
- package/lib/module/models/interfaces.js.map +1 -1
- package/lib/module/node/index.js +0 -3
- package/lib/module/node/index.js.map +1 -1
- package/lib/module/ui/components/BottomSheetRouter.js +2 -6
- package/lib/module/ui/components/BottomSheetRouter.js.map +1 -1
- package/lib/module/ui/components/OxyProvider.js +9 -20
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +779 -450
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/hooks/useAuthOperations.js +545 -0
- package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -0
- package/lib/module/ui/context/hooks/useDeviceManagement.js +68 -0
- package/lib/module/ui/context/hooks/useDeviceManagement.js.map +1 -0
- package/lib/module/ui/context/hooks/useStorage.js +74 -0
- package/lib/module/ui/context/hooks/useStorage.js.map +1 -0
- package/lib/module/ui/hooks/index.js +0 -1
- package/lib/module/ui/hooks/index.js.map +1 -1
- package/lib/module/ui/hooks/mutations/index.js +1 -1
- package/lib/module/ui/hooks/mutations/index.js.map +1 -1
- package/lib/module/ui/hooks/mutations/useAccountMutations.js +21 -71
- package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/module/ui/hooks/queries/index.js +1 -1
- package/lib/module/ui/hooks/queries/index.js.map +1 -1
- package/lib/module/ui/hooks/queries/queryKeys.js +1 -3
- package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/module/ui/hooks/queries/useAccountQueries.js +27 -61
- package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/module/ui/hooks/queries/useServicesQueries.js +6 -4
- package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/module/ui/hooks/useDeviceManagement.js +68 -0
- package/lib/module/ui/hooks/useDeviceManagement.js.map +1 -0
- package/lib/module/ui/hooks/useProfileEditing.js +5 -3
- package/lib/module/ui/hooks/useProfileEditing.js.map +1 -1
- package/lib/module/ui/hooks/useSessionManagement.js +279 -0
- package/lib/module/ui/hooks/useSessionManagement.js.map +1 -0
- package/lib/module/ui/index.js +1 -2
- package/lib/module/ui/index.js.map +1 -1
- package/lib/module/ui/navigation/routes.js +1 -5
- package/lib/module/ui/navigation/routes.js.map +1 -1
- package/lib/module/ui/screens/AccountCenterScreen.js +4 -9
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSettingsScreen.js +19 -37
- package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +5 -5
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/OxyAuthScreen.js +15 -2
- package/lib/module/ui/screens/OxyAuthScreen.js.map +1 -1
- package/lib/module/ui/screens/PrivacySettingsScreen.js +98 -77
- package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/ProfileScreen.js +6 -6
- package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/module/ui/stores/authStore.js +6 -54
- package/lib/module/ui/stores/authStore.js.map +1 -1
- package/lib/module/ui/styles/spacing.js +2 -6
- package/lib/module/ui/styles/spacing.js.map +1 -1
- package/lib/module/ui/utils/avatarUtils.js +12 -9
- package/lib/module/ui/utils/avatarUtils.js.map +1 -1
- package/lib/module/ui/utils/sessionHelpers.js +1 -7
- package/lib/module/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/module/utils/deviceManager.js +171 -0
- package/lib/module/utils/deviceManager.js.map +1 -0
- package/lib/module/utils/errorUtils.js +0 -7
- package/lib/module/utils/errorUtils.js.map +1 -1
- package/lib/module/utils/index.js +1 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/sessionUtils.js +1 -8
- package/lib/module/utils/sessionUtils.js.map +1 -1
- package/lib/module/utils/validationUtils.js +0 -13
- package/lib/module/utils/validationUtils.js.map +1 -1
- package/lib/typescript/core/OxyServices.d.ts +1 -1
- package/lib/typescript/core/index.d.ts +3 -3
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts +21 -44
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.user.d.ts +1 -0
- package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
- package/lib/typescript/core/mixins/index.d.ts +8 -15
- package/lib/typescript/core/mixins/index.d.ts.map +1 -1
- package/lib/typescript/core/services/TokenService.d.ts.map +1 -1
- package/lib/typescript/crypto/index.d.ts +0 -1
- package/lib/typescript/crypto/index.d.ts.map +1 -1
- package/lib/typescript/crypto/keyManager.d.ts +2 -15
- package/lib/typescript/crypto/keyManager.d.ts.map +1 -1
- package/lib/typescript/crypto/polyfill.d.ts +1 -2
- package/lib/typescript/crypto/polyfill.d.ts.map +1 -1
- package/lib/typescript/crypto/signatureService.d.ts +0 -13
- package/lib/typescript/crypto/signatureService.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +7 -12
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/interfaces.d.ts +36 -5
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/models/session.d.ts +18 -3
- package/lib/typescript/models/session.d.ts.map +1 -1
- package/lib/typescript/node/index.d.ts +0 -1
- package/lib/typescript/node/index.d.ts.map +1 -1
- package/lib/typescript/ui/components/BottomSheetRouter.d.ts +0 -5
- package/lib/typescript/ui/components/BottomSheetRouter.d.ts.map +1 -1
- package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/ui/components/TextField/Addons/Outline.d.ts +2 -2
- package/lib/typescript/ui/components/TextField/helpers.d.ts +2 -2
- package/lib/typescript/ui/components/TextField/types.d.ts +0 -1
- package/lib/typescript/ui/components/TextField/types.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +28 -5
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts +59 -0
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -0
- package/lib/typescript/ui/context/hooks/useDeviceManagement.d.ts +27 -0
- package/lib/typescript/ui/context/hooks/useDeviceManagement.d.ts.map +1 -0
- package/lib/typescript/ui/context/hooks/useStorage.d.ts +22 -0
- package/lib/typescript/ui/context/hooks/useStorage.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/index.d.ts +0 -1
- package/lib/typescript/ui/hooks/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/index.d.ts +1 -1
- package/lib/typescript/ui/hooks/mutations/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts +8 -19
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts +1 -1
- package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/index.d.ts +1 -1
- package/lib/typescript/ui/hooks/queries/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/queryKeys.d.ts +0 -2
- package/lib/typescript/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts +5 -17
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useDeviceManagement.d.ts +27 -0
- package/lib/typescript/ui/hooks/useDeviceManagement.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/useProfileEditing.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useSessionManagement.d.ts +41 -0
- package/lib/typescript/ui/hooks/useSessionManagement.d.ts.map +1 -0
- package/lib/typescript/ui/index.d.ts +0 -1
- package/lib/typescript/ui/index.d.ts.map +1 -1
- package/lib/typescript/ui/navigation/routes.d.ts +1 -1
- package/lib/typescript/ui/navigation/routes.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/OxyAuthScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/stores/authStore.d.ts +1 -8
- package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
- package/lib/typescript/ui/styles/spacing.d.ts +0 -5
- package/lib/typescript/ui/styles/spacing.d.ts.map +1 -1
- package/lib/typescript/ui/utils/avatarUtils.d.ts +4 -1
- package/lib/typescript/ui/utils/avatarUtils.d.ts.map +1 -1
- package/lib/typescript/ui/utils/sessionHelpers.d.ts +0 -1
- package/lib/typescript/ui/utils/sessionHelpers.d.ts.map +1 -1
- package/lib/typescript/utils/deviceManager.d.ts +66 -0
- package/lib/typescript/utils/deviceManager.d.ts.map +1 -0
- package/lib/typescript/utils/errorUtils.d.ts +0 -6
- package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +2 -0
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/sessionUtils.d.ts.map +1 -1
- package/lib/typescript/utils/validationUtils.d.ts +0 -8
- package/lib/typescript/utils/validationUtils.d.ts.map +1 -1
- package/package.json +1 -6
- package/src/core/OxyServices.ts +1 -1
- package/src/core/index.ts +5 -8
- package/src/core/mixins/OxyServices.auth.ts +44 -87
- package/src/core/mixins/OxyServices.user.ts +10 -18
- package/src/core/services/TokenService.ts +27 -16
- package/src/crypto/index.ts +1 -3
- package/src/crypto/keyManager.ts +21 -30
- package/src/crypto/polyfill.ts +1 -2
- package/src/crypto/signatureService.ts +19 -43
- package/src/index.ts +6 -41
- package/src/models/interfaces.ts +39 -12
- package/src/models/session.ts +19 -7
- package/src/node/index.ts +0 -3
- package/src/ui/components/BottomSheetRouter.tsx +1 -6
- package/src/ui/components/OxyProvider.tsx +10 -17
- package/src/ui/components/TextField/Addons/Outline.tsx +2 -2
- package/src/ui/components/TextField/helpers.tsx +2 -2
- package/src/ui/components/TextField/types.tsx +1 -1
- package/src/ui/context/OxyContext.tsx +831 -463
- package/src/ui/context/hooks/useAuthOperations.ts +620 -0
- package/src/ui/context/hooks/useDeviceManagement.ts +108 -0
- package/src/ui/context/hooks/useStorage.ts +104 -0
- package/src/ui/hooks/index.ts +1 -2
- package/src/ui/hooks/mutations/index.ts +0 -2
- package/src/ui/hooks/mutations/useAccountMutations.ts +20 -66
- package/src/ui/hooks/queries/index.ts +0 -2
- package/src/ui/hooks/queries/queryKeys.ts +0 -2
- package/src/ui/hooks/queries/useAccountQueries.ts +19 -53
- package/src/ui/hooks/queries/useServicesQueries.ts +5 -5
- package/src/ui/hooks/useDeviceManagement.ts +108 -0
- package/src/ui/hooks/useProfileEditing.ts +3 -3
- package/src/ui/hooks/useSessionManagement.ts +405 -0
- package/src/ui/index.ts +1 -2
- package/src/ui/navigation/routes.ts +2 -6
- package/src/ui/screens/AccountCenterScreen.tsx +4 -9
- package/src/ui/screens/AccountSettingsScreen.tsx +31 -49
- package/src/ui/screens/AccountSwitcherScreen.tsx +5 -5
- package/src/ui/screens/OxyAuthScreen.tsx +19 -4
- package/src/ui/screens/PrivacySettingsScreen.tsx +101 -67
- package/src/ui/screens/ProfileScreen.tsx +10 -10
- package/src/ui/stores/authStore.ts +8 -48
- package/src/ui/styles/spacing.ts +2 -15
- package/src/ui/utils/avatarUtils.ts +21 -19
- package/src/ui/utils/sessionHelpers.ts +0 -7
- package/src/utils/__tests__/validationUtils.test.ts +1 -16
- package/src/utils/deviceManager.ts +198 -0
- package/src/utils/errorUtils.ts +1 -8
- package/src/utils/index.ts +2 -1
- package/src/utils/sessionUtils.ts +0 -8
- package/src/utils/validationUtils.ts +0 -12
- package/lib/commonjs/adapters/expo/crypto.js +0 -56
- package/lib/commonjs/adapters/expo/crypto.js.map +0 -1
- package/lib/commonjs/adapters/expo/fetch.js +0 -30
- package/lib/commonjs/adapters/expo/fetch.js.map +0 -1
- package/lib/commonjs/adapters/expo/index.js +0 -48
- package/lib/commonjs/adapters/expo/index.js.map +0 -1
- package/lib/commonjs/adapters/expo/storage.js +0 -201
- package/lib/commonjs/adapters/expo/storage.js.map +0 -1
- package/lib/commonjs/adapters/index.js +0 -48
- package/lib/commonjs/adapters/index.js.map +0 -1
- package/lib/commonjs/adapters/node/crypto.js +0 -40
- package/lib/commonjs/adapters/node/crypto.js.map +0 -1
- package/lib/commonjs/adapters/node/fetch.js +0 -62
- package/lib/commonjs/adapters/node/fetch.js.map +0 -1
- package/lib/commonjs/adapters/node/index.js +0 -34
- package/lib/commonjs/adapters/node/index.js.map +0 -1
- package/lib/commonjs/adapters/node/storage.js +0 -163
- package/lib/commonjs/adapters/node/storage.js.map +0 -1
- package/lib/commonjs/core/identity-session/DeviceManager.js +0 -237
- package/lib/commonjs/core/identity-session/DeviceManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/INTEGRATION_GUIDE.md +0 -287
- package/lib/commonjs/core/identity-session/IdentityManager.js +0 -400
- package/lib/commonjs/core/identity-session/IdentityManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/IdentitySessionCore.js +0 -394
- package/lib/commonjs/core/identity-session/IdentitySessionCore.js.map +0 -1
- package/lib/commonjs/core/identity-session/RefreshManager.js +0 -137
- package/lib/commonjs/core/identity-session/RefreshManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/SessionManager.js +0 -427
- package/lib/commonjs/core/identity-session/SessionManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/createIdentitySessionCore.js +0 -24
- package/lib/commonjs/core/identity-session/createIdentitySessionCore.js.map +0 -1
- package/lib/commonjs/core/identity-session/errors.js +0 -176
- package/lib/commonjs/core/identity-session/errors.js.map +0 -1
- package/lib/commonjs/core/identity-session/index.js +0 -80
- package/lib/commonjs/core/identity-session/index.js.map +0 -1
- package/lib/commonjs/core/identity-session/types.js +0 -2
- package/lib/commonjs/core/identity-session/types.js.map +0 -1
- package/lib/commonjs/crypto/README.md +0 -142
- package/lib/commonjs/crypto/core.js +0 -147
- package/lib/commonjs/crypto/core.js.map +0 -1
- package/lib/commonjs/node/signatureService.js +0 -107
- package/lib/commonjs/node/signatureService.js.map +0 -1
- package/lib/commonjs/ui/hooks/auth/index.js +0 -37
- package/lib/commonjs/ui/hooks/auth/index.js.map +0 -1
- package/lib/commonjs/ui/hooks/auth/useUsernameValidation.js +0 -171
- package/lib/commonjs/ui/hooks/auth/useUsernameValidation.js.map +0 -1
- package/lib/commonjs/ui/hooks/useAvatarPicker.js +0 -52
- package/lib/commonjs/ui/hooks/useAvatarPicker.js.map +0 -1
- package/lib/commonjs/ui/hooks/useIdentityTransfer.js +0 -125
- package/lib/commonjs/ui/hooks/useIdentityTransfer.js.map +0 -1
- package/lib/commonjs/ui/hooks/useTransferCodesPersistence.js +0 -81
- package/lib/commonjs/ui/hooks/useTransferCodesPersistence.js.map +0 -1
- package/lib/commonjs/ui/hooks/useTransferQueries.js +0 -85
- package/lib/commonjs/ui/hooks/useTransferQueries.js.map +0 -1
- package/lib/commonjs/ui/stores/transferStore.js +0 -157
- package/lib/commonjs/ui/stores/transferStore.js.map +0 -1
- package/lib/module/adapters/expo/crypto.js +0 -51
- package/lib/module/adapters/expo/crypto.js.map +0 -1
- package/lib/module/adapters/expo/fetch.js +0 -26
- package/lib/module/adapters/expo/fetch.js.map +0 -1
- package/lib/module/adapters/expo/index.js +0 -45
- package/lib/module/adapters/expo/index.js.map +0 -1
- package/lib/module/adapters/expo/storage.js +0 -198
- package/lib/module/adapters/expo/storage.js.map +0 -1
- package/lib/module/adapters/index.js +0 -45
- package/lib/module/adapters/index.js.map +0 -1
- package/lib/module/adapters/node/crypto.js +0 -36
- package/lib/module/adapters/node/crypto.js.map +0 -1
- package/lib/module/adapters/node/fetch.js +0 -57
- package/lib/module/adapters/node/fetch.js.map +0 -1
- package/lib/module/adapters/node/index.js +0 -31
- package/lib/module/adapters/node/index.js.map +0 -1
- package/lib/module/adapters/node/storage.js +0 -159
- package/lib/module/adapters/node/storage.js.map +0 -1
- package/lib/module/core/identity-session/DeviceManager.js +0 -232
- package/lib/module/core/identity-session/DeviceManager.js.map +0 -1
- package/lib/module/core/identity-session/INTEGRATION_GUIDE.md +0 -287
- package/lib/module/core/identity-session/IdentityManager.js +0 -395
- package/lib/module/core/identity-session/IdentityManager.js.map +0 -1
- package/lib/module/core/identity-session/IdentitySessionCore.js +0 -390
- package/lib/module/core/identity-session/IdentitySessionCore.js.map +0 -1
- package/lib/module/core/identity-session/RefreshManager.js +0 -132
- package/lib/module/core/identity-session/RefreshManager.js.map +0 -1
- package/lib/module/core/identity-session/SessionManager.js +0 -422
- package/lib/module/core/identity-session/SessionManager.js.map +0 -1
- package/lib/module/core/identity-session/createIdentitySessionCore.js +0 -21
- package/lib/module/core/identity-session/createIdentitySessionCore.js.map +0 -1
- package/lib/module/core/identity-session/errors.js +0 -170
- package/lib/module/core/identity-session/errors.js.map +0 -1
- package/lib/module/core/identity-session/index.js +0 -17
- package/lib/module/core/identity-session/index.js.map +0 -1
- package/lib/module/core/identity-session/types.js +0 -2
- package/lib/module/core/identity-session/types.js.map +0 -1
- package/lib/module/crypto/README.md +0 -142
- package/lib/module/crypto/core.js +0 -133
- package/lib/module/crypto/core.js.map +0 -1
- package/lib/module/node/signatureService.js +0 -101
- package/lib/module/node/signatureService.js.map +0 -1
- package/lib/module/ui/hooks/auth/index.js +0 -7
- package/lib/module/ui/hooks/auth/index.js.map +0 -1
- package/lib/module/ui/hooks/auth/useUsernameValidation.js +0 -167
- package/lib/module/ui/hooks/auth/useUsernameValidation.js.map +0 -1
- package/lib/module/ui/hooks/useAvatarPicker.js +0 -48
- package/lib/module/ui/hooks/useAvatarPicker.js.map +0 -1
- package/lib/module/ui/hooks/useIdentityTransfer.js +0 -121
- package/lib/module/ui/hooks/useIdentityTransfer.js.map +0 -1
- package/lib/module/ui/hooks/useTransferCodesPersistence.js +0 -77
- package/lib/module/ui/hooks/useTransferCodesPersistence.js.map +0 -1
- package/lib/module/ui/hooks/useTransferQueries.js +0 -80
- package/lib/module/ui/hooks/useTransferQueries.js.map +0 -1
- package/lib/module/ui/stores/transferStore.js +0 -152
- package/lib/module/ui/stores/transferStore.js.map +0 -1
- package/lib/typescript/adapters/expo/crypto.d.ts +0 -17
- package/lib/typescript/adapters/expo/crypto.d.ts.map +0 -1
- package/lib/typescript/adapters/expo/fetch.d.ts +0 -16
- package/lib/typescript/adapters/expo/fetch.d.ts.map +0 -1
- package/lib/typescript/adapters/expo/index.d.ts +0 -23
- package/lib/typescript/adapters/expo/index.d.ts.map +0 -1
- package/lib/typescript/adapters/expo/storage.d.ts +0 -23
- package/lib/typescript/adapters/expo/storage.d.ts.map +0 -1
- package/lib/typescript/adapters/index.d.ts +0 -17
- package/lib/typescript/adapters/index.d.ts.map +0 -1
- package/lib/typescript/adapters/node/crypto.d.ts +0 -17
- package/lib/typescript/adapters/node/crypto.d.ts.map +0 -1
- package/lib/typescript/adapters/node/fetch.d.ts +0 -16
- package/lib/typescript/adapters/node/fetch.d.ts.map +0 -1
- package/lib/typescript/adapters/node/index.d.ts +0 -23
- package/lib/typescript/adapters/node/index.d.ts.map +0 -1
- package/lib/typescript/adapters/node/storage.d.ts +0 -23
- package/lib/typescript/adapters/node/storage.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/DeviceManager.d.ts +0 -64
- package/lib/typescript/core/identity-session/DeviceManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/IdentityManager.d.ts +0 -88
- package/lib/typescript/core/identity-session/IdentityManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/IdentitySessionCore.d.ts +0 -141
- package/lib/typescript/core/identity-session/IdentitySessionCore.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/RefreshManager.d.ts +0 -36
- package/lib/typescript/core/identity-session/RefreshManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/SessionManager.d.ts +0 -104
- package/lib/typescript/core/identity-session/SessionManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/createIdentitySessionCore.d.ts +0 -11
- package/lib/typescript/core/identity-session/createIdentitySessionCore.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/errors.d.ts +0 -63
- package/lib/typescript/core/identity-session/errors.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/index.d.ts +0 -14
- package/lib/typescript/core/identity-session/index.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/types.d.ts +0 -196
- package/lib/typescript/core/identity-session/types.d.ts.map +0 -1
- package/lib/typescript/crypto/core.d.ts +0 -56
- package/lib/typescript/crypto/core.d.ts.map +0 -1
- package/lib/typescript/node/signatureService.d.ts +0 -55
- package/lib/typescript/node/signatureService.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/auth/index.d.ts +0 -6
- package/lib/typescript/ui/hooks/auth/index.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/auth/useUsernameValidation.d.ts +0 -32
- package/lib/typescript/ui/hooks/auth/useUsernameValidation.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useAvatarPicker.d.ts +0 -18
- package/lib/typescript/ui/hooks/useAvatarPicker.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useIdentityTransfer.d.ts +0 -24
- package/lib/typescript/ui/hooks/useIdentityTransfer.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useTransferCodesPersistence.d.ts +0 -6
- package/lib/typescript/ui/hooks/useTransferCodesPersistence.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useTransferQueries.d.ts +0 -26
- package/lib/typescript/ui/hooks/useTransferQueries.d.ts.map +0 -1
- package/lib/typescript/ui/stores/transferStore.d.ts +0 -36
- package/lib/typescript/ui/stores/transferStore.d.ts.map +0 -1
- package/src/adapters/expo/crypto.ts +0 -55
- package/src/adapters/expo/fetch.ts +0 -28
- package/src/adapters/expo/index.ts +0 -51
- package/src/adapters/expo/storage.ts +0 -228
- package/src/adapters/index.ts +0 -48
- package/src/adapters/node/crypto.ts +0 -39
- package/src/adapters/node/fetch.ts +0 -59
- package/src/adapters/node/index.ts +0 -37
- package/src/adapters/node/storage.ts +0 -170
- package/src/core/identity-session/DeviceManager.ts +0 -273
- package/src/core/identity-session/INTEGRATION_GUIDE.md +0 -287
- package/src/core/identity-session/IdentityManager.ts +0 -474
- package/src/core/identity-session/IdentitySessionCore.ts +0 -464
- package/src/core/identity-session/RefreshManager.ts +0 -189
- package/src/core/identity-session/SessionManager.ts +0 -500
- package/src/core/identity-session/createIdentitySessionCore.ts +0 -19
- package/src/core/identity-session/errors.ts +0 -197
- package/src/core/identity-session/index.ts +0 -15
- package/src/core/identity-session/types.ts +0 -188
- package/src/crypto/README.md +0 -142
- package/src/crypto/__tests__/core.test.ts +0 -203
- package/src/crypto/core.ts +0 -142
- package/src/node/signatureService.ts +0 -126
- package/src/ui/hooks/auth/index.ts +0 -9
- package/src/ui/hooks/auth/useUsernameValidation.ts +0 -177
- package/src/ui/hooks/useAvatarPicker.ts +0 -62
- package/src/ui/hooks/useIdentityTransfer.ts +0 -135
- package/src/ui/hooks/useTransferCodesPersistence.ts +0 -80
- package/src/ui/hooks/useTransferQueries.ts +0 -102
- package/src/ui/stores/transferStore.ts +0 -201
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import type { ApiError } from '../../models/interfaces';
|
|
3
|
+
import { DeviceManager } from '../../utils/deviceManager';
|
|
4
|
+
import type { OxyServices } from '../../core';
|
|
5
|
+
import { handleAuthError } from '../utils/errorHandlers';
|
|
6
|
+
|
|
7
|
+
export interface UseDeviceManagementOptions {
|
|
8
|
+
oxyServices: OxyServices;
|
|
9
|
+
activeSessionId: string | null;
|
|
10
|
+
onError?: (error: ApiError) => void;
|
|
11
|
+
clearSessionState: () => Promise<void>;
|
|
12
|
+
logger?: (message: string, error?: unknown) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UseDeviceManagementResult {
|
|
16
|
+
getDeviceSessions: () => Promise<
|
|
17
|
+
Array<{
|
|
18
|
+
sessionId: string;
|
|
19
|
+
deviceId: string;
|
|
20
|
+
deviceName?: string;
|
|
21
|
+
lastActive?: string;
|
|
22
|
+
expiresAt?: string;
|
|
23
|
+
}>
|
|
24
|
+
>;
|
|
25
|
+
logoutAllDeviceSessions: () => Promise<void>;
|
|
26
|
+
updateDeviceName: (deviceName: string) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Provide device session management helpers tied to the current active session.
|
|
31
|
+
*
|
|
32
|
+
* @param options - Device management configuration
|
|
33
|
+
*/
|
|
34
|
+
export const useDeviceManagement = ({
|
|
35
|
+
oxyServices,
|
|
36
|
+
activeSessionId,
|
|
37
|
+
onError,
|
|
38
|
+
clearSessionState,
|
|
39
|
+
logger,
|
|
40
|
+
}: UseDeviceManagementOptions): UseDeviceManagementResult => {
|
|
41
|
+
const getDeviceSessions = useCallback(async (): Promise<
|
|
42
|
+
Array<{
|
|
43
|
+
sessionId: string;
|
|
44
|
+
deviceId: string;
|
|
45
|
+
deviceName?: string;
|
|
46
|
+
lastActive?: string;
|
|
47
|
+
expiresAt?: string;
|
|
48
|
+
}>
|
|
49
|
+
> => {
|
|
50
|
+
if (!activeSessionId) throw new Error('No active session');
|
|
51
|
+
try {
|
|
52
|
+
return await oxyServices.getDeviceSessions(activeSessionId);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
handleAuthError(error, {
|
|
55
|
+
defaultMessage: 'Failed to get device sessions',
|
|
56
|
+
code: 'GET_DEVICE_SESSIONS_ERROR',
|
|
57
|
+
onError,
|
|
58
|
+
logger,
|
|
59
|
+
});
|
|
60
|
+
throw error instanceof Error ? error : new Error('Failed to get device sessions');
|
|
61
|
+
}
|
|
62
|
+
}, [activeSessionId, logger, onError, oxyServices]);
|
|
63
|
+
|
|
64
|
+
const logoutAllDeviceSessions = useCallback(async (): Promise<void> => {
|
|
65
|
+
if (!activeSessionId) throw new Error('No active session');
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await oxyServices.logoutAllDeviceSessions(activeSessionId);
|
|
69
|
+
await clearSessionState();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
handleAuthError(error, {
|
|
72
|
+
defaultMessage: 'Failed to logout all device sessions',
|
|
73
|
+
code: 'LOGOUT_ALL_DEVICES_ERROR',
|
|
74
|
+
onError,
|
|
75
|
+
logger,
|
|
76
|
+
});
|
|
77
|
+
throw error instanceof Error ? error : new Error('Failed to logout all device sessions');
|
|
78
|
+
}
|
|
79
|
+
}, [activeSessionId, clearSessionState, logger, onError, oxyServices]);
|
|
80
|
+
|
|
81
|
+
const updateDeviceName = useCallback(
|
|
82
|
+
async (deviceName: string): Promise<void> => {
|
|
83
|
+
if (!activeSessionId) throw new Error('No active session');
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await oxyServices.updateDeviceName(activeSessionId, deviceName);
|
|
87
|
+
await DeviceManager.updateDeviceName(deviceName);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
handleAuthError(error, {
|
|
90
|
+
defaultMessage: 'Failed to update device name',
|
|
91
|
+
code: 'UPDATE_DEVICE_NAME_ERROR',
|
|
92
|
+
onError,
|
|
93
|
+
logger,
|
|
94
|
+
});
|
|
95
|
+
throw error instanceof Error ? error : new Error('Failed to update device name');
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
[activeSessionId, logger, onError, oxyServices],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
getDeviceSessions,
|
|
103
|
+
logoutAllDeviceSessions,
|
|
104
|
+
updateDeviceName,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { useI18n } from './useI18n';
|
|
3
3
|
import { useUpdateProfile } from './mutations/useAccountMutations';
|
|
4
|
-
import {
|
|
4
|
+
import { useCurrentUser } from './queries/useAccountQueries';
|
|
5
5
|
|
|
6
6
|
export interface ProfileUpdateData {
|
|
7
7
|
displayName?: string;
|
|
@@ -34,6 +34,7 @@ export interface ProfileUpdateData {
|
|
|
34
34
|
export const useProfileEditing = () => {
|
|
35
35
|
const { t } = useI18n();
|
|
36
36
|
const updateProfileMutation = useUpdateProfile();
|
|
37
|
+
const { data: currentUser } = useCurrentUser();
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Save profile updates to the server using TanStack Query
|
|
@@ -71,7 +72,6 @@ export const useProfileEditing = () => {
|
|
|
71
72
|
|
|
72
73
|
// Handle name field
|
|
73
74
|
if (updates.displayName !== undefined || updates.lastName !== undefined) {
|
|
74
|
-
const currentUser = useAuthStore.getState().user;
|
|
75
75
|
const currentName = currentUser?.name;
|
|
76
76
|
updateData.name = {
|
|
77
77
|
first: updates.displayName ?? (typeof currentName === 'object' ? currentName?.first : '') ?? '',
|
|
@@ -86,7 +86,7 @@ export const useProfileEditing = () => {
|
|
|
86
86
|
// Error toast is handled by the mutation
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
89
|
-
}, [updateProfileMutation, t]);
|
|
89
|
+
}, [updateProfileMutation, t, currentUser]);
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Update a single profile field
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { ApiError, User } from '../../models/interfaces';
|
|
3
|
+
import type { ClientSession } from '../../models/session';
|
|
4
|
+
import { mergeSessions, normalizeAndSortSessions, sessionsArraysEqual } from '../../utils/sessionUtils';
|
|
5
|
+
import { fetchSessionsWithFallback, mapSessionsToClient, validateSessionBatch } from '../utils/sessionHelpers';
|
|
6
|
+
import { getStorageKeys, type StorageInterface } from '../utils/storageHelpers';
|
|
7
|
+
import { handleAuthError, isInvalidSessionError } from '../utils/errorHandlers';
|
|
8
|
+
import type { OxyServices } from '../../core';
|
|
9
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
10
|
+
import { clearQueryCache } from './queryClient';
|
|
11
|
+
|
|
12
|
+
const getDeviceIdForSession = (sessions: ClientSession[] = [], sessionId: string | null) =>
|
|
13
|
+
sessionId ? sessions.find((s) => s.sessionId === sessionId)?.deviceId : undefined;
|
|
14
|
+
|
|
15
|
+
export interface UseSessionManagementOptions {
|
|
16
|
+
oxyServices: OxyServices;
|
|
17
|
+
storage: StorageInterface | null;
|
|
18
|
+
storageKeyPrefix?: string;
|
|
19
|
+
loginSuccess: (user: User) => void;
|
|
20
|
+
logoutStore: () => void;
|
|
21
|
+
applyLanguagePreference: (user: User) => Promise<void>;
|
|
22
|
+
onAuthStateChange?: (user: User | null) => void;
|
|
23
|
+
onError?: (error: ApiError) => void;
|
|
24
|
+
setAuthError?: (message: string | null) => void;
|
|
25
|
+
logger?: (message: string, error?: unknown) => void;
|
|
26
|
+
setTokenReady?: (ready: boolean) => void;
|
|
27
|
+
queryClient?: QueryClient | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UseSessionManagementResult {
|
|
31
|
+
sessions: ClientSession[];
|
|
32
|
+
activeSessionId: string | null;
|
|
33
|
+
setActiveSessionId: (sessionId: string | null) => void;
|
|
34
|
+
updateSessions: (incoming: ClientSession[], options?: { merge?: boolean }) => void;
|
|
35
|
+
switchSession: (sessionId: string) => Promise<User>;
|
|
36
|
+
refreshSessions: (activeUserId?: string) => Promise<void>;
|
|
37
|
+
clearSessionState: () => Promise<void>;
|
|
38
|
+
saveActiveSessionId: (sessionId: string) => Promise<void>;
|
|
39
|
+
trackRemovedSession: (sessionId: string) => void;
|
|
40
|
+
storageKeys: ReturnType<typeof getStorageKeys>;
|
|
41
|
+
isRefreshInFlight: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULT_SAVE_ERROR_MESSAGE = 'Failed to save session data';
|
|
45
|
+
const CLEAR_STORAGE_ERROR = 'Failed to clear storage';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Manage session state, persistence, and high-level multi-session operations.
|
|
49
|
+
*
|
|
50
|
+
* @param options - Session management configuration
|
|
51
|
+
*/
|
|
52
|
+
export const useSessionManagement = ({
|
|
53
|
+
oxyServices,
|
|
54
|
+
storage,
|
|
55
|
+
storageKeyPrefix,
|
|
56
|
+
loginSuccess,
|
|
57
|
+
logoutStore,
|
|
58
|
+
applyLanguagePreference,
|
|
59
|
+
onAuthStateChange,
|
|
60
|
+
onError,
|
|
61
|
+
setAuthError,
|
|
62
|
+
logger,
|
|
63
|
+
setTokenReady,
|
|
64
|
+
queryClient,
|
|
65
|
+
}: UseSessionManagementOptions): UseSessionManagementResult => {
|
|
66
|
+
const [sessions, setSessions] = useState<ClientSession[]>([]);
|
|
67
|
+
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
|
|
68
|
+
|
|
69
|
+
const refreshInFlightRef = useRef<Promise<void> | null>(null);
|
|
70
|
+
const removedSessionsRef = useRef<Set<string>>(new Set());
|
|
71
|
+
const lastRefreshRef = useRef<number>(0);
|
|
72
|
+
|
|
73
|
+
const storageKeys = useMemo(() => getStorageKeys(storageKeyPrefix), [storageKeyPrefix]);
|
|
74
|
+
|
|
75
|
+
const saveSessionIds = useCallback(
|
|
76
|
+
async (sessionIds: string[]): Promise<void> => {
|
|
77
|
+
if (!storage) return;
|
|
78
|
+
try {
|
|
79
|
+
const uniqueIds = Array.from(new Set(sessionIds));
|
|
80
|
+
await storage.setItem(storageKeys.sessionIds, JSON.stringify(uniqueIds));
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (logger) {
|
|
83
|
+
logger(DEFAULT_SAVE_ERROR_MESSAGE, error);
|
|
84
|
+
} else if (__DEV__) {
|
|
85
|
+
console.warn('Failed to save session IDs:', error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[logger, storage, storageKeys.sessionIds],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const updateSessions = useCallback(
|
|
93
|
+
(incoming: ClientSession[], options: { merge?: boolean } = {}): void => {
|
|
94
|
+
setSessions((prevSessions) => {
|
|
95
|
+
const processed = options.merge
|
|
96
|
+
? mergeSessions(prevSessions, incoming, activeSessionId, false)
|
|
97
|
+
: normalizeAndSortSessions(incoming, activeSessionId, false);
|
|
98
|
+
|
|
99
|
+
if (storage) {
|
|
100
|
+
void saveSessionIds(processed.map((session) => session.sessionId));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (sessionsArraysEqual(prevSessions, processed)) {
|
|
104
|
+
return prevSessions;
|
|
105
|
+
}
|
|
106
|
+
return processed;
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
[activeSessionId, saveSessionIds, storage],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const saveActiveSessionId = useCallback(
|
|
113
|
+
async (sessionId: string): Promise<void> => {
|
|
114
|
+
if (!storage) return;
|
|
115
|
+
try {
|
|
116
|
+
await storage.setItem(storageKeys.activeSessionId, sessionId);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
handleAuthError(error, {
|
|
119
|
+
defaultMessage: DEFAULT_SAVE_ERROR_MESSAGE,
|
|
120
|
+
code: 'SESSION_PERSISTENCE_ERROR',
|
|
121
|
+
onError,
|
|
122
|
+
setAuthError,
|
|
123
|
+
logger,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
[logger, onError, setAuthError, storage, storageKeys.activeSessionId],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const removeActiveSessionId = useCallback(async (): Promise<void> => {
|
|
131
|
+
if (!storage) return;
|
|
132
|
+
try {
|
|
133
|
+
await storage.removeItem(storageKeys.activeSessionId);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
handleAuthError(error, {
|
|
136
|
+
defaultMessage: DEFAULT_SAVE_ERROR_MESSAGE,
|
|
137
|
+
code: 'SESSION_PERSISTENCE_ERROR',
|
|
138
|
+
onError,
|
|
139
|
+
setAuthError,
|
|
140
|
+
logger,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}, [logger, onError, setAuthError, storage, storageKeys.activeSessionId]);
|
|
144
|
+
|
|
145
|
+
const clearSessionStorage = useCallback(async (): Promise<void> => {
|
|
146
|
+
if (!storage) return;
|
|
147
|
+
try {
|
|
148
|
+
await storage.removeItem(storageKeys.activeSessionId);
|
|
149
|
+
await storage.removeItem(storageKeys.sessionIds);
|
|
150
|
+
// Clear identity sync state
|
|
151
|
+
await storage.removeItem('oxy_identity_synced').catch(() => {});
|
|
152
|
+
} catch (error) {
|
|
153
|
+
handleAuthError(error, {
|
|
154
|
+
defaultMessage: CLEAR_STORAGE_ERROR,
|
|
155
|
+
code: 'STORAGE_ERROR',
|
|
156
|
+
onError,
|
|
157
|
+
setAuthError,
|
|
158
|
+
logger,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, [logger, onError, setAuthError, storage, storageKeys.activeSessionId, storageKeys.sessionIds]);
|
|
162
|
+
|
|
163
|
+
const clearSessionState = useCallback(async (): Promise<void> => {
|
|
164
|
+
setSessions([]);
|
|
165
|
+
setActiveSessionId(null);
|
|
166
|
+
logoutStore();
|
|
167
|
+
oxyServices.clearTokens();
|
|
168
|
+
|
|
169
|
+
// Clear TanStack Query cache (in-memory)
|
|
170
|
+
if (queryClient) {
|
|
171
|
+
queryClient.clear();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Clear persisted query cache
|
|
175
|
+
if (storage) {
|
|
176
|
+
try {
|
|
177
|
+
await clearQueryCache(storage);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (logger) {
|
|
180
|
+
logger('Failed to clear persisted query cache', error);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
await clearSessionStorage();
|
|
186
|
+
onAuthStateChange?.(null);
|
|
187
|
+
}, [clearSessionStorage, logoutStore, onAuthStateChange, queryClient, storage, logger, oxyServices]);
|
|
188
|
+
|
|
189
|
+
const activateSession = useCallback(
|
|
190
|
+
async (sessionId: string, user: User): Promise<void> => {
|
|
191
|
+
const deviceId = getDeviceIdForSession(sessions, sessionId);
|
|
192
|
+
await oxyServices.getTokenBySession(sessionId, deviceId);
|
|
193
|
+
setTokenReady?.(true);
|
|
194
|
+
setActiveSessionId(sessionId);
|
|
195
|
+
loginSuccess(user);
|
|
196
|
+
await saveActiveSessionId(sessionId);
|
|
197
|
+
await applyLanguagePreference(user);
|
|
198
|
+
onAuthStateChange?.(user);
|
|
199
|
+
},
|
|
200
|
+
[
|
|
201
|
+
applyLanguagePreference,
|
|
202
|
+
sessions,
|
|
203
|
+
loginSuccess,
|
|
204
|
+
onAuthStateChange,
|
|
205
|
+
oxyServices,
|
|
206
|
+
saveActiveSessionId,
|
|
207
|
+
setTokenReady,
|
|
208
|
+
],
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const trackRemovedSession = useCallback((sessionId: string) => {
|
|
212
|
+
removedSessionsRef.current.add(sessionId);
|
|
213
|
+
setTimeout(() => {
|
|
214
|
+
removedSessionsRef.current.delete(sessionId);
|
|
215
|
+
}, 5000);
|
|
216
|
+
}, []);
|
|
217
|
+
|
|
218
|
+
const findReplacementSession = useCallback(
|
|
219
|
+
async (sessionIds: string[]): Promise<User | null> => {
|
|
220
|
+
if (!sessionIds.length) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const validationResults = await validateSessionBatch(oxyServices, sessionIds, {
|
|
225
|
+
maxConcurrency: 3,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const validSession = validationResults.find((result) => result.valid);
|
|
229
|
+
if (!validSession) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const validation = await oxyServices.validateSession(validSession.sessionId, {
|
|
234
|
+
useHeaderValidation: true,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (!validation?.valid || !validation.user) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const user = validation.user as User;
|
|
242
|
+
await activateSession(validSession.sessionId, user);
|
|
243
|
+
return user;
|
|
244
|
+
},
|
|
245
|
+
[activateSession, oxyServices],
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const switchSession = useCallback(
|
|
249
|
+
async (sessionId: string): Promise<User> => {
|
|
250
|
+
try {
|
|
251
|
+
const validation = await oxyServices.validateSession(sessionId, { useHeaderValidation: true });
|
|
252
|
+
if (!validation?.valid) {
|
|
253
|
+
throw new Error('Session is invalid or expired');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!validation.user) {
|
|
257
|
+
throw new Error('User data not available from session validation');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const user = validation.user as User;
|
|
261
|
+
await activateSession(sessionId, user);
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
const deviceSessions = await fetchSessionsWithFallback(oxyServices, sessionId, {
|
|
265
|
+
fallbackUserId: user.id,
|
|
266
|
+
logger,
|
|
267
|
+
});
|
|
268
|
+
updateSessions(deviceSessions, { merge: true });
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (__DEV__) {
|
|
271
|
+
console.warn('Failed to synchronize sessions after switch:', error);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return user;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
const invalidSession = isInvalidSessionError(error);
|
|
278
|
+
|
|
279
|
+
if (invalidSession) {
|
|
280
|
+
updateSessions(sessions.filter((session) => session.sessionId !== sessionId), {
|
|
281
|
+
merge: false,
|
|
282
|
+
});
|
|
283
|
+
if (sessionId === activeSessionId) {
|
|
284
|
+
const otherSessionIds = sessions
|
|
285
|
+
.filter(
|
|
286
|
+
(session) =>
|
|
287
|
+
session.sessionId !== sessionId && !removedSessionsRef.current.has(session.sessionId),
|
|
288
|
+
)
|
|
289
|
+
.map((session) => session.sessionId);
|
|
290
|
+
|
|
291
|
+
const replacementUser = await findReplacementSession(otherSessionIds);
|
|
292
|
+
if (replacementUser) {
|
|
293
|
+
return replacementUser;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
handleAuthError(error, {
|
|
299
|
+
defaultMessage: 'Failed to switch session',
|
|
300
|
+
code: invalidSession ? 'INVALID_SESSION' : 'SESSION_SWITCH_ERROR',
|
|
301
|
+
onError,
|
|
302
|
+
setAuthError,
|
|
303
|
+
logger,
|
|
304
|
+
});
|
|
305
|
+
throw error instanceof Error ? error : new Error('Failed to switch session');
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
[
|
|
309
|
+
activateSession,
|
|
310
|
+
activeSessionId,
|
|
311
|
+
findReplacementSession,
|
|
312
|
+
logger,
|
|
313
|
+
loginSuccess,
|
|
314
|
+
onError,
|
|
315
|
+
oxyServices,
|
|
316
|
+
sessions,
|
|
317
|
+
setAuthError,
|
|
318
|
+
updateSessions,
|
|
319
|
+
],
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const refreshSessions = useCallback(
|
|
323
|
+
async (activeUserId?: string): Promise<void> => {
|
|
324
|
+
if (!activeSessionId) return;
|
|
325
|
+
|
|
326
|
+
if (refreshInFlightRef.current) {
|
|
327
|
+
await refreshInFlightRef.current;
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const now = Date.now();
|
|
332
|
+
if (now - lastRefreshRef.current < 500) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
lastRefreshRef.current = now;
|
|
336
|
+
|
|
337
|
+
const refreshPromise = (async () => {
|
|
338
|
+
try {
|
|
339
|
+
const deviceSessions = await fetchSessionsWithFallback(oxyServices, activeSessionId, {
|
|
340
|
+
fallbackUserId: activeUserId,
|
|
341
|
+
logger,
|
|
342
|
+
});
|
|
343
|
+
updateSessions(deviceSessions, { merge: true });
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (isInvalidSessionError(error)) {
|
|
346
|
+
const otherSessions = sessions
|
|
347
|
+
.filter(
|
|
348
|
+
(session) =>
|
|
349
|
+
session.sessionId !== activeSessionId &&
|
|
350
|
+
!removedSessionsRef.current.has(session.sessionId),
|
|
351
|
+
)
|
|
352
|
+
.map((session) => session.sessionId);
|
|
353
|
+
|
|
354
|
+
const replacementUser = await findReplacementSession(otherSessions);
|
|
355
|
+
if (!replacementUser) {
|
|
356
|
+
await clearSessionState();
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
handleAuthError(error, {
|
|
362
|
+
defaultMessage: 'Failed to refresh sessions',
|
|
363
|
+
code: 'SESSION_REFRESH_ERROR',
|
|
364
|
+
onError,
|
|
365
|
+
setAuthError,
|
|
366
|
+
logger,
|
|
367
|
+
});
|
|
368
|
+
} finally {
|
|
369
|
+
refreshInFlightRef.current = null;
|
|
370
|
+
lastRefreshRef.current = Date.now();
|
|
371
|
+
}
|
|
372
|
+
})();
|
|
373
|
+
|
|
374
|
+
refreshInFlightRef.current = refreshPromise;
|
|
375
|
+
await refreshPromise;
|
|
376
|
+
},
|
|
377
|
+
[
|
|
378
|
+
activeSessionId,
|
|
379
|
+
clearSessionState,
|
|
380
|
+
findReplacementSession,
|
|
381
|
+
logger,
|
|
382
|
+
onError,
|
|
383
|
+
oxyServices,
|
|
384
|
+
sessions,
|
|
385
|
+
setAuthError,
|
|
386
|
+
updateSessions,
|
|
387
|
+
],
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
const isRefreshInFlight = Boolean(refreshInFlightRef.current);
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
sessions,
|
|
394
|
+
activeSessionId,
|
|
395
|
+
setActiveSessionId,
|
|
396
|
+
updateSessions,
|
|
397
|
+
switchSession,
|
|
398
|
+
refreshSessions,
|
|
399
|
+
clearSessionState,
|
|
400
|
+
saveActiveSessionId,
|
|
401
|
+
trackRemovedSession,
|
|
402
|
+
storageKeys,
|
|
403
|
+
isRefreshInFlight,
|
|
404
|
+
};
|
|
405
|
+
};
|
package/src/ui/index.ts
CHANGED
|
@@ -79,6 +79,5 @@ export {
|
|
|
79
79
|
toast
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
//
|
|
83
|
-
export { OxyServices } from '../core';
|
|
82
|
+
// Removed convenience re-export of core services from UI context.
|
|
84
83
|
export type { User, LoginResponse, ApiError } from '../models/interfaces';
|
|
@@ -30,22 +30,18 @@ export type RouteName =
|
|
|
30
30
|
| 'UserLinks'
|
|
31
31
|
| 'HistoryView'
|
|
32
32
|
| 'SavesCollections'
|
|
33
|
-
| 'EditProfile' // For backward compatibility, maps to AccountSettings
|
|
34
33
|
| 'KarmaCenter'
|
|
35
34
|
| 'KarmaLeaderboard'
|
|
36
35
|
| 'KarmaRewards'
|
|
37
36
|
| 'KarmaRules'
|
|
38
37
|
| 'AboutKarma'
|
|
39
38
|
| 'KarmaFAQ'
|
|
40
|
-
|
|
41
|
-
| 'SignIn'; // Maps to OxyAuth
|
|
39
|
+
| 'EditProfile'
|
|
42
40
|
|
|
43
41
|
// Lazy screen loaders - functions that return screen components on-demand
|
|
44
42
|
// This breaks the require cycle by deferring imports until screens are actually needed
|
|
45
43
|
const screenLoaders: Record<RouteName, () => ComponentType<BaseScreenProps>> = {
|
|
46
44
|
OxyAuth: () => require('../screens/OxyAuthScreen').default,
|
|
47
|
-
// Legacy alias - SignIn now maps to OxyAuth
|
|
48
|
-
SignIn: () => require('../screens/OxyAuthScreen').default,
|
|
49
45
|
AccountOverview: () => require('../screens/AccountOverviewScreen').default,
|
|
50
46
|
AccountSettings: () => require('../screens/AccountSettingsScreen').default,
|
|
51
47
|
AccountCenter: () => require('../screens/AccountCenterScreen').default,
|
|
@@ -67,7 +63,7 @@ const screenLoaders: Record<RouteName, () => ComponentType<BaseScreenProps>> = {
|
|
|
67
63
|
UserLinks: () => require('../screens/UserLinksScreen').default,
|
|
68
64
|
HistoryView: () => require('../screens/HistoryViewScreen').default,
|
|
69
65
|
SavesCollections: () => require('../screens/SavesCollectionsScreen').default,
|
|
70
|
-
//
|
|
66
|
+
// EditProfile kept for historical references
|
|
71
67
|
EditProfile: () => require('../screens/AccountSettingsScreen').default,
|
|
72
68
|
// Karma screens
|
|
73
69
|
KarmaCenter: () => require('../screens/karma/KarmaCenterScreen').default,
|
|
@@ -86,14 +86,9 @@ const AccountCenterScreen: React.FC<BaseScreenProps> = ({
|
|
|
86
86
|
return (
|
|
87
87
|
<View style={[styles.container, { backgroundColor }]}>
|
|
88
88
|
{/* Header with user profile */}
|
|
89
|
-
{user &&
|
|
89
|
+
{user && (
|
|
90
90
|
<ProfileCard
|
|
91
|
-
user={
|
|
92
|
-
username: user.username,
|
|
93
|
-
email: user.email,
|
|
94
|
-
name: user.name,
|
|
95
|
-
avatar: user.avatar,
|
|
96
|
-
}}
|
|
91
|
+
user={user}
|
|
97
92
|
theme={normalizedTheme}
|
|
98
93
|
onEditPress={() => navigate?.('EditProfile', { activeTab: 'profile' })}
|
|
99
94
|
onClosePress={onClose}
|
|
@@ -194,7 +189,7 @@ const AccountCenterScreen: React.FC<BaseScreenProps> = ({
|
|
|
194
189
|
iconColor: colors.iconPersonalInfo,
|
|
195
190
|
title: t('accountCenter.items.addAccount.title') || 'Add Another Account',
|
|
196
191
|
subtitle: t('accountCenter.items.addAccount.subtitle') || 'Sign in with a different account',
|
|
197
|
-
onPress: () => navigate?.('
|
|
192
|
+
onPress: () => navigate?.('OxyAuth'),
|
|
198
193
|
},
|
|
199
194
|
], [sessions.length, navigate, t, colors])}
|
|
200
195
|
|
|
@@ -213,7 +208,7 @@ const AccountCenterScreen: React.FC<BaseScreenProps> = ({
|
|
|
213
208
|
iconColor: colors.iconPersonalInfo,
|
|
214
209
|
title: t('accountCenter.items.addAccount.title') || 'Add Another Account',
|
|
215
210
|
subtitle: t('accountCenter.items.addAccount.subtitle') || 'Sign in with a different account',
|
|
216
|
-
onPress: () => navigate?.('
|
|
211
|
+
onPress: () => navigate?.('OxyAuth'),
|
|
217
212
|
},
|
|
218
213
|
], [navigate, t, colors])}
|
|
219
214
|
|