@viasoftbr/shared-ui 0.0.7-2 → 0.0.7-3

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.
@@ -25547,19 +25547,24 @@ function formatAxiosError(err) {
25547
25547
  return err instanceof Error ? err : new Error(String(err));
25548
25548
  }
25549
25549
  var fetchApi = {
25550
- getJson: async (path, params, headers) => {
25550
+ getJson: async (path, params, headersOrOptions) => {
25551
25551
  try {
25552
- const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
25552
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
25553
+ const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
25554
+ params: withTokenQueryParams(requestOptions),
25555
+ headers: requestOptions.headers
25556
+ });
25553
25557
  return response.data;
25554
25558
  } catch (e10) {
25555
25559
  throw formatAxiosError(e10);
25556
25560
  }
25557
25561
  },
25558
- getText: async (path, params, headers) => {
25562
+ getText: async (path, params, headersOrOptions) => {
25559
25563
  try {
25564
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
25560
25565
  const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
25561
- params,
25562
- headers,
25566
+ params: withTokenQueryParams(requestOptions),
25567
+ headers: requestOptions.headers,
25563
25568
  responseType: "text"
25564
25569
  });
25565
25570
  return response.data;
@@ -25567,78 +25572,152 @@ var fetchApi = {
25567
25572
  throw formatAxiosError(e10);
25568
25573
  }
25569
25574
  },
25570
- getVoid: async (path, params, headers) => {
25575
+ getVoid: async (path, params, headersOrOptions) => {
25571
25576
  try {
25572
- await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
25577
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
25578
+ await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
25579
+ params: withTokenQueryParams(requestOptions),
25580
+ headers: requestOptions.headers
25581
+ });
25573
25582
  } catch (e10) {
25574
25583
  throw formatAxiosError(e10);
25575
25584
  }
25576
25585
  },
25577
- postJson: async (path, payload, headers) => {
25586
+ postJson: async (path, payload, headersOrOptions) => {
25578
25587
  try {
25579
- const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, { headers });
25588
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25589
+ const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
25590
+ headers: requestOptions.headers,
25591
+ params: withTokenQueryParams(requestOptions)
25592
+ });
25580
25593
  return response.data;
25581
25594
  } catch (e10) {
25582
25595
  throw formatAxiosError(e10);
25583
25596
  }
25584
25597
  },
25585
- patchJson: async (path, payload, headers) => {
25598
+ patchJson: async (path, payload, headersOrOptions) => {
25586
25599
  try {
25587
- const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, { headers });
25600
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25601
+ const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
25602
+ headers: requestOptions.headers,
25603
+ params: withTokenQueryParams(requestOptions)
25604
+ });
25588
25605
  return response.data;
25589
25606
  } catch (e10) {
25590
25607
  throw formatAxiosError(e10);
25591
25608
  }
25592
25609
  },
25593
- putJson: async (path, payload, headers) => {
25610
+ putJson: async (path, payload, headersOrOptions) => {
25594
25611
  try {
25595
- const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, { headers });
25612
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25613
+ const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
25614
+ headers: requestOptions.headers,
25615
+ params: withTokenQueryParams(requestOptions)
25616
+ });
25596
25617
  return response.data;
25597
25618
  } catch (e10) {
25598
25619
  throw formatAxiosError(e10);
25599
25620
  }
25600
25621
  },
25601
- deleteJson: async (path, headers) => {
25622
+ deleteJson: async (path, headersOrOptions) => {
25602
25623
  try {
25603
- const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
25624
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25625
+ const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
25626
+ headers: requestOptions.headers,
25627
+ params: withTokenQueryParams(requestOptions)
25628
+ });
25604
25629
  return response.data;
25605
25630
  } catch (e10) {
25606
25631
  throw formatAxiosError(e10);
25607
25632
  }
25608
25633
  },
25609
- deleteVoid: async (path, headers) => {
25634
+ deleteVoid: async (path, headersOrOptions) => {
25610
25635
  try {
25611
- await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
25636
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25637
+ await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
25638
+ headers: requestOptions.headers,
25639
+ params: withTokenQueryParams(requestOptions)
25640
+ });
25612
25641
  } catch (e10) {
25613
25642
  throw formatAxiosError(e10);
25614
25643
  }
25615
25644
  }
25616
25645
  };
25617
- function buildWsUrl(path = "/") {
25646
+ function buildWsUrl(path = "/", options = {}) {
25618
25647
  try {
25619
25648
  const origin2 = new URL(apiOrigin);
25620
25649
  origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
25621
25650
  if (!path.startsWith("/"))
25622
25651
  path = "/" + path;
25623
25652
  origin2.pathname = path;
25624
- return origin2.toString();
25653
+ return withAccessTokenQuery(origin2.toString(), {
25654
+ headers: options.headers,
25655
+ params: options.query,
25656
+ token: options.token ?? options.bearerToken,
25657
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
25658
+ includeStoredToken: options.includeStoredToken
25659
+ });
25625
25660
  } catch (e10) {
25626
25661
  const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
25627
25662
  const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
25628
- return `${proto}://${host}${path.startsWith("/") ? path : "/" + path}`;
25663
+ return withAccessTokenQuery(
25664
+ `${proto}://${host}${path.startsWith("/") ? path : "/" + path}`,
25665
+ {
25666
+ headers: options.headers,
25667
+ params: options.query,
25668
+ token: options.token ?? options.bearerToken,
25669
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
25670
+ includeStoredToken: options.includeStoredToken
25671
+ }
25672
+ );
25629
25673
  }
25630
25674
  }
25631
- function appendWsQueryParam(url, key, value) {
25675
+ function extractBearerToken(headers, explicitToken) {
25676
+ if (explicitToken)
25677
+ return explicitToken;
25678
+ if (!headers)
25679
+ return null;
25680
+ const authHeader = headers.Authorization || headers.authorization;
25681
+ if (!authHeader)
25682
+ return null;
25683
+ const match = authHeader.match(/^Bearer\s+(.+)$/i);
25684
+ return match ? match[1] : null;
25685
+ }
25686
+ function resolveAuthToken(options = {}) {
25687
+ const explicitToken = options.token ?? options.bearerToken ?? null;
25688
+ const headerToken = extractBearerToken(options.headers, explicitToken);
25689
+ if (headerToken)
25690
+ return headerToken;
25691
+ if (options.includeStoredToken === false)
25692
+ return null;
25693
+ return getAccessToken();
25694
+ }
25695
+ function mergeQueryParams(params, key, value) {
25696
+ const nextParams = { ...params ?? {} };
25697
+ if (key && value)
25698
+ nextParams[key] = value;
25699
+ return Object.keys(nextParams).length > 0 ? nextParams : void 0;
25700
+ }
25701
+ function appendQueryParams(url, params) {
25702
+ if (!params || Object.keys(params).length === 0)
25703
+ return url;
25632
25704
  try {
25633
25705
  const parsed = new URL(
25634
25706
  url,
25635
25707
  typeof window !== "undefined" ? window.location.href : void 0
25636
25708
  );
25637
- parsed.searchParams.set(key, value);
25709
+ for (const [key, value] of Object.entries(params)) {
25710
+ if (value === void 0 || value === null)
25711
+ continue;
25712
+ parsed.searchParams.set(key, String(value));
25713
+ }
25638
25714
  return parsed.toString();
25639
25715
  } catch {
25716
+ const search = Object.entries(params).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
25717
+ if (!search)
25718
+ return url;
25640
25719
  const separator = url.includes("?") ? "&" : "?";
25641
- return `${url}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
25720
+ return `${url}${separator}${search}`;
25642
25721
  }
25643
25722
  }
25644
25723
  function normalizeProtocols(protocols) {
@@ -25646,31 +25725,67 @@ function normalizeProtocols(protocols) {
25646
25725
  return void 0;
25647
25726
  return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
25648
25727
  }
25728
+ function normalizeRequestOptions(params, headersOrOptions) {
25729
+ const maybeOptions = headersOrOptions;
25730
+ const hasOptionShape = Boolean(
25731
+ maybeOptions && ("headers" in maybeOptions || "params" in maybeOptions || "sendTokenInQuery" in maybeOptions || "token" in maybeOptions || "tokenQueryParam" in maybeOptions || "includeStoredToken" in maybeOptions)
25732
+ );
25733
+ if (hasOptionShape) {
25734
+ return {
25735
+ ...maybeOptions,
25736
+ params: { ...params ?? {}, ...maybeOptions?.params ?? {} }
25737
+ };
25738
+ }
25739
+ return {
25740
+ params,
25741
+ headers: headersOrOptions
25742
+ };
25743
+ }
25744
+ function withTokenQueryParams(options) {
25745
+ if (!options.sendTokenInQuery)
25746
+ return options.params;
25747
+ const token = resolveAuthToken(options);
25748
+ return mergeQueryParams(
25749
+ options.params,
25750
+ options.tokenQueryParam ?? "access_token",
25751
+ token
25752
+ );
25753
+ }
25754
+ function withAccessTokenQuery(url, options = {}) {
25755
+ const token = resolveAuthToken(options);
25756
+ return appendQueryParams(
25757
+ url,
25758
+ mergeQueryParams(options.params, options.tokenQueryParam ?? "access_token", token)
25759
+ );
25760
+ }
25649
25761
  async function decodeFfurl(ffurl) {
25650
25762
  const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
25651
25763
  return settings;
25652
25764
  }
25653
- function resolveWsBearerToken(options) {
25654
- if (options.bearerToken)
25655
- return options.bearerToken;
25656
- if (options.autoAuth)
25657
- return getAccessToken();
25658
- return null;
25659
- }
25660
25765
  function subscribeToWebsocket(url, onMessage, options = {}) {
25661
- const token = resolveWsBearerToken(options);
25662
- const strategy = options.bearerStrategy ?? "query";
25766
+ const bearerToken = resolveAuthToken({
25767
+ headers: options.headers,
25768
+ token: options.token,
25769
+ bearerToken: options.bearerToken,
25770
+ includeStoredToken: options.includeStoredToken
25771
+ });
25772
+ const bearerStrategy = options.tokenTransport ?? options.bearerStrategy ?? "query";
25773
+ let resolvedUrl = appendQueryParams(url, options.query);
25663
25774
  const protocols = normalizeProtocols(options.protocols) ?? [];
25664
- let resolvedUrl = url;
25665
- if (token) {
25666
- if (strategy === "protocol") {
25667
- protocols.push("bearer", token);
25775
+ if (options.headers && Object.keys(options.headers).length > 0) {
25776
+ console.warn(
25777
+ "WebSocket connections in browsers do not support custom HTTP headers. shared-ui will derive bearer auth from Authorization and forward it using query string or subprotocol."
25778
+ );
25779
+ }
25780
+ if (bearerToken) {
25781
+ if (bearerStrategy === "protocol") {
25782
+ protocols.push("bearer", bearerToken);
25668
25783
  } else {
25669
- resolvedUrl = appendWsQueryParam(
25670
- url,
25671
- options.bearerQueryParam ?? "access_token",
25672
- token
25673
- );
25784
+ resolvedUrl = withAccessTokenQuery(resolvedUrl, {
25785
+ token: bearerToken,
25786
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
25787
+ includeStoredToken: false
25788
+ });
25674
25789
  }
25675
25790
  }
25676
25791
  const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
@@ -25679,7 +25794,7 @@ function subscribeToWebsocket(url, onMessage, options = {}) {
25679
25794
  const data = JSON.parse(event.data);
25680
25795
  onMessage(data);
25681
25796
  } catch (e10) {
25682
- console.error("WebSocket parse error", e10);
25797
+ console.error("Parse error", e10);
25683
25798
  }
25684
25799
  };
25685
25800
  socket.onerror = (err) => console.error("WebSocket error", err);
@@ -25490,19 +25490,24 @@ function formatAxiosError(err) {
25490
25490
  return err instanceof Error ? err : new Error(String(err));
25491
25491
  }
25492
25492
  var fetchApi = {
25493
- getJson: async (path, params, headers) => {
25493
+ getJson: async (path, params, headersOrOptions) => {
25494
25494
  try {
25495
- const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
25495
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
25496
+ const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
25497
+ params: withTokenQueryParams(requestOptions),
25498
+ headers: requestOptions.headers
25499
+ });
25496
25500
  return response.data;
25497
25501
  } catch (e10) {
25498
25502
  throw formatAxiosError(e10);
25499
25503
  }
25500
25504
  },
25501
- getText: async (path, params, headers) => {
25505
+ getText: async (path, params, headersOrOptions) => {
25502
25506
  try {
25507
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
25503
25508
  const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
25504
- params,
25505
- headers,
25509
+ params: withTokenQueryParams(requestOptions),
25510
+ headers: requestOptions.headers,
25506
25511
  responseType: "text"
25507
25512
  });
25508
25513
  return response.data;
@@ -25510,78 +25515,152 @@ var fetchApi = {
25510
25515
  throw formatAxiosError(e10);
25511
25516
  }
25512
25517
  },
25513
- getVoid: async (path, params, headers) => {
25518
+ getVoid: async (path, params, headersOrOptions) => {
25514
25519
  try {
25515
- await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
25520
+ const requestOptions = normalizeRequestOptions(params, headersOrOptions);
25521
+ await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
25522
+ params: withTokenQueryParams(requestOptions),
25523
+ headers: requestOptions.headers
25524
+ });
25516
25525
  } catch (e10) {
25517
25526
  throw formatAxiosError(e10);
25518
25527
  }
25519
25528
  },
25520
- postJson: async (path, payload, headers) => {
25529
+ postJson: async (path, payload, headersOrOptions) => {
25521
25530
  try {
25522
- const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, { headers });
25531
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25532
+ const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
25533
+ headers: requestOptions.headers,
25534
+ params: withTokenQueryParams(requestOptions)
25535
+ });
25523
25536
  return response.data;
25524
25537
  } catch (e10) {
25525
25538
  throw formatAxiosError(e10);
25526
25539
  }
25527
25540
  },
25528
- patchJson: async (path, payload, headers) => {
25541
+ patchJson: async (path, payload, headersOrOptions) => {
25529
25542
  try {
25530
- const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, { headers });
25543
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25544
+ const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
25545
+ headers: requestOptions.headers,
25546
+ params: withTokenQueryParams(requestOptions)
25547
+ });
25531
25548
  return response.data;
25532
25549
  } catch (e10) {
25533
25550
  throw formatAxiosError(e10);
25534
25551
  }
25535
25552
  },
25536
- putJson: async (path, payload, headers) => {
25553
+ putJson: async (path, payload, headersOrOptions) => {
25537
25554
  try {
25538
- const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, { headers });
25555
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25556
+ const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
25557
+ headers: requestOptions.headers,
25558
+ params: withTokenQueryParams(requestOptions)
25559
+ });
25539
25560
  return response.data;
25540
25561
  } catch (e10) {
25541
25562
  throw formatAxiosError(e10);
25542
25563
  }
25543
25564
  },
25544
- deleteJson: async (path, headers) => {
25565
+ deleteJson: async (path, headersOrOptions) => {
25545
25566
  try {
25546
- const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
25567
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25568
+ const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
25569
+ headers: requestOptions.headers,
25570
+ params: withTokenQueryParams(requestOptions)
25571
+ });
25547
25572
  return response.data;
25548
25573
  } catch (e10) {
25549
25574
  throw formatAxiosError(e10);
25550
25575
  }
25551
25576
  },
25552
- deleteVoid: async (path, headers) => {
25577
+ deleteVoid: async (path, headersOrOptions) => {
25553
25578
  try {
25554
- await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
25579
+ const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
25580
+ await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
25581
+ headers: requestOptions.headers,
25582
+ params: withTokenQueryParams(requestOptions)
25583
+ });
25555
25584
  } catch (e10) {
25556
25585
  throw formatAxiosError(e10);
25557
25586
  }
25558
25587
  }
25559
25588
  };
25560
- function buildWsUrl(path = "/") {
25589
+ function buildWsUrl(path = "/", options = {}) {
25561
25590
  try {
25562
25591
  const origin2 = new URL(apiOrigin);
25563
25592
  origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
25564
25593
  if (!path.startsWith("/"))
25565
25594
  path = "/" + path;
25566
25595
  origin2.pathname = path;
25567
- return origin2.toString();
25596
+ return withAccessTokenQuery(origin2.toString(), {
25597
+ headers: options.headers,
25598
+ params: options.query,
25599
+ token: options.token ?? options.bearerToken,
25600
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
25601
+ includeStoredToken: options.includeStoredToken
25602
+ });
25568
25603
  } catch (e10) {
25569
25604
  const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
25570
25605
  const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
25571
- return `${proto}://${host}${path.startsWith("/") ? path : "/" + path}`;
25606
+ return withAccessTokenQuery(
25607
+ `${proto}://${host}${path.startsWith("/") ? path : "/" + path}`,
25608
+ {
25609
+ headers: options.headers,
25610
+ params: options.query,
25611
+ token: options.token ?? options.bearerToken,
25612
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
25613
+ includeStoredToken: options.includeStoredToken
25614
+ }
25615
+ );
25572
25616
  }
25573
25617
  }
25574
- function appendWsQueryParam(url, key, value) {
25618
+ function extractBearerToken(headers, explicitToken) {
25619
+ if (explicitToken)
25620
+ return explicitToken;
25621
+ if (!headers)
25622
+ return null;
25623
+ const authHeader = headers.Authorization || headers.authorization;
25624
+ if (!authHeader)
25625
+ return null;
25626
+ const match = authHeader.match(/^Bearer\s+(.+)$/i);
25627
+ return match ? match[1] : null;
25628
+ }
25629
+ function resolveAuthToken(options = {}) {
25630
+ const explicitToken = options.token ?? options.bearerToken ?? null;
25631
+ const headerToken = extractBearerToken(options.headers, explicitToken);
25632
+ if (headerToken)
25633
+ return headerToken;
25634
+ if (options.includeStoredToken === false)
25635
+ return null;
25636
+ return getAccessToken();
25637
+ }
25638
+ function mergeQueryParams(params, key, value) {
25639
+ const nextParams = { ...params ?? {} };
25640
+ if (key && value)
25641
+ nextParams[key] = value;
25642
+ return Object.keys(nextParams).length > 0 ? nextParams : void 0;
25643
+ }
25644
+ function appendQueryParams(url, params) {
25645
+ if (!params || Object.keys(params).length === 0)
25646
+ return url;
25575
25647
  try {
25576
25648
  const parsed = new URL(
25577
25649
  url,
25578
25650
  typeof window !== "undefined" ? window.location.href : void 0
25579
25651
  );
25580
- parsed.searchParams.set(key, value);
25652
+ for (const [key, value] of Object.entries(params)) {
25653
+ if (value === void 0 || value === null)
25654
+ continue;
25655
+ parsed.searchParams.set(key, String(value));
25656
+ }
25581
25657
  return parsed.toString();
25582
25658
  } catch {
25659
+ const search = Object.entries(params).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
25660
+ if (!search)
25661
+ return url;
25583
25662
  const separator = url.includes("?") ? "&" : "?";
25584
- return `${url}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
25663
+ return `${url}${separator}${search}`;
25585
25664
  }
25586
25665
  }
25587
25666
  function normalizeProtocols(protocols) {
@@ -25589,31 +25668,67 @@ function normalizeProtocols(protocols) {
25589
25668
  return void 0;
25590
25669
  return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
25591
25670
  }
25671
+ function normalizeRequestOptions(params, headersOrOptions) {
25672
+ const maybeOptions = headersOrOptions;
25673
+ const hasOptionShape = Boolean(
25674
+ maybeOptions && ("headers" in maybeOptions || "params" in maybeOptions || "sendTokenInQuery" in maybeOptions || "token" in maybeOptions || "tokenQueryParam" in maybeOptions || "includeStoredToken" in maybeOptions)
25675
+ );
25676
+ if (hasOptionShape) {
25677
+ return {
25678
+ ...maybeOptions,
25679
+ params: { ...params ?? {}, ...maybeOptions?.params ?? {} }
25680
+ };
25681
+ }
25682
+ return {
25683
+ params,
25684
+ headers: headersOrOptions
25685
+ };
25686
+ }
25687
+ function withTokenQueryParams(options) {
25688
+ if (!options.sendTokenInQuery)
25689
+ return options.params;
25690
+ const token = resolveAuthToken(options);
25691
+ return mergeQueryParams(
25692
+ options.params,
25693
+ options.tokenQueryParam ?? "access_token",
25694
+ token
25695
+ );
25696
+ }
25697
+ function withAccessTokenQuery(url, options = {}) {
25698
+ const token = resolveAuthToken(options);
25699
+ return appendQueryParams(
25700
+ url,
25701
+ mergeQueryParams(options.params, options.tokenQueryParam ?? "access_token", token)
25702
+ );
25703
+ }
25592
25704
  async function decodeFfurl(ffurl) {
25593
25705
  const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
25594
25706
  return settings;
25595
25707
  }
25596
- function resolveWsBearerToken(options) {
25597
- if (options.bearerToken)
25598
- return options.bearerToken;
25599
- if (options.autoAuth)
25600
- return getAccessToken();
25601
- return null;
25602
- }
25603
25708
  function subscribeToWebsocket(url, onMessage, options = {}) {
25604
- const token = resolveWsBearerToken(options);
25605
- const strategy = options.bearerStrategy ?? "query";
25709
+ const bearerToken = resolveAuthToken({
25710
+ headers: options.headers,
25711
+ token: options.token,
25712
+ bearerToken: options.bearerToken,
25713
+ includeStoredToken: options.includeStoredToken
25714
+ });
25715
+ const bearerStrategy = options.tokenTransport ?? options.bearerStrategy ?? "query";
25716
+ let resolvedUrl = appendQueryParams(url, options.query);
25606
25717
  const protocols = normalizeProtocols(options.protocols) ?? [];
25607
- let resolvedUrl = url;
25608
- if (token) {
25609
- if (strategy === "protocol") {
25610
- protocols.push("bearer", token);
25718
+ if (options.headers && Object.keys(options.headers).length > 0) {
25719
+ console.warn(
25720
+ "WebSocket connections in browsers do not support custom HTTP headers. shared-ui will derive bearer auth from Authorization and forward it using query string or subprotocol."
25721
+ );
25722
+ }
25723
+ if (bearerToken) {
25724
+ if (bearerStrategy === "protocol") {
25725
+ protocols.push("bearer", bearerToken);
25611
25726
  } else {
25612
- resolvedUrl = appendWsQueryParam(
25613
- url,
25614
- options.bearerQueryParam ?? "access_token",
25615
- token
25616
- );
25727
+ resolvedUrl = withAccessTokenQuery(resolvedUrl, {
25728
+ token: bearerToken,
25729
+ tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
25730
+ includeStoredToken: false
25731
+ });
25617
25732
  }
25618
25733
  }
25619
25734
  const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
@@ -25622,7 +25737,7 @@ function subscribeToWebsocket(url, onMessage, options = {}) {
25622
25737
  const data = JSON.parse(event.data);
25623
25738
  onMessage(data);
25624
25739
  } catch (e10) {
25625
- console.error("WebSocket parse error", e10);
25740
+ console.error("Parse error", e10);
25626
25741
  }
25627
25742
  };
25628
25743
  socket.onerror = (err) => console.error("WebSocket error", err);