@secondlayer/sdk 14.0.1 → 14.2.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.
@@ -211,13 +211,20 @@ function resolveBaseUrl(explicit) {
211
211
  }
212
212
  return LOCAL_API_URL;
213
213
  }
214
- function resolveApiKey(apiKey) {
214
+ function isHostedApiUrl(url) {
215
+ try {
216
+ return new URL(url).hostname === "api.secondlayer.tools";
217
+ } catch {
218
+ return false;
219
+ }
220
+ }
221
+ function resolveApiKey(apiKey, baseUrl) {
215
222
  if (apiKey !== undefined)
216
223
  return apiKey;
217
224
  if (typeof process === "undefined")
218
225
  return;
219
- const token = process.env?.INSTANCE_TOKEN || undefined;
220
- return token;
226
+ const name = baseUrl !== undefined && isHostedApiUrl(baseUrl) ? ACCOUNT_KEY_ENV : INSTANCE_TOKEN_ENV;
227
+ return process.env?.[name] || undefined;
221
228
  }
222
229
  function resolveAccountKey(accountKey) {
223
230
  if (accountKey !== undefined)
@@ -275,7 +282,7 @@ class BaseClient {
275
282
  etagCache;
276
283
  constructor(options = {}) {
277
284
  this.baseUrl = resolveBaseUrl(options.baseUrl);
278
- this.apiKey = resolveApiKey(options.apiKey);
285
+ this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
279
286
  this.origin = options.origin ?? "cli";
280
287
  this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
281
288
  this.fetchImpl = options.fetchImpl ?? ((...args) => fetch(...args));
@@ -1237,7 +1244,7 @@ function isLoopbackUrl(baseUrl) {
1237
1244
  }
1238
1245
  function createStreamsClient(options) {
1239
1246
  const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
1240
- const apiKey = resolveApiKey(options.apiKey);
1247
+ const apiKey = resolveApiKey(options.apiKey, baseUrl);
1241
1248
  const origin = options.origin ?? "cli";
1242
1249
  const authHeaders = () => ({
1243
1250
  "x-sl-origin": origin,
@@ -1603,5 +1610,5 @@ export {
1603
1610
  isStxTransfer
1604
1611
  };
1605
1612
 
1606
- //# debugId=F2E7E752B64FBB0D64756E2164756E21
1613
+ //# debugId=B1CA7FDD739B36F364756E2164756E21
1607
1614
  //# sourceMappingURL=index.js.map