@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,16 @@
1
+ import type { Context } from 'hono';
2
+ import { answer, apiHeaders } from '#app/cms/content-api';
3
+ import { siteSearch } from '#app/cms/manage';
4
+
5
+ /**
6
+ * The site's search: `GET /api/cms/search?q=walrus+facts&page=2`. Published entries visitors may
7
+ * read, from every collection (`collection=posts` for one), best first: `{ items: [{ collection,
8
+ * id, title, url, snippet }], page, next, loose }`. A snippet is plain parts, `match` on the words
9
+ * that matched. Every word is required; `loose` is true when nothing had them all and the items
10
+ * have some. `locale=fr` searches one language on a site with several (default: the main one).
11
+ */
12
+ export const GET = (c: Context) => answer(c, async () => {
13
+ const found = await siteSearch(c, c.req.query());
14
+ apiHeaders(c);
15
+ return found;
16
+ });
@@ -0,0 +1,9 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { settingsRead, settingsUpdate } from '#app/cms/manage';
4
+
5
+ /** One settings group with its values and fields: `GET /api/cms/settings/general`. */
6
+ export const GET = (c: Context) => answer(c, () => settingsRead(c, c.req.param('group') ?? ''));
7
+
8
+ /** Change some fields of a group: `PATCH /api/cms/settings/general` with `{ siteTitle: "My site" }`; the others keep their values. */
9
+ export const PATCH = (c: Context) => answer(c, body => settingsUpdate(c, c.req.param('group') ?? '', body), { write: true });
@@ -0,0 +1,9 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { settingsApply, settingsRead } from '#app/cms/manage';
4
+
5
+ /** The settings document the caller may edit, `{ group: { field: value } }`: `GET /api/cms/settings`. The same shape Settings → Export writes. */
6
+ export const GET = (c: Context) => answer(c, () => settingsRead(c));
7
+
8
+ /** Apply a settings document, as Settings → Import does: `PUT /api/cms/settings` with `{ group: { field: value } }`. Groups left out keep their values. */
9
+ export const PUT = (c: Context) => answer(c, body => settingsApply(c, body), { write: true });
@@ -0,0 +1,34 @@
1
+ import type { Context } from 'hono';
2
+ import { hasPermission, holdsAll, isNetworkAdmin, MAIN_SITE, PERMISSIONS } from '@cossackframework/cms';
3
+ import { exportResponse, fileExportResponse } from '#app/cms/site-export';
4
+
5
+ /**
6
+ * This site's database as a JSON file, `GET /api/cms/site-export`, for its admins signed in
7
+ * with a session: at once on the main site or when the network lets sites export themselves,
8
+ * otherwise for 7 days after a network admin approves the site's request (Tools → Export).
9
+ * Both formats are for user managers who hold every permission any role gives (or network admins).
10
+ * `?format=romedb` downloads the database as a `.romedb` file. It holds the accounts' password
11
+ * hashes, so it is for those who may manage every account in it: network admins for the main
12
+ * site's (every network account), and on an added site user managers who hold every permission
13
+ * any of its roles gives, as changing any one of those accounts asks.
14
+ */
15
+ export const GET = async (c: Context) => {
16
+ const principal = c.get('principal');
17
+ if (principal.kind !== 'user' || c.get('cms.token')) return c.json({ error: 'Sign in to export the site.', code: 'CMS_UNAUTHENTICATED' }, 401);
18
+ if (!hasPermission(principal, PERMISSIONS.manageSettings)) return c.json({ error: 'Only the site\'s admins export it.', code: 'CMS_FORBIDDEN' }, 403);
19
+ const site = c.get('site');
20
+ if (!(await c.get('network').exportAccess(site.id)).allowed) return c.json({ error: 'A network admin approves this site\'s export first: request it under Tools → Export.', code: 'CMS_FORBIDDEN' }, 403);
21
+ const cms = c.get('cms');
22
+ // Both formats hold every account, submission, draft and note: only an administrator who may
23
+ // manage every account (holding each permission any role gives) exports them.
24
+ const roles = await cms.users.roles();
25
+ if (!isNetworkAdmin(principal) && (!hasPermission(principal, PERMISSIONS.manageUsers) || !holdsAll(principal, roles.flatMap(role => role.permissions)))) {
26
+ return c.json({ error: 'The export holds every account and submission: only an administrator who may manage all of them downloads it.', code: 'CMS_FORBIDDEN' }, 403);
27
+ }
28
+ if (c.req.query('format') === 'romedb') {
29
+ if (site.id === MAIN_SITE && !isNetworkAdmin(principal)) return c.json({ error: 'Only network admins download the main site\'s database file.', code: 'CMS_FORBIDDEN' }, 403);
30
+ return fileExportResponse(cms, site, c.req.raw.signal);
31
+ }
32
+ const title = await cms.settings.get('general.siteTitle').catch(() => '');
33
+ return exportResponse(cms, site, site.id === MAIN_SITE ? title : site.name ?? title);
34
+ };
@@ -0,0 +1,6 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { taxonomiesList } from '#app/cms/manage';
4
+
5
+ /** The site's taxonomies, such as categories and tags: `GET /api/cms/taxonomies`. Their terms are at `/api/cms/terms/<taxonomy>`. */
6
+ export const GET = (c: Context) => answer(c, async () => taxonomiesList(c));
@@ -0,0 +1,12 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { termDelete, termRead, termUpdate } from '#app/cms/manage';
4
+
5
+ /** One term: `GET /api/cms/terms/categories/<id>`. */
6
+ export const GET = (c: Context) => answer(c, () => termRead(c, c.req.param('taxonomy') ?? '', c.req.param('id') ?? ''));
7
+
8
+ /** Change a term: `PATCH /api/cms/terms/categories/<id>` with any of `name`, `slug`, `description`, `parent`. */
9
+ export const PATCH = (c: Context) => answer(c, body => termUpdate(c, c.req.param('taxonomy') ?? '', c.req.param('id') ?? '', body), { write: true });
10
+
11
+ /** Delete a term; entries keep their other terms: `DELETE /api/cms/terms/categories/<id>`. */
12
+ export const DELETE = (c: Context) => answer(c, () => termDelete(c, c.req.param('taxonomy') ?? '', c.req.param('id') ?? ''), { write: true });
@@ -0,0 +1,9 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { termCreate, termsList } from '#app/cms/manage';
4
+
5
+ /** A taxonomy's terms: `GET /api/cms/terms/categories?q=news&page=1&perPage=50`. */
6
+ export const GET = (c: Context) => answer(c, () => termsList(c, c.req.param('taxonomy') ?? '', c.req.query()));
7
+
8
+ /** A new term: `POST /api/cms/terms/categories` with `{ name, slug?, description?, parent? }`. Needs the terms permission. */
9
+ export const POST = (c: Context) => answer(c, body => termCreate(c, c.req.param('taxonomy') ?? '', body), { write: true, status: 201 });
@@ -0,0 +1,15 @@
1
+ import type { Context } from 'hono';
2
+ import { mediaUrl } from '@cossackframework/cms';
3
+ import { apiError, writeAllowed } from '#app/cms/content-api';
4
+
5
+ /** Finish an upload: the bytes are checked against the declared size and type, and the file is made. */
6
+ export const POST = async (c: Context) => {
7
+ const refused = writeAllowed(c);
8
+ if (refused) return refused;
9
+ const cms = c.get('cms');
10
+ if (!cms.files) return c.json({ error: 'File storage is not configured.', code: 'CMS_UNAVAILABLE' }, 503);
11
+ try {
12
+ const file = await cms.files.complete(c.req.param('id') ?? '', { principal: c.get('principal'), signal: c.req.raw.signal });
13
+ return c.json({ file: { id: file.id, url: mediaUrl(file), title: file.title, alt: file.alt, contentType: file.contentType, width: file.width, height: file.height } }, 201);
14
+ } catch (error) { return apiError(c, error); }
15
+ };
@@ -0,0 +1,15 @@
1
+ import type { Context } from 'hono';
2
+ import { apiError, writeAllowed } from '#app/cms/content-api';
3
+
4
+ /** The bytes of an upload begun at `POST /api/cms/uploads`, when the bucket does not take them directly. */
5
+ export const PUT = async (c: Context) => {
6
+ const refused = writeAllowed(c);
7
+ if (refused) return refused;
8
+ const cms = c.get('cms');
9
+ if (!cms.files) return c.json({ error: 'File storage is not configured.', code: 'CMS_UNAVAILABLE' }, 503);
10
+ if (!c.req.raw.body) return c.json({ error: 'Send the file as the request body.', code: 'CMS_VALIDATION' }, 400);
11
+ try {
12
+ await cms.files.receive(c.req.param('id') ?? '', c.req.raw.body, { principal: c.get('principal'), signal: c.req.raw.signal });
13
+ return c.body(null, 204);
14
+ } catch (error) { return apiError(c, error); }
15
+ };
@@ -0,0 +1,26 @@
1
+ import type { Context } from 'hono';
2
+ import { apiError, writeAllowed, writeBody } from '#app/cms/content-api';
3
+
4
+ /**
5
+ * Start an upload the browser sends itself: answers where to PUT the bytes. With a bucket that
6
+ * presigns (S3, R2 through its S3 API) the URL is the bucket's and `direct` is true; otherwise
7
+ * the bytes go to `PUT /api/cms/uploads/<id>` on this application. Either way the browser
8
+ * then posts `/api/cms/uploads/<id>/complete`, which checks the bytes and makes the file.
9
+ */
10
+ export const POST = async (c: Context) => {
11
+ const refused = writeAllowed(c);
12
+ if (refused) return refused;
13
+ const cms = c.get('cms');
14
+ if (!cms.files) return c.json({ error: 'File storage is not configured.', code: 'CMS_UNAVAILABLE' }, 503);
15
+ const body = await writeBody(c);
16
+ if (body instanceof Response) return body;
17
+ const name = typeof body.name === 'string' ? body.name : '';
18
+ const size = typeof body.size === 'number' ? body.size : Number(body.size);
19
+ if (!name || !Number.isSafeInteger(size)) return c.json({ error: 'Send the file\'s name, type and size.', code: 'CMS_VALIDATION' }, 400);
20
+ try {
21
+ const maxBytes = (await cms.settings.get('media.maxUploadMb')) * 1024 * 1024;
22
+ const pending = await cms.files.begin({ name, contentType: typeof body.type === 'string' ? body.type : '', size }, { principal: c.get('principal'), maxBytes });
23
+ const target = pending.direct ?? { url: new URL(`/api/cms/uploads/${pending.id}`, c.req.url).href, method: 'PUT' as const, headers: { 'content-type': pending.contentType } };
24
+ return c.json({ id: pending.id, url: target.url, method: target.method, headers: target.headers, direct: pending.direct !== null }, 201);
25
+ } catch (error) { return apiError(c, error); }
26
+ };
@@ -0,0 +1,12 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { userDelete, userGet, userUpdate } from '#app/cms/manage';
4
+
5
+ /** One user, by ID or email: `GET /api/cms/users/<id>`. */
6
+ export const GET = (c: Context) => answer(c, () => userGet(c, c.req.param('id') ?? ''));
7
+
8
+ /** Change a user: `PATCH /api/cms/users/<id>` with any of `name`, `email`, `password`, `roles` (role managers) and `status` (`active` or `disabled`). */
9
+ export const PATCH = (c: Context) => answer(c, body => userUpdate(c, c.req.param('id') ?? '', body), { write: true });
10
+
11
+ /** Delete a user (on an added site, remove the member): `DELETE /api/cms/users/<id>`. Never your own account. */
12
+ export const DELETE = (c: Context) => answer(c, () => userDelete(c, c.req.param('id') ?? ''), { write: true });
@@ -0,0 +1,40 @@
1
+ import type { Context } from 'hono';
2
+ import { hasPermission, PERMISSIONS } from '@cossackframework/cms';
3
+ import { apiError, writeAllowed, writeBody } from '#app/cms/content-api';
4
+ import { groupsView, metaInput, metaValues } from '#app/cms/content';
5
+ import { canManageUser } from '#app/services/rbac';
6
+ import { getUser } from '#app/services/users';
7
+ import type { PublicUser } from '#app/auth';
8
+ import type { Principal } from '@cossackframework/cms';
9
+
10
+ /** The caller as `canManageUser` takes it: the session's user, or an application password's principal. */
11
+ function actorOf(c: Context): PublicUser | undefined {
12
+ const user = c.get('user') as PublicUser | undefined;
13
+ if (user) return user;
14
+ const principal = c.get('principal') as Principal | undefined;
15
+ return principal?.kind === 'user' ? { id: principal.id, email: '', name: '', avatar: null, meta: null, roles: [], principal } : undefined;
16
+ }
17
+
18
+ /**
19
+ * Save a user's values of the field groups attached to users, as the user screen's meta boxes
20
+ * send them: `{ "meta": { …control values } }`. Answers the stored values as control values,
21
+ * or the fields' problems. For people who manage users and may change this account.
22
+ */
23
+ export const POST = async (c: Context) => {
24
+ const refused = writeAllowed(c);
25
+ if (refused) return refused;
26
+ if (!hasPermission(c.get('principal'), PERMISSIONS.manageUsers)) return c.json({ error: 'Not allowed to change users.', code: 'CMS_FORBIDDEN' }, 403);
27
+ const id = c.req.param('id') ?? '';
28
+ const target = await getUser(id);
29
+ if (!target || !canManageUser(actorOf(c), target)) return c.json({ error: 'This user does not exist.', code: 'CMS_NOT_FOUND' }, 404);
30
+ const body = await writeBody(c);
31
+ if (body instanceof Response) return body;
32
+ const cms = c.get('cms');
33
+ const { fields } = await groupsView(cms, { kind: 'users' });
34
+ const converted = metaInput(fields, body.meta && typeof body.meta === 'object' ? body.meta as Record<string, unknown> : {});
35
+ if (Object.keys(converted.errors).length) return c.json({ error: 'Some fields are invalid.', code: 'CMS_VALIDATION', fields: converted.errors }, 422);
36
+ try {
37
+ await cms.users.update(id, { meta: converted.meta }, { principal: c.get('principal') });
38
+ return c.json({ values: metaValues(fields, (await cms.users.get(id))?.meta ?? {}) });
39
+ } catch (error) { return apiError(c, error); }
40
+ };
@@ -0,0 +1,12 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { userCreate, usersList } from '#app/cms/manage';
4
+
5
+ /** The site's users: `GET /api/cms/users?q=ada&role=editor&page=1&perPage=20`. Needs the users permission. */
6
+ export const GET = (c: Context) => answer(c, () => usersList(c, c.req.query()));
7
+
8
+ /**
9
+ * A new user: `POST /api/cms/users` with `{ email, password, name?, roles? }`. Roles (IDs such as
10
+ * `editor`) take a role manager; without them the account gets General settings' default role.
11
+ */
12
+ export const POST = (c: Context) => answer(c, body => userCreate(c, body), { write: true, status: 201 });
@@ -0,0 +1,6 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { webhookDelete } from '#app/cms/manage';
4
+
5
+ /** Remove a webhook: `DELETE /api/cms/webhooks/<id>`. */
6
+ export const DELETE = (c: Context) => answer(c, () => webhookDelete(c, c.req.param('id') ?? ''), { write: true });
@@ -0,0 +1,9 @@
1
+ import type { Context } from 'hono';
2
+ import { answer } from '#app/cms/content-api';
3
+ import { webhookCreate, webhooksList } from '#app/cms/manage';
4
+
5
+ /** The site's webhooks: `GET /api/cms/webhooks`. Needs the webhooks permission. */
6
+ export const GET = (c: Context) => answer(c, () => webhooksList(c));
7
+
8
+ /** A new webhook: `POST /api/cms/webhooks` with `{ name, url, events, collections?, active? }`; the answer carries the signing secret once. */
9
+ export const POST = (c: Context) => answer(c, body => webhookCreate(c, body), { write: true, status: 201 });
@@ -0,0 +1,11 @@
1
+ import type { Context } from 'hono';
2
+ import { handleOAuthUser, oauth, oauthProvider } from '#app/auth';
3
+
4
+ /** The provider sends the visitor back here: sign in the account it names, or create one. A provider the project does not offer answers 404. */
5
+ export const GET = async (c: Context) => {
6
+ const provider = c.req.param('provider') ?? '';
7
+ if (!oauthProvider(provider)) return c.notFound();
8
+ return oauth.callback(provider, {
9
+ onUser: (user, tokens, context) => handleOAuthUser(provider, user, tokens, context),
10
+ })(c, async () => {});
11
+ };
@@ -0,0 +1,9 @@
1
+ import type { Context } from 'hono';
2
+ import { oauth, oauthProvider } from '#app/auth';
3
+
4
+ /** Send the visitor to the provider's consent page. A provider the project does not offer answers 404. */
5
+ export const GET = async (c: Context) => {
6
+ const provider = c.req.param('provider') ?? '';
7
+ if (!oauthProvider(provider)) return c.notFound();
8
+ return oauth.redirect(provider)(c, async () => {});
9
+ };
@@ -0,0 +1,75 @@
1
+ import { Cossack, Page, State, ClientState, ClientStore, Validate, Client, Server, storeRules, ClientVisibleError, isClientVisibleError } from '@cossackframework/core';
2
+ import { Field, Input, Button, Alert, Turnstile } from '@cossackframework/ui';
3
+ import { html, component, bind } from '@cossackframework/renderer';
4
+ import { requestPasswordReset } from '#app/auth';
5
+ import { resetRequestInput, type ResetRequestInput } 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
+ @Page({ transport: 'http' })
10
+ export default class ForgotPasswordPage extends Cossack {
11
+ @ClientStore()
12
+ @Validate({
13
+ rules: storeRules<{ email: string }>({
14
+ email: { required: true, email: true, message: 'Enter a valid email' },
15
+ }),
16
+ config: { trigger: 'all', runOn: 'client' }
17
+ })
18
+ form: { email: string } = { email: '' };
19
+
20
+ @ClientState() submitted = false;
21
+ @ClientState() error = '';
22
+ /** The Turnstile site key while the bot check is on. */
23
+ @State() botKey: string | null = null;
24
+
25
+ async init() {
26
+ this.botKey = botCheckKey();
27
+ }
28
+
29
+ @Client()
30
+ async handleSubmit(event: Event) {
31
+ event.preventDefault();
32
+ this.error = '';
33
+ const ok = await this.validateAll();
34
+ if (!ok) return;
35
+ try {
36
+ await this.requestReset({ email: this.form.email, turnstile: botCheckToken(event.target) });
37
+ this.submitted = true;
38
+ } catch (error) {
39
+ this.error = isClientVisibleError(error) && error.message === BOT_CHECK_FAILED ? BOT_CHECK_FAILED : 'Could not send the reset link. Try again.';
40
+ }
41
+ }
42
+
43
+ @Server({ input: resetRequestInput })
44
+ async requestReset(submitted: ResetRequestInput) {
45
+ const { email, turnstile } = await resetRequestInput.parse(submitted);
46
+ // Before anything else, so a failed check says nothing about the account.
47
+ if (!(await passesBotCheck(turnstile, 'reset'))) throw new ClientVisibleError(BOT_CHECK_FAILED);
48
+ // Build the reset base URL from the request origin.
49
+ const origin = new URL(this.c.req.url).origin;
50
+ try {
51
+ await requestPasswordReset(email, origin);
52
+ } catch {
53
+ throw new ClientVisibleError('Could not send the reset link. Try again.');
54
+ }
55
+ }
56
+
57
+ render() {
58
+ return html`
59
+ <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Forgot Password')}</h3>
60
+ ${this.error ? html`<div class="mb-4">${component(Alert, { variant: 'destructive' }, this.error)}</div>` : null}
61
+ ${this.submitted
62
+ ? component(Alert, { variant: 'success', title: __('Check your email') },
63
+ __('If an account exists for that email, a reset link has been sent.'))
64
+ : html`<form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
65
+ ${component(Field, { label: __('Email'), for: 'email', error: this.getError('form.email'),
66
+ control: attributes => component(Input, { ...attributes, type: 'email', placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email') }) })}
67
+ ${this.botKey ? component(Turnstile, { id: 'reset-verify', siteKey: this.botKey, action: 'reset', label: __('Bot protection') }) : null}
68
+ ${component(Button, { type: 'submit', block: true }, __('Send Reset Link'))}
69
+ </form>`}
70
+ <p class="mt-6 text-center text-sm text-muted-foreground">
71
+ <a href="/auth/login" class="text-primary font-medium hover:underline">&larr; ${__('Back to Login')}</a>
72
+ </p>
73
+ `;
74
+ }
75
+ }
@@ -0,0 +1,32 @@
1
+ import { Cossack, Page, server$ } from '@cossackframework/core';
2
+ import { Card, CardBody } from '@cossackframework/ui';
3
+ import { html, component } from '@cossackframework/renderer';
4
+ import { signInBrand } from '#app/brand';
5
+
6
+ @Page({ transport: 'http' })
7
+ export default class AuthLayout extends Cossack {
8
+ brand = server$(() => signInBrand(), { initial: { name: 'Cossack', logo: '/logo.svg', logoOnly: false, home: '/', network: '', networkSignIn: null } });
9
+ render() {
10
+ return html`
11
+ <div class="flex justify-center items-center min-h-screen bg-muted/40 px-4">
12
+ ${component(Card, { class: 'w-full max-w-sm' }, html`
13
+ ${component(CardBody, { class: 'pt-6' }, html`
14
+ <a href=${this.brand.home} class="flex items-center justify-center gap-2 mb-6">
15
+ ${this.brand.logoOnly
16
+ ? html`<img src=${this.brand.logo} alt=${this.brand.name} width="48" height="48" class="h-12 w-auto max-w-56 object-contain" />`
17
+ : html`<img src=${this.brand.logo} alt="" width="32" height="32" class="h-8 w-auto max-w-32 object-contain" />
18
+ <span class="text-lg font-semibold text-foreground">${this.brand.name}</span>`}
19
+ </a>
20
+ ${this.brand.network ? html`<p class="-mt-4 mb-6 text-center text-sm text-muted-foreground">${__('Sign in with your account on')} ${this.brand.network}.</p>` : null}
21
+ ${this.children}
22
+ ${this.brand.networkSignIn ? html`<p class="mt-6 text-center text-sm text-muted-foreground">${__('Network account?')}
23
+ <a href=${this.brand.networkSignIn.href} data-network-sign-in class="font-medium text-primary hover:underline">${__('Sign in on')} ${this.brand.networkSignIn.name}</a></p>` : null}
24
+ <div class="mt-6 text-center text-sm">
25
+ <a href=${this.brand.home} class="text-muted-foreground hover:text-foreground">&larr; ${__('Back to Home')}</a>
26
+ </div>
27
+ `)}
28
+ `)}
29
+ </div>
30
+ `;
31
+ }
32
+ }
@@ -0,0 +1,198 @@
1
+ import { Cossack, Page, State, ClientStore, Validate, Client, Server, storeRules } from '@cossackframework/core';
2
+ import { Field, Input, PasswordInput, Button, Alert, Turnstile } from '@cossackframework/ui';
3
+ import { html, component, bind, unsafeHTML } from '@cossackframework/renderer';
4
+ import { setCookie } from 'hono/cookie';
5
+ import { authSessions, beginTwoFactor, completePasskeySignIn, createSession, loginUser, passkeySignIn, registrationOpen, requestMagicLink, twoFactorAvailable, TWO_FACTOR_COOKIE } from '#app/auth';
6
+ import { loginInput, returnPath, type LoginInput } from '#app/auth-input';
7
+ import { botCheckKey, passesBotCheck } from '#app/auth-bot-check';
8
+ import { BOT_CHECK_FAILED, botCheckToken } from '#app/auth-bot-token';
9
+ import { authOptions } from '#app/auth-options';
10
+ import { OAUTH_PROVIDER_ICONS, OAUTH_PROVIDER_LABELS } from '#app/auth-providers';
11
+
12
+ /** Why a provider's sign-in did not happen, by the `oauth` query the callback sends. */
13
+ const OAUTH_REFUSALS: Record<string, string> = {
14
+ unverified: 'The provider did not confirm your email address, so it cannot sign you in here.',
15
+ closed: 'There is no account for this email, and registration is closed on this site.',
16
+ pending: 'Your account waits for an administrator to approve it. We will email you when it is ready.',
17
+ inactive: 'This account cannot sign in.',
18
+ passkey: 'Two-step sign-in is required, and this account\'s second step is its passkey. Sign in with your passkey.',
19
+ };
20
+
21
+ /** Sign-in failures the visitor is told about, after the password matched or before it is checked; see auth.ts. */
22
+ const TOLD = new Set(['SignInLockedError', 'SignInPendingError', 'SignInPasskeyError']);
23
+ import { usePasskey } from '#app/passkeys.client';
24
+
25
+ interface LoginForm {
26
+ email: string;
27
+ password: string;
28
+ }
29
+
30
+ @Page({ transport: 'http' })
31
+ export default class LoginPage extends Cossack {
32
+ @ClientStore()
33
+ @Validate({
34
+ rules: storeRules<LoginForm>({
35
+ email: { required: true, email: true, message: 'Enter a valid email' },
36
+ password: { required: true, minLength: 8, message: 'Password must be at least 8 characters' },
37
+ }),
38
+ config: { trigger: 'all', runOn: 'client' }
39
+ })
40
+ form: LoginForm = { email: '', password: '' };
41
+
42
+ @State() error = '';
43
+ @State() canRegister = true;
44
+ /** The auth store supports passkeys. */
45
+ @State() passkeys = false;
46
+ /** A sign-in link was requested: the page says to check the email, whatever the address. */
47
+ @State() linkSent = false;
48
+ /** The Turnstile site key while the bot check is on. */
49
+ @State() botKey: string | null = null;
50
+ /** Where to go once signed in: the `redirect` query, such as a members-only entry. Checked again on use. */
51
+ @State() returnTo = '';
52
+ /** The OAuth providers the project offers (src/dashboard.config.ts), each a button. */
53
+ @State() oauth: string[] = [];
54
+ /** Email and password sign-in is on; off, the page shows the providers only. */
55
+ @State() credentials = true;
56
+
57
+ async init() {
58
+ this.oauth = authOptions.authMethods.includes('oauth') ? [...authOptions.oauth] : [];
59
+ this.credentials = authOptions.authMethods.includes('credentials');
60
+ this.error = OAUTH_REFUSALS[this.c.req.query('oauth') ?? ''] ?? '';
61
+ this.canRegister = await registrationOpen();
62
+ this.passkeys = twoFactorAvailable;
63
+ this.botKey = botCheckKey();
64
+ this.returnTo = returnPath(this.c.req.query('redirect')) ?? '';
65
+ }
66
+
67
+ /** Where a completed sign-in goes: the page the visitor came from, or the configured default. */
68
+ private signedInPath(): string {
69
+ return returnPath(this.returnTo) ?? config('auth.redirectAfterLogin');
70
+ }
71
+
72
+ @Client()
73
+ async handleSubmit(event: Event) {
74
+ event.preventDefault();
75
+ this.error = '';
76
+ const ok = await this.validateAll();
77
+ if (!ok) return;
78
+ try {
79
+ await this.login({ email: this.form.email, password: this.form.password, turnstile: botCheckToken(event.target) });
80
+ } catch {
81
+ this.error = 'Could not sign in. Check your details and try again.';
82
+ }
83
+ }
84
+
85
+ @Server({ input: loginInput })
86
+ async login(submitted: LoginInput) {
87
+ // Native server calls bypass decorator gates, so validate here too.
88
+ const { email, password, turnstile } = await loginInput.parse(submitted);
89
+ this.error = '';
90
+ if (!(await passesBotCheck(turnstile, 'login'))) { this.error = BOT_CHECK_FAILED; return; }
91
+ try {
92
+ const user = await loginUser(email, password);
93
+ if (!user) { this.error = 'Invalid credentials'; return; }
94
+ // With an authenticator app, the password only starts the sign-in.
95
+ const pending = await beginTwoFactor(user.id);
96
+ if (pending) {
97
+ setCookie(this.c, TWO_FACTOR_COOKIE, pending, { path: '/', httpOnly: true, sameSite: 'Lax', maxAge: 300, secure: new URL(this.c.req.url).protocol === 'https:' });
98
+ const back = returnPath(this.returnTo);
99
+ this.redirect(back ? `/auth/two-factor?redirect=${encodeURIComponent(back)}` : '/auth/two-factor');
100
+ return;
101
+ }
102
+ const { headers } = await authSessions.create(user.id, this.c);
103
+ headers.forEach((value, key) => this.c.header(key, value));
104
+ this.redirect(this.signedInPath());
105
+ } catch (error) {
106
+ // A lock (too many wrong passwords) and an account awaiting approval are the failures the visitor is told about.
107
+ this.error = TOLD.has((error as Error)?.name) ? (error as Error).message : 'Could not sign in. Try again.';
108
+ }
109
+ }
110
+
111
+ @Client()
112
+ async emailLink(event: Event) {
113
+ event.preventDefault();
114
+ if (!this.form.email) { this.error = __('Enter your email first.'); return; }
115
+ await this.sendLink(this.form.email, botCheckToken((event.target as HTMLElement | null)?.closest?.('form') ?? null));
116
+ }
117
+
118
+ /** Email a one-time sign-in link; the answer is the same whether the account exists. */
119
+ @Server()
120
+ async sendLink(email: string, turnstile = '') {
121
+ this.error = '';
122
+ if (!(await passesBotCheck(turnstile, 'login'))) { this.error = BOT_CHECK_FAILED; return; }
123
+ try { await requestMagicLink(String(email).trim().toLowerCase().slice(0, 254), new URL(this.c.req.url).origin); } catch { /* the page says the same either way */ }
124
+ this.linkSent = true;
125
+ }
126
+
127
+ /** Sign in with a passkey: no password and no code. */
128
+ @Client()
129
+ async signInWithPasskey() {
130
+ this.error = '';
131
+ try {
132
+ const { challenge, options } = await this.passkeyOptions();
133
+ const response = await usePasskey(options);
134
+ await this.passkeyLogin(challenge, response);
135
+ } catch (error) {
136
+ if ((error as Error)?.name === 'NotAllowedError') return;
137
+ this.error = (error as Error)?.message || 'The passkey sign-in did not work.';
138
+ }
139
+ }
140
+
141
+ @Server()
142
+ async passkeyOptions() {
143
+ return passkeySignIn(this.c);
144
+ }
145
+
146
+ @Server()
147
+ async passkeyLogin(challenge: string, response: unknown) {
148
+ const user = await completePasskeySignIn(this.c, challenge, response as never);
149
+ if (!user) { this.error = 'This passkey is not recognised.'; return; }
150
+ const { headers } = await createSession(user.id, this.c, { secondFactor: true });
151
+ headers.forEach((value, key) => this.c.header(key, value));
152
+ this.redirect(this.signedInPath());
153
+ }
154
+
155
+ render() {
156
+ const providers = this.oauth.length ? html`<div class="mt-4 space-y-2" aria-label="OAuth sign in options">
157
+ ${this.oauth.map(provider => html`<a href="/auth/${provider}/redirect" data-oauth-provider=${provider} class="inline-flex h-10 w-full items-center justify-center gap-2 rounded-md border border-input bg-background px-4 text-sm font-medium text-foreground shadow-xs transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50">
158
+ ${unsafeHTML(OAUTH_PROVIDER_ICONS[provider] ?? '')}
159
+ <span>Continue with ${OAUTH_PROVIDER_LABELS[provider] ?? provider}</span>
160
+ </a>`)}
161
+ </div>` : null;
162
+ if (!this.credentials) return html`
163
+ <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Login')}</h3>
164
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
165
+ ${providers}
166
+ `;
167
+ return html`
168
+ <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Login')}</h3>
169
+ <form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
170
+ ${component(Field, { label: __('Email'), for: 'email', error: this.getError('form.email'),
171
+ control: attributes => component(Input, { ...attributes, type: 'email', placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email') }) })}
172
+ ${component(Field, { label: __('Password'), for: 'password', error: this.getError('form.password'),
173
+ control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, onValueChange: (v: string) => this.form.password = v }) })}
174
+ <div class="flex items-center justify-between gap-3 text-sm">
175
+ <button type="button" class="text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${(e: Event) => this.emailLink(e)}>${__('Email me a sign-in link')}</button>
176
+ <a href="/auth/forgot-password" class="text-primary hover:underline">${__('Forgot password?')}</a>
177
+ </div>
178
+ ${this.linkSent ? component(Alert, {}, __('If an account exists for that email, a sign-in link is on its way. It works once, for fifteen minutes.')) : null}
179
+ ${this.botKey ? component(Turnstile, { id: 'login-verify', siteKey: this.botKey, action: 'login', label: __('Bot protection') }) : null}
180
+ ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
181
+ ${component(Button, { type: 'submit', block: true }, __('Sign In'))}
182
+ </form>
183
+ ${providers ? html`<div class="mt-6 flex items-center gap-3" aria-hidden="true">
184
+ <div class="h-px flex-1 bg-border"></div>
185
+ <span class="text-xs font-medium uppercase text-muted-foreground">or</span>
186
+ <div class="h-px flex-1 bg-border"></div>
187
+ </div>${providers}` : null}
188
+ ${this.passkeys ? html`<div class="mt-4 space-y-4">
189
+ <p class="flex items-center gap-3 text-xs uppercase text-muted-foreground"><span class="h-px flex-1 bg-border"></span>${__('or')}<span class="h-px flex-1 bg-border"></span></p>
190
+ ${component(Button, { type: 'button', variant: 'outline', block: true, '@click': () => this.signInWithPasskey() }, __('Sign in with a passkey'))}
191
+ </div>` : null}
192
+ <p class="mt-6 text-center text-sm text-muted-foreground" ?hidden=${!this.canRegister}>
193
+ ${__("Don't have an account?")}
194
+ <a href=${this.returnTo ? `/auth/register?redirect=${encodeURIComponent(this.returnTo)}` : '/auth/register'} class="text-primary font-medium hover:underline">${__('Register')}</a>
195
+ </p>
196
+ `;
197
+ }
198
+ }