create-volt 0.12.0 → 0.13.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/CHANGELOG.md +15 -0
- package/README.md +12 -0
- package/addons/admin/files/lib/admin.js +44 -0
- package/addons/admin/files/public/admin-ui.js +62 -0
- package/addons/admin/meta.json +8 -0
- package/package.json +1 -1
- package/templates/default/public/app.js +7 -0
- package/templates/default/server.js +6 -1
- package/templates/default/setup/setup.js +3 -0
- package/templates/starter/public/app.js +10 -0
- package/templates/starter/server.js +6 -1
- package/templates/starter/setup/setup.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@ All notable changes to `create-volt` are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/), and this project adheres to
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.13.0] - 2026-06-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Opt-in **`admin`** add-on: a persistent, role-gated web admin (data browser)
|
|
11
|
+
for browser-only admins. Gated by auth **and** an `ADMIN_EMAILS` allowlist;
|
|
12
|
+
the panel is hidden for non-admins and `/admin/api/*` returns 403. Internal
|
|
13
|
+
collections (auth tokens/sessions) hidden. Wired into the default + starter
|
|
14
|
+
templates and the setup wizard (ADMIN_EMAILS field).
|
|
15
|
+
- `SECURITY.md` documenting the ephemeral-admin model and secure defaults.
|
|
16
|
+
|
|
17
|
+
### Note
|
|
18
|
+
- Prefer the ephemeral `--studio` (shell-gated) for admins with server access;
|
|
19
|
+
the `admin` add-on is the explicit standing-surface opt-in for non-shell admins.
|
|
20
|
+
|
|
7
21
|
## [0.12.0] - 2026-06-28
|
|
8
22
|
|
|
9
23
|
### Added
|
|
@@ -173,6 +187,7 @@ All notable changes to `create-volt` are documented here. The format follows
|
|
|
173
187
|
watching and full-page hot reload. Supports `--skip-install` and `--force`,
|
|
174
188
|
and auto-detects npm / pnpm / yarn / bun for the install step.
|
|
175
189
|
|
|
190
|
+
[0.13.0]: https://github.com/MIR-2025/volt/releases/tag/v0.13.0
|
|
176
191
|
[0.12.0]: https://github.com/MIR-2025/volt/releases/tag/v0.12.0
|
|
177
192
|
[0.11.0]: https://github.com/MIR-2025/volt/releases/tag/v0.11.0
|
|
178
193
|
[0.10.0]: https://github.com/MIR-2025/volt/releases/tag/v0.10.0
|
package/README.md
CHANGED
|
@@ -80,6 +80,18 @@ driver, and is **never** a route in the running app (no standing `/admin` to
|
|
|
80
80
|
attack — shell/SSH access is the gate). Needs a persistent driver (MongoDB /
|
|
81
81
|
MySQL / Postgres) to show data; the memory driver is per-process.
|
|
82
82
|
|
|
83
|
+
## Security & admin model
|
|
84
|
+
|
|
85
|
+
Volt is secure by default, and deliberately has **no standing admin route** —
|
|
86
|
+
the config wizard (`--edit`) and data browser (`--studio`) are ephemeral,
|
|
87
|
+
localhost-only processes; **shell/SSH access is the auth**. Several admins? Give
|
|
88
|
+
each an SSH key — stronger than a shared web panel, with nothing public to
|
|
89
|
+
attack. A persistent, role-gated web admin exists only as an **opt-in** add-on
|
|
90
|
+
(`admin`, gated by auth + an `ADMIN_EMAILS` allowlist) for when you truly need
|
|
91
|
+
browser-only admins. Plus: escaping by default (no XSS), server-side validation
|
|
92
|
+
+ caps, security headers, and `HttpOnly`+`SameSite` cookies. See
|
|
93
|
+
[SECURITY.md](https://github.com/MIR-2025/volt/blob/main/SECURITY.md).
|
|
94
|
+
|
|
83
95
|
## Updating Volt
|
|
84
96
|
|
|
85
97
|
Volt is vendored as a single file (`public/volt.js`), not an npm dependency.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// admin.js — opt-in, role-gated web admin (data browser) for the running app.
|
|
2
|
+
// This is the ONE deliberately-persistent privileged surface in Volt, for
|
|
3
|
+
// browser-only admins. Every route requires a session AND membership in the
|
|
4
|
+
// ADMIN_EMAILS allowlist. Internal collections (auth tokens/sessions) are hidden.
|
|
5
|
+
// Prefer `npm run dev -- --studio` (ephemeral) unless you truly need this.
|
|
6
|
+
|
|
7
|
+
import express from "express";
|
|
8
|
+
|
|
9
|
+
const HIDDEN = new Set(["auth_tokens", "auth_sessions", "__voltcheck"]);
|
|
10
|
+
const visible = (n) => n && !HIDDEN.has(n);
|
|
11
|
+
|
|
12
|
+
export function adminRouter({ store, requireAuth, adminEmails }) {
|
|
13
|
+
const allow = new Set((adminEmails || []).map((e) => String(e).trim().toLowerCase()).filter(Boolean));
|
|
14
|
+
const isAdmin = (email) => allow.has(String(email || "").toLowerCase());
|
|
15
|
+
|
|
16
|
+
const r = express.Router();
|
|
17
|
+
r.use(requireAuth); // must be signed in for anything under /admin/api
|
|
18
|
+
|
|
19
|
+
// any signed-in user may ask whether *they* are an admin (drives the UI)
|
|
20
|
+
r.get("/admin/api/me", (req, res) => res.json({ email: req.user.email, isAdmin: isAdmin(req.user.email) }));
|
|
21
|
+
|
|
22
|
+
// everything below is admins-only
|
|
23
|
+
r.use((req, res, next) => (isAdmin(req.user.email) ? next() : res.status(403).json({ ok: false, error: "Admins only." })));
|
|
24
|
+
|
|
25
|
+
r.get("/admin/api/collections", async (_req, res) => {
|
|
26
|
+
const all = (await store.collections()) || [];
|
|
27
|
+
res.json({ driver: store.name, collections: all.filter(visible) });
|
|
28
|
+
});
|
|
29
|
+
r.get("/admin/api/collection", async (req, res) => {
|
|
30
|
+
const name = String(req.query.name || "");
|
|
31
|
+
if (!visible(name)) return res.status(403).json({ ok: false, error: "hidden" });
|
|
32
|
+
res.json({ ok: true, name, docs: (await store.collection(name).all()).slice(0, 500) });
|
|
33
|
+
});
|
|
34
|
+
r.delete("/admin/api/doc", async (req, res) => {
|
|
35
|
+
const name = String(req.query.name || "");
|
|
36
|
+
const id = String(req.query.id || "");
|
|
37
|
+
if (!visible(name)) return res.status(403).json({ ok: false, error: "hidden" });
|
|
38
|
+
if (!id) return res.status(400).json({ ok: false, error: "missing id" });
|
|
39
|
+
await store.collection(name).delete(id);
|
|
40
|
+
res.json({ ok: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return r;
|
|
44
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// admin-ui.js — the role-gated admin panel (frontend for the admin add-on).
|
|
2
|
+
// Renders nothing for non-admins; for admins, a data browser over /admin/api/*.
|
|
3
|
+
// Mounted by the app when the admin add-on is enabled.
|
|
4
|
+
import { signal, html } from "/volt.js";
|
|
5
|
+
|
|
6
|
+
const j = async (url, opts) => {
|
|
7
|
+
const res = await fetch(url, opts);
|
|
8
|
+
return { status: res.status, body: await res.json().catch(() => ({})) };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function adminPanel() {
|
|
12
|
+
const ready = signal(false);
|
|
13
|
+
const isAdmin = signal(false);
|
|
14
|
+
const driver = signal("");
|
|
15
|
+
const collections = signal([]);
|
|
16
|
+
const current = signal("");
|
|
17
|
+
const docs = signal([]);
|
|
18
|
+
const note = signal("");
|
|
19
|
+
|
|
20
|
+
async function init() {
|
|
21
|
+
const { status, body } = await j("/admin/api/me");
|
|
22
|
+
if (status === 200) isAdmin(!!body.isAdmin);
|
|
23
|
+
ready(true);
|
|
24
|
+
if (isAdmin()) load();
|
|
25
|
+
}
|
|
26
|
+
async function load() {
|
|
27
|
+
const { body } = await j("/admin/api/collections");
|
|
28
|
+
driver(body.driver || "");
|
|
29
|
+
collections(body.collections || []);
|
|
30
|
+
if (!current() && collections().length) open(collections()[0]);
|
|
31
|
+
}
|
|
32
|
+
async function open(name) {
|
|
33
|
+
current(name);
|
|
34
|
+
const { body } = await j(`/admin/api/collection?name=${encodeURIComponent(name)}`);
|
|
35
|
+
docs(body.ok ? body.docs : []);
|
|
36
|
+
}
|
|
37
|
+
async function del(id) {
|
|
38
|
+
await j(`/admin/api/doc?name=${encodeURIComponent(current())}&id=${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
39
|
+
docs(docs().filter((d) => d.id !== id));
|
|
40
|
+
note("Deleted.");
|
|
41
|
+
}
|
|
42
|
+
init();
|
|
43
|
+
|
|
44
|
+
const tab = (name) =>
|
|
45
|
+
html`<button class=${() => "btn btn-sm " + (current() === name ? "btn-primary" : "btn-outline-secondary")} onclick=${() => open(name)}>${name}</button>`;
|
|
46
|
+
const row = (d) =>
|
|
47
|
+
html`<div class="d-flex justify-content-between align-items-start gap-2 py-1" style="border-top:1px solid #232a36">
|
|
48
|
+
<pre class="mb-0 small flex-grow-1" style="white-space:pre-wrap;color:#cfe3ff">${JSON.stringify(d, null, 2)}</pre>
|
|
49
|
+
<button class="btn btn-sm btn-outline-danger" onclick=${() => del(d.id)}>✕</button>
|
|
50
|
+
</div>`;
|
|
51
|
+
|
|
52
|
+
// hidden entirely for non-admins (and until we know)
|
|
53
|
+
return html`${() =>
|
|
54
|
+
!ready() || !isAdmin()
|
|
55
|
+
? null
|
|
56
|
+
: html`<div class="card-x p-4 mb-4">
|
|
57
|
+
<h2 class="h6 mb-3">Admin <span class="text-muted small">— data ${() => (driver() ? "· " + driver() : "")}</span></h2>
|
|
58
|
+
<div class="d-flex flex-wrap gap-1 mb-2">${() => (collections().length ? collections().map(tab) : html`<span class="text-muted small">No collections yet.</span>`)}</div>
|
|
59
|
+
<div style="max-height:260px;overflow:auto">${() => (docs().length ? docs().map(row) : html`<span class="text-muted small">Empty.</span>`)}</div>
|
|
60
|
+
${() => (note() ? html`<p class="small text-muted mb-0 mt-2">${note}</p>` : null)}
|
|
61
|
+
</div>`}`;
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Opt-in role-gated web admin: a persistent /admin data browser for browser-only admins (auth + ADMIN_EMAILS allowlist). Adds a standing surface — prefer `--studio` unless you need non-shell admins.",
|
|
3
|
+
"dependsOn": ["db", "auth"],
|
|
4
|
+
"sentinel": "lib/admin.js",
|
|
5
|
+
"install": ["express"],
|
|
6
|
+
"optional": {},
|
|
7
|
+
"wiring": "Set ADMIN_EMAILS in .env to a comma-separated allowlist of admin emails. Only those signed-in users see the admin panel and can reach /admin/api/*."
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -86,4 +86,11 @@ if (enabled.includes("realtime")) {
|
|
|
86
86
|
/* realtime UI unavailable */
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
if (enabled.includes("admin")) {
|
|
90
|
+
try {
|
|
91
|
+
nodes.push((await import("/admin-ui.js")).adminPanel());
|
|
92
|
+
} catch {
|
|
93
|
+
/* admin UI unavailable */
|
|
94
|
+
}
|
|
95
|
+
}
|
|
89
96
|
mount("#app", ...nodes);
|
|
@@ -22,7 +22,7 @@ const PKG_PATH = path.join(__dirname, "package.json");
|
|
|
22
22
|
const ADDONS_DIR = path.join(__dirname, ".volt", "addons"); // bundled add-on sources
|
|
23
23
|
const DEFAULT_PORT = 26628; // create-volt stamps this with the project's date-port
|
|
24
24
|
const PKG_VERSIONS = { mongodb: "^6.8.0", mysql2: "^3.11.0", pg: "^8.12.0", nodemailer: "^6.9.0" };
|
|
25
|
-
const LIB_FILE = { db: "store.js", mailer: "mailer.js", auth: "auth.js", realtime: "realtime.js" };
|
|
25
|
+
const LIB_FILE = { db: "store.js", mailer: "mailer.js", auth: "auth.js", realtime: "realtime.js", admin: "admin.js" };
|
|
26
26
|
|
|
27
27
|
// --- tiny .env loader (no dependency); never overrides an existing env var ---
|
|
28
28
|
function readEnvFile() {
|
|
@@ -101,6 +101,11 @@ async function startApp() {
|
|
|
101
101
|
if (enabled.has("db")) store = await (await addonMod("db")).createStore();
|
|
102
102
|
if (enabled.has("mailer")) mailer = await (await addonMod("mailer")).createMailer();
|
|
103
103
|
if (enabled.has("auth") && store && mailer) app.use((await addonMod("auth")).authRouter({ store, mailer }));
|
|
104
|
+
if (enabled.has("admin") && store && enabled.has("auth")) {
|
|
105
|
+
const adminEmails = String(process.env.ADMIN_EMAILS || "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
106
|
+
const requireAuth = (await addonMod("auth")).requireAuth(store);
|
|
107
|
+
app.use((await addonMod("admin")).adminRouter({ store, requireAuth, adminEmails }));
|
|
108
|
+
}
|
|
104
109
|
|
|
105
110
|
// expose which add-ons are on, and serve each enabled add-on's frontend assets
|
|
106
111
|
app.get("/__volt/addons", (_req, res) => res.json([...enabled]));
|
|
@@ -17,6 +17,7 @@ const state = signal({
|
|
|
17
17
|
dbUrl: current.DATABASE_URL || "",
|
|
18
18
|
smtpUrl: current.SMTP_URL || "",
|
|
19
19
|
mailFrom: current.MAIL_FROM || "",
|
|
20
|
+
adminEmails: current.ADMIN_EMAILS || "",
|
|
20
21
|
port: current.PORT || String(defaultPort),
|
|
21
22
|
});
|
|
22
23
|
const set = (patch) => state({ ...state(), ...patch });
|
|
@@ -53,6 +54,7 @@ function genEnv(s) {
|
|
|
53
54
|
else out.push("# SMTP_URL= # unset → emails print to the console");
|
|
54
55
|
if (s.mailFrom) out.push(`MAIL_FROM=${clean(s.mailFrom)}`);
|
|
55
56
|
}
|
|
57
|
+
if (eff.includes("admin")) out.push(`ADMIN_EMAILS=${clean(s.adminEmails)}`);
|
|
56
58
|
return out.join("\n") + "\n";
|
|
57
59
|
}
|
|
58
60
|
const env = computed(() => genEnv(state()));
|
|
@@ -148,6 +150,7 @@ mount(
|
|
|
148
150
|
${field("PORT", "port", String(defaultPort))}
|
|
149
151
|
${() => (eff().includes("db") ? dbSettings() : null)}
|
|
150
152
|
${() => (eff().includes("mailer") ? html`${field("SMTP_URL (optional)", "smtpUrl", "smtp://user:pass@smtp.host:587")}${field("MAIL_FROM", "mailFrom", "App <no-reply@you.com>")}` : null)}
|
|
153
|
+
${() => (eff().includes("admin") ? field("ADMIN_EMAILS (comma-separated)", "adminEmails", "you@example.com") : null)}
|
|
151
154
|
</div>`,
|
|
152
155
|
html`<div class="card-x p-4 mb-3">
|
|
153
156
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
@@ -137,11 +137,21 @@ if (hasChat) {
|
|
|
137
137
|
/* chat UI unavailable */
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
// Admin tab appears only for users in the ADMIN_EMAILS allowlist.
|
|
141
|
+
if (enabled.includes("admin")) {
|
|
142
|
+
try {
|
|
143
|
+
const r = await (await fetch("/admin/api/me")).json();
|
|
144
|
+
if (r.isAdmin) sections.admin = (await import("/admin-ui.js")).adminPanel();
|
|
145
|
+
} catch {
|
|
146
|
+
/* not signed in / not admin */
|
|
147
|
+
}
|
|
148
|
+
}
|
|
140
149
|
|
|
141
150
|
const TABS = [
|
|
142
151
|
["home", "Home"],
|
|
143
152
|
...(hasAuth ? [["notes", "Notes"]] : []),
|
|
144
153
|
...(sections.chat ? [["chat", "Chat"]] : []),
|
|
154
|
+
...(sections.admin ? [["admin", "Admin"]] : []),
|
|
145
155
|
["account", "Account"],
|
|
146
156
|
];
|
|
147
157
|
|
|
@@ -23,7 +23,7 @@ const PKG_PATH = path.join(__dirname, "package.json");
|
|
|
23
23
|
const ADDONS_DIR = path.join(__dirname, ".volt", "addons"); // bundled add-on sources
|
|
24
24
|
const DEFAULT_PORT = 26628; // create-volt stamps this with the project's date-port
|
|
25
25
|
const PKG_VERSIONS = { mongodb: "^6.8.0", mysql2: "^3.11.0", pg: "^8.12.0", nodemailer: "^6.9.0" };
|
|
26
|
-
const LIB_FILE = { db: "store.js", mailer: "mailer.js", auth: "auth.js", realtime: "realtime.js" };
|
|
26
|
+
const LIB_FILE = { db: "store.js", mailer: "mailer.js", auth: "auth.js", realtime: "realtime.js", admin: "admin.js" };
|
|
27
27
|
|
|
28
28
|
// --- tiny .env loader (no dependency); never overrides an existing env var ---
|
|
29
29
|
function readEnvFile() {
|
|
@@ -102,6 +102,11 @@ async function startApp() {
|
|
|
102
102
|
if (enabled.has("db")) store = await (await addonMod("db")).createStore();
|
|
103
103
|
if (enabled.has("mailer")) mailer = await (await addonMod("mailer")).createMailer();
|
|
104
104
|
if (enabled.has("auth") && store && mailer) app.use((await addonMod("auth")).authRouter({ store, mailer }));
|
|
105
|
+
if (enabled.has("admin") && store && enabled.has("auth")) {
|
|
106
|
+
const adminEmails = String(process.env.ADMIN_EMAILS || "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
107
|
+
const requireAuth = (await addonMod("auth")).requireAuth(store);
|
|
108
|
+
app.use((await addonMod("admin")).adminRouter({ store, requireAuth, adminEmails }));
|
|
109
|
+
}
|
|
105
110
|
|
|
106
111
|
// notes — a per-user CRUD example (auth-gated, owner-scoped, db-backed)
|
|
107
112
|
if (enabled.has("db") && enabled.has("auth") && store) {
|
|
@@ -17,6 +17,7 @@ const state = signal({
|
|
|
17
17
|
dbUrl: current.DATABASE_URL || "",
|
|
18
18
|
smtpUrl: current.SMTP_URL || "",
|
|
19
19
|
mailFrom: current.MAIL_FROM || "",
|
|
20
|
+
adminEmails: current.ADMIN_EMAILS || "",
|
|
20
21
|
port: current.PORT || String(defaultPort),
|
|
21
22
|
});
|
|
22
23
|
const set = (patch) => state({ ...state(), ...patch });
|
|
@@ -53,6 +54,7 @@ function genEnv(s) {
|
|
|
53
54
|
else out.push("# SMTP_URL= # unset → emails print to the console");
|
|
54
55
|
if (s.mailFrom) out.push(`MAIL_FROM=${clean(s.mailFrom)}`);
|
|
55
56
|
}
|
|
57
|
+
if (eff.includes("admin")) out.push(`ADMIN_EMAILS=${clean(s.adminEmails)}`);
|
|
56
58
|
return out.join("\n") + "\n";
|
|
57
59
|
}
|
|
58
60
|
const env = computed(() => genEnv(state()));
|
|
@@ -148,6 +150,7 @@ mount(
|
|
|
148
150
|
${field("PORT", "port", String(defaultPort))}
|
|
149
151
|
${() => (eff().includes("db") ? dbSettings() : null)}
|
|
150
152
|
${() => (eff().includes("mailer") ? html`${field("SMTP_URL (optional)", "smtpUrl", "smtp://user:pass@smtp.host:587")}${field("MAIL_FROM", "mailFrom", "App <no-reply@you.com>")}` : null)}
|
|
153
|
+
${() => (eff().includes("admin") ? field("ADMIN_EMAILS (comma-separated)", "adminEmails", "you@example.com") : null)}
|
|
151
154
|
</div>`,
|
|
152
155
|
html`<div class="card-x p-4 mb-3">
|
|
153
156
|
<div class="d-flex justify-content-between align-items-center mb-2">
|