@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,29 @@
|
|
|
1
|
+
import type { HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { getRequestContext } from '@cossackframework/core';
|
|
3
|
+
import { DASHBOARD_ACCENTS, DASHBOARD_PALETTES } from '@cossackframework/cms';
|
|
4
|
+
import { UI_PALETTE_META } from '@cossackframework/ui';
|
|
5
|
+
import { ICON_STYLE_META, iconStyle } from '../cms/icons';
|
|
6
|
+
|
|
7
|
+
/** The `ui-palette` meta content for Settings → Interface: `<base> <accent>`, neutral for anything unknown. */
|
|
8
|
+
export function dashboardPalette(palette: unknown, accent: unknown): string {
|
|
9
|
+
const base = DASHBOARD_PALETTES.find(entry => entry === palette) ?? 'neutral';
|
|
10
|
+
const tint = DASHBOARD_ACCENTS.find(entry => entry === accent) ?? 'neutral';
|
|
11
|
+
return `${base} ${tint}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The palettes of this page: the middleware's on the server, the server-drawn meta on the client. */
|
|
15
|
+
function palette(): string {
|
|
16
|
+
if (typeof document !== 'undefined') return document.querySelector(`meta[name="${UI_PALETTE_META}"]`)?.getAttribute('content') ?? dashboardPalette(undefined, undefined);
|
|
17
|
+
return getRequestContext()?.get('cms.palette') ?? dashboardPalette(undefined, undefined);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The dashboard's meta tags: the icon style, so client renders draw what the server drew, and
|
|
22
|
+
* the palettes `@cossackframework/ui/theme/palettes.css` applies (Settings → Interface).
|
|
23
|
+
*/
|
|
24
|
+
export function dashboardHead(): NonNullable<HeadValue['meta']> {
|
|
25
|
+
return [
|
|
26
|
+
{ tag: 'meta', attributes: { name: ICON_STYLE_META, content: iconStyle() } },
|
|
27
|
+
{ tag: 'meta', attributes: { name: UI_PALETTE_META, content: palette() } },
|
|
28
|
+
];
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { icon } from '../cms/icons';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The dashboard shell's own icons: the Dashboard link, the theme toggle, the account menu's
|
|
5
|
+
* chevron and Sign out, the list tables' search box and the sessions list's devices.
|
|
6
|
+
*/
|
|
7
|
+
export type ShellIcons = Record<'home' | 'light' | 'dark' | 'expand' | 'logout' | 'search' | 'mobile' | 'tablet' | 'desktop', ReturnType<typeof icon>>;
|
|
8
|
+
|
|
9
|
+
/** The shell's icons in the site's icon style (Appearance → Customize), asked for on every render. */
|
|
10
|
+
export function shellIcons(): ShellIcons {
|
|
11
|
+
return {
|
|
12
|
+
home: icon('widget-2'), light: icon('sun'), dark: icon('moon'), expand: icon('alt-arrow-right'), logout: icon('logout-3'),
|
|
13
|
+
search: icon('magnifier'), mobile: icon('smartphone'), tablet: icon('tablet'), desktop: icon('monitor'),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dashboard's lists (entries, users, roles, forms): one table, one filter bar and one footer,
|
|
3
|
+
* so every list reads the same. Filters are a GET form, so the address holds them; selection
|
|
4
|
+
* goes with `bulkBar` from `./bulk`, above and below the table.
|
|
5
|
+
*/
|
|
6
|
+
import { component, html, ifDefined, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import { Button, Card, CardBody, Icon, Input, Pagination } from '@cossackframework/ui';
|
|
8
|
+
import { shellIcons } from './icons';
|
|
9
|
+
import { selectAllBox, selectBox } from './bulk';
|
|
10
|
+
|
|
11
|
+
export interface ListColumn<T> {
|
|
12
|
+
/** The header; empty for a column of controls. */
|
|
13
|
+
label: string | TemplateResult;
|
|
14
|
+
cell(row: T): unknown;
|
|
15
|
+
/** Classes for the header and the cells, such as `w-14` or `text-muted-foreground`. */
|
|
16
|
+
class?: string;
|
|
17
|
+
/** How the list is sorted by this column, for `aria-sort`; a sortable header passes a link as its label. */
|
|
18
|
+
sort?: 'ascending' | 'descending' | 'none';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ListTableOptions<T> {
|
|
22
|
+
rows: readonly T[];
|
|
23
|
+
key(row: T): string;
|
|
24
|
+
/** Columns in order; a falsy entry is left out, so optional columns read inline. */
|
|
25
|
+
columns: readonly (ListColumn<T> | false | null | undefined)[];
|
|
26
|
+
/** Row checkboxes and the "select all" box. `selectable` limits which rows have one; all by default. */
|
|
27
|
+
selection?: { selected: readonly string[]; selectable?: readonly string[]; label(row: T): string; change(ids: string[]): void };
|
|
28
|
+
/** What an empty list says. */
|
|
29
|
+
empty?: string;
|
|
30
|
+
/** The rows' data attribute, such as `data-user`, holding the key: tests and scripts find rows by it. */
|
|
31
|
+
rowAttribute?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TH = 'px-3 py-2 font-medium';
|
|
35
|
+
const TD = 'px-3 py-2';
|
|
36
|
+
|
|
37
|
+
/** The list as a table in a card: a header row, a row per item, and the empty text when there are none. */
|
|
38
|
+
export function listTable<T>(options: ListTableOptions<T>): TemplateResult {
|
|
39
|
+
const columns = options.columns.filter((column): column is ListColumn<T> => !!column);
|
|
40
|
+
const selection = options.selection;
|
|
41
|
+
const selectable = selection ? selection.selectable ?? options.rows.map(options.key) : [];
|
|
42
|
+
const attribute = options.rowAttribute ?? 'data-row';
|
|
43
|
+
return component(Card, {}, component(CardBody, { class: 'p-0' }, html`
|
|
44
|
+
<div class="overflow-x-auto">
|
|
45
|
+
<table class="w-full text-sm">
|
|
46
|
+
<thead><tr class="border-b border-border text-left text-xs uppercase tracking-wide text-muted-foreground">
|
|
47
|
+
${selection ? html`<th class="w-10 px-3 py-2">${selectAllBox(selectable, selection.selected, ids => selection.change(ids))}</th>` : null}
|
|
48
|
+
${columns.map(column => html`<th class=${`${TH} ${column.class ?? ''}`} aria-sort=${column.sort ?? 'none'}>${column.label}</th>`)}
|
|
49
|
+
</tr></thead>
|
|
50
|
+
<tbody>${options.rows.map(row => {
|
|
51
|
+
const key = options.key(row);
|
|
52
|
+
const chosen = selection?.selected.includes(key) === true;
|
|
53
|
+
return html`<tr class=${`group border-b border-border last:border-0 align-top ${chosen ? 'bg-primary/5' : ''}`} ...=${{ [attribute]: key }}>
|
|
54
|
+
${selection ? html`<td class=${TD}>${selectable.includes(key) ? selectBox(key, selection.label(row), selection.selected, ids => selection.change(ids)) : null}</td>` : null}
|
|
55
|
+
${columns.map(column => html`<td class=${`${TD} ${column.class ?? ''}`}>${column.cell(row)}</td>`)}
|
|
56
|
+
</tr>`;
|
|
57
|
+
})}</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
${options.rows.length ? null : html`<p class="px-3 py-8 text-center text-sm text-muted-foreground">${options.empty ?? __('Nothing found.')}</p>`}
|
|
60
|
+
</div>`));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ListFiltersOptions {
|
|
64
|
+
/** The list's address; the form submits to it with GET. */
|
|
65
|
+
action: string;
|
|
66
|
+
/** Values the form keeps, such as the sort, as hidden inputs. */
|
|
67
|
+
hidden?: Readonly<Record<string, string>>;
|
|
68
|
+
/** The search box: its query name, value and placeholder. */
|
|
69
|
+
search: { name: string; value: string; placeholder: string };
|
|
70
|
+
/** More filters before the search box, such as a role or a language select. */
|
|
71
|
+
filters?: TemplateResult | null;
|
|
72
|
+
id?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The filter bar above a list: its filters, a search box with its icon, and the Filter button. */
|
|
76
|
+
export function listFilters(options: ListFiltersOptions): TemplateResult {
|
|
77
|
+
return html`<form method="get" action=${options.action} class="flex flex-wrap items-center gap-2" role="search" id=${ifDefined(options.id)}>
|
|
78
|
+
${Object.entries(options.hidden ?? {}).filter(([, value]) => value !== '').map(([name, value]) => html`<input type="hidden" name=${name} value=${value}>`)}
|
|
79
|
+
${options.filters ?? null}
|
|
80
|
+
<div class="relative w-64 max-w-full">
|
|
81
|
+
<span aria-hidden="true" class="pointer-events-none absolute left-2.5 top-1/2 inline-flex -translate-y-1/2 text-muted-foreground [&_svg]:size-4">${component(Icon, { entry: shellIcons().search, size: 16 })}</span>
|
|
82
|
+
${component(Input, { type: 'search', name: options.search.name, value: options.search.value, size: 'sm', class: 'pl-8', placeholder: options.search.placeholder, 'aria-label': options.search.placeholder })}
|
|
83
|
+
</div>
|
|
84
|
+
${component(Button, { type: 'submit', size: 'sm', variant: 'outline' }, __('Filter'))}
|
|
85
|
+
</form>`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Below a list: how many items there are and, past one page, the pages. */
|
|
89
|
+
/** The count and pages under a list. `more`: the count is what was found so far, and more follow (search). */
|
|
90
|
+
export function listFooter(options: { total: number; page: number; totalPages: number; more?: boolean; href(page: number): string }): TemplateResult {
|
|
91
|
+
return html`<div class="flex flex-col items-center justify-between gap-3 sm:flex-row">
|
|
92
|
+
<p class="text-xs text-muted-foreground">${options.total}${options.more ? '+' : ''} ${options.total === 1 && !options.more ? __('item') : __('items')}</p>
|
|
93
|
+
${options.totalPages > 1 ? component(Pagination, {
|
|
94
|
+
page: options.page, totalPages: options.totalPages, label: __('Pagination'), previousLabel: __('Previous page'), nextLabel: __('Next page'),
|
|
95
|
+
pageLabel: (page: number) => `${__('Page')} ${page}`, href: (page: number) => options.href(page),
|
|
96
|
+
}) : null}
|
|
97
|
+
</div>`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A row's quick action: a link, or a button that runs `run`. */
|
|
101
|
+
export interface RowAction {
|
|
102
|
+
/** Unique on the page, such as `user-<id>-delete`. */
|
|
103
|
+
id: string;
|
|
104
|
+
label: string;
|
|
105
|
+
href?: string;
|
|
106
|
+
run?(): void;
|
|
107
|
+
danger?: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A row's quick actions under its title, as words between bars; clearer when the row is hovered or focused. */
|
|
111
|
+
export function rowActions(actions: readonly RowAction[]): TemplateResult {
|
|
112
|
+
const separator = html`<span aria-hidden="true" class="text-muted-foreground">|</span>`;
|
|
113
|
+
return html`<div class="mt-1 flex flex-wrap items-center gap-2 text-xs opacity-80 group-hover:opacity-100 focus-within:opacity-100" data-quick-actions>${actions.flatMap((action, index) => {
|
|
114
|
+
const tone = action.danger ? 'text-destructive' : 'text-primary';
|
|
115
|
+
const control = action.href
|
|
116
|
+
? html`<a href=${action.href} id=${action.id} class=${`${tone} no-underline hover:underline`}>${action.label}</a>`
|
|
117
|
+
: html`<button type="button" id=${action.id} class=${`${tone} cursor-pointer border-none bg-transparent p-0 text-xs hover:underline`} @click=${() => action.run?.()}>${action.label}</button>`;
|
|
118
|
+
return index ? [separator, control] : [control];
|
|
119
|
+
})}</div>`;
|
|
120
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { ShieldKeyholeIcon as iconSvg } from '@cossackframework/solar-icons/shield-keyhole/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'roles',
|
|
8
|
+
label: 'Roles',
|
|
9
|
+
href: '/dashboard/roles',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'admin',
|
|
12
|
+
parent: 'users',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default descriptor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { MonitorSmartphoneIcon as iconSvg } from '@cossackframework/solar-icons/monitor-smartphone/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'sessions',
|
|
8
|
+
label: 'Sessions',
|
|
9
|
+
href: '/dashboard/sessions',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'authenticated',
|
|
12
|
+
placement: 'account',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default descriptor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { UserCircleIcon as iconSvg } from '@cossackframework/solar-icons/user-circle/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'settings',
|
|
8
|
+
label: 'Profile settings',
|
|
9
|
+
href: '/dashboard/profile',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'authenticated',
|
|
12
|
+
placement: 'account',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default descriptor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DashboardModule } from '../types';
|
|
2
|
+
import { UsersGroupRoundedIcon as iconSvg } from '@cossackframework/solar-icons/users-group-rounded/line';
|
|
3
|
+
|
|
4
|
+
const icon = { line: iconSvg };
|
|
5
|
+
|
|
6
|
+
const descriptor: DashboardModule = {
|
|
7
|
+
id: 'users',
|
|
8
|
+
label: 'Users',
|
|
9
|
+
href: '/dashboard/users',
|
|
10
|
+
icon,
|
|
11
|
+
authorization: 'admin',
|
|
12
|
+
children: [
|
|
13
|
+
{ label: 'All users', href: '/dashboard/users' },
|
|
14
|
+
{ label: 'Add user', href: '/dashboard/users/new' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default descriptor;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dashboard screen's Help and Screen options panels. Its heading, link buttons and messages
|
|
3
|
+
* come from `@cossackframework/ui/blocks` (`pageHeader`, `linkButton`, `notice`), which plugin
|
|
4
|
+
* screens import too.
|
|
5
|
+
*/
|
|
6
|
+
import { html, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
|
|
8
|
+
/** A screen's panel the taskbar opens: a native popover above the taskbar's buttons, dismissed by a click outside or Escape. */
|
|
9
|
+
function screenPanel(id: string, title: string, body: TemplateResult): TemplateResult {
|
|
10
|
+
return html`<div id=${id} popover="auto" aria-labelledby=${`${id}-title`} class="fixed inset-auto bottom-12 right-3 m-0 w-[min(26rem,calc(100vw-1.5rem))] rounded-lg border border-border bg-popover p-4 text-sm text-popover-foreground shadow-lg">
|
|
11
|
+
<h2 id=${`${id}-title`} class="mb-2 text-sm font-semibold text-foreground">${title}</h2>
|
|
12
|
+
<div class="space-y-2 text-muted-foreground [&_a]:text-primary [&_a]:hover:underline [&_b]:font-medium [&_b]:text-foreground">${body}</div>
|
|
13
|
+
</div>`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The screen's Help, opened from the taskbar's Help button: what the screen shows and what each part does. */
|
|
17
|
+
export function screenHelp(body: TemplateResult): TemplateResult {
|
|
18
|
+
return screenPanel('screen-help', __('Help'), body);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The screen's options, opened from the taskbar's Screen options button: controls that change how the screen shows its content. */
|
|
22
|
+
export function screenOptions(body: TemplateResult): TemplateResult {
|
|
23
|
+
return screenPanel('screen-options', __('Screen options'), body);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** What a screen's options keep: the columns hidden, by ID, and the items a page lists. */
|
|
27
|
+
export interface ScreenPreferences {
|
|
28
|
+
hidden: string[];
|
|
29
|
+
perPage: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Items per page a screen's options accept. */
|
|
33
|
+
export const PER_PAGE = { min: 1, max: 100 } as const;
|
|
34
|
+
|
|
35
|
+
/** The cookie a screen keeps its options in, per browser, as the sidebar keeps its state; `screen` names the screen, such as `entries-posts`. */
|
|
36
|
+
export function screenCookie(screen: string): string {
|
|
37
|
+
return `cs-screen-${screen.replace(/[^a-z0-9-]/gi, '_')}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A screen's options from its cookie's value; the defaults for whatever it lacks or does not parse. */
|
|
41
|
+
export function screenPreferences(value: string | undefined, defaults: ScreenPreferences): ScreenPreferences {
|
|
42
|
+
let parsed: unknown;
|
|
43
|
+
for (const text of [value, safeDecode(value)]) {
|
|
44
|
+
try { parsed = JSON.parse(text ?? ''); break; } catch { /* try the next reading */ }
|
|
45
|
+
}
|
|
46
|
+
const saved = parsed && typeof parsed === 'object' ? parsed as Partial<Record<keyof ScreenPreferences, unknown>> : {};
|
|
47
|
+
const hidden = Array.isArray(saved.hidden) ? saved.hidden.filter((id): id is string => typeof id === 'string' && id.length <= 100).slice(0, 50) : defaults.hidden;
|
|
48
|
+
return { hidden, perPage: clampPerPage(saved.perPage, defaults.perPage) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Items per page within {@link PER_PAGE}; `fallback` for anything that is not a number. */
|
|
52
|
+
export function clampPerPage(value: unknown, fallback: number): number {
|
|
53
|
+
const number = Math.trunc(Number(value));
|
|
54
|
+
return Number.isFinite(number) && number > 0 ? Math.min(Math.max(number, PER_PAGE.min), PER_PAGE.max) : fallback;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Keep a screen's options in its cookie for a year. Client only. */
|
|
58
|
+
export function saveScreenPreferences(screen: string, preferences: ScreenPreferences): void {
|
|
59
|
+
if (typeof document === 'undefined') return;
|
|
60
|
+
try {
|
|
61
|
+
document.cookie = `${screenCookie(screen)}=${encodeURIComponent(JSON.stringify(preferences))}; Path=/dashboard; Max-Age=31536000; SameSite=Lax`;
|
|
62
|
+
} catch { /* cookies unavailable */ }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function safeDecode(value: string | undefined): string | undefined {
|
|
66
|
+
try { return value === undefined ? undefined : decodeURIComponent(value); } catch { return undefined; }
|
|
67
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DashboardModule } from './types';
|
|
2
|
+
import { authOptions } from '../auth-options';
|
|
3
|
+
import users from './modules/users';
|
|
4
|
+
import sessions from './modules/sessions';
|
|
5
|
+
import settings from './modules/settings';
|
|
6
|
+
import roles from './modules/roles';
|
|
7
|
+
|
|
8
|
+
const modules: Record<string, DashboardModule> = { users, sessions, settings, roles };
|
|
9
|
+
|
|
10
|
+
/** The modules the project chose (src/dashboard.config.ts: `modules`), in this order. */
|
|
11
|
+
export const dashboardModules: DashboardModule[] = Object.entries(modules)
|
|
12
|
+
.filter(([id]) => (authOptions.modules as readonly string[]).includes(id))
|
|
13
|
+
.map(([, module]) => module);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The table of a user's signed-in sessions, shared by the Sessions page and the Sessions tab
|
|
3
|
+
* of the user screen. The caller's own session is marked current and cannot be ended here.
|
|
4
|
+
*/
|
|
5
|
+
import { Badge, Button, Icon, Tooltip } from '@cossackframework/ui';
|
|
6
|
+
import { html, component, type TemplateResult } from '@cossackframework/renderer';
|
|
7
|
+
import { shellIcons } from './icons';
|
|
8
|
+
import type { SessionInfo } from '../auth';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parses a User-Agent string into device type + human-readable browser/OS.
|
|
12
|
+
* Intentionally lightweight (no dep) — good enough for a sessions list tooltip.
|
|
13
|
+
*/
|
|
14
|
+
export function parseUserAgent(ua: string | null): {
|
|
15
|
+
device: 'mobile' | 'tablet' | 'desktop';
|
|
16
|
+
browser: string;
|
|
17
|
+
os: string;
|
|
18
|
+
} {
|
|
19
|
+
if (!ua) return { device: 'desktop', browser: 'Unknown', os: 'Unknown' };
|
|
20
|
+
const lower = ua.toLowerCase();
|
|
21
|
+
// OS
|
|
22
|
+
let os = 'Unknown';
|
|
23
|
+
if (/windows/.test(lower)) os = 'Windows';
|
|
24
|
+
else if (/mac os|macintosh|iphone|ipad/.test(lower)) os = /ipad|iphone/.test(lower) ? 'iOS' : 'macOS';
|
|
25
|
+
else if (/android/.test(lower)) os = 'Android';
|
|
26
|
+
else if (/linux/.test(lower)) os = 'Linux';
|
|
27
|
+
// Browser (order matters — check specific ones first)
|
|
28
|
+
let browser = 'Unknown';
|
|
29
|
+
if (/edg\//.test(lower)) browser = 'Edge';
|
|
30
|
+
else if (/opr\/|opera/.test(lower)) browser = 'Opera';
|
|
31
|
+
else if (/chrome/.test(lower) && !/chromium/.test(lower)) browser = 'Chrome';
|
|
32
|
+
else if (/firefox/.test(lower)) browser = 'Firefox';
|
|
33
|
+
else if (/safari/.test(lower)) browser = 'Safari';
|
|
34
|
+
// Device type
|
|
35
|
+
let device: 'mobile' | 'tablet' | 'desktop' = 'desktop';
|
|
36
|
+
if (/ipad|tablet/.test(lower)) device = 'tablet';
|
|
37
|
+
else if (/mobi|iphone|android.*mobile/.test(lower)) device = 'mobile';
|
|
38
|
+
return { device, browser, os };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function formatDate(iso: string): string {
|
|
42
|
+
try {
|
|
43
|
+
return new Date(iso).toLocaleString();
|
|
44
|
+
} catch {
|
|
45
|
+
return iso;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The sessions, the current one first, each with a button that ends it. */
|
|
50
|
+
export function sessionTable(sessions: readonly SessionInfo[], options: { id: string; onRevoke(reference: string): unknown }): TemplateResult {
|
|
51
|
+
const iconBtn = 'inline-flex items-center justify-center [&_svg]:size-4';
|
|
52
|
+
const ordered = [...sessions.filter((s) => s.current), ...sessions.filter((s) => !s.current)];
|
|
53
|
+
const row = (s: SessionInfo) => {
|
|
54
|
+
const ua = parseUserAgent(s.userAgent);
|
|
55
|
+
const deviceLabel = ua.device === 'mobile' ? __('Mobile') : ua.device === 'tablet' ? __('Tablet') : __('Desktop');
|
|
56
|
+
const tip = `${options.id}-${encodeURIComponent(s.reference)}-agent-tip`;
|
|
57
|
+
return html`
|
|
58
|
+
<tr class="border-t border-border">
|
|
59
|
+
<td class="py-3 pr-4 text-sm text-foreground">
|
|
60
|
+
${s.userAgent
|
|
61
|
+
? component(Tooltip, { id: tip, label: `${deviceLabel} · ${ua.browser} · ${ua.os}` }, html`
|
|
62
|
+
<span tabindex="0" aria-describedby=${tip} class="inline-flex items-center gap-2 cursor-help">
|
|
63
|
+
<span class=${iconBtn}>${component(Icon, { entry: shellIcons()[ua.device], size: 16 })}</span>
|
|
64
|
+
<span>${ua.browser} · ${ua.os}</span>
|
|
65
|
+
</span>`)
|
|
66
|
+
: html`<span class="text-muted-foreground">${__('Unknown device')}</span>`}
|
|
67
|
+
</td>
|
|
68
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground">${formatDate(s.createdAt)}</td>
|
|
69
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground">${formatDate(s.expiresAt)}</td>
|
|
70
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground">${s.location ?? '—'}</td>
|
|
71
|
+
<td class="py-3 pr-4 text-sm text-muted-foreground truncate max-w-[16rem]">${s.ipAddress ?? '—'}</td>
|
|
72
|
+
<td class="py-3 text-right">
|
|
73
|
+
${s.current
|
|
74
|
+
? component(Badge, {}, __('Current'))
|
|
75
|
+
: component(Button, { variant: 'destructive', size: 'sm', '@click': () => options.onRevoke(s.reference) }, __('Sign out'))}
|
|
76
|
+
</td>
|
|
77
|
+
</tr>
|
|
78
|
+
`;
|
|
79
|
+
};
|
|
80
|
+
return html`
|
|
81
|
+
<div class="overflow-x-auto">
|
|
82
|
+
<table class="w-full" id=${options.id}>
|
|
83
|
+
<thead>
|
|
84
|
+
<tr class="text-left text-xs uppercase tracking-wide text-muted-foreground">
|
|
85
|
+
<th class="py-2 pr-4 font-medium">${__('Device')}</th>
|
|
86
|
+
<th class="py-2 pr-4 font-medium">${__('Signed in')}</th>
|
|
87
|
+
<th class="py-2 pr-4 font-medium">${__('Expires')}</th>
|
|
88
|
+
<th class="py-2 pr-4 font-medium">${__('Location')}</th>
|
|
89
|
+
<th class="py-2 pr-4 font-medium">${__('IP')}</th>
|
|
90
|
+
<th class="py-2 text-right font-medium"><span class="sr-only">${__('Actions')}</span></th>
|
|
91
|
+
</tr>
|
|
92
|
+
</thead>
|
|
93
|
+
<tbody>${ordered.map(row)}</tbody>
|
|
94
|
+
</table>
|
|
95
|
+
</div>
|
|
96
|
+
${sessions.length === 0 ? html`<p class="py-6 text-center text-sm text-muted-foreground">${__('No active sessions.')}</p>` : null}
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Tab helpers shared by the dashboard's screens: a count beside a label, and the open tab kept in the address. */
|
|
2
|
+
import { component, html, type TemplateResult } from '@cossackframework/renderer';
|
|
3
|
+
import { Badge } from '@cossackframework/ui';
|
|
4
|
+
|
|
5
|
+
/** A count beside a label, such as a tab's items; nothing when there are none, so an empty tab stays quiet. */
|
|
6
|
+
export function countBadge(count: number): TemplateResult {
|
|
7
|
+
if (!count) return html``;
|
|
8
|
+
return html`<span class="ml-1.5 inline-flex align-middle">${component(Badge, { variant: 'default' }, String(count))}</span>`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The tab the address names (`?tab=`), when it is one of `values`; the first value otherwise. */
|
|
12
|
+
export function tabFromQuery<T extends string>(query: string | undefined, values: readonly T[]): T {
|
|
13
|
+
return values.find(value => value === query) ?? values[0]!;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Keep the open tab in the address so a reload or a shared link opens it; the first (default)
|
|
18
|
+
* tab drops the parameter. Client only: replaces the history entry.
|
|
19
|
+
*/
|
|
20
|
+
export function rememberTab(value: string, values: readonly string[], name = 'tab'): void {
|
|
21
|
+
if (typeof window === 'undefined') return;
|
|
22
|
+
const url = new URL(window.location.href);
|
|
23
|
+
if (value === values[0]) url.searchParams.delete(name);
|
|
24
|
+
else url.searchParams.set(name, value);
|
|
25
|
+
window.history.replaceState(window.history.state, '', url);
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getLocale } from '@cossackframework/core';
|
|
2
|
+
|
|
3
|
+
const UNITS: readonly (readonly [Intl.RelativeTimeFormatUnit, number])[] = [['year', 31_536_000], ['month', 2_592_000], ['week', 604_800], ['day', 86_400], ['hour', 3_600], ['minute', 60]];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A time relative to `now` in the active locale, such as "3 hours ago" or "yesterday".
|
|
7
|
+
* A page takes `now` once into its state, so its server render and the browser's agree.
|
|
8
|
+
*/
|
|
9
|
+
export function timeAgo(iso: string, now: number): string {
|
|
10
|
+
const time = Date.parse(iso);
|
|
11
|
+
if (Number.isNaN(time)) return iso;
|
|
12
|
+
const seconds = (time - now) / 1000;
|
|
13
|
+
const format = new Intl.RelativeTimeFormat(getLocale(), { numeric: 'auto' });
|
|
14
|
+
for (const [unit, size] of UNITS) if (Math.abs(seconds) >= size) return format.format(Math.trunc(seconds / size), unit);
|
|
15
|
+
return format.format(0, 'second');
|
|
16
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IconEntry } from '@cossackframework/solar-icons/types';
|
|
2
|
+
|
|
3
|
+
export interface DashboardModuleLink {
|
|
4
|
+
label: string;
|
|
5
|
+
href: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface DashboardModule {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
href: string;
|
|
12
|
+
icon: IconEntry;
|
|
13
|
+
/** Who sees the module: any signed-in user, administrators, or holders of a permission. */
|
|
14
|
+
authorization: 'authenticated' | 'admin' | { permission: string };
|
|
15
|
+
placement?: 'navigation' | 'account';
|
|
16
|
+
children?: DashboardModuleLink[];
|
|
17
|
+
/** Another module whose menu lists this one's links, after its own, when the user sees both. */
|
|
18
|
+
parent?: string;
|
|
19
|
+
/** Highlighted on every page under this path, such as `/dashboard/settings` for screens with their own navigation. */
|
|
20
|
+
activeFor?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A status the dashboard's taskbar shows: what waits for the user, and where to go. */
|
|
24
|
+
export interface DashboardStatus {
|
|
25
|
+
id: string;
|
|
26
|
+
label: string;
|
|
27
|
+
href: string;
|
|
28
|
+
/** How many, shown beside the label; omitted for a plain link. */
|
|
29
|
+
count?: number;
|
|
30
|
+
tone?: 'info' | 'warning' | 'error';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A message above every dashboard screen, such as one a CMS plugin returns. */
|
|
34
|
+
export interface DashboardNotice {
|
|
35
|
+
id: string;
|
|
36
|
+
tone: 'info' | 'success' | 'warning' | 'error';
|
|
37
|
+
message: string;
|
|
38
|
+
/** A same-site path the notice links to. */
|
|
39
|
+
href?: string;
|
|
40
|
+
}
|