@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
@@ -0,0 +1,381 @@
1
+ /**
2
+ * The entry editor's model: plain, serializable views of a collection's fields, and the
3
+ * conversion from form values to typed record input. Client-safe; the server converts and
4
+ * validates again before writing.
5
+ */
6
+ import { fieldPlacement, slugify, validateValue, type BlockCategory, type BlockCondition, type BlockStyle, type Breakpoint, type FieldDeclaration, type FieldKind, type ChoiceSource, type StyleProperty, type ThemePresets } from '@cossackframework/cms';
7
+ import { conditionInput } from './condition-control';
8
+
9
+ /** One field as the editor shows it. */
10
+ export interface EditorField {
11
+ name: string;
12
+ label: string;
13
+ kind: FieldKind;
14
+ required: boolean;
15
+ nullable: boolean;
16
+ description: string;
17
+ /** One value for an entry and its translations (`translatable: false`). */
18
+ shared: boolean;
19
+ placement: 'main' | 'sidebar';
20
+ format: 'plain' | 'markdown' | 'code';
21
+ /** code: the code editor's language, unless the block names one. */
22
+ language: string;
23
+ /** enum values, with labels. */
24
+ choices: { value: string; label: string }[];
25
+ /** Several values of the kind, as a list; `minItems` and `maxItems` bound it and `addLabel` names the Add button. */
26
+ multiple: boolean;
27
+ minItems: number | null;
28
+ maxItems: number | null;
29
+ addLabel: string;
30
+ media: boolean;
31
+ /** string: one of the site icons, chosen with the icon picker. */
32
+ icon: boolean;
33
+ /** string: a profile URL whose network's icon the site shows. */
34
+ brand: boolean;
35
+ /** media: the kinds of file the chooser lists first; images when the field names none. */
36
+ kinds: string[];
37
+ /** string: where its choices come from (forms, collections, terms); empty for free text. */
38
+ choicesFrom: ChoiceSource | '';
39
+ /** reference: the target resource, with selectable entries. */
40
+ target: string;
41
+ /** blocks: the block types allowed, or all. */
42
+ blocks: string[];
43
+ /** blocks: the field holds a form, so input blocks are offered. */
44
+ form: boolean;
45
+ min: number | null;
46
+ max: number | null;
47
+ /** The declared default, if any. */
48
+ defaultValue: unknown;
49
+ /** A group's subfields, such as an entry's SEO settings; empty otherwise. */
50
+ fields: EditorField[];
51
+ }
52
+
53
+ export interface TermOption { id: string; name: string; depth: number }
54
+
55
+ export interface EditorTaxonomy {
56
+ name: string;
57
+ label: string;
58
+ singular: string;
59
+ hierarchical: boolean;
60
+ terms: TermOption[];
61
+ }
62
+
63
+ export interface BlockOption {
64
+ name: string;
65
+ label: string;
66
+ description: string;
67
+ /** Solar icon name; see `blockIcon`. */
68
+ icon: string;
69
+ category: BlockCategory;
70
+ fields: EditorField[];
71
+ /** The field that is the block's text, shown as its summary in the tree. */
72
+ body?: string;
73
+ /** A container: the types it holds (empty for any) and how many at most. Null for a leaf block. */
74
+ children: { allowed: string[]; max: number | null } | null;
75
+ /** Types this block goes inside alone, such as a column in columns. */
76
+ parent: string[];
77
+ /** The Style tab's properties, from the type's supports and category. */
78
+ supports: StyleProperty[];
79
+ /** A form input, offered only in a form's blocks. */
80
+ input: boolean;
81
+ /** A field block's kind, offered only in a field group; empty otherwise. */
82
+ field: string;
83
+ /** Other words the picker's search matches. */
84
+ keywords: string[];
85
+ /** Offered in forms and field groups too. */
86
+ common: boolean;
87
+ /** Preset shapes of the block the inserter offers as entries of their own; `newBlock` starts a block from one. */
88
+ variations: BlockVariationOption[];
89
+ }
90
+
91
+ export interface BlockVariationOption { name: string; label: string; description: string; icon: string; keywords: string[]; data: Record<string, unknown> }
92
+
93
+ /** A field group attached to the entry's collection, as the editor shows it: a box of its layout. */
94
+ export interface EditorGroup {
95
+ id: string;
96
+ title: string;
97
+ description: string;
98
+ placement: 'main' | 'sidebar';
99
+ blocks: EditorBlock[];
100
+ }
101
+
102
+ /** A block as editors hold it: its data as control values, nested blocks under a container. */
103
+ export interface EditorBlock {
104
+ _id: string;
105
+ type: string;
106
+ data: Record<string, unknown>;
107
+ layout?: { hide?: Breakpoint[]; anchor?: string; className?: string; nosnippet?: boolean };
108
+ style?: BlockStyle;
109
+ /** In a form: when the block shows. */
110
+ when?: BlockCondition;
111
+ children?: EditorBlock[];
112
+ }
113
+
114
+ /** A tab of the entry editor's main column: its label and icon, and the layout blocks it holds. */
115
+ export interface EditorLayoutTab {
116
+ id: string;
117
+ label: string;
118
+ icon: string;
119
+ blocks: EditorBlock[];
120
+ }
121
+
122
+ export interface EditorView {
123
+ /** Resource ID, such as `cms/posts`. */
124
+ resource: string;
125
+ /** The route segment: `posts`, or `<owner>.<name>` for plugin resources. */
126
+ route: string;
127
+ label: string;
128
+ singular: string;
129
+ titleField: string;
130
+ /** Saving needs a title that is not blank. */
131
+ titleRequired: boolean;
132
+ slug: boolean;
133
+ publishable: boolean;
134
+ hierarchical: boolean;
135
+ /** Public URL base, or null when entries are not on the site. */
136
+ path: string | null;
137
+ /** The fields to edit; for a principal, without those they may not read or change (`access` on the field). */
138
+ fields: EditorField[];
139
+ /**
140
+ * Fields with an `access` rule of their own. The shared editing room leaves them out: each
141
+ * editor reads and saves them as the repository lets them, never through the room.
142
+ */
143
+ restricted: string[];
144
+ taxonomies: EditorTaxonomy[];
145
+ blocks: BlockOption[];
146
+ /** The active theme's presets, for the blocks' Style tab. */
147
+ presets: Required<ThemePresets>;
148
+ /** The blocks a new entry's content starts with, and how far they may change. */
149
+ template: EditorBlock[];
150
+ templateLock?: 'all' | 'insert';
151
+ /** Field groups attached to the collection, in order. */
152
+ groups: EditorGroup[];
153
+ /** The editor's arrangement: the main column's tabs (the first is the Edit tab) and the sidebar every tab shares; see `resolveEditorLayout`. */
154
+ layout: { tabs: EditorLayoutTab[]; sidebar: EditorBlock[] };
155
+ /** Every collection, for a pattern's starting layouts. */
156
+ collections: { name: string; label: string }[];
157
+ /** The site's forms, collections and terms, for fields that choose one (`choicesFrom`). */
158
+ sources: SourceChoices;
159
+ }
160
+
161
+ /** A choice of a field with `choicesFrom`: the stored value and what the list shows. */
162
+ export interface SourceChoice { value: string; label: string }
163
+ export type SourceChoices = Record<ChoiceSource, SourceChoice[]>;
164
+
165
+ /** Values the form controls hold: strings, booleans and lists. */
166
+ export type EditorValues = Record<string, unknown>;
167
+
168
+ /** Editor fields of a declaration, leaving out the ones the editor lays out itself. */
169
+ export function editorFields(fields: { readonly [name: string]: FieldDeclaration }, special: readonly string[]): EditorField[] {
170
+ return Object.entries(fields).filter(([name]) => !special.includes(name)).map(([name, declaration]) => editorField(name, declaration));
171
+ }
172
+
173
+ export function editorField(name: string, declaration: FieldDeclaration & { choices?: { readonly [value: string]: string } }): EditorField {
174
+ return {
175
+ name, label: declaration.label ?? name, kind: declaration.kind, required: declaration.required === true, nullable: declaration.nullable === true,
176
+ description: declaration.description ?? '', shared: declaration.translatable === false, placement: fieldPlacement(declaration),
177
+ format: declaration.format ?? 'plain', language: declaration.language ?? '',
178
+ choices: (declaration.values ?? []).map(value => ({ value, label: declaration.choices?.[value] ?? value })),
179
+ multiple: declaration.multiple === true, minItems: declaration.minItems ?? null, maxItems: declaration.maxItems ?? null, addLabel: declaration.addLabel ?? '',
180
+ media: declaration.media === true, icon: declaration.icon === true, brand: declaration.brand === true, kinds: [...(declaration.kinds ?? [])], choicesFrom: declaration.choicesFrom ?? '', target: declaration.target ?? '', blocks: [...(declaration.blocks ?? [])], form: declaration.form === true,
181
+ min: declaration.min ?? null, max: declaration.max ?? null, defaultValue: declaration.default ?? null,
182
+ fields: Object.entries(declaration.fields ?? {}).map(([sub, nested]) => editorField(sub, nested)),
183
+ };
184
+ }
185
+
186
+ /** The value a control shows for a stored value. */
187
+ export function controlValue(field: EditorField, value: unknown): unknown {
188
+ // A multiple field edits as a list of its kind's control values.
189
+ if (field.multiple) return (Array.isArray(value) ? value : []).map(item => controlValue({ ...field, multiple: false }, item));
190
+ // Rows edit as a list of objects of their fields' control values, each with its id.
191
+ if (field.kind === 'rows') {
192
+ return (Array.isArray(value) ? value : []).map(row => {
193
+ const object = row && typeof row === 'object' ? row as Record<string, unknown> : {};
194
+ return { _id: typeof object._id === 'string' ? object._id : '', ...Object.fromEntries(field.fields.map(sub => [sub.name, controlValue(sub, object[sub.name])])) };
195
+ });
196
+ }
197
+ // A group edits as an object of its subfields' control values.
198
+ if (field.fields.length) {
199
+ const object = value && typeof value === 'object' ? value as Record<string, unknown> : {};
200
+ return Object.fromEntries(field.fields.map(sub => [sub.name, controlValue(sub, object[sub.name])]));
201
+ }
202
+ if (value === null || value === undefined) {
203
+ if (field.kind === 'boolean') return false;
204
+ if (field.kind === 'blocks') return [];
205
+ if (field.kind === 'richtext') return null;
206
+ return '';
207
+ }
208
+ switch (field.kind) {
209
+ case 'datetime': return new Date(value as number).toISOString().slice(0, 16);
210
+ case 'json': return JSON.stringify(value, null, 2);
211
+ case 'integer': case 'number': return String(value);
212
+ case 'blocks': case 'richtext': return value;
213
+ default: return value;
214
+ }
215
+ }
216
+
217
+ /** A declaration to validate a converted value against. */
218
+ function declarationOf(field: EditorField): FieldDeclaration {
219
+ return {
220
+ kind: field.kind, required: field.required, nullable: field.nullable,
221
+ ...(field.min !== null ? { min: field.min } : {}), ...(field.max !== null ? { max: field.max } : {}),
222
+ ...(field.choices.length ? { values: field.choices.map(choice => choice.value) } : {}),
223
+ ...(field.multiple ? { multiple: true, ...(field.minItems !== null ? { minItems: field.minItems } : {}), ...(field.maxItems !== null ? { maxItems: field.maxItems } : {}) } : {}),
224
+ ...(field.fields.length ? { fields: Object.fromEntries(field.fields.map(sub => [sub.name, declarationOf(sub)])) } : {}),
225
+ };
226
+ }
227
+
228
+ /**
229
+ * Typed input from control values. Empty optional controls clear nullable fields and keep the
230
+ * others unchanged; unreadable text is reported per field.
231
+ */
232
+ export function editorInput(fields: readonly EditorField[], values: EditorValues, blocks: readonly BlockOption[] = []): { input: Record<string, unknown>; errors: Record<string, string> } {
233
+ const input: Record<string, unknown> = {};
234
+ const errors: Record<string, string> = {};
235
+ for (const field of fields) {
236
+ if (!(field.name in values)) continue;
237
+ const converted = convert(field, values[field.name], blocks);
238
+ if ('error' in converted) errors[field.name] = converted.error;
239
+ else if (converted.value !== undefined) input[field.name] = converted.value;
240
+ }
241
+ return { input, errors };
242
+ }
243
+
244
+ function convert(field: EditorField, raw: unknown, blocks: readonly BlockOption[]): { value: unknown } | { error: string } {
245
+ // A multiple field's items convert as the kind does; blank ones are left out, and the server checks the count.
246
+ if (field.multiple) {
247
+ const items: unknown[] = [];
248
+ for (const [index, entry] of (Array.isArray(raw) ? raw : []).entries()) {
249
+ const converted = convert({ ...field, multiple: false, nullable: true }, entry, blocks);
250
+ if ('error' in converted) return { error: `${__('item')} ${index + 1} ${converted.error}` };
251
+ if (converted.value !== undefined && converted.value !== null && converted.value !== '') items.push(converted.value);
252
+ }
253
+ return { value: items };
254
+ }
255
+ if (field.kind === 'rows') {
256
+ // Each row keeps its id and the fields that were set; the server checks what is required.
257
+ const rows: Record<string, unknown>[] = [];
258
+ for (const [index, row] of (Array.isArray(raw) ? raw : []).entries()) {
259
+ const source = row && typeof row === 'object' ? row as Record<string, unknown> : {};
260
+ const converted: Record<string, unknown> = typeof source._id === 'string' && source._id ? { _id: source._id } : {};
261
+ for (const sub of field.fields) {
262
+ const value = convert(sub, source[sub.name], blocks);
263
+ if ('error' in value) return { error: `${__('row')} ${index + 1}: ${sub.label} ${value.error}` };
264
+ if (value.value !== undefined && value.value !== null && value.value !== '' && value.value !== false) converted[sub.name] = value.value;
265
+ }
266
+ rows.push(converted);
267
+ }
268
+ return { value: rows };
269
+ }
270
+ if (field.fields.length) {
271
+ // Empty subfields and unchecked boxes are left out, so the group holds only what was set.
272
+ const source = raw && typeof raw === 'object' ? raw as Record<string, unknown> : {};
273
+ const group: Record<string, unknown> = {};
274
+ for (const sub of field.fields) {
275
+ const converted = convert(sub, source[sub.name], blocks);
276
+ if ('error' in converted) return { error: `${sub.label} ${converted.error}` };
277
+ if (converted.value !== undefined && converted.value !== null && converted.value !== '' && converted.value !== false) group[sub.name] = converted.value;
278
+ }
279
+ return { value: Object.keys(group).length ? group : field.nullable ? null : {} };
280
+ }
281
+ if (field.kind === 'boolean') return { value: raw === true || raw === 'true' || raw === 'on' };
282
+ // The editor's JSON document; the server validates it.
283
+ if (field.kind === 'richtext') return { value: raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : field.nullable ? null : undefined };
284
+ if (field.kind === 'blocks') {
285
+ if (!Array.isArray(raw)) return { value: [] };
286
+ const converted = blocksInput(raw as EditorBlock[], new Map(blocks.map(block => [block.name, block])));
287
+ return 'error' in converted ? converted : { value: converted.value };
288
+ }
289
+ const text = typeof raw === 'string' ? (field.kind === 'text' || field.kind === 'json' ? raw : raw.trim()) : raw === undefined || raw === null ? '' : String(raw);
290
+ if (text === '') {
291
+ if (field.nullable) return { value: null };
292
+ // An empty optional string is a value when the field accepts it; otherwise nothing changes.
293
+ if ((field.kind === 'string' || field.kind === 'text') && validateValue(field.name, declarationOf(field), '') === undefined) return { value: '' };
294
+ return { value: undefined };
295
+ }
296
+ switch (field.kind) {
297
+ case 'integer': { const value = Number(text); return Number.isSafeInteger(value) ? { value } : { error: 'must be a whole number.' }; }
298
+ case 'number': { const value = Number(text); return Number.isFinite(value) ? { value } : { error: 'must be a number.' }; }
299
+ case 'datetime': {
300
+ const value = Date.parse(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?$/.test(text) ? `${text}Z` : text);
301
+ return Number.isNaN(value) ? { error: 'must be a date and time.' } : { value };
302
+ }
303
+ case 'json': try { return { value: JSON.parse(text) }; } catch { return { error: 'must be valid JSON.' }; }
304
+ default: return { value: text };
305
+ }
306
+ }
307
+
308
+ /** Typed blocks from editor blocks, through the tree; a block's `layout` and `children` come along. */
309
+ export function blocksInput(raw: readonly EditorBlock[], types: ReadonlyMap<string, BlockOption>): { value: EditorBlock[] } | { error: string } {
310
+ const converted: EditorBlock[] = [];
311
+ for (const block of raw) {
312
+ const data: Record<string, unknown> = {};
313
+ for (const entry of types.get(block.type)?.fields ?? []) {
314
+ const value = convert(entry, block.data?.[entry.name], []);
315
+ if ('error' in value) return { error: `${entry.label} ${value.error}` };
316
+ if (value.value !== undefined && value.value !== null && value.value !== '') data[entry.name] = value.value;
317
+ }
318
+ const layout = blockLayoutInput(block.layout);
319
+ // Slugs, colors and media IDs are strings; the advanced background also has flags and an opacity. An empty value or an off flag is no value.
320
+ const style = Object.fromEntries(Object.entries(block.style ?? {}).filter(([, value]) => value !== undefined && value !== null && value !== '' && value !== false)) as BlockStyle;
321
+ const children = Array.isArray(block.children) ? blocksInput(block.children, types) : undefined;
322
+ if (children && 'error' in children) return children;
323
+ const when = conditionInput(block.when);
324
+ converted.push({ _id: block._id, type: block.type, data, ...(layout ? { layout } : {}), ...(Object.keys(style).length ? { style } : {}), ...(when ? { when } : {}), ...(children ? { children: children.value } : {}) });
325
+ }
326
+ return { value: converted };
327
+ }
328
+
329
+ /** A block's layout without empty entries; undefined when it has none. */
330
+ function blockLayoutInput(layout: EditorBlock['layout']): EditorBlock['layout'] | undefined {
331
+ const hide = layout?.hide?.filter(Boolean) ?? [];
332
+ const anchor = layout?.anchor?.trim() ?? '';
333
+ const className = layout?.className?.trim() ?? '';
334
+ const result = { ...(hide.length ? { hide } : {}), ...(anchor ? { anchor } : {}), ...(className ? { className } : {}) };
335
+ return Object.keys(result).length ? result : undefined;
336
+ }
337
+
338
+ /** The slug an untouched slug field follows. */
339
+ export function suggestedSlug(title: string): string {
340
+ return slugify(title) || '';
341
+ }
342
+
343
+ /** The public URL of an entry, from the collection path and the slugs of its ancestors. */
344
+ export { entryUrl } from '@cossackframework/cms';
345
+
346
+ /** A new block's data: each field's default, or empty. */
347
+ export function blockDefaults(block: BlockOption): Record<string, unknown> {
348
+ return Object.fromEntries(block.fields.map(field => [field.name, controlValue(field, field.defaultValue)]));
349
+ }
350
+
351
+ /** A new block of a type: defaults, and for columns two columns to start with. */
352
+ export function newBlock(type: string, options: readonly BlockOption[], id: () => string, variation?: string): EditorBlock | null {
353
+ const option = options.find(entry => entry.name === type);
354
+ if (!option) return null;
355
+ // A variation starts the block with its values over the defaults.
356
+ const preset = variation ? option.variations.find(entry => entry.name === variation)?.data ?? {} : {};
357
+ const block: EditorBlock = { _id: id(), type, data: { ...blockDefaults(option), ...preset }, ...(option.children ? { children: [] } : {}) };
358
+ if (type === 'core/columns') block.children = [1, 2].flatMap(() => newBlock('core/column', options, id) ?? []);
359
+ // Containers of named items start with a few, named, so the block shows something at once.
360
+ const seed = (child: string, labels: readonly string[], field: string) => labels.flatMap(label => { const item = newBlock(child, options, id); return item ? [{ ...item, data: { ...item.data, [field]: label } }] : []; });
361
+ if (type === 'core/tabs') block.children = seed('core/tab', ['Tab 1', 'Tab 2'], 'label');
362
+ if (type === 'core/accordion') block.children = seed('core/accordion-item', ['Section 1', 'Section 2'], 'label');
363
+ if (type === 'core/icon-list') block.children = seed('core/icon-item', ['First point', 'Second point', 'Third point'], 'text');
364
+ return block;
365
+ }
366
+
367
+ /** Stored block data as control values, through the tree, so the editor's controls can show them. */
368
+ /** The name of the collection's content: the `content` feature, or a plugin resource's first blocks field, which the template and patterns fill. */
369
+ export function contentField(view: Pick<EditorView, 'fields'>): string | null {
370
+ return view.fields.find(field => field.kind === 'blocks' && !field.form)?.name ?? null;
371
+ }
372
+
373
+ export function editorBlocks(blocks: readonly EditorBlock[], options: readonly BlockOption[]): EditorBlock[] {
374
+ return blocks.map(block => {
375
+ const option = options.find(entry => entry.name === block.type);
376
+ return {
377
+ ...block, data: option ? Object.fromEntries(option.fields.map(field => [field.name, controlValue(field, block.data[field.name])])) : { ...block.data },
378
+ ...(block.children ? { children: editorBlocks(block.children, options) } : {}),
379
+ };
380
+ });
381
+ }
@@ -0,0 +1,26 @@
1
+ import type { Context } from 'hono';
2
+ import { networkFor } from './index';
3
+ import { runNetworkMaintenance } from './maintenance';
4
+ import { pluginRouteActive } from './middleware';
5
+
6
+ /**
7
+ * The CMS's options for `createApp` in a project's `src/index.ts`: a rendered plugin's pages
8
+ * and handlers answer only while the plugin is active in the CMS.
9
+ */
10
+ export const cmsAppOptions: { isPluginActive(plugin: string, c: Context): Promise<boolean> } = { isPluginActive: pluginRouteActive };
11
+
12
+ /**
13
+ * The Worker's `scheduled` handler: recover unconfirmed writes, deliver outbox events and keep
14
+ * the Cloud database warm, on each site in turn.
15
+ */
16
+ export function cmsScheduled(env: unknown, ctx: { waitUntil(work: Promise<unknown>): void }): void {
17
+ ctx.waitUntil(runNetworkMaintenance(networkFor(env as never), { warm: true }));
18
+ }
19
+
20
+ /** The Node server's background work: the same maintenance, every minute in the server process. */
21
+ export function startCmsMaintenance(env: unknown): void {
22
+ const maintenance = setInterval(() => {
23
+ runNetworkMaintenance(networkFor(env as never)).catch(error => console.error('[cms] maintenance failed', error));
24
+ }, 60_000);
25
+ maintenance.unref();
26
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Syndication feeds: RSS 2.0, Atom and JSON Feed of a collection's published entries, the whole
3
+ * collection or one term's, sized and filled by Settings → Reading. Audio blocks become
4
+ * enclosures (RSS) and attachments (JSON Feed), so a feed of a podcast collection plays.
5
+ */
6
+ import { ANONYMOUS, blocksPlain, entryUrl, isCmsError, recordTitle, richTextExcerpt, richTextHtml, richTextPlain, type Block, type CollectionDefinition, type RichTextDoc } from '@cossackframework/cms';
7
+ import { renderMarkdown, excerptOf, type CmsHost, type CmsFile } from '@cossackframework/cms/server';
8
+ import { blocksHtml } from './content';
9
+ import { isMembersOnly, isProtected } from './site';
10
+ import { cacheHeaders } from './cache';
11
+
12
+ export type FeedFormat = 'rss' | 'atom' | 'json';
13
+
14
+ export interface FeedItem {
15
+ readonly id: string;
16
+ readonly title: string;
17
+ readonly link: string;
18
+ readonly publishedAt: number;
19
+ readonly updatedAt: number;
20
+ readonly summary: string;
21
+ readonly html: string;
22
+ readonly authors: readonly string[];
23
+ readonly enclosure: { readonly url: string; readonly type: string; readonly size: number } | null;
24
+ }
25
+
26
+ export interface Feed {
27
+ readonly title: string;
28
+ readonly description: string;
29
+ readonly home: string;
30
+ readonly self: string;
31
+ readonly items: readonly FeedItem[];
32
+ }
33
+
34
+ const escape = (text: string) => text.replace(/[<>&'"]/g, character => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;', "'": '&apos;', '"': '&quot;' })[character]!);
35
+ const cdata = (text: string) => `<![CDATA[${text.replaceAll(']]>', ']]]]><![CDATA[>')}]]>`;
36
+
37
+ /** Which collection and term a feed path names, or null when the path names nothing: `/feed`, `/feed/atom`, `/feed/<collection>`, `/feed/<collection>/json`. */
38
+ export function feedTarget(cms: CmsHost, segments: readonly string[]): { collection: CollectionDefinition; format: FeedFormat } | null {
39
+ const rest = [...segments];
40
+ let format: FeedFormat = 'rss';
41
+ if (rest.length && ['rss', 'atom', 'json'].includes(rest[rest.length - 1]!)) format = rest.pop() as FeedFormat;
42
+ if (rest.length > 1) return null;
43
+ const name = rest[0] ?? 'posts';
44
+ const collection = cms.collections().find(entry => entry.name === name && entry.publishable !== false && !entry.managed && typeof entry.path === 'string');
45
+ return collection ? { collection, format } : null;
46
+ }
47
+
48
+ /** The feed's entries: the newest published of the collection, of one term when `term` names a slug of one of its taxonomies. */
49
+ export async function buildFeed(cms: CmsHost, options: { collection: CollectionDefinition; origin: string; self: string; term?: string | null }): Promise<Feed> {
50
+ const { collection, origin } = options;
51
+ const settings = await cms.settings.all();
52
+ const resource = cms.resource(`cms/${collection.name}`);
53
+ const where: { [field: string]: unknown } = { status: 'published' };
54
+ let title = settings['general.siteTitle'];
55
+ let description = settings['general.tagline'];
56
+ if (collection.name !== 'posts') { title = `${title} · ${collection.label}`; description = collection.description || description; }
57
+ if (options.term) {
58
+ let matched = false;
59
+ for (const name of collection.taxonomies ?? []) {
60
+ const term = await cms.taxonomies.bySlug(name, options.term).catch(() => null);
61
+ if (!term) continue;
62
+ where[name] = { containsAny: (await cms.taxonomies.subtree(term.id)).slice(0, 50) };
63
+ title = `${title} · ${term.name}`;
64
+ matched = true;
65
+ break;
66
+ }
67
+ if (!matched) return { title, description, home: `${origin}/`, self: options.self, items: [] };
68
+ }
69
+ const page = await resource.list({ where: where as never, order: { field: 'publishedAt', direction: 'desc' }, limit: settings['reading.feedItems'] }, { principal: ANONYMOUS });
70
+ // Feed readers send no password cookie or session: protected and members-only entries stay out.
71
+ const records = page.records.filter(record => !isProtected(record) && !isMembersOnly(record));
72
+ const blocksOf = (record: Record<string, unknown>) => Array.isArray(record.content) ? record.content as Block[] : [];
73
+ const mediaIds = new Set<string>();
74
+ for (const record of records) for (const block of flat(blocksOf(record))) {
75
+ for (const value of Object.values(block.data)) if (typeof value === 'string' && value) mediaIds.add(value);
76
+ }
77
+ const files: Map<string, CmsFile> = cms.files ? await cms.files.getMany([...mediaIds]) : new Map();
78
+ const authors = await cms.users.getMany([...new Set(records.flatMap(record => Array.isArray(record.authors) ? record.authors as string[] : []))]);
79
+ const items = records.map((record): FeedItem => {
80
+ const blocks = blocksOf(record);
81
+ const doc = !blocks.length && record.body && typeof record.body === 'object' ? record.body as RichTextDoc : null;
82
+ const markdown = typeof record.body === 'string' ? record.body : '';
83
+ const full = blocks.length ? blocksHtml(cms, blocks, files) : doc ? richTextHtml(doc, { block: () => '' }) : renderMarkdown(markdown);
84
+ const summary = String(record.excerpt || record.summary || (blocks.length ? excerptOf(blocksPlain(blocks, cms.blockTypes, entry => richTextPlain(entry), 4000), 55) : doc ? richTextExcerpt(doc) : excerptOf(markdown, 55)));
85
+ const audio = flat(blocks).find(block => block.type === 'core/audio');
86
+ const file = audio && typeof audio.data.audio === 'string' ? files.get(audio.data.audio) : undefined;
87
+ return {
88
+ id: record.id, title: recordTitle(record, 'title'), link: `${origin}${entryUrl(collection.path ?? collection.name, [String(record.slug)])}`,
89
+ publishedAt: Number(record.publishedAt), updatedAt: Number(record.updatedAt ?? record.publishedAt), summary, html: settings['reading.feedContent'] === 'full' ? full : '',
90
+ authors: (Array.isArray(record.authors) ? record.authors as string[] : []).map(id => authors.get(id)?.name ?? '').filter(Boolean),
91
+ enclosure: file ? { url: `${origin}/media/${file.id}/${encodeURIComponent(file.name)}`, type: file.contentType, size: file.size } : null,
92
+ };
93
+ });
94
+ return { title, description, home: `${origin}/`, self: options.self, items };
95
+ }
96
+
97
+ function flat(blocks: readonly Block[]): Block[] {
98
+ return blocks.flatMap(block => [block, ...flat(block.children ?? [])]);
99
+ }
100
+
101
+ /** The feed as text with its content type. */
102
+ export function renderFeed(feed: Feed, format: FeedFormat): { body: string; contentType: string } {
103
+ if (format === 'json') {
104
+ return { contentType: 'application/feed+json; charset=utf-8', body: JSON.stringify({
105
+ version: 'https://jsonfeed.org/version/1.1', title: feed.title, description: feed.description, home_page_url: feed.home, feed_url: feed.self,
106
+ items: feed.items.map(item => ({
107
+ id: item.link, url: item.link, title: item.title, date_published: new Date(item.publishedAt).toISOString(), date_modified: new Date(item.updatedAt).toISOString(),
108
+ summary: item.summary, ...(item.html ? { content_html: item.html } : { content_text: item.summary }),
109
+ ...(item.authors.length ? { authors: item.authors.map(name => ({ name })) } : {}),
110
+ ...(item.enclosure ? { attachments: [{ url: item.enclosure.url, mime_type: item.enclosure.type, size_in_bytes: item.enclosure.size }] } : {}),
111
+ })),
112
+ }, null, 1) };
113
+ }
114
+ if (format === 'atom') {
115
+ const updated = feed.items.length ? Math.max(...feed.items.map(item => item.updatedAt)) : Date.now();
116
+ const entries = feed.items.map(item => `<entry><title>${escape(item.title)}</title><link href="${escape(item.link)}"/><id>${escape(item.link)}</id>`
117
+ + `<published>${new Date(item.publishedAt).toISOString()}</published><updated>${new Date(item.updatedAt).toISOString()}</updated>`
118
+ + item.authors.map(name => `<author><name>${escape(name)}</name></author>`).join('')
119
+ + `<summary>${escape(item.summary)}</summary>${item.html ? `<content type="html">${escape(item.html)}</content>` : ''}`
120
+ + (item.enclosure ? `<link rel="enclosure" href="${escape(item.enclosure.url)}" type="${escape(item.enclosure.type)}" length="${item.enclosure.size}"/>` : '') + '</entry>').join('');
121
+ return { contentType: 'application/atom+xml; charset=utf-8', body: `<?xml version="1.0" encoding="UTF-8"?>\n<feed xmlns="http://www.w3.org/2005/Atom"><title>${escape(feed.title)}</title><subtitle>${escape(feed.description)}</subtitle>`
122
+ + `<link href="${escape(feed.home)}"/><link rel="self" href="${escape(feed.self)}"/><id>${escape(feed.self)}</id><updated>${new Date(updated).toISOString()}</updated>${entries}</feed>\n` };
123
+ }
124
+ const items = feed.items.map(item => `<item><title>${escape(item.title)}</title><link>${escape(item.link)}</link><guid isPermaLink="true">${escape(item.link)}</guid>`
125
+ + `<pubDate>${new Date(item.publishedAt).toUTCString()}</pubDate><description>${item.html ? cdata(item.html) : escape(item.summary)}</description>`
126
+ + item.authors.map(name => `<dc:creator>${escape(name)}</dc:creator>`).join('')
127
+ + (item.enclosure ? `<enclosure url="${escape(item.enclosure.url)}" type="${escape(item.enclosure.type)}" length="${item.enclosure.size}"/>` : '') + '</item>').join('');
128
+ return { contentType: 'application/rss+xml; charset=utf-8', body: `<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>${escape(feed.title)}</title><link>${escape(feed.home)}</link>`
129
+ + `<atom:link href="${escape(feed.self)}" rel="self" type="application/rss+xml"/><description>${escape(feed.description)}</description>${items}</channel></rss>\n` };
130
+ }
131
+
132
+ /** Answer a feed request, or 404 for a path that names no collection. */
133
+ export async function feedResponse(cms: CmsHost, request: Request, segments: readonly string[]): Promise<Response> {
134
+ const target = feedTarget(cms, segments);
135
+ if (!target) return new Response('Not found', { status: 404 });
136
+ const url = new URL(request.url);
137
+ try {
138
+ const feed = await buildFeed(cms, { collection: target.collection, origin: url.origin, self: url.origin + url.pathname + url.search, term: url.searchParams.get('term') });
139
+ const { body, contentType } = renderFeed(feed, target.format);
140
+ return new Response(body, { headers: { 'content-type': contentType, ...await cacheHeaders(cms, [cms.purge.tag.collection(target.collection.name)]) } });
141
+ } catch (error) {
142
+ if (!isCmsError(error, 'CMS_UNAVAILABLE')) throw error;
143
+ return new Response('Not available yet', { status: 503 });
144
+ }
145
+ }