@secondlayer/shared 6.28.1 → 6.30.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/dist/src/db/index.d.ts +59 -2
- package/dist/src/db/index.js +4 -1
- package/dist/src/db/index.js.map +3 -3
- package/dist/src/db/queries/chain-reorgs.d.ts +53 -1
- package/dist/src/db/queries/chain-reorgs.js +4 -1
- package/dist/src/db/queries/chain-reorgs.js.map +3 -3
- package/dist/src/db/queries/contracts.d.ts +53 -1
- package/dist/src/db/queries/integrity.d.ts +53 -1
- package/dist/src/db/queries/subgraph-gaps.d.ts +53 -1
- package/dist/src/db/queries/subgraph-operations.d.ts +53 -1
- package/dist/src/db/queries/subgraphs.d.ts +63 -2
- package/dist/src/db/queries/subgraphs.js +16 -1
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/subscriptions.d.ts +53 -1
- package/dist/src/db/schema.d.ts +56 -2
- package/dist/src/errors.d.ts +11 -2
- package/dist/src/errors.js +14 -2
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index-http.d.ts +3 -0
- package/dist/src/index-http.js +12 -1
- package/dist/src/index-http.js.map +3 -3
- package/dist/src/index.d.ts +91 -11
- package/dist/src/index.js +101 -38
- package/dist/src/index.js.map +7 -7
- package/dist/src/node/hiro-client.d.ts +15 -1
- package/dist/src/node/hiro-client.js +10 -1
- package/dist/src/node/hiro-client.js.map +3 -3
- package/dist/src/node/local-client.d.ts +53 -1
- package/dist/src/schemas/index.d.ts +14 -0
- package/dist/src/schemas/index.js +3 -2
- package/dist/src/schemas/index.js.map +3 -3
- package/dist/src/schemas/subgraphs.d.ts +14 -0
- package/dist/src/schemas/subgraphs.js +3 -2
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/dist/src/subgraphs/spec.d.ts +3 -0
- package/dist/src/subgraphs/spec.js +83 -36
- package/dist/src/subgraphs/spec.js.map +3 -3
- package/dist/src/x402.d.ts +38 -0
- package/dist/src/x402.js +74 -0
- package/dist/src/x402.js.map +10 -0
- package/migrations/0090_events_streams_filter_idx.ts +8 -0
- package/migrations/0091_x402_payments.ts +41 -0
- package/migrations/0092_subgraph_visibility.ts +33 -0
- package/migrations/0093_ghost_accounts.ts +47 -0
- package/migrations/0094_paid_subgraph_deploys.ts +39 -0
- package/migrations/0095_x402_balances.ts +37 -0
- package/migrations/0096_x402_continuity.ts +48 -0
- package/package.json +6 -2
package/dist/src/index.js
CHANGED
|
@@ -672,6 +672,7 @@ var TABLE_TO_DB = {
|
|
|
672
672
|
api_keys: "target",
|
|
673
673
|
sessions: "target",
|
|
674
674
|
magic_links: "target",
|
|
675
|
+
claim_tokens: "target",
|
|
675
676
|
usage_daily: "target",
|
|
676
677
|
usage_snapshots: "target",
|
|
677
678
|
account_insights: "target",
|
|
@@ -698,6 +699,8 @@ var TABLE_TO_DB = {
|
|
|
698
699
|
subgraph_usage_daily: "target",
|
|
699
700
|
subgraph_processing_stats: "target",
|
|
700
701
|
subgraph_table_snapshots: "target",
|
|
702
|
+
x402_payments: "target",
|
|
703
|
+
x402_balances: "target",
|
|
701
704
|
service_heartbeats: "both"
|
|
702
705
|
};
|
|
703
706
|
|
|
@@ -864,6 +867,7 @@ var ErrorCodes = {
|
|
|
864
867
|
AUTHENTICATION_ERROR: "AUTHENTICATION_ERROR",
|
|
865
868
|
AUTHORIZATION_ERROR: "AUTHORIZATION_ERROR",
|
|
866
869
|
RATE_LIMIT_ERROR: "RATE_LIMIT_ERROR",
|
|
870
|
+
PAYMENT_REQUIRED: "PAYMENT_REQUIRED",
|
|
867
871
|
FORBIDDEN: "FORBIDDEN",
|
|
868
872
|
VERSION_CONFLICT: "VERSION_CONFLICT",
|
|
869
873
|
NOT_FOUND: "NOT_FOUND",
|
|
@@ -933,6 +937,12 @@ class RateLimitError extends SecondLayerError {
|
|
|
933
937
|
}
|
|
934
938
|
}
|
|
935
939
|
|
|
940
|
+
class PaymentRequiredError extends SecondLayerError {
|
|
941
|
+
constructor(message, details) {
|
|
942
|
+
super("PAYMENT_REQUIRED", message, undefined, details);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
936
946
|
class ForbiddenError extends SecondLayerError {
|
|
937
947
|
constructor(message = "Forbidden") {
|
|
938
948
|
super("FORBIDDEN", message);
|
|
@@ -963,6 +973,7 @@ class TenantSuspendedError extends SecondLayerError {
|
|
|
963
973
|
var CODE_TO_STATUS = {
|
|
964
974
|
AUTHENTICATION_ERROR: 401,
|
|
965
975
|
AUTHORIZATION_ERROR: 403,
|
|
976
|
+
PAYMENT_REQUIRED: 402,
|
|
966
977
|
RATE_LIMIT_ERROR: 429,
|
|
967
978
|
FORBIDDEN: 403,
|
|
968
979
|
NOT_FOUND: 404,
|
|
@@ -972,7 +983,10 @@ var CODE_TO_STATUS = {
|
|
|
972
983
|
NO_TENANT_FOR_PROJECT: 404,
|
|
973
984
|
INSTANCE_EXISTS: 409,
|
|
974
985
|
SUBGRAPH_NOT_FOUND: 404,
|
|
975
|
-
BYO_BREAKING_CHANGE: 422
|
|
986
|
+
BYO_BREAKING_CHANGE: 422,
|
|
987
|
+
PUBLIC_NAME_TAKEN: 409,
|
|
988
|
+
GHOST_KEY_READ_ONLY: 403,
|
|
989
|
+
GENESIS_BACKFILL_REQUIRES_PLAN: 403
|
|
976
990
|
};
|
|
977
991
|
function getErrorMessage(err) {
|
|
978
992
|
return err instanceof Error ? err.message : String(err);
|
|
@@ -1094,7 +1108,8 @@ var DeploySubgraphRequestSchema = z3.object({
|
|
|
1094
1108
|
startBlock: z3.number().int().nonnegative().optional(),
|
|
1095
1109
|
sourceCode: z3.string().max(1048576, "source code exceeds 1MB limit").optional(),
|
|
1096
1110
|
databaseUrl: z3.string().url().refine((u) => u.startsWith("postgres://") || u.startsWith("postgresql://"), "must be a postgres:// connection string").optional(),
|
|
1097
|
-
dryRun: z3.boolean().optional()
|
|
1111
|
+
dryRun: z3.boolean().optional(),
|
|
1112
|
+
visibility: z3.enum(["public", "private"]).optional()
|
|
1098
1113
|
});
|
|
1099
1114
|
|
|
1100
1115
|
// src/schemas/subscriptions.ts
|
|
@@ -1414,18 +1429,23 @@ function validateSubscriptionFilterForTable(input) {
|
|
|
1414
1429
|
// src/subgraphs/spec.ts
|
|
1415
1430
|
var SYSTEM_COLUMNS = ["_id", "_block_height", "_tx_id", "_created_at"];
|
|
1416
1431
|
var BASE_QUERY_PARAMS = ["_limit", "_offset", "_sort", "_order", "_fields"];
|
|
1432
|
+
var PUBLIC_BASE_QUERY_PARAMS = ["_limit", "cursor", "_order", "_fields"];
|
|
1417
1433
|
var COMPARISON_OPS = ["neq", "gt", "gte", "lt", "lte"];
|
|
1434
|
+
function isPublicRead(detail) {
|
|
1435
|
+
return detail.visibility === "public";
|
|
1436
|
+
}
|
|
1418
1437
|
function generatedAt(options) {
|
|
1419
1438
|
return options.generatedAt ?? new Date().toISOString();
|
|
1420
1439
|
}
|
|
1421
1440
|
function normalizeServerUrl(serverUrl) {
|
|
1422
1441
|
return (serverUrl ?? "https://api.secondlayer.tools").replace(/\/+$/, "");
|
|
1423
1442
|
}
|
|
1424
|
-
function tablePath(subgraphName, tableName) {
|
|
1425
|
-
|
|
1443
|
+
function tablePath(subgraphName, tableName, publicRead) {
|
|
1444
|
+
const base = publicRead ? "/v1/subgraphs" : "/api/subgraphs";
|
|
1445
|
+
return `${base}/${subgraphName}/${tableName}`;
|
|
1426
1446
|
}
|
|
1427
|
-
function countPath(subgraphName, tableName) {
|
|
1428
|
-
return `${tablePath(subgraphName, tableName)}/count`;
|
|
1447
|
+
function countPath(subgraphName, tableName, publicRead) {
|
|
1448
|
+
return `${tablePath(subgraphName, tableName, publicRead)}/count`;
|
|
1429
1449
|
}
|
|
1430
1450
|
function isTextLike(type) {
|
|
1431
1451
|
return type === "text" || type === "principal" || type === "timestamp";
|
|
@@ -1512,8 +1532,8 @@ function filterNames(table) {
|
|
|
1512
1532
|
}
|
|
1513
1533
|
return result;
|
|
1514
1534
|
}
|
|
1515
|
-
function queryParameters(table) {
|
|
1516
|
-
const params = [...BASE_QUERY_PARAMS];
|
|
1535
|
+
function queryParameters(table, publicRead) {
|
|
1536
|
+
const params = publicRead ? [...PUBLIC_BASE_QUERY_PARAMS] : [...BASE_QUERY_PARAMS];
|
|
1517
1537
|
if (searchableColumns(table).length > 0)
|
|
1518
1538
|
params.push("_search");
|
|
1519
1539
|
return params;
|
|
@@ -1534,8 +1554,24 @@ function openApiParameter(name2, description, schema = { type: "string" }) {
|
|
|
1534
1554
|
schema
|
|
1535
1555
|
};
|
|
1536
1556
|
}
|
|
1537
|
-
function tableParameters(table) {
|
|
1538
|
-
const parameters = [
|
|
1557
|
+
function tableParameters(table, publicRead) {
|
|
1558
|
+
const parameters = publicRead ? [
|
|
1559
|
+
openApiParameter("_limit", "Maximum rows to return.", {
|
|
1560
|
+
type: "integer",
|
|
1561
|
+
default: 50,
|
|
1562
|
+
minimum: 1,
|
|
1563
|
+
maximum: 1000
|
|
1564
|
+
}),
|
|
1565
|
+
openApiParameter("cursor", "Resume token from next_cursor (keyset pagination on _id).", { type: "string" }),
|
|
1566
|
+
openApiParameter("_order", "Sort direction (_id keyset).", {
|
|
1567
|
+
type: "string",
|
|
1568
|
+
enum: ["asc", "desc"],
|
|
1569
|
+
default: "asc"
|
|
1570
|
+
}),
|
|
1571
|
+
openApiParameter("_fields", "Comma-separated columns to include.", {
|
|
1572
|
+
type: "string"
|
|
1573
|
+
})
|
|
1574
|
+
] : [
|
|
1539
1575
|
openApiParameter("_limit", "Maximum rows to return.", {
|
|
1540
1576
|
type: "integer",
|
|
1541
1577
|
default: 50,
|
|
@@ -1589,19 +1625,24 @@ function tableParameters(table) {
|
|
|
1589
1625
|
}
|
|
1590
1626
|
function generateSubgraphAgentSchema(detail, options = {}) {
|
|
1591
1627
|
const serverUrl = normalizeServerUrl(options.serverUrl);
|
|
1628
|
+
const publicRead = isPublicRead(detail);
|
|
1592
1629
|
const tables = {};
|
|
1593
1630
|
for (const [tableName, table] of Object.entries(detail.tables)) {
|
|
1594
|
-
const path = tablePath(detail.name, tableName);
|
|
1631
|
+
const path = tablePath(detail.name, tableName, publicRead);
|
|
1595
1632
|
tables[tableName] = {
|
|
1596
1633
|
endpoint: `${serverUrl}${path}`,
|
|
1597
|
-
countEndpoint: `${serverUrl}${countPath(detail.name, tableName)}`,
|
|
1634
|
+
countEndpoint: `${serverUrl}${countPath(detail.name, tableName, publicRead)}`,
|
|
1635
|
+
...publicRead ? {
|
|
1636
|
+
aggregateEndpoint: `${serverUrl}${path}/aggregate`,
|
|
1637
|
+
streamEndpoint: `${serverUrl}${path}/stream`
|
|
1638
|
+
} : {},
|
|
1598
1639
|
rowCount: table.rowCount,
|
|
1599
1640
|
columns: table.columns,
|
|
1600
1641
|
...table.indexes ? { indexes: table.indexes } : {},
|
|
1601
1642
|
...table.uniqueKeys ? { uniqueKeys: table.uniqueKeys } : {},
|
|
1602
1643
|
query: {
|
|
1603
|
-
parameters: queryParameters(table),
|
|
1604
|
-
sortable: selectableColumns(table),
|
|
1644
|
+
parameters: queryParameters(table, publicRead),
|
|
1645
|
+
sortable: publicRead ? [] : selectableColumns(table),
|
|
1605
1646
|
selectable: selectableColumns(table),
|
|
1606
1647
|
searchable: searchableColumns(table),
|
|
1607
1648
|
filters: filterNames(table)
|
|
@@ -1609,7 +1650,7 @@ function generateSubgraphAgentSchema(detail, options = {}) {
|
|
|
1609
1650
|
examples: {
|
|
1610
1651
|
list: rowExample(table),
|
|
1611
1652
|
count: { count: table.rowCount },
|
|
1612
|
-
curl: `curl '${serverUrl}${path}?_limit=10&_sort=_block_height&_order=desc'`
|
|
1653
|
+
curl: publicRead ? `curl '${serverUrl}${path}?_limit=10&_order=desc'` : `curl '${serverUrl}${path}?_limit=10&_sort=_block_height&_order=desc'`
|
|
1613
1654
|
}
|
|
1614
1655
|
};
|
|
1615
1656
|
}
|
|
@@ -1626,6 +1667,7 @@ function generateSubgraphAgentSchema(detail, options = {}) {
|
|
|
1626
1667
|
}
|
|
1627
1668
|
function generateSubgraphOpenApi(detail, options = {}) {
|
|
1628
1669
|
const serverUrl = normalizeServerUrl(options.serverUrl);
|
|
1670
|
+
const publicRead = isPublicRead(detail);
|
|
1629
1671
|
const paths = {};
|
|
1630
1672
|
const schemas = {};
|
|
1631
1673
|
for (const [tableName, table] of Object.entries(detail.tables)) {
|
|
@@ -1643,44 +1685,62 @@ function generateSubgraphOpenApi(detail, options = {}) {
|
|
|
1643
1685
|
required,
|
|
1644
1686
|
example: rowExample(table)
|
|
1645
1687
|
};
|
|
1646
|
-
|
|
1688
|
+
const responseSchema = publicRead ? {
|
|
1689
|
+
type: "object",
|
|
1690
|
+
properties: {
|
|
1691
|
+
rows: {
|
|
1692
|
+
type: "array",
|
|
1693
|
+
items: { $ref: `#/components/schemas/${schemaName}` }
|
|
1694
|
+
},
|
|
1695
|
+
next_cursor: { type: ["string", "null"] },
|
|
1696
|
+
tip: {
|
|
1697
|
+
type: "object",
|
|
1698
|
+
properties: {
|
|
1699
|
+
block_height: { type: "integer" },
|
|
1700
|
+
subgraph_height: { type: "integer" },
|
|
1701
|
+
blocks_behind: { type: "integer" }
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
} : {
|
|
1706
|
+
type: "object",
|
|
1707
|
+
properties: {
|
|
1708
|
+
data: {
|
|
1709
|
+
type: "array",
|
|
1710
|
+
items: { $ref: `#/components/schemas/${schemaName}` }
|
|
1711
|
+
},
|
|
1712
|
+
meta: {
|
|
1713
|
+
type: "object",
|
|
1714
|
+
properties: {
|
|
1715
|
+
total: { type: "integer" },
|
|
1716
|
+
limit: { type: "integer" },
|
|
1717
|
+
offset: { type: "integer" }
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
paths[tablePath(detail.name, tableName, publicRead)] = {
|
|
1647
1723
|
get: {
|
|
1648
1724
|
summary: `Query ${detail.name}.${tableName}`,
|
|
1649
1725
|
operationId: `query_${detail.name.replace(/-/g, "_")}_${tableName}`,
|
|
1650
|
-
parameters: tableParameters(table),
|
|
1726
|
+
parameters: tableParameters(table, publicRead),
|
|
1651
1727
|
responses: {
|
|
1652
1728
|
"200": {
|
|
1653
1729
|
description: "Rows returned from the subgraph table.",
|
|
1654
1730
|
content: {
|
|
1655
1731
|
"application/json": {
|
|
1656
|
-
schema:
|
|
1657
|
-
type: "object",
|
|
1658
|
-
properties: {
|
|
1659
|
-
data: {
|
|
1660
|
-
type: "array",
|
|
1661
|
-
items: { $ref: `#/components/schemas/${schemaName}` }
|
|
1662
|
-
},
|
|
1663
|
-
meta: {
|
|
1664
|
-
type: "object",
|
|
1665
|
-
properties: {
|
|
1666
|
-
total: { type: "integer" },
|
|
1667
|
-
limit: { type: "integer" },
|
|
1668
|
-
offset: { type: "integer" }
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1732
|
+
schema: responseSchema
|
|
1673
1733
|
}
|
|
1674
1734
|
}
|
|
1675
1735
|
}
|
|
1676
1736
|
}
|
|
1677
1737
|
}
|
|
1678
1738
|
};
|
|
1679
|
-
paths[countPath(detail.name, tableName)] = {
|
|
1739
|
+
paths[countPath(detail.name, tableName, publicRead)] = {
|
|
1680
1740
|
get: {
|
|
1681
1741
|
summary: `Count ${detail.name}.${tableName}`,
|
|
1682
1742
|
operationId: `count_${detail.name.replace(/-/g, "_")}_${tableName}`,
|
|
1683
|
-
parameters: tableParameters(table),
|
|
1743
|
+
parameters: tableParameters(table, publicRead),
|
|
1684
1744
|
responses: {
|
|
1685
1745
|
"200": {
|
|
1686
1746
|
description: "Row count for the filtered table query.",
|
|
@@ -1719,17 +1779,19 @@ function generateSubgraphOpenApi(detail, options = {}) {
|
|
|
1719
1779
|
}
|
|
1720
1780
|
function generateSubgraphMarkdown(detail, options = {}) {
|
|
1721
1781
|
const agent = generateSubgraphAgentSchema(detail, options);
|
|
1782
|
+
const publicRead = isPublicRead(detail);
|
|
1722
1783
|
const lines = [
|
|
1723
1784
|
`# ${detail.name} Subgraph API`,
|
|
1724
1785
|
"",
|
|
1725
1786
|
`Version: ${detail.version}`,
|
|
1726
1787
|
detail.schemaHash ? `Schema hash: ${detail.schemaHash}` : undefined,
|
|
1727
1788
|
`Server: ${agent.serverUrl}`,
|
|
1789
|
+
publicRead ? "Visibility: public — anon reads, no API key. Responses use the `{ rows, next_cursor, tip }` envelope; paginate with `?cursor=<next_cursor>` and `_order=asc|desc` (`_offset`/`_sort` are rejected)." : undefined,
|
|
1728
1790
|
"",
|
|
1729
1791
|
detail.description
|
|
1730
1792
|
].filter((line) => line !== undefined && line !== "");
|
|
1731
1793
|
for (const [tableName, table] of Object.entries(agent.tables)) {
|
|
1732
|
-
lines.push("", `## ${tableName}`, "", `GET ${table.endpoint}`, `GET ${table.countEndpoint}`, "", `Rows: ${table.rowCount}`, "", "### Columns", "", "| Column | Type | Attributes |", "| --- | --- | --- |");
|
|
1794
|
+
lines.push("", `## ${tableName}`, "", `GET ${table.endpoint}`, `GET ${table.countEndpoint}`, ...table.aggregateEndpoint ? [`GET ${table.aggregateEndpoint}`] : [], ...table.streamEndpoint ? [`GET ${table.streamEndpoint} (SSE)`] : [], "", `Rows: ${table.rowCount}`, "", "### Columns", "", "| Column | Type | Attributes |", "| --- | --- | --- |");
|
|
1733
1795
|
for (const [columnName, col] of Object.entries(table.columns)) {
|
|
1734
1796
|
const attrs = [
|
|
1735
1797
|
SYSTEM_COLUMNS.includes(columnName) ? "system" : undefined,
|
|
@@ -2007,6 +2069,7 @@ export {
|
|
|
2007
2069
|
ReplaySubscriptionRequestSchema,
|
|
2008
2070
|
RateLimitError,
|
|
2009
2071
|
PrintEventFilterSchema,
|
|
2072
|
+
PaymentRequiredError,
|
|
2010
2073
|
NotFoundError,
|
|
2011
2074
|
NftTransferFilterSchema,
|
|
2012
2075
|
NftMintFilterSchema,
|
|
@@ -2034,5 +2097,5 @@ export {
|
|
|
2034
2097
|
AuthenticationError
|
|
2035
2098
|
};
|
|
2036
2099
|
|
|
2037
|
-
//# debugId=
|
|
2100
|
+
//# debugId=4E318E008C33ACC764756E2164756E21
|
|
2038
2101
|
//# sourceMappingURL=index.js.map
|