@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,476 @@
1
+ /**
2
+ * The CMS fields of a plugin manifest (`cossack-plugin.json`), validated as data. A plugin
3
+ * package never executes during installation; the host trusts what the manifest declares
4
+ * only after this check, the policy lints and an administrator's grant.
5
+ */
6
+ import { blockProblems, CORE_BLOCKS, flattenBlocks, validateBlocks, type Block, type BlockDeclaration } from './blocks';
7
+ import { blocksShapeProblem } from './block-shape';
8
+ import { collectionProblems, LOCALE, type CollectionDefinition } from './collections';
9
+ import { editorLayoutProblems, editorLayoutShapeProblem } from './editor-layout';
10
+ import { FIELD_BLOCKS, fieldGroupProblems, type FieldGroup } from './field-groups';
11
+ import { defineAction, defineFilter, type ExtensionPoint } from '@cossackframework/core/hooks';
12
+ import { cronProblem } from './cron';
13
+ import { EXTENSION_POINTS } from './hooks';
14
+ import { OWNER_NAME, resourceProblems, type ResourceAction, type ResourceDeclaration } from './resource';
15
+ import { themeProblems, type ThemeManifest } from './theme';
16
+ import { pluginSettingsProblems, type PluginSettingsDeclaration } from './plugin-settings';
17
+
18
+ export interface CommandOption {
19
+ readonly type: 'string' | 'number' | 'boolean';
20
+ readonly description?: string;
21
+ readonly required?: boolean;
22
+ }
23
+
24
+ export interface PluginCommand {
25
+ /** Lowercase name: `cossack <plugin>:<name>`. */
26
+ readonly name: string;
27
+ readonly description: string;
28
+ readonly options?: { readonly [name: string]: CommandOption };
29
+ /** Permission the operator needs, in addition to the dashboard. */
30
+ readonly permission?: string;
31
+ }
32
+
33
+ /** What `permissions.users` lets a plugin do with the site's members. */
34
+ export type UserAction = 'read' | 'write';
35
+ /** Capabilities a manifest switches on in `permissions`; each is the grant `capability:<name>`. */
36
+ export const CAPABILITIES = Object.freeze(['files', 'mail', 'jobs', 'cache', 'ai', 'payments', 'unrestricted'] as const);
37
+ export type Capability = (typeof CAPABILITIES)[number];
38
+ /** The grant that lifts every limit, from `permissions.unrestricted`. */
39
+ export const UNRESTRICTED_GRANT = 'capability:unrestricted';
40
+ /** A job the clock queues: `cron` is five UTC fields as Cloudflare reads them (1 = Sunday); `name` is the job handler. */
41
+ export interface PluginSchedule {
42
+ readonly name: string;
43
+ readonly cron: string;
44
+ readonly description?: string;
45
+ }
46
+
47
+ /** An extension point a plugin defines. */
48
+ export interface ProvidedPoint {
49
+ /** `<plugin>.<name>`, such as `shop.order-placed`. */
50
+ readonly point: string;
51
+ readonly kind: 'action' | 'filter';
52
+ /** Incremented for incompatible payload or value changes. */
53
+ readonly version: number;
54
+ /** Per-handler deadline in milliseconds. Default 5000. */
55
+ readonly timeoutMs?: number;
56
+ readonly description?: string;
57
+ }
58
+
59
+ export interface SlotLink {
60
+ readonly label: string;
61
+ readonly href: string;
62
+ readonly permission?: string;
63
+ /** A Solar icon name for the link in the dashboard navigation, such as `chart`; a plug when the dashboard has no such icon. */
64
+ readonly icon?: string;
65
+ }
66
+
67
+ /** A plugin's maker as its manifest names them. */
68
+ export interface PluginAuthor {
69
+ readonly name: string;
70
+ readonly url?: string;
71
+ readonly email?: string;
72
+ }
73
+
74
+ export interface CmsPluginManifest {
75
+ readonly schemaVersion: 1;
76
+ readonly name: string;
77
+ readonly version: string;
78
+ readonly description?: string;
79
+ /** Who made the plugin, shown on its card: a name, with a website and an email address. */
80
+ readonly author?: PluginAuthor;
81
+ readonly compatibility?: { readonly [pkg: string]: string };
82
+ readonly dependencies?: { readonly [pkg: string]: string };
83
+ readonly resources?: readonly ResourceDeclaration[];
84
+ /**
85
+ * Site collections, such as a portfolio theme's `projects`: entries with URLs, an archive
86
+ * and a dashboard section like posts, stored as `cms/<name>`. Migrated and granted with the plugin.
87
+ */
88
+ readonly collections?: readonly Omit<CollectionDefinition, 'builtin' | 'plugin'>[];
89
+ /** Block types named `<plugin>/<name>`; `ui.ts` renders them through its `blocks` export. */
90
+ readonly blocks?: readonly BlockDeclaration[];
91
+ /**
92
+ * Field groups the plugin ships, with IDs starting with `<plugin>-`: meta boxes attached to
93
+ * collections, taxonomies, users or menus. They are stored with the other groups when the
94
+ * plugin is granted (an upgrade replaces them), tagged with the plugin and read-only in the
95
+ * dashboard; their fields stay with the entries.
96
+ */
97
+ readonly fieldGroups?: readonly Omit<FieldGroup, 'plugin'>[];
98
+ /**
99
+ * Patterns the plugin ships: sections of core blocks and its own, offered in the pattern
100
+ * picker and as starting layouts. Stored once as `<plugin>-<slug>` when the plugin is
101
+ * granted or the theme activated; a pattern the site already has is left as it is.
102
+ */
103
+ readonly patterns?: readonly ManifestPattern[];
104
+ /**
105
+ * Tabs and sidebar boxes the plugin adds to a collection's entry editor while it is active:
106
+ * a partial editor layout per collection, its own or another's. Tab IDs are prefixed with the
107
+ * plugin's name; a layout the administrator saved keeps a tab it already placed.
108
+ */
109
+ readonly editor?: readonly { readonly collection: string; readonly tabs?: readonly Block[]; readonly sidebar?: readonly Block[] }[];
110
+ /**
111
+ * Extension points the plugin's server code registers handlers for: the CMS's own, or those
112
+ * another installed plugin `provides`. Each needs the `hook:<point>` grant.
113
+ */
114
+ /**
115
+ * Extension points the plugin handles. `priority` places an isolated plugin's handlers for
116
+ * the point among other plugins' (lower first, default 10); its handlers' own priorities
117
+ * order them inside its Worker.
118
+ */
119
+ readonly hooks?: readonly { readonly point: string; readonly version: number; readonly priority?: number }[];
120
+ /**
121
+ * Extension points the plugin defines for other plugins, named `<plugin>.<point>`. The host
122
+ * builds them from this list; the plugin invokes them through `context.hooks.doAction` and
123
+ * `applyFilters`, and a consumer looks one up by name with `context.hooks.point()`.
124
+ */
125
+ readonly provides?: readonly ProvidedPoint[];
126
+ readonly permissions?: {
127
+ /** Access to resources the plugin does not own: `{ "cms/posts": ["read"] }`. */
128
+ readonly resources?: { readonly [resource: string]: readonly ResourceAction[] };
129
+ /** Hosts the plugin's server code may contact, such as `api.example.com`. */
130
+ readonly network?: readonly string[];
131
+ /** Permissions the plugin defines for roles, named `<plugin>:<name>`. */
132
+ readonly define?: readonly string[];
133
+ /** Library files the plugin owns, through `context.files`. */
134
+ readonly files?: boolean;
135
+ /** Email sent as the site, through `context.mail`. */
136
+ readonly mail?: boolean;
137
+ /** Work queued for later, and the manifest's `schedules`, through `context.jobs`. */
138
+ readonly jobs?: boolean;
139
+ /** A namespace in the site's cache, through `context.cache`. */
140
+ readonly cache?: boolean;
141
+ /** The application's AI provider, through `context.ai`. */
142
+ readonly ai?: boolean;
143
+ /** Checkouts with the application's payments provider, through `context.payments`; `cms.payment.event` brings the results. */
144
+ readonly payments?: boolean;
145
+ /** No limits: `context.unrestricted()` gives the database, the host and every binding, and the policy lint steps aside. Installing and granting it each carry a danger warning. */
146
+ readonly unrestricted?: boolean;
147
+ /** The site's members through `context.users`: `read` them; `write` creates members and keeps the plugin's meta on them. */
148
+ readonly users?: readonly UserAction[];
149
+ /** Names of the application's bindings the plugin reads through `context.secrets`, such as `STRIPE_SECRET_KEY`. */
150
+ readonly secrets?: readonly string[];
151
+ };
152
+ readonly ui?: {
153
+ /** Links shown in dashboard slots, such as `dashboard.nav`. */
154
+ readonly slots?: { readonly [slot: string]: readonly SlotLink[] };
155
+ };
156
+ readonly commands?: readonly PluginCommand[];
157
+ /** Jobs the clock queues while the plugin is active; needs `permissions.jobs`. */
158
+ readonly schedules?: readonly PluginSchedule[];
159
+ /** `false` keeps the plugin in the application where it could run isolated: what `cossack add plugin --in-app` renders. */
160
+ readonly isolation?: false;
161
+ /** Scalar options rendered under Settings → Plugins in the plugin's own namespace. */
162
+ readonly settings?: PluginSettingsDeclaration;
163
+ /** A site theme: its `templates/` files (or `ui.ts` `theme` export) are the site templates. */
164
+ readonly theme?: ThemeManifest;
165
+ /** A square image in the plugin's `assets/` directory, such as `assets/logo.png`. Default: `assets/logo.*`. */
166
+ readonly logo?: string;
167
+ /** A 4:3 image for the Plugins and Themes screens, such as `assets/cover.png`. Default: `assets/cover.*`. */
168
+ readonly cover?: string;
169
+ /**
170
+ * The interface languages the plugin translates, such as `["vi"]`: a language pack's
171
+ * `translations/<code>.json` (the application's text) and `translations/<code>/<plugin>.json`
172
+ * (another plugin's). Each code needs its directory or file.
173
+ */
174
+ readonly translations?: readonly string[];
175
+ /** Rendered by `cossack add plugin`: the npm package the plugin came from. */
176
+ readonly package?: string;
177
+ readonly [field: string]: unknown;
178
+ }
179
+
180
+ /**
181
+ * Host slots plugins can fill with `ui.slots` links: the dashboard navigation, the dashboard's
182
+ * taskbar and the site's taskbar signed-in users see. `dashboard.overview` takes components, from
183
+ * the plugin's `ui.ts` `slots` export.
184
+ */
185
+ export const HOST_SLOTS = Object.freeze(['dashboard.nav', 'dashboard.overview', 'dashboard.taskbar', 'site.taskbar'] as const);
186
+ export type HostSlot = (typeof HOST_SLOTS)[number];
187
+
188
+ /** A pattern a plugin ships, stored as `<plugin>-<slug>` in the patterns collection. */
189
+ export interface ManifestPattern {
190
+ /** 1 to 40 lowercase letters, digits and hyphens. */
191
+ readonly slug: string;
192
+ readonly title: string;
193
+ /** Changes to the stored pattern show everywhere it is used. Off by default: editors get a copy to change. */
194
+ readonly synced?: boolean;
195
+ /** Collections whose new entries may start from the pattern. */
196
+ readonly starter?: readonly string[];
197
+ readonly blocks: readonly Block[];
198
+ }
199
+ const PATTERN_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
200
+
201
+ const KNOWN_FIELDS = new Set(['schemaVersion', 'name', 'version', 'description', 'author', 'compatibility', 'dependencies', 'resources', 'collections', 'blocks', 'fieldGroups', 'patterns', 'editor', 'hooks', 'permissions', 'ui', 'provides', 'commands', 'schedules', 'settings', 'theme', 'logo', 'cover', 'translations', 'package', 'source', 'isolation']);
202
+ const COLLECTION_NAME = /^[a-z][a-zA-Z0-9_]{0,40}$/;
203
+ const ARTWORK = /^assets\/[A-Za-z0-9][A-Za-z0-9._-]{0,80}\.(?:png|jpe?g|webp|gif|avif|svg)$/;
204
+ const HOST = /^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$|^localhost$/;
205
+ const ACTIONS = new Set(['read', 'create', 'update', 'delete']);
206
+ const USER_ACTIONS = new Set(['read', 'write']);
207
+ const SECRET_NAME = /^[A-Z][A-Z0-9_]{1,63}$/;
208
+ /** Bindings the host and the application own; a plugin names its own. */
209
+ const RESERVED_SECRET = /^(?:ROMEDB_|APP_|CMS_|CLOUDFLARE_|SMTP_|S3_|TURNSTILE_|OAUTH_|COSSACK_)|^(?:MAIL_FROM|EMAIL|AI|DB|KV|R2|STORAGE)$/;
210
+ const SCHEDULE_NAME = /^[a-z][a-z0-9-]{0,40}$/;
211
+ /** An extension point name, as `@cossackframework/core/hooks` accepts it. */
212
+ const POINT = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;
213
+
214
+ /** Whether a point name belongs to a plugin rather than the CMS: `<plugin>.<name>` with a plugin prefix other than `cms`. */
215
+ export function isPluginPoint(point: string): boolean {
216
+ return POINT.test(point) && point.includes('.') && !point.startsWith('cms.');
217
+ }
218
+
219
+ /** The plugin a point name belongs to: the segment before its first dot. */
220
+ export function pointOwner(point: string): string {
221
+ return point.slice(0, point.indexOf('.'));
222
+ }
223
+
224
+ /** The extension points a manifest provides, built for the hook registry. Call on a valid manifest. */
225
+ export function providedPoints(manifest: CmsPluginManifest): ExtensionPoint[] {
226
+ return (manifest.provides ?? []).map(declaration => {
227
+ const options = { version: declaration.version, ...(declaration.timeoutMs !== undefined ? { timeoutMs: declaration.timeoutMs } : {}) };
228
+ return declaration.kind === 'action' ? defineAction(declaration.point, options) : defineFilter(declaration.point, options);
229
+ });
230
+ }
231
+
232
+ /** List fields whose items are read without a shape check first; the others report a wrong shape item by item. */
233
+ const LIST_FIELDS = ['hooks', 'commands'] as const;
234
+
235
+ /** Problems with a manifest's CMS fields. Empty when it can be hosted. */
236
+ /**
237
+ * Names no plugin may take: the host's own owners (`cms/…` and `app/…` resources, `cms:…`
238
+ * permissions, `system:` principals, the `form/…` and `editor/…` blocks) and the framework's. A plugin named like one would hold
239
+ * their permissions as its own, such as assigning a role whose permissions are all `cms:…`.
240
+ */
241
+ export const RESERVED_PLUGIN_NAMES: ReadonlySet<string> = new Set(['cms', 'app', 'core', 'system', 'form', 'editor', 'cossack', 'framework']);
242
+ /** The host's own hook owners (`cms-comments`, `cms-cache`, `cms-automations`, `cms-search`): a plugin of that name would share their outbox retries. */
243
+ export const RESERVED_PLUGIN_PREFIX = 'cms-';
244
+
245
+ export function manifestProblems(manifest: unknown): string[] {
246
+ const problems: string[] = [];
247
+ if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) return ['The manifest must be an object.'];
248
+ const value = manifest as CmsPluginManifest;
249
+ if (value.schemaVersion !== 1) problems.push('schemaVersion must be 1.');
250
+ if (typeof value.name !== 'string' || !OWNER_NAME.test(value.name) || value.name.length > 64) problems.push('name must be a plugin name.');
251
+ else if (RESERVED_PLUGIN_NAMES.has(value.name) || value.name.startsWith(RESERVED_PLUGIN_PREFIX)) problems.push(`name ${value.name} is reserved.`);
252
+ if (typeof value.version !== 'string' || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(value.version)) problems.push('version must be a semantic version.');
253
+ for (const key of Object.keys(value)) if (!KNOWN_FIELDS.has(key)) problems.push(`${key} is not a manifest field.`);
254
+ // Lists are read item by item below; one of another shape would throw instead of being reported, and the host would not start.
255
+ const lists = [...LIST_FIELDS.filter(key => value[key] !== undefined && !Array.isArray(value[key])),
256
+ ...(['network', 'define'] as const).filter(key => value.permissions?.[key] !== undefined && !Array.isArray(value.permissions[key])).map(key => `permissions.${key}`)];
257
+ if (value.permissions !== undefined && (value.permissions === null || typeof value.permissions !== 'object' || Array.isArray(value.permissions))) lists.push('permissions');
258
+ if (lists.length) return [...problems, ...lists.map(key => key === 'permissions' ? 'permissions must be an object.' : `${key} must be a list.`)];
259
+ if (value.settings !== undefined) problems.push(...pluginSettingsProblems(value.settings));
260
+ if (value.translations !== undefined && (!Array.isArray(value.translations) || value.translations.length > 50 || new Set(value.translations).size !== value.translations.length
261
+ || value.translations.some(code => typeof code !== 'string' || !LOCALE.test(code)))) problems.push('translations lists at most 50 distinct language codes, such as vi or pt-br.');
262
+ const name = value.name;
263
+ const resourceNames = new Set<string>();
264
+ for (const [index, resource] of (Array.isArray(value.resources) ? value.resources : value.resources === undefined ? [] : [null]).entries()) {
265
+ if (!resource || typeof resource !== 'object') { problems.push(`resources[${index}] must be a resource declaration.`); continue; }
266
+ if (resource.owner !== undefined && resource.owner !== name) problems.push(`resources[${index}] must belong to the plugin.`);
267
+ for (const problem of resourceProblems({ ...resource, owner: name })) problems.push(`resource ${resource.name}: ${problem}`);
268
+ if (resourceNames.has(resource.name)) problems.push(`resource ${resource.name} is declared twice.`);
269
+ resourceNames.add(resource.name);
270
+ }
271
+ const collectionNames = new Set<string>();
272
+ for (const [index, collection] of (Array.isArray(value.collections) ? value.collections : value.collections === undefined ? [] : [null]).entries()) {
273
+ if (!collection || typeof collection !== 'object') { problems.push(`collections[${index}] must be a collection definition.`); continue; }
274
+ if ('builtin' in collection || 'plugin' in collection) problems.push(`collection ${collection.name}: builtin and plugin are set by the host.`);
275
+ for (const problem of collectionProblems(collection as CollectionDefinition)) problems.push(`collection ${collection.name}: ${problem}`);
276
+ if (collectionNames.has(collection.name)) problems.push(`collection ${collection.name} is declared twice.`);
277
+ collectionNames.add(collection.name);
278
+ }
279
+ const blockNames = new Set<string>();
280
+ for (const [index, block] of (Array.isArray(value.blocks) ? value.blocks : value.blocks === undefined ? [] : [null]).entries()) {
281
+ if (!block || typeof block !== 'object') { problems.push(`blocks[${index}] must be a block declaration.`); continue; }
282
+ problems.push(...blockProblems(block, name));
283
+ if (blockNames.has(block.name)) problems.push(`block ${block.name} is declared twice.`);
284
+ blockNames.add(block.name);
285
+ }
286
+ // Groups are checked against the core and field blocks here; the host checks them against every block type when it stores them.
287
+ const groupTypes = new Map([...CORE_BLOCKS, ...FIELD_BLOCKS].map(block => [block.name, block]));
288
+ const groupIds = new Set<string>();
289
+ for (const [index, group] of (Array.isArray(value.fieldGroups) ? value.fieldGroups : value.fieldGroups === undefined ? [] : [null]).entries()) {
290
+ if (!group || typeof group !== 'object') { problems.push(`fieldGroups[${index}] must be a field group.`); continue; }
291
+ const id = String(group.id);
292
+ if ('plugin' in group) problems.push(`field group ${id}: plugin is set by the host.`);
293
+ if (typeof group.id !== 'string' || !group.id.startsWith(`${name}-`)) problems.push(`field group ${id}: IDs start with ${name}-.`);
294
+ for (const problem of fieldGroupProblems(group as FieldGroup, groupTypes).problems) problems.push(`field group ${id}: ${problem}`);
295
+ if (groupIds.has(id)) problems.push(`field group ${id} is declared twice.`);
296
+ groupIds.add(id);
297
+ }
298
+ // Patterns hold core blocks and the plugin's own; the host checks them against every active type when it stores them.
299
+ const patternTypes = new Map([...CORE_BLOCKS, ...(Array.isArray(value.blocks) ? value.blocks as BlockDeclaration[] : [])].filter(block => block && typeof block.name === 'string').map(block => [block.name, block]));
300
+ const patternSlugs = new Set<string>();
301
+ const patterns = Array.isArray(value.patterns) ? value.patterns : value.patterns === undefined ? [] : [null];
302
+ if (patterns.length > 24) problems.push('patterns lists at most 24 patterns.');
303
+ for (const [index, pattern] of patterns.entries()) {
304
+ if (!pattern || typeof pattern !== 'object') { problems.push(`patterns[${index}] must be a pattern.`); continue; }
305
+ const slug = String(pattern.slug);
306
+ if (typeof pattern.slug !== 'string' || !PATTERN_SLUG.test(pattern.slug) || pattern.slug.length > 40) problems.push(`patterns[${index}]: slug is 1 to 40 lowercase letters, digits and hyphens.`);
307
+ else if (patternSlugs.has(slug)) problems.push(`pattern ${slug} is declared twice.`);
308
+ patternSlugs.add(slug);
309
+ if (typeof pattern.title !== 'string' || !pattern.title.trim() || pattern.title.length > 120) problems.push(`pattern ${slug}: needs a title of at most 120 characters.`);
310
+ if (pattern.synced !== undefined && typeof pattern.synced !== 'boolean') problems.push(`pattern ${slug}: synced is on or off.`);
311
+ if (pattern.starter !== undefined && (!Array.isArray(pattern.starter) || !pattern.starter.every((entry: unknown) => typeof entry === 'string' && COLLECTION_NAME.test(entry)))) problems.push(`pattern ${slug}: starter lists collection names.`);
312
+ const shape = blocksShapeProblem(pattern.blocks);
313
+ if (shape) { problems.push(`pattern ${slug}: blocks ${shape}`); continue; }
314
+ if (!(pattern.blocks as unknown[]).length) problems.push(`pattern ${slug}: needs at least one block.`);
315
+ for (const [path, error] of Object.entries(validateBlocks(pattern.blocks as Block[], patternTypes).errors)) problems.push(`pattern ${slug}: block ${path} ${error}`);
316
+ }
317
+ const editorCollections = new Set<string>();
318
+ for (const [index, entry] of (Array.isArray(value.editor) ? value.editor : value.editor === undefined ? [] : [null]).entries()) {
319
+ if (!entry || typeof entry !== 'object' || typeof entry.collection !== 'string' || !COLLECTION_NAME.test(entry.collection)) { problems.push(`editor[${index}] must name a collection.`); continue; }
320
+ const layout = { tabs: entry.tabs ?? [], sidebar: entry.sidebar ?? [] };
321
+ const shape = editorLayoutShapeProblem(layout);
322
+ if (shape) problems.push(`editor ${entry.collection}: the layout ${shape}`);
323
+ else problems.push(...editorLayoutProblems(layout, { partial: true }).problems.map(problem => `editor ${entry.collection}: ${problem}`));
324
+ if (editorCollections.has(entry.collection)) problems.push(`editor ${entry.collection} is declared twice.`);
325
+ editorCollections.add(entry.collection);
326
+ }
327
+ const provided = new Set<string>();
328
+ for (const [index, declaration] of (Array.isArray(value.provides) ? value.provides : value.provides === undefined ? [] : [null]).entries()) {
329
+ if (!declaration || typeof declaration !== 'object') { problems.push(`provides[${index}] must be an extension point declaration.`); continue; }
330
+ const point = String(declaration.point);
331
+ if (typeof declaration.point !== 'string' || !isPluginPoint(declaration.point) || pointOwner(declaration.point) !== name) problems.push(`provides: ${point} must be named ${name}.<name>.`);
332
+ else if (provided.has(point)) problems.push(`provides: ${point} is declared twice.`);
333
+ provided.add(point);
334
+ if (declaration.kind !== 'action' && declaration.kind !== 'filter') problems.push(`provides: ${point} must be an action or a filter.`);
335
+ if (!Number.isSafeInteger(declaration.version) || declaration.version < 1) problems.push(`provides: ${point} needs a version of 1 or more.`);
336
+ if (declaration.timeoutMs !== undefined && (!Number.isSafeInteger(declaration.timeoutMs) || declaration.timeoutMs < 1 || declaration.timeoutMs > 600_000)) problems.push(`provides: ${point} timeoutMs must be 1 to 600000.`);
337
+ if (declaration.description !== undefined && (typeof declaration.description !== 'string' || declaration.description.length > 300)) problems.push(`provides: ${point} description is at most 300 characters.`);
338
+ }
339
+ const points = new Map(EXTENSION_POINTS.map(point => [point.name, point.version]));
340
+ for (const hook of value.hooks ?? []) {
341
+ const point = hook?.point;
342
+ // A plugin's point is checked against its provider when the host loads both.
343
+ if (typeof point === 'string' && isPluginPoint(point)) {
344
+ if (!Number.isSafeInteger(hook.version) || hook.version < 1) problems.push(`hooks: ${point} needs a version of 1 or more.`);
345
+ } else if (!points.has(point)) problems.push(`hooks: ${String(point)} is not a CMS extension point.`);
346
+ else if (hook.version !== points.get(point)) problems.push(`hooks: ${point} is version ${points.get(point)}, not ${String(hook.version)}.`);
347
+ if (hook?.priority !== undefined && (!Number.isSafeInteger(hook.priority) || hook.priority < -1000 || hook.priority > 1000)) problems.push(`hooks: ${String(point)} priority must be a whole number from -1000 to 1000.`);
348
+ }
349
+ // A plugin can give isolation up; only its shape can give it.
350
+ if (value.isolation !== undefined && value.isolation !== false) problems.push('isolation can only be false, which keeps the plugin in the application.');
351
+ const permissions = value.permissions ?? {};
352
+ for (const [resource, actions] of Object.entries(permissions.resources ?? {})) {
353
+ if (!/^[a-z][a-z0-9-]*\/[a-z][a-z0-9_]*$/.test(resource)) problems.push(`permissions.resources: ${resource} is not a resource ID.`);
354
+ if (!Array.isArray(actions) || !actions.length || actions.some(action => !ACTIONS.has(action))) problems.push(`permissions.resources.${resource} must list read, create, update or delete.`);
355
+ }
356
+ for (const host of permissions.network ?? []) if (typeof host !== 'string' || !HOST.test(host)) problems.push(`permissions.network: ${String(host)} is not a host name.`);
357
+ for (const permission of permissions.define ?? []) {
358
+ if (typeof permission !== 'string' || !permission.startsWith(`${name}:`) || !/^[a-z0-9-]+:[a-z][a-z0-9._-]{0,63}$/.test(permission)) problems.push(`permissions.define: ${String(permission)} must be named ${name}:<name>.`);
359
+ }
360
+ for (const capability of CAPABILITIES) if (permissions[capability] !== undefined && typeof permissions[capability] !== 'boolean') problems.push(`permissions.${capability} is true or false.`);
361
+ if (permissions.users !== undefined && (!Array.isArray(permissions.users) || !permissions.users.length || permissions.users.some(action => !USER_ACTIONS.has(action)))) problems.push('permissions.users must list read or write.');
362
+ if (permissions.secrets !== undefined && !Array.isArray(permissions.secrets)) problems.push('permissions.secrets must list binding names.');
363
+ for (const secret of Array.isArray(permissions.secrets) ? permissions.secrets : []) {
364
+ if (typeof secret !== 'string' || !SECRET_NAME.test(secret)) problems.push(`permissions.secrets: ${String(secret)} must be an upper-case binding name.`);
365
+ else if (RESERVED_SECRET.test(secret)) problems.push(`permissions.secrets: ${secret} belongs to the host.`);
366
+ }
367
+ const schedules = Array.isArray(value.schedules) ? value.schedules : value.schedules === undefined ? [] : [null];
368
+ if (schedules.length > 20) problems.push('schedules: at most 20.');
369
+ if (schedules.length && permissions.jobs !== true && permissions.unrestricted !== true) problems.push('schedules need permissions.jobs.');
370
+ const scheduleNames = new Set<string>();
371
+ for (const [index, schedule] of schedules.entries()) {
372
+ if (!schedule || typeof schedule !== 'object') { problems.push(`schedules[${index}] must be an object.`); continue; }
373
+ if (typeof schedule.name !== 'string' || !SCHEDULE_NAME.test(schedule.name)) problems.push(`schedules[${index}] needs a name of lowercase letters, digits and hyphens.`);
374
+ else if (scheduleNames.has(schedule.name)) problems.push(`schedules: ${schedule.name} is listed twice.`);
375
+ else scheduleNames.add(schedule.name);
376
+ const problem = cronProblem(schedule.cron);
377
+ if (problem) problems.push(`schedules[${index}]: cron ${problem}`);
378
+ if (schedule.description !== undefined && (typeof schedule.description !== 'string' || schedule.description.length > 200)) problems.push(`schedules[${index}]: description is up to 200 characters.`);
379
+ }
380
+ for (const [slot, links] of Object.entries(value.ui?.slots ?? {})) {
381
+ if (!(HOST_SLOTS as readonly string[]).includes(slot)) problems.push(`ui.slots: ${slot} is not a host slot (${HOST_SLOTS.join(', ')}).`);
382
+ for (const link of Array.isArray(links) ? links : []) {
383
+ if (typeof link?.label !== 'string' || !link.label || link.label.length > 60) problems.push(`ui.slots.${slot}: links need a label.`);
384
+ if (typeof link?.href !== 'string' || !link.href.startsWith('/') || link.href.startsWith('//')) problems.push(`ui.slots.${slot}: link ${String(link?.label)} needs a same-site path.`);
385
+ if (link?.icon !== undefined && (typeof link.icon !== 'string' || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(link.icon) || link.icon.length > 60)) problems.push(`ui.slots.${slot}: link ${String(link?.label)} names its icon in lowercase words joined by hyphens, such as chart-2.`);
386
+ }
387
+ }
388
+ if (value.theme !== undefined) {
389
+ problems.push(...themeProblems(value.theme));
390
+ // An area's default blocks: checked like a saved area against the core types. A plugin's block is checked when its plugin is active, so here it only has to be a block.
391
+ for (const [area, entry] of Object.entries((value.theme as ThemeManifest | null)?.areas ?? {})) {
392
+ const blocks = entry && typeof entry === 'object' ? entry.blocks : undefined;
393
+ if (!Array.isArray(blocks) || blocksShapeProblem(blocks)) continue;
394
+ const types = new Map<string, BlockDeclaration>(CORE_BLOCKS.map(block => [block.name, block]));
395
+ for (const block of flattenBlocks(blocks)) if (!types.has(block.type)) types.set(block.type, { name: block.type, label: block.type, fields: {}, children: {} });
396
+ for (const [path, problem] of Object.entries(validateBlocks(blocks, types).errors)) problems.push(`theme.areas.${area}.blocks ${path} ${problem}`);
397
+ }
398
+ }
399
+ if (value.author !== undefined) problems.push(...authorProblems(value.author));
400
+ for (const key of ['logo', 'cover'] as const) {
401
+ if (value[key] !== undefined && (typeof value[key] !== 'string' || !ARTWORK.test(value[key]))) problems.push(`${key} must name a PNG, JPEG, WebP, GIF, AVIF or SVG file in assets/, such as assets/${key}.png.`);
402
+ }
403
+ const commandNames = new Set<string>();
404
+ for (const command of value.commands ?? []) {
405
+ if (typeof command?.name !== 'string' || !/^[a-z][a-z0-9-]{0,40}$/.test(command.name) || commandNames.has(command.name)) problems.push(`commands: ${String(command?.name)} needs a unique lowercase name.`);
406
+ commandNames.add(command?.name);
407
+ if (typeof command?.description !== 'string' || !command.description) problems.push(`commands: ${String(command?.name)} needs a description.`);
408
+ for (const [option, rule] of Object.entries(command?.options ?? {})) {
409
+ if (!/^[a-z][a-z0-9-]{0,40}$/.test(option) || !['string', 'number', 'boolean'].includes(rule?.type)) problems.push(`commands: ${command.name} option ${option} needs a type of string, number or boolean.`);
410
+ }
411
+ }
412
+ return problems;
413
+ }
414
+
415
+ export class ManifestError extends Error {
416
+ readonly problems: readonly string[];
417
+ constructor(problems: readonly string[]) {
418
+ super(`Invalid plugin manifest: ${problems.join(' ')}`);
419
+ this.name = 'ManifestError';
420
+ this.problems = problems;
421
+ }
422
+ }
423
+
424
+ export function validateManifest(manifest: unknown): CmsPluginManifest {
425
+ const problems = manifestProblems(manifest);
426
+ if (problems.length) throw new ManifestError(problems);
427
+ return manifest as CmsPluginManifest;
428
+ }
429
+
430
+ /**
431
+ * The grants a manifest requests, as stable strings: `resource:<id>:<action>`,
432
+ * `network:<host>` and `hook:<point>`. An upgrade that adds one needs a new grant.
433
+ */
434
+ export function requestedGrants(manifest: CmsPluginManifest): string[] {
435
+ const grants: string[] = [];
436
+ for (const [resource, actions] of Object.entries(manifest.permissions?.resources ?? {})) for (const action of actions) grants.push(`resource:${resource}:${action}`);
437
+ for (const host of manifest.permissions?.network ?? []) grants.push(`network:${host}`);
438
+ for (const hook of manifest.hooks ?? []) grants.push(`hook:${hook.point}`);
439
+ for (const capability of CAPABILITIES) if (manifest.permissions?.[capability] === true) grants.push(`capability:${capability}`);
440
+ for (const action of manifest.permissions?.users ?? []) grants.push(`users:${action}`);
441
+ for (const secret of manifest.permissions?.secrets ?? []) grants.push(`secret:${secret}`);
442
+ return [...new Set(grants)].sort();
443
+ }
444
+
445
+ /** Validate command input against a manifest command. Returns typed values or problems. */
446
+ export function commandInput(command: PluginCommand, input: { readonly [name: string]: unknown }): { values: { [name: string]: string | number | boolean }; problems: string[] } {
447
+ const values: { [name: string]: string | number | boolean } = {};
448
+ const problems: string[] = [];
449
+ const options = command.options ?? {};
450
+ for (const key of Object.keys(input)) if (!Object.hasOwn(options, key)) problems.push(`--${key} is not an option of ${command.name}.`);
451
+ for (const [name, rule] of Object.entries(options)) {
452
+ const raw = input[name];
453
+ if (raw === undefined) { if (rule.required) problems.push(`--${name} is required.`); continue; }
454
+ if (rule.type === 'boolean') values[name] = raw === true || raw === 'true';
455
+ else if (rule.type === 'number') {
456
+ const number = typeof raw === 'number' ? raw : Number(raw);
457
+ if (!Number.isFinite(number)) problems.push(`--${name} must be a number.`);
458
+ else values[name] = number;
459
+ } else if (typeof raw === 'string' && raw.length <= 1000) values[name] = raw;
460
+ else problems.push(`--${name} must be text.`);
461
+ }
462
+ return { values, problems };
463
+ }
464
+
465
+ const AUTHOR_KEYS = new Set(['name', 'url', 'email']);
466
+
467
+ function authorProblems(author: unknown): string[] {
468
+ if (!author || typeof author !== 'object' || Array.isArray(author)) return ['author is an object: { "name": "Acme", "url": "https://acme.example", "email": "hello@acme.example" }.'];
469
+ const { name, url, email } = author as Record<string, unknown>;
470
+ const problems: string[] = [];
471
+ for (const key of Object.keys(author)) if (!AUTHOR_KEYS.has(key)) problems.push(`author.${key} is not an author field (name, url, email).`);
472
+ if (typeof name !== 'string' || !name.trim() || name.length > 120) problems.push('author.name is a name of at most 120 characters.');
473
+ if (url !== undefined && (typeof url !== 'string' || !/^https?:\/\/[^\s]{1,300}$/.test(url))) problems.push('author.url is a web address starting with https://.');
474
+ if (email !== undefined && (typeof email !== 'string' || email.length > 191 || !/^[^\s@<>()[\]\\,;:"]+@[^\s@<>()[\]\\,;:"]+\.[^\s@<>()[\]\\,;:"]+$/.test(email))) problems.push('author.email is an email address, such as hello@acme.example.');
475
+ return problems;
476
+ }