@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.
Files changed (68) hide show
  1. package/lib/commonjs/index.js +7 -0
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/ui/context/OxyContext.js +53 -50
  4. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  5. package/lib/commonjs/ui/context/commitSessionFlow.js +91 -0
  6. package/lib/commonjs/ui/context/commitSessionFlow.js.map +1 -0
  7. package/lib/commonjs/ui/hooks/useOxyEvent.js +28 -0
  8. package/lib/commonjs/ui/hooks/useOxyEvent.js.map +1 -0
  9. package/lib/commonjs/ui/screens/FileManagementScreen.js +3 -9
  10. package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
  11. package/lib/commonjs/ui/session/createSessionClient.js +12 -8
  12. package/lib/commonjs/ui/session/createSessionClient.js.map +1 -1
  13. package/lib/commonjs/ui/session/tokenTransport.js +22 -32
  14. package/lib/commonjs/ui/session/tokenTransport.js.map +1 -1
  15. package/lib/module/index.js +1 -0
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/ui/context/OxyContext.js +54 -51
  18. package/lib/module/ui/context/OxyContext.js.map +1 -1
  19. package/lib/module/ui/context/commitSessionFlow.js +87 -0
  20. package/lib/module/ui/context/commitSessionFlow.js.map +1 -0
  21. package/lib/module/ui/hooks/useOxyEvent.js +25 -0
  22. package/lib/module/ui/hooks/useOxyEvent.js.map +1 -0
  23. package/lib/module/ui/screens/FileManagementScreen.js +3 -9
  24. package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
  25. package/lib/module/ui/session/createSessionClient.js +12 -8
  26. package/lib/module/ui/session/createSessionClient.js.map +1 -1
  27. package/lib/module/ui/session/tokenTransport.js +23 -33
  28. package/lib/module/ui/session/tokenTransport.js.map +1 -1
  29. package/lib/typescript/commonjs/index.d.ts +1 -0
  30. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/ui/context/commitSessionFlow.d.ts +39 -0
  33. package/lib/typescript/commonjs/ui/context/commitSessionFlow.d.ts.map +1 -0
  34. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +3 -1
  35. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/ui/hooks/useOxyEvent.d.ts +8 -0
  37. package/lib/typescript/commonjs/ui/hooks/useOxyEvent.d.ts.map +1 -0
  38. package/lib/typescript/commonjs/ui/screens/FileManagementScreen.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/ui/session/createSessionClient.d.ts +12 -8
  40. package/lib/typescript/commonjs/ui/session/createSessionClient.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts +11 -9
  42. package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts.map +1 -1
  43. package/lib/typescript/module/index.d.ts +1 -0
  44. package/lib/typescript/module/index.d.ts.map +1 -1
  45. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  46. package/lib/typescript/module/ui/context/commitSessionFlow.d.ts +39 -0
  47. package/lib/typescript/module/ui/context/commitSessionFlow.d.ts.map +1 -0
  48. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +3 -1
  49. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  50. package/lib/typescript/module/ui/hooks/useOxyEvent.d.ts +8 -0
  51. package/lib/typescript/module/ui/hooks/useOxyEvent.d.ts.map +1 -0
  52. package/lib/typescript/module/ui/screens/FileManagementScreen.d.ts.map +1 -1
  53. package/lib/typescript/module/ui/session/createSessionClient.d.ts +12 -8
  54. package/lib/typescript/module/ui/session/createSessionClient.d.ts.map +1 -1
  55. package/lib/typescript/module/ui/session/tokenTransport.d.ts +11 -9
  56. package/lib/typescript/module/ui/session/tokenTransport.d.ts.map +1 -1
  57. package/package.json +16 -16
  58. package/src/index.ts +1 -0
  59. package/src/ui/context/OxyContext.tsx +51 -49
  60. package/src/ui/context/__tests__/commitSessionFlow.test.ts +192 -0
  61. package/src/ui/context/commitSessionFlow.ts +115 -0
  62. package/src/ui/context/oxyContextTypes.ts +3 -1
  63. package/src/ui/hooks/useOxyEvent.ts +22 -0
  64. package/src/ui/screens/FileManagementScreen.tsx +3 -9
  65. package/src/ui/session/__tests__/createSessionClient.test.ts +5 -5
  66. package/src/ui/session/__tests__/tokenTransport.test.ts +43 -60
  67. package/src/ui/session/createSessionClient.ts +13 -10
  68. 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 refresh path
16
- * (`refreshPersistedSession`), which presents the persisted zero-cookie device
17
- * credential (`deviceId` + `deviceSecret`) at `POST /session/device/token`. The
18
- * persisted device credential is the sole durable restore credential.
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
- * Concurrent pushes coalesce onto one in-flight mint. A failure is logged and
21
- * swallowed: this method must never throw out (it runs inside the socket state
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
- await inFlightMint;
60
- } finally {
61
- inFlightMint = null;
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
  };