@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,94 @@
1
+ import { Cossack, Page, State, type HeadValue } from '@cossackframework/core';
2
+ import { Badge, Card, CardBody } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { PERMISSIONS } from '@cossackframework/cms';
5
+ import type { AuditEntry } from '@cossackframework/cms/server';
6
+ import { requireAny } from '#app/cms/guards';
7
+ import { pageHeader, shortDate } from '#app/cms/ui';
8
+
9
+ const PER_PAGE = 50;
10
+
11
+ /**
12
+ * Tools → Activity: the audit trail of every write, newest first, with who did it and a link to
13
+ * the record. Filter by resource or action; a year of rows is kept.
14
+ */
15
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSettings)] })
16
+ export default class ActivityPage extends Cossack {
17
+ @State() items: AuditEntry[] = [];
18
+ @State() total = 0;
19
+ @State() page = 1;
20
+ @State() resource = '';
21
+ @State() action = '';
22
+ @State() resources: string[] = [];
23
+ @State() actions: string[] = [];
24
+ /** Actor IDs to names, for the users among them. */
25
+ @State() names: Record<string, string> = {};
26
+
27
+ head(): HeadValue {
28
+ return { title: 'Activity' };
29
+ }
30
+
31
+ async init() {
32
+ const cms = this.c.get('cms');
33
+ const page = Number(this.c.req.query('page'));
34
+ this.page = Number.isSafeInteger(page) && page > 0 && page <= 2000 ? page : 1;
35
+ this.resource = (this.c.req.query('resource') ?? '').slice(0, 120);
36
+ this.action = (this.c.req.query('action') ?? '').slice(0, 40);
37
+ const { items, total } = await cms.audit.list({ limit: PER_PAGE, offset: (this.page - 1) * PER_PAGE, ...(this.resource ? { resource: this.resource } : {}), ...(this.action ? { action: this.action } : {}) });
38
+ this.items = items;
39
+ this.total = total;
40
+ const facets = await cms.audit.facets();
41
+ this.resources = facets.resources;
42
+ this.actions = facets.actions;
43
+ const userIds = [...new Set(items.map(entry => entry.actor).filter((actor): actor is string => !!actor && !actor.includes(':') && actor !== 'anonymous'))];
44
+ const users = await cms.users.getMany(userIds);
45
+ this.names = Object.fromEntries([...users].map(([id, user]) => [id, user.name || user.email]));
46
+ }
47
+
48
+ /** Where the record is edited: a collection entry, a plugin's resource entry, or nothing for the rest. */
49
+ private href(entry: AuditEntry): string | null {
50
+ const [owner, name] = entry.resource.split('/');
51
+ if (!owner || !name) return null;
52
+ return owner === 'cms' ? `/dashboard/content/${name}/${entry.recordId}` : `/dashboard/content/${owner}.${name}/${entry.recordId}`;
53
+ }
54
+
55
+ private link(overrides: { page?: number; resource?: string; action?: string }): string {
56
+ const query = new URLSearchParams();
57
+ const resource = overrides.resource ?? this.resource;
58
+ const action = overrides.action ?? this.action;
59
+ const page = overrides.page ?? 1;
60
+ if (resource) query.set('resource', resource);
61
+ if (action) query.set('action', action);
62
+ if (page > 1) query.set('page', String(page));
63
+ const text = query.toString();
64
+ return `/dashboard/tools/activity${text ? `?${text}` : ''}`;
65
+ }
66
+
67
+ render() {
68
+ const pages = Math.max(1, Math.ceil(this.total / PER_PAGE));
69
+ const actor = (entry: AuditEntry) => !entry.actor || entry.actor === 'anonymous' ? __('Visitor') : entry.actor.startsWith('system:') ? `${__('System')} (${entry.actor.slice(7)})` : this.names[entry.actor] ?? entry.actor;
70
+ const chip = (label: string, href: string, on: boolean) => html`<a href=${href} class=${`rounded-full border px-2.5 py-0.5 text-xs no-underline ${on ? 'border-primary bg-primary text-primary-foreground' : 'border-border text-foreground hover:bg-muted'}`}>${label}</a>`;
71
+ return html`<div class="space-y-6">
72
+ ${pageHeader(__('Activity'), { description: __('Every write to the site\'s content and settings: who, what and when. A year is kept.') })}
73
+ <div class="flex flex-wrap items-center gap-2">
74
+ <span class="text-xs text-muted-foreground">${__('Resource')}:</span>${chip(__('All'), this.link({ resource: '' }), !this.resource)}${this.resources.map(name => chip(name, this.link({ resource: name }), name === this.resource))}
75
+ </div>
76
+ <div class="flex flex-wrap items-center gap-2">
77
+ <span class="text-xs text-muted-foreground">${__('Action')}:</span>${chip(__('All'), this.link({ action: '' }), !this.action)}${this.actions.map(name => chip(name, this.link({ action: name }), name === this.action))}
78
+ </div>
79
+ ${component(Card, {}, component(CardBody, { class: 'p-0' }, this.items.length ? html`<table class="w-full text-sm" data-testid="activity">
80
+ <thead><tr class="border-b border-border text-left text-xs uppercase text-muted-foreground"><th class="px-4 py-2">${__('When')}</th><th class="px-4 py-2">${__('Who')}</th><th class="px-4 py-2">${__('Action')}</th><th class="px-4 py-2">${__('Record')}</th><th class="px-4 py-2">${__('Revision')}</th></tr></thead>
81
+ <tbody>${this.items.map(entry => { const href = this.href(entry); return html`<tr class="border-b border-border last:border-0">
82
+ <td class="whitespace-nowrap px-4 py-2 text-muted-foreground">${shortDate(entry.at)}</td>
83
+ <td class="px-4 py-2">${actor(entry)}</td>
84
+ <td class="px-4 py-2">${component(Badge, { variant: entry.action === 'delete' ? 'destructive' : 'secondary' }, entry.action)}</td>
85
+ <td class="px-4 py-2"><span class="text-muted-foreground">${entry.resource}</span> ${href ? html`<a href=${href} class="text-primary hover:underline">${entry.recordId.slice(0, 8)}…</a>` : html`<code class="text-xs">${entry.recordId.slice(0, 8)}…</code>`}</td>
86
+ <td class="px-4 py-2 text-muted-foreground">${entry.revision ?? '—'}</td></tr>`; })}</tbody></table>`
87
+ : html`<p class="px-4 py-6 text-sm text-muted-foreground">${__('Nothing recorded yet.')}</p>`))}
88
+ ${pages > 1 ? html`<nav class="flex items-center justify-between text-sm" aria-label=${__('Pages')}>
89
+ ${this.page > 1 ? html`<a href=${this.link({ page: this.page - 1 })} class="text-primary hover:underline">← ${__('Newer')}</a>` : html`<span></span>`}
90
+ <span class="text-muted-foreground">${__('Page')} ${this.page} / ${pages} · ${this.total} ${__('entries')}</span>
91
+ ${this.page < pages ? html`<a href=${this.link({ page: this.page + 1 })} class="text-primary hover:underline">${__('Older')} →</a>` : html`<span></span>`}</nav>` : null}
92
+ </div>`;
93
+ }
94
+ }
@@ -0,0 +1,131 @@
1
+ import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
2
+ import { input } from '@cossackframework/core/input';
3
+ import { Badge, Button, Card, CardBody, CardHeader, Checkbox, Field, Input, NativeSelect, Textarea } from '@cossackframework/ui';
4
+ import { html, component } from '@cossackframework/renderer';
5
+ import { AUTOMATION_EVENT_LABELS, AUTOMATION_EVENTS, isCmsError, PERMISSIONS, type Automation, type AutomationEvent } from '@cossackframework/cms';
6
+ import { requireAny } from '#app/cms/guards';
7
+ import { linkButton, notice, pageHeader, shortDate } from '#app/cms/ui';
8
+
9
+ interface Form { id: string; name: string; event: AutomationEvent; collection: string; form: string; to: string; subject: string; text: string; active: boolean }
10
+ const EMPTY: Form = { id: '', name: '', event: 'entry.published', collection: '', form: '', to: '', subject: '{{ $.title }} was published', text: '{{ $.title }}\n{{ $.url }}', active: true };
11
+
12
+ /**
13
+ * Tools → Automations: when something happens on the site (an entry is published, a form is
14
+ * submitted, a payment completes), send an email. Templates take the event's variables as
15
+ * {{ $.title }}, {{ $.url }}, {{ $.collection }}, {{ $.values.email }}, {{ $.customerEmail }}. Runs ride
16
+ * the outbox, so a failing action is retried and its last error is shown here. Posting the
17
+ * same events to a URL is Tools → Webhooks.
18
+ */
19
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSettings)] })
20
+ export default class AutomationsPage extends Cossack {
21
+ @State() items: Automation[] = [];
22
+ /** Automations that run as nobody: saved before they had an author, or imported with one who is not on this site. */
23
+ @State() ownerless: string[] = [];
24
+ @State() collections: { name: string; label: string }[] = [];
25
+ @State() forms: { slug: string; title: string }[] = [];
26
+ @State() form: Form = { ...EMPTY };
27
+ @State() error = '';
28
+ @State() message = '';
29
+
30
+ head(): HeadValue {
31
+ return { title: 'Automations' };
32
+ }
33
+
34
+ async init() {
35
+ const cms = this.c.get('cms');
36
+ this.collections = cms.collections().filter(collection => !collection.managed && collection.name !== 'forms').map(collection => ({ name: collection.name, label: collection.label }));
37
+ this.forms = (await cms.forms.all().catch(() => [])).map(form => ({ slug: String(form.record.slug ?? ''), title: String(form.record.title ?? form.record.slug ?? '') })).filter(form => form.slug);
38
+ await this.load(this.c.req.query('id') ?? '');
39
+ }
40
+
41
+ @Server()
42
+ async load(id: string) {
43
+ const cms = this.c.get('cms');
44
+ this.items = await cms.automations.list();
45
+ // Each runs as its author; one with no author who can still act is skipped until someone switches it on again.
46
+ const authors = [...new Set(this.items.map(item => item.author).filter((author): author is string => Boolean(author) && !author!.startsWith('system:')))];
47
+ const acting = new Set((await Promise.all(authors.map(async author => (await cms.users.principal(author).catch(() => null)) ? author : null))).filter(Boolean));
48
+ this.ownerless = this.items.filter(item => !item.author || (!item.author.startsWith('system:') && !acting.has(item.author))).map(item => item.id);
49
+ const found = this.items.find(entry => entry.id === id);
50
+ this.form = found ? { id: found.id, name: found.name, event: found.event, collection: found.conditions?.collection ?? '', form: found.conditions?.form ?? '',
51
+ to: found.action.to ?? '', subject: found.action.subject ?? '', text: found.action.text ?? '', active: found.active } : { ...EMPTY };
52
+ }
53
+
54
+ @Client()
55
+ async submit(event: Event) {
56
+ event.preventDefault();
57
+ this.message = '';
58
+ await this.save(this.form);
59
+ if (!this.error) this.message = this.form.id ? __('Automation saved.') : __('Automation added.');
60
+ }
61
+
62
+ @Server({ input: input.args(input.record<Form>()) })
63
+ async save(form: Form) {
64
+ this.error = '';
65
+ const cms = this.c.get('cms');
66
+ try {
67
+ const saved = await cms.automations.save({
68
+ name: form.name, event: form.event, active: form.active,
69
+ conditions: { ...(form.collection ? { collection: form.collection } : {}), ...(form.form ? { form: form.form } : {}) },
70
+ action: { kind: 'email', to: form.to, subject: form.subject, text: form.text },
71
+ }, { ...(form.id ? { id: form.id } : {}), principal: this.c.get('principal') });
72
+ await this.load(saved.id);
73
+ } catch (error) {
74
+ if (!isCmsError(error)) throw error;
75
+ this.error = error.message;
76
+ }
77
+ }
78
+
79
+ @Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 }), input.boolean()) })
80
+ async toggle(id: string, active: boolean) {
81
+ this.error = '';
82
+ try { await this.c.get('cms').automations.setActive(id, active, this.c.get('principal')); }
83
+ catch (error) { if (!isCmsError(error)) throw error; this.error = error.message; }
84
+ await this.load(this.form.id);
85
+ }
86
+
87
+ @Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 })) })
88
+ async remove(id: string) {
89
+ await this.c.get('cms').automations.delete(id);
90
+ await this.load('');
91
+ }
92
+
93
+ render() {
94
+ const input = (key: keyof Form, label: string, extra: Record<string, unknown> = {}) => component(Field, { label, for: `automation-${key}`, control: attributes => component(Input, { ...attributes, ...extra, '.value': String(this.form[key] ?? ''), '@input': (event: Event) => { this.form = { ...this.form, [key]: (event.target as HTMLInputElement).value }; } }) });
95
+ const select = (key: keyof Form, label: string, options: readonly { value: string; label: string }[], hint?: string) => component(Field, { label, for: `automation-${key}`, ...(hint ? { hint } : {}), control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => { this.form = { ...this.form, [key]: (event.target as HTMLSelectElement).value } as Form; } }, html`
96
+ ${options.map(option => html`<option value=${option.value} ?selected=${this.form[key] === option.value}>${option.label}</option>`)}`) });
97
+ const entryEvent = this.form.event.startsWith('entry.');
98
+ return html`<div class="space-y-6">
99
+ ${pageHeader(__('Automations'), { description: __('When something happens on the site, send an email. Runs are retried like other background work. To post events to a URL, add a webhook.') })}
100
+ ${this.message ? notice(this.message, 'success') : null}
101
+ ${this.error ? notice(this.error, 'error') : null}
102
+ <div class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_28rem]">
103
+ ${component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Automations')}</h2>`)}
104
+ ${component(CardBody, { class: 'p-0' }, this.items.length ? html`<ul class="divide-y divide-border" data-testid="automations">${this.items.map(item => html`<li class="flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-sm" data-automation=${item.id}>
105
+ <span><a href=${`/dashboard/tools/automations?id=${item.id}`} class="font-medium text-foreground hover:underline">${item.name}</a> ${component(Badge, { variant: item.active ? 'success' : 'secondary' }, item.active ? __('On') : __('Off'))}
106
+ <span class="block text-xs text-muted-foreground">${__(AUTOMATION_EVENT_LABELS[item.event])}${item.conditions?.collection ? ` · ${item.conditions.collection}` : ''}${item.conditions?.form ? ` · ${item.conditions.form}` : ''} → ${__('email')} ${item.action.to ?? ''}
107
+ · ${item.runs} ${__('run(s)')}${item.lastRunAt ? ` · ${__('last')} ${shortDate(item.lastRunAt)}` : ''}</span>
108
+ ${this.ownerless.includes(item.id) ? html`<span class="block text-xs text-destructive" data-testid="automation-ownerless">${__('Needs an owner: it runs as nobody, so it sends nothing. Switch it on again to run it as you.')}</span>` : null}
109
+ ${item.lastError ? html`<span class="block text-xs text-destructive">${item.lastError}</span>` : null}</span>
110
+ <span class="flex gap-2">
111
+ ${this.ownerless.includes(item.id) && item.active ? html`<button type="button" class="text-xs text-foreground hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.toggle(item.id, true)}>${__('Run as me')}</button>` : null}
112
+ <button type="button" class="text-xs text-foreground hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.toggle(item.id, !item.active)}>${item.active ? __('Turn off') : __('Turn on')}</button>
113
+ <button type="button" class="text-xs text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.remove(item.id)}>${__('Delete')}</button></span>
114
+ </li>`)}</ul>` : html`<p class="px-4 py-6 text-sm text-muted-foreground">${__('No automations yet. Add one on the right.')}</p>`)}`)}
115
+ ${component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${this.form.id ? __('Edit automation') : __('New automation')}</h2>`)}
116
+ ${component(CardBody, {}, html`<form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
117
+ ${input('name', __('Name'), { required: true, maxlength: 120 })}
118
+ ${select('event', __('When'), AUTOMATION_EVENTS.map(event => ({ value: event, label: __(AUTOMATION_EVENT_LABELS[event]) })))}
119
+ ${entryEvent ? select('collection', __('Only this collection'), [{ value: '', label: __('Any collection') }, ...this.collections.map(collection => ({ value: collection.name, label: collection.label }))]) : null}
120
+ ${this.form.event === 'form.submitted' ? select('form', __('Only this form'), [{ value: '', label: __('Any form') }, ...this.forms.map(form => ({ value: form.slug, label: form.title }))]) : null}
121
+ ${input('to', __('To'), { required: true, placeholder: 'editor@example.com, {{ $.customerEmail }}' })}
122
+ ${input('subject', __('Subject'), { required: true, maxlength: 200 })}
123
+ ${component(Field, { label: __('Text'), for: 'automation-text', hint: __('Variables: {{ $.title }}, {{ $.url }}, {{ $.collection }}, {{ $.status }}, {{ $.values.<field> }} for forms, {{ $.amount }}, {{ $.customerEmail }}, {{ $.reference }} for payments; {{ $site.title }} and {{ $user.name }} as in content.'),
124
+ control: attributes => component(Textarea, { ...attributes, rows: 5, required: true, '.value': this.form.text, '@input': (event: Event) => { this.form = { ...this.form, text: (event.target as HTMLTextAreaElement).value }; } }) })}
125
+ ${component(Checkbox, { label: __('Active'), checked: this.form.active, '@change': (event: Event) => { this.form = { ...this.form, active: (event.target as HTMLInputElement).checked }; } })}
126
+ <div class="flex flex-wrap items-center gap-2">${component(Button, { type: 'submit' }, this.form.id ? __('Save') : __('Add automation'))}${this.form.id ? linkButton(__('New'), '/dashboard/tools/automations', 'outline') : null}</div>
127
+ </form>`)}`)}
128
+ </div>
129
+ </div>`;
130
+ }
131
+ }
@@ -0,0 +1,92 @@
1
+ import { Cossack, Page, State, flash, flashed, type HeadValue } from '@cossackframework/core';
2
+ import { settingsSectionHref } from '#app/cms/settings-search';
3
+ import { Badge, Card, CardBody, CardHeader } from '@cossackframework/ui';
4
+ import { html, component } from '@cossackframework/renderer';
5
+ import { cacheHoldSeconds, cachePurge, isCmsError, isSameOriginPost, PERMISSIONS, type CacheHold } from '@cossackframework/cms';
6
+ import type { PurgeRecord } from '@cossackframework/cms/server';
7
+ import { requireAny } from '#app/cms/guards';
8
+ import { notice, pageHeader, shortDate } from '#app/cms/ui';
9
+ import { actionButton } from '#app/cms/network-view';
10
+
11
+ /**
12
+ * Tools → Cache: what the caches in front of the site are told (Settings → Cache), which
13
+ * purgers changes reach, the last purges run from this process, and a button that purges every
14
+ * page, for a change made outside the CMS.
15
+ */
16
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSettings)] })
17
+ export default class CachePage extends Cossack {
18
+ @State() hold: CacheHold = 'auto';
19
+ @State() seconds = 0;
20
+ /** The purgers the application configured, and the plugins with a `cms.cache.purge` handler. */
21
+ @State() purgers: string[] = [];
22
+ @State() plugins: string[] = [];
23
+ @State() recent: PurgeRecord[] = [];
24
+ @State() message = '';
25
+ @State() error = '';
26
+
27
+ head(): HeadValue {
28
+ return { title: 'Cache' };
29
+ }
30
+
31
+ async init() {
32
+ const cms = this.c.get('cms');
33
+ this.hold = await cms.settings.get('cache.hold');
34
+ this.seconds = cacheHoldSeconds(this.hold, { purging: cms.purge.configured });
35
+ this.purgers = cms.purge.purgers.map(purger => purger.name);
36
+ this.plugins = [...new Set(cms.hooks.handlers(cachePurge).map(handler => handler.plugin).filter(plugin => !plugin.startsWith('cms-purge-')))];
37
+ this.recent = cms.purge.recent;
38
+ this.message = flashed<string>('cache.message') ?? '';
39
+ this.error = flashed<string>('cache.error') ?? '';
40
+ }
41
+
42
+ /** Purge every page now: queued like any purge, then the outbox is run so the result shows at once. */
43
+ async post() {
44
+ if (!isSameOriginPost(this.c.req.raw)) return this.c.text('Forbidden', 403);
45
+ const action = String((await this.c.req.formData()).get('action') ?? '');
46
+ const cms = this.c.get('cms');
47
+ try {
48
+ if (action !== 'purge') throw new Error(__('Unknown action.'));
49
+ const event = await cms.purge.everything('manual');
50
+ await cms.outbox.dispatch({ limit: 10 });
51
+ const failed = cms.purge.recent.filter(record => record.eventId === event.eventId && !record.ok);
52
+ if (failed.length) flash('cache.error', `${failed[0]!.purger}: ${failed[0]!.message}`);
53
+ else flash('cache.message', cms.purge.configured || this.plugins.length ? __('Purged every page of the site.') : __('Queued. No purger is set up, so nothing was told; pages refresh when their hold ends.'));
54
+ } catch (error) {
55
+ flash('cache.error', isCmsError(error) || error instanceof Error ? (error as Error).message : __('The purge could not be queued.'));
56
+ }
57
+ return this.redirect('/dashboard/tools/cache');
58
+ }
59
+
60
+ render() {
61
+ const hold = this.seconds === 0 ? __('Pages are not held: every request reaches the site.')
62
+ : this.seconds >= 86_400 ? `${__('Pages may be held for')} ${Math.round(this.seconds / 86_400)} ${__('day(s)')}.`
63
+ : this.seconds >= 3_600 ? `${__('Pages may be held for')} ${Math.round(this.seconds / 3_600)} ${__('hour(s)')}.`
64
+ : `${__('Pages may be held for')} ${Math.round(this.seconds / 60)} ${__('minute(s)')}.`;
65
+ const purgers = [...this.purgers, ...this.plugins];
66
+ return html`<div class="space-y-6">
67
+ ${pageHeader(__('Cache'), { description: __('What the caches in front of the site are told, and the purges that keep them current.') })}
68
+ ${this.message ? notice(this.message, 'success') : null}
69
+ ${this.error ? notice(this.error, 'error') : null}
70
+ <div class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_24rem]">
71
+ <div class="space-y-6">
72
+ ${component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Recent purges')}</h2>`)}
73
+ ${component(CardBody, { class: 'p-0' }, this.recent.length ? html`<ul class="divide-y divide-border" data-testid="recent-purges">${this.recent.map(record => html`<li class="flex flex-wrap items-center justify-between gap-2 px-4 py-3 text-sm">
74
+ <span><code>${record.reason}</code> <span class="text-muted-foreground">· ${shortDate(record.at)} · ${record.purger} · ${record.tags.length} ${__('tag(s)')}${record.urls.length ? `, ${record.urls.length} ${__('URL(s)')}` : ''}</span>
75
+ ${record.message ? html`<span class="block text-xs text-destructive">${record.message}</span>` : null}</span>
76
+ ${component(Badge, { variant: record.ok ? 'success' : 'destructive' }, record.ok ? __('Purged') : __('Failed'))}
77
+ </li>`)}</ul>` : html`<p class="px-4 py-6 text-sm text-muted-foreground">${purgers.length ? __('No purges from this process yet. Publishing or changing an entry, a menu, a setting or the theme purges the pages it touched.') : __('No purger is set up. Set CLOUDFLARE_API_TOKEN (Zone → Cache Purge and Zone → Zone Read) to purge Cloudflare when pages change, or add a plugin with a cms.cache.purge handler for another CDN.')}</p>`)}`)}
78
+ </div>
79
+ <aside class="space-y-4">
80
+ ${component(Card, {}, component(CardBody, { class: 'space-y-3' }, html`<h2 class="text-base font-semibold text-foreground">${__('Hold')}</h2>
81
+ <p class="text-sm text-muted-foreground" data-testid="cache-hold">${hold}</p>
82
+ <p class="text-xs text-muted-foreground">${__('Anonymous pages say so in Cache-Control; a signed-in user\'s page, Live Edit, previews and protected entries are never held. Change it under')} <a href=${settingsSectionHref('cache')} class="text-primary hover:underline">${__('Settings → Cache')}</a>.</p>
83
+ <p class="text-xs text-muted-foreground">${__('On Cloudflare, add one cache rule for the site: cache everything, using the origin\'s Cache-Control. Crawler counts on Health then see only the requests the cache passes on.')}</p>`))}
84
+ ${component(Card, {}, component(CardBody, { class: 'space-y-3' }, html`<h2 class="text-base font-semibold text-foreground">${__('Purgers')}</h2>
85
+ ${purgers.length ? html`<ul class="space-y-1 text-sm text-foreground" data-testid="purgers">${purgers.map(name => html`<li><code>${name}</code></li>`)}</ul>` : html`<p class="text-sm text-muted-foreground">${__('None.')}</p>`}
86
+ <p class="text-xs text-muted-foreground">${__('Changes purge the pages they touched by themselves. Purge everything after a change made outside the CMS, such as a deploy.')}</p>
87
+ ${actionButton('purge', __('Purge everything'))}`))}
88
+ </aside>
89
+ </div>
90
+ </div>`;
91
+ }
92
+ }
@@ -0,0 +1,99 @@
1
+ import { Cossack, Page, State, flash, flashed, type HeadValue } from '@cossackframework/core';
2
+ import { Card, CardBody } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { hasPermission, holdsAll, isCmsError, isNetworkAdmin, isSameOriginPost, MAIN_SITE, PERMISSIONS } from '@cossackframework/cms';
5
+ import { requireAny } from '#app/cms/guards';
6
+ import { notice, pageHeader, shortDate } from '#app/cms/ui';
7
+ import { actionButton } from '#app/cms/network-view';
8
+
9
+ /** How this site may export its database: at once, or through a network admin's approval. */
10
+ type ExportAccess =
11
+ | { kind: 'download' }
12
+ | { kind: 'request' }
13
+ | { kind: 'requested'; at: number }
14
+ | { kind: 'approved'; until: number };
15
+
16
+ /**
17
+ * Tools → Export: this site's database as a JSON file, or a `.romedb` file where the install
18
+ * can make one. The main site, and sites the network lets export themselves, download at once;
19
+ * other sites ask a network admin, then download for 7 days after the approval.
20
+ */
21
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageSettings)] })
22
+ export default class ExportPage extends Cossack {
23
+ @State() access: ExportAccess = { kind: 'download' };
24
+ /** Whether this user may download the export: it holds every account and submission. */
25
+ @State() exportable = false;
26
+ /** Whether this user may have this site's `.romedb` file. */
27
+ @State() files = false;
28
+ @State() message = '';
29
+ @State() error = '';
30
+
31
+ head(): HeadValue {
32
+ return { title: 'Export' };
33
+ }
34
+
35
+ async init() {
36
+ const site = this.c.get('site');
37
+ const { allowed, request } = await this.c.get('network').exportAccess(site?.id ?? MAIN_SITE);
38
+ this.access = allowed ? request?.expiresAt ? { kind: 'approved', until: request.expiresAt } : { kind: 'download' }
39
+ : request ? { kind: 'requested', at: request.requestedAt } : { kind: 'request' };
40
+ const principal = this.c.get('principal');
41
+ this.exportable = await this.mayExport();
42
+ this.files = this.exportable && (site?.id !== MAIN_SITE || isNetworkAdmin(principal));
43
+ this.message = flashed<string>('export.message') ?? '';
44
+ this.error = flashed<string>('export.error') ?? '';
45
+ }
46
+
47
+ /** A network admin, or someone who manages users and holds every permission a role gives: the export holds them all. */
48
+ private async mayExport(): Promise<boolean> {
49
+ const principal = this.c.get('principal');
50
+ if (isNetworkAdmin(principal)) return true;
51
+ if (!hasPermission(principal, PERMISSIONS.manageUsers)) return false;
52
+ const roles = await this.c.get('cms').users.roles();
53
+ return holdsAll(principal, roles.flatMap(role => role.permissions));
54
+ }
55
+
56
+ async post() {
57
+ if (!isSameOriginPost(this.c.req.raw)) return this.c.text('Forbidden', 403);
58
+ const action = String((await this.c.req.formData()).get('action') ?? '');
59
+ const site = this.c.get('site');
60
+ const network = this.c.get('network');
61
+ try {
62
+ // Asking for an export, or withdrawing a request or an approval, is for those who may download it.
63
+ if (!await this.mayExport()) throw new Error(__('You cannot export this site.'));
64
+ if (!site || site.id === MAIN_SITE) throw new Error(__('This site downloads its export at once.'));
65
+ if (action === 'request') {
66
+ await network.requestExport(site.id, { principal: this.c.get('principal') });
67
+ flash('export.message', __('Requested. A network admin will review it; you can download the export here once it is approved.'));
68
+ } else if (action === 'withdraw') {
69
+ await network.withdrawExport(site.id, { principal: this.c.get('principal') });
70
+ flash('export.message', __('Request withdrawn.'));
71
+ }
72
+ } catch (error) {
73
+ flash('export.error', isCmsError(error) || error instanceof Error ? (error as Error).message : __('The request could not be sent.'));
74
+ }
75
+ return this.redirect('/dashboard/tools/export');
76
+ }
77
+
78
+ render() {
79
+ const download = !this.exportable ? notice(__('The export holds every account and submission: only an administrator who may manage all of them downloads it.'), 'info') : html`<div class="flex flex-wrap gap-2">
80
+ <a href="/api/cms/site-export" download class="inline-flex items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground no-underline">${__('Download export')}</a>
81
+ ${this.files ? html`<a href="/api/cms/site-export?format=romedb" download data-database-file class="inline-flex items-center justify-center rounded-md border border-border px-4 py-2 text-sm font-medium text-foreground no-underline hover:bg-muted">${__('Download database file')}</a>` : null}
82
+ </div>`;
83
+ const body = this.access.kind === 'download' ? html`<p class="text-sm text-muted-foreground">${__('One JSON file with every table of this site\'s database: content, settings, collections, terms, menus, comments, forms and members.')}</p>${download}`
84
+ : this.access.kind === 'approved' ? html`<p class="text-sm text-muted-foreground">${__('A network admin approved the export.')} ${this.access.until ? `${__('Download it until')} ${shortDate(this.access.until)}.` : ''}</p>${download}`
85
+ : this.access.kind === 'requested' ? html`<p class="text-sm text-muted-foreground">${__('Requested on')} ${shortDate(this.access.at)}. ${__('A network admin will review it; the download appears here once it is approved.')}</p>
86
+ ${actionButton('withdraw', __('Withdraw request'))}`
87
+ : html`<p class="text-sm text-muted-foreground">${__('This site belongs to a network: a network admin approves its export. Once approved, the download appears here for 7 days.')}</p>
88
+ ${actionButton('request', __('Request export'))}`;
89
+ return html`<div class="space-y-6">
90
+ ${pageHeader(__('Export'), { description: __('Download this site\'s database to keep a copy or move the site.') })}
91
+ ${this.message ? notice(this.message, 'success') : null}
92
+ ${this.error ? notice(this.error, 'error') : null}
93
+ ${component(Card, { class: 'max-w-2xl' }, component(CardBody, { class: 'space-y-4' }, html`${body}
94
+ <p class="text-xs text-muted-foreground">${__('Sessions, passwords, second factors, application passwords and webhook secrets stay out. Media files are not included; their records are.')}</p>
95
+ <p class="text-xs text-muted-foreground">${__('To move the site, import the file into a new install at its setup, or into a new site of a network from its page under Network → Sites.')}</p>
96
+ ${this.files ? html`<p class="text-xs text-muted-foreground">${__('The database file is a .romedb file that a new install opens directly, for sites too large to import. It keeps the site\'s own accounts with their password hashes and authenticator secrets, so keep it private. Sessions, webhooks and pending work stay out.')}</p>` : null}`))}
97
+ </div>`;
98
+ }
99
+ }