@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,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useAuth, useNavigate } from '@basicbenframework/core/client';
|
|
4
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
5
|
+
import { RootLayout } from "./RootLayout.js";
|
|
6
|
+
import { DesktopNav } from "../components/Nav/DesktopNav.js";
|
|
7
|
+
import { MobileNav } from "../components/Nav/MobileNav.js";
|
|
8
|
+
import { DarkModeToggle } from "../components/Nav/DarkModeToggle.js";
|
|
9
|
+
import { Logo } from "../components/Logo.js";
|
|
10
|
+
function AppLayoutInner({ children }) {
|
|
11
|
+
const { t, dark, setDark } = useTheme();
|
|
12
|
+
const { user, logout } = useAuth();
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
|
15
|
+
return (_jsxs("div", { className: "max-w-3xl mx-auto px-6", children: [_jsxs("nav", { className: `flex items-center justify-between h-14 border-b ${t.border} relative`, children: [_jsxs("button", { onClick: () => navigate('/'), className: "flex items-center gap-2 font-semibold hover:opacity-70 transition", children: [_jsx(Logo, { className: "w-6 h-6" }), _jsx("span", { children: "BasicBen" })] }), _jsx(DesktopNav, { user: user, navigate: navigate, logout: logout }), _jsxs("div", { className: "flex sm:hidden items-center gap-2", children: [_jsx(DarkModeToggle, { dark: dark, setDark: setDark }), _jsx("button", { onClick: () => setMobileMenuOpen(true), className: `p-2 rounded-lg ${t.card} transition`, "aria-label": "Open menu", children: _jsx("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M4 6h16M4 12h16M4 18h16" }) }) })] })] }), _jsx("main", { className: "py-8", children: children }), mobileMenuOpen && (_jsx(MobileNav, { user: user, navigate: navigate, onClose: () => setMobileMenuOpen(false), logout: logout }))] }));
|
|
16
|
+
}
|
|
17
|
+
export function AppLayout({ children }) {
|
|
18
|
+
return (_jsx(RootLayout, { children: _jsx(AppLayoutInner, { children: children }) }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useNavigate } from '@basicbenframework/core/client';
|
|
3
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
4
|
+
import { RootLayout } from "./RootLayout.js";
|
|
5
|
+
import { DarkModeToggle } from "../components/Nav/DarkModeToggle.js";
|
|
6
|
+
import { Logo } from "../components/Logo.js";
|
|
7
|
+
function AuthLayoutInner({ children }) {
|
|
8
|
+
const { t, dark, setDark } = useTheme();
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
return (_jsxs("div", { className: "max-w-3xl mx-auto px-6", children: [_jsxs("nav", { className: `flex items-center justify-between h-14 border-b ${t.border}`, children: [_jsxs("button", { onClick: () => navigate('/'), className: "flex items-center gap-2 font-semibold hover:opacity-70 transition", children: [_jsx(Logo, { className: "w-6 h-6" }), _jsx("span", { children: "BasicBen" })] }), _jsx(DarkModeToggle, { dark: dark, setDark: setDark })] }), _jsx("main", { className: "py-8 flex items-center justify-center min-h-[calc(100vh-3.5rem)]", children: children })] }));
|
|
11
|
+
}
|
|
12
|
+
export function AuthLayout({ children }) {
|
|
13
|
+
return (_jsx(RootLayout, { children: _jsx(AuthLayoutInner, { children: children }) }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useNavigate, usePath } from '@basicbenframework/core/client';
|
|
3
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
4
|
+
import { AppLayout } from "./AppLayout.js";
|
|
5
|
+
function SidebarLink({ href, active, children }) {
|
|
6
|
+
const { t } = useTheme();
|
|
7
|
+
const navigate = useNavigate();
|
|
8
|
+
return (_jsx("button", { onClick: () => navigate(href), className: `block w-full text-left px-3 py-2 rounded-lg text-sm transition ${active ? `${t.card} font-medium` : `${t.muted} hover:opacity-70`}`, children: children }));
|
|
9
|
+
}
|
|
10
|
+
function DocsSidebar({ children }) {
|
|
11
|
+
const path = usePath();
|
|
12
|
+
const docLinks = [
|
|
13
|
+
{ href: '/docs', label: 'Getting Started' },
|
|
14
|
+
{ href: '/docs/routing', label: 'Routing' },
|
|
15
|
+
{ href: '/docs/database', label: 'Database' },
|
|
16
|
+
{ href: '/docs/authentication', label: 'Authentication' },
|
|
17
|
+
{ href: '/docs/validation', label: 'Validation' },
|
|
18
|
+
{ href: '/docs/content', label: 'Content & Markdown' },
|
|
19
|
+
{ href: '/docs/storage', label: 'Object Storage' },
|
|
20
|
+
{ href: '/docs/extending', label: 'Extending' },
|
|
21
|
+
{ href: '/docs/headless', label: 'Headless API' },
|
|
22
|
+
{ href: '/docs/testing', label: 'Testing' },
|
|
23
|
+
];
|
|
24
|
+
return (_jsxs("div", { className: "flex gap-8", children: [_jsx("aside", { className: "hidden md:block w-48 flex-shrink-0", children: _jsx("nav", { className: "sticky top-20 space-y-1", children: docLinks.map(link => (_jsx(SidebarLink, { href: link.href, active: path === link.href, children: link.label }, link.href))) }) }), _jsx("div", { className: "flex-1 min-w-0", children: children })] }));
|
|
25
|
+
}
|
|
26
|
+
export function DocsLayout({ children }) {
|
|
27
|
+
return (_jsx(AppLayout, { children: _jsx(DocsSidebar, { children: children }) }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { ThemeContext } from "../components/ThemeContext.js";
|
|
4
|
+
import { ToastProvider } from "../contexts/ToastContext.js";
|
|
5
|
+
export function RootLayout({ children }) {
|
|
6
|
+
const [dark, setDark] = useState(true);
|
|
7
|
+
const t = dark
|
|
8
|
+
? { bg: 'bg-black', text: 'text-white', muted: 'text-white/50', subtle: 'text-white/30', border: 'border-white/10', card: 'bg-white/5', btn: 'bg-white text-black', btnHover: 'hover:bg-white/90', btnSecondary: 'bg-white/10 hover:bg-white/20' }
|
|
9
|
+
: { bg: 'bg-white', text: 'text-black', muted: 'text-black/50', subtle: 'text-black/30', border: 'border-black/10', card: 'bg-black/5', btn: 'bg-black text-white', btnHover: 'hover:bg-black/90', btnSecondary: 'bg-black/10 hover:bg-black/20' };
|
|
10
|
+
return (_jsx(ThemeContext.Provider, { value: { t, dark, setDark }, children: _jsx(ToastProvider, { children: _jsxs("div", { className: `min-h-screen ${t.bg} ${t.text} transition-colors duration-300`, children: [_jsxs("div", { className: "fixed inset-0 pointer-events-none overflow-hidden", children: [_jsx("div", { className: `absolute top-0 right-0 w-[500px] h-[500px] rounded-full blur-[150px] ${dark ? 'bg-purple-500/10' : 'bg-purple-500/5'}` }), _jsx("div", { className: `absolute bottom-0 left-0 w-[500px] h-[500px] rounded-full blur-[150px] ${dark ? 'bg-blue-500/10' : 'bg-blue-500/5'}` })] }), _jsx("div", { className: "relative", children: children })] }) }) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accept an invitation: the address is fixed, the name and password are theirs.
|
|
3
|
+
*
|
|
4
|
+
* Reachable whatever DISABLE_REGISTRATION and DISABLE_PUBLIC_SITE say — on a
|
|
5
|
+
* closed site this is the only way a new person gets an account, and it is an
|
|
6
|
+
* admin who opened the door.
|
|
7
|
+
*/
|
|
8
|
+
export declare function AcceptInvite(): import("react").JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { useAuth, useNavigate, useParams } from '@basicbenframework/core/client';
|
|
4
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
5
|
+
import { Input } from "../components/Input.js";
|
|
6
|
+
import { Button } from "../components/Button.js";
|
|
7
|
+
import { api } from "../../helpers/api.js";
|
|
8
|
+
import { useToast } from "../contexts/ToastContext.js";
|
|
9
|
+
/**
|
|
10
|
+
* Accept an invitation: the address is fixed, the name and password are theirs.
|
|
11
|
+
*
|
|
12
|
+
* Reachable whatever DISABLE_REGISTRATION and DISABLE_PUBLIC_SITE say — on a
|
|
13
|
+
* closed site this is the only way a new person gets an account, and it is an
|
|
14
|
+
* admin who opened the door.
|
|
15
|
+
*/
|
|
16
|
+
export function AcceptInvite() {
|
|
17
|
+
const { setUser } = useAuth();
|
|
18
|
+
const navigate = useNavigate();
|
|
19
|
+
const params = useParams();
|
|
20
|
+
const { t } = useTheme();
|
|
21
|
+
const toast = useToast();
|
|
22
|
+
const [info, setInfo] = useState(null);
|
|
23
|
+
const [invalid, setInvalid] = useState(null);
|
|
24
|
+
const [form, setForm] = useState({ name: '', password: '' });
|
|
25
|
+
const [loading, setLoading] = useState(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
api.get(`/api/invitations/${encodeURIComponent(params.token ?? '')}`)
|
|
28
|
+
.then((data) => {
|
|
29
|
+
setInfo(data);
|
|
30
|
+
setForm((current) => ({ ...current, name: data.name ?? '' }));
|
|
31
|
+
})
|
|
32
|
+
.catch((err) => setInvalid(err.message));
|
|
33
|
+
}, [params.token]);
|
|
34
|
+
const handleSubmit = async (e) => {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
setLoading(true);
|
|
37
|
+
try {
|
|
38
|
+
const data = await api.post(`/api/invitations/${encodeURIComponent(params.token ?? '')}/accept`, form);
|
|
39
|
+
// Stored exactly as sign-in stores it, so the rest of the app cannot
|
|
40
|
+
// tell an accepted invitation from a login.
|
|
41
|
+
localStorage.setItem('token', data.token);
|
|
42
|
+
setUser(data.user);
|
|
43
|
+
toast.success('Welcome aboard!');
|
|
44
|
+
navigate('/admin');
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
toast.error(err.message);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (invalid) {
|
|
54
|
+
return (_jsxs("div", { className: "max-w-xs mx-auto py-8 text-center", children: [_jsx("h1", { className: "text-2xl font-bold mb-1", children: "Invitation unavailable" }), _jsxs("p", { className: `text-sm ${t.muted} mb-6`, children: [invalid, " Ask whoever invited you to send another."] }), _jsx("button", { onClick: () => navigate('/login'), className: "text-xs underline hover:no-underline", children: "Go to sign in" })] }));
|
|
55
|
+
}
|
|
56
|
+
if (!info) {
|
|
57
|
+
return _jsx("div", { className: `max-w-xs mx-auto py-8 text-center text-sm ${t.muted}`, children: "Loading\u2026" });
|
|
58
|
+
}
|
|
59
|
+
return (_jsxs("div", { className: "max-w-xs mx-auto py-8", children: [_jsxs("h1", { className: "text-2xl font-bold text-center mb-1", children: ["Join ", info.siteName] }), _jsxs("p", { className: `text-sm ${t.muted} text-center mb-6`, children: ["You've been invited as ", /^[aeiou]/i.test(info.role) ? 'an' : 'a', " ", info.role, ". Set up your account for ", info.email, "."] }), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-3 mt-4", children: [_jsx(Input, { type: "email", value: info.email, disabled: true, readOnly: true, "aria-label": "Email" }), _jsx(Input, { placeholder: "Name", required: true, minLength: 2, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) }), _jsx(Input, { type: "password", placeholder: "Password", required: true, minLength: 8, autoComplete: "new-password", value: form.password, onChange: (e) => setForm({ ...form, password: e.target.value }) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : 'Create account' })] })] }));
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Auth(): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useAuth, useNavigate, usePath } from '@basicbenframework/core/client';
|
|
4
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
5
|
+
import { Input } from "../components/Input.js";
|
|
6
|
+
import { Button } from "../components/Button.js";
|
|
7
|
+
import { api } from "../../helpers/api.js";
|
|
8
|
+
import { useToast } from "../contexts/ToastContext.js";
|
|
9
|
+
export function Auth() {
|
|
10
|
+
const { setUser } = useAuth();
|
|
11
|
+
const navigate = useNavigate();
|
|
12
|
+
const path = usePath();
|
|
13
|
+
const { t } = useTheme();
|
|
14
|
+
const toast = useToast();
|
|
15
|
+
const [form, setForm] = useState({ name: '', email: '', password: '' });
|
|
16
|
+
const [loading, setLoading] = useState(false);
|
|
17
|
+
const isLogin = path === '/login';
|
|
18
|
+
const handleSubmit = async (e) => {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
setLoading(true);
|
|
21
|
+
try {
|
|
22
|
+
const endpoint = isLogin ? '/api/auth/login' : '/api/auth/register';
|
|
23
|
+
const data = await api(endpoint, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
body: JSON.stringify(isLogin ? { email: form.email, password: form.password } : form)
|
|
26
|
+
});
|
|
27
|
+
localStorage.setItem('token', data.token);
|
|
28
|
+
setUser(data.user);
|
|
29
|
+
toast.success(isLogin ? 'Welcome back!' : 'Account created!');
|
|
30
|
+
navigate('/');
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
toast.error(err.message);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
setLoading(false);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return (_jsxs("div", { className: "max-w-xs mx-auto py-8", children: [_jsx("h1", { className: "text-2xl font-bold text-center mb-1", children: isLogin ? 'Welcome back' : 'Create account' }), _jsx("p", { className: `text-sm ${t.muted} text-center mb-6`, children: isLogin ? 'Sign in to continue' : 'Get started for free' }), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-3 mt-4", children: [!isLogin && _jsx(Input, { placeholder: "Name", required: true, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) }), _jsx(Input, { type: "email", placeholder: "Email", required: true, value: form.email, onChange: (e) => setForm({ ...form, email: e.target.value }) }), _jsx(Input, { type: "password", placeholder: "Password", required: true, minLength: 8, value: form.password, onChange: (e) => setForm({ ...form, password: e.target.value }) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : isLogin ? 'Sign in' : 'Create account' })] }), isLogin && (_jsx("p", { className: `text-xs ${t.muted} text-center mt-4`, children: _jsx("button", { onClick: () => navigate('/forgot-password'), className: "underline hover:no-underline", children: "Forgot password?" }) })), !__DISABLE_REGISTRATION__ && (_jsxs("p", { className: `text-xs ${t.muted} text-center mt-4`, children: [isLogin ? "Don't have an account? " : 'Have an account? ', _jsx("button", { onClick: () => navigate(isLogin ? '/register' : '/login'), className: "underline hover:no-underline", children: isLogin ? 'Sign up' : 'Sign in' })] }))] }));
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Authentication(): import("react").JSX.Element;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
3
|
+
import { Card } from "../components/Card.js";
|
|
4
|
+
import { PageHeader } from "../components/PageHeader.js";
|
|
5
|
+
export function Authentication() {
|
|
6
|
+
const { t } = useTheme();
|
|
7
|
+
const CodeBlock = ({ children, title }) => (_jsxs("div", { className: "mt-4", children: [title && _jsx("div", { className: `text-xs font-medium mb-2 ${t.muted}`, children: title }), _jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${t.card} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: children }) })] }));
|
|
8
|
+
return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Authentication", subtitle: "JWT tokens, password hashing, protected routes, and roles" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Overview" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Authentication is built on ", _jsx("code", { children: "node:crypto" }), " \u2014 there is no bcrypt or jsonwebtoken dependency. Token and password helpers come from", _jsx("code", { children: "@basicbenframework/core/auth" }), ", and roles come from", _jsx("code", { children: "@basicbenframework/core/auth/permissions" }), "."] }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("div", { className: "font-semibold text-sm", children: "JWT Tokens" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Stateless authentication, signed HS256" })] }), _jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("div", { className: "font-semibold text-sm", children: "Scrypt Hashing" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Salted password storage" })] }), _jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("div", { className: "font-semibold text-sm", children: "Roles and Capabilities" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Decide who may do what" })] })] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "The Signing Secret" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["The framework does not hold a secret of its own and reads nothing from", _jsx("code", { children: "basicben.config.js" }), " for auth. Every call that signs or verifies a token takes the secret as an argument, so you decide where it comes from. The convention across the generated app is ", _jsx("code", { children: "process.env.APP_KEY" }), ", set in ", _jsx("code", { children: ".env" }), "."] }), _jsx(CodeBlock, { title: ".env", children: `APP_KEY=a-long-random-string` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Passing the secret explicitly means signing and verification cannot silently drift apart, and a route that mints tokens for a different audience can use a different key. Changing ", _jsx("code", { children: "APP_KEY" }), " invalidates every token already issued, which is the blunt way to sign everybody out."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Password Hashing" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Passwords are hashed with scrypt. Each hash gets its own random salt, and verification uses a timing-safe comparison. Both ", _jsx("code", { children: "hashPassword" }), " and", _jsx("code", { children: "verifyPassword" }), " are async, so both need ", _jsx("code", { children: "await" }), "."] }), _jsx(CodeBlock, { title: "Hash and verify passwords", children: `import { hashPassword, verifyPassword } from '@basicbenframework/core/auth'
|
|
9
|
+
|
|
10
|
+
// Registration: hash before storing
|
|
11
|
+
const hash = await hashPassword('correct-horse-battery-staple')
|
|
12
|
+
|
|
13
|
+
// Login: compare the submitted password against the stored hash
|
|
14
|
+
const isValid = await verifyPassword('correct-horse-battery-staple', hash)
|
|
15
|
+
// true
|
|
16
|
+
|
|
17
|
+
await verifyPassword('wrong-password', hash)
|
|
18
|
+
// false` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The stored value is a single string holding the salt, the derived key, and the parameters used to produce it, in the format", _jsx("code", { children: "base64(salt):base64(hash):N:r:p:keylen" }), ". Because the parameters travel with the hash, raising the cost later does not lock existing users out \u2014 old hashes still verify against their own settings. A ", _jsx("code", { children: "TEXT" }), " column is all you need."] }), _jsx(CodeBlock, { title: "Raising the cost over time", children: `import { hashPassword, verifyPassword, needsRehash } from '@basicbenframework/core/auth'
|
|
19
|
+
|
|
20
|
+
// After a successful login, while you still have the plain password
|
|
21
|
+
if (await verifyPassword(password, user.password) && needsRehash(user.password)) {
|
|
22
|
+
await User.update(user.id, { password: await hashPassword(password) })
|
|
23
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "needsRehash" }), " compares the parameters stored in the hash against the current defaults, or against options you pass as a second argument. It is the only one of the three that is synchronous."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "JWT Tokens" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "signJwt" }), " and ", _jsx("code", { children: "verifyJwt" }), " are synchronous. There is nothing to await, and no try/catch to write: ", _jsx("code", { children: "verifyJwt" }), " returns the decoded payload, or ", _jsx("code", { children: "null" }), " when the token is missing, malformed, signed with another secret, or expired."] }), _jsx(CodeBlock, { title: "Sign and verify", children: `import { signJwt, verifyJwt } from '@basicbenframework/core/auth'
|
|
24
|
+
|
|
25
|
+
// After checking a password
|
|
26
|
+
const token = signJwt(
|
|
27
|
+
{ userId: user.id, role: user.role },
|
|
28
|
+
process.env.APP_KEY,
|
|
29
|
+
{ expiresIn: '7d' }
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
// Later, on an incoming request
|
|
33
|
+
const payload = verifyJwt(token, process.env.APP_KEY)
|
|
34
|
+
|
|
35
|
+
if (!payload) {
|
|
36
|
+
// No token, wrong signature, or expired — treat as signed out
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
payload.userId // 1
|
|
40
|
+
payload.role // 'admin'
|
|
41
|
+
payload.iat // issued at, seconds since the epoch
|
|
42
|
+
payload.exp // expires at, present only when expiresIn was given` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "expiresIn" }), " takes a number of seconds, or a string with a unit:", _jsx("code", { children: "'60s'" }), ", ", _jsx("code", { children: "'5m'" }), ", ", _jsx("code", { children: "'2h'" }), ", ", _jsx("code", { children: "'7d'" }), ". Leave it out and the token never expires, which is rarely what you want. Tokens are signed HS256, and ", _jsx("code", { children: "signJwt" }), " throws when the secret is missing rather than signing with an empty key."] }), _jsx(CodeBlock, { title: "Reading a token without verifying it", children: `import { decodeJwt } from '@basicbenframework/core/auth'
|
|
43
|
+
|
|
44
|
+
// Returns the payload of any well-formed token, signature unchecked
|
|
45
|
+
const payload = decodeJwt(token)` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "decodeJwt" }), " is for logging and debugging \u2014 reading the user id out of an expired token, for instance. It proves nothing about the token, so never make an access decision from its result."] }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "The payload is signed, not encrypted. Anyone holding the token can read it, so put identifiers in it and keep secrets out." })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Registration" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "A registration endpoint validates the input, stores a hash rather than the password, and returns a token so the new user is signed in immediately." }), _jsx(CodeBlock, { title: "src/controllers/AuthController.js", children: `import { query } from '@basicbenframework/core/db'
|
|
46
|
+
import { validate, rules } from '@basicbenframework/core/validation'
|
|
47
|
+
import { hashPassword, signJwt } from '@basicbenframework/core/auth'
|
|
48
|
+
import { ROLES, DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions'
|
|
49
|
+
|
|
50
|
+
export const AuthController = {
|
|
51
|
+
async register(req, res) {
|
|
52
|
+
const result = await validate(req.body, {
|
|
53
|
+
name: [rules.required, rules.min(2)],
|
|
54
|
+
email: [rules.required, rules.email, rules.unique('users')],
|
|
55
|
+
password: [rules.required, rules.min(8)]
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
if (result.fails()) {
|
|
59
|
+
return res.json({ errors: result.errors }, 422)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { name, email, password } = req.body
|
|
63
|
+
|
|
64
|
+
// The first account to register is the operator setting the site up, so it
|
|
65
|
+
// becomes the admin. Everyone after gets the least privileged role.
|
|
66
|
+
const isFirstUser = (await (await query('users')).count()) === 0
|
|
67
|
+
const role = isFirstUser ? ROLES.ADMIN : DEFAULT_ROLE
|
|
68
|
+
|
|
69
|
+
const { lastInsertRowid } = await (await query('users')).insert({
|
|
70
|
+
name,
|
|
71
|
+
email,
|
|
72
|
+
password: await hashPassword(password),
|
|
73
|
+
role
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const token = signJwt({ userId: lastInsertRowid, role }, process.env.APP_KEY, {
|
|
77
|
+
expiresIn: '7d'
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
return res.json({ user: { id: lastInsertRowid, name, email, role }, token }, 201)
|
|
81
|
+
}
|
|
82
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The role is decided on the server from the number of existing users. Never read it out of ", _jsx("code", { children: "req.body" }), " \u2014 that would let anyone register as an administrator."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Login" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "Login looks the user up, compares the password against the stored hash, and issues a token carrying the user id and role." }), _jsx(CodeBlock, { title: "src/controllers/AuthController.js", children: `import { query } from '@basicbenframework/core/db'
|
|
83
|
+
import { verifyPassword, signJwt } from '@basicbenframework/core/auth'
|
|
84
|
+
import { DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions'
|
|
85
|
+
|
|
86
|
+
export const AuthController = {
|
|
87
|
+
async login(req, res) {
|
|
88
|
+
const { email, password } = req.body
|
|
89
|
+
|
|
90
|
+
if (!email || !password) {
|
|
91
|
+
return res.json({ error: 'Email and password required' }, 400)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const user = await (await query('users')).where('email', email).first()
|
|
95
|
+
|
|
96
|
+
// One message for both failures, so the response does not reveal which
|
|
97
|
+
// addresses have accounts.
|
|
98
|
+
if (!user || !(await verifyPassword(password, user.password))) {
|
|
99
|
+
return res.json({ error: 'Invalid credentials' }, 401)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const role = user.role ?? DEFAULT_ROLE
|
|
103
|
+
|
|
104
|
+
const token = signJwt({ userId: user.id, role }, process.env.APP_KEY, {
|
|
105
|
+
expiresIn: '7d'
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
return res.json({
|
|
109
|
+
user: { id: user.id, name: user.name, email: user.email, role },
|
|
110
|
+
token
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "res.json(data, status)" }), " takes the status code as a second argument.", _jsx("code", { children: "res.status(status).json(data)" }), " works too \u2014 use whichever reads better."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Auth Middleware" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["The middleware pulls the token off the ", _jsx("code", { children: "Authorization" }), " header, verifies it, and puts the result on the request. Everything downstream reads ", _jsx("code", { children: "req.user" }), "instead of touching the token again."] }), _jsx(CodeBlock, { title: "src/middleware/auth.js", children: `import { verifyJwt } from '@basicbenframework/core/auth'
|
|
114
|
+
import { DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions'
|
|
115
|
+
|
|
116
|
+
// Named export only, deliberately. See the note below.
|
|
117
|
+
export const auth = async (req, res, next) => {
|
|
118
|
+
const token = req.headers.authorization?.replace('Bearer ', '')
|
|
119
|
+
if (!token) {
|
|
120
|
+
return res.json({ error: 'Unauthorized' }, 401)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const payload = verifyJwt(token, process.env.APP_KEY)
|
|
124
|
+
if (!payload) {
|
|
125
|
+
return res.json({ error: 'Invalid token' }, 401)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
req.userId = payload.userId
|
|
129
|
+
req.user = { id: payload.userId, role: payload.role ?? DEFAULT_ROLE }
|
|
130
|
+
next()
|
|
131
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Export it as ", _jsx("code", { children: "auth" }), ", not as the default. Any ", _jsx("em", { children: "default" }), " export from a file in ", _jsx("code", { children: "src/middleware/" }), " is loaded automatically and applied to every request in the application. Default-exporting this function would therefore demand a valid token for the login endpoint, the registration endpoint, and every public page \u2014 an app that returns 401 to everyone, including the people trying to sign in. Reserve default exports for middleware that genuinely belongs on every request, such as request logging."] }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Verifying a token costs nothing but an HMAC, so this middleware does not touch the database. When a handler needs the full record, load it there from", _jsx("code", { children: "req.userId" }), ". Loading the user on every request also picks up a role change immediately, which the token alone will not do."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Protecting Routes" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "A route file default-exports a function that receives the router. Middleware goes between the path and the handler, and runs before it." }), _jsx(CodeBlock, { title: "src/routes/api/posts.js", children: `import { PostController } from '../../controllers/PostController.js'
|
|
132
|
+
import { auth } from '../../middleware/auth.js'
|
|
133
|
+
|
|
134
|
+
export default (router) => {
|
|
135
|
+
// Public
|
|
136
|
+
router.get('/api/feed', PostController.feed)
|
|
137
|
+
router.get('/api/feed/:id', PostController.feedShow)
|
|
138
|
+
|
|
139
|
+
// Requires a valid token
|
|
140
|
+
router.get('/api/posts', auth, PostController.index)
|
|
141
|
+
router.post('/api/posts', auth, PostController.store)
|
|
142
|
+
router.put('/api/posts/:id', auth, PostController.update)
|
|
143
|
+
router.delete('/api/posts/:id', auth, PostController.destroy)
|
|
144
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["It has to be a function. The loader imports each file under", _jsx("code", { children: "src/routes/" }), " and calls the default export only when it is a function, so a file that default-exports an array of route objects registers nothing and reports no error \u2014 the endpoints simply return 404. If a route you just added cannot be reached, check the shape of the export first."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Roles and Capabilities" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Authentication says who the user is; capabilities say what they may do. Roles ship with a fixed set of capabilities named ", _jsx("code", { children: "resource.action" }), ", and handlers ask about the capability rather than the role \u2014 so the check keeps working if the roles are rearranged later."] }), _jsx("div", { className: "grid gap-2 sm:grid-cols-2", children: [
|
|
145
|
+
{ role: 'admin', desc: 'Everything, including settings, users and API tokens' },
|
|
146
|
+
{ role: 'editor', desc: 'Create, edit, publish and delete any post or page' },
|
|
147
|
+
{ role: 'author', desc: 'Create and publish posts, edit and delete their own' },
|
|
148
|
+
{ role: 'contributor', desc: 'Write and edit their own drafts, but not publish or upload media' },
|
|
149
|
+
{ role: 'subscriber', desc: 'Comment only. The default for new accounts' },
|
|
150
|
+
].map(({ role, desc }) => (_jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("code", { className: "text-sm font-semibold", children: role }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: desc })] }, role))) }), _jsx(CodeBlock, { title: "Checking a capability", children: `import { can } from '@basicbenframework/core/auth/permissions'
|
|
151
|
+
|
|
152
|
+
can(req.user, 'settings.manage') // true only for admin
|
|
153
|
+
can(req.user, 'post.create') // true from contributor upward
|
|
154
|
+
|
|
155
|
+
// Ownership-scoped capabilities need the record being acted on
|
|
156
|
+
can(req.user, 'post.edit', post)` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["A role may hold the ", _jsx("code", { children: ".own" }), " variant of an action instead of the plain one. An author holds ", _jsx("code", { children: "post.edit.own" }), ", so ", _jsx("code", { children: "can(user, 'post.edit', post)" }), "is true for their own post and false for someone else\u2019s. Ownership is read from the record\u2019s ", _jsx("code", { children: "user_id" }), ", ", _jsx("code", { children: "author_id" }), " or ", _jsx("code", { children: "userId" }), ", whichever is present. Without a record to compare against, an ownership-scoped capability cannot be granted, so the check returns false \u2014 pass the resource whenever there is one."] }), _jsx(CodeBlock, { title: "Gating a route on a capability", children: `import { requireCapability, requireRole, ROLES } from '@basicbenframework/core/auth/permissions'
|
|
157
|
+
import { PostController } from '../../controllers/PostController.js'
|
|
158
|
+
import { UserController } from '../../controllers/UserController.js'
|
|
159
|
+
import { auth } from '../../middleware/auth.js'
|
|
160
|
+
import { Post } from '../../models/Post.js'
|
|
161
|
+
|
|
162
|
+
export default (router) => {
|
|
163
|
+
// 403 unless the user may edit this particular post
|
|
164
|
+
router.put(
|
|
165
|
+
'/api/posts/:id',
|
|
166
|
+
auth,
|
|
167
|
+
requireCapability('post.edit', { loadResource: (req) => Post.find(req.params.id) }),
|
|
168
|
+
PostController.update
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
// Role check, where a capability does not fit
|
|
172
|
+
router.get('/api/admin/users', auth, requireRole(ROLES.ADMIN), UserController.index)
|
|
173
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "requireCapability" }), " reads ", _jsx("code", { children: "req.user" }), ", so it always goes after", _jsx("code", { children: "auth" }), ". It answers 401 when there is no user and 403 when the capability is missing. Given a ", _jsx("code", { children: "loadResource" }), " function it loads the record first, answers 404 if there is none, and otherwise leaves it on ", _jsx("code", { children: "req.resource" }), " for the handler \u2014 so the row is fetched once, not twice."] }), _jsx(CodeBlock, { title: "Everything a role holds", children: `import { capabilitiesFor, ROLES, DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions'
|
|
174
|
+
|
|
175
|
+
capabilitiesFor(ROLES.ADMIN)
|
|
176
|
+
// ['*']
|
|
177
|
+
|
|
178
|
+
capabilitiesFor(ROLES.CONTRIBUTOR)
|
|
179
|
+
// ['post.create', 'post.edit.own', 'post.delete.own', 'comment.create']
|
|
180
|
+
|
|
181
|
+
DEFAULT_ROLE
|
|
182
|
+
// 'subscriber'` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The first account to register becomes the admin, on the assumption that it belongs to whoever is setting the site up. Everyone after that gets ", _jsx("code", { children: "DEFAULT_ROLE" }), "."] }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The role travels in the token, which is what makes these checks free. The cost is that promoting or demoting a user changes nothing until their token is reissued. Where that delay matters \u2014 revoking an administrator, say \u2014 reload the user in the handler and pass the fresh record to ", _jsx("code", { children: "can()" }), " rather than trusting", _jsx("code", { children: "req.user" }), "."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "On the Client" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "useAuth" }), " exposes the signed-in user and the two functions that change that state. The token lives in ", _jsx("code", { children: "localStorage" }), " under ", _jsx("code", { children: "token" }), "; on startup the router sends it to ", _jsx("code", { children: "/api/user" }), " to find out who it belongs to, and ", _jsx("code", { children: "loading" }), " is true until that answer arrives."] }), _jsx(CodeBlock, { title: "Reading the current user", children: `import { useAuth } from '@basicbenframework/core/client'
|
|
183
|
+
|
|
184
|
+
export function Profile() {
|
|
185
|
+
const { user, logout, loading } = useAuth()
|
|
186
|
+
|
|
187
|
+
if (loading) return null
|
|
188
|
+
if (!user) return null
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<div>
|
|
192
|
+
<p>{user.name} ({user.role})</p>
|
|
193
|
+
<button onClick={logout}>Sign out</button>
|
|
194
|
+
</div>
|
|
195
|
+
)
|
|
196
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["After a successful login, store the token and hand the user to ", _jsx("code", { children: "setUser" }), ". The ", _jsx("code", { children: "api" }), " helper reads the token back out of ", _jsx("code", { children: "localStorage" }), " and sends it as an ", _jsx("code", { children: "Authorization: Bearer" }), " header on later requests."] }), _jsx(CodeBlock, { title: "Signing in", children: `import { useAuth, useNavigate } from '@basicbenframework/core/client'
|
|
197
|
+
import { api } from '../../helpers/api'
|
|
198
|
+
|
|
199
|
+
export function Login() {
|
|
200
|
+
const { setUser } = useAuth()
|
|
201
|
+
const navigate = useNavigate()
|
|
202
|
+
|
|
203
|
+
const submit = async (e) => {
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
|
|
206
|
+
const data = await api('/api/auth/login', {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
body: JSON.stringify({ email, password })
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
localStorage.setItem('token', data.token)
|
|
212
|
+
setUser(data.user)
|
|
213
|
+
navigate('/')
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ...
|
|
217
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "logout" }), " does the reverse: it clears the token, forgets the user, and returns to the home page."] }), _jsx(CodeBlock, { title: "src/routes/App.jsx", children: `export const App = createClientApp({
|
|
218
|
+
routes: {
|
|
219
|
+
'/': Home,
|
|
220
|
+
|
|
221
|
+
// Signed out only — a signed-in visitor is sent to /
|
|
222
|
+
'/login': { component: Auth, layout: AuthLayout, guest: true },
|
|
223
|
+
'/register': { component: Auth, layout: AuthLayout, guest: true },
|
|
224
|
+
|
|
225
|
+
// Signed in only — a signed-out visitor is sent to /login
|
|
226
|
+
'/posts': { component: Posts, auth: true },
|
|
227
|
+
'/profile': { component: Profile, auth: true }
|
|
228
|
+
}
|
|
229
|
+
})` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["These guards decide what to render, nothing more. They keep a signed-out visitor from landing on a page that has no data to show, but anyone can call your API directly, so every protected route still needs the ", _jsx("code", { children: "auth" }), " middleware on the server."] })] })] })] }));
|
|
230
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Content(): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
3
|
+
import { Card } from "../components/Card.js";
|
|
4
|
+
import { PageHeader } from "../components/PageHeader.js";
|
|
5
|
+
export function Content() {
|
|
6
|
+
const { t } = useTheme();
|
|
7
|
+
const CodeBlock = ({ children, title }) => (_jsxs("div", { className: "mt-4", children: [title && _jsx("div", { className: `text-xs font-medium mb-2 ${t.muted}`, children: title }), _jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${t.card} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: children }) })] }));
|
|
8
|
+
return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Content & Markdown", subtitle: "Posts are written in Markdown, rendered and sanitized on save" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Rendering" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Every table that stores content keeps two columns. ", _jsx("code", { children: "content" }), " holds the Markdown and is canonical; ", _jsx("code", { children: "content_html" }), " holds the rendered, sanitized result. That is the one you render."] }), _jsx(CodeBlock, { title: "The content pipeline", children: `import { renderContent, excerpt, slugify } from '@basicbenframework/core/content'
|
|
9
|
+
|
|
10
|
+
const html = await renderContent('# Title\\n\\nSome **bold** text.')
|
|
11
|
+
const summary = excerpt(markdown, 200) // plain text, cut at a word boundary
|
|
12
|
+
const url = slugify('Hello, World!') // "hello-world"` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Rendering happens on ", _jsx("strong", { children: "save" }), ", not per request \u2014 a blog is read far more often than written. The models do it for you: ", _jsx("code", { children: "Post.create" }), " and", ' ', _jsx("code", { children: "Post.update" }), " re-render whenever ", _jsx("code", { children: "content" }), " changes, so the two columns cannot drift apart."] }), _jsx("div", { className: `mt-4 p-3 rounded-lg border ${t.border} ${t.card}`, children: _jsxs("p", { className: "text-sm", children: [_jsxs("strong", { children: ["Never render ", _jsx("code", { children: "content" }), " as HTML."] }), " It is Markdown.", ' ', _jsx("code", { children: "content_html" }), " is the column that has been through the sanitizer."] }) })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Why there is no Markdown dependency" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["The framework has no runtime dependencies, and this is where that argument usually breaks down: surely hand-writing a parser is an XSS risk. It is the reverse. CommonMark ", _jsx("em", { children: "requires" }), " raw HTML to pass through verbatim \u2014 64 of the spec's 652 cases exist to pin that down \u2014 which is exactly why every off-the-shelf parser tells you to sanitize its output. The dependency introduces the hazard rather than removing it."] }), _jsxs("p", { className: `text-sm ${t.muted}`, children: ["This parser refuses those 64 cases deliberately. It escapes everything it reads and emits only tags from its own vocabulary, so no input can become a tag. The correctness you give up is measured rather than claimed: it passes ", _jsx("strong", { children: "93% of the CommonMark suite" }), " excluding the raw-HTML sections, checked on every test run with a floor that fails the build on regression."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Supported syntax" }), _jsxs("p", { className: `text-sm ${t.muted}`, children: ["Headings (ATX and setext), emphasis, strong, strikethrough, inline code, fenced and indented code blocks, blockquotes, nested and tight/loose lists, links, reference links, images, autolinks, tables, hard line breaks, backslash escapes and HTML entities. Headings get ", _jsx("code", { children: "id" }), " anchors automatically."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Sanitizing other HTML" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "The parser is safe on its own, but imported content is not \u2014 a WordPress export, a a hook's output, a field you deliberately opened up to raw HTML." }), _jsx(CodeBlock, { title: "Allowlist-based sanitization", children: `import { sanitizeHtml } from '@basicbenframework/core/content'
|
|
13
|
+
|
|
14
|
+
sanitizeHtml(imported) // allowlist, drops the rest
|
|
15
|
+
sanitizeHtml(imported, { schemes: ['https'] }) // narrow the URL schemes
|
|
16
|
+
sanitizeHtml(imported, { allowed: { p: [], a: ['href'] } })` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Anything not named is removed. ", _jsx("code", { children: "script" }), ", ", _jsx("code", { children: "style" }), ",", ' ', _jsx("code", { children: "iframe" }), ", ", _jsx("code", { children: "svg" }), " and ", _jsx("code", { children: "math" }), " go with their contents; other unknown tags are unwrapped so their text survives. Event handlers and", ' ', _jsx("code", { children: "style" }), " attributes never pass. URLs are checked after entity decoding, so", ' ', _jsx("code", { children: "javascript:" }), " is caught."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Extending the pipeline" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["A listener post-processes rendered HTML through the ", _jsx("code", { children: "content.render" }), " filter \u2014 syntax highlighting, lazy-loaded images, a table of contents."] }), _jsx(CodeBlock, { title: "Filtering rendered content", children: `hooks.on('content.render', (html, { table, id }) =>
|
|
17
|
+
html.replace(/<code>/g, '<code class="hljs">')
|
|
18
|
+
)` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The filter runs ", _jsx("strong", { children: "before" }), " sanitization, never after \u2014 so no listener can put markup on the page the allowlist has not seen. The practical consequence, and the first thing you will hit writing one: your markup is subject to the allowlist too.", ' ', _jsx("code", { children: "<span class>" }), " and ", _jsx("code", { children: "<code class>" }), " pass;", ' ', _jsx("code", { children: "<p class>" }), " does not, and the attribute will simply be gone. Widen the list rather than moving the filter."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Rerendering" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Stored HTML goes stale when the parser changes, the allowlist changes, or a listener that hooks ", _jsx("code", { children: "content.render" }), " is installed or removed."] }), _jsx(CodeBlock, { title: "Rebuild content_html from the Markdown", children: `basicben content:rerender
|
|
19
|
+
basicben content:rerender posts # just one table
|
|
20
|
+
basicben content:rerender --dry-run` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["It only ever writes ", _jsx("code", { children: "content_html" }), ", so it is safe to run repeatedly."] })] })] })] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Database(): import("react").JSX.Element;
|