@cossackframework/cms 0.0.0-stage → 0.9.1

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 (427) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/agent-docs.json +259 -0
  4. package/app/README.md +78 -0
  5. package/app/cossack-recipe.json +43 -0
  6. package/app/src/auth-bot-check.ts +32 -0
  7. package/app/src/auth-bot-token.ts +11 -0
  8. package/app/src/auth-input.ts +35 -0
  9. package/app/src/auth-options.ts +18 -0
  10. package/app/src/auth-providers.ts +16 -0
  11. package/app/src/auth.ts +1082 -0
  12. package/app/src/brand.ts +68 -0
  13. package/app/src/cms/ai.ts +54 -0
  14. package/app/src/cms/analytics.ts +33 -0
  15. package/app/src/cms/block-errors.ts +55 -0
  16. package/app/src/cms/block-inserter.ts +111 -0
  17. package/app/src/cms/block-panel.ts +68 -0
  18. package/app/src/cms/block-rows.ts +44 -0
  19. package/app/src/cms/block-tree.ts +585 -0
  20. package/app/src/cms/blocks.css +708 -0
  21. package/app/src/cms/builder.ts +126 -0
  22. package/app/src/cms/cache.ts +44 -0
  23. package/app/src/cms/carousel.client.ts +52 -0
  24. package/app/src/cms/collab/presence.ts +69 -0
  25. package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
  26. package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
  27. package/app/src/cms/collab/room.ts +881 -0
  28. package/app/src/cms/compare.client.ts +47 -0
  29. package/app/src/cms/condition-control.ts +109 -0
  30. package/app/src/cms/content-api.ts +143 -0
  31. package/app/src/cms/content.ts +524 -0
  32. package/app/src/cms/countdown.client.ts +37 -0
  33. package/app/src/cms/editor-layout-editor.ts +260 -0
  34. package/app/src/cms/editor-layout-view.ts +37 -0
  35. package/app/src/cms/editor.ts +381 -0
  36. package/app/src/cms/entry.ts +26 -0
  37. package/app/src/cms/feeds.ts +145 -0
  38. package/app/src/cms/field-controls.ts +222 -0
  39. package/app/src/cms/field-group-editor.ts +105 -0
  40. package/app/src/cms/field-group-view.ts +211 -0
  41. package/app/src/cms/form-view.ts +203 -0
  42. package/app/src/cms/form.client.ts +203 -0
  43. package/app/src/cms/guards.ts +27 -0
  44. package/app/src/cms/handoff.ts +202 -0
  45. package/app/src/cms/headings.ts +51 -0
  46. package/app/src/cms/icons.ts +80 -0
  47. package/app/src/cms/import.client.ts +16 -0
  48. package/app/src/cms/index.ts +191 -0
  49. package/app/src/cms/lightbox.client.ts +109 -0
  50. package/app/src/cms/machine.ts +118 -0
  51. package/app/src/cms/maintenance.ts +97 -0
  52. package/app/src/cms/manage.ts +1236 -0
  53. package/app/src/cms/mcp-tools.ts +388 -0
  54. package/app/src/cms/mcp.ts +242 -0
  55. package/app/src/cms/media-chooser.ts +123 -0
  56. package/app/src/cms/media-usage.ts +57 -0
  57. package/app/src/cms/middleware.ts +199 -0
  58. package/app/src/cms/middlewares.ts +13 -0
  59. package/app/src/cms/network-ui.ts +36 -0
  60. package/app/src/cms/network-view.ts +38 -0
  61. package/app/src/cms/notes-announce.ts +65 -0
  62. package/app/src/cms/notes-rail.ts +207 -0
  63. package/app/src/cms/notification-rules.ts +66 -0
  64. package/app/src/cms/recovery.ts +82 -0
  65. package/app/src/cms/replace.ts +63 -0
  66. package/app/src/cms/reserved-paths.ts +19 -0
  67. package/app/src/cms/rich-text-field.ts +325 -0
  68. package/app/src/cms/rich-text-schema.ts +91 -0
  69. package/app/src/cms/rich-text.client.ts +255 -0
  70. package/app/src/cms/search.client.ts +116 -0
  71. package/app/src/cms/seo-head.ts +78 -0
  72. package/app/src/cms/seo.ts +241 -0
  73. package/app/src/cms/settings-draft.ts +218 -0
  74. package/app/src/cms/settings-file.ts +127 -0
  75. package/app/src/cms/settings-form.ts +180 -0
  76. package/app/src/cms/settings-languages.ts +125 -0
  77. package/app/src/cms/settings-nav.ts +102 -0
  78. package/app/src/cms/settings-network.ts +151 -0
  79. package/app/src/cms/settings-permalinks.ts +114 -0
  80. package/app/src/cms/settings-scroll.ts +10 -0
  81. package/app/src/cms/settings-search.ts +77 -0
  82. package/app/src/cms/settings-section.ts +38 -0
  83. package/app/src/cms/share.client.ts +27 -0
  84. package/app/src/cms/site-editing.ts +219 -0
  85. package/app/src/cms/site-editor.client.ts +1008 -0
  86. package/app/src/cms/site-editor.ts +99 -0
  87. package/app/src/cms/site-export.ts +60 -0
  88. package/app/src/cms/site-forms.ts +143 -0
  89. package/app/src/cms/site-import.ts +28 -0
  90. package/app/src/cms/site-session.ts +36 -0
  91. package/app/src/cms/site-taskbar.ts +77 -0
  92. package/app/src/cms/site-view.ts +1014 -0
  93. package/app/src/cms/site.ts +1322 -0
  94. package/app/src/cms/sitemaps.ts +131 -0
  95. package/app/src/cms/stat.client.ts +56 -0
  96. package/app/src/cms/style-controls.ts +252 -0
  97. package/app/src/cms/tabs.client.ts +36 -0
  98. package/app/src/cms/taskbar.ts +134 -0
  99. package/app/src/cms/term-icons.ts +10 -0
  100. package/app/src/cms/traffic.ts +26 -0
  101. package/app/src/cms/ui.ts +170 -0
  102. package/app/src/cms/updates.ts +124 -0
  103. package/app/src/cms/uploads.ts +26 -0
  104. package/app/src/cms/worker.ts +13 -0
  105. package/app/src/config/auth.ts +30 -0
  106. package/app/src/config/cms.ts +18 -0
  107. package/app/src/dashboard/access.ts +344 -0
  108. package/app/src/dashboard/agent-icons.ts +44 -0
  109. package/app/src/dashboard/app-passwords.ts +74 -0
  110. package/app/src/dashboard/avatar-field.ts +58 -0
  111. package/app/src/dashboard/bulk.ts +53 -0
  112. package/app/src/dashboard/head.ts +29 -0
  113. package/app/src/dashboard/icons.ts +15 -0
  114. package/app/src/dashboard/list-table.ts +120 -0
  115. package/app/src/dashboard/modules/roles.ts +15 -0
  116. package/app/src/dashboard/modules/sessions.ts +15 -0
  117. package/app/src/dashboard/modules/settings.ts +15 -0
  118. package/app/src/dashboard/modules/users.ts +18 -0
  119. package/app/src/dashboard/page.ts +67 -0
  120. package/app/src/dashboard/registry.ts +13 -0
  121. package/app/src/dashboard/session-list.ts +98 -0
  122. package/app/src/dashboard/tabs.ts +26 -0
  123. package/app/src/dashboard/time-ago.ts +16 -0
  124. package/app/src/dashboard/types.ts +40 -0
  125. package/app/src/dashboard/user-sections.ts +172 -0
  126. package/app/src/lib/permissions.ts +84 -0
  127. package/app/src/middlewares/auth.ts +117 -0
  128. package/app/src/pages/(site)/[...path]/index.ts +609 -0
  129. package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
  130. package/app/src/pages/(site)/feed/index.ts +12 -0
  131. package/app/src/pages/(site)/index.ts +11 -0
  132. package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
  133. package/app/src/pages/(site)/layout.ts +219 -0
  134. package/app/src/pages/(site)/llms.txt/index.ts +23 -0
  135. package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
  136. package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
  137. package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
  138. package/app/src/pages/(site)/robots.txt/index.ts +29 -0
  139. package/app/src/pages/(site)/search/index.ts +36 -0
  140. package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
  141. package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
  142. package/app/src/pages/api/auth/session.ts +48 -0
  143. package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
  144. package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
  145. package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
  146. package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
  147. package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
  148. package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
  149. package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
  150. package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
  151. package/app/src/pages/api/cms/cache/purge.ts +6 -0
  152. package/app/src/pages/api/cms/collections/index.ts +6 -0
  153. package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
  154. package/app/src/pages/api/cms/comments/[id].ts +9 -0
  155. package/app/src/pages/api/cms/comments/index.ts +126 -0
  156. package/app/src/pages/api/cms/comments/queue.ts +6 -0
  157. package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
  158. package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
  159. package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
  160. package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
  161. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
  162. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
  163. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
  164. package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
  165. package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
  166. package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
  167. package/app/src/pages/api/cms/export/[collection].ts +37 -0
  168. package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
  169. package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
  170. package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
  171. package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
  172. package/app/src/pages/api/cms/import/[collection].ts +23 -0
  173. package/app/src/pages/api/cms/mcp.ts +29 -0
  174. package/app/src/pages/api/cms/me/index.ts +6 -0
  175. package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
  176. package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
  177. package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
  178. package/app/src/pages/api/cms/media/[id].ts +6 -0
  179. package/app/src/pages/api/cms/media.ts +26 -0
  180. package/app/src/pages/api/cms/menus/[location].ts +14 -0
  181. package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
  182. package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
  183. package/app/src/pages/api/cms/network/sites/index.ts +14 -0
  184. package/app/src/pages/api/cms/notes/[id].ts +13 -0
  185. package/app/src/pages/api/cms/notes/index.ts +6 -0
  186. package/app/src/pages/api/cms/payments/webhook.ts +28 -0
  187. package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
  188. package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
  189. package/app/src/pages/api/cms/plugins/index.ts +6 -0
  190. package/app/src/pages/api/cms/recovery.ts +29 -0
  191. package/app/src/pages/api/cms/redirects/index.ts +9 -0
  192. package/app/src/pages/api/cms/roles/index.ts +6 -0
  193. package/app/src/pages/api/cms/schema/[collection].ts +13 -0
  194. package/app/src/pages/api/cms/search.ts +16 -0
  195. package/app/src/pages/api/cms/settings/[group].ts +9 -0
  196. package/app/src/pages/api/cms/settings/index.ts +9 -0
  197. package/app/src/pages/api/cms/site-export.ts +34 -0
  198. package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
  199. package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
  200. package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
  201. package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
  202. package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
  203. package/app/src/pages/api/cms/uploads/index.ts +26 -0
  204. package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
  205. package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
  206. package/app/src/pages/api/cms/users/index.ts +12 -0
  207. package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
  208. package/app/src/pages/api/cms/webhooks/index.ts +9 -0
  209. package/app/src/pages/auth/[provider]/callback.ts +11 -0
  210. package/app/src/pages/auth/[provider]/redirect.ts +9 -0
  211. package/app/src/pages/auth/forgot-password/index.ts +75 -0
  212. package/app/src/pages/auth/layout.ts +32 -0
  213. package/app/src/pages/auth/login/index.ts +198 -0
  214. package/app/src/pages/auth/magic/index.ts +68 -0
  215. package/app/src/pages/auth/register/index.ts +117 -0
  216. package/app/src/pages/auth/reset-password/index.ts +65 -0
  217. package/app/src/pages/auth/setup/index.ts +194 -0
  218. package/app/src/pages/auth/two-factor/index.ts +67 -0
  219. package/app/src/pages/auth/verify/index.ts +62 -0
  220. package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
  221. package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
  222. package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
  223. package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
  224. package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
  225. package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
  226. package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
  227. package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
  228. package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
  229. package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
  230. package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
  231. package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
  232. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
  233. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
  234. package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
  235. package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
  236. package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
  237. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
  238. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
  239. package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
  240. package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
  241. package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
  242. package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
  243. package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
  244. package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
  245. package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
  246. package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
  247. package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
  248. package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
  249. package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
  250. package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
  251. package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
  252. package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
  253. package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
  254. package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
  255. package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
  256. package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
  257. package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
  258. package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
  259. package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
  260. package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
  261. package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
  262. package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
  263. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
  264. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
  265. package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
  266. package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
  267. package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
  268. package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
  269. package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
  270. package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
  271. package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
  272. package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
  273. package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
  274. package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
  275. package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
  276. package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
  277. package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
  278. package/app/src/pages/dashboard/index.ts +214 -0
  279. package/app/src/pages/dashboard/layout.ts +320 -0
  280. package/app/src/pages/dashboard/profile/index.ts +211 -0
  281. package/app/src/pages/dashboard/profile/security/index.ts +255 -0
  282. package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
  283. package/app/src/pages/dashboard/roles/index.ts +134 -0
  284. package/app/src/pages/dashboard/roles/new/index.ts +95 -0
  285. package/app/src/pages/dashboard/sessions/index.ts +105 -0
  286. package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
  287. package/app/src/pages/dashboard/users/index.ts +299 -0
  288. package/app/src/pages/dashboard/users/new/index.ts +123 -0
  289. package/app/src/passkeys.client.ts +18 -0
  290. package/app/src/plugins/default-theme/assets/cover.svg +31 -0
  291. package/app/src/plugins/default-theme/assets/logo.svg +8 -0
  292. package/app/src/plugins/default-theme/parts/comments.ts +66 -0
  293. package/app/src/plugins/default-theme/parts/list.ts +38 -0
  294. package/app/src/plugins/default-theme/parts/media.ts +15 -0
  295. package/app/src/plugins/default-theme/parts/options.ts +45 -0
  296. package/app/src/plugins/default-theme/plugin.json +275 -0
  297. package/app/src/plugins/default-theme/templates/archive.ts +14 -0
  298. package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
  299. package/app/src/plugins/default-theme/templates/entry.ts +27 -0
  300. package/app/src/plugins/default-theme/templates/home.ts +8 -0
  301. package/app/src/plugins/default-theme/templates/layout.ts +40 -0
  302. package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
  303. package/app/src/plugins/default-theme/templates/search.ts +32 -0
  304. package/app/src/services/rbac.ts +65 -0
  305. package/app/src/services/roles.ts +89 -0
  306. package/app/src/services/users.ts +173 -0
  307. package/package.json +123 -3
  308. package/src/automations.ts +95 -0
  309. package/src/bindings.ts +138 -0
  310. package/src/block-references.ts +239 -0
  311. package/src/block-shape.ts +155 -0
  312. package/src/blocks.ts +1157 -0
  313. package/src/cache.ts +54 -0
  314. package/src/checks.ts +198 -0
  315. package/src/cloudflare-workers.d.ts +13 -0
  316. package/src/cloudflare.ts +61 -0
  317. package/src/collab.ts +372 -0
  318. package/src/collections.ts +421 -0
  319. package/src/comments.ts +46 -0
  320. package/src/cron.ts +95 -0
  321. package/src/dashboard-menu.ts +105 -0
  322. package/src/diff.ts +113 -0
  323. package/src/editor-layout.ts +316 -0
  324. package/src/errors.ts +50 -0
  325. package/src/field-groups.ts +498 -0
  326. package/src/fields.ts +411 -0
  327. package/src/form-builder.ts +1053 -0
  328. package/src/forms.ts +109 -0
  329. package/src/highlight.ts +134 -0
  330. package/src/hooks.ts +510 -0
  331. package/src/icon-catalog.ts +55 -0
  332. package/src/icons.ts +128 -0
  333. package/src/images.ts +149 -0
  334. package/src/index.ts +100 -0
  335. package/src/isolate-core.ts +245 -0
  336. package/src/isolate.ts +19 -0
  337. package/src/isolation.ts +69 -0
  338. package/src/mail.ts +182 -0
  339. package/src/manifest.ts +476 -0
  340. package/src/media.ts +193 -0
  341. package/src/menus.ts +287 -0
  342. package/src/module.ts +32 -0
  343. package/src/modules/content.ts +64 -0
  344. package/src/modules/forms.ts +35 -0
  345. package/src/node.ts +66 -0
  346. package/src/notes.ts +237 -0
  347. package/src/permissions.ts +139 -0
  348. package/src/plugin-settings.ts +114 -0
  349. package/src/records.ts +56 -0
  350. package/src/redirects.ts +59 -0
  351. package/src/resource.ts +245 -0
  352. package/src/richtext.ts +402 -0
  353. package/src/schema-json.ts +112 -0
  354. package/src/search.ts +89 -0
  355. package/src/seo.ts +477 -0
  356. package/src/server/accounts.ts +418 -0
  357. package/src/server/ai.ts +33 -0
  358. package/src/server/api-tokens.ts +91 -0
  359. package/src/server/areas.ts +116 -0
  360. package/src/server/audit.ts +94 -0
  361. package/src/server/auth.ts +89 -0
  362. package/src/server/automations.ts +190 -0
  363. package/src/server/autosaves.ts +69 -0
  364. package/src/server/brand-icons.ts +50 -0
  365. package/src/server/brands.ts +86 -0
  366. package/src/server/budget.ts +97 -0
  367. package/src/server/cache.ts +104 -0
  368. package/src/server/capabilities.ts +333 -0
  369. package/src/server/cloudflare.ts +92 -0
  370. package/src/server/comments.ts +237 -0
  371. package/src/server/drafts.ts +176 -0
  372. package/src/server/field-groups.ts +88 -0
  373. package/src/server/files.ts +780 -0
  374. package/src/server/forms.ts +726 -0
  375. package/src/server/handoffs.ts +107 -0
  376. package/src/server/host-schema.ts +312 -0
  377. package/src/server/host.ts +2892 -0
  378. package/src/server/images.ts +34 -0
  379. package/src/server/index.ts +59 -0
  380. package/src/server/indexnow.ts +91 -0
  381. package/src/server/isolation.ts +183 -0
  382. package/src/server/locked.ts +45 -0
  383. package/src/server/mail.ts +93 -0
  384. package/src/server/markdown.ts +24 -0
  385. package/src/server/menus.ts +286 -0
  386. package/src/server/network-policy.ts +60 -0
  387. package/src/server/network.ts +665 -0
  388. package/src/server/notes.ts +275 -0
  389. package/src/server/outbox.ts +213 -0
  390. package/src/server/path-moves.ts +33 -0
  391. package/src/server/payments.ts +59 -0
  392. package/src/server/previews.ts +62 -0
  393. package/src/server/purge.ts +140 -0
  394. package/src/server/reconcile.ts +38 -0
  395. package/src/server/redirects.ts +183 -0
  396. package/src/server/repository.ts +1107 -0
  397. package/src/server/schedules.ts +105 -0
  398. package/src/server/schema.ts +562 -0
  399. package/src/server/security.ts +391 -0
  400. package/src/server/seed.ts +52 -0
  401. package/src/server/shared-fields.ts +34 -0
  402. package/src/server/site-export.ts +151 -0
  403. package/src/server/site-import.ts +482 -0
  404. package/src/server/site-search.ts +289 -0
  405. package/src/server/site-settings.ts +286 -0
  406. package/src/server/sites.ts +243 -0
  407. package/src/server/stores.ts +314 -0
  408. package/src/server/stripe.ts +173 -0
  409. package/src/server/taxonomies.ts +415 -0
  410. package/src/server/tokens.ts +25 -0
  411. package/src/server/traffic.ts +118 -0
  412. package/src/server/users.ts +653 -0
  413. package/src/server/webhooks.ts +245 -0
  414. package/src/settings-controls.ts +54 -0
  415. package/src/settings-document.ts +111 -0
  416. package/src/settings.ts +426 -0
  417. package/src/storage/cloudflare.ts +94 -0
  418. package/src/storage/index.ts +30 -0
  419. package/src/storage/node.ts +114 -0
  420. package/src/taxonomy.ts +51 -0
  421. package/src/theme.ts +1135 -0
  422. package/src/to-markdown.ts +179 -0
  423. package/src/updates.ts +126 -0
  424. package/src/version.ts +2 -0
  425. package/src/vite.d.ts +25 -0
  426. package/src/vite.js +199 -0
  427. package/src/webhooks.ts +107 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The network pages' server helpers. They reach the CMS host through `./index`, which the client
3
+ * gets as stubs: call them from `init()` and `post()`, never from `render()` or `@Page` options.
4
+ * The guard is `requireNetworkAdmin` in `./guards`; render helpers are in `./network-view`.
5
+ */
6
+ import type { Context } from 'hono';
7
+ import { MAIN_SITE, type CmsHost, type CmsNetwork, type NetworkSite } from '@cossackframework/cms/server';
8
+ import { networkFor, siteUrl, type CmsBindings } from './index';
9
+
10
+ export function network(c: Context): CmsNetwork {
11
+ return networkFor(c.env as CmsBindings);
12
+ }
13
+
14
+ /** Site names by ID: the main site's title, and each added site's registry name. */
15
+ export async function siteNames(c: Context, ids: Iterable<string>): Promise<Map<string, string>> {
16
+ const net = network(c);
17
+ const names = new Map<string, string>();
18
+ for (const id of new Set(ids)) {
19
+ names.set(id, id === MAIN_SITE ? (await net.main.settings.get('general.siteTitle').catch(() => '')) || __('Main site') : (await net.sites.get(id))?.name ?? id);
20
+ }
21
+ return names;
22
+ }
23
+
24
+ /** A site's icon (Settings → General → Site icon) as a URL a page on another host can load; empty when it has none. */
25
+ export async function siteIconUrl(c: Context, host: CmsHost, site: Pick<NetworkSite, 'host'>): Promise<string> {
26
+ const icon = await host.settings.get('general.favicon').catch(() => '');
27
+ if (!icon || /^https?:\/\//.test(icon)) return icon;
28
+ // A library file is served by its own site.
29
+ return `${siteLinks(c, site).home.replace(/\/$/, '')}${icon}`;
30
+ }
31
+
32
+ /** A site's dashboard and home page. */
33
+ export function siteLinks(c: Context, site: Pick<NetworkSite, 'host'>): { home: string; dashboard: string } {
34
+ const home = (siteUrl(c.env as CmsBindings, site) ?? '').replace(/\/$/, '');
35
+ return { home: home || '/', dashboard: `${home}/dashboard` };
36
+ }
@@ -0,0 +1,38 @@
1
+ /** Render helpers for the network pages; client-safe, unlike `./network-ui`. */
2
+ import type { SiteStatus } from '@cossackframework/cms/server';
3
+ import { component, html, type TemplateResult } from '@cossackframework/renderer';
4
+ import { Button, Field, Icon, Input } from '@cossackframework/ui';
5
+ import { icon } from './icons';
6
+
7
+ const STATUS: Record<SiteStatus, string> = { creating: 'Being created', active: 'Active', archived: 'Archived', deleted: 'Deleted' };
8
+
9
+ export function siteStatus(status: SiteStatus): TemplateResult {
10
+ const tone = status === 'active' ? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300' : status === 'deleted' ? 'bg-destructive/10 text-destructive' : 'bg-muted text-muted-foreground';
11
+ return html`<span class=${`inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${tone}`}>${__(STATUS[status])}</span>`;
12
+ }
13
+
14
+ /** A site's icon beside its name, or a globe when neither the site nor the network has one. */
15
+ export function siteIcon(url: string): TemplateResult {
16
+ return url ? html`<img src=${url} alt="" width="20" height="20" loading="lazy" data-site-icon class="mt-0.5 size-5 shrink-0 rounded-sm object-contain">`
17
+ : html`<span aria-hidden="true" data-site-icon class="mt-0.5 inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-5">${component(Icon, { entry: icon('global'), size: 20 })}</span>`;
18
+ }
19
+
20
+ /** A labelled input for the network's plain forms, which post without JavaScript. */
21
+ export function field(name: string, label: string, options: { value?: string; type?: 'text' | 'email' | 'password'; required?: boolean; hint?: string; placeholder?: string } = {}): TemplateResult {
22
+ return component(Field, { label, for: `network-${name}`, ...(options.hint ? { hint: options.hint } : {}), ...(options.required ? { required: true } : {}),
23
+ control: attributes => component(Input, { ...attributes, name, type: options.type ?? 'text', '.value': options.value ?? '', ...(options.placeholder ? { placeholder: options.placeholder } : {}) }) });
24
+ }
25
+
26
+ /** A one-button form posting an action, such as archiving a site. */
27
+ export function actionButton(action: string, label: string, fields: Record<string, string> = {}, options: { danger?: boolean } = {}): TemplateResult {
28
+ return html`<form method="post" class="inline">
29
+ <input type="hidden" name="action" value=${action}>
30
+ ${Object.entries(fields).map(([name, value]) => html`<input type="hidden" name=${name} value=${value}>`)}
31
+ ${component(Button, { type: 'submit', size: 'sm', variant: options.danger ? 'destructive' : 'outline' }, label)}
32
+ </form>`;
33
+ }
34
+
35
+ /** The submit button of a plain form. */
36
+ export function submitButton(label: string): TemplateResult {
37
+ return component(Button, { type: 'submit' }, label);
38
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * What follows a note outside the entry's room: the webhook events `note.created` and
3
+ * `note.resolved` for the entry's collection, and the email to the people a new note names
4
+ * (its mentions and, for a reply, the thread's earlier voices), with the Writing setting on and
5
+ * an application that sends mail. Server-only; it runs from the outbox job the note's write queued
6
+ * (`announceNoteEvent`).
7
+ */
8
+ import { noteMail, type Note } from '@cossackframework/cms';
9
+ import type { CmsHost, NoteAnnouncedEvent } from '@cossackframework/cms/server';
10
+
11
+ /** The `note.announced` outbox job, queued with the note's write: the note as it is now, announced. */
12
+ export async function announceNoteEvent(cms: CmsHost, event: NoteAnnouncedEvent): Promise<void> {
13
+ const note = await cms.notes.get(event.noteId);
14
+ // A note removed before the job ran is not announced.
15
+ if (!note) return;
16
+ await announceNote(cms, { kind: event.kind, note }, event.context);
17
+ }
18
+
19
+ export interface NoteContext {
20
+ /**
21
+ * The site's configured origin, for the link to the entry's notes (`mailOrigin`): null without
22
+ * one, when emails carry no link and webhooks a path, never an address the request named.
23
+ */
24
+ readonly origin: string | null;
25
+ /** The entry's dashboard route (`posts`, `app.tickets`). */
26
+ readonly route: string;
27
+ /** The collection's name, for webhooks; null for a plugin's resource, which webhooks do not cover. */
28
+ readonly collection: string | null;
29
+ readonly title: string;
30
+ /** Who did it, by name. */
31
+ readonly author: string;
32
+ }
33
+
34
+ export async function announceNote(cms: CmsHost, change: { readonly kind: 'created' | 'resolved'; readonly note: Note }, context: NoteContext): Promise<void> {
35
+ const { note } = change;
36
+ const path = `/dashboard/content/${context.route}/${note.recordId}?notes=open`;
37
+ const url = context.origin ? `${context.origin}${path}` : path;
38
+ const event = change.kind === 'created' ? 'note.created' : 'note.resolved';
39
+ if (context.collection && await cms.webhooks.wants([event], context.collection).catch(() => false)) {
40
+ await cms.webhooks.enqueue({
41
+ event, eventId: change.kind === 'created' ? `note:${note.id}:created` : `note:${note.id}:resolved:${note.resolvedAt ?? 0}`, at: cms.now(), collection: context.collection,
42
+ entry: { id: note.recordId, title: context.title, url }, note: { ...note },
43
+ }).catch(error => console.warn('[cms] a note webhook could not be queued', error));
44
+ }
45
+ if (change.kind !== 'created' || !cms.mail || !(await cms.settings.get('writing.notesEmail').catch(() => false))) return;
46
+ const people = await cms.users.getMany(await cms.notes.mentioned(note.id));
47
+ if (!people.size) return;
48
+ const site = String((await cms.settings.get('general.siteTitle').catch(() => '')) ?? '');
49
+ const message = noteMail({ author: context.author, title: context.title, body: note.body, quote: note.quote, url: context.origin ? url : '', reply: note.parentId !== null, site });
50
+ for (const person of people.values()) {
51
+ if (person.status !== 'active' || !person.email || !(await mayReadNotes(cms, note, person.id))) continue;
52
+ await cms.mail.send({ kind: 'note', to: person.email, from: cms.mailFrom, subject: message.subject, text: message.text }).catch(error => console.warn(`[cms] the note email to ${person.email} failed`, error));
53
+ }
54
+ }
55
+
56
+ /** Whether the member may read the entry's notes (edit the entry, as the notes API asks): a mention does not show them a note they cannot open. */
57
+ async function mayReadNotes(cms: CmsHost, note: Note, userId: string): Promise<boolean> {
58
+ try {
59
+ const principal = await cms.users.principal(userId);
60
+ if (!principal) return false;
61
+ const repository = cms.resource(note.resource);
62
+ const record = await repository.get(note.recordId, { principal });
63
+ return record !== null && repository.canUpdate(record, principal);
64
+ } catch { return false; }
65
+ }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * The Notes rail of the entry editor: a sheet at the side listing the entry's review threads,
3
+ * open or resolved, each with where it sits (a field, a block, a quoted passage), its messages
4
+ * and a reply box; and the small markers the fields, blocks and passages carry. Everything here
5
+ * is drawn from props; the editor page owns the state and talks to the entry's room. Client-safe.
6
+ */
7
+ import { component, html, type TemplateResult } from '@cossackframework/renderer';
8
+ import { Button, Combobox, Icon, Textarea } from '@cossackframework/ui';
9
+ import { mentionToken, noteParts, type Note, type NoteRange, type NoteStatus, type NoteThread } from '@cossackframework/cms';
10
+ import { avatar, type Someone } from './collab/presence';
11
+ import { icon } from './icons';
12
+ import { iconButton, shortDate } from './ui';
13
+
14
+ /** A note being written: where it goes and the text so far. A reply names its thread. */
15
+ export interface NoteComposer {
16
+ target: string;
17
+ range: NoteRange | null;
18
+ quote: string;
19
+ parentId: string | null;
20
+ body: string;
21
+ }
22
+
23
+ /** Where a thread sits, in words: the field or block, and the passage it quotes. */
24
+ export interface NoteAnchorView {
25
+ label: string;
26
+ quote: string;
27
+ /** The passage is gone: the note shows on its block or field instead. */
28
+ detached: boolean;
29
+ }
30
+
31
+ export interface NotesRailProps {
32
+ /** Page-unique prefix for element IDs. */
33
+ id: string;
34
+ open: boolean;
35
+ threads: readonly NoteThread[];
36
+ filter: NoteStatus;
37
+ /** Who the notes name, by user ID. */
38
+ people: Record<string, Someone>;
39
+ /** The viewer's user ID: their own notes can be changed and removed. */
40
+ me: string;
41
+ /** The viewer removes anyone's notes. */
42
+ admin: boolean;
43
+ /** The thread chosen, highlighted here and in the content. */
44
+ active: string | null;
45
+ composer: NoteComposer | null;
46
+ /** A note whose text is being changed. */
47
+ editing: { id: string; body: string } | null;
48
+ mentionable: readonly { id: string; name: string }[];
49
+ busy: boolean;
50
+ error: string;
51
+ anchor(root: Note): NoteAnchorView;
52
+ onClose(): void;
53
+ onFilter(filter: NoteStatus): void;
54
+ onSelect(id: string): void;
55
+ onCompose(composer: NoteComposer | null): void;
56
+ onSubmit(): void;
57
+ onEdit(editing: { id: string; body: string } | null): void;
58
+ onSaveEdit(): void;
59
+ onResolve(id: string): void;
60
+ onReopen(id: string): void;
61
+ onRemove(id: string): void;
62
+ }
63
+
64
+ const AMBER = 'rounded-full border border-amber-500/60 bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium leading-none text-amber-700 dark:text-amber-300';
65
+
66
+ /** The count of open notes on a field, block or the entry: an amber chip that opens them. */
67
+ export function noteMarker(count: number, label: string, onClick: () => void): TemplateResult | null {
68
+ if (!count) return null;
69
+ return html`<button type="button" class=${`inline-flex items-center gap-1 ${AMBER} cursor-pointer hover:bg-amber-500/20`} data-notes=${count} aria-label=${`${count} ${count === 1 ? __('open note on') : __('open notes on')} ${label}`} title=${__('Show the notes')}
70
+ @click=${(event: Event) => { event.stopPropagation(); onClick(); }}>${component(Icon, { entry: icon('notes'), size: 12 })}${count}</button>`;
71
+ }
72
+
73
+ /** The button that starts a note on a field or block; shown when its row is hovered or focused. */
74
+ export function noteButton(id: string, label: string, onClick: () => void, options: { always?: boolean } = {}): TemplateResult {
75
+ return html`<button type="button" id=${id} class=${`inline-flex size-6 items-center justify-center rounded border-none bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground cursor-pointer [&_svg]:size-3.5 ${options.always ? '' : 'opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 focus:opacity-100'}`}
76
+ aria-label=${`${__('Add a note on')} ${label}`} title=${__('Add a note')} @click=${(event: Event) => { event.stopPropagation(); onClick(); }}>${component(Icon, { entry: icon('chat-round-line'), size: 14 })}</button>`;
77
+ }
78
+
79
+ /**
80
+ * A single line of text with its note tools inside, at the right end, as the title field shows
81
+ * them; without tools (a new entry) the control alone. Other kinds of fields keep the tools
82
+ * beside their label.
83
+ */
84
+ export function inlineNoteTools(control: TemplateResult, tools: TemplateResult | null): TemplateResult {
85
+ if (!tools) return control;
86
+ return html`<div class="relative [&_input]:pr-14">${control}<span class="absolute right-2 top-[1.125rem] flex -translate-y-1/2 items-center">${tools}</span></div>`;
87
+ }
88
+
89
+ /** A note's text with its mentions shown as names. */
90
+ export function noteBody(body: string): TemplateResult {
91
+ return html`<p class="whitespace-pre-wrap break-words text-sm text-foreground">${noteParts(body).map(part => part.kind === 'mention'
92
+ ? html`<span class="rounded bg-primary/10 px-1 font-medium text-primary" data-mention=${part.user}>@${part.name}</span>`
93
+ : part.text)}</p>`;
94
+ }
95
+
96
+ /** The composer's mention picker: a chosen person becomes a token at the end of the text. */
97
+ function mentionPicker(id: string, props: NotesRailProps, body: string, change: (body: string) => void): TemplateResult | null {
98
+ if (!props.mentionable.length) return null;
99
+ return component(Combobox, {
100
+ id, options: props.mentionable.map(person => ({ value: person.id, label: person.name })), value: '', placeholder: __('Mention someone…'), emptyLabel: __('Nobody matches.'), 'aria-label': __('Mention someone'),
101
+ onValueChange: (value: string) => {
102
+ const person = props.mentionable.find(entry => entry.id === value);
103
+ if (person) change(`${body}${body && !/\s$/.test(body) ? ' ' : ''}${mentionToken(person)} `);
104
+ },
105
+ });
106
+ }
107
+
108
+ /** The box a note or a reply is written in. */
109
+ function composerView(props: NotesRailProps, composer: NoteComposer, title: string): TemplateResult {
110
+ const id = `${props.id}-composer`;
111
+ return html`<form class="space-y-2 rounded-md border border-amber-500/50 bg-amber-500/5 p-3" data-note-composer=${composer.parentId ?? 'new'} @submit=${(event: Event) => { event.preventDefault(); props.onSubmit(); }}>
112
+ <p class="text-xs font-medium text-foreground">${title}</p>
113
+ ${composer.quote ? html`<blockquote class="border-l-2 border-amber-500 pl-2 text-xs italic text-muted-foreground">${composer.quote}</blockquote>` : null}
114
+ ${component(Textarea, { id, rows: 3, placeholder: __('Write a note…'), autofocus: true, 'aria-label': __('Note'), '.value': composer.body, '@input': (event: Event) => props.onCompose({ ...composer, body: (event.target as HTMLTextAreaElement).value }) })}
115
+ <div class="flex flex-wrap items-center gap-2">
116
+ ${mentionPicker(`${id}-mention`, props, composer.body, body => props.onCompose({ ...composer, body }))}
117
+ <span class="flex-1"></span>
118
+ ${component(Button, { type: 'button', variant: 'ghost', size: 'sm', '@click': () => props.onCompose(null) }, __('Cancel'))}
119
+ ${component(Button, { type: 'submit', size: 'sm', disabled: props.busy || !composer.body.trim() }, composer.parentId ? __('Reply') : __('Post note'))}
120
+ </div>
121
+ </form>`;
122
+ }
123
+
124
+ /** One message of a thread: who, when, the text; its author's edit and remove on hover. */
125
+ function messageView(props: NotesRailProps, note: Note, root: Note): TemplateResult {
126
+ const person = props.people[note.userId] ?? { user: note.userId, name: note.userId, avatar: null, color: 'var(--muted-foreground)' };
127
+ const mine = note.userId === props.me;
128
+ const editing = props.editing?.id === note.id ? props.editing : null;
129
+ return html`<div class="group/note flex gap-2" data-note=${note.id}>
130
+ <span class="mt-0.5 shrink-0">${avatar(person, 20)}</span>
131
+ <div class="min-w-0 flex-1 space-y-1">
132
+ <p class="flex flex-wrap items-baseline gap-x-2 text-xs">
133
+ <span class="font-medium text-foreground">${person.name}</span>
134
+ <span class="text-muted-foreground">${shortDate(note.createdAt)}${note.updatedAt > note.createdAt && note.parentId ? ` · ${__('edited')}` : ''}</span>
135
+ <span class="ml-auto inline-flex gap-1 opacity-0 transition-opacity group-hover/note:opacity-100 group-focus-within/note:opacity-100">
136
+ ${mine && !editing ? iconButton(`${props.id}-change-${note.id}`, 'pen', __('Edit'), () => props.onEdit({ id: note.id, body: note.body })) : null}
137
+ ${mine || props.admin ? iconButton(`${props.id}-remove-${note.id}`, 'trash-bin-trash', note.parentId ? __('Remove') : __('Remove thread'), () => props.onRemove(note.id), { danger: true }) : null}
138
+ </span>
139
+ </p>
140
+ ${editing ? html`<form class="space-y-2" @submit=${(event: Event) => { event.preventDefault(); props.onSaveEdit(); }}>
141
+ ${component(Textarea, { id: `${props.id}-edit-${note.id}`, rows: 3, autofocus: true, 'aria-label': __('Note'), '.value': editing.body, '@input': (event: Event) => props.onEdit({ id: note.id, body: (event.target as HTMLTextAreaElement).value }) })}
142
+ <div class="flex items-center justify-end gap-2">
143
+ ${component(Button, { type: 'button', variant: 'ghost', size: 'sm', '@click': () => props.onEdit(null) }, __('Cancel'))}
144
+ ${component(Button, { type: 'submit', size: 'sm', disabled: props.busy || !editing.body.trim() }, __('Save'))}
145
+ </div>
146
+ </form>` : noteBody(note.body)}
147
+ ${!note.parentId && root.status === 'resolved' && root.resolvedBy ? html`<p class="text-xs text-muted-foreground">${__('Resolved by')} ${props.people[root.resolvedBy]?.name ?? root.resolvedBy}${root.resolvedAt ? ` · ${shortDate(root.resolvedAt)}` : ''}</p>` : null}
148
+ </div>
149
+ </div>`;
150
+ }
151
+
152
+ function threadView(props: NotesRailProps, thread: NoteThread): TemplateResult {
153
+ const { root } = thread;
154
+ const where = props.anchor(root);
155
+ const active = props.active === root.id;
156
+ const replying = props.composer?.parentId === root.id ? props.composer : null;
157
+ return html`<article class=${`space-y-3 rounded-lg border bg-card p-3 ${active ? 'border-amber-500 ring-2 ring-amber-500/30' : 'border-border'}`} data-note-thread=${root.id} data-status=${root.status}>
158
+ <button type="button" class="flex w-full items-start gap-2 border-none bg-transparent p-0 text-left cursor-pointer" @click=${() => props.onSelect(root.id)} aria-label=${`${__('Show in the entry')}: ${where.label}`}>
159
+ <span class="inline-flex shrink-0 text-amber-600 [&_svg]:size-4"><span class="inline-flex">${component(Icon, { entry: icon(where.detached ? 'pin' : 'notes'), size: 16 })}</span></span>
160
+ <span class="min-w-0 flex-1">
161
+ <span class="block text-xs font-medium text-foreground">${where.label}${where.detached ? html` <span class="font-normal text-muted-foreground">(${__('the text changed')})</span>` : null}</span>
162
+ ${where.quote ? html`<span class="block truncate text-xs italic text-muted-foreground">“${where.quote}”</span>` : null}
163
+ </span>
164
+ </button>
165
+ ${messageView(props, root, root)}
166
+ ${thread.replies.length ? html`<div class="space-y-3 border-l-2 border-border pl-3">${thread.replies.map(reply => messageView(props, reply, root))}</div>` : null}
167
+ ${replying ? composerView(props, replying, __('Reply')) : html`<div class="flex flex-wrap items-center gap-2">
168
+ ${root.status === 'open' ? html`${component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => props.onCompose({ target: root.target, range: null, quote: '', parentId: root.id, body: '' }) }, __('Reply'))}
169
+ ${component(Button, { type: 'button', size: 'sm', variant: 'ghost', disabled: props.busy, '@click': () => props.onResolve(root.id) }, __('Resolve'))}`
170
+ : component(Button, { type: 'button', size: 'sm', variant: 'outline', disabled: props.busy, '@click': () => props.onReopen(root.id) }, __('Reopen'))}
171
+ </div>`}
172
+ </article>`;
173
+ }
174
+
175
+ /**
176
+ * The rail itself: a panel fixed at the right, not a modal, so the entry stays editable while
177
+ * the notes are read; it leaves the dashboard's taskbar visible. Escape inside it closes it.
178
+ */
179
+ export function notesRail(props: NotesRailProps): TemplateResult | null {
180
+ if (!props.open) return null;
181
+ const open = props.threads.filter(thread => thread.root.status === 'open');
182
+ const resolved = props.threads.filter(thread => thread.root.status === 'resolved');
183
+ const shown = props.filter === 'open' ? open : resolved;
184
+ const tab = (filter: NoteStatus, label: string, count: number) => html`<button type="button" role="tab" aria-selected=${props.filter === filter ? 'true' : 'false'}
185
+ class=${`rounded-md px-2.5 py-1 text-xs font-medium border-none cursor-pointer ${props.filter === filter ? 'bg-muted text-foreground' : 'bg-transparent text-muted-foreground hover:text-foreground'}`}
186
+ @click=${() => props.onFilter(filter)}>${label} <span class="text-muted-foreground">${count}</span></button>`;
187
+ return html`<aside id=${`${props.id}-rail`} role="complementary" aria-label=${__('Notes')} data-notes-rail
188
+ class="fixed inset-y-0 right-0 z-40 w-[26rem] max-w-[calc(100vw-1rem)] border-l border-border bg-background text-foreground shadow-xl md:bottom-10"
189
+ @keydown=${(event: KeyboardEvent) => { if (event.key === 'Escape') { event.stopPropagation(); props.onClose(); } }}>
190
+ <div class="flex h-full flex-col">
191
+ <header class="flex items-center gap-3 border-b border-border px-5 py-4">
192
+ <div role="heading" aria-level="2" class="text-base font-semibold text-foreground">${__('Notes')}</div>
193
+ <div role="tablist" class="flex items-center gap-1">${tab('open', __('Open'), open.length)}${tab('resolved', __('Resolved'), resolved.length)}</div>
194
+ <span class="flex-1"></span>
195
+ <button type="button" class="inline-flex size-8 shrink-0 items-center justify-center rounded-md border-none bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground cursor-pointer" aria-label=${__('Close')} @click=${() => props.onClose()}>✕</button>
196
+ </header>
197
+ <div class="min-h-0 flex-1 space-y-3 overflow-y-auto px-5 py-4">
198
+ ${props.error ? html`<p role="alert" class="text-sm text-destructive">${props.error}</p>` : null}
199
+ ${props.composer && !props.composer.parentId ? composerView(props, props.composer, `${__('New note on')} ${props.anchor({ target: props.composer.target } as Note).label}`) : null}
200
+ ${shown.length ? shown.map(thread => threadView(props, thread))
201
+ : html`<p class="text-sm text-muted-foreground">${props.filter === 'open'
202
+ ? __('No open notes. Hover a field or a block and choose “Add a note”, or select text and use Note in the toolbar.')
203
+ : __('Nothing resolved yet.')}</p>`}
204
+ </div>
205
+ </div>
206
+ </aside>`;
207
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * A form's notifications, edited as a list: who gets each email, its subject and text with
3
+ * merge tags, and when to send it. The field stores `{ rules: [...] }` as JSON text, as the
4
+ * editor keeps JSON fields; the server checks the rules against the form's inputs. Client-safe.
5
+ */
6
+ import { component, html, type TemplateResult } from '@cossackframework/renderer';
7
+ import { Button, Checkbox, Input, Textarea } from '@cossackframework/ui';
8
+ import { blockId, MERGE_TAGS, NOTIFICATION_LIMIT, notificationRules, type NotificationRule } from '@cossackframework/cms';
9
+ import { conditionControl, conditionInput, type ConditionField } from './condition-control';
10
+
11
+ function rulesOf(text: string): NotificationRule[] {
12
+ try { return text.trim() ? notificationRules(JSON.parse(text)) : []; } catch { return []; }
13
+ }
14
+
15
+ const textOf = (rules: readonly NotificationRule[]) => rules.length ? JSON.stringify({ rules }, null, 2) : '';
16
+
17
+ /** The rules control. `fields` are the form's inputs, for `{field:…}` tags and conditions. */
18
+ export function notificationRulesControl(text: string, fields: readonly ConditionField[], id: string, change: (text: string) => void): TemplateResult {
19
+ const rules = rulesOf(text);
20
+ const save = (next: readonly NotificationRule[]) => change(textOf(next.map(rule => {
21
+ const when = conditionInput(rule.when);
22
+ const { when: _when, ...rest } = rule;
23
+ return when ? { ...rest, when } : rest;
24
+ })));
25
+ const set = (index: number, next: Partial<NotificationRule>) => save(rules.map((rule, at) => at === index ? { ...rule, ...next } : rule));
26
+ const add = () => save([...rules, {
27
+ id: blockId(), label: rules.length ? __('Notification') : __('Admin notification'), to: '{admin_email}',
28
+ subject: `${__('New submission')}: {form:title}`, body: '{all_fields}\n\n{submission:url}',
29
+ }]);
30
+ const line = (index: number, key: 'label' | 'to' | 'replyTo' | 'subject', label: string, hint = '') => {
31
+ const control = `${id}-${index}-${key}`;
32
+ return html`<div class="min-w-0 space-y-1">
33
+ <label for=${control} class="block text-xs font-medium text-foreground">${label}</label>
34
+ ${component(Input, { id: control, size: 'sm', '.value': rules[index]![key] ?? '', '@input': (event: Event) => set(index, { [key]: (event.target as HTMLInputElement).value }) })}
35
+ ${hint ? html`<p class="text-xs text-muted-foreground">${hint}</p>` : null}
36
+ </div>`;
37
+ };
38
+ const tags = [...MERGE_TAGS.map(entry => ({ tag: entry.tag, label: __(entry.label) })), ...fields.map(field => ({ tag: `{field:${field.name}}`, label: field.label }))];
39
+ return html`<div id=${id} class="space-y-3">
40
+ ${rules.length ? null : html`<p class="text-sm text-muted-foreground">${__('No emails are sent for submissions.')}</p>`}
41
+ ${rules.map((rule, index) => html`<fieldset class="space-y-3 rounded-md border border-border p-3" data-notification=${rule.id}>
42
+ <legend class="sr-only">${rule.label}</legend>
43
+ <div class="flex items-center justify-between gap-2">
44
+ <span class="[&_.cs-checkbox]:font-medium">${component(Checkbox, { checked: rule.enabled !== false, '@change': (event: Event) => set(index, { enabled: (event.target as HTMLInputElement).checked }) },
45
+ html`${__('Send')} “${rule.label || __('Notification')}”`)}</span>
46
+ ${component(Button, { type: 'button', size: 'sm', variant: 'ghost', 'aria-label': `${__('Remove')} ${rule.label}`, '@click': () => save(rules.filter((_, at) => at !== index)) }, __('Remove'))}
47
+ </div>
48
+ <div class="grid gap-3 sm:grid-cols-2">
49
+ ${line(index, 'label', __('Name'))}
50
+ ${line(index, 'to', __('Send to'), `${__('Addresses or tags, separated by commas, such as')} {admin_email} ${__('or an email field.')}`)}
51
+ ${line(index, 'subject', __('Subject'))}
52
+ ${line(index, 'replyTo', __('Reply to'), __('Optional, such as an email field.'))}
53
+ </div>
54
+ <div class="space-y-1">
55
+ <label for=${`${id}-${index}-body`} class="block text-xs font-medium text-foreground">${__('Message')}</label>
56
+ ${component(Textarea, { id: `${id}-${index}-body`, rows: 5, '.value': rule.body, '@input': (event: Event) => set(index, { body: (event.target as HTMLTextAreaElement).value }) })}
57
+ </div>
58
+ ${conditionControl(rule.when, fields, `${id}-${index}`, when => set(index, when ? { when } : { when: undefined }),
59
+ { toggle: __('Send only when the answers match'), subject: __('this email'), show: __('Send'), hide: __('Do not send') })}
60
+ </fieldset>`)}
61
+ ${rules.length < NOTIFICATION_LIMIT ? component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': add }, __('Add notification')) : null}
62
+ <details class="text-xs text-muted-foreground"><summary class="cursor-pointer">${__('Merge tags')}</summary>
63
+ <ul class="mt-2 grid gap-1 sm:grid-cols-2">${tags.map(entry => html`<li><code class="text-foreground">${entry.tag}</code> ${entry.label}</li>`)}</ul>
64
+ </details>
65
+ </div>`;
66
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Recovery mode: a way back in for an administrator who forgot the password on a site that
3
+ * cannot send email. It is on while `CMS_RECOVERY_CODE` is set in the environment, so only
4
+ * whoever controls the deployment can use it; `cossack cms password reset` sends the code with
5
+ * an email and prints the one-hour reset link this answers with. The new password is chosen in
6
+ * the browser, as with Forgot password, so it never passes through the command line.
7
+ */
8
+ import type { Context } from 'hono';
9
+ import { getClientIp } from '@cossackframework/core';
10
+ import { sha256Hex, timingSafeEqual, type CmsHost } from '@cossackframework/cms/server';
11
+ import type { CmsBindings } from './index';
12
+ import { siteOrigin } from './seo';
13
+
14
+ /** Five tries per address in fifteen minutes. */
15
+ export const RECOVERY_ATTEMPTS = Object.freeze({ max: 5, windowMs: 15 * 60_000 });
16
+ /** Shorter codes are refused, so recovery cannot be switched on with a guessable one. */
17
+ export const RECOVERY_CODE_MIN_LENGTH = 16;
18
+
19
+ export class RecoveryError extends Error {
20
+ constructor(readonly code: 'CMS_RECOVERY_OFF' | 'CMS_RECOVERY_WEAK' | 'CMS_UNAUTHENTICATED' | 'CMS_RATE_LIMITED' | 'CMS_NOT_FOUND' | 'CMS_VALIDATION' | 'CMS_UNAVAILABLE', message: string, readonly status: 400 | 401 | 403 | 404 | 429 | 503) {
21
+ super(message);
22
+ }
23
+ }
24
+
25
+ /** The recovery code the environment holds, or null while recovery mode is off. */
26
+ export function recoveryCode(env: unknown): string | null {
27
+ const code = (env as { CMS_RECOVERY_CODE?: unknown } | undefined)?.CMS_RECOVERY_CODE;
28
+ return typeof code === 'string' && code.trim() ? code.trim() : null;
29
+ }
30
+
31
+ export interface RecoveryResult {
32
+ readonly email: string;
33
+ /** Open it within the hour to choose a new password. */
34
+ readonly resetUrl: string;
35
+ readonly expiresAt: number;
36
+ /** The authenticator app, recovery codes and passkeys were removed too. */
37
+ readonly secondFactorsCleared: boolean;
38
+ }
39
+
40
+ /**
41
+ * Check the code and make a reset link for an active account of this site (or its network
42
+ * account), optionally clearing its second factors. Every use is written to Tools → Activity,
43
+ * and the account is told by email when the site can send one.
44
+ */
45
+ export async function recoverAccount(c: Context, input: { code: unknown; email: unknown; secondFactors?: unknown }): Promise<RecoveryResult> {
46
+ const expected = recoveryCode(c.env);
47
+ if (!expected) throw new RecoveryError('CMS_RECOVERY_OFF', 'Recovery mode is off: set CMS_RECOVERY_CODE in the environment to turn it on.', 403);
48
+ if (expected.length < RECOVERY_CODE_MIN_LENGTH) throw new RecoveryError('CMS_RECOVERY_WEAK', `CMS_RECOVERY_CODE must be at least ${RECOVERY_CODE_MIN_LENGTH} characters.`, 403);
49
+ const host: CmsHost = c.get('cms');
50
+ const address = getClientIp(c) || 'unknown';
51
+ if (!(await host.security.attempt('recovery', `a:${address}`, RECOVERY_ATTEMPTS.max, RECOVERY_ATTEMPTS.windowMs)))
52
+ throw new RecoveryError('CMS_RATE_LIMITED', 'Too many recovery attempts. Wait fifteen minutes.', 429);
53
+ // Compared as digests, so the time taken says nothing about the code's length either.
54
+ if (typeof input.code !== 'string' || !timingSafeEqual(await sha256Hex(input.code), await sha256Hex(expected))) throw new RecoveryError('CMS_UNAUTHENTICATED', 'The recovery code is not correct.', 401);
55
+ const email = typeof input.email === 'string' ? input.email.trim() : '';
56
+ if (!email || email.length > 254 || !email.includes('@')) throw new RecoveryError('CMS_VALIDATION', 'Give the email address of the account.', 400);
57
+
58
+ const secondFactorsCleared = input.secondFactors === true;
59
+ // Logged before anything changes, and refused when it cannot be: a recovery never goes unrecorded.
60
+ // (The reset lives in the account's database, which may be the network's, so the two cannot share one write.)
61
+ const member = await host.users.findByEmail(email).catch(() => null);
62
+ try { await host.audit.record({ actor: 'system:recovery', action: secondFactorsCleared ? 'recover-account-factors' : 'recover-account', resource: 'cms/users', recordId: member?.id ?? email }); }
63
+ catch (error) {
64
+ console.error('[cms] could not log a recovery', error);
65
+ throw new RecoveryError('CMS_UNAVAILABLE', 'The recovery could not be recorded in Tools → Activity, so it was not made. Try again.', 503);
66
+ }
67
+
68
+ // A site account resets on its site; a network account on the network host, as Forgot password does.
69
+ let reset = await host.signIn.accounts.createPasswordReset(email);
70
+ let origin = siteOrigin(c);
71
+ if (!reset && host.siteAccounts && member?.account === 'network') {
72
+ reset = await host.accounts.createPasswordReset(email);
73
+ origin = (c.env as CmsBindings).APP_URL?.replace(/\/+$/, '') || siteOrigin(c);
74
+ }
75
+ if (!reset) throw new RecoveryError('CMS_NOT_FOUND', `No active account with the email ${email} on this site.`, 404);
76
+ const userId = reset.account.id;
77
+ if (secondFactorsCleared) await (await host.storesOf(userId)).security.reset(userId);
78
+ await host.mail?.send({ kind: 'other', to: reset.account.email, subject: 'Your account was recovered',
79
+ text: `Someone with the site's recovery code asked for a password reset link for your account${secondFactorsCleared ? ' and removed its two-step sign-in' : ''}, from ${address}.\n\nIf that was not you or another administrator, tell whoever runs the site: the recovery code should be removed from its environment.` })
80
+ .catch(error => console.error('[cms] could not send the recovery notice', error));
81
+ return { email: reset.account.email, resetUrl: `${origin.replace(/\/$/, '')}/auth/reset-password?token=${reset.token}`, expiresAt: Date.now() + 60 * 60_000, secondFactorsCleared };
82
+ }
@@ -0,0 +1,63 @@
1
+ /** Find and replace over entry values: the words people wrote, never IDs, links, choices or styles. */
2
+ import { blockIsData, type Block, type BlockDeclaration, type FieldDeclaration, type RichTextDoc, type RichTextNode } from '@cossackframework/cms';
3
+
4
+ export interface Replaced<T> { readonly value: T; readonly count: number }
5
+
6
+ /** Whether a field holds prose to search: plain or Markdown text, not a slug, URL, choice, reference, media or code. */
7
+ export function replaceableText(declaration: FieldDeclaration): boolean {
8
+ if (declaration.kind !== 'string' && declaration.kind !== 'text') return false;
9
+ return !declaration.media && !declaration.taxonomy && !declaration.multiple && !declaration.pattern && !declaration.choices && !declaration.choicesFrom
10
+ && declaration.format !== 'code';
11
+ }
12
+
13
+ /** The fields find and replace reads and writes: prose, rich text and blocks, never the entry's password. */
14
+ export function replaceableFields(fields: { readonly [name: string]: FieldDeclaration }): [string, FieldDeclaration][] {
15
+ return Object.entries(fields).filter(([name, declaration]) => name !== 'password' && (replaceableText(declaration) || declaration.kind === 'richtext' || declaration.kind === 'blocks'));
16
+ }
17
+
18
+ export function replaceInText(value: string, pattern: RegExp, replacement: string): Replaced<string> {
19
+ let count = 0;
20
+ const next = value.replace(pattern, () => { count++; return replacement; });
21
+ return { value: next, count };
22
+ }
23
+
24
+ /** Text nodes the replacement empties are removed: a rich text document has no empty text nodes. */
25
+ export function replaceInDoc(doc: RichTextDoc | null, pattern: RegExp, replacement: string): Replaced<RichTextDoc> | null {
26
+ if (!doc || !Array.isArray(doc.content)) return null;
27
+ let count = 0;
28
+ const visit = (node: RichTextNode): RichTextNode | null => {
29
+ if (node.type === 'text' && typeof node.text === 'string') {
30
+ const result = replaceInText(node.text, pattern, replacement);
31
+ count += result.count;
32
+ if (!result.count) return node;
33
+ return result.value ? { ...node, text: result.value } : null;
34
+ }
35
+ return node.content ? { ...node, content: node.content.map(visit).filter((child): child is RichTextNode => child !== null) } : node;
36
+ };
37
+ const content = doc.content.map(visit).filter((node): node is RichTextNode => node !== null);
38
+ return { value: { ...doc, content }, count };
39
+ }
40
+
41
+ /** Each block's text and rich text inputs, as its type declares them; blocks of an unknown or data type stay as they are. */
42
+ export function replaceInBlocks(blocks: Block[] | null, types: ReadonlyMap<string, BlockDeclaration>, pattern: RegExp, replacement: string): Replaced<Block[]> | null {
43
+ if (!Array.isArray(blocks)) return null;
44
+ let count = 0;
45
+ const visit = (block: Block): Block => {
46
+ const type = types.get(block.type);
47
+ const data: Record<string, unknown> = { ...block.data };
48
+ if (type && !blockIsData(type)) {
49
+ for (const [name, declaration] of Object.entries(type.fields)) {
50
+ const value = data[name];
51
+ if (declaration.kind === 'richtext' && value && typeof value === 'object') {
52
+ const result = replaceInDoc(value as RichTextDoc, pattern, replacement);
53
+ if (result?.count) { data[name] = result.value; count += result.count; }
54
+ } else if (typeof value === 'string' && replaceableText(declaration)) {
55
+ const result = replaceInText(value, pattern, replacement);
56
+ if (result.count) { data[name] = result.value; count += result.count; }
57
+ }
58
+ }
59
+ }
60
+ return { ...block, data, ...(block.children ? { children: block.children.map(visit) } : {}) };
61
+ };
62
+ return { value: blocks.map(visit), count };
63
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The first path segments the application's routes take, from its page files (the keys of
3
+ * `virtual:cossack-pages`, such as `/src/pages/(site)/search/index.ts`): the project's pages,
4
+ * the CMS's and every plugin's. An entry served at the site root cannot take one as its slug,
5
+ * or the entry would hide the page, or the page the entry.
6
+ */
7
+ export function reservedRouteSegments(files: readonly string[]): string[] {
8
+ const segments = new Set<string>();
9
+ for (const file of files) {
10
+ // Route groups, `(site)`, are not part of the address.
11
+ const [first, ...rest] = file.replace(/^\/src\/pages\//, '').split('/').filter(part => !/^\([^)]+\)$/.test(part));
12
+ if (!first) continue;
13
+ const segment = rest.length ? first : first.replace(/\.(?:ts|mdx?)$/, '');
14
+ // A parameter takes any address already, and these files are not routes of their own.
15
+ if (segment.startsWith('[') || ['index', '404', 'error', 'layout', 'loading'].includes(segment)) continue;
16
+ segments.add(segment);
17
+ }
18
+ return [...segments].sort();
19
+ }