@viasoftbr/shared-ui 0.0.7-4 → 0.0.7-6
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/components.cjs +45 -121
- package/dist/components.js +45 -121
- package/dist/hooks.cjs +18 -88
- package/dist/hooks.js +18 -88
- package/dist/index.cjs +46 -123
- package/dist/index.js +46 -123
- package/dist/services/api.d.ts +9 -18
- package/dist/services.cjs +46 -123
- package/dist/services.js +46 -123
- package/dist/types/websocket.d.ts +5 -8
- package/package.json +1 -1
package/dist/components.cjs
CHANGED
|
@@ -25547,24 +25547,22 @@ 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,
|
|
25550
|
+
getJson: async (path, params, headers) => {
|
|
25551
25551
|
try {
|
|
25552
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
25553
25552
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
25554
|
-
params
|
|
25555
|
-
headers
|
|
25553
|
+
params,
|
|
25554
|
+
headers
|
|
25556
25555
|
});
|
|
25557
25556
|
return response.data;
|
|
25558
25557
|
} catch (e10) {
|
|
25559
25558
|
throw formatAxiosError(e10);
|
|
25560
25559
|
}
|
|
25561
25560
|
},
|
|
25562
|
-
getText: async (path, params,
|
|
25561
|
+
getText: async (path, params, headers) => {
|
|
25563
25562
|
try {
|
|
25564
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
25565
25563
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
25566
|
-
params
|
|
25567
|
-
headers
|
|
25564
|
+
params,
|
|
25565
|
+
headers,
|
|
25568
25566
|
responseType: "text"
|
|
25569
25567
|
});
|
|
25570
25568
|
return response.data;
|
|
@@ -25572,106 +25570,61 @@ var fetchApi = {
|
|
|
25572
25570
|
throw formatAxiosError(e10);
|
|
25573
25571
|
}
|
|
25574
25572
|
},
|
|
25575
|
-
getVoid: async (path, params,
|
|
25573
|
+
getVoid: async (path, params, headers) => {
|
|
25576
25574
|
try {
|
|
25577
|
-
|
|
25578
|
-
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
25579
|
-
params: withTokenQueryParams(requestOptions),
|
|
25580
|
-
headers: requestOptions.headers
|
|
25581
|
-
});
|
|
25575
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
|
|
25582
25576
|
} catch (e10) {
|
|
25583
25577
|
throw formatAxiosError(e10);
|
|
25584
25578
|
}
|
|
25585
25579
|
},
|
|
25586
|
-
postJson: async (path, payload,
|
|
25580
|
+
postJson: async (path, payload, headers) => {
|
|
25587
25581
|
try {
|
|
25588
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25589
25582
|
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
25590
|
-
headers
|
|
25591
|
-
params: withTokenQueryParams(requestOptions)
|
|
25583
|
+
headers
|
|
25592
25584
|
});
|
|
25593
25585
|
return response.data;
|
|
25594
25586
|
} catch (e10) {
|
|
25595
25587
|
throw formatAxiosError(e10);
|
|
25596
25588
|
}
|
|
25597
25589
|
},
|
|
25598
|
-
patchJson: async (path, payload,
|
|
25590
|
+
patchJson: async (path, payload, headers) => {
|
|
25599
25591
|
try {
|
|
25600
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25601
25592
|
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
25602
|
-
headers
|
|
25603
|
-
params: withTokenQueryParams(requestOptions)
|
|
25593
|
+
headers
|
|
25604
25594
|
});
|
|
25605
25595
|
return response.data;
|
|
25606
25596
|
} catch (e10) {
|
|
25607
25597
|
throw formatAxiosError(e10);
|
|
25608
25598
|
}
|
|
25609
25599
|
},
|
|
25610
|
-
putJson: async (path, payload,
|
|
25600
|
+
putJson: async (path, payload, headers) => {
|
|
25611
25601
|
try {
|
|
25612
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25613
25602
|
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
25614
|
-
headers
|
|
25615
|
-
params: withTokenQueryParams(requestOptions)
|
|
25603
|
+
headers
|
|
25616
25604
|
});
|
|
25617
25605
|
return response.data;
|
|
25618
25606
|
} catch (e10) {
|
|
25619
25607
|
throw formatAxiosError(e10);
|
|
25620
25608
|
}
|
|
25621
25609
|
},
|
|
25622
|
-
deleteJson: async (path,
|
|
25610
|
+
deleteJson: async (path, headers) => {
|
|
25623
25611
|
try {
|
|
25624
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25625
25612
|
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
25626
|
-
headers
|
|
25627
|
-
params: withTokenQueryParams(requestOptions)
|
|
25613
|
+
headers
|
|
25628
25614
|
});
|
|
25629
25615
|
return response.data;
|
|
25630
25616
|
} catch (e10) {
|
|
25631
25617
|
throw formatAxiosError(e10);
|
|
25632
25618
|
}
|
|
25633
25619
|
},
|
|
25634
|
-
deleteVoid: async (path,
|
|
25620
|
+
deleteVoid: async (path, headers) => {
|
|
25635
25621
|
try {
|
|
25636
|
-
|
|
25637
|
-
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
25638
|
-
headers: requestOptions.headers,
|
|
25639
|
-
params: withTokenQueryParams(requestOptions)
|
|
25640
|
-
});
|
|
25622
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
|
|
25641
25623
|
} catch (e10) {
|
|
25642
25624
|
throw formatAxiosError(e10);
|
|
25643
25625
|
}
|
|
25644
25626
|
}
|
|
25645
25627
|
};
|
|
25646
|
-
function buildWsUrl(path = "/", options = {}) {
|
|
25647
|
-
try {
|
|
25648
|
-
const origin2 = new URL(apiOrigin);
|
|
25649
|
-
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
25650
|
-
if (!path.startsWith("/"))
|
|
25651
|
-
path = "/" + path;
|
|
25652
|
-
origin2.pathname = path;
|
|
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
|
-
});
|
|
25660
|
-
} catch (e10) {
|
|
25661
|
-
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
25662
|
-
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
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
|
-
);
|
|
25673
|
-
}
|
|
25674
|
-
}
|
|
25675
25628
|
function extractBearerToken(headers, explicitToken) {
|
|
25676
25629
|
if (explicitToken)
|
|
25677
25630
|
return explicitToken;
|
|
@@ -25683,7 +25636,7 @@ function extractBearerToken(headers, explicitToken) {
|
|
|
25683
25636
|
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
25684
25637
|
return match ? match[1] : null;
|
|
25685
25638
|
}
|
|
25686
|
-
function
|
|
25639
|
+
function resolveWebSocketToken(options = {}) {
|
|
25687
25640
|
const explicitToken = options.token ?? options.bearerToken ?? null;
|
|
25688
25641
|
const headerToken = extractBearerToken(options.headers, explicitToken);
|
|
25689
25642
|
if (headerToken)
|
|
@@ -25692,12 +25645,6 @@ function resolveAuthToken(options = {}) {
|
|
|
25692
25645
|
return null;
|
|
25693
25646
|
return getAccessToken();
|
|
25694
25647
|
}
|
|
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
25648
|
function appendQueryParams(url, params) {
|
|
25702
25649
|
if (!params || Object.keys(params).length === 0)
|
|
25703
25650
|
return url;
|
|
@@ -25720,73 +25667,50 @@ function appendQueryParams(url, params) {
|
|
|
25720
25667
|
return `${url}${separator}${search}`;
|
|
25721
25668
|
}
|
|
25722
25669
|
}
|
|
25670
|
+
function withWebSocketTokenQuery(url, options) {
|
|
25671
|
+
const token = resolveWebSocketToken(options);
|
|
25672
|
+
const params = { ...options.query ?? {} };
|
|
25673
|
+
if (token) {
|
|
25674
|
+
params[options.tokenQueryParam ?? options.bearerQueryParam ?? "token"] = token;
|
|
25675
|
+
}
|
|
25676
|
+
return appendQueryParams(url, params);
|
|
25677
|
+
}
|
|
25723
25678
|
function normalizeProtocols(protocols) {
|
|
25724
25679
|
if (!protocols)
|
|
25725
25680
|
return void 0;
|
|
25726
25681
|
return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
|
|
25727
25682
|
}
|
|
25728
|
-
function
|
|
25729
|
-
|
|
25730
|
-
|
|
25731
|
-
|
|
25732
|
-
|
|
25733
|
-
|
|
25734
|
-
|
|
25735
|
-
|
|
25736
|
-
|
|
25737
|
-
|
|
25683
|
+
function buildWsUrl(path = "/", options = {}) {
|
|
25684
|
+
try {
|
|
25685
|
+
const origin2 = new URL(apiOrigin);
|
|
25686
|
+
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
25687
|
+
if (!path.startsWith("/"))
|
|
25688
|
+
path = "/" + path;
|
|
25689
|
+
origin2.pathname = path;
|
|
25690
|
+
return withWebSocketTokenQuery(origin2.toString(), options);
|
|
25691
|
+
} catch (e10) {
|
|
25692
|
+
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
25693
|
+
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
25694
|
+
return withWebSocketTokenQuery(`${proto}://${host}${path.startsWith("/") ? path : "/" + path}`, options);
|
|
25738
25695
|
}
|
|
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
25696
|
}
|
|
25761
25697
|
async function decodeFfurl(ffurl) {
|
|
25762
25698
|
const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
|
|
25763
25699
|
return settings;
|
|
25764
25700
|
}
|
|
25765
25701
|
function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
25766
|
-
const
|
|
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);
|
|
25702
|
+
const tokenTransport = options.tokenTransport ?? options.bearerStrategy ?? "query";
|
|
25774
25703
|
const protocols = normalizeProtocols(options.protocols) ?? [];
|
|
25775
25704
|
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
25776
25705
|
console.warn(
|
|
25777
25706
|
"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
25707
|
);
|
|
25779
25708
|
}
|
|
25780
|
-
|
|
25781
|
-
|
|
25782
|
-
|
|
25783
|
-
|
|
25784
|
-
|
|
25785
|
-
token: bearerToken,
|
|
25786
|
-
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
25787
|
-
includeStoredToken: false
|
|
25788
|
-
});
|
|
25789
|
-
}
|
|
25709
|
+
let resolvedUrl = tokenTransport === "query" ? withWebSocketTokenQuery(url, options) : appendQueryParams(url, options.query);
|
|
25710
|
+
if (tokenTransport === "protocol") {
|
|
25711
|
+
const token = resolveWebSocketToken(options);
|
|
25712
|
+
if (token)
|
|
25713
|
+
protocols.push("bearer", token);
|
|
25790
25714
|
}
|
|
25791
25715
|
const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
|
|
25792
25716
|
socket.onmessage = (event) => {
|
package/dist/components.js
CHANGED
|
@@ -25490,24 +25490,22 @@ 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,
|
|
25493
|
+
getJson: async (path, params, headers) => {
|
|
25494
25494
|
try {
|
|
25495
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
25496
25495
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
25497
|
-
params
|
|
25498
|
-
headers
|
|
25496
|
+
params,
|
|
25497
|
+
headers
|
|
25499
25498
|
});
|
|
25500
25499
|
return response.data;
|
|
25501
25500
|
} catch (e10) {
|
|
25502
25501
|
throw formatAxiosError(e10);
|
|
25503
25502
|
}
|
|
25504
25503
|
},
|
|
25505
|
-
getText: async (path, params,
|
|
25504
|
+
getText: async (path, params, headers) => {
|
|
25506
25505
|
try {
|
|
25507
|
-
const requestOptions = normalizeRequestOptions(params, headersOrOptions);
|
|
25508
25506
|
const response = await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
25509
|
-
params
|
|
25510
|
-
headers
|
|
25507
|
+
params,
|
|
25508
|
+
headers,
|
|
25511
25509
|
responseType: "text"
|
|
25512
25510
|
});
|
|
25513
25511
|
return response.data;
|
|
@@ -25515,106 +25513,61 @@ var fetchApi = {
|
|
|
25515
25513
|
throw formatAxiosError(e10);
|
|
25516
25514
|
}
|
|
25517
25515
|
},
|
|
25518
|
-
getVoid: async (path, params,
|
|
25516
|
+
getVoid: async (path, params, headers) => {
|
|
25519
25517
|
try {
|
|
25520
|
-
|
|
25521
|
-
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), {
|
|
25522
|
-
params: withTokenQueryParams(requestOptions),
|
|
25523
|
-
headers: requestOptions.headers
|
|
25524
|
-
});
|
|
25518
|
+
await (path.includes("/auth") ? authApi : api).get(path.replace("/auth", ""), { params, headers });
|
|
25525
25519
|
} catch (e10) {
|
|
25526
25520
|
throw formatAxiosError(e10);
|
|
25527
25521
|
}
|
|
25528
25522
|
},
|
|
25529
|
-
postJson: async (path, payload,
|
|
25523
|
+
postJson: async (path, payload, headers) => {
|
|
25530
25524
|
try {
|
|
25531
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25532
25525
|
const response = await (path.includes("/auth") ? authApi : api).post(path.replace("/auth", ""), payload, {
|
|
25533
|
-
headers
|
|
25534
|
-
params: withTokenQueryParams(requestOptions)
|
|
25526
|
+
headers
|
|
25535
25527
|
});
|
|
25536
25528
|
return response.data;
|
|
25537
25529
|
} catch (e10) {
|
|
25538
25530
|
throw formatAxiosError(e10);
|
|
25539
25531
|
}
|
|
25540
25532
|
},
|
|
25541
|
-
patchJson: async (path, payload,
|
|
25533
|
+
patchJson: async (path, payload, headers) => {
|
|
25542
25534
|
try {
|
|
25543
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25544
25535
|
const response = await (path.includes("/auth") ? authApi : api).patch(path.replace("/auth", ""), payload, {
|
|
25545
|
-
headers
|
|
25546
|
-
params: withTokenQueryParams(requestOptions)
|
|
25536
|
+
headers
|
|
25547
25537
|
});
|
|
25548
25538
|
return response.data;
|
|
25549
25539
|
} catch (e10) {
|
|
25550
25540
|
throw formatAxiosError(e10);
|
|
25551
25541
|
}
|
|
25552
25542
|
},
|
|
25553
|
-
putJson: async (path, payload,
|
|
25543
|
+
putJson: async (path, payload, headers) => {
|
|
25554
25544
|
try {
|
|
25555
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25556
25545
|
const response = await (path.includes("/auth") ? authApi : api).put(path.replace("/auth", ""), payload, {
|
|
25557
|
-
headers
|
|
25558
|
-
params: withTokenQueryParams(requestOptions)
|
|
25546
|
+
headers
|
|
25559
25547
|
});
|
|
25560
25548
|
return response.data;
|
|
25561
25549
|
} catch (e10) {
|
|
25562
25550
|
throw formatAxiosError(e10);
|
|
25563
25551
|
}
|
|
25564
25552
|
},
|
|
25565
|
-
deleteJson: async (path,
|
|
25553
|
+
deleteJson: async (path, headers) => {
|
|
25566
25554
|
try {
|
|
25567
|
-
const requestOptions = normalizeRequestOptions(void 0, headersOrOptions);
|
|
25568
25555
|
const response = await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
25569
|
-
headers
|
|
25570
|
-
params: withTokenQueryParams(requestOptions)
|
|
25556
|
+
headers
|
|
25571
25557
|
});
|
|
25572
25558
|
return response.data;
|
|
25573
25559
|
} catch (e10) {
|
|
25574
25560
|
throw formatAxiosError(e10);
|
|
25575
25561
|
}
|
|
25576
25562
|
},
|
|
25577
|
-
deleteVoid: async (path,
|
|
25563
|
+
deleteVoid: async (path, headers) => {
|
|
25578
25564
|
try {
|
|
25579
|
-
|
|
25580
|
-
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), {
|
|
25581
|
-
headers: requestOptions.headers,
|
|
25582
|
-
params: withTokenQueryParams(requestOptions)
|
|
25583
|
-
});
|
|
25565
|
+
await (path.includes("/auth") ? authApi : api).delete(path.replace("/auth", ""), { headers });
|
|
25584
25566
|
} catch (e10) {
|
|
25585
25567
|
throw formatAxiosError(e10);
|
|
25586
25568
|
}
|
|
25587
25569
|
}
|
|
25588
25570
|
};
|
|
25589
|
-
function buildWsUrl(path = "/", options = {}) {
|
|
25590
|
-
try {
|
|
25591
|
-
const origin2 = new URL(apiOrigin);
|
|
25592
|
-
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
25593
|
-
if (!path.startsWith("/"))
|
|
25594
|
-
path = "/" + path;
|
|
25595
|
-
origin2.pathname = path;
|
|
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
|
-
});
|
|
25603
|
-
} catch (e10) {
|
|
25604
|
-
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
25605
|
-
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
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
|
-
);
|
|
25616
|
-
}
|
|
25617
|
-
}
|
|
25618
25571
|
function extractBearerToken(headers, explicitToken) {
|
|
25619
25572
|
if (explicitToken)
|
|
25620
25573
|
return explicitToken;
|
|
@@ -25626,7 +25579,7 @@ function extractBearerToken(headers, explicitToken) {
|
|
|
25626
25579
|
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
25627
25580
|
return match ? match[1] : null;
|
|
25628
25581
|
}
|
|
25629
|
-
function
|
|
25582
|
+
function resolveWebSocketToken(options = {}) {
|
|
25630
25583
|
const explicitToken = options.token ?? options.bearerToken ?? null;
|
|
25631
25584
|
const headerToken = extractBearerToken(options.headers, explicitToken);
|
|
25632
25585
|
if (headerToken)
|
|
@@ -25635,12 +25588,6 @@ function resolveAuthToken(options = {}) {
|
|
|
25635
25588
|
return null;
|
|
25636
25589
|
return getAccessToken();
|
|
25637
25590
|
}
|
|
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
25591
|
function appendQueryParams(url, params) {
|
|
25645
25592
|
if (!params || Object.keys(params).length === 0)
|
|
25646
25593
|
return url;
|
|
@@ -25663,73 +25610,50 @@ function appendQueryParams(url, params) {
|
|
|
25663
25610
|
return `${url}${separator}${search}`;
|
|
25664
25611
|
}
|
|
25665
25612
|
}
|
|
25613
|
+
function withWebSocketTokenQuery(url, options) {
|
|
25614
|
+
const token = resolveWebSocketToken(options);
|
|
25615
|
+
const params = { ...options.query ?? {} };
|
|
25616
|
+
if (token) {
|
|
25617
|
+
params[options.tokenQueryParam ?? options.bearerQueryParam ?? "token"] = token;
|
|
25618
|
+
}
|
|
25619
|
+
return appendQueryParams(url, params);
|
|
25620
|
+
}
|
|
25666
25621
|
function normalizeProtocols(protocols) {
|
|
25667
25622
|
if (!protocols)
|
|
25668
25623
|
return void 0;
|
|
25669
25624
|
return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
|
|
25670
25625
|
}
|
|
25671
|
-
function
|
|
25672
|
-
|
|
25673
|
-
|
|
25674
|
-
|
|
25675
|
-
|
|
25676
|
-
|
|
25677
|
-
|
|
25678
|
-
|
|
25679
|
-
|
|
25680
|
-
|
|
25626
|
+
function buildWsUrl(path = "/", options = {}) {
|
|
25627
|
+
try {
|
|
25628
|
+
const origin2 = new URL(apiOrigin);
|
|
25629
|
+
origin2.protocol = origin2.protocol === "https:" ? "wss:" : "ws:";
|
|
25630
|
+
if (!path.startsWith("/"))
|
|
25631
|
+
path = "/" + path;
|
|
25632
|
+
origin2.pathname = path;
|
|
25633
|
+
return withWebSocketTokenQuery(origin2.toString(), options);
|
|
25634
|
+
} catch (e10) {
|
|
25635
|
+
const proto = apiOrigin.startsWith("https") ? "wss" : "ws";
|
|
25636
|
+
const host = apiOrigin.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
25637
|
+
return withWebSocketTokenQuery(`${proto}://${host}${path.startsWith("/") ? path : "/" + path}`, options);
|
|
25681
25638
|
}
|
|
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
25639
|
}
|
|
25704
25640
|
async function decodeFfurl(ffurl) {
|
|
25705
25641
|
const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
|
|
25706
25642
|
return settings;
|
|
25707
25643
|
}
|
|
25708
25644
|
function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
25709
|
-
const
|
|
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);
|
|
25645
|
+
const tokenTransport = options.tokenTransport ?? options.bearerStrategy ?? "query";
|
|
25717
25646
|
const protocols = normalizeProtocols(options.protocols) ?? [];
|
|
25718
25647
|
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
25719
25648
|
console.warn(
|
|
25720
25649
|
"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
25650
|
);
|
|
25722
25651
|
}
|
|
25723
|
-
|
|
25724
|
-
|
|
25725
|
-
|
|
25726
|
-
|
|
25727
|
-
|
|
25728
|
-
token: bearerToken,
|
|
25729
|
-
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
25730
|
-
includeStoredToken: false
|
|
25731
|
-
});
|
|
25732
|
-
}
|
|
25652
|
+
let resolvedUrl = tokenTransport === "query" ? withWebSocketTokenQuery(url, options) : appendQueryParams(url, options.query);
|
|
25653
|
+
if (tokenTransport === "protocol") {
|
|
25654
|
+
const token = resolveWebSocketToken(options);
|
|
25655
|
+
if (token)
|
|
25656
|
+
protocols.push("bearer", token);
|
|
25733
25657
|
}
|
|
25734
25658
|
const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
|
|
25735
25659
|
socket.onmessage = (event) => {
|