@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,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Members, members-only posts and newsletters, as a feature.
|
|
3
|
+
*
|
|
4
|
+
* Remove this folder and its lines in src/features.ts, src/client/features.ts
|
|
5
|
+
* and src/features.manifest.ts, and the core runs without it. Its tables
|
|
6
|
+
* (migrations 033–035) and the `visibility` and `send_newsletter` columns stay,
|
|
7
|
+
* and core keeps withholding any post saved as `members` or `paid`: with no
|
|
8
|
+
* access policy, nothing but `public` is readable. How it all works:
|
|
9
|
+
* README.md.
|
|
10
|
+
*/
|
|
11
|
+
import './request.ts';
|
|
12
|
+
import type { Feature } from '../../host/index.ts';
|
|
13
|
+
import type { Request } from '../../types/index.ts';
|
|
14
|
+
/** The levels this feature offers. `paid` is enforced as `members` until paid tiers exist (migration 034). */
|
|
15
|
+
export declare const MEMBER_LEVELS: string[];
|
|
16
|
+
/**
|
|
17
|
+
* The editor's newsletter checkbox, saved through core's own save.
|
|
18
|
+
*
|
|
19
|
+
* Core does not know the field; it reaches the post through the
|
|
20
|
+
* `post.creating` / `post.updating` filters, which run inside core's save, so
|
|
21
|
+
* a post that has never been saved can ask for a send in the same request
|
|
22
|
+
* that creates it. Asking is an editor's call (`newsletterRefusal`); anyone
|
|
23
|
+
* else is refused with a 403, the status this check always had.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withNewsletterRequest(value: Record<string, unknown> | null | undefined, context: {
|
|
26
|
+
req?: Request;
|
|
27
|
+
post?: {
|
|
28
|
+
send_newsletter?: unknown;
|
|
29
|
+
} | null;
|
|
30
|
+
}): Record<string, unknown> | null | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* A provider reporting a subscription change made on its side (an
|
|
33
|
+
* unsubscribe link in its mail, a bounce). Its status wins for newsletters,
|
|
34
|
+
* so the member follows. Unknown people are ignored: the provider may have
|
|
35
|
+
* contacts who never became members here.
|
|
36
|
+
*/
|
|
37
|
+
export declare function applySubscription(payload: {
|
|
38
|
+
memberId?: unknown;
|
|
39
|
+
email?: unknown;
|
|
40
|
+
subscribed?: unknown;
|
|
41
|
+
provider?: unknown;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
declare const members: Feature;
|
|
44
|
+
export default members;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Members, members-only posts and newsletters, as a feature.
|
|
3
|
+
*
|
|
4
|
+
* Remove this folder and its lines in src/features.ts, src/client/features.ts
|
|
5
|
+
* and src/features.manifest.ts, and the core runs without it. Its tables
|
|
6
|
+
* (migrations 033–035) and the `visibility` and `send_newsletter` columns stay,
|
|
7
|
+
* and core keeps withholding any post saved as `members` or `paid`: with no
|
|
8
|
+
* access policy, nothing but `public` is readable. How it all works:
|
|
9
|
+
* README.md.
|
|
10
|
+
*/
|
|
11
|
+
import "./request.js";
|
|
12
|
+
import { HOOKS } from '@basicbenframework/core/hooks';
|
|
13
|
+
import { MEMBER_SETTINGS } from "./settings.js";
|
|
14
|
+
import { memberRoutes } from "./routes.js";
|
|
15
|
+
import { memberFromRequest } from "./middleware.js";
|
|
16
|
+
import { Member } from "./Member.js";
|
|
17
|
+
import { queueNewsletterFor, processNewsletterQueue, kickNewsletterQueue, newsletterRefusal } from "./newsletter.js";
|
|
18
|
+
import { pruneMagicLinks, normalizeEmail } from "./session.js";
|
|
19
|
+
import { NEWSLETTER_HOOKS } from "./events.js";
|
|
20
|
+
/** The levels this feature offers. `paid` is enforced as `members` until paid tiers exist (migration 034). */
|
|
21
|
+
export const MEMBER_LEVELS = ['members', 'paid'];
|
|
22
|
+
/**
|
|
23
|
+
* The editor's newsletter checkbox, saved through core's own save.
|
|
24
|
+
*
|
|
25
|
+
* Core does not know the field; it reaches the post through the
|
|
26
|
+
* `post.creating` / `post.updating` filters, which run inside core's save, so
|
|
27
|
+
* a post that has never been saved can ask for a send in the same request
|
|
28
|
+
* that creates it. Asking is an editor's call (`newsletterRefusal`); anyone
|
|
29
|
+
* else is refused with a 403, the status this check always had.
|
|
30
|
+
*/
|
|
31
|
+
export function withNewsletterRequest(value, context) {
|
|
32
|
+
const body = (context?.req?.body ?? {});
|
|
33
|
+
if (!value || value.cancel || !('send_newsletter' in body))
|
|
34
|
+
return value;
|
|
35
|
+
const values = { send_newsletter: body.send_newsletter ? 1 : 0 };
|
|
36
|
+
const refusal = newsletterRefusal(context.req, values, context.post ?? null);
|
|
37
|
+
if (refusal)
|
|
38
|
+
return { ...value, cancel: true, reason: refusal, status: 403 };
|
|
39
|
+
return { ...value, ...values };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A provider reporting a subscription change made on its side (an
|
|
43
|
+
* unsubscribe link in its mail, a bounce). Its status wins for newsletters,
|
|
44
|
+
* so the member follows. Unknown people are ignored: the provider may have
|
|
45
|
+
* contacts who never became members here.
|
|
46
|
+
*/
|
|
47
|
+
export async function applySubscription(payload) {
|
|
48
|
+
const provider = String(payload?.provider || 'provider').slice(0, 50);
|
|
49
|
+
const id = Number(payload?.memberId);
|
|
50
|
+
let member = Number.isInteger(id) && id > 0 ? await Member.find(id) : undefined;
|
|
51
|
+
if (!member && typeof payload?.email === 'string')
|
|
52
|
+
member = await Member.findByEmail(normalizeEmail(payload.email));
|
|
53
|
+
if (!member)
|
|
54
|
+
return;
|
|
55
|
+
const status = payload.subscribed ? 'active' : 'unsubscribed';
|
|
56
|
+
if (member.status !== status)
|
|
57
|
+
await Member.update(member.id, { status }, { origin: provider });
|
|
58
|
+
}
|
|
59
|
+
const members = {
|
|
60
|
+
name: 'members',
|
|
61
|
+
register(host) {
|
|
62
|
+
host.settings.define(MEMBER_SETTINGS);
|
|
63
|
+
host.routes(memberRoutes);
|
|
64
|
+
// Who may read a members-only post: anyone with a member session. The
|
|
65
|
+
// session comes from X-Member-Token (or a bearer header that verifies as
|
|
66
|
+
// one), and is checked against the member's row on every request.
|
|
67
|
+
host.access.policy({
|
|
68
|
+
levels: MEMBER_LEVELS,
|
|
69
|
+
headers: ['X-Member-Token'],
|
|
70
|
+
async identify(req) {
|
|
71
|
+
const member = await memberFromRequest(req);
|
|
72
|
+
if (member)
|
|
73
|
+
await Member.touch(member).catch(() => { });
|
|
74
|
+
return member;
|
|
75
|
+
},
|
|
76
|
+
mayRead: (post, member) => Boolean(member) && MEMBER_LEVELS.includes(String(post.visibility))
|
|
77
|
+
});
|
|
78
|
+
host.hooks.on(NEWSLETTER_HOOKS.SUBSCRIPTION, applySubscription, { name: 'members:subscription' });
|
|
79
|
+
host.hooks.on(HOOKS.POST_CREATING, withNewsletterRequest, { name: 'members:newsletter-request' });
|
|
80
|
+
host.hooks.on(HOOKS.POST_UPDATING, withNewsletterRequest, { name: 'members:newsletter-request' });
|
|
81
|
+
// Email a post to members when it goes live, if its author asked. Both
|
|
82
|
+
// events, because a post can go live through either: created already
|
|
83
|
+
// published, or updated into it — by the editor, a bulk action, or the
|
|
84
|
+
// publish-due task announcing a scheduled post whose time came. The
|
|
85
|
+
// listener only *queues*; `queueNewsletterFor` checks the post is live,
|
|
86
|
+
// asked for a send and has none yet, so firing it on every save is
|
|
87
|
+
// harmless.
|
|
88
|
+
for (const event of [HOOKS.POST_CREATED, HOOKS.POST_UPDATED]) {
|
|
89
|
+
host.hooks.on(event, async (payload) => {
|
|
90
|
+
const id = Number(payload?.post?.id);
|
|
91
|
+
if (!Number.isInteger(id))
|
|
92
|
+
return;
|
|
93
|
+
const send = await queueNewsletterFor(id);
|
|
94
|
+
// Start sending now rather than at the next tick. In the
|
|
95
|
+
// background: the editor's save should not wait on a mail provider.
|
|
96
|
+
if (send && send.status !== 'sent')
|
|
97
|
+
kickNewsletterQueue(25);
|
|
98
|
+
}, { name: `members:newsletter:${event}` });
|
|
99
|
+
}
|
|
100
|
+
// The queue is resumable, so a batch a minute finishes any send the kick
|
|
101
|
+
// above started, and picks up one a serverless function was frozen in.
|
|
102
|
+
host.cron.task('newsletters', 60, () => processNewsletterQueue(100));
|
|
103
|
+
host.cron.task('prune-magic-links', 3600, () => pruneMagicLinks());
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
export default members;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static facts about the members feature, for code that cannot boot the
|
|
3
|
+
* server: the export and backup scripts, and the admin menu. Imports nothing,
|
|
4
|
+
* so plain Node can load it (see src/helpers/export-data.ts for why).
|
|
5
|
+
*/
|
|
6
|
+
import type { FeatureManifest } from '../../host/manifest.ts';
|
|
7
|
+
declare const manifest: FeatureManifest;
|
|
8
|
+
export default manifest;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const manifest = {
|
|
2
|
+
name: 'members',
|
|
3
|
+
pages: [
|
|
4
|
+
{
|
|
5
|
+
path: '/admin/members',
|
|
6
|
+
label: 'Members',
|
|
7
|
+
section: 'Site',
|
|
8
|
+
// Gated: only someone who can manage accounts is shown the way to them.
|
|
9
|
+
// The routes behind it refuse everyone else regardless.
|
|
10
|
+
capability: 'user.manage',
|
|
11
|
+
icon: '✉️',
|
|
12
|
+
iconPath: 'M5 5h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM3 7l9 6 9-6'
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
// Magic-link hashes are credentials for an hour; never in a file.
|
|
16
|
+
neverExported: ['member_tokens']
|
|
17
|
+
};
|
|
18
|
+
export default manifest;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Member sessions on a request.
|
|
3
|
+
*
|
|
4
|
+
* Readers signed in with a magic link carry a member session (see
|
|
5
|
+
* session.ts). It is never an admin credential and nothing here
|
|
6
|
+
* sets `req.user` or `req.userId` — those belong to `auth`, and a route that
|
|
7
|
+
* checks them cannot be satisfied by a member whatever this file does.
|
|
8
|
+
*
|
|
9
|
+
* Where the token is read from:
|
|
10
|
+
*
|
|
11
|
+
* - `X-Member-Token: <token>` — always. This is the header for content reads,
|
|
12
|
+
* where `Authorization` already carries the site's own `content:read` token.
|
|
13
|
+
* - `Authorization: Bearer <token>` — as well, but only when it verifies as a
|
|
14
|
+
* member session. That lets a browser call the member endpoints with the
|
|
15
|
+
* usual bearer header; an admin JWT or an API token there is simply not a
|
|
16
|
+
* member token and is ignored by this file.
|
|
17
|
+
*
|
|
18
|
+
* No cookies, deliberately: front ends are on other origins, and a bearer
|
|
19
|
+
* header carries no ambient authority a cross-site request could borrow.
|
|
20
|
+
*
|
|
21
|
+
* Named exports only — a default export in src/middleware is applied to every
|
|
22
|
+
* route by the framework's autoloader. Relative imports carry `.ts` for the
|
|
23
|
+
* same autoloader, which uses Node's own `import()`.
|
|
24
|
+
*/
|
|
25
|
+
import { type MemberRow } from './Member.ts';
|
|
26
|
+
import type { Request, Response } from '../../types/index.ts';
|
|
27
|
+
type Next = () => void;
|
|
28
|
+
/** The member token on a request, if it carries one. Unverified. */
|
|
29
|
+
export declare function memberToken(req: Request): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* The member a token belongs to, as their row stands now. Null otherwise.
|
|
32
|
+
*
|
|
33
|
+
* The row is read on every use, for the reason `auth` reads the account row:
|
|
34
|
+
* a deleted member, or one who signed out everywhere, stops working on the
|
|
35
|
+
* next request rather than when the token happens to expire.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveMember(token: string | null): Promise<MemberRow | null>;
|
|
38
|
+
/** The member behind a request, or null. For controllers outside a member route. */
|
|
39
|
+
export declare function memberFromRequest(req: Request): Promise<MemberRow | null>;
|
|
40
|
+
/** Require a member session. */
|
|
41
|
+
export declare const requireMember: (req: Request, res: Response, next: Next) => Promise<void>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Member sessions on a request.
|
|
3
|
+
*
|
|
4
|
+
* Readers signed in with a magic link carry a member session (see
|
|
5
|
+
* session.ts). It is never an admin credential and nothing here
|
|
6
|
+
* sets `req.user` or `req.userId` — those belong to `auth`, and a route that
|
|
7
|
+
* checks them cannot be satisfied by a member whatever this file does.
|
|
8
|
+
*
|
|
9
|
+
* Where the token is read from:
|
|
10
|
+
*
|
|
11
|
+
* - `X-Member-Token: <token>` — always. This is the header for content reads,
|
|
12
|
+
* where `Authorization` already carries the site's own `content:read` token.
|
|
13
|
+
* - `Authorization: Bearer <token>` — as well, but only when it verifies as a
|
|
14
|
+
* member session. That lets a browser call the member endpoints with the
|
|
15
|
+
* usual bearer header; an admin JWT or an API token there is simply not a
|
|
16
|
+
* member token and is ignored by this file.
|
|
17
|
+
*
|
|
18
|
+
* No cookies, deliberately: front ends are on other origins, and a bearer
|
|
19
|
+
* header carries no ambient authority a cross-site request could borrow.
|
|
20
|
+
*
|
|
21
|
+
* Named exports only — a default export in src/middleware is applied to every
|
|
22
|
+
* route by the framework's autoloader. Relative imports carry `.ts` for the
|
|
23
|
+
* same autoloader, which uses Node's own `import()`.
|
|
24
|
+
*/
|
|
25
|
+
import { readMemberSession, MEMBER_HEADER } from "./session.js";
|
|
26
|
+
import { Member } from "./Member.js";
|
|
27
|
+
/** The member token on a request, if it carries one. Unverified. */
|
|
28
|
+
export function memberToken(req) {
|
|
29
|
+
const header = req.headers?.[MEMBER_HEADER];
|
|
30
|
+
if (typeof header === 'string' && header.trim())
|
|
31
|
+
return header.trim();
|
|
32
|
+
const authorization = req.headers?.authorization;
|
|
33
|
+
if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
|
|
34
|
+
const candidate = authorization.slice(7).trim();
|
|
35
|
+
// Only claimed if it really is one: the same header carries admin
|
|
36
|
+
// sessions and API tokens, which are not ours to refuse.
|
|
37
|
+
if (readMemberSession(candidate))
|
|
38
|
+
return candidate;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The member a token belongs to, as their row stands now. Null otherwise.
|
|
44
|
+
*
|
|
45
|
+
* The row is read on every use, for the reason `auth` reads the account row:
|
|
46
|
+
* a deleted member, or one who signed out everywhere, stops working on the
|
|
47
|
+
* next request rather than when the token happens to expire.
|
|
48
|
+
*/
|
|
49
|
+
export async function resolveMember(token) {
|
|
50
|
+
const claims = readMemberSession(token);
|
|
51
|
+
if (!claims)
|
|
52
|
+
return null;
|
|
53
|
+
const member = await Member.find(claims.mid);
|
|
54
|
+
if (!member || Number(member.session_version ?? 0) !== claims.sv)
|
|
55
|
+
return null;
|
|
56
|
+
return member;
|
|
57
|
+
}
|
|
58
|
+
/** The member behind a request, or null. For controllers outside a member route. */
|
|
59
|
+
export async function memberFromRequest(req) {
|
|
60
|
+
if (req.member !== undefined)
|
|
61
|
+
return req.member ?? null;
|
|
62
|
+
const member = await resolveMember(memberToken(req));
|
|
63
|
+
req.member = member;
|
|
64
|
+
return member;
|
|
65
|
+
}
|
|
66
|
+
/** Require a member session. */
|
|
67
|
+
export const requireMember = async (req, res, next) => {
|
|
68
|
+
const member = await memberFromRequest(req);
|
|
69
|
+
if (!member) {
|
|
70
|
+
return res.json({ error: 'Not signed in', hint: 'Send the member session as "X-Member-Token: <token>".' }, 401);
|
|
71
|
+
}
|
|
72
|
+
await Member.touch(member).catch(() => { });
|
|
73
|
+
next();
|
|
74
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Newsletters: emailing a post to the members subscribed to them.
|
|
3
|
+
*
|
|
4
|
+
* ## The lifecycle
|
|
5
|
+
*
|
|
6
|
+
* 1. An editor saves a post with "send as newsletter" ticked. That only sets
|
|
7
|
+
* `posts.send_newsletter` — a request.
|
|
8
|
+
* 2. When the post is *live* (published, not trashed, its time has come), the
|
|
9
|
+
* `post.created` / `post.updated` listener in src/hooks.ts calls
|
|
10
|
+
* `queueNewsletterFor`. A scheduled post is announced by the publish-due
|
|
11
|
+
* tick with `post.updated`, so it is mailed when it goes live, not when it
|
|
12
|
+
* was scheduled.
|
|
13
|
+
* 3. `queueNewsletterFor` creates the post's one `newsletter_sends` row — its
|
|
14
|
+
* `post_id` is unique, which is the "only once per post" guarantee — and
|
|
15
|
+
* copies every subscribed member into `newsletter_queue`.
|
|
16
|
+
* 4. `processNewsletterQueue(limit)` sends up to `limit` queued mails and
|
|
17
|
+
* returns. It is called from an interval on a long-running server, from
|
|
18
|
+
* `GET /api/cron/newsletters` for a platform scheduler, and opportunistically
|
|
19
|
+
* from the admin. Each call picks up where the last stopped, which is what
|
|
20
|
+
* makes this work on a serverless host with a ten-second function budget.
|
|
21
|
+
*
|
|
22
|
+
* ## Never twice
|
|
23
|
+
*
|
|
24
|
+
* A member gets a post at most once. The queue's UNIQUE (send_id, member_id)
|
|
25
|
+
* means enqueueing again adds nobody; a row is *claimed* with a conditional
|
|
26
|
+
* UPDATE before its mail goes, so two overlapping processors cannot both send
|
|
27
|
+
* it; and a row that was claimed but never finished — the function was frozen
|
|
28
|
+
* mid-send — is marked failed rather than retried, because nothing can tell
|
|
29
|
+
* whether its mail left before the process died. That is at-most-once, the
|
|
30
|
+
* same promise webhooks make. A provider error, by contrast, is a known
|
|
31
|
+
* non-delivery and is retried up to MAX_ATTEMPTS.
|
|
32
|
+
*/
|
|
33
|
+
import type { Request, Response } from '../../types/index.ts';
|
|
34
|
+
/** Tries per recipient before a provider error is final. */
|
|
35
|
+
export declare const MAX_ATTEMPTS = 3;
|
|
36
|
+
/** A claimed row older than this was interrupted, not slow. */
|
|
37
|
+
export declare const STALE_CLAIM_MS: number;
|
|
38
|
+
/** Mails per processor call when none is given. */
|
|
39
|
+
export declare const DEFAULT_BATCH = 50;
|
|
40
|
+
type Send = (message: Record<string, unknown>) => Promise<unknown>;
|
|
41
|
+
export interface NewsletterSendRow {
|
|
42
|
+
id: number;
|
|
43
|
+
post_id: number;
|
|
44
|
+
status: 'preparing' | 'sending' | 'sent' | 'handing_off' | 'handed_off' | 'handoff_failed';
|
|
45
|
+
subject: string | null;
|
|
46
|
+
provider?: string | null;
|
|
47
|
+
external_id?: string | null;
|
|
48
|
+
handoff_error?: string | null;
|
|
49
|
+
total_count: number;
|
|
50
|
+
sent_count: number;
|
|
51
|
+
failed_count: number;
|
|
52
|
+
skipped_count: number;
|
|
53
|
+
created_at: string;
|
|
54
|
+
started_at: string | null;
|
|
55
|
+
completed_at: string | null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* May this request ask for a post to be mailed to every member?
|
|
59
|
+
*
|
|
60
|
+
* Mailing the whole list is a bigger act than publishing one post, so it is
|
|
61
|
+
* `post.edit` held outright — editors and admins — as Ghost reserves sending
|
|
62
|
+
* for editors. An author can publish their own post; they cannot email it to
|
|
63
|
+
* everyone. Only *turning it on* is checked: re-saving a post whose flag is
|
|
64
|
+
* already set must not fail for the author who wrote it.
|
|
65
|
+
*
|
|
66
|
+
* Returns the refusal, or null.
|
|
67
|
+
*/
|
|
68
|
+
export declare function newsletterRefusal(req: Request, values: Record<string, unknown>, existing: {
|
|
69
|
+
send_newsletter?: unknown;
|
|
70
|
+
} | null): string | null;
|
|
71
|
+
/** The post's send, if it has one. */
|
|
72
|
+
export declare function newsletterFor(postId: number): Promise<NewsletterSendRow | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
* Queue a post's newsletter, if it asked for one, is live, and has none yet.
|
|
75
|
+
*
|
|
76
|
+
* Safe to call any number of times, from any number of places at once: the
|
|
77
|
+
* unique `post_id` lets exactly one send row exist, and `prepareSend` adds
|
|
78
|
+
* only recipients not already queued. Returns the send, or null when there is
|
|
79
|
+
* nothing to send.
|
|
80
|
+
*/
|
|
81
|
+
export declare function queueNewsletterFor(postId: number): Promise<NewsletterSendRow | null>;
|
|
82
|
+
/** Is a feature listening to take newsletters? */
|
|
83
|
+
export declare function hasProvider(): boolean;
|
|
84
|
+
/** A hand-off that failed is tried again after this long, and one claimed this long ago is taken as interrupted. */
|
|
85
|
+
export declare const HANDOFF_RETRY_MS: number;
|
|
86
|
+
/**
|
|
87
|
+
* Give a post's send to the provider listening on `newsletter.delivering`.
|
|
88
|
+
*
|
|
89
|
+
* The listener gets `{ send, post, message, handledBy: null, externalId: null }`
|
|
90
|
+
* — `message` is the newsletter as the built-in queue would send it, minus a
|
|
91
|
+
* recipient and minus the site's unsubscribe link, which a provider replaces
|
|
92
|
+
* with its own — and takes the send by returning it with `handledBy` (its
|
|
93
|
+
* name) and `externalId` set.
|
|
94
|
+
*
|
|
95
|
+
* - **Claimed first**, with a conditional UPDATE, so two callers cannot both
|
|
96
|
+
* hand a post off. A provider must still make its own call idempotent per
|
|
97
|
+
* `send.id`: a claim that was interrupted is retried after
|
|
98
|
+
* HANDOFF_RETRY_MS, and nothing can tell whether the provider heard it.
|
|
99
|
+
* - **Strict.** A listener that throws (or cancels) leaves the send
|
|
100
|
+
* `handoff_failed`, retried later. It never falls back to the built-in
|
|
101
|
+
* queue: a provider outage must not become a second sender.
|
|
102
|
+
* - **Declined:** if listeners return it untaken, the built-in queue sends it.
|
|
103
|
+
*/
|
|
104
|
+
export declare function handOffSend(sendId: number): Promise<void>;
|
|
105
|
+
interface PostForMail {
|
|
106
|
+
id: number;
|
|
107
|
+
title: string;
|
|
108
|
+
slug: string | null;
|
|
109
|
+
excerpt: string | null;
|
|
110
|
+
content_html: string | null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Make every link and image in a post's HTML absolute.
|
|
114
|
+
*
|
|
115
|
+
* A mail client has no page to resolve `/uploads/x.png` or `/blog/other`
|
|
116
|
+
* against. Images resolve against APP_URL — where local storage serves them —
|
|
117
|
+
* and links against the public site, the same split the content API uses.
|
|
118
|
+
* Only root-relative values are touched; `//host` and absolute URLs are left
|
|
119
|
+
* alone, and anything else the sanitizer already refused.
|
|
120
|
+
*/
|
|
121
|
+
export declare function absolutize(html: string, site?: string, app?: string): string;
|
|
122
|
+
/** The public URL of a post, as the feeds build it. */
|
|
123
|
+
export declare function postUrl(post: {
|
|
124
|
+
id: number;
|
|
125
|
+
slug: string | null;
|
|
126
|
+
}): string;
|
|
127
|
+
/**
|
|
128
|
+
* The message for one recipient.
|
|
129
|
+
*
|
|
130
|
+
* The body is sanitized again here even though `content_html` is already a
|
|
131
|
+
* sanitized render: it is about to be delivered outside the site, to mail
|
|
132
|
+
* clients with their own idea of what is safe, and a listener on
|
|
133
|
+
* `content.save` may have put something in the column the sanitizer would
|
|
134
|
+
* not. Sanitizing twice costs microseconds; trusting a cache is how a stored
|
|
135
|
+
* value becomes a mail-borne one.
|
|
136
|
+
*/
|
|
137
|
+
export declare function buildNewsletterMessage(post: PostForMail, recipient: {
|
|
138
|
+
email: string;
|
|
139
|
+
memberId: number | null;
|
|
140
|
+
}, { unsubscribe }?: {
|
|
141
|
+
unsubscribe?: boolean;
|
|
142
|
+
}): Promise<Record<string, unknown>>;
|
|
143
|
+
/**
|
|
144
|
+
* Send up to `limit` queued newsletter mails. Resumable; see the file header.
|
|
145
|
+
*
|
|
146
|
+
* `send` is the transport, injectable so a test can make delivery fail
|
|
147
|
+
* without a mail provider. Returns what it did.
|
|
148
|
+
*/
|
|
149
|
+
export declare function processNewsletterQueue(limit?: number, { send }?: {
|
|
150
|
+
send?: Send;
|
|
151
|
+
}): Promise<{
|
|
152
|
+
sent: number;
|
|
153
|
+
failed: number;
|
|
154
|
+
skipped: number;
|
|
155
|
+
retried: number;
|
|
156
|
+
}>;
|
|
157
|
+
/**
|
|
158
|
+
* Mail a post to one address as members will see it, without queueing.
|
|
159
|
+
*
|
|
160
|
+
* For "send a test to yourself". Works on drafts — previewing before
|
|
161
|
+
* publishing is the point — and never touches the queue or the send row.
|
|
162
|
+
*/
|
|
163
|
+
export declare function sendTestNewsletter(postId: number, to: string, send?: Send): Promise<boolean>;
|
|
164
|
+
/** Kick a small batch at most once a minute, without delaying the request. */
|
|
165
|
+
export declare function kickNewsletterQueue(limit?: number): void;
|
|
166
|
+
/** Middleware form of `kickNewsletterQueue`, for routes with traffic. */
|
|
167
|
+
export declare function newslettersOpportunistically(_req: Request, _res: Response, next: () => void): void;
|
|
168
|
+
/**
|
|
169
|
+
* `GET /api/cron/newsletters`, for a platform scheduler.
|
|
170
|
+
*
|
|
171
|
+
* The same rule as `/api/cron/publish-due`: `Authorization: Bearer
|
|
172
|
+
* $CRON_SECRET`, and with no secret configured the endpoint does not exist.
|
|
173
|
+
* `?limit=` sizes the batch (default 100, at most 500) so a host with a short
|
|
174
|
+
* function timeout can ask for less.
|
|
175
|
+
*/
|
|
176
|
+
export declare function newslettersCronEndpoint(req: Request, res: Response): Promise<void>;
|
|
177
|
+
export {};
|