@perceo/supabase 0.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/index.d.ts +707 -0
- package/dist/index.js +809 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { SupabaseClient, RealtimeChannel } from '@supabase/supabase-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Perceo Supabase Database Types
|
|
5
|
+
* Auto-generated from database schema
|
|
6
|
+
*/
|
|
7
|
+
type UUID = string;
|
|
8
|
+
type Timestamp = string;
|
|
9
|
+
type ProjectRole = "owner" | "admin" | "member" | "viewer";
|
|
10
|
+
type FlowPriority = "critical" | "high" | "medium" | "low";
|
|
11
|
+
type TestStatus = "pending" | "running" | "passed" | "failed" | "error" | "skipped";
|
|
12
|
+
type TestTrigger = "pr" | "watch" | "manual" | "schedule" | "ci";
|
|
13
|
+
type InsightType = "discrepancy" | "coverage-gap" | "ux-issue" | "prediction" | "performance" | "regression";
|
|
14
|
+
type InsightSeverity = "critical" | "high" | "medium" | "low" | "info";
|
|
15
|
+
type InsightStatus = "open" | "acknowledged" | "in_progress" | "resolved" | "dismissed" | "false_positive";
|
|
16
|
+
type PredictionBasis = "ml-model" | "heuristic" | "pattern" | "historical";
|
|
17
|
+
type RiskLevel = "critical" | "high" | "medium" | "low";
|
|
18
|
+
type EventSource = "observer" | "coordinator" | "analyzer" | "analytics" | "cli" | "dashboard";
|
|
19
|
+
type AnalyticsProvider = "ga4" | "mixpanel" | "amplitude" | "posthog" | "custom";
|
|
20
|
+
type SyncStatus = "success" | "failed" | "partial";
|
|
21
|
+
type ApiKeyScope = "ci:analyze" | "ci:test" | "flows:read" | "flows:write" | "insights:read" | "events:publish" | "workflows:start";
|
|
22
|
+
interface Project {
|
|
23
|
+
id: UUID;
|
|
24
|
+
name: string;
|
|
25
|
+
framework: string | null;
|
|
26
|
+
config: Record<string, unknown>;
|
|
27
|
+
git_remote_url: string | null;
|
|
28
|
+
created_at: Timestamp;
|
|
29
|
+
updated_at: Timestamp;
|
|
30
|
+
}
|
|
31
|
+
interface ProjectMember {
|
|
32
|
+
project_id: UUID;
|
|
33
|
+
user_id: UUID;
|
|
34
|
+
role: ProjectRole;
|
|
35
|
+
created_at: Timestamp;
|
|
36
|
+
}
|
|
37
|
+
interface Persona {
|
|
38
|
+
id: UUID;
|
|
39
|
+
project_id: UUID;
|
|
40
|
+
name: string;
|
|
41
|
+
description: string | null;
|
|
42
|
+
behaviors: Record<string, unknown>;
|
|
43
|
+
source: "user_configured" | "auto_generated";
|
|
44
|
+
created_at: Timestamp;
|
|
45
|
+
updated_at: Timestamp;
|
|
46
|
+
}
|
|
47
|
+
interface Flow {
|
|
48
|
+
id: UUID;
|
|
49
|
+
project_id: UUID;
|
|
50
|
+
persona_id: UUID | null;
|
|
51
|
+
name: string;
|
|
52
|
+
description: string | null;
|
|
53
|
+
priority: FlowPriority;
|
|
54
|
+
entry_point: string | null;
|
|
55
|
+
graph_data: Record<string, unknown>;
|
|
56
|
+
affected_by_changes: string[];
|
|
57
|
+
risk_score: number;
|
|
58
|
+
coverage_score: number | null;
|
|
59
|
+
is_active: boolean;
|
|
60
|
+
created_at: Timestamp;
|
|
61
|
+
updated_at: Timestamp;
|
|
62
|
+
}
|
|
63
|
+
interface StepAction {
|
|
64
|
+
type: "click" | "fill" | "navigate" | "wait" | "scroll" | "hover" | "assert" | "screenshot";
|
|
65
|
+
target?: string;
|
|
66
|
+
value?: string;
|
|
67
|
+
options?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
interface StepExpectedState {
|
|
70
|
+
url?: string;
|
|
71
|
+
visible?: string[];
|
|
72
|
+
hidden?: string[];
|
|
73
|
+
text?: Record<string, string>;
|
|
74
|
+
attributes?: Record<string, Record<string, string>>;
|
|
75
|
+
}
|
|
76
|
+
interface Step {
|
|
77
|
+
id: UUID;
|
|
78
|
+
flow_id: UUID;
|
|
79
|
+
sequence_order: number;
|
|
80
|
+
name: string;
|
|
81
|
+
actions: StepAction[];
|
|
82
|
+
expected_state: StepExpectedState;
|
|
83
|
+
timeout_ms: number;
|
|
84
|
+
retry_count: number;
|
|
85
|
+
next_step_id: UUID | null;
|
|
86
|
+
branch_config: {
|
|
87
|
+
condition: string;
|
|
88
|
+
trueStepId: UUID;
|
|
89
|
+
falseStepId: UUID;
|
|
90
|
+
} | null;
|
|
91
|
+
created_at: Timestamp;
|
|
92
|
+
updated_at: Timestamp;
|
|
93
|
+
}
|
|
94
|
+
interface FlowMetrics {
|
|
95
|
+
id: UUID;
|
|
96
|
+
flow_id: UUID;
|
|
97
|
+
synthetic_success_rate: number | null;
|
|
98
|
+
synthetic_avg_duration_ms: number | null;
|
|
99
|
+
synthetic_p50_duration_ms: number | null;
|
|
100
|
+
synthetic_p95_duration_ms: number | null;
|
|
101
|
+
synthetic_last_run: Timestamp | null;
|
|
102
|
+
synthetic_run_count: number;
|
|
103
|
+
prod_success_rate: number | null;
|
|
104
|
+
prod_daily_users: number | null;
|
|
105
|
+
prod_weekly_users: number | null;
|
|
106
|
+
prod_avg_duration_ms: number | null;
|
|
107
|
+
prod_top_exit_step: string | null;
|
|
108
|
+
prod_conversion_rate: number | null;
|
|
109
|
+
prod_device_breakdown: Record<string, number>;
|
|
110
|
+
prod_cohort_performance: Record<string, {
|
|
111
|
+
success_rate: number;
|
|
112
|
+
}>;
|
|
113
|
+
prod_last_updated: Timestamp | null;
|
|
114
|
+
gap_score: number | null;
|
|
115
|
+
updated_at: Timestamp;
|
|
116
|
+
}
|
|
117
|
+
interface TestRun {
|
|
118
|
+
id: UUID;
|
|
119
|
+
flow_id: UUID | null;
|
|
120
|
+
project_id: UUID;
|
|
121
|
+
status: TestStatus;
|
|
122
|
+
duration_ms: number | null;
|
|
123
|
+
error_message: string | null;
|
|
124
|
+
error_stack: string | null;
|
|
125
|
+
failed_step_id: UUID | null;
|
|
126
|
+
screenshots: string[];
|
|
127
|
+
video_url: string | null;
|
|
128
|
+
logs: unknown[];
|
|
129
|
+
triggered_by: TestTrigger | null;
|
|
130
|
+
pr_number: number | null;
|
|
131
|
+
commit_sha: string | null;
|
|
132
|
+
branch_name: string | null;
|
|
133
|
+
agent_id: string | null;
|
|
134
|
+
agent_type: string | null;
|
|
135
|
+
created_at: Timestamp;
|
|
136
|
+
started_at: Timestamp | null;
|
|
137
|
+
completed_at: Timestamp | null;
|
|
138
|
+
}
|
|
139
|
+
interface AnalyticsEvent {
|
|
140
|
+
id: UUID;
|
|
141
|
+
project_id: UUID;
|
|
142
|
+
event_type: string;
|
|
143
|
+
event_name: string | null;
|
|
144
|
+
user_id: string | null;
|
|
145
|
+
session_id: string | null;
|
|
146
|
+
anonymous_id: string | null;
|
|
147
|
+
flow_id: UUID | null;
|
|
148
|
+
flow_step: string | null;
|
|
149
|
+
flow_confidence: number | null;
|
|
150
|
+
url: string | null;
|
|
151
|
+
page_path: string | null;
|
|
152
|
+
referrer: string | null;
|
|
153
|
+
device_type: string | null;
|
|
154
|
+
browser: string | null;
|
|
155
|
+
os: string | null;
|
|
156
|
+
screen_resolution: string | null;
|
|
157
|
+
metadata: Record<string, unknown>;
|
|
158
|
+
provider: AnalyticsProvider | null;
|
|
159
|
+
provider_event_id: string | null;
|
|
160
|
+
created_at: Timestamp;
|
|
161
|
+
}
|
|
162
|
+
interface Insight {
|
|
163
|
+
id: UUID;
|
|
164
|
+
project_id: UUID;
|
|
165
|
+
flow_id: UUID | null;
|
|
166
|
+
type: InsightType;
|
|
167
|
+
severity: InsightSeverity;
|
|
168
|
+
title: string;
|
|
169
|
+
message: string;
|
|
170
|
+
suggested_action: string | null;
|
|
171
|
+
evidence: Record<string, unknown>;
|
|
172
|
+
revenue_impact: {
|
|
173
|
+
estimated_monthly_loss?: number;
|
|
174
|
+
confidence?: number;
|
|
175
|
+
affected_users?: number;
|
|
176
|
+
} | null;
|
|
177
|
+
status: InsightStatus;
|
|
178
|
+
resolved_by: UUID | null;
|
|
179
|
+
resolution_notes: string | null;
|
|
180
|
+
created_at: Timestamp;
|
|
181
|
+
acknowledged_at: Timestamp | null;
|
|
182
|
+
resolved_at: Timestamp | null;
|
|
183
|
+
}
|
|
184
|
+
interface Prediction {
|
|
185
|
+
id: UUID;
|
|
186
|
+
project_id: UUID;
|
|
187
|
+
flow_id: UUID;
|
|
188
|
+
pr_number: number | null;
|
|
189
|
+
commit_sha: string | null;
|
|
190
|
+
branch_name: string | null;
|
|
191
|
+
probability: number;
|
|
192
|
+
confidence: number;
|
|
193
|
+
reasoning: string | null;
|
|
194
|
+
based_on: PredictionBasis | null;
|
|
195
|
+
model_version: string | null;
|
|
196
|
+
features: Record<string, unknown>;
|
|
197
|
+
actual_result: TestStatus | null;
|
|
198
|
+
prediction_correct: boolean | null;
|
|
199
|
+
created_at: Timestamp;
|
|
200
|
+
validated_at: Timestamp | null;
|
|
201
|
+
}
|
|
202
|
+
interface PerceoEvent {
|
|
203
|
+
id: UUID;
|
|
204
|
+
project_id: UUID | null;
|
|
205
|
+
type: string;
|
|
206
|
+
payload: Record<string, unknown>;
|
|
207
|
+
source: EventSource | null;
|
|
208
|
+
processed: boolean;
|
|
209
|
+
processed_at: Timestamp | null;
|
|
210
|
+
created_at: Timestamp;
|
|
211
|
+
}
|
|
212
|
+
interface CodeChange {
|
|
213
|
+
id: UUID;
|
|
214
|
+
project_id: UUID;
|
|
215
|
+
base_sha: string;
|
|
216
|
+
head_sha: string;
|
|
217
|
+
branch_name: string | null;
|
|
218
|
+
pr_number: number | null;
|
|
219
|
+
files: {
|
|
220
|
+
path: string;
|
|
221
|
+
status: "added" | "modified" | "deleted" | "renamed";
|
|
222
|
+
additions?: number;
|
|
223
|
+
deletions?: number;
|
|
224
|
+
}[];
|
|
225
|
+
risk_level: RiskLevel | null;
|
|
226
|
+
risk_score: number | null;
|
|
227
|
+
affected_flow_ids: UUID[];
|
|
228
|
+
llm_analysis: {
|
|
229
|
+
summary?: string;
|
|
230
|
+
impacted_areas?: string[];
|
|
231
|
+
recommendations?: string[];
|
|
232
|
+
} | null;
|
|
233
|
+
created_at: Timestamp;
|
|
234
|
+
analyzed_at: Timestamp | null;
|
|
235
|
+
}
|
|
236
|
+
interface AnalyticsConnection {
|
|
237
|
+
id: UUID;
|
|
238
|
+
project_id: UUID;
|
|
239
|
+
provider: AnalyticsProvider;
|
|
240
|
+
provider_account_id: string | null;
|
|
241
|
+
config: Record<string, unknown>;
|
|
242
|
+
last_sync_at: Timestamp | null;
|
|
243
|
+
last_sync_status: SyncStatus | null;
|
|
244
|
+
last_sync_error: string | null;
|
|
245
|
+
events_synced_count: number;
|
|
246
|
+
sync_interval_seconds: number;
|
|
247
|
+
sync_enabled: boolean;
|
|
248
|
+
created_at: Timestamp;
|
|
249
|
+
updated_at: Timestamp;
|
|
250
|
+
}
|
|
251
|
+
interface ProjectApiKey {
|
|
252
|
+
id: UUID;
|
|
253
|
+
project_id: UUID;
|
|
254
|
+
name: string;
|
|
255
|
+
key_hash: string;
|
|
256
|
+
key_prefix: string;
|
|
257
|
+
scopes: ApiKeyScope[];
|
|
258
|
+
created_by: UUID | null;
|
|
259
|
+
created_at: Timestamp;
|
|
260
|
+
last_used_at: Timestamp | null;
|
|
261
|
+
last_used_ip: string | null;
|
|
262
|
+
expires_at: Timestamp | null;
|
|
263
|
+
revoked_at: Timestamp | null;
|
|
264
|
+
revoked_by: UUID | null;
|
|
265
|
+
revocation_reason: string | null;
|
|
266
|
+
}
|
|
267
|
+
interface ProjectApiKeyAudit {
|
|
268
|
+
id: UUID;
|
|
269
|
+
key_id: UUID;
|
|
270
|
+
action: "created" | "used" | "revoked" | "expired";
|
|
271
|
+
actor_id: UUID | null;
|
|
272
|
+
ip_address: string | null;
|
|
273
|
+
user_agent: string | null;
|
|
274
|
+
metadata: Record<string, unknown>;
|
|
275
|
+
created_at: Timestamp;
|
|
276
|
+
}
|
|
277
|
+
type ProjectInsert = Omit<Project, "id" | "created_at" | "updated_at"> & {
|
|
278
|
+
id?: UUID;
|
|
279
|
+
};
|
|
280
|
+
type PersonaInsert = Omit<Persona, "id" | "created_at" | "updated_at"> & {
|
|
281
|
+
id?: UUID;
|
|
282
|
+
behaviors?: Record<string, unknown>;
|
|
283
|
+
};
|
|
284
|
+
type FlowInsert = Omit<Flow, "id" | "created_at" | "updated_at" | "affected_by_changes" | "risk_score"> & {
|
|
285
|
+
id?: UUID;
|
|
286
|
+
affected_by_changes?: string[];
|
|
287
|
+
risk_score?: number;
|
|
288
|
+
graph_data?: Record<string, unknown>;
|
|
289
|
+
priority?: FlowPriority;
|
|
290
|
+
is_active?: boolean;
|
|
291
|
+
};
|
|
292
|
+
type StepInsert = Omit<Step, "id" | "created_at" | "updated_at"> & {
|
|
293
|
+
id?: UUID;
|
|
294
|
+
actions?: StepAction[];
|
|
295
|
+
expected_state?: StepExpectedState;
|
|
296
|
+
timeout_ms?: number;
|
|
297
|
+
retry_count?: number;
|
|
298
|
+
};
|
|
299
|
+
type TestRunInsert = Omit<TestRun, "id" | "created_at"> & {
|
|
300
|
+
id?: UUID;
|
|
301
|
+
screenshots?: string[];
|
|
302
|
+
logs?: unknown[];
|
|
303
|
+
};
|
|
304
|
+
type InsightInsert = Omit<Insight, "id" | "created_at" | "acknowledged_at" | "resolved_at"> & {
|
|
305
|
+
id?: UUID;
|
|
306
|
+
evidence?: Record<string, unknown>;
|
|
307
|
+
status?: InsightStatus;
|
|
308
|
+
};
|
|
309
|
+
type CodeChangeInsert = {
|
|
310
|
+
project_id: UUID;
|
|
311
|
+
base_sha: string;
|
|
312
|
+
head_sha: string;
|
|
313
|
+
files: {
|
|
314
|
+
path: string;
|
|
315
|
+
status: "added" | "modified" | "deleted" | "renamed";
|
|
316
|
+
additions?: number;
|
|
317
|
+
deletions?: number;
|
|
318
|
+
}[];
|
|
319
|
+
id?: UUID;
|
|
320
|
+
branch_name?: string | null;
|
|
321
|
+
pr_number?: number | null;
|
|
322
|
+
risk_level?: RiskLevel | null;
|
|
323
|
+
risk_score?: number | null;
|
|
324
|
+
affected_flow_ids?: UUID[];
|
|
325
|
+
llm_analysis?: {
|
|
326
|
+
summary?: string;
|
|
327
|
+
impacted_areas?: string[];
|
|
328
|
+
recommendations?: string[];
|
|
329
|
+
} | null;
|
|
330
|
+
};
|
|
331
|
+
type PerceoEventInsert = Omit<PerceoEvent, "id" | "created_at" | "processed" | "processed_at"> & {
|
|
332
|
+
id?: UUID;
|
|
333
|
+
};
|
|
334
|
+
type ProjectApiKeyInsert = {
|
|
335
|
+
project_id: UUID;
|
|
336
|
+
name: string;
|
|
337
|
+
key_hash: string;
|
|
338
|
+
key_prefix: string;
|
|
339
|
+
scopes: ApiKeyScope[];
|
|
340
|
+
created_by?: UUID | null;
|
|
341
|
+
expires_at?: Timestamp | null;
|
|
342
|
+
};
|
|
343
|
+
type ProjectApiKeyUpdate = {
|
|
344
|
+
name?: string;
|
|
345
|
+
scopes?: ApiKeyScope[];
|
|
346
|
+
expires_at?: Timestamp | null;
|
|
347
|
+
revoked_at?: Timestamp | null;
|
|
348
|
+
revoked_by?: UUID | null;
|
|
349
|
+
revocation_reason?: string | null;
|
|
350
|
+
};
|
|
351
|
+
type FlowUpdate = Partial<Omit<Flow, "id" | "project_id" | "created_at">>;
|
|
352
|
+
type TestRunUpdate = Partial<Omit<TestRun, "id" | "project_id" | "created_at">>;
|
|
353
|
+
type InsightUpdate = Partial<Omit<Insight, "id" | "project_id" | "created_at">>;
|
|
354
|
+
interface FlowWithSteps extends Flow {
|
|
355
|
+
steps: Step[];
|
|
356
|
+
}
|
|
357
|
+
interface FlowWithMetrics extends Flow {
|
|
358
|
+
metrics: FlowMetrics | null;
|
|
359
|
+
}
|
|
360
|
+
interface TestRunWithFlow extends TestRun {
|
|
361
|
+
flow: Flow | null;
|
|
362
|
+
}
|
|
363
|
+
interface InsightWithFlow extends Insight {
|
|
364
|
+
flow: Flow | null;
|
|
365
|
+
}
|
|
366
|
+
type RealtimeEventType = "INSERT" | "UPDATE" | "DELETE";
|
|
367
|
+
interface RealtimePayload<T> {
|
|
368
|
+
eventType: RealtimeEventType;
|
|
369
|
+
new: T;
|
|
370
|
+
old: T | null;
|
|
371
|
+
schema: string;
|
|
372
|
+
table: string;
|
|
373
|
+
commit_timestamp: string;
|
|
374
|
+
}
|
|
375
|
+
interface Database {
|
|
376
|
+
public: {
|
|
377
|
+
Tables: {
|
|
378
|
+
projects: {
|
|
379
|
+
Row: Project;
|
|
380
|
+
Insert: ProjectInsert;
|
|
381
|
+
Update: Partial<ProjectInsert>;
|
|
382
|
+
};
|
|
383
|
+
project_members: {
|
|
384
|
+
Row: ProjectMember;
|
|
385
|
+
Insert: Omit<ProjectMember, "created_at">;
|
|
386
|
+
Update: Partial<Omit<ProjectMember, "project_id" | "user_id" | "created_at">>;
|
|
387
|
+
};
|
|
388
|
+
personas: {
|
|
389
|
+
Row: Persona;
|
|
390
|
+
Insert: PersonaInsert;
|
|
391
|
+
Update: Partial<PersonaInsert>;
|
|
392
|
+
};
|
|
393
|
+
flows: {
|
|
394
|
+
Row: Flow;
|
|
395
|
+
Insert: FlowInsert;
|
|
396
|
+
Update: FlowUpdate;
|
|
397
|
+
};
|
|
398
|
+
steps: {
|
|
399
|
+
Row: Step;
|
|
400
|
+
Insert: StepInsert;
|
|
401
|
+
Update: Partial<StepInsert>;
|
|
402
|
+
};
|
|
403
|
+
flow_metrics: {
|
|
404
|
+
Row: FlowMetrics;
|
|
405
|
+
Insert: Omit<FlowMetrics, "id" | "updated_at">;
|
|
406
|
+
Update: Partial<Omit<FlowMetrics, "id" | "flow_id" | "updated_at">>;
|
|
407
|
+
};
|
|
408
|
+
test_runs: {
|
|
409
|
+
Row: TestRun;
|
|
410
|
+
Insert: TestRunInsert;
|
|
411
|
+
Update: TestRunUpdate;
|
|
412
|
+
};
|
|
413
|
+
analytics_events: {
|
|
414
|
+
Row: AnalyticsEvent;
|
|
415
|
+
Insert: Omit<AnalyticsEvent, "id" | "created_at">;
|
|
416
|
+
Update: never;
|
|
417
|
+
};
|
|
418
|
+
insights: {
|
|
419
|
+
Row: Insight;
|
|
420
|
+
Insert: InsightInsert;
|
|
421
|
+
Update: InsightUpdate;
|
|
422
|
+
};
|
|
423
|
+
predictions: {
|
|
424
|
+
Row: Prediction;
|
|
425
|
+
Insert: Omit<Prediction, "id" | "created_at" | "validated_at">;
|
|
426
|
+
Update: Partial<Omit<Prediction, "id" | "project_id" | "flow_id" | "created_at">>;
|
|
427
|
+
};
|
|
428
|
+
events: {
|
|
429
|
+
Row: PerceoEvent;
|
|
430
|
+
Insert: PerceoEventInsert;
|
|
431
|
+
Update: Partial<Omit<PerceoEvent, "id" | "created_at">>;
|
|
432
|
+
};
|
|
433
|
+
code_changes: {
|
|
434
|
+
Row: CodeChange;
|
|
435
|
+
Insert: CodeChangeInsert;
|
|
436
|
+
Update: Partial<Omit<CodeChange, "id" | "project_id" | "created_at">>;
|
|
437
|
+
};
|
|
438
|
+
analytics_connections: {
|
|
439
|
+
Row: AnalyticsConnection;
|
|
440
|
+
Insert: Omit<AnalyticsConnection, "id" | "created_at" | "updated_at">;
|
|
441
|
+
Update: Partial<Omit<AnalyticsConnection, "id" | "project_id" | "created_at">>;
|
|
442
|
+
};
|
|
443
|
+
project_api_keys: {
|
|
444
|
+
Row: ProjectApiKey;
|
|
445
|
+
Insert: ProjectApiKeyInsert;
|
|
446
|
+
Update: ProjectApiKeyUpdate;
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Perceo Supabase Data Client
|
|
454
|
+
*
|
|
455
|
+
* Provides typed CRUD operations and realtime subscriptions for all Perceo tables.
|
|
456
|
+
* This client is used by the Observer Engine, CLI, and Dashboard.
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
interface PerceoClientConfig {
|
|
460
|
+
supabaseUrl: string;
|
|
461
|
+
supabaseKey: string;
|
|
462
|
+
projectId?: string;
|
|
463
|
+
}
|
|
464
|
+
interface PerceoClientFromSupabaseConfig {
|
|
465
|
+
supabase: SupabaseClient;
|
|
466
|
+
projectId?: string;
|
|
467
|
+
}
|
|
468
|
+
declare class PerceoDataClient {
|
|
469
|
+
private readonly supabase;
|
|
470
|
+
private readonly projectId;
|
|
471
|
+
private channels;
|
|
472
|
+
constructor(config: PerceoClientConfig | PerceoClientFromSupabaseConfig);
|
|
473
|
+
/**
|
|
474
|
+
* Create a client from environment variables
|
|
475
|
+
*/
|
|
476
|
+
static fromEnv(projectId?: string): PerceoDataClient;
|
|
477
|
+
/**
|
|
478
|
+
* Create a client that uses a specific user session for auth.
|
|
479
|
+
* All queries made through this client will run as that user.
|
|
480
|
+
*/
|
|
481
|
+
static fromUserSession(params: {
|
|
482
|
+
supabaseUrl: string;
|
|
483
|
+
supabaseKey: string;
|
|
484
|
+
accessToken: string;
|
|
485
|
+
refreshToken: string;
|
|
486
|
+
projectId?: string;
|
|
487
|
+
}): Promise<PerceoDataClient>;
|
|
488
|
+
/**
|
|
489
|
+
* Get the underlying Supabase client (for advanced operations)
|
|
490
|
+
*/
|
|
491
|
+
getSupabaseClient(): SupabaseClient;
|
|
492
|
+
/**
|
|
493
|
+
* Alias for getSupabaseClient() for backward compatibility
|
|
494
|
+
*/
|
|
495
|
+
getClient(): SupabaseClient;
|
|
496
|
+
/**
|
|
497
|
+
* Store or update a project secret (LLM API keys, etc.)
|
|
498
|
+
* Only accessible with service role or by project admins
|
|
499
|
+
*/
|
|
500
|
+
upsertProjectSecret(projectId: UUID, keyName: string, value: string, createdBy?: UUID): Promise<UUID>;
|
|
501
|
+
/**
|
|
502
|
+
* Get a project secret (service role only)
|
|
503
|
+
* This is typically called by backend services, not by end users
|
|
504
|
+
*/
|
|
505
|
+
getProjectSecret(projectId: UUID, keyName: string): Promise<string | null>;
|
|
506
|
+
getProject(id: UUID): Promise<Project | null>;
|
|
507
|
+
getProjectByName(name: string): Promise<Project | null>;
|
|
508
|
+
createProject(project: ProjectInsert): Promise<Project>;
|
|
509
|
+
upsertProject(project: ProjectInsert): Promise<Project>;
|
|
510
|
+
updateProject(projectId: UUID, updates: Partial<ProjectInsert>): Promise<Project>;
|
|
511
|
+
/**
|
|
512
|
+
* Delete a project and all associated data (cascades to flows, steps, personas, API keys, etc.).
|
|
513
|
+
* Requires project admin/owner (enforced by RLS).
|
|
514
|
+
*/
|
|
515
|
+
deleteProject(projectId: UUID): Promise<void>;
|
|
516
|
+
/**
|
|
517
|
+
* Get the current user's role for a project, or null if not a member.
|
|
518
|
+
* Use with a client that has user session set (e.g. fromUserSession).
|
|
519
|
+
*/
|
|
520
|
+
getProjectMemberRole(projectId: UUID): Promise<ProjectRole | null>;
|
|
521
|
+
/**
|
|
522
|
+
* List members of a project. Requires project membership to view.
|
|
523
|
+
*/
|
|
524
|
+
getProjectMembers(projectId?: string): Promise<ProjectMember[]>;
|
|
525
|
+
/**
|
|
526
|
+
* Add a user as a project member. Requires project admin or owner role.
|
|
527
|
+
*/
|
|
528
|
+
addProjectMember(projectId: UUID, userId: UUID, role: ProjectRole): Promise<ProjectMember>;
|
|
529
|
+
/**
|
|
530
|
+
* Remove a member from a project. Requires project admin or owner role.
|
|
531
|
+
*/
|
|
532
|
+
removeProjectMember(projectId: UUID, userId: UUID): Promise<void>;
|
|
533
|
+
getPersonas(projectId?: string): Promise<Persona[]>;
|
|
534
|
+
createPersona(persona: PersonaInsert): Promise<Persona>;
|
|
535
|
+
getPersonasBySource(source: "user_configured" | "auto_generated", projectId?: string): Promise<Persona[]>;
|
|
536
|
+
createUserConfiguredPersonas(personas: PersonaInsert[], projectId?: string): Promise<Persona[]>;
|
|
537
|
+
deleteAutoGeneratedPersonas(projectId?: string): Promise<void>;
|
|
538
|
+
getFlows(projectId?: string): Promise<Flow[]>;
|
|
539
|
+
getFlow(id: UUID): Promise<Flow | null>;
|
|
540
|
+
getFlowByName(name: string, projectId?: string): Promise<Flow | null>;
|
|
541
|
+
getFlowWithSteps(id: UUID): Promise<FlowWithSteps | null>;
|
|
542
|
+
getFlowWithMetrics(id: UUID): Promise<FlowWithMetrics | null>;
|
|
543
|
+
createFlow(flow: FlowInsert): Promise<Flow>;
|
|
544
|
+
updateFlow(id: UUID, updates: FlowUpdate): Promise<Flow>;
|
|
545
|
+
upsertFlow(flow: FlowInsert): Promise<Flow>;
|
|
546
|
+
upsertFlows(flows: FlowInsert[]): Promise<Flow[]>;
|
|
547
|
+
/**
|
|
548
|
+
* Get flows affected by recent code changes
|
|
549
|
+
*/
|
|
550
|
+
getAffectedFlows(projectId?: string): Promise<Flow[]>;
|
|
551
|
+
/**
|
|
552
|
+
* Mark flows as affected by a code change
|
|
553
|
+
*/
|
|
554
|
+
markFlowsAffected(flowIds: UUID[], changeId: string, riskScoreIncrement?: number): Promise<void>;
|
|
555
|
+
/**
|
|
556
|
+
* Clear affected changes from flows (e.g., after tests pass)
|
|
557
|
+
*/
|
|
558
|
+
clearAffectedFlows(flowIds: UUID[]): Promise<void>;
|
|
559
|
+
getSteps(flowId: UUID): Promise<Step[]>;
|
|
560
|
+
createStep(step: StepInsert): Promise<Step>;
|
|
561
|
+
createSteps(steps: StepInsert[]): Promise<Step[]>;
|
|
562
|
+
getTestRuns(flowId: UUID, limit?: number): Promise<TestRun[]>;
|
|
563
|
+
getRecentTestRuns(projectId?: string, limit?: number): Promise<TestRun[]>;
|
|
564
|
+
createTestRun(testRun: TestRunInsert): Promise<TestRun>;
|
|
565
|
+
updateTestRun(id: UUID, updates: TestRunUpdate): Promise<TestRun>;
|
|
566
|
+
getInsights(projectId?: string, status?: string): Promise<Insight[]>;
|
|
567
|
+
getOpenInsights(projectId?: string): Promise<Insight[]>;
|
|
568
|
+
createInsight(insight: InsightInsert): Promise<Insight>;
|
|
569
|
+
updateInsight(id: UUID, updates: InsightUpdate): Promise<Insight>;
|
|
570
|
+
createCodeChange(change: CodeChangeInsert): Promise<CodeChange>;
|
|
571
|
+
getCodeChange(baseSha: string, headSha: string, projectId?: string): Promise<CodeChange | null>;
|
|
572
|
+
updateCodeChangeAnalysis(id: UUID, analysis: {
|
|
573
|
+
risk_level?: string;
|
|
574
|
+
risk_score?: number;
|
|
575
|
+
affected_flow_ids?: UUID[];
|
|
576
|
+
llm_analysis?: Record<string, unknown>;
|
|
577
|
+
}): Promise<CodeChange>;
|
|
578
|
+
publishEvent(event: Omit<PerceoEventInsert, "project_id"> & {
|
|
579
|
+
project_id?: UUID;
|
|
580
|
+
}): Promise<PerceoEvent>;
|
|
581
|
+
/**
|
|
582
|
+
* Publish a flow change event
|
|
583
|
+
*/
|
|
584
|
+
publishFlowsAffected(changeId: string, affectedFlows: {
|
|
585
|
+
id: UUID;
|
|
586
|
+
name: string;
|
|
587
|
+
riskScore: number;
|
|
588
|
+
}[], source?: EventSource): Promise<PerceoEvent>;
|
|
589
|
+
/**
|
|
590
|
+
* Publish a test status event
|
|
591
|
+
*/
|
|
592
|
+
publishTestStatus(testRunId: UUID, flowId: UUID, status: string, source?: EventSource): Promise<PerceoEvent>;
|
|
593
|
+
createPrediction(prediction: Omit<Prediction, "id" | "created_at" | "validated_at">): Promise<Prediction>;
|
|
594
|
+
getUnvalidatedPredictions(flowId: UUID): Promise<Prediction[]>;
|
|
595
|
+
getFlowMetrics(flowId: UUID): Promise<FlowMetrics | null>;
|
|
596
|
+
upsertFlowMetrics(flowId: UUID, metrics: Partial<Omit<FlowMetrics, "id" | "flow_id">>): Promise<FlowMetrics>;
|
|
597
|
+
/**
|
|
598
|
+
* Generate a new API key for a project
|
|
599
|
+
* Returns the full key (only shown once) and the created key record
|
|
600
|
+
*/
|
|
601
|
+
createApiKey(projectId: UUID, options: {
|
|
602
|
+
name: string;
|
|
603
|
+
scopes: ApiKeyScope[];
|
|
604
|
+
expiresAt?: Date;
|
|
605
|
+
createdBy?: UUID;
|
|
606
|
+
}): Promise<{
|
|
607
|
+
key: string;
|
|
608
|
+
keyRecord: ProjectApiKey;
|
|
609
|
+
}>;
|
|
610
|
+
/**
|
|
611
|
+
* Get all API keys for a project (metadata only, no hashes)
|
|
612
|
+
*/
|
|
613
|
+
getApiKeys(projectId?: string): Promise<Omit<ProjectApiKey, "key_hash">[]>;
|
|
614
|
+
/**
|
|
615
|
+
* Get active (non-revoked, non-expired) API keys for a project
|
|
616
|
+
*/
|
|
617
|
+
getActiveApiKeys(projectId?: string): Promise<Omit<ProjectApiKey, "key_hash">[]>;
|
|
618
|
+
/**
|
|
619
|
+
* Validate an API key and return the project info if valid
|
|
620
|
+
*/
|
|
621
|
+
validateApiKey(key: string): Promise<{
|
|
622
|
+
projectId: UUID;
|
|
623
|
+
scopes: ApiKeyScope[];
|
|
624
|
+
keyId: UUID;
|
|
625
|
+
} | null>;
|
|
626
|
+
/**
|
|
627
|
+
* Revoke an API key
|
|
628
|
+
*/
|
|
629
|
+
revokeApiKey(keyId: UUID, options?: {
|
|
630
|
+
revokedBy?: UUID;
|
|
631
|
+
reason?: string;
|
|
632
|
+
}): Promise<ProjectApiKey>;
|
|
633
|
+
/**
|
|
634
|
+
* Delete an API key permanently
|
|
635
|
+
*/
|
|
636
|
+
deleteApiKey(keyId: UUID): Promise<void>;
|
|
637
|
+
/**
|
|
638
|
+
* Check if an API key has a specific scope
|
|
639
|
+
*/
|
|
640
|
+
hasApiKeyScope(keyId: UUID, scope: ApiKeyScope): Promise<boolean>;
|
|
641
|
+
/**
|
|
642
|
+
* Subscribe to flow changes (via Postgres CDC)
|
|
643
|
+
*/
|
|
644
|
+
subscribeToFlows(projectId: string, callback: (payload: RealtimePayload<Flow>) => void): RealtimeChannel;
|
|
645
|
+
/**
|
|
646
|
+
* Subscribe to test run updates
|
|
647
|
+
*/
|
|
648
|
+
subscribeToTestRuns(projectId: string, callback: (payload: RealtimePayload<TestRun>) => void): RealtimeChannel;
|
|
649
|
+
/**
|
|
650
|
+
* Subscribe to new insights
|
|
651
|
+
*/
|
|
652
|
+
subscribeToInsights(projectId: string, callback: (payload: RealtimePayload<Insight>) => void): RealtimeChannel;
|
|
653
|
+
/**
|
|
654
|
+
* Subscribe to events (event bus)
|
|
655
|
+
*/
|
|
656
|
+
subscribeToEvents(projectId: string, eventTypes: string[] | null, callback: (payload: RealtimePayload<PerceoEvent>) => void): RealtimeChannel;
|
|
657
|
+
/**
|
|
658
|
+
* Broadcast ephemeral messages (not persisted)
|
|
659
|
+
*/
|
|
660
|
+
broadcast(channelName: string, event: string, payload: unknown): void;
|
|
661
|
+
/**
|
|
662
|
+
* Subscribe to broadcast messages
|
|
663
|
+
*/
|
|
664
|
+
subscribeToBroadcast(channelName: string, event: string, callback: (payload: unknown) => void): RealtimeChannel;
|
|
665
|
+
/**
|
|
666
|
+
* Unsubscribe from a channel
|
|
667
|
+
*/
|
|
668
|
+
unsubscribe(channelName: string): Promise<void>;
|
|
669
|
+
/**
|
|
670
|
+
* Unsubscribe from all channels
|
|
671
|
+
*/
|
|
672
|
+
unsubscribeAll(): Promise<void>;
|
|
673
|
+
/**
|
|
674
|
+
* Cleanup - call when done with the client
|
|
675
|
+
*/
|
|
676
|
+
cleanup(): Promise<void>;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Session data returned from magic-link auth flow.
|
|
681
|
+
* Callers add scope (project/global) when persisting.
|
|
682
|
+
*/
|
|
683
|
+
interface SupabaseAuthSession {
|
|
684
|
+
access_token: string;
|
|
685
|
+
refresh_token: string;
|
|
686
|
+
expires_at: number;
|
|
687
|
+
supabaseUrl: string;
|
|
688
|
+
}
|
|
689
|
+
declare function getSupabaseUrl(): string;
|
|
690
|
+
declare function getSupabaseAnonKey(): string;
|
|
691
|
+
declare function getSupabaseServiceRoleKey(): string | undefined;
|
|
692
|
+
/**
|
|
693
|
+
* Create a Supabase client for auth. Uses PERCEO_SUPABASE_URL and PERCEO_SUPABASE_ANON_KEY.
|
|
694
|
+
*/
|
|
695
|
+
declare function createSupabaseAuthClient(): SupabaseClient;
|
|
696
|
+
/**
|
|
697
|
+
* Exchange a redirect URL (with hash) from the magic link for a session and return session data for storage.
|
|
698
|
+
*/
|
|
699
|
+
declare function sessionFromRedirectUrl(supabase: SupabaseClient, redirectUrl: string): Promise<SupabaseAuthSession>;
|
|
700
|
+
/**
|
|
701
|
+
* Send a magic link to the given email. Redirect will go to redirectUrl (must be allowed in Supabase dashboard).
|
|
702
|
+
*/
|
|
703
|
+
declare function sendMagicLink(supabase: SupabaseClient, email: string, redirectUrl: string): Promise<{
|
|
704
|
+
error: Error | null;
|
|
705
|
+
}>;
|
|
706
|
+
|
|
707
|
+
export { type AnalyticsConnection, type AnalyticsEvent, type AnalyticsProvider, type ApiKeyScope, type CodeChange, type CodeChangeInsert, type Database, type EventSource, type Flow, type FlowInsert, type FlowMetrics, type FlowPriority, type FlowUpdate, type FlowWithMetrics, type FlowWithSteps, type Insight, type InsightInsert, type InsightSeverity, type InsightStatus, type InsightType, type InsightUpdate, type InsightWithFlow, type PerceoClientConfig, PerceoDataClient, type PerceoEvent, type PerceoEventInsert, type Persona, type PersonaInsert, type Prediction, type PredictionBasis, type Project, type ProjectApiKey, type ProjectApiKeyAudit, type ProjectApiKeyInsert, type ProjectApiKeyUpdate, type ProjectInsert, type ProjectMember, type ProjectRole, type RealtimeEventType, type RealtimePayload, type RiskLevel, type Step, type StepAction, type StepExpectedState, type StepInsert, type SupabaseAuthSession, type SyncStatus, type TestRun, type TestRunInsert, type TestRunUpdate, type TestRunWithFlow, type TestStatus, type TestTrigger, type Timestamp, type UUID, createSupabaseAuthClient, getSupabaseAnonKey, getSupabaseServiceRoleKey, getSupabaseUrl, sendMagicLink, sessionFromRedirectUrl };
|