@athenaintel/react 0.9.19 → 0.9.20

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/auth.d.ts ADDED
@@ -0,0 +1,240 @@
1
+ import { Context } from 'react';
2
+ import { JSX } from 'react/jsx-runtime';
3
+ import { ReactNode } from 'react';
4
+
5
+ /**
6
+ * Internal context used by `AthenaAuthProvider` to share auth state.
7
+ * Consumed by `useAthenaAuth()` and automatically by `AthenaProvider`.
8
+ */
9
+ export declare const AthenaAuthContext: Context<AthenaAuthState | null>;
10
+
11
+ /**
12
+ * Wraps your app with Athena authentication powered by PropelAuth.
13
+ *
14
+ * Place this **above** `<AthenaProvider>` in the component tree.
15
+ * When present, `AthenaProvider` will automatically use the access token
16
+ * from this provider — no need to pass `token` or `apiKey` manually.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * import { AthenaAuthProvider } from '@athenaintel/react/auth';
21
+ * import { AthenaProvider, AthenaChat } from '@athenaintel/react';
22
+ *
23
+ * function App() {
24
+ * return (
25
+ * <AthenaAuthProvider authUrl="https://auth.yourdomain.com">
26
+ * <AthenaProvider>
27
+ * <AthenaChat />
28
+ * </AthenaProvider>
29
+ * </AthenaAuthProvider>
30
+ * );
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function AthenaAuthProvider({ children, authUrl, postLoginRedirectUrl, displayWhileLoading, }: AthenaAuthProviderProps): JSX.Element;
35
+
36
+ export declare interface AthenaAuthProviderProps {
37
+ children: ReactNode;
38
+ /**
39
+ * Your PropelAuth auth URL (e.g. `https://auth.yourdomain.com`).
40
+ * Found in the PropelAuth dashboard under Frontend Integration.
41
+ */
42
+ authUrl: string;
43
+ /**
44
+ * Where to redirect after a successful login.
45
+ * Defaults to the current page URL.
46
+ */
47
+ postLoginRedirectUrl?: string;
48
+ /**
49
+ * Custom element displayed while the auth state is loading.
50
+ * Defaults to `null` (renders nothing).
51
+ */
52
+ displayWhileLoading?: ReactNode;
53
+ }
54
+
55
+ /**
56
+ * Auth state exposed by `useAthenaAuth()`.
57
+ */
58
+ export declare interface AthenaAuthState {
59
+ /** Whether the user is currently logged in. */
60
+ isLoggedIn: boolean;
61
+ /** Whether the auth state is still loading. */
62
+ isLoading: boolean;
63
+ /** The authenticated user, or `null` when not logged in. */
64
+ user: AthenaUser | null;
65
+ /** The current access token, or `null` when not logged in. */
66
+ accessToken: string | null;
67
+ /** Organizations the user belongs to. */
68
+ orgs: AthenaOrg[];
69
+ /** Log the user out. Redirects to the login page by default. */
70
+ logout: (redirectOnLogout?: boolean) => Promise<void>;
71
+ }
72
+
73
+ /**
74
+ * Athena organization membership.
75
+ */
76
+ export declare interface AthenaOrg {
77
+ orgId: string;
78
+ orgName: string;
79
+ urlSafeOrgName: string;
80
+ }
81
+
82
+ /**
83
+ * Organization membership returned by the SSO endpoint.
84
+ */
85
+ export declare interface AthenaSSOOrgInfo {
86
+ orgId: string;
87
+ orgName: string;
88
+ urlSafeOrgName: string;
89
+ }
90
+
91
+ /**
92
+ * Wraps your app with Athena authentication powered by an external SSO
93
+ * identity provider (e.g. Microsoft Entra / Azure AD, Okta, etc.).
94
+ *
95
+ * The SSO login flow is handled entirely by your backend. This provider
96
+ * verifies the session by fetching `ssoUserInfoUrl` and exposes the
97
+ * same `AthenaAuthState` context that `AthenaAuthProvider` (PropelAuth)
98
+ * provides, so downstream components like `<AthenaProvider>` and
99
+ * `useAthenaAuth()` work identically.
100
+ *
101
+ * Place this **above** `<AthenaProvider>` in the component tree.
102
+ *
103
+ * @example
104
+ * ```tsx
105
+ * import { AthenaSSOProvider } from '@athenaintel/react/auth';
106
+ * import { AthenaProvider, AthenaChat } from '@athenaintel/react';
107
+ *
108
+ * function App() {
109
+ * return (
110
+ * <AthenaSSOProvider
111
+ * ssoUserInfoUrl="https://api.yourdomain.com/api/sso/userinfo"
112
+ * ssoLoginUrl="https://api.yourdomain.com/api/sso/initiate"
113
+ * >
114
+ * <AthenaProvider>
115
+ * <AthenaChat />
116
+ * </AthenaProvider>
117
+ * </AthenaSSOProvider>
118
+ * );
119
+ * }
120
+ * ```
121
+ */
122
+ export declare function AthenaSSOProvider({ children, ssoBaseUrl, ssoUserInfoUrl, ssoLoginUrl, ssoLogoutUrl, displayWhileLoading, displayOnError, revalidateOnWindowFocus, }: AthenaSSOProviderProps): JSX.Element | null;
123
+
124
+ export declare interface AthenaSSOProviderProps {
125
+ children: ReactNode;
126
+ /**
127
+ * Base URL used to resolve the Athena SSO endpoints.
128
+ *
129
+ * When omitted, the provider defaults to same-origin relative paths:
130
+ * `/api/sso/userinfo`, `/api/sso/initiate`, and `/api/sso/logout`.
131
+ *
132
+ * Use this when your frontend and backend live on different origins
133
+ * (for example `https://app.example.com` + `https://api.example.com`).
134
+ */
135
+ ssoBaseUrl?: string;
136
+ /**
137
+ * Optional override for the SSO user-info endpoint that returns the
138
+ * authenticated user's data and access token.
139
+ *
140
+ * The endpoint must return JSON matching `AthenaSSOUserInfo`:
141
+ * ```json
142
+ * {
143
+ * "user": { "user_id": "…", "email": "…", … },
144
+ * "orgMemberInfos": [{ "orgId": "…", "orgName": "…", "urlSafeOrgName": "…" }],
145
+ * "accessToken": "…"
146
+ * }
147
+ * ```
148
+ *
149
+ * The request is sent with `credentials: 'include'` so that
150
+ * session cookies are forwarded automatically.
151
+ */
152
+ ssoUserInfoUrl?: string;
153
+ /**
154
+ * Optional override for the URL to redirect the user to when no valid
155
+ * SSO session exists.
156
+ * This is typically the SSO initiation endpoint on your backend
157
+ * (e.g. `https://api.yourdomain.com/api/sso/initiate`).
158
+ */
159
+ ssoLoginUrl?: string;
160
+ /**
161
+ * Optional override for the backend SSO logout endpoint.
162
+ * Defaults to `/api/sso/logout` (or `${ssoBaseUrl}/api/sso/logout`).
163
+ */
164
+ ssoLogoutUrl?: string;
165
+ /**
166
+ * Custom element displayed while the SSO session is being verified.
167
+ * Defaults to `null` (renders nothing).
168
+ */
169
+ displayWhileLoading?: ReactNode;
170
+ /**
171
+ * Custom element displayed when SSO authentication fails.
172
+ * If not provided, the user is automatically redirected to `ssoLoginUrl`.
173
+ */
174
+ displayOnError?: ReactNode;
175
+ /**
176
+ * Re-validate the SSO session when the window regains focus.
177
+ * Enabled by default so token expiry and user switching are picked up
178
+ * without requiring a full page reload.
179
+ */
180
+ revalidateOnWindowFocus?: boolean;
181
+ }
182
+
183
+ /**
184
+ * User data returned by the Athena SSO `/api/sso/userinfo` endpoint.
185
+ * Field names use snake_case to match the backend response format.
186
+ */
187
+ export declare interface AthenaSSOUserData {
188
+ user_id: string;
189
+ email: string;
190
+ first_name: string;
191
+ last_name: string;
192
+ username: string;
193
+ picture_url: string;
194
+ properties: Record<string, unknown>;
195
+ }
196
+
197
+ /**
198
+ * Full response from the Athena SSO `/api/sso/userinfo` endpoint.
199
+ */
200
+ export declare interface AthenaSSOUserInfo {
201
+ user: AthenaSSOUserData;
202
+ orgMemberInfos: AthenaSSOOrgInfo[];
203
+ accessToken: string;
204
+ }
205
+
206
+ /**
207
+ * Athena user information — a simplified, PropelAuth-agnostic representation.
208
+ */
209
+ export declare interface AthenaUser {
210
+ userId: string;
211
+ email: string;
212
+ firstName?: string;
213
+ lastName?: string;
214
+ username?: string;
215
+ pictureUrl?: string;
216
+ properties?: Record<string, unknown>;
217
+ }
218
+
219
+ /**
220
+ * Read the current Athena auth state.
221
+ *
222
+ * Must be used inside an `<AthenaAuthProvider>`.
223
+ *
224
+ * @example
225
+ * ```tsx
226
+ * function UserMenu() {
227
+ * const { user, isLoggedIn, logout } = useAthenaAuth();
228
+ * if (!isLoggedIn) return null;
229
+ * return (
230
+ * <div>
231
+ * <span>{user?.email}</span>
232
+ * <button onClick={() => logout()}>Log out</button>
233
+ * </div>
234
+ * );
235
+ * }
236
+ * ```
237
+ */
238
+ export declare function useAthenaAuth(): AthenaAuthState;
239
+
240
+ export { }
package/dist/auth.js ADDED
@@ -0,0 +1,359 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { RequiredAuthProvider, RedirectToLogin, useAuthInfo, useLogoutFunction } from "@propelauth/react";
3
+ import { useState, useEffect, useMemo, useRef, useCallback } from "react";
4
+ import { A as AthenaAuthContext } from "./AthenaAuthContext-DQsdayH2.js";
5
+ import { u } from "./AthenaAuthContext-DQsdayH2.js";
6
+ const ATHENA_LOCATION_CHANGE_EVENT = "athena:location-change";
7
+ let historyPatched = false;
8
+ function patchHistoryForLocationTracking() {
9
+ if (historyPatched || typeof window === "undefined") {
10
+ return;
11
+ }
12
+ const notifyLocationChange = () => {
13
+ window.dispatchEvent(new Event(ATHENA_LOCATION_CHANGE_EVENT));
14
+ };
15
+ const originalPushState = window.history.pushState;
16
+ window.history.pushState = function pushState(...args) {
17
+ const result = originalPushState.apply(this, args);
18
+ notifyLocationChange();
19
+ return result;
20
+ };
21
+ const originalReplaceState = window.history.replaceState;
22
+ window.history.replaceState = function replaceState(...args) {
23
+ const result = originalReplaceState.apply(this, args);
24
+ notifyLocationChange();
25
+ return result;
26
+ };
27
+ historyPatched = true;
28
+ }
29
+ function useCurrentHref() {
30
+ const [href, setHref] = useState(
31
+ typeof window !== "undefined" ? window.location.href : "/"
32
+ );
33
+ useEffect(() => {
34
+ if (typeof window === "undefined") {
35
+ return;
36
+ }
37
+ patchHistoryForLocationTracking();
38
+ const updateHref = () => {
39
+ setHref(window.location.href);
40
+ };
41
+ updateHref();
42
+ window.addEventListener("popstate", updateHref);
43
+ window.addEventListener("hashchange", updateHref);
44
+ window.addEventListener(ATHENA_LOCATION_CHANGE_EVENT, updateHref);
45
+ return () => {
46
+ window.removeEventListener("popstate", updateHref);
47
+ window.removeEventListener("hashchange", updateHref);
48
+ window.removeEventListener(ATHENA_LOCATION_CHANGE_EVENT, updateHref);
49
+ };
50
+ }, []);
51
+ return href;
52
+ }
53
+ function AthenaAuthBridge({
54
+ children,
55
+ displayWhileLoading
56
+ }) {
57
+ const authInfo = useAuthInfo();
58
+ const logoutFn = useLogoutFunction();
59
+ const authState = useMemo(() => {
60
+ var _a;
61
+ if (authInfo.loading) {
62
+ return {
63
+ isLoggedIn: false,
64
+ isLoading: true,
65
+ user: null,
66
+ accessToken: null,
67
+ orgs: [],
68
+ logout: async () => {
69
+ }
70
+ };
71
+ }
72
+ if (!authInfo.isLoggedIn) {
73
+ return {
74
+ isLoggedIn: false,
75
+ isLoading: false,
76
+ user: null,
77
+ accessToken: null,
78
+ orgs: [],
79
+ logout: async (redirect = true) => logoutFn(redirect)
80
+ };
81
+ }
82
+ const user = {
83
+ userId: authInfo.user.userId,
84
+ email: authInfo.user.email,
85
+ firstName: authInfo.user.firstName ?? void 0,
86
+ lastName: authInfo.user.lastName ?? void 0,
87
+ username: authInfo.user.username ?? void 0,
88
+ pictureUrl: authInfo.user.pictureUrl ?? void 0,
89
+ properties: authInfo.user.properties
90
+ };
91
+ const orgs = ((_a = authInfo.orgHelper) == null ? void 0 : _a.getOrgs().map((org) => ({
92
+ orgId: org.orgId,
93
+ orgName: org.orgName,
94
+ urlSafeOrgName: org.urlSafeOrgName
95
+ }))) ?? [];
96
+ return {
97
+ isLoggedIn: true,
98
+ isLoading: false,
99
+ user,
100
+ accessToken: authInfo.accessToken,
101
+ orgs,
102
+ logout: async (redirect = true) => logoutFn(redirect)
103
+ };
104
+ }, [authInfo, logoutFn]);
105
+ if (authState.isLoading) {
106
+ return /* @__PURE__ */ jsx(Fragment, { children: displayWhileLoading ?? null });
107
+ }
108
+ return /* @__PURE__ */ jsx(AthenaAuthContext.Provider, { value: authState, children });
109
+ }
110
+ function AthenaAuthProvider({
111
+ children,
112
+ authUrl,
113
+ postLoginRedirectUrl,
114
+ displayWhileLoading
115
+ }) {
116
+ const currentHref = useCurrentHref();
117
+ const redirectUrl = postLoginRedirectUrl ?? currentHref;
118
+ return /* @__PURE__ */ jsx(
119
+ RequiredAuthProvider,
120
+ {
121
+ authUrl,
122
+ displayWhileLoading: displayWhileLoading ? /* @__PURE__ */ jsx(Fragment, { children: displayWhileLoading }) : void 0,
123
+ displayIfLoggedOut: /* @__PURE__ */ jsx(RedirectToLogin, { postLoginRedirectUrl: redirectUrl }),
124
+ children: /* @__PURE__ */ jsx(AthenaAuthBridge, { displayWhileLoading, children })
125
+ }
126
+ );
127
+ }
128
+ const DEFAULT_SSO_PATHS = {
129
+ userInfo: "/api/sso/userinfo",
130
+ login: "/api/sso/initiate",
131
+ logout: "/api/sso/logout"
132
+ };
133
+ const trimTrailingSlash = (value) => value.replace(/\/+$/, "");
134
+ function resolveSSOUrl({
135
+ baseUrl,
136
+ overrideUrl,
137
+ defaultPath
138
+ }) {
139
+ if (overrideUrl) {
140
+ return overrideUrl;
141
+ }
142
+ if (!baseUrl) {
143
+ return defaultPath;
144
+ }
145
+ return `${trimTrailingSlash(baseUrl)}${defaultPath}`;
146
+ }
147
+ function isValidSSOUserInfo(data) {
148
+ if (!data || typeof data !== "object") {
149
+ return false;
150
+ }
151
+ const candidate = data;
152
+ return typeof candidate.accessToken === "string" && Array.isArray(candidate.orgMemberInfos) && !!candidate.user && typeof candidate.user.user_id === "string" && typeof candidate.user.email === "string";
153
+ }
154
+ function mapSSOResponse(data) {
155
+ const user = {
156
+ userId: data.user.user_id,
157
+ email: data.user.email,
158
+ firstName: data.user.first_name || void 0,
159
+ lastName: data.user.last_name || void 0,
160
+ username: data.user.username || void 0,
161
+ pictureUrl: data.user.picture_url || void 0,
162
+ properties: data.user.properties
163
+ };
164
+ const orgs = data.orgMemberInfos.map((org) => ({
165
+ orgId: org.orgId,
166
+ orgName: org.orgName,
167
+ urlSafeOrgName: org.urlSafeOrgName
168
+ }));
169
+ return { user, orgs, accessToken: data.accessToken };
170
+ }
171
+ function AthenaSSOProvider({
172
+ children,
173
+ ssoBaseUrl,
174
+ ssoUserInfoUrl,
175
+ ssoLoginUrl,
176
+ ssoLogoutUrl,
177
+ displayWhileLoading,
178
+ displayOnError,
179
+ revalidateOnWindowFocus = true
180
+ }) {
181
+ const [ssoData, setSSOData] = useState(null);
182
+ const [loading, setLoading] = useState(true);
183
+ const [error, setError] = useState(null);
184
+ const activeRequestRef = useRef(null);
185
+ const ssoUrls = useMemo(
186
+ () => ({
187
+ userInfo: resolveSSOUrl({
188
+ baseUrl: ssoBaseUrl,
189
+ overrideUrl: ssoUserInfoUrl,
190
+ defaultPath: DEFAULT_SSO_PATHS.userInfo
191
+ }),
192
+ login: resolveSSOUrl({
193
+ baseUrl: ssoBaseUrl,
194
+ overrideUrl: ssoLoginUrl,
195
+ defaultPath: DEFAULT_SSO_PATHS.login
196
+ }),
197
+ logout: resolveSSOUrl({
198
+ baseUrl: ssoBaseUrl,
199
+ overrideUrl: ssoLogoutUrl,
200
+ defaultPath: DEFAULT_SSO_PATHS.logout
201
+ })
202
+ }),
203
+ [ssoBaseUrl, ssoUserInfoUrl, ssoLoginUrl, ssoLogoutUrl]
204
+ );
205
+ const refreshSession = useCallback(
206
+ async ({ showLoading = false } = {}) => {
207
+ var _a;
208
+ (_a = activeRequestRef.current) == null ? void 0 : _a.abort();
209
+ const abortController = new AbortController();
210
+ activeRequestRef.current = abortController;
211
+ if (showLoading) {
212
+ setLoading(true);
213
+ }
214
+ try {
215
+ const response = await fetch(ssoUrls.userInfo, {
216
+ credentials: "include",
217
+ signal: abortController.signal
218
+ });
219
+ if (!response.ok) {
220
+ if (response.status === 401 || response.status === 403) {
221
+ setSSOData(null);
222
+ setError("unauthenticated");
223
+ } else {
224
+ setError("request_failed");
225
+ }
226
+ return;
227
+ }
228
+ const data = await response.json();
229
+ if (!isValidSSOUserInfo(data)) {
230
+ console.error(
231
+ '[AthenaSDK] Invalid SSO userinfo response: expected "user.user_id", "user.email", "orgMemberInfos", and "accessToken"'
232
+ );
233
+ setSSOData(null);
234
+ setError("invalid_response");
235
+ return;
236
+ }
237
+ setSSOData(data);
238
+ setError(null);
239
+ } catch (fetchError) {
240
+ if (fetchError instanceof DOMException && fetchError.name === "AbortError") {
241
+ return;
242
+ }
243
+ setError("request_failed");
244
+ } finally {
245
+ if (activeRequestRef.current === abortController) {
246
+ activeRequestRef.current = null;
247
+ setLoading(false);
248
+ }
249
+ }
250
+ },
251
+ [ssoUrls.userInfo]
252
+ );
253
+ useEffect(() => {
254
+ void refreshSession({ showLoading: true });
255
+ return () => {
256
+ var _a;
257
+ (_a = activeRequestRef.current) == null ? void 0 : _a.abort();
258
+ };
259
+ }, [refreshSession]);
260
+ useEffect(() => {
261
+ if (!revalidateOnWindowFocus || typeof window === "undefined") {
262
+ return;
263
+ }
264
+ const handleFocus = () => {
265
+ void refreshSession();
266
+ };
267
+ const handleVisibilityChange = () => {
268
+ if (document.visibilityState === "visible") {
269
+ void refreshSession();
270
+ }
271
+ };
272
+ window.addEventListener("focus", handleFocus);
273
+ document.addEventListener("visibilitychange", handleVisibilityChange);
274
+ return () => {
275
+ window.removeEventListener("focus", handleFocus);
276
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
277
+ };
278
+ }, [revalidateOnWindowFocus, refreshSession]);
279
+ useEffect(() => {
280
+ if (!loading && error === "unauthenticated" && !displayOnError && typeof window !== "undefined") {
281
+ window.location.assign(ssoUrls.login);
282
+ }
283
+ }, [loading, error, displayOnError, ssoUrls.login]);
284
+ const logout = useCallback(async (redirectOnLogout = true) => {
285
+ var _a;
286
+ (_a = activeRequestRef.current) == null ? void 0 : _a.abort();
287
+ try {
288
+ await fetch(ssoUrls.logout, {
289
+ method: "POST",
290
+ credentials: "include"
291
+ });
292
+ } catch (logoutError) {
293
+ console.error("[AthenaSDK] Failed to invalidate SSO session during logout", logoutError);
294
+ }
295
+ setSSOData(null);
296
+ setError(null);
297
+ setLoading(false);
298
+ if (redirectOnLogout && typeof window !== "undefined") {
299
+ window.location.assign(ssoUrls.login);
300
+ }
301
+ }, [ssoUrls.login, ssoUrls.logout]);
302
+ const authState = useMemo(() => {
303
+ if (loading) {
304
+ return {
305
+ isLoggedIn: false,
306
+ isLoading: true,
307
+ user: null,
308
+ accessToken: null,
309
+ orgs: [],
310
+ logout: async () => {
311
+ }
312
+ };
313
+ }
314
+ if (error === "request_failed" && ssoData) {
315
+ const { user: user2, orgs: orgs2, accessToken: accessToken2 } = mapSSOResponse(ssoData);
316
+ return {
317
+ isLoggedIn: true,
318
+ isLoading: false,
319
+ user: user2,
320
+ accessToken: accessToken2,
321
+ orgs: orgs2,
322
+ logout
323
+ };
324
+ }
325
+ if (error || !ssoData) {
326
+ return {
327
+ isLoggedIn: false,
328
+ isLoading: false,
329
+ user: null,
330
+ accessToken: null,
331
+ orgs: [],
332
+ logout
333
+ };
334
+ }
335
+ const { user, orgs, accessToken } = mapSSOResponse(ssoData);
336
+ return {
337
+ isLoggedIn: true,
338
+ isLoading: false,
339
+ user,
340
+ accessToken,
341
+ orgs,
342
+ logout
343
+ };
344
+ }, [loading, error, ssoData, logout]);
345
+ if (authState.isLoading) {
346
+ return /* @__PURE__ */ jsx(Fragment, { children: displayWhileLoading ?? null });
347
+ }
348
+ if (!authState.isLoggedIn) {
349
+ return displayOnError ? /* @__PURE__ */ jsx(Fragment, { children: displayOnError }) : null;
350
+ }
351
+ return /* @__PURE__ */ jsx(AthenaAuthContext.Provider, { value: authState, children });
352
+ }
353
+ export {
354
+ AthenaAuthContext,
355
+ AthenaAuthProvider,
356
+ AthenaSSOProvider,
357
+ u as useAthenaAuth
358
+ };
359
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sources":["../src/auth/AthenaAuthProvider.tsx","../src/auth/AthenaSSOProvider.tsx"],"sourcesContent":["import {\n RequiredAuthProvider,\n RedirectToLogin,\n useAuthInfo,\n useLogoutFunction,\n} from '@propelauth/react';\nimport type { ReactNode } from 'react';\nimport { useEffect, useMemo, useState } from 'react';\nimport { AthenaAuthContext } from './AthenaAuthContext';\nimport type { AthenaAuthState, AthenaOrg, AthenaUser } from './types';\n\n// ─── Props ────────────────────────────────────────────────────────────\n\nexport interface AthenaAuthProviderProps {\n children: ReactNode;\n\n /**\n * Your PropelAuth auth URL (e.g. `https://auth.yourdomain.com`).\n * Found in the PropelAuth dashboard under Frontend Integration.\n */\n authUrl: string;\n\n /**\n * Where to redirect after a successful login.\n * Defaults to the current page URL.\n */\n postLoginRedirectUrl?: string;\n\n /**\n * Custom element displayed while the auth state is loading.\n * Defaults to `null` (renders nothing).\n */\n displayWhileLoading?: ReactNode;\n}\n\nconst ATHENA_LOCATION_CHANGE_EVENT = 'athena:location-change';\nlet historyPatched = false;\n\nfunction patchHistoryForLocationTracking(): void {\n if (historyPatched || typeof window === 'undefined') {\n return;\n }\n\n const notifyLocationChange = () => {\n window.dispatchEvent(new Event(ATHENA_LOCATION_CHANGE_EVENT));\n };\n\n const originalPushState = window.history.pushState;\n window.history.pushState = function pushState(...args) {\n const result = originalPushState.apply(this, args);\n notifyLocationChange();\n return result;\n };\n\n const originalReplaceState = window.history.replaceState;\n window.history.replaceState = function replaceState(...args) {\n const result = originalReplaceState.apply(this, args);\n notifyLocationChange();\n return result;\n };\n\n historyPatched = true;\n}\n\nfunction useCurrentHref(): string {\n const [href, setHref] = useState(\n typeof window !== 'undefined' ? window.location.href : '/',\n );\n\n useEffect(() => {\n if (typeof window === 'undefined') {\n return;\n }\n\n patchHistoryForLocationTracking();\n\n const updateHref = () => {\n setHref(window.location.href);\n };\n\n updateHref();\n window.addEventListener('popstate', updateHref);\n window.addEventListener('hashchange', updateHref);\n window.addEventListener(ATHENA_LOCATION_CHANGE_EVENT, updateHref);\n\n return () => {\n window.removeEventListener('popstate', updateHref);\n window.removeEventListener('hashchange', updateHref);\n window.removeEventListener(ATHENA_LOCATION_CHANGE_EVENT, updateHref);\n };\n }, []);\n\n return href;\n}\n\n// ─── Internal Bridge ──────────────────────────────────────────────────\n\n/**\n * Reads PropelAuth state via hooks and maps it into the SDK's\n * `AthenaAuthState`, which is placed on `AthenaAuthContext`.\n */\nfunction AthenaAuthBridge({\n children,\n displayWhileLoading,\n}: {\n children: ReactNode;\n displayWhileLoading?: ReactNode;\n}) {\n const authInfo = useAuthInfo();\n const logoutFn = useLogoutFunction();\n\n const authState: AthenaAuthState = useMemo(() => {\n if (authInfo.loading) {\n return {\n isLoggedIn: false,\n isLoading: true,\n user: null,\n accessToken: null,\n orgs: [],\n logout: async () => {},\n };\n }\n\n if (!authInfo.isLoggedIn) {\n return {\n isLoggedIn: false,\n isLoading: false,\n user: null,\n accessToken: null,\n orgs: [],\n logout: async (redirect = true) => logoutFn(redirect),\n };\n }\n\n const user: AthenaUser = {\n userId: authInfo.user.userId,\n email: authInfo.user.email,\n firstName: authInfo.user.firstName ?? undefined,\n lastName: authInfo.user.lastName ?? undefined,\n username: authInfo.user.username ?? undefined,\n pictureUrl: authInfo.user.pictureUrl ?? undefined,\n properties: authInfo.user.properties,\n };\n\n const orgs: AthenaOrg[] =\n authInfo.orgHelper?.getOrgs().map((org) => ({\n orgId: org.orgId,\n orgName: org.orgName,\n urlSafeOrgName: org.urlSafeOrgName,\n })) ?? [];\n\n return {\n isLoggedIn: true,\n isLoading: false,\n user,\n accessToken: authInfo.accessToken,\n orgs,\n logout: async (redirect = true) => logoutFn(redirect),\n };\n }, [authInfo, logoutFn]);\n\n if (authState.isLoading) {\n return <>{displayWhileLoading ?? null}</>;\n }\n\n return (\n <AthenaAuthContext.Provider value={authState}>\n {children}\n </AthenaAuthContext.Provider>\n );\n}\n\n// ─── Public Provider ──────────────────────────────────────────────────\n\n/**\n * Wraps your app with Athena authentication powered by PropelAuth.\n *\n * Place this **above** `<AthenaProvider>` in the component tree.\n * When present, `AthenaProvider` will automatically use the access token\n * from this provider — no need to pass `token` or `apiKey` manually.\n *\n * @example\n * ```tsx\n * import { AthenaAuthProvider } from '@athenaintel/react/auth';\n * import { AthenaProvider, AthenaChat } from '@athenaintel/react';\n *\n * function App() {\n * return (\n * <AthenaAuthProvider authUrl=\"https://auth.yourdomain.com\">\n * <AthenaProvider>\n * <AthenaChat />\n * </AthenaProvider>\n * </AthenaAuthProvider>\n * );\n * }\n * ```\n */\nexport function AthenaAuthProvider({\n children,\n authUrl,\n postLoginRedirectUrl,\n displayWhileLoading,\n}: AthenaAuthProviderProps) {\n const currentHref = useCurrentHref();\n const redirectUrl = postLoginRedirectUrl ?? currentHref;\n\n return (\n <RequiredAuthProvider\n authUrl={authUrl}\n displayWhileLoading={\n displayWhileLoading ? <>{displayWhileLoading}</> : undefined\n }\n displayIfLoggedOut={<RedirectToLogin postLoginRedirectUrl={redirectUrl} />}\n >\n <AthenaAuthBridge displayWhileLoading={displayWhileLoading}>\n {children}\n </AthenaAuthBridge>\n </RequiredAuthProvider>\n );\n}\n","import type { ReactNode } from 'react';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { AthenaAuthContext } from './AthenaAuthContext';\nimport type {\n AthenaAuthState,\n AthenaOrg,\n AthenaSSOUserInfo,\n AthenaUser,\n} from './types';\n\n// ─── Props ────────────────────────────────────────────────────────────\n\nexport interface AthenaSSOProviderProps {\n children: ReactNode;\n\n /**\n * Base URL used to resolve the Athena SSO endpoints.\n *\n * When omitted, the provider defaults to same-origin relative paths:\n * `/api/sso/userinfo`, `/api/sso/initiate`, and `/api/sso/logout`.\n *\n * Use this when your frontend and backend live on different origins\n * (for example `https://app.example.com` + `https://api.example.com`).\n */\n ssoBaseUrl?: string;\n\n /**\n * Optional override for the SSO user-info endpoint that returns the\n * authenticated user's data and access token.\n *\n * The endpoint must return JSON matching `AthenaSSOUserInfo`:\n * ```json\n * {\n * \"user\": { \"user_id\": \"…\", \"email\": \"…\", … },\n * \"orgMemberInfos\": [{ \"orgId\": \"…\", \"orgName\": \"…\", \"urlSafeOrgName\": \"…\" }],\n * \"accessToken\": \"…\"\n * }\n * ```\n *\n * The request is sent with `credentials: 'include'` so that\n * session cookies are forwarded automatically.\n */\n ssoUserInfoUrl?: string;\n\n /**\n * Optional override for the URL to redirect the user to when no valid\n * SSO session exists.\n * This is typically the SSO initiation endpoint on your backend\n * (e.g. `https://api.yourdomain.com/api/sso/initiate`).\n */\n ssoLoginUrl?: string;\n\n /**\n * Optional override for the backend SSO logout endpoint.\n * Defaults to `/api/sso/logout` (or `${ssoBaseUrl}/api/sso/logout`).\n */\n ssoLogoutUrl?: string;\n\n /**\n * Custom element displayed while the SSO session is being verified.\n * Defaults to `null` (renders nothing).\n */\n displayWhileLoading?: ReactNode;\n\n /**\n * Custom element displayed when SSO authentication fails.\n * If not provided, the user is automatically redirected to `ssoLoginUrl`.\n */\n displayOnError?: ReactNode;\n\n /**\n * Re-validate the SSO session when the window regains focus.\n * Enabled by default so token expiry and user switching are picked up\n * without requiring a full page reload.\n */\n revalidateOnWindowFocus?: boolean;\n}\n\n// ─── Helpers ──────────────────────────────────────────────────────────\n\ntype AthenaSSOError = 'unauthenticated' | 'invalid_response' | 'request_failed';\n\nconst DEFAULT_SSO_PATHS = {\n userInfo: '/api/sso/userinfo',\n login: '/api/sso/initiate',\n logout: '/api/sso/logout',\n} as const;\n\nconst trimTrailingSlash = (value: string): string => value.replace(/\\/+$/, '');\n\nfunction resolveSSOUrl({\n baseUrl,\n overrideUrl,\n defaultPath,\n}: {\n baseUrl?: string;\n overrideUrl?: string;\n defaultPath: string;\n}): string {\n if (overrideUrl) {\n return overrideUrl;\n }\n\n if (!baseUrl) {\n return defaultPath;\n }\n\n return `${trimTrailingSlash(baseUrl)}${defaultPath}`;\n}\n\nfunction isValidSSOUserInfo(data: unknown): data is AthenaSSOUserInfo {\n if (!data || typeof data !== 'object') {\n return false;\n }\n\n const candidate = data as {\n accessToken?: unknown;\n orgMemberInfos?: unknown;\n user?: {\n user_id?: unknown;\n email?: unknown;\n };\n };\n\n return (\n typeof candidate.accessToken === 'string' &&\n Array.isArray(candidate.orgMemberInfos) &&\n !!candidate.user &&\n typeof candidate.user.user_id === 'string' &&\n typeof candidate.user.email === 'string'\n );\n}\n\n/** Map the backend SSO response to the SDK's user/org types. */\nfunction mapSSOResponse(data: AthenaSSOUserInfo): {\n user: AthenaUser;\n orgs: AthenaOrg[];\n accessToken: string;\n} {\n const user: AthenaUser = {\n userId: data.user.user_id,\n email: data.user.email,\n firstName: data.user.first_name || undefined,\n lastName: data.user.last_name || undefined,\n username: data.user.username || undefined,\n pictureUrl: data.user.picture_url || undefined,\n properties: data.user.properties,\n };\n\n const orgs: AthenaOrg[] = data.orgMemberInfos.map((org) => ({\n orgId: org.orgId,\n orgName: org.orgName,\n urlSafeOrgName: org.urlSafeOrgName,\n }));\n\n return { user, orgs, accessToken: data.accessToken };\n}\n\n// ─── Provider ─────────────────────────────────────────────────────────\n\n/**\n * Wraps your app with Athena authentication powered by an external SSO\n * identity provider (e.g. Microsoft Entra / Azure AD, Okta, etc.).\n *\n * The SSO login flow is handled entirely by your backend. This provider\n * verifies the session by fetching `ssoUserInfoUrl` and exposes the\n * same `AthenaAuthState` context that `AthenaAuthProvider` (PropelAuth)\n * provides, so downstream components like `<AthenaProvider>` and\n * `useAthenaAuth()` work identically.\n *\n * Place this **above** `<AthenaProvider>` in the component tree.\n *\n * @example\n * ```tsx\n * import { AthenaSSOProvider } from '@athenaintel/react/auth';\n * import { AthenaProvider, AthenaChat } from '@athenaintel/react';\n *\n * function App() {\n * return (\n * <AthenaSSOProvider\n * ssoUserInfoUrl=\"https://api.yourdomain.com/api/sso/userinfo\"\n * ssoLoginUrl=\"https://api.yourdomain.com/api/sso/initiate\"\n * >\n * <AthenaProvider>\n * <AthenaChat />\n * </AthenaProvider>\n * </AthenaSSOProvider>\n * );\n * }\n * ```\n */\nexport function AthenaSSOProvider({\n children,\n ssoBaseUrl,\n ssoUserInfoUrl,\n ssoLoginUrl,\n ssoLogoutUrl,\n displayWhileLoading,\n displayOnError,\n revalidateOnWindowFocus = true,\n}: AthenaSSOProviderProps) {\n const [ssoData, setSSOData] = useState<AthenaSSOUserInfo | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<AthenaSSOError | null>(null);\n const activeRequestRef = useRef<AbortController | null>(null);\n\n const ssoUrls = useMemo(\n () => ({\n userInfo: resolveSSOUrl({\n baseUrl: ssoBaseUrl,\n overrideUrl: ssoUserInfoUrl,\n defaultPath: DEFAULT_SSO_PATHS.userInfo,\n }),\n login: resolveSSOUrl({\n baseUrl: ssoBaseUrl,\n overrideUrl: ssoLoginUrl,\n defaultPath: DEFAULT_SSO_PATHS.login,\n }),\n logout: resolveSSOUrl({\n baseUrl: ssoBaseUrl,\n overrideUrl: ssoLogoutUrl,\n defaultPath: DEFAULT_SSO_PATHS.logout,\n }),\n }),\n [ssoBaseUrl, ssoUserInfoUrl, ssoLoginUrl, ssoLogoutUrl],\n );\n\n const refreshSession = useCallback(\n async ({ showLoading = false }: { showLoading?: boolean } = {}): Promise<void> => {\n activeRequestRef.current?.abort();\n const abortController = new AbortController();\n activeRequestRef.current = abortController;\n\n if (showLoading) {\n setLoading(true);\n }\n\n try {\n const response = await fetch(ssoUrls.userInfo, {\n credentials: 'include',\n signal: abortController.signal,\n });\n\n if (!response.ok) {\n if (response.status === 401 || response.status === 403) {\n setSSOData(null);\n setError('unauthenticated');\n } else {\n setError('request_failed');\n }\n return;\n }\n\n const data: unknown = await response.json();\n\n if (!isValidSSOUserInfo(data)) {\n console.error(\n '[AthenaSDK] Invalid SSO userinfo response: expected \"user.user_id\", \"user.email\", \"orgMemberInfos\", and \"accessToken\"',\n );\n setSSOData(null);\n setError('invalid_response');\n return;\n }\n\n setSSOData(data);\n setError(null);\n } catch (fetchError) {\n if (fetchError instanceof DOMException && fetchError.name === 'AbortError') {\n return;\n }\n\n setError('request_failed');\n } finally {\n if (activeRequestRef.current === abortController) {\n activeRequestRef.current = null;\n setLoading(false);\n }\n }\n },\n [ssoUrls.userInfo],\n );\n\n useEffect(() => {\n void refreshSession({ showLoading: true });\n\n return () => {\n activeRequestRef.current?.abort();\n };\n }, [refreshSession]);\n\n useEffect(() => {\n if (!revalidateOnWindowFocus || typeof window === 'undefined') {\n return;\n }\n\n const handleFocus = () => {\n void refreshSession();\n };\n const handleVisibilityChange = () => {\n if (document.visibilityState === 'visible') {\n void refreshSession();\n }\n };\n\n window.addEventListener('focus', handleFocus);\n document.addEventListener('visibilitychange', handleVisibilityChange);\n\n return () => {\n window.removeEventListener('focus', handleFocus);\n document.removeEventListener('visibilitychange', handleVisibilityChange);\n };\n }, [revalidateOnWindowFocus, refreshSession]);\n\n // Redirect to SSO login when session is invalid and no error UI provided.\n useEffect(() => {\n if (\n !loading &&\n error === 'unauthenticated' &&\n !displayOnError &&\n typeof window !== 'undefined'\n ) {\n window.location.assign(ssoUrls.login);\n }\n }, [loading, error, displayOnError, ssoUrls.login]);\n\n const logout = useCallback(async (redirectOnLogout = true) => {\n activeRequestRef.current?.abort();\n\n try {\n await fetch(ssoUrls.logout, {\n method: 'POST',\n credentials: 'include',\n });\n } catch (logoutError) {\n console.error('[AthenaSDK] Failed to invalidate SSO session during logout', logoutError);\n }\n\n setSSOData(null);\n setError(null);\n setLoading(false);\n\n if (redirectOnLogout && typeof window !== 'undefined') {\n window.location.assign(ssoUrls.login);\n }\n }, [ssoUrls.login, ssoUrls.logout]);\n\n const authState: AthenaAuthState = useMemo(() => {\n if (loading) {\n return {\n isLoggedIn: false,\n isLoading: true,\n user: null,\n accessToken: null,\n orgs: [],\n logout: async () => {},\n };\n }\n\n if (error === 'request_failed' && ssoData) {\n const { user, orgs, accessToken } = mapSSOResponse(ssoData);\n\n return {\n isLoggedIn: true,\n isLoading: false,\n user,\n accessToken,\n orgs,\n logout,\n };\n }\n\n if (error || !ssoData) {\n return {\n isLoggedIn: false,\n isLoading: false,\n user: null,\n accessToken: null,\n orgs: [],\n logout,\n };\n }\n\n const { user, orgs, accessToken } = mapSSOResponse(ssoData);\n\n return {\n isLoggedIn: true,\n isLoading: false,\n user,\n accessToken,\n orgs,\n logout,\n };\n }, [loading, error, ssoData, logout]);\n\n if (authState.isLoading) {\n return <>{displayWhileLoading ?? null}</>;\n }\n\n if (!authState.isLoggedIn) {\n return displayOnError ? <>{displayOnError}</> : null;\n }\n\n return (\n <AthenaAuthContext.Provider value={authState}>\n {children}\n </AthenaAuthContext.Provider>\n );\n}\n"],"names":["user","orgs","accessToken"],"mappings":";;;;;AAmCA,MAAM,+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