@secondlayer/shared 6.0.0 → 6.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.
@@ -0,0 +1,534 @@
1
+ import { ColumnType, Generated } from "kysely";
2
+ interface BlocksTable {
3
+ height: number;
4
+ hash: string;
5
+ parent_hash: string;
6
+ burn_block_height: number;
7
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
8
+ timestamp: number;
9
+ canonical: Generated<boolean>;
10
+ created_at: Generated<Date>;
11
+ }
12
+ interface TransactionsTable {
13
+ tx_id: string;
14
+ block_height: number;
15
+ tx_index: Generated<number>;
16
+ type: string;
17
+ sender: string;
18
+ status: string;
19
+ contract_id: string | null;
20
+ function_name: string | null;
21
+ function_args: Generated<unknown | null>;
22
+ raw_result: Generated<string | null>;
23
+ raw_tx: string;
24
+ created_at: Generated<Date>;
25
+ }
26
+ interface EventsTable {
27
+ id: Generated<string>;
28
+ tx_id: string;
29
+ block_height: number;
30
+ event_index: number;
31
+ type: string;
32
+ data: unknown;
33
+ created_at: Generated<Date>;
34
+ }
35
+ interface IndexProgressTable {
36
+ network: string;
37
+ last_indexed_block: Generated<number>;
38
+ last_contiguous_block: Generated<number>;
39
+ highest_seen_block: Generated<number>;
40
+ updated_at: Generated<Date>;
41
+ }
42
+ interface SubgraphsTable {
43
+ id: Generated<string>;
44
+ name: string;
45
+ version: Generated<string>;
46
+ status: Generated<string>;
47
+ definition: Record<string, unknown>;
48
+ schema_hash: string;
49
+ handler_path: string;
50
+ schema_name: string | null;
51
+ start_block: Generated<number>;
52
+ last_processed_block: Generated<number>;
53
+ reindex_from_block: number | null;
54
+ reindex_to_block: number | null;
55
+ last_error: string | null;
56
+ last_error_at: Date | null;
57
+ total_processed: Generated<number>;
58
+ total_errors: Generated<number>;
59
+ account_id: string;
60
+ handler_code: string | null;
61
+ source_code: string | null;
62
+ project_id: string | null;
63
+ created_at: Generated<Date>;
64
+ updated_at: Generated<Date>;
65
+ }
66
+ interface SubgraphGapsTable {
67
+ id: Generated<string>;
68
+ subgraph_id: string;
69
+ subgraph_name: string;
70
+ gap_start: number;
71
+ gap_end: number;
72
+ reason: string;
73
+ detected_at: Generated<Date>;
74
+ resolved_at: Date | null;
75
+ }
76
+ type SubgraphOperationKind = "reindex" | "backfill";
77
+ type SubgraphOperationStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
78
+ interface SubgraphOperationsTable {
79
+ id: Generated<string>;
80
+ subgraph_id: string;
81
+ subgraph_name: string;
82
+ account_id: string | null;
83
+ kind: ColumnType<SubgraphOperationKind, SubgraphOperationKind, SubgraphOperationKind>;
84
+ status: ColumnType<SubgraphOperationStatus, SubgraphOperationStatus | undefined, SubgraphOperationStatus>;
85
+ from_block: number | null;
86
+ to_block: number | null;
87
+ cancel_requested: Generated<boolean>;
88
+ locked_by: string | null;
89
+ locked_until: Date | null;
90
+ started_at: Date | null;
91
+ finished_at: Date | null;
92
+ processed_blocks: number | null;
93
+ error: string | null;
94
+ created_at: Generated<Date>;
95
+ updated_at: Generated<Date>;
96
+ }
97
+ interface ApiKeysTable {
98
+ id: Generated<string>;
99
+ key_hash: string;
100
+ key_prefix: string;
101
+ name: string | null;
102
+ status: Generated<string>;
103
+ rate_limit: Generated<number>;
104
+ ip_address: string;
105
+ account_id: string;
106
+ product: Generated<"account" | "streams" | "index">;
107
+ tier: "free" | "build" | "scale" | "enterprise" | null;
108
+ last_used_at: Date | null;
109
+ revoked_at: Date | null;
110
+ created_at: Generated<Date>;
111
+ }
112
+ interface AccountsTable {
113
+ id: Generated<string>;
114
+ email: string;
115
+ plan: Generated<string>;
116
+ display_name: string | null;
117
+ bio: string | null;
118
+ avatar_url: string | null;
119
+ slug: string | null;
120
+ stripe_customer_id: string | null;
121
+ created_at: Generated<Date>;
122
+ }
123
+ interface SessionsTable {
124
+ id: Generated<string>;
125
+ token_hash: string;
126
+ token_prefix: string;
127
+ account_id: string;
128
+ ip_address: string;
129
+ expires_at: Generated<Date>;
130
+ revoked_at: Date | null;
131
+ last_used_at: Date | null;
132
+ created_at: Generated<Date>;
133
+ }
134
+ interface MagicLinksTable {
135
+ id: Generated<string>;
136
+ email: string;
137
+ token: string;
138
+ code: string | null;
139
+ expires_at: Date;
140
+ used_at: Date | null;
141
+ failed_attempts: Generated<number>;
142
+ created_at: Generated<Date>;
143
+ }
144
+ interface UsageDailyTable {
145
+ account_id: string;
146
+ tenant_id: string | null;
147
+ date: string;
148
+ api_requests: Generated<number>;
149
+ deliveries: Generated<number>;
150
+ streams_events_returned: Generated<number>;
151
+ index_decoded_events_returned: Generated<number>;
152
+ }
153
+ interface UsageSnapshotsTable {
154
+ id: Generated<string>;
155
+ account_id: string;
156
+ measured_at: Generated<Date>;
157
+ storage_bytes: Generated<number>;
158
+ }
159
+ interface WaitlistTable {
160
+ id: Generated<string>;
161
+ email: string;
162
+ source: Generated<string>;
163
+ status: Generated<string>;
164
+ created_at: Generated<Date>;
165
+ }
166
+ interface AccountInsightsTable {
167
+ id: Generated<string>;
168
+ account_id: string;
169
+ category: string;
170
+ insight_type: string;
171
+ resource_id: string | null;
172
+ severity: string;
173
+ title: string;
174
+ body: string;
175
+ data: unknown;
176
+ dismissed_at: Date | null;
177
+ expires_at: Date | null;
178
+ created_at: Generated<Date>;
179
+ }
180
+ interface AccountAgentRunsTable {
181
+ id: Generated<string>;
182
+ account_id: string;
183
+ started_at: Generated<Date>;
184
+ completed_at: Date | null;
185
+ status: Generated<string>;
186
+ input_tokens: Generated<number>;
187
+ output_tokens: Generated<number>;
188
+ cost_usd: Generated<number>;
189
+ insights_created: Generated<number>;
190
+ error: string | null;
191
+ }
192
+ interface SubgraphProcessingStatsTable {
193
+ id: Generated<string>;
194
+ subgraph_name: string;
195
+ api_key_id: string | null;
196
+ bucket_start: Date | null;
197
+ bucket_end: Date | null;
198
+ blocks_processed: number | null;
199
+ total_time_ms: number | null;
200
+ handler_time_ms: number | null;
201
+ flush_time_ms: number | null;
202
+ max_block_time_ms: number | null;
203
+ max_handler_time_ms: number | null;
204
+ avg_ops_per_block: number | null;
205
+ is_catchup: Generated<boolean>;
206
+ created_at: Generated<Date>;
207
+ }
208
+ interface SubgraphTableSnapshotsTable {
209
+ id: Generated<string>;
210
+ subgraph_name: string;
211
+ api_key_id: string | null;
212
+ table_name: string;
213
+ row_count: number | null;
214
+ created_at: Generated<Date>;
215
+ }
216
+ interface SubgraphHealthSnapshotsTable {
217
+ id: Generated<string>;
218
+ subgraph_id: string;
219
+ total_processed: number;
220
+ total_errors: number;
221
+ last_processed_block: number | null;
222
+ captured_at: Generated<Date>;
223
+ }
224
+ interface SubgraphUsageDailyTable {
225
+ subgraph_id: string;
226
+ date: string;
227
+ query_count: Generated<number>;
228
+ }
229
+ interface ProjectsTable {
230
+ id: Generated<string>;
231
+ name: string;
232
+ slug: string;
233
+ account_id: string;
234
+ settings: Generated<Record<string, unknown>>;
235
+ network: Generated<string>;
236
+ node_rpc: string | null;
237
+ created_at: Generated<Date>;
238
+ updated_at: Generated<Date>;
239
+ }
240
+ interface TeamMembersTable {
241
+ id: Generated<string>;
242
+ project_id: string;
243
+ account_id: string;
244
+ role: Generated<string>;
245
+ invited_by: string | null;
246
+ created_at: Generated<Date>;
247
+ }
248
+ interface TeamInvitationsTable {
249
+ id: Generated<string>;
250
+ project_id: string;
251
+ email: string;
252
+ role: Generated<string>;
253
+ token: string;
254
+ invited_by: string | null;
255
+ expires_at: Date;
256
+ accepted_at: Date | null;
257
+ created_at: Generated<Date>;
258
+ }
259
+ interface ChatSessionsTable {
260
+ id: Generated<string>;
261
+ account_id: string;
262
+ title: string | null;
263
+ summary: unknown | null;
264
+ created_at: Generated<Date>;
265
+ updated_at: Generated<Date>;
266
+ }
267
+ interface ChatMessagesTable {
268
+ id: Generated<string>;
269
+ chat_session_id: string;
270
+ role: string;
271
+ parts: unknown;
272
+ metadata: unknown | null;
273
+ created_at: Generated<Date>;
274
+ }
275
+ interface ProcessedStripeEventsTable {
276
+ event_id: string;
277
+ event_type: string;
278
+ processed_at: Generated<Date>;
279
+ }
280
+ interface DecodedEventsTable {
281
+ cursor: string;
282
+ block_height: number;
283
+ tx_id: string;
284
+ tx_index: number;
285
+ event_index: number;
286
+ event_type: string;
287
+ microblock_hash: string | null;
288
+ canonical: Generated<boolean>;
289
+ contract_id: string | null;
290
+ sender: string | null;
291
+ recipient: string | null;
292
+ amount: string | null;
293
+ asset_identifier: string | null;
294
+ value: string | null;
295
+ memo: string | null;
296
+ source_cursor: string;
297
+ created_at: Generated<Date>;
298
+ }
299
+ interface L2DecoderCheckpointsTable {
300
+ decoder_name: string;
301
+ last_cursor: string | null;
302
+ updated_at: Generated<Date>;
303
+ }
304
+ interface ChainReorgsTable {
305
+ id: Generated<string>;
306
+ detected_at: Generated<Date>;
307
+ fork_point_height: number;
308
+ old_index_block_hash: string | null;
309
+ new_index_block_hash: string | null;
310
+ orphaned_from_height: number;
311
+ orphaned_from_event_index: number;
312
+ orphaned_to_height: number;
313
+ orphaned_to_event_index: number;
314
+ new_canonical_height: number;
315
+ new_canonical_event_index: number;
316
+ created_at: Generated<Date>;
317
+ }
318
+ interface Database {
319
+ blocks: BlocksTable;
320
+ transactions: TransactionsTable;
321
+ events: EventsTable;
322
+ index_progress: IndexProgressTable;
323
+ subgraphs: SubgraphsTable;
324
+ api_keys: ApiKeysTable;
325
+ accounts: AccountsTable;
326
+ sessions: SessionsTable;
327
+ magic_links: MagicLinksTable;
328
+ usage_daily: UsageDailyTable;
329
+ usage_snapshots: UsageSnapshotsTable;
330
+ waitlist: WaitlistTable;
331
+ account_insights: AccountInsightsTable;
332
+ account_agent_runs: AccountAgentRunsTable;
333
+ subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
334
+ subgraph_processing_stats: SubgraphProcessingStatsTable;
335
+ subgraph_table_snapshots: SubgraphTableSnapshotsTable;
336
+ subgraph_gaps: SubgraphGapsTable;
337
+ subgraph_operations: SubgraphOperationsTable;
338
+ subgraph_usage_daily: SubgraphUsageDailyTable;
339
+ projects: ProjectsTable;
340
+ team_members: TeamMembersTable;
341
+ team_invitations: TeamInvitationsTable;
342
+ chat_sessions: ChatSessionsTable;
343
+ chat_messages: ChatMessagesTable;
344
+ processed_stripe_events: ProcessedStripeEventsTable;
345
+ tenants: TenantsTable;
346
+ tenant_usage_monthly: TenantUsageMonthlyTable;
347
+ tenant_compute_addons: TenantComputeAddonsTable;
348
+ account_spend_caps: AccountSpendCapsTable;
349
+ provisioning_audit_log: ProvisioningAuditLogTable;
350
+ subscriptions: SubscriptionsTable;
351
+ subscription_outbox: SubscriptionOutboxTable;
352
+ subscription_deliveries: SubscriptionDeliveriesTable;
353
+ decoded_events: DecodedEventsTable;
354
+ l2_decoder_checkpoints: L2DecoderCheckpointsTable;
355
+ chain_reorgs: ChainReorgsTable;
356
+ }
357
+ type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
358
+ interface TenantsTable {
359
+ id: Generated<string>;
360
+ account_id: string;
361
+ slug: string;
362
+ status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
363
+ plan: string;
364
+ cpus: ColumnType<number, number | string, number | string>;
365
+ memory_mb: number;
366
+ storage_limit_mb: number;
367
+ storage_used_mb: number | null;
368
+ pg_container_id: string | null;
369
+ api_container_id: string | null;
370
+ processor_container_id: string | null;
371
+ target_database_url_enc: Buffer;
372
+ tenant_jwt_secret_enc: Buffer;
373
+ anon_key_enc: Buffer;
374
+ service_key_enc: Buffer;
375
+ api_url_internal: string;
376
+ api_url_public: string;
377
+ suspended_at: Date | null;
378
+ last_health_check_at: Date | null;
379
+ last_active_at: Generated<Date>;
380
+ service_gen: Generated<number>;
381
+ anon_gen: Generated<number>;
382
+ project_id: string | null;
383
+ created_at: Generated<Date>;
384
+ updated_at: Generated<Date>;
385
+ }
386
+ interface TenantUsageMonthlyTable {
387
+ id: Generated<string>;
388
+ tenant_id: string;
389
+ period_month: Date;
390
+ storage_peak_mb: Generated<number>;
391
+ storage_avg_mb: Generated<number>;
392
+ storage_last_mb: Generated<number>;
393
+ measurements: Generated<number>;
394
+ first_at: Generated<Date>;
395
+ last_at: Generated<Date>;
396
+ }
397
+ interface TenantComputeAddonsTable {
398
+ id: Generated<string>;
399
+ tenant_id: string;
400
+ memory_mb_delta: Generated<number>;
401
+ cpu_delta: Generated<number | string>;
402
+ storage_mb_delta: Generated<number>;
403
+ effective_from: Generated<Date>;
404
+ effective_until: Date | null;
405
+ stripe_subscription_item_id: string | null;
406
+ created_at: Generated<Date>;
407
+ }
408
+ interface AccountSpendCapsTable {
409
+ account_id: string;
410
+ monthly_cap_cents: number | null;
411
+ compute_cap_cents: number | null;
412
+ storage_cap_cents: number | null;
413
+ alert_threshold_pct: Generated<number>;
414
+ alert_sent_at: Date | null;
415
+ frozen_at: Date | null;
416
+ updated_at: Generated<Date>;
417
+ }
418
+ type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
419
+ type ProvisioningAuditStatus = "ok" | "error";
420
+ interface ProvisioningAuditLogTable {
421
+ id: Generated<string>;
422
+ tenant_id: string | null;
423
+ tenant_slug: string | null;
424
+ account_id: string | null;
425
+ actor: string;
426
+ event: ProvisioningAuditEvent;
427
+ status: ProvisioningAuditStatus;
428
+ detail: unknown | null;
429
+ error: string | null;
430
+ created_at: Generated<Date>;
431
+ }
432
+ type SubscriptionStatus = "active" | "paused" | "error";
433
+ type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
434
+ type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
435
+ interface SubscriptionsTable {
436
+ id: Generated<string>;
437
+ account_id: string;
438
+ project_id: string | null;
439
+ name: string;
440
+ status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
441
+ subgraph_name: string;
442
+ table_name: string;
443
+ filter: Generated<unknown>;
444
+ format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
445
+ runtime: SubscriptionRuntime | null;
446
+ url: string;
447
+ signing_secret_enc: Buffer;
448
+ auth_config: Generated<unknown>;
449
+ max_retries: Generated<number>;
450
+ timeout_ms: Generated<number>;
451
+ concurrency: Generated<number>;
452
+ circuit_failures: Generated<number>;
453
+ circuit_opened_at: Date | null;
454
+ last_delivery_at: Date | null;
455
+ last_success_at: Date | null;
456
+ last_error: string | null;
457
+ created_at: Generated<Date>;
458
+ updated_at: Generated<Date>;
459
+ }
460
+ type OutboxStatus = "pending" | "delivered" | "dead";
461
+ interface SubscriptionOutboxTable {
462
+ id: Generated<string>;
463
+ subscription_id: string;
464
+ subgraph_name: string;
465
+ table_name: string;
466
+ block_height: number | bigint;
467
+ tx_id: string | null;
468
+ row_pk: unknown;
469
+ event_type: string;
470
+ payload: unknown;
471
+ dedup_key: string;
472
+ attempt: Generated<number>;
473
+ next_attempt_at: Generated<Date>;
474
+ status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
475
+ is_replay: Generated<boolean>;
476
+ delivered_at: Date | null;
477
+ failed_at: Date | null;
478
+ locked_by: string | null;
479
+ locked_until: Date | null;
480
+ created_at: Generated<Date>;
481
+ }
482
+ interface SubscriptionDeliveriesTable {
483
+ id: Generated<string>;
484
+ outbox_id: string;
485
+ subscription_id: string;
486
+ attempt: number;
487
+ status_code: number | null;
488
+ response_headers: unknown | null;
489
+ response_body: string | null;
490
+ error_message: string | null;
491
+ duration_ms: number | null;
492
+ dispatched_at: Generated<Date>;
493
+ }
494
+ import { Kysely, Transaction as Transaction2 } from "kysely";
495
+ type ChainReorgCursor = {
496
+ block_height: number
497
+ event_index: number
498
+ };
499
+ type ChainReorgRecord = {
500
+ id: string
501
+ detected_at: string
502
+ fork_point_height: number
503
+ old_index_block_hash: string | null
504
+ new_index_block_hash: string | null
505
+ orphaned_range: {
506
+ from: string
507
+ to: string
508
+ }
509
+ new_canonical_tip: string
510
+ };
511
+ type InsertChainReorgParams = {
512
+ forkPointHeight: number
513
+ oldIndexBlockHash?: string | null
514
+ newIndexBlockHash?: string | null
515
+ orphanedFrom: ChainReorgCursor
516
+ orphanedTo: ChainReorgCursor
517
+ newCanonicalTip: ChainReorgCursor
518
+ db?: Kysely<Database> | Transaction2<Database>
519
+ };
520
+ type ReadChainReorgsSinceParams = {
521
+ since: Date | ChainReorgCursor
522
+ limit: number
523
+ db?: Kysely<Database>
524
+ };
525
+ type ReadChainReorgsForRangeParams = {
526
+ from: ChainReorgCursor
527
+ to: ChainReorgCursor
528
+ db?: Kysely<Database>
529
+ };
530
+ declare function encodeChainReorgCursor(cursor: ChainReorgCursor): string;
531
+ declare function insertChainReorg(params: InsertChainReorgParams): Promise<ChainReorgRecord>;
532
+ declare function readChainReorgsSince(params: ReadChainReorgsSinceParams): Promise<ChainReorgRecord[]>;
533
+ declare function readChainReorgsForRange(params: ReadChainReorgsForRangeParams): Promise<ChainReorgRecord[]>;
534
+ export { readChainReorgsSince, readChainReorgsForRange, insertChainReorg, encodeChainReorgCursor, ReadChainReorgsSinceParams, ReadChainReorgsForRangeParams, InsertChainReorgParams, ChainReorgRecord, ChainReorgCursor };