@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,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials for members: sessions, magic links and unsubscribe links.
|
|
3
|
+
*
|
|
4
|
+
* ## A member session can never be an admin session
|
|
5
|
+
*
|
|
6
|
+
* Admin sessions are JWTs signed with APP_KEY and carrying `userId`; `auth`
|
|
7
|
+
* verifies with APP_KEY and reads that claim. A member session is signed with
|
|
8
|
+
* a *different key*, derived from APP_KEY for this one purpose, and carries
|
|
9
|
+
* `mid` instead of `userId` plus an `aud` naming it a member token. So:
|
|
10
|
+
*
|
|
11
|
+
* - `auth` / `resolveSession` fail its signature check (different key) and
|
|
12
|
+
* answer "Invalid token" — the claims are never even read;
|
|
13
|
+
* - even a hypothetical key collision would leave `userId` undefined, which
|
|
14
|
+
* reads no account;
|
|
15
|
+
* - the reverse holds too: an admin JWT fails `readMemberSession`.
|
|
16
|
+
*
|
|
17
|
+
* `tests/phase3-members.test.js` proves the first and the last.
|
|
18
|
+
*
|
|
19
|
+
* ## Why derived keys
|
|
20
|
+
*
|
|
21
|
+
* The same reason `comment-guard.ts` derives its own: APP_KEY signs sessions,
|
|
22
|
+
* and every other kind of token signed with it is a token that might be
|
|
23
|
+
* replayed as one. Deriving per purpose also means an unsubscribe token cannot
|
|
24
|
+
* be presented as a session, or the reverse.
|
|
25
|
+
*
|
|
26
|
+
* ## Magic links
|
|
27
|
+
*
|
|
28
|
+
* Random, single-use and stored hashed in `member_tokens` — not a stateless
|
|
29
|
+
* JWT. A signed link would be replayable until it expired; a row can be
|
|
30
|
+
* claimed exactly once, by the conditional UPDATE that `redeemToken` in the
|
|
31
|
+
* framework uses for password resets.
|
|
32
|
+
*/
|
|
33
|
+
/** The audience a member session names. Checked on every read. */
|
|
34
|
+
export declare const MEMBER_AUDIENCE = "basicben:member";
|
|
35
|
+
/** How long a member stays signed in. Readers expect "remember me", not a daily login. */
|
|
36
|
+
export declare const MEMBER_SESSION_TTL = "30d";
|
|
37
|
+
/** How long a magic link works. Long enough to find the mail; short enough to be useless later. */
|
|
38
|
+
export declare const MAGIC_LINK_TTL_MS: number;
|
|
39
|
+
/**
|
|
40
|
+
* The header a member session travels in on content reads.
|
|
41
|
+
*
|
|
42
|
+
* Not `Authorization`, because on `/api/v1` that header is already taken by
|
|
43
|
+
* the `content:read` token a front end authenticates *itself* with. The two
|
|
44
|
+
* are different parties — the site, and the reader using it — and a request
|
|
45
|
+
* routinely carries both. The member endpoints themselves accept either.
|
|
46
|
+
*/
|
|
47
|
+
export declare const MEMBER_HEADER = "x-member-token";
|
|
48
|
+
export interface MemberSessionClaims {
|
|
49
|
+
mid: number;
|
|
50
|
+
/** The member's `session_version` when this was issued. */
|
|
51
|
+
sv: number;
|
|
52
|
+
aud: string;
|
|
53
|
+
}
|
|
54
|
+
/** Mint a member session. */
|
|
55
|
+
export declare function issueMemberSession(member: {
|
|
56
|
+
id: number;
|
|
57
|
+
session_version?: number | null;
|
|
58
|
+
}): string;
|
|
59
|
+
/**
|
|
60
|
+
* The claims of a member session, or null.
|
|
61
|
+
*
|
|
62
|
+
* Signature, expiry and audience. Whether the member still exists and the
|
|
63
|
+
* session has not been signed out is the caller's question — it needs the row.
|
|
64
|
+
*/
|
|
65
|
+
export declare function readMemberSession(token: unknown): MemberSessionClaims | null;
|
|
66
|
+
/**
|
|
67
|
+
* A link that unsubscribes one member from newsletters.
|
|
68
|
+
*
|
|
69
|
+
* No expiry: an unsubscribe link has to work in a mail opened a year later,
|
|
70
|
+
* and the most it can do is stop mail — the same reasoning, and the same
|
|
71
|
+
* shape, as the comment reply unsubscribe in comment-guard.ts.
|
|
72
|
+
*/
|
|
73
|
+
export declare function issueMemberUnsubscribeToken(memberId: number): string;
|
|
74
|
+
/** The member an unsubscribe token names, or null. */
|
|
75
|
+
export declare function readMemberUnsubscribeToken(token: unknown): number | null;
|
|
76
|
+
/** One normal form for an address, so the unique index means one mailbox. */
|
|
77
|
+
export declare function normalizeEmail(value: unknown): string;
|
|
78
|
+
export interface MagicLinkPayload {
|
|
79
|
+
/** Null for a sign-up: there is no member yet. */
|
|
80
|
+
memberId: number | null;
|
|
81
|
+
email: string;
|
|
82
|
+
metadata: {
|
|
83
|
+
name?: string | null;
|
|
84
|
+
newsletter?: boolean;
|
|
85
|
+
} | null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Issue a magic link for an address, revoking any earlier unused one.
|
|
89
|
+
*
|
|
90
|
+
* Only the newest link works — someone who asked twice and clicks the older
|
|
91
|
+
* mail should not be signed in by a link they may have forwarded.
|
|
92
|
+
*/
|
|
93
|
+
export declare function issueMagicLink(payload: MagicLinkPayload): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Spend a magic link. Null for anything not currently valid.
|
|
96
|
+
*
|
|
97
|
+
* Unknown, expired and already-used are one answer: the caller has no safe
|
|
98
|
+
* use for the difference, and telling them apart helps only a guesser.
|
|
99
|
+
*/
|
|
100
|
+
export declare function redeemMagicLink(token: unknown): Promise<MagicLinkPayload | null>;
|
|
101
|
+
/** Delete links that can no longer be used. Called opportunistically by the newsletter cron. */
|
|
102
|
+
export declare function pruneMagicLinks(): Promise<void>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials for members: sessions, magic links and unsubscribe links.
|
|
3
|
+
*
|
|
4
|
+
* ## A member session can never be an admin session
|
|
5
|
+
*
|
|
6
|
+
* Admin sessions are JWTs signed with APP_KEY and carrying `userId`; `auth`
|
|
7
|
+
* verifies with APP_KEY and reads that claim. A member session is signed with
|
|
8
|
+
* a *different key*, derived from APP_KEY for this one purpose, and carries
|
|
9
|
+
* `mid` instead of `userId` plus an `aud` naming it a member token. So:
|
|
10
|
+
*
|
|
11
|
+
* - `auth` / `resolveSession` fail its signature check (different key) and
|
|
12
|
+
* answer "Invalid token" — the claims are never even read;
|
|
13
|
+
* - even a hypothetical key collision would leave `userId` undefined, which
|
|
14
|
+
* reads no account;
|
|
15
|
+
* - the reverse holds too: an admin JWT fails `readMemberSession`.
|
|
16
|
+
*
|
|
17
|
+
* `tests/phase3-members.test.js` proves the first and the last.
|
|
18
|
+
*
|
|
19
|
+
* ## Why derived keys
|
|
20
|
+
*
|
|
21
|
+
* The same reason `comment-guard.ts` derives its own: APP_KEY signs sessions,
|
|
22
|
+
* and every other kind of token signed with it is a token that might be
|
|
23
|
+
* replayed as one. Deriving per purpose also means an unsubscribe token cannot
|
|
24
|
+
* be presented as a session, or the reverse.
|
|
25
|
+
*
|
|
26
|
+
* ## Magic links
|
|
27
|
+
*
|
|
28
|
+
* Random, single-use and stored hashed in `member_tokens` — not a stateless
|
|
29
|
+
* JWT. A signed link would be replayable until it expired; a row can be
|
|
30
|
+
* claimed exactly once, by the conditional UPDATE that `redeemToken` in the
|
|
31
|
+
* framework uses for password resets.
|
|
32
|
+
*/
|
|
33
|
+
import { createHmac, createHash, randomBytes } from 'node:crypto';
|
|
34
|
+
import { signJwt, verifyJwt } from '@basicbenframework/core/auth';
|
|
35
|
+
import { appKey } from '@basicbenframework/core/server';
|
|
36
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
37
|
+
/** The audience a member session names. Checked on every read. */
|
|
38
|
+
export const MEMBER_AUDIENCE = 'basicben:member';
|
|
39
|
+
/** How long a member stays signed in. Readers expect "remember me", not a daily login. */
|
|
40
|
+
export const MEMBER_SESSION_TTL = '30d';
|
|
41
|
+
/** How long a magic link works. Long enough to find the mail; short enough to be useless later. */
|
|
42
|
+
export const MAGIC_LINK_TTL_MS = 60 * 60 * 1000;
|
|
43
|
+
/**
|
|
44
|
+
* The header a member session travels in on content reads.
|
|
45
|
+
*
|
|
46
|
+
* Not `Authorization`, because on `/api/v1` that header is already taken by
|
|
47
|
+
* the `content:read` token a front end authenticates *itself* with. The two
|
|
48
|
+
* are different parties — the site, and the reader using it — and a request
|
|
49
|
+
* routinely carries both. The member endpoints themselves accept either.
|
|
50
|
+
*/
|
|
51
|
+
export const MEMBER_HEADER = 'x-member-token';
|
|
52
|
+
function keyFor(purpose) {
|
|
53
|
+
return createHmac('sha256', appKey('member sessions'))
|
|
54
|
+
.update(`basicben.members.${purpose}`)
|
|
55
|
+
.digest('hex');
|
|
56
|
+
}
|
|
57
|
+
/** Mint a member session. */
|
|
58
|
+
export function issueMemberSession(member) {
|
|
59
|
+
return signJwt({ mid: Number(member.id), sv: Number(member.session_version ?? 0), aud: MEMBER_AUDIENCE }, keyFor('session'), { expiresIn: MEMBER_SESSION_TTL });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The claims of a member session, or null.
|
|
63
|
+
*
|
|
64
|
+
* Signature, expiry and audience. Whether the member still exists and the
|
|
65
|
+
* session has not been signed out is the caller's question — it needs the row.
|
|
66
|
+
*/
|
|
67
|
+
export function readMemberSession(token) {
|
|
68
|
+
if (typeof token !== 'string' || !token || token.startsWith('bb_'))
|
|
69
|
+
return null;
|
|
70
|
+
const payload = verifyJwt(token, keyFor('session'));
|
|
71
|
+
if (!payload || payload.aud !== MEMBER_AUDIENCE)
|
|
72
|
+
return null;
|
|
73
|
+
const mid = Number(payload.mid);
|
|
74
|
+
if (!Number.isInteger(mid) || mid <= 0)
|
|
75
|
+
return null;
|
|
76
|
+
return { mid, sv: Number(payload.sv ?? 0), aud: MEMBER_AUDIENCE };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A link that unsubscribes one member from newsletters.
|
|
80
|
+
*
|
|
81
|
+
* No expiry: an unsubscribe link has to work in a mail opened a year later,
|
|
82
|
+
* and the most it can do is stop mail — the same reasoning, and the same
|
|
83
|
+
* shape, as the comment reply unsubscribe in comment-guard.ts.
|
|
84
|
+
*/
|
|
85
|
+
export function issueMemberUnsubscribeToken(memberId) {
|
|
86
|
+
return signJwt({ m: Number(memberId) }, keyFor('unsubscribe'));
|
|
87
|
+
}
|
|
88
|
+
/** The member an unsubscribe token names, or null. */
|
|
89
|
+
export function readMemberUnsubscribeToken(token) {
|
|
90
|
+
if (typeof token !== 'string' || !token)
|
|
91
|
+
return null;
|
|
92
|
+
const payload = verifyJwt(token, keyFor('unsubscribe'));
|
|
93
|
+
const id = Number(payload?.m);
|
|
94
|
+
return Number.isInteger(id) && id > 0 ? id : null;
|
|
95
|
+
}
|
|
96
|
+
/** One normal form for an address, so the unique index means one mailbox. */
|
|
97
|
+
export function normalizeEmail(value) {
|
|
98
|
+
return String(value ?? '').trim().toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
const hash = (token) => createHash('sha256').update(token).digest('hex');
|
|
101
|
+
/**
|
|
102
|
+
* Issue a magic link for an address, revoking any earlier unused one.
|
|
103
|
+
*
|
|
104
|
+
* Only the newest link works — someone who asked twice and clicks the older
|
|
105
|
+
* mail should not be signed in by a link they may have forwarded.
|
|
106
|
+
*/
|
|
107
|
+
export async function issueMagicLink(payload) {
|
|
108
|
+
const db = await getDb();
|
|
109
|
+
const email = normalizeEmail(payload.email);
|
|
110
|
+
const now = new Date().toISOString();
|
|
111
|
+
await db.run('UPDATE member_tokens SET used_at = ? WHERE email = ? AND used_at IS NULL', [now, email]);
|
|
112
|
+
const token = randomBytes(32).toString('base64url');
|
|
113
|
+
await db.run(`INSERT INTO member_tokens (member_id, email, token_hash, metadata, expires_at, created_at)
|
|
114
|
+
VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
115
|
+
payload.memberId,
|
|
116
|
+
email,
|
|
117
|
+
hash(token),
|
|
118
|
+
payload.metadata ? JSON.stringify(payload.metadata) : null,
|
|
119
|
+
new Date(Date.now() + MAGIC_LINK_TTL_MS).toISOString(),
|
|
120
|
+
now
|
|
121
|
+
]);
|
|
122
|
+
return token;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Spend a magic link. Null for anything not currently valid.
|
|
126
|
+
*
|
|
127
|
+
* Unknown, expired and already-used are one answer: the caller has no safe
|
|
128
|
+
* use for the difference, and telling them apart helps only a guesser.
|
|
129
|
+
*/
|
|
130
|
+
export async function redeemMagicLink(token) {
|
|
131
|
+
if (typeof token !== 'string' || token.length < 20 || token.length > 200)
|
|
132
|
+
return null;
|
|
133
|
+
const db = await getDb();
|
|
134
|
+
const tokenHash = hash(token);
|
|
135
|
+
const now = new Date().toISOString();
|
|
136
|
+
// One conditional UPDATE: atomic on every driver, so two requests racing
|
|
137
|
+
// with the same link cannot both get a session.
|
|
138
|
+
const claim = await db.run('UPDATE member_tokens SET used_at = ? WHERE token_hash = ? AND used_at IS NULL AND expires_at > ?', [now, tokenHash, now]);
|
|
139
|
+
if (Number(claim?.changes ?? 0) !== 1)
|
|
140
|
+
return null;
|
|
141
|
+
const row = (await db.get('SELECT member_id, email, metadata FROM member_tokens WHERE token_hash = ?', [tokenHash]));
|
|
142
|
+
if (!row)
|
|
143
|
+
return null;
|
|
144
|
+
let metadata = null;
|
|
145
|
+
try {
|
|
146
|
+
metadata = row.metadata ? JSON.parse(row.metadata) : null;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
metadata = null;
|
|
150
|
+
}
|
|
151
|
+
return { memberId: row.member_id === null ? null : Number(row.member_id), email: row.email, metadata };
|
|
152
|
+
}
|
|
153
|
+
/** Delete links that can no longer be used. Called opportunistically by the newsletter cron. */
|
|
154
|
+
export async function pruneMagicLinks() {
|
|
155
|
+
const db = await getDb();
|
|
156
|
+
const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
|
|
157
|
+
await db.run('DELETE FROM member_tokens WHERE expires_at < ?', [cutoff]);
|
|
158
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The members feature's settings, added to core's allowlist at boot through
|
|
3
|
+
* `host.settings.define`.
|
|
4
|
+
*/
|
|
5
|
+
import { type SettingDefinition } from '../../helpers/site-settings.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Who may become a member. See MemberController.
|
|
8
|
+
*
|
|
9
|
+
* - `open`: anyone may sign up with a magic link.
|
|
10
|
+
* - `invite`: only addresses an admin added or imported may sign in.
|
|
11
|
+
* - `closed`: no magic links at all. Existing sessions run until they end.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MEMBER_SIGNUP_MODES: readonly ["open", "invite", "closed"];
|
|
14
|
+
export declare const MEMBER_SETTINGS: Record<string, SettingDefinition>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The members feature's settings, added to core's allowlist at boot through
|
|
3
|
+
* `host.settings.define`.
|
|
4
|
+
*/
|
|
5
|
+
import { checks } from "../../helpers/site-settings.js";
|
|
6
|
+
/**
|
|
7
|
+
* Who may become a member. See MemberController.
|
|
8
|
+
*
|
|
9
|
+
* - `open`: anyone may sign up with a magic link.
|
|
10
|
+
* - `invite`: only addresses an admin added or imported may sign in.
|
|
11
|
+
* - `closed`: no magic links at all. Existing sessions run until they end.
|
|
12
|
+
*/
|
|
13
|
+
export const MEMBER_SIGNUP_MODES = ['open', 'invite', 'closed'];
|
|
14
|
+
// The sign-in URL is the front-end page a magic link opens — a setting, not a
|
|
15
|
+
// request parameter, so a caller can never have a link (and the token in it)
|
|
16
|
+
// delivered to a page of their choosing.
|
|
17
|
+
export const MEMBER_SETTINGS = {
|
|
18
|
+
members_signup: { group: 'members', check: checks.oneOf(MEMBER_SIGNUP_MODES) },
|
|
19
|
+
members_signin_url: { group: 'members', check: checks.httpUrlOrBlank },
|
|
20
|
+
newsletter_sender_name: { group: 'members', check: checks.text(100) },
|
|
21
|
+
newsletter_reply_to: { group: 'members', check: checks.emailOrBlank },
|
|
22
|
+
newsletter_footer: { group: 'members', check: checks.text(2000) }
|
|
23
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SettingsSectionProps } from '../../client/host/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* MySendbox: where newsletters go, who is copied there, and the button that
|
|
4
|
+
* copies the members who aren't yet. Saved with the rest of Settings, except
|
|
5
|
+
* the copy, which runs at once.
|
|
6
|
+
*/
|
|
7
|
+
export default function MySendboxSettingsCard({ values, onChange }: SettingsSectionProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { api } from "../../helpers/api.js";
|
|
4
|
+
import { useT } from "../../client/i18n/index.js";
|
|
5
|
+
const hint = { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' };
|
|
6
|
+
/**
|
|
7
|
+
* MySendbox: where newsletters go, who is copied there, and the button that
|
|
8
|
+
* copies the members who aren't yet. Saved with the rest of Settings, except
|
|
9
|
+
* the copy, which runs at once.
|
|
10
|
+
*/
|
|
11
|
+
export default function MySendboxSettingsCard({ values, onChange }) {
|
|
12
|
+
const { t } = useT();
|
|
13
|
+
const [status, setStatus] = useState(null);
|
|
14
|
+
const [copying, setCopying] = useState(false);
|
|
15
|
+
const [message, setMessage] = useState('');
|
|
16
|
+
const load = () => api.get('/api/mysendbox/status').then(setStatus).catch(() => setStatus(null));
|
|
17
|
+
useEffect(() => { load(); }, []);
|
|
18
|
+
// Not set up, or not someone who manages members: say nothing.
|
|
19
|
+
if (!status?.configured)
|
|
20
|
+
return null;
|
|
21
|
+
const copy = async () => {
|
|
22
|
+
setCopying(true);
|
|
23
|
+
setMessage('');
|
|
24
|
+
try {
|
|
25
|
+
let copied = 0;
|
|
26
|
+
// One batch per request, so a large list fits a short function budget.
|
|
27
|
+
for (let i = 0; i < 200; i++) {
|
|
28
|
+
const res = await api.post('/api/mysendbox/backfill', {});
|
|
29
|
+
copied += res?.done?.synced ?? 0;
|
|
30
|
+
if (!res || res.remaining === 0)
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
setMessage(t('{count} member(s) copied.', { count: copied }));
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
setMessage(err.message || t('The copy stopped.'));
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
setCopying(false);
|
|
40
|
+
load();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const c = status.contacts;
|
|
44
|
+
const field = (key, label, help, type = 'text') => (_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: key, children: label }), type === 'textarea' ? (_jsx("textarea", { id: key, rows: 3, value: values[key] ?? '', onChange: e => onChange({ [key]: e.target.value }), className: "admin-input" })) : (_jsx("input", { id: key, type: type, value: values[key] ?? '', onChange: e => onChange({ [key]: e.target.value }), className: "admin-input" })), _jsx("p", { style: hint, children: help })] }));
|
|
45
|
+
return (_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Newsletters through MySendbox') }), _jsxs("p", { style: hint, children: [t('{synced} member(s) in MySendbox, {waiting} waiting for consent, {refused} refused.', {
|
|
46
|
+
synced: c.synced ?? 0, waiting: c.needs_consent ?? 0, refused: c.refused ?? 0
|
|
47
|
+
}), ' ', status.sendable !== null && t('A broadcast would reach {count} now.', { count: status.sendable }), !status.webhook && _jsxs(_Fragment, { children: [" ", t('No webhook secret: unsubscribes made in MySendbox arrive through the daily check.')] })] }), status.error && _jsx("p", { style: { ...hint, color: 'var(--danger, #b00)' }, children: status.error }), field('mysendbox_from_address', t('From address'), t("Blank uses your MySendbox workspace's default sender."), 'email'), field('mysendbox_from_name', t('From name'), t('Blank uses the newsletter sender name.')), field('mysendbox_consent_attestation', t('Consent for members you added or imported'), t('How they agreed to receive posts by email, in your words. MySendbox records it with each contact. Leave blank and they are not copied, unless a signup form is set.'), 'textarea'), field('mysendbox_form_id', t('Signup form (frm_…)'), t('Optional. Members without recorded consent are sent this form’s confirmation email instead.')), field('mysendbox_audience_id', t('Audience (aud_…)'), t('Made for you on first use. Change it only to use another MySendbox list.')), _jsxs("div", { className: "admin-form-group", children: [_jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", disabled: copying, onClick: copy, children: copying ? t('Copying…') : t('Copy members to MySendbox') }), _jsx("p", { style: hint, children: message || t('Copies every subscribed member not yet in MySendbox. Safe to run again. Save settings first if you changed consent.') })] }), status.problems.length > 0 && (_jsxs("details", { children: [_jsx("summary", { children: t('Members not copied ({count})', { count: status.problems.length }) }), _jsx("ul", { style: hint, children: status.problems.map(p => _jsxs("li", { children: ["#", p.member_id, " \u2014 ", p.last_error || p.state] }, p.member_id)) })] }))] }));
|
|
48
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import MySendboxSettingsCard from "./MySendboxSettingsCard.js";
|
|
2
|
+
const mysendbox = {
|
|
3
|
+
name: 'mysendbox',
|
|
4
|
+
register(admin) {
|
|
5
|
+
admin.fill('settings.reading', MySendboxSettingsCard);
|
|
6
|
+
admin.dictionaries({ es: () => import("./i18n/es.js") });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export default mysendbox;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A post's newsletter as a MySendbox broadcast.
|
|
3
|
+
*
|
|
4
|
+
* The members feature hands the send over through its strict
|
|
5
|
+
* `newsletter.delivering` filter (members/newsletter.ts, `handOffSend`): it
|
|
6
|
+
* has already claimed the send, so only one caller is here at a time, but a
|
|
7
|
+
* claim that was interrupted is retried. So each step is recorded before the
|
|
8
|
+
* next, and a retry picks up where the last attempt stopped:
|
|
9
|
+
*
|
|
10
|
+
* 1. Bring contacts up to date (members who joined since the last sync).
|
|
11
|
+
* 2. Create the broadcast, and record its id in `mysendbox_broadcasts` at
|
|
12
|
+
* once. MySendbox's broadcasts take no idempotency key, so this row is
|
|
13
|
+
* what stops a retry making a second one.
|
|
14
|
+
* 3. Schedule it now, unless it already is (a retry after step 3).
|
|
15
|
+
*
|
|
16
|
+
* A crash between creating the broadcast and recording it leaves one unsent
|
|
17
|
+
* draft in MySendbox: harmless, and visible in its dashboard. Nothing here
|
|
18
|
+
* can send a post twice.
|
|
19
|
+
*
|
|
20
|
+
* Any failure throws, which the strict filter turns into `handoff_failed`
|
|
21
|
+
* and a later retry. It never falls back to the built-in queue.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DELIVERING_HOOK = "newsletter.delivering";
|
|
24
|
+
export declare const STATUS_HOOK = "newsletter.status";
|
|
25
|
+
interface Delivering {
|
|
26
|
+
send: {
|
|
27
|
+
id: number;
|
|
28
|
+
post_id: number;
|
|
29
|
+
subject?: string | null;
|
|
30
|
+
};
|
|
31
|
+
post: {
|
|
32
|
+
id: number;
|
|
33
|
+
title: string;
|
|
34
|
+
excerpt?: string | null;
|
|
35
|
+
};
|
|
36
|
+
message: {
|
|
37
|
+
subject?: string;
|
|
38
|
+
html?: string;
|
|
39
|
+
text?: string;
|
|
40
|
+
from?: string;
|
|
41
|
+
replyTo?: string;
|
|
42
|
+
};
|
|
43
|
+
handledBy: string | null;
|
|
44
|
+
externalId: string | null;
|
|
45
|
+
}
|
|
46
|
+
export declare function deliverAsBroadcast(value: Delivering): Promise<Delivering>;
|
|
47
|
+
/** `newsletter.status`: what MySendbox says about a send it took. Never throws. */
|
|
48
|
+
export declare function describeSend(value: {
|
|
49
|
+
send?: {
|
|
50
|
+
provider?: string | null;
|
|
51
|
+
external_id?: string | null;
|
|
52
|
+
};
|
|
53
|
+
provider: unknown;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
send?: {
|
|
56
|
+
provider?: string | null;
|
|
57
|
+
external_id?: string | null;
|
|
58
|
+
};
|
|
59
|
+
provider: unknown;
|
|
60
|
+
}>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A post's newsletter as a MySendbox broadcast.
|
|
3
|
+
*
|
|
4
|
+
* The members feature hands the send over through its strict
|
|
5
|
+
* `newsletter.delivering` filter (members/newsletter.ts, `handOffSend`): it
|
|
6
|
+
* has already claimed the send, so only one caller is here at a time, but a
|
|
7
|
+
* claim that was interrupted is retried. So each step is recorded before the
|
|
8
|
+
* next, and a retry picks up where the last attempt stopped:
|
|
9
|
+
*
|
|
10
|
+
* 1. Bring contacts up to date (members who joined since the last sync).
|
|
11
|
+
* 2. Create the broadcast, and record its id in `mysendbox_broadcasts` at
|
|
12
|
+
* once. MySendbox's broadcasts take no idempotency key, so this row is
|
|
13
|
+
* what stops a retry making a second one.
|
|
14
|
+
* 3. Schedule it now, unless it already is (a retry after step 3).
|
|
15
|
+
*
|
|
16
|
+
* A crash between creating the broadcast and recording it leaves one unsent
|
|
17
|
+
* draft in MySendbox: harmless, and visible in its dashboard. Nothing here
|
|
18
|
+
* can send a post twice.
|
|
19
|
+
*
|
|
20
|
+
* Any failure throws, which the strict filter turns into `handoff_failed`
|
|
21
|
+
* and a later retry. It never falls back to the built-in queue.
|
|
22
|
+
*/
|
|
23
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
24
|
+
import { client, audienceId, setting } from "./config.js";
|
|
25
|
+
import { syncDirty, PROVIDER } from "./contacts.js";
|
|
26
|
+
export const DELIVERING_HOOK = 'newsletter.delivering';
|
|
27
|
+
export const STATUS_HOOK = 'newsletter.status';
|
|
28
|
+
/** The broadcast statuses after which MySendbox will not send it again. */
|
|
29
|
+
const UNDER_WAY = new Set(['scheduled', 'sending', 'paused', 'sent']);
|
|
30
|
+
/** `"Name" <address>` → its parts. */
|
|
31
|
+
function splitFrom(from) {
|
|
32
|
+
const match = /^\s*"?([^"<]*)"?\s*<([^>]+)>\s*$/.exec(from ?? '');
|
|
33
|
+
return match ? { name: match[1].trim() || null, address: match[2].trim() } : { name: null, address: from?.trim() || null };
|
|
34
|
+
}
|
|
35
|
+
export async function deliverAsBroadcast(value) {
|
|
36
|
+
// Another provider took it first: not ours.
|
|
37
|
+
if (!value || value.handledBy)
|
|
38
|
+
return value;
|
|
39
|
+
const db = await getDb();
|
|
40
|
+
const api = client();
|
|
41
|
+
// People who joined since the last sync should get this one too.
|
|
42
|
+
await syncDirty(500);
|
|
43
|
+
const audience = await audienceId();
|
|
44
|
+
const recorded = (await db.get('SELECT broadcast_id FROM mysendbox_broadcasts WHERE send_id = ?', [value.send.id]));
|
|
45
|
+
let broadcastId = recorded?.broadcast_id;
|
|
46
|
+
if (!broadcastId) {
|
|
47
|
+
const sender = splitFrom(value.message.from);
|
|
48
|
+
const fromAddress = (await setting('mysendbox_from_address')) || null;
|
|
49
|
+
const fromName = (await setting('mysendbox_from_name')) || sender.name;
|
|
50
|
+
const created = await api.createBroadcast({
|
|
51
|
+
name: `Post ${value.post.id}: ${value.post.title}`.slice(0, 200),
|
|
52
|
+
subject: String(value.message.subject ?? value.post.title).slice(0, 300),
|
|
53
|
+
preheader: value.post.excerpt ? String(value.post.excerpt).slice(0, 300) : null,
|
|
54
|
+
html: String(value.message.html ?? ''),
|
|
55
|
+
text: value.message.text ? String(value.message.text) : null,
|
|
56
|
+
audienceId: audience,
|
|
57
|
+
// Blank: the workspace's own default From in MySendbox.
|
|
58
|
+
...(fromAddress ? { fromAddress } : {}),
|
|
59
|
+
...(fromName ? { fromName } : {}),
|
|
60
|
+
...(value.message.replyTo ? { replyTo: String(value.message.replyTo) } : {})
|
|
61
|
+
});
|
|
62
|
+
if (!created.ok)
|
|
63
|
+
throw new Error(`MySendbox refused the broadcast: ${created.error}`);
|
|
64
|
+
if (!created.data?.id)
|
|
65
|
+
throw new Error('MySendbox did not return a broadcast id');
|
|
66
|
+
broadcastId = created.data.id;
|
|
67
|
+
await db.run('INSERT INTO mysendbox_broadcasts (send_id, broadcast_id, created_at) VALUES (?, ?, ?)', [
|
|
68
|
+
value.send.id,
|
|
69
|
+
broadcastId,
|
|
70
|
+
new Date().toISOString()
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
// A retry after it was scheduled: leave it be.
|
|
74
|
+
const current = recorded ? await api.getBroadcast(broadcastId) : null;
|
|
75
|
+
if (!current?.ok || !UNDER_WAY.has(current.data.status)) {
|
|
76
|
+
if (current?.ok && current.data.status === 'canceled') {
|
|
77
|
+
throw new Error('The broadcast was canceled in MySendbox; it will not be sent again from here.');
|
|
78
|
+
}
|
|
79
|
+
const scheduled = await api.scheduleNow(broadcastId);
|
|
80
|
+
if (!scheduled.ok)
|
|
81
|
+
throw new Error(`MySendbox would not start the broadcast: ${scheduled.error}`);
|
|
82
|
+
}
|
|
83
|
+
return { ...value, handledBy: PROVIDER, externalId: broadcastId };
|
|
84
|
+
}
|
|
85
|
+
/** The per-recipient states MySendbox counts; their sum is the broadcast's recipients. */
|
|
86
|
+
const RECIPIENT_STATES = ['queued', 'sending', 'sent', 'delivered', 'soft_bounced', 'bounced', 'complained', 'suppressed', 'skipped', 'failed', 'canceled'];
|
|
87
|
+
const STATUS_LABELS = {
|
|
88
|
+
draft: 'draft',
|
|
89
|
+
scheduled: 'scheduled',
|
|
90
|
+
sending: 'sending',
|
|
91
|
+
paused: 'paused',
|
|
92
|
+
sent: 'sent',
|
|
93
|
+
canceled: 'canceled'
|
|
94
|
+
};
|
|
95
|
+
/** `newsletter.status`: what MySendbox says about a send it took. Never throws. */
|
|
96
|
+
export async function describeSend(value) {
|
|
97
|
+
const send = value?.send;
|
|
98
|
+
if (!send || send.provider !== PROVIDER || !send.external_id)
|
|
99
|
+
return value;
|
|
100
|
+
const found = await client().getBroadcast(send.external_id).catch(() => null);
|
|
101
|
+
if (!found?.ok) {
|
|
102
|
+
return { ...value, provider: { name: 'MySendbox', status: 'unknown', done: false, note: 'MySendbox could not be reached for its counts.' } };
|
|
103
|
+
}
|
|
104
|
+
const stats = (found.data.stats ?? {});
|
|
105
|
+
const recipients = RECIPIENT_STATES.reduce((sum, key) => sum + (Number(stats[key]) || 0), 0);
|
|
106
|
+
const delivered = Number(stats.delivered) || 0;
|
|
107
|
+
return {
|
|
108
|
+
...value,
|
|
109
|
+
provider: {
|
|
110
|
+
name: 'MySendbox',
|
|
111
|
+
status: STATUS_LABELS[found.data.status] ?? found.data.status,
|
|
112
|
+
done: found.data.status === 'sent' || found.data.status === 'canceled',
|
|
113
|
+
counts: {
|
|
114
|
+
recipients,
|
|
115
|
+
delivered,
|
|
116
|
+
opened: Number(stats.opened) || 0,
|
|
117
|
+
clicked: Number(stats.clicked) || 0,
|
|
118
|
+
bounced: (Number(stats.bounced) || 0) + (Number(stats.soft_bounced) || 0),
|
|
119
|
+
unsubscribed: Number(stats.unsubscribed) || 0
|
|
120
|
+
},
|
|
121
|
+
note: 'MySendbox leaves out subscribers with no opens, clicks or new consent in six months.'
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small client for MySendbox's REST API (https://api.mysendbox.com/v1).
|
|
3
|
+
*
|
|
4
|
+
* Only the calls this feature makes. Every call answers a result rather than
|
|
5
|
+
* throwing, so callers decide what a failure means: a 4xx is MySendbox saying
|
|
6
|
+
* no (not worth retrying until something changes), a 5xx, 429 or network
|
|
7
|
+
* error is MySendbox being unavailable (retry later).
|
|
8
|
+
*
|
|
9
|
+
* `fetch` and the base URL are injectable, so tests run against a fake.
|
|
10
|
+
*/
|
|
11
|
+
export type Result<T> = {
|
|
12
|
+
ok: true;
|
|
13
|
+
status: number;
|
|
14
|
+
data: T;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
status: number;
|
|
18
|
+
error: string;
|
|
19
|
+
code?: string;
|
|
20
|
+
retry: boolean;
|
|
21
|
+
};
|
|
22
|
+
export interface ContactRecord {
|
|
23
|
+
id: string;
|
|
24
|
+
email: string;
|
|
25
|
+
status: 'subscribed' | 'pending' | 'unsubscribed' | 'bounced' | 'complained' | 'cleaned';
|
|
26
|
+
attributes?: Record<string, unknown>;
|
|
27
|
+
audienceIds?: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface BroadcastRecord {
|
|
30
|
+
id: string;
|
|
31
|
+
status: 'draft' | 'scheduled' | 'sending' | 'paused' | 'sent' | 'canceled';
|
|
32
|
+
stats?: Record<string, number | boolean>;
|
|
33
|
+
}
|
|
34
|
+
export interface ClientOptions {
|
|
35
|
+
apiKey: string;
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
fetch?: typeof fetch;
|
|
38
|
+
}
|
|
39
|
+
export declare const DEFAULT_BASE_URL = "https://api.mysendbox.com/v1";
|
|
40
|
+
export declare function createClient({ apiKey, baseUrl, fetch: fetchImpl }: ClientOptions): {
|
|
41
|
+
createAudience: (name: string) => Promise<Result<{
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
}>>;
|
|
45
|
+
listAudiences: () => Promise<Result<{
|
|
46
|
+
audiences: Array<{
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
}>;
|
|
50
|
+
}>>;
|
|
51
|
+
/** Add or update by email. 201 new, 200 existing; 409 for someone who unsubscribed or was erased. */
|
|
52
|
+
upsertContact: (contact: {
|
|
53
|
+
email: string;
|
|
54
|
+
name?: string | null;
|
|
55
|
+
audienceIds?: string[];
|
|
56
|
+
attributes?: Record<string, unknown>;
|
|
57
|
+
consent: string;
|
|
58
|
+
confirmed: boolean;
|
|
59
|
+
}) => Promise<Result<ContactRecord>>;
|
|
60
|
+
unsubscribeContact: (id: string, note?: string) => Promise<Result<unknown>>;
|
|
61
|
+
eraseContact: (id: string) => Promise<Result<{
|
|
62
|
+
deleted: boolean;
|
|
63
|
+
}>>;
|
|
64
|
+
/** A signup form's double opt-in: MySendbox sends the confirmation mail. */
|
|
65
|
+
subscribeThroughForm: (formId: string, person: {
|
|
66
|
+
email: string;
|
|
67
|
+
name?: string | null;
|
|
68
|
+
}) => Promise<Result<{
|
|
69
|
+
contact?: ContactRecord;
|
|
70
|
+
confirmationSent?: boolean;
|
|
71
|
+
}>>;
|
|
72
|
+
listContacts: (query: Record<string, string | undefined>) => Promise<Result<{
|
|
73
|
+
contacts: ContactRecord[];
|
|
74
|
+
next: string | null;
|
|
75
|
+
}>>;
|
|
76
|
+
createBroadcast: (broadcast: {
|
|
77
|
+
name: string;
|
|
78
|
+
subject: string;
|
|
79
|
+
preheader?: string | null;
|
|
80
|
+
html: string;
|
|
81
|
+
text?: string | null;
|
|
82
|
+
audienceId?: string | null;
|
|
83
|
+
fromAddress?: string | null;
|
|
84
|
+
fromName?: string | null;
|
|
85
|
+
replyTo?: string | null;
|
|
86
|
+
}) => Promise<Result<BroadcastRecord>>;
|
|
87
|
+
scheduleNow: (id: string) => Promise<Result<BroadcastRecord>>;
|
|
88
|
+
getBroadcast: (id: string) => Promise<Result<BroadcastRecord>>;
|
|
89
|
+
sendableCount: (audienceId: string) => Promise<Result<{
|
|
90
|
+
total: number;
|
|
91
|
+
subscribed: number;
|
|
92
|
+
sendable: number;
|
|
93
|
+
}>>;
|
|
94
|
+
};
|
|
95
|
+
export type MySendboxClient = ReturnType<typeof createClient>;
|