@secondlayer/sdk 6.54.0 → 7.0.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 +13 -24
- package/dist/index.d.ts +15 -587
- package/dist/index.js +42 -395
- package/dist/index.js.map +15 -22
- package/dist/sinks/bun-sqlite.js +2 -24
- package/dist/sinks/bun-sqlite.js.map +3 -3
- package/dist/sinks/core.js +2 -24
- package/dist/sinks/core.js.map +3 -3
- package/dist/sinks/drizzle.js +2 -24
- package/dist/sinks/drizzle.js.map +3 -3
- package/dist/sinks/kysely.js +2 -24
- package/dist/sinks/kysely.js.map +3 -3
- package/dist/streams/index.d.ts +9 -378
- package/dist/streams/index.js +35 -309
- package/dist/streams/index.js.map +9 -15
- package/dist/streams/rows.d.ts +2 -355
- package/dist/streams/rows.js +26 -280
- package/dist/streams/rows.js.map +4 -10
- package/dist/subgraphs/index.d.ts +2 -295
- package/dist/subgraphs/index.js +10 -174
- package/dist/subgraphs/index.js.map +10 -13
- package/dist/x402.d.ts +4 -3
- package/dist/x402.js +273 -2
- package/dist/x402.js.map +6 -4
- package/package.json +3 -3
package/dist/subgraphs/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function statusRetryable(status) {
|
|
|
57
57
|
return status === 429 || status >= 500;
|
|
58
58
|
}
|
|
59
59
|
function docsFor(status, code) {
|
|
60
|
-
if (code === "UPGRADE_REQUIRED" ||
|
|
60
|
+
if (code === "UPGRADE_REQUIRED" || status === 402)
|
|
61
61
|
return `${DOCS_BASE}/docs/authentication#pay-as-you-go-credits`;
|
|
62
62
|
if (status === 429 || status === 401)
|
|
63
63
|
return `${DOCS_BASE}/docs/authentication`;
|
|
@@ -133,28 +133,6 @@ class VersionConflictError extends ApiError {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
class ByoBreakingChangeError extends ApiError {
|
|
137
|
-
details;
|
|
138
|
-
constructor(message, details) {
|
|
139
|
-
super(422, message, details, "BYO_BREAKING_CHANGE", {
|
|
140
|
-
metaMessages: [
|
|
141
|
-
"Review and run manually on your database:",
|
|
142
|
-
details.plan.dropStatement,
|
|
143
|
-
...details.plan.statements
|
|
144
|
-
]
|
|
145
|
-
});
|
|
146
|
-
this.name = "ByoBreakingChangeError";
|
|
147
|
-
this.details = details;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function isByoBreakingDetails(x) {
|
|
151
|
-
if (!x || typeof x !== "object")
|
|
152
|
-
return false;
|
|
153
|
-
const d = x;
|
|
154
|
-
const plan = d.plan;
|
|
155
|
-
return Array.isArray(d.reasons) && !!plan && typeof plan === "object" && typeof plan.dropStatement === "string";
|
|
156
|
-
}
|
|
157
|
-
|
|
158
136
|
// src/base.ts
|
|
159
137
|
var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
160
138
|
function resolveBaseUrl(explicit) {
|
|
@@ -283,9 +261,6 @@ class BaseClient {
|
|
|
283
261
|
if (errorBody)
|
|
284
262
|
message = errorBody;
|
|
285
263
|
}
|
|
286
|
-
if (response.status === 422 && code === "BYO_BREAKING_CHANGE" && parsedBody && typeof parsedBody === "object" && isByoBreakingDetails(parsedBody.details)) {
|
|
287
|
-
throw new ByoBreakingChangeError(message, parsedBody.details);
|
|
288
|
-
}
|
|
289
264
|
throw new ApiError(response.status, message, parsedBody, code);
|
|
290
265
|
}
|
|
291
266
|
return response;
|
|
@@ -398,12 +373,6 @@ class Subgraphs extends BaseClient {
|
|
|
398
373
|
const qs = buildQuery({ force: options?.force ? true : undefined });
|
|
399
374
|
return this.request("DELETE", `/api/subgraphs/${name}${qs}`);
|
|
400
375
|
}
|
|
401
|
-
async publish(name) {
|
|
402
|
-
return this.request("POST", `/api/subgraphs/${name}/publish`);
|
|
403
|
-
}
|
|
404
|
-
async unpublish(name) {
|
|
405
|
-
return this.request("POST", `/api/subgraphs/${name}/unpublish`);
|
|
406
|
-
}
|
|
407
376
|
async rows(name, table, params = {}) {
|
|
408
377
|
const { cursor, ...rest } = params;
|
|
409
378
|
const qs = buildSubgraphQueryString(rest);
|
|
@@ -512,25 +481,6 @@ class Subgraphs extends BaseClient {
|
|
|
512
481
|
};
|
|
513
482
|
}
|
|
514
483
|
}
|
|
515
|
-
// src/api-keys/client.ts
|
|
516
|
-
class ApiKeys extends BaseClient {
|
|
517
|
-
constructor(options = {}) {
|
|
518
|
-
super(options);
|
|
519
|
-
}
|
|
520
|
-
create(params = {}) {
|
|
521
|
-
return this.request("POST", "/v1/api-keys", {
|
|
522
|
-
product: params.product,
|
|
523
|
-
name: params.name
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
list() {
|
|
527
|
-
return this.request("GET", "/api/keys");
|
|
528
|
-
}
|
|
529
|
-
revoke(id) {
|
|
530
|
-
return this.request("DELETE", `/api/keys/${id}`);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
484
|
// src/contracts/client.ts
|
|
535
485
|
class Contracts extends BaseClient {
|
|
536
486
|
constructor(options = {}) {
|
|
@@ -974,9 +924,6 @@ class Index extends BaseClient {
|
|
|
974
924
|
constructor(options = {}) {
|
|
975
925
|
super(options);
|
|
976
926
|
}
|
|
977
|
-
usage() {
|
|
978
|
-
return this.request("GET", "/v1/index/usage");
|
|
979
|
-
}
|
|
980
927
|
discover() {
|
|
981
928
|
return this.request("GET", "/v1/index");
|
|
982
929
|
}
|
|
@@ -1316,97 +1263,16 @@ class Index extends BaseClient {
|
|
|
1316
1263
|
}
|
|
1317
1264
|
}
|
|
1318
1265
|
|
|
1319
|
-
// src/projects/client.ts
|
|
1320
|
-
class Projects extends BaseClient {
|
|
1321
|
-
constructor(options = {}) {
|
|
1322
|
-
super(options);
|
|
1323
|
-
}
|
|
1324
|
-
list() {
|
|
1325
|
-
return this.request("GET", "/api/projects");
|
|
1326
|
-
}
|
|
1327
|
-
get(slug) {
|
|
1328
|
-
return this.request("GET", `/api/projects/${slug}`);
|
|
1329
|
-
}
|
|
1330
|
-
create(params) {
|
|
1331
|
-
return this.request("POST", "/api/projects", params);
|
|
1332
|
-
}
|
|
1333
|
-
update(slug, patch) {
|
|
1334
|
-
return this.request("PATCH", `/api/projects/${slug}`, patch);
|
|
1335
|
-
}
|
|
1336
|
-
delete(slug) {
|
|
1337
|
-
return this.request("DELETE", `/api/projects/${slug}`);
|
|
1338
|
-
}
|
|
1339
|
-
team(slug) {
|
|
1340
|
-
return this.request("GET", `/api/projects/${slug}/team`);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
1266
|
// src/streams/client.ts
|
|
1345
1267
|
import { ed25519 as ed255192 } from "@secondlayer/shared";
|
|
1346
1268
|
|
|
1347
|
-
// src/streams/_payload.ts
|
|
1348
|
-
function requireString(payload, field, eventType) {
|
|
1349
|
-
const value = payload[field];
|
|
1350
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
1351
|
-
throw new Error(`${eventType} payload missing ${field}`);
|
|
1352
|
-
}
|
|
1353
|
-
return value;
|
|
1354
|
-
}
|
|
1355
|
-
function optionalString(value) {
|
|
1356
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
1357
|
-
}
|
|
1358
|
-
function requireAmountField(payload, field, eventType) {
|
|
1359
|
-
const amount = requireString(payload, field, eventType);
|
|
1360
|
-
if (!/^(0|[1-9]\d*)$/.test(amount)) {
|
|
1361
|
-
throw new Error(`${eventType} payload has malformed ${field}`);
|
|
1362
|
-
}
|
|
1363
|
-
return amount;
|
|
1364
|
-
}
|
|
1365
|
-
function requireAmount(payload, eventType) {
|
|
1366
|
-
return requireAmountField(payload, "amount", eventType);
|
|
1367
|
-
}
|
|
1368
|
-
function parseAssetIdentifier(assetIdentifier, eventType) {
|
|
1369
|
-
const [contractId, tokenName] = assetIdentifier.split("::");
|
|
1370
|
-
if (!contractId) {
|
|
1371
|
-
throw new Error(`${eventType} payload has malformed asset_identifier`);
|
|
1372
|
-
}
|
|
1373
|
-
return {
|
|
1374
|
-
contract_id: contractId,
|
|
1375
|
-
token_name: tokenName && tokenName.length > 0 ? tokenName : null
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
function requireHexValue(payload, eventType) {
|
|
1379
|
-
const rawValue = payload.raw_value;
|
|
1380
|
-
if (typeof rawValue === "string") {
|
|
1381
|
-
if (!/^0x[0-9a-fA-F]*$/.test(rawValue)) {
|
|
1382
|
-
throw new Error(`${eventType} payload has malformed value`);
|
|
1383
|
-
}
|
|
1384
|
-
return rawValue;
|
|
1385
|
-
}
|
|
1386
|
-
const value = payload.value;
|
|
1387
|
-
const hex = typeof value === "string" ? value : value && typeof value === "object" && typeof value.hex === "string" ? value.hex : null;
|
|
1388
|
-
if (!hex) {
|
|
1389
|
-
throw new Error(`${eventType} payload missing value`);
|
|
1390
|
-
}
|
|
1391
|
-
if (!/^0x[0-9a-fA-F]*$/.test(hex)) {
|
|
1392
|
-
throw new Error(`${eventType} payload has malformed value`);
|
|
1393
|
-
}
|
|
1394
|
-
return hex;
|
|
1395
|
-
}
|
|
1396
|
-
function decodedRow(event, eventType, decoded_payload) {
|
|
1397
|
-
return {
|
|
1398
|
-
cursor: event.cursor,
|
|
1399
|
-
block_height: event.block_height,
|
|
1400
|
-
tx_id: event.tx_id,
|
|
1401
|
-
tx_index: event.tx_index,
|
|
1402
|
-
event_index: event.event_index,
|
|
1403
|
-
event_type: eventType,
|
|
1404
|
-
decoded_payload,
|
|
1405
|
-
source_cursor: event.cursor
|
|
1406
|
-
};
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
1269
|
// src/streams/decode.ts
|
|
1270
|
+
import {
|
|
1271
|
+
optionalString,
|
|
1272
|
+
requireAmountField,
|
|
1273
|
+
requireHexValue,
|
|
1274
|
+
requireString
|
|
1275
|
+
} from "@secondlayer/shared/streams-rows";
|
|
1410
1276
|
function decode(event) {
|
|
1411
1277
|
const base = {
|
|
1412
1278
|
cursor: event.cursor,
|
|
@@ -1986,9 +1852,6 @@ function createStreamsClient(options) {
|
|
|
1986
1852
|
},
|
|
1987
1853
|
tip() {
|
|
1988
1854
|
return request("/v1/streams/tip");
|
|
1989
|
-
},
|
|
1990
|
-
usage() {
|
|
1991
|
-
return request("/v1/streams/usage");
|
|
1992
1855
|
}
|
|
1993
1856
|
};
|
|
1994
1857
|
}
|
|
@@ -2045,8 +1908,6 @@ class SecondLayer extends BaseClient {
|
|
|
2045
1908
|
contracts;
|
|
2046
1909
|
subgraphs;
|
|
2047
1910
|
subscriptions;
|
|
2048
|
-
apiKeys;
|
|
2049
|
-
projects;
|
|
2050
1911
|
constructor(options = {}) {
|
|
2051
1912
|
super(options);
|
|
2052
1913
|
this.streams = createStreamsClient({
|
|
@@ -2059,30 +1920,18 @@ class SecondLayer extends BaseClient {
|
|
|
2059
1920
|
this.contracts = new Contracts(options);
|
|
2060
1921
|
this.subgraphs = new Subgraphs(options);
|
|
2061
1922
|
this.subscriptions = new Subscriptions(options);
|
|
2062
|
-
this.apiKeys = new ApiKeys(options);
|
|
2063
|
-
this.projects = new Projects(options);
|
|
2064
1923
|
}
|
|
2065
1924
|
async batch(requests) {
|
|
2066
1925
|
return this.request("POST", "/v1/batch", { requests });
|
|
2067
1926
|
}
|
|
2068
1927
|
async context() {
|
|
2069
1928
|
const safe = (p) => p.then((v) => v).catch(() => null);
|
|
2070
|
-
const [
|
|
2071
|
-
account,
|
|
2072
|
-
streamsTip,
|
|
2073
|
-
indexEnv,
|
|
2074
|
-
subgraphsRes,
|
|
2075
|
-
subscriptionsRes,
|
|
2076
|
-
projectsRes,
|
|
2077
|
-
apiKeysRes
|
|
2078
|
-
] = await Promise.all([
|
|
1929
|
+
const [account, streamsTip, indexEnv, subgraphsRes, subscriptionsRes] = await Promise.all([
|
|
2079
1930
|
safe(this.request("GET", "/api/accounts/me")),
|
|
2080
1931
|
safe(this.streams.tip()),
|
|
2081
1932
|
safe(this.index.canonical.list({ limit: 1 })),
|
|
2082
1933
|
safe(this.subgraphs.list()),
|
|
2083
|
-
safe(this.subscriptions.list())
|
|
2084
|
-
safe(this.projects.list()),
|
|
2085
|
-
safe(this.apiKeys.list())
|
|
1934
|
+
safe(this.subscriptions.list())
|
|
2086
1935
|
]);
|
|
2087
1936
|
const subgraphs = subgraphsRes?.data ?? null;
|
|
2088
1937
|
let subscriptions = null;
|
|
@@ -2108,25 +1957,12 @@ class SecondLayer extends BaseClient {
|
|
|
2108
1957
|
}));
|
|
2109
1958
|
activeOperations = probed.filter((o) => o !== null);
|
|
2110
1959
|
}
|
|
2111
|
-
const projects = projectsRes ? projectsRes.projects.map((p) => ({
|
|
2112
|
-
name: p.name,
|
|
2113
|
-
slug: p.slug,
|
|
2114
|
-
network: p.network
|
|
2115
|
-
})) : null;
|
|
2116
|
-
const apiKeys = apiKeysRes ? apiKeysRes.keys.map((k) => ({
|
|
2117
|
-
prefix: k.prefix,
|
|
2118
|
-
name: k.name,
|
|
2119
|
-
status: k.status,
|
|
2120
|
-
product: k.product
|
|
2121
|
-
})) : null;
|
|
2122
1960
|
return {
|
|
2123
1961
|
account,
|
|
2124
1962
|
streamsTip,
|
|
2125
1963
|
indexTip: indexEnv?.tip ?? null,
|
|
2126
1964
|
subgraphs,
|
|
2127
1965
|
subscriptions,
|
|
2128
|
-
projects,
|
|
2129
|
-
apiKeys,
|
|
2130
1966
|
activeOperations
|
|
2131
1967
|
};
|
|
2132
1968
|
}
|
|
@@ -2147,5 +1983,5 @@ export {
|
|
|
2147
1983
|
Subgraphs
|
|
2148
1984
|
};
|
|
2149
1985
|
|
|
2150
|
-
//# debugId=
|
|
1986
|
+
//# debugId=D755EDD13178F73464756E2164756E21
|
|
2151
1987
|
//# sourceMappingURL=index.js.map
|