@cossackframework/cms 0.0.0 → 0.9.2
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 +145 -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 +21 -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 +709 -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 +114 -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 +62 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +22 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +28 -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 +18 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +2 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +43 -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 +82 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +205 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +124 -0
- package/app/src/pages/auth/reset-password/index.ts +74 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +69 -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 +183 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +227 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +249 -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 +114 -2
- 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,48 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { isSameOriginPost } from '@cossackframework/cms';
|
|
3
|
+
import { passesBotCheck } from '#app/auth-bot-check';
|
|
4
|
+
import { auth, completeTwoFactor, beginTwoFactor, createSession, loginUser, logout, SignInLockedError, SignInPasskeyError } from '#app/auth';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* JSON sign-in for tools such as `cossack <plugin>:<command>`: `{ email, password }` answers
|
|
8
|
+
* with the session cookie. Accounts with an authenticator app also send `code`; without it the
|
|
9
|
+
* answer is 401 `{ twoFactorRequired: true }`. While the Turnstile bot check is on, `turnstile`
|
|
10
|
+
* carries its token (403 `CMS_BOT_CHECK` without one). The auth kit refuses cross-site requests and
|
|
11
|
+
* non-JSON bodies.
|
|
12
|
+
*/
|
|
13
|
+
export const POST = auth.createLoginHandler({
|
|
14
|
+
// The session records whether the sign-in used a code, which required two-step sign-in asks of it.
|
|
15
|
+
createSession: (user, c) => createSession(user.id, c, { secondFactor: c.get('cms.signInSecondFactor') === true }),
|
|
16
|
+
validateCredentials: async (credentials, c) => {
|
|
17
|
+
const { email, password, code, turnstile } = credentials as { email?: unknown; password?: unknown; code?: unknown; turnstile?: unknown };
|
|
18
|
+
if (typeof email !== 'string' || typeof password !== 'string') return null;
|
|
19
|
+
// The sign-in form's bot check guards this door too; tools sign in with an application password instead.
|
|
20
|
+
if (!(await passesBotCheck(turnstile, 'login'))) return Response.json({ error: 'This site checks sign-ins for bots: send a Turnstile token as `turnstile`, or use an application password (`--token`).', code: 'CMS_BOT_CHECK' }, { status: 403 });
|
|
21
|
+
let user: Awaited<ReturnType<typeof loginUser>>;
|
|
22
|
+
try { user = await loginUser(email, password); }
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (!(error instanceof SignInLockedError)) throw error;
|
|
25
|
+
return Response.json({ error: error.message, code: 'CMS_RATE_LIMITED' }, { status: 429, headers: { 'retry-after': String(Math.ceil(error.retryAfterMs / 1000)) } });
|
|
26
|
+
}
|
|
27
|
+
if (!user) return null;
|
|
28
|
+
let pending: string | null;
|
|
29
|
+
try { pending = await beginTwoFactor(user.id); }
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (!(error instanceof SignInPasskeyError)) throw error;
|
|
32
|
+
return Response.json({ error: error.message, code: 'CMS_PASSKEY_REQUIRED' }, { status: 401 });
|
|
33
|
+
}
|
|
34
|
+
if (!pending) return user;
|
|
35
|
+
if (typeof code !== 'string' || !code.trim()) return Response.json({ error: 'Enter the code from your authenticator app.', twoFactorRequired: true }, { status: 401 });
|
|
36
|
+
const result = await completeTwoFactor(pending, code);
|
|
37
|
+
if ('user' in result) c.set('cms.signInSecondFactor', true);
|
|
38
|
+
return 'user' in result ? result.user : Response.json({ error: result.error, twoFactorRequired: true }, { status: 401 });
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** End the session the cookie names: `DELETE /api/auth/session`, same-origin, for tools that signed in to create an application password. */
|
|
43
|
+
export const DELETE = async (c: Context) => {
|
|
44
|
+
if (!c.get('user')) return c.json({ error: 'No session.', code: 'CMS_UNAUTHENTICATED' }, 401);
|
|
45
|
+
if (!isSameOriginPost(c.req.raw)) return c.json({ error: 'Cross-site requests are not allowed.', code: 'CMS_FORBIDDEN' }, 403);
|
|
46
|
+
const { headers } = await logout(c);
|
|
47
|
+
return new Response(null, { status: 204, headers });
|
|
48
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { areaRead, areaReset, areaUpdate } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** One widget area with its blocks and `rev` (0 while the theme's defaults show): `GET /api/cms/appearance/areas/<name>`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => areaRead(c, c.req.param('name') ?? ''));
|
|
7
|
+
|
|
8
|
+
/** Replace an area's blocks: `PUT /api/cms/appearance/areas/<name>` with `{ blocks, rev? }`; `rev` is the revision read, stale answers 409. */
|
|
9
|
+
export const PUT = (c: Context) => answer(c, body => areaUpdate(c, c.req.param('name') ?? '', body), { write: true });
|
|
10
|
+
|
|
11
|
+
/** Forget the area's saved blocks so the theme's defaults show again: `DELETE /api/cms/appearance/areas/<name>`. */
|
|
12
|
+
export const DELETE = (c: Context) => answer(c, () => areaReset(c, c.req.param('name') ?? ''), { write: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { areasList } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** The themes' widget areas (the active theme's first) with the blocks each shows, the theme's defaults until the site saves its own: `GET /api/cms/appearance/areas`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => areasList(c));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { menuLocationAssign } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** Show a menu at a location, or none: `PATCH /api/cms/appearance/locations/<location>` with `{ menu: "<id>" }` or `{ menu: null }`. */
|
|
6
|
+
export const PATCH = (c: Context) => answer(c, body => menuLocationAssign(c, c.req.param('location') ?? '', body), { write: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { menuLocationsList } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** The themes' menu locations (the active theme's first) and the menu at each: `GET /api/cms/appearance/locations`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => menuLocationsList(c));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { menuDelete, menuRead, menuUpdate } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** One menu with its items tree, `rev` and locations: `GET /api/cms/appearance/menus/<id>`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => menuRead(c, c.req.param('id') ?? ''));
|
|
7
|
+
|
|
8
|
+
/** Rename a menu, replace its items or move it: `PATCH /api/cms/appearance/menus/<id>` with any of `name`, `items`, `locations`, and `rev` (the revision read; stale answers 409). */
|
|
9
|
+
export const PATCH = (c: Context) => answer(c, body => menuUpdate(c, c.req.param('id') ?? '', body), { write: true });
|
|
10
|
+
|
|
11
|
+
/** Delete a menu; the locations it held show none: `DELETE /api/cms/appearance/menus/<id>`. */
|
|
12
|
+
export const DELETE = (c: Context) => answer(c, () => menuDelete(c, c.req.param('id') ?? ''), { write: true });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { menuCreate, menusList } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** The site's menus with how many items each has and where it shows: `GET /api/cms/appearance/menus`. Needs the appearance permission. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => menusList(c));
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A new menu: `POST /api/cms/appearance/menus` with `{ name, items?, locations? }`. Items are a
|
|
10
|
+
* tree (`kind`, `label`, the target, `description`, `panel`, `children`, …) and may leave out
|
|
11
|
+
* their IDs; `locations` names the theme locations the menu shows in.
|
|
12
|
+
*/
|
|
13
|
+
export const POST = (c: Context) => answer(c, body => menuCreate(c, body), { write: true, status: 201 });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { themeActivate } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** Make a theme the site's: `POST /api/cms/appearance/themes/<name>/activate`. */
|
|
6
|
+
export const POST = (c: Context) => answer(c, () => themeActivate(c, c.req.param('name') ?? ''), { write: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { themesList } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** The themes the site may use, the active one marked: `GET /api/cms/appearance/themes`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => themesList(c));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { cachePurge } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** Purge the caches in front of the site: `POST /api/cms/cache/purge` with `{ tags?, urls? }`, or `{}` for every page. */
|
|
6
|
+
export const POST = (c: Context) => answer(c, body => cachePurge(c, body), { write: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { collectionsList } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** The site's content types with their fields: `GET /api/cms/collections`. The JSON Schema of one is at `/api/cms/schema/<collection>`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, async () => collectionsList(c));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { commandInput, isCmsError, isSameOriginPost } from '@cossackframework/cms';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin commands (`cossack <plugin>:<command>`) run here, as the signed-in user, behind the
|
|
6
|
+
* same permissions as the dashboard. Input is checked against the manifest's options.
|
|
7
|
+
*/
|
|
8
|
+
export const POST = async (c: Context) => {
|
|
9
|
+
if (!isSameOriginPost(c.req.raw)) return c.json({ error: 'Forbidden', code: 'CMS_FORBIDDEN' }, 403);
|
|
10
|
+
const cms = c.get('cms');
|
|
11
|
+
const plugin = c.req.param('plugin') ?? '';
|
|
12
|
+
const name = c.req.param('command') ?? '';
|
|
13
|
+
const declared = cms.commands().find(entry => entry.plugin === plugin && entry.command.name === name);
|
|
14
|
+
if (!declared) return c.json({ error: `Unknown command ${plugin}:${name}.`, code: 'CMS_NOT_FOUND' }, 404);
|
|
15
|
+
let body: { input?: Record<string, unknown> };
|
|
16
|
+
try { body = await c.req.json(); } catch { return c.json({ error: 'Send a JSON body.', code: 'CMS_VALIDATION' }, 400); }
|
|
17
|
+
const { values, problems } = commandInput(declared.command, body.input ?? {});
|
|
18
|
+
if (problems.length) return c.json({ error: problems.join(' '), code: 'CMS_VALIDATION' }, 422);
|
|
19
|
+
try {
|
|
20
|
+
const result = await cms.runCommand(plugin, name, values, { principal: c.get('principal'), signal: c.req.raw.signal });
|
|
21
|
+
return c.json({ result: result ?? null });
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (isCmsError(error)) return c.json({ error: error.message, code: error.code }, error.status as 401 | 403 | 404 | 409 | 422 | 503);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { commentDelete, commentModerate } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** Moderate a comment: `PATCH /api/cms/comments/<id>` with `{ status: approved | pending | spam | trash }`. */
|
|
6
|
+
export const PATCH = (c: Context) => answer(c, body => commentModerate(c, c.req.param('id') ?? '', body), { write: true });
|
|
7
|
+
|
|
8
|
+
/** Delete a comment for good: `DELETE /api/cms/comments/<id>`. */
|
|
9
|
+
export const DELETE = (c: Context) => answer(c, () => commentDelete(c, c.req.param('id') ?? ''), { write: true });
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { createTurnstileVerifier } from '@cossackframework/auth/turnstile';
|
|
3
|
+
import { isCmsError, isSameOriginPost, systemPrincipal, type CommentShape } from '@cossackframework/cms';
|
|
4
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
5
|
+
import { getCookie } from 'hono/cookie';
|
|
6
|
+
import { getClientIp } from '@cossackframework/core';
|
|
7
|
+
import { apiError, cappedRequest } from '#app/cms/content-api';
|
|
8
|
+
import { mailOrigin } from '#app/cms/seo';
|
|
9
|
+
import { isMembersOnly, isProtected, requestLock, unlockCookie } from '#app/cms/site';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Approved comments of an entry, oldest first, for headless sites:
|
|
13
|
+
* `GET /api/cms/comments?collection=posts&entry=<id>`. Replies name their `parentId`.
|
|
14
|
+
*/
|
|
15
|
+
export const GET = async (c: Context) => {
|
|
16
|
+
const cms = c.get('cms');
|
|
17
|
+
try {
|
|
18
|
+
const collection = cms.collection(c.req.query('collection') ?? '');
|
|
19
|
+
const entry = await cms.resource(`cms/${collection.name}`).get(c.req.query('entry') ?? '', { principal: { kind: 'anonymous' } });
|
|
20
|
+
// A locked entry's discussion is as locked as its content.
|
|
21
|
+
const lock = entry ? await lockedFor(c, cms, collection.name, entry) : null;
|
|
22
|
+
if (!collection.comments || !entry || !lock || lock.locked) return c.json({ error: 'Entry not found.', code: 'CMS_NOT_FOUND' }, 404);
|
|
23
|
+
const comments = await cms.comments.forEntry(`cms/${collection.name}`, entry.id);
|
|
24
|
+
// Protected and members-only entries answer per reader: never from a shared cache.
|
|
25
|
+
c.header('cache-control', lock.lockable ? 'private, no-store' : 'public, max-age=60');
|
|
26
|
+
return c.json({ items: comments.map(comment => ({ id: comment.id, parentId: comment.parentId, author: comment.authorName, authorUrl: comment.authorUrl || null, content: comment.content, createdAt: comment.createdAt })) });
|
|
27
|
+
} catch (error) { return apiError(c, error); }
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The largest comment body read: the fields are short text, well under this. */
|
|
31
|
+
const COMMENT_MAX_BYTES = 64 * 1024;
|
|
32
|
+
|
|
33
|
+
/** What went wrong, for the form's message after a redirect. */
|
|
34
|
+
const REASONS: Record<string, string> = { CMS_FORBIDDEN: 'closed', CMS_UNAUTHENTICATED: 'sign-in', CMS_LIMIT: 'too-fast', CMS_VALIDATION: 'invalid', CMS_NOT_FOUND: 'closed' };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Post a comment from the site's form (`collection`, `entry`, `parent`, `content`,
|
|
38
|
+
* `authorName`, `authorEmail`, `authorUrl`) or as JSON. Forms return to the entry; JSON
|
|
39
|
+
* answers with the comment's status. Turnstile checks the form when its keys are set.
|
|
40
|
+
*/
|
|
41
|
+
export const POST = async (c: Context) => {
|
|
42
|
+
if (!isSameOriginPost(c.req.raw)) return c.json({ error: 'Cross-site comments are not allowed.', code: 'CMS_FORBIDDEN' }, 403);
|
|
43
|
+
const cms = c.get('cms');
|
|
44
|
+
const json = (c.req.header('content-type') ?? '').includes('application/json');
|
|
45
|
+
// A comment is a few kilobytes of text; the body is read only up to this.
|
|
46
|
+
const request = await cappedRequest(c, COMMENT_MAX_BYTES);
|
|
47
|
+
if (!request) return c.json({ error: 'The comment is too long.', code: 'CMS_LIMIT' }, 413);
|
|
48
|
+
let input: Record<string, string>;
|
|
49
|
+
try {
|
|
50
|
+
const raw = json ? await request.json() as Record<string, unknown> : Object.fromEntries(await request.formData());
|
|
51
|
+
input = Object.fromEntries(Object.entries(raw).map(([key, value]) => [key, typeof value === 'string' ? value : '']));
|
|
52
|
+
} catch { return c.json({ error: 'Send the comment as a form or JSON.', code: 'CMS_VALIDATION' }, 400); }
|
|
53
|
+
const back = async (reason: string, url: string | null) => c.redirect(`${url ?? '/'}?comment=${reason}#comments`, 303);
|
|
54
|
+
// The address the deployment trusts (TRUSTED_PROXY_HEADER, or the socket), not a header anyone can send.
|
|
55
|
+
const address = getClientIp(c);
|
|
56
|
+
const ip = address && address !== 'anonymous' ? address : undefined;
|
|
57
|
+
const secret = env('TURNSTILE_SECRET_KEY', '');
|
|
58
|
+
if (secret && env('TURNSTILE_SITE_KEY', '')) {
|
|
59
|
+
const verifier = createTurnstileVerifier({ secret, expectedHostname: env('TURNSTILE_HOSTNAME', '') || new URL(c.req.url).hostname, expectedAction: 'comment' });
|
|
60
|
+
const verdict = await verifier.verify({ token: input['cf-turnstile-response'] ?? input.turnstile, ...(ip && /^[a-fA-F0-9:.]{1,64}$/.test(ip) ? { remoteIP: ip } : {}) });
|
|
61
|
+
if (!verdict.success) return json ? c.json({ error: 'The check against bots failed. Try again.', code: 'CMS_FORBIDDEN' }, 403) : back('bot', await entryUrl(cms, input));
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const target = await commentTarget(cms, input);
|
|
65
|
+
if (target && (await lockedFor(c, cms, target.collection, target.entry)).locked) return json ? c.json({ error: 'Entry not found.', code: 'CMS_NOT_FOUND' }, 404) : back('closed', await entryUrl(cms, input));
|
|
66
|
+
const posted = await cms.postComment({
|
|
67
|
+
collection: input.collection ?? '', entry: input.entry ?? '', parent: input.parent || null, content: input.content ?? '',
|
|
68
|
+
authorName: input.authorName ?? '', authorEmail: input.authorEmail ?? '', authorUrl: input.authorUrl ?? '', trap: input.website ?? '',
|
|
69
|
+
}, { principal: c.get('principal'), ...(ip ? { ip } : {}), userAgent: c.req.header('user-agent') ?? '' });
|
|
70
|
+
notify(c, cms, posted.comment, posted.entry.title as string, posted.entry.owner, posted.url);
|
|
71
|
+
if (json) return c.json({ comment: { id: posted.comment.id, status: posted.comment.status } }, 201);
|
|
72
|
+
// Spam is treated like a held comment, so bots learn nothing.
|
|
73
|
+
return c.redirect(`${posted.url ?? '/'}?comment=${posted.comment.status === 'approved' ? 'posted' : 'held'}#${posted.comment.status === 'approved' ? `comment-${posted.comment.id}` : 'comments'}`, 303);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (json || !isCmsError(error)) return apiError(c, error);
|
|
76
|
+
return back(REASONS[error.code] ?? 'invalid', await entryUrl(cms, input));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** The entry's lock for this request's reader (a password not typed, or members only), and whether it has one at all. */
|
|
81
|
+
async function lockedFor(c: Context, cms: CmsHost, collection: string, entry: { id: string }): Promise<{ locked: boolean; lockable: boolean }> {
|
|
82
|
+
// The anonymous read leaves the password out; the lock needs the stored one.
|
|
83
|
+
const record = await cms.resource(`cms/${collection}`).get(entry.id, { principal: systemPrincipal('comments') });
|
|
84
|
+
if (!record) return { locked: true, lockable: true };
|
|
85
|
+
const lockable = isProtected(record) || isMembersOnly(record);
|
|
86
|
+
return { locked: lockable && await requestLock(cms, record, `cms/${collection}`, c.get('principal'), getCookie(c, unlockCookie(record))) !== null, lockable };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function commentTarget(cms: CmsHost, input: Record<string, string>): Promise<{ collection: string; entry: Record<string, unknown> & { id: string } } | null> {
|
|
90
|
+
try {
|
|
91
|
+
const collection = cms.collection(input.collection ?? '');
|
|
92
|
+
const entry = await cms.resource(`cms/${collection.name}`).get(input.entry ?? '', { principal: { kind: 'anonymous' } });
|
|
93
|
+
return entry ? { collection: collection.name, entry } : null;
|
|
94
|
+
} catch { return null; }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function entryUrl(cms: CmsHost, input: Record<string, string>): Promise<string | null> {
|
|
98
|
+
try {
|
|
99
|
+
const collection = cms.collection(input.collection ?? '');
|
|
100
|
+
const entry = await cms.resource(`cms/${collection.name}`).get(input.entry ?? '', { principal: { kind: 'anonymous' } });
|
|
101
|
+
return entry ? (await cms.entryUrls(collection, [entry])).get(entry.id) ?? null : null;
|
|
102
|
+
} catch { return null; }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Email the site and the entry's author about the comment, as Settings → Discussion asks. Needs a mail sender (`EMAIL`). */
|
|
106
|
+
function notify(c: Context, cms: CmsHost, comment: CommentShape, title: string, owner: string | null, url: string | null): void {
|
|
107
|
+
const mail = cms.mail;
|
|
108
|
+
if (!mail || comment.status === 'spam') return;
|
|
109
|
+
const work = (async () => {
|
|
110
|
+
const settings = await cms.settings.all();
|
|
111
|
+
const recipients = new Set<string>();
|
|
112
|
+
const held = comment.status === 'pending';
|
|
113
|
+
if (settings['general.adminEmail'] && (held ? settings['discussion.notifyHeld'] : settings['discussion.notifyPosted'])) recipients.add(settings['general.adminEmail']);
|
|
114
|
+
if (!held && settings['discussion.notifyAuthor'] && owner && owner !== comment.userId) {
|
|
115
|
+
const author = await cms.users.get(owner);
|
|
116
|
+
if (author) recipients.add(author.email);
|
|
117
|
+
}
|
|
118
|
+
// Links only from an address the site set, never from the poster's Host header.
|
|
119
|
+
const origin = mailOrigin(c);
|
|
120
|
+
const subject = `${held ? 'Please moderate' : 'New comment'}: “${title}”`;
|
|
121
|
+
const links = origin ? `${url ? `${origin}${url}\n` : ''}Moderate: ${origin}/dashboard/comments?status=${comment.status}` : 'Moderate it under Comments in the dashboard.';
|
|
122
|
+
const text = `${comment.authorName} <${comment.authorEmail}> wrote on “${title}”:\n\n${comment.content}\n\n${links}`;
|
|
123
|
+
for (const to of recipients) await mail.send({ kind: 'comment', to, from: cms.mailFrom, subject, text });
|
|
124
|
+
})().catch(error => console.error('[cms] could not send comment notifications', error));
|
|
125
|
+
try { c.executionCtx.waitUntil(work); } catch { /* Node keeps running the promise. */ }
|
|
126
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { commentsQueue } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** The moderation queue: `GET /api/cms/comments/queue?status=pending&q=&page=&perPage=`. Needs the comments permission. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => commentsQueue(c, c.req.query()));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { isCmsError } from '@cossackframework/cms';
|
|
3
|
+
import { routeResource } from '#app/cms/content';
|
|
4
|
+
import { writeAllowed, writeBody } from '#app/cms/content-api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's autosave: `POST /api/cms/content/<collection>/<id>/autosave` stores the signed-in
|
|
8
|
+
* user's unsaved form values for an entry (`new` before its first save) and answers `{ at }`.
|
|
9
|
+
* A plain request, apart from the page's server methods, so the editor's state is not re-applied
|
|
10
|
+
* and the page does not re-render while someone is typing. `<collection>` may also be a plugin
|
|
11
|
+
* resource's route, `<owner>.<name>`.
|
|
12
|
+
*/
|
|
13
|
+
export const POST = async (c: Context) => {
|
|
14
|
+
const refused = writeAllowed(c);
|
|
15
|
+
if (refused) return refused;
|
|
16
|
+
const values = await writeBody(c);
|
|
17
|
+
if (values instanceof Response) return values;
|
|
18
|
+
const cms = c.get('cms');
|
|
19
|
+
try {
|
|
20
|
+
const { resource } = routeResource(cms, c.req.param('collection') ?? '');
|
|
21
|
+
const at = await cms.autosave(resource.id, c.req.param('entry') ?? '', c.get('principal'), values);
|
|
22
|
+
return c.json({ at });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (isCmsError(error)) return c.json({ error: error.message, code: error.code }, error.status as 400);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { CmsError } from '@cossackframework/cms';
|
|
3
|
+
import { answer, apiHeaders } from '#app/cms/content-api';
|
|
4
|
+
import { entryBlock } from '#app/cms/manage';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One block of an entry by its ID: `GET /api/cms/content/posts/hello-world/blocks/hero`. Editors
|
|
8
|
+
* give a block an ID of their own under its Style tab → Advanced → Block ID; nested blocks and
|
|
9
|
+
* blocks embedded in rich text are found too. The answer names the field the block sits in.
|
|
10
|
+
*/
|
|
11
|
+
export const GET = (c: Context) => answer(c, async () => {
|
|
12
|
+
const found = await entryBlock(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', c.req.param('block') ?? '');
|
|
13
|
+
if (!found) throw new CmsError('CMS_NOT_FOUND', 'Block not found.');
|
|
14
|
+
apiHeaders(c);
|
|
15
|
+
return found;
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { noteAdd, notesForEntry } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An entry's review notes: `GET /api/cms/content/posts/<id>/notes` answers its threads, each a
|
|
7
|
+
* root with its replies, oldest first; `?status=open` or `resolved` keeps one kind. Whoever
|
|
8
|
+
* may edit the entry reads its notes.
|
|
9
|
+
*/
|
|
10
|
+
export const GET = (c: Context) => answer(c, () => notesForEntry(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', c.req.query('status')));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A new thread, or a reply: `POST /api/cms/content/posts/<id>/notes` with `body` and, for a
|
|
14
|
+
* thread, `target` (`entry`, `field:title`, `block:content:<blockId>`, `text:content:<blockId>.text`)
|
|
15
|
+
* with `range` and `quote` on a passage; a reply names its thread as `parentId`. Whoever may edit
|
|
16
|
+
* the entry writes notes. Editors with the entry open see the note when they next join its room.
|
|
17
|
+
*/
|
|
18
|
+
export const POST = (c: Context) => answer(c, body => noteAdd(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', body), { write: true, status: 201 });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { entryPublish } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Publish an entry: `POST /api/cms/content/posts/<id>/publish` with an optional `at` (ISO 8601;
|
|
7
|
+
* a future time schedules it) and `rev` (the revision you read; the current one when left out).
|
|
8
|
+
* An entry published before keeps its publication time unless `at` is given. With "Open notes
|
|
9
|
+
* hold publishing" on, open notes refuse it with 422.
|
|
10
|
+
*/
|
|
11
|
+
export const POST = (c: Context) => answer(c, body => entryPublish(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', body), { write: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { entryRevision } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** One revision's content: `GET /api/cms/content/posts/<id>/revisions/<n>`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => entryRevision(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', Number(c.req.param('revision'))));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { entryRestore } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** Restore a revision's fields as a new revision: `POST /api/cms/content/posts/<id>/revisions/<n>/restore` with an optional `rev`. The entry's status and publication stay. */
|
|
6
|
+
export const POST = (c: Context) => answer(c, body => entryRestore(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', Number(c.req.param('revision')), body.rev), { write: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { entryRevisions } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** An entry's revisions, newest first: `GET /api/cms/content/posts/<id>/revisions?limit=20` answers `{ current, items: [{ revision, at, actor, title, status }] }`. */
|
|
6
|
+
export const GET = (c: Context) => answer(c, () => entryRevisions(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', c.req.query()));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer } from '#app/cms/content-api';
|
|
3
|
+
import { entryUnpublish } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/** Take an entry off the site, back to a draft: `POST /api/cms/content/posts/<id>/unpublish` with an optional `rev`. */
|
|
6
|
+
export const POST = (c: Context) => answer(c, body => entryUnpublish(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', body), { write: true });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { CmsError } from '@cossackframework/cms';
|
|
3
|
+
import { answer, apiHeaders, writeAllowed, writeBody } from '#app/cms/content-api';
|
|
4
|
+
import { entryDelete, entryRead, entryUpdate } from '#app/cms/manage';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One entry by slug (published only) or by ID (whatever the reader may see, such as their own
|
|
8
|
+
* drafts): `GET /api/cms/content/posts/hello-world`. `?preview=<token>` reads an unpublished
|
|
9
|
+
* entry through its preview link. The answer lists the synced patterns its rich text uses and,
|
|
10
|
+
* on a site with several languages, its translations.
|
|
11
|
+
*/
|
|
12
|
+
export const GET = (c: Context) => answer(c, async () => {
|
|
13
|
+
const preview = c.req.query('preview');
|
|
14
|
+
const view = await entryRead(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', { ...(preview ? { preview } : {}), html: c.req.query('format') === 'html' });
|
|
15
|
+
if (!view) throw new CmsError('CMS_NOT_FOUND', 'Entry not found.');
|
|
16
|
+
if (preview) c.header('cache-control', 'private, no-store'); else apiHeaders(c);
|
|
17
|
+
return view;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Change an entry: `PATCH /api/cms/content/posts/<id>` with `rev` (the revision you read, or
|
|
22
|
+
* an `If-Match` header) and the fields to change. A stale revision answers 409.
|
|
23
|
+
*/
|
|
24
|
+
export const PATCH = async (c: Context) => {
|
|
25
|
+
const refused = writeAllowed(c);
|
|
26
|
+
if (refused) return refused;
|
|
27
|
+
const body = await writeBody(c);
|
|
28
|
+
if (body instanceof Response) return body;
|
|
29
|
+
const { rev, ...fields } = body;
|
|
30
|
+
const expected = rev ?? c.req.header('if-match')?.replaceAll('"', '');
|
|
31
|
+
if (expected === undefined || expected === '') return c.json({ error: 'Send the revision you read as rev, or in If-Match.', code: 'CMS_VALIDATION' }, 428);
|
|
32
|
+
return answer(c, () => entryUpdate(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', fields, expected));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Delete an entry permanently: `DELETE /api/cms/content/posts/<id>?rev=3`. */
|
|
36
|
+
export const DELETE = async (c: Context) => {
|
|
37
|
+
const refused = writeAllowed(c);
|
|
38
|
+
if (refused) return refused;
|
|
39
|
+
const expected = c.req.query('rev') ?? c.req.header('if-match')?.replaceAll('"', '');
|
|
40
|
+
if (expected === undefined || expected === '') return c.json({ error: 'Send the revision you read as ?rev=, or in If-Match.', code: 'CMS_VALIDATION' }, 428);
|
|
41
|
+
return answer(c, () => entryDelete(c, c.req.param('collection') ?? '', c.req.param('entry') ?? '', expected));
|
|
42
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { answer, apiHeaders } from '#app/cms/content-api';
|
|
3
|
+
import { entriesList, entryCreate } from '#app/cms/manage';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Entries of a collection: `GET /api/cms/content/posts?page=2&perPage=10`. Visitors get published
|
|
7
|
+
* entries, newest first; signed-in readers add `status=draft` (or `pending`, `scheduled`,
|
|
8
|
+
* `published`, `trash`, `any`). `term=categories:news` lists a term's entries, including those of
|
|
9
|
+
* terms below it; `q` searches; `locale=fr` lists one language's entries; `filter[field]=value`
|
|
10
|
+
* matches a field; `sort=publishedAt:asc` orders by a scalar field; `fields=title,slug,excerpt` keeps
|
|
11
|
+
* only those fields (and `id`, `url`); `format=html` adds rendered rich text beside the JSON documents.
|
|
12
|
+
*/
|
|
13
|
+
export const GET = (c: Context) => answer(c, async () => {
|
|
14
|
+
const page = await entriesList(c, c.req.param('collection') ?? '', c.req.query());
|
|
15
|
+
apiHeaders(c);
|
|
16
|
+
return page;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create an entry: `POST /api/cms/content/posts` with the fields as JSON, such as
|
|
21
|
+
* `{ "title": "Hello", "body": { "type": "doc", "content": [...] }, "status": "published" }`.
|
|
22
|
+
* Terms are IDs. Needs a session or an application password that may write.
|
|
23
|
+
*/
|
|
24
|
+
export const POST = (c: Context) => answer(c, body => entryCreate(c, c.req.param('collection') ?? '', body), { write: true, status: 201 });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { apiError } from '#app/cms/content-api';
|
|
3
|
+
import { exportEntries, routeResource } from '#app/cms/content';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every entry of a content type the caller may read, whatever its status, as a JSON document
|
|
7
|
+
* `{ collection, exportedAt, items }` that `/api/cms/import/<collection>` takes back:
|
|
8
|
+
* `GET /api/cms/export/posts`. For a session or an application password that may read them.
|
|
9
|
+
*/
|
|
10
|
+
export const GET = async (c: Context) => {
|
|
11
|
+
const cms = c.get('cms');
|
|
12
|
+
const principal = c.get('principal');
|
|
13
|
+
try {
|
|
14
|
+
const route = c.req.param('collection') ?? '';
|
|
15
|
+
const { resource } = routeResource(cms, route);
|
|
16
|
+
if (principal.kind !== 'user') return c.json({ error: 'Sign in, or send an application password.', code: 'CMS_UNAUTHENTICATED' }, 401, { 'www-authenticate': 'Bearer' });
|
|
17
|
+
const pages = exportEntries(cms, route, principal);
|
|
18
|
+
// The first page checks the permission before anything is sent.
|
|
19
|
+
const first = await pages.next();
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
let count = 0;
|
|
22
|
+
const chunk = (items: Record<string, unknown>[]) => items.map(item => `${count++ ? ',\n' : ''} ${JSON.stringify(item)}`).join('');
|
|
23
|
+
const body = new ReadableStream<Uint8Array>({
|
|
24
|
+
start(controller) { controller.enqueue(encoder.encode(`{\n "collection": ${JSON.stringify(route)},\n "exportedAt": ${JSON.stringify(new Date(cms.now()).toISOString())},\n "items": [\n${first.done ? '' : chunk(first.value)}`)); },
|
|
25
|
+
async pull(controller) {
|
|
26
|
+
const next = await pages.next();
|
|
27
|
+
if (next.done) { controller.enqueue(encoder.encode('\n ]\n}\n')); controller.close(); } else controller.enqueue(encoder.encode(chunk(next.value)));
|
|
28
|
+
},
|
|
29
|
+
async cancel() { await pages.return(undefined); },
|
|
30
|
+
});
|
|
31
|
+
const date = new Date(cms.now()).toISOString().slice(0, 10);
|
|
32
|
+
return new Response(body, { headers: {
|
|
33
|
+
'content-type': 'application/json; charset=utf-8', 'cache-control': 'private, no-store',
|
|
34
|
+
'content-disposition': `attachment; filename="${resource.name}-${date}.json"`,
|
|
35
|
+
} });
|
|
36
|
+
} catch (error) { return apiError(c, error); }
|
|
37
|
+
};
|