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
@@ -12,6 +12,7 @@ import {commentKey, commentNotice} from './lib/notices.js';
12
12
  import {authorPatch, permissionChecker} from './lib/access.js';
13
13
  import {getPermissionsFor, invalidate as invalidateRoles} from '../../server/services/roles.js';
14
14
  import {fmtDate} from '../_lib/admin/ui/dates.js';
15
+ import {cleanRichText} from '../../server/services/richText.js';
15
16
 
16
17
  const POSTS_SLUG = 'blog-posts';
17
18
  const CATEGORIES_SLUG = 'blog-categories';
@@ -81,6 +82,21 @@ export function postFields(body, user) {
81
82
  return out;
82
83
  }
83
84
 
85
+ /** The longest a category's description may be, markup included. */
86
+ const CATEGORY_DESCRIPTION_MAX = 4000;
87
+
88
+ /**
89
+ * A category's description as it is stored: rich text from the editor is
90
+ * cleaned to the shared allow-list, plain text (typed before, or from an API
91
+ * client) is kept as typed. Pure, so the save rule can be tested.
92
+ *
93
+ * @param {*} value - from a request body
94
+ * @returns {string}
95
+ */
96
+ export function categoryDescription(value) {
97
+ return cleanRichText(value, {max: CATEGORY_DESCRIPTION_MAX});
98
+ }
99
+
84
100
  // What a visitor may say in a comment, and how much of it. The form's
85
101
  // `maxlength` is the browser's word only; the route must cap too.
86
102
  const COMMENT_CAPS = {authorName: 80, authorEmail: 160, authorUrl: 300, body: 5000};
@@ -643,7 +659,7 @@ export default async function blogPlugin(fastify, options) {
643
659
  const entry = await createEntry(CATEGORIES_SLUG, {
644
660
  name: name.trim(),
645
661
  slug: derivedSlug,
646
- description: typeof description === 'string' ? description.trim() : ''
662
+ description: categoryDescription(description)
647
663
  }, { source: 'admin' });
648
664
 
649
665
  return reply.code(201).send(toCategory(entry));
@@ -663,7 +679,7 @@ export default async function blogPlugin(fastify, options) {
663
679
  const merged = { ...entry.data };
664
680
  if (typeof b.name === 'string' && b.name.trim()) merged.name = b.name.trim();
665
681
  if (typeof b.slug === 'string' && b.slug.trim()) merged.slug = slugify(b.slug);
666
- if (typeof b.description === 'string') merged.description = b.description.trim();
682
+ if (typeof b.description === 'string') merged.description = categoryDescription(b.description);
667
683
 
668
684
  const updated = await updateEntry(CATEGORIES_SLUG, request.params.id, merged);
669
685
  return reply.send(toCategory(updated));
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "blog",
3
3
  "displayName": "Blog",
4
- "version": "1.10.3",
4
+ "version": "1.11.0",
5
5
  "tier": "free",
6
6
  "description": "Public-facing blog with posts, categories and comments - layouts and listings built from editable blocks.",
7
7
  "author": "Domma CMS",
@@ -79,23 +79,23 @@
79
79
  ],
80
80
  "views": {
81
81
  "plugin-blog-posts": {
82
- "entry": "blog/admin/views/blog.js?v=11",
82
+ "entry": "blog/admin/views/blog.js?v=12",
83
83
  "exportName": "blogView"
84
84
  },
85
85
  "plugin-blog-post-editor": {
86
- "entry": "blog/admin/views/post-editor.js?v=11",
86
+ "entry": "blog/admin/views/post-editor.js?v=12",
87
87
  "exportName": "postEditorView"
88
88
  },
89
89
  "plugin-blog-categories": {
90
- "entry": "blog/admin/views/categories.js?v=10",
90
+ "entry": "blog/admin/views/categories.js?v=11",
91
91
  "exportName": "categoriesView"
92
92
  },
93
93
  "plugin-blog-comments": {
94
- "entry": "blog/admin/views/comments.js?v=12",
94
+ "entry": "blog/admin/views/comments.js?v=13",
95
95
  "exportName": "commentsView"
96
96
  },
97
97
  "plugin-blog-settings": {
98
- "entry": "blog/admin/views/settings.js?v=10",
98
+ "entry": "blog/admin/views/settings.js?v=11",
99
99
  "exportName": "settingsView"
100
100
  }
101
101
  }
@@ -16,6 +16,7 @@ import path from 'path';
16
16
  import {fileURLToPath} from 'url';
17
17
  import {renderBlogPage} from '../../server/services/renderer.js';
18
18
  import {getConfig} from '../../server/config.js';
19
+ import {renderRichText} from '../../server/services/richText.js';
19
20
  import {byNewest, escapeHtml, matchBlogPath, pickDisplay, safeImageUrl} from './lib/layouts.js';
20
21
  import {catalogue, renderCards} from './lib/render.js';
21
22
  import {authorNamesFor, isVisible, liveBase, liveSettings, loadEntries, publicPost, renderPostPage, resolveAuthorName} from './lib/page.js';
@@ -24,7 +25,7 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
24
25
  const TEMPLATES_DIR = path.join(__dirname, 'templates');
25
26
 
26
27
  /** Bumped with the plugin, so a release is never served a stale script. */
27
- const ASSET_V = '1.10.1';
28
+ const ASSET_V = '1.11.0';
28
29
 
29
30
  /**
30
31
  * Above this many posts a listing pages on the server instead: the browser
@@ -68,6 +69,19 @@ function scriptJson(value) {
68
69
  // Plugin
69
70
  // ---------------------------------------------------------------------------
70
71
 
72
+ /**
73
+ * The words under a listing's title. A category's description is rich text
74
+ * (or plain, when typed before it was): renderRichText cleans the one and
75
+ * escapes the other, so its result goes in as it is - never escaped again.
76
+ *
77
+ * @param {*} intro - as stored
78
+ * @returns {string} '' for nothing
79
+ */
80
+ export function archiveIntroHtml(intro) {
81
+ const html = renderRichText(intro);
82
+ return html ? `<div class="blog-archive-intro">${html}</div>` : '';
83
+ }
84
+
71
85
  export default async function blogPublicPlugin(fastify, options) {
72
86
  const {settings, config} = options;
73
87
 
@@ -126,7 +140,7 @@ ${items || ''}
126
140
  path.join(TEMPLATES_DIR, 'index.html'),
127
141
  {
128
142
  archiveTitle: escapeHtml(title),
129
- archiveIntro: intro ? `<p class="blog-archive-intro">${escapeHtml(intro)}</p>` : '',
143
+ archiveIntro: archiveIntroHtml(intro),
130
144
  archive,
131
145
  pagination: interactive ? '' : buildPagination(safePage, totalPages, base, requested),
132
146
  assetV: ASSET_V
@@ -30,6 +30,9 @@
30
30
  .blog-archive-head { margin-bottom: 1.25rem; }
31
31
  .blog-archive-head h1 { margin: 0 0 .35rem; font-size: clamp(2rem, 4vw, 2.6rem); letter-spacing: -.015em; }
32
32
  .blog-archive-intro { margin: 0; color: var(--dm-text-muted); font-size: 1.1rem; max-width: 42rem; }
33
+ .blog-archive-intro > * { margin: 0 0 .5em; }
34
+ .blog-archive-intro > :last-child { margin-bottom: 0; }
35
+ .blog-archive-intro ul, .blog-archive-intro ol { padding-left: 1.25em; }
33
36
 
34
37
  .blog-archive-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
35
38
  .blog-archive-bar:empty { display: none; }
@@ -15,8 +15,8 @@ import assert from 'node:assert/strict';
15
15
  import zlib from 'zlib';
16
16
  import Fastify from 'fastify';
17
17
  import compress from '@fastify/compress';
18
- import blogPublicPlugin from '../plugin.public.js';
19
- import {commentFields, postFields, usePermissionLookup} from '../plugin.js';
18
+ import blogPublicPlugin, {archiveIntroHtml} from '../plugin.public.js';
19
+ import {categoryDescription, commentFields, postFields, usePermissionLookup} from '../plugin.js';
20
20
  import {publicPost, slugHolder} from '../lib/page.js';
21
21
 
22
22
  async function buildPublic() {
@@ -121,3 +121,30 @@ test('a public comment is capped, needs an email, and names its post', () => {
121
121
  assert.match(commentFields({authorName: 'Jo', authorEmail: 'a@b.co', body: 'hi'}).error, /postId/);
122
122
  assert.match(commentFields({postId: 'p1', authorName: 'Jo', authorEmail: 'a@b.co'}).error, /body/);
123
123
  });
124
+
125
+ const HOSTILE = `<p onclick="steal()">Hi <strong>there</strong><script>alert(1)</script><img src=x onerror=alert(1)> <a href="javascript:alert(1)">bad</a> <a href="https://example.com" style="color:red">good</a></p>`;
126
+ const noScript = (html) => {
127
+ for (const bad of ['<script', 'onclick', 'onerror', 'javascript:', '<img', 'style=']) assert.ok(!html.includes(bad), `${bad} in ${html}`);
128
+ };
129
+
130
+ test('a category description is saved as rich text, cleaned; plain text is kept as typed', () => {
131
+ assert.equal(categoryDescription('<p>News and <strong>views</strong>.</p><ul><li>One</li></ul>'), '<p>News and <strong>views</strong>.</p><ul><li>One</li></ul>');
132
+ assert.equal(categoryDescription(' What is new,\nand what changed. '), 'What is new,\nand what changed.', 'plain: trimmed, its line break kept');
133
+ assert.equal(categoryDescription('<script>alert(1)</script> hello'), '<script>alert(1)</script> hello', 'plain text that mentions a tag stays plain (escaped when shown)');
134
+ const saved = categoryDescription(HOSTILE);
135
+ noScript(saved);
136
+ assert.match(saved, /<strong>there<\/strong>/);
137
+ assert.match(saved, /<a href="https:\/\/example\.com" rel="noopener noreferrer">good<\/a>/);
138
+ assert.equal(categoryDescription('<p><br></p>'), '', 'an empty editor saves nothing');
139
+ assert.equal(categoryDescription(undefined), '');
140
+ assert.ok(categoryDescription(`<p>${'x'.repeat(9000)}</p>`).length <= 4000 + 20, 'cut to the limit (closed again, so a closing tag over)');
141
+ assert.match(categoryDescription(`<p>${'x'.repeat(9000)}</p>`), /<\/p>$/, 'and still closed');
142
+ });
143
+
144
+ test('the category intro on the site: rich is formatted, plain is escaped, hostile is cleaned', () => {
145
+ assert.equal(archiveIntroHtml(''), '');
146
+ assert.equal(archiveIntroHtml('<p>News and <em>views</em>.</p>'), '<div class="blog-archive-intro"><p>News and <em>views</em>.</p></div>');
147
+ assert.equal(archiveIntroHtml('Tips & <b>tricks</b>\nfor you'), '<div class="blog-archive-intro"><p>Tips &amp; &lt;b&gt;tricks&lt;/b&gt;<br>for you</p></div>', 'text saved before the editor reads as it did');
148
+ noScript(archiveIntroHtml(HOSTILE)); // stored around the API: cleaned again on the way out
149
+ assert.ok(!archiveIntroHtml('<script>alert(1)</script>').includes('<script'));
150
+ });
@@ -192,3 +192,25 @@ at the next prune (older than a day, no longer named). Found on the dcm click-th
192
192
  mid-send keeps a draft of text already sent (and invites a second send).
193
193
  - `rowKeys` stops Enter/Space and runs the row's main action on the next tick: Domma's confirm adds its document
194
194
  keydown while the opening Enter is still bubbling and would read it as OK = Throw away.
195
+
196
+ ## Unreleased: the description is rich text
197
+
198
+ - **Compose** (`#fb-desc` in send.js) is the CMS's shared rich field (`richDescription()`, `/admin/js/lib/rich-field.js`,
199
+ CMS 1.67.0, hence `minCmsVersion`). The screenshot paste is heard on the editor's frame
200
+ (`.rich-description-editor`) in the CAPTURE phase, before the editor's own paste handler; it falls back to the textarea.
201
+ - **Stored:** the manager's record keeps ONE string in `description` - rich text (`cleanRichText`, 16,000 with markup)
202
+ or plain text as typed (8,000, older sites and reports from before). `cleanDescription()` in lib/shape.js is the one
203
+ cleaner; a description whose text is empty is still refused.
204
+ - **On the wire it is never rich in `description`.** Either end may run an older version that draws `description`
205
+ escaped, so both directions (`buildPayload` to `/fleet/submit`, `senderView` from `/fleet/mine` and `/sent`) send
206
+ `wireDescription()`: `description` = plain text, `descriptionHtml` = the cleaned formatting ('' / absent when plain).
207
+ The receiver stores `descriptionHtml` when it is rich (cleaned again), else `description`. The site's outbox keeps the
208
+ payload as sent. `buildPayload` drops `descriptionHtml` when the JSON would pass `PAYLOAD_MAX_BYTES` (28 KB; the
209
+ manager's body limit is 32 KB and an older manager cannot be asked for more) - the report then arrives as plain text.
210
+ - **Shown:** `showRichText()` in the inbox detail (`r.description`) and the sender's detail
211
+ (`r.descriptionHtml || r.description`). Never `innerHTML`, never `esc()` of a rich value.
212
+ - **Plain:** inbox search (`richTextToPlain`), the new-report notice (`descriptionSummary`, 300), "Copy what was sent"
213
+ (the sender view's `description` is already plain).
214
+ - **Waypoint:** `issueDescription(d, {rich: wp.richDescriptions === true})` - rich text plus the facts as an escaped
215
+ paragraph for a Waypoint that says it takes rich text, otherwise the words and the `---` block as before.
216
+ - Do not edit the copy of this Tool in domma-cms: it is synced from here (`make sync-free-tier`).
@@ -64,6 +64,8 @@
64
64
  .fb-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .5rem 1rem; margin: 0; }
65
65
  .fb-facts dt { color: var(--dm-text-secondary); font-size: var(--dm-font-size-xs); }
66
66
  .fb-facts dd { margin: 0; overflow-wrap: anywhere; }
67
+ /* A rich text description (showRichText) lays itself out: its paragraphs and lists, not the text's line breaks. */
68
+ .fb-text.rich-text { white-space: normal; }
67
69
  .fb-text { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--dm-background); border: 1px solid var(--dm-border);
68
70
  border-radius: var(--dm-radius-md); padding: .7rem .8rem; }
69
71
  .fb-reply { border-color: var(--dm-primary); }
@@ -10,6 +10,7 @@
10
10
 
11
11
  import {FILES, api, copyText, esc, guardPanel, offerDraft, openPanel, panelSet, refreshBadge, rowKeys, showFiles, stamp, store, when} from '../lib/kit.js';
12
12
  import {DRAFT_KEYS, draftQuestion, draftText, draftValues, reportForm, reportPrint} from '../lib/drafts.js';
13
+ import {richTextToPlain, showRichText} from '/admin/js/lib/rich-field.js';
13
14
 
14
15
  const ROW = `
15
16
  <div class="fb-row" data-id="{{id}}" tabindex="0" role="button" aria-haspopup="menu">
@@ -64,7 +65,7 @@ export async function mount(root, ctx) {
64
65
  .filter(r => f.match(r.status))
65
66
  .filter(r => !site.value || r.site === site.value)
66
67
  .filter(r => !type.value || r.type === type.value)
67
- .filter(r => !q || [r.title, r.description, r.userName, r.siteName, r.issueKey].join(' ').toLowerCase().includes(q))
68
+ .filter(r => !q || [r.title, richTextToPlain(r.description).replace(/\u00a0/g, ' '), r.userName, r.siteName, r.issueKey].join(' ').toLowerCase().includes(q))
68
69
  .map(r => ({
69
70
  id: r.id,
70
71
  title: r.title,
@@ -250,7 +251,7 @@ export async function mount(root, ctx) {
250
251
  html: `<div class="fb-detail">
251
252
  <dl class="fb-facts">${facts.map(([a, b]) => `<div><dt>${esc(a)}</dt><dd>${esc(b)}</dd></div>`).join('')}</dl>
252
253
  <h4>What they sent</h4>
253
- <div class="fb-text">${esc(r.description)}</div>
254
+ <div class="fb-text" data-description></div>
254
255
  ${(r.attachments || []).length ? `<h4>Files <span data-help="What the sender attached. Click one to open it in a new tab. A file still on its way follows its report within the site's next sync."></span></h4><div class="fb-files-host" data-files></div>` : ''}
255
256
 
256
257
  <div class="fb-form">
@@ -342,6 +343,8 @@ export async function mount(root, ctx) {
342
343
  // A picked-up draft keeps its own `was`: the question next time still measures from when the edits began.
343
344
  was: offer.state === 'keep' ? offer.draft.was : reportPrint(r)
344
345
  });
346
+ // Formatted when the report is rich text (through the admin's sanitiser); the text it is otherwise.
347
+ showRichText(panel.panel.querySelector('[data-description]'), r.description || '');
345
348
  panels.set('detail', {
346
349
  key: r.id,
347
350
  close: (how) => guard.close(how),
@@ -15,6 +15,7 @@ import {
15
15
  uploadFile, when
16
16
  } from '../lib/kit.js';
17
17
  import {DRAFT_KEYS, draftValues, newDraftQuestion} from '../lib/drafts.js';
18
+ import {richDescription, showRichText} from '/admin/js/lib/rich-field.js';
18
19
 
19
20
  const ROW = `
20
21
  <div class="fb-row" data-id="{{key}}" tabindex="0" role="button" aria-haspopup="menu">
@@ -193,7 +194,7 @@ export async function mount(root, ctx) {
193
194
  <label class="form-label" for="fb-title">Title</label>
194
195
  <input id="fb-title" class="form-input" maxlength="140" data-model="title.value" placeholder="One line: what happened, or what you would like">
195
196
  <label class="form-label" for="fb-desc">Description <span data-help="For a bug: what you did, what you expected, and what happened instead. For a request: what you are trying to get done - the why helps more than the how."></span></label>
196
- <textarea id="fb-desc" class="form-textarea" rows="8" maxlength="8000" data-model="description.value"></textarea>
197
+ <textarea id="fb-desc" class="form-textarea" rows="8" data-model="description.value"></textarea>
197
198
  <div data-bind-hidden="!isBug.value">
198
199
  <label class="form-label" for="fb-sev">How bad is it?</label>
199
200
  <select id="fb-sev" class="form-select" data-model="severity.value">
@@ -294,7 +295,11 @@ export async function mount(root, ctx) {
294
295
  input.addEventListener('change', onChange);
295
296
  offs.push(() => input.removeEventListener('change', onChange));
296
297
  // A screenshot pasted into the description is the quickest way there is.
297
- const desc = p.panel.querySelector('#fb-desc');
298
+ // The description is the rich text editor (the textarea stays the bound field), so the paste is heard on
299
+ // the editor's own frame - in the capture phase, before the editor takes the picture for itself.
300
+ const rich = richDescription(p.panel.querySelector('#fb-desc'), {minHeight: 160});
301
+ offs.push(() => rich.destroy());
302
+ const desc = p.panel.querySelector('.rich-description-editor') || p.panel.querySelector('#fb-desc');
298
303
  const onPaste = (e) => {
299
304
  const list = [...(e.clipboardData?.files || [])];
300
305
  if (!list.length) return;
@@ -302,8 +307,8 @@ export async function mount(root, ctx) {
302
307
  add(list.map(file => (file.name && file.name !== 'image.png' ? file
303
308
  : new File([file], `screenshot-${new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-')}.png`, {type: file.type}))));
304
309
  };
305
- desc?.addEventListener('paste', onPaste);
306
- offs.push(() => desc?.removeEventListener('paste', onPaste));
310
+ desc?.addEventListener('paste', onPaste, true);
311
+ offs.push(() => desc?.removeEventListener('paste', onPaste, true));
307
312
  p.panel.querySelector('#fb-title')?.focus();
308
313
  return p;
309
314
  }
@@ -335,7 +340,7 @@ export async function mount(root, ctx) {
335
340
  html: `<div class="fb-detail">
336
341
  <dl class="fb-facts">${lines.map(([a, b]) => `<div><dt>${esc(a)}</dt><dd>${esc(b)}</dd></div>`).join('')}</dl>
337
342
  <h4>What was sent</h4>
338
- <div class="fb-text">${esc(r.description)}</div>
343
+ <div class="fb-text" data-description></div>
339
344
  ${(r.attachments || []).length ? '<h4>Files</h4><div class="fb-files-host" data-files></div>' : ''}
340
345
  ${r.reply ? `<h4><span data-icon="corner-up-left" data-icon-size="14"></span> ${esc(COPY.replied)} <small>${esc(stamp(r.replyAt))}</small></h4><div class="fb-text fb-reply">${esc(r.reply)}</div>` : `<p class="fb-note">${esc(COPY.noReply)}</p>`}
341
346
  </div>`
@@ -346,6 +351,8 @@ export async function mount(root, ctx) {
346
351
  return;
347
352
  }
348
353
  panels.set('detail', {key: k, close: (how) => p.so.close(how)});
354
+ // Formatted when the report is rich text (through the admin's sanitiser); the text it is otherwise.
355
+ showRichText(p.panel.querySelector('[data-description]'), r.descriptionHtml || r.description || '');
349
356
  const host = p.panel.querySelector('[data-files]');
350
357
  if (host) {
351
358
  host.innerHTML = FILES;
@@ -17,7 +17,7 @@ Feedback lets you tell Domma what is broken, missing or good, straight from your
17
17
  1. Open [Feedback](#/plugins/feedback) from the admin sidebar.
18
18
  2. Click **Send feedback**.
19
19
  3. Under **What is it?** pick one: Something is broken, An idea or request, A question, Something we got right, or Something else.
20
- 4. Type a **Title** (one line) and a **Description**.
20
+ 4. Type a **Title** (one line) and a **Description**. The description is a rich text box: use the toolbar for bold, italic, underline, lists and links.
21
21
  5. For something broken, choose **How bad is it?**: Minor - a nuisance, Major - gets in the way, or Blocker - cannot carry on.
22
22
  6. Optional: fill in **Where** - the screen or page it is about, for example "Pages" or `/contact`.
23
23
  7. Optional: click **Attach a file**, or paste a screenshot straight into the description. Up to 3 files of 2 MB each: PNG, JPEG, GIF or WebP images, a PDF or a text file.
@@ -90,6 +90,7 @@ On the Domma server itself (the Manager), the same screen is the **Inbox** of ev
90
90
 
91
91
  - Only sites started by a Domma server can send. A standalone install cannot.
92
92
  - Up to 3 files per report, 2 MB each, and only images (PNG, JPEG, GIF, WebP), PDFs and text files.
93
- - Titles are limited to 140 characters and descriptions to 8,000.
93
+ - Titles are limited to 140 characters and descriptions to 8,000 (16,000 with formatting counted).
94
+ - A report keeps its formatting in the inbox, in your own list and in a Waypoint issue made from it. Notices and copied text are plain. If the other end runs an older version of Feedback it shows the same words without the formatting.
94
95
  - The Domma server accepts up to 10 reports from one site in 10 minutes. Any more show as **Waiting to send** and go later.
95
96
  - You cannot edit or withdraw a report once sent. Send a follow-up instead.
@@ -233,7 +233,7 @@ export function mergeReports(outboxItems, remote, seen = {}) {
233
233
  if (i.state === 'sent' && remote) continue; // the manager dropped it; nothing to show but noise
234
234
  const p = i.payload || {};
235
235
  out.push({
236
- id: '', ref: i.ref, type: p.type, title: p.title, description: p.description, where: p.where || '', severity: p.severity || '',
236
+ id: '', ref: i.ref, type: p.type, title: p.title, description: p.description, descriptionHtml: p.descriptionHtml || '', where: p.where || '', severity: p.severity || '',
237
237
  attachments: (p.attachments || []).map(a => ({...a, stored: false})),
238
238
  userName: p.user?.name || '', status: i.state === 'refused' ? 'refused' : 'waiting',
239
239
  statusLabel: i.state === 'refused' ? 'Not accepted' : 'Waiting to send',
@@ -7,6 +7,7 @@
7
7
  *
8
8
  * @module feedback/lib/shape
9
9
  */
10
+ import {cleanRichText, isRichText, renderRichText, richTextSummary, richTextToPlain} from '../../../server/services/richText.js';
10
11
 
11
12
  /** What a report can be. The icon is a Domma icon name (checked against the registry). */
12
13
  export const TYPES = [
@@ -42,6 +43,13 @@ export const typeLabel = (key) => TYPES.find(t => t.key === key)?.short ?? key;
42
43
 
43
44
  /** Longest a field may be. The route's bodyLimit (32 KB) is the outer wall. */
44
45
  export const LIMITS = {title: 140, description: 8000, where: 300, reply: 8000, notes: 8000};
46
+ /** The longest a rich text description may be, markup included (a plain one keeps LIMITS.description). */
47
+ export const RICH_DESCRIPTION_MAX = 16000;
48
+ /**
49
+ * The most a report's JSON may weigh on its way to the manager. The manager refuses a body over 32 KB, and an
50
+ * older manager cannot be asked to take more, so a report too heavy to carry its formatting goes as plain text.
51
+ */
52
+ export const PAYLOAD_MAX_BYTES = 28 * 1024;
45
53
 
46
54
  // Control characters go (all but tab and newline): each is 6 bytes once JSON-escaped, so 8000 of them
47
55
  // would pass here and then be refused by the manager's 32 KB body limit, forever.
@@ -107,6 +115,45 @@ export function cleanAttachments(list) {
107
115
  /** The sender-safe view of a stored attachment: what it is and whether the manager has the bytes yet. */
108
116
  export const attachmentView = (a) => ({id: a.id, name: a.name, type: a.type, size: a.size, stored: Boolean(a.stored)});
109
117
 
118
+ /** One line of a report's description, for a notice or a list row: always plain text. */
119
+ export const descriptionSummary = (stored, max = 300) => richTextSummary(stored, max);
120
+
121
+ /**
122
+ * A report's description as it is STORED: one string, rich text (from the editor - cleaned to the rich text
123
+ * allow-list) or plain text (typed before the editor, or sent by an older site - kept as typed).
124
+ *
125
+ * It arrives two ways. From the admin's form, `description` is the editor's value. Between sites (wireDescription)
126
+ * `description` is always plain text and the formatting rides in `descriptionHtml`, which wins when it is rich.
127
+ *
128
+ * @param {{description?: *, descriptionHtml?: *}} body
129
+ * @returns {string}
130
+ */
131
+ export function cleanDescription(body = {}) {
132
+ // Control characters go, as for plain text (each is 6 bytes once JSON-escaped); the cleaner keeps tab and newline.
133
+ const rich = (html) => cleanRichText(html.replace(/\r\n?/g, '\n').replace(/[\u0000-\u0008\u000B-\u001F\u007F]/g, ''), {max: RICH_DESCRIPTION_MAX});
134
+ if (typeof body.descriptionHtml === 'string' && isRichText(body.descriptionHtml)) {
135
+ const formatted = rich(body.descriptionHtml);
136
+ if (formatted) return formatted; // formatting that says nothing: the plain words stand
137
+ }
138
+ const source = typeof body.description === 'string' || typeof body.description === 'number' ? String(body.description) : '';
139
+ return isRichText(source) ? rich(source) : text(source, LIMITS.description);
140
+ }
141
+
142
+ /**
143
+ * A stored description as it TRAVELS between a site and the manager, either way: `description` is plain text, so a
144
+ * site or a manager running a version from before rich text shows words, never tags; `descriptionHtml` carries the
145
+ * formatting (cleaned again) for a version that knows it, and is '' for a plain description.
146
+ *
147
+ * @param {*} stored
148
+ * @returns {{description: string, descriptionHtml: string}}
149
+ */
150
+ export function wireDescription(stored) {
151
+ const value = typeof stored === 'string' ? stored : '';
152
+ if (!isRichText(value)) return {description: value, descriptionHtml: ''};
153
+ // A non-breaking space the editor wrote beside bold text is a space in the plain words.
154
+ return {description: richTextToPlain(value).replace(/\u00a0/g, ' ').slice(0, LIMITS.description), descriptionHtml: renderRichText(value)};
155
+ }
156
+
110
157
  /**
111
158
  * What a site admin typed, cleaned. Never carries who sent it - that comes
112
159
  * from the signed-in user on the server, not from the form.
@@ -117,9 +164,9 @@ export const attachmentView = (a) => ({id: a.id, name: a.name, type: a.type, siz
117
164
  export function cleanSubmission(body = {}) {
118
165
  const type = TYPE_KEYS.includes(body.type) ? body.type : 'other';
119
166
  const title = text(body.title, LIMITS.title);
120
- const description = text(body.description, LIMITS.description);
167
+ const description = cleanDescription(body);
121
168
  if (!title) return {error: 'Give it a short title.'};
122
- if (!description) return {error: 'Say a little more in the description.'};
169
+ if (!richTextToPlain(description)) return {error: 'Say a little more in the description.'};
123
170
  const severity = type === 'bug' && SEVERITY_KEYS.includes(body.severity) ? body.severity : '';
124
171
  // Descriptions of files, not the files: those follow one per request once the report is in.
125
172
  return {report: {type, title, description, where: text(body.where, LIMITS.where), severity, attachments: cleanAttachments(body.attachments)}};
@@ -134,13 +181,19 @@ export function cleanSubmission(body = {}) {
134
181
  * @returns {object}
135
182
  */
136
183
  export function buildPayload({report, user = {}, cmsVersion = '', site = '', ref}) {
137
- return {
184
+ const payload = {
138
185
  ref: text(ref, 64),
139
186
  ...report,
187
+ // Plain text for every manager, the formatting beside it for one that knows rich text (wireDescription).
188
+ ...wireDescription(report?.description),
140
189
  cmsVersion: text(cmsVersion, 20),
141
190
  site: text(site, 64),
142
191
  user: {id: text(user.id, 64), name: text(user.name, 120), email: text(user.email, 200)}
143
192
  };
193
+ if (!payload.descriptionHtml) delete payload.descriptionHtml;
194
+ // Too heavy with both (long text in a script that takes three bytes a letter): the words go, the formatting stays behind.
195
+ else if (new TextEncoder().encode(JSON.stringify(payload)).length > PAYLOAD_MAX_BYTES) delete payload.descriptionHtml;
196
+ return payload;
144
197
  }
145
198
 
146
199
  /**
@@ -193,7 +246,8 @@ export function senderView(entry) {
193
246
  ref: d.ref || '',
194
247
  type: d.type,
195
248
  title: d.title,
196
- description: d.description,
249
+ // Plain text for every site; `descriptionHtml` is the formatting for a site that knows rich text.
250
+ ...wireDescription(d.description),
197
251
  where: d.where || '',
198
252
  severity: d.severity || '',
199
253
  attachments: (d.attachments || []).map(attachmentView),
@@ -303,14 +357,21 @@ export function cleanSettings(raw, current = {}, side = 'sender') {
303
357
  * they came from.
304
358
  *
305
359
  * @param {object} d - report data
360
+ * @param {{rich?: boolean}} [options] - the Waypoint on this server stores rich text descriptions
306
361
  * @returns {string}
307
362
  */
308
- export function issueDescription(d = {}) {
309
- const lines = [d.description || '', '', '---', `From ${d.userName || 'an admin'} on ${d.site || 'a site'}`];
310
- if (d.cmsVersion) lines.push(`Domma CMS ${d.cmsVersion}`);
311
- if (d.where) lines.push(`Where: ${d.where}`);
312
- if (d.severity) lines.push(`Severity: ${d.severity}`);
363
+ export function issueDescription(d = {}, {rich = false} = {}) {
364
+ const facts = [`From ${d.userName || 'an admin'} on ${d.site || 'a site'}`];
365
+ if (d.cmsVersion) facts.push(`Domma CMS ${d.cmsVersion}`);
366
+ if (d.where) facts.push(`Where: ${d.where}`);
367
+ if (d.severity) facts.push(`Severity: ${d.severity}`);
313
368
  const files = (d.attachments || []).map(a => a.name);
314
- if (files.length) lines.push(`Attachments (in the Feedback inbox): ${files.join(', ')}`);
315
- return lines.join('\n');
369
+ if (files.length) facts.push(`Attachments (in the Feedback inbox): ${files.join(', ')}`);
370
+ // A rich report for a Waypoint that takes rich text: its formatting, then the facts as one paragraph.
371
+ if (rich && isRichText(d.description)) {
372
+ const esc = (s) => String(s).replace(/[&<>]/g, c => ({'&': '&amp;', '<': '&lt;', '>': '&gt;'}[c]));
373
+ return `${renderRichText(d.description)}<p>${facts.map(esc).join('<br>')}</p>`;
374
+ }
375
+ // Otherwise text, as it always was (a rich report's words, for a Waypoint from before rich text).
376
+ return [richTextToPlain(d.description || ''), '', '---', ...facts].join('\n');
316
377
  }
@@ -35,7 +35,7 @@ import path from 'node:path';
35
35
  import {fileURLToPath} from 'node:url';
36
36
  import defaults from './config.js';
37
37
  import {
38
- ATTACHMENTS, SEVERITIES, STATUSES, TYPES, buildPayload, cleanAttachment, cleanSubmission, cleanUpdate, cleanSettings, createThrottle, issueDescription, senderView
38
+ ATTACHMENTS, SEVERITIES, STATUSES, TYPES, buildPayload, cleanAttachment, cleanSubmission, cleanUpdate, cleanSettings, createThrottle, descriptionSummary, issueDescription, senderView
39
39
  } from './lib/shape.js';
40
40
  import {createStore, readUpload, sendFile} from './lib/attachments.js';
41
41
  import {createOutbox, flush, managerApi, managerOf, mergeReports, newRef} from './lib/sender.js';
@@ -299,7 +299,7 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
299
299
  if (r.error) return reply.code(400).send({error: r.error});
300
300
  if (r.created && notifyOk) {
301
301
  const d = r.entry.data;
302
- hooks.notify({title: `Feedback from ${names()[slug] || slug}: ${d.title}`, body: d.description.slice(0, 300),
302
+ hooks.notify({title: `Feedback from ${names()[slug] || slug}: ${d.title}`, body: descriptionSummary(d.description, 300),
303
303
  severity: d.severity === 'blocker' ? 'warning' : 'info', source: 'new-report',
304
304
  link: `#/plugins/feedback/${r.entry.id}`, dedupeKey: `feedback:${r.entry.id}`});
305
305
  }
@@ -479,7 +479,7 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
479
479
  if (!projectId) return reply.code(400).send({error: 'Choose a project.'});
480
480
  let issue;
481
481
  try {
482
- issue = await wp.createIssue({projectId: String(projectId), title: e.data.title, description: issueDescription({...e.data, site: names()[e.data.site] || e.data.site}),
482
+ issue = await wp.createIssue({projectId: String(projectId), title: e.data.title, description: issueDescription({...e.data, site: names()[e.data.site] || e.data.site}, {rich: wp.richDescriptions === true}),
483
483
  type: String(type || ''), priority: String(priority || ''), reporterName: e.data.userName,
484
484
  source: {plugin: 'feedback', id: e.id, site: e.data.site, url: `#/plugins/feedback/${e.id}`}});
485
485
  } catch (err) {
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "feedback",
3
3
  "displayName": "Feedback",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
+ "minCmsVersion": "1.67.2",
5
6
  "tier": "free",
6
7
  "description": "Tell Domma what is broken, missing or good - straight from your admin - and see what became of it: seen, planned, in progress, done, with Domma's reply.",
7
8
  "author": "Domma CMS",
@@ -40,7 +41,7 @@
40
41
  ],
41
42
  "views": {
42
43
  "plugin-feedback": {
43
- "entry": "feedback/admin/views/feedback.js?v=1.2.0",
44
+ "entry": "feedback/admin/views/feedback.js?v=1.3.0",
44
45
  "exportName": "feedbackView"
45
46
  }
46
47
  }
@@ -16,7 +16,7 @@ import {getRoleHierarchy, getRoleLevel, load as loadRoles} from '../../../server
16
16
 
17
17
  const PLUGINS = path.resolve('config/plugins.json');
18
18
  const COLL = path.resolve('content/collections/feedback-reports');
19
- const TOKENS = {'tok-acme': 'acme', 'tok-beta': 'beta', 'tok-flood': 'flood'};
19
+ const TOKENS = {'tok-acme': 'acme', 'tok-beta': 'beta', 'tok-flood': 'flood', 'tok-rich': 'rich'};
20
20
  let savedPlugins;
21
21
  let manager;
22
22
  let dataDir;
@@ -431,3 +431,49 @@ test('a file attached while the manager restarts waits with its report, then bot
431
431
  assert.equal(file.body, 'line one\nline two');
432
432
  await acme.close();
433
433
  });
434
+
435
+ test('a rich description: stored once on the manager, plain text on the wire, formatted for a Waypoint that takes it', async () => {
436
+ const P = '/api/plugins/feedback';
437
+ const RICH = '<p>Saving <strong>loses</strong> text</p><script>alert(1)</script><ul><li>Open</li></ul>';
438
+ const CLEAN = '<p>Saving <strong>loses</strong> text</p><ul><li>Open</li></ul>';
439
+ const rich = await site({token: 'tok-rich', user: {id: 'u9', name: 'Bea', email: 'bea@beta.test'}});
440
+ const before = notices.length;
441
+ let r = await call(rich, 'POST', '/send', {type: 'bug', title: 'Rich report', description: RICH, severity: 'minor'});
442
+ assert.equal(r.status, 201, JSON.stringify(r.body));
443
+ assert.equal(r.body.state, 'sent', JSON.stringify(r.body));
444
+ const report = (await call(manager, 'GET', `${P}/reports`)).body.reports.find(x => x.title === 'Rich report');
445
+ assert.equal(report.description, CLEAN, 'the inbox holds the formatting, cleaned, in the one field');
446
+ assert.equal(report.descriptionHtml, undefined);
447
+ const notice = notices.slice(before).find(n => n.source === 'new-report');
448
+ assert.equal(notice.body, 'Saving loses text - Open', 'the notice is plain text');
449
+
450
+ // What the site reads back: words in `description` (an older site draws that), formatting beside it.
451
+ const mine = (await call(rich, 'GET', '/sent')).body.reports.find(x => x.title === 'Rich report');
452
+ assert.equal(mine.description, 'Saving loses text\n\n- Open');
453
+ assert.equal(mine.descriptionHtml, CLEAN);
454
+ const raw = (await call(manager, 'GET', `${P}/fleet/mine`, null, {authorization: 'Bearer tok-rich'})).body.reports.find(x => x.title === 'Rich report');
455
+ assert.ok(!/[<>]/.test(raw.description));
456
+
457
+ // An older site's plain report is stored and shown as it always was.
458
+ r = await call(manager, 'POST', `${P}/fleet/submit`, {ref: 'old-site-1', type: 'idea', title: 'Old site', description: 'Plain <b>words</b>\nline two'}, {authorization: 'Bearer tok-rich'});
459
+ assert.equal(r.status, 201, JSON.stringify(r.body));
460
+ const old = (await call(manager, 'GET', `${P}/reports`)).body.reports.find(x => x.title === 'Old site');
461
+ assert.equal(old.description, 'Plain <b>words</b>\nline two');
462
+
463
+ // Waypoint: rich text when it says it takes it, the words when it does not.
464
+ const made = [];
465
+ const bridge = (extra) => ({version: 1, ...extra, listProjects: async () => [{id: 'p1', key: 'CMS', name: 'Domma CMS'}],
466
+ createIssue: async (input) => { made.push(input); return {id: `i${made.length + 20}`, key: `CMS-${made.length + 20}`, link: '#'}; },
467
+ getIssue: async () => null});
468
+ try {
469
+ globalThis.dommaWaypoint = bridge({richDescriptions: true});
470
+ r = await call(manager, 'POST', `${P}/reports/${report.id}/promote`, {projectId: 'p1', type: 'bug', priority: 'high'});
471
+ assert.equal(r.status, 200, JSON.stringify(r.body));
472
+ assert.match(made[0].description, new RegExp(`^${CLEAN.replace(/[/]/g, '\\/')}<p>From Bea on rich<br>(Domma CMS [\\d.]+<br>)?Severity: minor</p>$`));
473
+ globalThis.dommaWaypoint = bridge({});
474
+ r = await call(manager, 'POST', `${P}/reports/${old.id}/promote`, {projectId: 'p1'});
475
+ assert.equal(r.status, 200, JSON.stringify(r.body));
476
+ assert.equal(made[1].description, 'Plain <b>words</b>\nline two\n\n---\nFrom An admin on rich');
477
+ } finally { delete globalThis.dommaWaypoint; }
478
+ await rich.close();
479
+ });