@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.
- package/README.md +5 -5
- package/dist/index.d.ts +8 -3
- package/dist/index.js +15 -12
- package/dist/index.js.map +5 -5
- package/dist/sinks/bun-sqlite.js +5 -3
- package/dist/sinks/bun-sqlite.js.map +3 -3
- package/dist/sinks/core.js +5 -3
- package/dist/sinks/core.js.map +3 -3
- package/dist/sinks/drizzle.js +5 -3
- package/dist/sinks/drizzle.js.map +3 -3
- package/dist/sinks/kysely.js +5 -3
- package/dist/sinks/kysely.js.map +3 -3
- package/dist/streams/index.js +15 -12
- package/dist/streams/index.js.map +5 -5
- package/dist/subgraphs/index.js +15 -12
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +1 -1
package/dist/streams/index.js
CHANGED
|
@@ -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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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=
|
|
1578
|
+
//# debugId=C74383F8F8E34A3564756E2164756E21
|
|
1576
1579
|
//# sourceMappingURL=index.js.map
|