@oxyhq/services 19.1.2 → 19.1.3
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/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +53 -50
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/commitSessionFlow.js +91 -0
- package/lib/commonjs/ui/context/commitSessionFlow.js.map +1 -0
- package/lib/commonjs/ui/hooks/useOxyEvent.js +28 -0
- package/lib/commonjs/ui/hooks/useOxyEvent.js.map +1 -0
- package/lib/commonjs/ui/screens/FileManagementScreen.js +3 -9
- package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/session/createSessionClient.js +12 -8
- package/lib/commonjs/ui/session/createSessionClient.js.map +1 -1
- package/lib/commonjs/ui/session/tokenTransport.js +22 -32
- package/lib/commonjs/ui/session/tokenTransport.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +54 -51
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/commitSessionFlow.js +87 -0
- package/lib/module/ui/context/commitSessionFlow.js.map +1 -0
- package/lib/module/ui/hooks/useOxyEvent.js +25 -0
- package/lib/module/ui/hooks/useOxyEvent.js.map +1 -0
- package/lib/module/ui/screens/FileManagementScreen.js +3 -9
- package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/module/ui/session/createSessionClient.js +12 -8
- package/lib/module/ui/session/createSessionClient.js.map +1 -1
- package/lib/module/ui/session/tokenTransport.js +23 -33
- package/lib/module/ui/session/tokenTransport.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/commitSessionFlow.d.ts +39 -0
- package/lib/typescript/commonjs/ui/context/commitSessionFlow.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +3 -1
- package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useOxyEvent.d.ts +8 -0
- package/lib/typescript/commonjs/ui/hooks/useOxyEvent.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/FileManagementScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/session/createSessionClient.d.ts +12 -8
- package/lib/typescript/commonjs/ui/session/createSessionClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts +11 -9
- package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/commitSessionFlow.d.ts +39 -0
- package/lib/typescript/module/ui/context/commitSessionFlow.d.ts.map +1 -0
- package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +3 -1
- package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useOxyEvent.d.ts +8 -0
- package/lib/typescript/module/ui/hooks/useOxyEvent.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/FileManagementScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/session/createSessionClient.d.ts +12 -8
- package/lib/typescript/module/ui/session/createSessionClient.d.ts.map +1 -1
- package/lib/typescript/module/ui/session/tokenTransport.d.ts +11 -9
- package/lib/typescript/module/ui/session/tokenTransport.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/index.ts +1 -0
- package/src/ui/context/OxyContext.tsx +51 -49
- package/src/ui/context/__tests__/commitSessionFlow.test.ts +192 -0
- package/src/ui/context/commitSessionFlow.ts +115 -0
- package/src/ui/context/oxyContextTypes.ts +3 -1
- package/src/ui/hooks/useOxyEvent.ts +22 -0
- package/src/ui/screens/FileManagementScreen.tsx +3 -9
- package/src/ui/session/__tests__/createSessionClient.test.ts +5 -5
- package/src/ui/session/__tests__/tokenTransport.test.ts +43 -60
- package/src/ui/session/createSessionClient.ts +13 -10
- package/src/ui/session/tokenTransport.ts +22 -41
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
refreshPersistedSession,
|
|
3
|
-
logger,
|
|
4
|
-
type AuthStateStore,
|
|
5
|
-
type OxyServices,
|
|
6
|
-
type TokenTransport,
|
|
7
|
-
} from '@oxyhq/core';
|
|
1
|
+
import { logger, type OxyServices, type TokenTransport } from '@oxyhq/core';
|
|
8
2
|
import type { DeviceSessionState } from '@oxyhq/contracts';
|
|
9
3
|
|
|
10
4
|
/**
|
|
@@ -12,21 +6,18 @@ import type { DeviceSessionState } from '@oxyhq/contracts';
|
|
|
12
6
|
*
|
|
13
7
|
* `ensureActiveToken` is the fallback the client uses when a `session_state`
|
|
14
8
|
* push arrived WITHOUT an embedded `activeToken` and the app currently holds no
|
|
15
|
-
* bearer. It mints one through the ONE unified
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
9
|
+
* bearer. It mints one through the ONE unified single-flight the scheduler, the
|
|
10
|
+
* request-time preflight, and the 401 retry all use —
|
|
11
|
+
* `oxyServices.httpService.refreshAccessToken(...)` — which runs the installed
|
|
12
|
+
* refresh handler (present the persisted zero-cookie `deviceId` + `deviceSecret`
|
|
13
|
+
* at `POST /session/device/token`). Routing through the SAME entry point means
|
|
14
|
+
* this lane can never double-rotate the device secret against the others: it has
|
|
15
|
+
* NO private single-flight of its own.
|
|
19
16
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* handler).
|
|
17
|
+
* A failure is logged and swallowed: this method must never throw out (it runs
|
|
18
|
+
* inside the socket state handler).
|
|
23
19
|
*/
|
|
24
|
-
export function createTokenTransport(
|
|
25
|
-
oxyServices: OxyServices,
|
|
26
|
-
store: AuthStateStore,
|
|
27
|
-
): TokenTransport {
|
|
28
|
-
let inFlightMint: Promise<void> | null = null;
|
|
29
|
-
|
|
20
|
+
export function createTokenTransport(oxyServices: OxyServices): TokenTransport {
|
|
30
21
|
return {
|
|
31
22
|
async ensureActiveToken(state: DeviceSessionState): Promise<void> {
|
|
32
23
|
try {
|
|
@@ -37,28 +28,18 @@ export function createTokenTransport(
|
|
|
37
28
|
logger.warn('ensureActiveToken: getAccessToken threw', { component: 'TokenTransport' }, error);
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
if (inFlightMint) {
|
|
41
|
-
return inFlightMint;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
inFlightMint = (async () => {
|
|
45
|
-
try {
|
|
46
|
-
const token = await refreshPersistedSession({ oxy: oxyServices, store });
|
|
47
|
-
if (!token) {
|
|
48
|
-
logger.debug('ensureActiveToken: refresh produced no session', {
|
|
49
|
-
component: 'TokenTransport',
|
|
50
|
-
deviceId: state.deviceId,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
} catch (error) {
|
|
54
|
-
logger.warn('ensureActiveToken: refresh failed', { component: 'TokenTransport' }, error);
|
|
55
|
-
}
|
|
56
|
-
})();
|
|
57
|
-
|
|
58
31
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
32
|
+
// The shared HttpService single-flight coalesces concurrent callers onto
|
|
33
|
+
// one in-flight mint; no local `inFlightMint` guard is needed.
|
|
34
|
+
const token = await oxyServices.httpService.refreshAccessToken('preflight');
|
|
35
|
+
if (!token) {
|
|
36
|
+
logger.debug('ensureActiveToken: refresh produced no session', {
|
|
37
|
+
component: 'TokenTransport',
|
|
38
|
+
deviceId: state.deviceId,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
logger.warn('ensureActiveToken: refresh failed', { component: 'TokenTransport' }, error);
|
|
62
43
|
}
|
|
63
44
|
},
|
|
64
45
|
};
|