@secondlayer/sdk 16.1.0 → 16.2.1

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.
@@ -3653,9 +3653,9 @@ declare class Webhooks extends BaseClient {
3653
3653
  /** Get a webhook's hourly delivery counts for the last 7 days.
3654
3654
  *
3655
3655
  * Each hour has delivered, waiting, and gave-up counts, plus the current
3656
- * queue depth, failed attempts per hour, and the usual band. Pass
3657
- * `{ days: 30 }` to also get 30 daily totals. This is the events chart on
3658
- * the detail page. */
3656
+ * queue depth, failed attempts per hour, the usual band, and 30 daily
3657
+ * totals. This is the events chart on the detail page. `{ days: 30 }` is
3658
+ * accepted for older servers, which only send the daily totals when asked. */
3659
3659
  activity(id: string, opts?: {
3660
3660
  days?: 30;
3661
3661
  }): Promise<WebhookActivity>;
@@ -53,7 +53,9 @@ ${detailBlocks.join(`
53
53
  };
54
54
  }
55
55
  }
56
- function statusRetryable(status) {
56
+ function statusRetryable(status, code) {
57
+ if (code === "STACK_ASLEEP")
58
+ return false;
57
59
  return status === 429 || status >= 500;
58
60
  }
59
61
  function docsFor(status, code) {
@@ -70,7 +72,7 @@ class ApiError extends SecondLayerError {
70
72
  constructor(status, message, body, code, options = {}) {
71
73
  super(message, {
72
74
  code,
73
- retryable: options.retryable ?? statusRetryable(status),
75
+ retryable: options.retryable ?? statusRetryable(status, code),
74
76
  docsUrl: options.docsUrl ?? docsFor(status, code),
75
77
  ...options.cause ? { cause: options.cause } : {},
76
78
  ...options.details ? { details: options.details } : {},
@@ -210,18 +212,15 @@ var LOCAL_API_URL = "http://127.0.0.1:3800";
210
212
  var HOSTED_API_URL = "https://api.secondlayer.tools";
211
213
  var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
212
214
  var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
213
- function resolveBaseUrl(explicit) {
215
+ function resolveBaseUrl(explicit, apiKey) {
214
216
  if (explicit && explicit.length > 0)
215
217
  return explicit.replace(/\/+$/, "");
216
- if (typeof process !== "undefined") {
217
- const primary = process.env?.SECONDLAYER_API_URL || undefined;
218
- if (primary)
219
- return primary.replace(/\/+$/, "");
220
- if (process.env?.[ACCOUNT_KEY_ENV]?.startsWith("sk-sl_") && !process.env?.[INSTANCE_TOKEN_ENV]) {
221
- return HOSTED_API_URL;
222
- }
223
- }
224
- return LOCAL_API_URL;
218
+ const env = typeof process !== "undefined" ? process.env : undefined;
219
+ const primary = env?.SECONDLAYER_API_URL || undefined;
220
+ if (primary)
221
+ return primary.replace(/\/+$/, "");
222
+ const key = apiKey ?? (env?.[INSTANCE_TOKEN_ENV] ? undefined : env?.[ACCOUNT_KEY_ENV]);
223
+ return key?.startsWith("sk-sl_") ? HOSTED_API_URL : LOCAL_API_URL;
225
224
  }
226
225
  function isHostedApiUrl(url) {
227
226
  try {
@@ -293,7 +292,7 @@ class BaseClient {
293
292
  requestTimeoutMs;
294
293
  etagCache;
295
294
  constructor(options = {}) {
296
- this.baseUrl = resolveBaseUrl(options.baseUrl);
295
+ this.baseUrl = resolveBaseUrl(options.baseUrl, options.apiKey);
297
296
  this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
298
297
  this.origin = options.origin ?? "cli";
299
298
  this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
@@ -2350,7 +2349,7 @@ function isLoopbackUrl(baseUrl) {
2350
2349
  }
2351
2350
  }
2352
2351
  function createStreamsClient(options) {
2353
- const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
2352
+ const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl, options.apiKey));
2354
2353
  const apiKey = resolveApiKey(options.apiKey, baseUrl);
2355
2354
  const origin = options.origin ?? "cli";
2356
2355
  const authHeaders = () => ({
@@ -2847,5 +2846,5 @@ export {
2847
2846
  getSubgraph
2848
2847
  };
2849
2848
 
2850
- //# debugId=C9F15D050AD076D464756E2164756E21
2849
+ //# debugId=4BBCD55406927B9364756E2164756E21
2851
2850
  //# sourceMappingURL=index.js.map