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.
- package/LICENSE +10 -0
- package/README.md +46 -2
- package/app/app.config.ts +35 -0
- package/app/assets/brand/characters/bright/bird.svg +1 -0
- package/app/assets/brand/characters/bright/bunny.svg +1 -0
- package/app/assets/brand/characters/bright/elephant.svg +1 -0
- package/app/assets/brand/characters/bright/fox.svg +1 -0
- package/app/assets/brand/characters/bright/frog.svg +1 -0
- package/app/assets/brand/characters/bright/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/bee.svg +1 -0
- package/app/assets/brand/characters/muted/bird.svg +1 -0
- package/app/assets/brand/characters/muted/butterfly.svg +1 -0
- package/app/assets/brand/characters/muted/chick.svg +1 -0
- package/app/assets/brand/characters/muted/cow.svg +1 -0
- package/app/assets/brand/characters/muted/deer.svg +1 -0
- package/app/assets/brand/characters/muted/duck.svg +1 -0
- package/app/assets/brand/characters/muted/elephant.svg +1 -0
- package/app/assets/brand/characters/muted/fox.svg +1 -0
- package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
- package/app/assets/brand/characters/muted/koala.svg +1 -0
- package/app/assets/brand/characters/muted/ladybug.svg +1 -0
- package/app/assets/brand/characters/muted/lion.svg +1 -0
- package/app/assets/brand/characters/muted/mouse.svg +1 -0
- package/app/assets/brand/characters/muted/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/owl.svg +1 -0
- package/app/assets/brand/characters/muted/panda.svg +1 -0
- package/app/assets/brand/characters/muted/penguin.svg +1 -0
- package/app/assets/brand/characters/muted/pig.svg +1 -0
- package/app/assets/brand/characters/muted/poodle.svg +1 -0
- package/app/assets/brand/characters/muted/raccoon.svg +1 -0
- package/app/assets/brand/characters/muted/seal.svg +1 -0
- package/app/assets/brand/characters/muted/sheep.svg +1 -0
- package/app/assets/brand/characters/muted/snail.svg +1 -0
- package/app/assets/brand/characters/muted/turtle.svg +1 -0
- package/app/assets/brand/characters/muted/whale.svg +1 -0
- package/app/assets/brand/logo/favicon.svg +1 -0
- package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
- package/app/assets/brand/logo/logo-primary.svg +1 -0
- package/app/assets/brand/logo/mascot-reversed.svg +1 -0
- package/app/assets/brand/logo/mascot.svg +1 -0
- package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
- package/app/assets/brand/logo/wordmark.svg +1 -0
- package/app/assets/css/cms-admin.css +607 -0
- package/app/components/CmsBlocks.vue +30 -0
- package/app/components/CmsCell.vue +16 -0
- package/app/components/CmsCellBadge.vue +18 -0
- package/app/components/CmsCellBlocks.vue +9 -0
- package/app/components/CmsCellBoolean.vue +12 -0
- package/app/components/CmsCellCode.vue +7 -0
- package/app/components/CmsCellColor.vue +13 -0
- package/app/components/CmsCellDate.vue +10 -0
- package/app/components/CmsCellExcerpt.vue +21 -0
- package/app/components/CmsCellGallery.vue +10 -0
- package/app/components/CmsCellGroup.vue +23 -0
- package/app/components/CmsCellNumber.vue +7 -0
- package/app/components/CmsCellRelation.vue +8 -0
- package/app/components/CmsCellText.vue +12 -0
- package/app/components/CmsCellThumb.vue +18 -0
- package/app/components/CmsConfirmDialog.vue +55 -0
- package/app/components/CmsContent.vue +103 -0
- package/app/components/CmsDayPicker.vue +44 -0
- package/app/components/CmsEmptyState.vue +35 -0
- package/app/components/CmsField.vue +111 -0
- package/app/components/CmsFieldBlocks.vue +353 -0
- package/app/components/CmsFieldBoolean.vue +8 -0
- package/app/components/CmsFieldColor.vue +42 -0
- package/app/components/CmsFieldDate.vue +131 -0
- package/app/components/CmsFieldGallery.vue +114 -0
- package/app/components/CmsFieldGroup.vue +53 -0
- package/app/components/CmsFieldMedia.vue +219 -0
- package/app/components/CmsFieldNumber.vue +11 -0
- package/app/components/CmsFieldRelationMany.vue +54 -0
- package/app/components/CmsFieldRelationOne.vue +47 -0
- package/app/components/CmsFieldRichText.vue +45 -0
- package/app/components/CmsFieldSelect.vue +41 -0
- package/app/components/CmsFieldSlug.vue +46 -0
- package/app/components/CmsFieldText.vue +75 -0
- package/app/components/CmsFormSections.vue +150 -0
- package/app/components/CmsHighlight.vue +22 -0
- package/app/components/CmsImage.vue +39 -0
- package/app/components/CmsLinkPicker.vue +122 -0
- package/app/components/CmsLinkTarget.vue +35 -0
- package/app/components/CmsListFilters.vue +107 -0
- package/app/components/CmsLiveNotice.vue +64 -0
- package/app/components/CmsLoadError.vue +24 -0
- package/app/components/CmsMascot.vue +10 -0
- package/app/components/CmsMediaLibrary.vue +114 -0
- package/app/components/CmsMediaPreview.vue +34 -0
- package/app/components/CmsMediaThumb.vue +22 -0
- package/app/components/CmsMoment.vue +42 -0
- package/app/components/CmsNav.vue +39 -0
- package/app/components/CmsPage.vue +86 -0
- package/app/components/CmsPasswordInput.vue +22 -0
- package/app/components/CmsPresence.vue +29 -0
- package/app/components/CmsPreviewPanel.vue +131 -0
- package/app/components/CmsPublishReview.vue +102 -0
- package/app/components/CmsRevisions.vue +195 -0
- package/app/components/CmsRichTextEditor.vue +290 -0
- package/app/components/CmsSearch.vue +99 -0
- package/app/components/CmsSection.vue +20 -0
- package/app/components/CmsSingletonForm.vue +283 -0
- package/app/components/CmsStatusBadge.vue +21 -0
- package/app/components/CmsTime.vue +16 -0
- package/app/components/CmsTranslationRef.vue +27 -0
- package/app/components/CmsTreeList.vue +453 -0
- package/app/components/CmsUnsavedText.vue +34 -0
- package/app/components/CmsWordmark.vue +10 -0
- package/app/composables/useCmsAdminHead.ts +18 -0
- package/app/composables/useCmsCollab.ts +165 -0
- package/app/composables/useCmsConfirm.ts +39 -0
- package/app/composables/useCmsEntryActions.ts +75 -0
- package/app/composables/useCmsFocus.ts +13 -0
- package/app/composables/useCmsForm.ts +273 -0
- package/app/composables/useCmsI18n.ts +185 -0
- package/app/composables/useCmsLinkTargets.ts +84 -0
- package/app/composables/useCmsLive.ts +199 -0
- package/app/composables/useCmsSearch.ts +62 -0
- package/app/composables/useCmsSeo.ts +99 -0
- package/app/composables/useCmsSignedIn.ts +24 -0
- package/app/composables/useCmsUiLocale.ts +24 -0
- package/app/i18n/cs.ts +781 -0
- package/app/i18n/de.ts +781 -0
- package/app/i18n/en.ts +782 -0
- package/app/i18n/types.ts +22 -0
- package/app/layouts/admin.vue +224 -0
- package/app/layouts/cms-auth.vue +37 -0
- package/app/middleware/cms-api-not-a-page.global.ts +10 -0
- package/app/middleware/cms-auth.global.ts +16 -0
- package/app/pages/admin/[entity]/[id].vue +1109 -0
- package/app/pages/admin/[entity]/index.vue +733 -0
- package/app/pages/admin/account.vue +117 -0
- package/app/pages/admin/forgot.vue +50 -0
- package/app/pages/admin/index.vue +184 -0
- package/app/pages/admin/invite/[token].vue +73 -0
- package/app/pages/admin/login.vue +84 -0
- package/app/pages/admin/media.vue +494 -0
- package/app/pages/admin/privacy.vue +193 -0
- package/app/pages/admin/reset/[token].vue +52 -0
- package/app/pages/admin/setup.vue +87 -0
- package/app/pages/admin/styleguide.vue +261 -0
- package/app/pages/admin/team.vue +258 -0
- package/app/plugins/cmsLivePreview.client.ts +20 -0
- package/app/plugins/cmsSignedOut.client.ts +31 -0
- package/app/utils/cmsBlockType.ts +11 -0
- package/app/utils/cmsBrand.ts +38 -0
- package/app/utils/cmsDiff.ts +83 -0
- package/app/utils/cmsFetch.ts +7 -0
- package/app/utils/cmsFocusInvalid.ts +22 -0
- package/app/utils/cmsIssues.ts +128 -0
- package/app/utils/cmsJson.ts +28 -0
- package/app/utils/cmsMedia.ts +63 -0
- package/app/utils/cmsSections.ts +154 -0
- package/app/utils/cmsTime.ts +41 -0
- package/cli/backup.ts +713 -0
- package/cli/breaking.ts +174 -0
- package/cli/content-migrate.ts +239 -0
- package/cli/db.ts +86 -0
- package/cli/export.ts +336 -0
- package/cli/generate.ts +146 -0
- package/cli/import.ts +643 -0
- package/cli/index.ts +140 -0
- package/cli/links-convert.ts +291 -0
- package/cli/seed-engine.ts +705 -0
- package/cli/seed.ts +339 -0
- package/cli/status.ts +49 -0
- package/cli/tar.ts +304 -0
- package/cli/transfer.ts +677 -0
- package/cli/up.ts +27 -0
- package/cli/upgrade.ts +60 -0
- package/cli/versions.ts +60 -0
- package/forms/components/CmsForm.vue +186 -0
- package/forms/index.ts +203 -0
- package/forms/messages.ts +104 -0
- package/forms/retention.ts +48 -0
- package/forms/server/form.get.ts +12 -0
- package/forms/server/form.post.ts +109 -0
- package/forms/server/formSettings.ts +12 -0
- package/forms/server/forms.ts +127 -0
- package/module.ts +373 -0
- package/nuxt.config.ts +43 -0
- package/package.json +98 -3
- package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
- package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
- package/server/api/cms/[entity]/[id].delete.ts +52 -0
- package/server/api/cms/[entity]/[id].get.ts +21 -0
- package/server/api/cms/[entity]/[id].patch.ts +116 -0
- package/server/api/cms/[entity]/_export.get.ts +69 -0
- package/server/api/cms/[entity]/_move.post.ts +81 -0
- package/server/api/cms/[entity]/_order.post.ts +49 -0
- package/server/api/cms/[entity]/_tree.get.ts +41 -0
- package/server/api/cms/[entity]/index.get.ts +62 -0
- package/server/api/cms/[entity]/index.post.ts +38 -0
- package/server/api/cms/[entity]/options.get.ts +55 -0
- package/server/api/cms/_auth/accept.post.ts +33 -0
- package/server/api/cms/_auth/forgot.post.ts +39 -0
- package/server/api/cms/_auth/invite/[token].get.ts +18 -0
- package/server/api/cms/_auth/login.post.ts +42 -0
- package/server/api/cms/_auth/logout.post.ts +7 -0
- package/server/api/cms/_auth/me.get.ts +5 -0
- package/server/api/cms/_auth/me.patch.ts +32 -0
- package/server/api/cms/_auth/password.post.ts +29 -0
- package/server/api/cms/_auth/reset.post.ts +34 -0
- package/server/api/cms/_auth/setup.post.ts +46 -0
- package/server/api/cms/_auth/status.get.ts +18 -0
- package/server/api/cms/_collab/session.get.ts +30 -0
- package/server/api/cms/_collab/socket.ts +51 -0
- package/server/api/cms/_collab/unsaved.delete.ts +16 -0
- package/server/api/cms/_graph.get.ts +20 -0
- package/server/api/cms/_links/resolve.post.ts +17 -0
- package/server/api/cms/_links.get.ts +81 -0
- package/server/api/cms/_live.ts +30 -0
- package/server/api/cms/_media/[id]/usage.get.ts +14 -0
- package/server/api/cms/_media/[id].delete.ts +29 -0
- package/server/api/cms/_media/[id].get.ts +13 -0
- package/server/api/cms/_media/[id].patch.ts +64 -0
- package/server/api/cms/_media/exists.post.ts +15 -0
- package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
- package/server/api/cms/_media/index.get.ts +44 -0
- package/server/api/cms/_media/index.post.ts +147 -0
- package/server/api/cms/_media/raw/[...key].get.ts +85 -0
- package/server/api/cms/_media/raw/[...key].head.ts +2 -0
- package/server/api/cms/_overview.get.ts +87 -0
- package/server/api/cms/_preview.post.ts +17 -0
- package/server/api/cms/_privacy/delete.post.ts +14 -0
- package/server/api/cms/_privacy/export.post.ts +25 -0
- package/server/api/cms/_privacy/lookup.post.ts +27 -0
- package/server/api/cms/_search.get.ts +17 -0
- package/server/api/cms/_singleton/[name].get.ts +19 -0
- package/server/api/cms/_singleton/[name].put.ts +76 -0
- package/server/api/cms/_users/[id]/resend.post.ts +25 -0
- package/server/api/cms/_users/[id].delete.ts +21 -0
- package/server/api/cms/_users/[id].patch.ts +45 -0
- package/server/api/cms/_users/index.get.ts +28 -0
- package/server/api/cms/_users/index.post.ts +39 -0
- package/server/api/content/[entity]/[slug].get.ts +74 -0
- package/server/api/content/[entity]/index.get.ts +100 -0
- package/server/api/content/_global/[name].get.ts +23 -0
- package/server/api/content/_search.get.ts +28 -0
- package/server/api/content/_sitemap.get.ts +8 -0
- package/server/api/content/_tree/[entity].get.ts +31 -0
- package/server/api/content-types.ts.get.ts +17 -0
- package/server/api/health/live.get.ts +10 -0
- package/server/api/health/ready.get.ts +21 -0
- package/server/api/openapi.get.ts +48 -0
- package/server/api/openapi.json.get.ts +32 -0
- package/server/db/driver.ts +8 -0
- package/server/mail/mailer.ts +43 -0
- package/server/middleware/cms-0-headers.ts +37 -0
- package/server/middleware/cms-0-migrate-gate.ts +14 -0
- package/server/middleware/cms-csrf.ts +28 -0
- package/server/middleware/cms-limits.ts +20 -0
- package/server/middleware/cms-redirects.ts +21 -0
- package/server/middleware/cms-session.ts +41 -0
- package/server/middleware/cms-z-plugin-access.ts +15 -0
- package/server/plugins/cms-0-config-check.ts +35 -0
- package/server/plugins/cms-changes.ts +53 -0
- package/server/plugins/cms-content-etag.ts +21 -0
- package/server/plugins/cms-errors.ts +45 -0
- package/server/plugins/cms-migrate.ts +5 -0
- package/server/plugins/cms-plugins.ts +17 -0
- package/server/plugins/cms-search.ts +12 -0
- package/server/plugins/cms-setup-code.ts +15 -0
- package/server/routes/sitemap.xml.get.ts +25 -0
- package/server/store/redis.ts +95 -0
- package/server/store/types.ts +21 -0
- package/server/tasks/cms/retention.ts +10 -0
- package/server/tasks/cms/scheduled.ts +10 -0
- package/server/tasks/cms/search-reindex.ts +12 -0
- package/server/utils/cmsAudit.ts +29 -0
- package/server/utils/cmsAuth.ts +143 -0
- package/server/utils/cmsBlocks.ts +47 -0
- package/server/utils/cmsChanges.ts +222 -0
- package/server/utils/cmsCollab.ts +286 -0
- package/server/utils/cmsCollabServer.ts +451 -0
- package/server/utils/cmsCollate.ts +27 -0
- package/server/utils/cmsContent.ts +376 -0
- package/server/utils/cmsCrud.ts +361 -0
- package/server/utils/cmsCsv.ts +24 -0
- package/server/utils/cmsDb.ts +23 -0
- package/server/utils/cmsDemo.ts +36 -0
- package/server/utils/cmsEmails.ts +125 -0
- package/server/utils/cmsErrors.ts +40 -0
- package/server/utils/cmsFold.ts +17 -0
- package/server/utils/cmsImageSizes.ts +51 -0
- package/server/utils/cmsJson.ts +6 -0
- package/server/utils/cmsLinkAddress.ts +50 -0
- package/server/utils/cmsLinks.ts +248 -0
- package/server/utils/cmsListQuery.ts +93 -0
- package/server/utils/cmsLive.ts +393 -0
- package/server/utils/cmsLocales.ts +96 -0
- package/server/utils/cmsMail.ts +28 -0
- package/server/utils/cmsMediaGc.ts +188 -0
- package/server/utils/cmsMediaKeys.ts +62 -0
- package/server/utils/cmsMigrate.ts +86 -0
- package/server/utils/cmsPreviewDraft.ts +72 -0
- package/server/utils/cmsPrivacy.ts +176 -0
- package/server/utils/cmsPublished.ts +57 -0
- package/server/utils/cmsRange.ts +38 -0
- package/server/utils/cmsRateLimit.ts +82 -0
- package/server/utils/cmsRedirects.ts +160 -0
- package/server/utils/cmsRetention.ts +61 -0
- package/server/utils/cmsRevisions.ts +103 -0
- package/server/utils/cmsScheduler.ts +45 -0
- package/server/utils/cmsScrub.ts +107 -0
- package/server/utils/cmsSearch.ts +354 -0
- package/server/utils/cmsSession.ts +102 -0
- package/server/utils/cmsSetupCode.ts +97 -0
- package/server/utils/cmsSitemap.ts +176 -0
- package/server/utils/cmsStorage.ts +580 -0
- package/server/utils/cmsStore.ts +109 -0
- package/server/utils/cmsTiming.ts +14 -0
- package/server/utils/cmsTooMany.ts +9 -0
- package/server/utils/cmsTranslationWrite.ts +186 -0
- package/server/utils/cmsTree.ts +251 -0
- package/server/utils/cmsTreeAddress.ts +65 -0
- package/server/utils/cmsUpload.ts +228 -0
- package/server/utils/cmsWebhooks.ts +104 -0
- package/shared/json.ts +11 -0
- package/shared/richtext-editor.ts +56 -0
- package/shared/richtext-normalize.ts +33 -0
- package/shared/richtext-paste.ts +151 -0
- package/shared/storage-delivery.ts +53 -0
- package/src/blocks.ts +624 -0
- package/src/changes.ts +54 -0
- package/src/content-shape.ts +340 -0
- package/src/deprecate.ts +64 -0
- package/src/descriptor.ts +149 -0
- package/src/docs.ts +27 -0
- package/src/emitter.ts +94 -0
- package/src/entity.ts +624 -0
- package/src/errorReport.ts +41 -0
- package/src/fields.ts +465 -0
- package/src/i18n.ts +26 -0
- package/src/index.ts +54 -0
- package/src/linkref.ts +31 -0
- package/src/links.ts +179 -0
- package/src/locales.ts +39 -0
- package/src/media.ts +48 -0
- package/src/migrate.ts +236 -0
- package/src/openapi.ts +377 -0
- package/src/paths.ts +88 -0
- package/src/plugin.ts +505 -0
- package/src/presets.ts +230 -0
- package/src/richtext.ts +88 -0
- package/src/sdk.ts +181 -0
- package/src/search.ts +312 -0
- package/src/seed.ts +225 -0
- package/src/setupCode.ts +30 -0
- package/src/system.ts +219 -0
- package/src/tree.ts +421 -0
- package/src/upgrades.ts +137 -0
- package/starter/.env.example +10 -0
- package/starter/README.md +65 -0
- package/starter/app/app.config.ts +10 -0
- package/starter/app/app.vue +12 -0
- package/starter/app/assets/css/main.css +15 -0
- package/starter/app/components/global/BlockContact.vue +15 -0
- package/starter/app/components/global/BlockCta.vue +15 -0
- package/starter/app/components/global/BlockHero.vue +23 -0
- package/starter/app/components/global/BlockImage.vue +13 -0
- package/starter/app/components/global/BlockText.vue +12 -0
- package/starter/app/composables/useSite.ts +77 -0
- package/starter/app/error.vue +28 -0
- package/starter/app/layouts/default.vue +106 -0
- package/starter/app/lib/cms-content.ts +152 -0
- package/starter/app/pages/[...slug].vue +66 -0
- package/starter/app/pages/hledat.vue +59 -0
- package/starter/app/pages/index.vue +20 -0
- package/starter/cms.config.ts +137 -0
- package/starter/compose.yaml +15 -0
- package/starter/drizzle.config.ts +8 -0
- package/starter/gitignore.txt +8 -0
- package/starter/nuxt.config.ts +13 -0
- package/starter/package.json +38 -0
- package/starter/scripts/typecheck.mjs +38 -0
- package/starter/seed/index.ts +297 -0
- package/starter/seed/media/about.jpg +0 -0
- package/starter/seed/media/hero.jpg +0 -0
- package/starter/seed/media/logo.png +0 -0
- package/starter/seed/media/news-bread.jpg +0 -0
- package/starter/seed/media/news-morning.jpg +0 -0
- package/starter/server/db/migrations/0000_init.sql +269 -0
- package/starter/server/db/migrations/0001_page_tree.sql +5 -0
- package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
- package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
- package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
- package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
- package/starter/server/db/migrations/meta/_journal.json +27 -0
- package/starter/server/db/schema.ts +253 -0
- package/starter/server/plugins/sitemap.ts +11 -0
- package/starter/server/routes/robots.txt.get.ts +12 -0
- package/starter/tsconfig.json +9 -0
package/module.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { dirname, resolve } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { addComponentsDir, addServerHandler, addServerPlugin, addTypeTemplate, defineNuxtModule, extendPages } from '@nuxt/kit'
|
|
5
|
+
import { createJiti } from 'jiti'
|
|
6
|
+
import { collectPlugins, planPlugins, type CmsPlugin } from './src/plugin'
|
|
7
|
+
|
|
8
|
+
const layerDir = dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
|
|
10
|
+
export interface CmsModuleOptions {
|
|
11
|
+
/** Path to the host config, relative to rootDir. Default: 'cms.config.ts'. */
|
|
12
|
+
config?: string
|
|
13
|
+
/**
|
|
14
|
+
* Postgres connection string. Leave it out in production: the server reads
|
|
15
|
+
* NUXT_CMS_DATABASE_URL or DATABASE_URL at runtime, which win over this value.
|
|
16
|
+
*/
|
|
17
|
+
databaseUrl?: string
|
|
18
|
+
/** Blob storage for uploaded media. Defaults to the local filesystem driver. */
|
|
19
|
+
storage?: {
|
|
20
|
+
/** 'local' (default) writes to disk; 's3'/'r2' use an S3-compatible store. */
|
|
21
|
+
driver?: 'local' | 's3' | 'r2'
|
|
22
|
+
local?: {
|
|
23
|
+
/** Upload dir, resolved against the runtime cwd. Default '.cms-uploads'. */
|
|
24
|
+
dir?: string
|
|
25
|
+
/** URL base the local serving route is mounted at. */
|
|
26
|
+
publicBase?: string
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* S3-compatible object store (AWS S3 / Cloudflare R2 / MinIO). Secrets are
|
|
30
|
+
* server-only; prefer NUXT_CMS_STORAGE_S3_* env vars over committing them.
|
|
31
|
+
*/
|
|
32
|
+
s3?: {
|
|
33
|
+
endpoint?: string
|
|
34
|
+
region?: string
|
|
35
|
+
bucket?: string
|
|
36
|
+
accessKeyId?: string
|
|
37
|
+
secretAccessKey?: string
|
|
38
|
+
/** Public URL prefix for serving (CDN / r2.dev / custom domain). */
|
|
39
|
+
publicBaseUrl?: string
|
|
40
|
+
/**
|
|
41
|
+
* How browsers get the files. `'public'`: straight from a public bucket or CDN
|
|
42
|
+
* (the stored address is the bucket's). `'proxy'`: for a private bucket — the app
|
|
43
|
+
* streams each file (`/api/cms/_media/raw/<key>`, with byte ranges). `'redirect'`:
|
|
44
|
+
* private bucket, the app answers with a five-minute signed address; the stored
|
|
45
|
+
* address is the same app path, so it never expires. Default: `'public'` when
|
|
46
|
+
* `publicBaseUrl` is set, otherwise `'proxy'`. Env: NUXT_CMS_STORAGE_S3_DELIVERY.
|
|
47
|
+
*/
|
|
48
|
+
delivery?: 'public' | 'proxy' | 'redirect'
|
|
49
|
+
}
|
|
50
|
+
/** Max upload size in MB (per file). Default 10. */
|
|
51
|
+
maxSizeMb?: number
|
|
52
|
+
/** Per-user total storage quota in bytes. 0 = unlimited (default). */
|
|
53
|
+
maxBytesPerUser?: number
|
|
54
|
+
/** Max uploads per user per minute. 0 = unlimited. Default 60. */
|
|
55
|
+
uploadRatePerMin?: number
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Who owns sign-in. 'builtin' (default): the CMS has its own users, invites,
|
|
59
|
+
* password resets and roles. 'external': the host signs people in and sets
|
|
60
|
+
* `event.context.cmsUser` itself (e.g. SSO); the CMS's auth pages and team
|
|
61
|
+
* management are switched off.
|
|
62
|
+
*/
|
|
63
|
+
auth?: {
|
|
64
|
+
mode?: 'builtin' | 'external'
|
|
65
|
+
/**
|
|
66
|
+
* Proxies in front of the app that append to X-Forwarded-For (default 1 — one
|
|
67
|
+
* ingress/load balancer). The client IP for rate limits is read that many hops
|
|
68
|
+
* from the end, so a client cannot choose it. 0 = use the socket address.
|
|
69
|
+
*/
|
|
70
|
+
trustedProxies?: number
|
|
71
|
+
/** Header holding the client IP when a trusted edge sets one, e.g. 'cf-connecting-ip'. */
|
|
72
|
+
ipHeader?: string
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Absolute public URL of this app, e.g. 'https://cms.example.com'. Used for links
|
|
76
|
+
* in emails (invites, password resets) — required in production. Env: NUXT_CMS_PUBLIC_URL.
|
|
77
|
+
*/
|
|
78
|
+
publicUrl?: string
|
|
79
|
+
/**
|
|
80
|
+
* Outgoing email (invites, password resets).
|
|
81
|
+
* - 'log' (default): print to the server log
|
|
82
|
+
* - 'file': write each email as JSON into `file.dir` (local development, tests)
|
|
83
|
+
* - 'smtp': any SMTP server (Node runtime only)
|
|
84
|
+
* Env: NUXT_CMS_MAIL_TRANSPORT, NUXT_CMS_MAIL_FROM, NUXT_CMS_MAIL_SMTP_HOST, …
|
|
85
|
+
*/
|
|
86
|
+
mail?: {
|
|
87
|
+
transport?: 'log' | 'file' | 'smtp'
|
|
88
|
+
from?: string
|
|
89
|
+
smtp?: { host?: string; port?: number; secure?: boolean; user?: string; pass?: string }
|
|
90
|
+
file?: { dir?: string }
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Redis for state shared by all instances (rate limits, realtime). Defaults to the
|
|
94
|
+
* REDIS_URL environment variable (Pushbase sets it for a linked Redis service).
|
|
95
|
+
* Env: NUXT_CMS_REDIS_URL. Without it, state lives in each instance's memory.
|
|
96
|
+
* `prefix` (NUXT_CMS_REDIS_PREFIX) namespaces keys and channels; default
|
|
97
|
+
* `cms:<database name>`, so environments sharing one Redis stay apart.
|
|
98
|
+
*/
|
|
99
|
+
redis?: { url?: string; prefix?: string }
|
|
100
|
+
/**
|
|
101
|
+
* How often scheduled entries are checked for going live (a cron expression; build
|
|
102
|
+
* time, env CMS_SCHEDULER_CRON). Their content is live on time regardless — this
|
|
103
|
+
* only sends the webhooks and live updates for that moment. Default every minute.
|
|
104
|
+
*/
|
|
105
|
+
scheduler?: { cron?: string }
|
|
106
|
+
/**
|
|
107
|
+
* How long personal data is kept (GDPR). A daily scheduled task enforces it.
|
|
108
|
+
* - auditDays: delete audit-log entries older than this (default 365, 0 = keep forever).
|
|
109
|
+
* Env NUXT_CMS_RETENTION_AUDIT_DAYS.
|
|
110
|
+
* Form submissions have their own: `defineForm(name, { retentionDays })`.
|
|
111
|
+
* The task runs daily (build-time cron: env CMS_RETENTION_CRON, default '17 3 * * *').
|
|
112
|
+
*/
|
|
113
|
+
retention?: { auditDays?: number }
|
|
114
|
+
/** Revisions (history, compare, restore): how many to keep per entry and language. 0 = off. */
|
|
115
|
+
revisions?: { keep?: number }
|
|
116
|
+
/**
|
|
117
|
+
* Publish webhooks: every change visible on the website is POSTed, signed, to these
|
|
118
|
+
* URLs (e.g. the site's cache-purge endpoint). See server/utils/cmsWebhooks.ts.
|
|
119
|
+
* Env: NUXT_CMS_WEBHOOKS_URLS (comma separated), NUXT_CMS_WEBHOOKS_SECRET.
|
|
120
|
+
*/
|
|
121
|
+
webhooks?: { urls?: string | string[]; secret?: string }
|
|
122
|
+
/**
|
|
123
|
+
* Addresses on the website that are not entries (the news list, the contact page) so
|
|
124
|
+
* they belong in /sitemap.xml: full addresses (language prefix included), or one object
|
|
125
|
+
* per page with its address in each language, which makes them hreflang alternates:
|
|
126
|
+
*
|
|
127
|
+
* sitemap: { paths: ['/kontakt', { cs: '/aktuality', en: '/en/news' }] }
|
|
128
|
+
*
|
|
129
|
+
* For addresses that come from data, use the `cms:sitemap` Nitro hook instead (it can
|
|
130
|
+
* push entries). Both end up in /sitemap.xml and /api/content/_sitemap.
|
|
131
|
+
*/
|
|
132
|
+
sitemap?: { paths?: (string | Record<string, string>)[] }
|
|
133
|
+
/**
|
|
134
|
+
* Website forms (defineForm):
|
|
135
|
+
* - notifyTo: fallback recipients of new submissions, comma separated (env NUXT_CMS_FORMS_NOTIFY_TO)
|
|
136
|
+
* - turnstileSecret: Cloudflare Turnstile secret; when set, every submission must
|
|
137
|
+
* pass it (env NUXT_CMS_FORMS_TURNSTILE_SECRET). The site key goes to
|
|
138
|
+
* `public.cmsTurnstileSiteKey` (env NUXT_PUBLIC_CMS_TURNSTILE_SITE_KEY).
|
|
139
|
+
*/
|
|
140
|
+
forms?: { notifyTo?: string; turnstileSecret?: string; turnstileSiteKey?: string }
|
|
141
|
+
/**
|
|
142
|
+
* A public demo admin: the sign-in page shows these details, the account is created
|
|
143
|
+
* (as an editor) the first time someone signs in with them, and it cannot change
|
|
144
|
+
* its name or password or ask for a reset link. Both are public on purpose
|
|
145
|
+
* (env NUXT_PUBLIC_CMS_DEMO_EMAIL, NUXT_PUBLIC_CMS_DEMO_PASSWORD). Leave empty on
|
|
146
|
+
* real sites.
|
|
147
|
+
*/
|
|
148
|
+
demo?: { email?: string; password?: string }
|
|
149
|
+
/**
|
|
150
|
+
* Database migrations bundled into the server build and applied when it starts —
|
|
151
|
+
* for platforms that ship only the build output (Pushbase, containers).
|
|
152
|
+
* - dir: the drizzle-kit migrations folder, relative to rootDir (default server/db/migrations)
|
|
153
|
+
* - onStart: apply them at start (env NUXT_CMS_MIGRATIONS_ON_START=true). Default off.
|
|
154
|
+
*/
|
|
155
|
+
migrations?: { dir?: string; onStart?: boolean }
|
|
156
|
+
/** Public content-delivery API (`/api/content/*`). */
|
|
157
|
+
content?: {
|
|
158
|
+
/** If set, every content request must carry this token (x-api-key or Bearer). Default: open. */
|
|
159
|
+
token?: string
|
|
160
|
+
/** Cache-Control header for content responses when open. */
|
|
161
|
+
cacheControl?: string
|
|
162
|
+
/**
|
|
163
|
+
* Absolute public origin of this CMS (e.g. 'https://cms.example.com'), used as the
|
|
164
|
+
* OpenAPI `servers[].url`. Left blank, the spec uses a relative '/' server — never
|
|
165
|
+
* the request Host (which is attacker-controlled and would poison the cached spec).
|
|
166
|
+
*/
|
|
167
|
+
publicUrl?: string
|
|
168
|
+
/**
|
|
169
|
+
* The interactive API reference at `/api/openapi` (Scalar, loaded from a CDN, public
|
|
170
|
+
* on the admin's origin). Default: on in development, off in production; set `true`
|
|
171
|
+
* (env NUXT_CMS_CONTENT_DOCS=true) to publish it. `/api/openapi.json` is not affected.
|
|
172
|
+
*/
|
|
173
|
+
docs?: boolean
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The plugins of the host's `cms.config.ts` (`export const plugins = [...]`, plus the
|
|
179
|
+
* ones an entity registers by itself, see `collectPlugins`). The config is read at build
|
|
180
|
+
* time with jiti, exactly as the CLI reads it, because the admin pages, server routes
|
|
181
|
+
* and components a plugin brings have to be registered before the build starts.
|
|
182
|
+
*/
|
|
183
|
+
async function loadPlugins(configPath: string, alias: Record<string, string>): Promise<CmsPlugin[]> {
|
|
184
|
+
if (!existsSync(configPath)) return []
|
|
185
|
+
try {
|
|
186
|
+
const jiti = createJiti(configPath, { alias, interopDefault: true, moduleCache: false, fsCache: false })
|
|
187
|
+
return collectPlugins(await jiti.import<Record<string, any>>(configPath))
|
|
188
|
+
}
|
|
189
|
+
catch (err: any) {
|
|
190
|
+
throw new Error(`[tinyzoo] could not read the plugins from ${configPath}: ${err?.message ?? err}`, { cause: err })
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** `cms.sitemap.paths` checked at build time: each is an address starting with one "/" (or a map of them per language). */
|
|
195
|
+
function sitemapPaths(paths: (string | Record<string, string>)[] | undefined): (string | Record<string, string>)[] {
|
|
196
|
+
const ok = (p: unknown) => typeof p === 'string' && /^\/(?!\/)[^\s?#]*$/.test(p)
|
|
197
|
+
for (const p of paths ?? []) {
|
|
198
|
+
const all = typeof p === 'string' ? [p] : Object.values(p ?? {})
|
|
199
|
+
if (!all.length || !all.every(ok)) throw new Error(`[tinyzoo] sitemap.paths: ${JSON.stringify(p)} must be an address starting with "/" (no query or fragment), or an object of them per language.`)
|
|
200
|
+
}
|
|
201
|
+
return paths ?? []
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export default defineNuxtModule<CmsModuleOptions>({
|
|
205
|
+
meta: { name: 'tinyzoo', configKey: 'cms' },
|
|
206
|
+
defaults: { config: 'cms.config.ts' },
|
|
207
|
+
async setup(options, nuxt) {
|
|
208
|
+
const configPath = resolve(nuxt.options.rootDir, options.config || 'cms.config.ts')
|
|
209
|
+
if (!existsSync(configPath)) {
|
|
210
|
+
console.warn(`[tinyzoo] No cms.config.ts found at ${configPath}. Create one with defineEntity().`)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Expose the host config as a virtual alias to app and Nitro server.
|
|
214
|
+
nuxt.options.alias['#cms/config'] = configPath
|
|
215
|
+
// Bundle the host's migrations as server assets so they ship with .output.
|
|
216
|
+
const migrationsDir = resolve(nuxt.options.rootDir, options.migrations?.dir || 'server/db/migrations')
|
|
217
|
+
nuxt.hook('nitro:config', (nitro) => {
|
|
218
|
+
// nuxt-auth-utils adds a Nitro plugin when WebSockets are on (the admin's live socket
|
|
219
|
+
// is one) that reads the session on EVERY request: for a visitor without one that
|
|
220
|
+
// *creates* it and sets a cookie on every response, public pages, content API and
|
|
221
|
+
// media included, so no CDN caches them. The admin socket checks the session itself
|
|
222
|
+
// (admitAdminSocket) and only when the request carries one, so that plugin goes.
|
|
223
|
+
if (Array.isArray(nitro.plugins)) {
|
|
224
|
+
nitro.plugins = nitro.plugins.filter((p) => !/nuxt-auth-utils[\\/]dist[\\/]runtime[\\/]server[\\/]plugins[\\/]ws(\.|$)/.test(String(p)))
|
|
225
|
+
}
|
|
226
|
+
if (existsSync(migrationsDir)) {
|
|
227
|
+
nitro.serverAssets = nitro.serverAssets || []
|
|
228
|
+
nitro.serverAssets.push({ baseName: 'cms-migrations', dir: migrationsDir })
|
|
229
|
+
}
|
|
230
|
+
// Scheduled publishing: announce entries whose publish time has come.
|
|
231
|
+
nitro.experimental = { ...(nitro.experimental || {}), tasks: true }
|
|
232
|
+
const cron = options.scheduler?.cron || process.env.CMS_SCHEDULER_CRON || '* * * * *'
|
|
233
|
+
nitro.scheduledTasks = { ...(nitro.scheduledTasks || {}), [cron]: [...((nitro.scheduledTasks as any)?.[cron] ?? []), 'cms:scheduled'] }
|
|
234
|
+
// Retention (GDPR): delete form submissions and audit entries past their time, daily.
|
|
235
|
+
const retentionCron = process.env.CMS_RETENTION_CRON || '17 3 * * *'
|
|
236
|
+
nitro.scheduledTasks = { ...nitro.scheduledTasks, [retentionCron]: [...((nitro.scheduledTasks as any)?.[retentionCron] ?? []), 'cms:retention'] }
|
|
237
|
+
nitro.alias = nitro.alias || {}
|
|
238
|
+
nitro.alias['#cms/config'] = configPath
|
|
239
|
+
nitro.externals = nitro.externals || {}
|
|
240
|
+
nitro.externals.inline = nitro.externals.inline || []
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
// The session shape the built-in sign-in stores (nuxt-auth-utils' User/UserSession),
|
|
244
|
+
// so hosts get `useUserSession().user.value.role` typed without declaring it.
|
|
245
|
+
addTypeTemplate({
|
|
246
|
+
filename: 'types/cms-auth.d.ts',
|
|
247
|
+
getContents: () => `declare module '#auth-utils' {
|
|
248
|
+
interface User {
|
|
249
|
+
id: string
|
|
250
|
+
email: string
|
|
251
|
+
name: string
|
|
252
|
+
role: 'admin' | 'editor' | 'author' | (string & {})
|
|
253
|
+
locale: string | null
|
|
254
|
+
}
|
|
255
|
+
interface UserSession {
|
|
256
|
+
cms?: { uid: string; sv: number }
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
declare module 'nitropack/types' {
|
|
260
|
+
interface NitroRuntimeHooks {
|
|
261
|
+
/** A content change was saved (see CmsChange). Runs on the instance that saved it. */
|
|
262
|
+
'cms:change': (change: import('tinyzoo').CmsChange) => void | Promise<void>
|
|
263
|
+
/** The sitemap is being built: push entries for addresses that are not entries (see CmsSitemapEntry). Runs at most once a minute. */
|
|
264
|
+
'cms:sitemap': (entries: import('tinyzoo').CmsSitemapEntry[]) => void | Promise<void>
|
|
265
|
+
/** A server error (5xx request, failed scheduled task, webhook that gave up), after the response. See CmsErrorReport. */
|
|
266
|
+
'cms:error': (report: import('tinyzoo').CmsErrorReport) => void | Promise<void>
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export {}
|
|
270
|
+
`,
|
|
271
|
+
}, { nitro: true, nuxt: true })
|
|
272
|
+
|
|
273
|
+
// Plugins (defineCmsPlugin): their admin pages, server routes, Nitro plugins, components,
|
|
274
|
+
// field renderers and admin texts, registered here; their entities, hooks and upgrade
|
|
275
|
+
// steps reach the server through the registry (src/entity.ts, buildRegistry).
|
|
276
|
+
const plugins = await loadPlugins(configPath, nuxt.options.alias as Record<string, string>)
|
|
277
|
+
const plan = planPlugins(plugins, { exists: existsSync })
|
|
278
|
+
if (plan.pages.length) {
|
|
279
|
+
extendPages((pages) => {
|
|
280
|
+
for (const page of plan.pages) pages.push({ name: page.name, path: page.path, file: page.file })
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
for (const h of plan.handlers) addServerHandler({ method: h.method, route: h.route, handler: h.handler })
|
|
284
|
+
for (const file of plan.serverPlugins) addServerPlugin(file)
|
|
285
|
+
for (const path of plan.componentDirs) addComponentsDir({ path, pathPrefix: false, global: true })
|
|
286
|
+
// What the admin needs to know about plugins: the sidebar entries, the field renderers and
|
|
287
|
+
// the texts (public runtime config: nothing secret in it).
|
|
288
|
+
nuxt.options.runtimeConfig.public.cmsPlugins = {
|
|
289
|
+
plugins: plan.plugins,
|
|
290
|
+
navItems: plan.navItems,
|
|
291
|
+
fields: plan.fields,
|
|
292
|
+
messages: plan.messages,
|
|
293
|
+
} as any
|
|
294
|
+
// Runtime config consumed by the server DataSource (env override: NUXT_CMS_DATABASE_URL).
|
|
295
|
+
nuxt.options.runtimeConfig.cms = {
|
|
296
|
+
// Never read DATABASE_URL here: this runs at BUILD time and would bake the build
|
|
297
|
+
// machine's database into the output. useCms() reads the env at runtime.
|
|
298
|
+
databaseUrl: options.databaseUrl || '',
|
|
299
|
+
migrations: { onStart: options.migrations?.onStart ?? false },
|
|
300
|
+
redis: { url: options.redis?.url || '', prefix: options.redis?.prefix || '' },
|
|
301
|
+
// Revisions kept per entry and language (0 = off). Env NUXT_CMS_REVISIONS_KEEP.
|
|
302
|
+
revisions: { keep: options.revisions?.keep ?? 50 },
|
|
303
|
+
// Audit entries older than this are deleted daily (0 = keep). Env NUXT_CMS_RETENTION_AUDIT_DAYS.
|
|
304
|
+
retention: { auditDays: options.retention?.auditDays ?? 365 },
|
|
305
|
+
// Empty defaults so NUXT_CMS_WEBHOOKS_URLS / NUXT_CMS_WEBHOOKS_SECRET bind at runtime.
|
|
306
|
+
webhooks: {
|
|
307
|
+
urls: (Array.isArray(options.webhooks?.urls) ? options.webhooks.urls.join(',') : options.webhooks?.urls) || '',
|
|
308
|
+
secret: options.webhooks?.secret || '',
|
|
309
|
+
},
|
|
310
|
+
sitemap: { paths: sitemapPaths(options.sitemap?.paths) },
|
|
311
|
+
auth: {
|
|
312
|
+
mode: options.auth?.mode || 'builtin',
|
|
313
|
+
trustedProxies: options.auth?.trustedProxies ?? 1,
|
|
314
|
+
ipHeader: options.auth?.ipHeader || '',
|
|
315
|
+
// Empty default so NUXT_CMS_AUTH_SETUP_TOKEN binds at runtime ('' = no token needed).
|
|
316
|
+
setupToken: '',
|
|
317
|
+
},
|
|
318
|
+
// Empty defaults so NUXT_CMS_PUBLIC_URL / NUXT_CMS_MAIL_* bind at runtime.
|
|
319
|
+
publicUrl: options.publicUrl || '',
|
|
320
|
+
mail: {
|
|
321
|
+
transport: options.mail?.transport || 'log',
|
|
322
|
+
from: options.mail?.from || '',
|
|
323
|
+
smtp: {
|
|
324
|
+
host: options.mail?.smtp?.host || '',
|
|
325
|
+
port: options.mail?.smtp?.port ?? 587,
|
|
326
|
+
secure: options.mail?.smtp?.secure ?? false,
|
|
327
|
+
user: options.mail?.smtp?.user || '',
|
|
328
|
+
pass: options.mail?.smtp?.pass || '',
|
|
329
|
+
},
|
|
330
|
+
file: { dir: options.mail?.file?.dir || '.cms-mail' },
|
|
331
|
+
},
|
|
332
|
+
storage: {
|
|
333
|
+
driver: options.storage?.driver || 'local',
|
|
334
|
+
local: {
|
|
335
|
+
dir: options.storage?.local?.dir || '.cms-uploads',
|
|
336
|
+
publicBase: options.storage?.local?.publicBase || '/api/cms/_media/raw',
|
|
337
|
+
},
|
|
338
|
+
// Empty-string defaults so NUXT_CMS_STORAGE_S3_* env vars bind at runtime.
|
|
339
|
+
s3: {
|
|
340
|
+
endpoint: options.storage?.s3?.endpoint || '',
|
|
341
|
+
region: options.storage?.s3?.region || '',
|
|
342
|
+
bucket: options.storage?.s3?.bucket || '',
|
|
343
|
+
accessKeyId: options.storage?.s3?.accessKeyId || '',
|
|
344
|
+
secretAccessKey: options.storage?.s3?.secretAccessKey || '',
|
|
345
|
+
publicBaseUrl: options.storage?.s3?.publicBaseUrl || '',
|
|
346
|
+
// '' = the default (public with a publicBaseUrl, otherwise proxy), resolved where it is used.
|
|
347
|
+
delivery: options.storage?.s3?.delivery || '',
|
|
348
|
+
},
|
|
349
|
+
maxSizeMb: options.storage?.maxSizeMb ?? 10,
|
|
350
|
+
maxBytesPerUser: options.storage?.maxBytesPerUser ?? 0,
|
|
351
|
+
uploadRatePerMin: options.storage?.uploadRatePerMin ?? 60,
|
|
352
|
+
},
|
|
353
|
+
// Empty defaults so NUXT_CMS_FORMS_* bind at runtime.
|
|
354
|
+
forms: {
|
|
355
|
+
notifyTo: options.forms?.notifyTo || '',
|
|
356
|
+
turnstileSecret: options.forms?.turnstileSecret || '',
|
|
357
|
+
},
|
|
358
|
+
content: {
|
|
359
|
+
// Empty so NUXT_CMS_CONTENT_TOKEN can bind at runtime; '' = open API.
|
|
360
|
+
token: options.content?.token || '',
|
|
361
|
+
cacheControl: options.content?.cacheControl || '',
|
|
362
|
+
publicUrl: options.content?.publicUrl || '',
|
|
363
|
+
// '' = the default (on in development, off in production); NUXT_CMS_CONTENT_DOCS binds at runtime (as a string, like every env value).
|
|
364
|
+
docs: options.content?.docs === undefined ? '' : String(options.content.docs),
|
|
365
|
+
},
|
|
366
|
+
...(nuxt.options.runtimeConfig.cms as Record<string, unknown> | undefined),
|
|
367
|
+
}
|
|
368
|
+
// The Turnstile site key is public (it goes into the website's form).
|
|
369
|
+
nuxt.options.runtimeConfig.public.cmsTurnstileSiteKey ||= options.forms?.turnstileSiteKey || ''
|
|
370
|
+
// The demo admin's sign-in details are public (they are printed on the sign-in page).
|
|
371
|
+
nuxt.options.runtimeConfig.public.cmsDemo ||= { email: options.demo?.email || '', password: options.demo?.password || '' }
|
|
372
|
+
},
|
|
373
|
+
})
|
package/nuxt.config.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
// tinyzoo — Nuxt Layer. Ships /admin pages, Cms* components, and the CMS
|
|
5
|
+
// server API. Its module (build-time brain) is registered below, so a host gets
|
|
6
|
+
// everything from a single `extends`.
|
|
7
|
+
// NB: resolve the module path from the LAYER dir, never a bare './module'
|
|
8
|
+
// (relative module paths in a layer resolve against the HOST root — the footgun).
|
|
9
|
+
const layerDir = dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
|
|
11
|
+
export default defineNuxtConfig({
|
|
12
|
+
modules: [join(layerDir, 'module')],
|
|
13
|
+
// Register the layer's components as GLOBAL so the field/cell registry can
|
|
14
|
+
// resolve them by name at runtime (resolveComponent only finds globals; plain
|
|
15
|
+
// auto-imports are compile-time only). pathPrefix:false keeps flat names.
|
|
16
|
+
components: [
|
|
17
|
+
{ path: join(layerDir, 'app/components'), pathPrefix: false, global: true },
|
|
18
|
+
],
|
|
19
|
+
// Admin design tokens, scoped to html[data-cms-admin] so the host site's own
|
|
20
|
+
// theme is untouched (see app/assets/css/cms-admin.css).
|
|
21
|
+
css: [join(layerDir, 'app/assets/css/cms-admin.css')],
|
|
22
|
+
// Admin sessions end after 14 days at the latest (sign in again). Without a maxAge
|
|
23
|
+
// a copied session cookie would stay valid until the account changes. Hosts can
|
|
24
|
+
// override with runtimeConfig.session.maxAge / NUXT_SESSION_MAX_AGE.
|
|
25
|
+
runtimeConfig: {
|
|
26
|
+
session: { maxAge: 60 * 60 * 24 * 14 },
|
|
27
|
+
},
|
|
28
|
+
// The admin's realtime socket (/api/cms/_live): presence and live updates.
|
|
29
|
+
nitro: {
|
|
30
|
+
experimental: { websocket: true },
|
|
31
|
+
},
|
|
32
|
+
// The admin's typefaces, through @nuxt/fonts (bundled with Nuxt UI): downloaded at
|
|
33
|
+
// build time and served from the app itself — no requests to Google at runtime.
|
|
34
|
+
// The admin's tokens reference them through CSS variables, which @nuxt/fonts
|
|
35
|
+
// cannot see, so they are declared here and registered globally.
|
|
36
|
+
fonts: {
|
|
37
|
+
families: [
|
|
38
|
+
{ name: 'Inter', provider: 'google', weights: [400, 500, 600], global: true },
|
|
39
|
+
{ name: 'Manrope', provider: 'google', weights: [600, 700, 800], global: true },
|
|
40
|
+
{ name: 'Geist Mono', provider: 'google', weights: [400, 500], global: true },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,101 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinyzoo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Code-first, distributable CMS for Nuxt 4 (Layer + Module).",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"homepage": "https://github.com/tinyzookeeper/tinyzoo#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/tinyzookeeper/tinyzoo.git",
|
|
11
|
+
"directory": "packages/cms"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/tinyzookeeper/tinyzoo/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cms",
|
|
18
|
+
"headless-cms",
|
|
19
|
+
"nuxt",
|
|
20
|
+
"nuxt-layer",
|
|
21
|
+
"nuxt-module",
|
|
22
|
+
"drizzle",
|
|
23
|
+
"postgres",
|
|
24
|
+
"code-first"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/index.ts",
|
|
28
|
+
"./forms": "./forms/index.ts",
|
|
29
|
+
"./layer": "./nuxt.config.ts",
|
|
30
|
+
"./module": "./module.ts",
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"main": "./src/index.ts",
|
|
34
|
+
"types": "./src/index.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"app",
|
|
39
|
+
"app.config.ts",
|
|
40
|
+
"cli",
|
|
41
|
+
"forms",
|
|
42
|
+
"module.ts",
|
|
43
|
+
"nuxt.config.ts",
|
|
44
|
+
"server",
|
|
45
|
+
"shared",
|
|
46
|
+
"src",
|
|
47
|
+
"starter",
|
|
48
|
+
"!starter/node_modules",
|
|
49
|
+
"!starter/.nuxt",
|
|
50
|
+
"!starter/.output"
|
|
51
|
+
],
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@fastify/busboy": "^3.2.6",
|
|
54
|
+
"@hocuspocus/extension-redis": "^3.4.4",
|
|
55
|
+
"@hocuspocus/provider": "^3.4.4",
|
|
56
|
+
"@hocuspocus/server": "^3.4.4",
|
|
57
|
+
"@nuxt/kit": "^4.0.0",
|
|
58
|
+
"@tiptap/core": "^3.34.0",
|
|
59
|
+
"@tiptap/extension-collaboration": "^3.34.0",
|
|
60
|
+
"@tiptap/extension-collaboration-caret": "3.34.0",
|
|
61
|
+
"@tiptap/extension-image": "^3.34.0",
|
|
62
|
+
"@tiptap/extension-link": "^3.34.0",
|
|
63
|
+
"@tiptap/pm": "^3.34.0",
|
|
64
|
+
"@tiptap/starter-kit": "^3.34.0",
|
|
65
|
+
"@tiptap/vue-3": "^3.34.0",
|
|
66
|
+
"@tiptap/y-tiptap": "^3.3.0",
|
|
67
|
+
"@types/node": ">=20",
|
|
68
|
+
"@types/nodemailer": "^8.0.2",
|
|
69
|
+
"@types/pg": "^8.11.0",
|
|
70
|
+
"aws4fetch": "^1.0.20",
|
|
71
|
+
"drizzle-orm": "^0.44.0",
|
|
72
|
+
"image-size": "^2.0.2",
|
|
73
|
+
"ioredis": "^5.11.1",
|
|
74
|
+
"jiti": "^2.6.0",
|
|
75
|
+
"nodemailer": "^7.0.13",
|
|
76
|
+
"pg": "^8.16.3",
|
|
77
|
+
"sharp": "^0.34.5",
|
|
78
|
+
"tsx": "^4.19.0",
|
|
79
|
+
"yjs": "^13.6.31",
|
|
80
|
+
"zod": "^4.0.0"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"drizzle-kit": "^0.31.0",
|
|
84
|
+
"typescript": "^5.7.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@internationalized/date": "^3.12.2",
|
|
88
|
+
"@nuxt/ui": "^4.9.0",
|
|
89
|
+
"nuxt": "^4.4.0",
|
|
90
|
+
"nuxt-auth-utils": "^0.5.29"
|
|
91
|
+
},
|
|
92
|
+
"bin": {
|
|
93
|
+
"tinyzoo": "./cli/index.ts"
|
|
94
|
+
},
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": ">=22"
|
|
97
|
+
},
|
|
98
|
+
"publishConfig": {
|
|
99
|
+
"access": "public"
|
|
100
|
+
}
|
|
6
101
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// GET /api/cms/:entity/:id/revisions/:rev — one snapshot's values (to compare or
|
|
2
|
+
// restore in the editor). Anyone who may read the entry may see it.
|
|
3
|
+
import { and, eq } from 'tinyzoo'
|
|
4
|
+
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
const { db, reg } = useCms()
|
|
7
|
+
const user = requireCmsUser(event)
|
|
8
|
+
const e = getEntity(reg, getRouterParam(event, 'entity'))
|
|
9
|
+
const id = getIdParam(event)
|
|
10
|
+
const rev = getIdParam(event, 'rev')
|
|
11
|
+
const [row] = await db.select({ id: e.table.id }).from(e.table).where(both(eq(e.table.id, id), authorize(e, 'read', user)))
|
|
12
|
+
if (!row) throw createError({ statusCode: 404, statusMessage: 'Not found' })
|
|
13
|
+
const r = reg.cmsRevisions
|
|
14
|
+
const [found] = await db.select().from(r).where(and(eq(r.id, rev), eq(r.entity, e.name), eq(r.recordId, id)))
|
|
15
|
+
if (!found) throw createError({ statusCode: 404, statusMessage: 'Not found' })
|
|
16
|
+
// A snapshot made at an older shape is shown in the current one (restore loads it into the form).
|
|
17
|
+
if (found.data && typeof found.data === 'object') upgradeStoredJson(e, found.data, { admin: true, recordId: id })
|
|
18
|
+
return { revision: found }
|
|
19
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// GET /api/cms/:entity/:id/revisions?locale= — the entry's history (or one
|
|
2
|
+
// translation's), newest first. Anyone who may read the entry may see it.
|
|
3
|
+
import { eq } from 'tinyzoo'
|
|
4
|
+
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
const { db, reg } = useCms()
|
|
7
|
+
const user = requireCmsUser(event)
|
|
8
|
+
const e = getEntity(reg, getRouterParam(event, 'entity'))
|
|
9
|
+
const id = getIdParam(event)
|
|
10
|
+
const [row] = await db.select({ id: e.table.id }).from(e.table).where(both(eq(e.table.id, id), authorize(e, 'read', user)))
|
|
11
|
+
if (!row) throw createError({ statusCode: 404, statusMessage: 'Not found' })
|
|
12
|
+
const locale = requestedLocale(event, reg)
|
|
13
|
+
return { revisions: await listRevisions(e, id, isTranslationLocale(reg, locale) ? locale : null) }
|
|
14
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { eq } from 'tinyzoo'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The refusal for an entry that is still used: it names what uses it, but only what this
|
|
5
|
+
* person may read (a row-level `access.read` rule can hide an entry); the rest is a count.
|
|
6
|
+
*/
|
|
7
|
+
async function inUse(db: any, reg: any, user: any, used: { entity: string; id: string }[]) {
|
|
8
|
+
const { visible, hidden } = await splitReadable(db, reg, user, used)
|
|
9
|
+
return createError({ statusCode: 409, statusMessage: 'Still in use by other content', data: { code: 'in_use', usedBy: visible, ...(hidden ? { hidden } : {}) } })
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default defineEventHandler(async (event) => {
|
|
13
|
+
const { db, reg } = useCms()
|
|
14
|
+
const user = requireCmsUser(event)
|
|
15
|
+
const e = getEntity(reg, getRouterParam(event, 'entity'))
|
|
16
|
+
if (e.singleton) throw createError({ statusCode: 404, statusMessage: 'Globals are not deletable' })
|
|
17
|
+
const id = getIdParam(event)
|
|
18
|
+
// ?locale=<translation>: remove only that translation (needs edit rights, not delete).
|
|
19
|
+
const locale = requestedLocale(event, reg)
|
|
20
|
+
if (isTranslationLocale(reg, locale)) return deleteTranslation(event, e, id, locale, user, authorize(e, 'update', user))
|
|
21
|
+
const rowFilter = authorize(e, 'delete', user)
|
|
22
|
+
|
|
23
|
+
// People who may not publish cannot take a live entry off the website by deleting it.
|
|
24
|
+
const [current] = await db.select().from(e.table).where(both(eq(e.table.id, id), rowFilter))
|
|
25
|
+
if (!current) throw createError({ statusCode: 404, statusMessage: 'Not found or not permitted' })
|
|
26
|
+
assertPublishAllowed(e, user, {}, current)
|
|
27
|
+
// A page tree: pages below this one would lose their place (and their address): move or delete them first.
|
|
28
|
+
if (e.tree) await assertNoChildren(db, e, id, await readableTreeIds(db, e, user))
|
|
29
|
+
// Menus and links that point at this entry (by reference) would go dead: refused, saying which.
|
|
30
|
+
const linked = await linksTo(db, reg, e, id)
|
|
31
|
+
if (linked.length) throw await inUse(db, reg, user, [...await usedBy(db, reg, e, id), ...linked.map((l) => ({ ...l, via: 'link' }))])
|
|
32
|
+
const translatedMedia = await translationMediaIds(db, e, id)
|
|
33
|
+
const seenBefore = await changeSnapshot(e, id)
|
|
34
|
+
const deleted: any[] = await (db as any).delete(e.table).where(both(both(eq(e.table.id, id), rowFilter), notLiveCond(e, user))).returning()
|
|
35
|
+
.catch(async (err: any) => {
|
|
36
|
+
// Still used by other content: say by what, so the editor can go and change it.
|
|
37
|
+
if ((err?.code ?? err?.cause?.code) === '23503') throw await inUse(db, reg, user, await usedBy(db, reg, e, id))
|
|
38
|
+
return rethrowDbError(err, e, 'delete')
|
|
39
|
+
})
|
|
40
|
+
if (!deleted.length) throw createError({ statusCode: 404, statusMessage: 'Not found or not permitted' })
|
|
41
|
+
|
|
42
|
+
// GC media the deleted row owned, once nothing else references it.
|
|
43
|
+
const storage = useCmsStorage()
|
|
44
|
+
for (const mediaId of new Set([...mediaIdsOf(reg, e, deleted[0]), ...translatedMedia])) {
|
|
45
|
+
await gcMediaIfOrphan(db, reg, storage, mediaId, gcScope(user))
|
|
46
|
+
}
|
|
47
|
+
await audit(event, 'entry.delete', { entity: e.name, recordId: id })
|
|
48
|
+
await dropCollabDocuments(e.name, id)
|
|
49
|
+
await dropRevisions(e, id)
|
|
50
|
+
await reportChange(event, { type: 'entry.deleted', entity: e, id, before: seenBefore })
|
|
51
|
+
return { ok: true }
|
|
52
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { eq } from 'tinyzoo'
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const { db, reg } = useCms()
|
|
5
|
+
const user = requireCmsUser(event)
|
|
6
|
+
const e = getEntity(reg, getRouterParam(event, 'entity'))
|
|
7
|
+
const rowFilter = authorize(e, 'read', user)
|
|
8
|
+
const id = getIdParam(event)
|
|
9
|
+
|
|
10
|
+
const [row] = await db.select().from(e.table).where(both(eq(e.table.id, id), rowFilter))
|
|
11
|
+
if (!row) throw createError({ statusCode: 404, statusMessage: 'Not found' })
|
|
12
|
+
|
|
13
|
+
await hydrateRowForForm(db, reg, e, row)
|
|
14
|
+
// ?locale=<translation>: the translation itself (empty where missing) plus the
|
|
15
|
+
// default-language values for reference.
|
|
16
|
+
const locale = requestedLocale(event, reg)
|
|
17
|
+
if (isTranslationLocale(reg, locale) && e.localized.length) await translationFormRow(db, reg, e, row, locale)
|
|
18
|
+
if (reg.locales && e.localized.length) row.__locales = (await availableLocales(db, reg, e, [id])).get(id)
|
|
19
|
+
// Whether this person may save here (the form opens read-only when not).
|
|
20
|
+
return { row, can: await updateVerdict(db, e, user, id) }
|
|
21
|
+
})
|