@secondlayer/shared 15.2.1 → 15.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/archive/range-digest.d.ts +67 -9
- package/dist/src/archive/semantic-digest-builder.d.ts +67 -9
- package/dist/src/coverage/index.d.ts +70 -9
- package/dist/src/coverage/index.js.map +2 -2
- package/dist/src/db/index.d.ts +69 -10
- package/dist/src/db/index.js +19 -1
- package/dist/src/db/index.js.map +5 -4
- package/dist/src/db/queries/chain-reorgs.d.ts +67 -9
- package/dist/src/db/queries/chain-reorgs.js +17 -1
- package/dist/src/db/queries/chain-reorgs.js.map +5 -4
- package/dist/src/db/queries/contracts.d.ts +114 -28
- package/dist/src/db/queries/contracts.js +115 -15
- package/dist/src/db/queries/contracts.js.map +7 -5
- package/dist/src/db/queries/instance.d.ts +75 -10
- package/dist/src/db/queries/instance.js +147 -3
- package/dist/src/db/queries/instance.js.map +6 -4
- package/dist/src/db/queries/integrity.d.ts +83 -10
- package/dist/src/db/queries/integrity.js +236 -2
- package/dist/src/db/queries/integrity.js.map +7 -4
- package/dist/src/db/queries/subgraph-gaps.d.ts +75 -12
- package/dist/src/db/queries/subgraph-gaps.js +7 -3
- package/dist/src/db/queries/subgraph-gaps.js.map +3 -3
- package/dist/src/db/queries/subgraph-operations.d.ts +67 -9
- package/dist/src/db/queries/subgraphs.d.ts +128 -42
- package/dist/src/db/queries/subgraphs.js +85 -27
- package/dist/src/db/queries/subgraphs.js.map +7 -6
- package/dist/src/db/queries/sync-scope.d.ts +67 -9
- package/dist/src/db/queries/webhook-replays.d.ts +79 -13
- package/dist/src/db/queries/webhook-replays.js +468 -19
- package/dist/src/db/queries/webhook-replays.js.map +9 -4
- package/dist/src/db/queries/webhooks.d.ts +102 -21
- package/dist/src/db/queries/webhooks.js +72 -17
- package/dist/src/db/queries/webhooks.js.map +6 -5
- package/dist/src/db/schema.d.ts +68 -10
- package/dist/src/db/schema.js +20 -1
- package/dist/src/db/schema.js.map +4 -3
- package/dist/src/db/transition.d.ts +46 -0
- package/dist/src/db/transition.js +38 -0
- package/dist/src/db/transition.js.map +10 -0
- package/dist/src/email/index.d.ts +16 -1
- package/dist/src/email/index.js +186 -130
- package/dist/src/email/index.js.map +5 -4
- package/dist/src/errors.d.ts +7 -1
- package/dist/src/errors.js +12 -1
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index-http.d.ts +13 -3
- package/dist/src/index-http.js +3 -3
- package/dist/src/index-http.js.map +3 -3
- package/dist/src/index.d.ts +109 -20
- package/dist/src/index.js +41 -8
- package/dist/src/index.js.map +8 -7
- package/dist/src/insights/index.d.ts +68 -9
- package/dist/src/insights/index.js +55 -5
- package/dist/src/insights/index.js.map +7 -6
- package/dist/src/node/local-client.d.ts +67 -9
- package/dist/src/queue/listener.js +17 -1
- package/dist/src/queue/listener.js.map +5 -4
- package/dist/src/runtime/index.d.ts +0 -4
- package/dist/src/runtime/index.js +54 -4
- package/dist/src/runtime/index.js.map +6 -5
- package/dist/src/schemas/index.d.ts +36 -10
- package/dist/src/schemas/index.js +12 -8
- package/dist/src/schemas/index.js.map +4 -4
- package/dist/src/schemas/subgraphs.d.ts +22 -9
- package/dist/src/schemas/subgraphs.js +10 -6
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/dist/src/schemas/webhooks.d.ts +15 -2
- package/dist/src/schemas/webhooks.js +2 -2
- package/dist/src/schemas/webhooks.js.map +3 -3
- package/dist/src/subgraphs/spec.d.ts +5 -1
- package/dist/src/webhooks/health.d.ts +27 -0
- package/dist/src/webhooks/health.js +84 -0
- package/dist/src/webhooks/health.js.map +11 -0
- package/migrations/0184_status_checks.ts +92 -0
- package/migrations/0185_reorg_generation_settlement_seq.ts +89 -0
- package/migrations/0186_api_keys_one_active_tenant_per_name.ts +43 -0
- package/migrations/0187_accounts_email_lower_unique.ts +27 -0
- package/migrations/0188_webhook_reasons.ts +124 -0
- package/migrations/0189_subgraph_lifecycle.ts +83 -0
- package/migrations/0190_usage_ledger_debited_usd_micros.ts +59 -0
- package/migrations/0191_indexer_state_machines.ts +83 -0
- package/migrations/0192_hosted_stack_state.ts +37 -0
- package/migrations/0193_accounts_ghost_has_no_email.ts +34 -0
- package/migrations/0194_webhook_outbox_block_hash.ts +46 -0
- package/package.json +9 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -87,13 +87,21 @@ interface DeploySubgraphResponse {
|
|
|
87
87
|
breakingChanges: string[]
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
/**
|
|
91
|
-
* `
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
/** Every state `subgraphs.status` can hold; mirrored by the
|
|
91
|
+
* `subgraphs_status_check` CHECK (migration 0189). */
|
|
92
|
+
declare const SUBGRAPH_STATES: readonly ["active", "reindexing", "error"];
|
|
93
|
+
type SubgraphStatus = (typeof SUBGRAPH_STATES)[number];
|
|
94
|
+
/** What an operator sees: `synced` and `catching_up` are both `active` rows. */
|
|
95
|
+
type SubgraphSyncState = "synced" | "catching_up" | "reindexing" | "error";
|
|
96
|
+
/**
|
|
97
|
+
* The one answer to "is this subgraph caught up?". `tip` is the chain tip the
|
|
98
|
+
* subgraph is measured against (its reindex target while reindexing is the
|
|
99
|
+
* caller's concern: a reindexing subgraph is `reindexing` whatever its cursor).
|
|
100
|
+
*/
|
|
101
|
+
declare function syncState(subgraph: {
|
|
102
|
+
status: string
|
|
103
|
+
lastProcessedBlock: number | string
|
|
104
|
+
}, tip: number): SubgraphSyncState;
|
|
97
105
|
/** A subgraph's name, status, and indexing progress. */
|
|
98
106
|
interface SubgraphSummary {
|
|
99
107
|
name: string;
|
|
@@ -116,6 +124,9 @@ interface SubgraphSummary {
|
|
|
116
124
|
/** Most recent indexing error reason + when it occurred, if any. */
|
|
117
125
|
lastError?: string | null;
|
|
118
126
|
lastErrorAt?: string | null;
|
|
127
|
+
/** Billing code (`spend_cap_reached`, `insufficient_credits`) while reads
|
|
128
|
+
* are refused for the account; null otherwise. */
|
|
129
|
+
billingPausedCode?: string | null;
|
|
119
130
|
/** Last row mutation timestamp; powers per-card freshness. */
|
|
120
131
|
updatedAt?: string | null;
|
|
121
132
|
createdAt: string;
|
|
@@ -127,7 +138,7 @@ interface SubgraphGapRange {
|
|
|
127
138
|
reason: string;
|
|
128
139
|
}
|
|
129
140
|
interface SubgraphSyncInfo {
|
|
130
|
-
status:
|
|
141
|
+
status: SubgraphSyncState;
|
|
131
142
|
mode?: "sync" | "reindex";
|
|
132
143
|
startBlock: number;
|
|
133
144
|
lastProcessedBlock: number;
|
|
@@ -183,6 +194,8 @@ interface SubgraphDetail {
|
|
|
183
194
|
errorRate: number
|
|
184
195
|
lastError: string | null
|
|
185
196
|
lastErrorAt: string | null
|
|
197
|
+
/** Billing code while the account's reads are refused; null otherwise. */
|
|
198
|
+
billingPausedCode?: string | null
|
|
186
199
|
/** True after the processor matched work but user tables still have 0 rows. */
|
|
187
200
|
emptyMapping: boolean
|
|
188
201
|
};
|
|
@@ -264,6 +277,9 @@ interface SubgraphAggregateResponse {
|
|
|
264
277
|
min?: Record<string, string | null>;
|
|
265
278
|
max?: Record<string, string | null>;
|
|
266
279
|
}
|
|
280
|
+
/** Why a webhook is paused: the customer did it, or the circuit breaker did. */
|
|
281
|
+
type WebhookPauseReason = "user" | "circuit";
|
|
282
|
+
type WebhookHealth = "ok" | "failing" | "down" | "paused_user" | "paused_circuit";
|
|
267
283
|
interface BlocksTable {
|
|
268
284
|
height: number;
|
|
269
285
|
hash: string;
|
|
@@ -403,7 +419,7 @@ interface SubgraphsTable {
|
|
|
403
419
|
id: Generated<string>;
|
|
404
420
|
name: string;
|
|
405
421
|
version: Generated<string>;
|
|
406
|
-
status: Generated<
|
|
422
|
+
status: Generated<SubgraphStatus>;
|
|
407
423
|
definition: Record<string, unknown>;
|
|
408
424
|
schema_hash: string;
|
|
409
425
|
handler_path: string;
|
|
@@ -420,8 +436,10 @@ interface SubgraphsTable {
|
|
|
420
436
|
handler_code: string | null;
|
|
421
437
|
source_code: string | null;
|
|
422
438
|
project_id: string | null;
|
|
423
|
-
/**
|
|
424
|
-
|
|
439
|
+
/** Set while the account's metered reads are refused (spend cap, credits).
|
|
440
|
+
* Both columns are set or both null; `last_error` stays for real errors. */
|
|
441
|
+
billing_paused_at: Date | null;
|
|
442
|
+
billing_paused_code: string | null;
|
|
425
443
|
/** (event type, contract) probe pairs persisted at deploy for weight classification. */
|
|
426
444
|
sparse_probe_targets: unknown | null;
|
|
427
445
|
/** sha256 over everything that shapes rows (schema, handler bundle,
|
|
@@ -435,6 +453,9 @@ interface SubgraphsTable {
|
|
|
435
453
|
created_at: Generated<Date>;
|
|
436
454
|
updated_at: Generated<Date>;
|
|
437
455
|
}
|
|
456
|
+
/** Mirrored by the CHECK on `contracts.abi_status`. */
|
|
457
|
+
declare const ABI_STATUSES: readonly ["pending", "fetched", "unparseable", "failed"];
|
|
458
|
+
type AbiStatus = (typeof ABI_STATUSES)[number];
|
|
438
459
|
interface ContractsTable {
|
|
439
460
|
contract_id: string;
|
|
440
461
|
deployer: string;
|
|
@@ -443,17 +464,23 @@ interface ContractsTable {
|
|
|
443
464
|
abi: unknown | null;
|
|
444
465
|
declared_traits: Generated<string[]>;
|
|
445
466
|
inferred_standards: Generated<string[]>;
|
|
446
|
-
abi_status: Generated<
|
|
467
|
+
abi_status: Generated<AbiStatus>;
|
|
447
468
|
abi_fetched_at: Date | null;
|
|
469
|
+
/** Failed fetches so far; `failed` re-polls until the registry's attempt cap. */
|
|
470
|
+
abi_attempts: Generated<number>;
|
|
471
|
+
/** When a `failed` row is next due; NULL once attempts are exhausted. */
|
|
472
|
+
abi_next_attempt_at: Date | null;
|
|
448
473
|
created_at: Generated<Date>;
|
|
449
474
|
}
|
|
475
|
+
/** The only reasons the runtime records; mirrored by a CHECK on `subgraph_gaps.reason`. */
|
|
476
|
+
type GapReason = "block_missing" | "processing_error";
|
|
450
477
|
interface SubgraphGapsTable {
|
|
451
478
|
id: Generated<string>;
|
|
452
479
|
subgraph_id: string;
|
|
453
480
|
subgraph_name: string;
|
|
454
481
|
gap_start: number;
|
|
455
482
|
gap_end: number;
|
|
456
|
-
reason:
|
|
483
|
+
reason: GapReason;
|
|
457
484
|
detected_at: Generated<Date>;
|
|
458
485
|
resolved_at: Date | null;
|
|
459
486
|
}
|
|
@@ -499,12 +526,13 @@ interface SubgraphOperationsTable {
|
|
|
499
526
|
* (those checkpoint on subgraphs.last_processed_block). */
|
|
500
527
|
cursor_block: string | number | bigint | null;
|
|
501
528
|
}
|
|
529
|
+
type ApiKeyStatus = "active" | "revoked";
|
|
502
530
|
interface ApiKeysTable {
|
|
503
531
|
id: Generated<string>;
|
|
504
532
|
key_hash: string;
|
|
505
533
|
key_prefix: string;
|
|
506
534
|
name: string | null;
|
|
507
|
-
status: Generated<
|
|
535
|
+
status: Generated<ApiKeyStatus>;
|
|
508
536
|
rate_limit: Generated<number>;
|
|
509
537
|
ip_address: string;
|
|
510
538
|
account_id: string;
|
|
@@ -865,6 +893,10 @@ interface SbtcSettlementsTable {
|
|
|
865
893
|
last_checked_at: Generated<Date>;
|
|
866
894
|
/** Set once, when `settlement_confirmed` first flips true. */
|
|
867
895
|
confirmed_at: Date | null;
|
|
896
|
+
/** Monotonic stamp from `sbtc_settlements_seq`, retaken each time the sweep
|
|
897
|
+
* becomes confirmed. The webhook scan's watermark. BIGINT: a string at
|
|
898
|
+
* runtime. */
|
|
899
|
+
seq: Generated<number | string>;
|
|
868
900
|
updated_at: Generated<Date>;
|
|
869
901
|
}
|
|
870
902
|
type BnsNameEventTopic = "new-name" | "transfer-name" | "renew-name" | "burn-name" | "new-airdrop";
|
|
@@ -984,7 +1016,9 @@ interface PendingForkBlocksTable {
|
|
|
984
1016
|
payload: ColumnType<unknown, unknown, unknown>;
|
|
985
1017
|
received_at: Generated<Date>;
|
|
986
1018
|
}
|
|
987
|
-
|
|
1019
|
+
/** Mirrored by the CHECK on `observer_journal.status`. */
|
|
1020
|
+
declare const OBSERVER_JOURNAL_STATUSES: readonly ["received", "processed", "failed", "retried", "poisoned", "skipped"];
|
|
1021
|
+
type ObserverJournalStatus = (typeof OBSERVER_JOURNAL_STATUSES)[number];
|
|
988
1022
|
/**
|
|
989
1023
|
* Exact observer callback receipt. `raw_body` is immutable evidence; the
|
|
990
1024
|
* processing columns are updated only after the current derived-state write
|
|
@@ -1019,7 +1053,7 @@ interface StageRegistryTable {
|
|
|
1019
1053
|
enabled: Generated<boolean>;
|
|
1020
1054
|
created_at: Generated<Date>;
|
|
1021
1055
|
}
|
|
1022
|
-
/** One versioned sweep of a stage. */
|
|
1056
|
+
/** One versioned sweep of a stage. Nothing writes this table yet; kept because the receipts and failures tables reference it. */
|
|
1023
1057
|
interface StageRunsTable {
|
|
1024
1058
|
id: Generated<string>;
|
|
1025
1059
|
stage_id: string;
|
|
@@ -1153,6 +1187,7 @@ interface Database {
|
|
|
1153
1187
|
archive_fetches: ArchiveFetchesTable;
|
|
1154
1188
|
usage_ledger: UsageLedgerTable;
|
|
1155
1189
|
account_balance_alerts: AccountBalanceAlertsTable;
|
|
1190
|
+
hosted_stack_state: HostedStackStateTable;
|
|
1156
1191
|
webhook_incident_alerts: WebhookIncidentAlertsTable;
|
|
1157
1192
|
cli_device_logins: CliDeviceLoginsTable;
|
|
1158
1193
|
oauth_clients: OauthClientsTable;
|
|
@@ -1245,7 +1280,11 @@ interface UsageLedgerTable {
|
|
|
1245
1280
|
* floor to observe past. */
|
|
1246
1281
|
observed_quantity: string | number | null;
|
|
1247
1282
|
usd_micros: string | number | bigint;
|
|
1283
|
+
/** True when the whole price was taken; derived from `debited_usd_micros`. */
|
|
1248
1284
|
debited: Generated<boolean>;
|
|
1285
|
+
/** Amount actually taken from the balance, `0..usd_micros` (bounded the
|
|
1286
|
+
* other way for a negative top-up/grant row). Unpaid = price - this. */
|
|
1287
|
+
debited_usd_micros: Generated<string | number | bigint>;
|
|
1249
1288
|
source: string;
|
|
1250
1289
|
/** API key behind a metered read; null for non-read units and older rows. */
|
|
1251
1290
|
api_key_id: string | null;
|
|
@@ -1266,6 +1305,14 @@ interface AccountBalanceAlertsTable {
|
|
|
1266
1305
|
sent_2d_at: Date | null;
|
|
1267
1306
|
sent_stopped_at: Date | null;
|
|
1268
1307
|
}
|
|
1308
|
+
/** The workload host's report of one account's hosted stack. Written only by
|
|
1309
|
+
* `POST /internal/stack-state`; `reported_at` is the host's observation time. */
|
|
1310
|
+
interface HostedStackStateTable {
|
|
1311
|
+
account_id: string;
|
|
1312
|
+
state: "provisioning" | "running" | "stopped" | "destroyed";
|
|
1313
|
+
stop_reason: "credits" | "cap" | "idle" | null;
|
|
1314
|
+
reported_at: Date;
|
|
1315
|
+
}
|
|
1269
1316
|
/** Debounce state for the webhook-down email: one row per incident, open
|
|
1270
1317
|
* while `resolved_at` is null. No preference columns by design. */
|
|
1271
1318
|
interface WebhookIncidentAlertsTable {
|
|
@@ -1453,7 +1500,7 @@ type SubgraphHealthSnapshot = Selectable<SubgraphHealthSnapshotsTable>;
|
|
|
1453
1500
|
type InsertSubgraphHealthSnapshot = Insertable<SubgraphHealthSnapshotsTable>;
|
|
1454
1501
|
type SubgraphGap = Selectable<SubgraphGapsTable>;
|
|
1455
1502
|
type InsertSubgraphGap = Insertable<SubgraphGapsTable>;
|
|
1456
|
-
type WebhookStatus = "active" | "paused"
|
|
1503
|
+
type WebhookStatus = "active" | "paused";
|
|
1457
1504
|
/** Webhooks react to raw chain events matched directly off the Index/Streams
|
|
1458
1505
|
* clock. `chain` is the only kind since migration 0159 removed subgraph-row
|
|
1459
1506
|
* webhooks; the column stays as the discriminator. */
|
|
@@ -1479,6 +1526,8 @@ interface WebhooksTable {
|
|
|
1479
1526
|
concurrency: Generated<number>;
|
|
1480
1527
|
circuit_failures: Generated<number>;
|
|
1481
1528
|
circuit_opened_at: Date | null;
|
|
1529
|
+
/** Why a paused webhook is paused. Set exactly while `status` is `paused`. */
|
|
1530
|
+
pause_reason: WebhookPauseReason | null;
|
|
1482
1531
|
last_delivery_at: Date | null;
|
|
1483
1532
|
last_success_at: Date | null;
|
|
1484
1533
|
last_error: string | null;
|
|
@@ -1492,6 +1541,10 @@ type Webhook = Selectable<WebhooksTable>;
|
|
|
1492
1541
|
type InsertWebhook = Insertable<WebhooksTable>;
|
|
1493
1542
|
type UpdateWebhook = Updateable<WebhooksTable>;
|
|
1494
1543
|
type OutboxStatus = "pending" | "delivered" | "dead";
|
|
1544
|
+
/** Why a row is dead: retries ran out, or a reorg removed its event. An
|
|
1545
|
+
* orphaned row stays dead; requeueing it would resend an event the chain no
|
|
1546
|
+
* longer contains. */
|
|
1547
|
+
type DeadReason = "exhausted" | "orphaned";
|
|
1495
1548
|
interface WebhookOutboxTable {
|
|
1496
1549
|
id: Generated<string>;
|
|
1497
1550
|
webhook_id: string;
|
|
@@ -1521,6 +1574,14 @@ interface WebhookOutboxTable {
|
|
|
1521
1574
|
* into an orphaned fork. Null otherwise — delivery failures track their
|
|
1522
1575
|
* history on `webhooks.last_error`, not per-row. */
|
|
1523
1576
|
last_error: string | null;
|
|
1577
|
+
/** Set exactly while `status` is `dead`. */
|
|
1578
|
+
dead_reason: DeadReason | null;
|
|
1579
|
+
/** Hash of the block a chain apply row was emitted for. Null on rows
|
|
1580
|
+
* written before the column existed (the payload carries it too). */
|
|
1581
|
+
block_hash: string | null;
|
|
1582
|
+
/** Set when a reorg rollback recalled this delivered apply row, so a
|
|
1583
|
+
* later rollback for the same reorg skips it. */
|
|
1584
|
+
rolled_back_at: Date | null;
|
|
1524
1585
|
created_at: Generated<Date>;
|
|
1525
1586
|
}
|
|
1526
1587
|
type WebhookReplayStatus = "scanning" | "running" | "done" | "failed";
|
|
@@ -1580,6 +1641,13 @@ interface TriggerEvaluatorStateTable {
|
|
|
1580
1641
|
/** Watermark for the async sBTC settlement-confirmed webhook scan; null until
|
|
1581
1642
|
* the evaluator fast-forwards it on first run. */
|
|
1582
1643
|
last_settlement_scan_at: ColumnType<Date | null, Date | null | undefined, Date | null>;
|
|
1644
|
+
/** `sbtc_settlements.seq` watermark. Null until the first settlement row is
|
|
1645
|
+
* scanned; `last_settlement_scan_at` is the forward-only floor until then. */
|
|
1646
|
+
last_settlement_scan_seq: ColumnType<bigint | null, bigint | number | null | undefined, bigint | number | null>;
|
|
1647
|
+
/** Counts reorg rewinds. The evaluator checks it under the row lock in the
|
|
1648
|
+
* transaction that emits a batch and advances the cursor, so a reorg that
|
|
1649
|
+
* lands mid-tick rolls the batch back. */
|
|
1650
|
+
reorg_generation: ColumnType<bigint, bigint | number | undefined, bigint | number>;
|
|
1583
1651
|
/** Streams cursor (`<block_height>:<event_index>`) for the Bitcoin (Runes)
|
|
1584
1652
|
* chain-trigger evaluator (plan 060) — a separate clock from
|
|
1585
1653
|
* `last_processed_block` (Stacks). Null until the evaluator fast-forwards
|
|
@@ -2762,6 +2830,7 @@ declare const TABLE_TO_DB: {
|
|
|
2762
2830
|
archive_fetches: string
|
|
2763
2831
|
usage_ledger: string
|
|
2764
2832
|
account_balance_alerts: string
|
|
2833
|
+
hosted_stack_state: string
|
|
2765
2834
|
webhook_incident_alerts: string
|
|
2766
2835
|
sentinel_accounts: string
|
|
2767
2836
|
waitlists: string
|
|
@@ -2881,6 +2950,7 @@ declare const ErrorCodes: {
|
|
|
2881
2950
|
readonly NOT_FOUND: "NOT_FOUND"
|
|
2882
2951
|
readonly KEY_ROTATED: "KEY_ROTATED"
|
|
2883
2952
|
readonly KEY_REVOKED: "KEY_REVOKED"
|
|
2953
|
+
readonly KEY_EXPIRED: "KEY_EXPIRED"
|
|
2884
2954
|
readonly TENANT_SUSPENDED: "TENANT_SUSPENDED"
|
|
2885
2955
|
readonly NO_TENANT_FOR_PROJECT: "NO_TENANT_FOR_PROJECT"
|
|
2886
2956
|
readonly INSTANCE_EXISTS: "INSTANCE_EXISTS"
|
|
@@ -2925,6 +2995,11 @@ declare class AuthorizationError extends SecondLayerError {
|
|
|
2925
2995
|
declare class ApiKeyRevokedError extends SecondLayerError {
|
|
2926
2996
|
constructor();
|
|
2927
2997
|
}
|
|
2998
|
+
/** A real key whose `expires_at` has passed (docs keys live 24h). Said apart
|
|
2999
|
+
* from a revoked key: nobody revoked it, it ran out. */
|
|
3000
|
+
declare class ApiKeyExpiredError extends SecondLayerError {
|
|
3001
|
+
constructor();
|
|
3002
|
+
}
|
|
2928
3003
|
declare class RateLimitError extends SecondLayerError {
|
|
2929
3004
|
constructor(message: string);
|
|
2930
3005
|
}
|
|
@@ -3149,7 +3224,9 @@ declare const CHAIN_TRIGGER_TYPES: readonly ["stx_transfer", "stx_mint", "stx_bu
|
|
|
3149
3224
|
*/
|
|
3150
3225
|
declare const CHAIN_TRIGGER_FIELDS: Record<string, string[]>;
|
|
3151
3226
|
declare const WEBHOOK_FORMATS: readonly ["standard-webhooks", "inngest", "trigger", "cloudflare", "cloudevents", "raw"];
|
|
3152
|
-
|
|
3227
|
+
/** The database accepts only `active` and `paused`; a failing receiver is
|
|
3228
|
+
* `health`, not a status. */
|
|
3229
|
+
declare const WEBHOOK_STATUSES: readonly ["active", "paused"];
|
|
3153
3230
|
declare const WebhookStatusSchema: z4.ZodType<WebhookStatus2>;
|
|
3154
3231
|
declare const WebhookFormatSchema: z4.ZodType<WebhookFormat2>;
|
|
3155
3232
|
declare const CreateWebhookRequestSchema: z4.ZodType<ParsedCreateWebhookRequest>;
|
|
@@ -3333,6 +3410,14 @@ interface WebhookSummary {
|
|
|
3333
3410
|
* cleared on resume. Present on the list summary (not detail-only) so a
|
|
3334
3411
|
* numbers-only insight can be shown per row without a per-row fetch. */
|
|
3335
3412
|
circuitOpenedAt: string | null;
|
|
3413
|
+
/** Why the webhook is paused: `user` (you paused it) or `circuit` (20
|
|
3414
|
+
* straight failures tripped the breaker). Null while `active`. Absent from
|
|
3415
|
+
* servers that predate it. */
|
|
3416
|
+
pauseReason?: WebhookPauseReason | null;
|
|
3417
|
+
/** One verdict from the state above: `ok`, `failing` (recent failures),
|
|
3418
|
+
* `down` (5+ failures in a row and no success for 15 minutes),
|
|
3419
|
+
* `paused_user` or `paused_circuit`. Absent from servers that predate it. */
|
|
3420
|
+
health?: WebhookHealth;
|
|
3336
3421
|
/** Consecutive failed deliveries (reset to 0 on a success). On the
|
|
3337
3422
|
* summary so the list can show a failing receiver per row without a
|
|
3338
3423
|
* per-row fetch. */
|
|
@@ -3617,13 +3702,17 @@ interface RuneApplyEnvelope {
|
|
|
3617
3702
|
/** One orphaned delivery recalled by a reorg rollback. */
|
|
3618
3703
|
interface ChainReorgOrphanedEntry {
|
|
3619
3704
|
tx_id: string | null;
|
|
3705
|
+
/** Hash of the orphaned block the apply came from. Lets a receiver match
|
|
3706
|
+
* the entry to the `apply` it recalls and ignore a repeat. */
|
|
3707
|
+
block_hash: string | null;
|
|
3708
|
+
block_height: number;
|
|
3620
3709
|
/** The event body from the original `apply` delivery. */
|
|
3621
3710
|
event: unknown;
|
|
3622
3711
|
}
|
|
3623
3712
|
/**
|
|
3624
3713
|
* Delivered once per affected webhook on a reorg
|
|
3625
3714
|
* (`event_type: "chain.reorg.rollback"`). Lists the previously-delivered applies
|
|
3626
|
-
*
|
|
3715
|
+
* from the blocks the reorg orphaned (each event once), so the consumer can undo
|
|
3627
3716
|
* them precisely. `orphaned` is capped (currently 500); `truncated` flags overflow.
|
|
3628
3717
|
* `chain` is set to `"bitcoin"` on a Runes reorg (plan 060) and omitted on a
|
|
3629
3718
|
* Stacks one — added rather than always-present so the existing (Stacks-only)
|
|
@@ -3880,4 +3969,4 @@ declare function publicKeyPemFromPrivate(privateKeyPem: string): string;
|
|
|
3880
3969
|
declare function ed25519KeyId(publicKeyPem: string): string;
|
|
3881
3970
|
declare function signEd25519(payload: string, privateKey: KeyObject): string;
|
|
3882
3971
|
declare function verifyEd25519(payload: string, signatureBase64: string, publicKey: KeyObject): boolean;
|
|
3883
|
-
export { Account, AccountBalanceAlerts, AccountBalanceAlertsTable, AccountCredits, AccountCreditsTable, AccountSpendCap, AccountSpendCapsTable, AccountsTable, ApiFailedRequest, ApiFailedRequestsTable, ApiKey, ApiKeyRevokedError, ApiKeysTable, ApiRequestLogRow, ApiRequestLogTable, ArchiveFetch, ArchiveFetchesTable, AuthenticationError, AuthorizationError,
|
|
3972
|
+
export { ABI_STATUSES, AbiStatus, Account, AccountBalanceAlerts, AccountBalanceAlertsTable, AccountCredits, AccountCreditsTable, AccountSpendCap, AccountSpendCapsTable, AccountsTable, ApiFailedRequest, ApiFailedRequestsTable, ApiKey, ApiKeyExpiredError, ApiKeyRevokedError, ApiKeyStatus, ApiKeysTable, ApiRequestLogRow, ApiRequestLogTable, 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, CliDeviceLogin, CliDeviceLoginStatus, CliDeviceLoginsTable, CliDeviceProduct, ContactRequest, ContactRequestsTable, 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, DeadReason, DeadRow, DecodedEventType2 as DecodedEventType, DecodedEventsTable, DecoderCheckpointsTable, DeliveryRow, DeploySubgraphRequest, DeploySubgraphRequestSchema, DeploySubgraphResponse, EMPTY_RANGE_EVENT_INDEX_SENTINEL, Env, ErrorCode, ErrorCodes, Event, EventsArchiveTable, EventsTable, FailureClass, FailureUnit, FeedbackTicket, FeedbackTicketsTable, ForbiddenError, GapReason, HealthHour, HealthSnapshotPoint, HostedStackStateTable, INSIGHT_SEVERITIES, IndexColumn, IndexColumnType, IndexPrimaryKey, IndexProgress, IndexProgressTable, InsertAccount, InsertAccountBalanceAlerts, InsertAccountCredits, InsertAccountSpendCap, InsertApiFailedRequest, InsertApiKey, InsertApiRequestLogRow, InsertArchiveFetch, InsertBlock, InsertContactRequest, InsertContract, InsertEvent, InsertFeedbackTicket, InsertIndexProgress, InsertMagicLink, InsertMempoolTransaction, InsertSession, InsertStateWrite, InsertSubgraph, InsertSubgraphGap, InsertSubgraphHealthSnapshot, InsertSubgraphOperation, InsertTransaction, InsertUpdateSubscriber, InsertUsageLedgerRow, InsertVmEvent, InsertWaitlistSignup, InsertWebhook, InsertWebhookDelivery, InsertWebhookOutbox, Insight, InsightEvidence, InsightEvidenceSchema, InsightListResponse, InsightListResponseSchema, InsightMutesTable, InsightResourceKind, InsightResourceKindSchema, InsightSchema, InsightSeverity, InsightSeveritySchema, InsightsTable, InstancesTable, KeyRotatedError, MagicLink, MagicLinksTable, MempoolTransaction, MempoolTransactionsTable, MigrationRole, NativeClock, NotFoundError, NumericAsText, OBSERVER_JOURNAL_STATUSES, OauthClient, OauthClientsTable, OauthCodesTable, OauthGrant, OauthGrantsTable, OauthRefreshRetiredTable, OauthRequestStatus, OauthRequestsTable, OauthTokenKind, OauthTokensTable, ObserverJournalStatus, ObserverJournalTable, OutboxStatus, ParsedCreateWebhookRequest, ParsedReplayWebhookRequest, ParsedUpdateWebhookRequest, PaymentRequiredError, PendingForkBlocksTable, Pox4CallsTable, Pox4FunctionName, Pox5CycleSignersTable, Pox5CyclesTable, Pox5EventTopic, Pox5EventsTable, ProcessedStripeEventsTable, PushPrefs, PushPrefsTable, PushSentTable, PushSubscription, PushSubscriptionsTable, RUNE_EVENT_TYPES, RateLimitError, ReindexResponse, RepairMode, ReplayResult, ReplayWebhookRequest, ReplayWebhookRequestSchema, RetryState, RotateSecretResponse, RunStatus, RuneApplyDeliveryOf, RuneApplyEnvelope, RuneEventType, SEVERITY_ORDER, SOURCE_READ_COLUMNS, SOURCE_READ_PKS, SOURCE_READ_TYPES, STREAMS_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_TO_DB_EVENT_TYPES, SUBGRAPH_STATES, SbtcDepositEvent, SbtcEventTopic, SbtcEventsTable, SbtcSettlementsTable, SbtcTokenEventType, SbtcTokenEventsTable, SbtcWithdrawalEvent, SbtcWithdrawalSweptConfirmedEvent, SecondLayerError, SentinelAccount, SentinelAccountsTable, ServiceHeartbeatsTable, Session, SessionsTable, StageBlockReceiptsTable, StageFailuresTable, StageKind, StageRegistryTable, StageRunsTable, StateWrite, StateWritesArchiveTable, StateWritesTable, StreamsCursor, StreamsDbEventType, StreamsEventType, Subgraph, SubgraphAgentSchema, SubgraphAggregateParams, SubgraphAggregateResponse, SubgraphDetail, SubgraphErrorGroupsTable, SubgraphGap, SubgraphGapEntry, SubgraphGapRange, SubgraphGapsResponse, SubgraphGapsTable, SubgraphHealthSnapshot, SubgraphHealthSnapshotsTable, SubgraphOperation, SubgraphOperationKind, SubgraphOperationStatus, SubgraphOperationsTable, SubgraphProcessingStatsTable, SubgraphQueryParams, SubgraphSpecFormat, SubgraphSpecOptions, SubgraphStatus, SubgraphSummary, SubgraphSyncInfo, SubgraphSyncState, SubgraphVerification, SubgraphViolationsTable, SubgraphsTable, SyncScopesTable, TABLE_TO_DB, TenantSuspendedError, Transaction, TransactionsArchiveTable, TransactionsTable, TriggerEvaluatorState, TriggerEvaluatorStateTable, UpdateAccountBalanceAlerts, UpdateAccountCredits, UpdateAccountSpendCap, UpdateApiKey, UpdateArchiveFetch, UpdateBlock, UpdateContract, UpdateEvent, UpdateIndexProgress, UpdateSendsTable, UpdateSubgraph, UpdateSubgraphOperation, UpdateSubscriber, UpdateSubscribersTable, UpdateTransaction, UpdateUsageLedgerRow, UpdateVmEvent, UpdateWebhook, UpdateWebhookOutbox, UpdateWebhookRequest, UpdateWebhookRequestSchema, UsageLedgerRow, UsageLedgerTable, 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_FORMATS, WEBHOOK_STATUSES, Waitlist, WaitlistSignup, WaitlistSignupsTable, WaitlistsTable, Webhook, WebhookDeliveriesTable, WebhookDelivery, WebhookDeliveryHoursTable, WebhookDetail, WebhookFormat, WebhookFormatSchema, WebhookIncidentAlert, WebhookIncidentAlertsTable, WebhookKind, WebhookOutbox, WebhookOutboxTable, WebhookPauseReason, WebhookReplay, WebhookReplayStatus, WebhookReplaysTable, WebhookStatus, WebhookStatusSchema, WebhookSummary, WebhooksTable, applicationDatabaseUrl, assertDbSplit, blockEndCursor, bucketHourly, closeDb, closeDbOrTimeout, committedHeight, compareStreamsCursor, exports_hmac as crypto, decodeStreamsCursor, describeDbUrl, exports_ed25519 as ed25519, encodeStreamsCursor, finalizedBurnHeight, formatWebhookSchemaErrors, generateSubgraphAgentSchema, generateSubgraphMarkdown, generateSubgraphOpenApi, generateSubgraphSpec, getDb, getDbSplitStatus, getEnv, getErrorMessage, getMigrationRole, getRawClient, getSourceDb, getTargetDb, isBnsDecoderEnabled, isEmptyRangeCursor, isPox4DecoderEnabled, isPox5DecoderEnabled, isSbtcDecoderEnabled, jsonb, logger, onChainPlane, onControlPlane, parseJsonb, resolveSourceUrl, resolveTargetUrl, setMigrationRole, sql, syncState };
|
package/dist/src/index.js
CHANGED
|
@@ -299,6 +299,21 @@ function tlsOptions(url) {
|
|
|
299
299
|
// src/db/index.ts
|
|
300
300
|
import { sql as sql2 } from "kysely";
|
|
301
301
|
|
|
302
|
+
// src/db/types.ts
|
|
303
|
+
var ABI_STATUSES = [
|
|
304
|
+
"pending",
|
|
305
|
+
"fetched",
|
|
306
|
+
"unparseable",
|
|
307
|
+
"failed"
|
|
308
|
+
];
|
|
309
|
+
var OBSERVER_JOURNAL_STATUSES = [
|
|
310
|
+
"received",
|
|
311
|
+
"processed",
|
|
312
|
+
"failed",
|
|
313
|
+
"retried",
|
|
314
|
+
"poisoned",
|
|
315
|
+
"skipped"
|
|
316
|
+
];
|
|
302
317
|
// src/db/source-read-columns.ts
|
|
303
318
|
var SOURCE_READ_COLUMNS = {
|
|
304
319
|
blocks: [
|
|
@@ -917,6 +932,7 @@ var TABLE_TO_DB = {
|
|
|
917
932
|
archive_fetches: "target",
|
|
918
933
|
usage_ledger: "target",
|
|
919
934
|
account_balance_alerts: "target",
|
|
935
|
+
hosted_stack_state: "target",
|
|
920
936
|
webhook_incident_alerts: "target",
|
|
921
937
|
sentinel_accounts: "target",
|
|
922
938
|
waitlists: "target",
|
|
@@ -1118,6 +1134,7 @@ var ErrorCodes = {
|
|
|
1118
1134
|
NOT_FOUND: "NOT_FOUND",
|
|
1119
1135
|
KEY_ROTATED: "KEY_ROTATED",
|
|
1120
1136
|
KEY_REVOKED: "KEY_REVOKED",
|
|
1137
|
+
KEY_EXPIRED: "KEY_EXPIRED",
|
|
1121
1138
|
TENANT_SUSPENDED: "TENANT_SUSPENDED",
|
|
1122
1139
|
NO_TENANT_FOR_PROJECT: "NO_TENANT_FOR_PROJECT",
|
|
1123
1140
|
INSTANCE_EXISTS: "INSTANCE_EXISTS"
|
|
@@ -1185,6 +1202,14 @@ class ApiKeyRevokedError extends SecondLayerError {
|
|
|
1185
1202
|
}
|
|
1186
1203
|
}
|
|
1187
1204
|
|
|
1205
|
+
class ApiKeyExpiredError extends SecondLayerError {
|
|
1206
|
+
constructor() {
|
|
1207
|
+
super("KEY_EXPIRED", "API key has expired", undefined, {
|
|
1208
|
+
hint: "Make a new key at https://secondlayer.tools/account/keys and replace the expired one wherever it is configured."
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1188
1213
|
class RateLimitError extends SecondLayerError {
|
|
1189
1214
|
constructor(message) {
|
|
1190
1215
|
super("RATE_LIMIT_ERROR", message);
|
|
@@ -1236,6 +1261,7 @@ var CODE_TO_STATUS = {
|
|
|
1236
1261
|
VALIDATION_ERROR: 400,
|
|
1237
1262
|
KEY_ROTATED: 401,
|
|
1238
1263
|
KEY_REVOKED: 401,
|
|
1264
|
+
KEY_EXPIRED: 401,
|
|
1239
1265
|
TENANT_SUSPENDED: 423,
|
|
1240
1266
|
NO_TENANT_FOR_PROJECT: 404,
|
|
1241
1267
|
INSTANCE_EXISTS: 409,
|
|
@@ -1318,9 +1344,13 @@ var DeploySubgraphRequestSchema = z2.object({
|
|
|
1318
1344
|
sourceCode: z2.string().max(1048576, "source code exceeds 1MB limit").optional(),
|
|
1319
1345
|
dryRun: z2.boolean().optional()
|
|
1320
1346
|
});
|
|
1321
|
-
var
|
|
1322
|
-
function
|
|
1323
|
-
|
|
1347
|
+
var SUBGRAPH_STATES = ["active", "reindexing", "error"];
|
|
1348
|
+
function syncState(subgraph, tip) {
|
|
1349
|
+
if (subgraph.status === "reindexing")
|
|
1350
|
+
return "reindexing";
|
|
1351
|
+
if (subgraph.status === "error")
|
|
1352
|
+
return "error";
|
|
1353
|
+
return Number(subgraph.lastProcessedBlock) < tip ? "catching_up" : "synced";
|
|
1324
1354
|
}
|
|
1325
1355
|
// src/schemas/insights.ts
|
|
1326
1356
|
import { z as z3 } from "zod";
|
|
@@ -1511,7 +1541,7 @@ var WEBHOOK_FORMATS = [
|
|
|
1511
1541
|
"cloudevents",
|
|
1512
1542
|
"raw"
|
|
1513
1543
|
];
|
|
1514
|
-
var WEBHOOK_STATUSES = ["active", "paused"
|
|
1544
|
+
var WEBHOOK_STATUSES = ["active", "paused"];
|
|
1515
1545
|
var WEBHOOK_MAX_RETRIES_CEILING_DEFAULT = 100;
|
|
1516
1546
|
var WEBHOOK_TIMEOUT_MS_CEILING_DEFAULT = 300000;
|
|
1517
1547
|
function ceilingFromEnv(envVar, fallback) {
|
|
@@ -2356,10 +2386,11 @@ function verifyEd25519(payload, signatureBase64, publicKey) {
|
|
|
2356
2386
|
}
|
|
2357
2387
|
}
|
|
2358
2388
|
export {
|
|
2389
|
+
ABI_STATUSES,
|
|
2390
|
+
ApiKeyExpiredError,
|
|
2359
2391
|
ApiKeyRevokedError,
|
|
2360
2392
|
AuthenticationError,
|
|
2361
2393
|
AuthorizationError,
|
|
2362
|
-
BILLING_PAUSED_PREFIX,
|
|
2363
2394
|
CHAIN_TRIGGER_FIELDS,
|
|
2364
2395
|
CHAIN_TRIGGER_TYPES,
|
|
2365
2396
|
CODE_TO_STATUS,
|
|
@@ -2380,6 +2411,7 @@ export {
|
|
|
2380
2411
|
InsightSeveritySchema,
|
|
2381
2412
|
KeyRotatedError,
|
|
2382
2413
|
NotFoundError,
|
|
2414
|
+
OBSERVER_JOURNAL_STATUSES,
|
|
2383
2415
|
PaymentRequiredError,
|
|
2384
2416
|
RUNE_EVENT_TYPES,
|
|
2385
2417
|
RateLimitError,
|
|
@@ -2391,6 +2423,7 @@ export {
|
|
|
2391
2423
|
STREAMS_DB_EVENT_TYPES,
|
|
2392
2424
|
STREAMS_EVENT_TYPES,
|
|
2393
2425
|
STREAMS_TO_DB_EVENT_TYPES,
|
|
2426
|
+
SUBGRAPH_STATES,
|
|
2394
2427
|
SecondLayerError,
|
|
2395
2428
|
TABLE_TO_DB,
|
|
2396
2429
|
TenantSuspendedError,
|
|
@@ -2406,7 +2439,6 @@ export {
|
|
|
2406
2439
|
WebhookStatusSchema,
|
|
2407
2440
|
applicationDatabaseUrl,
|
|
2408
2441
|
assertDbSplit,
|
|
2409
|
-
billingPausedCode,
|
|
2410
2442
|
blockEndCursor,
|
|
2411
2443
|
bucketHourly,
|
|
2412
2444
|
closeDb,
|
|
@@ -2445,8 +2477,9 @@ export {
|
|
|
2445
2477
|
resolveSourceUrl,
|
|
2446
2478
|
resolveTargetUrl,
|
|
2447
2479
|
setMigrationRole,
|
|
2448
|
-
sql2 as sql
|
|
2480
|
+
sql2 as sql,
|
|
2481
|
+
syncState
|
|
2449
2482
|
};
|
|
2450
2483
|
|
|
2451
|
-
//# debugId=
|
|
2484
|
+
//# debugId=C1E5434557BE72FF64756E2164756E21
|
|
2452
2485
|
//# sourceMappingURL=index.js.map
|