@forgecharts/sdk 1.5.11 → 1.5.12

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/internal.js CHANGED
@@ -10801,6 +10801,7 @@ var LicenseManager = class _LicenseManager {
10801
10801
  payload = null;
10802
10802
  status = "idle";
10803
10803
  failureKind = null;
10804
+ hostState = "unknown";
10804
10805
  subscribers = /* @__PURE__ */ new Set();
10805
10806
  constructor() {
10806
10807
  }
@@ -10930,8 +10931,26 @@ var LicenseManager = class _LicenseManager {
10930
10931
  * unmanaged SDK path) keeps working exactly as before.
10931
10932
  */
10932
10933
  isDataBlocked() {
10934
+ if (this.hostState === "unlicensed") return true;
10935
+ if (this.hostState === "licensed") return false;
10933
10936
  return this.status === "failed" && this.failureKind === "invalid";
10934
10937
  }
10938
+ /** What the host deployment reports about its own licence. */
10939
+ getHostLicenseState() {
10940
+ return this.hostState;
10941
+ }
10942
+ /**
10943
+ * Record the host deployment's answer from GET /api/license.
10944
+ *
10945
+ * Pass 'unlicensed' ONLY when the host answered and said it has no licence.
10946
+ * A network failure, missing apiUrl, or non-OK response must pass 'unknown',
10947
+ * otherwise an outage would blank every chart the deployment serves.
10948
+ */
10949
+ setHostLicenseState(state) {
10950
+ if (this.hostState === state) return;
10951
+ this.hostState = state;
10952
+ this.notify();
10953
+ }
10935
10954
  /**
10936
10955
  * Runs a raw/legacy/partial payload through `migrateLegacyPayload` (fills
10937
10956
  * missing productTier/capabilities/schemaVersion, deterministically, with
@@ -10991,6 +11010,7 @@ var LicenseManager = class _LicenseManager {
10991
11010
  this.payload = null;
10992
11011
  this.status = "idle";
10993
11012
  this.failureKind = null;
11013
+ this.hostState = "unknown";
10994
11014
  this.notify();
10995
11015
  }
10996
11016
  };
@@ -18295,6 +18315,44 @@ function useLicenseDataBlocked() {
18295
18315
  }, []);
18296
18316
  return blocked;
18297
18317
  }
18318
+ function useHostLicense(apiUrl, getAuthToken) {
18319
+ useEffect(() => {
18320
+ if (!apiUrl) return;
18321
+ let cancelled = false;
18322
+ const lm = LicenseManager.getInstance();
18323
+ void (async () => {
18324
+ try {
18325
+ const headers = {};
18326
+ if (getAuthToken) {
18327
+ try {
18328
+ const tok = await getAuthToken();
18329
+ if (tok) headers["Authorization"] = `Bearer ${tok}`;
18330
+ } catch {
18331
+ }
18332
+ }
18333
+ const res = await fetch(`${apiUrl.replace(/\/+$/, "")}/api/license`, { headers });
18334
+ if (cancelled) return;
18335
+ if (!res.ok) {
18336
+ lm.setHostLicenseState("unknown");
18337
+ return;
18338
+ }
18339
+ const data = await res.json();
18340
+ if (cancelled) return;
18341
+ if (data.licensePayload && typeof data.licensePayload === "object") {
18342
+ lm.loadLicense(data.licensePayload);
18343
+ lm.setHostLicenseState("licensed");
18344
+ } else {
18345
+ lm.setHostLicenseState("unlicensed");
18346
+ }
18347
+ } catch {
18348
+ if (!cancelled) lm.setHostLicenseState("unknown");
18349
+ }
18350
+ })();
18351
+ return () => {
18352
+ cancelled = true;
18353
+ };
18354
+ }, [apiUrl, getAuthToken]);
18355
+ }
18298
18356
  function LicenseRequiredOverlay({
18299
18357
  reason,
18300
18358
  onOpenLicenseSettings
@@ -22874,6 +22932,7 @@ var ChartCanvas = forwardRef(
22874
22932
  const [panes, setPanes] = useState([]);
22875
22933
  const capabilities = useChartCapabilities();
22876
22934
  const dataBlocked = useLicenseDataBlocked();
22935
+ useHostLicense(apiUrl, getAuthToken);
22877
22936
  const [indicators, setIndicators] = useState([]);
22878
22937
  const [totalHeight, setTotalHeight] = useState(600);
22879
22938
  const [activeTool, setActiveTool] = useState(initialActiveTool ?? "cursor");