@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,99 @@
1
+ /**
2
+ * Editing an entry on the public site: the draft a site page keeps in edit mode and block
3
+ * moves. Client-safe and small, since site pages ship it to every visitor; the editor itself is
4
+ * `site-editor.client.ts`, loaded only in edit mode, and the bar that opens it is the site
5
+ * taskbar (`taskbar.ts`).
6
+ */
7
+ import type { Note } from '@cossackframework/cms';
8
+ import type { Someone } from './collab/presence';
9
+ import type { EditorBlock, EditorValues, EditorView } from './editor';
10
+ import type { MediaPreview } from './field-controls';
11
+ import type { MediaChooserState } from './media-chooser';
12
+
13
+ /** Who may edit the entry a site page shows, for its bar. Null for everyone else. */
14
+ export interface SiteEditable {
15
+ collection: string;
16
+ id: string;
17
+ /** The entry in the dashboard's editor. */
18
+ dashboard: string;
19
+ }
20
+
21
+ /**
22
+ * A block list edited beside the entry: one of the theme's widget areas on the page, or a synced
23
+ * pattern the page shows (in the content, an area or a menu panel), with its own revision and
24
+ * permission. The entry's own blocks are the `entry` document.
25
+ */
26
+ export interface SiteDocument {
27
+ /** `area:<name>` or `pattern:<id>`. */
28
+ key: string;
29
+ kind: 'area' | 'pattern';
30
+ /** The area's name, or the pattern's ID. */
31
+ name: string;
32
+ label: string;
33
+ /** 0 until the site saves the area: the theme's default blocks show. */
34
+ revision: number;
35
+ blocks: EditorBlock[];
36
+ /** The user may change it (`cms:appearance` for an area). A locked document shows its markers, but nothing in it selects. */
37
+ editable: boolean;
38
+ changed: boolean;
39
+ error: string;
40
+ /** Someone saved the area since the draft started. */
41
+ conflict: boolean;
42
+ }
43
+
44
+ /** The entry being edited on the site: control values as the dashboard editor keeps them, and the page's areas beside it. */
45
+ export interface SiteDraft {
46
+ collection: string;
47
+ id: string;
48
+ /** The revision the draft started from; saving with another one is a conflict. */
49
+ rev: number;
50
+ view: EditorView;
51
+ values: EditorValues;
52
+ previews: Record<string, MediaPreview>;
53
+ /** Reference fields' choices. */
54
+ references: Record<string, { id: string; title: string }[]>;
55
+ /** The entry's blocks field and rich text body, edited in place; null when it has none. */
56
+ blocksField: string | null;
57
+ bodyField: string | null;
58
+ /** The page's widget areas, each saved on its own. */
59
+ documents: SiteDocument[];
60
+ /** Changes since the last save. */
61
+ changed: boolean;
62
+ error: string;
63
+ errors: Record<string, string>;
64
+ /** Someone else saved the entry since the draft started. */
65
+ conflict: boolean;
66
+ chooser: MediaChooserState;
67
+ /** The entry's review notes, and who they name; written through the content API, since the site has no room. */
68
+ notes: Note[];
69
+ people: Record<string, Someone>;
70
+ /** The editor's user ID, and whether they remove anyone's notes. */
71
+ me: string;
72
+ admin: boolean;
73
+ mentionable: { id: string; name: string }[];
74
+ }
75
+
76
+ /** A block as the draft holds it: data as control values, nested blocks under a container. */
77
+ export type DraftBlock = EditorBlock;
78
+
79
+ export { blockRows, nestRows, reorderBlocks } from './block-rows';
80
+
81
+ /** The handlers a site page gives the editor; each change is kept in the page's draft. */
82
+ export type SiteEditorProps = {
83
+ draft: SiteDraft;
84
+ saving: boolean;
85
+ /** Keep new values; `preview` renders the page from them. */
86
+ onChange(values: EditorValues, preview: boolean): void;
87
+ onSave(): void;
88
+ /** Leave edit mode; unsaved changes are dropped. */
89
+ onExit(): void;
90
+ /** Start again from the saved entry, after a conflict. */
91
+ onReload(): void;
92
+ onSearchMedia(search: string): void;
93
+ onChooser(state: MediaChooserState): void;
94
+ onPreviews(previews: Record<string, MediaPreview>): void;
95
+ /** The notes changed through the API: keep them in the draft. */
96
+ onNotes(notes: Note[]): void;
97
+ /** A document's blocks changed; the layout previews them. */
98
+ onDocumentChange(key: string, blocks: EditorBlock[]): void;
99
+ };
@@ -0,0 +1,60 @@
1
+ /** Site exports as downloads, for the export endpoints. Server only. */
2
+ import { ClientError, type DatabaseFile } from '@cossackframework/romedb';
3
+ import { siteExport, siteFile, type CmsHost, type NetworkSite } from '@cossackframework/cms/server';
4
+
5
+ /**
6
+ * A site's database export as a download, `<site>-<date>.json`, streamed table by table. The
7
+ * first chunk is read before answering, so a database that cannot be read fails with an error
8
+ * instead of a cut-off file.
9
+ */
10
+ export async function exportResponse(host: CmsHost, site: Pick<NetworkSite, 'id' | 'host'>, name: string): Promise<Response> {
11
+ const chunks = siteExport(host.db, { site: { id: site.id, name, host: site.host }, now: () => host.now() });
12
+ const first = await chunks.next();
13
+ const encoder = new TextEncoder();
14
+ const body = new ReadableStream<Uint8Array>({
15
+ start(controller) { if (!first.done) controller.enqueue(encoder.encode(first.value)); },
16
+ async pull(controller) {
17
+ const next = await chunks.next();
18
+ if (next.done) controller.close(); else controller.enqueue(encoder.encode(next.value));
19
+ },
20
+ async cancel() { await chunks.return(undefined); },
21
+ });
22
+ const date = new Date(host.now()).toISOString().slice(0, 10);
23
+ return new Response(body, { headers: {
24
+ 'content-type': 'application/json; charset=utf-8', 'cache-control': 'private, no-store',
25
+ 'content-disposition': `attachment; filename="${site.id}-${date}.json"`,
26
+ } });
27
+ }
28
+
29
+ /**
30
+ * A site's database as a download, `<site>-<date>.romedb`, which a new install opens directly.
31
+ * Its accounts come along, so a site's own accounts keep their passwords; sessions, webhooks and
32
+ * pending work do not.
33
+ */
34
+ export async function fileExportResponse(host: CmsHost, site: Pick<NetworkSite, 'id'>, signal: AbortSignal): Promise<Response> {
35
+ let file;
36
+ try { file = await siteFile(host.db, { signal }); }
37
+ catch (error) {
38
+ if (!(error instanceof ClientError)) throw error;
39
+ // RomeDB builds one copy of a database at a time, and Cloud one across the service.
40
+ if (error.code === 'RDB_BUSY') return Response.json({ error: 'Another database copy is being made. Try again in a moment.', code: 'CMS_UNAVAILABLE' }, { status: 503, headers: { 'retry-after': String(Math.ceil((error.retryAfterMs ?? 30_000) / 1000)) } });
41
+ // RomeDB's deadline passed, rather than the visitor leaving: a large copy can take longer on Cloud.
42
+ if (error.code === 'RDB_CANCELLED' && !signal.aborted) return Response.json({ error: 'The database copy took too long to make. Download the JSON export instead.', code: 'CMS_UNAVAILABLE' }, { status: 504 });
43
+ throw error;
44
+ }
45
+ const date = new Date(host.now()).toISOString().slice(0, 10);
46
+ return new Response(sized(file), { headers: {
47
+ 'content-type': 'application/vnd.romedb.database', 'content-length': String(file.size), 'cache-control': 'private, no-store',
48
+ 'content-disposition': `attachment; filename="${site.id}-${date}.romedb"`,
49
+ } });
50
+ }
51
+
52
+ /**
53
+ * The file's bytes, with a length the runtime can send. Workers drop `content-length` from a
54
+ * stream they cannot measure, and a browser then shows no progress and cannot tell a cut-off
55
+ * download from a finished one.
56
+ */
57
+ function sized(file: DatabaseFile): ReadableStream<Uint8Array> {
58
+ const { FixedLengthStream } = globalThis as { FixedLengthStream?: new (length: number) => TransformStream<Uint8Array, Uint8Array> };
59
+ return FixedLengthStream ? file.body.pipeThrough(new FixedLengthStream(file.size)) : file.body;
60
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Forms placed on site pages. Each `core/form` block gets its form's view: the form's blocks
3
+ * rendered, every input with its value and error, from the post that came back (`?form=`
4
+ * and `?result=`) or from the form's defaults and the page's query. Server-only.
5
+ */
6
+ import {
7
+ escapeHtml, flatFormInputs, formVisibility, isRows, rowValues, TEMPLATE_ROW, validateSubmission,
8
+ type Block, type FormField, type FormRow, type FormValue, type FormValues, type FormView, type InputKind, type ItemsView, type PostedValue, type Principal, type RenderedBlock, type RepeaterView,
9
+ } from '@cossackframework/cms';
10
+ import { renderMarkdown, type CmsHost, type LoadedForm } from '@cossackframework/cms/server';
11
+
12
+ /** What a page tells its forms about the request. */
13
+ export interface FormRequest {
14
+ /** The page's query: `form` and `result` after a post, and values for hidden fields. */
15
+ readonly query: { readonly [name: string]: string };
16
+ readonly principal: Principal;
17
+ /** The page's path, where a post returns. */
18
+ readonly url: string;
19
+ }
20
+
21
+ /** What a form post keeps for its page, read once after the redirect. */
22
+ export interface FormResult {
23
+ /** `edit`: the form again with these values, after a row was added or removed without the page's script. */
24
+ readonly kind: 'success' | 'error' | 'edit';
25
+ /** Escaped HTML: the confirmation, or what went wrong. */
26
+ readonly html: string;
27
+ readonly errors?: { readonly [name: string]: string };
28
+ /** What the sender typed, to fill the form again. */
29
+ readonly values?: { readonly [name: string]: PostedValue };
30
+ }
31
+
32
+ /** The values a returning post shows: as typed, with ticked boxes as yes and a repeater's rows typed the same way. */
33
+ export function typedValues(inputs: readonly FormField[], raw: { readonly [name: string]: unknown }): FormValues {
34
+ const values: { [name: string]: FormValue } = {};
35
+ for (const input of inputs) {
36
+ const entry = raw[input.name];
37
+ // A page cannot fill in a file control: files are chosen again.
38
+ if (entry === undefined || entry === null || input.kind === 'file') continue;
39
+ if (input.kind === 'rows') {
40
+ if (!Array.isArray(entry)) continue;
41
+ values[input.name] = entry.filter((row): row is { [name: string]: unknown } => !!row && typeof row === 'object' && !Array.isArray(row))
42
+ .map((row, index): FormRow => ({ ...typedValues(input.inputs, row), _id: typeof row._id === 'string' && /^[A-Za-z0-9_-]{1,40}$/.test(row._id) ? row._id : `r${index + 1}` }));
43
+ }
44
+ else if (input.kind === 'boolean') values[input.name] = entry === true || entry === 'on' || entry === 'true';
45
+ else if (input.multiple) values[input.name] = (Array.isArray(entry) ? entry : [entry]).map(item => typeof item === 'number' ? item : String(item ?? '')) as string[] | number[];
46
+ else if (input.kind === 'choices') values[input.name] = Array.isArray(entry) ? entry.filter((item): item is string => typeof item === 'string') : [String(entry)];
47
+ else values[input.name] = Array.isArray(entry) ? String(entry[0] ?? '') : typeof entry === 'number' ? entry : String(entry);
48
+ }
49
+ return values;
50
+ }
51
+
52
+ /** A row's starting values: the row's inputs' defaults. */
53
+ function rowDefaults(input: FormField): FormValues {
54
+ const values: { [name: string]: FormValue } = {};
55
+ for (const child of input.inputs) {
56
+ const fallback = child.data.defaultValue;
57
+ if (fallback !== undefined && fallback !== null && fallback !== '') values[child.name] = fallback as FormValue;
58
+ }
59
+ return values;
60
+ }
61
+
62
+ /**
63
+ * The view of a form for a page. `render` turns stored blocks into rendered ones, with their
64
+ * Markdown and media, as the page renders its other blocks.
65
+ */
66
+ export async function formView(cms: CmsHost, form: LoadedForm, request: FormRequest, render: (block: Block) => RenderedBlock): Promise<FormView> {
67
+ const { slug } = form.ref;
68
+ const types = cms.blockTypes;
69
+ const kinds: { [type: string]: InputKind } = {};
70
+ for (const input of flatFormInputs(form.ref.inputs)) kinds[input.type] = input.kind;
71
+ const base = { id: form.ref.id, slug, title: form.ref.title, action: `/api/cms/forms/${slug}`, page: request.url, submitLabel: form.settings.submitLabel || 'Submit', startedAt: cms.now(), kinds };
72
+ const empty = { blocks: [], notice: null, closed: null, signInUrl: null, turnstileSiteKey: null };
73
+ const result = request.query.form === slug && request.query.result ? await cms.forms.takeResult(form.ref.id, request.query.result) as FormResult | null : null;
74
+ if (result?.kind === 'success') return { ...base, ...empty, notice: { kind: 'success', html: result.html } };
75
+ const closed = await cms.forms.closed(form);
76
+ if (closed !== null) return { ...base, ...empty, closed: renderMarkdown(closed) };
77
+ if ((form.settings.requireSignIn || form.settings.oncePerUser) && request.principal.kind !== 'user') {
78
+ return { ...base, ...empty, signInUrl: `/auth/login?next=${encodeURIComponent(request.url)}` };
79
+ }
80
+ const values = result?.values ? typedValues(form.ref.inputs, result.values) : await cms.forms.prefill(form, request.query, request.principal);
81
+ const errors = result?.errors ?? {};
82
+ // Conditions see the values a submission would keep; a repeater's rows have theirs under `<row id>:<block id>`.
83
+ const check = validateSubmission(form.blocks, types, values);
84
+ const hidden = new Set([...formVisibility(form.blocks, types, check.values).hidden, ...check.hidden]);
85
+ const inputs = new Map(form.ref.inputs.map(input => [input._id, input]));
86
+ /** A block with its input's state. In a repeater's row, ids and names are the row's. */
87
+ const withState = (block: RenderedBlock, row: { readonly id: string; readonly repeater: FormField; readonly values: FormValues } | null): RenderedBlock => {
88
+ const input = row ? row.repeater.inputs.find(child => child._id === block._id) : inputs.get(block._id);
89
+ const id = row ? `${row.id}:${block._id}` : block._id;
90
+ const key = row && input ? `${row.repeater.name}.${row.id}.${input.name}` : input?.name ?? '';
91
+ const name = row && input ? `${row.repeater.name}[${row.id}][${input.name}]` : input?.name ?? '';
92
+ const value = row ? row.values[input?.name ?? ''] : values[input?.name ?? ''];
93
+ const items = (): ItemsView => {
94
+ // A multiple input: its posted items in their positions, blanks included so the errors line up, or the fewest controls it needs (one, so the visitor sees what it asks).
95
+ const posted = Array.isArray(value) ? (value as readonly (string | number)[]).map(String) : value !== undefined && value !== null && value !== '' ? [String(value)] : [];
96
+ const min = typeof input!.data.minItems === 'number' ? input!.data.minItems : 0;
97
+ const list = posted.length ? posted : Array.from({ length: Math.max(min, 1) }, () => '');
98
+ return {
99
+ values: list, errors: list.map((_, index) => errors[`${key}.${index + 1}`] ?? ''),
100
+ min, max: typeof input!.data.maxItems === 'number' ? input!.data.maxItems : 50,
101
+ addLabel: typeof input!.data.addLabel === 'string' && input!.data.addLabel ? input!.data.addLabel : 'Add another',
102
+ };
103
+ };
104
+ const state: RenderedBlock = {
105
+ ...block, _id: id,
106
+ ...(block.when ? { shown: !hidden.has(id) } : {}),
107
+ ...(input ? { input: { name, key, kind: input.kind, id: `form-${slug}-${key.replaceAll('.', '-')}`, value: value ?? null, error: errors[key] ?? '', options: input.options, ...(input.multiple ? { items: items() } : {}) } } : {}),
108
+ ...(block.children ? { children: block.children.map(child => withState(child, row)) } : {}),
109
+ };
110
+ if (!input || input.kind !== 'rows' || row) return state;
111
+ // A repeater: its rows from the values, or the fewest rows it needs (one, so the visitor sees what a row asks), and the template of a new row.
112
+ const posted = isRows(values[input.name]) ? values[input.name] as readonly FormRow[] : [];
113
+ const fewest = Math.max(typeof input.data.min === 'number' ? input.data.min : 0, 1);
114
+ const rows = posted.length ? posted.map(entry => ({ id: entry._id, values: rowValues(entry) })) : Array.from({ length: fewest }, (_, index) => ({ id: `r${index + 1}`, values: rowDefaults(input) }));
115
+ const children = block.children ?? [];
116
+ const rowBlocks = (entry: { id: string; values: FormValues }) => {
117
+ // A row the visitor has not posted yet: its conditions settle on its defaults over the form's values.
118
+ if (!posted.length || entry.id === TEMPLATE_ROW) for (const off of formVisibility(children, types, { ...check.values, ...entry.values }).hidden) hidden.add(`${entry.id}:${off}`);
119
+ return children.map(child => withState(child, { id: entry.id, repeater: input, values: entry.values }));
120
+ };
121
+ const repeater: RepeaterView = {
122
+ rows: rows.map(entry => ({ id: entry.id, blocks: rowBlocks(entry) })),
123
+ template: rowBlocks({ id: TEMPLATE_ROW, values: rowDefaults(input) }),
124
+ min: typeof input.data.min === 'number' ? input.data.min : 0, max: typeof input.data.max === 'number' ? input.data.max : 50,
125
+ addLabel: typeof input.data.addLabel === 'string' && input.data.addLabel ? input.data.addLabel : 'Add another',
126
+ rowLabel: typeof input.data.rowLabel === 'string' ? input.data.rowLabel : '',
127
+ error: errors[input.name] ?? '',
128
+ };
129
+ return { ...state, repeater };
130
+ };
131
+ const siteKey = env('TURNSTILE_SITE_KEY', '');
132
+ return {
133
+ ...base, ...empty,
134
+ blocks: form.blocks.map(block => withState(render(block), null)),
135
+ notice: result?.kind === 'error' ? { kind: 'error', html: result.html } : null,
136
+ turnstileSiteKey: form.settings.turnstile && siteKey && env('TURNSTILE_SECRET_KEY', '') ? siteKey : null,
137
+ };
138
+ }
139
+
140
+ /** A visitor-facing message as one escaped paragraph. */
141
+ export function messageHtml(text: string): string {
142
+ return `<p>${escapeHtml(text)}</p>`;
143
+ }
@@ -0,0 +1,28 @@
1
+ /** Site imports from a page's POST, for setup and the network's site page. Server only. */
2
+ import type { Context } from 'hono';
3
+ import { CmsError } from '@cossackframework/cms';
4
+ import { siteImport, type CmsHost, type SiteImportReport } from '@cossackframework/cms/server';
5
+
6
+ /** Whether the POST carries an export as its body: the browser sends the file itself. */
7
+ export function sendsExport(c: Context): boolean {
8
+ return (c.req.header('content-type') ?? '').startsWith('application/json');
9
+ }
10
+
11
+ /** Import the export in the request: its body, or a multipart form's `file`. */
12
+ export async function importRequest(c: Context, host: CmsHost): Promise<SiteImportReport> {
13
+ let body: ReadableStream<Uint8Array> | null = null;
14
+ if (sendsExport(c)) body = c.req.raw.body;
15
+ else {
16
+ const file = (await c.req.formData()).get('file');
17
+ if (file instanceof File && file.size > 0) body = file.stream();
18
+ }
19
+ if (!body) throw new CmsError('CMS_VALIDATION', 'Choose an export file.');
20
+ return siteImport(host, body, { signal: c.req.raw.signal });
21
+ }
22
+
23
+ /** What the import brought in, for the page's message. */
24
+ export function importSummary(report: SiteImportReport): string {
25
+ const members = report.members.network + report.members.site + report.members.pending;
26
+ return `Imported ${report.site.name || report.site.id}: ${report.rows} rows in ${report.tables} tables, ${members} ${members === 1 ? 'member' : 'members'}.`
27
+ + (report.skipped.length ? ` Left out, with no table here: ${report.skipped.join(', ')}.` : '');
28
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The Live Edit session the site page and the site layout share in the browser. The page edits
3
+ * the entry and the page's widget areas (`SiteDocument`s); the frame around the entry is the
4
+ * layout's, so the layout previews the areas from this store through its own server method and
5
+ * reloads the saved ones when the session ends. Client-safe and tiny: it holds state only.
6
+ */
7
+ import { createStore } from '@cossackframework/core';
8
+ import type { EditorBlock } from './editor';
9
+
10
+ /** An area's blocks as the editor holds them: control values. */
11
+ export interface AreaDraft { name: string; blocks: EditorBlock[] }
12
+ /** A synced pattern's blocks as the editor holds them, by the pattern's ID. */
13
+ export interface PatternDraft { id: string; blocks: EditorBlock[] }
14
+
15
+ export interface SiteEditingSession {
16
+ areas: AreaDraft[];
17
+ patterns: PatternDraft[];
18
+ }
19
+
20
+ /** What the page tells the layout at render time, so the areas render with their markers from the first paint. */
21
+ export interface SiteEditingContext {
22
+ areas: AreaDraft[];
23
+ /** The signed-in user may change the areas; otherwise they are marked but locked. */
24
+ editable: boolean;
25
+ /** The synced patterns on the page, and whether the user may change each. */
26
+ patterns: { id: string; editable: boolean }[];
27
+ }
28
+
29
+ declare module 'hono' {
30
+ interface ContextVariableMap {
31
+ 'cms.editing': SiteEditingContext | undefined;
32
+ }
33
+ }
34
+
35
+ /** Null outside edit mode and before the editor's first change. */
36
+ export const siteSession = createStore<SiteEditingSession | null>(null);
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Builds the site taskbar's view for the signed-in user and the page they are on. Server-only:
3
+ * the site layout's `server$` resource runs it during render, after the page's `init()` has
4
+ * described the page through `c.set('cms.taskbar', …)`.
5
+ */
6
+ import type { Context } from 'hono';
7
+ import { settingsSectionHref } from './settings-search';
8
+ import type { User } from '@cossackframework/core';
9
+ import { ANONYMOUS, evaluateRule, hasPermission, PERMISSIONS, type Principal } from '@cossackframework/cms';
10
+ import type { CmsHost } from '@cossackframework/cms/server';
11
+ import { siteHasLogo, siteLogo, siteName } from '../brand';
12
+ import { navigation } from '../dashboard/access';
13
+ import { icon } from './icons';
14
+ import type { Resolved } from './site';
15
+ import type { TaskbarLink, TaskbarPage, TaskbarView } from './taskbar';
16
+
17
+ export async function siteTaskbar(c: Context, user: User | undefined): Promise<TaskbarView | null> {
18
+ const principal: Principal = c.get('principal') ?? ANONYMOUS;
19
+ if (!user || principal.kind !== 'user') return null;
20
+ const cms = c.get('cms');
21
+ try {
22
+ const modules = await navigation(c);
23
+ const nested = (parent: string | undefined) => !!parent && modules.some(module => module.id === parent);
24
+ const start: TaskbarLink[] = [
25
+ { label: 'Dashboard', href: '/dashboard', icon: icon('widget-2') },
26
+ ...modules.filter(module => module.placement !== 'account' && !nested(module.parent)).map(module => ({ label: module.label, href: module.href, icon: module.icon })),
27
+ ];
28
+ const account = modules.filter(module => module.placement === 'account').map(module => ({ label: module.label, href: module.href, icon: module.icon }));
29
+ const create: TaskbarLink[] = [];
30
+ for (const collection of cms.collections()) {
31
+ if (evaluateRule(cms.resourceById(`cms/${collection.name}`).access.create, principal) === 'deny') continue;
32
+ create.push({ label: `New ${collection.singular.toLowerCase()}`, href: `/dashboard/content/${collection.name}/new`, icon: icon(collection.icon) });
33
+ }
34
+ if (hasPermission(principal, PERMISSIONS.upload) || hasPermission(principal, PERMISSIONS.manageMedia)) create.push({ label: 'Upload file', href: '/dashboard/media/new', icon: icon('folder-with-files') });
35
+ const page = c.get('cms.taskbar');
36
+ const plugins = (await cms.slotLinks('site.taskbar', principal).catch(() => [])).map(link => ({ label: link.label, href: link.href }));
37
+ return {
38
+ site: { title: await siteName(), logo: await siteLogo(), logoOnly: await siteHasLogo() },
39
+ start,
40
+ context: pageContext(cms, principal, c.get('cms.site'), page, c.req.path),
41
+ create,
42
+ plugins,
43
+ seo: page?.seo ?? null,
44
+ user: { name: user.name || user.email, email: user.email, avatar: user.avatar ?? null, links: account },
45
+ };
46
+ } catch {
47
+ // Before setup, or while content is unavailable, the bar stays away rather than failing the page.
48
+ return null;
49
+ }
50
+ }
51
+
52
+ /** The current page's tools: editing the entry shown, or managing what the page lists. */
53
+ function pageContext(cms: CmsHost, principal: Principal, resolved: Resolved | { kind: 'unavailable' } | undefined, page: TaskbarPage | undefined, path: string): TaskbarView['context'] {
54
+ const can = (permission: string) => hasPermission(principal, permission);
55
+ const links: TaskbarLink[] = [];
56
+ const entry = page?.entry ?? null;
57
+ if (entry) {
58
+ // Live Edit edits the page in place; Edit opens the entry in the dashboard's editor.
59
+ links.push({ label: 'Edit', href: entry.dashboard, icon: icon('pen') });
60
+ return { status: entry.status || null, edit: entry.inPlace ? `${path}?edit` : null, links };
61
+ }
62
+ const kind = resolved?.kind ?? (path === '/' ? 'home' : 'other');
63
+ if (resolved?.kind === 'archive') {
64
+ const collection = resolved.collection;
65
+ const readable = evaluateRule(cms.resourceById(`cms/${collection.name}`).access.create, principal) !== 'deny' || can(`cms/${collection.name}:update`) || can(`cms/${collection.name}:read`);
66
+ if (readable) links.push({ label: `All ${collection.label.toLowerCase()}`, href: `/dashboard/content/${collection.name}`, icon: icon(collection.icon) });
67
+ } else if (resolved?.kind === 'term' && can(PERMISSIONS.manageTerms)) {
68
+ const taxonomy = cms.taxonomies.declaration(resolved.term.taxonomy);
69
+ links.push({ label: `Edit ${taxonomy.singular.toLowerCase()}`, href: `/dashboard/terms/${resolved.term.taxonomy}/${resolved.term.id}`, icon: icon('tag') });
70
+ } else if (resolved?.kind === 'author' && can(PERMISSIONS.manageUsers)) {
71
+ links.push({ label: 'Edit user', href: `/dashboard/users/${resolved.user.id}`, icon: icon('user') });
72
+ } else if (kind === 'home' && can(PERMISSIONS.manageSettings)) {
73
+ links.push({ label: 'Reading settings', href: settingsSectionHref('reading'), icon: icon('settings') });
74
+ }
75
+ // A list page: the header and footer are still editable in place for whoever may change the theme's areas.
76
+ return { status: null, edit: page?.frame ? `${path}?edit` : null, links };
77
+ }