sodabase 0.0.0-stage → 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/README.md +51 -2
- package/dist/api/client.js +230 -0
- package/dist/api/fakeClient.js +130 -0
- package/dist/api/gotrueAuth.js +160 -0
- package/dist/api/types.js +15 -0
- package/dist/app.js +47 -0
- package/dist/cli.js +87 -0
- package/dist/config/flowState.js +45 -0
- package/dist/config/tokenStore.js +33 -0
- package/dist/ui.js +606 -0
- package/package.json +54 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { render } from "ink";
|
|
4
|
+
import { SodabaseClient } from "./api/client.js";
|
|
5
|
+
import { FakeClient } from "./api/fakeClient.js";
|
|
6
|
+
import { App } from "./app.js";
|
|
7
|
+
import { clearProgress, loadProgress } from "./config/flowState.js";
|
|
8
|
+
import { clearCreds, loadCreds } from "./config/tokenStore.js";
|
|
9
|
+
const argv = process.argv.slice(2);
|
|
10
|
+
const args = new Set(argv);
|
|
11
|
+
if (args.has("--help") || args.has("-h")) {
|
|
12
|
+
process.stdout.write([
|
|
13
|
+
"sodabase — data-quality onboarding wizard",
|
|
14
|
+
"",
|
|
15
|
+
"Usage: npx sodabase [options]",
|
|
16
|
+
"",
|
|
17
|
+
"Options:",
|
|
18
|
+
" --demo run the whole flow offline against a fake backend",
|
|
19
|
+
" --fast shorter delays (implied by --demo)",
|
|
20
|
+
" --login sign in again (clears the saved session first)",
|
|
21
|
+
" --logout clear the saved session and exit",
|
|
22
|
+
" --help, -h show this help",
|
|
23
|
+
" --version print the version",
|
|
24
|
+
"",
|
|
25
|
+
"Env:",
|
|
26
|
+
" SODABASE_API_URL API origin (default https://sodabase.io)",
|
|
27
|
+
"",
|
|
28
|
+
"Read-only, always. The only write is one scoped, audited read-only role.",
|
|
29
|
+
"",
|
|
30
|
+
].join("\n"));
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
if (args.has("--version")) {
|
|
34
|
+
process.stdout.write("sodabase 0.0.0-dev\n");
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
// Sign out: drop the saved session (and resume state) and stop.
|
|
38
|
+
if (args.has("--logout")) {
|
|
39
|
+
clearCreds();
|
|
40
|
+
clearProgress();
|
|
41
|
+
process.stdout.write("Signed out of Sodabase.\n");
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
// Force a fresh sign-in: clear the saved session first, then run normally so it re-prompts.
|
|
45
|
+
if (args.has("--login")) {
|
|
46
|
+
clearCreds();
|
|
47
|
+
clearProgress();
|
|
48
|
+
}
|
|
49
|
+
const demo = args.has("--demo");
|
|
50
|
+
const fast = args.has("--fast") || demo;
|
|
51
|
+
// Interactive pickers need a raw-mode-capable TTY. Keyed off the TTY only — so
|
|
52
|
+
// `--demo` in a real terminal is a fully interactive offline playthrough, while a
|
|
53
|
+
// piped/CI run (no TTY) auto-advances. Opt out explicitly with --no-input.
|
|
54
|
+
const interactive = !!process.stdin.isTTY && !args.has("--no-input");
|
|
55
|
+
let signedIn = false;
|
|
56
|
+
let startPhase;
|
|
57
|
+
let initialCtx;
|
|
58
|
+
const services = demo
|
|
59
|
+
? new FakeClient({ fast })
|
|
60
|
+
: (() => {
|
|
61
|
+
const c = new SodabaseClient();
|
|
62
|
+
const creds = loadCreds();
|
|
63
|
+
// Require a real GoTrue JWT (starts "eyJ") — guards against a stale/fake token
|
|
64
|
+
// (e.g. a leftover --demo session) skipping sign-in and then 401-ing on /api/v1.
|
|
65
|
+
if (creds?.accessToken && creds.accessToken.startsWith("eyJ")) {
|
|
66
|
+
c.setBearer(creds.accessToken);
|
|
67
|
+
signedIn = !creds.expiresAt || creds.expiresAt > Date.now() + 60_000;
|
|
68
|
+
}
|
|
69
|
+
// Resume only when authenticated — re-attaching to the server-side state needs the token.
|
|
70
|
+
if (signedIn) {
|
|
71
|
+
const prog = loadProgress();
|
|
72
|
+
if (prog) {
|
|
73
|
+
startPhase = prog.phase;
|
|
74
|
+
const ctx = {};
|
|
75
|
+
if (prog.projectRef)
|
|
76
|
+
ctx.projectRef = prog.projectRef;
|
|
77
|
+
if (prog.connectionId)
|
|
78
|
+
ctx.connectionId = prog.connectionId;
|
|
79
|
+
if (prog.alreadyWatching)
|
|
80
|
+
ctx.alreadyWatching = true;
|
|
81
|
+
if (Object.keys(ctx).length)
|
|
82
|
+
initialCtx = ctx;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return c;
|
|
86
|
+
})();
|
|
87
|
+
render(_jsx(App, { services: services, fast: fast, interactive: interactive, signedIn: signedIn, demo: demo, ...(startPhase ? { startPhase } : {}), ...(initialCtx ? { initialCtx } : {}) }));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Lightweight resume state. The server already makes the work idempotent (connect
|
|
2
|
+
// provisioning is guarded by the connect state machine; the onboarding job has a unique
|
|
3
|
+
// index per connection, so re-starting attaches to the same run). So this is only a UX
|
|
4
|
+
// convenience — re-enter the flow where you left off instead of from the top. A 0600
|
|
5
|
+
// file next to the credentials; safe to delete.
|
|
6
|
+
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
const MAX_AGE_MS = 24 * 60 * 60 * 1000; // ignore stale progress after a day
|
|
10
|
+
function progressPath() {
|
|
11
|
+
const base = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
12
|
+
return join(base, "sodabase", "progress.json");
|
|
13
|
+
}
|
|
14
|
+
export function loadProgress() {
|
|
15
|
+
try {
|
|
16
|
+
const p = JSON.parse(readFileSync(progressPath(), "utf8"));
|
|
17
|
+
if (!p.phase || typeof p.updatedAt !== "number")
|
|
18
|
+
return null;
|
|
19
|
+
if (Date.now() - p.updatedAt > MAX_AGE_MS)
|
|
20
|
+
return null; // too old to trust
|
|
21
|
+
return p;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function saveProgress(p) {
|
|
28
|
+
try {
|
|
29
|
+
const path = progressPath();
|
|
30
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
31
|
+
writeFileSync(path, JSON.stringify({ ...p, updatedAt: Date.now() }, null, 2), { mode: 0o600 });
|
|
32
|
+
chmodSync(path, 0o600);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* non-fatal — resume is a convenience */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function clearProgress() {
|
|
39
|
+
try {
|
|
40
|
+
rmSync(progressPath());
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* already gone */
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Per-user credential storage. A 0600 file under the user's config dir — deliberately
|
|
2
|
+
// dep-free (no native keychain module). Documented tradeoff: less hardened than an OS
|
|
3
|
+
// keychain, but no node-gyp/platform build and no new dependency. Can move to a keychain
|
|
4
|
+
// later if warranted.
|
|
5
|
+
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
function credsPath() {
|
|
9
|
+
const base = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
10
|
+
return join(base, "sodabase", "credentials.json");
|
|
11
|
+
}
|
|
12
|
+
export function loadCreds() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(readFileSync(credsPath(), "utf8"));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null; // missing / unreadable / malformed → treat as signed-out
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function saveCreds(creds) {
|
|
21
|
+
const path = credsPath();
|
|
22
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
23
|
+
writeFileSync(path, JSON.stringify(creds, null, 2), { mode: 0o600 });
|
|
24
|
+
chmodSync(path, 0o600); // enforce even if the file pre-existed with looser perms
|
|
25
|
+
}
|
|
26
|
+
export function clearCreds() {
|
|
27
|
+
try {
|
|
28
|
+
rmSync(credsPath());
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
/* already gone */
|
|
32
|
+
}
|
|
33
|
+
}
|