@secondlayer/sdk 15.5.2 → 16.1.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/AGENTS.md CHANGED
@@ -96,7 +96,7 @@ import { kyselySink } from "@secondlayer/sdk/sinks/kysely";
96
96
 
97
97
  await sl.streams.events.consume({
98
98
  sink: kyselySink(db, { id: "my-indexer", tables: ["transfers"], height: "height" }),
99
- onBatch: async (events, _envelope, ctx) => {
99
+ onBatch: async (events, ctx) => {
100
100
  for (const e of events) await ctx.tx.insertInto("transfers").values(...).execute();
101
101
  },
102
102
  });
package/README.md CHANGED
@@ -15,13 +15,13 @@ import { SecondLayer } from "@secondlayer/sdk";
15
15
 
16
16
  const sl = new SecondLayer({
17
17
  apiKey: process.env.INSTANCE_TOKEN, // from secondlayer init; read from the env when omitted
18
- // default baseUrl: http://127.0.0.1:3800 (or SECONDLAYER_API_URL)
18
+ // default baseUrl: SECONDLAYER_API_URL, else http://127.0.0.1:3800
19
19
  });
20
20
  ```
21
21
 
22
- Hosted: point the client at `https://api.secondlayer.tools` (`SECONDLAYER_API_URL`)
23
- and it sends `SECONDLAYER_API_KEY` (`sk-sl_*`) automatically. Self-host: use
24
- `INSTANCE_TOKEN` as below. The key follows the host.
22
+ Hosted: set `SECONDLAYER_API_KEY` (`sk-sl_*`) and the client uses
23
+ `https://api.secondlayer.tools`. Self-host: use `INSTANCE_TOKEN` as below, which
24
+ keeps the client on your instance even with an account key set. The key follows the host.
25
25
 
26
26
  Auth, once (self-hosted instance): `sl.index`, `sl.streams`, `sl.subgraphs.rows`, and the typed
27
27
  `subscribe` read `/v1`, which is open on loopback and needs `INSTANCE_TOKEN`
@@ -114,11 +114,11 @@ await streams.events.consume({
114
114
  types: ["ft_transfer"],
115
115
  batchSize: 100,
116
116
  maxPages: 1,
117
- onBatch: async (events, envelope) => {
117
+ onBatch: async (events, ctx) => {
118
118
  for (const event of events) {
119
119
  console.log(event.cursor, event.tx_id);
120
120
  }
121
- return envelope.next_cursor;
121
+ return ctx.cursor;
122
122
  },
123
123
  });
124
124
  ```
@@ -231,9 +231,9 @@ await streams.events.replay({
231
231
  const bytes = await streams.dumps.download(file);
232
232
  await ingestParquet(bytes, { skipAtOrBelow: from }); // your tooling
233
233
  },
234
- async onBatch(events, envelope) {
234
+ async onBatch(events, ctx) {
235
235
  for (const event of events) await handle(event);
236
- return envelope.next_cursor;
236
+ return ctx.cursor;
237
237
  },
238
238
  });
239
239
  ```
@@ -272,7 +272,7 @@ for (const item of fetched.urls) {
272
272
  Decoder helper.
273
273
 
274
274
  ```typescript
275
- import { decodeFtTransfer, isFtTransfer } from "@secondlayer/sdk";
275
+ import { decodeFtTransfer, isFtTransfer } from "@secondlayer/sdk/streams/rows";
276
276
 
277
277
  for await (const event of streams.events.stream({ types: ["ft_transfer"] })) {
278
278
  if (!isFtTransfer(event)) continue;
@@ -333,7 +333,7 @@ await sl.index.contractCalls.consume({
333
333
  functionName: "purchase-asset",
334
334
  fromCursor: await loadCheckpoint(), // null on first run
335
335
  fromHeight: 0, // first run: backfill from genesis
336
- onBatch: async (calls, envelope, ctx) => {
336
+ onBatch: async (calls, ctx) => {
337
337
  await commitRowsAndCheckpoint(calls, ctx.cursor);
338
338
  return ctx.cursor;
339
339
  },
@@ -585,7 +585,7 @@ Every delivery, any `format`, also carries a universal authenticity
585
585
  signature you can verify with one published key, no per-webhook secret. The
586
586
  headers are `webhook-id`, `x-secondlayer-signature`, and
587
587
  `x-secondlayer-signature-keyid`; the signed content is `` `${webhook-id}.${rawBody}` ``
588
- (ed25519). Fetch the public key from `GET /public/streams/signing-key`.
588
+ (ed25519). Fetch the public key from `GET /api/webhooks/signing-key`, which takes your account key.
589
589
 
590
590
  ```typescript
591
591
  import { verifySecondlayerSignature } from "@secondlayer/sdk";
package/dist/index.d.ts CHANGED
@@ -298,8 +298,8 @@ type RequestOptions = {
298
298
  * signal's reason, an `AbortError` by default, never an `ApiError`. */
299
299
  signal?: AbortSignal;
300
300
  };
301
- /** Product default: the local one-box API. Override with `baseUrl` or
302
- * `SECONDLAYER_API_URL`. */
301
+ /** Default when nothing points at the hosted API: the local one-box API.
302
+ * Override with `baseUrl` or `SECONDLAYER_API_URL`. */
303
303
  declare const LOCAL_API_URL = "http://127.0.0.1:3800";
304
304
  /** Instance credential. `secondlayer init` writes this. */
305
305
  declare const INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
@@ -941,10 +941,7 @@ type ConsumerBatchContext<
941
941
  blocksBehind: number | null;
942
942
  /**
943
943
  * The full tip for this page — `StreamsTip` or `IndexTip` depending on the
944
- * surface. Exposed here so a handler never needs the `envelope` parameter,
945
- * which is the only way to reach it today and is also how the worst
946
- * `finalizedOnly` mistake becomes reachable (`return envelope.next_cursor`
947
- * jumps the cursor past events that were filtered out and never delivered).
944
+ * surface.
948
945
  */
949
946
  tip: TTip;
950
947
  /**
@@ -953,9 +950,6 @@ type ConsumerBatchContext<
953
950
  */
954
951
  reorgs: readonly TReorg[];
955
952
  };
956
- /** @deprecated Use {@link ConsumerBatchContext} — the Index and Streams loops
957
- * share one shape now. Kept as an alias so existing annotations compile. */
958
- type StreamsBatchContext = ConsumerBatchContext;
959
953
  /**
960
954
  * The checkpoint for a reorg rollback. Persist `cursor` (the rewind position)
961
955
  * inside the same transaction as your rollback so the two commit atomically.
@@ -1025,7 +1019,7 @@ type StreamsEventsConsumeParams<
1025
1019
  * labels do not interleave within a page — add `onBatch` when you need
1026
1020
  * strict global order across labels.
1027
1021
  */
1028
- on?: { [K in keyof F] : (events: StreamsEventForFilter<F[K], D>[], ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | Promise<void> };
1022
+ on?: { [K in keyof F] : (events: StreamsEventForFilter<F[K], D>[], ctx: ConsumerBatchContext<StreamsTip, StreamsReorg> & WithSinkTx<TTx>) => void | Promise<void> };
1029
1023
  batchSize?: number;
1030
1024
  /**
1031
1025
  * Apply a page of canonical events. Persist `ctx.cursor` in the same
@@ -1035,7 +1029,7 @@ type StreamsEventsConsumeParams<
1035
1029
  * Optional only when `on` handles the page instead; a consume call with
1036
1030
  * neither throws.
1037
1031
  */
1038
- onBatch?: (events: D extends true ? IndexEvent[] : StreamsEvent[], envelope: StreamsEventsEnvelope, ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
1032
+ onBatch?: (events: D extends true ? IndexEvent[] : StreamsEvent[], ctx: ConsumerBatchContext<StreamsTip, StreamsReorg> & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
1039
1033
  /**
1040
1034
  * Roll your projection back to `reorg.fork_point_height`, persisting
1041
1035
  * `ctx.cursor` in the same transaction. Called once per *new* reorg at or
@@ -1107,7 +1101,7 @@ type StreamsEventsConsumeBitcoinParams<TTx = never> = {
1107
1101
  /** A mainnet address. */
1108
1102
  address?: string;
1109
1103
  batchSize?: number;
1110
- onBatch: (events: RuneStreamsEvent[], envelope: StreamsEventsEnvelope<RuneStreamsEvent, StreamsBitcoinTip>, ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
1104
+ onBatch: (events: RuneStreamsEvent[], ctx: ConsumerBatchContext<StreamsBitcoinTip, StreamsReorg> & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
1111
1105
  onReorg?: (reorg: StreamsReorg, ctx: StreamsReorgContext) => Promise<void> | void;
1112
1106
  maxRollbackDepth?: number;
1113
1107
  retryCount?: number;
@@ -1206,7 +1200,7 @@ type StreamsEventsReplayParams = {
1206
1200
  from: string | null;
1207
1201
  }) => Promise<void> | void;
1208
1202
  /** Called per live page after the dump phase, like `consume`. */
1209
- onBatch: (events: StreamsEvent[], envelope: StreamsEventsEnvelope) => Promise<string | null | undefined> | string | null | undefined;
1203
+ onBatch: (events: StreamsEvent[], ctx: ConsumerBatchContext<StreamsTip, StreamsReorg>) => Promise<string | null | undefined> | string | null | undefined;
1210
1204
  /**
1211
1205
  * Called when the live-tail phase (after the dump backfill) crosses a reorg,
1212
1206
  * before the cursor rewinds and re-reads the now-canonical events — same
@@ -1529,7 +1523,7 @@ type IndexConsumeOptions<
1529
1523
  * an empty page still proves the loop is alive. Feed it to
1530
1524
  * `consumerHealth().record`. */
1531
1525
  onProgress?: (ctx: ConsumerBatchContext) => void;
1532
- onBatch: (items: TItem[], envelope: TEnvelope, ctx: ConsumerBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
1526
+ onBatch: (items: TItem[], ctx: ConsumerBatchContext<TEnvelope["tip"], TEnvelope["reorgs"][number]> & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
1533
1527
  /** Called once per new reorg at or below the checkpoint, before the loop
1534
1528
  * rewinds to `ctx.cursor` (`null` = pre-genesis) and re-reads. A reorg
1535
1529
  * whose fork sits ABOVE the checkpoint is not a rollback: nothing past
@@ -4154,8 +4148,6 @@ declare class ArchiveGateNotConfiguredError extends SecondLayerError {
4154
4148
  /** Parse a `Retry-After` header: delta-seconds or an HTTP-date. */
4155
4149
  declare function parseRetryAfter(value?: string | null): number | undefined;
4156
4150
  type CreateArchiveClientOptions = {
4157
- /** @deprecated Prefer `accountKey`. Kept one release as an alias. */
4158
- apiKey?: string;
4159
4151
  accountKey?: string;
4160
4152
  fetchImpl?: FetchLike;
4161
4153
  archiveBaseUrl?: string;
@@ -4387,7 +4379,6 @@ declare class StreamsServerError extends ApiError {
4387
4379
  declare class StreamsSignatureError extends SecondLayerError {
4388
4380
  constructor(message?: string);
4389
4381
  }
4390
- 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";
4391
4382
  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";
4392
4383
  /**
4393
4384
  * Helpers for Streams cursors. A cursor is the opaque `<block>:<index>` string
@@ -4427,4 +4418,4 @@ declare const Cursor: {
4427
4418
  };
4428
4419
  };
4429
4420
  import { decodeClarityValue, toJsonSafe } from "@secondlayer/shared/streams-rows";
4430
- export { ACCOUNT_KEY_ENV, ActiveSubgraphOperation, ApiError, ArchiveAuthError, ArchiveClient, ArchiveCreditsBalance, ArchiveDataset, ArchiveFetchItem, ArchiveFetchResult, ArchiveFlow, ArchiveGateNotConfiguredError, ArchiveLoadOptions, ArchiveManifest, ArchivePartition, ArchiveQuote, ArchiveSignatureError, ArchiveStatus, ArchiveVerifyInput, ArchiveVerifyRangeStatus, ArchiveVerifyResult, AuthError, BitcoinOutputSpent, BitcoinOutputUnspent, BitcoinOutspend, BitcoinResource, BlockEnvelope, BlocksEnvelope, BlocksListParams, BlocksWalkParams, CanonicalEnvelope, CanonicalListParams, CanonicalWalkParams, ChainApplyDeliveryOf, ChainApplyEnvelope, ChainApplyEnvelopeOf, ChainEventEnvelope, ChainFtBurnData, ChainFtMintData, ChainFtTransferData, ChainNftBurnData, ChainNftMintData, ChainNftTransferData, ChainPrintEventData, ChainReorgOrphanedEntry, ChainReorgRollbackDelivery, ChainReorgRollbackEnvelope, ChainStxBurnData, ChainStxLockData, ChainStxMintData, ChainStxTransferData, ChainTestDelivery, ChainTrigger, ChainTriggerType, ChainTxLevelEvent, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainWebhookEnvelope, ConsumerBatchContext, ConsumerHealth, ConsumerSink, ContextAccount, ContextField, ContextFieldError, ContextSnapshot, ContractCallsConsumeParams, ContractCallsEnvelope, ContractCallsListParams, ContractCallsWalkParams, ContractConformance, ContractSummary, Contracts, ContractsEnvelope, ContractsListParams, CreateArchiveClientOptions, CreateWebhookRequest2 as CreateWebhookRequest, CreateWebhookResponse2 as CreateWebhookResponse, Cursor, DEFAULT_REQUEST_TIMEOUT_MS, DOWN_MIN_CONSECUTIVE, DeadRow2 as DeadRow, 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, DeliveryRow2 as DeliveryRow, DoctorEvidence, DoctorFix, DoctorIssue, DoctorIssueCode, DoctorReport, DoctorSeverity, EtagCache, EtagEntry, EventsConsumeParams, EventsEnvelope, EventsListParams, EventsWalkParams, FetchLike2 as FetchLike, FtTransfer, FtTransferEvent, FtTransferPayload2 as FtTransferPayload, FtTransfersEnvelope, FtTransfersListParams, FtTransfersResource, FtTransfersWalkParams, INDEX_MAX_PAGE_SIZE, INSTANCE_TOKEN_ENV, Index, IndexAlwaysFields, IndexBitcoinTip, IndexBlock, IndexBtcReorg, IndexCanonicalBlock, IndexConsumeOptions, IndexContractCall, IndexDiscovery, IndexEvent, IndexEventFields, IndexEventOf, IndexEventType, IndexEventTypeFilters, IndexEventsResource, IndexFeedEnvelope, IndexFeedFetcher, IndexFeedItem, IndexFtBurn, IndexFtMint, IndexFtTransfer, IndexMapDelete, IndexMapInsert, IndexMapSet, IndexMempoolTransaction, IndexNestedContractCall, IndexNftBurn, IndexNftMint, IndexNftTransfer, IndexOrder, IndexPostCondition, IndexPox5Event, IndexPox5EventTopic, IndexPoxCycle, IndexPoxCycleSigner, IndexPrint, IndexReorg, IndexRuneBalance, IndexRuneEntry, IndexRuneEvent, IndexRuneEventKind, IndexRuneRefSummary, IndexRuneTerms, IndexSbtcDeposit, IndexSbtcDepositDetail, IndexSbtcEvent, IndexSbtcSummary, IndexSbtcWithdrawal, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawalPhase, IndexStackingAction, IndexStateWrite, IndexStxBurn, IndexStxLock, IndexStxMint, IndexStxTransfer, IndexTip, IndexTransaction, IndexVarSet, InstanceClient, InstanceDiagnosis3 as InstanceDiagnosis, InstanceIssue, InstanceState, InstanceStatus, InsufficientArchiveCreditsError, LOCAL_API_URL, LoadedArchive, MemoryEtagCache, MempoolEnvelope, MempoolListParams, MempoolTransactionEnvelope, MempoolWalkParams, NftTransfer, NftTransferEvent, NftTransferPayload2 as NftTransferPayload, NftTransfersEnvelope, NftTransfersListParams, NftTransfersResource, NftTransfersWalkParams, Pox5EventsConsumeParams, Pox5EventsEnvelope, Pox5EventsListParams, Pox5EventsWalkParams, Pox5Resource, PoxCycleEnvelope, PoxCyclesEnvelope, PoxCyclesListParams, PoxCyclesWalkParams, PoxResource, PrintSchemaResponse, PublicStatus2 as PublicStatus, RateLimitError, ReplayResult2 as ReplayResult, RequestOptions, RewardSet2 as RewardSet, RotateSecretResponse2 as RotateSecretResponse, RuneActivityEnvelope, RuneActivityListParams, RuneActivityWalkParams, RuneApplyDeliveryOf, RuneApplyEnvelope, RuneBalancesEnvelope, RuneBalancesListParams, RuneEnvelope, RuneEtchEntry, RuneEventPayload, RuneEventType, RuneId, RuneRef, RuneStreamsEvent, RunesEnvelope, RunesListParams, RunesResource, SbtcDepositEnvelope, SbtcDepositEvent, SbtcDepositsConsumeParams, SbtcDepositsEnvelope, SbtcDepositsListParams, SbtcDepositsWalkParams, SbtcEventTopic2 as SbtcEventTopic, SbtcEventsConsumeParams, SbtcEventsEnvelope, SbtcEventsListParams, SbtcEventsWalkParams, SbtcResource, SbtcSummaryEnvelope, SbtcWithdrawalEnvelope, SbtcWithdrawalEvent, SbtcWithdrawalStatus, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalsEnvelope, SbtcWithdrawalsListParams, SbtcWithdrawalsWalkParams, SecondLayer, SecondLayerArchive, SecondLayerError, SecondLayerErrorOptions, SecondLayerOptions, SinkTx, StackingEnvelope, StackingListParams, StackingWalkParams, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StateWritesEnvelope, StateWritesListParams, StateWritesWalkParams, StreamsBatch, StreamsBatchContext, StreamsBitcoinCanonicalBlock, StreamsBitcoinTip, StreamsCanonicalBlock, StreamsClient, StreamsConsumeBitcoinParams, StreamsConsumeParams, StreamsConsumeStacksParams, StreamsDumpFile, StreamsDumps, StreamsDumpsManifest, StreamsEvent, StreamsEventPayload, StreamsEventType, StreamsEventsBitcoinListParams, StreamsEventsConsumeBitcoinParams, StreamsEventsConsumeParams, StreamsEventsConsumeResult, StreamsEventsEnvelope, StreamsEventsListEnvelope, StreamsEventsListParams, StreamsEventsStacksListParams, StreamsEventsStreamBitcoinParams, StreamsEventsStreamParams, StreamsEventsStreamStacksParams, StreamsEventsSubscribeBitcoinParams, StreamsEventsSubscribeParams, StreamsEventsSubscribeStacksParams, StreamsReorg, StreamsReorgContext, StreamsReorgsListEnvelope, StreamsReorgsListParams, StreamsServerError, StreamsSignatureError, StreamsSubscription, StreamsTip, StreamsWireEvent2 as StreamsWireEvent, SubgraphAgentSchema3 as SubgraphAgentSchema, SubgraphOperationStatus, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphSpecOptions3 as SubgraphSpecOptions, Subgraphs, TransactionEnvelope, TransactionProof, TransactionProofVerifyResult, TransactionsEnvelope, TransactionsListParams, TransactionsWalkParams, UpdateWebhookRequest2 as UpdateWebhookRequest, ValidationError, VmStreamsEvent, WalkOptions, WebhookActivity2 as WebhookActivity, WebhookActivityHour, WebhookAuth, WebhookDeliveryDetail2 as WebhookDeliveryDetail, WebhookDetail2 as WebhookDetail, WebhookFormat, WebhookHeaderInput, WebhookKind, WebhookStatus, WebhookSummary2 as WebhookSummary, WebhookTestResult2 as WebhookTestResult, Webhooks, WithSinkTx, buildDoctorReport, buildListIssue, consumeIndexFeed, consumerHealth, contextField, createArchiveClient, createStreamsClient, decode, decodeChainWebhook, decodeClarityValue, decodeFtBurn, decodeFtMint, decodeFtTransfer, decodeNftBurn, decodeNftMint, decodeNftTransfer, decodePrint, decodeStxBurn, decodeStxLock, decodeStxMint, decodeStxTransfer, fetchRewardSet, getSubgraph, isFtBurn, isFtMint, isFtTransfer, isHostedApiUrl, isNftBurn, isNftMint, isNftTransfer, isPrint, isStxBurn, isStxLock, isStxMint, isStxTransfer, isSuccessDelivery, parseRetryAfter, resolveAccountKey, resolveApiKey, resolveBaseUrl, shutdownSignal, toJsonSafe, trigger, verifySecondlayerSignature, verify as verifyStandardWebhooksHeaders, verifyTransactionProof, verifyWebhookSignature };
4421
+ export { ACCOUNT_KEY_ENV, ActiveSubgraphOperation, ApiError, ArchiveAuthError, ArchiveClient, ArchiveCreditsBalance, ArchiveDataset, ArchiveFetchItem, ArchiveFetchResult, ArchiveFlow, ArchiveGateNotConfiguredError, ArchiveLoadOptions, ArchiveManifest, ArchivePartition, ArchiveQuote, ArchiveSignatureError, ArchiveStatus, ArchiveVerifyInput, ArchiveVerifyRangeStatus, ArchiveVerifyResult, AuthError, BitcoinOutputSpent, BitcoinOutputUnspent, BitcoinOutspend, BitcoinResource, BlockEnvelope, BlocksEnvelope, BlocksListParams, BlocksWalkParams, CanonicalEnvelope, CanonicalListParams, CanonicalWalkParams, ChainApplyDeliveryOf, ChainApplyEnvelope, ChainApplyEnvelopeOf, ChainEventEnvelope, ChainFtBurnData, ChainFtMintData, ChainFtTransferData, ChainNftBurnData, ChainNftMintData, ChainNftTransferData, ChainPrintEventData, ChainReorgOrphanedEntry, ChainReorgRollbackDelivery, ChainReorgRollbackEnvelope, ChainStxBurnData, ChainStxLockData, ChainStxMintData, ChainStxTransferData, ChainTestDelivery, ChainTrigger, ChainTriggerType, ChainTxLevelEvent, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainWebhookEnvelope, ConsumerBatchContext, ConsumerHealth, ConsumerSink, ContextAccount, ContextField, ContextFieldError, ContextSnapshot, ContractCallsConsumeParams, ContractCallsEnvelope, ContractCallsListParams, ContractCallsWalkParams, ContractConformance, ContractSummary, Contracts, ContractsEnvelope, ContractsListParams, CreateArchiveClientOptions, CreateWebhookRequest2 as CreateWebhookRequest, CreateWebhookResponse2 as CreateWebhookResponse, Cursor, DEFAULT_REQUEST_TIMEOUT_MS, DOWN_MIN_CONSECUTIVE, DeadRow2 as DeadRow, 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, DeliveryRow2 as DeliveryRow, DoctorEvidence, DoctorFix, DoctorIssue, DoctorIssueCode, DoctorReport, DoctorSeverity, EtagCache, EtagEntry, EventsConsumeParams, EventsEnvelope, EventsListParams, EventsWalkParams, FetchLike2 as FetchLike, FtTransfer, FtTransferEvent, FtTransferPayload2 as FtTransferPayload, FtTransfersEnvelope, FtTransfersListParams, FtTransfersResource, FtTransfersWalkParams, INDEX_MAX_PAGE_SIZE, INSTANCE_TOKEN_ENV, Index, IndexAlwaysFields, IndexBitcoinTip, IndexBlock, IndexBtcReorg, IndexCanonicalBlock, IndexConsumeOptions, IndexContractCall, IndexDiscovery, IndexEvent, IndexEventFields, IndexEventOf, IndexEventType, IndexEventTypeFilters, IndexEventsResource, IndexFeedEnvelope, IndexFeedFetcher, IndexFeedItem, IndexFtBurn, IndexFtMint, IndexFtTransfer, IndexMapDelete, IndexMapInsert, IndexMapSet, IndexMempoolTransaction, IndexNestedContractCall, IndexNftBurn, IndexNftMint, IndexNftTransfer, IndexOrder, IndexPostCondition, IndexPox5Event, IndexPox5EventTopic, IndexPoxCycle, IndexPoxCycleSigner, IndexPrint, IndexReorg, IndexRuneBalance, IndexRuneEntry, IndexRuneEvent, IndexRuneEventKind, IndexRuneRefSummary, IndexRuneTerms, IndexSbtcDeposit, IndexSbtcDepositDetail, IndexSbtcEvent, IndexSbtcSummary, IndexSbtcWithdrawal, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawalPhase, IndexStackingAction, IndexStateWrite, IndexStxBurn, IndexStxLock, IndexStxMint, IndexStxTransfer, IndexTip, IndexTransaction, IndexVarSet, InstanceClient, InstanceDiagnosis3 as InstanceDiagnosis, InstanceIssue, InstanceState, InstanceStatus, InsufficientArchiveCreditsError, LOCAL_API_URL, LoadedArchive, MemoryEtagCache, MempoolEnvelope, MempoolListParams, MempoolTransactionEnvelope, MempoolWalkParams, NftTransfer, NftTransferEvent, NftTransferPayload2 as NftTransferPayload, NftTransfersEnvelope, NftTransfersListParams, NftTransfersResource, NftTransfersWalkParams, Pox5EventsConsumeParams, Pox5EventsEnvelope, Pox5EventsListParams, Pox5EventsWalkParams, Pox5Resource, PoxCycleEnvelope, PoxCyclesEnvelope, PoxCyclesListParams, PoxCyclesWalkParams, PoxResource, PrintSchemaResponse, PublicStatus2 as PublicStatus, RateLimitError, ReplayResult2 as ReplayResult, RequestOptions, RewardSet2 as RewardSet, RotateSecretResponse2 as RotateSecretResponse, RuneActivityEnvelope, RuneActivityListParams, RuneActivityWalkParams, RuneApplyDeliveryOf, RuneApplyEnvelope, RuneBalancesEnvelope, RuneBalancesListParams, RuneEnvelope, RuneEtchEntry, RuneEventPayload, RuneEventType, RuneId, RuneRef, RuneStreamsEvent, RunesEnvelope, RunesListParams, RunesResource, SbtcDepositEnvelope, SbtcDepositEvent, SbtcDepositsConsumeParams, SbtcDepositsEnvelope, SbtcDepositsListParams, SbtcDepositsWalkParams, SbtcEventTopic2 as SbtcEventTopic, SbtcEventsConsumeParams, SbtcEventsEnvelope, SbtcEventsListParams, SbtcEventsWalkParams, SbtcResource, SbtcSummaryEnvelope, SbtcWithdrawalEnvelope, SbtcWithdrawalEvent, SbtcWithdrawalStatus, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalsEnvelope, SbtcWithdrawalsListParams, SbtcWithdrawalsWalkParams, SecondLayer, SecondLayerArchive, SecondLayerError, SecondLayerErrorOptions, SecondLayerOptions, SinkTx, StackingEnvelope, StackingListParams, StackingWalkParams, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StateWritesEnvelope, StateWritesListParams, StateWritesWalkParams, StreamsBatch, StreamsBitcoinCanonicalBlock, StreamsBitcoinTip, StreamsCanonicalBlock, StreamsClient, StreamsConsumeBitcoinParams, StreamsConsumeParams, StreamsConsumeStacksParams, StreamsDumpFile, StreamsDumps, StreamsDumpsManifest, StreamsEvent, StreamsEventPayload, StreamsEventType, StreamsEventsBitcoinListParams, StreamsEventsConsumeBitcoinParams, StreamsEventsConsumeParams, StreamsEventsConsumeResult, StreamsEventsEnvelope, StreamsEventsListEnvelope, StreamsEventsListParams, StreamsEventsStacksListParams, StreamsEventsStreamBitcoinParams, StreamsEventsStreamParams, StreamsEventsStreamStacksParams, StreamsEventsSubscribeBitcoinParams, StreamsEventsSubscribeParams, StreamsEventsSubscribeStacksParams, StreamsReorg, StreamsReorgContext, StreamsReorgsListEnvelope, StreamsReorgsListParams, StreamsServerError, StreamsSignatureError, StreamsSubscription, StreamsTip, StreamsWireEvent2 as StreamsWireEvent, SubgraphAgentSchema3 as SubgraphAgentSchema, SubgraphOperationStatus, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphSpecOptions3 as SubgraphSpecOptions, Subgraphs, TransactionEnvelope, TransactionProof, TransactionProofVerifyResult, TransactionsEnvelope, TransactionsListParams, TransactionsWalkParams, UpdateWebhookRequest2 as UpdateWebhookRequest, ValidationError, VmStreamsEvent, WalkOptions, WebhookActivity2 as WebhookActivity, WebhookActivityHour, WebhookAuth, WebhookDeliveryDetail2 as WebhookDeliveryDetail, WebhookDetail2 as WebhookDetail, WebhookFormat, WebhookHeaderInput, WebhookKind, WebhookStatus, WebhookSummary2 as WebhookSummary, WebhookTestResult2 as WebhookTestResult, Webhooks, WithSinkTx, buildDoctorReport, buildListIssue, consumeIndexFeed, consumerHealth, contextField, createArchiveClient, createStreamsClient, decode, decodeChainWebhook, decodeClarityValue, fetchRewardSet, getSubgraph, isHostedApiUrl, isSuccessDelivery, parseRetryAfter, resolveAccountKey, resolveApiKey, resolveBaseUrl, shutdownSignal, toJsonSafe, trigger, verifySecondlayerSignature, verify as verifyStandardWebhooksHeaders, verifyTransactionProof, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -214,6 +214,7 @@ function raceAbort(promise, signal) {
214
214
  });
215
215
  }
216
216
  var LOCAL_API_URL = "http://127.0.0.1:3800";
217
+ var HOSTED_API_URL = "https://api.secondlayer.tools";
217
218
  var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
218
219
  var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
219
220
  function resolveBaseUrl(explicit) {
@@ -223,6 +224,9 @@ function resolveBaseUrl(explicit) {
223
224
  const primary = process.env?.SECONDLAYER_API_URL || undefined;
224
225
  if (primary)
225
226
  return primary.replace(/\/+$/, "");
227
+ if (process.env?.[ACCOUNT_KEY_ENV]?.startsWith("sk-sl_") && !process.env?.[INSTANCE_TOKEN_ENV]) {
228
+ return HOSTED_API_URL;
229
+ }
226
230
  }
227
231
  return LOCAL_API_URL;
228
232
  }
@@ -450,7 +454,7 @@ function stripSlash(url) {
450
454
  return url.replace(/\/+$/, "");
451
455
  }
452
456
  function createArchiveClient(options = {}) {
453
- const accountKey = resolveAccountKey(options.accountKey ?? options.apiKey);
457
+ const accountKey = resolveAccountKey(options.accountKey);
454
458
  const fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init));
455
459
  const archiveBaseUrl = stripSlash(options.archiveBaseUrl ?? DEFAULT_ARCHIVE_BASE_URL);
456
460
  const archiveOpsUrl = stripSlash(options.archiveOpsUrl ?? DEFAULT_ARCHIVE_OPS_URL);
@@ -970,7 +974,7 @@ async function consumeStreamsEvents(opts) {
970
974
  const sink = opts.sink;
971
975
  if (checkpoint !== null && (checkpoint !== cursor || emitted.length > 0)) {
972
976
  await sink.commitBatch(checkpoint, async (tx) => {
973
- await opts.onBatch(emitted, envelope, {
977
+ await opts.onBatch(emitted, {
974
978
  ...ctx,
975
979
  tx
976
980
  });
@@ -978,7 +982,7 @@ async function consumeStreamsEvents(opts) {
978
982
  }
979
983
  nextCursor = checkpoint;
980
984
  } else {
981
- const returnedCursor = await opts.onBatch(emitted, envelope, ctx);
985
+ const returnedCursor = await opts.onBatch(emitted, ctx);
982
986
  if (finalizedOnly)
983
987
  assertFinalizedCheckpoint(returnedCursor, checkpoint);
984
988
  nextCursor = returnedCursor ?? checkpoint;
@@ -1151,7 +1155,7 @@ async function consumeIndexFeed(opts) {
1151
1155
  const sink = opts.sink;
1152
1156
  if (checkpoint !== null && (checkpoint !== cursor || emitted.length > 0)) {
1153
1157
  await sink.commitBatch(checkpoint, async (tx) => {
1154
- await opts.onBatch(emitted, envelope, {
1158
+ await opts.onBatch(emitted, {
1155
1159
  ...ctx,
1156
1160
  tx
1157
1161
  });
@@ -1159,7 +1163,7 @@ async function consumeIndexFeed(opts) {
1159
1163
  }
1160
1164
  nextCursor = checkpoint;
1161
1165
  } else {
1162
- const returnedCursor = await opts.onBatch(emitted, envelope, ctx);
1166
+ const returnedCursor = await opts.onBatch(emitted, ctx);
1163
1167
  if (finalizedOnly)
1164
1168
  assertFinalizedCheckpoint(returnedCursor, checkpoint);
1165
1169
  nextCursor = returnedCursor ?? checkpoint;
@@ -2223,7 +2227,7 @@ function createStreamsClient(options) {
2223
2227
  }
2224
2228
  const dispatch = params.on;
2225
2229
  const project = (events) => params.decoded ? events.map(decode) : events;
2226
- const onBatch = async (events, envelope, ctx) => {
2230
+ const onBatch = async (events, ctx) => {
2227
2231
  for (const label of labels) {
2228
2232
  const forLabel = events.filter((event) => event.matched?.includes(label));
2229
2233
  if (forLabel.length === 0)
@@ -2231,7 +2235,7 @@ function createStreamsClient(options) {
2231
2235
  await dispatch?.[label]?.(project(forLabel), ctx);
2232
2236
  }
2233
2237
  const userOnBatch = params.onBatch;
2234
- return await userOnBatch?.(project(events), envelope, ctx);
2238
+ return await userOnBatch?.(project(events), ctx);
2235
2239
  };
2236
2240
  return consumeStreamsEvents({
2237
2241
  fromCursor: params.fromCursor,
@@ -3356,32 +3360,6 @@ function verifyTransactionProof(proof, opts) {
3356
3360
  errors
3357
3361
  };
3358
3362
  }
3359
- // src/streams/index.ts
3360
- import {
3361
- decodeFtTransfer,
3362
- isFtTransfer,
3363
- decodeNftTransfer,
3364
- isNftTransfer,
3365
- decodeStxBurn,
3366
- decodeStxLock,
3367
- decodeStxMint,
3368
- decodeStxTransfer,
3369
- isStxBurn,
3370
- isStxLock,
3371
- isStxMint,
3372
- isStxTransfer,
3373
- decodeFtBurn,
3374
- decodeFtMint,
3375
- decodeNftBurn,
3376
- decodeNftMint,
3377
- isFtBurn,
3378
- isFtMint,
3379
- isNftBurn,
3380
- isNftMint,
3381
- decodePrint,
3382
- isPrint
3383
- } from "@secondlayer/shared/streams-rows";
3384
-
3385
3363
  // src/streams/types.ts
3386
3364
  import {
3387
3365
  RUNE_EVENT_TYPES,
@@ -3427,31 +3405,9 @@ export {
3427
3405
  decode,
3428
3406
  decodeChainWebhook,
3429
3407
  decodeClarityValue,
3430
- decodeFtBurn,
3431
- decodeFtMint,
3432
- decodeFtTransfer,
3433
- decodeNftBurn,
3434
- decodeNftMint,
3435
- decodeNftTransfer,
3436
- decodePrint,
3437
- decodeStxBurn,
3438
- decodeStxLock,
3439
- decodeStxMint,
3440
- decodeStxTransfer,
3441
3408
  fetchRewardSet,
3442
3409
  getSubgraph,
3443
- isFtBurn,
3444
- isFtMint,
3445
- isFtTransfer,
3446
3410
  isHostedApiUrl,
3447
- isNftBurn,
3448
- isNftMint,
3449
- isNftTransfer,
3450
- isPrint,
3451
- isStxBurn,
3452
- isStxLock,
3453
- isStxMint,
3454
- isStxTransfer,
3455
3411
  isSuccessDelivery,
3456
3412
  parseRetryAfter,
3457
3413
  resolveAccountKey,
@@ -3466,5 +3422,5 @@ export {
3466
3422
  verifyWebhookSignature
3467
3423
  };
3468
3424
 
3469
- //# debugId=92E785DAD5F0BBD664756E2164756E21
3425
+ //# debugId=8E37F0B7E094194F64756E2164756E21
3470
3426
  //# sourceMappingURL=index.js.map