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/cli/seed.ts ADDED
@@ -0,0 +1,339 @@
1
+ /**
2
+ * `tinyzoo seed [file]` — put a site's seed content (`seed/index.ts`, written with
3
+ * `defineSeed`) into a running site.
4
+ *
5
+ * SEED_PASSWORD=… tinyzoo seed --url http://localhost:3000 --email you@example.com
6
+ *
7
+ * [file] the seed (default seed/index.ts)
8
+ * --url where the site runs (default $SEED_URL, else http://localhost:3000)
9
+ * --email the administrator to sign in as ($SEED_EMAIL); the password is
10
+ * $SEED_PASSWORD only — never an argument, which would show in `ps`
11
+ * --name the first administrator's name when the site has none yet ($SEED_NAME)
12
+ * --setup-code the code a new production site asks for before its first account
13
+ * (the server's log prints it, or it is NUXT_CMS_AUTH_SETUP_TOKEN).
14
+ * Prefer $SEED_SETUP_CODE: an argument shows in `ps` (the command says so)
15
+ * --dry-run sign in, read, and say what would be created, changed or uploaded;
16
+ * nothing is written
17
+ * --reset first remove the entries and files this seed made (found by their
18
+ * key / name, and made by the account the seed signs in with: a page
19
+ * an editor made with the same address stays), then seed again. It
20
+ * lists every entry and file first and asks (`--yes` skips the
21
+ * question); if anything would be refused (a page another page still
22
+ * links to) it stops before removing anything
23
+ * --verbose also list what was already up to date
24
+ * --wait <sec> how long to wait for the site to answer (default 30)
25
+ *
26
+ * Why over HTTP and not straight into the database: the seed goes through the admin's own
27
+ * API, so each write is checked, stored and indexed by the same code an editor's save
28
+ * runs (validation, translations, media handling and sizes, the search index, saved
29
+ * versions, webhooks, access rules) — a seeded site cannot differ from one an editor
30
+ * filled in. It also works against a site that is deployed, where the database is not
31
+ * reachable from here, and needs nothing but the site's address and an administrator.
32
+ */
33
+ import { existsSync } from 'node:fs'
34
+ import { createInterface } from 'node:readline/promises'
35
+ import { resolve } from 'node:path'
36
+ import { pathToFileURL } from 'node:url'
37
+ import { buildRegistry } from '../src/index'
38
+ import { isSeed, type SeedDefinition } from '../src/seed'
39
+ import { parseArgs } from './transfer'
40
+ import {
41
+ describeReset, planReset, resetDeclared, runSeed, SeedError,
42
+ type MediaRow, type Row, type SeedBackend, type SeedOp,
43
+ } from './seed-engine'
44
+
45
+ export class HttpError extends Error {
46
+ constructor(message: string, readonly status: number) { super(message) }
47
+ }
48
+
49
+ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
50
+
51
+ /** A readable one-liner out of an error response (validation issues listed by field). */
52
+ function errorMessage(status: number, body: any, text: string): string {
53
+ const issues = Array.isArray(body?.data) ? body.data : Array.isArray(body?.data?.issues) ? body.data.issues : []
54
+ const listed = issues.slice(0, 6).map((i: any) => `${Array.isArray(i?.path) && i.path.length ? `${i.path.join('.')}: ` : ''}${i?.message ?? JSON.stringify(i)}`).join('; ')
55
+ const base = body?.statusMessage ?? body?.message ?? (typeof text === 'string' ? text.slice(0, 200) : '')
56
+ return `${status === 0 ? '' : `${status} `}${base}${listed ? ` — ${listed}` : ''}`.trim()
57
+ }
58
+
59
+ /** Cookie-keeping JSON client for the admin API. */
60
+ export class SiteClient {
61
+ private cookie = ''
62
+ constructor(readonly base: string) {}
63
+
64
+ async request<T = any>(method: string, path: string, body?: unknown, opts: { notFound?: boolean } = {}): Promise<T> {
65
+ for (let attempt = 1; ; attempt++) {
66
+ const headers: Record<string, string> = { accept: 'application/json', origin: this.base }
67
+ if (this.cookie) headers.cookie = this.cookie
68
+ let payload: BodyInit | undefined
69
+ if (body instanceof FormData) payload = body
70
+ else if (body !== undefined) { headers['content-type'] = 'application/json'; payload = JSON.stringify(body) }
71
+ const res = await fetch(this.base + path, { method, headers, body: payload, redirect: 'manual', signal: AbortSignal.timeout(120_000) })
72
+ const set = res.headers.getSetCookie?.() ?? []
73
+ if (set.length) this.cookie = set.map((c) => c.split(';')[0]).join('; ')
74
+ const text = await res.text()
75
+ let json: any = null
76
+ try { json = text ? JSON.parse(text) : null } catch { /* not JSON */ }
77
+ // The upload limit (60 a minute) clears within the minute: wait and go on. The sign-in
78
+ // limits last fifteen minutes; waiting here would only look like a hang.
79
+ if (res.status === 429 && path === '/api/cms/_media' && attempt <= 4) {
80
+ await sleep(Math.min(10 * attempt, 30) * 1000)
81
+ continue
82
+ }
83
+ if (res.status === 404 && opts.notFound) return null as T
84
+ if (res.status >= 300) throw new HttpError(`${method} ${path} → ${errorMessage(res.status, json, text)}`, res.status)
85
+ return json as T
86
+ }
87
+ }
88
+ }
89
+
90
+ const enc = encodeURIComponent
91
+
92
+ /** The seed's reads and writes as calls to the admin API. */
93
+ export function httpBackend(site: SiteClient): SeedBackend {
94
+ return {
95
+ async account() { return (await site.request<{ user: { id?: string } | null }>('GET', '/api/cms/_auth/me')).user?.id ?? null },
96
+ async list(entity) {
97
+ const rows: Row[] = []
98
+ for (let page = 1; ; page++) {
99
+ const r = await site.request<{ rows: Row[]; total: number }>('GET', `/api/cms/${enc(entity)}?limit=100&page=${page}&sort=createdAt&dir=asc`)
100
+ rows.push(...r.rows)
101
+ if (!r.rows.length || rows.length >= r.total) return rows
102
+ }
103
+ },
104
+ async get(entity, id, locale) {
105
+ const r = await site.request<{ row: Row }>('GET', `/api/cms/${enc(entity)}/${enc(id)}${locale ? `?locale=${enc(locale)}` : ''}`, undefined, { notFound: true })
106
+ return r?.row ?? null
107
+ },
108
+ async create(entity, data) { return (await site.request<{ row: Row }>('POST', `/api/cms/${enc(entity)}`, data)).row },
109
+ async update(entity, id, data, locale) {
110
+ return (await site.request<{ row: Row }>('PATCH', `/api/cms/${enc(entity)}/${enc(id)}${locale ? `?locale=${enc(locale)}` : ''}`, data)).row
111
+ },
112
+ async remove(entity, id) { await site.request('DELETE', `/api/cms/${enc(entity)}/${enc(id)}`) },
113
+ async getGlobal(entity, locale) {
114
+ const r = await site.request<{ row: Row | null }>('GET', `/api/cms/_singleton/${enc(entity)}${locale ? `?locale=${enc(locale)}` : ''}`)
115
+ return r.row ?? null
116
+ },
117
+ async putGlobal(entity, data, locale) {
118
+ return (await site.request<{ row: Row }>('PUT', `/api/cms/_singleton/${enc(entity)}${locale ? `?locale=${enc(locale)}` : ''}`, data)).row
119
+ },
120
+ async findMedia(q) {
121
+ for (let page = 1; ; page++) {
122
+ const r = await site.request<{ items: MediaRow[]; total: number }>(
123
+ 'GET', `/api/cms/_media?limit=60&page=${page}&q=${enc(q.name.slice(0, 100))}&folder=${enc(q.folder ?? 'none')}`,
124
+ )
125
+ const hit = r.items.find((m) => m.name === q.name && (m.folder ?? null) === q.folder && Number(m.size) === q.size && m.mime === q.mime)
126
+ if (hit) return hit
127
+ if (page * 60 >= r.total) return null
128
+ }
129
+ },
130
+ async uploadMedia(file) {
131
+ const form = new FormData()
132
+ form.append('file', new Blob([file.data as Uint8Array<ArrayBuffer>], { type: file.mime }), file.name)
133
+ if (file.folder) form.append('folder', file.folder)
134
+ if (file.library) form.append('library', '1')
135
+ return site.request<MediaRow>('POST', '/api/cms/_media', form)
136
+ },
137
+ async patchMedia(id, details) { return site.request<MediaRow>('PATCH', `/api/cms/_media/${enc(id)}`, details) },
138
+ async removeMedia(id) { await site.request('DELETE', `/api/cms/_media/${enc(id)}`) },
139
+ }
140
+ }
141
+
142
+ /** A site with nothing in it: what a dry run sees before the first administrator exists. */
143
+ export function emptyBackend(): SeedBackend {
144
+ const refuse = () => { throw new Error('read-only run') }
145
+ return {
146
+ account: async () => null, list: async () => [], get: async () => null, getGlobal: async () => null, findMedia: async () => null,
147
+ create: refuse, update: refuse, remove: refuse, putGlobal: refuse, uploadMedia: refuse, patchMedia: refuse, removeMedia: refuse,
148
+ }
149
+ }
150
+
151
+ // ── signing in ──────────────────────────────────────────────────────────────────
152
+
153
+ interface AuthStatus { mode: string; needsSetup: boolean; needsToken?: boolean; codeIn?: 'config' | 'log' }
154
+
155
+ async function waitForSite(site: SiteClient, seconds: number): Promise<AuthStatus> {
156
+ const until = Date.now() + seconds * 1000
157
+ let last: unknown
158
+ for (;;) {
159
+ try { return await site.request<AuthStatus>('GET', '/api/cms/_auth/status') }
160
+ catch (err) {
161
+ last = err
162
+ // A refused connection or a start-up error: the site may still be coming up. A real answer (4xx) is final.
163
+ if (err instanceof HttpError && err.status < 500) throw err
164
+ if (Date.now() > until) break
165
+ await sleep(500)
166
+ }
167
+ }
168
+ const reason = last instanceof Error ? ((last as any).cause?.code ?? last.message) : String(last)
169
+ throw new SeedError(`The site at ${site.base} does not answer (${reason}). Start it first (pnpm dev), or pass --url.`)
170
+ }
171
+
172
+ async function ask(question: string): Promise<string> {
173
+ const rl = createInterface({ input: process.stdin, output: process.stdout })
174
+ try { return (await rl.question(question)).trim() }
175
+ finally { rl.close() }
176
+ }
177
+
178
+ export interface SeedConnection {
179
+ email?: string
180
+ password?: string
181
+ name: string
182
+ setupCode?: string
183
+ dryRun: boolean
184
+ /** Whether a person can be asked (a terminal). */
185
+ interactive: boolean
186
+ log: (line: string) => void
187
+ }
188
+
189
+ /** Sign in, or set up the first administrator on a fresh site. Null: a dry run on a site with no account yet. */
190
+ export async function connect(site: SiteClient, c: SeedConnection, status: AuthStatus): Promise<'signed-in' | 'created' | null> {
191
+ if (status.mode !== 'builtin') {
192
+ throw new SeedError('This site signs people in with an external provider; the seed needs the CMS\'s own sign-in (it signs in with an email and a password).')
193
+ }
194
+ if (status.needsSetup) {
195
+ if (c.dryRun) return null
196
+ if (!c.email || !c.password) throw new SeedError('The site has no administrator yet. Set SEED_EMAIL (or --email) and SEED_PASSWORD: the seed creates the first account with them.')
197
+ let token = c.setupCode
198
+ if (status.needsToken && !token) {
199
+ const where = status.codeIn === 'log'
200
+ ? 'The server printed it in its log when it started ("No administrator yet. Setup code: …")'
201
+ : 'It is the site\'s NUXT_CMS_AUTH_SETUP_TOKEN'
202
+ if (!c.interactive) throw new SeedError(`This site asks for its setup code before the first account. ${where}. Pass it with --setup-code or SEED_SETUP_CODE.`)
203
+ token = await ask(`Setup code (${where}): `)
204
+ }
205
+ try {
206
+ await site.request('POST', '/api/cms/_auth/setup', { name: c.name, email: c.email, password: c.password, token: token || undefined })
207
+ }
208
+ catch (err) {
209
+ if (err instanceof HttpError && err.status === 403) throw new SeedError('The setup code is missing or wrong.')
210
+ throw err
211
+ }
212
+ c.log(`✓ created the first administrator ${c.email}`)
213
+ return 'created'
214
+ }
215
+ if (!c.email || !c.password) throw new SeedError('Set SEED_EMAIL (or --email) and SEED_PASSWORD: an administrator of the site to sign in as.')
216
+ try {
217
+ await site.request('POST', '/api/cms/_auth/login', { email: c.email, password: c.password })
218
+ }
219
+ catch (err) {
220
+ if (err instanceof HttpError && err.status === 401) throw new SeedError(`Wrong email or password for ${site.base}.`)
221
+ throw err
222
+ }
223
+ return 'signed-in'
224
+ }
225
+
226
+ // ── the command ─────────────────────────────────────────────────────────────────
227
+
228
+ /** The seed definition a file exports (`export default defineSeed(…)`). */
229
+ export async function loadSeed(file: string): Promise<SeedDefinition> {
230
+ const mod = await import(pathToFileURL(file).href)
231
+ const def = mod.default ?? mod.seed
232
+ if (isSeed(def)) return def
233
+ throw new SeedError(`${file} must export a seed: export default defineSeed(async (s) => { … })`)
234
+ }
235
+
236
+ const VERB: Record<string, [string, string]> = {
237
+ created: ['created', 'would create'], updated: ['updated', 'would update'], unchanged: ['unchanged', 'unchanged'],
238
+ kept: ['kept', 'would keep'], uploaded: ['uploaded', 'would upload'],
239
+ }
240
+
241
+ export function formatOp(op: SeedOp, dryRun: boolean): string {
242
+ const [done, would] = VERB[op.action]!
243
+ const verb = (dryRun ? would : done).padEnd(13)
244
+ const mark = op.action === 'unchanged' || op.action === 'kept' ? '·' : '✓'
245
+ return `${mark} ${verb}${op.label}${op.fields?.length && op.action === 'updated' ? ` (${op.fields.join(', ')})` : ''}`
246
+ }
247
+
248
+ export function summarize(ops: SeedOp[], dryRun: boolean): string {
249
+ const n = (a: string, kind?: SeedOp['kind']) => ops.filter((o) => o.action === a && (!kind || o.kind === kind)).length
250
+ const parts = [
251
+ [n('created'), dryRun ? 'to create' : 'created'],
252
+ [n('updated'), dryRun ? 'to update' : 'updated'],
253
+ [n('unchanged'), 'already up to date'],
254
+ [n('kept'), 'left as they are'],
255
+ ].filter(([c]) => c as number > 0).map(([c, w]) => `${c} ${w}`)
256
+ const files = n('uploaded')
257
+ if (files) parts.push(`${files} ${dryRun ? 'files to upload' : files === 1 ? 'file uploaded' : 'files uploaded'}`)
258
+ return parts.length ? parts.join(', ') : 'nothing to do'
259
+ }
260
+
261
+ /** Is this the machine itself: `localhost`, `*.localhost`, 127.0.0.1, ::1? Compared as a whole name, never as the start of one (`localhost.example.com` is somebody else's). */
262
+ export function isLocalHostname(hostname: string): boolean {
263
+ const h = hostname.toLowerCase().replace(/^\[|\]$/g, '')
264
+ return h === 'localhost' || h.endsWith('.localhost') || h === '127.0.0.1' || h === '::1'
265
+ }
266
+
267
+ /** Does this address send the password over the internet unencrypted? (http:// to anything but the machine itself.) */
268
+ export function sendsPasswordInTheClear(base: string): boolean {
269
+ const url = new URL(base)
270
+ return url.protocol === 'http:' && !isLocalHostname(url.hostname)
271
+ }
272
+
273
+ export async function seedCommand(config: Record<string, any>, argv: string[], io: { log?: (line: string) => void; env?: NodeJS.ProcessEnv; cwd?: string } = {}): Promise<void> {
274
+ const log = io.log ?? ((line: string) => console.log(line))
275
+ const env = io.env ?? process.env
276
+ const cwd = io.cwd ?? process.cwd()
277
+ const args = parseArgs(argv, ['url', 'email', 'name', 'setup-code', 'wait'], ['reset', 'dry-run', 'yes', 'verbose'])
278
+ const dryRun = args.flags.has('dry-run')
279
+ const reset = args.flags.has('reset')
280
+ const verbose = args.flags.has('verbose')
281
+
282
+ const file = resolve(cwd, args.positional[0] ?? ['seed/index.ts', 'seed/index.mjs', 'seed/index.js'].find((f) => existsSync(resolve(cwd, f))) ?? 'seed/index.ts')
283
+ if (!existsSync(file)) {
284
+ throw new SeedError(`No seed file (${file}). Create seed/index.ts with: export default defineSeed(async (s) => { … })`)
285
+ }
286
+ const base = (args.values.url ?? env.SEED_URL ?? 'http://localhost:3000').replace(/\/+$/, '')
287
+ try { new URL(base) } catch { throw new SeedError(`"${base}" is not a web address; pass --url http://localhost:3000.`) }
288
+ if (sendsPasswordInTheClear(base)) {
289
+ log(`! ${base} is not encrypted: the password travels in the clear. Use https:// for a site on the internet.`)
290
+ }
291
+ if (args.values['setup-code']) log('! --setup-code shows in the process list (ps) while the command runs; set SEED_SETUP_CODE in the environment instead.')
292
+
293
+ const reg = buildRegistry(config)
294
+ const def = await loadSeed(file)
295
+ const site = new SiteClient(base)
296
+ const status = await waitForSite(site, Number(args.values.wait ?? 30) || 30)
297
+ const connected = await connect(site, {
298
+ email: args.values.email ?? env.SEED_EMAIL,
299
+ password: env.SEED_PASSWORD,
300
+ name: args.values.name ?? env.SEED_NAME ?? 'Admin',
301
+ setupCode: args.values['setup-code'] ?? env.SEED_SETUP_CODE ?? env.SEED_SETUP_TOKEN,
302
+ dryRun,
303
+ interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
304
+ log,
305
+ }, status)
306
+ const backend = connected ? httpBackend(site) : emptyBackend()
307
+ if (!connected) log('· The site has no administrator yet: a real run creates the first one. Everything below is new.')
308
+
309
+ const print = (op: SeedOp) => { if (verbose || (op.action !== 'unchanged' && op.action !== 'kept')) log(formatOp(op, dryRun)) }
310
+
311
+ if (reset) {
312
+ const scanned = (await runSeed(def, { reg, backend, root: cwd, apply: false })).declared
313
+ const plan = await planReset(reg, backend, scanned)
314
+ const files = plan.media.length
315
+ const count = `${plan.entries.length} ${plan.entries.length === 1 ? 'entry' : 'entries'} and ${files} ${files === 1 ? 'file' : 'files'}`
316
+ if (dryRun) {
317
+ log(`· --reset would first remove ${count} the seed made${plan.blocked.length ? ' (but it cannot go through as things are)' : ''}.`)
318
+ for (const line of describeReset(plan, base)) log(line)
319
+ }
320
+ else if (plan.entries.length || plan.media.length || plan.blocked.length) {
321
+ log(`--reset removes ${count} this seed made on ${base}, then seeds again. Everything else stays.`)
322
+ for (const line of describeReset(plan, base)) log(line)
323
+ if (plan.blocked.length) throw new SeedError('Nothing was removed. Change what is listed above, or remove those entries by hand, and run it again.')
324
+ if (!args.flags.has('yes')) {
325
+ if (!process.stdin.isTTY) throw new SeedError('--reset deletes content: add --yes to confirm without a terminal.')
326
+ if (!/^y(es)?$/i.test(await ask('Remove them? [y/N] '))) throw new SeedError('Stopped; nothing was removed.')
327
+ }
328
+ const out = await resetDeclared(backend, plan, log)
329
+ log(`✓ removed ${out.entries} ${out.entries === 1 ? 'entry' : 'entries'} and ${out.media} ${out.media === 1 ? 'file' : 'files'}${out.keptMedia ? ` (${out.keptMedia} still in use stay)` : ''}`)
330
+ }
331
+ else {
332
+ log('· Nothing of this seed is on the site yet; nothing to remove.')
333
+ for (const line of describeReset(plan, base)) log(line)
334
+ }
335
+ }
336
+
337
+ const result = await runSeed(def, { reg, backend, root: cwd, apply: !dryRun && Boolean(connected), onOp: print })
338
+ log(dryRun ? `Dry run, nothing written: ${summarize(result.ops, true)}.` : `✓ Seeded ${base}: ${summarize(result.ops, false)}.`)
339
+ }
package/cli/status.ts ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `tinyzoo status`: what the database in DATABASE_URL has applied and what is still to do.
3
+ * Exit code 0: nothing pending. 1: something is pending or out of order (usable in CI and
4
+ * deploy scripts). 2: the database could not be read.
5
+ */
6
+ import { docsUrl } from '../src/docs'
7
+ import { inspectMigrations, ORDER_FIX, type MigrationStatus } from '../src/index'
8
+ import { databaseUrl, describeDatabase, diskSource, errorText, siteUpgradeSteps, withDatabase } from './db'
9
+
10
+ /** Whose step it is: tinyzoo's own, or the plugin named in front of the id. */
11
+ const stepOwner = (id: string) => (id.includes(':') ? id.slice(0, id.indexOf(':')) : 'tinyzoo')
12
+
13
+ /** The report as text, and whether everything is up to date. */
14
+ export function formatStatus(status: MigrationStatus): { text: string; clean: boolean } {
15
+ const lines: string[] = []
16
+ const pendingSteps = status.steps.filter((s) => s.state === 'pending')
17
+ const appliedSteps = status.steps.filter((s) => s.state === 'applied')
18
+ lines.push(`Migrations: ${status.applied.length} applied, ${status.pending.length} pending${status.freshInstall ? ' (empty database)' : ''}`)
19
+ for (const tag of status.pending) lines.push(` pending ${tag}`)
20
+ lines.push(`Upgrade steps: ${appliedSteps.length} applied, ${pendingSteps.length} pending`)
21
+ for (const s of pendingSteps) lines.push(` pending ${s.id} (${stepOwner(s.id)} ${s.since}) — ${s.description}${status.freshInstall ? ' [recorded without running on an empty database]' : ''}`)
22
+ if (status.outOfOrder.length) {
23
+ lines.push('', 'Out of order — these migrations were never applied, yet a newer one was, so they would be skipped:')
24
+ for (const tag of status.outOfOrder) lines.push(` ✗ ${tag}.sql`)
25
+ const files = status.outOfOrder.map((t) => `${t}.sql`).join(', ')
26
+ lines.push(` ${ORDER_FIX.regenerate(files)}`, ` ${ORDER_FIX.appliedElsewhere}`, ` More: ${docsUrl('neverApplied')}`)
27
+ }
28
+ if (status.unknown) lines.push('', `Note: the database has ${status.unknown} migration${status.unknown > 1 ? 's' : ''} this code does not know — a newer version of the site ran here.`)
29
+ const clean = !status.pending.length && !pendingSteps.length && !status.outOfOrder.length
30
+ lines.push('', clean ? '✓ up to date' : '✗ not up to date — run `tinyzoo up`, or start the app with NUXT_CMS_MIGRATIONS_ON_START=true')
31
+ return { text: lines.join('\n'), clean }
32
+ }
33
+
34
+ /** Returns the process exit code. */
35
+ export async function status(cwd: string): Promise<number> {
36
+ try {
37
+ const url = databaseUrl(cwd)
38
+ const source = diskSource(cwd)
39
+ const steps = await siteUpgradeSteps(cwd)
40
+ const result = await withDatabase(url, ({ run }) => inspectMigrations(source, run, steps))
41
+ const { text, clean } = formatStatus(result)
42
+ console.log(`Database: ${describeDatabase(url)}\n${text}`)
43
+ return clean ? 0 : 1
44
+ }
45
+ catch (err) {
46
+ console.error(`✗ could not read the database: ${errorText(err)}`)
47
+ return 2
48
+ }
49
+ }