@oxy.so/services 15.1.4 → 15.1.5
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.
- package/lib/commonjs/ui/boot/runProviderColdBoot.js +44 -328
- package/lib/commonjs/ui/boot/runProviderColdBoot.js.map +1 -1
- package/lib/commonjs/ui/session/tokenTransport.js +7 -69
- package/lib/commonjs/ui/session/tokenTransport.js.map +1 -1
- package/lib/module/ui/boot/runProviderColdBoot.js +44 -328
- package/lib/module/ui/boot/runProviderColdBoot.js.map +1 -1
- package/lib/module/ui/session/tokenTransport.js +3 -68
- package/lib/module/ui/session/tokenTransport.js.map +1 -1
- package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts +8 -31
- package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts +1 -33
- package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts.map +1 -1
- package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts +8 -31
- package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts.map +1 -1
- package/lib/typescript/module/ui/session/tokenTransport.d.ts +1 -33
- package/lib/typescript/module/ui/session/tokenTransport.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/ui/boot/runProviderColdBoot.ts +42 -363
- package/src/ui/session/tokenTransport.ts +3 -75
|
@@ -2,47 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { resolveApplicationSessionLane } from "../oauth/applicationSessionLane.js";
|
|
4
4
|
import { logger as loggerUtil } from '@oxy.so/core';
|
|
5
|
-
import { runSessionColdBoot } from '@oxy.so/core/session';
|
|
6
|
-
import { loadPersistedDeviceCredential } from "../utils/deviceCredential.js";
|
|
5
|
+
import { runSessionColdBoot, runWebSessionColdBoot } from '@oxy.so/core/session';
|
|
7
6
|
import { createPlatformSharedDeviceCredentialStore } from "../session/sharedDeviceCredentialStore.js";
|
|
8
7
|
import { tryCompleteOAuthReturn } from "../utils/oauthReturn.js";
|
|
9
8
|
import { isWebBrowser } from "../utils/isWebBrowser.js";
|
|
10
9
|
import { isNetConnectivityOnline } from "../utils/netConnectivity.js";
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
14
|
-
*/
|
|
15
|
-
function hasOAuthReturnOnUrl() {
|
|
16
|
-
const search = globalThis.location?.search;
|
|
17
|
-
if (!search) return false;
|
|
18
|
-
const params = new URLSearchParams(search);
|
|
19
|
-
return params.has('code') || params.has('error');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Whether this origin's own store holds anything a web boot could restore from:
|
|
24
|
-
* a warm access token to plant or a device secret to mint with. A presence
|
|
25
|
-
* check only — nothing read here is used, sent or synced before the
|
|
26
|
-
* classification allows it.
|
|
27
|
-
*/
|
|
28
|
-
async function hasRestorableState(store) {
|
|
29
|
-
const persisted = await store.load();
|
|
30
|
-
return Boolean(persisted?.accessToken || persisted?.deviceSecret);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** How long the cold boot waits for the post-boot SessionClient handoff (ms). */
|
|
34
|
-
export const SESSION_HANDOFF_DEADLINE_MS = 6000;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* HARD overall deadline (ms) for the whole `runSessionColdBoot` step chain.
|
|
38
|
-
*
|
|
39
|
-
* Bounds time-to-route: routing gates on `isAuthResolved`, which resolves when
|
|
40
|
-
* the cold boot finishes, so a network step that never settles (a black-hole
|
|
41
|
-
* network that neither connects nor rejects) would otherwise hang routing
|
|
42
|
-
* indefinitely. 12s comfortably exceeds the healthy worst case of the
|
|
43
|
-
* sequential, single-attempt (`retry:false`), 5s-capped network steps, so it is
|
|
44
|
-
* INERT on healthy loads and only trips on a pathological network. Offline
|
|
45
|
-
* devices short-circuit far sooner via the connectivity hint below.
|
|
11
|
+
* HARD overall deadline (ms) for the whole `runSessionColdBoot` step chain; see
|
|
12
|
+
* `runWebSessionColdBoot` in `@oxy.so/core/session`, which owns the boot.
|
|
46
13
|
*/
|
|
47
14
|
export const COLD_BOOT_OVERALL_DEADLINE_MS = 12_000;
|
|
48
15
|
|
|
@@ -54,308 +21,57 @@ export const COLD_BOOT_OVERALL_DEADLINE_MS = 12_000;
|
|
|
54
21
|
const OFFLINE_PROBE_TIMEOUT_MS = 500;
|
|
55
22
|
|
|
56
23
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* error) resolves to `false` (assume online) so a flaky probe can never falsely
|
|
62
|
-
* skip a real sign-in. Never rejects. On web it reads `navigator.onLine`; on
|
|
63
|
-
* native it races `NetInfo.fetch()` against {@link OFFLINE_PROBE_TIMEOUT_MS},
|
|
64
|
-
* mirroring the existing NetInfo dynamic-import pattern in `OxyProvider`.
|
|
24
|
+
* The native half of the boot's connectivity probe: races `NetInfo.fetch()`
|
|
25
|
+
* against {@link OFFLINE_PROBE_TIMEOUT_MS}. `true` ONLY on an EXPLICIT
|
|
26
|
+
* disconnected verdict; a timeout or an unknown state is "online". A missing
|
|
27
|
+
* NetInfo rejects, which the boot also reads as "online".
|
|
65
28
|
*/
|
|
66
|
-
async function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
setTimeout(() => resolve(null), OFFLINE_PROBE_TIMEOUT_MS);
|
|
76
|
-
})]);
|
|
77
|
-
// `null` ⇒ the probe timed out (unknown → assume online). Only an explicit
|
|
78
|
-
// disconnected verdict disables the network steps (the same rule as the
|
|
79
|
-
// online signal: `isConnected`, never the reachability probe).
|
|
80
|
-
return state !== null && !isNetConnectivityOnline(state);
|
|
81
|
-
} catch {
|
|
82
|
-
// NetInfo missing / probe threw — never block sign-in on a probe failure.
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
29
|
+
async function probeNetInfoOffline() {
|
|
30
|
+
const NetInfo = await import('@react-native-community/netinfo');
|
|
31
|
+
const state = await Promise.race([NetInfo.default.fetch(), new Promise(resolve => {
|
|
32
|
+
setTimeout(() => resolve(null), OFFLINE_PROBE_TIMEOUT_MS);
|
|
33
|
+
})]);
|
|
34
|
+
// `null` ⇒ the probe timed out (unknown → assume online). Only an explicit
|
|
35
|
+
// disconnected verdict disables the network steps (the same rule as the
|
|
36
|
+
// online signal: `isConnected`, never the reachability probe).
|
|
37
|
+
return state !== null && !isNetConnectivityOnline(state);
|
|
85
38
|
}
|
|
86
|
-
/** Starts the provider's fresh classification; a rejection is observed, not swallowed. */
|
|
87
|
-
function startClassification(opts) {
|
|
88
|
-
const classification = (async () => opts.resolveSessionLane?.() ?? resolveApplicationSessionLane(opts.oxyServices, opts.clientId))();
|
|
89
|
-
// Observed so a rejection that lands before it is awaited is not reported as
|
|
90
|
-
// unhandled; every caller still awaits it and sees the rejection.
|
|
91
|
-
classification.catch(() => undefined);
|
|
92
|
-
return classification;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** What the device lanes made of this holder: a session, a verdict against it, or no answer. */
|
|
96
|
-
|
|
97
39
|
/**
|
|
98
|
-
*
|
|
99
|
-
* the
|
|
40
|
+
* Device-first cold boot for `@oxy.so/services` providers: core's
|
|
41
|
+
* `runWebSessionColdBoot` (the order, the deadlines, the verdicts) with this
|
|
42
|
+
* package's platform parts — the registry classifier, the native connectivity
|
|
43
|
+
* probe, the shared device credential slot and the OAuth return leg.
|
|
100
44
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* painted boot already resolved auth from the cache, so nothing waits on the
|
|
104
|
-
* handoff and the pure-local warm token is skipped: the check needs the mint's
|
|
105
|
-
* verdict, which a still-valid token cannot give.
|
|
45
|
+
* The boot NEVER navigates the top-level window; the OAuth return leg only
|
|
46
|
+
* consumes a code that is already in the address bar (#691 phase 7b).
|
|
106
47
|
*/
|
|
107
|
-
|
|
48
|
+
export function runProviderColdBoot(opts) {
|
|
108
49
|
const {
|
|
109
50
|
oxyServices,
|
|
110
|
-
authStore,
|
|
111
|
-
sessionMode = 'account',
|
|
112
|
-
identity,
|
|
113
|
-
sessionClient,
|
|
114
|
-
syncDeviceCredentialToHost,
|
|
115
|
-
commitSession,
|
|
116
|
-
markAuthResolved
|
|
117
|
-
} = opts;
|
|
118
|
-
await opts.beforeDeviceBoot?.();
|
|
119
|
-
|
|
120
|
-
// Best-effort connectivity probe up front: an EXPLICIT offline verdict skips
|
|
121
|
-
// the two doomed network steps so routing settles immediately instead of
|
|
122
|
-
// burning the overall deadline on a mint that cannot succeed. Any ambiguity
|
|
123
|
-
// resolves to "online" — the network steps still run.
|
|
124
|
-
const offline = await detectOfflineHint();
|
|
125
|
-
let outcome = 'unreachable';
|
|
126
|
-
let holderRejected = false;
|
|
127
|
-
await runSessionColdBoot({
|
|
128
|
-
oxy: oxyServices,
|
|
129
|
-
store: authStore,
|
|
130
|
-
platform: {
|
|
131
|
-
isWeb: isWebBrowser(),
|
|
132
|
-
isNative: !isWebBrowser()
|
|
133
|
-
},
|
|
134
|
-
sessionMode,
|
|
135
|
-
identity,
|
|
136
|
-
// The device-wide shared credential slot, enabling the `shared-device-adopt`
|
|
137
|
-
// lane: a newly installed official app joins this device's existing session
|
|
138
|
-
// instead of falling back to signing a challenge with the Commons identity
|
|
139
|
-
// key. `null` on web, where each origin is its own device by design; the
|
|
140
|
-
// core lane is also skipped outright in `sessionMode: 'identity'`.
|
|
141
|
-
// Off when the provider was given a platform's own store: the credential
|
|
142
|
-
// then lives there and nowhere else.
|
|
143
|
-
sharedDeviceCredential: opts.useSharedDeviceCredential === false ? undefined : createPlatformSharedDeviceCredentialStore() ?? undefined,
|
|
144
|
-
overallDeadlineMs: COLD_BOOT_OVERALL_DEADLINE_MS,
|
|
145
|
-
isOffline: () => offline,
|
|
146
|
-
requireServerVerdict: painted,
|
|
147
|
-
onHolderRejected: () => {
|
|
148
|
-
holderRejected = true;
|
|
149
|
-
},
|
|
150
|
-
onStepDeadline: stepId => {
|
|
151
|
-
loggerUtil.warn(`Cold-boot step "${stepId}" exceeded the ${COLD_BOOT_OVERALL_DEADLINE_MS}ms overall deadline — abandoned; routing proceeds signed-out`, {
|
|
152
|
-
component: 'runProviderColdBoot',
|
|
153
|
-
method: 'onStepDeadline'
|
|
154
|
-
});
|
|
155
|
-
},
|
|
156
|
-
onSession: async session => {
|
|
157
|
-
outcome = 'session';
|
|
158
|
-
// Mint already persisted `{deviceId, deviceSecret}` to the store; sync the
|
|
159
|
-
// in-memory SessionClient host so sockets + tab-focus re-mint can use it.
|
|
160
|
-
await syncDeviceCredentialToHost();
|
|
161
|
-
const handoff = commitSession({
|
|
162
|
-
sessionId: session.sessionId,
|
|
163
|
-
accessToken: session.accessToken,
|
|
164
|
-
userId: session.userId,
|
|
165
|
-
deviceState: session.state
|
|
166
|
-
}, {
|
|
167
|
-
activate: false
|
|
168
|
-
});
|
|
169
|
-
if (painted) {
|
|
170
|
-
// The account is already on screen; the commit refreshes its profile.
|
|
171
|
-
await handoff;
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
let handoffDeadlineId;
|
|
175
|
-
await Promise.race([handoff, new Promise(resolve => {
|
|
176
|
-
handoffDeadlineId = setTimeout(resolve, SESSION_HANDOFF_DEADLINE_MS);
|
|
177
|
-
})]).finally(() => {
|
|
178
|
-
if (handoffDeadlineId !== undefined) {
|
|
179
|
-
clearTimeout(handoffDeadlineId);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
markAuthResolved();
|
|
183
|
-
},
|
|
184
|
-
onSignedOut: async () => {
|
|
185
|
-
outcome = holderRejected ? 'rejected' : 'unreachable';
|
|
186
|
-
await syncDeviceCredentialToHost();
|
|
187
|
-
// A painted session is the caller's to end or keep (see verifyCachedSession).
|
|
188
|
-
if (painted) return;
|
|
189
|
-
const cred = await loadPersistedDeviceCredential(authStore);
|
|
190
|
-
if (cred) {
|
|
191
|
-
try {
|
|
192
|
-
await sessionClient.start();
|
|
193
|
-
} catch (socketError) {
|
|
194
|
-
if (__DEV__) {
|
|
195
|
-
loggerUtil.debug('Device socket start failed (non-fatal)', {
|
|
196
|
-
component: 'runProviderColdBoot'
|
|
197
|
-
}, socketError);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
markAuthResolved();
|
|
202
|
-
},
|
|
203
|
-
onStepError: (id, error) => {
|
|
204
|
-
if (__DEV__) {
|
|
205
|
-
loggerUtil.debug(`Cold-boot step "${id}" errored (non-fatal, falling through)`, {
|
|
206
|
-
component: 'runProviderColdBoot'
|
|
207
|
-
}, error);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
await opts.afterDeviceBoot?.();
|
|
212
|
-
return outcome;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The background check of a painted session: the registry's classification and
|
|
217
|
-
* a mint with this holder's own credential (whose commit refreshes the profile).
|
|
218
|
-
* Each is asked until the server answers it. A verdict against the session
|
|
219
|
-
* signs out at that moment; no answer keeps the cached session on screen and
|
|
220
|
-
* hands the caller a retry.
|
|
221
|
-
*/
|
|
222
|
-
async function verifyCachedSession(opts, verified, classification) {
|
|
223
|
-
if (!verified.lane) {
|
|
224
|
-
let lane = null;
|
|
225
|
-
try {
|
|
226
|
-
lane = await classification;
|
|
227
|
-
} catch {
|
|
228
|
-
// The registry could not be asked (offline, timeout, 5xx). That is no
|
|
229
|
-
// verdict on this app: the cached `device` classification stands until it
|
|
230
|
-
// answers.
|
|
231
|
-
}
|
|
232
|
-
if (lane === 'oauth') {
|
|
233
|
-
await opts.onCachedSessionRejected?.();
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
verified.lane = lane === 'device';
|
|
237
|
-
}
|
|
238
|
-
if (!verified.session) {
|
|
239
|
-
const outcome = await restoreDeviceSession(opts, true);
|
|
240
|
-
if (outcome === 'rejected') {
|
|
241
|
-
await opts.onCachedSessionRejected?.();
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
verified.session = outcome === 'session';
|
|
245
|
-
}
|
|
246
|
-
if (!verified.lane || !verified.session) {
|
|
247
|
-
opts.onCachedSessionUnconfirmed?.(() => verifyCachedSession(opts, verified, verified.lane ? Promise.resolve('device') : startClassification(opts)));
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Device-first cold boot for `@oxy.so/services` providers.
|
|
253
|
-
*
|
|
254
|
-
* A returning session saved on this device (account mode, the app last
|
|
255
|
-
* classified `device`, its profile cached) paints first, with no network, and
|
|
256
|
-
* is then checked in the background — see `paintCachedSession`. Otherwise, a
|
|
257
|
-
* first boot:
|
|
258
|
-
*
|
|
259
|
-
* Ordered pipeline:
|
|
260
|
-
* 1. Complete an OAuth authorization-code return already on the URL (web)
|
|
261
|
-
* 2. `runSessionColdBoot` — device-secret mint (+ the native Commons-proof lane,
|
|
262
|
-
* or the primary-identity-key lane in `sessionMode: 'identity'`)
|
|
263
|
-
*
|
|
264
|
-
* Step 1 is ACCOUNT-MODE ONLY: it commits whichever account the IdP resolves,
|
|
265
|
-
* which for an identity-bound client is somebody else's account by construction.
|
|
266
|
-
* In `'identity'` mode the boot is exactly step 2.
|
|
267
|
-
*
|
|
268
|
-
* The boot NEVER navigates the top-level window. There is no automatic
|
|
269
|
-
* `prompt=none` bounce to the IdP: a web origin with no local device credential
|
|
270
|
-
* resolves SIGNED OUT and waits for the user's next explicit "Continue with
|
|
271
|
-
* Oxy", which opens a popup from a real gesture (#691 phase 7b). Step 1 is not a
|
|
272
|
-
* navigation — it only consumes a code that is already in the address bar.
|
|
273
|
-
*/
|
|
274
|
-
export async function runProviderColdBoot(opts) {
|
|
275
|
-
const {
|
|
276
|
-
oxyServices,
|
|
277
|
-
authStore,
|
|
278
51
|
clientId,
|
|
279
52
|
authRedirectUri,
|
|
280
|
-
|
|
281
|
-
commitSession,
|
|
282
|
-
markAuthResolved,
|
|
283
|
-
setTokenReady
|
|
53
|
+
commitSession
|
|
284
54
|
} = opts;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}, classification);
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// The verdict decides HOW a session is restored, never WHETHER there is one.
|
|
309
|
-
// A web origin with nothing to restore and no OAuth return on the URL ends
|
|
310
|
-
// signed out on either lane, so routing need not wait a network round trip
|
|
311
|
-
// for an answer that cannot change the outcome. The classification still
|
|
312
|
-
// completes below and still gates every later sign-in
|
|
313
|
-
// (`ensureDeviceSessionLane` shares this same in-flight lookup).
|
|
314
|
-
if (freshLaunch && isWebBrowser()) {
|
|
315
|
-
if (!(await hasRestorableState(authStore))) {
|
|
316
|
-
markAuthResolved();
|
|
317
|
-
const lane = await classification;
|
|
318
|
-
await opts.onClassified?.(lane);
|
|
319
|
-
if (lane === 'oauth') setTokenReady(true);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
const lane = await classification;
|
|
324
|
-
await opts.onClassified?.(lane);
|
|
325
|
-
if (identityBound && lane !== 'device') return;
|
|
326
|
-
// The redirect transport's RETURN leg. An app reaches it whenever the browser
|
|
327
|
-
// BLOCKED the sign-in popup and `startWebOAuthSignIn` fell back to a
|
|
328
|
-
// full-page redirect (`popup-blocked` / `popup-navigation-failed`), so it is
|
|
329
|
-
// load-bearing even though nothing here ever starts a redirect. It consumes a
|
|
330
|
-
// code (or a stale OAuth `error`) already in the address bar and rewrites the
|
|
331
|
-
// URL via `history.replaceState`; it never begins a navigation.
|
|
332
|
-
const oauthCompleted = identityBound ? false : await tryCompleteOAuthReturn({
|
|
333
|
-
oxyServices,
|
|
334
|
-
clientId,
|
|
335
|
-
authRedirectUri,
|
|
336
|
-
commitSession: input => commitSession(input, {
|
|
337
|
-
activate: true,
|
|
338
|
-
oauth: true
|
|
339
|
-
})
|
|
340
|
-
});
|
|
341
|
-
if (oauthCompleted) {
|
|
342
|
-
setTokenReady(true);
|
|
343
|
-
markAuthResolved();
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (lane === 'oauth') {
|
|
347
|
-
setTokenReady(true);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
await restoreDeviceSession(opts, false);
|
|
351
|
-
} catch (error) {
|
|
352
|
-
if (__DEV__) {
|
|
353
|
-
loggerUtil.error('Cold boot error', error instanceof Error ? error : new Error(String(error)), {
|
|
354
|
-
component: 'runProviderColdBoot'
|
|
355
|
-
});
|
|
55
|
+
return runWebSessionColdBoot({
|
|
56
|
+
...opts,
|
|
57
|
+
resolveSessionLane: () => opts.resolveSessionLane?.() ?? resolveApplicationSessionLane(oxyServices, clientId),
|
|
58
|
+
overallDeadlineMs: COLD_BOOT_OVERALL_DEADLINE_MS,
|
|
59
|
+
platform: {
|
|
60
|
+
isWeb: isWebBrowser,
|
|
61
|
+
probeNativeOffline: probeNetInfoOffline,
|
|
62
|
+
completeOAuthReturn: () => tryCompleteOAuthReturn({
|
|
63
|
+
oxyServices,
|
|
64
|
+
clientId,
|
|
65
|
+
authRedirectUri,
|
|
66
|
+
commitSession: input => commitSession(input, {
|
|
67
|
+
activate: true,
|
|
68
|
+
oauth: true
|
|
69
|
+
})
|
|
70
|
+
}),
|
|
71
|
+
sharedDeviceCredential: createPlatformSharedDeviceCredentialStore,
|
|
72
|
+
runSessionColdBoot,
|
|
73
|
+
logger: loggerUtil
|
|
356
74
|
}
|
|
357
|
-
}
|
|
358
|
-
markAuthResolved();
|
|
359
|
-
}
|
|
75
|
+
});
|
|
360
76
|
}
|
|
361
77
|
//# sourceMappingURL=runProviderColdBoot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["resolveApplicationSessionLane","logger","loggerUtil","runSessionColdBoot","
|
|
1
|
+
{"version":3,"names":["resolveApplicationSessionLane","logger","loggerUtil","runSessionColdBoot","runWebSessionColdBoot","createPlatformSharedDeviceCredentialStore","tryCompleteOAuthReturn","isWebBrowser","isNetConnectivityOnline","COLD_BOOT_OVERALL_DEADLINE_MS","OFFLINE_PROBE_TIMEOUT_MS","probeNetInfoOffline","NetInfo","state","Promise","race","default","fetch","resolve","setTimeout","runProviderColdBoot","opts","oxyServices","clientId","authRedirectUri","commitSession","resolveSessionLane","overallDeadlineMs","platform","isWeb","probeNativeOffline","completeOAuthReturn","input","activate","oauth","sharedDeviceCredential"],"sourceRoot":"../../../../src","sources":["ui/boot/runProviderColdBoot.ts"],"mappings":";;AAAA,SAASA,6BAA6B,QAAQ,oCAAiC;AAC/E,SAASC,MAAM,IAAIC,UAAU,QAA0B,cAAc;AACrE,SACEC,kBAAkB,EAClBC,qBAAqB,QAIhB,sBAAsB;AAE7B,SAASC,yCAAyC,QAAQ,2CAAwC;AAClG,SAASC,sBAAsB,QAAQ,yBAAsB;AAC7D,SAASC,YAAY,QAAQ,0BAAuB;AACpD,SAASC,uBAAuB,QAAQ,6BAA0B;AAGlE;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAA6B,GAAG,MAAM;;AAEnD;AACA;AACA;AACA;AACA;AACA,MAAMC,wBAAwB,GAAG,GAAG;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA,eAAeC,mBAAmBA,CAAA,EAAqB;EACrD,MAAMC,OAAO,GAAG,MAAM,MAAM,CAAC,iCAAiC,CAAC;EAC/D,MAAMC,KAAK,GAAG,MAAMC,OAAO,CAACC,IAAI,CAAC,CAC/BH,OAAO,CAACI,OAAO,CAACC,KAAK,CAAC,CAAC,EACvB,IAAIH,OAAO,CAAQI,OAAO,IAAK;IAC7BC,UAAU,CAAC,MAAMD,OAAO,CAAC,IAAI,CAAC,EAAER,wBAAwB,CAAC;EAC3D,CAAC,CAAC,CACH,CAAC;EACF;EACA;EACA;EACA,OAAOG,KAAK,KAAK,IAAI,IAAI,CAACL,uBAAuB,CAACK,KAAK,CAAC;AAC1D;AA0DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,mBAAmBA,CAACC,IAAgC,EAAiB;EACnF,MAAM;IAAEC,WAAW;IAAEC,QAAQ;IAAEC,eAAe;IAAEC;EAAc,CAAC,GAAGJ,IAAI;EACtE,OAAOjB,qBAAqB,CAAC;IAC3B,GAAGiB,IAAI;IACPK,kBAAkB,EAAEA,CAAA,KAClBL,IAAI,CAACK,kBAAkB,GAAG,CAAC,IAAI1B,6BAA6B,CAACsB,WAAW,EAAEC,QAAQ,CAAC;IACrFI,iBAAiB,EAAElB,6BAA6B;IAChDmB,QAAQ,EAAE;MACRC,KAAK,EAAEtB,YAAY;MACnBuB,kBAAkB,EAAEnB,mBAAmB;MACvCoB,mBAAmB,EAAEA,CAAA,KACnBzB,sBAAsB,CAAC;QACrBgB,WAAW;QACXC,QAAQ;QACRC,eAAe;QACfC,aAAa,EAAGO,KAAK,IAAKP,aAAa,CAACO,KAAK,EAAE;UAAEC,QAAQ,EAAE,IAAI;UAAEC,KAAK,EAAE;QAAK,CAAC;MAChF,CAAC,CAAC;MACJC,sBAAsB,EAAE9B,yCAAyC;MACjEF,kBAAkB;MAClBF,MAAM,EAAEC;IACV;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -1,71 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* `ensureActiveToken` is the fallback the client uses when a `session_state`
|
|
8
|
-
* push arrived WITHOUT an embedded `activeToken` and the planted bearer does not
|
|
9
|
-
* already belong to the state's active account. It mints one through the ONE
|
|
10
|
-
* unified single-flight the scheduler, the request-time preflight, and the 401
|
|
11
|
-
* retry all use — `oxyServices.http.refreshAccessToken(...)` — which runs
|
|
12
|
-
* the installed refresh handler (present the persisted zero-cookie `deviceId` +
|
|
13
|
-
* `deviceSecret` at `POST /session/device/token`, which mints for the device's
|
|
14
|
-
* CURRENT active account). Routing through the SAME entry point means this lane
|
|
15
|
-
* can never double-rotate the device secret against the others: it has NO
|
|
16
|
-
* private single-flight of its own.
|
|
17
|
-
*
|
|
18
|
-
* The short-circuit compares the planted bearer's ACCOUNT against
|
|
19
|
-
* `state.activeAccountId`, not mere token presence: a bearer for the PREVIOUS
|
|
20
|
-
* account (an account switch) must still mint the new account's token — skipping
|
|
21
|
-
* on presence alone would leave a subscriber observing the new active account
|
|
22
|
-
* under the old account's bearer (the account-switch 404 race).
|
|
23
|
-
*
|
|
24
|
-
* A failure is logged and swallowed: this method must never throw out (it runs
|
|
25
|
-
* inside the socket state handler).
|
|
26
|
-
*
|
|
27
|
-
* `getPinnedAccountId` is the identity-bound escape hatch. Converging the bearer
|
|
28
|
-
* on `state.activeAccountId` is precisely what an identity-bound client must
|
|
29
|
-
* never do — its token is minted for the PINNED account by the cold boot /
|
|
30
|
-
* re-mint lane. `SessionClient` already bypasses the transport entirely while
|
|
31
|
-
* pinned; this guard is the services-side half of that contract, so no future
|
|
32
|
-
* wiring can reintroduce the convergence from this end.
|
|
33
|
-
*/
|
|
34
|
-
export function createTokenTransport(oxyServices, getPinnedAccountId) {
|
|
35
|
-
return {
|
|
36
|
-
async ensureActiveToken(state) {
|
|
37
|
-
if ((getPinnedAccountId?.() ?? null) !== null) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
// Skip the mint ONLY when the planted bearer already identifies the
|
|
42
|
-
// active account. `getCurrentUserId()` decodes the bearer's `userId`/`id`
|
|
43
|
-
// (null when absent/opaque), directly comparable to the account id.
|
|
44
|
-
const activeAccountId = state.activeAccountId;
|
|
45
|
-
if (activeAccountId !== null && oxyServices.session.userId === activeAccountId) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
logger.warn('ensureActiveToken: bearer-account check threw', {
|
|
50
|
-
component: 'TokenTransport'
|
|
51
|
-
}, error);
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
// The shared HttpService single-flight coalesces concurrent callers onto
|
|
55
|
-
// one in-flight mint; no local `inFlightMint` guard is needed.
|
|
56
|
-
const token = await oxyServices.http.refreshAccessToken('preflight');
|
|
57
|
-
if (!token) {
|
|
58
|
-
logger.debug('ensureActiveToken: refresh produced no session', {
|
|
59
|
-
component: 'TokenTransport',
|
|
60
|
-
deviceId: state.deviceId
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
logger.warn('ensureActiveToken: refresh failed', {
|
|
65
|
-
component: 'TokenTransport'
|
|
66
|
-
}, error);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
3
|
+
// The transport moved to `@oxy.so/core/session` (core 7.66.0) so the React-free
|
|
4
|
+
// web session shares it; this module keeps the package's import site.
|
|
5
|
+
export { createTokenTransport } from '@oxy.so/core/session';
|
|
71
6
|
//# sourceMappingURL=tokenTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createTokenTransport"],"sourceRoot":"../../../../src","sources":["ui/session/tokenTransport.ts"],"mappings":";;AAAA;AACA;AACA,SAASA,oBAAoB,QAAQ,sBAAsB","ignoreList":[]}
|
|
@@ -2,18 +2,9 @@ import { type OxyServices } from '@oxy.so/core';
|
|
|
2
2
|
import { type AuthStateStore, type IdentityBinding, type SessionMode } from '@oxy.so/core/session';
|
|
3
3
|
import type { SessionClient } from '@oxy.so/core/session';
|
|
4
4
|
import type { CommitInput } from '../context/oxyContextTypes';
|
|
5
|
-
/** How long the cold boot waits for the post-boot SessionClient handoff (ms). */
|
|
6
|
-
export declare const SESSION_HANDOFF_DEADLINE_MS = 6000;
|
|
7
5
|
/**
|
|
8
|
-
* HARD overall deadline (ms) for the whole `runSessionColdBoot` step chain
|
|
9
|
-
*
|
|
10
|
-
* Bounds time-to-route: routing gates on `isAuthResolved`, which resolves when
|
|
11
|
-
* the cold boot finishes, so a network step that never settles (a black-hole
|
|
12
|
-
* network that neither connects nor rejects) would otherwise hang routing
|
|
13
|
-
* indefinitely. 12s comfortably exceeds the healthy worst case of the
|
|
14
|
-
* sequential, single-attempt (`retry:false`), 5s-capped network steps, so it is
|
|
15
|
-
* INERT on healthy loads and only trips on a pathological network. Offline
|
|
16
|
-
* devices short-circuit far sooner via the connectivity hint below.
|
|
6
|
+
* HARD overall deadline (ms) for the whole `runSessionColdBoot` step chain; see
|
|
7
|
+
* `runWebSessionColdBoot` in `@oxy.so/core/session`, which owns the boot.
|
|
17
8
|
*/
|
|
18
9
|
export declare const COLD_BOOT_OVERALL_DEADLINE_MS = 12000;
|
|
19
10
|
export interface RunProviderColdBootOptions {
|
|
@@ -72,27 +63,13 @@ export interface RunProviderColdBootOptions {
|
|
|
72
63
|
onCachedSessionUnconfirmed?: (retry: () => Promise<void>) => void;
|
|
73
64
|
}
|
|
74
65
|
/**
|
|
75
|
-
* Device-first cold boot for `@oxy.so/services` providers
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* is then checked in the background — see `paintCachedSession`. Otherwise, a
|
|
80
|
-
* first boot:
|
|
81
|
-
*
|
|
82
|
-
* Ordered pipeline:
|
|
83
|
-
* 1. Complete an OAuth authorization-code return already on the URL (web)
|
|
84
|
-
* 2. `runSessionColdBoot` — device-secret mint (+ the native Commons-proof lane,
|
|
85
|
-
* or the primary-identity-key lane in `sessionMode: 'identity'`)
|
|
86
|
-
*
|
|
87
|
-
* Step 1 is ACCOUNT-MODE ONLY: it commits whichever account the IdP resolves,
|
|
88
|
-
* which for an identity-bound client is somebody else's account by construction.
|
|
89
|
-
* In `'identity'` mode the boot is exactly step 2.
|
|
66
|
+
* Device-first cold boot for `@oxy.so/services` providers: core's
|
|
67
|
+
* `runWebSessionColdBoot` (the order, the deadlines, the verdicts) with this
|
|
68
|
+
* package's platform parts — the registry classifier, the native connectivity
|
|
69
|
+
* probe, the shared device credential slot and the OAuth return leg.
|
|
90
70
|
*
|
|
91
|
-
* The boot NEVER navigates the top-level window
|
|
92
|
-
*
|
|
93
|
-
* resolves SIGNED OUT and waits for the user's next explicit "Continue with
|
|
94
|
-
* Oxy", which opens a popup from a real gesture (#691 phase 7b). Step 1 is not a
|
|
95
|
-
* navigation — it only consumes a code that is already in the address bar.
|
|
71
|
+
* The boot NEVER navigates the top-level window; the OAuth return leg only
|
|
72
|
+
* consumes a code that is already in the address bar (#691 phase 7b).
|
|
96
73
|
*/
|
|
97
74
|
export declare function runProviderColdBoot(opts: RunProviderColdBootOptions): Promise<void>;
|
|
98
75
|
//# sourceMappingURL=runProviderColdBoot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runProviderColdBoot.d.ts","sourceRoot":"","sources":["../../../../../src/ui/boot/runProviderColdBoot.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,
|
|
1
|
+
{"version":3,"file":"runProviderColdBoot.d.ts","sourceRoot":"","sources":["../../../../../src/ui/boot/runProviderColdBoot.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAK1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAS,CAAC;AA6BpD,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,cAAc,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,aAAa,EAAE,aAAa,CAAC;IAC7B,8EAA8E;IAC9E,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC;IACvD,0EAA0E;IAC1E,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,0BAA0B,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,aAAa,EAAE,CACb,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KAC5C,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C;;;OAGG;IACH,0BAA0B,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;CACnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBnF"}
|
|
@@ -1,34 +1,2 @@
|
|
|
1
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"tokenTransport.d.ts","sourceRoot":"","sources":["../../../../../src/ui/session/tokenTransport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
|