@secondlayer/shared 1.1.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/db/index.d.ts +89 -6
- package/dist/src/db/index.js +53 -29
- package/dist/src/db/index.js.map +4 -4
- package/dist/src/db/jsonb.js.map +2 -2
- package/dist/src/db/queries/accounts.d.ts +58 -2
- package/dist/src/db/queries/integrity.d.ts +58 -2
- package/dist/src/db/queries/projects.d.ts +58 -2
- package/dist/src/db/queries/projects.js.map +2 -2
- package/dist/src/db/queries/{marketplace.d.ts → provisioning-audit.d.ts} +79 -56
- package/dist/src/db/queries/provisioning-audit.js +40 -0
- package/dist/src/db/queries/provisioning-audit.js.map +10 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +58 -2
- package/dist/src/db/queries/subgraphs.d.ts +62 -5
- package/dist/src/db/queries/subgraphs.js +3 -9
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/tenants.d.ts +527 -0
- package/dist/src/db/queries/tenants.js +220 -0
- package/dist/src/db/queries/tenants.js.map +11 -0
- package/dist/src/db/queries/usage.d.ts +58 -2
- package/dist/src/db/queries/usage.js +3 -3
- package/dist/src/db/queries/usage.js.map +3 -3
- package/dist/src/db/queries/workflows.d.ts +58 -2
- package/dist/src/db/queries/workflows.js +31 -3
- package/dist/src/db/queries/workflows.js.map +4 -4
- package/dist/src/db/schema.d.ts +67 -3
- package/dist/src/env.d.ts +10 -0
- package/dist/src/env.js +3 -1
- package/dist/src/env.js.map +3 -3
- package/dist/src/errors.d.ts +17 -3
- package/dist/src/errors.js +34 -3
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index.d.ts +142 -84
- package/dist/src/index.js +146 -99
- package/dist/src/index.js.map +8 -8
- package/dist/src/logger.js +3 -1
- package/dist/src/logger.js.map +3 -3
- package/dist/src/mode.d.ts +29 -0
- package/dist/src/mode.js +43 -0
- package/dist/src/mode.js.map +10 -0
- package/dist/src/node/archive-client.js +3 -1
- package/dist/src/node/archive-client.js.map +3 -3
- package/dist/src/node/hiro-client.js +3 -1
- package/dist/src/node/hiro-client.js.map +3 -3
- package/dist/src/node/local-client.d.ts +58 -2
- package/dist/src/queue/listener.d.ts +11 -2
- package/dist/src/queue/listener.js +11 -12
- package/dist/src/queue/listener.js.map +3 -3
- package/dist/src/schemas/accounts.d.ts +14 -0
- package/dist/src/schemas/{marketplace.js → accounts.js} +4 -14
- package/dist/src/schemas/accounts.js.map +10 -0
- package/dist/src/schemas/index.d.ts +28 -77
- package/dist/src/schemas/index.js +59 -69
- package/dist/src/schemas/index.js.map +4 -4
- package/dist/src/types.d.ts +10 -0
- package/migrations/0037_nullable_api_key.ts +35 -0
- package/migrations/0038_drop_workflow_tables.ts +46 -0
- package/migrations/0039_tenants.ts +66 -0
- package/migrations/0040_tenant_key_generations.ts +29 -0
- package/migrations/0041_subgraphs_drop_api_key_id.ts +49 -0
- package/migrations/0042_tenant_project_id.ts +25 -0
- package/migrations/0043_tenant_usage_monthly.ts +36 -0
- package/migrations/0044_provisioning_audit_log.ts +40 -0
- package/package.json +15 -7
- package/dist/src/db/queries/marketplace.js +0 -142
- package/dist/src/db/queries/marketplace.js.map +0 -10
- package/dist/src/schemas/marketplace.d.ts +0 -63
- package/dist/src/schemas/marketplace.js.map +0 -10
|
@@ -0,0 +1,527 @@
|
|
|
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
|
+
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
|
+
is_public: Generated<boolean>;
|
|
64
|
+
tags: Generated<string[]>;
|
|
65
|
+
description: string | null;
|
|
66
|
+
forked_from_id: string | null;
|
|
67
|
+
created_at: Generated<Date>;
|
|
68
|
+
updated_at: Generated<Date>;
|
|
69
|
+
}
|
|
70
|
+
interface SubgraphGapsTable {
|
|
71
|
+
id: Generated<string>;
|
|
72
|
+
subgraph_id: string;
|
|
73
|
+
subgraph_name: string;
|
|
74
|
+
gap_start: number;
|
|
75
|
+
gap_end: number;
|
|
76
|
+
reason: string;
|
|
77
|
+
detected_at: Generated<Date>;
|
|
78
|
+
resolved_at: Date | null;
|
|
79
|
+
}
|
|
80
|
+
interface ApiKeysTable {
|
|
81
|
+
id: Generated<string>;
|
|
82
|
+
key_hash: string;
|
|
83
|
+
key_prefix: string;
|
|
84
|
+
name: string | null;
|
|
85
|
+
status: Generated<string>;
|
|
86
|
+
rate_limit: Generated<number>;
|
|
87
|
+
ip_address: string;
|
|
88
|
+
account_id: string;
|
|
89
|
+
last_used_at: Date | null;
|
|
90
|
+
revoked_at: Date | null;
|
|
91
|
+
created_at: Generated<Date>;
|
|
92
|
+
}
|
|
93
|
+
interface AccountsTable {
|
|
94
|
+
id: Generated<string>;
|
|
95
|
+
email: string;
|
|
96
|
+
plan: Generated<string>;
|
|
97
|
+
display_name: string | null;
|
|
98
|
+
bio: string | null;
|
|
99
|
+
avatar_url: string | null;
|
|
100
|
+
slug: string | null;
|
|
101
|
+
created_at: Generated<Date>;
|
|
102
|
+
}
|
|
103
|
+
interface SessionsTable {
|
|
104
|
+
id: Generated<string>;
|
|
105
|
+
token_hash: string;
|
|
106
|
+
token_prefix: string;
|
|
107
|
+
account_id: string;
|
|
108
|
+
ip_address: string;
|
|
109
|
+
expires_at: Generated<Date>;
|
|
110
|
+
revoked_at: Date | null;
|
|
111
|
+
last_used_at: Date | null;
|
|
112
|
+
created_at: Generated<Date>;
|
|
113
|
+
}
|
|
114
|
+
interface MagicLinksTable {
|
|
115
|
+
id: Generated<string>;
|
|
116
|
+
email: string;
|
|
117
|
+
token: string;
|
|
118
|
+
code: string | null;
|
|
119
|
+
expires_at: Date;
|
|
120
|
+
used_at: Date | null;
|
|
121
|
+
failed_attempts: Generated<number>;
|
|
122
|
+
created_at: Generated<Date>;
|
|
123
|
+
}
|
|
124
|
+
interface UsageDailyTable {
|
|
125
|
+
account_id: string;
|
|
126
|
+
date: string;
|
|
127
|
+
api_requests: Generated<number>;
|
|
128
|
+
deliveries: Generated<number>;
|
|
129
|
+
}
|
|
130
|
+
interface UsageSnapshotsTable {
|
|
131
|
+
id: Generated<string>;
|
|
132
|
+
account_id: string;
|
|
133
|
+
measured_at: Generated<Date>;
|
|
134
|
+
storage_bytes: Generated<number>;
|
|
135
|
+
}
|
|
136
|
+
interface WaitlistTable {
|
|
137
|
+
id: Generated<string>;
|
|
138
|
+
email: string;
|
|
139
|
+
source: Generated<string>;
|
|
140
|
+
status: Generated<string>;
|
|
141
|
+
created_at: Generated<Date>;
|
|
142
|
+
}
|
|
143
|
+
interface AccountInsightsTable {
|
|
144
|
+
id: Generated<string>;
|
|
145
|
+
account_id: string;
|
|
146
|
+
category: string;
|
|
147
|
+
insight_type: string;
|
|
148
|
+
resource_id: string | null;
|
|
149
|
+
severity: string;
|
|
150
|
+
title: string;
|
|
151
|
+
body: string;
|
|
152
|
+
data: unknown;
|
|
153
|
+
dismissed_at: Date | null;
|
|
154
|
+
expires_at: Date | null;
|
|
155
|
+
created_at: Generated<Date>;
|
|
156
|
+
}
|
|
157
|
+
interface AccountAgentRunsTable {
|
|
158
|
+
id: Generated<string>;
|
|
159
|
+
account_id: string;
|
|
160
|
+
started_at: Generated<Date>;
|
|
161
|
+
completed_at: Date | null;
|
|
162
|
+
status: Generated<string>;
|
|
163
|
+
input_tokens: Generated<number>;
|
|
164
|
+
output_tokens: Generated<number>;
|
|
165
|
+
cost_usd: Generated<number>;
|
|
166
|
+
insights_created: Generated<number>;
|
|
167
|
+
error: string | null;
|
|
168
|
+
}
|
|
169
|
+
interface SubgraphProcessingStatsTable {
|
|
170
|
+
id: Generated<string>;
|
|
171
|
+
subgraph_name: string;
|
|
172
|
+
api_key_id: string | null;
|
|
173
|
+
bucket_start: Date | null;
|
|
174
|
+
bucket_end: Date | null;
|
|
175
|
+
blocks_processed: number | null;
|
|
176
|
+
total_time_ms: number | null;
|
|
177
|
+
handler_time_ms: number | null;
|
|
178
|
+
flush_time_ms: number | null;
|
|
179
|
+
max_block_time_ms: number | null;
|
|
180
|
+
max_handler_time_ms: number | null;
|
|
181
|
+
avg_ops_per_block: number | null;
|
|
182
|
+
is_catchup: Generated<boolean>;
|
|
183
|
+
created_at: Generated<Date>;
|
|
184
|
+
}
|
|
185
|
+
interface SubgraphTableSnapshotsTable {
|
|
186
|
+
id: Generated<string>;
|
|
187
|
+
subgraph_name: string;
|
|
188
|
+
api_key_id: string | null;
|
|
189
|
+
table_name: string;
|
|
190
|
+
row_count: number | null;
|
|
191
|
+
created_at: Generated<Date>;
|
|
192
|
+
}
|
|
193
|
+
interface SubgraphHealthSnapshotsTable {
|
|
194
|
+
id: Generated<string>;
|
|
195
|
+
subgraph_id: string;
|
|
196
|
+
total_processed: number;
|
|
197
|
+
total_errors: number;
|
|
198
|
+
last_processed_block: number | null;
|
|
199
|
+
captured_at: Generated<Date>;
|
|
200
|
+
}
|
|
201
|
+
interface SubgraphUsageDailyTable {
|
|
202
|
+
subgraph_id: string;
|
|
203
|
+
date: string;
|
|
204
|
+
query_count: Generated<number>;
|
|
205
|
+
}
|
|
206
|
+
interface ProjectsTable {
|
|
207
|
+
id: Generated<string>;
|
|
208
|
+
name: string;
|
|
209
|
+
slug: string;
|
|
210
|
+
account_id: string;
|
|
211
|
+
settings: Generated<Record<string, unknown>>;
|
|
212
|
+
network: Generated<string>;
|
|
213
|
+
node_rpc: string | null;
|
|
214
|
+
created_at: Generated<Date>;
|
|
215
|
+
updated_at: Generated<Date>;
|
|
216
|
+
}
|
|
217
|
+
interface TeamMembersTable {
|
|
218
|
+
id: Generated<string>;
|
|
219
|
+
project_id: string;
|
|
220
|
+
account_id: string;
|
|
221
|
+
role: Generated<string>;
|
|
222
|
+
invited_by: string | null;
|
|
223
|
+
created_at: Generated<Date>;
|
|
224
|
+
}
|
|
225
|
+
interface TeamInvitationsTable {
|
|
226
|
+
id: Generated<string>;
|
|
227
|
+
project_id: string;
|
|
228
|
+
email: string;
|
|
229
|
+
role: Generated<string>;
|
|
230
|
+
token: string;
|
|
231
|
+
invited_by: string | null;
|
|
232
|
+
expires_at: Date;
|
|
233
|
+
accepted_at: Date | null;
|
|
234
|
+
created_at: Generated<Date>;
|
|
235
|
+
}
|
|
236
|
+
interface ChatSessionsTable {
|
|
237
|
+
id: Generated<string>;
|
|
238
|
+
account_id: string;
|
|
239
|
+
title: string | null;
|
|
240
|
+
summary: unknown | null;
|
|
241
|
+
created_at: Generated<Date>;
|
|
242
|
+
updated_at: Generated<Date>;
|
|
243
|
+
}
|
|
244
|
+
interface ChatMessagesTable {
|
|
245
|
+
id: Generated<string>;
|
|
246
|
+
chat_session_id: string;
|
|
247
|
+
role: string;
|
|
248
|
+
parts: unknown;
|
|
249
|
+
metadata: unknown | null;
|
|
250
|
+
created_at: Generated<Date>;
|
|
251
|
+
}
|
|
252
|
+
interface WorkflowDefinitionsTable {
|
|
253
|
+
id: Generated<string>;
|
|
254
|
+
name: string;
|
|
255
|
+
version: Generated<string>;
|
|
256
|
+
status: Generated<string>;
|
|
257
|
+
trigger_type: string;
|
|
258
|
+
trigger_config: unknown;
|
|
259
|
+
handler_path: string;
|
|
260
|
+
source_code: string | null;
|
|
261
|
+
retries_config: unknown | null;
|
|
262
|
+
timeout_ms: number | null;
|
|
263
|
+
api_key_id: string;
|
|
264
|
+
project_id: string | null;
|
|
265
|
+
created_at: Generated<Date>;
|
|
266
|
+
updated_at: Generated<Date>;
|
|
267
|
+
}
|
|
268
|
+
interface WorkflowRunsTable {
|
|
269
|
+
id: Generated<string>;
|
|
270
|
+
definition_id: string;
|
|
271
|
+
status: Generated<string>;
|
|
272
|
+
trigger_type: string;
|
|
273
|
+
trigger_data: unknown | null;
|
|
274
|
+
dedup_key: string | null;
|
|
275
|
+
error: string | null;
|
|
276
|
+
started_at: Date | null;
|
|
277
|
+
completed_at: Date | null;
|
|
278
|
+
duration_ms: number | null;
|
|
279
|
+
total_ai_tokens: Generated<number>;
|
|
280
|
+
created_at: Generated<Date>;
|
|
281
|
+
}
|
|
282
|
+
interface WorkflowStepsTable {
|
|
283
|
+
id: Generated<string>;
|
|
284
|
+
run_id: string;
|
|
285
|
+
step_index: number;
|
|
286
|
+
step_id: string;
|
|
287
|
+
step_type: string;
|
|
288
|
+
status: Generated<string>;
|
|
289
|
+
input: unknown | null;
|
|
290
|
+
output: unknown | null;
|
|
291
|
+
error: string | null;
|
|
292
|
+
retry_count: Generated<number>;
|
|
293
|
+
ai_tokens_used: Generated<number>;
|
|
294
|
+
started_at: Date | null;
|
|
295
|
+
completed_at: Date | null;
|
|
296
|
+
duration_ms: number | null;
|
|
297
|
+
memo_key: string | null;
|
|
298
|
+
parent_step_id: string | null;
|
|
299
|
+
created_at: Generated<Date>;
|
|
300
|
+
}
|
|
301
|
+
interface WorkflowQueueTable {
|
|
302
|
+
id: Generated<string>;
|
|
303
|
+
run_id: string;
|
|
304
|
+
status: Generated<string>;
|
|
305
|
+
attempts: Generated<number>;
|
|
306
|
+
max_attempts: Generated<number>;
|
|
307
|
+
scheduled_for: Generated<Date>;
|
|
308
|
+
locked_at: Date | null;
|
|
309
|
+
locked_by: string | null;
|
|
310
|
+
error: string | null;
|
|
311
|
+
created_at: Generated<Date>;
|
|
312
|
+
completed_at: Date | null;
|
|
313
|
+
}
|
|
314
|
+
interface WorkflowSchedulesTable {
|
|
315
|
+
id: Generated<string>;
|
|
316
|
+
definition_id: string;
|
|
317
|
+
cron_expr: string;
|
|
318
|
+
timezone: Generated<string>;
|
|
319
|
+
next_run_at: Date;
|
|
320
|
+
last_run_at: Date | null;
|
|
321
|
+
enabled: Generated<boolean>;
|
|
322
|
+
created_at: Generated<Date>;
|
|
323
|
+
}
|
|
324
|
+
interface WorkflowCursorsTable {
|
|
325
|
+
name: string;
|
|
326
|
+
block_height: Generated<number>;
|
|
327
|
+
updated_at: Generated<Date>;
|
|
328
|
+
}
|
|
329
|
+
interface Database {
|
|
330
|
+
blocks: BlocksTable;
|
|
331
|
+
transactions: TransactionsTable;
|
|
332
|
+
events: EventsTable;
|
|
333
|
+
index_progress: IndexProgressTable;
|
|
334
|
+
subgraphs: SubgraphsTable;
|
|
335
|
+
api_keys: ApiKeysTable;
|
|
336
|
+
accounts: AccountsTable;
|
|
337
|
+
sessions: SessionsTable;
|
|
338
|
+
magic_links: MagicLinksTable;
|
|
339
|
+
usage_daily: UsageDailyTable;
|
|
340
|
+
usage_snapshots: UsageSnapshotsTable;
|
|
341
|
+
waitlist: WaitlistTable;
|
|
342
|
+
account_insights: AccountInsightsTable;
|
|
343
|
+
account_agent_runs: AccountAgentRunsTable;
|
|
344
|
+
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
345
|
+
subgraph_processing_stats: SubgraphProcessingStatsTable;
|
|
346
|
+
subgraph_table_snapshots: SubgraphTableSnapshotsTable;
|
|
347
|
+
subgraph_gaps: SubgraphGapsTable;
|
|
348
|
+
subgraph_usage_daily: SubgraphUsageDailyTable;
|
|
349
|
+
projects: ProjectsTable;
|
|
350
|
+
team_members: TeamMembersTable;
|
|
351
|
+
team_invitations: TeamInvitationsTable;
|
|
352
|
+
chat_sessions: ChatSessionsTable;
|
|
353
|
+
chat_messages: ChatMessagesTable;
|
|
354
|
+
workflow_definitions: WorkflowDefinitionsTable;
|
|
355
|
+
workflow_runs: WorkflowRunsTable;
|
|
356
|
+
workflow_steps: WorkflowStepsTable;
|
|
357
|
+
workflow_queue: WorkflowQueueTable;
|
|
358
|
+
workflow_schedules: WorkflowSchedulesTable;
|
|
359
|
+
workflow_cursors: WorkflowCursorsTable;
|
|
360
|
+
workflow_signer_secrets: WorkflowSignerSecretsTable;
|
|
361
|
+
workflow_budgets: WorkflowBudgetsTable;
|
|
362
|
+
tenants: TenantsTable;
|
|
363
|
+
tenant_usage_monthly: TenantUsageMonthlyTable;
|
|
364
|
+
provisioning_audit_log: ProvisioningAuditLogTable;
|
|
365
|
+
}
|
|
366
|
+
type TenantStatus = "provisioning" | "active" | "suspended" | "error" | "deleted";
|
|
367
|
+
interface TenantsTable {
|
|
368
|
+
id: Generated<string>;
|
|
369
|
+
account_id: string;
|
|
370
|
+
slug: string;
|
|
371
|
+
status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
|
|
372
|
+
plan: string;
|
|
373
|
+
cpus: ColumnType<number, number | string, number | string>;
|
|
374
|
+
memory_mb: number;
|
|
375
|
+
storage_limit_mb: number;
|
|
376
|
+
storage_used_mb: number | null;
|
|
377
|
+
pg_container_id: string | null;
|
|
378
|
+
api_container_id: string | null;
|
|
379
|
+
processor_container_id: string | null;
|
|
380
|
+
target_database_url_enc: Buffer;
|
|
381
|
+
tenant_jwt_secret_enc: Buffer;
|
|
382
|
+
anon_key_enc: Buffer;
|
|
383
|
+
service_key_enc: Buffer;
|
|
384
|
+
api_url_internal: string;
|
|
385
|
+
api_url_public: string;
|
|
386
|
+
trial_ends_at: Date;
|
|
387
|
+
suspended_at: Date | null;
|
|
388
|
+
last_health_check_at: Date | null;
|
|
389
|
+
service_gen: Generated<number>;
|
|
390
|
+
anon_gen: Generated<number>;
|
|
391
|
+
project_id: string | null;
|
|
392
|
+
created_at: Generated<Date>;
|
|
393
|
+
updated_at: Generated<Date>;
|
|
394
|
+
}
|
|
395
|
+
type Tenant = Selectable<TenantsTable>;
|
|
396
|
+
interface TenantUsageMonthlyTable {
|
|
397
|
+
id: Generated<string>;
|
|
398
|
+
tenant_id: string;
|
|
399
|
+
period_month: Date;
|
|
400
|
+
storage_peak_mb: Generated<number>;
|
|
401
|
+
storage_avg_mb: Generated<number>;
|
|
402
|
+
storage_last_mb: Generated<number>;
|
|
403
|
+
measurements: Generated<number>;
|
|
404
|
+
first_at: Generated<Date>;
|
|
405
|
+
last_at: Generated<Date>;
|
|
406
|
+
}
|
|
407
|
+
type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
|
|
408
|
+
type ProvisioningAuditStatus = "ok" | "error";
|
|
409
|
+
interface ProvisioningAuditLogTable {
|
|
410
|
+
id: Generated<string>;
|
|
411
|
+
tenant_id: string | null;
|
|
412
|
+
tenant_slug: string | null;
|
|
413
|
+
account_id: string | null;
|
|
414
|
+
actor: string;
|
|
415
|
+
event: ProvisioningAuditEvent;
|
|
416
|
+
status: ProvisioningAuditStatus;
|
|
417
|
+
detail: unknown | null;
|
|
418
|
+
error: string | null;
|
|
419
|
+
created_at: Generated<Date>;
|
|
420
|
+
}
|
|
421
|
+
interface WorkflowBudgetsTable {
|
|
422
|
+
id: Generated<string>;
|
|
423
|
+
workflow_definition_id: string;
|
|
424
|
+
/** Period key: "daily:YYYY-MM-DD" | "weekly:YYYY-Www" | "per-run:<uuid>". */
|
|
425
|
+
period: string;
|
|
426
|
+
ai_usd_used: Generated<string>;
|
|
427
|
+
ai_tokens_used: Generated<string>;
|
|
428
|
+
chain_microstx_used: Generated<string>;
|
|
429
|
+
chain_tx_count: Generated<number>;
|
|
430
|
+
run_count: Generated<number>;
|
|
431
|
+
step_count: Generated<number>;
|
|
432
|
+
reset_at: Date;
|
|
433
|
+
created_at: Generated<Date>;
|
|
434
|
+
updated_at: Generated<Date>;
|
|
435
|
+
}
|
|
436
|
+
interface WorkflowSignerSecretsTable {
|
|
437
|
+
id: Generated<string>;
|
|
438
|
+
account_id: string;
|
|
439
|
+
name: string;
|
|
440
|
+
/** AES-GCM ciphertext bytes produced by the runner's KMS on write. */
|
|
441
|
+
encrypted_value: Buffer;
|
|
442
|
+
created_at: Generated<Date>;
|
|
443
|
+
updated_at: Generated<Date>;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Tenant registry queries. Encrypted columns are stored as `bytea` and
|
|
447
|
+
* transparently encrypted/decrypted via `encryptSecret`/`decryptSecret`.
|
|
448
|
+
*
|
|
449
|
+
* Never return decrypted values from listTenants — only `getTenantCredentials`
|
|
450
|
+
* surfaces plaintext, and only when explicitly called by a caller that
|
|
451
|
+
* needs to hand creds to a CLI or dashboard session.
|
|
452
|
+
*/
|
|
453
|
+
interface NewTenantInput {
|
|
454
|
+
accountId: string;
|
|
455
|
+
slug: string;
|
|
456
|
+
plan: string;
|
|
457
|
+
cpus: number;
|
|
458
|
+
memoryMb: number;
|
|
459
|
+
storageLimitMb: number;
|
|
460
|
+
pgContainerId: string;
|
|
461
|
+
apiContainerId: string;
|
|
462
|
+
processorContainerId: string;
|
|
463
|
+
targetDatabaseUrl: string;
|
|
464
|
+
tenantJwtSecret: string;
|
|
465
|
+
anonKey: string;
|
|
466
|
+
serviceKey: string;
|
|
467
|
+
apiUrlInternal: string;
|
|
468
|
+
apiUrlPublic: string;
|
|
469
|
+
trialEndsAt: Date;
|
|
470
|
+
projectId?: string;
|
|
471
|
+
}
|
|
472
|
+
declare function insertTenant(db: Kysely<Database>, input: NewTenantInput): Promise<Tenant>;
|
|
473
|
+
declare function getTenantByAccount(db: Kysely<Database>, accountId: string): Promise<Tenant | null>;
|
|
474
|
+
declare function getTenantBySlug(db: Kysely<Database>, slug: string): Promise<Tenant | null>;
|
|
475
|
+
declare function listTenantsByStatus(db: Kysely<Database>, status: TenantStatus): Promise<Tenant[]>;
|
|
476
|
+
declare function listExpiredTrials(db: Kysely<Database>, now?: Date): Promise<Tenant[]>;
|
|
477
|
+
declare function listSuspendedOlderThan(db: Kysely<Database>, olderThan: Date): Promise<Tenant[]>;
|
|
478
|
+
declare function setTenantStatus(db: Kysely<Database>, slug: string, status: TenantStatus): Promise<void>;
|
|
479
|
+
declare function recordHealthCheck(db: Kysely<Database>, slug: string, storageUsedMb: number | null): Promise<void>;
|
|
480
|
+
/**
|
|
481
|
+
* Record a storage measurement into the current calendar month's bucket.
|
|
482
|
+
* Maintains peak, running average, and the most recent value in a single
|
|
483
|
+
* upsert. Billing will consume this later; for now the table just gives
|
|
484
|
+
* us evidence of usage over time.
|
|
485
|
+
*/
|
|
486
|
+
declare function recordMonthlyUsage(db: Kysely<Database>, tenantId: string, storageMb: number): Promise<void>;
|
|
487
|
+
declare function updateTenantPlan(db: Kysely<Database>, slug: string, plan: string, cpus: number, memoryMb: number, storageLimitMb: number): Promise<void>;
|
|
488
|
+
type RotateType = "service" | "anon" | "both";
|
|
489
|
+
/**
|
|
490
|
+
* Bump the selected gen counter(s) by 1 and return the new values.
|
|
491
|
+
* Used by the key-rotate endpoint to force the tenant API to reject
|
|
492
|
+
* previously-issued tokens of the rotated role(s).
|
|
493
|
+
*/
|
|
494
|
+
declare function bumpTenantKeyGen(db: Kysely<Database>, slug: string, type: RotateType): Promise<{
|
|
495
|
+
serviceGen: number
|
|
496
|
+
anonGen: number
|
|
497
|
+
}>;
|
|
498
|
+
/**
|
|
499
|
+
* Replace the encrypted key columns after a successful rotate. Only the
|
|
500
|
+
* rotated column(s) are written — the other stays untouched.
|
|
501
|
+
*/
|
|
502
|
+
declare function updateTenantKeys(db: Kysely<Database>, slug: string, keys: {
|
|
503
|
+
serviceKey?: string
|
|
504
|
+
anonKey?: string
|
|
505
|
+
}): Promise<void>;
|
|
506
|
+
/**
|
|
507
|
+
* Hard-delete a tenant row. Call only AFTER the provisioner has torn down
|
|
508
|
+
* containers + volume; otherwise orphaned resources linger. Returns whether
|
|
509
|
+
* a row was actually deleted.
|
|
510
|
+
*/
|
|
511
|
+
declare function deleteTenant(db: Kysely<Database>, slug: string): Promise<boolean>;
|
|
512
|
+
interface TenantCredentials {
|
|
513
|
+
slug: string;
|
|
514
|
+
targetDatabaseUrl: string;
|
|
515
|
+
tenantJwtSecret: string;
|
|
516
|
+
anonKey: string;
|
|
517
|
+
serviceKey: string;
|
|
518
|
+
apiUrlInternal: string;
|
|
519
|
+
apiUrlPublic: string;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Decrypts the four encrypted columns and returns them plaintext. Call
|
|
523
|
+
* this only when surfacing credentials to an authorized caller (dashboard,
|
|
524
|
+
* CLI). Never log the returned object.
|
|
525
|
+
*/
|
|
526
|
+
declare function getTenantCredentials(db: Kysely<Database>, slug: string): Promise<TenantCredentials | null>;
|
|
527
|
+
export { updateTenantPlan, updateTenantKeys, setTenantStatus, recordMonthlyUsage, recordHealthCheck, listTenantsByStatus, listSuspendedOlderThan, listExpiredTrials, insertTenant, getTenantCredentials, getTenantBySlug, getTenantByAccount, deleteTenant, bumpTenantKeyGen, TenantCredentials, RotateType, NewTenantInput };
|