@basicbenframework/cms 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +206 -2
- package/db/migrations/001_create_users.js +15 -0
- package/db/migrations/002_create_posts.js +18 -0
- package/db/migrations/003_create_categories.js +19 -0
- package/db/migrations/004_create_tags.js +16 -0
- package/db/migrations/005_create_post_tags.js +16 -0
- package/db/migrations/006_create_pages.js +26 -0
- package/db/migrations/007_create_comments.js +24 -0
- package/db/migrations/008_create_media.js +22 -0
- package/db/migrations/009_update_posts_blogging.js +27 -0
- package/db/migrations/010_create_settings.js +29 -0
- package/db/migrations/011_add_user_roles.js +23 -0
- package/db/migrations/012_create_auth_tokens.js +30 -0
- package/db/migrations/013_add_email_verified.js +24 -0
- package/db/migrations/014_create_user_two_factor.js +30 -0
- package/db/migrations/015_create_user_credentials.js +35 -0
- package/db/migrations/016_create_rate_limits.js +31 -0
- package/db/migrations/017_add_content_html.js +38 -0
- package/db/migrations/018_create_api_tokens.js +34 -0
- package/db/migrations/019_create_post_categories.js +40 -0
- package/db/migrations/020_add_author_profiles.js +60 -0
- package/db/migrations/021_add_page_featured_image.js +23 -0
- package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
- package/db/migrations/023_add_user_session_controls.js +25 -0
- package/db/migrations/024_add_post_status_and_trash.js +45 -0
- package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
- package/db/migrations/026_create_post_revisions.js +29 -0
- package/db/migrations/027_add_media_dimensions.js +19 -0
- package/db/migrations/028_create_navigation_menus.js +65 -0
- package/db/migrations/029_create_redirects.js +40 -0
- package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
- package/db/migrations/031_create_post_locks.js +38 -0
- package/db/migrations/032_create_snippets.js +31 -0
- package/db/migrations/033_create_members.js +70 -0
- package/db/migrations/034_add_post_visibility.js +28 -0
- package/db/migrations/035_create_newsletters.js +72 -0
- package/db/migrations/036_create_analytics.js +89 -0
- package/db/migrations/037_create_ops_heartbeats.js +30 -0
- package/db/migrations/038_create_content_types.js +84 -0
- package/db/migrations/039_create_content_type_fields.js +47 -0
- package/db/migrations/040_create_taxonomies.js +80 -0
- package/db/migrations/041_add_newsletter_handoff.js +28 -0
- package/db/migrations/042_create_mysendbox_contacts.js +63 -0
- package/lib/cli/backup.d.mts +2 -0
- package/lib/cli/backup.mjs +124 -0
- package/lib/cli/export.d.mts +2 -0
- package/lib/cli/export.mjs +54 -0
- package/lib/cli/import-ghost.d.mts +2 -0
- package/lib/cli/import-ghost.mjs +50 -0
- package/lib/cli/import-json.d.mts +2 -0
- package/lib/cli/import-json.mjs +61 -0
- package/lib/cli/import-wordpress.d.mts +2 -0
- package/lib/cli/import-wordpress.mjs +169 -0
- package/lib/cli/import-wxr.d.mts +2 -0
- package/lib/cli/import-wxr.mjs +55 -0
- package/lib/cli/index.d.mts +2 -0
- package/lib/cli/index.mjs +53 -0
- package/lib/cli/lib/backup.d.mts +112 -0
- package/lib/cli/lib/backup.mjs +297 -0
- package/lib/cli/lib/ghost.d.mts +30 -0
- package/lib/cli/lib/ghost.mjs +201 -0
- package/lib/cli/lib/html-to-markdown.d.mts +61 -0
- package/lib/cli/lib/html-to-markdown.mjs +523 -0
- package/lib/cli/lib/import-common.d.mts +100 -0
- package/lib/cli/lib/import-common.mjs +252 -0
- package/lib/cli/lib/json-import.d.mts +22 -0
- package/lib/cli/lib/json-import.mjs +422 -0
- package/lib/cli/lib/site-import.d.mts +32 -0
- package/lib/cli/lib/site-import.mjs +456 -0
- package/lib/cli/lib/wordpress-rest.d.mts +25 -0
- package/lib/cli/lib/wordpress-rest.mjs +177 -0
- package/lib/cli/lib/wxr.d.mts +18 -0
- package/lib/cli/lib/wxr.mjs +307 -0
- package/lib/cli/lib/xml.d.mts +33 -0
- package/lib/cli/lib/xml.mjs +186 -0
- package/lib/cli/restore.d.mts +2 -0
- package/lib/cli/restore.mjs +98 -0
- package/lib/client/components/Alert.d.ts +7 -0
- package/lib/client/components/Alert.js +8 -0
- package/lib/client/components/Avatar.d.ts +15 -0
- package/lib/client/components/Avatar.js +10 -0
- package/lib/client/components/BackLink.d.ts +7 -0
- package/lib/client/components/BackLink.js +6 -0
- package/lib/client/components/Button.d.ts +7 -0
- package/lib/client/components/Button.js +12 -0
- package/lib/client/components/Card.d.ts +7 -0
- package/lib/client/components/Card.js +6 -0
- package/lib/client/components/CommentThread.d.ts +15 -0
- package/lib/client/components/CommentThread.js +101 -0
- package/lib/client/components/Empty.d.ts +6 -0
- package/lib/client/components/Empty.js +6 -0
- package/lib/client/components/Input.d.ts +6 -0
- package/lib/client/components/Input.js +6 -0
- package/lib/client/components/Link.d.ts +31 -0
- package/lib/client/components/Link.js +49 -0
- package/lib/client/components/Loading.d.ts +1 -0
- package/lib/client/components/Loading.js +6 -0
- package/lib/client/components/Logo.d.ts +5 -0
- package/lib/client/components/Logo.js +4 -0
- package/lib/client/components/MarkdownEditor.d.ts +41 -0
- package/lib/client/components/MarkdownEditor.js +156 -0
- package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
- package/lib/client/components/Nav/DarkModeToggle.js +6 -0
- package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
- package/lib/client/components/Nav/DesktopNav.js +9 -0
- package/lib/client/components/Nav/MobileNav.d.ts +9 -0
- package/lib/client/components/Nav/MobileNav.js +15 -0
- package/lib/client/components/NavLink.d.ts +8 -0
- package/lib/client/components/NavLink.js +6 -0
- package/lib/client/components/PageHeader.d.ts +8 -0
- package/lib/client/components/PageHeader.js +6 -0
- package/lib/client/components/PostCard.d.ts +8 -0
- package/lib/client/components/PostCard.js +7 -0
- package/lib/client/components/Textarea.d.ts +6 -0
- package/lib/client/components/Textarea.js +6 -0
- package/lib/client/components/ThemeContext.d.ts +18 -0
- package/lib/client/components/ThemeContext.js +8 -0
- package/lib/client/components/admin/AdminIcons.d.ts +13 -0
- package/lib/client/components/admin/AdminIcons.js +66 -0
- package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
- package/lib/client/components/admin/ContentModelPanels.js +93 -0
- package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
- package/lib/client/components/admin/FeaturedImageBox.js +24 -0
- package/lib/client/components/admin/MediaGrid.d.ts +23 -0
- package/lib/client/components/admin/MediaGrid.js +69 -0
- package/lib/client/components/admin/MediaPicker.d.ts +17 -0
- package/lib/client/components/admin/MediaPicker.js +61 -0
- package/lib/client/components/admin/Pagination.d.ts +27 -0
- package/lib/client/components/admin/Pagination.js +29 -0
- package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
- package/lib/client/components/admin/SnippetPicker.js +65 -0
- package/lib/client/components/admin/TermPicker.d.ts +52 -0
- package/lib/client/components/admin/TermPicker.js +58 -0
- package/lib/client/contexts/ToastContext.d.ts +12 -0
- package/lib/client/contexts/ToastContext.js +49 -0
- package/lib/client/features.d.ts +11 -0
- package/lib/client/features.js +7 -0
- package/lib/client/hooks/useContentTypes.d.ts +48 -0
- package/lib/client/hooks/useContentTypes.js +48 -0
- package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
- package/lib/client/hooks/useMediaLibrary.js +189 -0
- package/lib/client/hooks/usePostLock.d.ts +32 -0
- package/lib/client/hooks/usePostLock.js +107 -0
- package/lib/client/host/index.d.ts +71 -0
- package/lib/client/host/index.js +58 -0
- package/lib/client/i18n/index.d.ts +79 -0
- package/lib/client/i18n/index.js +177 -0
- package/lib/client/i18n/locales/es/content.d.ts +4 -0
- package/lib/client/i18n/locales/es/content.js +220 -0
- package/lib/client/i18n/locales/es/editor.d.ts +9 -0
- package/lib/client/i18n/locales/es/editor.js +144 -0
- package/lib/client/i18n/locales/es/index.d.ts +8 -0
- package/lib/client/i18n/locales/es/index.js +7 -0
- package/lib/client/i18n/locales/es/layout.d.ts +4 -0
- package/lib/client/i18n/locales/es/layout.js +35 -0
- package/lib/client/i18n/locales/es/people.d.ts +4 -0
- package/lib/client/i18n/locales/es/people.js +187 -0
- package/lib/client/i18n/locales/es/site.d.ts +4 -0
- package/lib/client/i18n/locales/es/site.js +208 -0
- package/lib/client/layouts/AdminLayout.d.ts +7 -0
- package/lib/client/layouts/AdminLayout.js +1046 -0
- package/lib/client/layouts/AppLayout.d.ts +6 -0
- package/lib/client/layouts/AppLayout.js +19 -0
- package/lib/client/layouts/AuthLayout.d.ts +6 -0
- package/lib/client/layouts/AuthLayout.js +14 -0
- package/lib/client/layouts/DocsLayout.d.ts +6 -0
- package/lib/client/layouts/DocsLayout.js +28 -0
- package/lib/client/layouts/RootLayout.d.ts +6 -0
- package/lib/client/layouts/RootLayout.js +11 -0
- package/lib/client/pages/AcceptInvite.d.ts +8 -0
- package/lib/client/pages/AcceptInvite.js +60 -0
- package/lib/client/pages/Auth.d.ts +1 -0
- package/lib/client/pages/Auth.js +40 -0
- package/lib/client/pages/Authentication.d.ts +1 -0
- package/lib/client/pages/Authentication.js +230 -0
- package/lib/client/pages/Content.d.ts +1 -0
- package/lib/client/pages/Content.js +21 -0
- package/lib/client/pages/Database.d.ts +1 -0
- package/lib/client/pages/Database.js +264 -0
- package/lib/client/pages/Extending.d.ts +1 -0
- package/lib/client/pages/Extending.js +28 -0
- package/lib/client/pages/Feed.d.ts +1 -0
- package/lib/client/pages/Feed.js +19 -0
- package/lib/client/pages/FeedPost.d.ts +1 -0
- package/lib/client/pages/FeedPost.js +31 -0
- package/lib/client/pages/ForgotPassword.d.ts +8 -0
- package/lib/client/pages/ForgotPassword.js +38 -0
- package/lib/client/pages/GettingStarted.d.ts +1 -0
- package/lib/client/pages/GettingStarted.js +84 -0
- package/lib/client/pages/Headless.d.ts +1 -0
- package/lib/client/pages/Headless.js +49 -0
- package/lib/client/pages/Home.d.ts +1 -0
- package/lib/client/pages/Home.js +67 -0
- package/lib/client/pages/PostForm.d.ts +1 -0
- package/lib/client/pages/PostForm.js +55 -0
- package/lib/client/pages/Posts.d.ts +1 -0
- package/lib/client/pages/Posts.js +35 -0
- package/lib/client/pages/Profile.d.ts +1 -0
- package/lib/client/pages/Profile.js +153 -0
- package/lib/client/pages/ResetPassword.d.ts +8 -0
- package/lib/client/pages/ResetPassword.js +52 -0
- package/lib/client/pages/Routing.d.ts +1 -0
- package/lib/client/pages/Routing.js +192 -0
- package/lib/client/pages/Storage.d.ts +1 -0
- package/lib/client/pages/Storage.js +54 -0
- package/lib/client/pages/Testing.d.ts +1 -0
- package/lib/client/pages/Testing.js +141 -0
- package/lib/client/pages/Validation.d.ts +1 -0
- package/lib/client/pages/Validation.js +123 -0
- package/lib/client/pages/admin/Categories.d.ts +2 -0
- package/lib/client/pages/admin/Categories.js +75 -0
- package/lib/client/pages/admin/Comments.d.ts +11 -0
- package/lib/client/pages/admin/Comments.js +247 -0
- package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
- package/lib/client/pages/admin/ContentTypes.js +163 -0
- package/lib/client/pages/admin/Dashboard.d.ts +2 -0
- package/lib/client/pages/admin/Dashboard.js +66 -0
- package/lib/client/pages/admin/Health.d.ts +12 -0
- package/lib/client/pages/admin/Health.js +148 -0
- package/lib/client/pages/admin/Media.d.ts +2 -0
- package/lib/client/pages/admin/Media.js +101 -0
- package/lib/client/pages/admin/Navigation.d.ts +9 -0
- package/lib/client/pages/admin/Navigation.js +230 -0
- package/lib/client/pages/admin/Pages.d.ts +2 -0
- package/lib/client/pages/admin/Pages.js +53 -0
- package/lib/client/pages/admin/PostEditor.d.ts +17 -0
- package/lib/client/pages/admin/PostEditor.js +532 -0
- package/lib/client/pages/admin/Posts.d.ts +2 -0
- package/lib/client/pages/admin/Posts.js +152 -0
- package/lib/client/pages/admin/Redirects.d.ts +10 -0
- package/lib/client/pages/admin/Redirects.js +87 -0
- package/lib/client/pages/admin/Settings.d.ts +2 -0
- package/lib/client/pages/admin/Settings.js +111 -0
- package/lib/client/pages/admin/Snippets.d.ts +14 -0
- package/lib/client/pages/admin/Snippets.js +85 -0
- package/lib/client/pages/admin/Tags.d.ts +2 -0
- package/lib/client/pages/admin/Tags.js +74 -0
- package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
- package/lib/client/pages/admin/Taxonomies.js +130 -0
- package/lib/client/pages/admin/Tokens.d.ts +9 -0
- package/lib/client/pages/admin/Tokens.js +260 -0
- package/lib/client/pages/admin/Tools.d.ts +12 -0
- package/lib/client/pages/admin/Tools.js +111 -0
- package/lib/client/pages/admin/Users.d.ts +13 -0
- package/lib/client/pages/admin/Users.js +313 -0
- package/lib/client/pages/api-reference.d.ts +33 -0
- package/lib/client/pages/api-reference.js +198 -0
- package/lib/client/styles.css +37 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.js +39 -0
- package/lib/controllers/AdminController.d.ts +46 -0
- package/lib/controllers/AdminController.js +134 -0
- package/lib/controllers/AuthController.d.ts +15 -0
- package/lib/controllers/AuthController.js +194 -0
- package/lib/controllers/AuthorController.d.ts +17 -0
- package/lib/controllers/AuthorController.js +19 -0
- package/lib/controllers/CategoryController.d.ts +10 -0
- package/lib/controllers/CategoryController.js +88 -0
- package/lib/controllers/CommentController.d.ts +68 -0
- package/lib/controllers/CommentController.js +438 -0
- package/lib/controllers/ContentTypeController.d.ts +24 -0
- package/lib/controllers/ContentTypeController.js +91 -0
- package/lib/controllers/EmailVerificationController.d.ts +33 -0
- package/lib/controllers/EmailVerificationController.js +116 -0
- package/lib/controllers/ExportController.d.ts +15 -0
- package/lib/controllers/ExportController.js +41 -0
- package/lib/controllers/FeedController.d.ts +14 -0
- package/lib/controllers/FeedController.js +246 -0
- package/lib/controllers/HealthController.d.ts +21 -0
- package/lib/controllers/HealthController.js +176 -0
- package/lib/controllers/HomeController.d.ts +12 -0
- package/lib/controllers/HomeController.js +16 -0
- package/lib/controllers/MediaController.d.ts +24 -0
- package/lib/controllers/MediaController.js +189 -0
- package/lib/controllers/NavigationController.d.ts +22 -0
- package/lib/controllers/NavigationController.js +176 -0
- package/lib/controllers/PageController.d.ts +13 -0
- package/lib/controllers/PageController.js +172 -0
- package/lib/controllers/PasskeyController.d.ts +36 -0
- package/lib/controllers/PasskeyController.js +201 -0
- package/lib/controllers/PasswordResetController.d.ts +44 -0
- package/lib/controllers/PasswordResetController.js +160 -0
- package/lib/controllers/PostController.d.ts +51 -0
- package/lib/controllers/PostController.js +538 -0
- package/lib/controllers/PostLockController.d.ts +62 -0
- package/lib/controllers/PostLockController.js +101 -0
- package/lib/controllers/ProfileController.d.ts +13 -0
- package/lib/controllers/ProfileController.js +160 -0
- package/lib/controllers/PublicApiController.d.ts +23 -0
- package/lib/controllers/PublicApiController.js +100 -0
- package/lib/controllers/RedirectController.d.ts +32 -0
- package/lib/controllers/RedirectController.js +95 -0
- package/lib/controllers/SettingsController.d.ts +28 -0
- package/lib/controllers/SettingsController.js +105 -0
- package/lib/controllers/SnippetController.d.ts +27 -0
- package/lib/controllers/SnippetController.js +123 -0
- package/lib/controllers/TagController.d.ts +9 -0
- package/lib/controllers/TagController.js +70 -0
- package/lib/controllers/TaxonomyController.d.ts +24 -0
- package/lib/controllers/TaxonomyController.js +149 -0
- package/lib/controllers/TokenController.d.ts +27 -0
- package/lib/controllers/TokenController.js +83 -0
- package/lib/controllers/TwoFactorController.d.ts +31 -0
- package/lib/controllers/TwoFactorController.js +213 -0
- package/lib/controllers/UserController.d.ts +110 -0
- package/lib/controllers/UserController.js +504 -0
- package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
- package/lib/features/analytics/AnalyticsPage.js +123 -0
- package/lib/features/analytics/admin.d.ts +3 -0
- package/lib/features/analytics/admin.js +9 -0
- package/lib/features/analytics/controller.d.ts +19 -0
- package/lib/features/analytics/controller.js +79 -0
- package/lib/features/analytics/helpers.d.ts +84 -0
- package/lib/features/analytics/helpers.js +181 -0
- package/lib/features/analytics/i18n/es.d.ts +4 -0
- package/lib/features/analytics/i18n/es.js +31 -0
- package/lib/features/analytics/index.d.ts +28 -0
- package/lib/features/analytics/index.js +91 -0
- package/lib/features/analytics/manifest.d.ts +8 -0
- package/lib/features/analytics/manifest.js +18 -0
- package/lib/features/analytics/model.d.ts +130 -0
- package/lib/features/analytics/model.js +206 -0
- package/lib/features/members/Member.d.ts +93 -0
- package/lib/features/members/Member.js +194 -0
- package/lib/features/members/MemberAdminController.d.ts +60 -0
- package/lib/features/members/MemberAdminController.js +262 -0
- package/lib/features/members/MemberController.d.ts +88 -0
- package/lib/features/members/MemberController.js +250 -0
- package/lib/features/members/MembersPage.d.ts +10 -0
- package/lib/features/members/MembersPage.js +216 -0
- package/lib/features/members/PostAccessBox.d.ts +15 -0
- package/lib/features/members/PostAccessBox.js +70 -0
- package/lib/features/members/admin.d.ts +3 -0
- package/lib/features/members/admin.js +12 -0
- package/lib/features/members/csv.d.ts +21 -0
- package/lib/features/members/csv.js +74 -0
- package/lib/features/members/events.d.ts +34 -0
- package/lib/features/members/events.js +34 -0
- package/lib/features/members/i18n/es.d.ts +4 -0
- package/lib/features/members/i18n/es.js +106 -0
- package/lib/features/members/index.d.ts +44 -0
- package/lib/features/members/index.js +106 -0
- package/lib/features/members/manifest.d.ts +8 -0
- package/lib/features/members/manifest.js +18 -0
- package/lib/features/members/middleware.d.ts +42 -0
- package/lib/features/members/middleware.js +74 -0
- package/lib/features/members/newsletter.d.ts +177 -0
- package/lib/features/members/newsletter.js +439 -0
- package/lib/features/members/rate-limits.d.ts +34 -0
- package/lib/features/members/rate-limits.js +50 -0
- package/lib/features/members/request.d.ts +13 -0
- package/lib/features/members/request.js +6 -0
- package/lib/features/members/routes.d.ts +15 -0
- package/lib/features/members/routes.js +59 -0
- package/lib/features/members/session.d.ts +102 -0
- package/lib/features/members/session.js +158 -0
- package/lib/features/members/settings.d.ts +14 -0
- package/lib/features/members/settings.js +23 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
- package/lib/features/mysendbox/admin.d.ts +3 -0
- package/lib/features/mysendbox/admin.js +9 -0
- package/lib/features/mysendbox/broadcasts.d.ts +61 -0
- package/lib/features/mysendbox/broadcasts.js +124 -0
- package/lib/features/mysendbox/client.d.ts +95 -0
- package/lib/features/mysendbox/client.js +61 -0
- package/lib/features/mysendbox/config.d.ts +27 -0
- package/lib/features/mysendbox/config.js +74 -0
- package/lib/features/mysendbox/contacts.d.ts +121 -0
- package/lib/features/mysendbox/contacts.js +378 -0
- package/lib/features/mysendbox/controller.d.ts +11 -0
- package/lib/features/mysendbox/controller.js +47 -0
- package/lib/features/mysendbox/i18n/es.d.ts +4 -0
- package/lib/features/mysendbox/i18n/es.js +28 -0
- package/lib/features/mysendbox/index.d.ts +18 -0
- package/lib/features/mysendbox/index.js +71 -0
- package/lib/features/mysendbox/manifest.d.ts +7 -0
- package/lib/features/mysendbox/manifest.js +6 -0
- package/lib/features/mysendbox/routes.d.ts +6 -0
- package/lib/features/mysendbox/routes.js +14 -0
- package/lib/features/mysendbox/webhook.d.ts +23 -0
- package/lib/features/mysendbox/webhook.js +104 -0
- package/lib/features/theme/OEmbedController.d.ts +31 -0
- package/lib/features/theme/OEmbedController.js +128 -0
- package/lib/features/theme/ThemeController.d.ts +20 -0
- package/lib/features/theme/ThemeController.js +256 -0
- package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
- package/lib/features/theme/ThemeSettingsCard.js +12 -0
- package/lib/features/theme/admin.d.ts +3 -0
- package/lib/features/theme/admin.js +9 -0
- package/lib/features/theme/html.d.ts +48 -0
- package/lib/features/theme/html.js +97 -0
- package/lib/features/theme/i18n/es.d.ts +4 -0
- package/lib/features/theme/i18n/es.js +9 -0
- package/lib/features/theme/index.d.ts +11 -0
- package/lib/features/theme/index.js +23 -0
- package/lib/features/theme/manifest.d.ts +7 -0
- package/lib/features/theme/manifest.js +6 -0
- package/lib/features/theme/oembed.d.ts +36 -0
- package/lib/features/theme/oembed.js +58 -0
- package/lib/features/theme/routes.d.ts +17 -0
- package/lib/features/theme/routes.js +54 -0
- package/lib/features/theme/templates.d.ts +103 -0
- package/lib/features/theme/templates.js +283 -0
- package/lib/features.d.ts +15 -0
- package/lib/features.js +6 -0
- package/lib/features.manifest.d.ts +10 -0
- package/lib/features.manifest.js +6 -0
- package/lib/helpers/access.d.ts +62 -0
- package/lib/helpers/access.js +92 -0
- package/lib/helpers/api.d.ts +20 -0
- package/lib/helpers/api.js +44 -0
- package/lib/helpers/comment-guard.d.ts +145 -0
- package/lib/helpers/comment-guard.js +253 -0
- package/lib/helpers/comment-mail.d.ts +53 -0
- package/lib/helpers/comment-mail.js +188 -0
- package/lib/helpers/content-model.d.ts +50 -0
- package/lib/helpers/content-model.js +84 -0
- package/lib/helpers/content-paths.d.ts +107 -0
- package/lib/helpers/content-paths.js +200 -0
- package/lib/helpers/export-data.d.ts +85 -0
- package/lib/helpers/export-data.js +229 -0
- package/lib/helpers/gating.d.ts +53 -0
- package/lib/helpers/gating.js +83 -0
- package/lib/helpers/health.d.ts +91 -0
- package/lib/helpers/health.js +279 -0
- package/lib/helpers/heartbeat.d.ts +35 -0
- package/lib/helpers/heartbeat.js +55 -0
- package/lib/helpers/image-size.d.ts +18 -0
- package/lib/helpers/image-size.js +83 -0
- package/lib/helpers/images.d.ts +29 -0
- package/lib/helpers/images.js +41 -0
- package/lib/helpers/mail-templates.d.ts +11 -0
- package/lib/helpers/mail-templates.js +42 -0
- package/lib/helpers/publish-due.d.ts +28 -0
- package/lib/helpers/publish-due.js +67 -0
- package/lib/helpers/redirects.d.ts +43 -0
- package/lib/helpers/redirects.js +80 -0
- package/lib/helpers/seo-fields.d.ts +13 -0
- package/lib/helpers/seo-fields.js +52 -0
- package/lib/helpers/session.d.ts +30 -0
- package/lib/helpers/session.js +27 -0
- package/lib/helpers/site-settings.d.ts +98 -0
- package/lib/helpers/site-settings.js +232 -0
- package/lib/helpers/site.d.ts +14 -0
- package/lib/helpers/site.js +23 -0
- package/lib/helpers/write-hooks.d.ts +33 -0
- package/lib/helpers/write-hooks.js +37 -0
- package/lib/hooks.d.ts +17 -0
- package/lib/hooks.js +101 -0
- package/lib/host/core-tasks.d.ts +4 -0
- package/lib/host/core-tasks.js +26 -0
- package/lib/host/cron.d.ts +39 -0
- package/lib/host/cron.js +85 -0
- package/lib/host/enabled.d.ts +4 -0
- package/lib/host/enabled.js +40 -0
- package/lib/host/index.d.ts +81 -0
- package/lib/host/index.js +87 -0
- package/lib/host/manifest.d.ts +34 -0
- package/lib/host/manifest.js +7 -0
- package/lib/host/menu.d.ts +18 -0
- package/lib/host/menu.js +15 -0
- package/lib/main.d.ts +1 -0
- package/lib/main.js +24 -0
- package/lib/middleware/api-auth.d.ts +59 -0
- package/lib/middleware/api-auth.js +164 -0
- package/lib/middleware/auth.d.ts +49 -0
- package/lib/middleware/auth.js +112 -0
- package/lib/middleware/cache.d.ts +17 -0
- package/lib/middleware/cache.js +52 -0
- package/lib/middleware/rate-limits.d.ts +199 -0
- package/lib/middleware/rate-limits.js +276 -0
- package/lib/middleware/viewer.d.ts +13 -0
- package/lib/middleware/viewer.js +16 -0
- package/lib/models/Category.d.ts +24 -0
- package/lib/models/Category.js +102 -0
- package/lib/models/Comment.d.ts +120 -0
- package/lib/models/Comment.js +283 -0
- package/lib/models/ContentType.d.ts +142 -0
- package/lib/models/ContentType.js +462 -0
- package/lib/models/Credential.d.ts +21 -0
- package/lib/models/Credential.js +31 -0
- package/lib/models/Media.d.ts +53 -0
- package/lib/models/Media.js +132 -0
- package/lib/models/Menu.d.ts +131 -0
- package/lib/models/Menu.js +312 -0
- package/lib/models/Page.d.ts +55 -0
- package/lib/models/Page.js +218 -0
- package/lib/models/Post.d.ts +136 -0
- package/lib/models/Post.js +406 -0
- package/lib/models/PostLock.d.ts +67 -0
- package/lib/models/PostLock.js +112 -0
- package/lib/models/PostRevision.d.ts +45 -0
- package/lib/models/PostRevision.js +82 -0
- package/lib/models/PublicContent.d.ts +283 -0
- package/lib/models/PublicContent.js +577 -0
- package/lib/models/Redirect.d.ts +123 -0
- package/lib/models/Redirect.js +225 -0
- package/lib/models/Settings.d.ts +61 -0
- package/lib/models/Settings.js +128 -0
- package/lib/models/Snippet.d.ts +36 -0
- package/lib/models/Snippet.js +64 -0
- package/lib/models/Tag.d.ts +23 -0
- package/lib/models/Tag.js +117 -0
- package/lib/models/Taxonomy.d.ts +127 -0
- package/lib/models/Taxonomy.js +321 -0
- package/lib/models/TwoFactor.d.ts +26 -0
- package/lib/models/TwoFactor.js +60 -0
- package/lib/models/User.d.ts +49 -0
- package/lib/models/User.js +128 -0
- package/lib/models/derive.d.ts +69 -0
- package/lib/models/derive.js +81 -0
- package/lib/models/pagination.d.ts +30 -0
- package/lib/models/pagination.js +36 -0
- package/lib/models/visibility.d.ts +31 -0
- package/lib/models/visibility.js +47 -0
- package/lib/routes/App.d.ts +2 -0
- package/lib/routes/App.js +146 -0
- package/lib/routes/api/admin.d.ts +6 -0
- package/lib/routes/api/admin.js +11 -0
- package/lib/routes/api/auth.d.ts +6 -0
- package/lib/routes/api/auth.js +24 -0
- package/lib/routes/api/authors.d.ts +5 -0
- package/lib/routes/api/authors.js +8 -0
- package/lib/routes/api/categories.d.ts +8 -0
- package/lib/routes/api/categories.js +15 -0
- package/lib/routes/api/comments.d.ts +8 -0
- package/lib/routes/api/comments.js +35 -0
- package/lib/routes/api/content-model.d.ts +17 -0
- package/lib/routes/api/content-model.js +67 -0
- package/lib/routes/api/cron.d.ts +6 -0
- package/lib/routes/api/cron.js +9 -0
- package/lib/routes/api/export.d.ts +5 -0
- package/lib/routes/api/export.js +11 -0
- package/lib/routes/api/feed.d.ts +5 -0
- package/lib/routes/api/feed.js +16 -0
- package/lib/routes/api/media.d.ts +8 -0
- package/lib/routes/api/media.js +25 -0
- package/lib/routes/api/navigation.d.ts +12 -0
- package/lib/routes/api/navigation.js +17 -0
- package/lib/routes/api/ops.d.ts +9 -0
- package/lib/routes/api/ops.js +19 -0
- package/lib/routes/api/pages.d.ts +8 -0
- package/lib/routes/api/pages.js +21 -0
- package/lib/routes/api/passkeys.d.ts +7 -0
- package/lib/routes/api/passkeys.js +13 -0
- package/lib/routes/api/posts.d.ts +8 -0
- package/lib/routes/api/posts.js +39 -0
- package/lib/routes/api/profile.d.ts +6 -0
- package/lib/routes/api/profile.js +8 -0
- package/lib/routes/api/redirects.d.ts +12 -0
- package/lib/routes/api/redirects.js +13 -0
- package/lib/routes/api/settings.d.ts +8 -0
- package/lib/routes/api/settings.js +15 -0
- package/lib/routes/api/snippets.d.ts +15 -0
- package/lib/routes/api/snippets.js +16 -0
- package/lib/routes/api/tags.d.ts +8 -0
- package/lib/routes/api/tags.js +14 -0
- package/lib/routes/api/tokens.d.ts +7 -0
- package/lib/routes/api/tokens.js +15 -0
- package/lib/routes/api/two-factor.d.ts +7 -0
- package/lib/routes/api/two-factor.js +15 -0
- package/lib/routes/api/users.d.ts +8 -0
- package/lib/routes/api/users.js +25 -0
- package/lib/routes/api/v1.d.ts +12 -0
- package/lib/routes/api/v1.js +55 -0
- package/lib/routes/api/verification.d.ts +6 -0
- package/lib/routes/api/verification.js +11 -0
- package/lib/server/index.d.ts +24 -0
- package/lib/server/index.js +110 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.js +1 -0
- package/lib/vite.d.ts +2 -0
- package/lib/vite.js +101 -0
- package/mail/comment-moderation.html +27 -0
- package/mail/comment-moderation.txt +13 -0
- package/mail/comment-reply.html +28 -0
- package/mail/comment-reply.txt +14 -0
- package/mail/invitation.html +25 -0
- package/mail/invitation.txt +11 -0
- package/mail/member-magic-link.html +23 -0
- package/mail/member-magic-link.txt +10 -0
- package/mail/newsletter.html +26 -0
- package/mail/newsletter.txt +13 -0
- package/mail/password-reset.html +26 -0
- package/mail/password-reset.txt +10 -0
- package/mail/verify-email.html +25 -0
- package/mail/verify-email.txt +8 -0
- package/package.json +85 -4
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { validate, rules } from '@basicbenframework/core/validation';
|
|
2
|
+
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
3
|
+
import { can } from '@basicbenframework/core/auth/permissions';
|
|
4
|
+
import { Post } from "../models/Post.js";
|
|
5
|
+
import { paginationFrom, meta } from "../models/pagination.js";
|
|
6
|
+
import { PostRevision } from "../models/PostRevision.js";
|
|
7
|
+
import { seoFields } from "../helpers/seo-fields.js";
|
|
8
|
+
import { LISTING_FILTERS } from "../models/Post.js";
|
|
9
|
+
import { POST_STATUSES, toStoredTimestamp } from "../models/visibility.js";
|
|
10
|
+
import { lockConflict } from "./PostLockController.js";
|
|
11
|
+
import { redirectIfSlugChanged, releasePath } from "../helpers/redirects.js";
|
|
12
|
+
import { withholdBody } from "../helpers/gating.js";
|
|
13
|
+
import { accessLevels, viewerOf } from "../helpers/access.js";
|
|
14
|
+
import { guardWrite } from "../helpers/write-hooks.js";
|
|
15
|
+
import { typeAndFields, saveTerms, publicPathOf, editorExtras } from "../helpers/content-model.js";
|
|
16
|
+
/**
|
|
17
|
+
* Hooks fire from here so an app can take part in the content lifecycle.
|
|
18
|
+
*
|
|
19
|
+
* The `*.creating` and `*.updating` hooks are **filters**: a listener receives
|
|
20
|
+
* the data and returns it, possibly changed, or returns `{ cancel: true }` to
|
|
21
|
+
* refuse the write. The `*.created`, `*.updated` and `*.deleted` hooks are
|
|
22
|
+
* notifications — the write has happened and their return value is ignored.
|
|
23
|
+
*
|
|
24
|
+
* These live in the controller rather than the model because models here are
|
|
25
|
+
* hand-written plain objects with no base class to hang a lifecycle on. The
|
|
26
|
+
* cost is that an app which rewrites a controller has to keep the calls.
|
|
27
|
+
*/
|
|
28
|
+
export const PostController = {
|
|
29
|
+
async index(req, res) {
|
|
30
|
+
const { page, perPage, offset } = paginationFrom(req.query);
|
|
31
|
+
// An editor or an admin sees the whole site; an author sees their own work.
|
|
32
|
+
// The listing was scoped to the signed-in user unconditionally, so the
|
|
33
|
+
// people with `post.edit` — the ones responsible for everyone else's posts
|
|
34
|
+
// — could not see a single one of them.
|
|
35
|
+
const query = req.query;
|
|
36
|
+
const filter = LISTING_FILTERS.includes(query.status ?? '')
|
|
37
|
+
? query.status
|
|
38
|
+
: 'all';
|
|
39
|
+
const search = query.search?.trim().slice(0, 200) || undefined;
|
|
40
|
+
const userId = can(req.user, 'post.edit') ? undefined : req.userId;
|
|
41
|
+
// One content type at a time, `post` unless asked: the Posts screen and
|
|
42
|
+
// every client written before content types existed see only posts.
|
|
43
|
+
// `?type=any` lists every type.
|
|
44
|
+
const type = query.type === 'any' ? undefined : (query.type?.trim() || 'post');
|
|
45
|
+
const { posts, total } = await Post.paginate({ perPage, offset, userId, filter, search, type });
|
|
46
|
+
// `posts` stays where it was so nothing reading this breaks; `meta` is
|
|
47
|
+
// added alongside, in the same shape /api/v1 uses. `counts` sizes the
|
|
48
|
+
// status tabs.
|
|
49
|
+
res.json({ posts, meta: meta(page, perPage, total), counts: await Post.counts(userId, type) });
|
|
50
|
+
},
|
|
51
|
+
async show(req, res) {
|
|
52
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
53
|
+
if (!post || !mayEdit(req, post)) {
|
|
54
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
55
|
+
}
|
|
56
|
+
// The editor needs the current selection to check the right boxes, and a
|
|
57
|
+
// post has many of each now.
|
|
58
|
+
const taxonomy = await Post.taxonomy(post.id);
|
|
59
|
+
// An autosave newer than the post is work the author has not saved —
|
|
60
|
+
// a closed tab, a crash. The editor offers it back rather than losing it.
|
|
61
|
+
const autosave = await PostRevision.pendingAutosave(post.id, req.userId, String(post.updated_at ?? post.created_at));
|
|
62
|
+
res.json({
|
|
63
|
+
post: { ...post, category_ids: taxonomy.categories, tag_ids: taxonomy.tags, ...(await editorExtras(post)) },
|
|
64
|
+
autosave: autosave ?? null
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async store(req, res) {
|
|
68
|
+
const result = await validate(req.body, {
|
|
69
|
+
title: [rules.required, rules.string, rules.min(3), rules.max(200)],
|
|
70
|
+
content: [rules.required, rules.string, rules.min(10)]
|
|
71
|
+
});
|
|
72
|
+
if (result.fails()) {
|
|
73
|
+
return res.json({ errors: result.errors }, 422);
|
|
74
|
+
}
|
|
75
|
+
const fields = editableFields(req.body, null);
|
|
76
|
+
if ('errors' in fields)
|
|
77
|
+
return res.json({ errors: fields.errors }, 422);
|
|
78
|
+
// Content type and custom fields; see helpers/content-model.ts.
|
|
79
|
+
const typed = await typeAndFields(req.body, null);
|
|
80
|
+
if ('errors' in typed)
|
|
81
|
+
return res.json({ errors: typed.errors }, 422);
|
|
82
|
+
Object.assign(fields.values, typed.values);
|
|
83
|
+
const publishing = resolvePublishing(req, null);
|
|
84
|
+
if ('error' in publishing)
|
|
85
|
+
return res.json({ error: publishing.error }, publishing.status);
|
|
86
|
+
const creating = await guardWrite(HOOKS.POST_CREATING, {
|
|
87
|
+
// Attribution. Anyone may write as themselves; assigning a post to
|
|
88
|
+
// someone else is `post.edit`, the same capability that lets you edit
|
|
89
|
+
// their work — the WordPress rule, where only an editor can hand a post
|
|
90
|
+
// to another author.
|
|
91
|
+
user_id: authorFor(req),
|
|
92
|
+
...fields.values,
|
|
93
|
+
...publishing.values
|
|
94
|
+
}, { req }, { refused: 'Post rejected.' });
|
|
95
|
+
if (!creating.ok)
|
|
96
|
+
return res.json({ error: creating.error }, creating.status);
|
|
97
|
+
const draft = creating.value;
|
|
98
|
+
// Checked again after the filter, so a listener cannot publish on behalf
|
|
99
|
+
// of someone who may not. Publishing is its own capability: a contributor
|
|
100
|
+
// writes drafts and submits them for review; someone with `post.publish`
|
|
101
|
+
// puts them live.
|
|
102
|
+
if (draft?.published && !can(req.user, 'post.publish')) {
|
|
103
|
+
return res.json({ error: 'You do not have permission to publish posts.' }, 403);
|
|
104
|
+
}
|
|
105
|
+
const post = await Post.create(draft);
|
|
106
|
+
// A live post on a path an old redirect still claims would never be
|
|
107
|
+
// reached; pages release their path the same way.
|
|
108
|
+
if (post?.published && post.slug)
|
|
109
|
+
await releasePath(await publicPathOf(post));
|
|
110
|
+
// Categories and tags were accepted by the editor and dropped here — the
|
|
111
|
+
// request carried them, nothing read them, and the selection silently did
|
|
112
|
+
// nothing. They are persisted separately from the post row because both
|
|
113
|
+
// are many-to-many.
|
|
114
|
+
await saveTaxonomy(post.id, req.body);
|
|
115
|
+
await saveTerms(post.id, req.body);
|
|
116
|
+
await hooks.fire(HOOKS.POST_CREATED, { post, userId: req.userId });
|
|
117
|
+
res.json({ post }, 201);
|
|
118
|
+
},
|
|
119
|
+
async update(req, res) {
|
|
120
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
121
|
+
if (!post || !mayEdit(req, post)) {
|
|
122
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
123
|
+
}
|
|
124
|
+
const result = await validate(req.body, {
|
|
125
|
+
title: [rules.required, rules.string, rules.min(3), rules.max(200)],
|
|
126
|
+
content: [rules.required, rules.string, rules.min(10)]
|
|
127
|
+
});
|
|
128
|
+
if (result.fails()) {
|
|
129
|
+
return res.json({ errors: result.errors }, 422);
|
|
130
|
+
}
|
|
131
|
+
// Once a post is live, changing it is changing the site. A contributor may
|
|
132
|
+
// edit their own drafts and nothing that is published, which is the
|
|
133
|
+
// WordPress rule.
|
|
134
|
+
if (post.published && !can(req.user, 'post.publish')) {
|
|
135
|
+
return res.json({ error: 'You do not have permission to edit a published post.' }, 403);
|
|
136
|
+
}
|
|
137
|
+
if (post.deleted_at) {
|
|
138
|
+
return res.json({ error: 'Restore this post from the trash before editing it.' }, 409);
|
|
139
|
+
}
|
|
140
|
+
// Someone else has it open in the editor; see PostLockController.
|
|
141
|
+
const locked = await lockConflict(req, post);
|
|
142
|
+
if (locked)
|
|
143
|
+
return res.json(locked, 409);
|
|
144
|
+
const reassigned = authorFor(req, post.user_id);
|
|
145
|
+
const fields = editableFields(req.body, post);
|
|
146
|
+
if ('errors' in fields)
|
|
147
|
+
return res.json({ errors: fields.errors }, 422);
|
|
148
|
+
const typed = await typeAndFields(req.body, post);
|
|
149
|
+
if ('errors' in typed)
|
|
150
|
+
return res.json({ errors: typed.errors }, 422);
|
|
151
|
+
Object.assign(fields.values, typed.values);
|
|
152
|
+
// Absent means "leave it as it is". Coercing an absent key to 0 turned
|
|
153
|
+
// every request that did not mention publishing into an unpublish.
|
|
154
|
+
const publishing = resolvePublishing(req, post);
|
|
155
|
+
if ('error' in publishing)
|
|
156
|
+
return res.json({ error: publishing.error }, publishing.status);
|
|
157
|
+
const updating = await guardWrite(HOOKS.POST_UPDATING, {
|
|
158
|
+
...fields.values,
|
|
159
|
+
...(reassigned === post.user_id ? {} : { user_id: reassigned }),
|
|
160
|
+
...publishing.values
|
|
161
|
+
}, { req, post }, { refused: 'Update rejected.' });
|
|
162
|
+
if (!updating.ok)
|
|
163
|
+
return res.json({ error: updating.error }, updating.status);
|
|
164
|
+
const changes = updating.value;
|
|
165
|
+
if (changes?.published && !can(req.user, 'post.publish')) {
|
|
166
|
+
return res.json({ error: 'You do not have permission to publish posts.' }, 403);
|
|
167
|
+
}
|
|
168
|
+
// What it said before, so this save can be undone.
|
|
169
|
+
await PostRevision.snapshot(post, changes, req.userId ?? null);
|
|
170
|
+
const updated = await Post.update(parseInt(req.params.id), changes);
|
|
171
|
+
// A published post whose slug changed keeps its old URL working (a 301).
|
|
172
|
+
await redirectIfSlugChanged('post', post, updated);
|
|
173
|
+
// A real save supersedes whatever was autosaved while typing it.
|
|
174
|
+
await PostRevision.clearAutosave(post.id, req.userId);
|
|
175
|
+
await saveTaxonomy(parseInt(req.params.id), req.body);
|
|
176
|
+
await saveTerms(post.id, req.body, updated?.post_type !== post.post_type);
|
|
177
|
+
await hooks.fire(HOOKS.POST_UPDATED, { post: updated, previous: post, userId: req.userId });
|
|
178
|
+
res.json({ post: updated });
|
|
179
|
+
},
|
|
180
|
+
async destroy(req, res) {
|
|
181
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
182
|
+
if (!post || !mayEdit(req, post)) {
|
|
183
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
184
|
+
}
|
|
185
|
+
// Seeing a post is not the same as being allowed to remove it.
|
|
186
|
+
if (!can(req.user, 'post.delete', post)) {
|
|
187
|
+
return res.json({ error: 'You do not have permission to delete this post.' }, 403);
|
|
188
|
+
}
|
|
189
|
+
// A token may trash, which a person can undo; emptying the trash cannot be
|
|
190
|
+
// undone, so that stays with someone signed in.
|
|
191
|
+
if (req.apiToken && post.deleted_at) {
|
|
192
|
+
return res.json({ error: 'Deleting a post permanently requires a signed-in session.' }, 403);
|
|
193
|
+
}
|
|
194
|
+
const outcome = await removePost(req, post);
|
|
195
|
+
if ('error' in outcome)
|
|
196
|
+
return res.json({ error: outcome.error }, outcome.status);
|
|
197
|
+
res.json({ message: outcome.message, trashed: outcome.trashed });
|
|
198
|
+
},
|
|
199
|
+
/** Take a post back out of the trash. */
|
|
200
|
+
async restore(req, res) {
|
|
201
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
202
|
+
if (!post || !mayEdit(req, post)) {
|
|
203
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
204
|
+
}
|
|
205
|
+
const outcome = await restorePost(req, post);
|
|
206
|
+
if ('error' in outcome)
|
|
207
|
+
return res.json({ error: outcome.error }, outcome.status);
|
|
208
|
+
res.json({ post: await Post.find(post.id) });
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* One action over many posts: trash, restore, delete, publish, draft.
|
|
212
|
+
*
|
|
213
|
+
* Each post is checked exactly as the single-post endpoint would check it,
|
|
214
|
+
* so selecting forty rows cannot do to one of them what you could not do to
|
|
215
|
+
* it alone. What failed is reported per post rather than failing the batch.
|
|
216
|
+
*/
|
|
217
|
+
async bulk(req, res) {
|
|
218
|
+
const { action, ids } = (req.body ?? {});
|
|
219
|
+
const actions = ['trash', 'restore', 'delete', 'publish', 'draft'];
|
|
220
|
+
if (!action || !actions.includes(action) || !Array.isArray(ids) || ids.length === 0) {
|
|
221
|
+
return res.json({ error: `Send an action (${actions.join(', ')}) and a list of ids.` }, 422);
|
|
222
|
+
}
|
|
223
|
+
const unique = [...new Set(ids.map(Number).filter(Number.isInteger))].slice(0, 200);
|
|
224
|
+
const done = [];
|
|
225
|
+
const failed = [];
|
|
226
|
+
for (const id of unique) {
|
|
227
|
+
const post = await Post.find(id);
|
|
228
|
+
if (!post || !mayEdit(req, post)) {
|
|
229
|
+
failed.push({ id, error: 'Post not found' });
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
let outcome;
|
|
233
|
+
if (action === 'trash') {
|
|
234
|
+
outcome = post.deleted_at ? { error: 'Already in the trash', status: 409 } : await removePost(req, post);
|
|
235
|
+
}
|
|
236
|
+
else if (action === 'delete') {
|
|
237
|
+
outcome = post.deleted_at ? await removePost(req, post) : { error: 'Move it to the trash first', status: 409 };
|
|
238
|
+
}
|
|
239
|
+
else if (action === 'restore') {
|
|
240
|
+
outcome = await restorePost(req, post);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
outcome = await setStatus(req, post, action === 'publish' ? 'published' : 'draft');
|
|
244
|
+
}
|
|
245
|
+
if ('error' in outcome)
|
|
246
|
+
failed.push({ id, error: String(outcome.error) });
|
|
247
|
+
else
|
|
248
|
+
done.push(id);
|
|
249
|
+
}
|
|
250
|
+
res.json({ done, failed });
|
|
251
|
+
},
|
|
252
|
+
/** Every saved version of a post, newest first. */
|
|
253
|
+
async revisions(req, res) {
|
|
254
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
255
|
+
if (!post || !mayEdit(req, post)) {
|
|
256
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
257
|
+
}
|
|
258
|
+
res.json({ revisions: await PostRevision.list(post.id) });
|
|
259
|
+
},
|
|
260
|
+
/** One revision, with its full text, to compare against the post. */
|
|
261
|
+
async revision(req, res) {
|
|
262
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
263
|
+
if (!post || !mayEdit(req, post)) {
|
|
264
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
265
|
+
}
|
|
266
|
+
const revision = await PostRevision.find(post.id, parseInt(req.params.revisionId));
|
|
267
|
+
if (!revision)
|
|
268
|
+
return res.json({ error: 'Revision not found' }, 404);
|
|
269
|
+
res.json({ revision });
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Put an older version back.
|
|
273
|
+
*
|
|
274
|
+
* A save like any other — it goes through the same capability checks and
|
|
275
|
+
* snapshots the current text first — so restoring is itself undoable.
|
|
276
|
+
*/
|
|
277
|
+
async restoreRevision(req, res) {
|
|
278
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
279
|
+
if (!post || !mayEdit(req, post)) {
|
|
280
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
281
|
+
}
|
|
282
|
+
if (post.published && !can(req.user, 'post.publish')) {
|
|
283
|
+
return res.json({ error: 'You do not have permission to edit a published post.' }, 403);
|
|
284
|
+
}
|
|
285
|
+
const revision = await PostRevision.find(post.id, parseInt(req.params.revisionId));
|
|
286
|
+
if (!revision)
|
|
287
|
+
return res.json({ error: 'Revision not found' }, 404);
|
|
288
|
+
const locked = await lockConflict(req, post);
|
|
289
|
+
if (locked)
|
|
290
|
+
return res.json(locked, 409);
|
|
291
|
+
const changes = { title: revision.title, content: revision.content, excerpt: revision.excerpt ?? '' };
|
|
292
|
+
await PostRevision.snapshot(post, changes, req.userId ?? null);
|
|
293
|
+
const updated = await Post.update(post.id, changes);
|
|
294
|
+
await hooks.fire(HOOKS.POST_UPDATED, { post: updated, previous: post, userId: req.userId });
|
|
295
|
+
res.json({ post: updated });
|
|
296
|
+
},
|
|
297
|
+
/**
|
|
298
|
+
* Keep what is being typed, without saving it.
|
|
299
|
+
*
|
|
300
|
+
* The post is untouched — a live post does not change because its editor
|
|
301
|
+
* paused. The copy waits in the revisions table, one per author, and the
|
|
302
|
+
* editor offers it back if the page is reopened before a real save.
|
|
303
|
+
*/
|
|
304
|
+
async autosave(req, res) {
|
|
305
|
+
const post = await Post.find(parseInt(req.params.id));
|
|
306
|
+
if (!post || !mayEdit(req, post)) {
|
|
307
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
308
|
+
}
|
|
309
|
+
const { title, content, excerpt } = (req.body ?? {});
|
|
310
|
+
if (typeof title !== 'string' || typeof content !== 'string') {
|
|
311
|
+
return res.json({ error: 'title and content are required' }, 422);
|
|
312
|
+
}
|
|
313
|
+
// An autosave is harmless to the post, but one from a tab that lost the
|
|
314
|
+
// lock is typing that will be offered back over the new holder's work.
|
|
315
|
+
const locked = await lockConflict(req, post);
|
|
316
|
+
if (locked)
|
|
317
|
+
return res.json(locked, 409);
|
|
318
|
+
const saved = await PostRevision.autosave(post.id, req.userId, {
|
|
319
|
+
title: title.slice(0, 200),
|
|
320
|
+
content,
|
|
321
|
+
excerpt: typeof excerpt === 'string' ? excerpt : null
|
|
322
|
+
});
|
|
323
|
+
res.json({ autosave: { id: saved?.id, created_at: saved?.created_at } });
|
|
324
|
+
},
|
|
325
|
+
async feed(req, res) {
|
|
326
|
+
// The built-in blog's feed. Restricted bodies are withheld unless the
|
|
327
|
+
// access policy lets this reader have them — see helpers/gating.ts.
|
|
328
|
+
const viewer = await viewerOf(req);
|
|
329
|
+
const posts = (await Post.findPublished()).map((post) => withholdBody(post, viewer));
|
|
330
|
+
res.json({ posts });
|
|
331
|
+
},
|
|
332
|
+
async feedShow(req, res) {
|
|
333
|
+
const post = await Post.findPublishedById(parseInt(req.params.id));
|
|
334
|
+
if (!post) {
|
|
335
|
+
return res.json({ error: 'Post not found' }, 404);
|
|
336
|
+
}
|
|
337
|
+
res.json({ post: withholdBody(post, await viewerOf(req)) });
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* May this request act on this post?
|
|
342
|
+
*
|
|
343
|
+
* Its author always may, which is what every check here used to test on its
|
|
344
|
+
* own. `post.edit` is the capability for everyone else's work, so an editor and
|
|
345
|
+
* an admin stop getting "Post not found" for a post that plainly exists.
|
|
346
|
+
*/
|
|
347
|
+
function mayEdit(req, post) {
|
|
348
|
+
// Through `can()` rather than comparing ids, so the role still counts: an
|
|
349
|
+
// account that lost `post.edit.own` (or never confirmed its address) cannot
|
|
350
|
+
// keep editing posts just because they carry its id.
|
|
351
|
+
return can(req.user, 'post.edit', post);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Who the post belongs to.
|
|
355
|
+
*
|
|
356
|
+
* A `user_id` in the body is honoured only for a caller who can edit anyone's
|
|
357
|
+
* posts; for everyone else it is ignored rather than refused, because a body
|
|
358
|
+
* that carries the author it already had should not fail a save.
|
|
359
|
+
*/
|
|
360
|
+
function authorFor(req, fallback) {
|
|
361
|
+
const requested = Number(req.body.user_id);
|
|
362
|
+
const current = fallback ?? req.userId;
|
|
363
|
+
if (!Number.isInteger(requested) || requested === current)
|
|
364
|
+
return current;
|
|
365
|
+
return can(req.user, 'post.edit') ? requested : current;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The fields the editor sends and the post row stores.
|
|
369
|
+
*
|
|
370
|
+
* Everything but title, content and published used to be dropped here: the SEO
|
|
371
|
+
* panel, the excerpt and the featured image were all accepted by the API and
|
|
372
|
+
* written nowhere. Absent keys stay absent so a caller changing one field does
|
|
373
|
+
* not blank the rest; a blank slug or excerpt is a request to derive one, which
|
|
374
|
+
* the model does.
|
|
375
|
+
*
|
|
376
|
+
* Publishing state — `status`, `published`, `publish_at` — is not here; see
|
|
377
|
+
* `resolvePublishing`, which also decides who may change it.
|
|
378
|
+
*/
|
|
379
|
+
function editableFields(body, existing) {
|
|
380
|
+
const payload = (body ?? {});
|
|
381
|
+
const fields = {};
|
|
382
|
+
const errors = {};
|
|
383
|
+
for (const key of ['title', 'content', 'slug', 'excerpt', 'meta_title', 'meta_description']) {
|
|
384
|
+
if (key in payload)
|
|
385
|
+
fields[key] = payload[key];
|
|
386
|
+
}
|
|
387
|
+
// An id or nothing. The empty string an unset <select> sends would otherwise
|
|
388
|
+
// become a foreign key of '' and fail the write.
|
|
389
|
+
if ('featured_image' in payload) {
|
|
390
|
+
const id = Number(payload.featured_image);
|
|
391
|
+
fields.featured_image = Number.isInteger(id) && id > 0 ? id : null;
|
|
392
|
+
}
|
|
393
|
+
const seo = seoFields(payload);
|
|
394
|
+
if ('errors' in seo)
|
|
395
|
+
Object.assign(errors, seo.errors);
|
|
396
|
+
else
|
|
397
|
+
Object.assign(fields, seo.values);
|
|
398
|
+
// Who may read the body: `public` or a level the access policy offers. The
|
|
399
|
+
// level the post already has is always accepted, so a post saved under a
|
|
400
|
+
// feature that has since been removed can still be edited without being
|
|
401
|
+
// made public by accident.
|
|
402
|
+
if ('visibility' in payload) {
|
|
403
|
+
const levels = accessLevels();
|
|
404
|
+
const value = payload.visibility;
|
|
405
|
+
if (typeof value === 'string' && (levels.includes(value) || value === existing?.visibility))
|
|
406
|
+
fields.visibility = value;
|
|
407
|
+
else
|
|
408
|
+
errors.visibility = [`Must be one of ${levels.join(', ')}`];
|
|
409
|
+
}
|
|
410
|
+
return Object.keys(errors).length ? { errors } : { values: fields };
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Work out the publishing state a request asks for, and whether it may.
|
|
414
|
+
*
|
|
415
|
+
* Accepts `status` (`draft`, `pending`, `published`) and, for clients written
|
|
416
|
+
* before it existed, the old `published` boolean. `publish_at` in the future
|
|
417
|
+
* on a published post is a schedule: the post is stored as published and the
|
|
418
|
+
* public site starts showing it when the time comes.
|
|
419
|
+
*
|
|
420
|
+
* `existing` is null on create. On update, absent keys leave the state alone.
|
|
421
|
+
*/
|
|
422
|
+
function resolvePublishing(req, existing) {
|
|
423
|
+
const body = (req.body ?? {});
|
|
424
|
+
let status;
|
|
425
|
+
if (typeof body.status === 'string') {
|
|
426
|
+
if (!POST_STATUSES.includes(body.status)) {
|
|
427
|
+
return { error: `status must be one of ${POST_STATUSES.join(', ')}`, status: 422 };
|
|
428
|
+
}
|
|
429
|
+
status = body.status;
|
|
430
|
+
}
|
|
431
|
+
else if (body.published !== undefined) {
|
|
432
|
+
status = body.published ? 'published' : 'draft';
|
|
433
|
+
}
|
|
434
|
+
let publishAt;
|
|
435
|
+
if ('publish_at' in body) {
|
|
436
|
+
try {
|
|
437
|
+
publishAt = toStoredTimestamp(body.publish_at);
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
return { error: 'publish_at is not a valid date', status: 422 };
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const values = {};
|
|
444
|
+
const wasPublished = Boolean(existing?.published);
|
|
445
|
+
const finalStatus = status ?? (existing ? undefined : 'draft');
|
|
446
|
+
if (finalStatus === 'published' && !wasPublished && !can(req.user, 'post.publish')) {
|
|
447
|
+
return { error: 'You do not have permission to publish posts.', status: 403 };
|
|
448
|
+
}
|
|
449
|
+
if (finalStatus !== undefined) {
|
|
450
|
+
values.status = finalStatus;
|
|
451
|
+
values.published = finalStatus === 'published' ? 1 : 0;
|
|
452
|
+
}
|
|
453
|
+
if (publishAt !== undefined)
|
|
454
|
+
values.publish_at = publishAt;
|
|
455
|
+
// Going live with no date given means now. A post that was already live
|
|
456
|
+
// keeps the date it went live, so republishing does not reorder the blog.
|
|
457
|
+
const goingLive = finalStatus === 'published' && !wasPublished;
|
|
458
|
+
if (goingLive && !values.publish_at)
|
|
459
|
+
values.publish_at = new Date().toISOString();
|
|
460
|
+
// Webhooks hear about a live post when it is saved; a scheduled one is told
|
|
461
|
+
// by the publish-due tick when its time arrives.
|
|
462
|
+
const effectiveStatus = finalStatus ?? (wasPublished ? 'published' : existing?.status);
|
|
463
|
+
const effectiveAt = (values.publish_at ?? existing?.publish_at ?? null);
|
|
464
|
+
if (effectiveStatus === 'published' && (goingLive || 'publish_at' in values)) {
|
|
465
|
+
values.live_notified = effectiveAt && new Date(effectiveAt).getTime() > Date.now() ? 0 : 1;
|
|
466
|
+
}
|
|
467
|
+
return { values };
|
|
468
|
+
}
|
|
469
|
+
/** Trash a post, or delete it for good if it is already in the trash. */
|
|
470
|
+
async function removePost(req, post) {
|
|
471
|
+
// Seeing a post is not the same as being allowed to remove it.
|
|
472
|
+
if (!can(req.user, 'post.delete', post)) {
|
|
473
|
+
return { error: 'You do not have permission to delete this post.', status: 403 };
|
|
474
|
+
}
|
|
475
|
+
const permanent = Boolean(post.deleted_at);
|
|
476
|
+
const intent = await guardWrite(HOOKS.POST_DELETING, { post, cancel: false, permanent }, { req }, { refused: 'Deletion rejected.' });
|
|
477
|
+
if (!intent.ok)
|
|
478
|
+
return { error: intent.error, status: intent.status };
|
|
479
|
+
if (permanent) {
|
|
480
|
+
await Post.delete(post.id);
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
await Post.trash(post.id);
|
|
484
|
+
}
|
|
485
|
+
// Fired on trashing: that is when the post leaves the public site, which is
|
|
486
|
+
// what a webhook consumer needs to hear.
|
|
487
|
+
await hooks.fire(HOOKS.POST_DELETED, { post, userId: req.userId, permanent });
|
|
488
|
+
return permanent
|
|
489
|
+
? { message: 'Post deleted permanently', trashed: false }
|
|
490
|
+
: { message: 'Post moved to the trash', trashed: true };
|
|
491
|
+
}
|
|
492
|
+
async function restorePost(req, post) {
|
|
493
|
+
if (!post.deleted_at)
|
|
494
|
+
return { error: 'This post is not in the trash.', status: 409 };
|
|
495
|
+
if (!can(req.user, 'post.delete', post)) {
|
|
496
|
+
return { error: 'You do not have permission to restore this post.', status: 403 };
|
|
497
|
+
}
|
|
498
|
+
await Post.restore(post.id);
|
|
499
|
+
const restored = await Post.find(post.id);
|
|
500
|
+
await hooks.fire(HOOKS.POST_UPDATED, { post: restored, previous: post, userId: req.userId });
|
|
501
|
+
return { ok: true };
|
|
502
|
+
}
|
|
503
|
+
/** Publish or unpublish one post, for bulk actions. */
|
|
504
|
+
async function setStatus(req, post, status) {
|
|
505
|
+
if (post.deleted_at)
|
|
506
|
+
return { error: 'Restore it from the trash first.', status: 409 };
|
|
507
|
+
if (!can(req.user, 'post.publish')) {
|
|
508
|
+
return { error: 'You do not have permission to publish posts.', status: 403 };
|
|
509
|
+
}
|
|
510
|
+
const original = req.body;
|
|
511
|
+
req.body = { status };
|
|
512
|
+
const publishing = resolvePublishing(req, post);
|
|
513
|
+
req.body = original;
|
|
514
|
+
if ('error' in publishing)
|
|
515
|
+
return publishing;
|
|
516
|
+
const updated = await Post.update(post.id, publishing.values);
|
|
517
|
+
await hooks.fire(HOOKS.POST_UPDATED, { post: updated, previous: post, userId: req.userId });
|
|
518
|
+
return { ok: true };
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Persist the category and tag selection that comes with a post.
|
|
522
|
+
*
|
|
523
|
+
* Absent keys leave the existing selection alone, so a caller that only wants
|
|
524
|
+
* to change a title does not have to resend the taxonomy to keep it. An empty
|
|
525
|
+
* array is a real instruction and clears it.
|
|
526
|
+
*/
|
|
527
|
+
async function saveTaxonomy(postId, body) {
|
|
528
|
+
const payload = (body ?? {});
|
|
529
|
+
if (Array.isArray(payload.category_ids)) {
|
|
530
|
+
await Post.syncCategories(postId, payload.category_ids);
|
|
531
|
+
}
|
|
532
|
+
// The editor has always called this one `tags`; `tag_ids` is accepted too so
|
|
533
|
+
// the two halves of the pair are named alike from outside.
|
|
534
|
+
const tags = Array.isArray(payload.tag_ids) ? payload.tag_ids : payload.tags;
|
|
535
|
+
if (Array.isArray(tags)) {
|
|
536
|
+
await Post.syncTags(postId, tags);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type PostLockState } from '../models/PostLock.ts';
|
|
2
|
+
import type { Post as PostType, Request, Response } from '../types/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The editor's lock on a post: take it, keep it, give it back.
|
|
5
|
+
*
|
|
6
|
+
* Session-only (see the routes): a lock is "a person has this open", which a
|
|
7
|
+
* program does not. An API token never holds or takes over a lock; its writes
|
|
8
|
+
* are refused while a person holds one — see `lockConflict` below.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PostLockController: {
|
|
11
|
+
/** Who, if anyone, is editing this post. */
|
|
12
|
+
show(req: Request, res: Response): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Acquire or refresh — the editor's heartbeat.
|
|
15
|
+
*
|
|
16
|
+
* `take_over: true` takes the lock from whoever holds it. Anyone who may
|
|
17
|
+
* edit the post may do that, as in WordPress: the lock is a warning that
|
|
18
|
+
* someone is there, not a permission. A 409 means the lock is held by
|
|
19
|
+
* someone else and nothing changed; the body says who, so the editor can
|
|
20
|
+
* offer the take-over.
|
|
21
|
+
*/
|
|
22
|
+
acquire(req: Request, res: Response): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Let go, on leaving the editor.
|
|
25
|
+
*
|
|
26
|
+
* Sent with `fetch(..., { keepalive: true })` as the page unloads rather than
|
|
27
|
+
* `navigator.sendBeacon`, because a beacon cannot carry the Authorization
|
|
28
|
+
* header this API authenticates with. Always 200: there is nothing useful a
|
|
29
|
+
* closing page could do with a failure, and a stale lock expires anyway.
|
|
30
|
+
*/
|
|
31
|
+
release(req: Request, res: Response): Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Why this write must not go ahead, or null if it may.
|
|
35
|
+
*
|
|
36
|
+
* Called by every PostController action that changes a post's text (update,
|
|
37
|
+
* autosave, restoring a revision). A person holding a live lock on the post,
|
|
38
|
+
* other than the caller, blocks it with a 409 naming them.
|
|
39
|
+
*
|
|
40
|
+
* - A signed-in caller may send `take_over: true` with the save to take the
|
|
41
|
+
* lock as part of it — the "save anyway" button.
|
|
42
|
+
* - An API token cannot. A program overwriting what a person has open in
|
|
43
|
+
* front of them is the exact accident the lock exists to stop, and a script
|
|
44
|
+
* can retry after the lock lapses (two minutes after the editor closes)
|
|
45
|
+
* where a person cannot get their typing back.
|
|
46
|
+
*/
|
|
47
|
+
export declare function lockConflict(req: Request, post: PostType): Promise<{
|
|
48
|
+
error: string;
|
|
49
|
+
lock: ReturnType<typeof describe>;
|
|
50
|
+
} | null>;
|
|
51
|
+
/** A lock as the client sees it — with "is it mine" worked out, and the timings. */
|
|
52
|
+
declare function describe(lock: PostLockState | null, userId: number): {
|
|
53
|
+
locked: boolean;
|
|
54
|
+
mine: boolean;
|
|
55
|
+
user_id: number | null;
|
|
56
|
+
user_name: string | null;
|
|
57
|
+
locked_at: string | null;
|
|
58
|
+
expires_at: string | null;
|
|
59
|
+
heartbeat_ms: number;
|
|
60
|
+
ttl_ms: number;
|
|
61
|
+
};
|
|
62
|
+
export {};
|