@oxy.so/services 14.0.1 → 14.1.0

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 (152) hide show
  1. package/lib/commonjs/ui/components/accountSettings/AccountSettings.js +5 -5
  2. package/lib/commonjs/ui/components/accountSettings/AccountSettings.js.map +1 -1
  3. package/lib/commonjs/ui/components/signIn/OxyAuthenticatorPanel.js +2 -1
  4. package/lib/commonjs/ui/components/signIn/OxyAuthenticatorPanel.js.map +1 -1
  5. package/lib/commonjs/ui/components/signIn/OxyDeleteAccountPanel.js +9 -3
  6. package/lib/commonjs/ui/components/signIn/OxyDeleteAccountPanel.js.map +1 -1
  7. package/lib/commonjs/ui/components/signIn/OxyEmailPanel.js +2 -1
  8. package/lib/commonjs/ui/components/signIn/OxyEmailPanel.js.map +1 -1
  9. package/lib/commonjs/ui/components/signIn/OxyLinkCommonsPanel.js +2 -1
  10. package/lib/commonjs/ui/components/signIn/OxyLinkCommonsPanel.js.map +1 -1
  11. package/lib/commonjs/ui/components/signIn/OxyPasswordPanel.js +8 -1
  12. package/lib/commonjs/ui/components/signIn/OxyPasswordPanel.js.map +1 -1
  13. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js +6 -3
  14. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js.map +1 -1
  15. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js +39 -10
  16. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  17. package/lib/commonjs/ui/components/signIn/ReauthStep.js +7 -1
  18. package/lib/commonjs/ui/components/signIn/ReauthStep.js.map +1 -1
  19. package/lib/commonjs/ui/components/signIn/accountFlowParts.js +16 -86
  20. package/lib/commonjs/ui/components/signIn/accountFlowParts.js.map +1 -1
  21. package/lib/commonjs/ui/hooks/mutations/mutationFactory.js +5 -4
  22. package/lib/commonjs/ui/hooks/mutations/mutationFactory.js.map +1 -1
  23. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +31 -7
  24. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  25. package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js +22 -5
  26. package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js.map +1 -1
  27. package/lib/commonjs/ui/hooks/useUsernameAvailability.js +8 -3
  28. package/lib/commonjs/ui/hooks/useUsernameAvailability.js.map +1 -1
  29. package/lib/commonjs/ui/screens/AccountMembersScreen.js +25 -21
  30. package/lib/commonjs/ui/screens/AccountMembersScreen.js.map +1 -1
  31. package/lib/commonjs/ui/screens/CreateAccountScreen.js +15 -19
  32. package/lib/commonjs/ui/screens/CreateAccountScreen.js.map +1 -1
  33. package/lib/commonjs/ui/screens/DomainsScreen.js +25 -11
  34. package/lib/commonjs/ui/screens/DomainsScreen.js.map +1 -1
  35. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +10 -5
  36. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
  37. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js +27 -7
  38. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  39. package/lib/commonjs/ui/utils/apiErrorMessage.js +117 -0
  40. package/lib/commonjs/ui/utils/apiErrorMessage.js.map +1 -0
  41. package/lib/commonjs/ui/utils/usernamePolicy.js +75 -0
  42. package/lib/commonjs/ui/utils/usernamePolicy.js.map +1 -0
  43. package/lib/module/ui/components/accountSettings/AccountSettings.js +5 -5
  44. package/lib/module/ui/components/accountSettings/AccountSettings.js.map +1 -1
  45. package/lib/module/ui/components/signIn/OxyAuthenticatorPanel.js +3 -2
  46. package/lib/module/ui/components/signIn/OxyAuthenticatorPanel.js.map +1 -1
  47. package/lib/module/ui/components/signIn/OxyDeleteAccountPanel.js +9 -3
  48. package/lib/module/ui/components/signIn/OxyDeleteAccountPanel.js.map +1 -1
  49. package/lib/module/ui/components/signIn/OxyEmailPanel.js +3 -2
  50. package/lib/module/ui/components/signIn/OxyEmailPanel.js.map +1 -1
  51. package/lib/module/ui/components/signIn/OxyLinkCommonsPanel.js +3 -2
  52. package/lib/module/ui/components/signIn/OxyLinkCommonsPanel.js.map +1 -1
  53. package/lib/module/ui/components/signIn/OxyPasswordPanel.js +8 -1
  54. package/lib/module/ui/components/signIn/OxyPasswordPanel.js.map +1 -1
  55. package/lib/module/ui/components/signIn/OxySignInPanel.js +7 -4
  56. package/lib/module/ui/components/signIn/OxySignInPanel.js.map +1 -1
  57. package/lib/module/ui/components/signIn/OxySignUpPanel.js +38 -9
  58. package/lib/module/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  59. package/lib/module/ui/components/signIn/ReauthStep.js +9 -3
  60. package/lib/module/ui/components/signIn/ReauthStep.js.map +1 -1
  61. package/lib/module/ui/components/signIn/accountFlowParts.js +15 -82
  62. package/lib/module/ui/components/signIn/accountFlowParts.js.map +1 -1
  63. package/lib/module/ui/hooks/mutations/mutationFactory.js +5 -4
  64. package/lib/module/ui/hooks/mutations/mutationFactory.js.map +1 -1
  65. package/lib/module/ui/hooks/mutations/useAccountMutations.js +31 -7
  66. package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  67. package/lib/module/ui/hooks/mutations/useServicesMutations.js +22 -5
  68. package/lib/module/ui/hooks/mutations/useServicesMutations.js.map +1 -1
  69. package/lib/module/ui/hooks/useUsernameAvailability.js +8 -3
  70. package/lib/module/ui/hooks/useUsernameAvailability.js.map +1 -1
  71. package/lib/module/ui/screens/AccountMembersScreen.js +25 -21
  72. package/lib/module/ui/screens/AccountMembersScreen.js.map +1 -1
  73. package/lib/module/ui/screens/CreateAccountScreen.js +16 -20
  74. package/lib/module/ui/screens/CreateAccountScreen.js.map +1 -1
  75. package/lib/module/ui/screens/DomainsScreen.js +26 -10
  76. package/lib/module/ui/screens/DomainsScreen.js.map +1 -1
  77. package/lib/module/ui/screens/EditProfileFieldScreen.js +11 -6
  78. package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
  79. package/lib/module/ui/screens/WelcomeNewUserScreen.js +29 -9
  80. package/lib/module/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  81. package/lib/module/ui/utils/apiErrorMessage.js +107 -0
  82. package/lib/module/ui/utils/apiErrorMessage.js.map +1 -0
  83. package/lib/module/ui/utils/usernamePolicy.js +70 -0
  84. package/lib/module/ui/utils/usernamePolicy.js.map +1 -0
  85. package/lib/typescript/commonjs/ui/components/accountSettings/AccountSettings.d.ts.map +1 -1
  86. package/lib/typescript/commonjs/ui/components/signIn/OxyDeleteAccountPanel.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/ui/components/signIn/OxyLinkCommonsPanel.d.ts.map +1 -1
  88. package/lib/typescript/commonjs/ui/components/signIn/OxyPasswordPanel.d.ts.map +1 -1
  89. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/ui/components/signIn/ReauthStep.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/ui/components/signIn/accountFlowParts.d.ts +7 -16
  93. package/lib/typescript/commonjs/ui/components/signIn/accountFlowParts.d.ts.map +1 -1
  94. package/lib/typescript/commonjs/ui/hooks/mutations/mutationFactory.d.ts +4 -1
  95. package/lib/typescript/commonjs/ui/hooks/mutations/mutationFactory.d.ts.map +1 -1
  96. package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
  97. package/lib/typescript/commonjs/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
  98. package/lib/typescript/commonjs/ui/hooks/useUsernameAvailability.d.ts.map +1 -1
  99. package/lib/typescript/commonjs/ui/screens/AccountMembersScreen.d.ts.map +1 -1
  100. package/lib/typescript/commonjs/ui/screens/CreateAccountScreen.d.ts.map +1 -1
  101. package/lib/typescript/commonjs/ui/screens/DomainsScreen.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  103. package/lib/typescript/commonjs/ui/screens/WelcomeNewUserScreen.d.ts.map +1 -1
  104. package/lib/typescript/commonjs/ui/utils/apiErrorMessage.d.ts +30 -0
  105. package/lib/typescript/commonjs/ui/utils/apiErrorMessage.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/ui/utils/usernamePolicy.d.ts +33 -0
  107. package/lib/typescript/commonjs/ui/utils/usernamePolicy.d.ts.map +1 -0
  108. package/lib/typescript/module/ui/components/accountSettings/AccountSettings.d.ts.map +1 -1
  109. package/lib/typescript/module/ui/components/signIn/OxyDeleteAccountPanel.d.ts.map +1 -1
  110. package/lib/typescript/module/ui/components/signIn/OxyLinkCommonsPanel.d.ts.map +1 -1
  111. package/lib/typescript/module/ui/components/signIn/OxyPasswordPanel.d.ts.map +1 -1
  112. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  113. package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
  114. package/lib/typescript/module/ui/components/signIn/ReauthStep.d.ts.map +1 -1
  115. package/lib/typescript/module/ui/components/signIn/accountFlowParts.d.ts +7 -16
  116. package/lib/typescript/module/ui/components/signIn/accountFlowParts.d.ts.map +1 -1
  117. package/lib/typescript/module/ui/hooks/mutations/mutationFactory.d.ts +4 -1
  118. package/lib/typescript/module/ui/hooks/mutations/mutationFactory.d.ts.map +1 -1
  119. package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
  120. package/lib/typescript/module/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
  121. package/lib/typescript/module/ui/hooks/useUsernameAvailability.d.ts.map +1 -1
  122. package/lib/typescript/module/ui/screens/AccountMembersScreen.d.ts.map +1 -1
  123. package/lib/typescript/module/ui/screens/CreateAccountScreen.d.ts.map +1 -1
  124. package/lib/typescript/module/ui/screens/DomainsScreen.d.ts.map +1 -1
  125. package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  126. package/lib/typescript/module/ui/screens/WelcomeNewUserScreen.d.ts.map +1 -1
  127. package/lib/typescript/module/ui/utils/apiErrorMessage.d.ts +30 -0
  128. package/lib/typescript/module/ui/utils/apiErrorMessage.d.ts.map +1 -0
  129. package/lib/typescript/module/ui/utils/usernamePolicy.d.ts +33 -0
  130. package/lib/typescript/module/ui/utils/usernamePolicy.d.ts.map +1 -0
  131. package/package.json +6 -6
  132. package/src/ui/components/accountSettings/AccountSettings.tsx +5 -7
  133. package/src/ui/components/signIn/OxyAuthenticatorPanel.tsx +2 -2
  134. package/src/ui/components/signIn/OxyDeleteAccountPanel.tsx +7 -3
  135. package/src/ui/components/signIn/OxyEmailPanel.tsx +2 -2
  136. package/src/ui/components/signIn/OxyLinkCommonsPanel.tsx +3 -7
  137. package/src/ui/components/signIn/OxyPasswordPanel.tsx +6 -1
  138. package/src/ui/components/signIn/OxySignInPanel.tsx +13 -6
  139. package/src/ui/components/signIn/OxySignUpPanel.tsx +38 -11
  140. package/src/ui/components/signIn/ReauthStep.tsx +9 -3
  141. package/src/ui/components/signIn/accountFlowParts.tsx +16 -87
  142. package/src/ui/hooks/mutations/mutationFactory.ts +9 -10
  143. package/src/ui/hooks/mutations/useAccountMutations.ts +20 -9
  144. package/src/ui/hooks/mutations/useServicesMutations.ts +12 -5
  145. package/src/ui/hooks/useUsernameAvailability.ts +6 -3
  146. package/src/ui/screens/AccountMembersScreen.tsx +29 -27
  147. package/src/ui/screens/CreateAccountScreen.tsx +20 -40
  148. package/src/ui/screens/DomainsScreen.tsx +22 -11
  149. package/src/ui/screens/EditProfileFieldScreen.tsx +10 -8
  150. package/src/ui/screens/WelcomeNewUserScreen.tsx +36 -14
  151. package/src/ui/utils/apiErrorMessage.ts +111 -0
  152. package/src/ui/utils/usernamePolicy.ts +81 -0
@@ -30,7 +30,10 @@ export interface ProfileMutationConfig<TData, TVariables> {
30
30
  cancelQueryKeys?: unknown[][];
31
31
  /** Function to apply optimistic update to the user data */
32
32
  optimisticUpdate?: (previousUser: User, variables: TVariables) => Partial<User>;
33
- /** Error message to show on failure */
33
+ /**
34
+ * What the failure toast says, in the person's language. A function words it
35
+ * from the error; the server's own `message` is never shown.
36
+ */
34
37
  errorMessage?: string | ((error: Error) => string);
35
38
  /** Success message to show (optional) */
36
39
  successMessage?: string;
@@ -115,14 +118,9 @@ export function createProfileMutation<TVariables>(
115
118
  }
116
119
  }
117
120
 
118
- // Show error toast
119
- const message =
120
- typeof errorMessage === 'function'
121
- ? errorMessage(error)
122
- : error instanceof Error
123
- ? error.message
124
- : errorMessage;
125
- toast.error(message);
121
+ // The caller's words, never the server's `message`: that is English and,
122
+ // for a validation failure, just "Validation failed".
123
+ toast.error(typeof errorMessage === 'function' ? errorMessage(error) : errorMessage);
126
124
  },
127
125
 
128
126
  onSuccess: (data, variables) => {
@@ -217,7 +215,8 @@ export function createGenericMutation<TData, TVariables>(
217
215
  if (context?.previous !== undefined) {
218
216
  queryClient.setQueryData(queryKey, context.previous);
219
217
  }
220
- toast.error(error instanceof Error ? error.message : errorMessage);
218
+ // The caller's words, never the server's `message` (English, developer-facing).
219
+ toast.error(errorMessage);
221
220
  },
222
221
 
223
222
  onSuccess: (data) => {
@@ -23,11 +23,15 @@ import { toast } from '@oxy.so/bloom/toast';
23
23
  import { useAuthStore } from '../../stores/authStore';
24
24
  import { clearedFieldsFromProfileUpdate, upsertCachedUser } from '../queries/userCache';
25
25
  import { removeAppAccessFromCache } from '../queries/useFileQueries';
26
+ import { describeApiError } from '../../utils/apiErrorMessage';
27
+ import { describeUsernameRefusal } from '../../utils/usernamePolicy';
28
+ import { useI18n } from '../useI18n';
26
29
 
27
30
  /**
28
31
  * Update user profile with optimistic updates and offline queue support
29
32
  */
30
33
  export const useUpdateProfile = () => {
34
+ const { t } = useI18n();
31
35
  const { oxyServices, activeSessionId, user } = useOxy();
32
36
  const queryClient = useQueryClient();
33
37
 
@@ -94,7 +98,10 @@ export const useUpdateProfile = () => {
94
98
  }
95
99
  }
96
100
  }
97
- toast.error(error instanceof Error ? error.message : 'Failed to update profile');
101
+ toast.error(
102
+ describeUsernameRefusal(error, updates?.username ?? '', t) ??
103
+ describeApiError(error, t, t('actionErrors.updateProfile')),
104
+ );
98
105
  },
99
106
  // On success, invalidate and refetch
100
107
  onSuccess: (data, updates) => {
@@ -127,6 +134,7 @@ export const useUpdateProfile = () => {
127
134
  * Upload avatar with progress tracking and offline queue support
128
135
  */
129
136
  export const useUploadAvatar = () => {
137
+ const { t } = useI18n();
130
138
  const { oxyServices, activeSessionId } = useOxy();
131
139
  const queryClient = useQueryClient();
132
140
 
@@ -188,7 +196,7 @@ export const useUploadAvatar = () => {
188
196
  }
189
197
  }
190
198
  }
191
- toast.error(error instanceof Error ? error.message : 'Failed to upload avatar');
199
+ toast.error(describeApiError(error, t, t('actionErrors.uploadAvatar')));
192
200
  },
193
201
  onSuccess: (data) => {
194
202
  queryClient.setQueryData(queryKeys.accounts.current(activeSessionId), data);
@@ -246,6 +254,7 @@ interface UpdateAccountSettingsVariables {
246
254
  * underlying `.mutate({ updates, currentUser })` form via `.mutation`.
247
255
  */
248
256
  export const useUpdateAccountSettings = () => {
257
+ const { t } = useI18n();
249
258
  const { oxyServices, activeSessionId, user } = useOxy();
250
259
  const queryClient = useQueryClient();
251
260
 
@@ -311,7 +320,7 @@ export const useUpdateAccountSettings = () => {
311
320
  });
312
321
  }
313
322
  }
314
- toast.error(error instanceof Error ? error.message : 'Failed to update settings');
323
+ toast.error(describeApiError(error, t, t('actionErrors.updateSettings')));
315
324
  },
316
325
  onSuccess: (data) => {
317
326
  queryClient.setQueryData(queryKeys.accounts.current(activeSessionId), data);
@@ -357,6 +366,7 @@ export const useUpdateAccountSettings = () => {
357
366
  * Update privacy settings with optimistic updates and authentication handling
358
367
  */
359
368
  export const useUpdatePrivacySettings = () => {
369
+ const { t } = useI18n();
360
370
  const { oxyServices, activeSessionId, user } = useOxy();
361
371
  const queryClient = useQueryClient();
362
372
 
@@ -472,7 +482,7 @@ export const useUpdatePrivacySettings = () => {
472
482
  queryClient.invalidateQueries({ queryKey: queryKeys.privacy.settings(targetUserId) });
473
483
  }
474
484
 
475
- toast.error(error instanceof Error ? error.message : 'Failed to update privacy settings');
485
+ toast.error(describeApiError(error, t, t('actionErrors.updatePrivacy')));
476
486
  },
477
487
  // On success, MERGE the server response into the cached state. Older
478
488
  // API builds returned only the changed field (or wiped the privacySettings
@@ -555,6 +565,7 @@ interface UploadResult {
555
565
  * invalidation behaviour as `useUpdateProfile`.
556
566
  */
557
567
  export const useUpdateNotificationPreferences = () => {
568
+ const { t } = useI18n();
558
569
  const { oxyServices, activeSessionId } = useOxy();
559
570
  const queryClient = useQueryClient();
560
571
 
@@ -593,9 +604,7 @@ export const useUpdateNotificationPreferences = () => {
593
604
  });
594
605
  }
595
606
  }
596
- toast.error(
597
- error instanceof Error ? error.message : 'Failed to update notification preferences',
598
- );
607
+ toast.error(describeApiError(error, t, t('actionErrors.updateNotifications')));
599
608
  },
600
609
  onSuccess: (data) => {
601
610
  queryClient.setQueryData(queryKeys.accounts.current(activeSessionId), data);
@@ -611,6 +620,7 @@ export const useUpdateNotificationPreferences = () => {
611
620
  * `PUT /users/me`.
612
621
  */
613
622
  export const useUpdateUserPreferences = () => {
623
+ const { t } = useI18n();
614
624
  const { oxyServices, activeSessionId } = useOxy();
615
625
  const queryClient = useQueryClient();
616
626
 
@@ -649,7 +659,7 @@ export const useUpdateUserPreferences = () => {
649
659
  });
650
660
  }
651
661
  }
652
- toast.error(error instanceof Error ? error.message : 'Failed to update preferences');
662
+ toast.error(describeApiError(error, t, t('actionErrors.updatePreferences')));
653
663
  },
654
664
  onSuccess: (data) => {
655
665
  queryClient.setQueryData(queryKeys.accounts.current(activeSessionId), data);
@@ -666,6 +676,7 @@ export const useUpdateUserPreferences = () => {
666
676
  * re-consent.
667
677
  */
668
678
  export const useRevokeConnectedApp = () => {
679
+ const { t } = useI18n();
669
680
  const { oxyServices, activeSessionId } = useOxy();
670
681
  const queryClient = useQueryClient();
671
682
 
@@ -680,7 +691,7 @@ export const useRevokeConnectedApp = () => {
680
691
  invalidateConnectedAppsQueries(queryClient);
681
692
  },
682
693
  onError: (error) => {
683
- toast.error(error instanceof Error ? error.message : 'Failed to revoke connected app');
694
+ toast.error(describeApiError(error, t, t('actionErrors.revokeConnectedApp')));
684
695
  },
685
696
  });
686
697
  };
@@ -4,11 +4,14 @@ import { queryKeys, invalidateSessionQueries } from '../queries/queryKeys';
4
4
  import { mutationKeys } from './mutationKeys';
5
5
  import { useOxy } from '../../context/oxyRuntimeContext';
6
6
  import { toast } from '@oxy.so/bloom/toast';
7
+ import { describeApiError } from '../../utils/apiErrorMessage';
8
+ import { useI18n } from '../useI18n';
7
9
 
8
10
  /**
9
11
  * Switch active session
10
12
  */
11
13
  export const useSwitchSession = () => {
14
+ const { t } = useI18n();
12
15
  const { switchSession } = useOxy();
13
16
  const queryClient = useQueryClient();
14
17
 
@@ -28,7 +31,7 @@ export const useSwitchSession = () => {
28
31
  queryClient.invalidateQueries({ queryKey: queryKeys.accounts.all });
29
32
  },
30
33
  onError: (error) => {
31
- toast.error(error instanceof Error ? error.message : 'Failed to switch session');
34
+ toast.error(describeApiError(error, t, t('actionErrors.switchSession')));
32
35
  },
33
36
  });
34
37
  };
@@ -37,6 +40,7 @@ export const useSwitchSession = () => {
37
40
  * Logout from a session
38
41
  */
39
42
  export const useLogoutSession = () => {
43
+ const { t } = useI18n();
40
44
  const { oxyServices, activeSessionId } = useOxy();
41
45
  const queryClient = useQueryClient();
42
46
 
@@ -75,7 +79,7 @@ export const useLogoutSession = () => {
75
79
  if (context?.previousSessions) {
76
80
  queryClient.setQueryData(queryKeys.sessions.list(), context.previousSessions);
77
81
  }
78
- toast.error(error instanceof Error ? error.message : 'Failed to logout');
82
+ toast.error(describeApiError(error, t, t('actionErrors.logout')));
79
83
  },
80
84
  onSuccess: () => {
81
85
  // Invalidate all session queries
@@ -91,6 +95,7 @@ export const useLogoutSession = () => {
91
95
  * Logout from all sessions
92
96
  */
93
97
  export const useLogoutAll = () => {
98
+ const { t } = useI18n();
94
99
  const { oxyServices, activeSessionId, clearSessionState } = useOxy();
95
100
  const queryClient = useQueryClient();
96
101
 
@@ -110,7 +115,7 @@ export const useLogoutAll = () => {
110
115
  toast.success('Logged out from all sessions');
111
116
  },
112
117
  onError: (error) => {
113
- toast.error(error instanceof Error ? error.message : 'Failed to logout from all sessions');
118
+ toast.error(describeApiError(error, t, t('actionErrors.logoutAll')));
114
119
  },
115
120
  });
116
121
  };
@@ -119,6 +124,7 @@ export const useLogoutAll = () => {
119
124
  * Update device name
120
125
  */
121
126
  export const useUpdateDeviceName = () => {
127
+ const { t } = useI18n();
122
128
  const { oxyServices, activeSessionId } = useOxy();
123
129
  const queryClient = useQueryClient();
124
130
 
@@ -138,7 +144,7 @@ export const useUpdateDeviceName = () => {
138
144
  toast.success('Device name updated');
139
145
  },
140
146
  onError: (error) => {
141
- toast.error(error instanceof Error ? error.message : 'Failed to update device name');
147
+ toast.error(describeApiError(error, t, t('actionErrors.updateDeviceName')));
142
148
  },
143
149
  });
144
150
  };
@@ -147,6 +153,7 @@ export const useUpdateDeviceName = () => {
147
153
  * Remove a device
148
154
  */
149
155
  export const useRemoveDevice = () => {
156
+ const { t } = useI18n();
150
157
  const { oxyServices } = useOxy();
151
158
  const queryClient = useQueryClient();
152
159
 
@@ -163,7 +170,7 @@ export const useRemoveDevice = () => {
163
170
  toast.success('Device removed');
164
171
  },
165
172
  onError: (error) => {
166
- toast.error(error instanceof Error ? error.message : 'Failed to remove device');
173
+ toast.error(describeApiError(error, t, t('actionErrors.removeDevice')));
167
174
  },
168
175
  });
169
176
  };
@@ -1,15 +1,18 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { usernameCheck } from '@oxy.so/contracts/client';
3
2
  import { useOxy } from '../context/oxyRuntimeContext';
3
+ import { checkUsernameDraft } from '../utils/usernamePolicy';
4
+ import { useI18n } from './useI18n';
4
5
 
5
6
  type CheckResult = { candidate: string; status: 'available' | 'taken' | 'error' };
6
7
 
7
8
  /** Debounced server check; a response only applies to the draft that requested it. */
8
9
  export function useUsernameAvailability(value: string, enabled: boolean) {
9
10
  const { oxyServices, user } = useOxy();
11
+ const { t } = useI18n();
10
12
  const candidate = value.trim();
11
- const checked = usernameCheck(candidate, []);
12
- const invalid = checked.ok ? undefined : checked.issue.message;
13
+ // The policy of the signed-in account's kind: a bot's handle ends in `bot`.
14
+ const checked = checkUsernameDraft(candidate, t, user?.kind);
15
+ const invalid = checked.ok ? undefined : checked.error;
13
16
  const unchanged = candidate.toLowerCase() === user?.username?.toLowerCase();
14
17
  const [result, setResult] = useState<CheckResult>();
15
18
  const [attempt, setAttempt] = useState(0);
@@ -15,21 +15,20 @@ import { Text } from '@oxy.so/bloom/typography';
15
15
  import { Button } from '@oxy.so/bloom/button';
16
16
  import { TextField, TextFieldInput } from '@oxy.so/bloom/text-field';
17
17
  import { Divider } from '@oxy.so/bloom/divider';
18
+ import { checkContract, emailAddressCheck } from '@oxy.so/contracts/client';
18
19
  import type { AccountMember, AccountRole } from '@oxy.so/core';
19
20
  import { accountRoleLabel, getNormalizedUserHandle } from '@oxy.so/core';
20
21
  import type { BaseScreenProps } from '../types/navigation';
21
22
  import { useOxy } from '../context/oxyRuntimeContext';
22
23
  import { useI18n } from '../hooks/useI18n';
23
24
  import { useSurfaceHeader } from '../hooks/useSurfaceHeader';
25
+ import { describeApiError } from '../utils/apiErrorMessage';
24
26
 
25
27
  /** Roles assignable via invite / role change — everything except `owner`. */
26
28
  type AssignableRole = Exclude<AccountRole, 'owner'>;
27
29
 
28
30
  const ASSIGNABLE_ROLES: AssignableRole[] = ['admin', 'editor', 'developer', 'billing', 'viewer'];
29
31
 
30
- const errorMessage = (error: unknown, fallback: string): string =>
31
- error instanceof Error && error.message ? error.message : fallback;
32
-
33
32
  /**
34
33
  * Manage the members of an account (invite by email, change roles,
35
34
  * remove, transfer ownership). Gated on the caller's `callerMembership`
@@ -102,7 +101,8 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
102
101
  onSuccess: () => {
103
102
  void invitationsQuery.refetch();
104
103
  },
105
- onError: (error) => toast.error(errorMessage(error, 'Could not update invitation')),
104
+ onError: (error) =>
105
+ toast.error(describeApiError(error, t, t('accounts.members.toasts.invitationUpdateFailed'))),
106
106
  });
107
107
  const members = useMemo<AccountMember[]>(() => membersQuery.data ?? [], [membersQuery.data]);
108
108
  const memberUserIds = useMemo(
@@ -162,21 +162,18 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
162
162
 
163
163
  const inviteMutation = useMutation({
164
164
  mutationKey: ['accounts', 'members', 'invite', id],
165
- mutationFn: (input: { usernameOrEmail: string; role: AssignableRole }) =>
166
- oxyServices.accounts.invitations.create(id, {
167
- email: input.usernameOrEmail,
168
- role: input.role,
169
- }),
165
+ mutationFn: (input: { email: string; role: AssignableRole }) =>
166
+ oxyServices.accounts.invitations.create(id, input),
170
167
  onSuccess: () => {
171
168
  setInviteIdentifier('');
172
169
  setInviteRole('editor');
173
170
  setInviteError(null);
174
171
  invalidateMembers();
175
- toast.success('Invitation sent');
172
+ toast.success(t('accounts.members.toasts.invited'));
176
173
  },
177
174
  onError: (error) => {
178
175
  invalidateMembers();
179
- toast.error(errorMessage(error, 'Could not send invitation'));
176
+ toast.error(describeApiError(error, t, t('accounts.members.toasts.inviteFailed')));
180
177
  },
181
178
  });
182
179
 
@@ -189,9 +186,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
189
186
  toast.success(t('accounts.members.toasts.roleUpdated') || 'Role updated');
190
187
  },
191
188
  onError: (error) => {
192
- toast.error(
193
- errorMessage(error, t('accounts.members.toasts.roleFailed') || 'Failed to update role'),
194
- );
189
+ toast.error(describeApiError(error, t, t('accounts.members.toasts.roleFailed')));
195
190
  },
196
191
  });
197
192
 
@@ -203,9 +198,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
203
198
  toast.success(t('accounts.members.toasts.removed') || 'Member removed');
204
199
  },
205
200
  onError: (error) => {
206
- toast.error(
207
- errorMessage(error, t('accounts.members.toasts.removeFailed') || 'Failed to remove member'),
208
- );
201
+ toast.error(describeApiError(error, t, t('accounts.members.toasts.removeFailed')));
209
202
  },
210
203
  });
211
204
 
@@ -218,8 +211,9 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
218
211
  },
219
212
  onError: (error) => {
220
213
  toast.error(
221
- errorMessage(
214
+ describeApiError(
222
215
  error,
216
+ t,
223
217
  t('accounts.members.toasts.transferFailed') || 'Failed to transfer ownership',
224
218
  ),
225
219
  );
@@ -227,14 +221,19 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
227
221
  });
228
222
 
229
223
  const handleInvite = useCallback(() => {
230
- const usernameOrEmail = inviteIdentifier.trim();
231
- if (!usernameOrEmail) {
232
- setInviteError('Enter an email to invite');
224
+ if (!inviteIdentifier.trim()) {
225
+ setInviteError(t('accounts.members.errors.emailRequired'));
226
+ return;
227
+ }
228
+ // The contract `POST /accounts/:id/invitations` holds the address to.
229
+ const email = checkContract(emailAddressCheck, inviteIdentifier);
230
+ if (email === null) {
231
+ setInviteError(t('accounts.members.errors.emailInvalid'));
233
232
  return;
234
233
  }
235
234
  setInviteError(null);
236
- inviteMutation.mutate({ usernameOrEmail, role: inviteRole });
237
- }, [inviteIdentifier, inviteRole, inviteMutation]);
235
+ inviteMutation.mutate({ email, role: inviteRole });
236
+ }, [inviteIdentifier, inviteRole, inviteMutation, t]);
238
237
 
239
238
  const handleChangeRole = useCallback(
240
239
  (member: AccountMember, role: AccountRole) => {
@@ -302,11 +301,13 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
302
301
  {/* Invite form */}
303
302
  {canInvite ? (
304
303
  <View className="gap-space-12 p-space-16 rounded-radius-20 bg-fill">
305
- <Text className="text-body font-semibold text-text">{'Invite a member'}</Text>
304
+ <Text className="text-body font-semibold text-text">
305
+ {t('accounts.members.invite.title')}
306
+ </Text>
306
307
  <TextField isInvalid={!!inviteError}>
307
308
  <TextFieldInput
308
309
  floatingLabel
309
- label={'Email'}
310
+ label={t('accounts.members.invite.emailLabel')}
310
311
  value={inviteIdentifier}
311
312
  onChangeText={(value) => {
312
313
  setInviteIdentifier(value);
@@ -316,6 +317,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
316
317
  autoCapitalize="none"
317
318
  autoCorrect={false}
318
319
  autoComplete="off"
320
+ keyboardType="email-address"
319
321
  />
320
322
  </TextField>
321
323
  {inviteError ? (
@@ -350,10 +352,10 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
350
352
  onPress={handleInvite}
351
353
  disabled={inviteMutation.isPending || !inviteIdentifier.trim()}
352
354
  loading={inviteMutation.isPending}
353
- accessibilityLabel={'Send invitation'}
355
+ accessibilityLabel={t('accounts.members.invite.submit')}
354
356
  className="w-full"
355
357
  >
356
- {'Send invitation'}
358
+ {t('accounts.members.invite.submit')}
357
359
  </Button>
358
360
  </View>
359
361
  ) : null}
@@ -15,11 +15,7 @@ import {
15
15
  import {
16
16
  applyBotUsernameSuffix,
17
17
  stripDisallowedUsernameCharacters,
18
- usernameCheckForAccountKind,
19
- BOT_USERNAME_INVALID_MESSAGE,
20
- USERNAME_INVALID_MESSAGE,
21
18
  USERNAME_MAX_LENGTH,
22
- USERNAME_MIN_LENGTH,
23
19
  } from '@oxy.so/contracts/client';
24
20
  import type { BaseScreenProps } from '../types/navigation';
25
21
  import { useI18n } from '../hooks/useI18n';
@@ -32,6 +28,8 @@ import { GroupedSection, GroupedSectionItem } from '@oxy.so/bloom/grouped-sectio
32
28
  import { useOxy } from '../context/oxyRuntimeContext';
33
29
  import { AccountCategoriesSection } from '../components/accountSettings/AccountCategoriesSection';
34
30
  import { toast } from '@oxy.so/bloom/toast';
31
+ import { describeApiError } from '../utils/apiErrorMessage';
32
+ import { checkUsernameDraft, describeUsernameRefusal } from '../utils/usernamePolicy';
35
33
 
36
34
  type UsernameStatus = 'idle' | 'checking' | 'available' | 'taken' | 'invalid';
37
35
 
@@ -169,35 +167,20 @@ const CreateAccountScreen: React.FC<BaseScreenProps> = ({
169
167
  }
170
168
  const seq = ++usernameCheckSeqRef.current;
171
169
 
172
- if (!value || value.length < USERNAME_MIN_LENGTH) {
173
- setUsernameStatus(value.length > 0 ? 'invalid' : 'idle');
174
- setUsernameMessage(
175
- value.length > 0
176
- ? t('accounts.create.username.tooShort') ||
177
- `Username must be at least ${USERNAME_MIN_LENGTH} characters`
178
- : '',
179
- );
170
+ if (!value) {
171
+ setUsernameStatus('idle');
172
+ setUsernameMessage('');
180
173
  return;
181
174
  }
182
175
 
183
- // The ONE policy, from `@oxy.so/contracts`, for the kind being created. This
184
- // screen used to carry a private copy of the rule, and the server it talks to
185
- // enforced a LOOSER one — so a name this field refused was a name
186
- // `POST /accounts` would happily have stored.
187
- //
188
- // WHICH half failed decides the copy: for a bot the rule has two, and telling
189
- // somebody who typed `a.b` to append `bot` sends them to be refused a second
190
- // time. The issue is read to choose between two LOCALIZED strings rather than
191
- // shown directly — the schema's message is English, and this screen is not.
192
- const checked = usernameCheckForAccountKind(forKind)(value, []);
176
+ // The ONE policy, from `@oxy.so/contracts`, for the kind being created
177
+ // (`POST /accounts` holds it to the same one), worded by the rule that
178
+ // failed: telling somebody who typed `a--b` to append `bot` sends them to
179
+ // be refused a second time.
180
+ const checked = checkUsernameDraft(value, t, forKind);
193
181
  if (!checked.ok) {
194
- const failedTheLabel = checked.issue.message === BOT_USERNAME_INVALID_MESSAGE;
195
182
  setUsernameStatus('invalid');
196
- setUsernameMessage(
197
- failedTheLabel
198
- ? t('accounts.create.username.mustEndInBot') || BOT_USERNAME_INVALID_MESSAGE
199
- : t('accounts.create.username.invalidChars') || USERNAME_INVALID_MESSAGE,
200
- );
183
+ setUsernameMessage(checked.error);
201
184
  return;
202
185
  }
203
186
 
@@ -209,18 +192,16 @@ const CreateAccountScreen: React.FC<BaseScreenProps> = ({
209
192
  const result = await oxyServices.auth.checkUsername(value);
210
193
  if (seq !== usernameCheckSeqRef.current) return;
211
194
  setUsernameStatus(result.available ? 'available' : 'taken');
195
+ // The server's `message` is English; the copy is ours.
212
196
  setUsernameMessage(
213
- result.message ||
214
- (result.available
215
- ? t('accounts.create.username.available') || 'Username is available'
216
- : t('accounts.create.username.taken') || 'Username is taken'),
197
+ result.available
198
+ ? t('accounts.create.username.available')
199
+ : t('accounts.create.username.taken'),
217
200
  );
218
201
  } catch {
219
202
  if (seq !== usernameCheckSeqRef.current) return;
220
203
  setUsernameStatus('idle');
221
- setUsernameMessage(
222
- t('accounts.create.username.checkFailed') || 'Could not check availability',
223
- );
204
+ setUsernameMessage(t('accounts.create.username.checkFailed'));
224
205
  }
225
206
  }, DEBOUNCE_MS);
226
207
  },
@@ -326,11 +307,10 @@ const CreateAccountScreen: React.FC<BaseScreenProps> = ({
326
307
 
327
308
  onClose?.();
328
309
  } catch (error) {
329
- const message =
330
- error instanceof Error
331
- ? error.message
332
- : t('accounts.create.toasts.failed') || 'Failed to create account';
333
- toast.error(message);
310
+ toast.error(
311
+ describeUsernameRefusal(error, username, t) ??
312
+ describeApiError(error, t, t('accounts.create.toasts.failed')),
313
+ );
334
314
  } finally {
335
315
  setIsCreating(false);
336
316
  }
@@ -5,7 +5,8 @@ import type { DomainVerificationInstructions, VerifiedDomain } from '@oxy.so/con
5
5
  import { Button } from '@oxy.so/bloom/button';
6
6
  import { GroupedSection, GroupedSectionItem } from '@oxy.so/bloom/grouped-section';
7
7
  import { surfaces } from '@oxy.so/bloom/surfaces';
8
- import { TextField, TextFieldInput, TextFieldLabel } from '@oxy.so/bloom/text-field';
8
+ import { TextField, TextFieldHint, TextFieldInput, TextFieldLabel } from '@oxy.so/bloom/text-field';
9
+ import { DOMAIN_NAME_MAX_LENGTH, normalizeDomainName } from '@oxy.so/contracts/client';
9
10
  import { useTheme } from '@oxy.so/bloom/theme';
10
11
  import { toast } from '@oxy.so/bloom/toast';
11
12
  import { Text } from '@oxy.so/bloom/typography';
@@ -15,9 +16,7 @@ import { useOxy } from '../context/oxyRuntimeContext';
15
16
  import { queryKeys } from '../hooks/queries/queryKeys';
16
17
  import { useI18n } from '../hooks/useI18n';
17
18
  import { useSurfaceHeader } from '../hooks/useSurfaceHeader';
18
-
19
- const errorMessage = (error: unknown, fallback: string): string =>
20
- (error instanceof Error && error.message) || fallback;
19
+ import { describeApiError } from '../utils/apiErrorMessage';
21
20
 
22
21
  /**
23
22
  * DomainsScreen — prove that the signed-in identity controls a web domain.
@@ -35,6 +34,7 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
35
34
  const { oxyServices, user, isAuthenticated } = useOxy();
36
35
 
37
36
  const [domain, setDomain] = useState('');
37
+ const [invalid, setInvalid] = useState(false);
38
38
  const [pending, setPending] = useState<DomainVerificationInstructions | null>(null);
39
39
 
40
40
  const listKey = queryKeys.domains.list(user?.id);
@@ -50,7 +50,7 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
50
50
  setPending(instructions);
51
51
  setDomain('');
52
52
  },
53
- onError: (error) => toast.error(errorMessage(error, t('domains.errors.request'))),
53
+ onError: (error) => toast.error(describeApiError(error, t, t('domains.errors.request'))),
54
54
  });
55
55
 
56
56
  const verify = useMutation({
@@ -64,13 +64,13 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
64
64
  toast.success(t('domains.verified', { domain: result.domain.domain }));
65
65
  void queryClient.invalidateQueries({ queryKey: listKey });
66
66
  },
67
- onError: (error) => toast.error(errorMessage(error, t('domains.errors.notYet'))),
67
+ onError: (error) => toast.error(describeApiError(error, t, t('domains.errors.notYet'))),
68
68
  });
69
69
 
70
70
  const remove = useMutation({
71
71
  mutationFn: (name: string) => oxyServices.identity.domains.remove(name),
72
72
  onSuccess: () => void queryClient.invalidateQueries({ queryKey: listKey }),
73
- onError: (error) => toast.error(errorMessage(error, t('domains.errors.remove'))),
73
+ onError: (error) => toast.error(describeApiError(error, t, t('domains.errors.remove'))),
74
74
  });
75
75
 
76
76
  const confirmRemove = useCallback(
@@ -88,8 +88,14 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
88
88
  );
89
89
 
90
90
  const submit = () => {
91
- const name = domain.trim().toLowerCase();
92
- if (name && !request.isPending) request.mutate(name);
91
+ if (request.isPending || !domain.trim()) return;
92
+ // The same normalization `POST /identity/domains` applies.
93
+ const name = normalizeDomainName(domain);
94
+ if (name === null) {
95
+ setInvalid(true);
96
+ return;
97
+ }
98
+ request.mutate(name);
93
99
  };
94
100
 
95
101
  return (
@@ -135,20 +141,25 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
135
141
  <GroupedSection title={t('domains.add.title')}>
136
142
  <View className="px-space-16 py-space-12" style={styles.instructions}>
137
143
  <TextFieldLabel>{t('domains.add.label')}</TextFieldLabel>
138
- <TextField disabled={request.isPending}>
144
+ <TextField disabled={request.isPending} invalid={invalid}>
139
145
  <TextFieldInput
140
146
  testID="domains-input"
141
147
  label={t('domains.add.label')}
142
148
  value={domain}
143
- onValueChange={setDomain}
149
+ onValueChange={(value) => {
150
+ setDomain(value);
151
+ setInvalid(false);
152
+ }}
144
153
  placeholder="example.com"
145
154
  autoCapitalize="none"
146
155
  autoCorrect={false}
147
156
  keyboardType="url"
157
+ maxLength={DOMAIN_NAME_MAX_LENGTH}
148
158
  returnKeyType="go"
149
159
  onSubmitEditing={submit}
150
160
  />
151
161
  </TextField>
162
+ {invalid ? <TextFieldHint invalid>{t('domains.errors.invalid')}</TextFieldHint> : null}
152
163
  <Button
153
164
  appearance="solid"
154
165
  tone="action"