@basicbenframework/cms 0.0.0-stage → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +206 -2
- package/db/migrations/001_create_users.js +15 -0
- package/db/migrations/002_create_posts.js +18 -0
- package/db/migrations/003_create_categories.js +19 -0
- package/db/migrations/004_create_tags.js +16 -0
- package/db/migrations/005_create_post_tags.js +16 -0
- package/db/migrations/006_create_pages.js +26 -0
- package/db/migrations/007_create_comments.js +24 -0
- package/db/migrations/008_create_media.js +22 -0
- package/db/migrations/009_update_posts_blogging.js +27 -0
- package/db/migrations/010_create_settings.js +29 -0
- package/db/migrations/011_add_user_roles.js +23 -0
- package/db/migrations/012_create_auth_tokens.js +30 -0
- package/db/migrations/013_add_email_verified.js +24 -0
- package/db/migrations/014_create_user_two_factor.js +30 -0
- package/db/migrations/015_create_user_credentials.js +35 -0
- package/db/migrations/016_create_rate_limits.js +31 -0
- package/db/migrations/017_add_content_html.js +38 -0
- package/db/migrations/018_create_api_tokens.js +34 -0
- package/db/migrations/019_create_post_categories.js +40 -0
- package/db/migrations/020_add_author_profiles.js +60 -0
- package/db/migrations/021_add_page_featured_image.js +23 -0
- package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
- package/db/migrations/023_add_user_session_controls.js +25 -0
- package/db/migrations/024_add_post_status_and_trash.js +45 -0
- package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
- package/db/migrations/026_create_post_revisions.js +29 -0
- package/db/migrations/027_add_media_dimensions.js +19 -0
- package/db/migrations/028_create_navigation_menus.js +65 -0
- package/db/migrations/029_create_redirects.js +40 -0
- package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
- package/db/migrations/031_create_post_locks.js +38 -0
- package/db/migrations/032_create_snippets.js +31 -0
- package/db/migrations/033_create_members.js +70 -0
- package/db/migrations/034_add_post_visibility.js +28 -0
- package/db/migrations/035_create_newsletters.js +72 -0
- package/db/migrations/036_create_analytics.js +89 -0
- package/db/migrations/037_create_ops_heartbeats.js +30 -0
- package/db/migrations/038_create_content_types.js +84 -0
- package/db/migrations/039_create_content_type_fields.js +47 -0
- package/db/migrations/040_create_taxonomies.js +80 -0
- package/db/migrations/041_add_newsletter_handoff.js +28 -0
- package/db/migrations/042_create_mysendbox_contacts.js +63 -0
- package/lib/cli/backup.d.mts +2 -0
- package/lib/cli/backup.mjs +124 -0
- package/lib/cli/export.d.mts +2 -0
- package/lib/cli/export.mjs +54 -0
- package/lib/cli/import-ghost.d.mts +2 -0
- package/lib/cli/import-ghost.mjs +50 -0
- package/lib/cli/import-json.d.mts +2 -0
- package/lib/cli/import-json.mjs +61 -0
- package/lib/cli/import-wordpress.d.mts +2 -0
- package/lib/cli/import-wordpress.mjs +169 -0
- package/lib/cli/import-wxr.d.mts +2 -0
- package/lib/cli/import-wxr.mjs +55 -0
- package/lib/cli/index.d.mts +2 -0
- package/lib/cli/index.mjs +53 -0
- package/lib/cli/lib/backup.d.mts +112 -0
- package/lib/cli/lib/backup.mjs +297 -0
- package/lib/cli/lib/ghost.d.mts +30 -0
- package/lib/cli/lib/ghost.mjs +201 -0
- package/lib/cli/lib/html-to-markdown.d.mts +61 -0
- package/lib/cli/lib/html-to-markdown.mjs +523 -0
- package/lib/cli/lib/import-common.d.mts +100 -0
- package/lib/cli/lib/import-common.mjs +252 -0
- package/lib/cli/lib/json-import.d.mts +22 -0
- package/lib/cli/lib/json-import.mjs +422 -0
- package/lib/cli/lib/site-import.d.mts +32 -0
- package/lib/cli/lib/site-import.mjs +456 -0
- package/lib/cli/lib/wordpress-rest.d.mts +25 -0
- package/lib/cli/lib/wordpress-rest.mjs +177 -0
- package/lib/cli/lib/wxr.d.mts +18 -0
- package/lib/cli/lib/wxr.mjs +307 -0
- package/lib/cli/lib/xml.d.mts +33 -0
- package/lib/cli/lib/xml.mjs +186 -0
- package/lib/cli/restore.d.mts +2 -0
- package/lib/cli/restore.mjs +98 -0
- package/lib/client/components/Alert.d.ts +7 -0
- package/lib/client/components/Alert.js +8 -0
- package/lib/client/components/Avatar.d.ts +15 -0
- package/lib/client/components/Avatar.js +10 -0
- package/lib/client/components/BackLink.d.ts +7 -0
- package/lib/client/components/BackLink.js +6 -0
- package/lib/client/components/Button.d.ts +7 -0
- package/lib/client/components/Button.js +12 -0
- package/lib/client/components/Card.d.ts +7 -0
- package/lib/client/components/Card.js +6 -0
- package/lib/client/components/CommentThread.d.ts +15 -0
- package/lib/client/components/CommentThread.js +101 -0
- package/lib/client/components/Empty.d.ts +6 -0
- package/lib/client/components/Empty.js +6 -0
- package/lib/client/components/Input.d.ts +6 -0
- package/lib/client/components/Input.js +6 -0
- package/lib/client/components/Link.d.ts +31 -0
- package/lib/client/components/Link.js +49 -0
- package/lib/client/components/Loading.d.ts +1 -0
- package/lib/client/components/Loading.js +6 -0
- package/lib/client/components/Logo.d.ts +5 -0
- package/lib/client/components/Logo.js +4 -0
- package/lib/client/components/MarkdownEditor.d.ts +41 -0
- package/lib/client/components/MarkdownEditor.js +156 -0
- package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
- package/lib/client/components/Nav/DarkModeToggle.js +6 -0
- package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
- package/lib/client/components/Nav/DesktopNav.js +9 -0
- package/lib/client/components/Nav/MobileNav.d.ts +9 -0
- package/lib/client/components/Nav/MobileNav.js +15 -0
- package/lib/client/components/NavLink.d.ts +8 -0
- package/lib/client/components/NavLink.js +6 -0
- package/lib/client/components/PageHeader.d.ts +8 -0
- package/lib/client/components/PageHeader.js +6 -0
- package/lib/client/components/PostCard.d.ts +8 -0
- package/lib/client/components/PostCard.js +7 -0
- package/lib/client/components/Textarea.d.ts +6 -0
- package/lib/client/components/Textarea.js +6 -0
- package/lib/client/components/ThemeContext.d.ts +18 -0
- package/lib/client/components/ThemeContext.js +8 -0
- package/lib/client/components/admin/AdminIcons.d.ts +13 -0
- package/lib/client/components/admin/AdminIcons.js +66 -0
- package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
- package/lib/client/components/admin/ContentModelPanels.js +93 -0
- package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
- package/lib/client/components/admin/FeaturedImageBox.js +24 -0
- package/lib/client/components/admin/MediaGrid.d.ts +23 -0
- package/lib/client/components/admin/MediaGrid.js +69 -0
- package/lib/client/components/admin/MediaPicker.d.ts +17 -0
- package/lib/client/components/admin/MediaPicker.js +61 -0
- package/lib/client/components/admin/Pagination.d.ts +27 -0
- package/lib/client/components/admin/Pagination.js +29 -0
- package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
- package/lib/client/components/admin/SnippetPicker.js +65 -0
- package/lib/client/components/admin/TermPicker.d.ts +52 -0
- package/lib/client/components/admin/TermPicker.js +58 -0
- package/lib/client/contexts/ToastContext.d.ts +12 -0
- package/lib/client/contexts/ToastContext.js +49 -0
- package/lib/client/features.d.ts +11 -0
- package/lib/client/features.js +7 -0
- package/lib/client/hooks/useContentTypes.d.ts +48 -0
- package/lib/client/hooks/useContentTypes.js +48 -0
- package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
- package/lib/client/hooks/useMediaLibrary.js +189 -0
- package/lib/client/hooks/usePostLock.d.ts +32 -0
- package/lib/client/hooks/usePostLock.js +107 -0
- package/lib/client/host/index.d.ts +71 -0
- package/lib/client/host/index.js +58 -0
- package/lib/client/i18n/index.d.ts +79 -0
- package/lib/client/i18n/index.js +177 -0
- package/lib/client/i18n/locales/es/content.d.ts +4 -0
- package/lib/client/i18n/locales/es/content.js +220 -0
- package/lib/client/i18n/locales/es/editor.d.ts +9 -0
- package/lib/client/i18n/locales/es/editor.js +144 -0
- package/lib/client/i18n/locales/es/index.d.ts +8 -0
- package/lib/client/i18n/locales/es/index.js +7 -0
- package/lib/client/i18n/locales/es/layout.d.ts +4 -0
- package/lib/client/i18n/locales/es/layout.js +35 -0
- package/lib/client/i18n/locales/es/people.d.ts +4 -0
- package/lib/client/i18n/locales/es/people.js +187 -0
- package/lib/client/i18n/locales/es/site.d.ts +4 -0
- package/lib/client/i18n/locales/es/site.js +208 -0
- package/lib/client/layouts/AdminLayout.d.ts +7 -0
- package/lib/client/layouts/AdminLayout.js +1046 -0
- package/lib/client/layouts/AppLayout.d.ts +6 -0
- package/lib/client/layouts/AppLayout.js +19 -0
- package/lib/client/layouts/AuthLayout.d.ts +6 -0
- package/lib/client/layouts/AuthLayout.js +14 -0
- package/lib/client/layouts/DocsLayout.d.ts +6 -0
- package/lib/client/layouts/DocsLayout.js +28 -0
- package/lib/client/layouts/RootLayout.d.ts +6 -0
- package/lib/client/layouts/RootLayout.js +11 -0
- package/lib/client/pages/AcceptInvite.d.ts +8 -0
- package/lib/client/pages/AcceptInvite.js +60 -0
- package/lib/client/pages/Auth.d.ts +1 -0
- package/lib/client/pages/Auth.js +40 -0
- package/lib/client/pages/Authentication.d.ts +1 -0
- package/lib/client/pages/Authentication.js +230 -0
- package/lib/client/pages/Content.d.ts +1 -0
- package/lib/client/pages/Content.js +21 -0
- package/lib/client/pages/Database.d.ts +1 -0
- package/lib/client/pages/Database.js +264 -0
- package/lib/client/pages/Extending.d.ts +1 -0
- package/lib/client/pages/Extending.js +28 -0
- package/lib/client/pages/Feed.d.ts +1 -0
- package/lib/client/pages/Feed.js +19 -0
- package/lib/client/pages/FeedPost.d.ts +1 -0
- package/lib/client/pages/FeedPost.js +31 -0
- package/lib/client/pages/ForgotPassword.d.ts +8 -0
- package/lib/client/pages/ForgotPassword.js +38 -0
- package/lib/client/pages/GettingStarted.d.ts +1 -0
- package/lib/client/pages/GettingStarted.js +84 -0
- package/lib/client/pages/Headless.d.ts +1 -0
- package/lib/client/pages/Headless.js +49 -0
- package/lib/client/pages/Home.d.ts +1 -0
- package/lib/client/pages/Home.js +67 -0
- package/lib/client/pages/PostForm.d.ts +1 -0
- package/lib/client/pages/PostForm.js +55 -0
- package/lib/client/pages/Posts.d.ts +1 -0
- package/lib/client/pages/Posts.js +35 -0
- package/lib/client/pages/Profile.d.ts +1 -0
- package/lib/client/pages/Profile.js +153 -0
- package/lib/client/pages/ResetPassword.d.ts +8 -0
- package/lib/client/pages/ResetPassword.js +52 -0
- package/lib/client/pages/Routing.d.ts +1 -0
- package/lib/client/pages/Routing.js +192 -0
- package/lib/client/pages/Storage.d.ts +1 -0
- package/lib/client/pages/Storage.js +54 -0
- package/lib/client/pages/Testing.d.ts +1 -0
- package/lib/client/pages/Testing.js +141 -0
- package/lib/client/pages/Validation.d.ts +1 -0
- package/lib/client/pages/Validation.js +123 -0
- package/lib/client/pages/admin/Categories.d.ts +2 -0
- package/lib/client/pages/admin/Categories.js +75 -0
- package/lib/client/pages/admin/Comments.d.ts +11 -0
- package/lib/client/pages/admin/Comments.js +247 -0
- package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
- package/lib/client/pages/admin/ContentTypes.js +163 -0
- package/lib/client/pages/admin/Dashboard.d.ts +2 -0
- package/lib/client/pages/admin/Dashboard.js +66 -0
- package/lib/client/pages/admin/Health.d.ts +12 -0
- package/lib/client/pages/admin/Health.js +148 -0
- package/lib/client/pages/admin/Media.d.ts +2 -0
- package/lib/client/pages/admin/Media.js +101 -0
- package/lib/client/pages/admin/Navigation.d.ts +9 -0
- package/lib/client/pages/admin/Navigation.js +230 -0
- package/lib/client/pages/admin/Pages.d.ts +2 -0
- package/lib/client/pages/admin/Pages.js +53 -0
- package/lib/client/pages/admin/PostEditor.d.ts +17 -0
- package/lib/client/pages/admin/PostEditor.js +532 -0
- package/lib/client/pages/admin/Posts.d.ts +2 -0
- package/lib/client/pages/admin/Posts.js +152 -0
- package/lib/client/pages/admin/Redirects.d.ts +10 -0
- package/lib/client/pages/admin/Redirects.js +87 -0
- package/lib/client/pages/admin/Settings.d.ts +2 -0
- package/lib/client/pages/admin/Settings.js +111 -0
- package/lib/client/pages/admin/Snippets.d.ts +14 -0
- package/lib/client/pages/admin/Snippets.js +85 -0
- package/lib/client/pages/admin/Tags.d.ts +2 -0
- package/lib/client/pages/admin/Tags.js +74 -0
- package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
- package/lib/client/pages/admin/Taxonomies.js +130 -0
- package/lib/client/pages/admin/Tokens.d.ts +9 -0
- package/lib/client/pages/admin/Tokens.js +260 -0
- package/lib/client/pages/admin/Tools.d.ts +12 -0
- package/lib/client/pages/admin/Tools.js +111 -0
- package/lib/client/pages/admin/Users.d.ts +13 -0
- package/lib/client/pages/admin/Users.js +313 -0
- package/lib/client/pages/api-reference.d.ts +33 -0
- package/lib/client/pages/api-reference.js +198 -0
- package/lib/client/styles.css +37 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.js +39 -0
- package/lib/controllers/AdminController.d.ts +46 -0
- package/lib/controllers/AdminController.js +134 -0
- package/lib/controllers/AuthController.d.ts +15 -0
- package/lib/controllers/AuthController.js +194 -0
- package/lib/controllers/AuthorController.d.ts +17 -0
- package/lib/controllers/AuthorController.js +19 -0
- package/lib/controllers/CategoryController.d.ts +10 -0
- package/lib/controllers/CategoryController.js +88 -0
- package/lib/controllers/CommentController.d.ts +68 -0
- package/lib/controllers/CommentController.js +438 -0
- package/lib/controllers/ContentTypeController.d.ts +24 -0
- package/lib/controllers/ContentTypeController.js +91 -0
- package/lib/controllers/EmailVerificationController.d.ts +33 -0
- package/lib/controllers/EmailVerificationController.js +116 -0
- package/lib/controllers/ExportController.d.ts +15 -0
- package/lib/controllers/ExportController.js +41 -0
- package/lib/controllers/FeedController.d.ts +14 -0
- package/lib/controllers/FeedController.js +246 -0
- package/lib/controllers/HealthController.d.ts +21 -0
- package/lib/controllers/HealthController.js +176 -0
- package/lib/controllers/HomeController.d.ts +12 -0
- package/lib/controllers/HomeController.js +16 -0
- package/lib/controllers/MediaController.d.ts +24 -0
- package/lib/controllers/MediaController.js +189 -0
- package/lib/controllers/NavigationController.d.ts +22 -0
- package/lib/controllers/NavigationController.js +176 -0
- package/lib/controllers/PageController.d.ts +13 -0
- package/lib/controllers/PageController.js +172 -0
- package/lib/controllers/PasskeyController.d.ts +36 -0
- package/lib/controllers/PasskeyController.js +201 -0
- package/lib/controllers/PasswordResetController.d.ts +44 -0
- package/lib/controllers/PasswordResetController.js +160 -0
- package/lib/controllers/PostController.d.ts +51 -0
- package/lib/controllers/PostController.js +538 -0
- package/lib/controllers/PostLockController.d.ts +62 -0
- package/lib/controllers/PostLockController.js +101 -0
- package/lib/controllers/ProfileController.d.ts +13 -0
- package/lib/controllers/ProfileController.js +160 -0
- package/lib/controllers/PublicApiController.d.ts +23 -0
- package/lib/controllers/PublicApiController.js +100 -0
- package/lib/controllers/RedirectController.d.ts +32 -0
- package/lib/controllers/RedirectController.js +95 -0
- package/lib/controllers/SettingsController.d.ts +28 -0
- package/lib/controllers/SettingsController.js +105 -0
- package/lib/controllers/SnippetController.d.ts +27 -0
- package/lib/controllers/SnippetController.js +123 -0
- package/lib/controllers/TagController.d.ts +9 -0
- package/lib/controllers/TagController.js +70 -0
- package/lib/controllers/TaxonomyController.d.ts +24 -0
- package/lib/controllers/TaxonomyController.js +149 -0
- package/lib/controllers/TokenController.d.ts +27 -0
- package/lib/controllers/TokenController.js +83 -0
- package/lib/controllers/TwoFactorController.d.ts +31 -0
- package/lib/controllers/TwoFactorController.js +213 -0
- package/lib/controllers/UserController.d.ts +110 -0
- package/lib/controllers/UserController.js +504 -0
- package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
- package/lib/features/analytics/AnalyticsPage.js +123 -0
- package/lib/features/analytics/admin.d.ts +3 -0
- package/lib/features/analytics/admin.js +9 -0
- package/lib/features/analytics/controller.d.ts +19 -0
- package/lib/features/analytics/controller.js +79 -0
- package/lib/features/analytics/helpers.d.ts +84 -0
- package/lib/features/analytics/helpers.js +181 -0
- package/lib/features/analytics/i18n/es.d.ts +4 -0
- package/lib/features/analytics/i18n/es.js +31 -0
- package/lib/features/analytics/index.d.ts +28 -0
- package/lib/features/analytics/index.js +91 -0
- package/lib/features/analytics/manifest.d.ts +8 -0
- package/lib/features/analytics/manifest.js +18 -0
- package/lib/features/analytics/model.d.ts +130 -0
- package/lib/features/analytics/model.js +206 -0
- package/lib/features/members/Member.d.ts +93 -0
- package/lib/features/members/Member.js +194 -0
- package/lib/features/members/MemberAdminController.d.ts +60 -0
- package/lib/features/members/MemberAdminController.js +262 -0
- package/lib/features/members/MemberController.d.ts +88 -0
- package/lib/features/members/MemberController.js +250 -0
- package/lib/features/members/MembersPage.d.ts +10 -0
- package/lib/features/members/MembersPage.js +216 -0
- package/lib/features/members/PostAccessBox.d.ts +15 -0
- package/lib/features/members/PostAccessBox.js +70 -0
- package/lib/features/members/admin.d.ts +3 -0
- package/lib/features/members/admin.js +12 -0
- package/lib/features/members/csv.d.ts +21 -0
- package/lib/features/members/csv.js +74 -0
- package/lib/features/members/events.d.ts +34 -0
- package/lib/features/members/events.js +34 -0
- package/lib/features/members/i18n/es.d.ts +4 -0
- package/lib/features/members/i18n/es.js +106 -0
- package/lib/features/members/index.d.ts +44 -0
- package/lib/features/members/index.js +106 -0
- package/lib/features/members/manifest.d.ts +8 -0
- package/lib/features/members/manifest.js +18 -0
- package/lib/features/members/middleware.d.ts +42 -0
- package/lib/features/members/middleware.js +74 -0
- package/lib/features/members/newsletter.d.ts +177 -0
- package/lib/features/members/newsletter.js +439 -0
- package/lib/features/members/rate-limits.d.ts +34 -0
- package/lib/features/members/rate-limits.js +50 -0
- package/lib/features/members/request.d.ts +13 -0
- package/lib/features/members/request.js +6 -0
- package/lib/features/members/routes.d.ts +15 -0
- package/lib/features/members/routes.js +59 -0
- package/lib/features/members/session.d.ts +102 -0
- package/lib/features/members/session.js +158 -0
- package/lib/features/members/settings.d.ts +14 -0
- package/lib/features/members/settings.js +23 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
- package/lib/features/mysendbox/admin.d.ts +3 -0
- package/lib/features/mysendbox/admin.js +9 -0
- package/lib/features/mysendbox/broadcasts.d.ts +61 -0
- package/lib/features/mysendbox/broadcasts.js +124 -0
- package/lib/features/mysendbox/client.d.ts +95 -0
- package/lib/features/mysendbox/client.js +61 -0
- package/lib/features/mysendbox/config.d.ts +27 -0
- package/lib/features/mysendbox/config.js +74 -0
- package/lib/features/mysendbox/contacts.d.ts +121 -0
- package/lib/features/mysendbox/contacts.js +378 -0
- package/lib/features/mysendbox/controller.d.ts +11 -0
- package/lib/features/mysendbox/controller.js +47 -0
- package/lib/features/mysendbox/i18n/es.d.ts +4 -0
- package/lib/features/mysendbox/i18n/es.js +28 -0
- package/lib/features/mysendbox/index.d.ts +18 -0
- package/lib/features/mysendbox/index.js +71 -0
- package/lib/features/mysendbox/manifest.d.ts +7 -0
- package/lib/features/mysendbox/manifest.js +6 -0
- package/lib/features/mysendbox/routes.d.ts +6 -0
- package/lib/features/mysendbox/routes.js +14 -0
- package/lib/features/mysendbox/webhook.d.ts +23 -0
- package/lib/features/mysendbox/webhook.js +104 -0
- package/lib/features/theme/OEmbedController.d.ts +31 -0
- package/lib/features/theme/OEmbedController.js +128 -0
- package/lib/features/theme/ThemeController.d.ts +20 -0
- package/lib/features/theme/ThemeController.js +256 -0
- package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
- package/lib/features/theme/ThemeSettingsCard.js +12 -0
- package/lib/features/theme/admin.d.ts +3 -0
- package/lib/features/theme/admin.js +9 -0
- package/lib/features/theme/html.d.ts +48 -0
- package/lib/features/theme/html.js +97 -0
- package/lib/features/theme/i18n/es.d.ts +4 -0
- package/lib/features/theme/i18n/es.js +9 -0
- package/lib/features/theme/index.d.ts +11 -0
- package/lib/features/theme/index.js +23 -0
- package/lib/features/theme/manifest.d.ts +7 -0
- package/lib/features/theme/manifest.js +6 -0
- package/lib/features/theme/oembed.d.ts +36 -0
- package/lib/features/theme/oembed.js +58 -0
- package/lib/features/theme/routes.d.ts +17 -0
- package/lib/features/theme/routes.js +54 -0
- package/lib/features/theme/templates.d.ts +103 -0
- package/lib/features/theme/templates.js +283 -0
- package/lib/features.d.ts +15 -0
- package/lib/features.js +6 -0
- package/lib/features.manifest.d.ts +10 -0
- package/lib/features.manifest.js +6 -0
- package/lib/helpers/access.d.ts +62 -0
- package/lib/helpers/access.js +92 -0
- package/lib/helpers/api.d.ts +20 -0
- package/lib/helpers/api.js +44 -0
- package/lib/helpers/comment-guard.d.ts +145 -0
- package/lib/helpers/comment-guard.js +253 -0
- package/lib/helpers/comment-mail.d.ts +53 -0
- package/lib/helpers/comment-mail.js +188 -0
- package/lib/helpers/content-model.d.ts +50 -0
- package/lib/helpers/content-model.js +84 -0
- package/lib/helpers/content-paths.d.ts +107 -0
- package/lib/helpers/content-paths.js +200 -0
- package/lib/helpers/export-data.d.ts +85 -0
- package/lib/helpers/export-data.js +229 -0
- package/lib/helpers/gating.d.ts +53 -0
- package/lib/helpers/gating.js +83 -0
- package/lib/helpers/health.d.ts +91 -0
- package/lib/helpers/health.js +279 -0
- package/lib/helpers/heartbeat.d.ts +35 -0
- package/lib/helpers/heartbeat.js +55 -0
- package/lib/helpers/image-size.d.ts +18 -0
- package/lib/helpers/image-size.js +83 -0
- package/lib/helpers/images.d.ts +29 -0
- package/lib/helpers/images.js +41 -0
- package/lib/helpers/mail-templates.d.ts +11 -0
- package/lib/helpers/mail-templates.js +42 -0
- package/lib/helpers/publish-due.d.ts +28 -0
- package/lib/helpers/publish-due.js +67 -0
- package/lib/helpers/redirects.d.ts +43 -0
- package/lib/helpers/redirects.js +80 -0
- package/lib/helpers/seo-fields.d.ts +13 -0
- package/lib/helpers/seo-fields.js +52 -0
- package/lib/helpers/session.d.ts +30 -0
- package/lib/helpers/session.js +27 -0
- package/lib/helpers/site-settings.d.ts +98 -0
- package/lib/helpers/site-settings.js +232 -0
- package/lib/helpers/site.d.ts +14 -0
- package/lib/helpers/site.js +23 -0
- package/lib/helpers/write-hooks.d.ts +33 -0
- package/lib/helpers/write-hooks.js +37 -0
- package/lib/hooks.d.ts +17 -0
- package/lib/hooks.js +101 -0
- package/lib/host/core-tasks.d.ts +4 -0
- package/lib/host/core-tasks.js +26 -0
- package/lib/host/cron.d.ts +39 -0
- package/lib/host/cron.js +85 -0
- package/lib/host/enabled.d.ts +4 -0
- package/lib/host/enabled.js +40 -0
- package/lib/host/index.d.ts +81 -0
- package/lib/host/index.js +87 -0
- package/lib/host/manifest.d.ts +34 -0
- package/lib/host/manifest.js +7 -0
- package/lib/host/menu.d.ts +18 -0
- package/lib/host/menu.js +15 -0
- package/lib/main.d.ts +1 -0
- package/lib/main.js +24 -0
- package/lib/middleware/api-auth.d.ts +59 -0
- package/lib/middleware/api-auth.js +164 -0
- package/lib/middleware/auth.d.ts +49 -0
- package/lib/middleware/auth.js +112 -0
- package/lib/middleware/cache.d.ts +17 -0
- package/lib/middleware/cache.js +52 -0
- package/lib/middleware/rate-limits.d.ts +199 -0
- package/lib/middleware/rate-limits.js +276 -0
- package/lib/middleware/viewer.d.ts +13 -0
- package/lib/middleware/viewer.js +16 -0
- package/lib/models/Category.d.ts +24 -0
- package/lib/models/Category.js +102 -0
- package/lib/models/Comment.d.ts +120 -0
- package/lib/models/Comment.js +283 -0
- package/lib/models/ContentType.d.ts +142 -0
- package/lib/models/ContentType.js +462 -0
- package/lib/models/Credential.d.ts +21 -0
- package/lib/models/Credential.js +31 -0
- package/lib/models/Media.d.ts +53 -0
- package/lib/models/Media.js +132 -0
- package/lib/models/Menu.d.ts +131 -0
- package/lib/models/Menu.js +312 -0
- package/lib/models/Page.d.ts +55 -0
- package/lib/models/Page.js +218 -0
- package/lib/models/Post.d.ts +136 -0
- package/lib/models/Post.js +406 -0
- package/lib/models/PostLock.d.ts +67 -0
- package/lib/models/PostLock.js +112 -0
- package/lib/models/PostRevision.d.ts +45 -0
- package/lib/models/PostRevision.js +82 -0
- package/lib/models/PublicContent.d.ts +283 -0
- package/lib/models/PublicContent.js +577 -0
- package/lib/models/Redirect.d.ts +123 -0
- package/lib/models/Redirect.js +225 -0
- package/lib/models/Settings.d.ts +61 -0
- package/lib/models/Settings.js +128 -0
- package/lib/models/Snippet.d.ts +36 -0
- package/lib/models/Snippet.js +64 -0
- package/lib/models/Tag.d.ts +23 -0
- package/lib/models/Tag.js +117 -0
- package/lib/models/Taxonomy.d.ts +127 -0
- package/lib/models/Taxonomy.js +321 -0
- package/lib/models/TwoFactor.d.ts +26 -0
- package/lib/models/TwoFactor.js +60 -0
- package/lib/models/User.d.ts +49 -0
- package/lib/models/User.js +128 -0
- package/lib/models/derive.d.ts +69 -0
- package/lib/models/derive.js +81 -0
- package/lib/models/pagination.d.ts +30 -0
- package/lib/models/pagination.js +36 -0
- package/lib/models/visibility.d.ts +31 -0
- package/lib/models/visibility.js +47 -0
- package/lib/routes/App.d.ts +2 -0
- package/lib/routes/App.js +146 -0
- package/lib/routes/api/admin.d.ts +6 -0
- package/lib/routes/api/admin.js +11 -0
- package/lib/routes/api/auth.d.ts +6 -0
- package/lib/routes/api/auth.js +24 -0
- package/lib/routes/api/authors.d.ts +5 -0
- package/lib/routes/api/authors.js +8 -0
- package/lib/routes/api/categories.d.ts +8 -0
- package/lib/routes/api/categories.js +15 -0
- package/lib/routes/api/comments.d.ts +8 -0
- package/lib/routes/api/comments.js +35 -0
- package/lib/routes/api/content-model.d.ts +17 -0
- package/lib/routes/api/content-model.js +67 -0
- package/lib/routes/api/cron.d.ts +6 -0
- package/lib/routes/api/cron.js +9 -0
- package/lib/routes/api/export.d.ts +5 -0
- package/lib/routes/api/export.js +11 -0
- package/lib/routes/api/feed.d.ts +5 -0
- package/lib/routes/api/feed.js +16 -0
- package/lib/routes/api/media.d.ts +8 -0
- package/lib/routes/api/media.js +25 -0
- package/lib/routes/api/navigation.d.ts +12 -0
- package/lib/routes/api/navigation.js +17 -0
- package/lib/routes/api/ops.d.ts +9 -0
- package/lib/routes/api/ops.js +19 -0
- package/lib/routes/api/pages.d.ts +8 -0
- package/lib/routes/api/pages.js +21 -0
- package/lib/routes/api/passkeys.d.ts +7 -0
- package/lib/routes/api/passkeys.js +13 -0
- package/lib/routes/api/posts.d.ts +8 -0
- package/lib/routes/api/posts.js +39 -0
- package/lib/routes/api/profile.d.ts +6 -0
- package/lib/routes/api/profile.js +8 -0
- package/lib/routes/api/redirects.d.ts +12 -0
- package/lib/routes/api/redirects.js +13 -0
- package/lib/routes/api/settings.d.ts +8 -0
- package/lib/routes/api/settings.js +15 -0
- package/lib/routes/api/snippets.d.ts +15 -0
- package/lib/routes/api/snippets.js +16 -0
- package/lib/routes/api/tags.d.ts +8 -0
- package/lib/routes/api/tags.js +14 -0
- package/lib/routes/api/tokens.d.ts +7 -0
- package/lib/routes/api/tokens.js +15 -0
- package/lib/routes/api/two-factor.d.ts +7 -0
- package/lib/routes/api/two-factor.js +15 -0
- package/lib/routes/api/users.d.ts +8 -0
- package/lib/routes/api/users.js +25 -0
- package/lib/routes/api/v1.d.ts +12 -0
- package/lib/routes/api/v1.js +55 -0
- package/lib/routes/api/verification.d.ts +6 -0
- package/lib/routes/api/verification.js +11 -0
- package/lib/server/index.d.ts +24 -0
- package/lib/server/index.js +110 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.js +1 -0
- package/lib/vite.d.ts +2 -0
- package/lib/vite.js +101 -0
- package/mail/comment-moderation.html +27 -0
- package/mail/comment-moderation.txt +13 -0
- package/mail/comment-reply.html +28 -0
- package/mail/comment-reply.txt +14 -0
- package/mail/invitation.html +25 -0
- package/mail/invitation.txt +11 -0
- package/mail/member-magic-link.html +23 -0
- package/mail/member-magic-link.txt +10 -0
- package/mail/newsletter.html +26 -0
- package/mail/newsletter.txt +13 -0
- package/mail/password-reset.html +26 -0
- package/mail/password-reset.txt +10 -0
- package/mail/verify-email.html +25 -0
- package/mail/verify-email.txt +8 -0
- package/package.json +85 -4
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
// Generated from the interfaces in src/models/PublicContent.ts and the routes
|
|
6
|
+
// in src/routes/api/v1.ts. Editing the tables below by hand would put the
|
|
7
|
+
// response shape in two places, and the second one drifts.
|
|
8
|
+
import { ENDPOINTS, QUERY_PARAMS, SHAPES, ENVELOPE } from "./api-reference.js";
|
|
9
|
+
export function Headless() {
|
|
10
|
+
const { t } = useTheme();
|
|
11
|
+
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 }) })] }));
|
|
12
|
+
// Scrolls inside itself rather than widening the page: these tables carry
|
|
13
|
+
// long type signatures and a horizontally scrolling document is worse than a
|
|
14
|
+
// horizontally scrolling table.
|
|
15
|
+
const Table = ({ columns, children }) => (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-left", children: [_jsx("thead", { children: _jsx("tr", { className: `text-xs uppercase tracking-wide ${t.muted}`, children: columns.map((column) => (_jsx("th", { className: "py-2 pr-4 font-medium", children: column }, column))) }) }), _jsx("tbody", { children: children })] }) }));
|
|
16
|
+
return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Headless API", subtitle: "Read this site's content from somewhere else" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "What this is" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["A read-only content API at ", _jsx("code", { children: "/api/v1" }), ", authenticated with tokens rather than logins. The bundled admin and SPA are unchanged \u2014 this sits alongside them, so a blog can be served by the built-in frontend today and by a static site generator later without a rewrite."] }), _jsxs("p", { className: `text-sm ${t.muted}`, children: ["There is no ", _jsx("code", { children: "/api/v1" }), " write surface. The admin API already has one, gated on roles, and a second path to the same mutations is a second place for an authorization bug to live. Programs that write use that admin API with a ", _jsx("code", { children: "content:write" }), ' ', "or ", _jsx("code", { children: "media:write" }), " token, which acts as its owner and can never exceed their role; see ", _jsx("code", { children: "docs/admin-api.md" }), "."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Tokens" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Issue one at ", _jsx("code", { children: "/admin/tokens" }), ". The plaintext is shown once and never again \u2014 only a SHA-256 hash is stored, so a copy of the database does not hand over working credentials. Losing it means issuing another."] }), _jsx(CodeBlock, { title: "Using a token", children: `curl https://example.com/api/v1/posts \\
|
|
17
|
+
-H "Authorization: Bearer bb_..."` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The ", _jsx("code", { children: "bb_" }), " prefix is what lets one ", _jsx("code", { children: "Authorization: Bearer" }), " header carry either a token or a user session \u2014 middleware picks the verifier from the prefix rather than trying both."] }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Scopes: ", _jsx("code", { children: "content:read" }), ", ", _jsx("code", { children: "content:write" }), ", ", _jsx("code", { children: "media:read" }), ",", ' ', _jsx("code", { children: "media:write" }), ". A write scope grants the matching read. A token cannot manage tokens \u2014 otherwise a leaked read-only credential could mint itself a write-scoped one."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Endpoints" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "Every route is a GET, and only published content is returned. The scope is what an API token needs; a signed-in session passes without one." }), _jsx(Table, { columns: ['Path', 'Scope', 'Returns'], children: ENDPOINTS.map((endpoint) => (_jsxs("tr", { className: `border-t ${t.border} align-top`, children: [_jsxs("td", { className: "py-2 pr-4", children: [_jsx("div", { className: "font-mono", children: endpoint.path }), _jsx("div", { className: `text-xs mt-1 ${t.muted}`, children: endpoint.summary })] }), _jsx("td", { className: "py-2 pr-4 font-mono text-xs", children: endpoint.scope }), _jsx("td", { className: "py-2 font-mono text-xs", children: endpoint.collection ? `${endpoint.shape}[]` : endpoint.shape })] }, endpoint.path))) }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: ":slug" }), " also accepts a numeric id, since slugs are nullable on posts."] }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Comments are deliberately absent. That table stores ", _jsx("code", { children: "author_email" }), " for unauthenticated commenters, and a public feed of reader addresses is an incident rather than a feature."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Site, navigation and redirects" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Three more endpoints a front end needs to render a whole site, with the same token scope (", _jsx("code", { children: "content:read" }), "), caching and rate limit as the ones above. They are written here rather than generated, because they come from the settings, menus and redirects models rather than ", _jsx("code", { children: "PublicContent" }), "."] }), _jsxs("ul", { className: `text-sm ${t.muted} space-y-2 list-disc pl-5`, children: [_jsxs("li", { children: [_jsx("code", { children: "GET /api/v1/site" }), " \u2014 name, description, URL, logo, icon, default social image, time zone, locale, and the head and foot code injection. Code injection is admin-authored HTML, deliberately not sanitized: insert it as-is or not at all."] }), _jsxs("li", { children: [_jsx("code", { children: "GET /api/v1/navigation" }), " \u2014 every menu keyed by location (", _jsx("code", { children: "primary" }), ", ", _jsx("code", { children: "secondary" }), ", ", _jsx("code", { children: "footer" }), "), or one with", ' ', _jsx("code", { children: "?location=" }), ". Items linked to a post, page or category carry its current path; a link to something unpublished is left out, with its children."] }), _jsxs("li", { children: [_jsx("code", { children: "GET /api/v1/redirects" }), " \u2014 the whole redirect map, chains resolved to one hop, for a build step or edge middleware. ", _jsx("code", { children: "?path=/old" }), " looks up one path, for front ends that only ask on a 404. A published post or page whose slug changes gets a 301 from its old path automatically."] })] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Query parameters" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "Accepted on the collection routes. Filtering happens in SQL rather than over the page that happened to load \u2014 filtering a page client-side gives an answer that depends on the page size." }), _jsx(Table, { columns: ['Name', 'Meaning'], children: QUERY_PARAMS.map((param) => (_jsxs("tr", { className: `border-t ${t.border} align-top`, children: [_jsx("td", { className: "py-2 pr-4 font-mono text-xs whitespace-nowrap", children: param.name }), _jsx("td", { className: `py-2 text-sm ${t.muted}`, children: param.description })] }, param.name))) }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "?format=markdown" }), " returns the source instead of rendered HTML. Every item reports the ", _jsx("code", { children: "format" }), " it actually carries: a post written before HTML rendering existed has no cached HTML, and the API falls back to Markdown and says so rather than labelling Markdown as HTML for you to inject into a page.", ' ', _jsx("code", { children: "basicben content:rerender" }), " fills the cache."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "What comes back" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["One envelope for everything, so a consumer writes the unwrapping once.", ' ', _jsx("code", { children: "meta.total_pages" }), " is computed for you: ", _jsx("code", { children: "total / per_page" }), " is the sum people get wrong, and an off-by-one there means a paginating client either misses the last page or loops forever on an empty one."] }), _jsx(CodeBlock, { title: "A collection", children: ENVELOPE.collection }), _jsx(CodeBlock, { title: "A single item", children: ENVELOPE.item }), _jsx(CodeBlock, { title: "Anything that failed", children: ENVELOPE.error }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["A missing or unpublished item is a ", _jsx("code", { children: "404" }), "; a missing or insufficiently scoped credential is a ", _jsx("code", { children: "401" }), "; too many requests is a ", _jsx("code", { children: "429" }), ". There is no partial success \u2014 an error body carries ", _jsx("code", { children: "error" }), " and no ", _jsx("code", { children: "data" }), "."] })] }), SHAPES.map((shape) => (_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: shape.name }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: shape.description }), _jsx(Table, { columns: ['Field', 'Type', 'Meaning'], children: shape.fields.map((field) => (_jsxs("tr", { className: `border-t ${t.border} align-top`, children: [_jsx("td", { className: "py-2 pr-4 font-mono text-xs whitespace-nowrap", children: field.name }), _jsx("td", { className: `py-2 pr-4 font-mono text-xs ${t.muted}`, children: field.type }), _jsx("td", { className: `py-2 text-sm ${t.muted}`, children: field.description })] }, field.name))) })] }, shape.name))), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Media URLs" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Every URL the content API returns is absolute, resolved against ", _jsx("code", { children: "APP_URL" }), ". That matters more here than anywhere else in the app: the bundled frontend can resolve", ' ', _jsx("code", { children: "/uploads/x.png" }), " because it is served from the same origin, and a static build on another host cannot \u2014 it would emit markup pointing at its own server."] }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["With the default local driver the app serves those files itself, which works but puts every image request through your Node process. Object storage is the production answer, and ", _jsx("code", { children: "publicUrl" }), " points the URLs at a CDN or custom domain rather than the bucket's own hostname."] }), _jsx(CodeBlock, { title: "basicben.config.js", children: `storage: {
|
|
18
|
+
driver: 's3', // also r2, minio, spaces, b2
|
|
19
|
+
bucket: process.env.S3_BUCKET,
|
|
20
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
|
21
|
+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
|
22
|
+
publicUrl: 'https://cdn.example.com' // what consumers receive
|
|
23
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The API does not refuse to serve media when the local driver is active. Refusing would break the same-origin case, which is legitimate, and would tell a consumer nothing useful \u2014 an absolute URL at least resolves wherever the app is reachable. What it does instead is warn once at the first request if the URL is still relative, which means", ' ', _jsx("code", { children: "APP_URL" }), " is unset."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Public reads" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Off by default: ", _jsx("code", { children: "/api/v1" }), " requires a credential. Set ", _jsx("code", { children: "public_api" }), ' ', "to ", _jsx("code", { children: "true" }), " in settings to serve content anonymously \u2014 appropriate for a site whose content is public anyway, and for letting a browser-side consumer read it without shipping a token to the browser."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Caching" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Every read carries an ", _jsx("code", { children: "ETag" }), " and ", _jsx("code", { children: "Cache-Control" }), ", and a request with ", _jsx("code", { children: "If-None-Match" }), " gets a ", _jsx("code", { children: "304" }), " with no body. A build step that re-fetches the same content repeatedly \u2014 which is what most consumers are \u2014 stops re-downloading it."] }), _jsx(CodeBlock, { children: `curl -H "Authorization: Bearer bb_..." \\
|
|
24
|
+
-H 'If-None-Match: "1b2-uSkhG..."' \\
|
|
25
|
+
https://example.com/api/v1/posts
|
|
26
|
+
# 304, zero bytes` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Static files get the same treatment, plus ", _jsx("code", { children: "Accept-Ranges" }), " and real", ' ', _jsx("code", { children: "206" }), " responses, so media can be seeked and resumed. Previously", ' ', _jsx("code", { children: "Last-Modified" }), " was sent and the ", _jsx("code", { children: "If-Modified-Since" }), " that came back was ignored, so every conditional request was answered with the whole file."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Webhooks" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Add receivers at ", _jsx("code", { children: "/admin/settings" }), ", one URL per line. Each gets a POST when a post, page or media item is created, updated or deleted \u2014 which is what stops a consumer polling."] }), _jsx(CodeBlock, { title: "What arrives", children: `POST /your-hook
|
|
27
|
+
X-BasicBen-Event: post.created
|
|
28
|
+
X-BasicBen-Signature: sha256=<hex>
|
|
29
|
+
X-BasicBen-Timestamp: 1795430400
|
|
30
|
+
|
|
31
|
+
{ "event": "post.created", "id": 7, "slug": "hello", "at": "2026-08-18T…" }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The signature is an HMAC of the timestamp and the exact body (", _jsx("code", { children: '${timestamp}.${body}' }), "), keyed with your ", _jsx("code", { children: "WEBHOOK_SECRET" }), " \u2014 its own secret, never ", _jsx("code", { children: "APP_KEY" }), ", which signs sessions and must not leave the server. With no ", _jsx("code", { children: "WEBHOOK_SECRET" }), " set, nothing is sent. Verify it over the ", _jsx("strong", { children: "raw" }), " bytes \u2014 a body that has been parsed and re-serialised does not reproduce it, because whitespace and number formatting are free to change. That is what ", _jsx("code", { children: "bodyParser" }), "'s ", _jsx("code", { children: "skip" }), " option is for."] }), _jsx(CodeBlock, { title: "Verifying on the receiving end", children: `import { verify } from '@basicbenframework/core/webhooks'
|
|
32
|
+
|
|
33
|
+
// bodyParser({ skip: '/api/webhooks/' }) left the stream unread
|
|
34
|
+
let raw = ''
|
|
35
|
+
for await (const chunk of req) raw += chunk
|
|
36
|
+
|
|
37
|
+
// The signature covers the timestamp too, and verify() refuses one more
|
|
38
|
+
// than five minutes old — a captured delivery cannot be replayed later.
|
|
39
|
+
if (!verify(raw, req.headers['x-basicben-signature'], process.env.WEBHOOK_SECRET, {
|
|
40
|
+
timestamp: req.headers['x-basicben-timestamp']
|
|
41
|
+
})) {
|
|
42
|
+
return res.json({ error: 'Bad signature' }, 401)
|
|
43
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Delivery is ", _jsx("strong", { children: "at-most-once" }), ". A failure is logged and dropped; there is no retry queue, because a durable one needs a table and a worker and this framework has neither \u2014 an in-memory retry loop would lose everything on the next deploy while looking like a guarantee. Treat webhooks as a latency optimisation and poll as the backstop if you cannot miss an event."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Rate limits" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["120 requests a minute, per address. Every response carries", ' ', _jsx("code", { children: "RateLimit-Limit" }), ", ", _jsx("code", { children: "RateLimit-Remaining" }), " and", ' ', _jsx("code", { children: "RateLimit-Reset" }), "; a refused one adds ", _jsx("code", { children: "Retry-After" }), " and a 429."] }), _jsx("p", { className: `text-sm ${t.muted}`, children: "Per-token budgets would be the better accounting \u2014 a build server on a shared CI address would get its own \u2014 but a limiter has to run before authentication, or a flood of fabricated tokens is never limited at all. Before authentication the token is unverified, and keying on an unverified string hands an attacker a fresh budget per fabricated token. So the address it is. The limit is set high enough that sharing one rarely bites: a build fetching a thousand posts at the maximum hundred per page is ten requests." })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "CORS" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["A browser-side consumer on another origin needs an allowlist. The default is", ' ', _jsx("code", { children: "origin: '*'" }), ", which works for public reads but cannot carry credentials."] }), _jsx(CodeBlock, { title: "basicben.config.js", children: `export default {
|
|
44
|
+
cors: {
|
|
45
|
+
origin: ['https://blog.example.com', 'https://staging.example.com'],
|
|
46
|
+
credentials: true
|
|
47
|
+
}
|
|
48
|
+
}` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "origin" }), " takes a string, an array, or a function of the request origin. Setting ", _jsx("code", { children: "'*'" }), " together with ", _jsx("code", { children: "credentials: true" }), " is refused with a warning rather than honoured: browsers reject that pairing outright, so it would break every credentialed request silently. An origin that is not on the list receives no", ' ', _jsx("code", { children: "Access-Control-Allow-Origin" }), " at all, which is what makes the browser refuse it."] })] })] })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Home(): import("react").JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { useAuth, useNavigate } from '@basicbenframework/core/client';
|
|
4
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
5
|
+
import { Card } from "../components/Card.js";
|
|
6
|
+
import { Button } from "../components/Button.js";
|
|
7
|
+
import { Avatar } from "../components/Avatar.js";
|
|
8
|
+
import { Logo } from "../components/Logo.js";
|
|
9
|
+
export function Home() {
|
|
10
|
+
const { user } = useAuth();
|
|
11
|
+
const navigate = useNavigate();
|
|
12
|
+
const { t, dark } = useTheme();
|
|
13
|
+
const [version, setVersion] = useState(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
fetch('https://registry.npmjs.org/@basicbenframework/core/latest')
|
|
16
|
+
.then(res => res.json())
|
|
17
|
+
.then(data => setVersion(data.version))
|
|
18
|
+
.catch(() => { });
|
|
19
|
+
}, []);
|
|
20
|
+
const features = [
|
|
21
|
+
{
|
|
22
|
+
icon: (_jsx("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" }) })),
|
|
23
|
+
title: 'Zero Dependencies',
|
|
24
|
+
desc: 'No runtime deps. HTTP server, router, JWT, validation — all written from scratch using Node.js built-ins.'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
icon: (_jsx("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" }) })),
|
|
28
|
+
title: 'Laravel-Inspired DX',
|
|
29
|
+
desc: 'Migrations, controllers, models, and scaffolding commands. Familiar conventions without the magic.'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
icon: (_jsx("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z" }) })),
|
|
33
|
+
title: 'No Lock-in',
|
|
34
|
+
desc: 'Just React, Node.js, and Vite. You own your stack. Eject anytime — your code is still your code.'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
icon: (_jsxs("svg", { className: "w-5 h-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: [_jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" }), _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "M15 12a3 3 0 11-6 0 3 3 0 016 0z" })] })),
|
|
38
|
+
title: 'Escape Hatches',
|
|
39
|
+
desc: 'Every convention can be overridden via basicben.config.js. Use what works, change what doesn\'t.'
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
const comparisons = [
|
|
43
|
+
{ name: 'Next.js / Remix', issue: 'Too much magic, vendor lock-in' },
|
|
44
|
+
{ name: 'Express + Vite', issue: 'Wire everything yourself' },
|
|
45
|
+
{ name: 'BasicBen', issue: 'Conventions + control', highlight: true }
|
|
46
|
+
];
|
|
47
|
+
const builtIns = [
|
|
48
|
+
'JWT authentication',
|
|
49
|
+
'Password hashing',
|
|
50
|
+
'Request validation',
|
|
51
|
+
'Database migrations',
|
|
52
|
+
'Auto-loading routes',
|
|
53
|
+
'CLI scaffolding'
|
|
54
|
+
];
|
|
55
|
+
return (_jsxs("div", { className: "space-y-16 py-8", children: [_jsxs("section", { className: "text-center", children: [_jsx("div", { className: "flex justify-center mb-6", children: _jsx(Logo, { className: "w-16 h-16" }) }), _jsx("p", { className: `text-xs ${t.muted} mb-3 tracking-wide uppercase`, children: "Full-stack React Framework" }), _jsx("h1", { className: "text-4xl sm:text-5xl font-bold tracking-tight mb-4", children: "Ship faster with less" }), _jsx("p", { className: `${t.muted} max-w-lg mx-auto mb-8 text-lg`, children: "A productive, convention-driven framework for React apps. Zero runtime dependencies. Maximum clarity." }), _jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsxs("div", { className: `px-4 py-3 rounded-lg ${t.card} border ${t.border} font-mono text-sm`, children: [_jsx("span", { className: t.muted, children: "$" }), " npx @basicbenframework/create my-app"] }), _jsxs("div", { className: "flex gap-3", children: [_jsx(Button, { onClick: () => navigate('/docs'), children: "Get Started" }), _jsx(Button, { variant: "secondary", onClick: () => window.open('https://github.com/BasicBenFramework/core', '_blank'), children: "GitHub" })] })] })] }), _jsxs("section", { children: [_jsx("h2", { className: `text-center text-sm font-medium uppercase tracking-wider ${t.muted} mb-6`, children: "The Problem" }), _jsx(Card, { children: _jsx("div", { className: "space-y-3", children: comparisons.map(({ name, issue, highlight }) => (_jsxs("div", { className: `flex items-center justify-between p-3 rounded-lg ${highlight
|
|
56
|
+
? `${dark ? 'bg-white/10' : 'bg-black/10'} border ${t.border}`
|
|
57
|
+
: ''}`, children: [_jsx("span", { className: `font-medium ${highlight ? '' : t.muted}`, children: name }), _jsxs("span", { className: `text-sm ${highlight ? (dark ? 'text-green-400' : 'text-green-600') : t.muted}`, children: [highlight ? '✓ ' : '', issue] })] }, name))) }) })] }), _jsxs("section", { children: [_jsx("h2", { className: `text-center text-sm font-medium uppercase tracking-wider ${t.muted} mb-6`, children: "Why BasicBen" }), _jsx("div", { className: "grid gap-4 sm:grid-cols-2", children: features.map(({ icon, title, desc }) => (_jsxs(Card, { className: "hover:border-opacity-50 transition", children: [_jsx("div", { className: `inline-flex p-2 rounded-lg ${t.card} border ${t.border} mb-3`, children: icon }), _jsx("h3", { className: "font-semibold mb-1", children: title }), _jsx("p", { className: `text-sm ${t.muted}`, children: desc })] }, title))) })] }), _jsxs("section", { children: [_jsx("h2", { className: `text-center text-sm font-medium uppercase tracking-wider ${t.muted} mb-6`, children: "Batteries Included" }), _jsxs(Card, { children: [_jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "Everything you need to build a production app, without pulling in a dozen packages." }), _jsx("div", { className: "grid grid-cols-2 sm:grid-cols-3 gap-2", children: builtIns.map(item => (_jsxs("div", { className: `flex items-center gap-2 px-3 py-2 rounded-lg ${t.card} border ${t.border} text-sm`, children: [_jsx("svg", { className: `w-4 h-4 flex-shrink-0 ${dark ? 'text-green-400' : 'text-green-600'}`, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }), _jsx("span", { children: item })] }, item))) })] })] }), _jsxs("section", { children: [_jsx("h2", { className: `text-center text-sm font-medium uppercase tracking-wider ${t.muted} mb-6`, children: "Clean & Simple" }), _jsxs(Card, { children: [_jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${dark ? 'bg-black/50' : 'bg-black/5'} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: `// src/routes/posts.js
|
|
58
|
+
import { PostController } from '../controllers/PostController.js'
|
|
59
|
+
import { auth } from '../middleware/auth.js'
|
|
60
|
+
|
|
61
|
+
export default (router) => {
|
|
62
|
+
router.get('/api/posts', PostController.index)
|
|
63
|
+
router.post('/api/posts', auth, PostController.store)
|
|
64
|
+
router.put('/api/posts/:id', auth, PostController.update)
|
|
65
|
+
router.delete('/api/posts/:id', auth, PostController.destroy)
|
|
66
|
+
}` }) }), _jsx("p", { className: `text-sm ${t.muted} mt-3`, children: "Routes are auto-loaded. Controllers are plain objects. Middleware is just a function. No decorators, no magic." })] })] }), user && (_jsx(Card, { children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx(Avatar, { name: user.name }), _jsxs("div", { children: [_jsx("p", { className: "font-medium text-sm", children: user.name }), _jsx("p", { className: `text-xs ${t.muted}`, children: user.email })] })] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { variant: "secondary", onClick: () => navigate('/posts'), className: "text-xs px-3 py-1.5", children: "My Posts" }), _jsx(Button, { variant: "secondary", onClick: () => navigate('/profile'), className: "text-xs px-3 py-1.5", children: "Profile" })] })] }) })), _jsxs("footer", { className: `text-center text-xs ${t.muted} space-y-1`, children: [_jsx("p", { children: "Built with Node.js built-ins. Inspired by Laravel." }), version && _jsxs("p", { children: ["BasicBen v", version] })] })] }));
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function PostForm(): import("react").JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { useNavigate, useParams } from '@basicbenframework/core/client';
|
|
4
|
+
import { PageHeader } from "../components/PageHeader.js";
|
|
5
|
+
import { BackLink } from "../components/BackLink.js";
|
|
6
|
+
import { Input } from "../components/Input.js";
|
|
7
|
+
import { Textarea } from "../components/Textarea.js";
|
|
8
|
+
import { Button } from "../components/Button.js";
|
|
9
|
+
import { Loading } from "../components/Loading.js";
|
|
10
|
+
import { api } from "../../helpers/api.js";
|
|
11
|
+
import { useToast } from "../contexts/ToastContext.js";
|
|
12
|
+
export function PostForm() {
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const params = useParams();
|
|
15
|
+
const postId = params.id;
|
|
16
|
+
const toast = useToast();
|
|
17
|
+
const [form, setForm] = useState({ title: '', content: '', published: false });
|
|
18
|
+
const [loading, setLoading] = useState(!!postId);
|
|
19
|
+
const [saving, setSaving] = useState(false);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (postId) {
|
|
22
|
+
api(`/api/posts/${postId}`)
|
|
23
|
+
.then(data => setForm({ title: data.post.title, content: data.post.content, published: !!data.post.published }))
|
|
24
|
+
.catch(err => {
|
|
25
|
+
toast.error(err.message);
|
|
26
|
+
navigate('/posts');
|
|
27
|
+
})
|
|
28
|
+
.finally(() => setLoading(false));
|
|
29
|
+
}
|
|
30
|
+
}, [postId]);
|
|
31
|
+
const handleSubmit = async (e) => {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
setSaving(true);
|
|
34
|
+
try {
|
|
35
|
+
if (postId) {
|
|
36
|
+
await api(`/api/posts/${postId}`, { method: 'PUT', body: JSON.stringify(form) });
|
|
37
|
+
toast.success('Post updated');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await api('/api/posts', { method: 'POST', body: JSON.stringify(form) });
|
|
41
|
+
toast.success('Post created');
|
|
42
|
+
}
|
|
43
|
+
navigate('/posts');
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
toast.error(err.message);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
setSaving(false);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (loading)
|
|
53
|
+
return _jsx(Loading, {});
|
|
54
|
+
return (_jsxs("div", { className: "max-w-xl mx-auto", children: [_jsx(BackLink, { onClick: () => navigate('/posts'), children: "Back to posts" }), _jsx(PageHeader, { title: postId ? 'Edit Post' : 'New Post' }), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-4 mt-4", children: [_jsx(Input, { placeholder: "Title", required: true, value: form.title, onChange: (e) => setForm({ ...form, title: e.target.value }) }), _jsx(Textarea, { placeholder: "Write your post content...", required: true, rows: 10, value: form.content, onChange: (e) => setForm({ ...form, content: e.target.value }) }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: form.published, onChange: (e) => setForm({ ...form, published: e.target.checked }), className: "rounded" }), "Publish this post"] }), _jsx(Button, { type: "submit", disabled: saving, className: "w-full", children: saving ? '...' : postId ? 'Update Post' : 'Create Post' })] })] }));
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Posts(): import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { useNavigate } from '@basicbenframework/core/client';
|
|
4
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
5
|
+
import { PageHeader } from "../components/PageHeader.js";
|
|
6
|
+
import { Card } from "../components/Card.js";
|
|
7
|
+
import { Button } from "../components/Button.js";
|
|
8
|
+
import { Loading } from "../components/Loading.js";
|
|
9
|
+
import { Empty } from "../components/Empty.js";
|
|
10
|
+
import { api } from "../../helpers/api.js";
|
|
11
|
+
import { useToast } from "../contexts/ToastContext.js";
|
|
12
|
+
export function Posts() {
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const { t } = useTheme();
|
|
15
|
+
const toast = useToast();
|
|
16
|
+
const [posts, setPosts] = useState([]);
|
|
17
|
+
const [loading, setLoading] = useState(true);
|
|
18
|
+
const loadPosts = () => api('/api/posts').then(data => setPosts(data.posts)).finally(() => setLoading(false));
|
|
19
|
+
useEffect(() => { loadPosts(); }, []);
|
|
20
|
+
const deletePost = async (id) => {
|
|
21
|
+
if (!confirm('Delete this post?'))
|
|
22
|
+
return;
|
|
23
|
+
try {
|
|
24
|
+
await api(`/api/posts/${id}`, { method: 'DELETE' });
|
|
25
|
+
toast.success('Post deleted');
|
|
26
|
+
loadPosts();
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
toast.error(err.message);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (loading)
|
|
33
|
+
return _jsx(Loading, {});
|
|
34
|
+
return (_jsxs("div", { children: [_jsx(PageHeader, { title: "My Posts", action: _jsx(Button, { onClick: () => navigate('/posts/new'), children: "New Post" }) }), posts.length === 0 ? (_jsx(Empty, { children: "No posts yet. Create your first one!" })) : (_jsx("div", { className: "space-y-3", children: posts.map(post => (_jsxs(Card, { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex-1 min-w-0 mr-4", children: [_jsx("h2", { className: "font-medium truncate", children: post.title }), _jsxs("p", { className: `text-xs ${t.muted}`, children: [post.published ? 'Published' : 'Draft', " \u2022 ", new Date(post.created_at).toLocaleDateString()] })] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { variant: "secondary", onClick: () => navigate(`/posts/${post.id}/edit`), className: "text-xs px-3 py-1.5", children: "Edit" }), _jsx(Button, { variant: "danger", onClick: () => deletePost(post.id), className: "text-xs px-3 py-1.5", children: "Delete" })] })] }, post.id))) }))] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Profile(): import("react").JSX.Element;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import { useAuth } from '@basicbenframework/core/client';
|
|
4
|
+
import { PageHeader } from "../components/PageHeader.js";
|
|
5
|
+
import { Card } from "../components/Card.js";
|
|
6
|
+
import { Input } from "../components/Input.js";
|
|
7
|
+
import { Textarea } from "../components/Textarea.js";
|
|
8
|
+
import { Button } from "../components/Button.js";
|
|
9
|
+
import { Avatar } from "../components/Avatar.js";
|
|
10
|
+
import { api } from "../../helpers/api.js";
|
|
11
|
+
import { useMediaLibrary } from "../hooks/useMediaLibrary.js";
|
|
12
|
+
import { useToast } from "../contexts/ToastContext.js";
|
|
13
|
+
import { useTheme } from "../components/ThemeContext.js";
|
|
14
|
+
import { useT, ADMIN_LOCALES, localeOverride, chooseLocale, applySiteLocale } from "../i18n/index.js";
|
|
15
|
+
export function Profile() {
|
|
16
|
+
const { user, setUser } = useAuth();
|
|
17
|
+
const toast = useToast();
|
|
18
|
+
const { t: theme } = useTheme();
|
|
19
|
+
const { t } = useT();
|
|
20
|
+
const library = useMediaLibrary();
|
|
21
|
+
const fileInput = useRef(null);
|
|
22
|
+
const [form, setForm] = useState({
|
|
23
|
+
name: user?.name || '',
|
|
24
|
+
email: user?.email || '',
|
|
25
|
+
slug: '',
|
|
26
|
+
website: '',
|
|
27
|
+
bio: ''
|
|
28
|
+
});
|
|
29
|
+
const [avatar, setAvatar] = useState({
|
|
30
|
+
id: null,
|
|
31
|
+
url: null
|
|
32
|
+
});
|
|
33
|
+
const [pwForm, setPwForm] = useState({ currentPassword: '', newPassword: '' });
|
|
34
|
+
// The address the account has now, to tell whether the form is changing it.
|
|
35
|
+
const [savedEmail, setSavedEmail] = useState(user?.email || '');
|
|
36
|
+
const [emailPassword, setEmailPassword] = useState('');
|
|
37
|
+
const [loading, setLoading] = useState(false);
|
|
38
|
+
const [uploading, setUploading] = useState(false);
|
|
39
|
+
// This browser's admin language; '' follows the site's setting.
|
|
40
|
+
const [adminLocale, setAdminLocale] = useState(() => localeOverride() ?? '');
|
|
41
|
+
const [siteLocale, setSiteLocale] = useState(null);
|
|
42
|
+
// `useAuth` carries the name and the address and nothing else, so the profile
|
|
43
|
+
// is fetched rather than assumed — otherwise the first save would post empty
|
|
44
|
+
// strings over a biography the user had already written.
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
api('/api/profile')
|
|
47
|
+
.then(data => {
|
|
48
|
+
setForm({
|
|
49
|
+
name: data.user.name || '',
|
|
50
|
+
email: data.user.email || '',
|
|
51
|
+
slug: data.user.slug || '',
|
|
52
|
+
website: data.user.website || '',
|
|
53
|
+
bio: data.user.bio || ''
|
|
54
|
+
});
|
|
55
|
+
setAvatar({ id: data.user.avatar_id ?? null, url: data.user.avatar_url ?? null });
|
|
56
|
+
setSavedEmail(data.user.email || '');
|
|
57
|
+
})
|
|
58
|
+
.catch(() => {
|
|
59
|
+
// The form still works from what the session knows; a failed profile
|
|
60
|
+
// read should not leave the page blank.
|
|
61
|
+
});
|
|
62
|
+
}, []);
|
|
63
|
+
// The site's admin language, so "Site default" goes back to it rather than
|
|
64
|
+
// to English.
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
api('/api/admin/menu')
|
|
67
|
+
.then(data => {
|
|
68
|
+
setSiteLocale(data?.locale ?? null);
|
|
69
|
+
// This page may render outside the admin layout, which is what
|
|
70
|
+
// otherwise applies the site's language.
|
|
71
|
+
void applySiteLocale(data?.locale);
|
|
72
|
+
})
|
|
73
|
+
.catch(() => { });
|
|
74
|
+
}, []);
|
|
75
|
+
const changeAdminLocale = (e) => {
|
|
76
|
+
const value = e.target.value;
|
|
77
|
+
setAdminLocale(value);
|
|
78
|
+
void chooseLocale(value || null, siteLocale);
|
|
79
|
+
};
|
|
80
|
+
const updateProfile = async (e) => {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
setLoading(true);
|
|
83
|
+
try {
|
|
84
|
+
const data = await api('/api/profile', {
|
|
85
|
+
method: 'PUT',
|
|
86
|
+
body: JSON.stringify({
|
|
87
|
+
...form,
|
|
88
|
+
avatar_id: avatar.id,
|
|
89
|
+
...(form.email !== savedEmail ? { currentPassword: emailPassword } : {})
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
const changed = data.emailChanged;
|
|
93
|
+
setUser({ ...user, ...data.user, ...(changed ? { email_verified: false } : {}) });
|
|
94
|
+
setForm(prev => ({ ...prev, slug: data.user.slug || prev.slug }));
|
|
95
|
+
setSavedEmail(data.user.email || '');
|
|
96
|
+
setEmailPassword('');
|
|
97
|
+
toast.success(changed ? t('Profile updated — check your new address for a verification link') : t('Profile updated'));
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
toast.error(err.message);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
setLoading(false);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Upload a picture and use it.
|
|
108
|
+
*
|
|
109
|
+
* The same three-step upload the media library runs — sign, PUT to storage,
|
|
110
|
+
* confirm — because an avatar is a media row like any other and a second
|
|
111
|
+
* upload path would drift from this one the first time either changed.
|
|
112
|
+
*/
|
|
113
|
+
const chooseAvatar = async (event) => {
|
|
114
|
+
const file = event.target.files?.[0];
|
|
115
|
+
event.target.value = '';
|
|
116
|
+
if (!file)
|
|
117
|
+
return;
|
|
118
|
+
setUploading(true);
|
|
119
|
+
try {
|
|
120
|
+
const [uploaded] = await library.upload([file]);
|
|
121
|
+
if (!uploaded)
|
|
122
|
+
throw new Error(t('The upload did not complete.'));
|
|
123
|
+
setAvatar({ id: uploaded.id, url: uploaded.url || uploaded.path });
|
|
124
|
+
toast.success(t('Picture uploaded — save to keep it'));
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
toast.error(err.message);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
setUploading(false);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const changePassword = async (e) => {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
setLoading(true);
|
|
136
|
+
try {
|
|
137
|
+
const data = await api('/api/profile/password', { method: 'PUT', body: JSON.stringify(pwForm) });
|
|
138
|
+
// Changing the password ends every session, this one included; the
|
|
139
|
+
// response carries its replacement.
|
|
140
|
+
if (data?.token)
|
|
141
|
+
localStorage.setItem('token', data.token);
|
|
142
|
+
setPwForm({ currentPassword: '', newPassword: '' });
|
|
143
|
+
toast.success(t('Password changed'));
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
toast.error(err.message);
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
setLoading(false);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
return (_jsxs("div", { className: "max-w-md mx-auto space-y-6", children: [_jsx(PageHeader, { title: t('Profile') }), _jsx(Card, { children: _jsxs("form", { onSubmit: updateProfile, className: "space-y-3", children: [_jsx("h2", { className: "font-medium mb-2", children: t('Author profile') }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsx(Avatar, { name: form.name, src: avatar.url, size: "lg" }), _jsxs("div", { className: "space-y-1", children: [_jsx("input", { ref: fileInput, type: "file", accept: "image/*", className: "hidden", onChange: chooseAvatar }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", onClick: () => fileInput.current?.click(), disabled: uploading, children: uploading ? t('Uploading...') : avatar.url ? t('Change picture') : t('Add picture') }), avatar.url && (_jsx(Button, { type: "button", onClick: () => setAvatar({ id: null, url: null }), children: t('Remove') }))] }), _jsx("p", { className: `text-xs ${theme.muted}`, children: t('Shown on every post you write.') })] })] }), _jsx(Input, { placeholder: t('Name'), required: true, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) }), _jsx(Input, { type: "email", placeholder: t('Email'), required: true, value: form.email, onChange: (e) => setForm({ ...form, email: e.target.value }) }), form.email !== savedEmail && (_jsx(Input, { type: "password", placeholder: t('Current password, to change your email'), required: true, value: emailPassword, onChange: (e) => setEmailPassword(e.target.value) })), _jsx(Input, { placeholder: t('Profile URL — leave blank to use your name'), value: form.slug, onChange: (e) => setForm({ ...form, slug: e.target.value }) }), _jsx(Input, { type: "url", placeholder: t('Website'), value: form.website, onChange: (e) => setForm({ ...form, website: e.target.value }) }), _jsx(Textarea, { rows: 4, placeholder: t('A short biography, shown under your byline'), value: form.bio, onChange: (e) => setForm({ ...form, bio: e.target.value }) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : t('Save') })] }) }), _jsx(Card, { children: _jsxs("form", { onSubmit: changePassword, className: "space-y-3", children: [_jsx("h2", { className: "font-medium mb-2", children: t('Change Password') }), _jsx(Input, { type: "password", placeholder: t('Current password'), required: true, value: pwForm.currentPassword, onChange: (e) => setPwForm({ ...pwForm, currentPassword: e.target.value }) }), _jsx(Input, { type: "password", placeholder: t('New password'), required: true, minLength: 8, value: pwForm.newPassword, onChange: (e) => setPwForm({ ...pwForm, newPassword: e.target.value }) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : t('Change Password') })] }) }), _jsx(Card, { children: _jsxs("div", { className: "space-y-2", children: [_jsx("label", { htmlFor: "admin-locale", className: "font-medium block", children: t('Admin language') }), _jsxs("select", { id: "admin-locale", className: `w-full px-3 py-2 text-sm rounded-lg ${theme.card} border ${theme.border} focus:outline-none`, value: adminLocale, onChange: changeAdminLocale, children: [_jsx("option", { value: "", children: t('Site default') }), ADMIN_LOCALES.map(entry => _jsx("option", { value: entry.code, children: entry.name }, entry.code))] }), _jsx("p", { className: `text-xs ${theme.muted}`, children: t('Only on this browser. Leave on the site default to follow the site\'s setting.') })] }) })] }));
|
|
153
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choose a new password from an emailed link.
|
|
3
|
+
*
|
|
4
|
+
* Signs straight in when the server hands back a session. An account with a
|
|
5
|
+
* second factor gets no session from a reset — the mailbox is one factor —
|
|
6
|
+
* so it is sent to sign in, where the second factor is asked for as usual.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ResetPassword(): import("react").JSX.Element;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } 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
|
+
* Choose a new password from an emailed link.
|
|
11
|
+
*
|
|
12
|
+
* Signs straight in when the server hands back a session. An account with a
|
|
13
|
+
* second factor gets no session from a reset — the mailbox is one factor —
|
|
14
|
+
* so it is sent to sign in, where the second factor is asked for as usual.
|
|
15
|
+
*/
|
|
16
|
+
export function ResetPassword() {
|
|
17
|
+
const { setUser } = useAuth();
|
|
18
|
+
const navigate = useNavigate();
|
|
19
|
+
const params = useParams();
|
|
20
|
+
const { t } = useTheme();
|
|
21
|
+
const toast = useToast();
|
|
22
|
+
const [password, setPassword] = useState('');
|
|
23
|
+
const [confirmation, setConfirmation] = useState('');
|
|
24
|
+
const [loading, setLoading] = useState(false);
|
|
25
|
+
const handleSubmit = async (e) => {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
if (password !== confirmation) {
|
|
28
|
+
toast.error('The passwords do not match.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
setLoading(true);
|
|
32
|
+
try {
|
|
33
|
+
const data = await api.post('/api/auth/reset-password', { token: params.token, password });
|
|
34
|
+
if (data.token && data.user) {
|
|
35
|
+
localStorage.setItem('token', data.token);
|
|
36
|
+
setUser(data.user);
|
|
37
|
+
toast.success(data.message);
|
|
38
|
+
navigate('/');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
toast.success(data.message);
|
|
42
|
+
navigate('/login');
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
toast.error(err.message);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return (_jsxs("div", { className: "max-w-xs mx-auto py-8", children: [_jsx("h1", { className: "text-2xl font-bold text-center mb-1", children: "Choose a new password" }), _jsx("p", { className: `text-sm ${t.muted} text-center mb-6`, children: "This signs you out on every other device" }), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-3 mt-4", children: [_jsx(Input, { type: "password", placeholder: "New password", required: true, minLength: 8, autoComplete: "new-password", value: password, onChange: (e) => setPassword(e.target.value) }), _jsx(Input, { type: "password", placeholder: "Confirm new password", required: true, minLength: 8, autoComplete: "new-password", value: confirmation, onChange: (e) => setConfirmation(e.target.value) }), _jsx(Button, { type: "submit", disabled: loading, className: "w-full", children: loading ? '...' : 'Set password' })] }), _jsx("p", { className: `text-xs ${t.muted} text-center mt-4`, children: _jsx("button", { onClick: () => navigate('/forgot-password'), className: "underline hover:no-underline", children: "Need a new link?" }) })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Routing(): import("react").JSX.Element;
|