domma-cms 0.23.0 → 0.25.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/CLAUDE.md +14 -0
- package/admin/js/api.js +1 -1
- package/admin/js/app.js +4 -4
- package/admin/js/lib/crud-tutorial.js +1 -1
- package/admin/js/lib/project-context.js +1 -1
- package/admin/js/templates/api-endpoint-editor.html +120 -0
- package/admin/js/templates/api-endpoints.html +13 -0
- package/admin/js/templates/api-tokens.html +13 -0
- package/admin/js/templates/effects.html +752 -752
- package/admin/js/templates/form-submissions.html +30 -30
- package/admin/js/templates/forms.html +17 -17
- package/admin/js/templates/my-profile.html +17 -17
- package/admin/js/templates/role-editor.html +70 -70
- package/admin/js/templates/roles.html +10 -10
- package/admin/js/views/api-endpoint-editor.js +1 -0
- package/admin/js/views/api-endpoints.js +7 -0
- package/admin/js/views/api-tokens.js +8 -0
- package/admin/js/views/collection-editor.js +4 -4
- package/admin/js/views/index.js +1 -1
- package/admin/js/views/project-detail.js +1 -1
- package/admin/js/views/roles.js +1 -1
- package/bin/lib/config-merge.js +44 -44
- package/bin/update.js +547 -547
- package/config/menus/admin-sidebar.json +13 -1
- package/package.json +1 -1
- package/server/middleware/auth.js +253 -253
- package/server/routes/api/api-endpoints.js +96 -0
- package/server/routes/api/api-tokens.js +83 -0
- package/server/routes/api/auth.js +309 -309
- package/server/routes/api/collections.js +114 -17
- package/server/routes/api/endpoints-public.js +88 -0
- package/server/routes/api/navigation.js +42 -42
- package/server/routes/api/settings.js +141 -141
- package/server/routes/public.js +202 -202
- package/server/server.js +16 -1
- package/server/services/apiEndpoints.js +402 -0
- package/server/services/apiTokens.js +273 -0
- package/server/services/email.js +167 -167
- package/server/services/permissionRegistry.js +26 -0
- package/server/services/presetCollections.js +54 -0
- package/server/services/projects.js +18 -2
- package/server/services/roles.js +16 -0
- package/server/services/scaffolder.js +54 -1
- package/server/services/sidebar-migration.js +45 -0
- package/server/services/userProfiles.js +199 -199
- package/server/services/users.js +302 -302
- package/config/connections.json.bak +0 -9
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings API
|
|
3
|
-
* GET /api/settings - get site settings
|
|
4
|
-
* PUT /api/settings - save site settings
|
|
5
|
-
* POST /api/settings/test-email - send a test email using stored SMTP config
|
|
6
|
-
*/
|
|
7
|
-
import {getConfig, saveConfig} from '../../config.js';
|
|
8
|
-
import {authenticate, requirePermission} from '../../middleware/auth.js';
|
|
9
|
-
import nodemailer from 'nodemailer';
|
|
10
|
-
import fs from 'fs/promises';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
import {fileURLToPath} from 'url';
|
|
13
|
-
import * as cache from '../../services/cache/index.js';
|
|
14
|
-
|
|
15
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
-
const CUSTOM_CSS_FILE = path.resolve(__dirname, '../../../content/custom.css');
|
|
17
|
-
const CONNECTIONS_FILE = path.resolve(__dirname, '../../../config/connections.json');
|
|
18
|
-
const CUSTOM_CSS_MAX = 100 * 1024; // 100 KB
|
|
19
|
-
|
|
20
|
-
export async function settingsRoutes(fastify) {
|
|
21
|
-
const canRead = {preHandler: [authenticate, requirePermission('settings', 'read')]};
|
|
22
|
-
const canUpdate = {preHandler: [authenticate, requirePermission('settings', 'update')]};
|
|
23
|
-
|
|
24
|
-
fastify.get('/settings', canRead, async (request, reply) => {
|
|
25
|
-
const config = getConfig('site');
|
|
26
|
-
const safeConfig = { ...config };
|
|
27
|
-
if (safeConfig.smtp) {
|
|
28
|
-
safeConfig.smtp = { ...safeConfig.smtp, pass: '' };
|
|
29
|
-
}
|
|
30
|
-
return reply.send(safeConfig);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
fastify.put('/settings', canUpdate, async (request, reply) => {
|
|
34
|
-
const data = request.body;
|
|
35
|
-
if (!data || typeof data !== 'object') {
|
|
36
|
-
return reply.status(400).send({ error: 'Invalid settings data' });
|
|
37
|
-
}
|
|
38
|
-
const ALLOWED_KEYS = new Set([
|
|
39
|
-
'title', 'tagline', 'description', 'logo', 'favicon',
|
|
40
|
-
'theme', 'adminTheme', 'fontFamily', 'fontSize',
|
|
41
|
-
'smtp', 'footer', 'analytics', 'social', 'locale',
|
|
42
|
-
'layoutOptions', 'seo', 'backToTop', 'cookieConsent', 'breadcrumbs', 'autoTheme',
|
|
43
|
-
'adminBrand'
|
|
44
|
-
]);
|
|
45
|
-
const unknownKeys = Object.keys(data).filter(k => !ALLOWED_KEYS.has(k));
|
|
46
|
-
if (unknownKeys.length > 0) {
|
|
47
|
-
return reply.status(400).send({ error: `Unknown settings keys: ${unknownKeys.join(', ')}` });
|
|
48
|
-
}
|
|
49
|
-
// Merge incoming data with existing config so partial updates (e.g. just adminBrand)
|
|
50
|
-
// don't wipe unrelated keys. Nested objects get a shallow merge so sub-fields are
|
|
51
|
-
// preserved even when only some sub-fields are sent.
|
|
52
|
-
const existing = getConfig('site');
|
|
53
|
-
const merged = {...existing};
|
|
54
|
-
for (const [k, v] of Object.entries(data)) {
|
|
55
|
-
const isPlainObject = v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
56
|
-
const existingIsPlainObject = existing[k] !== null && typeof existing[k] === 'object' && !Array.isArray(existing[k]);
|
|
57
|
-
if (isPlainObject && existingIsPlainObject) {
|
|
58
|
-
merged[k] = {...existing[k], ...v};
|
|
59
|
-
} else {
|
|
60
|
-
merged[k] = v;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Never erase smtp.pass with the empty string that the GET endpoint injects for safety
|
|
64
|
-
if (merged.smtp && merged.smtp.pass === '' && existing.smtp?.pass) {
|
|
65
|
-
merged.smtp = {...merged.smtp, pass: existing.smtp.pass};
|
|
66
|
-
}
|
|
67
|
-
saveConfig('site', merged);
|
|
68
|
-
await cache.invalidateTags(['site']);
|
|
69
|
-
return { success: true };
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
fastify.post('/settings/test-email', canRead, async (request, reply) => {
|
|
73
|
-
const smtp = getConfig('site')?.smtp;
|
|
74
|
-
if (!smtp?.host) {
|
|
75
|
-
return reply.status(400).send({ error: 'SMTP is not configured. Save your SMTP settings first.' });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const transporter = nodemailer.createTransport({
|
|
79
|
-
host: smtp.host,
|
|
80
|
-
port: smtp.port || 587,
|
|
81
|
-
secure: smtp.secure || false,
|
|
82
|
-
auth: smtp.user ? { user: smtp.user, pass: smtp.pass } : undefined
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const to = request.body?.to || smtp.fromAddress;
|
|
86
|
-
if (!to) {
|
|
87
|
-
return reply.status(400).send({ error: 'No recipient address. Provide "to" in the request body or set a From Address.' });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
await transporter.sendMail({
|
|
92
|
-
from: smtp.fromName ? `"${smtp.fromName}" <${smtp.fromAddress}>` : smtp.fromAddress,
|
|
93
|
-
to,
|
|
94
|
-
subject: 'Domma CMS — Test Email',
|
|
95
|
-
text: 'This is a test email sent from Domma CMS to verify your SMTP configuration.',
|
|
96
|
-
html: '<p>This is a test email sent from <strong>Domma CMS</strong> to verify your SMTP configuration.</p>'
|
|
97
|
-
});
|
|
98
|
-
return { success: true, message: `Test email sent to ${to}` };
|
|
99
|
-
} catch (err) {
|
|
100
|
-
return reply.status(500).send({ error: `Failed to send email: ${err.message}` });
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// GET /api/settings/db-status — returns whether MongoDB connections are configured
|
|
105
|
-
fastify.get('/settings/db-status', canRead, async () => {
|
|
106
|
-
try {
|
|
107
|
-
const raw = await fs.readFile(CONNECTIONS_FILE, 'utf8');
|
|
108
|
-
const connections = JSON.parse(raw);
|
|
109
|
-
const names = Object.keys(connections).filter(k =>
|
|
110
|
-
connections[k]?.type === 'mongodb' && connections[k]?.uri
|
|
111
|
-
);
|
|
112
|
-
return {configured: names.length > 0, connections: names};
|
|
113
|
-
} catch {
|
|
114
|
-
return {configured: false, connections: []};
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// GET /api/settings/custom-css — return current CSS as JSON
|
|
119
|
-
fastify.get('/settings/custom-css', canUpdate, async () => {
|
|
120
|
-
try {
|
|
121
|
-
const css = await fs.readFile(CUSTOM_CSS_FILE, 'utf8');
|
|
122
|
-
return { css };
|
|
123
|
-
} catch {
|
|
124
|
-
return { css: '' };
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// PUT /api/settings/custom-css — save CSS to content/custom.css
|
|
129
|
-
fastify.put('/settings/custom-css', canUpdate, async (request, reply) => {
|
|
130
|
-
const { css } = request.body || {};
|
|
131
|
-
if (typeof css !== 'string') {
|
|
132
|
-
return reply.status(400).send({ error: 'css must be a string.' });
|
|
133
|
-
}
|
|
134
|
-
if (Buffer.byteLength(css, 'utf8') > CUSTOM_CSS_MAX) {
|
|
135
|
-
return reply.status(400).send({ error: 'CSS exceeds the 100 KB limit.' });
|
|
136
|
-
}
|
|
137
|
-
await fs.writeFile(CUSTOM_CSS_FILE, css, 'utf8');
|
|
138
|
-
await cache.invalidateTags(['site']);
|
|
139
|
-
return { success: true };
|
|
140
|
-
});
|
|
141
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Settings API
|
|
3
|
+
* GET /api/settings - get site settings
|
|
4
|
+
* PUT /api/settings - save site settings
|
|
5
|
+
* POST /api/settings/test-email - send a test email using stored SMTP config
|
|
6
|
+
*/
|
|
7
|
+
import {getConfig, saveConfig} from '../../config.js';
|
|
8
|
+
import {authenticate, requirePermission} from '../../middleware/auth.js';
|
|
9
|
+
import nodemailer from 'nodemailer';
|
|
10
|
+
import fs from 'fs/promises';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import {fileURLToPath} from 'url';
|
|
13
|
+
import * as cache from '../../services/cache/index.js';
|
|
14
|
+
|
|
15
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const CUSTOM_CSS_FILE = path.resolve(__dirname, '../../../content/custom.css');
|
|
17
|
+
const CONNECTIONS_FILE = path.resolve(__dirname, '../../../config/connections.json');
|
|
18
|
+
const CUSTOM_CSS_MAX = 100 * 1024; // 100 KB
|
|
19
|
+
|
|
20
|
+
export async function settingsRoutes(fastify) {
|
|
21
|
+
const canRead = {preHandler: [authenticate, requirePermission('settings', 'read')]};
|
|
22
|
+
const canUpdate = {preHandler: [authenticate, requirePermission('settings', 'update')]};
|
|
23
|
+
|
|
24
|
+
fastify.get('/settings', canRead, async (request, reply) => {
|
|
25
|
+
const config = getConfig('site');
|
|
26
|
+
const safeConfig = { ...config };
|
|
27
|
+
if (safeConfig.smtp) {
|
|
28
|
+
safeConfig.smtp = { ...safeConfig.smtp, pass: '' };
|
|
29
|
+
}
|
|
30
|
+
return reply.send(safeConfig);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
fastify.put('/settings', canUpdate, async (request, reply) => {
|
|
34
|
+
const data = request.body;
|
|
35
|
+
if (!data || typeof data !== 'object') {
|
|
36
|
+
return reply.status(400).send({ error: 'Invalid settings data' });
|
|
37
|
+
}
|
|
38
|
+
const ALLOWED_KEYS = new Set([
|
|
39
|
+
'title', 'tagline', 'description', 'logo', 'favicon',
|
|
40
|
+
'theme', 'adminTheme', 'fontFamily', 'fontSize',
|
|
41
|
+
'smtp', 'footer', 'analytics', 'social', 'locale',
|
|
42
|
+
'layoutOptions', 'seo', 'backToTop', 'cookieConsent', 'breadcrumbs', 'autoTheme',
|
|
43
|
+
'adminBrand'
|
|
44
|
+
]);
|
|
45
|
+
const unknownKeys = Object.keys(data).filter(k => !ALLOWED_KEYS.has(k));
|
|
46
|
+
if (unknownKeys.length > 0) {
|
|
47
|
+
return reply.status(400).send({ error: `Unknown settings keys: ${unknownKeys.join(', ')}` });
|
|
48
|
+
}
|
|
49
|
+
// Merge incoming data with existing config so partial updates (e.g. just adminBrand)
|
|
50
|
+
// don't wipe unrelated keys. Nested objects get a shallow merge so sub-fields are
|
|
51
|
+
// preserved even when only some sub-fields are sent.
|
|
52
|
+
const existing = getConfig('site');
|
|
53
|
+
const merged = {...existing};
|
|
54
|
+
for (const [k, v] of Object.entries(data)) {
|
|
55
|
+
const isPlainObject = v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
56
|
+
const existingIsPlainObject = existing[k] !== null && typeof existing[k] === 'object' && !Array.isArray(existing[k]);
|
|
57
|
+
if (isPlainObject && existingIsPlainObject) {
|
|
58
|
+
merged[k] = {...existing[k], ...v};
|
|
59
|
+
} else {
|
|
60
|
+
merged[k] = v;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Never erase smtp.pass with the empty string that the GET endpoint injects for safety
|
|
64
|
+
if (merged.smtp && merged.smtp.pass === '' && existing.smtp?.pass) {
|
|
65
|
+
merged.smtp = {...merged.smtp, pass: existing.smtp.pass};
|
|
66
|
+
}
|
|
67
|
+
saveConfig('site', merged);
|
|
68
|
+
await cache.invalidateTags(['site']);
|
|
69
|
+
return { success: true };
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
fastify.post('/settings/test-email', canRead, async (request, reply) => {
|
|
73
|
+
const smtp = getConfig('site')?.smtp;
|
|
74
|
+
if (!smtp?.host) {
|
|
75
|
+
return reply.status(400).send({ error: 'SMTP is not configured. Save your SMTP settings first.' });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const transporter = nodemailer.createTransport({
|
|
79
|
+
host: smtp.host,
|
|
80
|
+
port: smtp.port || 587,
|
|
81
|
+
secure: smtp.secure || false,
|
|
82
|
+
auth: smtp.user ? { user: smtp.user, pass: smtp.pass } : undefined
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const to = request.body?.to || smtp.fromAddress;
|
|
86
|
+
if (!to) {
|
|
87
|
+
return reply.status(400).send({ error: 'No recipient address. Provide "to" in the request body or set a From Address.' });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
await transporter.sendMail({
|
|
92
|
+
from: smtp.fromName ? `"${smtp.fromName}" <${smtp.fromAddress}>` : smtp.fromAddress,
|
|
93
|
+
to,
|
|
94
|
+
subject: 'Domma CMS — Test Email',
|
|
95
|
+
text: 'This is a test email sent from Domma CMS to verify your SMTP configuration.',
|
|
96
|
+
html: '<p>This is a test email sent from <strong>Domma CMS</strong> to verify your SMTP configuration.</p>'
|
|
97
|
+
});
|
|
98
|
+
return { success: true, message: `Test email sent to ${to}` };
|
|
99
|
+
} catch (err) {
|
|
100
|
+
return reply.status(500).send({ error: `Failed to send email: ${err.message}` });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// GET /api/settings/db-status — returns whether MongoDB connections are configured
|
|
105
|
+
fastify.get('/settings/db-status', canRead, async () => {
|
|
106
|
+
try {
|
|
107
|
+
const raw = await fs.readFile(CONNECTIONS_FILE, 'utf8');
|
|
108
|
+
const connections = JSON.parse(raw);
|
|
109
|
+
const names = Object.keys(connections).filter(k =>
|
|
110
|
+
connections[k]?.type === 'mongodb' && connections[k]?.uri
|
|
111
|
+
);
|
|
112
|
+
return {configured: names.length > 0, connections: names};
|
|
113
|
+
} catch {
|
|
114
|
+
return {configured: false, connections: []};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// GET /api/settings/custom-css — return current CSS as JSON
|
|
119
|
+
fastify.get('/settings/custom-css', canUpdate, async () => {
|
|
120
|
+
try {
|
|
121
|
+
const css = await fs.readFile(CUSTOM_CSS_FILE, 'utf8');
|
|
122
|
+
return { css };
|
|
123
|
+
} catch {
|
|
124
|
+
return { css: '' };
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// PUT /api/settings/custom-css — save CSS to content/custom.css
|
|
129
|
+
fastify.put('/settings/custom-css', canUpdate, async (request, reply) => {
|
|
130
|
+
const { css } = request.body || {};
|
|
131
|
+
if (typeof css !== 'string') {
|
|
132
|
+
return reply.status(400).send({ error: 'css must be a string.' });
|
|
133
|
+
}
|
|
134
|
+
if (Buffer.byteLength(css, 'utf8') > CUSTOM_CSS_MAX) {
|
|
135
|
+
return reply.status(400).send({ error: 'CSS exceeds the 100 KB limit.' });
|
|
136
|
+
}
|
|
137
|
+
await fs.writeFile(CUSTOM_CSS_FILE, css, 'utf8');
|
|
138
|
+
await cache.invalidateTags(['site']);
|
|
139
|
+
return { success: true };
|
|
140
|
+
});
|
|
141
|
+
}
|