@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.cjs CHANGED
@@ -66339,6 +66339,9 @@ function useAssetEmbed(assetId, options = {
66339
66339
  const [isLoading, setIsLoading] = React.useState(false);
66340
66340
  const [error2, setError] = React.useState(null);
66341
66341
  const abortRef = React.useRef(null);
66342
+ const tokenRef = React.useRef(token);
66343
+ tokenRef.current = token;
66344
+ const hasToken = !!token;
66342
66345
  React.useEffect(() => {
66343
66346
  var _a2;
66344
66347
  if (!assetId || !backendUrl) {
@@ -66347,7 +66350,8 @@ function useAssetEmbed(assetId, options = {
66347
66350
  setError(null);
66348
66351
  return;
66349
66352
  }
66350
- const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
66353
+ const authContext = hasToken ? "token" : apiKey ?? "anon";
66354
+ const cacheKey = `${assetId}:${readOnly}:${authContext}`;
66351
66355
  const cached = embedCache.get(cacheKey);
66352
66356
  if (cached && cached.expiresAt > Date.now() / 1e3) {
66353
66357
  setEmbedUrl(cached.url);
@@ -66363,8 +66367,9 @@ function useAssetEmbed(assetId, options = {
66363
66367
  setIsLoading(true);
66364
66368
  setError(null);
66365
66369
  const headers = { "Content-Type": "application/json" };
66366
- if (token) {
66367
- headers["Authorization"] = `Bearer ${token}`;
66370
+ const currentToken = tokenRef.current;
66371
+ if (currentToken) {
66372
+ headers["Authorization"] = `Bearer ${currentToken}`;
66368
66373
  } else if (apiKey) {
66369
66374
  headers["X-API-KEY"] = apiKey;
66370
66375
  }
@@ -66384,7 +66389,7 @@ function useAssetEmbed(assetId, options = {
66384
66389
  }
66385
66390
  return res.json();
66386
66391
  }).then((data) => {
66387
- embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
66392
+ embedCache.set(cacheKey, { url: data.embed_url, expiresAt: data.expires_at });
66388
66393
  setEmbedUrl(data.embed_url);
66389
66394
  setIsLoading(false);
66390
66395
  }).catch((err) => {
@@ -66393,7 +66398,7 @@ function useAssetEmbed(assetId, options = {
66393
66398
  setIsLoading(false);
66394
66399
  });
66395
66400
  return () => controller.abort();
66396
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
66401
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, hasToken]);
66397
66402
  return { embedUrl, isLoading, error: error2 };
66398
66403
  }
66399
66404
  const ASSET_TYPE_CONFIG = {