@secondlayer/sdk 6.43.0 → 6.45.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/index.d.ts CHANGED
@@ -686,7 +686,10 @@ type StreamsEventsSubscribeParams = {
686
686
  * block as `${height - 1}:<sentinel>`, so a rewound cursor parses to a
687
687
  * position that was never reached.
688
688
  */
689
- type ConsumerBatchContext = {
689
+ type ConsumerBatchContext<
690
+ TTip = unknown,
691
+ TReorg = unknown
692
+ > = {
690
693
  /** Checkpoint to commit alongside your rows. */
691
694
  cursor: string | null
692
695
  /** Highest canonical block the sweep has reached. `null` before the first
@@ -696,6 +699,19 @@ type ConsumerBatchContext = {
696
699
  tipHeight: number
697
700
  /** `tipHeight - height`, floored at 0. `null` until `height` is known. */
698
701
  blocksBehind: number | null
702
+ /**
703
+ * The full tip for this page — `StreamsTip` or `IndexTip` depending on the
704
+ * surface. Exposed here so a handler never needs the `envelope` parameter,
705
+ * which is the only way to reach it today and is also how the worst
706
+ * `finalizedOnly` mistake becomes reachable (`return envelope.next_cursor`
707
+ * jumps the cursor past events that were filtered out and never delivered).
708
+ */
709
+ tip: TTip
710
+ /**
711
+ * Reorgs reported alongside this page; empty when none. Rollback still
712
+ * belongs in `onReorg` — this is for observability inside a batch.
713
+ */
714
+ reorgs: readonly TReorg[]
699
715
  };
700
716
  /** @deprecated Use {@link ConsumerBatchContext} — the Index and Streams loops
701
717
  * share one shape now. Kept as an alias so existing annotations compile. */
@@ -1150,6 +1166,7 @@ type IndexUsage = {
1150
1166
  type FtTransfer = {
1151
1167
  cursor: string
1152
1168
  block_height: number
1169
+ block_time?: string | null
1153
1170
  tx_id: string
1154
1171
  tx_index: number
1155
1172
  event_index: number
@@ -1160,13 +1177,25 @@ type FtTransfer = {
1160
1177
  recipient: string
1161
1178
  amount: string
1162
1179
  };
1163
- type FtTransfersEnvelope = {
1164
- events: FtTransfer[]
1180
+ type FtTransfersEnvelope<TRow = FtTransfer> = {
1181
+ events: TRow[]
1165
1182
  next_cursor: string | null
1166
1183
  tip: IndexTip
1167
1184
  reorgs: IndexReorg[]
1168
1185
  };
1186
+ /** Transfer columns that survive any projection — the consume contract
1187
+ * (`cursor`, `block_height`) plus the `event_type` discriminant. */
1188
+ type FtTransferAlwaysFields = "cursor" | "block_height" | "event_type";
1189
+ /** An ft-transfer row narrowed to the requested columns plus the always-present ones. */
1190
+ type FtTransferFields<F extends keyof FtTransfer & string> = Pick<FtTransfer, (F | FtTransferAlwaysFields) & keyof FtTransfer>;
1169
1191
  type FtTransfersListParams = {
1192
+ /**
1193
+ * Columns to return. The server projects the row, so an unrequested column
1194
+ * is physically absent — and the narrowing overload on `list` makes reading
1195
+ * one a compile error rather than `undefined` at runtime. Omitting
1196
+ * `block_time` also lets the server skip the blocks join.
1197
+ */
1198
+ fields?: readonly (keyof FtTransfer & string)[]
1170
1199
  cursor?: string | null
1171
1200
  fromCursor?: string | null
1172
1201
  limit?: number
@@ -1183,6 +1212,7 @@ type FtTransfersWalkParams = Omit<FtTransfersListParams, "limit"> & {
1183
1212
  type NftTransfer = {
1184
1213
  cursor: string
1185
1214
  block_height: number
1215
+ block_time?: string | null
1186
1216
  tx_id: string
1187
1217
  tx_index: number
1188
1218
  event_index: number
@@ -1193,13 +1223,19 @@ type NftTransfer = {
1193
1223
  recipient: string
1194
1224
  value: string
1195
1225
  };
1196
- type NftTransfersEnvelope = {
1197
- events: NftTransfer[]
1226
+ type NftTransfersEnvelope<TRow = NftTransfer> = {
1227
+ events: TRow[]
1198
1228
  next_cursor: string | null
1199
1229
  tip: IndexTip
1200
1230
  reorgs: IndexReorg[]
1201
1231
  };
1232
+ /** See {@link FtTransferAlwaysFields}. */
1233
+ type NftTransferAlwaysFields = "cursor" | "block_height" | "event_type";
1234
+ /** An nft-transfer row narrowed to the requested columns plus the always-present ones. */
1235
+ type NftTransferFields<F extends keyof NftTransfer & string> = Pick<NftTransfer, (F | NftTransferAlwaysFields) & keyof NftTransfer>;
1202
1236
  type NftTransfersListParams = {
1237
+ /** Columns to return (see {@link FtTransfersListParams.fields}). */
1238
+ fields?: readonly (keyof NftTransfer & string)[]
1203
1239
  cursor?: string | null
1204
1240
  fromCursor?: string | null
1205
1241
  limit?: number
@@ -1539,8 +1575,8 @@ type IndexTransaction = {
1539
1575
  cause: number
1540
1576
  }
1541
1577
  };
1542
- type TransactionsEnvelope = {
1543
- transactions: IndexTransaction[]
1578
+ type TransactionsEnvelope<TRow = IndexTransaction> = {
1579
+ transactions: TRow[]
1544
1580
  next_cursor: string | null
1545
1581
  tip: IndexTip
1546
1582
  reorgs: IndexReorg[]
@@ -1549,7 +1585,17 @@ type TransactionEnvelope = {
1549
1585
  transaction: IndexTransaction
1550
1586
  tip: IndexTip
1551
1587
  };
1588
+ /** Transaction columns that survive any projection. */
1589
+ type TransactionAlwaysFields = "cursor" | "block_height" | "tx_id";
1590
+ /** A Transaction row narrowed to the requested columns plus the always-present ones. */
1591
+ type TransactionFields<F extends keyof IndexTransaction & string> = Pick<IndexTransaction, (F | TransactionAlwaysFields) & keyof IndexTransaction>;
1552
1592
  type TransactionsListParams = {
1593
+ /**
1594
+ * Columns to return. The server projects the row, so an unrequested column
1595
+ * is physically absent — and the narrowing overload on `list` makes reading
1596
+ * one a compile error rather than `undefined` at runtime.
1597
+ */
1598
+ fields?: readonly (keyof IndexTransaction & string)[]
1553
1599
  cursor?: string | null
1554
1600
  fromCursor?: string | null
1555
1601
  limit?: number
@@ -1814,8 +1860,8 @@ type SbtcDepositEnvelope = {
1814
1860
  deposit: IndexSbtcDepositDetail
1815
1861
  tip: IndexTip
1816
1862
  };
1817
- type SbtcWithdrawalsEnvelope = {
1818
- withdrawals: IndexSbtcWithdrawal[]
1863
+ type SbtcWithdrawalsEnvelope<TRow = IndexSbtcWithdrawal> = {
1864
+ withdrawals: TRow[]
1819
1865
  next_cursor: string | null
1820
1866
  tip: IndexTip
1821
1867
  reorgs: IndexReorg[]
@@ -1862,7 +1908,17 @@ type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & {
1862
1908
  batchSize?: number
1863
1909
  signal?: AbortSignal
1864
1910
  };
1911
+ /** SbtcWithdrawal columns that survive any projection. */
1912
+ type SbtcWithdrawalAlwaysFields = "cursor" | "request_id";
1913
+ /** A SbtcWithdrawal row narrowed to the requested columns plus the always-present ones. */
1914
+ type SbtcWithdrawalFields<F extends keyof IndexSbtcWithdrawal & string> = Pick<IndexSbtcWithdrawal, (F | SbtcWithdrawalAlwaysFields) & keyof IndexSbtcWithdrawal>;
1865
1915
  type SbtcWithdrawalsListParams = {
1916
+ /**
1917
+ * Columns to return. The server projects the row, so an unrequested column
1918
+ * is physically absent — and the narrowing overload on `list` makes reading
1919
+ * one a compile error rather than `undefined` at runtime.
1920
+ */
1921
+ fields?: readonly (keyof IndexSbtcWithdrawal & string)[]
1866
1922
  cursor?: string | null
1867
1923
  fromCursor?: string | null
1868
1924
  limit?: number
@@ -1922,6 +1978,11 @@ interface SbtcResource {
1922
1978
  get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
1923
1979
  };
1924
1980
  withdrawals: {
1981
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
1982
+ * requested columns plus {@link SbtcWithdrawalAlwaysFields}. */
1983
+ list<const F extends keyof IndexSbtcWithdrawal & string>(params: SbtcWithdrawalsListParams & {
1984
+ fields: readonly F[]
1985
+ }): Promise<SbtcWithdrawalsEnvelope<SbtcWithdrawalFields<F>>>
1925
1986
  list(params?: SbtcWithdrawalsListParams): Promise<SbtcWithdrawalsEnvelope>
1926
1987
  walk(params?: SbtcWithdrawalsWalkParams): AsyncIterable<IndexSbtcWithdrawal>
1927
1988
  /** Fetch a withdrawal's full lifecycle by request id; 404 → null. */
@@ -2026,15 +2087,25 @@ type IndexPox5Event = {
2026
2087
  /** The full decoded print tuple as JSON. */
2027
2088
  data: unknown
2028
2089
  };
2029
- type Pox5EventsEnvelope = {
2030
- events: IndexPox5Event[]
2090
+ type Pox5EventsEnvelope<TRow = IndexPox5Event> = {
2091
+ events: TRow[]
2031
2092
  next_cursor: string | null
2032
2093
  tip: IndexTip
2033
2094
  reorgs: IndexReorg[]
2034
2095
  /** Present only when the PoX-5 decoder is disabled, explaining an empty feed. */
2035
2096
  notes?: string
2036
2097
  };
2098
+ /** Pox5Event columns that survive any projection. */
2099
+ type Pox5EventAlwaysFields = "cursor" | "block_height" | "topic";
2100
+ /** A Pox5Event row narrowed to the requested columns plus the always-present ones. */
2101
+ type Pox5EventFields<F extends keyof IndexPox5Event & string> = Pick<IndexPox5Event, (F | Pox5EventAlwaysFields) & keyof IndexPox5Event>;
2037
2102
  type Pox5EventsListParams = {
2103
+ /**
2104
+ * Columns to return. The server projects the row, so an unrequested column
2105
+ * is physically absent — and the narrowing overload on `list` makes reading
2106
+ * one a compile error rather than `undefined` at runtime.
2107
+ */
2108
+ fields?: readonly (keyof IndexPox5Event & string)[]
2038
2109
  cursor?: string | null
2039
2110
  fromCursor?: string | null
2040
2111
  limit?: number
@@ -2057,6 +2128,11 @@ type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & {
2057
2128
  * epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
2058
2129
  interface Pox5Resource {
2059
2130
  events: {
2131
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2132
+ * requested columns plus {@link Pox5EventAlwaysFields}. */
2133
+ list<const F extends keyof IndexPox5Event & string>(params: Pox5EventsListParams & {
2134
+ fields: readonly F[]
2135
+ }): Promise<Pox5EventsEnvelope<Pox5EventFields<F>>>
2060
2136
  list(params?: Pox5EventsListParams): Promise<Pox5EventsEnvelope>
2061
2137
  walk(params?: Pox5EventsWalkParams): AsyncIterable<IndexPox5Event>
2062
2138
  };
@@ -2069,14 +2145,44 @@ interface Pox5Resource {
2069
2145
  * no amount filtering and no asset-slug resolution on /v1/index/ft-transfers.
2070
2146
  */
2071
2147
  interface FtTransfersResource {
2148
+ /** Narrowing overload for the callable shorthand — same wire path as
2149
+ * `list`, so it must narrow identically. */
2150
+ <const F extends keyof FtTransfer & string>(params: FtTransfersListParams & {
2151
+ fields: readonly F[]
2152
+ }): Promise<FtTransfersEnvelope<FtTransferFields<F>>>;
2072
2153
  (params?: FtTransfersListParams): Promise<FtTransfersEnvelope>;
2154
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2155
+ * requested columns plus {@link FtTransferAlwaysFields}. */
2156
+ list<const F extends keyof FtTransfer & string>(params: FtTransfersListParams & {
2157
+ fields: readonly F[]
2158
+ }): Promise<FtTransfersEnvelope<FtTransferFields<F>>>;
2073
2159
  list(params?: FtTransfersListParams): Promise<FtTransfersEnvelope>;
2160
+ /** Narrowing overload, matching `list`: `walk` forwards `fields` to the
2161
+ * wire, so without this the yielded rows are stripped while the type
2162
+ * still promises every column. */
2163
+ walk<const F extends keyof FtTransfer & string>(params: FtTransfersWalkParams & {
2164
+ fields: readonly F[]
2165
+ }): AsyncIterable<FtTransferFields<F>>;
2074
2166
  walk(params?: FtTransfersWalkParams): AsyncIterable<FtTransfer>;
2075
2167
  }
2076
2168
  /** `index.nftTransfers` — callable shorthand for `.list()` (see {@link FtTransfersResource}). */
2077
2169
  interface NftTransfersResource {
2170
+ /** Narrowing overload for the callable shorthand — same wire path as
2171
+ * `list`, so it must narrow identically. */
2172
+ <const F extends keyof NftTransfer & string>(params: NftTransfersListParams & {
2173
+ fields: readonly F[]
2174
+ }): Promise<NftTransfersEnvelope<NftTransferFields<F>>>;
2078
2175
  (params?: NftTransfersListParams): Promise<NftTransfersEnvelope>;
2176
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2177
+ * requested columns plus {@link NftTransferAlwaysFields}. */
2178
+ list<const F extends keyof NftTransfer & string>(params: NftTransfersListParams & {
2179
+ fields: readonly F[]
2180
+ }): Promise<NftTransfersEnvelope<NftTransferFields<F>>>;
2079
2181
  list(params?: NftTransfersListParams): Promise<NftTransfersEnvelope>;
2182
+ /** Narrowing overload, matching `list` (see {@link FtTransfersResource}). */
2183
+ walk<const F extends keyof NftTransfer & string>(params: NftTransfersWalkParams & {
2184
+ fields: readonly F[]
2185
+ }): AsyncIterable<NftTransferFields<F>>;
2080
2186
  walk(params?: NftTransfersWalkParams): AsyncIterable<NftTransfer>;
2081
2187
  }
2082
2188
  /** `index.events` — callable shorthand for `.list()`; `eventType` is required. */
@@ -2184,7 +2290,16 @@ declare class Index extends BaseClient {
2184
2290
  /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
2185
2291
  * (resolves to null on 404). */
2186
2292
  readonly transactions: {
2187
- list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
2293
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2294
+ * requested columns plus {@link TransactionAlwaysFields}. Declared as
2295
+ * an overloaded call signature because an arrow property cannot carry
2296
+ * overloads. */
2297
+ list: {
2298
+ <const F extends keyof IndexTransaction & string>(params: TransactionsListParams & {
2299
+ fields: readonly F[]
2300
+ }): Promise<TransactionsEnvelope<TransactionFields<F>>>
2301
+ (params?: TransactionsListParams): Promise<TransactionsEnvelope>
2302
+ }
2188
2303
  walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
2189
2304
  get: (txId: string) => Promise<TransactionEnvelope | null>
2190
2305
  getProof: (txId: string) => Promise<TransactionProof | null>
package/dist/index.js CHANGED
@@ -592,12 +592,15 @@ function assertFinalizedCheckpoint(returned, checkpoint) {
592
592
  throw new ValidationError(`onBatch returned cursor "${returned}", above the last delivered finalized event${boundary}. With finalizedOnly, events past that point were filtered out and will be re-read once finalized — committing beyond it skips them permanently. Return ctx.cursor (or nothing); never envelope.next_cursor.`, 400);
593
593
  }
594
594
  }
595
- function batchContext(cursor, height, tipHeight) {
595
+ function batchContext(cursor, height, tip, reorgs = []) {
596
+ const tipHeight = tip.block_height;
596
597
  return {
597
598
  cursor,
598
599
  height,
599
600
  tipHeight,
600
- blocksBehind: height === null ? null : Math.max(0, tipHeight - height)
601
+ blocksBehind: height === null ? null : Math.max(0, tipHeight - height),
602
+ tip,
603
+ reorgs
601
604
  };
602
605
  }
603
606
  var MAX_RETRY_AFTER_MS = 300000;
@@ -699,7 +702,7 @@ async function consumeStreamsEvents(opts) {
699
702
  const emitted = finalizedOnly ? envelope.events.filter((event) => event.finalized) : envelope.events;
700
703
  const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
701
704
  height = emitted.at(-1)?.block_height ?? height;
702
- const ctx = batchContext(checkpoint, height, envelope.tip.block_height);
705
+ const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
703
706
  opts.onProgress?.(ctx);
704
707
  let nextCursor;
705
708
  if (opts.sink) {
@@ -860,7 +863,7 @@ async function consumeIndexFeed(opts) {
860
863
  const emitted = finalizedOnly ? items.filter((item) => item.block_height <= envelope.tip.finalized_height) : items;
861
864
  const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
862
865
  height = emitted.at(-1)?.block_height ?? height;
863
- const ctx = batchContext(checkpoint, height, envelope.tip.block_height);
866
+ const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
864
867
  opts.onProgress?.(ctx);
865
868
  let nextCursor;
866
869
  if (opts.sink) {
@@ -1058,7 +1061,8 @@ class Index extends BaseClient {
1058
1061
  sender: params.sender,
1059
1062
  recipient: params.recipient,
1060
1063
  from_height: params.fromHeight,
1061
- to_height: params.toHeight
1064
+ to_height: params.toHeight,
1065
+ fields: params.fields?.join(",")
1062
1066
  })}`);
1063
1067
  }
1064
1068
  async listNftTransfers(params = {}) {
@@ -1071,7 +1075,8 @@ class Index extends BaseClient {
1071
1075
  sender: params.sender,
1072
1076
  recipient: params.recipient,
1073
1077
  from_height: params.fromHeight,
1074
- to_height: params.toHeight
1078
+ to_height: params.toHeight,
1079
+ fields: params.fields?.join(",")
1075
1080
  })}`);
1076
1081
  }
1077
1082
  async* keysetWalk(params, list, itemsOf) {
@@ -1177,7 +1182,8 @@ class Index extends BaseClient {
1177
1182
  sender: params.sender,
1178
1183
  contract_id: params.contractId,
1179
1184
  from_height: params.fromHeight,
1180
- to_height: params.toHeight
1185
+ to_height: params.toHeight,
1186
+ fields: params.fields?.join(",")
1181
1187
  })}`);
1182
1188
  }
1183
1189
  async getTransaction(txId) {
@@ -1250,7 +1256,8 @@ class Index extends BaseClient {
1250
1256
  request_id: params.requestId,
1251
1257
  settlement_confirmed: params.settlementConfirmed,
1252
1258
  from_height: params.fromHeight,
1253
- to_height: params.toHeight
1259
+ to_height: params.toHeight,
1260
+ fields: params.fields?.join(",")
1254
1261
  })}`);
1255
1262
  }
1256
1263
  walkSbtcWithdrawals(params = {}) {
@@ -1292,7 +1299,8 @@ class Index extends BaseClient {
1292
1299
  bond_index: params.bondIndex,
1293
1300
  reward_cycle: params.rewardCycle,
1294
1301
  from_height: params.fromHeight,
1295
- to_height: params.toHeight
1302
+ to_height: params.toHeight,
1303
+ fields: params.fields?.join(",")
1296
1304
  })}`);
1297
1305
  }
1298
1306
  walkPox5Events(params = {}) {
@@ -2878,5 +2886,5 @@ export {
2878
2886
  ApiError
2879
2887
  };
2880
2888
 
2881
- //# debugId=F96DBA9B81801E0B64756E2164756E21
2889
+ //# debugId=798F8DCB6A6B9EBD64756E2164756E21
2882
2890
  //# sourceMappingURL=index.js.map