@secondlayer/sdk 6.53.0 → 6.54.1
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/README.md +13 -24
- package/dist/index.d.ts +9 -5
- package/dist/index.js +17 -6
- package/dist/index.js.map +5 -5
- package/dist/streams/index.js +14 -5
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +1 -1
- package/dist/subgraphs/index.js +14 -5
- package/dist/subgraphs/index.js.map +4 -4
- package/dist/x402.d.ts +4 -3
- package/dist/x402.js +298 -2
- package/dist/x402.js.map +6 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,25 +14,14 @@ bun add @secondlayer/sdk
|
|
|
14
14
|
import { SecondLayer } from "@secondlayer/sdk";
|
|
15
15
|
|
|
16
16
|
const sl = new SecondLayer({
|
|
17
|
-
apiKey:
|
|
18
|
-
baseUrl:
|
|
17
|
+
apiKey: process.env.INSTANCE_TOKEN, // from sl init; omit on loopback
|
|
18
|
+
// default baseUrl: http://127.0.0.1:3800 (or SL_API_URL)
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
publicly-known free-tier token exists but a bearer is always required. Writes
|
|
26
|
-
require an `sk-sl_` API key, created in the platform console at
|
|
27
|
-
https://secondlayer.tools/platform/api-keys. (Public Streams bulk dumps —
|
|
28
|
-
`client.dumps`, `events.replay` — need no key.)
|
|
29
|
-
|
|
30
|
-
**API keys.** Each `sk-sl_` key has a `product`. An **`account`** key (dashboard
|
|
31
|
-
default) grants both `streams:read` and `index:read` and is the only key that can
|
|
32
|
-
mint new keys; **`streams`** / **`index`** keys are scoped, read-only, and cannot
|
|
33
|
-
mint. Mint scoped keys programmatically with `sl.apiKeys.create({ product })`
|
|
34
|
-
(needs an account/owner key) — the returned `key` is shown once and inherits your
|
|
35
|
-
plan's tier.
|
|
22
|
+
Reads hit your instance. Writes use `INSTANCE_TOKEN` from `sl init` when the
|
|
23
|
+
API is bound beyond loopback. Public archive dumps (`client.dumps`) need no
|
|
24
|
+
instance key.
|
|
36
25
|
|
|
37
26
|
## Mental model
|
|
38
27
|
|
|
@@ -43,14 +32,14 @@ Everything is indexing — the question is how much of the indexer you run:
|
|
|
43
32
|
with the checkpointed `consume()` loop (automatic reorg rewind), `walk()`
|
|
44
33
|
sweeps, and resumable cursors on every page.
|
|
45
34
|
- `sl.subgraphs` — deploy your own indexer (one `defineSubgraph()` file via the
|
|
46
|
-
CLI), then read
|
|
35
|
+
CLI), then read the tables on this instance.
|
|
47
36
|
- `sl.streams` — the raw ordered event firehose Index itself is built on, with
|
|
48
37
|
a checkpointed `consume()` and dumps `replay()` for building from zero.
|
|
49
38
|
- `sl.contracts` — find deployed contracts by trait (SIP-009/010/013).
|
|
50
39
|
|
|
51
40
|
## Streams
|
|
52
41
|
|
|
53
|
-
Typed HTTP client for the raw event firehose.
|
|
42
|
+
Typed HTTP client for the raw event firehose. Loopback reads need no key.
|
|
54
43
|
|
|
55
44
|
```typescript
|
|
56
45
|
const tip = await sl.streams.tip();
|
|
@@ -73,7 +62,7 @@ console.log({ tip, firstCursor: page.events[0]?.cursor });
|
|
|
73
62
|
import { createStreamsClient } from "@secondlayer/sdk";
|
|
74
63
|
|
|
75
64
|
const streams = createStreamsClient({
|
|
76
|
-
apiKey: process.env.
|
|
65
|
+
// apiKey: process.env.INSTANCE_TOKEN, // when the API is bound beyond loopback
|
|
77
66
|
// verify: true, // verify ed25519 X-Signature on every read
|
|
78
67
|
// // (auto-fetches the public key; { publicKey } pins a PEM)
|
|
79
68
|
// dumpsBaseUrl: process.env.SL_STREAMS_DUMPS_URL, // required to use client.dumps
|
|
@@ -289,7 +278,7 @@ client-side and trusts nothing the API returned.
|
|
|
289
278
|
import { verifyTransactionProof, fetchRewardSet } from "@secondlayer/sdk";
|
|
290
279
|
|
|
291
280
|
const proof = await fetch(
|
|
292
|
-
`
|
|
281
|
+
`http://127.0.0.1:3800/v1/index/transactions/${txid}/proof`,
|
|
293
282
|
).then((r) => r.json());
|
|
294
283
|
|
|
295
284
|
const result = verifyTransactionProof(proof); // anchored + consensus (embedded set)
|
|
@@ -531,8 +520,8 @@ few hundredths of a cent per request from a Stacks wallet. Payment is **gasless*
|
|
|
531
520
|
(you sign; we sponsor the STX fee) and uses standard **x402 v2** on `stacks:1`.
|
|
532
521
|
Supported assets: **sBTC** (default), **USDCx**, **STX**.
|
|
533
522
|
|
|
534
|
-
> Keyed (`
|
|
535
|
-
>
|
|
523
|
+
> Keyed (`INSTANCE_TOKEN`) requests skip x402. The rail is for accountless
|
|
524
|
+
> callers on an instance that has it enabled.
|
|
536
525
|
|
|
537
526
|
Drop-in `fetch` that pays on `402` automatically:
|
|
538
527
|
|
|
@@ -547,7 +536,7 @@ const x402fetch = withX402(fetch, {
|
|
|
547
536
|
});
|
|
548
537
|
|
|
549
538
|
const res = await x402fetch(
|
|
550
|
-
"
|
|
539
|
+
"http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer",
|
|
551
540
|
);
|
|
552
541
|
const data = await res.json();
|
|
553
542
|
readX402Receipt(res); // { success, txid, payer, network } | null
|
|
@@ -558,7 +547,7 @@ Or a small client returning `{ data, payment }`:
|
|
|
558
547
|
```typescript
|
|
559
548
|
import { createX402Client } from "@secondlayer/sdk";
|
|
560
549
|
|
|
561
|
-
const sl = createX402Client({ account
|
|
550
|
+
const sl = createX402Client({ account }); // baseUrl defaults to http://127.0.0.1:3800
|
|
562
551
|
const { data, payment } = await sl.get("/v1/index/events", {
|
|
563
552
|
query: { event_type: "ft_transfer" },
|
|
564
553
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { SubgraphAgentSchema, SubgraphSpecOptions } from "@secondlayer/shared/su
|
|
|
4
4
|
import { InferSubgraphClient } from "@secondlayer/subgraphs";
|
|
5
5
|
type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
6
6
|
interface SecondLayerOptions {
|
|
7
|
-
/** Base URL of the
|
|
7
|
+
/** Base URL of the instance API (trailing slashes are stripped). */
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
/** Bearer token for authenticated requests. */
|
|
10
10
|
apiKey?: string;
|
|
@@ -17,6 +17,9 @@ interface SecondLayerOptions {
|
|
|
17
17
|
/** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */
|
|
18
18
|
origin?: "cli" | "mcp" | "session";
|
|
19
19
|
}
|
|
20
|
+
/** Product default: the local one-box API. Override with `baseUrl` or `SL_API_URL`. */
|
|
21
|
+
declare const LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
22
|
+
declare function resolveBaseUrl(explicit?: string): string;
|
|
20
23
|
/** Resolve the credential a client should use. An explicit `apiKey` option
|
|
21
24
|
* always wins — including an explicit `""`, which is how you opt a client
|
|
22
25
|
* back into keyless reads on a machine that has a key exported. Otherwise
|
|
@@ -3284,11 +3287,12 @@ type X402Fetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
|
3284
3287
|
*
|
|
3285
3288
|
* @example
|
|
3286
3289
|
* const x402fetch = withX402(fetch, { account });
|
|
3287
|
-
* const res = await x402fetch("
|
|
3290
|
+
* const res = await x402fetch("http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer");
|
|
3288
3291
|
*/
|
|
3289
3292
|
declare function withX402(baseFetch: typeof fetch, opts: WithX402Options): X402Fetch;
|
|
3290
3293
|
type X402ClientOptions = WithX402Options & {
|
|
3291
|
-
|
|
3294
|
+
/** Instance API. Defaults to {@link resolveBaseUrl}. */
|
|
3295
|
+
baseUrl?: string;
|
|
3292
3296
|
/** Override the underlying fetch (tests). */
|
|
3293
3297
|
fetch?: typeof fetch;
|
|
3294
3298
|
};
|
|
@@ -3311,7 +3315,7 @@ type X402Client = {
|
|
|
3311
3315
|
* parsed JSON plus the settlement receipt.
|
|
3312
3316
|
*
|
|
3313
3317
|
* @example
|
|
3314
|
-
* const sl = createX402Client({ account, baseUrl: "
|
|
3318
|
+
* const sl = createX402Client({ account, baseUrl: "http://127.0.0.1:3800" });
|
|
3315
3319
|
* const { data, payment } = await sl.get("/v1/index/events", { query: { event_type: "ft_transfer" } });
|
|
3316
3320
|
*/
|
|
3317
3321
|
declare function createX402Client(opts: X402ClientOptions): X402Client;
|
|
@@ -3532,4 +3536,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
3532
3536
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
3533
3537
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
3534
3538
|
declare function decodeClarityValue(hex: string): unknown;
|
|
3535
|
-
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 };
|
|
3539
|
+
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, selectOffer, resolveBaseUrl, 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, LOCAL_API_URL, 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
|
@@ -156,7 +156,17 @@ function isByoBreakingDetails(x) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// src/base.ts
|
|
159
|
-
var
|
|
159
|
+
var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
160
|
+
function resolveBaseUrl(explicit) {
|
|
161
|
+
if (explicit && explicit.length > 0)
|
|
162
|
+
return explicit.replace(/\/+$/, "");
|
|
163
|
+
if (typeof process !== "undefined") {
|
|
164
|
+
const fromEnv = process.env?.SL_API_URL || process.env?.SECONDLAYER_API_URL;
|
|
165
|
+
if (fromEnv)
|
|
166
|
+
return fromEnv.replace(/\/+$/, "");
|
|
167
|
+
}
|
|
168
|
+
return LOCAL_API_URL;
|
|
169
|
+
}
|
|
160
170
|
function resolveApiKey(apiKey) {
|
|
161
171
|
if (apiKey !== undefined)
|
|
162
172
|
return apiKey;
|
|
@@ -184,7 +194,7 @@ class BaseClient {
|
|
|
184
194
|
origin;
|
|
185
195
|
fetchImpl;
|
|
186
196
|
constructor(options = {}) {
|
|
187
|
-
this.baseUrl = (options.baseUrl
|
|
197
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl);
|
|
188
198
|
this.apiKey = resolveApiKey(options.apiKey);
|
|
189
199
|
this.origin = options.origin ?? "cli";
|
|
190
200
|
this.fetchImpl = options.fetchImpl ?? ((...args) => fetch(...args));
|
|
@@ -1721,7 +1731,6 @@ function streamsFilters(params) {
|
|
|
1721
1731
|
filters: params.filters
|
|
1722
1732
|
};
|
|
1723
1733
|
}
|
|
1724
|
-
var DEFAULT_STREAMS_BASE_URL = "https://api.secondlayer.tools";
|
|
1725
1734
|
function normalizeBaseUrl(baseUrl) {
|
|
1726
1735
|
return baseUrl.replace(/\/+$/, "");
|
|
1727
1736
|
}
|
|
@@ -1761,7 +1770,7 @@ async function mapStreamsError(response) {
|
|
|
1761
1770
|
throw new ValidationError(errorMessage(body, `Streams request returned ${response.status}.`), response.status, body);
|
|
1762
1771
|
}
|
|
1763
1772
|
function createStreamsClient(options) {
|
|
1764
|
-
const baseUrl = normalizeBaseUrl(options.baseUrl
|
|
1773
|
+
const baseUrl = normalizeBaseUrl(resolveBaseUrl(options.baseUrl));
|
|
1765
1774
|
const fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init));
|
|
1766
1775
|
const verify = options.verify;
|
|
1767
1776
|
const verifyMode = verify === false ? "off" : verify === undefined ? "lenient" : "strict";
|
|
@@ -2539,7 +2548,7 @@ function withX402(baseFetch, opts) {
|
|
|
2539
2548
|
}
|
|
2540
2549
|
function createX402Client(opts) {
|
|
2541
2550
|
const f = withX402(opts.fetch ?? fetch, opts);
|
|
2542
|
-
const base = opts.baseUrl
|
|
2551
|
+
const base = resolveBaseUrl(opts.baseUrl);
|
|
2543
2552
|
async function request(method, path, o = {}) {
|
|
2544
2553
|
const qs = o.query ? `?${new URLSearchParams(o.query).toString()}` : "";
|
|
2545
2554
|
const init = { method };
|
|
@@ -2776,6 +2785,7 @@ export {
|
|
|
2776
2785
|
toJsonSafe,
|
|
2777
2786
|
shutdownSignal,
|
|
2778
2787
|
selectOffer,
|
|
2788
|
+
resolveBaseUrl,
|
|
2779
2789
|
resolveApiKey,
|
|
2780
2790
|
resolveAccountNonce,
|
|
2781
2791
|
readX402Receipt,
|
|
@@ -2825,6 +2835,7 @@ export {
|
|
|
2825
2835
|
SecondLayer,
|
|
2826
2836
|
RateLimitError,
|
|
2827
2837
|
Projects,
|
|
2838
|
+
LOCAL_API_URL,
|
|
2828
2839
|
Index,
|
|
2829
2840
|
DEFAULT_PREFER_ASSETS,
|
|
2830
2841
|
Cursor,
|
|
@@ -2835,5 +2846,5 @@ export {
|
|
|
2835
2846
|
ApiError
|
|
2836
2847
|
};
|
|
2837
2848
|
|
|
2838
|
-
//# debugId=
|
|
2849
|
+
//# debugId=00B669DC4969C3BE64756E2164756E21
|
|
2839
2850
|
//# sourceMappingURL=index.js.map
|