@athenaintel/react 0.10.12 → 0.10.13

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.d.ts CHANGED
@@ -1167,6 +1167,13 @@ export declare function useAppendToComposer(): (text: string, opts?: {
1167
1167
  /**
1168
1168
  * Hook to generate an embed URL for rendering an asset in an iframe.
1169
1169
  * Calls the Athena embed token endpoint.
1170
+ *
1171
+ * Note: The auth token is read via a ref and is intentionally NOT part
1172
+ * of the effect dependency array. PropelAuth and similar providers refresh
1173
+ * the token value periodically (e.g. on window focus), but the underlying
1174
+ * session is the same — re-running the effect on every token rotation
1175
+ * would force the iframe to reload unnecessarily. The effect only re-runs
1176
+ * when the auth _mode_ changes (auth vs anonymous) or the asset changes.
1170
1177
  */
1171
1178
  export declare function useAssetEmbed(assetId: string | null, options?: UseAssetEmbedOptions & {
1172
1179
  backendUrl: string;
package/dist/index.js CHANGED
@@ -66300,6 +66300,9 @@ function useAssetEmbed(assetId, options = {
66300
66300
  const [isLoading, setIsLoading] = useState(false);
66301
66301
  const [error2, setError] = useState(null);
66302
66302
  const abortRef = useRef(null);
66303
+ const tokenRef = useRef(token);
66304
+ tokenRef.current = token;
66305
+ const hasToken = !!token;
66303
66306
  useEffect(() => {
66304
66307
  var _a2;
66305
66308
  if (!assetId || !backendUrl) {
@@ -66308,7 +66311,8 @@ function useAssetEmbed(assetId, options = {
66308
66311
  setError(null);
66309
66312
  return;
66310
66313
  }
66311
- const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
66314
+ const authContext = hasToken ? "token" : apiKey ?? "anon";
66315
+ const cacheKey = `${assetId}:${readOnly}:${authContext}`;
66312
66316
  const cached = embedCache.get(cacheKey);
66313
66317
  if (cached && cached.expiresAt > Date.now() / 1e3) {
66314
66318
  setEmbedUrl(cached.url);
@@ -66324,8 +66328,9 @@ function useAssetEmbed(assetId, options = {
66324
66328
  setIsLoading(true);
66325
66329
  setError(null);
66326
66330
  const headers = { "Content-Type": "application/json" };
66327
- if (token) {
66328
- headers["Authorization"] = `Bearer ${token}`;
66331
+ const currentToken = tokenRef.current;
66332
+ if (currentToken) {
66333
+ headers["Authorization"] = `Bearer ${currentToken}`;
66329
66334
  } else if (apiKey) {
66330
66335
  headers["X-API-KEY"] = apiKey;
66331
66336
  }
@@ -66345,7 +66350,7 @@ function useAssetEmbed(assetId, options = {
66345
66350
  }
66346
66351
  return res.json();
66347
66352
  }).then((data) => {
66348
- embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
66353
+ embedCache.set(cacheKey, { url: data.embed_url, expiresAt: data.expires_at });
66349
66354
  setEmbedUrl(data.embed_url);
66350
66355
  setIsLoading(false);
66351
66356
  }).catch((err) => {
@@ -66354,7 +66359,7 @@ function useAssetEmbed(assetId, options = {
66354
66359
  setIsLoading(false);
66355
66360
  });
66356
66361
  return () => controller.abort();
66357
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
66362
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, hasToken]);
66358
66363
  return { embedUrl, isLoading, error: error2 };
66359
66364
  }
66360
66365
  const ASSET_TYPE_CONFIG = {