@secondlayer/sdk 5.4.0 → 5.6.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 CHANGED
@@ -14,11 +14,15 @@ bun add @secondlayer/sdk
14
14
  import { SecondLayer } from "@secondlayer/sdk";
15
15
 
16
16
  const sl = new SecondLayer({
17
- apiKey: "sk-sl_...", // or session token
17
+ apiKey: "sk-sl_...", // or `sl login` session token
18
18
  baseUrl: "https://api.secondlayer.tools", // default
19
19
  });
20
20
  ```
21
21
 
22
+ Reads are public during open beta — no key needed. Writes require an `sk-sl_`
23
+ API key, created in the platform console at
24
+ https://secondlayer.tools/platform/api-keys.
25
+
22
26
  ## Mental model
23
27
 
24
28
  - `sl.streams` reads raw ordered L1 events from Stacks Streams.
@@ -27,10 +31,7 @@ const sl = new SecondLayer({
27
31
 
28
32
  ## Stacks Streams
29
33
 
30
- Typed L1 HTTP client.
31
-
32
- `sk-sl_streams_status_public` is a public, non-secret Free-tier key used by the
33
- Second Layer status page. Production apps should use their own Streams API key.
34
+ Typed L1 HTTP client. Reads are public — no key needed.
34
35
 
35
36
  ```typescript
36
37
  const tip = await sl.streams.tip();
@@ -49,7 +50,7 @@ console.log({ tip, firstCursor: page.events[0]?.cursor });
49
50
  import { createStreamsClient } from "@secondlayer/sdk";
50
51
 
51
52
  const streams = createStreamsClient({
52
- apiKey: process.env.SECONDLAYER_API_KEY!,
53
+ apiKey: process.env.SL_SERVICE_KEY!, // sk-sl_...
53
54
  });
54
55
  ```
55
56
 
@@ -70,13 +71,7 @@ inside `onBatch`, then return the cursor you committed. It exits when
70
71
  `maxPages`, `maxEmptyPolls`, or `signal` stops it.
71
72
 
72
73
  ```typescript
73
- import { createStreamsClient } from "@secondlayer/sdk";
74
-
75
- const client = createStreamsClient({
76
- apiKey: process.env.SECONDLAYER_API_KEY!,
77
- });
78
-
79
- await client.events.consume({
74
+ await streams.events.consume({
80
75
  types: ["ft_transfer"],
81
76
  batchSize: 100,
82
77
  maxPages: 1,
@@ -95,16 +90,10 @@ Use `client.events.stream` for live processors and watch-style apps. It follows
95
90
  the tip indefinitely. Stop it with an `AbortSignal`.
96
91
 
97
92
  ```typescript
98
- import { createStreamsClient } from "@secondlayer/sdk";
99
-
100
- const client = createStreamsClient({
101
- apiKey: process.env.SECONDLAYER_API_KEY!,
102
- });
103
-
104
93
  const abort = new AbortController();
105
94
  process.once("SIGINT", () => abort.abort());
106
95
 
107
- for await (const event of client.events.stream({
96
+ for await (const event of streams.events.stream({
108
97
  types: ["ft_transfer"],
109
98
  batchSize: 100,
110
99
  signal: abort.signal,
@@ -116,17 +105,9 @@ for await (const event of client.events.stream({
116
105
  Decoder helper.
117
106
 
118
107
  ```typescript
119
- import {
120
- createStreamsClient,
121
- decodeFtTransfer,
122
- isFtTransfer,
123
- } from "@secondlayer/sdk";
124
-
125
- const client = createStreamsClient({
126
- apiKey: process.env.SECONDLAYER_API_KEY!,
127
- });
108
+ import { decodeFtTransfer, isFtTransfer } from "@secondlayer/sdk";
128
109
 
129
- for await (const event of client.events.stream({ types: ["ft_transfer"] })) {
110
+ for await (const event of streams.events.stream({ types: ["ft_transfer"] })) {
130
111
  if (!isFtTransfer(event)) continue;
131
112
  const transfer = decodeFtTransfer(event);
132
113
  console.log(transfer.decoded_payload);
@@ -172,7 +153,7 @@ for await (const transfer of sl.index.ftTransfers.walk({
172
153
 
173
154
  Deploy and query app-specific L3 tables.
174
155
 
175
- Subgraphs and subscriptions live on the platform API alongside Streams and Index. Authenticate with your `sk-sl_*` key — no extra setup, no tenant URL.
156
+ Subgraphs and subscriptions live on the platform API alongside Streams and Index. Deploying and managing them needs your `sk-sl_` key — no extra setup, no tenant URL.
176
157
 
177
158
  ```typescript
178
159
  // List
package/dist/index.d.ts CHANGED
@@ -216,6 +216,14 @@ type IndexStxBurn = IndexEventBase & {
216
216
  sender: string
217
217
  amount: string
218
218
  };
219
+ type IndexStxLock = IndexEventBase & {
220
+ event_type: "stx_lock"
221
+ sender: string
222
+ amount: string
223
+ payload: {
224
+ unlock_height: string | null
225
+ }
226
+ };
219
227
  type IndexFtMint = IndexEventBase & {
220
228
  event_type: "ft_mint"
221
229
  asset_identifier: string
@@ -249,7 +257,7 @@ type IndexPrint = IndexEventBase & {
249
257
  }
250
258
  };
251
259
  /** Decoded chain event, discriminated by `event_type`. */
252
- type IndexEvent = IndexFtTransfer | IndexNftTransfer | IndexStxTransfer | IndexStxMint | IndexStxBurn | IndexFtMint | IndexFtBurn | IndexNftMint | IndexNftBurn | IndexPrint;
260
+ type IndexEvent = IndexFtTransfer | IndexNftTransfer | IndexStxTransfer | IndexStxMint | IndexStxBurn | IndexStxLock | IndexFtMint | IndexFtBurn | IndexNftMint | IndexNftBurn | IndexPrint;
253
261
  type IndexEventType = IndexEvent["event_type"];
254
262
  type EventsEnvelope = {
255
263
  events: IndexEvent[]
@@ -654,6 +662,27 @@ declare function isStxBurn(event: StreamsEvent): event is StreamsEvent & {
654
662
  event_type: "stx_burn"
655
663
  };
656
664
  declare function decodeStxBurn(event: StreamsEvent): DecodedStxBurn;
665
+ type DecodedStxLockPayload = {
666
+ sender: string
667
+ amount: string
668
+ payload: {
669
+ unlock_height: string | null
670
+ }
671
+ };
672
+ type DecodedStxLock = {
673
+ cursor: string
674
+ block_height: number
675
+ tx_id: string
676
+ tx_index: number
677
+ event_index: number
678
+ event_type: "stx_lock"
679
+ decoded_payload: DecodedStxLockPayload
680
+ source_cursor: string
681
+ };
682
+ declare function isStxLock(event: StreamsEvent): event is StreamsEvent & {
683
+ event_type: "stx_lock"
684
+ };
685
+ declare function decodeStxLock(event: StreamsEvent): DecodedStxLock;
657
686
  type DecodedFtMintPayload = {
658
687
  asset_identifier: string
659
688
  contract_id: string
@@ -780,7 +809,89 @@ type DecodedEventColumns = {
780
809
  /** JSONB overflow for non-flat types (e.g. print's decoded value). */
781
810
  payload?: unknown
782
811
  };
783
- type DecodedEventRow = DecodedFtTransfer | DecodedNftTransfer | DecodedStxTransfer | DecodedStxMint | DecodedStxBurn | DecodedFtMint | DecodedFtBurn | DecodedNftMint | DecodedNftBurn | DecodedPrint;
812
+ type DecodedEventRow = DecodedFtTransfer | DecodedNftTransfer | DecodedStxTransfer | DecodedStxMint | DecodedStxBurn | DecodedStxLock | DecodedFtMint | DecodedFtBurn | DecodedNftMint | DecodedNftBurn | DecodedPrint;
813
+ /**
814
+ * Typed client for the Foundation Datasets REST API (`/v1/datasets/*`).
815
+ *
816
+ * Most datasets are cursor-paginated event lists with a uniform `list`/`walk`
817
+ * surface; a few (bns names/namespaces/resolve, network-health) are
818
+ * offset/single-object/summary and get bespoke methods. Query params are typed
819
+ * per dataset; rows are `DatasetRow` (JSON) in v1 — per-dataset row interfaces
820
+ * are a fast-follow.
821
+ */
822
+ /** A dataset row — flat JSON object. Per-dataset interfaces are a follow-up. */
823
+ type DatasetRow = Record<string, unknown>;
824
+ /** Filters shared by every cursor-paginated dataset. */
825
+ interface CursorListParams {
826
+ cursor?: string;
827
+ limit?: number;
828
+ fromBlock?: number;
829
+ toBlock?: number;
830
+ }
831
+ interface CursorEnvelope {
832
+ rows: DatasetRow[];
833
+ next_cursor: string | null;
834
+ tip?: {
835
+ block_height: number
836
+ };
837
+ }
838
+ type RangeFilters = CursorListParams;
839
+ type Pox4CallsParams = RangeFilters & {
840
+ functionName?: string
841
+ stacker?: string
842
+ delegateTo?: string
843
+ signerKey?: string
844
+ rewardCycle?: number
845
+ /** Any-role: matches caller OR stacker OR delegate_to. */
846
+ address?: string
847
+ };
848
+ /** Cursor-paginated dataset slugs → REST path + envelope row key. */
849
+ declare const CURSOR_SLUGS: Record<string, {
850
+ path: string
851
+ rowKey: string
852
+ }>;
853
+ declare class Datasets extends BaseClient {
854
+ constructor(options?: Partial<SecondLayerOptions>);
855
+ /** Dataset catalog + freshness (the discovery endpoint). */
856
+ listDatasets(): Promise<unknown>;
857
+ /**
858
+ * Generic cursor query by slug — used by the CLI. Params are passed through as
859
+ * REST query keys (snake_case), so callers can use the documented filter names
860
+ * directly. Throws for non-cursor (bespoke) datasets.
861
+ */
862
+ query(slug: string, params?: Record<string, unknown>): Promise<CursorEnvelope>;
863
+ readonly stxTransfers;
864
+ readonly sbtcEvents;
865
+ readonly sbtcTokenEvents;
866
+ readonly pox4Calls;
867
+ readonly bnsEvents;
868
+ readonly bnsNamespaceEvents;
869
+ readonly bnsMarketplaceEvents;
870
+ /** BNS names — offset-paginated. */
871
+ bnsNames(params?: {
872
+ namespace?: string
873
+ owner?: string
874
+ limit?: number
875
+ offset?: number
876
+ }): Promise<{
877
+ names: DatasetRow[]
878
+ }>;
879
+ /** All BNS namespaces (no pagination). */
880
+ bnsNamespaces(): Promise<{
881
+ namespaces: DatasetRow[]
882
+ }>;
883
+ /** Resolve a fully-qualified BNS name → single record. */
884
+ bnsResolve(fqn: string): Promise<{
885
+ name: DatasetRow | null
886
+ }>;
887
+ /** Network health summary. */
888
+ networkHealth(): Promise<{
889
+ summary: DatasetRow
890
+ }>;
891
+ private get;
892
+ private buildParams;
893
+ private cursorDataset;
894
+ }
784
895
  import { SubgraphAgentSchema as SubgraphAgentSchema3, SubgraphSpecFormat as SubgraphSpecFormat2, SubgraphSpecOptions as SubgraphSpecOptions3 } from "@secondlayer/shared/subgraphs/spec";
785
896
  /**
786
897
  * Error thrown by {@link SecondLayer} when an API request fails.
@@ -899,4 +1010,4 @@ declare function toJsonSafe(value: unknown): unknown;
899
1010
  /** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
900
1011
  * buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
901
1012
  declare function decodeClarityValue(hex: string): unknown;
902
- export { verifyWebhookSignature, toJsonSafe, isStxTransfer, isStxMint, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, decodeStxTransfer, decodeStxMint, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsClient, StreamsCanonicalBlock, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, IndexTip, IndexEventType, IndexEvent, IndexContractCall, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, AuthError, ApiError };
1013
+ export { verifyWebhookSignature, toJsonSafe, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsClient, StreamsCanonicalBlock, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, IndexTip, IndexEventType, IndexEvent, IndexContractCall, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, Datasets, DatasetRow, CursorListParams, CursorEnvelope, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, CURSOR_SLUGS, AuthError, ApiError };
package/dist/index.js CHANGED
@@ -143,7 +143,10 @@ function serializeWhere(where) {
143
143
  continue;
144
144
  if (op === "eq") {
145
145
  filters[col] = String(opValue);
146
- } else if (["neq", "gt", "gte", "lt", "lte"].includes(op)) {
146
+ } else if (op === "in" || op === "notIn") {
147
+ const arr = Array.isArray(opValue) ? opValue : [opValue];
148
+ filters[`${col}.${op}`] = arr.map((v) => String(v)).join(",");
149
+ } else if (["neq", "gt", "gte", "lt", "lte", "like"].includes(op)) {
147
150
  filters[`${col}.${op}`] = String(opValue);
148
151
  }
149
152
  }
@@ -257,18 +260,10 @@ class Subgraphs extends BaseClient {
257
260
  let sort;
258
261
  let order;
259
262
  if (options.orderBy) {
260
- const entries = Object.entries(options.orderBy);
263
+ const entries = Array.isArray(options.orderBy) ? options.orderBy : Object.entries(options.orderBy);
261
264
  if (entries.length > 0) {
262
- if (entries.length > 1) {
263
- const extra = entries.slice(1).map(([col]) => col).join(", ");
264
- throw new Error(`orderBy supports only one column; remove extra keys: ${extra}`);
265
- }
266
- const first = entries[0];
267
- if (first) {
268
- const [col, dir] = first;
269
- sort = resolveOrderByColumn(col);
270
- order = dir ?? "asc";
271
- }
265
+ sort = entries.map(([col]) => resolveOrderByColumn(col)).join(",");
266
+ order = entries.map(([, dir]) => dir ?? "asc").join(",");
272
267
  }
273
268
  }
274
269
  const params = {
@@ -944,13 +939,16 @@ function requireString3(payload, field, eventType) {
944
939
  function optionalString(value) {
945
940
  return typeof value === "string" && value.length > 0 ? value : null;
946
941
  }
947
- function requireAmount(payload, eventType) {
948
- const amount = requireString3(payload, "amount", eventType);
942
+ function requireAmountField(payload, field, eventType) {
943
+ const amount = requireString3(payload, field, eventType);
949
944
  if (!/^(0|[1-9]\d*)$/.test(amount)) {
950
- throw new Error(`${eventType} payload has malformed amount`);
945
+ throw new Error(`${eventType} payload has malformed ${field}`);
951
946
  }
952
947
  return amount;
953
948
  }
949
+ function requireAmount(payload, eventType) {
950
+ return requireAmountField(payload, "amount", eventType);
951
+ }
954
952
  function parseAssetIdentifier3(assetIdentifier, eventType) {
955
953
  const [contractId, tokenName] = assetIdentifier.split("::");
956
954
  if (!contractId) {
@@ -1034,6 +1032,20 @@ function decodeStxBurn(event) {
1034
1032
  amount: requireAmount(payload, "stx_burn")
1035
1033
  });
1036
1034
  }
1035
+ function isStxLock(event) {
1036
+ return event.event_type === "stx_lock";
1037
+ }
1038
+ function decodeStxLock(event) {
1039
+ if (!isStxLock(event)) {
1040
+ throw new Error(`Expected stx_lock event, got ${event.event_type}`);
1041
+ }
1042
+ const payload = event.payload;
1043
+ return decodedRow(event, "stx_lock", {
1044
+ sender: requireString3(payload, "locked_address", "stx_lock"),
1045
+ amount: requireAmountField(payload, "locked_amount", "stx_lock"),
1046
+ payload: { unlock_height: optionalString(payload.unlock_height) }
1047
+ });
1048
+ }
1037
1049
  // src/streams/token-mint-burn.ts
1038
1050
  function assetFields(event, eventType) {
1039
1051
  const assetIdentifier = requireString3(event.payload, "asset_identifier", eventType);
@@ -1163,6 +1175,126 @@ var STREAMS_EVENT_TYPES = [
1163
1175
  "nft_burn",
1164
1176
  "print"
1165
1177
  ];
1178
+ // src/datasets/client.ts
1179
+ function appendParam(params, name, value) {
1180
+ if (value === undefined || value === null)
1181
+ return;
1182
+ params.set(name, String(value));
1183
+ }
1184
+ var PARAM_KEYS = {
1185
+ fromBlock: "from_block",
1186
+ toBlock: "to_block",
1187
+ functionName: "function_name",
1188
+ delegateTo: "delegate_to",
1189
+ signerKey: "signer_key",
1190
+ rewardCycle: "reward_cycle",
1191
+ eventType: "event_type",
1192
+ bnsId: "bns_id"
1193
+ };
1194
+ var CURSOR_SLUGS = {
1195
+ "stx-transfers": { path: "stx-transfers", rowKey: "events" },
1196
+ "sbtc-events": { path: "sbtc/events", rowKey: "events" },
1197
+ "sbtc-token-events": { path: "sbtc/token-events", rowKey: "events" },
1198
+ "pox-4-calls": { path: "pox-4/calls", rowKey: "calls" },
1199
+ "bns-events": { path: "bns/events", rowKey: "events" },
1200
+ "bns-namespace-events": { path: "bns/namespace-events", rowKey: "events" },
1201
+ "bns-marketplace-events": {
1202
+ path: "bns/marketplace-events",
1203
+ rowKey: "events"
1204
+ }
1205
+ };
1206
+
1207
+ class Datasets extends BaseClient {
1208
+ constructor(options = {}) {
1209
+ super(options);
1210
+ }
1211
+ listDatasets() {
1212
+ return this.request("GET", "/v1/datasets");
1213
+ }
1214
+ async query(slug, params = {}) {
1215
+ const d = CURSOR_SLUGS[slug];
1216
+ if (!d) {
1217
+ throw new Error(`unknown cursor dataset "${slug}" (use one of: ${Object.keys(CURSOR_SLUGS).join(", ")})`);
1218
+ }
1219
+ const env = await this.get(d.path, this.buildParams(params));
1220
+ return {
1221
+ rows: env[d.rowKey] ?? [],
1222
+ next_cursor: env.next_cursor ?? null,
1223
+ tip: env.tip
1224
+ };
1225
+ }
1226
+ stxTransfers = this.cursorDataset("stx-transfers", "events");
1227
+ sbtcEvents = this.cursorDataset("sbtc/events", "events");
1228
+ sbtcTokenEvents = this.cursorDataset("sbtc/token-events", "events");
1229
+ pox4Calls = this.cursorDataset("pox-4/calls", "calls");
1230
+ bnsEvents = this.cursorDataset("bns/events", "events");
1231
+ bnsNamespaceEvents = this.cursorDataset("bns/namespace-events", "events");
1232
+ bnsMarketplaceEvents = this.cursorDataset("bns/marketplace-events", "events");
1233
+ bnsNames(params = {}) {
1234
+ const sp = new URLSearchParams;
1235
+ appendParam(sp, "namespace", params.namespace);
1236
+ appendParam(sp, "owner", params.owner);
1237
+ appendParam(sp, "limit", params.limit);
1238
+ appendParam(sp, "offset", params.offset);
1239
+ return this.get("bns/names", sp);
1240
+ }
1241
+ bnsNamespaces() {
1242
+ return this.get("bns/namespaces", new URLSearchParams);
1243
+ }
1244
+ bnsResolve(fqn) {
1245
+ const sp = new URLSearchParams;
1246
+ sp.set("fqn", fqn);
1247
+ return this.get("bns/resolve", sp);
1248
+ }
1249
+ networkHealth() {
1250
+ return this.get("network-health/summary", new URLSearchParams);
1251
+ }
1252
+ get(path, sp) {
1253
+ const qs = sp.toString();
1254
+ return this.request("GET", `/v1/datasets/${path}${qs ? `?${qs}` : ""}`);
1255
+ }
1256
+ buildParams(params) {
1257
+ const sp = new URLSearchParams;
1258
+ for (const [k, v] of Object.entries(params)) {
1259
+ if (v === undefined || v === null || k === "batchSize" || k === "signal")
1260
+ continue;
1261
+ appendParam(sp, PARAM_KEYS[k] ?? k, v);
1262
+ }
1263
+ return sp;
1264
+ }
1265
+ cursorDataset(path, rowKey) {
1266
+ const list = async (params = {}) => {
1267
+ const envelope = await this.get(path, this.buildParams(params));
1268
+ return {
1269
+ rows: envelope[rowKey] ?? [],
1270
+ next_cursor: envelope.next_cursor ?? null,
1271
+ tip: envelope.tip
1272
+ };
1273
+ };
1274
+ const walk = async function* (params = {}) {
1275
+ const batchSize = params.batchSize ?? 200;
1276
+ let cursor = params.cursor ?? null;
1277
+ let first = true;
1278
+ while (!params.signal?.aborted) {
1279
+ const env = await list({
1280
+ ...params,
1281
+ limit: batchSize,
1282
+ cursor: first ? params.cursor : cursor ?? undefined
1283
+ });
1284
+ for (const row of env.rows) {
1285
+ if (params.signal?.aborted)
1286
+ return;
1287
+ yield row;
1288
+ }
1289
+ if (!env.next_cursor || env.next_cursor === cursor || env.rows.length < batchSize)
1290
+ return;
1291
+ cursor = env.next_cursor;
1292
+ first = false;
1293
+ }
1294
+ }.bind(this);
1295
+ return { list, walk };
1296
+ }
1297
+ }
1166
1298
  // src/webhooks.ts
1167
1299
  import {
1168
1300
  verify
@@ -1211,6 +1343,7 @@ export {
1211
1343
  toJsonSafe,
1212
1344
  isStxTransfer,
1213
1345
  isStxMint,
1346
+ isStxLock,
1214
1347
  isStxBurn,
1215
1348
  isPrint,
1216
1349
  isNftTransfer,
@@ -1222,6 +1355,7 @@ export {
1222
1355
  getSubgraph,
1223
1356
  decodeStxTransfer,
1224
1357
  decodeStxMint,
1358
+ decodeStxLock,
1225
1359
  decodeStxBurn,
1226
1360
  decodePrint,
1227
1361
  decodeNftTransfer,
@@ -1240,9 +1374,11 @@ export {
1240
1374
  SecondLayer,
1241
1375
  RateLimitError,
1242
1376
  Index,
1377
+ Datasets,
1378
+ CURSOR_SLUGS,
1243
1379
  AuthError,
1244
1380
  ApiError
1245
1381
  };
1246
1382
 
1247
- //# debugId=9D4DDE30AE2D8C2F64756E2164756E21
1383
+ //# debugId=0E97B24861D9205A64756E2164756E21
1248
1384
  //# sourceMappingURL=index.js.map