@secondlayer/sdk 16.0.0 → 16.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.
@@ -56,7 +56,9 @@ ${detailBlocks.join(`
56
56
  };
57
57
  }
58
58
  }
59
- function statusRetryable(status) {
59
+ function statusRetryable(status, code) {
60
+ if (code === "STACK_ASLEEP")
61
+ return false;
60
62
  return status === 429 || status >= 500;
61
63
  }
62
64
  function docsFor(status, code) {
@@ -73,7 +75,7 @@ class ApiError extends SecondLayerError {
73
75
  constructor(status, message, body, code, options = {}) {
74
76
  super(message, {
75
77
  code,
76
- retryable: options.retryable ?? statusRetryable(status),
78
+ retryable: options.retryable ?? statusRetryable(status, code),
77
79
  docsUrl: options.docsUrl ?? docsFor(status, code),
78
80
  ...options.cause ? { cause: options.cause } : {},
79
81
  ...options.details ? { details: options.details } : {},
@@ -210,17 +212,18 @@ function raceAbort(promise, signal) {
210
212
  });
211
213
  }
212
214
  var LOCAL_API_URL = "http://127.0.0.1:3800";
215
+ var HOSTED_API_URL = "https://api.secondlayer.tools";
213
216
  var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
214
217
  var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
215
- function resolveBaseUrl(explicit) {
218
+ function resolveBaseUrl(explicit, apiKey) {
216
219
  if (explicit && explicit.length > 0)
217
220
  return explicit.replace(/\/+$/, "");
218
- if (typeof process !== "undefined") {
219
- const primary = process.env?.SECONDLAYER_API_URL || undefined;
220
- if (primary)
221
- return primary.replace(/\/+$/, "");
222
- }
223
- return LOCAL_API_URL;
221
+ const env = typeof process !== "undefined" ? process.env : undefined;
222
+ const primary = env?.SECONDLAYER_API_URL || undefined;
223
+ if (primary)
224
+ return primary.replace(/\/+$/, "");
225
+ const key = apiKey ?? (env?.[INSTANCE_TOKEN_ENV] ? undefined : env?.[ACCOUNT_KEY_ENV]);
226
+ return key?.startsWith("sk-sl_") ? HOSTED_API_URL : LOCAL_API_URL;
224
227
  }
225
228
  function isHostedApiUrl(url) {
226
229
  try {
@@ -292,7 +295,7 @@ class BaseClient {
292
295
  requestTimeoutMs;
293
296
  etagCache;
294
297
  constructor(options = {}) {
295
- this.baseUrl = resolveBaseUrl(options.baseUrl);
298
+ this.baseUrl = resolveBaseUrl(options.baseUrl, options.apiKey);
296
299
  this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
297
300
  this.origin = options.origin ?? "cli";
298
301
  this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
@@ -1254,7 +1257,7 @@ function isLoopbackUrl(baseUrl) {
1254
1257
  }
1255
1258
  }
1256
1259
  function createStreamsClient(options) {
1257
- const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
1260
+ const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl, options.apiKey));
1258
1261
  const apiKey = resolveApiKey(options.apiKey, baseUrl);
1259
1262
  const origin = options.origin ?? "cli";
1260
1263
  const authHeaders = () => ({
@@ -1572,5 +1575,5 @@ export {
1572
1575
  decode
1573
1576
  };
1574
1577
 
1575
- //# debugId=BAF7AFEF510AE0F364756E2164756E21
1578
+ //# debugId=C74383F8F8E34A3564756E2164756E21
1576
1579
  //# sourceMappingURL=index.js.map