domma-cms 1.67.2 → 1.69.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 (85) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/CLAUDE.md +2 -0
  3. package/admin/js/lib/layouts-arrange.js +1 -1
  4. package/admin/js/lib/rich-field.js +9 -2
  5. package/admin/js/lib/seo-defaults.js +1 -1
  6. package/admin/js/templates/docs/api-content.html +3 -2
  7. package/admin/js/templates/docs/api-layouts.html +1 -1
  8. package/admin/js/templates/docs/usage-navigation.html +2 -1
  9. package/admin/js/templates/docs/usage-pages.html +3 -1
  10. package/admin/js/templates/docs/usage-search-engines.html +3 -0
  11. package/admin/js/templates/page-editor.html +3 -3
  12. package/admin/js/views/form-editor.js +5 -5
  13. package/admin/js/views/layouts.js +7 -7
  14. package/admin/js/views/menu-editor.js +20 -20
  15. package/admin/js/views/page-editor.js +9 -9
  16. package/admin/js/views/seo.js +31 -30
  17. package/docs/DommaFeatures.md +6 -2
  18. package/docs/api-reference.md +7 -3
  19. package/docs/guides/multi-page-forms.md +1 -1
  20. package/docs/markdown-shortcodes.md +1 -1
  21. package/docs/plugin-development.md +20 -0
  22. package/package.json +1 -1
  23. package/plugins/blog/CHANGELOG.md +3 -0
  24. package/plugins/blog/CLAUDE.md +15 -0
  25. package/plugins/blog/admin/views/categories.js +5 -2
  26. package/plugins/blog/admin/views/kit.js +19 -0
  27. package/plugins/blog/docs/guide.md +2 -0
  28. package/plugins/blog/plugin.js +18 -2
  29. package/plugins/blog/plugin.json +6 -6
  30. package/plugins/blog/plugin.public.js +16 -2
  31. package/plugins/blog/public/blog.css +3 -0
  32. package/plugins/blog/tests/public.test.js +29 -2
  33. package/plugins/feedback/CLAUDE.md +22 -0
  34. package/plugins/feedback/admin/css/index.css +2 -0
  35. package/plugins/feedback/admin/views/inbox.js +5 -2
  36. package/plugins/feedback/admin/views/send.js +12 -5
  37. package/plugins/feedback/docs/guide.md +3 -2
  38. package/plugins/feedback/lib/sender.js +1 -1
  39. package/plugins/feedback/lib/shape.js +72 -11
  40. package/plugins/feedback/plugin.js +3 -3
  41. package/plugins/feedback/plugin.json +3 -2
  42. package/plugins/feedback/tests/api.test.js +47 -1
  43. package/plugins/feedback/tests/shape.test.js +87 -1
  44. package/plugins/free-tier.lock.json +43 -42
  45. package/plugins/shopping-cart/CHANGELOG.md +20 -0
  46. package/plugins/shopping-cart/CLAUDE.md +38 -1
  47. package/plugins/shopping-cart/admin/css/index.css +4 -0
  48. package/plugins/shopping-cart/admin/lib/kit.js +1 -0
  49. package/plugins/shopping-cart/admin/views/products.js +95 -3
  50. package/plugins/shopping-cart/admin/views/shop.js +2 -1
  51. package/plugins/shopping-cart/docs/guide.md +6 -1
  52. package/plugins/shopping-cart/inject/body.html +2 -2
  53. package/plugins/shopping-cart/lib/description.js +173 -0
  54. package/plugins/shopping-cart/lib/render.js +3 -2
  55. package/plugins/shopping-cart/lib/shop.js +4 -1
  56. package/plugins/shopping-cart/plugin.js +17 -2
  57. package/plugins/shopping-cart/plugin.json +3 -2
  58. package/plugins/shopping-cart/plugin.public.js +6 -9
  59. package/plugins/shopping-cart/public/lib/products.js +40 -3
  60. package/plugins/shopping-cart/public/shop.css +1 -0
  61. package/plugins/shopping-cart/tests/pure.test.js +26 -1
  62. package/plugins/shopping-cart/tests/seo.test.js +174 -0
  63. package/public/js/collection-browser.js +1 -1
  64. package/public/js/menu-cards.mjs +4 -4
  65. package/public/js/menu-look.mjs +1 -1
  66. package/public/js/rich-text.mjs +4 -4
  67. package/public/js/site.js +1 -1
  68. package/server/routes/api/collections.js +26 -12
  69. package/server/routes/api/forms.js +5 -3
  70. package/server/routes/api/layouts.js +8 -4
  71. package/server/routes/api/seo.js +10 -4
  72. package/server/services/adapters/FileAdapter.js +4 -3
  73. package/server/services/adapters/MongoAdapter.js +4 -2
  74. package/server/services/content.js +23 -0
  75. package/server/services/contentApi.js +27 -4
  76. package/server/services/filterEngine.js +33 -0
  77. package/server/services/forms.js +58 -2
  78. package/server/services/health.js +3 -1
  79. package/server/services/markdown.js +288 -38
  80. package/server/services/menus.js +56 -6
  81. package/server/services/renderer.js +28 -4
  82. package/server/services/richText.js +56 -3
  83. package/server/services/search.js +5 -2
  84. package/server/services/sitemap.js +5 -3
  85. package/server/templates/page.html +2 -2
@@ -65,6 +65,7 @@ import {hooks} from '../../services/hooks.js';
65
65
  import {DRAFT_STATUS, authenticateApiToken, draftsOnlyDecision, scopeAllows} from '../../services/apiTokens.js';
66
66
  import {contentRefusal, renderedContentRefusal} from '../../services/tokenContentPolicy.js';
67
67
  import {listBlocks} from '../../services/blocks.js';
68
+ import {confineFilter} from '../../services/filterEngine.js';
68
69
 
69
70
  /** Field types whose value is rendered as Markdown on a page (the Blog's post body, a notes field). */
70
71
  const RENDERED_TYPES = new Set(['textarea', 'markdown', 'richtext', 'html', 'wysiwyg', 'code']);
@@ -293,9 +294,8 @@ function redactTokenHash(entry) {
293
294
  /**
294
295
  * Apply the read-field allowlist (`schema.api.read.fields`) to a public read
295
296
  * payload. Absent or empty allowlist = all fields. Handles both list payloads
296
- * ({entries: [...]}) and single entries. Only entry.data is filtered -
297
- * `_refs` from resolveRefs is not (refs of stripped fields may still appear;
298
- * documented v1 behaviour).
297
+ * ({entries: [...]}) and single entries. entry.data and `_refs` (resolveRefs)
298
+ * are both cut to the list.
299
299
  *
300
300
  * @param {object} schema
301
301
  * @param {object} payload - listEntries() result or a single entry
@@ -304,10 +304,9 @@ function redactTokenHash(entry) {
304
304
  export function applyReadFieldAllowlist(schema, payload) {
305
305
  const fields = schema.api?.read?.fields;
306
306
  if (!Array.isArray(fields) || fields.length === 0) return payload;
307
- const strip = (e) => ({
308
- ...e,
309
- data: Object.fromEntries(Object.entries(e.data || {}).filter(([k]) => fields.includes(k)))
310
- });
307
+ const only = (object) => Object.fromEntries(Object.entries(object || {}).filter(([k]) => fields.includes(k)));
308
+ // _refs (resolveRefs) carries a reference field's id and label: a hidden field's go with it.
309
+ const strip = (e) => ({...e, data: only(e.data), ...(e._refs && {_refs: only(e._refs)})});
311
310
  if (Array.isArray(payload?.entries)) return { ...payload, entries: payload.entries.map(strip) };
312
311
  return strip(payload);
313
312
  }
@@ -813,7 +812,15 @@ export async function collectionsRoutes(fastify) {
813
812
  if (!schema) return reply.status(404).send({ error: 'Collection not found' });
814
813
 
815
814
  const { page, limit, sort, order, search, scope, resolveRefs } = request.query;
816
- const filter = extractBracketed(request.query, 'filter');
815
+ // A read limited to some fields (api.read.fields) is filtered, searched
816
+ // and sorted on those only - otherwise which rows come back, and in what
817
+ // order, answers questions about the fields the caller is never shown.
818
+ // The caller's filter is cut down HERE, before the server adds its own
819
+ // conditions (own rows) below, which are not the caller's to lose.
820
+ const listed = Array.isArray(schema.api?.read?.fields) && schema.api.read.fields.length
821
+ ? new Set(schema.api.read.fields) : null;
822
+ const asked = extractBracketed(request.query, 'filter');
823
+ const filter = listed ? confineFilter(asked, listed) : asked;
817
824
 
818
825
  // scope=mine has its own security model: it requires auth and scopes
819
826
  // results to the caller's own entries via `createdBy = user.id`. Bypasses
@@ -838,12 +845,15 @@ export async function collectionsRoutes(fastify) {
838
845
  }
839
846
  if (nobodysRows(request, reply, filter)) return;
840
847
 
848
+ const sortOn = typeof sort === 'string' && sort && (!listed || listed.has(sort) || sort === 'createdAt' || sort === 'updatedAt') ? sort : 'createdAt';
849
+
841
850
  const result = await listEntries(request.params.slug, {
842
851
  page: parseInt(page, 10) || 1,
843
852
  limit: parseInt(limit, 10) || 50,
844
- sort: sort || 'createdAt',
853
+ sort: sortOn,
845
854
  order: order || 'desc',
846
- search: search || undefined,
855
+ search: typeof search === 'string' && search ? search : undefined,
856
+ ...(listed && {searchFields: [...listed]}),
847
857
  filter: Object.keys(filter).length ? filter : undefined,
848
858
  resolveRefs: resolveRefs === 'true' || resolveRefs === '1'
849
859
  });
@@ -953,8 +963,12 @@ export async function collectionsRoutes(fastify) {
953
963
  return reply.status(403).send({ error: NOT_YOUR_ROWS });
954
964
  }
955
965
 
956
- const { renderCollectionFragment } = await import('../../services/markdown.js');
957
- const html = await renderCollectionFragment(attrs);
966
+ // The browser puts this in with innerHTML, after the page itself was
967
+ // sanitised - so it is cleaned here, as render-scope's fragment is.
968
+ const { renderCollectionFragment, sanitizePageHtml } = await import('../../services/markdown.js');
969
+ // These attributes came from the browser, not from a page: the fields
970
+ // public read lists (api.read.fields) are all it may draw, filter or sort on.
971
+ const html = sanitizePageHtml(await renderCollectionFragment(attrs, {readFields: schema.api?.read?.fields}));
958
972
  return { html };
959
973
  });
960
974
 
@@ -25,7 +25,7 @@ import {keepSubmissionsOut} from '../../services/siteGitignore.js';
25
25
  import {createRequire} from 'module';
26
26
  import {fileURLToPath} from 'url';
27
27
  import path from 'path';
28
- import {deleteForm, ensureCollectionForForm, ensureFormsDir, listForms, maxSubmissionBytes, publicFileLimits, readForm, slugify, writeForm} from '../../services/forms.js';
28
+ import {cleanFieldDescriptions, deleteForm, ensureCollectionForForm, ensureFormsDir, listForms, maxSubmissionBytes, publicFileLimits, publicFormDescriptions, readForm, slugify, writeForm} from '../../services/forms.js';
29
29
  import {executeAction} from '../../services/actions.js';
30
30
  // The same rules the browser draws the buttons by (a Cancel link must be safe).
31
31
  import {buttonSettingsProblems, formClassProblems, publicButtonSettings} from '../../../public/js/form-submit.mjs';
@@ -680,7 +680,7 @@ export async function formsRoutes(fastify) {
680
680
  slug,
681
681
  title: title.trim(),
682
682
  description: cleanRichText(body.description, {max: 4000}),
683
- fields: Array.isArray(body.fields) ? body.fields : [],
683
+ fields: cleanFieldDescriptions(body.fields),
684
684
  settings: {
685
685
  submitText: 'Submit',
686
686
  successMessage: 'Thank you for your submission.',
@@ -754,7 +754,7 @@ export async function formsRoutes(fastify) {
754
754
  // A Cancel link saved before the check (or written by hand) is
755
755
  // not handed to the page.
756
756
  if (safe.settings) safe.settings = publicButtonSettings(safe.settings);
757
- return publicFileLimits(safe);
757
+ return publicFileLimits(publicFormDescriptions(safe));
758
758
  } catch {
759
759
  return reply.status(404).send({ error: 'Form not found.' });
760
760
  }
@@ -785,6 +785,8 @@ export async function formsRoutes(fastify) {
785
785
  updatedAt: new Date().toISOString()
786
786
  };
787
787
  if ('description' in body) updated.description = cleanRichText(body.description, {max: 4000});
788
+ // A step's and an option's description are rich text too; what is answered is what is stored.
789
+ if (Array.isArray(updated.fields)) updated.fields = cleanFieldDescriptions(updated.fields);
788
790
  if (await refusedPluginTarget(request, reply, updated)) return;
789
791
  await writeForm(slug, updated);
790
792
 
@@ -18,10 +18,13 @@ import {
18
18
  authenticate as defaultAuthenticate,
19
19
  requirePermission as defaultRequirePermission
20
20
  } from '../../middleware/auth.js';
21
+ import {cleanRichText} from '../../services/richText.js';
21
22
 
22
23
  const VALID_WIDTHS = new Set(['narrow', 'normal', 'wide', 'full']);
23
24
  const BG_COLOR_RE = /^[a-zA-Z0-9#(),.\s%/-]+$/;
24
25
  const CLASS_RE = /[^a-zA-Z0-9\s_-]/g;
26
+ /** A layout's description: rich text (richText.js), markup included. */
27
+ const DESCRIPTION_MAX = 2000;
25
28
 
26
29
  const BUILTIN_PRESETS = {
27
30
  default: {
@@ -85,7 +88,7 @@ function sanitisePreset(data) {
85
88
  bgImage: typeof data.bgImage === 'string' ? data.bgImage.trim() : '',
86
89
  class: typeof data.class === 'string' ? data.class.replace(CLASS_RE, '').trim() : '',
87
90
  label: String(data.label || '').slice(0, 60).trim(),
88
- description: String(data.description || '').slice(0, 200).trim()
91
+ description: cleanRichText(data.description, {max: DESCRIPTION_MAX})
89
92
  };
90
93
  }
91
94
 
@@ -193,7 +196,10 @@ export async function layoutsRoutes(fastify, opts = {}) {
193
196
  return reply.status(400).send({error: `Invalid preset "${key}": missing or empty "label" field`});
194
197
  }
195
198
  }
196
- saveConfig('presets', data);
199
+ // Hand-built payloads too: a description is cleaned like any other save.
200
+ const cleaned = Object.fromEntries(Object.entries(data).map(([key, preset]) => [key,
201
+ typeof preset.description === 'string' ? {...preset, description: cleanRichText(preset.description, {max: DESCRIPTION_MAX})} : preset]));
202
+ saveConfig('presets', cleaned);
197
203
  return {success: true};
198
204
  });
199
205
 
@@ -232,8 +238,6 @@ export async function layoutsRoutes(fastify, opts = {}) {
232
238
  }
233
239
  presets[key] = {
234
240
  ...presets[key],
235
- label: String(label).slice(0, 60).trim(),
236
- description: String(description || '').slice(0, 200).trim(),
237
241
  ...sanitisePreset({label, description, ...rest}),
238
242
  key,
239
243
  builtin: presets[key].builtin // never overwrite builtin flag
@@ -17,6 +17,8 @@ import {invalidateTags} from '../../services/cache/index.js';
17
17
  import {excluded} from '../../../admin/js/lib/seo-settings.js';
18
18
  import {checkSeoDefaults, seoDefaults} from '../../../admin/js/lib/seo-defaults.js';
19
19
  import {googleBusinessRoutes} from './google-business.js';
20
+ import {cleanRichText, richTextLine} from '../../services/richText.js';
21
+ import {SEO_DESCRIPTION_MAX} from '../../services/content.js';
20
22
 
21
23
  /**
22
24
  * @param {import('fastify').FastifyInstance} fastify
@@ -88,11 +90,12 @@ export async function seoRoutes(fastify, opts = {}) {
88
90
  const s = site();
89
91
  return {
90
92
  urlPath, origin, kind: page ? 'page' : 'url',
91
- page: page ? {title: page.title, status: page.status, description: page.description || ''} : null,
93
+ page: page ? {title: page.title, status: page.status, description: richTextLine(page.description)} : null,
92
94
  fields,
93
95
  live: facts ? {title: facts.title, description: facts.description || '', image: facts.og.image, h1: facts.headings.find(h => h.level === 1)?.text || '', words: facts.words, canonical: facts.canonical} : null,
94
96
  status: fetched.status || 0,
95
- defaults: {separator: s.seo?.titleSeparator || ' | ', siteTitle: s.seo?.defaultTitle || s.title || '', description: s.seo?.defaultDescription || '', image: s.seo?.defaultImage || ''},
97
+ // Shown as the placeholder and counted by the length meter: the words.
98
+ defaults: {separator: s.seo?.titleSeparator || ' | ', siteTitle: s.seo?.defaultTitle || s.title || '', description: richTextLine(s.seo?.defaultDescription), image: s.seo?.defaultImage || ''},
96
99
  analysis: judged,
97
100
  limits,
98
101
  redirect: e.matchRedirect(e.store.rules(), urlPath)?.rule || null
@@ -104,7 +107,8 @@ export async function seoRoutes(fastify, opts = {}) {
104
107
  const b = request.body ?? {};
105
108
  const urlPath = e.normalisePath(b.path || '') || '/';
106
109
  const clip = (v, n) => String(v ?? '').trim().slice(0, n);
107
- const fields = {title: clip(b.title, 200), description: clip(b.description, 400), image: clip(b.image, 500), noindex: b.noindex === true, focus: clip(b.focus, 100)};
110
+ // The description is rich text (richText.js): cleaned, its limit allowing for markup.
111
+ const fields = {title: clip(b.title, 200), description: cleanRichText(b.description, {max: SEO_DESCRIPTION_MAX}), image: clip(b.image, 500), noindex: b.noindex === true, focus: clip(b.focus, 100)};
108
112
  if (fields.image && !/^(https?:\/\/|\/)/i.test(fields.image)) return reply.code(400).send({error: 'The image: a path like /media/photo.jpg, or a full web address.'});
109
113
  const page = await getPage(urlPath).catch(() => null);
110
114
  if (page) {
@@ -206,7 +210,9 @@ export async function seoRoutes(fastify, opts = {}) {
206
210
  if (r.errors) return reply.code(400).send({error: Object.values(r.errors).join(' '), errors: r.errors});
207
211
  if (defaults) {
208
212
  const current = site();
209
- saveConfig('site', {...current, seo: {...current.seo, ...defaults.defaults}});
213
+ // The default description is rich text: cleaned here, the shared check only measures it.
214
+ const cleaned = {...defaults.defaults, defaultDescription: cleanRichText(defaults.defaults.defaultDescription, {max: SEO_DESCRIPTION_MAX})};
215
+ saveConfig('site', {...current, seo: {...current.seo, ...cleaned}});
210
216
  await invalidateTags(['site']);
211
217
  }
212
218
  return {settings: r.settings, defaults: seoDefaults(site()), hooks: true};
@@ -21,7 +21,7 @@
21
21
  import fs from 'fs/promises';
22
22
  import path from 'path';
23
23
  import { config } from '../../config.js';
24
- import { applyFilter } from '../filterEngine.js';
24
+ import { applyFilter, searchedValues } from '../filterEngine.js';
25
25
  import { withFileLock, writeFileAtomic } from './fileLock.js';
26
26
  import {fileIn} from '../safePath.js';
27
27
 
@@ -77,16 +77,17 @@ export class FileAdapter {
77
77
  * @param {string} [opts.sort='createdAt']
78
78
  * @param {string} [opts.order='desc'] - 'asc' | 'desc'
79
79
  * @param {string} [opts.search] - Free-text substring across all fields
80
+ * @param {string[]} [opts.searchFields] - Search these fields only (a caller who may read only some)
80
81
  * @param {Record<string, unknown>} [opts.filter] - Structured filter; see filterEngine.js
81
82
  * @returns {Promise<{ entries: object[], total: number, page: number, limit: number }>}
82
83
  */
83
- async list(slug, { page = 1, limit = 50, sort = 'createdAt', order = 'desc', search, filter } = {}) {
84
+ async list(slug, { page = 1, limit = 50, sort = 'createdAt', order = 'desc', search, searchFields, filter } = {}) {
84
85
  let entries = await read(slug);
85
86
 
86
87
  if (search) {
87
88
  const term = search.toLowerCase();
88
89
  entries = entries.filter(entry =>
89
- Object.values(entry.data || {}).some(v => String(v).toLowerCase().includes(term))
90
+ searchedValues(entry.data, searchFields).some(v => String(v).toLowerCase().includes(term))
90
91
  );
91
92
  }
92
93
 
@@ -20,6 +20,7 @@
20
20
  * archive(slug) → string|null (set the entries aside after a storage move)
21
21
  */
22
22
  import { toSafeMongoQuery } from '../mongoQueryGuard.js';
23
+ import { searchedValues } from '../filterEngine.js';
23
24
 
24
25
  /** Prefix applied to all CMS collection names in MongoDB to avoid collisions. */
25
26
  const PREFIX = 'cms_';
@@ -93,10 +94,11 @@ export class MongoAdapter {
93
94
  * @param {string} [opts.sort='createdAt']
94
95
  * @param {string} [opts.order='desc'] - 'asc' | 'desc'
95
96
  * @param {string} [opts.search] - Free-text substring across all fields
97
+ * @param {string[]} [opts.searchFields] - Search these fields only (a caller who may read only some)
96
98
  * @param {Record<string, unknown>} [opts.filter] - Structured filter; see filterEngine.js
97
99
  * @returns {Promise<{ entries: object[], total: number, page: number, limit: number }>}
98
100
  */
99
- async list(slug, { page = 1, limit = 50, sort = 'createdAt', order = 'desc', search, filter } = {}) {
101
+ async list(slug, { page = 1, limit = 50, sort = 'createdAt', order = 'desc', search, searchFields, filter } = {}) {
100
102
  const col = await this._col(slug);
101
103
 
102
104
  const sortField = sort === 'createdAt' ? 'meta.createdAt' : `data.${sort}`;
@@ -116,7 +118,7 @@ export class MongoAdapter {
116
118
 
117
119
  const term = search.toLowerCase();
118
120
  const matched = all.filter(entry =>
119
- Object.values(entry.data || {}).some(v => String(v).toLowerCase().includes(term))
121
+ searchedValues(entry.data, searchFields).some(v => String(v).toLowerCase().includes(term))
120
122
  );
121
123
 
122
124
  const total = matched.length;
@@ -4,6 +4,7 @@
4
4
  * Pages live in content/pages/ mirroring URL structure.
5
5
  */
6
6
  import fs from 'fs/promises';
7
+ import {cleanRichText} from './richText.js';
7
8
  import path from 'path';
8
9
  import matter from 'gray-matter';
9
10
  import {parseMarkdown, serialiseMarkdown} from './markdown.js';
@@ -282,6 +283,25 @@ function cleanAdminTags(meta) {
282
283
  else delete meta.adminTags;
283
284
  }
284
285
 
286
+ /** The page's Description and its SEO description: rich text (richText.js), markup included. */
287
+ export const PAGE_DESCRIPTION_MAX = 4000;
288
+ export const SEO_DESCRIPTION_MAX = 2000;
289
+
290
+ /**
291
+ * The two descriptions of a page as they are stored. Only what this save
292
+ * carries is touched; a description sent as anything but text (null removes
293
+ * an SEO key, see updatePage) is left for the caller's own rules.
294
+ *
295
+ * @param {object} meta - frontmatter about to be written, changed in place
296
+ * @param {object} sent - the frontmatter this save was given
297
+ */
298
+ function cleanPageDescriptions(meta, sent) {
299
+ if (typeof sent?.description === 'string') meta.description = cleanRichText(sent.description, {max: PAGE_DESCRIPTION_MAX});
300
+ if (typeof sent?.seo?.description === 'string' && meta.seo && typeof meta.seo === 'object' && 'description' in meta.seo) {
301
+ meta.seo = {...meta.seo, description: cleanRichText(sent.seo.description, {max: SEO_DESCRIPTION_MAX})};
302
+ }
303
+ }
304
+
285
305
  export async function createPage(urlPath, frontmatter, body, {exclusive = false} = {}) {
286
306
  const filePath = urlPathToFilePath(urlPath);
287
307
  await fs.mkdir(path.dirname(filePath), { recursive: true });
@@ -306,6 +326,7 @@ export async function createPage(urlPath, frontmatter, body, {exclusive = false}
306
326
  };
307
327
  if (meta.project === '' || meta.project === undefined) delete meta.project;
308
328
  cleanAdminTags(meta);
329
+ cleanPageDescriptions(meta, frontmatter);
309
330
 
310
331
  // `exclusive`: only ever a new file (an API token's create) - EEXIST when anything is there,
311
332
  // even a page whose frontmatter will not parse (getPage reads that as missing).
@@ -352,6 +373,8 @@ export async function updatePage(urlPath, frontmatter, body, {author} = {}) {
352
373
  meta.seo = merged;
353
374
  }
354
375
 
376
+ cleanPageDescriptions(meta, frontmatter);
377
+
355
378
  if (existingMeta.createdAt) meta.createdAt = existingMeta.createdAt;
356
379
 
357
380
  // '' is the editor's "inherit by rootUrl" choice - drop the key so the
@@ -12,6 +12,7 @@ import {getConfig, saveConfig} from '../config.js';
12
12
  import {CONTENT_RESOURCES} from './apiTokens.js';
13
13
  import {isPubliclyListed} from './search.js';
14
14
  import {plural} from './sidebarBadges.js';
15
+ import {isRichText, renderRichText, richTextLine} from './richText.js';
15
16
 
16
17
  export const FORMATS = Object.freeze(['html', 'markdown']);
17
18
 
@@ -131,9 +132,27 @@ export function domma(html) {
131
132
  * @returns {object}
132
133
  */
133
134
  export function pageSummary(page) {
134
- return pick(page, SUMMARY_KEYS);
135
+ return withDescription(pick(page, SUMMARY_KEYS));
135
136
  }
136
137
 
138
+ /**
139
+ * A page's `description` as API consumers have always had it - plain text -
140
+ * with `descriptionHtml` beside it: the same words as safe HTML (formatted
141
+ * when the description was written in the rich editor, escaped paragraphs
142
+ * when it is plain). Neither key is added to a page without a description.
143
+ *
144
+ * @param {object} out - a payload holding `description` as stored
145
+ * @returns {object}
146
+ */
147
+ function withDescription(out) {
148
+ if (typeof out.description !== 'string') return out;
149
+ const html = renderRichText(out.description);
150
+ return {...out, description: richTextLine(out.description), ...(html && {descriptionHtml: html})};
151
+ }
152
+
153
+ /** An SEO block's description as the meta tag carries it: plain text. */
154
+ const plainSeo = (seo) => (isRichText(seo.description) ? {...seo, description: richTextLine(seo.description)} : seo);
155
+
137
156
  /**
138
157
  * One page. `html` is the body only (page.html), not the full document with
139
158
  * navbar and footer; `markdown` is the source, shortcodes and all.
@@ -143,8 +162,8 @@ export function pageSummary(page) {
143
162
  * @returns {object}
144
163
  */
145
164
  export function pageDetail(page, {format}) {
146
- const out = pick(page, DETAIL_KEYS);
147
- if (page.seo && typeof page.seo === 'object') out.seo = pick(page.seo, SEO_KEYS);
165
+ const out = withDescription(pick(page, DETAIL_KEYS));
166
+ if (page.seo && typeof page.seo === 'object') out.seo = plainSeo(pick(page.seo, SEO_KEYS));
148
167
  if (format === 'html' || format === 'both') out.html = page.html || '';
149
168
  if (format === 'markdown' || format === 'both') out.markdown = page.content || '';
150
169
  const custom = Array.isArray(page.usedComponents) ? page.usedComponents : [];
@@ -170,7 +189,11 @@ export function publicSiteSettings(site = {}) {
170
189
  if (site.footer && typeof site.footer === 'object') {
171
190
  out.footer = {...site.footer, links: (site.footer.links || []).filter(l => !l?.hidden)};
172
191
  }
173
- if (site.seo && typeof site.seo === 'object') out.seo = pick(site.seo, ['defaultTitle', 'titleSeparator', 'defaultDescription']);
192
+ if (site.seo && typeof site.seo === 'object') {
193
+ out.seo = pick(site.seo, ['defaultTitle', 'titleSeparator', 'defaultDescription']);
194
+ // As in the meta tag: a rich default description is given as its words.
195
+ if (isRichText(out.seo.defaultDescription)) out.seo.defaultDescription = richTextLine(out.seo.defaultDescription);
196
+ }
174
197
  return out;
175
198
  }
176
199
 
@@ -74,6 +74,39 @@ export function parseFilterKey(key) {
74
74
  return { field: key, op: '_eq' };
75
75
  }
76
76
 
77
+ /**
78
+ * The values a free-text search looks through: every field, or only those named
79
+ * (a caller who may read only some fields must not find rows by the others).
80
+ *
81
+ * @param {object|null|undefined} data
82
+ * @param {string[]|null|undefined} fields
83
+ * @returns {unknown[]}
84
+ */
85
+ export function searchedValues(data, fields) {
86
+ if (!Array.isArray(fields)) return Object.values(data || {});
87
+ return fields.filter(f => Object.hasOwn(data || {}, f)).map(f => data[f]);
88
+ }
89
+
90
+ /**
91
+ * A filter cut down to a set of field names - for a caller who may read only
92
+ * some fields (`api.read.fields`). A condition on any other field is dropped
93
+ * (meta pseudo-fields included), so the answer cannot be used to ask yes/no
94
+ * questions about a value the caller is never shown. The field is read the
95
+ * way the engine reads it (`parseFilterKey`, first segment of a dot-path).
96
+ *
97
+ * @param {Record<string, unknown>|null|undefined} filter
98
+ * @param {Set<string>} allowed
99
+ * @returns {Record<string, unknown>}
100
+ */
101
+ export function confineFilter(filter, allowed) {
102
+ const out = {};
103
+ for (const key of Object.keys(filter || {})) {
104
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;
105
+ if (allowed.has(parseFilterKey(key).field.split('.')[0])) out[key] = filter[key];
106
+ }
107
+ return out;
108
+ }
109
+
77
110
  /**
78
111
  * Resolve a dot-path against an entry, with two special-cased pseudo-fields.
79
112
  *
@@ -11,7 +11,7 @@ import * as cache from './cache/index.js';
11
11
  import {buttonSettingsProblems, formClassProblems} from '../../public/js/form-submit.mjs';
12
12
  import {fileIn} from './safePath.js';
13
13
  import {getConfig} from '../config.js';
14
- import {cleanRichText} from './richText.js';
14
+ import {cleanRichText, isRichText, renderRichTextPhrasing, richTextLine} from './richText.js';
15
15
 
16
16
  /** What one submission's files may hold in memory together when server.json sets nothing: 50 MB. */
17
17
  export const DEFAULT_MAX_SUBMISSION_BYTES = 50 * 1024 * 1024;
@@ -47,6 +47,61 @@ export function publicFileLimits(form) {
47
47
  return {...form, fileLimits: {maxTotalBytes: cap}};
48
48
  }
49
49
 
50
+ /** A wizard step's description and a chooser option's: rich text (richText.js), markup included. */
51
+ const STEP_DESCRIPTION_MAX = 2000;
52
+ const OPTION_DESCRIPTION_MAX = 1000;
53
+
54
+ /**
55
+ * A form's fields as they are stored: a step's description (a page-break
56
+ * field) and each option's description cleaned as rich text. A plain one is
57
+ * kept as typed; nothing else about a field is touched.
58
+ *
59
+ * @param {*} fields
60
+ * @returns {Array}
61
+ */
62
+ export function cleanFieldDescriptions(fields) {
63
+ if (!Array.isArray(fields)) return [];
64
+ return fields.map((f) => {
65
+ if (!f || typeof f !== 'object' || Array.isArray(f)) return f;
66
+ let next = f;
67
+ if (f.type === 'page-break' && typeof f.description === 'string') {
68
+ next = {...next, description: cleanRichText(f.description, {max: STEP_DESCRIPTION_MAX})};
69
+ }
70
+ if (Array.isArray(f.options) && f.options.some(o => o && typeof o === 'object' && typeof o.description === 'string')) {
71
+ next = {...next, options: f.options.map(o => (o && typeof o === 'object' && typeof o.description === 'string'
72
+ ? {...o, description: cleanRichText(o.description, {max: OPTION_DESCRIPTION_MAX})} : o))};
73
+ }
74
+ return next;
75
+ });
76
+ }
77
+
78
+ /**
79
+ * A form's descriptions as the page is given them. Domma draws both, and not
80
+ * the same way:
81
+ *
82
+ * - A step's description goes into the wizard's heading as HTML, inside a
83
+ * `<p>`. It is given as cleaned inline HTML (bold, italic, links; a
84
+ * paragraph or list item becomes a line break). A plain one written before
85
+ * descriptions were rich was drawn as HTML too, so inline markup typed by
86
+ * hand still works - and everything else in it is now dropped.
87
+ * - An option's description is drawn as text (the chooser sets textContent),
88
+ * so a rich one is given as its words.
89
+ *
90
+ * @param {object} form
91
+ * @returns {object}
92
+ */
93
+ export function publicFormDescriptions(form) {
94
+ if (!Array.isArray(form?.fields)) return form;
95
+ return {...form, fields: form.fields.map((f) => {
96
+ if (!f || typeof f !== 'object') return f;
97
+ if (f.type === 'page-break') {
98
+ return typeof f.description === 'string' ? {...f, description: renderRichTextPhrasing(f.description, {legacyHtml: true})} : f;
99
+ }
100
+ if (!Array.isArray(f.options) || !f.options.some(o => isRichText(o?.description))) return f;
101
+ return {...f, options: f.options.map(o => (isRichText(o?.description) ? {...o, description: richTextLine(o.description)} : o))};
102
+ })};
103
+ }
104
+
50
105
  /** The cache tag on every page that drew a form's file cap (markdown.js adds it). */
51
106
  export const FILE_LIMITS_TAG = 'forms:file-limits';
52
107
 
@@ -124,6 +179,7 @@ export async function writeForm(slug, data) {
124
179
  const {fileLimits: _limits, ...rest} = data;
125
180
  data = rest;
126
181
  }
182
+ if (data && Array.isArray(data.fields)) data = {...data, fields: cleanFieldDescriptions(data.fields)};
127
183
  const file = fileIn(FORMS_DIR, slug, '.json');
128
184
  await fs.writeFile(file, JSON.stringify(data, null, 4) + '\n', 'utf8');
129
185
  await cache.invalidateTags([`form:${slug}`]);
@@ -237,7 +293,7 @@ export async function createForm(data) {
237
293
  title: trimmedTitle,
238
294
  description: cleanRichText(description, {max: 4000}),
239
295
  ...(plugin ? {plugin} : {}),
240
- fields: Array.isArray(fields) ? fields : [],
296
+ fields: cleanFieldDescriptions(fields),
241
297
  settings: {
242
298
  submitText: 'Submit',
243
299
  successMessage: 'Thank you for your submission.',
@@ -11,6 +11,7 @@ import {getLastSendResult, isSmtpConfigured} from './email.js';
11
11
  import {listPages} from './content.js';
12
12
  import {getPluginLoadFailures} from './plugins.js';
13
13
  import {FORMS_DIR} from './forms.js';
14
+ import {richTextLine} from './richText.js';
14
15
 
15
16
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
17
  const ROOT = path.resolve(__dirname, '..', '..');
@@ -142,7 +143,8 @@ async function checkStalePages() {
142
143
 
143
144
  async function checkMissingMeta() {
144
145
  const pages = await listPages({render: false}).catch(() => []);
145
- const missing = pages.filter(p => !p.description || String(p.description).trim() === '');
146
+ // Judged on its words: an emptied rich editor's markup is not a description.
147
+ const missing = pages.filter(p => !richTextLine(p.description));
146
148
  return {
147
149
  id: 'missing-meta',
148
150
  level: missing.length === 0 ? 'ok' : 'warn',