@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/streams/index.js
CHANGED
|
@@ -60,7 +60,7 @@ function statusRetryable(status) {
|
|
|
60
60
|
return status === 429 || status >= 500;
|
|
61
61
|
}
|
|
62
62
|
function docsFor(status, code) {
|
|
63
|
-
if (code === "UPGRADE_REQUIRED" ||
|
|
63
|
+
if (code === "UPGRADE_REQUIRED" || status === 402)
|
|
64
64
|
return `${DOCS_BASE}/docs/authentication#pay-as-you-go-credits`;
|
|
65
65
|
if (status === 429 || status === 401)
|
|
66
66
|
return `${DOCS_BASE}/docs/authentication`;
|
|
@@ -136,28 +136,6 @@ class VersionConflictError extends ApiError {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
class ByoBreakingChangeError extends ApiError {
|
|
140
|
-
details;
|
|
141
|
-
constructor(message, details) {
|
|
142
|
-
super(422, message, details, "BYO_BREAKING_CHANGE", {
|
|
143
|
-
metaMessages: [
|
|
144
|
-
"Review and run manually on your database:",
|
|
145
|
-
details.plan.dropStatement,
|
|
146
|
-
...details.plan.statements
|
|
147
|
-
]
|
|
148
|
-
});
|
|
149
|
-
this.name = "ByoBreakingChangeError";
|
|
150
|
-
this.details = details;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function isByoBreakingDetails(x) {
|
|
154
|
-
if (!x || typeof x !== "object")
|
|
155
|
-
return false;
|
|
156
|
-
const d = x;
|
|
157
|
-
const plan = d.plan;
|
|
158
|
-
return Array.isArray(d.reasons) && !!plan && typeof plan === "object" && typeof plan.dropStatement === "string";
|
|
159
|
-
}
|
|
160
|
-
|
|
161
139
|
// src/base.ts
|
|
162
140
|
var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
163
141
|
function resolveBaseUrl(explicit) {
|
|
@@ -286,9 +264,6 @@ class BaseClient {
|
|
|
286
264
|
if (errorBody)
|
|
287
265
|
message = errorBody;
|
|
288
266
|
}
|
|
289
|
-
if (response.status === 422 && code === "BYO_BREAKING_CHANGE" && parsedBody && typeof parsedBody === "object" && isByoBreakingDetails(parsedBody.details)) {
|
|
290
|
-
throw new ByoBreakingChangeError(message, parsedBody.details);
|
|
291
|
-
}
|
|
292
267
|
throw new ApiError(response.status, message, parsedBody, code);
|
|
293
268
|
}
|
|
294
269
|
return response;
|
|
@@ -595,69 +570,13 @@ async function* streamStreamsEvents(opts) {
|
|
|
595
570
|
}
|
|
596
571
|
}
|
|
597
572
|
|
|
598
|
-
// src/streams/_payload.ts
|
|
599
|
-
function requireString(payload, field, eventType) {
|
|
600
|
-
const value = payload[field];
|
|
601
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
602
|
-
throw new Error(`${eventType} payload missing ${field}`);
|
|
603
|
-
}
|
|
604
|
-
return value;
|
|
605
|
-
}
|
|
606
|
-
function optionalString(value) {
|
|
607
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
608
|
-
}
|
|
609
|
-
function requireAmountField(payload, field, eventType) {
|
|
610
|
-
const amount = requireString(payload, field, eventType);
|
|
611
|
-
if (!/^(0|[1-9]\d*)$/.test(amount)) {
|
|
612
|
-
throw new Error(`${eventType} payload has malformed ${field}`);
|
|
613
|
-
}
|
|
614
|
-
return amount;
|
|
615
|
-
}
|
|
616
|
-
function requireAmount(payload, eventType) {
|
|
617
|
-
return requireAmountField(payload, "amount", eventType);
|
|
618
|
-
}
|
|
619
|
-
function parseAssetIdentifier(assetIdentifier, eventType) {
|
|
620
|
-
const [contractId, tokenName] = assetIdentifier.split("::");
|
|
621
|
-
if (!contractId) {
|
|
622
|
-
throw new Error(`${eventType} payload has malformed asset_identifier`);
|
|
623
|
-
}
|
|
624
|
-
return {
|
|
625
|
-
contract_id: contractId,
|
|
626
|
-
token_name: tokenName && tokenName.length > 0 ? tokenName : null
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
function requireHexValue(payload, eventType) {
|
|
630
|
-
const rawValue = payload.raw_value;
|
|
631
|
-
if (typeof rawValue === "string") {
|
|
632
|
-
if (!/^0x[0-9a-fA-F]*$/.test(rawValue)) {
|
|
633
|
-
throw new Error(`${eventType} payload has malformed value`);
|
|
634
|
-
}
|
|
635
|
-
return rawValue;
|
|
636
|
-
}
|
|
637
|
-
const value = payload.value;
|
|
638
|
-
const hex = typeof value === "string" ? value : value && typeof value === "object" && typeof value.hex === "string" ? value.hex : null;
|
|
639
|
-
if (!hex) {
|
|
640
|
-
throw new Error(`${eventType} payload missing value`);
|
|
641
|
-
}
|
|
642
|
-
if (!/^0x[0-9a-fA-F]*$/.test(hex)) {
|
|
643
|
-
throw new Error(`${eventType} payload has malformed value`);
|
|
644
|
-
}
|
|
645
|
-
return hex;
|
|
646
|
-
}
|
|
647
|
-
function decodedRow(event, eventType, decoded_payload) {
|
|
648
|
-
return {
|
|
649
|
-
cursor: event.cursor,
|
|
650
|
-
block_height: event.block_height,
|
|
651
|
-
tx_id: event.tx_id,
|
|
652
|
-
tx_index: event.tx_index,
|
|
653
|
-
event_index: event.event_index,
|
|
654
|
-
event_type: eventType,
|
|
655
|
-
decoded_payload,
|
|
656
|
-
source_cursor: event.cursor
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
|
|
660
573
|
// src/streams/decode.ts
|
|
574
|
+
import {
|
|
575
|
+
optionalString,
|
|
576
|
+
requireAmountField,
|
|
577
|
+
requireHexValue,
|
|
578
|
+
requireString
|
|
579
|
+
} from "@secondlayer/shared/streams-rows";
|
|
661
580
|
function decode(event) {
|
|
662
581
|
const base = {
|
|
663
582
|
cursor: event.cursor,
|
|
@@ -1237,233 +1156,40 @@ function createStreamsClient(options) {
|
|
|
1237
1156
|
},
|
|
1238
1157
|
tip() {
|
|
1239
1158
|
return request("/v1/streams/tip");
|
|
1240
|
-
},
|
|
1241
|
-
usage() {
|
|
1242
|
-
return request("/v1/streams/usage");
|
|
1243
1159
|
}
|
|
1244
1160
|
};
|
|
1245
1161
|
}
|
|
1246
|
-
// src/streams/ft-transfer.ts
|
|
1247
|
-
function isFtTransfer(event) {
|
|
1248
|
-
return event.event_type === "ft_transfer";
|
|
1249
|
-
}
|
|
1250
|
-
function decodeFtTransfer(event) {
|
|
1251
|
-
if (!isFtTransfer(event)) {
|
|
1252
|
-
throw new Error(`Expected ft_transfer event, got ${event.event_type}`);
|
|
1253
|
-
}
|
|
1254
|
-
const payload = event.payload;
|
|
1255
|
-
const assetIdentifier = requireString(payload, "asset_identifier", "ft_transfer");
|
|
1256
|
-
const sender = requireString(payload, "sender", "ft_transfer");
|
|
1257
|
-
const recipient = requireString(payload, "recipient", "ft_transfer");
|
|
1258
|
-
const amount = requireAmount(payload, "ft_transfer");
|
|
1259
|
-
const { contract_id, token_name } = parseAssetIdentifier(assetIdentifier, "ft_transfer");
|
|
1260
|
-
return decodedRow(event, "ft_transfer", {
|
|
1261
|
-
asset_identifier: assetIdentifier,
|
|
1262
|
-
contract_id: event.contract_id ?? contract_id,
|
|
1263
|
-
token_name,
|
|
1264
|
-
sender,
|
|
1265
|
-
recipient,
|
|
1266
|
-
amount
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
// src/streams/nft-transfer.ts
|
|
1270
|
-
function isNftTransfer(event) {
|
|
1271
|
-
return event.event_type === "nft_transfer";
|
|
1272
|
-
}
|
|
1273
|
-
function decodeNftTransfer(event) {
|
|
1274
|
-
if (!isNftTransfer(event)) {
|
|
1275
|
-
throw new Error(`Expected nft_transfer event, got ${event.event_type}`);
|
|
1276
|
-
}
|
|
1277
|
-
const payload = event.payload;
|
|
1278
|
-
const assetIdentifier = requireString(payload, "asset_identifier", "nft_transfer");
|
|
1279
|
-
const sender = requireString(payload, "sender", "nft_transfer");
|
|
1280
|
-
const recipient = requireString(payload, "recipient", "nft_transfer");
|
|
1281
|
-
const value = requireHexValue(payload, "nft_transfer");
|
|
1282
|
-
const { contract_id, token_name } = parseAssetIdentifier(assetIdentifier, "nft_transfer");
|
|
1283
|
-
return decodedRow(event, "nft_transfer", {
|
|
1284
|
-
asset_identifier: assetIdentifier,
|
|
1285
|
-
contract_id: event.contract_id ?? contract_id,
|
|
1286
|
-
token_name,
|
|
1287
|
-
sender,
|
|
1288
|
-
recipient,
|
|
1289
|
-
value
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
// src/streams/stx-events.ts
|
|
1293
|
-
function isStxTransfer(event) {
|
|
1294
|
-
return event.event_type === "stx_transfer";
|
|
1295
|
-
}
|
|
1296
|
-
function decodeStxTransfer(event) {
|
|
1297
|
-
if (!isStxTransfer(event)) {
|
|
1298
|
-
throw new Error(`Expected stx_transfer event, got ${event.event_type}`);
|
|
1299
|
-
}
|
|
1300
|
-
const payload = event.payload;
|
|
1301
|
-
return decodedRow(event, "stx_transfer", {
|
|
1302
|
-
sender: requireString(payload, "sender", "stx_transfer"),
|
|
1303
|
-
recipient: requireString(payload, "recipient", "stx_transfer"),
|
|
1304
|
-
amount: requireAmount(payload, "stx_transfer"),
|
|
1305
|
-
memo: optionalString(payload.memo)
|
|
1306
|
-
});
|
|
1307
|
-
}
|
|
1308
|
-
function isStxMint(event) {
|
|
1309
|
-
return event.event_type === "stx_mint";
|
|
1310
|
-
}
|
|
1311
|
-
function decodeStxMint(event) {
|
|
1312
|
-
if (!isStxMint(event)) {
|
|
1313
|
-
throw new Error(`Expected stx_mint event, got ${event.event_type}`);
|
|
1314
|
-
}
|
|
1315
|
-
const payload = event.payload;
|
|
1316
|
-
return decodedRow(event, "stx_mint", {
|
|
1317
|
-
recipient: requireString(payload, "recipient", "stx_mint"),
|
|
1318
|
-
amount: requireAmount(payload, "stx_mint")
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
function isStxBurn(event) {
|
|
1322
|
-
return event.event_type === "stx_burn";
|
|
1323
|
-
}
|
|
1324
|
-
function decodeStxBurn(event) {
|
|
1325
|
-
if (!isStxBurn(event)) {
|
|
1326
|
-
throw new Error(`Expected stx_burn event, got ${event.event_type}`);
|
|
1327
|
-
}
|
|
1328
|
-
const payload = event.payload;
|
|
1329
|
-
return decodedRow(event, "stx_burn", {
|
|
1330
|
-
sender: requireString(payload, "sender", "stx_burn"),
|
|
1331
|
-
amount: requireAmount(payload, "stx_burn")
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
function isStxLock(event) {
|
|
1335
|
-
return event.event_type === "stx_lock";
|
|
1336
|
-
}
|
|
1337
|
-
function decodeStxLock(event) {
|
|
1338
|
-
if (!isStxLock(event)) {
|
|
1339
|
-
throw new Error(`Expected stx_lock event, got ${event.event_type}`);
|
|
1340
|
-
}
|
|
1341
|
-
const payload = event.payload;
|
|
1342
|
-
return decodedRow(event, "stx_lock", {
|
|
1343
|
-
sender: requireString(payload, "locked_address", "stx_lock"),
|
|
1344
|
-
amount: requireAmountField(payload, "locked_amount", "stx_lock"),
|
|
1345
|
-
payload: { unlock_height: optionalString(payload.unlock_height) }
|
|
1346
|
-
});
|
|
1347
|
-
}
|
|
1348
|
-
// src/streams/token-mint-burn.ts
|
|
1349
|
-
function assetFields(event, eventType) {
|
|
1350
|
-
const assetIdentifier = requireString(event.payload, "asset_identifier", eventType);
|
|
1351
|
-
const { contract_id, token_name } = parseAssetIdentifier(assetIdentifier, eventType);
|
|
1352
|
-
return {
|
|
1353
|
-
asset_identifier: assetIdentifier,
|
|
1354
|
-
contract_id: event.contract_id ?? contract_id,
|
|
1355
|
-
token_name
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
function isFtMint(event) {
|
|
1359
|
-
return event.event_type === "ft_mint";
|
|
1360
|
-
}
|
|
1361
|
-
function decodeFtMint(event) {
|
|
1362
|
-
if (!isFtMint(event)) {
|
|
1363
|
-
throw new Error(`Expected ft_mint event, got ${event.event_type}`);
|
|
1364
|
-
}
|
|
1365
|
-
return decodedRow(event, "ft_mint", {
|
|
1366
|
-
...assetFields(event, "ft_mint"),
|
|
1367
|
-
recipient: requireString(event.payload, "recipient", "ft_mint"),
|
|
1368
|
-
amount: requireAmount(event.payload, "ft_mint")
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
function isFtBurn(event) {
|
|
1372
|
-
return event.event_type === "ft_burn";
|
|
1373
|
-
}
|
|
1374
|
-
function decodeFtBurn(event) {
|
|
1375
|
-
if (!isFtBurn(event)) {
|
|
1376
|
-
throw new Error(`Expected ft_burn event, got ${event.event_type}`);
|
|
1377
|
-
}
|
|
1378
|
-
return decodedRow(event, "ft_burn", {
|
|
1379
|
-
...assetFields(event, "ft_burn"),
|
|
1380
|
-
sender: requireString(event.payload, "sender", "ft_burn"),
|
|
1381
|
-
amount: requireAmount(event.payload, "ft_burn")
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
|
-
function isNftMint(event) {
|
|
1385
|
-
return event.event_type === "nft_mint";
|
|
1386
|
-
}
|
|
1387
|
-
function decodeNftMint(event) {
|
|
1388
|
-
if (!isNftMint(event)) {
|
|
1389
|
-
throw new Error(`Expected nft_mint event, got ${event.event_type}`);
|
|
1390
|
-
}
|
|
1391
|
-
return decodedRow(event, "nft_mint", {
|
|
1392
|
-
...assetFields(event, "nft_mint"),
|
|
1393
|
-
recipient: requireString(event.payload, "recipient", "nft_mint"),
|
|
1394
|
-
value: requireHexValue(event.payload, "nft_mint")
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
function isNftBurn(event) {
|
|
1398
|
-
return event.event_type === "nft_burn";
|
|
1399
|
-
}
|
|
1400
|
-
function decodeNftBurn(event) {
|
|
1401
|
-
if (!isNftBurn(event)) {
|
|
1402
|
-
throw new Error(`Expected nft_burn event, got ${event.event_type}`);
|
|
1403
|
-
}
|
|
1404
|
-
return decodedRow(event, "nft_burn", {
|
|
1405
|
-
...assetFields(event, "nft_burn"),
|
|
1406
|
-
sender: requireString(event.payload, "sender", "nft_burn"),
|
|
1407
|
-
value: requireHexValue(event.payload, "nft_burn")
|
|
1408
|
-
});
|
|
1409
|
-
}
|
|
1410
|
-
// src/clarity.ts
|
|
1411
|
-
import { cvToValue, deserializeCV } from "@secondlayer/stacks/clarity";
|
|
1412
|
-
function toJsonSafe(value) {
|
|
1413
|
-
if (typeof value === "bigint")
|
|
1414
|
-
return value.toString();
|
|
1415
|
-
if (Array.isArray(value))
|
|
1416
|
-
return value.map(toJsonSafe);
|
|
1417
|
-
if (value && typeof value === "object") {
|
|
1418
|
-
const out = {};
|
|
1419
|
-
for (const [key, val] of Object.entries(value)) {
|
|
1420
|
-
out[key] = toJsonSafe(val);
|
|
1421
|
-
}
|
|
1422
|
-
return out;
|
|
1423
|
-
}
|
|
1424
|
-
return value;
|
|
1425
|
-
}
|
|
1426
|
-
function decodeClarityValue(hex) {
|
|
1427
|
-
try {
|
|
1428
|
-
const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
1429
|
-
return toJsonSafe(cvToValue(deserializeCV(clean)));
|
|
1430
|
-
} catch {
|
|
1431
|
-
return hex;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
1162
|
|
|
1435
|
-
// src/streams/
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1163
|
+
// src/streams/index.ts
|
|
1164
|
+
import {
|
|
1165
|
+
decodeFtTransfer,
|
|
1166
|
+
isFtTransfer,
|
|
1167
|
+
decodeNftTransfer,
|
|
1168
|
+
isNftTransfer,
|
|
1169
|
+
decodeStxBurn,
|
|
1170
|
+
decodeStxLock,
|
|
1171
|
+
decodeStxMint,
|
|
1172
|
+
decodeStxTransfer,
|
|
1173
|
+
isStxBurn,
|
|
1174
|
+
isStxLock,
|
|
1175
|
+
isStxMint,
|
|
1176
|
+
isStxTransfer,
|
|
1177
|
+
decodeFtBurn,
|
|
1178
|
+
decodeFtMint,
|
|
1179
|
+
decodeNftBurn,
|
|
1180
|
+
decodeNftMint,
|
|
1181
|
+
isFtBurn,
|
|
1182
|
+
isFtMint,
|
|
1183
|
+
isNftBurn,
|
|
1184
|
+
isNftMint,
|
|
1185
|
+
decodePrint,
|
|
1186
|
+
isPrint
|
|
1187
|
+
} from "@secondlayer/shared/streams-rows";
|
|
1188
|
+
|
|
1463
1189
|
// src/streams/types.ts
|
|
1464
1190
|
import {
|
|
1465
1191
|
STREAMS_EVENT_TYPES
|
|
1466
|
-
} from "@secondlayer/shared";
|
|
1192
|
+
} from "@secondlayer/shared/streams-rows";
|
|
1467
1193
|
export {
|
|
1468
1194
|
isStxTransfer,
|
|
1469
1195
|
isStxMint,
|
|
@@ -1498,5 +1224,5 @@ export {
|
|
|
1498
1224
|
AuthError
|
|
1499
1225
|
};
|
|
1500
1226
|
|
|
1501
|
-
//# debugId=
|
|
1227
|
+
//# debugId=A2051B41B83FE0EE64756E2164756E21
|
|
1502
1228
|
//# sourceMappingURL=index.js.map
|