domma-cms 1.46.0 → 1.47.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 (123) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/admin/js/lib/api-tokens-arrange.js +2 -2
  3. package/admin/js/lib/whatsapp-call.js +1 -0
  4. package/admin/js/templates/contacts.html +2 -0
  5. package/admin/js/views/api-tokens.js +9 -4
  6. package/admin/js/views/contacts.js +12 -11
  7. package/admin/js/views/form-editor.js +5 -5
  8. package/admin/js/views/plugins.js +1 -1
  9. package/docs/api-reference.md +22 -0
  10. package/package.json +1 -1
  11. package/plugins/_lib/admin/mail/body-menu.js +1 -1
  12. package/plugins/_lib/admin/mail/cms-host.js +1 -1
  13. package/plugins/_lib/admin/mail/compose-window.js +1 -1
  14. package/plugins/_lib/admin/mail/contacts.js +1 -1
  15. package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
  16. package/plugins/_lib/admin/mail/drag-drop.js +1 -1
  17. package/plugins/_lib/admin/mail/folder-tree.js +1 -1
  18. package/plugins/_lib/admin/mail/font-controls.js +1 -1
  19. package/plugins/_lib/admin/mail/fonts.js +1 -1
  20. package/plugins/_lib/admin/mail/host-context.js +1 -1
  21. package/plugins/_lib/admin/mail/identity.js +1 -1
  22. package/plugins/_lib/admin/mail/image-senders-section.js +1 -1
  23. package/plugins/_lib/admin/mail/keyboard.js +1 -1
  24. package/plugins/_lib/admin/mail/mail.html +1 -1
  25. package/plugins/_lib/admin/mail/message-actions.js +1 -1
  26. package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
  27. package/plugins/_lib/admin/mail/panes.js +1 -1
  28. package/plugins/_lib/admin/mail/reader-kit.js +1 -1
  29. package/plugins/_lib/admin/mail/reader-runtime.js +7 -6
  30. package/plugins/_lib/admin/mail/reader-view.js +1 -1
  31. package/plugins/_lib/admin/mail/resizable.js +1 -1
  32. package/plugins/_lib/admin/mail/restore-spam.js +1 -1
  33. package/plugins/_lib/admin/mail/rules.js +1 -1
  34. package/plugins/_lib/admin/mail/scheduling.js +1 -1
  35. package/plugins/_lib/admin/mail/section-kit.js +1 -1
  36. package/plugins/_lib/admin/mail/security-note.js +1 -1
  37. package/plugins/_lib/admin/mail/settings-section.js +1 -1
  38. package/plugins/_lib/admin/mail/templates.js +1 -1
  39. package/plugins/_lib/admin/mail/threads.js +1 -1
  40. package/plugins/_lib/admin/mail/vacation.js +1 -1
  41. package/plugins/_lib/admin/mail/when-closed.js +1 -1
  42. package/plugins/_lib/admin/ui/dates.js +1 -1
  43. package/plugins/_lib/admin/ui/resizable.js +1 -1
  44. package/plugins/_lib/domma-mail.lock.json +80 -80
  45. package/plugins/_lib/mail/accountFileStore.js +1 -1
  46. package/plugins/_lib/mail/accountRepository.js +1 -1
  47. package/plugins/_lib/mail/accountRoutes.js +1 -1
  48. package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
  49. package/plugins/_lib/mail/bodyTokens.js +1 -1
  50. package/plugins/_lib/mail/compose.js +1 -1
  51. package/plugins/_lib/mail/defaults.js +1 -1
  52. package/plugins/_lib/mail/envelope.js +1 -1
  53. package/plugins/_lib/mail/folderActions.js +1 -1
  54. package/plugins/_lib/mail/folderRuntime.js +1 -1
  55. package/plugins/_lib/mail/folders.js +1 -1
  56. package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
  57. package/plugins/_lib/mail/mbox.js +1 -1
  58. package/plugins/_lib/mail/message-action.js +1 -1
  59. package/plugins/_lib/mail/messageSecurity.js +1 -1
  60. package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
  61. package/plugins/_lib/mail/networkAddresses.js +1 -1
  62. package/plugins/_lib/mail/networkPolicy.js +1 -1
  63. package/plugins/_lib/mail/oauthAccounts.js +1 -1
  64. package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
  65. package/plugins/_lib/mail/oauthRuntime.js +1 -1
  66. package/plugins/_lib/mail/pollSchedule.js +1 -1
  67. package/plugins/_lib/mail/poller.js +1 -1
  68. package/plugins/_lib/mail/pollerRuntime.js +1 -1
  69. package/plugins/_lib/mail/priority.js +1 -1
  70. package/plugins/_lib/mail/publicMailbox.js +1 -1
  71. package/plugins/_lib/mail/readRuntime.js +1 -1
  72. package/plugins/_lib/mail/render.js +1 -1
  73. package/plugins/_lib/mail/ruleRunner.js +1 -1
  74. package/plugins/_lib/mail/schedulerRuntime.js +1 -1
  75. package/plugins/_lib/mail/secretProvider.js +1 -1
  76. package/plugins/_lib/mail/secretbox.js +1 -1
  77. package/plugins/_lib/mail/senderAuth.js +1 -1
  78. package/plugins/_lib/mail/sieve.js +1 -1
  79. package/plugins/_lib/mail/smtpService.js +1 -1
  80. package/plugins/_lib/mail/snoozeRuntime.js +1 -1
  81. package/plugins/_lib/mail/store.js +1 -1
  82. package/plugins/_lib/mail/subscriptions.js +1 -1
  83. package/plugins/_lib/mail/syncPlan.js +1 -1
  84. package/plugins/_lib/mail/syncRuntime.js +1 -1
  85. package/plugins/_lib/mail/syncSelection.js +1 -1
  86. package/plugins/_lib/mail/unreadBadge.js +1 -1
  87. package/plugins/_lib/mail/unsubscribe.js +1 -1
  88. package/plugins/_lib/mail/vacationRuntime.js +1 -1
  89. package/plugins/_lib/mail/write.js +1 -1
  90. package/plugins/blog/CHANGELOG.md +5 -0
  91. package/plugins/blog/plugin.js +3 -0
  92. package/plugins/blog/plugin.json +2 -2
  93. package/plugins/free-tier.lock.json +37 -16
  94. package/plugins/security/CHANGELOG.md +6 -0
  95. package/plugins/security/admin/lib/health.js +4 -1
  96. package/plugins/security/plugin.json +2 -2
  97. package/plugins/security/server/facts.js +2 -1
  98. package/plugins/security/tests/security.test.js +5 -0
  99. package/plugins/shopping-cart/CHANGELOG.md +7 -0
  100. package/plugins/shopping-cart/admin/views/orders.js +3 -4
  101. package/plugins/shopping-cart/lib/summary.js +1 -1
  102. package/plugins/shopping-cart/plugin.json +2 -2
  103. package/plugins/shopping-cart/public/lib/orders.js +16 -0
  104. package/plugins/shopping-cart/public/shop.css +1 -1
  105. package/plugins/shopping-cart/tests/pure.test.js +16 -0
  106. package/plugins/whatsapp-calling/CLAUDE.md +12 -0
  107. package/plugins/whatsapp-calling/admin/css/index.css +22 -0
  108. package/plugins/whatsapp-calling/admin/templates/index.html +56 -0
  109. package/plugins/whatsapp-calling/admin/views/connection-help.js +55 -0
  110. package/plugins/whatsapp-calling/admin/views/index.js +275 -0
  111. package/plugins/whatsapp-calling/config.js +7 -0
  112. package/plugins/whatsapp-calling/docs/guide.md +70 -0
  113. package/plugins/whatsapp-calling/lib/calls.js +156 -0
  114. package/plugins/whatsapp-calling/lib/meta.js +55 -0
  115. package/plugins/whatsapp-calling/lib/recipients.js +26 -0
  116. package/plugins/whatsapp-calling/plugin.js +123 -0
  117. package/plugins/whatsapp-calling/plugin.json +86 -0
  118. package/plugins/whatsapp-calling/tests/calling.test.js +254 -0
  119. package/server/routes/api/api-tokens.js +2 -2
  120. package/server/routes/api/collections.js +42 -17
  121. package/server/routes/api/endpoints-public.js +1 -2
  122. package/server/services/apiTokens.js +59 -4
  123. package/server/services/presetCollections.js +1 -0
@@ -67,12 +67,13 @@ function hashToken(plaintext) {
67
67
  * @returns {object}
68
68
  */
69
69
  function sanitise(entry) {
70
- const {name, project, tokenHint, scopes, enabled, expiresAt, lastUsedAt, createdBy} = entry.data || {};
70
+ const {name, project, tokenHint, scopes, enabled, draftsOnly, expiresAt, lastUsedAt, createdBy} = entry.data || {};
71
71
  return {
72
72
  id: entry.id,
73
73
  name, project, tokenHint,
74
74
  scopes: Array.isArray(scopes) ? scopes : [],
75
75
  enabled: enabled !== false,
76
+ draftsOnly: draftsOnly === true,
76
77
  expiresAt: expiresAt || null,
77
78
  lastUsedAt: lastUsedAt || null,
78
79
  createdBy: createdBy || null,
@@ -141,6 +142,54 @@ export function contentScopeAllows(scopes, resource) {
141
142
  return scopes.some(s => s.content === resource);
142
143
  }
143
144
 
145
+ /** The status a drafts-only token's writes are held at. */
146
+ export const DRAFT_STATUS = 'draft';
147
+
148
+ /**
149
+ * The field that says whether an entry is a draft: a `status` field whose
150
+ * options include `draft` (the Blog's posts, any collection made the same
151
+ * way). Null when the collection has no such field - a drafts-only token
152
+ * may not write there at all, since nothing would hold its rows back.
153
+ *
154
+ * @param {{fields?: object[]}} schema
155
+ * @returns {string|null}
156
+ */
157
+ export function draftField(schema) {
158
+ const field = (schema?.fields || []).find(f => f?.name === 'status');
159
+ if (!field) return null;
160
+ const options = Array.isArray(field.options) ? field.options : [];
161
+ const values = options.map(o => (o && typeof o === 'object') ? o.value : o);
162
+ return values.includes(DRAFT_STATUS) ? field.name : null;
163
+ }
164
+
165
+ /**
166
+ * What a drafts-only token may do to a collection, decided before the write.
167
+ * Create: the row is held as a draft whatever the caller sent. Update: only a
168
+ * row that is a draft now, and it stays one. Delete: only a draft. Reads are
169
+ * not this flag's business (api.read and the scopes decide them).
170
+ *
171
+ * Pure - the route passes the stored row for update/delete.
172
+ *
173
+ * @param {{draftsOnly?: boolean}|null} token
174
+ * @param {{fields?: object[]}} schema
175
+ * @param {'create'|'read'|'update'|'delete'} operation
176
+ * @param {{data?: object}|null} [existing]
177
+ * @returns {{ok: true, field: string|null} | {ok: false, status: 403|404, error: string}}
178
+ */
179
+ export function draftsOnlyDecision(token, schema, operation, existing = null) {
180
+ if (!token?.draftsOnly || operation === 'read') return {ok: true, field: null};
181
+ const field = draftField(schema);
182
+ if (!field) {
183
+ return {ok: false, status: 403, error: 'This token may only write drafts, and this collection has no draft status'};
184
+ }
185
+ if (operation === 'create') return {ok: true, field};
186
+ if (!existing) return {ok: false, status: 404, error: 'Entry not found'};
187
+ if (existing.data?.[field] !== DRAFT_STATUS) {
188
+ return {ok: false, status: 403, error: 'This token may only change drafts, and this entry is not one'};
189
+ }
190
+ return {ok: true, field};
191
+ }
192
+
144
193
  const BEARER_RE = /^Bearer (dcms_[a-f0-9]{64})$/;
145
194
 
146
195
  /**
@@ -172,17 +221,18 @@ export async function authenticateApiToken(request, {project, allows, projectErr
172
221
  /**
173
222
  * Create a new token. The plaintext is returned ONCE here and never again.
174
223
  *
175
- * @param {{name: string, project: string, scopes?: object[], expiresAt?: string|null, createdBy?: string|null}} input
224
+ * @param {{name: string, project: string, scopes?: object[], expiresAt?: string|null, draftsOnly?: boolean, createdBy?: string|null}} input
176
225
  * @returns {Promise<{entry: object, plaintext: string}>} Sanitised entry + plaintext
177
226
  * @throws {Error} On validation failure
178
227
  */
179
- export async function createToken({name, project, scopes = [], expiresAt = null, createdBy = null}) {
228
+ export async function createToken({name, project, scopes = [], expiresAt = null, draftsOnly = false, createdBy = null}) {
180
229
  if (!name || typeof name !== 'string' || !name.trim()) throw new Error('Token name is required');
181
230
  if (!project || typeof project !== 'string') throw new Error('Token project is required');
182
231
  if (!await getProject(project)) throw new Error(`Unknown project "${project}"`);
183
232
  const scopeError = validateScopes(scopes);
184
233
  if (scopeError) throw new Error(scopeError);
185
234
  if (expiresAt != null && Number.isNaN(Date.parse(expiresAt))) throw new Error('expiresAt must be a valid date');
235
+ if (draftsOnly != null && typeof draftsOnly !== 'boolean') throw new Error('draftsOnly must be true or false');
186
236
 
187
237
  const plaintext = 'dcms_' + crypto.randomBytes(32).toString('hex');
188
238
  const data = {
@@ -192,6 +242,7 @@ export async function createToken({name, project, scopes = [], expiresAt = null,
192
242
  tokenHint: plaintext.slice(-4),
193
243
  scopes: scopes || [],
194
244
  enabled: true,
245
+ draftsOnly: draftsOnly === true,
195
246
  expiresAt: expiresAt || null,
196
247
  lastUsedAt: null,
197
248
  createdBy
@@ -281,7 +332,7 @@ export async function getTokenSanitised(id) {
281
332
  * for the token's lifetime - revoke and re-issue to rebind.
282
333
  *
283
334
  * @param {string} id
284
- * @param {{name?: string, enabled?: boolean, scopes?: object[], expiresAt?: string|null}} patch
335
+ * @param {{name?: string, enabled?: boolean, draftsOnly?: boolean, scopes?: object[], expiresAt?: string|null}} patch
285
336
  * @returns {Promise<object|null>} Sanitised entry, or null when not found
286
337
  * @throws {Error} On validation failure
287
338
  */
@@ -296,6 +347,10 @@ export async function updateToken(id, patch = {}) {
296
347
  data.name = patch.name.trim();
297
348
  }
298
349
  if (patch.enabled != null) data.enabled = patch.enabled !== false;
350
+ if (patch.draftsOnly != null) {
351
+ if (typeof patch.draftsOnly !== 'boolean') throw new Error('draftsOnly must be true or false');
352
+ data.draftsOnly = patch.draftsOnly;
353
+ }
299
354
  if (patch.scopes != null) {
300
355
  const scopeError = validateScopes(patch.scopes);
301
356
  if (scopeError) throw new Error(scopeError);
@@ -87,6 +87,7 @@ const PRESETS = [
87
87
  {name: 'tokenHint', label: 'Hint', type: 'text'},
88
88
  {name: 'scopes', label: 'Scopes', type: 'array', items: 'object', default: []},
89
89
  {name: 'enabled', label: 'Enabled', type: 'boolean', default: true},
90
+ {name: 'draftsOnly', label: 'Drafts Only', type: 'boolean', default: false},
90
91
  {name: 'expiresAt', label: 'Expires At', type: 'datetime'},
91
92
  {name: 'lastUsedAt', label: 'Last Used', type: 'datetime'},
92
93
  {name: 'createdBy', label: 'Created By', type: 'text'}