@secondlayer/sdk 10.2.0 → 10.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/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 SL_API_URL)
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
- apiKey: process.env.SL_API_KEY, // account key sk-sl_* for quote/fetch/credits
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 `SL_API_URL`. */
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
- /** Credential env vars, highest precedence first. `INSTANCE_TOKEN` is the
53
- * canonical name — it is what `secondlayer init` writes into `.env.local` and
54
- * what the instance API validates bearer tokens against. `SL_API_KEY` is a
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;
@@ -2975,7 +2967,9 @@ declare function shutdownSignal(options?: {
2975
2967
  signals?: readonly ("SIGTERM" | "SIGINT")[];
2976
2968
  }): AbortSignal;
2977
2969
  type CreateArchiveClientOptions = {
2970
+ /** @deprecated Prefer `accountKey`. Kept one release as an alias. */
2978
2971
  apiKey?: string;
2972
+ accountKey?: string;
2979
2973
  fetchImpl?: FetchLike;
2980
2974
  archiveBaseUrl?: string;
2981
2975
  archiveOpsUrl?: string;
@@ -3141,4 +3135,4 @@ declare function verifySecondlayerSignature(rawBody: string, headers: WebhookHea
3141
3135
  declare function decodeChainWebhook(rawBody: string): ChainWebhookDelivery;
3142
3136
  import { RewardSet as RewardSet2 } from "@secondlayer/shared/node/consensus";
3143
3137
  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, CREDENTIAL_ENV_VARS, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ArchiveVerifyResult, ArchiveVerifyRangeStatus, ArchiveVerifyInput, ArchiveSignatureError, ArchiveQuote, ArchivePartition, ArchiveManifest, ArchiveLoadOptions, ArchiveGateNotConfiguredError, ArchiveFlow, ArchiveFetchResult, ArchiveFetchItem, ArchiveDataset, ArchiveCreditsBalance, ArchiveClient, ArchiveAuthError, ApiError, ActiveSubgraphOperation };
3138
+ 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, 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 fromEnv = process.env?.SL_API_URL || process.env?.SECONDLAYER_API_URL;
180
- if (fromEnv)
181
- return fromEnv.replace(/\/+$/, "");
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 instanceToken = process.env?.INSTANCE_TOKEN || undefined;
193
- const legacyKey = process.env?.SL_API_KEY || undefined;
194
- if (instanceToken && legacyKey && instanceToken !== legacyKey) {
195
- const pair = `${instanceToken}\x00${legacyKey}`;
196
- if (!warnedConflicts.has(pair)) {
197
- warnedConflicts.add(pair);
198
- console.warn("[secondlayer] INSTANCE_TOKEN and SL_API_KEY are set to different values — using INSTANCE_TOKEN (SL_API_KEY is a legacy alias for it).");
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 instanceToken ?? legacyKey;
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 apiKey = resolveApiKey(options.apiKey);
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 && apiKey)
925
- headers.Authorization = `Bearer ${apiKey}`;
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,
@@ -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
- apiKey: this.apiKey,
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=ACBBAC86B270FAEA64756E2164756E21
2938
+ //# debugId=4C4D7DCC9A7B5FE064756E2164756E21
2910
2939
  //# sourceMappingURL=index.js.map