@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,68 @@
1
+ import { Client, Cossack, Page, Server, State } from '@cossackframework/core';
2
+ import { Alert, Button } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { setCookie } from 'hono/cookie';
5
+ import { authSessions, beginTwoFactor, consumeMagicLink, linkAccountEmail, SignInPasskeyError, TWO_FACTOR_COOKIE } from '#app/auth';
6
+
7
+ /**
8
+ * A sign-in link from the email. Opening it signs nobody in: a button does, so a mail scanner
9
+ * fetching the link does not spend it. The button cannot tell whose link it is, though: someone
10
+ * pressing it on a link another person sent would be signed into that person's account, so the
11
+ * page names the account first. Spent once, the link signs the account in, or starts the second
12
+ * factor's step for an account with one, as a password does; a spent or expired link says so.
13
+ */
14
+ @Page({ transport: 'http' })
15
+ export default class MagicLinkPage extends Cossack {
16
+ @State() token = '';
17
+ @State() failed = false;
18
+ /** Why the link did not sign in, when it was valid: the account signs in with its passkey. */
19
+ @State() message = '';
20
+ /** The account the link signs into, shown before the button. */
21
+ @State() email = '';
22
+
23
+ async init() {
24
+ this.token = (this.c.req.query('token') ?? '').trim();
25
+ const email = await linkAccountEmail('magic', this.token);
26
+ if (!email) { this.failed = true; this.c.status(400); return; }
27
+ this.email = email;
28
+ }
29
+
30
+ @Client()
31
+ async submit(event: Event) {
32
+ event.preventDefault();
33
+ await this.signIn(this.token);
34
+ }
35
+
36
+ @Server()
37
+ async signIn(token: string) {
38
+ const userId = await consumeMagicLink(String(token ?? '').trim());
39
+ if (!userId) { this.failed = true; return; }
40
+ // The email stands in for the password only: an enrolled authenticator is still asked for.
41
+ let pending: string | null;
42
+ try { pending = await beginTwoFactor(userId); }
43
+ catch (error) {
44
+ if (!(error instanceof SignInPasskeyError)) throw error;
45
+ this.failed = true; this.message = error.message; return;
46
+ }
47
+ if (pending) {
48
+ setCookie(this.c, TWO_FACTOR_COOKIE, pending, { path: '/', httpOnly: true, sameSite: 'Lax', maxAge: 300, secure: new URL(this.c.req.url).protocol === 'https:' });
49
+ this.redirect('/auth/two-factor');
50
+ return;
51
+ }
52
+ const { headers } = await authSessions.create(userId, this.c);
53
+ headers.forEach((value, key) => this.c.header(key, value));
54
+ this.redirect('/dashboard');
55
+ }
56
+
57
+ render() {
58
+ return html`
59
+ <h3 class="mb-3 text-xl font-semibold text-foreground">${__('Sign in')}</h3>
60
+ ${this.failed ? component(Alert, { variant: 'destructive' }, this.message || __('This sign-in link is not valid any more. Ask for a new one from the sign-in page.')) : html`
61
+ <form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
62
+ <p class="text-sm text-muted-foreground">${__('Continue to sign in as')} <strong class="text-foreground">${this.email}</strong>. ${__('If this is not your account, close this page.')}</p>
63
+ ${component(Button, { type: 'submit', block: true }, __('Sign in'))}
64
+ </form>`}
65
+ <p class="mt-6 text-center text-sm text-muted-foreground"><a href="/auth/login" class="text-primary font-medium hover:underline">${__('Back to sign in')}</a></p>
66
+ `;
67
+ }
68
+ }
@@ -0,0 +1,117 @@
1
+ import { Cossack, Page, State, ClientStore, Validate, Client, Server, storeRules, isClientVisibleError } from '@cossackframework/core';
2
+ import { Field, Input, PasswordInput, Button, Alert, Turnstile } from '@cossackframework/ui';
3
+ import { html, component, bind } from '@cossackframework/renderer';
4
+ import { authSessions, registerUser, registrationOpen } from '#app/auth';
5
+ import { registerInput, returnPath, type RegisterInput } from '#app/auth-input';
6
+ import { botCheckKey, passesBotCheck } from '#app/auth-bot-check';
7
+ import { BOT_CHECK_FAILED, botCheckToken } from '#app/auth-bot-token';
8
+
9
+ const REGISTRATION_MESSAGES = new Set(['An account with this email already exists.', 'Registration is closed on this site.']);
10
+
11
+ interface RegisterForm {
12
+ name: string;
13
+ email: string;
14
+ password: string;
15
+ }
16
+
17
+ @Page({ transport: 'http' })
18
+ export default class RegisterPage extends Cossack {
19
+ @ClientStore()
20
+ @Validate({
21
+ rules: storeRules<RegisterForm>({
22
+ email: { required: true, email: true, message: 'Enter a valid email' },
23
+ password: { required: true, minLength: 8, message: 'Password must be at least 8 characters' },
24
+ }),
25
+ config: { trigger: 'all', runOn: 'client' }
26
+ })
27
+ form: RegisterForm = { name: '', email: '', password: '' };
28
+
29
+ @State() error = '';
30
+ /** The confirmation email went out; no session yet. */
31
+ @State() sent = false;
32
+ /** The account waits for an administrator's approval; no session yet. */
33
+ @State() pending = false;
34
+ @State() closed = false;
35
+ /** The Turnstile site key while the bot check is on. */
36
+ @State() botKey: string | null = null;
37
+ /** Where to go once the account is made: the `redirect` query. Checked again on use. */
38
+ @State() returnTo = '';
39
+
40
+ async init() {
41
+ this.closed = !(await registrationOpen());
42
+ this.botKey = botCheckKey();
43
+ this.returnTo = returnPath(this.c.req.query('redirect')) ?? '';
44
+ }
45
+
46
+ @Client()
47
+ async handleSubmit(event: Event) {
48
+ event.preventDefault();
49
+ this.error = '';
50
+ const ok = await this.validateAll();
51
+ if (!ok) return;
52
+ try {
53
+ await this.register({ name: this.form.name, email: this.form.email, password: this.form.password, turnstile: botCheckToken(event.target) });
54
+ } catch {
55
+ this.error = 'Could not create the account. Check your details and try again.';
56
+ }
57
+ }
58
+
59
+ @Server({ input: registerInput })
60
+ async register(submitted: RegisterInput) {
61
+ const { name, email, password, turnstile } = await registerInput.parse(submitted);
62
+ this.error = '';
63
+ if (!(await passesBotCheck(turnstile, 'register'))) { this.error = BOT_CHECK_FAILED; return; }
64
+ try {
65
+ const user = await registerUser(email, password, name || undefined);
66
+ if (user.verification === 'sent') { this.sent = true; return; }
67
+ if (user.approval === 'pending') { this.pending = true; return; }
68
+ const { headers } = await authSessions.create(user.id, this.c);
69
+ headers.forEach((value, key) => this.c.header(key, value));
70
+ this.redirect(returnPath(this.returnTo) ?? config('auth.redirectAfterLogin'));
71
+ } catch (error) {
72
+ // Only known, safe messages reach the page; anything else stays generic.
73
+ this.error = isClientVisibleError(error) && REGISTRATION_MESSAGES.has(error.message)
74
+ ? error.message
75
+ : 'Could not create the account. Try again or sign in.';
76
+ }
77
+ }
78
+
79
+ render() {
80
+ if (this.sent) return html`
81
+ <h3 class="mb-3 text-xl font-semibold text-foreground">${__('Check your email')}</h3>
82
+ ${component(Alert, {}, __('We sent you a link to confirm your email address. Open it to finish creating your account; it works for two days.'))}
83
+ <p class="mt-6 text-center text-sm text-muted-foreground"><a href="/auth/login" class="text-primary font-medium hover:underline">${__('Back to sign in')}</a></p>
84
+ `;
85
+ if (this.pending) return html`
86
+ <h3 class="mb-3 text-xl font-semibold text-foreground">${__('Thanks for registering')}</h3>
87
+ ${component(Alert, {}, __('An administrator approves new accounts on this site. We will email you when yours is ready.'))}
88
+ <p class="mt-6 text-center text-sm text-muted-foreground"><a href="/auth/login" class="text-primary font-medium hover:underline">${__('Back to sign in')}</a></p>
89
+ `;
90
+ if (this.closed) return html`
91
+ <h3 class="mb-3 text-xl font-semibold text-foreground">${__('Register')}</h3>
92
+ ${component(Alert, {}, __('Registration is closed on this site.'))}
93
+ <p class="mt-6 text-center text-sm text-muted-foreground">
94
+ ${__('Already have an account?')}
95
+ <a href="/auth/login" class="text-primary font-medium hover:underline">${__('Login')}</a>
96
+ </p>
97
+ `;
98
+ return html`
99
+ <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Register')}</h3>
100
+ <form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
101
+ ${component(Field, { label: __('Name'), for: 'name',
102
+ control: attributes => component(Input, { ...attributes, type: 'text', '.value': bind(this.form, 'name') }) })}
103
+ ${component(Field, { label: __('Email'), for: 'email', error: this.getError('form.email'),
104
+ control: attributes => component(Input, { ...attributes, type: 'email', placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email') }) })}
105
+ ${component(Field, { label: __('Password'), for: 'password', error: this.getError('form.password'),
106
+ control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, onValueChange: (v: string) => this.form.password = v }) })}
107
+ ${this.botKey ? component(Turnstile, { id: 'register-verify', siteKey: this.botKey, action: 'register', label: __('Bot protection') }) : null}
108
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
109
+ ${component(Button, { type: 'submit', block: true }, __('Create Account'))}
110
+ </form>
111
+ <p class="mt-6 text-center text-sm text-muted-foreground">
112
+ ${__('Already have an account?')}
113
+ <a href="/auth/login" class="text-primary font-medium hover:underline">${__('Login')}</a>
114
+ </p>
115
+ `;
116
+ }
117
+ }
@@ -0,0 +1,65 @@
1
+ import { Cossack, Page, State, ClientStore, Validate, Client, Server, storeRules } from '@cossackframework/core';
2
+ import { Field, PasswordInput, Button, Alert } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { resetPassword } from '#app/auth';
5
+ import { resetPasswordInput, type ResetPasswordInput } from '#app/auth-input';
6
+
7
+ @Page({ transport: 'http' })
8
+ export default class ResetPasswordPage extends Cossack {
9
+ @ClientStore()
10
+ @Validate({
11
+ rules: storeRules<{ password: string; confirm: string }>({
12
+ password: { required: true, minLength: 8, message: 'Password must be at least 8 characters' },
13
+ confirm: { required: true, customAsync: async (value: string, page?: ResetPasswordPage) => value === page?.form.password, message: 'The passwords do not match' },
14
+ }),
15
+ config: { trigger: 'all', runOn: 'client' }
16
+ })
17
+ form: { password: string; confirm: string } = { password: '', confirm: '' };
18
+
19
+ @State() error = '';
20
+
21
+ private get token(): string {
22
+ return this.c?.req?.query('token') ?? '';
23
+ }
24
+
25
+ @Client()
26
+ async handleSubmit(event: Event) {
27
+ event.preventDefault();
28
+ this.error = '';
29
+ const ok = await this.validateAll();
30
+ if (!ok) return;
31
+ try {
32
+ await this.doReset({ token: this.token, password: this.form.password, confirm: this.form.confirm });
33
+ } catch {
34
+ this.error = 'Could not reset the password. Check the link and try again.';
35
+ }
36
+ }
37
+
38
+ @Server({ input: resetPasswordInput })
39
+ async doReset(submitted: ResetPasswordInput) {
40
+ const { token, password, confirm } = await resetPasswordInput.parse(submitted);
41
+ this.error = '';
42
+ if (confirm !== password) { this.error = 'The passwords do not match'; return; }
43
+ try {
44
+ const ok = await resetPassword(token, password);
45
+ if (!ok) { this.error = 'Invalid or expired reset link'; return; }
46
+ this.redirect('/auth/login');
47
+ } catch {
48
+ this.error = 'Could not reset the password. Request a new reset link.';
49
+ }
50
+ }
51
+
52
+ render() {
53
+ return html`
54
+ <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Reset Password')}</h3>
55
+ <form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
56
+ ${component(Field, { label: __('New Password'), for: 'password', error: this.getError('form.password'),
57
+ control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, placeholder: '••••••••', autocomplete: 'new-password', onValueChange: (v: string) => this.form.password = v }) })}
58
+ ${component(Field, { label: __('Confirm New Password'), for: 'confirm', error: this.getError('form.confirm'),
59
+ control: attributes => component(PasswordInput, { ...attributes, value: this.form.confirm, placeholder: '••••••••', autocomplete: 'new-password', onValueChange: (v: string) => this.form.confirm = v }) })}
60
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
61
+ ${component(Button, { type: 'submit', block: true }, __('Reset Password'))}
62
+ </form>
63
+ `;
64
+ }
65
+ }
@@ -0,0 +1,194 @@
1
+ import { Client, Cossack, Page, RateLimit, State, flash, flashed, type HeadValue } from '@cossackframework/core';
2
+ import { Alert } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { DEFAULT_ROLES, MAIN_SITE, NETWORK_ADMIN, isCmsError, isSameOriginPost, systemPrincipal } from '@cossackframework/cms';
5
+ import { normalizeEmail, seedStarterContent } from '@cossackframework/cms/server';
6
+ import { authSessions, setupRequired } from '#app/auth';
7
+ import { CONTROL } from '#app/cms/ui';
8
+ import { importRequest, importSummary, sendsExport } from '#app/cms/site-import';
9
+ import { sendExport } from '#app/cms/import.client';
10
+
11
+ /** Compare digests so the comparison time does not depend on how much of the code matches. */
12
+ async function sameSecret(candidate: string, expected: string): Promise<boolean> {
13
+ const digest = async (value: string) => new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value)));
14
+ const [a, b] = await Promise.all([digest(candidate), digest(expected)]);
15
+ let difference = 0;
16
+ for (let index = 0; index < a.length; index++) difference |= a[index]! ^ b[index]!;
17
+ return difference === 0;
18
+ }
19
+
20
+ /**
21
+ * First run: apply the schema, create the roles and the first administrator, and name the
22
+ * site. A database exported from a network's site has members but no accounts: setup then
23
+ * takes it over, with one of its administrators. A fresh install can also start from a site's
24
+ * JSON export, then take it over. Requires CMS_SETUP_CODE so a fresh deployment cannot be
25
+ * claimed by a visitor.
26
+ */
27
+ @Page({ transport: 'http' })
28
+ export default class SetupPage extends Cossack {
29
+ @State() done = false;
30
+ @State() error = '';
31
+ /** Members of a site whose database this is, when it came from a network; 0 for a new site. */
32
+ @State() members = 0;
33
+ @State() siteTitle = '';
34
+ /** What an import just brought in. */
35
+ @State() imported = '';
36
+ @State() importing = false;
37
+ @State() importError = '';
38
+
39
+ head(): HeadValue {
40
+ return { title: 'Set up your site' };
41
+ }
42
+
43
+ async init() {
44
+ this.error = flashed<string>('cms.setup') ?? '';
45
+ this.imported = flashed<string>('cms.setup.imported') ?? '';
46
+ this.done = !(await setupRequired());
47
+ if (!this.done) {
48
+ const cms = this.c.get('cms');
49
+ this.members = await cms.users.count().catch(() => 0);
50
+ if (this.members) this.siteTitle = await cms.settings.get('general.siteTitle').catch(() => '');
51
+ }
52
+ }
53
+
54
+ @RateLimit({ window: 60_000, max: 5 })
55
+ async post() {
56
+ if (!isSameOriginPost(this.c.req.raw)) return this.c.text('Forbidden', 403);
57
+ // An export sent as the request body; everything else is a form.
58
+ const raw = sendsExport(this.c);
59
+ const form = raw ? null : await this.c.req.formData();
60
+ const value = (name: string) => String(form?.get(name) ?? '');
61
+ const expected = (this.c.env as { CMS_SETUP_CODE?: string }).CMS_SETUP_CODE;
62
+ if (!expected || !(await sameSecret(raw ? this.c.req.header('x-cms-setup-code') ?? '' : value('code'), expected))) {
63
+ const message = 'The setup code is not correct. Find CMS_SETUP_CODE in the environment.';
64
+ if (raw) return this.c.json({ error: message }, 403);
65
+ flash('cms.setup', message);
66
+ return this.redirect('/auth/setup');
67
+ }
68
+ if (raw || value('action') === 'import') return this.importSite(raw);
69
+ const cms = this.c.get('cms');
70
+ const report = await cms.migrate();
71
+ if (report.failed) {
72
+ flash('cms.setup', `The schema could not be applied: ${report.failed.message}`);
73
+ return this.redirect('/auth/setup');
74
+ }
75
+ await cms.ready({ force: true });
76
+ if (await cms.accounts.hasNetworkAdmin()) return this.redirect('/auth/login');
77
+ if ((await cms.users.count()) > 0) return this.takeOver(value('email'), value('password'));
78
+ try {
79
+ for (const role of DEFAULT_ROLES) await cms.users.defineRole({ ...role, permissions: [...role.permissions] });
80
+ // The first account runs the network as well as this site.
81
+ const user = await cms.users.create({ email: value('email'), name: value('name'), password: value('password'), roles: ['admin'], networkRole: NETWORK_ADMIN });
82
+ await cms.settings.update('general', { siteTitle: value('siteTitle').trim() || 'My Site', adminEmail: user.email }, { principal: systemPrincipal('setup') });
83
+ // A first post, a category, a contact form and its page, as the administrator, when asked for; a restored database keeps its own content.
84
+ if (value('starter')) {
85
+ try { await seedStarterContent(cms, { principal: (await cms.users.principal(user.id))! }); }
86
+ catch (error) { console.warn(`[cms] the starter content could not be created: ${(error as Error).message}`); }
87
+ }
88
+ const { headers } = await authSessions.create(user.id, this.c);
89
+ headers.forEach((header, name) => this.c.header(name, header, { append: true }));
90
+ } catch (error) {
91
+ flash('cms.setup', isCmsError(error) ? error.message : 'The administrator could not be created.');
92
+ return this.redirect('/auth/setup');
93
+ }
94
+ return this.redirect('/dashboard');
95
+ }
96
+
97
+ /** A site's export becomes this install's content; its members then wait for the takeover form. */
98
+ private async importSite(raw: boolean) {
99
+ try {
100
+ if (!(await setupRequired())) throw new Error('This site is set up already.');
101
+ flash('cms.setup.imported', importSummary(await importRequest(this.c, this.c.get('cms'))));
102
+ return raw ? this.c.json({ next: '/auth/setup' }) : this.redirect('/auth/setup');
103
+ } catch (error) {
104
+ const message = isCmsError(error) || error instanceof Error ? (error as Error).message : 'The export could not be imported.';
105
+ if (raw) return this.c.json({ error: message }, 400);
106
+ flash('cms.setup', message);
107
+ return this.redirect('/auth/setup');
108
+ }
109
+ }
110
+
111
+ /** Send the export as the request body, so a large file is read as a stream. */
112
+ @Client()
113
+ async upload(event: SubmitEvent) {
114
+ event.preventDefault();
115
+ const form = event.currentTarget as HTMLFormElement;
116
+ this.importing = true;
117
+ this.importError = '';
118
+ const result = await sendExport(form, { 'x-cms-setup-code': (form.elements.namedItem('code') as HTMLInputElement).value });
119
+ if (result.next) { location.assign(result.next); return; }
120
+ this.importing = false;
121
+ this.importError = result.error ?? '';
122
+ }
123
+
124
+ /** A site exported from a network: its members get accounts, and this administrator a password and the network role. */
125
+ private async takeOver(email: string, password: string) {
126
+ const cms = this.c.get('cms');
127
+ try {
128
+ const address = normalizeEmail(email);
129
+ const member = (await cms.users.list({ search: address, limit: 100 })).items.find(user => user.email === address);
130
+ if (!member?.assignments.some(role => role.id === 'admin')) throw new Error('Enter the email of one of this site\'s administrators.');
131
+ await cms.accounts.adoptMembers(MAIN_SITE, member.id, password);
132
+ const { headers } = await authSessions.create(member.id, this.c);
133
+ headers.forEach((header, name) => this.c.header(name, header, { append: true }));
134
+ } catch (error) {
135
+ flash('cms.setup', isCmsError(error) || error instanceof Error ? (error as Error).message : 'The site could not be taken over.');
136
+ return this.redirect('/auth/setup');
137
+ }
138
+ return this.redirect('/dashboard');
139
+ }
140
+
141
+ render() {
142
+ const field = (name: string, label: string, type: 'text' | 'email' | 'password', autocomplete: string, options: { minlength?: number; hint?: string } = {}) => html`<div class="space-y-1.5">
143
+ <label for=${`setup-${name}`} class="block text-sm font-medium text-foreground">${label}</label>
144
+ <input id=${`setup-${name}`} name=${name} type=${type} required autocomplete=${autocomplete} minlength=${options.minlength ?? 1} class=${CONTROL}>
145
+ ${options.hint ? html`<p class="text-xs text-muted-foreground">${options.hint}</p>` : null}
146
+ </div>`;
147
+ if (this.done) return html`<div class="space-y-4 text-center">
148
+ <h3 class="text-xl font-semibold text-foreground">${__('Your site is set up')}</h3>
149
+ <a class="text-primary font-medium hover:underline" href="/auth/login">${__('Sign in')}</a>
150
+ </div>`;
151
+ if (this.members) return html`${this.imported ? html`<div class="mb-4">${component(Alert, { variant: 'success' }, this.imported)}</div>` : null}<h3 class="mb-2 text-xl font-semibold text-foreground">${__('Take over this site')}</h3>
152
+ <p class="mb-6 text-sm text-muted-foreground">${this.siteTitle ? `${this.siteTitle}: ` : ''}${__('this database comes from another install, with')} ${this.members} ${this.members === 1 ? __('member') : __('members')}.
153
+ ${__('Sign in as one of its administrators: that account gets this password and runs this install. The site\'s own accounts keep their passwords; members who signed in with a network account get accounts without one, and set it with Forgot password, or you set it under Users.')}</p>
154
+ <form method="post" class="space-y-4">
155
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
156
+ ${field('code', __('Setup code'), 'password', 'off', { hint: __('CMS_SETUP_CODE from the environment.') })}
157
+ ${field('email', __('Administrator email'), 'email', 'username')}
158
+ ${field('password', __('New password'), 'password', 'new-password', { minlength: 8, hint: __('At least 8 characters.') })}
159
+ <button type="submit" class="inline-flex w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground border-none cursor-pointer">${__('Take over the site')}</button>
160
+ </form>`;
161
+ return html`<h3 class="mb-2 text-xl font-semibold text-foreground">${__('Set up your site')}</h3>
162
+ <p class="mb-6 text-sm text-muted-foreground">${__('This creates the database tables and your administrator account.')}</p>
163
+ <form method="post" class="space-y-4">
164
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
165
+ ${field('code', __('Setup code'), 'password', 'off', { hint: __('CMS_SETUP_CODE from the environment.') })}
166
+ ${field('siteTitle', __('Site title'), 'text', 'organization')}
167
+ ${field('name', __('Your name'), 'text', 'name')}
168
+ ${field('email', __('Email'), 'email', 'username')}
169
+ ${field('password', __('Password'), 'password', 'new-password', { minlength: 8, hint: __('At least 8 characters.') })}
170
+ <label class="flex items-start gap-2 text-sm text-foreground cursor-pointer">
171
+ <input type="checkbox" name="starter" value="on" checked class="mt-0.5">
172
+ <span>${__('Add starter content')}<span class="block text-xs text-muted-foreground">${__('A first post, an Uncategorized category, a contact form and a Contact page, to edit or delete.')}</span></span>
173
+ </label>
174
+ <button type="submit" class="inline-flex w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground border-none cursor-pointer">${__('Set up')}</button>
175
+ </form>
176
+ <details class="mt-6 rounded-md border border-border p-4" data-site-import>
177
+ <summary class="cursor-pointer text-sm font-medium text-foreground">${__('Moving a site here? Start from its export')}</summary>
178
+ <form method="post" enctype="multipart/form-data" class="mt-4 space-y-4" @submit=${(event: SubmitEvent) => this.upload(event)}>
179
+ <input type="hidden" name="action" value="import">
180
+ ${this.importError ? component(Alert, { variant: 'destructive' }, this.importError) : null}
181
+ <p class="text-sm text-muted-foreground">${__('A JSON export from the site\'s Tools → Export. Its content, settings and members come in; you then take the site over as one of its administrators. Media files are not in exports: copy them to this site\'s storage.')}</p>
182
+ <div class="space-y-1.5">
183
+ <label for="import-code" class="block text-sm font-medium text-foreground">${__('Setup code')}</label>
184
+ <input id="import-code" name="code" type="password" required autocomplete="off" class=${CONTROL}>
185
+ </div>
186
+ <div class="space-y-1.5">
187
+ <label for="import-file" class="block text-sm font-medium text-foreground">${__('Export file')}</label>
188
+ <input id="import-file" name="file" type="file" required accept=".json,application/json" class="block w-full text-sm text-foreground">
189
+ </div>
190
+ <button type="submit" ?disabled=${this.importing} class="inline-flex w-full items-center justify-center rounded-md border border-border bg-background px-4 py-2 text-sm font-medium text-foreground cursor-pointer">${this.importing ? __('Importing…') : __('Import')}</button>
191
+ </form>
192
+ </details>`;
193
+ }
194
+ }
@@ -0,0 +1,67 @@
1
+ import { Cossack, Page, State, Server, Client } from '@cossackframework/core';
2
+ import { Alert, Button, Field, Input } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { deleteCookie, getCookie } from 'hono/cookie';
5
+ import { completeTwoFactor, createSession, TWO_FACTOR_COOKIE } from '#app/auth';
6
+ import { returnPath } from '#app/auth-input';
7
+
8
+ /**
9
+ * The second step of signing in: a code from the authenticator app, or a recovery code. The
10
+ * password step left a pending sign-in in a cookie; it lasts five minutes and five tries.
11
+ */
12
+ @Page({ transport: 'http' })
13
+ export default class TwoFactorPage extends Cossack {
14
+ @State() code = '';
15
+ @State() error = '';
16
+ @State() recovery = false;
17
+ /** Where to go once signed in, passed on by the sign-in page. Checked again on use. */
18
+ @State() returnTo = '';
19
+
20
+ async init() {
21
+ this.returnTo = returnPath(this.c.req.query('redirect')) ?? '';
22
+ if (!getCookie(this.c, TWO_FACTOR_COOKIE)) this.error = __('Enter your email and password first.');
23
+ }
24
+
25
+ @Client()
26
+ async submit(event: Event) {
27
+ event.preventDefault();
28
+ await this.verify(this.code);
29
+ }
30
+
31
+ @Server()
32
+ async verify(code: string) {
33
+ this.error = '';
34
+ const pending = getCookie(this.c, TWO_FACTOR_COOKIE) ?? '';
35
+ const result = await completeTwoFactor(pending, code);
36
+ if ('error' in result) {
37
+ this.error = result.error;
38
+ if (result.expired) deleteCookie(this.c, TWO_FACTOR_COOKIE, { path: '/' });
39
+ this.code = '';
40
+ return;
41
+ }
42
+ deleteCookie(this.c, TWO_FACTOR_COOKIE, { path: '/' });
43
+ const { headers } = await createSession(result.user.id, this.c, { secondFactor: true });
44
+ headers.forEach((value, key) => this.c.header(key, value));
45
+ // A used recovery code is a hint to set up the app again.
46
+ this.redirect(result.recovery ? '/dashboard/profile/security?recovered=1' : returnPath(this.returnTo) ?? config('auth.redirectAfterLogin'));
47
+ }
48
+
49
+ render() {
50
+ return html`
51
+ <h3 class="mb-2 text-xl font-semibold text-foreground">${__('Two-step sign-in')}</h3>
52
+ <p class="mb-6 text-sm text-muted-foreground">${this.recovery ? __('Enter one of your recovery codes. Each works once.') : __('Enter the 6-digit code from your authenticator app.')}</p>
53
+ <form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
54
+ ${component(Field, { label: this.recovery ? __('Recovery code') : __('Code'), for: 'two-factor-code',
55
+ control: attributes => component(Input, { ...attributes, autocomplete: 'one-time-code', inputmode: this.recovery ? 'text' : 'numeric', required: true, autofocus: true,
56
+ maxlength: this.recovery ? 20 : 6, '.value': this.code, '@input': (event: Event) => { this.code = (event.target as HTMLInputElement).value; } }) })}
57
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
58
+ ${component(Button, { type: 'submit', block: true, disabled: !this.code.trim() }, __('Verify'))}
59
+ </form>
60
+ <div class="mt-6 flex justify-between text-sm">
61
+ <button type="button" class="text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => { this.recovery = !this.recovery; this.code = ''; }}>
62
+ ${this.recovery ? __('Use the authenticator app') : __('Use a recovery code')}</button>
63
+ <a href="/auth/login" class="text-muted-foreground hover:text-foreground">${__('Start over')}</a>
64
+ </div>
65
+ `;
66
+ }
67
+ }
@@ -0,0 +1,62 @@
1
+ import { Client, Cossack, Page, Server, State } from '@cossackframework/core';
2
+ import { Alert, Button } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { authSessions, linkAccountEmail, verifyEmail } from '#app/auth';
5
+ import { networkFor, siteUrl, type CmsBindings } from '#app/cms/index';
6
+ import { networkSite } from '@cossackframework/cms/server';
7
+
8
+ /**
9
+ * The confirmation link of a new account. Opening it changes nothing: a button confirms, so a
10
+ * mail scanner fetching the link does not spend it. The button cannot tell whose link it is,
11
+ * though: someone pressing it on a link another person sent would be signed into that person's
12
+ * new account, so the page names the account first. Then the account becomes active and signs
13
+ * in; a spent or expired link says so.
14
+ */
15
+ @Page({ transport: 'http' })
16
+ export default class VerifyPage extends Cossack {
17
+ @State() token = '';
18
+ @State() failed = false;
19
+ /** The email is confirmed and the account waits for an administrator's approval. */
20
+ @State() pending = false;
21
+ /** The account the link confirms, shown before the button. */
22
+ @State() email = '';
23
+
24
+ async init() {
25
+ this.token = (this.c.req.query('token') ?? '').trim();
26
+ const email = await linkAccountEmail('verify', this.token);
27
+ if (!email) { this.failed = true; this.c.status(400); return; }
28
+ this.email = email;
29
+ }
30
+
31
+ @Client()
32
+ async submit(event: Event) {
33
+ event.preventDefault();
34
+ await this.confirm(this.token);
35
+ }
36
+
37
+ @Server()
38
+ async confirm(token: string) {
39
+ const verified = await verifyEmail(String(token ?? '').trim());
40
+ if (!verified) { this.failed = true; return; }
41
+ // Confirmed, and an administrator still approves the account: no session yet.
42
+ if (verified.pending) { this.pending = true; return; }
43
+ const { headers } = await authSessions.create(verified.user, this.c);
44
+ headers.forEach((value, key) => this.c.header(key, value));
45
+ // Registered on the network for one of its sites: signed in here, the site's handoff takes them there.
46
+ const record = verified.site ? await networkFor(this.c.env as CmsBindings).sites.get(verified.site).catch(() => null) : null;
47
+ const target = record ? siteUrl(this.c.env as CmsBindings, networkSite(record)) : undefined;
48
+ this.redirect(target ? `${target.replace(/\/+$/, '')}/auth/handoff?next=${encodeURIComponent('/dashboard?verified=1')}` : '/dashboard?verified=1');
49
+ }
50
+
51
+ render() {
52
+ return html`
53
+ <h3 class="mb-3 text-xl font-semibold text-foreground">${__('Confirm your email')}</h3>
54
+ ${this.pending ? component(Alert, {}, __('Your email address is confirmed. An administrator approves new accounts on this site; we will email you when yours is ready.')) : this.failed ? component(Alert, { variant: 'destructive' }, __('This link is not valid any more. Register again with the same email to get a new one, or sign in if your account is already confirmed.')) : html`
55
+ <form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
56
+ <p class="text-sm text-muted-foreground">${__('Confirm')} <strong class="text-foreground">${this.email}</strong> ${__('to finish creating your account. If this is not your address, close this page.')}</p>
57
+ ${component(Button, { type: 'submit', block: true }, __('Confirm email'))}
58
+ </form>`}
59
+ <p class="mt-6 text-center text-sm text-muted-foreground"><a href="/auth/login" class="text-primary font-medium hover:underline">${__('Sign in')}</a></p>
60
+ `;
61
+ }
62
+ }