@elevasis/ui 1.3.0 → 1.3.2

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 (279) hide show
  1. package/dist/CoreAuthKitInner-3J4RVQO6.js +43 -0
  2. package/dist/api/index.d.ts +7 -31
  3. package/dist/api/index.js +3 -2
  4. package/dist/auth/context.d.ts +23 -5
  5. package/dist/auth/guards/AdminGuard.d.ts +32 -0
  6. package/dist/auth/guards/AdminGuard.d.ts.map +1 -0
  7. package/dist/auth/guards/ProtectedRoute.d.ts +60 -0
  8. package/dist/auth/guards/ProtectedRoute.d.ts.map +1 -0
  9. package/dist/auth/guards/__tests__/AdminGuard.test.d.ts +12 -0
  10. package/dist/auth/guards/__tests__/AdminGuard.test.d.ts.map +1 -0
  11. package/dist/auth/guards/__tests__/ProtectedRoute.test.d.ts +14 -0
  12. package/dist/auth/guards/__tests__/ProtectedRoute.test.d.ts.map +1 -0
  13. package/dist/auth/index.d.ts +14 -171
  14. package/dist/auth/index.d.ts.map +1 -0
  15. package/dist/auth/index.js +5 -6
  16. package/dist/{chunk-FDCVFCOQ.js → chunk-2JBWPFHF.js} +23 -20
  17. package/dist/{chunk-BZTA7IIL.js → chunk-6IX5JZEH.js} +358 -4
  18. package/dist/chunk-FWZJH3TL.js +13 -0
  19. package/dist/chunk-GIFAF5ZS.js +313 -0
  20. package/dist/chunk-JGJSZ3UE.js +47 -0
  21. package/dist/chunk-JQLT6HBI.js +850 -0
  22. package/dist/{chunk-4KAG5U7A.js → chunk-L2CM2CUA.js} +0 -2
  23. package/dist/chunk-LFYO3MDC.js +58 -0
  24. package/dist/{chunk-OLD3NQLI.js → chunk-LTQAAIGE.js} +13 -17
  25. package/dist/{chunk-QQOLC46E.js → chunk-NEK6JKPW.js} +1 -1
  26. package/dist/{chunk-SITSZUFW.js → chunk-PVVQTENF.js} +1 -1
  27. package/dist/{chunk-FLJXZ7YC.js → chunk-SFF5MJEI.js} +2 -4
  28. package/dist/{chunk-EZMRFWZQ.js → chunk-U34YGJQB.js} +2 -94
  29. package/dist/{chunk-BWCC6ZJC.js → chunk-XLV6LYN2.js} +15 -60
  30. package/dist/components/index.d.ts +1 -1353
  31. package/dist/components/index.js +1 -20
  32. package/dist/components/navigation/index.d.ts +2 -32
  33. package/dist/components/navigation/index.js +1 -29
  34. package/dist/execution/index.d.ts +63 -231
  35. package/dist/execution/index.js +1 -4
  36. package/dist/graph/index.css +0 -1
  37. package/dist/graph/index.d.ts +4 -203
  38. package/dist/graph/index.js +1 -1
  39. package/dist/hooks/command-queue/index.d.ts +7 -0
  40. package/dist/hooks/command-queue/index.d.ts.map +1 -0
  41. package/dist/hooks/command-queue/useCommandQueue.d.ts +33 -0
  42. package/dist/hooks/command-queue/useCommandQueue.d.ts.map +1 -0
  43. package/dist/hooks/command-queue/useCommandQueueTotals.d.ts +17 -0
  44. package/dist/hooks/command-queue/useCommandQueueTotals.d.ts.map +1 -0
  45. package/dist/hooks/command-queue/useDeleteTask.d.ts +5 -0
  46. package/dist/hooks/command-queue/useDeleteTask.d.ts.map +1 -0
  47. package/dist/hooks/command-queue/usePatchTask.d.ts +6 -0
  48. package/dist/hooks/command-queue/usePatchTask.d.ts.map +1 -0
  49. package/dist/hooks/command-queue/useSubmitAction.d.ts +29 -0
  50. package/dist/hooks/command-queue/useSubmitAction.d.ts.map +1 -0
  51. package/dist/hooks/executions/index.d.ts +16 -0
  52. package/dist/hooks/executions/index.d.ts.map +1 -0
  53. package/dist/hooks/executions/useBulkDeleteExecutions.d.ts +15 -0
  54. package/dist/hooks/executions/useBulkDeleteExecutions.d.ts.map +1 -0
  55. package/dist/hooks/executions/useCancelExecution.d.ts +20 -0
  56. package/dist/hooks/executions/useCancelExecution.d.ts.map +1 -0
  57. package/dist/hooks/executions/useDeleteExecution.d.ts +13 -0
  58. package/dist/hooks/executions/useDeleteExecution.d.ts.map +1 -0
  59. package/dist/hooks/executions/useExecuteAsync.d.ts +21 -0
  60. package/dist/hooks/executions/useExecuteAsync.d.ts.map +1 -0
  61. package/dist/hooks/executions/useExecution.d.ts +10 -0
  62. package/dist/hooks/executions/useExecution.d.ts.map +1 -0
  63. package/dist/hooks/executions/useExecutions.d.ts +16 -0
  64. package/dist/hooks/executions/useExecutions.d.ts.map +1 -0
  65. package/dist/hooks/executions/useResourceDefinition.d.ts +9 -0
  66. package/dist/hooks/executions/useResourceDefinition.d.ts.map +1 -0
  67. package/dist/hooks/executions/useResources.d.ts +15 -0
  68. package/dist/hooks/executions/useResources.d.ts.map +1 -0
  69. package/dist/hooks/executions/useRetryExecution.d.ts +16 -0
  70. package/dist/hooks/executions/useRetryExecution.d.ts.map +1 -0
  71. package/dist/hooks/feature-access/createUseFeatureAccess.d.ts +44 -0
  72. package/dist/hooks/feature-access/createUseFeatureAccess.d.ts.map +1 -0
  73. package/dist/hooks/feature-access/index.d.ts +2 -0
  74. package/dist/hooks/feature-access/index.d.ts.map +1 -0
  75. package/dist/hooks/index.d.ts +11 -1927
  76. package/dist/hooks/index.d.ts.map +1 -0
  77. package/dist/hooks/index.js +5 -4
  78. package/dist/hooks/monitoring/index.d.ts +9 -0
  79. package/dist/hooks/monitoring/index.d.ts.map +1 -0
  80. package/dist/hooks/monitoring/useActivities.d.ts +52 -0
  81. package/dist/hooks/monitoring/useActivities.d.ts.map +1 -0
  82. package/dist/hooks/monitoring/useCostSummary.d.ts +7 -0
  83. package/dist/hooks/monitoring/useCostSummary.d.ts.map +1 -0
  84. package/dist/hooks/monitoring/useExecutionHealth.d.ts +10 -0
  85. package/dist/hooks/monitoring/useExecutionHealth.d.ts.map +1 -0
  86. package/dist/hooks/monitoring/useExecutionLogs.d.ts +56 -0
  87. package/dist/hooks/monitoring/useExecutionLogs.d.ts.map +1 -0
  88. package/dist/hooks/monitoring/useNotifications.d.ts +11 -0
  89. package/dist/hooks/monitoring/useNotifications.d.ts.map +1 -0
  90. package/dist/hooks/notifications/index.d.ts +8 -0
  91. package/dist/hooks/notifications/index.d.ts.map +1 -0
  92. package/dist/hooks/notifications/useMarkAllAsRead.d.ts +2 -0
  93. package/dist/hooks/notifications/useMarkAllAsRead.d.ts.map +1 -0
  94. package/dist/hooks/notifications/useMarkAsRead.d.ts +2 -0
  95. package/dist/hooks/notifications/useMarkAsRead.d.ts.map +1 -0
  96. package/dist/hooks/notifications/useNotificationCount.d.ts +8 -0
  97. package/dist/hooks/notifications/useNotificationCount.d.ts.map +1 -0
  98. package/dist/hooks/observability/index.d.ts +19 -0
  99. package/dist/hooks/observability/index.d.ts.map +1 -0
  100. package/dist/hooks/observability/useBusinessImpact.d.ts +9 -0
  101. package/dist/hooks/observability/useBusinessImpact.d.ts.map +1 -0
  102. package/dist/hooks/observability/useCostBreakdown.d.ts +10 -0
  103. package/dist/hooks/observability/useCostBreakdown.d.ts.map +1 -0
  104. package/dist/hooks/observability/useCostByModel.d.ts +3 -0
  105. package/dist/hooks/observability/useCostByModel.d.ts.map +1 -0
  106. package/dist/hooks/observability/useCostTrends.d.ts +3 -0
  107. package/dist/hooks/observability/useCostTrends.d.ts.map +1 -0
  108. package/dist/hooks/observability/useDashboardMetrics.d.ts +3 -0
  109. package/dist/hooks/observability/useDashboardMetrics.d.ts.map +1 -0
  110. package/dist/hooks/observability/useErrorAnalysis.d.ts +7 -0
  111. package/dist/hooks/observability/useErrorAnalysis.d.ts.map +1 -0
  112. package/dist/hooks/observability/useErrorDetails.d.ts +20 -0
  113. package/dist/hooks/observability/useErrorDetails.d.ts.map +1 -0
  114. package/dist/hooks/observability/useErrorDistribution.d.ts +12 -0
  115. package/dist/hooks/observability/useErrorDistribution.d.ts.map +1 -0
  116. package/dist/hooks/observability/useErrorTrends.d.ts +12 -0
  117. package/dist/hooks/observability/useErrorTrends.d.ts.map +1 -0
  118. package/dist/hooks/observability/useResolveError.d.ts +17 -0
  119. package/dist/hooks/observability/useResolveError.d.ts.map +1 -0
  120. package/dist/hooks/observability/useTopFailingResources.d.ts +13 -0
  121. package/dist/hooks/observability/useTopFailingResources.d.ts.map +1 -0
  122. package/dist/hooks/published.d.ts +19 -1652
  123. package/dist/hooks/published.d.ts.map +1 -0
  124. package/dist/hooks/published.js +369 -3
  125. package/dist/hooks/scheduling/index.d.ts +5 -0
  126. package/dist/hooks/scheduling/index.d.ts.map +1 -0
  127. package/dist/hooks/scheduling/useSchedules.d.ts +185 -0
  128. package/dist/hooks/scheduling/useSchedules.d.ts.map +1 -0
  129. package/dist/hooks/sessions/index.d.ts +8 -0
  130. package/dist/hooks/sessions/index.d.ts.map +1 -0
  131. package/dist/hooks/sessions/useSessionExecutions.d.ts +13 -0
  132. package/dist/hooks/sessions/useSessionExecutions.d.ts.map +1 -0
  133. package/dist/hooks/sessions/useSessionMessages.d.ts +7 -0
  134. package/dist/hooks/sessions/useSessionMessages.d.ts.map +1 -0
  135. package/dist/hooks/sessions/useSessions.d.ts +26 -0
  136. package/dist/hooks/sessions/useSessions.d.ts.map +1 -0
  137. package/dist/index.css +0 -118
  138. package/dist/index.d.ts +15 -7624
  139. package/dist/index.d.ts.map +1 -0
  140. package/dist/index.js +1125 -30
  141. package/dist/initialization/InitializationProvider.d.ts +48 -0
  142. package/dist/initialization/InitializationProvider.d.ts.map +1 -0
  143. package/dist/initialization/hooks/useAppInitialization.d.ts +32 -0
  144. package/dist/initialization/hooks/useAppInitialization.d.ts.map +1 -0
  145. package/dist/initialization/index.d.ts +22 -2361
  146. package/dist/initialization/index.d.ts.map +1 -0
  147. package/dist/initialization/index.js +4 -4
  148. package/dist/organization/context/OrganizationProvider.d.ts +20 -0
  149. package/dist/organization/context/OrganizationProvider.d.ts.map +1 -0
  150. package/dist/organization/hooks/useOrgInitialization.d.ts +56 -0
  151. package/dist/organization/hooks/useOrgInitialization.d.ts.map +1 -0
  152. package/dist/organization/index.d.ts +21 -283
  153. package/dist/organization/index.d.ts.map +1 -0
  154. package/dist/organization/index.js +4 -4
  155. package/dist/profile/context/ProfileProvider.d.ts +27 -0
  156. package/dist/profile/context/ProfileProvider.d.ts.map +1 -0
  157. package/dist/profile/hooks/useUserProfile.d.ts +31 -0
  158. package/dist/profile/hooks/useUserProfile.d.ts.map +1 -0
  159. package/dist/profile/index.d.ts +14 -2290
  160. package/dist/profile/index.d.ts.map +1 -0
  161. package/dist/profile/index.js +1 -1
  162. package/dist/provider/CoreAuthKitInner.d.ts +12 -0
  163. package/dist/provider/CoreAuthKitInner.d.ts.map +1 -0
  164. package/dist/provider/ElevasisCoreProvider.d.ts +39 -0
  165. package/dist/provider/ElevasisCoreProvider.d.ts.map +1 -0
  166. package/dist/provider/ElevasisServiceContext.d.ts +31 -0
  167. package/dist/provider/ElevasisServiceContext.d.ts.map +1 -0
  168. package/dist/provider/__tests__/CoreAuthKitInner.test.d.ts +2 -0
  169. package/dist/provider/__tests__/CoreAuthKitInner.test.d.ts.map +1 -0
  170. package/dist/provider/__tests__/ElevasisCoreProvider.test.d.ts +2 -0
  171. package/dist/provider/__tests__/ElevasisCoreProvider.test.d.ts.map +1 -0
  172. package/dist/provider/index.d.ts +7 -384
  173. package/dist/provider/index.d.ts.map +1 -0
  174. package/dist/provider/index.js +8 -9
  175. package/dist/provider/published.d.ts +9 -275
  176. package/dist/provider/published.d.ts.map +1 -0
  177. package/dist/provider/published.js +7 -8
  178. package/dist/provider/types.d.ts +190 -0
  179. package/dist/provider/types.d.ts.map +1 -0
  180. package/dist/sdk-barrel.d.ts +20 -0
  181. package/dist/sdk-barrel.d.ts.map +1 -0
  182. package/dist/supabase/index.d.ts +0 -255
  183. package/dist/supabase/index.js +2 -47
  184. package/dist/theme/cssVariables.d.ts +12 -0
  185. package/dist/theme/cssVariables.d.ts.map +1 -0
  186. package/dist/theme/index.d.ts +4 -0
  187. package/dist/theme/index.d.ts.map +1 -0
  188. package/dist/theme/presets/__tests__/getPreset.test.d.ts +2 -0
  189. package/dist/theme/presets/__tests__/getPreset.test.d.ts.map +1 -0
  190. package/dist/theme/presets/abyss.d.ts +3 -0
  191. package/dist/theme/presets/abyss.d.ts.map +1 -0
  192. package/dist/theme/presets/abyss.js +54 -0
  193. package/dist/theme/presets/aurora.d.ts +8 -0
  194. package/dist/theme/presets/aurora.d.ts.map +1 -0
  195. package/dist/theme/presets/aurora.js +59 -0
  196. package/dist/theme/presets/canopy.d.ts +3 -0
  197. package/dist/theme/presets/canopy.d.ts.map +1 -0
  198. package/dist/theme/presets/canopy.js +58 -0
  199. package/dist/theme/presets/cyber-flux.d.ts +8 -0
  200. package/dist/theme/presets/cyber-flux.d.ts.map +1 -0
  201. package/dist/theme/presets/cyber-strike.d.ts +9 -0
  202. package/dist/theme/presets/cyber-strike.d.ts.map +1 -0
  203. package/dist/theme/presets/cyber-void.d.ts +8 -0
  204. package/dist/theme/presets/cyber-void.d.ts.map +1 -0
  205. package/dist/theme/presets/cyber-volt.d.ts +8 -0
  206. package/dist/theme/presets/cyber-volt.d.ts.map +1 -0
  207. package/dist/theme/presets/default.d.ts +4 -0
  208. package/dist/theme/presets/default.d.ts.map +1 -0
  209. package/dist/theme/presets/ember.d.ts +8 -0
  210. package/dist/theme/presets/ember.d.ts.map +1 -0
  211. package/dist/theme/presets/ember.js +63 -0
  212. package/dist/theme/presets/honey.d.ts +3 -0
  213. package/dist/theme/presets/honey.d.ts.map +1 -0
  214. package/dist/theme/presets/honey.js +62 -0
  215. package/dist/theme/presets/index.d.ts +6 -0
  216. package/dist/theme/presets/index.d.ts.map +1 -0
  217. package/dist/theme/presets/midnight.d.ts +8 -0
  218. package/dist/theme/presets/midnight.d.ts.map +1 -0
  219. package/dist/theme/presets/midnight.js +68 -0
  220. package/dist/theme/presets/obsidian.d.ts +3 -0
  221. package/dist/theme/presets/obsidian.d.ts.map +1 -0
  222. package/dist/theme/presets/obsidian.js +56 -0
  223. package/dist/theme/presets/regal.d.ts +8 -0
  224. package/dist/theme/presets/regal.d.ts.map +1 -0
  225. package/dist/theme/presets/rose-gold.d.ts +8 -0
  226. package/dist/theme/presets/rose-gold.d.ts.map +1 -0
  227. package/dist/theme/presets/slate.d.ts +3 -0
  228. package/dist/theme/presets/slate.d.ts.map +1 -0
  229. package/dist/theme/presets/slate.js +56 -0
  230. package/dist/theme/presets/tactical.d.ts +8 -0
  231. package/dist/theme/presets/tactical.d.ts.map +1 -0
  232. package/dist/theme/presets/types.d.ts +26 -0
  233. package/dist/theme/presets/types.d.ts.map +1 -0
  234. package/dist/theme/presets/types.js +1 -0
  235. package/dist/utils/index.d.ts +1 -22
  236. package/dist/utils/index.js +1 -1
  237. package/package.json +67 -51
  238. package/dist/CoreAuthKitInner-KM72EYJS.js +0 -19
  239. package/dist/api/hooks/useApiClient.d.ts +0 -54
  240. package/dist/api/hooks/useApiClient.d.ts.map +0 -1
  241. package/dist/api/hooks/useApiClient.js +0 -185
  242. package/dist/chunk-3KMDHCAR.js +0 -52
  243. package/dist/chunk-6BJOYF6E.js +0 -8
  244. package/dist/chunk-BLO4SISK.js +0 -113
  245. package/dist/chunk-HUWJXLLF.js +0 -681
  246. package/dist/chunk-JVAZHVNV.js +0 -110
  247. package/dist/chunk-JYSYHVLU.js +0 -379
  248. package/dist/chunk-NE36BUGQ.js +0 -146
  249. package/dist/chunk-NIAVTSMB.js +0 -21
  250. package/dist/chunk-O3PY6B6E.js +0 -749
  251. package/dist/chunk-OXVOHOP3.js +0 -661
  252. package/dist/chunk-PCBXNHKY.js +0 -1460
  253. package/dist/chunk-PSLKGOBZ.js +0 -58
  254. package/dist/chunk-QSVZP2NU.js +0 -214
  255. package/dist/chunk-RJCA5672.js +0 -1664
  256. package/dist/chunk-TMFCNFLW.js +0 -107
  257. package/dist/chunk-TN3PU2WK.js +0 -748
  258. package/dist/chunk-W7ZBF5AA.js +0 -1
  259. package/dist/chunk-YZ6GTZXL.js +0 -48
  260. package/dist/components/command-queue/index.css +0 -53
  261. package/dist/components/command-queue/index.d.ts +0 -204
  262. package/dist/components/command-queue/index.js +0 -12
  263. package/dist/components/forms/index.d.ts +0 -56
  264. package/dist/components/forms/index.js +0 -2
  265. package/dist/components/index.css +0 -443
  266. package/dist/components/monitoring/index.d.ts +0 -66
  267. package/dist/components/monitoring/index.js +0 -2
  268. package/dist/components/notifications/index.d.ts +0 -52
  269. package/dist/components/notifications/index.js +0 -5
  270. package/dist/components/resource-definition/index.css +0 -388
  271. package/dist/components/resource-definition/index.d.ts +0 -301
  272. package/dist/components/resource-definition/index.js +0 -3
  273. package/dist/display/index.css +0 -53
  274. package/dist/display/index.d.ts +0 -606
  275. package/dist/display/index.js +0 -7
  276. package/dist/execution/index.css +0 -388
  277. package/dist/provider/index.css +0 -61
  278. /package/dist/{chunk-Q47SPRY7.js → chunk-BUZONXAW.js} +0 -0
  279. /package/dist/{chunk-NXHL23JW.js → chunk-XXDDMASA.js} +0 -0
@@ -0,0 +1,43 @@
1
+ import { AuthProvider } from './chunk-7PLEQFHO.js';
2
+ import { AuthKitProvider, useAuth } from '@workos-inc/authkit-react';
3
+ import { useMemo } from 'react';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ function CoreAuthKitInner({ auth, children }) {
7
+ return /* @__PURE__ */ jsx(
8
+ AuthKitProvider,
9
+ {
10
+ clientId: auth.clientId,
11
+ apiHostname: auth.apiHostname ?? "api.workos.com",
12
+ redirectUri: auth.redirectUri,
13
+ devMode: auth.devMode ?? false,
14
+ children: /* @__PURE__ */ jsx(WorkOSAuthAdapter, { children })
15
+ }
16
+ );
17
+ }
18
+ var WORKOS_REFRESH_TOKEN_KEY = "workos:refresh-token";
19
+ function hasWorkOSRefreshToken() {
20
+ try {
21
+ return !!localStorage.getItem(WORKOS_REFRESH_TOKEN_KEY);
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ function WorkOSAuthAdapter({ children }) {
27
+ const { user, isLoading, getAccessToken, organizationId, signIn } = useAuth();
28
+ const adaptedUser = useMemo(() => user ? { id: user.id } : null, [user?.id]);
29
+ const value = useMemo(
30
+ () => ({
31
+ user: adaptedUser,
32
+ isLoading,
33
+ getAccessToken,
34
+ organizationId: organizationId ?? null,
35
+ signIn,
36
+ canRecover: hasWorkOSRefreshToken
37
+ }),
38
+ [adaptedUser, isLoading, getAccessToken, organizationId, signIn]
39
+ );
40
+ return /* @__PURE__ */ jsx(AuthProvider, { value, children });
41
+ }
42
+
43
+ export { CoreAuthKitInner };
@@ -68,18 +68,17 @@ declare function useApiClientContext(): ApiClientContextValue;
68
68
  */
69
69
  declare function ApiClientProvider({ children, getAccessToken, organizationId, getOrganizationId: getOrganizationIdProp, isOrganizationReady, onError }: ApiClientProviderProps): react_jsx_runtime.JSX.Element;
70
70
 
71
- /**
72
- * Return type of useOrganizations hook (subset needed by the factory)
73
- */
74
- interface UseOrganizationsReturn {
75
- isInitializing: boolean;
76
- isOrgRefreshing: boolean;
77
- }
78
71
  /**
79
72
  * Hook that returns apiRequest and deferredApiRequest bound to the current
80
73
  * ApiClientContext. apiUrl is the only parameter because org ID is resolved
81
74
  * at call time via getOrganizationId() from context.
82
75
  *
76
+ * When OrganizationProvider is present in the tree, isOrganizationReady and
77
+ * isInitializing reflect the live org state (currentWorkOSOrganizationId,
78
+ * isInitializing, isOrgRefreshing). When OrganizationProvider is absent
79
+ * (e.g. theme-only mode, testing), the hook falls back to the values from
80
+ * ApiClientContext.
81
+ *
83
82
  * Usage:
84
83
  * ```typescript
85
84
  * import { useApiClient } from '@repo/ui/api'
@@ -97,29 +96,6 @@ declare function useApiClient(apiUrl: string): {
97
96
  isOrganizationReady: boolean;
98
97
  isInitializing: boolean;
99
98
  };
100
- /**
101
- * Factory function to create a useApiClient hook for your app.
102
- *
103
- * @deprecated Use the plain `useApiClient(apiUrl)` hook instead.
104
- * The factory pattern is no longer needed because org ID is resolved at
105
- * call time via getOrganizationId() from ApiClientContext.
106
- *
107
- * Migration:
108
- * ```typescript
109
- * // Before
110
- * export const useApiClient = createUseApiClient(useOrganizations, API_URL)
111
- *
112
- * // After
113
- * import { useApiClient } from '@repo/ui/api'
114
- * // call useApiClient(API_URL) directly in your hook/component
115
- * ```
116
- */
117
- declare function createUseApiClient(useOrganizations: () => UseOrganizationsReturn, apiUrl: string): () => {
118
- apiRequest: <T>(endpoint: string, options?: RequestInit) => Promise<T>;
119
- deferredApiRequest: <T>(endpoint: string, options?: RequestInit) => Promise<T>;
120
- isOrganizationReady: boolean;
121
- isInitializing: boolean;
122
- };
123
99
 
124
- export { ApiClientProvider, createUseApiClient, useApiClient, useApiClientContext };
100
+ export { ApiClientProvider, useApiClient, useApiClientContext };
125
101
  export type { ApiClientContextValue, ApiClientProviderProps, ApiErrorDetails };
package/dist/api/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import '../chunk-XCYKC6OZ.js';
2
- export { ApiClientProvider, createUseApiClient, useApiClient, useApiClientContext } from '../chunk-BWCC6ZJC.js';
3
- import '../chunk-JVAZHVNV.js';
2
+ export { ApiClientProvider, useApiClient, useApiClientContext } from '../chunk-XLV6LYN2.js';
3
+ import '../chunk-LFYO3MDC.js';
4
4
  import '../chunk-4VGWQ5AN.js';
5
+ import '../chunk-DD3CCMCZ.js';
@@ -1,19 +1,37 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
 
4
- interface AuthAdapter {
4
+ interface AuthContextValue {
5
5
  user: {
6
6
  id: string;
7
7
  } | null;
8
8
  isLoading: boolean;
9
9
  getAccessToken: () => Promise<string>;
10
10
  organizationId?: string | null;
11
+ /**
12
+ * Trigger WorkOS AuthKit's sign-in flow (redirect to WorkOS hosted auth page).
13
+ * Used by ProtectedRoute for auto-recovery when `canRecover()` returns true.
14
+ */
15
+ signIn: (options?: {
16
+ state?: {
17
+ returnTo?: string;
18
+ };
19
+ }) => void;
20
+ /**
21
+ * Returns true when a previous session can be recovered (refresh token
22
+ * exists in storage). ProtectedRoute calls `signIn()` only when this returns
23
+ * true; otherwise it navigates to the login page.
24
+ *
25
+ * Explicit logout clears the stored token, so canRecover() returns false
26
+ * and the user sees the login page as expected.
27
+ */
28
+ canRecover: () => boolean;
11
29
  }
12
- declare function useAuthContext(): AuthAdapter;
30
+ declare function useAuthContext(): AuthContextValue;
13
31
  declare function AuthProvider({ value, children }: {
14
- value: AuthAdapter;
32
+ value: AuthContextValue;
15
33
  children: ReactNode;
16
- }): react.FunctionComponentElement<react.ProviderProps<AuthAdapter | null>>;
34
+ }): react.FunctionComponentElement<react.ProviderProps<AuthContextValue | null>>;
17
35
 
18
36
  export { AuthProvider, useAuthContext };
19
- export type { AuthAdapter };
37
+ export type { AuthContextValue };
@@ -0,0 +1,32 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface AdminGuardProps {
3
+ children: ReactNode;
4
+ /**
5
+ * Path to redirect non-admin users to.
6
+ * @default '/'
7
+ */
8
+ redirectTo?: string;
9
+ /**
10
+ * Rendered while user readiness is being determined.
11
+ * When not provided, nothing is rendered during initialization.
12
+ */
13
+ fallback?: ReactNode;
14
+ }
15
+ /**
16
+ * Headless route guard for platform admin pages.
17
+ *
18
+ * Reads `profile.is_platform_admin` from the nearest InitializationProvider.
19
+ * Non-admin users are redirected to `redirectTo` (default: '/').
20
+ *
21
+ * Must be nested inside a ProtectedRoute (or equivalent) so that
22
+ * `userReady` is guaranteed to be true when this guard runs.
23
+ *
24
+ * @example
25
+ * <ProtectedRoute>
26
+ * <AdminGuard fallback={<AppShellLoader />}>
27
+ * <AdminDashboard />
28
+ * </AdminGuard>
29
+ * </ProtectedRoute>
30
+ */
31
+ export declare function AdminGuard({ children, redirectTo, fallback }: AdminGuardProps): import("react/jsx-runtime").JSX.Element | null;
32
+ //# sourceMappingURL=AdminGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdminGuard.d.ts","sourceRoot":"","sources":["../../../src/auth/guards/AdminGuard.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,SAAS,CAAA;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,UAAgB,EAAE,QAAe,EAAE,EAAE,eAAe,kDA0B1F"}
@@ -0,0 +1,60 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { InitializationError } from '../../initialization/hooks/useAppInitialization';
3
+ export interface ProtectedRouteProps {
4
+ children: ReactNode;
5
+ /**
6
+ * Path to redirect to when user is unauthenticated and the auth adapter
7
+ * does not provide a `signIn` function.
8
+ * @default '/login'
9
+ */
10
+ redirectTo?: string;
11
+ /**
12
+ * Rendered while initialization is in progress.
13
+ * When not provided, nothing is rendered during initialization.
14
+ */
15
+ fallback?: ReactNode;
16
+ /**
17
+ * Rendered when initialization fails with a non-organization error.
18
+ * Receives the error and a retry callback.
19
+ * When not provided, the error is silently swallowed (children not rendered).
20
+ */
21
+ errorFallback?: (error: InitializationError, retry: () => void) => ReactNode;
22
+ /**
23
+ * When true (default), waits for both user AND organization to be ready
24
+ * before rendering children. When false, only waits for user readiness.
25
+ * @default true
26
+ */
27
+ waitForOrganization?: boolean;
28
+ }
29
+ /**
30
+ * Headless route guard for authenticated pages.
31
+ *
32
+ * Reads initialization state from the nearest InitializationProvider.
33
+ *
34
+ * When `canRecover()` returns true (refresh token exists), unauthenticated users
35
+ * are sent directly to WorkOS AuthKit via `signIn()`. WorkOS checks its
36
+ * server-side session and either signs the user in immediately (page-reload case)
37
+ * or shows a login form (logged-out case). Explicit logout destroys the
38
+ * server-side session, so the next auto-signIn correctly presents a login form
39
+ * rather than looping.
40
+ *
41
+ * When `canRecover()` returns false, falls back to navigating to `redirectTo`
42
+ * (default: '/login') with a `returnTo` search param.
43
+ *
44
+ * Organization-layer errors are allowed through -- routes like /invitations
45
+ * must be accessible even when the user has no org membership.
46
+ *
47
+ * @example
48
+ * // With custom fallback (your Mantine loader):
49
+ * <ProtectedRoute fallback={<AppShellLoader />}>
50
+ * <DashboardPage />
51
+ * </ProtectedRoute>
52
+ *
53
+ * @example
54
+ * // Wait only for user, not org (e.g. /invitations route):
55
+ * <ProtectedRoute waitForOrganization={false}>
56
+ * <InvitationsPage />
57
+ * </ProtectedRoute>
58
+ */
59
+ export declare function ProtectedRoute({ children, redirectTo, fallback, errorFallback, waitForOrganization }: ProtectedRouteProps): import("react/jsx-runtime").JSX.Element | null;
60
+ //# sourceMappingURL=ProtectedRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProtectedRoute.d.ts","sourceRoot":"","sources":["../../../src/auth/guards/ProtectedRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAIzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAA;AAE1F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,SAAS,CAAA;IAC5E;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,UAAqB,EACrB,QAAe,EACf,aAAa,EACb,mBAA0B,EAC3B,EAAE,mBAAmB,kDAyDrB"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * AdminGuard Tests (shared @repo/ui guard)
3
+ *
4
+ * Tests role-based access control for platform admin pages:
5
+ * - Shows fallback while user is not ready
6
+ * - Renders children for platform admin users
7
+ * - Redirects non-admin users to redirectTo (default: '/')
8
+ * - Handles missing profile gracefully
9
+ * - Supports custom redirectTo
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=AdminGuard.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdminGuard.test.d.ts","sourceRoot":"","sources":["../../../../src/auth/guards/__tests__/AdminGuard.test.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * ProtectedRoute Tests (shared @repo/ui guard)
3
+ *
4
+ * Tests headless authentication guard behavior:
5
+ * - Shows fallback while initializing
6
+ * - Redirects unauthenticated users to login with returnTo
7
+ * - Renders children when user is ready
8
+ * - Renders children when org error (allows /invitations route pattern)
9
+ * - Shows errorFallback for non-organization errors
10
+ * - Waits for org readiness when waitForOrganization=true (default)
11
+ * - Renders after user ready when waitForOrganization=false
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=ProtectedRoute.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProtectedRoute.test.d.ts","sourceRoot":"","sources":["../../../../src/auth/guards/__tests__/ProtectedRoute.test.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
@@ -1,173 +1,16 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
-
5
- interface AuthAdapter {
6
- user: {
7
- id: string;
8
- } | null;
9
- isLoading: boolean;
10
- getAccessToken: () => Promise<string>;
11
- organizationId?: string | null;
12
- }
13
- declare function useAuthContext(): AuthAdapter;
14
- declare function AuthProvider({ value, children }: {
15
- value: AuthAdapter;
16
- children: ReactNode;
17
- }): react.FunctionComponentElement<react.ProviderProps<AuthAdapter | null>>;
18
-
19
1
  /**
20
- * Bridge component that reads WorkOS AuthKit state and provides it
21
- * via the generic AuthContext. Place inside AuthKitProvider.
22
- *
23
- * Narrows WorkOS User to { id: string } -- @repo/ui hooks only need the ID.
24
- * Uses useMemo to stabilize the user object and prevent unnecessary
25
- * useEffect re-runs in downstream hooks.
26
- */
27
- declare function WorkOSAuthBridge({ children }: {
28
- children: ReactNode;
29
- }): react_jsx_runtime.JSX.Element;
30
-
31
- interface OAuthContextValue {
32
- user: {
33
- id: string;
34
- } | null;
35
- isLoading: boolean;
36
- organizationId: string | null;
37
- getAccessToken: () => Promise<string>;
38
- error: string | null;
39
- initiateOAuthFlow: () => void;
40
- }
41
- declare function useOAuthContext(): OAuthContextValue;
42
-
43
- /**
44
- * Returns a stable reference to getAccessToken that won't change between renders
45
- *
46
- * This prevents SSE connections from reconnecting unnecessarily when the
47
- * WorkOS useAuth hook returns a new getAccessToken function reference
48
- *
49
- * @example
50
- * ```tsx
51
- * const getAccessToken = useStableAccessToken()
52
- *
53
- * useEffect(() => {
54
- * fetchEventSourceWithTokenRefresh({
55
- * getToken: getAccessToken,
56
- * // ...
57
- * })
58
- * }, [getAccessToken]) // Won't re-run on every render
59
- * ```
60
- */
61
- declare function useStableAccessToken(): () => Promise<string>;
62
-
63
- /**
64
- * Checks WorkOS session validity when window/tab regains focus
65
- *
66
- * When window or tab becomes visible after inactivity, validates session
67
- * by attempting to get access token. If session expired (WorkOS inactivity
68
- * timeout exceeded), signs out user and redirects to login.
69
- *
70
- * How it works:
71
- * 1. Window/tab regains focus after inactivity
72
- * 2. Cancel all pending queries to prevent 401 error cascade
73
- * 3. Attempt to get access token from WorkOS
74
- * 4. If successful: Resume queries with fresh token
75
- * 5. If failed (session expired): Sign out and redirect to login
76
- *
77
- * @example
78
- * // In __root.tsx
79
- * export function RootLayoutComponent() {
80
- * useSessionCheck()
81
- * return <YourApp />
82
- * }
83
- */
84
- declare function useSessionCheck(): void;
85
-
86
- interface InitializationError {
87
- layer: 'auth' | 'profile' | 'organization';
88
- message: string;
89
- originalError?: Error;
90
- }
91
-
92
- interface ProtectedRouteProps {
93
- children: ReactNode;
94
- /**
95
- * Path to redirect to when user is unauthenticated.
96
- * @default '/login'
97
- */
98
- redirectTo?: string;
99
- /**
100
- * Rendered while initialization is in progress.
101
- * When not provided, nothing is rendered during initialization.
102
- */
103
- fallback?: ReactNode;
104
- /**
105
- * Rendered when initialization fails with a non-organization error.
106
- * Receives the error and a retry callback.
107
- * When not provided, the error is silently swallowed (children not rendered).
108
- */
109
- errorFallback?: (error: InitializationError, retry: () => void) => ReactNode;
110
- /**
111
- * When true (default), waits for both user AND organization to be ready
112
- * before rendering children. When false, only waits for user readiness.
113
- * @default true
114
- */
115
- waitForOrganization?: boolean;
116
- }
117
- /**
118
- * Headless route guard for authenticated pages.
119
- *
120
- * Reads initialization state from the nearest InitializationProvider.
121
- * Redirects unauthenticated users to `redirectTo` (default: '/login')
122
- * with a `returnTo` search param preserving the current location.
123
- *
124
- * Organization-layer errors are allowed through — routes like /invitations
125
- * must be accessible even when the user has no org membership.
126
- *
127
- * @example
128
- * // With custom fallback (your Mantine loader):
129
- * <ProtectedRoute fallback={<AppShellLoader />}>
130
- * <DashboardPage />
131
- * </ProtectedRoute>
132
- *
133
- * @example
134
- * // Wait only for user, not org (e.g. /invitations route):
135
- * <ProtectedRoute waitForOrganization={false}>
136
- * <InvitationsPage />
137
- * </ProtectedRoute>
138
- */
139
- declare function ProtectedRoute({ children, redirectTo, fallback, errorFallback, waitForOrganization }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
140
-
141
- interface AdminGuardProps {
142
- children: ReactNode;
143
- /**
144
- * Path to redirect non-admin users to.
145
- * @default '/'
146
- */
147
- redirectTo?: string;
148
- /**
149
- * Rendered while user readiness is being determined.
150
- * When not provided, nothing is rendered during initialization.
151
- */
152
- fallback?: ReactNode;
153
- }
154
- /**
155
- * Headless route guard for platform admin pages.
156
- *
157
- * Reads `profile.is_platform_admin` from the nearest InitializationProvider.
158
- * Non-admin users are redirected to `redirectTo` (default: '/').
159
- *
160
- * Must be nested inside a ProtectedRoute (or equivalent) so that
161
- * `userReady` is guaranteed to be true when this guard runs.
162
- *
163
- * @example
164
- * <ProtectedRoute>
165
- * <AdminGuard fallback={<AppShellLoader />}>
166
- * <AdminDashboard />
167
- * </AdminGuard>
168
- * </ProtectedRoute>
2
+ * Auth module - Pure authentication concerns
3
+ *
4
+ * Exports:
5
+ * - AuthContextValue: Interface for auth state (user, isLoading, getAccessToken, organizationId, signIn, canRecover)
6
+ * - AuthProvider: React context provider for AuthContextValue
7
+ * - useAuthContext: Hook to consume AuthContextValue from context
8
+ * - useStableAccessToken: Stable reference to getAccessToken for SSE connections
9
+ * - useSessionCheck: Validates session on tab refocus
169
10
  */
170
- declare function AdminGuard({ children, redirectTo, fallback }: AdminGuardProps): react_jsx_runtime.JSX.Element | null;
171
-
172
- export { AdminGuard, AuthProvider, ProtectedRoute, WorkOSAuthBridge, useAuthContext, useOAuthContext, useSessionCheck as useRefocusSessionCheck, useSessionCheck, useStableAccessToken };
173
- export type { AdminGuardProps, AuthAdapter, OAuthContextValue, ProtectedRouteProps };
11
+ export { AuthProvider, useAuthContext, type AuthContextValue } from './context';
12
+ export * from './hooks/useStableAccessToken';
13
+ export * from './hooks/useSessionCheck';
14
+ export { ProtectedRoute, type ProtectedRouteProps } from './guards/ProtectedRoute';
15
+ export { AdminGuard, type AdminGuardProps } from './guards/AdminGuard';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC/E,cAAc,8BAA8B,CAAA;AAC5C,cAAc,yBAAyB,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAClF,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA"}
@@ -1,8 +1,7 @@
1
- export { AdminGuard, ProtectedRoute, useSessionCheck as useRefocusSessionCheck, useSessionCheck, useStableAccessToken } from '../chunk-FDCVFCOQ.js';
2
- export { WorkOSAuthBridge } from '../chunk-NIAVTSMB.js';
3
- export { useOAuthContext } from '../chunk-QSVZP2NU.js';
4
- import '../chunk-QQOLC46E.js';
5
- import '../chunk-DD3CCMCZ.js';
6
- import '../chunk-4KAG5U7A.js';
1
+ export { AdminGuard, ProtectedRoute, useSessionCheck as useRefocusSessionCheck, useSessionCheck } from '../chunk-2JBWPFHF.js';
2
+ export { useStableAccessToken } from '../chunk-FWZJH3TL.js';
3
+ import '../chunk-NEK6JKPW.js';
4
+ import '../chunk-L2CM2CUA.js';
7
5
  import '../chunk-KA7LO7U5.js';
6
+ import '../chunk-DD3CCMCZ.js';
8
7
  export { AuthProvider, useAuthContext } from '../chunk-7PLEQFHO.js';
@@ -1,22 +1,18 @@
1
- import { useInitialization } from './chunk-QQOLC46E.js';
1
+ import { useInitialization } from './chunk-NEK6JKPW.js';
2
2
  import { useAuthContext } from './chunk-7PLEQFHO.js';
3
- import { useRef, useCallback, useEffect } from 'react';
3
+ import { useRef, useEffect } from 'react';
4
4
  import { useQueryClient } from '@tanstack/react-query';
5
5
  import { useNavigate, useLocation } from '@tanstack/react-router';
6
6
  import { jsx, Fragment } from 'react/jsx-runtime';
7
7
 
8
- function useStableAccessToken() {
9
- const { getAccessToken } = useAuthContext();
10
- const getAccessTokenRef = useRef(getAccessToken);
11
- getAccessTokenRef.current = getAccessToken;
12
- return useCallback(() => {
13
- return getAccessTokenRef.current();
14
- }, []);
15
- }
16
8
  function useSessionCheck() {
17
9
  const { user } = useAuthContext();
18
10
  const queryClient = useQueryClient();
19
11
  const isCheckingRef = useRef(false);
12
+ const hadUserRef = useRef(false);
13
+ if (user) {
14
+ hadUserRef.current = true;
15
+ }
20
16
  useEffect(() => {
21
17
  const handleVisibilityChange = async () => {
22
18
  if (isCheckingRef.current || document.visibilityState !== "visible") {
@@ -24,12 +20,14 @@ function useSessionCheck() {
24
20
  }
25
21
  isCheckingRef.current = true;
26
22
  try {
27
- if (!user) {
23
+ if (!user && hadUserRef.current) {
28
24
  window.location.replace("/login");
29
25
  return;
30
26
  }
31
- await queryClient.cancelQueries();
32
- queryClient.invalidateQueries();
27
+ if (user) {
28
+ await queryClient.cancelQueries();
29
+ queryClient.invalidateQueries();
30
+ }
33
31
  } finally {
34
32
  isCheckingRef.current = false;
35
33
  }
@@ -50,6 +48,7 @@ function ProtectedRoute({
50
48
  waitForOrganization = true
51
49
  }) {
52
50
  const { userReady, allReady, isInitializing, error, retry } = useInitialization();
51
+ const { signIn, canRecover } = useAuthContext();
53
52
  const navigate = useNavigate();
54
53
  const location = useLocation();
55
54
  const hasRedirected = useRef(false);
@@ -59,12 +58,16 @@ function ProtectedRoute({
59
58
  hasRedirected.current = true;
60
59
  const searchStr = location.searchStr ?? "";
61
60
  const returnTo = location.pathname + searchStr;
62
- navigate({
63
- to: redirectTo,
64
- search: returnTo !== "/" ? { returnTo } : {}
65
- });
61
+ if (canRecover()) {
62
+ signIn({ state: { returnTo: returnTo !== "/" ? returnTo : void 0 } });
63
+ } else {
64
+ navigate({
65
+ to: redirectTo,
66
+ search: returnTo !== "/" ? { returnTo } : {}
67
+ });
68
+ }
66
69
  }
67
- }, [unauthenticated, navigate, redirectTo, location]);
70
+ }, [unauthenticated, signIn, canRecover, navigate, redirectTo, location]);
68
71
  if (isInitializing) {
69
72
  return /* @__PURE__ */ jsx(Fragment, { children: fallback });
70
73
  }
@@ -75,7 +78,7 @@ function ProtectedRoute({
75
78
  return null;
76
79
  }
77
80
  if (unauthenticated) {
78
- return null;
81
+ return /* @__PURE__ */ jsx(Fragment, { children: fallback });
79
82
  }
80
83
  if (waitForOrganization && !allReady && error?.layer !== "organization") {
81
84
  return /* @__PURE__ */ jsx(Fragment, { children: fallback });
@@ -102,4 +105,4 @@ function AdminGuard({ children, redirectTo = "/", fallback = null }) {
102
105
  return /* @__PURE__ */ jsx(Fragment, { children });
103
106
  }
104
107
 
105
- export { AdminGuard, ProtectedRoute, useSessionCheck, useStableAccessToken };
108
+ export { AdminGuard, ProtectedRoute, useSessionCheck };