@oxyhq/services 5.16.0 → 5.16.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.
Files changed (190) hide show
  1. package/lib/commonjs/core/mixins/OxyServices.assets.js +15 -0
  2. package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -1
  3. package/lib/commonjs/core/mixins/OxyServices.user.js +14 -13
  4. package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -1
  5. package/lib/commonjs/crypto/keyManager.js +164 -3
  6. package/lib/commonjs/crypto/keyManager.js.map +1 -1
  7. package/lib/commonjs/crypto/signatureService.js +26 -0
  8. package/lib/commonjs/crypto/signatureService.js.map +1 -1
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/ui/components/GroupedSection.js +1 -1
  11. package/lib/commonjs/ui/components/GroupedSection.js.map +1 -1
  12. package/lib/commonjs/ui/components/OxyProvider.js +71 -24
  13. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  14. package/lib/commonjs/ui/components/profile/EditDisplayNameModal.js +1 -4
  15. package/lib/commonjs/ui/components/profile/EditDisplayNameModal.js.map +1 -1
  16. package/lib/commonjs/ui/context/OxyContext.js +177 -4
  17. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  18. package/lib/commonjs/ui/context/hooks/useAuthOperations.js +148 -49
  19. package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
  20. package/lib/commonjs/ui/context/hooks/useSessionManagement.js +22 -2
  21. package/lib/commonjs/ui/context/hooks/useSessionManagement.js.map +1 -1
  22. package/lib/commonjs/ui/hooks/mutations/index.js +28 -0
  23. package/lib/commonjs/ui/hooks/mutations/index.js.map +1 -0
  24. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +314 -0
  25. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -0
  26. package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js +193 -0
  27. package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js.map +1 -0
  28. package/lib/commonjs/ui/hooks/queries/index.js +39 -0
  29. package/lib/commonjs/ui/hooks/queries/index.js.map +1 -0
  30. package/lib/commonjs/ui/hooks/queries/queryKeys.js +85 -0
  31. package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -0
  32. package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +145 -0
  33. package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -0
  34. package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +138 -0
  35. package/lib/commonjs/ui/hooks/queries/useServicesQueries.js.map +1 -0
  36. package/lib/commonjs/ui/hooks/queryClient.js +117 -0
  37. package/lib/commonjs/ui/hooks/queryClient.js.map +1 -0
  38. package/lib/commonjs/ui/hooks/useIdentityMutations.js +111 -0
  39. package/lib/commonjs/ui/hooks/useIdentityMutations.js.map +1 -0
  40. package/lib/commonjs/ui/hooks/useProfileEditing.js +42 -58
  41. package/lib/commonjs/ui/hooks/useProfileEditing.js.map +1 -1
  42. package/lib/commonjs/ui/hooks/useQueryClient.js +20 -0
  43. package/lib/commonjs/ui/hooks/useQueryClient.js.map +1 -0
  44. package/lib/commonjs/ui/hooks/useSessionManagement.js +22 -2
  45. package/lib/commonjs/ui/hooks/useSessionManagement.js.map +1 -1
  46. package/lib/commonjs/ui/screens/AccountOverviewScreen.js +43 -42
  47. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
  48. package/lib/commonjs/ui/screens/AccountSettingsScreen.js +63 -58
  49. package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
  50. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js +6 -6
  51. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  52. package/lib/commonjs/ui/stores/accountStore.js +57 -42
  53. package/lib/commonjs/ui/stores/accountStore.js.map +1 -1
  54. package/lib/commonjs/ui/stores/authStore.js +4 -25
  55. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  56. package/lib/module/core/mixins/OxyServices.assets.js +15 -0
  57. package/lib/module/core/mixins/OxyServices.assets.js.map +1 -1
  58. package/lib/module/core/mixins/OxyServices.user.js +14 -13
  59. package/lib/module/core/mixins/OxyServices.user.js.map +1 -1
  60. package/lib/module/crypto/keyManager.js +164 -3
  61. package/lib/module/crypto/keyManager.js.map +1 -1
  62. package/lib/module/crypto/signatureService.js +26 -0
  63. package/lib/module/crypto/signatureService.js.map +1 -1
  64. package/lib/module/index.js.map +1 -1
  65. package/lib/module/ui/components/GroupedSection.js +1 -1
  66. package/lib/module/ui/components/GroupedSection.js.map +1 -1
  67. package/lib/module/ui/components/OxyProvider.js +72 -25
  68. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  69. package/lib/module/ui/components/profile/EditDisplayNameModal.js +1 -4
  70. package/lib/module/ui/components/profile/EditDisplayNameModal.js.map +1 -1
  71. package/lib/module/ui/context/OxyContext.js +176 -4
  72. package/lib/module/ui/context/OxyContext.js.map +1 -1
  73. package/lib/module/ui/context/hooks/useAuthOperations.js +148 -49
  74. package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
  75. package/lib/module/ui/context/hooks/useSessionManagement.js +22 -2
  76. package/lib/module/ui/context/hooks/useSessionManagement.js.map +1 -1
  77. package/lib/module/ui/hooks/mutations/index.js +6 -0
  78. package/lib/module/ui/hooks/mutations/index.js.map +1 -0
  79. package/lib/module/ui/hooks/mutations/useAccountMutations.js +308 -0
  80. package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -0
  81. package/lib/module/ui/hooks/mutations/useServicesMutations.js +185 -0
  82. package/lib/module/ui/hooks/mutations/useServicesMutations.js.map +1 -0
  83. package/lib/module/ui/hooks/queries/index.js +7 -0
  84. package/lib/module/ui/hooks/queries/index.js.map +1 -0
  85. package/lib/module/ui/hooks/queries/queryKeys.js +78 -0
  86. package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -0
  87. package/lib/module/ui/hooks/queries/useAccountQueries.js +136 -0
  88. package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -0
  89. package/lib/module/ui/hooks/queries/useServicesQueries.js +130 -0
  90. package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -0
  91. package/lib/module/ui/hooks/queryClient.js +110 -0
  92. package/lib/module/ui/hooks/queryClient.js.map +1 -0
  93. package/lib/module/ui/hooks/useIdentityMutations.js +105 -0
  94. package/lib/module/ui/hooks/useIdentityMutations.js.map +1 -0
  95. package/lib/module/ui/hooks/useProfileEditing.js +43 -59
  96. package/lib/module/ui/hooks/useProfileEditing.js.map +1 -1
  97. package/lib/module/ui/hooks/useQueryClient.js +15 -0
  98. package/lib/module/ui/hooks/useQueryClient.js.map +1 -0
  99. package/lib/module/ui/hooks/useSessionManagement.js +22 -2
  100. package/lib/module/ui/hooks/useSessionManagement.js.map +1 -1
  101. package/lib/module/ui/screens/AccountOverviewScreen.js +43 -42
  102. package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
  103. package/lib/module/ui/screens/AccountSettingsScreen.js +63 -58
  104. package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
  105. package/lib/module/ui/screens/WelcomeNewUserScreen.js +6 -6
  106. package/lib/module/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  107. package/lib/module/ui/stores/accountStore.js +57 -42
  108. package/lib/module/ui/stores/accountStore.js.map +1 -1
  109. package/lib/module/ui/stores/authStore.js +4 -25
  110. package/lib/module/ui/stores/authStore.js.map +1 -1
  111. package/lib/typescript/core/mixins/OxyServices.assets.d.ts +7 -1
  112. package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -1
  113. package/lib/typescript/core/mixins/OxyServices.user.d.ts +4 -5
  114. package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
  115. package/lib/typescript/core/mixins/index.d.ts +1 -1
  116. package/lib/typescript/core/mixins/index.d.ts.map +1 -1
  117. package/lib/typescript/crypto/keyManager.d.ts +19 -2
  118. package/lib/typescript/crypto/keyManager.d.ts.map +1 -1
  119. package/lib/typescript/crypto/signatureService.d.ts +5 -0
  120. package/lib/typescript/crypto/signatureService.d.ts.map +1 -1
  121. package/lib/typescript/index.d.ts +1 -1
  122. package/lib/typescript/index.d.ts.map +1 -1
  123. package/lib/typescript/models/interfaces.d.ts +21 -0
  124. package/lib/typescript/models/interfaces.d.ts.map +1 -1
  125. package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
  126. package/lib/typescript/ui/components/profile/EditDisplayNameModal.d.ts.map +1 -1
  127. package/lib/typescript/ui/context/OxyContext.d.ts +4 -0
  128. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  129. package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  130. package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts +3 -1
  131. package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts.map +1 -1
  132. package/lib/typescript/ui/hooks/mutations/index.d.ts +3 -0
  133. package/lib/typescript/ui/hooks/mutations/index.d.ts.map +1 -0
  134. package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts +25 -0
  135. package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -0
  136. package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts +23 -0
  137. package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -0
  138. package/lib/typescript/ui/hooks/queries/index.d.ts +4 -0
  139. package/lib/typescript/ui/hooks/queries/index.d.ts.map +1 -0
  140. package/lib/typescript/ui/hooks/queries/queryKeys.d.ts +56 -0
  141. package/lib/typescript/ui/hooks/queries/queryKeys.d.ts.map +1 -0
  142. package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts +41 -0
  143. package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -0
  144. package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts +34 -0
  145. package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts.map +1 -0
  146. package/lib/typescript/ui/hooks/queryClient.d.ts +19 -0
  147. package/lib/typescript/ui/hooks/queryClient.d.ts.map +1 -0
  148. package/lib/typescript/ui/hooks/useIdentityMutations.d.ts +29 -0
  149. package/lib/typescript/ui/hooks/useIdentityMutations.d.ts.map +1 -0
  150. package/lib/typescript/ui/hooks/useProfileEditing.d.ts.map +1 -1
  151. package/lib/typescript/ui/hooks/useQueryClient.d.ts +7 -0
  152. package/lib/typescript/ui/hooks/useQueryClient.d.ts.map +1 -0
  153. package/lib/typescript/ui/hooks/useSessionManagement.d.ts +3 -1
  154. package/lib/typescript/ui/hooks/useSessionManagement.d.ts.map +1 -1
  155. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -1
  156. package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
  157. package/lib/typescript/ui/screens/WelcomeNewUserScreen.d.ts.map +1 -1
  158. package/lib/typescript/ui/stores/accountStore.d.ts.map +1 -1
  159. package/lib/typescript/ui/stores/authStore.d.ts +0 -4
  160. package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
  161. package/package.json +6 -5
  162. package/src/core/mixins/OxyServices.assets.ts +16 -1
  163. package/src/core/mixins/OxyServices.user.ts +17 -10
  164. package/src/crypto/keyManager.ts +177 -2
  165. package/src/crypto/signatureService.ts +30 -0
  166. package/src/index.ts +4 -1
  167. package/src/models/interfaces.ts +23 -0
  168. package/src/ui/components/GroupedSection.tsx +1 -1
  169. package/src/ui/components/OxyProvider.tsx +91 -37
  170. package/src/ui/components/profile/EditDisplayNameModal.tsx +1 -3
  171. package/src/ui/context/OxyContext.tsx +185 -2
  172. package/src/ui/context/hooks/useAuthOperations.ts +171 -58
  173. package/src/ui/context/hooks/useSessionManagement.ts +24 -1
  174. package/src/ui/hooks/mutations/index.ts +4 -0
  175. package/src/ui/hooks/mutations/useAccountMutations.ts +277 -0
  176. package/src/ui/hooks/mutations/useServicesMutations.ts +164 -0
  177. package/src/ui/hooks/queries/index.ts +5 -0
  178. package/src/ui/hooks/queries/queryKeys.ts +73 -0
  179. package/src/ui/hooks/queries/useAccountQueries.ts +126 -0
  180. package/src/ui/hooks/queries/useServicesQueries.ts +121 -0
  181. package/src/ui/hooks/queryClient.ts +112 -0
  182. package/src/ui/hooks/useIdentityMutations.ts +115 -0
  183. package/src/ui/hooks/useProfileEditing.ts +46 -60
  184. package/src/ui/hooks/useQueryClient.ts +17 -0
  185. package/src/ui/hooks/useSessionManagement.ts +24 -1
  186. package/src/ui/screens/AccountOverviewScreen.tsx +38 -46
  187. package/src/ui/screens/AccountSettingsScreen.tsx +54 -54
  188. package/src/ui/screens/WelcomeNewUserScreen.tsx +13 -12
  189. package/src/ui/stores/accountStore.ts +54 -43
  190. package/src/ui/stores/authStore.ts +3 -17
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ import { useQuery, useQueries } from '@tanstack/react-query';
4
+ import { queryKeys } from './queryKeys';
5
+ import { useOxy } from '../../context/OxyContext';
6
+
7
+ /**
8
+ * Get user profile by session ID
9
+ */
10
+ export const useUserProfile = (sessionId, options) => {
11
+ const {
12
+ oxyServices
13
+ } = useOxy();
14
+ return useQuery({
15
+ queryKey: queryKeys.users.profile(sessionId || ''),
16
+ queryFn: async () => {
17
+ if (!sessionId) {
18
+ throw new Error('Session ID is required');
19
+ }
20
+ return await oxyServices.getUserBySession(sessionId);
21
+ },
22
+ enabled: options?.enabled !== false && !!sessionId,
23
+ staleTime: 5 * 60 * 1000,
24
+ // 5 minutes
25
+ gcTime: 30 * 60 * 1000 // 30 minutes
26
+ });
27
+ };
28
+
29
+ /**
30
+ * Get multiple user profiles by session IDs (batch query)
31
+ */
32
+ export const useUserProfiles = (sessionIds, options) => {
33
+ const {
34
+ oxyServices
35
+ } = useOxy();
36
+ return useQueries({
37
+ queries: sessionIds.map(sessionId => ({
38
+ queryKey: queryKeys.users.profile(sessionId),
39
+ queryFn: async () => {
40
+ const results = await oxyServices.getUsersBySessions([sessionId]);
41
+ return results[0]?.user || null;
42
+ },
43
+ enabled: options?.enabled !== false && !!sessionId,
44
+ staleTime: 5 * 60 * 1000,
45
+ gcTime: 30 * 60 * 1000
46
+ }))
47
+ });
48
+ };
49
+
50
+ /**
51
+ * Get current authenticated user
52
+ */
53
+ export const useCurrentUser = options => {
54
+ const {
55
+ oxyServices,
56
+ activeSessionId,
57
+ isAuthenticated
58
+ } = useOxy();
59
+ return useQuery({
60
+ queryKey: queryKeys.accounts.current(),
61
+ queryFn: async () => {
62
+ if (!activeSessionId) {
63
+ throw new Error('No active session');
64
+ }
65
+ return await oxyServices.getUserBySession(activeSessionId);
66
+ },
67
+ enabled: options?.enabled !== false && isAuthenticated && !!activeSessionId,
68
+ staleTime: 1 * 60 * 1000,
69
+ // 1 minute for current user
70
+ gcTime: 30 * 60 * 1000
71
+ });
72
+ };
73
+
74
+ /**
75
+ * Get user by ID
76
+ */
77
+ export const useUserById = (userId, options) => {
78
+ const {
79
+ oxyServices
80
+ } = useOxy();
81
+ return useQuery({
82
+ queryKey: queryKeys.users.detail(userId || ''),
83
+ queryFn: async () => {
84
+ if (!userId) {
85
+ throw new Error('User ID is required');
86
+ }
87
+ return await oxyServices.getUserById(userId);
88
+ },
89
+ enabled: options?.enabled !== false && !!userId,
90
+ staleTime: 5 * 60 * 1000,
91
+ gcTime: 30 * 60 * 1000
92
+ });
93
+ };
94
+
95
+ /**
96
+ * Get user profile by username
97
+ */
98
+ export const useUserByUsername = (username, options) => {
99
+ const {
100
+ oxyServices
101
+ } = useOxy();
102
+ return useQuery({
103
+ queryKey: [...queryKeys.users.details(), 'username', username || ''],
104
+ queryFn: async () => {
105
+ if (!username) {
106
+ throw new Error('Username is required');
107
+ }
108
+ return await oxyServices.getProfileByUsername(username);
109
+ },
110
+ enabled: options?.enabled !== false && !!username,
111
+ staleTime: 5 * 60 * 1000,
112
+ gcTime: 30 * 60 * 1000
113
+ });
114
+ };
115
+
116
+ /**
117
+ * Batch get users by session IDs (optimized single API call)
118
+ */
119
+ export const useUsersBySessions = (sessionIds, options) => {
120
+ const {
121
+ oxyServices
122
+ } = useOxy();
123
+ return useQuery({
124
+ queryKey: queryKeys.accounts.list(sessionIds),
125
+ queryFn: async () => {
126
+ if (sessionIds.length === 0) {
127
+ return [];
128
+ }
129
+ return await oxyServices.getUsersBySessions(sessionIds);
130
+ },
131
+ enabled: options?.enabled !== false && sessionIds.length > 0,
132
+ staleTime: 5 * 60 * 1000,
133
+ gcTime: 30 * 60 * 1000
134
+ });
135
+ };
136
+ //# sourceMappingURL=useAccountQueries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useQuery","useQueries","queryKeys","useOxy","useUserProfile","sessionId","options","oxyServices","queryKey","users","profile","queryFn","Error","getUserBySession","enabled","staleTime","gcTime","useUserProfiles","sessionIds","queries","map","results","getUsersBySessions","user","useCurrentUser","activeSessionId","isAuthenticated","accounts","current","useUserById","userId","detail","getUserById","useUserByUsername","username","details","getProfileByUsername","useUsersBySessions","list","length"],"sourceRoot":"../../../../../src","sources":["ui/hooks/queries/useAccountQueries.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,UAAU,QAAQ,uBAAuB;AAG5D,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,MAAM,QAAQ,0BAA0B;;AAEjD;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAGA,CAACC,SAAwB,EAAEC,OAA+B,KAAK;EAC3F,MAAM;IAAEC;EAAY,CAAC,GAAGJ,MAAM,CAAC,CAAC;EAEhC,OAAOH,QAAQ,CAAC;IACdQ,QAAQ,EAAEN,SAAS,CAACO,KAAK,CAACC,OAAO,CAACL,SAAS,IAAI,EAAE,CAAC;IAClDM,OAAO,EAAE,MAAAA,CAAA,KAAY;MACnB,IAAI,CAACN,SAAS,EAAE;QACd,MAAM,IAAIO,KAAK,CAAC,wBAAwB,CAAC;MAC3C;MACA,OAAO,MAAML,WAAW,CAACM,gBAAgB,CAACR,SAAS,CAAC;IACtD,CAAC;IACDS,OAAO,EAAGR,OAAO,EAAEQ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,IAAI,EAAE,CAAC;IACpEvB,OAAO,EAAE,MAAAA,CAAA,KAAY;MACnB,IAAI,CAACuB,QAAQ,EAAE;QACb,MAAM,IAAItB,KAAK,CAAC,sBAAsB,CAAC;MACzC;MACA,OAAO,MAAML,WAAW,CAAC6B,oBAAoB,CAACF,QAAQ,CAAC;IACzD,CAAC;IACDpB,OAAO,EAAGR,OAAO,EAAEQ,OAAO,KAAK,KAAK,IAAK,CAAC,CAACoB,QAAQ;IACnDnB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IACxBC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG;EACpB,CAAC,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMqB,kBAAkB,GAAGA,CAACnB,UAAoB,EAAEZ,OAA+B,KAAK;EAC3F,MAAM;IAAEC;EAAY,CAAC,GAAGJ,MAAM,CAAC,CAAC;EAEhC,OAAOH,QAAQ,CAAC;IACdQ,QAAQ,EAAEN,SAAS,CAACyB,QAAQ,CAACW,IAAI,CAACpB,UAAU,CAAC;IAC7CP,OAAO,EAAE,MAAAA,CAAA,KAAY;MACnB,IAAIO,UAAU,CAACqB,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,EAAE;MACX;MACA,OAAO,MAAMhC,WAAW,CAACe,kBAAkB,CAACJ,UAAU,CAAC;IACzD,CAAC;IACDJ,OAAO,EAAGR,OAAO,EAAEQ,OAAO,KAAK,KAAK,IAAKI,UAAU,CAACqB,MAAM,GAAG,CAAC;IAC9DxB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IACxBC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG;EACpB,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ import { useQuery } from '@tanstack/react-query';
4
+ import { queryKeys } from './queryKeys';
5
+ import { useOxy } from '../../context/OxyContext';
6
+ import { fetchSessionsWithFallback, mapSessionsToClient } from '../../context/utils/sessionHelpers';
7
+
8
+ /**
9
+ * Get all active sessions for the current user
10
+ */
11
+ export const useSessions = (userId, options) => {
12
+ const {
13
+ oxyServices,
14
+ activeSessionId
15
+ } = useOxy();
16
+ return useQuery({
17
+ queryKey: queryKeys.sessions.list(userId),
18
+ queryFn: async () => {
19
+ if (!activeSessionId) {
20
+ throw new Error('No active session');
21
+ }
22
+ const sessions = await fetchSessionsWithFallback(oxyServices, activeSessionId, {
23
+ fallbackDeviceId: undefined,
24
+ fallbackUserId: userId
25
+ });
26
+ return mapSessionsToClient(sessions, activeSessionId);
27
+ },
28
+ enabled: options?.enabled !== false && !!activeSessionId,
29
+ staleTime: 2 * 60 * 1000,
30
+ // 2 minutes (sessions change frequently)
31
+ gcTime: 10 * 60 * 1000 // 10 minutes
32
+ });
33
+ };
34
+
35
+ /**
36
+ * Get specific session by ID
37
+ */
38
+ export const useSession = (sessionId, options) => {
39
+ const {
40
+ oxyServices
41
+ } = useOxy();
42
+ return useQuery({
43
+ queryKey: queryKeys.sessions.detail(sessionId || ''),
44
+ queryFn: async () => {
45
+ if (!sessionId) {
46
+ throw new Error('Session ID is required');
47
+ }
48
+ const validation = await oxyServices.validateSession(sessionId, {
49
+ useHeaderValidation: true
50
+ });
51
+ if (!validation?.valid || !validation.user) {
52
+ throw new Error('Session not found or invalid');
53
+ }
54
+ const now = new Date();
55
+ return {
56
+ sessionId,
57
+ deviceId: '',
58
+ // Device ID not available from validation response
59
+ expiresAt: validation.expiresAt || new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000).toISOString(),
60
+ lastActive: validation.lastActivity || now.toISOString(),
61
+ userId: validation.user.id?.toString() ?? '',
62
+ isCurrent: false
63
+ };
64
+ },
65
+ enabled: options?.enabled !== false && !!sessionId,
66
+ staleTime: 2 * 60 * 1000,
67
+ gcTime: 10 * 60 * 1000
68
+ });
69
+ };
70
+
71
+ /**
72
+ * Get device sessions for the current active session
73
+ */
74
+ export const useDeviceSessions = options => {
75
+ const {
76
+ oxyServices,
77
+ activeSessionId
78
+ } = useOxy();
79
+ return useQuery({
80
+ queryKey: queryKeys.sessions.active(),
81
+ queryFn: async () => {
82
+ if (!activeSessionId) {
83
+ throw new Error('No active session');
84
+ }
85
+ return await oxyServices.getDeviceSessions(activeSessionId);
86
+ },
87
+ enabled: options?.enabled !== false && !!activeSessionId,
88
+ staleTime: 2 * 60 * 1000,
89
+ gcTime: 10 * 60 * 1000
90
+ });
91
+ };
92
+
93
+ /**
94
+ * Get user devices
95
+ */
96
+ export const useUserDevices = options => {
97
+ const {
98
+ oxyServices,
99
+ isAuthenticated
100
+ } = useOxy();
101
+ return useQuery({
102
+ queryKey: queryKeys.devices.list(),
103
+ queryFn: async () => {
104
+ return await oxyServices.getUserDevices();
105
+ },
106
+ enabled: options?.enabled !== false && isAuthenticated,
107
+ staleTime: 5 * 60 * 1000,
108
+ gcTime: 30 * 60 * 1000
109
+ });
110
+ };
111
+
112
+ /**
113
+ * Get security information
114
+ */
115
+ export const useSecurityInfo = options => {
116
+ const {
117
+ oxyServices,
118
+ isAuthenticated
119
+ } = useOxy();
120
+ return useQuery({
121
+ queryKey: [...queryKeys.devices.all, 'security'],
122
+ queryFn: async () => {
123
+ return await oxyServices.getSecurityInfo();
124
+ },
125
+ enabled: options?.enabled !== false && isAuthenticated,
126
+ staleTime: 5 * 60 * 1000,
127
+ gcTime: 30 * 60 * 1000
128
+ });
129
+ };
130
+ //# sourceMappingURL=useServicesQueries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useQuery","queryKeys","useOxy","fetchSessionsWithFallback","mapSessionsToClient","useSessions","userId","options","oxyServices","activeSessionId","queryKey","sessions","list","queryFn","Error","fallbackDeviceId","undefined","fallbackUserId","enabled","staleTime","gcTime","useSession","sessionId","detail","validation","validateSession","useHeaderValidation","valid","user","now","Date","deviceId","expiresAt","getTime","toISOString","lastActive","lastActivity","id","toString","isCurrent","useDeviceSessions","active","getDeviceSessions","useUserDevices","isAuthenticated","devices","getUser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AAO,CAACG,GAAG,EAAE,UAAU,CAAC;IAChDnC,OAAO,EAAE,MAAAA,CAAA,KAAY;MACnB,OAAO,MAAML,WAAW,CAACyC,eAAe,CAAC,CAAC;IAC5C,CAAC;IACD/B,OAAO,EAAGX,OAAO,EAAEW,OAAO,KAAK,KAAK,IAAK0B,eAAe;IACxDzB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IACxBC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG;EACpB,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ const QUERY_CACHE_KEY = 'oxy_query_cache';
5
+ const QUERY_CACHE_VERSION = '1';
6
+
7
+ /**
8
+ * Custom persistence adapter for TanStack Query using our StorageInterface
9
+ */
10
+ export const createPersistenceAdapter = storage => {
11
+ return {
12
+ persistClient: async client => {
13
+ try {
14
+ const serialized = JSON.stringify({
15
+ clientState: client,
16
+ timestamp: Date.now(),
17
+ version: QUERY_CACHE_VERSION
18
+ });
19
+ await storage.setItem(QUERY_CACHE_KEY, serialized);
20
+ } catch (error) {
21
+ if (__DEV__) {
22
+ console.warn('[QueryClient] Failed to persist cache:', error);
23
+ }
24
+ }
25
+ },
26
+ restoreClient: async () => {
27
+ try {
28
+ const cached = await storage.getItem(QUERY_CACHE_KEY);
29
+ if (!cached) return undefined;
30
+ const parsed = JSON.parse(cached);
31
+
32
+ // Check version compatibility
33
+ if (parsed.version !== QUERY_CACHE_VERSION) {
34
+ // Clear old cache on version mismatch
35
+ await storage.removeItem(QUERY_CACHE_KEY);
36
+ return undefined;
37
+ }
38
+
39
+ // Check if cache is too old (30 days)
40
+ const maxAge = 30 * 24 * 60 * 60 * 1000;
41
+ if (parsed.timestamp && Date.now() - parsed.timestamp > maxAge) {
42
+ await storage.removeItem(QUERY_CACHE_KEY);
43
+ return undefined;
44
+ }
45
+ return parsed.clientState;
46
+ } catch (error) {
47
+ if (__DEV__) {
48
+ console.warn('[QueryClient] Failed to restore cache:', error);
49
+ }
50
+ return undefined;
51
+ }
52
+ },
53
+ removeClient: async () => {
54
+ try {
55
+ await storage.removeItem(QUERY_CACHE_KEY);
56
+ } catch (error) {
57
+ if (__DEV__) {
58
+ console.warn('[QueryClient] Failed to remove cache:', error);
59
+ }
60
+ }
61
+ }
62
+ };
63
+ };
64
+
65
+ /**
66
+ * Create a QueryClient with offline-first configuration
67
+ */
68
+ export const createQueryClient = storage => {
69
+ const client = new QueryClient({
70
+ defaultOptions: {
71
+ queries: {
72
+ // Data is fresh for 5 minutes
73
+ staleTime: 5 * 60 * 1000,
74
+ // Keep unused data in cache for 30 minutes
75
+ gcTime: 30 * 60 * 1000,
76
+ // Retry 3 times with exponential backoff
77
+ retry: 3,
78
+ retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, 30000),
79
+ // Refetch on reconnect
80
+ refetchOnReconnect: true,
81
+ // Don't refetch on window focus (better for mobile)
82
+ refetchOnWindowFocus: false,
83
+ // Offline-first: use cache when offline
84
+ networkMode: 'offlineFirst'
85
+ },
86
+ mutations: {
87
+ // Retry once for mutations
88
+ retry: 1,
89
+ // Offline-first: queue mutations when offline
90
+ networkMode: 'offlineFirst'
91
+ }
92
+ }
93
+ });
94
+
95
+ // Note: Persistence is handled by TanStack Query's built-in persistence
96
+ // For now, we rely on the query client's default behavior with networkMode: 'offlineFirst'
97
+ // The cache will be available in memory and queries will use cached data when offline
98
+ // Full persistence to AsyncStorage can be added later with @tanstack/react-query-persist-client if needed
99
+
100
+ return client;
101
+ };
102
+
103
+ /**
104
+ * Clear persisted query cache
105
+ */
106
+ export const clearQueryCache = async storage => {
107
+ const adapter = createPersistenceAdapter(storage);
108
+ await adapter.removeClient();
109
+ };
110
+ //# sourceMappingURL=queryClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["QueryClient","QUERY_CACHE_KEY","QUERY_CACHE_VERSION","createPersistenceAdapter","storage","persistClient","client","serialized","JSON","stringify","clientState","timestamp","Date","now","version","setItem","error","__DEV__","console","warn","restoreClient","cached","getItem","undefined","parsed","parse","removeItem","maxAge","removeClient","createQueryClient","defaultOptions","queries","staleTime","gcTime","retry","retryDelay","attemptIndex","Math","min","refetchOnReconnect","refetchOnWindowFocus","networkMode","mutations","clearQueryCache","adapter"],"sourceRoot":"../../../../src","sources":["ui/hooks/queryClient.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,uBAAuB;AAGnD,MAAMC,eAAe,GAAG,iBAAiB;AACzC,MAAMC,mBAAmB,GAAG,GAAG;;AAE/B;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAIC,OAAyB,IAAK;EACrE,OAAO;IACLC,aAAa,EAAE,MAAOC,MAAW,IAAK;MACpC,IAAI;QACF,MAAMC,UAAU,GAAGC,IAAI,CAACC,SAAS,CAAC;UAChCC,WAAW,EAAEJ,MAAM;UACnBK,SAAS,EAAEC,IAAI,CAACC,GAAG,CAAC,CAAC;UACrBC,OAAO,EAAEZ;QACX,CAAC,CAAC;QACF,MAAME,OAAO,CAACW,OAAO,CAACd,eAAe,EAAEM,UAAU,CAAC;MACpD,CAAC,CAAC,OAAOS,KAAK,EAAE;QACd,IAAIC,OAAO,EAAE;UACXC,OAAO,CAACC,IAAI,CAAC,wCAAwC,EAAEH,KAAK,CAAC;QAC/D;MACF;IACF,CAAC;IACDI,aAAa,EAAE,MAAAA,CAAA,KAAY;MACzB,IAAI;QACF,MAAMC,MAAM,GAAG,MAAMjB,OAAO,CAACkB,OAAO,CAACrB,eAAe,CAAC;QACrD,IAAI,CAACoB,MAAM,EAAE,OAAOE,SAAS;QAE7B,MAAMC,MAAM,GAAGhB,IAAI,CAACiB,KAAK,CAACJ,MAAM,CAAC;;QAEjC;QACA,IAAIG,MAAM,CAACV,OAAO,KAAKZ,mBAAmB,EAAE;UAC1C;UACA,MAAME,OAAO,CAACsB,UAAU,CAACzB,eAAe,CAAC;UACzC,OAAOsB,SAAS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;MACDC,SAAS,EAAE;QACT;QACAR,KAAK,EAAE,CAAC;QACR;QACAO,WAAW,EAAE;MACf;IACF;EACF,CAAC,CAAC;;EAEF;EACA;EACA;EACA;;EAEA,OAAOnC,MAAM;AACf,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMqC,eAAe,GAAG,MAAOvC,OAAyB,IAAoB;EACjF,MAAMwC,OAAO,GAAGzC,wBAAwB,CAACC,OAAO,CAAC;EACjD,MAAMwC,OAAO,CAAChB,YAAY,CAAC,CAAC;AAC9B,CAAC","ignoreList":[]}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * TanStack Query mutations for identity operations
5
+ * Provides offline-first mutations for identity creation, import, and sync
6
+ * Never deletes identity on errors - preserves user data
7
+ */
8
+
9
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
10
+ /**
11
+ * Hook for creating a new identity with offline support
12
+ * Never deletes identity on error - preserves user data
13
+ */
14
+ export function useCreateIdentity(createIdentityFn) {
15
+ const queryClient = useQueryClient();
16
+ return useMutation({
17
+ mutationFn: createIdentityFn,
18
+ onSuccess: data => {
19
+ // Invalidate user queries to refetch after identity creation
20
+ queryClient.invalidateQueries({
21
+ queryKey: ['user']
22
+ });
23
+ queryClient.invalidateQueries({
24
+ queryKey: ['identity']
25
+ });
26
+ },
27
+ onError: error => {
28
+ // Never delete identity on error - just log it
29
+ // User can recover using recovery phrase
30
+ if (__DEV__) {
31
+ console.warn('[useCreateIdentity] Identity creation error (identity may still exist):', error);
32
+ }
33
+ },
34
+ retry: false,
35
+ // Don't retry identity creation
36
+ networkMode: 'offlineFirst'
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Hook for importing an identity from recovery phrase
42
+ * Never deletes identity on error - preserves user data
43
+ */
44
+ export function useImportIdentity(importIdentityFn) {
45
+ const queryClient = useQueryClient();
46
+ return useMutation({
47
+ mutationFn: importIdentityFn,
48
+ onSuccess: data => {
49
+ queryClient.invalidateQueries({
50
+ queryKey: ['user']
51
+ });
52
+ queryClient.invalidateQueries({
53
+ queryKey: ['identity']
54
+ });
55
+ },
56
+ onError: error => {
57
+ // Never delete identity on error - just log it
58
+ if (__DEV__) {
59
+ console.warn('[useImportIdentity] Identity import error (identity may still exist):', error);
60
+ }
61
+ },
62
+ retry: false,
63
+ networkMode: 'offlineFirst'
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Hook for syncing identity with server
69
+ * Never deletes identity on error - only logs and allows retry
70
+ */
71
+ export function useSyncIdentity(syncIdentityFn) {
72
+ const queryClient = useQueryClient();
73
+ return useMutation({
74
+ mutationFn: syncIdentityFn,
75
+ onSuccess: user => {
76
+ // Update user cache
77
+ queryClient.setQueryData(['user', 'current'], user);
78
+ queryClient.invalidateQueries({
79
+ queryKey: ['user']
80
+ });
81
+ queryClient.invalidateQueries({
82
+ queryKey: ['identity']
83
+ });
84
+ },
85
+ onError: error => {
86
+ // Never delete identity on error - just log it
87
+ // User can retry sync later or use recovery phrase
88
+ if (__DEV__) {
89
+ console.warn('[useSyncIdentity] Sync failed, but identity is preserved:', error);
90
+ }
91
+ },
92
+ retry: (failureCount, error) => {
93
+ // Retry up to 2 times for sync operations
94
+ // Don't retry if it's a network error - user can retry when online
95
+ const errorMessage = error instanceof Error ? error.message : String(error);
96
+ const isNetworkError = errorMessage.includes('Network') || errorMessage.includes('Failed to fetch') || error?.code === 'NETWORK_ERROR';
97
+ if (isNetworkError) {
98
+ return false; // Don't retry network errors - user will retry when online
99
+ }
100
+ return failureCount < 2;
101
+ },
102
+ networkMode: 'offlineFirst'
103
+ });
104
+ }
105
+ //# sourceMappingURL=useIdentityMutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMutation","useQueryClient","useCreateIdentity","createIdentityFn","queryClient","mutationFn","onSuccess","data","invalidateQueries","queryKey","onError","error","__DEV__","console","warn","retry","networkMode","useImportIdentity","importIdentityFn","useSyncIdentity","syncIdentityFn","user","setQueryData","failureCount","errorMessage","Error","message","String","isNetworkError","includes","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back } from 'react';
4
- import { useOxy } from '../context/OxyContext';
5
- import { useAuthStore } from '../stores/authStore';
6
- import { toast } from '../../lib/sonner';
3
+ import { useCallback } from 'react';
7
4
  import { useI18n } from './useI18n';
5
+ import { useUpdateProfile } from './mutations/useAccountMutations';
6
+ import { useAuthStore } from '../stores/authStore';
8
7
  /**
9
8
  * Hook for managing profile editing operations
10
9
  * Provides functions to update profile fields and handle saving
11
10
  */
12
11
  export const useProfileEditing = () => {
13
- const {
14
- oxyServices,
15
- activeSessionId
16
- } = useOxy();
17
- const updateUser = useAuthStore(state => state.updateUser);
18
12
  const {
19
13
  t
20
14
  } = useI18n();
21
- const [isSaving, setIsSaving] = useState(false);
15
+ const updateProfileMutation = useUpdateProfile();
22
16
 
23
17
  /**
24
- * Save profile updates to the server
18
+ * Save profile updates to the server using TanStack Query
25
19
  */
26
20
  const saveProfile = useCallback(async updates => {
27
- if (!oxyServices) {
28
- toast.error(t('editProfile.toasts.serviceUnavailable') || 'Service not available');
29
- return false;
21
+ // Prepare update object
22
+ const updateData = {};
23
+ if (updates.username !== undefined) {
24
+ updateData.username = updates.username;
30
25
  }
31
- try {
32
- setIsSaving(true);
33
-
34
- // Prepare update object
35
- const updateData = {};
36
- if (updates.username !== undefined) {
37
- updateData.username = updates.username;
38
- }
39
- if (updates.email !== undefined) {
40
- updateData.email = updates.email;
41
- }
42
- if (updates.bio !== undefined) {
43
- updateData.bio = updates.bio;
44
- }
45
- if (updates.location !== undefined || updates.locations !== undefined) {
46
- updateData.location = updates.locations && updates.locations.length > 0 ? updates.locations[0].name : updates.location || '';
47
- if (updates.locations) {
48
- updateData.locations = updates.locations;
49
- }
50
- }
51
- if (updates.links !== undefined) {
52
- updateData.links = updates.links;
53
- }
54
- if (updates.linksMetadata !== undefined) {
55
- updateData.linksMetadata = updates.linksMetadata;
56
- }
57
- if (updates.avatar !== undefined) {
58
- updateData.avatar = updates.avatar;
26
+ if (updates.email !== undefined) {
27
+ updateData.email = updates.email;
28
+ }
29
+ if (updates.bio !== undefined) {
30
+ updateData.bio = updates.bio;
31
+ }
32
+ if (updates.location !== undefined || updates.locations !== undefined) {
33
+ updateData.location = updates.locations && updates.locations.length > 0 ? updates.locations[0].name : updates.location || '';
34
+ if (updates.locations) {
35
+ updateData.locations = updates.locations;
59
36
  }
37
+ }
38
+ if (updates.links !== undefined) {
39
+ updateData.links = updates.links;
40
+ }
41
+ if (updates.linksMetadata !== undefined) {
42
+ updateData.linksMetadata = updates.linksMetadata;
43
+ }
44
+ if (updates.avatar !== undefined) {
45
+ updateData.avatar = updates.avatar;
46
+ }
60
47
 
61
- // Handle name field
62
- if (updates.displayName !== undefined || updates.lastName !== undefined) {
63
- const currentUser = useAuthStore.getState().user;
64
- const currentName = currentUser?.name;
65
- updateData.name = {
66
- first: updates.displayName ?? (typeof currentName === 'object' ? currentName?.first : '') ?? '',
67
- last: updates.lastName ?? (typeof currentName === 'object' ? currentName?.last : '') ?? ''
68
- };
69
- }
70
- await updateUser(updateData, oxyServices);
71
- toast.success(t('editProfile.toasts.profileUpdated') || 'Profile updated successfully');
48
+ // Handle name field
49
+ if (updates.displayName !== undefined || updates.lastName !== undefined) {
50
+ const currentUser = useAuthStore.getState().user;
51
+ const currentName = currentUser?.name;
52
+ updateData.name = {
53
+ first: updates.displayName ?? (typeof currentName === 'object' ? currentName?.first : '') ?? '',
54
+ last: updates.lastName ?? (typeof currentName === 'object' ? currentName?.last : '') ?? ''
55
+ };
56
+ }
57
+ try {
58
+ await updateProfileMutation.mutateAsync(updateData);
72
59
  return true;
73
60
  } catch (error) {
74
- console.error('Failed to update profile:', error);
75
- toast.error(error?.message || t('editProfile.toasts.updateFailed') || 'Failed to update profile');
61
+ // Error toast is handled by the mutation
76
62
  return false;
77
- } finally {
78
- setIsSaving(false);
79
63
  }
80
- }, [oxyServices, updateUser, t]);
64
+ }, [updateProfileMutation, t]);
81
65
 
82
66
  /**
83
67
  * Update a single profile field
@@ -112,7 +96,7 @@ export const useProfileEditing = () => {
112
96
  return {
113
97
  saveProfile,
114
98
  updateField,
115
- isSaving
99
+ isSaving: updateProfileMutation.isPending
116
100
  };
117
101
  };
118
102
  //# sourceMappingURL=useProfileEditing.js.map