@izak0s/spacebring-api 1.8.0 → 1.10.0

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
@@ -2080,6 +2080,8 @@ var Spacebring = class {
2080
2080
  /** Typed openapi-fetch client — escape hatch for endpoints or options the facade does not cover. */
2081
2081
  raw;
2082
2082
  constructor(config) {
2083
+ const baseUrl = config.baseUrl ?? "https://api.spacebring.com";
2084
+ assertSecureBaseUrl(baseUrl);
2083
2085
  const headers = {
2084
2086
  Authorization: `Basic ${toBase64(`${config.clientId}:${config.clientSecret}`)}`
2085
2087
  };
@@ -2087,7 +2089,7 @@ var Spacebring = class {
2087
2089
  headers["spacebring-network-id"] = config.networkId;
2088
2090
  }
2089
2091
  this.raw = createClient({
2090
- baseUrl: config.baseUrl ?? "https://api.spacebring.com",
2092
+ baseUrl,
2091
2093
  headers,
2092
2094
  fetch: withRetry(config.fetch ?? globalThis.fetch, config.maxRetries ?? 3, config.timeoutMs)
2093
2095
  });
@@ -2156,6 +2158,20 @@ function sleep(ms, signal) {
2156
2158
  signal.addEventListener("abort", onAbort, { once: true });
2157
2159
  });
2158
2160
  }
2161
+ function assertSecureBaseUrl(baseUrl) {
2162
+ let url;
2163
+ try {
2164
+ url = new URL(baseUrl);
2165
+ } catch {
2166
+ throw new Error(`Spacebring baseUrl is not a valid URL: ${baseUrl}`);
2167
+ }
2168
+ if (url.protocol === "https:") return;
2169
+ const isLoopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]" || url.hostname === "::1";
2170
+ if (url.protocol === "http:" && isLoopback) return;
2171
+ throw new Error(
2172
+ `Spacebring baseUrl must use https (got "${url.protocol}//"): Basic-auth credentials would otherwise be sent in cleartext. Use https, or http only for a loopback host.`
2173
+ );
2174
+ }
2159
2175
  function toBase64(value) {
2160
2176
  if (typeof Buffer !== "undefined") {
2161
2177
  return Buffer.from(value, "utf8").toString("base64");