@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
package/src/node.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { lookup as dnsLookup, type LookupAddress } from 'node:dns';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import https from 'node:https';
|
|
4
|
+
import { isIP, type LookupFunction } from 'node:net';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
6
|
+
import { privateAddress } from './webhooks';
|
|
7
|
+
|
|
8
|
+
/** A name or address that leads to this machine or a private network. */
|
|
9
|
+
export class PrivateAddressError extends Error {
|
|
10
|
+
constructor(host: string) {
|
|
11
|
+
super(`${host} is this machine or a private network.`);
|
|
12
|
+
this.name = 'PrivateAddressError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A `fetch` for webhook deliveries on Node that refuses to connect to this machine or a private
|
|
18
|
+
* network. The check runs on the addresses the connection itself uses, so a name that resolves
|
|
19
|
+
* to a private address, or changes to one after the webhook was saved, is refused too. It sends
|
|
20
|
+
* a string body, never follows redirects, and honours `signal`.
|
|
21
|
+
*/
|
|
22
|
+
export const publicOnlyFetch: typeof globalThis.fetch = (input, init = {}) => {
|
|
23
|
+
const request = input instanceof Request ? input : null;
|
|
24
|
+
const url = new URL(request ? request.url : String(input));
|
|
25
|
+
const signal = init.signal ?? request?.signal ?? undefined;
|
|
26
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') return Promise.reject(new TypeError(`Unsupported protocol ${url.protocol}`));
|
|
27
|
+
const host = url.hostname.replace(/^\[|\]$/g, '');
|
|
28
|
+
if (isIP(host) && privateAddress(host)) return Promise.reject(new PrivateAddressError(host));
|
|
29
|
+
const headers = new Headers(init.headers ?? request?.headers);
|
|
30
|
+
const body = init.body ?? null;
|
|
31
|
+
if (body !== null && typeof body !== 'string') return Promise.reject(new TypeError('publicOnlyFetch sends string bodies only.'));
|
|
32
|
+
if (body !== null) headers.set('content-length', String(Buffer.byteLength(body)));
|
|
33
|
+
const lookup: LookupFunction = (hostname, options, callback) => {
|
|
34
|
+
dnsLookup(hostname, { ...options, all: true }, (error, addresses) => {
|
|
35
|
+
if (error) return callback(error, '', 0);
|
|
36
|
+
const list = addresses as unknown as LookupAddress[];
|
|
37
|
+
if (!list.length || list.some(entry => privateAddress(entry.address))) return callback(new PrivateAddressError(hostname), '', 0);
|
|
38
|
+
if ((options as { all?: boolean }).all) return (callback as unknown as (error: null, addresses: LookupAddress[]) => void)(null, list);
|
|
39
|
+
callback(null, list[0]!.address, list[0]!.family);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return new Promise<Response>((resolve, reject) => {
|
|
43
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
44
|
+
const send = url.protocol === 'https:' ? https.request : http.request;
|
|
45
|
+
const outgoing = send(url, { method: init.method ?? request?.method ?? 'GET', headers: Object.fromEntries(headers), lookup }, incoming => {
|
|
46
|
+
const status = incoming.statusCode ?? 0;
|
|
47
|
+
if (status < 200 || status > 599) {
|
|
48
|
+
incoming.resume();
|
|
49
|
+
return reject(new TypeError(`The receiver answered with status ${status}.`));
|
|
50
|
+
}
|
|
51
|
+
const responseHeaders = new Headers();
|
|
52
|
+
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
53
|
+
if (value === undefined) continue;
|
|
54
|
+
for (const item of Array.isArray(value) ? value : [value]) responseHeaders.append(name, item);
|
|
55
|
+
}
|
|
56
|
+
const empty = status === 204 || status === 205 || status === 304 || init.method === 'HEAD';
|
|
57
|
+
if (empty) incoming.resume();
|
|
58
|
+
resolve(new Response(empty ? null : Readable.toWeb(incoming) as ReadableStream, { status, headers: responseHeaders }));
|
|
59
|
+
});
|
|
60
|
+
const abort = () => outgoing.destroy(signal!.reason instanceof Error ? signal!.reason : new Error('aborted'));
|
|
61
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
62
|
+
outgoing.on('error', error => reject(signal?.aborted ? signal.reason : error));
|
|
63
|
+
outgoing.on('close', () => signal?.removeEventListener('abort', abort));
|
|
64
|
+
outgoing.end(body ?? undefined);
|
|
65
|
+
});
|
|
66
|
+
};
|
package/src/notes.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notes: review comments editors leave for each other on an entry, a field, a block or a
|
|
3
|
+
* passage of rich text, as Google Docs comments and WordPress 6.9 Notes. They live in their own
|
|
4
|
+
* tables beside the content, never in the collection's records, and travel live through the
|
|
5
|
+
* entry's room. Client-safe: the shapes, the anchors, the mentions and the rules; the host
|
|
6
|
+
* stores them (`server/notes.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import { CmsError } from './errors';
|
|
9
|
+
|
|
10
|
+
export const NOTE_STATUSES = Object.freeze(['open', 'resolved'] as const);
|
|
11
|
+
export type NoteStatus = (typeof NOTE_STATUSES)[number];
|
|
12
|
+
|
|
13
|
+
export const NOTE_LIMITS = Object.freeze({
|
|
14
|
+
/** A note's text, in characters. */
|
|
15
|
+
body: 4000,
|
|
16
|
+
/** The text a note on a passage quotes, in characters. */
|
|
17
|
+
quote: 200,
|
|
18
|
+
/** Notes one entry holds, roots and replies together. */
|
|
19
|
+
perEntry: 500,
|
|
20
|
+
/** People one note mentions. */
|
|
21
|
+
mentions: 20,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** Where a note is anchored. A text note also stores the passage's range and quote. */
|
|
25
|
+
export type NoteTarget =
|
|
26
|
+
| { readonly kind: 'entry' }
|
|
27
|
+
| { readonly kind: 'field'; readonly field: string }
|
|
28
|
+
| { readonly kind: 'block'; readonly field: string; readonly block: string }
|
|
29
|
+
/** A passage of a rich text document, named by its `richTextPath` (`body`, `content:b1.text`). */
|
|
30
|
+
| { readonly kind: 'text'; readonly path: string };
|
|
31
|
+
|
|
32
|
+
/** A passage of rich text, as ProseMirror positions when the note was made or last moved. */
|
|
33
|
+
export interface NoteRange {
|
|
34
|
+
readonly from: number;
|
|
35
|
+
readonly to: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Note {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
/** The entry's resource, such as `cms/posts`, and ID. */
|
|
41
|
+
readonly resource: string;
|
|
42
|
+
readonly recordId: string;
|
|
43
|
+
/** The thread's root for a reply; null on a root. */
|
|
44
|
+
readonly parentId: string | null;
|
|
45
|
+
readonly userId: string;
|
|
46
|
+
/** The anchor, as `formatNoteTarget` writes it: `entry`, `field:title`, `block:content:b1`, `text:content:b1.text`. */
|
|
47
|
+
readonly target: string;
|
|
48
|
+
readonly range: NoteRange | null;
|
|
49
|
+
readonly quote: string;
|
|
50
|
+
/** Plain text, with mentions as `@[Name](userId)`. */
|
|
51
|
+
readonly body: string;
|
|
52
|
+
/** On a root: the thread's status. Replies carry `open`. */
|
|
53
|
+
readonly status: NoteStatus;
|
|
54
|
+
readonly resolvedBy: string | null;
|
|
55
|
+
readonly resolvedAt: number | null;
|
|
56
|
+
readonly createdAt: number;
|
|
57
|
+
/** On a root: the thread's last activity (a reply, an edit, a resolution). */
|
|
58
|
+
readonly updatedAt: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A root note with its replies, oldest first. */
|
|
62
|
+
export interface NoteThread {
|
|
63
|
+
readonly root: Note;
|
|
64
|
+
readonly replies: readonly Note[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const NAME = /^[a-z][a-zA-Z0-9_]{0,62}$/;
|
|
68
|
+
/** A field anchor is a presence anchor without rows: a resource field, or a key such as `seo.description`. */
|
|
69
|
+
const FIELD = /^[a-z][a-zA-Z0-9_.]{0,100}$/;
|
|
70
|
+
const ID = /^[A-Za-z0-9_-]{1,80}$/;
|
|
71
|
+
|
|
72
|
+
export function formatNoteTarget(target: NoteTarget): string {
|
|
73
|
+
switch (target.kind) {
|
|
74
|
+
case 'entry': return 'entry';
|
|
75
|
+
case 'field': return `field:${target.field}`;
|
|
76
|
+
case 'block': return `block:${target.field}:${target.block}`;
|
|
77
|
+
case 'text': return `text:${target.path}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The anchor a stored target names, or null for one the editor cannot place. */
|
|
82
|
+
export function parseNoteTarget(text: unknown): NoteTarget | null {
|
|
83
|
+
if (typeof text !== 'string' || text.length > 200) return null;
|
|
84
|
+
if (text === 'entry') return { kind: 'entry' };
|
|
85
|
+
const [kind, ...rest] = text.split(':');
|
|
86
|
+
if (kind === 'field' && rest.length === 1 && FIELD.test(rest[0]!)) return { kind: 'field', field: rest[0]! };
|
|
87
|
+
if (kind === 'block' && rest.length === 2 && NAME.test(rest[0]!) && ID.test(rest[1]!)) return { kind: 'block', field: rest[0]!, block: rest[1]! };
|
|
88
|
+
if (kind === 'text' && rest.length) {
|
|
89
|
+
const path = rest.join(':');
|
|
90
|
+
if (/^[a-z][a-zA-Z0-9_]{0,62}(?::[A-Za-z0-9_-]{1,80}\.[a-z][a-zA-Z0-9_]{0,62})?$/.test(path)) return { kind: 'text', path };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The anchor's block, when it is a block or a passage inside one (`content:b1.text` is in block `b1`). */
|
|
96
|
+
export function noteBlock(target: NoteTarget): { field: string; block: string } | null {
|
|
97
|
+
if (target.kind === 'block') return { field: target.field, block: target.block };
|
|
98
|
+
if (target.kind === 'text') {
|
|
99
|
+
const match = /^([^:]+):([^.]+)\./.exec(target.path);
|
|
100
|
+
if (match) return { field: match[1]!, block: match[2]! };
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The anchor's field: the field itself, the field a block or a passage is in, or null on the entry. */
|
|
106
|
+
export function noteField(target: NoteTarget): string | null {
|
|
107
|
+
if (target.kind === 'entry') return null;
|
|
108
|
+
if (target.kind === 'text') return target.path.split(':')[0]!;
|
|
109
|
+
return target.field;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A trimmed note body within the limit, or a validation error. */
|
|
113
|
+
export function checkNoteBody(value: unknown): string {
|
|
114
|
+
const body = (typeof value === 'string' ? value : '').replace(/\r\n?/g, '\n').trim();
|
|
115
|
+
if (!body) throw new CmsError('CMS_VALIDATION', 'Write a note.', { fields: { body: 'Write a note.' } });
|
|
116
|
+
if ([...body].length > NOTE_LIMITS.body) throw new CmsError('CMS_VALIDATION', `Notes can be at most ${NOTE_LIMITS.body} characters.`, { fields: { body: `At most ${NOTE_LIMITS.body} characters.` } });
|
|
117
|
+
return body;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A passage's range as two nonnegative positions in order, or null for anything else. */
|
|
121
|
+
export function checkNoteRange(value: unknown): NoteRange | null {
|
|
122
|
+
if (!value || typeof value !== 'object') return null;
|
|
123
|
+
const { from, to } = value as { from?: unknown; to?: unknown };
|
|
124
|
+
if (typeof from !== 'number' || typeof to !== 'number' || !Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to < from) return null;
|
|
125
|
+
return { from, to };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A quote cut to the limit, single-spaced. */
|
|
129
|
+
export function checkNoteQuote(value: unknown): string {
|
|
130
|
+
return (typeof value === 'string' ? value : '').replace(/\s+/g, ' ').trim().slice(0, NOTE_LIMITS.quote);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A mention in a body: `@[Ada Lovelace](userId)`. */
|
|
134
|
+
const MENTION = /@\[([^\]\n]{1,100})\]\(([A-Za-z0-9_-]{1,80})\)/g;
|
|
135
|
+
|
|
136
|
+
/** The user IDs a body mentions, each once, in order, at most `NOTE_LIMITS.mentions`. */
|
|
137
|
+
export function mentionsIn(body: string): string[] {
|
|
138
|
+
const ids: string[] = [];
|
|
139
|
+
for (const match of body.matchAll(MENTION)) if (!ids.includes(match[2]!)) ids.push(match[2]!);
|
|
140
|
+
return ids.slice(0, NOTE_LIMITS.mentions);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** A body as parts to render: plain text and mentions, each with the name and user ID. */
|
|
144
|
+
export function noteParts(body: string): ({ kind: 'text'; text: string } | { kind: 'mention'; name: string; user: string })[] {
|
|
145
|
+
const parts: ({ kind: 'text'; text: string } | { kind: 'mention'; name: string; user: string })[] = [];
|
|
146
|
+
let at = 0;
|
|
147
|
+
for (const match of body.matchAll(MENTION)) {
|
|
148
|
+
if (match.index > at) parts.push({ kind: 'text', text: body.slice(at, match.index) });
|
|
149
|
+
parts.push({ kind: 'mention', name: match[1]!, user: match[2]! });
|
|
150
|
+
at = match.index + match[0].length;
|
|
151
|
+
}
|
|
152
|
+
if (at < body.length) parts.push({ kind: 'text', text: body.slice(at) });
|
|
153
|
+
return parts;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The mention token for a person, as the body stores it. */
|
|
157
|
+
export function mentionToken(user: { readonly id: string; readonly name: string }): string {
|
|
158
|
+
return `@[${user.name.replace(/[\]\n]/g, ' ').slice(0, 100)}](${user.id})`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The threads of an entry's notes: roots in the order given, each with its replies oldest first; a reply without its root is left out. */
|
|
162
|
+
export function noteThreads(notes: readonly Note[]): NoteThread[] {
|
|
163
|
+
const replies = new Map<string, Note[]>();
|
|
164
|
+
for (const note of notes) if (note.parentId) (replies.get(note.parentId) ?? replies.set(note.parentId, []).get(note.parentId)!).push(note);
|
|
165
|
+
return notes.filter(note => !note.parentId).map(root => ({ root, replies: (replies.get(root.id) ?? []).sort((a, b) => a.createdAt - b.createdAt || a.id.localeCompare(b.id)) }));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** What an editor asks the entry's room to do with notes. */
|
|
169
|
+
export type NoteAction =
|
|
170
|
+
| { readonly kind: 'create'; readonly target: string; readonly range?: NoteRange | null; readonly quote?: string; readonly body: string; readonly parentId?: string | null }
|
|
171
|
+
| { readonly kind: 'edit'; readonly id: string; readonly body: string }
|
|
172
|
+
| { readonly kind: 'resolve' | 'reopen' | 'remove'; readonly id: string }
|
|
173
|
+
/** Text notes' ranges after their passages moved, written back by the tab that saved. */
|
|
174
|
+
| { readonly kind: 'move'; readonly moves: readonly { readonly id: string; readonly range: NoteRange }[] };
|
|
175
|
+
|
|
176
|
+
/** A note action from client input, with every field checked, or a validation error. */
|
|
177
|
+
export function checkNoteAction(value: unknown): NoteAction {
|
|
178
|
+
const action = value && typeof value === 'object' ? value as Record<string, unknown> : {};
|
|
179
|
+
const id = () => { if (typeof action.id !== 'string' || !ID.test(action.id)) throw new CmsError('CMS_VALIDATION', 'Which note?'); return action.id; };
|
|
180
|
+
switch (action.kind) {
|
|
181
|
+
case 'create': {
|
|
182
|
+
const target = typeof action.target === 'string' ? action.target : 'entry';
|
|
183
|
+
if (!parseNoteTarget(target)) throw new CmsError('CMS_VALIDATION', 'The note has no place to go.');
|
|
184
|
+
const parentId = typeof action.parentId === 'string' && ID.test(action.parentId) ? action.parentId : null;
|
|
185
|
+
return { kind: 'create', target, range: checkNoteRange(action.range), quote: checkNoteQuote(action.quote), body: checkNoteBody(action.body), parentId };
|
|
186
|
+
}
|
|
187
|
+
case 'edit': return { kind: 'edit', id: id(), body: checkNoteBody(action.body) };
|
|
188
|
+
case 'resolve': case 'reopen': case 'remove': return { kind: action.kind, id: id() };
|
|
189
|
+
case 'move': {
|
|
190
|
+
const moves = (Array.isArray(action.moves) ? action.moves : []).slice(0, 100).flatMap(move => {
|
|
191
|
+
const entry = move && typeof move === 'object' ? move as Record<string, unknown> : {};
|
|
192
|
+
const range = checkNoteRange(entry.range);
|
|
193
|
+
return typeof entry.id === 'string' && ID.test(entry.id) && range ? [{ id: entry.id, range }] : [];
|
|
194
|
+
});
|
|
195
|
+
return { kind: 'move', moves };
|
|
196
|
+
}
|
|
197
|
+
default: throw new CmsError('CMS_VALIDATION', 'Unknown note action.');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A body as plain text for an email: mentions become `@Name`. */
|
|
202
|
+
export function notePlainText(body: string): string {
|
|
203
|
+
return noteParts(body).map(part => part.kind === 'mention' ? `@${part.name}` : part.text).join('');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The email to someone a note names: a new note on an entry, or a reply in their thread. */
|
|
207
|
+
export function noteMail(input: { readonly author: string; readonly title: string; readonly body: string; readonly quote: string; /** Empty when the site has no address to link to. */ readonly url: string; readonly reply: boolean; readonly site: string }): { subject: string; text: string } {
|
|
208
|
+
const title = input.title.trim() || 'an entry';
|
|
209
|
+
const subject = `${input.author} ${input.reply ? 'replied to a note on' : 'left you a note on'} “${title}”`.replace(/[\r\n]+/g, ' ').slice(0, 300);
|
|
210
|
+
const lines = [
|
|
211
|
+
`${input.author} ${input.reply ? 'replied to a note on' : 'left a note on'} “${title}”${input.site ? ` (${input.site})` : ''}:`,
|
|
212
|
+
'',
|
|
213
|
+
...(input.quote ? [`On “${input.quote}”:`, ''] : []),
|
|
214
|
+
notePlainText(input.body),
|
|
215
|
+
'',
|
|
216
|
+
// Without a link (no configured address), the reader is told where to look instead.
|
|
217
|
+
input.url ? `Open the entry's notes: ${input.url}` : 'Open the entry in the dashboard to see its notes.',
|
|
218
|
+
];
|
|
219
|
+
return { subject, text: lines.join('\n') };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Where a quote sits in a text: the occurrence nearest `near`, or -1. Used to put a note back on
|
|
224
|
+
* its words when the stored range no longer holds them.
|
|
225
|
+
*/
|
|
226
|
+
export function findQuote(text: string, quote: string, near: number): number {
|
|
227
|
+
if (!quote) return -1;
|
|
228
|
+
let best = -1;
|
|
229
|
+
let from = 0;
|
|
230
|
+
for (;;) {
|
|
231
|
+
const at = text.indexOf(quote, from);
|
|
232
|
+
if (at === -1) break;
|
|
233
|
+
if (best === -1 || Math.abs(at - near) < Math.abs(best - near)) best = at;
|
|
234
|
+
from = at + 1;
|
|
235
|
+
}
|
|
236
|
+
return best;
|
|
237
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { AccessRule } from './resource';
|
|
2
|
+
|
|
3
|
+
/** Who is acting. Built per request from the session; never from client input. */
|
|
4
|
+
export type Principal =
|
|
5
|
+
| { readonly kind: 'anonymous' }
|
|
6
|
+
| { readonly kind: 'user'; readonly id: string; readonly roles: readonly string[]; readonly permissions: readonly string[] }
|
|
7
|
+
/** Host work such as migrations, imports and outbox delivery. */
|
|
8
|
+
| { readonly kind: 'system'; readonly reason: string };
|
|
9
|
+
|
|
10
|
+
export const ANONYMOUS: Principal = Object.freeze({ kind: 'anonymous' });
|
|
11
|
+
|
|
12
|
+
export function systemPrincipal(reason: string): Principal {
|
|
13
|
+
return Object.freeze({ kind: 'system', reason });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function userPrincipal(id: string, roles: readonly string[], permissions: readonly string[]): Principal {
|
|
17
|
+
return Object.freeze({ kind: 'user', id, roles: Object.freeze([...roles]), permissions: Object.freeze([...new Set(permissions)].sort()) });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Built-in permissions. Resource permissions are `<resource>:<action>`, such as `cms/posts:update`. */
|
|
21
|
+
export const PERMISSIONS = Object.freeze({
|
|
22
|
+
/** Everything. Grant only to administrators. */
|
|
23
|
+
all: '*',
|
|
24
|
+
dashboard: 'cms:dashboard',
|
|
25
|
+
manageUsers: 'cms:users',
|
|
26
|
+
manageSchema: 'cms:schema',
|
|
27
|
+
managePlugins: 'cms:plugins',
|
|
28
|
+
manageSettings: 'cms:settings',
|
|
29
|
+
/** Define collections, their fields and taxonomies. */
|
|
30
|
+
manageCollections: 'cms:collections',
|
|
31
|
+
/** Create, rename, move and delete categories, tags and other terms. */
|
|
32
|
+
manageTerms: 'cms:terms',
|
|
33
|
+
/** Edit and delete anyone's media. */
|
|
34
|
+
manageMedia: 'cms:media',
|
|
35
|
+
/** Upload media and edit one's own. */
|
|
36
|
+
upload: 'cms:upload',
|
|
37
|
+
/** Choose and customize the theme, and edit menus. */
|
|
38
|
+
manageAppearance: 'cms:appearance',
|
|
39
|
+
/** Define roles and choose the roles of users. Without it, user managers add users with the default role. */
|
|
40
|
+
manageRoles: 'cms:roles',
|
|
41
|
+
/** Approve, edit, mark as spam and delete comments. Moderators' own comments are approved at once. */
|
|
42
|
+
moderateComments: 'cms:comments',
|
|
43
|
+
/** Manage redirects under Tools. */
|
|
44
|
+
manageRedirects: 'cms:redirects',
|
|
45
|
+
/** See the update notice and ask the project's pipeline to update the site, under Tools → Updates. */
|
|
46
|
+
manageUpdates: 'cms:updates',
|
|
47
|
+
/** Manage webhooks under Tools. */
|
|
48
|
+
manageWebhooks: 'cms:webhooks',
|
|
49
|
+
/** Read, sort, export and delete form submissions. Forms themselves are `cms/forms:*`. */
|
|
50
|
+
manageSubmissions: 'cms:submissions',
|
|
51
|
+
/** Add and change Custom HTML blocks, whose HTML runs as it is on the site. Grant only to people trusted like administrators. */
|
|
52
|
+
unfilteredHtml: 'cms:html',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The network role, held by an account rather than given by a site: full access on every site
|
|
57
|
+
* of the network, and the network dashboard. Sites cannot define a role with this ID.
|
|
58
|
+
*/
|
|
59
|
+
export const NETWORK_ADMIN = 'network_admin';
|
|
60
|
+
|
|
61
|
+
/** The main site's ID: the network database, served on the network host. */
|
|
62
|
+
export const MAIN_SITE = 'main';
|
|
63
|
+
|
|
64
|
+
/** Whether the principal is a network admin. A site role with `*` does not make one. */
|
|
65
|
+
export function isNetworkAdmin(principal: Principal): boolean {
|
|
66
|
+
return principal.kind === 'user' && principal.roles.includes(NETWORK_ADMIN);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Roles setup creates. Administrators can change them, except the administrator role itself. */
|
|
70
|
+
export const DEFAULT_ROLES = Object.freeze([
|
|
71
|
+
{ id: 'admin', name: 'Administrator', permissions: ['*'] },
|
|
72
|
+
{ id: 'editor', name: 'Editor', permissions: ['cms:dashboard', 'cms:terms', 'cms:media', 'cms:upload', 'cms:comments', 'cms:submissions', 'cms/*', 'app/*'] },
|
|
73
|
+
{ id: 'author', name: 'Author', permissions: ['cms:dashboard', 'cms:upload', 'cms/posts:create'] },
|
|
74
|
+
{ id: 'subscriber', name: 'Subscriber', permissions: [] },
|
|
75
|
+
] as const);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Permission patterns: `*` matches everything, `cms/*` every permission starting with `cms/`,
|
|
79
|
+
* and `cms/posts:*` every action on one resource.
|
|
80
|
+
*/
|
|
81
|
+
export function permissionMatches(pattern: string, permission: string): boolean {
|
|
82
|
+
if (pattern === '*' || pattern === permission) return true;
|
|
83
|
+
return pattern.endsWith('*') && permission.startsWith(pattern.slice(0, -1));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function hasPermission(principal: Principal, permission: string): boolean {
|
|
87
|
+
if (principal.kind === 'system') return true;
|
|
88
|
+
if (principal.kind !== 'user') return false;
|
|
89
|
+
return principal.permissions.some(pattern => permissionMatches(pattern, permission));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Whether the principal holds every one of the permissions (each pattern of them as written, so
|
|
94
|
+
* `cms/*` needs `cms/*` or `*`): what a role manager may put in a role or give someone, without
|
|
95
|
+
* reaching beyond their own permissions.
|
|
96
|
+
*/
|
|
97
|
+
export function holdsAll(principal: Principal, permissions: readonly string[]): boolean {
|
|
98
|
+
return permissions.every(permission => hasPermission(principal, permission));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Records an action is limited to: the principal's own, or those matching any of the conditions. */
|
|
102
|
+
export interface RecordScope {
|
|
103
|
+
readonly owner: boolean;
|
|
104
|
+
readonly where: readonly { readonly [field: string]: string | number | boolean }[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Evaluate a rule. `owner` means the action is allowed only on records the principal created,
|
|
109
|
+
* which the host enforces with a query condition, not by trusting input.
|
|
110
|
+
*/
|
|
111
|
+
export function evaluateRule(rule: AccessRule, principal: Principal): 'allow' | 'owner' | 'deny' {
|
|
112
|
+
const scope = ruleScope(rule, principal);
|
|
113
|
+
return scope === 'allow' || scope === 'deny' ? scope : 'owner';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Like `evaluateRule`, with the record conditions of `owner` and `where` rules. */
|
|
117
|
+
export function ruleScope(rule: AccessRule, principal: Principal): 'allow' | 'deny' | RecordScope {
|
|
118
|
+
if (principal.kind === 'system') return 'allow';
|
|
119
|
+
if (rule === 'public') return 'allow';
|
|
120
|
+
if (rule === 'none') return 'deny';
|
|
121
|
+
if (rule === 'authenticated') return principal.kind === 'user' ? 'allow' : 'deny';
|
|
122
|
+
if (rule === 'owner') return principal.kind === 'user' ? { owner: true, where: [] } : 'deny';
|
|
123
|
+
if ('permission' in rule) return hasPermission(principal, rule.permission) ? 'allow' : 'deny';
|
|
124
|
+
if ('where' in rule) return { owner: false, where: [rule.where] };
|
|
125
|
+
let owner = false;
|
|
126
|
+
const where: RecordScope['where'][number][] = [];
|
|
127
|
+
for (const entry of rule.any) {
|
|
128
|
+
const outcome = ruleScope(entry, principal);
|
|
129
|
+
if (outcome === 'allow') return 'allow';
|
|
130
|
+
if (outcome === 'deny') continue;
|
|
131
|
+
owner ||= outcome.owner;
|
|
132
|
+
where.push(...outcome.where);
|
|
133
|
+
}
|
|
134
|
+
return owner || where.length ? { owner, where } : 'deny';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function principalId(principal: Principal): string {
|
|
138
|
+
return principal.kind === 'user' ? principal.id : principal.kind === 'system' ? `system:${principal.reason}` : 'anonymous';
|
|
139
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Plugin settings are scalar declarations; the host supplies their namespace and access. */
|
|
2
|
+
import { fieldProblems, type FieldDeclaration } from './fields';
|
|
3
|
+
import { OWNER_NAME } from './resource';
|
|
4
|
+
import type { SettingDeclaration, SettingsSection } from './settings';
|
|
5
|
+
import { settingControlProblems } from './settings-controls';
|
|
6
|
+
|
|
7
|
+
/** Uses the shared field builders; manifest validation limits kinds and defaults to scalars. */
|
|
8
|
+
export type PluginSettingDeclaration = Pick<SettingDeclaration, 'kind' | 'default' | 'label' | 'description' | 'required' | 'nullable' | 'min' | 'max' | 'pattern' | 'values' | 'choices' | 'section' | 'control' | 'fileKinds'>;
|
|
9
|
+
|
|
10
|
+
export interface PluginSettingsDeclaration {
|
|
11
|
+
readonly label: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
readonly sections?: readonly SettingsSection[];
|
|
14
|
+
readonly fields: { readonly [name: string]: PluginSettingDeclaration };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const PLUGIN_SETTINGS_LIMITS = Object.freeze({ fields: 128, sections: 32, label: 120, description: 2000 });
|
|
18
|
+
const KINDS = new Set(['string', 'text', 'enum', 'boolean', 'integer', 'number']);
|
|
19
|
+
const OPTIONS = new Set(['kind', 'label', 'description', 'required', 'nullable', 'default', 'min', 'max', 'pattern', 'values', 'choices', 'section', 'control', 'fileKinds']);
|
|
20
|
+
const UNSAFE = new Set(['__proto__', 'constructor', 'prototype']);
|
|
21
|
+
const SECTION_ID = /^[a-z][a-z0-9-]{0,40}$/;
|
|
22
|
+
|
|
23
|
+
/** The plugin's storage namespace. A colon keeps it distinct from every ordinary group. */
|
|
24
|
+
export function pluginSettingsGroupId(name: string): string {
|
|
25
|
+
if (typeof name !== 'string' || !OWNER_NAME.test(name) || name.length > 64) throw new TypeError('Invalid plugin settings owner.');
|
|
26
|
+
return `plugin:${name}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function object(value: unknown): value is Record<string, unknown> {
|
|
30
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
31
|
+
&& (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Check untrusted manifest data before the host adds any of its settings. */
|
|
35
|
+
export function pluginSettingsProblems(value: unknown): string[] {
|
|
36
|
+
if (!object(value)) return ['settings must be an object.'];
|
|
37
|
+
const problems: string[] = [];
|
|
38
|
+
const label = (given: unknown, at: string, required = false) => {
|
|
39
|
+
if (given === undefined && !required) return;
|
|
40
|
+
if (typeof given !== 'string' || !given.trim() || given.length > PLUGIN_SETTINGS_LIMITS.label) problems.push(`${at} must be text of 1-${PLUGIN_SETTINGS_LIMITS.label} characters.`);
|
|
41
|
+
};
|
|
42
|
+
const description = (given: unknown, at: string) => {
|
|
43
|
+
if (given !== undefined && (typeof given !== 'string' || given.length > PLUGIN_SETTINGS_LIMITS.description)) problems.push(`${at} must be text of at most ${PLUGIN_SETTINGS_LIMITS.description} characters.`);
|
|
44
|
+
};
|
|
45
|
+
for (const key of Object.keys(value)) if (!['label', 'description', 'sections', 'fields'].includes(key)) problems.push(`settings.${key} is not a settings declaration option.`);
|
|
46
|
+
label(value.label, 'settings.label', true);
|
|
47
|
+
description(value.description, 'settings.description');
|
|
48
|
+
const sections = new Set<string>();
|
|
49
|
+
if (value.sections !== undefined && (!Array.isArray(value.sections) || value.sections.length > PLUGIN_SETTINGS_LIMITS.sections)) {
|
|
50
|
+
problems.push(`settings.sections must list at most ${PLUGIN_SETTINGS_LIMITS.sections} sections.`);
|
|
51
|
+
} else for (const [index, section] of ((value.sections ?? []) as unknown[]).entries()) {
|
|
52
|
+
const at = `settings.sections[${index}]`;
|
|
53
|
+
if (!object(section)) { problems.push(`${at} must be a section object.`); continue; }
|
|
54
|
+
for (const key of Object.keys(section)) if (!['id', 'label', 'description'].includes(key)) problems.push(`${at}.${key} is not a section option.`);
|
|
55
|
+
if (typeof section.id !== 'string' || !SECTION_ID.test(section.id) || UNSAFE.has(section.id)) problems.push(`${at}.id must be a lowercase section name.`);
|
|
56
|
+
else if (sections.has(section.id)) problems.push(`${at}.id is declared twice.`);
|
|
57
|
+
else sections.add(section.id);
|
|
58
|
+
label(section.label, `${at}.label`, true);
|
|
59
|
+
description(section.description, `${at}.description`);
|
|
60
|
+
}
|
|
61
|
+
if (!object(value.fields)) return [...problems, 'settings.fields must be an object of field declarations.'];
|
|
62
|
+
const fields = Object.entries(value.fields);
|
|
63
|
+
if (!fields.length || fields.length > PLUGIN_SETTINGS_LIMITS.fields) problems.push(`settings.fields must declare 1-${PLUGIN_SETTINGS_LIMITS.fields} fields.`);
|
|
64
|
+
for (const [name, declaration] of fields) {
|
|
65
|
+
const at = `settings.fields.${name}`;
|
|
66
|
+
if (UNSAFE.has(name)) { problems.push(`${at} is not a safe field name.`); continue; }
|
|
67
|
+
if (!object(declaration) || typeof declaration.kind !== 'string' || !KINDS.has(declaration.kind)) {
|
|
68
|
+
problems.push(`${at} must be a string, text, enum, boolean, integer or number field.`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
let validShape = true;
|
|
72
|
+
for (const key of Object.keys(declaration)) if (!OPTIONS.has(key)) { problems.push(`${at}.${key} is not a plugin setting option.`); validShape = false; }
|
|
73
|
+
label(declaration.label, `${at}.label`);
|
|
74
|
+
description(declaration.description, `${at}.description`);
|
|
75
|
+
for (const key of ['required', 'nullable']) if (declaration[key] !== undefined && typeof declaration[key] !== 'boolean') { problems.push(`${at}.${key} must be true or false.`); validShape = false; }
|
|
76
|
+
if (declaration.section !== undefined && (typeof declaration.section !== 'string' || !sections.has(declaration.section))) problems.push(`${at}.section must name a declared section.`);
|
|
77
|
+
if (declaration.pattern !== undefined && typeof declaration.pattern !== 'string') { problems.push(`${at}.pattern must be a regular expression string.`); validShape = false; }
|
|
78
|
+
for (const key of ['min', 'max']) {
|
|
79
|
+
const bound = declaration[key];
|
|
80
|
+
if (bound === undefined) continue;
|
|
81
|
+
if (!['string', 'text', 'integer', 'number'].includes(declaration.kind) || typeof bound !== 'number' || !Number.isFinite(bound)) {
|
|
82
|
+
problems.push(`${at}.${key} applies to text or numeric fields and must be a finite number.`);
|
|
83
|
+
validShape = false;
|
|
84
|
+
} else if (['string', 'text'].includes(declaration.kind) && (!Number.isSafeInteger(bound) || bound < 0)) {
|
|
85
|
+
problems.push(`${at}.${key} must be a nonnegative whole character count.`);
|
|
86
|
+
validShape = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (typeof declaration.min === 'number' && typeof declaration.max === 'number' && declaration.min > declaration.max) problems.push(`${at}.min must not exceed max.`);
|
|
90
|
+
if (declaration.kind === 'enum') {
|
|
91
|
+
if (!Array.isArray(declaration.values) || declaration.values.some(entry => typeof entry !== 'string')) { problems.push(`${at}.values must list enum strings.`); validShape = false; }
|
|
92
|
+
} else if (declaration.values !== undefined) { problems.push(`${at}.values applies to enum fields only.`); validShape = false; }
|
|
93
|
+
if (declaration.choices !== undefined) {
|
|
94
|
+
if (declaration.kind !== 'enum' || !object(declaration.choices)) problems.push(`${at}.choices applies to enum fields and must map values to labels.`);
|
|
95
|
+
else for (const [choice, text] of Object.entries(declaration.choices)) {
|
|
96
|
+
if (UNSAFE.has(choice) || !Array.isArray(declaration.values) || !declaration.values.includes(choice)) problems.push(`${at}.choices.${choice} must name an enum value.`);
|
|
97
|
+
label(text, `${at}.choices.${choice}`, true);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (declaration.default !== undefined && declaration.default !== null && !['string', 'number', 'boolean'].includes(typeof declaration.default)) {
|
|
101
|
+
problems.push(`${at}.default must be a scalar value or null.`);
|
|
102
|
+
validShape = false;
|
|
103
|
+
}
|
|
104
|
+
if (validShape) {
|
|
105
|
+
// A malformed rule can also throw while the shared checker validates its default.
|
|
106
|
+
try {
|
|
107
|
+
problems.push(...fieldProblems(name, declaration as unknown as FieldDeclaration).map(problem => `settings: ${problem}`));
|
|
108
|
+
problems.push(...settingControlProblems(name, declaration as unknown as SettingDeclaration).map(problem => `settings: ${problem}`));
|
|
109
|
+
}
|
|
110
|
+
catch { problems.push(`${at} has invalid validation rules or defaults.`); }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return problems;
|
|
114
|
+
}
|
package/src/records.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** JSON-safe public shape of a record. bigint fields are decimal strings; vectors are number arrays. */
|
|
2
|
+
export interface RecordShape {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly rev: number;
|
|
5
|
+
readonly createdAt: number;
|
|
6
|
+
readonly updatedAt: number;
|
|
7
|
+
/** User who created the record, for resources with ownership. */
|
|
8
|
+
readonly owner: string | null;
|
|
9
|
+
readonly [field: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RecordPage {
|
|
13
|
+
readonly records: readonly RecordShape[];
|
|
14
|
+
/** Pass as `after` to read the next page; absent on the last page. */
|
|
15
|
+
readonly next?: string;
|
|
16
|
+
/** More records follow, for pages read with `order` or `offset`. */
|
|
17
|
+
readonly more?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface RevisionShape {
|
|
21
|
+
readonly revision: number;
|
|
22
|
+
readonly at: number;
|
|
23
|
+
readonly actor: string | null;
|
|
24
|
+
readonly data: RecordShape;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type Scalar = string | number | boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A condition on one declared field: a value (or null) for equality, `ne`, `in`, a range for
|
|
31
|
+
* numbers and times, and `contains` / `containsAny` for indexed list fields such as terms.
|
|
32
|
+
*/
|
|
33
|
+
export type FieldFilter = Scalar | null
|
|
34
|
+
| { readonly ne: Scalar | null }
|
|
35
|
+
/** One of the values; a `null` among them also matches an unset field. */
|
|
36
|
+
| { readonly in: readonly (Scalar | null)[] }
|
|
37
|
+
| { readonly gt?: number; readonly gte?: number; readonly lt?: number; readonly lte?: number }
|
|
38
|
+
| { readonly contains: Scalar }
|
|
39
|
+
| { readonly containsAny: readonly Scalar[] };
|
|
40
|
+
|
|
41
|
+
export interface ListFilter {
|
|
42
|
+
readonly where?: { readonly [field: string]: FieldFilter };
|
|
43
|
+
/** Records created by this user ID (resources with ownership). */
|
|
44
|
+
readonly owner?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ListOptions extends ListFilter {
|
|
48
|
+
/** Sort by a declared scalar field, `createdAt` or `updatedAt`. Default: `updatedAt`, newest first. */
|
|
49
|
+
readonly order?: { readonly field: string; readonly direction?: 'asc' | 'desc' };
|
|
50
|
+
/** 1..100, default 20. */
|
|
51
|
+
readonly limit?: number;
|
|
52
|
+
/** Cursor from a previous page, for the default order. */
|
|
53
|
+
readonly after?: string;
|
|
54
|
+
/** Records to skip, up to 10,000, for numbered pages. */
|
|
55
|
+
readonly offset?: number;
|
|
56
|
+
}
|