@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,201 @@
|
|
|
1
|
+
import { verifyPassword } from '@basicbenframework/core/auth';
|
|
2
|
+
import { issueToken, redeemToken, TOKEN_KINDS } from '@basicbenframework/core/auth/tokens';
|
|
3
|
+
import { generateRegistrationOptions, generateAuthenticationOptions, verifyRegistration, verifyAuthentication } from '@basicbenframework/core/auth/webauthn';
|
|
4
|
+
import { User } from "../models/User.js";
|
|
5
|
+
import { Credential } from "../models/Credential.js";
|
|
6
|
+
const CHALLENGE_TTL = 5 * 60 * 1000;
|
|
7
|
+
/**
|
|
8
|
+
* The relying party is the domain, not the origin.
|
|
9
|
+
*
|
|
10
|
+
* Passkeys are bound to it: a credential enrolled on example.com does not work
|
|
11
|
+
* on app.example.com unless rpId was set to the parent. Changing this
|
|
12
|
+
* invalidates every enrolled passkey, so decide it before anyone enrols.
|
|
13
|
+
*/
|
|
14
|
+
const rpId = () => process.env.WEBAUTHN_RP_ID || new URL(appUrl()).hostname;
|
|
15
|
+
const rpName = () => process.env.SITE_NAME || 'BasicBen';
|
|
16
|
+
const appUrl = () => process.env.APP_URL || 'http://localhost:3000';
|
|
17
|
+
/** Origins a response may claim. */
|
|
18
|
+
const allowedOrigins = () => (process.env.WEBAUTHN_ORIGINS || appUrl()).split(',').map((o) => o.trim()).filter(Boolean);
|
|
19
|
+
/**
|
|
20
|
+
* Store a challenge server-side.
|
|
21
|
+
*
|
|
22
|
+
* This cannot be stateless. A challenge the client chooses is not a challenge —
|
|
23
|
+
* the server must have issued it, and it must be usable once.
|
|
24
|
+
*/
|
|
25
|
+
async function issueChallenge(userId, challenge) {
|
|
26
|
+
const { token } = await issueToken(userId, TOKEN_KINDS.WEBAUTHN_CHALLENGE, {
|
|
27
|
+
ttl: CHALLENGE_TTL,
|
|
28
|
+
metadata: { challenge }
|
|
29
|
+
});
|
|
30
|
+
return token;
|
|
31
|
+
}
|
|
32
|
+
async function redeemChallenge(handle) {
|
|
33
|
+
const redeemed = await redeemToken(handle, TOKEN_KINDS.WEBAUTHN_CHALLENGE);
|
|
34
|
+
if (!redeemed)
|
|
35
|
+
return null;
|
|
36
|
+
return {
|
|
37
|
+
userId: redeemed.userId,
|
|
38
|
+
challenge: redeemed.metadata?.challenge
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function confirmPassword(req, res) {
|
|
42
|
+
const { password } = req.body;
|
|
43
|
+
const user = await User.find(req.userId);
|
|
44
|
+
if (!user) {
|
|
45
|
+
res.json({ error: 'User not found' }, 404);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (!password || !(await verifyPassword(password, user.password))) {
|
|
49
|
+
res.json({ error: 'Your current password is required.' }, 403);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return user;
|
|
53
|
+
}
|
|
54
|
+
export const PasskeyController = {
|
|
55
|
+
/** Enrolled passkeys, for the account settings screen. */
|
|
56
|
+
async list(req, res) {
|
|
57
|
+
const credentials = await Credential.forUser(req.userId);
|
|
58
|
+
return res.json({
|
|
59
|
+
passkeys: credentials.map((c) => ({
|
|
60
|
+
id: c.id,
|
|
61
|
+
label: c.label,
|
|
62
|
+
createdAt: c.created_at,
|
|
63
|
+
lastUsedAt: c.last_used_at,
|
|
64
|
+
backedUp: Boolean(c.backed_up)
|
|
65
|
+
}))
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
/** Options for navigator.credentials.create(). */
|
|
69
|
+
async registerOptions(req, res) {
|
|
70
|
+
const user = await confirmPassword(req, res);
|
|
71
|
+
if (!user)
|
|
72
|
+
return;
|
|
73
|
+
const existing = await Credential.forUser(user.id);
|
|
74
|
+
const { options, challenge } = generateRegistrationOptions({
|
|
75
|
+
rpId: rpId(),
|
|
76
|
+
rpName: rpName(),
|
|
77
|
+
user: {
|
|
78
|
+
id: user.id,
|
|
79
|
+
// An opaque handle rather than the row id: it is stored on the
|
|
80
|
+
// authenticator and may be visible.
|
|
81
|
+
handle: `user-${user.id}`,
|
|
82
|
+
name: user.email,
|
|
83
|
+
displayName: user.name
|
|
84
|
+
},
|
|
85
|
+
// Stops the same authenticator enrolling twice.
|
|
86
|
+
excludeCredentials: existing.map((c) => ({ type: 'public-key', id: c.credential_id }))
|
|
87
|
+
});
|
|
88
|
+
const handle = await issueChallenge(user.id, challenge);
|
|
89
|
+
return res.json({ options, challengeHandle: handle });
|
|
90
|
+
},
|
|
91
|
+
/** Verify and store a new passkey. */
|
|
92
|
+
async registerVerify(req, res) {
|
|
93
|
+
const { challengeHandle, response, label } = req.body;
|
|
94
|
+
if (!response) {
|
|
95
|
+
return res.json({ error: 'No credential was supplied.' }, 400);
|
|
96
|
+
}
|
|
97
|
+
const redeemed = await redeemChallenge(challengeHandle);
|
|
98
|
+
// A redeemed token with no challenge in its metadata is as unusable as no
|
|
99
|
+
// token at all — verifying against undefined would accept anything.
|
|
100
|
+
if (!redeemed || redeemed.userId !== req.userId || !redeemed.challenge) {
|
|
101
|
+
return res.json({ error: 'That enrolment attempt has expired. Please start again.' }, 400);
|
|
102
|
+
}
|
|
103
|
+
let result;
|
|
104
|
+
try {
|
|
105
|
+
result = verifyRegistration({
|
|
106
|
+
response,
|
|
107
|
+
expectedChallenge: redeemed.challenge,
|
|
108
|
+
expectedOrigin: allowedOrigins(),
|
|
109
|
+
expectedRpId: rpId()
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return res.json({ error: err.message }, 400);
|
|
114
|
+
}
|
|
115
|
+
if (await Credential.findByCredentialId(result.credentialId)) {
|
|
116
|
+
return res.json({ error: 'That passkey is already enrolled.' }, 409);
|
|
117
|
+
}
|
|
118
|
+
await Credential.create({
|
|
119
|
+
user_id: req.userId,
|
|
120
|
+
credential_id: result.credentialId,
|
|
121
|
+
public_key: result.publicKey,
|
|
122
|
+
algorithm: result.algorithm,
|
|
123
|
+
sign_count: result.signCount,
|
|
124
|
+
backed_up: result.backedUp ? 1 : 0,
|
|
125
|
+
label: label || 'Passkey'
|
|
126
|
+
});
|
|
127
|
+
return res.json({ enrolled: true, credentialId: result.credentialId });
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Options for navigator.credentials.get(), as the second step of a login.
|
|
131
|
+
*
|
|
132
|
+
* Takes the 2FA challenge issued after a correct password, so it does not
|
|
133
|
+
* reveal whether an account has passkeys to an unauthenticated caller.
|
|
134
|
+
*/
|
|
135
|
+
async authenticateOptions(req, res) {
|
|
136
|
+
const { challenge: loginChallenge } = req.body;
|
|
137
|
+
// Peek rather than redeem: the login challenge is spent by /2fa/verify.
|
|
138
|
+
const redeemed = await redeemToken(loginChallenge, TOKEN_KINDS.TWO_FACTOR_CHALLENGE);
|
|
139
|
+
if (!redeemed) {
|
|
140
|
+
return res.json({ error: 'That sign-in attempt has expired. Please start again.' }, 401);
|
|
141
|
+
}
|
|
142
|
+
const credentials = await Credential.forUser(redeemed.userId);
|
|
143
|
+
if (credentials.length === 0) {
|
|
144
|
+
return res.json({ error: 'No passkey is enrolled for this account.' }, 400);
|
|
145
|
+
}
|
|
146
|
+
const { options, challenge } = generateAuthenticationOptions({
|
|
147
|
+
rpId: rpId(),
|
|
148
|
+
allowCredentials: credentials.map((c) => ({ type: 'public-key', id: c.credential_id }))
|
|
149
|
+
});
|
|
150
|
+
// A fresh handle carrying both the webauthn challenge and the user, since
|
|
151
|
+
// the login challenge has now been consumed.
|
|
152
|
+
const handle = await issueChallenge(redeemed.userId, challenge);
|
|
153
|
+
return res.json({ options, challengeHandle: handle });
|
|
154
|
+
},
|
|
155
|
+
/** Remove a passkey. */
|
|
156
|
+
async remove(req, res) {
|
|
157
|
+
const user = await confirmPassword(req, res);
|
|
158
|
+
if (!user)
|
|
159
|
+
return;
|
|
160
|
+
const removed = await Credential.delete(user.id, Number(req.params.id));
|
|
161
|
+
if (!removed) {
|
|
162
|
+
return res.json({ error: 'Passkey not found' }, 404);
|
|
163
|
+
}
|
|
164
|
+
return res.json({ removed: true });
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Verify a passkey assertion as a second factor.
|
|
169
|
+
*
|
|
170
|
+
* Exported for TwoFactorController, which owns the verify endpoint — passkeys
|
|
171
|
+
* are one method behind it rather than a separate login flow.
|
|
172
|
+
*/
|
|
173
|
+
export async function verifyPasskeyAssertion({ challengeHandle, response }) {
|
|
174
|
+
const redeemed = await redeemChallenge(challengeHandle);
|
|
175
|
+
if (!redeemed?.challenge)
|
|
176
|
+
return { ok: false, error: 'That sign-in attempt has expired.' };
|
|
177
|
+
const presentedId = response?.id;
|
|
178
|
+
const credential = presentedId ? await Credential.findByCredentialId(presentedId) : undefined;
|
|
179
|
+
// The credential has to belong to the account that started this sign-in.
|
|
180
|
+
if (!credential || credential.user_id !== redeemed.userId) {
|
|
181
|
+
return { ok: false, error: 'That passkey is not enrolled for this account.' };
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const result = verifyAuthentication({
|
|
185
|
+
response,
|
|
186
|
+
credential: {
|
|
187
|
+
credentialId: credential.credential_id,
|
|
188
|
+
publicKey: credential.public_key,
|
|
189
|
+
signCount: credential.sign_count
|
|
190
|
+
},
|
|
191
|
+
expectedChallenge: redeemed.challenge,
|
|
192
|
+
expectedOrigin: allowedOrigins(),
|
|
193
|
+
expectedRpId: rpId()
|
|
194
|
+
});
|
|
195
|
+
await Credential.recordUse(credential.id, result.signCount);
|
|
196
|
+
return { ok: true, userId: credential.user_id };
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
return { ok: false, error: err.message };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgotten passwords.
|
|
3
|
+
*
|
|
4
|
+
* Two rules shape everything here.
|
|
5
|
+
*
|
|
6
|
+
* The request endpoint must not say whether an address has an account. It
|
|
7
|
+
* answers every request with the same status and the same words, and the
|
|
8
|
+
* per-mailbox limit that throttles it is applied silently rather than as a
|
|
9
|
+
* 429 that only registered addresses could ever trigger.
|
|
10
|
+
*
|
|
11
|
+
* And a reset link is proof of a mailbox, not of a person. For an account with
|
|
12
|
+
* a second factor that is not enough to sign in on: whoever reads the mail
|
|
13
|
+
* could otherwise set a password and walk past TOTP or a passkey. So the reset
|
|
14
|
+
* changes the password and ends every session, but only an account without a
|
|
15
|
+
* second factor gets a session back — everyone else signs in the normal way,
|
|
16
|
+
* second factor included.
|
|
17
|
+
*/
|
|
18
|
+
import type { Request, Response } from '../types/index.ts';
|
|
19
|
+
/** The one answer the request endpoint gives, whoever asks. */
|
|
20
|
+
export declare const RESET_REQUESTED = "If an account exists for that email, a link to reset its password is on its way.";
|
|
21
|
+
export declare const PasswordResetController: {
|
|
22
|
+
/**
|
|
23
|
+
* Ask for a reset link.
|
|
24
|
+
*
|
|
25
|
+
* Always 200, always RESET_REQUESTED. Every branch below — no such account,
|
|
26
|
+
* a disabled one, a throttled mailbox, a provider outage — ends at the same
|
|
27
|
+
* response, and that is the whole contract.
|
|
28
|
+
*
|
|
29
|
+
* The mail is awaited rather than sent after responding, which leaves a
|
|
30
|
+
* timing difference of one provider round trip between an address that has
|
|
31
|
+
* an account and one that does not. Fire-and-forget would close it, but on
|
|
32
|
+
* a serverless deploy the function is frozen once the response is written
|
|
33
|
+
* and the mail would simply never leave. A link that works beats a timing
|
|
34
|
+
* channel that the per-address limit already makes slow to exploit.
|
|
35
|
+
*/
|
|
36
|
+
request(req: Request, res: Response): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Spend a reset link on a new password.
|
|
39
|
+
*
|
|
40
|
+
* Redeeming is the atomic step — a single conditional UPDATE in the
|
|
41
|
+
* framework — so one link cannot set two passwords.
|
|
42
|
+
*/
|
|
43
|
+
reset(req: Request, res: Response): Promise<void>;
|
|
44
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgotten passwords.
|
|
3
|
+
*
|
|
4
|
+
* Two rules shape everything here.
|
|
5
|
+
*
|
|
6
|
+
* The request endpoint must not say whether an address has an account. It
|
|
7
|
+
* answers every request with the same status and the same words, and the
|
|
8
|
+
* per-mailbox limit that throttles it is applied silently rather than as a
|
|
9
|
+
* 429 that only registered addresses could ever trigger.
|
|
10
|
+
*
|
|
11
|
+
* And a reset link is proof of a mailbox, not of a person. For an account with
|
|
12
|
+
* a second factor that is not enough to sign in on: whoever reads the mail
|
|
13
|
+
* could otherwise set a password and walk past TOTP or a passkey. So the reset
|
|
14
|
+
* changes the password and ends every session, but only an account without a
|
|
15
|
+
* second factor gets a session back — everyone else signs in the normal way,
|
|
16
|
+
* second factor included.
|
|
17
|
+
*/
|
|
18
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
19
|
+
import { hashPassword } from '@basicbenframework/core/auth';
|
|
20
|
+
import { DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions';
|
|
21
|
+
import { issueToken, redeemToken, revokeTokens, TOKEN_KINDS } from '@basicbenframework/core/auth/tokens';
|
|
22
|
+
import { sendMail } from '@basicbenframework/core/mail';
|
|
23
|
+
// The site's mail/ first, then the CMS's.
|
|
24
|
+
import { renderMail } from "../helpers/mail-templates.js";
|
|
25
|
+
import { User } from "../models/User.js";
|
|
26
|
+
import { TwoFactor } from "../models/TwoFactor.js";
|
|
27
|
+
import { Credential } from "../models/Credential.js";
|
|
28
|
+
import { emailSendLimiter } from "../middleware/rate-limits.js";
|
|
29
|
+
import { issueSessionToken, revokeSessions } from "../helpers/session.js";
|
|
30
|
+
const appUrl = () => process.env.APP_URL || 'http://localhost:3000';
|
|
31
|
+
const RESET_TTL = 60 * 60 * 1000; // 1 hour
|
|
32
|
+
/** The one answer the request endpoint gives, whoever asks. */
|
|
33
|
+
export const RESET_REQUESTED = 'If an account exists for that email, a link to reset its password is on its way.';
|
|
34
|
+
const INVALID_LINK = 'This reset link is invalid, has expired, or has already been used.';
|
|
35
|
+
/**
|
|
36
|
+
* Issue a reset link and mail it.
|
|
37
|
+
*
|
|
38
|
+
* Earlier links are revoked first, so only the newest email works — someone
|
|
39
|
+
* who asked twice and clicks the older one should not get a working reset
|
|
40
|
+
* from a link they may have forwarded or left lying around.
|
|
41
|
+
*/
|
|
42
|
+
async function sendResetEmail(user) {
|
|
43
|
+
await revokeTokens(user.id, TOKEN_KINDS.PASSWORD_RESET);
|
|
44
|
+
const { token } = await issueToken(user.id, TOKEN_KINDS.PASSWORD_RESET, {
|
|
45
|
+
ttl: RESET_TTL,
|
|
46
|
+
metadata: { email: user.email }
|
|
47
|
+
});
|
|
48
|
+
const resetUrl = `${appUrl()}/reset-password/${token}`;
|
|
49
|
+
await sendMail({
|
|
50
|
+
to: user.email,
|
|
51
|
+
subject: 'Reset your password',
|
|
52
|
+
...renderMail('password-reset', {
|
|
53
|
+
name: user.name,
|
|
54
|
+
siteName: process.env.SITE_NAME || 'BasicBen',
|
|
55
|
+
resetUrl
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export const PasswordResetController = {
|
|
60
|
+
/**
|
|
61
|
+
* Ask for a reset link.
|
|
62
|
+
*
|
|
63
|
+
* Always 200, always RESET_REQUESTED. Every branch below — no such account,
|
|
64
|
+
* a disabled one, a throttled mailbox, a provider outage — ends at the same
|
|
65
|
+
* response, and that is the whole contract.
|
|
66
|
+
*
|
|
67
|
+
* The mail is awaited rather than sent after responding, which leaves a
|
|
68
|
+
* timing difference of one provider round trip between an address that has
|
|
69
|
+
* an account and one that does not. Fire-and-forget would close it, but on
|
|
70
|
+
* a serverless deploy the function is frozen once the response is written
|
|
71
|
+
* and the mail would simply never leave. A link that works beats a timing
|
|
72
|
+
* channel that the per-address limit already makes slow to exploit.
|
|
73
|
+
*/
|
|
74
|
+
async request(req, res) {
|
|
75
|
+
const result = await validate(req.body, { email: [rules.required, rules.email] });
|
|
76
|
+
// A malformed address is refused for what it is. It says nothing about
|
|
77
|
+
// whether any account exists, so it does not need the uniform answer.
|
|
78
|
+
if (result.fails())
|
|
79
|
+
return res.json({ errors: result.errors }, 422);
|
|
80
|
+
const email = String(req.body.email).trim();
|
|
81
|
+
// Consumed whether or not the account exists, so the limit itself cannot
|
|
82
|
+
// be used to tell the two apart.
|
|
83
|
+
const allowance = await emailSendLimiter.consume(`password-reset:${email.toLowerCase()}`);
|
|
84
|
+
if (allowance.allowed) {
|
|
85
|
+
const user = await User.findByEmail(email);
|
|
86
|
+
// Disabled accounts get nothing: a reset would not let them sign in,
|
|
87
|
+
// and the mail would tell them the account still exists.
|
|
88
|
+
if (user && !user.disabled_at) {
|
|
89
|
+
try {
|
|
90
|
+
await sendResetEmail(user);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.error('Failed to send password reset email:', err.message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return res.json({ message: RESET_REQUESTED });
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Spend a reset link on a new password.
|
|
101
|
+
*
|
|
102
|
+
* Redeeming is the atomic step — a single conditional UPDATE in the
|
|
103
|
+
* framework — so one link cannot set two passwords.
|
|
104
|
+
*/
|
|
105
|
+
async reset(req, res) {
|
|
106
|
+
const result = await validate(req.body, {
|
|
107
|
+
token: [rules.required, rules.string],
|
|
108
|
+
password: [rules.required, rules.min(8)]
|
|
109
|
+
});
|
|
110
|
+
if (result.fails())
|
|
111
|
+
return res.json({ errors: result.errors }, 422);
|
|
112
|
+
const { token, password } = req.body;
|
|
113
|
+
// Hashed before the token is spent, so a slow scrypt cannot leave a
|
|
114
|
+
// consumed link and an unchanged password if the request dies midway.
|
|
115
|
+
const hashed = await hashPassword(password);
|
|
116
|
+
const redeemed = await redeemToken(token, TOKEN_KINDS.PASSWORD_RESET);
|
|
117
|
+
if (!redeemed)
|
|
118
|
+
return res.json({ error: INVALID_LINK }, 400);
|
|
119
|
+
const user = await User.find(redeemed.userId);
|
|
120
|
+
// The link proves the mailbox it was sent to. If the account's address has
|
|
121
|
+
// changed since, it proves nothing about the account.
|
|
122
|
+
const issuedFor = redeemed.metadata?.email;
|
|
123
|
+
if (!user || (issuedFor && issuedFor !== user.email) || user.disabled_at) {
|
|
124
|
+
return res.json({ error: INVALID_LINK }, 400);
|
|
125
|
+
}
|
|
126
|
+
await User.update(user.id, {
|
|
127
|
+
password: hashed,
|
|
128
|
+
// Following the emailed link is the same proof verification asks for.
|
|
129
|
+
email_verified: 1,
|
|
130
|
+
email_verified_at: user.email_verified ? (user.email_verified_at ?? new Date().toISOString()) : new Date().toISOString()
|
|
131
|
+
});
|
|
132
|
+
// Every session ends, on every device: if the reset is because someone
|
|
133
|
+
// else had the password, their session must not outlive it.
|
|
134
|
+
await revokeSessions(user.id);
|
|
135
|
+
await revokeTokens(user.id, TOKEN_KINDS.PASSWORD_RESET);
|
|
136
|
+
const twoFactor = await TwoFactor.find(user.id);
|
|
137
|
+
const passkeyCount = await Credential.countForUser(user.id);
|
|
138
|
+
if (TwoFactor.isEnabled(twoFactor) || passkeyCount > 0) {
|
|
139
|
+
// No session: a mailbox is one factor, and this account asked for two.
|
|
140
|
+
return res.json({
|
|
141
|
+
message: 'Your password has been changed. Sign in with it to continue.',
|
|
142
|
+
signInRequired: true
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// Re-read, so the session carries the token version revokeSessions just
|
|
146
|
+
// bumped — one minted from the stale row would be dead on arrival.
|
|
147
|
+
const fresh = (await User.find(user.id));
|
|
148
|
+
res.json({
|
|
149
|
+
message: 'Your password has been changed.',
|
|
150
|
+
user: {
|
|
151
|
+
id: fresh.id,
|
|
152
|
+
name: fresh.name,
|
|
153
|
+
email: fresh.email,
|
|
154
|
+
role: fresh.role ?? DEFAULT_ROLE,
|
|
155
|
+
email_verified: true
|
|
156
|
+
},
|
|
157
|
+
token: issueSessionToken(fresh)
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Hooks fire from here so an app can take part in the content lifecycle.
|
|
4
|
+
*
|
|
5
|
+
* The `*.creating` and `*.updating` hooks are **filters**: a listener receives
|
|
6
|
+
* the data and returns it, possibly changed, or returns `{ cancel: true }` to
|
|
7
|
+
* refuse the write. The `*.created`, `*.updated` and `*.deleted` hooks are
|
|
8
|
+
* notifications — the write has happened and their return value is ignored.
|
|
9
|
+
*
|
|
10
|
+
* These live in the controller rather than the model because models here are
|
|
11
|
+
* hand-written plain objects with no base class to hang a lifecycle on. The
|
|
12
|
+
* cost is that an app which rewrites a controller has to keep the calls.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PostController: {
|
|
15
|
+
index(req: Request, res: Response): Promise<void>;
|
|
16
|
+
show(req: Request, res: Response): Promise<void>;
|
|
17
|
+
store(req: Request, res: Response): Promise<void>;
|
|
18
|
+
update(req: Request, res: Response): Promise<void>;
|
|
19
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
20
|
+
/** Take a post back out of the trash. */
|
|
21
|
+
restore(req: Request, res: Response): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* One action over many posts: trash, restore, delete, publish, draft.
|
|
24
|
+
*
|
|
25
|
+
* Each post is checked exactly as the single-post endpoint would check it,
|
|
26
|
+
* so selecting forty rows cannot do to one of them what you could not do to
|
|
27
|
+
* it alone. What failed is reported per post rather than failing the batch.
|
|
28
|
+
*/
|
|
29
|
+
bulk(req: Request, res: Response): Promise<void>;
|
|
30
|
+
/** Every saved version of a post, newest first. */
|
|
31
|
+
revisions(req: Request, res: Response): Promise<void>;
|
|
32
|
+
/** One revision, with its full text, to compare against the post. */
|
|
33
|
+
revision(req: Request, res: Response): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Put an older version back.
|
|
36
|
+
*
|
|
37
|
+
* A save like any other — it goes through the same capability checks and
|
|
38
|
+
* snapshots the current text first — so restoring is itself undoable.
|
|
39
|
+
*/
|
|
40
|
+
restoreRevision(req: Request, res: Response): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Keep what is being typed, without saving it.
|
|
43
|
+
*
|
|
44
|
+
* The post is untouched — a live post does not change because its editor
|
|
45
|
+
* paused. The copy waits in the revisions table, one per author, and the
|
|
46
|
+
* editor offers it back if the page is reopened before a real save.
|
|
47
|
+
*/
|
|
48
|
+
autosave(req: Request, res: Response): Promise<void>;
|
|
49
|
+
feed(req: Request, res: Response): Promise<void>;
|
|
50
|
+
feedShow(req: Request, res: Response): Promise<void>;
|
|
51
|
+
};
|