@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/index.cjs CHANGED
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5
5
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
6
  const jsxRuntime = require("react/jsx-runtime");
7
7
  const React = require("react");
8
+ const AthenaAuthContext = require("./AthenaAuthContext-B3AwLA5Z.cjs");
8
9
  const ReactDOM = require("react-dom");
9
10
  function _interopNamespaceDefault(e) {
10
11
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -16583,17 +16584,50 @@ function createAthenaSpacesUrl({
16583
16584
  }
16584
16585
  return url.toString();
16585
16586
  }
16586
- function isTrustedOrigin(origin) {
16587
+ function isTrustedOrigin({
16588
+ origin,
16589
+ trustedOrigins
16590
+ }) {
16587
16591
  try {
16588
- const { hostname } = new URL(origin);
16592
+ const normalizedOrigin = new URL(origin).origin;
16593
+ if (trustedOrigins.includes(normalizedOrigin)) {
16594
+ return true;
16595
+ }
16596
+ const { hostname } = new URL(normalizedOrigin);
16589
16597
  return hostname === "athenaintel.com" || hostname.endsWith(".athenaintel.com") || hostname === "localhost";
16590
16598
  } catch {
16591
16599
  return false;
16592
16600
  }
16593
16601
  }
16594
16602
  const BRIDGE_TIMEOUT_MS = 2e3;
16595
- function useParentBridge() {
16603
+ const normalizeOrigin = (value) => {
16604
+ try {
16605
+ return new URL(value).origin;
16606
+ } catch {
16607
+ return null;
16608
+ }
16609
+ };
16610
+ function useParentBridge({
16611
+ trustedOrigins = []
16612
+ } = {}) {
16596
16613
  const isInIframe = typeof window !== "undefined" && window.parent !== window;
16614
+ const runtimeTrustedOrigins = React.useMemo(() => {
16615
+ const origins = /* @__PURE__ */ new Set();
16616
+ if (typeof window !== "undefined") {
16617
+ origins.add(window.location.origin);
16618
+ const referrerOrigin = normalizeOrigin(document.referrer);
16619
+ if (referrerOrigin) {
16620
+ origins.add(referrerOrigin);
16621
+ }
16622
+ }
16623
+ for (const trustedOrigin of trustedOrigins) {
16624
+ const normalizedOrigin = normalizeOrigin(trustedOrigin);
16625
+ if (normalizedOrigin) {
16626
+ origins.add(normalizedOrigin);
16627
+ }
16628
+ }
16629
+ return [...origins];
16630
+ }, [trustedOrigins]);
16597
16631
  const [state, setState] = React.useState({
16598
16632
  token: null,
16599
16633
  apiUrl: null,
@@ -16607,7 +16641,9 @@ function useParentBridge() {
16607
16641
  React.useEffect(() => {
16608
16642
  if (!isInIframe) return;
16609
16643
  const handler = (event) => {
16610
- if (!isTrustedOrigin(event.origin)) return;
16644
+ if (!isTrustedOrigin({ origin: event.origin, trustedOrigins: runtimeTrustedOrigins })) {
16645
+ return;
16646
+ }
16611
16647
  if (!event.data || typeof event.data !== "object") return;
16612
16648
  if (event.data.type === "athena-config") {
16613
16649
  configReceived.current = true;
@@ -16642,7 +16678,7 @@ function useParentBridge() {
16642
16678
  window.removeEventListener("message", handler);
16643
16679
  clearTimeout(timer);
16644
16680
  };
16645
- }, [isInIframe]);
16681
+ }, [isInIframe, runtimeTrustedOrigins]);
16646
16682
  return state;
16647
16683
  }
16648
16684
  function useParentAuth() {
@@ -24990,8 +25026,13 @@ function AthenaProvider({
24990
25026
  const configuredApiUrl = (config2 == null ? void 0 : config2.apiUrl) ?? apiUrl;
24991
25027
  const configuredBackendUrl = (config2 == null ? void 0 : config2.backendUrl) ?? backendUrl;
24992
25028
  const configuredAppUrl = (config2 == null ? void 0 : config2.appUrl) ?? appUrl;
24993
- const bridge = useParentBridge();
24994
- const effectiveToken = configuredToken !== void 0 ? configuredToken : bridge.token;
25029
+ const configuredTrustedParentOrigins = config2 == null ? void 0 : config2.trustedParentOrigins;
25030
+ const bridge = useParentBridge({
25031
+ trustedOrigins: configuredTrustedParentOrigins
25032
+ });
25033
+ const authContext = React.useContext(AthenaAuthContext.AthenaAuthContext);
25034
+ const authProviderToken = (authContext == null ? void 0 : authContext.accessToken) ?? null;
25035
+ const effectiveToken = configuredToken !== void 0 ? configuredToken : authProviderToken ?? bridge.token;
24995
25036
  const effectiveApiUrl = configuredApiUrl ?? bridge.apiUrl ?? environmentUrls.apiUrl;
24996
25037
  const effectiveBackendUrl = configuredBackendUrl ?? bridge.backendUrl ?? environmentUrls.backendUrl;
24997
25038
  const effectiveAppUrl = configuredAppUrl ?? bridge.appUrl ?? deriveAthenaAppUrl({ apiUrl: effectiveApiUrl, backendUrl: effectiveBackendUrl }) ?? environmentUrls.appUrl;
@@ -62374,7 +62415,9 @@ const TOOL_META = {
62374
62415
  create_email_draft: { displayName: "Drafting email", icon: Mail },
62375
62416
  unified_email_create_draft: { displayName: "Drafting email", icon: Mail },
62376
62417
  edit_email_draft: { displayName: "Editing email draft", icon: Mail },
62377
- unified_edit_email_draft: { displayName: "Editing email draft", icon: Mail },
62418
+ unified_email_edit_draft: { displayName: "Editing email draft", icon: Mail },
62419
+ unified_email_fetch_attachments: { displayName: "Fetching email attachments", icon: Mail },
62420
+ unified_email_forward: { displayName: "Forwarding email", icon: Mail },
62378
62421
  // Documents
62379
62422
  read_full_asset: { displayName: "Reading document", icon: BookOpen },
62380
62423
  create_new_document: { displayName: "Creating document", icon: FileText },