@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,132 @@
|
|
|
1
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
2
|
+
export const Media = {
|
|
3
|
+
/**
|
|
4
|
+
* A page of media, optionally filtered.
|
|
5
|
+
*
|
|
6
|
+
* Search and type are applied in SQL rather than by the caller because the
|
|
7
|
+
* result is paginated: filtering the twenty rows a page happens to hold would
|
|
8
|
+
* search the current page instead of the library.
|
|
9
|
+
*
|
|
10
|
+
* @param page - 1-based
|
|
11
|
+
* @param perPage
|
|
12
|
+
* @param filters - `search` matches the original filename; `type` is a mime
|
|
13
|
+
* prefix such as 'image', or 'other' for anything that is not image, video
|
|
14
|
+
* or audio.
|
|
15
|
+
*/
|
|
16
|
+
async all(page = 1, perPage = 20, filters = {}) {
|
|
17
|
+
const db = await getDb();
|
|
18
|
+
const offset = (page - 1) * perPage;
|
|
19
|
+
const where = [];
|
|
20
|
+
const params = [];
|
|
21
|
+
if (filters.search) {
|
|
22
|
+
where.push('m.original_name LIKE ?');
|
|
23
|
+
params.push(`%${filters.search}%`);
|
|
24
|
+
}
|
|
25
|
+
if (filters.type === 'other') {
|
|
26
|
+
where.push("COALESCE(m.mime_type, '') NOT LIKE 'image/%'");
|
|
27
|
+
where.push("COALESCE(m.mime_type, '') NOT LIKE 'video/%'");
|
|
28
|
+
where.push("COALESCE(m.mime_type, '') NOT LIKE 'audio/%'");
|
|
29
|
+
}
|
|
30
|
+
else if (filters.type) {
|
|
31
|
+
where.push('m.mime_type LIKE ?');
|
|
32
|
+
params.push(`${filters.type}/%`);
|
|
33
|
+
}
|
|
34
|
+
const clause = where.length ? `WHERE ${where.join(' AND ')}` : '';
|
|
35
|
+
const items = await db.all(`
|
|
36
|
+
SELECT m.*, u.name as user_name
|
|
37
|
+
FROM media m
|
|
38
|
+
LEFT JOIN users u ON u.id = m.user_id
|
|
39
|
+
${clause}
|
|
40
|
+
ORDER BY m.created_at DESC
|
|
41
|
+
LIMIT ? OFFSET ?
|
|
42
|
+
`, [...params, perPage, offset]);
|
|
43
|
+
const countResult = await db.get(`SELECT COUNT(*) as total FROM media m ${clause}`, params);
|
|
44
|
+
const total = countResult?.total || 0;
|
|
45
|
+
return { items, total };
|
|
46
|
+
},
|
|
47
|
+
async find(id) {
|
|
48
|
+
const db = await getDb();
|
|
49
|
+
return db.get('SELECT * FROM media WHERE id = ?', [id]);
|
|
50
|
+
},
|
|
51
|
+
async findByFilename(filename) {
|
|
52
|
+
const db = await getDb();
|
|
53
|
+
return db.get('SELECT * FROM media WHERE filename = ?', [filename]);
|
|
54
|
+
},
|
|
55
|
+
async findByUser(userId) {
|
|
56
|
+
const db = await getDb();
|
|
57
|
+
return db.all('SELECT * FROM media WHERE user_id = ? ORDER BY created_at DESC', [userId]);
|
|
58
|
+
},
|
|
59
|
+
async findByMimeType(mimeType) {
|
|
60
|
+
const db = await getDb();
|
|
61
|
+
return db.all('SELECT * FROM media WHERE mime_type LIKE ? ORDER BY created_at DESC', [`${mimeType}%`]);
|
|
62
|
+
},
|
|
63
|
+
async create(data) {
|
|
64
|
+
const db = await getDb();
|
|
65
|
+
const now = new Date().toISOString();
|
|
66
|
+
// Through the query builder, which appends RETURNING id on Postgres. A raw
|
|
67
|
+
// INSERT there reports lastInsertRowid as null, so the row is written and
|
|
68
|
+
// the caller is handed an object with no id.
|
|
69
|
+
const result = await (await query('media')).insert({
|
|
70
|
+
user_id: data.user_id || null,
|
|
71
|
+
filename: data.filename,
|
|
72
|
+
original_name: data.original_name,
|
|
73
|
+
path: data.path,
|
|
74
|
+
mime_type: data.mime_type || null,
|
|
75
|
+
size: data.size || null,
|
|
76
|
+
alt_text: data.alt_text || null,
|
|
77
|
+
width: data.width ?? null,
|
|
78
|
+
height: data.height ?? null,
|
|
79
|
+
created_at: now
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
id: result.lastInsertRowid,
|
|
83
|
+
user_id: data.user_id,
|
|
84
|
+
filename: data.filename,
|
|
85
|
+
original_name: data.original_name,
|
|
86
|
+
path: data.path,
|
|
87
|
+
mime_type: data.mime_type,
|
|
88
|
+
size: data.size,
|
|
89
|
+
alt_text: data.alt_text,
|
|
90
|
+
width: data.width ?? null,
|
|
91
|
+
height: data.height ?? null,
|
|
92
|
+
created_at: now
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
async update(id, data) {
|
|
96
|
+
const db = await getDb();
|
|
97
|
+
const fields = Object.keys(data).map(k => `${k} = ?`).join(', ');
|
|
98
|
+
await db.run(`UPDATE media SET ${fields} WHERE id = ?`, [...Object.values(data), id]);
|
|
99
|
+
return this.find(id);
|
|
100
|
+
},
|
|
101
|
+
async delete(id) {
|
|
102
|
+
const db = await getDb();
|
|
103
|
+
// Get media info before deleting (for file cleanup)
|
|
104
|
+
const media = await this.find(id);
|
|
105
|
+
if (media) {
|
|
106
|
+
// Update posts that use this as featured image
|
|
107
|
+
await db.run('UPDATE posts SET featured_image = NULL WHERE featured_image = ?', [id]);
|
|
108
|
+
// Delete media record
|
|
109
|
+
await db.run('DELETE FROM media WHERE id = ?', [id]);
|
|
110
|
+
}
|
|
111
|
+
return media;
|
|
112
|
+
},
|
|
113
|
+
async getTotalSize() {
|
|
114
|
+
const db = await getDb();
|
|
115
|
+
const result = await db.get('SELECT SUM(size) as total FROM media');
|
|
116
|
+
return result?.total || 0;
|
|
117
|
+
},
|
|
118
|
+
async getStats() {
|
|
119
|
+
const db = await getDb();
|
|
120
|
+
const total = await db.get('SELECT COUNT(*) as count FROM media');
|
|
121
|
+
const images = await db.get("SELECT COUNT(*) as count FROM media WHERE mime_type LIKE 'image/%'");
|
|
122
|
+
const documents = await db.get("SELECT COUNT(*) as count FROM media WHERE mime_type LIKE 'application/pdf' OR mime_type LIKE 'application/%document%'");
|
|
123
|
+
const sizeResult = await db.get('SELECT SUM(size) as total FROM media');
|
|
124
|
+
return {
|
|
125
|
+
total: total?.count || 0,
|
|
126
|
+
images: images?.count || 0,
|
|
127
|
+
documents: documents?.count || 0,
|
|
128
|
+
other: (total?.count || 0) - (images?.count || 0) - (documents?.count || 0),
|
|
129
|
+
totalSize: sizeResult?.total || 0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation menus and their items.
|
|
3
|
+
*
|
|
4
|
+
* The admin side reads and writes raw rows. The public side goes through
|
|
5
|
+
* `publicNavigation()`, which resolves linked content to its current path and
|
|
6
|
+
* leaves out anything a visitor could not open — so a menu never links to a
|
|
7
|
+
* draft, a trashed post, or a page that was deleted out from under it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TARGET_TYPES: readonly ["post", "page", "category"];
|
|
10
|
+
export type TargetType = (typeof TARGET_TYPES)[number];
|
|
11
|
+
export interface MenuRow {
|
|
12
|
+
id: number;
|
|
13
|
+
location: string;
|
|
14
|
+
name: string;
|
|
15
|
+
created_at: string;
|
|
16
|
+
updated_at: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MenuItemRow {
|
|
19
|
+
id: number;
|
|
20
|
+
menu_id: number;
|
|
21
|
+
parent_id: number | null;
|
|
22
|
+
label: string;
|
|
23
|
+
url: string | null;
|
|
24
|
+
target_type: TargetType | null;
|
|
25
|
+
target_id: number | null;
|
|
26
|
+
open_in_new_tab: number | boolean;
|
|
27
|
+
sort_order: number;
|
|
28
|
+
created_at?: string;
|
|
29
|
+
updated_at?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A menu item as `/api/v1/navigation` returns it. */
|
|
32
|
+
export interface PublicMenuItem {
|
|
33
|
+
id: number;
|
|
34
|
+
label: string;
|
|
35
|
+
/** Where the link goes: a site-relative path for linked content, or the URL as entered. */
|
|
36
|
+
url: string;
|
|
37
|
+
/** `url` for a typed link, otherwise the kind of content linked. */
|
|
38
|
+
type: 'url' | TargetType;
|
|
39
|
+
/** The linked content, so a front end with its own URL scheme can build its own link. Null for typed links. */
|
|
40
|
+
target: {
|
|
41
|
+
id: number;
|
|
42
|
+
slug: string;
|
|
43
|
+
} | null;
|
|
44
|
+
/** Open in a new tab/window. */
|
|
45
|
+
new_tab: boolean;
|
|
46
|
+
children: PublicMenuItem[];
|
|
47
|
+
}
|
|
48
|
+
/** Slugs of the linked content a visitor may see, by type and id. */
|
|
49
|
+
export type ResolvedTargets = Record<TargetType, Map<number, string>>;
|
|
50
|
+
/**
|
|
51
|
+
* Turn item rows into the public tree.
|
|
52
|
+
*
|
|
53
|
+
* An item linking to content that is not in `targets` — unpublished, trashed,
|
|
54
|
+
* scheduled, deleted — is dropped, and so are its children: a dropdown whose
|
|
55
|
+
* heading has gone would otherwise appear as orphaned links with no parent to
|
|
56
|
+
* hang from, and promoting them to the top level silently restructures the
|
|
57
|
+
* menu the admin built. Pure, so it is tested without a database.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildPublicTree(items: MenuItemRow[], targets: ResolvedTargets): PublicMenuItem[];
|
|
60
|
+
/** What a menu's `location` may be: a short identifier a front end can hard-code. */
|
|
61
|
+
export declare const LOCATION_PATTERN: RegExp;
|
|
62
|
+
/** Locations every install has. They can be emptied but not deleted. */
|
|
63
|
+
export declare const BUILT_IN_LOCATIONS: string[];
|
|
64
|
+
export type MenuItemValues = Omit<MenuItemRow, 'id' | 'menu_id' | 'created_at' | 'updated_at'>;
|
|
65
|
+
/**
|
|
66
|
+
* Validate a menu item's fields (not its relationships — whether the parent
|
|
67
|
+
* and target exist needs the database, and the controller checks those).
|
|
68
|
+
*
|
|
69
|
+
* An item is a typed link *or* a link to content, never both: given a target,
|
|
70
|
+
* any URL is discarded, so there is one answer to "where does this go".
|
|
71
|
+
*/
|
|
72
|
+
export declare function validateMenuItem(input: Record<string, unknown>): {
|
|
73
|
+
values: Omit<MenuItemValues, 'sort_order'> & {
|
|
74
|
+
sort_order: number | null;
|
|
75
|
+
};
|
|
76
|
+
} | {
|
|
77
|
+
errors: Record<string, string[]>;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Validate a reorder of one menu: the complete list of its items with each
|
|
81
|
+
* one's parent, in display order.
|
|
82
|
+
*
|
|
83
|
+
* Complete, not partial — a partial list could move a parent under another
|
|
84
|
+
* item while leaving its children where they were, producing the second
|
|
85
|
+
* level of nesting the menu does not support. Pure, for tests.
|
|
86
|
+
*/
|
|
87
|
+
export declare function validateReorder(input: unknown, existingIds: number[]): {
|
|
88
|
+
order: Array<{
|
|
89
|
+
id: number;
|
|
90
|
+
parent_id: number | null;
|
|
91
|
+
sort_order: number;
|
|
92
|
+
}>;
|
|
93
|
+
} | {
|
|
94
|
+
error: string;
|
|
95
|
+
};
|
|
96
|
+
export declare const Menu: {
|
|
97
|
+
all(): Promise<MenuRow[]>;
|
|
98
|
+
find(id: number): Promise<MenuRow | undefined>;
|
|
99
|
+
findByLocation(location: string): Promise<MenuRow | undefined>;
|
|
100
|
+
create(data: {
|
|
101
|
+
location: string;
|
|
102
|
+
name: string;
|
|
103
|
+
}): Promise<MenuRow | undefined>;
|
|
104
|
+
update(id: number, data: {
|
|
105
|
+
location: string;
|
|
106
|
+
name: string;
|
|
107
|
+
}): Promise<MenuRow | undefined>;
|
|
108
|
+
delete(id: number): Promise<void>;
|
|
109
|
+
items(menuId: number): Promise<MenuItemRow[]>;
|
|
110
|
+
findItem(id: number): Promise<MenuItemRow | undefined>;
|
|
111
|
+
createItem(menuId: number, data: MenuItemValues): Promise<MenuItemRow | undefined>;
|
|
112
|
+
updateItem(id: number, data: MenuItemValues): Promise<MenuItemRow | undefined>;
|
|
113
|
+
deleteItem(id: number): Promise<void>;
|
|
114
|
+
/** Apply a validated ordering: each item's parent and position. */
|
|
115
|
+
reorder(order: Array<{
|
|
116
|
+
id: number;
|
|
117
|
+
parent_id: number | null;
|
|
118
|
+
sort_order: number;
|
|
119
|
+
}>): Promise<void>;
|
|
120
|
+
/** The next sort position at the end of a menu (or of one parent's children). */
|
|
121
|
+
nextSortOrder(menuId: number, parentId: number | null): Promise<number>;
|
|
122
|
+
/** Does the linked content exist at all? (Admins may link to a draft.) */
|
|
123
|
+
targetExists(type: TargetType, id: number): Promise<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* Every menu, keyed by location, resolved for the public.
|
|
126
|
+
*
|
|
127
|
+
* Three queries for the linked content however many items there are — one
|
|
128
|
+
* per type, by id — rather than a lookup per item.
|
|
129
|
+
*/
|
|
130
|
+
publicNavigation(location?: string): Promise<Record<string, PublicMenuItem[]>>;
|
|
131
|
+
};
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation menus and their items.
|
|
3
|
+
*
|
|
4
|
+
* The admin side reads and writes raw rows. The public side goes through
|
|
5
|
+
* `publicNavigation()`, which resolves linked content to its current path and
|
|
6
|
+
* leaves out anything a visitor could not open — so a menu never links to a
|
|
7
|
+
* draft, a trashed post, or a page that was deleted out from under it.
|
|
8
|
+
*/
|
|
9
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
10
|
+
import { livePost } from "./visibility.js";
|
|
11
|
+
import { postPath, pagePath, categoryPath, isSafeLinkUrl } from "../helpers/content-paths.js";
|
|
12
|
+
export const TARGET_TYPES = ['post', 'page', 'category'];
|
|
13
|
+
/**
|
|
14
|
+
* Turn item rows into the public tree.
|
|
15
|
+
*
|
|
16
|
+
* An item linking to content that is not in `targets` — unpublished, trashed,
|
|
17
|
+
* scheduled, deleted — is dropped, and so are its children: a dropdown whose
|
|
18
|
+
* heading has gone would otherwise appear as orphaned links with no parent to
|
|
19
|
+
* hang from, and promoting them to the top level silently restructures the
|
|
20
|
+
* menu the admin built. Pure, so it is tested without a database.
|
|
21
|
+
*/
|
|
22
|
+
export function buildPublicTree(items, targets) {
|
|
23
|
+
const present = (item) => {
|
|
24
|
+
let url;
|
|
25
|
+
let target = null;
|
|
26
|
+
if (item.target_type && item.target_id) {
|
|
27
|
+
const slug = targets[item.target_type]?.get(Number(item.target_id));
|
|
28
|
+
if (slug === undefined)
|
|
29
|
+
return null;
|
|
30
|
+
url = item.target_type === 'post' ? postPath(slug, item.target_id)
|
|
31
|
+
: item.target_type === 'page' ? pagePath(slug)
|
|
32
|
+
: categoryPath(slug);
|
|
33
|
+
target = { id: Number(item.target_id), slug };
|
|
34
|
+
}
|
|
35
|
+
else if (item.url) {
|
|
36
|
+
url = item.url;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
id: item.id,
|
|
43
|
+
label: item.label,
|
|
44
|
+
url,
|
|
45
|
+
type: item.target_type ?? 'url',
|
|
46
|
+
target,
|
|
47
|
+
new_tab: Boolean(Number(item.open_in_new_tab)),
|
|
48
|
+
children: []
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const ordered = [...items].sort((a, b) => a.sort_order - b.sort_order || a.id - b.id);
|
|
52
|
+
const top = new Map();
|
|
53
|
+
const tree = [];
|
|
54
|
+
for (const item of ordered.filter(row => !row.parent_id)) {
|
|
55
|
+
const node = present(item);
|
|
56
|
+
if (!node)
|
|
57
|
+
continue;
|
|
58
|
+
top.set(item.id, node);
|
|
59
|
+
tree.push(node);
|
|
60
|
+
}
|
|
61
|
+
for (const item of ordered.filter(row => row.parent_id)) {
|
|
62
|
+
const parent = top.get(Number(item.parent_id));
|
|
63
|
+
const node = parent ? present(item) : null;
|
|
64
|
+
if (parent && node)
|
|
65
|
+
parent.children.push(node);
|
|
66
|
+
}
|
|
67
|
+
return tree;
|
|
68
|
+
}
|
|
69
|
+
/** What a menu's `location` may be: a short identifier a front end can hard-code. */
|
|
70
|
+
export const LOCATION_PATTERN = /^[a-z][a-z0-9_-]{0,49}$/;
|
|
71
|
+
/** Locations every install has. They can be emptied but not deleted. */
|
|
72
|
+
export const BUILT_IN_LOCATIONS = ['primary', 'secondary', 'footer'];
|
|
73
|
+
/**
|
|
74
|
+
* Validate a menu item's fields (not its relationships — whether the parent
|
|
75
|
+
* and target exist needs the database, and the controller checks those).
|
|
76
|
+
*
|
|
77
|
+
* An item is a typed link *or* a link to content, never both: given a target,
|
|
78
|
+
* any URL is discarded, so there is one answer to "where does this go".
|
|
79
|
+
*/
|
|
80
|
+
export function validateMenuItem(input) {
|
|
81
|
+
const errors = {};
|
|
82
|
+
const label = typeof input.label === 'string' ? input.label.trim() : '';
|
|
83
|
+
if (label === '')
|
|
84
|
+
errors.label = ['Label is required'];
|
|
85
|
+
else if (label.length > 120)
|
|
86
|
+
errors.label = ['Label must be at most 120 characters'];
|
|
87
|
+
let url = null;
|
|
88
|
+
let targetType = null;
|
|
89
|
+
let targetId = null;
|
|
90
|
+
const hasTarget = input.target_type !== undefined && input.target_type !== null && input.target_type !== '';
|
|
91
|
+
if (hasTarget) {
|
|
92
|
+
if (!TARGET_TYPES.includes(input.target_type)) {
|
|
93
|
+
errors.target_type = ['Must be post, page or category'];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
targetType = input.target_type;
|
|
97
|
+
}
|
|
98
|
+
const id = Number(input.target_id);
|
|
99
|
+
if (!Number.isInteger(id) || id <= 0)
|
|
100
|
+
errors.target_id = ['Choose what to link to'];
|
|
101
|
+
else
|
|
102
|
+
targetId = id;
|
|
103
|
+
}
|
|
104
|
+
else if (isSafeLinkUrl(input.url)) {
|
|
105
|
+
url = input.url.trim();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
errors.url = ['Must be an http(s) URL, a path starting with /, or a mailto: link'];
|
|
109
|
+
}
|
|
110
|
+
let parentId = null;
|
|
111
|
+
if (input.parent_id !== undefined && input.parent_id !== null && input.parent_id !== '') {
|
|
112
|
+
const id = Number(input.parent_id);
|
|
113
|
+
if (!Number.isInteger(id) || id <= 0)
|
|
114
|
+
errors.parent_id = ['Invalid parent'];
|
|
115
|
+
else
|
|
116
|
+
parentId = id;
|
|
117
|
+
}
|
|
118
|
+
let sortOrder = null;
|
|
119
|
+
if (input.sort_order !== undefined && input.sort_order !== null && input.sort_order !== '') {
|
|
120
|
+
const n = Number(input.sort_order);
|
|
121
|
+
if (!Number.isInteger(n) || n < 0)
|
|
122
|
+
errors.sort_order = ['Must be a whole number'];
|
|
123
|
+
else
|
|
124
|
+
sortOrder = n;
|
|
125
|
+
}
|
|
126
|
+
if (Object.keys(errors).length)
|
|
127
|
+
return { errors };
|
|
128
|
+
return {
|
|
129
|
+
values: {
|
|
130
|
+
label,
|
|
131
|
+
url,
|
|
132
|
+
target_type: targetType,
|
|
133
|
+
target_id: targetId,
|
|
134
|
+
parent_id: parentId,
|
|
135
|
+
open_in_new_tab: input.open_in_new_tab === true || input.open_in_new_tab === 'true' || input.open_in_new_tab === 1,
|
|
136
|
+
sort_order: sortOrder
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Validate a reorder of one menu: the complete list of its items with each
|
|
142
|
+
* one's parent, in display order.
|
|
143
|
+
*
|
|
144
|
+
* Complete, not partial — a partial list could move a parent under another
|
|
145
|
+
* item while leaving its children where they were, producing the second
|
|
146
|
+
* level of nesting the menu does not support. Pure, for tests.
|
|
147
|
+
*/
|
|
148
|
+
export function validateReorder(input, existingIds) {
|
|
149
|
+
if (!Array.isArray(input))
|
|
150
|
+
return { error: 'Items array is required' };
|
|
151
|
+
const order = input.map((entry, index) => ({
|
|
152
|
+
id: Number(entry?.id),
|
|
153
|
+
parent_id: entry?.parent_id === null || entry?.parent_id === undefined || entry?.parent_id === '' ? null : Number(entry.parent_id),
|
|
154
|
+
sort_order: index
|
|
155
|
+
}));
|
|
156
|
+
const ids = new Set(order.map(item => item.id));
|
|
157
|
+
const known = new Set(existingIds);
|
|
158
|
+
if (ids.size !== order.length)
|
|
159
|
+
return { error: 'Each item may appear only once' };
|
|
160
|
+
if (ids.size !== known.size || [...ids].some(id => !known.has(id))) {
|
|
161
|
+
return { error: 'The list must contain every item in this menu, and only those' };
|
|
162
|
+
}
|
|
163
|
+
const topLevel = new Set(order.filter(item => item.parent_id === null).map(item => item.id));
|
|
164
|
+
for (const item of order) {
|
|
165
|
+
if (item.parent_id === null)
|
|
166
|
+
continue;
|
|
167
|
+
if (item.parent_id === item.id)
|
|
168
|
+
return { error: 'An item cannot be its own parent' };
|
|
169
|
+
if (!topLevel.has(item.parent_id))
|
|
170
|
+
return { error: 'Items can be nested one level deep, under a top-level item' };
|
|
171
|
+
}
|
|
172
|
+
return { order };
|
|
173
|
+
}
|
|
174
|
+
const placeholders = (n) => Array(n).fill('?').join(', ');
|
|
175
|
+
export const Menu = {
|
|
176
|
+
async all() {
|
|
177
|
+
const db = await getDb();
|
|
178
|
+
return db.all('SELECT * FROM menus ORDER BY id');
|
|
179
|
+
},
|
|
180
|
+
async find(id) {
|
|
181
|
+
const db = await getDb();
|
|
182
|
+
return db.get('SELECT * FROM menus WHERE id = ?', [id]);
|
|
183
|
+
},
|
|
184
|
+
async findByLocation(location) {
|
|
185
|
+
const db = await getDb();
|
|
186
|
+
return db.get('SELECT * FROM menus WHERE location = ?', [location]);
|
|
187
|
+
},
|
|
188
|
+
async create(data) {
|
|
189
|
+
const db = await getDb();
|
|
190
|
+
const now = new Date().toISOString();
|
|
191
|
+
// Raw INSERT then a read by the unique location, which behaves the same on
|
|
192
|
+
// every adapter without relying on RETURNING.
|
|
193
|
+
await db.run('INSERT INTO menus (location, name, created_at, updated_at) VALUES (?, ?, ?, ?)', [data.location, data.name, now, now]);
|
|
194
|
+
return this.findByLocation(data.location);
|
|
195
|
+
},
|
|
196
|
+
async update(id, data) {
|
|
197
|
+
const db = await getDb();
|
|
198
|
+
await db.run('UPDATE menus SET location = ?, name = ?, updated_at = ? WHERE id = ?', [data.location, data.name, new Date().toISOString(), id]);
|
|
199
|
+
return this.find(id);
|
|
200
|
+
},
|
|
201
|
+
async delete(id) {
|
|
202
|
+
const db = await getDb();
|
|
203
|
+
// Explicitly rather than by ON DELETE CASCADE, which SQLite only honours
|
|
204
|
+
// with foreign_keys switched on for the connection.
|
|
205
|
+
await db.run('DELETE FROM menu_items WHERE menu_id = ?', [id]);
|
|
206
|
+
await db.run('DELETE FROM menus WHERE id = ?', [id]);
|
|
207
|
+
},
|
|
208
|
+
async items(menuId) {
|
|
209
|
+
const db = await getDb();
|
|
210
|
+
return db.all('SELECT * FROM menu_items WHERE menu_id = ? ORDER BY sort_order, id', [menuId]);
|
|
211
|
+
},
|
|
212
|
+
async findItem(id) {
|
|
213
|
+
const db = await getDb();
|
|
214
|
+
return db.get('SELECT * FROM menu_items WHERE id = ?', [id]);
|
|
215
|
+
},
|
|
216
|
+
async createItem(menuId, data) {
|
|
217
|
+
const db = await getDb();
|
|
218
|
+
const now = new Date().toISOString();
|
|
219
|
+
// There is no natural unique key to read an item back by, so this one
|
|
220
|
+
// goes through the query builder, which appends RETURNING id on Postgres.
|
|
221
|
+
const result = await (await query('menu_items')).insert({
|
|
222
|
+
menu_id: menuId,
|
|
223
|
+
parent_id: data.parent_id,
|
|
224
|
+
label: data.label,
|
|
225
|
+
url: data.url,
|
|
226
|
+
target_type: data.target_type,
|
|
227
|
+
target_id: data.target_id,
|
|
228
|
+
open_in_new_tab: data.open_in_new_tab ? 1 : 0,
|
|
229
|
+
sort_order: data.sort_order,
|
|
230
|
+
created_at: now,
|
|
231
|
+
updated_at: now
|
|
232
|
+
});
|
|
233
|
+
return this.findItem(Number(result.lastInsertRowid));
|
|
234
|
+
},
|
|
235
|
+
async updateItem(id, data) {
|
|
236
|
+
const db = await getDb();
|
|
237
|
+
await db.run(`UPDATE menu_items
|
|
238
|
+
SET parent_id = ?, label = ?, url = ?, target_type = ?, target_id = ?,
|
|
239
|
+
open_in_new_tab = ?, sort_order = ?, updated_at = ?
|
|
240
|
+
WHERE id = ?`, [data.parent_id, data.label, data.url, data.target_type, data.target_id,
|
|
241
|
+
data.open_in_new_tab ? 1 : 0, data.sort_order, new Date().toISOString(), id]);
|
|
242
|
+
return this.findItem(id);
|
|
243
|
+
},
|
|
244
|
+
async deleteItem(id) {
|
|
245
|
+
const db = await getDb();
|
|
246
|
+
await db.run('DELETE FROM menu_items WHERE parent_id = ?', [id]);
|
|
247
|
+
await db.run('DELETE FROM menu_items WHERE id = ?', [id]);
|
|
248
|
+
},
|
|
249
|
+
/** Apply a validated ordering: each item's parent and position. */
|
|
250
|
+
async reorder(order) {
|
|
251
|
+
const db = await getDb();
|
|
252
|
+
const now = new Date().toISOString();
|
|
253
|
+
for (const item of order) {
|
|
254
|
+
await db.run('UPDATE menu_items SET parent_id = ?, sort_order = ?, updated_at = ? WHERE id = ?', [item.parent_id, item.sort_order, now, item.id]);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
/** The next sort position at the end of a menu (or of one parent's children). */
|
|
258
|
+
async nextSortOrder(menuId, parentId) {
|
|
259
|
+
const db = await getDb();
|
|
260
|
+
const row = parentId
|
|
261
|
+
? await db.get('SELECT MAX(sort_order) AS max FROM menu_items WHERE menu_id = ? AND parent_id = ?', [menuId, parentId])
|
|
262
|
+
: await db.get('SELECT MAX(sort_order) AS max FROM menu_items WHERE menu_id = ? AND parent_id IS NULL', [menuId]);
|
|
263
|
+
return row?.max === null || row?.max === undefined ? 0 : Number(row.max) + 1;
|
|
264
|
+
},
|
|
265
|
+
/** Does the linked content exist at all? (Admins may link to a draft.) */
|
|
266
|
+
async targetExists(type, id) {
|
|
267
|
+
const db = await getDb();
|
|
268
|
+
const table = type === 'post' ? 'posts' : type === 'page' ? 'pages' : 'categories';
|
|
269
|
+
return Boolean(await db.get(`SELECT id FROM ${table} WHERE id = ?`, [id]));
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Every menu, keyed by location, resolved for the public.
|
|
273
|
+
*
|
|
274
|
+
* Three queries for the linked content however many items there are — one
|
|
275
|
+
* per type, by id — rather than a lookup per item.
|
|
276
|
+
*/
|
|
277
|
+
async publicNavigation(location) {
|
|
278
|
+
const db = await getDb();
|
|
279
|
+
const menus = location
|
|
280
|
+
? await db.all('SELECT * FROM menus WHERE location = ?', [location])
|
|
281
|
+
: await db.all('SELECT * FROM menus ORDER BY id');
|
|
282
|
+
if (menus.length === 0)
|
|
283
|
+
return {};
|
|
284
|
+
const items = await db.all(`SELECT * FROM menu_items WHERE menu_id IN (${placeholders(menus.length)}) ORDER BY sort_order, id`, menus.map(menu => menu.id));
|
|
285
|
+
const ids = (type) => [...new Set(items.filter(item => item.target_type === type && item.target_id).map(item => Number(item.target_id)))];
|
|
286
|
+
const lookup = async (type, sql) => {
|
|
287
|
+
const list = ids(type);
|
|
288
|
+
const map = new Map();
|
|
289
|
+
if (list.length === 0)
|
|
290
|
+
return map;
|
|
291
|
+
const rows = await db.all(sql(placeholders(list.length)), list);
|
|
292
|
+
// A post without a slug is still reachable by id, so it resolves to
|
|
293
|
+
// its id; the path helper does the same.
|
|
294
|
+
for (const row of rows)
|
|
295
|
+
map.set(Number(row.id), row.slug || String(row.id));
|
|
296
|
+
return map;
|
|
297
|
+
};
|
|
298
|
+
// The same visibility rules as the rest of the public API: `livePost` for
|
|
299
|
+
// posts (published, not trashed, its time has come), `published = 1` for
|
|
300
|
+
// pages. Categories have no visibility of their own.
|
|
301
|
+
const targets = {
|
|
302
|
+
post: await lookup('post', list => `SELECT posts.id, posts.slug FROM posts WHERE posts.id IN (${list}) AND ${livePost('posts')}`),
|
|
303
|
+
page: await lookup('page', list => `SELECT id, slug FROM pages WHERE id IN (${list}) AND published = 1`),
|
|
304
|
+
category: await lookup('category', list => `SELECT id, slug FROM categories WHERE id IN (${list})`)
|
|
305
|
+
};
|
|
306
|
+
const result = {};
|
|
307
|
+
for (const menu of menus) {
|
|
308
|
+
result[menu.location] = buildPublicTree(items.filter(item => item.menu_id === menu.id), targets);
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Page as PageType } from '../types/index.ts';
|
|
2
|
+
interface CreatePageData {
|
|
3
|
+
title: string;
|
|
4
|
+
slug?: string;
|
|
5
|
+
content?: string;
|
|
6
|
+
featured_image?: number | null;
|
|
7
|
+
template?: string;
|
|
8
|
+
published?: boolean;
|
|
9
|
+
parent_id?: number;
|
|
10
|
+
menu_order?: number;
|
|
11
|
+
meta_title?: string;
|
|
12
|
+
meta_description?: string;
|
|
13
|
+
}
|
|
14
|
+
interface UpdatePageData {
|
|
15
|
+
title?: string;
|
|
16
|
+
slug?: string;
|
|
17
|
+
content?: string;
|
|
18
|
+
featured_image?: number | null;
|
|
19
|
+
template?: string;
|
|
20
|
+
published?: boolean;
|
|
21
|
+
parent_id?: number;
|
|
22
|
+
menu_order?: number;
|
|
23
|
+
meta_title?: string;
|
|
24
|
+
meta_description?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const Page: {
|
|
27
|
+
/**
|
|
28
|
+
* One page of pages, with the total so a caller can size the pager.
|
|
29
|
+
*
|
|
30
|
+
* Counted separately rather than with a window function: the drivers do not
|
|
31
|
+
* agree on those, and this runs on all of them.
|
|
32
|
+
*/
|
|
33
|
+
paginate({ perPage, offset }: {
|
|
34
|
+
perPage: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
pages: PageType[];
|
|
38
|
+
total: number;
|
|
39
|
+
}>;
|
|
40
|
+
all(): Promise<PageType[]>;
|
|
41
|
+
find(id: number): Promise<PageType | undefined>;
|
|
42
|
+
findBySlug(slug: string): Promise<PageType | undefined>;
|
|
43
|
+
findPublished(): Promise<PageType[]>;
|
|
44
|
+
findPublishedBySlug(slug: string): Promise<PageType | undefined>;
|
|
45
|
+
tree(): Promise<PageType[]>;
|
|
46
|
+
create(data: CreatePageData): Promise<PageType>;
|
|
47
|
+
update(id: number, data: UpdatePageData): Promise<PageType>;
|
|
48
|
+
delete(id: number): Promise<void>;
|
|
49
|
+
slugExists(slug: string, excludeId?: number): Promise<boolean>;
|
|
50
|
+
reorder(pages: {
|
|
51
|
+
id: number;
|
|
52
|
+
menu_order: number;
|
|
53
|
+
}[]): Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
export {};
|