@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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dashboard's lists (entries, users, roles, forms), from `@cossackframework/ui/blocks` with
|
|
3
|
+
* the dashboard's translations and icon style. Selection goes with `bulkBar` from `./bulk`.
|
|
4
|
+
*/
|
|
5
|
+
import type { TemplateResult } from '@cossackframework/renderer';
|
|
6
|
+
import * as blocks from '@cossackframework/ui/blocks';
|
|
7
|
+
import type { ListFiltersOptions, ListFooterOptions, ListTableOptions } from '@cossackframework/ui/blocks';
|
|
8
|
+
import { shellIcons } from './icons';
|
|
9
|
+
|
|
10
|
+
export type { ListColumn, RowAction } from '@cossackframework/ui/blocks';
|
|
11
|
+
export { rowActions } from '@cossackframework/ui/blocks';
|
|
12
|
+
|
|
13
|
+
/** The list as a table in a card; a row's checkbox reads "Select <label>". */
|
|
14
|
+
export function listTable<T>(options: ListTableOptions<T>): TemplateResult {
|
|
15
|
+
const selection = options.selection && { ...options.selection, selectAllLabel: __('Select all'), label: (row: T) => `${__('Select')} ${options.selection!.label(row)}` };
|
|
16
|
+
return blocks.listTable({ ...options, selection, empty: options.empty ?? __('Nothing found.') });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The filter bar above a list. */
|
|
20
|
+
export function listFilters(options: ListFiltersOptions): TemplateResult {
|
|
21
|
+
return blocks.listFilters({ filterLabel: __('Filter'), searchIcon: shellIcons().search, ...options });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The count and pages under a list. */
|
|
25
|
+
export function listFooter(options: Omit<ListFooterOptions, 'labels'>): TemplateResult {
|
|
26
|
+
return blocks.listFooter({ ...options, labels: { item: __('item'), items: __('items'), pagination: __('Pagination'), previous: __('Previous page'), next: __('Next page'),
|
|
27
|
+
page: (page: number) => `${__('Page')} ${page}` } });
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { ShieldKeyholeIcon as iconSvg } from '@cossackframework/solar-icons/shield-keyhole/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'roles',
|
|
8
|
+
label: 'Roles',
|
|
9
|
+
href: '/dashboard/roles',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'admin',
|
|
12
|
+
parent: 'users',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default descriptor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { MonitorSmartphoneIcon as iconSvg } from '@cossackframework/solar-icons/monitor-smartphone/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'sessions',
|
|
8
|
+
label: 'Sessions',
|
|
9
|
+
href: '/dashboard/sessions',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'authenticated',
|
|
12
|
+
placement: 'account',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default descriptor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { UserCircleIcon as iconSvg } from '@cossackframework/solar-icons/user-circle/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'settings',
|
|
8
|
+
label: 'Profile settings',
|
|
9
|
+
href: '/dashboard/profile',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'authenticated',
|
|
12
|
+
placement: 'account',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default descriptor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { UsersGroupRoundedIcon as iconSvg } from '@cossackframework/solar-icons/users-group-rounded/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'users',
|
|
8
|
+
label: 'Users',
|
|
9
|
+
href: '/dashboard/users',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'admin',
|
|
12
|
+
children: [
|
|
13
|
+
{ label: 'All users', href: '/dashboard/users' },
|
|
14
|
+
{ label: 'Add user', href: '/dashboard/users/new' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default descriptor;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dashboard screen's Help and Screen options panels. Its heading, link buttons and messages
|
|
3
|
+
* come from `@cossackframework/ui/blocks` (`pageHeader`, `linkButton`, `notice`), which plugin
|
|
4
|
+
* screens import too.
|
|
5
|
+
*/
|
|
6
|
+
import { html, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
|
|
8
|
+
/** A screen's panel the taskbar opens: a native popover above the taskbar's buttons, dismissed by a click outside or Escape. */
|
|
9
|
+
function screenPanel(id: string, title: string, body: TemplateResult): TemplateResult {
|
|
10
|
+
return html`<div id=${id} popover="auto" aria-labelledby=${`${id}-title`} class="fixed inset-auto bottom-12 right-3 m-0 w-[min(26rem,calc(100vw-1.5rem))] rounded-lg border border-border bg-popover p-4 text-sm text-popover-foreground shadow-lg">
|
|
11
|
+
<h2 id=${`${id}-title`} class="mb-2 text-sm font-semibold text-foreground">${title}</h2>
|
|
12
|
+
<div class="space-y-2 text-muted-foreground [&_a]:text-primary [&_a]:hover:underline [&_b]:font-medium [&_b]:text-foreground">${body}</div>
|
|
13
|
+
</div>`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The screen's Help, opened from the taskbar's Help button: what the screen shows and what each part does. */
|
|
17
|
+
export function screenHelp(body: TemplateResult): TemplateResult {
|
|
18
|
+
return screenPanel('screen-help', __('Help'), body);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The screen's options, opened from the taskbar's Screen options button: controls that change how the screen shows its content. */
|
|
22
|
+
export function screenOptions(body: TemplateResult): TemplateResult {
|
|
23
|
+
return screenPanel('screen-options', __('Screen options'), body);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** What a screen's options keep: the columns hidden, by ID, and the items a page lists. */
|
|
27
|
+
export interface ScreenPreferences {
|
|
28
|
+
hidden: string[];
|
|
29
|
+
perPage: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Items per page a screen's options accept. */
|
|
33
|
+
export const PER_PAGE = { min: 1, max: 100 } as const;
|
|
34
|
+
|
|
35
|
+
/** The cookie a screen keeps its options in, per browser, as the sidebar keeps its state; `screen` names the screen, such as `entries-posts`. */
|
|
36
|
+
export function screenCookie(screen: string): string {
|
|
37
|
+
return `cs-screen-${screen.replace(/[^a-z0-9-]/gi, '_')}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A screen's options from its cookie's value; the defaults for whatever it lacks or does not parse. */
|
|
41
|
+
export function screenPreferences(value: string | undefined, defaults: ScreenPreferences): ScreenPreferences {
|
|
42
|
+
let parsed: unknown;
|
|
43
|
+
for (const text of [value, safeDecode(value)]) {
|
|
44
|
+
try { parsed = JSON.parse(text ?? ''); break; } catch { /* try the next reading */ }
|
|
45
|
+
}
|
|
46
|
+
const saved = parsed && typeof parsed === 'object' ? parsed as Partial<Record<keyof ScreenPreferences, unknown>> : {};
|
|
47
|
+
const hidden = Array.isArray(saved.hidden) ? saved.hidden.filter((id): id is string => typeof id === 'string' && id.length <= 100).slice(0, 50) : defaults.hidden;
|
|
48
|
+
return { hidden, perPage: clampPerPage(saved.perPage, defaults.perPage) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Items per page within {@link PER_PAGE}; `fallback` for anything that is not a number. */
|
|
52
|
+
export function clampPerPage(value: unknown, fallback: number): number {
|
|
53
|
+
const number = Math.trunc(Number(value));
|
|
54
|
+
return Number.isFinite(number) && number > 0 ? Math.min(Math.max(number, PER_PAGE.min), PER_PAGE.max) : fallback;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Keep a screen's options in its cookie for a year. Client only. */
|
|
58
|
+
export function saveScreenPreferences(screen: string, preferences: ScreenPreferences): void {
|
|
59
|
+
if (typeof document === 'undefined') return;
|
|
60
|
+
try {
|
|
61
|
+
document.cookie = `${screenCookie(screen)}=${encodeURIComponent(JSON.stringify(preferences))}; Path=/dashboard; Max-Age=31536000; SameSite=Lax`;
|
|
62
|
+
} catch { /* cookies unavailable */ }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function safeDecode(value: string | undefined): string | undefined {
|
|
66
|
+
try { return value === undefined ? undefined : decodeURIComponent(value); } catch { return undefined; }
|
|
67
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DashboardModule } from './types';
|
|
2
|
+
import { authOptions } from '../auth-options';
|
|
3
|
+
import users from './modules/users';
|
|
4
|
+
import sessions from './modules/sessions';
|
|
5
|
+
import settings from './modules/settings';
|
|
6
|
+
import roles from './modules/roles';
|
|
7
|
+
import { Widget4Icon } from '@cossackframework/solar-icons/widget-4/line';
|
|
8
|
+
|
|
9
|
+
const modules: Record<string, DashboardModule> = { users, sessions, settings, roles };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The modules the project chose (src/dashboard.config.ts: `modules`), in this order, then the
|
|
13
|
+
* project's own screens (`navigation`).
|
|
14
|
+
*/
|
|
15
|
+
export const dashboardModules: DashboardModule[] = [
|
|
16
|
+
...Object.entries(modules).filter(([id]) => (authOptions.modules as readonly string[]).includes(id)).map(([, module]) => module),
|
|
17
|
+
...authOptions.navigation.map((item): DashboardModule => ({ ...item, icon: item.icon ?? { line: Widget4Icon }, authorization: item.authorization ?? 'authenticated' })),
|
|
18
|
+
];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The table of a user's signed-in sessions, shared by the Sessions page and the Sessions tab
|
|
3
|
+
* of the user screen. The caller's own session is marked current and cannot be ended here.
|
|
4
|
+
*/
|
|
5
|
+
import { Badge, Button, Icon, Tooltip } from '@cossackframework/ui';
|
|
6
|
+
import { html, component, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import { shellIcons } from './icons';
|
|
8
|
+
import type { SessionInfo } from '../auth';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parses a User-Agent string into device type + human-readable browser/OS.
|
|
12
|
+
* Intentionally lightweight (no dep) — good enough for a sessions list tooltip.
|
|
13
|
+
*/
|
|
14
|
+
export function parseUserAgent(ua: string | null): {
|
|
15
|
+
device: 'mobile' | 'tablet' | 'desktop';
|
|
16
|
+
browser: string;
|
|
17
|
+
os: string;
|
|
18
|
+
} {
|
|
19
|
+
if (!ua) return { device: 'desktop', browser: 'Unknown', os: 'Unknown' };
|
|
20
|
+
const lower = ua.toLowerCase();
|
|
21
|
+
// OS
|
|
22
|
+
let os = 'Unknown';
|
|
23
|
+
if (/windows/.test(lower)) os = 'Windows';
|
|
24
|
+
else if (/mac os|macintosh|iphone|ipad/.test(lower)) os = /ipad|iphone/.test(lower) ? 'iOS' : 'macOS';
|
|
25
|
+
else if (/android/.test(lower)) os = 'Android';
|
|
26
|
+
else if (/linux/.test(lower)) os = 'Linux';
|
|
27
|
+
// Browser (order matters — check specific ones first)
|
|
28
|
+
let browser = 'Unknown';
|
|
29
|
+
if (/edg\//.test(lower)) browser = 'Edge';
|
|
30
|
+
else if (/opr\/|opera/.test(lower)) browser = 'Opera';
|
|
31
|
+
else if (/chrome/.test(lower) && !/chromium/.test(lower)) browser = 'Chrome';
|
|
32
|
+
else if (/firefox/.test(lower)) browser = 'Firefox';
|
|
33
|
+
else if (/safari/.test(lower)) browser = 'Safari';
|
|
34
|
+
// Device type
|
|
35
|
+
let device: 'mobile' | 'tablet' | 'desktop' = 'desktop';
|
|
36
|
+
if (/ipad|tablet/.test(lower)) device = 'tablet';
|
|
37
|
+
else if (/mobi|iphone|android.*mobile/.test(lower)) device = 'mobile';
|
|
38
|
+
return { device, browser, os };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function formatDate(iso: string): string {
|
|
42
|
+
try {
|
|
43
|
+
return new Date(iso).toLocaleString();
|
|
44
|
+
} catch {
|
|
45
|
+
return iso;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The sessions, the current one first, each with a button that ends it. */
|
|
50
|
+
export function sessionTable(sessions: readonly SessionInfo[], options: { id: string; onRevoke(reference: string): unknown }): TemplateResult {
|
|
51
|
+
const iconBtn = 'inline-flex items-center justify-center [&_svg]:size-4';
|
|
52
|
+
const ordered = [...sessions.filter((s) => s.current), ...sessions.filter((s) => !s.current)];
|
|
53
|
+
const row = (s: SessionInfo) => {
|
|
54
|
+
const ua = parseUserAgent(s.userAgent);
|
|
55
|
+
const deviceLabel = ua.device === 'mobile' ? __('Mobile') : ua.device === 'tablet' ? __('Tablet') : __('Desktop');
|
|
56
|
+
const tip = `${options.id}-${encodeURIComponent(s.reference)}-agent-tip`;
|
|
57
|
+
return html`
|
|
58
|
+
<tr class="border-t border-border">
|
|
59
|
+
<td class="py-3 pr-4 text-sm text-foreground">
|
|
60
|
+
${s.userAgent
|
|
61
|
+
? component(Tooltip, { id: tip, label: `${deviceLabel} · ${ua.browser} · ${ua.os}` }, html`
|
|
62
|
+
<span tabindex="0" aria-describedby=${tip} class="inline-flex items-center gap-2 cursor-help">
|
|
63
|
+
<span class=${iconBtn}>${component(Icon, { entry: shellIcons()[ua.device], size: 16 })}</span>
|
|
64
|
+
<span>${ua.browser} · ${ua.os}</span>
|
|
65
|
+
</span>`)
|
|
66
|
+
: html`<span class="text-muted-foreground">${__('Unknown device')}</span>`}
|
|
67
|
+
</td>
|
|
68
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground">${formatDate(s.createdAt)}</td>
|
|
69
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground">${formatDate(s.expiresAt)}</td>
|
|
70
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground">${s.location ?? '—'}</td>
|
|
71
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground truncate max-w-[16rem]">${s.ipAddress ?? '—'}</td>
|
|
72
|
+
<td class="py-3 text-right">
|
|
73
|
+
${s.current
|
|
74
|
+
? component(Badge, {}, __('Current'))
|
|
75
|
+
: component(Button, { variant: 'destructive', size: 'sm', '@click': () => options.onRevoke(s.reference) }, __('Sign out'))}
|
|
76
|
+
</td>
|
|
77
|
+
</tr>
|
|
78
|
+
`;
|
|
79
|
+
};
|
|
80
|
+
return html`
|
|
81
|
+
<div class="overflow-x-auto">
|
|
82
|
+
<table class="w-full" id=${options.id}>
|
|
83
|
+
<thead>
|
|
84
|
+
<tr class="text-left text-xs uppercase tracking-wide text-muted-foreground">
|
|
85
|
+
<th class="py-2 pr-4 font-medium">${__('Device')}</th>
|
|
86
|
+
<th class="py-2 pr-4 font-medium">${__('Signed in')}</th>
|
|
87
|
+
<th class="py-2 pr-4 font-medium">${__('Expires')}</th>
|
|
88
|
+
<th class="py-2 pr-4 font-medium">${__('Location')}</th>
|
|
89
|
+
<th class="py-2 pr-4 font-medium">${__('IP')}</th>
|
|
90
|
+
<th class="py-2 text-right font-medium"><span class="sr-only">${__('Actions')}</span></th>
|
|
91
|
+
</tr>
|
|
92
|
+
</thead>
|
|
93
|
+
<tbody>${ordered.map(row)}</tbody>
|
|
94
|
+
</table>
|
|
95
|
+
</div>
|
|
96
|
+
${sessions.length === 0 ? html`<p class="py-6 text-center text-sm text-muted-foreground">${__('No active sessions.')}</p>` : null}
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getLocale } from '@cossackframework/core';
|
|
2
|
+
|
|
3
|
+
const UNITS: readonly (readonly [Intl.RelativeTimeFormatUnit, number])[] = [['year', 31_536_000], ['month', 2_592_000], ['week', 604_800], ['day', 86_400], ['hour', 3_600], ['minute', 60]];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A time relative to `now` in the active locale, such as "3 hours ago" or "yesterday".
|
|
7
|
+
* A page takes `now` once into its state, so its server render and the browser's agree.
|
|
8
|
+
*/
|
|
9
|
+
export function timeAgo(iso: string, now: number): string {
|
|
10
|
+
const time = Date.parse(iso);
|
|
11
|
+
if (Number.isNaN(time)) return iso;
|
|
12
|
+
const seconds = (time - now) / 1000;
|
|
13
|
+
const format = new Intl.RelativeTimeFormat(getLocale(), { numeric: 'auto' });
|
|
14
|
+
for (const [unit, size] of UNITS) if (Math.abs(seconds) >= size) return format.format(Math.trunc(seconds / size), unit);
|
|
15
|
+
return format.format(0, 'second');
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { IconEntry } from '@cossackframework/solar-icons/types';
|
|
2
|
+
|
|
3
|
+
export interface DashboardModuleLink {
|
|
4
|
+
label: string;
|
|
5
|
+
href: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface DashboardModule {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
href: string;
|
|
12
|
+
icon: IconEntry;
|
|
13
|
+
/** Who sees the module: any signed-in user, administrators, or holders of a permission. */
|
|
14
|
+
authorization: 'authenticated' | 'admin' | { permission: string };
|
|
15
|
+
placement?: 'navigation' | 'account';
|
|
16
|
+
children?: DashboardModuleLink[];
|
|
17
|
+
/** Another module whose menu lists this one's links, after its own, when the user sees both. */
|
|
18
|
+
parent?: string;
|
|
19
|
+
/** Highlighted on every page under this path, such as `/dashboard/settings` for screens with their own navigation. */
|
|
20
|
+
activeFor?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A screen of the project in the navigation (src/dashboard.config.ts: `navigation`): a module whose icon and authorization have defaults. */
|
|
24
|
+
export type DashboardNavigationItem = Omit<DashboardModule, 'icon' | 'authorization'> & Partial<Pick<DashboardModule, 'icon' | 'authorization'>>;
|
|
25
|
+
|
|
26
|
+
/** A status the dashboard's taskbar shows: what waits for the user, and where to go. */
|
|
27
|
+
export interface DashboardStatus {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
href: string;
|
|
31
|
+
/** How many, shown beside the label; omitted for a plain link. */
|
|
32
|
+
count?: number;
|
|
33
|
+
tone?: 'info' | 'warning' | 'error';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A message above every dashboard screen, such as one a CMS plugin returns. */
|
|
37
|
+
export interface DashboardNotice {
|
|
38
|
+
id: string;
|
|
39
|
+
tone: 'info' | 'success' | 'warning' | 'error';
|
|
40
|
+
message: string;
|
|
41
|
+
/** A same-site path the notice links to. */
|
|
42
|
+
href?: string;
|
|
43
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field groups attached to users, as meta boxes on the user screen's Profile tab, with their
|
|
3
|
+
* own Save and media chooser. The screen loads them with `userFields`; the boxes save through
|
|
4
|
+
* `POST /api/cms/users/<id>/meta`. Replaces the scaffold's empty module.
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from 'hono';
|
|
7
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
8
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
9
|
+
import { Button } from '@cossackframework/ui';
|
|
10
|
+
import { fieldVisibility, hasPermission, PERMISSIONS } from '@cossackframework/cms';
|
|
11
|
+
import { groupsView, metaFilePreviews, metaValues, type GroupsView } from '../cms/content';
|
|
12
|
+
import type { EditorField, EditorValues } from '../cms/editor';
|
|
13
|
+
import { fieldControl, type MediaHooks, type MediaPreview } from '../cms/field-controls';
|
|
14
|
+
import { FieldGroupView, plainBlocks, visibilityTypes, type RowPath } from '../cms/field-group-view';
|
|
15
|
+
import { closedChooser, mediaChooser, uploadMedia, withFile, type MediaChooserState } from '../cms/media-chooser';
|
|
16
|
+
import { box, notice } from '../cms/ui';
|
|
17
|
+
|
|
18
|
+
export interface UserFieldsData {
|
|
19
|
+
readonly view: GroupsView;
|
|
20
|
+
readonly values: EditorValues;
|
|
21
|
+
readonly previews: Record<string, MediaPreview>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The user's field groups and values, for people who manage users; null when no group is attached. */
|
|
25
|
+
export async function userFields(c: Context, userId: string): Promise<UserFieldsData | null> {
|
|
26
|
+
if (!hasPermission(c.get('principal'), PERMISSIONS.manageUsers)) return null;
|
|
27
|
+
const cms = c.get('cms');
|
|
28
|
+
const view = await groupsView(cms, { kind: 'users' });
|
|
29
|
+
if (!view.groups.length) return null;
|
|
30
|
+
const meta = (await cms.users.get(userId))?.meta ?? {};
|
|
31
|
+
return { view, values: metaValues(view.fields, meta), previews: await metaFilePreviews(cms, meta) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Where a chosen file goes: a meta field, through the rows it sits in. */
|
|
35
|
+
interface MetaTarget { field: string; rows: RowPath; key: string; multiple: boolean }
|
|
36
|
+
|
|
37
|
+
@Component()
|
|
38
|
+
export class UserFields extends Cossack {
|
|
39
|
+
declare props: { userId: string; data: UserFieldsData };
|
|
40
|
+
/** The values being edited; the loaded ones until the first change. */
|
|
41
|
+
@ClientState() private values: EditorValues | null = null;
|
|
42
|
+
@ClientState() private previews: Record<string, MediaPreview> = {};
|
|
43
|
+
@ClientState() private errors: Record<string, string> = {};
|
|
44
|
+
@ClientState() private message = '';
|
|
45
|
+
@ClientState() private error = '';
|
|
46
|
+
@ClientState() private saving = false;
|
|
47
|
+
@ClientState() private chooser: MediaChooserState = closedChooser();
|
|
48
|
+
private target: MetaTarget | null = null;
|
|
49
|
+
|
|
50
|
+
private get current(): EditorValues {
|
|
51
|
+
return this.values ?? this.props.data.values;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Client()
|
|
55
|
+
private set(name: string, value: unknown) {
|
|
56
|
+
this.values = { ...this.current, [name]: value };
|
|
57
|
+
if (this.errors[name]) this.errors = Object.fromEntries(Object.entries(this.errors).filter(([key]) => key !== name));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Set a row's field through the rows above it. */
|
|
61
|
+
@Client()
|
|
62
|
+
private setRowValue(field: string, rows: RowPath, key: string, value: unknown) {
|
|
63
|
+
const update = (list: unknown, depth: number): unknown => (Array.isArray(list) ? list as Record<string, unknown>[] : []).map(entry => {
|
|
64
|
+
const row = rows[depth]!;
|
|
65
|
+
if (entry._id !== row.id) return entry;
|
|
66
|
+
return depth === rows.length - 1 ? { ...entry, [key]: value } : { ...entry, [rows[depth + 1]!.field]: update(entry[rows[depth + 1]!.field], depth + 1) };
|
|
67
|
+
});
|
|
68
|
+
this.set(field, update(this.current[field], 0));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Client()
|
|
72
|
+
private rowValue(field: string, rows: RowPath, key: string): unknown {
|
|
73
|
+
let value: unknown = this.current[field];
|
|
74
|
+
for (const [index, row] of rows.entries()) {
|
|
75
|
+
const found = (Array.isArray(value) ? value as Record<string, unknown>[] : []).find(entry => entry._id === row.id);
|
|
76
|
+
if (!found) return undefined;
|
|
77
|
+
value = index === rows.length - 1 ? found[key] : found[rows[index + 1]!.field];
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- Media --------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
@Client()
|
|
85
|
+
private async searchMedia(search: string) {
|
|
86
|
+
const query = new URLSearchParams({ q: search, kind: this.chooser.kind });
|
|
87
|
+
const response = await fetch(`/api/cms/media?${query}`).catch(() => null);
|
|
88
|
+
const items = response?.ok ? (await response.json() as { items: MediaPreview[] }).items : [];
|
|
89
|
+
this.chooser = { ...this.chooser, search, items };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Client()
|
|
93
|
+
private async filterMedia(kind: string) {
|
|
94
|
+
this.chooser = { ...this.chooser, kind };
|
|
95
|
+
await this.searchMedia(this.chooser.search);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Client()
|
|
99
|
+
private async openChooser(target: MetaTarget) {
|
|
100
|
+
this.target = target;
|
|
101
|
+
this.chooser = { ...this.chooser, open: true, error: '', field: target.key, multiple: target.multiple, kind: 'image' };
|
|
102
|
+
await this.searchMedia(this.chooser.search);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Client()
|
|
106
|
+
private chooseFile(file: MediaPreview) {
|
|
107
|
+
const target = this.target;
|
|
108
|
+
if (!target) return;
|
|
109
|
+
this.previews = { ...this.previews, [file.id]: file };
|
|
110
|
+
const current = target.rows.length ? this.rowValue(target.field, target.rows, target.key) : this.current[target.field];
|
|
111
|
+
const next = withFile(current, file.id, target.multiple);
|
|
112
|
+
if (target.rows.length) this.setRowValue(target.field, target.rows, target.key, next); else this.set(target.field, next);
|
|
113
|
+
if (!target.multiple) this.chooser = { ...this.chooser, open: false };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Client()
|
|
117
|
+
private async uploadFile(event: Event) {
|
|
118
|
+
const { files, error } = await uploadMedia(event.currentTarget as HTMLInputElement);
|
|
119
|
+
this.chooser = { ...this.chooser, error };
|
|
120
|
+
for (const file of files) this.chooseFile(file);
|
|
121
|
+
await this.searchMedia('');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// --- Saving -------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
@Client()
|
|
127
|
+
private async save(event: Event) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
this.saving = true;
|
|
130
|
+
this.message = '';
|
|
131
|
+
this.error = '';
|
|
132
|
+
try {
|
|
133
|
+
const response = await fetch(`/api/cms/users/${encodeURIComponent(this.props.userId)}/meta`, {
|
|
134
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ meta: this.current }),
|
|
135
|
+
});
|
|
136
|
+
const result = await response.json().catch(() => ({})) as { values?: EditorValues; error?: string; fields?: Record<string, string> };
|
|
137
|
+
if (!response.ok) { this.errors = result.fields ?? {}; this.error = result.error ?? __('The fields could not be saved.'); return; }
|
|
138
|
+
this.errors = {};
|
|
139
|
+
this.values = result.values ?? this.current;
|
|
140
|
+
this.message = __('Fields saved.');
|
|
141
|
+
} catch { this.error = __('The fields could not be saved.'); }
|
|
142
|
+
finally { this.saving = false; }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// --- Rendering ----------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
private control(field: EditorField, value: unknown, change: (value: unknown) => void, rows: RowPath, id: string): TemplateResult | null {
|
|
148
|
+
const root = rows[0]?.field ?? field.name;
|
|
149
|
+
const media: MediaHooks = { previews: { ...this.props.data.previews, ...this.previews }, choose: multiple => this.openChooser({ field: root, rows, key: field.name, multiple }) };
|
|
150
|
+
return fieldControl(field, value, change, id, { media });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
render() {
|
|
154
|
+
const { groups, fields, options } = this.props.data.view;
|
|
155
|
+
const values = this.current;
|
|
156
|
+
const hidden = fieldVisibility(plainBlocks(groups.flatMap(group => group.blocks)), visibilityTypes(options), values).hidden;
|
|
157
|
+
return html`<form class="space-y-4" data-user-fields @submit=${(event: Event) => this.save(event)}>
|
|
158
|
+
${this.message && !this.error ? notice(this.message, 'success') : null}
|
|
159
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
160
|
+
${groups.map(group => box(group.title, html`
|
|
161
|
+
${group.description ? html`<p class="text-xs text-muted-foreground">${group.description}</p>` : null}
|
|
162
|
+
${component(FieldGroupView, {
|
|
163
|
+
id: `group-${group.id}`, blocks: group.blocks, options, fields, values, hidden, errors: this.errors,
|
|
164
|
+
onChange: (name: string, value: unknown) => this.set(name, value),
|
|
165
|
+
control: (field: EditorField, value: unknown, change: (value: unknown) => void, rows: RowPath, id: string) => this.control(field, value, change, rows, id),
|
|
166
|
+
})}`, { id: `group-${group.id}-title` }))}
|
|
167
|
+
<div>${component(Button, { type: 'submit', variant: 'outline', disabled: this.saving }, this.saving ? __('Saving…') : __('Save fields'))}</div>
|
|
168
|
+
${mediaChooser(this.chooser, { search: text => this.searchMedia(text), filter: kind => this.filterMedia(kind), choose: file => this.chooseFile(file),
|
|
169
|
+
upload: event => this.uploadFile(event), close: () => { this.chooser = { ...this.chooser, open: false }; } })}
|
|
170
|
+
</form>`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/lib/permissions.ts
|
|
2
|
+
//
|
|
3
|
+
// Permissions the Roles screen offers. CMS permissions are patterns: `*` grants everything,
|
|
4
|
+
// `cms/*` every collection, and `cms/posts:update` one action on one collection. Collections
|
|
5
|
+
// made in the dashboard are covered by `cms/*` and their own `cms/<name>:<action>`.
|
|
6
|
+
|
|
7
|
+
export const PERMISSIONS = [
|
|
8
|
+
'*',
|
|
9
|
+
'cms:dashboard',
|
|
10
|
+
'cms:users',
|
|
11
|
+
'cms:roles',
|
|
12
|
+
'cms:appearance',
|
|
13
|
+
'cms:settings',
|
|
14
|
+
'cms:collections',
|
|
15
|
+
'cms:plugins',
|
|
16
|
+
'cms:schema',
|
|
17
|
+
'cms:terms',
|
|
18
|
+
'cms:media',
|
|
19
|
+
'cms:upload',
|
|
20
|
+
'cms:comments',
|
|
21
|
+
'cms:redirects',
|
|
22
|
+
'cms:webhooks',
|
|
23
|
+
'cms:updates',
|
|
24
|
+
'cms:submissions',
|
|
25
|
+
'cms:html',
|
|
26
|
+
'cms/*',
|
|
27
|
+
'cms/posts:read',
|
|
28
|
+
'cms/posts:create',
|
|
29
|
+
'cms/posts:update',
|
|
30
|
+
'cms/posts:delete',
|
|
31
|
+
'cms/pages:read',
|
|
32
|
+
'cms/pages:create',
|
|
33
|
+
'cms/pages:update',
|
|
34
|
+
'cms/pages:delete',
|
|
35
|
+
'cms/patterns:read',
|
|
36
|
+
'cms/patterns:create',
|
|
37
|
+
'cms/patterns:update',
|
|
38
|
+
'cms/patterns:delete',
|
|
39
|
+
'app/*',
|
|
40
|
+
] as const;
|
|
41
|
+
|
|
42
|
+
export type Permission = (typeof PERMISSIONS)[number] | (string & {});
|
|
43
|
+
|
|
44
|
+
export const ALL_PERMISSIONS: Permission[] = ['*'];
|
|
45
|
+
|
|
46
|
+
const LABELS: Record<string, string> = {
|
|
47
|
+
'*': 'Everything (administrator)',
|
|
48
|
+
'cms:dashboard': 'Use the content dashboard',
|
|
49
|
+
'cms:users': 'Manage users',
|
|
50
|
+
'cms:roles': 'Define roles and choose users’ roles',
|
|
51
|
+
'cms:appearance': 'Choose the theme and edit menus',
|
|
52
|
+
'cms:settings': 'Change site settings',
|
|
53
|
+
'cms:collections': 'Define collections, fields and taxonomies',
|
|
54
|
+
'cms:plugins': 'Enable and disable plugins',
|
|
55
|
+
'cms:schema': 'Apply schema migrations',
|
|
56
|
+
'cms:terms': 'Manage categories, tags and other terms',
|
|
57
|
+
'cms:media': 'Edit and delete anyone\'s media',
|
|
58
|
+
'cms:upload': 'Upload media',
|
|
59
|
+
'cms:comments': 'Moderate comments',
|
|
60
|
+
'cms:redirects': 'Manage redirects',
|
|
61
|
+
'cms:webhooks': 'Manage webhooks',
|
|
62
|
+
'cms:updates': 'See update notices and request an update of the site',
|
|
63
|
+
'cms:submissions': 'Read and handle form submissions',
|
|
64
|
+
'cms:html': 'Add and change Custom HTML blocks, which run as written on the site',
|
|
65
|
+
'cms/*': 'Read and edit every collection, including others\' entries',
|
|
66
|
+
'cms/posts:read': 'Read draft posts',
|
|
67
|
+
'cms/posts:create': 'Write posts',
|
|
68
|
+
'cms/posts:update': 'Edit others\' posts',
|
|
69
|
+
'cms/posts:delete': 'Delete others\' posts',
|
|
70
|
+
'cms/pages:read': 'Read draft pages',
|
|
71
|
+
'cms/pages:create': 'Create pages',
|
|
72
|
+
'cms/pages:update': 'Edit pages',
|
|
73
|
+
'cms/pages:delete': 'Delete pages',
|
|
74
|
+
'cms/patterns:read': 'See patterns',
|
|
75
|
+
'cms/patterns:create': 'Create patterns',
|
|
76
|
+
'cms/patterns:update': 'Edit patterns',
|
|
77
|
+
'cms/patterns:delete': 'Delete patterns',
|
|
78
|
+
'app/*': 'Every application resource',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** A readable name for a permission, with the permission itself for unknown ones. */
|
|
82
|
+
export function permissionLabel(permission: string): string {
|
|
83
|
+
return LABELS[permission] ?? permission;
|
|
84
|
+
}
|