@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
package/src/icons.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icons by name. Any icon of @cossackframework/solar-icons (`ICON_CATEGORIES`, generated) can be
|
|
3
|
+
* chosen wherever the dashboard asks for one, and drawn on the site and in the dashboard in the
|
|
4
|
+
* style Settings → Appearance picks. Icons ship as sprites of `<symbol>`s under `/assets/icons/`,
|
|
5
|
+
* one per style and category plus one of the hot set below, written by the `cossackCmsIcons()`
|
|
6
|
+
* Vite plugin (`@cossackframework/cms/vite`); a page draws `<svg><use href="…#name">`, so no icon
|
|
7
|
+
* markup is in the HTML or the bundles, and the browser caches each sprite for a year.
|
|
8
|
+
*/
|
|
9
|
+
import { ICON_CATEGORIES, ICON_SET_VERSION, type IconCategory } from './icon-catalog';
|
|
10
|
+
|
|
11
|
+
export { ICON_CATEGORIES, ICON_SET_VERSION, type IconCategory };
|
|
12
|
+
|
|
13
|
+
export const ICON_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
14
|
+
|
|
15
|
+
/** The six Solar styles, as the icon package names them. */
|
|
16
|
+
export const ICON_STYLES = Object.freeze(['line', 'bold', 'duotone', 'broken', 'outline', 'line-duotone'] as const);
|
|
17
|
+
export type IconStyleName = (typeof ICON_STYLES)[number];
|
|
18
|
+
export const ICON_STYLE_LABELS: Readonly<Record<IconStyleName, string>> = Object.freeze({
|
|
19
|
+
line: 'Line', bold: 'Bold', duotone: 'Bold duotone', broken: 'Broken', outline: 'Outline', 'line-duotone': 'Line duotone',
|
|
20
|
+
});
|
|
21
|
+
export const DEFAULT_ICON_STYLE: IconStyleName = 'line';
|
|
22
|
+
|
|
23
|
+
export function isIconStyle(value: unknown): value is IconStyleName {
|
|
24
|
+
return typeof value === 'string' && (ICON_STYLES as readonly string[]).includes(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const SITE_ICON_NAMES: readonly string[] = Object.freeze([
|
|
28
|
+
// Marks and states
|
|
29
|
+
'check-circle', 'close-circle', 'add-circle', 'info-circle', 'question-circle', 'danger-triangle', 'star', 'stars', 'heart', 'like', 'smile-circle',
|
|
30
|
+
// Energy and achievement
|
|
31
|
+
'bolt', 'rocket', 'lightbulb', 'crown', 'medal-ribbon', 'cup', 'gift', 'confetti', 'target', 'flag',
|
|
32
|
+
// Trust and technology
|
|
33
|
+
'shield', 'shield-check', 'shield-star', 'lock', 'key', 'settings', 'code-square', 'cpu', 'server-2', 'database', 'cloud', 'global', 'earth',
|
|
34
|
+
// Places and time
|
|
35
|
+
'map', 'map-point', 'pin', 'home-2', 'buildings', 'bell', 'clock-circle', 'calendar', 'hourglass', 'history', 'refresh',
|
|
36
|
+
// Numbers and money
|
|
37
|
+
'chart', 'chart-2', 'chart-square', 'pie-chart', 'graph', 'course-up', 'course-down', 'dollar', 'euro', 'wallet', 'wallet-money', 'hand-money', 'hand-heart',
|
|
38
|
+
// Commerce
|
|
39
|
+
'cart-large-2', 'bag-4', 'shop', 'delivery', 'box', 'tag',
|
|
40
|
+
// Contact and people
|
|
41
|
+
'letter', 'mailbox', 'phone', 'chat-round-dots', 'chat-round-line', 'dialog', 'link', 'share', 'user', 'user-circle', 'user-id', 'user-plus', 'users-group-rounded', 'case',
|
|
42
|
+
// Documents and learning
|
|
43
|
+
'book', 'bookmark', 'notebook', 'document-text', 'notes', 'clipboard-list', 'checklist', 'list-check', 'diploma', 'square-academic-cap', 'pen', 'magnifier', 'eye',
|
|
44
|
+
// Media and devices
|
|
45
|
+
'camera', 'gallery', 'video-frame', 'play-circle', 'music-note', 'microphone', 'monitor', 'laptop', 'smartphone', 'tablet', 'palette', 'ruler', 'scale',
|
|
46
|
+
// Nature, travel and health
|
|
47
|
+
'leaf', 'sun', 'moon', 'fire', 'snowflake', 'umbrella', 'plane', 'bus', 'running', 'health', 'stethoscope', 'pills', 'hospital', 'bed',
|
|
48
|
+
// Arrows
|
|
49
|
+
'arrow-right', 'arrow-left', 'arrow-up', 'arrow-down', 'download-minimalistic', 'upload-minimalistic',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The icons the dashboard draws besides the site's: collections' choices, sections, blocks and
|
|
55
|
+
* controls. With `SITE_ICON_NAMES` they make the hot sprite, which a dashboard page loads in one request.
|
|
56
|
+
*/
|
|
57
|
+
export const DASHBOARD_ICON_NAMES: readonly string[] = Object.freeze([
|
|
58
|
+
'document-text', 'notebook', 'box', 'bag-4', 'cart-large-2', 'shop', 'gallery', 'calendar-mark', 'map-point', 'star', 'bookmark', 'case', 'cup', 'home-2',
|
|
59
|
+
'notes', 'clipboard-list', 'graph', 'medal-ribbon', 'video-library', 'book', 'ticket', 'user-id', 'hashtag', 'folder', 'tag', 'widget-4', 'structure', 'tuning-2',
|
|
60
|
+
'server-2', 'plug-circle', 'settings', 'text-field', 'palette-2', 'widget-add', 'chat-round-dots', 'paragraph-spacing', 'text-bold', 'gallery-wide', 'chat-round-line',
|
|
61
|
+
'list', 'code-square', 'cursor-square', 'play-circle', 'video-frame', 'music-note', 'minus-square', 'layers', 'widget', 'widget-2', 'widget-3', 'smartphone',
|
|
62
|
+
'tablet', 'monitor', 'trash-bin-trash', 'alt-arrow-down', 'alt-arrow-right', 'arrow-up', 'arrow-down', 'arrow-left', 'arrow-right', 'sidebar-minimalistic',
|
|
63
|
+
'align-left', 'align-horizontal-center', 'align-right', 'palette', 'checklist-minimalistic', 'letter', 'link', 'phone', 'text-square', 'calculator', 'calendar',
|
|
64
|
+
'list-down', 'record-circle', 'checklist', 'check-square', 'shield-check', 'eye-closed', 'inbox', 'download-minimalistic', 'upload-minimalistic', 'filter',
|
|
65
|
+
'copy', 'pen', 'close-circle', 'sort-vertical', 'alt-arrow-up', 'login-2', 'posts-carousel-horizontal', 'card', 'text-selection', 'database', 'list-arrow-down',
|
|
66
|
+
'link-round', 'hamburger-menu', 'history', 'eye', 'magnifier', 'check-circle', 'restart', 'pen-new-square', 'folder-with-files', 'user', 'users-group-rounded',
|
|
67
|
+
'clock-circle', 'danger-triangle', 'info-circle', 'heart', 'flag', 'pin', 'lightbulb', 'bolt', 'global', 'map', 'crown', 'gift', 'rocket', 'menu-dots', 'cursor', 'add-square',
|
|
68
|
+
// The dashboard shell and its account modules.
|
|
69
|
+
'sun', 'moon', 'logout-3', 'monitor-smartphone', 'user-circle', 'shield-keyhole',
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
/** The names of the hot sprite: the site's and the dashboard's own icons, in one file. */
|
|
73
|
+
export const HOT_ICON_NAMES: readonly string[] = Object.freeze([...new Set([...SITE_ICON_NAMES, ...DASHBOARD_ICON_NAMES])].sort());
|
|
74
|
+
const HOT_ICON_SET: ReadonlySet<string> = new Set(HOT_ICON_NAMES);
|
|
75
|
+
|
|
76
|
+
/** Every icon name of the catalog. */
|
|
77
|
+
export const ICON_NAME_SET: ReadonlySet<string> = new Set(ICON_CATEGORIES.flatMap(category => category.names));
|
|
78
|
+
const CATEGORY_OF: ReadonlyMap<string, string> = new Map(ICON_CATEGORIES.flatMap(category => category.names.map((name): [string, string] => [name, category.id])));
|
|
79
|
+
|
|
80
|
+
export function isIconName(value: unknown): value is string {
|
|
81
|
+
return typeof value === 'string' && ICON_NAME_SET.has(value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The category an icon belongs to, or undefined for a name outside the catalog. */
|
|
85
|
+
export function iconCategoryOf(name: string): string | undefined {
|
|
86
|
+
return CATEGORY_OF.get(name);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The sprite groups: `hot` (the hot set) and one per category. */
|
|
90
|
+
export const ICON_SPRITE_GROUPS: readonly string[] = Object.freeze(['hot', ...ICON_CATEGORIES.map(category => category.id)]);
|
|
91
|
+
|
|
92
|
+
/** The names a sprite group holds, or undefined for an unknown group. */
|
|
93
|
+
export function iconSpriteNames(group: string): readonly string[] | undefined {
|
|
94
|
+
if (group === 'hot') return HOT_ICON_NAMES;
|
|
95
|
+
return ICON_CATEGORIES.find(category => category.id === group)?.names;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The sprite an icon is drawn from: the hot sprite when it is in the hot set, else its category's; undefined outside the catalog. */
|
|
99
|
+
export function iconSpriteGroup(name: string): string | undefined {
|
|
100
|
+
return HOT_ICON_SET.has(name) ? 'hot' : CATEGORY_OF.get(name);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** FNV-1a, 32 bits, as eight hex digits: enough to tell one list from another in a file name. */
|
|
104
|
+
function fingerprint(text: string): string {
|
|
105
|
+
let hash = 0x811c9dc5;
|
|
106
|
+
for (let index = 0; index < text.length; index++) {
|
|
107
|
+
hash ^= text.charCodeAt(index);
|
|
108
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
109
|
+
}
|
|
110
|
+
return hash.toString(16).padStart(8, '0');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The version in every sprite's file name: the icon package's version and the hot set, so a
|
|
115
|
+
* new package or a changed list is a new file (both adapters cache `/assets/*.<hash>.*` for a year).
|
|
116
|
+
*/
|
|
117
|
+
export const ICON_SPRITE_VERSION = `${ICON_SET_VERSION.replace(/[^a-zA-Z0-9]+/g, '')}${fingerprint(`${ICON_SET_VERSION}\n${HOT_ICON_NAMES.join(',')}`)}`;
|
|
118
|
+
|
|
119
|
+
/** Where a sprite is served: `/assets/icons/<style>/<group>.<version>.svg`. */
|
|
120
|
+
export function iconSpriteUrl(style: IconStyleName, group: string): string {
|
|
121
|
+
return `/assets/icons/${style}/${group}.${ICON_SPRITE_VERSION}.svg`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The `<use>` reference of an icon in a style, or undefined for a name outside the catalog. */
|
|
125
|
+
export function iconHref(name: string, style: IconStyleName = DEFAULT_ICON_STYLE): string | undefined {
|
|
126
|
+
const group = iconSpriteGroup(name);
|
|
127
|
+
return group ? `${iconSpriteUrl(style, group)}#${name}` : undefined;
|
|
128
|
+
}
|
package/src/images.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Responsive images: the widths the media route serves, crop and focal point edits, and the
|
|
3
|
+
* URLs and `srcset` of an image. Client-safe; the host's image transformer makes the variants.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Widths variants are made in. Requests for other widths use the next larger one. */
|
|
7
|
+
export const IMAGE_WIDTHS = Object.freeze([320, 640, 960, 1280, 1920, 2560] as const);
|
|
8
|
+
|
|
9
|
+
/** Types the transformer resizes. GIF keeps its animation and SVG scales by itself, so both are served as uploaded. */
|
|
10
|
+
export const TRANSFORMABLE_TYPES = Object.freeze(['image/jpeg', 'image/png', 'image/webp', 'image/avif']);
|
|
11
|
+
|
|
12
|
+
export interface ImageRect {
|
|
13
|
+
readonly x: number;
|
|
14
|
+
readonly y: number;
|
|
15
|
+
readonly width: number;
|
|
16
|
+
readonly height: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Edits of an image: a crop in source pixels, and the point to keep in view when filling a shape (0-1 each way). */
|
|
20
|
+
export interface ImageEdits {
|
|
21
|
+
readonly crop?: ImageRect;
|
|
22
|
+
readonly focus?: { readonly x: number; readonly y: number };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** What an image needs to describe its variants. */
|
|
26
|
+
export interface ImageSource {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly contentType: string;
|
|
30
|
+
readonly width: number | null;
|
|
31
|
+
readonly height: number | null;
|
|
32
|
+
readonly edits?: ImageEdits | null;
|
|
33
|
+
/** Changes when the image's edits change, so cached variants are not reused. */
|
|
34
|
+
readonly version: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Problems with edits for an image of this size; empty when valid. */
|
|
38
|
+
export function imageEditsProblems(edits: ImageEdits, width: number, height: number): string[] {
|
|
39
|
+
const problems: string[] = [];
|
|
40
|
+
if (edits.crop !== undefined) {
|
|
41
|
+
const { x, y, width: w, height: h } = edits.crop;
|
|
42
|
+
if (![x, y, w, h].every(Number.isSafeInteger) || x < 0 || y < 0 || w < 16 || h < 16 || x + w > width || y + h > height) problems.push('The crop must lie inside the image and be at least 16 pixels each way.');
|
|
43
|
+
}
|
|
44
|
+
if (edits.focus !== undefined) {
|
|
45
|
+
const { x, y } = edits.focus;
|
|
46
|
+
if (![x, y].every(value => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1)) problems.push('The focal point is two numbers from 0 to 1.');
|
|
47
|
+
}
|
|
48
|
+
return problems;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The image's size after its crop. */
|
|
52
|
+
export function editedSize(image: Pick<ImageSource, 'width' | 'height' | 'edits'>): { width: number; height: number } | null {
|
|
53
|
+
if (!image.width || !image.height) return null;
|
|
54
|
+
const crop = image.edits?.crop;
|
|
55
|
+
return crop ? { width: crop.width, height: crop.height } : { width: image.width, height: image.height };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The variant width serving `width`: the smallest listed width at least as large, or the largest. */
|
|
59
|
+
export function variantWidth(width: number, widths: readonly number[] = IMAGE_WIDTHS): number {
|
|
60
|
+
return widths.find(entry => entry >= width) ?? widths[widths.length - 1]!;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The part of the (cropped) image a variant shows: all of it, or for a target shape the
|
|
65
|
+
* largest rectangle of that shape around the focal point.
|
|
66
|
+
*/
|
|
67
|
+
export function variantRect(image: Pick<ImageSource, 'width' | 'height' | 'edits'>, aspect?: number): ImageRect | null {
|
|
68
|
+
if (!image.width || !image.height) return null;
|
|
69
|
+
const base = image.edits?.crop ?? { x: 0, y: 0, width: image.width, height: image.height };
|
|
70
|
+
if (!aspect || !Number.isFinite(aspect) || aspect <= 0) return base;
|
|
71
|
+
const focus = image.edits?.focus ?? { x: 0.5, y: 0.5 };
|
|
72
|
+
let width = base.width;
|
|
73
|
+
let height = Math.round(width / aspect);
|
|
74
|
+
if (height > base.height) { height = base.height; width = Math.round(height * aspect); }
|
|
75
|
+
const centre = (start: number, size: number, part: number, at: number) => Math.min(Math.max(Math.round(start + size * at - part / 2), start), start + size - part);
|
|
76
|
+
return { x: centre(base.x, base.width, width, focus.x), y: centre(base.y, base.height, height, focus.y), width, height };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Whether variants can be made of this file. */
|
|
80
|
+
export function transformable(contentType: string): boolean {
|
|
81
|
+
return TRANSFORMABLE_TYPES.includes(contentType);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The URL of a variant: `/media/<id>/<name>?w=640&v=<version>`, with `h` for a fixed shape. */
|
|
85
|
+
export function imageUrl(image: ImageSource, options: { width: number; height?: number }): string {
|
|
86
|
+
const params = new URLSearchParams({ w: String(variantWidth(options.width)) });
|
|
87
|
+
if (options.height) params.set('h', String(Math.max(1, Math.round(options.height * variantWidth(options.width) / options.width))));
|
|
88
|
+
params.set('v', String(image.version));
|
|
89
|
+
return `/media/${image.id}/${encodeURIComponent(image.name)}?${params}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A `srcset` of the image's variants up to its own width, or empty when it cannot be resized.
|
|
94
|
+
* With `aspect`, every variant has that shape around the focal point. `widths` are the site's
|
|
95
|
+
* (Settings → Files), `IMAGE_WIDTHS` by default.
|
|
96
|
+
*/
|
|
97
|
+
export function imageSrcset(image: ImageSource, options: { aspect?: number; widths?: readonly number[] } = {}): string {
|
|
98
|
+
const size = editedSize(image);
|
|
99
|
+
if (!size || !transformable(image.contentType)) return '';
|
|
100
|
+
const listed = options.widths?.length ? options.widths : IMAGE_WIDTHS;
|
|
101
|
+
// Each listed width below the image's own, then the image at full size.
|
|
102
|
+
const widths: number[] = listed.filter(width => width < size.width);
|
|
103
|
+
widths.push(Math.min(size.width, listed[listed.length - 1]!));
|
|
104
|
+
return [...new Set(widths.map(width => variantWidth(width, listed)))].map(width => `${imageUrl(image, { width, ...(options.aspect ? { height: Math.round(width / options.aspect) } : {}) })} ${Math.min(width, size.width)}w`).join(', ');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A `srcset` with every variant cut to `aspect` (16 / 9 by default) around the focal point, for
|
|
109
|
+
* cards and headers: the same variants with a height each. Empty for an empty `srcset`.
|
|
110
|
+
*/
|
|
111
|
+
export function wideSrcset(srcset: string, aspect = 16 / 9): string {
|
|
112
|
+
return srcset.split(',').map(candidate => candidate.trim()).filter(Boolean).map(candidate => {
|
|
113
|
+
const [url = '', size = ''] = candidate.split(/\s+/);
|
|
114
|
+
const width = Number(/[?&]w=(\d+)/.exec(url)?.[1]);
|
|
115
|
+
if (!width) return candidate;
|
|
116
|
+
return `${url.replace(/([?&]w=\d+)/, `$1&h=${Math.max(1, Math.round(width / aspect))}`)} ${size}`.trim();
|
|
117
|
+
}).join(', ');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The widths of Settings → Files, sorted and without repeats; `IMAGE_WIDTHS` when the text names none. */
|
|
121
|
+
export function imageWidths(text: string | undefined): readonly number[] {
|
|
122
|
+
const widths = [...new Set((text ?? '').split(',').map(part => Number(part.trim())).filter(width => Number.isSafeInteger(width) && width >= 16 && width <= 8192))].sort((a, b) => a - b).slice(0, 12);
|
|
123
|
+
return widths.length ? widths : IMAGE_WIDTHS;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A CSS `background-image` that blurs a tiny placeholder up to the image's shape: an SVG with a
|
|
128
|
+
* Gaussian blur over the `data:` URL, so the edges stay sharp and no pixels show.
|
|
129
|
+
*/
|
|
130
|
+
export function blurredPlaceholder(placeholder: string, width: number | null, height: number | null): string {
|
|
131
|
+
const w = width && width > 0 ? width : 16;
|
|
132
|
+
const h = height && height > 0 ? height : 9;
|
|
133
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${w} ${h}'><filter id='b' color-interpolation-filters='sRGB'><feGaussianBlur stdDeviation='${Math.max(w, h) / 40}'/><feComponentTransfer><feFuncA type='discrete' tableValues='1 1'/></feComponentTransfer></filter><image width='100%' height='100%' preserveAspectRatio='none' filter='url(#b)' href='${placeholder}'/></svg>`;
|
|
134
|
+
// Only what an unquoted `url()` and an HTML attribute cannot hold is escaped: the page carries one of these per image.
|
|
135
|
+
return `url(data:image/svg+xml,${svg.replace(/[%#<>'"()\\\s]/g, character => `%${character.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0')}`)})`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The inline style that shows a placeholder blurred behind an image while it loads; empty without one. */
|
|
139
|
+
export function placeholderStyle(placeholder: string | null | undefined, width: number | null, height: number | null): string {
|
|
140
|
+
return placeholder ? `background-image:${blurredPlaceholder(placeholder, width, height)};background-size:cover;background-repeat:no-repeat` : '';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A script for the site's head that drops an image's blurred placeholder once the image has
|
|
145
|
+
* loaded, so it never shows through transparent pixels or around an image that does not fill
|
|
146
|
+
* its box. Image `load` events do not bubble, so it listens in the capture phase, before any
|
|
147
|
+
* image in the document loads.
|
|
148
|
+
*/
|
|
149
|
+
export const PLACEHOLDER_SCRIPT = "addEventListener('load',function(e){var t=e.target;if(t&&t.tagName==='IMG'&&t.style.backgroundImage)t.style.backgroundImage=''},true)";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Client-safe CMS declarations: resources, fields, permissions, extension points and records.
|
|
2
|
+
export { defineResource, resolveResource, resourceProblems, storageName, permissionFor, declarationHash, canonicalJson, SYSTEM_FIELDS, RESOURCE_NAME, OWNER_NAME, ResourceDeclarationError,
|
|
3
|
+
type ResourceDeclaration, type Resource, type ResourceAccess, type ResourceAction, type AccessRule, type IndexDeclaration, type MigrationStep } from './resource';
|
|
4
|
+
export { field, fieldProblems, validateValue, storageType, storageCheck, slugify, FIELD_NAME, SLUG_PATTERN, TAXONOMY_NAME, ROW_ID, ROW_LIMITS, ITEM_LIMITS, MULTIPLE_KINDS, FIELD_MEDIA_KINDS, CHOICE_SOURCES, type FieldMediaKind, type ChoiceSource, type FieldDeclaration, type FieldKind, type ListItemKind } from './fields';
|
|
5
|
+
export {
|
|
6
|
+
FIELD_BLOCK_TYPES, FIELD_BLOCKS, FIELD_GROUP_ID, FIELD_GROUP_LIMITS, fieldBlockFields, fieldBlockDeclaration, rowsSearchable, metaProblems, SYSTEM_META, flattenGroupFields, fieldGroupDeclarations, fieldBlockKindOf, fieldBlockOf, layoutOf, sameTarget, targetOrder, groupsForTarget, withTarget, fieldGroupProblems,
|
|
7
|
+
withRowIds, indexedRowPaths, indexedRowField, rowIndexPath, rowsPlain, rowUniqueProblem, conditionValues, hiddenKey, fieldVisibility, clearHidden,
|
|
8
|
+
type FieldGroup, type FieldGroupTarget, type Row,
|
|
9
|
+
} from './field-groups';
|
|
10
|
+
export { ANONYMOUS, PERMISSIONS, DEFAULT_ROLES, NETWORK_ADMIN, MAIN_SITE, isNetworkAdmin, systemPrincipal, userPrincipal, hasPermission, holdsAll, permissionMatches, evaluateRule, ruleScope, principalId, type Principal, type RecordScope } from './permissions';
|
|
11
|
+
export { CmsError, isCmsError, type CmsErrorCode } from './errors';
|
|
12
|
+
export { CMS_VERSION } from './version';
|
|
13
|
+
export { checkForUpdate, compareVersions, parseUpdateAnswer, updateCheckUrl, DEFAULT_UPDATES_URL, DEFAULT_UPDATES_CHANNEL, type UpdatesOptions, type UpdateAnswer, type UpdateCheck } from './updates';
|
|
14
|
+
export { beforeWrite, afterCommit, cachePurge, pluginJob, paymentEvent, formValidate, formBeforeSubmit, formPrefill, formConfirmation, formNotification, formSubmitted, termBeforeSave, commentBeforeSave, menuBeforeSave, entryActions, entryColumns, bulkActions, ENTRY_ACTION_IDS, EXTENSION_POINTS,
|
|
15
|
+
dashboardNotices, dashboardTaskbar, siteMarkdown, dashboardNoticesOf, taskbarItemsOf,
|
|
16
|
+
type BeforeWriteInput, type Draft, type ResourceEvent, type CachePurgeEvent, type PluginJobEvent, type PaymentEvent, type WriteActor, type FormRef, type SubmissionContext, type FormErrors, type FormConfirmation, type FormEmail, type FormSubmittedEvent,
|
|
17
|
+
type TermDraft, type TermWriteInput, type CommentDraft, type CommentWriteInput, type MenuWriteInput, type EntryAction, type BuiltinEntryAction, type EntryColumn, type EntryListInput,
|
|
18
|
+
type DashboardNotice, type TaskbarItem } from './hooks';
|
|
19
|
+
export { siteEntryView, ENTRY_VIEW_REFUSED_BLOCKS, type EntryViewParts } from './hooks';
|
|
20
|
+
export { userBeforeRegister, userRegistered, userSignedIn, registrationDraftOf, type RegistrationDraft, type UserRef, type UserRegisteredEvent, type UserSignedInEvent } from './hooks';
|
|
21
|
+
export { mailBeforeSend, mailMessageOf, mailRecipientsLocked, MAIL_KINDS, MAIL_LIMITS, type MailKind, type MailMessage, type MailSendInput } from './hooks';
|
|
22
|
+
export { mailHtml, mailBodyHtml, MAIL_ACCENT, type MailLayout } from './mail';
|
|
23
|
+
export type { RecordShape, RecordPage, RevisionShape, FieldFilter, ListFilter, ListOptions } from './records';
|
|
24
|
+
export { contentModule, categories, tags, patterns } from './modules/content';
|
|
25
|
+
export { formsModule } from './modules/forms';
|
|
26
|
+
export {
|
|
27
|
+
FORM_BLOCKS, FORM_EMBED_BLOCK, FORM_SETTINGS, FORM_ROW_LIMIT, FORM_ITEM_LIMIT, FORM_FILE_LIMIT, FORM_FILE_MAX_MB, FORM_UPLOAD_LIMIT_MB, MULTIPLE_INPUT_KINDS, formFiles, acceptList, acceptsFile, type FormFile, TEMPLATE_ROW, SUBMISSION_STATUSES, SUBMISSION_META, SUBMISSION_PREFIX, NOTIFICATION_LIMIT, MERGE_TAGS,
|
|
28
|
+
forms, inputFields, choiceOptions, formInputs, flatFormInputs, isRows, rowValues, inputHtmlName, inputKey, ruleMatches, conditionShows, formVisibility, visibleBlocks, formDataValues, validateSubmission, displayValue, displayRows,
|
|
29
|
+
formSettings, submissionResourceName, submissionResource, submissionOf, notificationRules, notificationProblems, renderMergeTags, escapeMarkdown, emailAddresses,
|
|
30
|
+
type ChoiceOption, type FormField, type FormValue, type FormValues, type FormRow, type PostedValue, type SubmittedValues, type SubmissionCheck, type FormSettings, type SubmissionStatus,
|
|
31
|
+
type SubmissionMeta, type SubmissionShape, type NotificationRule, type MergeContext,
|
|
32
|
+
} from './form-builder';
|
|
33
|
+
export {
|
|
34
|
+
EDITOR_BOX, EDITOR_OWN_BOXES, EDITOR_LAYOUT_BLOCKS, EDITOR_LAYOUT_CORE, EDITOR_LAYOUT_INSIDE, EDITOR_LAYOUT_TYPES, EDITOR_LAYOUT_LIMITS, EDIT_TAB, EDITOR_TAB_ID, EDITOR_TAB_RESERVED,
|
|
35
|
+
fieldPlacement, editorBoxes, editorLayoutTypes, editorTabId, boxBlock, layoutBoxes, defaultEditorLayout, editorLayoutShapeProblem, editorLayoutProblems, resolveEditorLayout, boxFields,
|
|
36
|
+
type EditorBox, type EditorBoxesInput, type EditorLayout, type EditorLayoutAddition, type ResolvedEditorLayout,
|
|
37
|
+
} from './editor-layout';
|
|
38
|
+
export { CONTENT_STATUSES, CORE_FIELDS, ENTRY_TEMPLATE, entryAuthors, FEATURE_FIELDS, RESERVED_FIELDS, LOCALE, SEO_FIELDS, collectionProblems, collectionResource, contentBlocks, entryUrl, extendCollection, languageFlag, languageName, orderedFields, posts, pages, translationGroupOf, type CollectionDefinition, type CollectionFeatures, type ContentStatus } from './collections';
|
|
39
|
+
export { CORE_BLOCKS, BLOCK_CATEGORIES, BLOCK_ID, BLOCK_NAME, BLOCK_LIMITS, CUSTOM_COLOR, MEDIA_ID, BACKGROUND_SIZES, FIELD_BLOCK_KINDS, FIELD_GROUP_LAYOUT, FIELD_GROUP_LIMIT, RESERVED_FIELD_NAMES, BREAKPOINTS, STYLE_PROPERTIES, TEXT_ALIGNMENTS, PRESET_SLUG, INPUT_KINDS, INPUT_NAME, CONDITION_OPERATORS, CONDITION_LIMIT, FORM_INPUT_LIMIT, RESERVED_INPUT_NAMES,
|
|
40
|
+
blockCategory, blockIdProblem, blockIsData, blockProblems, blocksShapeProblem, blockLayoutProblem, blockStyleProblem, styleValueProblem, blockConditionProblem, blockSupports, blockAllowedIn, validateBlocks, textFieldProblem, blockMedia, blockDocuments, blocksPlain, cloneBlocks, blockId, inputName,
|
|
41
|
+
flattenBlocks, placeBlocks, findBlock, HTML_BLOCK, htmlBlocks, htmlBlocksChanged, updateBlock, removeBlock, insertBlock, moveBlock, shiftBlock, blockTreeProblem,
|
|
42
|
+
type Block, type BlockCategory, type BlockDeclaration, type BlockLayout, type BlockStyle, type BlockSupports, type BlockMove, type BlockPlace, type Breakpoint, type StyleProperty,
|
|
43
|
+
type BlockCondition, type ConditionRule, type ConditionOperator, type InputKind, type FieldBlockKind, type ValidateBlocksOptions, EMBED_URL } from './blocks';
|
|
44
|
+
export { hasBinding, bindingPaths, bindingRefs, bindingValue, bindingText, bindingProblem, usesUserBinding, resolveBindings, resolveBlockBindings, withBinding, siteBindingScope, BINDING_SCOPES, type BindingScope, type BindingScopes } from './bindings';
|
|
45
|
+
export { parseBlockText, hasBlockReference, textBlocks, PATTERN_REFERENCE, type TextPart, type ParsedText } from './block-references';
|
|
46
|
+
export { formInput, formValue, recordTitle, isSameOriginPost, type FormInput, type SubmittedForm } from './forms';
|
|
47
|
+
export { manifestProblems, validateManifest, RESERVED_PLUGIN_NAMES, RESERVED_PLUGIN_PREFIX, requestedGrants, commandInput, isPluginPoint, pointOwner, providedPoints, ManifestError, HOST_SLOTS, CAPABILITIES, UNRESTRICTED_GRANT, type Capability, type UserAction, type PluginSchedule, type CmsPluginManifest, type PluginAuthor, type ProvidedPoint, type PluginCommand, type CommandOption, type SlotLink, type HostSlot } from './manifest';
|
|
48
|
+
export { MEDIA_TYPES, AVATAR_TYPES, ARCHIVE_TYPES, SVG_TYPE, MEDIA_FILTERS, MEDIA_FILTER_EXCLUDES, mediaKind, mediaUrl, formatBytes, matchesSignature, imageHasAlpha, imageSize, declaredType, sanitizeSvg, EXTENSION_TYPES, fileExtension, fileType, type MediaKind } from './media';
|
|
49
|
+
export { taxonomyProblems, type TaxonomyDeclaration, type TermShape } from './taxonomy';
|
|
50
|
+
export { general, interfaceGroup, DASHBOARD_PALETTES, DASHBOARD_ACCENTS, type DashboardPalette, type DashboardAccent, media, appearance, dashboard, writing, reading, discussion, seo, crawlers, indexnow, cache, languages, DATE_FORMATS, TIME_FORMATS, TITLE_SEPARATORS, formatSiteDate, validTimeZone, type SettingsGroup, type SettingsSection, type SettingDeclaration, type SettingSource, type SettingControl, type SiteSettings } from './settings';
|
|
51
|
+
export { validateSettingValue, settingControlProblems } from './settings-controls';
|
|
52
|
+
export { pluginSettingsProblems, pluginSettingsGroupId, PLUGIN_SETTINGS_LIMITS, type PluginSettingsDeclaration, type PluginSettingDeclaration } from './plugin-settings';
|
|
53
|
+
export { parseSettingsDocument, checkSettingsDocument, stringifySettingsDocument, settingsJsonSchema, isPortableSetting, SETTINGS_DOCUMENT_MAX_BYTES, SETTINGS_DOCUMENT_MAX_FIELDS, type SettingsValue, type SettingsDocument } from './settings-document';
|
|
54
|
+
export type { CmsModule, ModuleContext } from './module';
|
|
55
|
+
export {
|
|
56
|
+
MENU_LIMITS, MENU_LOCATION, MENU_ATTRIBUTE, menuProblems, normalizeMenu, menuSize, menuItemId, flattenMenu, buildMenu, subtreeEnd, dropDepths, moveRows, shiftRows, allowedMoves,
|
|
57
|
+
type MenuItem, type MenuItemKind, type MenuShape, type MenuItemView, type ResolvedMenuItem, type MenuRow, type MenuMove,
|
|
58
|
+
} from './menus';
|
|
59
|
+
export {
|
|
60
|
+
RICH_TEXT_LIMITS, RICH_TEXT_NODES, RICH_TEXT_MARKS, checkRichText, richTextProblem, normalizeRichText, emptyRichText, richTextFromPlain, richTextEmpty, richTextPlain, richTextExcerpt, richTextBlocks, richTextMedia,
|
|
61
|
+
richTextParts, richTextHtml, withRichTextBlocks, escapeHtml, safeLinkUrl, safeImageUrl,
|
|
62
|
+
type RichTextDoc, type RichTextNode, type RichTextMark, type EmbeddedBlock, type ContentPart, type RichTextRenderOptions, type RichTextMediaInfo,
|
|
63
|
+
} from './richtext';
|
|
64
|
+
export {
|
|
65
|
+
themeProblems, siteThemeProblems, assembleSiteTheme, layerSiteThemes, entryTemplate, withContentFields, archiveTemplate, entryTemplateChoices, templateCandidates, pickTemplate, SPECIFIC_TEMPLATE,
|
|
66
|
+
PRESET_KINDS, DEFAULT_PRESETS, GRADIENT_VALUE, LANGUAGE_SWITCHER_STYLES, presetProblems, layerPresets, resolvePresets, presetOverridesProblem, presetStyle, blockStyleAttributes, backgroundImageUrl, customCssProblem,
|
|
67
|
+
type Preset, type PresetKind, type ThemePresets, type PresetOverrides, type BlockStyleAttributes,
|
|
68
|
+
type ThemeManifest, type ThemeAreaManifest, themeArea, type SiteTheme, type ThemeSource, type EntryTemplate, type ArchiveTemplate, type BlockRenderer, type SiteBasics, type ThemeContext, type LayoutContext, type HeadContext, type EntryContext, type ArchiveContext, type LockedContext, type MembersContext, type BlockContext, type TemplatePage, type ThemeData, type FieldView, type EntryReference, type ThemeHelpers, type SiteView, type EntryView, type ArchiveView, type AuthorView, type RenderedBlock, type RepeaterView, type ItemsView, type BodyPart, type MediaView, type TermLink, type Paging,
|
|
69
|
+
type EntryAuthor, type CommentView, type CommentsView, type CommentFormView, type LanguageLink, type LanguageSwitcherOptions, type MenuOptions, type MenuStyle, type MenuMotion, type SearchOptions, type LanguageSwitcherStyle, type FormView, type InputView,
|
|
70
|
+
} from './theme';
|
|
71
|
+
export type { BrandIcon, BreadcrumbView, HeadingView } from './theme';
|
|
72
|
+
export { SHARE_NETWORKS, SHARE_BRAND_URLS, type ShareNetwork, type BlockVariation } from './blocks';
|
|
73
|
+
export type { PluginHead, PluginHeadContext } from './theme';
|
|
74
|
+
export { ICON_NAME, SITE_ICON_NAMES, DASHBOARD_ICON_NAMES, HOT_ICON_NAMES, ICON_NAME_SET, ICON_CATEGORIES, ICON_SET_VERSION, ICON_STYLES, ICON_STYLE_LABELS, DEFAULT_ICON_STYLE, ICON_SPRITE_GROUPS, ICON_SPRITE_VERSION, isIconStyle, isIconName, iconCategoryOf, iconSpriteNames, iconSpriteGroup, iconSpriteUrl, iconHref, type IconCategory, type IconStyleName } from './icons';
|
|
75
|
+
export { MAP_EMBED_URL } from './blocks';
|
|
76
|
+
export { diffWords, compareRecords, comparableValue, type DiffPart, type FieldChange } from './diff';
|
|
77
|
+
export {
|
|
78
|
+
SCHEMA_TYPES, SCHEMA_TYPE_LABELS, SCHEMA_PROPERTIES, ARTICLE_TYPES, SEO_TEMPLATE_VARIABLES, SEO_TEMPLATE_DEFAULTS, AUTHOR_FIELDS,
|
|
79
|
+
collectionSeoProblems, renderSeoTemplate, robotsDirectives, authorUrl, urlList, schemaGraph, schemaProperties,
|
|
80
|
+
CRAWLER_GROUPS, blockedCrawlerGroups, robotsTxtLines, crawlerOf, type CrawlerGroup, type CrawlerSettings,
|
|
81
|
+
type SchemaType, type SchemaProperty, type CollectionSchema, type CollectionRobots, type CollectionSeoTemplates, type SeoTemplateVariable, type ImagePreview, type RobotsOptions,
|
|
82
|
+
type SchemaImage, type SchemaSite, type SchemaAuthor, type SchemaBreadcrumb, type SchemaPage,
|
|
83
|
+
} from './seo';
|
|
84
|
+
export { richTextMarkdown, blocksMarkdown, entryMarkdown, type EntryMarkdownInput, type MarkdownOptions } from './to-markdown';
|
|
85
|
+
export { entryChecks, analyzeContent, blockLinks, richTextLinks, markdownLinks, internalLinkPath, type Check, type CheckStatus, type CheckInput } from './checks';
|
|
86
|
+
export { recordSchema, fieldSchema, type JsonSchema } from './schema-json';
|
|
87
|
+
export { REDIRECT_STATUSES, REDIRECT_PATH, redirectPath, redirectProblems, type Redirect, type RedirectInput, type RedirectStatus } from './redirects';
|
|
88
|
+
export { WEBHOOK_EVENTS, webhookUrlProblem, type Webhook, type WebhookDelivery, type WebhookEvent, type WebhookInput, type WebhookPayload } from './webhooks';
|
|
89
|
+
export { COMMENT_STATUSES, checkComment, type CommentShape, type CommentRow, type CommentStatus } from './comments';
|
|
90
|
+
export { IMAGE_WIDTHS, PLACEHOLDER_SCRIPT, TRANSFORMABLE_TYPES, blurredPlaceholder, wideSrcset, imageWidths, placeholderStyle, imageEditsProblems, editedSize, variantWidth, variantRect, transformable, imageUrl, imageSrcset, type ImageEdits, type ImageRect, type ImageSource } from './images';
|
|
91
|
+
export { COLLAB_COLORS, PRESENCE_TIMEOUT, participantColor, livePeers, expiredPeers, groupPeers, checkPresence, PendingKeys, scalarKey, patchKey, richTextPath, parseRichTextPath, stableJson, treeOps, applyTreeOp, treeHash, StepLog, type PeerPresence, type PeerState, type Participant, type TreeOp, type TreeOpsOptions } from './collab';
|
|
92
|
+
export { NOTE_STATUSES, NOTE_LIMITS, formatNoteTarget, parseNoteTarget, noteBlock, noteField, checkNoteBody, checkNoteRange, checkNoteQuote, checkNoteAction, mentionsIn, noteParts, notePlainText, noteMail, mentionToken, noteThreads, findQuote, type Note, type NoteAction, type NoteRange, type NoteStatus, type NoteTarget, type NoteThread } from './notes';
|
|
93
|
+
|
|
94
|
+
export { CACHE_HOLDS, cacheControl, cacheHoldSeconds, cacheTags, cacheTagHeader, type CacheHold } from './cache';
|
|
95
|
+
export { parseCron, nextCronTime, cronProblem, type CronFields } from './cron';
|
|
96
|
+
export { highlightCode, highlightLanguage, HIGHLIGHT_LANGUAGES, type TokenClass } from './highlight';
|
|
97
|
+
export { searchQuery, searchWords, isSearchSyntaxError, SEARCH_LIMITS, type SearchQuery, type SnippetPart } from './search';
|
|
98
|
+
export { AUTOMATION_EVENTS, AUTOMATION_EVENT_LABELS, automationProblems, automationMatches, renderAutomationTemplate, type Automation, type AutomationAction, type AutomationConditions, type AutomationEvent, type AutomationInput } from './automations';
|
|
99
|
+
export { ISOLATE_PROTOCOL, ISOLATE_MEMBERS, type IsolateCall, type IsolateRun, type IsolatePoint, type IsolateMember, type IsolateBridge, type IsolateEntrypoint } from './isolation';
|
|
100
|
+
export { applyDashboardMenu, dashboardLinkHrefProblem, dashboardLinkModuleId, dashboardMenuOf, dashboardMenuProblems, DASHBOARD_MENU_LIMITS, EMPTY_DASHBOARD_MENU, type DashboardMenu, type DashboardMenuLink } from './dashboard-menu';
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin side of an isolated plugin, without platform imports so Node can test it:
|
|
3
|
+
* `isolate.ts` wraps it in a `WorkerEntrypoint` with `AsyncLocalStorage`.
|
|
4
|
+
*
|
|
5
|
+
* `register()` runs once per site in each isolate, under that site's call, and gets a context
|
|
6
|
+
* shaped like the one plugins get in the application. Its members forward to the bridge of
|
|
7
|
+
* the call in progress, so a handler that captured `context` at registration reaches the host
|
|
8
|
+
* of whichever call runs it.
|
|
9
|
+
*/
|
|
10
|
+
import { createHookRegistry, HookError, type ExtensionPoint, type HookRegistry } from '@cossackframework/core/hooks';
|
|
11
|
+
import type { CmsPluginManifest } from './manifest';
|
|
12
|
+
import { mediaUrl } from './media';
|
|
13
|
+
import type { Principal } from './permissions';
|
|
14
|
+
import { ISOLATE_PROTOCOL, type IsolateBridge, type IsolateCall, type IsolateMember, type IsolatePoint } from './isolation';
|
|
15
|
+
import type { CommandHandler, PluginContext } from './server/host';
|
|
16
|
+
import type { PluginJobHandler } from './server/capabilities';
|
|
17
|
+
|
|
18
|
+
/** The call in progress; `AsyncLocalStorage` in the isolate. */
|
|
19
|
+
export interface CallScope<T> {
|
|
20
|
+
run<R>(store: T, fn: () => R): R;
|
|
21
|
+
getStore(): T | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CurrentCall {
|
|
25
|
+
readonly bridge: IsolateBridge;
|
|
26
|
+
readonly call: IsolateCall;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SiteRegistrations {
|
|
30
|
+
readonly hooks: HookRegistry;
|
|
31
|
+
readonly points: ReadonlyMap<string, ExtensionPoint>;
|
|
32
|
+
readonly commands: ReadonlyMap<string, CommandHandler>;
|
|
33
|
+
readonly jobs: ReadonlyMap<string, PluginJobHandler>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IsolateRuntime {
|
|
37
|
+
run(call: IsolateCall, bridge: IsolateBridge): Promise<unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** As the host's `JOB_NAME`. */
|
|
41
|
+
const JOB_NAME = /^[a-z][a-z0-9-]{0,40}$/;
|
|
42
|
+
|
|
43
|
+
/** An error that keeps its code across the boundary, like the host's `CmsError`. */
|
|
44
|
+
function failure(code: string, message: string): Error {
|
|
45
|
+
return Object.assign(new Error(message), { code });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createIsolateRuntime(plugin: Readonly<Record<string, unknown>>, manifest: CmsPluginManifest, scope: CallScope<CurrentCall>): IsolateRuntime {
|
|
49
|
+
const name = manifest.name;
|
|
50
|
+
const sites = new Map<string, Promise<SiteRegistrations>>();
|
|
51
|
+
const declared = new Set((manifest.hooks ?? []).map(hook => hook.point));
|
|
52
|
+
const provided = new Set((manifest.provides ?? []).map(point => point.point));
|
|
53
|
+
const declaredCommands = new Set((manifest.commands ?? []).map(command => command.name));
|
|
54
|
+
|
|
55
|
+
const current = (): CurrentCall => {
|
|
56
|
+
const store = scope.getStore();
|
|
57
|
+
if (!store) throw new Error(`Plugin ${name} used its context outside a call from the host.`);
|
|
58
|
+
return store;
|
|
59
|
+
};
|
|
60
|
+
const forward = (member: IsolateMember, ...args: unknown[]): Promise<unknown> => current().bridge.call(member, args);
|
|
61
|
+
|
|
62
|
+
async function registerFor(call: IsolateCall): Promise<SiteRegistrations> {
|
|
63
|
+
const hooks = createHookRegistry();
|
|
64
|
+
const points = new Map<string, ExtensionPoint>(call.points.map((point: IsolatePoint) => [point.name, Object.freeze({ ...point })]));
|
|
65
|
+
const commands = new Map<string, CommandHandler>();
|
|
66
|
+
const jobs = new Map<string, PluginJobHandler>();
|
|
67
|
+
const checkHook = (point: ExtensionPoint) => {
|
|
68
|
+
if (!declared.has(point.name)) throw new Error(`Plugin ${name} registers ${point.name}, which its manifest does not declare in hooks.`);
|
|
69
|
+
const known = points.get(point.name);
|
|
70
|
+
if (known && (known.kind !== point.kind || known.version !== point.version)) throw new Error(`Plugin ${name} registers ${point.name} as a version ${point.version} ${point.kind}; the host has a version ${known.version} ${known.kind}.`);
|
|
71
|
+
};
|
|
72
|
+
const checkProvided = (point: ExtensionPoint) => {
|
|
73
|
+
if (!provided.has(point.name)) throw new Error(`Plugin ${name} invokes ${point.name}, which its manifest does not declare in provides.`);
|
|
74
|
+
};
|
|
75
|
+
// Signals cannot cross; the host keeps its own deadline.
|
|
76
|
+
const withoutSignal = (options: unknown) => {
|
|
77
|
+
if (!options || typeof options !== 'object') return options;
|
|
78
|
+
const { signal: _signal, ...rest } = options as { signal?: unknown };
|
|
79
|
+
return rest;
|
|
80
|
+
};
|
|
81
|
+
// As in the application: a resource the plugin neither owns nor asks for fails at once.
|
|
82
|
+
const own = (id: string) => call.resources.includes(id) || (manifest.collections ?? []).some(collection => `cms/${collection.name}` === id)
|
|
83
|
+
|| Object.hasOwn(manifest.permissions?.resources ?? {}, id);
|
|
84
|
+
const resource = (id: string) => {
|
|
85
|
+
if (!own(id)) throw failure('CMS_FORBIDDEN', `Plugin ${name} has no grant for ${id}.`);
|
|
86
|
+
const at = (method: string, ...args: unknown[]) => forward(`resource.${method}` as IsolateMember, id, ...args.map(withoutSignal));
|
|
87
|
+
return {
|
|
88
|
+
get: (key: unknown, context: unknown) => at('get', key, context),
|
|
89
|
+
list: (options: unknown, context: unknown) => at('list', options, context),
|
|
90
|
+
count: (filter: unknown, context: unknown) => at('count', filter, context),
|
|
91
|
+
search: (query: unknown, options: unknown, context: unknown) => at('search', query, options, context),
|
|
92
|
+
create: (input: unknown, context: unknown) => at('create', input, context),
|
|
93
|
+
update: (key: unknown, patch: unknown, context: unknown) => at('update', key, patch, context),
|
|
94
|
+
delete: (key: unknown, context: unknown) => at('delete', key, context),
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const context = {
|
|
98
|
+
name,
|
|
99
|
+
version: manifest.version,
|
|
100
|
+
resources: call.resources,
|
|
101
|
+
hooks: {
|
|
102
|
+
addAction: (point: ExtensionPoint, handler: (payload: unknown, context: unknown) => unknown, options: { priority?: number } = {}) => {
|
|
103
|
+
checkHook(point);
|
|
104
|
+
hooks.addAction(point as never, handler as never, { ...options, plugin: name });
|
|
105
|
+
},
|
|
106
|
+
addFilter: (point: ExtensionPoint, handler: (value: unknown, context: unknown) => unknown, options: { priority?: number } = {}) => {
|
|
107
|
+
checkHook(point);
|
|
108
|
+
hooks.addFilter(point as never, handler as never, { ...options, plugin: name });
|
|
109
|
+
},
|
|
110
|
+
point: (pointName: string, kind: 'action' | 'filter') => {
|
|
111
|
+
const known = points.get(pointName);
|
|
112
|
+
if (!known) throw new Error(`Plugin ${name} asks for ${pointName}, which its manifest does not declare in hooks or provides.`);
|
|
113
|
+
if (known.kind !== kind) throw new Error(`${pointName} is ${known.kind === 'action' ? 'an action' : 'a filter'}, not ${kind === 'action' ? 'an action' : 'a filter'}.`);
|
|
114
|
+
return known;
|
|
115
|
+
},
|
|
116
|
+
doAction: (point: ExtensionPoint, payload: unknown, options?: unknown) => { checkProvided(point); return forward('hooks.doAction', point.name, payload, withoutSignal(options)); },
|
|
117
|
+
applyFilters: (point: ExtensionPoint, value: unknown, input: unknown, options?: unknown) => { checkProvided(point); return forward('hooks.applyFilters', point.name, value, input, withoutSignal(options)); },
|
|
118
|
+
},
|
|
119
|
+
commands: {
|
|
120
|
+
add: (command: string, handler: CommandHandler) => {
|
|
121
|
+
if (!declaredCommands.has(command)) throw new Error(`Plugin ${name} adds command ${command}, which its manifest does not declare.`);
|
|
122
|
+
commands.set(command, handler);
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
cms: { resource },
|
|
126
|
+
settings: {
|
|
127
|
+
get: (field: string) => forward('settings.get', field),
|
|
128
|
+
all: () => forward('settings.all'),
|
|
129
|
+
},
|
|
130
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => forward('fetch', new Request(input, init)),
|
|
131
|
+
files: {
|
|
132
|
+
upload: (file: unknown) => forward('files.upload', file),
|
|
133
|
+
get: (id: string) => forward('files.get', id),
|
|
134
|
+
list: (options?: unknown) => forward('files.list', options),
|
|
135
|
+
open: (id: string) => forward('files.open', id),
|
|
136
|
+
update: (id: string, patch: unknown) => forward('files.update', id, patch),
|
|
137
|
+
delete: (id: string) => forward('files.delete', id),
|
|
138
|
+
url: (file: { readonly id: string; readonly name: string }) => mediaUrl(file),
|
|
139
|
+
},
|
|
140
|
+
mail: { send: (message: unknown) => forward('mail.send', message) },
|
|
141
|
+
jobs: {
|
|
142
|
+
handle: (jobName: string, handler: PluginJobHandler) => {
|
|
143
|
+
if (typeof jobName !== 'string' || !JOB_NAME.test(jobName)) throw new Error(`Plugin ${name} names job ${String(jobName)}; job names are lowercase letters, digits and hyphens.`);
|
|
144
|
+
if (typeof handler !== 'function') throw new Error(`Plugin ${name} handles job ${jobName} without a function.`);
|
|
145
|
+
if (jobs.has(jobName)) throw new Error(`Plugin ${name} handles job ${jobName} twice.`);
|
|
146
|
+
jobs.set(jobName, handler);
|
|
147
|
+
},
|
|
148
|
+
enqueue: async (jobName: string, payload?: unknown, options?: unknown) => {
|
|
149
|
+
if (typeof jobName !== 'string' || !jobs.has(jobName)) throw failure('CMS_NOT_FOUND', `Plugin ${name} has no handler for job ${String(jobName)}.`);
|
|
150
|
+
return forward('jobs.enqueue', jobName, payload ?? null, options ?? {});
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
users: {
|
|
154
|
+
get: (id: string) => forward('users.get', id),
|
|
155
|
+
findByEmail: (email: string) => forward('users.findByEmail', email),
|
|
156
|
+
list: (options?: unknown) => forward('users.list', options),
|
|
157
|
+
create: (input: unknown) => forward('users.create', input),
|
|
158
|
+
setMeta: (id: string, value: unknown) => forward('users.setMeta', id, value),
|
|
159
|
+
},
|
|
160
|
+
cache: {
|
|
161
|
+
get: (key: string) => forward('cache.get', key),
|
|
162
|
+
set: (key: string, value: unknown, ttlMs?: number) => forward('cache.set', key, value, ttlMs),
|
|
163
|
+
delete: (key: string) => forward('cache.delete', key),
|
|
164
|
+
// The compute function stays here: only the value crosses.
|
|
165
|
+
remember: async (key: string, ttlMs: number, compute: () => Promise<unknown>) => {
|
|
166
|
+
const cached = await forward('cache.get', key);
|
|
167
|
+
if (cached !== undefined) return cached;
|
|
168
|
+
const value = await compute();
|
|
169
|
+
await forward('cache.set', key, value, ttlMs);
|
|
170
|
+
return value;
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
secrets: { get: (secret: string) => forward('secrets.get', secret) },
|
|
174
|
+
ai: { complete: (request: unknown) => forward('ai.complete', request) },
|
|
175
|
+
payments: {
|
|
176
|
+
checkout: (input: unknown) => forward('payments.checkout', input),
|
|
177
|
+
get provider() { return current().call.payments; },
|
|
178
|
+
},
|
|
179
|
+
unrestricted: async () => { throw failure('CMS_FORBIDDEN', `Plugin ${name} runs isolated, where unrestricted access does not exist.`); },
|
|
180
|
+
};
|
|
181
|
+
const register = plugin.register;
|
|
182
|
+
if (typeof register === 'function') await (register as (context: PluginContext) => unknown)(context as unknown as PluginContext);
|
|
183
|
+
hooks.freeze();
|
|
184
|
+
return { hooks, points, commands, jobs };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function registrations(call: IsolateCall): Promise<SiteRegistrations> {
|
|
188
|
+
let pending = sites.get(call.site);
|
|
189
|
+
if (!pending) {
|
|
190
|
+
pending = registerFor(call);
|
|
191
|
+
sites.set(call.site, pending);
|
|
192
|
+
// A failed registration is tried again on the next call.
|
|
193
|
+
pending.catch(() => { if (sites.get(call.site) === pending) sites.delete(call.site); });
|
|
194
|
+
}
|
|
195
|
+
return pending;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The handler's own error, so its code reaches the host; timeouts and cancellations stay hook errors. */
|
|
199
|
+
const cause = (error: unknown): unknown => error instanceof HookError && error.code === 'COSSACK_HOOK_FAILED' && error.cause !== undefined ? error.cause : error;
|
|
200
|
+
|
|
201
|
+
const withDeadline = async <T>(deadline: number, run: (signal: AbortSignal) => Promise<T>): Promise<T> => {
|
|
202
|
+
const controller = new AbortController();
|
|
203
|
+
const timer = setTimeout(() => controller.abort(failure('COSSACK_HOOK_TIMEOUT', `Plugin ${name} did not finish before its deadline.`)), Math.max(0, deadline - Date.now()));
|
|
204
|
+
try { return await run(controller.signal); } finally { clearTimeout(timer); }
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
run(call, bridge) {
|
|
209
|
+
if (call?.protocol !== ISOLATE_PROTOCOL) return Promise.reject(new Error(`Plugin ${name} was built for isolate protocol ${ISOLATE_PROTOCOL}, and the host called it with ${String(call?.protocol)}. Rebuild the application.`));
|
|
210
|
+
return scope.run({ bridge, call }, async () => {
|
|
211
|
+
const site = await registrations(call);
|
|
212
|
+
const run = call.run;
|
|
213
|
+
const timeoutMs = Math.max(1, call.deadline - Date.now());
|
|
214
|
+
switch (run.kind) {
|
|
215
|
+
case 'action': {
|
|
216
|
+
const point = site.points.get(run.point);
|
|
217
|
+
if (!point || point.kind !== 'action') throw new Error(`Plugin ${name} was asked to run ${run.point}, which it does not handle as an action.`);
|
|
218
|
+
const report = await site.hooks.doAction(point as never, run.payload, { timeoutMs });
|
|
219
|
+
const failed = report.outcomes.find(outcome => outcome.status !== 'ok');
|
|
220
|
+
if (failed) throw cause(failed.error);
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
case 'filter': {
|
|
224
|
+
const point = site.points.get(run.point);
|
|
225
|
+
if (!point || point.kind !== 'filter') throw new Error(`Plugin ${name} was asked to run ${run.point}, which it does not handle as a filter.`);
|
|
226
|
+
const applyFilters = site.hooks.applyFilters.bind(site.hooks) as (point: ExtensionPoint, value: unknown, input: unknown, options: { timeoutMs: number }) => Promise<unknown>;
|
|
227
|
+
try { return await applyFilters(point, run.value, run.input, { timeoutMs }); }
|
|
228
|
+
catch (error) { throw cause(error); }
|
|
229
|
+
}
|
|
230
|
+
case 'command': {
|
|
231
|
+
const handler = site.commands.get(run.name);
|
|
232
|
+
if (!handler) throw failure('CMS_NOT_FOUND', `Plugin ${name} has no handler for command ${run.name}.`);
|
|
233
|
+
return withDeadline(call.deadline, signal => Promise.resolve(handler(run.input, { principal: run.principal, signal })));
|
|
234
|
+
}
|
|
235
|
+
case 'job': {
|
|
236
|
+
const handler = site.jobs.get(run.name);
|
|
237
|
+
if (!handler) throw failure('CMS_NOT_FOUND', `Plugin ${name} has no handler for job ${run.name}.`);
|
|
238
|
+
await withDeadline(call.deadline, signal => Promise.resolve(handler(run.payload, { principal: run.principal as Principal, scheduledAt: run.scheduledAt, signal })));
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|