@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.
@@ -24946,7 +24946,7 @@ function exposeProviderOnWindow(internals) {
24946
24946
  if (typeof window === "undefined") return;
24947
24947
  const w = window;
24948
24948
  const root = w.__UI_BRIDGE__ ?? (w.__UI_BRIDGE__ = {});
24949
- root.version = "0.9.1";
24949
+ root.version = "0.10.0";
24950
24950
  root.specs = { getGlobalSpecStore };
24951
24951
  root.registry = internals.registry;
24952
24952
  root.browserCapture = internals.browserCapture;
@@ -32909,10 +32909,39 @@ function safeJsonStringify(value) {
32909
32909
  });
32910
32910
  }
32911
32911
  var HEARTBEAT_INTERVAL_MS = 1e4;
32912
+ function resolveAuthToken(authHeader) {
32913
+ if (!authHeader) return null;
32914
+ try {
32915
+ const value = authHeader();
32916
+ if (typeof value !== "string") return null;
32917
+ const trimmed = value.trim();
32918
+ return trimmed.length > 0 ? trimmed : null;
32919
+ } catch {
32920
+ return null;
32921
+ }
32922
+ }
32923
+ function transportHeaders(authHeader) {
32924
+ const headers = {
32925
+ "Content-Type": "application/json"
32926
+ };
32927
+ const token = resolveAuthToken(authHeader);
32928
+ if (token) {
32929
+ headers.Authorization = `Bearer ${token}`;
32930
+ }
32931
+ return headers;
32932
+ }
32933
+ function appendAuthQuery(url, authHeader) {
32934
+ const token = resolveAuthToken(authHeader);
32935
+ if (!token) return url;
32936
+ const sep = url.includes("?") ? "&" : "?";
32937
+ return `${url}${sep}_auth=${encodeURIComponent(token)}`;
32938
+ }
32912
32939
  function useCommandRelay(options) {
32913
32940
  const enabled = options?.enabled ?? true;
32914
32941
  const basePath = options?.basePath ?? "/api/ui-bridge";
32915
32942
  const heartbeatIntervalMs = options?.heartbeatInterval ?? HEARTBEAT_INTERVAL_MS;
32943
+ const authHeaderRef = useRef(void 0);
32944
+ authHeaderRef.current = options?.authHeader;
32916
32945
  const uiBridge = useUIBridge();
32917
32946
  const context = useUIBridgeOptional();
32918
32947
  const bridge2 = useMemo(
@@ -32968,7 +32997,7 @@ function useCommandRelay(options) {
32968
32997
  try {
32969
32998
  await fetch(`${basePath}/commands`, {
32970
32999
  method: "POST",
32971
- headers: { "Content-Type": "application/json" },
33000
+ headers: transportHeaders(authHeaderRef.current),
32972
33001
  body: safeJsonStringify({
32973
33002
  commandId,
32974
33003
  success: ok,
@@ -33034,9 +33063,8 @@ function useCommandRelay(options) {
33034
33063
  let isMounted = true;
33035
33064
  const connect = () => {
33036
33065
  if (!isMounted) return;
33037
- const es = new EventSource(
33038
- `${basePath}/commands/stream${tabId ? `?tabId=${encodeURIComponent(tabId)}` : ""}`
33039
- );
33066
+ const baseUrl = `${basePath}/commands/stream${tabId ? `?tabId=${encodeURIComponent(tabId)}` : ""}`;
33067
+ const es = new EventSource(appendAuthQuery(baseUrl, authHeaderRef.current));
33040
33068
  eventSourceRef.current = es;
33041
33069
  es.onmessage = (event) => {
33042
33070
  try {
@@ -33123,7 +33151,7 @@ function useCommandRelay(options) {
33123
33151
  if (heartbeatVersion !== void 0) body.version = heartbeatVersion;
33124
33152
  const resp = await fetch(`${basePath}/heartbeat`, {
33125
33153
  method: "POST",
33126
- headers: { "Content-Type": "application/json" },
33154
+ headers: transportHeaders(authHeaderRef.current),
33127
33155
  body: JSON.stringify(body)
33128
33156
  });
33129
33157
  if (resp.ok) {
@@ -33254,7 +33282,8 @@ function CommandRelayListener(props) {
33254
33282
  appType: props.appType,
33255
33283
  framework: props.framework,
33256
33284
  capabilities: props.capabilities,
33257
- version: props.version
33285
+ version: props.version,
33286
+ authHeader: props.authHeader
33258
33287
  };
33259
33288
  useCommandRelay(options);
33260
33289
  return null;