@elevasis/ui 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CoreAuthKitInner-3J4RVQO6.js +43 -0
- package/dist/api/index.d.ts +32 -18
- package/dist/api/index.js +4 -2
- package/dist/auth/context.d.ts +23 -5
- package/dist/auth/index.d.ts +119 -30
- package/dist/auth/index.js +6 -3
- package/dist/chunk-2JBWPFHF.js +108 -0
- package/dist/chunk-4VGWQ5AN.js +91 -0
- package/dist/chunk-72HOBFMP.js +87 -0
- package/dist/{chunk-WNWKOCGJ.js → chunk-A3MCANC6.js} +296 -2
- package/dist/{chunk-JKERRYVS.js → chunk-BLO4SISK.js} +7 -3
- package/dist/chunk-DD3CCMCZ.js +15 -0
- package/dist/chunk-FWZJH3TL.js +13 -0
- package/dist/{chunk-GEFB5YIR.js → chunk-JBFFCZI4.js} +1 -1
- package/dist/chunk-JGJSZ3UE.js +47 -0
- package/dist/{chunk-7AI5ZYJ4.js → chunk-JVAZHVNV.js} +2 -94
- package/dist/{chunk-ZGHDPDTF.js → chunk-JYSYHVLU.js} +3 -3
- package/dist/{chunk-5UWFGBFM.js → chunk-L2CM2CUA.js} +16 -4
- package/dist/chunk-NEK6JKPW.js +75 -0
- package/dist/{chunk-J3FALDQE.js → chunk-NXHL23JW.js} +7 -13
- package/dist/{chunk-OUHGHTE7.js → chunk-O3PY6B6E.js} +3 -2
- package/dist/{chunk-YULUKCS6.js → chunk-PVVQTENF.js} +1 -1
- package/dist/chunk-TIRMFDM4.js +33 -0
- package/dist/{chunk-PYL4XW6H.js → chunk-TMFCNFLW.js} +1 -1
- package/dist/{chunk-S66I2PYB.js → chunk-TN3PU2WK.js} +1 -1
- package/dist/chunk-TYV5NJV2.js +1 -0
- package/dist/{chunk-B64YDSAY.js → chunk-TZPAA4RC.js} +54 -97
- package/dist/chunk-UMXDDEAG.js +148 -0
- package/dist/chunk-XLV6LYN2.js +157 -0
- package/dist/components/command-queue/index.js +6 -4
- package/dist/components/index.js +9 -7
- package/dist/components/notifications/index.js +4 -3
- package/dist/display/index.js +3 -2
- package/dist/hooks/index.d.ts +2630 -3
- package/dist/hooks/index.js +9 -5
- package/dist/hooks/published.d.ts +2630 -3
- package/dist/hooks/published.js +7 -3
- package/dist/index.d.ts +759 -164
- package/dist/index.js +24 -18
- package/dist/initialization/index.d.ts +49 -1
- package/dist/initialization/index.js +5 -2
- package/dist/organization/index.d.ts +61 -2
- package/dist/organization/index.js +5 -2
- package/dist/profile/index.d.ts +30 -2
- package/dist/profile/index.js +2 -1
- package/dist/provider/index.d.ts +116 -43
- package/dist/provider/index.js +10 -6
- package/dist/provider/published.d.ts +88 -28
- package/dist/provider/published.js +9 -4
- package/dist/supabase/index.js +2 -47
- package/dist/utils/index.js +2 -1
- package/package.json +15 -2
- package/dist/CoreAuthKitInner-KM72EYJS.js +0 -19
- package/dist/chunk-GDV44UWF.js +0 -138
- package/dist/chunk-HBRMWW6V.js +0 -43
- package/dist/chunk-NIAVTSMB.js +0 -21
- package/dist/chunk-QSVZP2NU.js +0 -214
- package/dist/chunk-ZQVPUAGR.js +0 -89
- /package/dist/{chunk-Q47SPRY7.js → chunk-RNP5R5I3.js} +0 -0
|
@@ -10,6 +10,53 @@ interface ApiErrorDetails {
|
|
|
10
10
|
requestId?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Pluggable notification adapter interface.
|
|
15
|
+
*
|
|
16
|
+
* Implement this to connect any notification library (Mantine, react-toastify, etc.)
|
|
17
|
+
* to the Elevasis UI hooks.
|
|
18
|
+
*/
|
|
19
|
+
interface NotificationAdapter {
|
|
20
|
+
success(title: string, message: string): void;
|
|
21
|
+
error(title: string, message: string): void;
|
|
22
|
+
info(title: string, message: string): void;
|
|
23
|
+
warning(title: string, message: string): void;
|
|
24
|
+
/** Formats and displays an API error using structured error-utils helpers. */
|
|
25
|
+
apiError(error: unknown): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Provides a notification adapter to all descendant components.
|
|
29
|
+
*
|
|
30
|
+
* Pass a `MantineNotificationAdapter` for Command Center, or any custom
|
|
31
|
+
* adapter for other consumers (template, tests, etc.).
|
|
32
|
+
*
|
|
33
|
+
* When omitted, hooks fall back to the console adapter automatically.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* import { NotificationProvider } from '@repo/ui/provider'
|
|
38
|
+
* import { mantineNotificationAdapter } from '@repo/ui/provider'
|
|
39
|
+
*
|
|
40
|
+
* <NotificationProvider adapter={mantineNotificationAdapter}>
|
|
41
|
+
* <App />
|
|
42
|
+
* </NotificationProvider>
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function NotificationProvider({ adapter, children }: {
|
|
46
|
+
adapter: NotificationAdapter;
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
}): react_jsx_runtime.JSX.Element;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the active notification adapter.
|
|
51
|
+
*
|
|
52
|
+
* Falls back to the console adapter when used outside a NotificationProvider,
|
|
53
|
+
* so hooks remain functional in template environments without Mantine.
|
|
54
|
+
*
|
|
55
|
+
* Named `useNotificationAdapter` to avoid collision with the data-fetching
|
|
56
|
+
* `useNotifications` hook exported from `hooks/monitoring`.
|
|
57
|
+
*/
|
|
58
|
+
declare function useNotificationAdapter(): NotificationAdapter;
|
|
59
|
+
|
|
13
60
|
/** Flat + per-scheme override pattern. Flat values apply to both; `light`/`dark` win over flat. */
|
|
14
61
|
type WithSchemes<T> = T & {
|
|
15
62
|
light?: T;
|
|
@@ -58,10 +105,10 @@ interface ElevasisCoreThemeConfig {
|
|
|
58
105
|
}
|
|
59
106
|
/**
|
|
60
107
|
* Auth configuration union.
|
|
61
|
-
* 'authkit' (WorkOS AuthKit)
|
|
108
|
+
* 'authkit' (WorkOS AuthKit) is the supported mode.
|
|
62
109
|
* 'apiKey' is defined for forward type compatibility but will throw at runtime.
|
|
63
110
|
*/
|
|
64
|
-
type AuthConfig = AuthKitConfig |
|
|
111
|
+
type AuthConfig = AuthKitConfig | ApiKeyConfig;
|
|
65
112
|
interface AuthKitConfig {
|
|
66
113
|
mode: 'authkit';
|
|
67
114
|
clientId: string;
|
|
@@ -72,25 +119,13 @@ interface AuthKitConfig {
|
|
|
72
119
|
/** Keep refresh tokens in localStorage. Defaults to false. */
|
|
73
120
|
devMode?: boolean;
|
|
74
121
|
}
|
|
75
|
-
/** OAuth config for "Sign in with Elevasis" via WorkOS Connect. */
|
|
76
|
-
interface OAuthConfig {
|
|
77
|
-
mode: 'oauth';
|
|
78
|
-
clientId: string;
|
|
79
|
-
redirectUri: string;
|
|
80
|
-
/** Persist tokens in sessionStorage. Default is memory-only. */
|
|
81
|
-
tokenStorage?: 'session';
|
|
82
|
-
/** Pre-select organization in WorkOS flow. */
|
|
83
|
-
organizationId?: string;
|
|
84
|
-
/** Auth provider for the authorize request. Defaults to 'authkit' (hosted login UI). */
|
|
85
|
-
provider?: 'authkit' | 'GoogleOAuth' | 'MicrosoftOAuth' | 'GitHubOAuth' | 'AppleOAuth';
|
|
86
|
-
}
|
|
87
122
|
/** Deferred -- will throw at runtime. */
|
|
88
123
|
interface ApiKeyConfig {
|
|
89
124
|
mode: 'apiKey';
|
|
90
125
|
key: string;
|
|
91
126
|
}
|
|
92
127
|
interface ElevasisCoreProviderProps {
|
|
93
|
-
/** Auth configuration. Supports 'authkit'
|
|
128
|
+
/** Auth configuration. Supports 'authkit' mode. */
|
|
94
129
|
auth: AuthConfig;
|
|
95
130
|
/**
|
|
96
131
|
* Elevasis core theme configuration (Mantine-free).
|
|
@@ -99,16 +134,18 @@ interface ElevasisCoreProviderProps {
|
|
|
99
134
|
*/
|
|
100
135
|
theme?: ElevasisCoreThemeConfig;
|
|
101
136
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
137
|
+
* @deprecated Organization ID is now resolved automatically via OrganizationProvider.
|
|
138
|
+
* This prop is accepted for backwards compatibility during migration but is no longer
|
|
139
|
+
* used when the full provider stack is active (apiUrl provided).
|
|
105
140
|
*/
|
|
106
141
|
organizationId?: string | null;
|
|
107
142
|
/** Custom QueryClient. If omitted, a default is created internally. */
|
|
108
143
|
queryClient?: QueryClient;
|
|
109
144
|
/**
|
|
110
145
|
* API base URL (e.g., 'https://api.elevasis.com' or 'http://localhost:5170').
|
|
111
|
-
* When provided, ElevasisCoreProvider composes
|
|
146
|
+
* When provided, ElevasisCoreProvider composes the full provider stack:
|
|
147
|
+
* ApiClientProvider + ElevasisServiceProvider + ProfileProvider +
|
|
148
|
+
* OrganizationProvider + NotificationProvider + InitializationProvider.
|
|
112
149
|
* When omitted, no service context is provided (theme-only mode).
|
|
113
150
|
*/
|
|
114
151
|
apiUrl?: string;
|
|
@@ -118,11 +155,19 @@ interface ElevasisCoreProviderProps {
|
|
|
118
155
|
*/
|
|
119
156
|
onError?: (endpoint: string, error: Error, details?: ApiErrorDetails) => void;
|
|
120
157
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* Command-center passes `!!currentMembership` for its stricter readiness requirement.
|
|
158
|
+
* @deprecated Organization readiness is now managed internally by OrganizationProvider.
|
|
159
|
+
* Accepted for backwards compatibility but ignored when apiUrl is provided.
|
|
124
160
|
*/
|
|
125
161
|
isOrganizationReady?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Notification adapter for displaying success/error/info messages.
|
|
164
|
+
* When provided, wraps the subtree in a NotificationProvider with this adapter.
|
|
165
|
+
* When omitted, the console fallback adapter is used automatically.
|
|
166
|
+
*
|
|
167
|
+
* ElevasisUIProvider (Mantine variant) passes mantineNotificationAdapter here automatically.
|
|
168
|
+
* Headless/SDK consumers can pass a custom adapter or omit for console output.
|
|
169
|
+
*/
|
|
170
|
+
notifications?: NotificationAdapter;
|
|
126
171
|
/**
|
|
127
172
|
* Whether to inject CSS variables, `data-elevasis-scheme` attribute, and font links.
|
|
128
173
|
* Set to `false` when the consumer has its own complete design system and only
|
|
@@ -157,21 +202,36 @@ interface ElevasisServiceProviderProps {
|
|
|
157
202
|
* variables, set `data-elevasis-scheme`, or load fonts. Consumers that need
|
|
158
203
|
* Elevasis theming should use `ElevasisProvider` (Mantine) instead.
|
|
159
204
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
205
|
+
* When `apiUrl` is provided, composes the full provider stack:
|
|
206
|
+
* QueryClientProvider -> AuthProvider -> ApiClientProvider ->
|
|
207
|
+
* ElevasisServiceProvider -> ProfileProvider -> OrganizationProvider ->
|
|
208
|
+
* NotificationProvider -> InitializationProvider
|
|
209
|
+
*
|
|
210
|
+
* The `notifications` prop wires a custom adapter (e.g. mantineNotificationAdapter)
|
|
211
|
+
* into the NotificationProvider. When omitted, the console fallback is used.
|
|
162
212
|
*
|
|
163
213
|
* @example Headless SDK consumer
|
|
164
214
|
* ```tsx
|
|
165
215
|
* <ElevasisCoreProvider
|
|
166
216
|
* auth={{ mode: 'authkit', clientId: '...', redirectUri: '/' }}
|
|
167
|
-
* theme={{ colorScheme: 'dark', preset: 'default' }}
|
|
168
217
|
* apiUrl="https://api.elevasis.com"
|
|
169
218
|
* >
|
|
170
219
|
* <Dashboard />
|
|
171
220
|
* </ElevasisCoreProvider>
|
|
172
221
|
* ```
|
|
222
|
+
*
|
|
223
|
+
* @example With custom notification adapter
|
|
224
|
+
* ```tsx
|
|
225
|
+
* <ElevasisCoreProvider
|
|
226
|
+
* auth={{ mode: 'authkit', clientId: '...', redirectUri: '/' }}
|
|
227
|
+
* apiUrl="https://api.elevasis.com"
|
|
228
|
+
* notifications={myNotificationAdapter}
|
|
229
|
+
* >
|
|
230
|
+
* <Dashboard />
|
|
231
|
+
* </ElevasisCoreProvider>
|
|
232
|
+
* ```
|
|
173
233
|
*/
|
|
174
|
-
declare function ElevasisCoreProvider({ auth,
|
|
234
|
+
declare function ElevasisCoreProvider({ auth, queryClient, apiUrl, onError, notifications, children }: ElevasisCoreProviderProps): react_jsx_runtime.JSX.Element;
|
|
175
235
|
|
|
176
236
|
/**
|
|
177
237
|
* Hook to access the ElevasisServiceProvider context.
|
|
@@ -202,5 +262,5 @@ declare function useElevasisServices(): ElevasisServiceContextValue;
|
|
|
202
262
|
*/
|
|
203
263
|
declare function ElevasisServiceProvider({ apiRequest, organizationId, isReady, children }: ElevasisServiceProviderProps): react_jsx_runtime.JSX.Element;
|
|
204
264
|
|
|
205
|
-
export { ElevasisCoreProvider, ElevasisServiceProvider, useElevasisServices };
|
|
206
|
-
export type { ApiKeyConfig, AuthConfig, AuthKitConfig, ElevasisCoreProviderProps, ElevasisCoreThemeConfig, ElevasisServiceContextValue, ElevasisServiceProviderProps, ElevasisTokenOverrides,
|
|
265
|
+
export { ElevasisCoreProvider, ElevasisServiceProvider, NotificationProvider, useElevasisServices, useNotificationAdapter };
|
|
266
|
+
export type { ApiKeyConfig, AuthConfig, AuthKitConfig, ElevasisCoreProviderProps, ElevasisCoreThemeConfig, ElevasisServiceContextValue, ElevasisServiceProviderProps, ElevasisTokenOverrides, NotificationAdapter, WithSchemes };
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
export { ElevasisCoreProvider } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { ElevasisCoreProvider } from '../chunk-72HOBFMP.js';
|
|
2
|
+
import '../chunk-UMXDDEAG.js';
|
|
3
|
+
import '../chunk-XLV6LYN2.js';
|
|
4
|
+
export { NotificationProvider, useNotificationAdapter } from '../chunk-TIRMFDM4.js';
|
|
5
|
+
import '../chunk-JVAZHVNV.js';
|
|
6
|
+
import '../chunk-4VGWQ5AN.js';
|
|
7
|
+
import '../chunk-NEK6JKPW.js';
|
|
8
|
+
import '../chunk-L2CM2CUA.js';
|
|
9
|
+
import '../chunk-DD3CCMCZ.js';
|
|
3
10
|
export { ElevasisServiceProvider, useElevasisServices } from '../chunk-KA7LO7U5.js';
|
|
4
|
-
import '../chunk-7AI5ZYJ4.js';
|
|
5
|
-
import '../chunk-QSVZP2NU.js';
|
|
6
11
|
import '../chunk-7PLEQFHO.js';
|
package/dist/supabase/index.js
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
function getSupabaseConfig() {
|
|
6
|
-
const url = import.meta.env?.VITE_SUPABASE_URL;
|
|
7
|
-
const anonKey = import.meta.env?.VITE_SUPABASE_ANON_KEY;
|
|
8
|
-
if (!url || !anonKey) {
|
|
9
|
-
throw new Error("Missing Supabase environment variables (VITE_SUPABASE_URL, VITE_SUPABASE_ANON_KEY)");
|
|
10
|
-
}
|
|
11
|
-
return { url, anonKey };
|
|
12
|
-
}
|
|
13
|
-
var _supabase = null;
|
|
14
|
-
function getSupabaseClient() {
|
|
15
|
-
if (!_supabase) {
|
|
16
|
-
const { url, anonKey } = getSupabaseConfig();
|
|
17
|
-
_supabase = createClient(url, anonKey);
|
|
18
|
-
}
|
|
19
|
-
return _supabase;
|
|
20
|
-
}
|
|
21
|
-
var useSupabase = () => {
|
|
22
|
-
const { getAccessToken } = useAuthContext();
|
|
23
|
-
const { url, anonKey } = getSupabaseConfig();
|
|
24
|
-
return useMemo(
|
|
25
|
-
() => createClient(url, anonKey, {
|
|
26
|
-
global: {
|
|
27
|
-
headers: {
|
|
28
|
-
// Additional headers if needed
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
accessToken: async () => {
|
|
32
|
-
try {
|
|
33
|
-
const token = await getAccessToken();
|
|
34
|
-
if (!token) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
return token;
|
|
38
|
-
} catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
[getAccessToken, url, anonKey]
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { getSupabaseClient, useSupabase };
|
|
1
|
+
export { getSupabaseClient, useSupabase } from '../chunk-JGJSZ3UE.js';
|
|
2
|
+
import '../chunk-7PLEQFHO.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { formatDate, getResourceColor, getResourceIcon, showApiErrorNotification, showErrorNotification, showInfoNotification, showSuccessNotification, showWarningNotification, validateEmail } from '../chunk-JVAZHVNV.js';
|
|
2
|
+
export { APIClientError, formatErrorMessage, getErrorInfo, getErrorTitle, isAPIClientError } from '../chunk-4VGWQ5AN.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elevasis/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "UI components and platform-aware hooks for building custom frontends on the Elevasis platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,6 +26,18 @@
|
|
|
26
26
|
"./sse": {
|
|
27
27
|
"types": "./dist/sse/index.d.ts",
|
|
28
28
|
"import": "./dist/sse/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./initialization": {
|
|
31
|
+
"types": "./dist/initialization/index.d.ts",
|
|
32
|
+
"import": "./dist/initialization/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./profile": {
|
|
35
|
+
"types": "./dist/profile/index.d.ts",
|
|
36
|
+
"import": "./dist/profile/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./organization": {
|
|
39
|
+
"types": "./dist/organization/index.d.ts",
|
|
40
|
+
"import": "./dist/organization/index.js"
|
|
29
41
|
}
|
|
30
42
|
},
|
|
31
43
|
"publishConfig": {
|
|
@@ -33,7 +45,8 @@
|
|
|
33
45
|
"peerDependencies": {
|
|
34
46
|
"react": "^19.2.0",
|
|
35
47
|
"react-dom": "^19.2.0",
|
|
36
|
-
"@tanstack/react-query": "^5.76.2"
|
|
48
|
+
"@tanstack/react-query": "^5.76.2",
|
|
49
|
+
"@tanstack/react-router": "^1.131.28"
|
|
37
50
|
}
|
|
38
51
|
},
|
|
39
52
|
"peerDependencies": {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { WorkOSAuthBridge } from './chunk-NIAVTSMB.js';
|
|
2
|
-
import './chunk-7PLEQFHO.js';
|
|
3
|
-
import { AuthKitProvider } from '@workos-inc/authkit-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(WorkOSAuthBridge, { children })
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { CoreAuthKitInner };
|
package/dist/chunk-GDV44UWF.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { APIClientError } from './chunk-7AI5ZYJ4.js';
|
|
2
|
-
import { createContext, useContext, useMemo, useCallback } from 'react';
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
var ApiClientContext = createContext(null);
|
|
6
|
-
function useApiClientContext() {
|
|
7
|
-
const context = useContext(ApiClientContext);
|
|
8
|
-
if (!context) {
|
|
9
|
-
throw new Error("useApiClient must be used within ApiClientProvider");
|
|
10
|
-
}
|
|
11
|
-
return context;
|
|
12
|
-
}
|
|
13
|
-
function ApiClientProvider({
|
|
14
|
-
children,
|
|
15
|
-
getAccessToken,
|
|
16
|
-
organizationId,
|
|
17
|
-
isOrganizationReady,
|
|
18
|
-
onError
|
|
19
|
-
}) {
|
|
20
|
-
const value = useMemo(
|
|
21
|
-
() => ({
|
|
22
|
-
getAccessToken,
|
|
23
|
-
organizationId,
|
|
24
|
-
isOrganizationReady,
|
|
25
|
-
onError
|
|
26
|
-
}),
|
|
27
|
-
[getAccessToken, organizationId, isOrganizationReady, onError]
|
|
28
|
-
);
|
|
29
|
-
return /* @__PURE__ */ jsx(ApiClientContext.Provider, { value, children });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ../core/src/platform/constants/http.ts
|
|
33
|
-
var HTTP_HEADERS = {
|
|
34
|
-
/**
|
|
35
|
-
* Organization context header
|
|
36
|
-
* Note: Node.js normalizes all headers to lowercase, so we use lowercase consistently
|
|
37
|
-
*/
|
|
38
|
-
WORKOS_ORGANIZATION_ID: "workos-organization-id",
|
|
39
|
-
AGENT_ORGANIZATION: "x-agent-organization",
|
|
40
|
-
AGENT_MODE: "x-agent-mode"
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/api/hooks/useApiClient.ts
|
|
44
|
-
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
45
|
-
function createUseApiClient(useOrganizations, apiUrl) {
|
|
46
|
-
return function useApiClient() {
|
|
47
|
-
const { getAccessToken, organizationId, isOrganizationReady, onError } = useApiClientContext();
|
|
48
|
-
const { isInitializing, isOrgRefreshing } = useOrganizations();
|
|
49
|
-
const handleResponseError = useCallback(
|
|
50
|
-
async (endpoint, response, options) => {
|
|
51
|
-
const errorData = await response.json().catch(() => ({
|
|
52
|
-
error: `HTTP ${response.status}`,
|
|
53
|
-
code: "INTERNAL_SERVER_ERROR"
|
|
54
|
-
}));
|
|
55
|
-
if (response.status >= 500 && onError) {
|
|
56
|
-
onError(endpoint, new Error(errorData.error), {
|
|
57
|
-
method: options.method || "GET",
|
|
58
|
-
statusCode: response.status,
|
|
59
|
-
requestId: errorData.requestId
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
throw new APIClientError(errorData.error, errorData.code, response.status, errorData.requestId, errorData.fields, errorData.retryAfter);
|
|
63
|
-
},
|
|
64
|
-
[onError]
|
|
65
|
-
);
|
|
66
|
-
const apiRequest = useCallback(
|
|
67
|
-
async (endpoint, options = {}) => {
|
|
68
|
-
try {
|
|
69
|
-
const token = await getAccessToken();
|
|
70
|
-
const headers = {
|
|
71
|
-
...options.body ? { "Content-Type": "application/json" } : {},
|
|
72
|
-
...token ? { Authorization: `Bearer ${token}` } : {},
|
|
73
|
-
...organizationId && { [HTTP_HEADERS.WORKOS_ORGANIZATION_ID]: organizationId },
|
|
74
|
-
...options.headers
|
|
75
|
-
};
|
|
76
|
-
const timeoutSignal = AbortSignal.timeout(DEFAULT_TIMEOUT_MS);
|
|
77
|
-
const signal = options.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal;
|
|
78
|
-
const response = await fetch(`${apiUrl}/api${endpoint}`, {
|
|
79
|
-
...options,
|
|
80
|
-
headers,
|
|
81
|
-
signal
|
|
82
|
-
});
|
|
83
|
-
if (!response.ok) {
|
|
84
|
-
await handleResponseError(endpoint, response, options);
|
|
85
|
-
}
|
|
86
|
-
if (response.status === 204) {
|
|
87
|
-
return void 0;
|
|
88
|
-
}
|
|
89
|
-
const responseData = await response.json();
|
|
90
|
-
return responseData;
|
|
91
|
-
} catch (error) {
|
|
92
|
-
if (error instanceof Error && error.message.includes("No access token")) {
|
|
93
|
-
const headers = {
|
|
94
|
-
...options.body ? { "Content-Type": "application/json" } : {},
|
|
95
|
-
...options.headers
|
|
96
|
-
};
|
|
97
|
-
const fallbackTimeoutSignal = AbortSignal.timeout(DEFAULT_TIMEOUT_MS);
|
|
98
|
-
const fallbackSignal = options.signal ? AbortSignal.any([options.signal, fallbackTimeoutSignal]) : fallbackTimeoutSignal;
|
|
99
|
-
const response = await fetch(`${apiUrl}/api${endpoint}`, {
|
|
100
|
-
...options,
|
|
101
|
-
headers,
|
|
102
|
-
signal: fallbackSignal
|
|
103
|
-
});
|
|
104
|
-
if (!response.ok) {
|
|
105
|
-
await handleResponseError(endpoint, response, options);
|
|
106
|
-
}
|
|
107
|
-
if (response.status === 204) {
|
|
108
|
-
return void 0;
|
|
109
|
-
}
|
|
110
|
-
return response.json();
|
|
111
|
-
}
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
[getAccessToken, organizationId, handleResponseError, apiUrl]
|
|
116
|
-
);
|
|
117
|
-
const deferredApiRequest = useCallback(
|
|
118
|
-
async (endpoint, options = {}) => {
|
|
119
|
-
if (isInitializing || isOrgRefreshing) {
|
|
120
|
-
throw new Error("Organization context is still initializing. Please wait.");
|
|
121
|
-
}
|
|
122
|
-
if (!isOrganizationReady) {
|
|
123
|
-
throw new Error("No organization selected. Please select an organization.");
|
|
124
|
-
}
|
|
125
|
-
return apiRequest(endpoint, options);
|
|
126
|
-
},
|
|
127
|
-
[apiRequest, isInitializing, isOrgRefreshing, isOrganizationReady]
|
|
128
|
-
);
|
|
129
|
-
return {
|
|
130
|
-
apiRequest,
|
|
131
|
-
deferredApiRequest,
|
|
132
|
-
isOrganizationReady,
|
|
133
|
-
isInitializing: isInitializing || isOrgRefreshing
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export { ApiClientProvider, createUseApiClient, useApiClientContext };
|
package/dist/chunk-HBRMWW6V.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { useAuthContext } from './chunk-7PLEQFHO.js';
|
|
2
|
-
import { useRef, useCallback, useEffect } from 'react';
|
|
3
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
|
|
5
|
-
function useStableAccessToken() {
|
|
6
|
-
const { getAccessToken } = useAuthContext();
|
|
7
|
-
const getAccessTokenRef = useRef(getAccessToken);
|
|
8
|
-
getAccessTokenRef.current = getAccessToken;
|
|
9
|
-
return useCallback(() => {
|
|
10
|
-
return getAccessTokenRef.current();
|
|
11
|
-
}, []);
|
|
12
|
-
}
|
|
13
|
-
function useSessionCheck() {
|
|
14
|
-
const { user } = useAuthContext();
|
|
15
|
-
const queryClient = useQueryClient();
|
|
16
|
-
const isCheckingRef = useRef(false);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const handleVisibilityChange = async () => {
|
|
19
|
-
if (isCheckingRef.current || document.visibilityState !== "visible") {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
isCheckingRef.current = true;
|
|
23
|
-
try {
|
|
24
|
-
if (!user) {
|
|
25
|
-
window.location.replace("/login");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
await queryClient.cancelQueries();
|
|
29
|
-
queryClient.invalidateQueries();
|
|
30
|
-
} finally {
|
|
31
|
-
isCheckingRef.current = false;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
35
|
-
window.addEventListener("focus", handleVisibilityChange);
|
|
36
|
-
return () => {
|
|
37
|
-
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
38
|
-
window.removeEventListener("focus", handleVisibilityChange);
|
|
39
|
-
};
|
|
40
|
-
}, [user, queryClient]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { useSessionCheck, useStableAccessToken };
|
package/dist/chunk-NIAVTSMB.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AuthProvider } from './chunk-7PLEQFHO.js';
|
|
2
|
-
import { useAuth } from '@workos-inc/authkit-react';
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
|
|
6
|
-
function WorkOSAuthBridge({ children }) {
|
|
7
|
-
const { user, isLoading, getAccessToken, organizationId } = useAuth();
|
|
8
|
-
const adaptedUser = useMemo(() => user ? { id: user.id } : null, [user?.id]);
|
|
9
|
-
const value = useMemo(
|
|
10
|
-
() => ({
|
|
11
|
-
user: adaptedUser,
|
|
12
|
-
isLoading,
|
|
13
|
-
getAccessToken,
|
|
14
|
-
organizationId: organizationId ?? null
|
|
15
|
-
}),
|
|
16
|
-
[adaptedUser, isLoading, getAccessToken, organizationId]
|
|
17
|
-
);
|
|
18
|
-
return /* @__PURE__ */ jsx(AuthProvider, { value, children });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { WorkOSAuthBridge };
|