@spoketech/hub-client 0.1.4 → 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 +18 -2
- 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
|
}
|
|
@@ -3802,6 +3816,7 @@ var makeHubApiClient = (options) => HttpApiClient.make(HubApi, {
|
|
|
3802
3816
|
transformResponse: options.transformResponse
|
|
3803
3817
|
}).pipe(Effect.provide(FetchHttpClient.layer));
|
|
3804
3818
|
var makeServiceHubApiClient = (options) => Effect.gen(function* () {
|
|
3819
|
+
const apiBaseUrl = resolveHubApiBaseUrl(options.baseUrl, options.apiBasePath);
|
|
3805
3820
|
const client = yield* makeHubApiClient({
|
|
3806
3821
|
baseUrl: options.baseUrl,
|
|
3807
3822
|
apiBasePath: options.apiBasePath,
|
|
@@ -3809,7 +3824,8 @@ var makeServiceHubApiClient = (options) => Effect.gen(function* () {
|
|
|
3809
3824
|
transformClient: (client2) => {
|
|
3810
3825
|
const configured = configureSignedHttpClient(client2, {
|
|
3811
3826
|
clientId: options.clientId,
|
|
3812
|
-
privateKey: options.privateKey
|
|
3827
|
+
privateKey: options.privateKey,
|
|
3828
|
+
apiBaseUrl
|
|
3813
3829
|
});
|
|
3814
3830
|
return options.transformClient ? options.transformClient(configured) : configured;
|
|
3815
3831
|
},
|