@cosmicdrift/kumiko-bundled-features 0.362.0 → 0.364.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 (468) hide show
  1. package/dist/admin-shell/feature.d.ts +3 -0
  2. package/dist/admin-shell/feature.js +6 -1
  3. package/dist/agent-tools/agent-manifest.js +2 -1
  4. package/dist/agent-tools/filter-ops.d.ts +1 -1
  5. package/dist/agent-tools/filter-ops.js +1 -3
  6. package/dist/agent-tools/tool-dispatch.js +2 -1
  7. package/dist/audit/handlers/list.query.js +9 -5
  8. package/dist/auth-email-password/bootstrap.d.ts +8 -5
  9. package/dist/auth-email-password/bootstrap.js +12 -4
  10. package/dist/auth-email-password/email-rate-limits.d.ts +4 -0
  11. package/dist/auth-email-password/email-rate-limits.js +13 -0
  12. package/dist/auth-email-password/email-templates.d.ts +4 -26
  13. package/dist/auth-email-password/email-templates.js +9 -101
  14. package/dist/auth-email-password/feature.js +24 -6
  15. package/dist/auth-email-password/handlers/change-password.write.d.ts +1 -1
  16. package/dist/auth-email-password/handlers/change-password.write.js +6 -2
  17. package/dist/auth-email-password/handlers/confirm-account-unlock.write.d.ts +1 -1
  18. package/dist/auth-email-password/handlers/invite-accept-with-login.write.d.ts +1 -1
  19. package/dist/auth-email-password/handlers/invite-accept.write.d.ts +1 -1
  20. package/dist/auth-email-password/handlers/invite-create.write.d.ts +2 -2
  21. package/dist/auth-email-password/handlers/invite-create.write.js +4 -4
  22. package/dist/auth-email-password/handlers/invite-signup-complete.write.d.ts +1 -1
  23. package/dist/auth-email-password/handlers/login.write.d.ts +1 -1
  24. package/dist/auth-email-password/handlers/logout.write.d.ts +1 -1
  25. package/dist/auth-email-password/handlers/logout.write.js +6 -2
  26. package/dist/auth-email-password/handlers/request-account-unlock.write.d.ts +1 -1
  27. package/dist/auth-email-password/handlers/request-account-unlock.write.js +2 -4
  28. package/dist/auth-email-password/handlers/request-email-verification.write.d.ts +1 -1
  29. package/dist/auth-email-password/handlers/request-email-verification.write.js +2 -4
  30. package/dist/auth-email-password/handlers/request-password-reset.write.d.ts +1 -1
  31. package/dist/auth-email-password/handlers/request-password-reset.write.js +2 -4
  32. package/dist/auth-email-password/handlers/reset-password.write.d.ts +1 -1
  33. package/dist/auth-email-password/handlers/signup-confirm.write.d.ts +1 -1
  34. package/dist/auth-email-password/handlers/signup-confirm.write.js +3 -4
  35. package/dist/auth-email-password/handlers/signup-request.write.d.ts +1 -1
  36. package/dist/auth-email-password/handlers/signup-request.write.js +2 -1
  37. package/dist/auth-email-password/handlers/switch-tenant-mfa-gate.write.d.ts +1 -1
  38. package/dist/auth-email-password/handlers/token-request-handler.d.ts +2 -3
  39. package/dist/auth-email-password/handlers/token-request-handler.js +2 -2
  40. package/dist/auth-email-password/handlers/verify-email.write.d.ts +1 -1
  41. package/dist/auth-email-password/index.d.ts +2 -2
  42. package/dist/auth-email-password/index.js +1 -1
  43. package/dist/auth-email-password/magic-link-mail.d.ts +3 -2
  44. package/dist/auth-email-password/magic-link-mail.js +19 -14
  45. package/dist/auth-email-password/mail-notifications.d.ts +32 -0
  46. package/dist/auth-email-password/mail-notifications.js +116 -0
  47. package/dist/auth-email-password/signup-activation.d.ts +1 -1
  48. package/dist/auth-email-password/signup-activation.js +2 -3
  49. package/dist/auth-email-password/web/auth-gate.js +16 -4
  50. package/dist/auth-foundation/types.js +2 -8
  51. package/dist/auth-mfa/feature.js +4 -4
  52. package/dist/auth-mfa/handlers/disable.write.d.ts +1 -1
  53. package/dist/auth-mfa/handlers/enable-confirm-preauth.write.d.ts +1 -1
  54. package/dist/auth-mfa/handlers/enable-confirm.write.d.ts +1 -1
  55. package/dist/auth-mfa/handlers/enable-start-preauth.write.d.ts +1 -1
  56. package/dist/auth-mfa/handlers/enable-start.write.d.ts +1 -1
  57. package/dist/auth-mfa/handlers/regenerate-recovery.write.d.ts +1 -1
  58. package/dist/auth-mfa/handlers/verify.write.d.ts +1 -1
  59. package/dist/auth-mfa/hmac-token-codec.js +4 -4
  60. package/dist/auth-mfa/mfa-challenge-token.js +3 -3
  61. package/dist/auth-mfa/mfa-preauth-setup-token.js +3 -3
  62. package/dist/auth-mfa/mfa-setup-token.js +8 -8
  63. package/dist/billing-foundation/constants.d.ts +3 -3
  64. package/dist/billing-foundation/constants.js +5 -4
  65. package/dist/billing-foundation/consumer-protection/confirmation-mail.d.ts +32 -14
  66. package/dist/billing-foundation/consumer-protection/confirmation-mail.js +74 -32
  67. package/dist/billing-foundation/consumer-protection/consent-gate.d.ts +3 -0
  68. package/dist/billing-foundation/consumer-protection/consent-gate.js +21 -2
  69. package/dist/billing-foundation/consumer-protection/issue-confirmation.js +3 -3
  70. package/dist/billing-foundation/consumer-protection/mail-notifications.d.ts +8 -0
  71. package/dist/billing-foundation/consumer-protection/mail-notifications.js +95 -0
  72. package/dist/billing-foundation/consumer-protection/register-consent.js +2 -0
  73. package/dist/billing-foundation/consumer-protection/register-termination.js +11 -1
  74. package/dist/billing-foundation/consumer-protection/termination-mail.d.ts +25 -13
  75. package/dist/billing-foundation/consumer-protection/termination-mail.js +11 -23
  76. package/dist/billing-foundation/consumer-protection/termination-notify.js +2 -2
  77. package/dist/billing-foundation/consumer-protection/termination-pages.js +1 -3
  78. package/dist/billing-foundation/consumer-protection/termination-receipt-limit.d.ts +6 -0
  79. package/dist/billing-foundation/consumer-protection/termination-receipt-limit.js +34 -0
  80. package/dist/billing-foundation/consumer-protection/termination-record.d.ts +2 -0
  81. package/dist/billing-foundation/consumer-protection/termination-record.js +7 -1
  82. package/dist/billing-foundation/consumer-protection/termination-request.js +31 -21
  83. package/dist/billing-foundation/consumer-protection/termination-texts.d.ts +1 -1
  84. package/dist/billing-foundation/consumer-protection/termination-texts.js +6 -0
  85. package/dist/billing-foundation/consumer-protection/withdrawal-period.d.ts +10 -0
  86. package/dist/billing-foundation/consumer-protection/withdrawal-period.js +26 -0
  87. package/dist/billing-foundation/handlers/create-checkout-session.write.js +11 -5
  88. package/dist/billing-foundation/handlers/process-event.write.js +12 -8
  89. package/dist/billing-foundation/handlers/process-payment-event.write.js +1 -1
  90. package/dist/billing-foundation/i18n.js +3 -0
  91. package/dist/billing-foundation/subscription-tier-sync.d.ts +7 -1
  92. package/dist/billing-foundation/subscription-tier-sync.js +16 -9
  93. package/dist/billing-foundation/types.d.ts +7 -2
  94. package/dist/cap-counter/calendar-cap-usage-reservation.js +2 -0
  95. package/dist/cap-counter/enforce-cap.d.ts +18 -1
  96. package/dist/cap-counter/enforce-cap.js +49 -6
  97. package/dist/cap-counter/index.d.ts +1 -1
  98. package/dist/cap-counter/index.js +1 -1
  99. package/dist/cap-counter/with-cap-enforcement.d.ts +2 -0
  100. package/dist/cap-overview/handlers/tenant-caps-list.query.js +2 -1
  101. package/dist/cap-overview/web/cap-usage-cell.js +5 -4
  102. package/dist/channel-email/email-channel.d.ts +2 -2
  103. package/dist/channel-email/email-channel.js +101 -26
  104. package/dist/channel-email/feature.js +3 -3
  105. package/dist/channel-email/index.d.ts +1 -1
  106. package/dist/channel-email/index.js +1 -1
  107. package/dist/channel-email/pii-guard.js +10 -0
  108. package/dist/channel-email/smtp-transport.js +13 -0
  109. package/dist/channel-email/types.d.ts +8 -0
  110. package/dist/channel-in-app/handlers/mark-all-read.write.d.ts +1 -1
  111. package/dist/channel-in-app/handlers/mark-read.write.d.ts +1 -1
  112. package/dist/compliance-profiles/handlers/set-profile.write.d.ts +1 -1
  113. package/dist/config/handlers/reset.write.d.ts +1 -1
  114. package/dist/config/handlers/set.write.d.ts +1 -1
  115. package/dist/config/handlers/set.write.js +3 -4
  116. package/dist/config/resolver.d.ts +1 -0
  117. package/dist/config/resolver.js +11 -14
  118. package/dist/config/write-helpers.d.ts +2 -0
  119. package/dist/config/write-helpers.js +19 -0
  120. package/dist/crypto-shredding/handlers/forget-subject.write.d.ts +1 -1
  121. package/dist/crypto-shredding/handlers/forget-subject.write.js +29 -19
  122. package/dist/custom-fields/handlers/update-tenant-field.write.js +0 -1
  123. package/dist/custom-fields/lib/value-schema.js +10 -11
  124. package/dist/custom-fields/wire-user-data-rights.js +7 -6
  125. package/dist/data-retention/index.d.ts +1 -0
  126. package/dist/data-retention/index.js +1 -0
  127. package/dist/data-retention/run-retention-cleanup.js +6 -6
  128. package/dist/delivery/attachment-ref.d.ts +41 -0
  129. package/dist/delivery/attachment-ref.js +78 -0
  130. package/dist/delivery/channel-context.d.ts +8 -4
  131. package/dist/delivery/channel-context.js +94 -2
  132. package/dist/delivery/constants.d.ts +1 -0
  133. package/dist/delivery/constants.js +1 -0
  134. package/dist/delivery/delivery-service.d.ts +4 -1
  135. package/dist/delivery/delivery-service.js +38 -32
  136. package/dist/delivery/feature.js +1 -1
  137. package/dist/delivery/handlers/resubscribe-address.write.d.ts +1 -1
  138. package/dist/delivery/handlers/resubscribe-user.write.d.ts +1 -1
  139. package/dist/delivery/handlers/set-preference.write.d.ts +1 -1
  140. package/dist/delivery/handlers/unsubscribe-address.write.d.ts +1 -1
  141. package/dist/delivery/handlers/unsubscribe-user.write.d.ts +1 -1
  142. package/dist/delivery/index.d.ts +5 -2
  143. package/dist/delivery/index.js +4 -1
  144. package/dist/delivery/jobs.js +66 -14
  145. package/dist/delivery/notify-factory.js +4 -1
  146. package/dist/delivery/testing.d.ts +4 -1
  147. package/dist/delivery/types.d.ts +26 -14
  148. package/dist/delivery/unsubscribe.js +4 -1
  149. package/dist/derivatives-sharp/render.js +1 -18
  150. package/dist/document-ingest-foundation/pages.js +4 -4
  151. package/dist/feature-toggles/handlers/set.write.d.ts +1 -1
  152. package/dist/feature-toggles/toggle-sync-signal.js +4 -4
  153. package/dist/file-derivatives/handlers/public-variant.query.js +1 -1
  154. package/dist/file-foundation/index.d.ts +1 -0
  155. package/dist/file-foundation/index.js +1 -0
  156. package/dist/file-foundation/read-file-ref-content.d.ts +27 -0
  157. package/dist/file-foundation/read-file-ref-content.js +51 -0
  158. package/dist/files-tenant-data/hooks.js +4 -0
  159. package/dist/folders/web/folder-manager.js +3 -2
  160. package/dist/form-draft/db/queries/cleanup.js +4 -4
  161. package/dist/form-draft/db/queries/draft-count.js +2 -2
  162. package/dist/form-draft/db/queries/owned-file-refs.js +2 -2
  163. package/dist/form-draft/handlers/discard.write.d.ts +1 -1
  164. package/dist/form-draft/handlers/save.write.d.ts +1 -1
  165. package/dist/form-draft/release-file-refs.js +3 -2
  166. package/dist/inbound-mail-foundation/handlers/connect-account.write.js +1 -1
  167. package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +6 -6
  168. package/dist/inbound-mail-foundation/handlers/scope-visibility.d.ts +1 -1
  169. package/dist/inbound-mail-foundation/oauth-access-token.js +8 -3
  170. package/dist/inbound-mail-foundation/oauth-state.js +7 -7
  171. package/dist/inbound-mail-foundation/types.js +4 -4
  172. package/dist/inbound-mail-foundation/watch-supervisor.js +24 -13
  173. package/dist/inbound-provider-imap/imap-client.js +4 -3
  174. package/dist/jobs/db/queries/stale-run-sweep.d.ts +1 -1
  175. package/dist/jobs/db/queries/stale-run-sweep.js +12 -5
  176. package/dist/jobs/feature.js +5 -3
  177. package/dist/jobs/handlers/list.query.js +3 -1
  178. package/dist/jobs/handlers/retry.write.d.ts +1 -1
  179. package/dist/jobs/handlers/stale-run-sweep.job.d.ts +1 -1
  180. package/dist/jobs/handlers/stale-run-sweep.job.js +2 -2
  181. package/dist/jobs/handlers/trigger.write.d.ts +1 -1
  182. package/dist/jobs/job-run-logger.js +32 -10
  183. package/dist/jobs/tenant-job-run-table.js +3 -2
  184. package/dist/ledger/entity.js +3 -1
  185. package/dist/ledger/recurring.js +1 -3
  186. package/dist/managed-pages/branding.d.ts +2 -0
  187. package/dist/managed-pages/branding.js +24 -2
  188. package/dist/managed-pages/feature.js +1 -0
  189. package/dist/managed-pages/handlers/set.write.d.ts +1 -1
  190. package/dist/managed-pages/i18n.js +1 -0
  191. package/dist/managed-pages/screens/branding-screen.js +8 -1
  192. package/dist/page-render/branding.d.ts +1 -0
  193. package/dist/page-render/branding.js +1 -0
  194. package/dist/page-render/markdown.js +1 -1
  195. package/dist/personal-access-tokens/feature.js +1 -1
  196. package/dist/personal-access-tokens/handlers/create.write.d.ts +1 -1
  197. package/dist/personal-access-tokens/handlers/list.query.js +2 -1
  198. package/dist/personal-access-tokens/handlers/revoke.write.d.ts +1 -1
  199. package/dist/personal-access-tokens/revoke-for-user.js +2 -1
  200. package/dist/renderer-foundation/api.d.ts +13 -13
  201. package/dist/renderer-foundation/api.js +1 -1
  202. package/dist/renderer-foundation/constants.js +2 -4
  203. package/dist/renderer-foundation/feature.js +7 -7
  204. package/dist/renderer-foundation/index.d.ts +2 -1
  205. package/dist/renderer-foundation/index.js +1 -0
  206. package/dist/renderer-foundation/types.d.ts +94 -32
  207. package/dist/renderer-pdf/feature.js +7 -1
  208. package/dist/renderer-pdf/render-table-pdf.d.ts +27 -33
  209. package/dist/renderer-pdf/render-table-pdf.js +95 -34
  210. package/dist/secrets/feature.js +4 -3
  211. package/dist/secrets/handlers/delete.write.d.ts +1 -1
  212. package/dist/secrets/handlers/set.write.d.ts +1 -1
  213. package/dist/secrets/secrets-context.js +15 -3
  214. package/dist/sessions/db/queries/cleanup.js +2 -2
  215. package/dist/sessions/feature.js +1 -1
  216. package/dist/sessions/handlers/list.query.js +2 -1
  217. package/dist/sessions/handlers/revoke-all-for-user.write.d.ts +1 -1
  218. package/dist/sessions/handlers/revoke-all-others.write.d.ts +1 -1
  219. package/dist/sessions/handlers/revoke.write.d.ts +1 -1
  220. package/dist/shared/attachment-file-name.d.ts +3 -0
  221. package/dist/shared/attachment-file-name.js +35 -0
  222. package/dist/shared/chunked-entity-migration.d.ts +1 -0
  223. package/dist/shared/chunked-entity-migration.js +1 -1
  224. package/dist/shared/index.d.ts +3 -0
  225. package/dist/shared/index.js +3 -0
  226. package/dist/shared/is-tenant-db.js +1 -1
  227. package/dist/shared/mail-template-body.d.ts +7 -0
  228. package/dist/shared/mail-template-body.js +27 -0
  229. package/dist/shared/sharp-input-limits.d.ts +6 -0
  230. package/dist/shared/sharp-input-limits.js +22 -0
  231. package/dist/shared/signup-handover.js +2 -2
  232. package/dist/subscription-stripe/plugin-methods.js +18 -8
  233. package/dist/subscription-stripe/verify-webhook.d.ts +1 -1
  234. package/dist/tags/handlers/assign-tag.write.js +3 -1
  235. package/dist/tags/web/tag-chip.js +2 -0
  236. package/dist/template-resolver/api.d.ts +30 -2
  237. package/dist/template-resolver/api.js +42 -6
  238. package/dist/template-resolver/compile-document-body.d.ts +12 -0
  239. package/dist/template-resolver/compile-document-body.js +205 -0
  240. package/dist/template-resolver/constants.d.ts +13 -4
  241. package/dist/template-resolver/constants.js +32 -10
  242. package/dist/template-resolver/document-sanitizer.d.ts +32 -0
  243. package/dist/template-resolver/document-sanitizer.js +201 -0
  244. package/dist/template-resolver/document-schema.d.ts +21 -0
  245. package/dist/template-resolver/document-schema.js +316 -0
  246. package/dist/template-resolver/feature.d.ts +20 -0
  247. package/dist/template-resolver/feature.js +53 -6
  248. package/dist/template-resolver/handlers/bundle-import.d.ts +20 -0
  249. package/dist/template-resolver/handlers/bundle-import.js +147 -0
  250. package/dist/template-resolver/handlers/collection-set.write.d.ts +1 -1
  251. package/dist/template-resolver/handlers/collection-set.write.js +25 -2
  252. package/dist/template-resolver/handlers/copy-locale.write.d.ts +19 -0
  253. package/dist/template-resolver/handlers/copy-locale.write.js +134 -0
  254. package/dist/template-resolver/handlers/diff-to-system.query.d.ts +22 -0
  255. package/dist/template-resolver/handlers/diff-to-system.query.js +30 -0
  256. package/dist/template-resolver/handlers/discard-draft.write.d.ts +13 -0
  257. package/dist/template-resolver/handlers/discard-draft.write.js +37 -0
  258. package/dist/template-resolver/handlers/export-bundle.query.d.ts +35 -0
  259. package/dist/template-resolver/handlers/export-bundle.query.js +118 -0
  260. package/dist/template-resolver/handlers/find-by-id.query.d.ts +2 -0
  261. package/dist/template-resolver/handlers/find-by-id.query.js +9 -6
  262. package/dist/template-resolver/handlers/import-bundle-system.write.d.ts +39 -0
  263. package/dist/template-resolver/handlers/import-bundle-system.write.js +36 -0
  264. package/dist/template-resolver/handlers/import-bundle.write.d.ts +40 -0
  265. package/dist/template-resolver/handlers/import-bundle.write.js +19 -0
  266. package/dist/template-resolver/handlers/layout-source.query.d.ts +31 -0
  267. package/dist/template-resolver/handlers/layout-source.query.js +87 -0
  268. package/dist/template-resolver/handlers/list.query.d.ts +4 -1
  269. package/dist/template-resolver/handlers/list.query.js +9 -8
  270. package/dist/template-resolver/handlers/override-diff.d.ts +20 -0
  271. package/dist/template-resolver/handlers/override-diff.js +41 -0
  272. package/dist/template-resolver/handlers/overview.query.d.ts +65 -0
  273. package/dist/template-resolver/handlers/overview.query.js +205 -0
  274. package/dist/template-resolver/handlers/preview.query.d.ts +12 -0
  275. package/dist/template-resolver/handlers/preview.query.js +24 -0
  276. package/dist/template-resolver/handlers/reset-to-system.write.d.ts +8 -0
  277. package/dist/template-resolver/handlers/reset-to-system.write.js +50 -0
  278. package/dist/template-resolver/handlers/resource-link-pdf.write.d.ts +8 -0
  279. package/dist/template-resolver/handlers/resource-link-pdf.write.js +32 -0
  280. package/dist/template-resolver/handlers/resource-remove.write.d.ts +9 -0
  281. package/dist/template-resolver/handlers/resource-remove.write.js +44 -0
  282. package/dist/template-resolver/handlers/resource-shared.d.ts +9 -0
  283. package/dist/template-resolver/handlers/resource-shared.js +14 -0
  284. package/dist/template-resolver/handlers/resource-upload.write.d.ts +13 -0
  285. package/dist/template-resolver/handlers/resource-upload.write.js +98 -0
  286. package/dist/template-resolver/handlers/send-test.write.d.ts +13 -0
  287. package/dist/template-resolver/handlers/send-test.write.js +108 -0
  288. package/dist/template-resolver/handlers/set.write.d.ts +5 -2
  289. package/dist/template-resolver/handlers/set.write.js +25 -3
  290. package/dist/template-resolver/handlers/shared.d.ts +9 -5
  291. package/dist/template-resolver/handlers/shared.js +6 -2
  292. package/dist/template-resolver/handlers/template-gates.d.ts +36 -0
  293. package/dist/template-resolver/handlers/template-gates.js +142 -0
  294. package/dist/template-resolver/handlers/template-write.d.ts +45 -0
  295. package/dist/template-resolver/handlers/template-write.js +141 -0
  296. package/dist/template-resolver/handlers/tenant-overrides.query.d.ts +49 -0
  297. package/dist/template-resolver/handlers/tenant-overrides.query.js +112 -0
  298. package/dist/template-resolver/handlers/toggle-status.write.d.ts +27 -2
  299. package/dist/template-resolver/handlers/toggle-status.write.js +47 -15
  300. package/dist/template-resolver/handlers/upsert-system.write.d.ts +5 -8
  301. package/dist/template-resolver/handlers/upsert-system.write.js +14 -59
  302. package/dist/template-resolver/handlers/upsert-tenant.write.d.ts +5 -8
  303. package/dist/template-resolver/handlers/upsert-tenant.write.js +11 -62
  304. package/dist/template-resolver/handlers/usage.query.d.ts +17 -0
  305. package/dist/template-resolver/handlers/usage.query.js +24 -0
  306. package/dist/template-resolver/handlers/validate.query.d.ts +74 -0
  307. package/dist/template-resolver/handlers/validate.query.js +80 -0
  308. package/dist/template-resolver/index.d.ts +19 -1
  309. package/dist/template-resolver/index.js +17 -1
  310. package/dist/template-resolver/layout-appearance.d.ts +10 -0
  311. package/dist/template-resolver/layout-appearance.js +26 -0
  312. package/dist/template-resolver/layout-regions.d.ts +23 -0
  313. package/dist/template-resolver/layout-regions.js +125 -0
  314. package/dist/template-resolver/linked-resources.d.ts +17 -0
  315. package/dist/template-resolver/linked-resources.js +75 -0
  316. package/dist/template-resolver/pdf-constants.d.ts +7 -0
  317. package/dist/template-resolver/pdf-constants.js +8 -0
  318. package/dist/template-resolver/preview-display-html.d.ts +7 -0
  319. package/dist/template-resolver/preview-display-html.js +27 -0
  320. package/dist/template-resolver/print-document.d.ts +1 -0
  321. package/dist/template-resolver/print-document.js +55 -0
  322. package/dist/template-resolver/qualified-names.d.ts +34 -0
  323. package/dist/template-resolver/qualified-names.js +34 -0
  324. package/dist/template-resolver/record-mapping.d.ts +2 -0
  325. package/dist/template-resolver/record-mapping.js +21 -0
  326. package/dist/template-resolver/resource-image.d.ts +15 -0
  327. package/dist/template-resolver/resource-image.js +34 -0
  328. package/dist/template-resolver/seeding.d.ts +14 -1
  329. package/dist/template-resolver/seeding.js +125 -18
  330. package/dist/template-resolver/store-template-resource.d.ts +64 -0
  331. package/dist/template-resolver/store-template-resource.js +264 -0
  332. package/dist/template-resolver/table.d.ts +150 -8
  333. package/dist/template-resolver/table.js +20 -2
  334. package/dist/template-resolver/template-bundle.d.ts +36 -0
  335. package/dist/template-resolver/template-bundle.js +60 -0
  336. package/dist/template-resolver/template-diff.d.ts +7 -0
  337. package/dist/template-resolver/template-diff.js +68 -0
  338. package/dist/template-resolver/template-draft.d.ts +51 -0
  339. package/dist/template-resolver/template-draft.js +72 -0
  340. package/dist/template-resolver/template-meta.d.ts +85 -0
  341. package/dist/template-resolver/template-meta.js +145 -0
  342. package/dist/template-resolver/template-preview.d.ts +103 -0
  343. package/dist/template-resolver/template-preview.js +418 -0
  344. package/dist/template-resolver/template-resources.d.ts +19 -0
  345. package/dist/template-resolver/template-resources.js +73 -0
  346. package/dist/template-resolver/template-usage.d.ts +16 -0
  347. package/dist/template-resolver/template-usage.js +35 -0
  348. package/dist/template-resolver/template-validation.d.ts +22 -0
  349. package/dist/template-resolver/template-validation.js +173 -0
  350. package/dist/template-resolver/testing.js +5 -5
  351. package/dist/template-resolver/user-content-table.d.ts +14 -8
  352. package/dist/template-resolver/web/client-plugin.d.ts +1 -0
  353. package/dist/template-resolver/web/client-plugin.js +12 -7
  354. package/dist/template-resolver/web/document-editor-extensions.d.ts +18 -0
  355. package/dist/template-resolver/web/document-editor-extensions.js +145 -0
  356. package/dist/template-resolver/web/document-editor.d.ts +4 -0
  357. package/dist/template-resolver/web/document-editor.js +17 -0
  358. package/dist/template-resolver/web/document-tiptap-editor.d.ts +3 -0
  359. package/dist/template-resolver/web/document-tiptap-editor.js +492 -0
  360. package/dist/template-resolver/web/document-toolbar-blocks.d.ts +41 -0
  361. package/dist/template-resolver/web/document-toolbar-blocks.js +19 -0
  362. package/dist/template-resolver/web/editor-handle.d.ts +3 -0
  363. package/dist/template-resolver/web/editor-handle.js +24 -0
  364. package/dist/template-resolver/web/i18n.js +91 -0
  365. package/dist/template-resolver/web/index.d.ts +5 -0
  366. package/dist/template-resolver/web/index.js +5 -0
  367. package/dist/template-resolver/web/placeholder-line-editor-lazy.d.ts +4 -0
  368. package/dist/template-resolver/web/placeholder-line-editor-lazy.js +16 -0
  369. package/dist/template-resolver/web/placeholder-line-editor.d.ts +17 -0
  370. package/dist/template-resolver/web/placeholder-line-editor.js +94 -0
  371. package/dist/template-resolver/web/placeholder-text.d.ts +4 -0
  372. package/dist/template-resolver/web/placeholder-text.js +34 -0
  373. package/dist/template-resolver/web/use-stable-by-key.d.ts +1 -0
  374. package/dist/template-resolver/web/use-stable-by-key.js +13 -0
  375. package/dist/tenant/handlers/add-member.write.d.ts +1 -1
  376. package/dist/tenant/handlers/cancel-invitation.write.d.ts +1 -1
  377. package/dist/tenant/handlers/create.write.d.ts +1 -1
  378. package/dist/tenant/handlers/remove-member.write.d.ts +1 -1
  379. package/dist/tenant/handlers/team-list.query.js +3 -2
  380. package/dist/tenant/handlers/toggle-enabled.write.d.ts +2 -2
  381. package/dist/tenant/handlers/update-member-roles.write.d.ts +1 -1
  382. package/dist/tenant/handlers/update.write.d.ts +1 -1
  383. package/dist/tenant/seeding.js +31 -6
  384. package/dist/tenant-handover/handlers/claim.write.d.ts +1 -1
  385. package/dist/tenant-lifecycle/handlers/cancel-destruction.write.d.ts +2 -2
  386. package/dist/tenant-lifecycle/handlers/cancel-destruction.write.js +2 -1
  387. package/dist/tenant-lifecycle/handlers/request-destruction.write.d.ts +1 -1
  388. package/dist/tier-engine/feature.js +9 -3
  389. package/dist/tier-engine/handlers/set-tenant-tier.write.d.ts +1 -1
  390. package/dist/user/db/queries/stream-tenant-backfill.js +4 -4
  391. package/dist/user/handlers/create.write.d.ts +1 -1
  392. package/dist/user/handlers/detail.query.js +2 -1
  393. package/dist/user/handlers/update.write.d.ts +1 -1
  394. package/dist/user/resolve-display-names.js +5 -9
  395. package/dist/user/seeding.js +20 -1
  396. package/dist/user-data-rights/db/queries/forget-cleanup.d.ts +2 -2
  397. package/dist/user-data-rights/email-templates.d.ts +1 -29
  398. package/dist/user-data-rights/email-templates.js +5 -106
  399. package/dist/user-data-rights/feature.js +53 -35
  400. package/dist/user-data-rights/handlers/cancel-deletion.write.d.ts +2 -2
  401. package/dist/user-data-rights/handlers/cancel-deletion.write.js +2 -1
  402. package/dist/user-data-rights/handlers/confirm-deletion-by-token.write.d.ts +1 -1
  403. package/dist/user-data-rights/handlers/lift-restriction.write.d.ts +1 -1
  404. package/dist/user-data-rights/handlers/request-deletion-by-email.write.d.ts +1 -1
  405. package/dist/user-data-rights/handlers/request-deletion.write.d.ts +1 -1
  406. package/dist/user-data-rights/handlers/request-deletion.write.js +5 -7
  407. package/dist/user-data-rights/handlers/request-export.write.d.ts +1 -1
  408. package/dist/user-data-rights/handlers/restrict-account.write.d.ts +1 -1
  409. package/dist/user-data-rights/handlers/run-forget-cleanup.write.d.ts +1 -1
  410. package/dist/user-data-rights/lib/default-mailers.d.ts +15 -7
  411. package/dist/user-data-rights/lib/default-mailers.js +100 -48
  412. package/dist/user-data-rights/lib/update-user-lifecycle.js +1 -1
  413. package/dist/user-data-rights/mail-notifications.d.ts +13 -0
  414. package/dist/user-data-rights/mail-notifications.js +118 -0
  415. package/dist/user-data-rights/web/privacy-center-screen.js +2 -1
  416. package/dist/user-profile/handlers/change-email.write.d.ts +1 -1
  417. package/dist/user-profile/web/profile-screen.js +2 -1
  418. package/dist/waitlist/feature.js +10 -0
  419. package/dist/waitlist/handlers/invite.write.d.ts +1 -1
  420. package/dist/waitlist/handlers/reject.write.d.ts +1 -1
  421. package/dist/waitlist/handlers/submit.write.d.ts +1 -1
  422. package/dist/waitlist/handlers/submit.write.js +3 -4
  423. package/dist/waitlist/mail.d.ts +19 -6
  424. package/dist/waitlist/mail.js +50 -14
  425. package/dist/waitlist/options.js +1 -1
  426. package/dist/workflow-runner/event-trigger.js +2 -2
  427. package/dist/workflow-runner/handlers/resume-run.write.js +7 -2
  428. package/package.json +37 -17
  429. package/src/admin-shell/changes.json +6 -0
  430. package/src/audit/changes.json +6 -0
  431. package/src/auth-email-password/changes.json +51 -0
  432. package/src/billing-foundation/changes.json +43 -0
  433. package/src/cap-counter/changes.json +6 -0
  434. package/src/channel-email/changes.json +19 -0
  435. package/src/config/changes.json +6 -0
  436. package/src/crypto-shredding/changes.json +6 -0
  437. package/src/custom-fields/changes.json +6 -0
  438. package/src/data-retention/changes.json +6 -0
  439. package/src/delivery/changes.json +66 -0
  440. package/src/file-foundation/changes.json +6 -0
  441. package/src/files-tenant-data/changes.json +6 -0
  442. package/src/inbound-mail-foundation/changes.json +6 -0
  443. package/src/jobs/changes.json +19 -0
  444. package/src/ledger/changes.json +7 -0
  445. package/src/managed-pages/changes.json +6 -0
  446. package/src/renderer-foundation/changes.json +39 -0
  447. package/src/renderer-pdf/changes.json +12 -0
  448. package/src/secrets/changes.json +6 -0
  449. package/src/shared/changes.json +6 -0
  450. package/src/subscription-stripe/changes.json +6 -0
  451. package/src/template-resolver/changes.json +186 -0
  452. package/src/tier-engine/changes.json +6 -0
  453. package/src/user/changes.json +6 -0
  454. package/src/user-data-rights/changes.json +13 -0
  455. package/src/user-profile/changes.json +1 -1
  456. package/src/waitlist/changes.json +7 -0
  457. package/src/workflow-runner/changes.json +6 -0
  458. package/dist/renderer-simple/feature.d.ts +0 -10
  459. package/dist/renderer-simple/feature.js +0 -42
  460. package/dist/renderer-simple/index.d.ts +0 -3
  461. package/dist/renderer-simple/index.js +0 -2
  462. package/dist/renderer-simple/mail-blocks.d.ts +0 -21
  463. package/dist/renderer-simple/mail-blocks.js +0 -107
  464. package/dist/renderer-simple/resolve-variables.d.ts +0 -7
  465. package/dist/renderer-simple/resolve-variables.js +0 -47
  466. package/dist/renderer-simple/simple-renderer.d.ts +0 -24
  467. package/dist/renderer-simple/simple-renderer.js +0 -200
  468. package/src/renderer-simple/changes.json +0 -27
@@ -0,0 +1,108 @@
1
+ import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
3
+ import * as z from "zod";
4
+ import { collectChannels, createEmailAttachmentReader, EMAIL_CHANNEL_NAME, } from "../../delivery/index.js";
5
+ import { fileContextForTenant } from "../../file-foundation/index.js";
6
+ import { TEST_MAIL_NOTIFICATION_TYPE, TEST_MAIL_SUBJECT_PREFIX } from "../constants.js";
7
+ import { TemplateResolverErrors } from "../qualified-names.js";
8
+ import { renderTemplatePreview } from "../template-preview.js";
9
+ import { localeSchema, templateSlugSchema } from "./shared.js";
10
+ const TEST_MAIL_RATE_LIMIT = { limit: 10, windowSeconds: 3600 };
11
+ function emailChannelOf(registry) {
12
+ return collectChannels(registry).find((channel) => channel.name === EMAIL_CHANNEL_NAME);
13
+ }
14
+ // Transport errors can carry provider responses or the address, so the client only gets a fixed code.
15
+ function testMailFailed(code) {
16
+ return writeFailure(new UnprocessableError(TemplateResolverErrors.testMailFailed, {
17
+ i18nKey: "templateResolver.errors.testMail.failed",
18
+ details: { code },
19
+ }));
20
+ }
21
+ function errorCodeOf(error) {
22
+ const code = error instanceof Error ? Reflect.get(error, "code") : undefined;
23
+ return typeof code === "string" ? code : undefined;
24
+ }
25
+ // The only recipient is the caller's own address, resolved server-side, so the handler can never mail a third party.
26
+ export const sendTestWrite = defineWriteHandler({
27
+ name: "send-test",
28
+ schema: z.object({
29
+ slug: templateSlugSchema,
30
+ locale: localeSchema,
31
+ content: z.string().max(200_000).optional(),
32
+ meta: z.unknown().optional(),
33
+ variableSchema: z.record(z.string(), z.unknown()).default({}),
34
+ includeAttachments: z.boolean().default(true),
35
+ prefixSubject: z.boolean().default(true),
36
+ }),
37
+ access: { roles: ["TenantAdmin", "SystemAdmin"] },
38
+ rateLimit: { per: "user+handler", ...TEST_MAIL_RATE_LIMIT },
39
+ description: "Sends the rendered preview of a mail template draft, or of the stored template when no content is given, to the calling user's own address with the subject prefixed by [TEST] unless prefixSubject is false, carrying the inline images and, unless includeAttachments is false, the files attached to the template; there is no recipient input, the sample values come from the declared variable examples, and a draft that fails the write rules is rejected without sending.",
40
+ handler: async (event, ctx) => {
41
+ const { includeAttachments, prefixSubject, ...previewPayload } = event.payload;
42
+ const outcome = await renderTemplatePreview(ctx, event.user, {
43
+ ...previewPayload,
44
+ kind: "mail",
45
+ });
46
+ if (!outcome.ok)
47
+ return writeFailure(outcome.error);
48
+ const { preview, sender } = outcome;
49
+ const mailAttachments = includeAttachments
50
+ ? outcome.mailAttachments
51
+ : outcome.mailAttachments.filter((ref) => ref.kind === "inline");
52
+ const channel = emailChannelOf(ctx.registry);
53
+ if (channel === undefined) {
54
+ return writeFailure(new UnprocessableError(TemplateResolverErrors.testMailNoChannel, {
55
+ i18nKey: "templateResolver.errors.testMail.noChannel",
56
+ }));
57
+ }
58
+ const channelContext = {
59
+ db: ctx.db,
60
+ registry: ctx.registry,
61
+ sseBroker: undefined,
62
+ tenantId: event.user.tenantId,
63
+ secrets: ctx.secrets,
64
+ readAttachment: createEmailAttachmentReader(ctx.db, ctx.registry, event.user.tenantId, ctx.config, (tenantId) => fileContextForTenant(ctx, ctx.user.tenantId, tenantId)),
65
+ };
66
+ const address = (await channel.resolve?.(event.user.id, channelContext)) ?? null;
67
+ if (address === null) {
68
+ return writeFailure(new UnprocessableError(TemplateResolverErrors.testMailNoAddress, {
69
+ i18nKey: "templateResolver.errors.testMail.noAddress",
70
+ }));
71
+ }
72
+ const subject = `${prefixSubject ? TEST_MAIL_SUBJECT_PREFIX : ""}${preview.subject ?? ""}`;
73
+ let sentStatus;
74
+ try {
75
+ const result = await channel.send(address, {
76
+ notificationType: TEST_MAIL_NOTIFICATION_TYPE,
77
+ title: subject,
78
+ body: undefined,
79
+ data: undefined,
80
+ locale: event.payload.locale,
81
+ }, channelContext, {
82
+ subject,
83
+ html: preview.html,
84
+ text: preview.text ?? "",
85
+ ...sender,
86
+ attachments: mailAttachments,
87
+ });
88
+ sentStatus = result.status;
89
+ }
90
+ catch (error) {
91
+ // Class and code only: the message can carry the address or a provider response body.
92
+ ctx.log?.warn("template test mail: channel threw", {
93
+ tenantId: event.user.tenantId,
94
+ errorClass: error instanceof Error ? error.name : typeof error,
95
+ errorCode: errorCodeOf(error),
96
+ });
97
+ return testMailFailed("channel_error");
98
+ }
99
+ if (sentStatus !== "sent") {
100
+ ctx.log?.warn("template test mail: channel did not send", {
101
+ tenantId: event.user.tenantId,
102
+ status: sentStatus,
103
+ });
104
+ return testMailFailed("not_sent");
105
+ }
106
+ return { isSuccess: true, data: { subject, checks: preview.checks } };
107
+ },
108
+ });
@@ -6,8 +6,11 @@ export declare const setWrite: import("@cosmicdrift/kumiko-types/define-handler"
6
6
  "ai-prompt": "ai-prompt";
7
7
  "document-pdf": "document-pdf";
8
8
  "image-snapshot": "image-snapshot";
9
- "mail-html": "mail-html";
9
+ mail: "mail";
10
+ "mail-layout": "mail-layout";
10
11
  notification: "notification";
12
+ "pdf-layout": "pdf-layout";
13
+ snippet: "snippet";
11
14
  "text-block": "text-block";
12
15
  }>>;
13
16
  title: z.ZodString;
@@ -24,4 +27,4 @@ export declare const setWrite: import("@cosmicdrift/kumiko-types/define-handler"
24
27
  slug: string;
25
28
  locale: string;
26
29
  isNew: boolean;
27
- }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
30
+ }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap, undefined>;
@@ -1,10 +1,14 @@
1
1
  import { fetchOne } from "@cosmicdrift/kumiko-framework/bun-db";
2
2
  import { defineWriteHandler, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
3
4
  import * as z from "zod";
4
5
  import { requireForTenant } from "../../shared/index.js";
5
- import { TEMPLATE_KINDS, TEXT_BLOCK_KIND } from "../constants.js";
6
+ import { TEMPLATE_KINDS, TEXT_BLOCK_KIND, UPSERT_KINDS } from "../constants.js";
6
7
  import { templateResourcesTable } from "../table.js";
8
+ import { resolveTemplateVariables } from "../template-validation.js";
7
9
  import { contentFormatSchema, executor, folderSchema, localeSchema, slugSchema } from "./shared.js";
10
+ import { parseStoredJson, storedRecord } from "./template-gates.js";
11
+ import { gateTemplateWrite } from "./template-write.js";
8
12
  // Upsert of a single resource, one operation per (tenantId, slug, kind,
9
13
  // locale). This is the content-tree authoring path: unlike upsertTenant it
10
14
  // takes a title and a folder, has no draft stage (saving publishes) and it may
@@ -21,6 +25,9 @@ import { contentFormatSchema, executor, folderSchema, localeSchema, slugSchema }
21
25
  // upsertTenant → publish draft stage. That is the deliberate split between
22
26
  // the two authoring routes — use upsertSystem/upsertTenant when a template
23
27
  // needs a draft or a variable schema.
28
+ //
29
+ // Kinds that upsertSystem/upsertTenant also write run the same validation
30
+ // pipeline here, and because saving publishes, publish issues reject too.
24
31
  export const setWrite = defineWriteHandler({
25
32
  name: "set",
26
33
  schema: z.object({
@@ -55,17 +62,32 @@ export const setWrite = defineWriteHandler({
55
62
  kind,
56
63
  locale: event.payload.locale,
57
64
  });
65
+ const scope = tenantId === SYSTEM_TENANT_ID ? "system" : "tenant";
66
+ let content = event.payload.content;
67
+ if (isOneOf(UPSERT_KINDS, kind)) {
68
+ const gated = gateTemplateWrite({
69
+ kind,
70
+ scope,
71
+ contentFormat: event.payload.contentFormat,
72
+ content,
73
+ rawMeta: parseStoredJson(existing?.meta ?? null),
74
+ variables: resolveTemplateVariables(ctx.registry, event.payload.slug, storedRecord(existing?.variableSchema ?? null)),
75
+ }, "active");
76
+ if (!gated.ok)
77
+ return gated.failure;
78
+ content = gated.evaluated.content;
79
+ }
58
80
  const fields = {
59
81
  slug: event.payload.slug,
60
82
  kind,
61
83
  locale: event.payload.locale,
62
84
  title: event.payload.title,
63
- content: event.payload.content,
85
+ content,
64
86
  contentFormat: event.payload.contentFormat,
65
87
  folder: event.payload.folder ?? null,
66
88
  variableSchema: "{}",
67
89
  linkedResources: "{}",
68
- scope: tenantId === SYSTEM_TENANT_ID ? "system" : "tenant",
90
+ scope,
69
91
  parentTemplateId: null,
70
92
  // Text blocks have no draft stage — saving publishes, so resolveTemplate
71
93
  // (which only returns active rows) finds them.
@@ -1,13 +1,16 @@
1
1
  import * as z from "zod";
2
+ import { templateSlugSchema } from "../template-meta.js";
2
3
  export declare const executor: import("@cosmicdrift/kumiko-types/event-store-executor-types").EventStoreExecutor;
3
4
  export declare const slugSchema: z.ZodString;
5
+ export { templateSlugSchema };
4
6
  export declare const localeSchema: z.ZodString;
5
7
  export declare const kindSchema: z.ZodEnum<{
6
8
  "ai-prompt": "ai-prompt";
7
9
  "document-pdf": "document-pdf";
8
10
  "image-snapshot": "image-snapshot";
9
- "mail-html": "mail-html";
10
- notification: "notification";
11
+ mail: "mail";
12
+ "mail-layout": "mail-layout";
13
+ "pdf-layout": "pdf-layout";
11
14
  }>;
12
15
  export declare const folderSchema: z.ZodString;
13
16
  export declare const titleSchema: z.ZodString;
@@ -28,8 +31,9 @@ export declare const upsertPayloadSchema: z.ZodObject<{
28
31
  "ai-prompt": "ai-prompt";
29
32
  "document-pdf": "document-pdf";
30
33
  "image-snapshot": "image-snapshot";
31
- "mail-html": "mail-html";
32
- notification: "notification";
34
+ mail: "mail";
35
+ "mail-layout": "mail-layout";
36
+ "pdf-layout": "pdf-layout";
33
37
  }>;
34
38
  locale: z.ZodString;
35
39
  content: z.ZodString;
@@ -40,7 +44,7 @@ export declare const upsertPayloadSchema: z.ZodObject<{
40
44
  plain: "plain";
41
45
  }>;
42
46
  variableSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
43
- linkedResources: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
47
+ meta: z.ZodOptional<z.ZodUnknown>;
44
48
  parentTemplateId: z.ZodOptional<z.ZodString>;
45
49
  title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
50
  folder: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -2,6 +2,7 @@ import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
2
2
  import * as z from "zod";
3
3
  import { CONTENT_FORMATS, TEMPLATE_STATUSES, UPSERT_KINDS } from "../constants.js";
4
4
  import { templateResourceEntity, templateResourcesTable } from "../table.js";
5
+ import { templateSlugSchema } from "../template-meta.js";
5
6
  // One executor per bundle, shared by all four handlers for create/update via
6
7
  // event store + optimistic lock.
7
8
  export const executor = createEventStoreExecutor(templateResourcesTable, templateResourceEntity, {
@@ -13,6 +14,7 @@ export const slugSchema = z
13
14
  .min(1)
14
15
  .max(80)
15
16
  .regex(/^[a-z0-9][a-z0-9-]*$/, "slug must be kebab-case (lowercase, digits, dashes)");
17
+ export { templateSlugSchema };
16
18
  export const localeSchema = z
17
19
  .string()
18
20
  .min(2)
@@ -31,13 +33,15 @@ export const statusSchema = z.enum(TEMPLATE_STATUSES);
31
33
  // Common Upsert-Payload — geteilt zwischen upsertSystem + upsertTenant.
32
34
  // Unterschied: ACL + tenantId-Bestimmung, sonst identisch.
33
35
  export const upsertPayloadSchema = z.object({
34
- slug: slugSchema,
36
+ slug: templateSlugSchema,
35
37
  kind: kindSchema,
36
38
  locale: localeSchema,
37
39
  content: z.string().max(200_000),
38
40
  contentFormat: contentFormatSchema,
39
41
  variableSchema: z.record(z.string(), z.unknown()).default({}),
40
- linkedResources: z.record(z.string(), z.string()).default({}),
42
+ // Shape depends on kind; validated against template-meta.ts in the handler so
43
+ // problems surface as field issues on `meta.*`.
44
+ meta: z.unknown().optional(),
41
45
  parentTemplateId: z.string().min(1).optional(),
42
46
  title: titleSchema.nullable().optional(),
43
47
  folder: folderSchema.nullable().optional(),
@@ -0,0 +1,36 @@
1
+ import type { Registry, TemplateVariables } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { FieldIssue } from "@cosmicdrift/kumiko-framework/errors";
3
+ import { type ContentFormat, type TemplateKind } from "../constants.js";
4
+ import { type TemplateWriteScope } from "../layout-regions.js";
5
+ import type { TemplateResourceRow } from "../table.js";
6
+ import { type TemplateValidation } from "../template-validation.js";
7
+ export declare function placeholderIssues(validation: TemplateValidation, opts: {
8
+ readonly requireAllRequired: boolean;
9
+ }): FieldIssue[];
10
+ export type TemplateWriteInput = {
11
+ readonly kind: TemplateKind;
12
+ readonly scope: TemplateWriteScope;
13
+ readonly contentFormat: ContentFormat;
14
+ readonly content: string | null;
15
+ readonly rawMeta: unknown;
16
+ readonly variables: TemplateVariables;
17
+ /** Keys with an uploaded file besides the built-in `logo`; only feeds the unknownResources warning. */
18
+ readonly resourceKeys?: readonly string[];
19
+ };
20
+ export type TemplateWriteResult = {
21
+ readonly ok: true;
22
+ readonly content: string | null;
23
+ readonly metaJson: string | null;
24
+ readonly validation: TemplateValidation | null;
25
+ /** Problems that still allow a draft but block publishing. */
26
+ readonly publishIssues: readonly FieldIssue[];
27
+ } | {
28
+ readonly ok: false;
29
+ readonly issues: readonly FieldIssue[];
30
+ /** Set when the placeholder scan ran, so callers can still list what it found. */
31
+ readonly validation: TemplateValidation | null;
32
+ };
33
+ export declare function evaluateTemplateWrite(input: TemplateWriteInput): TemplateWriteResult;
34
+ export declare function parseStoredJson(raw: string | null): unknown;
35
+ export declare function storedRecord(raw: string | null): Readonly<Record<string, unknown>>;
36
+ export declare function publishGateIssues(registry: Registry, row: TemplateResourceRow): readonly FieldIssue[];
@@ -0,0 +1,142 @@
1
+ import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
2
+ import { CONTENT_FORMATS, TEMPLATE_KINDS, } from "../constants.js";
3
+ import { documentViolationsToFieldIssues } from "../document-sanitizer.js";
4
+ import { sanitizeTemplateWriteBody } from "../layout-regions.js";
5
+ import { imageResourceKeysOf } from "../linked-resources.js";
6
+ import { parseTemplateMeta } from "../template-meta.js";
7
+ import { resolveTemplateVariables, validateTemplatePlaceholders, } from "../template-validation.js";
8
+ const PLACEHOLDER_VALIDATED_KINDS = new Set([
9
+ "mail",
10
+ "document-pdf",
11
+ "pdf-layout",
12
+ ]);
13
+ // The parser's wording is English and meant for logs; the UI gets a key per setting instead.
14
+ const META_FIELDS_WITH_MESSAGES = new Set([
15
+ "subject",
16
+ "previewText",
17
+ "senderName",
18
+ "replyTo",
19
+ "layoutSlug",
20
+ "fileName",
21
+ ]);
22
+ function metaIssueToFieldIssue(issue) {
23
+ const hasMessage = META_FIELDS_WITH_MESSAGES.has(issue.field);
24
+ return {
25
+ path: issue.path,
26
+ code: "invalid_meta",
27
+ i18nKey: hasMessage
28
+ ? `templateResolver.errors.template.meta.${issue.field}.${issue.missing ? "required" : "invalid"}`
29
+ : "templateResolver.errors.template.invalidMeta",
30
+ };
31
+ }
32
+ export function placeholderIssues(validation, opts) {
33
+ const issues = [];
34
+ if (validation.unknown.length > 0) {
35
+ issues.push({
36
+ path: "content",
37
+ code: "unknown_placeholder",
38
+ i18nKey: "templateResolver.errors.template.unknownPlaceholders",
39
+ params: { detail: validation.unknown.join(", ") },
40
+ });
41
+ }
42
+ if (opts.requireAllRequired && validation.missingRequired.length > 0) {
43
+ issues.push({
44
+ path: "content",
45
+ code: "missing_required_placeholder",
46
+ i18nKey: "templateResolver.errors.template.missingRequiredPlaceholders",
47
+ params: { detail: validation.missingRequired.join(", ") },
48
+ });
49
+ }
50
+ return issues;
51
+ }
52
+ const NO_PUBLISH_ISSUES = [];
53
+ function isPlaceholderValidated(kind, contentFormat) {
54
+ if (kind === "mail-layout")
55
+ return contentFormat === "html";
56
+ return PLACEHOLDER_VALIDATED_KINDS.has(kind);
57
+ }
58
+ // The single validation pipeline of every template write: sanitize and layout
59
+ // rules, then meta, then placeholders.
60
+ export function evaluateTemplateWrite(input) {
61
+ const body = sanitizeTemplateWriteBody({
62
+ kind: input.kind,
63
+ scope: input.scope,
64
+ contentFormat: input.contentFormat,
65
+ content: input.content,
66
+ });
67
+ if (!body.ok)
68
+ return {
69
+ ok: false,
70
+ issues: documentViolationsToFieldIssues(body.violations),
71
+ validation: null,
72
+ };
73
+ const parsedMeta = parseTemplateMeta(input.kind, input.rawMeta);
74
+ if (!parsedMeta.ok) {
75
+ return { ok: false, issues: parsedMeta.issues.map(metaIssueToFieldIssue), validation: null };
76
+ }
77
+ const metaJson = parsedMeta.meta === null ? null : JSON.stringify(parsedMeta.meta);
78
+ if (!isPlaceholderValidated(input.kind, input.contentFormat)) {
79
+ return {
80
+ ok: true,
81
+ content: body.content,
82
+ metaJson,
83
+ validation: null,
84
+ publishIssues: NO_PUBLISH_ISSUES,
85
+ };
86
+ }
87
+ const validation = validateTemplatePlaceholders({
88
+ kind: input.kind,
89
+ body: body.content ?? "",
90
+ meta: parsedMeta.meta,
91
+ variables: input.variables,
92
+ resourceKeys: input.resourceKeys,
93
+ });
94
+ const issues = placeholderIssues(validation, { requireAllRequired: false });
95
+ if (issues.length > 0)
96
+ return { ok: false, issues, validation };
97
+ return {
98
+ ok: true,
99
+ content: body.content,
100
+ metaJson,
101
+ validation,
102
+ publishIssues: placeholderIssues(validation, { requireAllRequired: true }),
103
+ };
104
+ }
105
+ function isTemplateKind(kind) {
106
+ return isOneOf(TEMPLATE_KINDS, kind);
107
+ }
108
+ export function parseStoredJson(raw) {
109
+ if (!raw)
110
+ return undefined;
111
+ try {
112
+ return JSON.parse(raw);
113
+ }
114
+ catch {
115
+ return undefined;
116
+ }
117
+ }
118
+ function isGatedKind(kind) {
119
+ return isTemplateKind(kind) && (kind === "mail-layout" || PLACEHOLDER_VALIDATED_KINDS.has(kind));
120
+ }
121
+ export function storedRecord(raw) {
122
+ const parsed = parseStoredJson(raw);
123
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
124
+ ? Object.fromEntries(Object.entries(parsed))
125
+ : {};
126
+ }
127
+ // Publishing makes a row servable, so a stored row must pass the same pipeline
128
+ // as an active write would have.
129
+ export function publishGateIssues(registry, row) {
130
+ if (!isGatedKind(row.kind) || !isOneOf(CONTENT_FORMATS, row.contentFormat))
131
+ return [];
132
+ const result = evaluateTemplateWrite({
133
+ kind: row.kind,
134
+ scope: row.scope === "system" ? "system" : "tenant",
135
+ contentFormat: row.contentFormat,
136
+ content: row.content,
137
+ rawMeta: parseStoredJson(row.meta),
138
+ variables: resolveTemplateVariables(registry, row.slug, storedRecord(row.variableSchema)),
139
+ resourceKeys: imageResourceKeysOf(row.linkedResources),
140
+ });
141
+ return result.ok ? result.publishIssues : result.issues;
142
+ }
@@ -0,0 +1,45 @@
1
+ import { type HandlerContext, type SessionUser, type TemplateVariables, type TenantId, type WriteResult } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { type WriteFailure } from "@cosmicdrift/kumiko-framework/errors";
3
+ import type { ContentFormat, TemplateKind } from "../constants.js";
4
+ import type { TemplateWriteScope } from "../layout-regions.js";
5
+ import type { TemplateValidation } from "../template-validation.js";
6
+ import { type TemplateWriteInput, type TemplateWriteResult } from "./template-gates.js";
7
+ export type TemplateRowPayload = {
8
+ readonly slug: string;
9
+ readonly kind: TemplateKind;
10
+ readonly locale: string;
11
+ readonly content: string | null;
12
+ readonly contentFormat: ContentFormat;
13
+ readonly variableSchema: Readonly<Record<string, unknown>>;
14
+ readonly meta?: unknown;
15
+ readonly title?: string | null | undefined;
16
+ readonly folder?: string | null | undefined;
17
+ readonly parentTemplateId?: string | null | undefined;
18
+ };
19
+ export type WrittenTemplateRow = {
20
+ readonly id: string;
21
+ readonly slug: string;
22
+ readonly isNew: boolean;
23
+ readonly validation: TemplateValidation | null;
24
+ };
25
+ export type TemplateRowWrite = {
26
+ readonly ctx: HandlerContext;
27
+ readonly user: SessionUser;
28
+ readonly tenantId: TenantId;
29
+ readonly scope: TemplateWriteScope;
30
+ readonly status: "draft" | "active";
31
+ readonly variables: TemplateVariables;
32
+ readonly payload: TemplateRowPayload;
33
+ };
34
+ export declare function refuseTenantScopeUnderSystemTenant(scope: TemplateWriteScope, tenantId: string): WriteResult<never> | null;
35
+ export type GatedTemplateWrite = {
36
+ readonly ok: true;
37
+ readonly evaluated: Extract<TemplateWriteResult, {
38
+ ok: true;
39
+ }>;
40
+ } | {
41
+ readonly ok: false;
42
+ readonly failure: WriteFailure;
43
+ };
44
+ export declare function gateTemplateWrite(input: TemplateWriteInput, status: "draft" | "active"): GatedTemplateWrite;
45
+ export declare function writeTemplateRow(args: TemplateRowWrite): Promise<WriteResult<WrittenTemplateRow>>;
@@ -0,0 +1,141 @@
1
+ import { fetchOne } from "@cosmicdrift/kumiko-framework/bun-db";
2
+ import { SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { AccessDeniedError, ValidationError, writeFailure, } from "@cosmicdrift/kumiko-framework/errors";
4
+ import { requireForTenant } from "../../shared/index.js";
5
+ import { templateResourcesTable } from "../table.js";
6
+ import { activationChanges, serializeTemplateDraft } from "../template-draft.js";
7
+ import { executor } from "./shared.js";
8
+ import { evaluateTemplateWrite, } from "./template-gates.js";
9
+ // The tenant-scope-under-system-tenant ban lives here so no write path can
10
+ // create the inconsistent state the resolver does not model.
11
+ export function refuseTenantScopeUnderSystemTenant(scope, tenantId) {
12
+ if (scope !== "tenant" || tenantId !== SYSTEM_TENANT_ID)
13
+ return null;
14
+ return writeFailure(new AccessDeniedError({
15
+ i18nKey: "templateResolver.errors.useUpsertSystemForSystemTenant",
16
+ details: { reason: "system_tenant_override_not_allowed_use_upsert_system" },
17
+ }));
18
+ }
19
+ // Evaluation plus the publish rule: a row that goes active must not carry
20
+ // publish issues, a draft may.
21
+ export function gateTemplateWrite(input, status) {
22
+ const evaluated = evaluateTemplateWrite(input);
23
+ if (!evaluated.ok) {
24
+ return {
25
+ ok: false,
26
+ failure: writeFailure(new ValidationError({ fields: [...evaluated.issues] })),
27
+ };
28
+ }
29
+ if (status === "active" && evaluated.publishIssues.length > 0) {
30
+ return {
31
+ ok: false,
32
+ failure: writeFailure(new ValidationError({ fields: [...evaluated.publishIssues] })),
33
+ };
34
+ }
35
+ return { ok: true, evaluated };
36
+ }
37
+ // A draft over an active row is stored beside it; every other write replaces the main fields.
38
+ function updateChanges(existing, status, fields) {
39
+ if (status === "active")
40
+ return { ...fields, ...activationChanges(existing) };
41
+ if (existing.status !== "active")
42
+ return { ...fields, status, draft: null };
43
+ const draft = serializeTemplateDraft({
44
+ content: fields.content,
45
+ contentFormat: fields.contentFormat,
46
+ variableSchema: fields.variableSchema,
47
+ meta: fields.meta,
48
+ title: fields.title,
49
+ folder: fields.folder,
50
+ parentTemplateId: fields.parentTemplateId,
51
+ });
52
+ return existing.activeVersion === null
53
+ ? {
54
+ draft,
55
+ activeVersion: existing.version,
56
+ activeSince: existing.modifiedAt ?? existing.insertedAt,
57
+ }
58
+ : { draft };
59
+ }
60
+ // Shared by every template write: validate through the one pipeline, then
61
+ // create or update the (tenant, slug, kind, locale) row via the event-store
62
+ // executor. linkedResources is never part of an update; resources are attached
63
+ // separately.
64
+ export async function writeTemplateRow(args) {
65
+ const { ctx, user, tenantId, scope, status, payload } = args;
66
+ const refused = refuseTenantScopeUnderSystemTenant(scope, tenantId);
67
+ if (refused !== null)
68
+ return refused;
69
+ const { db, streamTenantId } = requireForTenant(ctx, tenantId);
70
+ const gated = gateTemplateWrite({
71
+ kind: payload.kind,
72
+ scope,
73
+ contentFormat: payload.contentFormat,
74
+ content: payload.content,
75
+ rawMeta: payload.meta,
76
+ variables: args.variables,
77
+ }, status);
78
+ if (!gated.ok)
79
+ return gated.failure;
80
+ const { evaluated } = gated;
81
+ const existing = await fetchOne(db, templateResourcesTable, {
82
+ tenantId,
83
+ slug: payload.slug,
84
+ kind: payload.kind,
85
+ locale: payload.locale,
86
+ });
87
+ const fields = {
88
+ slug: payload.slug,
89
+ kind: payload.kind,
90
+ locale: payload.locale,
91
+ content: evaluated.content,
92
+ contentFormat: payload.contentFormat,
93
+ variableSchema: JSON.stringify(payload.variableSchema),
94
+ meta: evaluated.metaJson,
95
+ title: payload.title ?? null,
96
+ folder: payload.folder ?? null,
97
+ scope,
98
+ parentTemplateId: payload.parentTemplateId ?? null,
99
+ status,
100
+ };
101
+ if (existing) {
102
+ const result = await executor.update({
103
+ id: existing.id,
104
+ version: existing.version,
105
+ changes: updateChanges(existing, status, fields),
106
+ }, user, db, { streamTenantId });
107
+ if (!result.isSuccess)
108
+ return result;
109
+ return {
110
+ isSuccess: true,
111
+ data: {
112
+ id: String(existing.id),
113
+ slug: payload.slug,
114
+ isNew: false,
115
+ validation: evaluated.validation,
116
+ },
117
+ };
118
+ }
119
+ const result = await executor.create({
120
+ ...fields,
121
+ linkedResources: "{}",
122
+ tenantId,
123
+ draft: null,
124
+ ...(status === "active" ? activationChanges(null) : {}),
125
+ }, user, db, { streamTenantId });
126
+ if (!result.isSuccess)
127
+ return result;
128
+ // @cast-boundary db-row — executor.create returnt Record-row aus
129
+ // INSERT RETURNING; shape { id } ist garantiert weil PK in der
130
+ // Returning-Klausel ist.
131
+ const createdRow = result.data;
132
+ return {
133
+ isSuccess: true,
134
+ data: {
135
+ id: String(createdRow.id),
136
+ slug: payload.slug,
137
+ isNew: true,
138
+ validation: evaluated.validation,
139
+ },
140
+ };
141
+ }