@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.
- package/README.md +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +14 -15
- 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 +14 -15
- package/dist/streams/index.js.map +5 -5
- package/dist/subgraphs/index.js +14 -15
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ const sl = new SecondLayer({
|
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Hosted: set `SECONDLAYER_API_KEY` (`sk-sl_*`) and the client uses
|
|
22
|
+
Hosted: set `SECONDLAYER_API_KEY` or pass `apiKey` (`sk-sl_*`) and the client uses
|
|
23
23
|
`https://api.secondlayer.tools`. Self-host: use `INSTANCE_TOKEN` as below, which
|
|
24
24
|
keeps the client on your instance even with an account key set. The key follows the host.
|
|
25
25
|
|
package/dist/index.d.ts
CHANGED
|
@@ -305,7 +305,12 @@ declare const LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
|
305
305
|
declare const INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
306
306
|
/** Hosted account key (`sk-sl_*`) for api.secondlayer.tools. */
|
|
307
307
|
declare const ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
308
|
-
|
|
308
|
+
/** The API to call. A named URL wins (`explicit`, then `SECONDLAYER_API_URL`).
|
|
309
|
+
* Otherwise the key picks the host, so a credential never reaches the wrong
|
|
310
|
+
* one: `apiKey` if the caller passed one, else a lone account key in the env.
|
|
311
|
+
* Self-hosters often hold an account key for archive credits too, so an env
|
|
312
|
+
* instance token keeps them on their instance. */
|
|
313
|
+
declare function resolveBaseUrl(explicit?: string, apiKey?: string): string;
|
|
309
314
|
/** True when `url` is the hosted Secondlayer API (`api.secondlayer.tools`). */
|
|
310
315
|
declare function isHostedApiUrl(url: string): boolean;
|
|
311
316
|
/** Resolve the bearer credential; the key follows the host. Precedence:
|
package/dist/index.js
CHANGED
|
@@ -60,7 +60,9 @@ ${detailBlocks.join(`
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
function statusRetryable(status) {
|
|
63
|
+
function statusRetryable(status, code) {
|
|
64
|
+
if (code === "STACK_ASLEEP")
|
|
65
|
+
return false;
|
|
64
66
|
return status === 429 || status >= 500;
|
|
65
67
|
}
|
|
66
68
|
function docsFor(status, code) {
|
|
@@ -77,7 +79,7 @@ class ApiError extends SecondLayerError {
|
|
|
77
79
|
constructor(status, message, body, code, options = {}) {
|
|
78
80
|
super(message, {
|
|
79
81
|
code,
|
|
80
|
-
retryable: options.retryable ?? statusRetryable(status),
|
|
82
|
+
retryable: options.retryable ?? statusRetryable(status, code),
|
|
81
83
|
docsUrl: options.docsUrl ?? docsFor(status, code),
|
|
82
84
|
...options.cause ? { cause: options.cause } : {},
|
|
83
85
|
...options.details ? { details: options.details } : {},
|
|
@@ -217,18 +219,15 @@ var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
|
217
219
|
var HOSTED_API_URL = "https://api.secondlayer.tools";
|
|
218
220
|
var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
219
221
|
var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
220
|
-
function resolveBaseUrl(explicit) {
|
|
222
|
+
function resolveBaseUrl(explicit, apiKey) {
|
|
221
223
|
if (explicit && explicit.length > 0)
|
|
222
224
|
return explicit.replace(/\/+$/, "");
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return LOCAL_API_URL;
|
|
225
|
+
const env = typeof process !== "undefined" ? process.env : undefined;
|
|
226
|
+
const primary = env?.SECONDLAYER_API_URL || undefined;
|
|
227
|
+
if (primary)
|
|
228
|
+
return primary.replace(/\/+$/, "");
|
|
229
|
+
const key = apiKey ?? (env?.[INSTANCE_TOKEN_ENV] ? undefined : env?.[ACCOUNT_KEY_ENV]);
|
|
230
|
+
return key?.startsWith("sk-sl_") ? HOSTED_API_URL : LOCAL_API_URL;
|
|
232
231
|
}
|
|
233
232
|
function isHostedApiUrl(url) {
|
|
234
233
|
try {
|
|
@@ -300,7 +299,7 @@ class BaseClient {
|
|
|
300
299
|
requestTimeoutMs;
|
|
301
300
|
etagCache;
|
|
302
301
|
constructor(options = {}) {
|
|
303
|
-
this.baseUrl = resolveBaseUrl(options.baseUrl);
|
|
302
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl, options.apiKey);
|
|
304
303
|
this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
|
|
305
304
|
this.origin = options.origin ?? "cli";
|
|
306
305
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
@@ -2075,7 +2074,7 @@ function isLoopbackUrl(baseUrl) {
|
|
|
2075
2074
|
}
|
|
2076
2075
|
}
|
|
2077
2076
|
function createStreamsClient(options) {
|
|
2078
|
-
const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
|
|
2077
|
+
const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl, options.apiKey));
|
|
2079
2078
|
const apiKey = resolveApiKey(options.apiKey, baseUrl);
|
|
2080
2079
|
const origin = options.origin ?? "cli";
|
|
2081
2080
|
const authHeaders = () => ({
|
|
@@ -3422,5 +3421,5 @@ export {
|
|
|
3422
3421
|
verifyWebhookSignature
|
|
3423
3422
|
};
|
|
3424
3423
|
|
|
3425
|
-
//# debugId=
|
|
3424
|
+
//# debugId=F50384CF029DB60E64756E2164756E21
|
|
3426
3425
|
//# sourceMappingURL=index.js.map
|