@secondlayer/sdk 10.2.0 → 10.3.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.
- package/README.md +3 -2
- package/dist/index.d.ts +23 -28
- package/dist/index.js +51 -22
- package/dist/index.js.map +5 -5
- package/dist/streams/index.js +36 -14
- package/dist/streams/index.js.map +3 -3
- package/dist/subgraphs/index.d.ts +6 -2
- package/dist/subgraphs/index.js +47 -20
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +2 -2
package/dist/subgraphs/index.js
CHANGED
|
@@ -172,33 +172,55 @@ function raceAbort(promise, signal) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
175
|
+
var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
176
|
+
var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
177
|
+
var warnedUrlAlias = false;
|
|
175
178
|
function resolveBaseUrl(explicit) {
|
|
176
179
|
if (explicit && explicit.length > 0)
|
|
177
180
|
return explicit.replace(/\/+$/, "");
|
|
178
181
|
if (typeof process !== "undefined") {
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
181
|
-
return
|
|
182
|
+
const primary = process.env?.SECONDLAYER_API_URL || undefined;
|
|
183
|
+
if (primary)
|
|
184
|
+
return primary.replace(/\/+$/, "");
|
|
185
|
+
const legacy = process.env?.SL_API_URL || undefined;
|
|
186
|
+
if (legacy) {
|
|
187
|
+
if (!warnedUrlAlias) {
|
|
188
|
+
warnedUrlAlias = true;
|
|
189
|
+
console.warn("[secondlayer] SL_API_URL is a legacy alias of SECONDLAYER_API_URL; using the alias this once.");
|
|
190
|
+
}
|
|
191
|
+
return legacy.replace(/\/+$/, "");
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
return LOCAL_API_URL;
|
|
184
195
|
}
|
|
185
|
-
var CREDENTIAL_ENV_VARS = ["INSTANCE_TOKEN", "SL_API_KEY"];
|
|
186
|
-
var warnedConflicts = new Set;
|
|
187
196
|
function resolveApiKey(apiKey) {
|
|
188
197
|
if (apiKey !== undefined)
|
|
189
198
|
return apiKey;
|
|
190
199
|
if (typeof process === "undefined")
|
|
191
200
|
return;
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
const token = process.env?.INSTANCE_TOKEN || undefined;
|
|
202
|
+
return token;
|
|
203
|
+
}
|
|
204
|
+
var warnedArchiveAlias = false;
|
|
205
|
+
function resolveAccountKey(accountKey) {
|
|
206
|
+
if (accountKey !== undefined)
|
|
207
|
+
return accountKey;
|
|
208
|
+
if (typeof process === "undefined")
|
|
209
|
+
return;
|
|
210
|
+
const primary = process.env?.SECONDLAYER_API_KEY || undefined;
|
|
211
|
+
const slAlias = process.env?.SL_API_KEY || undefined;
|
|
212
|
+
const archiveAlias = process.env?.SL_ARCHIVE_API_KEY || undefined;
|
|
213
|
+
if (primary)
|
|
214
|
+
return primary;
|
|
215
|
+
const legacy = slAlias ?? archiveAlias;
|
|
216
|
+
if (legacy) {
|
|
217
|
+
if (!warnedArchiveAlias) {
|
|
218
|
+
warnedArchiveAlias = true;
|
|
219
|
+
console.warn("[secondlayer] SL_API_KEY / SL_ARCHIVE_API_KEY are legacy aliases of SECONDLAYER_API_KEY; using the alias this once.");
|
|
220
|
+
}
|
|
221
|
+
return legacy;
|
|
200
222
|
}
|
|
201
|
-
return
|
|
223
|
+
return;
|
|
202
224
|
}
|
|
203
225
|
function seg(value) {
|
|
204
226
|
return encodeURIComponent(String(value));
|
|
@@ -857,6 +879,7 @@ var OFFICIAL_ARCHIVE_HOST = "archive.secondlayer.tools";
|
|
|
857
879
|
var DEFAULT_ARCHIVE_BASE_URL = "https://archive.secondlayer.tools";
|
|
858
880
|
var DEFAULT_ARCHIVE_OPS_URL = "https://api.secondlayer.tools";
|
|
859
881
|
var MAX_FETCH_BATCH = 64;
|
|
882
|
+
var ARCHIVE_CREDENTIAL_RE = /^s[ks]-sl_/;
|
|
860
883
|
function quoteFromBody(body) {
|
|
861
884
|
return {
|
|
862
885
|
partitions: body.partitions,
|
|
@@ -873,7 +896,7 @@ function stripSlash(url) {
|
|
|
873
896
|
return url.replace(/\/+$/, "");
|
|
874
897
|
}
|
|
875
898
|
function createArchiveClient(options = {}) {
|
|
876
|
-
const
|
|
899
|
+
const accountKey = resolveAccountKey(options.accountKey ?? options.apiKey);
|
|
877
900
|
const fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init));
|
|
878
901
|
const archiveBaseUrl = stripSlash(options.archiveBaseUrl ?? DEFAULT_ARCHIVE_BASE_URL);
|
|
879
902
|
const archiveOpsUrl = stripSlash(options.archiveOpsUrl ?? DEFAULT_ARCHIVE_OPS_URL);
|
|
@@ -921,8 +944,12 @@ function createArchiveClient(options = {}) {
|
|
|
921
944
|
const headers = {
|
|
922
945
|
"Content-Type": "application/json"
|
|
923
946
|
};
|
|
924
|
-
if (authed &&
|
|
925
|
-
|
|
947
|
+
if (authed && accountKey) {
|
|
948
|
+
if (!ARCHIVE_CREDENTIAL_RE.test(accountKey)) {
|
|
949
|
+
throw new ArchiveAuthError("archive ops need SECONDLAYER_API_KEY (sk-sl_*), not INSTANCE_TOKEN");
|
|
950
|
+
}
|
|
951
|
+
headers.Authorization = `Bearer ${accountKey}`;
|
|
952
|
+
}
|
|
926
953
|
const response = await fetchImpl(`${archiveOpsUrl}${path}`, {
|
|
927
954
|
method,
|
|
928
955
|
headers,
|
|
@@ -956,7 +983,7 @@ function createArchiveClient(options = {}) {
|
|
|
956
983
|
if (!response.ok) {
|
|
957
984
|
throw new ApiError(response.status, `Could not fetch archive status (${response.status}).`);
|
|
958
985
|
}
|
|
959
|
-
return response.json();
|
|
986
|
+
return await response.json();
|
|
960
987
|
}
|
|
961
988
|
function partitions(ref, filter) {
|
|
962
989
|
let list = ref.manifest.partitions ?? [];
|
|
@@ -2518,7 +2545,7 @@ class SecondLayer extends BaseClient {
|
|
|
2518
2545
|
const request = (method, path, body) => this.request(method, path, body);
|
|
2519
2546
|
this.archive = {
|
|
2520
2547
|
...createArchiveClient({
|
|
2521
|
-
|
|
2548
|
+
accountKey: options.accountKey,
|
|
2522
2549
|
fetchImpl: options.fetchImpl,
|
|
2523
2550
|
archiveBaseUrl: options.archiveBaseUrl,
|
|
2524
2551
|
archiveOpsUrl: options.archiveOpsUrl
|
|
@@ -2617,5 +2644,5 @@ export {
|
|
|
2617
2644
|
Subgraphs
|
|
2618
2645
|
};
|
|
2619
2646
|
|
|
2620
|
-
//# debugId=
|
|
2647
|
+
//# debugId=19288C06BA36D64664756E2164756E21
|
|
2621
2648
|
//# sourceMappingURL=index.js.map
|