@secondlayer/shared 11.7.1 → 11.8.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/dist/src/archive/copy-loader.d.ts +1 -1
- package/dist/src/archive/copy-loader.js +4 -20
- package/dist/src/archive/copy-loader.js.map +2 -2
- package/dist/src/archive/derived-stage-report.d.ts +1 -1
- package/dist/src/archive/derived-stage-report.js +3 -19
- package/dist/src/archive/derived-stage-report.js.map +2 -2
- package/dist/src/archive/disk-guard.d.ts +1 -1
- package/dist/src/archive/disk-guard.js +3 -19
- package/dist/src/archive/disk-guard.js.map +2 -2
- package/dist/src/archive/instance-diagnosis.d.ts +1 -1
- package/dist/src/archive/instance-diagnosis.js +6 -22
- package/dist/src/archive/instance-diagnosis.js.map +2 -2
- package/dist/src/archive/key-registry.d.ts +1 -1
- package/dist/src/archive/key-registry.js +12 -12
- package/dist/src/archive/key-registry.js.map +1 -1
- package/dist/src/archive/per-height-digest.d.ts +1 -1
- package/dist/src/archive/per-height-digest.js +3 -17
- package/dist/src/archive/per-height-digest.js.map +5 -5
- package/dist/src/archive/progress.d.ts +1 -1
- package/dist/src/archive/progress.js +4 -20
- package/dist/src/archive/progress.js.map +2 -2
- package/dist/src/archive/range-digest.d.ts +2 -3
- package/dist/src/archive/range-digest.js +4 -20
- package/dist/src/archive/range-digest.js.map +2 -2
- package/dist/src/archive/reference.d.ts +1 -1
- package/dist/src/archive/reference.js +14 -12
- package/dist/src/archive/reference.js.map +5 -5
- package/dist/src/archive/root-key.d.ts +1 -1
- package/dist/src/archive/root-key.js +3 -19
- package/dist/src/archive/root-key.js.map +2 -2
- package/dist/src/archive/semantic-digest-builder.d.ts +2 -3
- package/dist/src/archive/semantic-digest-builder.js +5 -19
- package/dist/src/archive/semantic-digest-builder.js.map +5 -5
- package/dist/src/archive/semantic-digest.d.ts +1 -1
- package/dist/src/archive/semantic-digest.js +4 -20
- package/dist/src/archive/semantic-digest.js.map +2 -2
- package/dist/src/archive/status.d.ts +1 -1
- package/dist/src/archive/status.js +4 -20
- package/dist/src/archive/status.js.map +2 -2
- package/dist/src/coverage/index.d.ts +1 -2
- package/dist/src/coverage/index.js +80 -96
- package/dist/src/coverage/index.js.map +2 -2
- package/dist/src/crypto/ed25519.d.ts +1 -1
- package/dist/src/crypto/ed25519.js +13 -13
- package/dist/src/crypto/ed25519.js.map +1 -1
- package/dist/src/crypto/hmac.d.ts +1 -1
- package/dist/src/crypto/hmac.js +9 -9
- package/dist/src/crypto/hmac.js.map +1 -1
- package/dist/src/crypto/secondlayer-webhook.d.ts +1 -1
- package/dist/src/crypto/secondlayer-webhook.js +14 -14
- package/dist/src/crypto/secondlayer-webhook.js.map +2 -2
- package/dist/src/crypto/secrets.d.ts +1 -1
- package/dist/src/crypto/secrets.js +15 -29
- package/dist/src/crypto/secrets.js.map +5 -5
- package/dist/src/crypto/standard-webhooks.d.ts +1 -1
- package/dist/src/crypto/standard-webhooks.js +3 -19
- package/dist/src/crypto/standard-webhooks.js.map +2 -2
- package/dist/src/db/index.d.ts +18 -19
- package/dist/src/db/index.js +40 -55
- package/dist/src/db/index.js.map +5 -5
- package/dist/src/db/jsonb.d.ts +1 -1
- package/dist/src/db/jsonb.js +3 -19
- package/dist/src/db/jsonb.js.map +2 -2
- package/dist/src/db/queries/chain-reorgs.d.ts +1 -2
- package/dist/src/db/queries/chain-reorgs.js +27 -42
- package/dist/src/db/queries/chain-reorgs.js.map +5 -5
- package/dist/src/db/queries/contracts.d.ts +1 -2
- package/dist/src/db/queries/contracts.js +9 -23
- package/dist/src/db/queries/contracts.js.map +5 -5
- package/dist/src/db/queries/instance.d.ts +1 -2
- package/dist/src/db/queries/instance.js +7 -23
- package/dist/src/db/queries/instance.js.map +2 -2
- package/dist/src/db/queries/integrity.d.ts +1 -2
- package/dist/src/db/queries/integrity.js +5 -21
- package/dist/src/db/queries/integrity.js.map +2 -2
- package/dist/src/db/queries/subgraph-gaps.d.ts +1 -2
- package/dist/src/db/queries/subgraph-gaps.js +5 -21
- package/dist/src/db/queries/subgraph-gaps.js.map +2 -2
- package/dist/src/db/queries/subgraph-operations.d.ts +1 -2
- package/dist/src/db/queries/subgraph-operations.js +17 -33
- package/dist/src/db/queries/subgraph-operations.js.map +2 -2
- package/dist/src/db/queries/subgraphs.d.ts +2 -14
- package/dist/src/db/queries/subgraphs.js +15 -37
- package/dist/src/db/queries/subgraphs.js.map +5 -5
- package/dist/src/db/queries/sync-scope.d.ts +1 -2
- package/dist/src/db/queries/sync-scope.js +6 -22
- package/dist/src/db/queries/sync-scope.js.map +2 -2
- package/dist/src/db/queries/webhooks.d.ts +1 -2
- package/dist/src/db/queries/webhooks.js +54 -50
- package/dist/src/db/queries/webhooks.js.map +5 -5
- package/dist/src/db/schema.d.ts +1 -2
- package/dist/src/env.d.ts +1 -1
- package/dist/src/env.js +7 -23
- package/dist/src/env.js.map +2 -2
- package/dist/src/errors.d.ts +1 -1
- package/dist/src/errors.js +15 -31
- package/dist/src/errors.js.map +2 -2
- package/dist/src/index-http.d.ts +1 -1
- package/dist/src/index-http.js +3 -19
- package/dist/src/index-http.js.map +2 -2
- package/dist/src/index-internal-auth.d.ts +1 -1
- package/dist/src/index-internal-auth.js +7 -23
- package/dist/src/index-internal-auth.js.map +2 -2
- package/dist/src/index.d.ts +136 -149
- package/dist/src/index.js +259 -313
- package/dist/src/index.js.map +12 -12
- package/dist/src/leader.d.ts +1 -1
- package/dist/src/leader.js +7 -21
- package/dist/src/leader.js.map +5 -5
- package/dist/src/logger.js +1 -17
- package/dist/src/logger.js.map +2 -2
- package/dist/src/mode.d.ts +1 -1
- package/dist/src/mode.js +5 -21
- package/dist/src/mode.js.map +2 -2
- package/dist/src/node/archive-client.d.ts +1 -1
- package/dist/src/node/archive-client.js +9 -23
- package/dist/src/node/archive-client.js.map +5 -5
- package/dist/src/node/client.d.ts +1 -1
- package/dist/src/node/client.js +4 -18
- package/dist/src/node/client.js.map +5 -5
- package/dist/src/node/consensus.d.ts +1 -1
- package/dist/src/node/consensus.js +5 -21
- package/dist/src/node/consensus.js.map +2 -2
- package/dist/src/node/hiro-client.d.ts +1 -1
- package/dist/src/node/hiro-client.js +1 -17
- package/dist/src/node/hiro-client.js.map +2 -2
- package/dist/src/node/hiro-pg-client.js +1 -17
- package/dist/src/node/hiro-pg-client.js.map +2 -2
- package/dist/src/node/local-client.d.ts +1 -2
- package/dist/src/node/local-client.js +3 -19
- package/dist/src/node/local-client.js.map +2 -2
- package/dist/src/node/nakamoto.d.ts +1 -1
- package/dist/src/node/nakamoto.js +12 -28
- package/dist/src/node/nakamoto.js.map +2 -2
- package/dist/src/queue/listener.d.ts +1 -1
- package/dist/src/queue/listener.js +4 -20
- package/dist/src/queue/listener.js.map +2 -2
- package/dist/src/runtime/index.d.ts +1 -1
- package/dist/src/runtime/index.js +51 -67
- package/dist/src/runtime/index.js.map +2 -2
- package/dist/src/schemas/index.d.ts +1 -4
- package/dist/src/schemas/index.js +19 -37
- package/dist/src/schemas/index.js.map +3 -3
- package/dist/src/schemas/subgraphs.d.ts +1 -4
- package/dist/src/schemas/subgraphs.js +1 -18
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/dist/src/schemas/webhooks.d.ts +1 -1
- package/dist/src/schemas/webhooks.js +21 -37
- package/dist/src/schemas/webhooks.js.map +2 -2
- package/dist/src/streams-bulk-manifest.d.ts +1 -1
- package/dist/src/streams-bulk-manifest.js +9 -9
- package/dist/src/streams-bulk-manifest.js.map +1 -1
- package/dist/src/streams-rows/index.d.ts +1 -1
- package/dist/src/streams-rows/index.js +32 -48
- package/dist/src/streams-rows/index.js.map +2 -2
- package/dist/src/subgraphs/spec.d.ts +1 -11
- package/dist/src/subgraphs/spec.js +27 -93
- package/dist/src/subgraphs/spec.js.map +3 -3
- package/dist/src/types.d.ts +1 -1
- package/migrations/0136_drop_subgraph_visibility.ts +34 -0
- package/package.json +1 -1
package/dist/src/index-http.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __returnValue = (v) => v;
|
|
4
|
-
function __exportSetter(name, newValue) {
|
|
5
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
-
}
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
set: __exportSetter.bind(all, name)
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
1
|
// src/index-internal-auth.ts
|
|
18
2
|
var INDEX_INTERNAL_TENANT_ID = "tenant_index_internal";
|
|
19
3
|
var INTERNAL_STREAMS_TENANT_ID = "tenant_streams_decode_internal";
|
|
@@ -189,9 +173,9 @@ function createInternalIndexHttpClient() {
|
|
|
189
173
|
});
|
|
190
174
|
}
|
|
191
175
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
IndexHttpClient,
|
|
177
|
+
createInternalIndexHttpClient
|
|
194
178
|
};
|
|
195
179
|
|
|
196
|
-
//# debugId=
|
|
180
|
+
//# debugId=DB848C152DF9051A64756E2164756E21
|
|
197
181
|
//# sourceMappingURL=index-http.js.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"// Internal service credentials for first-party consumers of /v1/index and\n// /v1/streams over HTTP (decoder, subgraph processor PublicApiBlockSource).\n// Seeded as internal tenants with NO account_id, so these reads are\n// unmetered (metering gates on account_id). Lives in shared so the API (seed)\n// and the consumers import it without a cycle.\n//\n// Resolution: STREAMS_INTERNAL_API_KEY / INDEX_INTERNAL_API_KEY, then\n// INSTANCE_TOKEN (OSS). No committed fallback. Empty-string env values fall\n// through (`trim()`, then empty): compose interpolates\n// `${STREAMS_INTERNAL_API_KEY:-}` which is \"\" when unset.\n//\n// Archive keys must not use the `sk-sl_` prefix; generate with `sl-int_`.\n// OSS compose should omit the internal env and send INSTANCE_TOKEN.\nexport const INDEX_INTERNAL_TENANT_ID = \"tenant_index_internal\";\nexport const INTERNAL_STREAMS_TENANT_ID = \"tenant_streams_decode_internal\";\n\nconst DEFAULT_INTERNAL_INDEX_BASE_URL = \"http://api:3800\";\n\nconst MISSING_INTERNAL_STREAMS_API_KEY =\n\t\"Set STREAMS_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Empty env no longer falls back to a committed secret.\";\n\nconst MISSING_INTERNAL_INDEX_API_KEY =\n\t\"Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads go out anonymously and are capped at the last 24h, so any seek into older history 402s.\";\n\nexport function defaultInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.INDEX_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\nexport function defaultInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.STREAMS_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\n/**\n * Platform-mode Index consumer: refuse to run with neither credential.\n *\n * A keyless Index read is not an error — it is an anonymous read, and the API\n * serves it for the last 24h (`api/src/index/free-window.ts`). That makes a\n * missing key invisible right up until a consumer's cursor falls out of the\n * window, at which point every read 402s and the container goes unhealthy,\n * possibly weeks after the misconfiguration. Callers that seek older history\n * on a platform-mode instance should fail here at startup instead.\n *\n * Self-hosted (oss/dedicated) instances are not gated, so they must NOT call\n * this — `defaultInternalIndexApiKey()` returning undefined is correct there.\n */\nexport function requireInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalIndexApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_INDEX_API_KEY);\n\treturn key;\n}\n\n/** Decoder startup: refuse to run with neither credential. */\nexport function requireInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalStreamsApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_STREAMS_API_KEY);\n\treturn key;\n}\n\n/** Shared env contract for decoder + subgraph HTTP dogfood. */\nexport function defaultInternalIndexBaseUrl(): string {\n\treturn (\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ||\n\t\tprocess.env.STREAMS_API_URL ||\n\t\tDEFAULT_INTERNAL_INDEX_BASE_URL\n\t);\n}\n",
|
|
6
6
|
"import {\n\tdefaultInternalIndexApiKey,\n\tdefaultInternalIndexBaseUrl,\n\tdefaultInternalStreamsApiKey,\n} from \"./index-internal-auth.ts\";\n\n/**\n * Low-level transport for the public Index (`/v1/index`) + Streams clock\n * (`/v1/streams`) HTTP APIs: cursor-paginated reads, tip, reorgs. Lives in\n * `shared` (a leaf both the SDK and the subgraph runtime depend on) so the wire\n * format has one home and no package cycle. The SDK's ergonomic client should\n * eventually consume these row types too (see the plan's convergence task).\n *\n * This is intentionally minimal — just the GETs the subgraph runtime's\n * PublicApiBlockSource needs. It is NOT the SDK's full client (walk/consume/\n * retries/auth resolution).\n */\n\nconst PAGE_LIMIT = 1000;\n\n// Transport resilience for the streams-index data plane. The api runs N>1\n// replicas behind Caddy; during a rolling deploy one replica is briefly\n// unreachable, surfacing as a thrown fetch (connection refused/reset) or a\n// Caddy 502/503/504 while it fails over. Retrying a few times with backoff\n// makes a single-replica recreate transparent to the subgraph-processor /\n// decoder — closing the processors-depend-on-api coupling.\nconst MAX_ATTEMPTS = 4;\nconst RETRY_BASE_MS = 150;\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nconst delay = (ms: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(resolve, ms));\n\ntype Envelope<K extends string, T> = {\n\t[P in K]: T[];\n} & { next_cursor: string | null };\n\n// ── Index API wire shapes (single source of truth) ─────────────────────────\nexport type IndexBlockRow = {\n\tblock_height: number;\n\tblock_hash: string;\n\tparent_hash: string;\n\tburn_block_height: number;\n\tburn_block_hash: string | null;\n\t/** Nakamoto StacksBlockId. Absent from pre-2026-07 API deployments. */\n\tindex_block_hash?: string | null;\n\tblock_time: string | null;\n};\n\ntype IndexEventCommon = {\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index?: number;\n\tevent_index: number;\n\tcontract_id: string | null;\n\t/** Submitting-tx context — present only when the read passed `tx_context=true`.\n\t * Lets a consumer build the tx for `ctx.tx` without a separate\n\t * walkTransactions (the ~37x reindex over-fetch; see indexing-speed plan). */\n\ttx_sender?: string | null;\n\ttx_type?: string | null;\n\ttx_status?: string | null;\n\ttx_contract_id?: string | null;\n\ttx_function_name?: string | null;\n};\n\nexport type IndexEventRow = IndexEventCommon &\n\t(\n\t\t| {\n\t\t\t\tevent_type: \"ft_transfer\" | \"ft_mint\" | \"ft_burn\";\n\t\t\t\tasset_identifier: string;\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tamount: string;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"nft_transfer\" | \"nft_mint\" | \"nft_burn\";\n\t\t\t\tasset_identifier: string;\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tvalue: string;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"stx_transfer\" | \"stx_mint\" | \"stx_burn\";\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tamount: string;\n\t\t\t\tmemo?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"stx_lock\";\n\t\t\t\tsender: string;\n\t\t\t\tamount: string;\n\t\t\t\tpayload: { unlock_height: string | null };\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"print\";\n\t\t\t\tpayload: {\n\t\t\t\t\ttopic: string | null;\n\t\t\t\t\tvalue: unknown;\n\t\t\t\t\traw_value: string | null;\n\t\t\t\t};\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"nested_contract_call\";\n\t\t\t\tsender?: string | null;\n\t\t\t\tcaller: string;\n\t\t\t\tfunction_name: string;\n\t\t\t\tfunction_args?: unknown;\n\t\t\t\traw_result?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"var_set\";\n\t\t\t\tvar_name: string;\n\t\t\t\traw_value?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"map_set\" | \"map_insert\";\n\t\t\t\tmap: string;\n\t\t\t\traw_key?: string | null;\n\t\t\t\traw_value?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"map_delete\";\n\t\t\t\tmap: string;\n\t\t\t\traw_key?: string | null;\n\t\t }\n\t);\n\nexport type IndexTransactionRow = {\n\ttx_id: string;\n\tblock_height: number;\n\tblock_time?: string | null;\n\tburn_block_height?: number | null;\n\ttx_index: number;\n\ttx_type: string;\n\tsender: string;\n\tstatus: string;\n\tcontract_call?: {\n\t\tcontract_id: string;\n\t\tfunction_name: string;\n\t\tfunction_args_hex?: string[] | null;\n\t\tresult_hex?: string | null;\n\t} | null;\n\tsmart_contract?: { contract_id: string | null } | null;\n};\n\nexport type StreamsReorgRow = {\n\tid: string;\n\tdetected_at: string;\n\tfork_point_height: number;\n\torphaned_range: { from: string; to: string };\n\tnew_canonical_tip: string;\n};\n\nexport type IndexHttpOptions = {\n\t/** Base URL for /v1/index (the decoded data plane). */\n\tindexBaseUrl: string;\n\t/** Bearer for /v1/index. Empty/unset omits the header. */\n\tindexApiKey?: string;\n\t/** Base URL for /v1/streams (the canonical clock). */\n\tstreamsBaseUrl: string;\n\t/** Bearer for /v1/streams. Empty/unset omits the header. */\n\tstreamsApiKey?: string;\n};\n\nexport class IndexHttpClient {\n\tprivate readonly indexBaseUrl: string;\n\tprivate readonly indexApiKey: string | undefined;\n\tprivate readonly streamsBaseUrl: string;\n\tprivate readonly streamsApiKey: string | undefined;\n\n\tconstructor(opts: IndexHttpOptions) {\n\t\tthis.indexBaseUrl = opts.indexBaseUrl.replace(/\\/+$/, \"\");\n\t\tthis.indexApiKey = opts.indexApiKey ?? defaultInternalIndexApiKey();\n\t\tthis.streamsBaseUrl = opts.streamsBaseUrl.replace(/\\/+$/, \"\");\n\t\tthis.streamsApiKey = opts.streamsApiKey;\n\t}\n\n\tprivate async get<T>(url: string, apiKey: string | undefined): Promise<T> {\n\t\t// Index reads are anon — omit the header entirely when no key is set, so\n\t\t// an empty key reads anonymously rather than 401-ing as an invalid bearer.\n\t\tconst headers: Record<string, string> = apiKey\n\t\t\t? { authorization: `Bearer ${apiKey}` }\n\t\t\t: {};\n\t\tlet lastErr: unknown;\n\t\tfor (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {\n\t\t\tlet res: Response;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url, { headers });\n\t\t\t} catch (err) {\n\t\t\t\t// An explicit abort/cancel is intentional — surface it immediately\n\t\t\t\t// rather than burning the retry budget masking it as transient.\n\t\t\t\tif (err instanceof Error && err.name === \"AbortError\") throw err;\n\t\t\t\t// Otherwise a transport-level failure (connection refused/reset) —\n\t\t\t\t// e.g. an api replica mid-recreate. Retry; the next attempt\n\t\t\t\t// round-robins to a healthy replica.\n\t\t\t\tlastErr = err;\n\t\t\t\tif (attempt >= MAX_ATTEMPTS) break;\n\t\t\t\tawait delay(RETRY_BASE_MS * 2 ** (attempt - 1));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!res.ok) {\n\t\t\t\tif (RETRYABLE_STATUS.has(res.status) && attempt < MAX_ATTEMPTS) {\n\t\t\t\t\t// Drain the body so the connection can be reused, then back off.\n\t\t\t\t\tawait res.text().catch(() => {});\n\t\t\t\t\tawait delay(RETRY_BASE_MS * 2 ** (attempt - 1));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new Error(`GET ${url} → ${res.status} ${await res.text()}`);\n\t\t\t}\n\t\t\treturn (await res.json()) as T;\n\t\t}\n\t\tthrow (\n\t\t\tlastErr ?? new Error(`GET ${url} failed after ${MAX_ATTEMPTS} attempts`)\n\t\t);\n\t}\n\n\t/** Fetch a single cursor page of an Index collection. */\n\tprivate async getPage<K extends string, T>(\n\t\tpath: string,\n\t\tkey: K,\n\t\tparams: URLSearchParams,\n\t): Promise<{ items: T[]; next_cursor: string | null }> {\n\t\tconst env: Envelope<K, T> = await this.get(\n\t\t\t`${this.indexBaseUrl}${path}?${params}`,\n\t\t\tthis.indexApiKey,\n\t\t);\n\t\treturn { items: env[key], next_cursor: env.next_cursor };\n\t}\n\n\t/** Drain a cursor-paginated Index collection over [fromHeight, toHeight]. */\n\tprivate async walk<K extends string, T>(\n\t\tpath: string,\n\t\tkey: K,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\textraParams: Record<string, string> = {},\n\t): Promise<T[]> {\n\t\tconst out: T[] = [];\n\t\tlet cursor: string | null = null;\n\t\tdo {\n\t\t\tconst params = new URLSearchParams({\n\t\t\t\tto_height: String(toHeight),\n\t\t\t\tlimit: String(PAGE_LIMIT),\n\t\t\t\t...extraParams,\n\t\t\t});\n\t\t\t// from_height and cursor are mutually exclusive — anchor the first page\n\t\t\t// by height, then page forward by cursor only.\n\t\t\tif (cursor) params.set(\"cursor\", cursor);\n\t\t\telse params.set(\"from_height\", String(fromHeight));\n\t\t\tconst { items, next_cursor } = await this.getPage<K, T>(\n\t\t\t\tpath,\n\t\t\t\tkey,\n\t\t\t\tparams,\n\t\t\t);\n\t\t\tout.push(...items);\n\t\t\tcursor = next_cursor;\n\t\t} while (cursor);\n\t\treturn out;\n\t}\n\n\t/**\n\t * Fetch ONE page of contract-call transactions filtered to `contractId`.\n\t * Unlike walk(), this does NOT drain — the caller pages by feeding back\n\t * next_cursor — so a sparse high-volume filter (e.g. a single contract over\n\t * all history) costs one request per batch, not O(all-history) per tick.\n\t * `cursor` is exclusive (rows strictly after it); on the first call pass\n\t * `fromHeight` to anchor the backfill start instead.\n\t */\n\tasync fetchContractCalls(\n\t\tcontractId: string,\n\t\topts: {\n\t\t\ttoHeight: number;\n\t\t\tcursor?: string | null;\n\t\t\tfromHeight?: number;\n\t\t\tlimit?: number;\n\t\t},\n\t): Promise<{\n\t\ttransactions: IndexTransactionRow[];\n\t\tnext_cursor: string | null;\n\t}> {\n\t\tconst params = new URLSearchParams({\n\t\t\tto_height: String(opts.toHeight),\n\t\t\tlimit: String(opts.limit ?? PAGE_LIMIT),\n\t\t\tcontract_id: contractId,\n\t\t});\n\t\tif (opts.cursor) params.set(\"cursor\", opts.cursor);\n\t\telse params.set(\"from_height\", String(opts.fromHeight ?? 0));\n\t\tconst { items, next_cursor } = await this.getPage<\n\t\t\t\"transactions\",\n\t\t\tIndexTransactionRow\n\t\t>(\"/v1/index/transactions\", \"transactions\", params);\n\t\treturn { transactions: items, next_cursor };\n\t}\n\n\twalkBlocks(fromHeight: number, toHeight: number): Promise<IndexBlockRow[]> {\n\t\treturn this.walk<\"blocks\", IndexBlockRow>(\n\t\t\t\"/v1/index/blocks\",\n\t\t\t\"blocks\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t);\n\t}\n\n\t/** Lowest block height in [fromHeight, toHeight] with a matching event, or\n\t * null. One page, limit 1 — built for sparse-scan probes. */\n\tasync firstEventHeight(\n\t\teventType: string,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\tcontractId?: string,\n\t): Promise<number | null> {\n\t\tconst params = new URLSearchParams({\n\t\t\tevent_type: eventType,\n\t\t\tfrom_height: String(fromHeight),\n\t\t\tto_height: String(toHeight),\n\t\t\tlimit: \"1\",\n\t\t\t...(contractId ? { contract_id: contractId } : {}),\n\t\t});\n\t\tconst { items } = await this.getPage<\"events\", IndexEventRow>(\n\t\t\t\"/v1/index/events\",\n\t\t\t\"events\",\n\t\t\tparams,\n\t\t);\n\t\treturn items[0]?.block_height ?? null;\n\t}\n\n\twalkEvents(\n\t\teventType: string,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\t/** Join the submitting tx so each row carries `tx_*` — lets an event-only\n\t\t * subgraph skip walkTransactions and build `ctx.tx` from the event. */\n\t\twithTx = false,\n\t): Promise<IndexEventRow[]> {\n\t\treturn this.walk<\"events\", IndexEventRow>(\n\t\t\t\"/v1/index/events\",\n\t\t\t\"events\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t\t{\n\t\t\t\tevent_type: eventType,\n\t\t\t\t...(withTx ? { tx_context: \"true\" } : {}),\n\t\t\t},\n\t\t);\n\t}\n\n\twalkTransactions(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<IndexTransactionRow[]> {\n\t\treturn this.walk<\"transactions\", IndexTransactionRow>(\n\t\t\t\"/v1/index/transactions\",\n\t\t\t\"transactions\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t);\n\t}\n\n\t/** Canonical tip height from the Streams clock. */\n\tasync getStreamsTip(): Promise<number> {\n\t\tconst tip = await this.get<{ block_height: number }>(\n\t\t\t`${this.streamsBaseUrl}/v1/streams/tip`,\n\t\t\tthis.streamsApiKey,\n\t\t);\n\t\treturn Number(tip.block_height) || 0;\n\t}\n\n\t/**\n\t * Highest block height the Index data plane can serve (tip is inline in every\n\t * envelope). This is the data-availability bound — a consumer must not\n\t * process past it, even if the Streams clock is ahead.\n\t */\n\tasync getIndexTip(): Promise<number> {\n\t\tconst env = await this.getIndexTipEnvelope();\n\t\treturn Number(env.tip?.block_height) || 0;\n\t}\n\n\t/** Ingest tip. VM rows land with the block; decoded `block_height` can lag. */\n\tasync getIndexSourceTip(): Promise<number> {\n\t\tconst env = await this.getIndexTipEnvelope();\n\t\treturn Number(env.tip?.source_block_height ?? env.tip?.block_height) || 0;\n\t}\n\n\tprivate async getIndexTipEnvelope(): Promise<{\n\t\ttip: { block_height: number; source_block_height?: number };\n\t}> {\n\t\treturn this.get<{\n\t\t\ttip: { block_height: number; source_block_height?: number };\n\t\t}>(`${this.indexBaseUrl}/v1/index/blocks?limit=1`, this.indexApiKey);\n\t}\n\n\t/** Reorgs since a resume token (wall-clock `detected_at`-keyed). */\n\tasync listReorgs(\n\t\tsince: string,\n\t): Promise<{ reorgs: StreamsReorgRow[]; next_since: string | null }> {\n\t\tconst params = new URLSearchParams({ since });\n\t\treturn this.get(\n\t\t\t`${this.streamsBaseUrl}/v1/streams/reorgs?${params}`,\n\t\t\tthis.streamsApiKey,\n\t\t);\n\t}\n}\n\n/** Decoder + subgraph processor client. One env contract; omits bearer when no key. */\nexport function createInternalIndexHttpClient(): IndexHttpClient {\n\tconst baseUrl = defaultInternalIndexBaseUrl();\n\treturn new IndexHttpClient({\n\t\tindexBaseUrl: baseUrl,\n\t\tstreamsBaseUrl: baseUrl,\n\t\tindexApiKey: defaultInternalIndexApiKey(),\n\t\tstreamsApiKey: defaultInternalStreamsApiKey(),\n\t});\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": "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",
|
|
9
|
+
"debugId": "DB848C152DF9051A64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -20,4 +20,4 @@ declare function requireInternalIndexApiKey(env?: NodeJS.ProcessEnv): string;
|
|
|
20
20
|
declare function requireInternalStreamsApiKey(env?: NodeJS.ProcessEnv): string;
|
|
21
21
|
/** Shared env contract for decoder + subgraph HTTP dogfood. */
|
|
22
22
|
declare function defaultInternalIndexBaseUrl(): string;
|
|
23
|
-
export {
|
|
23
|
+
export { INDEX_INTERNAL_TENANT_ID, INTERNAL_STREAMS_TENANT_ID, defaultInternalIndexApiKey, defaultInternalIndexBaseUrl, defaultInternalStreamsApiKey, requireInternalIndexApiKey, requireInternalStreamsApiKey };
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __returnValue = (v) => v;
|
|
4
|
-
function __exportSetter(name, newValue) {
|
|
5
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
-
}
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
set: __exportSetter.bind(all, name)
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
1
|
// src/index-internal-auth.ts
|
|
18
2
|
var INDEX_INTERNAL_TENANT_ID = "tenant_index_internal";
|
|
19
3
|
var INTERNAL_STREAMS_TENANT_ID = "tenant_streams_decode_internal";
|
|
@@ -54,14 +38,14 @@ function defaultInternalIndexBaseUrl() {
|
|
|
54
38
|
return process.env.SUBGRAPH_INDEX_API_URL || process.env.STREAMS_API_URL || DEFAULT_INTERNAL_INDEX_BASE_URL;
|
|
55
39
|
}
|
|
56
40
|
export {
|
|
57
|
-
|
|
58
|
-
requireInternalIndexApiKey,
|
|
59
|
-
defaultInternalStreamsApiKey,
|
|
60
|
-
defaultInternalIndexBaseUrl,
|
|
61
|
-
defaultInternalIndexApiKey,
|
|
41
|
+
INDEX_INTERNAL_TENANT_ID,
|
|
62
42
|
INTERNAL_STREAMS_TENANT_ID,
|
|
63
|
-
|
|
43
|
+
defaultInternalIndexApiKey,
|
|
44
|
+
defaultInternalIndexBaseUrl,
|
|
45
|
+
defaultInternalStreamsApiKey,
|
|
46
|
+
requireInternalIndexApiKey,
|
|
47
|
+
requireInternalStreamsApiKey
|
|
64
48
|
};
|
|
65
49
|
|
|
66
|
-
//# debugId=
|
|
50
|
+
//# debugId=06EA6409A0ADD75064756E2164756E21
|
|
67
51
|
//# sourceMappingURL=index-internal-auth.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"// Internal service credentials for first-party consumers of /v1/index and\n// /v1/streams over HTTP (decoder, subgraph processor PublicApiBlockSource).\n// Seeded as internal tenants with NO account_id, so these reads are\n// unmetered (metering gates on account_id). Lives in shared so the API (seed)\n// and the consumers import it without a cycle.\n//\n// Resolution: STREAMS_INTERNAL_API_KEY / INDEX_INTERNAL_API_KEY, then\n// INSTANCE_TOKEN (OSS). No committed fallback. Empty-string env values fall\n// through (`trim()`, then empty): compose interpolates\n// `${STREAMS_INTERNAL_API_KEY:-}` which is \"\" when unset.\n//\n// Archive keys must not use the `sk-sl_` prefix; generate with `sl-int_`.\n// OSS compose should omit the internal env and send INSTANCE_TOKEN.\nexport const INDEX_INTERNAL_TENANT_ID = \"tenant_index_internal\";\nexport const INTERNAL_STREAMS_TENANT_ID = \"tenant_streams_decode_internal\";\n\nconst DEFAULT_INTERNAL_INDEX_BASE_URL = \"http://api:3800\";\n\nconst MISSING_INTERNAL_STREAMS_API_KEY =\n\t\"Set STREAMS_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Empty env no longer falls back to a committed secret.\";\n\nconst MISSING_INTERNAL_INDEX_API_KEY =\n\t\"Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads go out anonymously and are capped at the last 24h, so any seek into older history 402s.\";\n\nexport function defaultInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.INDEX_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\nexport function defaultInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.STREAMS_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\n/**\n * Platform-mode Index consumer: refuse to run with neither credential.\n *\n * A keyless Index read is not an error — it is an anonymous read, and the API\n * serves it for the last 24h (`api/src/index/free-window.ts`). That makes a\n * missing key invisible right up until a consumer's cursor falls out of the\n * window, at which point every read 402s and the container goes unhealthy,\n * possibly weeks after the misconfiguration. Callers that seek older history\n * on a platform-mode instance should fail here at startup instead.\n *\n * Self-hosted (oss/dedicated) instances are not gated, so they must NOT call\n * this — `defaultInternalIndexApiKey()` returning undefined is correct there.\n */\nexport function requireInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalIndexApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_INDEX_API_KEY);\n\treturn key;\n}\n\n/** Decoder startup: refuse to run with neither credential. */\nexport function requireInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalStreamsApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_STREAMS_API_KEY);\n\treturn key;\n}\n\n/** Shared env contract for decoder + subgraph HTTP dogfood. */\nexport function defaultInternalIndexBaseUrl(): string {\n\treturn (\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ||\n\t\tprocess.env.STREAMS_API_URL ||\n\t\tDEFAULT_INTERNAL_INDEX_BASE_URL\n\t);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAaO,IAAM,2BAA2B;AACjC,IAAM,6BAA6B;AAE1C,IAAM,kCAAkC;AAExC,IAAM,mCACL;AAED,IAAM,iCACL;AAEM,SAAS,0BAA0B,CACzC,MAAyB,QAAQ,KACZ;AAAA,EACrB,MAAM,WAAW,IAAI,wBAAwB,KAAK;AAAA,EAClD,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB,MAAM,WAAW,IAAI,gBAAgB,KAAK;AAAA,EAC1C,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB;AAAA;AAGM,SAAS,4BAA4B,CAC3C,MAAyB,QAAQ,KACZ;AAAA,EACrB,MAAM,WAAW,IAAI,0BAA0B,KAAK;AAAA,EACpD,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB,MAAM,WAAW,IAAI,gBAAgB,KAAK;AAAA,EAC1C,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB;AAAA;AAgBM,SAAS,0BAA0B,CACzC,MAAyB,QAAQ,KACxB;AAAA,EACT,MAAM,MAAM,2BAA2B,GAAG;AAAA,EAC1C,IAAI,CAAC;AAAA,IAAK,MAAM,IAAI,MAAM,8BAA8B;AAAA,EACxD,OAAO;AAAA;AAID,SAAS,4BAA4B,CAC3C,MAAyB,QAAQ,KACxB;AAAA,EACT,MAAM,MAAM,6BAA6B,GAAG;AAAA,EAC5C,IAAI,CAAC;AAAA,IAAK,MAAM,IAAI,MAAM,gCAAgC;AAAA,EAC1D,OAAO;AAAA;AAID,SAAS,2BAA2B,GAAW;AAAA,EACrD,OACC,QAAQ,IAAI,0BACZ,QAAQ,IAAI,mBACZ;AAAA;",
|
|
8
|
+
"debugId": "06EA6409A0ADD75064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -152,7 +152,6 @@ interface SubgraphsTable {
|
|
|
152
152
|
handler_code: string | null;
|
|
153
153
|
source_code: string | null;
|
|
154
154
|
project_id: string | null;
|
|
155
|
-
visibility: Generated<string>;
|
|
156
155
|
/** Paid (wallet-ghost) deploys expire unless renewed or claimed; NULL = no expiry. */
|
|
157
156
|
expires_at: Date | null;
|
|
158
157
|
/** (event type, contract) probe pairs persisted at deploy for weight classification. */
|
|
@@ -1034,23 +1033,22 @@ declare function isPox5DecoderEnabled(env?: EnvMap): boolean;
|
|
|
1034
1033
|
declare function isSbtcDecoderEnabled(env?: EnvMap): boolean;
|
|
1035
1034
|
/** Default OFF. Opt in with `BNS_DECODER_ENABLED=true`. */
|
|
1036
1035
|
declare function isBnsDecoderEnabled(env?: EnvMap): boolean;
|
|
1037
|
-
import {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
*
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
*
|
|
1046
|
-
*/
|
|
1047
|
-
declare
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
declare function parseJsonb<T = unknown>(value: unknown): T;
|
|
1036
|
+
import { DECODED_EVENT_TYPES, VM_NODE_TO_STORED_TYPE } from "@secondlayer/stacks/filters";
|
|
1037
|
+
import { DecodedEventType } from "@secondlayer/stacks/filters";
|
|
1038
|
+
import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE as VM_NODE_TO_STORED_TYPE2, DecodedEventType as DecodedEventType2, VmEventType, VmNodeEventType } from "@secondlayer/stacks/filters";
|
|
1039
|
+
type VmStoredToNode = { [K in keyof typeof VM_NODE_TO_STORED_TYPE as (typeof VM_NODE_TO_STORED_TYPE)[K]] : K };
|
|
1040
|
+
/** Inverse of {@link VM_NODE_TO_STORED_TYPE}. Replay reconstruction emits the
|
|
1041
|
+
* node-shaped `/new_block.vm_events` body, so ingest can re-parse it. */
|
|
1042
|
+
declare const VM_STORED_TO_NODE_TYPE: VmStoredToNode;
|
|
1043
|
+
/** Alias kept for the Streams surface (identical to {@link DECODED_EVENT_TYPES}).
|
|
1044
|
+
* Explicit type annotation required — isolatedDeclarations emits `unknown` for
|
|
1045
|
+
* a bare const-to-const alias. */
|
|
1046
|
+
declare const STREAMS_EVENT_TYPES: typeof DECODED_EVENT_TYPES;
|
|
1047
|
+
type StreamsEventType = DecodedEventType;
|
|
1048
|
+
declare const STREAMS_DB_EVENT_TYPES: readonly ["stx_transfer_event", "stx_mint_event", "stx_burn_event", "stx_lock_event", "ft_transfer_event", "ft_mint_event", "ft_burn_event", "nft_transfer_event", "nft_mint_event", "nft_burn_event", "smart_contract_event", "contract_event"];
|
|
1049
|
+
type StreamsDbEventType = (typeof STREAMS_DB_EVENT_TYPES)[number];
|
|
1050
|
+
declare const DB_TO_STREAMS_EVENT_TYPE: Record<StreamsDbEventType, StreamsEventType>;
|
|
1051
|
+
declare const STREAMS_TO_DB_EVENT_TYPES: Record<StreamsEventType, readonly StreamsDbEventType[]>;
|
|
1054
1052
|
import { Kysely } from "kysely";
|
|
1055
1053
|
import postgres from "postgres";
|
|
1056
1054
|
import { sql } from "kysely";
|
|
@@ -1886,6 +1884,23 @@ declare const SOURCE_READ_PKS: {
|
|
|
1886
1884
|
readonly events: readonly ["tx_id", "event_index"]
|
|
1887
1885
|
readonly chain_reorgs: null
|
|
1888
1886
|
};
|
|
1887
|
+
import { RawBuilder } from "kysely";
|
|
1888
|
+
/**
|
|
1889
|
+
* Safely encode a JS value as a JSONB literal for Kysely inserts/updates.
|
|
1890
|
+
* Kysely + postgres.js double-encodes JSON when using parameterized queries
|
|
1891
|
+
* with ::jsonb casts. This uses sql.raw to inline a properly escaped literal.
|
|
1892
|
+
*
|
|
1893
|
+
* Generic parameter lets callers set the RawBuilder's output type so they
|
|
1894
|
+
* don't need to cast at the insert site. Default is `unknown` — widen at
|
|
1895
|
+
* the call site when the column type is narrower, e.g. `jsonb<MyShape>(...)`.
|
|
1896
|
+
*/
|
|
1897
|
+
declare function jsonb<T = unknown>(value: T): RawBuilder<T>;
|
|
1898
|
+
/**
|
|
1899
|
+
* Safely parse a JSONB value from the database.
|
|
1900
|
+
* Handles double-encoded strings where postgres.js returns a JSON string
|
|
1901
|
+
* instead of a parsed object.
|
|
1902
|
+
*/
|
|
1903
|
+
declare function parseJsonb<T = unknown>(value: unknown): T;
|
|
1889
1904
|
/**
|
|
1890
1905
|
* Per-migration DB-plane gating for the source/target split.
|
|
1891
1906
|
*
|
|
@@ -2142,6 +2157,56 @@ declare class TenantSuspendedError extends SecondLayerError {
|
|
|
2142
2157
|
* (avoids cross-bundle instanceof failures from bunup class duplication). */
|
|
2143
2158
|
declare const CODE_TO_STATUS: Record<string, 400 | 401 | 402 | 403 | 404 | 409 | 415 | 422 | 423 | 429 | 503>;
|
|
2144
2159
|
declare function getErrorMessage(err: unknown): string;
|
|
2160
|
+
/**
|
|
2161
|
+
* Block finality, anchored to the burn (Bitcoin) chain.
|
|
2162
|
+
*
|
|
2163
|
+
* Post-Nakamoto, Stacks blocks arrive every few seconds, so a fixed count of
|
|
2164
|
+
* Stacks blocks is a poor finality proxy (e.g. 144 fast blocks ≈ 12 minutes).
|
|
2165
|
+
* A Stacks block is final once its anchoring burn block has enough Bitcoin
|
|
2166
|
+
* confirmations — so finality is expressed in burn-block confirmations and
|
|
2167
|
+
* mapped to a Stacks height via the burn_block_height carried on each block.
|
|
2168
|
+
*/
|
|
2169
|
+
/** Bitcoin confirmations required before a block is treated as final. ~1 hour. */
|
|
2170
|
+
declare const DEFAULT_BTC_CONFIRMATIONS = 6;
|
|
2171
|
+
/**
|
|
2172
|
+
* Highest burn (Bitcoin) block height considered finalized given the current
|
|
2173
|
+
* burn tip. Stacks blocks whose `burn_block_height` is at or below the result
|
|
2174
|
+
* are final. Returns 0 when the chain is shorter than the confirmation window.
|
|
2175
|
+
*/
|
|
2176
|
+
declare function finalizedBurnHeight(burnTipHeight: number, confirmations?: number): number;
|
|
2177
|
+
/**
|
|
2178
|
+
* Canonical Streams cursor codec, shared by every product (Streams, Index,
|
|
2179
|
+
* Datasets, bulk). A cursor is `"<block_height>:<event_index>"` — an opaque,
|
|
2180
|
+
* monotonic resume token. One implementation so encode/decode and the
|
|
2181
|
+
* empty-range sentinel can never drift between products.
|
|
2182
|
+
*
|
|
2183
|
+
* NOTE: this codec IS the shared piece worth centralizing. A broader "shared
|
|
2184
|
+
* canonical reader" across the ~10 raw-event query sites (streams-events,
|
|
2185
|
+
* streams-bulk/query, l2/storage) was deliberately NOT built: those sites split
|
|
2186
|
+
* into distinct query patterns and share only the row_number ordering *pattern*,
|
|
2187
|
+
* not an identical reader. The reorg-archive design (migration 0084) keeps the
|
|
2188
|
+
* main tables canonical-only, so each reader's `WHERE canonical` filter already
|
|
2189
|
+
* needs no dedup logic. Forcing one mega-reader was the wrong abstraction; this
|
|
2190
|
+
* codec captures the only part that actually drifts.
|
|
2191
|
+
*/
|
|
2192
|
+
type StreamsCursor = {
|
|
2193
|
+
block_height: number
|
|
2194
|
+
event_index: number
|
|
2195
|
+
};
|
|
2196
|
+
/**
|
|
2197
|
+
* Event index used to advance a cursor past a fully-filtered range instead of
|
|
2198
|
+
* returning null. A filter that eliminates every event in a scanned range would
|
|
2199
|
+
* otherwise pin the consumer at the previous cursor and spin forever. Must fit
|
|
2200
|
+
* in Postgres int4 (the `stream_event_index` column type) — int4 max is plenty,
|
|
2201
|
+
* real blocks have far fewer than ~2.1B events.
|
|
2202
|
+
*/
|
|
2203
|
+
declare const EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
|
|
2204
|
+
declare function encodeStreamsCursor(cursor: StreamsCursor): string;
|
|
2205
|
+
declare function decodeStreamsCursor(cursor: string): StreamsCursor;
|
|
2206
|
+
declare function compareStreamsCursor(a: StreamsCursor, b: StreamsCursor): number;
|
|
2207
|
+
declare function isEmptyRangeCursor(cursor: StreamsCursor): boolean;
|
|
2208
|
+
/** Exclusive end of every event that can live in `height`. */
|
|
2209
|
+
declare function blockEndCursor(height: number): StreamsCursor;
|
|
2145
2210
|
declare class Logger {
|
|
2146
2211
|
private _level?;
|
|
2147
2212
|
private _isProduction?;
|
|
@@ -2160,7 +2225,6 @@ declare const logger: Logger;
|
|
|
2160
2225
|
import { z as z2 } from "zod";
|
|
2161
2226
|
interface DeploySubgraphRequest {
|
|
2162
2227
|
name: string;
|
|
2163
|
-
version?: string;
|
|
2164
2228
|
description?: string;
|
|
2165
2229
|
sources: Record<string, Record<string, unknown>>;
|
|
2166
2230
|
schema: Record<string, unknown>;
|
|
@@ -2213,7 +2277,6 @@ interface SubgraphSummary {
|
|
|
2213
2277
|
gapCount: number;
|
|
2214
2278
|
/** history_filling = expected gaps while a tip-first backfill op runs. */
|
|
2215
2279
|
integrity: "complete" | "gaps_detected" | "history_filling";
|
|
2216
|
-
visibility?: "public" | "private";
|
|
2217
2280
|
/** Most recent indexing error reason + when it occurred, if any. */
|
|
2218
2281
|
lastError?: string | null;
|
|
2219
2282
|
lastErrorAt?: string | null;
|
|
@@ -2270,7 +2333,6 @@ interface SubgraphDetail {
|
|
|
2270
2333
|
version: string;
|
|
2271
2334
|
schemaHash?: string;
|
|
2272
2335
|
status: string;
|
|
2273
|
-
visibility?: "public" | "private";
|
|
2274
2336
|
lastProcessedBlock: number;
|
|
2275
2337
|
description?: string;
|
|
2276
2338
|
sources?: Record<string, unknown>;
|
|
@@ -2635,15 +2697,6 @@ type SubgraphSpecFormat = "openapi" | "agent" | "markdown";
|
|
|
2635
2697
|
interface SubgraphSpecOptions {
|
|
2636
2698
|
serverUrl?: string;
|
|
2637
2699
|
generatedAt?: string;
|
|
2638
|
-
/**
|
|
2639
|
-
* Self-hosted instances ignore the `visibility` column when deciding
|
|
2640
|
-
* whether a read needs a key (`/v1/subgraphs` auth is the loopback rule,
|
|
2641
|
-
* not the flag) — but this generator still branched on it, so a spec built
|
|
2642
|
-
* for a self-hosted deploy pointed readers at the authenticated `/api`
|
|
2643
|
-
* path for a read that was actually open. Callers on that mode should set
|
|
2644
|
-
* this so the generated URLs match the auth the API actually enforces.
|
|
2645
|
-
*/
|
|
2646
|
-
forcePublicRead?: boolean;
|
|
2647
2700
|
}
|
|
2648
2701
|
interface SubgraphAgentSchema {
|
|
2649
2702
|
name: string;
|
|
@@ -2682,124 +2735,6 @@ declare function generateSubgraphAgentSchema(detail: SubgraphDetail, options?: S
|
|
|
2682
2735
|
declare function generateSubgraphOpenApi(detail: SubgraphDetail, options?: SubgraphSpecOptions): Record<string, unknown>;
|
|
2683
2736
|
declare function generateSubgraphMarkdown(detail: SubgraphDetail, options?: SubgraphSpecOptions): string;
|
|
2684
2737
|
declare function generateSubgraphSpec(detail: SubgraphDetail, format: SubgraphSpecFormat, options?: SubgraphSpecOptions): Record<string, unknown> | SubgraphAgentSchema | string;
|
|
2685
|
-
declare namespace exports_hmac {
|
|
2686
|
-
export { verifySignatureHeader, verifySignature, signPayload, generateSecret, createSignatureHeader };
|
|
2687
|
-
}
|
|
2688
|
-
/**
|
|
2689
|
-
* Generate a random secret for delivery signing
|
|
2690
|
-
* Returns 32 bytes as a 64-character hex string
|
|
2691
|
-
*/
|
|
2692
|
-
declare function generateSecret(): string;
|
|
2693
|
-
/**
|
|
2694
|
-
* Sign a payload with HMAC-SHA256
|
|
2695
|
-
* Returns the signature as a hex string
|
|
2696
|
-
*/
|
|
2697
|
-
declare function signPayload(payload: string, secret: string): string;
|
|
2698
|
-
/**
|
|
2699
|
-
* Verify an HMAC signature
|
|
2700
|
-
* Uses constant-time comparison to prevent timing attacks
|
|
2701
|
-
*/
|
|
2702
|
-
declare function verifySignature(payload: string, signature: string, secret: string): boolean;
|
|
2703
|
-
/**
|
|
2704
|
-
* Create a Stripe-style signature header
|
|
2705
|
-
* Format: t=timestamp,v1=signature
|
|
2706
|
-
*/
|
|
2707
|
-
declare function createSignatureHeader(payload: string, secret: string, timestamp?: number): string;
|
|
2708
|
-
/**
|
|
2709
|
-
* Parse and verify a Stripe-style signature header
|
|
2710
|
-
* Returns true if valid, false otherwise
|
|
2711
|
-
*/
|
|
2712
|
-
declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
2713
|
-
declare namespace exports_ed25519 {
|
|
2714
|
-
export { verifyEd25519, signEd25519, publicKeyPemFromPrivate, loadEd25519PublicKey, loadEd25519PrivateKey, generateEd25519KeyPair, ed25519KeyId };
|
|
2715
|
-
}
|
|
2716
|
-
import { KeyObject } from "node:crypto";
|
|
2717
|
-
/**
|
|
2718
|
-
* Asymmetric ed25519 signing for Streams response proofs.
|
|
2719
|
-
*
|
|
2720
|
-
* Asymmetric (not HMAC) so the proof is real: only the server holds the private
|
|
2721
|
-
* key, and any consumer verifies with the published public key — no shared
|
|
2722
|
-
* secret to leak. ed25519 uses node's `sign`/`verify` with a `null` algorithm.
|
|
2723
|
-
* Keys are PEM (PKCS8 private / SPKI public) for env transport; load once and
|
|
2724
|
-
* reuse the KeyObject on hot paths.
|
|
2725
|
-
*/
|
|
2726
|
-
declare function generateEd25519KeyPair(): {
|
|
2727
|
-
privateKeyPem: string
|
|
2728
|
-
publicKeyPem: string
|
|
2729
|
-
};
|
|
2730
|
-
declare function loadEd25519PrivateKey(pem: string): KeyObject;
|
|
2731
|
-
declare function loadEd25519PublicKey(pem: string): KeyObject;
|
|
2732
|
-
declare function publicKeyPemFromPrivate(privateKeyPem: string): string;
|
|
2733
|
-
/** Stable short id for a public key (rotation hint via X-Signature-KeyId). */
|
|
2734
|
-
declare function ed25519KeyId(publicKeyPem: string): string;
|
|
2735
|
-
declare function signEd25519(payload: string, privateKey: KeyObject): string;
|
|
2736
|
-
declare function verifyEd25519(payload: string, signatureBase64: string, publicKey: KeyObject): boolean;
|
|
2737
|
-
import { DECODED_EVENT_TYPES, VM_NODE_TO_STORED_TYPE } from "@secondlayer/stacks/filters";
|
|
2738
|
-
import { DecodedEventType } from "@secondlayer/stacks/filters";
|
|
2739
|
-
import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE as VM_NODE_TO_STORED_TYPE2, DecodedEventType as DecodedEventType2, VmEventType, VmNodeEventType } from "@secondlayer/stacks/filters";
|
|
2740
|
-
type VmStoredToNode = { [K in keyof typeof VM_NODE_TO_STORED_TYPE as (typeof VM_NODE_TO_STORED_TYPE)[K]] : K };
|
|
2741
|
-
/** Inverse of {@link VM_NODE_TO_STORED_TYPE}. Replay reconstruction emits the
|
|
2742
|
-
* node-shaped `/new_block.vm_events` body, so ingest can re-parse it. */
|
|
2743
|
-
declare const VM_STORED_TO_NODE_TYPE: VmStoredToNode;
|
|
2744
|
-
/** Alias kept for the Streams surface (identical to {@link DECODED_EVENT_TYPES}).
|
|
2745
|
-
* Explicit type annotation required — isolatedDeclarations emits `unknown` for
|
|
2746
|
-
* a bare const-to-const alias. */
|
|
2747
|
-
declare const STREAMS_EVENT_TYPES: typeof DECODED_EVENT_TYPES;
|
|
2748
|
-
type StreamsEventType = DecodedEventType;
|
|
2749
|
-
declare const STREAMS_DB_EVENT_TYPES: readonly ["stx_transfer_event", "stx_mint_event", "stx_burn_event", "stx_lock_event", "ft_transfer_event", "ft_mint_event", "ft_burn_event", "nft_transfer_event", "nft_mint_event", "nft_burn_event", "smart_contract_event", "contract_event"];
|
|
2750
|
-
type StreamsDbEventType = (typeof STREAMS_DB_EVENT_TYPES)[number];
|
|
2751
|
-
declare const DB_TO_STREAMS_EVENT_TYPE: Record<StreamsDbEventType, StreamsEventType>;
|
|
2752
|
-
declare const STREAMS_TO_DB_EVENT_TYPES: Record<StreamsEventType, readonly StreamsDbEventType[]>;
|
|
2753
|
-
/**
|
|
2754
|
-
* Block finality, anchored to the burn (Bitcoin) chain.
|
|
2755
|
-
*
|
|
2756
|
-
* Post-Nakamoto, Stacks blocks arrive every few seconds, so a fixed count of
|
|
2757
|
-
* Stacks blocks is a poor finality proxy (e.g. 144 fast blocks ≈ 12 minutes).
|
|
2758
|
-
* A Stacks block is final once its anchoring burn block has enough Bitcoin
|
|
2759
|
-
* confirmations — so finality is expressed in burn-block confirmations and
|
|
2760
|
-
* mapped to a Stacks height via the burn_block_height carried on each block.
|
|
2761
|
-
*/
|
|
2762
|
-
/** Bitcoin confirmations required before a block is treated as final. ~1 hour. */
|
|
2763
|
-
declare const DEFAULT_BTC_CONFIRMATIONS = 6;
|
|
2764
|
-
/**
|
|
2765
|
-
* Highest burn (Bitcoin) block height considered finalized given the current
|
|
2766
|
-
* burn tip. Stacks blocks whose `burn_block_height` is at or below the result
|
|
2767
|
-
* are final. Returns 0 when the chain is shorter than the confirmation window.
|
|
2768
|
-
*/
|
|
2769
|
-
declare function finalizedBurnHeight(burnTipHeight: number, confirmations?: number): number;
|
|
2770
|
-
/**
|
|
2771
|
-
* Canonical Streams cursor codec, shared by every product (Streams, Index,
|
|
2772
|
-
* Datasets, bulk). A cursor is `"<block_height>:<event_index>"` — an opaque,
|
|
2773
|
-
* monotonic resume token. One implementation so encode/decode and the
|
|
2774
|
-
* empty-range sentinel can never drift between products.
|
|
2775
|
-
*
|
|
2776
|
-
* NOTE: this codec IS the shared piece worth centralizing. A broader "shared
|
|
2777
|
-
* canonical reader" across the ~10 raw-event query sites (streams-events,
|
|
2778
|
-
* streams-bulk/query, l2/storage) was deliberately NOT built: those sites split
|
|
2779
|
-
* into distinct query patterns and share only the row_number ordering *pattern*,
|
|
2780
|
-
* not an identical reader. The reorg-archive design (migration 0084) keeps the
|
|
2781
|
-
* main tables canonical-only, so each reader's `WHERE canonical` filter already
|
|
2782
|
-
* needs no dedup logic. Forcing one mega-reader was the wrong abstraction; this
|
|
2783
|
-
* codec captures the only part that actually drifts.
|
|
2784
|
-
*/
|
|
2785
|
-
type StreamsCursor = {
|
|
2786
|
-
block_height: number
|
|
2787
|
-
event_index: number
|
|
2788
|
-
};
|
|
2789
|
-
/**
|
|
2790
|
-
* Event index used to advance a cursor past a fully-filtered range instead of
|
|
2791
|
-
* returning null. A filter that eliminates every event in a scanned range would
|
|
2792
|
-
* otherwise pin the consumer at the previous cursor and spin forever. Must fit
|
|
2793
|
-
* in Postgres int4 (the `stream_event_index` column type) — int4 max is plenty,
|
|
2794
|
-
* real blocks have far fewer than ~2.1B events.
|
|
2795
|
-
*/
|
|
2796
|
-
declare const EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
|
|
2797
|
-
declare function encodeStreamsCursor(cursor: StreamsCursor): string;
|
|
2798
|
-
declare function decodeStreamsCursor(cursor: string): StreamsCursor;
|
|
2799
|
-
declare function compareStreamsCursor(a: StreamsCursor, b: StreamsCursor): number;
|
|
2800
|
-
declare function isEmptyRangeCursor(cursor: StreamsCursor): boolean;
|
|
2801
|
-
/** Exclusive end of every event that can live in `height`. */
|
|
2802
|
-
declare function blockEndCursor(height: number): StreamsCursor;
|
|
2803
2738
|
/**
|
|
2804
2739
|
* Payload for `sbtc_deposit` (topic: completed-deposit).
|
|
2805
2740
|
* `sender` is the Stacks address that initiated the deposit and receives the sBTC.
|
|
@@ -3059,4 +2994,56 @@ interface ChainTestDelivery {
|
|
|
3059
2994
|
* "Chain webhook webhook payloads" doc.
|
|
3060
2995
|
*/
|
|
3061
2996
|
type ChainWebhookDelivery = ChainApplyDeliveryOf<"stx_transfer", ChainEventEnvelope<"stx_transfer_event", ChainStxTransferData>> | ChainApplyDeliveryOf<"stx_mint", ChainEventEnvelope<"stx_mint_event", ChainStxMintData>> | ChainApplyDeliveryOf<"stx_burn", ChainEventEnvelope<"stx_burn_event", ChainStxBurnData>> | ChainApplyDeliveryOf<"stx_lock", ChainEventEnvelope<"stx_lock_event", ChainStxLockData>> | ChainApplyDeliveryOf<"ft_transfer", ChainEventEnvelope<"ft_transfer_event", ChainFtTransferData>> | ChainApplyDeliveryOf<"ft_mint", ChainEventEnvelope<"ft_mint_event", ChainFtMintData>> | ChainApplyDeliveryOf<"ft_burn", ChainEventEnvelope<"ft_burn_event", ChainFtBurnData>> | ChainApplyDeliveryOf<"nft_transfer", ChainEventEnvelope<"nft_transfer_event", ChainNftTransferData>> | ChainApplyDeliveryOf<"nft_mint", ChainEventEnvelope<"nft_mint_event", ChainNftMintData>> | ChainApplyDeliveryOf<"nft_burn", ChainEventEnvelope<"nft_burn_event", ChainNftBurnData>> | ChainApplyDeliveryOf<"print_event", ChainEventEnvelope<"contract_event", ChainPrintEventData>> | ChainApplyDeliveryOf<"contract_call", ChainTxLevelEvent> | ChainApplyDeliveryOf<"contract_deploy", ChainTxLevelEvent> | ChainApplyDeliveryOf<"sbtc_deposit", SbtcDepositEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_create", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_accept", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_reject", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_swept_confirmed", SbtcWithdrawalSweptConfirmedEvent> | ChainReorgRollbackDelivery | ChainTestDelivery;
|
|
3062
|
-
|
|
2997
|
+
declare namespace exports_hmac {
|
|
2998
|
+
export { createSignatureHeader, generateSecret, signPayload, verifySignature, verifySignatureHeader };
|
|
2999
|
+
}
|
|
3000
|
+
/**
|
|
3001
|
+
* Generate a random secret for delivery signing
|
|
3002
|
+
* Returns 32 bytes as a 64-character hex string
|
|
3003
|
+
*/
|
|
3004
|
+
declare function generateSecret(): string;
|
|
3005
|
+
/**
|
|
3006
|
+
* Sign a payload with HMAC-SHA256
|
|
3007
|
+
* Returns the signature as a hex string
|
|
3008
|
+
*/
|
|
3009
|
+
declare function signPayload(payload: string, secret: string): string;
|
|
3010
|
+
/**
|
|
3011
|
+
* Verify an HMAC signature
|
|
3012
|
+
* Uses constant-time comparison to prevent timing attacks
|
|
3013
|
+
*/
|
|
3014
|
+
declare function verifySignature(payload: string, signature: string, secret: string): boolean;
|
|
3015
|
+
/**
|
|
3016
|
+
* Create a Stripe-style signature header
|
|
3017
|
+
* Format: t=timestamp,v1=signature
|
|
3018
|
+
*/
|
|
3019
|
+
declare function createSignatureHeader(payload: string, secret: string, timestamp?: number): string;
|
|
3020
|
+
/**
|
|
3021
|
+
* Parse and verify a Stripe-style signature header
|
|
3022
|
+
* Returns true if valid, false otherwise
|
|
3023
|
+
*/
|
|
3024
|
+
declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
3025
|
+
declare namespace exports_ed25519 {
|
|
3026
|
+
export { ed25519KeyId, generateEd25519KeyPair, loadEd25519PrivateKey, loadEd25519PublicKey, publicKeyPemFromPrivate, signEd25519, verifyEd25519 };
|
|
3027
|
+
}
|
|
3028
|
+
import { KeyObject } from "node:crypto";
|
|
3029
|
+
/**
|
|
3030
|
+
* Asymmetric ed25519 signing for Streams response proofs.
|
|
3031
|
+
*
|
|
3032
|
+
* Asymmetric (not HMAC) so the proof is real: only the server holds the private
|
|
3033
|
+
* key, and any consumer verifies with the published public key — no shared
|
|
3034
|
+
* secret to leak. ed25519 uses node's `sign`/`verify` with a `null` algorithm.
|
|
3035
|
+
* Keys are PEM (PKCS8 private / SPKI public) for env transport; load once and
|
|
3036
|
+
* reuse the KeyObject on hot paths.
|
|
3037
|
+
*/
|
|
3038
|
+
declare function generateEd25519KeyPair(): {
|
|
3039
|
+
privateKeyPem: string
|
|
3040
|
+
publicKeyPem: string
|
|
3041
|
+
};
|
|
3042
|
+
declare function loadEd25519PrivateKey(pem: string): KeyObject;
|
|
3043
|
+
declare function loadEd25519PublicKey(pem: string): KeyObject;
|
|
3044
|
+
declare function publicKeyPemFromPrivate(privateKeyPem: string): string;
|
|
3045
|
+
/** Stable short id for a public key (rotation hint via X-Signature-KeyId). */
|
|
3046
|
+
declare function ed25519KeyId(publicKeyPem: string): string;
|
|
3047
|
+
declare function signEd25519(payload: string, privateKey: KeyObject): string;
|
|
3048
|
+
declare function verifyEd25519(payload: string, signatureBase64: string, publicKey: KeyObject): boolean;
|
|
3049
|
+
export { Account, AccountCredits, AccountCreditsTable, AccountSpendCap, AccountSpendCapsTable, AccountsTable, ApiKey, ApiKeysTable, ArchiveFetch, ArchiveFetchesTable, AuthenticationError, AuthorizationError, Block, BlocksTable, BnsMarketplaceAction, BnsMarketplaceEventsTable, BnsNameEventTopic, BnsNameEventsTable, BnsNamesTable, BnsNamespaceEventStatus, BnsNamespaceEventsTable, BnsNamespacesTable, BurnBlockRewardSlotsTable, BurnBlockRewardsTable, CHAIN_TRIGGER_FIELDS, CHAIN_TRIGGER_TYPES, CODE_TO_STATUS, ChainApplyDeliveryOf, ChainApplyEnvelope, ChainApplyEnvelopeOf, ChainEventEnvelope, ChainFtBurnData, ChainFtMintData, ChainFtTransferData, ChainNftBurnData, ChainNftMintData, ChainNftTransferData, ChainPrintEventData, ChainReadCacheTable, ChainReorgOrphanedEntry, ChainReorgRollbackDelivery, ChainReorgRollbackEnvelope, ChainReorgsTable, ChainStxBurnData, ChainStxLockData, ChainStxMintData, ChainStxTransferData, ChainTestDelivery, ChainTxLevelEvent, ChainWebhookDelivery, ChainWebhookEnvelope, Contract, ContractsTable, CoverageSegmentsTable, CreateWebhookRequest, CreateWebhookRequestSchema, CreateWebhookResponse, DB_TO_STREAMS_EVENT_TYPE, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DEFAULT_BTC_CONFIRMATIONS, Database, DatabaseError, DbPlane, DbReadRow, DbSplitStatus, DeadLetterEventsTable, DeadRow, DecodedEventType2 as DecodedEventType, DecodedEventsTable, DecoderCheckpointsTable, DeliveryRow, DeploySubgraphRequest, DeploySubgraphRequestSchema, DeploySubgraphResponse, EMPTY_RANGE_EVENT_INDEX_SENTINEL, Env, ErrorCode, ErrorCodes, Event, EventsArchiveTable, EventsTable, FailureClass, FailureUnit, ForbiddenError, IndexColumn, IndexColumnType, IndexPrimaryKey, IndexProgress, IndexProgressTable, InsertAccount, InsertAccountCredits, InsertAccountSpendCap, InsertApiKey, InsertArchiveFetch, InsertBlock, InsertContract, InsertEvent, InsertIndexProgress, InsertMagicLink, InsertMempoolTransaction, InsertSession, InsertSubgraph, InsertSubgraphGap, InsertSubgraphHealthSnapshot, InsertSubgraphOperation, InsertTransaction, InsertVmEvent, InsertWaitlistSignup, InsertWebhook, InsertWebhookDelivery, InsertWebhookOutbox, InstancesTable, KeyRotatedError, MagicLink, MagicLinksTable, MempoolTransaction, MempoolTransactionsTable, MigrationRole, NativeClock, NotFoundError, NumericAsText, ObserverJournalStatus, ObserverJournalTable, OutboxStatus, ParsedCreateWebhookRequest, ParsedReplayWebhookRequest, ParsedUpdateWebhookRequest, PaymentRequiredError, PendingForkBlocksTable, Pox4CallsTable, Pox4FunctionName, Pox5EventTopic, Pox5EventsTable, ProcessedStripeEventsTable, RateLimitError, ReindexResponse, RepairMode, ReplayResult, ReplayWebhookRequest, ReplayWebhookRequestSchema, RetryState, RotateSecretResponse, RunStatus, SOURCE_READ_COLUMNS, SOURCE_READ_PKS, SOURCE_READ_TYPES, STREAMS_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_TO_DB_EVENT_TYPES, SbtcDepositEvent, SbtcEventTopic, SbtcEventsTable, SbtcSettlementsTable, SbtcTokenEventType, SbtcTokenEventsTable, SbtcWithdrawalEvent, SbtcWithdrawalSweptConfirmedEvent, SecondLayerError, ServiceHeartbeatsTable, Session, SessionsTable, StageBlockReceiptsTable, StageFailuresTable, StageKind, StageRegistryTable, StageRunsTable, StreamsCursor, StreamsDbEventType, StreamsEventType, Subgraph, SubgraphAgentSchema, SubgraphAggregateParams, SubgraphAggregateResponse, SubgraphDetail, SubgraphGap, SubgraphGapEntry, SubgraphGapRange, SubgraphGapsResponse, SubgraphGapsTable, SubgraphHealthSnapshot, SubgraphHealthSnapshotsTable, SubgraphOperation, SubgraphOperationKind, SubgraphOperationStatus, SubgraphOperationsTable, SubgraphProcessingStatsTable, SubgraphQueryParams, SubgraphSpecFormat, SubgraphSpecOptions, SubgraphSummary, SubgraphSyncInfo, SubgraphViolationsTable, SubgraphsTable, SyncScopesTable, TABLE_TO_DB, TenantSuspendedError, Transaction, TransactionsArchiveTable, TransactionsTable, TriggerEvaluatorState, TriggerEvaluatorStateTable, UpdateAccountCredits, UpdateAccountSpendCap, UpdateApiKey, UpdateArchiveFetch, UpdateBlock, UpdateContract, UpdateEvent, UpdateIndexProgress, UpdateSubgraph, UpdateSubgraphOperation, UpdateTransaction, UpdateVmEvent, UpdateWebhook, UpdateWebhookOutbox, UpdateWebhookRequest, UpdateWebhookRequestSchema, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE2 as VM_NODE_TO_STORED_TYPE, VM_STORED_TO_NODE_TYPE, ValidationError, VersionConflictError, VmEvent, VmEventType, VmEventsArchiveTable, VmEventsTable, VmNodeEventType, WEBHOOK_FILTER_OPERATORS, WEBHOOK_FORMATS, WEBHOOK_RUNTIMES, WEBHOOK_STATUSES, Waitlist, WaitlistSignup, WaitlistSignupsTable, WaitlistsTable, Webhook, WebhookDeliveriesTable, WebhookDelivery, WebhookDetail, WebhookFilter, WebhookFilterClause, WebhookFilterClauseSchema, WebhookFilterOperator, WebhookFilterOperatorSchema, WebhookFilterPrimitive, WebhookFilterPrimitiveSchema, WebhookFilterSchema, WebhookFormat, WebhookFormatSchema, WebhookKind, WebhookOutbox, WebhookOutboxTable, WebhookRuntime, WebhookRuntimeSchema, WebhookSchemaColumn, WebhookSchemaTable, WebhookSchemaTables, WebhookStatus, WebhookStatusSchema, WebhookSummary, WebhooksTable, applicationDatabaseUrl, assertDbSplit, blockEndCursor, closeDb, compareStreamsCursor, exports_hmac as crypto, decodeStreamsCursor, exports_ed25519 as ed25519, encodeStreamsCursor, finalizedBurnHeight, formatWebhookSchemaErrors, generateSubgraphAgentSchema, generateSubgraphMarkdown, generateSubgraphOpenApi, generateSubgraphSpec, getDb, getDbSplitStatus, getEnv, getErrorMessage, getMigrationRole, getRawClient, getRawClientFor, getSourceDb, getTargetDb, isBnsDecoderEnabled, isEmptyRangeCursor, isPox4DecoderEnabled, isPox5DecoderEnabled, isSbtcDecoderEnabled, jsonb, logger, onChainPlane, onControlPlane, parseJsonb, setMigrationRole, sql, validateWebhookFilterForTable };
|