@basicbenframework/cms 0.0.0-stage → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +206 -2
- package/db/migrations/001_create_users.js +15 -0
- package/db/migrations/002_create_posts.js +18 -0
- package/db/migrations/003_create_categories.js +19 -0
- package/db/migrations/004_create_tags.js +16 -0
- package/db/migrations/005_create_post_tags.js +16 -0
- package/db/migrations/006_create_pages.js +26 -0
- package/db/migrations/007_create_comments.js +24 -0
- package/db/migrations/008_create_media.js +22 -0
- package/db/migrations/009_update_posts_blogging.js +27 -0
- package/db/migrations/010_create_settings.js +29 -0
- package/db/migrations/011_add_user_roles.js +23 -0
- package/db/migrations/012_create_auth_tokens.js +30 -0
- package/db/migrations/013_add_email_verified.js +24 -0
- package/db/migrations/014_create_user_two_factor.js +30 -0
- package/db/migrations/015_create_user_credentials.js +35 -0
- package/db/migrations/016_create_rate_limits.js +31 -0
- package/db/migrations/017_add_content_html.js +38 -0
- package/db/migrations/018_create_api_tokens.js +34 -0
- package/db/migrations/019_create_post_categories.js +40 -0
- package/db/migrations/020_add_author_profiles.js +60 -0
- package/db/migrations/021_add_page_featured_image.js +23 -0
- package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
- package/db/migrations/023_add_user_session_controls.js +25 -0
- package/db/migrations/024_add_post_status_and_trash.js +45 -0
- package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
- package/db/migrations/026_create_post_revisions.js +29 -0
- package/db/migrations/027_add_media_dimensions.js +19 -0
- package/db/migrations/028_create_navigation_menus.js +65 -0
- package/db/migrations/029_create_redirects.js +40 -0
- package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
- package/db/migrations/031_create_post_locks.js +38 -0
- package/db/migrations/032_create_snippets.js +31 -0
- package/db/migrations/033_create_members.js +70 -0
- package/db/migrations/034_add_post_visibility.js +28 -0
- package/db/migrations/035_create_newsletters.js +72 -0
- package/db/migrations/036_create_analytics.js +89 -0
- package/db/migrations/037_create_ops_heartbeats.js +30 -0
- package/db/migrations/038_create_content_types.js +84 -0
- package/db/migrations/039_create_content_type_fields.js +47 -0
- package/db/migrations/040_create_taxonomies.js +80 -0
- package/db/migrations/041_add_newsletter_handoff.js +28 -0
- package/db/migrations/042_create_mysendbox_contacts.js +63 -0
- package/lib/cli/backup.d.mts +2 -0
- package/lib/cli/backup.mjs +124 -0
- package/lib/cli/export.d.mts +2 -0
- package/lib/cli/export.mjs +54 -0
- package/lib/cli/import-ghost.d.mts +2 -0
- package/lib/cli/import-ghost.mjs +50 -0
- package/lib/cli/import-json.d.mts +2 -0
- package/lib/cli/import-json.mjs +61 -0
- package/lib/cli/import-wordpress.d.mts +2 -0
- package/lib/cli/import-wordpress.mjs +169 -0
- package/lib/cli/import-wxr.d.mts +2 -0
- package/lib/cli/import-wxr.mjs +55 -0
- package/lib/cli/index.d.mts +2 -0
- package/lib/cli/index.mjs +53 -0
- package/lib/cli/lib/backup.d.mts +112 -0
- package/lib/cli/lib/backup.mjs +297 -0
- package/lib/cli/lib/ghost.d.mts +30 -0
- package/lib/cli/lib/ghost.mjs +201 -0
- package/lib/cli/lib/html-to-markdown.d.mts +61 -0
- package/lib/cli/lib/html-to-markdown.mjs +523 -0
- package/lib/cli/lib/import-common.d.mts +100 -0
- package/lib/cli/lib/import-common.mjs +252 -0
- package/lib/cli/lib/json-import.d.mts +22 -0
- package/lib/cli/lib/json-import.mjs +422 -0
- package/lib/cli/lib/site-import.d.mts +32 -0
- package/lib/cli/lib/site-import.mjs +456 -0
- package/lib/cli/lib/wordpress-rest.d.mts +25 -0
- package/lib/cli/lib/wordpress-rest.mjs +177 -0
- package/lib/cli/lib/wxr.d.mts +18 -0
- package/lib/cli/lib/wxr.mjs +307 -0
- package/lib/cli/lib/xml.d.mts +33 -0
- package/lib/cli/lib/xml.mjs +186 -0
- package/lib/cli/restore.d.mts +2 -0
- package/lib/cli/restore.mjs +98 -0
- package/lib/client/components/Alert.d.ts +7 -0
- package/lib/client/components/Alert.js +8 -0
- package/lib/client/components/Avatar.d.ts +15 -0
- package/lib/client/components/Avatar.js +10 -0
- package/lib/client/components/BackLink.d.ts +7 -0
- package/lib/client/components/BackLink.js +6 -0
- package/lib/client/components/Button.d.ts +7 -0
- package/lib/client/components/Button.js +12 -0
- package/lib/client/components/Card.d.ts +7 -0
- package/lib/client/components/Card.js +6 -0
- package/lib/client/components/CommentThread.d.ts +15 -0
- package/lib/client/components/CommentThread.js +101 -0
- package/lib/client/components/Empty.d.ts +6 -0
- package/lib/client/components/Empty.js +6 -0
- package/lib/client/components/Input.d.ts +6 -0
- package/lib/client/components/Input.js +6 -0
- package/lib/client/components/Link.d.ts +31 -0
- package/lib/client/components/Link.js +49 -0
- package/lib/client/components/Loading.d.ts +1 -0
- package/lib/client/components/Loading.js +6 -0
- package/lib/client/components/Logo.d.ts +5 -0
- package/lib/client/components/Logo.js +4 -0
- package/lib/client/components/MarkdownEditor.d.ts +41 -0
- package/lib/client/components/MarkdownEditor.js +156 -0
- package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
- package/lib/client/components/Nav/DarkModeToggle.js +6 -0
- package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
- package/lib/client/components/Nav/DesktopNav.js +9 -0
- package/lib/client/components/Nav/MobileNav.d.ts +9 -0
- package/lib/client/components/Nav/MobileNav.js +15 -0
- package/lib/client/components/NavLink.d.ts +8 -0
- package/lib/client/components/NavLink.js +6 -0
- package/lib/client/components/PageHeader.d.ts +8 -0
- package/lib/client/components/PageHeader.js +6 -0
- package/lib/client/components/PostCard.d.ts +8 -0
- package/lib/client/components/PostCard.js +7 -0
- package/lib/client/components/Textarea.d.ts +6 -0
- package/lib/client/components/Textarea.js +6 -0
- package/lib/client/components/ThemeContext.d.ts +18 -0
- package/lib/client/components/ThemeContext.js +8 -0
- package/lib/client/components/admin/AdminIcons.d.ts +13 -0
- package/lib/client/components/admin/AdminIcons.js +66 -0
- package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
- package/lib/client/components/admin/ContentModelPanels.js +93 -0
- package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
- package/lib/client/components/admin/FeaturedImageBox.js +24 -0
- package/lib/client/components/admin/MediaGrid.d.ts +23 -0
- package/lib/client/components/admin/MediaGrid.js +69 -0
- package/lib/client/components/admin/MediaPicker.d.ts +17 -0
- package/lib/client/components/admin/MediaPicker.js +61 -0
- package/lib/client/components/admin/Pagination.d.ts +27 -0
- package/lib/client/components/admin/Pagination.js +29 -0
- package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
- package/lib/client/components/admin/SnippetPicker.js +65 -0
- package/lib/client/components/admin/TermPicker.d.ts +52 -0
- package/lib/client/components/admin/TermPicker.js +58 -0
- package/lib/client/contexts/ToastContext.d.ts +12 -0
- package/lib/client/contexts/ToastContext.js +49 -0
- package/lib/client/features.d.ts +11 -0
- package/lib/client/features.js +7 -0
- package/lib/client/hooks/useContentTypes.d.ts +48 -0
- package/lib/client/hooks/useContentTypes.js +48 -0
- package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
- package/lib/client/hooks/useMediaLibrary.js +189 -0
- package/lib/client/hooks/usePostLock.d.ts +32 -0
- package/lib/client/hooks/usePostLock.js +107 -0
- package/lib/client/host/index.d.ts +71 -0
- package/lib/client/host/index.js +58 -0
- package/lib/client/i18n/index.d.ts +79 -0
- package/lib/client/i18n/index.js +177 -0
- package/lib/client/i18n/locales/es/content.d.ts +4 -0
- package/lib/client/i18n/locales/es/content.js +220 -0
- package/lib/client/i18n/locales/es/editor.d.ts +9 -0
- package/lib/client/i18n/locales/es/editor.js +144 -0
- package/lib/client/i18n/locales/es/index.d.ts +8 -0
- package/lib/client/i18n/locales/es/index.js +7 -0
- package/lib/client/i18n/locales/es/layout.d.ts +4 -0
- package/lib/client/i18n/locales/es/layout.js +35 -0
- package/lib/client/i18n/locales/es/people.d.ts +4 -0
- package/lib/client/i18n/locales/es/people.js +187 -0
- package/lib/client/i18n/locales/es/site.d.ts +4 -0
- package/lib/client/i18n/locales/es/site.js +208 -0
- package/lib/client/layouts/AdminLayout.d.ts +7 -0
- package/lib/client/layouts/AdminLayout.js +1046 -0
- package/lib/client/layouts/AppLayout.d.ts +6 -0
- package/lib/client/layouts/AppLayout.js +19 -0
- package/lib/client/layouts/AuthLayout.d.ts +6 -0
- package/lib/client/layouts/AuthLayout.js +14 -0
- package/lib/client/layouts/DocsLayout.d.ts +6 -0
- package/lib/client/layouts/DocsLayout.js +28 -0
- package/lib/client/layouts/RootLayout.d.ts +6 -0
- package/lib/client/layouts/RootLayout.js +11 -0
- package/lib/client/pages/AcceptInvite.d.ts +8 -0
- package/lib/client/pages/AcceptInvite.js +60 -0
- package/lib/client/pages/Auth.d.ts +1 -0
- package/lib/client/pages/Auth.js +40 -0
- package/lib/client/pages/Authentication.d.ts +1 -0
- package/lib/client/pages/Authentication.js +230 -0
- package/lib/client/pages/Content.d.ts +1 -0
- package/lib/client/pages/Content.js +21 -0
- package/lib/client/pages/Database.d.ts +1 -0
- package/lib/client/pages/Database.js +264 -0
- package/lib/client/pages/Extending.d.ts +1 -0
- package/lib/client/pages/Extending.js +28 -0
- package/lib/client/pages/Feed.d.ts +1 -0
- package/lib/client/pages/Feed.js +19 -0
- package/lib/client/pages/FeedPost.d.ts +1 -0
- package/lib/client/pages/FeedPost.js +31 -0
- package/lib/client/pages/ForgotPassword.d.ts +8 -0
- package/lib/client/pages/ForgotPassword.js +38 -0
- package/lib/client/pages/GettingStarted.d.ts +1 -0
- package/lib/client/pages/GettingStarted.js +84 -0
- package/lib/client/pages/Headless.d.ts +1 -0
- package/lib/client/pages/Headless.js +49 -0
- package/lib/client/pages/Home.d.ts +1 -0
- package/lib/client/pages/Home.js +67 -0
- package/lib/client/pages/PostForm.d.ts +1 -0
- package/lib/client/pages/PostForm.js +55 -0
- package/lib/client/pages/Posts.d.ts +1 -0
- package/lib/client/pages/Posts.js +35 -0
- package/lib/client/pages/Profile.d.ts +1 -0
- package/lib/client/pages/Profile.js +153 -0
- package/lib/client/pages/ResetPassword.d.ts +8 -0
- package/lib/client/pages/ResetPassword.js +52 -0
- package/lib/client/pages/Routing.d.ts +1 -0
- package/lib/client/pages/Routing.js +192 -0
- package/lib/client/pages/Storage.d.ts +1 -0
- package/lib/client/pages/Storage.js +54 -0
- package/lib/client/pages/Testing.d.ts +1 -0
- package/lib/client/pages/Testing.js +141 -0
- package/lib/client/pages/Validation.d.ts +1 -0
- package/lib/client/pages/Validation.js +123 -0
- package/lib/client/pages/admin/Categories.d.ts +2 -0
- package/lib/client/pages/admin/Categories.js +75 -0
- package/lib/client/pages/admin/Comments.d.ts +11 -0
- package/lib/client/pages/admin/Comments.js +247 -0
- package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
- package/lib/client/pages/admin/ContentTypes.js +163 -0
- package/lib/client/pages/admin/Dashboard.d.ts +2 -0
- package/lib/client/pages/admin/Dashboard.js +66 -0
- package/lib/client/pages/admin/Health.d.ts +12 -0
- package/lib/client/pages/admin/Health.js +148 -0
- package/lib/client/pages/admin/Media.d.ts +2 -0
- package/lib/client/pages/admin/Media.js +101 -0
- package/lib/client/pages/admin/Navigation.d.ts +9 -0
- package/lib/client/pages/admin/Navigation.js +230 -0
- package/lib/client/pages/admin/Pages.d.ts +2 -0
- package/lib/client/pages/admin/Pages.js +53 -0
- package/lib/client/pages/admin/PostEditor.d.ts +17 -0
- package/lib/client/pages/admin/PostEditor.js +532 -0
- package/lib/client/pages/admin/Posts.d.ts +2 -0
- package/lib/client/pages/admin/Posts.js +152 -0
- package/lib/client/pages/admin/Redirects.d.ts +10 -0
- package/lib/client/pages/admin/Redirects.js +87 -0
- package/lib/client/pages/admin/Settings.d.ts +2 -0
- package/lib/client/pages/admin/Settings.js +111 -0
- package/lib/client/pages/admin/Snippets.d.ts +14 -0
- package/lib/client/pages/admin/Snippets.js +85 -0
- package/lib/client/pages/admin/Tags.d.ts +2 -0
- package/lib/client/pages/admin/Tags.js +74 -0
- package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
- package/lib/client/pages/admin/Taxonomies.js +130 -0
- package/lib/client/pages/admin/Tokens.d.ts +9 -0
- package/lib/client/pages/admin/Tokens.js +260 -0
- package/lib/client/pages/admin/Tools.d.ts +12 -0
- package/lib/client/pages/admin/Tools.js +111 -0
- package/lib/client/pages/admin/Users.d.ts +13 -0
- package/lib/client/pages/admin/Users.js +313 -0
- package/lib/client/pages/api-reference.d.ts +33 -0
- package/lib/client/pages/api-reference.js +198 -0
- package/lib/client/styles.css +37 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.js +39 -0
- package/lib/controllers/AdminController.d.ts +46 -0
- package/lib/controllers/AdminController.js +134 -0
- package/lib/controllers/AuthController.d.ts +15 -0
- package/lib/controllers/AuthController.js +194 -0
- package/lib/controllers/AuthorController.d.ts +17 -0
- package/lib/controllers/AuthorController.js +19 -0
- package/lib/controllers/CategoryController.d.ts +10 -0
- package/lib/controllers/CategoryController.js +88 -0
- package/lib/controllers/CommentController.d.ts +68 -0
- package/lib/controllers/CommentController.js +438 -0
- package/lib/controllers/ContentTypeController.d.ts +24 -0
- package/lib/controllers/ContentTypeController.js +91 -0
- package/lib/controllers/EmailVerificationController.d.ts +33 -0
- package/lib/controllers/EmailVerificationController.js +116 -0
- package/lib/controllers/ExportController.d.ts +15 -0
- package/lib/controllers/ExportController.js +41 -0
- package/lib/controllers/FeedController.d.ts +14 -0
- package/lib/controllers/FeedController.js +246 -0
- package/lib/controllers/HealthController.d.ts +21 -0
- package/lib/controllers/HealthController.js +176 -0
- package/lib/controllers/HomeController.d.ts +12 -0
- package/lib/controllers/HomeController.js +16 -0
- package/lib/controllers/MediaController.d.ts +24 -0
- package/lib/controllers/MediaController.js +189 -0
- package/lib/controllers/NavigationController.d.ts +22 -0
- package/lib/controllers/NavigationController.js +176 -0
- package/lib/controllers/PageController.d.ts +13 -0
- package/lib/controllers/PageController.js +172 -0
- package/lib/controllers/PasskeyController.d.ts +36 -0
- package/lib/controllers/PasskeyController.js +201 -0
- package/lib/controllers/PasswordResetController.d.ts +44 -0
- package/lib/controllers/PasswordResetController.js +160 -0
- package/lib/controllers/PostController.d.ts +51 -0
- package/lib/controllers/PostController.js +538 -0
- package/lib/controllers/PostLockController.d.ts +62 -0
- package/lib/controllers/PostLockController.js +101 -0
- package/lib/controllers/ProfileController.d.ts +13 -0
- package/lib/controllers/ProfileController.js +160 -0
- package/lib/controllers/PublicApiController.d.ts +23 -0
- package/lib/controllers/PublicApiController.js +100 -0
- package/lib/controllers/RedirectController.d.ts +32 -0
- package/lib/controllers/RedirectController.js +95 -0
- package/lib/controllers/SettingsController.d.ts +28 -0
- package/lib/controllers/SettingsController.js +105 -0
- package/lib/controllers/SnippetController.d.ts +27 -0
- package/lib/controllers/SnippetController.js +123 -0
- package/lib/controllers/TagController.d.ts +9 -0
- package/lib/controllers/TagController.js +70 -0
- package/lib/controllers/TaxonomyController.d.ts +24 -0
- package/lib/controllers/TaxonomyController.js +149 -0
- package/lib/controllers/TokenController.d.ts +27 -0
- package/lib/controllers/TokenController.js +83 -0
- package/lib/controllers/TwoFactorController.d.ts +31 -0
- package/lib/controllers/TwoFactorController.js +213 -0
- package/lib/controllers/UserController.d.ts +110 -0
- package/lib/controllers/UserController.js +504 -0
- package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
- package/lib/features/analytics/AnalyticsPage.js +123 -0
- package/lib/features/analytics/admin.d.ts +3 -0
- package/lib/features/analytics/admin.js +9 -0
- package/lib/features/analytics/controller.d.ts +19 -0
- package/lib/features/analytics/controller.js +79 -0
- package/lib/features/analytics/helpers.d.ts +84 -0
- package/lib/features/analytics/helpers.js +181 -0
- package/lib/features/analytics/i18n/es.d.ts +4 -0
- package/lib/features/analytics/i18n/es.js +31 -0
- package/lib/features/analytics/index.d.ts +28 -0
- package/lib/features/analytics/index.js +91 -0
- package/lib/features/analytics/manifest.d.ts +8 -0
- package/lib/features/analytics/manifest.js +18 -0
- package/lib/features/analytics/model.d.ts +130 -0
- package/lib/features/analytics/model.js +206 -0
- package/lib/features/members/Member.d.ts +93 -0
- package/lib/features/members/Member.js +194 -0
- package/lib/features/members/MemberAdminController.d.ts +60 -0
- package/lib/features/members/MemberAdminController.js +262 -0
- package/lib/features/members/MemberController.d.ts +88 -0
- package/lib/features/members/MemberController.js +250 -0
- package/lib/features/members/MembersPage.d.ts +10 -0
- package/lib/features/members/MembersPage.js +216 -0
- package/lib/features/members/PostAccessBox.d.ts +15 -0
- package/lib/features/members/PostAccessBox.js +70 -0
- package/lib/features/members/admin.d.ts +3 -0
- package/lib/features/members/admin.js +12 -0
- package/lib/features/members/csv.d.ts +21 -0
- package/lib/features/members/csv.js +74 -0
- package/lib/features/members/events.d.ts +34 -0
- package/lib/features/members/events.js +34 -0
- package/lib/features/members/i18n/es.d.ts +4 -0
- package/lib/features/members/i18n/es.js +106 -0
- package/lib/features/members/index.d.ts +44 -0
- package/lib/features/members/index.js +106 -0
- package/lib/features/members/manifest.d.ts +8 -0
- package/lib/features/members/manifest.js +18 -0
- package/lib/features/members/middleware.d.ts +42 -0
- package/lib/features/members/middleware.js +74 -0
- package/lib/features/members/newsletter.d.ts +177 -0
- package/lib/features/members/newsletter.js +439 -0
- package/lib/features/members/rate-limits.d.ts +34 -0
- package/lib/features/members/rate-limits.js +50 -0
- package/lib/features/members/request.d.ts +13 -0
- package/lib/features/members/request.js +6 -0
- package/lib/features/members/routes.d.ts +15 -0
- package/lib/features/members/routes.js +59 -0
- package/lib/features/members/session.d.ts +102 -0
- package/lib/features/members/session.js +158 -0
- package/lib/features/members/settings.d.ts +14 -0
- package/lib/features/members/settings.js +23 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
- package/lib/features/mysendbox/admin.d.ts +3 -0
- package/lib/features/mysendbox/admin.js +9 -0
- package/lib/features/mysendbox/broadcasts.d.ts +61 -0
- package/lib/features/mysendbox/broadcasts.js +124 -0
- package/lib/features/mysendbox/client.d.ts +95 -0
- package/lib/features/mysendbox/client.js +61 -0
- package/lib/features/mysendbox/config.d.ts +27 -0
- package/lib/features/mysendbox/config.js +74 -0
- package/lib/features/mysendbox/contacts.d.ts +121 -0
- package/lib/features/mysendbox/contacts.js +378 -0
- package/lib/features/mysendbox/controller.d.ts +11 -0
- package/lib/features/mysendbox/controller.js +47 -0
- package/lib/features/mysendbox/i18n/es.d.ts +4 -0
- package/lib/features/mysendbox/i18n/es.js +28 -0
- package/lib/features/mysendbox/index.d.ts +18 -0
- package/lib/features/mysendbox/index.js +71 -0
- package/lib/features/mysendbox/manifest.d.ts +7 -0
- package/lib/features/mysendbox/manifest.js +6 -0
- package/lib/features/mysendbox/routes.d.ts +6 -0
- package/lib/features/mysendbox/routes.js +14 -0
- package/lib/features/mysendbox/webhook.d.ts +23 -0
- package/lib/features/mysendbox/webhook.js +104 -0
- package/lib/features/theme/OEmbedController.d.ts +31 -0
- package/lib/features/theme/OEmbedController.js +128 -0
- package/lib/features/theme/ThemeController.d.ts +20 -0
- package/lib/features/theme/ThemeController.js +256 -0
- package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
- package/lib/features/theme/ThemeSettingsCard.js +12 -0
- package/lib/features/theme/admin.d.ts +3 -0
- package/lib/features/theme/admin.js +9 -0
- package/lib/features/theme/html.d.ts +48 -0
- package/lib/features/theme/html.js +97 -0
- package/lib/features/theme/i18n/es.d.ts +4 -0
- package/lib/features/theme/i18n/es.js +9 -0
- package/lib/features/theme/index.d.ts +11 -0
- package/lib/features/theme/index.js +23 -0
- package/lib/features/theme/manifest.d.ts +7 -0
- package/lib/features/theme/manifest.js +6 -0
- package/lib/features/theme/oembed.d.ts +36 -0
- package/lib/features/theme/oembed.js +58 -0
- package/lib/features/theme/routes.d.ts +17 -0
- package/lib/features/theme/routes.js +54 -0
- package/lib/features/theme/templates.d.ts +103 -0
- package/lib/features/theme/templates.js +283 -0
- package/lib/features.d.ts +15 -0
- package/lib/features.js +6 -0
- package/lib/features.manifest.d.ts +10 -0
- package/lib/features.manifest.js +6 -0
- package/lib/helpers/access.d.ts +62 -0
- package/lib/helpers/access.js +92 -0
- package/lib/helpers/api.d.ts +20 -0
- package/lib/helpers/api.js +44 -0
- package/lib/helpers/comment-guard.d.ts +145 -0
- package/lib/helpers/comment-guard.js +253 -0
- package/lib/helpers/comment-mail.d.ts +53 -0
- package/lib/helpers/comment-mail.js +188 -0
- package/lib/helpers/content-model.d.ts +50 -0
- package/lib/helpers/content-model.js +84 -0
- package/lib/helpers/content-paths.d.ts +107 -0
- package/lib/helpers/content-paths.js +200 -0
- package/lib/helpers/export-data.d.ts +85 -0
- package/lib/helpers/export-data.js +229 -0
- package/lib/helpers/gating.d.ts +53 -0
- package/lib/helpers/gating.js +83 -0
- package/lib/helpers/health.d.ts +91 -0
- package/lib/helpers/health.js +279 -0
- package/lib/helpers/heartbeat.d.ts +35 -0
- package/lib/helpers/heartbeat.js +55 -0
- package/lib/helpers/image-size.d.ts +18 -0
- package/lib/helpers/image-size.js +83 -0
- package/lib/helpers/images.d.ts +29 -0
- package/lib/helpers/images.js +41 -0
- package/lib/helpers/mail-templates.d.ts +11 -0
- package/lib/helpers/mail-templates.js +42 -0
- package/lib/helpers/publish-due.d.ts +28 -0
- package/lib/helpers/publish-due.js +67 -0
- package/lib/helpers/redirects.d.ts +43 -0
- package/lib/helpers/redirects.js +80 -0
- package/lib/helpers/seo-fields.d.ts +13 -0
- package/lib/helpers/seo-fields.js +52 -0
- package/lib/helpers/session.d.ts +30 -0
- package/lib/helpers/session.js +27 -0
- package/lib/helpers/site-settings.d.ts +98 -0
- package/lib/helpers/site-settings.js +232 -0
- package/lib/helpers/site.d.ts +14 -0
- package/lib/helpers/site.js +23 -0
- package/lib/helpers/write-hooks.d.ts +33 -0
- package/lib/helpers/write-hooks.js +37 -0
- package/lib/hooks.d.ts +17 -0
- package/lib/hooks.js +101 -0
- package/lib/host/core-tasks.d.ts +4 -0
- package/lib/host/core-tasks.js +26 -0
- package/lib/host/cron.d.ts +39 -0
- package/lib/host/cron.js +85 -0
- package/lib/host/enabled.d.ts +4 -0
- package/lib/host/enabled.js +40 -0
- package/lib/host/index.d.ts +81 -0
- package/lib/host/index.js +87 -0
- package/lib/host/manifest.d.ts +34 -0
- package/lib/host/manifest.js +7 -0
- package/lib/host/menu.d.ts +18 -0
- package/lib/host/menu.js +15 -0
- package/lib/main.d.ts +1 -0
- package/lib/main.js +24 -0
- package/lib/middleware/api-auth.d.ts +59 -0
- package/lib/middleware/api-auth.js +164 -0
- package/lib/middleware/auth.d.ts +49 -0
- package/lib/middleware/auth.js +112 -0
- package/lib/middleware/cache.d.ts +17 -0
- package/lib/middleware/cache.js +52 -0
- package/lib/middleware/rate-limits.d.ts +199 -0
- package/lib/middleware/rate-limits.js +276 -0
- package/lib/middleware/viewer.d.ts +13 -0
- package/lib/middleware/viewer.js +16 -0
- package/lib/models/Category.d.ts +24 -0
- package/lib/models/Category.js +102 -0
- package/lib/models/Comment.d.ts +120 -0
- package/lib/models/Comment.js +283 -0
- package/lib/models/ContentType.d.ts +142 -0
- package/lib/models/ContentType.js +462 -0
- package/lib/models/Credential.d.ts +21 -0
- package/lib/models/Credential.js +31 -0
- package/lib/models/Media.d.ts +53 -0
- package/lib/models/Media.js +132 -0
- package/lib/models/Menu.d.ts +131 -0
- package/lib/models/Menu.js +312 -0
- package/lib/models/Page.d.ts +55 -0
- package/lib/models/Page.js +218 -0
- package/lib/models/Post.d.ts +136 -0
- package/lib/models/Post.js +406 -0
- package/lib/models/PostLock.d.ts +67 -0
- package/lib/models/PostLock.js +112 -0
- package/lib/models/PostRevision.d.ts +45 -0
- package/lib/models/PostRevision.js +82 -0
- package/lib/models/PublicContent.d.ts +283 -0
- package/lib/models/PublicContent.js +577 -0
- package/lib/models/Redirect.d.ts +123 -0
- package/lib/models/Redirect.js +225 -0
- package/lib/models/Settings.d.ts +61 -0
- package/lib/models/Settings.js +128 -0
- package/lib/models/Snippet.d.ts +36 -0
- package/lib/models/Snippet.js +64 -0
- package/lib/models/Tag.d.ts +23 -0
- package/lib/models/Tag.js +117 -0
- package/lib/models/Taxonomy.d.ts +127 -0
- package/lib/models/Taxonomy.js +321 -0
- package/lib/models/TwoFactor.d.ts +26 -0
- package/lib/models/TwoFactor.js +60 -0
- package/lib/models/User.d.ts +49 -0
- package/lib/models/User.js +128 -0
- package/lib/models/derive.d.ts +69 -0
- package/lib/models/derive.js +81 -0
- package/lib/models/pagination.d.ts +30 -0
- package/lib/models/pagination.js +36 -0
- package/lib/models/visibility.d.ts +31 -0
- package/lib/models/visibility.js +47 -0
- package/lib/routes/App.d.ts +2 -0
- package/lib/routes/App.js +146 -0
- package/lib/routes/api/admin.d.ts +6 -0
- package/lib/routes/api/admin.js +11 -0
- package/lib/routes/api/auth.d.ts +6 -0
- package/lib/routes/api/auth.js +24 -0
- package/lib/routes/api/authors.d.ts +5 -0
- package/lib/routes/api/authors.js +8 -0
- package/lib/routes/api/categories.d.ts +8 -0
- package/lib/routes/api/categories.js +15 -0
- package/lib/routes/api/comments.d.ts +8 -0
- package/lib/routes/api/comments.js +35 -0
- package/lib/routes/api/content-model.d.ts +17 -0
- package/lib/routes/api/content-model.js +67 -0
- package/lib/routes/api/cron.d.ts +6 -0
- package/lib/routes/api/cron.js +9 -0
- package/lib/routes/api/export.d.ts +5 -0
- package/lib/routes/api/export.js +11 -0
- package/lib/routes/api/feed.d.ts +5 -0
- package/lib/routes/api/feed.js +16 -0
- package/lib/routes/api/media.d.ts +8 -0
- package/lib/routes/api/media.js +25 -0
- package/lib/routes/api/navigation.d.ts +12 -0
- package/lib/routes/api/navigation.js +17 -0
- package/lib/routes/api/ops.d.ts +9 -0
- package/lib/routes/api/ops.js +19 -0
- package/lib/routes/api/pages.d.ts +8 -0
- package/lib/routes/api/pages.js +21 -0
- package/lib/routes/api/passkeys.d.ts +7 -0
- package/lib/routes/api/passkeys.js +13 -0
- package/lib/routes/api/posts.d.ts +8 -0
- package/lib/routes/api/posts.js +39 -0
- package/lib/routes/api/profile.d.ts +6 -0
- package/lib/routes/api/profile.js +8 -0
- package/lib/routes/api/redirects.d.ts +12 -0
- package/lib/routes/api/redirects.js +13 -0
- package/lib/routes/api/settings.d.ts +8 -0
- package/lib/routes/api/settings.js +15 -0
- package/lib/routes/api/snippets.d.ts +15 -0
- package/lib/routes/api/snippets.js +16 -0
- package/lib/routes/api/tags.d.ts +8 -0
- package/lib/routes/api/tags.js +14 -0
- package/lib/routes/api/tokens.d.ts +7 -0
- package/lib/routes/api/tokens.js +15 -0
- package/lib/routes/api/two-factor.d.ts +7 -0
- package/lib/routes/api/two-factor.js +15 -0
- package/lib/routes/api/users.d.ts +8 -0
- package/lib/routes/api/users.js +25 -0
- package/lib/routes/api/v1.d.ts +12 -0
- package/lib/routes/api/v1.js +55 -0
- package/lib/routes/api/verification.d.ts +6 -0
- package/lib/routes/api/verification.js +11 -0
- package/lib/server/index.d.ts +24 -0
- package/lib/server/index.js +110 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.js +1 -0
- package/lib/vite.d.ts +2 -0
- package/lib/vite.js +101 -0
- package/mail/comment-moderation.html +27 -0
- package/mail/comment-moderation.txt +13 -0
- package/mail/comment-reply.html +28 -0
- package/mail/comment-reply.txt +14 -0
- package/mail/invitation.html +25 -0
- package/mail/invitation.txt +11 -0
- package/mail/member-magic-link.html +23 -0
- package/mail/member-magic-link.txt +10 -0
- package/mail/newsletter.html +26 -0
- package/mail/newsletter.txt +13 -0
- package/mail/password-reset.html +26 -0
- package/mail/password-reset.txt +10 -0
- package/mail/verify-email.html +25 -0
- package/mail/verify-email.txt +8 -0
- package/package.json +85 -4
|
@@ -0,0 +1,439 @@
|
|
|
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 { timingSafeEqual } from 'node:crypto';
|
|
34
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
35
|
+
import { sendMail, getMailer, extractAddress } from '@basicbenframework/core/mail';
|
|
36
|
+
// The site's mail/ first, then the CMS's.
|
|
37
|
+
import { renderMail } from "../../helpers/mail-templates.js";
|
|
38
|
+
import { sanitizeHtml, stripTags } from '@basicbenframework/core/content';
|
|
39
|
+
import { absoluteUrl } from '@basicbenframework/core/storage';
|
|
40
|
+
import { can } from '@basicbenframework/core/auth/permissions';
|
|
41
|
+
import { livePost } from "../../models/visibility.js";
|
|
42
|
+
import { Settings } from "../../models/Settings.js";
|
|
43
|
+
import { siteUrl } from "../../helpers/site.js";
|
|
44
|
+
import { issueMemberUnsubscribeToken, pruneMagicLinks } from "./session.js";
|
|
45
|
+
import { NEWSLETTER_HOOKS } from "./events.js";
|
|
46
|
+
import { hooks } from '@basicbenframework/core/hooks';
|
|
47
|
+
import { guardWrite } from "../../helpers/write-hooks.js";
|
|
48
|
+
/** Tries per recipient before a provider error is final. */
|
|
49
|
+
export const MAX_ATTEMPTS = 3;
|
|
50
|
+
/** A claimed row older than this was interrupted, not slow. */
|
|
51
|
+
export const STALE_CLAIM_MS = 15 * 60 * 1000;
|
|
52
|
+
/** Mails per processor call when none is given. */
|
|
53
|
+
export const DEFAULT_BATCH = 50;
|
|
54
|
+
const appUrl = () => (process.env.APP_URL || 'http://localhost:3000').replace(/\/+$/, '');
|
|
55
|
+
/**
|
|
56
|
+
* May this request ask for a post to be mailed to every member?
|
|
57
|
+
*
|
|
58
|
+
* Mailing the whole list is a bigger act than publishing one post, so it is
|
|
59
|
+
* `post.edit` held outright — editors and admins — as Ghost reserves sending
|
|
60
|
+
* for editors. An author can publish their own post; they cannot email it to
|
|
61
|
+
* everyone. Only *turning it on* is checked: re-saving a post whose flag is
|
|
62
|
+
* already set must not fail for the author who wrote it.
|
|
63
|
+
*
|
|
64
|
+
* Returns the refusal, or null.
|
|
65
|
+
*/
|
|
66
|
+
export function newsletterRefusal(req, values, existing) {
|
|
67
|
+
if (!values.send_newsletter || Number(existing?.send_newsletter ?? 0))
|
|
68
|
+
return null;
|
|
69
|
+
return can(req.user, 'post.edit') ? null : 'Only an editor can send a post as a newsletter.';
|
|
70
|
+
}
|
|
71
|
+
/** The post's send, if it has one. */
|
|
72
|
+
export async function newsletterFor(postId) {
|
|
73
|
+
const db = await getDb();
|
|
74
|
+
return db.get('SELECT * FROM newsletter_sends WHERE post_id = ?', [postId]);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Queue a post's newsletter, if it asked for one, is live, and has none yet.
|
|
78
|
+
*
|
|
79
|
+
* Safe to call any number of times, from any number of places at once: the
|
|
80
|
+
* unique `post_id` lets exactly one send row exist, and `prepareSend` adds
|
|
81
|
+
* only recipients not already queued. Returns the send, or null when there is
|
|
82
|
+
* nothing to send.
|
|
83
|
+
*/
|
|
84
|
+
export async function queueNewsletterFor(postId) {
|
|
85
|
+
const db = await getDb();
|
|
86
|
+
const post = (await db.get(`SELECT id, title, send_newsletter FROM posts WHERE id = ? AND ${livePost('posts')}`, [postId]));
|
|
87
|
+
if (!post || !Number(post.send_newsletter))
|
|
88
|
+
return null;
|
|
89
|
+
let send = await newsletterFor(post.id);
|
|
90
|
+
if (!send) {
|
|
91
|
+
try {
|
|
92
|
+
await db.run('INSERT INTO newsletter_sends (post_id, status, subject, created_at) VALUES (?, ?, ?, ?)', [post.id, 'preparing', post.title, new Date().toISOString()]);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Lost the race to another caller: the unique index did its job, and
|
|
96
|
+
// their row is the one to use.
|
|
97
|
+
}
|
|
98
|
+
send = await newsletterFor(post.id);
|
|
99
|
+
}
|
|
100
|
+
if (send?.status === 'preparing') {
|
|
101
|
+
if (hasProvider())
|
|
102
|
+
await handOffSend(send.id);
|
|
103
|
+
else
|
|
104
|
+
await prepareSend(send.id);
|
|
105
|
+
}
|
|
106
|
+
return (await newsletterFor(post.id)) ?? null;
|
|
107
|
+
}
|
|
108
|
+
/** Is a feature listening to take newsletters? */
|
|
109
|
+
export function hasProvider() {
|
|
110
|
+
return hooks.has(NEWSLETTER_HOOKS.DELIVERING);
|
|
111
|
+
}
|
|
112
|
+
/** A hand-off that failed is tried again after this long, and one claimed this long ago is taken as interrupted. */
|
|
113
|
+
export const HANDOFF_RETRY_MS = 10 * 60 * 1000;
|
|
114
|
+
/**
|
|
115
|
+
* Give a post's send to the provider listening on `newsletter.delivering`.
|
|
116
|
+
*
|
|
117
|
+
* The listener gets `{ send, post, message, handledBy: null, externalId: null }`
|
|
118
|
+
* — `message` is the newsletter as the built-in queue would send it, minus a
|
|
119
|
+
* recipient and minus the site's unsubscribe link, which a provider replaces
|
|
120
|
+
* with its own — and takes the send by returning it with `handledBy` (its
|
|
121
|
+
* name) and `externalId` set.
|
|
122
|
+
*
|
|
123
|
+
* - **Claimed first**, with a conditional UPDATE, so two callers cannot both
|
|
124
|
+
* hand a post off. A provider must still make its own call idempotent per
|
|
125
|
+
* `send.id`: a claim that was interrupted is retried after
|
|
126
|
+
* HANDOFF_RETRY_MS, and nothing can tell whether the provider heard it.
|
|
127
|
+
* - **Strict.** A listener that throws (or cancels) leaves the send
|
|
128
|
+
* `handoff_failed`, retried later. It never falls back to the built-in
|
|
129
|
+
* queue: a provider outage must not become a second sender.
|
|
130
|
+
* - **Declined:** if listeners return it untaken, the built-in queue sends it.
|
|
131
|
+
*/
|
|
132
|
+
export async function handOffSend(sendId) {
|
|
133
|
+
const db = await getDb();
|
|
134
|
+
const now = new Date().toISOString();
|
|
135
|
+
const retryBefore = new Date(Date.now() - HANDOFF_RETRY_MS).toISOString();
|
|
136
|
+
const claim = await db.run(`UPDATE newsletter_sends SET status = 'handing_off', started_at = ?
|
|
137
|
+
WHERE id = ? AND (status = 'preparing'
|
|
138
|
+
OR (status IN ('handoff_failed', 'handing_off') AND (started_at IS NULL OR started_at < ?)))`, [now, sendId, retryBefore]);
|
|
139
|
+
if (Number(claim?.changes ?? 0) !== 1)
|
|
140
|
+
return;
|
|
141
|
+
const send = (await db.get('SELECT * FROM newsletter_sends WHERE id = ?', [sendId]));
|
|
142
|
+
const post = (await db.get(`SELECT p.id, p.title, p.slug, p.excerpt, p.content_html FROM posts p WHERE p.id = ? AND ${livePost('p')}`, [send.post_id]));
|
|
143
|
+
const fail = (error) => db.run("UPDATE newsletter_sends SET status = 'handoff_failed', handoff_error = ? WHERE id = ?", [error.slice(0, 500), sendId]);
|
|
144
|
+
// Taken down since it was queued: the editor's call wins, as in the queue.
|
|
145
|
+
if (!post)
|
|
146
|
+
return void (await fail('The post is no longer published.'));
|
|
147
|
+
const { to: _nobody, ...message } = await buildNewsletterMessage(post, { email: '', memberId: null }, { unsubscribe: false });
|
|
148
|
+
const result = await guardWrite(NEWSLETTER_HOOKS.DELIVERING, { send, post, message, handledBy: null, externalId: null }, {}, { refused: 'The newsletter provider refused the send.' });
|
|
149
|
+
if (!result.ok)
|
|
150
|
+
return void (await fail(result.error));
|
|
151
|
+
if (!result.value?.handledBy) {
|
|
152
|
+
// Nobody took it: the built-in queue sends it, as with no provider at all.
|
|
153
|
+
await db.run("UPDATE newsletter_sends SET status = 'preparing', handoff_error = NULL WHERE id = ?", [sendId]);
|
|
154
|
+
return prepareSend(sendId);
|
|
155
|
+
}
|
|
156
|
+
await db.run("UPDATE newsletter_sends SET status = 'handed_off', provider = ?, external_id = ?, handoff_error = NULL WHERE id = ?", [String(result.value.handledBy).slice(0, 50), result.value.externalId == null ? null : String(result.value.externalId).slice(0, 200), sendId]);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Copy the subscribed members into the queue, then mark the send sending.
|
|
160
|
+
*
|
|
161
|
+
* One INSERT … SELECT, so a large list is one statement rather than a round
|
|
162
|
+
* trip per member. `NOT EXISTS` rather than ON CONFLICT so it is the same SQL
|
|
163
|
+
* on SQLite, libSQL and Postgres; the unique index is still there behind it.
|
|
164
|
+
* The id and timestamp are inlined because Postgres cannot always infer a
|
|
165
|
+
* parameter's type in a SELECT list — both are our own values, never input.
|
|
166
|
+
*/
|
|
167
|
+
async function prepareSend(sendId) {
|
|
168
|
+
const db = await getDb();
|
|
169
|
+
const id = Number(sendId);
|
|
170
|
+
if (!Number.isInteger(id))
|
|
171
|
+
return;
|
|
172
|
+
const now = new Date().toISOString();
|
|
173
|
+
await db.run(`INSERT INTO newsletter_queue (send_id, member_id, email, status, attempts, created_at)
|
|
174
|
+
SELECT ${id}, m.id, m.email, 'pending', 0, '${now}'
|
|
175
|
+
FROM members m
|
|
176
|
+
WHERE m.status = 'active'
|
|
177
|
+
AND NOT EXISTS (SELECT 1 FROM newsletter_queue q WHERE q.send_id = ${id} AND q.member_id = m.id)`);
|
|
178
|
+
await db.run(`UPDATE newsletter_sends
|
|
179
|
+
SET status = 'sending', started_at = ?,
|
|
180
|
+
total_count = (SELECT COUNT(*) FROM newsletter_queue WHERE send_id = ?)
|
|
181
|
+
WHERE id = ? AND status = 'preparing'`, [now, id, id]);
|
|
182
|
+
// A list with nobody subscribed is finished the moment it starts.
|
|
183
|
+
await refreshCounts(id);
|
|
184
|
+
}
|
|
185
|
+
/** Recount a send from its queue, and close it when nothing is left to do. */
|
|
186
|
+
async function refreshCounts(sendId) {
|
|
187
|
+
const db = await getDb();
|
|
188
|
+
const rows = (await db.all('SELECT status, COUNT(*) AS total FROM newsletter_queue WHERE send_id = ? GROUP BY status', [sendId]));
|
|
189
|
+
const of = (status) => Number(rows.find(row => row.status === status)?.total) || 0;
|
|
190
|
+
const total = rows.reduce((sum, row) => sum + (Number(row.total) || 0), 0);
|
|
191
|
+
const open = of('pending') + of('sending');
|
|
192
|
+
await db.run(`UPDATE newsletter_sends
|
|
193
|
+
SET total_count = ?, sent_count = ?, failed_count = ?, skipped_count = ?,
|
|
194
|
+
status = CASE WHEN ? = 0 AND status = 'sending' THEN 'sent' ELSE status END,
|
|
195
|
+
completed_at = CASE WHEN ? = 0 AND status = 'sending' THEN ? ELSE completed_at END
|
|
196
|
+
WHERE id = ?`, [total, of('sent'), of('failed'), of('skipped'), open, open, new Date().toISOString(), sendId]);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Make every link and image in a post's HTML absolute.
|
|
200
|
+
*
|
|
201
|
+
* A mail client has no page to resolve `/uploads/x.png` or `/blog/other`
|
|
202
|
+
* against. Images resolve against APP_URL — where local storage serves them —
|
|
203
|
+
* and links against the public site, the same split the content API uses.
|
|
204
|
+
* Only root-relative values are touched; `//host` and absolute URLs are left
|
|
205
|
+
* alone, and anything else the sanitizer already refused.
|
|
206
|
+
*/
|
|
207
|
+
export function absolutize(html, site = siteUrl(), app = appUrl()) {
|
|
208
|
+
return html.replace(/(\s(href|src)=")(\/(?!\/)[^"]*)"/gi, (_match, prefix, attr, path) => {
|
|
209
|
+
const base = attr.toLowerCase() === 'src' ? app : site;
|
|
210
|
+
return `${prefix}${base ? absoluteUrl(path, base) : path}"`;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/** The public URL of a post, as the feeds build it. */
|
|
214
|
+
export function postUrl(post) {
|
|
215
|
+
return `${siteUrl()}/blog/${post.slug || post.id}`;
|
|
216
|
+
}
|
|
217
|
+
/** For text placed inside the unsubscribe paragraph, which is inserted unescaped. */
|
|
218
|
+
function escapeAttribute(value) {
|
|
219
|
+
return String(value).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
220
|
+
}
|
|
221
|
+
/** A display name that cannot break out of a From header. */
|
|
222
|
+
function cleanName(value) {
|
|
223
|
+
return value.replace(/[\r\n"<>\\]/g, '').trim().slice(0, 100);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The message for one recipient.
|
|
227
|
+
*
|
|
228
|
+
* The body is sanitized again here even though `content_html` is already a
|
|
229
|
+
* sanitized render: it is about to be delivered outside the site, to mail
|
|
230
|
+
* clients with their own idea of what is safe, and a listener on
|
|
231
|
+
* `content.save` may have put something in the column the sanitizer would
|
|
232
|
+
* not. Sanitizing twice costs microseconds; trusting a cache is how a stored
|
|
233
|
+
* value becomes a mail-borne one.
|
|
234
|
+
*/
|
|
235
|
+
export async function buildNewsletterMessage(post, recipient, { unsubscribe = true } = {}) {
|
|
236
|
+
const [siteName, senderName, replyTo, footer] = await Promise.all([
|
|
237
|
+
Settings.getSiteName(),
|
|
238
|
+
Settings.get('newsletter_sender_name'),
|
|
239
|
+
Settings.get('newsletter_reply_to'),
|
|
240
|
+
Settings.get('newsletter_footer')
|
|
241
|
+
]);
|
|
242
|
+
const contentHtml = absolutize(sanitizeHtml(post.content_html ?? ''));
|
|
243
|
+
// A test send goes to someone who is not a member; their link names nobody
|
|
244
|
+
// and the unsubscribe page says so rather than unsubscribing a stranger.
|
|
245
|
+
const unsubscribeUrl = `${appUrl()}/api/v1/members/unsubscribe?token=${encodeURIComponent(issueMemberUnsubscribeToken(recipient.memberId ?? 0))}`;
|
|
246
|
+
const { from } = await getMailer();
|
|
247
|
+
const name = cleanName(senderName || siteName);
|
|
248
|
+
const address = from ? extractAddress(from) : '';
|
|
249
|
+
// Without the site's own link when a provider sends it: the provider adds
|
|
250
|
+
// its unsubscribe footer and header, and a second link that only the CMS
|
|
251
|
+
// understands would unsubscribe someone from the wrong list.
|
|
252
|
+
const escaped = escapeAttribute(unsubscribeUrl);
|
|
253
|
+
const unsubscribeHtml = unsubscribe
|
|
254
|
+
? `<p style="margin: 0; font-size: 13px; color: #666; line-height: 1.5;">You are receiving this because you subscribed to ${escapeAttribute(siteName)}. <a href="${escaped}" style="color: #666;">Unsubscribe</a> — no account needed.</p>`
|
|
255
|
+
: '';
|
|
256
|
+
const unsubscribeText = unsubscribe
|
|
257
|
+
? `You are receiving this because you subscribed to ${siteName}.\nUnsubscribe, no account needed:\n${unsubscribeUrl}`
|
|
258
|
+
: '';
|
|
259
|
+
return {
|
|
260
|
+
to: recipient.email,
|
|
261
|
+
...(address && name ? { from: `"${name}" <${address}>` } : {}),
|
|
262
|
+
...(replyTo ? { replyTo } : {}),
|
|
263
|
+
subject: post.title,
|
|
264
|
+
// RFC 8058 one-click: the mail client's own unsubscribe button POSTs to
|
|
265
|
+
// the same link, so a reader never has to find it in the body — and
|
|
266
|
+
// Gmail and Yahoo require it of bulk senders.
|
|
267
|
+
headers: unsubscribe
|
|
268
|
+
? {
|
|
269
|
+
'List-Unsubscribe': `<${unsubscribeUrl}>`,
|
|
270
|
+
'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click',
|
|
271
|
+
Precedence: 'bulk'
|
|
272
|
+
}
|
|
273
|
+
: { Precedence: 'bulk' },
|
|
274
|
+
...renderMail('newsletter', {
|
|
275
|
+
title: post.title,
|
|
276
|
+
siteName,
|
|
277
|
+
postUrl: postUrl(post),
|
|
278
|
+
contentHtml,
|
|
279
|
+
contentText: stripTags(contentHtml),
|
|
280
|
+
footer: footer || '',
|
|
281
|
+
unsubscribeHtml,
|
|
282
|
+
unsubscribeText
|
|
283
|
+
})
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Send up to `limit` queued newsletter mails. Resumable; see the file header.
|
|
288
|
+
*
|
|
289
|
+
* `send` is the transport, injectable so a test can make delivery fail
|
|
290
|
+
* without a mail provider. Returns what it did.
|
|
291
|
+
*/
|
|
292
|
+
export async function processNewsletterQueue(limit = DEFAULT_BATCH, { send = sendMail } = {}) {
|
|
293
|
+
const db = await getDb();
|
|
294
|
+
const outcome = { sent: 0, failed: 0, skipped: 0, retried: 0 };
|
|
295
|
+
const touched = new Set();
|
|
296
|
+
// Sends whose queueing was interrupted finish queueing first, or, with a
|
|
297
|
+
// provider listening, are handed to it; a hand-off that failed or was
|
|
298
|
+
// interrupted is tried again (handOffSend waits HANDOFF_RETRY_MS between).
|
|
299
|
+
const preparing = (await db.all("SELECT id FROM newsletter_sends WHERE status = 'preparing'"));
|
|
300
|
+
for (const row of preparing) {
|
|
301
|
+
if (hasProvider())
|
|
302
|
+
await handOffSend(row.id);
|
|
303
|
+
else
|
|
304
|
+
await prepareSend(row.id);
|
|
305
|
+
}
|
|
306
|
+
if (hasProvider()) {
|
|
307
|
+
const stuck = (await db.all("SELECT id FROM newsletter_sends WHERE status IN ('handoff_failed', 'handing_off')"));
|
|
308
|
+
for (const row of stuck)
|
|
309
|
+
await handOffSend(row.id);
|
|
310
|
+
}
|
|
311
|
+
// Claimed and never finished: the process died mid-send. Not retried — see
|
|
312
|
+
// "Never twice" above.
|
|
313
|
+
const staleBefore = new Date(Date.now() - STALE_CLAIM_MS).toISOString();
|
|
314
|
+
const stale = (await db.all("SELECT DISTINCT send_id FROM newsletter_queue WHERE status = 'sending' AND claimed_at < ?", [staleBefore]));
|
|
315
|
+
if (stale.length) {
|
|
316
|
+
await db.run("UPDATE newsletter_queue SET status = 'failed', error = ? WHERE status = 'sending' AND claimed_at < ?", ['Interrupted while sending; not retried in case it was delivered', staleBefore]);
|
|
317
|
+
for (const row of stale)
|
|
318
|
+
touched.add(Number(row.send_id));
|
|
319
|
+
}
|
|
320
|
+
const batch = Math.max(1, Math.min(500, Math.floor(Number(limit) || DEFAULT_BATCH)));
|
|
321
|
+
const candidates = (await db.all(`SELECT q.id, q.send_id, q.member_id, q.attempts
|
|
322
|
+
FROM newsletter_queue q
|
|
323
|
+
JOIN newsletter_sends s ON s.id = q.send_id
|
|
324
|
+
WHERE q.status = 'pending' AND s.status = 'sending'
|
|
325
|
+
ORDER BY q.id ASC
|
|
326
|
+
LIMIT ?`, [batch]));
|
|
327
|
+
// Each send's post is read once per batch, not once per recipient.
|
|
328
|
+
const posts = new Map();
|
|
329
|
+
for (const row of candidates) {
|
|
330
|
+
const now = new Date().toISOString();
|
|
331
|
+
// The claim. Whoever changes the row owns it; everyone else moves on.
|
|
332
|
+
const claim = await db.run("UPDATE newsletter_queue SET status = 'sending', claimed_at = ?, attempts = attempts + 1 WHERE id = ? AND status = 'pending'", [now, row.id]);
|
|
333
|
+
if (Number(claim?.changes ?? 0) !== 1)
|
|
334
|
+
continue;
|
|
335
|
+
touched.add(Number(row.send_id));
|
|
336
|
+
const member = (await db.get('SELECT id, email, status FROM members WHERE id = ?', [row.member_id]));
|
|
337
|
+
// Unsubscribed (or deleted) since the queue was built: their wish now
|
|
338
|
+
// beats the list as it was then.
|
|
339
|
+
if (!member || member.status !== 'active') {
|
|
340
|
+
await db.run("UPDATE newsletter_queue SET status = 'skipped', error = ? WHERE id = ?", ['No longer subscribed', row.id]);
|
|
341
|
+
outcome.skipped++;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (!posts.has(row.send_id)) {
|
|
345
|
+
posts.set(row.send_id, (await db.get(`SELECT p.id, p.title, p.slug, p.excerpt, p.content_html
|
|
346
|
+
FROM newsletter_sends s JOIN posts p ON p.id = s.post_id
|
|
347
|
+
WHERE s.id = ? AND ${livePost('p')}`, [row.send_id])) ?? null);
|
|
348
|
+
}
|
|
349
|
+
const post = posts.get(row.send_id);
|
|
350
|
+
// Unpublished or trashed mid-send. The rest of the list does not get it:
|
|
351
|
+
// the editor took it down for a reason.
|
|
352
|
+
if (!post) {
|
|
353
|
+
await db.run("UPDATE newsletter_queue SET status = 'skipped', error = ? WHERE id = ?", ['Post is no longer published', row.id]);
|
|
354
|
+
outcome.skipped++;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
await send(await buildNewsletterMessage(post, { email: member.email, memberId: member.id }));
|
|
359
|
+
await db.run("UPDATE newsletter_queue SET status = 'sent', sent_at = ?, error = NULL WHERE id = ?", [new Date().toISOString(), row.id]);
|
|
360
|
+
outcome.sent++;
|
|
361
|
+
}
|
|
362
|
+
catch (err) {
|
|
363
|
+
const message = String(err?.message ?? err).slice(0, 500);
|
|
364
|
+
const attempts = Number(row.attempts) + 1;
|
|
365
|
+
// A provider error is a known non-delivery, so it may be tried again —
|
|
366
|
+
// on the next call, which is at least the next tick.
|
|
367
|
+
if (attempts >= MAX_ATTEMPTS) {
|
|
368
|
+
await db.run("UPDATE newsletter_queue SET status = 'failed', error = ? WHERE id = ?", [message, row.id]);
|
|
369
|
+
outcome.failed++;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
await db.run("UPDATE newsletter_queue SET status = 'pending', error = ? WHERE id = ?", [message, row.id]);
|
|
373
|
+
outcome.retried++;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
for (const sendId of touched)
|
|
378
|
+
await refreshCounts(sendId);
|
|
379
|
+
return outcome;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Mail a post to one address as members will see it, without queueing.
|
|
383
|
+
*
|
|
384
|
+
* For "send a test to yourself". Works on drafts — previewing before
|
|
385
|
+
* publishing is the point — and never touches the queue or the send row.
|
|
386
|
+
*/
|
|
387
|
+
export async function sendTestNewsletter(postId, to, send = sendMail) {
|
|
388
|
+
const db = await getDb();
|
|
389
|
+
const post = (await db.get('SELECT id, title, slug, excerpt, content_html FROM posts WHERE id = ? AND deleted_at IS NULL', [postId]));
|
|
390
|
+
if (!post)
|
|
391
|
+
return false;
|
|
392
|
+
const message = await buildNewsletterMessage(post, { email: to, memberId: null });
|
|
393
|
+
await send({ ...message, subject: `[Test] ${post.title}` });
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Run a job without the request waiting for it, and never let it throw.
|
|
398
|
+
*
|
|
399
|
+
* As comment-mail's `inBackground`: on a serverless host the function may be
|
|
400
|
+
* frozen before it finishes, which costs nothing here — the queue resumes.
|
|
401
|
+
*/
|
|
402
|
+
function inBackground(job) {
|
|
403
|
+
Promise.resolve().then(job).catch(err => console.error('[newsletter]', err?.message ?? err));
|
|
404
|
+
}
|
|
405
|
+
let lastRun = 0;
|
|
406
|
+
/** Kick a small batch at most once a minute, without delaying the request. */
|
|
407
|
+
export function kickNewsletterQueue(limit = 10) {
|
|
408
|
+
if (Date.now() - lastRun < 60_000)
|
|
409
|
+
return;
|
|
410
|
+
lastRun = Date.now();
|
|
411
|
+
inBackground(() => processNewsletterQueue(limit));
|
|
412
|
+
}
|
|
413
|
+
/** Middleware form of `kickNewsletterQueue`, for routes with traffic. */
|
|
414
|
+
export function newslettersOpportunistically(_req, _res, next) {
|
|
415
|
+
kickNewsletterQueue();
|
|
416
|
+
next();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* `GET /api/cron/newsletters`, for a platform scheduler.
|
|
420
|
+
*
|
|
421
|
+
* The same rule as `/api/cron/publish-due`: `Authorization: Bearer
|
|
422
|
+
* $CRON_SECRET`, and with no secret configured the endpoint does not exist.
|
|
423
|
+
* `?limit=` sizes the batch (default 100, at most 500) so a host with a short
|
|
424
|
+
* function timeout can ask for less.
|
|
425
|
+
*/
|
|
426
|
+
export async function newslettersCronEndpoint(req, res) {
|
|
427
|
+
const secret = process.env.CRON_SECRET;
|
|
428
|
+
const given = String(req.headers.authorization ?? '');
|
|
429
|
+
const expected = `Bearer ${secret}`;
|
|
430
|
+
if (!secret || given.length !== expected.length || !timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
|
|
431
|
+
return res.json({ error: 'Not found' }, 404);
|
|
432
|
+
}
|
|
433
|
+
lastRun = Date.now();
|
|
434
|
+
const limit = Math.min(500, Math.max(1, Number(req.query?.limit) || 100));
|
|
435
|
+
const outcome = await processNewsletterQueue(limit);
|
|
436
|
+
// Housekeeping that needs a tick and has no other: spent magic links.
|
|
437
|
+
await pruneMagicLinks().catch(() => { });
|
|
438
|
+
res.json(outcome);
|
|
439
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The members feature's rate limits. Same store and address keying as core's
|
|
3
|
+
* (middleware/rate-limits.ts), each on its own bucket.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Asking for a member magic link, from one address.
|
|
7
|
+
*
|
|
8
|
+
* The per-address half, as middleware: it refuses everyone from the address
|
|
9
|
+
* alike, so its 429 says nothing about whether any address is a member. The
|
|
10
|
+
* per-mailbox half runs silently inside MemberController on
|
|
11
|
+
* `emailSendLimiter`, for the reason `passwordResetLimit` gives.
|
|
12
|
+
*/
|
|
13
|
+
export declare const memberMagicLinkLimit: Function & {
|
|
14
|
+
limiter: import("@basicbenframework/core/rate-limit").Limiter;
|
|
15
|
+
key: (req: any) => string | null | undefined;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Spending a magic link. The tokens are 32 random bytes, so entropy stops
|
|
19
|
+
* guessing; this stops one address hammering the lookup.
|
|
20
|
+
*/
|
|
21
|
+
export declare const memberVerifyLimit: Function & {
|
|
22
|
+
limiter: import("@basicbenframework/core/rate-limit").Limiter;
|
|
23
|
+
key: (req: any) => string | null | undefined;
|
|
24
|
+
};
|
|
25
|
+
/** A member changing their own profile. Keyed on the member, so it runs after `requireMember`. */
|
|
26
|
+
export declare const memberAccountLimit: Function & {
|
|
27
|
+
limiter: import("@basicbenframework/core/rate-limit").Limiter;
|
|
28
|
+
key: (req: any) => string | null | undefined;
|
|
29
|
+
};
|
|
30
|
+
/** The newsletter unsubscribe link. Its own bucket, not the comment one. */
|
|
31
|
+
export declare const memberUnsubscribeLimit: Function & {
|
|
32
|
+
limiter: import("@basicbenframework/core/rate-limit").Limiter;
|
|
33
|
+
key: (req: any) => string | null | undefined;
|
|
34
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The members feature's rate limits. Same store and address keying as core's
|
|
3
|
+
* (middleware/rate-limits.ts), each on its own bucket.
|
|
4
|
+
*/
|
|
5
|
+
import { rateLimit } from '@basicbenframework/core/rate-limit';
|
|
6
|
+
import { store, addressIn } from "../../middleware/rate-limits.js";
|
|
7
|
+
/**
|
|
8
|
+
* Asking for a member magic link, from one address.
|
|
9
|
+
*
|
|
10
|
+
* The per-address half, as middleware: it refuses everyone from the address
|
|
11
|
+
* alike, so its 429 says nothing about whether any address is a member. The
|
|
12
|
+
* per-mailbox half runs silently inside MemberController on
|
|
13
|
+
* `emailSendLimiter`, for the reason `passwordResetLimit` gives.
|
|
14
|
+
*/
|
|
15
|
+
export const memberMagicLinkLimit = rateLimit({
|
|
16
|
+
limit: 5,
|
|
17
|
+
window: '15m',
|
|
18
|
+
blockFor: '15m',
|
|
19
|
+
store,
|
|
20
|
+
key: addressIn('member-magic-link'),
|
|
21
|
+
message: 'Too many sign-in requests. Please try again shortly.'
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Spending a magic link. The tokens are 32 random bytes, so entropy stops
|
|
25
|
+
* guessing; this stops one address hammering the lookup.
|
|
26
|
+
*/
|
|
27
|
+
export const memberVerifyLimit = rateLimit({
|
|
28
|
+
limit: 20,
|
|
29
|
+
window: '15m',
|
|
30
|
+
blockFor: '15m',
|
|
31
|
+
store,
|
|
32
|
+
key: addressIn('member-verify'),
|
|
33
|
+
message: 'Too many attempts. Please try again shortly.'
|
|
34
|
+
});
|
|
35
|
+
/** A member changing their own profile. Keyed on the member, so it runs after `requireMember`. */
|
|
36
|
+
export const memberAccountLimit = rateLimit({
|
|
37
|
+
limit: 30,
|
|
38
|
+
window: '15m',
|
|
39
|
+
store,
|
|
40
|
+
key: (req) => (req.member ? `member:${req.member.id}` : null),
|
|
41
|
+
message: 'Too many changes. Please try again shortly.'
|
|
42
|
+
});
|
|
43
|
+
/** The newsletter unsubscribe link. Its own bucket, not the comment one. */
|
|
44
|
+
export const memberUnsubscribeLimit = rateLimit({
|
|
45
|
+
limit: 30,
|
|
46
|
+
window: '10m',
|
|
47
|
+
store,
|
|
48
|
+
key: addressIn('member-unsubscribe'),
|
|
49
|
+
message: 'Too many requests. Please try again shortly.'
|
|
50
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The member on a request, added to core's Request type for this feature's
|
|
3
|
+
* code. Set by middleware.ts; core never reads it (core sees only the opaque
|
|
4
|
+
* `viewer` the access policy returns).
|
|
5
|
+
*/
|
|
6
|
+
import type { MemberRow } from './Member.ts';
|
|
7
|
+
declare module '../../types' {
|
|
8
|
+
interface Request {
|
|
9
|
+
/** The signed-in reader, or null when the request carried no valid member session. Never an admin principal. */
|
|
10
|
+
member?: MemberRow | null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Router } from '../../host/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Members, newsletters, and their admin.
|
|
4
|
+
*
|
|
5
|
+
* The member routes sit under /api/v1 because headless front ends call them,
|
|
6
|
+
* but outside `requireScope`: a reader's browser holds no `content:read`
|
|
7
|
+
* token (that is the site's secret), and the member session is the credential
|
|
8
|
+
* here. Each is rate limited on its own bucket. They are not `cacheable` —
|
|
9
|
+
* every response is about one person.
|
|
10
|
+
*
|
|
11
|
+
* The admin routes are `auth` then a capability, like every other admin
|
|
12
|
+
* route. `auth` refuses member sessions outright: they are signed with a
|
|
13
|
+
* different key and never verify as an admin session.
|
|
14
|
+
*/
|
|
15
|
+
export declare function memberRoutes(router: Router): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { requireCapability } from '@basicbenframework/core/auth/permissions';
|
|
2
|
+
import { MemberController } from "./MemberController.js";
|
|
3
|
+
import { MemberAdminController } from "./MemberAdminController.js";
|
|
4
|
+
import { auth } from "../../middleware/auth.js";
|
|
5
|
+
import { requireMember } from "./middleware.js";
|
|
6
|
+
import { memberMagicLinkLimit, memberVerifyLimit, memberAccountLimit, memberUnsubscribeLimit } from "./rate-limits.js";
|
|
7
|
+
import { newslettersCronEndpoint } from "./newsletter.js";
|
|
8
|
+
import { Post } from "../../models/Post.js";
|
|
9
|
+
/**
|
|
10
|
+
* Members, newsletters, and their admin.
|
|
11
|
+
*
|
|
12
|
+
* The member routes sit under /api/v1 because headless front ends call them,
|
|
13
|
+
* but outside `requireScope`: a reader's browser holds no `content:read`
|
|
14
|
+
* token (that is the site's secret), and the member session is the credential
|
|
15
|
+
* here. Each is rate limited on its own bucket. They are not `cacheable` —
|
|
16
|
+
* every response is about one person.
|
|
17
|
+
*
|
|
18
|
+
* The admin routes are `auth` then a capability, like every other admin
|
|
19
|
+
* route. `auth` refuses member sessions outright: they are signed with a
|
|
20
|
+
* different key and never verify as an admin session.
|
|
21
|
+
*/
|
|
22
|
+
export function memberRoutes(router) {
|
|
23
|
+
// --- Readers (cross-origin, bearer tokens, no cookies) ---------------------
|
|
24
|
+
router.post('/api/v1/members/magic-link', memberMagicLinkLimit, MemberController.magicLink);
|
|
25
|
+
router.post('/api/v1/members/verify', memberVerifyLimit, MemberController.verify);
|
|
26
|
+
router.get('/api/v1/members/verify', memberVerifyLimit, MemberController.verify);
|
|
27
|
+
router.get('/api/v1/members/me', requireMember, memberAccountLimit, MemberController.me);
|
|
28
|
+
router.put('/api/v1/members/me', requireMember, memberAccountLimit, MemberController.update);
|
|
29
|
+
router.post('/api/v1/members/signout', requireMember, memberAccountLimit, MemberController.signout);
|
|
30
|
+
// The newsletter's unsubscribe link: GET shows a button, POST (and RFC 8058
|
|
31
|
+
// one-click) unsubscribes. The signed token is the credential.
|
|
32
|
+
router.get('/api/v1/members/unsubscribe', memberUnsubscribeLimit, MemberController.unsubscribePage);
|
|
33
|
+
router.post('/api/v1/members/unsubscribe', memberUnsubscribeLimit, MemberController.unsubscribe);
|
|
34
|
+
// --- Admin: the member list (admin only) ----------------------------------
|
|
35
|
+
const manage = [auth, requireCapability('user.manage')];
|
|
36
|
+
router.get('/api/members', ...manage, MemberAdminController.index);
|
|
37
|
+
// Before /api/members/:id so neither is read as an id.
|
|
38
|
+
router.get('/api/members/export', ...manage, MemberAdminController.export);
|
|
39
|
+
router.post('/api/members/import', ...manage, MemberAdminController.import);
|
|
40
|
+
router.post('/api/members', ...manage, MemberAdminController.store);
|
|
41
|
+
router.put('/api/members/:id', ...manage, MemberAdminController.update);
|
|
42
|
+
router.delete('/api/members/:id', ...manage, MemberAdminController.destroy);
|
|
43
|
+
router.get('/api/newsletters', ...manage, MemberAdminController.sends);
|
|
44
|
+
// --- Admin: one post's newsletter -----------------------------------------
|
|
45
|
+
// Anyone who may edit the post may see whether it went out and mail
|
|
46
|
+
// themselves a preview; *requesting* the send is `post.edit` outright, and
|
|
47
|
+
// is checked where the flag is saved (PostController via newsletterRefusal).
|
|
48
|
+
const editablePost = requireCapability('post.edit', {
|
|
49
|
+
loadResource: async (req) => {
|
|
50
|
+
const post = await Post.find(Number(req.params.id));
|
|
51
|
+
return post && !post.deleted_at ? post : null;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
router.get('/api/posts/:id/newsletter', auth, editablePost, MemberAdminController.status);
|
|
55
|
+
router.post('/api/posts/:id/newsletter/test', auth, editablePost, MemberAdminController.test);
|
|
56
|
+
// Kept from before the cron tick, which now sends newsletters too. Sends
|
|
57
|
+
// the next batch now (`?limit=`, default 100), whether or not one is due.
|
|
58
|
+
router.get('/api/cron/newsletters', newslettersCronEndpoint);
|
|
59
|
+
}
|