@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/README.md +57 -1
- package/dist/AthenaAuthContext-B3AwLA5Z.cjs +15 -0
- package/dist/AthenaAuthContext-B3AwLA5Z.cjs.map +1 -0
- package/dist/AthenaAuthContext-DQsdayH2.js +16 -0
- package/dist/AthenaAuthContext-DQsdayH2.js.map +1 -0
- package/dist/auth.cjs +358 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.ts +240 -0
- package/dist/auth.js +359 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.cjs +51 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.js +51 -8
- package/dist/index.js.map +1 -1
- package/package.json +15 -3
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ React SDK for building AI-powered chat applications with the Athena platform.
|
|
|
8
8
|
npm install @athenaintel/react
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
If you use the PropelAuth-specific provider from `@athenaintel/react/auth`, also install:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @propelauth/react
|
|
15
|
+
```
|
|
16
|
+
|
|
11
17
|
## Quick Start
|
|
12
18
|
|
|
13
19
|
```tsx
|
|
@@ -44,10 +50,60 @@ function App() {
|
|
|
44
50
|
</AthenaProvider>
|
|
45
51
|
```
|
|
46
52
|
|
|
47
|
-
`config` accepts `apiKey`, `token`, `apiUrl`, `backendUrl`, `appUrl`, and `environment`. Top-level `apiKey`, `token`, `apiUrl`, `backendUrl`, `appUrl`, and `environment` props remain supported as compatibility aliases, but `config` is now the preferred API.
|
|
53
|
+
`config` accepts `apiKey`, `token`, `apiUrl`, `backendUrl`, `appUrl`, `trustedParentOrigins`, and `environment`. Top-level `apiKey`, `token`, `apiUrl`, `backendUrl`, `appUrl`, and `environment` props remain supported as compatibility aliases, but `config` is now the preferred API.
|
|
48
54
|
|
|
49
55
|
If `config.appUrl` is omitted, the provider resolves it from the parent bridge or from the matching Athena environment defaults. Known Athena staging and production `apiUrl` and `backendUrl` values automatically fall back to the corresponding frontend origin.
|
|
50
56
|
|
|
57
|
+
Use `trustedParentOrigins` when the SDK runs inside an iframe on a private-cloud or custom parent domain and you want to explicitly allow postMessage auth/config from that parent.
|
|
58
|
+
|
|
59
|
+
## Authentication
|
|
60
|
+
|
|
61
|
+
### Same-origin SSO defaults
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { AthenaSSOProvider } from '@athenaintel/react/auth';
|
|
65
|
+
import { AthenaChat, AthenaProvider } from '@athenaintel/react';
|
|
66
|
+
|
|
67
|
+
function App() {
|
|
68
|
+
return (
|
|
69
|
+
<AthenaSSOProvider>
|
|
70
|
+
<AthenaProvider enableThreadList>
|
|
71
|
+
<AthenaChat />
|
|
72
|
+
</AthenaProvider>
|
|
73
|
+
</AthenaSSOProvider>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
By default, `AthenaSSOProvider` uses same-origin SSO endpoints:
|
|
79
|
+
|
|
80
|
+
- `/api/sso/userinfo`
|
|
81
|
+
- `/api/sso/initiate`
|
|
82
|
+
- `/api/sso/logout`
|
|
83
|
+
|
|
84
|
+
This makes the SSO URLs optional when your frontend is reverse-proxied with the backend.
|
|
85
|
+
|
|
86
|
+
### Cross-origin SSO backend
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { AthenaSSOProvider } from '@athenaintel/react/auth';
|
|
90
|
+
|
|
91
|
+
<AthenaSSOProvider ssoBaseUrl="https://api.example.com">
|
|
92
|
+
<AthenaProvider
|
|
93
|
+
config={{
|
|
94
|
+
backendUrl: 'https://api.example.com/api/assistant-ui',
|
|
95
|
+
apiUrl: 'https://sync.example.com/api/chat',
|
|
96
|
+
trustedParentOrigins: ['https://app.example.com'],
|
|
97
|
+
}}
|
|
98
|
+
enableThreadList
|
|
99
|
+
>
|
|
100
|
+
<AthenaChat />
|
|
101
|
+
</AthenaProvider>
|
|
102
|
+
</AthenaSSOProvider>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
If you need full control, `ssoUserInfoUrl`, `ssoLoginUrl`, and `ssoLogoutUrl` remain available as explicit overrides.
|
|
106
|
+
|
|
51
107
|
## Citation Links
|
|
52
108
|
|
|
53
109
|
When you render chat inside `<AthenaLayout>`, Athena citation links (`app.athenaintel.com/dashboard/spaces?...`) now open the referenced asset in the SDK asset pane by default instead of navigating away.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const AthenaAuthContext = React.createContext(null);
|
|
4
|
+
function useAthenaAuth() {
|
|
5
|
+
const ctx = React.useContext(AthenaAuthContext);
|
|
6
|
+
if (!ctx) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"[AthenaSDK] useAthenaAuth must be used within an <AthenaAuthProvider>"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return ctx;
|
|
12
|
+
}
|
|
13
|
+
exports.AthenaAuthContext = AthenaAuthContext;
|
|
14
|
+
exports.useAthenaAuth = useAthenaAuth;
|
|
15
|
+
//# sourceMappingURL=AthenaAuthContext-B3AwLA5Z.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AthenaAuthContext-B3AwLA5Z.cjs","sources":["../src/auth/AthenaAuthContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AthenaAuthState } from './types';\n\n/**\n * Internal context used by `AthenaAuthProvider` to share auth state.\n * Consumed by `useAthenaAuth()` and automatically by `AthenaProvider`.\n */\nexport const AthenaAuthContext = createContext<AthenaAuthState | null>(null);\n\n/**\n * Read the current Athena auth state.\n *\n * Must be used inside an `<AthenaAuthProvider>`.\n *\n * @example\n * ```tsx\n * function UserMenu() {\n * const { user, isLoggedIn, logout } = useAthenaAuth();\n * if (!isLoggedIn) return null;\n * return (\n * <div>\n * <span>{user?.email}</span>\n * <button onClick={() => logout()}>Log out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useAthenaAuth(): AthenaAuthState {\n const ctx = useContext(AthenaAuthContext);\n if (!ctx) {\n throw new Error(\n '[AthenaSDK] useAthenaAuth must be used within an <AthenaAuthProvider>',\n );\n }\n return ctx;\n}\n"],"names":["createContext","useContext"],"mappings":";;AAOO,MAAM,oBAAoBA,MAAAA,cAAsC,IAAI;AAqBpE,SAAS,gBAAiC;AAC/C,QAAM,MAAMC,MAAAA,WAAW,iBAAiB;AACxC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const AthenaAuthContext = createContext(null);
|
|
3
|
+
function useAthenaAuth() {
|
|
4
|
+
const ctx = useContext(AthenaAuthContext);
|
|
5
|
+
if (!ctx) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"[AthenaSDK] useAthenaAuth must be used within an <AthenaAuthProvider>"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return ctx;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
AthenaAuthContext as A,
|
|
14
|
+
useAthenaAuth as u
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=AthenaAuthContext-DQsdayH2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AthenaAuthContext-DQsdayH2.js","sources":["../src/auth/AthenaAuthContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AthenaAuthState } from './types';\n\n/**\n * Internal context used by `AthenaAuthProvider` to share auth state.\n * Consumed by `useAthenaAuth()` and automatically by `AthenaProvider`.\n */\nexport const AthenaAuthContext = createContext<AthenaAuthState | null>(null);\n\n/**\n * Read the current Athena auth state.\n *\n * Must be used inside an `<AthenaAuthProvider>`.\n *\n * @example\n * ```tsx\n * function UserMenu() {\n * const { user, isLoggedIn, logout } = useAthenaAuth();\n * if (!isLoggedIn) return null;\n * return (\n * <div>\n * <span>{user?.email}</span>\n * <button onClick={() => logout()}>Log out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useAthenaAuth(): AthenaAuthState {\n const ctx = useContext(AthenaAuthContext);\n if (!ctx) {\n throw new Error(\n '[AthenaSDK] useAthenaAuth must be used within an <AthenaAuthProvider>',\n );\n }\n return ctx;\n}\n"],"names":[],"mappings":";AAOO,MAAM,oBAAoB,cAAsC,IAAI;AAqBpE,SAAS,gBAAiC;AAC/C,QAAM,MAAM,WAAW,iBAAiB;AACxC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT;"}
|
package/dist/auth.cjs
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("@propelauth/react");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const AthenaAuthContext = require("./AthenaAuthContext-B3AwLA5Z.cjs");
|
|
7
|
+
const ATHENA_LOCATION_CHANGE_EVENT = "athena:location-change";
|
|
8
|
+
let historyPatched = false;
|
|
9
|
+
function patchHistoryForLocationTracking() {
|
|
10
|
+
if (historyPatched || typeof window === "undefined") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const notifyLocationChange = () => {
|
|
14
|
+
window.dispatchEvent(new Event(ATHENA_LOCATION_CHANGE_EVENT));
|
|
15
|
+
};
|
|
16
|
+
const originalPushState = window.history.pushState;
|
|
17
|
+
window.history.pushState = function pushState(...args) {
|
|
18
|
+
const result = originalPushState.apply(this, args);
|
|
19
|
+
notifyLocationChange();
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
const originalReplaceState = window.history.replaceState;
|
|
23
|
+
window.history.replaceState = function replaceState(...args) {
|
|
24
|
+
const result = originalReplaceState.apply(this, args);
|
|
25
|
+
notifyLocationChange();
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
historyPatched = true;
|
|
29
|
+
}
|
|
30
|
+
function useCurrentHref() {
|
|
31
|
+
const [href, setHref] = React.useState(
|
|
32
|
+
typeof window !== "undefined" ? window.location.href : "/"
|
|
33
|
+
);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (typeof window === "undefined") {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
patchHistoryForLocationTracking();
|
|
39
|
+
const updateHref = () => {
|
|
40
|
+
setHref(window.location.href);
|
|
41
|
+
};
|
|
42
|
+
updateHref();
|
|
43
|
+
window.addEventListener("popstate", updateHref);
|
|
44
|
+
window.addEventListener("hashchange", updateHref);
|
|
45
|
+
window.addEventListener(ATHENA_LOCATION_CHANGE_EVENT, updateHref);
|
|
46
|
+
return () => {
|
|
47
|
+
window.removeEventListener("popstate", updateHref);
|
|
48
|
+
window.removeEventListener("hashchange", updateHref);
|
|
49
|
+
window.removeEventListener(ATHENA_LOCATION_CHANGE_EVENT, updateHref);
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
return href;
|
|
53
|
+
}
|
|
54
|
+
function AthenaAuthBridge({
|
|
55
|
+
children,
|
|
56
|
+
displayWhileLoading
|
|
57
|
+
}) {
|
|
58
|
+
const authInfo = react.useAuthInfo();
|
|
59
|
+
const logoutFn = react.useLogoutFunction();
|
|
60
|
+
const authState = React.useMemo(() => {
|
|
61
|
+
var _a;
|
|
62
|
+
if (authInfo.loading) {
|
|
63
|
+
return {
|
|
64
|
+
isLoggedIn: false,
|
|
65
|
+
isLoading: true,
|
|
66
|
+
user: null,
|
|
67
|
+
accessToken: null,
|
|
68
|
+
orgs: [],
|
|
69
|
+
logout: async () => {
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (!authInfo.isLoggedIn) {
|
|
74
|
+
return {
|
|
75
|
+
isLoggedIn: false,
|
|
76
|
+
isLoading: false,
|
|
77
|
+
user: null,
|
|
78
|
+
accessToken: null,
|
|
79
|
+
orgs: [],
|
|
80
|
+
logout: async (redirect = true) => logoutFn(redirect)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const user = {
|
|
84
|
+
userId: authInfo.user.userId,
|
|
85
|
+
email: authInfo.user.email,
|
|
86
|
+
firstName: authInfo.user.firstName ?? void 0,
|
|
87
|
+
lastName: authInfo.user.lastName ?? void 0,
|
|
88
|
+
username: authInfo.user.username ?? void 0,
|
|
89
|
+
pictureUrl: authInfo.user.pictureUrl ?? void 0,
|
|
90
|
+
properties: authInfo.user.properties
|
|
91
|
+
};
|
|
92
|
+
const orgs = ((_a = authInfo.orgHelper) == null ? void 0 : _a.getOrgs().map((org) => ({
|
|
93
|
+
orgId: org.orgId,
|
|
94
|
+
orgName: org.orgName,
|
|
95
|
+
urlSafeOrgName: org.urlSafeOrgName
|
|
96
|
+
}))) ?? [];
|
|
97
|
+
return {
|
|
98
|
+
isLoggedIn: true,
|
|
99
|
+
isLoading: false,
|
|
100
|
+
user,
|
|
101
|
+
accessToken: authInfo.accessToken,
|
|
102
|
+
orgs,
|
|
103
|
+
logout: async (redirect = true) => logoutFn(redirect)
|
|
104
|
+
};
|
|
105
|
+
}, [authInfo, logoutFn]);
|
|
106
|
+
if (authState.isLoading) {
|
|
107
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: displayWhileLoading ?? null });
|
|
108
|
+
}
|
|
109
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AthenaAuthContext.AthenaAuthContext.Provider, { value: authState, children });
|
|
110
|
+
}
|
|
111
|
+
function AthenaAuthProvider({
|
|
112
|
+
children,
|
|
113
|
+
authUrl,
|
|
114
|
+
postLoginRedirectUrl,
|
|
115
|
+
displayWhileLoading
|
|
116
|
+
}) {
|
|
117
|
+
const currentHref = useCurrentHref();
|
|
118
|
+
const redirectUrl = postLoginRedirectUrl ?? currentHref;
|
|
119
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
120
|
+
react.RequiredAuthProvider,
|
|
121
|
+
{
|
|
122
|
+
authUrl,
|
|
123
|
+
displayWhileLoading: displayWhileLoading ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: displayWhileLoading }) : void 0,
|
|
124
|
+
displayIfLoggedOut: /* @__PURE__ */ jsxRuntime.jsx(react.RedirectToLogin, { postLoginRedirectUrl: redirectUrl }),
|
|
125
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AthenaAuthBridge, { displayWhileLoading, children })
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
const DEFAULT_SSO_PATHS = {
|
|
130
|
+
userInfo: "/api/sso/userinfo",
|
|
131
|
+
login: "/api/sso/initiate",
|
|
132
|
+
logout: "/api/sso/logout"
|
|
133
|
+
};
|
|
134
|
+
const trimTrailingSlash = (value) => value.replace(/\/+$/, "");
|
|
135
|
+
function resolveSSOUrl({
|
|
136
|
+
baseUrl,
|
|
137
|
+
overrideUrl,
|
|
138
|
+
defaultPath
|
|
139
|
+
}) {
|
|
140
|
+
if (overrideUrl) {
|
|
141
|
+
return overrideUrl;
|
|
142
|
+
}
|
|
143
|
+
if (!baseUrl) {
|
|
144
|
+
return defaultPath;
|
|
145
|
+
}
|
|
146
|
+
return `${trimTrailingSlash(baseUrl)}${defaultPath}`;
|
|
147
|
+
}
|
|
148
|
+
function isValidSSOUserInfo(data) {
|
|
149
|
+
if (!data || typeof data !== "object") {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const candidate = data;
|
|
153
|
+
return typeof candidate.accessToken === "string" && Array.isArray(candidate.orgMemberInfos) && !!candidate.user && typeof candidate.user.user_id === "string" && typeof candidate.user.email === "string";
|
|
154
|
+
}
|
|
155
|
+
function mapSSOResponse(data) {
|
|
156
|
+
const user = {
|
|
157
|
+
userId: data.user.user_id,
|
|
158
|
+
email: data.user.email,
|
|
159
|
+
firstName: data.user.first_name || void 0,
|
|
160
|
+
lastName: data.user.last_name || void 0,
|
|
161
|
+
username: data.user.username || void 0,
|
|
162
|
+
pictureUrl: data.user.picture_url || void 0,
|
|
163
|
+
properties: data.user.properties
|
|
164
|
+
};
|
|
165
|
+
const orgs = data.orgMemberInfos.map((org) => ({
|
|
166
|
+
orgId: org.orgId,
|
|
167
|
+
orgName: org.orgName,
|
|
168
|
+
urlSafeOrgName: org.urlSafeOrgName
|
|
169
|
+
}));
|
|
170
|
+
return { user, orgs, accessToken: data.accessToken };
|
|
171
|
+
}
|
|
172
|
+
function AthenaSSOProvider({
|
|
173
|
+
children,
|
|
174
|
+
ssoBaseUrl,
|
|
175
|
+
ssoUserInfoUrl,
|
|
176
|
+
ssoLoginUrl,
|
|
177
|
+
ssoLogoutUrl,
|
|
178
|
+
displayWhileLoading,
|
|
179
|
+
displayOnError,
|
|
180
|
+
revalidateOnWindowFocus = true
|
|
181
|
+
}) {
|
|
182
|
+
const [ssoData, setSSOData] = React.useState(null);
|
|
183
|
+
const [loading, setLoading] = React.useState(true);
|
|
184
|
+
const [error, setError] = React.useState(null);
|
|
185
|
+
const activeRequestRef = React.useRef(null);
|
|
186
|
+
const ssoUrls = React.useMemo(
|
|
187
|
+
() => ({
|
|
188
|
+
userInfo: resolveSSOUrl({
|
|
189
|
+
baseUrl: ssoBaseUrl,
|
|
190
|
+
overrideUrl: ssoUserInfoUrl,
|
|
191
|
+
defaultPath: DEFAULT_SSO_PATHS.userInfo
|
|
192
|
+
}),
|
|
193
|
+
login: resolveSSOUrl({
|
|
194
|
+
baseUrl: ssoBaseUrl,
|
|
195
|
+
overrideUrl: ssoLoginUrl,
|
|
196
|
+
defaultPath: DEFAULT_SSO_PATHS.login
|
|
197
|
+
}),
|
|
198
|
+
logout: resolveSSOUrl({
|
|
199
|
+
baseUrl: ssoBaseUrl,
|
|
200
|
+
overrideUrl: ssoLogoutUrl,
|
|
201
|
+
defaultPath: DEFAULT_SSO_PATHS.logout
|
|
202
|
+
})
|
|
203
|
+
}),
|
|
204
|
+
[ssoBaseUrl, ssoUserInfoUrl, ssoLoginUrl, ssoLogoutUrl]
|
|
205
|
+
);
|
|
206
|
+
const refreshSession = React.useCallback(
|
|
207
|
+
async ({ showLoading = false } = {}) => {
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = activeRequestRef.current) == null ? void 0 : _a.abort();
|
|
210
|
+
const abortController = new AbortController();
|
|
211
|
+
activeRequestRef.current = abortController;
|
|
212
|
+
if (showLoading) {
|
|
213
|
+
setLoading(true);
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const response = await fetch(ssoUrls.userInfo, {
|
|
217
|
+
credentials: "include",
|
|
218
|
+
signal: abortController.signal
|
|
219
|
+
});
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
if (response.status === 401 || response.status === 403) {
|
|
222
|
+
setSSOData(null);
|
|
223
|
+
setError("unauthenticated");
|
|
224
|
+
} else {
|
|
225
|
+
setError("request_failed");
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const data = await response.json();
|
|
230
|
+
if (!isValidSSOUserInfo(data)) {
|
|
231
|
+
console.error(
|
|
232
|
+
'[AthenaSDK] Invalid SSO userinfo response: expected "user.user_id", "user.email", "orgMemberInfos", and "accessToken"'
|
|
233
|
+
);
|
|
234
|
+
setSSOData(null);
|
|
235
|
+
setError("invalid_response");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
setSSOData(data);
|
|
239
|
+
setError(null);
|
|
240
|
+
} catch (fetchError) {
|
|
241
|
+
if (fetchError instanceof DOMException && fetchError.name === "AbortError") {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
setError("request_failed");
|
|
245
|
+
} finally {
|
|
246
|
+
if (activeRequestRef.current === abortController) {
|
|
247
|
+
activeRequestRef.current = null;
|
|
248
|
+
setLoading(false);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
[ssoUrls.userInfo]
|
|
253
|
+
);
|
|
254
|
+
React.useEffect(() => {
|
|
255
|
+
void refreshSession({ showLoading: true });
|
|
256
|
+
return () => {
|
|
257
|
+
var _a;
|
|
258
|
+
(_a = activeRequestRef.current) == null ? void 0 : _a.abort();
|
|
259
|
+
};
|
|
260
|
+
}, [refreshSession]);
|
|
261
|
+
React.useEffect(() => {
|
|
262
|
+
if (!revalidateOnWindowFocus || typeof window === "undefined") {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const handleFocus = () => {
|
|
266
|
+
void refreshSession();
|
|
267
|
+
};
|
|
268
|
+
const handleVisibilityChange = () => {
|
|
269
|
+
if (document.visibilityState === "visible") {
|
|
270
|
+
void refreshSession();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
window.addEventListener("focus", handleFocus);
|
|
274
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
275
|
+
return () => {
|
|
276
|
+
window.removeEventListener("focus", handleFocus);
|
|
277
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
278
|
+
};
|
|
279
|
+
}, [revalidateOnWindowFocus, refreshSession]);
|
|
280
|
+
React.useEffect(() => {
|
|
281
|
+
if (!loading && error === "unauthenticated" && !displayOnError && typeof window !== "undefined") {
|
|
282
|
+
window.location.assign(ssoUrls.login);
|
|
283
|
+
}
|
|
284
|
+
}, [loading, error, displayOnError, ssoUrls.login]);
|
|
285
|
+
const logout = React.useCallback(async (redirectOnLogout = true) => {
|
|
286
|
+
var _a;
|
|
287
|
+
(_a = activeRequestRef.current) == null ? void 0 : _a.abort();
|
|
288
|
+
try {
|
|
289
|
+
await fetch(ssoUrls.logout, {
|
|
290
|
+
method: "POST",
|
|
291
|
+
credentials: "include"
|
|
292
|
+
});
|
|
293
|
+
} catch (logoutError) {
|
|
294
|
+
console.error("[AthenaSDK] Failed to invalidate SSO session during logout", logoutError);
|
|
295
|
+
}
|
|
296
|
+
setSSOData(null);
|
|
297
|
+
setError(null);
|
|
298
|
+
setLoading(false);
|
|
299
|
+
if (redirectOnLogout && typeof window !== "undefined") {
|
|
300
|
+
window.location.assign(ssoUrls.login);
|
|
301
|
+
}
|
|
302
|
+
}, [ssoUrls.login, ssoUrls.logout]);
|
|
303
|
+
const authState = React.useMemo(() => {
|
|
304
|
+
if (loading) {
|
|
305
|
+
return {
|
|
306
|
+
isLoggedIn: false,
|
|
307
|
+
isLoading: true,
|
|
308
|
+
user: null,
|
|
309
|
+
accessToken: null,
|
|
310
|
+
orgs: [],
|
|
311
|
+
logout: async () => {
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (error === "request_failed" && ssoData) {
|
|
316
|
+
const { user: user2, orgs: orgs2, accessToken: accessToken2 } = mapSSOResponse(ssoData);
|
|
317
|
+
return {
|
|
318
|
+
isLoggedIn: true,
|
|
319
|
+
isLoading: false,
|
|
320
|
+
user: user2,
|
|
321
|
+
accessToken: accessToken2,
|
|
322
|
+
orgs: orgs2,
|
|
323
|
+
logout
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
if (error || !ssoData) {
|
|
327
|
+
return {
|
|
328
|
+
isLoggedIn: false,
|
|
329
|
+
isLoading: false,
|
|
330
|
+
user: null,
|
|
331
|
+
accessToken: null,
|
|
332
|
+
orgs: [],
|
|
333
|
+
logout
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
const { user, orgs, accessToken } = mapSSOResponse(ssoData);
|
|
337
|
+
return {
|
|
338
|
+
isLoggedIn: true,
|
|
339
|
+
isLoading: false,
|
|
340
|
+
user,
|
|
341
|
+
accessToken,
|
|
342
|
+
orgs,
|
|
343
|
+
logout
|
|
344
|
+
};
|
|
345
|
+
}, [loading, error, ssoData, logout]);
|
|
346
|
+
if (authState.isLoading) {
|
|
347
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: displayWhileLoading ?? null });
|
|
348
|
+
}
|
|
349
|
+
if (!authState.isLoggedIn) {
|
|
350
|
+
return displayOnError ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: displayOnError }) : null;
|
|
351
|
+
}
|
|
352
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AthenaAuthContext.AthenaAuthContext.Provider, { value: authState, children });
|
|
353
|
+
}
|
|
354
|
+
exports.AthenaAuthContext = AthenaAuthContext.AthenaAuthContext;
|
|
355
|
+
exports.useAthenaAuth = AthenaAuthContext.useAthenaAuth;
|
|
356
|
+
exports.AthenaAuthProvider = AthenaAuthProvider;
|
|
357
|
+
exports.AthenaSSOProvider = AthenaSSOProvider;
|
|
358
|
+
//# sourceMappingURL=auth.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.cjs","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":["useState","useEffect","useAuthInfo","useLogoutFunction","useMemo","jsx","Fragment","AthenaAuthContext","RequiredAuthProvider","RedirectToLogin","useRef","useCallback","user","orgs","accessToken"],"mappings":";;;;;;AAmCA,MAAM,+BAA+B;AACrC,IAAI,iBAAiB;AAErB,SAAS,kCAAwC;AAC/C,MAAI,kBAAkB,OAAO,WAAW,aAAa;AACnD;AAAA,EACF;AAEA,QAAM,uBAAuB,MAAM;AACjC,WAAO,cAAc,IAA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