@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,19 @@
|
|
|
1
|
+
import type { Request, Response } from '../../types/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Cookieless page-view counting. The privacy model is in this folder's README.md.
|
|
4
|
+
*/
|
|
5
|
+
export declare const AnalyticsController: {
|
|
6
|
+
/**
|
|
7
|
+
* `POST /api/v1/analytics/hit` — `{ path, referrer? }`, from any origin.
|
|
8
|
+
*
|
|
9
|
+
* Public, like posting a comment, because the reader's browser is the
|
|
10
|
+
* caller and it has no credential to send. It answers 204 whether or not
|
|
11
|
+
* the hit was counted — a bot, an opt-out and a disabled site all look the
|
|
12
|
+
* same from outside, so the response tells a scraper nothing — and 400 only
|
|
13
|
+
* for a request that could never be counted, which is a front end's bug
|
|
14
|
+
* worth surfacing while it is being built.
|
|
15
|
+
*/
|
|
16
|
+
hit(req: Request, res: Response): Promise<void>;
|
|
17
|
+
/** `GET /api/admin/analytics?days=7|30|90` */
|
|
18
|
+
summary(req: Request, res: Response): Promise<void>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { clientIp } from "../../middleware/rate-limits.js";
|
|
2
|
+
import { normalizeAnalyticsPath, referrerDomain, hostOf, isBot, optedOut, parseHitBody } from "./helpers.js";
|
|
3
|
+
import { recordHit, summary, analyticsSettings, purgeOpportunistically } from "./model.js";
|
|
4
|
+
/** The ranges the admin offers. Anything else is refused, not clamped. */
|
|
5
|
+
const RANGES = [7, 30, 90];
|
|
6
|
+
/** 204 with nothing to cache: a hit is never a resource. */
|
|
7
|
+
function accepted(res) {
|
|
8
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
9
|
+
res.status(204).end();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Cookieless page-view counting. The privacy model is in this folder's README.md.
|
|
13
|
+
*/
|
|
14
|
+
export const AnalyticsController = {
|
|
15
|
+
/**
|
|
16
|
+
* `POST /api/v1/analytics/hit` — `{ path, referrer? }`, from any origin.
|
|
17
|
+
*
|
|
18
|
+
* Public, like posting a comment, because the reader's browser is the
|
|
19
|
+
* caller and it has no credential to send. It answers 204 whether or not
|
|
20
|
+
* the hit was counted — a bot, an opt-out and a disabled site all look the
|
|
21
|
+
* same from outside, so the response tells a scraper nothing — and 400 only
|
|
22
|
+
* for a request that could never be counted, which is a front end's bug
|
|
23
|
+
* worth surfacing while it is being built.
|
|
24
|
+
*/
|
|
25
|
+
async hit(req, res) {
|
|
26
|
+
const body = parseHitBody(req.body);
|
|
27
|
+
const path = normalizeAnalyticsPath(body.path);
|
|
28
|
+
if (!path) {
|
|
29
|
+
return res.json({ error: 'path must be a path starting with / (or an http(s) URL)' }, 400);
|
|
30
|
+
}
|
|
31
|
+
// Opt-outs and bots are not counted at all — not counted and discarded,
|
|
32
|
+
// not counted: nothing about the request is written.
|
|
33
|
+
if (optedOut(req.headers) || isBot(req.headers['user-agent']))
|
|
34
|
+
return accepted(res);
|
|
35
|
+
try {
|
|
36
|
+
const settings = await analyticsSettings();
|
|
37
|
+
if (!settings.enabled)
|
|
38
|
+
return accepted(res);
|
|
39
|
+
const ownHosts = [
|
|
40
|
+
hostOf(process.env.SITE_URL),
|
|
41
|
+
hostOf(process.env.APP_URL),
|
|
42
|
+
hostOf(req.headers.origin),
|
|
43
|
+
hostOf(body.path)
|
|
44
|
+
].filter((h) => Boolean(h));
|
|
45
|
+
await recordHit({
|
|
46
|
+
path,
|
|
47
|
+
referrer: referrerDomain(body.referrer, ownHosts),
|
|
48
|
+
address: clientIp(req),
|
|
49
|
+
userAgent: String(req.headers['user-agent'] ?? ''),
|
|
50
|
+
pepper: process.env.APP_KEY ?? ''
|
|
51
|
+
});
|
|
52
|
+
await purgeOpportunistically();
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
// A failed count is not the reader's problem, and their page has long
|
|
56
|
+
// since moved on. Logged without the request: no address in the logs.
|
|
57
|
+
console.error('[analytics] hit not recorded:', err.message);
|
|
58
|
+
}
|
|
59
|
+
accepted(res);
|
|
60
|
+
},
|
|
61
|
+
/** `GET /api/admin/analytics?days=7|30|90` */
|
|
62
|
+
async summary(req, res) {
|
|
63
|
+
const days = req.query.days === undefined ? 30 : Number(req.query.days);
|
|
64
|
+
if (!RANGES.includes(days)) {
|
|
65
|
+
return res.json({ errors: { days: [`Must be one of ${RANGES.join(', ')}`] } }, 422);
|
|
66
|
+
}
|
|
67
|
+
// A quiet site still forgets on time when its admin looks at the page.
|
|
68
|
+
await purgeOpportunistically();
|
|
69
|
+
const [data, settings] = await Promise.all([summary({ days }), analyticsSettings()]);
|
|
70
|
+
res.json({
|
|
71
|
+
data,
|
|
72
|
+
settings: {
|
|
73
|
+
analytics_enabled: settings.enabled,
|
|
74
|
+
analytics_dedup_hours: settings.dedupHours,
|
|
75
|
+
analytics_retention_days: settings.retentionDays
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of page-view analytics: what counts as a page, a referrer, a
|
|
3
|
+
* bot and an opt-out, and how a visitor becomes an unlinkable hash.
|
|
4
|
+
*
|
|
5
|
+
* The privacy model is in src/features/analytics/README.md and migration 036. Everything
|
|
6
|
+
* here is a function of its arguments — no database, no environment — so the
|
|
7
|
+
* rules a privacy review cares about are tested directly.
|
|
8
|
+
*/
|
|
9
|
+
/** Longest path kept. Anything longer is almost certainly not a page. */
|
|
10
|
+
export declare const MAX_PATH_LENGTH = 300;
|
|
11
|
+
/**
|
|
12
|
+
* The page a hit is for, as a stable key: a path with a leading slash, no
|
|
13
|
+
* query string, no fragment, no trailing slash, no doubled slashes.
|
|
14
|
+
*
|
|
15
|
+
* The query is dropped on purpose rather than for tidiness: it is where
|
|
16
|
+
* tracking parameters, search terms, email addresses in a "confirm
|
|
17
|
+
* subscription" link and password-reset tokens live, and none of that belongs
|
|
18
|
+
* in a table that is kept indefinitely.
|
|
19
|
+
*
|
|
20
|
+
* A full http(s) URL is accepted and reduced to its path, because
|
|
21
|
+
* `location.href` is the obvious thing for a front end to send. Anything else —
|
|
22
|
+
* another scheme, a protocol-relative `//host`, whitespace or control
|
|
23
|
+
* characters — is refused, since it can only be a mistake or garbage.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeAnalyticsPath(input: unknown): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* The referring site as a bare host name (`news.ycombinator.com`), or null.
|
|
28
|
+
*
|
|
29
|
+
* Only the domain is kept, never the URL: a full referrer can carry a search
|
|
30
|
+
* query, a session id or a link to someone's private document. A leading
|
|
31
|
+
* `www.` is dropped so one site does not appear twice. The site's own hosts
|
|
32
|
+
* are not referrers — moving between its own pages is not traffic arriving.
|
|
33
|
+
*/
|
|
34
|
+
export declare function referrerDomain(input: unknown, ownHosts?: string[]): string | null;
|
|
35
|
+
/** The host of a URL, or null — for building the `ownHosts` list. */
|
|
36
|
+
export declare function hostOf(url: unknown): string | null;
|
|
37
|
+
export declare function isBot(userAgent: unknown): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the browser has asked not to be tracked.
|
|
40
|
+
*
|
|
41
|
+
* Do Not Track is deprecated in browsers but still sent by people who turned
|
|
42
|
+
* it on; Global Privacy Control (`Sec-GPC: 1`) is its successor with legal
|
|
43
|
+
* weight in some jurisdictions. Either is honoured by not counting at all —
|
|
44
|
+
* the counts are anonymous, but "not tracked" should not need a lawyer to
|
|
45
|
+
* interpret.
|
|
46
|
+
*/
|
|
47
|
+
export declare function optedOut(headers: Record<string, unknown>): boolean;
|
|
48
|
+
/** A date's UTC day as `YYYY-MM-DD`, the key every analytics table uses. */
|
|
49
|
+
export declare function utcDay(date?: Date): string;
|
|
50
|
+
/** The UTC day `n` days before `date`. */
|
|
51
|
+
export declare function daysBefore(date: Date, n: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* One visitor, for one day, as an opaque string.
|
|
54
|
+
*
|
|
55
|
+
* `scope` is empty for "this visitor, anywhere on the site" and the path for
|
|
56
|
+
* "this visitor, on this page". Hashing the path in, rather than storing it
|
|
57
|
+
* beside the hash, is what keeps the rows of one visitor from being grouped
|
|
58
|
+
* into a browsing trail: two pages by the same person are two unrelated
|
|
59
|
+
* strings. Truncated to 128 bits — collisions at a blog's scale are not a
|
|
60
|
+
* concern, and a shorter value is less of an identifier.
|
|
61
|
+
*/
|
|
62
|
+
export declare function visitorHash(salt: string, address: string, userAgent: string, scope?: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* The body of a hit, whatever shape it arrived in.
|
|
65
|
+
*
|
|
66
|
+
* `navigator.sendBeacon` with a string body sends `text/plain`, which is what
|
|
67
|
+
* makes it a "simple" request a browser will send cross-origin without a
|
|
68
|
+
* preflight — and the body parser leaves text/plain as a raw string. So both a
|
|
69
|
+
* parsed object and a JSON string are accepted.
|
|
70
|
+
*/
|
|
71
|
+
export declare function parseHitBody(body: unknown): {
|
|
72
|
+
path?: unknown;
|
|
73
|
+
referrer?: unknown;
|
|
74
|
+
};
|
|
75
|
+
/** A day-by-day series, with days that had no rows filled in as zero. */
|
|
76
|
+
export declare function fillSeries(rows: Array<{
|
|
77
|
+
day: string;
|
|
78
|
+
views: number;
|
|
79
|
+
visitors: number;
|
|
80
|
+
}>, days: number, now?: Date): Array<{
|
|
81
|
+
day: string;
|
|
82
|
+
views: number;
|
|
83
|
+
visitors: number;
|
|
84
|
+
}>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of page-view analytics: what counts as a page, a referrer, a
|
|
3
|
+
* bot and an opt-out, and how a visitor becomes an unlinkable hash.
|
|
4
|
+
*
|
|
5
|
+
* The privacy model is in src/features/analytics/README.md and migration 036. Everything
|
|
6
|
+
* here is a function of its arguments — no database, no environment — so the
|
|
7
|
+
* rules a privacy review cares about are tested directly.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
/** Longest path kept. Anything longer is almost certainly not a page. */
|
|
11
|
+
export const MAX_PATH_LENGTH = 300;
|
|
12
|
+
/**
|
|
13
|
+
* The page a hit is for, as a stable key: a path with a leading slash, no
|
|
14
|
+
* query string, no fragment, no trailing slash, no doubled slashes.
|
|
15
|
+
*
|
|
16
|
+
* The query is dropped on purpose rather than for tidiness: it is where
|
|
17
|
+
* tracking parameters, search terms, email addresses in a "confirm
|
|
18
|
+
* subscription" link and password-reset tokens live, and none of that belongs
|
|
19
|
+
* in a table that is kept indefinitely.
|
|
20
|
+
*
|
|
21
|
+
* A full http(s) URL is accepted and reduced to its path, because
|
|
22
|
+
* `location.href` is the obvious thing for a front end to send. Anything else —
|
|
23
|
+
* another scheme, a protocol-relative `//host`, whitespace or control
|
|
24
|
+
* characters — is refused, since it can only be a mistake or garbage.
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeAnalyticsPath(input) {
|
|
27
|
+
if (typeof input !== 'string')
|
|
28
|
+
return null;
|
|
29
|
+
let value = input.trim();
|
|
30
|
+
if (value === '' || value.length > 2048)
|
|
31
|
+
return null;
|
|
32
|
+
if (/^https?:\/\//i.test(value)) {
|
|
33
|
+
try {
|
|
34
|
+
value = new URL(value).pathname;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!value.startsWith('/') || value.startsWith('//'))
|
|
41
|
+
return null;
|
|
42
|
+
value = value.replace(/[?#].*$/s, '');
|
|
43
|
+
// Control characters and whitespace: never part of a real path, and a way to
|
|
44
|
+
// make one "page" look like many.
|
|
45
|
+
if (/[\u0000- \u007f]/.test(value))
|
|
46
|
+
return null;
|
|
47
|
+
value = value.replace(/\/{2,}/g, '/');
|
|
48
|
+
if (value.length > 1)
|
|
49
|
+
value = value.replace(/\/+$/, '');
|
|
50
|
+
if (value.length > MAX_PATH_LENGTH)
|
|
51
|
+
return null;
|
|
52
|
+
return value || '/';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The referring site as a bare host name (`news.ycombinator.com`), or null.
|
|
56
|
+
*
|
|
57
|
+
* Only the domain is kept, never the URL: a full referrer can carry a search
|
|
58
|
+
* query, a session id or a link to someone's private document. A leading
|
|
59
|
+
* `www.` is dropped so one site does not appear twice. The site's own hosts
|
|
60
|
+
* are not referrers — moving between its own pages is not traffic arriving.
|
|
61
|
+
*/
|
|
62
|
+
export function referrerDomain(input, ownHosts = []) {
|
|
63
|
+
if (typeof input !== 'string' || input === '' || input.length > 2048)
|
|
64
|
+
return null;
|
|
65
|
+
let url;
|
|
66
|
+
try {
|
|
67
|
+
url = new URL(input);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
73
|
+
return null;
|
|
74
|
+
const host = url.hostname.toLowerCase().replace(/^www\./, '').replace(/\.$/, '');
|
|
75
|
+
if (!host || host.length > 253 || !/^[a-z0-9.-]+$/.test(host))
|
|
76
|
+
return null;
|
|
77
|
+
const own = new Set(ownHosts.filter(Boolean).map((h) => h.toLowerCase().replace(/^www\./, '')));
|
|
78
|
+
if (own.has(host))
|
|
79
|
+
return null;
|
|
80
|
+
return host;
|
|
81
|
+
}
|
|
82
|
+
/** The host of a URL, or null — for building the `ownHosts` list. */
|
|
83
|
+
export function hostOf(url) {
|
|
84
|
+
if (typeof url !== 'string' || !url)
|
|
85
|
+
return null;
|
|
86
|
+
try {
|
|
87
|
+
return new URL(url).hostname.toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Crawlers, monitors, link unfurlers and HTTP libraries.
|
|
95
|
+
*
|
|
96
|
+
* A heuristic, like every bot filter, and tuned to fail towards not counting:
|
|
97
|
+
* an empty user agent is a bot, because no browser sends one. A determined
|
|
98
|
+
* fake will get through — the rate limit is what bounds that.
|
|
99
|
+
*/
|
|
100
|
+
const BOT_UA = new RegExp([
|
|
101
|
+
'bot\\b', 'bot/', 'crawl', 'spider', 'slurp', 'mediapartners', 'facebookexternalhit', 'embedly',
|
|
102
|
+
'preview', 'headless', 'lighthouse', 'pagespeed', 'phantomjs', 'puppeteer', 'playwright', 'selenium',
|
|
103
|
+
'curl/', 'wget/', 'python-requests', 'python-urllib', 'aiohttp', 'httpx', 'go-http-client',
|
|
104
|
+
'java/', 'okhttp', 'axios/', 'node-fetch', 'undici', 'libwww', 'httpclient', 'scrapy',
|
|
105
|
+
'uptime', 'pingdom', 'monitor', 'statuscake', 'feedfetcher', 'feedly', 'validator', 'archive.org'
|
|
106
|
+
].join('|'), 'i');
|
|
107
|
+
export function isBot(userAgent) {
|
|
108
|
+
if (typeof userAgent !== 'string' || userAgent.trim() === '')
|
|
109
|
+
return true;
|
|
110
|
+
return BOT_UA.test(userAgent);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Whether the browser has asked not to be tracked.
|
|
114
|
+
*
|
|
115
|
+
* Do Not Track is deprecated in browsers but still sent by people who turned
|
|
116
|
+
* it on; Global Privacy Control (`Sec-GPC: 1`) is its successor with legal
|
|
117
|
+
* weight in some jurisdictions. Either is honoured by not counting at all —
|
|
118
|
+
* the counts are anonymous, but "not tracked" should not need a lawyer to
|
|
119
|
+
* interpret.
|
|
120
|
+
*/
|
|
121
|
+
export function optedOut(headers) {
|
|
122
|
+
return String(headers['dnt'] ?? '').trim() === '1' || String(headers['sec-gpc'] ?? '').trim() === '1';
|
|
123
|
+
}
|
|
124
|
+
/** A date's UTC day as `YYYY-MM-DD`, the key every analytics table uses. */
|
|
125
|
+
export function utcDay(date = new Date()) {
|
|
126
|
+
return date.toISOString().slice(0, 10);
|
|
127
|
+
}
|
|
128
|
+
/** The UTC day `n` days before `date`. */
|
|
129
|
+
export function daysBefore(date, n) {
|
|
130
|
+
return utcDay(new Date(date.getTime() - n * 86_400_000));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* One visitor, for one day, as an opaque string.
|
|
134
|
+
*
|
|
135
|
+
* `scope` is empty for "this visitor, anywhere on the site" and the path for
|
|
136
|
+
* "this visitor, on this page". Hashing the path in, rather than storing it
|
|
137
|
+
* beside the hash, is what keeps the rows of one visitor from being grouped
|
|
138
|
+
* into a browsing trail: two pages by the same person are two unrelated
|
|
139
|
+
* strings. Truncated to 128 bits — collisions at a blog's scale are not a
|
|
140
|
+
* concern, and a shorter value is less of an identifier.
|
|
141
|
+
*/
|
|
142
|
+
export function visitorHash(salt, address, userAgent, scope = '') {
|
|
143
|
+
return createHash('sha256')
|
|
144
|
+
.update(salt).update('\0')
|
|
145
|
+
.update(address).update('\0')
|
|
146
|
+
.update(userAgent).update('\0')
|
|
147
|
+
.update(scope)
|
|
148
|
+
.digest('hex')
|
|
149
|
+
.slice(0, 32);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The body of a hit, whatever shape it arrived in.
|
|
153
|
+
*
|
|
154
|
+
* `navigator.sendBeacon` with a string body sends `text/plain`, which is what
|
|
155
|
+
* makes it a "simple" request a browser will send cross-origin without a
|
|
156
|
+
* preflight — and the body parser leaves text/plain as a raw string. So both a
|
|
157
|
+
* parsed object and a JSON string are accepted.
|
|
158
|
+
*/
|
|
159
|
+
export function parseHitBody(body) {
|
|
160
|
+
if (typeof body === 'string') {
|
|
161
|
+
try {
|
|
162
|
+
const parsed = JSON.parse(body);
|
|
163
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return body && typeof body === 'object' ? body : {};
|
|
170
|
+
}
|
|
171
|
+
/** A day-by-day series, with days that had no rows filled in as zero. */
|
|
172
|
+
export function fillSeries(rows, days, now = new Date()) {
|
|
173
|
+
const byDay = new Map(rows.map((row) => [row.day, row]));
|
|
174
|
+
const out = [];
|
|
175
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
176
|
+
const day = daysBefore(now, i);
|
|
177
|
+
const row = byDay.get(day);
|
|
178
|
+
out.push({ day, views: Number(row?.views ?? 0), visitors: Number(row?.visitors ?? 0) });
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Spanish for the analytics feature. Merged over the admin's own dictionary. */
|
|
2
|
+
const strings = {
|
|
3
|
+
"{count} day|{count} days": { "one": "{count} día", "other": "{count} días" },
|
|
4
|
+
"{count} view|{count} views": { "one": "{count} visita", "other": "{count} visitas" },
|
|
5
|
+
"{count} visitor|{count} visitors": { "one": "{count} visitante", "other": "{count} visitantes" },
|
|
6
|
+
"Saved.": "Guardado.",
|
|
7
|
+
"Analytics": "Analítica",
|
|
8
|
+
"Range": "Intervalo",
|
|
9
|
+
"Page views": "Páginas vistas",
|
|
10
|
+
"Daily visitors, summed": "Visitantes diarios, sumados",
|
|
11
|
+
"Views per day": "Visitas por día",
|
|
12
|
+
"{from} to {to} (UTC)": "Del {from} al {to} (UTC)",
|
|
13
|
+
"Views": "Visitas",
|
|
14
|
+
"Visitors": "Visitantes",
|
|
15
|
+
"Top pages": "Páginas principales",
|
|
16
|
+
"No page views yet.": "Aún no hay páginas vistas.",
|
|
17
|
+
"Path": "Ruta",
|
|
18
|
+
"Top referrers": "Principales referentes",
|
|
19
|
+
"No referred visits yet.": "Aún no hay visitas referidas.",
|
|
20
|
+
"Domain": "Dominio",
|
|
21
|
+
"How this is counted": "Cómo se cuenta",
|
|
22
|
+
"No cookies, no stored IP addresses or user agents. A visitor is a hash of their address, browser and a random salt that changes every UTC day and is then deleted, so nobody — including you — can tell who visited, or link one day's visitors to the next. Browsers sending Do Not Track or Global Privacy Control are not counted at all, and neither are known bots.": "Sin cookies, sin direcciones IP ni agentes de usuario almacenados. Un visitante es un hash de su dirección, su navegador y una sal aleatoria que cambia cada día UTC y después se elimina, así que nadie —ni siquiera tú— puede saber quién visitó el sitio ni relacionar los visitantes de un día con los del siguiente. Los navegadores que envían Do Not Track o Global Privacy Control no se cuentan en absoluto, ni tampoco los bots conocidos.",
|
|
23
|
+
"Your front end reports page views with a short snippet: {endpoint}. See {doc}.": "Tu front end informa de las páginas vistas con un fragmento breve: {endpoint}. Consulta {doc}.",
|
|
24
|
+
"Count page views": "Contar páginas vistas",
|
|
25
|
+
"Forget visitor hashes after (hours, 1–24)": "Olvidar los hashes de visitantes tras (horas, 1–24)",
|
|
26
|
+
"Keep daily counts for (days, 0 = forever)": "Conservar los recuentos diarios durante (días, 0 = siempre)",
|
|
27
|
+
"Save": "Guardar",
|
|
28
|
+
"Views and visitors per day": "Visitas y visitantes por día",
|
|
29
|
+
"{day}: {views}, {visitors}": "{day}: {views}, {visitors}"
|
|
30
|
+
};
|
|
31
|
+
export default strings;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookieless page-view analytics, as a feature.
|
|
3
|
+
*
|
|
4
|
+
* Remove this folder and its lines in src/features.ts, src/client/features.ts
|
|
5
|
+
* and src/features.manifest.ts, and the core runs without it. Its tables
|
|
6
|
+
* (migration 036) stay, empty and harmless. How the counting works and what
|
|
7
|
+
* it never stores: README.md.
|
|
8
|
+
*/
|
|
9
|
+
import type { Feature } from '../../host/index.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Page-view hits from anyone (`POST /api/v1/analytics/hit`).
|
|
12
|
+
*
|
|
13
|
+
* The analytics promise is that no address is stored, and the limiter's own
|
|
14
|
+
* table would otherwise be the exception: its key is normally the address in
|
|
15
|
+
* the clear. So this one keys on a hash of it, with APP_KEY mixed in so the
|
|
16
|
+
* key cannot be reversed by hashing every IPv4 address. The row still lives
|
|
17
|
+
* only as long as the limiter's window, like every other.
|
|
18
|
+
*
|
|
19
|
+
* Generous — a reader opening tabs, or an office behind one NAT, is a lot of
|
|
20
|
+
* page views a minute — because its job is bounding garbage, not policing
|
|
21
|
+
* readers.
|
|
22
|
+
*/
|
|
23
|
+
export declare const analyticsHitLimit: Function & {
|
|
24
|
+
limiter: import("@basicbenframework/core/rate-limit").Limiter;
|
|
25
|
+
key: (req: any) => string | null | undefined;
|
|
26
|
+
};
|
|
27
|
+
declare const analytics: Feature;
|
|
28
|
+
export default analytics;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookieless page-view analytics, as a feature.
|
|
3
|
+
*
|
|
4
|
+
* Remove this folder and its lines in src/features.ts, src/client/features.ts
|
|
5
|
+
* and src/features.manifest.ts, and the core runs without it. Its tables
|
|
6
|
+
* (migration 036) stay, empty and harmless. How the counting works and what
|
|
7
|
+
* it never stores: README.md.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
import { rateLimit } from '@basicbenframework/core/rate-limit';
|
|
11
|
+
import { requireCapability } from '@basicbenframework/core/auth/permissions';
|
|
12
|
+
import { auth } from "../../middleware/auth.js";
|
|
13
|
+
import { store, clientIp } from "../../middleware/rate-limits.js";
|
|
14
|
+
import { checks } from "../../helpers/site-settings.js";
|
|
15
|
+
import { check } from "../../helpers/health.js";
|
|
16
|
+
import { AnalyticsController } from "./controller.js";
|
|
17
|
+
import { purge } from "./model.js";
|
|
18
|
+
/**
|
|
19
|
+
* Page-view hits from anyone (`POST /api/v1/analytics/hit`).
|
|
20
|
+
*
|
|
21
|
+
* The analytics promise is that no address is stored, and the limiter's own
|
|
22
|
+
* table would otherwise be the exception: its key is normally the address in
|
|
23
|
+
* the clear. So this one keys on a hash of it, with APP_KEY mixed in so the
|
|
24
|
+
* key cannot be reversed by hashing every IPv4 address. The row still lives
|
|
25
|
+
* only as long as the limiter's window, like every other.
|
|
26
|
+
*
|
|
27
|
+
* Generous — a reader opening tabs, or an office behind one NAT, is a lot of
|
|
28
|
+
* page views a minute — because its job is bounding garbage, not policing
|
|
29
|
+
* readers.
|
|
30
|
+
*/
|
|
31
|
+
export const analyticsHitLimit = rateLimit({
|
|
32
|
+
limit: 120,
|
|
33
|
+
window: '1m',
|
|
34
|
+
blockFor: '5m',
|
|
35
|
+
store,
|
|
36
|
+
key: (req) => {
|
|
37
|
+
const ip = clientIp(req);
|
|
38
|
+
if (!ip)
|
|
39
|
+
return null;
|
|
40
|
+
const hashed = createHash('sha256').update(`${process.env.APP_KEY ?? ''}\0analytics\0${ip}`).digest('hex').slice(0, 32);
|
|
41
|
+
return `analytics:${hashed}`;
|
|
42
|
+
},
|
|
43
|
+
message: 'Too many requests.'
|
|
44
|
+
});
|
|
45
|
+
const analytics = {
|
|
46
|
+
name: 'analytics',
|
|
47
|
+
register(host) {
|
|
48
|
+
host.settings.define({
|
|
49
|
+
// Unset means on: the ingest endpoint does nothing until a front end
|
|
50
|
+
// calls it anyway.
|
|
51
|
+
analytics_enabled: { group: 'analytics', check: checks.flag },
|
|
52
|
+
// How long a visitor hash may live, in hours. Hashes are deleted when
|
|
53
|
+
// their UTC day ends regardless (the day's salt goes with it), so more
|
|
54
|
+
// than 24 buys nothing; less trades accuracy for holding even
|
|
55
|
+
// pseudonymous data for a shorter time.
|
|
56
|
+
analytics_dedup_hours: { group: 'analytics', check: checks.integer(1, 24) },
|
|
57
|
+
// Days of daily counts to keep. 0 keeps them indefinitely: they are
|
|
58
|
+
// counts, not personal data.
|
|
59
|
+
analytics_retention_days: { group: 'analytics', check: checks.integer(0, 3650) }
|
|
60
|
+
});
|
|
61
|
+
host.routes((router) => {
|
|
62
|
+
// Counts, not people, so editors may read them too. Changing the
|
|
63
|
+
// settings goes through PUT /api/settings, which is settings.manage.
|
|
64
|
+
router.get('/api/admin/analytics', auth, requireCapability('post.edit'), AnalyticsController.summary);
|
|
65
|
+
// Public by design: the caller is a reader's browser, which has no
|
|
66
|
+
// credential. Under /api/v1 because it is part of the surface a headless
|
|
67
|
+
// front end talks to.
|
|
68
|
+
router.post('/api/v1/analytics/hit', analyticsHitLimit, AnalyticsController.hit);
|
|
69
|
+
});
|
|
70
|
+
// Hashes must not outlive their window on a quiet day, when no hit comes
|
|
71
|
+
// in to trigger the opportunistic purge.
|
|
72
|
+
host.cron.task('purge', 600, () => purge({}));
|
|
73
|
+
host.health.check('purge', async ({ db, now }) => {
|
|
74
|
+
let stale;
|
|
75
|
+
try {
|
|
76
|
+
// An hour's grace past the longest window: the purge is throttled,
|
|
77
|
+
// and a hash from 23:59 is legitimately alive for a few minutes after
|
|
78
|
+
// midnight.
|
|
79
|
+
const row = await db.get('SELECT COUNT(*) AS n FROM analytics_seen WHERE created_at < ?', [now.getTime() - 25 * 3_600_000]);
|
|
80
|
+
stale = Number(row?.n ?? 0);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return stale > 0
|
|
86
|
+
? check('analytics_purge', 'Analytics purge', 'warn', `${stale} visitor hash(es) are past their window.`, 'The purge runs on traffic and on GET /api/cron/tick; schedule the cron so the privacy promise holds on quiet days.')
|
|
87
|
+
: check('analytics_purge', 'Analytics purge', 'pass', 'No visitor hashes kept past their window.');
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
export default analytics;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static facts about the analytics feature, for code that cannot boot the
|
|
3
|
+
* server: the export and backup scripts, and the admin menu. Imports nothing,
|
|
4
|
+
* so plain Node can load it (see src/helpers/export-data.ts for why).
|
|
5
|
+
*/
|
|
6
|
+
import type { FeatureManifest } from '../../host/manifest.ts';
|
|
7
|
+
declare const manifest: FeatureManifest;
|
|
8
|
+
export default manifest;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const manifest = {
|
|
2
|
+
name: 'analytics',
|
|
3
|
+
pages: [
|
|
4
|
+
{
|
|
5
|
+
path: '/admin/analytics',
|
|
6
|
+
label: 'Analytics',
|
|
7
|
+
section: 'Site',
|
|
8
|
+
capability: 'post.edit',
|
|
9
|
+
icon: '📈',
|
|
10
|
+
iconPath: 'M4 20V10M10 20V4M16 20v-7M22 20H2'
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
// The visitor hashes and the day's salt exist only so they can be deleted
|
|
14
|
+
// within a day; copying them into a file would defeat that. The counts are
|
|
15
|
+
// simply not exported (no natural key for an importer to merge on).
|
|
16
|
+
neverExported: ['analytics_salts', 'analytics_seen']
|
|
17
|
+
};
|
|
18
|
+
export default manifest;
|