@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,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collections: content types such as posts, pages and products, defined as data. Each is a
|
|
3
|
+
* schemaless resource `cms/<name>` stored in its own document table; the host validates the
|
|
4
|
+
* fields. Built-in collections keep their core fields and accept added ones.
|
|
5
|
+
*/
|
|
6
|
+
import { blocksShapeProblem, type Block } from './blocks';
|
|
7
|
+
import { FIELD_NAME, field, fieldProblems, TAXONOMY_NAME, type FieldDeclaration } from './fields';
|
|
8
|
+
import { RESOURCE_NAME, type AccessRule, type ResourceDeclaration } from './resource';
|
|
9
|
+
import { collectionSeoProblems, type CollectionRobots, type CollectionSchema, type CollectionSeoTemplates } from './seo';
|
|
10
|
+
import { editorLayoutProblems, editorLayoutShapeProblem, type EditorLayout } from './editor-layout';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Entry states of a publishable collection. Pending entries wait for review; scheduled ones are
|
|
14
|
+
* published when their publication time comes. Trash keeps an entry until it is deleted.
|
|
15
|
+
*/
|
|
16
|
+
export const CONTENT_STATUSES = ['draft', 'pending', 'scheduled', 'published', 'trash'] as const;
|
|
17
|
+
export type ContentStatus = (typeof CONTENT_STATUSES)[number];
|
|
18
|
+
|
|
19
|
+
/** A language code in URLs and entries: `en`, `pt-br`, `zh-hans`. */
|
|
20
|
+
export const LOCALE = /^[a-z]{2,3}(?:-[a-z0-9]{2,8})?$/;
|
|
21
|
+
|
|
22
|
+
/** A language's own name, such as `Français` for `fr`. Client-safe: dashboards render it. */
|
|
23
|
+
/** The translation group of an entry: the group's first entry names it and keeps no group of its own. */
|
|
24
|
+
export function translationGroupOf(record: { readonly id: string; readonly translationGroup?: unknown }): string {
|
|
25
|
+
return typeof record.translationGroup === 'string' ? record.translationGroup : record.id;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function languageName(code: string): string {
|
|
29
|
+
try {
|
|
30
|
+
const name = new Intl.DisplayNames([code], { type: 'language' }).of(code) ?? code;
|
|
31
|
+
return name.charAt(0).toLocaleUpperCase(code) + name.slice(1);
|
|
32
|
+
} catch { return code; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The region whose flag stands for a language that names none, such as `vi` → Vietnam. */
|
|
36
|
+
const LANGUAGE_REGIONS: Readonly<Record<string, string>> = Object.freeze({
|
|
37
|
+
af: 'ZA', am: 'ET', ar: 'SA', az: 'AZ', be: 'BY', bg: 'BG', bn: 'BD', bs: 'BA', ca: 'ES', cs: 'CZ', cy: 'GB', da: 'DK', de: 'DE', el: 'GR', en: 'GB', es: 'ES', et: 'EE', eu: 'ES', fa: 'IR', fi: 'FI', fil: 'PH', fr: 'FR',
|
|
38
|
+
ga: 'IE', gl: 'ES', gu: 'IN', he: 'IL', hi: 'IN', hr: 'HR', hu: 'HU', hy: 'AM', id: 'ID', is: 'IS', it: 'IT', ja: 'JP', ka: 'GE', kk: 'KZ', km: 'KH', kn: 'IN', ko: 'KR', lo: 'LA', lt: 'LT', lv: 'LV', mk: 'MK', ml: 'IN', mn: 'MN',
|
|
39
|
+
mr: 'IN', ms: 'MY', mt: 'MT', my: 'MM', nb: 'NO', ne: 'NP', nl: 'NL', nn: 'NO', no: 'NO', pa: 'IN', pl: 'PL', pt: 'PT', ro: 'RO', ru: 'RU', si: 'LK', sk: 'SK', sl: 'SI', sq: 'AL', sr: 'RS', sv: 'SE', sw: 'KE', ta: 'IN', te: 'IN',
|
|
40
|
+
th: 'TH', tl: 'PH', tr: 'TR', uk: 'UA', ur: 'PK', uz: 'UZ', vi: 'VN', zh: 'CN',
|
|
41
|
+
});
|
|
42
|
+
/** Script subtags with a region of their own: traditional Chinese is Taiwan's. */
|
|
43
|
+
const SCRIPT_REGIONS: Readonly<Record<string, string>> = Object.freeze({ hant: 'TW', hans: 'CN' });
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A flag emoji for a language code, such as 🇻🇳 for `vi`, 🇧🇷 for `pt-br` and 🇹🇼 for
|
|
47
|
+
* `zh-hant`: the code's own region when it names one, otherwise the region most speakers
|
|
48
|
+
* associate with the language. Empty for a language without one. Client-safe.
|
|
49
|
+
*/
|
|
50
|
+
export function languageFlag(code: string): string {
|
|
51
|
+
const [language = '', subtag = ''] = code.toLowerCase().split('-');
|
|
52
|
+
const region = /^[a-z]{2}$/.test(subtag) ? subtag.toUpperCase() : SCRIPT_REGIONS[subtag] ?? LANGUAGE_REGIONS[language] ?? '';
|
|
53
|
+
if (!region) return '';
|
|
54
|
+
return [...region].map(letter => String.fromCodePoint(0x1f1e6 + letter.charCodeAt(0) - 65)).join('');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** An entry's search and sharing settings; each falls back to the entry's own values. */
|
|
58
|
+
export const SEO_FIELDS = Object.freeze({
|
|
59
|
+
title: field.string({ max: 200, label: 'SEO title' }),
|
|
60
|
+
description: field.text({ max: 500, label: 'Meta description' }),
|
|
61
|
+
image: field.media({ label: 'Social image' }),
|
|
62
|
+
canonical: field.string({ max: 2000, pattern: '(?:https?://[^\\s]+|/[^\\s]*)?', label: 'Canonical URL' }),
|
|
63
|
+
noindex: field.boolean({ label: 'Hide from search engines' }),
|
|
64
|
+
/** Engines may not quote the page in results and AI answers. */
|
|
65
|
+
nosnippet: field.boolean({ label: 'No snippets' }),
|
|
66
|
+
/** Characters engines may quote; empty for no limit. */
|
|
67
|
+
maxSnippet: field.integer({ min: 0, max: 100_000, label: 'Snippet length' }),
|
|
68
|
+
/** Bing keeps no cached copy, which also keeps the page out of Copilot's training. */
|
|
69
|
+
noarchive: field.boolean({ label: 'No cached copy' }),
|
|
70
|
+
/** Shared links carry these instead of the SEO title and description when set. */
|
|
71
|
+
socialTitle: field.string({ max: 200, label: 'Social title' }),
|
|
72
|
+
socialDescription: field.text({ max: 500, label: 'Social description' }),
|
|
73
|
+
/** One of the site's most important entries: listed first for assistants, and expected to have links from elsewhere. */
|
|
74
|
+
cornerstone: field.boolean({ label: 'Cornerstone content' }),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The standard fields and behaviours a collection turns on, with fixed names so themes and
|
|
79
|
+
* code can rely on `entry.content`, `entry.excerpt` and `entry.featuredImage`.
|
|
80
|
+
*/
|
|
81
|
+
export interface CollectionFeatures {
|
|
82
|
+
/** A `content` blocks field, searchable, which the content template fills; by hand, with the block types it allows. */
|
|
83
|
+
readonly content?: boolean | { readonly blocks?: readonly string[] };
|
|
84
|
+
/** An `excerpt` text field: a short summary for lists and feeds. */
|
|
85
|
+
readonly excerpt?: boolean;
|
|
86
|
+
/** A `featuredImage` media field in the sidebar. */
|
|
87
|
+
readonly featuredImage?: boolean;
|
|
88
|
+
/** A revision of every write, with compare and restore. Default true. */
|
|
89
|
+
readonly revisions?: boolean;
|
|
90
|
+
/** A `password` field: visitors type it to read the entry on the site, as WordPress protects posts. */
|
|
91
|
+
readonly password?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* A `membersOnly` switch and `memberRoles` in the sidebar: only signed-in users read the entry on
|
|
94
|
+
* the site, those with one of the roles when any is chosen; others see its title and a prompt.
|
|
95
|
+
*/
|
|
96
|
+
readonly members?: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The feature names that are fields; a feature off leaves its name reserved. */
|
|
100
|
+
export const FEATURE_FIELDS = Object.freeze(['content', 'excerpt', 'featuredImage', 'password', 'membersOnly', 'memberRoles'] as const);
|
|
101
|
+
|
|
102
|
+
/** The block types a content feature allows: `[]` for every type, null when it is off or malformed. */
|
|
103
|
+
export function contentBlocks(content: CollectionFeatures['content']): readonly string[] | null {
|
|
104
|
+
if (content === true) return [];
|
|
105
|
+
if (!content || typeof content !== 'object' || Array.isArray(content)) return null;
|
|
106
|
+
const blocks = content.blocks ?? [];
|
|
107
|
+
return Array.isArray(blocks) && blocks.every(type => typeof type === 'string') ? blocks : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface CollectionDefinition {
|
|
111
|
+
/** Lowercase name, such as `products`. The resource is `cms/<name>`. */
|
|
112
|
+
readonly name: string;
|
|
113
|
+
/** Plural label, such as `Products`. */
|
|
114
|
+
readonly label: string;
|
|
115
|
+
/** One entry, such as `Product`. */
|
|
116
|
+
readonly singular: string;
|
|
117
|
+
readonly description?: string;
|
|
118
|
+
/** Solar icon name for navigation, such as `box`. */
|
|
119
|
+
readonly icon?: string;
|
|
120
|
+
/** Derive a unique slug from the title. Default true. */
|
|
121
|
+
readonly slug?: boolean;
|
|
122
|
+
/** Draft, published and trash states with a publication time. Default true. */
|
|
123
|
+
readonly publishable?: boolean;
|
|
124
|
+
/** Entries nest through `parent`. Default false. */
|
|
125
|
+
readonly hierarchical?: boolean;
|
|
126
|
+
/** Taxonomies whose terms entries can carry, such as `categories`. */
|
|
127
|
+
readonly taxonomies?: readonly string[];
|
|
128
|
+
/**
|
|
129
|
+
* Public URL base: entries at `/<path>/<slug>`. `''` serves entries at the site root, as
|
|
130
|
+
* WordPress's "Post name" permalinks do; root slugs stay unique across root collections.
|
|
131
|
+
* Null or absent keeps them off the site.
|
|
132
|
+
*/
|
|
133
|
+
readonly path?: string | null;
|
|
134
|
+
/**
|
|
135
|
+
* What comes between the path and the slug: nothing (the default), or `category` for the
|
|
136
|
+
* slug of the entry's first term in the collection's first taxonomy, as WordPress's
|
|
137
|
+
* `/%category%/%postname%/` does. An entry without a term is at the plain address.
|
|
138
|
+
*/
|
|
139
|
+
readonly permalink?: 'slug' | 'category';
|
|
140
|
+
/** Entries on the site are listed in the XML sitemap. Default true. */
|
|
141
|
+
readonly sitemap?: boolean;
|
|
142
|
+
/** The structured data of entries on the site: their schema.org type and which fields fill it. Default `WebPage`. */
|
|
143
|
+
readonly schema?: CollectionSchema;
|
|
144
|
+
/** Robots directives of entries and the archive. Default: all indexed and followed. */
|
|
145
|
+
readonly robots?: CollectionRobots;
|
|
146
|
+
/** Title and description templates of entries and the archive; Settings → SEO's apply otherwise. */
|
|
147
|
+
readonly seoTemplates?: CollectionSeoTemplates;
|
|
148
|
+
/** Unpublishable collections: readable by anyone (`public`) or by permission (`private`, the default). */
|
|
149
|
+
readonly visibility?: 'public' | 'private';
|
|
150
|
+
/** Visitors can comment on published entries; each entry can close its comments. Default false. */
|
|
151
|
+
readonly comments?: boolean;
|
|
152
|
+
/** The standard fields and behaviours that are on. Built-in collections lock theirs. */
|
|
153
|
+
readonly features?: CollectionFeatures;
|
|
154
|
+
/**
|
|
155
|
+
* Fields declared by hand (modules and plugins), besides the core ones and the features'.
|
|
156
|
+
* Fields made in the dashboard live in field groups attached to the collection.
|
|
157
|
+
*/
|
|
158
|
+
readonly fields: { readonly [name: string]: FieldDeclaration };
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The blocks a new entry's content starts with, as WordPress's block templates: a structure
|
|
162
|
+
* such as a heading, an image and a rich text, with data blocks for what the entry stores.
|
|
163
|
+
* Needs the `content` feature.
|
|
164
|
+
*/
|
|
165
|
+
readonly template?: readonly Block[];
|
|
166
|
+
/** How far entries may change the template: `insert` keeps its blocks (no adding or removing), `all` keeps their order too. */
|
|
167
|
+
readonly templateLock?: 'all' | 'insert';
|
|
168
|
+
/**
|
|
169
|
+
* How the entry editor is arranged: tabs for the main column and the sidebar every tab shares,
|
|
170
|
+
* placing the editor's boxes (`editorBoxes`). Absent, the editor shows `defaultEditorLayout`.
|
|
171
|
+
*/
|
|
172
|
+
readonly editor?: EditorLayout;
|
|
173
|
+
/**
|
|
174
|
+
* The order of the fields, for built-in collections, whose module fields are not stored with
|
|
175
|
+
* the added ones. Fields it does not name follow in their declared order.
|
|
176
|
+
*/
|
|
177
|
+
readonly fieldOrder?: readonly string[];
|
|
178
|
+
/** Shipped with a module: core settings and fields cannot change, but fields can be added. */
|
|
179
|
+
readonly builtin?: boolean;
|
|
180
|
+
/** The plugin that ships the collection. Its entries are on the site and in the dashboard only while the plugin is active. */
|
|
181
|
+
readonly plugin?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Shipped with screens of its own, as forms are: the module or plugin owns its settings and
|
|
184
|
+
* fields, so the collection manager leaves it out, no field group can attach to it, and the
|
|
185
|
+
* dashboard cannot save it. Declared by the module or plugin, never from the dashboard.
|
|
186
|
+
*/
|
|
187
|
+
readonly managed?: boolean;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Field names the host derives from a definition. */
|
|
191
|
+
export const CORE_FIELDS = Object.freeze(['title', 'slug', 'status', 'publishedAt', 'unpublishAt', 'parent', 'menuOrder', 'authors', 'seo', 'summary', 'locale', 'translationGroup', 'commentsOpen', 'template']);
|
|
192
|
+
|
|
193
|
+
/** The users who wrote an entry, first its main author: its `authors`, or its creator for entries from before co-authors. */
|
|
194
|
+
export function entryAuthors(record: { readonly owner?: string | null; readonly [field: string]: unknown }): string[] {
|
|
195
|
+
const authors = Array.isArray(record.authors) ? record.authors.filter((id): id is string => typeof id === 'string' && id !== '') : [];
|
|
196
|
+
return authors.length ? [...new Set(authors)] : record.owner ? [record.owner] : [];
|
|
197
|
+
}
|
|
198
|
+
/** Field names no declared field or group field may take: the core fields and the features'. */
|
|
199
|
+
export const RESERVED_FIELDS = Object.freeze([...CORE_FIELDS, ...FEATURE_FIELDS]);
|
|
200
|
+
const FEATURES = Object.freeze(['content', 'excerpt', 'featuredImage', 'revisions', 'password', 'members'] as const);
|
|
201
|
+
/** A template an editor can choose for one entry: one of the active theme's `entry-*` templates. Empty for the default. */
|
|
202
|
+
export const ENTRY_TEMPLATE = 'entry-[a-z][a-z0-9_-]{0,73}';
|
|
203
|
+
const RESERVED = new Set(['media', 'users', 'roles', 'terms', 'settings', 'collections', 'taxonomies', 'blocks', 'plugins', 'schema', 'content', 'new']);
|
|
204
|
+
const PATH = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/;
|
|
205
|
+
const ICON = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
206
|
+
|
|
207
|
+
/** Problems in a collection definition; empty when valid. */
|
|
208
|
+
export function collectionProblems(definition: CollectionDefinition): string[] {
|
|
209
|
+
const problems: string[] = [];
|
|
210
|
+
if (typeof definition?.name !== 'string' || !RESOURCE_NAME.test(definition.name) || definition.name.includes('__')) problems.push('The name must be lowercase letters, digits and single underscores, starting with a letter.');
|
|
211
|
+
else if (RESERVED.has(definition.name)) problems.push(`${definition.name} is reserved.`);
|
|
212
|
+
// Form submissions are stored as cms/form_<form id>.
|
|
213
|
+
else if (definition.name.startsWith('form_')) problems.push('Names starting with form_ are reserved for form submissions.');
|
|
214
|
+
for (const key of ['label', 'singular'] as const) {
|
|
215
|
+
if (typeof definition?.[key] !== 'string' || !definition[key].trim() || definition[key].length > 60) problems.push(`The ${key === 'label' ? 'plural label' : 'singular label'} must be 1-60 characters.`);
|
|
216
|
+
}
|
|
217
|
+
if (definition.description !== undefined && (typeof definition.description !== 'string' || definition.description.length > 500)) problems.push('The description can be at most 500 characters.');
|
|
218
|
+
if (definition.icon !== undefined && (typeof definition.icon !== 'string' || !ICON.test(definition.icon))) problems.push('The icon must be a Solar icon name.');
|
|
219
|
+
if (definition.path !== undefined && definition.path !== null && definition.path !== '' && (typeof definition.path !== 'string' || !PATH.test(definition.path) || definition.path.length > 100)) problems.push('The URL path uses lowercase letters, digits, hyphens and slashes.');
|
|
220
|
+
if (definition.visibility !== undefined && !['public', 'private'].includes(definition.visibility)) problems.push('Visibility is public or private.');
|
|
221
|
+
if (definition.permalink !== undefined && !['slug', 'category'].includes(definition.permalink)) problems.push('The permalink structure is slug or category.');
|
|
222
|
+
if (definition.permalink === 'category' && !(definition.taxonomies ?? []).length) problems.push('Category permalinks need a taxonomy.');
|
|
223
|
+
if (definition.permalink === 'category' && definition.hierarchical) problems.push('Category permalinks do not apply to nested collections.');
|
|
224
|
+
if (definition.comments !== undefined && typeof definition.comments !== 'boolean') problems.push('Comments are on or off.');
|
|
225
|
+
if (definition.sitemap !== undefined && typeof definition.sitemap !== 'boolean') problems.push('The sitemap listing is on or off.');
|
|
226
|
+
if (definition.managed !== undefined && typeof definition.managed !== 'boolean') problems.push('Managed is on or off.');
|
|
227
|
+
problems.push(...collectionSeoProblems({ schema: definition.schema, robots: definition.robots, seoTemplates: definition.seoTemplates }));
|
|
228
|
+
const taxonomies = definition.taxonomies ?? [];
|
|
229
|
+
if (!Array.isArray(taxonomies) || taxonomies.length > 8 || taxonomies.some(name => typeof name !== 'string' || !TAXONOMY_NAME.test(name)) || new Set(taxonomies).size !== taxonomies.length) problems.push('Choose at most 8 distinct taxonomies.');
|
|
230
|
+
const fields = Object.entries(definition.fields ?? {});
|
|
231
|
+
if (fields.length > 32) problems.push('Add at most 32 fields.');
|
|
232
|
+
if (definition.features !== undefined && (definition.features === null || typeof definition.features !== 'object' || Array.isArray(definition.features)
|
|
233
|
+
|| Object.entries(definition.features).some(([name, value]) => !(FEATURES as readonly string[]).includes(name) || (typeof value !== 'boolean' && !(name === 'content' && contentBlocks(value) !== null))))) problems.push(`Features are ${FEATURES.join(', ')}, each on or off.`);
|
|
234
|
+
if (definition.template !== undefined) {
|
|
235
|
+
const shape = blocksShapeProblem(definition.template);
|
|
236
|
+
if (shape) problems.push(`The content template ${shape}`);
|
|
237
|
+
else if (definition.template.length > 50) problems.push('The content template holds at most 50 blocks.');
|
|
238
|
+
else if (definition.template.length && !definition.features?.content) problems.push('The content template needs the content feature.');
|
|
239
|
+
}
|
|
240
|
+
if (definition.templateLock !== undefined && !['all', 'insert'].includes(definition.templateLock)) problems.push('The template lock is all or insert.');
|
|
241
|
+
if (definition.editor !== undefined) {
|
|
242
|
+
const shape = editorLayoutShapeProblem(definition.editor);
|
|
243
|
+
if (shape) problems.push(`The editor layout ${shape}`);
|
|
244
|
+
else problems.push(...editorLayoutProblems(definition.editor).problems.map(problem => `Editor layout: ${problem}`));
|
|
245
|
+
}
|
|
246
|
+
if (definition.fieldOrder !== undefined && (!Array.isArray(definition.fieldOrder) || definition.fieldOrder.length > 64 || definition.fieldOrder.some(name => typeof name !== 'string' || !FIELD_NAME.test(name)))) problems.push('The field order names at most 64 fields.');
|
|
247
|
+
const taken = new Set([...RESERVED_FIELDS, ...taxonomies]);
|
|
248
|
+
for (const [name, declaration] of fields) {
|
|
249
|
+
if (taken.has(name)) problems.push((FEATURE_FIELDS as readonly string[]).includes(name) ? `${name} is a feature; turn it on instead of declaring it.` : `${name} is a core field of every collection.`);
|
|
250
|
+
if (!FIELD_NAME.test(name)) problems.push(`Field ${name}: names start with a lowercase letter and use letters and digits.`);
|
|
251
|
+
if (declaration?.kind === 'vector' || declaration?.kind === 'bigint') problems.push(`Field ${name}: ${declaration.kind} fields are not available in collections.`);
|
|
252
|
+
if (declaration?.taxonomy) problems.push(`Field ${name}: choose taxonomies on the collection instead.`);
|
|
253
|
+
problems.push(...fieldProblems(name, declaration ?? ({} as FieldDeclaration)).map(problem => problem.replace(/^field /, 'Field ')));
|
|
254
|
+
}
|
|
255
|
+
return problems;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** The resource for a collection: core fields from the definition, then its own. */
|
|
259
|
+
export function collectionResource(definition: CollectionDefinition, labels: { readonly [taxonomy: string]: string } = {}): ResourceDeclaration {
|
|
260
|
+
const id = `cms/${definition.name}`;
|
|
261
|
+
const slug = definition.slug !== false;
|
|
262
|
+
const publishable = definition.publishable !== false;
|
|
263
|
+
const features = definition.features ?? {};
|
|
264
|
+
const fields: { [name: string]: FieldDeclaration } = {
|
|
265
|
+
title: field.string({ required: true, max: 200, search: true, label: 'Title' }),
|
|
266
|
+
// Each language has its own slugs: /about and /fr/about can be translations of each other.
|
|
267
|
+
...(slug ? { slug: field.slug('title', { required: true, label: 'Slug', uniqueBy: ['locale'] }) } : {}),
|
|
268
|
+
// The content is blocks, as in WordPress; the Rich text block is the word processor among them.
|
|
269
|
+
...(contentBlocks(features.content) ? { content: field.blocks({ search: true, label: 'Content', ...(contentBlocks(features.content)!.length ? { blocks: contentBlocks(features.content)! } : {}) }) } : {}),
|
|
270
|
+
...(features.excerpt ? { excerpt: field.text({ max: 1000, label: 'Excerpt', description: 'A short summary for lists, feeds and link previews.' }) } : {}),
|
|
271
|
+
...(features.featuredImage ? { featuredImage: field.media({ placement: 'sidebar', label: 'Featured image' }) } : {}),
|
|
272
|
+
...(features.password ? { password: field.string({ max: 100, placement: 'sidebar', label: 'Password', description: 'Visitors type it to read this entry. Empty for none.' }) } : {}),
|
|
273
|
+
...(features.members ? {
|
|
274
|
+
membersOnly: field.boolean({ nullable: true, placement: 'sidebar', label: 'Members only', description: 'Only signed-in users read it; visitors see its title and a sign-in link.' }),
|
|
275
|
+
memberRoles: field.list('string', { max: 64, maxItems: 20, placement: 'sidebar', choicesFrom: 'roles', label: 'Member roles', description: 'With Members only: just these roles read it. None ticked: every signed-in user.' }),
|
|
276
|
+
} : {}),
|
|
277
|
+
...(publishable ? {
|
|
278
|
+
status: field.enum(CONTENT_STATUSES, { required: true, default: 'draft', index: true, label: 'Status' }),
|
|
279
|
+
publishedAt: field.datetime({ nullable: true, index: true, label: 'Published at' }),
|
|
280
|
+
// A published entry goes back to draft at this time; the scheduler clears it then.
|
|
281
|
+
unpublishAt: field.datetime({ nullable: true, index: true, label: 'Unpublish at' }),
|
|
282
|
+
} : {}),
|
|
283
|
+
...(definition.hierarchical ? {
|
|
284
|
+
parent: field.reference(id, { nullable: true, label: `Parent ${definition.singular.toLowerCase()}` }),
|
|
285
|
+
menuOrder: field.integer({ default: 0, min: -1000, max: 1000, label: 'Order' }),
|
|
286
|
+
} : {}),
|
|
287
|
+
// Who wrote the entry, as Git co-authors: user IDs, the first its main author. The repository fills in the creator; entries from before have none and read as their creator's.
|
|
288
|
+
authors: field.list('string', { max: 80, maxItems: 20, index: true, label: 'Authors' }),
|
|
289
|
+
seo: field.group(SEO_FIELDS, { label: 'SEO' }),
|
|
290
|
+
// The answer up front: two or three sentences themes show first, the meta description falls back to, and assistants quote.
|
|
291
|
+
...(typeof definition.path === 'string' ? { summary: field.text({ max: 600, label: 'Summary', description: 'Two or three sentences that answer what the entry is about.' }) } : {}),
|
|
292
|
+
// The entry's language, and the group its translations share; see Settings → Languages.
|
|
293
|
+
locale: field.string({ max: 16, nullable: true, index: true, pattern: LOCALE.source.slice(1, -1), label: 'Language' }),
|
|
294
|
+
translationGroup: field.string({ max: 80, nullable: true, index: true, pattern: '[A-Za-z0-9_-]{1,80}', label: 'Translations' }),
|
|
295
|
+
// New entries take Settings → Discussion's default; null reads as open.
|
|
296
|
+
...(definition.comments ? { commentsOpen: field.boolean({ nullable: true, label: 'Allow comments' }) } : {}),
|
|
297
|
+
// Entries on the site can use another of the active theme's templates.
|
|
298
|
+
...(typeof definition.path === 'string' ? { template: field.string({ max: 80, nullable: true, pattern: `(?:${ENTRY_TEMPLATE})?`, label: 'Template' }) } : {}),
|
|
299
|
+
};
|
|
300
|
+
for (const taxonomy of definition.taxonomies ?? []) fields[taxonomy] = field.terms(taxonomy, { label: labels[taxonomy] ?? taxonomy });
|
|
301
|
+
for (const [name, declaration] of Object.entries(definition.fields)) fields[name] = declaration;
|
|
302
|
+
const read: AccessRule = publishable ? { any: [{ where: { status: 'published' } }, 'owner', { permission: `${id}:read` }] }
|
|
303
|
+
: definition.visibility === 'public' ? 'public' : { any: ['owner', { permission: `${id}:read` }] };
|
|
304
|
+
return {
|
|
305
|
+
name: definition.name,
|
|
306
|
+
owner: 'cms',
|
|
307
|
+
label: definition.label,
|
|
308
|
+
titleField: 'title',
|
|
309
|
+
ownership: true,
|
|
310
|
+
coOwners: 'authors',
|
|
311
|
+
schemaless: true,
|
|
312
|
+
revisions: features.revisions !== false,
|
|
313
|
+
fields,
|
|
314
|
+
indexes: publishable ? [{ name: 'published', fields: ['status', 'publishedAt'] }] : [],
|
|
315
|
+
access: {
|
|
316
|
+
read,
|
|
317
|
+
create: { permission: `${id}:create` },
|
|
318
|
+
update: { any: ['owner', { permission: `${id}:update` }] },
|
|
319
|
+
delete: { any: ['owner', { permission: `${id}:delete` }] },
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The public URL of an entry: the collection's path, then its ancestors' slugs and its own. */
|
|
325
|
+
export function entryUrl(path: string | null | undefined, slugs: readonly string[]): string | null {
|
|
326
|
+
if (path === null || path === undefined || !slugs.length || slugs.some(slug => !slug)) return null;
|
|
327
|
+
return `/${[...(path ? [path] : []), ...slugs].join('/')}`;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Fields in the given order; fields it does not name follow in their own order. */
|
|
331
|
+
export function orderedFields<T>(fields: { readonly [name: string]: T }, order: readonly string[] = []): { [name: string]: T } {
|
|
332
|
+
const result: { [name: string]: T } = {};
|
|
333
|
+
for (const name of order) if (Object.hasOwn(fields, name)) result[name] = fields[name]!;
|
|
334
|
+
for (const [name, value] of Object.entries(fields)) if (!Object.hasOwn(result, name)) result[name] = value;
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* A built-in collection with what an administrator changed: labels, URL, comments, template,
|
|
340
|
+
* added taxonomies and features. Core settings, features and fields win.
|
|
341
|
+
*/
|
|
342
|
+
export function extendCollection(builtin: CollectionDefinition, stored: Partial<CollectionDefinition>): CollectionDefinition {
|
|
343
|
+
const added = Object.fromEntries(Object.entries(stored.fields ?? {}).filter(([name]) => !Object.hasOwn(builtin.fields, name)));
|
|
344
|
+
return {
|
|
345
|
+
...builtin,
|
|
346
|
+
label: stored.label ?? builtin.label,
|
|
347
|
+
singular: stored.singular ?? builtin.singular,
|
|
348
|
+
...(stored.description !== undefined ? { description: stored.description } : {}),
|
|
349
|
+
...(stored.icon !== undefined ? { icon: stored.icon } : {}),
|
|
350
|
+
...(stored.path !== undefined ? { path: builtin.path === '' ? '' : stored.path } : {}),
|
|
351
|
+
...(stored.permalink !== undefined ? { permalink: stored.permalink } : {}),
|
|
352
|
+
...(stored.sitemap !== undefined ? { sitemap: stored.sitemap } : {}),
|
|
353
|
+
...(stored.schema !== undefined ? { schema: stored.schema } : {}),
|
|
354
|
+
...(stored.robots !== undefined ? { robots: stored.robots } : {}),
|
|
355
|
+
...(stored.seoTemplates !== undefined ? { seoTemplates: stored.seoTemplates } : {}),
|
|
356
|
+
...(stored.comments !== undefined ? { comments: stored.comments } : {}),
|
|
357
|
+
...(stored.template !== undefined ? { template: stored.template } : {}),
|
|
358
|
+
...(stored.templateLock !== undefined ? { templateLock: stored.templateLock } : {}),
|
|
359
|
+
...(stored.editor !== undefined ? { editor: stored.editor } : {}),
|
|
360
|
+
|
|
361
|
+
// The module's features are locked; stored ones add to them.
|
|
362
|
+
...(builtin.features || stored.features ? { features: { ...stored.features, ...builtin.features } } : {}),
|
|
363
|
+
taxonomies: [...new Set([...(builtin.taxonomies ?? []), ...(stored.taxonomies ?? [])])],
|
|
364
|
+
fields: orderedFields({ ...builtin.fields, ...added }, stored.fieldOrder),
|
|
365
|
+
builtin: true,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Built-in posts: published to the blog, with categories, tags and an author. */
|
|
370
|
+
export const posts: CollectionDefinition = {
|
|
371
|
+
name: 'posts',
|
|
372
|
+
label: 'Posts',
|
|
373
|
+
singular: 'Post',
|
|
374
|
+
icon: 'document-text',
|
|
375
|
+
builtin: true,
|
|
376
|
+
taxonomies: ['categories', 'tags'],
|
|
377
|
+
path: 'posts',
|
|
378
|
+
comments: true,
|
|
379
|
+
schema: { type: 'BlogPosting' },
|
|
380
|
+
features: { content: true, excerpt: true, featuredImage: true, password: true, members: true },
|
|
381
|
+
fields: {
|
|
382
|
+
sticky: field.boolean({ default: false, placement: 'sidebar', label: 'Stick to the top of the blog' }),
|
|
383
|
+
},
|
|
384
|
+
template: [{ _id: 'text', type: 'core/richtext', data: {} }],
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
/** Built-in pages: nested; a page's URL is its ancestors' slugs. */
|
|
388
|
+
export const pages: CollectionDefinition = {
|
|
389
|
+
name: 'pages',
|
|
390
|
+
label: 'Pages',
|
|
391
|
+
singular: 'Page',
|
|
392
|
+
icon: 'notebook',
|
|
393
|
+
builtin: true,
|
|
394
|
+
hierarchical: true,
|
|
395
|
+
path: '',
|
|
396
|
+
schema: { type: 'WebPage' },
|
|
397
|
+
features: { content: true, excerpt: true, featuredImage: true, password: true, members: true },
|
|
398
|
+
fields: {},
|
|
399
|
+
template: [{ _id: 'text', type: 'core/richtext', data: {} }],
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Built-in patterns: saved blocks to reuse. A synced pattern is inserted as one Pattern block,
|
|
404
|
+
* so editing it changes every entry that uses it; an unsynced one is inserted as a copy of its
|
|
405
|
+
* blocks. Starter patterns are offered as the first content of new entries.
|
|
406
|
+
*/
|
|
407
|
+
export const patterns: CollectionDefinition = {
|
|
408
|
+
name: 'patterns',
|
|
409
|
+
label: 'Patterns',
|
|
410
|
+
singular: 'Pattern',
|
|
411
|
+
icon: 'widget-add',
|
|
412
|
+
builtin: true,
|
|
413
|
+
slug: false,
|
|
414
|
+
publishable: false,
|
|
415
|
+
visibility: 'private',
|
|
416
|
+
features: { content: true },
|
|
417
|
+
fields: {
|
|
418
|
+
synced: field.boolean({ default: true, placement: 'sidebar', label: 'Synced', description: 'Changes show everywhere the pattern is used.' }),
|
|
419
|
+
starter: field.list('string', { placement: 'sidebar', label: 'Starting layout for', description: 'Collections whose new entries can start from this pattern.' }),
|
|
420
|
+
},
|
|
421
|
+
};
|
package/src/comments.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Comments: statuses, shape and the checks of a posted comment. Client-safe; the host stores them. */
|
|
2
|
+
import { CmsError } from './errors';
|
|
3
|
+
|
|
4
|
+
export const COMMENT_STATUSES = Object.freeze(['pending', 'approved', 'spam', 'trash'] as const);
|
|
5
|
+
export type CommentStatus = (typeof COMMENT_STATUSES)[number];
|
|
6
|
+
|
|
7
|
+
export interface CommentShape {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/** The entry's resource, such as `cms/posts`, and ID. */
|
|
10
|
+
readonly resource: string;
|
|
11
|
+
readonly recordId: string;
|
|
12
|
+
readonly parentId: string | null;
|
|
13
|
+
/** The signed-in author, if any. */
|
|
14
|
+
readonly userId: string | null;
|
|
15
|
+
readonly authorName: string;
|
|
16
|
+
readonly authorEmail: string;
|
|
17
|
+
readonly authorUrl: string;
|
|
18
|
+
readonly content: string;
|
|
19
|
+
readonly status: CommentStatus;
|
|
20
|
+
readonly createdAt: number;
|
|
21
|
+
readonly updatedAt: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CommentRow extends CommentShape {
|
|
25
|
+
readonly ipHash: string | null;
|
|
26
|
+
readonly userAgent: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Trimmed comment fields, or a validation error naming the fields. */
|
|
30
|
+
export function checkComment(input: { content?: unknown; authorName?: unknown; authorEmail?: unknown; authorUrl?: unknown }, requireNameEmail: boolean): { content: string; authorName: string; authorEmail: string; authorUrl: string } {
|
|
31
|
+
const errors: { [field: string]: string } = {};
|
|
32
|
+
const text = (value: unknown) => typeof value === 'string' ? value.trim() : '';
|
|
33
|
+
const content = text(input.content).replace(/\r\n?/g, '\n');
|
|
34
|
+
const authorName = text(input.authorName);
|
|
35
|
+
const authorEmail = text(input.authorEmail).toLowerCase();
|
|
36
|
+
const authorUrl = text(input.authorUrl);
|
|
37
|
+
if (!content) errors.content = 'Write a comment.';
|
|
38
|
+
else if ([...content].length > 5000) errors.content = 'Comments can be at most 5000 characters.';
|
|
39
|
+
if (requireNameEmail && !authorName) errors.authorName = 'Enter your name.';
|
|
40
|
+
if (authorName.length > 100) errors.authorName = 'Names can be at most 100 characters.';
|
|
41
|
+
if (requireNameEmail && !authorEmail) errors.authorEmail = 'Enter your email address.';
|
|
42
|
+
else if (authorEmail && (authorEmail.length > 254 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(authorEmail))) errors.authorEmail = 'Enter a valid email address.';
|
|
43
|
+
if (authorUrl && (authorUrl.length > 200 || !/^https?:\/\/[^\s]+$/.test(authorUrl))) errors.authorUrl = 'Enter a website starting with https://.';
|
|
44
|
+
if (Object.keys(errors).length) throw new CmsError('CMS_VALIDATION', Object.values(errors).join(' '), { fields: errors });
|
|
45
|
+
return { content, authorName, authorEmail, authorUrl };
|
|
46
|
+
}
|
package/src/cron.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Five-field UTC cron expressions as Cloudflare's cron triggers read them: minute, hour, day of
|
|
3
|
+
* month, month and day of week (1 = Sunday to 7 = Saturday; `JAN`, `MON` names allowed), each a
|
|
4
|
+
* `*`, a number, a range, a list or a step. When both the day of month and the day of week are
|
|
5
|
+
* restricted, a day matches either. `nextCronTime` finds the next matching minute after a
|
|
6
|
+
* moment; plugin schedules run from it. Pure functions; no I/O.
|
|
7
|
+
*/
|
|
8
|
+
import { validateScheduleCron } from '@cossackframework/core/schedules';
|
|
9
|
+
|
|
10
|
+
export interface CronFields {
|
|
11
|
+
readonly minutes: readonly number[];
|
|
12
|
+
readonly hours: readonly number[];
|
|
13
|
+
/** Days of the month, 1 to 31; empty when unrestricted. */
|
|
14
|
+
readonly days: readonly number[];
|
|
15
|
+
readonly months: readonly number[];
|
|
16
|
+
/** Days of the week, 1 (Sunday) to 7 (Saturday); empty when unrestricted. */
|
|
17
|
+
readonly weekdays: readonly number[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
|
21
|
+
const WEEKDAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
|
|
22
|
+
const LIMITS: readonly (readonly [number, number])[] = [[0, 59], [0, 23], [1, 31], [1, 12], [1, 7]];
|
|
23
|
+
/** How far ahead an occurrence is looked for: a yearly schedule on February 29 needs four years. */
|
|
24
|
+
const HORIZON_DAYS = 366 * 5;
|
|
25
|
+
|
|
26
|
+
/** The expression's fields as sorted numbers; throws on a malformed expression. */
|
|
27
|
+
export function parseCron(expression: string): CronFields {
|
|
28
|
+
const fields = validateScheduleCron(expression).split(' ');
|
|
29
|
+
const sets = fields.map((field, index) => {
|
|
30
|
+
const [min, max] = LIMITS[index]!;
|
|
31
|
+
const names = index === 3 ? MONTHS : index === 4 ? WEEKDAYS : [];
|
|
32
|
+
const number = (part: string): number => { const alias = names.indexOf(part); return alias >= 0 ? alias + 1 : Number(part); };
|
|
33
|
+
const values = new Set<number>();
|
|
34
|
+
for (const item of field.split(',')) {
|
|
35
|
+
const [base, stepText] = item.split('/');
|
|
36
|
+
const step = stepText ? Number(stepText) : 1;
|
|
37
|
+
let start = min;
|
|
38
|
+
let end = max;
|
|
39
|
+
if (base !== '*') {
|
|
40
|
+
const range = base!.split('-');
|
|
41
|
+
start = number(range[0]!);
|
|
42
|
+
end = range.length === 2 ? number(range[1]!) : stepText ? max : start;
|
|
43
|
+
}
|
|
44
|
+
for (let value = start; value <= end; value += step) values.add(value);
|
|
45
|
+
}
|
|
46
|
+
const all = values.size === max - min + 1;
|
|
47
|
+
// An unrestricted day field is "any", which matters when the other day field restricts.
|
|
48
|
+
return { values: [...values].sort((a, b) => a - b), all };
|
|
49
|
+
});
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
minutes: sets[0]!.values, hours: sets[1]!.values,
|
|
52
|
+
days: sets[2]!.all ? [] : sets[2]!.values, months: sets[3]!.values,
|
|
53
|
+
weekdays: sets[4]!.all ? [] : sets[4]!.values,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether the UTC day of this moment is one the expression names. */
|
|
58
|
+
function dayMatches(fields: CronFields, date: Date): boolean {
|
|
59
|
+
if (!fields.months.includes(date.getUTCMonth() + 1)) return false;
|
|
60
|
+
const day = fields.days.length === 0 || fields.days.includes(date.getUTCDate());
|
|
61
|
+
const weekday = fields.weekdays.length === 0 || fields.weekdays.includes(date.getUTCDay() + 1);
|
|
62
|
+
if (fields.days.length && fields.weekdays.length) return day || weekday;
|
|
63
|
+
return day && weekday;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The first minute after `after` (exclusive) the expression names, in milliseconds since the
|
|
68
|
+
* epoch. Walks days, then the named hours and minutes within a matching day. Throws when
|
|
69
|
+
* nothing matches within five years (an impossible date such as `0 0 30 2 *`).
|
|
70
|
+
*/
|
|
71
|
+
export function nextCronTime(expression: string | CronFields, after: number): number {
|
|
72
|
+
const fields = typeof expression === 'string' ? parseCron(expression) : expression;
|
|
73
|
+
const start = Math.floor(after / 60_000) * 60_000 + 60_000;
|
|
74
|
+
const first = new Date(start);
|
|
75
|
+
for (let offset = 0; offset < HORIZON_DAYS; offset++) {
|
|
76
|
+
const day = new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth(), first.getUTCDate() + offset));
|
|
77
|
+
if (!dayMatches(fields, day)) continue;
|
|
78
|
+
const sameDay = offset === 0;
|
|
79
|
+
for (const hour of fields.hours) {
|
|
80
|
+
if (sameDay && hour < first.getUTCHours()) continue;
|
|
81
|
+
for (const minute of fields.minutes) {
|
|
82
|
+
if (sameDay && hour === first.getUTCHours() && minute < first.getUTCMinutes()) continue;
|
|
83
|
+
return Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), day.getUTCDate(), hour, minute);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`The schedule ${typeof expression === 'string' ? expression : ''} never comes.`.replace(' ', ' '));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The expression's problem as a sentence, or null when it is valid and has an occurrence. */
|
|
91
|
+
export function cronProblem(expression: unknown): string | null {
|
|
92
|
+
if (typeof expression !== 'string') return 'must be a five-field cron expression.';
|
|
93
|
+
try { nextCronTime(expression, Date.now()); return null; }
|
|
94
|
+
catch (error) { return /never comes/.test((error as Error).message) ? 'names a day that never comes.' : 'is not a five-field UTC cron expression (minute hour day month weekday).'; }
|
|
95
|
+
}
|