@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
package/lib/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './client/styles.css';
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom/client';
|
|
4
|
+
import './client/styles.css';
|
|
5
|
+
import { registerAdminFeatures } from "./client/host/index.js";
|
|
6
|
+
import adminFeatures from "./client/features.js";
|
|
7
|
+
import manifests from "./features.manifest.js";
|
|
8
|
+
import { manifestsFor } from "./host/enabled.js";
|
|
9
|
+
/**
|
|
10
|
+
* Register the site's features, then build the app.
|
|
11
|
+
*
|
|
12
|
+
* __BASICBEN_FEATURES__ is the site's `features` list, checked and baked in
|
|
13
|
+
* at build time (vite.config). Only those features' admin halves are loaded,
|
|
14
|
+
* and they register before App.tsx is imported, because the route table and
|
|
15
|
+
* the menu are built from what is registered when App.tsx loads.
|
|
16
|
+
*/
|
|
17
|
+
async function boot() {
|
|
18
|
+
const names = __BASICBEN_FEATURES__;
|
|
19
|
+
const loaded = await Promise.all(names.filter((name) => adminFeatures[name]).map((name) => adminFeatures[name]()));
|
|
20
|
+
registerAdminFeatures(loaded.map((module) => module.default), manifestsFor(names, manifests));
|
|
21
|
+
const { default: App } = await import("./routes/App.js");
|
|
22
|
+
ReactDOM.createRoot(document.getElementById('root')).render(_jsx(React.StrictMode, { children: _jsx(App, {}) }));
|
|
23
|
+
}
|
|
24
|
+
boot();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication for the public content API and the Admin API.
|
|
3
|
+
*
|
|
4
|
+
* One `Authorization: Bearer` header carries either a user JWT or an API token,
|
|
5
|
+
* told apart by the `bb_` prefix rather than by trying both verifiers. Trying
|
|
6
|
+
* both would mean a failed JWT verification on every token request and a
|
|
7
|
+
* database lookup on every session request, and it would make the failure
|
|
8
|
+
* message depend on which verifier happened to run last.
|
|
9
|
+
*
|
|
10
|
+
* What each grants is deliberately different. An API token has scopes; a
|
|
11
|
+
* session has a role. On the read API a token's scope is the whole check. On
|
|
12
|
+
* the Admin API (`authOrToken`) a token acts as its owner, so the owner's role
|
|
13
|
+
* is checked as well and the scope only ever narrows it.
|
|
14
|
+
*/
|
|
15
|
+
import type { Request, Response } from '../types/index.ts';
|
|
16
|
+
type Next = () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Require a credential granting `scope`, from either a token or a session.
|
|
19
|
+
*
|
|
20
|
+
* A logged-in user passes without holding a scope: scopes constrain programs
|
|
21
|
+
* that were handed a credential, not people who signed in, and a session
|
|
22
|
+
* already carries a role that the capability system checks separately.
|
|
23
|
+
*
|
|
24
|
+
* Both branches read the account row, the same way `auth` does. The session
|
|
25
|
+
* branch used to trust the JWT's own claims — its role and its verification
|
|
26
|
+
* flag — so a session that had been signed out everywhere, or belonged to a
|
|
27
|
+
* disabled account, kept working here for the rest of its seven days, with
|
|
28
|
+
* whatever role it had at sign-in. A token whose owner has been disabled is
|
|
29
|
+
* refused for the same reason: it acts as that person.
|
|
30
|
+
*/
|
|
31
|
+
export declare const requireScope: (scope: string) => (req: Request, res: Response, next: Next) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* The Admin API: a session, or an API token holding `scope`.
|
|
34
|
+
*
|
|
35
|
+
* Used in place of `auth` on the admin routes a program may drive — creating
|
|
36
|
+
* and editing posts, tags and categories, uploading media. Everything after it
|
|
37
|
+
* (capability checks, ownership, the publish rule) runs unchanged, because
|
|
38
|
+
* with a token `req.user` is the token *owner's* account as it stands now: its
|
|
39
|
+
* current role, its verification, refused if disabled. A token therefore never
|
|
40
|
+
* exceeds the person who issued it, and the scope narrows it further — an
|
|
41
|
+
* admin's `content:write` token can write posts and still cannot touch users
|
|
42
|
+
* or settings, which stay behind `auth` and refuse tokens outright.
|
|
43
|
+
*
|
|
44
|
+
* With a token, `req.apiToken` is set, which is what lets a controller treat a
|
|
45
|
+
* program differently from a person (permanent deletion, the edit lock), and
|
|
46
|
+
* what `requireSession` keys on. Every token write is counted against the
|
|
47
|
+
* token's own budget, answered with an `X-BasicBen-Token-Id` header, and
|
|
48
|
+
* logged with the token id, so a change made by a program can be traced to the
|
|
49
|
+
* credential that made it rather than only to the person who owns it.
|
|
50
|
+
*/
|
|
51
|
+
export declare const authOrToken: (scope: string) => (req: Request, res: Response, next: Next) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Refuse an API token, requiring a real session.
|
|
54
|
+
*
|
|
55
|
+
* Used on token management itself. Without it a leaked read-only token could
|
|
56
|
+
* mint a write-scoped one and scopes would be decorative.
|
|
57
|
+
*/
|
|
58
|
+
export declare const requireSession: (req: Request, res: Response, next: Next) => void;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication for the public content API and the Admin API.
|
|
3
|
+
*
|
|
4
|
+
* One `Authorization: Bearer` header carries either a user JWT or an API token,
|
|
5
|
+
* told apart by the `bb_` prefix rather than by trying both verifiers. Trying
|
|
6
|
+
* both would mean a failed JWT verification on every token request and a
|
|
7
|
+
* database lookup on every session request, and it would make the failure
|
|
8
|
+
* message depend on which verifier happened to run last.
|
|
9
|
+
*
|
|
10
|
+
* What each grants is deliberately different. An API token has scopes; a
|
|
11
|
+
* session has a role. On the read API a token's scope is the whole check. On
|
|
12
|
+
* the Admin API (`authOrToken`) a token acts as its owner, so the owner's role
|
|
13
|
+
* is checked as well and the scope only ever narrows it.
|
|
14
|
+
*/
|
|
15
|
+
import { hasScope, isApiToken, verifyApiToken } from '@basicbenframework/core/auth/api-tokens';
|
|
16
|
+
// The extension is required. Everything in src/middleware is imported by the
|
|
17
|
+
// middleware autoloader through Node's own `import()`, which does no extension
|
|
18
|
+
// guessing — Vite resolves it either way, so without this the file works in the
|
|
19
|
+
// bundle and fails to load at boot, reported and skipped.
|
|
20
|
+
import { Settings } from "../models/Settings.js";
|
|
21
|
+
import { resolveSession, accountForToken } from "./auth.js";
|
|
22
|
+
import { tokenWriteLimiter } from "./rate-limits.js";
|
|
23
|
+
function bearer(req) {
|
|
24
|
+
const header = req.headers.authorization;
|
|
25
|
+
if (!header || !header.startsWith('Bearer '))
|
|
26
|
+
return null;
|
|
27
|
+
return header.slice('Bearer '.length).trim() || null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether the site serves its content API without a credential.
|
|
31
|
+
*
|
|
32
|
+
* Off by default. A CMS that starts life publishing its whole database to
|
|
33
|
+
* anonymous readers is a surprise, and the admin API next door already requires
|
|
34
|
+
* auth — an unauthenticated public API would be the odd one out, not the norm.
|
|
35
|
+
*/
|
|
36
|
+
async function publicReadsAllowed() {
|
|
37
|
+
return Settings.getTyped('public_api', false);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Require a credential granting `scope`, from either a token or a session.
|
|
41
|
+
*
|
|
42
|
+
* A logged-in user passes without holding a scope: scopes constrain programs
|
|
43
|
+
* that were handed a credential, not people who signed in, and a session
|
|
44
|
+
* already carries a role that the capability system checks separately.
|
|
45
|
+
*
|
|
46
|
+
* Both branches read the account row, the same way `auth` does. The session
|
|
47
|
+
* branch used to trust the JWT's own claims — its role and its verification
|
|
48
|
+
* flag — so a session that had been signed out everywhere, or belonged to a
|
|
49
|
+
* disabled account, kept working here for the rest of its seven days, with
|
|
50
|
+
* whatever role it had at sign-in. A token whose owner has been disabled is
|
|
51
|
+
* refused for the same reason: it acts as that person.
|
|
52
|
+
*/
|
|
53
|
+
export const requireScope = (scope) => async (req, res, next) => {
|
|
54
|
+
const credential = bearer(req);
|
|
55
|
+
if (credential && isApiToken(credential)) {
|
|
56
|
+
const token = await verifyApiToken(credential, scope);
|
|
57
|
+
const owner = token ? await accountForToken(token.userId) : null;
|
|
58
|
+
// One message for an unknown token, an under-scoped one and one whose
|
|
59
|
+
// owner can no longer sign in: telling them apart tells a guesser which
|
|
60
|
+
// of their strings was real.
|
|
61
|
+
if (!token || !owner) {
|
|
62
|
+
return res.json({ error: 'Invalid or insufficiently scoped token' }, 401);
|
|
63
|
+
}
|
|
64
|
+
req.userId = token.userId;
|
|
65
|
+
req.apiToken = { id: token.id, name: token.name, scopes: token.scopes };
|
|
66
|
+
return next();
|
|
67
|
+
}
|
|
68
|
+
if (credential) {
|
|
69
|
+
const session = await resolveSession(credential);
|
|
70
|
+
if (session.ok) {
|
|
71
|
+
req.userId = session.userId;
|
|
72
|
+
req.user = session.user;
|
|
73
|
+
return next();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// No usable credential — absent, malformed, expired or revoked. Anonymous
|
|
77
|
+
// reads are allowed only if the site has opted in, and only for reads —
|
|
78
|
+
// `requireScope` is never applied to a mutating route without a session
|
|
79
|
+
// check in front of it. A revoked session falling through to anonymous
|
|
80
|
+
// gains nothing by it: it sees what anyone sees.
|
|
81
|
+
if (await publicReadsAllowed()) {
|
|
82
|
+
return next();
|
|
83
|
+
}
|
|
84
|
+
return res.json({
|
|
85
|
+
error: 'Unauthorized',
|
|
86
|
+
hint: 'Send an API token as "Authorization: Bearer bb_...", or enable public reads in settings.'
|
|
87
|
+
}, 401);
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The Admin API: a session, or an API token holding `scope`.
|
|
91
|
+
*
|
|
92
|
+
* Used in place of `auth` on the admin routes a program may drive — creating
|
|
93
|
+
* and editing posts, tags and categories, uploading media. Everything after it
|
|
94
|
+
* (capability checks, ownership, the publish rule) runs unchanged, because
|
|
95
|
+
* with a token `req.user` is the token *owner's* account as it stands now: its
|
|
96
|
+
* current role, its verification, refused if disabled. A token therefore never
|
|
97
|
+
* exceeds the person who issued it, and the scope narrows it further — an
|
|
98
|
+
* admin's `content:write` token can write posts and still cannot touch users
|
|
99
|
+
* or settings, which stay behind `auth` and refuse tokens outright.
|
|
100
|
+
*
|
|
101
|
+
* With a token, `req.apiToken` is set, which is what lets a controller treat a
|
|
102
|
+
* program differently from a person (permanent deletion, the edit lock), and
|
|
103
|
+
* what `requireSession` keys on. Every token write is counted against the
|
|
104
|
+
* token's own budget, answered with an `X-BasicBen-Token-Id` header, and
|
|
105
|
+
* logged with the token id, so a change made by a program can be traced to the
|
|
106
|
+
* credential that made it rather than only to the person who owns it.
|
|
107
|
+
*/
|
|
108
|
+
export const authOrToken = (scope) => async (req, res, next) => {
|
|
109
|
+
const credential = bearer(req);
|
|
110
|
+
if (!credential) {
|
|
111
|
+
return res.json({ error: 'Unauthorized' }, 401);
|
|
112
|
+
}
|
|
113
|
+
if (!isApiToken(credential)) {
|
|
114
|
+
const session = await resolveSession(credential);
|
|
115
|
+
if (!session.ok)
|
|
116
|
+
return res.json(session.body, session.status);
|
|
117
|
+
req.userId = session.userId;
|
|
118
|
+
req.user = session.user;
|
|
119
|
+
return next();
|
|
120
|
+
}
|
|
121
|
+
// Verified without the scope first, so that a real token which simply
|
|
122
|
+
// lacks it can be told so. Its holder already has the token; saying it is
|
|
123
|
+
// valid tells them nothing new, and "invalid token" for a working read
|
|
124
|
+
// token sends people looking for the wrong problem.
|
|
125
|
+
const token = await verifyApiToken(credential);
|
|
126
|
+
const owner = token ? await accountForToken(token.userId) : null;
|
|
127
|
+
if (!token || !owner) {
|
|
128
|
+
return res.json({ error: 'Invalid token' }, 401);
|
|
129
|
+
}
|
|
130
|
+
if (!hasScope(token.scopes, scope)) {
|
|
131
|
+
return res.json({ error: `This token does not hold the ${scope} scope` }, 403);
|
|
132
|
+
}
|
|
133
|
+
const method = String(req.method ?? 'GET').toUpperCase();
|
|
134
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
135
|
+
const limit = await tokenWriteLimiter.consume(`api-token:${token.id}`);
|
|
136
|
+
if (!limit.allowed) {
|
|
137
|
+
res.setHeader('Retry-After', String(limit.retryAfter));
|
|
138
|
+
return res.json({ error: 'Too many writes with this token. Please slow down.', retryAfter: limit.retryAfter }, 429);
|
|
139
|
+
}
|
|
140
|
+
// The audit line. A log rather than a table: it costs nothing on the
|
|
141
|
+
// request, every host already collects stdout, and the hooks that fire
|
|
142
|
+
// on each write receive `req` — so a site that wants a durable trail can
|
|
143
|
+
// record `req.apiToken` wherever it likes from a listener.
|
|
144
|
+
const url = String(req.url ?? '');
|
|
145
|
+
console.info(`[admin-api] token ${token.id} "${token.name}" (user ${token.userId}) ${method} ${url}`);
|
|
146
|
+
}
|
|
147
|
+
res.setHeader('X-BasicBen-Token-Id', String(token.id));
|
|
148
|
+
req.userId = token.userId;
|
|
149
|
+
req.user = owner;
|
|
150
|
+
req.apiToken = { id: token.id, name: token.name, scopes: token.scopes };
|
|
151
|
+
next();
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Refuse an API token, requiring a real session.
|
|
155
|
+
*
|
|
156
|
+
* Used on token management itself. Without it a leaked read-only token could
|
|
157
|
+
* mint a write-scoped one and scopes would be decorative.
|
|
158
|
+
*/
|
|
159
|
+
export const requireSession = (req, res, next) => {
|
|
160
|
+
if (req.apiToken) {
|
|
161
|
+
return res.json({ error: 'This endpoint requires a signed-in session, not an API token' }, 403);
|
|
162
|
+
}
|
|
163
|
+
next();
|
|
164
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/** The request user, as every capability check reads it. */
|
|
3
|
+
export interface CurrentUser {
|
|
4
|
+
id: number;
|
|
5
|
+
role: string;
|
|
6
|
+
email_verified: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type Resolved = {
|
|
9
|
+
ok: true;
|
|
10
|
+
userId: number;
|
|
11
|
+
user: CurrentUser;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
status: number;
|
|
15
|
+
body: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The account behind an API token, as it stands now.
|
|
19
|
+
*
|
|
20
|
+
* A token carries no role of its own — it acts as its owner — so the owner's
|
|
21
|
+
* row is read on every use for the same reason a session's is: a disabled
|
|
22
|
+
* account's tokens stop working on their next request, and a demoted owner's
|
|
23
|
+
* token is demoted with them. Token version is deliberately not compared:
|
|
24
|
+
* "sign out everywhere" ends sessions, and tokens are revoked on their own
|
|
25
|
+
* screen (or all at once when an admin disables the account).
|
|
26
|
+
*
|
|
27
|
+
* Null when there is no usable account behind it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function accountForToken(userId: number): Promise<CurrentUser | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Turn a bearer token into the signed-in user, or say why not.
|
|
32
|
+
*
|
|
33
|
+
* The token proves who is asking; the account row decides what they may do.
|
|
34
|
+
* Reading the row on every request is what makes a session revocable — a
|
|
35
|
+
* signed-out, disabled or demoted account stops working on its next request
|
|
36
|
+
* rather than when its token happens to expire — and it means the role checked
|
|
37
|
+
* is the role the account has now, not the one it had at sign-in.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveSession(token: string): Promise<Resolved>;
|
|
40
|
+
export declare const auth: (req: Request, res: Response, next: () => void) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Identify the caller if they are signed in, and carry on either way.
|
|
43
|
+
*
|
|
44
|
+
* For routes anyone may use but a signed-in user uses differently — posting a
|
|
45
|
+
* comment as yourself rather than as a guest, or a moderator seeing the queue.
|
|
46
|
+
* A bad token is treated as no token rather than refused: the request was
|
|
47
|
+
* allowed without one.
|
|
48
|
+
*/
|
|
49
|
+
export declare const optionalAuth: (req: Request, _res: Response, next: () => void) => Promise<void>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { verifyJwt } from '@basicbenframework/core/auth';
|
|
2
|
+
import { DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions';
|
|
3
|
+
import { isApiToken } from '@basicbenframework/core/auth/api-tokens';
|
|
4
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
5
|
+
async function readAccount(userId) {
|
|
6
|
+
const db = await getDb();
|
|
7
|
+
return (await db.get('SELECT role, email_verified, token_version, disabled_at FROM users WHERE id = ?', [userId]));
|
|
8
|
+
}
|
|
9
|
+
function currentUser(userId, account) {
|
|
10
|
+
return {
|
|
11
|
+
id: userId,
|
|
12
|
+
role: account.role ?? DEFAULT_ROLE,
|
|
13
|
+
// Absent means verified: rows created before verification existed have
|
|
14
|
+
// no value, and treating that as unverified would lock everyone out.
|
|
15
|
+
email_verified: account.email_verified === null || account.email_verified === undefined
|
|
16
|
+
? true
|
|
17
|
+
: Boolean(account.email_verified)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The account behind an API token, as it stands now.
|
|
22
|
+
*
|
|
23
|
+
* A token carries no role of its own — it acts as its owner — so the owner's
|
|
24
|
+
* row is read on every use for the same reason a session's is: a disabled
|
|
25
|
+
* account's tokens stop working on their next request, and a demoted owner's
|
|
26
|
+
* token is demoted with them. Token version is deliberately not compared:
|
|
27
|
+
* "sign out everywhere" ends sessions, and tokens are revoked on their own
|
|
28
|
+
* screen (or all at once when an admin disables the account).
|
|
29
|
+
*
|
|
30
|
+
* Null when there is no usable account behind it.
|
|
31
|
+
*/
|
|
32
|
+
export async function accountForToken(userId) {
|
|
33
|
+
const account = await readAccount(userId);
|
|
34
|
+
if (!account || account.disabled_at)
|
|
35
|
+
return null;
|
|
36
|
+
return currentUser(userId, account);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Turn a bearer token into the signed-in user, or say why not.
|
|
40
|
+
*
|
|
41
|
+
* The token proves who is asking; the account row decides what they may do.
|
|
42
|
+
* Reading the row on every request is what makes a session revocable — a
|
|
43
|
+
* signed-out, disabled or demoted account stops working on its next request
|
|
44
|
+
* rather than when its token happens to expire — and it means the role checked
|
|
45
|
+
* is the role the account has now, not the one it had at sign-in.
|
|
46
|
+
*/
|
|
47
|
+
export async function resolveSession(token) {
|
|
48
|
+
// An API token can never verify as a JWT, so this would refuse one anyway —
|
|
49
|
+
// but "Invalid token" for a credential that is perfectly valid elsewhere
|
|
50
|
+
// reads as a bug in the token rather than a rule about this route.
|
|
51
|
+
if (isApiToken(token)) {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
status: 403,
|
|
55
|
+
body: {
|
|
56
|
+
error: 'This endpoint requires a signed-in session, not an API token',
|
|
57
|
+
hint: 'API tokens work on /api/v1/* and on the Admin API write routes (docs/admin-api.md). This one requires logging in.'
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const payload = verifyJwt(token, process.env.APP_KEY);
|
|
62
|
+
if (!payload) {
|
|
63
|
+
return { ok: false, status: 401, body: { error: 'Invalid token' } };
|
|
64
|
+
}
|
|
65
|
+
const account = await readAccount(payload.userId);
|
|
66
|
+
// Tokens from before versioning carry no `tv`; they match version 0, which
|
|
67
|
+
// every account starts at, so a deploy signs nobody out.
|
|
68
|
+
const tokenVersion = Number(payload.tv ?? 0);
|
|
69
|
+
if (!account || account.disabled_at || Number(account.token_version ?? 0) !== tokenVersion) {
|
|
70
|
+
return { ok: false, status: 401, body: { error: 'Session expired. Please sign in again.' } };
|
|
71
|
+
}
|
|
72
|
+
return { ok: true, userId: payload.userId, user: currentUser(payload.userId, account) };
|
|
73
|
+
}
|
|
74
|
+
function bearer(req) {
|
|
75
|
+
const header = req.headers.authorization;
|
|
76
|
+
return typeof header === 'string' && header.startsWith('Bearer ') ? header.slice(7) : undefined;
|
|
77
|
+
}
|
|
78
|
+
// Named exports only, deliberately. The framework applies any DEFAULT export
|
|
79
|
+
// from src/middleware/*.js to every route, which would 401 the whole site
|
|
80
|
+
// including the login endpoint.
|
|
81
|
+
export const auth = async (req, res, next) => {
|
|
82
|
+
const token = bearer(req);
|
|
83
|
+
if (!token) {
|
|
84
|
+
return res.json({ error: 'Unauthorized' }, 401);
|
|
85
|
+
}
|
|
86
|
+
const result = await resolveSession(token);
|
|
87
|
+
if (!result.ok) {
|
|
88
|
+
return res.json(result.body, result.status);
|
|
89
|
+
}
|
|
90
|
+
req.userId = result.userId;
|
|
91
|
+
req.user = result.user;
|
|
92
|
+
next();
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Identify the caller if they are signed in, and carry on either way.
|
|
96
|
+
*
|
|
97
|
+
* For routes anyone may use but a signed-in user uses differently — posting a
|
|
98
|
+
* comment as yourself rather than as a guest, or a moderator seeing the queue.
|
|
99
|
+
* A bad token is treated as no token rather than refused: the request was
|
|
100
|
+
* allowed without one.
|
|
101
|
+
*/
|
|
102
|
+
export const optionalAuth = async (req, _res, next) => {
|
|
103
|
+
const token = bearer(req);
|
|
104
|
+
if (token) {
|
|
105
|
+
const result = await resolveSession(token);
|
|
106
|
+
if (result.ok) {
|
|
107
|
+
req.userId = result.userId;
|
|
108
|
+
req.user = result.user;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
next();
|
|
112
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional GETs for JSON responses.
|
|
3
|
+
*
|
|
4
|
+
* A headless consumer is usually a build step that fetches the same content
|
|
5
|
+
* repeatedly — a static site generator rebuilding, a cron re-syncing. Sending
|
|
6
|
+
* an unchanged 200KB payload to a client that already has it is the bulk of
|
|
7
|
+
* what such an API does if nobody makes it cacheable.
|
|
8
|
+
*
|
|
9
|
+
* The ETag is a hash of the body, computed after the handler has produced it,
|
|
10
|
+
* so it costs one hash per response and needs no bookkeeping about which tables
|
|
11
|
+
* a route touched. That is the trade: it saves bandwidth and client parsing,
|
|
12
|
+
* not the database work that produced the body.
|
|
13
|
+
*/
|
|
14
|
+
import type { Request, Response } from '../types/index.ts';
|
|
15
|
+
type Next = () => void;
|
|
16
|
+
export declare const cacheable: (req: Request, res: Response, next: Next) => void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional GETs for JSON responses.
|
|
3
|
+
*
|
|
4
|
+
* A headless consumer is usually a build step that fetches the same content
|
|
5
|
+
* repeatedly — a static site generator rebuilding, a cron re-syncing. Sending
|
|
6
|
+
* an unchanged 200KB payload to a client that already has it is the bulk of
|
|
7
|
+
* what such an API does if nobody makes it cacheable.
|
|
8
|
+
*
|
|
9
|
+
* The ETag is a hash of the body, computed after the handler has produced it,
|
|
10
|
+
* so it costs one hash per response and needs no bookkeeping about which tables
|
|
11
|
+
* a route touched. That is the trade: it saves bandwidth and client parsing,
|
|
12
|
+
* not the database work that produced the body.
|
|
13
|
+
*/
|
|
14
|
+
import { strongEtag, conditional } from '@basicbenframework/core/etag';
|
|
15
|
+
import { credentialHeaders } from "../helpers/access.js";
|
|
16
|
+
/** How long a consumer may reuse a response without revalidating. */
|
|
17
|
+
const MAX_AGE_SECONDS = 60;
|
|
18
|
+
export const cacheable = (req, res, next) => {
|
|
19
|
+
const send = res.json.bind(res);
|
|
20
|
+
res.json = (data, status) => {
|
|
21
|
+
// Only successful reads are cacheable. A 404 carrying an ETag would have a
|
|
22
|
+
// client revalidating a resource that does not exist, and an error body is
|
|
23
|
+
// not a representation of anything worth storing.
|
|
24
|
+
if (status !== undefined && status >= 300) {
|
|
25
|
+
return send(data, status);
|
|
26
|
+
}
|
|
27
|
+
const body = JSON.stringify(data);
|
|
28
|
+
// A response that needed a credential is for whoever held it. Marking it
|
|
29
|
+
// `public` let a shared cache or CDN hand it to the next caller with no
|
|
30
|
+
// token at all; `private` keeps it in the requesting client's own cache.
|
|
31
|
+
// Anonymous reads (public_api on) stay public and shareable.
|
|
32
|
+
//
|
|
33
|
+
// A reader's credential for restricted posts (the access policy names
|
|
34
|
+
// its headers; the members feature's is X-Member-Token) counts too: with
|
|
35
|
+
// one, a restricted body is in the response, and a shared cache that
|
|
36
|
+
// stored it would hand it to the next anonymous reader. The header's mere
|
|
37
|
+
// presence is enough — valid or not — so the rule cannot depend on a
|
|
38
|
+
// lookup, and `Vary` names it so a cache keyed on headers never crosses
|
|
39
|
+
// the two.
|
|
40
|
+
const readerHeaders = credentialHeaders();
|
|
41
|
+
const credentialed = Boolean(req.headers.authorization || readerHeaders.some((name) => req.headers[name.toLowerCase()]));
|
|
42
|
+
res.setHeader('Vary', ['Authorization', ...readerHeaders].join(', '));
|
|
43
|
+
if (conditional(req, res, {
|
|
44
|
+
etag: strongEtag(body),
|
|
45
|
+
cacheControl: `${credentialed ? 'private' : 'public'}, max-age=${MAX_AGE_SECONDS}`
|
|
46
|
+
})) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
send(data, status);
|
|
50
|
+
};
|
|
51
|
+
next();
|
|
52
|
+
};
|