@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,211 @@
|
|
|
1
|
+
import { Cossack, Page, State, ClientState, Store, Validate, Client, Server, storeRules, getLocale, getSupportedLocales, setLocale } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { Card, CardBody, CardHeader, Field, Input, Button, Avatar, Form, NativeSelect } from '@cossackframework/ui';
|
|
4
|
+
import { notice, pageHeader } from '@cossackframework/ui/blocks';
|
|
5
|
+
import { html, component, bind } from '@cossackframework/renderer';
|
|
6
|
+
import { avatarUploads, deleteOwnAccount, updateUserProfile, uploadAvatar } from '#app/auth';
|
|
7
|
+
import { avatarField } from '#app/dashboard/avatar-field';
|
|
8
|
+
|
|
9
|
+
/** A language's name in itself, such as Français or Tiếng Việt. */
|
|
10
|
+
function languageLabel(code: string): string {
|
|
11
|
+
try { return new Intl.DisplayNames([code], { type: 'language' }).of(code) ?? code; } catch { return code; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ProfileForm {
|
|
15
|
+
name: string;
|
|
16
|
+
avatar: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Page({ transport: 'http' })
|
|
20
|
+
export default class ProfilePage extends Cossack {
|
|
21
|
+
@Store()
|
|
22
|
+
@Validate({
|
|
23
|
+
rules: storeRules<ProfileForm>({
|
|
24
|
+
name: { required: true, message: 'Name is required' },
|
|
25
|
+
}),
|
|
26
|
+
config: { trigger: 'all', runOn: 'both' }
|
|
27
|
+
})
|
|
28
|
+
form: ProfileForm = { name: '', avatar: '' };
|
|
29
|
+
|
|
30
|
+
@State() saved = false;
|
|
31
|
+
@State() error = '';
|
|
32
|
+
/** What the last action did, shown under the heading. */
|
|
33
|
+
@State() message = '';
|
|
34
|
+
/** Email shown in the profile card (read-only; seeded server-side). */
|
|
35
|
+
@State() userEmail = '';
|
|
36
|
+
/** Whether the auth store accepts picture uploads; otherwise the avatar is a URL. */
|
|
37
|
+
@State() avatarUploads = false;
|
|
38
|
+
@ClientState() uploading = false;
|
|
39
|
+
@ClientState() avatarError = '';
|
|
40
|
+
/** The chosen picture while it uploads; browser-only, so server state never echoes it back. */
|
|
41
|
+
@ClientState() avatarPreview = '';
|
|
42
|
+
/** Languages the interface has catalogs for, from the application and language packs. */
|
|
43
|
+
@State() languages: { code: string; label: string }[] = [];
|
|
44
|
+
@State() language = '';
|
|
45
|
+
|
|
46
|
+
async init() {
|
|
47
|
+
// Seed the form server-side (serializes via @Store) so it's populated
|
|
48
|
+
// at SSR — not empty until onMount runs client-side.
|
|
49
|
+
const user = this.user;
|
|
50
|
+
if (user) {
|
|
51
|
+
this.form.name = user.name;
|
|
52
|
+
this.form.avatar = user.avatar ?? '';
|
|
53
|
+
this.userEmail = user.email;
|
|
54
|
+
}
|
|
55
|
+
this.avatarUploads = avatarUploads;
|
|
56
|
+
this.languages = getSupportedLocales().map(code => ({ code, label: languageLabel(code) }));
|
|
57
|
+
this.language = getLocale();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Keep the dashboard's language in this browser (the `cossack_locale` cookie), then draw it again. */
|
|
61
|
+
@Client()
|
|
62
|
+
async chooseLanguage(event: Event) {
|
|
63
|
+
this.error = '';
|
|
64
|
+
try {
|
|
65
|
+
await setLocale((event.target as HTMLSelectElement).value);
|
|
66
|
+
window.location.reload();
|
|
67
|
+
} catch {
|
|
68
|
+
this.error = __('That language could not be loaded.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Upload a picture: it shows at once and is saved when the upload finishes. */
|
|
73
|
+
@Client()
|
|
74
|
+
async chooseAvatar(file: File) {
|
|
75
|
+
this.avatarError = '';
|
|
76
|
+
this.message = '';
|
|
77
|
+
this.uploading = true;
|
|
78
|
+
const preview = URL.createObjectURL(file);
|
|
79
|
+
this.avatarPreview = preview;
|
|
80
|
+
try {
|
|
81
|
+
await this.storeAvatar(file);
|
|
82
|
+
this.message = __('Picture updated.');
|
|
83
|
+
} catch (e: any) {
|
|
84
|
+
this.avatarError = e?.message || __('The picture could not be uploaded.');
|
|
85
|
+
} finally {
|
|
86
|
+
this.uploading = false;
|
|
87
|
+
this.avatarPreview = '';
|
|
88
|
+
URL.revokeObjectURL(preview);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The stored picture's URL comes back as state. */
|
|
93
|
+
@Server({ input: input.args(input.file()) })
|
|
94
|
+
async storeAvatar(file: File) {
|
|
95
|
+
this.form.avatar = await uploadAvatar(this.user!.id, file);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Client()
|
|
99
|
+
async removeAvatar() {
|
|
100
|
+
this.form.avatar = '';
|
|
101
|
+
this.message = '';
|
|
102
|
+
await this.clearAvatar();
|
|
103
|
+
this.message = __('Picture removed.');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Server()
|
|
107
|
+
async clearAvatar() {
|
|
108
|
+
await updateUserProfile(this.user!.id, { avatar: null });
|
|
109
|
+
this.form.avatar = '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@Client()
|
|
113
|
+
async handleSubmit(event: Event) {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
this.error = '';
|
|
116
|
+
this.message = '';
|
|
117
|
+
this.saved = false;
|
|
118
|
+
const ok = await this.validateAll();
|
|
119
|
+
if (!ok) return;
|
|
120
|
+
try {
|
|
121
|
+
await this.save(this.form.name, this.form.avatar);
|
|
122
|
+
this.saved = true;
|
|
123
|
+
this.message = __('Profile updated.');
|
|
124
|
+
} catch (e: any) {
|
|
125
|
+
this.error = e?.message || 'Could not save profile';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Server()
|
|
130
|
+
async save(name: string, avatar: string) {
|
|
131
|
+
await updateUserProfile(this.user!.id, { name, avatar: avatar || null });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@ClientState() deletePassword = '';
|
|
135
|
+
@State() deleteError = '';
|
|
136
|
+
|
|
137
|
+
@Client()
|
|
138
|
+
async confirmDelete(event: Event) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
if (!this.deletePassword || !window.confirm(__('Delete your account for good? This cannot be undone.'))) return;
|
|
141
|
+
await this.deleteAccount(this.deletePassword);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Ends every session and deletes the account; the browser lands on the home page signed out. */
|
|
145
|
+
@Server()
|
|
146
|
+
async deleteAccount(password: string) {
|
|
147
|
+
this.deleteError = '';
|
|
148
|
+
try {
|
|
149
|
+
const { headers } = await deleteOwnAccount(this.c, this.user!.id, password);
|
|
150
|
+
headers.forEach((value, key) => this.c.header(key, value));
|
|
151
|
+
this.redirect('/');
|
|
152
|
+
} catch (error) {
|
|
153
|
+
this.deleteError = (error as Error).message || __('The account could not be deleted.');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
render() {
|
|
158
|
+
return html`
|
|
159
|
+
<div class="max-w-2xl space-y-6">
|
|
160
|
+
${pageHeader(__('Profile'), { description: __('Update your display name and avatar.'),
|
|
161
|
+
actions: html`<a href="/dashboard/profile/security" class="text-sm text-primary hover:underline">${__('Security and application passwords')} →</a>` })}
|
|
162
|
+
${this.message && !this.error ? notice(this.message, 'success') : null}
|
|
163
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
164
|
+
|
|
165
|
+
${component(Card, {}, component(CardBody, {}, html`
|
|
166
|
+
<div class="flex items-center gap-4">
|
|
167
|
+
${component(Avatar, { src: this.form.avatar || undefined, alt: this.form.name, size: 56 })}
|
|
168
|
+
<div>
|
|
169
|
+
<div class="text-sm text-muted-foreground">${__('Email')}</div>
|
|
170
|
+
<div class="text-foreground font-medium">${this.userEmail}</div>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
`))}
|
|
174
|
+
|
|
175
|
+
${component(Card, {}, html`
|
|
176
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Edit profile')}</h2>`)}
|
|
177
|
+
${component(CardBody, {}, html`
|
|
178
|
+
${component(Form, {
|
|
179
|
+
submit: (e: Event) => this.handleSubmit(e),
|
|
180
|
+
}, html`
|
|
181
|
+
<div class="flex flex-col space-y-4">
|
|
182
|
+
${component(Field, { label: __('Name'), for: 'name', error: this.getError('form.name'),
|
|
183
|
+
control: attributes => component(Input, { ...attributes, type: 'text', '.value': bind(this.form, 'name') }) })}
|
|
184
|
+
${avatarField({ id: 'avatar', value: this.avatarPreview || this.form.avatar, name: this.form.name, uploads: this.avatarUploads, uploading: this.uploading, error: this.avatarError,
|
|
185
|
+
onFile: file => this.chooseAvatar(file), onUrl: url => { this.form.avatar = url; }, onRemove: () => this.removeAvatar() })}
|
|
186
|
+
<div>${component(Button, { type: 'submit' }, __('Save changes'))}</div>
|
|
187
|
+
</div>
|
|
188
|
+
`)}
|
|
189
|
+
`)}
|
|
190
|
+
`)}
|
|
191
|
+
|
|
192
|
+
${this.languages.length > 1 ? component(Card, {}, html`
|
|
193
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Dashboard language')}</h2>`)}
|
|
194
|
+
${component(CardBody, {}, component(Field, { label: __('Language'), for: 'dashboard-language', hint: __('Kept in this browser.'),
|
|
195
|
+
control: attributes => component(NativeSelect, { ...attributes, '@change': (event: Event) => this.chooseLanguage(event) }, html`
|
|
196
|
+
${this.languages.map(language => html`<option value=${language.code} ?selected=${language.code === this.language}>${language.label}</option>`)}`) }))}
|
|
197
|
+
`) : null}
|
|
198
|
+
${component(Card, {}, html`
|
|
199
|
+
${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-destructive">${__('Delete your account')}</h2>
|
|
200
|
+
<p class="text-sm text-muted-foreground">${__('Your account and its sessions go for good. What you published stays, without you as its author.')}</p>`)}
|
|
201
|
+
${component(CardBody, {}, html`<form class="flex flex-wrap items-end gap-3" @submit=${(event: Event) => this.confirmDelete(event)}>
|
|
202
|
+
${component(Field, { label: __('Your password'), for: 'delete-password', control: attributes => component(Input, { ...attributes, type: 'password', autocomplete: 'current-password', required: true,
|
|
203
|
+
'.value': this.deletePassword, '@input': (event: Event) => { this.deletePassword = (event.target as HTMLInputElement).value; } }) })}
|
|
204
|
+
${component(Button, { type: 'submit', variant: 'destructive' }, __('Delete my account'))}
|
|
205
|
+
${this.deleteError ? html`<p role="alert" class="w-full text-sm text-destructive">${this.deleteError}</p>` : null}
|
|
206
|
+
</form>`)}
|
|
207
|
+
`)}
|
|
208
|
+
</div>
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
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, CopyField, 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
|
+
|
|
98
|
+
// --- Passkeys ------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
@Client()
|
|
101
|
+
async addPasskey() {
|
|
102
|
+
this.error = '';
|
|
103
|
+
this.message = '';
|
|
104
|
+
try {
|
|
105
|
+
const { challenge, options } = await this.passkeyOptions();
|
|
106
|
+
const response = await createPasskey(options);
|
|
107
|
+
await this.savePasskey(challenge, response, this.passkeyName || navigatorName());
|
|
108
|
+
if (!this.error) { this.passkeyName = ''; this.message = __('Passkey added.'); }
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if ((error as Error)?.name === 'NotAllowedError') return;
|
|
111
|
+
this.error = (error as Error)?.message || __('The passkey could not be added.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Server()
|
|
116
|
+
async passkeyOptions() {
|
|
117
|
+
return passkeyRegistration(this.c, this.user as PublicUser);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Server()
|
|
121
|
+
async savePasskey(challenge: string, response: unknown, name: string) {
|
|
122
|
+
this.error = '';
|
|
123
|
+
try {
|
|
124
|
+
await addPasskey(this.c, this.user as PublicUser, challenge, response as never, name);
|
|
125
|
+
await this.load();
|
|
126
|
+
} catch (error) { this.error = (error as Error).message; }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Server({ input: input.args(input.string({ minLength: 1, maxLength: 200 })) })
|
|
130
|
+
async deletePasskey(id: string) {
|
|
131
|
+
await removePasskey(this.user!.id, id);
|
|
132
|
+
await this.load();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// --- Application passwords -----------------------------------------------------
|
|
136
|
+
|
|
137
|
+
/** Returns whether the password was created; the form keeps its values otherwise. */
|
|
138
|
+
@Server()
|
|
139
|
+
async addToken(name: string, scope: 'read' | 'write', expiresInDays: number): Promise<boolean> {
|
|
140
|
+
this.error = '';
|
|
141
|
+
try {
|
|
142
|
+
this.newToken = await createApiToken(this.user!.id, name, scope === 'read' ? 'read' : 'write', expiresInDays);
|
|
143
|
+
await this.load();
|
|
144
|
+
return true;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
this.error = (error as Error).message;
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Server()
|
|
152
|
+
async deleteToken(id: string) {
|
|
153
|
+
await revokeApiToken(this.user!.id, id);
|
|
154
|
+
await this.load();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The passkeys, added and removed here, or listed with a link to the host that keeps them. */
|
|
158
|
+
private passkeys(): TemplateResult {
|
|
159
|
+
const elsewhere = this.status.passkeysManagedAt;
|
|
160
|
+
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">
|
|
161
|
+
<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>
|
|
162
|
+
${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>`}
|
|
163
|
+
</li>`)}</ul>` : html`<p class="text-sm text-muted-foreground">${__('No passkeys yet.')}</p>`;
|
|
164
|
+
if (elsewhere) return html`${list}
|
|
165
|
+
<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 })}
|
|
166
|
+
${elsewhere.href ? html`<a href=${elsewhere.href} class="font-medium text-foreground underline">${__('Manage passkeys on :site', { site: elsewhere.name })}</a>` : null}</p>`;
|
|
167
|
+
return html`${list}
|
|
168
|
+
<div class="flex flex-wrap items-end gap-2">
|
|
169
|
+
${component(Field, { label: __('Name'), for: 'passkey-name', control: attributes => component(Input, { ...attributes, maxlength: 80, placeholder: __('Such as Work laptop'),
|
|
170
|
+
'.value': this.passkeyName, '@input': (event: Event) => { this.passkeyName = (event.target as HTMLInputElement).value; } }) })}
|
|
171
|
+
${component(Button, { type: 'button', variant: 'outline', '@click': () => this.addPasskey() }, __('Add a passkey'))}
|
|
172
|
+
</div>`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private authenticator(): TemplateResult {
|
|
176
|
+
const codeInput = (id: string) => component(Input, { id, autocomplete: 'one-time-code', inputmode: 'numeric', maxlength: 20, placeholder: '123456', class: 'max-w-40',
|
|
177
|
+
'.value': this.code, '@input': (event: Event) => { this.code = (event.target as HTMLInputElement).value; } });
|
|
178
|
+
if (this.setup) return html`<div class="space-y-4">
|
|
179
|
+
<ol class="list-decimal space-y-1 pl-5 text-sm text-foreground">
|
|
180
|
+
<li>${__('Scan this code with an authenticator app, such as 1Password, Google Authenticator or Microsoft Authenticator.')}</li>
|
|
181
|
+
<li>${__('Enter the 6-digit code the app shows.')}</li>
|
|
182
|
+
</ol>
|
|
183
|
+
<div class="flex flex-wrap items-start gap-6">
|
|
184
|
+
<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>
|
|
185
|
+
<div class="space-y-2 text-sm">
|
|
186
|
+
<p class="text-muted-foreground">${__('Cannot scan? Enter this key:')}</p>
|
|
187
|
+
<code class="block break-all rounded bg-muted px-2 py-1 text-xs" data-totp-secret>${this.setup.secret}</code>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
<form class="flex flex-wrap items-end gap-2" @submit=${(event: Event) => { event.preventDefault(); void this.finishSetup(this.code); }}>
|
|
191
|
+
${component(Field, { label: __('Code'), for: 'totp-confirm', control: () => codeInput('totp-confirm') })}
|
|
192
|
+
${component(Button, { type: 'submit', disabled: !this.code.trim() }, __('Turn on'))}
|
|
193
|
+
${component(Button, { type: 'button', variant: 'ghost', '@click': () => { this.setup = null; } }, __('Cancel'))}
|
|
194
|
+
</form>
|
|
195
|
+
</div>`;
|
|
196
|
+
if (!this.status.totp) return html`<div class="space-y-3">
|
|
197
|
+
<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>
|
|
198
|
+
${component(Button, { type: 'button', '@click': () => this.beginSetup() }, __('Set up an authenticator app'))}
|
|
199
|
+
</div>`;
|
|
200
|
+
return html`<div class="space-y-4">
|
|
201
|
+
<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>
|
|
202
|
+
<p class="text-sm text-muted-foreground">${this.status.recoveryCodes} ${__('recovery codes left. Each works once, when you do not have your phone.')}</p>
|
|
203
|
+
<form class="flex flex-wrap items-end gap-2" @submit=${(event: Event) => event.preventDefault()}>
|
|
204
|
+
${component(Field, { label: __('Current code'), for: 'totp-current', control: () => codeInput('totp-current') })}
|
|
205
|
+
${component(Button, { type: 'button', variant: 'outline', disabled: !this.code.trim(), '@click': () => this.regenerate(this.code) }, __('New recovery codes'))}
|
|
206
|
+
${component(Button, { type: 'button', variant: 'destructive', disabled: !this.code.trim(), '@click': () => this.turnOff(this.code) }, __('Turn off'))}
|
|
207
|
+
<p class="w-full text-xs text-muted-foreground">${__('From the app, or a recovery code.')}</p>
|
|
208
|
+
</form>
|
|
209
|
+
</div>`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
render() {
|
|
213
|
+
if (!this.available && !this.tokensAvailable) return html`<div class="max-w-2xl space-y-4">
|
|
214
|
+
<h1 class="text-2xl font-bold text-foreground">${__('Security')}</h1>
|
|
215
|
+
<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>
|
|
216
|
+
</div>`;
|
|
217
|
+
return html`<div class="max-w-3xl space-y-6">
|
|
218
|
+
${pageHeader(__('Security'), { description: __('Protect your account, and connect apps to the content API.'),
|
|
219
|
+
actions: html`<a href="/dashboard/profile" class="text-sm text-muted-foreground hover:text-foreground">← ${__('Profile')}</a>` })}
|
|
220
|
+
${this.required ? component(Alert, { variant: 'warning' }, this.status.totp || this.status.passkeys.length
|
|
221
|
+
? __('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.')
|
|
222
|
+
: __('This site requires two-step sign-in. Add an authenticator app or a passkey to continue.')) : null}
|
|
223
|
+
${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}
|
|
224
|
+
${this.message && !this.error ? notice(this.message, 'success') : null}
|
|
225
|
+
${this.error ? notice(this.error, 'error') : null}
|
|
226
|
+
${this.recoveryCodes.length ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Your recovery codes')}</h2>`)}
|
|
227
|
+
${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>
|
|
228
|
+
${component(CopyField, { label: __('Your recovery codes'), value: this.recoveryCodes.join('\n'), 'data-recovery-codes': '',
|
|
229
|
+
copyLabel: __('Copy'), copiedLabel: __('Copied.'), copyFailedLabel: __('Copy the codes from the list.') })}`)}`) : null}
|
|
230
|
+
${this.available ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Two-step sign-in')}</h2>`)}
|
|
231
|
+
${component(CardBody, {}, this.authenticator())}`) : null}
|
|
232
|
+
${this.available ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Passkeys')}</h2>
|
|
233
|
+
<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>`)}
|
|
234
|
+
${component(CardBody, { class: 'space-y-4' }, this.passkeys())}`) : null}
|
|
235
|
+
${this.tokensAvailable ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Application passwords')}</h2>
|
|
236
|
+
<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>`)}
|
|
237
|
+
${component(CardBody, {}, component(AppPasswords, { tokens: this.tokens, newToken: this.newToken,
|
|
238
|
+
onAdd: (name: string, scope: 'read' | 'write', expiresInDays: number) => this.addToken(name, scope, expiresInDays), onRevoke: (id: string) => this.deleteToken(id) }))}`) : null}
|
|
239
|
+
</div>`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** A default passkey name from the browser, such as `Chrome on macOS`. */
|
|
244
|
+
function navigatorName(): string {
|
|
245
|
+
const agent = navigator.userAgent;
|
|
246
|
+
const browser = /Edg\//.test(agent) ? 'Edge' : /Firefox\//.test(agent) ? 'Firefox' : /Chrome\//.test(agent) ? 'Chrome' : /Safari\//.test(agent) ? 'Safari' : 'Browser';
|
|
247
|
+
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' : '';
|
|
248
|
+
return system ? `${browser} on ${system}` : browser;
|
|
249
|
+
}
|
|
@@ -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
|
+
}
|