@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,438 @@
|
|
|
1
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
2
|
+
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
3
|
+
import { Comment } from "../models/Comment.js";
|
|
4
|
+
import { Settings } from "../models/Settings.js";
|
|
5
|
+
import { Post } from "../models/Post.js";
|
|
6
|
+
import { can } from '@basicbenframework/core/auth/permissions';
|
|
7
|
+
import { paginationFrom, meta } from "../models/pagination.js";
|
|
8
|
+
import { clientIp } from "../middleware/rate-limits.js";
|
|
9
|
+
import { guardWrite } from "../helpers/write-hooks.js";
|
|
10
|
+
import { MAX_DEPTH, HONEYPOT_FIELD, DEFAULT_MAX_LINKS, COMMENT_STATUSES, isCommentStatus, issueFormToken, readUnsubscribeToken, parseBlocklist, assess } from "../helpers/comment-guard.js";
|
|
11
|
+
import { inBackground, notifyAwaitingModeration, notifyParentOfReply, notifyAudience, NOTIFY_AUDIENCES } from "../helpers/comment-mail.js";
|
|
12
|
+
/** The most comments one bulk action may touch: a page and then some. */
|
|
13
|
+
const MAX_BULK = 200;
|
|
14
|
+
/** The blocklist setting's size cap. Thousands of entries, not a megabyte of text. */
|
|
15
|
+
const MAX_BLOCKLIST_LENGTH = 20_000;
|
|
16
|
+
/**
|
|
17
|
+
* What the commenter is told about the comment they just posted.
|
|
18
|
+
*
|
|
19
|
+
* Built field by field: the stored row carries their address and IP, and
|
|
20
|
+
* nothing else in this response needs either. Spam is reported as pending —
|
|
21
|
+
* telling a bot which of its tricks was caught is telling it what to change.
|
|
22
|
+
*/
|
|
23
|
+
function submitted(comment) {
|
|
24
|
+
const status = comment.status === 'approved' ? 'approved' : 'pending';
|
|
25
|
+
return {
|
|
26
|
+
id: comment.id,
|
|
27
|
+
post_id: comment.post_id,
|
|
28
|
+
parent_id: comment.parent_id ?? null,
|
|
29
|
+
author_name: comment.author_name ?? null,
|
|
30
|
+
content: comment.content,
|
|
31
|
+
created_at: comment.created_at,
|
|
32
|
+
approved: status === 'approved',
|
|
33
|
+
status
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The ids in a request body, as positive integers, deduplicated and capped. */
|
|
37
|
+
function idsFrom(value) {
|
|
38
|
+
if (!Array.isArray(value))
|
|
39
|
+
return null;
|
|
40
|
+
const ids = [...new Set(value.map(Number).filter(id => Number.isInteger(id) && id > 0))];
|
|
41
|
+
return ids.length && ids.length <= MAX_BULK ? ids : null;
|
|
42
|
+
}
|
|
43
|
+
/** Everything that should follow a comment becoming approved. */
|
|
44
|
+
async function afterApproved(changed, userId) {
|
|
45
|
+
for (const comment of changed) {
|
|
46
|
+
await hooks.fire(HOOKS.COMMENT_APPROVED, { comment, userId });
|
|
47
|
+
if (comment.parent_id) {
|
|
48
|
+
inBackground('reply notification', () => notifyParentOfReply(Number(comment.id)));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function commentSettings() {
|
|
53
|
+
const maxLinks = Number.parseInt((await Settings.get('comment_max_links')) ?? '', 10);
|
|
54
|
+
return {
|
|
55
|
+
comment_blocklist: (await Settings.get('comment_blocklist')) ?? '',
|
|
56
|
+
comment_max_links: Number.isInteger(maxLinks) && maxLinks >= 0 ? maxLinks : DEFAULT_MAX_LINKS,
|
|
57
|
+
comment_notify: await notifyAudience()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const escapeHtml = (value) => value
|
|
61
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
62
|
+
.replace(/"/g, '"').replace(/'/g, ''');
|
|
63
|
+
/** A bare page for the unsubscribe link, which is opened from a mail client, not the app. */
|
|
64
|
+
function page(res, status, title, body) {
|
|
65
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
66
|
+
// Never cached, and never indexed: the URL carries a token.
|
|
67
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
68
|
+
res.setHeader('X-Robots-Tag', 'noindex');
|
|
69
|
+
res.status(status).send(`<!doctype html>
|
|
70
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
71
|
+
<meta name="referrer" content="no-referrer"><title>${escapeHtml(title)}</title></head>
|
|
72
|
+
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; max-width: 480px; margin: 48px auto; padding: 0 16px; color: #111; line-height: 1.5;">
|
|
73
|
+
<h1 style="font-size: 20px;">${escapeHtml(title)}</h1>
|
|
74
|
+
${body}
|
|
75
|
+
</body></html>`);
|
|
76
|
+
}
|
|
77
|
+
export const CommentController = {
|
|
78
|
+
/**
|
|
79
|
+
* The moderation list: one status, one page, and the count behind every tab.
|
|
80
|
+
*
|
|
81
|
+
* `?status=` is pending, approved, spam, trash or all (pending and approved
|
|
82
|
+
* together). It used to return every comment ever written, in one response.
|
|
83
|
+
*/
|
|
84
|
+
async index(req, res) {
|
|
85
|
+
const query = (req.query ?? {});
|
|
86
|
+
const status = query.status === undefined || query.status === 'all'
|
|
87
|
+
? 'all'
|
|
88
|
+
: isCommentStatus(query.status) ? query.status : null;
|
|
89
|
+
if (!status) {
|
|
90
|
+
return res.json({ errors: { status: [`Must be one of: all, ${COMMENT_STATUSES.join(', ')}`] } }, 422);
|
|
91
|
+
}
|
|
92
|
+
const { page, perPage, offset } = paginationFrom(query);
|
|
93
|
+
const [{ comments, total }, counts] = await Promise.all([
|
|
94
|
+
Comment.list({ status, limit: perPage, offset }),
|
|
95
|
+
Comment.counts()
|
|
96
|
+
]);
|
|
97
|
+
res.json({ comments, counts, meta: meta(page, perPage, total) });
|
|
98
|
+
},
|
|
99
|
+
async pending(req, res) {
|
|
100
|
+
const comments = await Comment.findPending();
|
|
101
|
+
const count = await Comment.countPending();
|
|
102
|
+
res.json({ comments, count });
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* A post's comments.
|
|
106
|
+
*
|
|
107
|
+
* For readers, the approved comments as a tree — see
|
|
108
|
+
* `Comment.findPublicByPostId` for the shape and order — plus `form`, what a
|
|
109
|
+
* comment form needs to post back: whether comments are open, the signed
|
|
110
|
+
* timestamp, the honeypot's name and how deep replies may go. A form that
|
|
111
|
+
* ignores `form` still works; its comments are held for moderation.
|
|
112
|
+
*/
|
|
113
|
+
async byPost(req, res) {
|
|
114
|
+
const postId = parseInt(req.params.postId);
|
|
115
|
+
// The whole thread — the moderation queue and the commenters' addresses —
|
|
116
|
+
// is for moderators. `?all=true` used to unlock it for anyone who asked.
|
|
117
|
+
if (req.query.all === 'true' && can(req.user, 'comment.moderate')) {
|
|
118
|
+
const comments = await Comment.findByPostId(postId, false);
|
|
119
|
+
return res.json({ comments });
|
|
120
|
+
}
|
|
121
|
+
// A draft's comments are as unpublished as the draft.
|
|
122
|
+
if (!(await Post.findPublishedById(postId))) {
|
|
123
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
124
|
+
}
|
|
125
|
+
const comments = await Comment.findPublicByPostId(postId);
|
|
126
|
+
res.json({
|
|
127
|
+
comments,
|
|
128
|
+
form: {
|
|
129
|
+
open: await Settings.getAllowComments(),
|
|
130
|
+
token: issueFormToken(postId),
|
|
131
|
+
honeypot: HONEYPOT_FIELD,
|
|
132
|
+
max_depth: MAX_DEPTH
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
async show(req, res) {
|
|
137
|
+
const comment = await Comment.find(parseInt(req.params.id));
|
|
138
|
+
if (!comment) {
|
|
139
|
+
return res.json({ error: 'Comment not found' }, 404);
|
|
140
|
+
}
|
|
141
|
+
res.json({ comment });
|
|
142
|
+
},
|
|
143
|
+
async store(req, res) {
|
|
144
|
+
const postId = parseInt(req.params.postId);
|
|
145
|
+
// Check if comments are allowed
|
|
146
|
+
const allowComments = await Settings.getAllowComments();
|
|
147
|
+
if (!allowComments) {
|
|
148
|
+
return res.json({ error: 'Comments are disabled' }, 403);
|
|
149
|
+
}
|
|
150
|
+
const requiresAuth = !req.userId;
|
|
151
|
+
const validationRules = {
|
|
152
|
+
content: [rules.required, rules.string, rules.min(3), rules.max(2000)]
|
|
153
|
+
};
|
|
154
|
+
// If not authenticated, require author info
|
|
155
|
+
if (requiresAuth) {
|
|
156
|
+
validationRules.author_name = [rules.required, rules.string, rules.min(2), rules.max(100)];
|
|
157
|
+
validationRules.author_email = [rules.required, rules.email];
|
|
158
|
+
}
|
|
159
|
+
const result = await validate(req.body, validationRules);
|
|
160
|
+
if (result.fails()) {
|
|
161
|
+
return res.json({ errors: result.errors }, 422);
|
|
162
|
+
}
|
|
163
|
+
const body = req.body;
|
|
164
|
+
const { content, author_name, author_email } = body;
|
|
165
|
+
// A checkbox arrives as true, "true", "on" or "1" depending on the form.
|
|
166
|
+
const notifyReplies = [true, 'true', 'on', '1', 1].includes(body.notify_replies);
|
|
167
|
+
// Only a published post takes comments; otherwise anyone could attach text
|
|
168
|
+
// to a draft by guessing its id.
|
|
169
|
+
const post = await Post.findPublishedById(postId);
|
|
170
|
+
if (!post) {
|
|
171
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
172
|
+
}
|
|
173
|
+
// A reply must answer a comment on the same post, or a thread could be
|
|
174
|
+
// stitched together across posts; must answer one readers can see, or a
|
|
175
|
+
// reply could be hung on a pending comment to fish for whether it exists;
|
|
176
|
+
// and must not nest deeper than the page will draw.
|
|
177
|
+
let parent_id;
|
|
178
|
+
const requestedParent = body.parent_id;
|
|
179
|
+
if (requestedParent !== undefined && requestedParent !== null && requestedParent !== '') {
|
|
180
|
+
const parent = await Comment.find(Number(requestedParent));
|
|
181
|
+
// Not approved gets the same answer as missing, for the reason above.
|
|
182
|
+
if (!parent || Number(parent.post_id) !== postId || parent.status !== 'approved') {
|
|
183
|
+
return res.json({ errors: { parent_id: ['That comment does not exist on this post'] } }, 422);
|
|
184
|
+
}
|
|
185
|
+
if ((await Comment.depthOf(parent)) >= MAX_DEPTH) {
|
|
186
|
+
return res.json({ errors: { parent_id: [`Replies can only nest ${MAX_DEPTH} levels deep`] } }, 422);
|
|
187
|
+
}
|
|
188
|
+
parent_id = Number(parent.id);
|
|
189
|
+
}
|
|
190
|
+
if (req.userId && !can(req.user, 'comment.create')) {
|
|
191
|
+
return res.json({ error: 'You do not have permission to comment.' }, 403);
|
|
192
|
+
}
|
|
193
|
+
// Check if moderation is enabled
|
|
194
|
+
const moderateComments = await Settings.getModerateComments();
|
|
195
|
+
// The spam checks. A moderator is exempt from all of them — they would
|
|
196
|
+
// only be marking their own words as spam to approve again — and any
|
|
197
|
+
// other signed-in commenter skips the bot checks but not the blocklist.
|
|
198
|
+
const ip = clientIp(req);
|
|
199
|
+
const settings = await commentSettings();
|
|
200
|
+
const verdict = can(req.user, 'comment.moderate')
|
|
201
|
+
? { status: null, reason: null }
|
|
202
|
+
: assess({
|
|
203
|
+
submission: { content, name: author_name, email: author_email, ip },
|
|
204
|
+
honeypot: body[HONEYPOT_FIELD],
|
|
205
|
+
formToken: body.form_token,
|
|
206
|
+
postId,
|
|
207
|
+
blocklist: parseBlocklist(settings.comment_blocklist),
|
|
208
|
+
maxLinks: settings.comment_max_links,
|
|
209
|
+
trusted: !!req.userId
|
|
210
|
+
});
|
|
211
|
+
// Auto-approve if moderation is off or user is logged in — unless a check
|
|
212
|
+
// objected, which always wins.
|
|
213
|
+
const initialStatus = verdict.status ?? (!moderateComments || !!req.userId ? 'approved' : 'pending');
|
|
214
|
+
const initialApproved = initialStatus === 'approved';
|
|
215
|
+
// A filter, so a spam check can reject a comment or force it into
|
|
216
|
+
// moderation before it is ever stored.
|
|
217
|
+
const creating = await guardWrite(HOOKS.COMMENT_CREATING, {
|
|
218
|
+
post_id: postId,
|
|
219
|
+
user_id: req.userId,
|
|
220
|
+
parent_id,
|
|
221
|
+
author_name: req.userId ? undefined : author_name,
|
|
222
|
+
author_email: req.userId ? undefined : author_email,
|
|
223
|
+
content,
|
|
224
|
+
approved: initialApproved,
|
|
225
|
+
status: initialStatus,
|
|
226
|
+
held_reason: verdict.reason,
|
|
227
|
+
author_ip: ip || null,
|
|
228
|
+
notify_replies: notifyReplies
|
|
229
|
+
}, { req }, { refused: 'Comment rejected.', showErrors: false });
|
|
230
|
+
// A public write: a listener that throws gets a generic refusal, never
|
|
231
|
+
// its own error message.
|
|
232
|
+
if (!creating.ok)
|
|
233
|
+
return res.json({ error: creating.error }, creating.status);
|
|
234
|
+
const draft = creating.value;
|
|
235
|
+
// Listeners written before `status` existed set `approved`. Whichever of
|
|
236
|
+
// the two a listener changed is the one it meant.
|
|
237
|
+
const finalStatus = isCommentStatus(draft.status) && draft.status !== initialStatus
|
|
238
|
+
? draft.status
|
|
239
|
+
: Boolean(draft.approved) !== initialApproved
|
|
240
|
+
? (draft.approved ? 'approved' : 'pending')
|
|
241
|
+
: initialStatus;
|
|
242
|
+
const comment = await Comment.create({ ...draft, status: finalStatus });
|
|
243
|
+
await hooks.fire(HOOKS.COMMENT_CREATED, { comment, userId: req.userId });
|
|
244
|
+
// After the row exists and the response is decided; never awaited.
|
|
245
|
+
if (finalStatus === 'pending') {
|
|
246
|
+
inBackground('moderation notice', () => notifyAwaitingModeration(comment, post));
|
|
247
|
+
}
|
|
248
|
+
if (finalStatus === 'approved' && parent_id) {
|
|
249
|
+
inBackground('reply notification', () => notifyParentOfReply(Number(comment.id)));
|
|
250
|
+
}
|
|
251
|
+
res.json({
|
|
252
|
+
comment: submitted(comment),
|
|
253
|
+
message: finalStatus === 'approved' ? 'Comment posted.' : 'Your comment is awaiting moderation.'
|
|
254
|
+
}, 201);
|
|
255
|
+
},
|
|
256
|
+
async update(req, res) {
|
|
257
|
+
const comment = await Comment.find(parseInt(req.params.id));
|
|
258
|
+
if (!comment) {
|
|
259
|
+
return res.json({ error: 'Comment not found' }, 404);
|
|
260
|
+
}
|
|
261
|
+
const result = await validate(req.body, {
|
|
262
|
+
content: [rules.required, rules.string, rules.min(3), rules.max(2000)]
|
|
263
|
+
});
|
|
264
|
+
if (result.fails()) {
|
|
265
|
+
return res.json({ errors: result.errors }, 422);
|
|
266
|
+
}
|
|
267
|
+
const { content } = req.body;
|
|
268
|
+
const updated = await Comment.update(parseInt(req.params.id), { content });
|
|
269
|
+
res.json({ comment: updated });
|
|
270
|
+
},
|
|
271
|
+
async approve(req, res) {
|
|
272
|
+
const id = parseInt(req.params.id);
|
|
273
|
+
const comment = await Comment.find(id);
|
|
274
|
+
if (!comment) {
|
|
275
|
+
return res.json({ error: 'Comment not found' }, 404);
|
|
276
|
+
}
|
|
277
|
+
const changed = await Comment.setStatus([id], 'approved');
|
|
278
|
+
await afterApproved(changed, req.userId);
|
|
279
|
+
res.json({ comment: await Comment.find(id) });
|
|
280
|
+
},
|
|
281
|
+
/** Move one comment to a status: approve, unapprove, spam, not spam, trash, restore. */
|
|
282
|
+
async setStatus(req, res) {
|
|
283
|
+
const id = parseInt(req.params.id);
|
|
284
|
+
const status = req.body?.status;
|
|
285
|
+
if (!isCommentStatus(status)) {
|
|
286
|
+
return res.json({ errors: { status: [`Must be one of: ${COMMENT_STATUSES.join(', ')}`] } }, 422);
|
|
287
|
+
}
|
|
288
|
+
if (!(await Comment.find(id))) {
|
|
289
|
+
return res.json({ error: 'Comment not found' }, 404);
|
|
290
|
+
}
|
|
291
|
+
const changed = await Comment.setStatus([id], status);
|
|
292
|
+
if (status === 'approved')
|
|
293
|
+
await afterApproved(changed, req.userId);
|
|
294
|
+
res.json({ comment: await Comment.find(id) });
|
|
295
|
+
},
|
|
296
|
+
/**
|
|
297
|
+
* One action over many comments: `approve`, `pending`, `spam`, `trash` or
|
|
298
|
+
* `delete` (for good). Up to MAX_BULK ids at once.
|
|
299
|
+
*/
|
|
300
|
+
async bulk(req, res) {
|
|
301
|
+
const { ids: rawIds, action } = (req.body ?? {});
|
|
302
|
+
const ids = idsFrom(rawIds);
|
|
303
|
+
if (!ids) {
|
|
304
|
+
return res.json({ errors: { ids: [`Give between 1 and ${MAX_BULK} comment ids`] } }, 422);
|
|
305
|
+
}
|
|
306
|
+
if (action === 'delete') {
|
|
307
|
+
let deleted = 0;
|
|
308
|
+
for (const id of ids) {
|
|
309
|
+
const comment = await Comment.find(id);
|
|
310
|
+
if (!comment)
|
|
311
|
+
continue;
|
|
312
|
+
await Comment.delete(id);
|
|
313
|
+
await hooks.fire(HOOKS.COMMENT_DELETED, { comment, userId: req.userId });
|
|
314
|
+
deleted++;
|
|
315
|
+
}
|
|
316
|
+
return res.json({ affected: deleted });
|
|
317
|
+
}
|
|
318
|
+
const status = action === 'approve' ? 'approved' : isCommentStatus(action) ? action : null;
|
|
319
|
+
if (!status) {
|
|
320
|
+
return res.json({ errors: { action: ['Must be one of: approve, pending, spam, trash, delete'] } }, 422);
|
|
321
|
+
}
|
|
322
|
+
const changed = await Comment.setStatus(ids, status);
|
|
323
|
+
if (status === 'approved')
|
|
324
|
+
await afterApproved(changed, req.userId);
|
|
325
|
+
res.json({ affected: changed.length });
|
|
326
|
+
},
|
|
327
|
+
/** Empty the spam folder or the trash, for good. */
|
|
328
|
+
async empty(req, res) {
|
|
329
|
+
const status = req.body?.status;
|
|
330
|
+
if (status !== 'spam' && status !== 'trash') {
|
|
331
|
+
return res.json({ errors: { status: ['Must be spam or trash'] } }, 422);
|
|
332
|
+
}
|
|
333
|
+
// Not fired per comment: COMMENT_DELETED listeners are for a person's
|
|
334
|
+
// decision about a comment, and a spam folder is thousands of bots.
|
|
335
|
+
const deleted = await Comment.deleteByStatus(status);
|
|
336
|
+
res.json({ affected: deleted });
|
|
337
|
+
},
|
|
338
|
+
/**
|
|
339
|
+
* Delete a comment: to the trash first, then for good.
|
|
340
|
+
*
|
|
341
|
+
* A comment already in the spam or the trash, or a request with
|
|
342
|
+
* `?force=true`, is deleted permanently; anything else is trashed, so one
|
|
343
|
+
* misclick in a moderation queue can be undone.
|
|
344
|
+
*/
|
|
345
|
+
async destroy(req, res) {
|
|
346
|
+
const id = parseInt(req.params.id);
|
|
347
|
+
const comment = await Comment.find(id);
|
|
348
|
+
if (!comment) {
|
|
349
|
+
return res.json({ error: 'Comment not found' }, 404);
|
|
350
|
+
}
|
|
351
|
+
const permanent = req.query?.force === 'true' || comment.status === 'trash' || comment.status === 'spam';
|
|
352
|
+
if (!permanent) {
|
|
353
|
+
await Comment.setStatus([id], 'trash');
|
|
354
|
+
return res.json({ message: 'Comment moved to trash', comment: await Comment.find(id) });
|
|
355
|
+
}
|
|
356
|
+
await Comment.delete(id);
|
|
357
|
+
await hooks.fire(HOOKS.COMMENT_DELETED, { comment, userId: req.userId });
|
|
358
|
+
res.json({ message: 'Comment deleted' });
|
|
359
|
+
},
|
|
360
|
+
/**
|
|
361
|
+
* The comment settings this page owns: the blocklist, the link limit and
|
|
362
|
+
* who hears about comments awaiting moderation.
|
|
363
|
+
*
|
|
364
|
+
* Moderators may read them — the blocklist is what explains why a comment
|
|
365
|
+
* was caught — but changing them is site configuration.
|
|
366
|
+
*/
|
|
367
|
+
async settings(req, res) {
|
|
368
|
+
res.json({
|
|
369
|
+
settings: await commentSettings(),
|
|
370
|
+
can_manage: can(req.user, 'settings.manage')
|
|
371
|
+
});
|
|
372
|
+
},
|
|
373
|
+
async updateSettings(req, res) {
|
|
374
|
+
const body = (req.body ?? {});
|
|
375
|
+
const errors = {};
|
|
376
|
+
if (body.comment_blocklist !== undefined) {
|
|
377
|
+
if (typeof body.comment_blocklist !== 'string' || body.comment_blocklist.length > MAX_BLOCKLIST_LENGTH) {
|
|
378
|
+
errors.comment_blocklist = [`Must be text of at most ${MAX_BLOCKLIST_LENGTH} characters`];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (body.comment_max_links !== undefined) {
|
|
382
|
+
const n = Number(body.comment_max_links);
|
|
383
|
+
if (!Number.isInteger(n) || n < 0 || n > 100)
|
|
384
|
+
errors.comment_max_links = ['Must be a whole number from 0 to 100'];
|
|
385
|
+
}
|
|
386
|
+
if (body.comment_notify !== undefined && !NOTIFY_AUDIENCES.includes(body.comment_notify)) {
|
|
387
|
+
errors.comment_notify = [`Must be one of: ${NOTIFY_AUDIENCES.join(', ')}`];
|
|
388
|
+
}
|
|
389
|
+
if (Object.keys(errors).length)
|
|
390
|
+
return res.json({ errors }, 422);
|
|
391
|
+
if (body.comment_blocklist !== undefined) {
|
|
392
|
+
// Settings.get reads an empty value as absent, which is what an empty
|
|
393
|
+
// blocklist means anyway.
|
|
394
|
+
await Settings.set('comment_blocklist', String(body.comment_blocklist), 'discussion');
|
|
395
|
+
}
|
|
396
|
+
if (body.comment_max_links !== undefined) {
|
|
397
|
+
await Settings.set('comment_max_links', Number(body.comment_max_links), 'discussion');
|
|
398
|
+
}
|
|
399
|
+
if (body.comment_notify !== undefined) {
|
|
400
|
+
await Settings.set('comment_notify', String(body.comment_notify), 'discussion');
|
|
401
|
+
}
|
|
402
|
+
res.json({ settings: await commentSettings() });
|
|
403
|
+
},
|
|
404
|
+
/**
|
|
405
|
+
* The unsubscribe link from a reply notification: a confirmation page.
|
|
406
|
+
*
|
|
407
|
+
* GET only shows a button. Mail scanners and link previewers open every
|
|
408
|
+
* link in a message, and a GET that unsubscribed would turn notifications
|
|
409
|
+
* off before the reader saw them.
|
|
410
|
+
*/
|
|
411
|
+
async unsubscribePage(req, res) {
|
|
412
|
+
const token = String(req.query?.token ?? '');
|
|
413
|
+
if (!readUnsubscribeToken(token)) {
|
|
414
|
+
return page(res, 400, 'This link is not valid', '<p>It may have been copied incompletely. Nothing has changed.</p>');
|
|
415
|
+
}
|
|
416
|
+
return page(res, 200, 'Stop reply emails?', `<p>You will no longer be emailed when someone replies to this comment.</p>
|
|
417
|
+
<form method="post" action="/api/comments/unsubscribe?token=${encodeURIComponent(token)}">
|
|
418
|
+
<button type="submit" style="background: #111; color: #fff; border: 0; padding: 10px 20px; border-radius: 6px; font-size: 15px; cursor: pointer;">Stop emails</button>
|
|
419
|
+
</form>`);
|
|
420
|
+
},
|
|
421
|
+
/**
|
|
422
|
+
* Turn reply emails off for one comment.
|
|
423
|
+
*
|
|
424
|
+
* Also the RFC 8058 one-click target, which a mail client POSTs to with
|
|
425
|
+
* `List-Unsubscribe=One-Click` and reads only the status of. Safe without
|
|
426
|
+
* a session or CSRF token: the signed link is the authority, and the only
|
|
427
|
+
* thing it can do is stop mail.
|
|
428
|
+
*/
|
|
429
|
+
async unsubscribe(req, res) {
|
|
430
|
+
const id = readUnsubscribeToken(req.query?.token ?? req.body?.token);
|
|
431
|
+
if (!id) {
|
|
432
|
+
return page(res, 400, 'This link is not valid', '<p>It may have been copied incompletely. Nothing has changed.</p>');
|
|
433
|
+
}
|
|
434
|
+
// A deleted comment has nothing left to notify about; the answer is the same.
|
|
435
|
+
await Comment.unsubscribe(id);
|
|
436
|
+
return page(res, 200, 'Done', '<p>You will no longer be emailed about replies to this comment.</p>');
|
|
437
|
+
}
|
|
438
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Content types: the admin's CRUD, and the public list at `/api/v1/types`.
|
|
4
|
+
*
|
|
5
|
+
* Writing a type needs `settings.manage`. A type decides URLs across the whole
|
|
6
|
+
* site and what every editor sees, which is the weight of a site setting, not
|
|
7
|
+
* of an editorial choice. Reading needs only a session or a content token —
|
|
8
|
+
* the editor has to know a type's fields to show them.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ContentTypeController: {
|
|
11
|
+
index(_req: Request, res: Response): Promise<void>;
|
|
12
|
+
show(req: Request, res: Response): Promise<void>;
|
|
13
|
+
store(req: Request, res: Response): Promise<void>;
|
|
14
|
+
update(req: Request, res: Response): Promise<void>;
|
|
15
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* `GET /api/v1/types` — every public content type, with its field schema.
|
|
18
|
+
*
|
|
19
|
+
* What a front end needs to route and render custom types: where each lives
|
|
20
|
+
* (`route_base`), what to call it, and which custom fields to expect in a
|
|
21
|
+
* post's `fields`. Private types are left out with their entries.
|
|
22
|
+
*/
|
|
23
|
+
publicIndex(_req: Request, res: Response): Promise<void>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ContentType, validateContentType } from "../models/ContentType.js";
|
|
2
|
+
/**
|
|
3
|
+
* Content types: the admin's CRUD, and the public list at `/api/v1/types`.
|
|
4
|
+
*
|
|
5
|
+
* Writing a type needs `settings.manage`. A type decides URLs across the whole
|
|
6
|
+
* site and what every editor sees, which is the weight of a site setting, not
|
|
7
|
+
* of an editorial choice. Reading needs only a session or a content token —
|
|
8
|
+
* the editor has to know a type's fields to show them.
|
|
9
|
+
*/
|
|
10
|
+
export const ContentTypeController = {
|
|
11
|
+
async index(_req, res) {
|
|
12
|
+
res.json({ content_types: await ContentType.all() });
|
|
13
|
+
},
|
|
14
|
+
async show(req, res) {
|
|
15
|
+
const type = await findParam(req);
|
|
16
|
+
if (!type)
|
|
17
|
+
return res.json({ error: 'Content type not found' }, 404);
|
|
18
|
+
res.json({ content_type: { ...type, post_count: await ContentType.postCount(type.key) } });
|
|
19
|
+
},
|
|
20
|
+
async store(req, res) {
|
|
21
|
+
const checked = validateContentType(req.body, null);
|
|
22
|
+
if ('errors' in checked)
|
|
23
|
+
return res.json({ errors: checked.errors }, 422);
|
|
24
|
+
const clash = await ContentType.clashes(checked.values);
|
|
25
|
+
if (Object.keys(clash).length)
|
|
26
|
+
return res.json({ errors: clash }, 422);
|
|
27
|
+
const type = await ContentType.create(checked.values);
|
|
28
|
+
res.json({ content_type: type }, 201);
|
|
29
|
+
},
|
|
30
|
+
async update(req, res) {
|
|
31
|
+
const existing = await findParam(req);
|
|
32
|
+
if (!existing)
|
|
33
|
+
return res.json({ error: 'Content type not found' }, 404);
|
|
34
|
+
const checked = validateContentType(req.body, existing);
|
|
35
|
+
if ('errors' in checked)
|
|
36
|
+
return res.json({ errors: checked.errors }, 422);
|
|
37
|
+
const clash = await ContentType.clashes(checked.values, existing.id);
|
|
38
|
+
if (Object.keys(clash).length)
|
|
39
|
+
return res.json({ errors: clash }, 422);
|
|
40
|
+
// A route base change moves every entry of the type. Redirects for that
|
|
41
|
+
// are not written automatically (it could be thousands of rows); the
|
|
42
|
+
// response says so, and the admin screen warns before saving.
|
|
43
|
+
const moved = existing.route_base !== checked.values.route_base;
|
|
44
|
+
const type = await ContentType.update(existing.id, checked.values);
|
|
45
|
+
res.json({ content_type: type, ...(moved ? { notice: `Entries now live under ${type.route_base}. Add a redirect from ${existing.route_base}/* if links to the old address exist.` } : {}) });
|
|
46
|
+
},
|
|
47
|
+
async destroy(req, res) {
|
|
48
|
+
const existing = await findParam(req);
|
|
49
|
+
if (!existing)
|
|
50
|
+
return res.json({ error: 'Content type not found' }, 404);
|
|
51
|
+
if (existing.builtin) {
|
|
52
|
+
return res.json({ error: 'The built-in post type cannot be deleted.' }, 422);
|
|
53
|
+
}
|
|
54
|
+
// Deleting a type with entries would leave posts nothing can render or
|
|
55
|
+
// edit as what they are. Moving or deleting them first is a decision the
|
|
56
|
+
// admin should make knowingly, one post at a time if need be.
|
|
57
|
+
const count = await ContentType.postCount(existing.key);
|
|
58
|
+
if (count > 0) {
|
|
59
|
+
return res.json({ error: `${count} ${count === 1 ? 'entry uses' : 'entries use'} this type. Move or delete them first.` }, 409);
|
|
60
|
+
}
|
|
61
|
+
await ContentType.delete(existing.id);
|
|
62
|
+
res.json({ message: 'Content type deleted' });
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* `GET /api/v1/types` — every public content type, with its field schema.
|
|
66
|
+
*
|
|
67
|
+
* What a front end needs to route and render custom types: where each lives
|
|
68
|
+
* (`route_base`), what to call it, and which custom fields to expect in a
|
|
69
|
+
* post's `fields`. Private types are left out with their entries.
|
|
70
|
+
*/
|
|
71
|
+
async publicIndex(_req, res) {
|
|
72
|
+
const types = await ContentType.all({ publicOnly: true });
|
|
73
|
+
res.json({ data: types.map(presentType) });
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function presentType(type) {
|
|
77
|
+
return {
|
|
78
|
+
key: type.key,
|
|
79
|
+
singular_label: type.singular_label,
|
|
80
|
+
plural_label: type.plural_label,
|
|
81
|
+
description: type.description,
|
|
82
|
+
route_base: type.route_base,
|
|
83
|
+
hierarchical: type.hierarchical,
|
|
84
|
+
supports: type.supports,
|
|
85
|
+
fields: type.supports.custom_fields ? type.fields : []
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function findParam(req) {
|
|
89
|
+
const id = Number(req.params.id);
|
|
90
|
+
return Number.isInteger(id) ? ContentType.find(id) : ContentType.findByKey(String(req.params.id));
|
|
91
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Issue a token and email the link.
|
|
4
|
+
*
|
|
5
|
+
* Exported because registration sends the first one.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sendVerificationEmail(user: {
|
|
8
|
+
id: number;
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
}): Promise<string>;
|
|
12
|
+
export declare const EmailVerificationController: {
|
|
13
|
+
/**
|
|
14
|
+
* Redeem a token from the emailed link.
|
|
15
|
+
*
|
|
16
|
+
* This is a link target rather than an API call, so it redirects into the app
|
|
17
|
+
* with the outcome instead of returning JSON.
|
|
18
|
+
*/
|
|
19
|
+
verify(req: Request, res: Response): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Send another verification email.
|
|
22
|
+
*/
|
|
23
|
+
resend(req: Request, res: Response): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the signed-in user still needs to verify.
|
|
26
|
+
*/
|
|
27
|
+
status(req: Request, res: Response): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Invalidate outstanding links when the address changes, so a link sent to the
|
|
31
|
+
* old address cannot verify the new one.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resetVerification(userId: number): Promise<void>;
|