@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,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin surface extension points.
|
|
3
|
+
*
|
|
4
|
+
* `admin.menu`, `admin.dashboard` and `admin.init` were declared as hooks and
|
|
5
|
+
* fired by nothing, so there was no way to add a nav item or a dashboard
|
|
6
|
+
* panel.
|
|
7
|
+
*
|
|
8
|
+
* They fire **here**, on the server, rather than in the React admin — which
|
|
9
|
+
* matters more than it looks. The hook registry is a singleton per JavaScript
|
|
10
|
+
* realm, and the browser is a different realm from the server. `src/hooks.ts`
|
|
11
|
+
* is imported by the server entry, so its listeners are on that registry; a hook
|
|
12
|
+
* fired in the browser would consult an empty one and find nothing. So the
|
|
13
|
+
* admin UI asks the server what to render, and the server is where listeners are.
|
|
14
|
+
*/
|
|
15
|
+
import type { Request, Response } from '../types/index.ts';
|
|
16
|
+
export declare const AdminController: {
|
|
17
|
+
/**
|
|
18
|
+
* The admin navigation, after listeners have had their say.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* hooks.on('admin.menu', (items) => [
|
|
22
|
+
* ...items,
|
|
23
|
+
* { path: '/admin/seo', label: 'SEO', icon: '🔍', section: 'Site' }
|
|
24
|
+
* ])
|
|
25
|
+
*
|
|
26
|
+
* An item joins the section it names, wherever in the list it is added, and
|
|
27
|
+
* creates that heading if it is a new one. Leave `section` off and it sits at
|
|
28
|
+
* the top beside the dashboard.
|
|
29
|
+
*/
|
|
30
|
+
menu(req: Request, res: Response): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Dashboard statistics, and any panels listeners contribute.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* hooks.on('admin.dashboard', (data) => ({
|
|
36
|
+
* ...data,
|
|
37
|
+
* panels: [...data.panels, { title: 'Search', body: '…' }]
|
|
38
|
+
* }))
|
|
39
|
+
*/
|
|
40
|
+
dashboard(req: Request, res: Response): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Fired once when the admin UI boots, so a listener can register or warm
|
|
43
|
+
* anything it needs before the first screen renders.
|
|
44
|
+
*/
|
|
45
|
+
init(req: Request, res: Response): Promise<void>;
|
|
46
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin surface extension points.
|
|
3
|
+
*
|
|
4
|
+
* `admin.menu`, `admin.dashboard` and `admin.init` were declared as hooks and
|
|
5
|
+
* fired by nothing, so there was no way to add a nav item or a dashboard
|
|
6
|
+
* panel.
|
|
7
|
+
*
|
|
8
|
+
* They fire **here**, on the server, rather than in the React admin — which
|
|
9
|
+
* matters more than it looks. The hook registry is a singleton per JavaScript
|
|
10
|
+
* realm, and the browser is a different realm from the server. `src/hooks.ts`
|
|
11
|
+
* is imported by the server entry, so its listeners are on that registry; a hook
|
|
12
|
+
* fired in the browser would consult an empty one and find nothing. So the
|
|
13
|
+
* admin UI asks the server what to render, and the server is where listeners are.
|
|
14
|
+
*/
|
|
15
|
+
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
16
|
+
import { can } from '@basicbenframework/core/auth/permissions';
|
|
17
|
+
import { Post } from "../models/Post.js";
|
|
18
|
+
import { Page } from "../models/Page.js";
|
|
19
|
+
import { Comment } from "../models/Comment.js";
|
|
20
|
+
import { Media } from "../models/Media.js";
|
|
21
|
+
import { Settings } from "../models/Settings.js";
|
|
22
|
+
import { withFeaturePages } from "../host/menu.js";
|
|
23
|
+
import { enabledManifests } from "../host/index.js";
|
|
24
|
+
/**
|
|
25
|
+
* The menu the admin ships with. Listeners filter it, they do not replace it.
|
|
26
|
+
*
|
|
27
|
+
* `section` is the heading an item sits under in the sidebar. Ten flat links
|
|
28
|
+
* read as a list to be scanned; grouped, the shape of the admin is visible from
|
|
29
|
+
* the nav — what you write, what you configure, and what is yours. An item
|
|
30
|
+
* without a section sits at the top with the dashboard.
|
|
31
|
+
*
|
|
32
|
+
* The client keeps an identical copy as its fallback, and a test fails when the
|
|
33
|
+
* two disagree — a difference is not a fallback, it is a flicker on every
|
|
34
|
+
* navigation.
|
|
35
|
+
*/
|
|
36
|
+
const CORE_MENU = [
|
|
37
|
+
{ path: '/admin', label: 'Dashboard', icon: '📊' },
|
|
38
|
+
{ path: '/admin/posts', label: 'Posts', icon: '📝', section: 'Content' },
|
|
39
|
+
{ path: '/admin/pages', label: 'Pages', icon: '📄', section: 'Content' },
|
|
40
|
+
{ path: '/admin/categories', label: 'Categories', icon: '📁', section: 'Content' },
|
|
41
|
+
{ path: '/admin/tags', label: 'Tags', icon: '🏷️', section: 'Content' },
|
|
42
|
+
{ path: '/admin/taxonomies', label: 'Taxonomies', icon: '🗃️', section: 'Content', capability: 'settings.manage' },
|
|
43
|
+
{ path: '/admin/comments', label: 'Comments', icon: '💬', section: 'Content' },
|
|
44
|
+
{ path: '/admin/media', label: 'Media', icon: '🖼️', section: 'Content' },
|
|
45
|
+
{ path: '/admin/snippets', label: 'Snippets', icon: '🧩', section: 'Content', capability: 'post.publish' },
|
|
46
|
+
{ path: '/admin/tokens', label: 'API tokens', icon: '🔑', section: 'Site' },
|
|
47
|
+
{ path: '/admin/settings', label: 'Settings', icon: '⚙️', section: 'Site' },
|
|
48
|
+
{ path: '/admin/content-types', label: 'Content types', icon: '🗂️', section: 'Site', capability: 'settings.manage' },
|
|
49
|
+
{ path: '/admin/navigation', label: 'Navigation', icon: '🧭', section: 'Site', capability: 'settings.manage' },
|
|
50
|
+
{ path: '/admin/redirects', label: 'Redirects', icon: '↪️', section: 'Site', capability: 'settings.manage' },
|
|
51
|
+
// Gated: only someone who can manage accounts is shown the way to them. The
|
|
52
|
+
// routes behind it refuse everyone else regardless — this is presentation.
|
|
53
|
+
{ path: '/admin/users', label: 'Users', icon: '👥', section: 'Site', capability: 'user.manage' },
|
|
54
|
+
{ path: '/admin/tools', label: 'Tools', icon: '🧰', section: 'Site', capability: 'user.manage' },
|
|
55
|
+
{ path: '/admin/health', label: 'Site health', icon: '🩺', section: 'Site', capability: 'user.manage' },
|
|
56
|
+
// Where an author edits their own byline. It lives outside /admin because it
|
|
57
|
+
// is the one screen every account has, admin area or not — but the people
|
|
58
|
+
// writing posts are in here, so the way to it has to be too.
|
|
59
|
+
{ path: '/profile', label: 'Profile', icon: '👤', section: 'Account' }
|
|
60
|
+
];
|
|
61
|
+
/**
|
|
62
|
+
* Core's menu with each enabled feature's pages placed in it. A function, as
|
|
63
|
+
* this module loads before the server registers the site's features.
|
|
64
|
+
*/
|
|
65
|
+
function defaultMenu() {
|
|
66
|
+
return withFeaturePages(CORE_MENU, enabledManifests());
|
|
67
|
+
}
|
|
68
|
+
export const AdminController = {
|
|
69
|
+
/**
|
|
70
|
+
* The admin navigation, after listeners have had their say.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* hooks.on('admin.menu', (items) => [
|
|
74
|
+
* ...items,
|
|
75
|
+
* { path: '/admin/seo', label: 'SEO', icon: '🔍', section: 'Site' }
|
|
76
|
+
* ])
|
|
77
|
+
*
|
|
78
|
+
* An item joins the section it names, wherever in the list it is added, and
|
|
79
|
+
* creates that heading if it is a new one. Leave `section` off and it sits at
|
|
80
|
+
* the top beside the dashboard.
|
|
81
|
+
*/
|
|
82
|
+
async menu(req, res) {
|
|
83
|
+
const fallback = defaultMenu();
|
|
84
|
+
const items = await hooks.filter(HOOKS.ADMIN_MENU, [...fallback], { req });
|
|
85
|
+
// A listener that returns something that is not a list should not blank the
|
|
86
|
+
// navigation — it should be ignored.
|
|
87
|
+
const menu = Array.isArray(items) ? items : fallback;
|
|
88
|
+
res.json({
|
|
89
|
+
// The admin's default language; see src/client/i18n. Here rather than
|
|
90
|
+
// a request of its own because every admin screen already makes this one.
|
|
91
|
+
locale: (await Settings.get('admin_locale')) || null,
|
|
92
|
+
menu: menu.filter((item) => item && typeof item.path === 'string' && typeof item.label === 'string' &&
|
|
93
|
+
// After the listeners, so an item a hook adds can be gated the same
|
|
94
|
+
// way by naming a capability.
|
|
95
|
+
(!item.capability || can(req.user ?? null, item.capability)))
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Dashboard statistics, and any panels listeners contribute.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* hooks.on('admin.dashboard', (data) => ({
|
|
103
|
+
* ...data,
|
|
104
|
+
* panels: [...data.panels, { title: 'Search', body: '…' }]
|
|
105
|
+
* }))
|
|
106
|
+
*/
|
|
107
|
+
async dashboard(req, res) {
|
|
108
|
+
const [posts, pages, pendingComments, mediaStats] = await Promise.all([
|
|
109
|
+
Post.findByUser(req.userId),
|
|
110
|
+
Page.all(),
|
|
111
|
+
Comment.countPending(),
|
|
112
|
+
Media.getStats()
|
|
113
|
+
]);
|
|
114
|
+
const data = await hooks.filter(HOOKS.ADMIN_DASHBOARD, {
|
|
115
|
+
stats: {
|
|
116
|
+
posts: posts.length,
|
|
117
|
+
pages: pages.length,
|
|
118
|
+
pendingComments,
|
|
119
|
+
media: mediaStats?.total ?? 0
|
|
120
|
+
},
|
|
121
|
+
recentPosts: posts.slice(0, 5),
|
|
122
|
+
panels: []
|
|
123
|
+
}, { req });
|
|
124
|
+
res.json(data);
|
|
125
|
+
},
|
|
126
|
+
/**
|
|
127
|
+
* Fired once when the admin UI boots, so a listener can register or warm
|
|
128
|
+
* anything it needs before the first screen renders.
|
|
129
|
+
*/
|
|
130
|
+
async init(req, res) {
|
|
131
|
+
await hooks.fire(HOOKS.ADMIN_INIT, { userId: req.userId, req });
|
|
132
|
+
res.json({ ok: true });
|
|
133
|
+
}
|
|
134
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
export declare const AuthController: {
|
|
3
|
+
register(req: Request, res: Response): Promise<void>;
|
|
4
|
+
login(req: Request, res: Response): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Sign out, everywhere.
|
|
7
|
+
*
|
|
8
|
+
* Bumps the account's token version, so this token and every other one the
|
|
9
|
+
* account holds stop working on their next request. A stateless token cannot
|
|
10
|
+
* be revoked one at a time without a denylist; ending them all is the
|
|
11
|
+
* conservative choice for an admin account.
|
|
12
|
+
*/
|
|
13
|
+
logout(req: Request, res: Response): Promise<void>;
|
|
14
|
+
user(req: Request, res: Response): Promise<void>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
2
|
+
import { hashPassword, verifyPassword } from '@basicbenframework/core/auth';
|
|
3
|
+
import { ROLES, DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions';
|
|
4
|
+
import { User } from "../models/User.js";
|
|
5
|
+
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
6
|
+
import { sendVerificationEmail } from "./EmailVerificationController.js";
|
|
7
|
+
import { issueChallenge } from "./TwoFactorController.js";
|
|
8
|
+
import { TwoFactor } from "../models/TwoFactor.js";
|
|
9
|
+
import { Credential } from "../models/Credential.js";
|
|
10
|
+
import { loginByAddress, loginByAccount } from "../middleware/rate-limits.js";
|
|
11
|
+
import { issueSessionToken, revokeSessions } from "../helpers/session.js";
|
|
12
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
13
|
+
/**
|
|
14
|
+
* A hash to check against when the address has no account.
|
|
15
|
+
*
|
|
16
|
+
* Without it a login for an unknown address returns before scrypt runs, and
|
|
17
|
+
* the difference in response time says which addresses are registered.
|
|
18
|
+
* Computed once, lazily, from a password nobody will ever send.
|
|
19
|
+
*/
|
|
20
|
+
let dummyHash = null;
|
|
21
|
+
function decoyHash() {
|
|
22
|
+
dummyHash ??= hashPassword('basicben-timing-decoy-' + Math.random());
|
|
23
|
+
return dummyHash;
|
|
24
|
+
}
|
|
25
|
+
// Computed at startup rather than on the first unknown address, which would
|
|
26
|
+
// otherwise pay for hashing twice and be the one slow response.
|
|
27
|
+
void decoyHash();
|
|
28
|
+
export const AuthController = {
|
|
29
|
+
async register(req, res) {
|
|
30
|
+
const result = await validate(req.body, {
|
|
31
|
+
name: [rules.required, rules.string, rules.min(2)],
|
|
32
|
+
email: [rules.required, rules.email],
|
|
33
|
+
password: [rules.required, rules.min(8)]
|
|
34
|
+
});
|
|
35
|
+
if (result.fails()) {
|
|
36
|
+
return res.json({ errors: result.errors }, 422);
|
|
37
|
+
}
|
|
38
|
+
const { name, email, password } = req.body;
|
|
39
|
+
// The first account to register is the operator setting the site up, so it
|
|
40
|
+
// becomes the admin. Everyone after gets the least privileged role.
|
|
41
|
+
const isFirstUser = (await User.count()) === 0;
|
|
42
|
+
// DISABLE_REGISTRATION closes the door behind that first account.
|
|
43
|
+
//
|
|
44
|
+
// It deliberately does not apply when there are no users at all. A fresh
|
|
45
|
+
// deployment with the flag already set would otherwise have no way to
|
|
46
|
+
// create its own admin — the flag would lock the operator out of the site
|
|
47
|
+
// they are installing, which is a trap rather than a security measure.
|
|
48
|
+
// Once one account exists the flag is absolute.
|
|
49
|
+
//
|
|
50
|
+
// Enforced here rather than in the router because the client hides the
|
|
51
|
+
// form, and hiding a form is not a control.
|
|
52
|
+
//
|
|
53
|
+
// This runs *before* the address is looked up, and the order is the point.
|
|
54
|
+
// Checking for a duplicate first would answer a question the caller has no
|
|
55
|
+
// business asking: a taken address would come back "already registered"
|
|
56
|
+
// while a free one came back "closed", turning an endpoint that refuses
|
|
57
|
+
// everyone into a way to test which addresses have accounts.
|
|
58
|
+
if (!isFirstUser && process.env.DISABLE_REGISTRATION === 'true') {
|
|
59
|
+
return res.json({ error: 'Registration is closed' }, 403);
|
|
60
|
+
}
|
|
61
|
+
// Check if email exists
|
|
62
|
+
const existing = await User.findByEmail(email);
|
|
63
|
+
if (existing) {
|
|
64
|
+
return res.json({ error: 'Email already registered' }, 400);
|
|
65
|
+
}
|
|
66
|
+
const role = isFirstUser ? ROLES.ADMIN : DEFAULT_ROLE;
|
|
67
|
+
// The first account is the operator setting the site up, and on a fresh
|
|
68
|
+
// install mail is very likely unconfigured. Requiring them to click a link
|
|
69
|
+
// that was never delivered would lock them out of their own admin.
|
|
70
|
+
const emailVerified = isFirstUser;
|
|
71
|
+
let user = await User.create({
|
|
72
|
+
name,
|
|
73
|
+
email,
|
|
74
|
+
password: await hashPassword(password),
|
|
75
|
+
role,
|
|
76
|
+
email_verified: emailVerified ? 1 : 0,
|
|
77
|
+
email_verified_at: emailVerified ? new Date().toISOString() : null
|
|
78
|
+
});
|
|
79
|
+
// "First" was decided by a count taken before the insert, so two signups
|
|
80
|
+
// racing on a fresh install could both see zero and both become admin.
|
|
81
|
+
// Only the lowest id keeps it; anyone else who raced is demoted on the spot.
|
|
82
|
+
if (isFirstUser) {
|
|
83
|
+
const db = await getDb();
|
|
84
|
+
const first = await db.get('SELECT MIN(id) AS id FROM users');
|
|
85
|
+
if (Number(first?.id) !== Number(user.id)) {
|
|
86
|
+
user = await User.update(user.id, { role: DEFAULT_ROLE, email_verified: 0, email_verified_at: null });
|
|
87
|
+
return res.json({ error: 'Registration conflicted with another signup. Please sign in.' }, 409);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let verificationSent = false;
|
|
91
|
+
if (!emailVerified) {
|
|
92
|
+
// A provider outage must not fail the registration. The account exists
|
|
93
|
+
// either way, so returning 500 here would leave the caller believing it
|
|
94
|
+
// does not; the flag lets the client offer a resend instead.
|
|
95
|
+
try {
|
|
96
|
+
await sendVerificationEmail(user);
|
|
97
|
+
verificationSent = true;
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error('Failed to send verification email:', err.message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const token = issueSessionToken({ id: user.id, role, email_verified: emailVerified, token_version: 0 });
|
|
104
|
+
await hooks.fire(HOOKS.AUTH_REGISTER, { user, role, verificationSent });
|
|
105
|
+
res.json({
|
|
106
|
+
user: {
|
|
107
|
+
id: user.id,
|
|
108
|
+
name: user.name,
|
|
109
|
+
email: user.email,
|
|
110
|
+
role,
|
|
111
|
+
email_verified: emailVerified
|
|
112
|
+
},
|
|
113
|
+
token,
|
|
114
|
+
verificationSent
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
async login(req, res) {
|
|
118
|
+
const { email, password } = req.body;
|
|
119
|
+
if (!email || !password) {
|
|
120
|
+
return res.json({ error: 'Email and password required' }, 400);
|
|
121
|
+
}
|
|
122
|
+
const user = await User.findByEmail(email);
|
|
123
|
+
if (!user) {
|
|
124
|
+
// Same work as a wrong password, so the two cannot be told apart by time.
|
|
125
|
+
await verifyPassword(password, await decoyHash());
|
|
126
|
+
return res.json({ error: 'Invalid credentials' }, 401);
|
|
127
|
+
}
|
|
128
|
+
if (!(await verifyPassword(password, user.password))) {
|
|
129
|
+
return res.json({ error: 'Invalid credentials' }, 401);
|
|
130
|
+
}
|
|
131
|
+
// Checked only after the password, so a disabled account is not revealed
|
|
132
|
+
// to someone who does not know its password.
|
|
133
|
+
if (user.disabled_at) {
|
|
134
|
+
return res.json({ error: 'This account has been disabled.' }, 403);
|
|
135
|
+
}
|
|
136
|
+
// With a second factor enrolled the password alone is not a session. The
|
|
137
|
+
// caller gets a challenge to exchange at /api/auth/2fa/verify instead.
|
|
138
|
+
// The password was correct, so this attempt should not count against the
|
|
139
|
+
// guess allowance.
|
|
140
|
+
await loginByAddress.limiter.reset(loginByAddress.key(req));
|
|
141
|
+
await loginByAccount.limiter.reset(loginByAccount.key(req));
|
|
142
|
+
const twoFactor = await TwoFactor.find(user.id);
|
|
143
|
+
const passkeyCount = await Credential.countForUser(user.id);
|
|
144
|
+
if (TwoFactor.isEnabled(twoFactor) || passkeyCount > 0) {
|
|
145
|
+
const { challenge, expiresAt } = await issueChallenge(user.id);
|
|
146
|
+
const methods = [];
|
|
147
|
+
if (passkeyCount > 0)
|
|
148
|
+
methods.push('passkey');
|
|
149
|
+
if (TwoFactor.isEnabled(twoFactor))
|
|
150
|
+
methods.push('totp', 'recovery');
|
|
151
|
+
return res.json({ twoFactorRequired: true, methods, challenge, expiresAt });
|
|
152
|
+
}
|
|
153
|
+
const token = issueSessionToken(user);
|
|
154
|
+
await hooks.fire(HOOKS.AUTH_LOGIN, { user, req });
|
|
155
|
+
res.json({
|
|
156
|
+
user: {
|
|
157
|
+
id: user.id,
|
|
158
|
+
name: user.name,
|
|
159
|
+
email: user.email,
|
|
160
|
+
role: user.role ?? DEFAULT_ROLE,
|
|
161
|
+
email_verified: Boolean(user.email_verified)
|
|
162
|
+
},
|
|
163
|
+
token
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Sign out, everywhere.
|
|
168
|
+
*
|
|
169
|
+
* Bumps the account's token version, so this token and every other one the
|
|
170
|
+
* account holds stop working on their next request. A stateless token cannot
|
|
171
|
+
* be revoked one at a time without a denylist; ending them all is the
|
|
172
|
+
* conservative choice for an admin account.
|
|
173
|
+
*/
|
|
174
|
+
async logout(req, res) {
|
|
175
|
+
await revokeSessions(req.userId);
|
|
176
|
+
await hooks.fire(HOOKS.AUTH_LOGOUT, { userId: req.userId, req });
|
|
177
|
+
res.json({ message: 'Signed out.' });
|
|
178
|
+
},
|
|
179
|
+
async user(req, res) {
|
|
180
|
+
const user = await User.find(req.userId);
|
|
181
|
+
if (!user) {
|
|
182
|
+
return res.json({ error: 'User not found' }, 404);
|
|
183
|
+
}
|
|
184
|
+
res.json({
|
|
185
|
+
user: {
|
|
186
|
+
id: user.id,
|
|
187
|
+
name: user.name,
|
|
188
|
+
email: user.email,
|
|
189
|
+
role: user.role ?? DEFAULT_ROLE,
|
|
190
|
+
email_verified: Boolean(user.email_verified)
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who a post can be attributed to.
|
|
3
|
+
*
|
|
4
|
+
* The editor needs a list of people before it can offer an Author menu, and
|
|
5
|
+
* that list is not "every user": a subscriber has an account so they can
|
|
6
|
+
* comment, and putting them in a byline menu invites a post attributed to
|
|
7
|
+
* someone who cannot write one. `User.authors()` filters by capability instead
|
|
8
|
+
* of by role name, so the answer stays right when the role table changes.
|
|
9
|
+
*
|
|
10
|
+
* Reading the list needs `post.create` — you have to be able to write before
|
|
11
|
+
* the question is meaningful. Actually reassigning a post needs `post.edit`,
|
|
12
|
+
* which `PostController` enforces on the write.
|
|
13
|
+
*/
|
|
14
|
+
import type { Request, Response } from '../types/index.ts';
|
|
15
|
+
export declare const AuthorController: {
|
|
16
|
+
index(_req: Request, res: Response): Promise<void>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who a post can be attributed to.
|
|
3
|
+
*
|
|
4
|
+
* The editor needs a list of people before it can offer an Author menu, and
|
|
5
|
+
* that list is not "every user": a subscriber has an account so they can
|
|
6
|
+
* comment, and putting them in a byline menu invites a post attributed to
|
|
7
|
+
* someone who cannot write one. `User.authors()` filters by capability instead
|
|
8
|
+
* of by role name, so the answer stays right when the role table changes.
|
|
9
|
+
*
|
|
10
|
+
* Reading the list needs `post.create` — you have to be able to write before
|
|
11
|
+
* the question is meaningful. Actually reassigning a post needs `post.edit`,
|
|
12
|
+
* which `PostController` enforces on the write.
|
|
13
|
+
*/
|
|
14
|
+
import { User } from "../models/User.js";
|
|
15
|
+
export const AuthorController = {
|
|
16
|
+
async index(_req, res) {
|
|
17
|
+
res.json({ authors: await User.authors() });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
export declare const CategoryController: {
|
|
3
|
+
index(req: Request, res: Response): Promise<void>;
|
|
4
|
+
tree(req: Request, res: Response): Promise<void>;
|
|
5
|
+
show(req: Request, res: Response): Promise<void>;
|
|
6
|
+
showBySlug(req: Request, res: Response): Promise<void>;
|
|
7
|
+
store(req: Request, res: Response): Promise<void>;
|
|
8
|
+
update(req: Request, res: Response): Promise<void>;
|
|
9
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
2
|
+
import { Category } from "../models/Category.js";
|
|
3
|
+
export const CategoryController = {
|
|
4
|
+
async index(req, res) {
|
|
5
|
+
const categories = await Category.all();
|
|
6
|
+
res.json({ categories });
|
|
7
|
+
},
|
|
8
|
+
async tree(req, res) {
|
|
9
|
+
const categories = await Category.tree();
|
|
10
|
+
res.json({ categories });
|
|
11
|
+
},
|
|
12
|
+
async show(req, res) {
|
|
13
|
+
const category = await Category.find(parseInt(req.params.id));
|
|
14
|
+
if (!category) {
|
|
15
|
+
return res.json({ error: 'Category not found' }, 404);
|
|
16
|
+
}
|
|
17
|
+
res.json({ category });
|
|
18
|
+
},
|
|
19
|
+
async showBySlug(req, res) {
|
|
20
|
+
const category = await Category.findBySlug(req.params.slug);
|
|
21
|
+
if (!category) {
|
|
22
|
+
return res.json({ error: 'Category not found' }, 404);
|
|
23
|
+
}
|
|
24
|
+
res.json({ category });
|
|
25
|
+
},
|
|
26
|
+
async store(req, res) {
|
|
27
|
+
const result = await validate(req.body, {
|
|
28
|
+
name: [rules.required, rules.string, rules.min(2), rules.max(100)]
|
|
29
|
+
});
|
|
30
|
+
if (result.fails()) {
|
|
31
|
+
return res.json({ errors: result.errors }, 422);
|
|
32
|
+
}
|
|
33
|
+
const { name, slug, description, parent_id } = req.body;
|
|
34
|
+
// Check for slug uniqueness if provided
|
|
35
|
+
if (slug) {
|
|
36
|
+
const exists = await Category.slugExists(slug);
|
|
37
|
+
if (exists) {
|
|
38
|
+
return res.json({ errors: { slug: ['Slug already exists'] } }, 422);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const category = await Category.create({
|
|
42
|
+
name,
|
|
43
|
+
slug: slug || name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, ''),
|
|
44
|
+
description,
|
|
45
|
+
parent_id
|
|
46
|
+
});
|
|
47
|
+
res.json({ category }, 201);
|
|
48
|
+
},
|
|
49
|
+
async update(req, res) {
|
|
50
|
+
const category = await Category.find(parseInt(req.params.id));
|
|
51
|
+
if (!category) {
|
|
52
|
+
return res.json({ error: 'Category not found' }, 404);
|
|
53
|
+
}
|
|
54
|
+
const result = await validate(req.body, {
|
|
55
|
+
name: [rules.required, rules.string, rules.min(2), rules.max(100)]
|
|
56
|
+
});
|
|
57
|
+
if (result.fails()) {
|
|
58
|
+
return res.json({ errors: result.errors }, 422);
|
|
59
|
+
}
|
|
60
|
+
const { name, slug, description, parent_id } = req.body;
|
|
61
|
+
// Check for slug uniqueness if changed
|
|
62
|
+
if (slug && slug !== category.slug) {
|
|
63
|
+
const exists = await Category.slugExists(slug, category.id);
|
|
64
|
+
if (exists) {
|
|
65
|
+
return res.json({ errors: { slug: ['Slug already exists'] } }, 422);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Prevent setting parent to self or to a child
|
|
69
|
+
if (parent_id === category.id) {
|
|
70
|
+
return res.json({ errors: { parent_id: ['Cannot set category as its own parent'] } }, 422);
|
|
71
|
+
}
|
|
72
|
+
const updated = await Category.update(parseInt(req.params.id), {
|
|
73
|
+
name,
|
|
74
|
+
slug,
|
|
75
|
+
description,
|
|
76
|
+
parent_id
|
|
77
|
+
});
|
|
78
|
+
res.json({ category: updated });
|
|
79
|
+
},
|
|
80
|
+
async destroy(req, res) {
|
|
81
|
+
const category = await Category.find(parseInt(req.params.id));
|
|
82
|
+
if (!category) {
|
|
83
|
+
return res.json({ error: 'Category not found' }, 404);
|
|
84
|
+
}
|
|
85
|
+
await Category.delete(parseInt(req.params.id));
|
|
86
|
+
res.json({ message: 'Category deleted' });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
export declare const CommentController: {
|
|
3
|
+
/**
|
|
4
|
+
* The moderation list: one status, one page, and the count behind every tab.
|
|
5
|
+
*
|
|
6
|
+
* `?status=` is pending, approved, spam, trash or all (pending and approved
|
|
7
|
+
* together). It used to return every comment ever written, in one response.
|
|
8
|
+
*/
|
|
9
|
+
index(req: Request, res: Response): Promise<void>;
|
|
10
|
+
pending(req: Request, res: Response): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* A post's comments.
|
|
13
|
+
*
|
|
14
|
+
* For readers, the approved comments as a tree — see
|
|
15
|
+
* `Comment.findPublicByPostId` for the shape and order — plus `form`, what a
|
|
16
|
+
* comment form needs to post back: whether comments are open, the signed
|
|
17
|
+
* timestamp, the honeypot's name and how deep replies may go. A form that
|
|
18
|
+
* ignores `form` still works; its comments are held for moderation.
|
|
19
|
+
*/
|
|
20
|
+
byPost(req: Request, res: Response): Promise<void>;
|
|
21
|
+
show(req: Request, res: Response): Promise<void>;
|
|
22
|
+
store(req: Request, res: Response): Promise<void>;
|
|
23
|
+
update(req: Request, res: Response): Promise<void>;
|
|
24
|
+
approve(req: Request, res: Response): Promise<void>;
|
|
25
|
+
/** Move one comment to a status: approve, unapprove, spam, not spam, trash, restore. */
|
|
26
|
+
setStatus(req: Request, res: Response): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* One action over many comments: `approve`, `pending`, `spam`, `trash` or
|
|
29
|
+
* `delete` (for good). Up to MAX_BULK ids at once.
|
|
30
|
+
*/
|
|
31
|
+
bulk(req: Request, res: Response): Promise<void>;
|
|
32
|
+
/** Empty the spam folder or the trash, for good. */
|
|
33
|
+
empty(req: Request, res: Response): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete a comment: to the trash first, then for good.
|
|
36
|
+
*
|
|
37
|
+
* A comment already in the spam or the trash, or a request with
|
|
38
|
+
* `?force=true`, is deleted permanently; anything else is trashed, so one
|
|
39
|
+
* misclick in a moderation queue can be undone.
|
|
40
|
+
*/
|
|
41
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* The comment settings this page owns: the blocklist, the link limit and
|
|
44
|
+
* who hears about comments awaiting moderation.
|
|
45
|
+
*
|
|
46
|
+
* Moderators may read them — the blocklist is what explains why a comment
|
|
47
|
+
* was caught — but changing them is site configuration.
|
|
48
|
+
*/
|
|
49
|
+
settings(req: Request, res: Response): Promise<void>;
|
|
50
|
+
updateSettings(req: Request, res: Response): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* The unsubscribe link from a reply notification: a confirmation page.
|
|
53
|
+
*
|
|
54
|
+
* GET only shows a button. Mail scanners and link previewers open every
|
|
55
|
+
* link in a message, and a GET that unsubscribed would turn notifications
|
|
56
|
+
* off before the reader saw them.
|
|
57
|
+
*/
|
|
58
|
+
unsubscribePage(req: Request, res: Response): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Turn reply emails off for one comment.
|
|
61
|
+
*
|
|
62
|
+
* Also the RFC 8058 one-click target, which a mail client POSTs to with
|
|
63
|
+
* `List-Unsubscribe=One-Click` and reads only the status of. Safe without
|
|
64
|
+
* a session or CSRF token: the signed link is the authority, and the only
|
|
65
|
+
* thing it can do is stop mail.
|
|
66
|
+
*/
|
|
67
|
+
unsubscribe(req: Request, res: Response): Promise<void>;
|
|
68
|
+
};
|