@cossackframework/cms 0.0.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +114 -2
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { Alert, Badge, Button, Card, CardBody, CardHeader, Field, Input } from '@cossackframework/ui';
|
|
4
|
+
import { notice, pageHeader } from '@cossackframework/ui/blocks';
|
|
5
|
+
import { html, component, unsafeHTML, type TemplateResult } from '@cossackframework/renderer';
|
|
6
|
+
import {
|
|
7
|
+
addPasskey, apiTokensAvailable, confirmAuthenticator, createApiToken, disableAuthenticator, listApiTokens, newRecoveryCodes, passkeyRegistration,
|
|
8
|
+
removePasskey, revokeApiToken, securityStatus, startAuthenticator, twoFactorAvailable, type ApiToken, type PublicUser, type SecurityStatus,
|
|
9
|
+
} from '#app/auth';
|
|
10
|
+
import { createPasskey } from '#app/passkeys.client';
|
|
11
|
+
import { AppPasswords } from '#app/dashboard/app-passwords';
|
|
12
|
+
|
|
13
|
+
const date = (value: number | null) => value ? new Date(value).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : '—';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Account security: two-step sign-in with an authenticator app (and recovery codes),
|
|
17
|
+
* passkeys, and application passwords for apps and scripts that use the content API.
|
|
18
|
+
*/
|
|
19
|
+
@Page({ transport: 'http' })
|
|
20
|
+
export default class SecurityPage extends Cossack {
|
|
21
|
+
@State() available = false;
|
|
22
|
+
@State() tokensAvailable = false;
|
|
23
|
+
@State() status: SecurityStatus = { totp: false, recoveryCodes: 0, passkeys: [] };
|
|
24
|
+
@State() setup: { secret: string; uri: string; qr: string } | null = null;
|
|
25
|
+
@State() code = '';
|
|
26
|
+
@State() recoveryCodes: string[] = [];
|
|
27
|
+
@State() passkeyName = '';
|
|
28
|
+
@State() tokens: ApiToken[] = [];
|
|
29
|
+
@State() newToken = '';
|
|
30
|
+
@State() required = false;
|
|
31
|
+
@State() recovered = false;
|
|
32
|
+
@State() error = '';
|
|
33
|
+
/** What the last action did, beside the errors. */
|
|
34
|
+
@State() message = '';
|
|
35
|
+
|
|
36
|
+
head(): HeadValue {
|
|
37
|
+
return { title: __('Security') };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async init() {
|
|
41
|
+
this.available = twoFactorAvailable;
|
|
42
|
+
this.tokensAvailable = apiTokensAvailable;
|
|
43
|
+
this.required = this.c.req.query('required') === '1';
|
|
44
|
+
this.recovered = this.c.req.query('recovered') === '1';
|
|
45
|
+
await this.load();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private async load() {
|
|
49
|
+
const user = this.user as PublicUser | undefined;
|
|
50
|
+
if (!user) return;
|
|
51
|
+
this.status = await securityStatus(user.id);
|
|
52
|
+
this.tokens = await listApiTokens(user.id);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// --- Authenticator app -------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
@Server()
|
|
58
|
+
async beginSetup() {
|
|
59
|
+
this.error = '';
|
|
60
|
+
this.recoveryCodes = [];
|
|
61
|
+
try { this.setup = await startAuthenticator(this.user as PublicUser); }
|
|
62
|
+
catch (error) { this.error = (error as Error).message; }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Server()
|
|
66
|
+
async finishSetup(code: string) {
|
|
67
|
+
this.error = '';
|
|
68
|
+
try {
|
|
69
|
+
this.recoveryCodes = await confirmAuthenticator(this.user!.id, code);
|
|
70
|
+
this.setup = null;
|
|
71
|
+
this.code = '';
|
|
72
|
+
await this.load();
|
|
73
|
+
} catch (error) { this.error = (error as Error).message; }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Server()
|
|
77
|
+
async turnOff(code: string) {
|
|
78
|
+
this.error = '';
|
|
79
|
+
try {
|
|
80
|
+
await disableAuthenticator(this.user!.id, code);
|
|
81
|
+
this.code = '';
|
|
82
|
+
this.recoveryCodes = [];
|
|
83
|
+
await this.load();
|
|
84
|
+
} catch (error) { this.error = (error as Error).message; }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Server()
|
|
88
|
+
async regenerate(code: string) {
|
|
89
|
+
this.error = '';
|
|
90
|
+
try {
|
|
91
|
+
this.recoveryCodes = await newRecoveryCodes(this.user!.id, code);
|
|
92
|
+
this.code = '';
|
|
93
|
+
await this.load();
|
|
94
|
+
} catch (error) { this.error = (error as Error).message; }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Client()
|
|
98
|
+
async copyCodes() {
|
|
99
|
+
this.error = '';
|
|
100
|
+
try { await navigator.clipboard.writeText(this.recoveryCodes.join('\n')); this.message = __('Recovery codes copied.'); }
|
|
101
|
+
catch { this.message = ''; this.error = __('Copy the codes from the list.'); }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// --- Passkeys ------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
@Client()
|
|
107
|
+
async addPasskey() {
|
|
108
|
+
this.error = '';
|
|
109
|
+
this.message = '';
|
|
110
|
+
try {
|
|
111
|
+
const { challenge, options } = await this.passkeyOptions();
|
|
112
|
+
const response = await createPasskey(options);
|
|
113
|
+
await this.savePasskey(challenge, response, this.passkeyName || navigatorName());
|
|
114
|
+
if (!this.error) { this.passkeyName = ''; this.message = __('Passkey added.'); }
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if ((error as Error)?.name === 'NotAllowedError') return;
|
|
117
|
+
this.error = (error as Error)?.message || __('The passkey could not be added.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Server()
|
|
122
|
+
async passkeyOptions() {
|
|
123
|
+
return passkeyRegistration(this.c, this.user as PublicUser);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Server()
|
|
127
|
+
async savePasskey(challenge: string, response: unknown, name: string) {
|
|
128
|
+
this.error = '';
|
|
129
|
+
try {
|
|
130
|
+
await addPasskey(this.c, this.user as PublicUser, challenge, response as never, name);
|
|
131
|
+
await this.load();
|
|
132
|
+
} catch (error) { this.error = (error as Error).message; }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 })) })
|
|
136
|
+
async deletePasskey(id: string) {
|
|
137
|
+
await removePasskey(this.user!.id, id);
|
|
138
|
+
await this.load();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// --- Application passwords -----------------------------------------------------
|
|
142
|
+
|
|
143
|
+
/** Returns whether the password was created; the form keeps its values otherwise. */
|
|
144
|
+
@Server()
|
|
145
|
+
async addToken(name: string, scope: 'read' | 'write', expiresInDays: number): Promise<boolean> {
|
|
146
|
+
this.error = '';
|
|
147
|
+
try {
|
|
148
|
+
this.newToken = await createApiToken(this.user!.id, name, scope === 'read' ? 'read' : 'write', expiresInDays);
|
|
149
|
+
await this.load();
|
|
150
|
+
return true;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
this.error = (error as Error).message;
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Server()
|
|
158
|
+
async deleteToken(id: string) {
|
|
159
|
+
await revokeApiToken(this.user!.id, id);
|
|
160
|
+
await this.load();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The passkeys, added and removed here, or listed with a link to the host that keeps them. */
|
|
164
|
+
private passkeys(): TemplateResult {
|
|
165
|
+
const elsewhere = this.status.passkeysManagedAt;
|
|
166
|
+
const list = this.status.passkeys.length ? html`<ul class="divide-y divide-border rounded-md border border-border">${this.status.passkeys.map(passkey => html`<li class="flex flex-wrap items-center justify-between gap-2 px-3 py-2 text-sm">
|
|
167
|
+
<span><span class="font-medium text-foreground">${passkey.name}</span> <span class="text-xs text-muted-foreground">· ${__('added')} ${date(passkey.createdAt)} · ${__('last used')} ${date(passkey.lastUsedAt)}${passkey.backedUp ? ` · ${__('synced')}` : ''}</span></span>
|
|
168
|
+
${elsewhere ? null : html`<button type="button" class="text-xs text-destructive hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.deletePasskey(passkey.id)}>${__('Remove')}</button>`}
|
|
169
|
+
</li>`)}</ul>` : html`<p class="text-sm text-muted-foreground">${__('No passkeys yet.')}</p>`;
|
|
170
|
+
if (elsewhere) return html`${list}
|
|
171
|
+
<p class="text-sm text-muted-foreground" data-passkeys-elsewhere>${__('Your passkeys sign you in on :site. Add or remove them there.', { site: elsewhere.name })}
|
|
172
|
+
${elsewhere.href ? html`<a href=${elsewhere.href} class="font-medium text-foreground underline">${__('Manage passkeys on :site', { site: elsewhere.name })}</a>` : null}</p>`;
|
|
173
|
+
return html`${list}
|
|
174
|
+
<div class="flex flex-wrap items-end gap-2">
|
|
175
|
+
${component(Field, { label: __('Name'), for: 'passkey-name', control: attributes => component(Input, { ...attributes, maxlength: 80, placeholder: __('Such as Work laptop'),
|
|
176
|
+
'.value': this.passkeyName, '@input': (event: Event) => { this.passkeyName = (event.target as HTMLInputElement).value; } }) })}
|
|
177
|
+
${component(Button, { type: 'button', variant: 'outline', '@click': () => this.addPasskey() }, __('Add a passkey'))}
|
|
178
|
+
</div>`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private authenticator(): TemplateResult {
|
|
182
|
+
const codeInput = (id: string) => component(Input, { id, autocomplete: 'one-time-code', inputmode: 'numeric', maxlength: 20, placeholder: '123456', class: 'max-w-40',
|
|
183
|
+
'.value': this.code, '@input': (event: Event) => { this.code = (event.target as HTMLInputElement).value; } });
|
|
184
|
+
if (this.setup) return html`<div class="space-y-4">
|
|
185
|
+
<ol class="list-decimal space-y-1 pl-5 text-sm text-foreground">
|
|
186
|
+
<li>${__('Scan this code with an authenticator app, such as 1Password, Google Authenticator or Microsoft Authenticator.')}</li>
|
|
187
|
+
<li>${__('Enter the 6-digit code the app shows.')}</li>
|
|
188
|
+
</ol>
|
|
189
|
+
<div class="flex flex-wrap items-start gap-6">
|
|
190
|
+
<div class="size-44 rounded-md border border-border bg-white p-2 text-black [&_svg]:h-full [&_svg]:w-full" role="img" aria-label=${__('QR code for the authenticator app')}>${unsafeHTML(this.setup.qr)}</div>
|
|
191
|
+
<div class="space-y-2 text-sm">
|
|
192
|
+
<p class="text-muted-foreground">${__('Cannot scan? Enter this key:')}</p>
|
|
193
|
+
<code class="block break-all rounded bg-muted px-2 py-1 text-xs" data-totp-secret>${this.setup.secret}</code>
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
<form class="flex flex-wrap items-end gap-2" @submit=${(event: Event) => { event.preventDefault(); void this.finishSetup(this.code); }}>
|
|
197
|
+
${component(Field, { label: __('Code'), for: 'totp-confirm', control: () => codeInput('totp-confirm') })}
|
|
198
|
+
${component(Button, { type: 'submit', disabled: !this.code.trim() }, __('Turn on'))}
|
|
199
|
+
${component(Button, { type: 'button', variant: 'ghost', '@click': () => { this.setup = null; } }, __('Cancel'))}
|
|
200
|
+
</form>
|
|
201
|
+
</div>`;
|
|
202
|
+
if (!this.status.totp) return html`<div class="space-y-3">
|
|
203
|
+
<p class="text-sm text-muted-foreground">${__('After your password, sign-in asks for a code from an app on your phone, so a stolen password is not enough.')}</p>
|
|
204
|
+
${component(Button, { type: 'button', '@click': () => this.beginSetup() }, __('Set up an authenticator app'))}
|
|
205
|
+
</div>`;
|
|
206
|
+
return html`<div class="space-y-4">
|
|
207
|
+
<p class="flex items-center gap-2 text-sm text-foreground">${component(Badge, { variant: 'success' }, __('On'))} ${__('Sign-in asks for a code from your authenticator app.')}</p>
|
|
208
|
+
<p class="text-sm text-muted-foreground">${this.status.recoveryCodes} ${__('recovery codes left. Each works once, when you do not have your phone.')}</p>
|
|
209
|
+
<form class="flex flex-wrap items-end gap-2" @submit=${(event: Event) => event.preventDefault()}>
|
|
210
|
+
${component(Field, { label: __('Current code'), for: 'totp-current', control: () => codeInput('totp-current') })}
|
|
211
|
+
${component(Button, { type: 'button', variant: 'outline', disabled: !this.code.trim(), '@click': () => this.regenerate(this.code) }, __('New recovery codes'))}
|
|
212
|
+
${component(Button, { type: 'button', variant: 'destructive', disabled: !this.code.trim(), '@click': () => this.turnOff(this.code) }, __('Turn off'))}
|
|
213
|
+
<p class="w-full text-xs text-muted-foreground">${__('From the app, or a recovery code.')}</p>
|
|
214
|
+
</form>
|
|
215
|
+
</div>`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
render() {
|
|
219
|
+
if (!this.available && !this.tokensAvailable) return html`<div class="max-w-2xl space-y-4">
|
|
220
|
+
<h1 class="text-2xl font-bold text-foreground">${__('Security')}</h1>
|
|
221
|
+
<p class="text-sm text-muted-foreground">${__('This site signs in with passwords. Two-step sign-in and passkeys come with the CMS auth store.')}</p>
|
|
222
|
+
</div>`;
|
|
223
|
+
return html`<div class="max-w-3xl space-y-6">
|
|
224
|
+
${pageHeader(__('Security'), { description: __('Protect your account, and connect apps to the content API.'),
|
|
225
|
+
actions: html`<a href="/dashboard/profile" class="text-sm text-muted-foreground hover:text-foreground">← ${__('Profile')}</a>` })}
|
|
226
|
+
${this.required ? component(Alert, { variant: 'warning' }, this.status.totp || this.status.passkeys.length
|
|
227
|
+
? __('This site requires two-step sign-in, and this session signed in without it. Sign out, then sign in again with your authenticator app or passkey.')
|
|
228
|
+
: __('This site requires two-step sign-in. Add an authenticator app or a passkey to continue.')) : null}
|
|
229
|
+
${this.recovered ? component(Alert, { variant: 'warning' }, __('You signed in with a recovery code. If you lost your phone, turn the authenticator off and set it up again.')) : null}
|
|
230
|
+
${this.message && !this.error ? notice(this.message, 'success') : null}
|
|
231
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
232
|
+
${this.recoveryCodes.length ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Your recovery codes')}</h2>`)}
|
|
233
|
+
${component(CardBody, { class: 'space-y-3' }, html`<p class="text-sm text-muted-foreground">${__('Save them somewhere safe. They are shown only now; each signs you in once without your phone.')}</p>
|
|
234
|
+
<ul class="grid grid-cols-2 gap-1 font-mono text-sm sm:grid-cols-5" data-recovery-codes>${this.recoveryCodes.map(code => html`<li class="rounded bg-muted px-2 py-1 text-center">${code}</li>`)}</ul>
|
|
235
|
+
${component(Button, { type: 'button', variant: 'outline', size: 'sm', '@click': () => this.copyCodes() }, __('Copy'))}`)}`) : null}
|
|
236
|
+
${this.available ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Two-step sign-in')}</h2>`)}
|
|
237
|
+
${component(CardBody, {}, this.authenticator())}`) : null}
|
|
238
|
+
${this.available ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Passkeys')}</h2>
|
|
239
|
+
<p class="text-sm text-muted-foreground">${__('Sign in with your fingerprint, face or device PIN instead of a password. Passkeys cannot be phished.')}</p>`)}
|
|
240
|
+
${component(CardBody, { class: 'space-y-4' }, this.passkeys())}`) : null}
|
|
241
|
+
${this.tokensAvailable ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Application passwords')}</h2>
|
|
242
|
+
<p class="text-sm text-muted-foreground">${__('Let apps and scripts use the content API as you: send the password as Authorization: Bearer. Revoke one to cut off its app.')}</p>`)}
|
|
243
|
+
${component(CardBody, {}, component(AppPasswords, { tokens: this.tokens, newToken: this.newToken,
|
|
244
|
+
onAdd: (name: string, scope: 'read' | 'write', expiresInDays: number) => this.addToken(name, scope, expiresInDays), onRevoke: (id: string) => this.deleteToken(id) }))}`) : null}
|
|
245
|
+
</div>`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** A default passkey name from the browser, such as `Chrome on macOS`. */
|
|
250
|
+
function navigatorName(): string {
|
|
251
|
+
const agent = navigator.userAgent;
|
|
252
|
+
const browser = /Edg\//.test(agent) ? 'Edge' : /Firefox\//.test(agent) ? 'Firefox' : /Chrome\//.test(agent) ? 'Chrome' : /Safari\//.test(agent) ? 'Safari' : 'Browser';
|
|
253
|
+
const system = /Mac OS X/.test(agent) ? 'macOS' : /Windows/.test(agent) ? 'Windows' : /Android/.test(agent) ? 'Android' : /iPhone|iPad/.test(agent) ? 'iOS' : /Linux/.test(agent) ? 'Linux' : '';
|
|
254
|
+
return system ? `${browser} on ${system}` : browser;
|
|
255
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ClientVisibleError, Cossack, Page, State, Store, Validate, Client, Server, storeRules } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { Card, CardBody, CardHeader, Field, Input, Button, Checkbox, Form } from '@cossackframework/ui';
|
|
4
|
+
import { linkButton, notice, pageHeader } from '@cossackframework/ui/blocks';
|
|
5
|
+
import { html, component, bind } from '@cossackframework/renderer';
|
|
6
|
+
import { requireRoleManager } from '#app/services/rbac';
|
|
7
|
+
import { getRole, updateRole, type RoleDetail } from '#app/services/roles';
|
|
8
|
+
import { PERMISSIONS, permissionLabel, type Permission } from '#app/lib/permissions';
|
|
9
|
+
|
|
10
|
+
@Page({ transport: 'http', middlewares: [requireRoleManager] })
|
|
11
|
+
export default class EditRolePage extends Cossack {
|
|
12
|
+
@Store()
|
|
13
|
+
@Validate({
|
|
14
|
+
rules: storeRules<RoleDetail>({
|
|
15
|
+
name: { required: true, message: 'Name is required' },
|
|
16
|
+
}),
|
|
17
|
+
config: { trigger: 'all', runOn: 'both' }
|
|
18
|
+
})
|
|
19
|
+
role: RoleDetail | null = null;
|
|
20
|
+
|
|
21
|
+
@State() selected: Permission[] = [];
|
|
22
|
+
@State() saved = false;
|
|
23
|
+
@State() error = '';
|
|
24
|
+
|
|
25
|
+
@Server()
|
|
26
|
+
async init() {
|
|
27
|
+
const id = this.c.req.param('id')!;
|
|
28
|
+
const role = await getRole(id);
|
|
29
|
+
if (!role) {
|
|
30
|
+
this.error = __('Role not found');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.role = role;
|
|
34
|
+
this.selected = role.permissions as Permission[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Client()
|
|
38
|
+
togglePermission(perm: Permission, checked: boolean) {
|
|
39
|
+
this.selected = checked
|
|
40
|
+
? [...this.selected, perm]
|
|
41
|
+
: this.selected.filter((p) => p !== perm);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Client()
|
|
45
|
+
async handleSubmit(event: Event) {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
this.error = '';
|
|
48
|
+
this.saved = false;
|
|
49
|
+
const ok = await this.validateAll();
|
|
50
|
+
if (!ok) return;
|
|
51
|
+
|
|
52
|
+
if (!this.role) return;
|
|
53
|
+
try {
|
|
54
|
+
await this.save(this.role.name, this.selected);
|
|
55
|
+
this.saved = true;
|
|
56
|
+
} catch (e: any) {
|
|
57
|
+
this.error = e?.message || __('Could not save role');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 }), input.array(input.string({ maxLength: 200 }), { maxItems: 1000 })) })
|
|
62
|
+
async save(name: string, permissions: string[]) {
|
|
63
|
+
// The role the URL names, never one the client's state names.
|
|
64
|
+
const role = await getRole(this.c.req.param('id') ?? '');
|
|
65
|
+
if (!role) throw new ClientVisibleError(__('Role not found'));
|
|
66
|
+
// The roles service checks each permission (and that the actor holds it) before saving.
|
|
67
|
+
await updateRole(role.id, { name, permissions: permissions as Permission[] });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
render() {
|
|
71
|
+
if (!this.role && !this.error) return html`<div class="text-sm text-muted-foreground">${__('Loading…')}</div>`;
|
|
72
|
+
if (!this.role) return notice(this.error, 'error');
|
|
73
|
+
|
|
74
|
+
return html`
|
|
75
|
+
<div class="max-w-2xl space-y-6">
|
|
76
|
+
${pageHeader(this.role.name, { description: __('Edit the role and its permissions.') })}
|
|
77
|
+
${this.saved && !this.error ? notice(__('Saved.'), 'success') : null}
|
|
78
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
79
|
+
|
|
80
|
+
${component(Card, {}, html`
|
|
81
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Details')}</h2>`)}
|
|
82
|
+
${component(CardBody, {}, html`
|
|
83
|
+
${component(Form, {
|
|
84
|
+
submit: (e: Event) => this.handleSubmit(e),
|
|
85
|
+
}, html`
|
|
86
|
+
<div class="flex flex-col space-y-4">
|
|
87
|
+
${component(Field, { label: __('Name'), for: 'name', error: this.getError('name'),
|
|
88
|
+
control: attributes => component(Input, { ...attributes, type: 'text', '.value': bind(this.role, 'name') }) })}
|
|
89
|
+
|
|
90
|
+
<div>
|
|
91
|
+
<p class="text-sm font-medium text-foreground mb-2">${__('Permissions')}</p>
|
|
92
|
+
<div class="space-y-2">
|
|
93
|
+
${PERMISSIONS.map((perm) => html`
|
|
94
|
+
<div class="[&_.cs-checkbox]:items-start [&_.cs-checkbox>input]:mt-0.5">${component(Checkbox, {
|
|
95
|
+
checked: this.selected.includes(perm),
|
|
96
|
+
'@change': (e: any) => this.togglePermission(perm, e.target.checked),
|
|
97
|
+
}, html`<span>
|
|
98
|
+
<span class="block text-sm text-foreground">${__(permissionLabel(perm))}</span>
|
|
99
|
+
<span class="block text-xs text-muted-foreground font-mono">${perm}</span>
|
|
100
|
+
</span>`)}</div>
|
|
101
|
+
`)}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div class="flex items-center gap-2">
|
|
106
|
+
${component(Button, { type: 'submit' }, __('Save changes'))}
|
|
107
|
+
${linkButton(__('Back'), '/dashboard/roles', 'outline')}
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
`)}
|
|
111
|
+
`)}
|
|
112
|
+
`)}
|
|
113
|
+
</div>
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Cossack, Page, State, Server, Client } from '@cossackframework/core';
|
|
2
|
+
import { AlertDialog } from '@cossackframework/ui';
|
|
3
|
+
import { html, component } from '@cossackframework/renderer';
|
|
4
|
+
import { requireRoleManager } from '#app/services/rbac';
|
|
5
|
+
import { listFilters, listFooter, listTable, rowActions } from '#app/dashboard/list-table';
|
|
6
|
+
import { linkButton, notice, pageHeader } from '@cossackframework/ui/blocks';
|
|
7
|
+
import {
|
|
8
|
+
listRoles,
|
|
9
|
+
deleteRole,
|
|
10
|
+
type RoleDetail,
|
|
11
|
+
type ListRolesResult,
|
|
12
|
+
} from '#app/services/roles';
|
|
13
|
+
|
|
14
|
+
const PAGE_SIZE = 20;
|
|
15
|
+
|
|
16
|
+
@Page({ transport: 'http', middlewares: [requireRoleManager] })
|
|
17
|
+
export default class RolesPage extends Cossack {
|
|
18
|
+
@State() roles: RoleDetail[] = [];
|
|
19
|
+
@State() total = 0;
|
|
20
|
+
@State() page = 1;
|
|
21
|
+
@State() appliedSearch = '';
|
|
22
|
+
@State() error = '';
|
|
23
|
+
@State() message = '';
|
|
24
|
+
/** Role pending deletion confirmation (null = dialog closed). */
|
|
25
|
+
@State() pendingDelete: RoleDetail | null = null;
|
|
26
|
+
|
|
27
|
+
@Server()
|
|
28
|
+
async init() {
|
|
29
|
+
// Drive initial state from the URL so the search/page are bookmarkable
|
|
30
|
+
// and shareable (the search form is a native GET, pagination is links).
|
|
31
|
+
const search = this.c.req.query('search')?.trim() ?? '';
|
|
32
|
+
const pageParam = Number(this.c.req.query('page'));
|
|
33
|
+
this.appliedSearch = search;
|
|
34
|
+
this.page = pageParam >= 1 ? pageParam : 1;
|
|
35
|
+
this.applyResult(await this.query());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private async query(): Promise<ListRolesResult> {
|
|
39
|
+
return listRoles({
|
|
40
|
+
search: this.appliedSearch || undefined,
|
|
41
|
+
page: this.page,
|
|
42
|
+
pageSize: PAGE_SIZE,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private applyResult(result: ListRolesResult) {
|
|
47
|
+
this.roles = result.items;
|
|
48
|
+
this.total = result.total;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Server()
|
|
52
|
+
async remove(id: string) {
|
|
53
|
+
this.message = '';
|
|
54
|
+
this.error = '';
|
|
55
|
+
try {
|
|
56
|
+
await deleteRole(id);
|
|
57
|
+
this.message = __('Role deleted.');
|
|
58
|
+
const result = await this.query();
|
|
59
|
+
const maxPage = Math.max(1, Math.ceil(result.total / PAGE_SIZE));
|
|
60
|
+
if (this.page > maxPage) {
|
|
61
|
+
this.page = maxPage;
|
|
62
|
+
this.applyResult(await this.query());
|
|
63
|
+
} else {
|
|
64
|
+
this.applyResult(result);
|
|
65
|
+
}
|
|
66
|
+
} catch (e: any) {
|
|
67
|
+
this.error = e?.message || __('Could not delete role');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Open the delete-confirmation dialog for a role (client-side). */
|
|
72
|
+
@Client()
|
|
73
|
+
requestDelete(r: RoleDetail) {
|
|
74
|
+
if (r.name === 'admin') return;
|
|
75
|
+
this.pendingDelete = r;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Confirm: actually delete the pending role, then close the dialog. */
|
|
79
|
+
@Client()
|
|
80
|
+
async confirmDelete() {
|
|
81
|
+
const r = this.pendingDelete;
|
|
82
|
+
this.pendingDelete = null;
|
|
83
|
+
if (!r) return;
|
|
84
|
+
await this.remove(r.id);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Query-string for pagination links — preserves the current search. */
|
|
88
|
+
private pageHref(p: number): string {
|
|
89
|
+
const params = new URLSearchParams();
|
|
90
|
+
if (this.appliedSearch) params.set('search', this.appliedSearch);
|
|
91
|
+
if (p > 1) params.set('page', String(p));
|
|
92
|
+
const qs = params.toString();
|
|
93
|
+
return qs ? `/dashboard/roles?${qs}` : '/dashboard/roles';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
render() {
|
|
97
|
+
const totalPages = Math.max(1, Math.ceil(this.total / PAGE_SIZE));
|
|
98
|
+
return html`
|
|
99
|
+
<div class="space-y-6">
|
|
100
|
+
${pageHeader(__('Roles'), { description: __('Manage roles and their permissions.'), titleActions: linkButton(__('New role'), '/dashboard/roles/new', 'primary', { size: 'sm' }) })}
|
|
101
|
+
${this.message && !this.error ? notice(this.message, 'success') : null}
|
|
102
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
103
|
+
${listFilters({ action: '/dashboard/roles', search: { name: 'search', value: this.appliedSearch, placeholder: __('Search roles') } })}
|
|
104
|
+
${listTable<RoleDetail>({
|
|
105
|
+
rows: this.roles, key: role => role.id, rowAttribute: 'data-role', empty: __('No roles found.'),
|
|
106
|
+
columns: [
|
|
107
|
+
{ label: __('Role'), cell: role => html`<a href="/dashboard/roles/${role.id}" class="font-medium text-foreground no-underline hover:text-primary">${role.name}</a>
|
|
108
|
+
${rowActions([
|
|
109
|
+
{ id: `role-${role.id}-edit`, label: __('Edit'), href: `/dashboard/roles/${role.id}` },
|
|
110
|
+
{ id: `role-${role.id}-users`, label: __('View users'), href: `/dashboard/users?role=${encodeURIComponent(role.name)}` },
|
|
111
|
+
...(role.name !== 'admin' ? [{ id: `role-${role.id}-delete`, label: __('Delete'), danger: true, run: () => this.requestDelete(role) }] : []),
|
|
112
|
+
])}` },
|
|
113
|
+
{ label: __('Users'), class: 'text-muted-foreground', cell: role => html`<a href="/dashboard/users?role=${encodeURIComponent(role.name)}" class="text-muted-foreground no-underline hover:text-primary">${role.userCount ?? 0}</a>` },
|
|
114
|
+
],
|
|
115
|
+
})}
|
|
116
|
+
${listFooter({ total: this.total, page: this.page, totalPages, href: p => this.pageHref(p) })}
|
|
117
|
+
|
|
118
|
+
${component(AlertDialog, {
|
|
119
|
+
id: 'delete-role-dialog',
|
|
120
|
+
open: this.pendingDelete !== null,
|
|
121
|
+
title: __('Delete role?'),
|
|
122
|
+
description: this.pendingDelete
|
|
123
|
+
? `${__('Are you sure you want to delete the')} "${this.pendingDelete.name}" ${__('role')}? ${__('Users assigned this role will lose its permissions. This action cannot be undone.')}`
|
|
124
|
+
: '',
|
|
125
|
+
cancelLabel: __('Cancel'),
|
|
126
|
+
actionLabel: __('Delete'),
|
|
127
|
+
actionVariant: 'destructive',
|
|
128
|
+
onAction: () => this.confirmDelete(),
|
|
129
|
+
onOpenChange: () => { this.pendingDelete = null; },
|
|
130
|
+
})}
|
|
131
|
+
</div>
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Cossack, Page, Store, State, Validate, Client, Server, storeRules } from '@cossackframework/core';
|
|
2
|
+
import { Card, CardBody, CardHeader, Field, Input, Button, Checkbox, Form } from '@cossackframework/ui';
|
|
3
|
+
import { linkButton, notice, pageHeader } from '@cossackframework/ui/blocks';
|
|
4
|
+
import { html, component, bind } from '@cossackframework/renderer';
|
|
5
|
+
import { requireRoleManager } from '#app/services/rbac';
|
|
6
|
+
import { createRole } from '#app/services/roles';
|
|
7
|
+
import { PERMISSIONS, permissionLabel, type Permission } from '#app/lib/permissions';
|
|
8
|
+
|
|
9
|
+
interface NewRoleForm {
|
|
10
|
+
name: string;
|
|
11
|
+
permissions: Permission[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Page({ transport: 'http', middlewares: [requireRoleManager] })
|
|
15
|
+
export default class NewRolePage extends Cossack {
|
|
16
|
+
@Store()
|
|
17
|
+
@Validate({
|
|
18
|
+
rules: storeRules<NewRoleForm>({
|
|
19
|
+
name: { required: true, message: 'Name is required' },
|
|
20
|
+
}),
|
|
21
|
+
config: { trigger: 'all', runOn: 'both' }
|
|
22
|
+
})
|
|
23
|
+
form: NewRoleForm = { name: '', permissions: [] };
|
|
24
|
+
|
|
25
|
+
@State() error = '';
|
|
26
|
+
|
|
27
|
+
@Client()
|
|
28
|
+
togglePermission(perm: Permission, checked: boolean) {
|
|
29
|
+
this.form.permissions = checked
|
|
30
|
+
? [...this.form.permissions, perm]
|
|
31
|
+
: this.form.permissions.filter((p) => p !== perm);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Client()
|
|
35
|
+
async handleSubmit(event: Event) {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
this.error = '';
|
|
38
|
+
const ok = await this.validateAll();
|
|
39
|
+
if (!ok) return;
|
|
40
|
+
try {
|
|
41
|
+
await this.create(this.form.name, this.form.permissions);
|
|
42
|
+
} catch (e: any) {
|
|
43
|
+
this.error = e?.message || __('Could not create role');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Server()
|
|
48
|
+
async create(name: string, permissions: Permission[]) {
|
|
49
|
+
await createRole({ name, permissions });
|
|
50
|
+
this.redirect('/dashboard/roles');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
return html`
|
|
55
|
+
<div class="max-w-2xl space-y-6">
|
|
56
|
+
${pageHeader(__('New role'), { description: __('Define a role and the permissions it grants.') })}
|
|
57
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
58
|
+
|
|
59
|
+
${component(Card, {}, html`
|
|
60
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Details')}</h2>`)}
|
|
61
|
+
${component(CardBody, {}, html`
|
|
62
|
+
${component(Form, {
|
|
63
|
+
submit: (e: Event) => this.handleSubmit(e),
|
|
64
|
+
}, html`
|
|
65
|
+
<div class="flex flex-col space-y-4">
|
|
66
|
+
${component(Field, { label: __('Name'), for: 'name', error: this.getError('form.name'),
|
|
67
|
+
control: attributes => component(Input, { ...attributes, type: 'text', placeholder: 'editor', '.value': bind(this.form, 'name') }) })}
|
|
68
|
+
|
|
69
|
+
<div>
|
|
70
|
+
<p class="text-sm font-medium text-foreground mb-2">${__('Permissions')}</p>
|
|
71
|
+
<div class="space-y-2">
|
|
72
|
+
${PERMISSIONS.map((perm) => html`
|
|
73
|
+
<div class="[&_.cs-checkbox]:items-start [&_.cs-checkbox>input]:mt-0.5">${component(Checkbox, {
|
|
74
|
+
checked: this.form.permissions.includes(perm),
|
|
75
|
+
'@change': (e: any) => this.togglePermission(perm, e.target.checked),
|
|
76
|
+
}, html`<span>
|
|
77
|
+
<span class="block text-sm text-foreground">${__(permissionLabel(perm))}</span>
|
|
78
|
+
<span class="block text-xs text-muted-foreground font-mono">${perm}</span>
|
|
79
|
+
</span>`)}</div>
|
|
80
|
+
`)}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<div class="flex items-center gap-2">
|
|
85
|
+
${component(Button, { type: 'submit' }, __('Create role'))}
|
|
86
|
+
${linkButton(__('Cancel'), '/dashboard/roles', 'outline')}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
`)}
|
|
90
|
+
`)}
|
|
91
|
+
`)}
|
|
92
|
+
</div>
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
}
|