@viasoftbr/shared-ui 0.0.7-1 → 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.
- package/dist/components.cjs +137 -31
- package/dist/components.js +137 -31
- package/dist/hooks.cjs +98 -17
- package/dist/hooks.js +98 -17
- package/dist/index.cjs +139 -32
- package/dist/index.js +139 -32
- package/dist/services/api.d.ts +19 -10
- package/dist/services.cjs +139 -32
- package/dist/services.js +139 -32
- package/dist/types/websocket.d.ts +12 -1
- package/package.json +1 -1
- package/dist/components/RemoteModule.d.ts +0 -8
- package/dist/package.json +0 -111
- package/dist/services/loadRemoteModule.d.ts +0 -9
- package/dist/services/metadataLoader.d.ts +0 -9
package/dist/components.cjs
CHANGED
|
@@ -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,
|
|
25550
|
+
getJson: async (path, params, headersOrOptions) => {
|
|
25551
25551
|
try {
|
|
25552
|
-
const
|
|
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,
|
|
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,65 +25572,104 @@ var fetchApi = {
|
|
|
25567
25572
|
throw formatAxiosError(e10);
|
|
25568
25573
|
}
|
|
25569
25574
|
},
|
|
25570
|
-
getVoid: async (path, params,
|
|
25575
|
+
getVoid: async (path, params, headersOrOptions) => {
|
|
25571
25576
|
try {
|
|
25572
|
-
|
|
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,
|
|
25586
|
+
postJson: async (path, payload, headersOrOptions) => {
|
|
25578
25587
|
try {
|
|
25579
|
-
const
|
|
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,
|
|
25598
|
+
patchJson: async (path, payload, headersOrOptions) => {
|
|
25586
25599
|
try {
|
|
25587
|
-
const
|
|
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,
|
|
25610
|
+
putJson: async (path, payload, headersOrOptions) => {
|
|
25594
25611
|
try {
|
|
25595
|
-
const
|
|
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,
|
|
25622
|
+
deleteJson: async (path, headersOrOptions) => {
|
|
25602
25623
|
try {
|
|
25603
|
-
const
|
|
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,
|
|
25634
|
+
deleteVoid: async (path, headersOrOptions) => {
|
|
25610
25635
|
try {
|
|
25611
|
-
|
|
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
|
|
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
25675
|
function extractBearerToken(headers, explicitToken) {
|
|
@@ -25639,17 +25683,41 @@ function extractBearerToken(headers, explicitToken) {
|
|
|
25639
25683
|
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
25640
25684
|
return match ? match[1] : null;
|
|
25641
25685
|
}
|
|
25642
|
-
function
|
|
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;
|
|
25643
25704
|
try {
|
|
25644
25705
|
const parsed = new URL(
|
|
25645
25706
|
url,
|
|
25646
25707
|
typeof window !== "undefined" ? window.location.href : void 0
|
|
25647
25708
|
);
|
|
25648
|
-
|
|
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
|
+
}
|
|
25649
25714
|
return parsed.toString();
|
|
25650
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;
|
|
25651
25719
|
const separator = url.includes("?") ? "&" : "?";
|
|
25652
|
-
return `${url}${separator}${
|
|
25720
|
+
return `${url}${separator}${search}`;
|
|
25653
25721
|
}
|
|
25654
25722
|
}
|
|
25655
25723
|
function normalizeProtocols(protocols) {
|
|
@@ -25657,14 +25725,52 @@ function normalizeProtocols(protocols) {
|
|
|
25657
25725
|
return void 0;
|
|
25658
25726
|
return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
|
|
25659
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
|
+
}
|
|
25660
25761
|
async function decodeFfurl(ffurl) {
|
|
25661
25762
|
const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
|
|
25662
25763
|
return settings;
|
|
25663
25764
|
}
|
|
25664
25765
|
function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
25665
|
-
const bearerToken =
|
|
25666
|
-
|
|
25667
|
-
|
|
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);
|
|
25668
25774
|
const protocols = normalizeProtocols(options.protocols) ?? [];
|
|
25669
25775
|
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
25670
25776
|
console.warn(
|
|
@@ -25675,11 +25781,11 @@ function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
|
25675
25781
|
if (bearerStrategy === "protocol") {
|
|
25676
25782
|
protocols.push("bearer", bearerToken);
|
|
25677
25783
|
} else {
|
|
25678
|
-
resolvedUrl =
|
|
25679
|
-
|
|
25680
|
-
options.
|
|
25681
|
-
|
|
25682
|
-
);
|
|
25784
|
+
resolvedUrl = withAccessTokenQuery(resolvedUrl, {
|
|
25785
|
+
token: bearerToken,
|
|
25786
|
+
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
25787
|
+
includeStoredToken: false
|
|
25788
|
+
});
|
|
25683
25789
|
}
|
|
25684
25790
|
}
|
|
25685
25791
|
const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
|
package/dist/components.js
CHANGED
|
@@ -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,
|
|
25493
|
+
getJson: async (path, params, headersOrOptions) => {
|
|
25494
25494
|
try {
|
|
25495
|
-
const
|
|
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,
|
|
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,65 +25515,104 @@ var fetchApi = {
|
|
|
25510
25515
|
throw formatAxiosError(e10);
|
|
25511
25516
|
}
|
|
25512
25517
|
},
|
|
25513
|
-
getVoid: async (path, params,
|
|
25518
|
+
getVoid: async (path, params, headersOrOptions) => {
|
|
25514
25519
|
try {
|
|
25515
|
-
|
|
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,
|
|
25529
|
+
postJson: async (path, payload, headersOrOptions) => {
|
|
25521
25530
|
try {
|
|
25522
|
-
const
|
|
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,
|
|
25541
|
+
patchJson: async (path, payload, headersOrOptions) => {
|
|
25529
25542
|
try {
|
|
25530
|
-
const
|
|
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,
|
|
25553
|
+
putJson: async (path, payload, headersOrOptions) => {
|
|
25537
25554
|
try {
|
|
25538
|
-
const
|
|
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,
|
|
25565
|
+
deleteJson: async (path, headersOrOptions) => {
|
|
25545
25566
|
try {
|
|
25546
|
-
const
|
|
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,
|
|
25577
|
+
deleteVoid: async (path, headersOrOptions) => {
|
|
25553
25578
|
try {
|
|
25554
|
-
|
|
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
|
|
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
25618
|
function extractBearerToken(headers, explicitToken) {
|
|
@@ -25582,17 +25626,41 @@ function extractBearerToken(headers, explicitToken) {
|
|
|
25582
25626
|
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
25583
25627
|
return match ? match[1] : null;
|
|
25584
25628
|
}
|
|
25585
|
-
function
|
|
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;
|
|
25586
25647
|
try {
|
|
25587
25648
|
const parsed = new URL(
|
|
25588
25649
|
url,
|
|
25589
25650
|
typeof window !== "undefined" ? window.location.href : void 0
|
|
25590
25651
|
);
|
|
25591
|
-
|
|
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
|
+
}
|
|
25592
25657
|
return parsed.toString();
|
|
25593
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;
|
|
25594
25662
|
const separator = url.includes("?") ? "&" : "?";
|
|
25595
|
-
return `${url}${separator}${
|
|
25663
|
+
return `${url}${separator}${search}`;
|
|
25596
25664
|
}
|
|
25597
25665
|
}
|
|
25598
25666
|
function normalizeProtocols(protocols) {
|
|
@@ -25600,14 +25668,52 @@ function normalizeProtocols(protocols) {
|
|
|
25600
25668
|
return void 0;
|
|
25601
25669
|
return Array.isArray(protocols) ? protocols.filter(Boolean) : [protocols];
|
|
25602
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
|
+
}
|
|
25603
25704
|
async function decodeFfurl(ffurl) {
|
|
25604
25705
|
const { settings } = await fetchApi.postJson("/auth/protocols/ffurl/decode", { ffurl });
|
|
25605
25706
|
return settings;
|
|
25606
25707
|
}
|
|
25607
25708
|
function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
25608
|
-
const bearerToken =
|
|
25609
|
-
|
|
25610
|
-
|
|
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);
|
|
25611
25717
|
const protocols = normalizeProtocols(options.protocols) ?? [];
|
|
25612
25718
|
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
25613
25719
|
console.warn(
|
|
@@ -25618,11 +25724,11 @@ function subscribeToWebsocket(url, onMessage, options = {}) {
|
|
|
25618
25724
|
if (bearerStrategy === "protocol") {
|
|
25619
25725
|
protocols.push("bearer", bearerToken);
|
|
25620
25726
|
} else {
|
|
25621
|
-
resolvedUrl =
|
|
25622
|
-
|
|
25623
|
-
options.
|
|
25624
|
-
|
|
25625
|
-
);
|
|
25727
|
+
resolvedUrl = withAccessTokenQuery(resolvedUrl, {
|
|
25728
|
+
token: bearerToken,
|
|
25729
|
+
tokenQueryParam: options.tokenQueryParam ?? options.bearerQueryParam,
|
|
25730
|
+
includeStoredToken: false
|
|
25731
|
+
});
|
|
25626
25732
|
}
|
|
25627
25733
|
}
|
|
25628
25734
|
const socket = protocols.length > 0 ? new WebSocket(resolvedUrl, protocols) : new WebSocket(resolvedUrl);
|