@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,406 @@
|
|
|
1
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
2
|
+
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
3
|
+
import { renderContent } from '@basicbenframework/core/content';
|
|
4
|
+
import { getStorage } from '@basicbenframework/core/storage';
|
|
5
|
+
import { derivedFields } from "./derive.js";
|
|
6
|
+
import { livePost } from "./visibility.js";
|
|
7
|
+
/**
|
|
8
|
+
* Columns `update()` will write, and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* The old version built its SET clause from whatever keys it was handed, which
|
|
11
|
+
* was safe only because the controller happened to pass three it had picked
|
|
12
|
+
* itself. Anything that later passed a body straight through — a hook filter
|
|
13
|
+
* returning the request, say — would have written any column named in it,
|
|
14
|
+
* `user_id` and `created_at` included.
|
|
15
|
+
*/
|
|
16
|
+
const UPDATABLE = [
|
|
17
|
+
'user_id', 'title', 'content', 'content_html', 'published', 'slug', 'excerpt',
|
|
18
|
+
'featured_image', 'meta_title', 'meta_description', 'publish_at',
|
|
19
|
+
'status', 'deleted_at', 'live_notified',
|
|
20
|
+
'og_title', 'og_description', 'og_image', 'twitter_title', 'twitter_description',
|
|
21
|
+
'twitter_image', 'canonical_url', 'noindex',
|
|
22
|
+
'visibility', 'send_newsletter',
|
|
23
|
+
// Content types (migrations 038–039). Validated by helpers/content-model.ts
|
|
24
|
+
// before they reach here.
|
|
25
|
+
'post_type', 'fields'
|
|
26
|
+
];
|
|
27
|
+
/** The social and indexing fields, written on create exactly as given. */
|
|
28
|
+
export const SEO_FIELDS = [
|
|
29
|
+
'og_title', 'og_description', 'og_image', 'twitter_title', 'twitter_description',
|
|
30
|
+
'twitter_image', 'canonical_url', 'noindex'
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* The admin listing's filters, in the order the tabs show them.
|
|
34
|
+
*
|
|
35
|
+
* `scheduled` is not a stored status: it is a published post whose time has
|
|
36
|
+
* not come, which is exactly how the public site decides not to show it.
|
|
37
|
+
*/
|
|
38
|
+
export const LISTING_FILTERS = ['all', 'draft', 'pending', 'scheduled', 'published', 'trash'];
|
|
39
|
+
function listingWhere(filter, now) {
|
|
40
|
+
switch (filter) {
|
|
41
|
+
case 'trash': return 'posts.deleted_at IS NOT NULL';
|
|
42
|
+
case 'draft': return "posts.deleted_at IS NULL AND posts.status = 'draft'";
|
|
43
|
+
case 'pending': return "posts.deleted_at IS NULL AND posts.status = 'pending'";
|
|
44
|
+
case 'scheduled': return `posts.deleted_at IS NULL AND posts.published = 1 AND posts.publish_at > '${now}'`;
|
|
45
|
+
case 'published': return `posts.deleted_at IS NULL AND posts.published = 1 AND (posts.publish_at IS NULL OR posts.publish_at <= '${now}')`;
|
|
46
|
+
default: return 'posts.deleted_at IS NULL';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const Post = {
|
|
50
|
+
async all() {
|
|
51
|
+
const db = await getDb();
|
|
52
|
+
return db.all('SELECT * FROM posts ORDER BY created_at DESC');
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Replace a post's categories.
|
|
56
|
+
*
|
|
57
|
+
* Rebuilt rather than merged, because the editor sends the complete set: a
|
|
58
|
+
* merge would make unchecking a box do nothing, which is the kind of bug
|
|
59
|
+
* people re-report for months.
|
|
60
|
+
*
|
|
61
|
+
* `posts.category_id` is kept in step as the *primary* category — the first
|
|
62
|
+
* of the set — so a breadcrumb or canonical URL still has one to name.
|
|
63
|
+
*/
|
|
64
|
+
async syncCategories(postId, categoryIds) {
|
|
65
|
+
const db = await getDb();
|
|
66
|
+
const ids = [...new Set(categoryIds.map(Number).filter(Number.isInteger))];
|
|
67
|
+
await db.run('DELETE FROM post_categories WHERE post_id = ?', [postId]);
|
|
68
|
+
for (const id of ids) {
|
|
69
|
+
await db.run('INSERT INTO post_categories (post_id, category_id) VALUES (?, ?)', [postId, id]);
|
|
70
|
+
}
|
|
71
|
+
await db.run('UPDATE posts SET category_id = ? WHERE id = ?', [ids[0] ?? null, postId]);
|
|
72
|
+
},
|
|
73
|
+
/** Replace a post's tags. Rebuilt, for the same reason as categories. */
|
|
74
|
+
async syncTags(postId, tagIds) {
|
|
75
|
+
const db = await getDb();
|
|
76
|
+
const ids = [...new Set(tagIds.map(Number).filter(Number.isInteger))];
|
|
77
|
+
await db.run('DELETE FROM post_tags WHERE post_id = ?', [postId]);
|
|
78
|
+
for (const id of ids) {
|
|
79
|
+
await db.run('INSERT INTO post_tags (post_id, tag_id) VALUES (?, ?)', [postId, id]);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
/** The ids of a post's categories and tags, for the editor to preselect. */
|
|
83
|
+
async taxonomy(postId) {
|
|
84
|
+
const db = await getDb();
|
|
85
|
+
const categories = await db.all('SELECT category_id AS id FROM post_categories WHERE post_id = ?', [postId]);
|
|
86
|
+
const tags = await db.all('SELECT tag_id AS id FROM post_tags WHERE post_id = ?', [postId]);
|
|
87
|
+
return {
|
|
88
|
+
categories: categories.map((row) => row.id),
|
|
89
|
+
tags: tags.map((row) => row.id)
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
async find(id) {
|
|
93
|
+
const db = await getDb();
|
|
94
|
+
// Joined rather than a bare `SELECT *` so the editor gets a URL for the
|
|
95
|
+
// featured image instead of the media id it stores, and a name for the
|
|
96
|
+
// author instead of a number — both of which it has to show.
|
|
97
|
+
const row = await db.get(`SELECT posts.*, media.path AS featured_image_path, users.name AS author_name
|
|
98
|
+
FROM posts
|
|
99
|
+
LEFT JOIN media ON media.id = posts.featured_image
|
|
100
|
+
LEFT JOIN users ON users.id = posts.user_id
|
|
101
|
+
WHERE posts.id = ?`, [id]);
|
|
102
|
+
return row ? (await withFeaturedImages([row]))[0] : undefined;
|
|
103
|
+
},
|
|
104
|
+
async findByUser(userId) {
|
|
105
|
+
const db = await getDb();
|
|
106
|
+
return db.all('SELECT * FROM posts WHERE user_id = ? AND deleted_at IS NULL ORDER BY created_at DESC', [userId]);
|
|
107
|
+
},
|
|
108
|
+
/** How many posts sit in each listing tab, for the counts beside them. */
|
|
109
|
+
async counts(userId, type) {
|
|
110
|
+
const db = await getDb();
|
|
111
|
+
const now = new Date().toISOString();
|
|
112
|
+
const result = {};
|
|
113
|
+
for (const filter of LISTING_FILTERS) {
|
|
114
|
+
const where = [listingWhere(filter, now)];
|
|
115
|
+
const params = [];
|
|
116
|
+
if (userId !== undefined) {
|
|
117
|
+
where.push('posts.user_id = ?');
|
|
118
|
+
params.push(userId);
|
|
119
|
+
}
|
|
120
|
+
if (type !== undefined) {
|
|
121
|
+
where.push('posts.post_type = ?');
|
|
122
|
+
params.push(type);
|
|
123
|
+
}
|
|
124
|
+
const row = await db.get(`SELECT COUNT(*) AS total FROM posts WHERE ${where.join(' AND ')}`, params);
|
|
125
|
+
result[filter] = Number(row?.total) || 0;
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
},
|
|
129
|
+
/** Move to the trash. Hidden everywhere, restorable until emptied. */
|
|
130
|
+
async trash(id) {
|
|
131
|
+
const db = await getDb();
|
|
132
|
+
await db.run('UPDATE posts SET deleted_at = ? WHERE id = ?', [new Date().toISOString(), id]);
|
|
133
|
+
},
|
|
134
|
+
/** Take out of the trash, in whatever state it was in before. */
|
|
135
|
+
async restore(id) {
|
|
136
|
+
const db = await getDb();
|
|
137
|
+
await db.run('UPDATE posts SET deleted_at = NULL WHERE id = ?', [id]);
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Scheduled posts whose time has come and that webhooks have not heard about.
|
|
141
|
+
*
|
|
142
|
+
* The public site needs nothing to make a scheduled post appear — the read
|
|
143
|
+
* filter does that — but a webhook consumer has to be told, and nothing
|
|
144
|
+
* happens at the moment the time passes. `publishDue()` asks this, tells
|
|
145
|
+
* the consumers, then marks each one with `markNotified`.
|
|
146
|
+
*/
|
|
147
|
+
async dueForNotification() {
|
|
148
|
+
const db = await getDb();
|
|
149
|
+
return db.all(`SELECT * FROM posts WHERE live_notified = 0 AND ${livePost('posts')}`);
|
|
150
|
+
},
|
|
151
|
+
async markNotified(id) {
|
|
152
|
+
const db = await getDb();
|
|
153
|
+
await db.run('UPDATE posts SET live_notified = 1 WHERE id = ?', [id]);
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* One page of posts, with the total so a caller can size the pager.
|
|
157
|
+
*
|
|
158
|
+
* `userId` narrows it to one author's work. Omitting it returns everyone's,
|
|
159
|
+
* which is what an editor or an admin should see — they can edit any post, so
|
|
160
|
+
* a listing that showed only their own hid the site from the people
|
|
161
|
+
* responsible for it.
|
|
162
|
+
*
|
|
163
|
+
* The count is a second query rather than a window function, because the
|
|
164
|
+
* three drivers do not agree on those and this has to run on all of them.
|
|
165
|
+
* It is cheap: an indexed count.
|
|
166
|
+
*/
|
|
167
|
+
async paginate({ perPage, offset, userId, filter = 'all', search, type }) {
|
|
168
|
+
const db = await getDb();
|
|
169
|
+
// The trash is its own tab; everything else leaves it out. `now` is our
|
|
170
|
+
// own ISO string, so inlining it is safe (see visibility.ts).
|
|
171
|
+
const conditions = [listingWhere(filter, new Date().toISOString())];
|
|
172
|
+
const scope = [];
|
|
173
|
+
if (userId !== undefined) {
|
|
174
|
+
conditions.push('posts.user_id = ?');
|
|
175
|
+
scope.push(userId);
|
|
176
|
+
}
|
|
177
|
+
if (type !== undefined) {
|
|
178
|
+
conditions.push('posts.post_type = ?');
|
|
179
|
+
scope.push(type);
|
|
180
|
+
}
|
|
181
|
+
if (search) {
|
|
182
|
+
// Case-insensitive on every driver. LIKE is on SQLite and not on
|
|
183
|
+
// Postgres, so both sides are lowered rather than trusting the default.
|
|
184
|
+
// `%` and `_` in the search are literal characters, not wildcards.
|
|
185
|
+
const needle = `%${search.toLowerCase().replace(/[\\%_]/g, (c) => '\\' + c)}%`;
|
|
186
|
+
conditions.push("(LOWER(posts.title) LIKE ? ESCAPE '\\' OR LOWER(posts.content) LIKE ? ESCAPE '\\')");
|
|
187
|
+
scope.push(needle, needle);
|
|
188
|
+
}
|
|
189
|
+
const where = `WHERE ${conditions.join(' AND ')}`;
|
|
190
|
+
// `id` breaks ties. `created_at` alone is not a total order — these rows
|
|
191
|
+
// are written in the same second all the time — and an unspecified order
|
|
192
|
+
// is merely untidy until you paginate it, at which point LIMIT/OFFSET can
|
|
193
|
+
// return a row on two pages and never return another. SQLite happens to be
|
|
194
|
+
// stable here; Postgres is under no obligation to be.
|
|
195
|
+
const posts = await db.all(`SELECT posts.*, users.name AS author_name
|
|
196
|
+
FROM posts
|
|
197
|
+
LEFT JOIN users ON users.id = posts.user_id
|
|
198
|
+
${where}
|
|
199
|
+
ORDER BY posts.created_at DESC, posts.id DESC
|
|
200
|
+
LIMIT ? OFFSET ?`, [...scope, perPage, offset]);
|
|
201
|
+
const counted = await db.get(`SELECT COUNT(*) AS total FROM posts ${where}`, scope);
|
|
202
|
+
// The listing showed a `category_name` this query never selected, so its
|
|
203
|
+
// Category column rendered an em dash for every row whatever the post was
|
|
204
|
+
// filed under. Categories are many-to-many now, so it could not have been a
|
|
205
|
+
// single column anyway — they come back as an array, fetched once for the
|
|
206
|
+
// page rather than once per row.
|
|
207
|
+
return {
|
|
208
|
+
posts: await withCategories(db, posts),
|
|
209
|
+
total: Number(counted?.total) || 0
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
async findPublished() {
|
|
213
|
+
const db = await getDb();
|
|
214
|
+
const rows = await db.all(`
|
|
215
|
+
SELECT ${PUBLISHED_COLUMNS} ${PUBLISHED_JOINS}
|
|
216
|
+
WHERE ${livePost('posts')} AND posts.post_type = 'post'
|
|
217
|
+
ORDER BY COALESCE(posts.publish_at, posts.created_at) DESC
|
|
218
|
+
`);
|
|
219
|
+
return withAuthors(await withFeaturedImages(rows));
|
|
220
|
+
},
|
|
221
|
+
async findPublishedById(id) {
|
|
222
|
+
const db = await getDb();
|
|
223
|
+
const row = await db.get(`
|
|
224
|
+
SELECT ${PUBLISHED_COLUMNS} ${PUBLISHED_JOINS}
|
|
225
|
+
WHERE posts.id = ? AND ${livePost('posts')}
|
|
226
|
+
`, [id]);
|
|
227
|
+
if (!row)
|
|
228
|
+
return undefined;
|
|
229
|
+
return (await withAuthors(await withFeaturedImages([row])))[0];
|
|
230
|
+
},
|
|
231
|
+
async create(data) {
|
|
232
|
+
const db = await getDb();
|
|
233
|
+
// Markdown is what the author wrote and what gets stored; the HTML beside
|
|
234
|
+
// it is a cache, rebuilt here so reads never have to render.
|
|
235
|
+
const contentHtml = await renderContent(data.content || '', {
|
|
236
|
+
context: { table: 'posts', userId: data.user_id }
|
|
237
|
+
});
|
|
238
|
+
// The last point a listener can alter what is stored. Its return value has
|
|
239
|
+
// to be what gets written, or the filter is decoration.
|
|
240
|
+
const contentSaved = await hooks.filter(HOOKS.CONTENT_SAVE, contentHtml, { type: 'post', data });
|
|
241
|
+
// A slug and an excerpt the author did not type. Both were columns the
|
|
242
|
+
// editor showed and nothing ever wrote: every post this CMS created had a
|
|
243
|
+
// null slug, so its only URL was an id.
|
|
244
|
+
const derived = await derivedFields('posts', data);
|
|
245
|
+
// Through the query builder, which appends RETURNING id on Postgres. A raw
|
|
246
|
+
// INSERT there reports lastInsertRowid as null, so the row is written and
|
|
247
|
+
// the caller is handed an object with no id — the failure looks like a bug
|
|
248
|
+
// in whatever used the id next.
|
|
249
|
+
const result = await (await query('posts')).insert({
|
|
250
|
+
user_id: data.user_id,
|
|
251
|
+
title: data.title,
|
|
252
|
+
content: data.content,
|
|
253
|
+
content_html: contentSaved,
|
|
254
|
+
slug: derived.slug,
|
|
255
|
+
excerpt: derived.excerpt,
|
|
256
|
+
featured_image: data.featured_image ?? null,
|
|
257
|
+
meta_title: data.meta_title ?? null,
|
|
258
|
+
meta_description: data.meta_description ?? null,
|
|
259
|
+
publish_at: data.publish_at ?? null,
|
|
260
|
+
published: data.published ? 1 : 0,
|
|
261
|
+
status: data.status ?? (data.published ? 'published' : 'draft'),
|
|
262
|
+
live_notified: data.live_notified ?? 1,
|
|
263
|
+
visibility: data.visibility ?? 'public',
|
|
264
|
+
send_newsletter: data.send_newsletter ?? 0,
|
|
265
|
+
post_type: data.post_type ?? 'post',
|
|
266
|
+
fields: data.fields ?? null,
|
|
267
|
+
...Object.fromEntries(SEO_FIELDS.filter((key) => data[key] !== undefined).map((key) => [key, data[key]]))
|
|
268
|
+
});
|
|
269
|
+
const now = new Date().toISOString();
|
|
270
|
+
return {
|
|
271
|
+
id: result.lastInsertRowid,
|
|
272
|
+
...data,
|
|
273
|
+
...derived,
|
|
274
|
+
content_html: contentSaved,
|
|
275
|
+
published: data.published,
|
|
276
|
+
created_at: now,
|
|
277
|
+
updated_at: now
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
async update(id, data) {
|
|
281
|
+
const db = await getDb();
|
|
282
|
+
const existing = await this.find(id);
|
|
283
|
+
const updateData = { ...data };
|
|
284
|
+
// Re-render whenever the source changes, so the two can never disagree.
|
|
285
|
+
if ('content' in data) {
|
|
286
|
+
updateData.content_html = await renderContent(data.content || '', {
|
|
287
|
+
context: { table: 'posts', id }
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
// Blank means "derive it", the same as on create — except that a post which
|
|
291
|
+
// already has a slug keeps it, so retitling does not move a published URL.
|
|
292
|
+
if ('slug' in data || 'excerpt' in data || 'title' in data || 'content' in data) {
|
|
293
|
+
const derived = await derivedFields('posts', {
|
|
294
|
+
title: data.title ?? existing?.title,
|
|
295
|
+
content: data.content ?? existing?.content,
|
|
296
|
+
slug: data.slug,
|
|
297
|
+
excerpt: data.excerpt
|
|
298
|
+
}, { excludeId: id, existingSlug: existing?.slug, existingExcerpt: existing?.excerpt });
|
|
299
|
+
updateData.slug = derived.slug;
|
|
300
|
+
updateData.excerpt = derived.excerpt;
|
|
301
|
+
}
|
|
302
|
+
// `undefined` means the caller said nothing about that column. Writing it
|
|
303
|
+
// would bind undefined into the statement, which is either an error or a
|
|
304
|
+
// null depending on the driver — both of them wrong.
|
|
305
|
+
const writable = Object.entries(updateData).filter(([key, value]) => UPDATABLE.includes(key) && value !== undefined);
|
|
306
|
+
if (writable.length === 0)
|
|
307
|
+
return this.find(id);
|
|
308
|
+
const fields = writable.map(([key]) => `${key} = ?`).join(', ');
|
|
309
|
+
await db.run(`UPDATE posts SET ${fields}, updated_at = CURRENT_TIMESTAMP WHERE id = ?`, [...writable.map(([, value]) => value), id]);
|
|
310
|
+
return this.find(id);
|
|
311
|
+
},
|
|
312
|
+
/** Gone for good. Only ever called on a post already in the trash. */
|
|
313
|
+
async delete(id) {
|
|
314
|
+
const db = await getDb();
|
|
315
|
+
await db.run('DELETE FROM post_revisions WHERE post_id = ?', [id]);
|
|
316
|
+
await db.run('DELETE FROM posts WHERE id = ?', [id]);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* What the feed selects, named once so the list and the single-item query
|
|
321
|
+
* cannot drift apart.
|
|
322
|
+
*
|
|
323
|
+
* The author's profile travels with the post because a byline is more than a
|
|
324
|
+
* name now — a face and a line of biography are what make a multi-author blog
|
|
325
|
+
* read like one. `avatar_path` is a storage key; `withAuthors` turns it into
|
|
326
|
+
* something a browser can load.
|
|
327
|
+
*/
|
|
328
|
+
const PUBLISHED_COLUMNS = `
|
|
329
|
+
posts.*,
|
|
330
|
+
users.name AS author_name,
|
|
331
|
+
users.slug AS author_slug,
|
|
332
|
+
users.bio AS author_bio,
|
|
333
|
+
users.website AS author_website,
|
|
334
|
+
avatars.path AS author_avatar_path,
|
|
335
|
+
media.path AS featured_image_path
|
|
336
|
+
`;
|
|
337
|
+
const PUBLISHED_JOINS = `
|
|
338
|
+
FROM posts
|
|
339
|
+
JOIN users ON posts.user_id = users.id
|
|
340
|
+
LEFT JOIN media ON media.id = posts.featured_image
|
|
341
|
+
LEFT JOIN media AS avatars ON avatars.id = users.avatar_id
|
|
342
|
+
`;
|
|
343
|
+
/**
|
|
344
|
+
* Resolve each post's featured image to a URL.
|
|
345
|
+
*
|
|
346
|
+
* `featured_image` is a foreign key into `media`, but the front end renders it as
|
|
347
|
+
* a filename — producing `/uploads/3` for every post that had one. The join
|
|
348
|
+
* supplies the storage key and this turns it into a URL, which is the only
|
|
349
|
+
* thing a browser can use.
|
|
350
|
+
*
|
|
351
|
+
* The key is resolved here rather than stored as a URL so that moving buckets,
|
|
352
|
+
* or putting a CDN in front of one, does not mean rewriting every row.
|
|
353
|
+
*/
|
|
354
|
+
async function withFeaturedImages(rows) {
|
|
355
|
+
if (!rows.some((row) => row.featured_image_path))
|
|
356
|
+
return rows;
|
|
357
|
+
const storage = await getStorage();
|
|
358
|
+
return rows.map((row) => ({
|
|
359
|
+
...row,
|
|
360
|
+
featured_image_url: row.featured_image_path
|
|
361
|
+
? storage.publicUrl(row.featured_image_path)
|
|
362
|
+
: null
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Fold the joined author columns into one profile object.
|
|
367
|
+
*
|
|
368
|
+
* `author_name` stays where it is: every byline already reads it, and moving it
|
|
369
|
+
* would be a change to a shape the front end has always had for the sake of
|
|
370
|
+
* tidiness. The profile is added beside it.
|
|
371
|
+
*
|
|
372
|
+
* The avatar URL is resolved from the same storage adapter as a featured image,
|
|
373
|
+
* so the two cannot disagree about where files live.
|
|
374
|
+
*/
|
|
375
|
+
async function withAuthors(rows) {
|
|
376
|
+
const storage = rows.some((row) => row.author_avatar_path) ? await getStorage() : null;
|
|
377
|
+
return rows.map((row) => ({
|
|
378
|
+
...row,
|
|
379
|
+
author: {
|
|
380
|
+
id: row.user_id,
|
|
381
|
+
name: row.author_name ?? '',
|
|
382
|
+
slug: row.author_slug ?? null,
|
|
383
|
+
bio: row.author_bio ?? null,
|
|
384
|
+
website: row.author_website ?? null,
|
|
385
|
+
avatar_url: row.author_avatar_path && storage ? storage.publicUrl(row.author_avatar_path) : null
|
|
386
|
+
}
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
389
|
+
async function withCategories(db, posts) {
|
|
390
|
+
if (posts.length === 0)
|
|
391
|
+
return [];
|
|
392
|
+
const ids = posts.map((post) => post.id);
|
|
393
|
+
const placeholders = ids.map(() => '?').join(', ');
|
|
394
|
+
const rows = (await db.all(`SELECT pc.post_id, c.id, c.name, c.slug
|
|
395
|
+
FROM post_categories pc
|
|
396
|
+
JOIN categories c ON c.id = pc.category_id
|
|
397
|
+
WHERE pc.post_id IN (${placeholders})
|
|
398
|
+
ORDER BY c.name ASC`, ids));
|
|
399
|
+
const byPost = new Map();
|
|
400
|
+
for (const row of rows) {
|
|
401
|
+
const list = byPost.get(row.post_id) ?? [];
|
|
402
|
+
list.push({ id: row.id, name: row.name, slug: row.slug });
|
|
403
|
+
byPost.set(row.post_id, list);
|
|
404
|
+
}
|
|
405
|
+
return posts.map((post) => ({ ...post, categories: byPost.get(post.id) ?? [] }));
|
|
406
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft edit locks on posts — who has a post open in the editor.
|
|
3
|
+
*
|
|
4
|
+
* Soft, as in WordPress: the lock does not stop anyone *reading* a post, and
|
|
5
|
+
* anyone who may edit it may take the lock over. What it stops is the silent
|
|
6
|
+
* overwrite — two people saving the same post, the second replacing the first
|
|
7
|
+
* without either knowing the other was there. A save from someone who does not
|
|
8
|
+
* hold a live lock gets a 409 naming who does.
|
|
9
|
+
*
|
|
10
|
+
* The editor holds the lock by heartbeat (every 30 seconds) and releases it on
|
|
11
|
+
* leaving. A lock not refreshed for `LOCK_TTL_MS` is stale and free: a closed
|
|
12
|
+
* laptop or a crashed tab must not hold a post hostage. Two minutes is four
|
|
13
|
+
* missed heartbeats — enough to ride out a flaky connection, short enough that
|
|
14
|
+
* the next person is not left waiting long.
|
|
15
|
+
*
|
|
16
|
+
* Locks are per account, not per tab: the same person in two tabs holds one
|
|
17
|
+
* lock, as in WordPress. A post nobody holds is editable by anyone, so API
|
|
18
|
+
* clients and scripts that never take a lock still work — they are only
|
|
19
|
+
* refused while a person is actively in the editor.
|
|
20
|
+
*/
|
|
21
|
+
export declare const LOCK_TTL_MS: number;
|
|
22
|
+
/** How often the editor should refresh, told to the client so the two agree. */
|
|
23
|
+
export declare const LOCK_HEARTBEAT_MS: number;
|
|
24
|
+
export interface PostLockState {
|
|
25
|
+
post_id: number;
|
|
26
|
+
user_id: number;
|
|
27
|
+
user_name: string | null;
|
|
28
|
+
locked_at: string;
|
|
29
|
+
expires_at: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const PostLock: {
|
|
32
|
+
/** The live lock on a post, or null when nobody holds one (or it went stale). */
|
|
33
|
+
current(postId: number, now?: number): Promise<PostLockState | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Take or refresh the lock, if it is free, stale, or already ours.
|
|
36
|
+
*
|
|
37
|
+
* One conditional upsert, so two editors opening the same post at the same
|
|
38
|
+
* moment cannot both come away holding it: the row is keyed on the post, and
|
|
39
|
+
* the `WHERE` on the conflict branch only lets the update through for the
|
|
40
|
+
* holder or over a stale lock. `takeOver` drops that condition — the person
|
|
41
|
+
* has been shown who holds it and chosen to take it anyway.
|
|
42
|
+
*
|
|
43
|
+
* Works unchanged on SQLite (3.24+), libSQL and Postgres, which all speak
|
|
44
|
+
* `ON CONFLICT … DO UPDATE … WHERE`.
|
|
45
|
+
*/
|
|
46
|
+
acquire(postId: number, userId: number, options?: {
|
|
47
|
+
takeOver?: boolean;
|
|
48
|
+
now?: number;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
acquired: boolean;
|
|
51
|
+
lock: PostLockState | null;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Let go, if we hold it.
|
|
55
|
+
*
|
|
56
|
+
* Scoped to the holder so a tab closing after its lock was taken over does
|
|
57
|
+
* not free the post from under the person who took it.
|
|
58
|
+
*/
|
|
59
|
+
release(postId: number, userId: number): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* The lock that stops `userId` saving, or null if nothing does.
|
|
62
|
+
*
|
|
63
|
+
* Nothing does when the post is unlocked, the lock went stale, or it is
|
|
64
|
+
* this account's own.
|
|
65
|
+
*/
|
|
66
|
+
blocking(postId: number, userId: number, now?: number): Promise<PostLockState | null>;
|
|
67
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
2
|
+
/**
|
|
3
|
+
* Soft edit locks on posts — who has a post open in the editor.
|
|
4
|
+
*
|
|
5
|
+
* Soft, as in WordPress: the lock does not stop anyone *reading* a post, and
|
|
6
|
+
* anyone who may edit it may take the lock over. What it stops is the silent
|
|
7
|
+
* overwrite — two people saving the same post, the second replacing the first
|
|
8
|
+
* without either knowing the other was there. A save from someone who does not
|
|
9
|
+
* hold a live lock gets a 409 naming who does.
|
|
10
|
+
*
|
|
11
|
+
* The editor holds the lock by heartbeat (every 30 seconds) and releases it on
|
|
12
|
+
* leaving. A lock not refreshed for `LOCK_TTL_MS` is stale and free: a closed
|
|
13
|
+
* laptop or a crashed tab must not hold a post hostage. Two minutes is four
|
|
14
|
+
* missed heartbeats — enough to ride out a flaky connection, short enough that
|
|
15
|
+
* the next person is not left waiting long.
|
|
16
|
+
*
|
|
17
|
+
* Locks are per account, not per tab: the same person in two tabs holds one
|
|
18
|
+
* lock, as in WordPress. A post nobody holds is editable by anyone, so API
|
|
19
|
+
* clients and scripts that never take a lock still work — they are only
|
|
20
|
+
* refused while a person is actively in the editor.
|
|
21
|
+
*/
|
|
22
|
+
export const LOCK_TTL_MS = 2 * 60 * 1000;
|
|
23
|
+
/** How often the editor should refresh, told to the client so the two agree. */
|
|
24
|
+
export const LOCK_HEARTBEAT_MS = 30 * 1000;
|
|
25
|
+
/**
|
|
26
|
+
* A stored timestamp as milliseconds.
|
|
27
|
+
*
|
|
28
|
+
* Written as ISO strings here, but Postgres hands a TIMESTAMP column back as a
|
|
29
|
+
* Date and SQLite's default format has a space and no zone — both are UTC.
|
|
30
|
+
*/
|
|
31
|
+
function millis(value) {
|
|
32
|
+
if (value instanceof Date)
|
|
33
|
+
return value.getTime();
|
|
34
|
+
const bare = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?$/.test(value);
|
|
35
|
+
return new Date(bare ? `${value.replace(' ', 'T')}Z` : value).getTime();
|
|
36
|
+
}
|
|
37
|
+
function shape(row, now) {
|
|
38
|
+
if (!row)
|
|
39
|
+
return null;
|
|
40
|
+
const at = millis(row.locked_at);
|
|
41
|
+
if (!Number.isFinite(at) || now - at >= LOCK_TTL_MS)
|
|
42
|
+
return null;
|
|
43
|
+
return {
|
|
44
|
+
post_id: Number(row.post_id),
|
|
45
|
+
user_id: Number(row.user_id),
|
|
46
|
+
user_name: row.user_name ?? null,
|
|
47
|
+
locked_at: new Date(at).toISOString(),
|
|
48
|
+
expires_at: new Date(at + LOCK_TTL_MS).toISOString()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export const PostLock = {
|
|
52
|
+
/** The live lock on a post, or null when nobody holds one (or it went stale). */
|
|
53
|
+
async current(postId, now = Date.now()) {
|
|
54
|
+
const db = await getDb();
|
|
55
|
+
const row = (await db.get(`SELECT post_locks.post_id, post_locks.user_id, post_locks.locked_at, users.name AS user_name
|
|
56
|
+
FROM post_locks
|
|
57
|
+
LEFT JOIN users ON users.id = post_locks.user_id
|
|
58
|
+
WHERE post_locks.post_id = ?`, [postId]));
|
|
59
|
+
return shape(row, now);
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Take or refresh the lock, if it is free, stale, or already ours.
|
|
63
|
+
*
|
|
64
|
+
* One conditional upsert, so two editors opening the same post at the same
|
|
65
|
+
* moment cannot both come away holding it: the row is keyed on the post, and
|
|
66
|
+
* the `WHERE` on the conflict branch only lets the update through for the
|
|
67
|
+
* holder or over a stale lock. `takeOver` drops that condition — the person
|
|
68
|
+
* has been shown who holds it and chosen to take it anyway.
|
|
69
|
+
*
|
|
70
|
+
* Works unchanged on SQLite (3.24+), libSQL and Postgres, which all speak
|
|
71
|
+
* `ON CONFLICT … DO UPDATE … WHERE`.
|
|
72
|
+
*/
|
|
73
|
+
async acquire(postId, userId, options = {}) {
|
|
74
|
+
const now = options.now ?? Date.now();
|
|
75
|
+
const stamp = new Date(now).toISOString();
|
|
76
|
+
const staleBefore = new Date(now - LOCK_TTL_MS).toISOString();
|
|
77
|
+
const db = await getDb();
|
|
78
|
+
if (options.takeOver) {
|
|
79
|
+
await db.run(`INSERT INTO post_locks (post_id, user_id, locked_at) VALUES (?, ?, ?)
|
|
80
|
+
ON CONFLICT (post_id) DO UPDATE SET user_id = excluded.user_id, locked_at = excluded.locked_at`, [postId, userId, stamp]);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
await db.run(`INSERT INTO post_locks (post_id, user_id, locked_at) VALUES (?, ?, ?)
|
|
84
|
+
ON CONFLICT (post_id) DO UPDATE SET user_id = excluded.user_id, locked_at = excluded.locked_at
|
|
85
|
+
WHERE post_locks.user_id = excluded.user_id OR post_locks.locked_at <= ?`, [postId, userId, stamp, staleBefore]);
|
|
86
|
+
}
|
|
87
|
+
// Read back rather than trusting the change count, which drivers report
|
|
88
|
+
// differently for an upsert that took its conflict branch.
|
|
89
|
+
const lock = await PostLock.current(postId, now);
|
|
90
|
+
return { acquired: Boolean(lock && lock.user_id === userId), lock };
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Let go, if we hold it.
|
|
94
|
+
*
|
|
95
|
+
* Scoped to the holder so a tab closing after its lock was taken over does
|
|
96
|
+
* not free the post from under the person who took it.
|
|
97
|
+
*/
|
|
98
|
+
async release(postId, userId) {
|
|
99
|
+
const db = await getDb();
|
|
100
|
+
await db.run('DELETE FROM post_locks WHERE post_id = ? AND user_id = ?', [postId, userId]);
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* The lock that stops `userId` saving, or null if nothing does.
|
|
104
|
+
*
|
|
105
|
+
* Nothing does when the post is unlocked, the lock went stale, or it is
|
|
106
|
+
* this account's own.
|
|
107
|
+
*/
|
|
108
|
+
async blocking(postId, userId, now = Date.now()) {
|
|
109
|
+
const lock = await PostLock.current(postId, now);
|
|
110
|
+
return lock && lock.user_id !== userId ? lock : null;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface PostRevision {
|
|
2
|
+
id: number;
|
|
3
|
+
post_id: number;
|
|
4
|
+
user_id: number | null;
|
|
5
|
+
author_name?: string | null;
|
|
6
|
+
title: string;
|
|
7
|
+
content: string;
|
|
8
|
+
excerpt: string | null;
|
|
9
|
+
autosave: number;
|
|
10
|
+
created_at: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Revisions of a post.
|
|
14
|
+
*
|
|
15
|
+
* A revision is a copy of the post *before* a save changed it, so the newest
|
|
16
|
+
* revision plus the post itself is the whole history. Autosaves live in the
|
|
17
|
+
* same table, flagged, one per post and author: replaced on every autosave
|
|
18
|
+
* and cleared when the author saves for real.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PostRevision: {
|
|
21
|
+
/** Record what a post said before a save, if the save changes it. */
|
|
22
|
+
snapshot(before: {
|
|
23
|
+
id: number;
|
|
24
|
+
title: string;
|
|
25
|
+
content: string;
|
|
26
|
+
excerpt?: string | null;
|
|
27
|
+
}, after: {
|
|
28
|
+
title?: string;
|
|
29
|
+
content?: string;
|
|
30
|
+
excerpt?: string | null;
|
|
31
|
+
}, userId: number | null): Promise<void>;
|
|
32
|
+
list(postId: number): Promise<PostRevision[]>;
|
|
33
|
+
find(postId: number, id: number): Promise<PostRevision | undefined>;
|
|
34
|
+
/** Replace this author's autosave of this post. */
|
|
35
|
+
autosave(postId: number, userId: number, data: {
|
|
36
|
+
title: string;
|
|
37
|
+
content: string;
|
|
38
|
+
excerpt?: string | null;
|
|
39
|
+
}): Promise<PostRevision | undefined>;
|
|
40
|
+
/** An author's pending autosave of a post, if it is newer than the post. */
|
|
41
|
+
pendingAutosave(postId: number, userId: number, postUpdatedAt: string): Promise<PostRevision | undefined>;
|
|
42
|
+
clearAutosave(postId: number, userId: number): Promise<void>;
|
|
43
|
+
/** Keep the newest KEEP saved revisions; autosaves are not counted. */
|
|
44
|
+
prune(postId: number): Promise<void>;
|
|
45
|
+
};
|