@oxy.so/services 15.1.4 → 15.1.6

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 (60) hide show
  1. package/bloom/Package.bloom +15 -0
  2. package/bloom/Resources/Localizable/ar-SA.json +108 -0
  3. package/bloom/Resources/Localizable/bn-BD.json +108 -0
  4. package/bloom/Resources/Localizable/ca-ES.json +111 -0
  5. package/bloom/Resources/Localizable/de-DE.json +108 -0
  6. package/bloom/Resources/Localizable/en-US.json +124 -0
  7. package/bloom/Resources/Localizable/es-ES.json +124 -0
  8. package/bloom/Resources/Localizable/fr-FR.json +108 -0
  9. package/bloom/Resources/Localizable/hi-IN.json +108 -0
  10. package/bloom/Resources/Localizable/id-ID.json +108 -0
  11. package/bloom/Resources/Localizable/it-IT.json +108 -0
  12. package/bloom/Resources/Localizable/ja-JP.json +108 -0
  13. package/bloom/Resources/Localizable/ko-KR.json +108 -0
  14. package/bloom/Resources/Localizable/pt-PT.json +108 -0
  15. package/bloom/Resources/Localizable/ru-RU.json +108 -0
  16. package/bloom/Resources/Localizable/tr-TR.json +108 -0
  17. package/bloom/Resources/Localizable/zh-CN.json +108 -0
  18. package/bloom/Sources/OxyAccountUI/SignInFlow.bloom +322 -0
  19. package/bloom/Sources/OxyAccountUI/SignInRules.bloom +135 -0
  20. package/bloom/Sources/OxyAccountUI/SignInService.bloom +141 -0
  21. package/bloom/Sources/OxyAccountUI/SignUpFlow.bloom +322 -0
  22. package/bloom/Sources/OxyAccountUI/SignUpRules.bloom +189 -0
  23. package/bloom/Sources/OxyAccountUIChecks/Checks.bloom +254 -0
  24. package/bloom/Sources/OxyAccountUIChecks/FakeAuth.bloom +123 -0
  25. package/bloom/Sources/OxyAccountUIChecks/SignUpChecks.bloom +193 -0
  26. package/lib/commonjs/ui/boot/runProviderColdBoot.js +43 -329
  27. package/lib/commonjs/ui/boot/runProviderColdBoot.js.map +1 -1
  28. package/lib/commonjs/ui/context/OxyContext.js +7 -1
  29. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  30. package/lib/commonjs/ui/oauth/applicationSessionLane.js +12 -25
  31. package/lib/commonjs/ui/oauth/applicationSessionLane.js.map +1 -1
  32. package/lib/commonjs/ui/session/tokenTransport.js +7 -69
  33. package/lib/commonjs/ui/session/tokenTransport.js.map +1 -1
  34. package/lib/module/ui/boot/runProviderColdBoot.js +43 -329
  35. package/lib/module/ui/boot/runProviderColdBoot.js.map +1 -1
  36. package/lib/module/ui/context/OxyContext.js +8 -2
  37. package/lib/module/ui/context/OxyContext.js.map +1 -1
  38. package/lib/module/ui/oauth/applicationSessionLane.js +4 -23
  39. package/lib/module/ui/oauth/applicationSessionLane.js.map +1 -1
  40. package/lib/module/ui/session/tokenTransport.js +3 -68
  41. package/lib/module/ui/session/tokenTransport.js.map +1 -1
  42. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts +8 -31
  43. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/ui/oauth/applicationSessionLane.d.ts +1 -5
  46. package/lib/typescript/commonjs/ui/oauth/applicationSessionLane.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts +1 -33
  48. package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts.map +1 -1
  49. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts +8 -31
  50. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  51. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  52. package/lib/typescript/module/ui/oauth/applicationSessionLane.d.ts +1 -5
  53. package/lib/typescript/module/ui/oauth/applicationSessionLane.d.ts.map +1 -1
  54. package/lib/typescript/module/ui/session/tokenTransport.d.ts +1 -33
  55. package/lib/typescript/module/ui/session/tokenTransport.d.ts.map +1 -1
  56. package/package.json +10 -5
  57. package/src/ui/boot/runProviderColdBoot.ts +40 -364
  58. package/src/ui/context/OxyContext.tsx +8 -1
  59. package/src/ui/oauth/applicationSessionLane.ts +7 -35
  60. package/src/ui/session/tokenTransport.ts +3 -75
@@ -1,34 +1,2 @@
1
- import { type OxyServices } from '@oxy.so/core';
2
- import type { TokenTransport } from '@oxy.so/core/session';
3
- /**
4
- * Platform `TokenTransport` for `SessionClient` (device-first model).
5
- *
6
- * `ensureActiveToken` is the fallback the client uses when a `session_state`
7
- * push arrived WITHOUT an embedded `activeToken` and the planted bearer does not
8
- * already belong to the state's active account. It mints one through the ONE
9
- * unified single-flight the scheduler, the request-time preflight, and the 401
10
- * retry all use — `oxyServices.http.refreshAccessToken(...)` — which runs
11
- * the installed refresh handler (present the persisted zero-cookie `deviceId` +
12
- * `deviceSecret` at `POST /session/device/token`, which mints for the device's
13
- * CURRENT active account). Routing through the SAME entry point means this lane
14
- * can never double-rotate the device secret against the others: it has NO
15
- * private single-flight of its own.
16
- *
17
- * The short-circuit compares the planted bearer's ACCOUNT against
18
- * `state.activeAccountId`, not mere token presence: a bearer for the PREVIOUS
19
- * account (an account switch) must still mint the new account's token — skipping
20
- * on presence alone would leave a subscriber observing the new active account
21
- * under the old account's bearer (the account-switch 404 race).
22
- *
23
- * A failure is logged and swallowed: this method must never throw out (it runs
24
- * inside the socket state handler).
25
- *
26
- * `getPinnedAccountId` is the identity-bound escape hatch. Converging the bearer
27
- * on `state.activeAccountId` is precisely what an identity-bound client must
28
- * never do — its token is minted for the PINNED account by the cold boot /
29
- * re-mint lane. `SessionClient` already bypasses the transport entirely while
30
- * pinned; this guard is the services-side half of that contract, so no future
31
- * wiring can reintroduce the convergence from this end.
32
- */
33
- export declare function createTokenTransport(oxyServices: OxyServices, getPinnedAccountId?: () => string | null): TokenTransport;
1
+ export { createTokenTransport } from '@oxy.so/core/session';
34
2
  //# sourceMappingURL=tokenTransport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokenTransport.d.ts","sourceRoot":"","sources":["../../../../../src/ui/session/tokenTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,WAAW,EACxB,kBAAkB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,GACvC,cAAc,CAqChB"}
1
+ {"version":3,"file":"tokenTransport.d.ts","sourceRoot":"","sources":["../../../../../src/ui/session/tokenTransport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/services",
3
- "version": "15.1.4",
3
+ "version": "15.1.6",
4
4
  "description": "OxyHQ Expo/React Native SDK — UI components, screens, and native features",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -146,7 +146,10 @@
146
146
  "ios/OxyAssetFilesModule.swift",
147
147
  "ios/OxyIdentity.podspec",
148
148
  "plugins",
149
- "expo-module.config.json"
149
+ "expo-module.config.json",
150
+ "bloom/Package.bloom",
151
+ "bloom/Sources",
152
+ "bloom/Resources"
150
153
  ],
151
154
  "keywords": [
152
155
  "react-native",
@@ -178,8 +181,10 @@
178
181
  "generate:icon-fonts": "node scripts/generate-icon-font-subsets.mjs",
179
182
  "check:icon-fonts": "node scripts/check-icon-font-subsets.mjs",
180
183
  "check:compat-expo-58": "bun compat/expo-58/check.mjs",
184
+ "check:bloom": "bun bloom/checks/run.mjs && bun bloom/strings.mjs --check",
185
+ "generate:bloom-strings": "bun bloom/strings.mjs",
181
186
  "build:js": "bun x react-native-builder-bob build --target commonjs && bun x react-native-builder-bob build --target module && bun run copy-assets",
182
- "test": "jest --passWithNoTests",
187
+ "test": "bun run check:bloom && jest --passWithNoTests",
183
188
  "test:watch": "jest --watch",
184
189
  "test:coverage": "jest --coverage",
185
190
  "copy-assets": "copyfiles -u 1 \"src/assets/**/*\" lib/commonjs/assets && copyfiles -u 1 \"src/assets/**/*\" lib/module/assets",
@@ -197,7 +202,7 @@
197
202
  "devDependencies": {
198
203
  "@expo/app-integrity": "~58.0.2",
199
204
  "@expo/vector-icons": "^15.1.1",
200
- "@oxy.so/core": "7.65.0",
205
+ "@oxy.so/core": "7.68.0",
201
206
  "@react-native-async-storage/async-storage": "^3.1.1",
202
207
  "@react-native-community/netinfo": "^12.0.1",
203
208
  "@react-native/babel-preset": "^0.88.1",
@@ -248,7 +253,7 @@
248
253
  "@expo/vector-icons": "^15.0.3",
249
254
  "@oxy.so/bloom": ">=23.0.0",
250
255
  "@oxy.so/bloom-data": ">=0.1.0",
251
- "@oxy.so/core": "^7.49.0",
256
+ "@oxy.so/core": "^7.68.0",
252
257
  "@react-native-async-storage/async-storage": ">=2.0.0 <4.0.0",
253
258
  "@react-native-community/netinfo": ">=11.4.1 <13.0.0",
254
259
  "@types/react": "<20.0.0",
@@ -1,13 +1,12 @@
1
- import { resolveApplicationSessionLane } from '../oauth/applicationSessionLane';
2
1
  import { logger as loggerUtil, type OxyServices } from '@oxy.so/core';
3
2
  import {
4
3
  runSessionColdBoot,
4
+ runWebSessionColdBoot,
5
5
  type AuthStateStore,
6
6
  type IdentityBinding,
7
7
  type SessionMode,
8
8
  } from '@oxy.so/core/session';
9
9
  import type { SessionClient } from '@oxy.so/core/session';
10
- import { loadPersistedDeviceCredential } from '../utils/deviceCredential';
11
10
  import { createPlatformSharedDeviceCredentialStore } from '../session/sharedDeviceCredentialStore';
12
11
  import { tryCompleteOAuthReturn } from '../utils/oauthReturn';
13
12
  import { isWebBrowser } from '../utils/isWebBrowser';
@@ -15,40 +14,8 @@ import { isNetConnectivityOnline } from '../utils/netConnectivity';
15
14
  import type { CommitInput } from '../context/oxyContextTypes';
16
15
 
17
16
  /**
18
- * Whether the URL carries an OAuth return (`?code=` or `?error=`) for
19
- * `tryCompleteOAuthReturn` to consume. Reads the address bar only.
20
- */
21
- function hasOAuthReturnOnUrl(): boolean {
22
- const search = (globalThis as { location?: { search?: string } }).location?.search;
23
- if (!search) return false;
24
- const params = new URLSearchParams(search);
25
- return params.has('code') || params.has('error');
26
- }
27
-
28
- /**
29
- * Whether this origin's own store holds anything a web boot could restore from:
30
- * a warm access token to plant or a device secret to mint with. A presence
31
- * check only — nothing read here is used, sent or synced before the
32
- * classification allows it.
33
- */
34
- async function hasRestorableState(store: AuthStateStore): Promise<boolean> {
35
- const persisted = await store.load();
36
- return Boolean(persisted?.accessToken || persisted?.deviceSecret);
37
- }
38
-
39
- /** How long the cold boot waits for the post-boot SessionClient handoff (ms). */
40
- export const SESSION_HANDOFF_DEADLINE_MS = 6000;
41
-
42
- /**
43
- * HARD overall deadline (ms) for the whole `runSessionColdBoot` step chain.
44
- *
45
- * Bounds time-to-route: routing gates on `isAuthResolved`, which resolves when
46
- * the cold boot finishes, so a network step that never settles (a black-hole
47
- * network that neither connects nor rejects) would otherwise hang routing
48
- * indefinitely. 12s comfortably exceeds the healthy worst case of the
49
- * sequential, single-attempt (`retry:false`), 5s-capped network steps, so it is
50
- * INERT on healthy loads and only trips on a pathological network. Offline
51
- * devices short-circuit far sooner via the connectivity hint below.
17
+ * HARD overall deadline (ms) for the whole `runSessionColdBoot` step chain; see
18
+ * `runWebSessionColdBoot` in `@oxy.so/core/session`, which owns the boot.
52
19
  */
53
20
  export const COLD_BOOT_OVERALL_DEADLINE_MS = 12_000;
54
21
 
@@ -60,37 +27,23 @@ export const COLD_BOOT_OVERALL_DEADLINE_MS = 12_000;
60
27
  const OFFLINE_PROBE_TIMEOUT_MS = 500;
61
28
 
62
29
  /**
63
- * Best-effort, FAST connectivity probe run once before the cold boot.
64
- *
65
- * Returns `true` ONLY on an EXPLICIT disconnected verdict; every ambiguous
66
- * outcome (probe timeout, unknown/`null` state, NetInfo unavailable, a thrown
67
- * error) resolves to `false` (assume online) so a flaky probe can never falsely
68
- * skip a real sign-in. Never rejects. On web it reads `navigator.onLine`; on
69
- * native it races `NetInfo.fetch()` against {@link OFFLINE_PROBE_TIMEOUT_MS},
70
- * mirroring the existing NetInfo dynamic-import pattern in `OxyProvider`.
30
+ * The native half of the boot's connectivity probe: races `NetInfo.fetch()`
31
+ * against {@link OFFLINE_PROBE_TIMEOUT_MS}. `true` ONLY on an EXPLICIT
32
+ * disconnected verdict; a timeout or an unknown state is "online". A missing
33
+ * NetInfo rejects, which the boot also reads as "online".
71
34
  */
72
- async function detectOfflineHint(): Promise<boolean> {
73
- try {
74
- if (isWebBrowser()) {
75
- const online = (globalThis as { navigator?: { onLine?: boolean } }).navigator?.onLine;
76
- // Only an explicit `false` is an offline verdict; `undefined` ⇒ assume online.
77
- return online === false;
78
- }
79
- const NetInfo = await import('@react-native-community/netinfo');
80
- const state = await Promise.race([
81
- NetInfo.default.fetch(),
82
- new Promise<null>((resolve) => {
83
- setTimeout(() => resolve(null), OFFLINE_PROBE_TIMEOUT_MS);
84
- }),
85
- ]);
86
- // `null` ⇒ the probe timed out (unknown → assume online). Only an explicit
87
- // disconnected verdict disables the network steps (the same rule as the
88
- // online signal: `isConnected`, never the reachability probe).
89
- return state !== null && !isNetConnectivityOnline(state);
90
- } catch {
91
- // NetInfo missing / probe threw — never block sign-in on a probe failure.
92
- return false;
93
- }
35
+ async function probeNetInfoOffline(): Promise<boolean> {
36
+ const NetInfo = await import('@react-native-community/netinfo');
37
+ const state = await Promise.race([
38
+ NetInfo.default.fetch(),
39
+ new Promise<null>((resolve) => {
40
+ setTimeout(() => resolve(null), OFFLINE_PROBE_TIMEOUT_MS);
41
+ }),
42
+ ]);
43
+ // `null` ⇒ the probe timed out (unknown → assume online). Only an explicit
44
+ // disconnected verdict disables the network steps (the same rule as the
45
+ // online signal: `isConnected`, never the reachability probe).
46
+ return state !== null && !isNetConnectivityOnline(state);
94
47
  }
95
48
 
96
49
  export interface RunProviderColdBootOptions {
@@ -149,310 +102,33 @@ export interface RunProviderColdBootOptions {
149
102
  onCachedSessionUnconfirmed?: (retry: () => Promise<void>) => void;
150
103
  }
151
104
 
152
- type ClassificationLane = 'device' | 'oauth';
153
-
154
- /** Starts the provider's fresh classification; a rejection is observed, not swallowed. */
155
- function startClassification(opts: RunProviderColdBootOptions): Promise<ClassificationLane> {
156
- const classification = (async () =>
157
- opts.resolveSessionLane?.() ??
158
- resolveApplicationSessionLane(opts.oxyServices, opts.clientId))();
159
- // Observed so a rejection that lands before it is awaited is not reported as
160
- // unhandled; every caller still awaits it and sees the rejection.
161
- classification.catch(() => undefined);
162
- return classification;
163
- }
164
-
165
- /** What the device lanes made of this holder: a session, a verdict against it, or no answer. */
166
- type DeviceRestoreOutcome = 'session' | 'rejected' | 'unreachable';
167
-
168
105
  /**
169
- * The device lanes of the boot (`runSessionColdBoot`), for a first boot or for
170
- * the background check of a painted one.
106
+ * Device-first cold boot for `@oxy.so/services` providers: core's
107
+ * `runWebSessionColdBoot` (the order, the deadlines, the verdicts) with this
108
+ * package's platform parts — the registry classifier, the native connectivity
109
+ * probe, the shared device credential slot and the OAuth return leg.
171
110
  *
172
- * A first boot (`painted: false`) is on the critical path: its committed
173
- * session resolves auth, bounded by {@link SESSION_HANDOFF_DEADLINE_MS}. A
174
- * painted boot already resolved auth from the cache, so nothing waits on the
175
- * handoff and the pure-local warm token is skipped: the check needs the mint's
176
- * verdict, which a still-valid token cannot give.
111
+ * The boot NEVER navigates the top-level window; the OAuth return leg only
112
+ * consumes a code that is already in the address bar (#691 phase 7b).
177
113
  */
178
- async function restoreDeviceSession(
179
- opts: RunProviderColdBootOptions,
180
- painted: boolean,
181
- ): Promise<DeviceRestoreOutcome> {
182
- const {
183
- oxyServices,
184
- authStore,
185
- sessionMode = 'account',
186
- identity,
187
- sessionClient,
188
- syncDeviceCredentialToHost,
189
- commitSession,
190
- markAuthResolved,
191
- } = opts;
192
-
193
- await opts.beforeDeviceBoot?.();
194
-
195
- // Best-effort connectivity probe up front: an EXPLICIT offline verdict skips
196
- // the two doomed network steps so routing settles immediately instead of
197
- // burning the overall deadline on a mint that cannot succeed. Any ambiguity
198
- // resolves to "online" — the network steps still run.
199
- const offline = await detectOfflineHint();
200
-
201
- let outcome: DeviceRestoreOutcome = 'unreachable';
202
- let holderRejected = false;
203
- await runSessionColdBoot({
204
- oxy: oxyServices,
205
- store: authStore,
206
- platform: { isWeb: isWebBrowser(), isNative: !isWebBrowser() },
207
- sessionMode,
208
- identity,
209
- // The device-wide shared credential slot, enabling the `shared-device-adopt`
210
- // lane: a newly installed official app joins this device's existing session
211
- // instead of falling back to signing a challenge with the Commons identity
212
- // key. `null` on web, where each origin is its own device by design; the
213
- // core lane is also skipped outright in `sessionMode: 'identity'`.
214
- // Off when the provider was given a platform's own store: the credential
215
- // then lives there and nowhere else.
216
- sharedDeviceCredential:
217
- opts.useSharedDeviceCredential === false
218
- ? undefined
219
- : (createPlatformSharedDeviceCredentialStore() ?? undefined),
114
+ export function runProviderColdBoot(opts: RunProviderColdBootOptions): Promise<void> {
115
+ const { oxyServices, clientId, authRedirectUri, commitSession } = opts;
116
+ return runWebSessionColdBoot({
117
+ ...opts,
220
118
  overallDeadlineMs: COLD_BOOT_OVERALL_DEADLINE_MS,
221
- isOffline: () => offline,
222
- requireServerVerdict: painted,
223
- onHolderRejected: () => {
224
- holderRejected = true;
225
- },
226
- onStepDeadline: (stepId) => {
227
- loggerUtil.warn(
228
- `Cold-boot step "${stepId}" exceeded the ${COLD_BOOT_OVERALL_DEADLINE_MS}ms overall deadline — abandoned; routing proceeds signed-out`,
229
- { component: 'runProviderColdBoot', method: 'onStepDeadline' },
230
- );
231
- },
232
- onSession: async (session) => {
233
- outcome = 'session';
234
- // Mint already persisted `{deviceId, deviceSecret}` to the store; sync the
235
- // in-memory SessionClient host so sockets + tab-focus re-mint can use it.
236
- await syncDeviceCredentialToHost();
237
- const handoff = commitSession(
238
- {
239
- sessionId: session.sessionId,
240
- accessToken: session.accessToken,
241
- userId: session.userId,
242
- deviceState: session.state,
243
- },
244
- { activate: false },
245
- );
246
- if (painted) {
247
- // The account is already on screen; the commit refreshes its profile.
248
- await handoff;
249
- return;
250
- }
251
- let handoffDeadlineId: ReturnType<typeof setTimeout> | undefined;
252
- await Promise.race([
253
- handoff,
254
- new Promise<void>((resolve) => {
255
- handoffDeadlineId = setTimeout(resolve, SESSION_HANDOFF_DEADLINE_MS);
256
- }),
257
- ]).finally(() => {
258
- if (handoffDeadlineId !== undefined) {
259
- clearTimeout(handoffDeadlineId);
260
- }
261
- });
262
- markAuthResolved();
263
- },
264
- onSignedOut: async () => {
265
- outcome = holderRejected ? 'rejected' : 'unreachable';
266
- await syncDeviceCredentialToHost();
267
- // A painted session is the caller's to end or keep (see verifyCachedSession).
268
- if (painted) return;
269
- const cred = await loadPersistedDeviceCredential(authStore);
270
- if (cred) {
271
- try {
272
- await sessionClient.start();
273
- } catch (socketError) {
274
- if (__DEV__) {
275
- loggerUtil.debug(
276
- 'Device socket start failed (non-fatal)',
277
- { component: 'runProviderColdBoot' },
278
- socketError,
279
- );
280
- }
281
- }
282
- }
283
- markAuthResolved();
284
- },
285
- onStepError: (id, error) => {
286
- if (__DEV__) {
287
- loggerUtil.debug(
288
- `Cold-boot step "${id}" errored (non-fatal, falling through)`,
289
- { component: 'runProviderColdBoot' },
290
- error,
291
- );
292
- }
293
- },
294
- });
295
- await opts.afterDeviceBoot?.();
296
- return outcome;
297
- }
298
-
299
- /**
300
- * The background check of a painted session: the registry's classification and
301
- * a mint with this holder's own credential (whose commit refreshes the profile).
302
- * Each is asked until the server answers it. A verdict against the session
303
- * signs out at that moment; no answer keeps the cached session on screen and
304
- * hands the caller a retry.
305
- */
306
- async function verifyCachedSession(
307
- opts: RunProviderColdBootOptions,
308
- verified: { lane: boolean; session: boolean },
309
- classification: Promise<ClassificationLane>,
310
- ): Promise<void> {
311
- if (!verified.lane) {
312
- let lane: ClassificationLane | null = null;
313
- try {
314
- lane = await classification;
315
- } catch {
316
- // The registry could not be asked (offline, timeout, 5xx). That is no
317
- // verdict on this app: the cached `device` classification stands until it
318
- // answers.
319
- }
320
- if (lane === 'oauth') {
321
- await opts.onCachedSessionRejected?.();
322
- return;
323
- }
324
- verified.lane = lane === 'device';
325
- }
326
- if (!verified.session) {
327
- const outcome = await restoreDeviceSession(opts, true);
328
- if (outcome === 'rejected') {
329
- await opts.onCachedSessionRejected?.();
330
- return;
331
- }
332
- verified.session = outcome === 'session';
333
- }
334
- if (!verified.lane || !verified.session) {
335
- opts.onCachedSessionUnconfirmed?.(() =>
336
- verifyCachedSession(
337
- opts,
338
- verified,
339
- verified.lane ? Promise.resolve('device') : startClassification(opts),
340
- ),
341
- );
342
- }
343
- }
344
-
345
- /**
346
- * Device-first cold boot for `@oxy.so/services` providers.
347
- *
348
- * A returning session saved on this device (account mode, the app last
349
- * classified `device`, its profile cached) paints first, with no network, and
350
- * is then checked in the background — see `paintCachedSession`. Otherwise, a
351
- * first boot:
352
- *
353
- * Ordered pipeline:
354
- * 1. Complete an OAuth authorization-code return already on the URL (web)
355
- * 2. `runSessionColdBoot` — device-secret mint (+ the native Commons-proof lane,
356
- * or the primary-identity-key lane in `sessionMode: 'identity'`)
357
- *
358
- * Step 1 is ACCOUNT-MODE ONLY: it commits whichever account the IdP resolves,
359
- * which for an identity-bound client is somebody else's account by construction.
360
- * In `'identity'` mode the boot is exactly step 2.
361
- *
362
- * The boot NEVER navigates the top-level window. There is no automatic
363
- * `prompt=none` bounce to the IdP: a web origin with no local device credential
364
- * resolves SIGNED OUT and waits for the user's next explicit "Continue with
365
- * Oxy", which opens a popup from a real gesture (#691 phase 7b). Step 1 is not a
366
- * navigation — it only consumes a code that is already in the address bar.
367
- */
368
- export async function runProviderColdBoot(opts: RunProviderColdBootOptions): Promise<void> {
369
- const {
370
- oxyServices,
371
- authStore,
372
- clientId,
373
- authRedirectUri,
374
- sessionMode = 'account',
375
- commitSession,
376
- markAuthResolved,
377
- setTokenReady,
378
- } = opts;
379
-
380
- const identityBound = sessionMode === 'identity';
381
-
382
- setTokenReady(false);
383
-
384
- try {
385
- // Classification precedes every USE of a local secret, the shared credential
386
- // and the identity key. Unavailable registry metadata fails closed on a first
387
- // boot, including offline. It starts now, before anything else, so its round
388
- // trip overlaps the local work below.
389
- const classification = startClassification(opts);
390
-
391
- // A returning session saved on this device paints at once from the cache:
392
- // the account, its cached content, auth resolved, no network on the way.
393
- // The classification and the session are then checked in the background,
394
- // and a verdict against either signs out at that moment. Identity-bound
395
- // clients and OAuth returns keep the path below.
396
- const freshLaunch = !identityBound && !hasOAuthReturnOnUrl();
397
- if (freshLaunch && (await opts.paintCachedSession?.())) {
398
- await verifyCachedSession(opts, { lane: false, session: false }, classification);
399
- return;
400
- }
401
-
402
- // The verdict decides HOW a session is restored, never WHETHER there is one.
403
- // A web origin with nothing to restore and no OAuth return on the URL ends
404
- // signed out on either lane, so routing need not wait a network round trip
405
- // for an answer that cannot change the outcome. The classification still
406
- // completes below and still gates every later sign-in
407
- // (`ensureDeviceSessionLane` shares this same in-flight lookup).
408
- if (freshLaunch && isWebBrowser()) {
409
- if (!(await hasRestorableState(authStore))) {
410
- markAuthResolved();
411
- const lane = await classification;
412
- await opts.onClassified?.(lane);
413
- if (lane === 'oauth') setTokenReady(true);
414
- return;
415
- }
416
- }
417
-
418
- const lane = await classification;
419
- await opts.onClassified?.(lane);
420
- if (identityBound && lane !== 'device') return;
421
- // The redirect transport's RETURN leg. An app reaches it whenever the browser
422
- // BLOCKED the sign-in popup and `startWebOAuthSignIn` fell back to a
423
- // full-page redirect (`popup-blocked` / `popup-navigation-failed`), so it is
424
- // load-bearing even though nothing here ever starts a redirect. It consumes a
425
- // code (or a stale OAuth `error`) already in the address bar and rewrites the
426
- // URL via `history.replaceState`; it never begins a navigation.
427
- const oauthCompleted = identityBound
428
- ? false
429
- : await tryCompleteOAuthReturn({
119
+ platform: {
120
+ isWeb: isWebBrowser,
121
+ probeNativeOffline: probeNetInfoOffline,
122
+ completeOAuthReturn: () =>
123
+ tryCompleteOAuthReturn({
430
124
  oxyServices,
431
125
  clientId,
432
126
  authRedirectUri,
433
127
  commitSession: (input) => commitSession(input, { activate: true, oauth: true }),
434
- });
435
- if (oauthCompleted) {
436
- setTokenReady(true);
437
- markAuthResolved();
438
- return;
439
- }
440
-
441
- if (lane === 'oauth') {
442
- setTokenReady(true);
443
- return;
444
- }
445
-
446
- await restoreDeviceSession(opts, false);
447
- } catch (error) {
448
- if (__DEV__) {
449
- loggerUtil.error(
450
- 'Cold boot error',
451
- error instanceof Error ? error : new Error(String(error)),
452
- { component: 'runProviderColdBoot' },
453
- );
454
- }
455
- } finally {
456
- markAuthResolved();
457
- }
128
+ }),
129
+ sharedDeviceCredential: createPlatformSharedDeviceCredentialStore,
130
+ runSessionColdBoot,
131
+ logger: loggerUtil,
132
+ },
133
+ });
458
134
  }
@@ -38,6 +38,7 @@ import {
38
38
  createAuthRefreshHandler,
39
39
  startTokenRefreshScheduler,
40
40
  createAccountDialogController,
41
+ saveWebSessionAccountSummary,
41
42
  } from '@oxy.so/core/session';
42
43
  import { logger as loggerUtil } from '@oxy.so/core';
43
44
  import {
@@ -1355,13 +1356,18 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
1355
1356
  // cold boot can paint it before the network answers. Only for a device-lane
1356
1357
  // account session: an identity-bound client and an isolated OAuth session
1357
1358
  // always boot through the network. A sign-out deletes it.
1359
+ // On the web the account's summary also goes where a page without React
1360
+ // reads it before its first draw (`peekWebSession`, core's web session):
1361
+ // `localStorage` is synchronous, the profile cache above is not.
1358
1362
  const cachedAccountJsonRef = useRef<string | null>(null);
1359
1363
  useEffect(() => {
1360
1364
  if (!cachedBoot || identity) return;
1365
+ const web = isWebBrowser() && usesSharedDeviceCredential;
1361
1366
  if (user === null) {
1362
1367
  if (cachedAccountJsonRef.current !== null) {
1363
1368
  cachedAccountJsonRef.current = null;
1364
1369
  void cachedBoot.clearAccount();
1370
+ if (web) saveWebSessionAccountSummary(null);
1365
1371
  }
1366
1372
  return;
1367
1373
  }
@@ -1370,7 +1376,8 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
1370
1376
  if (json === cachedAccountJsonRef.current) return;
1371
1377
  cachedAccountJsonRef.current = json;
1372
1378
  void cachedBoot.saveAccount(user);
1373
- }, [cachedBoot, identity, user, runtime]);
1379
+ if (web) saveWebSessionAccountSummary(user);
1380
+ }, [cachedBoot, identity, user, runtime, usesSharedDeviceCredential]);
1374
1381
 
1375
1382
  // Paint the session saved on this device: the bearer it left (when still
1376
1383
  // valid), the session mirror, the account from its cached profile, auth
@@ -1,35 +1,7 @@
1
- import { publicApplicationCheck, parseContract } from '@oxy.so/contracts/client';
2
- import type { OxyServices } from '@oxy.so/core';
3
-
4
- export function classifyApplicationSessionLane(metadata: unknown): 'device' | 'oauth' {
5
- const application = parseContract(publicApplicationCheck, metadata);
6
- return application.type === 'third_party' && !application.isOfficial && !application.isInternal
7
- ? 'oauth'
8
- : 'device';
9
- }
10
-
11
- export const APPLICATION_CLASSIFICATION_DEADLINE_MS = 5000;
12
-
13
- /** The active registry projection is authoritative; names and origins confer no trust. */
14
- export async function resolveApplicationSessionLane(
15
- oxyServices: OxyServices,
16
- clientId: string | null | undefined,
17
- ): Promise<'device' | 'oauth'> {
18
- if (!clientId) throw new Error('A registered clientId is required');
19
- // The public endpoint rejects inactive applications and unusable credentials.
20
- let timer: ReturnType<typeof setTimeout> | undefined;
21
- try {
22
- const metadata = await Promise.race([
23
- oxyServices.apps.getPublic(clientId, { cache: false }),
24
- new Promise<never>((_, reject) => {
25
- timer = setTimeout(
26
- () => reject(new Error('Application classification timed out')),
27
- APPLICATION_CLASSIFICATION_DEADLINE_MS,
28
- );
29
- }),
30
- ]);
31
- return classifyApplicationSessionLane(metadata);
32
- } finally {
33
- if (timer !== undefined) clearTimeout(timer);
34
- }
35
- }
1
+ // The registry's lane for an app lives in `@oxy.so/core/session` (core 7.68.0),
2
+ // which the cold boot and the React-free web session share; this module keeps
3
+ // the package's import site.
4
+ export {
5
+ classifyApplicationSessionLane,
6
+ resolveApplicationSessionLane,
7
+ } from '@oxy.so/core/session';