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