@doujins/payments-ui 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 CHANGED
@@ -88,13 +88,15 @@ var createClient = (config) => {
88
88
  }
89
89
  };
90
90
  const buildUrl = (path, query) => {
91
- path = path.replace(/^\/+/, "");
92
- const url = new URL(`${config.baseUrl.replace(/^\/+/, "")}${path.endsWith("v1") ? "" : "/v1"}${path}`);
91
+ const sanitizedPath = path.replace(/^\/+/, "");
92
+ const baseUrl = config.baseUrl.trim().replace(/\/+$/, "");
93
+ const versionedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
94
+ const url = new URL(sanitizedPath, `${versionedBaseUrl.replace(/\/+$/, "")}/`);
93
95
  if (query) {
94
- Object.entries(query).forEach(([key, value]) => {
95
- if (value === void 0 || value === null) return;
96
+ for (const [key, value] of Object.entries(query)) {
97
+ if (value === void 0 || value === null) continue;
96
98
  url.searchParams.append(key, String(value));
97
- });
99
+ }
98
100
  }
99
101
  return url.toString();
100
102
  };