@basicbenframework/cms 0.0.0-stage → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +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,20 @@
|
|
|
1
|
+
interface ApiOptions extends RequestInit {
|
|
2
|
+
headers?: Record<string, string>;
|
|
3
|
+
}
|
|
4
|
+
interface Api {
|
|
5
|
+
<T = unknown>(path: string, options?: ApiOptions): Promise<T>;
|
|
6
|
+
get<T = unknown>(path: string, options?: ApiOptions): Promise<T>;
|
|
7
|
+
post<T = unknown>(path: string, body?: unknown, options?: ApiOptions): Promise<T>;
|
|
8
|
+
put<T = unknown>(path: string, body?: unknown, options?: ApiOptions): Promise<T>;
|
|
9
|
+
patch<T = unknown>(path: string, body?: unknown, options?: ApiOptions): Promise<T>;
|
|
10
|
+
delete<T = unknown>(path: string, options?: ApiOptions): Promise<T>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The verb helpers every admin page calls.
|
|
14
|
+
*
|
|
15
|
+
* These were being used throughout the admin without existing, so every page
|
|
16
|
+
* that loaded one threw `api.get is not a function` before it rendered. The
|
|
17
|
+
* type checker had been reporting it as 48 separate errors.
|
|
18
|
+
*/
|
|
19
|
+
export declare const api: Api;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const request = async (path, options = {}) => {
|
|
2
|
+
const token = localStorage.getItem('token');
|
|
3
|
+
let res;
|
|
4
|
+
try {
|
|
5
|
+
res = await fetch(path, {
|
|
6
|
+
...options,
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
10
|
+
...options.headers
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new Error('Unable to connect to server');
|
|
16
|
+
}
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
data = await res.json();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error(res.ok ? 'Invalid response from server' : `Server error (${res.status})`);
|
|
23
|
+
}
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
const errorValues = data.errors ? Object.values(data.errors) : [];
|
|
26
|
+
const firstError = errorValues[0]?.[0];
|
|
27
|
+
throw new Error(data.error || firstError || 'Request failed');
|
|
28
|
+
}
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The verb helpers every admin page calls.
|
|
33
|
+
*
|
|
34
|
+
* These were being used throughout the admin without existing, so every page
|
|
35
|
+
* that loaded one threw `api.get is not a function` before it rendered. The
|
|
36
|
+
* type checker had been reporting it as 48 separate errors.
|
|
37
|
+
*/
|
|
38
|
+
export const api = Object.assign(request, {
|
|
39
|
+
get: (path, options = {}) => request(path, { ...options, method: 'GET' }),
|
|
40
|
+
post: (path, body, options = {}) => request(path, { ...options, method: 'POST', body: body === undefined ? undefined : JSON.stringify(body) }),
|
|
41
|
+
put: (path, body, options = {}) => request(path, { ...options, method: 'PUT', body: body === undefined ? undefined : JSON.stringify(body) }),
|
|
42
|
+
patch: (path, body, options = {}) => request(path, { ...options, method: 'PATCH', body: body === undefined ? undefined : JSON.stringify(body) }),
|
|
43
|
+
delete: (path, options = {}) => request(path, { ...options, method: 'DELETE' })
|
|
44
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeping spam out of the comments without a third-party service.
|
|
3
|
+
*
|
|
4
|
+
* Comments are the one write any visitor can make without an account, so they
|
|
5
|
+
* are what every bot on the internet aims at. A hosted spam filter would mean
|
|
6
|
+
* a dependency and sending every reader's words to someone else; these are
|
|
7
|
+
* the cheap checks that catch the bulk of it, in order of how sure they are:
|
|
8
|
+
*
|
|
9
|
+
* - **A honeypot.** A field a person never sees and a form-filling bot cannot
|
|
10
|
+
* resist. Filled in means a machine, and the comment goes to spam.
|
|
11
|
+
* - **A signed timestamp.** The form is handed a token saying when it was
|
|
12
|
+
* loaded. A submission back within a few seconds was not typed by anyone.
|
|
13
|
+
* The token is an HMAC, so there is no state to keep and nothing for a bot
|
|
14
|
+
* to forge without APP_KEY.
|
|
15
|
+
* - **A blocklist** the site owner maintains: words, addresses, domains and
|
|
16
|
+
* IP ranges. A match goes to spam.
|
|
17
|
+
* - **Too many links**, which is what most spam is for. That one is only held
|
|
18
|
+
* for a person to look at, since plenty of real comments cite sources.
|
|
19
|
+
*
|
|
20
|
+
* Everything here is pure — no database, no request — so it can be tested
|
|
21
|
+
* directly and the controller decides what to do with the verdict.
|
|
22
|
+
*/
|
|
23
|
+
import { BlockList } from 'node:net';
|
|
24
|
+
/**
|
|
25
|
+
* How deep replies may nest: a comment, a reply to it, and a reply to that.
|
|
26
|
+
*
|
|
27
|
+
* Three, not WordPress's five. Every level indents, and on a phone-width
|
|
28
|
+
* column the fourth level leaves a sliver of text; past three a thread is
|
|
29
|
+
* almost always two people going back and forth, which reads better flat
|
|
30
|
+
* anyway. It also bounds the walk up the parent chain to a couple of queries.
|
|
31
|
+
*/
|
|
32
|
+
export declare const MAX_DEPTH = 3;
|
|
33
|
+
/**
|
|
34
|
+
* The fastest a person can plausibly read a post and write a comment.
|
|
35
|
+
*
|
|
36
|
+
* Deliberately low: a reader who wrote their reply in a text editor and
|
|
37
|
+
* pasted it is still a reader. Bots submit in milliseconds.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MIN_SUBMIT_MS = 3000;
|
|
40
|
+
/**
|
|
41
|
+
* How long a form token stays fresh.
|
|
42
|
+
*
|
|
43
|
+
* A day covers a tab left open overnight. An older token is not evidence of a
|
|
44
|
+
* bot — only of an old tab — so it holds the comment for moderation rather
|
|
45
|
+
* than marking it spam.
|
|
46
|
+
*/
|
|
47
|
+
export declare const FORM_TOKEN_TTL_MS: number;
|
|
48
|
+
/** The honeypot's field name. Named like a field bots expect to fill. */
|
|
49
|
+
export declare const HONEYPOT_FIELD = "website";
|
|
50
|
+
/** Links allowed before a comment is held, when the setting is absent. */
|
|
51
|
+
export declare const DEFAULT_MAX_LINKS = 2;
|
|
52
|
+
export type CommentStatus = 'pending' | 'approved' | 'spam' | 'trash';
|
|
53
|
+
export declare const COMMENT_STATUSES: CommentStatus[];
|
|
54
|
+
export declare function isCommentStatus(value: unknown): value is CommentStatus;
|
|
55
|
+
/**
|
|
56
|
+
* A token saying this form, for this post, was loaded now.
|
|
57
|
+
*
|
|
58
|
+
* Milliseconds in the payload rather than the JWT's own `iat`, which counts
|
|
59
|
+
* whole seconds — too coarse for a three-second threshold.
|
|
60
|
+
*/
|
|
61
|
+
export declare function issueFormToken(postId: number, now?: number): string;
|
|
62
|
+
export type FormTokenVerdict = 'ok' | 'missing' | 'invalid' | 'too_fast' | 'expired';
|
|
63
|
+
/**
|
|
64
|
+
* What a submitted form token says about the submission.
|
|
65
|
+
*
|
|
66
|
+
* `missing` is its own answer, not `invalid`: comment forms written before
|
|
67
|
+
* this existed — a headless front end, an old cached page — send none, and
|
|
68
|
+
* they are owed moderation, not a spam verdict.
|
|
69
|
+
*/
|
|
70
|
+
export declare function checkFormToken(token: unknown, postId: number, now?: number): FormTokenVerdict;
|
|
71
|
+
/**
|
|
72
|
+
* A link that stops reply notifications for one comment.
|
|
73
|
+
*
|
|
74
|
+
* No expiry: an unsubscribe link must keep working in a mail opened a year
|
|
75
|
+
* later. It can only ever turn notifications off, so a leaked one costs the
|
|
76
|
+
* owner some emails they may not have wanted anyway.
|
|
77
|
+
*/
|
|
78
|
+
export declare function issueUnsubscribeToken(commentId: number): string;
|
|
79
|
+
/** The comment an unsubscribe token names, or null if it is not one of ours. */
|
|
80
|
+
export declare function readUnsubscribeToken(token: unknown): number | null;
|
|
81
|
+
export interface Blocklist {
|
|
82
|
+
words: string[];
|
|
83
|
+
emails: Set<string>;
|
|
84
|
+
domains: string[];
|
|
85
|
+
addresses: BlockList;
|
|
86
|
+
/** How many address entries were added, so an empty list can skip the check. */
|
|
87
|
+
addressCount: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Read the blocklist setting: one entry per line.
|
|
91
|
+
*
|
|
92
|
+
* Each line is taken as what it looks like —
|
|
93
|
+
*
|
|
94
|
+
* - `203.0.113.7`, `198.51.100.0/24`, `2001:db8::/32` — an address or a range
|
|
95
|
+
* - `spammer@example.com` — one address; `@example.com` — the whole domain
|
|
96
|
+
* - anything else — a word or phrase, matched case-insensitively anywhere in
|
|
97
|
+
* the comment, the name or the email
|
|
98
|
+
*
|
|
99
|
+
* Lines starting with `#` are notes. A malformed range is skipped rather than
|
|
100
|
+
* thrown: one typo must not stop every comment on the site.
|
|
101
|
+
*
|
|
102
|
+
* IPv6 entries are widened to their /64. The rate limiter keys a client on its
|
|
103
|
+
* /64 (one subscriber is routinely handed the whole range) and that is the
|
|
104
|
+
* address the controller has to check, so a narrower entry could never match.
|
|
105
|
+
*/
|
|
106
|
+
export declare function parseBlocklist(text: string | null | undefined): Blocklist;
|
|
107
|
+
export interface Submission {
|
|
108
|
+
content: string;
|
|
109
|
+
name?: string | null;
|
|
110
|
+
email?: string | null;
|
|
111
|
+
ip?: string | null;
|
|
112
|
+
}
|
|
113
|
+
/** Why a submission matches the blocklist, or null. */
|
|
114
|
+
export declare function matchBlocklist(list: Blocklist, submission: Submission): string | null;
|
|
115
|
+
/**
|
|
116
|
+
* How many links a comment carries.
|
|
117
|
+
*
|
|
118
|
+
* Counts what a reader's mail client or the rendered page would turn into a
|
|
119
|
+
* link — schemes and bare `www.` hosts — not every dot. Generous by design:
|
|
120
|
+
* this only ever holds a comment for a person, it never discards one.
|
|
121
|
+
*/
|
|
122
|
+
export declare function countLinks(content: string): number;
|
|
123
|
+
export interface Verdict {
|
|
124
|
+
/** Where the comment goes. `null` means no check objected. */
|
|
125
|
+
status: 'spam' | 'pending' | null;
|
|
126
|
+
reason: string | null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Run every check and return the strictest outcome.
|
|
130
|
+
*
|
|
131
|
+
* `trusted` skips the bot checks for a signed-in commenter: an account is
|
|
132
|
+
* already a stronger signal than a hidden field, and a front end that signs
|
|
133
|
+
* people in may not render the form these tokens come from. The blocklist and
|
|
134
|
+
* the link count apply to everyone but moderators, whom the caller exempts.
|
|
135
|
+
*/
|
|
136
|
+
export declare function assess(input: {
|
|
137
|
+
submission: Submission;
|
|
138
|
+
honeypot: unknown;
|
|
139
|
+
formToken: unknown;
|
|
140
|
+
postId: number;
|
|
141
|
+
blocklist: Blocklist;
|
|
142
|
+
maxLinks: number;
|
|
143
|
+
trusted: boolean;
|
|
144
|
+
now?: number;
|
|
145
|
+
}): Verdict;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeping spam out of the comments without a third-party service.
|
|
3
|
+
*
|
|
4
|
+
* Comments are the one write any visitor can make without an account, so they
|
|
5
|
+
* are what every bot on the internet aims at. A hosted spam filter would mean
|
|
6
|
+
* a dependency and sending every reader's words to someone else; these are
|
|
7
|
+
* the cheap checks that catch the bulk of it, in order of how sure they are:
|
|
8
|
+
*
|
|
9
|
+
* - **A honeypot.** A field a person never sees and a form-filling bot cannot
|
|
10
|
+
* resist. Filled in means a machine, and the comment goes to spam.
|
|
11
|
+
* - **A signed timestamp.** The form is handed a token saying when it was
|
|
12
|
+
* loaded. A submission back within a few seconds was not typed by anyone.
|
|
13
|
+
* The token is an HMAC, so there is no state to keep and nothing for a bot
|
|
14
|
+
* to forge without APP_KEY.
|
|
15
|
+
* - **A blocklist** the site owner maintains: words, addresses, domains and
|
|
16
|
+
* IP ranges. A match goes to spam.
|
|
17
|
+
* - **Too many links**, which is what most spam is for. That one is only held
|
|
18
|
+
* for a person to look at, since plenty of real comments cite sources.
|
|
19
|
+
*
|
|
20
|
+
* Everything here is pure — no database, no request — so it can be tested
|
|
21
|
+
* directly and the controller decides what to do with the verdict.
|
|
22
|
+
*/
|
|
23
|
+
import { createHmac } from 'node:crypto';
|
|
24
|
+
import { BlockList, isIP } from 'node:net';
|
|
25
|
+
import { signJwt, verifyJwt } from '@basicbenframework/core/auth';
|
|
26
|
+
import { appKey } from '@basicbenframework/core/server';
|
|
27
|
+
/**
|
|
28
|
+
* How deep replies may nest: a comment, a reply to it, and a reply to that.
|
|
29
|
+
*
|
|
30
|
+
* Three, not WordPress's five. Every level indents, and on a phone-width
|
|
31
|
+
* column the fourth level leaves a sliver of text; past three a thread is
|
|
32
|
+
* almost always two people going back and forth, which reads better flat
|
|
33
|
+
* anyway. It also bounds the walk up the parent chain to a couple of queries.
|
|
34
|
+
*/
|
|
35
|
+
export const MAX_DEPTH = 3;
|
|
36
|
+
/**
|
|
37
|
+
* The fastest a person can plausibly read a post and write a comment.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately low: a reader who wrote their reply in a text editor and
|
|
40
|
+
* pasted it is still a reader. Bots submit in milliseconds.
|
|
41
|
+
*/
|
|
42
|
+
export const MIN_SUBMIT_MS = 3_000;
|
|
43
|
+
/**
|
|
44
|
+
* How long a form token stays fresh.
|
|
45
|
+
*
|
|
46
|
+
* A day covers a tab left open overnight. An older token is not evidence of a
|
|
47
|
+
* bot — only of an old tab — so it holds the comment for moderation rather
|
|
48
|
+
* than marking it spam.
|
|
49
|
+
*/
|
|
50
|
+
export const FORM_TOKEN_TTL_MS = 24 * 60 * 60 * 1000;
|
|
51
|
+
/** The honeypot's field name. Named like a field bots expect to fill. */
|
|
52
|
+
export const HONEYPOT_FIELD = 'website';
|
|
53
|
+
/** Links allowed before a comment is held, when the setting is absent. */
|
|
54
|
+
export const DEFAULT_MAX_LINKS = 2;
|
|
55
|
+
export const COMMENT_STATUSES = ['pending', 'approved', 'spam', 'trash'];
|
|
56
|
+
export function isCommentStatus(value) {
|
|
57
|
+
return typeof value === 'string' && COMMENT_STATUSES.includes(value);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A signing key for one purpose, derived from APP_KEY.
|
|
61
|
+
*
|
|
62
|
+
* Never APP_KEY itself: that key signs sessions, and a token minted for a
|
|
63
|
+
* comment form must not be anything else. Deriving per purpose also means a
|
|
64
|
+
* form token cannot be replayed as an unsubscribe token or the reverse.
|
|
65
|
+
*/
|
|
66
|
+
function keyFor(purpose) {
|
|
67
|
+
return createHmac('sha256', appKey('comment tokens'))
|
|
68
|
+
.update(`basicben.comments.${purpose}`)
|
|
69
|
+
.digest('hex');
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A token saying this form, for this post, was loaded now.
|
|
73
|
+
*
|
|
74
|
+
* Milliseconds in the payload rather than the JWT's own `iat`, which counts
|
|
75
|
+
* whole seconds — too coarse for a three-second threshold.
|
|
76
|
+
*/
|
|
77
|
+
export function issueFormToken(postId, now = Date.now()) {
|
|
78
|
+
return signJwt({ p: Number(postId), t: now }, keyFor('form'));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* What a submitted form token says about the submission.
|
|
82
|
+
*
|
|
83
|
+
* `missing` is its own answer, not `invalid`: comment forms written before
|
|
84
|
+
* this existed — a headless front end, an old cached page — send none, and
|
|
85
|
+
* they are owed moderation, not a spam verdict.
|
|
86
|
+
*/
|
|
87
|
+
export function checkFormToken(token, postId, now = Date.now()) {
|
|
88
|
+
if (token === undefined || token === null || token === '')
|
|
89
|
+
return 'missing';
|
|
90
|
+
if (typeof token !== 'string')
|
|
91
|
+
return 'invalid';
|
|
92
|
+
const payload = verifyJwt(token, keyFor('form'));
|
|
93
|
+
if (!payload)
|
|
94
|
+
return 'invalid';
|
|
95
|
+
// A token for another post is a token harvested once and replayed.
|
|
96
|
+
if (Number(payload.p) !== Number(postId))
|
|
97
|
+
return 'invalid';
|
|
98
|
+
const issued = Number(payload.t);
|
|
99
|
+
if (!Number.isFinite(issued) || issued > now + 60_000)
|
|
100
|
+
return 'invalid';
|
|
101
|
+
if (now - issued < MIN_SUBMIT_MS)
|
|
102
|
+
return 'too_fast';
|
|
103
|
+
if (now - issued > FORM_TOKEN_TTL_MS)
|
|
104
|
+
return 'expired';
|
|
105
|
+
return 'ok';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A link that stops reply notifications for one comment.
|
|
109
|
+
*
|
|
110
|
+
* No expiry: an unsubscribe link must keep working in a mail opened a year
|
|
111
|
+
* later. It can only ever turn notifications off, so a leaked one costs the
|
|
112
|
+
* owner some emails they may not have wanted anyway.
|
|
113
|
+
*/
|
|
114
|
+
export function issueUnsubscribeToken(commentId) {
|
|
115
|
+
return signJwt({ c: Number(commentId) }, keyFor('unsubscribe'));
|
|
116
|
+
}
|
|
117
|
+
/** The comment an unsubscribe token names, or null if it is not one of ours. */
|
|
118
|
+
export function readUnsubscribeToken(token) {
|
|
119
|
+
if (typeof token !== 'string' || !token)
|
|
120
|
+
return null;
|
|
121
|
+
const payload = verifyJwt(token, keyFor('unsubscribe'));
|
|
122
|
+
const id = Number(payload?.c);
|
|
123
|
+
return Number.isInteger(id) && id > 0 ? id : null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Read the blocklist setting: one entry per line.
|
|
127
|
+
*
|
|
128
|
+
* Each line is taken as what it looks like —
|
|
129
|
+
*
|
|
130
|
+
* - `203.0.113.7`, `198.51.100.0/24`, `2001:db8::/32` — an address or a range
|
|
131
|
+
* - `spammer@example.com` — one address; `@example.com` — the whole domain
|
|
132
|
+
* - anything else — a word or phrase, matched case-insensitively anywhere in
|
|
133
|
+
* the comment, the name or the email
|
|
134
|
+
*
|
|
135
|
+
* Lines starting with `#` are notes. A malformed range is skipped rather than
|
|
136
|
+
* thrown: one typo must not stop every comment on the site.
|
|
137
|
+
*
|
|
138
|
+
* IPv6 entries are widened to their /64. The rate limiter keys a client on its
|
|
139
|
+
* /64 (one subscriber is routinely handed the whole range) and that is the
|
|
140
|
+
* address the controller has to check, so a narrower entry could never match.
|
|
141
|
+
*/
|
|
142
|
+
export function parseBlocklist(text) {
|
|
143
|
+
const list = { words: [], emails: new Set(), domains: [], addresses: new BlockList(), addressCount: 0 };
|
|
144
|
+
for (const raw of String(text ?? '').split('\n')) {
|
|
145
|
+
const line = raw.trim();
|
|
146
|
+
if (!line || line.startsWith('#'))
|
|
147
|
+
continue;
|
|
148
|
+
const [base, prefixText] = line.split('/');
|
|
149
|
+
const family = isIP(base);
|
|
150
|
+
if (family) {
|
|
151
|
+
const type = family === 4 ? 'ipv4' : 'ipv6';
|
|
152
|
+
const max = family === 4 ? 32 : 64;
|
|
153
|
+
const prefix = prefixText === undefined ? max : Number(prefixText);
|
|
154
|
+
if (!Number.isInteger(prefix) || prefix < 0 || prefix > (family === 4 ? 32 : 128))
|
|
155
|
+
continue;
|
|
156
|
+
try {
|
|
157
|
+
list.addresses.addSubnet(base, Math.min(prefix, max), type);
|
|
158
|
+
list.addressCount++;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Skipped, as above.
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const lower = line.toLowerCase();
|
|
166
|
+
if (lower.startsWith('@'))
|
|
167
|
+
list.domains.push(lower);
|
|
168
|
+
else if (/^[^\s@]+@[^\s@]+$/.test(lower))
|
|
169
|
+
list.emails.add(lower);
|
|
170
|
+
else
|
|
171
|
+
list.words.push(lower);
|
|
172
|
+
}
|
|
173
|
+
return list;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Whether a client key — the rate limiter's normalised address — is listed.
|
|
177
|
+
*
|
|
178
|
+
* The key is an IPv4 address or an IPv6 `/64` written `a:b:c:d::/64`; the
|
|
179
|
+
* network address stands for the range.
|
|
180
|
+
*/
|
|
181
|
+
function addressListed(list, key) {
|
|
182
|
+
if (!key || list.addressCount === 0)
|
|
183
|
+
return false;
|
|
184
|
+
if (isIP(key) === 4)
|
|
185
|
+
return list.addresses.check(key, 'ipv4');
|
|
186
|
+
if (key.endsWith('::/64')) {
|
|
187
|
+
const network = key.slice(0, -3);
|
|
188
|
+
return isIP(network) === 6 && list.addresses.check(network, 'ipv6');
|
|
189
|
+
}
|
|
190
|
+
if (isIP(key) === 6)
|
|
191
|
+
return list.addresses.check(key, 'ipv6');
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
/** Why a submission matches the blocklist, or null. */
|
|
195
|
+
export function matchBlocklist(list, submission) {
|
|
196
|
+
const email = String(submission.email ?? '').trim().toLowerCase();
|
|
197
|
+
if (email && list.emails.has(email))
|
|
198
|
+
return 'blocklist: email';
|
|
199
|
+
if (email && list.domains.some(domain => email.endsWith(domain)))
|
|
200
|
+
return 'blocklist: email domain';
|
|
201
|
+
if (addressListed(list, submission.ip))
|
|
202
|
+
return 'blocklist: address';
|
|
203
|
+
if (list.words.length) {
|
|
204
|
+
const haystack = `${submission.content}\n${submission.name ?? ''}\n${email}`.toLowerCase();
|
|
205
|
+
if (list.words.some(word => haystack.includes(word)))
|
|
206
|
+
return 'blocklist: word';
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* How many links a comment carries.
|
|
212
|
+
*
|
|
213
|
+
* Counts what a reader's mail client or the rendered page would turn into a
|
|
214
|
+
* link — schemes and bare `www.` hosts — not every dot. Generous by design:
|
|
215
|
+
* this only ever holds a comment for a person, it never discards one.
|
|
216
|
+
*/
|
|
217
|
+
export function countLinks(content) {
|
|
218
|
+
return (String(content).match(/\bhttps?:\/\/|\bwww\.[a-z0-9-]/gi) ?? []).length;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Run every check and return the strictest outcome.
|
|
222
|
+
*
|
|
223
|
+
* `trusted` skips the bot checks for a signed-in commenter: an account is
|
|
224
|
+
* already a stronger signal than a hidden field, and a front end that signs
|
|
225
|
+
* people in may not render the form these tokens come from. The blocklist and
|
|
226
|
+
* the link count apply to everyone but moderators, whom the caller exempts.
|
|
227
|
+
*/
|
|
228
|
+
export function assess(input) {
|
|
229
|
+
if (!input.trusted) {
|
|
230
|
+
if (input.honeypot !== undefined && input.honeypot !== null && String(input.honeypot).trim() !== '') {
|
|
231
|
+
return { status: 'spam', reason: 'honeypot' };
|
|
232
|
+
}
|
|
233
|
+
const token = checkFormToken(input.formToken, input.postId, input.now);
|
|
234
|
+
if (token === 'invalid')
|
|
235
|
+
return { status: 'spam', reason: 'form token: invalid' };
|
|
236
|
+
if (token === 'too_fast')
|
|
237
|
+
return { status: 'spam', reason: 'form token: submitted too fast' };
|
|
238
|
+
}
|
|
239
|
+
const listed = matchBlocklist(input.blocklist, input.submission);
|
|
240
|
+
if (listed)
|
|
241
|
+
return { status: 'spam', reason: listed };
|
|
242
|
+
if (!input.trusted) {
|
|
243
|
+
const token = checkFormToken(input.formToken, input.postId, input.now);
|
|
244
|
+
if (token === 'missing')
|
|
245
|
+
return { status: 'pending', reason: 'form token: missing' };
|
|
246
|
+
if (token === 'expired')
|
|
247
|
+
return { status: 'pending', reason: 'form token: expired' };
|
|
248
|
+
}
|
|
249
|
+
const links = countLinks(input.submission.content);
|
|
250
|
+
if (links > input.maxLinks)
|
|
251
|
+
return { status: 'pending', reason: `links: ${links}` };
|
|
252
|
+
return { status: null, reason: null };
|
|
253
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two emails comments send.
|
|
3
|
+
*
|
|
4
|
+
* - To the people who look after a post, when a comment on it is waiting for
|
|
5
|
+
* moderation. Who that is — the post's author, everyone who can moderate,
|
|
6
|
+
* both, or nobody — is the `comment_notify` setting.
|
|
7
|
+
* - To a commenter, when someone's reply to them is approved, and only if
|
|
8
|
+
* they ticked the box asking for it. Each of those mails carries a signed
|
|
9
|
+
* link that turns it off without an account.
|
|
10
|
+
*
|
|
11
|
+
* Neither may cost the commenter anything. Both run after the response is
|
|
12
|
+
* decided, are never awaited by the request, and log rather than throw: a
|
|
13
|
+
* mail provider being down is not a reason for a comment to fail, and a slow
|
|
14
|
+
* one is not a reason for the form to hang.
|
|
15
|
+
*
|
|
16
|
+
* The cost of not awaiting is the one PasswordResetController describes — on
|
|
17
|
+
* a serverless deploy the function can be frozen once the response is
|
|
18
|
+
* written, and a mail still in flight may never leave. For a reset link that
|
|
19
|
+
* would be the whole feature; for a courtesy notification it is an acceptable
|
|
20
|
+
* loss, and the moderation queue is still there whether or not the mail was.
|
|
21
|
+
*/
|
|
22
|
+
import type { Comment as CommentType } from '../types/index.ts';
|
|
23
|
+
export type NotifyAudience = 'author' | 'moderators' | 'both' | 'none';
|
|
24
|
+
export declare const NOTIFY_AUDIENCES: NotifyAudience[];
|
|
25
|
+
/** Who hears about comments awaiting moderation. The author, unless told otherwise. */
|
|
26
|
+
export declare function notifyAudience(): Promise<NotifyAudience>;
|
|
27
|
+
/**
|
|
28
|
+
* Run a mail job without the request waiting for it.
|
|
29
|
+
*
|
|
30
|
+
* The catch is the point: an unhandled rejection here would take the process
|
|
31
|
+
* down on Node's default settings, over an email.
|
|
32
|
+
*/
|
|
33
|
+
export declare function inBackground(label: string, job: () => Promise<unknown>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Tell the post's people that a comment is waiting for them.
|
|
36
|
+
*
|
|
37
|
+
* Only for `pending`: an approved comment needs nothing from anyone, and
|
|
38
|
+
* mailing a moderator every time the spam folder catches a bot would train
|
|
39
|
+
* them to ignore the mail that matters.
|
|
40
|
+
*/
|
|
41
|
+
export declare function notifyAwaitingModeration(comment: CommentType, post: {
|
|
42
|
+
id: number;
|
|
43
|
+
title: string;
|
|
44
|
+
user_id?: number | null;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Tell a commenter that their comment has an approved reply, if they asked.
|
|
48
|
+
*
|
|
49
|
+
* Called whenever a reply becomes approved — on creation or by a moderator —
|
|
50
|
+
* and safe to call twice: `claimReplyNotification` lets exactly one call
|
|
51
|
+
* through per reply, ever.
|
|
52
|
+
*/
|
|
53
|
+
export declare function notifyParentOfReply(replyId: number): Promise<void>;
|