sodabase 0.0.0-stage → 0.1.2
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/README.md +51 -2
- package/dist/api/client.js +291 -0
- package/dist/api/fakeClient.js +154 -0
- package/dist/api/gotrueAuth.js +180 -0
- package/dist/api/types.js +15 -0
- package/dist/app.js +98 -0
- package/dist/cli.js +83 -0
- package/dist/config/tokenStore.js +33 -0
- package/dist/ui.js +768 -0
- package/package.json +54 -4
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sodabase (v2 CLI)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `npx sodabase` interactive onboarding wizard — the real, shippable package.
|
|
4
|
+
Design: `docs/specs/v2-cli-onboarding-spec.md` (planning repo). Proven first as the
|
|
5
|
+
zero-dep spike in that repo's `scripts/cli-wizard-spike/`; this is the Ink/TS port.
|
|
6
|
+
|
|
7
|
+
> **Status: scaffold.** Toolchain + API client + token store are in; the flow screens
|
|
8
|
+
> are being built on top. Lands behind the spec's §9 gates; **not published** (`private: true`).
|
|
9
|
+
|
|
10
|
+
## Stack
|
|
11
|
+
|
|
12
|
+
Ink 7 + React 19 + TypeScript (Node ≥22). Deliberately dep-light: native `fetch`,
|
|
13
|
+
`child_process` for opening a browser, a `0600` config file for the token (no native
|
|
14
|
+
keychain), `useInput` for pickers (no extra component libs), and `tsc` for the build
|
|
15
|
+
(no bundler).
|
|
16
|
+
|
|
17
|
+
## Develop
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd cli
|
|
21
|
+
npm install
|
|
22
|
+
npm run typecheck # tsc --noEmit
|
|
23
|
+
npm run build # -> dist/
|
|
24
|
+
node dist/cli.js # run the built CLI
|
|
25
|
+
# or, no build step:
|
|
26
|
+
npm run dev # node --experimental-strip-types src/cli.tsx
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Point at a local backend with `SODABASE_API_URL=http://localhost:8080`.
|
|
30
|
+
|
|
31
|
+
## Layout
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
cli.tsx entry — renders <App/>
|
|
36
|
+
app.tsx the Ink app (flow orchestrator + screens)
|
|
37
|
+
api/
|
|
38
|
+
client.ts HTTP client for the real endpoints (device grant, onboarding
|
|
39
|
+
job poll, connections, relevance, scan report)
|
|
40
|
+
types.ts wire types
|
|
41
|
+
config/
|
|
42
|
+
tokenStore.ts 0600 credential file
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## What backs each step (all real endpoints)
|
|
46
|
+
|
|
47
|
+
- **Sign-in:** OAuth device grant (`/oauth/device_authorization` + `/oauth/token`) — PR #383.
|
|
48
|
+
- **Connect:** Supabase authorize + poll `GET /connections`.
|
|
49
|
+
- **Discover / monitors / scan:** trigger + poll the server-side onboarding job
|
|
50
|
+
(`POST`/`GET /onboarding/jobs/{id}`, per-step `steps[]`).
|
|
51
|
+
- **Scope:** onboard-then-adjust via `confirm`/`decline_proposals`.
|
|
52
|
+
- **MCP install:** consented in-flow `add-mcp -a <chosen>`.
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// Real HTTP client for the Sodabase /api/v1 API. Native fetch only (Node 22) — no deps.
|
|
2
|
+
// The CLI is a GoTrue client: every /api/v1 call carries Authorization: Bearer <GoTrue JWT>.
|
|
3
|
+
// NOTE: this is NOT the mcp_oauth device-grant token (that targets the MCP server, a
|
|
4
|
+
// different audience, and /api/v1 rejects it). See signIn()'s TODO(gotrue-auth).
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { emailOtpStart, emailOtpVerify, loopbackSignIn, resolveGoTrueConfig } from "./gotrueAuth.js";
|
|
9
|
+
import { ApiError, } from "./types.js";
|
|
10
|
+
export const MCP_URL = "https://sodabase.io/mcp";
|
|
11
|
+
/** The trust-advisor skill repo, resolved by the `skills` CLI (owner/repo on its default branch). */
|
|
12
|
+
export const SKILL_REF = "sodabase/agent-skills";
|
|
13
|
+
/** An error thrown when `connect()`'s poll is aborted (the user left the connect screen). */
|
|
14
|
+
const abortedError = () => new ApiError("connect aborted", 499, "aborted");
|
|
15
|
+
/** Resolve after `ms`, or reject immediately if `signal` aborts (so leaving the screen doesn't wait).
|
|
16
|
+
* The abort listener is removed when the timer wins — otherwise connect()'s per-poll calls would pile
|
|
17
|
+
* up listeners on the same signal and trip Node's MaxListenersExceededWarning (which corrupts the TUI). */
|
|
18
|
+
function sleepAbortable(ms, signal) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
if (signal?.aborted)
|
|
21
|
+
return reject(abortedError());
|
|
22
|
+
const onAbort = () => {
|
|
23
|
+
clearTimeout(t);
|
|
24
|
+
reject(abortedError());
|
|
25
|
+
};
|
|
26
|
+
const t = setTimeout(() => {
|
|
27
|
+
signal?.removeEventListener("abort", onAbort);
|
|
28
|
+
resolve();
|
|
29
|
+
}, ms);
|
|
30
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Open a URL in the user's default browser (best-effort; the URL is also shown as text). */
|
|
34
|
+
function openUrl(url) {
|
|
35
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
36
|
+
try {
|
|
37
|
+
spawn(cmd, [url], { stdio: "ignore", detached: true, shell: process.platform === "win32" }).unref();
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
/* best-effort */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class SodabaseClient {
|
|
44
|
+
site;
|
|
45
|
+
api;
|
|
46
|
+
bearer;
|
|
47
|
+
constructor(opts = {}) {
|
|
48
|
+
this.site = (opts.baseUrl ?? process.env.SODABASE_API_URL ?? "https://sodabase.io").replace(/\/$/, "");
|
|
49
|
+
this.api = `${this.site}/api/v1`;
|
|
50
|
+
this.bearer = opts.bearer;
|
|
51
|
+
}
|
|
52
|
+
setBearer(token) {
|
|
53
|
+
this.bearer = token;
|
|
54
|
+
}
|
|
55
|
+
// ── Leg 1: GoTrue sign-in (loopback PKCE → aud="authenticated" session) ──────
|
|
56
|
+
async signIn(provider) {
|
|
57
|
+
// Matches the web app's @supabase/ssr PKCE flow, driven from a loopback redirect.
|
|
58
|
+
// Config + the one-time redirect-allowlist requirement live in gotrueAuth.ts.
|
|
59
|
+
const cfg = resolveGoTrueConfig();
|
|
60
|
+
const session = await loopbackSignIn(provider ? { ...cfg, provider } : cfg);
|
|
61
|
+
this.bearer = session.accessToken;
|
|
62
|
+
return session;
|
|
63
|
+
}
|
|
64
|
+
// ── Leg 1 (alt): browserless email one-time-code sign-in (no loopback, no PKCE) ──
|
|
65
|
+
async emailOtpStart(email) {
|
|
66
|
+
await emailOtpStart(resolveGoTrueConfig(), email);
|
|
67
|
+
}
|
|
68
|
+
async emailOtpVerify(email, code) {
|
|
69
|
+
const session = await emailOtpVerify(resolveGoTrueConfig(), email, code);
|
|
70
|
+
this.bearer = session.accessToken;
|
|
71
|
+
return session;
|
|
72
|
+
}
|
|
73
|
+
// ── Local: detect the Supabase project from the cwd ─────────────────────────
|
|
74
|
+
async detectProject() {
|
|
75
|
+
const cwd = process.cwd();
|
|
76
|
+
const configToml = join(cwd, "supabase", "config.toml");
|
|
77
|
+
const hasConfigToml = existsSync(configToml);
|
|
78
|
+
let projectRef = "";
|
|
79
|
+
if (hasConfigToml) {
|
|
80
|
+
// project_id may be single- or double-quoted
|
|
81
|
+
const m = /project_id\s*=\s*["']([^"']+)["']/.exec(readFileSync(configToml, "utf8"));
|
|
82
|
+
if (m?.[1])
|
|
83
|
+
projectRef = m[1];
|
|
84
|
+
}
|
|
85
|
+
const pkg = join(cwd, "package.json");
|
|
86
|
+
const hasPackageJson = existsSync(pkg);
|
|
87
|
+
let framework = "";
|
|
88
|
+
if (hasPackageJson) {
|
|
89
|
+
try {
|
|
90
|
+
const json = JSON.parse(readFileSync(pkg, "utf8"));
|
|
91
|
+
// Scan both dependency sets — supabase-js often lives under devDependencies, and monorepo
|
|
92
|
+
// roots vary. (Framework is display-only; it never drives onboarding.)
|
|
93
|
+
const all = { ...json.devDependencies, ...json.dependencies };
|
|
94
|
+
if (all["@supabase/supabase-js"])
|
|
95
|
+
framework = "@supabase/supabase-js";
|
|
96
|
+
if (all.next)
|
|
97
|
+
framework = "Next.js + @supabase/supabase-js";
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
/* a malformed package.json in the cwd must not crash boot — detection is best-effort */
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { directory: cwd, framework, projectRef, hasPackageJson, hasConfigToml };
|
|
104
|
+
}
|
|
105
|
+
// ── Leg 2: Supabase connect via the HOSTED handback (Supabase requires an HTTPS public-host
|
|
106
|
+
// redirect, so no loopback). start(redirect_uri = hosted handback) → browser authorizes →
|
|
107
|
+
// Supabase redirects to sodabase.io/.../cli-handback (stashes code+state) → the CLI polls
|
|
108
|
+
// cli-complete with its OWN Bearer; the backend exchanges + creates server-side. The raw
|
|
109
|
+
// Supabase code never reaches the CLI.
|
|
110
|
+
handbackUrl() {
|
|
111
|
+
// MUST equal the backend's allowlisted value (connect_service.cli_handback_redirect_uri,
|
|
112
|
+
// derived from SITE_URL) and be registered on the Supabase OAuth app.
|
|
113
|
+
return `${this.api}/connections/supabase/cli-handback`;
|
|
114
|
+
}
|
|
115
|
+
async startConnect(redirectUri) {
|
|
116
|
+
const r = await this.post("/connections/supabase/start", { redirect_uri: redirectUri });
|
|
117
|
+
return { authorizeUrl: r.authorize_url };
|
|
118
|
+
}
|
|
119
|
+
/** One poll of cli-complete. `pending` → keep polling; otherwise the connection is created (or, when the org
|
|
120
|
+
* was already connected, the existing one is returned with `already_connected`). */
|
|
121
|
+
async cliComplete(state) {
|
|
122
|
+
const r = await this.post("/connections/supabase/cli-complete", { state });
|
|
123
|
+
return {
|
|
124
|
+
status: r.status,
|
|
125
|
+
...(r.connection_id ? { connectionId: r.connection_id } : {}),
|
|
126
|
+
...(r.already_connected ? { alreadyConnected: true } : {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async connect(signal) {
|
|
130
|
+
if (signal?.aborted)
|
|
131
|
+
throw abortedError();
|
|
132
|
+
const { authorizeUrl } = await this.startConnect(this.handbackUrl());
|
|
133
|
+
const state = new URL(authorizeUrl).searchParams.get("state");
|
|
134
|
+
if (!state)
|
|
135
|
+
throw new ApiError("authorize URL is missing state", 500, "connect");
|
|
136
|
+
openUrl(authorizeUrl);
|
|
137
|
+
const deadline = Date.now() + 5 * 60_000; // give the user time to approve in the browser
|
|
138
|
+
// Serialize polls (await each before the next) per the cli-complete polling contract — overlapping
|
|
139
|
+
// in-flight polls can race the take-before-exchange window. The signal stops the loop when the user
|
|
140
|
+
// leaves the connect screen, so an abandoned authorize doesn't keep polling (and a re-entry can't
|
|
141
|
+
// start a competing loop).
|
|
142
|
+
let seenPending = false;
|
|
143
|
+
for (;;) {
|
|
144
|
+
if (signal?.aborted)
|
|
145
|
+
throw abortedError();
|
|
146
|
+
let r;
|
|
147
|
+
try {
|
|
148
|
+
r = await this.cliComplete(state);
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
// Contract: a 400 AFTER a prior 'pending' means a poll likely consumed the state mid-exchange —
|
|
152
|
+
// the connect may have completed. Surface that instead of a hard failure, rather than crash.
|
|
153
|
+
if (seenPending && e instanceof ApiError && e.status === 400) {
|
|
154
|
+
throw new ApiError("Connection may have completed — re-run `sodabase` to resume, or check your dashboard.", 409, "maybe_completed");
|
|
155
|
+
}
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
158
|
+
if (r.connectionId)
|
|
159
|
+
return { connectionId: r.connectionId, ...(r.alreadyConnected ? { alreadyConnected: true } : {}) };
|
|
160
|
+
seenPending = true; // status was "pending"
|
|
161
|
+
if (Date.now() > deadline) {
|
|
162
|
+
throw new ApiError("timed out waiting for Supabase authorization in the browser", 408, "timeout");
|
|
163
|
+
}
|
|
164
|
+
await sleepAbortable(2000, signal);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async listProjects(connectionId) {
|
|
168
|
+
const rows = await this.get(`/connections/${encodeURIComponent(connectionId)}/projects`);
|
|
169
|
+
return rows.map((p) => ({
|
|
170
|
+
id: p.id,
|
|
171
|
+
ref: p.ref,
|
|
172
|
+
name: p.name,
|
|
173
|
+
status: p.status ?? "",
|
|
174
|
+
...(p.region ? { region: p.region } : {}),
|
|
175
|
+
...(p.already_connected_elsewhere ? { alreadyConnectedElsewhere: true } : {}),
|
|
176
|
+
...(p.already_watched ? { watching: true } : {}),
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
// ── Status: the workspace's watched projects + live open-issue counts ────────
|
|
180
|
+
async dashboardProjects() {
|
|
181
|
+
const rows = await this.get("/projects");
|
|
182
|
+
return rows.map((p) => ({
|
|
183
|
+
ref: p.ref,
|
|
184
|
+
name: p.name,
|
|
185
|
+
openIssues: p.open_issues ?? 0,
|
|
186
|
+
dataQualityIssues: p.data_quality_issues ?? 0,
|
|
187
|
+
watched: p.watched ?? 0,
|
|
188
|
+
status: p.status ?? "ready",
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
// ── The server-side onboarding job ──────────────────────────────────────────
|
|
192
|
+
async enqueueOnboarding(connectionId, projectRef) {
|
|
193
|
+
return this.post("/onboarding/jobs", {
|
|
194
|
+
connection_id: connectionId,
|
|
195
|
+
project_ref: projectRef,
|
|
196
|
+
slack_alerting: true,
|
|
197
|
+
email_alerting: true,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
async jobStatus(jobId) {
|
|
201
|
+
return this.get(`/onboarding/jobs/${encodeURIComponent(jobId)}`);
|
|
202
|
+
}
|
|
203
|
+
// ── Manage: a project's tables + per-table watch toggle (same endpoints the dashboard uses) ──
|
|
204
|
+
async projectDatasets(projectRef) {
|
|
205
|
+
const rows = await this.get(`/projects/${encodeURIComponent(projectRef)}/datasets`);
|
|
206
|
+
// Be defensive about the body shape — a non-array (empty-body {} / error envelope) must not throw
|
|
207
|
+
// `.map is not a function` up into the screen.
|
|
208
|
+
return Array.isArray(rows) ? rows.map((d) => ({ id: d.id, name: d.name, monitored: d.monitored })) : [];
|
|
209
|
+
}
|
|
210
|
+
async toggleDataset(projectRef, datasetId, enabled) {
|
|
211
|
+
const r = await this.post(`/projects/${encodeURIComponent(projectRef)}/datasets/${encodeURIComponent(datasetId)}/monitor`, { enabled });
|
|
212
|
+
return { monitored: r.monitored, needsReauth: r.needs_reauth };
|
|
213
|
+
}
|
|
214
|
+
// ── Scope: relevance (onboard-then-adjust; operates on monitor ids) ──────────
|
|
215
|
+
async proposals() {
|
|
216
|
+
return this.get("/relevance/proposals");
|
|
217
|
+
}
|
|
218
|
+
async confirmProposals(monitorIds) {
|
|
219
|
+
await this.post("/relevance/proposals/confirm", { monitor_ids: monitorIds });
|
|
220
|
+
}
|
|
221
|
+
async declineProposals(monitorIds) {
|
|
222
|
+
await this.post("/relevance/proposals/decline", { monitor_ids: monitorIds });
|
|
223
|
+
}
|
|
224
|
+
// ── Local: consented in-flow MCP install via add-mcp ────────────────────────
|
|
225
|
+
async installMcp(agents) {
|
|
226
|
+
// `-y` on npx skips its first-run "install add-mcp?" prompt; `-y` on add-mcp skips ITS confirmation. We run
|
|
227
|
+
// non-interactively (stdio is not a TTY), so without BOTH, add-mcp blocks on a prompt it can never get and
|
|
228
|
+
// the install silently does nothing. (`-g -a <agent>` is add-mcp's global + per-agent targeting.)
|
|
229
|
+
const args = ["-y", "add-mcp", MCP_URL, "-g", ...agents.flatMap((a) => ["-a", a]), "-y"];
|
|
230
|
+
const command = `npx ${args.join(" ")}`;
|
|
231
|
+
await new Promise((resolve, reject) => {
|
|
232
|
+
let stderr = "";
|
|
233
|
+
// On Windows npx is `npx.cmd`, only resolvable via the shell (args are a fixed constant list — no injection).
|
|
234
|
+
const child = spawn("npx", args, { stdio: ["ignore", "ignore", "pipe"], shell: process.platform === "win32" });
|
|
235
|
+
child.stderr?.on("data", (d) => (stderr += String(d)));
|
|
236
|
+
child.on("error", reject);
|
|
237
|
+
child.on("exit", (code) => code === 0
|
|
238
|
+
? resolve()
|
|
239
|
+
: reject(new Error(`add-mcp exited ${code}${stderr ? `: ${stderr.trim().split("\n").slice(-2).join("; ")}` : ""}`)));
|
|
240
|
+
});
|
|
241
|
+
const paths = {
|
|
242
|
+
"claude-code": "~/.claude.json",
|
|
243
|
+
cursor: "~/.cursor/mcp.json",
|
|
244
|
+
codex: "~/.codex/config.toml",
|
|
245
|
+
};
|
|
246
|
+
return { command, wrote: agents.map((a) => ({ agent: a, path: paths[a] ?? "~/.config/<agent>" })) };
|
|
247
|
+
}
|
|
248
|
+
// ── Local: consented in-flow trust-advisor skill install via the `skills` CLI ──
|
|
249
|
+
async installSkill(agents) {
|
|
250
|
+
// Same non-TTY reasoning as installMcp: the leading `-y` skips npx's first-run prompt; the trailing
|
|
251
|
+
// `-y` (skills' --yes) skips ALL of its confirmation prompts (incl. the symlink-vs-copy method choice),
|
|
252
|
+
// which it would otherwise block on without a TTY. `-g -a <agent>` mirrors the MCP targets.
|
|
253
|
+
const args = ["-y", "skills", "add", SKILL_REF, "-g", ...agents.flatMap((a) => ["-a", a]), "-y"];
|
|
254
|
+
const command = `npx ${args.join(" ")}`;
|
|
255
|
+
await new Promise((resolve, reject) => {
|
|
256
|
+
let stderr = "";
|
|
257
|
+
// On Windows npx is `npx.cmd`, only resolvable via the shell (args are a fixed constant list — no injection).
|
|
258
|
+
const child = spawn("npx", args, { stdio: ["ignore", "ignore", "pipe"], shell: process.platform === "win32" });
|
|
259
|
+
child.stderr?.on("data", (d) => (stderr += String(d)));
|
|
260
|
+
child.on("error", reject);
|
|
261
|
+
child.on("exit", (code) => code === 0
|
|
262
|
+
? resolve()
|
|
263
|
+
: reject(new Error(`skills exited ${code}${stderr ? `: ${stderr.trim().split("\n").slice(-2).join("; ")}` : ""}`)));
|
|
264
|
+
});
|
|
265
|
+
return { command };
|
|
266
|
+
}
|
|
267
|
+
// ── low-level helpers ───────────────────────────────────────────────────────
|
|
268
|
+
authHeaders() {
|
|
269
|
+
return this.bearer ? { authorization: `Bearer ${this.bearer}` } : {};
|
|
270
|
+
}
|
|
271
|
+
async get(path) {
|
|
272
|
+
return this.parse(await fetch(`${this.api}${path}`, { headers: this.authHeaders() }));
|
|
273
|
+
}
|
|
274
|
+
async post(path, json) {
|
|
275
|
+
const init = { method: "POST", headers: { ...this.authHeaders() } };
|
|
276
|
+
if (json !== undefined) {
|
|
277
|
+
init.headers["content-type"] = "application/json";
|
|
278
|
+
init.body = JSON.stringify(json);
|
|
279
|
+
}
|
|
280
|
+
return this.parse(await fetch(`${this.api}${path}`, init));
|
|
281
|
+
}
|
|
282
|
+
async parse(res) {
|
|
283
|
+
const text = await res.text();
|
|
284
|
+
const body = text ? JSON.parse(text) : {};
|
|
285
|
+
if (!res.ok) {
|
|
286
|
+
const b = body;
|
|
287
|
+
throw new ApiError(String(b.error_description ?? b.detail ?? res.statusText), res.status, b.error);
|
|
288
|
+
}
|
|
289
|
+
return body;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Offline stand-in for the real Services (used by `sodabase --demo`). Scripted data +
|
|
2
|
+
// small delays. Lets the full flow run with no backend — a hands-off/interactive
|
|
3
|
+
// playthrough and the UI test harness. Matches the real /api/v1 shapes.
|
|
4
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5
|
+
const JOB_STEPS = [
|
|
6
|
+
{ name: "Map schema & relationships", detail: "reltuples-first; no table scans" },
|
|
7
|
+
{ name: "Set up freshness monitors", detail: "4 core tables" },
|
|
8
|
+
{ name: "Set up volume monitors", detail: "row_count baselines" },
|
|
9
|
+
{ name: "Run day-1 quality scan", detail: "missing · invalid · duplicate (async)" },
|
|
10
|
+
{ name: "Set up flow monitors", detail: "no partitioned tables — skipped", skip: true },
|
|
11
|
+
{ name: "Establish baselines", detail: "alerts quiet for 24h warm-up" },
|
|
12
|
+
{ name: "Build trust dashboard", detail: "" },
|
|
13
|
+
];
|
|
14
|
+
export class FakeClient {
|
|
15
|
+
fast;
|
|
16
|
+
jobIdx = 0;
|
|
17
|
+
// Per-project demo tables with a MIX of watched/unwatched state, so toggling shows real changes.
|
|
18
|
+
datasets = {};
|
|
19
|
+
constructor(opts = {}) {
|
|
20
|
+
this.fast = opts.fast ?? false;
|
|
21
|
+
}
|
|
22
|
+
datasetsFor(ref) {
|
|
23
|
+
if (!this.datasets[ref]) {
|
|
24
|
+
this.datasets[ref] = [
|
|
25
|
+
{ id: "ds_orders", name: "public.orders", monitored: true },
|
|
26
|
+
{ id: "ds_payments", name: "public.payments", monitored: true },
|
|
27
|
+
{ id: "ds_events", name: "public.events", monitored: true },
|
|
28
|
+
{ id: "ds_users", name: "public.users", monitored: false },
|
|
29
|
+
{ id: "ds_feature_flags", name: "public.feature_flags", monitored: false },
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
return this.datasets[ref];
|
|
33
|
+
}
|
|
34
|
+
tick(ms) {
|
|
35
|
+
return sleep(Math.round(ms * (this.fast ? 0.12 : 1)));
|
|
36
|
+
}
|
|
37
|
+
async detectProject() {
|
|
38
|
+
await this.tick(700);
|
|
39
|
+
return {
|
|
40
|
+
directory: "project-supabase",
|
|
41
|
+
framework: "Next.js + @supabase/supabase-js",
|
|
42
|
+
projectRef: "supabase-demo",
|
|
43
|
+
hasPackageJson: true,
|
|
44
|
+
hasConfigToml: true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async signIn(_provider) {
|
|
48
|
+
await this.tick(800);
|
|
49
|
+
return { accessToken: "demo.gotrue.jwt", expiresAt: Date.now() + 3600_000 };
|
|
50
|
+
}
|
|
51
|
+
async emailOtpStart(_email) {
|
|
52
|
+
// No real email in demo — just a short beat before the "enter the code" step.
|
|
53
|
+
await this.tick(600);
|
|
54
|
+
}
|
|
55
|
+
async emailOtpVerify(_email, _code) {
|
|
56
|
+
await this.tick(800);
|
|
57
|
+
return { accessToken: "demo.gotrue.jwt", expiresAt: Date.now() + 3600_000 };
|
|
58
|
+
}
|
|
59
|
+
setBearer() {
|
|
60
|
+
/* no-op in demo */
|
|
61
|
+
}
|
|
62
|
+
async connect(signal) {
|
|
63
|
+
// No real browser in demo — just simulate the authorize + callback round-trip.
|
|
64
|
+
await this.tick(900);
|
|
65
|
+
if (signal?.aborted)
|
|
66
|
+
throw new Error("connect aborted");
|
|
67
|
+
return { connectionId: "conn_demo" };
|
|
68
|
+
}
|
|
69
|
+
async listProjects(_connectionId) {
|
|
70
|
+
await this.tick(500);
|
|
71
|
+
return [
|
|
72
|
+
{ id: "prj_1", ref: "supabase-demo", name: "Supabase Demo", status: "ACTIVE_HEALTHY" },
|
|
73
|
+
{ id: "prj_2", ref: "analytics", name: "Analytics", status: "ACTIVE_HEALTHY", watching: true },
|
|
74
|
+
{ id: "prj_3", ref: "staging", name: "Staging", status: "INACTIVE" },
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
async enqueueOnboarding() {
|
|
78
|
+
await this.tick(300);
|
|
79
|
+
this.jobIdx = 0;
|
|
80
|
+
return { id: "job_demo", status: "queued" };
|
|
81
|
+
}
|
|
82
|
+
async dashboardProjects() {
|
|
83
|
+
await this.tick(300);
|
|
84
|
+
return [
|
|
85
|
+
{ ref: "supabase-demo", name: "Supabase Demo", openIssues: 2, dataQualityIssues: 13, watched: 7, status: "ready" },
|
|
86
|
+
{ ref: "analytics", name: "Analytics", openIssues: 0, dataQualityIssues: 0, watched: 4, status: "ready" },
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
async jobStatus(jobId) {
|
|
90
|
+
await this.tick(650);
|
|
91
|
+
const done = this.jobIdx;
|
|
92
|
+
this.jobIdx += 1;
|
|
93
|
+
const steps = JOB_STEPS.map((s, i) => ({
|
|
94
|
+
name: s.name,
|
|
95
|
+
detail: s.detail,
|
|
96
|
+
status: s.skip ? "skipped" : i < done ? "done" : i === done ? "running" : "pending",
|
|
97
|
+
}));
|
|
98
|
+
const finished = done >= JOB_STEPS.length;
|
|
99
|
+
return {
|
|
100
|
+
id: jobId,
|
|
101
|
+
status: finished ? "done" : "running",
|
|
102
|
+
step: finished ? null : (JOB_STEPS[done]?.name ?? null),
|
|
103
|
+
steps,
|
|
104
|
+
error: null,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async projectDatasets(ref) {
|
|
108
|
+
await this.tick(400);
|
|
109
|
+
return this.datasetsFor(ref).map((d) => ({ ...d }));
|
|
110
|
+
}
|
|
111
|
+
async toggleDataset(ref, datasetId, enabled) {
|
|
112
|
+
await this.tick(300);
|
|
113
|
+
const d = this.datasetsFor(ref).find((x) => x.id === datasetId);
|
|
114
|
+
if (d)
|
|
115
|
+
d.monitored = enabled;
|
|
116
|
+
return { monitored: enabled, needsReauth: false };
|
|
117
|
+
}
|
|
118
|
+
async proposals() {
|
|
119
|
+
await this.tick(500);
|
|
120
|
+
return {
|
|
121
|
+
enabled: true,
|
|
122
|
+
total_datasets: 34,
|
|
123
|
+
proposals: [
|
|
124
|
+
{ id: "m1", dataset: "public.orders", type: "freshness", reason: "high write rate", row_estimate: 1_420_000 },
|
|
125
|
+
{ id: "m2", dataset: "public.orders", type: "row_count", reason: "core table", row_estimate: 1_420_000 },
|
|
126
|
+
{ id: "m3", dataset: "public.payments", type: "freshness", reason: "high write rate", row_estimate: 1_390_000 },
|
|
127
|
+
{ id: "m4", dataset: "public.events", type: "row_count", reason: "append-only", row_estimate: 22_700_000 },
|
|
128
|
+
],
|
|
129
|
+
others: [{ id: "d9", dataset: "public.feature_flags", row_estimate: 36 }],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async confirmProposals() {
|
|
133
|
+
await this.tick(400);
|
|
134
|
+
}
|
|
135
|
+
async declineProposals() {
|
|
136
|
+
await this.tick(400);
|
|
137
|
+
}
|
|
138
|
+
async installMcp(agents) {
|
|
139
|
+
await this.tick(500);
|
|
140
|
+
const paths = {
|
|
141
|
+
"claude-code": "~/.claude.json",
|
|
142
|
+
cursor: "~/.cursor/mcp.json",
|
|
143
|
+
codex: "~/.codex/config.toml",
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
command: `npx add-mcp https://sodabase.io/mcp -g ${agents.map((a) => "-a " + a).join(" ")}`,
|
|
147
|
+
wrote: agents.map((a) => ({ agent: a, path: paths[a] ?? "~/.config/<agent>" })),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async installSkill(agents) {
|
|
151
|
+
await this.tick(500);
|
|
152
|
+
return { command: `npx skills add sodabase/agent-skills -g ${agents.map((a) => "-a " + a).join(" ")}` };
|
|
153
|
+
}
|
|
154
|
+
}
|