@secondlayer/shared 6.3.4 → 6.4.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.
Files changed (31) hide show
  1. package/dist/src/crypto/secrets.js +2 -5
  2. package/dist/src/crypto/secrets.js.map +3 -3
  3. package/dist/src/db/index.d.ts +6 -1
  4. package/dist/src/db/queries/account-spend-caps.d.ts +5 -0
  5. package/dist/src/db/queries/account-usage.d.ts +5 -0
  6. package/dist/src/db/queries/accounts.d.ts +5 -0
  7. package/dist/src/db/queries/chain-reorgs.d.ts +5 -0
  8. package/dist/src/db/queries/integrity.d.ts +5 -0
  9. package/dist/src/db/queries/projects.d.ts +5 -0
  10. package/dist/src/db/queries/provisioning-audit.d.ts +5 -0
  11. package/dist/src/db/queries/subgraph-gaps.d.ts +5 -0
  12. package/dist/src/db/queries/subgraph-operations.d.ts +5 -0
  13. package/dist/src/db/queries/subgraphs.d.ts +5 -0
  14. package/dist/src/db/queries/subscriptions.d.ts +5 -0
  15. package/dist/src/db/queries/subscriptions.js +2 -5
  16. package/dist/src/db/queries/subscriptions.js.map +3 -3
  17. package/dist/src/db/queries/tenant-compute-addons.d.ts +5 -0
  18. package/dist/src/db/queries/usage.d.ts +5 -0
  19. package/dist/src/db/schema.d.ts +6 -1
  20. package/dist/src/index.d.ts +6 -1
  21. package/dist/src/mode.d.ts +6 -12
  22. package/dist/src/mode.js +2 -6
  23. package/dist/src/mode.js.map +3 -3
  24. package/dist/src/node/local-client.d.ts +5 -0
  25. package/migrations/0074_service_heartbeats.ts +23 -0
  26. package/migrations/0075_restore_subgraphs_on_platform.ts +166 -0
  27. package/migrations/0076_deprecate_tenants.ts +19 -0
  28. package/package.json +1 -1
  29. package/dist/src/db/queries/tenants.d.ts +0 -795
  30. package/dist/src/db/queries/tenants.js +0 -308
  31. package/dist/src/db/queries/tenants.js.map +0 -12
@@ -1,795 +0,0 @@
1
- import { Kysely } from "kysely";
2
- import { ColumnType, Generated, Selectable } from "kysely";
3
- interface BlocksTable {
4
- height: number;
5
- hash: string;
6
- parent_hash: string;
7
- burn_block_height: number;
8
- burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
9
- timestamp: number;
10
- canonical: Generated<boolean>;
11
- created_at: Generated<Date>;
12
- }
13
- interface TransactionsTable {
14
- tx_id: string;
15
- block_height: number;
16
- tx_index: Generated<number>;
17
- type: string;
18
- sender: string;
19
- status: string;
20
- contract_id: string | null;
21
- function_name: string | null;
22
- function_args: Generated<unknown | null>;
23
- raw_result: Generated<string | null>;
24
- raw_tx: string;
25
- created_at: Generated<Date>;
26
- }
27
- interface EventsTable {
28
- id: Generated<string>;
29
- tx_id: string;
30
- block_height: number;
31
- event_index: number;
32
- type: string;
33
- data: unknown;
34
- created_at: Generated<Date>;
35
- }
36
- interface IndexProgressTable {
37
- network: string;
38
- last_indexed_block: Generated<number>;
39
- last_contiguous_block: Generated<number>;
40
- highest_seen_block: Generated<number>;
41
- updated_at: Generated<Date>;
42
- }
43
- interface SubgraphsTable {
44
- id: Generated<string>;
45
- name: string;
46
- version: Generated<string>;
47
- status: Generated<string>;
48
- definition: Record<string, unknown>;
49
- schema_hash: string;
50
- handler_path: string;
51
- schema_name: string | null;
52
- start_block: Generated<number>;
53
- last_processed_block: Generated<number>;
54
- reindex_from_block: number | null;
55
- reindex_to_block: number | null;
56
- last_error: string | null;
57
- last_error_at: Date | null;
58
- total_processed: Generated<number>;
59
- total_errors: Generated<number>;
60
- account_id: string;
61
- handler_code: string | null;
62
- source_code: string | null;
63
- project_id: string | null;
64
- created_at: Generated<Date>;
65
- updated_at: Generated<Date>;
66
- }
67
- interface SubgraphGapsTable {
68
- id: Generated<string>;
69
- subgraph_id: string;
70
- subgraph_name: string;
71
- gap_start: number;
72
- gap_end: number;
73
- reason: string;
74
- detected_at: Generated<Date>;
75
- resolved_at: Date | null;
76
- }
77
- type SubgraphOperationKind = "reindex" | "backfill";
78
- type SubgraphOperationStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
79
- interface SubgraphOperationsTable {
80
- id: Generated<string>;
81
- subgraph_id: string;
82
- subgraph_name: string;
83
- account_id: string | null;
84
- kind: ColumnType<SubgraphOperationKind, SubgraphOperationKind, SubgraphOperationKind>;
85
- status: ColumnType<SubgraphOperationStatus, SubgraphOperationStatus | undefined, SubgraphOperationStatus>;
86
- from_block: number | null;
87
- to_block: number | null;
88
- cancel_requested: Generated<boolean>;
89
- locked_by: string | null;
90
- locked_until: Date | null;
91
- started_at: Date | null;
92
- finished_at: Date | null;
93
- processed_blocks: number | null;
94
- error: string | null;
95
- created_at: Generated<Date>;
96
- updated_at: Generated<Date>;
97
- }
98
- interface ApiKeysTable {
99
- id: Generated<string>;
100
- key_hash: string;
101
- key_prefix: string;
102
- name: string | null;
103
- status: Generated<string>;
104
- rate_limit: Generated<number>;
105
- ip_address: string;
106
- account_id: string;
107
- product: Generated<"account" | "streams" | "index">;
108
- tier: "free" | "build" | "scale" | "enterprise" | null;
109
- last_used_at: Date | null;
110
- revoked_at: Date | null;
111
- created_at: Generated<Date>;
112
- }
113
- interface AccountsTable {
114
- id: Generated<string>;
115
- email: string;
116
- plan: Generated<string>;
117
- display_name: string | null;
118
- bio: string | null;
119
- avatar_url: string | null;
120
- slug: string | null;
121
- stripe_customer_id: string | null;
122
- created_at: Generated<Date>;
123
- }
124
- interface SessionsTable {
125
- id: Generated<string>;
126
- token_hash: string;
127
- token_prefix: string;
128
- account_id: string;
129
- ip_address: string;
130
- expires_at: Generated<Date>;
131
- revoked_at: Date | null;
132
- last_used_at: Date | null;
133
- created_at: Generated<Date>;
134
- }
135
- interface MagicLinksTable {
136
- id: Generated<string>;
137
- email: string;
138
- token: string;
139
- code: string | null;
140
- expires_at: Date;
141
- used_at: Date | null;
142
- failed_attempts: Generated<number>;
143
- created_at: Generated<Date>;
144
- }
145
- interface UsageDailyTable {
146
- account_id: string;
147
- tenant_id: string | null;
148
- date: string;
149
- api_requests: Generated<number>;
150
- deliveries: Generated<number>;
151
- streams_events_returned: Generated<number>;
152
- index_decoded_events_returned: Generated<number>;
153
- }
154
- interface UsageSnapshotsTable {
155
- id: Generated<string>;
156
- account_id: string;
157
- measured_at: Generated<Date>;
158
- storage_bytes: Generated<number>;
159
- }
160
- interface WaitlistTable {
161
- id: Generated<string>;
162
- email: string;
163
- source: Generated<string>;
164
- status: Generated<string>;
165
- created_at: Generated<Date>;
166
- }
167
- interface AccountInsightsTable {
168
- id: Generated<string>;
169
- account_id: string;
170
- category: string;
171
- insight_type: string;
172
- resource_id: string | null;
173
- severity: string;
174
- title: string;
175
- body: string;
176
- data: unknown;
177
- dismissed_at: Date | null;
178
- expires_at: Date | null;
179
- created_at: Generated<Date>;
180
- }
181
- interface AccountAgentRunsTable {
182
- id: Generated<string>;
183
- account_id: string;
184
- started_at: Generated<Date>;
185
- completed_at: Date | null;
186
- status: Generated<string>;
187
- input_tokens: Generated<number>;
188
- output_tokens: Generated<number>;
189
- cost_usd: Generated<number>;
190
- insights_created: Generated<number>;
191
- error: string | null;
192
- }
193
- interface SubgraphProcessingStatsTable {
194
- id: Generated<string>;
195
- subgraph_name: string;
196
- api_key_id: string | null;
197
- bucket_start: Date | null;
198
- bucket_end: Date | null;
199
- blocks_processed: number | null;
200
- total_time_ms: number | null;
201
- handler_time_ms: number | null;
202
- flush_time_ms: number | null;
203
- max_block_time_ms: number | null;
204
- max_handler_time_ms: number | null;
205
- avg_ops_per_block: number | null;
206
- is_catchup: Generated<boolean>;
207
- created_at: Generated<Date>;
208
- }
209
- interface SubgraphTableSnapshotsTable {
210
- id: Generated<string>;
211
- subgraph_name: string;
212
- api_key_id: string | null;
213
- table_name: string;
214
- row_count: number | null;
215
- created_at: Generated<Date>;
216
- }
217
- interface SubgraphHealthSnapshotsTable {
218
- id: Generated<string>;
219
- subgraph_id: string;
220
- total_processed: number;
221
- total_errors: number;
222
- last_processed_block: number | null;
223
- captured_at: Generated<Date>;
224
- }
225
- interface SubgraphUsageDailyTable {
226
- subgraph_id: string;
227
- date: string;
228
- query_count: Generated<number>;
229
- }
230
- interface ProjectsTable {
231
- id: Generated<string>;
232
- name: string;
233
- slug: string;
234
- account_id: string;
235
- settings: Generated<Record<string, unknown>>;
236
- network: Generated<string>;
237
- node_rpc: string | null;
238
- created_at: Generated<Date>;
239
- updated_at: Generated<Date>;
240
- }
241
- interface TeamMembersTable {
242
- id: Generated<string>;
243
- project_id: string;
244
- account_id: string;
245
- role: Generated<string>;
246
- invited_by: string | null;
247
- created_at: Generated<Date>;
248
- }
249
- interface TeamInvitationsTable {
250
- id: Generated<string>;
251
- project_id: string;
252
- email: string;
253
- role: Generated<string>;
254
- token: string;
255
- invited_by: string | null;
256
- expires_at: Date;
257
- accepted_at: Date | null;
258
- created_at: Generated<Date>;
259
- }
260
- interface ChatSessionsTable {
261
- id: Generated<string>;
262
- account_id: string;
263
- title: string | null;
264
- summary: unknown | null;
265
- created_at: Generated<Date>;
266
- updated_at: Generated<Date>;
267
- }
268
- interface ChatMessagesTable {
269
- id: Generated<string>;
270
- chat_session_id: string;
271
- role: string;
272
- parts: unknown;
273
- metadata: unknown | null;
274
- created_at: Generated<Date>;
275
- }
276
- interface ProcessedStripeEventsTable {
277
- event_id: string;
278
- event_type: string;
279
- processed_at: Generated<Date>;
280
- }
281
- interface DecodedEventsTable {
282
- cursor: string;
283
- block_height: number;
284
- tx_id: string;
285
- tx_index: number;
286
- event_index: number;
287
- event_type: string;
288
- microblock_hash: string | null;
289
- canonical: Generated<boolean>;
290
- contract_id: string | null;
291
- sender: string | null;
292
- recipient: string | null;
293
- amount: string | null;
294
- asset_identifier: string | null;
295
- value: string | null;
296
- memo: string | null;
297
- source_cursor: string;
298
- created_at: Generated<Date>;
299
- }
300
- interface L2DecoderCheckpointsTable {
301
- decoder_name: string;
302
- last_cursor: string | null;
303
- updated_at: Generated<Date>;
304
- }
305
- interface ChainReorgsTable {
306
- id: Generated<string>;
307
- detected_at: Generated<Date>;
308
- fork_point_height: number;
309
- old_index_block_hash: string | null;
310
- new_index_block_hash: string | null;
311
- orphaned_from_height: number;
312
- orphaned_from_event_index: number;
313
- orphaned_to_height: number;
314
- orphaned_to_event_index: number;
315
- new_canonical_height: number;
316
- new_canonical_event_index: number;
317
- created_at: Generated<Date>;
318
- }
319
- type Pox4FunctionName = "stack-stx" | "delegate-stx" | "stack-extend" | "stack-increase" | "revoke-delegate-stx" | "delegate-stack-stx" | "delegate-stack-extend" | "delegate-stack-increase" | "stack-aggregation-commit" | "stack-aggregation-commit-indexed" | "stack-aggregation-increase" | "set-signer-key-authorization";
320
- interface Pox4CallsTable {
321
- cursor: string;
322
- block_height: number;
323
- block_time: Date;
324
- burn_block_height: number;
325
- tx_id: string;
326
- tx_index: number;
327
- function_name: Pox4FunctionName;
328
- caller: string;
329
- stacker: string | null;
330
- delegate_to: string | null;
331
- amount_ustx: string | null;
332
- lock_period: number | null;
333
- pox_addr_version: number | null;
334
- pox_addr_hashbytes: string | null;
335
- pox_addr_btc: string | null;
336
- start_cycle: number | null;
337
- end_cycle: number | null;
338
- signer_key: string | null;
339
- signer_signature: string | null;
340
- auth_id: string | null;
341
- max_amount: string | null;
342
- reward_cycle: number | null;
343
- aggregated_amount_ustx: string | null;
344
- aggregated_signer_index: number | null;
345
- auth_period: number | null;
346
- auth_topic: string | null;
347
- auth_allowed: boolean | null;
348
- result_ok: boolean;
349
- result_raw: string;
350
- canonical: Generated<boolean>;
351
- source_cursor: string;
352
- created_at: Generated<Date>;
353
- }
354
- interface Pox4CyclesDailyTable {
355
- date: string;
356
- reward_cycle: number;
357
- total_stacked_ustx: Generated<string>;
358
- solo_stackers: Generated<number>;
359
- delegated_principals: Generated<number>;
360
- unique_pools: Generated<number>;
361
- unique_signers: Generated<number>;
362
- calls_today: Generated<number>;
363
- updated_at: Generated<Date>;
364
- }
365
- interface Pox4SignersDailyTable {
366
- date: string;
367
- reward_cycle: number;
368
- signer_key: string;
369
- weight_ustx: Generated<string>;
370
- stacker_count: Generated<number>;
371
- aggregation_calls: Generated<number>;
372
- updated_at: Generated<Date>;
373
- }
374
- type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
375
- interface SbtcEventsTable {
376
- cursor: string;
377
- block_height: number;
378
- block_time: Date;
379
- tx_id: string;
380
- tx_index: number;
381
- event_index: number;
382
- topic: SbtcEventTopic;
383
- request_id: number | null;
384
- amount: string | null;
385
- sender: string | null;
386
- recipient_btc_version: number | null;
387
- recipient_btc_hashbytes: string | null;
388
- bitcoin_txid: string | null;
389
- output_index: number | null;
390
- sweep_txid: string | null;
391
- burn_hash: string | null;
392
- burn_height: number | null;
393
- signer_bitmap: string | null;
394
- max_fee: string | null;
395
- fee: string | null;
396
- block_height_at_request: number | null;
397
- governance_contract_type: number | null;
398
- governance_new_contract: string | null;
399
- signer_aggregate_pubkey: string | null;
400
- signer_threshold: number | null;
401
- signer_address: string | null;
402
- signer_keys_count: number | null;
403
- canonical: Generated<boolean>;
404
- source_cursor: string;
405
- created_at: Generated<Date>;
406
- }
407
- type SbtcTokenEventType = "transfer" | "mint" | "burn";
408
- interface SbtcTokenEventsTable {
409
- cursor: string;
410
- block_height: number;
411
- block_time: Date;
412
- tx_id: string;
413
- tx_index: number;
414
- event_index: number;
415
- event_type: SbtcTokenEventType;
416
- sender: string | null;
417
- recipient: string | null;
418
- amount: string;
419
- memo: string | null;
420
- canonical: Generated<boolean>;
421
- source_cursor: string;
422
- created_at: Generated<Date>;
423
- }
424
- interface SbtcSupplySnapshotsTable {
425
- date: string;
426
- total_supply: Generated<string>;
427
- mints_today: Generated<string>;
428
- burns_today: Generated<string>;
429
- deposit_count: Generated<number>;
430
- withdrawal_create_count: Generated<number>;
431
- withdrawal_accept_count: Generated<number>;
432
- withdrawal_reject_count: Generated<number>;
433
- updated_at: Generated<Date>;
434
- }
435
- type BnsNameEventTopic = "new-name" | "transfer-name" | "renew-name" | "burn-name" | "new-airdrop";
436
- interface BnsNameEventsTable {
437
- cursor: string;
438
- block_height: number;
439
- block_time: Date;
440
- tx_id: string;
441
- tx_index: number;
442
- event_index: number;
443
- topic: BnsNameEventTopic;
444
- namespace: string;
445
- name: string;
446
- fqn: string;
447
- owner: string | null;
448
- bns_id: string;
449
- registered_at: number | null;
450
- imported_at: number | null;
451
- renewal_height: number | null;
452
- stx_burn: string | null;
453
- preordered_by: string | null;
454
- hashed_salted_fqn_preorder: string | null;
455
- canonical: Generated<boolean>;
456
- source_cursor: string;
457
- created_at: Generated<Date>;
458
- }
459
- type BnsNamespaceEventStatus = "launch" | "transfer-manager" | "freeze-manager" | "update-price-manager" | "freeze-price-manager" | "turn-off-manager-transfers";
460
- interface BnsNamespaceEventsTable {
461
- cursor: string;
462
- block_height: number;
463
- block_time: Date;
464
- tx_id: string;
465
- tx_index: number;
466
- event_index: number;
467
- status: BnsNamespaceEventStatus;
468
- namespace: string;
469
- manager: string | null;
470
- manager_frozen: boolean | null;
471
- manager_transfers_disabled: boolean | null;
472
- price_function: string | null;
473
- price_frozen: boolean | null;
474
- lifetime: number | null;
475
- revealed_at: number | null;
476
- launched_at: number | null;
477
- canonical: Generated<boolean>;
478
- source_cursor: string;
479
- created_at: Generated<Date>;
480
- }
481
- type BnsMarketplaceAction = "list-in-ustx" | "unlist-in-ustx" | "buy-in-ustx";
482
- interface BnsMarketplaceEventsTable {
483
- cursor: string;
484
- block_height: number;
485
- block_time: Date;
486
- tx_id: string;
487
- tx_index: number;
488
- event_index: number;
489
- action: BnsMarketplaceAction;
490
- bns_id: string;
491
- price_ustx: string | null;
492
- commission: string | null;
493
- canonical: Generated<boolean>;
494
- source_cursor: string;
495
- created_at: Generated<Date>;
496
- }
497
- interface BnsNamesTable {
498
- fqn: string;
499
- namespace: string;
500
- name: string;
501
- owner: string;
502
- bns_id: string;
503
- registered_at: number | null;
504
- renewal_height: number | null;
505
- last_event_cursor: string;
506
- last_event_at: Date;
507
- updated_at: Generated<Date>;
508
- }
509
- interface BnsNamespacesTable {
510
- namespace: string;
511
- manager: string | null;
512
- manager_frozen: Generated<boolean>;
513
- price_frozen: Generated<boolean>;
514
- lifetime: number | null;
515
- launched_at: number | null;
516
- last_event_cursor: string;
517
- last_event_at: Date;
518
- name_count: Generated<number>;
519
- updated_at: Generated<Date>;
520
- }
521
- interface Database {
522
- blocks: BlocksTable;
523
- transactions: TransactionsTable;
524
- events: EventsTable;
525
- index_progress: IndexProgressTable;
526
- subgraphs: SubgraphsTable;
527
- api_keys: ApiKeysTable;
528
- accounts: AccountsTable;
529
- sessions: SessionsTable;
530
- magic_links: MagicLinksTable;
531
- usage_daily: UsageDailyTable;
532
- usage_snapshots: UsageSnapshotsTable;
533
- waitlist: WaitlistTable;
534
- account_insights: AccountInsightsTable;
535
- account_agent_runs: AccountAgentRunsTable;
536
- subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
537
- subgraph_processing_stats: SubgraphProcessingStatsTable;
538
- subgraph_table_snapshots: SubgraphTableSnapshotsTable;
539
- subgraph_gaps: SubgraphGapsTable;
540
- subgraph_operations: SubgraphOperationsTable;
541
- subgraph_usage_daily: SubgraphUsageDailyTable;
542
- projects: ProjectsTable;
543
- team_members: TeamMembersTable;
544
- team_invitations: TeamInvitationsTable;
545
- chat_sessions: ChatSessionsTable;
546
- chat_messages: ChatMessagesTable;
547
- processed_stripe_events: ProcessedStripeEventsTable;
548
- tenants: TenantsTable;
549
- tenant_usage_monthly: TenantUsageMonthlyTable;
550
- tenant_compute_addons: TenantComputeAddonsTable;
551
- account_spend_caps: AccountSpendCapsTable;
552
- provisioning_audit_log: ProvisioningAuditLogTable;
553
- subscriptions: SubscriptionsTable;
554
- subscription_outbox: SubscriptionOutboxTable;
555
- subscription_deliveries: SubscriptionDeliveriesTable;
556
- decoded_events: DecodedEventsTable;
557
- l2_decoder_checkpoints: L2DecoderCheckpointsTable;
558
- chain_reorgs: ChainReorgsTable;
559
- pox4_calls: Pox4CallsTable;
560
- pox4_cycles_daily: Pox4CyclesDailyTable;
561
- pox4_signers_daily: Pox4SignersDailyTable;
562
- sbtc_events: SbtcEventsTable;
563
- sbtc_token_events: SbtcTokenEventsTable;
564
- sbtc_supply_snapshots: SbtcSupplySnapshotsTable;
565
- bns_name_events: BnsNameEventsTable;
566
- bns_namespace_events: BnsNamespaceEventsTable;
567
- bns_marketplace_events: BnsMarketplaceEventsTable;
568
- bns_names: BnsNamesTable;
569
- bns_namespaces: BnsNamespacesTable;
570
- }
571
- type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
572
- interface TenantsTable {
573
- id: Generated<string>;
574
- account_id: string;
575
- slug: string;
576
- status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
577
- plan: string;
578
- cpus: ColumnType<number, number | string, number | string>;
579
- memory_mb: number;
580
- storage_limit_mb: number;
581
- storage_used_mb: number | null;
582
- pg_container_id: string | null;
583
- api_container_id: string | null;
584
- processor_container_id: string | null;
585
- target_database_url_enc: Buffer;
586
- tenant_jwt_secret_enc: Buffer;
587
- anon_key_enc: Buffer;
588
- service_key_enc: Buffer;
589
- api_url_internal: string;
590
- api_url_public: string;
591
- suspended_at: Date | null;
592
- last_health_check_at: Date | null;
593
- last_active_at: Generated<Date>;
594
- service_gen: Generated<number>;
595
- anon_gen: Generated<number>;
596
- project_id: string | null;
597
- created_at: Generated<Date>;
598
- updated_at: Generated<Date>;
599
- }
600
- type Tenant = Selectable<TenantsTable>;
601
- interface TenantUsageMonthlyTable {
602
- id: Generated<string>;
603
- tenant_id: string;
604
- period_month: Date;
605
- storage_peak_mb: Generated<number>;
606
- storage_avg_mb: Generated<number>;
607
- storage_last_mb: Generated<number>;
608
- measurements: Generated<number>;
609
- first_at: Generated<Date>;
610
- last_at: Generated<Date>;
611
- }
612
- interface TenantComputeAddonsTable {
613
- id: Generated<string>;
614
- tenant_id: string;
615
- memory_mb_delta: Generated<number>;
616
- cpu_delta: Generated<number | string>;
617
- storage_mb_delta: Generated<number>;
618
- effective_from: Generated<Date>;
619
- effective_until: Date | null;
620
- stripe_subscription_item_id: string | null;
621
- created_at: Generated<Date>;
622
- }
623
- interface AccountSpendCapsTable {
624
- account_id: string;
625
- monthly_cap_cents: number | null;
626
- compute_cap_cents: number | null;
627
- storage_cap_cents: number | null;
628
- alert_threshold_pct: Generated<number>;
629
- alert_sent_at: Date | null;
630
- frozen_at: Date | null;
631
- updated_at: Generated<Date>;
632
- }
633
- type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
634
- type ProvisioningAuditStatus = "ok" | "error";
635
- interface ProvisioningAuditLogTable {
636
- id: Generated<string>;
637
- tenant_id: string | null;
638
- tenant_slug: string | null;
639
- account_id: string | null;
640
- actor: string;
641
- event: ProvisioningAuditEvent;
642
- status: ProvisioningAuditStatus;
643
- detail: unknown | null;
644
- error: string | null;
645
- created_at: Generated<Date>;
646
- }
647
- type SubscriptionStatus = "active" | "paused" | "error";
648
- type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
649
- type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
650
- interface SubscriptionsTable {
651
- id: Generated<string>;
652
- account_id: string;
653
- project_id: string | null;
654
- name: string;
655
- status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
656
- subgraph_name: string;
657
- table_name: string;
658
- filter: Generated<unknown>;
659
- format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
660
- runtime: SubscriptionRuntime | null;
661
- url: string;
662
- signing_secret_enc: Buffer;
663
- auth_config: Generated<unknown>;
664
- max_retries: Generated<number>;
665
- timeout_ms: Generated<number>;
666
- concurrency: Generated<number>;
667
- circuit_failures: Generated<number>;
668
- circuit_opened_at: Date | null;
669
- last_delivery_at: Date | null;
670
- last_success_at: Date | null;
671
- last_error: string | null;
672
- created_at: Generated<Date>;
673
- updated_at: Generated<Date>;
674
- }
675
- type OutboxStatus = "pending" | "delivered" | "dead";
676
- interface SubscriptionOutboxTable {
677
- id: Generated<string>;
678
- subscription_id: string;
679
- subgraph_name: string;
680
- table_name: string;
681
- block_height: number | bigint;
682
- tx_id: string | null;
683
- row_pk: unknown;
684
- event_type: string;
685
- payload: unknown;
686
- dedup_key: string;
687
- attempt: Generated<number>;
688
- next_attempt_at: Generated<Date>;
689
- status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
690
- is_replay: Generated<boolean>;
691
- delivered_at: Date | null;
692
- failed_at: Date | null;
693
- locked_by: string | null;
694
- locked_until: Date | null;
695
- created_at: Generated<Date>;
696
- }
697
- interface SubscriptionDeliveriesTable {
698
- id: Generated<string>;
699
- outbox_id: string;
700
- subscription_id: string;
701
- attempt: number;
702
- status_code: number | null;
703
- response_headers: unknown | null;
704
- response_body: string | null;
705
- error_message: string | null;
706
- duration_ms: number | null;
707
- dispatched_at: Generated<Date>;
708
- }
709
- /**
710
- * Tenant registry queries. Encrypted columns are stored as `bytea` and
711
- * transparently encrypted/decrypted via `encryptSecret`/`decryptSecret`.
712
- *
713
- * Never return decrypted values from listTenants — only `getTenantCredentials`
714
- * surfaces plaintext, and only when explicitly called by a caller that
715
- * needs to hand creds to a CLI or dashboard session.
716
- */
717
- interface NewTenantInput {
718
- accountId: string;
719
- slug: string;
720
- plan: string;
721
- cpus: number;
722
- memoryMb: number;
723
- storageLimitMb: number;
724
- pgContainerId: string;
725
- apiContainerId: string;
726
- processorContainerId: string;
727
- targetDatabaseUrl: string;
728
- tenantJwtSecret: string;
729
- anonKey: string;
730
- serviceKey: string;
731
- apiUrlInternal: string;
732
- apiUrlPublic: string;
733
- projectId?: string;
734
- }
735
- declare function insertTenant(db: Kysely<Database>, input: NewTenantInput): Promise<Tenant>;
736
- declare function getTenantByAccount(db: Kysely<Database>, accountId: string): Promise<Tenant | null>;
737
- declare function getTenantBySlug(db: Kysely<Database>, slug: string): Promise<Tenant | null>;
738
- declare function listTenantsByStatus(db: Kysely<Database>, status: TenantStatus): Promise<Tenant[]>;
739
- /**
740
- * Bump `last_active_at` for a tenant. Callers are expected to throttle
741
- * (don't hammer on every request) — the tenant-API activity middleware
742
- * enforces a 60s per-tenant min between writes.
743
- */
744
- declare function bumpTenantActivity(db: Kysely<Database>, slug: string): Promise<void>;
745
- declare function listSuspendedOlderThan(db: Kysely<Database>, olderThan: Date): Promise<Tenant[]>;
746
- declare function setTenantStatus(db: Kysely<Database>, slug: string, status: TenantStatus): Promise<void>;
747
- declare function recordHealthCheck(db: Kysely<Database>, slug: string, storageUsedMb: number | null): Promise<void>;
748
- /**
749
- * Record a storage measurement into the current calendar month's bucket.
750
- * Maintains peak, running average, and the most recent value in a single
751
- * upsert. Billing will consume this later; for now the table just gives
752
- * us evidence of usage over time.
753
- */
754
- declare function recordMonthlyUsage(db: Kysely<Database>, tenantId: string, storageMb: number): Promise<void>;
755
- declare function updateTenantPlan(db: Kysely<Database>, slug: string, plan: string, cpus: number, memoryMb: number, storageLimitMb: number): Promise<void>;
756
- type RotateType = "service" | "anon" | "both";
757
- /**
758
- * Bump the selected gen counter(s) by 1 and return the new values.
759
- * Used by the key-rotate endpoint to force the tenant API to reject
760
- * previously-issued tokens of the rotated role(s).
761
- */
762
- declare function bumpTenantKeyGen(db: Kysely<Database>, slug: string, type: RotateType): Promise<{
763
- serviceGen: number
764
- anonGen: number
765
- }>;
766
- /**
767
- * Replace the encrypted key columns after a successful rotate. Only the
768
- * rotated column(s) are written — the other stays untouched.
769
- */
770
- declare function updateTenantKeys(db: Kysely<Database>, slug: string, keys: {
771
- serviceKey?: string
772
- anonKey?: string
773
- }): Promise<void>;
774
- /**
775
- * Hard-delete a tenant row. Call only AFTER the provisioner has torn down
776
- * containers + volume; otherwise orphaned resources linger. Returns whether
777
- * a row was actually deleted.
778
- */
779
- declare function deleteTenant(db: Kysely<Database>, slug: string): Promise<boolean>;
780
- interface TenantCredentials {
781
- slug: string;
782
- targetDatabaseUrl: string;
783
- tenantJwtSecret: string;
784
- anonKey: string;
785
- serviceKey: string;
786
- apiUrlInternal: string;
787
- apiUrlPublic: string;
788
- }
789
- /**
790
- * Decrypts the four encrypted columns and returns them plaintext. Call
791
- * this only when surfacing credentials to an authorized caller (dashboard,
792
- * CLI). Never log the returned object.
793
- */
794
- declare function getTenantCredentials(db: Kysely<Database>, slug: string): Promise<TenantCredentials | null>;
795
- export { updateTenantPlan, updateTenantKeys, setTenantStatus, recordMonthlyUsage, recordHealthCheck, listTenantsByStatus, listSuspendedOlderThan, insertTenant, getTenantCredentials, getTenantBySlug, getTenantByAccount, deleteTenant, bumpTenantKeyGen, bumpTenantActivity, TenantCredentials, RotateType, NewTenantInput };