@qontinui/ui-bridge 0.9.1 → 0.10.0

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.mjs CHANGED
@@ -25799,7 +25799,7 @@ function exposeProviderOnWindow(internals) {
25799
25799
  if (typeof window === "undefined") return;
25800
25800
  const w = window;
25801
25801
  const root = w.__UI_BRIDGE__ ?? (w.__UI_BRIDGE__ = {});
25802
- root.version = "0.9.1";
25802
+ root.version = "0.10.0";
25803
25803
  root.specs = { getGlobalSpecStore };
25804
25804
  root.registry = internals.registry;
25805
25805
  root.browserCapture = internals.browserCapture;
@@ -37519,10 +37519,39 @@ function safeJsonStringify(value) {
37519
37519
  });
37520
37520
  }
37521
37521
  var HEARTBEAT_INTERVAL_MS = 1e4;
37522
+ function resolveAuthToken(authHeader) {
37523
+ if (!authHeader) return null;
37524
+ try {
37525
+ const value = authHeader();
37526
+ if (typeof value !== "string") return null;
37527
+ const trimmed = value.trim();
37528
+ return trimmed.length > 0 ? trimmed : null;
37529
+ } catch {
37530
+ return null;
37531
+ }
37532
+ }
37533
+ function transportHeaders(authHeader) {
37534
+ const headers = {
37535
+ "Content-Type": "application/json"
37536
+ };
37537
+ const token = resolveAuthToken(authHeader);
37538
+ if (token) {
37539
+ headers.Authorization = `Bearer ${token}`;
37540
+ }
37541
+ return headers;
37542
+ }
37543
+ function appendAuthQuery(url, authHeader) {
37544
+ const token = resolveAuthToken(authHeader);
37545
+ if (!token) return url;
37546
+ const sep = url.includes("?") ? "&" : "?";
37547
+ return `${url}${sep}_auth=${encodeURIComponent(token)}`;
37548
+ }
37522
37549
  function useCommandRelay(options) {
37523
37550
  const enabled = options?.enabled ?? true;
37524
37551
  const basePath = options?.basePath ?? "/api/ui-bridge";
37525
37552
  const heartbeatIntervalMs = options?.heartbeatInterval ?? HEARTBEAT_INTERVAL_MS;
37553
+ const authHeaderRef = useRef(void 0);
37554
+ authHeaderRef.current = options?.authHeader;
37526
37555
  const uiBridge = useUIBridge();
37527
37556
  const context = useUIBridgeOptional();
37528
37557
  const bridge2 = useMemo(
@@ -37578,7 +37607,7 @@ function useCommandRelay(options) {
37578
37607
  try {
37579
37608
  await fetch(`${basePath}/commands`, {
37580
37609
  method: "POST",
37581
- headers: { "Content-Type": "application/json" },
37610
+ headers: transportHeaders(authHeaderRef.current),
37582
37611
  body: safeJsonStringify({
37583
37612
  commandId,
37584
37613
  success: ok,
@@ -37644,9 +37673,8 @@ function useCommandRelay(options) {
37644
37673
  let isMounted = true;
37645
37674
  const connect = () => {
37646
37675
  if (!isMounted) return;
37647
- const es = new EventSource(
37648
- `${basePath}/commands/stream${tabId ? `?tabId=${encodeURIComponent(tabId)}` : ""}`
37649
- );
37676
+ const baseUrl = `${basePath}/commands/stream${tabId ? `?tabId=${encodeURIComponent(tabId)}` : ""}`;
37677
+ const es = new EventSource(appendAuthQuery(baseUrl, authHeaderRef.current));
37650
37678
  eventSourceRef.current = es;
37651
37679
  es.onmessage = (event) => {
37652
37680
  try {
@@ -37733,7 +37761,7 @@ function useCommandRelay(options) {
37733
37761
  if (heartbeatVersion !== void 0) body.version = heartbeatVersion;
37734
37762
  const resp = await fetch(`${basePath}/heartbeat`, {
37735
37763
  method: "POST",
37736
- headers: { "Content-Type": "application/json" },
37764
+ headers: transportHeaders(authHeaderRef.current),
37737
37765
  body: JSON.stringify(body)
37738
37766
  });
37739
37767
  if (resp.ok) {
@@ -37864,7 +37892,8 @@ function CommandRelayListener(props) {
37864
37892
  appType: props.appType,
37865
37893
  framework: props.framework,
37866
37894
  capabilities: props.capabilities,
37867
- version: props.version
37895
+ version: props.version,
37896
+ authHeader: props.authHeader
37868
37897
  };
37869
37898
  useCommandRelay(options);
37870
37899
  return null;