@cosmicdrift/kumiko-bundled-features 0.374.0 → 0.378.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 (260) hide show
  1. package/dist/account-security/constants.d.ts +1 -0
  2. package/dist/account-security/constants.js +1 -0
  3. package/dist/account-security/index.d.ts +1 -1
  4. package/dist/account-security/index.js +1 -1
  5. package/dist/admin-shell/web/client-plugin.d.ts +1 -1
  6. package/dist/audit/web/client-plugin.d.ts +1 -1
  7. package/dist/auth-email-password/mail-notifications.js +1 -1
  8. package/dist/auth-email-password/web/auth-client.js +1 -1
  9. package/dist/auth-email-password/web/auth-form-primitives.js +1 -1
  10. package/dist/auth-email-password/web/default-topbar-actions.js +1 -1
  11. package/dist/auth-email-password/web/index.js +1 -1
  12. package/dist/auth-email-password/web/session.js +1 -1
  13. package/dist/auth-email-password/web/tenant-menu-items.js +1 -1
  14. package/dist/auth-email-password/web/tenant-switcher.js +1 -1
  15. package/dist/auth-email-password/web/user-menu.js +1 -1
  16. package/dist/auth-foundation/env.d.ts +9 -0
  17. package/dist/auth-foundation/env.js +21 -0
  18. package/dist/auth-foundation/index.d.ts +1 -0
  19. package/dist/auth-foundation/index.js +1 -0
  20. package/dist/auth-mfa/schema/user-mfa.d.ts +6 -6
  21. package/dist/billing-foundation/consumer-protection/confirmation-mail.js +1 -1
  22. package/dist/billing-foundation/consumer-protection/termination-pages.js +1 -1
  23. package/dist/billing-foundation/contact-card.d.ts +2 -0
  24. package/dist/billing-foundation/contact-card.js +16 -0
  25. package/dist/billing-foundation/entities.d.ts +8 -8
  26. package/dist/billing-foundation/handlers/billing-plans.query.js +1 -1
  27. package/dist/billing-foundation/index.d.ts +1 -1
  28. package/dist/billing-foundation/plan-catalog.js +1 -0
  29. package/dist/billing-foundation/projection.d.ts +8 -8
  30. package/dist/billing-foundation/types.d.ts +11 -0
  31. package/dist/billing-foundation/validate-options.js +13 -0
  32. package/dist/billing-foundation/web/billing-contact-plan.d.ts +5 -0
  33. package/dist/billing-foundation/web/billing-contact-plan.js +17 -0
  34. package/dist/billing-foundation/web/billing-plans-panel.js +5 -13
  35. package/dist/billing-foundation/web/cancel-contract-dialog.js +2 -2
  36. package/dist/billing-foundation/web/checkout-consent-dialog.d.ts +1 -1
  37. package/dist/billing-foundation/web/checkout-consent-dialog.js +1 -0
  38. package/dist/billing-foundation/web/client-plugin.d.ts +1 -1
  39. package/dist/billing-foundation/web/localized-params.d.ts +1 -0
  40. package/dist/billing-foundation/web/localized-params.js +11 -0
  41. package/dist/cap-counter/entity.d.ts +1 -1
  42. package/dist/cap-counter/stock-cap-guard.js +8 -0
  43. package/dist/cap-overview/web/cap-cards-panel.js +3 -3
  44. package/dist/cap-overview/web/client-plugin.d.ts +1 -1
  45. package/dist/channel-email/email-channel.d.ts +2 -1
  46. package/dist/compliance-profiles/web/client-plugin.d.ts +1 -1
  47. package/dist/config/feature.js +2 -2
  48. package/dist/config/table.d.ts +6 -6
  49. package/dist/config/web/i18n.js +1 -0
  50. package/dist/custom-fields/entity.d.ts +4 -4
  51. package/dist/custom-fields/web/client-plugin.d.ts +1 -1
  52. package/dist/data-retention/schema/tenant-retention-override.d.ts +4 -4
  53. package/dist/delivery/tables.d.ts +6 -6
  54. package/dist/delivery/unsubscribe-page.js +1 -1
  55. package/dist/delivery/web/client-plugin.d.ts +1 -1
  56. package/dist/delivery/web/delivery-status-cell.js +1 -1
  57. package/dist/document-ingest-foundation/entity.d.ts +4 -4
  58. package/dist/feature-toggles/web/client-plugin.d.ts +1 -1
  59. package/dist/file-provider-s3/env-named-feature.d.ts +17 -0
  60. package/dist/file-provider-s3/env-named-feature.js +23 -0
  61. package/dist/file-provider-s3/env-schema.d.ts +7 -0
  62. package/dist/file-provider-s3/env-schema.js +15 -10
  63. package/dist/file-provider-s3/index.d.ts +1 -0
  64. package/dist/file-provider-s3/index.js +1 -0
  65. package/dist/folders/entity.d.ts +8 -8
  66. package/dist/folders/web/client-plugin.d.ts +1 -1
  67. package/dist/form-draft/entity.d.ts +2 -2
  68. package/dist/host-routing/constants.d.ts +2 -0
  69. package/dist/host-routing/constants.js +3 -0
  70. package/dist/host-routing/dispatch.d.ts +1 -1
  71. package/dist/host-routing/dispatch.js +35 -25
  72. package/dist/host-routing/feature.js +100 -27
  73. package/dist/host-routing/host.d.ts +9 -0
  74. package/dist/host-routing/host.js +24 -2
  75. package/dist/host-routing/index.d.ts +2 -1
  76. package/dist/host-routing/index.js +1 -0
  77. package/dist/host-routing/options.d.ts +14 -0
  78. package/dist/host-routing/redirects.d.ts +6 -0
  79. package/dist/host-routing/redirects.js +27 -0
  80. package/dist/host-routing/tenant-lookup.d.ts +7 -0
  81. package/dist/host-routing/tenant-lookup.js +39 -0
  82. package/dist/host-routing/validate-options.js +34 -1
  83. package/dist/inbound-mail-foundation/entities.d.ts +25 -25
  84. package/dist/inbound-mail-foundation/feature.js +7 -0
  85. package/dist/inbound-mail-foundation/handlers/list-accounts.query.d.ts +1 -1
  86. package/dist/inbound-mail-foundation/handlers/list-accounts.query.js +11 -3
  87. package/dist/inbound-mail-foundation/i18n.d.ts +3 -0
  88. package/dist/inbound-mail-foundation/i18n.js +35 -0
  89. package/dist/inbound-mail-foundation/index.d.ts +1 -0
  90. package/dist/inbound-mail-foundation/index.js +1 -0
  91. package/dist/inbound-mail-foundation/projection.d.ts +20 -20
  92. package/dist/inbound-mail-foundation/screens.d.ts +7 -0
  93. package/dist/inbound-mail-foundation/screens.js +86 -0
  94. package/dist/inbound-mail-foundation/types.d.ts +2 -2
  95. package/dist/jobs/job-run-table.d.ts +6 -6
  96. package/dist/jobs/web/client-plugin.d.ts +1 -1
  97. package/dist/ledger/entity.d.ts +13 -13
  98. package/dist/legal-pages/feature.js +11 -1
  99. package/dist/legal-pages/layout.d.ts +2 -2
  100. package/dist/legal-pages/layout.js +4 -4
  101. package/dist/legal-pages/web/client-plugin.d.ts +1 -1
  102. package/dist/mail-foundation/feature.d.ts +20 -21
  103. package/dist/mail-foundation/feature.js +1 -1
  104. package/dist/mail-foundation/i18n.d.ts +5 -2
  105. package/dist/mail-foundation/i18n.js +3 -2
  106. package/dist/mail-transport-smtp/i18n.d.ts +1 -1
  107. package/dist/mail-transport-smtp/i18n.js +1 -1
  108. package/dist/managed-pages/table.d.ts +12 -12
  109. package/dist/managed-pages/web/client-plugin.d.ts +1 -1
  110. package/dist/notes-history/entity.d.ts +12 -12
  111. package/dist/notes-history/web/client-plugin.d.ts +1 -1
  112. package/dist/page-render/branding.js +1 -1
  113. package/dist/page-render/layout.d.ts +1 -1
  114. package/dist/page-render/layout.js +2 -2
  115. package/dist/page-render/markdown.js +1 -1
  116. package/dist/personal-access-tokens/i18n.js +1 -1
  117. package/dist/personal-access-tokens/schema/api-token.d.ts +6 -6
  118. package/dist/personal-access-tokens/screens.js +1 -1
  119. package/dist/secrets/feature.d.ts +1 -1
  120. package/dist/secrets/feature.js +3 -3
  121. package/dist/secrets/table.d.ts +1 -1
  122. package/dist/seo/sitemap.js +1 -1
  123. package/dist/sessions/schema/user-session.d.ts +4 -4
  124. package/dist/shared/mail-template-body.js +1 -1
  125. package/dist/shared/purge-files-reaching-subject.js +98 -3
  126. package/dist/tags/entity.d.ts +9 -9
  127. package/dist/tags/web/client-plugin.d.ts +1 -1
  128. package/dist/template-resolver/compile-document-body.d.ts +3 -0
  129. package/dist/template-resolver/compile-document-body.js +50 -3
  130. package/dist/template-resolver/constants.d.ts +3 -0
  131. package/dist/template-resolver/constants.js +2 -0
  132. package/dist/template-resolver/document-blocks.d.ts +5 -0
  133. package/dist/template-resolver/document-blocks.js +22 -0
  134. package/dist/template-resolver/document-images.d.ts +2 -0
  135. package/dist/template-resolver/document-images.js +28 -0
  136. package/dist/template-resolver/document-ops.d.ts +167 -0
  137. package/dist/template-resolver/document-ops.js +390 -0
  138. package/dist/template-resolver/document-sanitizer.d.ts +4 -1
  139. package/dist/template-resolver/document-sanitizer.js +26 -0
  140. package/dist/template-resolver/document-schema.d.ts +2 -1
  141. package/dist/template-resolver/document-schema.js +4 -0
  142. package/dist/template-resolver/feature.d.ts +11 -0
  143. package/dist/template-resolver/feature.js +60 -31
  144. package/dist/template-resolver/handlers/bundle-import.js +1 -0
  145. package/dist/template-resolver/handlers/collection-item.query.js +2 -1
  146. package/dist/template-resolver/handlers/collection-list.query.js +2 -1
  147. package/dist/template-resolver/handlers/collection-set.write.js +2 -2
  148. package/dist/template-resolver/handlers/collection-shared.d.ts +1 -2
  149. package/dist/template-resolver/handlers/collection-shared.js +0 -4
  150. package/dist/template-resolver/handlers/copy-locale.write.d.ts +2 -1
  151. package/dist/template-resolver/handlers/copy-locale.write.js +67 -63
  152. package/dist/template-resolver/handlers/discard-draft.write.d.ts +3 -2
  153. package/dist/template-resolver/handlers/discard-draft.write.js +18 -6
  154. package/dist/template-resolver/handlers/document-base.d.ts +23 -0
  155. package/dist/template-resolver/handlers/document-base.js +55 -0
  156. package/dist/template-resolver/handlers/document-blocks.query.d.ts +22 -0
  157. package/dist/template-resolver/handlers/document-blocks.query.js +46 -0
  158. package/dist/template-resolver/handlers/export-bundle.query.d.ts +1 -0
  159. package/dist/template-resolver/handlers/export-bundle.query.js +9 -2
  160. package/dist/template-resolver/handlers/import-bundle-system.write.d.ts +1 -0
  161. package/dist/template-resolver/handlers/import-bundle.write.d.ts +3 -1
  162. package/dist/template-resolver/handlers/import-bundle.write.js +30 -25
  163. package/dist/template-resolver/handlers/overview.query.d.ts +2 -1
  164. package/dist/template-resolver/handlers/overview.query.js +46 -42
  165. package/dist/template-resolver/handlers/patch-draft.write.d.ts +67 -0
  166. package/dist/template-resolver/handlers/patch-draft.write.js +111 -0
  167. package/dist/template-resolver/handlers/preview.query.d.ts +1 -0
  168. package/dist/template-resolver/handlers/preview.query.js +2 -1
  169. package/dist/template-resolver/handlers/reset-to-system.write.d.ts +2 -1
  170. package/dist/template-resolver/handlers/reset-to-system.write.js +51 -44
  171. package/dist/template-resolver/handlers/resource-link-pdf.write.d.ts +2 -1
  172. package/dist/template-resolver/handlers/resource-link-pdf.write.js +34 -28
  173. package/dist/template-resolver/handlers/resource-remove.write.d.ts +2 -1
  174. package/dist/template-resolver/handlers/resource-remove.write.js +39 -33
  175. package/dist/template-resolver/handlers/resource-upload.write.d.ts +2 -1
  176. package/dist/template-resolver/handlers/resource-upload.write.js +104 -96
  177. package/dist/template-resolver/handlers/send-test-shared.d.ts +5 -0
  178. package/dist/template-resolver/handlers/send-test-shared.js +19 -0
  179. package/dist/template-resolver/handlers/send-test-status.query.d.ts +9 -0
  180. package/dist/template-resolver/handlers/send-test-status.query.js +18 -0
  181. package/dist/template-resolver/handlers/send-test.write.d.ts +3 -1
  182. package/dist/template-resolver/handlers/send-test.write.js +87 -88
  183. package/dist/template-resolver/handlers/set.write.d.ts +2 -1
  184. package/dist/template-resolver/handlers/set.write.js +94 -90
  185. package/dist/template-resolver/handlers/template-write.d.ts +2 -0
  186. package/dist/template-resolver/handlers/template-write.js +14 -2
  187. package/dist/template-resolver/handlers/toggle-status.write.d.ts +6 -7
  188. package/dist/template-resolver/handlers/toggle-status.write.js +28 -10
  189. package/dist/template-resolver/handlers/upsert-tenant.write.d.ts +2 -1
  190. package/dist/template-resolver/handlers/upsert-tenant.write.js +30 -24
  191. package/dist/template-resolver/handlers/validate.query.d.ts +10 -4
  192. package/dist/template-resolver/handlers/validate.query.js +12 -7
  193. package/dist/template-resolver/index.d.ts +4 -2
  194. package/dist/template-resolver/index.js +3 -1
  195. package/dist/template-resolver/{web/placeholder-text.js → placeholder-text.js} +1 -1
  196. package/dist/template-resolver/qualified-names.d.ts +4 -0
  197. package/dist/template-resolver/qualified-names.js +4 -0
  198. package/dist/template-resolver/seeding.d.ts +1 -0
  199. package/dist/template-resolver/seeding.js +2 -1
  200. package/dist/template-resolver/table.d.ts +10 -10
  201. package/dist/template-resolver/template-bundle.d.ts +1 -0
  202. package/dist/template-resolver/template-bundle.js +6 -1
  203. package/dist/template-resolver/template-edit-policy.d.ts +22 -0
  204. package/dist/template-resolver/template-edit-policy.js +45 -0
  205. package/dist/template-resolver/template-preview.d.ts +4 -1
  206. package/dist/template-resolver/template-preview.js +23 -5
  207. package/dist/template-resolver/template-validation.d.ts +2 -1
  208. package/dist/template-resolver/template-validation.js +34 -14
  209. package/dist/template-resolver/user-content-table.d.ts +10 -10
  210. package/dist/template-resolver/web/client-plugin.d.ts +1 -1
  211. package/dist/template-resolver/web/client-plugin.js +3 -3
  212. package/dist/template-resolver/web/document-editor-extensions.d.ts +1 -0
  213. package/dist/template-resolver/web/document-editor-extensions.js +21 -1
  214. package/dist/template-resolver/web/document-tiptap-editor.d.ts +1 -1
  215. package/dist/template-resolver/web/document-tiptap-editor.js +23 -7
  216. package/dist/template-resolver/web/document-toolbar-blocks.d.ts +4 -5
  217. package/dist/template-resolver/web/document-toolbar-blocks.js +1 -21
  218. package/dist/template-resolver/web/i18n.js +18 -0
  219. package/dist/template-resolver/web/placeholder-line-editor.js +2 -2
  220. package/dist/tenant/invitation-table.d.ts +6 -6
  221. package/dist/tenant/membership-table.d.ts +4 -4
  222. package/dist/tenant/schema/tenant.d.ts +6 -6
  223. package/dist/tenant/web/client-plugin.d.ts +1 -1
  224. package/dist/tenant/web/member-status-cell.js +1 -1
  225. package/dist/tier-engine/entity.d.ts +1 -1
  226. package/dist/tier-engine/tier-resolver.d.ts +1 -1
  227. package/dist/tier-engine/web/client-plugin.d.ts +1 -1
  228. package/dist/user/schema/user.d.ts +12 -12
  229. package/dist/user-data-rights/env.d.ts +5 -0
  230. package/dist/user-data-rights/env.js +11 -0
  231. package/dist/user-data-rights/feature.js +4 -2
  232. package/dist/user-data-rights/index.d.ts +1 -0
  233. package/dist/user-data-rights/index.js +1 -0
  234. package/dist/user-data-rights/lib/mail-transport-resolver.js +1 -1
  235. package/dist/user-data-rights/lib/storage-provider-resolver.js +1 -1
  236. package/dist/user-data-rights/mail-notifications.js +1 -1
  237. package/dist/user-data-rights/schema/download-attempt.d.ts +14 -14
  238. package/dist/user-data-rights/schema/download-token.d.ts +8 -8
  239. package/dist/user-data-rights/schema/export-job.d.ts +6 -6
  240. package/dist/user-data-rights/web/client-plugin.d.ts +1 -1
  241. package/dist/user-data-rights/web/privacy-center-screen.js +2 -2
  242. package/dist/waitlist/entity.d.ts +14 -14
  243. package/dist/waitlist/legacy-migrate.d.ts +2 -0
  244. package/dist/waitlist/legacy-migrate.js +38 -3
  245. package/package.json +16 -11
  246. package/src/account-security/changes.json +6 -0
  247. package/src/auth-foundation/changes.json +6 -0
  248. package/src/billing-foundation/changes.json +6 -0
  249. package/src/cap-counter/changes.json +12 -0
  250. package/src/channel-email/changes.json +6 -0
  251. package/src/crypto-shredding/changes.json +6 -0
  252. package/src/file-provider-s3/changes.json +6 -0
  253. package/src/host-routing/changes.json +6 -0
  254. package/src/inbound-mail-foundation/changes.json +13 -0
  255. package/src/legal-pages/changes.json +6 -0
  256. package/src/mail-foundation/changes.json +6 -0
  257. package/src/template-resolver/changes.json +38 -0
  258. package/src/user-data-rights/changes.json +6 -0
  259. package/src/waitlist/changes.json +6 -0
  260. /package/dist/template-resolver/{web/placeholder-text.d.ts → placeholder-text.d.ts} +0 -0
@@ -1,4 +1,5 @@
1
1
  import { type ContentCollectionDefinition } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { TenantEditableTemplate } from "./template-edit-policy.ts";
2
3
  export type TemplateResolverOptions = {
3
4
  /** Content collections this app mounts. Declared here rather than inside the
4
5
  * feature because `access` needs the host's role vocabulary — a bundled
@@ -10,6 +11,13 @@ export type TemplateResolverOptions = {
10
11
  * access rule, so the dispatcher enforces the separation instead of a
11
12
  * branch in a shared handler. */
12
13
  readonly collections?: readonly ContentCollectionDefinition[];
14
+ /** Templates a TenantAdmin may edit for the own tenant (override, draft, publish, archive,
15
+ * reset, copy-locale, import, resources). Without an entry only a SystemAdmin edits.
16
+ * A tenant-edited mail goes out under the platform's name, so the app opts in per
17
+ * template instead of the framework guessing which ones a tenant may reword.
18
+ * `access` is required: the host decides its role vocabulary here, like for
19
+ * `collections`. SystemAdmin always passes. */
20
+ readonly tenantEditable?: readonly TenantEditableTemplate[];
13
21
  };
14
22
  export declare function createTemplateResolverFeature(opts?: TemplateResolverOptions): import("@cosmicdrift/kumiko-types/feature").FeatureDefinition & {
15
23
  readonly exports: {
@@ -31,6 +39,7 @@ export declare function createTemplateResolverFeature(opts?: TemplateResolverOpt
31
39
  resourceRemove: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
32
40
  resourceLinkPdf: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
33
41
  sendTest: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
42
+ patchDraft: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
34
43
  };
35
44
  queries: {
36
45
  findById: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
@@ -44,7 +53,9 @@ export declare function createTemplateResolverFeature(opts?: TemplateResolverOpt
44
53
  diffToSystem: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
45
54
  validate: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
46
55
  preview: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
56
+ documentBlocks: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
47
57
  exportBundle: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
58
+ sendTestStatus: import("@cosmicdrift/kumiko-types/handlers").HandlerRef;
48
59
  };
49
60
  treeHandle: import("@cosmicdrift/kumiko-types/tree-node").TreeActionsHandle<"template-resolver", {
50
61
  readonly edit: {
@@ -1,31 +1,34 @@
1
1
  import { createSystemConfig, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
2
- import { isCollectionRefusedKind } from "./constants.js";
2
+ import { DEFAULT_COLLECTION_ACCESS, isCollectionRefusedKind } from "./constants.js";
3
3
  import { bySlugQuery } from "./handlers/by-slug.query.js";
4
4
  import { byTenantQuery } from "./handlers/by-tenant.query.js";
5
5
  import { makeCollectionItemQuery } from "./handlers/collection-item.query.js";
6
6
  import { makeCollectionListQuery } from "./handlers/collection-list.query.js";
7
7
  import { makeCollectionSetWrite } from "./handlers/collection-set.write.js";
8
- import { copyLocaleWrite } from "./handlers/copy-locale.write.js";
8
+ import { makeCopyLocaleWrite } from "./handlers/copy-locale.write.js";
9
9
  import { diffToSystemQuery } from "./handlers/diff-to-system.query.js";
10
- import { discardDraftSystemWrite, discardDraftWrite } from "./handlers/discard-draft.write.js";
10
+ import { makeDiscardDraftSystemWrite, makeDiscardDraftWrite, } from "./handlers/discard-draft.write.js";
11
+ import { documentBlocksQuery } from "./handlers/document-blocks.query.js";
11
12
  import { exportBundleQuery } from "./handlers/export-bundle.query.js";
12
13
  import { findByIdQuery } from "./handlers/find-by-id.query.js";
13
- import { importBundleWrite } from "./handlers/import-bundle.write.js";
14
+ import { makeImportBundleWrite } from "./handlers/import-bundle.write.js";
14
15
  import { importBundleSystemWrite } from "./handlers/import-bundle-system.write.js";
15
16
  import { layoutSourceQuery } from "./handlers/layout-source.query.js";
16
17
  import { listQuery } from "./handlers/list.query.js";
17
- import { overviewQuery } from "./handlers/overview.query.js";
18
+ import { makeOverviewQuery } from "./handlers/overview.query.js";
19
+ import { makePatchDraftWrite } from "./handlers/patch-draft.write.js";
18
20
  import { previewQuery } from "./handlers/preview.query.js";
19
- import { resetToSystemWrite } from "./handlers/reset-to-system.write.js";
20
- import { resourceLinkPdfWrite } from "./handlers/resource-link-pdf.write.js";
21
- import { resourceRemoveWrite } from "./handlers/resource-remove.write.js";
22
- import { resourceUploadWrite } from "./handlers/resource-upload.write.js";
23
- import { sendTestWrite } from "./handlers/send-test.write.js";
24
- import { setWrite } from "./handlers/set.write.js";
21
+ import { makeResetToSystemWrite } from "./handlers/reset-to-system.write.js";
22
+ import { makeResourceLinkPdfWrite } from "./handlers/resource-link-pdf.write.js";
23
+ import { makeResourceRemoveWrite } from "./handlers/resource-remove.write.js";
24
+ import { makeResourceUploadWrite } from "./handlers/resource-upload.write.js";
25
+ import { makeSendTestWrite } from "./handlers/send-test.write.js";
26
+ import { sendTestStatusQuery } from "./handlers/send-test-status.query.js";
27
+ import { makeSetWrite } from "./handlers/set.write.js";
25
28
  import { tenantOverridesQuery } from "./handlers/tenant-overrides.query.js";
26
- import { archiveSystemWrite, archiveWrite, publishSystemWrite, publishWrite, } from "./handlers/toggle-status.write.js";
29
+ import { makeArchiveSystemWrite, makeArchiveWrite, makePublishSystemWrite, makePublishWrite, } from "./handlers/toggle-status.write.js";
27
30
  import { upsertSystemWrite } from "./handlers/upsert-system.write.js";
28
- import { upsertTenantWrite } from "./handlers/upsert-tenant.write.js";
31
+ import { makeUpsertTenantWrite } from "./handlers/upsert-tenant.write.js";
29
32
  import { usageQuery } from "./handlers/usage.query.js";
30
33
  import { validateQuery } from "./handlers/validate.query.js";
31
34
  import { templateResourceEntity } from "./table.js";
@@ -37,19 +40,39 @@ function assertCollectionKindsAllowed(collections) {
37
40
  }
38
41
  }
39
42
  }
43
+ function assertTenantEditableValid(entries) {
44
+ const seen = new Set();
45
+ for (const entry of entries) {
46
+ const key = `${entry.kind}/${entry.slug}`;
47
+ if (seen.has(key)) {
48
+ throw new Error(`template-resolver: tenantEditable lists "${key}" twice`);
49
+ }
50
+ seen.add(key);
51
+ if (entry.slug.trim() === "") {
52
+ throw new Error(`template-resolver: tenantEditable entry of kind "${entry.kind}" has an empty slug`);
53
+ }
54
+ if (entry.access.roles.length === 0) {
55
+ throw new Error(`template-resolver: tenantEditable entry "${entry.kind}/${entry.slug}" has no roles in access`);
56
+ }
57
+ }
58
+ }
40
59
  export function createTemplateResolverFeature(opts = {}) {
41
60
  const collections = opts.collections ?? [];
42
61
  assertCollectionKindsAllowed(collections);
62
+ const tenantEditable = opts.tenantEditable ?? [];
63
+ assertTenantEditableValid(tenantEditable);
64
+ const policy = { tenantEditable };
43
65
  const hasUserOwned = collections.some((c) => c.ownership === "user");
44
66
  return defineFeature("template-resolver", (r) => {
45
67
  r.describe([
46
68
  "Every piece of editable text lives here, in one entity: mail bodies, notification texts, PDF document templates, AI prompts and plain text blocks. What a record is used for is the `kind` (`notification`, `mail`, `mail-layout`, `document-pdf`, `pdf-layout`, `ai-prompt`, `text-block`, `snippet`, `image-snapshot`).",
47
69
  "Reading is one call — `ctx.templateResolver.resolveTemplate({ tenantId, slug, kind, locale })`. It walks four levels: tenant+locale, system+locale, tenant+fallback-locale, system+fallback-locale. A tenant overrides a system default by simply having its own record; no application code changes. Writing programmatically goes through the `upsertSystem`, `upsertTenant`, `publish` and `archive` write handlers; a SystemAdmin retires or restores a system default with `publishSystem` and `archiveSystem`, and a tenant drops its override with `resetToSystem`. Saving a draft over an active template keeps the active version served and stores the edit beside it (column `draft`); `publish` makes it the served version, `discardDraft` / `discardDraftSystem` throws it away.",
70
+ 'Editing templates is for SystemAdmin only. A TenantAdmin edits only the templates the app unlocks at the mount site, `createTemplateResolverFeature({ tenantEditable: [{ kind: "mail", slug: "status-update", access: { roles: ["TenantAdmin"] } }] })`, and every write handler enforces that on the server (override, draft, publish, archive, reset, copy-locale, import, resources, `set`). Each entry carries the `access` roles allowed to edit it, because a bundled feature cannot know the host\'s roles. Reading and delivery do not depend on it: a tenant override that exists is served. A collection mounted without `access` is SystemAdmin only.',
48
71
  "Text an editor should be able to change belongs in a collection, declared at mount: `createTemplateResolverFeature({ collections: [{ id, kind, access: { roles }, nav }] })`. It appears in the navigation, and `access` is part of the mount because a bundled feature cannot know the host's roles. Each collection gets its own `<id>-list` / `<id>-item` / `<id>-set` handlers, so the dispatcher enforces the separation.",
49
72
  "How a collection is edited follows from `contentFormat`: `plain` gives a text area, `rich` a small WYSIWYG (bold, italic, headings, lists, links), `markdown` a text area that stores markdown text (same insertable chips as `plain`). All three offer the collection's `variableSchema` as insertable chips and a preview rendered with sample data — an editor sees what `{{firstName}}` becomes without sending a mail. An app can register its own editor for a format; the last `clientFeature` that registers a format wins (a conflict logs a warning).",
50
73
  'A collection is tenant-wide by default. With `ownership: "user"` every user keeps their own entries — mail signatures being the obvious case. Those rows live in the separate `user-content-entry` entity and count as user data, so mounting one also requires the `template-resolver-user-data` feature and a migration on the app side.',
51
74
  "`validate` dry-runs the write pipeline for a draft (sanitizer, layout rules, placeholders) and reports what the template uses and misses. `export-bundle` / `import-bundle` (and `import-bundle-system`) move one template with all locales and resource files between tenants or environments; `copy-locale` starts a translation from an existing locale. Layouts are structured: a mail or PDF layout is `data-header` / `data-content` / `data-signature` / `data-footer` regions, and mjml layout source is system-only.",
52
- "`preview` renders a draft (or the stored template) with sample values taken from the `example` of each declared variable, through the same gates and the same mail renderer as a real send, and returns subject, html, `displayHtml` (the html with cid images as data URIs for an editor), text, attachments (inline images and files) and `checks` (images resolved, plain text present, size under 10 MiB, required placeholders used); nothing is saved or sent. `send-test` mails that rendering to the calling user's own address only, subject prefixed with `[TEST]`, at most 10 per user and hour; it needs `delivery`, `channel-email` and `renderer-mail-html` to be mounted.",
75
+ "`preview` renders a draft (or the stored template) with sample values taken from the `example` of each declared variable, through the same gates and the same mail renderer as a real send, and returns subject, html, `displayHtml` (the html with cid images as data URIs for an editor), text, attachments (inline images and files) and `checks` (images resolved, plain text present, size under 10 MiB, required placeholders used); nothing is saved or sent. `send-test` mails that rendering to the calling user's own address only, subject prefixed with `[TEST]`, at most 10 per user and hour; it needs `delivery`, `channel-email` and `renderer-mail-html` to be mounted. `send-test-status` tells an editor beforehand whether that send can work for the caller (`canSend`, else `reason` `no_channel` or `no_address`), never returning the address.",
53
76
  'Images used by a template (`<img data-resource="logo">`) are uploaded with `resourceUpload`, which re-encodes them, stores a file and links it under the key; `resourceRemove` unlinks it. `linkedResources` is written only through these two handlers. With `purpose: "attachment"` and a `fileName`, `resourceUpload` stores a PDF, PNG or JPEG as a file attachment of a mail template (original bytes, at most 10) that the mail renderer attaches after the inline images. `resourceLinkPdf` instead links a `document-pdf` template under a key: every mail sent from the template then carries that PDF, rendered at send time with the mail\'s own variables and locale, under a file name pattern such as `invoice-{{number}}.pdf`; files and linked PDFs share the limit of 10.',
54
77
  "Replaces the former `text-content` feature; its blocks now live here as kind `text-block`.",
55
78
  ].join("\n\n"));
@@ -72,22 +95,23 @@ export function createTemplateResolverFeature(opts = {}) {
72
95
  r.entity({ name: "user-content-entry", ...userContentEntryEntity });
73
96
  const handlers = {
74
97
  upsertSystem: r.writeHandler(upsertSystemWrite),
75
- upsertTenant: r.writeHandler(upsertTenantWrite),
76
- publish: r.writeHandler(publishWrite),
77
- archive: r.writeHandler(archiveWrite),
78
- publishSystem: r.writeHandler(publishSystemWrite),
79
- archiveSystem: r.writeHandler(archiveSystemWrite),
80
- discardDraft: r.writeHandler(discardDraftWrite),
81
- discardDraftSystem: r.writeHandler(discardDraftSystemWrite),
82
- resetToSystem: r.writeHandler(resetToSystemWrite),
83
- set: r.writeHandler(setWrite),
84
- importBundle: r.writeHandler(importBundleWrite),
98
+ upsertTenant: r.writeHandler(makeUpsertTenantWrite(policy)),
99
+ publish: r.writeHandler(makePublishWrite(policy)),
100
+ archive: r.writeHandler(makeArchiveWrite(policy)),
101
+ publishSystem: r.writeHandler(makePublishSystemWrite(policy)),
102
+ archiveSystem: r.writeHandler(makeArchiveSystemWrite(policy)),
103
+ discardDraft: r.writeHandler(makeDiscardDraftWrite(policy)),
104
+ discardDraftSystem: r.writeHandler(makeDiscardDraftSystemWrite(policy)),
105
+ resetToSystem: r.writeHandler(makeResetToSystemWrite(policy)),
106
+ set: r.writeHandler(makeSetWrite(policy)),
107
+ importBundle: r.writeHandler(makeImportBundleWrite(policy)),
85
108
  importBundleSystem: r.writeHandler(importBundleSystemWrite),
86
- copyLocale: r.writeHandler(copyLocaleWrite),
87
- resourceUpload: r.writeHandler(resourceUploadWrite),
88
- resourceRemove: r.writeHandler(resourceRemoveWrite),
89
- resourceLinkPdf: r.writeHandler(resourceLinkPdfWrite),
90
- sendTest: r.writeHandler(sendTestWrite),
109
+ copyLocale: r.writeHandler(makeCopyLocaleWrite(policy)),
110
+ resourceUpload: r.writeHandler(makeResourceUploadWrite(policy)),
111
+ resourceRemove: r.writeHandler(makeResourceRemoveWrite(policy)),
112
+ resourceLinkPdf: r.writeHandler(makeResourceLinkPdfWrite(policy)),
113
+ sendTest: r.writeHandler(makeSendTestWrite(policy)),
114
+ patchDraft: r.writeHandler(makePatchDraftWrite(policy)),
91
115
  };
92
116
  const queries = {
93
117
  findById: r.queryHandler(findByIdQuery),
@@ -95,16 +119,21 @@ export function createTemplateResolverFeature(opts = {}) {
95
119
  bySlug: r.queryHandler(bySlugQuery),
96
120
  byTenant: r.queryHandler(byTenantQuery),
97
121
  usage: r.queryHandler(usageQuery),
98
- overview: r.queryHandler(overviewQuery),
122
+ overview: r.queryHandler(makeOverviewQuery(policy)),
99
123
  layoutSource: r.queryHandler(layoutSourceQuery),
100
124
  tenantOverrides: r.queryHandler(tenantOverridesQuery),
101
125
  diffToSystem: r.queryHandler(diffToSystemQuery),
102
126
  validate: r.queryHandler(validateQuery),
103
127
  preview: r.queryHandler(previewQuery),
128
+ documentBlocks: r.queryHandler(documentBlocksQuery),
104
129
  exportBundle: r.queryHandler(exportBundleQuery),
130
+ sendTestStatus: r.queryHandler(sendTestStatusQuery),
105
131
  };
106
132
  for (const collection of collections) {
107
- r.contentCollection(collection);
133
+ r.contentCollection({
134
+ ...collection,
135
+ access: collection.access ?? DEFAULT_COLLECTION_ACCESS,
136
+ });
108
137
  r.queryHandler(makeCollectionListQuery(collection));
109
138
  r.queryHandler(makeCollectionItemQuery(collection));
110
139
  r.writeHandler(makeCollectionSetWrite(collection));
@@ -147,6 +147,7 @@ export async function importTemplateBundle(args) {
147
147
  contentFormat: args.bundle.contentFormat,
148
148
  variableSchema,
149
149
  meta: entry.meta,
150
+ ...(entry.title !== undefined && { title: entry.title }),
150
151
  };
151
152
  const written = await writeTemplateRow({
152
153
  ctx: args.ctx,
@@ -1,7 +1,8 @@
1
1
  import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
2
2
  import { defineQueryHandler, } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import * as z from "zod";
4
- import { collectionStore, DEFAULT_COLLECTION_ACCESS, toCollectionEntry, } from "./collection-shared.js";
4
+ import { DEFAULT_COLLECTION_ACCESS } from "../constants.js";
5
+ import { collectionStore, toCollectionEntry, } from "./collection-shared.js";
5
6
  // Single entry of one collection, for the editor behind a tree node. Same
6
7
  // per-collection construction as collection-list — see there for why.
7
8
  export function makeCollectionItemQuery(collection) {
@@ -1,7 +1,8 @@
1
1
  import { castTenantRows, selectMany } from "@cosmicdrift/kumiko-framework/db";
2
2
  import { defineQueryHandler, } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import * as z from "zod";
4
- import { collectionStore, DEFAULT_COLLECTION_ACCESS, toCollectionEntry, } from "./collection-shared.js";
4
+ import { DEFAULT_COLLECTION_ACCESS } from "../constants.js";
5
+ import { collectionStore, toCollectionEntry, } from "./collection-shared.js";
5
6
  // One list handler per declared collection: `kind`, `ownership` and `access`
6
7
  // come from the declaration, never from the payload.
7
8
  //
@@ -3,9 +3,9 @@ import { defineWriteHandler, } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import { ValidationError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
4
4
  import * as z from "zod";
5
5
  import { requireForTenant } from "../../shared/index.js";
6
- import { isCollectionRefusedKind } from "../constants.js";
6
+ import { DEFAULT_COLLECTION_ACCESS, isCollectionRefusedKind } from "../constants.js";
7
7
  import { documentViolationsToFieldIssues, sanitizeTemplateBody } from "../document-sanitizer.js";
8
- import { collectionStore, DEFAULT_COLLECTION_ACCESS, } from "./collection-shared.js";
8
+ import { collectionStore } from "./collection-shared.js";
9
9
  import { contentFormatSchema, folderSchema, localeSchema, slugSchema } from "./shared.js";
10
10
  // Upsert inside one collection. Mirrors set.write for text-blocks, but the
11
11
  // kind comes from the declaration and the access rule is the collection's own,
@@ -1,9 +1,8 @@
1
1
  import type { EventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
2
- import type { AccessRule, ContentCollectionDefinition, SessionUser, TenantId } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { ContentCollectionDefinition, SessionUser, TenantId } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
4
4
  import { templateResourcesTable } from "../table.ts";
5
5
  import { userContentEntriesTable } from "../user-content-table.ts";
6
- export declare const DEFAULT_COLLECTION_ACCESS: AccessRule;
7
6
  export type CollectionEntryRow = {
8
7
  readonly id: string | number;
9
8
  readonly version: number;
@@ -2,10 +2,6 @@ import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
2
2
  import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import { templateResourceEntity, templateResourcesTable } from "../table.js";
4
4
  import { userContentEntriesTable, userContentEntryEntity } from "../user-content-table.js";
5
- // Applies when an app mounts a collection without saying who may reach it.
6
- // Deliberately narrow: a collection whose access nobody decided should be
7
- // invisible to normal users rather than open by default.
8
- export const DEFAULT_COLLECTION_ACCESS = { roles: ["TenantAdmin", "SystemAdmin"] };
9
5
  const templateExecutor = createEventStoreExecutor(templateResourcesTable, templateResourceEntity, {
10
6
  entityName: "template-resource",
11
7
  });
@@ -1,5 +1,6 @@
1
1
  import * as z from "zod";
2
- export declare const copyLocaleWrite: import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"copy-locale", z.ZodObject<{
2
+ import { type TemplateEditPolicy } from "../template-edit-policy.ts";
3
+ export declare function makeCopyLocaleWrite(policy: TemplateEditPolicy): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"copy-locale", z.ZodObject<{
3
4
  slug: z.ZodString;
4
5
  kind: z.ZodEnum<{
5
6
  "ai-prompt": "ai-prompt";
@@ -10,6 +10,7 @@ import { TemplateResolverErrors } from "../qualified-names.js";
10
10
  import { createLinkedResourceCopies, prepareLinkedResourceCopiesBeforeTransaction, } from "../store-template-resource.js";
11
11
  import { templateResourcesTable } from "../table.js";
12
12
  import { toWorkingRow } from "../template-draft.js";
13
+ import { refuseTemplateEdit, templateEditAccess, } from "../template-edit-policy.js";
13
14
  import { attachTemplateResources } from "../template-resources.js";
14
15
  import { resolveTemplateVariables } from "../template-validation.js";
15
16
  import { targetExistsIssue } from "./bundle-import.js";
@@ -50,7 +51,7 @@ const copyLocaleSchema = z.object({
50
51
  scope: z.enum(["tenant", "system"]).default("tenant"),
51
52
  });
52
53
  // Runs before the upload (reject early, store nothing) and again in the transaction on the fresh rows.
53
- async function checkCopyRequest(ctx, event) {
54
+ async function checkCopyRequest(ctx, policy, event) {
54
55
  const { slug, kind, fromLocale, toLocale, overwrite, scope } = event.payload;
55
56
  if (scope === "system" && !event.user.roles.includes("SystemAdmin")) {
56
57
  return writeFailure(new AccessDeniedError({
@@ -59,7 +60,8 @@ async function checkCopyRequest(ctx, event) {
59
60
  }));
60
61
  }
61
62
  const tenantId = scope === "system" ? SYSTEM_TENANT_ID : event.user.tenantId;
62
- const refused = refuseTenantScopeUnderSystemTenant(scope, tenantId) ??
63
+ const refused = (scope === "tenant" ? refuseTemplateEdit(policy, event.user, { slug, kind }) : null) ??
64
+ refuseTenantScopeUnderSystemTenant(scope, tenantId) ??
63
65
  refuseSystemOnlyTenantOverride(ctx.registry, scope, slug, kind);
64
66
  if (refused !== null)
65
67
  return refused;
@@ -99,65 +101,67 @@ async function checkCopyRequest(ctx, event) {
99
101
  },
100
102
  };
101
103
  }
102
- export const copyLocaleWrite = defineWriteHandler({
103
- name: "copy-locale",
104
- schema: copyLocaleSchema,
105
- access: { roles: ["TenantAdmin", "SystemAdmin"] },
106
- description: "Copies the text of one locale of a template into another locale as a draft override of the caller's tenant, taking the tenant's own row or else the system default as the source; use it as the starting point for a translation. It refuses an existing target unless overwrite is set. With scope system (SystemAdmin only) both source and target are system-default rows and the target lands as a system draft; any other caller gets a 403.",
107
- beforeTransaction: async (event, ctx) => {
108
- const request = await checkCopyRequest(ctx, event);
109
- if (!request.isSuccess)
110
- return request;
111
- if (!request.data.sourceIsForeign)
112
- return { isSuccess: true, data: [] };
113
- return prepareLinkedResourceCopiesBeforeTransaction({
114
- ctx,
115
- user: event.user,
116
- tenantId: request.data.tenantId,
117
- resources: request.data.sourceResources,
118
- });
119
- },
120
- handler: async (event, ctx) => {
121
- const { slug, kind, toLocale } = event.payload;
122
- const request = await checkCopyRequest(ctx, event);
123
- if (!request.isSuccess)
124
- return request;
125
- const { scope, tenantId, source, contentFormat, sourceResources, sourceIsForeign } = request.data;
126
- const variableSchema = storedRecord(source.variableSchema);
127
- const written = await writeTemplateRow({
128
- ctx,
129
- user: event.user,
130
- tenantId,
131
- scope,
132
- status: "draft",
133
- variables: resolveTemplateVariables(ctx.registry, slug, variableSchema),
134
- payload: {
135
- slug,
136
- kind,
137
- locale: toLocale,
138
- content: source.content,
139
- contentFormat,
140
- variableSchema,
141
- meta: parseStoredJson(source.meta),
142
- title: source.title,
143
- folder: source.folder,
144
- },
145
- });
146
- if (!written.isSuccess)
104
+ export function makeCopyLocaleWrite(policy) {
105
+ return defineWriteHandler({
106
+ name: "copy-locale",
107
+ schema: copyLocaleSchema,
108
+ access: templateEditAccess(policy.tenantEditable),
109
+ description: "Copies the text of one locale of a template into another locale as a draft override of the caller's tenant, taking the tenant's own row or else the system default as the source; use it as the starting point for a translation. It refuses an existing target unless overwrite is set. With scope system (SystemAdmin only) both source and target are system-default rows and the target lands as a system draft; any other caller gets a 403. A TenantAdmin may copy only templates the app lists in tenantEditable, otherwise SystemAdmin only.",
110
+ beforeTransaction: async (event, ctx) => {
111
+ const request = await checkCopyRequest(ctx, policy, event);
112
+ if (!request.isSuccess)
113
+ return request;
114
+ if (!request.data.sourceIsForeign)
115
+ return { isSuccess: true, data: [] };
116
+ return prepareLinkedResourceCopiesBeforeTransaction({
117
+ ctx,
118
+ user: event.user,
119
+ tenantId: request.data.tenantId,
120
+ resources: request.data.sourceResources,
121
+ });
122
+ },
123
+ handler: async (event, ctx) => {
124
+ const { slug, kind, toLocale } = event.payload;
125
+ const request = await checkCopyRequest(ctx, policy, event);
126
+ if (!request.isSuccess)
127
+ return request;
128
+ const { scope, tenantId, source, contentFormat, sourceResources, sourceIsForeign } = request.data;
129
+ const variableSchema = storedRecord(source.variableSchema);
130
+ const written = await writeTemplateRow({
131
+ ctx,
132
+ user: event.user,
133
+ tenantId,
134
+ scope,
135
+ status: "draft",
136
+ variables: resolveTemplateVariables(ctx.registry, slug, variableSchema),
137
+ payload: {
138
+ slug,
139
+ kind,
140
+ locale: toLocale,
141
+ content: source.content,
142
+ contentFormat,
143
+ variableSchema,
144
+ meta: parseStoredJson(source.meta),
145
+ title: source.title,
146
+ folder: source.folder,
147
+ },
148
+ });
149
+ if (!written.isSuccess)
150
+ return written;
151
+ const resources = sourceIsForeign
152
+ ? await createLinkedResourceCopies({ ctx, user: event.user, tenantId }, event.prepared)
153
+ : { isSuccess: true, data: sourceResources };
154
+ if (!resources.isSuccess)
155
+ return resources;
156
+ const attached = await attachTemplateResources(ctx, {
157
+ user: event.user,
158
+ tenantId,
159
+ templateId: written.data.id,
160
+ resources: resources.data,
161
+ });
162
+ if (!attached.isSuccess)
163
+ return attached;
147
164
  return written;
148
- const resources = sourceIsForeign
149
- ? await createLinkedResourceCopies({ ctx, user: event.user, tenantId }, event.prepared)
150
- : { isSuccess: true, data: sourceResources };
151
- if (!resources.isSuccess)
152
- return resources;
153
- const attached = await attachTemplateResources(ctx, {
154
- user: event.user,
155
- tenantId,
156
- templateId: written.data.id,
157
- resources: resources.data,
158
- });
159
- if (!attached.isSuccess)
160
- return attached;
161
- return written;
162
- },
163
- });
165
+ },
166
+ });
167
+ }
@@ -1,11 +1,12 @@
1
1
  import * as z from "zod";
2
- export declare const discardDraftWrite: import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<string, z.ZodObject<{
2
+ import { type TemplateEditPolicy } from "../template-edit-policy.ts";
3
+ export declare function makeDiscardDraftWrite(policy: TemplateEditPolicy): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<string, z.ZodObject<{
3
4
  id: z.ZodString;
4
5
  }, z.core.$strip>, {
5
6
  id: string;
6
7
  discarded: boolean;
7
8
  }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap, undefined>;
8
- export declare const discardDraftSystemWrite: import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<string, z.ZodObject<{
9
+ export declare function makeDiscardDraftSystemWrite(policy: TemplateEditPolicy): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<string, z.ZodObject<{
9
10
  id: z.ZodString;
10
11
  }, z.core.$strip>, {
11
12
  id: string;
@@ -2,19 +2,27 @@ import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
2
2
  import { NotFoundError, ValidationError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
3
3
  import * as z from "zod";
4
4
  import { TemplateResolverErrors } from "../qualified-names.js";
5
+ import { refuseMissingTemplate, refuseTemplateEdit, } from "../template-edit-policy.js";
5
6
  import { executor } from "./shared.js";
6
7
  import { loadTargetRow, writeAccessFor } from "./toggle-status.write.js";
7
- function createDiscardDraftHandler(name, target, description) {
8
+ function createDiscardDraftHandler(policy, name, target, description) {
8
9
  return defineWriteHandler({
9
10
  name,
10
11
  schema: z.object({ id: z.string().min(1) }),
11
- access: writeAccessFor(target),
12
+ access: writeAccessFor(target, policy),
12
13
  ...(target === "system" ? { agent: { risk: "high" } } : {}),
13
14
  description,
14
15
  handler: async (event, ctx) => {
15
16
  const { db, scoped, row } = await loadTargetRow(ctx, target, event.user, event.payload.id);
16
- if (!row)
17
- return writeFailure(new NotFoundError("template-resource", event.payload.id));
17
+ if (!row) {
18
+ const refused = target === "own" ? refuseMissingTemplate(policy, event.user) : null;
19
+ return refused ?? writeFailure(new NotFoundError("template-resource", event.payload.id));
20
+ }
21
+ if (target === "own") {
22
+ const refused = refuseTemplateEdit(policy, event.user, row);
23
+ if (refused !== null)
24
+ return refused;
25
+ }
18
26
  if (row.draft === null) {
19
27
  return writeFailure(new ValidationError({
20
28
  fields: [
@@ -33,5 +41,9 @@ function createDiscardDraftHandler(name, target, description) {
33
41
  },
34
42
  });
35
43
  }
36
- export const discardDraftWrite = createDiscardDraftHandler("discard-draft", "own", "Throws away the open draft of one template resource of the caller's tenant so the editor shows the active version again; the served version is untouched. Refused with no_draft when there is no draft.");
37
- export const discardDraftSystemWrite = createDiscardDraftHandler("discard-draft-system", "system", "Throws away the open draft of one system-default template; the served version stays. SystemAdmin only, refused with no_draft when there is no draft.");
44
+ export function makeDiscardDraftWrite(policy) {
45
+ return createDiscardDraftHandler(policy, "discard-draft", "own", "Throws away the open draft of one template resource of the caller's tenant so the editor shows the active version again; the served version is untouched. Refused with no_draft when there is no draft. Outside the templates the app lists in tenantEditable only a SystemAdmin may use it.");
46
+ }
47
+ export function makeDiscardDraftSystemWrite(policy) {
48
+ return createDiscardDraftHandler(policy, "discard-draft-system", "system", "Throws away the open draft of one system-default template; the served version stays. SystemAdmin only, refused with no_draft when there is no draft.");
49
+ }
@@ -0,0 +1,23 @@
1
+ import { type HandlerContext, type SessionUser } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { DocumentHtmlKind } from "../constants.ts";
3
+ export type DocumentBase = {
4
+ readonly scope: "tenant" | "system";
5
+ /** The stored row's own version, which counts every draft save. */
6
+ readonly version: number;
7
+ };
8
+ export type LoadedDocument = {
9
+ readonly rowId: string;
10
+ readonly base: DocumentBase;
11
+ readonly status: string;
12
+ readonly content: string;
13
+ readonly meta: Readonly<Record<string, unknown>>;
14
+ readonly variableSchema: Readonly<Record<string, unknown>>;
15
+ readonly title: string | null;
16
+ readonly folder: string | null;
17
+ readonly parentTemplateId: string | null;
18
+ };
19
+ export declare function loadDocumentBase(ctx: HandlerContext, user: SessionUser, where: {
20
+ readonly slug: string;
21
+ readonly kind: DocumentHtmlKind;
22
+ readonly locale: string;
23
+ }): Promise<LoadedDocument | null>;
@@ -0,0 +1,55 @@
1
+ import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
2
+ import { SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
4
+ import { templateResourcesTable } from "../table.js";
5
+ import { isHiddenSystemDraft, toWorkingRow } from "../template-draft.js";
6
+ import { isSystemOnlyTemplateHiddenFrom } from "../template-system-only.js";
7
+ import { parseStoredJson } from "./template-gates.js";
8
+ function recordOrEmpty(raw) {
9
+ const parsed = parseStoredJson(raw);
10
+ return isPlainObject(parsed) ? parsed : {};
11
+ }
12
+ // The version an editor works on: the caller's own row (its open draft if there is one),
13
+ // else the served system default. A system default as base is what a patch copies into a tenant draft.
14
+ export async function loadDocumentBase(ctx, user, where) {
15
+ const own = await fetchOne(ctx.db, templateResourcesTable, {
16
+ tenantId: user.tenantId,
17
+ ...where,
18
+ });
19
+ if (own !== undefined && !isSystemOnlyTemplateHiddenFrom(user, ctx.registry, own)) {
20
+ const working = toWorkingRow(own, user.tenantId);
21
+ return {
22
+ rowId: String(own.id),
23
+ base: { scope: own.scope === "system" ? "system" : "tenant", version: own.version },
24
+ status: working.status,
25
+ content: working.content ?? "",
26
+ meta: recordOrEmpty(working.meta),
27
+ variableSchema: recordOrEmpty(working.variableSchema),
28
+ title: working.title,
29
+ folder: working.folder,
30
+ parentTemplateId: working.parentTemplateId,
31
+ };
32
+ }
33
+ const system = await fetchOne(ctx.db, templateResourcesTable, {
34
+ tenantId: SYSTEM_TENANT_ID,
35
+ scope: "system",
36
+ status: "active",
37
+ ...where,
38
+ });
39
+ if (system === undefined ||
40
+ isHiddenSystemDraft(user, system) ||
41
+ isSystemOnlyTemplateHiddenFrom(user, ctx.registry, system)) {
42
+ return null;
43
+ }
44
+ return {
45
+ rowId: String(system.id),
46
+ base: { scope: "system", version: system.version },
47
+ status: system.status,
48
+ content: system.content ?? "",
49
+ meta: recordOrEmpty(system.meta),
50
+ variableSchema: recordOrEmpty(system.variableSchema),
51
+ title: system.title,
52
+ folder: system.folder,
53
+ parentTemplateId: String(system.id),
54
+ };
55
+ }
@@ -0,0 +1,22 @@
1
+ import * as z from "zod";
2
+ export declare const documentBlocksQuery: import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"document-blocks", z.ZodObject<{
3
+ slug: z.ZodString;
4
+ kind: z.ZodEnum<{
5
+ "document-pdf": "document-pdf";
6
+ mail: "mail";
7
+ }>;
8
+ locale: z.ZodString;
9
+ }, z.core.$strip>, {
10
+ slug: string;
11
+ kind: "document-pdf" | "mail";
12
+ locale: string;
13
+ base: import("./document-base.ts").DocumentBase;
14
+ status: string;
15
+ blocks: import("../document-ops.ts").DocumentBlock[];
16
+ meta: Readonly<Record<string, unknown>>;
17
+ variableSchema: Readonly<Record<string, unknown>>;
18
+ variables: Readonly<Record<string, import("@cosmicdrift/kumiko-types/config").TemplateVariableDef>>;
19
+ variablesDeclaredByFeature: boolean;
20
+ allowedBlocks: readonly import("../document-blocks.ts").DocumentToolbarBlock[];
21
+ resourceKeys: string[];
22
+ }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;