@secondlayer/sdk 6.54.1 → 7.0.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.
@@ -1,4 +1,4 @@
1
- import { STREAMS_EVENT_TYPES, StreamsEventType } from "@secondlayer/shared";
1
+ import { STREAMS_EVENT_TYPES, StreamsEvent, StreamsEventType } from "@secondlayer/shared/streams-rows";
2
2
  /**
3
3
  * A consumer sink: the destination adapter a consume loop writes through.
4
4
  *
@@ -216,113 +216,7 @@ type IndexPrint = IndexEventBase & {
216
216
  };
217
217
  /** Decoded chain event, discriminated by `event_type`. */
218
218
  type IndexEvent = IndexFtTransfer | IndexNftTransfer | IndexStxTransfer | IndexStxMint | IndexStxBurn | IndexStxLock | IndexFtMint | IndexFtBurn | IndexNftMint | IndexNftBurn | IndexPrint;
219
- /** A Clarity value as Streams serves it: the canonical hex string, a typed
220
- * object carrying that hex (`{ hex }`), or a decoded Clarity-JSON object.
221
- * Decode helpers (`decodeNftTransfer`, etc.) resolve it to a concrete value. */
222
- type StreamsClarityValue = string | {
223
- hex: string;
224
- } | Record<string, unknown>;
225
- type StxTransferPayload = {
226
- sender: string;
227
- recipient: string;
228
- amount: string;
229
- memo?: string;
230
- };
231
- type StxMintPayload = {
232
- recipient: string;
233
- amount: string;
234
- };
235
- type StxBurnPayload = {
236
- sender: string;
237
- amount: string;
238
- };
239
- type StxLockPayload = {
240
- locked_address: string;
241
- locked_amount: string;
242
- unlock_height: string;
243
- };
244
- type FtTransferPayload = {
245
- asset_identifier: string;
246
- sender: string;
247
- recipient: string;
248
- amount: string;
249
- };
250
- type FtMintPayload = {
251
- asset_identifier: string;
252
- recipient: string;
253
- amount: string;
254
- };
255
- type FtBurnPayload = {
256
- asset_identifier: string;
257
- sender: string;
258
- amount: string;
259
- };
260
- type NftTransferPayload = {
261
- asset_identifier: string;
262
- sender: string;
263
- recipient: string;
264
- value: StreamsClarityValue;
265
- /** Canonical serialized hex of `value`, when the stream carries it. */
266
- raw_value?: string;
267
- };
268
- type NftMintPayload = {
269
- asset_identifier: string;
270
- recipient: string;
271
- value: StreamsClarityValue;
272
- raw_value?: string;
273
- };
274
- type NftBurnPayload = {
275
- asset_identifier: string;
276
- sender: string;
277
- value: StreamsClarityValue;
278
- raw_value?: string;
279
- };
280
- type PrintPayload = {
281
- contract_id?: string | null;
282
- topic?: string;
283
- value?: unknown;
284
- raw_value?: string;
285
- };
286
- /** Union of every Streams payload shape, discriminated by `event_type` on the
287
- * parent `StreamsEvent`. */
288
- type StreamsEventPayload = StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | PrintPayload;
289
- type StreamsEventBase = {
290
- /**
291
- * Globally unique, monotonic position of this event (`<block>:<index>`). Use
292
- * it as the primary key of your projection rows — replaying a batch then
293
- * upserts cleanly. Don't synthesize your own id from `tx_id`/`event_index`.
294
- */
295
- cursor: string;
296
- block_height: number;
297
- block_hash: string;
298
- burn_block_height: number;
299
- tx_id: string;
300
- tx_index: number;
301
- event_index: number;
302
- contract_id: string | null;
303
- ts: string;
304
- /**
305
- * True when this event's block is past the finality boundary (immutable).
306
- * Optional for back-compat; the API always sets it on Streams responses.
307
- */
308
- finalized?: boolean;
309
- /**
310
- * Labels whose filter group this event satisfied, present only when the
311
- * request used a labelled `filters` map. The SDK dispatches on it for you
312
- * (`on.<label>`), so handlers rarely read it directly.
313
- */
314
- matched?: string[];
315
- };
316
- type StreamsEventOf<
317
- T extends StreamsEventType,
318
- P
319
- > = StreamsEventBase & {
320
- event_type: T;
321
- payload: P;
322
- };
323
- /** A raw Streams event. Discriminated on `event_type`, so `event.payload`
324
- * narrows to the matching payload shape once the type is checked. */
325
- type StreamsEvent = StreamsEventOf<"stx_transfer", StxTransferPayload> | StreamsEventOf<"stx_mint", StxMintPayload> | StreamsEventOf<"stx_burn", StxBurnPayload> | StreamsEventOf<"stx_lock", StxLockPayload> | StreamsEventOf<"ft_transfer", FtTransferPayload> | StreamsEventOf<"ft_mint", FtMintPayload> | StreamsEventOf<"ft_burn", FtBurnPayload> | StreamsEventOf<"nft_transfer", NftTransferPayload> | StreamsEventOf<"nft_mint", NftMintPayload> | StreamsEventOf<"nft_burn", NftBurnPayload> | StreamsEventOf<"print", PrintPayload>;
219
+ import { StreamsEventPayload } from "@secondlayer/shared/streams-rows";
326
220
  type StreamsTip = {
327
221
  block_height: number;
328
222
  block_hash: string;
@@ -819,20 +713,6 @@ type StreamsClient = {
819
713
  dumps: StreamsDumps;
820
714
  canonical(height: number): Promise<StreamsCanonicalBlock>;
821
715
  tip(): Promise<StreamsTip>;
822
- /** Your own Streams consumption (events today + this month) and tier limits. */
823
- usage(): Promise<StreamsUsage>;
824
- };
825
- type StreamsUsage = {
826
- product: "streams";
827
- tier: string;
828
- limits: {
829
- rate_limit_per_second: number | null;
830
- retention_days: number | null;
831
- };
832
- usage: {
833
- events_today: number;
834
- events_this_month: number;
835
- };
836
716
  };
837
717
  type CreateStreamsClientOptions = {
838
718
  apiKey: string;
@@ -893,7 +773,7 @@ declare function decode(event: StreamsEvent): IndexEvent;
893
773
  interface SecondLayerErrorOptions {
894
774
  cause?: Error;
895
775
  details?: string;
896
- /** Stable machine-readable code (e.g. `UPGRADE_REQUIRED`, `BYO_BREAKING_CHANGE`). */
776
+ /** Stable machine-readable code (e.g. `UPGRADE_REQUIRED`). */
897
777
  code?: string;
898
778
  /** Docs page that explains this failure and its fix. */
899
779
  docsUrl?: string;
@@ -908,10 +788,9 @@ interface SecondLayerErrorOptions {
908
788
  * Root of the SDK error family. Implements the same protocol as `BaseError`
909
789
  * in `@secondlayer/stacks` (`shortMessage`, `cause`, `toJSON`) so a failed
910
790
  * chain read and a failed platform read serialize and introspect identically.
911
- * It intentionally does NOT extend that class: `BaseError.details` is a
912
- * `string`, while {@link ByoBreakingChangeError.details} is the documented
913
- * structured migration plan — and cross-package `instanceof` is unreliable
914
- * under per-package bundling anyway (match on `code`/`name` across packages).
791
+ * It intentionally does NOT extend that class: cross-package `instanceof` is
792
+ * unreliable under per-package bundling anyway (match on `code`/`name` across
793
+ * packages).
915
794
  *
916
795
  * `retryable` is the signal the consume loops act on: 429/5xx/network are
917
796
  * retryable, 4xx and body-serialization failures are not.
@@ -990,255 +869,8 @@ declare class StreamsServerError extends ApiError {
990
869
  declare class StreamsSignatureError extends SecondLayerError {
991
870
  constructor(message?: string);
992
871
  }
993
- type FtTransferEvent = Extract<StreamsEvent, {
994
- event_type: "ft_transfer";
995
- }>;
996
- type DecodedFtTransferPayload = {
997
- asset_identifier: string;
998
- contract_id: string;
999
- token_name: string | null;
1000
- sender: string;
1001
- recipient: string;
1002
- amount: string;
1003
- };
1004
- type DecodedFtTransfer = {
1005
- cursor: string;
1006
- block_height: number;
1007
- tx_id: string;
1008
- tx_index: number;
1009
- event_index: number;
1010
- event_type: "ft_transfer";
1011
- decoded_payload: DecodedFtTransferPayload;
1012
- source_cursor: string;
1013
- };
1014
- declare function isFtTransfer(event: StreamsEvent): event is FtTransferEvent;
1015
- declare function decodeFtTransfer(event: StreamsEvent): DecodedFtTransfer;
1016
- type NftTransferEvent = Extract<StreamsEvent, {
1017
- event_type: "nft_transfer";
1018
- }>;
1019
- type DecodedNftTransferPayload = {
1020
- asset_identifier: string;
1021
- contract_id: string;
1022
- token_name: string | null;
1023
- sender: string;
1024
- recipient: string;
1025
- value: string;
1026
- };
1027
- type DecodedNftTransfer = {
1028
- cursor: string;
1029
- block_height: number;
1030
- tx_id: string;
1031
- tx_index: number;
1032
- event_index: number;
1033
- event_type: "nft_transfer";
1034
- decoded_payload: DecodedNftTransferPayload;
1035
- source_cursor: string;
1036
- };
1037
- declare function isNftTransfer(event: StreamsEvent): event is NftTransferEvent;
1038
- declare function decodeNftTransfer(event: StreamsEvent): DecodedNftTransfer;
1039
- type DecodedStxTransferPayload = {
1040
- sender: string;
1041
- recipient: string;
1042
- amount: string;
1043
- memo: string | null;
1044
- };
1045
- type DecodedStxTransfer = {
1046
- cursor: string;
1047
- block_height: number;
1048
- tx_id: string;
1049
- tx_index: number;
1050
- event_index: number;
1051
- event_type: "stx_transfer";
1052
- decoded_payload: DecodedStxTransferPayload;
1053
- source_cursor: string;
1054
- };
1055
- type DecodedStxMintPayload = {
1056
- recipient: string;
1057
- amount: string;
1058
- };
1059
- type DecodedStxMint = {
1060
- cursor: string;
1061
- block_height: number;
1062
- tx_id: string;
1063
- tx_index: number;
1064
- event_index: number;
1065
- event_type: "stx_mint";
1066
- decoded_payload: DecodedStxMintPayload;
1067
- source_cursor: string;
1068
- };
1069
- type DecodedStxBurnPayload = {
1070
- sender: string;
1071
- amount: string;
1072
- };
1073
- type DecodedStxBurn = {
1074
- cursor: string;
1075
- block_height: number;
1076
- tx_id: string;
1077
- tx_index: number;
1078
- event_index: number;
1079
- event_type: "stx_burn";
1080
- decoded_payload: DecodedStxBurnPayload;
1081
- source_cursor: string;
1082
- };
1083
- declare function isStxTransfer(event: StreamsEvent): event is StreamsEvent & {
1084
- event_type: "stx_transfer";
1085
- };
1086
- declare function decodeStxTransfer(event: StreamsEvent): DecodedStxTransfer;
1087
- declare function isStxMint(event: StreamsEvent): event is StreamsEvent & {
1088
- event_type: "stx_mint";
1089
- };
1090
- declare function decodeStxMint(event: StreamsEvent): DecodedStxMint;
1091
- declare function isStxBurn(event: StreamsEvent): event is StreamsEvent & {
1092
- event_type: "stx_burn";
1093
- };
1094
- declare function decodeStxBurn(event: StreamsEvent): DecodedStxBurn;
1095
- type DecodedStxLockPayload = {
1096
- sender: string;
1097
- amount: string;
1098
- payload: {
1099
- unlock_height: string | null;
1100
- };
1101
- };
1102
- type DecodedStxLock = {
1103
- cursor: string;
1104
- block_height: number;
1105
- tx_id: string;
1106
- tx_index: number;
1107
- event_index: number;
1108
- event_type: "stx_lock";
1109
- decoded_payload: DecodedStxLockPayload;
1110
- source_cursor: string;
1111
- };
1112
- declare function isStxLock(event: StreamsEvent): event is StreamsEvent & {
1113
- event_type: "stx_lock";
1114
- };
1115
- declare function decodeStxLock(event: StreamsEvent): DecodedStxLock;
1116
- type DecodedFtMintPayload = {
1117
- asset_identifier: string;
1118
- contract_id: string;
1119
- token_name: string | null;
1120
- recipient: string;
1121
- amount: string;
1122
- };
1123
- type DecodedFtMint = {
1124
- cursor: string;
1125
- block_height: number;
1126
- tx_id: string;
1127
- tx_index: number;
1128
- event_index: number;
1129
- event_type: "ft_mint";
1130
- decoded_payload: DecodedFtMintPayload;
1131
- source_cursor: string;
1132
- };
1133
- type DecodedFtBurnPayload = {
1134
- asset_identifier: string;
1135
- contract_id: string;
1136
- token_name: string | null;
1137
- sender: string;
1138
- amount: string;
1139
- };
1140
- type DecodedFtBurn = {
1141
- cursor: string;
1142
- block_height: number;
1143
- tx_id: string;
1144
- tx_index: number;
1145
- event_index: number;
1146
- event_type: "ft_burn";
1147
- decoded_payload: DecodedFtBurnPayload;
1148
- source_cursor: string;
1149
- };
1150
- type DecodedNftMintPayload = {
1151
- asset_identifier: string;
1152
- contract_id: string;
1153
- token_name: string | null;
1154
- recipient: string;
1155
- value: string;
1156
- };
1157
- type DecodedNftMint = {
1158
- cursor: string;
1159
- block_height: number;
1160
- tx_id: string;
1161
- tx_index: number;
1162
- event_index: number;
1163
- event_type: "nft_mint";
1164
- decoded_payload: DecodedNftMintPayload;
1165
- source_cursor: string;
1166
- };
1167
- type DecodedNftBurnPayload = {
1168
- asset_identifier: string;
1169
- contract_id: string;
1170
- token_name: string | null;
1171
- sender: string;
1172
- value: string;
1173
- };
1174
- type DecodedNftBurn = {
1175
- cursor: string;
1176
- block_height: number;
1177
- tx_id: string;
1178
- tx_index: number;
1179
- event_index: number;
1180
- event_type: "nft_burn";
1181
- decoded_payload: DecodedNftBurnPayload;
1182
- source_cursor: string;
1183
- };
1184
- declare function isFtMint(event: StreamsEvent): event is StreamsEvent & {
1185
- event_type: "ft_mint";
1186
- };
1187
- declare function decodeFtMint(event: StreamsEvent): DecodedFtMint;
1188
- declare function isFtBurn(event: StreamsEvent): event is StreamsEvent & {
1189
- event_type: "ft_burn";
1190
- };
1191
- declare function decodeFtBurn(event: StreamsEvent): DecodedFtBurn;
1192
- declare function isNftMint(event: StreamsEvent): event is StreamsEvent & {
1193
- event_type: "nft_mint";
1194
- };
1195
- declare function decodeNftMint(event: StreamsEvent): DecodedNftMint;
1196
- declare function isNftBurn(event: StreamsEvent): event is StreamsEvent & {
1197
- event_type: "nft_burn";
1198
- };
1199
- declare function decodeNftBurn(event: StreamsEvent): DecodedNftBurn;
1200
- /** Decoded form of a Clarity `print` event:
1201
- * - `topic`: the print topic, when the contract emits a `{ topic, ... }` tuple
1202
- * - `value`: the Clarity value decoded to JSON (uints as strings, buffers as
1203
- * `0x…` hex, tuples as objects)
1204
- * - `raw_value`: the canonical serialized hex, for byte-exact consumers */
1205
- type DecodedPrintValue = {
1206
- topic: string | null;
1207
- value: unknown;
1208
- raw_value: string | null;
1209
- };
1210
- type DecodedPrintPayload = {
1211
- contract_id: string | null;
1212
- payload: DecodedPrintValue;
1213
- };
1214
- type DecodedPrint = {
1215
- cursor: string;
1216
- block_height: number;
1217
- tx_id: string;
1218
- tx_index: number;
1219
- event_index: number;
1220
- event_type: "print";
1221
- decoded_payload: DecodedPrintPayload;
1222
- source_cursor: string;
1223
- };
1224
- declare function isPrint(event: StreamsEvent): event is StreamsEvent & {
1225
- event_type: "print";
1226
- };
1227
- declare function decodePrint(event: StreamsEvent): DecodedPrint;
1228
- /** Superset of the columns the decoded_events table holds. Every decoded
1229
- * event's `decoded_payload` is assignable to this, so the indexer's writer
1230
- * can map columns generically instead of per-event-type. */
1231
- type DecodedEventColumns = {
1232
- contract_id?: string | null;
1233
- asset_identifier?: string | null;
1234
- sender?: string | null;
1235
- recipient?: string | null;
1236
- amount?: string | null;
1237
- value?: string | null;
1238
- memo?: string | null;
1239
- /** JSONB overflow for non-flat types (e.g. print's decoded value). */
1240
- payload?: unknown;
1241
- };
872
+ import { decodeFtTransfer, isFtTransfer, decodeNftTransfer, isNftTransfer, decodeStxBurn, decodeStxLock, decodeStxMint, decodeStxTransfer, isStxBurn, isStxLock, isStxMint, isStxTransfer, decodeFtBurn, decodeFtMint, decodeNftBurn, decodeNftMint, isFtBurn, isFtMint, isNftBurn, isNftMint, decodePrint, isPrint } from "@secondlayer/shared/streams-rows";
873
+ import { DecodedEventColumns, DecodedEventRow, DecodedFtBurn, DecodedFtBurnPayload, DecodedFtMint, DecodedFtMintPayload, DecodedFtTransfer, DecodedFtTransferPayload, DecodedNftBurn, DecodedNftBurnPayload, DecodedNftMint, DecodedNftMintPayload, DecodedNftTransfer, DecodedNftTransferPayload, DecodedPrint, DecodedPrintPayload, DecodedPrintValue, DecodedStxBurn, DecodedStxBurnPayload, DecodedStxLock, DecodedStxLockPayload, DecodedStxMint, DecodedStxMintPayload, DecodedStxTransfer, DecodedStxTransferPayload, FtTransferEvent, FtTransferPayload as FtTransferPayload2, NftTransferEvent, NftTransferPayload as NftTransferPayload2 } from "@secondlayer/shared/streams-rows";
1242
874
  /**
1243
875
  * Helpers for Streams cursors. A cursor is the opaque `<block>:<index>` string
1244
876
  * that marks a position in the event stream; treat the format as an
@@ -1269,5 +901,4 @@ declare const Cursor: {
1269
901
  eventIndex: number;
1270
902
  };
1271
903
  };
1272
- type DecodedEventRow = DecodedFtTransfer | DecodedNftTransfer | DecodedStxTransfer | DecodedStxMint | DecodedStxBurn | DecodedStxLock | DecodedFtMint | DecodedFtBurn | DecodedNftMint | DecodedNftBurn | DecodedPrint;
1273
- export { isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decode, createStreamsClient, ValidationError, 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, STREAMS_EVENT_TYPES, RateLimitError, NftTransferPayload, NftTransferEvent, FtTransferPayload, FtTransferEvent, FetchLike2 as FetchLike, 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, Cursor, ConsumerBatchContext, AuthError };
904
+ export { isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decode, createStreamsClient, ValidationError, 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, STREAMS_EVENT_TYPES, RateLimitError, NftTransferPayload2 as NftTransferPayload, NftTransferEvent, FtTransferPayload2 as FtTransferPayload, FtTransferEvent, FetchLike2 as FetchLike, 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, Cursor, ConsumerBatchContext, AuthError };