@cossackframework/cms 0.0.0 → 0.9.2

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 +145 -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 +21 -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 +709 -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 +114 -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 +62 -0
  110. package/app/src/dashboard/avatar-field.ts +58 -0
  111. package/app/src/dashboard/bulk.ts +22 -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 +28 -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 +18 -0
  121. package/app/src/dashboard/session-list.ts +98 -0
  122. package/app/src/dashboard/tabs.ts +2 -0
  123. package/app/src/dashboard/time-ago.ts +16 -0
  124. package/app/src/dashboard/types.ts +43 -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 +82 -0
  212. package/app/src/pages/auth/layout.ts +32 -0
  213. package/app/src/pages/auth/login/index.ts +205 -0
  214. package/app/src/pages/auth/magic/index.ts +68 -0
  215. package/app/src/pages/auth/register/index.ts +124 -0
  216. package/app/src/pages/auth/reset-password/index.ts +74 -0
  217. package/app/src/pages/auth/setup/index.ts +194 -0
  218. package/app/src/pages/auth/two-factor/index.ts +69 -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 +183 -0
  278. package/app/src/pages/dashboard/index.ts +214 -0
  279. package/app/src/pages/dashboard/layout.ts +227 -0
  280. package/app/src/pages/dashboard/profile/index.ts +211 -0
  281. package/app/src/pages/dashboard/profile/security/index.ts +249 -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 +114 -2
  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,183 @@
1
+ import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
2
+ import { input } from '@cossackframework/core/input';
3
+ import { AlertDialog, Badge, Button, Card, CardBody, CardHeader, Checkbox, CopyField, Field, Input } from '@cossackframework/ui';
4
+ import { html, component } from '@cossackframework/renderer';
5
+ import { isCmsError, PERMISSIONS, WEBHOOK_EVENTS, type Webhook, type WebhookDelivery, type WebhookEvent } from '@cossackframework/cms';
6
+ import { requireAny } from '#app/cms/guards';
7
+ import { notice, pageHeader, shortDate } from '#app/cms/ui';
8
+
9
+ const EVENT_LABELS: Record<WebhookEvent, string> = {
10
+ 'entry.created': 'An entry is created', 'entry.updated': 'An entry changes', 'entry.published': 'An entry is published',
11
+ 'entry.unpublished': 'An entry is unpublished', 'entry.deleted': 'An entry is deleted', 'form.submitted': 'A form is submitted',
12
+ 'note.created': 'A note is left on an entry', 'note.resolved': 'A note is resolved', 'payment.completed': 'A payment is completed',
13
+ };
14
+
15
+ interface Form { id: string; name: string; url: string; events: string[]; collections: string[]; active: boolean }
16
+ const EMPTY: Form = { id: '', name: '', url: '', events: ['entry.published', 'entry.unpublished'], collections: [], active: true };
17
+
18
+ /**
19
+ * Webhooks post entry events to other services, such as a static site's build hook. Each
20
+ * delivery is signed with the webhook's secret and retried with backoff when it fails.
21
+ */
22
+ @Page({ transport: 'http', middlewares: [requireAny(PERMISSIONS.manageWebhooks)] })
23
+ export default class WebhooksPage extends Cossack {
24
+ @State() hooks: Webhook[] = [];
25
+ @State() collections: { name: string; label: string }[] = [];
26
+ @State() form: Form = { ...EMPTY, events: [...EMPTY.events] };
27
+ @State() deliveries: WebhookDelivery[] = [];
28
+ @State() selected = '';
29
+ /** The selected webhook's secret, once shown: lists carry only its first characters. */
30
+ @State() revealed = '';
31
+ @State() error = '';
32
+ /** What the last save or test did. */
33
+ @State() message = '';
34
+ @State() pendingDelete: Webhook | null = null;
35
+
36
+ head(): HeadValue {
37
+ return { title: __('Webhooks') };
38
+ }
39
+
40
+ async init() {
41
+ this.collections = this.c.get('cms').collections().map(collection => ({ name: collection.name, label: collection.label }));
42
+ await this.load(this.c.req.query('id') ?? '');
43
+ }
44
+
45
+ @Server()
46
+ async load(id: string) {
47
+ const cms = this.c.get('cms');
48
+ this.hooks = await cms.webhooks.list();
49
+ const hook = this.hooks.find(entry => entry.id === id);
50
+ this.selected = hook?.id ?? '';
51
+ this.revealed = '';
52
+ this.form = hook ? { id: hook.id, name: hook.name, url: hook.url, events: [...hook.events], collections: [...hook.collections], active: hook.active } : { ...EMPTY, events: [...EMPTY.events] };
53
+ this.deliveries = hook ? await cms.webhooks.deliveries(hook.id, 20) : [];
54
+ }
55
+
56
+ /** Read the selected webhook's secret, for whoever manages webhooks here. */
57
+ @Server()
58
+ async reveal() {
59
+ // The client names the webhook: only one of this site's, read again here.
60
+ const cms = this.c.get('cms');
61
+ const hook = (await cms.webhooks.list()).find(entry => entry.id === this.selected);
62
+ this.revealed = hook ? await cms.webhooks.secret(hook.id) ?? '' : '';
63
+ }
64
+
65
+ @Client()
66
+ toggle(key: 'events' | 'collections', value: string, checked: boolean) {
67
+ this.form = { ...this.form, [key]: checked ? [...new Set([...this.form[key], value])] : this.form[key].filter(entry => entry !== value) };
68
+ }
69
+
70
+ @Client()
71
+ async submit(event: Event) {
72
+ event.preventDefault();
73
+ const editing = Boolean(this.form.id);
74
+ this.message = '';
75
+ await this.save(this.form);
76
+ if (!this.error) this.message = editing ? __('Webhook updated.') : __('Webhook added. Copy its secret to verify deliveries.');
77
+ }
78
+
79
+ @Server()
80
+ async save(form: Form) {
81
+ this.error = '';
82
+ const cms = this.c.get('cms');
83
+ try {
84
+ const principal = this.c.get('principal');
85
+ const hook = await cms.webhooks.save({ name: form.name, url: form.url, events: form.events, collections: form.collections, active: form.active },
86
+ { ...(form.id ? { id: form.id } : {}), by: principal.kind === 'user' ? principal.id : null, collections: cms.collections().map(collection => collection.name) });
87
+ await this.load(hook.id);
88
+ if (hook.secret) this.revealed = hook.secret;
89
+ } catch (error) {
90
+ this.error = isCmsError(error) ? error.message : __('The webhook could not be saved.');
91
+ }
92
+ }
93
+
94
+ @Client()
95
+ async test() {
96
+ this.message = '';
97
+ this.error = '';
98
+ const result = await this.ping(this.selected);
99
+ if (result.ok) this.message = `${__('The receiver answered')} ${result.status}.`;
100
+ else this.error = result.error ?? __('The test failed.');
101
+ }
102
+
103
+ @Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 })) })
104
+ async ping(id: string) {
105
+ return this.c.get('cms').webhooks.ping(id);
106
+ }
107
+
108
+ @Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 })) })
109
+ async redeliver(deliveryId: string) {
110
+ const cms = this.c.get('cms');
111
+ await cms.webhooks.redeliver(deliveryId);
112
+ await cms.webhooks.dispatch({ limit: 5 });
113
+ const hook = (await cms.webhooks.list()).find(entry => entry.id === this.selected);
114
+ this.deliveries = hook ? await cms.webhooks.deliveries(hook.id, 20) : [];
115
+ }
116
+
117
+ @Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 })) })
118
+ async remove(id: string) {
119
+ this.message = '';
120
+ await this.c.get('cms').webhooks.delete(id);
121
+ await this.load('');
122
+ }
123
+
124
+ render() {
125
+ const hook = this.hooks.find(entry => entry.id === this.selected);
126
+ return html`<div class="space-y-6">
127
+ ${pageHeader(__('Webhooks'), { description: __('Tell other services when entries change, such as to rebuild a static site.'),
128
+ actions: this.selected ? html`<a href="/dashboard/tools/webhooks" class="text-sm text-primary hover:underline">+ ${__('Add webhook')}</a>` : null })}
129
+ ${this.message ? notice(this.message, 'success') : null}
130
+ ${this.error ? notice(this.error, 'error') : null}
131
+ <div class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_24rem]">
132
+ <div class="space-y-6">
133
+ ${component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${this.selected ? `${__('Edit')} ${hook?.name ?? ''}` : __('Add webhook')}</h2>`)}
134
+ ${component(CardBody, {}, html`<form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
135
+ ${component(Field, { label: __('Name'), for: 'hook-name', control: attributes => component(Input, { ...attributes, required: true, maxlength: 80, placeholder: __('Rebuild the site'),
136
+ '.value': this.form.name, '@input': (event: Event) => { this.form = { ...this.form, name: (event.target as HTMLInputElement).value }; } }) })}
137
+ ${component(Field, { label: __('URL'), for: 'hook-url', hint: __('HTTPS, or http://localhost while developing.'), control: attributes => component(Input, { ...attributes, type: 'url', required: true,
138
+ placeholder: 'https://api.example.com/hooks/cms', '.value': this.form.url, '@input': (event: Event) => { this.form = { ...this.form, url: (event.target as HTMLInputElement).value }; } }) })}
139
+ <fieldset class="space-y-2"><legend class="mb-1 text-sm font-medium text-foreground">${__('Events')}</legend>
140
+ ${WEBHOOK_EVENTS.map(event => html`<div>${component(Checkbox, { checked: this.form.events.includes(event), '@change': (change: Event) => this.toggle('events', event, (change.target as HTMLInputElement).checked) },
141
+ html`${__(EVENT_LABELS[event])} <code class="text-xs text-muted-foreground">${event}</code>`)}</div>`)}</fieldset>
142
+ <fieldset class="space-y-2"><legend class="mb-1 text-sm font-medium text-foreground">${__('Collections')}</legend>
143
+ <p class="text-xs text-muted-foreground">${__('None checked sends events of every collection.')}</p>
144
+ <div class="grid gap-2 sm:grid-cols-3">${this.collections.map(collection => html`<div>${component(Checkbox, { label: collection.label, checked: this.form.collections.includes(collection.name), '@change': (change: Event) => this.toggle('collections', collection.name, (change.target as HTMLInputElement).checked) })}</div>`)}</div></fieldset>
145
+ ${component(Checkbox, { label: __('Active'), checked: this.form.active, '@change': (change: Event) => { this.form = { ...this.form, active: (change.target as HTMLInputElement).checked }; } })}
146
+ <div class="flex flex-wrap gap-2">
147
+ ${component(Button, { type: 'submit' }, this.selected ? __('Save webhook') : __('Add webhook'))}
148
+ ${this.selected ? component(Button, { type: 'button', variant: 'outline', '@click': () => this.test() }, __('Send a test')) : null}
149
+ ${hook ? component(Button, { type: 'button', variant: 'ghost', class: 'text-destructive', '@click': () => { this.pendingDelete = hook; } }, __('Delete')) : null}
150
+ </div>
151
+ </form>`)}`)}
152
+ ${hook ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Recent deliveries')}</h2>`)}
153
+ ${component(CardBody, { class: 'p-0' }, this.deliveries.length ? html`<ul class="divide-y divide-border">${this.deliveries.map(delivery => html`<li class="flex flex-wrap items-center justify-between gap-2 px-4 py-3 text-sm">
154
+ <span><code>${delivery.event}</code> <span class="text-muted-foreground">· ${shortDate(delivery.createdAt)} · ${__('attempts')}: ${delivery.attempts}</span>
155
+ ${delivery.error ? html`<span class="block text-xs text-destructive">${delivery.error}</span>` : null}</span>
156
+ <span class="flex items-center gap-2">${component(Badge, { variant: delivery.status === 'delivered' ? 'success' : delivery.status === 'failed' ? 'destructive' : 'secondary' },
157
+ delivery.status === 'delivered' ? `${__('Delivered')} ${delivery.responseStatus ?? ''}` : delivery.status === 'failed' ? __('Failed') : __('Pending'))}
158
+ ${delivery.status !== 'pending' ? html`<button type="button" class="text-xs text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.redeliver(delivery.id)}>${__('Send again')}</button>` : null}</span>
159
+ </li>`)}</ul>` : html`<p class="px-4 py-6 text-sm text-muted-foreground">${__('No deliveries yet.')}</p>`)}`) : null}
160
+ </div>
161
+ <aside class="space-y-4">
162
+ ${component(Card, {}, component(CardBody, { class: 'space-y-3' }, html`<h2 class="text-base font-semibold text-foreground">${__('Webhooks')}</h2>
163
+ ${this.hooks.length ? html`<ul class="space-y-2">${this.hooks.map(entry => html`<li><a href=${`/dashboard/tools/webhooks?id=${entry.id}`}
164
+ class=${`block rounded-md border px-3 py-2 no-underline ${entry.id === this.selected ? 'border-primary' : 'border-border hover:bg-muted'}`}>
165
+ <span class="flex items-center justify-between gap-2"><span class="truncate text-sm font-medium text-foreground">${entry.name}</span>
166
+ ${component(Badge, { variant: entry.active ? 'success' : 'secondary' }, entry.active ? __('Active') : __('Off'))}</span>
167
+ <span class="block truncate text-xs text-muted-foreground">${entry.url}</span></a></li>`)}</ul>` : html`<p class="text-sm text-muted-foreground">${__('No webhooks yet.')}</p>`}`))}
168
+ ${hook ? component(Card, {}, component(CardBody, { class: 'space-y-2' }, html`<h2 class="text-base font-semibold text-foreground">${__('Signing secret')}</h2>
169
+ ${this.revealed ? component(CopyField, { label: __('Signing secret'), value: this.revealed, 'data-webhook-secret': '', copyLabel: __('Copy'), copiedLabel: __('Copied.'), copyFailedLabel: __('Copy it from the box.') })
170
+ : html`<code class="block break-all rounded bg-muted px-2 py-1 text-xs">${`${hook.secretHint}${'•'.repeat(16)}`}</code>`}
171
+ ${this.revealed ? null : html`<button type="button" class="text-xs text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.reveal()}>${__('Show')}</button>`}
172
+ <p class="text-xs text-muted-foreground">${__('Each delivery has X-Cossack-Signature: sha256= the HMAC-SHA256 of “timestamp.body” with this secret, and the timestamp in X-Cossack-Timestamp.')}</p>`)) : null}
173
+ </aside>
174
+ </div>
175
+ ${component(AlertDialog, {
176
+ id: 'delete-webhook-dialog', open: this.pendingDelete !== null, title: __('Delete this webhook?'),
177
+ description: this.pendingDelete ? `${this.pendingDelete.name} ${__('stops receiving events, and its delivery history is deleted.')}` : '',
178
+ cancelLabel: __('Cancel'), actionLabel: __('Delete'), actionVariant: 'destructive',
179
+ onAction: () => { const item = this.pendingDelete; this.pendingDelete = null; if (item) void this.remove(item.id); }, onOpenChange: () => { this.pendingDelete = null; },
180
+ })}
181
+ </div>`;
182
+ }
183
+ }
@@ -0,0 +1,214 @@
1
+ import { Cossack, Page, State, Server, type HeadValue } from '@cossackframework/core';
2
+ import { Avatar, Badge, Icon } from '@cossackframework/ui';
3
+ import { html, component, type TemplateResult } from '@cossackframework/renderer';
4
+ import { plugins } from '@cossackframework/framework/plugins';
5
+ import { evaluateRule, hasPermission, PERMISSIONS, recordTitle } from '@cossackframework/cms';
6
+ import { icon } from '#app/cms/icons';
7
+ import { box, notice, screenHelp, shortDate } from '#app/cms/ui';
8
+ import { agentIcon, browserIcon, osIcon } from '#app/dashboard/agent-icons';
9
+ import { parseUserAgent } from '#app/dashboard/session-list';
10
+
11
+ /** Components active plugins export as `slots['dashboard.overview']` from their ui.ts. */
12
+ function overviewWidgets(active: readonly string[]): TemplateResult[] {
13
+ return plugins.filter(plugin => active.includes(plugin.name)).flatMap(plugin => {
14
+ const slots = (plugin.ui as { slots?: Record<string, unknown[]> } | null)?.slots;
15
+ return (slots?.['dashboard.overview'] ?? []).map(widget => component(widget as never, {}));
16
+ });
17
+ }
18
+
19
+ interface Glance { label: string; href: string; icon: string; published: number; drafts: number }
20
+ interface Item { title: string; href: string; at: number; meta?: string; /** The author, for an avatar before the title. */ author?: { name: string; avatar: string | null } }
21
+ /** A sign-in: the account and the device, from the session's user agent; browser and OS are empty when unknown. */
22
+ interface SignIn { name: string; avatar: string | null; href: string; at: number; browser: string; os: string; ip: string }
23
+
24
+ /** The dashboard home: at a glance, recent activity and what needs attention, in collapsible boxes. */
25
+ @Page({ transport: 'http' })
26
+ export default class DashboardPage extends Cossack {
27
+ @State() userName = '';
28
+ @State() userAvatar: string | null = null;
29
+ @State() glance: Glance[] = [];
30
+ @State() media = -1;
31
+ @State() users = -1;
32
+ @State() published: Item[] = [];
33
+ /** Entries waiting for review, across collections, for editors. */
34
+ @State() pending: Item[] = [];
35
+ @State() pendingTotal = 0;
36
+ /** Open note threads the user started or is named in, newest activity first. */
37
+ @State() notesForMe: Item[] = [];
38
+ /** Who signed in lately, for user managers. */
39
+ @State() signIns: SignIn[] = [];
40
+ @State() canSeeSignIns = false;
41
+ @State() attention: { text: string; href: string }[] = [];
42
+ @State() outbox = 0;
43
+ @State() unconfirmed = 0;
44
+ @State() canMigrate = false;
45
+ @State() widgets: string[] = [];
46
+
47
+ head(): HeadValue {
48
+ return { title: 'Dashboard' };
49
+ }
50
+
51
+ async init() {
52
+ const user = this.user;
53
+ this.userName = user?.name ?? '';
54
+ this.userAvatar = user?.avatar ?? null;
55
+ await this.load();
56
+ }
57
+
58
+ @Server()
59
+ async load() {
60
+ const cms = this.c.get('cms');
61
+ const principal = this.c.get('principal');
62
+ const context = { principal };
63
+ const glance: Glance[] = [];
64
+ for (const collection of cms.collections()) {
65
+ const resource = cms.resourceById(`cms/${collection.name}`);
66
+ if (evaluateRule(resource.access.create, principal) === 'deny' && !hasPermission(principal, `cms/${collection.name}:read`)) continue;
67
+ const repository = cms.resource(resource.id);
68
+ const counts = collection.publishable === false
69
+ ? [await repository.count({}, context).catch(() => 0), 0]
70
+ : await repository.countMany([{ where: { status: 'published' } }, { where: { status: 'draft' } }], context).catch(() => [0, 0]);
71
+ glance.push({ label: collection.label, href: `/dashboard/content/${collection.name}`, icon: collection.icon ?? 'document-text', published: counts[0]!, drafts: counts[1]! });
72
+ }
73
+ this.glance = glance;
74
+ if (cms.files && (hasPermission(principal, PERMISSIONS.upload) || hasPermission(principal, PERMISSIONS.manageMedia))) this.media = (await cms.files.list({ limit: 1 })).total;
75
+ if (hasPermission(principal, PERMISSIONS.manageUsers)) this.users = (await cms.users.list({ limit: 1 })).total;
76
+ // The newest published entries of every publishable collection, together, with their authors.
77
+ const recent: (Item & { owner: string })[] = [];
78
+ for (const collection of cms.collections()) {
79
+ if (collection.publishable === false || collection.name === 'forms') continue;
80
+ const page = await cms.resource(`cms/${collection.name}`).list({ where: { status: 'published' }, order: { field: 'publishedAt', direction: 'desc' }, limit: 5 }, context).catch(() => ({ records: [] }));
81
+ recent.push(...page.records.map(record => ({ title: recordTitle(record, 'title'), href: `/dashboard/content/${collection.name}/${record.id}`, at: Number(record.publishedAt), meta: collection.singular, owner: record.owner ?? '' })));
82
+ }
83
+ const newest = recent.sort((a, b) => b.at - a.at).slice(0, 8);
84
+ const authors = await cms.users.getMany([...new Set(newest.map(item => item.owner).filter(Boolean))]);
85
+ this.published = newest.map(({ owner, ...item }) => {
86
+ const author = owner ? authors.get(owner) : undefined;
87
+ return author ? { ...item, author: { name: author.name || author.email, avatar: author.avatar ?? null } } : item;
88
+ });
89
+ const status = await cms.status();
90
+ this.canMigrate = hasPermission(principal, PERMISSIONS.manageSchema);
91
+ // Comments and reviews waiting for someone.
92
+ const waiting: { text: string; href: string }[] = [];
93
+ if (hasPermission(principal, PERMISSIONS.moderateComments)) {
94
+ const pending = await cms.comments.counts().then(counts => counts.pending).catch(() => 0);
95
+ if (pending) waiting.push({ text: `${pending} ${pending === 1 ? __('comment is waiting for moderation.') : __('comments are waiting for moderation.')}`, href: '/dashboard/comments?status=pending' });
96
+ }
97
+ // Entries waiting for review get their own card; the notice stays for the count.
98
+ const pending: Item[] = [];
99
+ let pendingTotal = 0;
100
+ for (const collection of cms.collections()) {
101
+ if (collection.publishable === false || !hasPermission(principal, `cms/${collection.name}:update`)) continue;
102
+ const repository = cms.resource(`cms/${collection.name}`);
103
+ const count = await repository.count({ where: { status: 'pending' } }, context).catch(() => 0);
104
+ if (!count) continue;
105
+ pendingTotal += count;
106
+ const page = await repository.list({ where: { status: 'pending' }, order: { field: 'updatedAt', direction: 'desc' }, limit: 5 }, context).catch(() => ({ records: [] }));
107
+ const owners = await cms.users.getMany(page.records.map(record => record.owner).filter((owner): owner is string => !!owner));
108
+ pending.push(...page.records.map(record => ({ title: recordTitle(record, 'title'), href: `/dashboard/content/${collection.name}/${record.id}`, at: record.updatedAt,
109
+ meta: [collection.singular, record.owner ? owners.get(record.owner)?.name : ''].filter(Boolean).join(' · ') })));
110
+ }
111
+ this.pending = pending.sort((a, b) => b.at - a.at).slice(0, 8);
112
+ this.pendingTotal = pendingTotal;
113
+ if (pendingTotal) waiting.push({ text: `${pendingTotal} ${pendingTotal === 1 ? __('entry is pending review.') : __('entries are pending review.')}`, href: '#pending-review' });
114
+ // Notes for you: open threads you started or were mentioned in, with the entry and the words they quote.
115
+ if (principal.kind === 'user') {
116
+ const threads = await cms.notes.forUser(principal.id, 8).catch(() => []);
117
+ const authors = await cms.users.getMany([...new Set(threads.map(note => note.userId))]);
118
+ const items: Item[] = [];
119
+ for (const note of threads) {
120
+ const [owner, name] = note.resource.split('/');
121
+ const record = await cms.resource(note.resource).get(note.recordId, context).catch(() => null);
122
+ if (!record || !cms.resource(note.resource).canUpdate(record, principal)) continue;
123
+ const author = authors.get(note.userId);
124
+ const excerpt = note.quote ? `“${note.quote.slice(0, 80)}”` : note.body.replace(/@\[([^\]]+)\]\([^)]+\)/g, '@$1').slice(0, 80);
125
+ items.push({ title: recordTitle(record, cms.resourceById(note.resource).titleField), href: `/dashboard/content/${owner === 'cms' ? name : `${owner}.${name}`}/${record.id}?notes=open`, at: note.updatedAt, meta: excerpt,
126
+ ...(author ? { author: { name: author.name || author.email, avatar: author.avatar } } : {}) });
127
+ }
128
+ this.notesForMe = items;
129
+ }
130
+ // Who signed in lately: sessions end at sign-out, so these are the accounts signed in now.
131
+ this.canSeeSignIns = hasPermission(principal, PERMISSIONS.manageUsers);
132
+ if (this.canSeeSignIns) {
133
+ const sessions = await cms.authSessions.listRecent(Date.now(), 8).catch(() => []);
134
+ const users = await cms.users.getMany([...new Set(sessions.map(session => session.userId))]);
135
+ this.signIns = sessions.map(session => {
136
+ const user = users.get(session.userId);
137
+ const agent = parseUserAgent(session.userAgent);
138
+ return { name: user?.name || user?.email || __('Deleted user'), avatar: user?.avatar ?? null, href: user ? `/dashboard/users/${user.id}?tab=sessions` : '/dashboard/users',
139
+ at: session.createdAt, browser: session.userAgent ? agent.browser : '', os: session.userAgent ? agent.os : '', ip: session.ip ?? '' };
140
+ });
141
+ }
142
+ this.attention = [
143
+ ...waiting,
144
+ ...status.resources.filter(resource => !resource.active).map(resource => ({ text: `${resource.id} ${__('is waiting for a schema migration.')}`, href: '/dashboard/tools/schema' })),
145
+ ...status.plugins.filter(plugin => !plugin.active && plugin.missing.length).map(plugin => ({ text: `${plugin.name}: ${plugin.reason ?? __('not enabled.')}`, href: '/dashboard/plugins' })),
146
+ ];
147
+ if (this.canMigrate) {
148
+ this.outbox = (await cms.outbox.pending({ limit: 100 }).catch(() => [])).length;
149
+ this.unconfirmed = (await cms.db.pending.list({ limit: 100 })).length;
150
+ }
151
+ this.widgets = status.plugins.filter(plugin => plugin.active).map(plugin => plugin.name);
152
+ }
153
+
154
+ render() {
155
+ const widgets = overviewWidgets(this.widgets);
156
+ const list = (items: Item[], empty: string) => items.length
157
+ ? html`<ul class="space-y-2">${items.map(item => html`<li class="flex items-center justify-between gap-3 text-sm">
158
+ <span class="flex min-w-0 items-center gap-2">
159
+ ${item.author ? html`<span class="inline-flex shrink-0" title=${item.author.name}>${component(Avatar, { src: item.author.avatar ?? undefined, alt: item.author.name, size: 24 })}</span>` : null}
160
+ <span class="min-w-0 truncate"><a href=${item.href} class="text-primary hover:underline">${item.title}</a>${item.meta ? html`<span class="ml-2 text-xs text-muted-foreground">${item.meta}</span>` : null}</span>
161
+ </span>
162
+ <span class="shrink-0 text-xs text-muted-foreground">${shortDate(item.at)}</span></li>`)}</ul>`
163
+ : html`<p class="text-sm text-muted-foreground">${empty}</p>`;
164
+ const glance = [...this.glance.map(entry => ({ ...entry, note: entry.drafts ? `${entry.drafts} ${entry.drafts === 1 ? __('draft') : __('drafts')}` : '' })),
165
+ ...(this.media >= 0 ? [{ label: __('Media'), href: '/dashboard/media', icon: 'gallery', published: this.media, note: '' }] : []),
166
+ ...(this.users >= 0 ? [{ label: __('Users'), href: '/dashboard/users', icon: 'users-group-rounded', published: this.users, note: '' }] : [])];
167
+ const signIns = this.signIns.length ? html`<ul class="divide-y divide-border">${this.signIns.map(entry => html`<li class="flex items-center gap-3 py-2 text-sm first:pt-0 last:pb-0">
168
+ ${component(Avatar, { src: entry.avatar ?? undefined, alt: entry.name, size: 28 })}
169
+ <span class="min-w-0 flex-1"><a href=${entry.href} class="block truncate font-medium text-foreground no-underline hover:text-primary">${entry.name}</a>
170
+ <span class="flex items-center gap-1.5 text-xs text-muted-foreground">
171
+ ${entry.browser || entry.os ? html`${agentIcon(browserIcon(entry.browser), entry.browser || __('Unknown browser'), 14)}${agentIcon(osIcon(entry.os), entry.os || __('Unknown system'), 14)}` : html`<span>${__('Unknown device')}</span>`}
172
+ ${entry.ip ? html`<span class="truncate">${entry.ip}</span>` : null}
173
+ </span></span>
174
+ <span class="shrink-0 text-xs text-muted-foreground">${shortDate(entry.at)}</span></li>`)}</ul>`
175
+ : html`<p class="text-sm text-muted-foreground">${__('No one is signed in.')}</p>`;
176
+ return html`<div class="space-y-6">
177
+ ${screenHelp(html`<p>${__('At a glance counts the published entries of each collection, with drafts beside them; Recently published lists the newest entries with their authors.')}</p>
178
+ <p>${__('Notices at the top, and the taskbar below, show what waits for someone: comments to moderate, entries pending review, schema migrations and plugins waiting for a grant.')}</p>
179
+ <p>${__('Each box collapses from its title; plugins add their own boxes. Delivery counts the events and writes the site has not confirmed yet.')}</p>`)}
180
+ <div class="flex items-center gap-4">
181
+ ${component(Avatar, { src: this.userAvatar ?? undefined, alt: this.userName, size: 48 })}
182
+ <div>
183
+ <h1 class="text-2xl font-bold text-foreground">${__('Dashboard')}</h1>
184
+ <p class="text-sm text-muted-foreground">${__('Welcome back')}, ${this.userName}.</p>
185
+ </div>
186
+ </div>
187
+ ${this.attention.map(item => html`<a href=${item.href} class="block no-underline">${notice(item.text, 'error')}</a>`)}
188
+ <div class="grid gap-6 xl:grid-cols-3">
189
+ <div class="space-y-6 xl:col-span-2">
190
+ ${box(__('At a glance'), html`<dl class="grid grid-cols-2 gap-3 sm:grid-cols-3">
191
+ ${glance.map(entry => html`<a href=${entry.href} class="group rounded-lg border border-border p-3 no-underline transition-colors hover:border-primary/50 hover:bg-muted/40">
192
+ <dt class="flex items-center gap-2 text-sm text-muted-foreground group-hover:text-foreground"><span class="inline-flex [&_svg]:size-4">${component(Icon, { entry: icon(entry.icon), size: 16 })}</span>${entry.label}</dt>
193
+ <dd class="mt-1 text-2xl font-semibold text-foreground">${entry.published}</dd>
194
+ ${entry.note ? html`<dd class="text-xs text-muted-foreground">${entry.note}</dd>` : null}
195
+ </a>`)}
196
+ </dl>`, { id: 'box-glance' })}
197
+ ${this.notesForMe.length ? html`<div id="notes-for-you">${box(__('Notes for you'), list(this.notesForMe, ''), { id: 'box-notes', extra: component(Badge, { variant: 'warning' }, String(this.notesForMe.length)) })}</div>` : null}
198
+ ${this.pendingTotal ? html`<div id="pending-review">${box(__('Waiting for review'), html`${list(this.pending, '')}
199
+ ${this.pendingTotal > this.pending.length ? html`<p class="mt-3 text-xs"><a href="/dashboard/content/posts?status=pending" class="text-primary hover:underline">${__('Show everything pending')}</a></p>` : null}`,
200
+ { id: 'box-pending', extra: component(Badge, { variant: 'warning' }, String(this.pendingTotal)) })}</div>` : null}
201
+ ${box(__('Recently published'), list(this.published, __('Nothing published yet.')), { id: 'box-published' })}
202
+ ${widgets.length ? html`<section class="grid gap-4 sm:grid-cols-2">${widgets}</section>` : null}
203
+ </div>
204
+ <div class="space-y-6">
205
+ ${this.canSeeSignIns ? box(__('Recent sign-ins'), signIns, { id: 'box-sign-ins', extra: html`<a href="/dashboard/users" class="text-xs font-normal text-primary hover:underline">${__('All users')}</a>` }) : null}
206
+ ${this.canMigrate ? box(__('Delivery'), html`<dl class="grid gap-3 sm:grid-cols-2 xl:grid-cols-1">
207
+ <div class="rounded-lg border border-border p-3"><dt class="text-sm text-muted-foreground">${__('Events waiting for delivery')}</dt><dd class="text-2xl font-semibold text-foreground" data-testid="outbox">${this.outbox}</dd></div>
208
+ <div class="rounded-lg border border-border p-3"><dt class="text-sm text-muted-foreground">${__('Writes waiting for confirmation')}</dt><dd class="text-2xl font-semibold text-foreground">${this.unconfirmed}</dd></div>
209
+ </dl>`, { id: 'box-delivery' }) : null}
210
+ </div>
211
+ </div>
212
+ </div>`;
213
+ }
214
+ }
@@ -0,0 +1,227 @@
1
+ import { Cossack, Page, Server, State, Client, server$, type HeadValue } from '@cossackframework/core';
2
+ import type { SidebarItem } from '@cossackframework/ui';
3
+ import { DashboardShell, type CommandItem } from '@cossackframework/ui/blocks';
4
+ import { html, component, type TemplateResult } from '@cossackframework/renderer';
5
+ import { getCookie } from 'hono/cookie';
6
+ import { dashboardFind, dashboardNotices, dashboardSearch, dashboardStatus, navigation } from '#app/dashboard/access';
7
+ import { shellIcons } from '#app/dashboard/icons';
8
+ import { dashboardHead } from '#app/dashboard/head';
9
+ import { siteHasLogo, siteLogo, siteName } from '#app/brand';
10
+ import type { DashboardModule, DashboardNotice, DashboardStatus } from '#app/dashboard/types';
11
+ import { logout } from '#app/auth';
12
+ import { requireDashboardUser } from '#app/middlewares/auth';
13
+ import { themeStore } from '@/stores.client';
14
+
15
+ /**
16
+ * Dashboard layout, shared by every /dashboard/* page: it decides what the signed-in user sees
17
+ * and renders it in `DashboardShell` from `@cossackframework/ui/blocks` (sidebar, account menu,
18
+ * theme toggle, palette, notices, taskbar). src/dashboard/access.ts decides which modules the
19
+ * user sees; each describes its icon, destination, submenu links, and whether it belongs in
20
+ * navigation or the account menu.
21
+ *
22
+ * The theme toggle writes the same `cs-theme` cookie and themeStore the App
23
+ * component applies to `<html>.dark`, and draws itself from that class.
24
+ *
25
+ * The taskbar along the bottom (desktop and tablet) opens the site, shows what
26
+ * waits for the user (`dashboardStatus` in src/dashboard/access.ts, a `server$`
27
+ * resource so it is fresh on every navigation) and holds the Screen options and
28
+ * Help buttons, which open the `#screen-options` and `#screen-help` popovers a
29
+ * screen renders with `screenOptions()` and `screenHelp()` from src/dashboard/page.ts.
30
+ */
31
+ @Page({ transport: 'http', middlewares: [requireDashboardUser] })
32
+ export default class DashboardLayout extends Cossack {
33
+ appName = server$(() => siteName(), { initial: 'Cossack' });
34
+ appLogo = server$(() => siteLogo(), { initial: '/logo.svg' });
35
+ /** The site set its own logo: it shows without the name beside it. */
36
+ appLogoOnly = server$(() => siteHasLogo(), { initial: false });
37
+ /** What waits for the user, with counts, for the taskbar. */
38
+ statuses: DashboardStatus[] = server$(() => dashboardStatus(this.c), { initial: [] });
39
+ /** Messages above every screen, such as the ones CMS plugins return; fresh on every navigation, like the statuses. */
40
+ notices: DashboardNotice[] = server$(() => dashboardNotices(this.c), { initial: [] });
41
+ /** Sidebar collapsed state. Seeded from the cookie at SSR (via this.c) and
42
+ * re-read client-side in onMount; persists across client navigations. */
43
+ @State() sidebarCollapsed = false;
44
+ /** Navigation the signed-in user may open, resolved on the server. */
45
+ @State() modules: DashboardModule[] = [];
46
+ /** Where Ctrl/Cmd+K can go: every screen of the navigation, resolved with it. */
47
+ @State() commands: { id: string; label: string; group: string; href: string }[] = [];
48
+ /** What the palette found for its text besides the screens (`dashboardFind`): the CMS's entries. */
49
+ @State() found: { id: string; label: string; group: string; href: string }[] = [];
50
+ /** The palette's text the next find is for; one find runs at a time, so an older answer never replaces a newer one. */
51
+ private wanted = '';
52
+ private finding = false;
53
+ private findTimer: ReturnType<typeof setTimeout> | undefined;
54
+ @State() logoutError = '';
55
+ @State() account: { name: string; email: string; avatar: string | null } = {
56
+ name: '',
57
+ email: '',
58
+ avatar: null,
59
+ };
60
+
61
+ @Client()
62
+ toggleTheme() {
63
+ // The opposite of what shows. Back to the system's scheme forgets the choice, so the
64
+ // page follows the system again; a choice that differs from it is kept until undone.
65
+ const theme = themeStore.get() === 'dark' ? 'light' : 'dark';
66
+ const system = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
67
+ document.cookie = theme === system ? 'cs-theme=; Path=/; Max-Age=0; SameSite=Lax' : `cs-theme=${theme}; Path=/; Max-Age=31536000; SameSite=Lax`;
68
+ themeStore.set(theme);
69
+ }
70
+
71
+ /** Flip the sidebar collapsed state and persist to a cookie so the next
72
+ * SSR render paints the correct state (no flash). The @State update drives
73
+ * the Sidebar re-render (controlled component). */
74
+ /** Open the screen or entry a palette entry names; the palette's ids are the hrefs. */
75
+ @Client()
76
+ go(id: string) {
77
+ const found = [...this.commands, ...this.found].find((entry) => entry.id === id);
78
+ if (found) window.location.assign(found.href);
79
+ }
80
+
81
+ /** The palette's text changed: find for it a moment after the typing stops, from two characters. */
82
+ @Client()
83
+ onPaletteSearch(text: string) {
84
+ this.wanted = text.trim();
85
+ clearTimeout(this.findTimer);
86
+ if (this.wanted.length < 2) {
87
+ if (this.found.length) this.found = [];
88
+ return;
89
+ }
90
+ this.findTimer = setTimeout(() => void this.findWanted(), 150);
91
+ }
92
+
93
+ /** Find for the text wanted, again while it changed during a find. */
94
+ @Client()
95
+ async findWanted() {
96
+ if (this.finding) return;
97
+ this.finding = true;
98
+ try {
99
+ let text: string;
100
+ do {
101
+ text = this.wanted;
102
+ if (text.length >= 2) await this.find(text);
103
+ } while (text !== this.wanted);
104
+ if (this.wanted.length < 2 && this.found.length) this.found = [];
105
+ } catch {
106
+ /* the screens still show; the next text finds again */
107
+ } finally {
108
+ this.finding = false;
109
+ }
110
+ }
111
+
112
+ @Server()
113
+ async find(text: string) {
114
+ const seen = new Set(this.commands.map((entry) => entry.id));
115
+ this.found = typeof text === 'string' ? (await dashboardFind(this.c, text.slice(0, 200))).filter((entry) => !seen.has(entry.id)) : [];
116
+ }
117
+
118
+ @Client()
119
+ onToggleSidebar() {
120
+ this.sidebarCollapsed = !this.sidebarCollapsed;
121
+ try {
122
+ document.cookie = `cs-sidebar-collapsed=${this.sidebarCollapsed}; Path=/; Max-Age=31536000; SameSite=Lax`;
123
+ } catch { /* document.cookie unavailable */ }
124
+ }
125
+
126
+ @Server()
127
+ async doLogout() {
128
+ this.logoutError = '';
129
+ try {
130
+ const { headers } = await logout(this.c);
131
+ headers.forEach((value, key) => this.c.header(key, value));
132
+ this.redirect(config('auth.redirectAfterLogout'));
133
+ } catch {
134
+ this.logoutError = 'Could not sign out. Try again.';
135
+ }
136
+ }
137
+
138
+ async init() {
139
+ const user = this.user;
140
+ if (this.c) {
141
+ this.modules = await navigation(this.c);
142
+ this.commands = await dashboardSearch(this.c);
143
+ }
144
+ this.account = {
145
+ name: user?.name ?? '',
146
+ email: user?.email ?? '',
147
+ avatar: user?.avatar ?? null,
148
+ };
149
+
150
+ this.sidebarCollapsed = this.c
151
+ ? getCookie(this.c, 'cs-sidebar-collapsed') === 'true'
152
+ : this.sidebarCollapsed;
153
+ }
154
+
155
+ head(): HeadValue {
156
+ return { meta: dashboardHead() };
157
+ }
158
+
159
+ render(): TemplateResult {
160
+ const icons = shellIcons();
161
+ const availableModules = this.modules;
162
+ // A module with a parent the user also sees is listed inside the parent's menu.
163
+ const nested = (module: DashboardModule) => !!module.parent && availableModules.some((other) => other.id === module.parent);
164
+ const navigationModules = availableModules.filter(
165
+ (module) => module.placement !== 'account' && !nested(module),
166
+ );
167
+ const accountModules = availableModules.filter(
168
+ (module) => module.placement === 'account',
169
+ );
170
+ const items: SidebarItem[] = [
171
+ {
172
+ value: 'dashboard',
173
+ label: __('Dashboard'),
174
+ href: '/dashboard',
175
+ icon: icons.home,
176
+ active: this.isActive('/dashboard'),
177
+ },
178
+ ...navigationModules.map((module): SidebarItem => {
179
+ const item = {
180
+ value: `module:${module.id}`,
181
+ label: __(module.label), href: module.href, icon: module.icon,
182
+ active: module.activeFor ? this.isActive(module.activeFor, false) : this.isActive(module.href),
183
+ };
184
+ const children = [
185
+ ...(module.children ?? []),
186
+ ...availableModules.filter((other) => other.parent === module.id && nested(other))
187
+ .flatMap((other) => other.children?.length ? other.children : [{ label: other.label, href: other.href }]),
188
+ ];
189
+ if (!children.length) return item;
190
+ // A group lists its own page as a link too; leave it out when a child already opens it.
191
+ const { href: _href, active: _active, ...group } = item;
192
+ return {
193
+ ...(children.some((child) => child.href === module.href) ? group : item),
194
+ children: children.map((child) => ({
195
+ value: `module:${module.id}:${child.href}`,
196
+ label: __(child.label), href: child.href,
197
+ active: this.isActive(child.href),
198
+ })),
199
+ };
200
+ }),
201
+ ];
202
+
203
+ return html`${component(DashboardShell, {
204
+ brand: { name: this.appName, logo: this.appLogo, logoOnly: this.appLogoOnly },
205
+ account: this.account,
206
+ navigation: items,
207
+ accountLinks: accountModules.map((module) => ({ label: __(module.label), href: module.href, icon: module.icon })),
208
+ collapsed: this.sidebarCollapsed,
209
+ onCollapsedChange: () => this.onToggleSidebar(),
210
+ onLogout: () => this.doLogout(),
211
+ onThemeToggle: () => this.toggleTheme(),
212
+ commands: [...this.commands.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group })),
213
+ ...this.found.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group, matched: true }))],
214
+ onCommand: (id: string) => this.go(id),
215
+ onCommandSearch: (text: string) => this.onPaletteSearch(text),
216
+ notices: this.notices,
217
+ statuses: this.statuses.map((item) => ({ ...item, label: __(item.label) })),
218
+ error: this.logoutError,
219
+ icons: { light: icons.light, dark: icons.dark, expand: icons.expand, logout: icons.logout },
220
+ labels: {
221
+ navigation: __('Dashboard navigation'), expand: __('Expand navigation'), collapse: __('Collapse navigation'), viewSite: __('View site'),
222
+ toggleTheme: __('Switch between light and dark mode'), lightMode: __('Light mode'), darkMode: __('Dark mode'), logOut: __('Log out'),
223
+ palette: __('Go to'), palettePlaceholder: __('Type a screen name or search…'), taskbar: __('Dashboard taskbar'), screenOptions: __('Screen options'), help: __('Help'),
224
+ },
225
+ }, this.children)}`;
226
+ }
227
+ }