@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,202 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { deleteCookie, getCookie, setCookie } from 'hono/cookie';
|
|
3
|
+
import { NETWORK_ADMIN } from '@cossackframework/cms';
|
|
4
|
+
import { MAIN_SITE, networkSite, type ChildSession, type CmsHost, type CmsNetwork, type NetworkSite } from '@cossackframework/cms/server';
|
|
5
|
+
import { authSessions, SESSION_COOKIE_NAME } from '../auth';
|
|
6
|
+
import { siteUrl, type CmsBindings } from './index';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sign-in for a network of sites. An added site's own sign-in pages sign in its site accounts.
|
|
10
|
+
* Network accounts sign in only on the network host (the main site), and the site gets its own
|
|
11
|
+
* child session back through a one-use code:
|
|
12
|
+
*
|
|
13
|
+
* 1. `<site>/auth/handoff?next=<path>` (the sign-in pages' network link) →
|
|
14
|
+
* `<network>/auth/handoff?site=<id>&next=<path>`.
|
|
15
|
+
* 2. Without a network session, the network keeps the request in a cookie and shows its sign-in;
|
|
16
|
+
* after any sign-in, the next page continues the handoff.
|
|
17
|
+
* 3. With one, the network issues a code bound to the site and the session, valid for a minute,
|
|
18
|
+
* and sends the visitor to `<site>/auth/handoff?code=…&state=…`, which trades it for a child
|
|
19
|
+
* session when `state` is the one the site set in this browser at step 1.
|
|
20
|
+
*
|
|
21
|
+
* A visitor who opens a site's dashboard without a session there goes through the same steps on
|
|
22
|
+
* their own, with `auto=1`: a network admin, or a member signed in on the network, arrives signed
|
|
23
|
+
* in without a click; anyone else comes back to the site's own sign-in, and the attempt is not
|
|
24
|
+
* repeated for a while (`cms_handoff_auto`), so a site account signs in there as before.
|
|
25
|
+
*/
|
|
26
|
+
const HANDOFF_COOKIE = 'cms_handoff';
|
|
27
|
+
/** Set by a site that started a handoff on its own: no second attempt until it expires. */
|
|
28
|
+
const AUTO_COOKIE = 'cms_handoff_auto';
|
|
29
|
+
/**
|
|
30
|
+
* Set by a site as it sends the visitor to the network, and sent back with the code: a code
|
|
31
|
+
* opened in a browser that did not start the handoff (a link someone else made with their own
|
|
32
|
+
* account) is refused, so nobody is signed in to another person's account.
|
|
33
|
+
*/
|
|
34
|
+
const STATE_COOKIE = 'cms_handoff_state';
|
|
35
|
+
const STATE = /^[0-9a-f]{32}$/;
|
|
36
|
+
/** The site paths a missing session starts a handoff for: the dashboard, which needs one. */
|
|
37
|
+
const AUTO_PATHS = /^\/dashboard(?:\/|$)/;
|
|
38
|
+
|
|
39
|
+
/** A path on the same site to go to afterwards; anything else is the dashboard. */
|
|
40
|
+
function nextPath(value: string | null | undefined): string {
|
|
41
|
+
return value && /^\/(?!\/)[^\s\\]*$/.test(value) ? value : '/dashboard';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function secure(c: Context): boolean {
|
|
45
|
+
return new URL(c.req.url).protocol === 'https:';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Handoff routes and redirects, before auth runs. Null lets the request through. Without
|
|
50
|
+
* APP_URL there is no network host to send sign-ins to, and each site signs in on its own host.
|
|
51
|
+
*/
|
|
52
|
+
export async function handoff(c: Context, network: CmsNetwork, site: NetworkSite): Promise<Response | null> {
|
|
53
|
+
const env = c.env as CmsBindings;
|
|
54
|
+
const url = new URL(c.req.url);
|
|
55
|
+
if (site.id !== MAIN_SITE) {
|
|
56
|
+
if (url.pathname === '/auth/handoff') {
|
|
57
|
+
if (url.searchParams.has('code')) return toSite(c, network, site);
|
|
58
|
+
// Sign in with a network account: on the network host, which hands the session back.
|
|
59
|
+
if (!env.APP_URL) return c.text('This network has no sign-in host: set APP_URL.', 404);
|
|
60
|
+
return c.redirect(toNetwork(env.APP_URL, site, nextPath(url.searchParams.get('next')), url.searchParams.get('auto') === '1', startState(c)));
|
|
61
|
+
}
|
|
62
|
+
// The dashboard without a live session here: the network may have one, so ask it once before the site's sign-in shows.
|
|
63
|
+
if (env.APP_URL && c.req.method === 'GET' && AUTO_PATHS.test(url.pathname) && !getCookie(c, AUTO_COOKIE) && !(await siteSession(c))) {
|
|
64
|
+
setCookie(c, AUTO_COOKIE, '1', { path: '/', httpOnly: true, sameSite: 'Lax', maxAge: 300, secure: secure(c) });
|
|
65
|
+
return c.redirect(toNetwork(env.APP_URL, site, nextPath(url.pathname + url.search), true, startState(c)));
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (url.pathname === '/auth/handoff') return fromNetwork(c, network);
|
|
70
|
+
// After signing in on the network host, continue the handoff the visitor came for.
|
|
71
|
+
const pending = getCookie(c, HANDOFF_COOKIE);
|
|
72
|
+
if (pending && !url.pathname.startsWith('/auth/') && !url.pathname.startsWith('/api/') && await networkSession(c, network)) {
|
|
73
|
+
deleteCookie(c, HANDOFF_COOKIE, { path: '/' });
|
|
74
|
+
const { site: id, next, state } = parsePending(pending);
|
|
75
|
+
if (id) return c.redirect(`/auth/handoff?site=${encodeURIComponent(id)}&next=${encodeURIComponent(next)}&state=${encodeURIComponent(state)}`);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The network's handoff address for a site: where the site sends a visitor to sign in, or to try their network session (`auto`). */
|
|
81
|
+
function toNetwork(appUrl: string, site: Pick<NetworkSite, 'id'>, next: string, auto: boolean, state: string): string {
|
|
82
|
+
const target = new URL('/auth/handoff', appUrl);
|
|
83
|
+
target.searchParams.set('site', site.id);
|
|
84
|
+
target.searchParams.set('next', next);
|
|
85
|
+
target.searchParams.set('state', state);
|
|
86
|
+
if (auto) target.searchParams.set('auto', '1');
|
|
87
|
+
return target.toString();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A new handoff state for this browser, kept in a cookie on the site for ten minutes. */
|
|
91
|
+
function startState(c: Context): string {
|
|
92
|
+
const state = [...crypto.getRandomValues(new Uint8Array(16))].map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
93
|
+
setCookie(c, STATE_COOKIE, state, { path: '/auth/handoff', httpOnly: true, sameSite: 'Lax', maxAge: 600, secure: secure(c) });
|
|
94
|
+
return state;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Whether the request carries a live session of this site. */
|
|
98
|
+
async function siteSession(c: Context): Promise<boolean> {
|
|
99
|
+
const id = getCookie(c, SESSION_COOKIE_NAME);
|
|
100
|
+
return !!id && !!(await authSessions.validate(id, c).catch(() => null));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* On the network host: issue a code for the site, or sign in first. An attempt the site started
|
|
105
|
+
* on its own (`auto`) never shows the network's sign-in: without a session, or for an account
|
|
106
|
+
* that is not a member, the visitor goes back to the site's own sign-in.
|
|
107
|
+
*/
|
|
108
|
+
async function fromNetwork(c: Context, network: CmsNetwork): Promise<Response> {
|
|
109
|
+
const env = c.env as CmsBindings;
|
|
110
|
+
const url = new URL(c.req.url);
|
|
111
|
+
const id = url.searchParams.get('site') ?? '';
|
|
112
|
+
const next = nextPath(url.searchParams.get('next'));
|
|
113
|
+
const auto = url.searchParams.get('auto') === '1';
|
|
114
|
+
const state = url.searchParams.get('state') ?? '';
|
|
115
|
+
if (!STATE.test(state)) return c.text('Start signing in from the site.', 400);
|
|
116
|
+
const record = await network.sites.get(id);
|
|
117
|
+
if (!record || (record.status !== 'active' && record.status !== 'archived')) return c.text('No site at this address.', 404);
|
|
118
|
+
const site = networkSite(record);
|
|
119
|
+
const siteLogin = () => c.redirect(new URL('/auth/login', siteUrl(env, site)).toString());
|
|
120
|
+
const session = await networkSession(c, network);
|
|
121
|
+
if (!session) {
|
|
122
|
+
if (auto) return siteLogin();
|
|
123
|
+
setCookie(c, HANDOFF_COOKIE, JSON.stringify({ site: id, next, state }), { path: '/', httpOnly: true, sameSite: 'Lax', maxAge: 600, secure: secure(c) });
|
|
124
|
+
return c.redirect(url.searchParams.get('register') === '1' ? '/auth/register' : '/auth/login');
|
|
125
|
+
}
|
|
126
|
+
deleteCookie(c, HANDOFF_COOKIE, { path: '/' });
|
|
127
|
+
const account = await network.main.accounts.get(session.userId);
|
|
128
|
+
if (!account || account.status !== 'active') return auto ? siteLogin() : c.redirect('/auth/login');
|
|
129
|
+
if (account.networkRole !== NETWORK_ADMIN && !(await network.hostOf(site).users.get(account.id))) {
|
|
130
|
+
if (auto) return siteLogin();
|
|
131
|
+
return c.text(`Your account is not a member of ${record.name}. Ask its administrator to add you.`, 403);
|
|
132
|
+
}
|
|
133
|
+
const code = await network.handoffs.issue({ session: session.reference, user: account.id, site: site.id });
|
|
134
|
+
const target = new URL('/auth/handoff', siteUrl(c.env as CmsBindings, site));
|
|
135
|
+
target.searchParams.set('code', code);
|
|
136
|
+
target.searchParams.set('next', next);
|
|
137
|
+
target.searchParams.set('state', state);
|
|
138
|
+
return c.redirect(target.toString());
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** On a site: trade the code for a child session in the site's own database. */
|
|
142
|
+
async function toSite(c: Context, network: CmsNetwork, site: NetworkSite): Promise<Response> {
|
|
143
|
+
const url = new URL(c.req.url);
|
|
144
|
+
// Only the browser that started this handoff may finish it; the code is left unused otherwise.
|
|
145
|
+
const state = getCookie(c, STATE_COOKIE) ?? '';
|
|
146
|
+
if (!STATE.test(state) || url.searchParams.get('state') !== state) return c.html('<p>This sign-in did not start in this browser. <a href="/auth/login">Sign in again</a>.</p>', 400);
|
|
147
|
+
deleteCookie(c, STATE_COOKIE, { path: '/auth/handoff' });
|
|
148
|
+
const handoff = await network.handoffs.consume(url.searchParams.get('code') ?? '', site.id);
|
|
149
|
+
if (!handoff) return c.html('<p>This sign-in link expired or was used. <a href="/auth/login">Sign in again</a>.</p>', 400);
|
|
150
|
+
const cms = network.hostOf(site);
|
|
151
|
+
// A network admin may open any site; the first visit copies them in without a role, so their writes have an author.
|
|
152
|
+
if (handoff.networkRole === NETWORK_ADMIN) await cms.users.addMember(handoff.user);
|
|
153
|
+
if (!(await cms.users.get(handoff.user))) return c.text('Your account is not a member of this site.', 403);
|
|
154
|
+
// The child session used a second factor only if the network session did: the site's own two-step requirement then asks it of the child.
|
|
155
|
+
c.set('cms.child', { parentId: handoff.session, networkRole: handoff.networkRole, expiresAt: handoff.expiresAt, secondFactor: handoff.secondFactor });
|
|
156
|
+
const { headers } = await authSessions.create(handoff.user, c);
|
|
157
|
+
headers.forEach((value, name) => c.header(name, value, { append: true }));
|
|
158
|
+
deleteCookie(c, AUTO_COOKIE, { path: '/' });
|
|
159
|
+
return c.redirect(nextPath(url.searchParams.get('next')));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** On the network host, the site a visitor is signing in to (active or archived), or null. */
|
|
163
|
+
export async function pendingSite(c: Context, network: CmsNetwork): Promise<NetworkSite | null> {
|
|
164
|
+
const id = parsePending(getCookie(c, HANDOFF_COOKIE) ?? '').site;
|
|
165
|
+
if (!id || c.get('site')?.id !== MAIN_SITE) return null;
|
|
166
|
+
const record = await network.sites.get(id);
|
|
167
|
+
return record && (record.status === 'active' || record.status === 'archived') ? networkSite(record) : null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** On the network host, the site a visitor is registering for, or null. */
|
|
171
|
+
export async function handoffSite(c: Context, network: CmsNetwork): Promise<CmsHost | null> {
|
|
172
|
+
const id = parsePending(getCookie(c, HANDOFF_COOKIE) ?? '').site;
|
|
173
|
+
if (!id || c.get('site')?.id !== MAIN_SITE) return null;
|
|
174
|
+
const record = await network.sites.get(id);
|
|
175
|
+
return record && record.status === 'active' ? network.hostOf(networkSite(record)) : null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The visitor's live session on the network host, with its public reference. */
|
|
179
|
+
async function networkSession(c: Context, network: CmsNetwork): Promise<{ userId: string; reference: string } | null> {
|
|
180
|
+
const id = getCookie(c, SESSION_COOKIE_NAME);
|
|
181
|
+
if (!id) return null;
|
|
182
|
+
const record = await authSessions.validate(id, c).catch(() => null);
|
|
183
|
+
const reference = record ? await network.main.authSessions.publicReference(id) : null;
|
|
184
|
+
return record && reference ? { userId: record.userId, reference } : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function parsePending(value: string): { site: string | null; next: string; state: string } {
|
|
188
|
+
try {
|
|
189
|
+
const parsed = JSON.parse(value) as { site?: unknown; next?: unknown; state?: unknown };
|
|
190
|
+
return { site: typeof parsed.site === 'string' && /^[a-z0-9-]{1,63}$/.test(parsed.site) ? parsed.site : null, next: nextPath(typeof parsed.next === 'string' ? parsed.next : null),
|
|
191
|
+
state: typeof parsed.state === 'string' && STATE.test(parsed.state) ? parsed.state : '' };
|
|
192
|
+
} catch { return { site: null, next: '/dashboard', state: '' }; }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare module 'hono' {
|
|
196
|
+
interface ContextVariableMap {
|
|
197
|
+
/** A handoff in progress: the next session created on this request is a child session. */
|
|
198
|
+
'cms.child': ChildSession;
|
|
199
|
+
/** The network role a child session copied at its handoff. */
|
|
200
|
+
'cms.networkRole': string | null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The headings of an entry's content, for `core/toc`: each `core/heading` gets an anchor
|
|
3
|
+
* (its own from Advanced settings, else one made from its text, kept distinct), and every
|
|
4
|
+
* table of contents in the content receives the list. Client-safe; the server runs it once
|
|
5
|
+
* per entry after the content is rendered.
|
|
6
|
+
*/
|
|
7
|
+
import { slugify, type RenderedBlock } from '@cossackframework/cms';
|
|
8
|
+
|
|
9
|
+
export interface HeadingView {
|
|
10
|
+
/** The anchor the heading's wrapper carries, without `#`. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly text: string;
|
|
13
|
+
/** 2, 3 or 4. */
|
|
14
|
+
readonly level: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const LEVELS: Readonly<Record<string, number>> = { h2: 2, h3: 3, h4: 4 };
|
|
18
|
+
|
|
19
|
+
/** An anchor from a heading's text: a letter first, at most 60 characters, `section` when nothing is left. */
|
|
20
|
+
export function headingAnchor(text: string): string {
|
|
21
|
+
const slug = slugify(text).slice(0, 60).replace(/-+$/, '');
|
|
22
|
+
return !slug ? 'section' : /^[A-Za-z]/.test(slug) ? slug : `h-${slug}`.slice(0, 60);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The content with its headings anchored and its tables of contents filled; unchanged when it has neither. */
|
|
26
|
+
export function withHeadingAnchors(blocks: readonly RenderedBlock[]): RenderedBlock[] {
|
|
27
|
+
const taken = new Set<string>();
|
|
28
|
+
const headings: HeadingView[] = [];
|
|
29
|
+
let changed = false;
|
|
30
|
+
const anchor = (block: RenderedBlock): RenderedBlock => {
|
|
31
|
+
if (block.type === 'core/heading') {
|
|
32
|
+
const text = typeof block.data.text === 'string' ? block.data.text.trim() : '';
|
|
33
|
+
const level = LEVELS[typeof block.data.level === 'string' ? block.data.level : 'h2'] ?? 2;
|
|
34
|
+
let id = block.layout?.anchor || headingAnchor(text);
|
|
35
|
+
for (let n = 2; taken.has(id); n++) id = `${headingAnchor(text).slice(0, 56)}-${n}`;
|
|
36
|
+
taken.add(id);
|
|
37
|
+
headings.push({ id, text, level });
|
|
38
|
+
if (block.layout?.anchor !== id) { changed = true; return { ...block, layout: { ...block.layout, anchor: id } }; }
|
|
39
|
+
return block;
|
|
40
|
+
}
|
|
41
|
+
if (block.type === 'core/toc') changed = true;
|
|
42
|
+
if (!block.children?.length) return block;
|
|
43
|
+
const children = block.children.map(anchor);
|
|
44
|
+
return children.some((child, index) => child !== block.children![index]) ? { ...block, children } : block;
|
|
45
|
+
};
|
|
46
|
+
const anchored = blocks.map(anchor);
|
|
47
|
+
if (!changed) return anchored;
|
|
48
|
+
const fill = (block: RenderedBlock): RenderedBlock => block.type === 'core/toc' ? { ...block, headings }
|
|
49
|
+
: block.children?.length ? { ...block, children: block.children.map(fill) } : block;
|
|
50
|
+
return anchored.map(fill);
|
|
51
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icons for the dashboard and the site, any of the catalog's 1,246, drawn in the style
|
|
3
|
+
* Settings → Appearance picks. `icon(name)` is a sprite reference, `<use href="…#name">` into
|
|
4
|
+
* `/assets/icons/<style>/<group>.<version>.svg`, which the `cossackCmsIcons()` Vite plugin
|
|
5
|
+
* serves and builds: no icon markup ships in the client bundle or the HTML, and the browser
|
|
6
|
+
* caches each sprite for a year. The hot set (the site's and the dashboard's own icons) is one
|
|
7
|
+
* sprite, so a dashboard page loads its icons in one request; any other icon comes from its
|
|
8
|
+
* category's sprite.
|
|
9
|
+
*/
|
|
10
|
+
import { DEFAULT_ICON_STYLE, ICON_CATEGORIES, iconHref, isIconStyle, type IconStyleName } from '@cossackframework/cms';
|
|
11
|
+
import { getRequestContext } from '@cossackframework/core';
|
|
12
|
+
import type { IconEntry } from '@cossackframework/solar-icons/types';
|
|
13
|
+
import type { IconPickerCatalog, SpriteIconEntry } from '@cossackframework/ui';
|
|
14
|
+
|
|
15
|
+
/** The `<meta>` the dashboard (`dashboardHead()`) and the site's pages carry, so client renders draw the same style as the server. */
|
|
16
|
+
export const ICON_STYLE_META = 'cms-icon-style';
|
|
17
|
+
|
|
18
|
+
let clientStyle: IconStyleName | undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The style of this request's icons: on the server what the CMS middleware read from the
|
|
22
|
+
* site's settings (Settings → Interface); on the client the page's meta tag, or failing that the
|
|
23
|
+
* style of the first icon the server drew; `line` when nothing is at hand (jobs, tests). Read
|
|
24
|
+
* once per page on the client.
|
|
25
|
+
*/
|
|
26
|
+
export function iconStyle(): IconStyleName {
|
|
27
|
+
if (typeof document !== 'undefined') {
|
|
28
|
+
if (!clientStyle) {
|
|
29
|
+
const content = document.querySelector(`meta[name="${ICON_STYLE_META}"]`)?.getAttribute('content')
|
|
30
|
+
?? document.querySelector('use[href^="/assets/icons/"]')?.getAttribute('href')?.split('/')[3];
|
|
31
|
+
clientStyle = isIconStyle(content) ? content : DEFAULT_ICON_STYLE;
|
|
32
|
+
}
|
|
33
|
+
return clientStyle;
|
|
34
|
+
}
|
|
35
|
+
const style = getRequestContext()?.get('cms.iconStyle');
|
|
36
|
+
return isIconStyle(style) ? style : DEFAULT_ICON_STYLE;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** For tests: forget the style read from the document. */
|
|
40
|
+
export function resetIconStyle(): void {
|
|
41
|
+
clientStyle = undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** An icon by name in the request's style; a name outside the catalog gets the fallback. */
|
|
45
|
+
export function icon(name: string | undefined, fallback = 'document-text'): IconEntry {
|
|
46
|
+
const style = iconStyle();
|
|
47
|
+
const href = (name && iconHref(name, style)) || iconHref(fallback, style);
|
|
48
|
+
if (!href) throw new Error(`${fallback} is not an icon of the catalog.`);
|
|
49
|
+
const entry: SpriteIconEntry = { href };
|
|
50
|
+
return entry;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Whether a name is in the catalog, for places that draw nothing rather than a fallback. */
|
|
54
|
+
export function hasIcon(name: string | undefined): boolean {
|
|
55
|
+
return !!name && iconHref(name) !== undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The whole catalog for the icon picker: every category and its names, drawn through `icon()`. */
|
|
59
|
+
export const ICON_CATALOG: IconPickerCatalog = Object.freeze({ categories: ICON_CATEGORIES, entry: (name: string) => icon(name) });
|
|
60
|
+
|
|
61
|
+
/** Names offered for collections, in the builder's order. */
|
|
62
|
+
export const COLLECTION_ICONS = Object.freeze(['document-text', 'notebook', 'box', 'bag-4', 'cart-large-2', 'shop', 'gallery', 'calendar-mark', 'map-point', 'star', 'bookmark', 'case', 'cup', 'home-2', 'notes', 'clipboard-list', 'graph', 'medal-ribbon', 'video-library', 'music-note', 'book', 'ticket', 'user-id', 'hashtag', 'widget-add']);
|
|
63
|
+
|
|
64
|
+
/** A block's icon; plugin blocks naming an icon the catalog lacks get a generic one. */
|
|
65
|
+
export function blockIcon(name: string | undefined): IconEntry {
|
|
66
|
+
return icon(name, 'widget-4');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The color of a block's icon by its category, so block types tell apart at a glance: text
|
|
71
|
+
* blue, media violet, design amber, widgets emerald, embeds sky, form fields rose, data slate.
|
|
72
|
+
*/
|
|
73
|
+
export const BLOCK_CATEGORY_COLORS: Readonly<Record<string, string>> = Object.freeze({
|
|
74
|
+
text: 'text-blue-600 dark:text-blue-400', media: 'text-violet-600 dark:text-violet-400', design: 'text-amber-600 dark:text-amber-400',
|
|
75
|
+
widgets: 'text-emerald-600 dark:text-emerald-400', embeds: 'text-sky-600 dark:text-sky-400', form: 'text-rose-600 dark:text-rose-400', field: 'text-teal-600 dark:text-teal-400', data: 'text-slate-500 dark:text-slate-400',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export function blockIconColor(category: string | undefined): string {
|
|
79
|
+
return BLOCK_CATEGORY_COLORS[category ?? ''] ?? 'text-muted-foreground';
|
|
80
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sending a site export from the browser. The chosen file goes as the request body, so the
|
|
3
|
+
* server reads it as a stream however large it is; the form posts it as a multipart upload
|
|
4
|
+
* when JavaScript is off.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Post the form's file to its page; resolves to where to go next, or the server's error. */
|
|
8
|
+
export async function sendExport(form: HTMLFormElement, headers: Record<string, string> = {}): Promise<{ next?: string; error?: string }> {
|
|
9
|
+
const file = (form.elements.namedItem('file') as HTMLInputElement | null)?.files?.[0];
|
|
10
|
+
if (!file) return { error: 'Choose an export file.' };
|
|
11
|
+
try {
|
|
12
|
+
const response = await fetch(form.action || location.href, { method: 'POST', body: file, headers: { 'content-type': 'application/json', accept: 'application/json', ...headers } });
|
|
13
|
+
const result = await response.json().catch(() => ({})) as { next?: string; error?: string };
|
|
14
|
+
return response.ok ? { next: result.next ?? location.href } : { error: result.error ?? `The import failed (${response.status}).` };
|
|
15
|
+
} catch { return { error: 'The export could not be sent. Check the connection and try again.' }; }
|
|
16
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { createRomeDB } from '@cossackframework/romedb';
|
|
2
|
+
import { getRequestContext } from '@cossackframework/core';
|
|
3
|
+
import { cloudflarePurger, cmsReconcilers, CmsNetwork, createCMS, DEFAULT_RESERVED_PATHS, MAIN_SITE, prefixedStorage, stripePayments, type CachePurger, type CmsHost, type NetworkSite, type PluginRunner } from '@cossackframework/cms/server';
|
|
4
|
+
import type { CmsStorage } from '@cossackframework/cms/storage';
|
|
5
|
+
import { aiProvider, type AiBindings } from './ai';
|
|
6
|
+
import { DEFAULT_UPDATES_CHANNEL, DEFAULT_UPDATES_URL, type IconStyleName, type Principal } from '@cossackframework/cms';
|
|
7
|
+
import { plugins } from '@cossackframework/framework/plugins';
|
|
8
|
+
// The project's own: its resources, modules, the options it sets, and where the CMS keeps its data.
|
|
9
|
+
import { modules, options as projectOptions, resources, storage as projectStorage } from '@/cms.config';
|
|
10
|
+
import { announceNoteEvent } from './notes-announce';
|
|
11
|
+
import { reservedRouteSegments } from './reserved-paths';
|
|
12
|
+
import registry from 'virtual:cossack-pages';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The environment bindings the CMS application reads. The project's storage (`storage` in
|
|
16
|
+
* src/cms.config.ts) reads its own: the database address, the media bucket and so on.
|
|
17
|
+
*/
|
|
18
|
+
export interface CmsBindings extends AiBindings {
|
|
19
|
+
/** Stripe as the payments provider: the secret key, and the webhook endpoint's signing secret. */
|
|
20
|
+
STRIPE_SECRET_KEY?: string;
|
|
21
|
+
STRIPE_WEBHOOK_SECRET?: string;
|
|
22
|
+
/** Stripe's API base, for tests. */
|
|
23
|
+
STRIPE_API_URL?: string;
|
|
24
|
+
APP_URL?: string;
|
|
25
|
+
/** Sends the site's emails, plain text with an HTML part: Cloudflare's Email Service binding, the Node adapter's SMTP sender, or any `{ send(message) }`. */
|
|
26
|
+
EMAIL?: { send(message: { to: string; from: string; subject: string; text: string; html?: string; replyTo?: string }): Promise<unknown> };
|
|
27
|
+
/** The sender of the site's emails. */
|
|
28
|
+
MAIL_FROM?: string;
|
|
29
|
+
/** Purges the Cloudflare cache when pages change: a token with Zone → Cache Purge, and Zone → Zone Read unless the zone ID is given. */
|
|
30
|
+
CLOUDFLARE_API_TOKEN?: string;
|
|
31
|
+
/** The zone to purge; without it, the zone is looked up by each site's host. */
|
|
32
|
+
CLOUDFLARE_ZONE_ID?: string;
|
|
33
|
+
/** The Cloudflare API's base URL, for tests. */
|
|
34
|
+
CLOUDFLARE_API_URL?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Where Tools → Updates sends its request: the project's pipeline, which runs `cossack upgrade`.
|
|
37
|
+
* For GitHub: https://api.github.com/repos/<owner>/<repository>/dispatches.
|
|
38
|
+
*/
|
|
39
|
+
CMS_UPDATE_HOOK_URL?: string;
|
|
40
|
+
/** Sent to the hook as a bearer token. For GitHub: a fine-grained token with Contents: read and write on the repository. */
|
|
41
|
+
CMS_UPDATE_HOOK_TOKEN?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module 'hono' {
|
|
45
|
+
interface ContextVariableMap {
|
|
46
|
+
/** The host of the site the request reached. */
|
|
47
|
+
cms: CmsHost;
|
|
48
|
+
site: NetworkSite;
|
|
49
|
+
/** The network the site belongs to; `enabled()` says whether it serves added sites. */
|
|
50
|
+
network: CmsNetwork;
|
|
51
|
+
principal: Principal;
|
|
52
|
+
/** Cache tags the site layout adds to every page: the collections its widget areas list. */
|
|
53
|
+
'cms.cacheTags'?: readonly string[];
|
|
54
|
+
/** What the dashboard computed for this request already (`remember` in `dashboard/access.ts`). */
|
|
55
|
+
'cms.memo'?: Map<string, Promise<unknown>>;
|
|
56
|
+
/** The Solar style this request's icons are drawn in (Settings → Appearance); `iconStyle()` reads it. */
|
|
57
|
+
'cms.iconStyle'?: IconStyleName;
|
|
58
|
+
/** The dashboard's `ui-palette` meta content, `<base> <accent>`, from Settings → Interface. */
|
|
59
|
+
'cms.palette'?: string;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let current: { key: string; network: CmsNetwork } | undefined;
|
|
64
|
+
/** Each network's update settings, for the scheduled run, which has the network and not the bindings. */
|
|
65
|
+
const networkUpdates = new WeakMap<CmsNetwork, { check: boolean; url: string; channel: string }>();
|
|
66
|
+
export function updateSettingsOf(network: CmsNetwork): { check: boolean; url: string; channel: string } | undefined {
|
|
67
|
+
return networkUpdates.get(network);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The update notice's settings, from `updates` in src/cms.config.ts; an unset one keeps its default. */
|
|
71
|
+
export function updateSettings(env: CmsBindings): { check: boolean; url: string; channel: string } {
|
|
72
|
+
const project = typeof projectOptions === 'function' ? projectOptions(env as Record<string, unknown>, { id: MAIN_SITE }) : projectOptions;
|
|
73
|
+
return { check: project.updates?.check !== false, url: project.updates?.url || DEFAULT_UPDATES_URL, channel: project.updates?.channel || DEFAULT_UPDATES_CHANNEL };
|
|
74
|
+
}
|
|
75
|
+
let pluginRunner: PluginRunner | null = null;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Runs isolated plugins: a Cloudflare Worker entry sets `cloudflarePluginRunner()` from
|
|
79
|
+
* `@cossackframework/cms/cloudflare` before the first request. Node sets none, and its build
|
|
80
|
+
* keeps every plugin in the application.
|
|
81
|
+
*/
|
|
82
|
+
export function setPluginRunner(runner: PluginRunner | null): void {
|
|
83
|
+
pluginRunner = runner;
|
|
84
|
+
current = undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* One network per isolate or process, keyed by the main database's address and credential. The
|
|
89
|
+
* main database holds the accounts and the site registry; each added site has its own database.
|
|
90
|
+
*/
|
|
91
|
+
export function networkFor(env: CmsBindings): CmsNetwork {
|
|
92
|
+
// The runtime's storage names its own bindings; this module passes the environment through.
|
|
93
|
+
const store = projectStorage as CmsStorage<unknown>;
|
|
94
|
+
const connection = store.databaseConnection(env);
|
|
95
|
+
const key = `${connection.url}\n${connection.token ?? ''}`;
|
|
96
|
+
if (current?.key !== key) {
|
|
97
|
+
const db = createRomeDB({ ...connection, pending: store.pendingWrites(env), reconcilers: cmsReconcilers() });
|
|
98
|
+
const storage = store.mediaStorage(env);
|
|
99
|
+
const images = store.imageTransformer(env);
|
|
100
|
+
const mail = env.EMAIL;
|
|
101
|
+
const ai = aiProvider(env);
|
|
102
|
+
const payments = env.STRIPE_SECRET_KEY?.trim() ? stripePayments({ secretKey: env.STRIPE_SECRET_KEY.trim(), ...(env.STRIPE_WEBHOOK_SECRET ? { webhookSecret: env.STRIPE_WEBHOOK_SECRET } : {}), ...(env.STRIPE_API_URL ? { api: env.STRIPE_API_URL } : {}) }) : null;
|
|
103
|
+
const multisite = store.siteDatabase(env, MAIN_SITE) !== null;
|
|
104
|
+
const directory = store.siteDirectory(env);
|
|
105
|
+
const webhookFetch = store.webhookFetch;
|
|
106
|
+
const network: CmsNetwork = new CmsNetwork({
|
|
107
|
+
db,
|
|
108
|
+
networkHost: () => urlOf(env.APP_URL)?.host,
|
|
109
|
+
...(multisite ? { open: site => createRomeDB({ ...store.siteDatabase(env, site.database)!, pending: store.pendingWrites(env, site.database), reconcilers: cmsReconcilers() }) } : {}),
|
|
110
|
+
...(directory ? { directory } : {}),
|
|
111
|
+
hostUrl: host => siteUrl(env, { host })!,
|
|
112
|
+
host: (site, siteDb) => {
|
|
113
|
+
// What the project sets in src/cms.config.ts goes over the defaults below.
|
|
114
|
+
const project = typeof projectOptions === 'function' ? projectOptions(env as Record<string, unknown>, site) : projectOptions;
|
|
115
|
+
return createCMS({
|
|
116
|
+
db: siteDb, network: db, site: site.id, modules, resources, plugins,
|
|
117
|
+
// A site whose APP_URL is this machine is in development: its webhooks may stay local. No APP_URL is no exception.
|
|
118
|
+
localWebhooks: localAddress(env.APP_URL),
|
|
119
|
+
...(webhookFetch && !localAddress(env.APP_URL) ? { webhookFetch } : {}),
|
|
120
|
+
// A site's media keys start with sites/<id>/; the main site keeps its own.
|
|
121
|
+
...(storage ? { storage: site.id === MAIN_SITE ? storage : prefixedStorage(storage, `sites/${site.id}/`) } : {}),
|
|
122
|
+
...(images ? { images } : {}), siteUrl: () => siteUrl(env, site),
|
|
123
|
+
...(mail ? { mail: { send: message => mail.send(message) }, mailFrom: env.MAIL_FROM || 'no-reply@example.com' } : {}),
|
|
124
|
+
// Ending a network session ends the child sessions sites made from it.
|
|
125
|
+
sessionsEnded: ended => network.endSessions(ended),
|
|
126
|
+
// A note's webhooks and emails, from the outbox job its write queued.
|
|
127
|
+
announceNote: announceNoteEvent,
|
|
128
|
+
purgers: [...purgers(env, site), ...(project.purgers ?? [])],
|
|
129
|
+
...(ai ? { ai } : {}),
|
|
130
|
+
...(payments ? { payments } : {}),
|
|
131
|
+
// Bindings a plugin's manifest names in permissions.secrets; strings only, read when asked.
|
|
132
|
+
secrets: name => { const value = (env as Record<string, unknown>)[name]; return typeof value === 'string' ? value : undefined; },
|
|
133
|
+
// Every binding, for a plugin granted unrestricted access.
|
|
134
|
+
env: env as Record<string, unknown>,
|
|
135
|
+
runner: pluginRunner,
|
|
136
|
+
...(({ purgers: _purgers, reservedPaths: _reserved, updates: _updates, ...rest }) => rest)(project),
|
|
137
|
+
// An entry's slug cannot take the address of a page: the CMS's routes, every page file of the
|
|
138
|
+
// application (the project's, the CMS's and plugins'), and what the project names itself.
|
|
139
|
+
reservedPaths: [...new Set([...DEFAULT_RESERVED_PATHS, ...reservedRouteSegments(Object.keys(registry.pages)), ...(project.reservedPaths ?? [])])],
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
current = { key, network };
|
|
144
|
+
networkUpdates.set(network, updateSettings(env));
|
|
145
|
+
}
|
|
146
|
+
return current.network;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The caches in front of a site that its changes purge: Cloudflare's, when the application has a token for it. */
|
|
150
|
+
function purgers(env: CmsBindings, site: NetworkSite): CachePurger[] {
|
|
151
|
+
const token = env.CLOUDFLARE_API_TOKEN?.trim();
|
|
152
|
+
if (!token) return [];
|
|
153
|
+
return [cloudflarePurger({
|
|
154
|
+
token, ...(env.CLOUDFLARE_ZONE_ID ? { zoneId: env.CLOUDFLARE_ZONE_ID } : {}), ...(env.CLOUDFLARE_API_URL ? { api: env.CLOUDFLARE_API_URL } : {}),
|
|
155
|
+
hosts: () => { const host = urlOf(siteUrl(env, site))?.hostname; return host ? [host] : []; },
|
|
156
|
+
})];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The main site's host. A request's own site is `c.get('cms')`. */
|
|
160
|
+
export function cmsFor(env: CmsBindings): CmsHost {
|
|
161
|
+
return networkFor(env).main;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A site's address: APP_URL for the main site, its primary domain for the others, never the
|
|
166
|
+
* request's Host header. With an http APP_URL (development), sites keep its scheme and port.
|
|
167
|
+
*/
|
|
168
|
+
export function siteUrl(env: CmsBindings, site: Pick<NetworkSite, 'host'>): string | undefined {
|
|
169
|
+
if (!site.host) return env.APP_URL;
|
|
170
|
+
const network = urlOf(env.APP_URL);
|
|
171
|
+
return network?.protocol === 'http:' ? `http://${site.host}${network.port ? `:${network.port}` : ''}` : `https://${site.host}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function urlOf(value: string | undefined): URL | undefined {
|
|
175
|
+
try { return value ? new URL(value) : undefined; }
|
|
176
|
+
catch { return undefined; }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The CMS host of the current request, for server code without a context argument. */
|
|
180
|
+
export function currentCms(): CmsHost {
|
|
181
|
+
const c = getRequestContext();
|
|
182
|
+
const cms = c?.get('cms');
|
|
183
|
+
if (!cms) throw new Error('No CMS on this request. Register cmsMiddleware in src/bootstrap/middlewares.ts.');
|
|
184
|
+
return cms;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Whether APP_URL names this machine. An unset or unreadable APP_URL is not local. */
|
|
188
|
+
export function localAddress(appUrl: string | undefined): boolean {
|
|
189
|
+
const host = urlOf(appUrl)?.hostname;
|
|
190
|
+
return host === 'localhost' || host === '127.0.0.1' || host === '[::1]' || host?.endsWith('.localhost') === true;
|
|
191
|
+
}
|