@cossackframework/cms 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +123 -3
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server helpers for the dashboard's content screens: which resource a route names, the
|
|
3
|
+
* editor's view of it, and saving entries. Pages call these from their server methods.
|
|
4
|
+
*/
|
|
5
|
+
import { blockCategory, blockMedia, entryAuthors, blockSupports, bulkActions, cloneBlocks, editorBoxes, escapeHtml, fieldGroupDeclarations, type FieldGroupTarget, CmsError, CORE_FIELDS, hasPermission, entryActions, entryColumns, flattenBlocks, isCmsError, mediaUrl, principalId, recordTitle, resolveEditorLayout, richTextHtml, richTextMedia, type Block, type BlockDeclaration, type CollectionDefinition, type EntryAction, type EntryColumn, type ListOptions, type MediaKind, type Principal, type RecordShape, type Resource, type RichTextDoc, type WriteActor } from '@cossackframework/cms';
|
|
6
|
+
import { lockedCopy, renderMarkdown, type CmsHost } from '@cossackframework/cms/server';
|
|
7
|
+
import { activePresets, entryLock } from './site';
|
|
8
|
+
import { controlValue, editorBlocks, editorField, editorFields, editorInput, type BlockOption, type EditorBlock, type EditorField, type EditorGroup, type EditorTaxonomy, type EditorValues, type EditorView, type SourceChoice, type SourceChoices, type TermOption } from './editor';
|
|
9
|
+
|
|
10
|
+
/** A collection by name (`posts`), or a plugin or application resource as `<owner>.<name>`. */
|
|
11
|
+
export function routeResource(cms: CmsHost, route: string): { resource: Resource; collection: CollectionDefinition | null } {
|
|
12
|
+
const [owner, name] = route.includes('.') ? route.split('.', 2) : ['cms', route];
|
|
13
|
+
if (owner === 'cms' && route.includes('.')) throw new CmsError('CMS_NOT_FOUND', 'Unknown content type.');
|
|
14
|
+
const resource = cms.resourceById(`${owner}/${name}`);
|
|
15
|
+
return { resource, collection: owner === 'cms' ? cms.collection(name!) : null };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** What fields with `choicesFrom` choose from: the site's forms by title, its collections, its terms by taxonomy (200 of each at most), the themes' menu locations, its authors and its roles. */
|
|
19
|
+
export async function sourceChoices(cms: CmsHost): Promise<SourceChoices> {
|
|
20
|
+
const terms: SourceChoice[] = [];
|
|
21
|
+
for (const declaration of cms.taxonomies.declarations) {
|
|
22
|
+
if (terms.length >= 200) break;
|
|
23
|
+
terms.push(...(await cms.taxonomies.tree(declaration.name)).slice(0, 200 - terms.length).map(term => ({ value: term.id, label: `${declaration.label}: ${'— '.repeat(term.depth)}${term.name}` })));
|
|
24
|
+
}
|
|
25
|
+
const forms = await cms.forms.all().catch(() => []);
|
|
26
|
+
return {
|
|
27
|
+
forms: forms.map(form => ({ value: String(form.record.slug ?? ''), label: `${recordTitle(form.record, 'title')} (${String(form.record.slug ?? '')})` })).filter(choice => choice.value),
|
|
28
|
+
collections: cms.collections().filter(entry => entry.publishable !== false && !entry.managed).map(entry => ({ value: entry.name, label: entry.label })),
|
|
29
|
+
terms,
|
|
30
|
+
// The site's authors (people who wrote something), for blocks that list one author's entries.
|
|
31
|
+
authors: (await cms.users.authors({ limit: 200 }).catch(() => [])).map(user => ({ value: user.id, label: user.name || user.email })),
|
|
32
|
+
locations: (await cms.menuLocations()).map(location => ({ value: location.name, label: location.active ? location.label : `${location.label} (${location.theme})` })),
|
|
33
|
+
// The site's roles, for who may read a members-only entry.
|
|
34
|
+
roles: (await cms.users.roles({ limit: 100 }).catch(() => [])).map(role => ({ value: role.id, label: role.name })),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Terms of a taxonomy in tree order, for checklists and selects. */
|
|
39
|
+
export async function termOptions(cms: CmsHost, taxonomy: string): Promise<TermOption[]> {
|
|
40
|
+
return (await cms.taxonomies.tree(taxonomy)).map(term => ({ id: term.id, name: term.name, depth: term.depth }));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The editor of a route's entries. With a principal, the fields they may not read or change are
|
|
45
|
+
* left out, so no control shows a hidden value as empty or takes an edit the save would refuse.
|
|
46
|
+
*/
|
|
47
|
+
export async function editorView(cms: CmsHost, route: string, principal?: Principal): Promise<EditorView> {
|
|
48
|
+
const { resource, collection } = routeResource(cms, route);
|
|
49
|
+
const taxonomyFields = Object.entries(resource.fields).filter(([, field]) => field.taxonomy).map(([name, field]) => ({ name, taxonomy: field.taxonomy! }));
|
|
50
|
+
const special = collection ? [...CORE_FIELDS, ...taxonomyFields.map(entry => entry.name)] : [resource.titleField ?? '', ...taxonomyFields.map(entry => entry.name)];
|
|
51
|
+
const taxonomies: EditorTaxonomy[] = [];
|
|
52
|
+
for (const { taxonomy } of taxonomyFields) {
|
|
53
|
+
const declaration = cms.taxonomies.declaration(taxonomy);
|
|
54
|
+
taxonomies.push({ name: declaration.name, label: declaration.label, singular: declaration.singular, hierarchical: declaration.hierarchical,
|
|
55
|
+
terms: declaration.hierarchical ? await termOptions(cms, taxonomy) : (await cms.taxonomies.list(taxonomy, { limit: 100 })).items.map(term => ({ id: term.id, name: term.name, depth: 0 })) });
|
|
56
|
+
}
|
|
57
|
+
const blocks = await blockOptions(cms);
|
|
58
|
+
const titleField = collection ? 'title' : resource.titleField ?? '';
|
|
59
|
+
const groups = collection ? cms.fieldGroupsFor({ kind: 'collection', name: collection.name }) : [];
|
|
60
|
+
// The editor's boxes, placed by the collection's layout (or the default), with what active plugins add.
|
|
61
|
+
const boxes = editorBoxes({ collection: collection ?? { path: null }, fields: resource.fields, groups, taxonomies: taxonomies.map(taxonomy => ({ name: taxonomy.name, label: taxonomy.label })), special });
|
|
62
|
+
const resolved = resolveEditorLayout(collection?.editor, boxes, collection ? cms.editorLayoutAdditions(collection.name) : []);
|
|
63
|
+
return {
|
|
64
|
+
resource: resource.id, route, label: resource.label ?? resource.id, singular: collection?.singular ?? 'Entry',
|
|
65
|
+
titleField, titleRequired: Boolean(titleField && resource.fields[titleField]?.required),
|
|
66
|
+
slug: Boolean(collection && collection.slug !== false), publishable: Boolean(collection && collection.publishable !== false), hierarchical: Boolean(collection?.hierarchical),
|
|
67
|
+
path: collection?.path ?? null,
|
|
68
|
+
fields: editorFields(resource.fields, special).filter(field => !principal || fieldAllowed(resource.fields[field.name], principal)),
|
|
69
|
+
restricted: [...restrictedFields(cms, resource.id)],
|
|
70
|
+
taxonomies, blocks, presets: await activePresets(cms),
|
|
71
|
+
template: editorBlocks(cloneBlocks(collection?.template ?? []) as EditorBlock[], blocks), ...(collection?.templateLock ? { templateLock: collection.templateLock } : {}),
|
|
72
|
+
collections: cms.collections().filter(entry => entry.publishable !== false && !entry.managed).map(entry => ({ name: entry.name, label: entry.label })),
|
|
73
|
+
sources: await sourceChoices(cms),
|
|
74
|
+
groups: groups.map(group => ({
|
|
75
|
+
id: group.id, title: group.title, description: group.description ?? '', placement: group.placement ?? 'main', blocks: editorBlocks(group.blocks as EditorBlock[], blocks),
|
|
76
|
+
})),
|
|
77
|
+
// The layout keeps its IDs: a section's open or closed state is remembered by its ID.
|
|
78
|
+
layout: {
|
|
79
|
+
tabs: resolved.tabs.map(tab => ({ id: tab._id, label: String(tab.data.label ?? ''), icon: String(tab.data.icon ?? ''), blocks: [...(tab.children ?? [])] as EditorBlock[] })),
|
|
80
|
+
sidebar: [...resolved.sidebar] as EditorBlock[],
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** What a screen needs to show a target's field groups: the boxes, their fields and the block types. */
|
|
86
|
+
export interface GroupsView {
|
|
87
|
+
groups: EditorGroup[];
|
|
88
|
+
fields: EditorField[];
|
|
89
|
+
options: BlockOption[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The field groups attached to a target, for the editors of terms, users and menu items. */
|
|
93
|
+
export async function groupsView(cms: CmsHost, target: FieldGroupTarget): Promise<GroupsView> {
|
|
94
|
+
const options = await blockOptions(cms);
|
|
95
|
+
const groups = cms.fieldGroupsFor(target);
|
|
96
|
+
const fields = editorFields(fieldGroupDeclarations(groups.flatMap(group => group.blocks), cms.blockTypes), []);
|
|
97
|
+
return {
|
|
98
|
+
groups: groups.map(group => ({ id: group.id, title: group.title, description: group.description ?? '', placement: group.placement ?? 'main', blocks: editorBlocks(group.blocks as EditorBlock[], options) })),
|
|
99
|
+
fields, options,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A target's meta as control values. */
|
|
104
|
+
export function metaValues(fields: readonly EditorField[], meta: { readonly [field: string]: unknown } | undefined): EditorValues {
|
|
105
|
+
return Object.fromEntries(fields.map(field => [field.name, controlValue(field, meta?.[field.name])]));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Typed meta from control values; invalid text is reported by field. */
|
|
109
|
+
export function metaInput(fields: readonly EditorField[], values: EditorValues): { meta: Record<string, unknown>; errors: Record<string, string> } {
|
|
110
|
+
const { input, errors } = editorInput(fields, values);
|
|
111
|
+
return { meta: input, errors };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { contentField } from './editor';
|
|
115
|
+
|
|
116
|
+
/** A pattern's blocks, with fresh IDs for the copy. Null when it is gone or private to someone else. */
|
|
117
|
+
export async function patternBlocks(cms: CmsHost, id: string, principal: Principal): Promise<Block[] | null> {
|
|
118
|
+
const record = await cms.resource('cms/patterns').get(id, { principal }).catch(() => null);
|
|
119
|
+
return Array.isArray(record?.content) ? cloneBlocks(record.content as Block[]) : null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Blocks as plain HTML, for feeds and the content API's `?format=html`: rich text and Markdown
|
|
124
|
+
* rendered, images as tags, the rest as its text. Containers render what they hold.
|
|
125
|
+
*/
|
|
126
|
+
export function blocksHtml(cms: CmsHost, blocks: readonly Block[], files: ReadonlyMap<string, { id: string; name: string; alt: string }> = new Map()): string {
|
|
127
|
+
const parts: string[] = [];
|
|
128
|
+
for (const block of blocks) {
|
|
129
|
+
const type = cms.blockTypes.get(block.type);
|
|
130
|
+
if (!type || blockCategory(type) === 'data') continue;
|
|
131
|
+
for (const [name, declaration] of Object.entries(type.fields)) {
|
|
132
|
+
const value = block.data[name];
|
|
133
|
+
if (declaration.kind === 'richtext' && value && typeof value === 'object') parts.push(richTextHtml(value as RichTextDoc, { block: () => '' }));
|
|
134
|
+
else if (declaration.kind === 'text' && declaration.format === 'markdown' && typeof value === 'string') parts.push(renderMarkdown(value));
|
|
135
|
+
else if (declaration.media && typeof value === 'string' && files.get(value)) parts.push(`<p><img src="${mediaUrl(files.get(value)!)}" alt="${(files.get(value)!.alt).replace(/"/g, '"')}"></p>`);
|
|
136
|
+
else if (block.type === 'core/heading' && name === 'text' && typeof value === 'string') { const level = typeof block.data.level === 'string' ? block.data.level : 'h2'; parts.push(`<${level}>${escape(value)}</${level}>`); }
|
|
137
|
+
else if (block.type === 'core/list' && name === 'items' && Array.isArray(value)) parts.push(`<${block.data.ordered ? 'ol' : 'ul'}>${value.map(item => `<li>${escape(String(item))}</li>`).join('')}</${block.data.ordered ? 'ol' : 'ul'}>`);
|
|
138
|
+
else if (block.type === 'core/quote' && name === 'text' && typeof value === 'string') parts.push(`<blockquote><p>${escape(value)}</p></blockquote>`);
|
|
139
|
+
}
|
|
140
|
+
if (block.children?.length) parts.push(blocksHtml(cms, block.children, files));
|
|
141
|
+
}
|
|
142
|
+
return parts.join('\n');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const escape = escapeHtml;
|
|
146
|
+
|
|
147
|
+
/** Control values for an entry; tags show as names. */
|
|
148
|
+
export async function entryValues(cms: CmsHost, view: EditorView, record: RecordShape | null): Promise<EditorValues> {
|
|
149
|
+
const { resource } = routeResource(cms, view.route);
|
|
150
|
+
const values: EditorValues = {};
|
|
151
|
+
for (const [name, declaration] of Object.entries(resource.fields)) {
|
|
152
|
+
const stored = record ? record[name] : declaration.default ?? null;
|
|
153
|
+
values[name] = controlValue(editorField(name, declaration), stored);
|
|
154
|
+
}
|
|
155
|
+
for (const taxonomy of view.taxonomies) {
|
|
156
|
+
const ids = (record?.[taxonomy.name] as string[] | undefined) ?? [];
|
|
157
|
+
if (taxonomy.hierarchical) { values[taxonomy.name] = ids; continue; }
|
|
158
|
+
const terms = await cms.taxonomies.getMany(ids);
|
|
159
|
+
values[taxonomy.name] = ids.map(id => terms.get(id)?.name).filter(Boolean);
|
|
160
|
+
}
|
|
161
|
+
if (view.publishable) {
|
|
162
|
+
values.status = (record?.status as string | undefined) ?? 'draft';
|
|
163
|
+
values.publishedAt = record?.publishedAt ? new Date(record.publishedAt as number).toISOString().slice(0, 16) : '';
|
|
164
|
+
values.unpublishAt = record?.unpublishAt ? new Date(record.unpublishAt as number).toISOString().slice(0, 16) : '';
|
|
165
|
+
}
|
|
166
|
+
if (view.hierarchical) {
|
|
167
|
+
values.parent = (record?.parent as string | null | undefined) ?? '';
|
|
168
|
+
values.menuOrder = String(record?.menuOrder ?? 0);
|
|
169
|
+
}
|
|
170
|
+
const languages = await cms.languages();
|
|
171
|
+
values.locale = typeof record?.locale === 'string' ? record.locale : languages.default;
|
|
172
|
+
if (resource.fields.commentsOpen) values.commentsOpen = record ? record.commentsOpen !== false : await cms.settings.get('discussion.defaultOpen');
|
|
173
|
+
// Authors as user IDs, the first the main author; a new entry's are filled in with its creator on save.
|
|
174
|
+
if (resource.fields.authors) values.authors = record ? entryAuthors(record) : [];
|
|
175
|
+
return values;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { MediaPreview } from './field-controls';
|
|
179
|
+
import type { MediaPreview } from './field-controls';
|
|
180
|
+
|
|
181
|
+
/** The block types editors can add: those of modules and active plugins. */
|
|
182
|
+
export async function blockOptions(cms: CmsHost): Promise<BlockOption[]> {
|
|
183
|
+
return (await cms.blocks()).map(blockOption);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The options of a set of block types that are not the host's, such as the editor layout's. */
|
|
187
|
+
export function optionsOf(types: ReadonlyMap<string, BlockDeclaration>): BlockOption[] {
|
|
188
|
+
return [...types.values()].map(blockOption);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A block type as the editors hold it. */
|
|
192
|
+
export function blockOption(block: BlockDeclaration): BlockOption {
|
|
193
|
+
return { name: block.name, label: block.label, description: block.description ?? '', icon: block.icon ?? '',
|
|
194
|
+
category: blockCategory(block), fields: editorFields(block.fields, []), ...(block.body ? { body: block.body } : {}),
|
|
195
|
+
children: block.children ? { allowed: [...(block.children.allowed ?? [])], max: block.children.max ?? null } : null, parent: [...(block.parent ?? [])], supports: [...blockSupports(block)], field: block.field?.kind ?? '', input: Boolean(block.input), keywords: [...(block.keywords ?? [])], common: block.common === true,
|
|
196
|
+
variations: (block.variations ?? []).map(variation => ({ name: variation.name, label: variation.label, description: variation.description ?? '', icon: variation.icon ?? block.icon ?? '', keywords: [...(variation.keywords ?? [])], data: { ...variation.data } })) };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Previews of files by ID; missing files are left out. */
|
|
200
|
+
export async function filePreviews(cms: CmsHost, ids: Iterable<string>): Promise<Record<string, MediaPreview>> {
|
|
201
|
+
const wanted = [...new Set(ids)].filter(Boolean).slice(0, 200);
|
|
202
|
+
if (!cms.files || !wanted.length) return {};
|
|
203
|
+
const files = await cms.files.getMany(wanted);
|
|
204
|
+
return Object.fromEntries([...files.values()].map(file => [file.id, { id: file.id, url: mediaUrl(file), title: file.title, alt: file.alt, contentType: file.contentType, width: file.width, height: file.height }]));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Previews of the files meta names, at any depth, such as a user's or a term's field values. */
|
|
208
|
+
export function metaFilePreviews(cms: CmsHost, meta: { readonly [field: string]: unknown }): Promise<Record<string, MediaPreview>> {
|
|
209
|
+
const ids: string[] = [];
|
|
210
|
+
const walk = (value: unknown) => {
|
|
211
|
+
if (typeof value === 'string' && /^[A-Za-z0-9_-]{1,80}$/.test(value)) ids.push(value);
|
|
212
|
+
else if (Array.isArray(value)) value.forEach(walk);
|
|
213
|
+
else if (value && typeof value === 'object') Object.values(value).forEach(walk);
|
|
214
|
+
};
|
|
215
|
+
walk(meta);
|
|
216
|
+
return filePreviews(cms, ids);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Previews of the files blocks use. */
|
|
220
|
+
export function blockFilePreviews(cms: CmsHost, blocks: readonly Block[]): Promise<Record<string, MediaPreview>> {
|
|
221
|
+
return filePreviews(cms, blockMedia(blocks, cms.blockTypes));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** The media library's newest files matching a search, for a media chooser. */
|
|
225
|
+
export async function findMedia(cms: CmsHost, search: string, kind = ''): Promise<MediaPreview[]> {
|
|
226
|
+
if (!cms.files) return [];
|
|
227
|
+
const page = await cms.files.list({ search: search.slice(0, 100), limit: 40, ...(kind ? { kind: kind as MediaKind } : {}) });
|
|
228
|
+
return page.items.map(file => ({ id: file.id, url: mediaUrl(file), title: file.title, alt: file.alt, contentType: file.contentType, width: file.width, height: file.height }));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Previews of the media an entry's fields and blocks use. */
|
|
232
|
+
export async function mediaPreviews(cms: CmsHost, values: EditorValues, view: EditorView): Promise<Record<string, MediaPreview>> {
|
|
233
|
+
const ids = new Set<string>();
|
|
234
|
+
const collect = (fields: EditorView['fields'], source: Record<string, unknown>) => {
|
|
235
|
+
for (const field of fields) {
|
|
236
|
+
const value = source[field.name];
|
|
237
|
+
if (field.media && typeof value === 'string' && value) ids.add(value);
|
|
238
|
+
if (field.media && Array.isArray(value)) for (const id of value) if (typeof id === 'string') ids.add(id);
|
|
239
|
+
if (field.kind === 'richtext' && value && typeof value === 'object') for (const id of richTextMedia(value as RichTextDoc)) ids.add(id);
|
|
240
|
+
if (field.kind === 'blocks' && Array.isArray(value)) {
|
|
241
|
+
for (const block of flattenBlocks(value as EditorBlock[])) {
|
|
242
|
+
collect(view.blocks.find(option => option.name === block.type)?.fields ?? [], block.data ?? {});
|
|
243
|
+
for (const id of [block.style?.image, block.style?.video]) if (typeof id === 'string' && id) ids.add(id);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
collect(view.fields, values);
|
|
249
|
+
const seo = values.seo as Record<string, unknown> | undefined;
|
|
250
|
+
if (typeof seo?.image === 'string' && seo.image) ids.add(seo.image);
|
|
251
|
+
if (!cms.files || !ids.size) return {};
|
|
252
|
+
const files = await cms.files.getMany([...ids]);
|
|
253
|
+
return Object.fromEntries([...files.values()].map(file => [file.id, { id: file.id, url: mediaUrl(file), title: file.title, alt: file.alt, contentType: file.contentType, width: file.width, height: file.height }]));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Entries an entry can nest under: everything except itself and its descendants. */
|
|
257
|
+
export async function parentOptions(cms: CmsHost, resourceId: string, self: string | null, principal: Principal): Promise<TermOption[]> {
|
|
258
|
+
const page = await cms.resource(resourceId).list({ where: { status: { ne: 'trash' } }, order: { field: 'title', direction: 'asc' }, limit: 100 }, { principal });
|
|
259
|
+
const children = new Map<string | null, RecordShape[]>();
|
|
260
|
+
for (const record of page.records) {
|
|
261
|
+
const parent = (record.parent as string | null) ?? null;
|
|
262
|
+
children.set(parent, [...(children.get(parent) ?? []), record]);
|
|
263
|
+
}
|
|
264
|
+
const known = new Set(page.records.map(record => record.id));
|
|
265
|
+
const options: TermOption[] = [];
|
|
266
|
+
const visit = (parent: string | null, depth: number) => {
|
|
267
|
+
for (const record of children.get(parent) ?? []) {
|
|
268
|
+
if (record.id === self) continue;
|
|
269
|
+
options.push({ id: record.id, name: recordTitle(record, 'title'), depth });
|
|
270
|
+
visit(record.id, depth + 1);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
visit(null, 0);
|
|
274
|
+
// Entries whose parent is outside this page still appear, at the top level.
|
|
275
|
+
for (const record of page.records) {
|
|
276
|
+
const parent = record.parent as string | null;
|
|
277
|
+
if (parent && !known.has(parent) && record.id !== self) options.push({ id: record.id, name: recordTitle(record, 'title'), depth: 0 });
|
|
278
|
+
}
|
|
279
|
+
return options;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type SaveIntent = 'draft' | 'publish' | 'update' | 'trash' | 'restore';
|
|
283
|
+
|
|
284
|
+
/** Record input from control values, without terms: what saving would write, for previews and saves. */
|
|
285
|
+
export async function entryInput(cms: CmsHost, route: string, values: EditorValues): Promise<Record<string, unknown>> {
|
|
286
|
+
const view = await editorView(cms, route);
|
|
287
|
+
const { resource } = routeResource(cms, route);
|
|
288
|
+
const fields = [...view.fields];
|
|
289
|
+
const titleField = view.titleField;
|
|
290
|
+
if (titleField && resource.fields[titleField]) fields.push(editorField(titleField, resource.fields[titleField]!));
|
|
291
|
+
for (const name of ['slug', 'publishedAt', 'unpublishAt', 'parent', 'menuOrder', 'authors', 'seo', 'summary', 'locale', 'commentsOpen', 'template']) {
|
|
292
|
+
if (resource.fields[name] && (name !== 'slug' || view.slug) && ((name !== 'publishedAt' && name !== 'unpublishAt') || view.publishable)) fields.push(editorField(name, resource.fields[name]!));
|
|
293
|
+
}
|
|
294
|
+
const { input, errors } = editorInput(fields, values, view.blocks);
|
|
295
|
+
if (Object.keys(errors).length) throw new CmsError('CMS_VALIDATION', 'Some fields are invalid.', { fields: errors });
|
|
296
|
+
return input;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Fields whose reading or writing is limited to some principals (`access` on the field). A
|
|
301
|
+
* principal's editor shows those they may read and change, and saves only those; the shared
|
|
302
|
+
* editing room leaves them all out.
|
|
303
|
+
*/
|
|
304
|
+
export function restrictedFields(cms: CmsHost, resourceId: string): Set<string> {
|
|
305
|
+
return new Set(Object.entries(cms.resourceById(resourceId).fields).filter(([, declaration]) => declaration.access?.read || declaration.access?.write).map(([name]) => name));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Whether the principal may read and change a field: its `access` rules, where it has them, allow both. */
|
|
309
|
+
function fieldAllowed(declaration: Resource['fields'][string] | undefined, principal: Principal): boolean {
|
|
310
|
+
const access = declaration?.access;
|
|
311
|
+
return !access || ((!access.read || hasPermission(principal, access.read)) && (!access.write || hasPermission(principal, access.write)));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Leave out of an input the fields the principal's editor does not show: their values are not a request to change them. */
|
|
315
|
+
export function writableInput(cms: CmsHost, resourceId: string, input: Record<string, unknown>, principal: Principal): Record<string, unknown> {
|
|
316
|
+
const fields = cms.resourceById(resourceId).fields;
|
|
317
|
+
for (const name of Object.keys(input)) if (!fieldAllowed(fields[name], principal)) delete input[name];
|
|
318
|
+
return input;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Create or update an entry from control values. Typed tags become term IDs, creating the
|
|
323
|
+
* missing ones. The status is the one chosen, or follows the button pressed. Field errors
|
|
324
|
+
* come back keyed by field.
|
|
325
|
+
*/
|
|
326
|
+
export async function saveEntry(cms: CmsHost, route: string, id: string | null, values: EditorValues, intent: SaveIntent, revision: number, principal: Principal): Promise<RecordShape> {
|
|
327
|
+
const view = await editorView(cms, route);
|
|
328
|
+
const { resource } = routeResource(cms, route);
|
|
329
|
+
const repository = cms.resource(resource.id);
|
|
330
|
+
// Moving to the trash changes only the status, as in WordPress; edits are not saved.
|
|
331
|
+
if (intent === 'trash' && id && view.publishable) return repository.update(id, { status: 'trash' }, { principal, expectedRevision: revision });
|
|
332
|
+
const input = writableInput(cms, resource.id, await entryInput(cms, route, values), principal);
|
|
333
|
+
for (const taxonomy of view.taxonomies) {
|
|
334
|
+
const raw = values[taxonomy.name];
|
|
335
|
+
const list = Array.isArray(raw) ? raw.filter((item): item is string => typeof item === 'string') : [];
|
|
336
|
+
input[taxonomy.name] = taxonomy.hierarchical ? list : await cms.taxonomies.ensure(taxonomy.name, list, { principal });
|
|
337
|
+
}
|
|
338
|
+
if (view.publishable) {
|
|
339
|
+
const current = typeof values.status === 'string' && ['draft', 'pending', 'scheduled', 'published'].includes(values.status) ? values.status : 'draft';
|
|
340
|
+
input.status = intent === 'publish' ? 'published' : intent === 'draft' ? 'draft' : intent === 'trash' ? 'trash' : intent === 'restore' ? 'draft' : current;
|
|
341
|
+
}
|
|
342
|
+
const record = id ? await repository.update(id, input, { principal, expectedRevision: revision }) : await repository.create(input, { principal });
|
|
343
|
+
// The saved entry replaces the editor's autosave.
|
|
344
|
+
await cms.discardAutosave(resource.id, id ?? 'new', principal).catch(() => undefined);
|
|
345
|
+
return record;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Fields a copy of an entry does not take: its identity, its slug (derived again), its publication and its translation group. */
|
|
349
|
+
const NOT_COPIED = new Set(['slug', 'status', 'publishedAt', 'unpublishAt', 'translationGroup']);
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* A draft copy of an entry, as WordPress's duplicate plugins make one: the same fields with
|
|
353
|
+
* "(Copy)" after the title, a new slug, unpublished, owned by whoever copies it.
|
|
354
|
+
*/
|
|
355
|
+
export async function duplicateEntry(cms: CmsHost, route: string, id: string, principal: Principal): Promise<RecordShape> {
|
|
356
|
+
const { resource, collection } = routeResource(cms, route);
|
|
357
|
+
const repository = cms.resource(resource.id);
|
|
358
|
+
const source = await repository.get(id, { principal });
|
|
359
|
+
if (!source) throw new CmsError('CMS_NOT_FOUND', 'The entry does not exist.');
|
|
360
|
+
// A copy holds everything the entry does: a reader the entry is locked for gets no copy to open.
|
|
361
|
+
if (lockedCopy(source, repository.canUpdate(source, principal))) throw new CmsError('CMS_FORBIDDEN', 'Only its editors can copy a protected or members-only entry.');
|
|
362
|
+
const input: Record<string, unknown> = {};
|
|
363
|
+
for (const [name, declaration] of Object.entries(resource.fields)) {
|
|
364
|
+
// Empty fields stay unset: the repository refuses null where a field has no value.
|
|
365
|
+
if (NOT_COPIED.has(name) || source[name] === undefined || source[name] === null) continue;
|
|
366
|
+
if (declaration.access?.write && !hasPermission(principal, declaration.access.write)) continue;
|
|
367
|
+
input[name] = source[name];
|
|
368
|
+
}
|
|
369
|
+
const titleField = resource.titleField ?? 'title';
|
|
370
|
+
if (typeof source[titleField] === 'string') input[titleField] = `${source[titleField]} (${__('Copy')})`;
|
|
371
|
+
if (collection && collection.publishable !== false) input.status = 'draft';
|
|
372
|
+
return repository.create(input, { principal });
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function writeActor(principal: Principal): WriteActor {
|
|
376
|
+
return { kind: principal.kind, id: principalId(principal) };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** What plugins add to an entries list: actions under each row, extra columns and bulk actions. */
|
|
380
|
+
/**
|
|
381
|
+
* Plugins' additions to an entries list. Each record's quick actions start from `builtin`
|
|
382
|
+
* (the list's own, named by `id`), which plugins may add to, remove from or reorder; a failing
|
|
383
|
+
* filter leaves the built-in ones.
|
|
384
|
+
*/
|
|
385
|
+
export async function listExtras(cms: CmsHost, resource: string, records: readonly RecordShape[], principal: Principal, builtin: (record: RecordShape) => EntryAction[] = () => []): Promise<{ actions: Record<string, EntryAction[]>; columns: EntryColumn[]; bulk: EntryAction[] }> {
|
|
386
|
+
const actor = writeActor(principal);
|
|
387
|
+
const actions: Record<string, EntryAction[]> = {};
|
|
388
|
+
for (const record of records) {
|
|
389
|
+
const own = builtin(record);
|
|
390
|
+
const result = await cms.hooks.applyFilters(entryActions, own, { resource, record, actor }).catch(() => own);
|
|
391
|
+
actions[record.id] = Array.isArray(result) ? result.filter(action => action && typeof action.label === 'string') : own;
|
|
392
|
+
}
|
|
393
|
+
const columns = await cms.hooks.applyFilters(entryColumns, [], { resource, records, actor }).catch(() => []);
|
|
394
|
+
const bulk = await cms.hooks.applyFilters(bulkActions, [], { resource, actor }).catch(() => []);
|
|
395
|
+
return { actions, columns: [...columns], bulk: [...bulk] };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** Run a plugin command an action names, with the entry or entries as its input. */
|
|
399
|
+
export async function runEntryCommand(cms: CmsHost, action: EntryAction, input: { resource: string; id?: string; ids?: readonly string[] }, principal: Principal, signal?: AbortSignal): Promise<void> {
|
|
400
|
+
if (!action.command) return;
|
|
401
|
+
await cms.runCommand(action.command.plugin, action.command.name, { resource: input.resource, ...(input.id ? { id: input.id } : {}), ...(input.ids ? { ids: input.ids.join(',') } : {}) }, { principal, ...(signal ? { signal } : {}) });
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The CMS error's field messages with labels, for showing next to controls. */
|
|
405
|
+
export function fieldErrors(error: unknown): Record<string, string> {
|
|
406
|
+
return isCmsError(error) && error.fields ? { ...error.fields } : {};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* The writable part of an entry in the API's shape: its declared fields. The rest (id, rev,
|
|
411
|
+
* owner, the dates, url, anything a plugin adds to the answer) is read-only, so the JSON tab
|
|
412
|
+
* shows it and ignores edits to it.
|
|
413
|
+
*/
|
|
414
|
+
export function writableEntryFields(fields: { readonly [name: string]: unknown }, declared: { readonly [name: string]: unknown }): Record<string, unknown> {
|
|
415
|
+
return Object.fromEntries(Object.entries(fields).filter(([name]) => Object.hasOwn(declared, name)));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** An entry as the content API answers it, as indented JSON for the editor's JSON tab. */
|
|
419
|
+
export async function entryJson(cms: CmsHost, route: string, record: RecordShape): Promise<string> {
|
|
420
|
+
const { collection } = routeResource(cms, route);
|
|
421
|
+
const url = collection ? (await cms.entryUrls(collection, [record])).get(record.id) ?? null : null;
|
|
422
|
+
return JSON.stringify({ ...record, ...(collection ? { url } : {}) }, null, 2);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface ImportReport {
|
|
426
|
+
created: number;
|
|
427
|
+
updated: number;
|
|
428
|
+
failed: { index: number; id: string | null; error: string; fields?: Record<string, string> }[];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** The most entries one import takes. */
|
|
432
|
+
export const IMPORT_LIMIT = 1000;
|
|
433
|
+
|
|
434
|
+
/** The entries an export or an upload holds: a list, or an export's `{ items }` document. */
|
|
435
|
+
export function importItems(parsed: unknown): Record<string, unknown>[] | string {
|
|
436
|
+
const list = Array.isArray(parsed) ? parsed : parsed && typeof parsed === 'object' && Array.isArray((parsed as { items?: unknown }).items) ? (parsed as { items: unknown[] }).items : null;
|
|
437
|
+
if (!list) return 'Send a list of entries, or an export with its items.';
|
|
438
|
+
if (list.length > IMPORT_LIMIT) return `Import at most ${IMPORT_LIMIT} entries at a time.`;
|
|
439
|
+
if (!list.every(item => item && typeof item === 'object' && !Array.isArray(item))) return 'Every entry is a JSON object.';
|
|
440
|
+
return list as Record<string, unknown>[];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Import entries in the API's shape, as an export wrote them: an entry whose `id` exists is
|
|
445
|
+
* updated, else one with the same slug; the rest are created, keeping their IDs so references
|
|
446
|
+
* between them hold. Each entry is written with the same checks as a save, and a failure
|
|
447
|
+
* leaves the others untouched. Media and terms are referenced by ID and must exist.
|
|
448
|
+
*/
|
|
449
|
+
export async function importEntries(cms: CmsHost, route: string, items: readonly Record<string, unknown>[], principal: Principal): Promise<ImportReport> {
|
|
450
|
+
const { resource } = routeResource(cms, route);
|
|
451
|
+
const repository = cms.resource(resource.id);
|
|
452
|
+
const report: ImportReport = { created: 0, updated: 0, failed: [] };
|
|
453
|
+
for (const [index, item] of items.entries()) {
|
|
454
|
+
const id = typeof item.id === 'string' && /^[A-Za-z0-9_-]{1,80}$/.test(item.id) ? item.id : null;
|
|
455
|
+
const fields = writableEntryFields(item, resource.fields);
|
|
456
|
+
try {
|
|
457
|
+
let existing = id ? await repository.get(id, { principal }) : null;
|
|
458
|
+
if (!existing && resource.fields.slug && typeof fields.slug === 'string' && fields.slug) {
|
|
459
|
+
// Slugs are unique per language: match the entry's language, or the default one.
|
|
460
|
+
const locale = resource.fields.locale ? typeof fields.locale === 'string' ? fields.locale : (await cms.languages()).default : null;
|
|
461
|
+
existing = (await repository.list({ where: { slug: fields.slug, ...(locale ? { locale } : {}) }, limit: 1 }, { principal })).records[0] ?? null;
|
|
462
|
+
}
|
|
463
|
+
if (existing) {
|
|
464
|
+
await repository.update(existing.id, fields, { principal, expectedRevision: existing.rev });
|
|
465
|
+
report.updated++;
|
|
466
|
+
} else {
|
|
467
|
+
await repository.create(fields, { principal, ...(id ? { id } : {}) });
|
|
468
|
+
report.created++;
|
|
469
|
+
}
|
|
470
|
+
} catch (error) {
|
|
471
|
+
if (!isCmsError(error)) throw error;
|
|
472
|
+
report.failed.push({ index, id, error: error.message, ...(error.fields ? { fields: { ...error.fields } } : {}) });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return report;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Up to `most` entries of a list, read in pages of 100 (the most one list call returns), for a picker's options. */
|
|
479
|
+
export async function listUpTo(cms: CmsHost, resourceId: string, options: Omit<ListOptions, 'limit' | 'offset'>, principal: Principal, most: number): Promise<RecordShape[]> {
|
|
480
|
+
const records: RecordShape[] = [];
|
|
481
|
+
for (let offset = 0; records.length < most; offset += 100) {
|
|
482
|
+
const page = await cms.resource(resourceId).list({ ...options, limit: Math.min(100, most - records.length), offset }, { principal });
|
|
483
|
+
records.push(...page.records);
|
|
484
|
+
if (!page.more || !page.records.length) break;
|
|
485
|
+
}
|
|
486
|
+
return records;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Every entry the principal may read, in the API's shape, in pages of 100, for an export. */
|
|
490
|
+
export async function* exportEntries(cms: CmsHost, route: string, principal: Principal): AsyncGenerator<Record<string, unknown>[]> {
|
|
491
|
+
const { resource, collection } = routeResource(cms, route);
|
|
492
|
+
const repository = cms.resource(resource.id);
|
|
493
|
+
for (let offset = 0; offset <= 10_000; offset += 100) {
|
|
494
|
+
const page = await repository.list({ order: { field: 'createdAt', direction: 'asc' }, limit: 100, offset }, { principal });
|
|
495
|
+
if (!page.records.length) return;
|
|
496
|
+
// An export goes back in through the import, so it holds whole entries: those the caller
|
|
497
|
+
// may change in full, others without their password, and none the caller could not open
|
|
498
|
+
// (a protected entry, or members-only for other roles).
|
|
499
|
+
const roles = principal.kind === 'user' ? principal.roles : [];
|
|
500
|
+
const records = page.records.flatMap(record => {
|
|
501
|
+
if (repository.canUpdate(record, principal)) return [record];
|
|
502
|
+
if (entryLock(record, { editor: false, signedIn: principal.kind === 'user', roles })) return [];
|
|
503
|
+
const { password: _password, ...rest } = record;
|
|
504
|
+
return [rest as RecordShape];
|
|
505
|
+
});
|
|
506
|
+
const urls = collection ? await cms.entryUrls(collection, records) : new Map<string, string | null>();
|
|
507
|
+
yield records.map(record => ({ ...record, ...(collection ? { url: urls.get(record.id) ?? null } : {}) }));
|
|
508
|
+
if (page.records.length < 100) return;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Save an entry from the JSON tab: the document is the API's shape, so read-only fields are
|
|
514
|
+
* dropped and the rest is written as a `PATCH /api/cms/content/<collection>/<id>` would be,
|
|
515
|
+
* through the same validation.
|
|
516
|
+
*/
|
|
517
|
+
export async function applyEntryJson(cms: CmsHost, route: string, id: string, text: string, revision: number, principal: Principal): Promise<RecordShape> {
|
|
518
|
+
let parsed: unknown;
|
|
519
|
+
try { parsed = JSON.parse(text); } catch (error) { throw new CmsError('CMS_VALIDATION', `The JSON is not valid: ${(error as Error).message}`); }
|
|
520
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new CmsError('CMS_VALIDATION', 'The JSON must be an object of the entry\'s fields.');
|
|
521
|
+
const { resource } = routeResource(cms, route);
|
|
522
|
+
const fields = writableEntryFields(parsed as Record<string, unknown>, resource.fields);
|
|
523
|
+
return cms.resource(resource.id).update(id, fields, { principal, expectedRevision: revision });
|
|
524
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser's part of a countdown block: the units tick every second until the moment, then
|
|
3
|
+
* the block shows what it was told to show after. The server wrote the first values.
|
|
4
|
+
*/
|
|
5
|
+
const enhanced = new WeakSet<HTMLElement>();
|
|
6
|
+
|
|
7
|
+
/** Days, hours, minutes and seconds between two moments; null once `until` has passed. */
|
|
8
|
+
export function remaining(until: number, now: number): { days: number; hours: number; minutes: number; seconds: number } | null {
|
|
9
|
+
const left = Math.floor((until - now) / 1000);
|
|
10
|
+
if (left <= 0) return null;
|
|
11
|
+
return { days: Math.floor(left / 86_400), hours: Math.floor((left % 86_400) / 3600), minutes: Math.floor((left % 3600) / 60), seconds: left % 60 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function enhanceCountdown(root: HTMLElement): void {
|
|
15
|
+
if (enhanced.has(root)) return;
|
|
16
|
+
enhanced.add(root);
|
|
17
|
+
const until = Number(root.dataset.until);
|
|
18
|
+
if (!Number.isFinite(until)) return;
|
|
19
|
+
const values = [...root.querySelectorAll<HTMLElement>('.cms-countdown-value')];
|
|
20
|
+
const units = root.querySelector<HTMLElement>('.cms-countdown-units');
|
|
21
|
+
const done = root.querySelector<HTMLElement>('.cms-countdown-done');
|
|
22
|
+
const tick = () => {
|
|
23
|
+
const left = remaining(until, Date.now());
|
|
24
|
+
if (!left) {
|
|
25
|
+
if (units) units.hidden = true;
|
|
26
|
+
if (done) done.hidden = false;
|
|
27
|
+
clearInterval(timer);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
for (const value of values) {
|
|
31
|
+
const unit = value.dataset.unit as 'days' | 'hours' | 'minutes' | 'seconds' | undefined;
|
|
32
|
+
if (unit && unit in left) value.textContent = unit === 'days' ? String(left[unit]) : String(left[unit]).padStart(2, '0');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const timer = setInterval(() => { if (!root.isConnected) clearInterval(timer); else tick(); }, 1000);
|
|
36
|
+
tick();
|
|
37
|
+
}
|