@secondlayer/sdk 16.1.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 } : {},
@@ -213,18 +215,15 @@ var LOCAL_API_URL = "http://127.0.0.1:3800";
213
215
  var HOSTED_API_URL = "https://api.secondlayer.tools";
214
216
  var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
215
217
  var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
216
- function resolveBaseUrl(explicit) {
218
+ function resolveBaseUrl(explicit, apiKey) {
217
219
  if (explicit && explicit.length > 0)
218
220
  return explicit.replace(/\/+$/, "");
219
- if (typeof process !== "undefined") {
220
- const primary = process.env?.SECONDLAYER_API_URL || undefined;
221
- if (primary)
222
- return primary.replace(/\/+$/, "");
223
- if (process.env?.[ACCOUNT_KEY_ENV]?.startsWith("sk-sl_") && !process.env?.[INSTANCE_TOKEN_ENV]) {
224
- return HOSTED_API_URL;
225
- }
226
- }
227
- 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;
228
227
  }
229
228
  function isHostedApiUrl(url) {
230
229
  try {
@@ -296,7 +295,7 @@ class BaseClient {
296
295
  requestTimeoutMs;
297
296
  etagCache;
298
297
  constructor(options = {}) {
299
- this.baseUrl = resolveBaseUrl(options.baseUrl);
298
+ this.baseUrl = resolveBaseUrl(options.baseUrl, options.apiKey);
300
299
  this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
301
300
  this.origin = options.origin ?? "cli";
302
301
  this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
@@ -1258,7 +1257,7 @@ function isLoopbackUrl(baseUrl) {
1258
1257
  }
1259
1258
  }
1260
1259
  function createStreamsClient(options) {
1261
- const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
1260
+ const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl, options.apiKey));
1262
1261
  const apiKey = resolveApiKey(options.apiKey, baseUrl);
1263
1262
  const origin = options.origin ?? "cli";
1264
1263
  const authHeaders = () => ({
@@ -1576,5 +1575,5 @@ export {
1576
1575
  decode
1577
1576
  };
1578
1577
 
1579
- //# debugId=8888B6D720E4ED2E64756E2164756E21
1578
+ //# debugId=C74383F8F8E34A3564756E2164756E21
1580
1579
  //# sourceMappingURL=index.js.map