@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,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content types — WordPress's custom post types — and their custom fields.
|
|
3
|
+
*
|
|
4
|
+
* Every entry of every type is a row in `posts`, told apart by
|
|
5
|
+
* `posts.post_type`, so everything a post already has (status, scheduling,
|
|
6
|
+
* revisions, locks, SEO, the editor) a recipe has for free. This module holds
|
|
7
|
+
* what differs per type: its labels, where it lives on the public site, which
|
|
8
|
+
* editor panels it supports, and the schema its custom fields are validated
|
|
9
|
+
* against. See migrations 038 and 039.
|
|
10
|
+
*
|
|
11
|
+
* The validators at the top are pure and exported, so tests drive them without
|
|
12
|
+
* a database. Imports carry `.ts` extensions so the module also loads under
|
|
13
|
+
* plain Node, which is how tests/phase3-content-model.test.js exercises it.
|
|
14
|
+
*/
|
|
15
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
16
|
+
import { isHttpUrl, isRelativePath, MAX_URL_LENGTH, normalizeRouteBase, POST_ROUTE_BASE } from "../helpers/content-paths.js";
|
|
17
|
+
/** The kinds of custom field an editor can declare. */
|
|
18
|
+
export const FIELD_TYPES = ['text', 'textarea', 'number', 'url', 'date', 'boolean', 'select'];
|
|
19
|
+
/** The editor panels and public behaviours a type can switch off. */
|
|
20
|
+
export const SUPPORTS = ['excerpt', 'featured_image', 'comments', 'categories', 'tags', 'custom_fields'];
|
|
21
|
+
/**
|
|
22
|
+
* Keys a custom type may not take. `post` is the built-in; the rest are words
|
|
23
|
+
* the API already gives a meaning (`?type=any`) or WordPress reserves, which an
|
|
24
|
+
* importer mapping WordPress types across would otherwise collide with.
|
|
25
|
+
*/
|
|
26
|
+
export const RESERVED_TYPE_KEYS = ['post', 'page', 'any', 'all', 'attachment', 'revision', 'nav_menu_item', 'media', 'comment'];
|
|
27
|
+
/** Longest stored value per field type, so a field cannot become a second body. */
|
|
28
|
+
const TEXT_MAX = 1000;
|
|
29
|
+
const TEXTAREA_MAX = 20_000;
|
|
30
|
+
const MAX_FIELDS = 50;
|
|
31
|
+
const MAX_OPTIONS = 100;
|
|
32
|
+
// --- Pure validation ---------------------------------------------------------
|
|
33
|
+
const truthy = (value) => value === true || value === 1 || value === '1' || value === 'true' || value === 'on';
|
|
34
|
+
function label(value, max = 100) {
|
|
35
|
+
if (typeof value !== 'string')
|
|
36
|
+
return null;
|
|
37
|
+
const trimmed = value.trim();
|
|
38
|
+
return trimmed && trimmed.length <= max ? trimmed : null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The type definition a create or update asks for.
|
|
42
|
+
*
|
|
43
|
+
* `existing` is null on create. On update absent keys keep their value, and the
|
|
44
|
+
* built-in type keeps its key, route base and visibility whatever is sent: they
|
|
45
|
+
* are what every URL the site has already published is made of.
|
|
46
|
+
*
|
|
47
|
+
* Uniqueness (key, route base) needs the database and is checked by the model.
|
|
48
|
+
*/
|
|
49
|
+
export function validateContentType(input, existing = null) {
|
|
50
|
+
const body = (input && typeof input === 'object' ? input : {});
|
|
51
|
+
const errors = {};
|
|
52
|
+
let key = existing?.key ?? '';
|
|
53
|
+
if (!existing) {
|
|
54
|
+
const raw = typeof body.key === 'string' ? body.key.trim().toLowerCase() : '';
|
|
55
|
+
if (!/^[a-z][a-z0-9_]{0,31}$/.test(raw)) {
|
|
56
|
+
errors.key = ['Key must start with a letter and use lowercase letters, digits and underscores (32 at most)'];
|
|
57
|
+
}
|
|
58
|
+
else if (RESERVED_TYPE_KEYS.includes(raw)) {
|
|
59
|
+
errors.key = [`"${raw}" is reserved`];
|
|
60
|
+
}
|
|
61
|
+
key = raw;
|
|
62
|
+
}
|
|
63
|
+
else if (body.key !== undefined && body.key !== existing.key) {
|
|
64
|
+
// Renaming the key would orphan every post that carries the old one.
|
|
65
|
+
errors.key = ['The key cannot be changed once a type exists'];
|
|
66
|
+
}
|
|
67
|
+
const singular = 'singular_label' in body || !existing ? label(body.singular_label) : existing.singular_label;
|
|
68
|
+
const plural = 'plural_label' in body || !existing ? label(body.plural_label) : existing.plural_label;
|
|
69
|
+
if (!singular)
|
|
70
|
+
errors.singular_label = ['Singular label is required (100 characters at most)'];
|
|
71
|
+
if (!plural)
|
|
72
|
+
errors.plural_label = ['Plural label is required (100 characters at most)'];
|
|
73
|
+
let routeBase = existing?.route_base ?? '';
|
|
74
|
+
if (existing?.builtin) {
|
|
75
|
+
routeBase = POST_ROUTE_BASE;
|
|
76
|
+
}
|
|
77
|
+
else if ('route_base' in body || !existing) {
|
|
78
|
+
const requested = typeof body.route_base === 'string' && body.route_base.trim()
|
|
79
|
+
? body.route_base
|
|
80
|
+
: key.replace(/_/g, '-');
|
|
81
|
+
const normalized = normalizeRouteBase(requested);
|
|
82
|
+
if (!normalized) {
|
|
83
|
+
errors.route_base = ['Route base must be one path segment (letters, digits, hyphens) that the site does not already use'];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
routeBase = normalized;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const description = 'description' in body
|
|
90
|
+
? (typeof body.description === 'string' && body.description.trim() ? body.description.trim().slice(0, 1000) : null)
|
|
91
|
+
: existing?.description ?? null;
|
|
92
|
+
const supports = {};
|
|
93
|
+
const requestedSupports = (body.supports && typeof body.supports === 'object' ? body.supports : {});
|
|
94
|
+
for (const name of SUPPORTS) {
|
|
95
|
+
supports[name] = name in requestedSupports
|
|
96
|
+
? truthy(requestedSupports[name])
|
|
97
|
+
: existing ? existing.supports[name] : true;
|
|
98
|
+
}
|
|
99
|
+
const isPublic = existing?.builtin ? true : 'public' in body ? truthy(body.public) : existing?.public ?? true;
|
|
100
|
+
const sortOrder = 'sort_order' in body && Number.isInteger(Number(body.sort_order))
|
|
101
|
+
? Number(body.sort_order)
|
|
102
|
+
: existing?.sort_order ?? 0;
|
|
103
|
+
let fields;
|
|
104
|
+
if ('fields' in body) {
|
|
105
|
+
const checked = validateFieldDefinitions(body.fields);
|
|
106
|
+
if ('errors' in checked)
|
|
107
|
+
Object.assign(errors, checked.errors);
|
|
108
|
+
else
|
|
109
|
+
fields = checked.fields;
|
|
110
|
+
}
|
|
111
|
+
if (Object.keys(errors).length)
|
|
112
|
+
return { errors };
|
|
113
|
+
return {
|
|
114
|
+
values: {
|
|
115
|
+
key,
|
|
116
|
+
singular_label: singular,
|
|
117
|
+
plural_label: plural,
|
|
118
|
+
description,
|
|
119
|
+
route_base: routeBase,
|
|
120
|
+
public: isPublic,
|
|
121
|
+
// Stored for when hierarchy arrives; nothing reads it yet, so it is
|
|
122
|
+
// refused rather than silently accepted and ignored.
|
|
123
|
+
hierarchical: false,
|
|
124
|
+
sort_order: sortOrder,
|
|
125
|
+
supports,
|
|
126
|
+
...(fields ? { fields } : {})
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** A type's field list, as the admin's fields editor sends it. */
|
|
131
|
+
export function validateFieldDefinitions(input) {
|
|
132
|
+
if (!Array.isArray(input))
|
|
133
|
+
return { errors: { fields: ['Fields must be a list'] } };
|
|
134
|
+
if (input.length > MAX_FIELDS)
|
|
135
|
+
return { errors: { fields: [`At most ${MAX_FIELDS} fields per type`] } };
|
|
136
|
+
const errors = {};
|
|
137
|
+
const fields = [];
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
input.forEach((raw, index) => {
|
|
140
|
+
const item = (raw && typeof raw === 'object' ? raw : {});
|
|
141
|
+
const at = `fields.${index}`;
|
|
142
|
+
const key = typeof item.key === 'string' ? item.key.trim().toLowerCase() : '';
|
|
143
|
+
if (!/^[a-z][a-z0-9_]{0,49}$/.test(key)) {
|
|
144
|
+
errors[`${at}.key`] = ['Field key must start with a letter and use lowercase letters, digits and underscores'];
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (seen.has(key)) {
|
|
148
|
+
errors[`${at}.key`] = [`Duplicate field key "${key}"`];
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
seen.add(key);
|
|
152
|
+
const fieldLabel = label(item.label) ?? null;
|
|
153
|
+
if (!fieldLabel)
|
|
154
|
+
errors[`${at}.label`] = ['Label is required'];
|
|
155
|
+
const type = FIELD_TYPES.includes(String(item.type)) ? item.type : null;
|
|
156
|
+
if (!type)
|
|
157
|
+
errors[`${at}.type`] = [`Type must be one of ${FIELD_TYPES.join(', ')}`];
|
|
158
|
+
let options = [];
|
|
159
|
+
if (type === 'select') {
|
|
160
|
+
const list = Array.isArray(item.options)
|
|
161
|
+
? item.options
|
|
162
|
+
: typeof item.options === 'string' ? item.options.split('\n') : [];
|
|
163
|
+
options = [...new Set(list.map((option) => String(option).trim()).filter(Boolean))];
|
|
164
|
+
if (options.length === 0)
|
|
165
|
+
errors[`${at}.options`] = ['A select field needs at least one option'];
|
|
166
|
+
if (options.length > MAX_OPTIONS)
|
|
167
|
+
errors[`${at}.options`] = [`At most ${MAX_OPTIONS} options`];
|
|
168
|
+
if (options.some((option) => option.length > 200))
|
|
169
|
+
errors[`${at}.options`] = ['Options are 200 characters at most'];
|
|
170
|
+
}
|
|
171
|
+
const help = typeof item.help_text === 'string' && item.help_text.trim() ? item.help_text.trim().slice(0, 500) : null;
|
|
172
|
+
if (fieldLabel && type) {
|
|
173
|
+
fields.push({ key, label: fieldLabel, type, options, required: truthy(item.required), help_text: help });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return Object.keys(errors).length ? { errors } : { fields };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A post's custom field values, checked against its type's schema.
|
|
180
|
+
*
|
|
181
|
+
* Each value is coerced to its field's type and stored in that form — a number
|
|
182
|
+
* as a number, a date as `YYYY-MM-DD`, a boolean as a boolean — so a consumer
|
|
183
|
+
* never has to guess whether `"3"` is three. Blank values are left out rather
|
|
184
|
+
* than stored as empty strings, which is also what "not filled in" means to a
|
|
185
|
+
* required check.
|
|
186
|
+
*
|
|
187
|
+
* Keys the schema does not declare are dropped, not refused: a field removed
|
|
188
|
+
* from a type should not make every post that still carries a value for it
|
|
189
|
+
* unsaveable. Only declared, valid values are ever stored.
|
|
190
|
+
*/
|
|
191
|
+
export function validateFieldValues(definitions, input) {
|
|
192
|
+
const body = (input && typeof input === 'object' && !Array.isArray(input) ? input : {});
|
|
193
|
+
const values = {};
|
|
194
|
+
const errors = {};
|
|
195
|
+
for (const field of definitions) {
|
|
196
|
+
const raw = body[field.key];
|
|
197
|
+
const blank = raw === undefined || raw === null || (typeof raw === 'string' && raw.trim() === '');
|
|
198
|
+
// A boolean is never blank in the way text is: unchecked is `false`, and
|
|
199
|
+
// `false` is an answer. Required on a boolean therefore means "present".
|
|
200
|
+
if (field.type === 'boolean') {
|
|
201
|
+
if (raw === undefined || raw === null || raw === '') {
|
|
202
|
+
if (field.required)
|
|
203
|
+
errors[`fields.${field.key}`] = [`${field.label} is required`];
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
values[field.key] = truthy(raw);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (blank) {
|
|
210
|
+
if (field.required)
|
|
211
|
+
errors[`fields.${field.key}`] = [`${field.label} is required`];
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const result = coerce(field, raw);
|
|
215
|
+
if ('error' in result)
|
|
216
|
+
errors[`fields.${field.key}`] = [result.error];
|
|
217
|
+
else
|
|
218
|
+
values[field.key] = result.value;
|
|
219
|
+
}
|
|
220
|
+
return Object.keys(errors).length ? { errors } : { values };
|
|
221
|
+
}
|
|
222
|
+
function coerce(field, raw) {
|
|
223
|
+
const text = typeof raw === 'string' ? raw.trim() : typeof raw === 'number' ? String(raw) : null;
|
|
224
|
+
switch (field.type) {
|
|
225
|
+
case 'text':
|
|
226
|
+
if (text === null)
|
|
227
|
+
return { error: `${field.label} must be text` };
|
|
228
|
+
if (/[\r\n]/.test(text))
|
|
229
|
+
return { error: `${field.label} must be a single line` };
|
|
230
|
+
return text.length <= TEXT_MAX ? { value: text } : { error: `${field.label} is ${TEXT_MAX} characters at most` };
|
|
231
|
+
case 'textarea':
|
|
232
|
+
if (text === null)
|
|
233
|
+
return { error: `${field.label} must be text` };
|
|
234
|
+
return text.length <= TEXTAREA_MAX ? { value: text } : { error: `${field.label} is ${TEXTAREA_MAX} characters at most` };
|
|
235
|
+
case 'number': {
|
|
236
|
+
const n = typeof raw === 'number' ? raw : Number(text);
|
|
237
|
+
return text !== null && text !== '' && Number.isFinite(n) ? { value: n } : { error: `${field.label} must be a number` };
|
|
238
|
+
}
|
|
239
|
+
case 'url':
|
|
240
|
+
// The same allowlist a menu link gets: these are rendered into `href` by
|
|
241
|
+
// a theme, and a `javascript:` value there is stored XSS.
|
|
242
|
+
if (text === null || text.length > MAX_URL_LENGTH || (!isHttpUrl(text) && !isRelativePath(text))) {
|
|
243
|
+
return { error: `${field.label} must be an http(s) URL or a path starting with /` };
|
|
244
|
+
}
|
|
245
|
+
return { value: text };
|
|
246
|
+
case 'date': {
|
|
247
|
+
// Stored as a calendar date. A datetime would carry a time zone, and
|
|
248
|
+
// "the event is on the 3rd" is not a moment.
|
|
249
|
+
const match = text?.match(/^(\d{4})-(\d{2})-(\d{2})(?:$|T)/);
|
|
250
|
+
if (!match)
|
|
251
|
+
return { error: `${field.label} must be a date (YYYY-MM-DD)` };
|
|
252
|
+
const date = new Date(`${match[1]}-${match[2]}-${match[3]}T00:00:00Z`);
|
|
253
|
+
if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== `${match[1]}-${match[2]}-${match[3]}`) {
|
|
254
|
+
return { error: `${field.label} must be a real date` };
|
|
255
|
+
}
|
|
256
|
+
return { value: `${match[1]}-${match[2]}-${match[3]}` };
|
|
257
|
+
}
|
|
258
|
+
case 'select':
|
|
259
|
+
return text !== null && field.options.includes(text)
|
|
260
|
+
? { value: text }
|
|
261
|
+
: { error: `${field.label} must be one of ${field.options.join(', ')}` };
|
|
262
|
+
default:
|
|
263
|
+
return { error: `${field.label} has an unknown type` };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** The `fields` column as an object. Corrupt or absent JSON reads as empty. */
|
|
267
|
+
export function parseStoredFields(value) {
|
|
268
|
+
if (value && typeof value === 'object' && !Array.isArray(value))
|
|
269
|
+
return value;
|
|
270
|
+
if (typeof value !== 'string' || !value)
|
|
271
|
+
return {};
|
|
272
|
+
try {
|
|
273
|
+
const parsed = JSON.parse(value);
|
|
274
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
return {};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Stored values, restricted to what the type declares now.
|
|
282
|
+
*
|
|
283
|
+
* What a public read returns. A value left behind by a field that has since
|
|
284
|
+
* been deleted is not part of the type any more and should not keep being
|
|
285
|
+
* published.
|
|
286
|
+
*/
|
|
287
|
+
export function publicFieldValues(definitions, stored) {
|
|
288
|
+
const values = parseStoredFields(stored);
|
|
289
|
+
const out = {};
|
|
290
|
+
for (const field of definitions) {
|
|
291
|
+
if (field.key in values)
|
|
292
|
+
out[field.key] = values[field.key];
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
// --- Rows to records ---------------------------------------------------------
|
|
297
|
+
function shapeField(row) {
|
|
298
|
+
let options = [];
|
|
299
|
+
try {
|
|
300
|
+
const parsed = row.options ? JSON.parse(row.options) : [];
|
|
301
|
+
options = Array.isArray(parsed) ? parsed.map(String) : [];
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
options = [];
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
key: row.key,
|
|
308
|
+
label: row.label,
|
|
309
|
+
type: FIELD_TYPES.includes(row.type) ? row.type : 'text',
|
|
310
|
+
options,
|
|
311
|
+
required: Boolean(Number(row.required)),
|
|
312
|
+
help_text: row.help_text
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function shapeType(row, fields) {
|
|
316
|
+
return {
|
|
317
|
+
id: Number(row.id),
|
|
318
|
+
key: row.key,
|
|
319
|
+
singular_label: row.singular_label,
|
|
320
|
+
plural_label: row.plural_label,
|
|
321
|
+
description: row.description,
|
|
322
|
+
route_base: row.route_base,
|
|
323
|
+
public: Boolean(Number(row.is_public)),
|
|
324
|
+
hierarchical: Boolean(Number(row.hierarchical)),
|
|
325
|
+
builtin: Boolean(Number(row.builtin)),
|
|
326
|
+
sort_order: Number(row.sort_order) || 0,
|
|
327
|
+
supports: {
|
|
328
|
+
excerpt: Boolean(Number(row.supports_excerpt)),
|
|
329
|
+
featured_image: Boolean(Number(row.supports_featured_image)),
|
|
330
|
+
comments: Boolean(Number(row.supports_comments)),
|
|
331
|
+
categories: Boolean(Number(row.supports_categories)),
|
|
332
|
+
tags: Boolean(Number(row.supports_tags)),
|
|
333
|
+
custom_fields: Boolean(Number(row.supports_custom_fields))
|
|
334
|
+
},
|
|
335
|
+
fields
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function columnsFor(values) {
|
|
339
|
+
return {
|
|
340
|
+
key: values.key,
|
|
341
|
+
singular_label: values.singular_label,
|
|
342
|
+
plural_label: values.plural_label,
|
|
343
|
+
description: values.description,
|
|
344
|
+
route_base: values.route_base,
|
|
345
|
+
is_public: values.public ? 1 : 0,
|
|
346
|
+
hierarchical: values.hierarchical ? 1 : 0,
|
|
347
|
+
sort_order: values.sort_order,
|
|
348
|
+
supports_excerpt: values.supports.excerpt ? 1 : 0,
|
|
349
|
+
supports_featured_image: values.supports.featured_image ? 1 : 0,
|
|
350
|
+
supports_comments: values.supports.comments ? 1 : 0,
|
|
351
|
+
supports_categories: values.supports.categories ? 1 : 0,
|
|
352
|
+
supports_tags: values.supports.tags ? 1 : 0,
|
|
353
|
+
supports_custom_fields: values.supports.custom_fields ? 1 : 0
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
// --- Database ----------------------------------------------------------------
|
|
357
|
+
/**
|
|
358
|
+
* Every type with its fields, in two queries however many types there are.
|
|
359
|
+
*
|
|
360
|
+
* Content types are a handful of rows read on most requests that touch a post,
|
|
361
|
+
* so this is the one read everything else builds on; it is not cached in
|
|
362
|
+
* memory because a serverless instance has no way to hear that an admin
|
|
363
|
+
* changed one on another instance.
|
|
364
|
+
*/
|
|
365
|
+
async function loadAll() {
|
|
366
|
+
const db = await getDb();
|
|
367
|
+
const rows = (await db.all('SELECT * FROM content_types ORDER BY sort_order ASC, id ASC'));
|
|
368
|
+
const fieldRows = (await db.all('SELECT * FROM content_type_fields ORDER BY sort_order ASC, id ASC'));
|
|
369
|
+
const byType = new Map();
|
|
370
|
+
for (const row of fieldRows) {
|
|
371
|
+
const list = byType.get(Number(row.content_type_id)) ?? [];
|
|
372
|
+
list.push(shapeField(row));
|
|
373
|
+
byType.set(Number(row.content_type_id), list);
|
|
374
|
+
}
|
|
375
|
+
return rows.map((row) => shapeType(row, byType.get(Number(row.id)) ?? []));
|
|
376
|
+
}
|
|
377
|
+
export const ContentType = {
|
|
378
|
+
async all(options = {}) {
|
|
379
|
+
const types = await loadAll();
|
|
380
|
+
return options.publicOnly ? types.filter((type) => type.public) : types;
|
|
381
|
+
},
|
|
382
|
+
async find(id) {
|
|
383
|
+
return (await loadAll()).find((type) => type.id === id);
|
|
384
|
+
},
|
|
385
|
+
async findByKey(key) {
|
|
386
|
+
return (await loadAll()).find((type) => type.key === key);
|
|
387
|
+
},
|
|
388
|
+
/** Which type owns a route base, for the theme's `/:base/:slug`. */
|
|
389
|
+
async findByRouteBase(routeBase) {
|
|
390
|
+
return (await loadAll()).find((type) => type.route_base === routeBase);
|
|
391
|
+
},
|
|
392
|
+
/** Posts of a type, trashed ones included — a type with any cannot be deleted. */
|
|
393
|
+
async postCount(key) {
|
|
394
|
+
const db = await getDb();
|
|
395
|
+
const row = await db.get('SELECT COUNT(*) AS total FROM posts WHERE post_type = ?', [key]);
|
|
396
|
+
return Number(row?.total) || 0;
|
|
397
|
+
},
|
|
398
|
+
/** Is this key or route base taken by a type other than `excludeId`? */
|
|
399
|
+
async clashes(values, excludeId) {
|
|
400
|
+
const types = await loadAll();
|
|
401
|
+
const errors = {};
|
|
402
|
+
const others = types.filter((type) => type.id !== excludeId);
|
|
403
|
+
if (others.some((type) => type.key === values.key))
|
|
404
|
+
errors.key = ['A content type with this key already exists'];
|
|
405
|
+
if (others.some((type) => type.route_base === values.route_base))
|
|
406
|
+
errors.route_base = ['Another content type already lives at this route base'];
|
|
407
|
+
return errors;
|
|
408
|
+
},
|
|
409
|
+
async create(values) {
|
|
410
|
+
// Through the query builder, which appends RETURNING id on Postgres.
|
|
411
|
+
const result = await (await query('content_types')).insert({ ...columnsFor(values), builtin: 0 });
|
|
412
|
+
const id = Number(result.lastInsertRowid);
|
|
413
|
+
if (values.fields)
|
|
414
|
+
await this.replaceFields(id, values.fields);
|
|
415
|
+
return (await this.find(id));
|
|
416
|
+
},
|
|
417
|
+
async update(id, values) {
|
|
418
|
+
const db = await getDb();
|
|
419
|
+
const columns = columnsFor(values);
|
|
420
|
+
const keys = Object.keys(columns);
|
|
421
|
+
await db.run(`UPDATE content_types SET ${keys.map((key) => `${key} = ?`).join(', ')}, updated_at = ? WHERE id = ?`, [...keys.map((key) => columns[key]), new Date().toISOString(), id]);
|
|
422
|
+
if (values.fields)
|
|
423
|
+
await this.replaceFields(id, values.fields);
|
|
424
|
+
return (await this.find(id));
|
|
425
|
+
},
|
|
426
|
+
/**
|
|
427
|
+
* Replace a type's field list.
|
|
428
|
+
*
|
|
429
|
+
* Rebuilt rather than diffed, for the same reason categories are: the editor
|
|
430
|
+
* sends the whole list, and a merge would make removing a field do nothing.
|
|
431
|
+
* Stored values on posts are left alone — `publicFieldValues` stops a removed
|
|
432
|
+
* field being published, and re-adding it brings the values back.
|
|
433
|
+
*/
|
|
434
|
+
async replaceFields(typeId, fields) {
|
|
435
|
+
const db = await getDb();
|
|
436
|
+
await db.run('DELETE FROM content_type_fields WHERE content_type_id = ?', [typeId]);
|
|
437
|
+
for (const [index, field] of fields.entries()) {
|
|
438
|
+
await db.run(`INSERT INTO content_type_fields (content_type_id, key, label, type, options, required, help_text, sort_order)
|
|
439
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [typeId, field.key, field.label, field.type, field.options.length ? JSON.stringify(field.options) : null,
|
|
440
|
+
field.required ? 1 : 0, field.help_text, index]);
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
async delete(id) {
|
|
444
|
+
const db = await getDb();
|
|
445
|
+
await db.run('DELETE FROM content_type_fields WHERE content_type_id = ?', [id]);
|
|
446
|
+
await db.run('DELETE FROM taxonomy_content_types WHERE content_type_id = ?', [id]);
|
|
447
|
+
await db.run('DELETE FROM content_types WHERE id = ? AND builtin = 0', [id]);
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* A type's route base, or null when the type is unknown.
|
|
452
|
+
*
|
|
453
|
+
* Exported on its own because the redirect helper needs exactly this and
|
|
454
|
+
* nothing else about the type.
|
|
455
|
+
*/
|
|
456
|
+
export async function routeBaseFor(key) {
|
|
457
|
+
if (key === 'post')
|
|
458
|
+
return POST_ROUTE_BASE;
|
|
459
|
+
const db = await getDb();
|
|
460
|
+
const row = await db.get('SELECT route_base FROM content_types WHERE key = ?', [key]);
|
|
461
|
+
return row?.route_base ?? null;
|
|
462
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface CredentialRecord {
|
|
2
|
+
id: number;
|
|
3
|
+
user_id: number;
|
|
4
|
+
credential_id: string;
|
|
5
|
+
public_key: string;
|
|
6
|
+
algorithm: number;
|
|
7
|
+
sign_count: number;
|
|
8
|
+
transports: string | null;
|
|
9
|
+
label: string | null;
|
|
10
|
+
backed_up: number;
|
|
11
|
+
last_used_at: string | null;
|
|
12
|
+
created_at: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const Credential: {
|
|
15
|
+
forUser(userId: number): Promise<CredentialRecord[]>;
|
|
16
|
+
findByCredentialId(credentialId: string): Promise<CredentialRecord | undefined>;
|
|
17
|
+
create(data: Record<string, unknown>): Promise<CredentialRecord | undefined>;
|
|
18
|
+
recordUse(id: number, signCount: number): Promise<void>;
|
|
19
|
+
delete(userId: number, id: number): Promise<boolean>;
|
|
20
|
+
countForUser(userId: number): Promise<number>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
2
|
+
export const Credential = {
|
|
3
|
+
async forUser(userId) {
|
|
4
|
+
const db = await getDb();
|
|
5
|
+
return db.all('SELECT * FROM user_credentials WHERE user_id = ? ORDER BY created_at', [userId]);
|
|
6
|
+
},
|
|
7
|
+
async findByCredentialId(credentialId) {
|
|
8
|
+
const db = await getDb();
|
|
9
|
+
return db.get('SELECT * FROM user_credentials WHERE credential_id = ?', [credentialId]);
|
|
10
|
+
},
|
|
11
|
+
async create(data) {
|
|
12
|
+
const credentials = await query('user_credentials');
|
|
13
|
+
await credentials.insert(data);
|
|
14
|
+
return this.findByCredentialId(data.credential_id);
|
|
15
|
+
},
|
|
16
|
+
async recordUse(id, signCount) {
|
|
17
|
+
const db = await getDb();
|
|
18
|
+
await db.run('UPDATE user_credentials SET sign_count = ?, last_used_at = ? WHERE id = ?', [signCount, new Date().toISOString(), id]);
|
|
19
|
+
},
|
|
20
|
+
async delete(userId, id) {
|
|
21
|
+
const db = await getDb();
|
|
22
|
+
// Scoped by user so one account cannot remove another's passkey.
|
|
23
|
+
const result = await db.run('DELETE FROM user_credentials WHERE id = ? AND user_id = ?', [id, userId]);
|
|
24
|
+
return (result.changes ?? 0) > 0;
|
|
25
|
+
},
|
|
26
|
+
async countForUser(userId) {
|
|
27
|
+
const db = await getDb();
|
|
28
|
+
const row = await db.get('SELECT COUNT(*) as count FROM user_credentials WHERE user_id = ?', [userId]);
|
|
29
|
+
return Number(row?.count ?? 0);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Media as MediaType } from '../types/index.ts';
|
|
2
|
+
interface CreateMediaData {
|
|
3
|
+
user_id?: number;
|
|
4
|
+
filename: string;
|
|
5
|
+
original_name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
mime_type?: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
alt_text?: string;
|
|
10
|
+
width?: number | null;
|
|
11
|
+
height?: number | null;
|
|
12
|
+
}
|
|
13
|
+
interface UpdateMediaData {
|
|
14
|
+
alt_text?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const Media: {
|
|
17
|
+
/**
|
|
18
|
+
* A page of media, optionally filtered.
|
|
19
|
+
*
|
|
20
|
+
* Search and type are applied in SQL rather than by the caller because the
|
|
21
|
+
* result is paginated: filtering the twenty rows a page happens to hold would
|
|
22
|
+
* search the current page instead of the library.
|
|
23
|
+
*
|
|
24
|
+
* @param page - 1-based
|
|
25
|
+
* @param perPage
|
|
26
|
+
* @param filters - `search` matches the original filename; `type` is a mime
|
|
27
|
+
* prefix such as 'image', or 'other' for anything that is not image, video
|
|
28
|
+
* or audio.
|
|
29
|
+
*/
|
|
30
|
+
all(page?: number, perPage?: number, filters?: {
|
|
31
|
+
search?: string;
|
|
32
|
+
type?: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
items: MediaType[];
|
|
35
|
+
total: number;
|
|
36
|
+
}>;
|
|
37
|
+
find(id: number): Promise<MediaType | undefined>;
|
|
38
|
+
findByFilename(filename: string): Promise<MediaType | undefined>;
|
|
39
|
+
findByUser(userId: number): Promise<MediaType[]>;
|
|
40
|
+
findByMimeType(mimeType: string): Promise<MediaType[]>;
|
|
41
|
+
create(data: CreateMediaData): Promise<MediaType>;
|
|
42
|
+
update(id: number, data: UpdateMediaData): Promise<MediaType>;
|
|
43
|
+
delete(id: number): Promise<MediaType | undefined>;
|
|
44
|
+
getTotalSize(): Promise<number>;
|
|
45
|
+
getStats(): Promise<{
|
|
46
|
+
total: number;
|
|
47
|
+
images: number;
|
|
48
|
+
documents: number;
|
|
49
|
+
other: number;
|
|
50
|
+
totalSize: number;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
export {};
|