@basicbenframework/cms 0.9.0 → 0.10.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.
Files changed (50) hide show
  1. package/lib/client/components/Nav/DesktopNav.js +3 -1
  2. package/lib/client/components/Nav/MobileNav.js +3 -1
  3. package/lib/client/components/admin/ConfigField.d.ts +34 -0
  4. package/lib/client/components/admin/ConfigField.js +26 -0
  5. package/lib/client/hooks/useRegistrationOpen.d.ts +1 -0
  6. package/lib/client/hooks/useRegistrationOpen.js +31 -0
  7. package/lib/client/host/index.d.ts +5 -0
  8. package/lib/client/i18n/locales/es/site.js +40 -0
  9. package/lib/client/pages/Auth.js +3 -1
  10. package/lib/client/pages/admin/Health.js +5 -1
  11. package/lib/client/pages/admin/Settings.js +41 -4
  12. package/lib/client/styles.css +9 -0
  13. package/lib/controllers/AuthController.js +2 -1
  14. package/lib/controllers/EmailVerificationController.js +2 -1
  15. package/lib/controllers/HealthController.js +15 -5
  16. package/lib/controllers/MediaController.js +5 -5
  17. package/lib/controllers/PasskeyController.js +2 -1
  18. package/lib/controllers/PasswordResetController.js +2 -1
  19. package/lib/controllers/SettingsController.d.ts +0 -8
  20. package/lib/controllers/SettingsController.js +72 -20
  21. package/lib/controllers/TwoFactorController.js +2 -1
  22. package/lib/controllers/UserController.js +1 -1
  23. package/lib/features/analytics/controller.js +2 -1
  24. package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +1 -1
  25. package/lib/features/mysendbox/MySendboxSettingsCard.js +15 -5
  26. package/lib/features/mysendbox/config.d.ts +10 -7
  27. package/lib/features/mysendbox/config.js +17 -10
  28. package/lib/features/mysendbox/i18n/es.js +6 -1
  29. package/lib/helpers/config.d.ts +77 -0
  30. package/lib/helpers/config.js +158 -0
  31. package/lib/helpers/export-data.js +1 -1
  32. package/lib/helpers/health.js +4 -4
  33. package/lib/helpers/images.js +2 -1
  34. package/lib/helpers/secrets.d.ts +18 -0
  35. package/lib/helpers/secrets.js +52 -0
  36. package/lib/helpers/site-settings.d.ts +6 -0
  37. package/lib/helpers/site-settings.js +34 -1
  38. package/lib/helpers/site.d.ts +2 -2
  39. package/lib/helpers/site.js +4 -3
  40. package/lib/helpers/storage.d.ts +16 -0
  41. package/lib/helpers/storage.js +58 -0
  42. package/lib/hooks.js +11 -0
  43. package/lib/host/cron.js +5 -0
  44. package/lib/models/Page.js +1 -1
  45. package/lib/models/Post.js +1 -1
  46. package/lib/models/PublicContent.js +2 -1
  47. package/lib/models/Settings.d.ts +1 -1
  48. package/lib/models/Settings.js +4 -2
  49. package/lib/models/User.js +1 -1
  50. package/package.json +1 -1
@@ -3,7 +3,9 @@ import { useTheme } from "../ThemeContext.js";
3
3
  import { NavLink } from "../NavLink.js";
4
4
  import { Button } from "../Button.js";
5
5
  import { DarkModeToggle } from "./DarkModeToggle.js";
6
+ import { useRegistrationOpen } from "../../hooks/useRegistrationOpen.js";
6
7
  export function DesktopNav({ user, navigate, logout }) {
7
8
  const { t, dark, setDark } = useTheme();
8
- return (_jsxs("div", { className: "hidden sm:flex items-center gap-2", children: [!__DISABLE_PUBLIC_SITE__ && _jsx(NavLink, { onClick: () => navigate('/docs'), children: "Docs" }), _jsx("div", { className: `w-px h-5 mx-1 ${dark ? 'bg-white/20' : 'bg-black/20'}` }), _jsx(DarkModeToggle, { dark: dark, setDark: setDark }), user ? (_jsxs(_Fragment, { children: [!__DISABLE_PUBLIC_SITE__ && _jsx(NavLink, { onClick: () => navigate('/feed'), children: "Feed" }), _jsx(NavLink, { onClick: () => navigate('/posts'), children: "My Posts" }), _jsx(NavLink, { onClick: () => navigate('/profile'), children: "Profile" }), _jsx(Button, { variant: "secondary", onClick: logout, className: "px-3 py-1.5", children: "Log out" })] })) : (_jsxs(_Fragment, { children: [_jsx(NavLink, { onClick: () => navigate('/login'), children: "Sign in" }), !__DISABLE_REGISTRATION__ && (_jsx(Button, { onClick: () => navigate('/register'), className: "px-3 py-1.5", children: "Get started" }))] }))] }));
9
+ const registrationOpen = useRegistrationOpen();
10
+ return (_jsxs("div", { className: "hidden sm:flex items-center gap-2", children: [!__DISABLE_PUBLIC_SITE__ && _jsx(NavLink, { onClick: () => navigate('/docs'), children: "Docs" }), _jsx("div", { className: `w-px h-5 mx-1 ${dark ? 'bg-white/20' : 'bg-black/20'}` }), _jsx(DarkModeToggle, { dark: dark, setDark: setDark }), user ? (_jsxs(_Fragment, { children: [!__DISABLE_PUBLIC_SITE__ && _jsx(NavLink, { onClick: () => navigate('/feed'), children: "Feed" }), _jsx(NavLink, { onClick: () => navigate('/posts'), children: "My Posts" }), _jsx(NavLink, { onClick: () => navigate('/profile'), children: "Profile" }), _jsx(Button, { variant: "secondary", onClick: logout, className: "px-3 py-1.5", children: "Log out" })] })) : (_jsxs(_Fragment, { children: [_jsx(NavLink, { onClick: () => navigate('/login'), children: "Sign in" }), registrationOpen && (_jsx(Button, { onClick: () => navigate('/register'), className: "px-3 py-1.5", children: "Get started" }))] }))] }));
9
11
  }
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useTheme } from "../ThemeContext.js";
3
3
  import { Logo } from "../Logo.js";
4
+ import { useRegistrationOpen } from "../../hooks/useRegistrationOpen.js";
4
5
  export function MobileNav({ user, navigate, onClose, logout }) {
5
6
  const { t } = useTheme();
7
+ const registrationOpen = useRegistrationOpen();
6
8
  const handleNav = (view) => {
7
9
  navigate(view);
8
10
  onClose();
@@ -11,5 +13,5 @@ export function MobileNav({ user, navigate, onClose, logout }) {
11
13
  logout();
12
14
  onClose();
13
15
  };
14
- return (_jsx("div", { className: `fixed inset-0 z-50 ${t.bg} ${t.text}`, children: _jsxs("div", { className: "flex flex-col h-full", children: [_jsxs("div", { className: `flex items-center justify-between h-14 px-6 border-b ${t.border}`, children: [_jsxs("span", { className: "flex items-center gap-2 font-semibold", children: [_jsx(Logo, { className: "w-5 h-5" }), _jsx("span", { children: "BasicBen" })] }), _jsx("button", { onClick: onClose, className: `p-2 rounded-lg ${t.card} transition`, "aria-label": "Close menu", children: _jsx("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) })] }), _jsxs("div", { className: "flex-1 overflow-y-auto px-6 py-4", children: [!__DISABLE_PUBLIC_SITE__ && (_jsxs("div", { className: "space-y-1", children: [_jsx("button", { onClick: () => handleNav('/'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Home" }), _jsx("button", { onClick: () => handleNav('/docs'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Docs" })] })), user ? (_jsxs(_Fragment, { children: [_jsx("div", { className: `my-4 border-t ${t.border}` }), _jsx("p", { className: `px-4 py-2 text-xs font-medium uppercase tracking-wider ${t.muted}`, children: "Account" }), _jsxs("div", { className: "space-y-1", children: [!__DISABLE_PUBLIC_SITE__ && (_jsx("button", { onClick: () => handleNav('/feed'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Feed" })), _jsx("button", { onClick: () => handleNav('/posts'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "My Posts" }), _jsx("button", { onClick: () => handleNav('/profile'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Profile" })] }), _jsx("div", { className: `my-4 border-t ${t.border}` }), _jsx("button", { onClick: handleLogout, className: `w-full text-left px-4 py-3 rounded-lg ${t.btnSecondary} transition`, children: "Log out" })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: `my-4 border-t ${t.border}` }), _jsxs("div", { className: "space-y-2", children: [_jsx("button", { onClick: () => handleNav('/login'), className: `w-full px-4 py-3 rounded-lg ${t.btnSecondary} transition`, children: "Sign in" }), !__DISABLE_REGISTRATION__ && (_jsx("button", { onClick: () => handleNav('/register'), className: `w-full px-4 py-3 rounded-lg ${t.btn} ${t.btnHover} transition`, children: "Get started" }))] })] }))] })] }) }));
16
+ return (_jsx("div", { className: `fixed inset-0 z-50 ${t.bg} ${t.text}`, children: _jsxs("div", { className: "flex flex-col h-full", children: [_jsxs("div", { className: `flex items-center justify-between h-14 px-6 border-b ${t.border}`, children: [_jsxs("span", { className: "flex items-center gap-2 font-semibold", children: [_jsx(Logo, { className: "w-5 h-5" }), _jsx("span", { children: "BasicBen" })] }), _jsx("button", { onClick: onClose, className: `p-2 rounded-lg ${t.card} transition`, "aria-label": "Close menu", children: _jsx("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) })] }), _jsxs("div", { className: "flex-1 overflow-y-auto px-6 py-4", children: [!__DISABLE_PUBLIC_SITE__ && (_jsxs("div", { className: "space-y-1", children: [_jsx("button", { onClick: () => handleNav('/'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Home" }), _jsx("button", { onClick: () => handleNav('/docs'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Docs" })] })), user ? (_jsxs(_Fragment, { children: [_jsx("div", { className: `my-4 border-t ${t.border}` }), _jsx("p", { className: `px-4 py-2 text-xs font-medium uppercase tracking-wider ${t.muted}`, children: "Account" }), _jsxs("div", { className: "space-y-1", children: [!__DISABLE_PUBLIC_SITE__ && (_jsx("button", { onClick: () => handleNav('/feed'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Feed" })), _jsx("button", { onClick: () => handleNav('/posts'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "My Posts" }), _jsx("button", { onClick: () => handleNav('/profile'), className: `w-full text-left px-4 py-3 rounded-lg ${t.card} hover:opacity-80 transition`, children: "Profile" })] }), _jsx("div", { className: `my-4 border-t ${t.border}` }), _jsx("button", { onClick: handleLogout, className: `w-full text-left px-4 py-3 rounded-lg ${t.btnSecondary} transition`, children: "Log out" })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: `my-4 border-t ${t.border}` }), _jsxs("div", { className: "space-y-2", children: [_jsx("button", { onClick: () => handleNav('/login'), className: `w-full px-4 py-3 rounded-lg ${t.btnSecondary} transition`, children: "Sign in" }), registrationOpen && (_jsx("button", { onClick: () => handleNav('/register'), className: `w-full px-4 py-3 rounded-lg ${t.btn} ${t.btnHover} transition`, children: "Get started" }))] })] }))] })] }) }));
15
17
  }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ /** Where a configurable value comes from, as `GET /api/settings` reports it (helpers/config.ts). */
3
+ export interface ConfigStatus {
4
+ env: string;
5
+ setting: string;
6
+ label: string;
7
+ group: string;
8
+ secret: boolean;
9
+ source: 'env' | 'settings' | 'unset' | 'unreadable';
10
+ locked_by: string | null;
11
+ value: string | null;
12
+ }
13
+ interface Props {
14
+ name: string;
15
+ label: string;
16
+ help?: React.ReactNode;
17
+ value: string;
18
+ onChange(value: string): void;
19
+ /** This setting's entry from `config`; absent for a plain setting. */
20
+ status?: ConfigStatus;
21
+ /** For a secret: whether one is saved. */
22
+ saved?: boolean;
23
+ placeholder?: string;
24
+ }
25
+ /**
26
+ * A setting the environment can also set.
27
+ *
28
+ * - Set by the environment: shown disabled, with the variable named. The
29
+ * value in use is shown unless it is a secret.
30
+ * - Secret: a password field that starts blank. The saved value never reaches
31
+ * the browser; leaving the field blank keeps it.
32
+ */
33
+ export declare function ConfigField({ name, label, help, value, onChange, status, saved, placeholder }: Props): React.JSX.Element;
34
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useT, slots } from "../../i18n/index.js";
3
+ const hint = { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' };
4
+ /**
5
+ * A setting the environment can also set.
6
+ *
7
+ * - Set by the environment: shown disabled, with the variable named. The
8
+ * value in use is shown unless it is a secret.
9
+ * - Secret: a password field that starts blank. The saved value never reaches
10
+ * the browser; leaving the field blank keeps it.
11
+ */
12
+ export function ConfigField({ name, label, help, value, onChange, status, saved, placeholder }) {
13
+ const { t } = useT();
14
+ const locked = status?.locked_by;
15
+ const secret = Boolean(status?.secret);
16
+ let shown = value;
17
+ let hold = placeholder;
18
+ if (locked) {
19
+ shown = secret ? '' : status?.value ?? '';
20
+ hold = secret ? t('Set in the environment') : hold;
21
+ }
22
+ else if (secret && saved) {
23
+ hold = t('Saved. Leave blank to keep it.');
24
+ }
25
+ return (_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: name, children: label }), _jsx("input", { id: name, name: name, type: secret ? 'password' : 'text', autoComplete: secret ? 'new-password' : 'off', value: shown, onChange: (e) => onChange(e.target.value), className: "admin-input", placeholder: hold, disabled: Boolean(locked) }), locked ? (_jsx("p", { style: hint, children: slots(t('Set by {variable} in the environment, which wins over this setting.'), { variable: _jsx("code", { children: locked }) }) })) : status?.source === 'unreadable' ? (_jsx("p", { style: { ...hint, color: 'var(--danger)' }, children: t('The saved value cannot be read. APP_KEY has changed since it was saved; enter it again.') })) : (help && _jsx("p", { style: hint, children: help }))] }));
26
+ }
@@ -0,0 +1 @@
1
+ export declare function useRegistrationOpen(): boolean;
@@ -0,0 +1,31 @@
1
+ import { useEffect, useState } from 'react';
2
+ /**
3
+ * Whether new accounts may register, for hiding the sign-up links.
4
+ *
5
+ * Two switches close registration: DISABLE_REGISTRATION at build time (which
6
+ * also drops the /register route), and the Registration setting, which can
7
+ * change without a rebuild and so is asked of the server (`GET /api/site`).
8
+ * Either one closes it. The server refuses a registration on its own either
9
+ * way; this only keeps the admin from offering a door that is shut.
10
+ *
11
+ * Asked once per page load and shared by every caller.
12
+ */
13
+ let pending = null;
14
+ function fetchOpen() {
15
+ pending ??= fetch('/api/site', { headers: { Accept: 'application/json' } })
16
+ .then((res) => (res.ok ? res.json() : null))
17
+ .then((body) => body?.registration_open !== false)
18
+ .catch(() => true);
19
+ return pending;
20
+ }
21
+ export function useRegistrationOpen() {
22
+ const [open, setOpen] = useState(!__DISABLE_REGISTRATION__);
23
+ useEffect(() => {
24
+ if (__DISABLE_REGISTRATION__)
25
+ return;
26
+ let live = true;
27
+ fetchOpen().then((value) => live && setOpen(value));
28
+ return () => { live = false; };
29
+ }, []);
30
+ return open;
31
+ }
@@ -10,6 +10,7 @@
10
10
  import { type ComponentType, type ReactNode } from 'react';
11
11
  import { type Dictionary } from '../i18n/index.ts';
12
12
  import type { FeatureManifest } from '../../host/manifest.ts';
13
+ import type { ConfigStatus } from '../components/admin/ConfigField.tsx';
13
14
  export interface AdminFeature {
14
15
  name: string;
15
16
  register(admin: AdminHost): void;
@@ -59,6 +60,10 @@ export declare function registerAdminFeatures(features: AdminFeature[], manifest
59
60
  export interface SettingsSectionProps {
60
61
  values: Record<string, string>;
61
62
  onChange(changes: Record<string, string>): void;
63
+ /** Where each value the environment can also set comes from (helpers/config.ts). */
64
+ config?: ConfigStatus[];
65
+ /** Which secret settings are saved. Their values are never sent. */
66
+ secrets?: Record<string, boolean>;
62
67
  }
63
68
  /** Whether any feature fills a slot. */
64
69
  export declare function hasFills(name: SlotName): boolean;
@@ -209,5 +209,45 @@ const strings = {
209
209
  "Sends a short message to your own account's address — never to any other.": 'Envía un mensaje breve a la dirección de tu propia cuenta, nunca a ninguna otra.',
210
210
  'Sending…': 'Enviando…',
211
211
  'Send test email to me': 'Enviarme un correo de prueba',
212
+ "Configuration": "Configuración",
213
+ "Where each value comes from. The environment wins over Settings; secrets show whether they are set, never what they are.": "De dónde sale cada valor. El entorno tiene prioridad sobre los Ajustes; de los secretos solo se muestra si están definidos, nunca su valor.",
214
+ "Value": "Valor",
215
+ "Variable": "Variable",
216
+ "In use": "En uso",
217
+ "Environment": "Entorno",
218
+ "Settings (unreadable: re-enter it)": "Ajustes (ilegible: vuelve a introducirlo)",
219
+ "Not used: {variable} is set": "Sin uso: {variable} está definida",
220
+ "Not set": "Sin definir",
221
+ "Set": "Definido",
222
+ "Set by {variable} in the environment, which wins over this setting.": "Lo define {variable} en el entorno, que tiene prioridad sobre este ajuste.",
223
+ "Set in the environment": "Definido en el entorno",
224
+ "Saved. Leave blank to keep it.": "Guardado. Déjalo en blanco para conservarlo.",
225
+ "The saved value cannot be read. APP_KEY has changed since it was saved; enter it again.": "No se puede leer el valor guardado. APP_KEY ha cambiado desde que se guardó; vuelve a introducirlo.",
226
+ "The public site, if it is not this app. Feeds, the sitemap and {path} link to it. Blank uses APP_URL.": "El sitio público, si no es esta aplicación. Los feeds, el mapa del sitio y {path} enlazan a él. En blanco se usa APP_URL.",
227
+ "Registration": "Registro",
228
+ "Who can create an account": "Quién puede crear una cuenta",
229
+ "Anyone, from the sign-up page": "Cualquiera, desde la página de registro",
230
+ "Only people you invite from Users": "Solo las personas que invites desde Usuarios",
231
+ "The first account can always be created, so a new site can make its admin.": "La primera cuenta siempre se puede crear, para que un sitio nuevo pueda tener su administrador.",
232
+ "Media Storage": "Almacenamiento de medios",
233
+ "Storage is configured by {variable} and the other S3 variables in the environment, which win over these settings.": "El almacenamiento lo configuran {variable} y las demás variables S3 del entorno, que tienen prioridad sobre estos ajustes.",
234
+ "Any S3-compatible bucket: Cloudflare R2, AWS S3, Backblaze B2, MinIO. Without one, uploads go to this server's disk, which serverless hosts do not keep.": "Cualquier bucket compatible con S3: Cloudflare R2, AWS S3, Backblaze B2, MinIO. Sin uno, las subidas van al disco de este servidor, que los hosts serverless no conservan.",
235
+ "Bucket": "Bucket",
236
+ "Endpoint": "Endpoint",
237
+ "Blank for AWS S3.": "En blanco para AWS S3.",
238
+ "Region": "Región",
239
+ "auto for R2; the bucket's region for AWS S3.": "auto para R2; la región del bucket para AWS S3.",
240
+ "Public URL": "URL pública",
241
+ "Where the files are served from: a custom domain or CDN in front of the bucket.": "Desde dónde se sirven los archivos: un dominio propio o una CDN delante del bucket.",
242
+ "Access key ID": "ID de la clave de acceso",
243
+ "Secret access key": "Clave de acceso secreta",
244
+ "Stored encrypted with APP_KEY and never shown again.": "Se guarda cifrada con APP_KEY y no se vuelve a mostrar.",
245
+ "Image transform URL": "URL de transformación de imágenes",
246
+ "Optional. A resizing service template with {url} and {width}, so images get a srcset.": "Opcional. Una plantilla de un servicio de redimensionado con {url} y {width}, para que las imágenes tengan srcset.",
247
+ "Site name": "Nombre del sitio",
248
+ "Registration closed": "Registro cerrado",
249
+ "Public theme": "Tema público",
250
+ "MySendbox API key": "Clave de API de MySendbox",
251
+ "MySendbox API URL": "URL de la API de MySendbox",
212
252
  };
213
253
  export default strings;
@@ -6,6 +6,7 @@ import { Input } from "../components/Input.js";
6
6
  import { Button } from "../components/Button.js";
7
7
  import { api } from "../../helpers/api.js";
8
8
  import { useToast } from "../contexts/ToastContext.js";
9
+ import { useRegistrationOpen } from "../hooks/useRegistrationOpen.js";
9
10
  export function Auth() {
10
11
  const { setUser } = useAuth();
11
12
  const navigate = useNavigate();
@@ -15,6 +16,7 @@ export function Auth() {
15
16
  const [form, setForm] = useState({ name: '', email: '', password: '' });
16
17
  const [loading, setLoading] = useState(false);
17
18
  const isLogin = path === '/login';
19
+ const registrationOpen = useRegistrationOpen();
18
20
  const handleSubmit = async (e) => {
19
21
  e.preventDefault();
20
22
  setLoading(true);
@@ -36,5 +38,5 @@ export function Auth() {
36
38
  setLoading(false);
37
39
  }
38
40
  };
39
- return (_jsxs("div", { className: "max-w-xs mx-auto py-8", children: [_jsx("h1", { className: "text-2xl font-bold text-center mb-1", children: isLogin ? 'Welcome back' : 'Create account' }), _jsx("p", { className: `text-sm ${t.muted} text-center mb-6`, children: isLogin ? 'Sign in to continue' : 'Get started for free' }), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-3 mt-4", children: [!isLogin && _jsx(Input, { placeholder: "Name", required: true, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) }), _jsx(Input, { type: "email", placeholder: "Email", required: true, value: form.email, onChange: (e) => setForm({ ...form, email: e.target.value }) }), _jsx(Input, { type: "password", placeholder: "Password", required: true, minLength: 8, value: form.password, onChange: (e) => setForm({ ...form, password: e.target.value }) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : isLogin ? 'Sign in' : 'Create account' })] }), isLogin && (_jsx("p", { className: `text-xs ${t.muted} text-center mt-4`, children: _jsx("button", { onClick: () => navigate('/forgot-password'), className: "underline hover:no-underline", children: "Forgot password?" }) })), !__DISABLE_REGISTRATION__ && (_jsxs("p", { className: `text-xs ${t.muted} text-center mt-4`, children: [isLogin ? "Don't have an account? " : 'Have an account? ', _jsx("button", { onClick: () => navigate(isLogin ? '/register' : '/login'), className: "underline hover:no-underline", children: isLogin ? 'Sign up' : 'Sign in' })] }))] }));
41
+ return (_jsxs("div", { className: "max-w-xs mx-auto py-8", children: [_jsx("h1", { className: "text-2xl font-bold text-center mb-1", children: isLogin ? 'Welcome back' : 'Create account' }), _jsx("p", { className: `text-sm ${t.muted} text-center mb-6`, children: isLogin ? 'Sign in to continue' : 'Get started for free' }), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-3 mt-4", children: [!isLogin && _jsx(Input, { placeholder: "Name", required: true, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) }), _jsx(Input, { type: "email", placeholder: "Email", required: true, value: form.email, onChange: (e) => setForm({ ...form, email: e.target.value }) }), _jsx(Input, { type: "password", placeholder: "Password", required: true, minLength: 8, value: form.password, onChange: (e) => setForm({ ...form, password: e.target.value }) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : isLogin ? 'Sign in' : 'Create account' })] }), isLogin && (_jsx("p", { className: `text-xs ${t.muted} text-center mt-4`, children: _jsx("button", { onClick: () => navigate('/forgot-password'), className: "underline hover:no-underline", children: "Forgot password?" }) })), registrationOpen && (_jsxs("p", { className: `text-xs ${t.muted} text-center mt-4`, children: [isLogin ? "Don't have an account? " : 'Have an account? ', _jsx("button", { onClick: () => navigate(isLogin ? '/register' : '/login'), className: "underline hover:no-underline", children: isLogin ? 'Sign up' : 'Sign in' })] }))] }));
40
42
  }
@@ -76,7 +76,11 @@ export default function AdminHealth() {
76
76
  count: counts.pass.toLocaleString(locale)
77
77
  }), _jsxs("span", { className: "health-muted", children: [' ', report.environment.serverless
78
78
  ? t('NODE_ENV {env}, serverless · checked {time}', { env: report.environment.node_env ?? t('unset'), time: new Date(report.generated_at).toLocaleTimeString(locale) })
79
- : t('NODE_ENV {env} · checked {time}', { env: report.environment.node_env ?? t('unset'), time: new Date(report.generated_at).toLocaleTimeString(locale) })] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary health-refresh", onClick: load, disabled: loading, children: loading ? t('Checking…') : t('Re-check') })] })), loading && !report && _jsx("div", { className: "admin-card", children: t('Checking…') }), checks.length > 0 && (_jsx("div", { className: "admin-card", children: _jsx("ul", { className: "health-list", children: checks.map((c) => (_jsxs("li", { className: "health-item", children: [_jsx("span", { className: `health-pill health-pill-${c.status}`, children: LABEL[c.status] }), _jsxs("div", { children: [_jsx("div", { className: "health-label", children: c.label }), _jsx("div", { className: "health-message", children: c.message }), c.hint && _jsx("div", { className: "health-hint", children: c.hint })] })] }, c.id))) }) })), _jsxs("div", { className: "admin-card", children: [_jsx("div", { className: "admin-card-header", children: _jsx("h2", { className: "admin-card-title", children: t('Live checks') }) }), _jsxs("div", { className: "health-actions", children: [_jsxs("div", { children: [_jsxs("p", { children: [_jsx("strong", { children: t('Storage probe.') }), ' ', slots(t('Writes a small file under {path}, reads it back and deletes it, using the same credentials uploads use.'), { path: _jsx("code", { children: 'health-probe/' }) })] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: runProbe, disabled: probing, children: probing ? t('Probing…') : t('Run storage probe') }), probe && (_jsx("ul", { className: "health-steps", children: probe.steps.map((s) => (_jsxs("li", { className: s.ok ? 'health-ok' : 'health-bad', children: [s.step, ": ", s.ok ? t('ok ({ms} ms)', { ms: s.ms }) : s.error] }, s.step))) }))] }), _jsxs("div", { children: [_jsxs("p", { children: [_jsx("strong", { children: t('Test email.') }), ' ', t("Sends a short message to your own account's address — never to any other.")] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: sendTest, disabled: mailing, children: mailing ? t('Sending…') : t('Send test email to me') }), mail && _jsx("p", { className: "health-muted", children: mail })] })] })] })] }));
79
+ : t('NODE_ENV {env} · checked {time}', { env: report.environment.node_env ?? t('unset'), time: new Date(report.generated_at).toLocaleTimeString(locale) })] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary health-refresh", onClick: load, disabled: loading, children: loading ? t('Checking…') : t('Re-check') })] })), loading && !report && _jsx("div", { className: "admin-card", children: t('Checking…') }), checks.length > 0 && (_jsx("div", { className: "admin-card", children: _jsx("ul", { className: "health-list", children: checks.map((c) => (_jsxs("li", { className: "health-item", children: [_jsx("span", { className: `health-pill health-pill-${c.status}`, children: LABEL[c.status] }), _jsxs("div", { children: [_jsx("div", { className: "health-label", children: c.label }), _jsx("div", { className: "health-message", children: c.message }), c.hint && _jsx("div", { className: "health-hint", children: c.hint })] })] }, c.id))) }) })), report?.config && report.config.length > 0 && (_jsxs("div", { className: "admin-card", children: [_jsx("div", { className: "admin-card-header", children: _jsx("h2", { className: "admin-card-title", children: t('Configuration') }) }), _jsx("p", { className: "health-muted", style: { marginTop: 0 }, children: t('Where each value comes from. The environment wins over Settings; secrets show whether they are set, never what they are.') }), _jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t('Value') }), _jsx("th", { children: t('Variable') }), _jsx("th", { children: t('Source') }), _jsx("th", { children: t('In use') })] }) }), _jsx("tbody", { children: report.config.map((entry) => (_jsxs("tr", { children: [_jsx("td", { children: t(entry.label) }), _jsx("td", { children: _jsx("code", { children: entry.env }) }), _jsx("td", { children: entry.source === 'env' ? t('Environment')
80
+ : entry.source === 'settings' ? t('Settings')
81
+ : entry.source === 'unreadable' ? t('Settings (unreadable: re-enter it)')
82
+ : entry.locked_by ? slots(t('Not used: {variable} is set'), { variable: _jsx("code", { children: entry.locked_by }) })
83
+ : t('Not set') }), _jsx("td", { children: entry.source === 'unset' || entry.source === 'unreadable' ? '—' : entry.secret ? t('Set') : entry.value })] }, entry.env))) })] })] })), _jsxs("div", { className: "admin-card", children: [_jsx("div", { className: "admin-card-header", children: _jsx("h2", { className: "admin-card-title", children: t('Live checks') }) }), _jsxs("div", { className: "health-actions", children: [_jsxs("div", { children: [_jsxs("p", { children: [_jsx("strong", { children: t('Storage probe.') }), ' ', slots(t('Writes a small file under {path}, reads it back and deletes it, using the same credentials uploads use.'), { path: _jsx("code", { children: 'health-probe/' }) })] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: runProbe, disabled: probing, children: probing ? t('Probing…') : t('Run storage probe') }), probe && (_jsx("ul", { className: "health-steps", children: probe.steps.map((s) => (_jsxs("li", { className: s.ok ? 'health-ok' : 'health-bad', children: [s.step, ": ", s.ok ? t('ok ({ms} ms)', { ms: s.ms }) : s.error] }, s.step))) }))] }), _jsxs("div", { children: [_jsxs("p", { children: [_jsx("strong", { children: t('Test email.') }), ' ', t("Sends a short message to your own account's address — never to any other.")] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: sendTest, disabled: mailing, children: mailing ? t('Sending…') : t('Send test email to me') }), mail && _jsx("p", { className: "health-muted", children: mail })] })] })] })] }));
80
84
  }
81
85
  const healthStyles = `
82
86
  .health-banner {
@@ -4,6 +4,7 @@ import { api } from "../../../helpers/api.js";
4
4
  import AdminLayout from "../../layouts/AdminLayout.js";
5
5
  import { useT, ADMIN_LOCALES, applySiteLocale, slots } from "../../i18n/index.js";
6
6
  import { Slot } from "../../host/index.js";
7
+ import { ConfigField } from "../../components/admin/ConfigField.js";
7
8
  const DEFAULTS = {
8
9
  site_name: '',
9
10
  site_description: '',
@@ -20,7 +21,16 @@ const DEFAULTS = {
20
21
  locale: 'en',
21
22
  admin_locale: '',
22
23
  code_injection_head: '',
23
- code_injection_foot: ''
24
+ code_injection_foot: '',
25
+ site_url: '',
26
+ disable_registration: 'false',
27
+ image_transform_url: '',
28
+ storage_bucket: '',
29
+ storage_endpoint: '',
30
+ storage_region: '',
31
+ storage_public_url: '',
32
+ storage_access_key_id: '',
33
+ storage_secret_access_key: ''
24
34
  };
25
35
  // The zones the runtime knows, for the picker. The server validates against
26
36
  // the same Intl data, so anything offered here is accepted there.
@@ -34,6 +44,8 @@ const TIME_ZONES = (() => {
34
44
  })();
35
45
  const mono = { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' };
36
46
  const hint = { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' };
47
+ /** The value in use for a configurable setting, when it is not secret. */
48
+ const configValueOf = (status) => status?.value ?? '';
37
49
  export default function AdminSettings() {
38
50
  const { t } = useT();
39
51
  const [settings, setSettings] = useState(DEFAULTS);
@@ -45,6 +57,17 @@ export default function AdminSettings() {
45
57
  // Every stored setting, for features' sections, and what they changed.
46
58
  const [stored, setStored] = useState({});
47
59
  const [extra, setExtra] = useState({});
60
+ // Where each configurable value comes from, and which secrets are saved.
61
+ const [config, setConfig] = useState([]);
62
+ const [secrets, setSecrets] = useState({});
63
+ const statusOf = (setting) => config.find((entry) => entry.setting === setting);
64
+ const field = (name) => ({
65
+ name,
66
+ value: settings[name],
67
+ onChange: (value) => setSettings(prev => ({ ...prev, [name]: value })),
68
+ status: statusOf(name),
69
+ saved: secrets[name]
70
+ });
48
71
  useEffect(() => {
49
72
  loadSettings();
50
73
  }, []);
@@ -64,6 +87,8 @@ export default function AdminSettings() {
64
87
  setStored(Object.fromEntries(Object.entries(res.settings).map(([key, value]) => [key, String(value ?? '')])));
65
88
  }
66
89
  setSiteUrl(res?.site_url || '');
90
+ setConfig(res?.config || []);
91
+ setSecrets(res?.secrets || {});
67
92
  }
68
93
  catch (error) {
69
94
  console.error('Failed to load settings:', error);
@@ -78,7 +103,15 @@ export default function AdminSettings() {
78
103
  setMessage('');
79
104
  setFailed(false);
80
105
  try {
81
- await api.put('/api/settings', { settings: { ...settings, ...extra } });
106
+ const saved = await api.put('/api/settings', { settings: { ...settings, ...extra } });
107
+ // A secret is sent once: clear its field and show it as saved.
108
+ const sent = new Set(Object.keys(saved?.secrets || {}));
109
+ setSettings(prev => Object.fromEntries(Object.entries(prev).map(([key, value]) => [key, sent.has(key) ? '' : value])));
110
+ setExtra(prev => Object.fromEntries(Object.entries(prev).filter(([key]) => !sent.has(key))));
111
+ if (saved?.config)
112
+ setConfig(saved.config);
113
+ if (saved?.secrets)
114
+ setSecrets(saved.secrets);
82
115
  // The admin's own language may have just changed; show it now.
83
116
  await applySiteLocale(settings.admin_locale);
84
117
  setMessage(t('Settings saved successfully!'));
@@ -99,7 +132,7 @@ export default function AdminSettings() {
99
132
  if (loading) {
100
133
  return (_jsx(AdminLayout, { title: t('Settings'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
101
134
  }
102
- return (_jsx(AdminLayout, { title: t('Settings'), children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('General') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site Name') }), _jsx("input", { type: "text", name: "site_name", value: settings.site_name, onChange: handleChange, className: "admin-input", placeholder: t('My Blog') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site Description') }), _jsx("textarea", { name: "site_description", value: settings.site_description, onChange: handleChange, className: "admin-textarea", style: { minHeight: '80px' }, placeholder: t('A brief description of your site') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Site Identity') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site URL') }), _jsx("input", { type: "text", value: siteUrl, className: "admin-input", readOnly: true, disabled: true }), _jsx("p", { style: hint, children: slots(t('Set by {variable} in the environment, not here. Feeds, the sitemap and {path} link to it.'), { variable: _jsx("code", { children: 'SITE_URL' }), path: _jsx("code", { children: '/api/v1/site' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Logo URL') }), _jsx("input", { type: "text", name: "site_logo", value: settings.site_logo, onChange: handleChange, className: "admin-input", placeholder: t('/uploads/logo.svg or https://…') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Icon URL') }), _jsx("input", { type: "text", name: "site_icon", value: settings.site_icon, onChange: handleChange, className: "admin-input", placeholder: t('/uploads/icon.png — favicon and app icon') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Default Social Image URL') }), _jsx("input", { type: "text", name: "default_social_image", value: settings.default_social_image, onChange: handleChange, className: "admin-input", placeholder: t('Used on share cards when a post or page has no image') }), _jsx("p", { style: hint, children: t('Paste a URL from the media library, or a path starting with /.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Language & Time') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Time Zone') }), _jsxs("select", { name: "timezone", value: settings.timezone, onChange: handleChange, className: "admin-select", children: [!TIME_ZONES.includes(settings.timezone) && _jsx("option", { value: settings.timezone, children: settings.timezone }), TIME_ZONES.map(zone => _jsx("option", { value: zone, children: zone }, zone))] }), _jsx("p", { style: hint, children: t('Dates are stored in UTC; this is the zone the front end shows them in.') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Locale') }), _jsx("input", { type: "text", name: "locale", value: settings.locale, onChange: handleChange, className: "admin-input", placeholder: t('en, en-GB, fr-CA') }), _jsx("p", { style: hint, children: slots(t('A BCP 47 language tag, for {tag} and date formatting.'), { tag: _jsx("code", { children: '<html lang>' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "admin_locale", children: t('Admin language') }), _jsx("select", { id: "admin_locale", name: "admin_locale", value: settings.admin_locale || 'en', onChange: handleChange, className: "admin-select", children: ADMIN_LOCALES.map(option => _jsx("option", { value: option.code, children: option.name }, option.code)) }), _jsx("p", { style: hint, children: t('The admin\'s language for everyone who has not chosen one in their profile.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Reading') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Posts Per Page') }), _jsx("input", { type: "number", name: "posts_per_page", value: settings.posts_per_page, onChange: handleChange, className: "admin-input", min: "1", max: "100" })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: 'robots.txt' }), _jsx("textarea", { name: "robots_txt", value: settings.robots_txt, onChange: handleChange, className: "admin-textarea", rows: 5, placeholder: t('Blank uses the default:') + '\nUser-agent: *\nDisallow: /admin\nDisallow: /api/\nAllow: /api/v1/\nSitemap: …/sitemap.xml', style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' } })] })] }), _jsx(Slot, { name: "settings.reading", values: { ...stored, ...extra }, onChange: (changes) => setExtra(prev => ({ ...prev, ...changes })) }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Discussion') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Allow Comments') }), _jsxs("select", { name: "allow_comments", value: settings.allow_comments, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "true", children: t('Yes') }), _jsx("option", { value: "false", children: t('No') })] })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Moderate Comments') }), _jsxs("select", { name: "moderate_comments", value: settings.moderate_comments, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "true", children: t('Yes - Require approval') }), _jsx("option", { value: "false", children: t('No - Auto-approve all') })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: t('If enabled, comments from guests will require approval before appearing.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Headless API') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Public reads') }), _jsxs("select", { name: "public_api", value: settings.public_api, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "false", children: t('No - /api/v1 requires a token') }), _jsx("option", { value: "true", children: t('Yes - serve content to anyone') })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: slots(t('Turning this on serves published content at {path} with no credential. Appropriate for a site whose content is public anyway, and for a browser-side consumer that cannot be trusted with a token.'), { path: _jsx("code", { children: '/api/v1' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Webhook URLs') }), _jsx("textarea", { name: "webhook_urls", value: settings.webhook_urls, onChange: handleChange, className: "admin-input", rows: 4, placeholder: 'https://example.com/rebuild\nhttps://another.example.com/hook', style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' } }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: slots(t('One per line. Each gets a POST when a post, page or media item is created, updated or deleted — which is what stops a consumer polling. Every request carries {signature}, an HMAC of {timestamp} and the exact body, keyed with your {secret} (set in the environment; nothing is sent without it); verify it over the {raw} body, since a parsed and re-serialised one will not match.'), {
135
+ return (_jsx(AdminLayout, { title: t('Settings'), children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('General') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site Name') }), _jsx("input", { type: "text", name: "site_name", value: statusOf('site_name')?.locked_by ? statusOf('site_name')?.value ?? '' : settings.site_name, onChange: handleChange, className: "admin-input", placeholder: t('My Blog'), disabled: Boolean(statusOf('site_name')?.locked_by) }), statusOf('site_name')?.locked_by && (_jsx("p", { style: hint, children: slots(t('Set by {variable} in the environment, which wins over this setting.'), { variable: _jsx("code", { children: 'SITE_NAME' }) }) }))] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site Description') }), _jsx("textarea", { name: "site_description", value: settings.site_description, onChange: handleChange, className: "admin-textarea", style: { minHeight: '80px' }, placeholder: t('A brief description of your site') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Site Identity') }), _jsx(ConfigField, { ...field('site_url'), label: t('Site URL'), placeholder: siteUrl, help: slots(t('The public site, if it is not this app. Feeds, the sitemap and {path} link to it. Blank uses APP_URL.'), { path: _jsx("code", { children: '/api/v1/site' }) }) }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Logo URL') }), _jsx("input", { type: "text", name: "site_logo", value: settings.site_logo, onChange: handleChange, className: "admin-input", placeholder: t('/uploads/logo.svg or https://…') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Icon URL') }), _jsx("input", { type: "text", name: "site_icon", value: settings.site_icon, onChange: handleChange, className: "admin-input", placeholder: t('/uploads/icon.png — favicon and app icon') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Default Social Image URL') }), _jsx("input", { type: "text", name: "default_social_image", value: settings.default_social_image, onChange: handleChange, className: "admin-input", placeholder: t('Used on share cards when a post or page has no image') }), _jsx("p", { style: hint, children: t('Paste a URL from the media library, or a path starting with /.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Language & Time') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Time Zone') }), _jsxs("select", { name: "timezone", value: settings.timezone, onChange: handleChange, className: "admin-select", children: [!TIME_ZONES.includes(settings.timezone) && _jsx("option", { value: settings.timezone, children: settings.timezone }), TIME_ZONES.map(zone => _jsx("option", { value: zone, children: zone }, zone))] }), _jsx("p", { style: hint, children: t('Dates are stored in UTC; this is the zone the front end shows them in.') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Locale') }), _jsx("input", { type: "text", name: "locale", value: settings.locale, onChange: handleChange, className: "admin-input", placeholder: t('en, en-GB, fr-CA') }), _jsx("p", { style: hint, children: slots(t('A BCP 47 language tag, for {tag} and date formatting.'), { tag: _jsx("code", { children: '<html lang>' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "admin_locale", children: t('Admin language') }), _jsx("select", { id: "admin_locale", name: "admin_locale", value: settings.admin_locale || 'en', onChange: handleChange, className: "admin-select", children: ADMIN_LOCALES.map(option => _jsx("option", { value: option.code, children: option.name }, option.code)) }), _jsx("p", { style: hint, children: t('The admin\'s language for everyone who has not chosen one in their profile.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Reading') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Posts Per Page') }), _jsx("input", { type: "number", name: "posts_per_page", value: settings.posts_per_page, onChange: handleChange, className: "admin-input", min: "1", max: "100" })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: 'robots.txt' }), _jsx("textarea", { name: "robots_txt", value: settings.robots_txt, onChange: handleChange, className: "admin-textarea", rows: 5, placeholder: t('Blank uses the default:') + '\nUser-agent: *\nDisallow: /admin\nDisallow: /api/\nAllow: /api/v1/\nSitemap: …/sitemap.xml', style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' } })] })] }), _jsx(Slot, { name: "settings.reading", values: { ...stored, ...extra }, config: config, secrets: secrets, onChange: (changes) => setExtra(prev => ({ ...prev, ...changes })) }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Discussion') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Allow Comments') }), _jsxs("select", { name: "allow_comments", value: settings.allow_comments, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "true", children: t('Yes') }), _jsx("option", { value: "false", children: t('No') })] })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Moderate Comments') }), _jsxs("select", { name: "moderate_comments", value: settings.moderate_comments, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "true", children: t('Yes - Require approval') }), _jsx("option", { value: "false", children: t('No - Auto-approve all') })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: t('If enabled, comments from guests will require approval before appearing.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Headless API') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Public reads') }), _jsxs("select", { name: "public_api", value: settings.public_api, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "false", children: t('No - /api/v1 requires a token') }), _jsx("option", { value: "true", children: t('Yes - serve content to anyone') })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: slots(t('Turning this on serves published content at {path} with no credential. Appropriate for a site whose content is public anyway, and for a browser-side consumer that cannot be trusted with a token.'), { path: _jsx("code", { children: '/api/v1' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Webhook URLs') }), _jsx("textarea", { name: "webhook_urls", value: settings.webhook_urls, onChange: handleChange, className: "admin-input", rows: 4, placeholder: 'https://example.com/rebuild\nhttps://another.example.com/hook', style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' } }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: slots(t('One per line. Each gets a POST when a post, page or media item is created, updated or deleted — which is what stops a consumer polling. Every request carries {signature}, an HMAC of {timestamp} and the exact body, keyed with your {secret} (set in the environment; nothing is sent without it); verify it over the {raw} body, since a parsed and re-serialised one will not match.'), {
103
136
  signature: _jsx("code", { children: 'X-BasicBen-Signature' }),
104
137
  timestamp: _jsx("code", { children: 'X-BasicBen-Timestamp' }),
105
138
  secret: _jsx("code", { children: 'WEBHOOK_SECRET' }),
@@ -107,5 +140,9 @@ export default function AdminSettings() {
107
140
  }) }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: t('Delivery is at-most-once: a failure is logged and dropped, with no retry queue. A consumer that cannot miss an event should poll as a backstop.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Code Injection') }), _jsx("p", { style: { ...hint, marginTop: 0, marginBottom: '1rem' }, children: slots(t('HTML your front end inserts verbatim on every page — analytics, verification tags, a font stylesheet. It is {warning}: anything here runs on your site for every visitor. Served to the front end at {path}.'), {
108
141
  warning: _jsx("strong", { children: t('not sanitised') }),
109
142
  path: _jsx("code", { children: '/api/v1/site' })
110
- }) }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site header (inside {tag})', { tag: '<head>' }) }), _jsx("textarea", { name: "code_injection_head", value: settings.code_injection_head, onChange: handleChange, className: "admin-textarea", rows: 6, style: mono })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site footer (before {tag})', { tag: '</body>' }) }), _jsx("textarea", { name: "code_injection_foot", value: settings.code_injection_foot, onChange: handleChange, className: "admin-textarea", rows: 6, style: mono })] })] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '1rem' }, children: [_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", disabled: saving, children: saving ? t('Saving...') : t('Save Settings') }), message && (_jsx("span", { style: { color: failed ? 'var(--danger)' : 'var(--success)' }, children: message }))] })] }) }));
143
+ }) }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site header (inside {tag})', { tag: '<head>' }) }), _jsx("textarea", { name: "code_injection_head", value: settings.code_injection_head, onChange: handleChange, className: "admin-textarea", rows: 6, style: mono })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site footer (before {tag})', { tag: '</body>' }) }), _jsx("textarea", { name: "code_injection_foot", value: settings.code_injection_foot, onChange: handleChange, className: "admin-textarea", rows: 6, style: mono })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Registration') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "disable_registration", children: t('Who can create an account') }), _jsxs("select", { id: "disable_registration", name: "disable_registration", value: statusOf('disable_registration')?.locked_by ? (configValueOf(statusOf('disable_registration')) === 'true' ? 'true' : 'false') : settings.disable_registration, onChange: handleChange, className: "admin-select", disabled: Boolean(statusOf('disable_registration')?.locked_by), children: [_jsx("option", { value: "false", children: t('Anyone, from the sign-up page') }), _jsx("option", { value: "true", children: t('Only people you invite from Users') })] }), _jsx("p", { style: hint, children: statusOf('disable_registration')?.locked_by
144
+ ? slots(t('Set by {variable} in the environment, which wins over this setting.'), { variable: _jsx("code", { children: 'DISABLE_REGISTRATION' }) })
145
+ : t('The first account can always be created, so a new site can make its admin.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Media Storage') }), _jsx("p", { style: { ...hint, marginTop: 0, marginBottom: '1rem' }, children: statusOf('storage_bucket')?.locked_by
146
+ ? slots(t('Storage is configured by {variable} and the other S3 variables in the environment, which win over these settings.'), { variable: _jsx("code", { children: 'S3_BUCKET' }) })
147
+ : t('Any S3-compatible bucket: Cloudflare R2, AWS S3, Backblaze B2, MinIO. Without one, uploads go to this server\'s disk, which serverless hosts do not keep.') }), _jsx(ConfigField, { ...field('storage_bucket'), label: t('Bucket') }), _jsx(ConfigField, { ...field('storage_endpoint'), label: t('Endpoint'), placeholder: 'https://<account-id>.r2.cloudflarestorage.com', help: t('Blank for AWS S3.') }), _jsx(ConfigField, { ...field('storage_region'), label: t('Region'), placeholder: 'auto', help: t('auto for R2; the bucket\'s region for AWS S3.') }), _jsx(ConfigField, { ...field('storage_public_url'), label: t('Public URL'), placeholder: 'https://media.example.com', help: t('Where the files are served from: a custom domain or CDN in front of the bucket.') }), _jsx(ConfigField, { ...field('storage_access_key_id'), label: t('Access key ID') }), _jsx(ConfigField, { ...field('storage_secret_access_key'), label: t('Secret access key'), help: t('Stored encrypted with APP_KEY and never shown again.') }), _jsx(ConfigField, { ...field('image_transform_url'), label: t('Image transform URL'), placeholder: 'https://example.com/cdn-cgi/image/width={width}/{url}', help: t('Optional. A resizing service template with {url} and {width}, so images get a srcset.') })] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '1rem' }, children: [_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", disabled: saving, children: saving ? t('Saving...') : t('Save Settings') }), message && (_jsx("span", { style: { color: failed ? 'var(--danger)' : 'var(--success)' }, children: message }))] })] }) }));
111
148
  }
@@ -13,6 +13,15 @@
13
13
 
14
14
  @import 'tailwindcss';
15
15
 
16
+ /*
17
+ * Tailwind finds class names by scanning files, and it skips node_modules. A
18
+ * site that installs the CMS builds this file from
19
+ * node_modules/@basicbenframework/cms/lib/client, so without this line none of
20
+ * the admin's classes were scanned and it shipped unstyled. '../' is lib/ in
21
+ * the package and src/ here.
22
+ */
23
+ @source '../';
24
+
16
25
  @theme {
17
26
  /* Used by the page shell in index.html. */
18
27
  --color-dark-900: #0f0f0f;
@@ -10,6 +10,7 @@ import { Credential } from "../models/Credential.js";
10
10
  import { loginByAddress, loginByAccount } from "../middleware/rate-limits.js";
11
11
  import { issueSessionToken, revokeSessions } from "../helpers/session.js";
12
12
  import { getDb } from '@basicbenframework/core/db';
13
+ import { registrationOpen } from "../helpers/config.js";
13
14
  /**
14
15
  * A hash to check against when the address has no account.
15
16
  *
@@ -55,7 +56,7 @@ export const AuthController = {
55
56
  // business asking: a taken address would come back "already registered"
56
57
  // while a free one came back "closed", turning an endpoint that refuses
57
58
  // everyone into a way to test which addresses have accounts.
58
- if (!isFirstUser && process.env.DISABLE_REGISTRATION === 'true') {
59
+ if (!isFirstUser && !registrationOpen()) {
59
60
  return res.json({ error: 'Registration is closed' }, 403);
60
61
  }
61
62
  // Check if email exists
@@ -5,6 +5,7 @@ import { issueToken, redeemToken, revokeTokens, TOKEN_KINDS } from '@basicbenfra
5
5
  import { emailSendLimiter } from "../middleware/rate-limits.js";
6
6
  import { hooks, HOOKS } from '@basicbenframework/core/hooks';
7
7
  import { User } from "../models/User.js";
8
+ import { siteName } from "../helpers/config.js";
8
9
  const appUrl = () => process.env.APP_URL || 'http://localhost:3000';
9
10
  /**
10
11
  * Issue a token and email the link.
@@ -18,7 +19,7 @@ export async function sendVerificationEmail(user) {
18
19
  const verifyUrl = `${appUrl()}/verify/${token}`;
19
20
  const body = renderMail('verify-email', {
20
21
  name: user.name,
21
- siteName: process.env.SITE_NAME || 'BasicBen',
22
+ siteName: siteName(),
22
23
  verifyUrl
23
24
  });
24
25
  await sendMail({
@@ -2,7 +2,8 @@ import { randomUUID } from 'node:crypto';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { getDb } from '@basicbenframework/core/db';
4
4
  import { loadConfig } from '@basicbenframework/core/server';
5
- import { getStorage, resolveConfig } from '@basicbenframework/core/storage';
5
+ import { resolveConfig } from '@basicbenframework/core/storage';
6
+ import { getStorage, storageSource } from "../helpers/storage.js";
6
7
  import { sendMail } from '@basicbenframework/core/mail';
7
8
  import { Post } from "../models/Post.js";
8
9
  import { User } from "../models/User.js";
@@ -10,6 +11,7 @@ import { featureHealthChecks } from "../host/index.js";
10
11
  import { runCron, cronAuthorized } from "../host/cron.js";
11
12
  import { readHeartbeats } from "../helpers/heartbeat.js";
12
13
  import { evaluateHealth, overallStatus, databaseFacts, migrationFilesIn, isServerless } from "../helpers/health.js";
14
+ import { CONFIG, configValue, describeConfig } from "../helpers/config.js";
13
15
  /**
14
16
  * The installed framework version, read from its package.json.
15
17
  *
@@ -60,19 +62,22 @@ export const HealthController = {
60
62
  // The migrator's own list: defineSite's (the CMS's, then the site's), or
61
63
  // the framework's default.
62
64
  migrationFiles: migrationFilesIn(config.migrations ?? 'db/migrations'),
63
- storageDriver: String(resolveConfig(config.storage || {}).driver),
65
+ storageDriver: storageSource() === 'settings' ? 's3' : String(resolveConfig(config.storage || {}).driver),
64
66
  mailTransport: transportName(config.mail),
65
67
  mailFrom: config.mail?.from ?? null,
66
68
  heartbeats: await readHeartbeats(db),
67
69
  dueUnannounced,
68
70
  ...(await databaseFacts(db, now))
69
71
  };
70
- const checks = evaluateHealth(process.env, facts, now);
72
+ // The values in use, wherever they come from: a setting the admin saved
73
+ // counts as configured, the same as the variable would.
74
+ const env = { ...process.env, ...effectiveEnv() };
75
+ const checks = evaluateHealth(env, facts, now);
71
76
  // Features' own checks. One that throws reports itself as a warning rather
72
77
  // than taking the page down.
73
78
  for (const { name, run } of featureHealthChecks()) {
74
79
  try {
75
- const found = await run({ db, now, env: process.env });
80
+ const found = await run({ db, now, env });
76
81
  if (found)
77
82
  checks.push(...(Array.isArray(found) ? found : [found]));
78
83
  }
@@ -88,7 +93,8 @@ export const HealthController = {
88
93
  node_env: process.env.NODE_ENV || null,
89
94
  serverless: isServerless(process.env)
90
95
  },
91
- checks
96
+ checks,
97
+ config: describeConfig()
92
98
  });
93
99
  },
94
100
  /**
@@ -174,3 +180,7 @@ export const HealthController = {
174
180
  res.json(await runCron());
175
181
  }
176
182
  };
183
+ /** Every configurable variable, with the value in use (env or setting) or absent. */
184
+ function effectiveEnv() {
185
+ return Object.fromEntries(CONFIG.map((entry) => [entry.env, configValue(entry.env) || undefined]));
186
+ }
@@ -18,7 +18,7 @@ import { imageSize } from "../helpers/image-size.js";
18
18
  * against R2, S3, MinIO or the local disk.
19
19
  */
20
20
  import { signUpload, confirmUpload, deleteUpload } from '@basicbenframework/core/storage/uploads';
21
- import { getStorage } from '@basicbenframework/core/storage';
21
+ import { getStorage } from "../helpers/storage.js";
22
22
  import { Media } from "../models/Media.js";
23
23
  import { guardWrite, MEDIA_HOOKS } from "../helpers/write-hooks.js";
24
24
  const MAX_FILE_SIZE = 10 * 1024 * 1024;
@@ -58,7 +58,7 @@ export const MediaController = {
58
58
  */
59
59
  async sign(req, res) {
60
60
  const { filename, contentType, size } = req.body;
61
- const result = await signUpload({ filename: filename, contentType: contentType, size: size, userId: req.userId }, { maxSize: MAX_FILE_SIZE });
61
+ const result = await signUpload({ filename: filename, contentType: contentType, size: size, userId: req.userId }, { maxSize: MAX_FILE_SIZE, storage: await getStorage() });
62
62
  if (!result.ok) {
63
63
  return res.json({ error: result.error }, 422);
64
64
  }
@@ -79,7 +79,7 @@ export const MediaController = {
79
79
  */
80
80
  async confirm(req, res) {
81
81
  const { key, ticket, filename, altText } = req.body;
82
- const result = await confirmUpload({ key: key, ticket: ticket, userId: req.userId }, { maxSize: MAX_FILE_SIZE });
82
+ const result = await confirmUpload({ key: key, ticket: ticket, userId: req.userId }, { maxSize: MAX_FILE_SIZE, storage: await getStorage() });
83
83
  if (!result.ok) {
84
84
  return res.json({ error: result.error }, 422);
85
85
  }
@@ -117,7 +117,7 @@ export const MediaController = {
117
117
  height: dimensions?.height ?? null
118
118
  }, { req }, { refused: 'Upload rejected.' });
119
119
  if (!creating.ok) {
120
- await deleteUpload(result.key, { userId: req.userId }).catch(() => { });
120
+ await deleteUpload(result.key, { userId: req.userId, storage: await getStorage() }).catch(() => { });
121
121
  return res.json({ error: creating.error }, creating.status);
122
122
  }
123
123
  // The key is the object that was verified; a listener may change the
@@ -163,7 +163,7 @@ export const MediaController = {
163
163
  // The row is the record; a storage object that outlives it is a leak, but a
164
164
  // failure to remove it should not fail the request the user asked for.
165
165
  try {
166
- await deleteUpload(media.path, { userId: req.userId });
166
+ await deleteUpload(media.path, { userId: req.userId, storage: await getStorage() });
167
167
  }
168
168
  catch (err) {
169
169
  console.error('Failed to remove the stored object:', err.message);
@@ -3,6 +3,7 @@ import { issueToken, redeemToken, TOKEN_KINDS } from '@basicbenframework/core/au
3
3
  import { generateRegistrationOptions, generateAuthenticationOptions, verifyRegistration, verifyAuthentication } from '@basicbenframework/core/auth/webauthn';
4
4
  import { User } from "../models/User.js";
5
5
  import { Credential } from "../models/Credential.js";
6
+ import { siteName } from "../helpers/config.js";
6
7
  const CHALLENGE_TTL = 5 * 60 * 1000;
7
8
  /**
8
9
  * The relying party is the domain, not the origin.
@@ -12,7 +13,7 @@ const CHALLENGE_TTL = 5 * 60 * 1000;
12
13
  * invalidates every enrolled passkey, so decide it before anyone enrols.
13
14
  */
14
15
  const rpId = () => process.env.WEBAUTHN_RP_ID || new URL(appUrl()).hostname;
15
- const rpName = () => process.env.SITE_NAME || 'BasicBen';
16
+ const rpName = () => siteName();
16
17
  const appUrl = () => process.env.APP_URL || 'http://localhost:3000';
17
18
  /** Origins a response may claim. */
18
19
  const allowedOrigins = () => (process.env.WEBAUTHN_ORIGINS || appUrl()).split(',').map((o) => o.trim()).filter(Boolean);