@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,179 @@
1
+ /**
2
+ * Entries as Markdown, for agents and assistants that ask for `text/markdown`: rich text and
3
+ * the core blocks become headings, paragraphs, lists, quotes, code and images. Client-safe.
4
+ */
5
+ import { blockIsData, flattenBlocks, type Block, type BlockDeclaration } from './blocks';
6
+ import { richTextBlocks, safeImageUrl, safeLinkUrl, type RichTextDoc, type RichTextNode } from './richtext';
7
+
8
+ const escapeText = (text: string) => text.replace(/([\\`*_{}[\]<>])/g, '\\$1');
9
+
10
+ /** What the conversion reads besides the document: file URLs by media ID, and a rewrite of each text run (bindings). */
11
+ interface MarkdownContext {
12
+ readonly media: (id: string) => string | null;
13
+ readonly text: (text: string) => string;
14
+ }
15
+
16
+ function inlineMarkdown(nodes: readonly RichTextNode[] = [], context: MarkdownContext): string {
17
+ return nodes.map(node => {
18
+ if (node.type === 'hardBreak') return ' \n';
19
+ if (node.type !== 'text') return '';
20
+ let text = node.text ?? '';
21
+ const marks = node.marks ?? [];
22
+ if (marks.some(mark => mark.type === 'code')) return `\`${text.replace(/`/g, '\\`')}\``;
23
+ text = escapeText(context.text(text));
24
+ if (marks.some(mark => mark.type === 'bold')) text = `**${text}**`;
25
+ if (marks.some(mark => mark.type === 'italic')) text = `*${text}*`;
26
+ if (marks.some(mark => mark.type === 'strike')) text = `~~${text}~~`;
27
+ const link = marks.find(mark => mark.type === 'link');
28
+ if (link && safeLinkUrl(link.attrs?.href)) text = `[${text}](${String(link.attrs!.href)})`;
29
+ return text;
30
+ }).join('');
31
+ }
32
+
33
+ function listMarkdown(node: RichTextNode, ordered: boolean, depth: number, context: MarkdownContext): string {
34
+ const start = ordered && Number.isSafeInteger(node.attrs?.start) ? node.attrs!.start as number : 1;
35
+ return (node.content ?? []).map((item, index) => {
36
+ const marker = ordered ? `${start + index}. ` : '- ';
37
+ const body = (item.content ?? []).map(child => nodeMarkdown(child, depth + 1, context)).filter(Boolean);
38
+ const [first = '', ...rest] = body;
39
+ const indent = ' '.repeat(marker.length);
40
+ return `${' '.repeat(depth)}${marker}${first.replace(/\n/g, `\n${indent}`)}${rest.map(part => `\n\n${part.split('\n').map(line => `${indent}${line}`).join('\n')}`).join('')}`;
41
+ }).join('\n');
42
+ }
43
+
44
+ function nodeMarkdown(node: RichTextNode, depth: number, context: MarkdownContext): string {
45
+ switch (node.type) {
46
+ case 'paragraph': return inlineMarkdown(node.content, context);
47
+ case 'heading': {
48
+ const level = Number.isInteger(node.attrs?.level) ? Math.min(Math.max(node.attrs!.level as number, 1), 6) : 2;
49
+ return `${'#'.repeat(level)} ${inlineMarkdown(node.content, context)}`;
50
+ }
51
+ case 'blockquote': return (node.content ?? []).map(child => nodeMarkdown(child, depth, context)).filter(Boolean).join('\n\n').split('\n').map(line => `> ${line}`).join('\n');
52
+ case 'bulletList': return listMarkdown(node, false, depth, context);
53
+ case 'orderedList': return listMarkdown(node, true, depth, context);
54
+ case 'codeBlock': {
55
+ const language = typeof node.attrs?.language === 'string' ? node.attrs.language.replace(/[^a-z0-9+#-]/gi, '') : '';
56
+ return `\`\`\`${language}\n${(node.content ?? []).map(child => child.text ?? '').join('')}\n\`\`\``;
57
+ }
58
+ case 'horizontalRule': return '---';
59
+ case 'table': return tableMarkdown(node, depth, context);
60
+ case 'image': {
61
+ const mediaId = typeof node.attrs?.mediaId === 'string' ? node.attrs.mediaId : null;
62
+ const src = (mediaId ? context.media(mediaId) : null) ?? node.attrs?.src;
63
+ if (!safeImageUrl(src)) return '';
64
+ return `![${escapeText(typeof node.attrs?.alt === 'string' ? node.attrs.alt : '')}](${String(src)})`;
65
+ }
66
+ default: return '';
67
+ }
68
+ }
69
+
70
+ /** What the Markdown conversions take: file URLs by media ID, and `text`, which rewrites text before it is written, such as resolving bindings. Code keeps its text. */
71
+ export interface MarkdownOptions {
72
+ readonly media?: (id: string) => string | null;
73
+ readonly text?: (text: string) => string;
74
+ }
75
+
76
+ /** A rich text document as Markdown; embedded blocks render through `block`. */
77
+ export function richTextMarkdown(doc: RichTextDoc | null | undefined, options: MarkdownOptions & { block?: (block: Block) => string } = {}): string {
78
+ if (!doc || !Array.isArray(doc.content)) return '';
79
+ const context: MarkdownContext = { media: options.media ?? (() => null), text: options.text ?? (text => text) };
80
+ return doc.content.map(node => node.type === 'cmsBlock' ? options.block?.(richTextBlocks({ type: 'doc', content: [node] })[0]!) ?? '' : nodeMarkdown(node, 0, context)).filter(Boolean).join('\n\n');
81
+ }
82
+
83
+ /**
84
+ * Blocks as Markdown: the core text and media blocks by shape, other blocks by their text
85
+ * fields (as `blocksPlain` reads them). Data blocks and forms render nothing.
86
+ */
87
+ export function blocksMarkdown(blocks: readonly Block[], types: ReadonlyMap<string, BlockDeclaration>, options: MarkdownOptions & { mediaAlt?: (id: string) => string } = {}): string {
88
+ const media = options.media ?? (() => null);
89
+ const alt = options.mediaAlt ?? (() => '');
90
+ const resolve = options.text ?? (text => text);
91
+ const rich = { media, ...(options.text ? { text: options.text } : {}) };
92
+ const parts: string[] = [];
93
+ const render = (block: Block): string => {
94
+ const type = types.get(block.type);
95
+ if (!type || blockIsData(type) || type.input) return '';
96
+ const data = block.data;
97
+ // Text fields resolve as on the page; code and media IDs stay as written.
98
+ const raw = (name: string) => typeof data[name] === 'string' ? data[name] as string : '';
99
+ const text = (name: string) => resolve(raw(name));
100
+ switch (block.type) {
101
+ case 'core/richtext': return data.text && typeof data.text === 'object' ? richTextMarkdown(data.text as RichTextDoc, { ...rich, block: render }) : '';
102
+ case 'core/paragraph': return text('text');
103
+ case 'core/heading': return `${'#'.repeat(Number(String(data.level ?? 'h2').slice(1)) || 2)} ${text('text')}`;
104
+ case 'core/quote': return `${text('text').split('\n').map(line => `> ${line}`).join('\n')}${text('citation') ? `\n>\n> — ${text('citation')}` : ''}`;
105
+ case 'core/list': return (Array.isArray(data.items) ? data.items as string[] : []).map((item, index) => `${data.ordered ? `${index + 1}. ` : '- '}${resolve(String(item))}`).join('\n');
106
+ case 'core/code': return `\`\`\`${raw('language')}\n${raw('code')}\n\`\`\``;
107
+ case 'core/table': {
108
+ const rows = raw('rows').split('\n').map(line => line.trim()).filter(Boolean).map(line => line.replace(/^\||\|$/g, '').split('|').map(cell => cell.trim()));
109
+ if (!rows.length) return '';
110
+ const width = Math.max(...rows.map(row => row.length));
111
+ const line = (cells: string[]) => `| ${Array.from({ length: width }, (_, index) => cells[index] ?? '').join(' | ')} |`;
112
+ const header = data.header !== false;
113
+ const body = header ? rows.slice(1) : rows;
114
+ return [line(header ? rows[0]! : Array.from({ length: width }, () => '')), `| ${Array.from({ length: width }, () => '---').join(' | ')} |`, ...body.map(line)].join('\n');
115
+ }
116
+ case 'core/file': { const url = media(raw('file')); return url ? `[${escapeText(text('label') || 'Download')}](${url})` : ''; }
117
+ case 'core/image': { const url = media(raw('image')); return url ? `![${escapeText(alt(raw('image')) || text('caption'))}](${url})${text('caption') ? `\n\n*${text('caption')}*` : ''}` : ''; }
118
+ case 'core/gallery': return (Array.isArray(data.images) ? data.images as string[] : []).map(id => { const url = media(id); return url ? `![${escapeText(alt(id))}](${url})` : ''; }).filter(Boolean).join('\n\n');
119
+ case 'core/button': return `[${text('label')}](${text('url')})`;
120
+ case 'core/answer': return `${text('label') ? `**${text('label')}** ` : ''}${text('text')}`;
121
+ case 'core/faq-item': return `### ${text('question')}\n\n${text('answer')}`;
122
+ case 'core/step': return `### ${text('title')}${text('text') ? `\n\n${text('text')}` : ''}`;
123
+ case 'core/claim': { const source = text('sourceUrl') ? `[${text('sourceName')}](${text('sourceUrl')})` : text('sourceName'); return `> ${text('text')}\n>\n> — ${source}${text('date') ? `, ${text('date')}` : ''}`; }
124
+ case 'core/definition': return `**${text('term')}**: ${text('definition')}`;
125
+ case 'core/divider': return '---';
126
+ case 'core/card': return [text('title') ? `### ${text('title')}` : '', text('text'), text('url') ? `[${text('linkLabel') || text('url')}](${text('url')})` : ''].filter(Boolean).join('\n\n');
127
+ default: {
128
+ const fields = Object.entries(type.fields).flatMap(([name, declaration]) => {
129
+ const value = data[name];
130
+ if (declaration.kind === 'richtext' && value && typeof value === 'object') return [richTextMarkdown(value as RichTextDoc, { ...rich, block: render })];
131
+ if ((declaration.kind === 'string' || declaration.kind === 'text') && typeof value === 'string' && !declaration.media && !declaration.pattern) return [resolve(value)];
132
+ return [];
133
+ });
134
+ return fields.filter(part => part.trim()).join('\n\n');
135
+ }
136
+ }
137
+ };
138
+ for (const block of flattenBlocks(blocks)) {
139
+ // Containers render through their children, which the flattening lists after them.
140
+ if (block.children?.length && !['core/richtext'].includes(block.type)) continue;
141
+ const text = render(block);
142
+ if (text.trim()) parts.push(text.trim());
143
+ }
144
+ return parts.join('\n\n');
145
+ }
146
+
147
+ export interface EntryMarkdownInput {
148
+ readonly title: string;
149
+ readonly url: string;
150
+ readonly site: string;
151
+ readonly description?: string;
152
+ readonly author?: string;
153
+ readonly published?: string;
154
+ readonly updated?: string;
155
+ readonly terms?: readonly { readonly label: string; readonly terms: readonly string[] }[];
156
+ readonly body: string;
157
+ }
158
+
159
+ /** One entry as a Markdown document with a front-matter header, the way agents read pages. */
160
+ export function entryMarkdown(input: EntryMarkdownInput): string {
161
+ const quote = (value: string) => JSON.stringify(value);
162
+ const header = [
163
+ `title: ${quote(input.title)}`, `url: ${quote(input.url)}`, `site: ${quote(input.site)}`,
164
+ ...(input.description ? [`description: ${quote(input.description)}`] : []), ...(input.author ? [`author: ${quote(input.author)}`] : []),
165
+ ...(input.published ? [`published: ${input.published}`] : []), ...(input.updated ? [`updated: ${input.updated}`] : []),
166
+ ...(input.terms ?? []).filter(group => group.terms.length).map(group => `${group.label.toLowerCase().replace(/[^a-z0-9]+/g, '_')}: [${group.terms.map(quote).join(', ')}]`),
167
+ ];
168
+ return `---\n${header.join('\n')}\n---\n\n# ${input.title}\n\n${input.description ? `${input.description}\n\n` : ''}${input.body}\n`;
169
+ }
170
+
171
+ /** A table as GFM when every cell is one paragraph; cells of several blocks join their lines with spaces. The first row is the header. */
172
+ function tableMarkdown(node: RichTextNode, depth: number, context: MarkdownContext): string {
173
+ const rows = (node.content ?? []).map(row => (row.content ?? []).map(cell =>
174
+ (cell.content ?? []).map(child => nodeMarkdown(child, depth, context)).filter(Boolean).join(' ').replace(/\s*\n\s*/g, ' ').replace(/\|/g, '\\|').trim()));
175
+ if (!rows.length) return '';
176
+ const width = Math.max(...rows.map(row => row.length));
177
+ const line = (cells: readonly string[]) => `| ${Array.from({ length: width }, (_, index) => cells[index] ?? '').join(' | ')} |`;
178
+ return [line(rows[0]!), `| ${Array.from({ length: width }, () => '---').join(' | ')} |`, ...rows.slice(1).map(line)].join('\n');
179
+ }
package/src/updates.ts ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The update notice (specs/cms-updates.md). The CMS asks an update server which version is the
3
+ * latest. The request carries the installed version and the channel, and nothing about the
4
+ * site. The answer only informs: code always comes from the package registry through the
5
+ * project's own pipeline.
6
+ */
7
+ export const DEFAULT_UPDATES_URL = 'https://cms.cossack.dev/update';
8
+ export const DEFAULT_UPDATES_CHANNEL = 'latest';
9
+
10
+ /** `updates` in `src/cms.config.ts`. */
11
+ export interface UpdatesOptions {
12
+ /** Ask the update server once a day. Default true. */
13
+ readonly check?: boolean;
14
+ /** The update server. */
15
+ readonly url?: string;
16
+ /** The release channel: `latest`, or a pre-release channel such as `canary`. */
17
+ readonly channel?: string;
18
+ }
19
+
20
+ /** What the update server said, when it named a version newer than the installed one. */
21
+ export interface UpdateAnswer {
22
+ readonly latest: string;
23
+ /** When the version was published, as an ISO date. */
24
+ readonly published?: string;
25
+ /** The release notes. */
26
+ readonly notes?: string;
27
+ /** A release between the installed version and `latest` fixes a security problem. */
28
+ readonly security: boolean;
29
+ /** The scaffold template the latest version needs: the update also changes project files. */
30
+ readonly hostTemplate?: string;
31
+ /** The oldest version that can go to `latest` in one step. */
32
+ readonly minimumFrom?: string;
33
+ }
34
+
35
+ /** The last check, as the site stores it. */
36
+ export interface UpdateCheck {
37
+ readonly checkedAt: number;
38
+ readonly installed: string;
39
+ readonly channel: string;
40
+ /** Null when the installed version is the latest, or when no check has answered yet. */
41
+ readonly available: UpdateAnswer | null;
42
+ /** Why the last check did not answer. The earlier answer is kept. */
43
+ readonly error?: string;
44
+ }
45
+
46
+ const VERSION = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
47
+
48
+ /** Order two versions: negative when `a` is older. A pre-release is older than its release. Null for a text that is no version. */
49
+ export function compareVersions(a: string, b: string): number | null {
50
+ const left = VERSION.exec(a), right = VERSION.exec(b);
51
+ if (!left || !right) return null;
52
+ for (let index = 1; index <= 3; index++) {
53
+ const difference = Number(left[index]) - Number(right[index]);
54
+ if (difference) return difference;
55
+ }
56
+ if (left[4] === right[4]) return 0;
57
+ if (left[4] === undefined) return 1;
58
+ if (right[4] === undefined) return -1;
59
+ const parts = [left[4].split('.'), right[4].split('.')] as const;
60
+ for (let index = 0; index < Math.max(parts[0].length, parts[1].length); index++) {
61
+ const [x, y] = [parts[0][index], parts[1][index]];
62
+ if (x === undefined) return -1;
63
+ if (y === undefined) return 1;
64
+ if (x === y) continue;
65
+ const numeric = /^\d+$/.test(x) && /^\d+$/.test(y);
66
+ return numeric ? Number(x) - Number(y) : x < y ? -1 : 1;
67
+ }
68
+ return 0;
69
+ }
70
+
71
+ const text = (value: unknown, limit: number): string | undefined => typeof value === 'string' && value.length > 0 && value.length <= limit ? value : undefined;
72
+ const httpUrl = (value: unknown): string | undefined => {
73
+ const candidate = text(value, 500);
74
+ if (!candidate) return undefined;
75
+ try { const url = new URL(candidate); return url.protocol === 'https:' || url.protocol === 'http:' ? url.toString() : undefined; }
76
+ catch { return undefined; }
77
+ };
78
+
79
+ /**
80
+ * The server's answer, checked: a valid version newer than the installed one, or null. A wrong
81
+ * answer can then show at most a wrong notice.
82
+ */
83
+ export function parseUpdateAnswer(body: unknown, installed: string): UpdateAnswer | null {
84
+ if (!body || typeof body !== 'object' || Array.isArray(body)) return null;
85
+ const answer = body as Record<string, unknown>;
86
+ const latest = text(answer.latest, 64);
87
+ if (!latest || !((compareVersions(latest, installed) ?? 0) > 0)) return null;
88
+ const version = (value: unknown) => { const candidate = text(value, 64); return candidate && compareVersions(candidate, candidate) === 0 ? candidate : undefined; };
89
+ const published = text(answer.published, 40);
90
+ const notes = httpUrl(answer.notes), hostTemplate = version(answer.hostTemplate), minimumFrom = version(answer.minimumFrom);
91
+ return {
92
+ latest, security: answer.security === true,
93
+ ...(published && !Number.isNaN(Date.parse(published)) ? { published } : {}),
94
+ ...(notes ? { notes } : {}), ...(hostTemplate ? { hostTemplate } : {}), ...(minimumFrom ? { minimumFrom } : {}),
95
+ };
96
+ }
97
+
98
+ /** The request: the installed version and the channel, and nothing else. */
99
+ export function updateCheckUrl(options: { url: string; channel: string }, installed: string): string {
100
+ const url = new URL(options.url);
101
+ url.searchParams.set('version', installed);
102
+ url.searchParams.set('channel', options.channel);
103
+ return url.toString();
104
+ }
105
+
106
+ /**
107
+ * Ask the update server. A failed check (the server is down, the answer is not JSON) keeps
108
+ * `previous`'s answer and records the reason.
109
+ */
110
+ export async function checkForUpdate(options: {
111
+ installed: string; url: string; channel: string; now: number; previous?: UpdateCheck | null;
112
+ fetch?: typeof globalThis.fetch; timeoutMs?: number;
113
+ }): Promise<UpdateCheck> {
114
+ const base = { checkedAt: options.now, installed: options.installed, channel: options.channel };
115
+ // An earlier answer still counts while it names a version newer than the one installed now.
116
+ const kept = options.previous?.available && (compareVersions(options.previous.available.latest, options.installed) ?? 0) > 0 ? options.previous.available : null;
117
+ try {
118
+ const response = await (options.fetch ?? globalThis.fetch)(updateCheckUrl(options, options.installed), {
119
+ headers: { accept: 'application/json' }, redirect: 'follow', signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
120
+ });
121
+ if (!response.ok) { await response.body?.cancel().catch(() => undefined); return { ...base, available: kept, error: `The update server answered ${response.status}.` }; }
122
+ return { ...base, available: parseUpdateAnswer(await response.json(), options.installed) };
123
+ } catch (error) {
124
+ return { ...base, available: kept, error: error instanceof Error ? error.message : 'The update server did not answer.' };
125
+ }
126
+ }
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** The version of this package. A test keeps it equal to `package.json`. */
2
+ export const CMS_VERSION = '0.9.1';
package/src/vite.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { Plugin, UserConfig } from 'vite';
2
+ import type { IconStyleName } from './icons';
3
+
4
+ /** Puts the space back between attributes the icon package's artwork glues together, so a sprite is well-formed XML. */
5
+ export function xmlSafe(markup: string): string;
6
+
7
+ /** The sprite of a group in a style, or undefined for an unknown group. Missing artwork in a style falls back to line. */
8
+ export function iconSprite(style: IconStyleName, group: string): Promise<string | undefined>;
9
+
10
+ /**
11
+ * The Vite plugin that delivers the icons: one sprite per style and group under
12
+ * `/assets/icons/<style>/<group>.<version>.svg`, served in development and emitted into the
13
+ * client build.
14
+ */
15
+ export function cossackCmsIcons(): Plugin;
16
+
17
+ /** The CMS's part of a project's Vite configuration, which the `cossack/vite` preset adds. */
18
+ export function cossackVite(context: { root: string; runtime: string; mode: string; command: 'build' | 'serve' }): Promise<{
19
+ setup: Plugin[];
20
+ plugins: Plugin[];
21
+ pluginPolicy: boolean;
22
+ pages: Record<string, unknown>;
23
+ cloudflare: Record<string, unknown>;
24
+ config: UserConfig | undefined;
25
+ }>;
package/src/vite.js ADDED
@@ -0,0 +1,199 @@
1
+ /**
2
+ * `cossackCmsIcons()`: the Vite plugin that delivers the icons. For each Solar style it makes
3
+ * one SVG sprite of `<symbol>`s per group (`ICON_SPRITE_GROUPS` in icons.ts: the hot set and one
4
+ * per category) from the installed `@cossackframework/solar-icons`, serves them in development
5
+ * and emits them into the client build under `/assets/icons/<style>/<group>.<version>.svg`,
6
+ * where both adapters cache them for a year. Pages draw `<svg><use href="…#name">`, so no icon
7
+ * markup travels in the HTML or the bundles and a style change in Settings changes URLs, not code.
8
+ *
9
+ * import { cossackCmsIcons } from '@cossackframework/cms/vite';
10
+ * plugins: [cossackCmsIcons(), …]
11
+ *
12
+ * Plain JavaScript: Vite's config loader hands this file to Node as is, so it cannot be
13
+ * TypeScript; the package's TypeScript modules it needs are loaded through Vite's `runnerImport`.
14
+ */
15
+ import { fileURLToPath } from 'node:url';
16
+ import { readFileSync } from 'node:fs';
17
+ import { readFile } from 'node:fs/promises';
18
+ import { isAbsolute, join } from 'node:path';
19
+ import { runnerImport } from 'vite';
20
+
21
+ /**
22
+ * A `<use>` of another file parses that file as XML, where `r="10"stroke="…"` (which the icon
23
+ * package's artwork has, and HTML forgives) is an error that empties the whole sprite: put the
24
+ * space back between attributes.
25
+ * @param {string} markup
26
+ */
27
+ export function xmlSafe(markup) {
28
+ return markup.replace(/"(?=[a-zA-Z][\w:-]*=")/g, '" ');
29
+ }
30
+
31
+ /** @typedef {import('./icons').IconStyleName} IconStyleName */
32
+ /** @typedef {Pick<typeof import('./icons'), 'ICON_SPRITE_GROUPS' | 'ICON_SPRITE_VERSION' | 'ICON_STYLES' | 'iconSpriteNames' | 'iconSpriteUrl' | 'isIconStyle'>} IconModule */
33
+
34
+ /** @type {Promise<IconModule> | undefined} */
35
+ let iconModule;
36
+ /** The package's icons.ts (TypeScript), loaded once through Vite's module runner. */
37
+ function icons() {
38
+ return iconModule ??= runnerImport(fileURLToPath(new URL('./icons.ts', import.meta.url)), { logLevel: 'silent' })
39
+ .then(result => /** @type {IconModule} */ (result.module));
40
+ }
41
+
42
+ /** @type {Promise<Readonly<Record<string, Partial<Record<IconStyleName, string>>>>> | undefined} */
43
+ /**
44
+ * One icon's artwork in a style, or undefined when the package lacks it. Each style of each icon
45
+ * is its own small module, so a sprite loads only its own names: the package's registry imports
46
+ * all 8,700 modules, half a minute on a slow file system, and stalls the dev server meanwhile.
47
+ * @param {string} name
48
+ * @param {IconStyleName} style
49
+ * @returns {Promise<string | undefined>}
50
+ */
51
+ async function artwork(name, style) {
52
+ // Resolving each icon through the package's 2,500-entry exports map costs about 9 ms; its files sit at dist/<name>/<style>.js.
53
+ const file = new URL(`${name}/${style}.js`, artworkRoot());
54
+ // The module is one string constant; reading it as text is far cheaper than importing thousands of modules for a build.
55
+ const literal = /=\s*("(?:[^"\\]|\\.)*")\s*;/.exec(await readFile(file, 'utf8').catch(() => ''))?.[1];
56
+ if (literal) {
57
+ try { return JSON.parse(literal); } catch { /* not plain JSON: import it */ }
58
+ }
59
+ try {
60
+ const markup = Object.values(await import(`@cossackframework/solar-icons/${name}/${style}`))[0];
61
+ return typeof markup === 'string' ? markup : undefined;
62
+ } catch {
63
+ return undefined;
64
+ }
65
+ }
66
+
67
+ let root;
68
+ /** The folder of the icon package's built modules, next to its registry. */
69
+ function artworkRoot() {
70
+ return root ??= new URL('./', import.meta.resolve('@cossackframework/solar-icons/registry'));
71
+ }
72
+
73
+ /**
74
+ * The sprite of a group in a style, or undefined for an unknown group. Missing artwork in a
75
+ * style falls back to line.
76
+ * @param {IconStyleName} style
77
+ * @param {string} group
78
+ * @returns {Promise<string | undefined>}
79
+ */
80
+ export async function iconSprite(style, group) {
81
+ const names = (await icons()).iconSpriteNames(group);
82
+ if (!names) return undefined;
83
+ const symbols = await Promise.all(names.map(async name => {
84
+ const markup = await artwork(name, style) ?? (style === 'line' ? undefined : await artwork(name, 'line'));
85
+ if (!markup) throw new Error(`@cossackframework/solar-icons has no artwork for ${name}`);
86
+ return `<symbol id="${name}" viewBox="0 0 24 24" fill="none">${xmlSafe(markup)}</symbol>`;
87
+ }));
88
+ return `<svg xmlns="http://www.w3.org/2000/svg">${symbols.join('')}</svg>`;
89
+ }
90
+
91
+ const SPRITE_PATH = /^\/assets\/icons\/([a-z-]+)\/([a-z0-9-]+)\.([a-z0-9]+)\.svg$/;
92
+
93
+ /** @returns {import('vite').Plugin} */
94
+ export function cossackCmsIcons() {
95
+ /** @type {Map<string, Promise<string | undefined>>} */
96
+ const made = new Map();
97
+ /** @param {IconStyleName} style @param {string} group */
98
+ const sprite = (style, group) => {
99
+ const key = `${style}/${group}`;
100
+ let pending = made.get(key);
101
+ if (!pending) {
102
+ pending = iconSprite(style, group);
103
+ made.set(key, pending);
104
+ pending.catch(() => made.delete(key));
105
+ }
106
+ return pending;
107
+ };
108
+ return {
109
+ name: 'cossack:cms-icons',
110
+ configureServer(server) {
111
+ server.middlewares.use((request, response, next) => {
112
+ const match = SPRITE_PATH.exec((request.url ?? '').split('?')[0] ?? '');
113
+ if (!match) return next();
114
+ const [, style, group, version] = match;
115
+ icons().then(async module => {
116
+ if (!module.isIconStyle(style) || version !== module.ICON_SPRITE_VERSION) { response.statusCode = 404; response.end(); return; }
117
+ const body = await sprite(style, /** @type {string} */ (group));
118
+ if (!body) { response.statusCode = 404; response.end(); return; }
119
+ response.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
120
+ response.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
121
+ response.end(body);
122
+ }).catch(error => { response.statusCode = 500; response.end(error instanceof Error ? error.message : String(error)); });
123
+ });
124
+ },
125
+ async generateBundle() {
126
+ // The sprites are client assets; the server build and the plugin bundles do not carry them.
127
+ if (this.environment?.name !== 'client') return;
128
+ const module = await icons();
129
+ for (const style of module.ICON_STYLES) {
130
+ for (const group of module.ICON_SPRITE_GROUPS) {
131
+ const source = await sprite(style, group);
132
+ if (source) this.emitFile({ type: 'asset', fileName: module.iconSpriteUrl(style, group).slice(1), source });
133
+ }
134
+ }
135
+ },
136
+ };
137
+ }
138
+
139
+ /** The Worker entrypoint classes of `cms/worker` that a project's entry exports and no binding names. */
140
+ const WORKER_ENTRYPOINTS = ['PluginBridge', 'PluginTail'];
141
+
142
+ /**
143
+ * Development only: names the CMS's Worker entrypoints in the Worker's configuration, as
144
+ * service bindings to itself. The Cloudflare plugin starts the local runtime from the exports
145
+ * the configuration declares, loads the Worker to see what it does export, and starts the
146
+ * runtime again when the two differ: without this, every start loads the Worker twice (the
147
+ * second time with the first request). Only the classes the project's entry exports are named.
148
+ * @param {string} root
149
+ * @param {string} command
150
+ * @param {{ name?: string, main?: string, services?: { entrypoint?: string }[] }} workerConfig
151
+ */
152
+ function developmentExports(root, command, workerConfig) {
153
+ if (command !== 'serve' || !workerConfig?.name) return {};
154
+ let entry = '';
155
+ try { entry = readFileSync(workerConfig.main && isAbsolute(workerConfig.main) ? workerConfig.main : join(root, workerConfig.main ?? 'src/index.ts'), 'utf8'); }
156
+ catch { return {}; }
157
+ const declared = new Set((workerConfig.services ?? []).map(service => service.entrypoint));
158
+ const services = WORKER_ENTRYPOINTS
159
+ .filter(name => new RegExp(`\\b${name}\\b`).test(entry) && !declared.has(name))
160
+ .map(name => ({ binding: `COSSACK_DEV_${name.replace(/(?<=[a-z])(?=[A-Z])/g, '_').toUpperCase()}`, service: workerConfig.name, entrypoint: name }));
161
+ return services.length ? { services } : {};
162
+ }
163
+
164
+ /** Every entry of the CMS library and its database bindings that server code imports on Workers. */
165
+ const SERVER_ENTRIES = [
166
+ '@cossackframework/cms', '@cossackframework/cms/server', '@cossackframework/cms/cloudflare',
167
+ '@cossackframework/cms/storage', '@cossackframework/cms/storage/cloudflare',
168
+ '@cossackframework/romedb', '@cossackframework/romedb/cloudflare',
169
+ ];
170
+
171
+ /**
172
+ * The CMS's part of a project's Vite configuration; the `cossack/vite` preset calls it
173
+ * (`cossack.vite` in this package's package.json).
174
+ */
175
+ export async function cossackVite({ root, runtime, mode, command }) {
176
+ const { romedbDev, romedbDevVars } = await import('@cossackframework/romedb/dev');
177
+ return {
178
+ // Starts `romedb serve` in development when ROMEDB_URL is a loopback URL.
179
+ setup: [romedbDev()],
180
+ // The icon sprites under /assets/icons/, served in development and emitted into the client build.
181
+ plugins: [cossackCmsIcons()],
182
+ // Rendered plugins must stay within their manifest: raw RomeQL, undeclared network,
183
+ // permissions or hooks fail the build.
184
+ pluginPolicy: true,
185
+ // Plugins with only server code run in Workers of their own on Cloudflare (specs/cms-plugin-isolation.md).
186
+ pages: { pluginIsolation: { runtime: '@cossackframework/cms/isolate' } },
187
+ // The token of the local romedb serve that romedbDev started.
188
+ cloudflare: { config: workerConfig => ({ ...romedbDevVars(), ...developmentExports(root, command, workerConfig) }) },
189
+ // RomeDB's native addon loads with Node, not through Vite, and shares @romedb/client's classes.
190
+ config: runtime === 'node' && !(mode === 'desktop' && command === 'build')
191
+ ? { environments: { ssr: { resolve: { external: ['@romedb/client', '@romedb/node'] } } } }
192
+ // The Workers development server fetches the server entry one module at a time. The
193
+ // CMS library and the RomeDB bindings are over a hundred modules that every start
194
+ // loads, so they are pre-bundled, all entries in one pass: they share their state.
195
+ : runtime === 'cloudflare' && command === 'serve'
196
+ ? { environments: { ssr: { optimizeDeps: { include: SERVER_ENTRIES } } } }
197
+ : undefined,
198
+ };
199
+ }
@@ -0,0 +1,107 @@
1
+ /** Webhooks: their events, shape and URL rules. Client-safe; the host stores and sends them. */
2
+ /**
3
+ * Entry events; `form.submitted` for each kept or sent form submission (not spam), going to
4
+ * webhooks for all collections or for Forms; `note.created` and `note.resolved` for editors'
5
+ * review notes on an entry, going to webhooks for the entry's collection; and
6
+ * `payment.completed` for a checkout or payment the payments provider confirmed, going to
7
+ * webhooks for all collections.
8
+ */
9
+ export const WEBHOOK_EVENTS = Object.freeze(['entry.created', 'entry.updated', 'entry.published', 'entry.unpublished', 'entry.deleted', 'form.submitted', 'note.created', 'note.resolved', 'payment.completed'] as const);
10
+ export type WebhookEvent = (typeof WEBHOOK_EVENTS)[number];
11
+
12
+ export interface Webhook {
13
+ readonly id: string;
14
+ readonly name: string;
15
+ readonly url: string;
16
+ readonly events: readonly WebhookEvent[];
17
+ /** Collection names; empty for all. */
18
+ readonly collections: readonly string[];
19
+ /** The signing secret's prefix (`whsec_`), none of its secret characters; the secret itself comes once at creation, or from `secret(id)`. */
20
+ readonly secretHint: string;
21
+ readonly active: boolean;
22
+ readonly createdAt: number;
23
+ readonly updatedAt: number;
24
+ }
25
+
26
+ export interface WebhookInput {
27
+ readonly name: string;
28
+ readonly url: string;
29
+ readonly events: readonly string[];
30
+ readonly collections?: readonly string[];
31
+ readonly active?: boolean;
32
+ }
33
+
34
+ export interface WebhookDelivery {
35
+ readonly id: string;
36
+ readonly webhookId: string;
37
+ readonly event: string;
38
+ readonly status: 'pending' | 'delivered' | 'failed';
39
+ readonly attempts: number;
40
+ readonly responseStatus: number | null;
41
+ readonly error: string | null;
42
+ readonly createdAt: number;
43
+ readonly deliveredAt: number | null;
44
+ readonly nextAttemptAt: number;
45
+ }
46
+
47
+ /** What a delivery posts. */
48
+ export interface WebhookPayload {
49
+ readonly event: WebhookEvent | 'ping';
50
+ /** Stable across retries: the outbox event and the webhook event. */
51
+ readonly eventId: string;
52
+ readonly at: number;
53
+ readonly collection?: string;
54
+ readonly entry?: { readonly [field: string]: unknown };
55
+ /** `form.submitted`: the form and the submission. */
56
+ readonly form?: { readonly id: string; readonly slug: string; readonly title: string };
57
+ readonly submission?: { readonly [field: string]: unknown };
58
+ readonly previousStatus?: string | null;
59
+ /** `note.created` and `note.resolved`: the note, with `entry` naming its entry (`id`, `title`, the editor's `url`). */
60
+ readonly note?: { readonly [field: string]: unknown };
61
+ /** `payment.completed`: the `PaymentEvent` without the provider's object (`provider`, `type`, `checkoutId`, `reference`, `customerEmail`, `amount`, `currency`, `metadata`). */
62
+ readonly payment?: { readonly [field: string]: unknown };
63
+ }
64
+
65
+ /**
66
+ * HTTPS to a public address. A site in development (`local`) may also use plain HTTP and its
67
+ * own machine or network, for a local receiver; otherwise addresses that name this machine or a
68
+ * private network are refused, so a site's webhooks cannot reach services behind the server.
69
+ * Names are not resolved here; pass `webhookFetch` (such as `publicOnlyFetch` from
70
+ * `@cossackframework/cms/node`) to refuse a name that resolves to a private address when sending.
71
+ */
72
+ export function webhookUrlProblem(url: string, options: { local?: boolean } = {}): string | undefined {
73
+ let parsed: URL;
74
+ try { parsed = new URL(url); } catch { return 'Enter a full URL, such as https://example.com/hooks/cms.'; }
75
+ if (url.length > 2000 || parsed.username || parsed.password) return 'Enter a URL of at most 2000 characters, without credentials.';
76
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') return 'Webhooks use HTTPS.';
77
+ if (options.local) return parsed.protocol === 'https:' || privateHost(parsed.hostname) ? undefined : 'Webhooks use HTTPS, except to this machine or network.';
78
+ if (parsed.protocol !== 'https:') return 'Webhooks use HTTPS.';
79
+ if (privateHost(parsed.hostname)) return 'Webhooks go to public addresses, not this machine or a private network.';
80
+ return undefined;
81
+ }
82
+
83
+ /** Whether a URL's host names this machine or a private, link-local or shared network. */
84
+ function privateHost(hostname: string): boolean {
85
+ const host = hostname.toLowerCase().replace(/\.$/, '');
86
+ if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.local') || host.endsWith('.internal')) return true;
87
+ if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(host)) return privateAddress(host);
88
+ if (host.startsWith('[')) return privateAddress(host.slice(1, -1));
89
+ // A bare number or hex form is an IPv4 address in another spelling.
90
+ return /^(0x[0-9a-f]+|\d+)$/.test(host);
91
+ }
92
+
93
+ /**
94
+ * Whether an IP address (dotted IPv4, or IPv6 without brackets) is this machine, a private,
95
+ * link-local, shared or multicast network, or unspecified. For checking what a name resolves to.
96
+ */
97
+ export function privateAddress(address: string): boolean {
98
+ const ip = address.toLowerCase();
99
+ const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(ip)?.slice(1).map(Number);
100
+ if (v4) {
101
+ const [a, b] = v4 as [number, number];
102
+ return a === 0 || a === 10 || a === 127 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || a >= 224;
103
+ }
104
+ if (!ip.includes(':')) return true;
105
+ // IPv4-mapped and IPv4-compatible forms carry an IPv4 address; refuse them all rather than parse.
106
+ return ip === '::' || ip === '::1' || ip.startsWith('::') || /^f[cd]/.test(ip) || /^fe[89ab]/.test(ip) || ip.startsWith('ff') || ip.startsWith('64:ff9b:');
107
+ }