tinyzoo 0.0.0-stage → 0.2.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 (392) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +46 -2
  3. package/app/app.config.ts +35 -0
  4. package/app/assets/brand/characters/bright/bird.svg +1 -0
  5. package/app/assets/brand/characters/bright/bunny.svg +1 -0
  6. package/app/assets/brand/characters/bright/elephant.svg +1 -0
  7. package/app/assets/brand/characters/bright/fox.svg +1 -0
  8. package/app/assets/brand/characters/bright/frog.svg +1 -0
  9. package/app/assets/brand/characters/bright/octopus.svg +1 -0
  10. package/app/assets/brand/characters/muted/bee.svg +1 -0
  11. package/app/assets/brand/characters/muted/bird.svg +1 -0
  12. package/app/assets/brand/characters/muted/butterfly.svg +1 -0
  13. package/app/assets/brand/characters/muted/chick.svg +1 -0
  14. package/app/assets/brand/characters/muted/cow.svg +1 -0
  15. package/app/assets/brand/characters/muted/deer.svg +1 -0
  16. package/app/assets/brand/characters/muted/duck.svg +1 -0
  17. package/app/assets/brand/characters/muted/elephant.svg +1 -0
  18. package/app/assets/brand/characters/muted/fox.svg +1 -0
  19. package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
  20. package/app/assets/brand/characters/muted/koala.svg +1 -0
  21. package/app/assets/brand/characters/muted/ladybug.svg +1 -0
  22. package/app/assets/brand/characters/muted/lion.svg +1 -0
  23. package/app/assets/brand/characters/muted/mouse.svg +1 -0
  24. package/app/assets/brand/characters/muted/octopus.svg +1 -0
  25. package/app/assets/brand/characters/muted/owl.svg +1 -0
  26. package/app/assets/brand/characters/muted/panda.svg +1 -0
  27. package/app/assets/brand/characters/muted/penguin.svg +1 -0
  28. package/app/assets/brand/characters/muted/pig.svg +1 -0
  29. package/app/assets/brand/characters/muted/poodle.svg +1 -0
  30. package/app/assets/brand/characters/muted/raccoon.svg +1 -0
  31. package/app/assets/brand/characters/muted/seal.svg +1 -0
  32. package/app/assets/brand/characters/muted/sheep.svg +1 -0
  33. package/app/assets/brand/characters/muted/snail.svg +1 -0
  34. package/app/assets/brand/characters/muted/turtle.svg +1 -0
  35. package/app/assets/brand/characters/muted/whale.svg +1 -0
  36. package/app/assets/brand/logo/favicon.svg +1 -0
  37. package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
  38. package/app/assets/brand/logo/logo-primary.svg +1 -0
  39. package/app/assets/brand/logo/mascot-reversed.svg +1 -0
  40. package/app/assets/brand/logo/mascot.svg +1 -0
  41. package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
  42. package/app/assets/brand/logo/wordmark.svg +1 -0
  43. package/app/assets/css/cms-admin.css +607 -0
  44. package/app/components/CmsBlocks.vue +30 -0
  45. package/app/components/CmsCell.vue +16 -0
  46. package/app/components/CmsCellBadge.vue +18 -0
  47. package/app/components/CmsCellBlocks.vue +9 -0
  48. package/app/components/CmsCellBoolean.vue +12 -0
  49. package/app/components/CmsCellCode.vue +7 -0
  50. package/app/components/CmsCellColor.vue +13 -0
  51. package/app/components/CmsCellDate.vue +10 -0
  52. package/app/components/CmsCellExcerpt.vue +21 -0
  53. package/app/components/CmsCellGallery.vue +10 -0
  54. package/app/components/CmsCellGroup.vue +23 -0
  55. package/app/components/CmsCellNumber.vue +7 -0
  56. package/app/components/CmsCellRelation.vue +8 -0
  57. package/app/components/CmsCellText.vue +12 -0
  58. package/app/components/CmsCellThumb.vue +18 -0
  59. package/app/components/CmsConfirmDialog.vue +55 -0
  60. package/app/components/CmsContent.vue +103 -0
  61. package/app/components/CmsDayPicker.vue +44 -0
  62. package/app/components/CmsEmptyState.vue +35 -0
  63. package/app/components/CmsField.vue +111 -0
  64. package/app/components/CmsFieldBlocks.vue +353 -0
  65. package/app/components/CmsFieldBoolean.vue +8 -0
  66. package/app/components/CmsFieldColor.vue +42 -0
  67. package/app/components/CmsFieldDate.vue +131 -0
  68. package/app/components/CmsFieldGallery.vue +114 -0
  69. package/app/components/CmsFieldGroup.vue +53 -0
  70. package/app/components/CmsFieldMedia.vue +219 -0
  71. package/app/components/CmsFieldNumber.vue +11 -0
  72. package/app/components/CmsFieldRelationMany.vue +54 -0
  73. package/app/components/CmsFieldRelationOne.vue +47 -0
  74. package/app/components/CmsFieldRichText.vue +45 -0
  75. package/app/components/CmsFieldSelect.vue +41 -0
  76. package/app/components/CmsFieldSlug.vue +46 -0
  77. package/app/components/CmsFieldText.vue +75 -0
  78. package/app/components/CmsFormSections.vue +150 -0
  79. package/app/components/CmsHighlight.vue +22 -0
  80. package/app/components/CmsImage.vue +39 -0
  81. package/app/components/CmsLinkPicker.vue +122 -0
  82. package/app/components/CmsLinkTarget.vue +35 -0
  83. package/app/components/CmsListFilters.vue +107 -0
  84. package/app/components/CmsLiveNotice.vue +64 -0
  85. package/app/components/CmsLoadError.vue +24 -0
  86. package/app/components/CmsMascot.vue +10 -0
  87. package/app/components/CmsMediaLibrary.vue +114 -0
  88. package/app/components/CmsMediaPreview.vue +34 -0
  89. package/app/components/CmsMediaThumb.vue +22 -0
  90. package/app/components/CmsMoment.vue +42 -0
  91. package/app/components/CmsNav.vue +39 -0
  92. package/app/components/CmsPage.vue +86 -0
  93. package/app/components/CmsPasswordInput.vue +22 -0
  94. package/app/components/CmsPresence.vue +29 -0
  95. package/app/components/CmsPreviewPanel.vue +131 -0
  96. package/app/components/CmsPublishReview.vue +102 -0
  97. package/app/components/CmsRevisions.vue +195 -0
  98. package/app/components/CmsRichTextEditor.vue +290 -0
  99. package/app/components/CmsSearch.vue +99 -0
  100. package/app/components/CmsSection.vue +20 -0
  101. package/app/components/CmsSingletonForm.vue +283 -0
  102. package/app/components/CmsStatusBadge.vue +21 -0
  103. package/app/components/CmsTime.vue +16 -0
  104. package/app/components/CmsTranslationRef.vue +27 -0
  105. package/app/components/CmsTreeList.vue +453 -0
  106. package/app/components/CmsUnsavedText.vue +34 -0
  107. package/app/components/CmsWordmark.vue +10 -0
  108. package/app/composables/useCmsAdminHead.ts +18 -0
  109. package/app/composables/useCmsCollab.ts +165 -0
  110. package/app/composables/useCmsConfirm.ts +39 -0
  111. package/app/composables/useCmsEntryActions.ts +75 -0
  112. package/app/composables/useCmsFocus.ts +13 -0
  113. package/app/composables/useCmsForm.ts +273 -0
  114. package/app/composables/useCmsI18n.ts +185 -0
  115. package/app/composables/useCmsLinkTargets.ts +84 -0
  116. package/app/composables/useCmsLive.ts +199 -0
  117. package/app/composables/useCmsSearch.ts +62 -0
  118. package/app/composables/useCmsSeo.ts +99 -0
  119. package/app/composables/useCmsSignedIn.ts +24 -0
  120. package/app/composables/useCmsUiLocale.ts +24 -0
  121. package/app/i18n/cs.ts +781 -0
  122. package/app/i18n/de.ts +781 -0
  123. package/app/i18n/en.ts +782 -0
  124. package/app/i18n/types.ts +22 -0
  125. package/app/layouts/admin.vue +224 -0
  126. package/app/layouts/cms-auth.vue +37 -0
  127. package/app/middleware/cms-api-not-a-page.global.ts +10 -0
  128. package/app/middleware/cms-auth.global.ts +16 -0
  129. package/app/pages/admin/[entity]/[id].vue +1109 -0
  130. package/app/pages/admin/[entity]/index.vue +733 -0
  131. package/app/pages/admin/account.vue +117 -0
  132. package/app/pages/admin/forgot.vue +50 -0
  133. package/app/pages/admin/index.vue +184 -0
  134. package/app/pages/admin/invite/[token].vue +73 -0
  135. package/app/pages/admin/login.vue +84 -0
  136. package/app/pages/admin/media.vue +494 -0
  137. package/app/pages/admin/privacy.vue +193 -0
  138. package/app/pages/admin/reset/[token].vue +52 -0
  139. package/app/pages/admin/setup.vue +87 -0
  140. package/app/pages/admin/styleguide.vue +261 -0
  141. package/app/pages/admin/team.vue +258 -0
  142. package/app/plugins/cmsLivePreview.client.ts +20 -0
  143. package/app/plugins/cmsSignedOut.client.ts +31 -0
  144. package/app/utils/cmsBlockType.ts +11 -0
  145. package/app/utils/cmsBrand.ts +38 -0
  146. package/app/utils/cmsDiff.ts +83 -0
  147. package/app/utils/cmsFetch.ts +7 -0
  148. package/app/utils/cmsFocusInvalid.ts +22 -0
  149. package/app/utils/cmsIssues.ts +128 -0
  150. package/app/utils/cmsJson.ts +28 -0
  151. package/app/utils/cmsMedia.ts +63 -0
  152. package/app/utils/cmsSections.ts +154 -0
  153. package/app/utils/cmsTime.ts +41 -0
  154. package/cli/backup.ts +713 -0
  155. package/cli/breaking.ts +174 -0
  156. package/cli/content-migrate.ts +239 -0
  157. package/cli/db.ts +86 -0
  158. package/cli/export.ts +336 -0
  159. package/cli/generate.ts +146 -0
  160. package/cli/import.ts +643 -0
  161. package/cli/index.ts +140 -0
  162. package/cli/links-convert.ts +291 -0
  163. package/cli/seed-engine.ts +705 -0
  164. package/cli/seed.ts +339 -0
  165. package/cli/status.ts +49 -0
  166. package/cli/tar.ts +304 -0
  167. package/cli/transfer.ts +677 -0
  168. package/cli/up.ts +27 -0
  169. package/cli/upgrade.ts +60 -0
  170. package/cli/versions.ts +60 -0
  171. package/forms/components/CmsForm.vue +186 -0
  172. package/forms/index.ts +203 -0
  173. package/forms/messages.ts +104 -0
  174. package/forms/retention.ts +48 -0
  175. package/forms/server/form.get.ts +12 -0
  176. package/forms/server/form.post.ts +109 -0
  177. package/forms/server/formSettings.ts +12 -0
  178. package/forms/server/forms.ts +127 -0
  179. package/module.ts +373 -0
  180. package/nuxt.config.ts +43 -0
  181. package/package.json +98 -3
  182. package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
  183. package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
  184. package/server/api/cms/[entity]/[id].delete.ts +52 -0
  185. package/server/api/cms/[entity]/[id].get.ts +21 -0
  186. package/server/api/cms/[entity]/[id].patch.ts +116 -0
  187. package/server/api/cms/[entity]/_export.get.ts +69 -0
  188. package/server/api/cms/[entity]/_move.post.ts +81 -0
  189. package/server/api/cms/[entity]/_order.post.ts +49 -0
  190. package/server/api/cms/[entity]/_tree.get.ts +41 -0
  191. package/server/api/cms/[entity]/index.get.ts +62 -0
  192. package/server/api/cms/[entity]/index.post.ts +38 -0
  193. package/server/api/cms/[entity]/options.get.ts +55 -0
  194. package/server/api/cms/_auth/accept.post.ts +33 -0
  195. package/server/api/cms/_auth/forgot.post.ts +39 -0
  196. package/server/api/cms/_auth/invite/[token].get.ts +18 -0
  197. package/server/api/cms/_auth/login.post.ts +42 -0
  198. package/server/api/cms/_auth/logout.post.ts +7 -0
  199. package/server/api/cms/_auth/me.get.ts +5 -0
  200. package/server/api/cms/_auth/me.patch.ts +32 -0
  201. package/server/api/cms/_auth/password.post.ts +29 -0
  202. package/server/api/cms/_auth/reset.post.ts +34 -0
  203. package/server/api/cms/_auth/setup.post.ts +46 -0
  204. package/server/api/cms/_auth/status.get.ts +18 -0
  205. package/server/api/cms/_collab/session.get.ts +30 -0
  206. package/server/api/cms/_collab/socket.ts +51 -0
  207. package/server/api/cms/_collab/unsaved.delete.ts +16 -0
  208. package/server/api/cms/_graph.get.ts +20 -0
  209. package/server/api/cms/_links/resolve.post.ts +17 -0
  210. package/server/api/cms/_links.get.ts +81 -0
  211. package/server/api/cms/_live.ts +30 -0
  212. package/server/api/cms/_media/[id]/usage.get.ts +14 -0
  213. package/server/api/cms/_media/[id].delete.ts +29 -0
  214. package/server/api/cms/_media/[id].get.ts +13 -0
  215. package/server/api/cms/_media/[id].patch.ts +64 -0
  216. package/server/api/cms/_media/exists.post.ts +15 -0
  217. package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
  218. package/server/api/cms/_media/index.get.ts +44 -0
  219. package/server/api/cms/_media/index.post.ts +147 -0
  220. package/server/api/cms/_media/raw/[...key].get.ts +85 -0
  221. package/server/api/cms/_media/raw/[...key].head.ts +2 -0
  222. package/server/api/cms/_overview.get.ts +87 -0
  223. package/server/api/cms/_preview.post.ts +17 -0
  224. package/server/api/cms/_privacy/delete.post.ts +14 -0
  225. package/server/api/cms/_privacy/export.post.ts +25 -0
  226. package/server/api/cms/_privacy/lookup.post.ts +27 -0
  227. package/server/api/cms/_search.get.ts +17 -0
  228. package/server/api/cms/_singleton/[name].get.ts +19 -0
  229. package/server/api/cms/_singleton/[name].put.ts +76 -0
  230. package/server/api/cms/_users/[id]/resend.post.ts +25 -0
  231. package/server/api/cms/_users/[id].delete.ts +21 -0
  232. package/server/api/cms/_users/[id].patch.ts +45 -0
  233. package/server/api/cms/_users/index.get.ts +28 -0
  234. package/server/api/cms/_users/index.post.ts +39 -0
  235. package/server/api/content/[entity]/[slug].get.ts +74 -0
  236. package/server/api/content/[entity]/index.get.ts +100 -0
  237. package/server/api/content/_global/[name].get.ts +23 -0
  238. package/server/api/content/_search.get.ts +28 -0
  239. package/server/api/content/_sitemap.get.ts +8 -0
  240. package/server/api/content/_tree/[entity].get.ts +31 -0
  241. package/server/api/content-types.ts.get.ts +17 -0
  242. package/server/api/health/live.get.ts +10 -0
  243. package/server/api/health/ready.get.ts +21 -0
  244. package/server/api/openapi.get.ts +48 -0
  245. package/server/api/openapi.json.get.ts +32 -0
  246. package/server/db/driver.ts +8 -0
  247. package/server/mail/mailer.ts +43 -0
  248. package/server/middleware/cms-0-headers.ts +37 -0
  249. package/server/middleware/cms-0-migrate-gate.ts +14 -0
  250. package/server/middleware/cms-csrf.ts +28 -0
  251. package/server/middleware/cms-limits.ts +20 -0
  252. package/server/middleware/cms-redirects.ts +21 -0
  253. package/server/middleware/cms-session.ts +41 -0
  254. package/server/middleware/cms-z-plugin-access.ts +15 -0
  255. package/server/plugins/cms-0-config-check.ts +35 -0
  256. package/server/plugins/cms-changes.ts +53 -0
  257. package/server/plugins/cms-content-etag.ts +21 -0
  258. package/server/plugins/cms-errors.ts +45 -0
  259. package/server/plugins/cms-migrate.ts +5 -0
  260. package/server/plugins/cms-plugins.ts +17 -0
  261. package/server/plugins/cms-search.ts +12 -0
  262. package/server/plugins/cms-setup-code.ts +15 -0
  263. package/server/routes/sitemap.xml.get.ts +25 -0
  264. package/server/store/redis.ts +95 -0
  265. package/server/store/types.ts +21 -0
  266. package/server/tasks/cms/retention.ts +10 -0
  267. package/server/tasks/cms/scheduled.ts +10 -0
  268. package/server/tasks/cms/search-reindex.ts +12 -0
  269. package/server/utils/cmsAudit.ts +29 -0
  270. package/server/utils/cmsAuth.ts +143 -0
  271. package/server/utils/cmsBlocks.ts +47 -0
  272. package/server/utils/cmsChanges.ts +222 -0
  273. package/server/utils/cmsCollab.ts +286 -0
  274. package/server/utils/cmsCollabServer.ts +451 -0
  275. package/server/utils/cmsCollate.ts +27 -0
  276. package/server/utils/cmsContent.ts +376 -0
  277. package/server/utils/cmsCrud.ts +361 -0
  278. package/server/utils/cmsCsv.ts +24 -0
  279. package/server/utils/cmsDb.ts +23 -0
  280. package/server/utils/cmsDemo.ts +36 -0
  281. package/server/utils/cmsEmails.ts +125 -0
  282. package/server/utils/cmsErrors.ts +40 -0
  283. package/server/utils/cmsFold.ts +17 -0
  284. package/server/utils/cmsImageSizes.ts +51 -0
  285. package/server/utils/cmsJson.ts +6 -0
  286. package/server/utils/cmsLinkAddress.ts +50 -0
  287. package/server/utils/cmsLinks.ts +248 -0
  288. package/server/utils/cmsListQuery.ts +93 -0
  289. package/server/utils/cmsLive.ts +393 -0
  290. package/server/utils/cmsLocales.ts +96 -0
  291. package/server/utils/cmsMail.ts +28 -0
  292. package/server/utils/cmsMediaGc.ts +188 -0
  293. package/server/utils/cmsMediaKeys.ts +62 -0
  294. package/server/utils/cmsMigrate.ts +86 -0
  295. package/server/utils/cmsPreviewDraft.ts +72 -0
  296. package/server/utils/cmsPrivacy.ts +176 -0
  297. package/server/utils/cmsPublished.ts +57 -0
  298. package/server/utils/cmsRange.ts +38 -0
  299. package/server/utils/cmsRateLimit.ts +82 -0
  300. package/server/utils/cmsRedirects.ts +160 -0
  301. package/server/utils/cmsRetention.ts +61 -0
  302. package/server/utils/cmsRevisions.ts +103 -0
  303. package/server/utils/cmsScheduler.ts +45 -0
  304. package/server/utils/cmsScrub.ts +107 -0
  305. package/server/utils/cmsSearch.ts +354 -0
  306. package/server/utils/cmsSession.ts +102 -0
  307. package/server/utils/cmsSetupCode.ts +97 -0
  308. package/server/utils/cmsSitemap.ts +176 -0
  309. package/server/utils/cmsStorage.ts +580 -0
  310. package/server/utils/cmsStore.ts +109 -0
  311. package/server/utils/cmsTiming.ts +14 -0
  312. package/server/utils/cmsTooMany.ts +9 -0
  313. package/server/utils/cmsTranslationWrite.ts +186 -0
  314. package/server/utils/cmsTree.ts +251 -0
  315. package/server/utils/cmsTreeAddress.ts +65 -0
  316. package/server/utils/cmsUpload.ts +228 -0
  317. package/server/utils/cmsWebhooks.ts +104 -0
  318. package/shared/json.ts +11 -0
  319. package/shared/richtext-editor.ts +56 -0
  320. package/shared/richtext-normalize.ts +33 -0
  321. package/shared/richtext-paste.ts +151 -0
  322. package/shared/storage-delivery.ts +53 -0
  323. package/src/blocks.ts +624 -0
  324. package/src/changes.ts +54 -0
  325. package/src/content-shape.ts +340 -0
  326. package/src/deprecate.ts +64 -0
  327. package/src/descriptor.ts +149 -0
  328. package/src/docs.ts +27 -0
  329. package/src/emitter.ts +94 -0
  330. package/src/entity.ts +624 -0
  331. package/src/errorReport.ts +41 -0
  332. package/src/fields.ts +465 -0
  333. package/src/i18n.ts +26 -0
  334. package/src/index.ts +54 -0
  335. package/src/linkref.ts +31 -0
  336. package/src/links.ts +179 -0
  337. package/src/locales.ts +39 -0
  338. package/src/media.ts +48 -0
  339. package/src/migrate.ts +236 -0
  340. package/src/openapi.ts +377 -0
  341. package/src/paths.ts +88 -0
  342. package/src/plugin.ts +505 -0
  343. package/src/presets.ts +230 -0
  344. package/src/richtext.ts +88 -0
  345. package/src/sdk.ts +181 -0
  346. package/src/search.ts +312 -0
  347. package/src/seed.ts +225 -0
  348. package/src/setupCode.ts +30 -0
  349. package/src/system.ts +219 -0
  350. package/src/tree.ts +421 -0
  351. package/src/upgrades.ts +137 -0
  352. package/starter/.env.example +10 -0
  353. package/starter/README.md +65 -0
  354. package/starter/app/app.config.ts +10 -0
  355. package/starter/app/app.vue +12 -0
  356. package/starter/app/assets/css/main.css +15 -0
  357. package/starter/app/components/global/BlockContact.vue +15 -0
  358. package/starter/app/components/global/BlockCta.vue +15 -0
  359. package/starter/app/components/global/BlockHero.vue +23 -0
  360. package/starter/app/components/global/BlockImage.vue +13 -0
  361. package/starter/app/components/global/BlockText.vue +12 -0
  362. package/starter/app/composables/useSite.ts +77 -0
  363. package/starter/app/error.vue +28 -0
  364. package/starter/app/layouts/default.vue +106 -0
  365. package/starter/app/lib/cms-content.ts +152 -0
  366. package/starter/app/pages/[...slug].vue +66 -0
  367. package/starter/app/pages/hledat.vue +59 -0
  368. package/starter/app/pages/index.vue +20 -0
  369. package/starter/cms.config.ts +137 -0
  370. package/starter/compose.yaml +15 -0
  371. package/starter/drizzle.config.ts +8 -0
  372. package/starter/gitignore.txt +8 -0
  373. package/starter/nuxt.config.ts +13 -0
  374. package/starter/package.json +38 -0
  375. package/starter/scripts/typecheck.mjs +38 -0
  376. package/starter/seed/index.ts +297 -0
  377. package/starter/seed/media/about.jpg +0 -0
  378. package/starter/seed/media/hero.jpg +0 -0
  379. package/starter/seed/media/logo.png +0 -0
  380. package/starter/seed/media/news-bread.jpg +0 -0
  381. package/starter/seed/media/news-morning.jpg +0 -0
  382. package/starter/server/db/migrations/0000_init.sql +269 -0
  383. package/starter/server/db/migrations/0001_page_tree.sql +5 -0
  384. package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
  385. package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
  386. package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
  387. package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
  388. package/starter/server/db/migrations/meta/_journal.json +27 -0
  389. package/starter/server/db/schema.ts +253 -0
  390. package/starter/server/plugins/sitemap.ts +11 -0
  391. package/starter/server/routes/robots.txt.get.ts +12 -0
  392. package/starter/tsconfig.json +9 -0
package/src/plugin.ts ADDED
@@ -0,0 +1,505 @@
1
+ /**
2
+ * The plugin API: `defineCmsPlugin()` and what the rest of tinyzoo does with it.
3
+ *
4
+ * A plugin is a plain description of what it adds to a site: entities, admin pages,
5
+ * server routes, field renderers, texts, upgrade steps and a few hooks. It is
6
+ * registered in the site's `cms.config.ts`:
7
+ *
8
+ * export const plugins = [formsPlugin(), eventsPlugin()]
9
+ *
10
+ * The parts split by when they are needed:
11
+ * - at **runtime** (entities, singletons, hooks, upgrade steps, the admin graph) they flow
12
+ * through the registry (`buildRegistry`) like the site's own definitions;
13
+ * - at **build time** (admin pages, server routes, Nitro plugins, components, texts,
14
+ * field renderers) the Nuxt module reads the same config and registers them
15
+ * (`planPlugins` computes what, `module.ts` does it).
16
+ *
17
+ * Everything a plugin adds lives under its own name, so two plugins and the site never
18
+ * collide: entities are `<plugin>` or `<plugin>_<name>`, routes `/api/cms/_p/<plugin>/…`,
19
+ * admin pages `/admin/p/<plugin>/…`, upgrade steps `<plugin>:<id>`, texts
20
+ * `plugins.<plugin>.…`. Mistakes (a taken name, a missing file, a route on someone
21
+ * else's address) stop the build or the start with a message that names the plugin.
22
+ *
23
+ * File paths in a definition (`handler`, `file`, `components`, `serverPlugins`) are
24
+ * absolute: build them with `pluginFile(import.meta.url, './server/ping.ts')`, so a
25
+ * plugin works from `node_modules` as it does from a folder of the site.
26
+ */
27
+ import type { CmsEntity, CmsRegistry } from './entity'
28
+ import type { LocalizedText } from './i18n'
29
+ import type { UpgradeStep } from './upgrades'
30
+
31
+ // ── definition ──────────────────────────────────────────────────────────────────
32
+ export type CmsHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete'
33
+
34
+ /**
35
+ * Who may call a plugin route under `/api/cms/_p/<plugin>/…`:
36
+ * `user` (default) a signed-in person with any role, `admin` an administrator,
37
+ * `public` anyone (the handler then guards itself). Enforced before the handler runs.
38
+ */
39
+ export type CmsRouteAccess = 'user' | 'admin' | 'public'
40
+
41
+ export interface CmsPluginHandler {
42
+ method?: CmsHttpMethod
43
+ /**
44
+ * Address under the plugin's own namespace: `'/ping'` is served at
45
+ * `/api/cms/_p/<plugin>/ping`. `:param` matches one segment.
46
+ */
47
+ route?: string
48
+ /**
49
+ * Also (or instead) served on the public content API at `/api/content/<contentPath>`,
50
+ * for plugins that give a website something to call: `'_form/:name'`. The first
51
+ * segment starts with `_` and is not one of the content API's own. These routes are
52
+ * open; the handler decides who may use them (a content token, a spam check…).
53
+ */
54
+ contentPath?: string
55
+ /** Absolute path of the Nitro handler file (default export: `defineEventHandler(…)`). */
56
+ handler: string
57
+ /** Applies to `route` (default `user`). */
58
+ access?: CmsRouteAccess
59
+ }
60
+
61
+ export interface CmsPluginAdminPage {
62
+ /** Path under `/admin/p/<plugin>/`; `''` is the plugin's index page. `:id` matches one segment. */
63
+ path: string
64
+ /** Absolute path of the page's Vue file. Use `definePageMeta({ layout: 'admin' })` in it. */
65
+ file: string
66
+ }
67
+
68
+ export interface CmsPluginNavItem {
69
+ label: LocalizedText
70
+ /** Iconify name, e.g. `i-lucide-calendar`. */
71
+ icon?: string
72
+ /** An admin page of this plugin, by its `path` (`''` for the index page). */
73
+ page?: string
74
+ /** Or any admin address (`/admin/events_ticket`). One of `page` and `to` is needed. */
75
+ to?: string
76
+ /** Where in the sidebar (default `content`). */
77
+ group?: 'content' | 'settings'
78
+ /** Shown to administrators only. */
79
+ adminOnly?: boolean
80
+ }
81
+
82
+ export interface CmsFieldRenderer {
83
+ /** Name of a global component that edits a field of this type in the form. */
84
+ edit?: string
85
+ /** Name of a global component that shows the value in lists. */
86
+ cell?: string
87
+ }
88
+
89
+ /** What a plugin adds to an entity's entry in the admin graph (see `graph`). */
90
+ export interface CmsGraphExtension {
91
+ /** `false`: the admin offers no "New …" button for this collection (entries arrive some other way). */
92
+ create?: boolean
93
+ /** Short lines under the collection's list: an icon and an admin text from `i18n`. */
94
+ notices?: { icon?: string; key: `plugins.${string}`; params?: Record<string, string | number> }[]
95
+ }
96
+
97
+ export interface CmsRetentionContext {
98
+ /** The retention task's transaction (it holds the task's advisory lock). */
99
+ tx: any
100
+ reg: CmsRegistry
101
+ /** Rows to delete per statement. */
102
+ batch: number
103
+ }
104
+
105
+ export interface CmsPluginHooks {
106
+ /**
107
+ * The daily retention task (`cms:retention`) calls this inside its transaction, for
108
+ * data the plugin keeps that must not be kept forever. Return what was deleted, as
109
+ * `{ what: count }`; the counts go into the audit entry (never the data).
110
+ */
111
+ retention?: (ctx: CmsRetentionContext) => Promise<Record<string, number> | void> | Record<string, number> | void
112
+ }
113
+
114
+ /** An upgrade step as a plugin writes it: `id` is namespaced by the plugin, `since` defaults to the plugin's version. */
115
+ export type CmsPluginUpgradeStep = Omit<UpgradeStep, 'since'> & { since?: string }
116
+
117
+ export interface CmsPluginDef {
118
+ /** Lowercase letters, digits and dashes (`events`, `my-shop`). Namespaces everything the plugin adds. */
119
+ name: string
120
+ /** The plugin's own version (recorded with its upgrade steps). */
121
+ version: string
122
+ /** Collections (`defineEntity`). Each name is the plugin's name or starts with `<name>_` (dashes as underscores). */
123
+ entities?: unknown[]
124
+ /** Single-row globals (`defineSingleton`), named like `entities`. */
125
+ singletons?: unknown[]
126
+ /** Renderers for field types, by type (`{ color: { edit: 'EventsColorField' } }`); the site's own `app.config` still wins. */
127
+ fields?: Record<string, CmsFieldRenderer>
128
+ /** Directory of Vue components, registered globally under their file names. Needed for `fields` and nothing else. */
129
+ components?: string
130
+ adminPages?: CmsPluginAdminPage[]
131
+ navItems?: CmsPluginNavItem[]
132
+ serverHandlers?: CmsPluginHandler[]
133
+ /** Absolute paths of Nitro plugin files (`defineNitroPlugin`). */
134
+ serverPlugins?: string[]
135
+ hooks?: CmsPluginHooks
136
+ /**
137
+ * Admin texts by language: `{ en: { retention: '…' }, cs: { … } }`, nested objects of strings.
138
+ * `en` is required; another language may leave keys out (English is used then).
139
+ * Read them in the admin as `t('plugins.<name>.<key>')`.
140
+ */
141
+ i18n?: Record<string, Record<string, unknown>>
142
+ /** Upgrade steps, run with tinyzoo's own by the start-up migration, `tinyzoo up` and `tinyzoo status`. */
143
+ upgrades?: CmsPluginUpgradeStep[]
144
+ /** Adds to an entity's entry in the admin graph (called for every entity). */
145
+ graph?: (entity: CmsEntity) => CmsGraphExtension | void
146
+ }
147
+
148
+ export interface CmsPlugin extends Readonly<Omit<CmsPluginDef, 'entities' | 'singletons'>> {
149
+ readonly __cms: 'plugin'
150
+ readonly entities: readonly CmsEntity[]
151
+ readonly singletons: readonly CmsEntity[]
152
+ }
153
+
154
+ // ── names ───────────────────────────────────────────────────────────────────────
155
+ const NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/
156
+ const VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/
157
+ const STEP_ID = /^[a-z0-9][a-z0-9-]*$/
158
+ const LOCALE = /^[a-z]{2,3}(-[A-Za-z0-9]+)?$/
159
+ const RESERVED_PLUGIN_NAMES = new Set(['cms', 'core', 'tinyzoo', 'admin', 'api', 'content', 'media', 'plugins', 'p', 'auth', 'system'])
160
+ /** Content API addresses tinyzoo uses itself. */
161
+ const RESERVED_CONTENT_SEGMENTS = new Set(['_global', '_search', '_sitemap'])
162
+
163
+ /** Where plugin routes and pages live. */
164
+ export const pluginApiBase = (plugin: string) => `/api/cms/_p/${plugin}`
165
+ export const pluginAdminBase = (plugin: string) => `/admin/p/${plugin}`
166
+
167
+ /** Entity names of a plugin are `<name>` or `<name>_<rest>`, dashes written as underscores. */
168
+ export const pluginEntityPrefix = (plugin: string) => plugin.replace(/-/g, '_')
169
+
170
+ const fail = (name: string | undefined, message: string): never => {
171
+ throw new Error(`Plugin "${name ?? '?'}": ${message}`)
172
+ }
173
+
174
+ /** Absolute path of a file next to the plugin's source: `pluginFile(import.meta.url, './server/ping.ts')`. */
175
+ export function pluginFile(base: string | URL, relative: string): string {
176
+ try {
177
+ const url = new URL(relative, base)
178
+ // A file: URL as a path (no node:url here: this module is part of the framework-free core).
179
+ return decodeURIComponent(url.pathname).replace(/^\/([A-Za-z]:)/, '$1')
180
+ }
181
+ catch {
182
+ return relative
183
+ }
184
+ }
185
+
186
+ const isAbsolute = (p: string) => p.startsWith('/') || /^[A-Za-z]:[\\/]/.test(p)
187
+
188
+ function checkRoute(name: string, what: string, route: string) {
189
+ if (!route.startsWith('/')) fail(name, `${what} "${route}" must start with "/".`)
190
+ if (route.length > 1 && route.endsWith('/')) fail(name, `${what} "${route}" must not end with "/".`)
191
+ if (!/^[A-Za-z0-9_\-/:.]+$/.test(route) || route.includes('//') || route.split('/').some((s) => s === '..' || s === '.')) {
192
+ fail(name, `${what} "${route}" may only hold letters, digits, "-", "_", "." and ":param" segments.`)
193
+ }
194
+ }
195
+
196
+ const PLURAL_CATEGORIES = new Set(['zero', 'one', 'two', 'few', 'many', 'other'])
197
+ const isPlural = (o: unknown): boolean => !!o && typeof o === 'object' && typeof (o as any).other === 'string'
198
+ && Object.entries(o as object).every(([k, v]) => PLURAL_CATEGORIES.has(k) && typeof v === 'string')
199
+
200
+ function checkMessages(name: string, i18n: Record<string, Record<string, unknown>>) {
201
+ const keysOf = (o: unknown, prefix = ''): string[] => {
202
+ if (typeof o === 'string') return [prefix]
203
+ // A plural message ({ one, few, other }) is one text, not a branch.
204
+ if (isPlural(o)) return [prefix]
205
+ if (o && typeof o === 'object' && !Array.isArray(o)) {
206
+ return Object.entries(o).flatMap(([k, v]) => {
207
+ if (!/^[A-Za-z0-9_-]+$/.test(k)) fail(name, `i18n key "${prefix ? `${prefix}.` : ''}${k}" may only hold letters, digits, "-" and "_".`)
208
+ return keysOf(v, prefix ? `${prefix}.${k}` : k)
209
+ })
210
+ }
211
+ return fail(name, `i18n value at "${prefix}" must be a string or an object of strings.`)
212
+ }
213
+ if (!i18n.en) fail(name, 'i18n needs an "en" catalogue (English is what every other language falls back to).')
214
+ const en = new Set(keysOf(i18n.en))
215
+ for (const [locale, catalogue] of Object.entries(i18n)) {
216
+ if (!LOCALE.test(locale)) fail(name, `i18n language "${locale}" is not a language code.`)
217
+ for (const key of keysOf(catalogue)) {
218
+ if (!en.has(key)) fail(name, `i18n "${locale}" has the key "${key}", which "en" does not.`)
219
+ }
220
+ }
221
+ }
222
+
223
+ /** Validate and normalise a plugin. Throws a message that names the plugin. */
224
+ export function defineCmsPlugin(def: CmsPluginDef): CmsPlugin {
225
+ const name = def?.name
226
+ if (typeof name !== 'string' || !NAME.test(name)) {
227
+ return fail(name, `the name must be lowercase letters, digits and dashes (e.g. "events", "my-shop"), got ${JSON.stringify(name)}.`)
228
+ }
229
+ if (RESERVED_PLUGIN_NAMES.has(name)) fail(name, `"${name}" is reserved by tinyzoo.`)
230
+ if (typeof def.version !== 'string' || !VERSION.test(def.version)) fail(name, `version must look like 1.2.3, got ${JSON.stringify(def.version)}.`)
231
+
232
+ const prefix = pluginEntityPrefix(name)
233
+ const asEntities = (list: unknown[] | undefined, what: 'entities' | 'singletons'): CmsEntity[] => {
234
+ const out: CmsEntity[] = []
235
+ for (const e of list ?? []) {
236
+ const entity = e as CmsEntity
237
+ if (!entity || (entity as any).__cms !== 'entity') fail(name, `${what} takes entities made with ${what === 'entities' ? 'defineEntity' : 'defineSingleton'}().`)
238
+ if (entity.name !== prefix && !entity.name.startsWith(`${prefix}_`)) {
239
+ fail(name, `the ${what === 'entities' ? 'entity' : 'singleton'} "${entity.name}" must be named "${prefix}" or "${prefix}_…", so it cannot collide with the site or another plugin.`)
240
+ }
241
+ if (what === 'singletons' && !entity.singleton) fail(name, `"${entity.name}" is in singletons but is not a singleton (use defineSingleton).`)
242
+ if (what === 'entities' && entity.singleton) fail(name, `"${entity.name}" is a singleton: list it under singletons.`)
243
+ out.push(entity)
244
+ }
245
+ return out
246
+ }
247
+ const entities = asEntities(def.entities, 'entities')
248
+ const singletons = asEntities(def.singletons, 'singletons')
249
+ const seenEntities = new Set<string>()
250
+ for (const e of [...entities, ...singletons]) {
251
+ if (seenEntities.has(e.name)) fail(name, `the entity "${e.name}" is listed twice.`)
252
+ seenEntities.add(e.name)
253
+ }
254
+
255
+ for (const [type, r] of Object.entries(def.fields ?? {})) {
256
+ if (!/^[a-z][A-Za-z0-9]*$/.test(type)) fail(name, `fields: "${type}" is not a field type name.`)
257
+ if (!r || (typeof r.edit !== 'string' && typeof r.cell !== 'string')) fail(name, `fields.${type} needs an "edit" and/or a "cell" component name.`)
258
+ if (r.edit !== undefined && !r.edit || r.cell !== undefined && !r.cell) fail(name, `fields.${type} has an empty component name.`)
259
+ }
260
+ if (def.components !== undefined && !isAbsolute(def.components)) fail(name, 'components must be an absolute directory (use pluginFile(import.meta.url, "./components")).')
261
+ if (Object.keys(def.fields ?? {}).length && !def.components) fail(name, 'fields name components, so the plugin needs `components` (the directory they are in).')
262
+
263
+ const pages = new Set<string>()
264
+ for (const page of def.adminPages ?? []) {
265
+ if (typeof page.path !== 'string' || (page.path !== '' && !/^[A-Za-z0-9_\-:]+(\/[A-Za-z0-9_\-:]+)*$/.test(page.path))) {
266
+ fail(name, `adminPages: "${page.path}" is not a path (letters, digits, "-", "_", ":param", joined by "/"; "" for the index page).`)
267
+ }
268
+ if (!isAbsolute(String(page.file ?? ''))) fail(name, `adminPages "${page.path}": file must be an absolute path.`)
269
+ const key = normalizeParams(page.path)
270
+ if (pages.has(key)) fail(name, `adminPages: "${page.path}" is declared twice.`)
271
+ pages.add(key)
272
+ }
273
+ for (const item of def.navItems ?? []) {
274
+ if (!item.label) fail(name, 'navItems: every item needs a label.')
275
+ if (item.page === undefined && !item.to) fail(name, `navItems "${typeof item.label === 'string' ? item.label : JSON.stringify(item.label)}": give a "page" of this plugin or a "to" address.`)
276
+ if (item.page !== undefined && !pages.has(normalizeParams(item.page))) fail(name, `navItems: "${item.page}" is not one of the plugin's adminPages.`)
277
+ if (item.to !== undefined && !/^\/admin(\/|$)/.test(item.to)) fail(name, `navItems: "to" must be an address in the admin ("/admin/…"), got "${item.to}".`)
278
+ }
279
+
280
+ const routes = new Set<string>()
281
+ const contentRoutes = new Set<string>()
282
+ for (const h of def.serverHandlers ?? []) {
283
+ if (!h.route && !h.contentPath) fail(name, 'serverHandlers: every handler needs a "route" or a "contentPath".')
284
+ if (!isAbsolute(String(h.handler ?? ''))) fail(name, `serverHandlers "${h.route ?? h.contentPath}": handler must be an absolute path.`)
285
+ const method = h.method ?? 'get'
286
+ if (!['get', 'post', 'put', 'patch', 'delete'].includes(method)) fail(name, `serverHandlers: unknown method "${method}".`)
287
+ if (h.access !== undefined && !['user', 'admin', 'public'].includes(h.access)) fail(name, `serverHandlers: unknown access "${h.access}".`)
288
+ if (h.route !== undefined) {
289
+ checkRoute(name, 'route', h.route)
290
+ const key = `${method} ${normalizeParams(h.route)}`
291
+ if (routes.has(key)) fail(name, `serverHandlers: ${method.toUpperCase()} ${h.route} is declared twice.`)
292
+ routes.add(key)
293
+ }
294
+ if (h.contentPath !== undefined) {
295
+ checkRoute(name, 'contentPath', `/${h.contentPath}`)
296
+ const first = h.contentPath.split('/')[0]!
297
+ if (!first.startsWith('_') || RESERVED_CONTENT_SEGMENTS.has(first)) {
298
+ fail(name, `contentPath "${h.contentPath}": the first segment must start with "_" and not be one of ${[...RESERVED_CONTENT_SEGMENTS].join(', ')}.`)
299
+ }
300
+ const key = `${method} ${normalizeParams(h.contentPath)}`
301
+ if (contentRoutes.has(key)) fail(name, `serverHandlers: ${method.toUpperCase()} /api/content/${h.contentPath} is declared twice.`)
302
+ contentRoutes.add(key)
303
+ }
304
+ }
305
+ for (const p of def.serverPlugins ?? []) if (!isAbsolute(p)) fail(name, `serverPlugins: "${p}" must be an absolute path.`)
306
+
307
+ for (const key of Object.keys(def.hooks ?? {})) {
308
+ if (key !== 'retention') fail(name, `hooks: "${key}" is not a hook (available: retention).`)
309
+ }
310
+ if (def.i18n) checkMessages(name, def.i18n)
311
+
312
+ const steps = new Set<string>()
313
+ for (const s of def.upgrades ?? []) {
314
+ if (!STEP_ID.test(s.id)) fail(name, `upgrade step id "${s.id}" must be kebab-case (letters, digits, dashes); the plugin's name is added in front.`)
315
+ if (steps.has(s.id)) fail(name, `two upgrade steps share the id "${s.id}".`)
316
+ steps.add(s.id)
317
+ if (s.phase !== 'before' && s.phase !== 'after') fail(name, `upgrade step "${s.id}" needs phase 'before' or 'after'.`)
318
+ if (s.since !== undefined && !VERSION.test(s.since)) fail(name, `upgrade step "${s.id}": since must look like 1.2.3.`)
319
+ }
320
+
321
+ return Object.freeze({ ...def, __cms: 'plugin' as const, entities, singletons }) as CmsPlugin
322
+ }
323
+
324
+ /** `:id` and `:slug` are the same address: compare routes without the parameter names. */
325
+ function normalizeParams(path: string): string {
326
+ return path.split('/').map((s) => (s.startsWith(':') ? ':' : s)).join('/')
327
+ }
328
+
329
+ export const isCmsPlugin = (v: unknown): v is CmsPlugin => !!v && typeof v === 'object' && (v as any).__cms === 'plugin'
330
+
331
+ // ── collecting plugins from a host config ───────────────────────────────────────
332
+ /**
333
+ * Marks an entity that needs a plugin: `defineForm` needs `forms`. A plugin that is not
334
+ * registered is an error, unless the entity says how to make it (`create`): the
335
+ * deprecated way of using forms, which registers the plugin by itself.
336
+ */
337
+ export interface CmsPluginRequirement {
338
+ plugin: string
339
+ /** How to register it, for the error message. */
340
+ hint: string
341
+ /** Makes the plugin when the site did not register it (deprecated paths only). */
342
+ create?: () => CmsPlugin
343
+ }
344
+
345
+ /**
346
+ * The plugins of a host config: the arrays exported as `plugins` and any plugin
347
+ * exported by itself, plus those an entity of the config asks for by itself. Throws on
348
+ * two plugins with one name, or an entity whose plugin is missing.
349
+ */
350
+ export function collectPlugins(config: Record<string, any>): CmsPlugin[] {
351
+ const found: CmsPlugin[] = []
352
+ const add = (v: unknown) => {
353
+ if (Array.isArray(v)) v.forEach(add)
354
+ else if (isCmsPlugin(v) && !found.includes(v)) found.push(v)
355
+ else if (v !== undefined && v !== null && !isCmsPlugin(v)) throw new Error(`\`plugins\` in cms.config.ts takes plugins (defineCmsPlugin()), got ${typeof v}.`)
356
+ }
357
+ for (const [key, v] of Object.entries(config)) {
358
+ if (key === 'plugins') add(v)
359
+ else if (isCmsPlugin(v)) add(v)
360
+ }
361
+ const byName = new Map<string, CmsPlugin>()
362
+ for (const p of found) {
363
+ if (byName.has(p.name)) throw new Error(`Two plugins are named "${p.name}": register it once.`)
364
+ byName.set(p.name, p)
365
+ }
366
+ for (const v of Object.values(config)) {
367
+ const need = (v as any)?.requiresPlugin as CmsPluginRequirement | undefined
368
+ if (!need || byName.has(need.plugin)) continue
369
+ if (!need.create) {
370
+ throw new Error(`"${(v as any).name}" needs the "${need.plugin}" plugin, which is not registered: ${need.hint}`)
371
+ }
372
+ const made = need.create()
373
+ byName.set(made.name, made)
374
+ found.push(made)
375
+ }
376
+ return found
377
+ }
378
+
379
+ /** tinyzoo's own steps are not namespaced; a plugin's are `<plugin>:<id>`. */
380
+ export const pluginStepId = (plugin: string, id: string) => `${plugin}:${id}`
381
+
382
+ /** The upgrade steps of the plugins, namespaced, ready for the runner. */
383
+ export function pluginUpgradeSteps(plugins: readonly CmsPlugin[]): UpgradeStep[] {
384
+ return plugins.flatMap((p) => (p.upgrades ?? []).map((s) => ({ ...s, id: pluginStepId(p.name, s.id), since: s.since ?? p.version })))
385
+ }
386
+
387
+ /** Every entity the plugins add (collections and singletons). */
388
+ export const pluginEntities = (plugins: readonly CmsPlugin[]): CmsEntity[] => plugins.flatMap((p) => [...p.entities, ...p.singletons])
389
+
390
+ // ── routes ──────────────────────────────────────────────────────────────────────
391
+ /** Does `path` (no query) match a route with `:param` segments? */
392
+ export function matchRoute(pattern: string, path: string): boolean {
393
+ const a = pattern.split('/')
394
+ const b = routePath(path).split('/')
395
+ const rest = a.indexOf('**')
396
+ if (rest !== -1) return b.length >= rest && a.slice(0, rest).every((s, i) => (s.startsWith(':') ? b[i]! !== '' : s === b[i]))
397
+ return a.length === b.length && a.every((s, i) => (s.startsWith(':') ? b[i]! !== '' : s === b[i]))
398
+ }
399
+
400
+ /**
401
+ * A request path the way the router sees it: no query, no trailing slashes (`/x/` and
402
+ * `/x` reach the same handler, so they must get the same access rule).
403
+ */
404
+ export const routePath = (path: string): string => path.split('?')[0]!.replace(/\/+$/, '') || '/'
405
+
406
+ /**
407
+ * The access rule for a request to `/api/cms/_p/…`: `null` when the path is not under
408
+ * a plugin namespace at all, otherwise the declared access of the matching route, or
409
+ * `user` for an address no route declares (never open by accident).
410
+ */
411
+ export function pluginRouteAccess(plugins: readonly CmsPlugin[], method: string, path: string): CmsRouteAccess | null {
412
+ if (!path.split('?')[0]!.startsWith('/api/cms/_p/')) return null
413
+ const clean = routePath(path)
414
+ const m = method.toLowerCase()
415
+ for (const p of plugins) {
416
+ const base = pluginApiBase(p.name)
417
+ if (clean !== base && !clean.startsWith(`${base}/`)) continue
418
+ const handlers = (p.serverHandlers ?? []).filter((h) => h.route !== undefined)
419
+ for (const h of handlers) {
420
+ if ((h.method ?? 'get') !== m) continue
421
+ if (matchRoute(base + h.route, clean)) return h.access ?? 'user'
422
+ }
423
+ // An address in this plugin's namespace that no route declares (the router may still
424
+ // reach a handler by a spelling this matcher doesn't know): the strictest rule the
425
+ // plugin uses anywhere, never less than a signed-in person.
426
+ return handlers.some((h) => h.access === 'admin') ? 'admin' : 'user'
427
+ }
428
+ return 'user'
429
+ }
430
+
431
+ // ── what the Nuxt module registers ──────────────────────────────────────────────
432
+ export interface PluginPlan {
433
+ pages: { name: string; path: string; file: string; plugin: string }[]
434
+ handlers: { method: CmsHttpMethod; route: string; handler: string; plugin: string }[]
435
+ serverPlugins: string[]
436
+ componentDirs: string[]
437
+ navItems: { plugin: string; label: LocalizedText; icon?: string; to: string; group: 'content' | 'settings'; adminOnly: boolean }[]
438
+ fields: Record<string, { edit?: string; cell?: string; plugin: string }>
439
+ messages: Record<string, Record<string, Record<string, unknown>>>
440
+ plugins: { name: string; version: string }[]
441
+ }
442
+
443
+ /**
444
+ * What the build must register for these plugins, or an error that names the plugin:
445
+ * duplicate names, two plugins on one route, page or field type, files that do not
446
+ * exist (`exists`: the module passes `existsSync`).
447
+ */
448
+ export function planPlugins(plugins: readonly CmsPlugin[], opts: { exists?: (file: string) => boolean } = {}): PluginPlan {
449
+ const exists = opts.exists ?? (() => true)
450
+ const plan: PluginPlan = { pages: [], handlers: [], serverPlugins: [], componentDirs: [], navItems: [], fields: {}, messages: {}, plugins: [] }
451
+ const names = new Set<string>()
452
+ const taken = new Map<string, string>() // "get /api/cms/_p/x/y" → plugin
453
+ const need = (plugin: string, what: string, file: string) => {
454
+ if (!exists(file)) fail(plugin, `${what} "${file}" does not exist.`)
455
+ }
456
+ const claim = (plugin: string, key: string, shown: string) => {
457
+ const other = taken.get(key)
458
+ if (other) fail(plugin, `${shown} is already served by the plugin "${other}".`)
459
+ taken.set(key, plugin)
460
+ }
461
+ for (const p of plugins) {
462
+ if (names.has(p.name)) throw new Error(`Two plugins are named "${p.name}": register it once.`)
463
+ names.add(p.name)
464
+ plan.plugins.push({ name: p.name, version: p.version })
465
+
466
+ for (const page of p.adminPages ?? []) {
467
+ need(p.name, `admin page "${page.path}": file`, page.file)
468
+ const path = page.path ? `${pluginAdminBase(p.name)}/${page.path}` : pluginAdminBase(p.name)
469
+ plan.pages.push({ name: `cms-plugin-${p.name}-${page.path.replace(/[^A-Za-z0-9]+/g, '-') || 'index'}`, path, file: page.file, plugin: p.name })
470
+ }
471
+ for (const h of p.serverHandlers ?? []) {
472
+ need(p.name, `server handler "${h.route ?? h.contentPath}": handler`, h.handler)
473
+ const method = h.method ?? 'get'
474
+ if (h.route !== undefined) {
475
+ const route = pluginApiBase(p.name) + h.route
476
+ claim(p.name, `${method} ${normalizeParams(route)}`, `${method.toUpperCase()} ${route}`)
477
+ plan.handlers.push({ method, route, handler: h.handler, plugin: p.name })
478
+ }
479
+ if (h.contentPath !== undefined) {
480
+ const route = `/api/content/${h.contentPath}`
481
+ claim(p.name, `${method} ${normalizeParams(route)}`, `${method.toUpperCase()} ${route}`)
482
+ plan.handlers.push({ method, route, handler: h.handler, plugin: p.name })
483
+ }
484
+ }
485
+ for (const file of p.serverPlugins ?? []) {
486
+ need(p.name, 'server plugin', file)
487
+ plan.serverPlugins.push(file)
488
+ }
489
+ if (p.components) {
490
+ need(p.name, 'components directory', p.components)
491
+ plan.componentDirs.push(p.components)
492
+ }
493
+ for (const [type, r] of Object.entries(p.fields ?? {})) {
494
+ const other = plan.fields[type]
495
+ if (other) fail(p.name, `the field type "${type}" already has renderers from the plugin "${other.plugin}".`)
496
+ plan.fields[type] = { ...r, plugin: p.name }
497
+ }
498
+ for (const item of p.navItems ?? []) {
499
+ const to = item.page !== undefined ? (item.page ? `${pluginAdminBase(p.name)}/${item.page}` : pluginAdminBase(p.name)) : item.to!
500
+ plan.navItems.push({ plugin: p.name, label: item.label, icon: item.icon, to, group: item.group ?? 'content', adminOnly: !!item.adminOnly })
501
+ }
502
+ if (p.i18n) plan.messages[p.name] = p.i18n as Record<string, Record<string, unknown>>
503
+ }
504
+ return plan
505
+ }