@spoketech/hub-client 0.1.5 → 0.1.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/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3746,6 +3746,20 @@ function normalizeSignedQuery(url) {
|
|
|
3746
3746
|
);
|
|
3747
3747
|
return entries.map(([key, value]) => `${encodeQueryComponent(key)}=${encodeQueryComponent(value)}`).join("&");
|
|
3748
3748
|
}
|
|
3749
|
+
function resolveSignedRequestUrl(requestUrl, apiBaseUrl) {
|
|
3750
|
+
const baseUrl = new URL(apiBaseUrl);
|
|
3751
|
+
try {
|
|
3752
|
+
return new URL(requestUrl);
|
|
3753
|
+
} catch {
|
|
3754
|
+
const relativeUrl = new URL(requestUrl, "http://spoke.local");
|
|
3755
|
+
const basePath = baseUrl.pathname.replace(/\/+$/, "");
|
|
3756
|
+
const requestPath = relativeUrl.pathname.replace(/^\/+/, "");
|
|
3757
|
+
baseUrl.pathname = `${basePath}/${requestPath}`.replace(/\/{2,}/g, "/");
|
|
3758
|
+
baseUrl.search = relativeUrl.search;
|
|
3759
|
+
baseUrl.hash = "";
|
|
3760
|
+
return baseUrl;
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3749
3763
|
function signRequestWithPrivateKey(input) {
|
|
3750
3764
|
const payload = [
|
|
3751
3765
|
input.method.trim().toUpperCase(),
|
|
@@ -3764,7 +3778,7 @@ function signRequestWithPrivateKey(input) {
|
|
|
3764
3778
|
function configureSignedHttpClient(client, options) {
|
|
3765
3779
|
return client.pipe(
|
|
3766
3780
|
HttpClient.mapRequest((request) => {
|
|
3767
|
-
const url =
|
|
3781
|
+
const url = resolveSignedRequestUrl(request.url, options.apiBaseUrl);
|
|
3768
3782
|
for (const [key, value] of request.urlParams) {
|
|
3769
3783
|
url.searchParams.append(key, value);
|
|
3770
3784
|
}
|