@secondlayer/sdk 6.37.0 → 6.38.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 +184 -24
- package/dist/index.js +265 -78
- package/dist/index.js.map +11 -9
- package/dist/sinks/kysely.d.ts +108 -0
- package/dist/sinks/kysely.js +236 -0
- package/dist/sinks/kysely.js.map +11 -0
- package/dist/streams/index.d.ts +188 -6
- package/dist/streams/index.js +199 -71
- package/dist/streams/index.js.map +8 -7
- package/dist/subgraphs/index.d.ts +124 -21
- package/dist/subgraphs/index.js +222 -16
- package/dist/subgraphs/index.js.map +9 -7
- package/package.json +20 -7
package/dist/index.d.ts
CHANGED
|
@@ -285,6 +285,8 @@ declare class Contracts extends BaseClient {
|
|
|
285
285
|
includeAbi?: boolean
|
|
286
286
|
}): Promise<ContractSummary | null>;
|
|
287
287
|
}
|
|
288
|
+
import { Pox5EventTopic } from "@secondlayer/stacks/pox5";
|
|
289
|
+
import { SbtcEventTopic } from "@secondlayer/stacks/sbtc";
|
|
288
290
|
import { InferredTopicSchema } from "@secondlayer/subgraphs";
|
|
289
291
|
import { RewardSet } from "@secondlayer/shared/node/consensus";
|
|
290
292
|
import { MerkleProofStep } from "@secondlayer/shared/node/nakamoto";
|
|
@@ -365,6 +367,57 @@ declare function fetchRewardSet(opts: {
|
|
|
365
367
|
declare function verifyTransactionProof(proof: TransactionProof, opts?: {
|
|
366
368
|
rewardSet?: RewardSet
|
|
367
369
|
}): TransactionProofVerifyResult;
|
|
370
|
+
/**
|
|
371
|
+
* A consumer sink: the destination adapter a consume loop writes through.
|
|
372
|
+
*
|
|
373
|
+
* Without a sink, the user owns the three hard parts of a durable indexer —
|
|
374
|
+
* checkpoint persistence, rows+cursor atomicity, and reorg rollback — and
|
|
375
|
+
* the reasoning that makes them safe lives in doc comments. A sink owns all
|
|
376
|
+
* three: the loop loads its committed cursor, hands the handler a
|
|
377
|
+
* transaction, commits rows AND cursor atomically, and rolls back reorgs
|
|
378
|
+
* without any user code. Crucially, a sink also closes the silent-skip
|
|
379
|
+
* hazard where omitting `onReorg` meant reorgs were ignored forever: with a
|
|
380
|
+
* sink attached, rollback is unconditional.
|
|
381
|
+
*
|
|
382
|
+
* The interface is dependency-free on purpose: implementations with real
|
|
383
|
+
* database drivers live behind subpath exports (`@secondlayer/sdk/sinks/*`)
|
|
384
|
+
* so the root entry ships no DB dependency.
|
|
385
|
+
*/
|
|
386
|
+
interface ConsumerSink<Tx = unknown> {
|
|
387
|
+
/** Phantom marker carrying `Tx` in a directly-inferable position, so the
|
|
388
|
+
* consume loops' `TTx` type parameter resolves from the `sink` option
|
|
389
|
+
* (never set at runtime). */
|
|
390
|
+
readonly _tx?: Tx;
|
|
391
|
+
/** The committed checkpoint, or `null` on first run. Called once, before
|
|
392
|
+
* the first page. Implementations may create their checkpoint storage
|
|
393
|
+
* here and SHOULD validate their rollback preconditions (e.g. that every
|
|
394
|
+
* declared table carries the height column). */
|
|
395
|
+
loadCursor(): Promise<string | null>;
|
|
396
|
+
/**
|
|
397
|
+
* Apply one batch atomically: open a transaction, run `write(tx)` (the
|
|
398
|
+
* user's inserts), and commit the rows AND `cursor` together. A throw
|
|
399
|
+
* from `write` must abort the whole transaction — leaving neither rows
|
|
400
|
+
* nor cursor, so a crashed batch is simply re-read on restart.
|
|
401
|
+
*/
|
|
402
|
+
commitBatch(cursor: string, write: (tx: Tx) => Promise<void> | void): Promise<void>;
|
|
403
|
+
/**
|
|
404
|
+
* Roll the projection back to the fork: delete everything AT OR ABOVE
|
|
405
|
+
* `forkPointHeight` (inclusive `>=` — the new chain re-supplies the fork
|
|
406
|
+
* block) and commit `rewindCursor` in the SAME transaction. Deleting
|
|
407
|
+
* without the rewound cursor is the classic silent-gap bug: a crash
|
|
408
|
+
* between the two writes resumes above the fork and the deleted range is
|
|
409
|
+
* never re-read.
|
|
410
|
+
*/
|
|
411
|
+
rollback(forkPointHeight: number, rewindCursor: string): Promise<void>;
|
|
412
|
+
}
|
|
413
|
+
/** The transaction type a sink hands to `onBatch` (`ctx.tx`). */
|
|
414
|
+
type SinkTx<S> = S extends ConsumerSink<infer Tx> ? Tx : never;
|
|
415
|
+
/** `ctx` gains `tx` exactly when a sink is attached; without one the shape
|
|
416
|
+
* is unchanged (an intersection with `unknown` is an identity, so
|
|
417
|
+
* contextual typing of `onBatch` callbacks never degrades to a union). */
|
|
418
|
+
type WithSinkTx<TTx> = [TTx] extends [never] ? unknown : {
|
|
419
|
+
tx: TTx
|
|
420
|
+
};
|
|
368
421
|
import { StreamsEventType } from "@secondlayer/shared";
|
|
369
422
|
/** A Clarity value as Streams serves it: the canonical hex string, a typed
|
|
370
423
|
* object carrying that hex (`{ hex }`), or a decoded Clarity-JSON object.
|
|
@@ -610,8 +663,28 @@ type StreamsBatchContext = ConsumerBatchContext;
|
|
|
610
663
|
type StreamsReorgContext = {
|
|
611
664
|
cursor: string
|
|
612
665
|
};
|
|
613
|
-
type StreamsEventsConsumeParams
|
|
666
|
+
type StreamsEventsConsumeParams<
|
|
667
|
+
TTx = never,
|
|
668
|
+
D extends boolean = false
|
|
669
|
+
> = {
|
|
614
670
|
fromCursor?: string | null
|
|
671
|
+
/**
|
|
672
|
+
* Deliver events pre-decoded as the flat, `event_type`-discriminated rows
|
|
673
|
+
* Index serves (`IndexEvent`), so Streams consumption reads identically
|
|
674
|
+
* to Index consumption — no guard+decode pairs in your handler.
|
|
675
|
+
*/
|
|
676
|
+
decoded?: D
|
|
677
|
+
/**
|
|
678
|
+
* Destination adapter that owns the checkpoint + rollback transaction
|
|
679
|
+
* (e.g. `kyselySink` from `@secondlayer/sdk/sinks/kysely`). With a sink:
|
|
680
|
+
* the loop resumes from the sink's committed cursor, `onBatch` receives
|
|
681
|
+
* `ctx.tx` and must write ONLY through it (rows and cursor commit in one
|
|
682
|
+
* transaction), reorg rollback is automatic, and `onBatch`'s return value
|
|
683
|
+
* is ignored.
|
|
684
|
+
*/
|
|
685
|
+
sink?: ConsumerSink<TTx>
|
|
686
|
+
/** Fires once per page, before `onBatch` and before any early return. */
|
|
687
|
+
onProgress?: (ctx: ConsumerBatchContext) => void
|
|
615
688
|
mode?: "tail" | "bounded"
|
|
616
689
|
/**
|
|
617
690
|
* Emit only finalized (immutable) events and never surface reorgs. The SDK
|
|
@@ -632,7 +705,7 @@ type StreamsEventsConsumeParams = {
|
|
|
632
705
|
* transaction as your writes. Returning a cursor overrides `ctx.cursor` as
|
|
633
706
|
* the resume point (advanced manual control); returning nothing uses it.
|
|
634
707
|
*/
|
|
635
|
-
onBatch: (events: StreamsEvent[], envelope: StreamsEventsEnvelope, ctx: StreamsBatchContext) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
708
|
+
onBatch: (events: D extends true ? IndexEvent[] : StreamsEvent[], envelope: StreamsEventsEnvelope, ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
636
709
|
/**
|
|
637
710
|
* Roll your projection back to `reorg.fork_point_height`, persisting
|
|
638
711
|
* `ctx.cursor` in the same transaction. Called once per *new* reorg
|
|
@@ -790,7 +863,12 @@ type StreamsClient = {
|
|
|
790
863
|
* The consumer also exits when `maxPages`, `maxEmptyPolls`, or `signal`
|
|
791
864
|
* stops it.
|
|
792
865
|
*/
|
|
793
|
-
consume
|
|
866
|
+
consume<
|
|
867
|
+
TTx = never,
|
|
868
|
+
D extends boolean = false
|
|
869
|
+
>(params: StreamsEventsConsumeParams<TTx, D> & {
|
|
870
|
+
sink?: ConsumerSink<TTx>
|
|
871
|
+
}): Promise<StreamsEventsConsumeResult>
|
|
794
872
|
/**
|
|
795
873
|
* Backfill from bulk dumps, then continue live from the dump→live seam in
|
|
796
874
|
* one call. Iterates finalized dump files (via `onDumpFile`) in block
|
|
@@ -879,16 +957,18 @@ type IndexFeedFetcher<TEnvelope extends IndexFeedEnvelope> = (params: {
|
|
|
879
957
|
}) => Promise<TEnvelope>;
|
|
880
958
|
/** Consumer options shared by `index.events.consume` and
|
|
881
959
|
* `index.contractCalls.consume`. Same contract as the Streams consumer:
|
|
882
|
-
* commit your writes inside `onBatch`, return the cursor you committed
|
|
960
|
+
* commit your writes inside `onBatch`, return the cursor you committed —
|
|
961
|
+
* or attach a `sink` and let it own checkpointing and rollback entirely. */
|
|
883
962
|
type IndexConsumeOptions<
|
|
884
963
|
TItem extends IndexFeedItem,
|
|
885
|
-
TEnvelope extends IndexFeedEnvelope
|
|
964
|
+
TEnvelope extends IndexFeedEnvelope,
|
|
965
|
+
TTx = never
|
|
886
966
|
> = {
|
|
887
967
|
/** Resume from a committed checkpoint. Without it (and without
|
|
888
968
|
* `fromHeight`) the API serves only the recent default window. */
|
|
889
969
|
fromCursor?: string | null
|
|
890
970
|
/** Start a fresh sweep at this height (e.g. `0` for genesis backfill).
|
|
891
|
-
* Ignored once a cursor exists. */
|
|
971
|
+
* Ignored once a cursor exists (including a sink's committed cursor). */
|
|
892
972
|
fromHeight?: number
|
|
893
973
|
/** `tail` (default) keeps polling at the tip; `bounded` returns on the
|
|
894
974
|
* first empty page. */
|
|
@@ -898,7 +978,20 @@ type IndexConsumeOptions<
|
|
|
898
978
|
* never reorgs, so `onReorg` is skipped entirely. */
|
|
899
979
|
finalizedOnly?: boolean
|
|
900
980
|
batchSize?: number
|
|
901
|
-
|
|
981
|
+
/**
|
|
982
|
+
* Destination adapter that owns the checkpoint + rollback transaction
|
|
983
|
+
* (e.g. `kyselySink` from `@secondlayer/sdk/sinks/kysely`). With a sink:
|
|
984
|
+
* the loop resumes from the sink's committed cursor, `onBatch` receives
|
|
985
|
+
* `ctx.tx` and must write ONLY through it (rows and cursor commit in one
|
|
986
|
+
* transaction — a throw aborts both), reorg rollback is automatic (no
|
|
987
|
+
* `onReorg` needed), and `onBatch`'s return value is ignored.
|
|
988
|
+
*/
|
|
989
|
+
sink?: ConsumerSink<TTx>
|
|
990
|
+
/** Fires once per page, before `onBatch` and before any early return —
|
|
991
|
+
* an empty page still proves the loop is alive. Feed it to
|
|
992
|
+
* `consumerHealth().record`. */
|
|
993
|
+
onProgress?: (ctx: ConsumerBatchContext) => void
|
|
994
|
+
onBatch: (items: TItem[], envelope: TEnvelope, ctx: ConsumerBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
902
995
|
onReorg?: (reorg: IndexReorg, ctx: {
|
|
903
996
|
cursor: string
|
|
904
997
|
}) => Promise<void> | void
|
|
@@ -929,8 +1022,9 @@ type IndexConsumeOptions<
|
|
|
929
1022
|
*/
|
|
930
1023
|
declare function consumeIndexFeed<
|
|
931
1024
|
TItem extends IndexFeedItem,
|
|
932
|
-
TEnvelope extends IndexFeedEnvelope
|
|
933
|
-
|
|
1025
|
+
TEnvelope extends IndexFeedEnvelope,
|
|
1026
|
+
TTx = never
|
|
1027
|
+
>(opts: IndexConsumeOptions<TItem, TEnvelope, TTx> & {
|
|
934
1028
|
fetchPage: IndexFeedFetcher<TEnvelope>
|
|
935
1029
|
itemsOf: (envelope: TEnvelope) => TItem[]
|
|
936
1030
|
}): Promise<{
|
|
@@ -938,6 +1032,7 @@ declare function consumeIndexFeed<
|
|
|
938
1032
|
pages: number
|
|
939
1033
|
emptyPolls: number
|
|
940
1034
|
}>;
|
|
1035
|
+
import { SbtcEventTopic as SbtcEventTopic2 } from "@secondlayer/stacks/sbtc";
|
|
941
1036
|
type IndexTip = {
|
|
942
1037
|
block_height: number
|
|
943
1038
|
/** Highest height treated as immutable (past the burn-confirmation
|
|
@@ -1185,7 +1280,10 @@ type EventsWalkParams<T extends IndexEventType = IndexEventType> = Omit<EventsLi
|
|
|
1185
1280
|
batchSize?: number
|
|
1186
1281
|
signal?: AbortSignal
|
|
1187
1282
|
};
|
|
1188
|
-
type EventsConsumeParams<
|
|
1283
|
+
type EventsConsumeParams<
|
|
1284
|
+
T extends IndexEventType = IndexEventType,
|
|
1285
|
+
TTx = never
|
|
1286
|
+
> = Omit<EventsListParams<T>, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexEventOf<T>, EventsEnvelope<T>, TTx>;
|
|
1189
1287
|
type IndexContractCall = {
|
|
1190
1288
|
cursor: string
|
|
1191
1289
|
block_height: number
|
|
@@ -1225,7 +1323,7 @@ type ContractCallsWalkParams = Omit<ContractCallsListParams, "limit"> & {
|
|
|
1225
1323
|
batchSize?: number
|
|
1226
1324
|
signal?: AbortSignal
|
|
1227
1325
|
};
|
|
1228
|
-
type ContractCallsConsumeParams = Omit<ContractCallsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexContractCall, ContractCallsEnvelope>;
|
|
1326
|
+
type ContractCallsConsumeParams<TTx = never> = Omit<ContractCallsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexContractCall, ContractCallsEnvelope, TTx>;
|
|
1229
1327
|
/** One canonical block in the sync map. Lean by design — block + parent hash
|
|
1230
1328
|
* for chain linkage, burn anchor for Bitcoin confirmations. Use `blocks` for
|
|
1231
1329
|
* the full block resource. */
|
|
@@ -1496,8 +1594,6 @@ type PrintSchemaResponse = {
|
|
|
1496
1594
|
}
|
|
1497
1595
|
tip: IndexTip
|
|
1498
1596
|
};
|
|
1499
|
-
/** The decoded `sbtc_events` topics. */
|
|
1500
|
-
type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
|
|
1501
1597
|
type SbtcWithdrawalStatus = "REQUESTED" | "ACCEPTED" | "REJECTED";
|
|
1502
1598
|
/** A completed sBTC peg-in, keyed by `bitcoin_txid` (deposits carry no
|
|
1503
1599
|
* `request_id`). One terminal `completed-deposit` event per deposit. */
|
|
@@ -1698,8 +1794,8 @@ type SbtcEventsWalkParams = Omit<SbtcEventsListParams, "limit"> & {
|
|
|
1698
1794
|
batchSize?: number
|
|
1699
1795
|
signal?: AbortSignal
|
|
1700
1796
|
};
|
|
1701
|
-
type SbtcEventsConsumeParams = Omit<SbtcEventsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcEvent, SbtcEventsEnvelope>;
|
|
1702
|
-
type SbtcDepositsConsumeParams = Omit<SbtcDepositsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcDeposit, SbtcDepositsEnvelope>;
|
|
1797
|
+
type SbtcEventsConsumeParams<TTx = never> = Omit<SbtcEventsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcEvent, SbtcEventsEnvelope, TTx>;
|
|
1798
|
+
type SbtcDepositsConsumeParams<TTx = never> = Omit<SbtcDepositsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcDeposit, SbtcDepositsEnvelope, TTx>;
|
|
1703
1799
|
/** `index.sbtc` — the decoded sBTC peg surface (deposits, withdrawals, raw
|
|
1704
1800
|
* events, scoreboard). The only productized decoded sBTC peg feed on Stacks. */
|
|
1705
1801
|
interface SbtcResource {
|
|
@@ -1708,7 +1804,9 @@ interface SbtcResource {
|
|
|
1708
1804
|
walk(params?: SbtcDepositsWalkParams): AsyncIterable<IndexSbtcDeposit>
|
|
1709
1805
|
/** Checkpointed sweep of completed deposits — append-only, so safe to
|
|
1710
1806
|
* mirror. See {@link IndexConsumeOptions}. */
|
|
1711
|
-
consume(params: SbtcDepositsConsumeParams
|
|
1807
|
+
consume<TTx = never>(params: SbtcDepositsConsumeParams<TTx> & {
|
|
1808
|
+
sink?: ConsumerSink<TTx>
|
|
1809
|
+
}): Promise<{
|
|
1712
1810
|
cursor: string | null
|
|
1713
1811
|
pages: number
|
|
1714
1812
|
emptyPolls: number
|
|
@@ -1727,7 +1825,9 @@ interface SbtcResource {
|
|
|
1727
1825
|
walk(params?: SbtcEventsWalkParams): AsyncIterable<IndexSbtcEvent>
|
|
1728
1826
|
/** Checkpointed sweep of the raw peg event log — append-only across all
|
|
1729
1827
|
* six topics. See {@link IndexConsumeOptions}. */
|
|
1730
|
-
consume(params: SbtcEventsConsumeParams
|
|
1828
|
+
consume<TTx = never>(params: SbtcEventsConsumeParams<TTx> & {
|
|
1829
|
+
sink?: ConsumerSink<TTx>
|
|
1830
|
+
}): Promise<{
|
|
1731
1831
|
cursor: string | null
|
|
1732
1832
|
pages: number
|
|
1733
1833
|
emptyPolls: number
|
|
@@ -1787,10 +1887,10 @@ interface PoxResource {
|
|
|
1787
1887
|
get(rewardCycle: number): Promise<PoxCycleEnvelope | null>
|
|
1788
1888
|
};
|
|
1789
1889
|
}
|
|
1790
|
-
/** The decoded `pox-5` boot-contract print topics (SIP-045 Bitcoin Staking)
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
type IndexPox5EventTopic =
|
|
1890
|
+
/** The decoded `pox-5` boot-contract print topics (SIP-045 Bitcoin Staking) —
|
|
1891
|
+
* one source of truth in `@secondlayer/stacks/pox5` (already a dependency;
|
|
1892
|
+
* the old "SDK owns its own dependency surface" rationale predated that). */
|
|
1893
|
+
type IndexPox5EventTopic = Pox5EventTopic;
|
|
1794
1894
|
/** A raw decoded PoX-5 print event. Promoted fields cover the hot query paths;
|
|
1795
1895
|
* `data` always carries the full decoded tuple, including nested shapes
|
|
1796
1896
|
* (`btc-lockup`, `bond-rewards`, `bond-periods`) that have no flat column. */
|
|
@@ -1877,7 +1977,12 @@ interface IndexEventsResource {
|
|
|
1877
1977
|
<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1878
1978
|
list<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1879
1979
|
walk<T extends IndexEventType>(params: EventsWalkParams<T>): AsyncIterable<IndexEventOf<T>>;
|
|
1880
|
-
consume<
|
|
1980
|
+
consume<
|
|
1981
|
+
T extends IndexEventType,
|
|
1982
|
+
TTx = never
|
|
1983
|
+
>(params: EventsConsumeParams<T, TTx> & {
|
|
1984
|
+
sink?: ConsumerSink<TTx>
|
|
1985
|
+
}): Promise<{
|
|
1881
1986
|
cursor: string | null
|
|
1882
1987
|
pages: number
|
|
1883
1988
|
emptyPolls: number
|
|
@@ -1923,7 +2028,9 @@ declare class Index extends BaseClient {
|
|
|
1923
2028
|
readonly contractCalls: {
|
|
1924
2029
|
list: (params?: ContractCallsListParams) => Promise<ContractCallsEnvelope>
|
|
1925
2030
|
walk: (params?: ContractCallsWalkParams) => AsyncIterable<IndexContractCall>
|
|
1926
|
-
consume: (params: ContractCallsConsumeParams
|
|
2031
|
+
consume: <TTx = never>(params: ContractCallsConsumeParams<TTx> & {
|
|
2032
|
+
sink?: ConsumerSink<TTx>
|
|
2033
|
+
}) => Promise<{
|
|
1927
2034
|
cursor: string | null
|
|
1928
2035
|
pages: number
|
|
1929
2036
|
emptyPolls: number
|
|
@@ -2255,6 +2362,22 @@ type CreateStreamsClientOptions = {
|
|
|
2255
2362
|
verifyDumpsManifest?: boolean
|
|
2256
2363
|
};
|
|
2257
2364
|
declare function createStreamsClient(options: CreateStreamsClientOptions): StreamsClient;
|
|
2365
|
+
/**
|
|
2366
|
+
* Decode a raw Streams event into the SAME flat, `event_type`-discriminated
|
|
2367
|
+
* row shape Index serves — so Streams consumption reads identically to Index
|
|
2368
|
+
* consumption, with one call instead of eleven guard+decode pairs.
|
|
2369
|
+
*
|
|
2370
|
+
* ```ts
|
|
2371
|
+
* for (const event of envelope.events) {
|
|
2372
|
+
* const row = decode(event);
|
|
2373
|
+
* if (row.event_type === "ft_transfer") row.amount; // string, narrowed
|
|
2374
|
+
* }
|
|
2375
|
+
* ```
|
|
2376
|
+
*
|
|
2377
|
+
* Prefer `decoded: true` on `streams.events.consume` — then decoding never
|
|
2378
|
+
* appears in your code at all.
|
|
2379
|
+
*/
|
|
2380
|
+
declare function decode(event: StreamsEvent): IndexEvent;
|
|
2258
2381
|
import { ByoBreakingChangeDetails } from "@secondlayer/shared/errors";
|
|
2259
2382
|
/** Options accepted by every error in the family. */
|
|
2260
2383
|
interface SecondLayerErrorOptions {
|
|
@@ -2829,6 +2952,43 @@ type PayAndRetryOptions = Omit<WithX402Options, never> & {
|
|
|
2829
2952
|
*/
|
|
2830
2953
|
declare function payAndRetry(doFetch: X402FetchFn, opts: PayAndRetryOptions): Promise<Response>;
|
|
2831
2954
|
import { SubgraphAgentSchema as SubgraphAgentSchema3, SubgraphSpecFormat as SubgraphSpecFormat2, SubgraphSpecOptions as SubgraphSpecOptions3 } from "@secondlayer/shared/subgraphs/spec";
|
|
2955
|
+
/**
|
|
2956
|
+
* The two pieces every "deploy a consumer" guide leaves out, packaged:
|
|
2957
|
+
* a liveness endpoint and a graceful-shutdown signal. Both are
|
|
2958
|
+
* runtime-agnostic — the SDK never binds a port or assumes Bun/Node.
|
|
2959
|
+
*/
|
|
2960
|
+
interface ConsumerHealth {
|
|
2961
|
+
/** Feed this to the consume loop's `onProgress` — it stamps arrival time
|
|
2962
|
+
* and keeps the latest progress ctx for the health body. */
|
|
2963
|
+
record: (ctx: ConsumerBatchContext) => void;
|
|
2964
|
+
/** Fetch-style handler for `GET /health`. Mount it on whatever serves
|
|
2965
|
+
* HTTP in your runtime:
|
|
2966
|
+
* `Bun.serve({ port, fetch: health.handler })` ·
|
|
2967
|
+
* `http.createServer(...)` via an adapter · a Workers route. */
|
|
2968
|
+
handler: (req: Request) => Response;
|
|
2969
|
+
}
|
|
2970
|
+
/**
|
|
2971
|
+
* Liveness for a consume loop. The gate is "did a page land recently", NOT
|
|
2972
|
+
* "are we near the tip": during a genesis backfill the loop is millions of
|
|
2973
|
+
* blocks behind and perfectly healthy, so lag can't be the signal. A wedged
|
|
2974
|
+
* loop stops reporting pages and flips to 503 — that's what platforms
|
|
2975
|
+
* should restart on. `blocks_behind` still ships in the body for dashboards.
|
|
2976
|
+
*/
|
|
2977
|
+
declare function consumerHealth(options?: {
|
|
2978
|
+
staleAfterMs?: number
|
|
2979
|
+
}): ConsumerHealth;
|
|
2980
|
+
/**
|
|
2981
|
+
* An `AbortSignal` wired to SIGTERM/SIGINT (redeploys arrive as SIGTERM).
|
|
2982
|
+
* Pass it as the consume loop's `signal`: aborting is checked at the top of
|
|
2983
|
+
* the loop, never mid-batch, so the in-flight transaction — rows AND
|
|
2984
|
+
* checkpoint — always commits before the process exits. Nothing is
|
|
2985
|
+
* half-written; the next run resumes from exactly that cursor.
|
|
2986
|
+
*
|
|
2987
|
+
* No-op (never fires) on runtimes without `process` signal handling.
|
|
2988
|
+
*/
|
|
2989
|
+
declare function shutdownSignal(options?: {
|
|
2990
|
+
signals?: readonly ("SIGTERM" | "SIGINT")[]
|
|
2991
|
+
}): AbortSignal;
|
|
2832
2992
|
import { ChainWebhookDelivery } from "@secondlayer/shared";
|
|
2833
2993
|
import { StandardWebhooksHeaders } from "@secondlayer/shared/crypto/standard-webhooks";
|
|
2834
2994
|
import { StandardWebhooksHeaders as StandardWebhooksHeaders2, verify } from "@secondlayer/shared/crypto/standard-webhooks";
|
|
@@ -2992,4 +3152,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
2992
3152
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
2993
3153
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
2994
3154
|
declare function decodeClarityValue(hex: string): unknown;
|
|
2995
|
-
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, selectOffer, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, parseRetryAfter, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, createX402Client, createStreamsClient, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SelectOfferOptions, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, 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, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
|
3155
|
+
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, selectOffer, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, parseRetryAfter, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, decode, createX402Client, createStreamsClient, consumerHealth, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WithSinkTx, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SinkTx, SelectOfferOptions, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic2 as SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, 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, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ConsumerSink, ConsumerHealth, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|