@cossackframework/cms 0.0.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +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 +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image transformers make the resized variants the media route serves: the Cloudflare Images
|
|
3
|
+
* binding on Workers, sharp on Node. The host computes the region and size; a transformer only
|
|
4
|
+
* cuts, scales and encodes.
|
|
5
|
+
*/
|
|
6
|
+
import type { ImageRect } from '../images';
|
|
7
|
+
|
|
8
|
+
export type ImageFormat = 'avif' | 'webp' | 'jpeg' | 'png';
|
|
9
|
+
|
|
10
|
+
export interface ImageTransformRequest {
|
|
11
|
+
/** The part of the source to keep, in source pixels. */
|
|
12
|
+
readonly rect: ImageRect;
|
|
13
|
+
/** The source's full size, for transformers that trim by edges. */
|
|
14
|
+
readonly source: { readonly width: number; readonly height: number };
|
|
15
|
+
/** The output size; the region already has its shape. */
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
readonly format: ImageFormat;
|
|
19
|
+
readonly quality: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ImageTransformer {
|
|
23
|
+
transform(input: ReadableStream<Uint8Array>, request: ImageTransformRequest): Promise<Uint8Array>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const FORMAT_TYPES: { readonly [F in ImageFormat]: string } = Object.freeze({ avif: 'image/avif', webp: 'image/webp', jpeg: 'image/jpeg', png: 'image/png' });
|
|
27
|
+
|
|
28
|
+
/** The best format the browser accepts: AVIF, then WebP, else the original's. */
|
|
29
|
+
export function negotiateFormat(accept: string | undefined, contentType: string): ImageFormat {
|
|
30
|
+
const header = (accept ?? '').toLowerCase();
|
|
31
|
+
if (header.includes('image/avif')) return 'avif';
|
|
32
|
+
if (header.includes('image/webp')) return 'webp';
|
|
33
|
+
return contentType === 'image/png' ? 'png' : 'jpeg';
|
|
34
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Server-only CMS host. Import from server code; the security transform keeps it out of the client.
|
|
2
|
+
export { CmsHost, createCMS, DEFAULT_RESERVED_PATHS, lockedCopy, PLUGIN_ENABLED, type AccountStores, type SiteLanguages, type ThemeInfo, type PluginAuthorView, type CmsOptions, type CmsProjectOptions, type CmsProjectConfig, type CmsModule, type PluginContext, type PluginUnrestricted, type PluginCms, type PluginResource, type PluginRegistrationLike, type ActivationStatus, type PluginStatus, type CommandHandler, type CommandContext, type ThemeLoader, type ThemeLoaders, type ThemeLoaderContext, type ThemeLoaderInput, type LayoutLoaderContext, type EntryLoaderContext, type ArchiveLoaderContext } from './host';
|
|
3
|
+
export { isLockedRecord, lockedView, withheldFieldNames } from './locked';
|
|
4
|
+
export { ResourceRepository, type OperationContext, type ListOptions, type ListFilter, type FieldFilter } from './repository';
|
|
5
|
+
export { CmsMenus, type MenuSummary } from './menus';
|
|
6
|
+
export { CmsAreas, type AreaShape } from './areas';
|
|
7
|
+
export { CmsFieldGroups } from './field-groups';
|
|
8
|
+
export { parseMeta, type MetaCheck } from './taxonomies';
|
|
9
|
+
export { collectionSpec, searchTextPath, defineFieldRql, indexRql, readCatalog, planSchema, migrate, type Catalog, type SchemaPlan, type PlannedStep, type SchemaProblem, type MigrationReport, type CollectionSpec, type FieldSpec, type IndexSpec } from './schema';
|
|
10
|
+
export { HOST_STEPS, HOST_TABLES, unknownHostSteps } from './host-schema';
|
|
11
|
+
export { Outbox, type DispatchReport, type OutboxOptions } from './outbox';
|
|
12
|
+
export { CmsUsers, type CmsUser, type CmsMember, type CmsRole, type UserPage } from './users';
|
|
13
|
+
export { CmsAccounts, normalizeEmail, type CmsAccount, type AccountProfile } from './accounts';
|
|
14
|
+
export { CmsSites, MAIN_SITE, siteHost, type SiteRecord, type SiteDomain, type SiteStatus } from './sites';
|
|
15
|
+
export { CmsNetwork, MAIN, networkSite, prefixedStorage, type NetworkSite, type SiteResolution, type CmsNetworkOptions, type NewSite, type NetworkSettings, type SiteExportPolicy, type ExportRequest } from './network';
|
|
16
|
+
export { siteExport, siteFile, EXPORT_SKIPPED_TABLES, EXPORT_REDACTED_COLUMNS, FILE_EXPORT_EMPTIED_TABLES, type SiteExportOptions } from './site-export';
|
|
17
|
+
export { siteImport, siteImportState, type SiteImportOptions, type SiteImportReport } from './site-import';
|
|
18
|
+
export { OPEN_POLICY, pluginState, readPolicy, type NetworkPluginState, type NetworkPolicy, type NetworkThemeState } from './network-policy';
|
|
19
|
+
export { CmsHandoffs, type Handoff } from './handoffs';
|
|
20
|
+
export { FileService, MAX_FILE_VARIANTS, VARIANT_ASPECTS, type CmsFile, type FileServiceOptions, type FileMetadata, type FileSummary, type ImageSettings, type PendingUpload } from './files';
|
|
21
|
+
export { CmsCache, type CacheEntry } from './cache';
|
|
22
|
+
export { CmsTaxonomies, freeSlug, type TermUsage, type TermInput } from './taxonomies';
|
|
23
|
+
export { CmsSettings } from './site-settings';
|
|
24
|
+
export { renderMarkdown, excerptOf } from './markdown';
|
|
25
|
+
export { brandIcon } from './brands';
|
|
26
|
+
export { createCmsAuth, type CmsAuth, type CmsAuthOptions, type CmsRequestUser } from './auth';
|
|
27
|
+
export {
|
|
28
|
+
createAuthSessionStore, createOAuthStateStore, createSessionStore, createJobStore, createNotificationStore,
|
|
29
|
+
type CmsAuthSessionStore, type CmsOAuthStateStore, type CmsSessionStore, type CmsAuthSession, type ChildSession, type EndedSessions,
|
|
30
|
+
} from './stores';
|
|
31
|
+
export { cmsReconcilers } from './reconcile';
|
|
32
|
+
export { CmsPreviews, type PreviewLink } from './previews';
|
|
33
|
+
export { CmsAutosaves, type Autosave } from './autosaves';
|
|
34
|
+
export { CmsDrafts, EDITING_WINDOW, saveBytes, type Draft, type DraftInput } from './drafts';
|
|
35
|
+
export { CmsNotes, noteAnnounced, type NoteAnnouncedEvent, type NoteAnnouncement, type NoteInput } from './notes';
|
|
36
|
+
export { CmsRedirects } from './redirects';
|
|
37
|
+
export { CmsApiTokens, API_TOKEN_LIMIT, type ApiToken, type ApiTokenScope } from './api-tokens';
|
|
38
|
+
export { CmsWebhooks, verifyWebhookSignature } from './webhooks';
|
|
39
|
+
export { CmsIndexNow, INDEXNOW_ENDPOINT, INDEXNOW_KEY, type IndexNowOptions } from './indexnow';
|
|
40
|
+
export { CmsPurge, PurgeError, type CachePurger, type CmsPurgeOptions, type PurgeContext, type PurgeRecord } from './purge';
|
|
41
|
+
export { SiteSearch, SITE_SEARCH, type SearchedCollection, type SearchRebuildEvent, type SiteSearchHit, type SiteSearchOptions, type SiteSearchPage } from './site-search';
|
|
42
|
+
export { workerLoaderRunner, serveIsolatedCall, inFlightLimiter, ISOLATE_LIMITS, ISOLATES_IN_FLIGHT, ISOLATE_COMPATIBILITY_DATE, type PluginRunner, type IsolatedPluginCode, type BridgeProps, type IsolatedWork, type IsolateLimits, type WorkerLoaderLike, type WorkerCodeLike, type LoopbackExports } from './isolation';
|
|
43
|
+
export { pluginCapabilities, pluginMetaKey, JOB_NAME, type PluginFiles, type PluginMail, type PluginJobs, type PluginJobContext, type PluginJobHandler, type PluginUsers, type PluginUser, type PluginCache, type PluginSecrets, type PluginAi, type PluginPayments, type PluginCapabilities, type CapabilityHost } from './capabilities';
|
|
44
|
+
export { CmsSchedules, SCHEDULE_GRACE_MS, type DueSchedule, type ScheduleRow } from './schedules';
|
|
45
|
+
export { CmsAudit, AUDIT_RETENTION_MS, type AuditEntry, type AuditQuery } from './audit';
|
|
46
|
+
export { CmsAutomations, type AutomationsOptions } from './automations';
|
|
47
|
+
export { AI_LIMITS, checkAiRequest, type AiProvider, type AiRequest } from './ai';
|
|
48
|
+
export { checkCheckout, type Checkout, type CheckoutInput, type PaymentsProvider } from './payments';
|
|
49
|
+
export { stripePayments, STRIPE_API, STRIPE_TOLERANCE_MS, type StripePaymentsOptions } from './stripe';
|
|
50
|
+
export { cloudflarePurger, zoneCandidates, CLOUDFLARE_API, type CloudflarePurgerOptions } from './cloudflare';
|
|
51
|
+
export { CmsTraffic, type CrawlerVisits, type NotFoundRow, type VisitKind } from './traffic';
|
|
52
|
+
export { CmsComments, type CommentListOptions } from './comments';
|
|
53
|
+
export { CmsForms, type CmsMail, type LoadedForm, type SubmitContext, type SubmitResult, type SubmissionList } from './forms';
|
|
54
|
+
export { siteMailer, type CmsMailer, type MailTransport, type OutgoingMail, type SiteMailerOptions } from './mail';
|
|
55
|
+
export { sha256Hex, randomToken, base64Url, timingSafeEqual } from './tokens';
|
|
56
|
+
export { FORMAT_TYPES, negotiateFormat, type ImageTransformer, type ImageTransformRequest, type ImageFormat } from './images';
|
|
57
|
+
export { CmsSecurity, SIGN_IN_ATTEMPTS, SIGN_IN_LOCK, RESET_REQUESTS, type PasskeyInfo, type StoredPasskeyRow, type SecurityStatus, type ChallengeKind } from './security';
|
|
58
|
+
export * from '../index';
|
|
59
|
+
export { seedStarterContent, type SeedReport } from './seed';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexNow: tell Bing, Yandex, Naver and Seznam at once that pages changed, so their indexes
|
|
3
|
+
* (and the answers built on them, such as Copilot) refresh in minutes. Pings run from the
|
|
4
|
+
* outbox after a commit, so a failed one retries. Settings → IndexNow holds the key, which
|
|
5
|
+
* the site serves at `/indexnow/<key>.txt`.
|
|
6
|
+
*/
|
|
7
|
+
import type { CmsSettings } from './site-settings';
|
|
8
|
+
import type { ResourceEvent } from '../hooks';
|
|
9
|
+
import type { CollectionDefinition } from '../collections';
|
|
10
|
+
import { systemPrincipal } from '../permissions';
|
|
11
|
+
|
|
12
|
+
export const INDEXNOW_ENDPOINT = 'https://api.indexnow.org/indexnow';
|
|
13
|
+
/** A key is 8 to 128 of a-z, A-Z, 0-9 and hyphens. */
|
|
14
|
+
export const INDEXNOW_KEY = /^[A-Za-z0-9-]{8,128}$/;
|
|
15
|
+
|
|
16
|
+
export interface IndexNowOptions {
|
|
17
|
+
/** The public origin of the site, such as `https://example.com`; pings need it. */
|
|
18
|
+
readonly siteUrl?: () => string | undefined;
|
|
19
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
20
|
+
readonly now?: () => number;
|
|
21
|
+
readonly endpoint?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class CmsIndexNow {
|
|
25
|
+
readonly #settings: CmsSettings;
|
|
26
|
+
readonly #siteUrl: () => string | undefined;
|
|
27
|
+
readonly #fetch: typeof globalThis.fetch;
|
|
28
|
+
readonly #endpoint: string;
|
|
29
|
+
/** The last submissions made from this isolate, newest first, for the dashboard. */
|
|
30
|
+
readonly recent: { at: number; urls: string[]; status: number }[] = [];
|
|
31
|
+
readonly #now: () => number;
|
|
32
|
+
|
|
33
|
+
constructor(settings: CmsSettings, options: IndexNowOptions = {}) {
|
|
34
|
+
this.#settings = settings;
|
|
35
|
+
this.#siteUrl = options.siteUrl ?? (() => undefined);
|
|
36
|
+
this.#fetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
37
|
+
this.#endpoint = options.endpoint ?? INDEXNOW_ENDPOINT;
|
|
38
|
+
this.#now = options.now ?? Date.now;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The site's origin without a trailing slash, or null when unknown. */
|
|
42
|
+
origin(): string | null {
|
|
43
|
+
const url = this.#siteUrl()?.trim().replace(/\/+$/, '');
|
|
44
|
+
return url && /^https?:\/\/[^/\s]+$/.test(url) ? url : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The key, made and stored the first time pings are on. Null while IndexNow is off. */
|
|
48
|
+
async key(): Promise<string | null> {
|
|
49
|
+
const settings = await this.#settings.all();
|
|
50
|
+
if (!settings['indexnow.enabled']) return null;
|
|
51
|
+
const stored = settings['indexnow.key'];
|
|
52
|
+
if (INDEXNOW_KEY.test(stored)) return stored;
|
|
53
|
+
const key = crypto.randomUUID().replaceAll('-', '');
|
|
54
|
+
await this.#settings.update('indexnow', { key }, { principal: systemPrincipal('indexnow') });
|
|
55
|
+
return key;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Where the key file is served. */
|
|
59
|
+
keyLocation(origin: string, key: string): string {
|
|
60
|
+
return `${origin}/indexnow/${key}.txt`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Submit absolute or site-relative URLs. Throws on a failed request, so the outbox retries. Returns the response status, or null when off. */
|
|
64
|
+
async submit(urls: readonly string[]): Promise<number | null> {
|
|
65
|
+
const key = await this.key();
|
|
66
|
+
const origin = this.origin();
|
|
67
|
+
if (!key || !origin || !urls.length) return null;
|
|
68
|
+
const list = [...new Set(urls.map(url => /^https?:\/\//.test(url) ? url : `${origin}${url}`))].filter(url => url.startsWith(`${origin}/`) || url === origin).slice(0, 10_000);
|
|
69
|
+
if (!list.length) return null;
|
|
70
|
+
const response = await this.#fetch(this.#endpoint, {
|
|
71
|
+
method: 'POST', headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
72
|
+
body: JSON.stringify({ host: new URL(origin).host, key, keyLocation: this.keyLocation(origin, key), urlList: list }),
|
|
73
|
+
});
|
|
74
|
+
this.recent.unshift({ at: this.#now(), urls: list, status: response.status });
|
|
75
|
+
this.recent.splice(20);
|
|
76
|
+
// 200 and 202 accept the URLs; 4xx mean the key or URLs are wrong and retrying will not help.
|
|
77
|
+
if (response.status >= 500 || response.status === 429) throw new Error(`IndexNow answered ${response.status}.`);
|
|
78
|
+
return response.status;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Whether an entry event changed a public page: the entry is or was published, in a
|
|
83
|
+
* collection on the site that engines may index. Drafts and private collections ping nothing.
|
|
84
|
+
*/
|
|
85
|
+
static concerns(event: ResourceEvent, collection: CollectionDefinition): boolean {
|
|
86
|
+
if (collection.path === null || collection.path === undefined || collection.robots?.noindex || !event.record) return false;
|
|
87
|
+
const publishable = collection.publishable !== false;
|
|
88
|
+
if (!publishable) return collection.visibility === 'public';
|
|
89
|
+
return event.previousStatus === 'published' || event.record.status === 'published';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's side of isolated plugins (specs/cms-plugin-isolation.md): the runner that calls
|
|
3
|
+
* a plugin's Worker, and what the bridge serves back. Platform-free: the Cloudflare pieces
|
|
4
|
+
* that import `cloudflare:workers` are in `../cloudflare.ts`.
|
|
5
|
+
*/
|
|
6
|
+
import { getRequestContext } from '@cossackframework/core';
|
|
7
|
+
import { CmsError } from '../errors';
|
|
8
|
+
import { ISOLATE_MEMBERS, type IsolateCall, type IsolateEntrypoint } from '../isolation';
|
|
9
|
+
import { systemPrincipal, type Principal } from '../permissions';
|
|
10
|
+
import type { PluginContext } from './host';
|
|
11
|
+
|
|
12
|
+
/** An isolated plugin's bundle, from the registry. */
|
|
13
|
+
export interface IsolatedPluginCode {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly version: string;
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly hash: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What only the host knows about a call; the bridge reads it from its props. */
|
|
21
|
+
export interface BridgeProps {
|
|
22
|
+
readonly site: string;
|
|
23
|
+
readonly plugin: string;
|
|
24
|
+
/** Unix milliseconds after which the bridge refuses the call. */
|
|
25
|
+
readonly deadline: number;
|
|
26
|
+
/** The principals the host passed with the call: the only ones the plugin may act as, besides its own. */
|
|
27
|
+
readonly principals: readonly Principal[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Hooks are short; commands, jobs and schedules do work. */
|
|
31
|
+
export type IsolatedWork = 'hook' | 'work';
|
|
32
|
+
|
|
33
|
+
export interface PluginRunner {
|
|
34
|
+
run(plugin: IsolatedPluginCode, call: IsolateCall, props: BridgeProps, work: IsolatedWork): Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IsolateLimits {
|
|
38
|
+
readonly cpuMs: number;
|
|
39
|
+
readonly subRequests: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** First guesses, to check on Cloudflare: Miniflare enforces neither. */
|
|
43
|
+
export const ISOLATE_LIMITS: Readonly<Record<IsolatedWork, IsolateLimits>> = Object.freeze({
|
|
44
|
+
hook: Object.freeze({ cpuMs: 50, subRequests: 50 }),
|
|
45
|
+
work: Object.freeze({ cpuMs: 1_000, subRequests: 1_000 }),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** Distinct Dynamic Workers a Worker request may have in flight. */
|
|
49
|
+
export const ISOLATES_IN_FLIGHT = 4;
|
|
50
|
+
|
|
51
|
+
/** The compatibility date isolated plugins run with; generated applications use the same. */
|
|
52
|
+
export const ISOLATE_COMPATIBILITY_DATE = '2026-06-06';
|
|
53
|
+
|
|
54
|
+
/** The Worker Loader binding (`env.LOADER`), as far as the runner uses it. */
|
|
55
|
+
export interface WorkerLoaderLike {
|
|
56
|
+
get(id: string, load: () => Promise<WorkerCodeLike>): { getEntrypoint(name?: string, options?: { limits?: IsolateLimits }): unknown };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface WorkerCodeLike {
|
|
60
|
+
readonly compatibilityDate: string;
|
|
61
|
+
readonly compatibilityFlags?: readonly string[];
|
|
62
|
+
readonly mainModule: string;
|
|
63
|
+
readonly modules: Readonly<Record<string, string>>;
|
|
64
|
+
readonly env?: Readonly<Record<string, unknown>>;
|
|
65
|
+
readonly globalOutbound?: unknown;
|
|
66
|
+
readonly tails?: readonly unknown[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The application's loopback exports (`ctx.exports`): its `PluginBridge`, and `PluginTail` for logs. */
|
|
70
|
+
export interface LoopbackExports {
|
|
71
|
+
readonly PluginBridge?: (options: { props: BridgeProps }) => unknown;
|
|
72
|
+
readonly PluginTail?: (options: { props: { plugin: string } }) => unknown;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const SHARED = {};
|
|
76
|
+
|
|
77
|
+
/** At most `limit` distinct plugins in flight per request; the rest wait their turn. */
|
|
78
|
+
export function inFlightLimiter(limit: number, request: () => object | undefined = () => getRequestContext()) {
|
|
79
|
+
const requests = new WeakMap<object, { running: Map<string, number>; waiting: (() => void)[] }>();
|
|
80
|
+
return async <T>(plugin: string, run: () => Promise<T>): Promise<T> => {
|
|
81
|
+
const key = request() ?? SHARED;
|
|
82
|
+
let state = requests.get(key);
|
|
83
|
+
if (!state) { state = { running: new Map(), waiting: [] }; requests.set(key, state); }
|
|
84
|
+
const entry = state;
|
|
85
|
+
while (!entry.running.has(plugin) && entry.running.size >= limit) await new Promise<void>(resolve => entry.waiting.push(resolve));
|
|
86
|
+
entry.running.set(plugin, (entry.running.get(plugin) ?? 0) + 1);
|
|
87
|
+
try { return await run(); }
|
|
88
|
+
finally {
|
|
89
|
+
const count = (entry.running.get(plugin) ?? 1) - 1;
|
|
90
|
+
if (count) entry.running.set(plugin, count);
|
|
91
|
+
else { entry.running.delete(plugin); entry.waiting.splice(0).forEach(resolve => resolve()); }
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Runs isolated plugins in Dynamic Workers: one per plugin version, shared by every site,
|
|
98
|
+
* with no bindings and no network, and the bridge passed with each call.
|
|
99
|
+
*/
|
|
100
|
+
export function workerLoaderRunner(options: {
|
|
101
|
+
readonly loader: WorkerLoaderLike;
|
|
102
|
+
readonly exports: () => LoopbackExports;
|
|
103
|
+
readonly compatibilityDate?: string;
|
|
104
|
+
readonly limits?: Partial<Record<IsolatedWork, IsolateLimits>>;
|
|
105
|
+
}): PluginRunner {
|
|
106
|
+
const limit = inFlightLimiter(ISOLATES_IN_FLIGHT);
|
|
107
|
+
const limits = { ...ISOLATE_LIMITS, ...options.limits };
|
|
108
|
+
return {
|
|
109
|
+
run(plugin, call, props, work) {
|
|
110
|
+
const exports = options.exports();
|
|
111
|
+
if (!exports.PluginBridge) throw new CmsError('CMS_UNAVAILABLE', 'The application does not export PluginBridge, which isolated plugins call the CMS through.');
|
|
112
|
+
const tail = exports.PluginTail;
|
|
113
|
+
const worker = options.loader.get(`${plugin.name}@${plugin.version}:${plugin.hash.slice(0, 16)}`, async () => ({
|
|
114
|
+
compatibilityDate: options.compatibilityDate ?? ISOLATE_COMPATIBILITY_DATE,
|
|
115
|
+
// AsyncLocalStorage keeps concurrent calls on their own bridges.
|
|
116
|
+
compatibilityFlags: ['nodejs_als'],
|
|
117
|
+
mainModule: 'plugin.js',
|
|
118
|
+
modules: { 'plugin.js': plugin.code },
|
|
119
|
+
env: {},
|
|
120
|
+
globalOutbound: null,
|
|
121
|
+
...(tail ? { tails: [tail({ props: { plugin: plugin.name } })] } : {}),
|
|
122
|
+
}));
|
|
123
|
+
const entrypoint = worker.getEntrypoint(undefined, { limits: limits[work] }) as IsolateEntrypoint;
|
|
124
|
+
const bridge = exports.PluginBridge({ props });
|
|
125
|
+
return limit(plugin.name, () => entrypoint.run(call, bridge as never));
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Principals compared by value: the host hands out plain objects, and they cross as copies. */
|
|
131
|
+
function samePrincipal(left: unknown, right: Principal): boolean {
|
|
132
|
+
return stableJson(left) === stableJson(right);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function stableJson(value: unknown): string {
|
|
136
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(',')}]`;
|
|
137
|
+
if (value && typeof value === 'object') return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${stableJson((value as Record<string, unknown>)[key])}`).join(',')}}`;
|
|
138
|
+
return JSON.stringify(value) ?? 'undefined';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The resource methods isolated plugins may call, with how many arguments each takes; the last is the operation context. */
|
|
142
|
+
const RESOURCE_METHODS = new Map<string, number>([['get', 2], ['list', 2], ['count', 2], ['search', 3], ['create', 2], ['update', 3], ['delete', 2]]);
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Serve one bridge call from the plugin's context: the one the host builds for in-app plugins,
|
|
146
|
+
* so every grant and limit check applies unchanged. Only `ISOLATE_MEMBERS` are served, and a
|
|
147
|
+
* repository call must act as a principal the host gave the call, or as the plugin itself.
|
|
148
|
+
*/
|
|
149
|
+
export async function serveIsolatedCall(context: PluginContext, member: string, args: readonly unknown[], principals: readonly Principal[]): Promise<unknown> {
|
|
150
|
+
const name = context.name;
|
|
151
|
+
if (!(ISOLATE_MEMBERS as readonly string[]).includes(member)) throw new CmsError('CMS_FORBIDDEN', `Plugin ${name} asked for ${member}, which isolated plugins cannot use.`);
|
|
152
|
+
const [group, method] = member.split('.') as [string, string | undefined];
|
|
153
|
+
const call = (target: object, key: string, values: readonly unknown[]) => (target as Record<string, (...values: unknown[]) => unknown>)[key]!(...values);
|
|
154
|
+
switch (group) {
|
|
155
|
+
case 'settings': return method === 'get' ? context.settings.get(String(args[0])) : context.settings.all();
|
|
156
|
+
case 'resource': {
|
|
157
|
+
const [id, ...rest] = args;
|
|
158
|
+
const arity = method ? RESOURCE_METHODS.get(method) : undefined;
|
|
159
|
+
if (!method || arity === undefined) throw new CmsError('CMS_FORBIDDEN', `Plugin ${name} asked for ${member}.`);
|
|
160
|
+
// Exactly the method's arguments: the context checked here is the one the method reads, not an extra one after it.
|
|
161
|
+
if (rest.length !== arity) throw new CmsError('CMS_FORBIDDEN', `Plugin ${name} called ${member} with ${rest.length} arguments; it takes ${arity}, the last its operation context.`);
|
|
162
|
+
const operation = rest[arity - 1] as { principal?: unknown } | undefined;
|
|
163
|
+
const own = systemPrincipal(`plugin:${name}`);
|
|
164
|
+
if (!operation || typeof operation !== 'object' || !(samePrincipal(operation.principal, own) || principals.some(principal => samePrincipal(operation.principal, principal)))) {
|
|
165
|
+
throw new CmsError('CMS_FORBIDDEN', `Plugin ${name} must act as the principal its handler was given, or as plugin:${name}.`);
|
|
166
|
+
}
|
|
167
|
+
return call(context.cms.resource(String(id)), method, rest);
|
|
168
|
+
}
|
|
169
|
+
case 'fetch': {
|
|
170
|
+
const request = args[0];
|
|
171
|
+
if (!(request instanceof Request)) throw new CmsError('CMS_VALIDATION', `Plugin ${name} must fetch with a Request.`);
|
|
172
|
+
return context.fetch(request);
|
|
173
|
+
}
|
|
174
|
+
case 'hooks': {
|
|
175
|
+
const [point, ...rest] = args;
|
|
176
|
+
if (method === 'doAction') return context.hooks.doAction(context.hooks.point(String(point), 'action'), rest[0], rest[1] as never);
|
|
177
|
+
return context.hooks.applyFilters(context.hooks.point(String(point), 'filter'), rest[0], rest[1], rest[2] as never);
|
|
178
|
+
}
|
|
179
|
+
case 'files': case 'mail': case 'jobs': case 'users': case 'cache': case 'secrets': case 'ai': case 'payments':
|
|
180
|
+
return call(context[group as 'files'], method!, args);
|
|
181
|
+
}
|
|
182
|
+
throw new CmsError('CMS_FORBIDDEN', `Plugin ${name} asked for ${member}.`);
|
|
183
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locked entries (specs/cms-invariants.md, rule 1): an entry with a password (protected) or
|
|
3
|
+
* members-only. Those who may update it read it whole; everyone else gets the reader's view:
|
|
4
|
+
* its core fields, taxonomies and lock flags, without its password or its content. This module
|
|
5
|
+
* is the one place that says what is locked and what the reader's view holds.
|
|
6
|
+
*/
|
|
7
|
+
import { CORE_FIELDS } from '../collections';
|
|
8
|
+
import type { FieldDeclaration } from '../fields';
|
|
9
|
+
import type { RecordShape } from '../records';
|
|
10
|
+
|
|
11
|
+
/** Whether an entry is protected (it has a password) or members-only. */
|
|
12
|
+
export function isLockedRecord(record: { readonly [field: string]: unknown }): boolean {
|
|
13
|
+
return (typeof record.password === 'string' && record.password.length > 0) || record.membersOnly === true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Fields that stay in the reader's view of a locked entry: the lock itself, so readers know why. */
|
|
17
|
+
const LOCK_FIELDS: readonly string[] = ['membersOnly'];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The fields a locked entry's readers do not get: every declared field but the core fields
|
|
21
|
+
* (less `summary`, which is written from the content), taxonomies and the lock flags. The
|
|
22
|
+
* password is always among them.
|
|
23
|
+
*/
|
|
24
|
+
export function withheldFieldNames(fields: { readonly [name: string]: FieldDeclaration }): Set<string> {
|
|
25
|
+
const kept = new Set<string>([...CORE_FIELDS.filter(name => name !== 'summary'), ...LOCK_FIELDS]);
|
|
26
|
+
return new Set(Object.entries(fields)
|
|
27
|
+
.filter(([name, field]) => name === 'password' || (!kept.has(name) && !(field.kind === 'string' && field.taxonomy)))
|
|
28
|
+
.map(([name]) => name));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The reader's view of a record: without its password always, and, when it is locked, without
|
|
33
|
+
* the withheld fields (`withheldFieldNames`). Undeclared keys (id, revision, timestamps, owner)
|
|
34
|
+
* stay. A record that is not locked comes back whole, less an empty password.
|
|
35
|
+
*/
|
|
36
|
+
export function lockedView<T extends RecordShape>(record: T, fields: { readonly [name: string]: FieldDeclaration }): T {
|
|
37
|
+
if (!isLockedRecord(record)) {
|
|
38
|
+
if (!('password' in record)) return record;
|
|
39
|
+
const { password: _password, ...rest } = record;
|
|
40
|
+
return rest as unknown as T;
|
|
41
|
+
}
|
|
42
|
+
const withheld = withheldFieldNames(fields);
|
|
43
|
+
withheld.add('password');
|
|
44
|
+
return Object.fromEntries(Object.entries(record).filter(([name]) => !withheld.has(name))) as unknown as T;
|
|
45
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's mailer, `host.mail`: every email the CMS sends goes out as its plain text plus an
|
|
3
|
+
* HTML part laid out from it with Settings → Email, after the `cms.mail.before-send` filters,
|
|
4
|
+
* through the application's transport (Cloudflare's `EMAIL` binding, the Node adapter's SMTP
|
|
5
|
+
* sender, or any `{ send(message) }`).
|
|
6
|
+
*/
|
|
7
|
+
import type { HookRegistry } from '@cossackframework/core/hooks';
|
|
8
|
+
import { mailBeforeSend, mailMessageOf, MAIL_KINDS, type MailKind, type MailMessage, type MailSendInput } from '../hooks';
|
|
9
|
+
import { mailHtml } from '../mail';
|
|
10
|
+
|
|
11
|
+
/** What hands a laid-out message to a mail service. */
|
|
12
|
+
export interface MailTransport {
|
|
13
|
+
send(message: MailMessage): Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A message for `host.mail.send`: plain text, which the mailer lays out as HTML too. */
|
|
17
|
+
export interface OutgoingMail {
|
|
18
|
+
readonly to: string;
|
|
19
|
+
/** Default: the site's sender (`mailFrom`). */
|
|
20
|
+
readonly from?: string;
|
|
21
|
+
readonly subject: string;
|
|
22
|
+
readonly text: string;
|
|
23
|
+
readonly replyTo?: string;
|
|
24
|
+
/** What it is, for `cms.mail.before-send` filters and the button's text. Default `other`, whose recipient filters cannot change. */
|
|
25
|
+
readonly kind?: MailKind;
|
|
26
|
+
/** The plugin sending it, for `kind: 'plugin'`. */
|
|
27
|
+
readonly plugin?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CmsMailer {
|
|
31
|
+
/** Lay out, filter and send one message: false when a filter cancelled it. Transport errors are thrown. */
|
|
32
|
+
send(message: OutgoingMail): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SiteMailerOptions {
|
|
36
|
+
readonly transport: MailTransport;
|
|
37
|
+
/** The sender when a message names none. */
|
|
38
|
+
readonly from: string;
|
|
39
|
+
readonly site: string;
|
|
40
|
+
readonly hooks: Pick<HookRegistry, 'applyFilters'>;
|
|
41
|
+
/** The site's settings, for the layout; when they cannot be read, the defaults are used. */
|
|
42
|
+
readonly settings: () => Promise<Readonly<Record<string, unknown>>>;
|
|
43
|
+
/** The site's public address, for links and a root-relative logo. */
|
|
44
|
+
readonly siteUrl: () => string | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The button's text by the kind of message, when one line of it is a link alone. */
|
|
48
|
+
const ACTIONS: Partial<Record<MailKind, string>> = {
|
|
49
|
+
verification: 'Confirm your email', reset: 'Reset your password', 'magic-link': 'Sign in', invitation: 'Set your password', comment: 'Open the page', note: 'Open the notes',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export function siteMailer(options: SiteMailerOptions): CmsMailer {
|
|
53
|
+
return {
|
|
54
|
+
async send(message) {
|
|
55
|
+
const kind: MailKind = (MAIL_KINDS as readonly string[]).includes(message.kind ?? '') ? message.kind! : 'other';
|
|
56
|
+
const subject = message.subject.replace(/[\r\n]+/g, ' ').trim().slice(0, 300);
|
|
57
|
+
const settings = await options.settings().catch(() => ({} as Readonly<Record<string, unknown>>));
|
|
58
|
+
const text = (key: string) => typeof settings[key] === 'string' ? settings[key] as string : '';
|
|
59
|
+
const siteUrl = options.siteUrl()?.trim() || undefined;
|
|
60
|
+
const logo = mailLogo([text('email.logo'), text('general.logo'), text('general.appIcon'), text('general.favicon')], siteUrl);
|
|
61
|
+
const html = mailHtml({
|
|
62
|
+
subject, text: message.text,
|
|
63
|
+
site: { title: text('general.siteTitle'), ...(siteUrl ? { url: siteUrl } : {}), ...(logo ? { logo } : {}) },
|
|
64
|
+
footer: text('email.footer'), accent: text('email.accentColor'), lang: text('languages.default'), ...(ACTIONS[kind] ? { action: ACTIONS[kind] } : {}),
|
|
65
|
+
});
|
|
66
|
+
const laid: MailMessage = { to: message.to, from: message.from ?? options.from, subject, text: message.text, html, ...(message.replyTo ? { replyTo: message.replyTo } : {}) };
|
|
67
|
+
const input: MailSendInput = { kind, plugin: kind === 'plugin' ? message.plugin ?? null : null, site: options.site };
|
|
68
|
+
const final = await options.hooks.applyFilters(mailBeforeSend, laid as MailMessage | null, input).then(
|
|
69
|
+
value => mailMessageOf(value, laid, kind),
|
|
70
|
+
error => { console.warn(`[cms] a ${mailBeforeSend.name} filter failed, so the ${kind} email to ${laid.to} goes out as laid out`, error); return laid; });
|
|
71
|
+
if (!final) return false;
|
|
72
|
+
await options.transport.send(final);
|
|
73
|
+
return true;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The first logo that can show in an email, as an absolute URL: Settings → Email's as chosen,
|
|
80
|
+
* then the site's logo, app icon and site icon unless they are SVG, which many email apps do
|
|
81
|
+
* not show. A root-relative one needs the site's address.
|
|
82
|
+
*/
|
|
83
|
+
function mailLogo(candidates: readonly string[], siteUrl: string | undefined): string | undefined {
|
|
84
|
+
for (const [index, candidate] of candidates.entries()) {
|
|
85
|
+
const value = candidate.trim();
|
|
86
|
+
if (!value || (index > 0 && /\.svg(?:[?#]|$)/i.test(value))) continue;
|
|
87
|
+
try {
|
|
88
|
+
const url = new URL(value, siteUrl);
|
|
89
|
+
if (url.protocol === 'https:' || url.protocol === 'http:') return url.href;
|
|
90
|
+
} catch { /* a relative address without the site's: none */ }
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown for post and page bodies, rendered on the server. Raw HTML is escaped rather
|
|
3
|
+
* than passed through, and links and images use markdown-it's safe URL check, so stored
|
|
4
|
+
* content cannot inject script into the public site.
|
|
5
|
+
*/
|
|
6
|
+
import MarkdownIt from 'markdown-it';
|
|
7
|
+
|
|
8
|
+
const markdown = new MarkdownIt({ html: false, linkify: true, typographer: true });
|
|
9
|
+
|
|
10
|
+
/** HTML for a Markdown body. */
|
|
11
|
+
export function renderMarkdown(text: string): string {
|
|
12
|
+
return markdown.render(typeof text === 'string' ? text : '');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Plain text of a Markdown body, cut at a word boundary after `words` words. */
|
|
16
|
+
export function excerptOf(text: string, words = 55): string {
|
|
17
|
+
const parts: string[] = [];
|
|
18
|
+
for (const token of markdown.parse(typeof text === 'string' ? text : '', {})) {
|
|
19
|
+
if (token.type !== 'inline') continue;
|
|
20
|
+
parts.push((token.children ?? []).filter(child => child.type === 'text' || child.type === 'code_inline').map(child => child.content).join(''));
|
|
21
|
+
}
|
|
22
|
+
const all = parts.join(' ').replace(/\s+/g, ' ').trim().split(' ').filter(Boolean);
|
|
23
|
+
return all.length > words ? `${all.slice(0, words).join(' ')}…` : all.join(' ');
|
|
24
|
+
}
|