@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/subgraphs/index.js
CHANGED
|
@@ -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 } : {},
|
|
@@ -207,17 +209,18 @@ function raceAbort(promise, signal) {
|
|
|
207
209
|
});
|
|
208
210
|
}
|
|
209
211
|
var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
212
|
+
var HOSTED_API_URL = "https://api.secondlayer.tools";
|
|
210
213
|
var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
211
214
|
var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
212
|
-
function resolveBaseUrl(explicit) {
|
|
215
|
+
function resolveBaseUrl(explicit, apiKey) {
|
|
213
216
|
if (explicit && explicit.length > 0)
|
|
214
217
|
return explicit.replace(/\/+$/, "");
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
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;
|
|
221
224
|
}
|
|
222
225
|
function isHostedApiUrl(url) {
|
|
223
226
|
try {
|
|
@@ -289,7 +292,7 @@ class BaseClient {
|
|
|
289
292
|
requestTimeoutMs;
|
|
290
293
|
etagCache;
|
|
291
294
|
constructor(options = {}) {
|
|
292
|
-
this.baseUrl = resolveBaseUrl(options.baseUrl);
|
|
295
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl, options.apiKey);
|
|
293
296
|
this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
|
|
294
297
|
this.origin = options.origin ?? "cli";
|
|
295
298
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
@@ -2346,7 +2349,7 @@ function isLoopbackUrl(baseUrl) {
|
|
|
2346
2349
|
}
|
|
2347
2350
|
}
|
|
2348
2351
|
function createStreamsClient(options) {
|
|
2349
|
-
const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
|
|
2352
|
+
const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl, options.apiKey));
|
|
2350
2353
|
const apiKey = resolveApiKey(options.apiKey, baseUrl);
|
|
2351
2354
|
const origin = options.origin ?? "cli";
|
|
2352
2355
|
const authHeaders = () => ({
|
|
@@ -2843,5 +2846,5 @@ export {
|
|
|
2843
2846
|
getSubgraph
|
|
2844
2847
|
};
|
|
2845
2848
|
|
|
2846
|
-
//# debugId=
|
|
2849
|
+
//# debugId=4BBCD55406927B9364756E2164756E21
|
|
2847
2850
|
//# sourceMappingURL=index.js.map
|