@cossackframework/cms 0.0.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +21 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +709 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +114 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +62 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +22 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +28 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +18 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +2 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +43 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +82 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +205 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +124 -0
- package/app/src/pages/auth/reset-password/index.ts +74 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +69 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +183 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +227 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +249 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { ClientVisibleError, getRequestContext } from '@cossackframework/core';
|
|
2
|
+
import { isCmsError, NETWORK_ADMIN, systemPrincipal } from '@cossackframework/cms';
|
|
3
|
+
import { MAIN_SITE, randomToken, type CmsHost, type CmsUser } from '@cossackframework/cms/server';
|
|
4
|
+
import { currentCms, networkFor, type CmsBindings } from '../cms/index';
|
|
5
|
+
import { getCookie } from 'hono/cookie';
|
|
6
|
+
import { linkOrigin, manageableHere, NETWORK_ACCOUNT_LOCKED, SESSION_COOKIE_NAME, type PublicUser, type RoleAssignment } from '../auth';
|
|
7
|
+
|
|
8
|
+
export interface UserSummary {
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
name: string;
|
|
12
|
+
avatar: string | null;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
/** When the user last signed in, recorded when a session starts; null when never. */
|
|
15
|
+
lastSignedInAt: string | null;
|
|
16
|
+
roles: RoleAssignment[];
|
|
17
|
+
/** On an added site, *Network account* for members who sign in through the network. */
|
|
18
|
+
badge?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface UserDetail extends UserSummary {
|
|
22
|
+
/** The account administers the network: only another network admin changes it. */
|
|
23
|
+
networkAdmin?: true;
|
|
24
|
+
/** For others on an added site, why a network account's profile, password and sign-in methods are not changed here. */
|
|
25
|
+
lockedProfile?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ListUsersOptions {
|
|
29
|
+
search?: string;
|
|
30
|
+
roleId?: string;
|
|
31
|
+
page?: number;
|
|
32
|
+
pageSize?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ListUsersResult {
|
|
36
|
+
items: UserSummary[];
|
|
37
|
+
total: number;
|
|
38
|
+
page: number;
|
|
39
|
+
pageSize: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface CreateUserInput {
|
|
43
|
+
email: string;
|
|
44
|
+
/** Required unless `invite` is set. */
|
|
45
|
+
password?: string;
|
|
46
|
+
/** Send an invitation: the account starts with a random password and an email with a link to set one, good for seven days. */
|
|
47
|
+
invite?: boolean;
|
|
48
|
+
name?: string;
|
|
49
|
+
/** Roles chosen by someone who may assign them; otherwise the default role. */
|
|
50
|
+
roleIds?: string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface UpdateUserInput {
|
|
54
|
+
name?: string;
|
|
55
|
+
email?: string;
|
|
56
|
+
avatar?: string | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function summary(user: CmsUser): UserSummary {
|
|
60
|
+
return {
|
|
61
|
+
id: user.id, email: user.email, name: user.name, avatar: user.avatar, createdAt: new Date(user.createdAt).toISOString(),
|
|
62
|
+
lastSignedInAt: user.lastSignInAt === null ? null : new Date(user.lastSignInAt).toISOString(),
|
|
63
|
+
roles: user.assignments.map(role => ({ id: role.id, name: role.name, permissions: [...role.permissions] })),
|
|
64
|
+
// Site accounts are an added site's own; members with a network account are marked.
|
|
65
|
+
...(currentCms().siteAccounts && user.account === 'network' ? { badge: 'Network account' } : {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** CMS failures carry safe text; pages show it. */
|
|
70
|
+
async function visible<T>(work: Promise<T>): Promise<T> {
|
|
71
|
+
try { return await work; }
|
|
72
|
+
catch (error) { throw isCmsError(error) ? new ClientVisibleError(error.message) : error; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function listUsers(options: ListUsersOptions = {}): Promise<ListUsersResult> {
|
|
76
|
+
const page = Math.max(1, options.page ?? 1);
|
|
77
|
+
const pageSize = Math.min(Math.max(1, options.pageSize ?? 20), 100);
|
|
78
|
+
const result = await currentCms().users.list({ search: options.search, role: options.roleId, limit: pageSize, offset: (page - 1) * pageSize });
|
|
79
|
+
return { items: result.items.map(summary), total: result.total, page, pageSize };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function getUser(id: string): Promise<UserDetail | null> {
|
|
83
|
+
const user = await currentCms().users.get(id);
|
|
84
|
+
if (!user) return null;
|
|
85
|
+
const cms = currentCms();
|
|
86
|
+
const networkAdmin = user.account === 'network' && (await cms.accounts.get(id))?.networkRole === NETWORK_ADMIN;
|
|
87
|
+
return { ...summary(user), ...(networkAdmin ? { networkAdmin: true as const } : {}), ...(await manageableHere(id) ? {} : { lockedProfile: NETWORK_ACCOUNT_LOCKED }) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A new account with the chosen roles, or General settings' default role. */
|
|
91
|
+
export async function createUser(input: CreateUserInput): Promise<Omit<PublicUser, 'principal'>> {
|
|
92
|
+
const cms = currentCms();
|
|
93
|
+
let roles: string[];
|
|
94
|
+
if (input.roleIds) {
|
|
95
|
+
roles = [...new Set(input.roleIds)];
|
|
96
|
+
for (const id of roles) if (!(await cms.users.role(id))) throw new ClientVisibleError('Choose roles that exist.');
|
|
97
|
+
} else {
|
|
98
|
+
const role = await cms.settings.get('general.defaultRole');
|
|
99
|
+
roles = role && (await cms.users.role(role)) ? [role] : [];
|
|
100
|
+
}
|
|
101
|
+
if (!input.invite && !input.password) throw new ClientVisibleError('Set a password or send an invitation.');
|
|
102
|
+
if (input.invite && !cms.mail) throw new ClientVisibleError('No email sender is configured, so invitations cannot be sent. Set a password instead.');
|
|
103
|
+
const password = input.invite ? randomToken(32) : input.password!;
|
|
104
|
+
const user = await visible(cms.users.create({ email: input.email, password, name: input.name?.trim() || input.email.split('@')[0]!, roles }));
|
|
105
|
+
if (input.invite) await sendInvitation(cms, user.email, user.name);
|
|
106
|
+
return { ...summary(user), meta: null };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The invitation: a link to set a password, good for seven days, from the site's sender. */
|
|
110
|
+
async function sendInvitation(cms: CmsHost, email: string, name: string): Promise<void> {
|
|
111
|
+
const reset = await cms.signIn.accounts.createPasswordReset(email, { ttlMs: 7 * 24 * 60 * 60_000 });
|
|
112
|
+
// The site's own address, never the request's Host: without one, no link is sent.
|
|
113
|
+
const origin = linkOrigin();
|
|
114
|
+
if (!reset || !cms.mail || !origin) return;
|
|
115
|
+
const title = await cms.settings.get('general.siteTitle').catch(() => '');
|
|
116
|
+
const link = `${origin.replace(/\/$/, '')}/auth/reset-password?token=${reset.token}`;
|
|
117
|
+
await cms.mail.send({ kind: 'invitation', to: email, from: cms.mailFrom, subject: `You are invited to ${title || 'the site'}`,
|
|
118
|
+
text: `Hello ${name || email},\n\nAn account was made for you on ${title || origin}. Set your password here within seven days:\n${link}\n\nIf you were not expecting this, ignore this email.` });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** A network account on an added site keeps its name, email and picture unless the person or a network admin changes them. */
|
|
122
|
+
export async function updateUser(id: string, patch: UpdateUserInput): Promise<void> {
|
|
123
|
+
const cms = currentCms();
|
|
124
|
+
if (!(await manageableHere(id))) {
|
|
125
|
+
const user = await cms.users.get(id);
|
|
126
|
+
if (user && (Object.keys(patch) as (keyof UpdateUserInput)[]).some(key => patch[key] !== undefined && patch[key] !== user[key])) throw new ClientVisibleError(NETWORK_ACCOUNT_LOCKED);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
await visible(cms.users.update(id, patch));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Set a user's password. Every other session of the account ends, so whoever had the old
|
|
134
|
+
* password is signed out; the caller's own session stays when it is their own password.
|
|
135
|
+
*/
|
|
136
|
+
export async function changeUserPassword(id: string, newPassword: string): Promise<void> {
|
|
137
|
+
if (!(await manageableHere(id))) throw new ClientVisibleError(NETWORK_ACCOUNT_LOCKED);
|
|
138
|
+
const cms = currentCms();
|
|
139
|
+
if (!(await visible(cms.users.setPassword(id, newPassword)))) throw new ClientVisibleError('User not found.');
|
|
140
|
+
const c = getRequestContext();
|
|
141
|
+
const own = c && (c.get('user') as { id?: string } | undefined)?.id === id ? getCookie(c, SESSION_COOKIE_NAME) : undefined;
|
|
142
|
+
// On an added site, a network account's sessions are the network host's; its sites' child sessions end with them.
|
|
143
|
+
const sessions = cms.siteAccounts && (await cms.storesOf(id)).kind === 'network' && c ? networkFor(c.env as CmsBindings).main.authSessions : cms.authSessions;
|
|
144
|
+
await sessions.revokeAllForUser(id, own);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* On the main site, deletes the account: from every site it belongs to, then what signs it in.
|
|
149
|
+
* On another site, removes the member and their roles: a site account goes with them, a network
|
|
150
|
+
* account stays. Content keeps its author ID. The last network admin cannot be deleted.
|
|
151
|
+
*/
|
|
152
|
+
export async function deleteUser(id: string): Promise<void> {
|
|
153
|
+
const c = getRequestContext();
|
|
154
|
+
const cms = currentCms();
|
|
155
|
+
if (c?.get('site')?.id && c.get('site').id !== MAIN_SITE) { await visible(cms.users.delete(id)); return; }
|
|
156
|
+
// Deleting on the main site removes the account from every site it belongs to.
|
|
157
|
+
if (!(await manageableHere(id))) throw new ClientVisibleError(NETWORK_ACCOUNT_LOCKED);
|
|
158
|
+
await visible(networkFor(c!.env as CmsBindings).deleteAccount(id, { principal: systemPrincipal('users') }));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function assignRole(userId: string, roleId: string): Promise<void> {
|
|
162
|
+
const user = await currentCms().users.get(userId);
|
|
163
|
+
if (user) await syncUserRoles(userId, [...new Set([...user.roles, roleId])]);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function removeRole(userId: string, roleId: string): Promise<void> {
|
|
167
|
+
const user = await currentCms().users.get(userId);
|
|
168
|
+
if (user) await syncUserRoles(userId, user.roles.filter(role => role !== roleId));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function syncUserRoles(userId: string, roleIds: string[]): Promise<void> {
|
|
172
|
+
await visible(currentCms().users.setRoles(userId, roleIds));
|
|
173
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cossackframework/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Cossack CMS: resources, schema planning, repositories, auth and stores on RomeDB",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"repository": {
|
|
@@ -8,7 +9,118 @@
|
|
|
8
9
|
"url": "https://github.com/cossackframework/cossack",
|
|
9
10
|
"directory": "packages/cms"
|
|
10
11
|
},
|
|
12
|
+
"main": "src/index.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"app",
|
|
16
|
+
"!app/src/plugins/example",
|
|
17
|
+
"agent-docs.json"
|
|
18
|
+
],
|
|
11
19
|
"publishConfig": {
|
|
12
20
|
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@cossackframework/solar-icons": "0.7.1",
|
|
24
|
+
"@simplewebauthn/browser": "14.0.0",
|
|
25
|
+
"@tiptap/core": "3.32.0",
|
|
26
|
+
"@tiptap/extension-document": "3.32.0",
|
|
27
|
+
"@tiptap/extension-image": "3.32.0",
|
|
28
|
+
"@tiptap/extension-table": "3.32.0",
|
|
29
|
+
"@tiptap/extension-text-align": "3.32.0",
|
|
30
|
+
"@tiptap/extensions": "3.32.0",
|
|
31
|
+
"@tiptap/pm": "3.32.0",
|
|
32
|
+
"@tiptap/starter-kit": "3.32.0",
|
|
33
|
+
"markdown-it": "15.0.3",
|
|
34
|
+
"prosemirror-collab": "1.3.1",
|
|
35
|
+
"uqr": "0.1.3",
|
|
36
|
+
"@cossackframework/auth": "0.9.2",
|
|
37
|
+
"@cossackframework/romedb": "0.9.2",
|
|
38
|
+
"@cossackframework/core": "0.9.2",
|
|
39
|
+
"@cossackframework/renderer": "0.9.2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@aws-sdk/client-s3": "^3.1156.0",
|
|
43
|
+
"hono": "^4.13.18",
|
|
44
|
+
"sharp": "^0.35.5",
|
|
45
|
+
"vite": "*",
|
|
46
|
+
"@cossackframework/framework": "0.9.2",
|
|
47
|
+
"@cossackframework/node-adapter": "0.9.2",
|
|
48
|
+
"@cossackframework/ui": "0.9.2"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@aws-sdk/client-s3": "^3.1156.0",
|
|
52
|
+
"@types/markdown-it": "^14.2.0",
|
|
53
|
+
"@types/node": "^22.19.0",
|
|
54
|
+
"hono": "^4.13.18",
|
|
55
|
+
"miniflare": "4.20260722.0",
|
|
56
|
+
"rolldown": "~1.1.5",
|
|
57
|
+
"sharp": "^0.35.5",
|
|
58
|
+
"simple-icons": "16.36.0",
|
|
59
|
+
"vite": "^8.1.6",
|
|
60
|
+
"vitest": "^4.1.12",
|
|
61
|
+
"@cossackframework/framework": "0.9.2",
|
|
62
|
+
"@cossackframework/node-adapter": "0.9.2"
|
|
63
|
+
},
|
|
64
|
+
"exports": {
|
|
65
|
+
".": "./src/index.ts",
|
|
66
|
+
"./server": "./src/server/index.ts",
|
|
67
|
+
"./updates": "./src/updates.ts",
|
|
68
|
+
"./isolate": "./src/isolate.ts",
|
|
69
|
+
"./cloudflare": "./src/cloudflare.ts",
|
|
70
|
+
"./node": "./src/node.ts",
|
|
71
|
+
"./storage": "./src/storage/index.ts",
|
|
72
|
+
"./storage/cloudflare": "./src/storage/cloudflare.ts",
|
|
73
|
+
"./storage/node": "./src/storage/node.ts",
|
|
74
|
+
"./vite": {
|
|
75
|
+
"types": "./src/vite.d.ts",
|
|
76
|
+
"default": "./src/vite.js"
|
|
77
|
+
},
|
|
78
|
+
"./app/*": "./app/src/*.ts",
|
|
79
|
+
"./app/cms/blocks.css": "./app/src/cms/blocks.css",
|
|
80
|
+
"./package.json": "./package.json"
|
|
81
|
+
},
|
|
82
|
+
"imports": {
|
|
83
|
+
"#app/*": "./app/src/*.ts"
|
|
84
|
+
},
|
|
85
|
+
"cossack": {
|
|
86
|
+
"vite": "src/vite.js",
|
|
87
|
+
"root": "app/src",
|
|
88
|
+
"alias": "cms",
|
|
89
|
+
"pages": [
|
|
90
|
+
"pages/"
|
|
91
|
+
],
|
|
92
|
+
"plugins": [
|
|
93
|
+
"plugins/default-theme/"
|
|
94
|
+
],
|
|
95
|
+
"config": [
|
|
96
|
+
"config/cms.ts",
|
|
97
|
+
"config/auth.ts"
|
|
98
|
+
],
|
|
99
|
+
"host": [
|
|
100
|
+
"cms.config.ts",
|
|
101
|
+
"stores.client.ts"
|
|
102
|
+
],
|
|
103
|
+
"hostTemplate": "0.9.0"
|
|
104
|
+
},
|
|
105
|
+
"peerDependenciesMeta": {
|
|
106
|
+
"@aws-sdk/client-s3": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"@cossackframework/node-adapter": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"sharp": {
|
|
113
|
+
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"vite": {
|
|
116
|
+
"optional": true
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"scripts": {
|
|
120
|
+
"dev": "pnpm --dir app run dev",
|
|
121
|
+
"sync": "pnpm --dir app run sync",
|
|
122
|
+
"brands": "node scripts/brand-icons.mjs",
|
|
123
|
+
"test": "pnpm sync && vitest",
|
|
124
|
+
"icons": "node scripts/icon-catalog.mjs"
|
|
13
125
|
}
|
|
14
|
-
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automations: "when this happens, do that", kept as data and run from the outbox events the
|
|
3
|
+
* CMS already delivers. An automation names an event, optional conditions, and one action:
|
|
4
|
+
* an email from the site. Templates use the site's bindings: `{{ $.title }}` reads the event's
|
|
5
|
+
* variables, `{{ $site.title }}` the site and `{{ $user.name }}` the person who acted. Posting the
|
|
6
|
+
* same events to a URL is what webhooks do, with a delivery log. Pure shapes and checks; the
|
|
7
|
+
* server module runs them.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { resolveBindings, type BindingScopes } from './bindings';
|
|
11
|
+
|
|
12
|
+
export const AUTOMATION_EVENTS = Object.freeze(['entry.published', 'entry.created', 'entry.updated', 'entry.deleted', 'form.submitted', 'payment.completed'] as const);
|
|
13
|
+
export type AutomationEvent = (typeof AUTOMATION_EVENTS)[number];
|
|
14
|
+
|
|
15
|
+
export const AUTOMATION_EVENT_LABELS: Readonly<Record<AutomationEvent, string>> = Object.freeze({
|
|
16
|
+
'entry.published': 'An entry is published', 'entry.created': 'An entry is created', 'entry.updated': 'An entry changes', 'entry.deleted': 'An entry is deleted',
|
|
17
|
+
'form.submitted': 'A form is submitted', 'payment.completed': 'A payment is completed',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export interface AutomationConditions {
|
|
21
|
+
/** For entry events: only this collection. */
|
|
22
|
+
readonly collection?: string;
|
|
23
|
+
/** For form events: only this form, by slug. */
|
|
24
|
+
readonly form?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type AutomationAction = { readonly kind: 'email'; readonly to: string; readonly subject: string; readonly text: string };
|
|
28
|
+
|
|
29
|
+
export interface AutomationInput {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly event: AutomationEvent;
|
|
32
|
+
readonly conditions?: AutomationConditions;
|
|
33
|
+
readonly action: AutomationAction;
|
|
34
|
+
readonly active?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Automation extends AutomationInput {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly active: boolean;
|
|
40
|
+
readonly runs: number;
|
|
41
|
+
readonly lastRunAt: number | null;
|
|
42
|
+
readonly lastError: string;
|
|
43
|
+
readonly createdAt: number;
|
|
44
|
+
readonly updatedAt: number;
|
|
45
|
+
/** Who saved or last switched it on: it runs with their current permissions, and sends only what they may read. */
|
|
46
|
+
readonly author: string | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const EMAIL = /^(?:[^\s@]+@[^\s@]+\.[^\s@]+|\{\{\s*\$[a-z]*\.[A-Za-z_][\w.#-]*\s*\}\})$/;
|
|
50
|
+
const NAME = /^[a-z][a-z0-9_]{0,40}$/;
|
|
51
|
+
|
|
52
|
+
/** What is wrong with an automation, as sentences; empty when it can be saved. */
|
|
53
|
+
export function automationProblems(input: unknown): string[] {
|
|
54
|
+
const problems: string[] = [];
|
|
55
|
+
if (!input || typeof input !== 'object') return ['The automation must be an object.'];
|
|
56
|
+
const value = input as Record<string, unknown>;
|
|
57
|
+
if (typeof value.name !== 'string' || !value.name.trim() || value.name.length > 120) problems.push('Name the automation in 1 to 120 characters.');
|
|
58
|
+
if (!(AUTOMATION_EVENTS as readonly string[]).includes(value.event as string)) problems.push(`Choose an event: ${AUTOMATION_EVENTS.join(', ')}.`);
|
|
59
|
+
const conditions = value.conditions as Record<string, unknown> | undefined;
|
|
60
|
+
if (conditions !== undefined) {
|
|
61
|
+
if (!conditions || typeof conditions !== 'object') problems.push('Conditions must be an object.');
|
|
62
|
+
else {
|
|
63
|
+
if (conditions.collection !== undefined && conditions.collection !== '' && (typeof conditions.collection !== 'string' || !NAME.test(conditions.collection))) problems.push('The collection condition must be a collection name.');
|
|
64
|
+
if (conditions.form !== undefined && conditions.form !== '' && (typeof conditions.form !== 'string' || !/^[a-z0-9-]{1,120}$/.test(conditions.form))) problems.push('The form condition must be a form slug.');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const action = value.action as Record<string, unknown> | undefined;
|
|
68
|
+
if (!action || typeof action !== 'object') problems.push('Choose an action.');
|
|
69
|
+
else if (action.kind === 'email') {
|
|
70
|
+
const recipients = String(action.to ?? '').split(',').map(part => part.trim()).filter(Boolean);
|
|
71
|
+
if (!recipients.length || recipients.length > 10 || recipients.some(part => !EMAIL.test(part))) problems.push('Email: up to ten addresses, or a binding such as {{ $.customerEmail }}.');
|
|
72
|
+
if (typeof action.subject !== 'string' || !action.subject.trim() || action.subject.length > 200) problems.push('Email: a subject of 1 to 200 characters.');
|
|
73
|
+
if (typeof action.text !== 'string' || !action.text.trim() || action.text.length > 20_000) problems.push('Email: a text of up to 20,000 characters.');
|
|
74
|
+
} else problems.push('The action is an email; to post events to a URL, add a webhook.');
|
|
75
|
+
if (value.active !== undefined && typeof value.active !== 'boolean') problems.push('active is true or false.');
|
|
76
|
+
return problems;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Fill a template with the site's bindings: `{{ $.title }}` and `{{ $.values.email }}` read the
|
|
81
|
+
* event's variables, `{{ $site.title }}` and `{{ $user.name }}` the other scopes. Unknown paths
|
|
82
|
+
* become empty, as on a page; `{{ name }}` without a scope stays as written.
|
|
83
|
+
*/
|
|
84
|
+
export function renderAutomationTemplate(template: string, vars: Record<string, unknown>, scopes: Omit<BindingScopes, 'entry'> = {}): string {
|
|
85
|
+
return resolveBindings(template, { ...scopes, entry: vars });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Whether the automation's conditions hold for the variables of an event. */
|
|
89
|
+
export function automationMatches(automation: Pick<Automation, 'event' | 'conditions'>, event: AutomationEvent, vars: Record<string, unknown>): boolean {
|
|
90
|
+
if (automation.event !== event) return false;
|
|
91
|
+
const conditions = automation.conditions ?? {};
|
|
92
|
+
if (conditions.collection && vars.collection !== conditions.collection) return false;
|
|
93
|
+
if (conditions.form && vars.form !== conditions.form) return false;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
package/src/bindings.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic content: a text field may put values inside its text with `{{ $.price }}`, so words
|
|
3
|
+
* and formatting can surround them. A path walks into objects and lists with dots:
|
|
4
|
+
* `{{ $.specs.0.name }}`. Three scopes:
|
|
5
|
+
*
|
|
6
|
+
* - `$`: the entry shown. A widget on an entry's page sees that entry; elsewhere it is empty.
|
|
7
|
+
* - `$site`: the site's public settings, such as `{{ $site.title }}`.
|
|
8
|
+
* - `$user`: the signed-in user, such as `{{ $user.name }}`; empty for visitors. A page that
|
|
9
|
+
* uses it is not cached for everyone.
|
|
10
|
+
*
|
|
11
|
+
* The site resolves bindings when it renders; the editor keeps the syntax.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { SiteSettings } from './settings';
|
|
15
|
+
|
|
16
|
+
/** The scopes a binding can read: `''` for `$` (the entry), `site` and `user`. */
|
|
17
|
+
export const BINDING_SCOPES = Object.freeze(['', 'site', 'user'] as const);
|
|
18
|
+
export type BindingScope = (typeof BINDING_SCOPES)[number];
|
|
19
|
+
|
|
20
|
+
/** What bindings read, by scope. A missing scope renders its bindings empty. */
|
|
21
|
+
export interface BindingScopes {
|
|
22
|
+
readonly entry?: Readonly<Record<string, unknown>> | null;
|
|
23
|
+
readonly site?: Readonly<Record<string, unknown>> | null;
|
|
24
|
+
readonly user?: Readonly<Record<string, unknown>> | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Bindings inside text: `{{ $.a.b }}`, `{{ $site.title }}`, `{{ $.content#hero.title }}`; the scope is captured even when unknown, so it can be reported. */
|
|
28
|
+
const INLINE = /\{\{\s*\$([a-z]*)\.([A-Za-z_][\w-]*(?:#[\w-]+)?(?:\.[\w-]+(?:#[\w-]+)?)*)\s*\}\}/g;
|
|
29
|
+
|
|
30
|
+
/** What `$site` reads: the site's public settings, the same on a page and in an automation's email. */
|
|
31
|
+
export function siteBindingScope(settings: SiteSettings): Record<string, unknown> {
|
|
32
|
+
return { title: settings['general.siteTitle'], tagline: settings['general.tagline'], logo: settings['general.logo'], icon: settings['general.favicon'], year: new Date().getFullYear() };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether a value binds to anything at all, so a renderer knows to resolve it. */
|
|
36
|
+
export function hasBinding(value: unknown): value is string {
|
|
37
|
+
return typeof value === 'string' && /\{\{\s*\$[a-z]*\./.test(value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The bindings of a value, in order, with their scopes. */
|
|
41
|
+
export function bindingRefs(value: unknown): { scope: string; path: string }[] {
|
|
42
|
+
if (typeof value !== 'string') return [];
|
|
43
|
+
return [...value.matchAll(INLINE)].map(match => ({ scope: match[1]!, path: match[2]! }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The entry field paths a value binds to (`$` only), in order, for pickers and checks. */
|
|
47
|
+
export function bindingPaths(value: unknown): string[] {
|
|
48
|
+
return bindingRefs(value).filter(ref => ref.scope === '').map(ref => ref.path);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether a value reads the signed-in user, so the page it is on cannot be cached for everyone. */
|
|
52
|
+
export function usesUserBinding(value: unknown): boolean {
|
|
53
|
+
return bindingRefs(value).some(ref => ref.scope === 'user');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Why a value's bindings are refused: a scope other than `$`, `$site` and `$user`. Undefined when fine. */
|
|
57
|
+
export function bindingProblem(value: unknown): string | undefined {
|
|
58
|
+
const unknown = bindingRefs(value).find(ref => !(BINDING_SCOPES as readonly string[]).includes(ref.scope));
|
|
59
|
+
return unknown ? `{{ $${unknown.scope}.${unknown.path} }} reads an unknown scope: use $ (the entry), $site or $user.` : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The value at a dotted path of the scope; undefined when the path leads nowhere. A segment
|
|
64
|
+
* `field#id` picks the block with that ID out of a blocks field, nested ones included, and
|
|
65
|
+
* stands for its data: `{{ $.content#hero.title }}` is the `title` of the block `hero`.
|
|
66
|
+
*/
|
|
67
|
+
export function bindingValue(scope: Readonly<Record<string, unknown>>, path: string): unknown {
|
|
68
|
+
let current: unknown = scope;
|
|
69
|
+
for (const part of path.split('.')) {
|
|
70
|
+
if (current === null || current === undefined) return undefined;
|
|
71
|
+
const hash = part.indexOf('#');
|
|
72
|
+
if (hash > 0 && typeof current === 'object' && !Array.isArray(current)) {
|
|
73
|
+
const block = blockById((current as Record<string, unknown>)[part.slice(0, hash)], part.slice(hash + 1));
|
|
74
|
+
current = block ? block.data : undefined;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(current)) { const index = Number(part); current = Number.isInteger(index) ? current[index] : undefined; continue; }
|
|
78
|
+
if (typeof current !== 'object') return undefined;
|
|
79
|
+
current = (current as Record<string, unknown>)[part];
|
|
80
|
+
}
|
|
81
|
+
return current;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The block with this `_id` in a blocks value, at any depth; undefined when the value holds none. */
|
|
85
|
+
function blockById(value: unknown, id: string): { data: unknown } | undefined {
|
|
86
|
+
if (!Array.isArray(value)) return undefined;
|
|
87
|
+
for (const entry of value) {
|
|
88
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
89
|
+
const block = entry as { _id?: unknown; data?: unknown; children?: unknown };
|
|
90
|
+
if (block._id === id) return { data: block.data };
|
|
91
|
+
const inner = blockById(block.children, id);
|
|
92
|
+
if (inner) return inner;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A field's value as text for a block: numbers and booleans as they are written, lists joined
|
|
99
|
+
* with commas, dates (fields of kind datetime hold milliseconds) left as numbers for the theme
|
|
100
|
+
* to format, objects as nothing. Rich text and blocks do not bind; use their own blocks.
|
|
101
|
+
*/
|
|
102
|
+
export function bindingText(value: unknown): string {
|
|
103
|
+
if (value === null || value === undefined) return '';
|
|
104
|
+
if (typeof value === 'string') return value;
|
|
105
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return String(value);
|
|
106
|
+
if (Array.isArray(value)) return value.map(bindingText).filter(Boolean).join(', ');
|
|
107
|
+
return '';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The value with its bindings replaced by the scopes' values, in place. Unknown paths and scopes become empty text. */
|
|
111
|
+
export function resolveBindings(value: string, scopes: BindingScopes): string {
|
|
112
|
+
return value.replace(INLINE, (_match, scope: string, path: string) => {
|
|
113
|
+
const source = scope === '' ? scopes.entry : scope === 'site' ? scopes.site : scope === 'user' ? scopes.user : null;
|
|
114
|
+
return source ? bindingText(bindingValue(source, path)) : '';
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A block's data with every bound string field resolved against the scopes; other fields stay.
|
|
120
|
+
* `fields` names the block type's text-like fields (string and text kinds), the only ones that bind.
|
|
121
|
+
*/
|
|
122
|
+
export function resolveBlockBindings(data: Readonly<Record<string, unknown>>, fields: readonly string[], scopes: BindingScopes): Record<string, unknown> {
|
|
123
|
+
let changed = false;
|
|
124
|
+
const next: Record<string, unknown> = { ...data };
|
|
125
|
+
for (const name of fields) {
|
|
126
|
+
const value = data[name];
|
|
127
|
+
if (!hasBinding(value)) continue;
|
|
128
|
+
next[name] = resolveBindings(value, scopes);
|
|
129
|
+
changed = true;
|
|
130
|
+
}
|
|
131
|
+
return changed ? next : { ...data };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The value with `{{ $.name }}` appended, after a space when there is text. */
|
|
135
|
+
export function withBinding(value: unknown, path: string): string {
|
|
136
|
+
const current = typeof value === 'string' ? value : '';
|
|
137
|
+
return current.trim() === '' ? `{{ $.${path} }}` : `${current}${current.endsWith(' ') ? '' : ' '}{{ $.${path} }}`;
|
|
138
|
+
}
|