@oxyhq/services 28.0.0 → 29.0.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 (324) hide show
  1. package/NOTICE +10 -9
  2. package/README.md +65 -2
  3. package/android/src/main/java/so/oxy/devicesession/OxyDeviceSessionModule.kt +178 -0
  4. package/android/src/main/java/so/oxy/devicesession/OxyDeviceSessionProvider.kt +99 -0
  5. package/android/src/main/java/so/oxy/devicesession/OxyDeviceSessionStore.kt +115 -0
  6. package/expo-module.config.json +1 -0
  7. package/lib/commonjs/index.js +60 -16
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/ui/boot/runProviderColdBoot.js +7 -0
  10. package/lib/commonjs/ui/boot/runProviderColdBoot.js.map +1 -1
  11. package/lib/commonjs/ui/client.js +12 -7
  12. package/lib/commonjs/ui/client.js.map +1 -1
  13. package/lib/commonjs/ui/components/OxyAccountDialogScreen.js +10 -27
  14. package/lib/commonjs/ui/components/OxyAccountDialogScreen.js.map +1 -1
  15. package/lib/commonjs/ui/components/OxyAuthChooser.js +132 -44
  16. package/lib/commonjs/ui/components/OxyAuthChooser.js.map +1 -1
  17. package/lib/commonjs/ui/components/OxyProvider.js +4 -2
  18. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  19. package/lib/commonjs/ui/components/SurfaceScreen.js +31 -3
  20. package/lib/commonjs/ui/components/SurfaceScreen.js.map +1 -1
  21. package/lib/commonjs/ui/components/authChooser/AccountsMenuView.js +209 -84
  22. package/lib/commonjs/ui/components/authChooser/AccountsMenuView.js.map +1 -1
  23. package/lib/commonjs/ui/components/authChooser/SignInEntryView.js +25 -7
  24. package/lib/commonjs/ui/components/authChooser/SignInEntryView.js.map +1 -1
  25. package/lib/commonjs/ui/components/authChooser/primitives.js +35 -22
  26. package/lib/commonjs/ui/components/authChooser/primitives.js.map +1 -1
  27. package/lib/commonjs/ui/components/authChooser/types.js +11 -0
  28. package/lib/commonjs/ui/components/authChooser/types.js.map +1 -1
  29. package/lib/commonjs/ui/context/OxyContext.js +257 -306
  30. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  31. package/lib/commonjs/ui/context/hooks/useAuthOperations.js +27 -37
  32. package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
  33. package/lib/commonjs/ui/context/oxyContextHelpers.js +0 -29
  34. package/lib/commonjs/ui/context/oxyContextHelpers.js.map +1 -1
  35. package/lib/commonjs/ui/context/useOxyAccountGraph.js +6 -17
  36. package/lib/commonjs/ui/context/useOxyAccountGraph.js.map +1 -1
  37. package/lib/commonjs/ui/hooks/accountDialogSnapshot.js +42 -0
  38. package/lib/commonjs/ui/hooks/accountDialogSnapshot.js.map +1 -0
  39. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +0 -19
  40. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  41. package/lib/commonjs/ui/hooks/useDeviceSwitcher.js +57 -0
  42. package/lib/commonjs/ui/hooks/useDeviceSwitcher.js.map +1 -0
  43. package/lib/commonjs/ui/hooks/useI18n.js +22 -3
  44. package/lib/commonjs/ui/hooks/useI18n.js.map +1 -1
  45. package/lib/commonjs/ui/hooks/useSessionManagement.js +46 -153
  46. package/lib/commonjs/ui/hooks/useSessionManagement.js.map +1 -1
  47. package/lib/commonjs/ui/index.js +12 -7
  48. package/lib/commonjs/ui/index.js.map +1 -1
  49. package/lib/commonjs/ui/navigation/routes.js +85 -73
  50. package/lib/commonjs/ui/navigation/routes.js.map +1 -1
  51. package/lib/commonjs/ui/navigation/surfaces.js +8 -7
  52. package/lib/commonjs/ui/navigation/surfaces.js.map +1 -1
  53. package/lib/commonjs/ui/runtime/createOxyRuntime.js +433 -0
  54. package/lib/commonjs/ui/runtime/createOxyRuntime.js.map +1 -0
  55. package/lib/commonjs/ui/runtime/index.js +63 -0
  56. package/lib/commonjs/ui/runtime/index.js.map +1 -0
  57. package/lib/commonjs/ui/runtime/runtimeContext.js +83 -0
  58. package/lib/commonjs/ui/runtime/runtimeContext.js.map +1 -0
  59. package/lib/commonjs/ui/runtime/types.js +6 -0
  60. package/lib/commonjs/ui/runtime/types.js.map +1 -0
  61. package/lib/commonjs/ui/runtime/useRuntimeSnapshot.js +57 -0
  62. package/lib/commonjs/ui/runtime/useRuntimeSnapshot.js.map +1 -0
  63. package/lib/commonjs/ui/server.js +1 -2
  64. package/lib/commonjs/ui/server.js.map +1 -1
  65. package/lib/commonjs/ui/session/authStore.js +45 -9
  66. package/lib/commonjs/ui/session/authStore.js.map +1 -1
  67. package/lib/commonjs/ui/session/sharedDeviceCredentialStore.js +306 -0
  68. package/lib/commonjs/ui/session/sharedDeviceCredentialStore.js.map +1 -0
  69. package/lib/commonjs/ui/stores/authStore.js +154 -55
  70. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  71. package/lib/commonjs/ui/utils/avatarUtils.js +2 -36
  72. package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -1
  73. package/lib/module/index.js +16 -8
  74. package/lib/module/index.js.map +1 -1
  75. package/lib/module/ui/boot/runProviderColdBoot.js +7 -0
  76. package/lib/module/ui/boot/runProviderColdBoot.js.map +1 -1
  77. package/lib/module/ui/client.js +1 -2
  78. package/lib/module/ui/client.js.map +1 -1
  79. package/lib/module/ui/components/OxyAccountDialogScreen.js +10 -27
  80. package/lib/module/ui/components/OxyAccountDialogScreen.js.map +1 -1
  81. package/lib/module/ui/components/OxyAuthChooser.js +134 -44
  82. package/lib/module/ui/components/OxyAuthChooser.js.map +1 -1
  83. package/lib/module/ui/components/OxyProvider.js +5 -3
  84. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  85. package/lib/module/ui/components/SurfaceScreen.js +33 -5
  86. package/lib/module/ui/components/SurfaceScreen.js.map +1 -1
  87. package/lib/module/ui/components/authChooser/AccountsMenuView.js +210 -85
  88. package/lib/module/ui/components/authChooser/AccountsMenuView.js.map +1 -1
  89. package/lib/module/ui/components/authChooser/SignInEntryView.js +25 -7
  90. package/lib/module/ui/components/authChooser/SignInEntryView.js.map +1 -1
  91. package/lib/module/ui/components/authChooser/primitives.js +35 -22
  92. package/lib/module/ui/components/authChooser/primitives.js.map +1 -1
  93. package/lib/module/ui/components/authChooser/types.js +11 -0
  94. package/lib/module/ui/components/authChooser/types.js.map +1 -1
  95. package/lib/module/ui/context/OxyContext.js +251 -303
  96. package/lib/module/ui/context/OxyContext.js.map +1 -1
  97. package/lib/module/ui/context/hooks/useAuthOperations.js +27 -37
  98. package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
  99. package/lib/module/ui/context/oxyContextHelpers.js +0 -28
  100. package/lib/module/ui/context/oxyContextHelpers.js.map +1 -1
  101. package/lib/module/ui/context/useOxyAccountGraph.js +6 -17
  102. package/lib/module/ui/context/useOxyAccountGraph.js.map +1 -1
  103. package/lib/module/ui/hooks/accountDialogSnapshot.js +38 -0
  104. package/lib/module/ui/hooks/accountDialogSnapshot.js.map +1 -0
  105. package/lib/module/ui/hooks/mutations/useAccountMutations.js +0 -19
  106. package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  107. package/lib/module/ui/hooks/useDeviceSwitcher.js +53 -0
  108. package/lib/module/ui/hooks/useDeviceSwitcher.js.map +1 -0
  109. package/lib/module/ui/hooks/useI18n.js +24 -4
  110. package/lib/module/ui/hooks/useI18n.js.map +1 -1
  111. package/lib/module/ui/hooks/useSessionManagement.js +47 -155
  112. package/lib/module/ui/hooks/useSessionManagement.js.map +1 -1
  113. package/lib/module/ui/index.js +1 -2
  114. package/lib/module/ui/index.js.map +1 -1
  115. package/lib/module/ui/navigation/routes.js +84 -72
  116. package/lib/module/ui/navigation/routes.js.map +1 -1
  117. package/lib/module/ui/navigation/surfaces.js +6 -6
  118. package/lib/module/ui/navigation/surfaces.js.map +1 -1
  119. package/lib/module/ui/runtime/createOxyRuntime.js +430 -0
  120. package/lib/module/ui/runtime/createOxyRuntime.js.map +1 -0
  121. package/lib/module/ui/runtime/index.js +15 -0
  122. package/lib/module/ui/runtime/index.js.map +1 -0
  123. package/lib/module/ui/runtime/runtimeContext.js +75 -0
  124. package/lib/module/ui/runtime/runtimeContext.js.map +1 -0
  125. package/lib/module/ui/runtime/types.js +4 -0
  126. package/lib/module/ui/runtime/types.js.map +1 -0
  127. package/lib/module/ui/runtime/useRuntimeSnapshot.js +52 -0
  128. package/lib/module/ui/runtime/useRuntimeSnapshot.js.map +1 -0
  129. package/lib/module/ui/server.js +0 -1
  130. package/lib/module/ui/server.js.map +1 -1
  131. package/lib/module/ui/session/authStore.js +46 -11
  132. package/lib/module/ui/session/authStore.js.map +1 -1
  133. package/lib/module/ui/session/sharedDeviceCredentialStore.js +302 -0
  134. package/lib/module/ui/session/sharedDeviceCredentialStore.js.map +1 -0
  135. package/lib/module/ui/stores/authStore.js +154 -55
  136. package/lib/module/ui/stores/authStore.js.map +1 -1
  137. package/lib/module/ui/utils/avatarUtils.js +2 -35
  138. package/lib/module/ui/utils/avatarUtils.js.map +1 -1
  139. package/lib/typescript/commonjs/index.d.ts +5 -3
  140. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  141. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  142. package/lib/typescript/commonjs/ui/client.d.ts +1 -2
  143. package/lib/typescript/commonjs/ui/client.d.ts.map +1 -1
  144. package/lib/typescript/commonjs/ui/components/OxyAccountDialogScreen.d.ts.map +1 -1
  145. package/lib/typescript/commonjs/ui/components/OxyAuthChooser.d.ts.map +1 -1
  146. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  147. package/lib/typescript/commonjs/ui/components/SurfaceScreen.d.ts.map +1 -1
  148. package/lib/typescript/commonjs/ui/components/authChooser/AccountsMenuView.d.ts +11 -4
  149. package/lib/typescript/commonjs/ui/components/authChooser/AccountsMenuView.d.ts.map +1 -1
  150. package/lib/typescript/commonjs/ui/components/authChooser/SignInEntryView.d.ts +3 -1
  151. package/lib/typescript/commonjs/ui/components/authChooser/SignInEntryView.d.ts.map +1 -1
  152. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts +18 -6
  153. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts.map +1 -1
  154. package/lib/typescript/commonjs/ui/components/authChooser/types.d.ts +33 -1
  155. package/lib/typescript/commonjs/ui/components/authChooser/types.d.ts.map +1 -1
  156. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts +35 -4
  157. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  158. package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts +8 -12
  159. package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  160. package/lib/typescript/commonjs/ui/context/oxyContextHelpers.d.ts +0 -2
  161. package/lib/typescript/commonjs/ui/context/oxyContextHelpers.d.ts.map +1 -1
  162. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +9 -1
  163. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  164. package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts +1 -3
  165. package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts.map +1 -1
  166. package/lib/typescript/commonjs/ui/hooks/accountDialogSnapshot.d.ts +15 -0
  167. package/lib/typescript/commonjs/ui/hooks/accountDialogSnapshot.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
  169. package/lib/typescript/commonjs/ui/hooks/useDeviceSwitcher.d.ts +49 -0
  170. package/lib/typescript/commonjs/ui/hooks/useDeviceSwitcher.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/ui/hooks/useI18n.d.ts +13 -0
  172. package/lib/typescript/commonjs/ui/hooks/useI18n.d.ts.map +1 -1
  173. package/lib/typescript/commonjs/ui/hooks/useSessionManagement.d.ts +23 -18
  174. package/lib/typescript/commonjs/ui/hooks/useSessionManagement.d.ts.map +1 -1
  175. package/lib/typescript/commonjs/ui/index.d.ts +1 -2
  176. package/lib/typescript/commonjs/ui/index.d.ts.map +1 -1
  177. package/lib/typescript/commonjs/ui/navigation/routes.d.ts +15 -1
  178. package/lib/typescript/commonjs/ui/navigation/routes.d.ts.map +1 -1
  179. package/lib/typescript/commonjs/ui/navigation/surfaces.d.ts.map +1 -1
  180. package/lib/typescript/commonjs/ui/runtime/createOxyRuntime.d.ts +144 -0
  181. package/lib/typescript/commonjs/ui/runtime/createOxyRuntime.d.ts.map +1 -0
  182. package/lib/typescript/commonjs/ui/runtime/index.d.ts +16 -0
  183. package/lib/typescript/commonjs/ui/runtime/index.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/ui/runtime/runtimeContext.d.ts +43 -0
  185. package/lib/typescript/commonjs/ui/runtime/runtimeContext.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/ui/runtime/types.d.ts +89 -0
  187. package/lib/typescript/commonjs/ui/runtime/types.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/ui/runtime/useRuntimeSnapshot.d.ts +23 -0
  189. package/lib/typescript/commonjs/ui/runtime/useRuntimeSnapshot.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/ui/server.d.ts +0 -1
  191. package/lib/typescript/commonjs/ui/server.d.ts.map +1 -1
  192. package/lib/typescript/commonjs/ui/session/authStore.d.ts +60 -9
  193. package/lib/typescript/commonjs/ui/session/authStore.d.ts.map +1 -1
  194. package/lib/typescript/commonjs/ui/session/sharedDeviceCredentialStore.d.ts +32 -0
  195. package/lib/typescript/commonjs/ui/session/sharedDeviceCredentialStore.d.ts.map +1 -0
  196. package/lib/typescript/commonjs/ui/stores/authStore.d.ts +49 -5
  197. package/lib/typescript/commonjs/ui/stores/authStore.d.ts.map +1 -1
  198. package/lib/typescript/commonjs/ui/types/navigation.d.ts +26 -0
  199. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  200. package/lib/typescript/commonjs/ui/utils/avatarUtils.d.ts +2 -10
  201. package/lib/typescript/commonjs/ui/utils/avatarUtils.d.ts.map +1 -1
  202. package/lib/typescript/module/index.d.ts +5 -3
  203. package/lib/typescript/module/index.d.ts.map +1 -1
  204. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  205. package/lib/typescript/module/ui/client.d.ts +1 -2
  206. package/lib/typescript/module/ui/client.d.ts.map +1 -1
  207. package/lib/typescript/module/ui/components/OxyAccountDialogScreen.d.ts.map +1 -1
  208. package/lib/typescript/module/ui/components/OxyAuthChooser.d.ts.map +1 -1
  209. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  210. package/lib/typescript/module/ui/components/SurfaceScreen.d.ts.map +1 -1
  211. package/lib/typescript/module/ui/components/authChooser/AccountsMenuView.d.ts +11 -4
  212. package/lib/typescript/module/ui/components/authChooser/AccountsMenuView.d.ts.map +1 -1
  213. package/lib/typescript/module/ui/components/authChooser/SignInEntryView.d.ts +3 -1
  214. package/lib/typescript/module/ui/components/authChooser/SignInEntryView.d.ts.map +1 -1
  215. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts +18 -6
  216. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts.map +1 -1
  217. package/lib/typescript/module/ui/components/authChooser/types.d.ts +33 -1
  218. package/lib/typescript/module/ui/components/authChooser/types.d.ts.map +1 -1
  219. package/lib/typescript/module/ui/context/OxyContext.d.ts +35 -4
  220. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  221. package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts +8 -12
  222. package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  223. package/lib/typescript/module/ui/context/oxyContextHelpers.d.ts +0 -2
  224. package/lib/typescript/module/ui/context/oxyContextHelpers.d.ts.map +1 -1
  225. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +9 -1
  226. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  227. package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts +1 -3
  228. package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts.map +1 -1
  229. package/lib/typescript/module/ui/hooks/accountDialogSnapshot.d.ts +15 -0
  230. package/lib/typescript/module/ui/hooks/accountDialogSnapshot.d.ts.map +1 -0
  231. package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
  232. package/lib/typescript/module/ui/hooks/useDeviceSwitcher.d.ts +49 -0
  233. package/lib/typescript/module/ui/hooks/useDeviceSwitcher.d.ts.map +1 -0
  234. package/lib/typescript/module/ui/hooks/useI18n.d.ts +13 -0
  235. package/lib/typescript/module/ui/hooks/useI18n.d.ts.map +1 -1
  236. package/lib/typescript/module/ui/hooks/useSessionManagement.d.ts +23 -18
  237. package/lib/typescript/module/ui/hooks/useSessionManagement.d.ts.map +1 -1
  238. package/lib/typescript/module/ui/index.d.ts +1 -2
  239. package/lib/typescript/module/ui/index.d.ts.map +1 -1
  240. package/lib/typescript/module/ui/navigation/routes.d.ts +15 -1
  241. package/lib/typescript/module/ui/navigation/routes.d.ts.map +1 -1
  242. package/lib/typescript/module/ui/navigation/surfaces.d.ts.map +1 -1
  243. package/lib/typescript/module/ui/runtime/createOxyRuntime.d.ts +144 -0
  244. package/lib/typescript/module/ui/runtime/createOxyRuntime.d.ts.map +1 -0
  245. package/lib/typescript/module/ui/runtime/index.d.ts +16 -0
  246. package/lib/typescript/module/ui/runtime/index.d.ts.map +1 -0
  247. package/lib/typescript/module/ui/runtime/runtimeContext.d.ts +43 -0
  248. package/lib/typescript/module/ui/runtime/runtimeContext.d.ts.map +1 -0
  249. package/lib/typescript/module/ui/runtime/types.d.ts +89 -0
  250. package/lib/typescript/module/ui/runtime/types.d.ts.map +1 -0
  251. package/lib/typescript/module/ui/runtime/useRuntimeSnapshot.d.ts +23 -0
  252. package/lib/typescript/module/ui/runtime/useRuntimeSnapshot.d.ts.map +1 -0
  253. package/lib/typescript/module/ui/server.d.ts +0 -1
  254. package/lib/typescript/module/ui/server.d.ts.map +1 -1
  255. package/lib/typescript/module/ui/session/authStore.d.ts +60 -9
  256. package/lib/typescript/module/ui/session/authStore.d.ts.map +1 -1
  257. package/lib/typescript/module/ui/session/sharedDeviceCredentialStore.d.ts +32 -0
  258. package/lib/typescript/module/ui/session/sharedDeviceCredentialStore.d.ts.map +1 -0
  259. package/lib/typescript/module/ui/stores/authStore.d.ts +49 -5
  260. package/lib/typescript/module/ui/stores/authStore.d.ts.map +1 -1
  261. package/lib/typescript/module/ui/types/navigation.d.ts +26 -0
  262. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  263. package/lib/typescript/module/ui/utils/avatarUtils.d.ts +2 -10
  264. package/lib/typescript/module/ui/utils/avatarUtils.d.ts.map +1 -1
  265. package/package.json +6 -7
  266. package/plugins/withSharedDeviceSessionProvider.js +102 -0
  267. package/plugins/withSharedDeviceSessionReader.js +57 -0
  268. package/src/__tests__/esmSourcePurity.test.ts +61 -0
  269. package/src/index.ts +31 -9
  270. package/src/ui/boot/runProviderColdBoot.ts +7 -0
  271. package/src/ui/client.ts +1 -2
  272. package/src/ui/components/OxyAccountDialogScreen.tsx +10 -29
  273. package/src/ui/components/OxyAuthChooser.tsx +149 -50
  274. package/src/ui/components/OxyProvider.tsx +7 -5
  275. package/src/ui/components/SurfaceScreen.tsx +28 -4
  276. package/src/ui/components/authChooser/AccountsMenuView.tsx +246 -96
  277. package/src/ui/components/authChooser/SignInEntryView.tsx +31 -8
  278. package/src/ui/components/authChooser/primitives.tsx +37 -23
  279. package/src/ui/components/authChooser/types.ts +34 -1
  280. package/src/ui/context/OxyContext.tsx +269 -324
  281. package/src/ui/context/hooks/useAuthOperations.ts +32 -35
  282. package/src/ui/context/oxyContextHelpers.ts +0 -30
  283. package/src/ui/context/oxyContextTypes.ts +9 -1
  284. package/src/ui/context/useOxyAccountGraph.ts +5 -19
  285. package/src/ui/hooks/accountDialogSnapshot.ts +37 -0
  286. package/src/ui/hooks/mutations/useAccountMutations.ts +0 -19
  287. package/src/ui/hooks/queries/__tests__/userCache.test.ts +12 -1
  288. package/src/ui/hooks/useDeviceSwitcher.ts +110 -0
  289. package/src/ui/hooks/useI18n.ts +23 -3
  290. package/src/ui/hooks/useSessionManagement.ts +62 -211
  291. package/src/ui/index.ts +1 -2
  292. package/src/ui/navigation/routes.ts +85 -75
  293. package/src/ui/navigation/surfaces.ts +6 -9
  294. package/src/ui/runtime/createOxyRuntime.ts +623 -0
  295. package/src/ui/runtime/index.ts +34 -0
  296. package/src/ui/runtime/runtimeContext.tsx +111 -0
  297. package/src/ui/runtime/types.ts +110 -0
  298. package/src/ui/runtime/useRuntimeSnapshot.ts +52 -0
  299. package/src/ui/server.ts +0 -1
  300. package/src/ui/session/__tests__/authStore.test.ts +90 -0
  301. package/src/ui/session/__tests__/sharedDeviceCredentialStore.test.ts +289 -0
  302. package/src/ui/session/authStore.ts +78 -9
  303. package/src/ui/session/sharedDeviceCredentialStore.ts +318 -0
  304. package/src/ui/stores/authStore.ts +171 -43
  305. package/src/ui/types/navigation.ts +26 -0
  306. package/src/ui/utils/avatarUtils.ts +2 -37
  307. package/lib/commonjs/ui/hooks/useSwitchableAccounts.js +0 -64
  308. package/lib/commonjs/ui/hooks/useSwitchableAccounts.js.map +0 -1
  309. package/lib/commonjs/ui/stores/accountStore.js +0 -221
  310. package/lib/commonjs/ui/stores/accountStore.js.map +0 -1
  311. package/lib/module/ui/hooks/useSwitchableAccounts.js +0 -60
  312. package/lib/module/ui/hooks/useSwitchableAccounts.js.map +0 -1
  313. package/lib/module/ui/stores/accountStore.js +0 -213
  314. package/lib/module/ui/stores/accountStore.js.map +0 -1
  315. package/lib/typescript/commonjs/ui/hooks/useSwitchableAccounts.d.ts +0 -23
  316. package/lib/typescript/commonjs/ui/hooks/useSwitchableAccounts.d.ts.map +0 -1
  317. package/lib/typescript/commonjs/ui/stores/accountStore.d.ts +0 -27
  318. package/lib/typescript/commonjs/ui/stores/accountStore.d.ts.map +0 -1
  319. package/lib/typescript/module/ui/hooks/useSwitchableAccounts.d.ts +0 -23
  320. package/lib/typescript/module/ui/hooks/useSwitchableAccounts.d.ts.map +0 -1
  321. package/lib/typescript/module/ui/stores/accountStore.d.ts +0 -27
  322. package/lib/typescript/module/ui/stores/accountStore.d.ts.map +0 -1
  323. package/src/ui/hooks/useSwitchableAccounts.ts +0 -75
  324. package/src/ui/stores/accountStore.ts +0 -264
@@ -0,0 +1,433 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createOxyRuntime = createOxyRuntime;
7
+ var _core = require("@oxyhq/core");
8
+ /**
9
+ * A change of SUBJECT — the account the session acts as.
10
+ *
11
+ * `previous === null` is an initial sign-in (nothing account-scoped is cached
12
+ * yet); `next === null` is a sign-out; both non-null and different is a switch,
13
+ * the only case that must invalidate a warm cache.
14
+ */
15
+
16
+ /**
17
+ * The three seams the runtime reads, declared STRUCTURALLY rather than as the
18
+ * concrete `OxyServices` / `SessionClient` / `SessionClientHost` types.
19
+ *
20
+ * The real classes satisfy them, so nothing changes at the call site — but a
21
+ * test can hand the runtime three plain objects instead of casting a stub
22
+ * through `unknown`, which is how a stub silently drifts from the interface it
23
+ * pretends to implement.
24
+ */
25
+
26
+ /**
27
+ * The headless session runtime (ADR 0004).
28
+ *
29
+ * It owns the session facts and the ORDER in which they become visible. React
30
+ * is an adapter: the provider hands components this object and they subscribe
31
+ * with selectors, so an unrelated change (a locale, a dialog opening) cannot
32
+ * rebuild an auth consumer's view.
33
+ */
34
+
35
+ const EMPTY_SESSIONS = [];
36
+ function deriveStatus(facts) {
37
+ if (!facts.authResolved) {
38
+ return 'booting';
39
+ }
40
+ if (facts.account !== null) {
41
+ return 'authenticated';
42
+ }
43
+ return facts.error !== null ? 'error' : 'signed_out';
44
+ }
45
+ function deriveTokenStatus(facts) {
46
+ if (facts.hasAccessToken && facts.tokenReady) {
47
+ return 'ready';
48
+ }
49
+ if (facts.account !== null || facts.hasAccessToken) {
50
+ return 'refreshing';
51
+ }
52
+ return 'missing';
53
+ }
54
+
55
+ /**
56
+ * The actor behind the active context, resolved to a full `User`.
57
+ *
58
+ * Falls back to the subject: on a device with no directory, and on any
59
+ * non-delegated context, the two ARE the same person, and saying so is more
60
+ * useful than a `null` every caller would have to special-case.
61
+ */
62
+ function derivePrincipal(activeContext, profiles, account) {
63
+ if (activeContext === null) {
64
+ return account;
65
+ }
66
+ return profiles.get(activeContext.actor.userId) ?? account;
67
+ }
68
+ function createOxyRuntime(config) {
69
+ const {
70
+ oxyServices,
71
+ sessionClient,
72
+ sessionClientHost,
73
+ identity,
74
+ onSubjectChange,
75
+ onDeviceEmpty,
76
+ onSessionsProjected,
77
+ onIdentityUnbound,
78
+ logger
79
+ } = config;
80
+ const facts = {
81
+ deviceState: null,
82
+ directory: null,
83
+ profiles: new Map(),
84
+ sessions: EMPTY_SESSIONS,
85
+ activeSessionId: null,
86
+ account: null,
87
+ pinnedAccountId: null,
88
+ isLoading: false,
89
+ error: null,
90
+ storageReady: false,
91
+ tokenReady: true,
92
+ hasAccessToken: Boolean(oxyServices.getAccessToken()),
93
+ authResolved: false,
94
+ switching: false
95
+ };
96
+ const listeners = new Set();
97
+ let snapshot = buildSnapshot();
98
+ /**
99
+ * Depth of the current transition. Nested mutations publish ONCE, at the
100
+ * outermost boundary — a projection that sets sessions, the active id and the
101
+ * account must not wake React three times with two of them half-applied.
102
+ */
103
+ let depth = 0;
104
+ let dirty = false;
105
+ /** The subject as it stood when the OUTERMOST transition opened. */
106
+ let subjectAtEntry = null;
107
+ function buildSnapshot() {
108
+ const activeContext = (0, _core.resolveActiveContext)(facts.directory);
109
+ return Object.freeze({
110
+ status: deriveStatus(facts),
111
+ device: facts.directory,
112
+ deviceState: facts.deviceState,
113
+ activeContext,
114
+ principal: derivePrincipal(activeContext, facts.profiles, facts.account),
115
+ account: facts.account,
116
+ tokenStatus: deriveTokenStatus(facts),
117
+ authResolved: facts.authResolved,
118
+ switching: facts.switching,
119
+ error: facts.error === null ? null : {
120
+ message: facts.error,
121
+ code: 'oxy_runtime_error'
122
+ },
123
+ sessions: facts.sessions,
124
+ activeSessionId: facts.activeSessionId,
125
+ isLoading: facts.isLoading,
126
+ storageReady: facts.storageReady,
127
+ hasAccessToken: facts.hasAccessToken,
128
+ tokenReady: facts.tokenReady
129
+ });
130
+ }
131
+ function notify() {
132
+ for (const listener of [...listeners]) {
133
+ try {
134
+ listener();
135
+ } catch (error) {
136
+ logger('An OxyRuntime subscriber threw', error);
137
+ }
138
+ }
139
+ }
140
+
141
+ /**
142
+ * The ONE ordered transition. Every fact change goes through here, so the
143
+ * sequence ADR 0002 mandates holds for a local switch, a socket push, a cold
144
+ * boot and a cross-tab wake alike:
145
+ *
146
+ * the bearer is already committed (SessionClient awaits its mint before it
147
+ * calls us) → reset account-scoped caches → publish the snapshot → notify.
148
+ *
149
+ * Publishing before the reset would let a woken component read a cache entry
150
+ * belonging to the previous subject while holding the new subject's bearer,
151
+ * which is the account-switch race in its quietest form: no error, just the
152
+ * wrong person's data.
153
+ */
154
+ function transition(mutate) {
155
+ if (depth === 0) {
156
+ subjectAtEntry = facts.account?.id ?? null;
157
+ }
158
+ depth += 1;
159
+ try {
160
+ mutate();
161
+ } finally {
162
+ depth -= 1;
163
+ }
164
+ if (depth > 0) {
165
+ // A nested transition publishes nothing and fires no reset: the subject
166
+ // is compared once, at the outermost boundary, so a projection that
167
+ // touches the account twice cannot reset the caches twice.
168
+ return;
169
+ }
170
+ const nextSubject = facts.account?.id ?? null;
171
+ if (nextSubject !== subjectAtEntry) {
172
+ dirty = true;
173
+ onSubjectChange?.({
174
+ previous: subjectAtEntry,
175
+ next: nextSubject
176
+ });
177
+ }
178
+ if (!dirty) {
179
+ return;
180
+ }
181
+ dirty = false;
182
+ snapshot = buildSnapshot();
183
+ notify();
184
+ }
185
+
186
+ /** Mark the snapshot stale from inside a transition. */
187
+ function touch() {
188
+ dirty = true;
189
+ }
190
+ function setSessions(next) {
191
+ if ((0, _core.sessionsArraysEqual)(facts.sessions, next)) {
192
+ return;
193
+ }
194
+ facts.sessions = next;
195
+ touch();
196
+ }
197
+ function setActiveSessionIdFact(sessionId) {
198
+ if (facts.activeSessionId === sessionId) {
199
+ return;
200
+ }
201
+ facts.activeSessionId = sessionId;
202
+ touch();
203
+ }
204
+
205
+ /**
206
+ * The one place a `User` becomes THE subject — and the one place identity is
207
+ * normalised, so a profile arriving as `_id` from one lane and `id` from
208
+ * another can never produce two accounts that are the same person.
209
+ */
210
+ function setAccountFact(user) {
211
+ if (user === null) {
212
+ if (facts.account === null) {
213
+ return;
214
+ }
215
+ facts.account = null;
216
+ touch();
217
+ return;
218
+ }
219
+ if (facts.account === user) {
220
+ return;
221
+ }
222
+ facts.account = (0, _core.normalizeUserIdentity)(user);
223
+ touch();
224
+ }
225
+
226
+ // ── Projection ───────────────────────────────────────────────────────────
227
+
228
+ async function reconcileFromClient() {
229
+ const state = sessionClient.getState();
230
+ if (state === null) {
231
+ return;
232
+ }
233
+ if (state.accounts.length === 0) {
234
+ sessionClientHost.setCurrentAccountId(null);
235
+ await onDeviceEmpty();
236
+ return;
237
+ }
238
+ // Capture the revision this projection is for, then bail after the async
239
+ // profile fetch if a fresher state has landed — last-writer-wins, so two
240
+ // overlapping projections can never publish in the wrong order.
241
+ const capturedRevision = state.revision;
242
+ // Resolve the pin BEFORE the fetch (memoised: one storage + keychain read
243
+ // per boot) so the first pass over a freshly applied state is already bound.
244
+ // Deferring it would let a sibling app's switch render once as this
245
+ // client's user before the pin corrected it.
246
+ const pinnedAccountId = identity ? await identity.ensurePinnedAccountId() : null;
247
+ const ids = (0, _core.accountIdsOf)(state);
248
+ let users = [];
249
+ try {
250
+ users = ids.length > 0 ? await oxyServices.getUsersByIds(ids) : [];
251
+ } catch (fetchError) {
252
+ logger('Failed to resolve account profiles during the device projection', fetchError);
253
+ return;
254
+ }
255
+ const latest = sessionClient.getState();
256
+ if (!latest || latest.revision !== capturedRevision) {
257
+ return;
258
+ }
259
+ if (identity && (pinnedAccountId === null || (0, _core.activeSessionIdOf)(latest, pinnedAccountId) === null)) {
260
+ // Either no verified pin, or the pinned account left this device's session
261
+ // set. Leave the current projection untouched and re-derive from the key.
262
+ onIdentityUnbound?.(identity, latest.revision);
263
+ return;
264
+ }
265
+ const directory = sessionClient.getDirectory();
266
+ transition(() => {
267
+ facts.pinnedAccountId = pinnedAccountId;
268
+ if (facts.deviceState !== latest) {
269
+ facts.deviceState = latest;
270
+ touch();
271
+ }
272
+ if (facts.directory !== directory) {
273
+ facts.directory = directory;
274
+ touch();
275
+ }
276
+ for (const resolved of users) {
277
+ facts.profiles.set(resolved.id, resolved);
278
+ }
279
+ const projected = (0, _core.normalizeAndSortSessions)((0, _core.deviceStateToClientSessions)(latest, facts.profiles, pinnedAccountId), facts.activeSessionId, false);
280
+ setSessions(projected);
281
+ onSessionsProjected?.(projected.map(session => session.sessionId));
282
+ setActiveSessionIdFact((0, _core.activeSessionIdOf)(latest, pinnedAccountId));
283
+ const activeUser = (0, _core.activeUserOf)(latest, facts.profiles, pinnedAccountId);
284
+ if (activeUser) {
285
+ setAccountFact(activeUser);
286
+ }
287
+ });
288
+ // The host's current account feeds the socket handshake and the bearer's
289
+ // token-account comparisons, so it tracks the PIN — never the account
290
+ // another app switched the device to.
291
+ sessionClientHost.setCurrentAccountId(pinnedAccountId ?? latest.activeAccountId);
292
+ }
293
+ return {
294
+ getSnapshot: () => snapshot,
295
+ subscribe(listener) {
296
+ listeners.add(listener);
297
+ return () => {
298
+ listeners.delete(listener);
299
+ };
300
+ },
301
+ start() {
302
+ return sessionClient.subscribe(() => {
303
+ void reconcileFromClient().catch(error => {
304
+ logger('Failed to project a device-state transition', error);
305
+ });
306
+ });
307
+ },
308
+ reconcileFromClient,
309
+ batch(mutate) {
310
+ transition(mutate);
311
+ },
312
+ async activateContext(contextId) {
313
+ // `switching` is published BEFORE the request so a switcher can disable
314
+ // its rows for the whole round trip, and cleared in `finally` so a
315
+ // refused activation does not strand it on.
316
+ this.setSwitching(true);
317
+ try {
318
+ await sessionClient.activateContext(contextId);
319
+ await reconcileFromClient();
320
+ } finally {
321
+ this.setSwitching(false);
322
+ }
323
+ },
324
+ async signOutContext(contextId) {
325
+ await sessionClient.signOutContext(contextId);
326
+ await reconcileFromClient();
327
+ },
328
+ async signOutPrincipal(principalId) {
329
+ await sessionClient.signOutPrincipal(principalId);
330
+ await reconcileFromClient();
331
+ },
332
+ async refreshDirectory() {
333
+ await sessionClient.refreshDirectory();
334
+ const directory = sessionClient.getDirectory();
335
+ transition(() => {
336
+ if (facts.directory === directory) {
337
+ return;
338
+ }
339
+ facts.directory = directory;
340
+ touch();
341
+ });
342
+ },
343
+ setAccount(user) {
344
+ transition(() => {
345
+ setAccountFact(user);
346
+ if (facts.isLoading) {
347
+ facts.isLoading = false;
348
+ touch();
349
+ }
350
+ if (facts.error !== null) {
351
+ facts.error = null;
352
+ touch();
353
+ }
354
+ facts.profiles.set(user.id, user);
355
+ });
356
+ },
357
+ setLoading(loading) {
358
+ transition(() => {
359
+ if (facts.isLoading === loading) return;
360
+ facts.isLoading = loading;
361
+ touch();
362
+ });
363
+ },
364
+ setError(error) {
365
+ transition(() => {
366
+ if (facts.error === error) return;
367
+ facts.error = error;
368
+ touch();
369
+ });
370
+ },
371
+ setStorageReady(ready) {
372
+ transition(() => {
373
+ if (facts.storageReady === ready) return;
374
+ facts.storageReady = ready;
375
+ touch();
376
+ });
377
+ },
378
+ setTokenReady(ready) {
379
+ transition(() => {
380
+ if (facts.tokenReady === ready) return;
381
+ facts.tokenReady = ready;
382
+ touch();
383
+ });
384
+ },
385
+ setHasAccessToken(has) {
386
+ transition(() => {
387
+ if (facts.hasAccessToken === has) return;
388
+ facts.hasAccessToken = has;
389
+ touch();
390
+ });
391
+ },
392
+ setSwitching(switching) {
393
+ transition(() => {
394
+ if (facts.switching === switching) return;
395
+ facts.switching = switching;
396
+ touch();
397
+ });
398
+ },
399
+ markAuthResolved() {
400
+ transition(() => {
401
+ if (facts.authResolved) return;
402
+ facts.authResolved = true;
403
+ facts.tokenReady = true;
404
+ touch();
405
+ });
406
+ },
407
+ mergeSessions(incoming, options = {}) {
408
+ transition(() => {
409
+ const processed = options.merge ? (0, _core.mergeSessions)(facts.sessions, incoming, facts.activeSessionId, false) : (0, _core.normalizeAndSortSessions)(incoming, facts.activeSessionId, false);
410
+ onSessionsProjected?.([...processed.map(session => session.sessionId), ...(options.preserveSessionIds ?? [])]);
411
+ setSessions(processed);
412
+ });
413
+ },
414
+ setActiveSessionId(sessionId) {
415
+ transition(() => {
416
+ setActiveSessionIdFact(sessionId);
417
+ });
418
+ },
419
+ clearSession() {
420
+ transition(() => {
421
+ setSessions(EMPTY_SESSIONS);
422
+ setActiveSessionIdFact(null);
423
+ setAccountFact(null);
424
+ facts.deviceState = null;
425
+ facts.directory = null;
426
+ facts.profiles = new Map();
427
+ facts.pinnedAccountId = null;
428
+ touch();
429
+ });
430
+ }
431
+ };
432
+ }
433
+ //# sourceMappingURL=createOxyRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_core","require","EMPTY_SESSIONS","deriveStatus","facts","authResolved","account","error","deriveTokenStatus","hasAccessToken","tokenReady","derivePrincipal","activeContext","profiles","get","actor","userId","createOxyRuntime","config","oxyServices","sessionClient","sessionClientHost","identity","onSubjectChange","onDeviceEmpty","onSessionsProjected","onIdentityUnbound","logger","deviceState","directory","Map","sessions","activeSessionId","pinnedAccountId","isLoading","storageReady","Boolean","getAccessToken","switching","listeners","Set","snapshot","buildSnapshot","depth","dirty","subjectAtEntry","resolveActiveContext","Object","freeze","status","device","principal","tokenStatus","message","code","notify","listener","transition","mutate","id","nextSubject","previous","next","touch","setSessions","sessionsArraysEqual","setActiveSessionIdFact","sessionId","setAccountFact","user","normalizeUserIdentity","reconcileFromClient","state","getState","accounts","length","setCurrentAccountId","capturedRevision","revision","ensurePinnedAccountId","ids","accountIdsOf","users","getUsersByIds","fetchError","latest","activeSessionIdOf","getDirectory","resolved","set","projected","normalizeAndSortSessions","deviceStateToClientSessions","map","session","activeUser","activeUserOf","activeAccountId","getSnapshot","subscribe","add","delete","start","catch","batch","activateContext","contextId","setSwitching","signOutContext","signOutPrincipal","principalId","refreshDirectory","setAccount","setLoading","loading","setError","setStorageReady","ready","setTokenReady","setHasAccessToken","has","markAuthResolved","mergeSessions","incoming","options","processed","merge","mergeSessionLists","preserveSessionIds","setActiveSessionId","clearSession"],"sourceRoot":"../../../../src","sources":["ui/runtime/createOxyRuntime.ts"],"mappings":";;;;;;AAEA,IAAAA,KAAA,GAAAC,OAAA;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA2FA,MAAMC,cAA+B,GAAG,EAAE;AAE1C,SAASC,YAAYA,CAACC,KAAmB,EAAoB;EAC3D,IAAI,CAACA,KAAK,CAACC,YAAY,EAAE;IACvB,OAAO,SAAS;EAClB;EACA,IAAID,KAAK,CAACE,OAAO,KAAK,IAAI,EAAE;IAC1B,OAAO,eAAe;EACxB;EACA,OAAOF,KAAK,CAACG,KAAK,KAAK,IAAI,GAAG,OAAO,GAAG,YAAY;AACtD;AAEA,SAASC,iBAAiBA,CAACJ,KAAmB,EAAkB;EAC9D,IAAIA,KAAK,CAACK,cAAc,IAAIL,KAAK,CAACM,UAAU,EAAE;IAC5C,OAAO,OAAO;EAChB;EACA,IAAIN,KAAK,CAACE,OAAO,KAAK,IAAI,IAAIF,KAAK,CAACK,cAAc,EAAE;IAClD,OAAO,YAAY;EACrB;EACA,OAAO,SAAS;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAeA,CACtBC,aAAmC,EACnCC,QAA2B,EAC3BP,OAAoB,EACP;EACb,IAAIM,aAAa,KAAK,IAAI,EAAE;IAC1B,OAAON,OAAO;EAChB;EACA,OAAOO,QAAQ,CAACC,GAAG,CAACF,aAAa,CAACG,KAAK,CAACC,MAAM,CAAC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B,SAAS,CAAC,EAChD,IAAIyD,OAAO,CAACI,kBAAkB,IAAI,EAAE,CAAC,CACtC,CAAC;QACFhE,WAAW,CAAC6D,SAAS,CAAC;MACxB,CAAC,CAAC;IACJ,CAAC;IAEDI,kBAAkBA,CAAC9D,SAAS,EAAE;MAC5BV,UAAU,CAAC,MAAM;QACfS,sBAAsB,CAACC,SAAS,CAAC;MACnC,CAAC,CAAC;IACJ,CAAC;IAED+D,YAAYA,CAAA,EAAG;MACbzE,UAAU,CAAC,MAAM;QACfO,WAAW,CAAC9D,cAAc,CAAC;QAC3BgE,sBAAsB,CAAC,IAAI,CAAC;QAC5BE,cAAc,CAAC,IAAI,CAAC;QACpBhE,KAAK,CAACwB,WAAW,GAAG,IAAI;QACxBxB,KAAK,CAACyB,SAAS,GAAG,IAAI;QACtBzB,KAAK,CAACS,QAAQ,GAAG,IAAIiB,GAAG,CAAC,CAAC;QAC1B1B,KAAK,CAAC6B,eAAe,GAAG,IAAI;QAC5B8B,KAAK,CAAC,CAAC;MACT,CAAC,CAAC;IACJ;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "OxyRuntimeHandleProvider", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _runtimeContext.OxyRuntimeHandleProvider;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "OxyRuntimeMissingError", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _runtimeContext.OxyRuntimeMissingError;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "createOxyRuntime", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _createOxyRuntime.createOxyRuntime;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useActiveAccount", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _runtimeContext.useActiveAccount;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "useDeviceDirectory", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _runtimeContext.useDeviceDirectory;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "useOxyRuntime", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _runtimeContext.useOxyRuntime;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "useOxySnapshot", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _runtimeContext.useOxySnapshot;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "useRuntimeSelector", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _useRuntimeSnapshot.useRuntimeSelector;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "useRuntimeSnapshot", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _useRuntimeSnapshot.useRuntimeSnapshot;
58
+ }
59
+ });
60
+ var _createOxyRuntime = require("./createOxyRuntime.js");
61
+ var _useRuntimeSnapshot = require("./useRuntimeSnapshot.js");
62
+ var _runtimeContext = require("./runtimeContext.js");
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_createOxyRuntime","require","_useRuntimeSnapshot","_runtimeContext"],"sourceRoot":"../../../../src","sources":["ui/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAAA,iBAAA,GAAAC,OAAA;AASA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA","ignoreList":[]}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OxyRuntimeMissingError = exports.OxyRuntimeHandleProvider = void 0;
7
+ exports.useActiveAccount = useActiveAccount;
8
+ exports.useDeviceDirectory = useDeviceDirectory;
9
+ exports.useOxyRuntime = useOxyRuntime;
10
+ exports.useOxySnapshot = useOxySnapshot;
11
+ var _react = require("react");
12
+ var _useRuntimeSnapshot = require("./useRuntimeSnapshot.js");
13
+ /**
14
+ * The runtime reference itself, as a context value that NEVER changes identity
15
+ * (ADR 0004).
16
+ *
17
+ * It is deliberately a second context beside the big `OxyContextState` one.
18
+ * That value is rebuilt whenever any of its fifty-odd members moves — a locale,
19
+ * a dialog opening — and every hook reading it re-renders with it. Hooks
20
+ * hanging off this one subscribe to the runtime with a selector instead, so
21
+ * only a change to what they actually selected wakes them. Retiring the wide
22
+ * context is Phase 8; this is what its replacements are built on.
23
+ */
24
+ const OxyRuntimeHandleContext = /*#__PURE__*/(0, _react.createContext)(null);
25
+ const OxyRuntimeHandleProvider = exports.OxyRuntimeHandleProvider = OxyRuntimeHandleContext.Provider;
26
+ const RUNTIME_MISSING_MESSAGE = 'useOxyRuntime() was called outside <OxyProvider>. Mount <OxyProvider clientId="…"> above this component.';
27
+ class OxyRuntimeMissingError extends Error {
28
+ code = 'oxy_runtime_missing';
29
+ constructor() {
30
+ super(RUNTIME_MISSING_MESSAGE);
31
+ this.name = 'OxyRuntimeMissingError';
32
+ }
33
+ }
34
+
35
+ /** The runtime this provider owns. THROWS when no `<OxyProvider>` is mounted. */
36
+ exports.OxyRuntimeMissingError = OxyRuntimeMissingError;
37
+ function useOxyRuntime() {
38
+ const runtime = (0, _react.useContext)(OxyRuntimeHandleContext);
39
+ if (runtime === null) {
40
+ throw new OxyRuntimeMissingError();
41
+ }
42
+ return runtime;
43
+ }
44
+ function selectActiveAccount(snapshot) {
45
+ return {
46
+ principal: snapshot.principal,
47
+ account: snapshot.account,
48
+ context: snapshot.activeContext,
49
+ isDelegated: snapshot.activeContext?.isDelegated ?? false,
50
+ status: snapshot.status
51
+ };
52
+ }
53
+ function activeAccountsEqual(a, b) {
54
+ return a.principal === b.principal && a.account === b.account && a.context === b.context && a.isDelegated === b.isDelegated && a.status === b.status;
55
+ }
56
+
57
+ /**
58
+ * Who this app is running as, with the actor and the subject kept apart.
59
+ *
60
+ * Unlike `useOxy()`, this re-renders only when one of those five facts moves —
61
+ * a locale change, a dialog opening or a session-list refresh does not reach it.
62
+ */
63
+ function useActiveAccount() {
64
+ return (0, _useRuntimeSnapshot.useRuntimeSelector)(useOxyRuntime(), selectActiveAccount, activeAccountsEqual);
65
+ }
66
+ const selectDirectory = snapshot => snapshot.device;
67
+
68
+ /**
69
+ * The device directory — every principal on this device and the contexts each
70
+ * may act as (ADR 0002).
71
+ *
72
+ * `null` until something calls `runtime.refreshDirectory()`. A client that
73
+ * never asks for one never pays for the round trip.
74
+ */
75
+ function useDeviceDirectory() {
76
+ return (0, _useRuntimeSnapshot.useRuntimeSelector)(useOxyRuntime(), selectDirectory);
77
+ }
78
+
79
+ /** The whole runtime snapshot. Prefer a narrower hook where one exists. */
80
+ function useOxySnapshot() {
81
+ return (0, _useRuntimeSnapshot.useRuntimeSnapshot)(useOxyRuntime());
82
+ }
83
+ //# sourceMappingURL=runtimeContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_useRuntimeSnapshot","OxyRuntimeHandleContext","createContext","OxyRuntimeHandleProvider","exports","Provider","RUNTIME_MISSING_MESSAGE","OxyRuntimeMissingError","Error","code","constructor","name","useOxyRuntime","runtime","useContext","selectActiveAccount","snapshot","principal","account","context","activeContext","isDelegated","status","activeAccountsEqual","a","b","useActiveAccount","useRuntimeSelector","selectDirectory","device","useDeviceDirectory","useOxySnapshot","useRuntimeSnapshot"],"sourceRoot":"../../../../src","sources":["ui/runtime/runtimeContext.tsx"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKA,IAAAC,mBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,uBAAuB,gBAAG,IAAAC,oBAAa,EAAoB,IAAI,CAAC;AAE/D,MAAMC,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GAAGF,uBAAuB,CAACI,QAAQ;AAExE,MAAMC,uBAAuB,GAC3B,0GAA0G;AAErG,MAAMC,sBAA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CAACa,MAAM;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAA,EAA2B;EAC3D,OAAO,IAAAH,sCAAkB,EAACf,aAAa,CAAC,CAAC,EAAEgB,eAAe,CAAC;AAC7D;;AAEA;AACO,SAASG,cAAcA,CAAA,EAA0C;EACtE,OAAO,IAAAC,sCAAkB,EAACpB,aAAa,CAAC,CAAC,CAAC;AAC5C","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["ui/runtime/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useRuntimeSelector = useRuntimeSelector;
7
+ exports.useRuntimeSnapshot = useRuntimeSnapshot;
8
+ var _react = require("react");
9
+ /**
10
+ * Subscribe to the whole runtime snapshot.
11
+ *
12
+ * The runtime publishes a frozen object only when a fact actually changed, so
13
+ * identity comparison is exact: a locale change, a dialog opening or an
14
+ * unrelated query settling does not wake anything subscribed here.
15
+ */
16
+ function useRuntimeSnapshot(runtime) {
17
+ return (0, _react.useSyncExternalStore)(runtime.subscribe, runtime.getSnapshot, runtime.getSnapshot);
18
+ }
19
+
20
+ /**
21
+ * Subscribe to one derived value of the runtime snapshot.
22
+ *
23
+ * The selection is cached against the snapshot it was computed from, which is
24
+ * what makes a selector returning a fresh object (`{user, isAuthenticated}`)
25
+ * safe here: `useSyncExternalStore` calls `getSnapshot` several times per
26
+ * commit and would otherwise see a new object every call and loop.
27
+ *
28
+ * `selector` must be stable — hoist it to module scope or wrap it in
29
+ * `useCallback`. An inline arrow re-subscribes on every render.
30
+ */
31
+ function useRuntimeSelector(runtime, selector, isEqual) {
32
+ const cache = (0, _react.useRef)(null);
33
+ const getSelection = (0, _react.useCallback)(() => {
34
+ const snapshot = runtime.getSnapshot();
35
+ const cached = cache.current;
36
+ if (cached !== null && cached.snapshot === snapshot) {
37
+ return cached.value;
38
+ }
39
+ const value = selector(snapshot);
40
+ if (cached !== null && isEqual?.(cached.value, value) === true) {
41
+ // Same value under the caller's equality: keep the PREVIOUS reference so a
42
+ // structurally-equal recomputation does not read as a change.
43
+ cache.current = {
44
+ snapshot,
45
+ value: cached.value
46
+ };
47
+ return cached.value;
48
+ }
49
+ cache.current = {
50
+ snapshot,
51
+ value
52
+ };
53
+ return value;
54
+ }, [runtime, selector, isEqual]);
55
+ return (0, _react.useSyncExternalStore)(runtime.subscribe, getSelection, getSelection);
56
+ }
57
+ //# sourceMappingURL=useRuntimeSnapshot.js.map