@oxy.so/services 15.0.0 → 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 (101) 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/oauth/browserBridge.js +15 -1
  17. package/lib/commonjs/ui/oauth/browserBridge.js.map +1 -1
  18. package/lib/commonjs/ui/screens/OxyOneScreen.js +2 -2
  19. package/lib/commonjs/ui/screens/OxyOneScreen.js.map +1 -1
  20. package/lib/commonjs/ui/utils/handlePreview.js +20 -0
  21. package/lib/commonjs/ui/utils/handlePreview.js.map +1 -0
  22. package/lib/commonjs/ui/utils/usernameLookupBudget.js +95 -0
  23. package/lib/commonjs/ui/utils/usernameLookupBudget.js.map +1 -0
  24. package/lib/module/ui/components/OxyProvider.js +8 -1
  25. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  26. package/lib/module/ui/components/accountDialogHost.js +42 -0
  27. package/lib/module/ui/components/accountDialogHost.js.map +1 -0
  28. package/lib/module/ui/components/authChooser/primitives.js +5 -3
  29. package/lib/module/ui/components/authChooser/primitives.js.map +1 -1
  30. package/lib/module/ui/components/signIn/InlineCommonsQr.js +28 -25
  31. package/lib/module/ui/components/signIn/InlineCommonsQr.js.map +1 -1
  32. package/lib/module/ui/components/signIn/OxySignInPanel.js +64 -24
  33. package/lib/module/ui/components/signIn/OxySignInPanel.js.map +1 -1
  34. package/lib/module/ui/components/signIn/OxySignUpPanel.js +95 -27
  35. package/lib/module/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  36. package/lib/module/ui/hooks/useUsernameAvailability.js +21 -7
  37. package/lib/module/ui/hooks/useUsernameAvailability.js.map +1 -1
  38. package/lib/module/ui/oauth/browserBridge.js +14 -0
  39. package/lib/module/ui/oauth/browserBridge.js.map +1 -1
  40. package/lib/module/ui/screens/OxyOneScreen.js +2 -2
  41. package/lib/module/ui/screens/OxyOneScreen.js.map +1 -1
  42. package/lib/module/ui/utils/handlePreview.js +16 -0
  43. package/lib/module/ui/utils/handlePreview.js.map +1 -0
  44. package/lib/module/ui/utils/usernameLookupBudget.js +88 -0
  45. package/lib/module/ui/utils/usernameLookupBudget.js.map +1 -0
  46. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/ui/components/accountDialogHost.d.ts +24 -0
  48. package/lib/typescript/commonjs/ui/components/accountDialogHost.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts +5 -3
  50. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/ui/components/signIn/InlineCommonsQr.d.ts +6 -0
  52. package/lib/typescript/commonjs/ui/components/signIn/InlineCommonsQr.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts +4 -2
  54. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts +12 -2
  56. package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/ui/hooks/useUsernameAvailability.d.ts +15 -1
  58. package/lib/typescript/commonjs/ui/hooks/useUsernameAvailability.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/ui/oauth/browserBridge.d.ts +4 -0
  60. package/lib/typescript/commonjs/ui/oauth/browserBridge.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/ui/types/navigation.d.ts +14 -0
  62. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  63. package/lib/typescript/commonjs/ui/utils/handlePreview.d.ts +10 -0
  64. package/lib/typescript/commonjs/ui/utils/handlePreview.d.ts.map +1 -0
  65. package/lib/typescript/commonjs/ui/utils/usernameLookupBudget.d.ts +36 -0
  66. package/lib/typescript/commonjs/ui/utils/usernameLookupBudget.d.ts.map +1 -0
  67. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  68. package/lib/typescript/module/ui/components/accountDialogHost.d.ts +24 -0
  69. package/lib/typescript/module/ui/components/accountDialogHost.d.ts.map +1 -0
  70. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts +5 -3
  71. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts.map +1 -1
  72. package/lib/typescript/module/ui/components/signIn/InlineCommonsQr.d.ts +6 -0
  73. package/lib/typescript/module/ui/components/signIn/InlineCommonsQr.d.ts.map +1 -1
  74. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts +4 -2
  75. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  76. package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts +12 -2
  77. package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
  78. package/lib/typescript/module/ui/hooks/useUsernameAvailability.d.ts +15 -1
  79. package/lib/typescript/module/ui/hooks/useUsernameAvailability.d.ts.map +1 -1
  80. package/lib/typescript/module/ui/oauth/browserBridge.d.ts +4 -0
  81. package/lib/typescript/module/ui/oauth/browserBridge.d.ts.map +1 -1
  82. package/lib/typescript/module/ui/types/navigation.d.ts +14 -0
  83. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  84. package/lib/typescript/module/ui/utils/handlePreview.d.ts +10 -0
  85. package/lib/typescript/module/ui/utils/handlePreview.d.ts.map +1 -0
  86. package/lib/typescript/module/ui/utils/usernameLookupBudget.d.ts +36 -0
  87. package/lib/typescript/module/ui/utils/usernameLookupBudget.d.ts.map +1 -0
  88. package/package.json +3 -3
  89. package/src/ui/components/OxyProvider.tsx +11 -1
  90. package/src/ui/components/accountDialogHost.tsx +54 -0
  91. package/src/ui/components/authChooser/primitives.tsx +5 -3
  92. package/src/ui/components/signIn/InlineCommonsQr.tsx +24 -18
  93. package/src/ui/components/signIn/OxySignInPanel.tsx +64 -22
  94. package/src/ui/components/signIn/OxySignUpPanel.tsx +115 -26
  95. package/src/ui/hooks/useUsernameAvailability.ts +42 -7
  96. package/src/ui/oauth/__tests__/browserBridge.test.ts +6 -0
  97. package/src/ui/oauth/browserBridge.ts +13 -0
  98. package/src/ui/screens/OxyOneScreen.tsx +2 -2
  99. package/src/ui/types/navigation.ts +14 -0
  100. package/src/ui/utils/handlePreview.ts +16 -0
  101. package/src/ui/utils/usernameLookupBudget.ts +91 -0
@@ -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
+ }