@secondlayer/sdk 6.19.0 → 6.20.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 +61 -4
- package/dist/index.d.ts +256 -14
- package/dist/index.js +245 -7
- package/dist/index.js.map +9 -8
- package/dist/streams/index.d.ts +46 -1
- package/dist/streams/index.js +48 -1
- package/dist/streams/index.js.map +5 -5
- package/dist/subgraphs/index.d.ts +109 -13
- package/dist/subgraphs/index.js +67 -7
- package/dist/subgraphs/index.js.map +6 -6
- package/dist/x402.d.ts +149 -0
- package/dist/x402.js +184 -0
- package/dist/x402.js.map +10 -0
- package/package.json +7 -3
|
@@ -52,6 +52,16 @@ interface SubgraphOperationStatus {
|
|
|
52
52
|
createdAt: string;
|
|
53
53
|
updatedAt: string;
|
|
54
54
|
}
|
|
55
|
+
/** /v1 cursor envelope for subgraph table reads. */
|
|
56
|
+
interface SubgraphRowsEnvelope<T = unknown> {
|
|
57
|
+
rows: T[];
|
|
58
|
+
next_cursor: string | null;
|
|
59
|
+
tip: {
|
|
60
|
+
block_height: number
|
|
61
|
+
subgraph_height: number
|
|
62
|
+
blocks_behind: number
|
|
63
|
+
};
|
|
64
|
+
}
|
|
55
65
|
interface BundleSubgraphResponse {
|
|
56
66
|
ok: true;
|
|
57
67
|
name: string;
|
|
@@ -94,6 +104,29 @@ declare class Subgraphs extends BaseClient {
|
|
|
94
104
|
}): Promise<{
|
|
95
105
|
message: string
|
|
96
106
|
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Publish: claim the name in the global public namespace and open anon
|
|
109
|
+
* reads on /v1/subgraphs/:name. 409 PUBLIC_NAME_TAKEN if another account
|
|
110
|
+
* holds the public name.
|
|
111
|
+
*/
|
|
112
|
+
publish(name: string): Promise<{
|
|
113
|
+
name: string
|
|
114
|
+
visibility: "public"
|
|
115
|
+
url: string
|
|
116
|
+
}>;
|
|
117
|
+
/** Make reads private again (owning account's bearer key required). */
|
|
118
|
+
unpublish(name: string): Promise<{
|
|
119
|
+
name: string
|
|
120
|
+
visibility: "private"
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Open /v1 read: cursor-paginated rows. Anon works for public subgraphs;
|
|
124
|
+
* pass an apiKey on the client for private ones. Resume with the returned
|
|
125
|
+
* `next_cursor`.
|
|
126
|
+
*/
|
|
127
|
+
rows<T = unknown>(name: string, table: string, params?: Omit<SubgraphQueryParams, "offset" | "sort"> & {
|
|
128
|
+
cursor?: string
|
|
129
|
+
}): Promise<SubgraphRowsEnvelope<T>>;
|
|
97
130
|
/** Recent reindex/backfill operations for a subgraph, newest first. */
|
|
98
131
|
operations(name: string): Promise<{
|
|
99
132
|
operations: SubgraphOperationStatus[]
|
|
@@ -920,6 +953,30 @@ type MempoolWalkParams = Omit<MempoolListParams, "limit"> & {
|
|
|
920
953
|
batchSize?: number
|
|
921
954
|
signal?: AbortSignal
|
|
922
955
|
};
|
|
956
|
+
/**
|
|
957
|
+
* `index.ftTransfers` — callable shorthand for `.list()`, with `.list`/`.walk`
|
|
958
|
+
* still available: `await sl.index.ftTransfers({ contractId })`.
|
|
959
|
+
*
|
|
960
|
+
* The API accepts `contract_id`/`sender`/`recipient` equality filters only —
|
|
961
|
+
* no amount filtering and no asset-slug resolution on /v1/index/ft-transfers.
|
|
962
|
+
*/
|
|
963
|
+
interface FtTransfersResource {
|
|
964
|
+
(params?: FtTransfersListParams): Promise<FtTransfersEnvelope>;
|
|
965
|
+
list(params?: FtTransfersListParams): Promise<FtTransfersEnvelope>;
|
|
966
|
+
walk(params?: FtTransfersWalkParams): AsyncIterable<FtTransfer>;
|
|
967
|
+
}
|
|
968
|
+
/** `index.nftTransfers` — callable shorthand for `.list()` (see {@link FtTransfersResource}). */
|
|
969
|
+
interface NftTransfersResource {
|
|
970
|
+
(params?: NftTransfersListParams): Promise<NftTransfersEnvelope>;
|
|
971
|
+
list(params?: NftTransfersListParams): Promise<NftTransfersEnvelope>;
|
|
972
|
+
walk(params?: NftTransfersWalkParams): AsyncIterable<NftTransfer>;
|
|
973
|
+
}
|
|
974
|
+
/** `index.events` — callable shorthand for `.list()`; `eventType` is required. */
|
|
975
|
+
interface IndexEventsResource {
|
|
976
|
+
(params: EventsListParams): Promise<EventsEnvelope>;
|
|
977
|
+
list(params: EventsListParams): Promise<EventsEnvelope>;
|
|
978
|
+
walk(params: EventsWalkParams): AsyncIterable<IndexEvent>;
|
|
979
|
+
}
|
|
923
980
|
/** Per-event-type filter vocabulary in the {@link IndexDiscovery} doc. */
|
|
924
981
|
type IndexEventTypeFilters = {
|
|
925
982
|
columns?: string[]
|
|
@@ -944,19 +1001,13 @@ declare class Index extends BaseClient {
|
|
|
944
1001
|
* learn what's queryable (and which types accept `trait`) instead of hardcoding.
|
|
945
1002
|
*/
|
|
946
1003
|
discover(): Promise<IndexDiscovery>;
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
};
|
|
955
|
-
/** Generic decoded events by `event_type` (the full /v1/index/events surface). */
|
|
956
|
-
readonly events: {
|
|
957
|
-
list: (params: EventsListParams) => Promise<EventsEnvelope>
|
|
958
|
-
walk: (params: EventsWalkParams) => AsyncIterable<IndexEvent>
|
|
959
|
-
};
|
|
1004
|
+
/** Callable: `index.ftTransfers(params)` ≡ `index.ftTransfers.list(params)`. */
|
|
1005
|
+
readonly ftTransfers: FtTransfersResource;
|
|
1006
|
+
/** Callable: `index.nftTransfers(params)` ≡ `index.nftTransfers.list(params)`. */
|
|
1007
|
+
readonly nftTransfers: NftTransfersResource;
|
|
1008
|
+
/** Generic decoded events by `event_type` (the full /v1/index/events surface).
|
|
1009
|
+
* Callable: `index.events(params)` ≡ `index.events.list(params)`. */
|
|
1010
|
+
readonly events: IndexEventsResource;
|
|
960
1011
|
readonly contractCalls: {
|
|
961
1012
|
list: (params?: ContractCallsListParams) => Promise<ContractCallsEnvelope>
|
|
962
1013
|
walk: (params?: ContractCallsWalkParams) => AsyncIterable<IndexContractCall>
|
|
@@ -1338,6 +1389,36 @@ type StreamsEventsConsumeParams = {
|
|
|
1338
1389
|
maxEmptyPolls?: number
|
|
1339
1390
|
signal?: AbortSignal
|
|
1340
1391
|
};
|
|
1392
|
+
/**
|
|
1393
|
+
* One yielded page from {@link StreamsClient.consume} — the
|
|
1394
|
+
* `GET /v1/streams/events` envelope verbatim, with `next_cursor` renamed to
|
|
1395
|
+
* `cursor` (the checkpoint to persist and resume from).
|
|
1396
|
+
*/
|
|
1397
|
+
type StreamsBatch = {
|
|
1398
|
+
/** Canonical events of this page, in cursor order. */
|
|
1399
|
+
events: StreamsEvent[]
|
|
1400
|
+
/** Checkpoint after this page — pass back as `consume({ cursor })` to resume. */
|
|
1401
|
+
cursor: string | null
|
|
1402
|
+
tip: StreamsTip
|
|
1403
|
+
/** Chain reorgs reported alongside this page; empty when none. */
|
|
1404
|
+
reorgs: StreamsReorg[]
|
|
1405
|
+
};
|
|
1406
|
+
type StreamsConsumeParams = {
|
|
1407
|
+
/** Resume strictly after this cursor; omit to start from the oldest seekable page. */
|
|
1408
|
+
cursor?: string | null
|
|
1409
|
+
types?: readonly StreamsEventType[]
|
|
1410
|
+
notTypes?: readonly StreamsEventType[]
|
|
1411
|
+
contractId?: StreamsFilterValue
|
|
1412
|
+
sender?: StreamsFilterValue
|
|
1413
|
+
recipient?: StreamsFilterValue
|
|
1414
|
+
assetIdentifier?: string
|
|
1415
|
+
/** Events per page (the `limit` query param). Default 100. */
|
|
1416
|
+
batchSize?: number
|
|
1417
|
+
/** Poll interval while caught up at the tip, in ms. Default 2000. */
|
|
1418
|
+
intervalMs?: number
|
|
1419
|
+
/** Abort to end the iteration. */
|
|
1420
|
+
signal?: AbortSignal
|
|
1421
|
+
};
|
|
1341
1422
|
type StreamsEventsConsumeResult = {
|
|
1342
1423
|
cursor: string | null
|
|
1343
1424
|
pages: number
|
|
@@ -1405,6 +1486,21 @@ type StreamsDumps = {
|
|
|
1405
1486
|
download(file: StreamsDumpFile): Promise<Uint8Array>
|
|
1406
1487
|
};
|
|
1407
1488
|
type StreamsClient = {
|
|
1489
|
+
/**
|
|
1490
|
+
* Follow Streams as an async iterator of page batches.
|
|
1491
|
+
*
|
|
1492
|
+
* Yields one {@link StreamsBatch} per `GET /v1/streams/events` page — the
|
|
1493
|
+
* existing envelope (`events`, `next_cursor` → `cursor`, `tip`, `reorgs`)
|
|
1494
|
+
* with zero extra API calls. Batches are chosen over per-block groupings
|
|
1495
|
+
* because the envelope is page-keyed, so every yield is exactly one fetch.
|
|
1496
|
+
* Empty pages are skipped; at the tip the iterator re-polls every
|
|
1497
|
+
* `intervalMs` (default 2000) until aborted via `signal`.
|
|
1498
|
+
*
|
|
1499
|
+
* Reorgs are surfaced on the batch (`batch.reorgs`) but the cursor is not
|
|
1500
|
+
* rewound automatically — use `events.consume` with `onReorg` for managed
|
|
1501
|
+
* rollback semantics.
|
|
1502
|
+
*/
|
|
1503
|
+
consume(params?: StreamsConsumeParams): AsyncIterableIterator<StreamsBatch>
|
|
1408
1504
|
events: {
|
|
1409
1505
|
list(params?: StreamsEventsListParams): Promise<StreamsEventsEnvelope>
|
|
1410
1506
|
byTxId(txId: string): Promise<StreamsEventsListEnvelope>
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -281,6 +281,19 @@ class Subgraphs extends BaseClient {
|
|
|
281
281
|
const qs = options?.force ? "?force=true" : "";
|
|
282
282
|
return this.request("DELETE", `/api/subgraphs/${name}${qs}`);
|
|
283
283
|
}
|
|
284
|
+
async publish(name) {
|
|
285
|
+
return this.request("POST", `/api/subgraphs/${name}/publish`);
|
|
286
|
+
}
|
|
287
|
+
async unpublish(name) {
|
|
288
|
+
return this.request("POST", `/api/subgraphs/${name}/unpublish`);
|
|
289
|
+
}
|
|
290
|
+
async rows(name, table, params = {}) {
|
|
291
|
+
const { cursor, ...rest } = params;
|
|
292
|
+
const qs = buildSubgraphQueryString(rest);
|
|
293
|
+
const sep = qs ? "&" : "?";
|
|
294
|
+
const cursorQs = cursor ? `${sep}cursor=${encodeURIComponent(cursor)}` : "";
|
|
295
|
+
return this.request("GET", `/v1/subgraphs/${name}/${table}${qs}${cursorQs}`);
|
|
296
|
+
}
|
|
284
297
|
async operations(name) {
|
|
285
298
|
return this.request("GET", `/api/subgraphs/${name}/operations`);
|
|
286
299
|
}
|
|
@@ -606,18 +619,18 @@ class Index extends BaseClient {
|
|
|
606
619
|
discover() {
|
|
607
620
|
return this.request("GET", "/v1/index");
|
|
608
621
|
}
|
|
609
|
-
ftTransfers = {
|
|
622
|
+
ftTransfers = Object.assign((params = {}) => this.listFtTransfers(params), {
|
|
610
623
|
list: (params = {}) => this.listFtTransfers(params),
|
|
611
624
|
walk: (params = {}) => this.walkFtTransfers(params)
|
|
612
|
-
};
|
|
613
|
-
nftTransfers = {
|
|
625
|
+
});
|
|
626
|
+
nftTransfers = Object.assign((params = {}) => this.listNftTransfers(params), {
|
|
614
627
|
list: (params = {}) => this.listNftTransfers(params),
|
|
615
628
|
walk: (params = {}) => this.walkNftTransfers(params)
|
|
616
|
-
};
|
|
617
|
-
events = {
|
|
629
|
+
});
|
|
630
|
+
events = Object.assign((params) => this.listEvents(params), {
|
|
618
631
|
list: (params) => this.listEvents(params),
|
|
619
632
|
walk: (params) => this.walkEvents(params)
|
|
620
|
-
};
|
|
633
|
+
});
|
|
621
634
|
contractCalls = {
|
|
622
635
|
list: (params = {}) => this.listContractCalls(params),
|
|
623
636
|
walk: (params = {}) => this.walkContractCalls(params)
|
|
@@ -1182,6 +1195,38 @@ async function consumeStreamsEvents(opts) {
|
|
|
1182
1195
|
}
|
|
1183
1196
|
return { cursor, pages, emptyPolls };
|
|
1184
1197
|
}
|
|
1198
|
+
async function* iterateStreamsBatches(opts) {
|
|
1199
|
+
const sleep = opts.sleep ?? defaultSleep;
|
|
1200
|
+
let cursor = opts.fromCursor ?? null;
|
|
1201
|
+
while (!opts.signal?.aborted) {
|
|
1202
|
+
const envelope = await opts.fetchEvents({
|
|
1203
|
+
cursor,
|
|
1204
|
+
limit: opts.batchSize,
|
|
1205
|
+
types: opts.types,
|
|
1206
|
+
notTypes: opts.notTypes,
|
|
1207
|
+
contractId: opts.contractId,
|
|
1208
|
+
sender: opts.sender,
|
|
1209
|
+
recipient: opts.recipient,
|
|
1210
|
+
assetIdentifier: opts.assetIdentifier
|
|
1211
|
+
});
|
|
1212
|
+
const checkpoint = envelope.next_cursor ?? cursor;
|
|
1213
|
+
if (envelope.events.length > 0 || envelope.reorgs.length > 0) {
|
|
1214
|
+
yield {
|
|
1215
|
+
events: envelope.events,
|
|
1216
|
+
cursor: checkpoint,
|
|
1217
|
+
tip: envelope.tip,
|
|
1218
|
+
reorgs: envelope.reorgs
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
const advanced = checkpoint !== null && checkpoint !== cursor;
|
|
1222
|
+
cursor = checkpoint;
|
|
1223
|
+
if (!advanced && envelope.events.length === 0) {
|
|
1224
|
+
if (opts.signal?.aborted)
|
|
1225
|
+
return;
|
|
1226
|
+
await sleep(opts.intervalMs, opts.signal);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1185
1230
|
async function* streamStreamsEvents(opts) {
|
|
1186
1231
|
const sleep = opts.sleep ?? defaultSleep;
|
|
1187
1232
|
const emptyBackoffMs = opts.emptyBackoffMs ?? 500;
|
|
@@ -1559,6 +1604,21 @@ function createStreamsClient(options) {
|
|
|
1559
1604
|
})}`);
|
|
1560
1605
|
}
|
|
1561
1606
|
return {
|
|
1607
|
+
consume(params = {}) {
|
|
1608
|
+
return iterateStreamsBatches({
|
|
1609
|
+
fromCursor: params.cursor,
|
|
1610
|
+
batchSize: params.batchSize ?? 100,
|
|
1611
|
+
intervalMs: params.intervalMs ?? 2000,
|
|
1612
|
+
types: params.types,
|
|
1613
|
+
notTypes: params.notTypes,
|
|
1614
|
+
contractId: params.contractId,
|
|
1615
|
+
sender: params.sender,
|
|
1616
|
+
recipient: params.recipient,
|
|
1617
|
+
assetIdentifier: params.assetIdentifier,
|
|
1618
|
+
signal: params.signal,
|
|
1619
|
+
fetchEvents
|
|
1620
|
+
});
|
|
1621
|
+
},
|
|
1562
1622
|
events: {
|
|
1563
1623
|
list: listEvents,
|
|
1564
1624
|
byTxId(txId) {
|
|
@@ -1815,5 +1875,5 @@ export {
|
|
|
1815
1875
|
Subgraphs
|
|
1816
1876
|
};
|
|
1817
1877
|
|
|
1818
|
-
//# debugId=
|
|
1878
|
+
//# debugId=DD9EE9C3CECE53B564756E2164756E21
|
|
1819
1879
|
//# sourceMappingURL=index.js.map
|