@secondlayer/shared 0.2.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 +19 -0
- package/dist/src/crypto/hmac.d.ts +26 -0
- package/dist/src/crypto/hmac.js +75 -0
- package/dist/src/crypto/hmac.js.map +10 -0
- package/dist/src/db/index.d.ts +227 -0
- package/dist/src/db/index.js +75 -0
- package/dist/src/db/index.js.map +11 -0
- package/dist/src/db/jsonb.d.ts +13 -0
- package/dist/src/db/jsonb.js +35 -0
- package/dist/src/db/jsonb.js.map +10 -0
- package/dist/src/db/queries/accounts.d.ts +179 -0
- package/dist/src/db/queries/accounts.js +39 -0
- package/dist/src/db/queries/accounts.js.map +10 -0
- package/dist/src/db/queries/integrity.d.ts +178 -0
- package/dist/src/db/queries/integrity.js +68 -0
- package/dist/src/db/queries/integrity.js.map +10 -0
- package/dist/src/db/queries/metrics.d.ts +179 -0
- package/dist/src/db/queries/metrics.js +51 -0
- package/dist/src/db/queries/metrics.js.map +10 -0
- package/dist/src/db/queries/usage.d.ts +205 -0
- package/dist/src/db/queries/usage.js +117 -0
- package/dist/src/db/queries/usage.js.map +11 -0
- package/dist/src/db/queries/views.d.ts +191 -0
- package/dist/src/db/queries/views.js +111 -0
- package/dist/src/db/queries/views.js.map +11 -0
- package/dist/src/db/schema.d.ts +207 -0
- package/dist/src/db/schema.js +3 -0
- package/dist/src/db/schema.js.map +9 -0
- package/dist/src/env.d.ts +7 -0
- package/dist/src/env.js +60 -0
- package/dist/src/env.js.map +10 -0
- package/dist/src/errors.d.ts +51 -0
- package/dist/src/errors.js +103 -0
- package/dist/src/errors.js.map +10 -0
- package/dist/src/index.d.ts +464 -0
- package/dist/src/index.js +642 -0
- package/dist/src/index.js.map +19 -0
- package/dist/src/lib/plans.d.ts +10 -0
- package/dist/src/lib/plans.js +34 -0
- package/dist/src/lib/plans.js.map +10 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.js +130 -0
- package/dist/src/logger.js.map +11 -0
- package/dist/src/node/client.d.ts +35 -0
- package/dist/src/node/client.js +56 -0
- package/dist/src/node/client.js.map +10 -0
- package/dist/src/node/hiro-client.d.ts +186 -0
- package/dist/src/node/hiro-client.js +410 -0
- package/dist/src/node/hiro-client.js.map +12 -0
- package/dist/src/queue/index.d.ts +50 -0
- package/dist/src/queue/index.js +176 -0
- package/dist/src/queue/index.js.map +12 -0
- package/dist/src/queue/listener.d.ts +20 -0
- package/dist/src/queue/listener.js +63 -0
- package/dist/src/queue/listener.js.map +10 -0
- package/dist/src/queue/recovery.d.ts +14 -0
- package/dist/src/queue/recovery.js +100 -0
- package/dist/src/queue/recovery.js.map +12 -0
- package/dist/src/schemas/filters.d.ts +30 -0
- package/dist/src/schemas/filters.js +133 -0
- package/dist/src/schemas/filters.js.map +10 -0
- package/dist/src/schemas/index.d.ts +109 -0
- package/dist/src/schemas/index.js +228 -0
- package/dist/src/schemas/index.js.map +12 -0
- package/dist/src/schemas/views.d.ts +51 -0
- package/dist/src/schemas/views.js +29 -0
- package/dist/src/schemas/views.js.map +10 -0
- package/dist/src/types.d.ts +102 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +9 -0
- package/migrations/0001_initial.ts +182 -0
- package/migrations/0002_api_keys.ts +38 -0
- package/migrations/0003_tenant_isolation.ts +114 -0
- package/migrations/0004_accounts_and_usage.ts +90 -0
- package/migrations/0005_sessions.ts +42 -0
- package/package.json +128 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/db/jsonb.ts", "../src/db/index.ts", "../src/errors.ts", "../src/env.ts", "../src/logger.ts", "../src/queue/index.ts", "../src/schemas/filters.ts", "../src/schemas/views.ts", "../src/schemas/stream.ts", "../src/crypto/hmac.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { sql } from \"kysely\";\n\n/**\n * Safely encode a JS value as a JSONB literal for Kysely inserts/updates.\n * Kysely + postgres.js double-encodes JSON when using parameterized queries\n * with ::jsonb casts. This uses sql.raw to inline a properly escaped literal.\n */\nexport function jsonb(value: unknown) {\n const escaped = JSON.stringify(value).replace(/'/g, \"''\");\n return sql`${sql.raw(`'${escaped}'::jsonb`)}`;\n}\n\n/**\n * Safely parse a JSONB value from the database.\n * Handles double-encoded strings where postgres.js returns a JSON string\n * instead of a parsed object.\n */\nexport function parseJsonb<T = unknown>(value: unknown): T {\n if (typeof value === \"string\") {\n try {\n return JSON.parse(value) as T;\n } catch {\n return value as T;\n }\n }\n return (value ?? {}) as T;\n}\n",
|
|
6
|
+
"import { Kysely } from \"kysely\";\nimport { PostgresJSDialect } from \"kysely-postgres-js\";\nimport postgres from \"postgres\";\nimport type { Database } from \"./types.ts\";\n\nlet db: Kysely<Database> | null = null;\nlet rawClient: ReturnType<typeof postgres> | null = null;\n\nexport function getDb(connectionString?: string): Kysely<Database> {\n if (!db) {\n const url = connectionString || process.env.DATABASE_URL || \"postgres://postgres:postgres@localhost:5432/streams_dev\";\n\n // Always use SSL for remote databases, just disable cert verification if needed\n const isLocal = url.includes(\"localhost\") || url.includes(\"127.0.0.1\") || url.includes(\"@postgres:\");\n rawClient = postgres(url, {\n ssl: isLocal ? undefined : { rejectUnauthorized: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== \"0\" },\n });\n db = new Kysely<Database>({\n dialect: new PostgresJSDialect({ postgres: rawClient }),\n });\n }\n return db;\n}\n\n/** Raw postgres.js client for dynamic schema DDL (CREATE SCHEMA, DROP, etc.) */\nexport function getRawClient(): ReturnType<typeof postgres> {\n if (!rawClient) getDb();\n return rawClient!;\n}\n\n/** Close the DB connection pool. Call in CLI commands to allow process exit. */\nexport async function closeDb(): Promise<void> {\n if (db) {\n await db.destroy();\n db = null;\n }\n if (rawClient) {\n await rawClient.end();\n rawClient = null;\n }\n}\n\nimport { sql } from \"kysely\";\nexport { sql };\nexport * from \"./types.ts\";\nexport { jsonb, parseJsonb } from \"./jsonb.ts\";\n",
|
|
7
|
+
"/**\n * Base error class for all Stacks Streams errors\n */\nexport class StreamsError extends Error {\n public code: string;\n public override cause?: unknown;\n\n constructor(\n code: string,\n message: string,\n cause?: unknown\n ) {\n super(message);\n this.code = code;\n this.cause = cause;\n this.name = this.constructor.name;\n Error.captureStackTrace?.(this, this.constructor);\n }\n\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n stack: this.stack,\n cause: this.cause,\n };\n }\n}\n\n/**\n * Stream not found error\n */\nexport class StreamNotFoundError extends StreamsError {\n constructor(streamId: string) {\n super(\"STREAM_NOT_FOUND\", `Stream not found: ${streamId}`);\n }\n}\n\n/**\n * Validation error for invalid input\n */\nexport class ValidationError extends StreamsError {\n constructor(message: string, cause?: unknown) {\n super(\"VALIDATION_ERROR\", message, cause);\n }\n}\n\n/**\n * Database operation error\n */\nexport class DatabaseError extends StreamsError {\n constructor(message: string, cause?: unknown) {\n super(\"DATABASE_ERROR\", message, cause);\n }\n}\n\n/**\n * Webhook delivery error\n */\nexport class WebhookDeliveryError extends StreamsError {\n constructor(\n message: string,\n public statusCode?: number,\n cause?: unknown\n ) {\n super(\"WEBHOOK_DELIVERY_ERROR\", message, cause);\n }\n\n override toJSON() {\n return {\n ...super.toJSON(),\n statusCode: this.statusCode,\n };\n }\n}\n\n/**\n * Filter evaluation error\n */\nexport class FilterEvaluationError extends StreamsError {\n constructor(message: string, cause?: unknown) {\n super(\"FILTER_EVALUATION_ERROR\", message, cause);\n }\n}\n\nexport class AuthenticationError extends StreamsError {\n constructor(message: string) {\n super(\"AUTHENTICATION_ERROR\", message);\n }\n}\n\nexport class AuthorizationError extends StreamsError {\n constructor(message: string) {\n super(\"AUTHORIZATION_ERROR\", message);\n }\n}\n\nexport class RateLimitError extends StreamsError {\n constructor(message: string) {\n super(\"RATE_LIMIT_ERROR\", message);\n }\n}\n",
|
|
8
|
+
"import { z } from \"zod\";\n\n// Parse comma-separated networks\nconst networksSchema = z.string().transform((val) => {\n const networks = val.split(\",\").map((n) => n.trim()).filter(Boolean);\n const valid = [\"mainnet\", \"testnet\"];\n for (const n of networks) {\n if (!valid.includes(n)) {\n throw new Error(`Invalid network: ${n}. Must be one of: ${valid.join(\", \")}`);\n }\n }\n return networks as (\"mainnet\" | \"testnet\")[];\n});\n\nconst envSchema = z.object({\n // DATABASE_URL is optional - consumers must provide their own\n DATABASE_URL: z.preprocess(\n (val) => (typeof val === \"string\" && val.length === 0) ? undefined : val,\n z.string().url().optional(),\n ),\n // Single network (deprecated, for backwards compatibility)\n NETWORK: z.enum([\"mainnet\", \"testnet\"]).optional(),\n // Multiple networks (comma-separated)\n NETWORKS: networksSchema.optional(),\n LOG_LEVEL: z.enum([\"debug\", \"info\", \"warn\", \"error\"]).default(\"info\"),\n NODE_ENV: z.enum([\"development\", \"production\", \"test\"]).default(\"development\"),\n});\n\nexport type Env = z.infer<typeof envSchema> & {\n enabledNetworks: (\"mainnet\" | \"testnet\")[];\n};\n\nlet cachedEnv: Env | null = null;\n\nexport function getEnv(): Env {\n if (cachedEnv) {\n return cachedEnv;\n }\n\n const result = envSchema.safeParse(process.env);\n\n if (!result.success) {\n console.error(\"❌ Invalid environment configuration:\");\n console.error(result.error.format());\n throw new Error(\"Invalid environment configuration\");\n }\n\n // Compute enabled networks from NETWORKS or NETWORK\n let enabledNetworks: (\"mainnet\" | \"testnet\")[];\n if (result.data.NETWORKS && result.data.NETWORKS.length > 0) {\n enabledNetworks = result.data.NETWORKS;\n } else if (result.data.NETWORK) {\n enabledNetworks = [result.data.NETWORK];\n } else {\n enabledNetworks = [\"mainnet\"]; // Default\n }\n\n cachedEnv = { ...result.data, enabledNetworks };\n return cachedEnv;\n}\n\n// Export for testing\nexport { envSchema };\n",
|
|
9
|
+
"import { getEnv } from \"./env.ts\";\n\ntype LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n};\n\nclass Logger {\n private _level?: LogLevel;\n private _isProduction?: boolean;\n private _initialized = false;\n\n private init() {\n if (this._initialized) return;\n this._initialized = true;\n try {\n const env = getEnv();\n this._level = env.LOG_LEVEL;\n this._isProduction = env.NODE_ENV === \"production\";\n } catch {\n // Fallback when env is unavailable (e.g. tests without DATABASE_URL)\n this._level = \"info\";\n this._isProduction = false;\n }\n }\n\n private get level(): LogLevel {\n this.init();\n return this._level!;\n }\n\n private get isProduction(): boolean {\n this.init();\n return this._isProduction!;\n }\n\n private shouldLog(level: LogLevel): boolean {\n return LOG_LEVELS[level] >= LOG_LEVELS[this.level];\n }\n\n private formatMessage(level: LogLevel, message: string, meta?: Record<string, any>) {\n const timestamp = new Date().toISOString();\n\n if (this.isProduction) {\n // JSON output for production\n return JSON.stringify({\n timestamp,\n level,\n message,\n ...meta,\n });\n }\n\n // Human-readable output for development\n const metaStr = meta ? ` ${JSON.stringify(meta)}` : \"\";\n return `[${timestamp}] ${level.toUpperCase()}: ${message}${metaStr}`;\n }\n\n debug(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"debug\")) {\n console.debug(this.formatMessage(\"debug\", message, meta));\n }\n }\n\n info(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"info\")) {\n console.info(this.formatMessage(\"info\", message, meta));\n }\n }\n\n warn(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"warn\")) {\n console.warn(this.formatMessage(\"warn\", message, meta));\n }\n }\n\n error(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"error\")) {\n console.error(this.formatMessage(\"error\", message, meta));\n }\n }\n}\n\n// Export singleton instance\nexport const logger = new Logger();\n",
|
|
10
|
+
"import { sql } from \"kysely\";\nimport { getDb } from \"../db/index.ts\";\nimport type { Job } from \"../db/types.ts\";\nimport { randomUUID } from \"crypto\";\n\nexport interface QueueStats {\n pending: number;\n processing: number;\n completed: number;\n failed: number;\n total: number;\n}\n\n// Worker identifier for this process\nconst WORKER_ID = `worker-${randomUUID().slice(0, 8)}`;\n\n/**\n * Enqueue a new job for stream evaluation\n */\nexport async function enqueue(\n streamId: string,\n blockHeight: number,\n backfill = false\n): Promise<string> {\n const db = getDb();\n\n const row = await db\n .insertInto(\"jobs\")\n .values({\n stream_id: streamId,\n block_height: blockHeight,\n backfill,\n status: \"pending\",\n attempts: 0,\n })\n .returning([\"id\"])\n .executeTakeFirstOrThrow();\n\n return row.id;\n}\n\n/**\n * Claim a pending job using SKIP LOCKED to prevent concurrent access\n * Returns null if no jobs available\n */\nexport async function claim(): Promise<Job | null> {\n const db = getDb();\n\n const { rows } = await sql<Job>`\n UPDATE jobs\n SET\n status = 'processing',\n locked_at = NOW(),\n locked_by = ${WORKER_ID},\n attempts = attempts + 1\n WHERE id = (\n SELECT id FROM jobs\n WHERE status = 'pending'\n ORDER BY\n backfill ASC,\n block_height ASC,\n created_at ASC\n FOR UPDATE SKIP LOCKED\n LIMIT 1\n )\n RETURNING *\n `.execute(db);\n\n return rows[0] ?? null;\n}\n\n/**\n * Mark a job as completed\n */\nexport async function complete(jobId: string): Promise<void> {\n const db = getDb();\n\n await db\n .updateTable(\"jobs\")\n .set({\n status: \"completed\",\n completed_at: new Date(),\n locked_at: null,\n locked_by: null,\n })\n .where(\"id\", \"=\", jobId)\n .execute();\n}\n\n/**\n * Mark a job as failed\n * Re-queues if under max attempts, otherwise marks as permanently failed\n */\nexport async function fail(\n jobId: string,\n error: string,\n maxAttempts = 3\n): Promise<void> {\n const db = getDb();\n\n const job = await db\n .selectFrom(\"jobs\")\n .select(\"attempts\")\n .where(\"id\", \"=\", jobId)\n .executeTakeFirst();\n\n if (!job) return;\n\n if (job.attempts < maxAttempts) {\n await db\n .updateTable(\"jobs\")\n .set({\n status: \"pending\",\n error,\n locked_at: null,\n locked_by: null,\n })\n .where(\"id\", \"=\", jobId)\n .execute();\n } else {\n await db\n .updateTable(\"jobs\")\n .set({\n status: \"failed\",\n error,\n completed_at: new Date(),\n locked_at: null,\n locked_by: null,\n })\n .where(\"id\", \"=\", jobId)\n .execute();\n }\n}\n\n/**\n * Get queue statistics\n */\nexport async function stats(): Promise<QueueStats> {\n const { rows } = await sql<{ status: string; count: string }>`\n SELECT status, COUNT(*) as count\n FROM jobs\n GROUP BY status\n `.execute(getDb());\n\n const counts: Record<string, number> = {};\n for (const row of rows) {\n counts[row.status] = parseInt(row.count, 10);\n }\n\n return {\n pending: counts[\"pending\"] || 0,\n processing: counts[\"processing\"] || 0,\n completed: counts[\"completed\"] || 0,\n failed: counts[\"failed\"] || 0,\n total: Object.values(counts).reduce((a, b) => a + b, 0),\n };\n}\n\n/**\n * Get worker ID for this process\n */\nexport function getWorkerId(): string {\n return WORKER_ID;\n}\n\nexport { WORKER_ID };\n",
|
|
11
|
+
"import { z } from \"zod\";\nimport { validateStacksAddress } from \"@stacks/transactions\";\n\n/** Validate a Stacks principal (standard or contract, e.g. SP2J...ABC or SP2J...ABC.contract-name) */\nconst stacksPrincipal = z.string().refine((val) => {\n const parts = val.split(\".\");\n if (parts.length > 2) return false;\n return validateStacksAddress(parts[0]!);\n}, \"Invalid Stacks principal address\");\n\n// Base filter with common fields\nconst baseFilter = {\n // Optional: filter by sender\n sender: stacksPrincipal.optional(),\n // Optional: filter by recipient\n recipient: stacksPrincipal.optional(),\n};\n\n// STX Transfer Filter\nexport const StxTransferFilterSchema = z.object({\n type: z.literal(\"stx_transfer\"),\n ...baseFilter,\n // Optional: minimum amount in microSTX\n minAmount: z.coerce.number().int().positive().optional(),\n // Optional: maximum amount in microSTX\n maxAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Mint Filter\nexport const StxMintFilterSchema = z.object({\n type: z.literal(\"stx_mint\"),\n recipient: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Burn Filter\nexport const StxBurnFilterSchema = z.object({\n type: z.literal(\"stx_burn\"),\n sender: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// STX Lock Filter\nexport const StxLockFilterSchema = z.object({\n type: z.literal(\"stx_lock\"),\n lockedAddress: stacksPrincipal.optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Transfer Filter\nexport const FtTransferFilterSchema = z.object({\n type: z.literal(\"ft_transfer\"),\n ...baseFilter,\n // Contract that defines the token (e.g., SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx)\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Mint Filter\nexport const FtMintFilterSchema = z.object({\n type: z.literal(\"ft_mint\"),\n recipient: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// FT Burn Filter\nexport const FtBurnFilterSchema = z.object({\n type: z.literal(\"ft_burn\"),\n sender: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n minAmount: z.coerce.number().int().positive().optional(),\n});\n\n// NFT Transfer Filter\nexport const NftTransferFilterSchema = z.object({\n type: z.literal(\"nft_transfer\"),\n ...baseFilter,\n assetIdentifier: z.string().optional(),\n // Optional: filter by specific token ID (Clarity value as hex)\n tokenId: z.string().optional(),\n});\n\n// NFT Mint Filter\nexport const NftMintFilterSchema = z.object({\n type: z.literal(\"nft_mint\"),\n recipient: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n tokenId: z.string().optional(),\n});\n\n// NFT Burn Filter\nexport const NftBurnFilterSchema = z.object({\n type: z.literal(\"nft_burn\"),\n sender: stacksPrincipal.optional(),\n assetIdentifier: z.string().optional(),\n tokenId: z.string().optional(),\n});\n\n// Contract Call Filter\nexport const ContractCallFilterSchema = z.object({\n type: z.literal(\"contract_call\"),\n // Contract being called\n contractId: stacksPrincipal.optional(),\n // Function name (supports wildcards with *)\n functionName: z.string().optional(),\n // Caller address\n caller: stacksPrincipal.optional(),\n});\n\n// Contract Deploy Filter\nexport const ContractDeployFilterSchema = z.object({\n type: z.literal(\"contract_deploy\"),\n // Deployer address\n deployer: stacksPrincipal.optional(),\n // Contract name pattern (supports wildcards)\n contractName: z.string().optional(),\n});\n\n// Print Event Filter (smart contract events)\nexport const PrintEventFilterSchema = z.object({\n type: z.literal(\"print_event\"),\n // Contract emitting the event\n contractId: stacksPrincipal.optional(),\n // Topic/name of the event\n topic: z.string().optional(),\n // Search for substring in event data\n contains: z.string().optional(),\n});\n\n// Union of all filter types\nexport const StreamFilterSchema = z.discriminatedUnion(\"type\", [\n StxTransferFilterSchema,\n StxMintFilterSchema,\n StxBurnFilterSchema,\n StxLockFilterSchema,\n FtTransferFilterSchema,\n FtMintFilterSchema,\n FtBurnFilterSchema,\n NftTransferFilterSchema,\n NftMintFilterSchema,\n NftBurnFilterSchema,\n ContractCallFilterSchema,\n ContractDeployFilterSchema,\n PrintEventFilterSchema,\n]);\n\n// Type exports\nexport type StxTransferFilter = z.infer<typeof StxTransferFilterSchema>;\nexport type StxMintFilter = z.infer<typeof StxMintFilterSchema>;\nexport type StxBurnFilter = z.infer<typeof StxBurnFilterSchema>;\nexport type StxLockFilter = z.infer<typeof StxLockFilterSchema>;\nexport type FtTransferFilter = z.infer<typeof FtTransferFilterSchema>;\nexport type FtMintFilter = z.infer<typeof FtMintFilterSchema>;\nexport type FtBurnFilter = z.infer<typeof FtBurnFilterSchema>;\nexport type NftTransferFilter = z.infer<typeof NftTransferFilterSchema>;\nexport type NftMintFilter = z.infer<typeof NftMintFilterSchema>;\nexport type NftBurnFilter = z.infer<typeof NftBurnFilterSchema>;\nexport type ContractCallFilter = z.infer<typeof ContractCallFilterSchema>;\nexport type ContractDeployFilter = z.infer<typeof ContractDeployFilterSchema>;\nexport type PrintEventFilter = z.infer<typeof PrintEventFilterSchema>;\nexport type StreamFilter = z.infer<typeof StreamFilterSchema>;\n",
|
|
12
|
+
"import { z } from \"zod\";\n\n// ── Deploy View Request ─────────────────────────────────────────────────\n\nexport const DeployViewRequestSchema = z.object({\n name: z.string().regex(/^[a-z0-9-]+$/, \"lowercase alphanumeric + hyphens only\").max(63),\n version: z.string().optional(),\n description: z.string().optional(),\n sources: z.array(z.string()).min(1),\n schema: z.record(z.unknown()),\n handlerCode: z.string().max(1_048_576, \"handler code exceeds 1MB limit\"),\n reindex: z.boolean().optional(),\n});\n\nexport type DeployViewRequest = z.infer<typeof DeployViewRequestSchema>;\n\nexport interface DeployViewResponse {\n action: \"created\" | \"unchanged\" | \"updated\" | \"reindexed\";\n viewId: string;\n message: string;\n}\n\n// View API response types\n\nexport interface ViewSummary {\n name: string;\n version: string;\n status: string;\n lastProcessedBlock: number;\n tables: string[];\n createdAt: string;\n}\n\nexport interface ViewDetail {\n name: string;\n version: string;\n status: string;\n lastProcessedBlock: number;\n health: {\n totalProcessed: number;\n totalErrors: number;\n errorRate: number;\n lastError: string | null;\n lastErrorAt: string | null;\n };\n tables: Record<string, {\n endpoint: string;\n columns: Record<string, string>;\n rowCount: number;\n example: string;\n }>;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ReindexResponse {\n message: string;\n fromBlock: number;\n toBlock: number | string;\n}\n\nexport interface ViewQueryParams {\n sort?: string;\n order?: string;\n limit?: number;\n offset?: number;\n fields?: string;\n filters?: Record<string, string>;\n}\n",
|
|
13
|
+
"import { z } from \"zod\";\nimport { StreamFilterSchema } from \"./filters.ts\";\n\n// Stream options schema\nexport const StreamOptionsSchema = z.object({\n // Include decoded Clarity values in webhook payload\n decodeClarityValues: z.boolean().default(true),\n // Include raw transaction hex in payload\n includeRawTx: z.boolean().default(false),\n // Include full block metadata\n includeBlockMetadata: z.boolean().default(true),\n // Rate limit: max webhooks per second\n rateLimit: z.number().int().positive().max(100).default(10),\n // Timeout for webhook delivery in ms\n timeoutMs: z.number().int().positive().max(30000).default(10000),\n // Max retry attempts for failed webhooks\n maxRetries: z.number().int().min(0).max(10).default(3),\n});\n\n// Create stream schema\nexport const CreateStreamSchema = z.object({\n name: z.string().min(1).max(255),\n webhookUrl: z.string().url(),\n // At least one filter required\n filters: z.array(StreamFilterSchema).min(1),\n // Optional settings\n options: StreamOptionsSchema.optional().default({}),\n // Optional: start processing from specific block (for backfill)\n startBlock: z.number().int().positive().optional(),\n // Optional: stop processing at specific block\n endBlock: z.number().int().positive().optional(),\n});\n\n// Update stream schema (all fields optional)\nexport const UpdateStreamSchema = z.object({\n name: z.string().min(1).max(255).optional(),\n webhookUrl: z.string().url().optional(),\n filters: z.array(StreamFilterSchema).min(1).optional(),\n options: StreamOptionsSchema.partial().optional(),\n}).refine(\n (data) => Object.keys(data).length > 0,\n { message: \"At least one field must be provided for update\" }\n);\n\n// Webhook payload schema (what gets sent to the user's endpoint)\nexport const WebhookPayloadSchema = z.object({\n // Stream metadata\n streamId: z.string().uuid(),\n streamName: z.string(),\n\n // Block metadata\n block: z.object({\n height: z.number(),\n hash: z.string(),\n parentHash: z.string(),\n burnBlockHeight: z.number(),\n timestamp: z.number(),\n }),\n\n // Matched data\n matches: z.object({\n transactions: z.array(z.object({\n txId: z.string(),\n type: z.string(),\n sender: z.string(),\n status: z.string(),\n contractId: z.string().nullable(),\n functionName: z.string().nullable(),\n rawTx: z.string().optional(),\n })),\n events: z.array(z.object({\n txId: z.string(),\n eventIndex: z.number(),\n type: z.string(),\n data: z.any(),\n })),\n }),\n\n // Metadata\n isBackfill: z.boolean(),\n deliveredAt: z.string().datetime(),\n});\n\n// Stream response schema (what API returns)\n// Stream metrics schema\nexport const StreamMetricsSchema = z.object({\n totalDeliveries: z.number(),\n failedDeliveries: z.number(),\n lastTriggeredAt: z.string().datetime().nullable(),\n lastTriggeredBlock: z.number().nullable(),\n errorMessage: z.string().nullable(),\n});\n\n// Stream response schema (what API returns)\nexport const StreamResponseSchema = z.object({\n id: z.string().uuid(),\n name: z.string(),\n status: z.enum([\"inactive\", \"active\", \"paused\", \"failed\"]),\n webhookUrl: z.string().url(),\n filters: z.array(StreamFilterSchema),\n options: StreamOptionsSchema,\n\n // Metrics (joined from stream_metrics)\n totalDeliveries: z.number().int().default(0),\n failedDeliveries: z.number().int().default(0),\n lastTriggeredAt: z.string().datetime().nullable().optional(),\n lastTriggeredBlock: z.number().int().nullable().optional(),\n errorMessage: z.string().nullable().optional(),\n\n createdAt: z.string().datetime(),\n updatedAt: z.string().datetime(),\n});\n\n// Type exports\nexport type StreamOptions = z.infer<typeof StreamOptionsSchema>;\nexport type CreateStream = z.infer<typeof CreateStreamSchema>;\nexport type UpdateStream = z.infer<typeof UpdateStreamSchema>;\nexport type WebhookPayload = z.infer<typeof WebhookPayloadSchema>;\nexport type StreamResponse = z.infer<typeof StreamResponseSchema>;\nexport type StreamMetricsResponse = z.infer<typeof StreamMetricsSchema>;\n\n// API response types\nexport interface CreateStreamResponse {\n stream: StreamResponse;\n webhookSecret: string;\n}\n\nexport interface ListStreamsResponse {\n streams: StreamResponse[];\n total: number;\n}\n\nexport interface BulkPauseResponse {\n paused: number;\n streams: StreamResponse[];\n}\n\nexport interface BulkResumeResponse {\n resumed: number;\n streams: StreamResponse[];\n}\n",
|
|
14
|
+
"import { createHmac, randomBytes } from \"crypto\";\n\n/**\n * Generate a random secret for webhook signing\n * Returns 32 bytes as a 64-character hex string\n */\nexport function generateSecret(): string {\n return randomBytes(32).toString(\"hex\");\n}\n\n/**\n * Sign a payload with HMAC-SHA256\n * Returns the signature as a hex string\n */\nexport function signPayload(payload: string, secret: string): string {\n const hmac = createHmac(\"sha256\", secret);\n hmac.update(payload);\n return hmac.digest(\"hex\");\n}\n\n/**\n * Verify an HMAC signature\n * Uses constant-time comparison to prevent timing attacks\n */\nexport function verifySignature(\n payload: string,\n signature: string,\n secret: string\n): boolean {\n const expectedSignature = signPayload(payload, secret);\n\n // Constant-time comparison\n if (signature.length !== expectedSignature.length) {\n return false;\n }\n\n let result = 0;\n for (let i = 0; i < signature.length; i++) {\n result |= signature.charCodeAt(i) ^ expectedSignature.charCodeAt(i);\n }\n\n return result === 0;\n}\n\n/**\n * Create a Stripe-style signature header\n * Format: t=timestamp,v1=signature\n */\nexport function createSignatureHeader(\n payload: string,\n secret: string,\n timestamp?: number\n): string {\n const ts = timestamp ?? Math.floor(Date.now() / 1000);\n const signedPayload = `${ts}.${payload}`;\n const signature = signPayload(signedPayload, secret);\n\n return `t=${ts},v1=${signature}`;\n}\n\n/**\n * Parse and verify a Stripe-style signature header\n * Returns true if valid, false otherwise\n */\nexport function verifySignatureHeader(\n payload: string,\n header: string,\n secret: string,\n toleranceSeconds = 300 // 5 minutes\n): boolean {\n // Parse header\n const parts = header.split(\",\");\n const timestamp = parts\n .find((p) => p.startsWith(\"t=\"))\n ?.slice(2);\n const signature = parts\n .find((p) => p.startsWith(\"v1=\"))\n ?.slice(3);\n\n if (!timestamp || !signature) {\n return false;\n }\n\n const ts = parseInt(timestamp, 10);\n if (isNaN(ts)) {\n return false;\n }\n\n // Check timestamp is within tolerance\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > toleranceSeconds) {\n return false;\n }\n\n // Verify signature\n const signedPayload = `${ts}.${payload}`;\n return verifySignature(signedPayload, signature, secret);\n}\n"
|
|
15
|
+
],
|
|
16
|
+
"mappings": ";;;;;;;;;;;;AAAA;AAOO,SAAS,KAAK,CAAC,OAAgB;AAAA,EACpC,MAAM,UAAU,KAAK,UAAU,KAAK,EAAE,QAAQ,MAAM,IAAI;AAAA,EACxD,OAAO,MAAM,IAAI,IAAI,IAAI,iBAAiB;AAAA;AAQrC,SAAS,UAAuB,CAAC,OAAmB;AAAA,EACzD,IAAI,OAAO,UAAU,UAAU;AAAA,IAC7B,IAAI;AAAA,MACF,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,MAAM;AAAA,MACN,OAAO;AAAA;AAAA,EAEX;AAAA,EACA,OAAQ,SAAS,CAAC;AAAA;;;ACzBpB;AACA;AACA;AAwCA,gBAAS;AArCT,IAAI,KAA8B;AAClC,IAAI,YAAgD;AAE7C,SAAS,KAAK,CAAC,kBAA6C;AAAA,EACjE,IAAI,CAAC,IAAI;AAAA,IACP,MAAM,MAAM,oBAAoB,QAAQ,IAAI,gBAAgB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,EACpE;AAAA,EAEA,OAAO,WAAW;AAAA;AAOb,SAAS,qBAAqB,CACnC,SACA,QACA,WACQ;AAAA,EACR,MAAM,KAAK,aAAa,KAAK,MAAM,KAAK,IAAI,IAAI,IAAI;AAAA,EACpD,MAAM,gBAAgB,GAAG,MAAM;AAAA,EAC/B,MAAM,YAAY,YAAY,eAAe,MAAM;AAAA,EAEnD,OAAO,KAAK,SAAS;AAAA;AAOhB,SAAS,qBAAqB,CACnC,SACA,QACA,QACA,mBAAmB,KACV;AAAA,EAET,MAAM,QAAQ,OAAO,MAAM,GAAG;AAAA,EAC9B,MAAM,YAAY,MACf,KAAK,CAAC,MAAM,EAAE,WAAW,IAAI,CAAC,GAC7B,MAAM,CAAC;AAAA,EACX,MAAM,YAAY,MACf,KAAK,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAC9B,MAAM,CAAC;AAAA,EAEX,IAAI,CAAC,aAAa,CAAC,WAAW;AAAA,IAC5B,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,SAAS,WAAW,EAAE;AAAA,EACjC,IAAI,MAAM,EAAE,GAAG;AAAA,IACb,OAAO;AAAA,EACT;AAAA,EAGA,MAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,IAAI;AAAA,EACxC,IAAI,KAAK,IAAI,MAAM,EAAE,IAAI,kBAAkB;AAAA,IACzC,OAAO;AAAA,EACT;AAAA,EAGA,MAAM,gBAAgB,GAAG,MAAM;AAAA,EAC/B,OAAO,gBAAgB,eAAe,WAAW,MAAM;AAAA;",
|
|
17
|
+
"debugId": "52ED396A08F9D61564756E2164756E21",
|
|
18
|
+
"names": []
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface PlanLimits {
|
|
2
|
+
streams: number;
|
|
3
|
+
views: number;
|
|
4
|
+
apiRequestsPerDay: number;
|
|
5
|
+
deliveriesPerMonth: number;
|
|
6
|
+
storageBytes: number;
|
|
7
|
+
}
|
|
8
|
+
declare const FREE_PLAN: PlanLimits;
|
|
9
|
+
declare function getPlanLimits(plan: string): PlanLimits;
|
|
10
|
+
export { getPlanLimits, PlanLimits, FREE_PLAN };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/lib/plans.ts
|
|
14
|
+
var FREE_PLAN = {
|
|
15
|
+
streams: 3,
|
|
16
|
+
views: 2,
|
|
17
|
+
apiRequestsPerDay: 1000,
|
|
18
|
+
deliveriesPerMonth: 5000,
|
|
19
|
+
storageBytes: 100 * 1024 * 1024
|
|
20
|
+
};
|
|
21
|
+
function getPlanLimits(plan) {
|
|
22
|
+
switch (plan) {
|
|
23
|
+
case "free":
|
|
24
|
+
default:
|
|
25
|
+
return FREE_PLAN;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
getPlanLimits,
|
|
30
|
+
FREE_PLAN
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//# debugId=1071D4513115365B64756E2164756E21
|
|
34
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/plans.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export interface PlanLimits {\n streams: number;\n views: number;\n apiRequestsPerDay: number;\n deliveriesPerMonth: number;\n storageBytes: number;\n}\n\nexport const FREE_PLAN: PlanLimits = {\n streams: 3,\n views: 2,\n apiRequestsPerDay: 1_000,\n deliveriesPerMonth: 5_000,\n storageBytes: 100 * 1024 * 1024, // 100MB\n};\n\nexport function getPlanLimits(plan: string): PlanLimits {\n switch (plan) {\n case \"free\":\n default:\n return FREE_PLAN;\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;AAQO,IAAM,YAAwB;AAAA,EACnC,SAAS;AAAA,EACT,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACpB,cAAc,MAAM,OAAO;AAC7B;AAEO,SAAS,aAAa,CAAC,MAA0B;AAAA,EACtD,QAAQ;AAAA,SACD;AAAA;AAAA,MAEH,OAAO;AAAA;AAAA;",
|
|
8
|
+
"debugId": "1071D4513115365B64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/env.ts
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
var networksSchema = z.string().transform((val) => {
|
|
16
|
+
const networks = val.split(",").map((n) => n.trim()).filter(Boolean);
|
|
17
|
+
const valid = ["mainnet", "testnet"];
|
|
18
|
+
for (const n of networks) {
|
|
19
|
+
if (!valid.includes(n)) {
|
|
20
|
+
throw new Error(`Invalid network: ${n}. Must be one of: ${valid.join(", ")}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return networks;
|
|
24
|
+
});
|
|
25
|
+
var envSchema = z.object({
|
|
26
|
+
DATABASE_URL: z.preprocess((val) => typeof val === "string" && val.length === 0 ? undefined : val, z.string().url().optional()),
|
|
27
|
+
NETWORK: z.enum(["mainnet", "testnet"]).optional(),
|
|
28
|
+
NETWORKS: networksSchema.optional(),
|
|
29
|
+
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
|
30
|
+
NODE_ENV: z.enum(["development", "production", "test"]).default("development")
|
|
31
|
+
});
|
|
32
|
+
var cachedEnv = null;
|
|
33
|
+
function getEnv() {
|
|
34
|
+
if (cachedEnv) {
|
|
35
|
+
return cachedEnv;
|
|
36
|
+
}
|
|
37
|
+
const result = envSchema.safeParse(process.env);
|
|
38
|
+
if (!result.success) {
|
|
39
|
+
console.error("❌ Invalid environment configuration:");
|
|
40
|
+
console.error(result.error.format());
|
|
41
|
+
throw new Error("Invalid environment configuration");
|
|
42
|
+
}
|
|
43
|
+
let enabledNetworks;
|
|
44
|
+
if (result.data.NETWORKS && result.data.NETWORKS.length > 0) {
|
|
45
|
+
enabledNetworks = result.data.NETWORKS;
|
|
46
|
+
} else if (result.data.NETWORK) {
|
|
47
|
+
enabledNetworks = [result.data.NETWORK];
|
|
48
|
+
} else {
|
|
49
|
+
enabledNetworks = ["mainnet"];
|
|
50
|
+
}
|
|
51
|
+
cachedEnv = { ...result.data, enabledNetworks };
|
|
52
|
+
return cachedEnv;
|
|
53
|
+
}
|
|
54
|
+
// src/logger.ts
|
|
55
|
+
var LOG_LEVELS = {
|
|
56
|
+
debug: 0,
|
|
57
|
+
info: 1,
|
|
58
|
+
warn: 2,
|
|
59
|
+
error: 3
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
class Logger {
|
|
63
|
+
_level;
|
|
64
|
+
_isProduction;
|
|
65
|
+
_initialized = false;
|
|
66
|
+
init() {
|
|
67
|
+
if (this._initialized)
|
|
68
|
+
return;
|
|
69
|
+
this._initialized = true;
|
|
70
|
+
try {
|
|
71
|
+
const env = getEnv();
|
|
72
|
+
this._level = env.LOG_LEVEL;
|
|
73
|
+
this._isProduction = env.NODE_ENV === "production";
|
|
74
|
+
} catch {
|
|
75
|
+
this._level = "info";
|
|
76
|
+
this._isProduction = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
get level() {
|
|
80
|
+
this.init();
|
|
81
|
+
return this._level;
|
|
82
|
+
}
|
|
83
|
+
get isProduction() {
|
|
84
|
+
this.init();
|
|
85
|
+
return this._isProduction;
|
|
86
|
+
}
|
|
87
|
+
shouldLog(level) {
|
|
88
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
|
|
89
|
+
}
|
|
90
|
+
formatMessage(level, message, meta) {
|
|
91
|
+
const timestamp = new Date().toISOString();
|
|
92
|
+
if (this.isProduction) {
|
|
93
|
+
return JSON.stringify({
|
|
94
|
+
timestamp,
|
|
95
|
+
level,
|
|
96
|
+
message,
|
|
97
|
+
...meta
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const metaStr = meta ? ` ${JSON.stringify(meta)}` : "";
|
|
101
|
+
return `[${timestamp}] ${level.toUpperCase()}: ${message}${metaStr}`;
|
|
102
|
+
}
|
|
103
|
+
debug(message, meta) {
|
|
104
|
+
if (this.shouldLog("debug")) {
|
|
105
|
+
console.debug(this.formatMessage("debug", message, meta));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
info(message, meta) {
|
|
109
|
+
if (this.shouldLog("info")) {
|
|
110
|
+
console.info(this.formatMessage("info", message, meta));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
warn(message, meta) {
|
|
114
|
+
if (this.shouldLog("warn")) {
|
|
115
|
+
console.warn(this.formatMessage("warn", message, meta));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
error(message, meta) {
|
|
119
|
+
if (this.shouldLog("error")) {
|
|
120
|
+
console.error(this.formatMessage("error", message, meta));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
var logger = new Logger;
|
|
125
|
+
export {
|
|
126
|
+
logger
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
//# debugId=C3A89D3B91522A5964756E2164756E21
|
|
130
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/env.ts", "../src/logger.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { z } from \"zod\";\n\n// Parse comma-separated networks\nconst networksSchema = z.string().transform((val) => {\n const networks = val.split(\",\").map((n) => n.trim()).filter(Boolean);\n const valid = [\"mainnet\", \"testnet\"];\n for (const n of networks) {\n if (!valid.includes(n)) {\n throw new Error(`Invalid network: ${n}. Must be one of: ${valid.join(\", \")}`);\n }\n }\n return networks as (\"mainnet\" | \"testnet\")[];\n});\n\nconst envSchema = z.object({\n // DATABASE_URL is optional - consumers must provide their own\n DATABASE_URL: z.preprocess(\n (val) => (typeof val === \"string\" && val.length === 0) ? undefined : val,\n z.string().url().optional(),\n ),\n // Single network (deprecated, for backwards compatibility)\n NETWORK: z.enum([\"mainnet\", \"testnet\"]).optional(),\n // Multiple networks (comma-separated)\n NETWORKS: networksSchema.optional(),\n LOG_LEVEL: z.enum([\"debug\", \"info\", \"warn\", \"error\"]).default(\"info\"),\n NODE_ENV: z.enum([\"development\", \"production\", \"test\"]).default(\"development\"),\n});\n\nexport type Env = z.infer<typeof envSchema> & {\n enabledNetworks: (\"mainnet\" | \"testnet\")[];\n};\n\nlet cachedEnv: Env | null = null;\n\nexport function getEnv(): Env {\n if (cachedEnv) {\n return cachedEnv;\n }\n\n const result = envSchema.safeParse(process.env);\n\n if (!result.success) {\n console.error(\"❌ Invalid environment configuration:\");\n console.error(result.error.format());\n throw new Error(\"Invalid environment configuration\");\n }\n\n // Compute enabled networks from NETWORKS or NETWORK\n let enabledNetworks: (\"mainnet\" | \"testnet\")[];\n if (result.data.NETWORKS && result.data.NETWORKS.length > 0) {\n enabledNetworks = result.data.NETWORKS;\n } else if (result.data.NETWORK) {\n enabledNetworks = [result.data.NETWORK];\n } else {\n enabledNetworks = [\"mainnet\"]; // Default\n }\n\n cachedEnv = { ...result.data, enabledNetworks };\n return cachedEnv;\n}\n\n// Export for testing\nexport { envSchema };\n",
|
|
6
|
+
"import { getEnv } from \"./env.ts\";\n\ntype LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n};\n\nclass Logger {\n private _level?: LogLevel;\n private _isProduction?: boolean;\n private _initialized = false;\n\n private init() {\n if (this._initialized) return;\n this._initialized = true;\n try {\n const env = getEnv();\n this._level = env.LOG_LEVEL;\n this._isProduction = env.NODE_ENV === \"production\";\n } catch {\n // Fallback when env is unavailable (e.g. tests without DATABASE_URL)\n this._level = \"info\";\n this._isProduction = false;\n }\n }\n\n private get level(): LogLevel {\n this.init();\n return this._level!;\n }\n\n private get isProduction(): boolean {\n this.init();\n return this._isProduction!;\n }\n\n private shouldLog(level: LogLevel): boolean {\n return LOG_LEVELS[level] >= LOG_LEVELS[this.level];\n }\n\n private formatMessage(level: LogLevel, message: string, meta?: Record<string, any>) {\n const timestamp = new Date().toISOString();\n\n if (this.isProduction) {\n // JSON output for production\n return JSON.stringify({\n timestamp,\n level,\n message,\n ...meta,\n });\n }\n\n // Human-readable output for development\n const metaStr = meta ? ` ${JSON.stringify(meta)}` : \"\";\n return `[${timestamp}] ${level.toUpperCase()}: ${message}${metaStr}`;\n }\n\n debug(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"debug\")) {\n console.debug(this.formatMessage(\"debug\", message, meta));\n }\n }\n\n info(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"info\")) {\n console.info(this.formatMessage(\"info\", message, meta));\n }\n }\n\n warn(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"warn\")) {\n console.warn(this.formatMessage(\"warn\", message, meta));\n }\n }\n\n error(message: string, meta?: Record<string, any>) {\n if (this.shouldLog(\"error\")) {\n console.error(this.formatMessage(\"error\", message, meta));\n }\n }\n}\n\n// Export singleton instance\nexport const logger = new Logger();\n"
|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AAM,UAAU,OAAO,IAAI,KAAK,UAAU,IAAI,MAAM;AAAA,IACpD,OAAO,IAAI,cAAc,MAAM,YAAY,MAAM,UAAU;AAAA;AAAA,EAG7D,KAAK,CAAC,SAAiB,MAA4B;AAAA,IACjD,IAAI,KAAK,UAAU,OAAO,GAAG;AAAA,MAC3B,QAAQ,MAAM,KAAK,cAAc,SAAS,SAAS,IAAI,CAAC;AAAA,IAC1D;AAAA;AAAA,EAGF,IAAI,CAAC,SAAiB,MAA4B;AAAA,IAChD,IAAI,KAAK,UAAU,MAAM,GAAG;AAAA,MAC1B,QAAQ,KAAK,KAAK,cAAc,QAAQ,SAAS,IAAI,CAAC;AAAA,IACxD;AAAA;AAAA,EAGF,IAAI,CAAC,SAAiB,MAA4B;AAAA,IAChD,IAAI,KAAK,UAAU,MAAM,GAAG;AAAA,MAC1B,QAAQ,KAAK,KAAK,cAAc,QAAQ,SAAS,IAAI,CAAC;AAAA,IACxD;AAAA;AAAA,EAGF,KAAK,CAAC,SAAiB,MAA4B;AAAA,IACjD,IAAI,KAAK,UAAU,OAAO,GAAG;AAAA,MAC3B,QAAQ,MAAM,KAAK,cAAc,SAAS,SAAS,IAAI,CAAC;AAAA,IAC1D;AAAA;AAEJ;AAGO,IAAM,SAAS,IAAI;",
|
|
9
|
+
"debugId": "C3A89D3B91522A5964756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface NodeInfo {
|
|
2
|
+
peer_version: number;
|
|
3
|
+
pox_consensus: string;
|
|
4
|
+
burn_block_height: number;
|
|
5
|
+
stable_pox_consensus: string;
|
|
6
|
+
stable_burn_block_height: number;
|
|
7
|
+
server_version: string;
|
|
8
|
+
network_id: number;
|
|
9
|
+
parent_network_id: number;
|
|
10
|
+
stacks_tip_height: number;
|
|
11
|
+
stacks_tip: string;
|
|
12
|
+
stacks_tip_consensus_hash: string;
|
|
13
|
+
genesis_chainstate_hash: string;
|
|
14
|
+
}
|
|
15
|
+
interface BlockResponse {
|
|
16
|
+
hash: string;
|
|
17
|
+
height: number;
|
|
18
|
+
parent_block_hash: string;
|
|
19
|
+
burn_block_height: number;
|
|
20
|
+
burn_block_hash: string;
|
|
21
|
+
burn_block_time: number;
|
|
22
|
+
index_block_hash: string;
|
|
23
|
+
parent_index_block_hash: string;
|
|
24
|
+
miner_txid: string;
|
|
25
|
+
txs: string[];
|
|
26
|
+
}
|
|
27
|
+
declare class StacksNodeClient {
|
|
28
|
+
private rpcUrl;
|
|
29
|
+
constructor(rpcUrl?: string);
|
|
30
|
+
getInfo(): Promise<NodeInfo>;
|
|
31
|
+
getBlock(height: number): Promise<BlockResponse | null>;
|
|
32
|
+
isHealthy(): Promise<boolean>;
|
|
33
|
+
getRpcUrl(): string;
|
|
34
|
+
}
|
|
35
|
+
export { StacksNodeClient, NodeInfo, BlockResponse };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/node/client.ts
|
|
14
|
+
class StacksNodeClient {
|
|
15
|
+
rpcUrl;
|
|
16
|
+
constructor(rpcUrl) {
|
|
17
|
+
this.rpcUrl = rpcUrl || process.env.STACKS_NODE_RPC_URL || "http://localhost:20443";
|
|
18
|
+
}
|
|
19
|
+
async getInfo() {
|
|
20
|
+
const res = await fetch(`${this.rpcUrl}/v2/info`, {
|
|
21
|
+
signal: AbortSignal.timeout(1e4)
|
|
22
|
+
});
|
|
23
|
+
if (!res.ok) {
|
|
24
|
+
throw new Error(`Node RPC /v2/info returned ${res.status}`);
|
|
25
|
+
}
|
|
26
|
+
return res.json();
|
|
27
|
+
}
|
|
28
|
+
async getBlock(height) {
|
|
29
|
+
const res = await fetch(`${this.rpcUrl}/v2/blocks/${height}`, {
|
|
30
|
+
signal: AbortSignal.timeout(30000)
|
|
31
|
+
});
|
|
32
|
+
if (res.status === 404)
|
|
33
|
+
return null;
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
throw new Error(`Node RPC /v2/blocks/${height} returned ${res.status}`);
|
|
36
|
+
}
|
|
37
|
+
return res.json();
|
|
38
|
+
}
|
|
39
|
+
async isHealthy() {
|
|
40
|
+
try {
|
|
41
|
+
const info = await this.getInfo();
|
|
42
|
+
return info.stacks_tip_height > 0;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
getRpcUrl() {
|
|
48
|
+
return this.rpcUrl;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
StacksNodeClient
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//# debugId=7275B22E4C7CC11864756E2164756E21
|
|
56
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/node/client.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"\nexport interface NodeInfo {\n peer_version: number;\n pox_consensus: string;\n burn_block_height: number;\n stable_pox_consensus: string;\n stable_burn_block_height: number;\n server_version: string;\n network_id: number;\n parent_network_id: number;\n stacks_tip_height: number;\n stacks_tip: string;\n stacks_tip_consensus_hash: string;\n genesis_chainstate_hash: string;\n}\n\nexport interface BlockResponse {\n hash: string;\n height: number;\n parent_block_hash: string;\n burn_block_height: number;\n burn_block_hash: string;\n burn_block_time: number;\n index_block_hash: string;\n parent_index_block_hash: string;\n miner_txid: string;\n txs: string[];\n // Full block data varies by endpoint — kept minimal for fetch use case\n}\n\nexport class StacksNodeClient {\n private rpcUrl: string;\n\n constructor(rpcUrl?: string) {\n this.rpcUrl = rpcUrl || process.env.STACKS_NODE_RPC_URL || \"http://localhost:20443\";\n }\n\n async getInfo(): Promise<NodeInfo> {\n const res = await fetch(`${this.rpcUrl}/v2/info`, {\n signal: AbortSignal.timeout(10_000),\n });\n if (!res.ok) {\n throw new Error(`Node RPC /v2/info returned ${res.status}`);\n }\n return res.json() as Promise<NodeInfo>;\n }\n\n async getBlock(height: number): Promise<BlockResponse | null> {\n // Stacks API v2 block-by-height endpoint\n const res = await fetch(`${this.rpcUrl}/v2/blocks/${height}`, {\n signal: AbortSignal.timeout(30_000),\n });\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Node RPC /v2/blocks/${height} returned ${res.status}`);\n }\n return res.json() as Promise<BlockResponse>;\n }\n\n async isHealthy(): Promise<boolean> {\n try {\n const info = await this.getInfo();\n return info.stacks_tip_height > 0;\n } catch {\n return false;\n }\n }\n\n getRpcUrl(): string {\n return this.rpcUrl;\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;AA8BO,MAAM,iBAAiB;AAAA,EACpB;AAAA,EAER,WAAW,CAAC,QAAiB;AAAA,IAC3B,KAAK,SAAS,UAAU,QAAQ,IAAI,uBAAuB;AAAA;AAAA,OAGvD,QAAO,GAAsB;AAAA,IACjC,MAAM,MAAM,MAAM,MAAM,GAAG,KAAK,kBAAkB;AAAA,MAChD,QAAQ,YAAY,QAAQ,GAAM;AAAA,IACpC,CAAC;AAAA,IACD,IAAI,CAAC,IAAI,IAAI;AAAA,MACX,MAAM,IAAI,MAAM,8BAA8B,IAAI,QAAQ;AAAA,IAC5D;AAAA,IACA,OAAO,IAAI,KAAK;AAAA;AAAA,OAGZ,SAAQ,CAAC,QAA+C;AAAA,IAE5D,MAAM,MAAM,MAAM,MAAM,GAAG,KAAK,oBAAoB,UAAU;AAAA,MAC5D,QAAQ,YAAY,QAAQ,KAAM;AAAA,IACpC,CAAC;AAAA,IACD,IAAI,IAAI,WAAW;AAAA,MAAK,OAAO;AAAA,IAC/B,IAAI,CAAC,IAAI,IAAI;AAAA,MACX,MAAM,IAAI,MAAM,uBAAuB,mBAAmB,IAAI,QAAQ;AAAA,IACxE;AAAA,IACA,OAAO,IAAI,KAAK;AAAA;AAAA,OAGZ,UAAS,GAAqB;AAAA,IAClC,IAAI;AAAA,MACF,MAAM,OAAO,MAAM,KAAK,QAAQ;AAAA,MAChC,OAAO,KAAK,oBAAoB;AAAA,MAChC,MAAM;AAAA,MACN,OAAO;AAAA;AAAA;AAAA,EAIX,SAAS,GAAW;AAAA,IAClB,OAAO,KAAK;AAAA;AAEhB;",
|
|
8
|
+
"debugId": "7275B22E4C7CC11864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/** v2 /extended/v2/blocks/{height} response */
|
|
2
|
+
interface HiroBlockResponse {
|
|
3
|
+
canonical: boolean;
|
|
4
|
+
height: number;
|
|
5
|
+
hash: string;
|
|
6
|
+
block_time: number;
|
|
7
|
+
block_time_iso: string;
|
|
8
|
+
index_block_hash: string;
|
|
9
|
+
parent_block_hash: string;
|
|
10
|
+
parent_index_block_hash: string;
|
|
11
|
+
burn_block_hash: string;
|
|
12
|
+
burn_block_height: number;
|
|
13
|
+
burn_block_time: number;
|
|
14
|
+
miner_txid: string;
|
|
15
|
+
tx_count: number;
|
|
16
|
+
}
|
|
17
|
+
/** v2 /extended/v2/blocks/{height}/transactions response */
|
|
18
|
+
interface HiroBlockTxsResponse {
|
|
19
|
+
limit: number;
|
|
20
|
+
offset: number;
|
|
21
|
+
total: number;
|
|
22
|
+
results: HiroTxResponse[];
|
|
23
|
+
}
|
|
24
|
+
interface HiroTxResponse {
|
|
25
|
+
tx_id: string;
|
|
26
|
+
tx_type: string;
|
|
27
|
+
tx_status: string;
|
|
28
|
+
sender_address: string;
|
|
29
|
+
fee_rate: string;
|
|
30
|
+
nonce: number;
|
|
31
|
+
block_hash: string;
|
|
32
|
+
block_height: number;
|
|
33
|
+
burn_block_height: number;
|
|
34
|
+
tx_index: number;
|
|
35
|
+
event_count: number;
|
|
36
|
+
token_transfer?: {
|
|
37
|
+
recipient_address: string
|
|
38
|
+
amount: string
|
|
39
|
+
memo: string
|
|
40
|
+
};
|
|
41
|
+
contract_call?: {
|
|
42
|
+
contract_id: string
|
|
43
|
+
function_name: string
|
|
44
|
+
function_args: unknown[]
|
|
45
|
+
};
|
|
46
|
+
smart_contract?: {
|
|
47
|
+
contract_id: string
|
|
48
|
+
source_code: string
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface HiroEvent {
|
|
52
|
+
event_index: number;
|
|
53
|
+
event_type: string;
|
|
54
|
+
tx_id: string;
|
|
55
|
+
asset?: {
|
|
56
|
+
asset_event_type: string
|
|
57
|
+
sender?: string
|
|
58
|
+
recipient?: string
|
|
59
|
+
amount?: string
|
|
60
|
+
memo?: string
|
|
61
|
+
asset_id?: string
|
|
62
|
+
value?: unknown
|
|
63
|
+
};
|
|
64
|
+
contract_log?: {
|
|
65
|
+
contract_id: string
|
|
66
|
+
topic: string
|
|
67
|
+
value: unknown
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface HiroEventsResponse {
|
|
71
|
+
limit: number;
|
|
72
|
+
offset: number;
|
|
73
|
+
events: HiroEvent[];
|
|
74
|
+
}
|
|
75
|
+
/** Shape our indexer expects at POST /new_block */
|
|
76
|
+
interface NewBlockPayload {
|
|
77
|
+
block_hash: string;
|
|
78
|
+
block_height: number;
|
|
79
|
+
index_block_hash: string;
|
|
80
|
+
parent_block_hash: string;
|
|
81
|
+
parent_index_block_hash: string;
|
|
82
|
+
burn_block_hash: string;
|
|
83
|
+
burn_block_height: number;
|
|
84
|
+
burn_block_timestamp: number;
|
|
85
|
+
miner_txid: string;
|
|
86
|
+
timestamp: number;
|
|
87
|
+
transactions: TransactionPayload[];
|
|
88
|
+
events: TransactionEventPayload[];
|
|
89
|
+
}
|
|
90
|
+
interface TransactionPayload {
|
|
91
|
+
txid: string;
|
|
92
|
+
raw_tx: string;
|
|
93
|
+
status: string;
|
|
94
|
+
tx_index: number;
|
|
95
|
+
tx_type?: string;
|
|
96
|
+
sender_address?: string;
|
|
97
|
+
}
|
|
98
|
+
interface TransactionEventPayload {
|
|
99
|
+
txid: string;
|
|
100
|
+
event_index: number;
|
|
101
|
+
committed: boolean;
|
|
102
|
+
type: string;
|
|
103
|
+
stx_transfer_event?: {
|
|
104
|
+
sender: string
|
|
105
|
+
recipient: string
|
|
106
|
+
amount: string
|
|
107
|
+
memo?: string
|
|
108
|
+
};
|
|
109
|
+
stx_mint_event?: {
|
|
110
|
+
recipient: string
|
|
111
|
+
amount: string
|
|
112
|
+
};
|
|
113
|
+
stx_burn_event?: {
|
|
114
|
+
sender: string
|
|
115
|
+
amount: string
|
|
116
|
+
};
|
|
117
|
+
stx_lock_event?: {
|
|
118
|
+
locked_amount: string
|
|
119
|
+
unlock_height: string
|
|
120
|
+
locked_address: string
|
|
121
|
+
};
|
|
122
|
+
ft_transfer_event?: {
|
|
123
|
+
asset_identifier: string
|
|
124
|
+
sender: string
|
|
125
|
+
recipient: string
|
|
126
|
+
amount: string
|
|
127
|
+
};
|
|
128
|
+
ft_mint_event?: {
|
|
129
|
+
asset_identifier: string
|
|
130
|
+
recipient: string
|
|
131
|
+
amount: string
|
|
132
|
+
};
|
|
133
|
+
ft_burn_event?: {
|
|
134
|
+
asset_identifier: string
|
|
135
|
+
sender: string
|
|
136
|
+
amount: string
|
|
137
|
+
};
|
|
138
|
+
nft_transfer_event?: {
|
|
139
|
+
asset_identifier: string
|
|
140
|
+
sender: string
|
|
141
|
+
recipient: string
|
|
142
|
+
value: unknown
|
|
143
|
+
};
|
|
144
|
+
nft_mint_event?: {
|
|
145
|
+
asset_identifier: string
|
|
146
|
+
recipient: string
|
|
147
|
+
value: unknown
|
|
148
|
+
};
|
|
149
|
+
nft_burn_event?: {
|
|
150
|
+
asset_identifier: string
|
|
151
|
+
sender: string
|
|
152
|
+
value: unknown
|
|
153
|
+
};
|
|
154
|
+
smart_contract_event?: {
|
|
155
|
+
contract_identifier: string
|
|
156
|
+
topic: string
|
|
157
|
+
value: unknown
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
declare class HiroClient {
|
|
161
|
+
private apiUrl;
|
|
162
|
+
private apiKey;
|
|
163
|
+
private maxRetries;
|
|
164
|
+
constructor(apiUrl?: string, maxRetries?: number);
|
|
165
|
+
private get headers();
|
|
166
|
+
/** Fetch with retry on 429/5xx using exponential backoff */
|
|
167
|
+
private fetchWithRetry;
|
|
168
|
+
/**
|
|
169
|
+
* Fetch a complete block by height, including all transactions and events,
|
|
170
|
+
* transformed into the NewBlockPayload format our indexer expects.
|
|
171
|
+
*
|
|
172
|
+
* Uses 3-step approach:
|
|
173
|
+
* 1. GET /extended/v2/blocks/{height} — block metadata
|
|
174
|
+
* 2. GET /extended/v2/blocks/{height}/transactions — all txs (paginated)
|
|
175
|
+
* 3. GET /extended/v1/tx/events?tx_id={txId} — events per tx (only for txs with events)
|
|
176
|
+
*/
|
|
177
|
+
getBlockForIndexer(height: number): Promise<NewBlockPayload | null>;
|
|
178
|
+
/** v2 block metadata */
|
|
179
|
+
private fetchBlock;
|
|
180
|
+
/** v2 block transactions (paginated) */
|
|
181
|
+
private fetchBlockTransactions;
|
|
182
|
+
private fetchAllEvents;
|
|
183
|
+
isHealthy(): Promise<boolean>;
|
|
184
|
+
getApiUrl(): string;
|
|
185
|
+
}
|
|
186
|
+
export { NewBlockPayload, HiroTxResponse, HiroEventsResponse, HiroEvent, HiroClient, HiroBlockTxsResponse, HiroBlockResponse };
|