@secondlayer/sdk 10.2.0 → 10.3.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 +3 -2
- package/dist/index.d.ts +23 -28
- package/dist/index.js +51 -22
- package/dist/index.js.map +5 -5
- package/dist/streams/index.js +36 -14
- package/dist/streams/index.js.map +3 -3
- package/dist/subgraphs/index.d.ts +6 -2
- package/dist/subgraphs/index.js +47 -20
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ 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
|
|
18
|
+
// default baseUrl: http://127.0.0.1:3800 (or SECONDLAYER_API_URL)
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -245,8 +245,9 @@ and bootstrap remain CLI.
|
|
|
245
245
|
|
|
246
246
|
```typescript
|
|
247
247
|
const sl = new SecondLayer({
|
|
248
|
-
|
|
248
|
+
accountKey: process.env.SECONDLAYER_API_KEY,
|
|
249
249
|
});
|
|
250
|
+
// SECONDLAYER_API_KEY is the hosted account key (sk-sl_*). It is not the instance token.
|
|
250
251
|
|
|
251
252
|
const ref = await sl.archive.latest();
|
|
252
253
|
const partitions = sl.archive.partitions(ref, { dataset: "blocks" });
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,11 @@ type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<
|
|
|
6
6
|
interface SecondLayerOptions {
|
|
7
7
|
/** Base URL of the instance API (trailing slashes are stripped). */
|
|
8
8
|
baseUrl: string;
|
|
9
|
-
/** Bearer token for authenticated requests. */
|
|
9
|
+
/** Bearer token for authenticated instance requests (`INSTANCE_TOKEN`). */
|
|
10
10
|
apiKey?: string;
|
|
11
|
+
/** Hosted account key (`sk-sl_*`). Env `SECONDLAYER_API_KEY`. Used by
|
|
12
|
+
* `sl.archive` quote/fetch/credits, never by instance `/v1` or `/api`. */
|
|
13
|
+
accountKey?: string;
|
|
11
14
|
/** Fetch implementation. Tests and edge runtimes can provide their own. */
|
|
12
15
|
fetchImpl?: FetchLike;
|
|
13
16
|
/** Public base URL for Streams bulk parquet dumps (the cold backfill plane).
|
|
@@ -46,34 +49,23 @@ type RequestOptions = {
|
|
|
46
49
|
* signal's reason, an `AbortError` by default, never an `ApiError`. */
|
|
47
50
|
signal?: AbortSignal;
|
|
48
51
|
};
|
|
49
|
-
/** Product default: the local one-box API. Override with `baseUrl` or
|
|
52
|
+
/** Product default: the local one-box API. Override with `baseUrl` or
|
|
53
|
+
* `SECONDLAYER_API_URL`. */
|
|
50
54
|
declare const LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
55
|
+
/** Instance credential. `secondlayer init` writes this. */
|
|
56
|
+
declare const INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
57
|
+
/** Hosted account key (`sk-sl_*`) for api.secondlayer.tools. */
|
|
58
|
+
declare const ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
51
59
|
declare function resolveBaseUrl(explicit?: string): string;
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* legacy alias, kept working so existing exports and CI secrets don't break. */
|
|
56
|
-
declare const CREDENTIAL_ENV_VARS: readonly ["INSTANCE_TOKEN", "SL_API_KEY"];
|
|
57
|
-
/** Resolve the credential a client should use. Precedence, highest first:
|
|
58
|
-
*
|
|
59
|
-
* 1. an explicit `apiKey` option — including an explicit `""`, which is how
|
|
60
|
-
* you opt a client back into keyless reads on a machine that has a key
|
|
61
|
-
* exported;
|
|
62
|
-
* 2. `INSTANCE_TOKEN` — the canonical credential var, shared with the CLI
|
|
63
|
-
* and MCP server;
|
|
64
|
-
* 3. `SL_API_KEY` — legacy alias for the same value.
|
|
65
|
-
*
|
|
66
|
-
* Env values that are empty strings count as unset. Falling back to the env at
|
|
67
|
-
* all is what stops `new Index()` from silently running keyless and 402-ing on
|
|
68
|
-
* the first deep-history read.
|
|
69
|
-
*
|
|
70
|
-
* When both env vars are set to *different* non-empty values there is no
|
|
71
|
-
* correct silent answer, so `INSTANCE_TOKEN` wins and we warn once on stderr —
|
|
72
|
-
* the whole point of this precedence is that a misconfigured credential should
|
|
73
|
-
* never authenticate as nobody without saying so.
|
|
74
|
-
*
|
|
75
|
-
* Guarded for browsers and edge runtimes, where `process` is undefined. */
|
|
60
|
+
/** Resolve the instance credential. Precedence: explicit `apiKey` (including
|
|
61
|
+
* `""` for keyless) → `INSTANCE_TOKEN`. Does not read the hosted account key
|
|
62
|
+
* env vars. Guarded for browsers and edge runtimes. */
|
|
76
63
|
declare function resolveApiKey(apiKey?: string): string | undefined;
|
|
64
|
+
/** Resolve the hosted account key for archive quote/fetch/credits.
|
|
65
|
+
* Precedence: explicit `accountKey` → `SECONDLAYER_API_KEY` → `SL_API_KEY` /
|
|
66
|
+
* `SL_ARCHIVE_API_KEY` (one-release warn-fallbacks). Does not read
|
|
67
|
+
* `INSTANCE_TOKEN`. */
|
|
68
|
+
declare function resolveAccountKey(accountKey?: string): string | undefined;
|
|
77
69
|
declare abstract class BaseClient {
|
|
78
70
|
protected baseUrl: string;
|
|
79
71
|
protected apiKey?: string;
|
|
@@ -285,6 +277,7 @@ type ArchiveVerifyResult = {
|
|
|
285
277
|
reason?: string;
|
|
286
278
|
};
|
|
287
279
|
import { RangeDigest } from "@secondlayer/shared/archive/range-digest";
|
|
280
|
+
import { ArchiveStatus } from "@secondlayer/shared/archive/status";
|
|
288
281
|
type ArchiveDataset = "blocks" | "transactions" | "events";
|
|
289
282
|
type ArchiveFlow = "bootstrap" | "repair";
|
|
290
283
|
type ArchivePartition = {
|
|
@@ -354,7 +347,7 @@ type ArchiveLoadOptions = {
|
|
|
354
347
|
type ArchiveClient = {
|
|
355
348
|
latest(against?: string, opts?: ArchiveLoadOptions): Promise<LoadedArchive>;
|
|
356
349
|
load(against: string, opts?: ArchiveLoadOptions): Promise<LoadedArchive>;
|
|
357
|
-
status(): Promise<
|
|
350
|
+
status(): Promise<ArchiveStatus>;
|
|
358
351
|
partitions(ref: LoadedArchive, filter?: {
|
|
359
352
|
dataset?: ArchiveDataset;
|
|
360
353
|
fromBlock?: number;
|
|
@@ -2975,7 +2968,9 @@ declare function shutdownSignal(options?: {
|
|
|
2975
2968
|
signals?: readonly ("SIGTERM" | "SIGINT")[];
|
|
2976
2969
|
}): AbortSignal;
|
|
2977
2970
|
type CreateArchiveClientOptions = {
|
|
2971
|
+
/** @deprecated Prefer `accountKey`. Kept one release as an alias. */
|
|
2978
2972
|
apiKey?: string;
|
|
2973
|
+
accountKey?: string;
|
|
2979
2974
|
fetchImpl?: FetchLike;
|
|
2980
2975
|
archiveBaseUrl?: string;
|
|
2981
2976
|
archiveOpsUrl?: string;
|
|
@@ -3141,4 +3136,4 @@ declare function verifySecondlayerSignature(rawBody: string, headers: WebhookHea
|
|
|
3141
3136
|
declare function decodeChainWebhook(rawBody: string): ChainWebhookDelivery;
|
|
3142
3137
|
import { RewardSet as RewardSet2 } from "@secondlayer/shared/node/consensus";
|
|
3143
3138
|
import { decodeClarityValue, toJsonSafe } from "@secondlayer/shared/streams-rows";
|
|
3144
|
-
export { verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, resolveBaseUrl, resolveApiKey, 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, createStreamsClient, createArchiveClient, contextField, consumerHealth, consumeIndexFeed, WithSinkTx, WebhookHeaderInput, WalkOptions, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, 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, StreamsTip, StreamsSubscription, 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, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayerArchive, SecondLayer, 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, RequestOptions, ReplayResult2 as ReplayResult, RateLimitError, PublicStatus2 as PublicStatus, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload2 as NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, LoadedArchive, LOCAL_API_URL, InsufficientArchiveCreditsError, InstanceStatus, InstanceState, InstanceIssue, InstanceDiagnosis3 as InstanceDiagnosis, InstanceClient, 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, INDEX_MAX_PAGE_SIZE, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload2 as 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_REQUEST_TIMEOUT_MS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateArchiveClientOptions, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextFieldError, ContextField, 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,
|
|
3139
|
+
export { verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, resolveBaseUrl, resolveApiKey, resolveAccountKey, 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, createStreamsClient, createArchiveClient, contextField, consumerHealth, consumeIndexFeed, WithSinkTx, WebhookHeaderInput, WalkOptions, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, 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, StreamsTip, StreamsSubscription, 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, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayerArchive, SecondLayer, 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, RequestOptions, ReplayResult2 as ReplayResult, RateLimitError, PublicStatus2 as PublicStatus, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload2 as NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, LoadedArchive, LOCAL_API_URL, InsufficientArchiveCreditsError, InstanceStatus, InstanceState, InstanceIssue, InstanceDiagnosis3 as InstanceDiagnosis, InstanceClient, 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, INSTANCE_TOKEN_ENV, INDEX_MAX_PAGE_SIZE, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload2 as 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_REQUEST_TIMEOUT_MS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateArchiveClientOptions, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextFieldError, ContextField, 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, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ArchiveVerifyResult, ArchiveVerifyRangeStatus, ArchiveVerifyInput, ArchiveStatus, ArchiveSignatureError, ArchiveQuote, ArchivePartition, ArchiveManifest, ArchiveLoadOptions, ArchiveGateNotConfiguredError, ArchiveFlow, ArchiveFetchResult, ArchiveFetchItem, ArchiveDataset, ArchiveCreditsBalance, ArchiveClient, ArchiveAuthError, ApiError, ActiveSubgraphOperation, ACCOUNT_KEY_ENV };
|
package/dist/index.js
CHANGED
|
@@ -172,33 +172,55 @@ function raceAbort(promise, signal) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
var LOCAL_API_URL = "http://127.0.0.1:3800";
|
|
175
|
+
var INSTANCE_TOKEN_ENV = "INSTANCE_TOKEN";
|
|
176
|
+
var ACCOUNT_KEY_ENV = "SECONDLAYER_API_KEY";
|
|
177
|
+
var warnedUrlAlias = false;
|
|
175
178
|
function resolveBaseUrl(explicit) {
|
|
176
179
|
if (explicit && explicit.length > 0)
|
|
177
180
|
return explicit.replace(/\/+$/, "");
|
|
178
181
|
if (typeof process !== "undefined") {
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
181
|
-
return
|
|
182
|
+
const primary = process.env?.SECONDLAYER_API_URL || undefined;
|
|
183
|
+
if (primary)
|
|
184
|
+
return primary.replace(/\/+$/, "");
|
|
185
|
+
const legacy = process.env?.SL_API_URL || undefined;
|
|
186
|
+
if (legacy) {
|
|
187
|
+
if (!warnedUrlAlias) {
|
|
188
|
+
warnedUrlAlias = true;
|
|
189
|
+
console.warn("[secondlayer] SL_API_URL is a legacy alias of SECONDLAYER_API_URL; using the alias this once.");
|
|
190
|
+
}
|
|
191
|
+
return legacy.replace(/\/+$/, "");
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
return LOCAL_API_URL;
|
|
184
195
|
}
|
|
185
|
-
var CREDENTIAL_ENV_VARS = ["INSTANCE_TOKEN", "SL_API_KEY"];
|
|
186
|
-
var warnedConflicts = new Set;
|
|
187
196
|
function resolveApiKey(apiKey) {
|
|
188
197
|
if (apiKey !== undefined)
|
|
189
198
|
return apiKey;
|
|
190
199
|
if (typeof process === "undefined")
|
|
191
200
|
return;
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
const token = process.env?.INSTANCE_TOKEN || undefined;
|
|
202
|
+
return token;
|
|
203
|
+
}
|
|
204
|
+
var warnedArchiveAlias = false;
|
|
205
|
+
function resolveAccountKey(accountKey) {
|
|
206
|
+
if (accountKey !== undefined)
|
|
207
|
+
return accountKey;
|
|
208
|
+
if (typeof process === "undefined")
|
|
209
|
+
return;
|
|
210
|
+
const primary = process.env?.SECONDLAYER_API_KEY || undefined;
|
|
211
|
+
const slAlias = process.env?.SL_API_KEY || undefined;
|
|
212
|
+
const archiveAlias = process.env?.SL_ARCHIVE_API_KEY || undefined;
|
|
213
|
+
if (primary)
|
|
214
|
+
return primary;
|
|
215
|
+
const legacy = slAlias ?? archiveAlias;
|
|
216
|
+
if (legacy) {
|
|
217
|
+
if (!warnedArchiveAlias) {
|
|
218
|
+
warnedArchiveAlias = true;
|
|
219
|
+
console.warn("[secondlayer] SL_API_KEY / SL_ARCHIVE_API_KEY are legacy aliases of SECONDLAYER_API_KEY; using the alias this once.");
|
|
220
|
+
}
|
|
221
|
+
return legacy;
|
|
200
222
|
}
|
|
201
|
-
return
|
|
223
|
+
return;
|
|
202
224
|
}
|
|
203
225
|
function seg(value) {
|
|
204
226
|
return encodeURIComponent(String(value));
|
|
@@ -857,6 +879,7 @@ var OFFICIAL_ARCHIVE_HOST = "archive.secondlayer.tools";
|
|
|
857
879
|
var DEFAULT_ARCHIVE_BASE_URL = "https://archive.secondlayer.tools";
|
|
858
880
|
var DEFAULT_ARCHIVE_OPS_URL = "https://api.secondlayer.tools";
|
|
859
881
|
var MAX_FETCH_BATCH = 64;
|
|
882
|
+
var ARCHIVE_CREDENTIAL_RE = /^s[ks]-sl_/;
|
|
860
883
|
function quoteFromBody(body) {
|
|
861
884
|
return {
|
|
862
885
|
partitions: body.partitions,
|
|
@@ -873,7 +896,7 @@ function stripSlash(url) {
|
|
|
873
896
|
return url.replace(/\/+$/, "");
|
|
874
897
|
}
|
|
875
898
|
function createArchiveClient(options = {}) {
|
|
876
|
-
const
|
|
899
|
+
const accountKey = resolveAccountKey(options.accountKey ?? options.apiKey);
|
|
877
900
|
const fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init));
|
|
878
901
|
const archiveBaseUrl = stripSlash(options.archiveBaseUrl ?? DEFAULT_ARCHIVE_BASE_URL);
|
|
879
902
|
const archiveOpsUrl = stripSlash(options.archiveOpsUrl ?? DEFAULT_ARCHIVE_OPS_URL);
|
|
@@ -921,8 +944,12 @@ function createArchiveClient(options = {}) {
|
|
|
921
944
|
const headers = {
|
|
922
945
|
"Content-Type": "application/json"
|
|
923
946
|
};
|
|
924
|
-
if (authed &&
|
|
925
|
-
|
|
947
|
+
if (authed && accountKey) {
|
|
948
|
+
if (!ARCHIVE_CREDENTIAL_RE.test(accountKey)) {
|
|
949
|
+
throw new ArchiveAuthError("archive ops need SECONDLAYER_API_KEY (sk-sl_*), not INSTANCE_TOKEN");
|
|
950
|
+
}
|
|
951
|
+
headers.Authorization = `Bearer ${accountKey}`;
|
|
952
|
+
}
|
|
926
953
|
const response = await fetchImpl(`${archiveOpsUrl}${path}`, {
|
|
927
954
|
method,
|
|
928
955
|
headers,
|
|
@@ -956,7 +983,7 @@ function createArchiveClient(options = {}) {
|
|
|
956
983
|
if (!response.ok) {
|
|
957
984
|
throw new ApiError(response.status, `Could not fetch archive status (${response.status}).`);
|
|
958
985
|
}
|
|
959
|
-
return response.json();
|
|
986
|
+
return await response.json();
|
|
960
987
|
}
|
|
961
988
|
function partitions(ref, filter) {
|
|
962
989
|
let list = ref.manifest.partitions ?? [];
|
|
@@ -2518,7 +2545,7 @@ class SecondLayer extends BaseClient {
|
|
|
2518
2545
|
const request = (method, path, body) => this.request(method, path, body);
|
|
2519
2546
|
this.archive = {
|
|
2520
2547
|
...createArchiveClient({
|
|
2521
|
-
|
|
2548
|
+
accountKey: options.accountKey,
|
|
2522
2549
|
fetchImpl: options.fetchImpl,
|
|
2523
2550
|
archiveBaseUrl: options.archiveBaseUrl,
|
|
2524
2551
|
archiveOpsUrl: options.archiveOpsUrl
|
|
@@ -2850,6 +2877,7 @@ export {
|
|
|
2850
2877
|
shutdownSignal,
|
|
2851
2878
|
resolveBaseUrl,
|
|
2852
2879
|
resolveApiKey,
|
|
2880
|
+
resolveAccountKey,
|
|
2853
2881
|
parseRetryAfter,
|
|
2854
2882
|
isStxTransfer,
|
|
2855
2883
|
isStxMint,
|
|
@@ -2894,17 +2922,18 @@ export {
|
|
|
2894
2922
|
LOCAL_API_URL,
|
|
2895
2923
|
InsufficientArchiveCreditsError,
|
|
2896
2924
|
Index,
|
|
2925
|
+
INSTANCE_TOKEN_ENV,
|
|
2897
2926
|
INDEX_MAX_PAGE_SIZE,
|
|
2898
2927
|
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
2899
2928
|
Cursor,
|
|
2900
2929
|
Contracts,
|
|
2901
|
-
CREDENTIAL_ENV_VARS,
|
|
2902
2930
|
AuthError,
|
|
2903
2931
|
ArchiveSignatureError,
|
|
2904
2932
|
ArchiveGateNotConfiguredError,
|
|
2905
2933
|
ArchiveAuthError,
|
|
2906
|
-
ApiError
|
|
2934
|
+
ApiError,
|
|
2935
|
+
ACCOUNT_KEY_ENV
|
|
2907
2936
|
};
|
|
2908
2937
|
|
|
2909
|
-
//# debugId=
|
|
2938
|
+
//# debugId=18BFA99012559AFD64756E2164756E21
|
|
2910
2939
|
//# sourceMappingURL=index.js.map
|