@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.
Files changed (59) hide show
  1. package/dist/CoreAuthKitInner-3J4RVQO6.js +43 -0
  2. package/dist/api/index.d.ts +32 -18
  3. package/dist/api/index.js +4 -2
  4. package/dist/auth/context.d.ts +23 -5
  5. package/dist/auth/index.d.ts +119 -30
  6. package/dist/auth/index.js +6 -3
  7. package/dist/chunk-2JBWPFHF.js +108 -0
  8. package/dist/chunk-4VGWQ5AN.js +91 -0
  9. package/dist/chunk-72HOBFMP.js +87 -0
  10. package/dist/{chunk-WNWKOCGJ.js → chunk-A3MCANC6.js} +296 -2
  11. package/dist/{chunk-JKERRYVS.js → chunk-BLO4SISK.js} +7 -3
  12. package/dist/chunk-DD3CCMCZ.js +15 -0
  13. package/dist/chunk-FWZJH3TL.js +13 -0
  14. package/dist/{chunk-GEFB5YIR.js → chunk-JBFFCZI4.js} +1 -1
  15. package/dist/chunk-JGJSZ3UE.js +47 -0
  16. package/dist/{chunk-7AI5ZYJ4.js → chunk-JVAZHVNV.js} +2 -94
  17. package/dist/{chunk-ZGHDPDTF.js → chunk-JYSYHVLU.js} +3 -3
  18. package/dist/{chunk-5UWFGBFM.js → chunk-L2CM2CUA.js} +16 -4
  19. package/dist/chunk-NEK6JKPW.js +75 -0
  20. package/dist/{chunk-J3FALDQE.js → chunk-NXHL23JW.js} +7 -13
  21. package/dist/{chunk-OUHGHTE7.js → chunk-O3PY6B6E.js} +3 -2
  22. package/dist/{chunk-YULUKCS6.js → chunk-PVVQTENF.js} +1 -1
  23. package/dist/chunk-TIRMFDM4.js +33 -0
  24. package/dist/{chunk-PYL4XW6H.js → chunk-TMFCNFLW.js} +1 -1
  25. package/dist/{chunk-S66I2PYB.js → chunk-TN3PU2WK.js} +1 -1
  26. package/dist/chunk-TYV5NJV2.js +1 -0
  27. package/dist/{chunk-B64YDSAY.js → chunk-TZPAA4RC.js} +54 -97
  28. package/dist/chunk-UMXDDEAG.js +148 -0
  29. package/dist/chunk-XLV6LYN2.js +157 -0
  30. package/dist/components/command-queue/index.js +6 -4
  31. package/dist/components/index.js +9 -7
  32. package/dist/components/notifications/index.js +4 -3
  33. package/dist/display/index.js +3 -2
  34. package/dist/hooks/index.d.ts +2630 -3
  35. package/dist/hooks/index.js +9 -5
  36. package/dist/hooks/published.d.ts +2630 -3
  37. package/dist/hooks/published.js +7 -3
  38. package/dist/index.d.ts +759 -164
  39. package/dist/index.js +24 -18
  40. package/dist/initialization/index.d.ts +49 -1
  41. package/dist/initialization/index.js +5 -2
  42. package/dist/organization/index.d.ts +61 -2
  43. package/dist/organization/index.js +5 -2
  44. package/dist/profile/index.d.ts +30 -2
  45. package/dist/profile/index.js +2 -1
  46. package/dist/provider/index.d.ts +116 -43
  47. package/dist/provider/index.js +10 -6
  48. package/dist/provider/published.d.ts +88 -28
  49. package/dist/provider/published.js +9 -4
  50. package/dist/supabase/index.js +2 -47
  51. package/dist/utils/index.js +2 -1
  52. package/package.json +15 -2
  53. package/dist/CoreAuthKitInner-KM72EYJS.js +0 -19
  54. package/dist/chunk-GDV44UWF.js +0 -138
  55. package/dist/chunk-HBRMWW6V.js +0 -43
  56. package/dist/chunk-NIAVTSMB.js +0 -21
  57. package/dist/chunk-QSVZP2NU.js +0 -214
  58. package/dist/chunk-ZQVPUAGR.js +0 -89
  59. /package/dist/{chunk-Q47SPRY7.js → chunk-RNP5R5I3.js} +0 -0
@@ -1,214 +0,0 @@
1
- import { AuthProvider } from './chunk-7PLEQFHO.js';
2
- import { createContext, useContext, useState, useCallback, useEffect, useMemo } from 'react';
3
- import { jsx } from 'react/jsx-runtime';
4
-
5
- function generateRandomString(length) {
6
- const array = new Uint8Array(length);
7
- crypto.getRandomValues(array);
8
- return Array.from(array, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, length);
9
- }
10
- async function generateCodeChallenge(verifier) {
11
- const encoder = new TextEncoder();
12
- const data = encoder.encode(verifier);
13
- const digest = await crypto.subtle.digest("SHA-256", data);
14
- return btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
15
- }
16
- function generateState() {
17
- return generateRandomString(32);
18
- }
19
- var STORAGE_KEYS = {
20
- tokens: "elevasis_oauth_tokens",
21
- codeVerifier: "elevasis_oauth_code_verifier",
22
- state: "elevasis_oauth_state"
23
- };
24
- function saveToStorage(key, value) {
25
- try {
26
- sessionStorage.setItem(key, value);
27
- } catch {
28
- }
29
- }
30
- function loadFromStorage(key) {
31
- try {
32
- return sessionStorage.getItem(key);
33
- } catch {
34
- return null;
35
- }
36
- }
37
- function clearStorageKeys() {
38
- try {
39
- sessionStorage.removeItem(STORAGE_KEYS.tokens);
40
- sessionStorage.removeItem(STORAGE_KEYS.codeVerifier);
41
- sessionStorage.removeItem(STORAGE_KEYS.state);
42
- } catch {
43
- }
44
- }
45
- function loadStoredTokens() {
46
- const raw = loadFromStorage(STORAGE_KEYS.tokens);
47
- if (!raw) return null;
48
- try {
49
- const parsed = JSON.parse(raw);
50
- if (parsed.accessToken) return parsed;
51
- } catch {
52
- }
53
- return null;
54
- }
55
- function saveTokens(tokens) {
56
- saveToStorage(STORAGE_KEYS.tokens, JSON.stringify(tokens));
57
- }
58
- function decodeJwtPayload(token) {
59
- try {
60
- const parts = token.split(".");
61
- if (parts.length !== 3) return null;
62
- const payload = parts[1];
63
- const padded = payload.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - payload.length % 4) % 4);
64
- return JSON.parse(atob(padded));
65
- } catch {
66
- return null;
67
- }
68
- }
69
- function decodeUserFromJwt(token) {
70
- const payload = decodeJwtPayload(token);
71
- if (!payload) return null;
72
- const sub = payload.sub;
73
- if (sub) return { id: sub };
74
- return null;
75
- }
76
- function decodeOrgIdFromJwt(token) {
77
- const payload = decodeJwtPayload(token);
78
- if (!payload) return null;
79
- return payload.org_id ?? null;
80
- }
81
- var OAuthContext = createContext(null);
82
- function useOAuthContext() {
83
- const ctx = useContext(OAuthContext);
84
- if (!ctx) {
85
- throw new Error("useOAuthContext must be used within an OAuthProvider.");
86
- }
87
- return ctx;
88
- }
89
- function OAuthProvider({ config, children }) {
90
- const useStorage = config.tokenStorage === "session";
91
- const [state, setState] = useState(() => {
92
- const storedTokens = useStorage ? loadStoredTokens() : null;
93
- return {
94
- tokens: storedTokens,
95
- user: storedTokens ? decodeUserFromJwt(storedTokens.accessToken) : null,
96
- organizationId: storedTokens ? decodeOrgIdFromJwt(storedTokens.accessToken) : config.organizationId ?? null,
97
- isLoading: false,
98
- error: null
99
- };
100
- });
101
- const exchangeCodeForTokens = useCallback(
102
- async (code, codeVerifier) => {
103
- setState((prev) => ({ ...prev, isLoading: true, error: null }));
104
- try {
105
- const response = await fetch("https://api.workos.com/user_management/authenticate", {
106
- method: "POST",
107
- headers: { "Content-Type": "application/json" },
108
- body: JSON.stringify({
109
- client_id: config.clientId,
110
- code_verifier: codeVerifier,
111
- grant_type: "authorization_code",
112
- code
113
- })
114
- });
115
- if (!response.ok) {
116
- const text = await response.text();
117
- throw new Error(`Token exchange failed (${response.status}): ${text}`);
118
- }
119
- const data = await response.json();
120
- const tokens = {
121
- accessToken: data.access_token,
122
- refreshToken: data.refresh_token
123
- };
124
- if (useStorage) saveTokens(tokens);
125
- setState({
126
- tokens,
127
- user: decodeUserFromJwt(tokens.accessToken),
128
- organizationId: decodeOrgIdFromJwt(tokens.accessToken) ?? config.organizationId ?? null,
129
- isLoading: false,
130
- error: null
131
- });
132
- } catch (err) {
133
- setState((prev) => ({
134
- ...prev,
135
- isLoading: false,
136
- error: err instanceof Error ? err.message : "Token exchange failed"
137
- }));
138
- }
139
- },
140
- [config.clientId, config.organizationId, useStorage]
141
- );
142
- const initiateOAuthFlow = useCallback(() => {
143
- const start = async () => {
144
- const verifier = generateRandomString(64);
145
- const challenge = await generateCodeChallenge(verifier);
146
- const oauthState = generateState();
147
- saveToStorage(STORAGE_KEYS.codeVerifier, verifier);
148
- saveToStorage(STORAGE_KEYS.state, oauthState);
149
- const params = new URLSearchParams({
150
- client_id: config.clientId,
151
- redirect_uri: config.redirectUri,
152
- response_type: "code",
153
- provider: config.provider ?? "authkit",
154
- code_challenge: challenge,
155
- code_challenge_method: "S256",
156
- state: oauthState
157
- });
158
- if (config.organizationId) {
159
- params.set("organization_id", config.organizationId);
160
- }
161
- window.location.href = `https://api.workos.com/user_management/authorize?${params.toString()}`;
162
- };
163
- void start();
164
- }, [config.clientId, config.redirectUri, config.organizationId, config.provider]);
165
- useEffect(() => {
166
- const url = new URL(window.location.href);
167
- const code = url.searchParams.get("code");
168
- const returnedState = url.searchParams.get("state");
169
- if (!code) return;
170
- const storedState = loadFromStorage(STORAGE_KEYS.state);
171
- if (storedState && returnedState !== storedState) {
172
- setState((prev) => ({ ...prev, error: "OAuth state mismatch" }));
173
- return;
174
- }
175
- const codeVerifier = loadFromStorage(STORAGE_KEYS.codeVerifier);
176
- if (!codeVerifier) {
177
- setState((prev) => ({ ...prev, error: "Missing code verifier" }));
178
- return;
179
- }
180
- url.searchParams.delete("code");
181
- url.searchParams.delete("state");
182
- window.history.replaceState({}, "", url.pathname + url.search);
183
- clearStorageKeys();
184
- void exchangeCodeForTokens(code, codeVerifier);
185
- }, [exchangeCodeForTokens]);
186
- const getAccessToken = useCallback(async () => {
187
- if (state.tokens?.accessToken) return state.tokens.accessToken;
188
- initiateOAuthFlow();
189
- throw new Error("No access token available. Redirecting to login.");
190
- }, [state.tokens, initiateOAuthFlow]);
191
- const value = useMemo(
192
- () => ({
193
- user: state.user,
194
- isLoading: state.isLoading,
195
- organizationId: state.organizationId,
196
- getAccessToken,
197
- error: state.error,
198
- initiateOAuthFlow
199
- }),
200
- [state.user, state.isLoading, state.organizationId, state.error, getAccessToken, initiateOAuthFlow]
201
- );
202
- const authValue = useMemo(
203
- () => ({
204
- user: state.user,
205
- isLoading: state.isLoading,
206
- getAccessToken,
207
- organizationId: state.organizationId
208
- }),
209
- [state.user, state.isLoading, getAccessToken, state.organizationId]
210
- );
211
- return /* @__PURE__ */ jsx(OAuthContext.Provider, { value, children: /* @__PURE__ */ jsx(AuthProvider, { value: authValue, children }) });
212
- }
213
-
214
- export { OAuthProvider, useOAuthContext };
@@ -1,89 +0,0 @@
1
- import { ApiClientProvider, createUseApiClient } from './chunk-GDV44UWF.js';
2
- import { ElevasisServiceProvider } from './chunk-KA7LO7U5.js';
3
- import { OAuthProvider } from './chunk-QSVZP2NU.js';
4
- import { useAuthContext } from './chunk-7PLEQFHO.js';
5
- import { lazy, Suspense, useRef } from 'react';
6
- import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
7
- import { jsx } from 'react/jsx-runtime';
8
-
9
- var LazyCoreAuthKitInner = lazy(() => import('./CoreAuthKitInner-KM72EYJS.js').then((m) => ({ default: m.CoreAuthKitInner })));
10
- var defaultQueryClient = null;
11
- function getDefaultQueryClient() {
12
- if (!defaultQueryClient) {
13
- defaultQueryClient = new QueryClient({
14
- defaultOptions: { queries: { retry: 1 } }
15
- });
16
- }
17
- return defaultQueryClient;
18
- }
19
- var defaultUseOrganizations = () => ({ isInitializing: false, isOrgRefreshing: false });
20
- function ElevasisCoreProvider({
21
- auth,
22
- organizationId = null,
23
- queryClient,
24
- apiUrl,
25
- onError,
26
- isOrganizationReady,
27
- children
28
- }) {
29
- if (auth.mode === "apiKey") {
30
- throw new Error(
31
- `ElevasisCoreProvider: auth mode 'apiKey' is not yet implemented. Only 'authkit' and 'oauth' modes are supported.`
32
- );
33
- }
34
- const resolvedQueryClient = queryClient ?? getDefaultQueryClient();
35
- const content = apiUrl ? /* @__PURE__ */ jsx(
36
- CoreServiceBridge,
37
- {
38
- apiUrl,
39
- organizationId,
40
- isOrganizationReady,
41
- onError,
42
- children
43
- }
44
- ) : children;
45
- const AuthInner = auth.mode === "authkit" ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(LazyCoreAuthKitInner, { auth, children: content }) }) : /* @__PURE__ */ jsx(CoreOAuthInner, { auth, children: content });
46
- return /* @__PURE__ */ jsx(QueryClientProvider, { client: resolvedQueryClient, children: AuthInner });
47
- }
48
- function CoreOAuthInner({ auth, children }) {
49
- return /* @__PURE__ */ jsx(OAuthProvider, { config: auth, children });
50
- }
51
- function CoreServiceBridge({
52
- apiUrl,
53
- organizationId,
54
- isOrganizationReady,
55
- onError,
56
- children
57
- }) {
58
- const { getAccessToken } = useAuthContext();
59
- return /* @__PURE__ */ jsx(
60
- ApiClientProvider,
61
- {
62
- getAccessToken,
63
- organizationId,
64
- isOrganizationReady: isOrganizationReady ?? !!organizationId,
65
- onError,
66
- children: /* @__PURE__ */ jsx(CoreServiceBridgeInner, { apiUrl, organizationId, isOrganizationReady, children })
67
- }
68
- );
69
- }
70
- function CoreServiceBridgeInner({
71
- apiUrl,
72
- organizationId,
73
- isOrganizationReady,
74
- children
75
- }) {
76
- const useApiClient = useRef(createUseApiClient(defaultUseOrganizations, apiUrl)).current;
77
- const { apiRequest } = useApiClient();
78
- return /* @__PURE__ */ jsx(
79
- ElevasisServiceProvider,
80
- {
81
- apiRequest,
82
- organizationId,
83
- isReady: isOrganizationReady ?? !!organizationId,
84
- children
85
- }
86
- );
87
- }
88
-
89
- export { ElevasisCoreProvider };
File without changes