@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,27 @@
|
|
|
1
|
+
import { type SnippetRow } from '../models/Snippet.ts';
|
|
2
|
+
import type { Request, Response } from '../types/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Who may use snippets at all: authors and up.
|
|
5
|
+
*
|
|
6
|
+
* There is no snippet capability in the framework's role table, so this is
|
|
7
|
+
* expressed through the nearest one that draws the same line — `post.publish`
|
|
8
|
+
* is what an author has and a contributor does not. A contributor writes drafts
|
|
9
|
+
* for someone else to review; a shared library of site-wide boilerplate (the
|
|
10
|
+
* legal disclosure, the sign-off) is for the people who put posts live.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mayUseSnippets(user: Request['user']): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Who may change or delete this snippet: whoever wrote it, or an editor.
|
|
15
|
+
*
|
|
16
|
+
* `post.edit` (without `.own`) is the editor's "anyone's work" capability, so
|
|
17
|
+
* it is the same rule as posts: authors look after their own, editors look
|
|
18
|
+
* after everyone's.
|
|
19
|
+
*/
|
|
20
|
+
export declare function mayManageSnippet(user: Request['user'], snippet: Pick<SnippetRow, 'created_by'>): boolean;
|
|
21
|
+
export declare const SnippetController: {
|
|
22
|
+
index(req: Request, res: Response): Promise<void>;
|
|
23
|
+
show(req: Request, res: Response): Promise<void>;
|
|
24
|
+
store(req: Request, res: Response): Promise<void>;
|
|
25
|
+
update(req: Request, res: Response): Promise<void>;
|
|
26
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { can } from '@basicbenframework/core/auth/permissions';
|
|
2
|
+
// Extensions on these imports so the controller loads under plain Node too,
|
|
3
|
+
// which is how tests/phase2-api-editing.test.js exercises it.
|
|
4
|
+
import { Snippet } from "../models/Snippet.js";
|
|
5
|
+
const NAME_MAX = 100;
|
|
6
|
+
const CONTENT_MAX = 20_000;
|
|
7
|
+
/**
|
|
8
|
+
* Who may use snippets at all: authors and up.
|
|
9
|
+
*
|
|
10
|
+
* There is no snippet capability in the framework's role table, so this is
|
|
11
|
+
* expressed through the nearest one that draws the same line — `post.publish`
|
|
12
|
+
* is what an author has and a contributor does not. A contributor writes drafts
|
|
13
|
+
* for someone else to review; a shared library of site-wide boilerplate (the
|
|
14
|
+
* legal disclosure, the sign-off) is for the people who put posts live.
|
|
15
|
+
*/
|
|
16
|
+
export function mayUseSnippets(user) {
|
|
17
|
+
return can(user ?? null, 'post.publish');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Who may change or delete this snippet: whoever wrote it, or an editor.
|
|
21
|
+
*
|
|
22
|
+
* `post.edit` (without `.own`) is the editor's "anyone's work" capability, so
|
|
23
|
+
* it is the same rule as posts: authors look after their own, editors look
|
|
24
|
+
* after everyone's.
|
|
25
|
+
*/
|
|
26
|
+
export function mayManageSnippet(user, snippet) {
|
|
27
|
+
if (!mayUseSnippets(user))
|
|
28
|
+
return false;
|
|
29
|
+
if (can(user ?? null, 'post.edit'))
|
|
30
|
+
return true;
|
|
31
|
+
return snippet.created_by !== null && String(snippet.created_by) === String(user?.id);
|
|
32
|
+
}
|
|
33
|
+
function present(snippet, user) {
|
|
34
|
+
return { ...snippet, can_edit: mayManageSnippet(user, snippet) };
|
|
35
|
+
}
|
|
36
|
+
/** Validate a body, for create (`partial` false) or update (`partial` true). */
|
|
37
|
+
function fieldsFrom(body, partial) {
|
|
38
|
+
const payload = (body ?? {});
|
|
39
|
+
const errors = {};
|
|
40
|
+
const values = {};
|
|
41
|
+
if (payload.name !== undefined || !partial) {
|
|
42
|
+
const name = typeof payload.name === 'string' ? payload.name.trim() : '';
|
|
43
|
+
if (!name)
|
|
44
|
+
errors.name = ['A snippet needs a name'];
|
|
45
|
+
else if (name.length > NAME_MAX)
|
|
46
|
+
errors.name = [`At most ${NAME_MAX} characters`];
|
|
47
|
+
else
|
|
48
|
+
values.name = name;
|
|
49
|
+
}
|
|
50
|
+
if (payload.content !== undefined || !partial) {
|
|
51
|
+
// Not trimmed: leading and trailing blank lines can be deliberate spacing
|
|
52
|
+
// when the snippet lands in the middle of a post.
|
|
53
|
+
const content = typeof payload.content === 'string' ? payload.content : '';
|
|
54
|
+
if (!content.trim())
|
|
55
|
+
errors.content = ['A snippet needs some content'];
|
|
56
|
+
else if (content.length > CONTENT_MAX)
|
|
57
|
+
errors.content = [`At most ${CONTENT_MAX} characters`];
|
|
58
|
+
else
|
|
59
|
+
values.content = content;
|
|
60
|
+
}
|
|
61
|
+
return Object.keys(errors).length ? { errors } : { values };
|
|
62
|
+
}
|
|
63
|
+
export const SnippetController = {
|
|
64
|
+
async index(req, res) {
|
|
65
|
+
if (!mayUseSnippets(req.user))
|
|
66
|
+
return res.json({ error: 'Forbidden' }, 403);
|
|
67
|
+
const search = typeof req.query?.search === 'string' ? req.query.search.trim().slice(0, 100) : '';
|
|
68
|
+
const snippets = await Snippet.all(search || undefined);
|
|
69
|
+
res.json({ snippets: snippets.map(snippet => present(snippet, req.user)) });
|
|
70
|
+
},
|
|
71
|
+
async show(req, res) {
|
|
72
|
+
if (!mayUseSnippets(req.user))
|
|
73
|
+
return res.json({ error: 'Forbidden' }, 403);
|
|
74
|
+
const snippet = await Snippet.find(parseInt(req.params.id));
|
|
75
|
+
if (!snippet)
|
|
76
|
+
return res.json({ error: 'Snippet not found' }, 404);
|
|
77
|
+
res.json({ snippet: present(snippet, req.user) });
|
|
78
|
+
},
|
|
79
|
+
async store(req, res) {
|
|
80
|
+
if (!mayUseSnippets(req.user))
|
|
81
|
+
return res.json({ error: 'Forbidden' }, 403);
|
|
82
|
+
const fields = fieldsFrom(req.body, false);
|
|
83
|
+
if ('errors' in fields)
|
|
84
|
+
return res.json({ errors: fields.errors }, 422);
|
|
85
|
+
const snippet = await Snippet.create({
|
|
86
|
+
name: fields.values.name,
|
|
87
|
+
content: fields.values.content,
|
|
88
|
+
created_by: req.userId
|
|
89
|
+
});
|
|
90
|
+
res.json({ snippet: snippet ? present(snippet, req.user) : null }, 201);
|
|
91
|
+
},
|
|
92
|
+
async update(req, res) {
|
|
93
|
+
const snippet = await Snippet.find(parseInt(req.params.id));
|
|
94
|
+
// Someone who cannot use snippets at all gets the same 403 as on the
|
|
95
|
+
// listing; someone who can but did not write this one is told why.
|
|
96
|
+
if (!mayUseSnippets(req.user))
|
|
97
|
+
return res.json({ error: 'Forbidden' }, 403);
|
|
98
|
+
if (!snippet)
|
|
99
|
+
return res.json({ error: 'Snippet not found' }, 404);
|
|
100
|
+
if (!mayManageSnippet(req.user, snippet)) {
|
|
101
|
+
return res.json({ error: 'Only its author or an editor can change this snippet.' }, 403);
|
|
102
|
+
}
|
|
103
|
+
const fields = fieldsFrom(req.body, true);
|
|
104
|
+
if ('errors' in fields)
|
|
105
|
+
return res.json({ errors: fields.errors }, 422);
|
|
106
|
+
const updated = await Snippet.update(snippet.id, fields.values);
|
|
107
|
+
res.json({ snippet: updated ? present(updated, req.user) : null });
|
|
108
|
+
},
|
|
109
|
+
async destroy(req, res) {
|
|
110
|
+
const snippet = await Snippet.find(parseInt(req.params.id));
|
|
111
|
+
if (!mayUseSnippets(req.user))
|
|
112
|
+
return res.json({ error: 'Forbidden' }, 403);
|
|
113
|
+
if (!snippet)
|
|
114
|
+
return res.json({ error: 'Snippet not found' }, 404);
|
|
115
|
+
if (!mayManageSnippet(req.user, snippet)) {
|
|
116
|
+
return res.json({ error: 'Only its author or an editor can delete this snippet.' }, 403);
|
|
117
|
+
}
|
|
118
|
+
// Deleting a snippet leaves every post that used it alone: the text was
|
|
119
|
+
// copied in, not linked.
|
|
120
|
+
await Snippet.delete(snippet.id);
|
|
121
|
+
res.json({ deleted: true });
|
|
122
|
+
}
|
|
123
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
export declare const TagController: {
|
|
3
|
+
index(req: Request, res: Response): Promise<void>;
|
|
4
|
+
show(req: Request, res: Response): Promise<void>;
|
|
5
|
+
showBySlug(req: Request, res: Response): Promise<void>;
|
|
6
|
+
store(req: Request, res: Response): Promise<void>;
|
|
7
|
+
update(req: Request, res: Response): Promise<void>;
|
|
8
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
2
|
+
import { Tag } from "../models/Tag.js";
|
|
3
|
+
export const TagController = {
|
|
4
|
+
async index(req, res) {
|
|
5
|
+
const tags = await Tag.all();
|
|
6
|
+
res.json({ tags });
|
|
7
|
+
},
|
|
8
|
+
async show(req, res) {
|
|
9
|
+
const tag = await Tag.find(parseInt(req.params.id));
|
|
10
|
+
if (!tag) {
|
|
11
|
+
return res.json({ error: 'Tag not found' }, 404);
|
|
12
|
+
}
|
|
13
|
+
res.json({ tag });
|
|
14
|
+
},
|
|
15
|
+
async showBySlug(req, res) {
|
|
16
|
+
const tag = await Tag.findBySlug(req.params.slug);
|
|
17
|
+
if (!tag) {
|
|
18
|
+
return res.json({ error: 'Tag not found' }, 404);
|
|
19
|
+
}
|
|
20
|
+
res.json({ tag });
|
|
21
|
+
},
|
|
22
|
+
async store(req, res) {
|
|
23
|
+
const result = await validate(req.body, {
|
|
24
|
+
name: [rules.required, rules.string, rules.min(2), rules.max(50)]
|
|
25
|
+
});
|
|
26
|
+
if (result.fails()) {
|
|
27
|
+
return res.json({ errors: result.errors }, 422);
|
|
28
|
+
}
|
|
29
|
+
const { name, slug } = req.body;
|
|
30
|
+
// Check for slug uniqueness if provided
|
|
31
|
+
if (slug) {
|
|
32
|
+
const exists = await Tag.slugExists(slug);
|
|
33
|
+
if (exists) {
|
|
34
|
+
return res.json({ errors: { slug: ['Slug already exists'] } }, 422);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const tag = await Tag.create({ name, slug });
|
|
38
|
+
res.json({ tag }, 201);
|
|
39
|
+
},
|
|
40
|
+
async update(req, res) {
|
|
41
|
+
const tag = await Tag.find(parseInt(req.params.id));
|
|
42
|
+
if (!tag) {
|
|
43
|
+
return res.json({ error: 'Tag not found' }, 404);
|
|
44
|
+
}
|
|
45
|
+
const result = await validate(req.body, {
|
|
46
|
+
name: [rules.required, rules.string, rules.min(2), rules.max(50)]
|
|
47
|
+
});
|
|
48
|
+
if (result.fails()) {
|
|
49
|
+
return res.json({ errors: result.errors }, 422);
|
|
50
|
+
}
|
|
51
|
+
const { name, slug } = req.body;
|
|
52
|
+
// Check for slug uniqueness if changed
|
|
53
|
+
if (slug && slug !== tag.slug) {
|
|
54
|
+
const exists = await Tag.slugExists(slug, tag.id);
|
|
55
|
+
if (exists) {
|
|
56
|
+
return res.json({ errors: { slug: ['Slug already exists'] } }, 422);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const updated = await Tag.update(parseInt(req.params.id), { name, slug });
|
|
60
|
+
res.json({ tag: updated });
|
|
61
|
+
},
|
|
62
|
+
async destroy(req, res) {
|
|
63
|
+
const tag = await Tag.find(parseInt(req.params.id));
|
|
64
|
+
if (!tag) {
|
|
65
|
+
return res.json({ error: 'Tag not found' }, 404);
|
|
66
|
+
}
|
|
67
|
+
await Tag.delete(parseInt(req.params.id));
|
|
68
|
+
res.json({ message: 'Tag deleted' });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Custom taxonomies and their terms: admin CRUD and the public reads.
|
|
4
|
+
*
|
|
5
|
+
* Defining a taxonomy is `settings.manage`, like a content type — it changes
|
|
6
|
+
* the shape of the editor for everyone. Managing its terms is
|
|
7
|
+
* `category.manage`, the same capability that manages categories, because a
|
|
8
|
+
* cuisine is to a recipe what a category is to a post.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TaxonomyController: {
|
|
11
|
+
index(req: Request, res: Response): Promise<void>;
|
|
12
|
+
store(req: Request, res: Response): Promise<void>;
|
|
13
|
+
update(req: Request, res: Response): Promise<void>;
|
|
14
|
+
/** Deletes the taxonomy, its terms, and every post's link to them. */
|
|
15
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
16
|
+
terms(req: Request, res: Response): Promise<void>;
|
|
17
|
+
storeTerm(req: Request, res: Response): Promise<void>;
|
|
18
|
+
updateTerm(req: Request, res: Response): Promise<void>;
|
|
19
|
+
destroyTerm(req: Request, res: Response): Promise<void>;
|
|
20
|
+
/** `GET /api/v1/taxonomies` — every public custom taxonomy. */
|
|
21
|
+
publicIndex(_req: Request, res: Response): Promise<void>;
|
|
22
|
+
/** `GET /api/v1/taxonomies/:key/terms` — a public taxonomy's terms, with live-post counts. */
|
|
23
|
+
publicTerms(req: Request, res: Response): Promise<void>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Taxonomy, validateTaxonomy, validateTerm } from "../models/Taxonomy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Custom taxonomies and their terms: admin CRUD and the public reads.
|
|
4
|
+
*
|
|
5
|
+
* Defining a taxonomy is `settings.manage`, like a content type — it changes
|
|
6
|
+
* the shape of the editor for everyone. Managing its terms is
|
|
7
|
+
* `category.manage`, the same capability that manages categories, because a
|
|
8
|
+
* cuisine is to a recipe what a category is to a post.
|
|
9
|
+
*/
|
|
10
|
+
export const TaxonomyController = {
|
|
11
|
+
async index(req, res) {
|
|
12
|
+
const type = typeof req.query.type === 'string' ? req.query.type : undefined;
|
|
13
|
+
res.json({ taxonomies: await Taxonomy.all({ contentType: type }) });
|
|
14
|
+
},
|
|
15
|
+
async store(req, res) {
|
|
16
|
+
const checked = validateTaxonomy(req.body, null);
|
|
17
|
+
if ('errors' in checked)
|
|
18
|
+
return res.json({ errors: checked.errors }, 422);
|
|
19
|
+
if (await Taxonomy.keyTaken(checked.values.key)) {
|
|
20
|
+
return res.json({ errors: { key: ['A taxonomy with this key already exists'] } }, 422);
|
|
21
|
+
}
|
|
22
|
+
const unknown = await Taxonomy.unknownContentTypes(checked.values.content_types);
|
|
23
|
+
if (unknown.length)
|
|
24
|
+
return res.json({ errors: { content_types: [`Unknown content type: ${unknown.join(', ')}`] } }, 422);
|
|
25
|
+
res.json({ taxonomy: await Taxonomy.create(checked.values) }, 201);
|
|
26
|
+
},
|
|
27
|
+
async update(req, res) {
|
|
28
|
+
const existing = await findTaxonomy(req);
|
|
29
|
+
if (!existing)
|
|
30
|
+
return res.json({ error: 'Taxonomy not found' }, 404);
|
|
31
|
+
const checked = validateTaxonomy(req.body, existing);
|
|
32
|
+
if ('errors' in checked)
|
|
33
|
+
return res.json({ errors: checked.errors }, 422);
|
|
34
|
+
const unknown = await Taxonomy.unknownContentTypes(checked.values.content_types);
|
|
35
|
+
if (unknown.length)
|
|
36
|
+
return res.json({ errors: { content_types: [`Unknown content type: ${unknown.join(', ')}`] } }, 422);
|
|
37
|
+
res.json({ taxonomy: await Taxonomy.update(existing.id, checked.values) });
|
|
38
|
+
},
|
|
39
|
+
/** Deletes the taxonomy, its terms, and every post's link to them. */
|
|
40
|
+
async destroy(req, res) {
|
|
41
|
+
const existing = await findTaxonomy(req);
|
|
42
|
+
if (!existing)
|
|
43
|
+
return res.json({ error: 'Taxonomy not found' }, 404);
|
|
44
|
+
await Taxonomy.delete(existing.id);
|
|
45
|
+
res.json({ message: 'Taxonomy deleted' });
|
|
46
|
+
},
|
|
47
|
+
async terms(req, res) {
|
|
48
|
+
const taxonomy = await findTaxonomy(req);
|
|
49
|
+
if (!taxonomy)
|
|
50
|
+
return res.json({ error: 'Taxonomy not found' }, 404);
|
|
51
|
+
res.json({ taxonomy, terms: await Taxonomy.terms(taxonomy.id) });
|
|
52
|
+
},
|
|
53
|
+
async storeTerm(req, res) {
|
|
54
|
+
const taxonomy = await findTaxonomy(req);
|
|
55
|
+
if (!taxonomy)
|
|
56
|
+
return res.json({ error: 'Taxonomy not found' }, 404);
|
|
57
|
+
const checked = validateTerm(req.body, null);
|
|
58
|
+
if ('errors' in checked)
|
|
59
|
+
return res.json({ errors: checked.errors }, 422);
|
|
60
|
+
const parentError = await checkParent(taxonomy, checked.values.parent_id);
|
|
61
|
+
if (parentError)
|
|
62
|
+
return res.json({ errors: { parent_id: [parentError] } }, 422);
|
|
63
|
+
if (await Taxonomy.termSlugTaken(taxonomy.id, checked.values.slug)) {
|
|
64
|
+
return res.json({ errors: { slug: [`"${checked.values.slug}" is already a ${taxonomy.singular_label.toLowerCase()}`] } }, 422);
|
|
65
|
+
}
|
|
66
|
+
res.json({ term: await Taxonomy.createTerm(taxonomy.id, checked.values) }, 201);
|
|
67
|
+
},
|
|
68
|
+
async updateTerm(req, res) {
|
|
69
|
+
const term = await Taxonomy.findTerm(Number(req.params.id));
|
|
70
|
+
if (!term)
|
|
71
|
+
return res.json({ error: 'Term not found' }, 404);
|
|
72
|
+
const taxonomy = (await Taxonomy.find(term.taxonomy_id));
|
|
73
|
+
const checked = validateTerm(req.body, term);
|
|
74
|
+
if ('errors' in checked)
|
|
75
|
+
return res.json({ errors: checked.errors }, 422);
|
|
76
|
+
const parentError = await checkParent(taxonomy, checked.values.parent_id, term.id);
|
|
77
|
+
if (parentError)
|
|
78
|
+
return res.json({ errors: { parent_id: [parentError] } }, 422);
|
|
79
|
+
if (await Taxonomy.termSlugTaken(taxonomy.id, checked.values.slug, term.id)) {
|
|
80
|
+
return res.json({ errors: { slug: [`"${checked.values.slug}" is already a ${taxonomy.singular_label.toLowerCase()}`] } }, 422);
|
|
81
|
+
}
|
|
82
|
+
res.json({ term: await Taxonomy.updateTerm(term.id, checked.values) });
|
|
83
|
+
},
|
|
84
|
+
async destroyTerm(req, res) {
|
|
85
|
+
const term = await Taxonomy.findTerm(Number(req.params.id));
|
|
86
|
+
if (!term)
|
|
87
|
+
return res.json({ error: 'Term not found' }, 404);
|
|
88
|
+
await Taxonomy.deleteTerm(term.id);
|
|
89
|
+
res.json({ message: 'Term deleted' });
|
|
90
|
+
},
|
|
91
|
+
/** `GET /api/v1/taxonomies` — every public custom taxonomy. */
|
|
92
|
+
async publicIndex(_req, res) {
|
|
93
|
+
const taxonomies = await Taxonomy.all({ publicOnly: true });
|
|
94
|
+
res.json({ data: taxonomies.map(presentTaxonomy) });
|
|
95
|
+
},
|
|
96
|
+
/** `GET /api/v1/taxonomies/:key/terms` — a public taxonomy's terms, with live-post counts. */
|
|
97
|
+
async publicTerms(req, res) {
|
|
98
|
+
const taxonomy = await Taxonomy.findByKey(String(req.params.key));
|
|
99
|
+
if (!taxonomy || !taxonomy.public)
|
|
100
|
+
return res.json({ error: 'Not found' }, 404);
|
|
101
|
+
const terms = await Taxonomy.terms(taxonomy.id);
|
|
102
|
+
res.json({
|
|
103
|
+
data: terms.map((term) => ({
|
|
104
|
+
id: term.id,
|
|
105
|
+
name: term.name,
|
|
106
|
+
slug: term.slug,
|
|
107
|
+
description: term.description,
|
|
108
|
+
parent_id: term.parent_id,
|
|
109
|
+
post_count: term.post_count ?? 0
|
|
110
|
+
})),
|
|
111
|
+
meta: { taxonomy: presentTaxonomy(taxonomy) }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function presentTaxonomy(taxonomy) {
|
|
116
|
+
return {
|
|
117
|
+
key: taxonomy.key,
|
|
118
|
+
singular_label: taxonomy.singular_label,
|
|
119
|
+
plural_label: taxonomy.plural_label,
|
|
120
|
+
description: taxonomy.description,
|
|
121
|
+
hierarchical: taxonomy.hierarchical,
|
|
122
|
+
content_types: taxonomy.content_types
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function findTaxonomy(req) {
|
|
126
|
+
const id = Number(req.params.id);
|
|
127
|
+
return Number.isInteger(id) ? Taxonomy.find(id) : Taxonomy.findByKey(String(req.params.id));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A parent must be a term of the same taxonomy, the taxonomy must allow
|
|
131
|
+
* nesting, and the parent must not sit below the term being moved — or the
|
|
132
|
+
* tree would loop and every breadcrumb built from it would never finish.
|
|
133
|
+
*/
|
|
134
|
+
async function checkParent(taxonomy, parentId, termId) {
|
|
135
|
+
if (parentId === null)
|
|
136
|
+
return null;
|
|
137
|
+
if (!taxonomy.hierarchical)
|
|
138
|
+
return `${taxonomy.plural_label} do not nest`;
|
|
139
|
+
let cursor = parentId;
|
|
140
|
+
for (let hops = 0; cursor !== null && hops < 50; hops++) {
|
|
141
|
+
if (cursor === termId)
|
|
142
|
+
return 'A term cannot sit below itself';
|
|
143
|
+
const parent = await Taxonomy.findTerm(cursor);
|
|
144
|
+
if (!parent || parent.taxonomy_id !== taxonomy.id)
|
|
145
|
+
return 'The parent must be a term of the same taxonomy';
|
|
146
|
+
cursor = parent.parent_id;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
export declare const TokenController: {
|
|
3
|
+
/**
|
|
4
|
+
* A user's own tokens.
|
|
5
|
+
*
|
|
6
|
+
* Always scoped to `req.userId` rather than accepting one, so there is no
|
|
7
|
+
* parameter to tamper with. An admin has no listing of everyone's tokens on
|
|
8
|
+
* purpose: the point of hash-only storage is that nobody, including an admin,
|
|
9
|
+
* can read someone else's credential.
|
|
10
|
+
*/
|
|
11
|
+
index(req: Request, res: Response): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Issue a token.
|
|
14
|
+
*
|
|
15
|
+
* The plaintext comes back exactly once, in this response, and is never
|
|
16
|
+
* retrievable again — which is the whole point of storing only its hash.
|
|
17
|
+
*/
|
|
18
|
+
store(req: Request, res: Response): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Revoke a token.
|
|
21
|
+
*
|
|
22
|
+
* Scoped to the owner in the query itself, so a guessed id belonging to
|
|
23
|
+
* someone else deletes nothing and returns 404 rather than confirming it
|
|
24
|
+
* exists.
|
|
25
|
+
*/
|
|
26
|
+
destroy(req: Request, res: Response): Promise<void>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createApiToken, listApiTokens, revokeApiToken, SCOPES } from '@basicbenframework/core/auth/api-tokens';
|
|
2
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
3
|
+
const ALL_SCOPES = Object.values(SCOPES);
|
|
4
|
+
/** Days, converted to the ttl the token store wants. */
|
|
5
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
export const TokenController = {
|
|
7
|
+
/**
|
|
8
|
+
* A user's own tokens.
|
|
9
|
+
*
|
|
10
|
+
* Always scoped to `req.userId` rather than accepting one, so there is no
|
|
11
|
+
* parameter to tamper with. An admin has no listing of everyone's tokens on
|
|
12
|
+
* purpose: the point of hash-only storage is that nobody, including an admin,
|
|
13
|
+
* can read someone else's credential.
|
|
14
|
+
*/
|
|
15
|
+
async index(req, res) {
|
|
16
|
+
res.json({ tokens: await listApiTokens(req.userId), scopes: ALL_SCOPES });
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* Issue a token.
|
|
20
|
+
*
|
|
21
|
+
* The plaintext comes back exactly once, in this response, and is never
|
|
22
|
+
* retrievable again — which is the whole point of storing only its hash.
|
|
23
|
+
*/
|
|
24
|
+
async store(req, res) {
|
|
25
|
+
const result = await validate(req.body, {
|
|
26
|
+
name: [rules.required, rules.string, rules.min(1)]
|
|
27
|
+
});
|
|
28
|
+
if (result.fails()) {
|
|
29
|
+
return res.json({ errors: result.errors }, 422);
|
|
30
|
+
}
|
|
31
|
+
const { name, scopes, expiresInDays } = req.body;
|
|
32
|
+
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
33
|
+
return res.json({ errors: { scopes: ['Pick at least one scope'] } }, 422);
|
|
34
|
+
}
|
|
35
|
+
// Days rather than a raw ttl because that is what the form collects, and a
|
|
36
|
+
// number of milliseconds arriving from a client is a number nobody checked.
|
|
37
|
+
let ttl;
|
|
38
|
+
if (expiresInDays !== undefined && expiresInDays !== null) {
|
|
39
|
+
const days = Number(expiresInDays);
|
|
40
|
+
if (!Number.isFinite(days) || days <= 0) {
|
|
41
|
+
return res.json({ errors: { expiresInDays: ['Must be a positive number of days'] } }, 422);
|
|
42
|
+
}
|
|
43
|
+
ttl = days * DAY_MS;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const token = await createApiToken(req.userId, { name, scopes, ttl });
|
|
47
|
+
res.json({
|
|
48
|
+
// Named `token` and returned only here. The listing endpoint cannot
|
|
49
|
+
// produce it, so a client that discards this value has lost it.
|
|
50
|
+
token: token.token,
|
|
51
|
+
created: {
|
|
52
|
+
id: token.id,
|
|
53
|
+
name: token.name,
|
|
54
|
+
scopes: token.scopes,
|
|
55
|
+
expiresAt: token.expiresAt
|
|
56
|
+
}
|
|
57
|
+
}, 201);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// createApiToken throws on an unknown scope or a blank name, which are
|
|
61
|
+
// both client mistakes rather than server faults.
|
|
62
|
+
return res.json({ errors: { scopes: [error.message] } }, 422);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Revoke a token.
|
|
67
|
+
*
|
|
68
|
+
* Scoped to the owner in the query itself, so a guessed id belonging to
|
|
69
|
+
* someone else deletes nothing and returns 404 rather than confirming it
|
|
70
|
+
* exists.
|
|
71
|
+
*/
|
|
72
|
+
async destroy(req, res) {
|
|
73
|
+
const id = Number(req.params.id);
|
|
74
|
+
if (!Number.isInteger(id)) {
|
|
75
|
+
return res.json({ error: 'Token not found' }, 404);
|
|
76
|
+
}
|
|
77
|
+
const revoked = await revokeApiToken(id, req.userId);
|
|
78
|
+
if (!revoked) {
|
|
79
|
+
return res.json({ error: 'Token not found' }, 404);
|
|
80
|
+
}
|
|
81
|
+
res.json({ revoked: true });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Request, Response } from '../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Start the second step of a login.
|
|
4
|
+
*
|
|
5
|
+
* Returns an opaque challenge rather than a session token. It lives in
|
|
6
|
+
* auth_tokens, never as a JWT, so verifyJwt cannot return one and it can never
|
|
7
|
+
* be mistaken for a session — which would bypass the second factor entirely.
|
|
8
|
+
*/
|
|
9
|
+
export declare function issueChallenge(userId: number): Promise<{
|
|
10
|
+
challenge: string;
|
|
11
|
+
expiresAt: Date;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const TwoFactorController: {
|
|
14
|
+
/** What is enrolled, for the account settings screen. */
|
|
15
|
+
status(req: Request, res: Response): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Generate a secret. Deliberately does not enable anything — enrolment is
|
|
18
|
+
* only complete once a working code proves the authenticator was configured.
|
|
19
|
+
*/
|
|
20
|
+
setupTotp(req: Request, res: Response): Promise<void>;
|
|
21
|
+
/** Confirm the authenticator works, then enable and hand over recovery codes. */
|
|
22
|
+
confirmTotp(req: Request, res: Response): Promise<void>;
|
|
23
|
+
/** Remove the authenticator. */
|
|
24
|
+
disableTotp(req: Request, res: Response): Promise<void>;
|
|
25
|
+
/** Replace the recovery codes, invalidating the old set. */
|
|
26
|
+
rotateRecoveryCodes(req: Request, res: Response): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* The second step of a login: exchange a challenge plus a code for a session.
|
|
29
|
+
*/
|
|
30
|
+
verify(req: Request, res: Response): Promise<void>;
|
|
31
|
+
};
|