@oxy.so/services 15.0.1 → 15.0.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 (91) hide show
  1. package/android/src/main/java/so/oxy/security/OxyCallerPolicy.kt +0 -2
  2. package/lib/commonjs/ui/components/OxyProvider.js +8 -1
  3. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  4. package/lib/commonjs/ui/components/accountDialogHost.js +48 -0
  5. package/lib/commonjs/ui/components/accountDialogHost.js.map +1 -0
  6. package/lib/commonjs/ui/components/authChooser/primitives.js +5 -3
  7. package/lib/commonjs/ui/components/authChooser/primitives.js.map +1 -1
  8. package/lib/commonjs/ui/components/signIn/InlineCommonsQr.js +28 -25
  9. package/lib/commonjs/ui/components/signIn/InlineCommonsQr.js.map +1 -1
  10. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js +63 -23
  11. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js.map +1 -1
  12. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js +94 -26
  13. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  14. package/lib/commonjs/ui/hooks/useUsernameAvailability.js +21 -7
  15. package/lib/commonjs/ui/hooks/useUsernameAvailability.js.map +1 -1
  16. package/lib/commonjs/ui/screens/OxyOneScreen.js +2 -2
  17. package/lib/commonjs/ui/screens/OxyOneScreen.js.map +1 -1
  18. package/lib/commonjs/ui/utils/handlePreview.js +20 -0
  19. package/lib/commonjs/ui/utils/handlePreview.js.map +1 -0
  20. package/lib/commonjs/ui/utils/usernameLookupBudget.js +95 -0
  21. package/lib/commonjs/ui/utils/usernameLookupBudget.js.map +1 -0
  22. package/lib/module/ui/components/OxyProvider.js +8 -1
  23. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  24. package/lib/module/ui/components/accountDialogHost.js +42 -0
  25. package/lib/module/ui/components/accountDialogHost.js.map +1 -0
  26. package/lib/module/ui/components/authChooser/primitives.js +5 -3
  27. package/lib/module/ui/components/authChooser/primitives.js.map +1 -1
  28. package/lib/module/ui/components/signIn/InlineCommonsQr.js +28 -25
  29. package/lib/module/ui/components/signIn/InlineCommonsQr.js.map +1 -1
  30. package/lib/module/ui/components/signIn/OxySignInPanel.js +64 -24
  31. package/lib/module/ui/components/signIn/OxySignInPanel.js.map +1 -1
  32. package/lib/module/ui/components/signIn/OxySignUpPanel.js +95 -27
  33. package/lib/module/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  34. package/lib/module/ui/hooks/useUsernameAvailability.js +21 -7
  35. package/lib/module/ui/hooks/useUsernameAvailability.js.map +1 -1
  36. package/lib/module/ui/screens/OxyOneScreen.js +2 -2
  37. package/lib/module/ui/screens/OxyOneScreen.js.map +1 -1
  38. package/lib/module/ui/utils/handlePreview.js +16 -0
  39. package/lib/module/ui/utils/handlePreview.js.map +1 -0
  40. package/lib/module/ui/utils/usernameLookupBudget.js +88 -0
  41. package/lib/module/ui/utils/usernameLookupBudget.js.map +1 -0
  42. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/ui/components/accountDialogHost.d.ts +24 -0
  44. package/lib/typescript/commonjs/ui/components/accountDialogHost.d.ts.map +1 -0
  45. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts +5 -3
  46. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/ui/components/signIn/InlineCommonsQr.d.ts +6 -0
  48. package/lib/typescript/commonjs/ui/components/signIn/InlineCommonsQr.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts +4 -2
  50. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts +12 -2
  52. package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/ui/hooks/useUsernameAvailability.d.ts +15 -1
  54. package/lib/typescript/commonjs/ui/hooks/useUsernameAvailability.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/ui/types/navigation.d.ts +14 -0
  56. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/ui/utils/handlePreview.d.ts +10 -0
  58. package/lib/typescript/commonjs/ui/utils/handlePreview.d.ts.map +1 -0
  59. package/lib/typescript/commonjs/ui/utils/usernameLookupBudget.d.ts +36 -0
  60. package/lib/typescript/commonjs/ui/utils/usernameLookupBudget.d.ts.map +1 -0
  61. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  62. package/lib/typescript/module/ui/components/accountDialogHost.d.ts +24 -0
  63. package/lib/typescript/module/ui/components/accountDialogHost.d.ts.map +1 -0
  64. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts +5 -3
  65. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts.map +1 -1
  66. package/lib/typescript/module/ui/components/signIn/InlineCommonsQr.d.ts +6 -0
  67. package/lib/typescript/module/ui/components/signIn/InlineCommonsQr.d.ts.map +1 -1
  68. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts +4 -2
  69. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  70. package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts +12 -2
  71. package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
  72. package/lib/typescript/module/ui/hooks/useUsernameAvailability.d.ts +15 -1
  73. package/lib/typescript/module/ui/hooks/useUsernameAvailability.d.ts.map +1 -1
  74. package/lib/typescript/module/ui/types/navigation.d.ts +14 -0
  75. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  76. package/lib/typescript/module/ui/utils/handlePreview.d.ts +10 -0
  77. package/lib/typescript/module/ui/utils/handlePreview.d.ts.map +1 -0
  78. package/lib/typescript/module/ui/utils/usernameLookupBudget.d.ts +36 -0
  79. package/lib/typescript/module/ui/utils/usernameLookupBudget.d.ts.map +1 -0
  80. package/package.json +3 -3
  81. package/src/ui/components/OxyProvider.tsx +11 -1
  82. package/src/ui/components/accountDialogHost.tsx +54 -0
  83. package/src/ui/components/authChooser/primitives.tsx +5 -3
  84. package/src/ui/components/signIn/InlineCommonsQr.tsx +24 -18
  85. package/src/ui/components/signIn/OxySignInPanel.tsx +64 -22
  86. package/src/ui/components/signIn/OxySignUpPanel.tsx +115 -26
  87. package/src/ui/hooks/useUsernameAvailability.ts +42 -7
  88. package/src/ui/screens/OxyOneScreen.tsx +2 -2
  89. package/src/ui/types/navigation.ts +14 -0
  90. package/src/ui/utils/handlePreview.ts +16 -0
  91. package/src/ui/utils/usernameLookupBudget.ts +91 -0
@@ -4,8 +4,10 @@
4
4
  * differs (`host`). Sign-in happens IN it, on every origin: no window opens.
5
5
  *
6
6
  * picker a returning device: "Choose an account", then "Use another account"
7
- * identifier the header, the Commons way in, and "Email or username" with its
8
- * Continue. On the web, from `md`, the screen is Bloom `AuthCard`'s
7
+ * identifier the header (what an Oxy account is, naming the host app when the
8
+ * dialog knows it), the Commons way in, and "Email or username"
9
+ * with its Continue, then a Create account button. On the web,
10
+ * from `md`, the screen is Bloom `AuthCard`'s
9
11
  * split card and the Commons way in is the embedded QR over its
10
12
  * photo carousel, in the right column (the account dialog grows to
11
13
  * that card); below `md` it is "Continue with Oxy" at the top. A
@@ -29,7 +31,7 @@
29
31
 
30
32
  import type React from 'react';
31
33
  import { useCallback, useEffect, useRef, useState } from 'react';
32
- import { Linking, Platform, Text as RNText, StyleSheet, View } from 'react-native';
34
+ import { Linking, Platform, StyleSheet, View } from 'react-native';
33
35
  import { AuthMediaCarousel } from '@oxy.so/bloom/auth-card';
34
36
  import { Button } from '@oxy.so/bloom/button';
35
37
  import { Divider } from '@oxy.so/bloom/divider';
@@ -61,6 +63,7 @@ import { useSurfaceFrameWidth } from '../../hooks/useSurfaceFrameWidth';
61
63
  import { getCommonsAcquisitionUrl } from '../../utils/commonsStoreLinks';
62
64
  import { resolveSignInDevice } from '../../utils/signInDevice';
63
65
  import { SubtleLink } from '../authChooser/primitives';
66
+ import { useAccountDialogHost } from '../accountDialogHost';
64
67
  import { SIGN_IN_SLIDES } from './artwork';
65
68
  import { InlineCommonsQr } from './InlineCommonsQr';
66
69
  import { OxyAccountPicker } from './OxyAccountPicker';
@@ -147,6 +150,9 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
147
150
  }) => {
148
151
  const theme = useTheme();
149
152
  const { t } = useI18n();
153
+ const hostDialog = useAccountDialogHost();
154
+ // A prop wins; otherwise the hosting app's `OxyProvider`. Blank names none.
155
+ const resolvedAppName = (appName ?? hostDialog.appName)?.trim() || null;
150
156
  const {
151
157
  accountDialogController: controller,
152
158
  openAccountDialog,
@@ -528,7 +534,7 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
528
534
  return (
529
535
  <OxyAccountPicker
530
536
  principals={principals}
531
- appName={appName}
537
+ appName={resolvedAppName}
532
538
  signedOut={!snapshot.hasSession}
533
539
  pendingContextId={snapshot.activatingContextId}
534
540
  isLoading={snapshot.activatingContextId !== null}
@@ -781,9 +787,12 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
781
787
  const title = adding ? t('signin.addAccountTitle') : t('signin.title');
782
788
  const description = adding
783
789
  ? t('signin.addAccountSubtitle')
784
- : appName
785
- ? t('signin.subtitleToApp', { app: appName })
790
+ : resolvedAppName
791
+ ? t('signin.subtitleToApp', { app: resolvedAppName })
786
792
  : t('signin.subtitle');
793
+ const oneAccount = resolvedAppName
794
+ ? t('signin.oneAccountInApp', { app: resolvedAppName })
795
+ : t('signin.oneAccount');
787
796
 
788
797
  const continueWithOxyButton = (
789
798
  <Button
@@ -801,7 +810,22 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
801
810
 
802
811
  form = (
803
812
  <OxyAuthScreen inSplit={splits}>
804
- <OxyAuthScreenHeader title={title} description={description} />
813
+ <OxyAuthScreenHeader
814
+ title={title}
815
+ description={
816
+ <View style={styles.intro}>
817
+ <Text style={[styles.introLine, { color: theme.colors.textSecondary }]}>
818
+ {description}
819
+ </Text>
820
+ <Text
821
+ testID="signin-one-account"
822
+ style={[styles.oneAccount, { color: theme.colors.textSecondary }]}
823
+ >
824
+ {oneAccount}
825
+ </Text>
826
+ </View>
827
+ }
828
+ />
805
829
 
806
830
  {/* The Commons way in, then the email. On the web from `md` the QR
807
831
  beside the form IS the Commons way in; below `md` this screen is
@@ -855,17 +879,6 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
855
879
  autoFocus={device !== 'phone'}
856
880
  testID="signin-identifier"
857
881
  />
858
- <Text style={[styles.note, styles.noAccount, { color: theme.colors.textSecondary }]}>
859
- {t('signin.noAccount')}{' '}
860
- <RNText
861
- accessibilityRole="link"
862
- onPress={onCreateAccount}
863
- style={[styles.noAccountLink, { color: theme.colors.text }]}
864
- testID="create-account-link"
865
- >
866
- {t('signin.createAccount')}
867
- </RNText>
868
- </Text>
869
882
  {rateLimitNotice}
870
883
  <AccountFlowAction
871
884
  label={t('signin.actions.continue')}
@@ -874,6 +887,22 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
874
887
  disabled={rateLimitSeconds > 0}
875
888
  testID="signin-identifier-continue"
876
889
  />
890
+ <View style={styles.createAccount}>
891
+ <Text style={[styles.createAccountPrompt, { color: theme.colors.textSecondary }]}>
892
+ {t('signin.noAccount')}
893
+ </Text>
894
+ <Button
895
+ appearance="outline"
896
+ tone="neutral"
897
+ size="lg"
898
+ fullWidth
899
+ onPress={onCreateAccount}
900
+ accessibilityLabel={t('signin.createAccount')}
901
+ testID="create-account-link"
902
+ >
903
+ {t('signin.createAccount')}
904
+ </Button>
905
+ </View>
877
906
  </View>
878
907
  <OxyAuthTerms />
879
908
  </OxyAuthScreen>
@@ -911,10 +940,23 @@ const styles = StyleSheet.create({
911
940
  lineHeight: 20,
912
941
  textAlign: 'center',
913
942
  },
914
- noAccount: {
915
- textAlign: 'left',
943
+ intro: {
944
+ gap: 8,
945
+ },
946
+ introLine: {
947
+ fontSize: 18,
948
+ lineHeight: 28,
916
949
  },
917
- noAccountLink: {
918
- textDecorationLine: 'underline',
950
+ oneAccount: {
951
+ fontSize: 16,
952
+ lineHeight: 24,
953
+ },
954
+ createAccount: {
955
+ gap: 8,
956
+ },
957
+ createAccountPrompt: {
958
+ fontSize: 16,
959
+ lineHeight: 22,
960
+ textAlign: 'center',
919
961
  },
920
962
  });
@@ -10,16 +10,20 @@
10
10
  * The email is confirmed before the account exists, and it is how the account
11
11
  * signs in (a code or a link each time). A password and an authenticator app
12
12
  * are added later, in the account's security settings. Commons stays the way to
13
- * hold your own key: "Create it in Commons instead" — and linking Commons later
14
- * makes the account self-custodied and deletes the email.
13
+ * hold your own key: the username step says what that means, then "Create it in
14
+ * Commons instead" — and linking Commons later makes the account self-custodied
15
+ * and deletes the email. A host may preview the profile the username becomes
16
+ * (`handlePreviewTemplate`); this screen never names an app's domain itself.
15
17
  */
16
18
 
17
19
  import type React from 'react';
18
20
  import { useEffect, useState } from 'react';
19
- import { Linking, Platform, View } from 'react-native';
21
+ import { Linking, Platform, StyleSheet, View } from 'react-native';
20
22
  import { DatePicker } from '@oxy.so/bloom/date-picker';
21
23
  import { TextFieldLabel } from '@oxy.so/bloom/text-field';
24
+ import { useTheme } from '@oxy.so/bloom/theme';
22
25
  import { toast } from '@oxy.so/bloom/toast';
26
+ import { Text } from '@oxy.so/bloom/typography';
23
27
  import type { EmailVerificationConfirmResponse } from '@oxy.so/contracts';
24
28
  import {
25
29
  MIN_BIRTH_YEAR,
@@ -33,11 +37,18 @@ import {
33
37
  import { useOxy } from '../../context/oxyRuntimeContext';
34
38
  import { useAccountDialogSnapshot } from '../../hooks/accountDialogSnapshot';
35
39
  import { useI18n } from '../../hooks/useI18n';
40
+ import { useUsernameAvailability } from '../../hooks/useUsernameAvailability';
36
41
  import { getCommonsAcquisitionUrl } from '../../utils/commonsStoreLinks';
37
42
  import { isWebBrowser } from '../../utils/isWebBrowser';
38
43
  import { fromCalendarDate, toCalendarDate } from '../../utils/calendarDate';
44
+ import { renderHandlePreview } from '../../utils/handlePreview';
45
+ import {
46
+ shareUsernameLookup,
47
+ usernameLookupCooldownSeconds,
48
+ } from '../../utils/usernameLookupBudget';
39
49
  import { checkUsernameDraft, describeUsernameRefusal } from '../../utils/usernamePolicy';
40
50
  import { SubtleLink } from '../authChooser/primitives';
51
+ import { useAccountDialogHost } from '../accountDialogHost';
41
52
  import { OxyAuthScreen, OxyAuthScreenHeader, OxyAuthTerms } from './OxyAuthScreen';
42
53
  import { readSignInFlow, writeSignInFlow } from './signInFlowStore';
43
54
  import {
@@ -70,6 +81,14 @@ export interface OxySignUpPanelProps {
70
81
  * this screen (`signInFlowStore`). `page` — a page of its own.
71
82
  */
72
83
  host?: 'dialog' | 'page';
84
+ /**
85
+ * Preview of the public profile this username becomes. `{username}` is
86
+ * replaced with the typed handle. The host writes its own origin, for
87
+ * example `{base}/@{username}` with that base already filled in. Omitted,
88
+ * the screen uses the template from `OxyProvider`, or shows none. Wins over
89
+ * the provider when both are set.
90
+ */
91
+ handlePreviewTemplate?: string | null;
73
92
  }
74
93
 
75
94
  /** What the dialog keeps of this screen across a remount. */
@@ -86,8 +105,11 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
86
105
  onSignedIn,
87
106
  onSignIn,
88
107
  host = 'page',
108
+ handlePreviewTemplate,
89
109
  }) => {
110
+ const theme = useTheme();
90
111
  const { t } = useI18n();
112
+ const hostDialog = useAccountDialogHost();
91
113
  const {
92
114
  oxyServices,
93
115
  handleWebSession,
@@ -104,6 +126,22 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
104
126
  const [dateOfBirth, setDateOfBirth] = useState(saved?.dateOfBirth ?? '');
105
127
  const [pending, setPending] = useState(false);
106
128
  const [error, setError] = useState<string | null>(null);
129
+ // A new account is not the one already signed in on this device, so a matching
130
+ // handle is checked rather than treated as "unchanged".
131
+ const availability = useUsernameAvailability(username, step.name === 'username', {
132
+ matchCurrentUser: false,
133
+ // Preview lookups share the ten-a-minute quota with the check below.
134
+ reserveSubmit: true,
135
+ });
136
+ const previewTemplate = (handlePreviewTemplate ?? hostDialog.handlePreviewTemplate)?.trim() || '';
137
+ const handlePreview = renderHandlePreview(previewTemplate, username);
138
+ const liveTaken =
139
+ !error && availability.status === 'taken' && availability.candidate === username.trim();
140
+ const showAvailable =
141
+ !error &&
142
+ availability.status === 'available' &&
143
+ availability.candidate === username.trim() &&
144
+ username.trim().length > 0;
107
145
 
108
146
  useEffect(() => {
109
147
  writeSignInFlow(flowOwner, SIGN_UP_FLOW_KEY, {
@@ -141,9 +179,23 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
141
179
  }
142
180
  const handle = draft.username;
143
181
  setUsername(handle);
182
+ // The live check already answered for this exact handle.
183
+ if (availability.status === 'taken' && availability.candidate === handle) {
184
+ setError(t('signup.username.taken'));
185
+ return;
186
+ }
144
187
  run(async () => {
145
- const { available } = await oxyServices.auth.checkUsername(handle);
146
- if (!available) throw new UsernameTakenError();
188
+ // Reuses the preview's answer for this exact handle, or the one lookup
189
+ // the preview left unused. Past that, wait out the window — sending
190
+ // would be refused and the refusal would count too.
191
+ const outcome = await shareUsernameLookup(handle, 'submit', (name) =>
192
+ oxyServices.auth.checkUsername(name),
193
+ );
194
+ if (outcome === 'deferred') {
195
+ setError(t('signin.errors.rateLimited', { seconds: usernameLookupCooldownSeconds() }));
196
+ return;
197
+ }
198
+ if (!outcome.available) throw new UsernameTakenError();
147
199
  setStep({ name: 'birthdate' });
148
200
  });
149
201
  };
@@ -344,33 +396,57 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
344
396
  <OxyAuthScreen>
345
397
  <OxyAuthScreenHeader title={t('signup.title')} description={t('signup.subtitle')} />
346
398
  {progress(0)}
347
- <AccountFlowField
348
- label={t('signup.username.label')}
349
- value={username}
350
- onChange={(value) => {
351
- setUsername(stripDisallowedUsernameCharacters(value));
352
- if (error) setError(null);
353
- }}
354
- onSubmit={submitUsername}
355
- error={error}
356
- disabled={pending}
357
- placeholder={t('signup.username.placeholder')}
358
- hint={t('usernamePolicy.hint')}
359
- maxLength={USERNAME_MAX_LENGTH}
360
- autoComplete="username"
361
- testID="signup-username"
362
- />
399
+ <View style={styles.usernameBlock}>
400
+ <AccountFlowField
401
+ label={t('signup.username.label')}
402
+ value={username}
403
+ onChange={(value) => {
404
+ setUsername(stripDisallowedUsernameCharacters(value));
405
+ if (error) setError(null);
406
+ }}
407
+ onSubmit={submitUsername}
408
+ error={error ?? (liveTaken ? t('signup.username.taken') : null)}
409
+ disabled={pending}
410
+ placeholder={t('signup.username.placeholder')}
411
+ hint={t('usernamePolicy.hint')}
412
+ maxLength={USERNAME_MAX_LENGTH}
413
+ autoComplete="username"
414
+ testID="signup-username"
415
+ />
416
+ {showAvailable ? (
417
+ <Text
418
+ testID="signup-username-status"
419
+ accessibilityLiveRegion="polite"
420
+ style={[styles.status, { color: theme.colors.success }]}
421
+ >
422
+ {t('signup.username.available')}
423
+ </Text>
424
+ ) : null}
425
+ {handlePreview ? (
426
+ <Text
427
+ testID="signup-handle-preview"
428
+ style={[styles.status, { color: theme.colors.textSecondary }]}
429
+ >
430
+ {handlePreview}
431
+ </Text>
432
+ ) : null}
433
+ </View>
363
434
  <AccountFlowAction
364
435
  label={t('signin.actions.continue')}
365
436
  onPress={submitUsername}
366
437
  pending={pending}
367
438
  testID="signup-username-continue"
368
439
  />
369
- <SubtleLink
370
- label={t('signup.createInCommons')}
371
- onPress={createInCommons}
372
- testID="signup-commons-instead"
373
- />
440
+ <View style={styles.commons}>
441
+ <AccountFlowNote testID="signup-commons-note">
442
+ {t('signup.commonsSubtitle')}
443
+ </AccountFlowNote>
444
+ <SubtleLink
445
+ label={t('signup.createInCommons')}
446
+ onPress={createInCommons}
447
+ testID="signup-commons-instead"
448
+ />
449
+ </View>
374
450
  <SubtleLink
375
451
  label={t('signup.backToSignInLink')}
376
452
  onPress={onSignIn}
@@ -384,3 +460,16 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
384
460
 
385
461
  /** The username was taken between typing it and creating the account. */
386
462
  class UsernameTakenError extends Error {}
463
+
464
+ const styles = StyleSheet.create({
465
+ usernameBlock: {
466
+ gap: 8,
467
+ },
468
+ status: {
469
+ fontSize: 16,
470
+ lineHeight: 22,
471
+ },
472
+ commons: {
473
+ gap: 8,
474
+ },
475
+ });
@@ -1,19 +1,44 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { useOxy } from '../context/oxyRuntimeContext';
3
+ import { shareUsernameLookup } from '../utils/usernameLookupBudget';
3
4
  import { checkUsernameDraft } from '../utils/usernamePolicy';
4
5
  import { useI18n } from './useI18n';
5
6
 
6
- type CheckResult = { candidate: string; status: 'available' | 'taken' | 'error' };
7
+ type CheckResult = {
8
+ candidate: string;
9
+ status: 'available' | 'taken' | 'error' | 'deferred';
10
+ };
11
+
12
+ export interface UsernameAvailabilityOptions {
13
+ /**
14
+ * When true (the default), a handle that already belongs to the signed-in
15
+ * account is "unchanged" and is not sent to the server. Signup passes false:
16
+ * a new account needs its own free handle, even on a device that is signed in.
17
+ */
18
+ matchCurrentUser?: boolean;
19
+ /**
20
+ * Count preview lookups against the production ten-a-minute quota and stop
21
+ * one short of it. Signup sets this so Continue still has a lookup left.
22
+ * Profile editing leaves it off: saving there does not look the name up again.
23
+ */
24
+ reserveSubmit?: boolean;
25
+ }
7
26
 
8
27
  /** Debounced server check; a response only applies to the draft that requested it. */
9
- export function useUsernameAvailability(value: string, enabled: boolean) {
28
+ export function useUsernameAvailability(
29
+ value: string,
30
+ enabled: boolean,
31
+ options?: UsernameAvailabilityOptions,
32
+ ) {
10
33
  const { oxyServices, user } = useOxy();
11
34
  const { t } = useI18n();
35
+ const matchCurrentUser = options?.matchCurrentUser !== false;
36
+ const reserveSubmit = options?.reserveSubmit === true;
12
37
  const candidate = value.trim();
13
38
  // The policy of the signed-in account's kind: a bot's handle ends in `bot`.
14
39
  const checked = enabled ? checkUsernameDraft(candidate, t, user?.kind) : null;
15
40
  const invalid = checked && !checked.ok ? checked.error : undefined;
16
- const unchanged = candidate.toLowerCase() === user?.username?.toLowerCase();
41
+ const unchanged = matchCurrentUser && candidate.toLowerCase() === user?.username?.toLowerCase();
17
42
  const [result, setResult] = useState<CheckResult>();
18
43
  const [attempt, setAttempt] = useState(0);
19
44
 
@@ -23,9 +48,19 @@ export function useUsernameAvailability(value: string, enabled: boolean) {
23
48
  setResult(undefined);
24
49
  let active = true;
25
50
  const timer = setTimeout(() => {
26
- void oxyServices.auth.checkUsername(candidate).then(
27
- ({ available }) => {
28
- if (active) setResult({ candidate, status: available ? 'available' : 'taken' });
51
+ const lookup = reserveSubmit
52
+ ? shareUsernameLookup(candidate, 'background', (name) =>
53
+ oxyServices.auth.checkUsername(name),
54
+ )
55
+ : oxyServices.auth.checkUsername(candidate).then(({ available }) => ({ available }));
56
+ void lookup.then(
57
+ (outcome) => {
58
+ if (!active) return;
59
+ if (outcome === 'deferred') {
60
+ setResult({ candidate, status: 'deferred' });
61
+ return;
62
+ }
63
+ setResult({ candidate, status: outcome.available ? 'available' : 'taken' });
29
64
  },
30
65
  () => {
31
66
  if (active) setResult({ candidate, status: 'error' });
@@ -36,7 +71,7 @@ export function useUsernameAvailability(value: string, enabled: boolean) {
36
71
  active = false;
37
72
  clearTimeout(timer);
38
73
  };
39
- }, [candidate, enabled, invalid, unchanged, oxyServices, attempt]);
74
+ }, [candidate, enabled, invalid, unchanged, oxyServices, attempt, reserveSubmit]);
40
75
 
41
76
  const status = !enabled
42
77
  ? 'idle'
@@ -27,8 +27,8 @@ import { useSurfaceHeader } from '../hooks/useSurfaceHeader';
27
27
 
28
28
  const apps = {
29
29
  personal: ['alia', 'mention', 'inbox', 'noted', 'clarity', 'homiio'],
30
- creator: ['alia', 'mention', 'inbox', 'noted', 'clarity', 'schedio', 'mercaria'],
31
- business: ['alia', 'mention', 'inbox', 'noted', 'clarity', 'schedio'],
30
+ creator: ['alia', 'mention', 'inbox', 'noted', 'clarity', 'mercaria'],
31
+ business: ['alia', 'mention', 'inbox', 'noted', 'clarity'],
32
32
  } as const;
33
33
 
34
34
  /** The shared Bloom presentation, populated with Oxy's approved commercial terms.
@@ -86,6 +86,20 @@ export interface OxyProviderProps {
86
86
  * flow cannot start.
87
87
  */
88
88
  clientId?: string;
89
+ /**
90
+ * The app this provider's account dialog is signing into. When set, the
91
+ * sign-in screen says that one Oxy account works across this app and the
92
+ * others. Omitted, the line stays generic and names no app.
93
+ */
94
+ appName?: string;
95
+ /**
96
+ * Preview of the public profile a new username becomes, shown while signing
97
+ * up. `{username}` is replaced with the typed handle. Pass the host's own
98
+ * profile path, for example `{base}/@{username}` with the host's origin
99
+ * already written in place of `{base}` (`https://example.com/@{username}`).
100
+ * This SDK does not know or insert an app's domain.
101
+ */
102
+ handlePreviewTemplate?: string;
89
103
  baseURL?: string;
90
104
  authWebUrl?: string;
91
105
  authRedirectUri?: string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The public profile a typed username would have, from a host template.
3
+ *
4
+ * `{username}` is the only token. The host writes its own origin into the
5
+ * template — `{base}/@{username}` means that host's base, not a domain this
6
+ * SDK knows. An empty handle, or a template with no `{username}`, previews
7
+ * nothing.
8
+ */
9
+ export function renderHandlePreview(
10
+ template: string | null | undefined,
11
+ username: string,
12
+ ): string | null {
13
+ const handle = username.trim();
14
+ if (!template || !handle || !template.includes('{username}')) return null;
15
+ return template.split('{username}').join(handle);
16
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Shared budget for `GET /auth/check-username`.
3
+ *
4
+ * Outside development that route allows ten lookups a minute per IP
5
+ * (`checkLimiter` in `packages/api/src/routes/auth.ts`). Signup spends the
6
+ * same budget on a debounced preview while a name is typed and again when
7
+ * Continue confirms it. Preview stops one short of the limit, so typing
8
+ * cannot take the request Continue needs. A lookup already in flight or
9
+ * already answered for the same name is reused. Creating the account still
10
+ * checks uniqueness on its own.
11
+ */
12
+
13
+ /** Production ceiling of `checkLimiter`. Development's higher cap is ignored. */
14
+ export const USERNAME_LOOKUP_LIMIT = 10;
15
+
16
+ /** How long `checkLimiter` remembers a lookup. */
17
+ export const USERNAME_LOOKUP_WINDOW_MS = 60_000;
18
+
19
+ /**
20
+ * Preview lookups a single window may start. One slot stays for an explicit
21
+ * submit (`Continue`), which is the request typing must not spend.
22
+ */
23
+ export const USERNAME_LOOKUP_BACKGROUND_MAX = USERNAME_LOOKUP_LIMIT - 1;
24
+
25
+ export type UsernameLookupPurpose = 'background' | 'submit';
26
+
27
+ type Settled = { at: number; available: boolean };
28
+
29
+ const sentAt: number[] = [];
30
+ const settled = new Map<string, Settled>();
31
+ const inflight = new Map<string, Promise<{ available: boolean }>>();
32
+
33
+ /** Tests start from an empty window. */
34
+ export function resetUsernameLookupBudget(): void {
35
+ sentAt.length = 0;
36
+ settled.clear();
37
+ inflight.clear();
38
+ }
39
+
40
+ function prune(now: number): void {
41
+ const cutoff = now - USERNAME_LOOKUP_WINDOW_MS;
42
+ while (sentAt.length > 0 && sentAt[0] <= cutoff) sentAt.shift();
43
+ for (const [key, value] of settled) {
44
+ if (value.at <= cutoff) settled.delete(key);
45
+ }
46
+ }
47
+
48
+ function roomFor(purpose: UsernameLookupPurpose): number {
49
+ return purpose === 'background' ? USERNAME_LOOKUP_BACKGROUND_MAX : USERNAME_LOOKUP_LIMIT;
50
+ }
51
+
52
+ /** Seconds until a full window will accept another explicit lookup. `0` when it already can. */
53
+ export function usernameLookupCooldownSeconds(now = Date.now()): number {
54
+ prune(now);
55
+ if (sentAt.length < USERNAME_LOOKUP_LIMIT) return 0;
56
+ const oldest = sentAt[0];
57
+ if (oldest === undefined) return 0;
58
+ return Math.max(1, Math.ceil((oldest + USERNAME_LOOKUP_WINDOW_MS - now) / 1000));
59
+ }
60
+
61
+ /**
62
+ * One network lookup per name at a time, counted against the production quota.
63
+ * `'deferred'` means this call would have been one past the purpose's room, so
64
+ * the caller must not hit the API (a 429 counts against the same window).
65
+ */
66
+ export async function shareUsernameLookup(
67
+ username: string,
68
+ purpose: UsernameLookupPurpose,
69
+ check: (username: string) => Promise<{ available: boolean }>,
70
+ ): Promise<{ available: boolean } | 'deferred'> {
71
+ const key = username.trim().toLowerCase();
72
+ const now = Date.now();
73
+ prune(now);
74
+ const cached = settled.get(key);
75
+ if (cached) return { available: cached.available };
76
+ const pending = inflight.get(key);
77
+ if (pending) return pending;
78
+ if (sentAt.length >= roomFor(purpose)) return 'deferred';
79
+ // Record before the request starts so a second caller in this turn sees it.
80
+ sentAt.push(now);
81
+ const request = check(username).then((result) => {
82
+ settled.set(key, { at: Date.now(), available: result.available });
83
+ return result;
84
+ });
85
+ inflight.set(key, request);
86
+ try {
87
+ return await request;
88
+ } finally {
89
+ inflight.delete(key);
90
+ }
91
+ }