@oxy.so/services 14.15.1 → 14.16.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 (98) hide show
  1. package/lib/commonjs/index.js +18 -0
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/ui/components/setupFlow/OxySetupFlow.js +272 -0
  4. package/lib/commonjs/ui/components/setupFlow/OxySetupFlow.js.map +1 -0
  5. package/lib/commonjs/ui/components/setupFlow/oxySignInStep.js +34 -0
  6. package/lib/commonjs/ui/components/setupFlow/oxySignInStep.js.map +1 -0
  7. package/lib/commonjs/ui/components/signIn/OxyAuthScreen.js +21 -7
  8. package/lib/commonjs/ui/components/signIn/OxyAuthScreen.js.map +1 -1
  9. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js +27 -2
  10. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js.map +1 -1
  11. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js +3 -1
  12. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  13. package/lib/commonjs/ui/components/signIn/ReauthStep.js +21 -0
  14. package/lib/commonjs/ui/components/signIn/ReauthStep.js.map +1 -1
  15. package/lib/commonjs/ui/context/OxyContext.js +18 -5
  16. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  17. package/lib/commonjs/ui/session/deviceCredentialTracker.js +4 -2
  18. package/lib/commonjs/ui/session/deviceCredentialTracker.js.map +1 -1
  19. package/lib/commonjs/ui/session/setupSignIn.js +6 -0
  20. package/lib/commonjs/ui/session/setupSignIn.js.map +1 -0
  21. package/lib/module/index.js +5 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/ui/components/setupFlow/OxySetupFlow.js +269 -0
  24. package/lib/module/ui/components/setupFlow/OxySetupFlow.js.map +1 -0
  25. package/lib/module/ui/components/setupFlow/oxySignInStep.js +29 -0
  26. package/lib/module/ui/components/setupFlow/oxySignInStep.js.map +1 -0
  27. package/lib/module/ui/components/signIn/OxyAuthScreen.js +22 -8
  28. package/lib/module/ui/components/signIn/OxyAuthScreen.js.map +1 -1
  29. package/lib/module/ui/components/signIn/OxySignInPanel.js +27 -2
  30. package/lib/module/ui/components/signIn/OxySignInPanel.js.map +1 -1
  31. package/lib/module/ui/components/signIn/OxySignUpPanel.js +3 -1
  32. package/lib/module/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  33. package/lib/module/ui/components/signIn/ReauthStep.js +22 -1
  34. package/lib/module/ui/components/signIn/ReauthStep.js.map +1 -1
  35. package/lib/module/ui/context/OxyContext.js +18 -5
  36. package/lib/module/ui/context/OxyContext.js.map +1 -1
  37. package/lib/module/ui/session/deviceCredentialTracker.js +4 -2
  38. package/lib/module/ui/session/deviceCredentialTracker.js.map +1 -1
  39. package/lib/module/ui/session/setupSignIn.js +4 -0
  40. package/lib/module/ui/session/setupSignIn.js.map +1 -0
  41. package/lib/typescript/commonjs/index.d.ts +5 -0
  42. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/ui/components/setupFlow/OxySetupFlow.d.ts +88 -0
  44. package/lib/typescript/commonjs/ui/components/setupFlow/OxySetupFlow.d.ts.map +1 -0
  45. package/lib/typescript/commonjs/ui/components/setupFlow/oxySignInStep.d.ts +23 -0
  46. package/lib/typescript/commonjs/ui/components/setupFlow/oxySignInStep.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/ui/components/signIn/OxyAuthScreen.d.ts +12 -3
  48. package/lib/typescript/commonjs/ui/components/signIn/OxyAuthScreen.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/ui/components/signIn/ReauthStep.d.ts +2 -1
  51. package/lib/typescript/commonjs/ui/components/signIn/ReauthStep.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +10 -3
  54. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts +1 -1
  56. package/lib/typescript/commonjs/ui/icons/MaterialCommunityIcons.d.ts +1 -1
  57. package/lib/typescript/commonjs/ui/session/deviceCredentialTracker.d.ts +3 -12
  58. package/lib/typescript/commonjs/ui/session/deviceCredentialTracker.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/ui/session/setupSignIn.d.ts +38 -0
  60. package/lib/typescript/commonjs/ui/session/setupSignIn.d.ts.map +1 -0
  61. package/lib/typescript/commonjs/ui/types/navigation.d.ts +7 -3
  62. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  63. package/lib/typescript/module/index.d.ts +5 -0
  64. package/lib/typescript/module/index.d.ts.map +1 -1
  65. package/lib/typescript/module/ui/components/setupFlow/OxySetupFlow.d.ts +88 -0
  66. package/lib/typescript/module/ui/components/setupFlow/OxySetupFlow.d.ts.map +1 -0
  67. package/lib/typescript/module/ui/components/setupFlow/oxySignInStep.d.ts +23 -0
  68. package/lib/typescript/module/ui/components/setupFlow/oxySignInStep.d.ts.map +1 -0
  69. package/lib/typescript/module/ui/components/signIn/OxyAuthScreen.d.ts +12 -3
  70. package/lib/typescript/module/ui/components/signIn/OxyAuthScreen.d.ts.map +1 -1
  71. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  72. package/lib/typescript/module/ui/components/signIn/ReauthStep.d.ts +2 -1
  73. package/lib/typescript/module/ui/components/signIn/ReauthStep.d.ts.map +1 -1
  74. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  75. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +10 -3
  76. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  77. package/lib/typescript/module/ui/icons/Ionicons.d.ts +1 -1
  78. package/lib/typescript/module/ui/icons/MaterialCommunityIcons.d.ts +1 -1
  79. package/lib/typescript/module/ui/session/deviceCredentialTracker.d.ts +3 -12
  80. package/lib/typescript/module/ui/session/deviceCredentialTracker.d.ts.map +1 -1
  81. package/lib/typescript/module/ui/session/setupSignIn.d.ts +38 -0
  82. package/lib/typescript/module/ui/session/setupSignIn.d.ts.map +1 -0
  83. package/lib/typescript/module/ui/types/navigation.d.ts +7 -3
  84. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  85. package/package.json +4 -4
  86. package/src/index.ts +17 -0
  87. package/src/ui/components/setupFlow/OxySetupFlow.tsx +339 -0
  88. package/src/ui/components/setupFlow/__tests__/OxySetupFlow.test.tsx +312 -0
  89. package/src/ui/components/setupFlow/oxySignInStep.tsx +32 -0
  90. package/src/ui/components/signIn/OxyAuthScreen.tsx +30 -7
  91. package/src/ui/components/signIn/OxySignInPanel.tsx +22 -2
  92. package/src/ui/components/signIn/OxySignUpPanel.tsx +1 -1
  93. package/src/ui/components/signIn/ReauthStep.tsx +26 -1
  94. package/src/ui/context/OxyContext.tsx +26 -5
  95. package/src/ui/context/oxyContextTypes.ts +11 -3
  96. package/src/ui/session/deviceCredentialTracker.ts +10 -5
  97. package/src/ui/session/setupSignIn.ts +41 -0
  98. package/src/ui/types/navigation.ts +7 -3
@@ -2,8 +2,8 @@
2
2
  * The shell every Oxy sign-in screen shares — the in-app account dialog and
3
3
  * every page of the auth.oxy.so IdP render these, so the two cannot drift:
4
4
  *
5
- * header the Oxy mark (56), then the title (48/800, tight) and a 18px
6
- * description, 8 apart
5
+ * header the Oxy mark (56) or the screen's own icon, then the title
6
+ * (48/800, tight) and a 18px description, 8 apart
7
7
  * screen blocks 24 apart, at most 448 wide
8
8
  * split from `md`, Bloom `AuthCard`'s split base — max 880, radius 24,
9
9
  * 1px border, two equal columns, the right one on the secondary
@@ -17,7 +17,7 @@
17
17
  */
18
18
 
19
19
  import type React from 'react';
20
- import { Linking, Text as RNText } from 'react-native';
20
+ import { Linking, Platform, Text as RNText } from 'react-native';
21
21
  import { View } from 'react-native-css/components';
22
22
  import { Loading } from '@oxy.so/bloom/loading';
23
23
  import { useTheme } from '@oxy.so/bloom/theme';
@@ -32,20 +32,43 @@ const PRIVACY_URL = 'https://oxy.so/company/transparency/policies/privacy';
32
32
  const TITLE = { fontSize: 48, lineHeight: 48, fontWeight: '800', letterSpacing: -1.2 } as const;
33
33
  const DESCRIPTION = { fontSize: 18, lineHeight: 28 } as const;
34
34
  const TERMS = { fontSize: 14, lineHeight: 20, textAlign: 'center', paddingHorizontal: 24 } as const;
35
+ /** A title focused by code is a place, not a control: no focus ring. */
36
+ const PLACE = { outlineWidth: 0 } as const;
35
37
 
36
38
  export interface OxyAuthScreenHeaderProps {
37
39
  title: string;
38
40
  description?: React.ReactNode;
41
+ /** Drawn in place of the Oxy mark (a platform's own step icon), at most 56 tall. */
42
+ icon?: React.ReactNode;
43
+ /**
44
+ * The title's host view, for a surface that moves focus to it (a setup
45
+ * assistant's step change). Given, the title also takes focus from code on
46
+ * the web (`tabIndex` -1), never from Tab.
47
+ */
48
+ titleRef?: React.Ref<React.ComponentRef<typeof RNText>>;
39
49
  }
40
50
 
41
- /** The Oxy mark over the screen's title and description. */
42
- export const OxyAuthScreenHeader: React.FC<OxyAuthScreenHeaderProps> = ({ title, description }) => {
51
+ /** The Oxy mark (or the screen's icon) over the screen's title and description. */
52
+ export const OxyAuthScreenHeader: React.FC<OxyAuthScreenHeaderProps> = ({
53
+ title,
54
+ description,
55
+ icon,
56
+ titleRef,
57
+ }) => {
43
58
  const theme = useTheme();
59
+ const focusable = titleRef != null && Platform.OS === 'web';
44
60
  return (
45
61
  <View className="gap-6">
46
- <LogoIcon height={LOGO_HEIGHT} />
62
+ {icon ?? <LogoIcon height={LOGO_HEIGHT} />}
47
63
  <View className="max-w-[90%] gap-2">
48
- <Text accessibilityRole="header" style={[TITLE, { color: theme.colors.text }]}>
64
+ <Text
65
+ accessibilityRole="header"
66
+ // Bloom's `Text` hands `ref` (a prop in React 19) and react-native-web's
67
+ // `tabIndex` to its host text; neither is in React Native's `TextProps`.
68
+ {...{ ref: titleRef }}
69
+ {...(focusable ? { tabIndex: -1 } : null)}
70
+ style={[TITLE, { color: theme.colors.text }, focusable ? PLACE : null]}
71
+ >
49
72
  {title}
50
73
  </Text>
51
74
  {description != null && description !== '' ? (
@@ -78,6 +78,7 @@ import {
78
78
  isCompleteSignInCode,
79
79
  } from './accountFlowParts';
80
80
  import { readSignInFlow, writeSignInFlow } from './signInFlowStore';
81
+ import type { SetupSignInContext } from '../../session/setupSignIn';
81
82
  import { resolveSignInMethods } from './signInMethods';
82
83
  import { describeApiError, errorCode, retryAfterSeconds } from '../../utils/apiErrorMessage';
83
84
  import { withoutWhitespace } from '../../utils/withoutWhitespace';
@@ -244,6 +245,16 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
244
245
 
245
246
  // One sign-in ends once: the typed code and the opened link can race.
246
247
  const finishingRef = useRef(false);
248
+ // How this sign-in's first factor went, for a platform's setup store
249
+ // (`SetupSignInContext`): kept only until the sign-in commits or fails, so
250
+ // the password typed is held no longer than the request that uses it.
251
+ const firstFactorRef = useRef<SetupSignInContext | null>(null);
252
+ useEffect(
253
+ () => () => {
254
+ firstFactorRef.current = null;
255
+ },
256
+ [],
257
+ );
247
258
  const finish = useCallback(
248
259
  async (
249
260
  result: EmailSignInStepResult,
@@ -273,8 +284,10 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
273
284
  }
274
285
  finishingRef.current = true;
275
286
  writeSignInFlow(flowOwner, SIGN_IN_FLOW_KEY, undefined);
287
+ const setup = firstFactorRef.current ?? undefined;
288
+ firstFactorRef.current = null;
276
289
  try {
277
- await handleWebSession(result as LoginResult);
290
+ await handleWebSession(result as LoginResult, setup);
278
291
  } catch (reason) {
279
292
  finishingRef.current = false;
280
293
  throw reason;
@@ -332,6 +345,7 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
332
345
  setError(null);
333
346
  setNotice(null);
334
347
  setPending(true);
348
+ firstFactorRef.current = { method: 'emailCode' };
335
349
  oxyServices.auth.email
336
350
  .confirm({
337
351
  requestId: request.requestId,
@@ -353,6 +367,7 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
353
367
  setError(null);
354
368
  setPending(true);
355
369
  setChoosingId(account.id);
370
+ firstFactorRef.current = { method: 'emailCode' };
356
371
  oxyServices.auth.email
357
372
  .choose({
358
373
  requestId: request.requestId,
@@ -376,10 +391,14 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
376
391
  const name = step.identifier;
377
392
  setError(null);
378
393
  setPending(true);
394
+ firstFactorRef.current = { method: 'password', password };
379
395
  oxyServices.auth.password
380
396
  .signIn({ identifier: name, password })
381
397
  .then((result) => finish(result, name))
382
- .catch(fail)
398
+ .catch((reason: unknown) => {
399
+ firstFactorRef.current = null;
400
+ fail(reason);
401
+ })
383
402
  .finally(() => setPending(false));
384
403
  };
385
404
 
@@ -427,6 +446,7 @@ export const OxySignInPanel: React.FC<OxySignInPanelProps> = ({
427
446
  try {
428
447
  const result = await oxyServices.auth.email.collect({ requestId, requestSecret });
429
448
  if (!('status' in result)) {
449
+ firstFactorRef.current = { method: 'emailCode' };
430
450
  await finishRef.current(result, requestIdentifier, { requestId, requestSecret });
431
451
  return;
432
452
  }
@@ -166,7 +166,7 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
166
166
  languages: [currentLanguage],
167
167
  ...(campaignAttribution ? { campaignAttribution } : {}),
168
168
  });
169
- await handleWebSession(session);
169
+ await handleWebSession(session, { method: 'signup' });
170
170
  writeSignInFlow(flowOwner, SIGN_UP_FLOW_KEY, undefined);
171
171
  } catch (reason) {
172
172
  if (errorCode(reason) === SIGN_IN_ERROR_CODES.usernameTaken) {
@@ -38,7 +38,8 @@ export interface ReauthStepProps {
38
38
  allowPassword?: boolean;
39
39
  /**
40
40
  * The account has an email, and this change accepts a code sent to it.
41
- * Without it the proof is the password alone.
41
+ * Without it the proof is the password alone; with neither, the change is
42
+ * not offered (there is no proof the account could give).
42
43
  */
43
44
  allowEmail?: boolean;
44
45
  /** The account has an authenticator: its code is required too. */
@@ -137,6 +138,30 @@ export const ReauthStep: React.FC<ReauthStepProps> = ({
137
138
 
138
139
  const needsCode = mode === 'email' && !verificationId;
139
140
 
141
+ // No proof this account can give: no email to send a code to, and no password
142
+ // this change accepts. Offering either anyway sends a code nowhere or asks for
143
+ // a password that does not exist, so the change is not offered at all; the
144
+ // account needs an email first (the API refuses both, `reauth.service`).
145
+ if (!allowPassword && !allowEmail) {
146
+ return (
147
+ <OxyAuthScreen>
148
+ <OxyAuthScreenHeader title={title} />
149
+ <AccountFlowNote>{t('signInSecurity.email.noneDescription')}</AccountFlowNote>
150
+ {secondary ? (
151
+ <Button
152
+ appearance="plain"
153
+ tone="neutral"
154
+ size="lg"
155
+ onPress={secondary.onPress}
156
+ testID="reauth-cancel"
157
+ >
158
+ {secondary.label}
159
+ </Button>
160
+ ) : null}
161
+ </OxyAuthScreen>
162
+ );
163
+ }
164
+
140
165
  return (
141
166
  <OxyAuthScreen>
142
167
  <OxyAuthScreenHeader title={title} description={description} />
@@ -120,6 +120,7 @@ import {
120
120
  useBackgroundSessionSync,
121
121
  type IdentitySessionBinding,
122
122
  } from '../session';
123
+ import type { SetupSignInContext } from '../session/setupSignIn';
123
124
  import type { OxyContextState, OxyRuntimeProviderProps, CommitInput } from './oxyContextTypes';
124
125
  import { DEFAULT_SESSION_VALIDITY_MS } from './oxyContextHelpers';
125
126
  import { useFollow } from '../hooks/useFollow';
@@ -847,7 +848,15 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
847
848
  // Used by the QR device flow (`handleWebSession`), password sign-in, 2FA
848
849
  // completion, and the cold boot.
849
850
  const commitSession = useCallback(
850
- async (input: CommitInput, options: { activate: boolean; oauth?: boolean }): Promise<void> => {
851
+ async (
852
+ input: CommitInput,
853
+ options: {
854
+ activate: boolean;
855
+ oauth?: boolean;
856
+ /** How the sign-in happened, for a platform's setup store only. */
857
+ setup?: SetupSignInContext;
858
+ },
859
+ ): Promise<void> => {
851
860
  const isolatedOAuth = options.oauth === true && !input.deviceId && !input.deviceSecret;
852
861
  if (isolatedOAuth || hasIsolatedOAuthSession(runtime)) {
853
862
  sessionClient.resetLocalState();
@@ -881,7 +890,13 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
881
890
  ...(input.accessToken ? { accessToken: input.accessToken } : {}),
882
891
  ...(input.expiresAt ? { expiresAt: input.expiresAt } : {}),
883
892
  };
884
- await authStore.save(next);
893
+ // A platform's setup store (`authStateStore`) is also told how the
894
+ // sign-in happened; the platform's own stores never are.
895
+ if (options.setup && !usesSharedDeviceCredential && authStoreRef.current) {
896
+ await authStoreRef.current.save(next, options.setup);
897
+ } else {
898
+ await authStore.save(next);
899
+ }
885
900
  sessionClientHost.setDeviceCredential({
886
901
  deviceId: input.deviceId,
887
902
  deviceSecret: input.deviceSecret,
@@ -962,6 +977,7 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
962
977
  logger,
963
978
  clientId,
964
979
  identity,
980
+ usesSharedDeviceCredential,
965
981
  ],
966
982
  );
967
983
  const commitSessionRef = useRef(commitSession);
@@ -970,7 +986,10 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
970
986
  // Public `handleWebSession`: commit a session from the QR device flow. It is a
971
987
  // deliberate sign-in on THIS device, so it activates the account.
972
988
  const handleWebSession = useCallback(
973
- async (session: SessionLoginResponse | LoginSessionResult): Promise<void> => {
989
+ async (
990
+ session: SessionLoginResponse | LoginSessionResult,
991
+ setup?: SetupSignInContext,
992
+ ): Promise<void> => {
974
993
  if (!session?.user || !session?.sessionId || !session.accessToken) {
975
994
  throw new Error('Session response did not include a usable session');
976
995
  }
@@ -984,7 +1003,7 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
984
1003
  userId: session.user.id,
985
1004
  user: session.user,
986
1005
  },
987
- { activate: true },
1006
+ { activate: true, ...(setup ? { setup } : {}) },
988
1007
  );
989
1008
  },
990
1009
  [commitSession],
@@ -1103,7 +1122,9 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
1103
1122
  oxyServices,
1104
1123
  sessionClient,
1105
1124
  clientId,
1106
- commitSession: (session) => handleWebSessionRef.current(session),
1125
+ // The controller's sign-ins are approvals from a device the person holds
1126
+ // (the QR, the Commons identity): passwordless.
1127
+ commitSession: (session) => handleWebSessionRef.current(session, { method: 'qr' }),
1107
1128
  onSignedIn: () => {
1108
1129
  // Close the dialog: pop the morphed frame back to its host surface, or
1109
1130
  // dismiss the detached surface (whose settle flips `accountDialogOpen`).
@@ -17,11 +17,11 @@ import type {
17
17
  import type {
18
18
  AccountDialogController,
19
19
  AccountDialogView,
20
- AuthStateStore,
21
20
  SessionClient,
22
21
  SessionMode,
23
22
  } from '@oxy.so/core/session';
24
23
  import type { UseFollowHook } from '../hooks/useFollow.types';
24
+ import type { PlatformSetupAuthStateStore, SetupSignInContext } from '../session/setupSignIn';
25
25
  import type { useLanguageManagement } from '../hooks/useLanguageManagement';
26
26
  import type { RouteName } from '../navigation/routes';
27
27
  import type { StartWebOAuthSignInOptions } from '../oauth/browserAuthTransport';
@@ -118,7 +118,15 @@ export interface OxyContextState {
118
118
  * code exchange, an email code or link, a password, a sign-up — as the
119
119
  * active one.
120
120
  */
121
- handleWebSession: (session: SessionLoginResponse | LoginSessionResult) => Promise<void>;
121
+ handleWebSession: (
122
+ session: SessionLoginResponse | LoginSessionResult,
123
+ /**
124
+ * How the sign-in happened, handed to a platform's setup store
125
+ * (`authStateStore`) with the credential, and to no other store
126
+ * (`SetupSignInContext`).
127
+ */
128
+ setup?: SetupSignInContext,
129
+ ) => Promise<void>;
122
130
 
123
131
  /**
124
132
  * Run a WEB third-party OAuth sign-in (authorization code + PKCE) end to end
@@ -259,7 +267,7 @@ export interface OxyRuntimeProviderProps {
259
267
  /** Storage instance owned by the public provider; internal composition seam. */
260
268
  platformStorage?: StorageInterface | null;
261
269
  /** See `OxyProviderProps.authStateStore`. Read once, at mount. */
262
- authStateStore?: AuthStateStore;
270
+ authStateStore?: PlatformSetupAuthStateStore;
263
271
  /** See `OxyProviderProps.accountQueries`. Read once, at mount. */
264
272
  accountQueries?: AccountQueriesConfig;
265
273
  }
@@ -7,14 +7,15 @@
7
7
  * every load, save and clear passes through, so the press can read it at once.
8
8
  * The cold boot loads the store on mount, long before anyone presses sign-in.
9
9
  */
10
- import type { AuthStateStore, AuthStateWriteGuard, PersistedAuthState } from '@oxy.so/core/session';
10
+ import type { AuthStateWriteGuard, PersistedAuthState } from '@oxy.so/core/session';
11
+ import type { PlatformSetupAuthStateStore, SetupSignInContext } from './setupSignIn';
11
12
 
12
13
  export interface HeldDeviceCredential {
13
14
  deviceId: string;
14
15
  deviceSecret: string;
15
16
  }
16
17
 
17
- export interface CredentialTrackingAuthStateStore extends AuthStateStore {
18
+ export interface CredentialTrackingAuthStateStore extends PlatformSetupAuthStateStore {
18
19
  /**
19
20
  * The credential last seen through this store; `undefined` until the store has
20
21
  * been read at least once (unknown — the caller should not guess).
@@ -30,7 +31,9 @@ function credentialOf(
30
31
  : null;
31
32
  }
32
33
 
33
- export function trackDeviceCredential(store: AuthStateStore): CredentialTrackingAuthStateStore {
34
+ export function trackDeviceCredential(
35
+ store: PlatformSetupAuthStateStore,
36
+ ): CredentialTrackingAuthStateStore {
34
37
  let held: HeldDeviceCredential | null | undefined;
35
38
  return {
36
39
  ...store,
@@ -39,9 +42,11 @@ export function trackDeviceCredential(store: AuthStateStore): CredentialTracking
39
42
  held = credentialOf(state);
40
43
  return state;
41
44
  },
42
- save: async (state) => {
45
+ // The setup context (how the sign-in happened) goes to the wrapped store
46
+ // only when the caller passed one, so a plain store sees its usual call.
47
+ save: async (state: PersistedAuthState, context?: SetupSignInContext) => {
43
48
  held = credentialOf(state);
44
- return store.save(state);
49
+ return context ? store.save(state, context) : store.save(state);
45
50
  },
46
51
  ...(store.saveIfCurrent
47
52
  ? {
@@ -0,0 +1,41 @@
1
+ /**
2
+ * What a platform's setup client is told about each sign-in it commits.
3
+ *
4
+ * A platform that runs the SDK's own sign-in at its setup (OxyOS's login
5
+ * screen) gives the provider its own store (`OxyProviderProps.authStateStore`),
6
+ * and `save()` receives the credential the moment a sign-in commits. The
7
+ * platform also needs to know HOW the person signed in, because its own setup
8
+ * differs:
9
+ *
10
+ * - `'qr'`: approved from a device the person already holds (the QR a phone
11
+ * scans, or the Commons identity): passwordless, so the platform asks no
12
+ * password; its service redeems the approval for its own credential
13
+ * (`POST /session/device/platform`, ADR 0058 R6);
14
+ * - `'password'`: the account's password, which the person just typed and the
15
+ * platform may reuse once (OxyOS keeps it as its offline verifier) instead of
16
+ * asking for it again; it is in `password`, with or without a second factor;
17
+ * - `'emailCode'`: the code or the link sent by email;
18
+ * - `'signup'`: a new account.
19
+ *
20
+ * Passed as `save()`'s second argument, and ONLY to a store the app provided:
21
+ * the platform's default stores never receive it. The SDK never keeps the
22
+ * password beyond handing it over, never persists it and never logs it.
23
+ */
24
+
25
+ import type { AuthStateStore, PersistedAuthState } from '@oxy.so/core/session';
26
+
27
+ export type SetupSignInMethod = 'qr' | 'password' | 'emailCode' | 'signup';
28
+
29
+ export interface SetupSignInContext {
30
+ method: SetupSignInMethod;
31
+ /** The password just typed; present only when `method` is `'password'`. */
32
+ password?: string;
33
+ }
34
+
35
+ /**
36
+ * A platform's setup store: an {@link AuthStateStore} whose `save()` may also
37
+ * read how the sign-in happened. Every `AuthStateStore` is one.
38
+ */
39
+ export interface PlatformSetupAuthStateStore extends Omit<AuthStateStore, 'save'> {
40
+ save(state: PersistedAuthState, context?: SetupSignInContext): Promise<boolean>;
41
+ }
@@ -4,7 +4,8 @@ import type { AccountQueriesConfig } from '../hooks/accountQueryPersistence';
4
4
  import type { RouteName } from '../navigation/routes';
5
5
  import type { User } from '@oxy.so/core';
6
6
  import type { ClientSession } from '@oxy.so/core';
7
- import type { AuthStateStore, SessionMode } from '@oxy.so/core/session';
7
+ import type { SessionMode } from '@oxy.so/core/session';
8
+ import type { PlatformSetupAuthStateStore } from '../session/setupSignIn';
8
9
  import type { WebAuthMode } from '../oauth/types';
9
10
  import type { ProductAnalytics } from '../analytics/productAnalytics';
10
11
 
@@ -200,13 +201,16 @@ export interface OxyProviderProps {
200
201
  * off) and no background credential (`backgroundSession` is ignored). The
201
202
  * email-code, password and authenticator sign-ins and the "add a password"
202
203
  * flow (ADR 0030) run as usual; `save()` receives the credential the moment
203
- * a sign-in commits, so the platform can take it over.
204
+ * a sign-in commits, so the platform can take it over, and, as its second
205
+ * argument, how the sign-in happened (`SetupSignInContext`: the QR's
206
+ * approval, a password with the password just typed, an email code, a
207
+ * sign-up). Only this store ever receives that context.
204
208
  *
205
209
  * Ordinary apps never pass it. Never combined with a session host: when a
206
210
  * platform has registered one (`@oxy.so/core/host`), the host wins and this
207
211
  * is ignored. Read once, at mount.
208
212
  */
209
- authStateStore?: AuthStateStore;
213
+ authStateStore?: PlatformSetupAuthStateStore;
210
214
  }
211
215
 
212
216
  export interface OxyLanguageConfig {