@cossackframework/cms 0.0.0 → 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 +145 -2
  3. package/agent-docs.json +259 -0
  4. package/app/README.md +78 -0
  5. package/app/cossack-recipe.json +43 -0
  6. package/app/src/auth-bot-check.ts +32 -0
  7. package/app/src/auth-bot-token.ts +11 -0
  8. package/app/src/auth-input.ts +35 -0
  9. package/app/src/auth-options.ts +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 +114 -2
  308. package/src/automations.ts +95 -0
  309. package/src/bindings.ts +138 -0
  310. package/src/block-references.ts +239 -0
  311. package/src/block-shape.ts +155 -0
  312. package/src/blocks.ts +1157 -0
  313. package/src/cache.ts +54 -0
  314. package/src/checks.ts +198 -0
  315. package/src/cloudflare-workers.d.ts +13 -0
  316. package/src/cloudflare.ts +61 -0
  317. package/src/collab.ts +372 -0
  318. package/src/collections.ts +421 -0
  319. package/src/comments.ts +46 -0
  320. package/src/cron.ts +95 -0
  321. package/src/dashboard-menu.ts +105 -0
  322. package/src/diff.ts +113 -0
  323. package/src/editor-layout.ts +316 -0
  324. package/src/errors.ts +50 -0
  325. package/src/field-groups.ts +498 -0
  326. package/src/fields.ts +411 -0
  327. package/src/form-builder.ts +1053 -0
  328. package/src/forms.ts +109 -0
  329. package/src/highlight.ts +134 -0
  330. package/src/hooks.ts +510 -0
  331. package/src/icon-catalog.ts +55 -0
  332. package/src/icons.ts +128 -0
  333. package/src/images.ts +149 -0
  334. package/src/index.ts +100 -0
  335. package/src/isolate-core.ts +245 -0
  336. package/src/isolate.ts +19 -0
  337. package/src/isolation.ts +69 -0
  338. package/src/mail.ts +182 -0
  339. package/src/manifest.ts +476 -0
  340. package/src/media.ts +193 -0
  341. package/src/menus.ts +287 -0
  342. package/src/module.ts +32 -0
  343. package/src/modules/content.ts +64 -0
  344. package/src/modules/forms.ts +35 -0
  345. package/src/node.ts +66 -0
  346. package/src/notes.ts +237 -0
  347. package/src/permissions.ts +139 -0
  348. package/src/plugin-settings.ts +114 -0
  349. package/src/records.ts +56 -0
  350. package/src/redirects.ts +59 -0
  351. package/src/resource.ts +245 -0
  352. package/src/richtext.ts +402 -0
  353. package/src/schema-json.ts +112 -0
  354. package/src/search.ts +89 -0
  355. package/src/seo.ts +477 -0
  356. package/src/server/accounts.ts +418 -0
  357. package/src/server/ai.ts +33 -0
  358. package/src/server/api-tokens.ts +91 -0
  359. package/src/server/areas.ts +116 -0
  360. package/src/server/audit.ts +94 -0
  361. package/src/server/auth.ts +89 -0
  362. package/src/server/automations.ts +190 -0
  363. package/src/server/autosaves.ts +69 -0
  364. package/src/server/brand-icons.ts +50 -0
  365. package/src/server/brands.ts +86 -0
  366. package/src/server/budget.ts +97 -0
  367. package/src/server/cache.ts +104 -0
  368. package/src/server/capabilities.ts +333 -0
  369. package/src/server/cloudflare.ts +92 -0
  370. package/src/server/comments.ts +237 -0
  371. package/src/server/drafts.ts +176 -0
  372. package/src/server/field-groups.ts +88 -0
  373. package/src/server/files.ts +780 -0
  374. package/src/server/forms.ts +726 -0
  375. package/src/server/handoffs.ts +107 -0
  376. package/src/server/host-schema.ts +312 -0
  377. package/src/server/host.ts +2892 -0
  378. package/src/server/images.ts +34 -0
  379. package/src/server/index.ts +59 -0
  380. package/src/server/indexnow.ts +91 -0
  381. package/src/server/isolation.ts +183 -0
  382. package/src/server/locked.ts +45 -0
  383. package/src/server/mail.ts +93 -0
  384. package/src/server/markdown.ts +24 -0
  385. package/src/server/menus.ts +286 -0
  386. package/src/server/network-policy.ts +60 -0
  387. package/src/server/network.ts +665 -0
  388. package/src/server/notes.ts +275 -0
  389. package/src/server/outbox.ts +213 -0
  390. package/src/server/path-moves.ts +33 -0
  391. package/src/server/payments.ts +59 -0
  392. package/src/server/previews.ts +62 -0
  393. package/src/server/purge.ts +140 -0
  394. package/src/server/reconcile.ts +38 -0
  395. package/src/server/redirects.ts +183 -0
  396. package/src/server/repository.ts +1107 -0
  397. package/src/server/schedules.ts +105 -0
  398. package/src/server/schema.ts +562 -0
  399. package/src/server/security.ts +391 -0
  400. package/src/server/seed.ts +52 -0
  401. package/src/server/shared-fields.ts +34 -0
  402. package/src/server/site-export.ts +151 -0
  403. package/src/server/site-import.ts +482 -0
  404. package/src/server/site-search.ts +289 -0
  405. package/src/server/site-settings.ts +286 -0
  406. package/src/server/sites.ts +243 -0
  407. package/src/server/stores.ts +314 -0
  408. package/src/server/stripe.ts +173 -0
  409. package/src/server/taxonomies.ts +415 -0
  410. package/src/server/tokens.ts +25 -0
  411. package/src/server/traffic.ts +118 -0
  412. package/src/server/users.ts +653 -0
  413. package/src/server/webhooks.ts +245 -0
  414. package/src/settings-controls.ts +54 -0
  415. package/src/settings-document.ts +111 -0
  416. package/src/settings.ts +426 -0
  417. package/src/storage/cloudflare.ts +94 -0
  418. package/src/storage/index.ts +30 -0
  419. package/src/storage/node.ts +114 -0
  420. package/src/taxonomy.ts +51 -0
  421. package/src/theme.ts +1135 -0
  422. package/src/to-markdown.ts +179 -0
  423. package/src/updates.ts +126 -0
  424. package/src/version.ts +2 -0
  425. package/src/vite.d.ts +25 -0
  426. package/src/vite.js +199 -0
  427. package/src/webhooks.ts +107 -0
package/src/media.ts ADDED
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Media helpers shared by the dashboard and the server: accepted types, file signatures,
3
+ * image dimensions and public URLs. Pure functions over bytes; no I/O.
4
+ */
5
+
6
+ /**
7
+ * Content types with a known signature. Every type is accepted: these are checked against the
8
+ * file's first bytes, SVG is sanitized, and the rest are stored as declared and served as
9
+ * downloads. A `FileService` can still be limited to a list.
10
+ */
11
+ export const MEDIA_TYPES = Object.freeze([
12
+ 'image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif', 'image/svg+xml',
13
+ 'application/pdf', 'text/plain', 'video/mp4', 'video/webm', 'audio/mpeg',
14
+ ]);
15
+
16
+ export const SVG_TYPE = 'image/svg+xml';
17
+
18
+ /** Archives, for the library's filter. */
19
+ export const ARCHIVE_TYPES = Object.freeze(['application/zip', 'application/x-zip-compressed', 'application/gzip', 'application/x-gzip', 'application/x-tar', 'application/x-7z-compressed', 'application/x-rar-compressed', 'application/vnd.rar', 'application/x-bzip2']);
20
+
21
+ export type MediaKind = 'image' | 'video' | 'audio' | 'archive' | 'document';
22
+
23
+ /** Profile pictures: still and animated images (GIF, APNG, animated WebP and AVIF). */
24
+ export const AVATAR_TYPES = Object.freeze(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif']);
25
+
26
+ export function mediaKind(contentType: string): MediaKind {
27
+ if (contentType.startsWith('image/')) return 'image';
28
+ if (contentType.startsWith('video/')) return 'video';
29
+ if (contentType.startsWith('audio/')) return 'audio';
30
+ if (ARCHIVE_TYPES.includes(contentType)) return 'archive';
31
+ return 'document';
32
+ }
33
+
34
+ /** Content type prefixes for each library filter; `document` is everything else. */
35
+ export const MEDIA_FILTERS: { readonly [K in MediaKind]: readonly string[] } = Object.freeze({
36
+ image: ['image/'], video: ['video/'], audio: ['audio/'], archive: ARCHIVE_TYPES, document: ['application/', 'text/'],
37
+ });
38
+
39
+ /** The types a kind filter leaves out, for `document`. */
40
+ export const MEDIA_FILTER_EXCLUDES: { readonly [K in MediaKind]?: readonly string[] } = Object.freeze({ document: ARCHIVE_TYPES });
41
+
42
+ /** A file's name with a content type the browser did not name: `application/octet-stream`. */
43
+ export function declaredType(contentType: string): string {
44
+ const type = contentType.split(';')[0]!.trim().toLowerCase();
45
+ return /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/.test(type) ? type : 'application/octet-stream';
46
+ }
47
+
48
+ /** Content types of common file extensions, so a file's type follows its name and then its signature, not what the browser declared. */
49
+ export const EXTENSION_TYPES: { readonly [extension: string]: string } = Object.freeze({
50
+ png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', avif: 'image/avif', svg: SVG_TYPE, heic: 'image/heic',
51
+ pdf: 'application/pdf', txt: 'text/plain', csv: 'text/csv', md: 'text/markdown', rtf: 'application/rtf', json: 'application/json', xml: 'application/xml',
52
+ doc: 'application/msword', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
53
+ xls: 'application/vnd.ms-excel', xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
54
+ ppt: 'application/vnd.ms-powerpoint', pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
55
+ odt: 'application/vnd.oasis.opendocument.text', ods: 'application/vnd.oasis.opendocument.spreadsheet', odp: 'application/vnd.oasis.opendocument.presentation',
56
+ zip: 'application/zip', gz: 'application/gzip', tar: 'application/x-tar', '7z': 'application/x-7z-compressed', rar: 'application/vnd.rar',
57
+ mp4: 'video/mp4', webm: 'video/webm', mov: 'video/quicktime', mp3: 'audio/mpeg', wav: 'audio/wav', ogg: 'audio/ogg', m4a: 'audio/mp4',
58
+ html: 'text/html', htm: 'text/html', js: 'text/javascript', mjs: 'text/javascript', css: 'text/css',
59
+ });
60
+
61
+ /** A file's extension, lowercase without the dot; empty when its name has none. */
62
+ export function fileExtension(name: string): string {
63
+ const match = /\.([A-Za-z0-9]{1,16})$/.exec(name.trim());
64
+ return match ? match[1]!.toLowerCase() : '';
65
+ }
66
+
67
+ /** The type a file is taken as: its extension's, when known, else the declared one. The stored bytes must then match it (`matchesSignature`). */
68
+ export function fileType(name: string, declared: string): string {
69
+ const extension = fileExtension(name);
70
+ return Object.hasOwn(EXTENSION_TYPES, extension) ? EXTENSION_TYPES[extension]! : declaredType(declared);
71
+ }
72
+
73
+ /**
74
+ * SVG with its script removed: `<script>`, event handler attributes, `javascript:` URLs,
75
+ * `<foreignObject>`, and references to other documents. The result is still the same drawing.
76
+ * The site also serves SVG under a Content Security Policy that forbids script, so this is the
77
+ * second of two locks. Null when the text is not an SVG document.
78
+ */
79
+ export function sanitizeSvg(text: string): string | null {
80
+ if (!/^\s*(?:<\?xml[^>]*\?>\s*)?(?:<!--[\s\S]*?-->\s*)*(?:<!DOCTYPE[^>]*>\s*)?<svg[\s>]/i.test(text)) return null;
81
+ let clean = text.replace(/<!DOCTYPE[^>]*(?:\[[\s\S]*?\])?[^>]*>/gi, '');
82
+ // Elements that run or load code, with their content.
83
+ clean = clean.replace(/<(script|foreignObject|iframe|embed|object|set|animate|animateTransform|animateMotion|handler|listener)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, '').replace(/<(script|foreignObject|iframe|embed|object|set|animate|animateTransform|animateMotion|handler|listener)\b[^>]*\/?>/gi, '');
84
+ // Event handlers and script URLs in attributes.
85
+ clean = clean.replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, '');
86
+ clean = clean.replace(/\s+(href|xlink:href|src|action|formaction|data)\s*=\s*("|')\s*(?:javascript|data|vbscript)\s*:[^"']*\2/gi, '');
87
+ // Links to other documents keep the picture from fetching anything: only fragment references stay.
88
+ clean = clean.replace(/\s+(href|xlink:href)\s*=\s*("|')(?!#)[^"']*\2/gi, '');
89
+ clean = clean.replace(/url\(\s*(?:"|')?\s*(?!#)[^)]*\)/gi, 'none');
90
+ return clean;
91
+ }
92
+
93
+ /** The public URL of a stored file. The name is decorative; the ID selects the file. */
94
+ export function mediaUrl(file: { readonly id: string; readonly name: string }): string {
95
+ return `/media/${file.id}/${encodeURIComponent(file.name)}`;
96
+ }
97
+
98
+ export function formatBytes(size: number): string {
99
+ if (size < 1024) return `${size} B`;
100
+ const units = ['KB', 'MB', 'GB'];
101
+ let value = size / 1024;
102
+ let unit = 0;
103
+ while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit++; }
104
+ return `${value >= 10 ? Math.round(value) : Math.round(value * 10) / 10} ${units[unit]}`;
105
+ }
106
+
107
+ const ascii = (bytes: Uint8Array, offset: number, length: number) => String.fromCharCode(...bytes.subarray(offset, offset + length));
108
+
109
+ /**
110
+ * True when the first bytes fit the declared type. Images, PDF, video and audio have
111
+ * signatures; plain text must not contain NUL bytes.
112
+ */
113
+ export function matchesSignature(contentType: string, head: Uint8Array): boolean {
114
+ switch (contentType) {
115
+ case 'image/png': return head.length >= 8 && head[0] === 0x89 && ascii(head, 1, 3) === 'PNG' && head[4] === 0x0d && head[5] === 0x0a;
116
+ case 'image/jpeg': return head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff;
117
+ case 'image/gif': return ['GIF87a', 'GIF89a'].includes(ascii(head, 0, 6));
118
+ case 'image/webp': return ascii(head, 0, 4) === 'RIFF' && ascii(head, 8, 4) === 'WEBP';
119
+ case 'image/avif': return ascii(head, 4, 4) === 'ftyp' && ['avif', 'avis'].includes(ascii(head, 8, 4));
120
+ case 'application/pdf': return ascii(head, 0, 5) === '%PDF-';
121
+ case 'video/mp4': return ascii(head, 4, 4) === 'ftyp';
122
+ case 'video/webm': return head.length >= 4 && head[0] === 0x1a && head[1] === 0x45 && head[2] === 0xdf && head[3] === 0xa3;
123
+ case 'audio/mpeg': return ascii(head, 0, 3) === 'ID3' || (head.length >= 2 && head[0] === 0xff && (head[1]! & 0xe0) === 0xe0);
124
+ case 'text/plain': return !head.includes(0);
125
+ case 'image/svg+xml': return /^\s*(?:<\?xml[\s\S]{0,200}?\?>\s*)?(?:<!--[\s\S]*?-->\s*)*(?:<!DOCTYPE[\s\S]{0,500}?>\s*)?<svg[\s>]/i.test(new TextDecoder().decode(head.subarray(0, 2048)));
126
+ // Other types have no signature to check: they are stored as declared and served as downloads.
127
+ default: return true;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Whether an image can have transparent pixels, from its first bytes: a PNG with an alpha
133
+ * channel or a `tRNS` chunk before its image data, or a WebP whose header flags alpha. JPEG
134
+ * never does; other types are taken as opaque. A blurred placeholder behind such an image would
135
+ * show through it once it has loaded, so transparent images get none.
136
+ */
137
+ export function imageHasAlpha(contentType: string, bytes: Uint8Array): boolean {
138
+ try {
139
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
140
+ if (contentType === 'image/png') {
141
+ if (bytes.length < 29 || ascii(bytes, 12, 4) !== 'IHDR') return false;
142
+ // The color type: 4 is grayscale with alpha, 6 is truecolor with alpha.
143
+ const colorType = bytes[25]!;
144
+ if (colorType === 4 || colorType === 6) return true;
145
+ for (let offset = 8; offset + 8 <= bytes.length;) {
146
+ const type = ascii(bytes, offset + 4, 4);
147
+ if (type === 'tRNS') return true;
148
+ if (type === 'IDAT' || type === 'IEND') return false;
149
+ offset += 12 + view.getUint32(offset);
150
+ }
151
+ return false;
152
+ }
153
+ if (contentType === 'image/webp' && bytes.length >= 30) {
154
+ const chunk = ascii(bytes, 12, 4);
155
+ if (chunk === 'VP8X') return (bytes[20]! & 0x10) !== 0;
156
+ if (chunk === 'VP8L') return ((view.getUint32(21, true) >>> 28) & 1) === 1;
157
+ }
158
+ } catch { /* truncated header */ }
159
+ return false;
160
+ }
161
+
162
+ /** Width and height of a PNG, GIF, JPEG or WebP image from its first bytes, or null. */
163
+ export function imageSize(contentType: string, bytes: Uint8Array): { width: number; height: number } | null {
164
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
165
+ const valid = (width: number, height: number) => width > 0 && height > 0 ? { width, height } : null;
166
+ try {
167
+ if (contentType === 'image/png' && bytes.length >= 24 && ascii(bytes, 12, 4) === 'IHDR') return valid(view.getUint32(16), view.getUint32(20));
168
+ if (contentType === 'image/gif' && bytes.length >= 10) return valid(view.getUint16(6, true), view.getUint16(8, true));
169
+ if (contentType === 'image/webp' && bytes.length >= 30) {
170
+ const chunk = ascii(bytes, 12, 4);
171
+ if (chunk === 'VP8 ') return valid(view.getUint16(26, true) & 0x3fff, view.getUint16(28, true) & 0x3fff);
172
+ if (chunk === 'VP8L') {
173
+ const bits = view.getUint32(21, true);
174
+ return valid((bits & 0x3fff) + 1, ((bits >> 14) & 0x3fff) + 1);
175
+ }
176
+ if (chunk === 'VP8X') return valid(1 + (bytes[24]! | bytes[25]! << 8 | bytes[26]! << 16), 1 + (bytes[27]! | bytes[28]! << 8 | bytes[29]! << 16));
177
+ return null;
178
+ }
179
+ if (contentType === 'image/jpeg') {
180
+ // Walk the segments to the first start-of-frame marker.
181
+ let offset = 2;
182
+ while (offset + 9 < bytes.length) {
183
+ if (bytes[offset] !== 0xff) return null;
184
+ const marker = bytes[offset + 1]!;
185
+ if (marker === 0xd8 || (marker >= 0xd0 && marker <= 0xd7) || marker === 0x01 || marker === 0xff) { offset += marker === 0xff ? 1 : 2; continue; }
186
+ const length = view.getUint16(offset + 2);
187
+ if (marker >= 0xc0 && marker <= 0xcf && ![0xc4, 0xc8, 0xcc].includes(marker)) return valid(view.getUint16(offset + 7), view.getUint16(offset + 5));
188
+ offset += 2 + length;
189
+ }
190
+ }
191
+ } catch { /* truncated header */ }
192
+ return null;
193
+ }
package/src/menus.ts ADDED
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Navigation menus: a tree of items saved as one document. Items link to a URL, an entry, a
3
+ * collection archive or a term, or are a heading that groups the links under it; entries and
4
+ * terms are stored by ID and resolved when the site renders. An item may carry a description,
5
+ * a panel (a pattern the theme shows beside its links, for mega menus) and the values of the
6
+ * field groups attached to menu items. Client-safe: the dashboard edits the tree with the
7
+ * helpers below, the host validates it on save.
8
+ */
9
+ import { safeLinkUrl } from './richtext';
10
+ import type { FieldView, RenderedBlock } from './theme';
11
+
12
+ export type MenuItemKind = 'link' | 'entry' | 'archive' | 'term' | 'heading';
13
+
14
+ export interface MenuItem {
15
+ /** Stable within the menu: 1-40 letters, digits, `_` or `-`. */
16
+ readonly id: string;
17
+ readonly kind: MenuItemKind;
18
+ /** Text shown on the site. Empty uses the entry's title, the collection's label or the term's name. */
19
+ readonly label: string;
20
+ /** link: the URL. */
21
+ readonly url?: string;
22
+ /** entry and archive: the collection name. */
23
+ readonly collection?: string;
24
+ /** entry: the entry ID. */
25
+ readonly entry?: string;
26
+ /** term: the taxonomy and term ID. */
27
+ readonly taxonomy?: string;
28
+ readonly term?: string;
29
+ /** A line under the link in a mega menu panel; at most 300 characters. */
30
+ readonly description?: string;
31
+ /** The ID of a pattern shown beside the item's links, for a mega menu. */
32
+ readonly panel?: string;
33
+ /** Open in a new tab. */
34
+ readonly newTab?: boolean;
35
+ /** Extra class names on the item's link, for the theme's stylesheet. */
36
+ readonly className?: string;
37
+ /** Extra attributes on the item's link, such as `data-track` or `rel`. */
38
+ readonly attributes?: { readonly [name: string]: string };
39
+ /** Values of the field groups attached to menu items. */
40
+ readonly meta?: { readonly [field: string]: unknown };
41
+ readonly children: readonly MenuItem[];
42
+ }
43
+
44
+ export interface MenuShape {
45
+ readonly id: string;
46
+ readonly name: string;
47
+ readonly items: readonly MenuItem[];
48
+ readonly revision: number;
49
+ readonly createdAt: number;
50
+ readonly updatedAt: number;
51
+ }
52
+
53
+ /**
54
+ * An item the host resolved for visitors: entries, archives and terms have their current title
55
+ * and URL, items whose target is gone are left out. `meta` is still raw and `panel` a pattern
56
+ * ID; the site finishes them into a `MenuItemView`.
57
+ */
58
+ export interface ResolvedMenuItem {
59
+ readonly id: string;
60
+ readonly label: string;
61
+ /** Null for a heading. */
62
+ readonly url: string | null;
63
+ readonly newTab: boolean;
64
+ readonly kind: MenuItemKind;
65
+ readonly description: string;
66
+ readonly className: string;
67
+ readonly attributes: { readonly [name: string]: string };
68
+ readonly meta: { readonly [field: string]: unknown };
69
+ readonly panel: string | null;
70
+ readonly children: readonly ResolvedMenuItem[];
71
+ }
72
+
73
+ /** An item as the site and the content API show it: its fields typed and its panel rendered. */
74
+ export interface MenuItemView {
75
+ readonly id: string;
76
+ readonly label: string;
77
+ /** Null for a heading, which groups the links under it. */
78
+ readonly url: string | null;
79
+ readonly newTab: boolean;
80
+ readonly kind: MenuItemKind;
81
+ readonly description: string;
82
+ readonly className: string;
83
+ readonly attributes: { readonly [name: string]: string };
84
+ /** The values of the field groups attached to menu items, typed like `EntryView.fields`. */
85
+ readonly fields: { readonly [name: string]: FieldView };
86
+ /** The item's panel pattern rendered, or null: render it with `helpers.block`. */
87
+ readonly panel: readonly RenderedBlock[] | null;
88
+ readonly children: readonly MenuItemView[];
89
+ }
90
+
91
+ export const MENU_LIMITS = Object.freeze({ items: 300, depth: 5, label: 120, description: 300, name: 80, className: 200, attributes: 10, attributeValue: 500 });
92
+ /** Attribute names an item may set: lowercase, hyphenated, never an event handler or what the link already sets. */
93
+ export const MENU_ATTRIBUTE = /^(?!on)[a-z][a-z0-9-]{0,60}$/;
94
+ const FIXED_ATTRIBUTES = new Set(['href', 'class', 'target', 'style', 'srcdoc']);
95
+ export const MENU_LOCATION = /^[a-z][a-z0-9-]{0,31}$/;
96
+
97
+ const ITEM_ID = /^[A-Za-z0-9_-]{1,40}$/;
98
+ const NAME = /^[a-z][a-z0-9_]*$/;
99
+ const RECORD_ID = /^[A-Za-z0-9_-]{1,80}$/;
100
+ const KINDS = new Set(['link', 'entry', 'archive', 'term', 'heading']);
101
+
102
+ /** Problems with a menu's items; empty when it can be saved. */
103
+ export function menuProblems(items: unknown): string[] {
104
+ const problems: string[] = [];
105
+ if (!Array.isArray(items)) return ['Menu items must be a list.'];
106
+ const ids = new Set<string>();
107
+ let count = 0;
108
+ const visit = (list: readonly unknown[], depth: number) => {
109
+ for (const value of list) {
110
+ count++;
111
+ const item = value as Partial<MenuItem> | null;
112
+ const at = `Item ${typeof item?.label === 'string' && item.label ? `“${item.label.slice(0, 40)}”` : count}`;
113
+ if (!item || typeof item !== 'object' || Array.isArray(item)) { problems.push(`Item ${count} must be an object.`); continue; }
114
+ if (typeof item.id !== 'string' || !ITEM_ID.test(item.id) || ids.has(item.id)) problems.push(`${at} needs a distinct ID.`);
115
+ else ids.add(item.id);
116
+ if (!KINDS.has(item.kind as string)) problems.push(`${at}: the kind is link, entry, archive, term or heading.`);
117
+ if (typeof item.label !== 'string' || [...item.label].length > MENU_LIMITS.label) problems.push(`${at}: labels are at most ${MENU_LIMITS.label} characters.`);
118
+ else if ((item.kind === 'link' || item.kind === 'heading') && !item.label.trim()) problems.push(`${at}: ${item.kind === 'link' ? 'custom links' : 'headings'} need a label.`);
119
+ if (item.kind === 'link' && !safeLinkUrl(item.url)) problems.push(`${at}: the URL must start with https://, http://, /, #, mailto: or tel:.`);
120
+ if ((item.kind === 'entry' || item.kind === 'archive') && (typeof item.collection !== 'string' || !NAME.test(item.collection))) problems.push(`${at} needs a collection.`);
121
+ if (item.kind === 'entry' && (typeof item.entry !== 'string' || !RECORD_ID.test(item.entry))) problems.push(`${at} needs an entry.`);
122
+ if (item.kind === 'term' && (typeof item.taxonomy !== 'string' || !/^[a-z][a-zA-Z0-9]{0,40}$/.test(item.taxonomy) || typeof item.term !== 'string' || !RECORD_ID.test(item.term))) problems.push(`${at} needs a term.`);
123
+ if (item.description !== undefined && (typeof item.description !== 'string' || [...item.description].length > MENU_LIMITS.description)) problems.push(`${at}: descriptions are at most ${MENU_LIMITS.description} characters.`);
124
+ if (item.panel !== undefined && item.panel !== '' && (typeof item.panel !== 'string' || !RECORD_ID.test(item.panel))) problems.push(`${at}: the panel is a pattern's ID.`);
125
+ if (item.newTab !== undefined && typeof item.newTab !== 'boolean') problems.push(`${at}: newTab is true or false.`);
126
+ if (item.className !== undefined && (typeof item.className !== 'string' || item.className.length > MENU_LIMITS.className)) problems.push(`${at}: class names are at most ${MENU_LIMITS.className} characters.`);
127
+ if (item.attributes !== undefined) {
128
+ const entries = item.attributes && typeof item.attributes === 'object' && !Array.isArray(item.attributes) ? Object.entries(item.attributes) : null;
129
+ if (!entries) problems.push(`${at}: attributes map names to values.`);
130
+ else if (entries.length > MENU_LIMITS.attributes) problems.push(`${at}: at most ${MENU_LIMITS.attributes} attributes.`);
131
+ else for (const [name, value] of entries) {
132
+ if (!MENU_ATTRIBUTE.test(name) || FIXED_ATTRIBUTES.has(name)) problems.push(`${at}: ${name} is not an attribute an item can set.`);
133
+ if (typeof value !== 'string' || value.length > MENU_LIMITS.attributeValue) problems.push(`${at}: the value of ${name} is at most ${MENU_LIMITS.attributeValue} characters.`);
134
+ }
135
+ }
136
+ if (item.meta !== undefined && (item.meta === null || typeof item.meta !== 'object' || Array.isArray(item.meta))) problems.push(`${at}: meta is an object of fields.`);
137
+ if (!Array.isArray(item.children)) { problems.push(`${at}: children must be a list.`); continue; }
138
+ if (item.children.length && depth + 1 >= MENU_LIMITS.depth) problems.push(`${at}: menus nest at most ${MENU_LIMITS.depth} levels deep.`);
139
+ else visit(item.children, depth + 1);
140
+ }
141
+ };
142
+ visit(items, 0);
143
+ if (count > MENU_LIMITS.items) problems.push(`A menu holds at most ${MENU_LIMITS.items} items.`);
144
+ return problems;
145
+ }
146
+
147
+ /** A clean copy of valid items: only the fields of each kind. */
148
+ export function normalizeMenu(items: readonly MenuItem[]): MenuItem[] {
149
+ return items.map(item => Object.freeze({
150
+ id: item.id, kind: item.kind, label: item.label.trim(),
151
+ ...(item.kind === 'link' ? { url: item.url } : {}),
152
+ ...(item.kind === 'entry' || item.kind === 'archive' ? { collection: item.collection } : {}),
153
+ ...(item.kind === 'entry' ? { entry: item.entry } : {}),
154
+ ...(item.kind === 'term' ? { taxonomy: item.taxonomy, term: item.term } : {}),
155
+ ...(item.description?.trim() ? { description: item.description.trim() } : {}),
156
+ ...(item.panel ? { panel: item.panel } : {}),
157
+ ...(item.newTab && item.kind !== 'heading' ? { newTab: true } : {}),
158
+ ...(item.className?.trim() ? { className: item.className.trim().split(/\s+/).join(' ') } : {}),
159
+ ...(item.attributes && Object.keys(item.attributes).length ? { attributes: Object.freeze(Object.fromEntries(Object.entries(item.attributes).map(([name, value]) => [name, value.trim()]))) } : {}),
160
+ ...(item.meta && Object.keys(item.meta).length ? { meta: Object.freeze({ ...item.meta }) } : {}),
161
+ children: Object.freeze(normalizeMenu(item.children)),
162
+ }));
163
+ }
164
+
165
+ /** Items counted across every level. */
166
+ export function menuSize(items: readonly MenuItem[]): number {
167
+ return items.reduce((total, item) => total + 1 + menuSize(item.children), 0);
168
+ }
169
+
170
+ export function menuItemId(): string {
171
+ return crypto.randomUUID().replaceAll('-', '').slice(0, 12);
172
+ }
173
+
174
+ // --- Editing as a flat list -------------------------------------------------------------
175
+ // The editor shows the tree as rows with depths: a row's parent is the nearest row above it
176
+ // with a smaller depth. A row and the deeper rows after it are its subtree.
177
+
178
+ export type MenuRow = Omit<MenuItem, 'children'> & { readonly depth: number };
179
+
180
+ /** The tree as rows, parents before their children. */
181
+ export function flattenMenu(items: readonly MenuItem[], depth = 0): MenuRow[] {
182
+ return items.flatMap(({ children, ...item }) => [{ ...item, depth }, ...flattenMenu(children, depth + 1)]);
183
+ }
184
+
185
+ /** Rows back to a tree. Depths that skip a level attach to the nearest possible parent. */
186
+ export function buildMenu(rows: readonly MenuRow[]): MenuItem[] {
187
+ const root: MenuItem[] = [];
188
+ const stack: { depth: number; children: MenuItem[] }[] = [{ depth: -1, children: root }];
189
+ for (const { depth, ...item } of rows) {
190
+ while (stack.length > 1 && stack.at(-1)!.depth >= depth) stack.pop();
191
+ const children: MenuItem[] = [];
192
+ stack.at(-1)!.children.push({ ...item, children });
193
+ stack.push({ depth, children });
194
+ }
195
+ return root;
196
+ }
197
+
198
+ /** The index after a row's subtree. */
199
+ export function subtreeEnd(rows: readonly MenuRow[], index: number): number {
200
+ const depth = rows[index]!.depth;
201
+ let end = index + 1;
202
+ while (end < rows.length && rows[end]!.depth > depth) end++;
203
+ return end;
204
+ }
205
+
206
+ /** Levels below a row: 0 for a row without children. */
207
+ function subtreeHeight(rows: readonly MenuRow[], index: number): number {
208
+ const end = subtreeEnd(rows, index);
209
+ let height = 0;
210
+ for (let row = index; row < end; row++) height = Math.max(height, rows[row]!.depth - rows[index]!.depth);
211
+ return height;
212
+ }
213
+
214
+ /**
215
+ * Depths a subtree can take when inserted before position `to` of the rows without it: at
216
+ * most one deeper than the row above, and no shallower than the row below, which keeps its
217
+ * parent. `max < min` means the subtree cannot go there.
218
+ */
219
+ export function dropDepths(rows: readonly MenuRow[], from: number, to: number): { min: number; max: number } {
220
+ const end = subtreeEnd(rows, from);
221
+ const rest = [...rows.slice(0, from), ...rows.slice(end)];
222
+ const above = rest[to - 1];
223
+ const below = rest[to];
224
+ const max = Math.min(above ? above.depth + 1 : 0, MENU_LIMITS.depth - 1 - subtreeHeight(rows, from));
225
+ return { min: below ? below.depth : 0, max };
226
+ }
227
+
228
+ /**
229
+ * Move the subtree at `from` before position `to` of the rows without it, with its root at
230
+ * `depth` (clamped to what fits there). Returns the rows unchanged when it does not fit.
231
+ */
232
+ export function moveRows(rows: readonly MenuRow[], from: number, to: number, depth: number): MenuRow[] {
233
+ if (from < 0 || from >= rows.length) return [...rows];
234
+ const end = subtreeEnd(rows, from);
235
+ const moving = rows.slice(from, end);
236
+ const rest = [...rows.slice(0, from), ...rows.slice(end)];
237
+ const position = Math.min(Math.max(to, 0), rest.length);
238
+ const { min, max } = dropDepths(rows, from, position);
239
+ if (max < min) return [...rows];
240
+ const target = Math.min(Math.max(depth, min), max);
241
+ const shift = target - moving[0]!.depth;
242
+ return [...rest.slice(0, position), ...moving.map(row => ({ ...row, depth: row.depth + shift })), ...rest.slice(position)];
243
+ }
244
+
245
+ export type MenuMove = 'up' | 'down' | 'in' | 'out';
246
+
247
+ /** The moves the row at `index` allows, for its buttons. */
248
+ export function allowedMoves(rows: readonly MenuRow[], index: number): Set<MenuMove> {
249
+ const moves = new Set<MenuMove>();
250
+ for (const move of ['up', 'down', 'in', 'out'] as const) if (shiftRows(rows, index, move) !== rows) moves.add(move);
251
+ return moves;
252
+ }
253
+
254
+ /**
255
+ * WordPress's move links: up or down past a sibling, in under the sibling above (as its last
256
+ * child), or out to follow its parent. Returns the same array when the move is not possible.
257
+ */
258
+ export function shiftRows(rows: readonly MenuRow[], index: number, move: MenuMove): readonly MenuRow[] {
259
+ const row = rows[index];
260
+ if (!row) return rows;
261
+ const end = subtreeEnd(rows, index);
262
+ const previousSibling = (() => {
263
+ for (let other = index - 1; other >= 0; other--) {
264
+ if (rows[other]!.depth < row.depth) return -1;
265
+ if (rows[other]!.depth === row.depth) return other;
266
+ }
267
+ return -1;
268
+ })();
269
+ const changed = (next: MenuRow[]) => next.every((entry, position) => entry.id === rows[position]?.id && entry.depth === rows[position]?.depth) ? rows : next;
270
+ switch (move) {
271
+ case 'up': return previousSibling < 0 ? rows : changed(moveRows(rows, index, previousSibling, row.depth));
272
+ case 'down': {
273
+ const next = rows[end];
274
+ if (!next || next.depth !== row.depth) return rows;
275
+ // After the next sibling's subtree, counted in the rows without this subtree.
276
+ return changed(moveRows(rows, index, subtreeEnd(rows, end) - (end - index), row.depth));
277
+ }
278
+ case 'in': return previousSibling < 0 ? rows : changed(moveRows(rows, index, index, row.depth + 1));
279
+ case 'out': {
280
+ if (row.depth === 0) return rows;
281
+ let parent = index - 1;
282
+ while (parent >= 0 && rows[parent]!.depth >= row.depth) parent--;
283
+ const parentEnd = subtreeEnd(rows, parent);
284
+ return changed(moveRows(rows, index, parentEnd - (end - index), row.depth - 1));
285
+ }
286
+ }
287
+ }
package/src/module.ts ADDED
@@ -0,0 +1,32 @@
1
+ /** What a built-in module ships: resources, taxonomies, settings and its own hook handlers. Client-safe types. */
2
+ import type { HookRegistry } from '@cossackframework/core/hooks';
3
+ import type { BlockDeclaration } from './blocks';
4
+ import type { CollectionDefinition } from './collections';
5
+ import type { ResourceDeclaration } from './resource';
6
+ import type { SettingsGroup, SiteSettings } from './settings';
7
+ import type { TaxonomyDeclaration, TermShape } from './taxonomy';
8
+
9
+ /** Host services a module's `register` may use. */
10
+ export interface ModuleContext {
11
+ readonly hooks: HookRegistry;
12
+ readonly settings: { all(): Promise<SiteSettings> };
13
+ readonly taxonomies: { get(id: string): Promise<TermShape | null> };
14
+ /** A current collection by name, built in or defined in the dashboard. */
15
+ readonly collection: (name: string) => CollectionDefinition | undefined;
16
+ /** Every block type, by name. */
17
+ readonly blocks: () => ReadonlyMap<string, BlockDeclaration>;
18
+ readonly now: () => number;
19
+ }
20
+
21
+ /** A group of resources shipped together, such as the built-in content module. */
22
+ export interface CmsModule {
23
+ readonly owner: string;
24
+ readonly resources: readonly ResourceDeclaration[];
25
+ /** Built-in collections, stored as `cms/<name>`. */
26
+ readonly collections?: readonly CollectionDefinition[];
27
+ readonly taxonomies?: readonly TaxonomyDeclaration[];
28
+ readonly blocks?: readonly BlockDeclaration[];
29
+ readonly settings?: readonly SettingsGroup[];
30
+ /** Register the module's filters and actions. Runs once, before plugins. */
31
+ readonly register?: (context: ModuleContext) => void;
32
+ }
@@ -0,0 +1,64 @@
1
+ import { CORE_BLOCKS } from '../blocks';
2
+ import { FIELD_BLOCKS } from '../field-groups';
3
+ import { pages, patterns, posts } from '../collections';
4
+ import { CmsError } from '../errors';
5
+ import { beforeWrite } from '../hooks';
6
+ import type { CmsModule } from '../module';
7
+ import { crawlers, discussion, indexnow, languages, reading, seo, writing } from '../settings';
8
+ import type { TaxonomyDeclaration } from '../taxonomy';
9
+
10
+ export { CONTENT_STATUSES, pages, patterns, posts, type ContentStatus } from '../collections';
11
+
12
+ /** Hierarchical categories and flat tags for posts. */
13
+ export const categories: TaxonomyDeclaration = { name: 'categories', label: 'Categories', singular: 'Category', hierarchical: true, path: 'category', builtin: true };
14
+ export const tags: TaxonomyDeclaration = { name: 'tags', label: 'Tags', singular: 'Tag', hierarchical: false, path: 'tag', builtin: true };
15
+
16
+ /**
17
+ * The built-in content module: posts, pages and patterns, categories and tags, the core blocks,
18
+ * and Writing, Reading, Discussion, SEO and Languages settings. In every publishable collection,
19
+ * publishing without a time publishes now; publishing with a future time schedules the entry,
20
+ * and a scheduled entry whose time has come is published; an `unpublishAt` time takes it back
21
+ * to draft then (`runSchedule()`), and must be after the publication. New entries take the default
22
+ * language. A post saved without a category gets the Writing settings' default category.
23
+ */
24
+ export const contentModule: CmsModule = {
25
+ owner: 'cms',
26
+ resources: [],
27
+ collections: [posts, pages, patterns],
28
+ taxonomies: [categories, tags],
29
+ blocks: [...CORE_BLOCKS, ...FIELD_BLOCKS],
30
+ settings: [writing, reading, discussion, seo, crawlers, indexnow, languages],
31
+ register({ hooks, settings, taxonomies, collection, now }) {
32
+ hooks.addFilter(beforeWrite, async (draft, { input }) => {
33
+ if (!input.resource.startsWith('cms/')) return draft;
34
+ let next = draft;
35
+ const status = draft.status ?? input.previous?.status;
36
+ let publishedAt = 'publishedAt' in draft ? draft.publishedAt : input.previous?.publishedAt ?? null;
37
+ const at = now();
38
+ if ((status === 'published' || status === 'scheduled') && (publishedAt === null || publishedAt === undefined)) {
39
+ publishedAt = at;
40
+ next = { ...next, publishedAt: at };
41
+ }
42
+ if (status === 'published' && typeof publishedAt === 'number' && publishedAt > at) next = { ...next, status: 'scheduled' };
43
+ else if (status === 'scheduled' && typeof publishedAt === 'number' && publishedAt <= at) next = { ...next, status: 'published' };
44
+ // An unpublish time comes after the publication; a passed one is refused rather than acted on at once.
45
+ if ('unpublishAt' in draft && typeof draft.unpublishAt === 'number') {
46
+ if (typeof publishedAt === 'number' && draft.unpublishAt <= publishedAt) throw new CmsError('CMS_VALIDATION', 'The unpublish time must be after the publication time.', { fields: { unpublishAt: 'Choose a time after the publication.' } });
47
+ if (draft.unpublishAt <= at) throw new CmsError('CMS_VALIDATION', 'The unpublish time has passed.', { fields: { unpublishAt: 'Choose a time in the future.' } });
48
+ }
49
+ if (input.action === 'create' && (draft.locale === undefined || draft.locale === null)) {
50
+ const locale = (await settings.all())['languages.default'];
51
+ if (typeof locale === 'string' && locale) next = { ...next, locale };
52
+ }
53
+ if (input.action === 'create' && draft.commentsOpen === undefined && collection(input.resource.slice(4))?.comments) {
54
+ next = { ...next, commentsOpen: (await settings.all())['discussion.defaultOpen'] };
55
+ }
56
+ const assigned = 'categories' in draft ? draft.categories : input.action === 'create' ? [] : undefined;
57
+ if (input.resource === 'cms/posts' && Array.isArray(assigned) && assigned.length === 0) {
58
+ const fallback = (await settings.all())['writing.defaultCategory'];
59
+ if (fallback && (await taxonomies.get(fallback))?.taxonomy === 'categories') next = { ...next, categories: [fallback] };
60
+ }
61
+ return next;
62
+ }, { plugin: 'cms', priority: 5 });
63
+ },
64
+ };
@@ -0,0 +1,35 @@
1
+ import { CmsError } from '../errors';
2
+ import { FORM_BLOCKS, FORM_EMBED_BLOCK, forms, formInputs, formSettings, notificationProblems } from '../form-builder';
3
+ import { beforeWrite } from '../hooks';
4
+ import type { CmsModule } from '../module';
5
+ import type { Block } from '../blocks';
6
+
7
+ export { forms, FORM_BLOCKS } from '../form-builder';
8
+
9
+ /**
10
+ * The built-in forms module: the `forms` collection, its input blocks and `core/form`, which
11
+ * places a form in content. A form's settings and notifications are checked against its
12
+ * inputs when it is saved.
13
+ */
14
+ export const formsModule: CmsModule = {
15
+ owner: 'cms',
16
+ resources: [],
17
+ collections: [forms],
18
+ blocks: [...FORM_BLOCKS, FORM_EMBED_BLOCK],
19
+ register({ hooks, blocks }) {
20
+ hooks.addFilter(beforeWrite, (draft, { input }) => {
21
+ if (input.resource !== 'cms/forms') return draft;
22
+ const value = (name: string) => name in draft ? draft[name] : input.previous?.[name];
23
+ const inputs = formInputs((value('body') ?? []) as Block[], blocks());
24
+ const problems = notificationProblems(value('notifications'), inputs);
25
+ const settings = formSettings(value('settings'));
26
+ if (settings.confirmation === 'redirect' && !settings.redirectUrl) problems.push('Choose the page to go to after submitting.');
27
+ if (settings.oncePerEmail && inputs.find(entry => entry.name === settings.oncePerEmail)?.kind !== 'email') problems.push(`One submission per address needs an email field; ${settings.oncePerEmail} is not one.`);
28
+ if (settings.opensAt !== null && settings.closesAt !== null && settings.closesAt <= settings.opensAt) problems.push('The form must close after it opens.');
29
+ // Uploaded files are kept with their submission, so a form that keeps nothing cannot take them.
30
+ if (!settings.store && inputs.some(entry => entry.kind === 'file')) problems.push('A form with a file upload keeps its submissions: turn Keep submissions on.');
31
+ if (problems.length) throw new CmsError('CMS_VALIDATION', problems.join(' '));
32
+ return draft;
33
+ }, { plugin: 'cms', priority: 20 });
34
+ },
35
+ };