@secondlayer/sdk 6.38.0 → 6.40.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 +107 -6
- package/dist/index.js +67 -36
- package/dist/index.js.map +7 -7
- package/dist/streams/index.d.ts +69 -3
- package/dist/streams/index.js +65 -35
- package/dist/streams/index.js.map +6 -6
- package/dist/subgraphs/index.d.ts +106 -5
- package/dist/subgraphs/index.js +67 -36
- package/dist/subgraphs/index.js.map +6 -6
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -509,6 +509,12 @@ type StreamsEventBase = {
|
|
|
509
509
|
* Optional for back-compat; the API always sets it on Streams responses.
|
|
510
510
|
*/
|
|
511
511
|
finalized?: boolean
|
|
512
|
+
/**
|
|
513
|
+
* Labels whose filter group this event satisfied, present only when the
|
|
514
|
+
* request used a labelled `filters` map. The SDK dispatches on it for you
|
|
515
|
+
* (`on.<label>`), so handlers rarely read it directly.
|
|
516
|
+
*/
|
|
517
|
+
matched?: string[]
|
|
512
518
|
};
|
|
513
519
|
type StreamsEventOf<
|
|
514
520
|
T extends StreamsEventType,
|
|
@@ -578,6 +584,34 @@ type StreamsReorgsListEnvelope = {
|
|
|
578
584
|
};
|
|
579
585
|
/** A filter that matches a single value or any value in a list. */
|
|
580
586
|
type StreamsFilterValue = string | readonly string[];
|
|
587
|
+
/**
|
|
588
|
+
* One labelled filter group. Fields inside a group AND together; groups in a
|
|
589
|
+
* map OR together server-side.
|
|
590
|
+
*/
|
|
591
|
+
type StreamsLabelledFilter = {
|
|
592
|
+
types?: readonly StreamsEventType[]
|
|
593
|
+
contractId?: StreamsFilterValue
|
|
594
|
+
sender?: StreamsFilterValue
|
|
595
|
+
recipient?: StreamsFilterValue
|
|
596
|
+
assetIdentifier?: string
|
|
597
|
+
};
|
|
598
|
+
/** A map of label → filter group. Labels are yours; the server echoes them. */
|
|
599
|
+
type StreamsFilterMap = Record<string, StreamsLabelledFilter>;
|
|
600
|
+
/**
|
|
601
|
+
* The events one label can yield. A group that declares `types` narrows to
|
|
602
|
+
* exactly those variants, so a per-label handler needs no `event_type` guard;
|
|
603
|
+
* a group without `types` keeps the full union.
|
|
604
|
+
*/
|
|
605
|
+
type StreamsEventForFilter<
|
|
606
|
+
F,
|
|
607
|
+
D extends boolean = false
|
|
608
|
+
> = F extends {
|
|
609
|
+
types: readonly (infer T extends StreamsEventType)[]
|
|
610
|
+
} ? D extends true ? Extract<IndexEvent, {
|
|
611
|
+
event_type: T
|
|
612
|
+
}> : Extract<StreamsEvent, {
|
|
613
|
+
event_type: T
|
|
614
|
+
}> : D extends true ? IndexEvent : StreamsEvent;
|
|
581
615
|
type StreamsEventsListParams = {
|
|
582
616
|
cursor?: string | null
|
|
583
617
|
fromHeight?: number
|
|
@@ -589,6 +623,12 @@ type StreamsEventsListParams = {
|
|
|
589
623
|
sender?: StreamsFilterValue
|
|
590
624
|
recipient?: StreamsFilterValue
|
|
591
625
|
assetIdentifier?: string
|
|
626
|
+
/**
|
|
627
|
+
* Labelled filter groups. The groups OR together in one scan and each
|
|
628
|
+
* returned event carries the labels it matched (`event.matched`) — two
|
|
629
|
+
* unrelated concerns share one page, one cursor, one checkpoint.
|
|
630
|
+
*/
|
|
631
|
+
filters?: StreamsFilterMap
|
|
592
632
|
limit?: number
|
|
593
633
|
};
|
|
594
634
|
type StreamsEventsStreamParams = {
|
|
@@ -599,6 +639,8 @@ type StreamsEventsStreamParams = {
|
|
|
599
639
|
sender?: StreamsFilterValue
|
|
600
640
|
recipient?: StreamsFilterValue
|
|
601
641
|
assetIdentifier?: string
|
|
642
|
+
/** Labelled filter groups; see {@link StreamsEventsListParams.filters}. */
|
|
643
|
+
filters?: StreamsFilterMap
|
|
602
644
|
batchSize?: number
|
|
603
645
|
emptyBackoffMs?: number
|
|
604
646
|
maxPages?: number
|
|
@@ -614,6 +656,8 @@ type StreamsEventsSubscribeParams = {
|
|
|
614
656
|
sender?: StreamsFilterValue
|
|
615
657
|
recipient?: StreamsFilterValue
|
|
616
658
|
assetIdentifier?: string
|
|
659
|
+
/** Labelled filter groups; see {@link StreamsEventsListParams.filters}. */
|
|
660
|
+
filters?: StreamsFilterMap
|
|
617
661
|
/** Abort to unsubscribe (the returned function does the same). */
|
|
618
662
|
signal?: AbortSignal
|
|
619
663
|
/** Called for each pushed event, in order. */
|
|
@@ -665,7 +709,8 @@ type StreamsReorgContext = {
|
|
|
665
709
|
};
|
|
666
710
|
type StreamsEventsConsumeParams<
|
|
667
711
|
TTx = never,
|
|
668
|
-
D extends boolean = false
|
|
712
|
+
D extends boolean = false,
|
|
713
|
+
F extends StreamsFilterMap = Record<never, never>
|
|
669
714
|
> = {
|
|
670
715
|
fromCursor?: string | null
|
|
671
716
|
/**
|
|
@@ -699,13 +744,33 @@ type StreamsEventsConsumeParams<
|
|
|
699
744
|
sender?: StreamsFilterValue
|
|
700
745
|
recipient?: StreamsFilterValue
|
|
701
746
|
assetIdentifier?: string
|
|
747
|
+
/**
|
|
748
|
+
* Labelled filter groups. The groups OR together in ONE server-side scan,
|
|
749
|
+
* so two unrelated concerns share one page, one cursor, and one checkpoint
|
|
750
|
+
* instead of two consume loops. Pair with `on` to handle each label.
|
|
751
|
+
*/
|
|
752
|
+
filters?: F
|
|
753
|
+
/**
|
|
754
|
+
* One handler per label in `filters`. Every label must be handled, so
|
|
755
|
+
* adding a label is a compile error until its handler exists.
|
|
756
|
+
*
|
|
757
|
+
* A label's declared `types` narrows its handler's events, so `payload` is
|
|
758
|
+
* typed without an `event_type` guard. Labels are dispatched in declaration
|
|
759
|
+
* order: a label's own events stay in cursor order, but events of different
|
|
760
|
+
* labels do not interleave within a page — add `onBatch` when you need
|
|
761
|
+
* strict global order across labels.
|
|
762
|
+
*/
|
|
763
|
+
on?: { [K in keyof F] : (events: StreamsEventForFilter<F[K], D>[], ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | Promise<void> }
|
|
702
764
|
batchSize?: number
|
|
703
765
|
/**
|
|
704
766
|
* Apply a page of canonical events. Persist `ctx.cursor` in the same
|
|
705
767
|
* transaction as your writes. Returning a cursor overrides `ctx.cursor` as
|
|
706
768
|
* the resume point (advanced manual control); returning nothing uses it.
|
|
769
|
+
*
|
|
770
|
+
* Optional only when `on` handles the page instead; a consume call with
|
|
771
|
+
* neither throws.
|
|
707
772
|
*/
|
|
708
|
-
onBatch
|
|
773
|
+
onBatch?: (events: D extends true ? IndexEvent[] : StreamsEvent[], envelope: StreamsEventsEnvelope, ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
709
774
|
/**
|
|
710
775
|
* Roll your projection back to `reorg.fork_point_height`, persisting
|
|
711
776
|
* `ctx.cursor` in the same transaction. Called once per *new* reorg
|
|
@@ -864,9 +929,10 @@ type StreamsClient = {
|
|
|
864
929
|
* stops it.
|
|
865
930
|
*/
|
|
866
931
|
consume<
|
|
932
|
+
const F extends StreamsFilterMap = Record<never, never>,
|
|
867
933
|
TTx = never,
|
|
868
934
|
D extends boolean = false
|
|
869
|
-
>(params: StreamsEventsConsumeParams<TTx, D> & {
|
|
935
|
+
>(params: StreamsEventsConsumeParams<TTx, D, F> & {
|
|
870
936
|
sink?: ConsumerSink<TTx>
|
|
871
937
|
}): Promise<StreamsEventsConsumeResult>
|
|
872
938
|
/**
|
|
@@ -1241,8 +1307,19 @@ type IndexPrint = IndexEventBase & {
|
|
|
1241
1307
|
/** Decoded chain event, discriminated by `event_type`. */
|
|
1242
1308
|
type IndexEvent = IndexFtTransfer | IndexNftTransfer | IndexStxTransfer | IndexStxMint | IndexStxBurn | IndexStxLock | IndexFtMint | IndexFtBurn | IndexNftMint | IndexNftBurn | IndexPrint;
|
|
1243
1309
|
type IndexEventType = IndexEvent["event_type"];
|
|
1244
|
-
|
|
1245
|
-
|
|
1310
|
+
/** Fields every read returns regardless of `fields` — the consume contract
|
|
1311
|
+
* (`cursor`, `block_height`) plus the union discriminant. */
|
|
1312
|
+
type IndexAlwaysFields = "cursor" | "block_height" | "event_type";
|
|
1313
|
+
/** An event row narrowed to a `fields` selection (plus what always ships). */
|
|
1314
|
+
type IndexEventFields<
|
|
1315
|
+
T extends IndexEventType,
|
|
1316
|
+
F extends keyof IndexEventOf<T> & string
|
|
1317
|
+
> = Pick<IndexEventOf<T>, (F | IndexAlwaysFields) & keyof IndexEventOf<T>>;
|
|
1318
|
+
type EventsEnvelope<
|
|
1319
|
+
T extends IndexEventType = IndexEventType,
|
|
1320
|
+
TRow = IndexEventOf<T>
|
|
1321
|
+
> = {
|
|
1322
|
+
events: TRow[]
|
|
1246
1323
|
next_cursor: string | null
|
|
1247
1324
|
tip: IndexTip
|
|
1248
1325
|
reorgs: IndexReorg[]
|
|
@@ -1275,6 +1352,21 @@ type EventsListParams<T extends IndexEventType = IndexEventType> = {
|
|
|
1275
1352
|
* Avoids a `/v1/index/transactions` call per event; for `print` events it's
|
|
1276
1353
|
* the only source of the submitting sender. */
|
|
1277
1354
|
txContext?: boolean
|
|
1355
|
+
/**
|
|
1356
|
+
* Return only these columns. The server projects the SELECT, so an
|
|
1357
|
+
* unrequested field is physically absent — and the returned row type
|
|
1358
|
+
* narrows to match, making a read of one a compile error rather than
|
|
1359
|
+
* `undefined`.
|
|
1360
|
+
*
|
|
1361
|
+
* `cursor`, `block_height`, and `event_type` come back regardless: the
|
|
1362
|
+
* first two are the consume contract, the third carries the discriminant.
|
|
1363
|
+
* Don't list them.
|
|
1364
|
+
*
|
|
1365
|
+
* Cost note: this does NOT change your bill — Index meters per row read,
|
|
1366
|
+
* not per field. What it buys is wire bytes, plus skipping the `blocks`
|
|
1367
|
+
* join when `block_time` is omitted.
|
|
1368
|
+
*/
|
|
1369
|
+
fields?: readonly (keyof IndexEventOf<T> & string)[]
|
|
1278
1370
|
};
|
|
1279
1371
|
type EventsWalkParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "limit"> & {
|
|
1280
1372
|
batchSize?: number
|
|
@@ -1975,6 +2067,15 @@ interface NftTransfersResource {
|
|
|
1975
2067
|
/** `index.events` — callable shorthand for `.list()`; `eventType` is required. */
|
|
1976
2068
|
interface IndexEventsResource {
|
|
1977
2069
|
<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
2070
|
+
/** Narrowing overload: `fields` shrinks the returned row type to exactly
|
|
2071
|
+
* the requested columns plus {@link IndexAlwaysFields}. `const F` means no
|
|
2072
|
+
* `as const` at the call site. */
|
|
2073
|
+
list<
|
|
2074
|
+
T extends IndexEventType,
|
|
2075
|
+
const F extends keyof IndexEventOf<T> & string
|
|
2076
|
+
>(params: EventsListParams<T> & {
|
|
2077
|
+
fields: readonly F[]
|
|
2078
|
+
}): Promise<EventsEnvelope<T, IndexEventFields<T, F>>>;
|
|
1978
2079
|
list<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1979
2080
|
walk<T extends IndexEventType>(params: EventsWalkParams<T>): AsyncIterable<IndexEventOf<T>>;
|
|
1980
2081
|
consume<
|
|
@@ -3152,4 +3253,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
3152
3253
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
3153
3254
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
3154
3255
|
declare function decodeClarityValue(hex: string): unknown;
|
|
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 };
|
|
3256
|
+
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, IndexEventFields, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, IndexAlwaysFields, 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 };
|
package/dist/index.js
CHANGED
|
@@ -669,7 +669,8 @@ async function consumeStreamsEvents(opts) {
|
|
|
669
669
|
contractId: opts.contractId,
|
|
670
670
|
sender: opts.sender,
|
|
671
671
|
recipient: opts.recipient,
|
|
672
|
-
assetIdentifier: opts.assetIdentifier
|
|
672
|
+
assetIdentifier: opts.assetIdentifier,
|
|
673
|
+
filters: opts.filters
|
|
673
674
|
}), {
|
|
674
675
|
retryCount: opts.retryCount,
|
|
675
676
|
retryDelay: opts.retryDelay,
|
|
@@ -746,7 +747,8 @@ async function* iterateStreamsBatches(opts) {
|
|
|
746
747
|
contractId: opts.contractId,
|
|
747
748
|
sender: opts.sender,
|
|
748
749
|
recipient: opts.recipient,
|
|
749
|
-
assetIdentifier: opts.assetIdentifier
|
|
750
|
+
assetIdentifier: opts.assetIdentifier,
|
|
751
|
+
filters: opts.filters
|
|
750
752
|
});
|
|
751
753
|
const checkpoint = envelope.next_cursor ?? cursor;
|
|
752
754
|
if (envelope.events.length > 0 || envelope.reorgs.length > 0) {
|
|
@@ -783,7 +785,8 @@ async function* streamStreamsEvents(opts) {
|
|
|
783
785
|
contractId: opts.contractId,
|
|
784
786
|
sender: opts.sender,
|
|
785
787
|
recipient: opts.recipient,
|
|
786
|
-
assetIdentifier: opts.assetIdentifier
|
|
788
|
+
assetIdentifier: opts.assetIdentifier,
|
|
789
|
+
filters: opts.filters
|
|
787
790
|
});
|
|
788
791
|
pages++;
|
|
789
792
|
for (const event of envelope.events) {
|
|
@@ -1113,7 +1116,8 @@ class Index extends BaseClient {
|
|
|
1113
1116
|
from_height: params.fromHeight,
|
|
1114
1117
|
to_height: params.toHeight,
|
|
1115
1118
|
trait: params.trait,
|
|
1116
|
-
tx_context: params.txContext ? "true" : undefined
|
|
1119
|
+
tx_context: params.txContext ? "true" : undefined,
|
|
1120
|
+
fields: params.fields?.join(",")
|
|
1117
1121
|
})}`);
|
|
1118
1122
|
}
|
|
1119
1123
|
walkEvents(params) {
|
|
@@ -1597,7 +1601,8 @@ function subscribeStreamsEvents(opts) {
|
|
|
1597
1601
|
contract_id: params.contractId,
|
|
1598
1602
|
sender: params.sender,
|
|
1599
1603
|
recipient: params.recipient,
|
|
1600
|
-
asset_identifier: params.assetIdentifier
|
|
1604
|
+
asset_identifier: params.assetIdentifier,
|
|
1605
|
+
filters: params.filters ? JSON.stringify(params.filters) : undefined
|
|
1601
1606
|
})}`;
|
|
1602
1607
|
const res = await opts.fetchImpl(url, {
|
|
1603
1608
|
headers: {
|
|
@@ -1841,7 +1846,8 @@ function createStreamsClient(options) {
|
|
|
1841
1846
|
contractId,
|
|
1842
1847
|
sender,
|
|
1843
1848
|
recipient,
|
|
1844
|
-
assetIdentifier
|
|
1849
|
+
assetIdentifier,
|
|
1850
|
+
filters
|
|
1845
1851
|
}) => {
|
|
1846
1852
|
return listEvents({
|
|
1847
1853
|
cursor,
|
|
@@ -1851,9 +1857,13 @@ function createStreamsClient(options) {
|
|
|
1851
1857
|
contractId,
|
|
1852
1858
|
sender,
|
|
1853
1859
|
recipient,
|
|
1854
|
-
assetIdentifier
|
|
1860
|
+
assetIdentifier,
|
|
1861
|
+
filters
|
|
1855
1862
|
});
|
|
1856
1863
|
};
|
|
1864
|
+
function encodeFilters(filters) {
|
|
1865
|
+
return filters ? JSON.stringify(filters) : undefined;
|
|
1866
|
+
}
|
|
1857
1867
|
async function listEvents(params = {}) {
|
|
1858
1868
|
return request(`/v1/streams/events${buildQuery({
|
|
1859
1869
|
cursor: params.cursor,
|
|
@@ -1865,9 +1875,56 @@ function createStreamsClient(options) {
|
|
|
1865
1875
|
recipient: params.recipient,
|
|
1866
1876
|
asset_identifier: params.assetIdentifier,
|
|
1867
1877
|
types: params.types,
|
|
1868
|
-
not_types: params.notTypes
|
|
1878
|
+
not_types: params.notTypes,
|
|
1879
|
+
filters: encodeFilters(params.filters)
|
|
1869
1880
|
})}`);
|
|
1870
1881
|
}
|
|
1882
|
+
function consumeEvents(params) {
|
|
1883
|
+
const labels = params.filters ? Object.keys(params.filters) : [];
|
|
1884
|
+
if (labels.length === 0 && !params.onBatch) {
|
|
1885
|
+
throw new ValidationError("consume requires onBatch, or filters + on handlers.", 400);
|
|
1886
|
+
}
|
|
1887
|
+
if (labels.length > 0 && !params.on && !params.onBatch) {
|
|
1888
|
+
throw new ValidationError("consume with filters requires on handlers (or onBatch).", 400);
|
|
1889
|
+
}
|
|
1890
|
+
const dispatch = params.on;
|
|
1891
|
+
const project = (events) => params.decoded ? events.map(decode) : events;
|
|
1892
|
+
const onBatch = async (events, envelope, ctx) => {
|
|
1893
|
+
for (const label of labels) {
|
|
1894
|
+
const forLabel = events.filter((event) => event.matched?.includes(label));
|
|
1895
|
+
if (forLabel.length === 0)
|
|
1896
|
+
continue;
|
|
1897
|
+
await dispatch?.[label]?.(project(forLabel), ctx);
|
|
1898
|
+
}
|
|
1899
|
+
const userOnBatch = params.onBatch;
|
|
1900
|
+
return await userOnBatch?.(project(events), envelope, ctx);
|
|
1901
|
+
};
|
|
1902
|
+
return consumeStreamsEvents({
|
|
1903
|
+
fromCursor: params.fromCursor,
|
|
1904
|
+
sink: params.sink,
|
|
1905
|
+
onProgress: params.onProgress,
|
|
1906
|
+
mode: params.mode,
|
|
1907
|
+
finalizedOnly: params.finalizedOnly,
|
|
1908
|
+
types: params.types,
|
|
1909
|
+
notTypes: params.notTypes,
|
|
1910
|
+
contractId: params.contractId,
|
|
1911
|
+
sender: params.sender,
|
|
1912
|
+
recipient: params.recipient,
|
|
1913
|
+
assetIdentifier: params.assetIdentifier,
|
|
1914
|
+
filters: params.filters,
|
|
1915
|
+
batchSize: params.batchSize ?? 100,
|
|
1916
|
+
fetchEvents,
|
|
1917
|
+
onBatch,
|
|
1918
|
+
onReorg: params.onReorg,
|
|
1919
|
+
emptyBackoffMs: params.emptyBackoffMs,
|
|
1920
|
+
maxPages: params.maxPages,
|
|
1921
|
+
maxEmptyPolls: params.maxEmptyPolls,
|
|
1922
|
+
signal: params.signal,
|
|
1923
|
+
retryCount: params.retryCount,
|
|
1924
|
+
retryDelay: params.retryDelay,
|
|
1925
|
+
onError: params.onError
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1871
1928
|
return {
|
|
1872
1929
|
consume(params = {}) {
|
|
1873
1930
|
return iterateStreamsBatches({
|
|
@@ -1889,33 +1946,7 @@ function createStreamsClient(options) {
|
|
|
1889
1946
|
byTxId(txId) {
|
|
1890
1947
|
return request(`/v1/streams/events/${encodeURIComponent(txId)}`);
|
|
1891
1948
|
},
|
|
1892
|
-
consume
|
|
1893
|
-
const onBatch = params.decoded ? (events, envelope, ctx) => params.onBatch(events.map(decode), envelope, ctx) : params.onBatch;
|
|
1894
|
-
return consumeStreamsEvents({
|
|
1895
|
-
fromCursor: params.fromCursor,
|
|
1896
|
-
sink: params.sink,
|
|
1897
|
-
onProgress: params.onProgress,
|
|
1898
|
-
mode: params.mode,
|
|
1899
|
-
finalizedOnly: params.finalizedOnly,
|
|
1900
|
-
types: params.types,
|
|
1901
|
-
notTypes: params.notTypes,
|
|
1902
|
-
contractId: params.contractId,
|
|
1903
|
-
sender: params.sender,
|
|
1904
|
-
recipient: params.recipient,
|
|
1905
|
-
assetIdentifier: params.assetIdentifier,
|
|
1906
|
-
batchSize: params.batchSize ?? 100,
|
|
1907
|
-
fetchEvents,
|
|
1908
|
-
onBatch,
|
|
1909
|
-
onReorg: params.onReorg,
|
|
1910
|
-
emptyBackoffMs: params.emptyBackoffMs,
|
|
1911
|
-
maxPages: params.maxPages,
|
|
1912
|
-
maxEmptyPolls: params.maxEmptyPolls,
|
|
1913
|
-
signal: params.signal,
|
|
1914
|
-
retryCount: params.retryCount,
|
|
1915
|
-
retryDelay: params.retryDelay,
|
|
1916
|
-
onError: params.onError
|
|
1917
|
-
});
|
|
1918
|
-
},
|
|
1949
|
+
consume: consumeEvents,
|
|
1919
1950
|
stream(params = {}) {
|
|
1920
1951
|
return streamStreamsEvents({
|
|
1921
1952
|
fromCursor: params.fromCursor,
|
|
@@ -2844,5 +2875,5 @@ export {
|
|
|
2844
2875
|
ApiError
|
|
2845
2876
|
};
|
|
2846
2877
|
|
|
2847
|
-
//# debugId=
|
|
2878
|
+
//# debugId=0D258137688545B064756E2164756E21
|
|
2848
2879
|
//# sourceMappingURL=index.js.map
|