@basicbenframework/cms 0.0.0-stage → 0.6.0
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 +9 -0
- package/README.md +206 -2
- package/db/migrations/001_create_users.js +15 -0
- package/db/migrations/002_create_posts.js +18 -0
- package/db/migrations/003_create_categories.js +19 -0
- package/db/migrations/004_create_tags.js +16 -0
- package/db/migrations/005_create_post_tags.js +16 -0
- package/db/migrations/006_create_pages.js +26 -0
- package/db/migrations/007_create_comments.js +24 -0
- package/db/migrations/008_create_media.js +22 -0
- package/db/migrations/009_update_posts_blogging.js +27 -0
- package/db/migrations/010_create_settings.js +29 -0
- package/db/migrations/011_add_user_roles.js +23 -0
- package/db/migrations/012_create_auth_tokens.js +30 -0
- package/db/migrations/013_add_email_verified.js +24 -0
- package/db/migrations/014_create_user_two_factor.js +30 -0
- package/db/migrations/015_create_user_credentials.js +35 -0
- package/db/migrations/016_create_rate_limits.js +31 -0
- package/db/migrations/017_add_content_html.js +38 -0
- package/db/migrations/018_create_api_tokens.js +34 -0
- package/db/migrations/019_create_post_categories.js +40 -0
- package/db/migrations/020_add_author_profiles.js +60 -0
- package/db/migrations/021_add_page_featured_image.js +23 -0
- package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
- package/db/migrations/023_add_user_session_controls.js +25 -0
- package/db/migrations/024_add_post_status_and_trash.js +45 -0
- package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
- package/db/migrations/026_create_post_revisions.js +29 -0
- package/db/migrations/027_add_media_dimensions.js +19 -0
- package/db/migrations/028_create_navigation_menus.js +65 -0
- package/db/migrations/029_create_redirects.js +40 -0
- package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
- package/db/migrations/031_create_post_locks.js +38 -0
- package/db/migrations/032_create_snippets.js +31 -0
- package/db/migrations/033_create_members.js +70 -0
- package/db/migrations/034_add_post_visibility.js +28 -0
- package/db/migrations/035_create_newsletters.js +72 -0
- package/db/migrations/036_create_analytics.js +89 -0
- package/db/migrations/037_create_ops_heartbeats.js +30 -0
- package/db/migrations/038_create_content_types.js +84 -0
- package/db/migrations/039_create_content_type_fields.js +47 -0
- package/db/migrations/040_create_taxonomies.js +80 -0
- package/db/migrations/041_add_newsletter_handoff.js +28 -0
- package/db/migrations/042_create_mysendbox_contacts.js +63 -0
- package/lib/cli/backup.d.mts +2 -0
- package/lib/cli/backup.mjs +124 -0
- package/lib/cli/export.d.mts +2 -0
- package/lib/cli/export.mjs +54 -0
- package/lib/cli/import-ghost.d.mts +2 -0
- package/lib/cli/import-ghost.mjs +50 -0
- package/lib/cli/import-json.d.mts +2 -0
- package/lib/cli/import-json.mjs +61 -0
- package/lib/cli/import-wordpress.d.mts +2 -0
- package/lib/cli/import-wordpress.mjs +169 -0
- package/lib/cli/import-wxr.d.mts +2 -0
- package/lib/cli/import-wxr.mjs +55 -0
- package/lib/cli/index.d.mts +2 -0
- package/lib/cli/index.mjs +53 -0
- package/lib/cli/lib/backup.d.mts +112 -0
- package/lib/cli/lib/backup.mjs +297 -0
- package/lib/cli/lib/ghost.d.mts +30 -0
- package/lib/cli/lib/ghost.mjs +201 -0
- package/lib/cli/lib/html-to-markdown.d.mts +61 -0
- package/lib/cli/lib/html-to-markdown.mjs +523 -0
- package/lib/cli/lib/import-common.d.mts +100 -0
- package/lib/cli/lib/import-common.mjs +252 -0
- package/lib/cli/lib/json-import.d.mts +22 -0
- package/lib/cli/lib/json-import.mjs +422 -0
- package/lib/cli/lib/site-import.d.mts +32 -0
- package/lib/cli/lib/site-import.mjs +456 -0
- package/lib/cli/lib/wordpress-rest.d.mts +25 -0
- package/lib/cli/lib/wordpress-rest.mjs +177 -0
- package/lib/cli/lib/wxr.d.mts +18 -0
- package/lib/cli/lib/wxr.mjs +307 -0
- package/lib/cli/lib/xml.d.mts +33 -0
- package/lib/cli/lib/xml.mjs +186 -0
- package/lib/cli/restore.d.mts +2 -0
- package/lib/cli/restore.mjs +98 -0
- package/lib/client/components/Alert.d.ts +7 -0
- package/lib/client/components/Alert.js +8 -0
- package/lib/client/components/Avatar.d.ts +15 -0
- package/lib/client/components/Avatar.js +10 -0
- package/lib/client/components/BackLink.d.ts +7 -0
- package/lib/client/components/BackLink.js +6 -0
- package/lib/client/components/Button.d.ts +7 -0
- package/lib/client/components/Button.js +12 -0
- package/lib/client/components/Card.d.ts +7 -0
- package/lib/client/components/Card.js +6 -0
- package/lib/client/components/CommentThread.d.ts +15 -0
- package/lib/client/components/CommentThread.js +101 -0
- package/lib/client/components/Empty.d.ts +6 -0
- package/lib/client/components/Empty.js +6 -0
- package/lib/client/components/Input.d.ts +6 -0
- package/lib/client/components/Input.js +6 -0
- package/lib/client/components/Link.d.ts +31 -0
- package/lib/client/components/Link.js +49 -0
- package/lib/client/components/Loading.d.ts +1 -0
- package/lib/client/components/Loading.js +6 -0
- package/lib/client/components/Logo.d.ts +5 -0
- package/lib/client/components/Logo.js +4 -0
- package/lib/client/components/MarkdownEditor.d.ts +41 -0
- package/lib/client/components/MarkdownEditor.js +156 -0
- package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
- package/lib/client/components/Nav/DarkModeToggle.js +6 -0
- package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
- package/lib/client/components/Nav/DesktopNav.js +9 -0
- package/lib/client/components/Nav/MobileNav.d.ts +9 -0
- package/lib/client/components/Nav/MobileNav.js +15 -0
- package/lib/client/components/NavLink.d.ts +8 -0
- package/lib/client/components/NavLink.js +6 -0
- package/lib/client/components/PageHeader.d.ts +8 -0
- package/lib/client/components/PageHeader.js +6 -0
- package/lib/client/components/PostCard.d.ts +8 -0
- package/lib/client/components/PostCard.js +7 -0
- package/lib/client/components/Textarea.d.ts +6 -0
- package/lib/client/components/Textarea.js +6 -0
- package/lib/client/components/ThemeContext.d.ts +18 -0
- package/lib/client/components/ThemeContext.js +8 -0
- package/lib/client/components/admin/AdminIcons.d.ts +13 -0
- package/lib/client/components/admin/AdminIcons.js +66 -0
- package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
- package/lib/client/components/admin/ContentModelPanels.js +93 -0
- package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
- package/lib/client/components/admin/FeaturedImageBox.js +24 -0
- package/lib/client/components/admin/MediaGrid.d.ts +23 -0
- package/lib/client/components/admin/MediaGrid.js +69 -0
- package/lib/client/components/admin/MediaPicker.d.ts +17 -0
- package/lib/client/components/admin/MediaPicker.js +61 -0
- package/lib/client/components/admin/Pagination.d.ts +27 -0
- package/lib/client/components/admin/Pagination.js +29 -0
- package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
- package/lib/client/components/admin/SnippetPicker.js +65 -0
- package/lib/client/components/admin/TermPicker.d.ts +52 -0
- package/lib/client/components/admin/TermPicker.js +58 -0
- package/lib/client/contexts/ToastContext.d.ts +12 -0
- package/lib/client/contexts/ToastContext.js +49 -0
- package/lib/client/features.d.ts +11 -0
- package/lib/client/features.js +7 -0
- package/lib/client/hooks/useContentTypes.d.ts +48 -0
- package/lib/client/hooks/useContentTypes.js +48 -0
- package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
- package/lib/client/hooks/useMediaLibrary.js +189 -0
- package/lib/client/hooks/usePostLock.d.ts +32 -0
- package/lib/client/hooks/usePostLock.js +107 -0
- package/lib/client/host/index.d.ts +71 -0
- package/lib/client/host/index.js +58 -0
- package/lib/client/i18n/index.d.ts +79 -0
- package/lib/client/i18n/index.js +177 -0
- package/lib/client/i18n/locales/es/content.d.ts +4 -0
- package/lib/client/i18n/locales/es/content.js +220 -0
- package/lib/client/i18n/locales/es/editor.d.ts +9 -0
- package/lib/client/i18n/locales/es/editor.js +144 -0
- package/lib/client/i18n/locales/es/index.d.ts +8 -0
- package/lib/client/i18n/locales/es/index.js +7 -0
- package/lib/client/i18n/locales/es/layout.d.ts +4 -0
- package/lib/client/i18n/locales/es/layout.js +35 -0
- package/lib/client/i18n/locales/es/people.d.ts +4 -0
- package/lib/client/i18n/locales/es/people.js +187 -0
- package/lib/client/i18n/locales/es/site.d.ts +4 -0
- package/lib/client/i18n/locales/es/site.js +208 -0
- package/lib/client/layouts/AdminLayout.d.ts +7 -0
- package/lib/client/layouts/AdminLayout.js +1046 -0
- package/lib/client/layouts/AppLayout.d.ts +6 -0
- package/lib/client/layouts/AppLayout.js +19 -0
- package/lib/client/layouts/AuthLayout.d.ts +6 -0
- package/lib/client/layouts/AuthLayout.js +14 -0
- package/lib/client/layouts/DocsLayout.d.ts +6 -0
- package/lib/client/layouts/DocsLayout.js +28 -0
- package/lib/client/layouts/RootLayout.d.ts +6 -0
- package/lib/client/layouts/RootLayout.js +11 -0
- package/lib/client/pages/AcceptInvite.d.ts +8 -0
- package/lib/client/pages/AcceptInvite.js +60 -0
- package/lib/client/pages/Auth.d.ts +1 -0
- package/lib/client/pages/Auth.js +40 -0
- package/lib/client/pages/Authentication.d.ts +1 -0
- package/lib/client/pages/Authentication.js +230 -0
- package/lib/client/pages/Content.d.ts +1 -0
- package/lib/client/pages/Content.js +21 -0
- package/lib/client/pages/Database.d.ts +1 -0
- package/lib/client/pages/Database.js +264 -0
- package/lib/client/pages/Extending.d.ts +1 -0
- package/lib/client/pages/Extending.js +28 -0
- package/lib/client/pages/Feed.d.ts +1 -0
- package/lib/client/pages/Feed.js +19 -0
- package/lib/client/pages/FeedPost.d.ts +1 -0
- package/lib/client/pages/FeedPost.js +31 -0
- package/lib/client/pages/ForgotPassword.d.ts +8 -0
- package/lib/client/pages/ForgotPassword.js +38 -0
- package/lib/client/pages/GettingStarted.d.ts +1 -0
- package/lib/client/pages/GettingStarted.js +84 -0
- package/lib/client/pages/Headless.d.ts +1 -0
- package/lib/client/pages/Headless.js +49 -0
- package/lib/client/pages/Home.d.ts +1 -0
- package/lib/client/pages/Home.js +67 -0
- package/lib/client/pages/PostForm.d.ts +1 -0
- package/lib/client/pages/PostForm.js +55 -0
- package/lib/client/pages/Posts.d.ts +1 -0
- package/lib/client/pages/Posts.js +35 -0
- package/lib/client/pages/Profile.d.ts +1 -0
- package/lib/client/pages/Profile.js +153 -0
- package/lib/client/pages/ResetPassword.d.ts +8 -0
- package/lib/client/pages/ResetPassword.js +52 -0
- package/lib/client/pages/Routing.d.ts +1 -0
- package/lib/client/pages/Routing.js +192 -0
- package/lib/client/pages/Storage.d.ts +1 -0
- package/lib/client/pages/Storage.js +54 -0
- package/lib/client/pages/Testing.d.ts +1 -0
- package/lib/client/pages/Testing.js +141 -0
- package/lib/client/pages/Validation.d.ts +1 -0
- package/lib/client/pages/Validation.js +123 -0
- package/lib/client/pages/admin/Categories.d.ts +2 -0
- package/lib/client/pages/admin/Categories.js +75 -0
- package/lib/client/pages/admin/Comments.d.ts +11 -0
- package/lib/client/pages/admin/Comments.js +247 -0
- package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
- package/lib/client/pages/admin/ContentTypes.js +163 -0
- package/lib/client/pages/admin/Dashboard.d.ts +2 -0
- package/lib/client/pages/admin/Dashboard.js +66 -0
- package/lib/client/pages/admin/Health.d.ts +12 -0
- package/lib/client/pages/admin/Health.js +148 -0
- package/lib/client/pages/admin/Media.d.ts +2 -0
- package/lib/client/pages/admin/Media.js +101 -0
- package/lib/client/pages/admin/Navigation.d.ts +9 -0
- package/lib/client/pages/admin/Navigation.js +230 -0
- package/lib/client/pages/admin/Pages.d.ts +2 -0
- package/lib/client/pages/admin/Pages.js +53 -0
- package/lib/client/pages/admin/PostEditor.d.ts +17 -0
- package/lib/client/pages/admin/PostEditor.js +532 -0
- package/lib/client/pages/admin/Posts.d.ts +2 -0
- package/lib/client/pages/admin/Posts.js +152 -0
- package/lib/client/pages/admin/Redirects.d.ts +10 -0
- package/lib/client/pages/admin/Redirects.js +87 -0
- package/lib/client/pages/admin/Settings.d.ts +2 -0
- package/lib/client/pages/admin/Settings.js +111 -0
- package/lib/client/pages/admin/Snippets.d.ts +14 -0
- package/lib/client/pages/admin/Snippets.js +85 -0
- package/lib/client/pages/admin/Tags.d.ts +2 -0
- package/lib/client/pages/admin/Tags.js +74 -0
- package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
- package/lib/client/pages/admin/Taxonomies.js +130 -0
- package/lib/client/pages/admin/Tokens.d.ts +9 -0
- package/lib/client/pages/admin/Tokens.js +260 -0
- package/lib/client/pages/admin/Tools.d.ts +12 -0
- package/lib/client/pages/admin/Tools.js +111 -0
- package/lib/client/pages/admin/Users.d.ts +13 -0
- package/lib/client/pages/admin/Users.js +313 -0
- package/lib/client/pages/api-reference.d.ts +33 -0
- package/lib/client/pages/api-reference.js +198 -0
- package/lib/client/styles.css +37 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.js +39 -0
- package/lib/controllers/AdminController.d.ts +46 -0
- package/lib/controllers/AdminController.js +134 -0
- package/lib/controllers/AuthController.d.ts +15 -0
- package/lib/controllers/AuthController.js +194 -0
- package/lib/controllers/AuthorController.d.ts +17 -0
- package/lib/controllers/AuthorController.js +19 -0
- package/lib/controllers/CategoryController.d.ts +10 -0
- package/lib/controllers/CategoryController.js +88 -0
- package/lib/controllers/CommentController.d.ts +68 -0
- package/lib/controllers/CommentController.js +438 -0
- package/lib/controllers/ContentTypeController.d.ts +24 -0
- package/lib/controllers/ContentTypeController.js +91 -0
- package/lib/controllers/EmailVerificationController.d.ts +33 -0
- package/lib/controllers/EmailVerificationController.js +116 -0
- package/lib/controllers/ExportController.d.ts +15 -0
- package/lib/controllers/ExportController.js +41 -0
- package/lib/controllers/FeedController.d.ts +14 -0
- package/lib/controllers/FeedController.js +246 -0
- package/lib/controllers/HealthController.d.ts +21 -0
- package/lib/controllers/HealthController.js +176 -0
- package/lib/controllers/HomeController.d.ts +12 -0
- package/lib/controllers/HomeController.js +16 -0
- package/lib/controllers/MediaController.d.ts +24 -0
- package/lib/controllers/MediaController.js +189 -0
- package/lib/controllers/NavigationController.d.ts +22 -0
- package/lib/controllers/NavigationController.js +176 -0
- package/lib/controllers/PageController.d.ts +13 -0
- package/lib/controllers/PageController.js +172 -0
- package/lib/controllers/PasskeyController.d.ts +36 -0
- package/lib/controllers/PasskeyController.js +201 -0
- package/lib/controllers/PasswordResetController.d.ts +44 -0
- package/lib/controllers/PasswordResetController.js +160 -0
- package/lib/controllers/PostController.d.ts +51 -0
- package/lib/controllers/PostController.js +538 -0
- package/lib/controllers/PostLockController.d.ts +62 -0
- package/lib/controllers/PostLockController.js +101 -0
- package/lib/controllers/ProfileController.d.ts +13 -0
- package/lib/controllers/ProfileController.js +160 -0
- package/lib/controllers/PublicApiController.d.ts +23 -0
- package/lib/controllers/PublicApiController.js +100 -0
- package/lib/controllers/RedirectController.d.ts +32 -0
- package/lib/controllers/RedirectController.js +95 -0
- package/lib/controllers/SettingsController.d.ts +28 -0
- package/lib/controllers/SettingsController.js +105 -0
- package/lib/controllers/SnippetController.d.ts +27 -0
- package/lib/controllers/SnippetController.js +123 -0
- package/lib/controllers/TagController.d.ts +9 -0
- package/lib/controllers/TagController.js +70 -0
- package/lib/controllers/TaxonomyController.d.ts +24 -0
- package/lib/controllers/TaxonomyController.js +149 -0
- package/lib/controllers/TokenController.d.ts +27 -0
- package/lib/controllers/TokenController.js +83 -0
- package/lib/controllers/TwoFactorController.d.ts +31 -0
- package/lib/controllers/TwoFactorController.js +213 -0
- package/lib/controllers/UserController.d.ts +110 -0
- package/lib/controllers/UserController.js +504 -0
- package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
- package/lib/features/analytics/AnalyticsPage.js +123 -0
- package/lib/features/analytics/admin.d.ts +3 -0
- package/lib/features/analytics/admin.js +9 -0
- package/lib/features/analytics/controller.d.ts +19 -0
- package/lib/features/analytics/controller.js +79 -0
- package/lib/features/analytics/helpers.d.ts +84 -0
- package/lib/features/analytics/helpers.js +181 -0
- package/lib/features/analytics/i18n/es.d.ts +4 -0
- package/lib/features/analytics/i18n/es.js +31 -0
- package/lib/features/analytics/index.d.ts +28 -0
- package/lib/features/analytics/index.js +91 -0
- package/lib/features/analytics/manifest.d.ts +8 -0
- package/lib/features/analytics/manifest.js +18 -0
- package/lib/features/analytics/model.d.ts +130 -0
- package/lib/features/analytics/model.js +206 -0
- package/lib/features/members/Member.d.ts +93 -0
- package/lib/features/members/Member.js +194 -0
- package/lib/features/members/MemberAdminController.d.ts +60 -0
- package/lib/features/members/MemberAdminController.js +262 -0
- package/lib/features/members/MemberController.d.ts +88 -0
- package/lib/features/members/MemberController.js +250 -0
- package/lib/features/members/MembersPage.d.ts +10 -0
- package/lib/features/members/MembersPage.js +216 -0
- package/lib/features/members/PostAccessBox.d.ts +15 -0
- package/lib/features/members/PostAccessBox.js +70 -0
- package/lib/features/members/admin.d.ts +3 -0
- package/lib/features/members/admin.js +12 -0
- package/lib/features/members/csv.d.ts +21 -0
- package/lib/features/members/csv.js +74 -0
- package/lib/features/members/events.d.ts +34 -0
- package/lib/features/members/events.js +34 -0
- package/lib/features/members/i18n/es.d.ts +4 -0
- package/lib/features/members/i18n/es.js +106 -0
- package/lib/features/members/index.d.ts +44 -0
- package/lib/features/members/index.js +106 -0
- package/lib/features/members/manifest.d.ts +8 -0
- package/lib/features/members/manifest.js +18 -0
- package/lib/features/members/middleware.d.ts +42 -0
- package/lib/features/members/middleware.js +74 -0
- package/lib/features/members/newsletter.d.ts +177 -0
- package/lib/features/members/newsletter.js +439 -0
- package/lib/features/members/rate-limits.d.ts +34 -0
- package/lib/features/members/rate-limits.js +50 -0
- package/lib/features/members/request.d.ts +13 -0
- package/lib/features/members/request.js +6 -0
- package/lib/features/members/routes.d.ts +15 -0
- package/lib/features/members/routes.js +59 -0
- package/lib/features/members/session.d.ts +102 -0
- package/lib/features/members/session.js +158 -0
- package/lib/features/members/settings.d.ts +14 -0
- package/lib/features/members/settings.js +23 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
- package/lib/features/mysendbox/admin.d.ts +3 -0
- package/lib/features/mysendbox/admin.js +9 -0
- package/lib/features/mysendbox/broadcasts.d.ts +61 -0
- package/lib/features/mysendbox/broadcasts.js +124 -0
- package/lib/features/mysendbox/client.d.ts +95 -0
- package/lib/features/mysendbox/client.js +61 -0
- package/lib/features/mysendbox/config.d.ts +27 -0
- package/lib/features/mysendbox/config.js +74 -0
- package/lib/features/mysendbox/contacts.d.ts +121 -0
- package/lib/features/mysendbox/contacts.js +378 -0
- package/lib/features/mysendbox/controller.d.ts +11 -0
- package/lib/features/mysendbox/controller.js +47 -0
- package/lib/features/mysendbox/i18n/es.d.ts +4 -0
- package/lib/features/mysendbox/i18n/es.js +28 -0
- package/lib/features/mysendbox/index.d.ts +18 -0
- package/lib/features/mysendbox/index.js +71 -0
- package/lib/features/mysendbox/manifest.d.ts +7 -0
- package/lib/features/mysendbox/manifest.js +6 -0
- package/lib/features/mysendbox/routes.d.ts +6 -0
- package/lib/features/mysendbox/routes.js +14 -0
- package/lib/features/mysendbox/webhook.d.ts +23 -0
- package/lib/features/mysendbox/webhook.js +104 -0
- package/lib/features/theme/OEmbedController.d.ts +31 -0
- package/lib/features/theme/OEmbedController.js +128 -0
- package/lib/features/theme/ThemeController.d.ts +20 -0
- package/lib/features/theme/ThemeController.js +256 -0
- package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
- package/lib/features/theme/ThemeSettingsCard.js +12 -0
- package/lib/features/theme/admin.d.ts +3 -0
- package/lib/features/theme/admin.js +9 -0
- package/lib/features/theme/html.d.ts +48 -0
- package/lib/features/theme/html.js +97 -0
- package/lib/features/theme/i18n/es.d.ts +4 -0
- package/lib/features/theme/i18n/es.js +9 -0
- package/lib/features/theme/index.d.ts +11 -0
- package/lib/features/theme/index.js +23 -0
- package/lib/features/theme/manifest.d.ts +7 -0
- package/lib/features/theme/manifest.js +6 -0
- package/lib/features/theme/oembed.d.ts +36 -0
- package/lib/features/theme/oembed.js +58 -0
- package/lib/features/theme/routes.d.ts +17 -0
- package/lib/features/theme/routes.js +54 -0
- package/lib/features/theme/templates.d.ts +103 -0
- package/lib/features/theme/templates.js +283 -0
- package/lib/features.d.ts +15 -0
- package/lib/features.js +6 -0
- package/lib/features.manifest.d.ts +10 -0
- package/lib/features.manifest.js +6 -0
- package/lib/helpers/access.d.ts +62 -0
- package/lib/helpers/access.js +92 -0
- package/lib/helpers/api.d.ts +20 -0
- package/lib/helpers/api.js +44 -0
- package/lib/helpers/comment-guard.d.ts +145 -0
- package/lib/helpers/comment-guard.js +253 -0
- package/lib/helpers/comment-mail.d.ts +53 -0
- package/lib/helpers/comment-mail.js +188 -0
- package/lib/helpers/content-model.d.ts +50 -0
- package/lib/helpers/content-model.js +84 -0
- package/lib/helpers/content-paths.d.ts +107 -0
- package/lib/helpers/content-paths.js +200 -0
- package/lib/helpers/export-data.d.ts +85 -0
- package/lib/helpers/export-data.js +229 -0
- package/lib/helpers/gating.d.ts +53 -0
- package/lib/helpers/gating.js +83 -0
- package/lib/helpers/health.d.ts +91 -0
- package/lib/helpers/health.js +279 -0
- package/lib/helpers/heartbeat.d.ts +35 -0
- package/lib/helpers/heartbeat.js +55 -0
- package/lib/helpers/image-size.d.ts +18 -0
- package/lib/helpers/image-size.js +83 -0
- package/lib/helpers/images.d.ts +29 -0
- package/lib/helpers/images.js +41 -0
- package/lib/helpers/mail-templates.d.ts +11 -0
- package/lib/helpers/mail-templates.js +42 -0
- package/lib/helpers/publish-due.d.ts +28 -0
- package/lib/helpers/publish-due.js +67 -0
- package/lib/helpers/redirects.d.ts +43 -0
- package/lib/helpers/redirects.js +80 -0
- package/lib/helpers/seo-fields.d.ts +13 -0
- package/lib/helpers/seo-fields.js +52 -0
- package/lib/helpers/session.d.ts +30 -0
- package/lib/helpers/session.js +27 -0
- package/lib/helpers/site-settings.d.ts +98 -0
- package/lib/helpers/site-settings.js +232 -0
- package/lib/helpers/site.d.ts +14 -0
- package/lib/helpers/site.js +23 -0
- package/lib/helpers/write-hooks.d.ts +33 -0
- package/lib/helpers/write-hooks.js +37 -0
- package/lib/hooks.d.ts +17 -0
- package/lib/hooks.js +101 -0
- package/lib/host/core-tasks.d.ts +4 -0
- package/lib/host/core-tasks.js +26 -0
- package/lib/host/cron.d.ts +39 -0
- package/lib/host/cron.js +85 -0
- package/lib/host/enabled.d.ts +4 -0
- package/lib/host/enabled.js +40 -0
- package/lib/host/index.d.ts +81 -0
- package/lib/host/index.js +87 -0
- package/lib/host/manifest.d.ts +34 -0
- package/lib/host/manifest.js +7 -0
- package/lib/host/menu.d.ts +18 -0
- package/lib/host/menu.js +15 -0
- package/lib/main.d.ts +1 -0
- package/lib/main.js +24 -0
- package/lib/middleware/api-auth.d.ts +59 -0
- package/lib/middleware/api-auth.js +164 -0
- package/lib/middleware/auth.d.ts +49 -0
- package/lib/middleware/auth.js +112 -0
- package/lib/middleware/cache.d.ts +17 -0
- package/lib/middleware/cache.js +52 -0
- package/lib/middleware/rate-limits.d.ts +199 -0
- package/lib/middleware/rate-limits.js +276 -0
- package/lib/middleware/viewer.d.ts +13 -0
- package/lib/middleware/viewer.js +16 -0
- package/lib/models/Category.d.ts +24 -0
- package/lib/models/Category.js +102 -0
- package/lib/models/Comment.d.ts +120 -0
- package/lib/models/Comment.js +283 -0
- package/lib/models/ContentType.d.ts +142 -0
- package/lib/models/ContentType.js +462 -0
- package/lib/models/Credential.d.ts +21 -0
- package/lib/models/Credential.js +31 -0
- package/lib/models/Media.d.ts +53 -0
- package/lib/models/Media.js +132 -0
- package/lib/models/Menu.d.ts +131 -0
- package/lib/models/Menu.js +312 -0
- package/lib/models/Page.d.ts +55 -0
- package/lib/models/Page.js +218 -0
- package/lib/models/Post.d.ts +136 -0
- package/lib/models/Post.js +406 -0
- package/lib/models/PostLock.d.ts +67 -0
- package/lib/models/PostLock.js +112 -0
- package/lib/models/PostRevision.d.ts +45 -0
- package/lib/models/PostRevision.js +82 -0
- package/lib/models/PublicContent.d.ts +283 -0
- package/lib/models/PublicContent.js +577 -0
- package/lib/models/Redirect.d.ts +123 -0
- package/lib/models/Redirect.js +225 -0
- package/lib/models/Settings.d.ts +61 -0
- package/lib/models/Settings.js +128 -0
- package/lib/models/Snippet.d.ts +36 -0
- package/lib/models/Snippet.js +64 -0
- package/lib/models/Tag.d.ts +23 -0
- package/lib/models/Tag.js +117 -0
- package/lib/models/Taxonomy.d.ts +127 -0
- package/lib/models/Taxonomy.js +321 -0
- package/lib/models/TwoFactor.d.ts +26 -0
- package/lib/models/TwoFactor.js +60 -0
- package/lib/models/User.d.ts +49 -0
- package/lib/models/User.js +128 -0
- package/lib/models/derive.d.ts +69 -0
- package/lib/models/derive.js +81 -0
- package/lib/models/pagination.d.ts +30 -0
- package/lib/models/pagination.js +36 -0
- package/lib/models/visibility.d.ts +31 -0
- package/lib/models/visibility.js +47 -0
- package/lib/routes/App.d.ts +2 -0
- package/lib/routes/App.js +146 -0
- package/lib/routes/api/admin.d.ts +6 -0
- package/lib/routes/api/admin.js +11 -0
- package/lib/routes/api/auth.d.ts +6 -0
- package/lib/routes/api/auth.js +24 -0
- package/lib/routes/api/authors.d.ts +5 -0
- package/lib/routes/api/authors.js +8 -0
- package/lib/routes/api/categories.d.ts +8 -0
- package/lib/routes/api/categories.js +15 -0
- package/lib/routes/api/comments.d.ts +8 -0
- package/lib/routes/api/comments.js +35 -0
- package/lib/routes/api/content-model.d.ts +17 -0
- package/lib/routes/api/content-model.js +67 -0
- package/lib/routes/api/cron.d.ts +6 -0
- package/lib/routes/api/cron.js +9 -0
- package/lib/routes/api/export.d.ts +5 -0
- package/lib/routes/api/export.js +11 -0
- package/lib/routes/api/feed.d.ts +5 -0
- package/lib/routes/api/feed.js +16 -0
- package/lib/routes/api/media.d.ts +8 -0
- package/lib/routes/api/media.js +25 -0
- package/lib/routes/api/navigation.d.ts +12 -0
- package/lib/routes/api/navigation.js +17 -0
- package/lib/routes/api/ops.d.ts +9 -0
- package/lib/routes/api/ops.js +19 -0
- package/lib/routes/api/pages.d.ts +8 -0
- package/lib/routes/api/pages.js +21 -0
- package/lib/routes/api/passkeys.d.ts +7 -0
- package/lib/routes/api/passkeys.js +13 -0
- package/lib/routes/api/posts.d.ts +8 -0
- package/lib/routes/api/posts.js +39 -0
- package/lib/routes/api/profile.d.ts +6 -0
- package/lib/routes/api/profile.js +8 -0
- package/lib/routes/api/redirects.d.ts +12 -0
- package/lib/routes/api/redirects.js +13 -0
- package/lib/routes/api/settings.d.ts +8 -0
- package/lib/routes/api/settings.js +15 -0
- package/lib/routes/api/snippets.d.ts +15 -0
- package/lib/routes/api/snippets.js +16 -0
- package/lib/routes/api/tags.d.ts +8 -0
- package/lib/routes/api/tags.js +14 -0
- package/lib/routes/api/tokens.d.ts +7 -0
- package/lib/routes/api/tokens.js +15 -0
- package/lib/routes/api/two-factor.d.ts +7 -0
- package/lib/routes/api/two-factor.js +15 -0
- package/lib/routes/api/users.d.ts +8 -0
- package/lib/routes/api/users.js +25 -0
- package/lib/routes/api/v1.d.ts +12 -0
- package/lib/routes/api/v1.js +55 -0
- package/lib/routes/api/verification.d.ts +6 -0
- package/lib/routes/api/verification.js +11 -0
- package/lib/server/index.d.ts +24 -0
- package/lib/server/index.js +110 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.js +1 -0
- package/lib/vite.d.ts +2 -0
- package/lib/vite.js +101 -0
- package/mail/comment-moderation.html +27 -0
- package/mail/comment-moderation.txt +13 -0
- package/mail/comment-reply.html +28 -0
- package/mail/comment-reply.txt +14 -0
- package/mail/invitation.html +25 -0
- package/mail/invitation.txt +11 -0
- package/mail/member-magic-link.html +23 -0
- package/mail/member-magic-link.txt +10 -0
- package/mail/newsletter.html +26 -0
- package/mail/newsletter.txt +13 -0
- package/mail/password-reset.html +26 -0
- package/mail/password-reset.txt +10 -0
- package/mail/verify-email.html +25 -0
- package/mail/verify-email.txt +8 -0
- package/package.json +85 -4
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { can } from '@basicbenframework/core/auth/permissions';
|
|
2
|
+
import { Post } from "../models/Post.js";
|
|
3
|
+
import { PostLock, LOCK_HEARTBEAT_MS, LOCK_TTL_MS } from "../models/PostLock.js";
|
|
4
|
+
/**
|
|
5
|
+
* The editor's lock on a post: take it, keep it, give it back.
|
|
6
|
+
*
|
|
7
|
+
* Session-only (see the routes): a lock is "a person has this open", which a
|
|
8
|
+
* program does not. An API token never holds or takes over a lock; its writes
|
|
9
|
+
* are refused while a person holds one — see `lockConflict` below.
|
|
10
|
+
*/
|
|
11
|
+
export const PostLockController = {
|
|
12
|
+
/** Who, if anyone, is editing this post. */
|
|
13
|
+
async show(req, res) {
|
|
14
|
+
const post = await editable(req);
|
|
15
|
+
if (!post)
|
|
16
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
17
|
+
res.json({ lock: describe(await PostLock.current(post.id), req.userId) });
|
|
18
|
+
},
|
|
19
|
+
/**
|
|
20
|
+
* Acquire or refresh — the editor's heartbeat.
|
|
21
|
+
*
|
|
22
|
+
* `take_over: true` takes the lock from whoever holds it. Anyone who may
|
|
23
|
+
* edit the post may do that, as in WordPress: the lock is a warning that
|
|
24
|
+
* someone is there, not a permission. A 409 means the lock is held by
|
|
25
|
+
* someone else and nothing changed; the body says who, so the editor can
|
|
26
|
+
* offer the take-over.
|
|
27
|
+
*/
|
|
28
|
+
async acquire(req, res) {
|
|
29
|
+
const post = await editable(req);
|
|
30
|
+
if (!post)
|
|
31
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
32
|
+
const takeOver = req.body?.take_over === true;
|
|
33
|
+
const { acquired, lock } = await PostLock.acquire(post.id, req.userId, { takeOver });
|
|
34
|
+
if (!acquired) {
|
|
35
|
+
return res.json({ error: `${lock?.user_name || 'Someone else'} is editing this post.`, lock: describe(lock, req.userId) }, 409);
|
|
36
|
+
}
|
|
37
|
+
res.json({ lock: describe(lock, req.userId) });
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Let go, on leaving the editor.
|
|
41
|
+
*
|
|
42
|
+
* Sent with `fetch(..., { keepalive: true })` as the page unloads rather than
|
|
43
|
+
* `navigator.sendBeacon`, because a beacon cannot carry the Authorization
|
|
44
|
+
* header this API authenticates with. Always 200: there is nothing useful a
|
|
45
|
+
* closing page could do with a failure, and a stale lock expires anyway.
|
|
46
|
+
*/
|
|
47
|
+
async release(req, res) {
|
|
48
|
+
const post = await editable(req);
|
|
49
|
+
if (post)
|
|
50
|
+
await PostLock.release(post.id, req.userId);
|
|
51
|
+
res.json({ released: true });
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Why this write must not go ahead, or null if it may.
|
|
56
|
+
*
|
|
57
|
+
* Called by every PostController action that changes a post's text (update,
|
|
58
|
+
* autosave, restoring a revision). A person holding a live lock on the post,
|
|
59
|
+
* other than the caller, blocks it with a 409 naming them.
|
|
60
|
+
*
|
|
61
|
+
* - A signed-in caller may send `take_over: true` with the save to take the
|
|
62
|
+
* lock as part of it — the "save anyway" button.
|
|
63
|
+
* - An API token cannot. A program overwriting what a person has open in
|
|
64
|
+
* front of them is the exact accident the lock exists to stop, and a script
|
|
65
|
+
* can retry after the lock lapses (two minutes after the editor closes)
|
|
66
|
+
* where a person cannot get their typing back.
|
|
67
|
+
*/
|
|
68
|
+
export async function lockConflict(req, post) {
|
|
69
|
+
const takeOver = !req.apiToken && req.body?.take_over === true;
|
|
70
|
+
if (takeOver) {
|
|
71
|
+
await PostLock.acquire(post.id, req.userId, { takeOver: true });
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const lock = await PostLock.blocking(post.id, req.userId);
|
|
75
|
+
if (!lock)
|
|
76
|
+
return null;
|
|
77
|
+
return {
|
|
78
|
+
error: `${lock.user_name || 'Someone else'} is editing this post. Your changes were not saved.`,
|
|
79
|
+
lock: describe(lock, req.userId)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** A lock as the client sees it — with "is it mine" worked out, and the timings. */
|
|
83
|
+
function describe(lock, userId) {
|
|
84
|
+
return {
|
|
85
|
+
locked: Boolean(lock),
|
|
86
|
+
mine: Boolean(lock && lock.user_id === userId),
|
|
87
|
+
user_id: lock?.user_id ?? null,
|
|
88
|
+
user_name: lock?.user_name ?? null,
|
|
89
|
+
locked_at: lock?.locked_at ?? null,
|
|
90
|
+
expires_at: lock?.expires_at ?? null,
|
|
91
|
+
heartbeat_ms: LOCK_HEARTBEAT_MS,
|
|
92
|
+
ttl_ms: LOCK_TTL_MS
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** The post, if this request may edit it — the same rule PostController uses. */
|
|
96
|
+
async function editable(req) {
|
|
97
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
98
|
+
if (!post || !can(req.user, 'post.edit', post))
|
|
99
|
+
return null;
|
|
100
|
+
return post;
|
|
101
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The account, and the author profile attached to it.
|
|
4
|
+
*
|
|
5
|
+
* These are the same record: `users` holds both the credentials and the byline.
|
|
6
|
+
* What separates them is who may see which half — the address and the role stay
|
|
7
|
+
* here, behind the session; the profile travels to every published post.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ProfileController: {
|
|
10
|
+
show(req: Request, res: Response): Promise<void>;
|
|
11
|
+
update(req: Request, res: Response): Promise<void>;
|
|
12
|
+
changePassword(req: Request, res: Response): Promise<void>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
2
|
+
import { User } from "../models/User.js";
|
|
3
|
+
import { hashPassword, verifyPassword } from '@basicbenframework/core/auth';
|
|
4
|
+
import { resetVerification, sendVerificationEmail } from "./EmailVerificationController.js";
|
|
5
|
+
import { issueSessionToken, revokeSessions } from "../helpers/session.js";
|
|
6
|
+
/**
|
|
7
|
+
* An http(s) URL or nothing.
|
|
8
|
+
*
|
|
9
|
+
* The website travels to every byline through /api/v1, where a headless
|
|
10
|
+
* consumer may render it as a link without React's protection against
|
|
11
|
+
* `javascript:` URLs.
|
|
12
|
+
*/
|
|
13
|
+
function safeWebsite(value) {
|
|
14
|
+
const trimmed = value.trim();
|
|
15
|
+
if (!trimmed)
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
const url = new URL(trimmed);
|
|
19
|
+
return url.protocol === 'http:' || url.protocol === 'https:' ? url.toString() : false;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The account, and the author profile attached to it.
|
|
27
|
+
*
|
|
28
|
+
* These are the same record: `users` holds both the credentials and the byline.
|
|
29
|
+
* What separates them is who may see which half — the address and the role stay
|
|
30
|
+
* here, behind the session; the profile travels to every published post.
|
|
31
|
+
*/
|
|
32
|
+
export const ProfileController = {
|
|
33
|
+
async show(req, res) {
|
|
34
|
+
const user = await User.find(req.userId);
|
|
35
|
+
if (!user) {
|
|
36
|
+
return res.json({ error: 'User not found' }, 404);
|
|
37
|
+
}
|
|
38
|
+
const profile = await User.profile(req.userId);
|
|
39
|
+
res.json({
|
|
40
|
+
user: {
|
|
41
|
+
id: user.id,
|
|
42
|
+
name: user.name,
|
|
43
|
+
email: user.email,
|
|
44
|
+
role: user.role,
|
|
45
|
+
slug: user.slug ?? null,
|
|
46
|
+
bio: user.bio ?? null,
|
|
47
|
+
website: user.website ?? null,
|
|
48
|
+
avatar_id: user.avatar_id ?? null,
|
|
49
|
+
// Resolved through the storage adapter, so the form can show the
|
|
50
|
+
// picture rather than a media id.
|
|
51
|
+
avatar_url: profile?.avatar_url ?? null,
|
|
52
|
+
created_at: user.created_at
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async update(req, res) {
|
|
57
|
+
const result = await validate(req.body, {
|
|
58
|
+
name: [rules.required, rules.string, rules.min(2)],
|
|
59
|
+
email: [rules.required, rules.email]
|
|
60
|
+
});
|
|
61
|
+
if (result.fails()) {
|
|
62
|
+
return res.json({ errors: result.errors }, 422);
|
|
63
|
+
}
|
|
64
|
+
const { name, email, slug, bio, website, avatar_id } = req.body;
|
|
65
|
+
const user = await User.find(req.userId);
|
|
66
|
+
if (!user) {
|
|
67
|
+
return res.json({ error: 'User not found' }, 404);
|
|
68
|
+
}
|
|
69
|
+
const emailChanged = email !== user.email;
|
|
70
|
+
if (emailChanged) {
|
|
71
|
+
// The address is where password resets go, so changing it is taking
|
|
72
|
+
// over the account. A session alone — one left open on a shared
|
|
73
|
+
// machine, or stolen — must not be enough.
|
|
74
|
+
const currentPassword = req.body.currentPassword;
|
|
75
|
+
if (!currentPassword || !(await verifyPassword(currentPassword, user.password))) {
|
|
76
|
+
return res.json({ error: 'Enter your current password to change your email address.' }, 403);
|
|
77
|
+
}
|
|
78
|
+
const existing = await User.findByEmail(email);
|
|
79
|
+
if (existing) {
|
|
80
|
+
return res.json({ error: 'Email already taken' }, 400);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let cleanWebsite;
|
|
84
|
+
if (typeof website === 'string') {
|
|
85
|
+
const checked = safeWebsite(website);
|
|
86
|
+
if (checked === false) {
|
|
87
|
+
return res.json({ errors: { website: ['Website must be an http or https URL'] } }, 422);
|
|
88
|
+
}
|
|
89
|
+
cleanWebsite = checked;
|
|
90
|
+
}
|
|
91
|
+
// Only what the request actually carried. A client that knows nothing about
|
|
92
|
+
// profiles — the framework's own signup form, anything written before this
|
|
93
|
+
// — sends name and email, and must not blank a biography by omission.
|
|
94
|
+
const profile = { name, email };
|
|
95
|
+
// Blank asks for one derived from the name, the way it was set at
|
|
96
|
+
// registration; the model makes whatever it gets unique.
|
|
97
|
+
if (typeof slug === 'string')
|
|
98
|
+
profile.slug = slug.trim() || name;
|
|
99
|
+
if (typeof bio === 'string')
|
|
100
|
+
profile.bio = bio.trim() || null;
|
|
101
|
+
if (cleanWebsite !== undefined)
|
|
102
|
+
profile.website = cleanWebsite;
|
|
103
|
+
if ('avatar_id' in req.body)
|
|
104
|
+
profile.avatar_id = Number(avatar_id) || null;
|
|
105
|
+
const updated = await User.update(req.userId, profile);
|
|
106
|
+
// A new address has not been confirmed by anyone. Keeping the old flag
|
|
107
|
+
// would let an account claim any address as verified.
|
|
108
|
+
let verificationSent = false;
|
|
109
|
+
if (emailChanged) {
|
|
110
|
+
await resetVerification(req.userId);
|
|
111
|
+
try {
|
|
112
|
+
await sendVerificationEmail({ ...updated, email });
|
|
113
|
+
verificationSent = true;
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
console.error('Failed to send verification email:', err.message);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const shaped = await User.profile(req.userId);
|
|
120
|
+
res.json({
|
|
121
|
+
user: {
|
|
122
|
+
id: updated.id,
|
|
123
|
+
name: updated.name,
|
|
124
|
+
email: updated.email,
|
|
125
|
+
slug: updated.slug ?? null,
|
|
126
|
+
bio: updated.bio ?? null,
|
|
127
|
+
website: updated.website ?? null,
|
|
128
|
+
avatar_id: updated.avatar_id ?? null,
|
|
129
|
+
avatar_url: shaped?.avatar_url ?? null
|
|
130
|
+
},
|
|
131
|
+
...(emailChanged ? { emailChanged: true, verificationSent } : {})
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
async changePassword(req, res) {
|
|
135
|
+
const result = await validate(req.body, {
|
|
136
|
+
currentPassword: [rules.required],
|
|
137
|
+
newPassword: [rules.required, rules.min(8)]
|
|
138
|
+
});
|
|
139
|
+
if (result.fails()) {
|
|
140
|
+
return res.json({ errors: result.errors }, 422);
|
|
141
|
+
}
|
|
142
|
+
const { currentPassword, newPassword } = req.body;
|
|
143
|
+
const user = await User.find(req.userId);
|
|
144
|
+
if (!user) {
|
|
145
|
+
return res.json({ error: 'User not found' }, 404);
|
|
146
|
+
}
|
|
147
|
+
if (!(await verifyPassword(currentPassword, user.password))) {
|
|
148
|
+
return res.json({ error: 'Current password is incorrect' }, 400);
|
|
149
|
+
}
|
|
150
|
+
// The framework's scrypt hash, the same one registration writes. This
|
|
151
|
+
// used to compare and store unsalted SHA-256, so it never matched and
|
|
152
|
+
// nobody could change a password at all.
|
|
153
|
+
await User.update(req.userId, { password: await hashPassword(newPassword) });
|
|
154
|
+
// A changed password is usually a response to a suspected compromise, so
|
|
155
|
+
// every other session ends. This one carries on with a fresh token.
|
|
156
|
+
await revokeSessions(req.userId);
|
|
157
|
+
const fresh = await User.find(req.userId);
|
|
158
|
+
res.json({ message: 'Password updated successfully', token: issueSessionToken(fresh) });
|
|
159
|
+
}
|
|
160
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The read-only content API, mounted at /api/v1.
|
|
4
|
+
*
|
|
5
|
+
* Versioned where the admin API is not, because this one has consumers the site
|
|
6
|
+
* does not control — a static build, someone's app — and breaking them silently
|
|
7
|
+
* on a Tuesday is exactly what a version prefix exists to prevent.
|
|
8
|
+
*
|
|
9
|
+
* Everything here is a read. There is no v1 write surface: the admin API
|
|
10
|
+
* already has one, gated on roles, and a second path to the same mutations is a
|
|
11
|
+
* second place for an authorization bug to live.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PublicApiController: {
|
|
14
|
+
posts(req: Request, res: Response): Promise<void>;
|
|
15
|
+
post(req: Request, res: Response): Promise<void>;
|
|
16
|
+
pages(req: Request, res: Response): Promise<void>;
|
|
17
|
+
page(req: Request, res: Response): Promise<void>;
|
|
18
|
+
authors(_req: Request, res: Response): Promise<void>;
|
|
19
|
+
author(req: Request, res: Response): Promise<void>;
|
|
20
|
+
categories(_req: Request, res: Response): Promise<void>;
|
|
21
|
+
tags(_req: Request, res: Response): Promise<void>;
|
|
22
|
+
media(req: Request, res: Response): Promise<void>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { PublicContent, paging, contentFormat } from "../models/PublicContent.js";
|
|
2
|
+
import { taxonomyFilters } from "../models/Taxonomy.js";
|
|
3
|
+
import { viewerOf } from "../helpers/access.js";
|
|
4
|
+
/**
|
|
5
|
+
* The read-only content API, mounted at /api/v1.
|
|
6
|
+
*
|
|
7
|
+
* Versioned where the admin API is not, because this one has consumers the site
|
|
8
|
+
* does not control — a static build, someone's app — and breaking them silently
|
|
9
|
+
* on a Tuesday is exactly what a version prefix exists to prevent.
|
|
10
|
+
*
|
|
11
|
+
* Everything here is a read. There is no v1 write surface: the admin API
|
|
12
|
+
* already has one, gated on roles, and a second path to the same mutations is a
|
|
13
|
+
* second place for an authorization bug to live.
|
|
14
|
+
*/
|
|
15
|
+
export const PublicApiController = {
|
|
16
|
+
async posts(req, res) {
|
|
17
|
+
const { page, perPage, offset } = paging(req.query);
|
|
18
|
+
const { posts, total } = await PublicContent.posts({
|
|
19
|
+
perPage,
|
|
20
|
+
offset,
|
|
21
|
+
category: req.query.category,
|
|
22
|
+
tag: req.query.tag,
|
|
23
|
+
author: req.query.author,
|
|
24
|
+
search: req.query.search,
|
|
25
|
+
format: contentFormat(req.query),
|
|
26
|
+
// Identified by `identifyViewer` in v1.ts; restricted bodies are withheld without a reader the policy lets in.
|
|
27
|
+
viewer: await viewerOf(req),
|
|
28
|
+
// Content types and custom taxonomies. `type` defaults to `post` in the
|
|
29
|
+
// model, so leaving it off is the listing every consumer already had.
|
|
30
|
+
type: req.query.type || undefined,
|
|
31
|
+
// `?tax=cuisine:italian` and `?taxonomy[cuisine]=italian` alike.
|
|
32
|
+
taxonomy: taxonomyFilters(req.query, req.query.tax)
|
|
33
|
+
});
|
|
34
|
+
res.json({
|
|
35
|
+
data: posts,
|
|
36
|
+
meta: {
|
|
37
|
+
page,
|
|
38
|
+
per_page: perPage,
|
|
39
|
+
total,
|
|
40
|
+
// Computed rather than left to the consumer: total/per_page is the sum
|
|
41
|
+
// people get wrong, and an off-by-one here means a paginating client
|
|
42
|
+
// either misses the last page or loops forever on an empty one.
|
|
43
|
+
total_pages: Math.max(1, Math.ceil(total / perPage))
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async post(req, res) {
|
|
48
|
+
const post = await PublicContent.post(req.params.slug, contentFormat(req.query), { viewer: await viewerOf(req), type: req.query.type || 'post' });
|
|
49
|
+
if (!post) {
|
|
50
|
+
return res.json({ error: 'Not found' }, 404);
|
|
51
|
+
}
|
|
52
|
+
res.json({ data: post });
|
|
53
|
+
},
|
|
54
|
+
async pages(req, res) {
|
|
55
|
+
const { page, perPage, offset } = paging(req.query);
|
|
56
|
+
const { pages, total } = await PublicContent.pages({
|
|
57
|
+
perPage,
|
|
58
|
+
offset,
|
|
59
|
+
format: contentFormat(req.query)
|
|
60
|
+
});
|
|
61
|
+
res.json({
|
|
62
|
+
data: pages,
|
|
63
|
+
meta: { page, per_page: perPage, total, total_pages: Math.max(1, Math.ceil(total / perPage)) }
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
async page(req, res) {
|
|
67
|
+
const found = await PublicContent.page(req.params.slug, contentFormat(req.query));
|
|
68
|
+
if (!found) {
|
|
69
|
+
return res.json({ error: 'Not found' }, 404);
|
|
70
|
+
}
|
|
71
|
+
res.json({ data: found });
|
|
72
|
+
},
|
|
73
|
+
async authors(_req, res) {
|
|
74
|
+
res.json({ data: await PublicContent.authors() });
|
|
75
|
+
},
|
|
76
|
+
async author(req, res) {
|
|
77
|
+
const found = await PublicContent.author(req.params.slug);
|
|
78
|
+
if (!found) {
|
|
79
|
+
return res.json({ error: 'Not found' }, 404);
|
|
80
|
+
}
|
|
81
|
+
res.json({ data: found });
|
|
82
|
+
},
|
|
83
|
+
async categories(_req, res) {
|
|
84
|
+
res.json({ data: await PublicContent.categories() });
|
|
85
|
+
},
|
|
86
|
+
async tags(_req, res) {
|
|
87
|
+
res.json({ data: await PublicContent.tags() });
|
|
88
|
+
},
|
|
89
|
+
async media(req, res) {
|
|
90
|
+
const id = Number(req.params.id);
|
|
91
|
+
if (!Number.isInteger(id)) {
|
|
92
|
+
return res.json({ error: 'Not found' }, 404);
|
|
93
|
+
}
|
|
94
|
+
const item = await PublicContent.media(id);
|
|
95
|
+
if (!item) {
|
|
96
|
+
return res.json({ error: 'Not found' }, 404);
|
|
97
|
+
}
|
|
98
|
+
res.json({ data: item });
|
|
99
|
+
}
|
|
100
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Redirect management for the admin, and the public lookup for front ends.
|
|
4
|
+
*
|
|
5
|
+
* The admin routes require `settings.manage`. A redirect can send every
|
|
6
|
+
* visitor of any path anywhere on the web, which is a site-wide decision of
|
|
7
|
+
* the same weight as the site's settings, not an editorial one.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RedirectController: {
|
|
10
|
+
index(req: Request, res: Response): Promise<void>;
|
|
11
|
+
store(req: Request, res: Response): Promise<void>;
|
|
12
|
+
update(req: Request, res: Response): Promise<void>;
|
|
13
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* `GET /api/v1/redirects` — the whole map, or one path with `?path=`.
|
|
16
|
+
*
|
|
17
|
+
* The list is the primary interface. A headless front end applies redirects
|
|
18
|
+
* itself, and the sensible places to do that — a build step writing a
|
|
19
|
+
* `_redirects` / `vercel.json` file, or edge middleware holding the map in
|
|
20
|
+
* memory — want every rule at once. Asking per path would put an API round
|
|
21
|
+
* trip in front of every request the front end cannot otherwise answer. The
|
|
22
|
+
* list is ETag-cached like every v1 read, so re-fetching an unchanged map
|
|
23
|
+
* costs a 304.
|
|
24
|
+
*
|
|
25
|
+
* `?path=` is there for front ends that only consult the CMS on a 404 (a
|
|
26
|
+
* catch-all route). It returns 404 when nothing matches, and counts a hit
|
|
27
|
+
* when something does.
|
|
28
|
+
*
|
|
29
|
+
* Chains are resolved either way: `to` is always the final destination.
|
|
30
|
+
*/
|
|
31
|
+
publicIndex(req: Request, res: Response): Promise<void>;
|
|
32
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Redirect, validateRedirect } from "../models/Redirect.js";
|
|
2
|
+
import { paginationFrom, meta } from "../models/pagination.js";
|
|
3
|
+
import { normalizeRedirectSource } from "../helpers/content-paths.js";
|
|
4
|
+
/**
|
|
5
|
+
* Redirect management for the admin, and the public lookup for front ends.
|
|
6
|
+
*
|
|
7
|
+
* The admin routes require `settings.manage`. A redirect can send every
|
|
8
|
+
* visitor of any path anywhere on the web, which is a site-wide decision of
|
|
9
|
+
* the same weight as the site's settings, not an editorial one.
|
|
10
|
+
*/
|
|
11
|
+
export const RedirectController = {
|
|
12
|
+
async index(req, res) {
|
|
13
|
+
const { page, perPage, offset } = paginationFrom(req.query);
|
|
14
|
+
const search = typeof req.query.search === 'string' ? req.query.search.trim().slice(0, 200) : '';
|
|
15
|
+
const { redirects, total } = await Redirect.paginate({ perPage, offset, search: search || undefined });
|
|
16
|
+
res.json({ redirects, meta: meta(page, perPage, total) });
|
|
17
|
+
},
|
|
18
|
+
async store(req, res) {
|
|
19
|
+
const result = validateRedirect(req.body);
|
|
20
|
+
if ('errors' in result)
|
|
21
|
+
return res.json({ errors: result.errors }, 422);
|
|
22
|
+
const { from_path, to_path } = result.values;
|
|
23
|
+
if (await Redirect.findByPath(from_path)) {
|
|
24
|
+
return res.json({ errors: { from_path: ['A redirect from this path already exists'] } }, 422);
|
|
25
|
+
}
|
|
26
|
+
if (await Redirect.wouldLoop(from_path, to_path)) {
|
|
27
|
+
return res.json({ errors: { to_path: ['This would create a redirect loop'] } }, 422);
|
|
28
|
+
}
|
|
29
|
+
const redirect = await Redirect.save(result.values, 'manual');
|
|
30
|
+
res.json({ redirect }, 201);
|
|
31
|
+
},
|
|
32
|
+
async update(req, res) {
|
|
33
|
+
const id = Number(req.params.id);
|
|
34
|
+
const existing = Number.isInteger(id) ? await Redirect.find(id) : undefined;
|
|
35
|
+
if (!existing)
|
|
36
|
+
return res.json({ error: 'Redirect not found' }, 404);
|
|
37
|
+
const result = validateRedirect({ ...existing, ...req.body });
|
|
38
|
+
if ('errors' in result)
|
|
39
|
+
return res.json({ errors: result.errors }, 422);
|
|
40
|
+
const { from_path, to_path } = result.values;
|
|
41
|
+
const clash = await Redirect.findByPath(from_path);
|
|
42
|
+
if (clash && clash.id !== id) {
|
|
43
|
+
return res.json({ errors: { from_path: ['A redirect from this path already exists'] } }, 422);
|
|
44
|
+
}
|
|
45
|
+
if (await Redirect.wouldLoop(from_path, to_path, id)) {
|
|
46
|
+
return res.json({ errors: { to_path: ['This would create a redirect loop'] } }, 422);
|
|
47
|
+
}
|
|
48
|
+
const redirect = await Redirect.update(id, result.values);
|
|
49
|
+
res.json({ redirect });
|
|
50
|
+
},
|
|
51
|
+
async destroy(req, res) {
|
|
52
|
+
const id = Number(req.params.id);
|
|
53
|
+
const existing = Number.isInteger(id) ? await Redirect.find(id) : undefined;
|
|
54
|
+
if (!existing)
|
|
55
|
+
return res.json({ error: 'Redirect not found' }, 404);
|
|
56
|
+
await Redirect.delete(id);
|
|
57
|
+
res.json({ message: 'Redirect deleted' });
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* `GET /api/v1/redirects` — the whole map, or one path with `?path=`.
|
|
61
|
+
*
|
|
62
|
+
* The list is the primary interface. A headless front end applies redirects
|
|
63
|
+
* itself, and the sensible places to do that — a build step writing a
|
|
64
|
+
* `_redirects` / `vercel.json` file, or edge middleware holding the map in
|
|
65
|
+
* memory — want every rule at once. Asking per path would put an API round
|
|
66
|
+
* trip in front of every request the front end cannot otherwise answer. The
|
|
67
|
+
* list is ETag-cached like every v1 read, so re-fetching an unchanged map
|
|
68
|
+
* costs a 304.
|
|
69
|
+
*
|
|
70
|
+
* `?path=` is there for front ends that only consult the CMS on a 404 (a
|
|
71
|
+
* catch-all route). It returns 404 when nothing matches, and counts a hit
|
|
72
|
+
* when something does.
|
|
73
|
+
*
|
|
74
|
+
* Chains are resolved either way: `to` is always the final destination.
|
|
75
|
+
*/
|
|
76
|
+
async publicIndex(req, res) {
|
|
77
|
+
const present = (row) => ({
|
|
78
|
+
from: row.from_path,
|
|
79
|
+
to: row.to_path,
|
|
80
|
+
status: Number(row.status)
|
|
81
|
+
});
|
|
82
|
+
if (req.query.path !== undefined) {
|
|
83
|
+
const path = normalizeRedirectSource(req.query.path);
|
|
84
|
+
if (!path)
|
|
85
|
+
return res.json({ error: 'Not found' }, 404);
|
|
86
|
+
const match = await Redirect.lookup(path);
|
|
87
|
+
if (!match)
|
|
88
|
+
return res.json({ error: 'Not found' }, 404);
|
|
89
|
+
await Redirect.hit(match.id);
|
|
90
|
+
return res.json({ data: present(match) });
|
|
91
|
+
}
|
|
92
|
+
const rows = await Redirect.allResolved();
|
|
93
|
+
res.json({ data: rows.map(present), meta: { total: rows.length } });
|
|
94
|
+
}
|
|
95
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Site settings.
|
|
4
|
+
*
|
|
5
|
+
* Every write goes through `validateSettings`, which knows each key the site
|
|
6
|
+
* uses and what it accepts (see helpers/site-settings.ts). The routes require
|
|
7
|
+
* `settings.manage`, which only the admin role holds — that matters most for
|
|
8
|
+
* code injection, which is raw HTML the front end renders unsanitised.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SettingsController: {
|
|
11
|
+
index(req: Request, res: Response): Promise<void>;
|
|
12
|
+
byGroup(req: Request, res: Response): Promise<void>;
|
|
13
|
+
get(req: Request, res: Response): Promise<void>;
|
|
14
|
+
update(req: Request, res: Response): Promise<void>;
|
|
15
|
+
set(req: Request, res: Response): Promise<void>;
|
|
16
|
+
delete(req: Request, res: Response): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* `GET /api/v1/site` — the site's identity: name, description, URL, logo,
|
|
19
|
+
* icon, default social image, time zone, locale and code injection.
|
|
20
|
+
*
|
|
21
|
+
* `code_injection` is admin-authored HTML for the front end to insert raw
|
|
22
|
+
* into <head> and before </body>. It is deliberately not sanitised — it
|
|
23
|
+
* exists to carry <script> tags — and only the admin role can set it.
|
|
24
|
+
*/
|
|
25
|
+
publicSite(_req: Request, res: Response): Promise<void>;
|
|
26
|
+
getSiteInfo(req: Request, res: Response): Promise<void>;
|
|
27
|
+
updateSiteInfo(req: Request, res: Response): Promise<void>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Settings } from "../models/Settings.js";
|
|
2
|
+
import { validateSettings, isKnownSetting } from "../helpers/site-settings.js";
|
|
3
|
+
import { siteUrl } from "../helpers/site.js";
|
|
4
|
+
/**
|
|
5
|
+
* Site settings.
|
|
6
|
+
*
|
|
7
|
+
* Every write goes through `validateSettings`, which knows each key the site
|
|
8
|
+
* uses and what it accepts (see helpers/site-settings.ts). The routes require
|
|
9
|
+
* `settings.manage`, which only the admin role holds — that matters most for
|
|
10
|
+
* code injection, which is raw HTML the front end renders unsanitised.
|
|
11
|
+
*/
|
|
12
|
+
export const SettingsController = {
|
|
13
|
+
async index(req, res) {
|
|
14
|
+
const settings = await Settings.asObject();
|
|
15
|
+
// The site URL is configuration (SITE_URL), not a setting: it is shown so
|
|
16
|
+
// the admin can see what feeds and the sitemap link to, and it is never
|
|
17
|
+
// writable from here — a URL that can be changed from a form is one stolen
|
|
18
|
+
// admin session away from pointing every feed reader somewhere else.
|
|
19
|
+
res.json({ settings, site_url: siteUrl(req) });
|
|
20
|
+
},
|
|
21
|
+
async byGroup(req, res) {
|
|
22
|
+
const settings = await Settings.asObject(req.params.group);
|
|
23
|
+
res.json({ settings });
|
|
24
|
+
},
|
|
25
|
+
async get(req, res) {
|
|
26
|
+
const value = await Settings.get(req.params.key);
|
|
27
|
+
if (value === null) {
|
|
28
|
+
return res.json({ error: 'Setting not found' }, 404);
|
|
29
|
+
}
|
|
30
|
+
res.json({ key: req.params.key, value });
|
|
31
|
+
},
|
|
32
|
+
async update(req, res) {
|
|
33
|
+
const { settings } = req.body;
|
|
34
|
+
const result = validateSettings(settings);
|
|
35
|
+
if ('errors' in result)
|
|
36
|
+
return res.json({ errors: result.errors }, 422);
|
|
37
|
+
for (const [key, { value, group }] of Object.entries(result.values)) {
|
|
38
|
+
await Settings.set(key, value, group);
|
|
39
|
+
}
|
|
40
|
+
const updated = await Settings.asObject();
|
|
41
|
+
res.json({ settings: updated });
|
|
42
|
+
},
|
|
43
|
+
async set(req, res) {
|
|
44
|
+
const { value } = req.body;
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
return res.json({ errors: { value: ['Value is required'] } }, 422);
|
|
47
|
+
}
|
|
48
|
+
// The group comes from the definition now, not the request: a client
|
|
49
|
+
// naming its own group was how a setting ended up filed somewhere
|
|
50
|
+
// `byGroup` would never find it.
|
|
51
|
+
const result = validateSettings({ [req.params.key]: value });
|
|
52
|
+
if ('errors' in result)
|
|
53
|
+
return res.json({ errors: result.errors }, 422);
|
|
54
|
+
const stored = result.values[req.params.key];
|
|
55
|
+
await Settings.set(req.params.key, stored.value, stored.group);
|
|
56
|
+
res.json({ key: req.params.key, value: stored.value });
|
|
57
|
+
},
|
|
58
|
+
async delete(req, res) {
|
|
59
|
+
// Deleting an unknown key is harmless, but refusing it keeps the API
|
|
60
|
+
// consistent: every key this controller touches is one it knows about.
|
|
61
|
+
// Legacy rows with unknown keys stay readable through `index`.
|
|
62
|
+
if (!isKnownSetting(req.params.key)) {
|
|
63
|
+
return res.json({ errors: { [req.params.key]: ['Unknown setting'] } }, 422);
|
|
64
|
+
}
|
|
65
|
+
await Settings.delete(req.params.key);
|
|
66
|
+
res.json({ message: 'Setting deleted' });
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* `GET /api/v1/site` — the site's identity: name, description, URL, logo,
|
|
70
|
+
* icon, default social image, time zone, locale and code injection.
|
|
71
|
+
*
|
|
72
|
+
* `code_injection` is admin-authored HTML for the front end to insert raw
|
|
73
|
+
* into <head> and before </body>. It is deliberately not sanitised — it
|
|
74
|
+
* exists to carry <script> tags — and only the admin role can set it.
|
|
75
|
+
*/
|
|
76
|
+
async publicSite(_req, res) {
|
|
77
|
+
res.json({ data: await Settings.siteInfo() });
|
|
78
|
+
},
|
|
79
|
+
// Convenience endpoints for common settings
|
|
80
|
+
async getSiteInfo(req, res) {
|
|
81
|
+
const siteName = await Settings.getSiteName();
|
|
82
|
+
const siteDescription = await Settings.getSiteDescription();
|
|
83
|
+
res.json({
|
|
84
|
+
site_name: siteName,
|
|
85
|
+
site_description: siteDescription
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
async updateSiteInfo(req, res) {
|
|
89
|
+
const { site_name, site_description } = req.body;
|
|
90
|
+
// Same rules as `update`, so this older endpoint is not a way around them.
|
|
91
|
+
const result = validateSettings({
|
|
92
|
+
...(site_name ? { site_name } : {}),
|
|
93
|
+
...(site_description !== undefined ? { site_description } : {})
|
|
94
|
+
});
|
|
95
|
+
if ('errors' in result)
|
|
96
|
+
return res.json({ errors: result.errors }, 422);
|
|
97
|
+
for (const [key, { value, group }] of Object.entries(result.values)) {
|
|
98
|
+
await Settings.set(key, value, group);
|
|
99
|
+
}
|
|
100
|
+
res.json({
|
|
101
|
+
site_name: await Settings.getSiteName(),
|
|
102
|
+
site_description: await Settings.getSiteDescription()
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|