@oxyhq/services 5.16.1 → 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 (175) hide show
  1. package/lib/commonjs/core/mixins/OxyServices.user.js +14 -13
  2. package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -1
  3. package/lib/commonjs/crypto/keyManager.js +164 -3
  4. package/lib/commonjs/crypto/keyManager.js.map +1 -1
  5. package/lib/commonjs/crypto/signatureService.js +26 -0
  6. package/lib/commonjs/crypto/signatureService.js.map +1 -1
  7. package/lib/commonjs/ui/components/GroupedSection.js +1 -1
  8. package/lib/commonjs/ui/components/GroupedSection.js.map +1 -1
  9. package/lib/commonjs/ui/components/OxyProvider.js +71 -24
  10. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  11. package/lib/commonjs/ui/components/profile/EditDisplayNameModal.js +1 -4
  12. package/lib/commonjs/ui/components/profile/EditDisplayNameModal.js.map +1 -1
  13. package/lib/commonjs/ui/context/OxyContext.js +177 -4
  14. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  15. package/lib/commonjs/ui/context/hooks/useAuthOperations.js +148 -49
  16. package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
  17. package/lib/commonjs/ui/context/hooks/useSessionManagement.js +22 -2
  18. package/lib/commonjs/ui/context/hooks/useSessionManagement.js.map +1 -1
  19. package/lib/commonjs/ui/hooks/mutations/index.js +28 -0
  20. package/lib/commonjs/ui/hooks/mutations/index.js.map +1 -0
  21. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +314 -0
  22. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -0
  23. package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js +193 -0
  24. package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js.map +1 -0
  25. package/lib/commonjs/ui/hooks/queries/index.js +39 -0
  26. package/lib/commonjs/ui/hooks/queries/index.js.map +1 -0
  27. package/lib/commonjs/ui/hooks/queries/queryKeys.js +85 -0
  28. package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -0
  29. package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +145 -0
  30. package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -0
  31. package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +138 -0
  32. package/lib/commonjs/ui/hooks/queries/useServicesQueries.js.map +1 -0
  33. package/lib/commonjs/ui/hooks/queryClient.js +117 -0
  34. package/lib/commonjs/ui/hooks/queryClient.js.map +1 -0
  35. package/lib/commonjs/ui/hooks/useIdentityMutations.js +111 -0
  36. package/lib/commonjs/ui/hooks/useIdentityMutations.js.map +1 -0
  37. package/lib/commonjs/ui/hooks/useProfileEditing.js +42 -58
  38. package/lib/commonjs/ui/hooks/useProfileEditing.js.map +1 -1
  39. package/lib/commonjs/ui/hooks/useQueryClient.js +20 -0
  40. package/lib/commonjs/ui/hooks/useQueryClient.js.map +1 -0
  41. package/lib/commonjs/ui/hooks/useSessionManagement.js +22 -2
  42. package/lib/commonjs/ui/hooks/useSessionManagement.js.map +1 -1
  43. package/lib/commonjs/ui/screens/AccountOverviewScreen.js +43 -42
  44. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
  45. package/lib/commonjs/ui/screens/AccountSettingsScreen.js +63 -58
  46. package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
  47. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js +6 -6
  48. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  49. package/lib/commonjs/ui/stores/accountStore.js +57 -42
  50. package/lib/commonjs/ui/stores/accountStore.js.map +1 -1
  51. package/lib/commonjs/ui/stores/authStore.js +4 -25
  52. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  53. package/lib/module/core/mixins/OxyServices.user.js +14 -13
  54. package/lib/module/core/mixins/OxyServices.user.js.map +1 -1
  55. package/lib/module/crypto/keyManager.js +164 -3
  56. package/lib/module/crypto/keyManager.js.map +1 -1
  57. package/lib/module/crypto/signatureService.js +26 -0
  58. package/lib/module/crypto/signatureService.js.map +1 -1
  59. package/lib/module/ui/components/GroupedSection.js +1 -1
  60. package/lib/module/ui/components/GroupedSection.js.map +1 -1
  61. package/lib/module/ui/components/OxyProvider.js +72 -25
  62. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  63. package/lib/module/ui/components/profile/EditDisplayNameModal.js +1 -4
  64. package/lib/module/ui/components/profile/EditDisplayNameModal.js.map +1 -1
  65. package/lib/module/ui/context/OxyContext.js +176 -4
  66. package/lib/module/ui/context/OxyContext.js.map +1 -1
  67. package/lib/module/ui/context/hooks/useAuthOperations.js +148 -49
  68. package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
  69. package/lib/module/ui/context/hooks/useSessionManagement.js +22 -2
  70. package/lib/module/ui/context/hooks/useSessionManagement.js.map +1 -1
  71. package/lib/module/ui/hooks/mutations/index.js +6 -0
  72. package/lib/module/ui/hooks/mutations/index.js.map +1 -0
  73. package/lib/module/ui/hooks/mutations/useAccountMutations.js +308 -0
  74. package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -0
  75. package/lib/module/ui/hooks/mutations/useServicesMutations.js +185 -0
  76. package/lib/module/ui/hooks/mutations/useServicesMutations.js.map +1 -0
  77. package/lib/module/ui/hooks/queries/index.js +7 -0
  78. package/lib/module/ui/hooks/queries/index.js.map +1 -0
  79. package/lib/module/ui/hooks/queries/queryKeys.js +78 -0
  80. package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -0
  81. package/lib/module/ui/hooks/queries/useAccountQueries.js +136 -0
  82. package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -0
  83. package/lib/module/ui/hooks/queries/useServicesQueries.js +130 -0
  84. package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -0
  85. package/lib/module/ui/hooks/queryClient.js +110 -0
  86. package/lib/module/ui/hooks/queryClient.js.map +1 -0
  87. package/lib/module/ui/hooks/useIdentityMutations.js +105 -0
  88. package/lib/module/ui/hooks/useIdentityMutations.js.map +1 -0
  89. package/lib/module/ui/hooks/useProfileEditing.js +43 -59
  90. package/lib/module/ui/hooks/useProfileEditing.js.map +1 -1
  91. package/lib/module/ui/hooks/useQueryClient.js +15 -0
  92. package/lib/module/ui/hooks/useQueryClient.js.map +1 -0
  93. package/lib/module/ui/hooks/useSessionManagement.js +22 -2
  94. package/lib/module/ui/hooks/useSessionManagement.js.map +1 -1
  95. package/lib/module/ui/screens/AccountOverviewScreen.js +43 -42
  96. package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
  97. package/lib/module/ui/screens/AccountSettingsScreen.js +63 -58
  98. package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
  99. package/lib/module/ui/screens/WelcomeNewUserScreen.js +6 -6
  100. package/lib/module/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  101. package/lib/module/ui/stores/accountStore.js +57 -42
  102. package/lib/module/ui/stores/accountStore.js.map +1 -1
  103. package/lib/module/ui/stores/authStore.js +4 -25
  104. package/lib/module/ui/stores/authStore.js.map +1 -1
  105. package/lib/typescript/core/mixins/OxyServices.user.d.ts +4 -5
  106. package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
  107. package/lib/typescript/core/mixins/index.d.ts +0 -1
  108. package/lib/typescript/core/mixins/index.d.ts.map +1 -1
  109. package/lib/typescript/crypto/keyManager.d.ts +19 -2
  110. package/lib/typescript/crypto/keyManager.d.ts.map +1 -1
  111. package/lib/typescript/crypto/signatureService.d.ts +5 -0
  112. package/lib/typescript/crypto/signatureService.d.ts.map +1 -1
  113. package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
  114. package/lib/typescript/ui/components/profile/EditDisplayNameModal.d.ts.map +1 -1
  115. package/lib/typescript/ui/context/OxyContext.d.ts +4 -0
  116. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  117. package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  118. package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts +3 -1
  119. package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts.map +1 -1
  120. package/lib/typescript/ui/hooks/mutations/index.d.ts +3 -0
  121. package/lib/typescript/ui/hooks/mutations/index.d.ts.map +1 -0
  122. package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts +25 -0
  123. package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -0
  124. package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts +23 -0
  125. package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -0
  126. package/lib/typescript/ui/hooks/queries/index.d.ts +4 -0
  127. package/lib/typescript/ui/hooks/queries/index.d.ts.map +1 -0
  128. package/lib/typescript/ui/hooks/queries/queryKeys.d.ts +56 -0
  129. package/lib/typescript/ui/hooks/queries/queryKeys.d.ts.map +1 -0
  130. package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts +41 -0
  131. package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -0
  132. package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts +34 -0
  133. package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts.map +1 -0
  134. package/lib/typescript/ui/hooks/queryClient.d.ts +19 -0
  135. package/lib/typescript/ui/hooks/queryClient.d.ts.map +1 -0
  136. package/lib/typescript/ui/hooks/useIdentityMutations.d.ts +29 -0
  137. package/lib/typescript/ui/hooks/useIdentityMutations.d.ts.map +1 -0
  138. package/lib/typescript/ui/hooks/useProfileEditing.d.ts.map +1 -1
  139. package/lib/typescript/ui/hooks/useQueryClient.d.ts +7 -0
  140. package/lib/typescript/ui/hooks/useQueryClient.d.ts.map +1 -0
  141. package/lib/typescript/ui/hooks/useSessionManagement.d.ts +3 -1
  142. package/lib/typescript/ui/hooks/useSessionManagement.d.ts.map +1 -1
  143. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -1
  144. package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
  145. package/lib/typescript/ui/screens/WelcomeNewUserScreen.d.ts.map +1 -1
  146. package/lib/typescript/ui/stores/accountStore.d.ts.map +1 -1
  147. package/lib/typescript/ui/stores/authStore.d.ts +0 -4
  148. package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
  149. package/package.json +5 -4
  150. package/src/core/mixins/OxyServices.user.ts +17 -10
  151. package/src/crypto/keyManager.ts +177 -2
  152. package/src/crypto/signatureService.ts +30 -0
  153. package/src/ui/components/GroupedSection.tsx +1 -1
  154. package/src/ui/components/OxyProvider.tsx +91 -37
  155. package/src/ui/components/profile/EditDisplayNameModal.tsx +1 -3
  156. package/src/ui/context/OxyContext.tsx +185 -2
  157. package/src/ui/context/hooks/useAuthOperations.ts +171 -58
  158. package/src/ui/context/hooks/useSessionManagement.ts +24 -1
  159. package/src/ui/hooks/mutations/index.ts +4 -0
  160. package/src/ui/hooks/mutations/useAccountMutations.ts +277 -0
  161. package/src/ui/hooks/mutations/useServicesMutations.ts +164 -0
  162. package/src/ui/hooks/queries/index.ts +5 -0
  163. package/src/ui/hooks/queries/queryKeys.ts +73 -0
  164. package/src/ui/hooks/queries/useAccountQueries.ts +126 -0
  165. package/src/ui/hooks/queries/useServicesQueries.ts +121 -0
  166. package/src/ui/hooks/queryClient.ts +112 -0
  167. package/src/ui/hooks/useIdentityMutations.ts +115 -0
  168. package/src/ui/hooks/useProfileEditing.ts +46 -60
  169. package/src/ui/hooks/useQueryClient.ts +17 -0
  170. package/src/ui/hooks/useSessionManagement.ts +24 -1
  171. package/src/ui/screens/AccountOverviewScreen.tsx +38 -46
  172. package/src/ui/screens/AccountSettingsScreen.tsx +54 -54
  173. package/src/ui/screens/WelcomeNewUserScreen.tsx +13 -12
  174. package/src/ui/stores/accountStore.ts +54 -43
  175. package/src/ui/stores/authStore.ts +3 -17
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import { queryKeys, invalidateAccountQueries, invalidateUserQueries } from '../queries/queryKeys';
5
+ import { useOxy } from '../../context/OxyContext';
6
+ import { toast } from '../../../lib/sonner';
7
+
8
+ /**
9
+ * Update user profile with optimistic updates and offline queue support
10
+ */
11
+ export const useUpdateProfile = () => {
12
+ const {
13
+ oxyServices,
14
+ activeSessionId,
15
+ user,
16
+ syncIdentity
17
+ } = useOxy();
18
+ const queryClient = useQueryClient();
19
+ return useMutation({
20
+ mutationFn: async updates => {
21
+ // Ensure we have a valid token before making the request
22
+ if (!oxyServices.hasValidToken() && activeSessionId) {
23
+ try {
24
+ // Try to get token for the session
25
+ await oxyServices.getTokenBySession(activeSessionId);
26
+ } catch (tokenError) {
27
+ // If getting token fails, might be an offline session - try syncing
28
+ const errorMessage = tokenError instanceof Error ? tokenError.message : String(tokenError);
29
+ if (errorMessage.includes('AUTH_REQUIRED_OFFLINE_SESSION') || errorMessage.includes('offline')) {
30
+ try {
31
+ await syncIdentity();
32
+ // Retry getting token after sync
33
+ await oxyServices.getTokenBySession(activeSessionId);
34
+ } catch (syncError) {
35
+ throw new Error('Session needs to be synced. Please try again.');
36
+ }
37
+ } else {
38
+ throw tokenError;
39
+ }
40
+ }
41
+ }
42
+ try {
43
+ return await oxyServices.updateProfile(updates);
44
+ } catch (error) {
45
+ const errorMessage = error?.message || '';
46
+ const status = error?.status || error?.response?.status;
47
+
48
+ // Handle authentication errors
49
+ if (status === 401 || errorMessage.includes('Authentication required') || errorMessage.includes('Invalid or missing authorization header')) {
50
+ // Try to sync session and get token
51
+ if (activeSessionId) {
52
+ try {
53
+ await syncIdentity();
54
+ await oxyServices.getTokenBySession(activeSessionId);
55
+ // Retry the update after getting token
56
+ return await oxyServices.updateProfile(updates);
57
+ } catch (retryError) {
58
+ throw new Error('Authentication failed. Please sign in again.');
59
+ }
60
+ } else {
61
+ throw new Error('No active session. Please sign in.');
62
+ }
63
+ }
64
+
65
+ // TanStack Query will automatically retry on network errors
66
+ throw error;
67
+ }
68
+ },
69
+ // Optimistic update
70
+ onMutate: async updates => {
71
+ // Cancel outgoing refetches
72
+ await queryClient.cancelQueries({
73
+ queryKey: queryKeys.accounts.current()
74
+ });
75
+
76
+ // Snapshot previous value
77
+ const previousUser = queryClient.getQueryData(queryKeys.accounts.current());
78
+
79
+ // Optimistically update
80
+ if (previousUser) {
81
+ queryClient.setQueryData(queryKeys.accounts.current(), {
82
+ ...previousUser,
83
+ ...updates
84
+ });
85
+
86
+ // Also update profile query if sessionId is available
87
+ if (activeSessionId) {
88
+ queryClient.setQueryData(queryKeys.users.profile(activeSessionId), {
89
+ ...previousUser,
90
+ ...updates
91
+ });
92
+ }
93
+ }
94
+ return {
95
+ previousUser
96
+ };
97
+ },
98
+ // On error, rollback
99
+ onError: (error, updates, context) => {
100
+ if (context?.previousUser) {
101
+ queryClient.setQueryData(queryKeys.accounts.current(), context.previousUser);
102
+ if (activeSessionId) {
103
+ queryClient.setQueryData(queryKeys.users.profile(activeSessionId), context.previousUser);
104
+ }
105
+ }
106
+ toast.error(error instanceof Error ? error.message : 'Failed to update profile');
107
+ },
108
+ // On success, invalidate and refetch
109
+ onSuccess: data => {
110
+ // Update cache with server response
111
+ queryClient.setQueryData(queryKeys.accounts.current(), data);
112
+ if (activeSessionId) {
113
+ queryClient.setQueryData(queryKeys.users.profile(activeSessionId), data);
114
+ }
115
+
116
+ // Invalidate related queries
117
+ invalidateUserQueries(queryClient);
118
+ },
119
+ // Always refetch after error or success
120
+ onSettled: () => {
121
+ queryClient.invalidateQueries({
122
+ queryKey: queryKeys.accounts.current()
123
+ });
124
+ if (activeSessionId) {
125
+ queryClient.invalidateQueries({
126
+ queryKey: queryKeys.users.profile(activeSessionId)
127
+ });
128
+ }
129
+ }
130
+ });
131
+ };
132
+
133
+ /**
134
+ * Upload avatar with progress tracking and offline queue support
135
+ */
136
+ export const useUploadAvatar = () => {
137
+ const {
138
+ oxyServices,
139
+ activeSessionId,
140
+ syncIdentity
141
+ } = useOxy();
142
+ const queryClient = useQueryClient();
143
+ return useMutation({
144
+ mutationFn: async file => {
145
+ // Ensure we have a valid token before making the request
146
+ if (!oxyServices.hasValidToken() && activeSessionId) {
147
+ try {
148
+ await oxyServices.getTokenBySession(activeSessionId);
149
+ } catch (tokenError) {
150
+ const errorMessage = tokenError instanceof Error ? tokenError.message : String(tokenError);
151
+ if (errorMessage.includes('AUTH_REQUIRED_OFFLINE_SESSION') || errorMessage.includes('offline')) {
152
+ try {
153
+ await syncIdentity();
154
+ await oxyServices.getTokenBySession(activeSessionId);
155
+ } catch (syncError) {
156
+ throw new Error('Session needs to be synced. Please try again.');
157
+ }
158
+ } else {
159
+ throw tokenError;
160
+ }
161
+ }
162
+ }
163
+ try {
164
+ // Upload file first
165
+ const uploadResult = await oxyServices.assetUpload(file, 'public');
166
+ const fileId = uploadResult?.file?.id || uploadResult?.id || uploadResult;
167
+ if (!fileId || typeof fileId !== 'string') {
168
+ throw new Error('Failed to get file ID from upload result');
169
+ }
170
+
171
+ // Update profile with file ID
172
+ return await oxyServices.updateProfile({
173
+ avatar: fileId
174
+ });
175
+ } catch (error) {
176
+ const errorMessage = error?.message || '';
177
+ const status = error?.status || error?.response?.status;
178
+
179
+ // Handle authentication errors
180
+ if (status === 401 || errorMessage.includes('Authentication required') || errorMessage.includes('Invalid or missing authorization header')) {
181
+ if (activeSessionId) {
182
+ try {
183
+ await syncIdentity();
184
+ await oxyServices.getTokenBySession(activeSessionId);
185
+ // Retry upload
186
+ const uploadResult = await oxyServices.assetUpload(file, 'public');
187
+ const fileId = uploadResult?.file?.id || uploadResult?.id || uploadResult;
188
+ if (!fileId || typeof fileId !== 'string') {
189
+ throw new Error('Failed to get file ID from upload result');
190
+ }
191
+ return await oxyServices.updateProfile({
192
+ avatar: fileId
193
+ });
194
+ } catch (retryError) {
195
+ throw new Error('Authentication failed. Please sign in again.');
196
+ }
197
+ } else {
198
+ throw new Error('No active session. Please sign in.');
199
+ }
200
+ }
201
+
202
+ // TanStack Query will automatically retry on network errors
203
+ throw error;
204
+ }
205
+ },
206
+ onMutate: async file => {
207
+ await queryClient.cancelQueries({
208
+ queryKey: queryKeys.accounts.current()
209
+ });
210
+ const previousUser = queryClient.getQueryData(queryKeys.accounts.current());
211
+
212
+ // Optimistically set a temporary avatar (using file URI as placeholder)
213
+ if (previousUser) {
214
+ const optimisticUser = {
215
+ ...previousUser,
216
+ avatar: file.uri // Temporary, will be replaced with fileId
217
+ };
218
+ queryClient.setQueryData(queryKeys.accounts.current(), optimisticUser);
219
+ if (activeSessionId) {
220
+ queryClient.setQueryData(queryKeys.users.profile(activeSessionId), optimisticUser);
221
+ }
222
+ }
223
+ return {
224
+ previousUser
225
+ };
226
+ },
227
+ onError: (error, file, context) => {
228
+ if (context?.previousUser) {
229
+ queryClient.setQueryData(queryKeys.accounts.current(), context.previousUser);
230
+ if (activeSessionId) {
231
+ queryClient.setQueryData(queryKeys.users.profile(activeSessionId), context.previousUser);
232
+ }
233
+ }
234
+ toast.error(error instanceof Error ? error.message : 'Failed to upload avatar');
235
+ },
236
+ onSuccess: data => {
237
+ queryClient.setQueryData(queryKeys.accounts.current(), data);
238
+ if (activeSessionId) {
239
+ queryClient.setQueryData(queryKeys.users.profile(activeSessionId), data);
240
+ }
241
+ invalidateUserQueries(queryClient);
242
+ toast.success('Avatar updated successfully');
243
+ },
244
+ onSettled: () => {
245
+ queryClient.invalidateQueries({
246
+ queryKey: queryKeys.accounts.current()
247
+ });
248
+ if (activeSessionId) {
249
+ queryClient.invalidateQueries({
250
+ queryKey: queryKeys.users.profile(activeSessionId)
251
+ });
252
+ }
253
+ }
254
+ });
255
+ };
256
+
257
+ /**
258
+ * Update account settings
259
+ */
260
+ export const useUpdateAccountSettings = () => {
261
+ const {
262
+ oxyServices,
263
+ activeSessionId
264
+ } = useOxy();
265
+ const queryClient = useQueryClient();
266
+ return useMutation({
267
+ mutationFn: async settings => {
268
+ return await oxyServices.updateProfile({
269
+ privacySettings: settings
270
+ });
271
+ },
272
+ onMutate: async settings => {
273
+ await queryClient.cancelQueries({
274
+ queryKey: queryKeys.accounts.settings()
275
+ });
276
+ const previousUser = queryClient.getQueryData(queryKeys.accounts.current());
277
+ if (previousUser) {
278
+ queryClient.setQueryData(queryKeys.accounts.current(), {
279
+ ...previousUser,
280
+ privacySettings: {
281
+ ...previousUser.privacySettings,
282
+ ...settings
283
+ }
284
+ });
285
+ }
286
+ return {
287
+ previousUser
288
+ };
289
+ },
290
+ onError: (error, settings, context) => {
291
+ if (context?.previousUser) {
292
+ queryClient.setQueryData(queryKeys.accounts.current(), context.previousUser);
293
+ }
294
+ toast.error(error instanceof Error ? error.message : 'Failed to update settings');
295
+ },
296
+ onSuccess: data => {
297
+ queryClient.setQueryData(queryKeys.accounts.current(), data);
298
+ invalidateAccountQueries(queryClient);
299
+ toast.success('Settings updated successfully');
300
+ },
301
+ onSettled: () => {
302
+ queryClient.invalidateQueries({
303
+ queryKey: queryKeys.accounts.settings()
304
+ });
305
+ }
306
+ });
307
+ };
308
+ //# sourceMappingURL=useAccountMutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMutation","useQueryClient","queryKeys","invalidateAccountQueries","invalidateUserQueries","useOxy","toast","useUpdateProfile","oxyServices","activeSessionId","user","syncIdentity","queryClient","mutationFn","updates","hasValidToken","getTokenBySession","tokenError","errorMessage","Error","message","String","includes","syncError","updateProfile","error","status","response","retryError","onMutate","cancelQueries","queryKey","accounts","current","previousUser","getQueryData","setQueryData","users","profile","onError","context","onSuccess","data","onSettled","invalidateQueries","useUploadAvatar","file","uploadResult","assetUpload","fileId","id","avatar","optimisticUser","uri","success","useUpdateAccountSettings","settings","privacySettings"],"sourceRoot":"../../../../../src","sources":["ui/hooks/mutations/useAccountMutations.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,cAAc,QAAQ,uBAAuB;AAEnE,SAASC,SAAS,EAAEC,wBAAwB,EAAEC,qBAAqB,QAAQ,sBAAsB;AACjG,SAASC,MAAM,QAA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MAEA,OAAO;QAAEtB;MAAa,CAAC;IACzB,CAAC;IACDK,OAAO,EAAEA,CAACd,KAAK,EAAE+B,QAAQ,EAAEhB,OAAO,KAAK;MACrC,IAAIA,OAAO,EAAEN,YAAY,EAAE;QACzBtB,WAAW,CAACwB,YAAY,CAAClC,SAAS,CAAC8B,QAAQ,CAACC,OAAO,CAAC,CAAC,EAAEO,OAAO,CAACN,YAAY,CAAC;MAC9E;MACA5B,KAAK,CAACmB,KAAK,CAACA,KAAK,YAAYN,KAAK,GAAGM,KAAK,CAACL,OAAO,GAAG,2BAA2B,CAAC;IACnF,CAAC;IACDqB,SAAS,EAAGC,IAAI,IAAK;MACnB9B,WAAW,CAACwB,YAAY,CAAClC,SAAS,CAAC8B,QAAQ,CAACC,OAAO,CAAC,CAAC,EAAES,IAAI,CAAC;MAC5DvC,wBAAwB,CAACS,WAAW,CAAC;MACrCN,KAAK,CAACgD,OAAO,CAAC,+BAA+B,CAAC;IAChD,CAAC;IACDX,SAAS,EAAEA,CAAA,KAAM;MACf/B,WAAW,CAACgC,iBAAiB,CAAC;QAAEb,QAAQ,EAAE7B,SAAS,CAAC8B,QAAQ,CAACwB,QAAQ,CAAC;MAAE,CAAC,CAAC;IAC5E;EACF,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import { queryKeys, invalidateSessionQueries } from '../queries/queryKeys';
5
+ import { useOxy } from '../../context/OxyContext';
6
+ import { toast } from '../../../lib/sonner';
7
+
8
+ /**
9
+ * Switch active session
10
+ */
11
+ export const useSwitchSession = () => {
12
+ const {
13
+ switchSession,
14
+ activeSessionId
15
+ } = useOxy();
16
+ const queryClient = useQueryClient();
17
+ return useMutation({
18
+ mutationFn: async sessionId => {
19
+ return await switchSession(sessionId);
20
+ },
21
+ onSuccess: user => {
22
+ // Invalidate all session queries
23
+ invalidateSessionQueries(queryClient);
24
+
25
+ // Update current user query
26
+ queryClient.setQueryData(queryKeys.accounts.current(), user);
27
+
28
+ // Invalidate account queries
29
+ queryClient.invalidateQueries({
30
+ queryKey: queryKeys.accounts.all
31
+ });
32
+ },
33
+ onError: error => {
34
+ toast.error(error instanceof Error ? error.message : 'Failed to switch session');
35
+ }
36
+ });
37
+ };
38
+
39
+ /**
40
+ * Logout from a session
41
+ */
42
+ export const useLogoutSession = () => {
43
+ const {
44
+ oxyServices,
45
+ activeSessionId,
46
+ sessions
47
+ } = useOxy();
48
+ const queryClient = useQueryClient();
49
+ return useMutation({
50
+ mutationFn: async targetSessionId => {
51
+ if (!activeSessionId) {
52
+ throw new Error('No active session');
53
+ }
54
+ const sessionToLogout = targetSessionId || activeSessionId;
55
+ await oxyServices.logoutSession(activeSessionId, sessionToLogout);
56
+ return sessionToLogout;
57
+ },
58
+ onMutate: async targetSessionId => {
59
+ // Cancel outgoing queries
60
+ await queryClient.cancelQueries({
61
+ queryKey: queryKeys.sessions.all
62
+ });
63
+
64
+ // Snapshot previous sessions
65
+ const previousSessions = queryClient.getQueryData(queryKeys.sessions.list());
66
+
67
+ // Optimistically remove session
68
+ if (previousSessions) {
69
+ const sessionToLogout = targetSessionId || activeSessionId;
70
+ const updatedSessions = previousSessions.filter(s => s.sessionId !== sessionToLogout);
71
+ queryClient.setQueryData(queryKeys.sessions.list(), updatedSessions);
72
+ }
73
+ return {
74
+ previousSessions
75
+ };
76
+ },
77
+ onError: (error, targetSessionId, context) => {
78
+ // Rollback on error
79
+ if (context?.previousSessions) {
80
+ queryClient.setQueryData(queryKeys.sessions.list(), context.previousSessions);
81
+ }
82
+ toast.error(error instanceof Error ? error.message : 'Failed to logout');
83
+ },
84
+ onSuccess: () => {
85
+ // Invalidate all session queries
86
+ invalidateSessionQueries(queryClient);
87
+ },
88
+ onSettled: () => {
89
+ queryClient.invalidateQueries({
90
+ queryKey: queryKeys.sessions.all
91
+ });
92
+ }
93
+ });
94
+ };
95
+
96
+ /**
97
+ * Logout from all sessions
98
+ */
99
+ export const useLogoutAll = () => {
100
+ const {
101
+ oxyServices,
102
+ activeSessionId,
103
+ clearSessionState
104
+ } = useOxy();
105
+ const queryClient = useQueryClient();
106
+ return useMutation({
107
+ mutationFn: async () => {
108
+ if (!activeSessionId) {
109
+ throw new Error('No active session');
110
+ }
111
+ await oxyServices.logoutAllSessions(activeSessionId);
112
+ await clearSessionState();
113
+ },
114
+ onSuccess: () => {
115
+ // Clear all queries
116
+ queryClient.clear();
117
+ toast.success('Logged out from all sessions');
118
+ },
119
+ onError: error => {
120
+ toast.error(error instanceof Error ? error.message : 'Failed to logout from all sessions');
121
+ }
122
+ });
123
+ };
124
+
125
+ /**
126
+ * Update device name
127
+ */
128
+ export const useUpdateDeviceName = () => {
129
+ const {
130
+ oxyServices,
131
+ activeSessionId
132
+ } = useOxy();
133
+ const queryClient = useQueryClient();
134
+ return useMutation({
135
+ mutationFn: async deviceName => {
136
+ if (!activeSessionId) {
137
+ throw new Error('No active session');
138
+ }
139
+ return await oxyServices.updateDeviceName(activeSessionId, deviceName);
140
+ },
141
+ onSuccess: () => {
142
+ // Invalidate device and session queries
143
+ queryClient.invalidateQueries({
144
+ queryKey: queryKeys.devices.all
145
+ });
146
+ queryClient.invalidateQueries({
147
+ queryKey: queryKeys.sessions.all
148
+ });
149
+ toast.success('Device name updated');
150
+ },
151
+ onError: error => {
152
+ toast.error(error instanceof Error ? error.message : 'Failed to update device name');
153
+ }
154
+ });
155
+ };
156
+
157
+ /**
158
+ * Remove a device
159
+ */
160
+ export const useRemoveDevice = () => {
161
+ const {
162
+ oxyServices
163
+ } = useOxy();
164
+ const queryClient = useQueryClient();
165
+ return useMutation({
166
+ mutationFn: async deviceId => {
167
+ await oxyServices.removeDevice(deviceId);
168
+ return deviceId;
169
+ },
170
+ onSuccess: () => {
171
+ // Invalidate device queries
172
+ queryClient.invalidateQueries({
173
+ queryKey: queryKeys.devices.all
174
+ });
175
+ queryClient.invalidateQueries({
176
+ queryKey: queryKeys.sessions.all
177
+ });
178
+ toast.success('Device removed');
179
+ },
180
+ onError: error => {
181
+ toast.error(error instanceof Error ? error.message : 'Failed to remove device');
182
+ }
183
+ });
184
+ };
185
+ //# sourceMappingURL=useServicesMutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMutation","useQueryClient","queryKeys","invalidateSessionQueries","useOxy","toast","useSwitchSession","switchSession","activeSessionId","queryClient","mutationFn","sessionId","onSuccess","user","setQueryData","accounts","current","invalidateQueries","queryKey","all","onError","error","Error","message","useLogoutSession","oxyServices","sessions","targetSessionId","sessionToLogout","logoutSession","onMutate","cancelQueries","previousSessions","getQueryData","list","updatedSessions","filter","s","context","onSettled","useLogoutAll","clearSessionState","logoutAllSessions","clear","success","useUpdateDeviceName","deviceName","updateDeviceName","devices","useRemoveDevice","deviceId","removeDevice"],"sourceRoot":"../../../../../src","sources":["ui/hooks/mutations/useServicesMutations.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,cAAc,QAAQ,uBAAuB;AAEnE,SAASC,SAAS,EAAEC,wBAAwB,QAAQ,sBAAsB;AAC1E,SAASC,MAAM,QAAQ,0BAA0B;AACjD,SAASC,KAAK,QAAQ,qBAAqB;;AAE3C;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;EACpC,MAAM;IAAEC,aAAa;IAAEC;EAAgB,CAAC,GAAGJ,MAAM,CAAC,CAAC;EACnD,MAAMK,WAAW,GAAGR,cAAc,CAAC,CAAC;EAEpC,OAAOD,WAAW,CAAC;IACjBU,UAAU,EAAE,MAAOC,SAAiB,IAAK;MACvC,OAAO,MAAMJ,aAAa,CAACI,SAAS,CAAC;IACvC,CAAC;IACDC,SAAS,EAAGC,IAAI,IAAK;MACnB;MACAV,wBAAwB,CAACM,WAAW,CAAC;;MAErC;MACAA,WAAW,CAACK,YAAY,CAACZ,SAAS,CAACa,QAAQ,CAACC,OAAO,CAAC,CAAC,EAAEH,IAAI,CAAC;;MAE5D;MACAJ,W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MAAM,CAAC,CAAC;EAChC,MAAMK,WAAW,GAAGR,cAAc,CAAC,CAAC;EAEpC,OAAOD,WAAW,CAAC;IACjBU,UAAU,EAAE,MAAOwC,QAAgB,IAAK;MACtC,MAAMzB,WAAW,CAAC0B,YAAY,CAACD,QAAQ,CAAC;MACxC,OAAOA,QAAQ;IACjB,CAAC;IACDtC,SAAS,EAAEA,CAAA,KAAM;MACf;MACAH,WAAW,CAACQ,iBAAiB,CAAC;QAAEC,QAAQ,EAAEhB,SAAS,CAAC8C,OAAO,CAAC7B;MAAI,CAAC,CAAC;MAClEV,WAAW,CAACQ,iBAAiB,CAAC;QAAEC,QAAQ,EAAEhB,SAAS,CAACwB,QAAQ,CAACP;MAAI,CAAC,CAAC;MACnEd,KAAK,CAACuC,OAAO,CAAC,gBAAgB,CAAC;IACjC,CAAC;IACDxB,OAAO,EAAGC,KAAK,IAAK;MAClBhB,KAAK,CAACgB,KAAK,CAACA,KAAK,YAAYC,KAAK,GAAGD,KAAK,CAACE,OAAO,GAAG,yBAAyB,CAAC;IACjF;EACF,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ // Export all query hooks
4
+ export * from './useAccountQueries';
5
+ export * from './useServicesQueries';
6
+ export * from './queryKeys';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["ui/hooks/queries/index.ts"],"mappings":";;AAAA;AACA,cAAc,qBAAqB;AACnC,cAAc,sBAAsB;AACpC,cAAc,aAAa","ignoreList":[]}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Centralized query keys for TanStack Query
5
+ *
6
+ * Following best practices:
7
+ * - Use arrays for hierarchical keys
8
+ * - Include all parameters in the key
9
+ * - Use consistent naming conventions
10
+ */
11
+
12
+ export const queryKeys = {
13
+ // Account queries
14
+ accounts: {
15
+ all: ['accounts'],
16
+ lists: () => [...queryKeys.accounts.all, 'list'],
17
+ list: sessionIds => [...queryKeys.accounts.lists(), sessionIds],
18
+ details: () => [...queryKeys.accounts.all, 'detail'],
19
+ detail: sessionId => [...queryKeys.accounts.details(), sessionId],
20
+ current: () => [...queryKeys.accounts.all, 'current'],
21
+ settings: () => [...queryKeys.accounts.all, 'settings']
22
+ },
23
+ // User queries
24
+ users: {
25
+ all: ['users'],
26
+ lists: () => [...queryKeys.users.all, 'list'],
27
+ list: userIds => [...queryKeys.users.lists(), userIds],
28
+ details: () => [...queryKeys.users.all, 'detail'],
29
+ detail: userId => [...queryKeys.users.details(), userId],
30
+ profile: sessionId => [...queryKeys.users.details(), sessionId, 'profile']
31
+ },
32
+ // Session queries
33
+ sessions: {
34
+ all: ['sessions'],
35
+ lists: () => [...queryKeys.sessions.all, 'list'],
36
+ list: userId => [...queryKeys.sessions.lists(), userId],
37
+ details: () => [...queryKeys.sessions.all, 'detail'],
38
+ detail: sessionId => [...queryKeys.sessions.details(), sessionId],
39
+ active: () => [...queryKeys.sessions.all, 'active'],
40
+ device: deviceId => [...queryKeys.sessions.all, 'device', deviceId]
41
+ },
42
+ // Device queries
43
+ devices: {
44
+ all: ['devices'],
45
+ lists: () => [...queryKeys.devices.all, 'list'],
46
+ list: userId => [...queryKeys.devices.lists(), userId],
47
+ details: () => [...queryKeys.devices.all, 'detail'],
48
+ detail: deviceId => [...queryKeys.devices.details(), deviceId]
49
+ }
50
+ };
51
+
52
+ /**
53
+ * Helper to invalidate all account-related queries
54
+ */
55
+ export const invalidateAccountQueries = queryClient => {
56
+ queryClient.invalidateQueries({
57
+ queryKey: queryKeys.accounts.all
58
+ });
59
+ };
60
+
61
+ /**
62
+ * Helper to invalidate all user-related queries
63
+ */
64
+ export const invalidateUserQueries = queryClient => {
65
+ queryClient.invalidateQueries({
66
+ queryKey: queryKeys.users.all
67
+ });
68
+ };
69
+
70
+ /**
71
+ * Helper to invalidate all session-related queries
72
+ */
73
+ export const invalidateSessionQueries = queryClient => {
74
+ queryClient.invalidateQueries({
75
+ queryKey: queryKeys.sessions.all
76
+ });
77
+ };
78
+ //# sourceMappingURL=queryKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["queryKeys","accounts","all","lists","list","sessionIds","details","detail","sessionId","current","settings","users","userIds","userId","profile","sessions","active","device","deviceId","devices","invalidateAccountQueries","queryClient","invalidateQueries","queryKey","invalidateUserQueries","invalidateSessionQueries"],"sourceRoot":"../../../../../src","sources":["ui/hooks/queries/queryKeys.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,SAAS,GAAG;EACvB;EACAC,QAAQ,EAAE;IACRC,GAAG,EAAE,CAAC,UAAU,CAAU;IAC1BC,KAAK,EAAEA,CAAA,KAAM,CAAC,GAAGH,SAAS,CAACC,QAAQ,CAACC,GAAG,EAAE,MAAM,CAAU;IACzDE,IAAI,EAAGC,UAAoB,IAAK,CAAC,GAAGL,SAAS,CAACC,QAAQ,CAACE,KAAK,CAAC,CAAC,EAAEE,UAAU,CAAU;IACpFC,OAAO,EAAEA,CAAA,KAAM,CAAC,GAAGN,SAAS,CAACC,QAAQ,CAACC,GAAG,EAAE,QAAQ,CAAU;IAC7DK,MAAM,EAAGC,SAAiB,IAAK,CAAC,GAAGR,SAAS,CAACC,QAAQ,CAACK,OAAO,CAAC,CAAC,EAAEE,SAAS,CAAU;IACpFC,OAAO,EAAEA,CAAA,KAAM,CAAC,GAAGT,SAAS,CAACC,QAAQ,CAACC,GAAG,EAAE,SAAS,CAAU;IAC9DQ,QAAQ,EAAEA,CAAA,KAAM,CAAC,GAAGV,SAAS,CAACC,QAAQ,CAACC,GAAG,EAAE,UAAU;EACxD,CAAC;EAED;EACAS,KAAK,EAAE;IACLT,GAAG,EAAE,CAAC,OAAO,CAAU;IACvBC,KAAK,EAAEA,CAAA,KAAM,CAAC,GAAGH,SAAS,CAACW,KAAK,CAACT,GAAG,EAAE,MAAM,CAAU;IACtDE,IAA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