@secondlayer/sdk 14.1.0 → 14.3.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 +6 -0
- package/README.md +5 -1
- package/dist/index.d.ts +53 -7
- package/dist/index.js +31 -6
- package/dist/index.js.map +5 -5
- package/dist/streams/index.js +13 -6
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +43 -2
- package/dist/subgraphs/index.js +30 -6
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +3 -3
package/AGENTS.md
CHANGED
|
@@ -6,6 +6,12 @@ silently loses or corrupts data.
|
|
|
6
6
|
|
|
7
7
|
## 1. `/v1` reads are open on loopback; `/api` needs the token
|
|
8
8
|
|
|
9
|
+
The key follows the host. On `https://api.secondlayer.tools` the client sends
|
|
10
|
+
`SECONDLAYER_API_KEY` (`sk-sl_*`) automatically and `INSTANCE_TOKEN` is not
|
|
11
|
+
used. Hosted subgraph sources are event filters and `contract_call` /
|
|
12
|
+
`contract_deploy` only (`422 SOURCE_NOT_HOSTABLE`), and subgraph webhooks are
|
|
13
|
+
self-host only. What follows describes a self-hosted instance.
|
|
14
|
+
|
|
9
15
|
`sl.index.*`, `sl.streams.*`, `sl.subgraphs.rows`, and the typed `subscribe`
|
|
10
16
|
read `/v1`, open on loopback. Construct the client with no credentials and start reading:
|
|
11
17
|
|
package/README.md
CHANGED
|
@@ -19,7 +19,11 @@ const sl = new SecondLayer({
|
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
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.
|
|
25
|
+
|
|
26
|
+
Auth, once (self-hosted instance): `sl.index`, `sl.streams`, `sl.subgraphs.rows`, and the typed
|
|
23
27
|
`subscribe` read `/v1`, which is open on loopback and needs `INSTANCE_TOKEN`
|
|
24
28
|
once the API is bound beyond it. Everything under `sl.subgraphs.*` and `sl.webhooks.*` calls
|
|
25
29
|
`/api`, which needs `INSTANCE_TOKEN` as soon as one is configured, loopback
|
package/dist/index.d.ts
CHANGED
|
@@ -153,10 +153,13 @@ type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<
|
|
|
153
153
|
interface SecondLayerOptions {
|
|
154
154
|
/** Base URL of the instance API (trailing slashes are stripped). */
|
|
155
155
|
baseUrl: string;
|
|
156
|
-
/** Bearer token for authenticated
|
|
156
|
+
/** Bearer token for authenticated requests. Defaults to
|
|
157
|
+
* `SECONDLAYER_API_KEY` on `api.secondlayer.tools`, `INSTANCE_TOKEN`
|
|
158
|
+
* elsewhere. */
|
|
157
159
|
apiKey?: string;
|
|
158
160
|
/** Hosted account key (`sk-sl_*`). Env `SECONDLAYER_API_KEY`. Used by
|
|
159
|
-
* `sl.archive` quote/fetch/credits
|
|
161
|
+
* `sl.archive` quote/fetch/credits; reaches `/v1` and `/api` only through
|
|
162
|
+
* `apiKey` when the base URL is the hosted API. */
|
|
160
163
|
accountKey?: string;
|
|
161
164
|
/** Fetch implementation. Tests and edge runtimes can provide their own. */
|
|
162
165
|
fetchImpl?: FetchLike;
|
|
@@ -229,10 +232,15 @@ declare const INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
|
229
232
|
/** Hosted account key (`sk-sl_*`) for api.secondlayer.tools. */
|
|
230
233
|
declare const ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
231
234
|
declare function resolveBaseUrl(explicit?: string): string;
|
|
232
|
-
/**
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
/** True when `url` is the hosted Secondlayer API (`api.secondlayer.tools`). */
|
|
236
|
+
declare function isHostedApiUrl(url: string): boolean;
|
|
237
|
+
/** Resolve the bearer credential; the key follows the host. Precedence:
|
|
238
|
+
* explicit `apiKey` (including `""` for keyless) → on the hosted API,
|
|
239
|
+
* `SECONDLAYER_API_KEY`; anywhere else (or with no `baseUrl`),
|
|
240
|
+
* `INSTANCE_TOKEN`. Never crosses over: the instance token is not sent to the
|
|
241
|
+
* hosted API and the account key is not sent to an instance. Guarded for
|
|
242
|
+
* browsers and edge runtimes. */
|
|
243
|
+
declare function resolveApiKey(apiKey?: string, baseUrl?: string): string | undefined;
|
|
236
244
|
/** Resolve the hosted account key for archive quote/fetch/credits.
|
|
237
245
|
* Precedence: explicit `accountKey` → `SECONDLAYER_API_KEY`. Does not read
|
|
238
246
|
* `INSTANCE_TOKEN`. */
|
|
@@ -1798,6 +1806,37 @@ type CanonicalListParams = {
|
|
|
1798
1806
|
toHeight?: number;
|
|
1799
1807
|
};
|
|
1800
1808
|
type CanonicalWalkParams = Omit<CanonicalListParams, "limit"> & WalkOptions;
|
|
1809
|
+
/** One MARF write a block committed, in the node's write order. Present only
|
|
1810
|
+
* from the height the instance's node subscribed to `state_writes`. */
|
|
1811
|
+
type IndexStateWrite = {
|
|
1812
|
+
/** `<block_height>:<ordinal>`. */
|
|
1813
|
+
cursor: string;
|
|
1814
|
+
block_height: number;
|
|
1815
|
+
/** Position in the block's write order: a separate clock from
|
|
1816
|
+
* `event_index`. */
|
|
1817
|
+
ordinal: number;
|
|
1818
|
+
/** Null for block-level writes. */
|
|
1819
|
+
tx_index: number | null;
|
|
1820
|
+
/** Full MARF key, e.g. `vm::<contract>::0::map::<hex>`. */
|
|
1821
|
+
key: string;
|
|
1822
|
+
value_hex: string;
|
|
1823
|
+
};
|
|
1824
|
+
type StateWritesEnvelope = {
|
|
1825
|
+
state_writes: IndexStateWrite[];
|
|
1826
|
+
next_cursor: string | null;
|
|
1827
|
+
tip: IndexTip;
|
|
1828
|
+
reorgs: IndexReorg[];
|
|
1829
|
+
};
|
|
1830
|
+
type StateWritesListParams = {
|
|
1831
|
+
cursor?: string | null;
|
|
1832
|
+
fromCursor?: string | null;
|
|
1833
|
+
limit?: number;
|
|
1834
|
+
fromHeight?: number;
|
|
1835
|
+
toHeight?: number;
|
|
1836
|
+
/** One block. Excludes `fromHeight`/`toHeight`; a cursor must sit at it. */
|
|
1837
|
+
blockHeight?: number;
|
|
1838
|
+
};
|
|
1839
|
+
type StateWritesWalkParams = Omit<StateWritesListParams, "limit"> & WalkOptions;
|
|
1801
1840
|
/** A block resource. Metadata is intentionally thin — only chain-linkage and
|
|
1802
1841
|
* burn-anchor fields are persisted (no miner / tx_count / signer). */
|
|
1803
1842
|
type IndexBlock = {
|
|
@@ -2809,6 +2848,11 @@ declare class Index extends BaseClient {
|
|
|
2809
2848
|
list: (params?: CanonicalListParams) => Promise<CanonicalEnvelope>;
|
|
2810
2849
|
walk: (params?: CanonicalWalkParams) => AsyncIterable<IndexCanonicalBlock>;
|
|
2811
2850
|
};
|
|
2851
|
+
/** Exact MARF writes per canonical block (`/v1/index/state-writes`). */
|
|
2852
|
+
readonly stateWrites: {
|
|
2853
|
+
list: (params?: StateWritesListParams) => Promise<StateWritesEnvelope>;
|
|
2854
|
+
walk: (params?: StateWritesWalkParams) => AsyncIterable<IndexStateWrite>;
|
|
2855
|
+
};
|
|
2812
2856
|
/** Canonical blocks: paginated `list`/`walk`, plus `get` by height or hash
|
|
2813
2857
|
* (resolves to null on 404). */
|
|
2814
2858
|
readonly blocks: {
|
|
@@ -2878,6 +2922,8 @@ declare class Index extends BaseClient {
|
|
|
2878
2922
|
private walkContractCalls;
|
|
2879
2923
|
private listCanonical;
|
|
2880
2924
|
private walkCanonical;
|
|
2925
|
+
private listStateWrites;
|
|
2926
|
+
private walkStateWrites;
|
|
2881
2927
|
private listBlocks;
|
|
2882
2928
|
private getBlock;
|
|
2883
2929
|
private walkBlocks;
|
|
@@ -3723,4 +3769,4 @@ declare const Cursor: {
|
|
|
3723
3769
|
};
|
|
3724
3770
|
};
|
|
3725
3771
|
import { decodeClarityValue, toJsonSafe } from "@secondlayer/shared/streams-rows";
|
|
3726
|
-
export { ACCOUNT_KEY_ENV, ActiveSubgraphOperation, ApiError, ArchiveAuthError, ArchiveClient, ArchiveCreditsBalance, ArchiveDataset, ArchiveFetchItem, ArchiveFetchResult, ArchiveFlow, ArchiveGateNotConfiguredError, ArchiveLoadOptions, ArchiveManifest, ArchivePartition, ArchiveQuote, ArchiveSignatureError, ArchiveStatus, ArchiveVerifyInput, ArchiveVerifyRangeStatus, ArchiveVerifyResult, AuthError, 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, IndexPostCondition, IndexPox5Event, IndexPox5EventTopic, IndexPoxCycle, IndexPoxCycleSigner, IndexPrint, IndexReorg, IndexRuneBalance, IndexRuneEntry, IndexRuneEvent, IndexRuneEventKind, IndexRuneRefSummary, IndexRuneTerms, IndexSbtcDeposit, IndexSbtcDepositDetail, IndexSbtcEvent, IndexSbtcSummary, IndexSbtcWithdrawal, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawalPhase, IndexStackingAction, 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, 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, WebhookRuntime, 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, isNftBurn, isNftMint, isNftTransfer, isPrint, isStxBurn, isStxLock, isStxMint, isStxTransfer, isSuccessDelivery, parseRetryAfter, resolveAccountKey, resolveApiKey, resolveBaseUrl, shutdownSignal, toJsonSafe, trigger, verifySecondlayerSignature, verify as verifyStandardWebhooksHeaders, verifyTransactionProof, verifyWebhookSignature };
|
|
3772
|
+
export { ACCOUNT_KEY_ENV, ActiveSubgraphOperation, ApiError, ArchiveAuthError, ArchiveClient, ArchiveCreditsBalance, ArchiveDataset, ArchiveFetchItem, ArchiveFetchResult, ArchiveFlow, ArchiveGateNotConfiguredError, ArchiveLoadOptions, ArchiveManifest, ArchivePartition, ArchiveQuote, ArchiveSignatureError, ArchiveStatus, ArchiveVerifyInput, ArchiveVerifyRangeStatus, ArchiveVerifyResult, AuthError, 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, 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, WebhookRuntime, 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 };
|
package/dist/index.js
CHANGED
|
@@ -215,13 +215,20 @@ function resolveBaseUrl(explicit) {
|
|
|
215
215
|
}
|
|
216
216
|
return LOCAL_API_URL;
|
|
217
217
|
}
|
|
218
|
-
function
|
|
218
|
+
function isHostedApiUrl(url) {
|
|
219
|
+
try {
|
|
220
|
+
return new URL(url).hostname === "api.secondlayer.tools";
|
|
221
|
+
} catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function resolveApiKey(apiKey, baseUrl) {
|
|
219
226
|
if (apiKey !== undefined)
|
|
220
227
|
return apiKey;
|
|
221
228
|
if (typeof process === "undefined")
|
|
222
229
|
return;
|
|
223
|
-
const
|
|
224
|
-
return
|
|
230
|
+
const name = baseUrl !== undefined && isHostedApiUrl(baseUrl) ? ACCOUNT_KEY_ENV : INSTANCE_TOKEN_ENV;
|
|
231
|
+
return process.env?.[name] || undefined;
|
|
225
232
|
}
|
|
226
233
|
function resolveAccountKey(accountKey) {
|
|
227
234
|
if (accountKey !== undefined)
|
|
@@ -279,7 +286,7 @@ class BaseClient {
|
|
|
279
286
|
etagCache;
|
|
280
287
|
constructor(options = {}) {
|
|
281
288
|
this.baseUrl = resolveBaseUrl(options.baseUrl);
|
|
282
|
-
this.apiKey = resolveApiKey(options.apiKey);
|
|
289
|
+
this.apiKey = resolveApiKey(options.apiKey, this.baseUrl);
|
|
283
290
|
this.origin = options.origin ?? "cli";
|
|
284
291
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
285
292
|
this.fetchImpl = options.fetchImpl ?? ((...args) => fetch(...args));
|
|
@@ -1240,6 +1247,10 @@ class Index extends BaseClient {
|
|
|
1240
1247
|
list: (params = {}) => this.listCanonical(params),
|
|
1241
1248
|
walk: (params = {}) => this.walkCanonical(params)
|
|
1242
1249
|
};
|
|
1250
|
+
stateWrites = {
|
|
1251
|
+
list: (params = {}) => this.listStateWrites(params),
|
|
1252
|
+
walk: (params = {}) => this.walkStateWrites(params)
|
|
1253
|
+
};
|
|
1243
1254
|
blocks = {
|
|
1244
1255
|
list: (params = {}) => this.listBlocks(params),
|
|
1245
1256
|
walk: (params = {}) => this.walkBlocks(params),
|
|
@@ -1435,6 +1446,19 @@ class Index extends BaseClient {
|
|
|
1435
1446
|
walkCanonical(params = {}) {
|
|
1436
1447
|
return this.keysetWalk(params, (page) => this.listCanonical({ ...params, ...page }), (e) => e.canonical);
|
|
1437
1448
|
}
|
|
1449
|
+
async listStateWrites(params = {}) {
|
|
1450
|
+
return this.request("GET", `/v1/index/state-writes${buildQuery({
|
|
1451
|
+
...indexPageQuery(params),
|
|
1452
|
+
block_height: params.blockHeight
|
|
1453
|
+
})}`, undefined, { signal: params.signal });
|
|
1454
|
+
}
|
|
1455
|
+
walkStateWrites(params = {}) {
|
|
1456
|
+
return this.keysetWalk(params, (page) => this.listStateWrites({
|
|
1457
|
+
...params,
|
|
1458
|
+
...page,
|
|
1459
|
+
fromHeight: params.blockHeight === undefined ? page.fromHeight : undefined
|
|
1460
|
+
}), (e) => e.state_writes);
|
|
1461
|
+
}
|
|
1438
1462
|
async listBlocks(params = {}) {
|
|
1439
1463
|
return this.request("GET", `/v1/index/blocks${buildQuery(indexPageQuery(params))}`, undefined, { signal: params.signal });
|
|
1440
1464
|
}
|
|
@@ -2028,7 +2052,7 @@ function isLoopbackUrl(baseUrl) {
|
|
|
2028
2052
|
}
|
|
2029
2053
|
function createStreamsClient(options) {
|
|
2030
2054
|
const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
|
|
2031
|
-
const apiKey = resolveApiKey(options.apiKey);
|
|
2055
|
+
const apiKey = resolveApiKey(options.apiKey, baseUrl);
|
|
2032
2056
|
const origin = options.origin ?? "cli";
|
|
2033
2057
|
const authHeaders = () => ({
|
|
2034
2058
|
"x-sl-origin": origin,
|
|
@@ -3417,6 +3441,7 @@ export {
|
|
|
3417
3441
|
isFtBurn,
|
|
3418
3442
|
isFtMint,
|
|
3419
3443
|
isFtTransfer,
|
|
3444
|
+
isHostedApiUrl,
|
|
3420
3445
|
isNftBurn,
|
|
3421
3446
|
isNftMint,
|
|
3422
3447
|
isNftTransfer,
|
|
@@ -3439,5 +3464,5 @@ export {
|
|
|
3439
3464
|
verifyWebhookSignature
|
|
3440
3465
|
};
|
|
3441
3466
|
|
|
3442
|
-
//# debugId=
|
|
3467
|
+
//# debugId=B2DAEC1BBFDB7B6E64756E2164756E21
|
|
3443
3468
|
//# sourceMappingURL=index.js.map
|