@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,117 @@
|
|
|
1
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
2
|
+
import { livePost } from "./visibility.js";
|
|
3
|
+
function slugify(text) {
|
|
4
|
+
return text
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
7
|
+
.replace(/(^-|-$)/g, '');
|
|
8
|
+
}
|
|
9
|
+
export const Tag = {
|
|
10
|
+
async all() {
|
|
11
|
+
const db = await getDb();
|
|
12
|
+
return db.all(`
|
|
13
|
+
SELECT t.*, COUNT(pt.post_id) as post_count
|
|
14
|
+
FROM tags t
|
|
15
|
+
LEFT JOIN post_tags pt ON pt.tag_id = t.id
|
|
16
|
+
LEFT JOIN posts p ON p.id = pt.post_id AND ${livePost('p')}
|
|
17
|
+
GROUP BY t.id
|
|
18
|
+
ORDER BY t.name ASC
|
|
19
|
+
`);
|
|
20
|
+
},
|
|
21
|
+
async find(id) {
|
|
22
|
+
const db = await getDb();
|
|
23
|
+
return db.get(`
|
|
24
|
+
SELECT t.*, COUNT(pt.post_id) as post_count
|
|
25
|
+
FROM tags t
|
|
26
|
+
LEFT JOIN post_tags pt ON pt.tag_id = t.id
|
|
27
|
+
LEFT JOIN posts p ON p.id = pt.post_id AND ${livePost('p')}
|
|
28
|
+
WHERE t.id = ?
|
|
29
|
+
GROUP BY t.id
|
|
30
|
+
`, [id]);
|
|
31
|
+
},
|
|
32
|
+
async findBySlug(slug) {
|
|
33
|
+
const db = await getDb();
|
|
34
|
+
return db.get(`
|
|
35
|
+
SELECT t.*, COUNT(pt.post_id) as post_count
|
|
36
|
+
FROM tags t
|
|
37
|
+
LEFT JOIN post_tags pt ON pt.tag_id = t.id
|
|
38
|
+
LEFT JOIN posts p ON p.id = pt.post_id AND ${livePost('p')}
|
|
39
|
+
WHERE t.slug = ?
|
|
40
|
+
GROUP BY t.id
|
|
41
|
+
`, [slug]);
|
|
42
|
+
},
|
|
43
|
+
async findByIds(ids) {
|
|
44
|
+
if (ids.length === 0)
|
|
45
|
+
return [];
|
|
46
|
+
const db = await getDb();
|
|
47
|
+
const placeholders = ids.map(() => '?').join(', ');
|
|
48
|
+
return db.all(`SELECT * FROM tags WHERE id IN (${placeholders})`, ids);
|
|
49
|
+
},
|
|
50
|
+
async findByPostId(postId) {
|
|
51
|
+
const db = await getDb();
|
|
52
|
+
return db.all(`
|
|
53
|
+
SELECT t.*
|
|
54
|
+
FROM tags t
|
|
55
|
+
JOIN post_tags pt ON pt.tag_id = t.id
|
|
56
|
+
WHERE pt.post_id = ?
|
|
57
|
+
ORDER BY t.name ASC
|
|
58
|
+
`, [postId]);
|
|
59
|
+
},
|
|
60
|
+
async create(data) {
|
|
61
|
+
const db = await getDb();
|
|
62
|
+
const slug = data.slug || slugify(data.name);
|
|
63
|
+
// Through the query builder, which appends RETURNING id on Postgres. A raw
|
|
64
|
+
// INSERT there reports lastInsertRowid as null, so the row is written and
|
|
65
|
+
// the caller is handed an object with no id — the failure looks like a bug
|
|
66
|
+
// in whatever used the id next.
|
|
67
|
+
const result = await (await query('tags')).insert({ name: data.name, slug });
|
|
68
|
+
return {
|
|
69
|
+
id: result.lastInsertRowid,
|
|
70
|
+
name: data.name,
|
|
71
|
+
slug,
|
|
72
|
+
created_at: new Date().toISOString(),
|
|
73
|
+
post_count: 0
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
async findOrCreate(name) {
|
|
77
|
+
const slug = slugify(name);
|
|
78
|
+
const existing = await this.findBySlug(slug);
|
|
79
|
+
if (existing)
|
|
80
|
+
return existing;
|
|
81
|
+
return this.create({ name, slug });
|
|
82
|
+
},
|
|
83
|
+
async update(id, data) {
|
|
84
|
+
const db = await getDb();
|
|
85
|
+
if (data.name && !data.slug) {
|
|
86
|
+
data.slug = slugify(data.name);
|
|
87
|
+
}
|
|
88
|
+
const fields = Object.keys(data).map(k => `${k} = ?`).join(', ');
|
|
89
|
+
await db.run(`UPDATE tags SET ${fields} WHERE id = ?`, [...Object.values(data), id]);
|
|
90
|
+
return this.find(id);
|
|
91
|
+
},
|
|
92
|
+
async delete(id) {
|
|
93
|
+
const db = await getDb();
|
|
94
|
+
// Delete pivot table entries
|
|
95
|
+
await db.run('DELETE FROM post_tags WHERE tag_id = ?', [id]);
|
|
96
|
+
// Delete tag
|
|
97
|
+
await db.run('DELETE FROM tags WHERE id = ?', [id]);
|
|
98
|
+
},
|
|
99
|
+
async syncToPost(postId, tagIds) {
|
|
100
|
+
const db = await getDb();
|
|
101
|
+
// Remove existing tags
|
|
102
|
+
await db.run('DELETE FROM post_tags WHERE post_id = ?', [postId]);
|
|
103
|
+
// Add new tags
|
|
104
|
+
for (const tagId of tagIds) {
|
|
105
|
+
await db.run('INSERT INTO post_tags (post_id, tag_id) VALUES (?, ?)', [postId, tagId]);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
async slugExists(slug, excludeId) {
|
|
109
|
+
const db = await getDb();
|
|
110
|
+
const query = excludeId
|
|
111
|
+
? 'SELECT id FROM tags WHERE slug = ? AND id != ?'
|
|
112
|
+
: 'SELECT id FROM tags WHERE slug = ?';
|
|
113
|
+
const params = excludeId ? [slug, excludeId] : [slug];
|
|
114
|
+
const result = await db.get(query, params);
|
|
115
|
+
return !!result;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom taxonomies and their terms.
|
|
3
|
+
*
|
|
4
|
+
* Categories and tags keep their own tables (see migration 040 for why); this
|
|
5
|
+
* is everything beyond them — "cuisine", "diet", "season" — each attached to
|
|
6
|
+
* the content types it applies to. A post's terms are only ever ones from a
|
|
7
|
+
* taxonomy attached to its type: the sync below drops anything else rather
|
|
8
|
+
* than filing a blog post under a recipe's cuisine.
|
|
9
|
+
*
|
|
10
|
+
* Validators are pure and exported for tests. Imports carry `.ts` extensions
|
|
11
|
+
* so this loads under plain Node too.
|
|
12
|
+
*/
|
|
13
|
+
/** Keys the built-in taxonomies answer to, and words the API already uses. */
|
|
14
|
+
export declare const RESERVED_TAXONOMY_KEYS: string[];
|
|
15
|
+
export interface TaxonomyRecord {
|
|
16
|
+
id: number;
|
|
17
|
+
key: string;
|
|
18
|
+
singular_label: string;
|
|
19
|
+
plural_label: string;
|
|
20
|
+
description: string | null;
|
|
21
|
+
hierarchical: boolean;
|
|
22
|
+
public: boolean;
|
|
23
|
+
/** Keys of the content types this taxonomy applies to. */
|
|
24
|
+
content_types: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface TermRecord {
|
|
27
|
+
id: number;
|
|
28
|
+
taxonomy_id: number;
|
|
29
|
+
name: string;
|
|
30
|
+
slug: string;
|
|
31
|
+
description: string | null;
|
|
32
|
+
parent_id: number | null;
|
|
33
|
+
sort_order: number;
|
|
34
|
+
/** Live posts carrying this term. Present on listings. */
|
|
35
|
+
post_count?: number;
|
|
36
|
+
}
|
|
37
|
+
type Errors = Record<string, string[]>;
|
|
38
|
+
/** A taxonomy definition. `existing` is null on create; the key is fixed after. */
|
|
39
|
+
export declare function validateTaxonomy(input: unknown, existing?: TaxonomyRecord | null): {
|
|
40
|
+
values: Omit<TaxonomyRecord, 'id'>;
|
|
41
|
+
} | {
|
|
42
|
+
errors: Errors;
|
|
43
|
+
};
|
|
44
|
+
/** A term's name, slug and parent. The slug is derived when left blank. */
|
|
45
|
+
export declare function validateTerm(input: unknown, existing?: TermRecord | null): {
|
|
46
|
+
values: {
|
|
47
|
+
name: string;
|
|
48
|
+
slug: string;
|
|
49
|
+
description: string | null;
|
|
50
|
+
parent_id: number | null;
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
errors: Errors;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* `?taxonomy[cuisine]=italian` and `?tax=cuisine:italian,diet:vegan` as one map.
|
|
57
|
+
*
|
|
58
|
+
* Both spellings because the first is what a form or a PHP-minded consumer
|
|
59
|
+
* builds and the second fits in a URL someone types. The framework parses the
|
|
60
|
+
* query string flat, so the bracketed form arrives as a key named
|
|
61
|
+
* `taxonomy[cuisine]`. Several filters combine with AND, like `?category=`
|
|
62
|
+
* and `?tag=` do.
|
|
63
|
+
*/
|
|
64
|
+
export declare function taxonomyFilters(query: Record<string, unknown>, tax?: unknown): Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* SQL that narrows `posts` to entries carrying every given term.
|
|
67
|
+
*
|
|
68
|
+
* One `IN (subquery)` per taxonomy, all bound — keys and slugs are input. A
|
|
69
|
+
* taxonomy that does not exist, or is not public, matches nothing, so an
|
|
70
|
+
* archive for it is empty rather than unfiltered.
|
|
71
|
+
*/
|
|
72
|
+
export declare function taxonomyWhere(alias: string, filters: Record<string, string>): {
|
|
73
|
+
where: string[];
|
|
74
|
+
params: unknown[];
|
|
75
|
+
};
|
|
76
|
+
export declare const Taxonomy: {
|
|
77
|
+
all(options?: {
|
|
78
|
+
publicOnly?: boolean;
|
|
79
|
+
contentType?: string;
|
|
80
|
+
}): Promise<TaxonomyRecord[]>;
|
|
81
|
+
find(id: number): Promise<TaxonomyRecord | undefined>;
|
|
82
|
+
findByKey(key: string): Promise<TaxonomyRecord | undefined>;
|
|
83
|
+
keyTaken(key: string, excludeId?: number): Promise<boolean>;
|
|
84
|
+
/** Content type keys that do not exist, so the controller can name them. */
|
|
85
|
+
unknownContentTypes(keys: string[]): Promise<string[]>;
|
|
86
|
+
create(values: Omit<TaxonomyRecord, "id">): Promise<TaxonomyRecord>;
|
|
87
|
+
update(id: number, values: Omit<TaxonomyRecord, "id">): Promise<TaxonomyRecord>;
|
|
88
|
+
/** Replace which content types the taxonomy applies to. */
|
|
89
|
+
attach(id: number, contentTypes: string[]): Promise<void>;
|
|
90
|
+
/** Deletes its terms and every post's link to them, through the cascades. */
|
|
91
|
+
delete(id: number): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* A taxonomy's terms, with live-post counts.
|
|
94
|
+
*
|
|
95
|
+
* Counted the way categories are: every live post carrying the term, through
|
|
96
|
+
* the shared visibility predicate, so a scheduled post is not counted early.
|
|
97
|
+
*/
|
|
98
|
+
terms(taxonomyId: number): Promise<TermRecord[]>;
|
|
99
|
+
findTerm(id: number): Promise<TermRecord | undefined>;
|
|
100
|
+
findTermBySlug(taxonomyId: number, slug: string): Promise<TermRecord | undefined>;
|
|
101
|
+
termSlugTaken(taxonomyId: number, slug: string, excludeId?: number): Promise<boolean>;
|
|
102
|
+
createTerm(taxonomyId: number, values: {
|
|
103
|
+
name: string;
|
|
104
|
+
slug: string;
|
|
105
|
+
description: string | null;
|
|
106
|
+
parent_id: number | null;
|
|
107
|
+
}): Promise<TermRecord>;
|
|
108
|
+
updateTerm(id: number, values: {
|
|
109
|
+
name: string;
|
|
110
|
+
slug: string;
|
|
111
|
+
description: string | null;
|
|
112
|
+
parent_id: number | null;
|
|
113
|
+
}): Promise<TermRecord>;
|
|
114
|
+
deleteTerm(id: number): Promise<void>;
|
|
115
|
+
/** The ids of a post's custom terms, for the editor to preselect. */
|
|
116
|
+
termIdsFor(postId: number): Promise<number[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Replace a post's custom terms.
|
|
119
|
+
*
|
|
120
|
+
* Rebuilt, like categories and tags, because the editor sends the whole set.
|
|
121
|
+
* Only terms of taxonomies attached to the post's type survive: the editor
|
|
122
|
+
* never offers others, and an API caller sending one is filing the post
|
|
123
|
+
* somewhere its type has no place for.
|
|
124
|
+
*/
|
|
125
|
+
syncPostTerms(postId: number, termIds: unknown[]): Promise<void>;
|
|
126
|
+
};
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom taxonomies and their terms.
|
|
3
|
+
*
|
|
4
|
+
* Categories and tags keep their own tables (see migration 040 for why); this
|
|
5
|
+
* is everything beyond them — "cuisine", "diet", "season" — each attached to
|
|
6
|
+
* the content types it applies to. A post's terms are only ever ones from a
|
|
7
|
+
* taxonomy attached to its type: the sync below drops anything else rather
|
|
8
|
+
* than filing a blog post under a recipe's cuisine.
|
|
9
|
+
*
|
|
10
|
+
* Validators are pure and exported for tests. Imports carry `.ts` extensions
|
|
11
|
+
* so this loads under plain Node too.
|
|
12
|
+
*/
|
|
13
|
+
import { getDb, query } from '@basicbenframework/core/db';
|
|
14
|
+
import { slugify } from '@basicbenframework/core/content';
|
|
15
|
+
import { livePost } from "./visibility.js";
|
|
16
|
+
/** Keys the built-in taxonomies answer to, and words the API already uses. */
|
|
17
|
+
export const RESERVED_TAXONOMY_KEYS = ['category', 'categories', 'tag', 'tags', 'post_tag', 'type', 'author', 'any'];
|
|
18
|
+
const truthy = (value) => value === true || value === 1 || value === '1' || value === 'true' || value === 'on';
|
|
19
|
+
function label(value, max = 100) {
|
|
20
|
+
if (typeof value !== 'string')
|
|
21
|
+
return null;
|
|
22
|
+
const trimmed = value.trim();
|
|
23
|
+
return trimmed && trimmed.length <= max ? trimmed : null;
|
|
24
|
+
}
|
|
25
|
+
/** A taxonomy definition. `existing` is null on create; the key is fixed after. */
|
|
26
|
+
export function validateTaxonomy(input, existing = null) {
|
|
27
|
+
const body = (input && typeof input === 'object' ? input : {});
|
|
28
|
+
const errors = {};
|
|
29
|
+
let key = existing?.key ?? '';
|
|
30
|
+
if (!existing) {
|
|
31
|
+
const raw = typeof body.key === 'string' ? body.key.trim().toLowerCase() : '';
|
|
32
|
+
if (!/^[a-z][a-z0-9_]{0,31}$/.test(raw)) {
|
|
33
|
+
errors.key = ['Key must start with a letter and use lowercase letters, digits and underscores (32 at most)'];
|
|
34
|
+
}
|
|
35
|
+
else if (RESERVED_TAXONOMY_KEYS.includes(raw)) {
|
|
36
|
+
errors.key = [`"${raw}" is reserved — categories and tags are built in`];
|
|
37
|
+
}
|
|
38
|
+
key = raw;
|
|
39
|
+
}
|
|
40
|
+
else if (body.key !== undefined && body.key !== existing.key) {
|
|
41
|
+
errors.key = ['The key cannot be changed once a taxonomy exists'];
|
|
42
|
+
}
|
|
43
|
+
const singular = 'singular_label' in body || !existing ? label(body.singular_label) : existing.singular_label;
|
|
44
|
+
const plural = 'plural_label' in body || !existing ? label(body.plural_label) : existing.plural_label;
|
|
45
|
+
if (!singular)
|
|
46
|
+
errors.singular_label = ['Singular label is required (100 characters at most)'];
|
|
47
|
+
if (!plural)
|
|
48
|
+
errors.plural_label = ['Plural label is required (100 characters at most)'];
|
|
49
|
+
const description = 'description' in body
|
|
50
|
+
? (typeof body.description === 'string' && body.description.trim() ? body.description.trim().slice(0, 1000) : null)
|
|
51
|
+
: existing?.description ?? null;
|
|
52
|
+
let contentTypes = existing?.content_types ?? ['post'];
|
|
53
|
+
if ('content_types' in body) {
|
|
54
|
+
if (!Array.isArray(body.content_types) || body.content_types.some((item) => typeof item !== 'string')) {
|
|
55
|
+
errors.content_types = ['Content types must be a list of type keys'];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
contentTypes = [...new Set(body.content_types)];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (Object.keys(errors).length)
|
|
62
|
+
return { errors };
|
|
63
|
+
return {
|
|
64
|
+
values: {
|
|
65
|
+
key,
|
|
66
|
+
singular_label: singular,
|
|
67
|
+
plural_label: plural,
|
|
68
|
+
description,
|
|
69
|
+
hierarchical: 'hierarchical' in body ? truthy(body.hierarchical) : existing?.hierarchical ?? false,
|
|
70
|
+
public: 'public' in body ? truthy(body.public) : existing?.public ?? true,
|
|
71
|
+
content_types: contentTypes
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** A term's name, slug and parent. The slug is derived when left blank. */
|
|
76
|
+
export function validateTerm(input, existing = null) {
|
|
77
|
+
const body = (input && typeof input === 'object' ? input : {});
|
|
78
|
+
const errors = {};
|
|
79
|
+
const name = 'name' in body || !existing ? label(body.name, 200) : existing.name;
|
|
80
|
+
if (!name)
|
|
81
|
+
errors.name = ['Name is required (200 characters at most)'];
|
|
82
|
+
const typedSlug = typeof body.slug === 'string' ? body.slug.trim() : '';
|
|
83
|
+
const slug = typedSlug ? slugify(typedSlug) : 'slug' in body || !existing ? slugify(name || '') : existing.slug;
|
|
84
|
+
if (!slug)
|
|
85
|
+
errors.slug = ['Could not make a slug from that — type one'];
|
|
86
|
+
const description = 'description' in body
|
|
87
|
+
? (typeof body.description === 'string' && body.description.trim() ? body.description.trim().slice(0, 1000) : null)
|
|
88
|
+
: existing?.description ?? null;
|
|
89
|
+
let parentId = existing?.parent_id ?? null;
|
|
90
|
+
if ('parent_id' in body) {
|
|
91
|
+
const id = Number(body.parent_id);
|
|
92
|
+
parentId = Number.isInteger(id) && id > 0 ? id : null;
|
|
93
|
+
if (existing && parentId === existing.id)
|
|
94
|
+
errors.parent_id = ['A term cannot be its own parent'];
|
|
95
|
+
}
|
|
96
|
+
if (Object.keys(errors).length)
|
|
97
|
+
return { errors };
|
|
98
|
+
return { values: { name: name, slug, description, parent_id: parentId } };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* `?taxonomy[cuisine]=italian` and `?tax=cuisine:italian,diet:vegan` as one map.
|
|
102
|
+
*
|
|
103
|
+
* Both spellings because the first is what a form or a PHP-minded consumer
|
|
104
|
+
* builds and the second fits in a URL someone types. The framework parses the
|
|
105
|
+
* query string flat, so the bracketed form arrives as a key named
|
|
106
|
+
* `taxonomy[cuisine]`. Several filters combine with AND, like `?category=`
|
|
107
|
+
* and `?tag=` do.
|
|
108
|
+
*/
|
|
109
|
+
export function taxonomyFilters(query, tax = query?.tax) {
|
|
110
|
+
const filters = {};
|
|
111
|
+
for (const [name, value] of Object.entries(query ?? {})) {
|
|
112
|
+
const match = name.match(/^taxonomy\[([a-z][a-z0-9_]{0,31})\]$/);
|
|
113
|
+
if (match && typeof value === 'string' && value)
|
|
114
|
+
filters[match[1]] = value.slice(0, 200);
|
|
115
|
+
}
|
|
116
|
+
if (typeof tax === 'string') {
|
|
117
|
+
for (const pair of tax.split(',').slice(0, 10)) {
|
|
118
|
+
const [key, slug] = pair.split(':').map((part) => part.trim());
|
|
119
|
+
if (key && slug && /^[a-z][a-z0-9_]{0,31}$/.test(key))
|
|
120
|
+
filters[key] = slug.slice(0, 200);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return filters;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* SQL that narrows `posts` to entries carrying every given term.
|
|
127
|
+
*
|
|
128
|
+
* One `IN (subquery)` per taxonomy, all bound — keys and slugs are input. A
|
|
129
|
+
* taxonomy that does not exist, or is not public, matches nothing, so an
|
|
130
|
+
* archive for it is empty rather than unfiltered.
|
|
131
|
+
*/
|
|
132
|
+
export function taxonomyWhere(alias, filters) {
|
|
133
|
+
const where = [];
|
|
134
|
+
const params = [];
|
|
135
|
+
for (const [key, slug] of Object.entries(filters)) {
|
|
136
|
+
where.push(`${alias}.id IN (
|
|
137
|
+
SELECT tr.post_id FROM term_relationships tr
|
|
138
|
+
JOIN terms ON terms.id = tr.term_id
|
|
139
|
+
JOIN taxonomies ON taxonomies.id = terms.taxonomy_id
|
|
140
|
+
WHERE taxonomies.key = ? AND taxonomies.is_public = 1 AND (terms.slug = ? OR terms.id = ?)
|
|
141
|
+
)`);
|
|
142
|
+
params.push(key, slug, Number(slug) || -1);
|
|
143
|
+
}
|
|
144
|
+
return { where, params };
|
|
145
|
+
}
|
|
146
|
+
async function loadAll() {
|
|
147
|
+
const db = await getDb();
|
|
148
|
+
const rows = (await db.all('SELECT * FROM taxonomies ORDER BY plural_label ASC, id ASC'));
|
|
149
|
+
const links = (await db.all(`SELECT tct.taxonomy_id, ct.key FROM taxonomy_content_types tct
|
|
150
|
+
JOIN content_types ct ON ct.id = tct.content_type_id`));
|
|
151
|
+
return rows.map((row) => ({
|
|
152
|
+
id: Number(row.id),
|
|
153
|
+
key: row.key,
|
|
154
|
+
singular_label: row.singular_label,
|
|
155
|
+
plural_label: row.plural_label,
|
|
156
|
+
description: row.description,
|
|
157
|
+
hierarchical: Boolean(Number(row.hierarchical)),
|
|
158
|
+
public: Boolean(Number(row.is_public)),
|
|
159
|
+
content_types: links.filter((link) => Number(link.taxonomy_id) === Number(row.id)).map((link) => link.key)
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
function shapeTerm(row) {
|
|
163
|
+
return {
|
|
164
|
+
id: Number(row.id),
|
|
165
|
+
taxonomy_id: Number(row.taxonomy_id),
|
|
166
|
+
name: String(row.name),
|
|
167
|
+
slug: String(row.slug),
|
|
168
|
+
description: row.description ?? null,
|
|
169
|
+
parent_id: row.parent_id === null || row.parent_id === undefined ? null : Number(row.parent_id),
|
|
170
|
+
sort_order: Number(row.sort_order) || 0,
|
|
171
|
+
...(row.post_count !== undefined ? { post_count: Number(row.post_count) || 0 } : {})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export const Taxonomy = {
|
|
175
|
+
async all(options = {}) {
|
|
176
|
+
let list = await loadAll();
|
|
177
|
+
if (options.publicOnly)
|
|
178
|
+
list = list.filter((taxonomy) => taxonomy.public);
|
|
179
|
+
if (options.contentType)
|
|
180
|
+
list = list.filter((taxonomy) => taxonomy.content_types.includes(options.contentType));
|
|
181
|
+
return list;
|
|
182
|
+
},
|
|
183
|
+
async find(id) {
|
|
184
|
+
return (await loadAll()).find((taxonomy) => taxonomy.id === id);
|
|
185
|
+
},
|
|
186
|
+
async findByKey(key) {
|
|
187
|
+
return (await loadAll()).find((taxonomy) => taxonomy.key === key);
|
|
188
|
+
},
|
|
189
|
+
async keyTaken(key, excludeId) {
|
|
190
|
+
return (await loadAll()).some((taxonomy) => taxonomy.key === key && taxonomy.id !== excludeId);
|
|
191
|
+
},
|
|
192
|
+
/** Content type keys that do not exist, so the controller can name them. */
|
|
193
|
+
async unknownContentTypes(keys) {
|
|
194
|
+
const db = await getDb();
|
|
195
|
+
const rows = (await db.all('SELECT key FROM content_types'));
|
|
196
|
+
const known = new Set(rows.map((row) => row.key));
|
|
197
|
+
return keys.filter((key) => !known.has(key));
|
|
198
|
+
},
|
|
199
|
+
async create(values) {
|
|
200
|
+
const result = await (await query('taxonomies')).insert({
|
|
201
|
+
key: values.key,
|
|
202
|
+
singular_label: values.singular_label,
|
|
203
|
+
plural_label: values.plural_label,
|
|
204
|
+
description: values.description,
|
|
205
|
+
hierarchical: values.hierarchical ? 1 : 0,
|
|
206
|
+
is_public: values.public ? 1 : 0
|
|
207
|
+
});
|
|
208
|
+
const id = Number(result.lastInsertRowid);
|
|
209
|
+
await this.attach(id, values.content_types);
|
|
210
|
+
return (await this.find(id));
|
|
211
|
+
},
|
|
212
|
+
async update(id, values) {
|
|
213
|
+
const db = await getDb();
|
|
214
|
+
await db.run(`UPDATE taxonomies SET singular_label = ?, plural_label = ?, description = ?, hierarchical = ?, is_public = ?, updated_at = ?
|
|
215
|
+
WHERE id = ?`, [values.singular_label, values.plural_label, values.description, values.hierarchical ? 1 : 0,
|
|
216
|
+
values.public ? 1 : 0, new Date().toISOString(), id]);
|
|
217
|
+
await this.attach(id, values.content_types);
|
|
218
|
+
return (await this.find(id));
|
|
219
|
+
},
|
|
220
|
+
/** Replace which content types the taxonomy applies to. */
|
|
221
|
+
async attach(id, contentTypes) {
|
|
222
|
+
const db = await getDb();
|
|
223
|
+
await db.run('DELETE FROM taxonomy_content_types WHERE taxonomy_id = ?', [id]);
|
|
224
|
+
for (const key of contentTypes) {
|
|
225
|
+
await db.run(`INSERT INTO taxonomy_content_types (taxonomy_id, content_type_id)
|
|
226
|
+
SELECT ?, id FROM content_types WHERE key = ?`, [id, key]);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
/** Deletes its terms and every post's link to them, through the cascades. */
|
|
230
|
+
async delete(id) {
|
|
231
|
+
const db = await getDb();
|
|
232
|
+
// Spelled out as well as cascaded: SQLite only honours ON DELETE when
|
|
233
|
+
// foreign keys are switched on for the connection.
|
|
234
|
+
await db.run('DELETE FROM term_relationships WHERE term_id IN (SELECT id FROM terms WHERE taxonomy_id = ?)', [id]);
|
|
235
|
+
await db.run('DELETE FROM terms WHERE taxonomy_id = ?', [id]);
|
|
236
|
+
await db.run('DELETE FROM taxonomy_content_types WHERE taxonomy_id = ?', [id]);
|
|
237
|
+
await db.run('DELETE FROM taxonomies WHERE id = ?', [id]);
|
|
238
|
+
},
|
|
239
|
+
/**
|
|
240
|
+
* A taxonomy's terms, with live-post counts.
|
|
241
|
+
*
|
|
242
|
+
* Counted the way categories are: every live post carrying the term, through
|
|
243
|
+
* the shared visibility predicate, so a scheduled post is not counted early.
|
|
244
|
+
*/
|
|
245
|
+
async terms(taxonomyId) {
|
|
246
|
+
const db = await getDb();
|
|
247
|
+
const rows = (await db.all(`SELECT t.id, t.taxonomy_id, t.name, t.slug, t.description, t.parent_id, t.sort_order,
|
|
248
|
+
COUNT(p.id) AS post_count
|
|
249
|
+
FROM terms t
|
|
250
|
+
LEFT JOIN term_relationships tr ON tr.term_id = t.id
|
|
251
|
+
LEFT JOIN posts p ON p.id = tr.post_id AND ${livePost('p')}
|
|
252
|
+
WHERE t.taxonomy_id = ?
|
|
253
|
+
GROUP BY t.id, t.taxonomy_id, t.name, t.slug, t.description, t.parent_id, t.sort_order
|
|
254
|
+
ORDER BY t.sort_order ASC, t.name ASC`, [taxonomyId]));
|
|
255
|
+
return rows.map(shapeTerm);
|
|
256
|
+
},
|
|
257
|
+
async findTerm(id) {
|
|
258
|
+
const db = await getDb();
|
|
259
|
+
const row = await db.get('SELECT * FROM terms WHERE id = ?', [id]);
|
|
260
|
+
return row ? shapeTerm(row) : undefined;
|
|
261
|
+
},
|
|
262
|
+
async findTermBySlug(taxonomyId, slug) {
|
|
263
|
+
const db = await getDb();
|
|
264
|
+
const row = await db.get('SELECT * FROM terms WHERE taxonomy_id = ? AND slug = ?', [taxonomyId, slug]);
|
|
265
|
+
return row ? shapeTerm(row) : undefined;
|
|
266
|
+
},
|
|
267
|
+
async termSlugTaken(taxonomyId, slug, excludeId) {
|
|
268
|
+
const db = await getDb();
|
|
269
|
+
const row = await db.get('SELECT id FROM terms WHERE taxonomy_id = ? AND slug = ? AND id != ?', [taxonomyId, slug, excludeId ?? -1]);
|
|
270
|
+
return Boolean(row);
|
|
271
|
+
},
|
|
272
|
+
async createTerm(taxonomyId, values) {
|
|
273
|
+
const result = await (await query('terms')).insert({ taxonomy_id: taxonomyId, ...values });
|
|
274
|
+
return (await this.findTerm(Number(result.lastInsertRowid)));
|
|
275
|
+
},
|
|
276
|
+
async updateTerm(id, values) {
|
|
277
|
+
const db = await getDb();
|
|
278
|
+
await db.run('UPDATE terms SET name = ?, slug = ?, description = ?, parent_id = ? WHERE id = ?', [values.name, values.slug, values.description, values.parent_id, id]);
|
|
279
|
+
return (await this.findTerm(id));
|
|
280
|
+
},
|
|
281
|
+
async deleteTerm(id) {
|
|
282
|
+
const db = await getDb();
|
|
283
|
+
await db.run('DELETE FROM term_relationships WHERE term_id = ?', [id]);
|
|
284
|
+
await db.run('UPDATE terms SET parent_id = NULL WHERE parent_id = ?', [id]);
|
|
285
|
+
await db.run('DELETE FROM terms WHERE id = ?', [id]);
|
|
286
|
+
},
|
|
287
|
+
/** The ids of a post's custom terms, for the editor to preselect. */
|
|
288
|
+
async termIdsFor(postId) {
|
|
289
|
+
const db = await getDb();
|
|
290
|
+
const rows = (await db.all('SELECT term_id FROM term_relationships WHERE post_id = ?', [postId]));
|
|
291
|
+
return rows.map((row) => Number(row.term_id));
|
|
292
|
+
},
|
|
293
|
+
/**
|
|
294
|
+
* Replace a post's custom terms.
|
|
295
|
+
*
|
|
296
|
+
* Rebuilt, like categories and tags, because the editor sends the whole set.
|
|
297
|
+
* Only terms of taxonomies attached to the post's type survive: the editor
|
|
298
|
+
* never offers others, and an API caller sending one is filing the post
|
|
299
|
+
* somewhere its type has no place for.
|
|
300
|
+
*/
|
|
301
|
+
async syncPostTerms(postId, termIds) {
|
|
302
|
+
const db = await getDb();
|
|
303
|
+
const ids = [...new Set(termIds.map(Number).filter(Number.isInteger))];
|
|
304
|
+
const post = await db.get('SELECT post_type FROM posts WHERE id = ?', [postId]);
|
|
305
|
+
if (!post)
|
|
306
|
+
return;
|
|
307
|
+
let allowed = [];
|
|
308
|
+
if (ids.length) {
|
|
309
|
+
const placeholders = ids.map(() => '?').join(', ');
|
|
310
|
+
const rows = (await db.all(`SELECT terms.id FROM terms
|
|
311
|
+
JOIN taxonomy_content_types tct ON tct.taxonomy_id = terms.taxonomy_id
|
|
312
|
+
JOIN content_types ct ON ct.id = tct.content_type_id
|
|
313
|
+
WHERE ct.key = ? AND terms.id IN (${placeholders})`, [post.post_type || 'post', ...ids]));
|
|
314
|
+
allowed = rows.map((row) => Number(row.id));
|
|
315
|
+
}
|
|
316
|
+
await db.run('DELETE FROM term_relationships WHERE post_id = ?', [postId]);
|
|
317
|
+
for (const id of allowed) {
|
|
318
|
+
await db.run('INSERT INTO term_relationships (post_id, term_id) VALUES (?, ?)', [postId, id]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface TwoFactorRecord {
|
|
2
|
+
user_id: number;
|
|
3
|
+
totp_secret: string | null;
|
|
4
|
+
totp_enabled_at: string | null;
|
|
5
|
+
totp_last_step: number | null;
|
|
6
|
+
recovery_codes: string | null;
|
|
7
|
+
failed_attempts: number;
|
|
8
|
+
locked_until: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const TwoFactor: {
|
|
11
|
+
find(userId: number): Promise<TwoFactorRecord | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the row, creating it if this user has never enrolled.
|
|
14
|
+
*/
|
|
15
|
+
findOrCreate(userId: number): Promise<TwoFactorRecord>;
|
|
16
|
+
update(userId: number, data: Record<string, unknown>): Promise<TwoFactorRecord | undefined>;
|
|
17
|
+
delete(userId: number): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a usable second factor is enrolled.
|
|
20
|
+
*
|
|
21
|
+
* A secret that was generated but never confirmed does not count — enabling
|
|
22
|
+
* on generation is how people lock themselves out.
|
|
23
|
+
*/
|
|
24
|
+
isEnabled(record?: TwoFactorRecord | null): boolean;
|
|
25
|
+
parseRecoveryCodes(record?: TwoFactorRecord | null): string[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
2
|
+
// Columns update() may write.
|
|
3
|
+
const UPDATABLE = [
|
|
4
|
+
'totp_secret',
|
|
5
|
+
'totp_enabled_at',
|
|
6
|
+
'totp_last_step',
|
|
7
|
+
'recovery_codes',
|
|
8
|
+
'failed_attempts',
|
|
9
|
+
'locked_until'
|
|
10
|
+
];
|
|
11
|
+
export const TwoFactor = {
|
|
12
|
+
async find(userId) {
|
|
13
|
+
const db = await getDb();
|
|
14
|
+
return db.get('SELECT * FROM user_two_factor WHERE user_id = ?', [userId]);
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* Get the row, creating it if this user has never enrolled.
|
|
18
|
+
*/
|
|
19
|
+
async findOrCreate(userId) {
|
|
20
|
+
const existing = await this.find(userId);
|
|
21
|
+
if (existing)
|
|
22
|
+
return existing;
|
|
23
|
+
const db = await getDb();
|
|
24
|
+
await db.run('INSERT INTO user_two_factor (user_id) VALUES (?)', [userId]);
|
|
25
|
+
return (await this.find(userId));
|
|
26
|
+
},
|
|
27
|
+
async update(userId, data) {
|
|
28
|
+
const db = await getDb();
|
|
29
|
+
const entries = Object.entries(data).filter(([k]) => UPDATABLE.includes(k));
|
|
30
|
+
if (entries.length === 0)
|
|
31
|
+
return this.find(userId);
|
|
32
|
+
const fields = entries.map(([k]) => `${k} = ?`).join(', ');
|
|
33
|
+
await db.run(`UPDATE user_two_factor SET ${fields} WHERE user_id = ?`, [...entries.map(([, v]) => v), userId]);
|
|
34
|
+
return this.find(userId);
|
|
35
|
+
},
|
|
36
|
+
async delete(userId) {
|
|
37
|
+
const db = await getDb();
|
|
38
|
+
await db.run('DELETE FROM user_two_factor WHERE user_id = ?', [userId]);
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Whether a usable second factor is enrolled.
|
|
42
|
+
*
|
|
43
|
+
* A secret that was generated but never confirmed does not count — enabling
|
|
44
|
+
* on generation is how people lock themselves out.
|
|
45
|
+
*/
|
|
46
|
+
isEnabled(record) {
|
|
47
|
+
return Boolean(record?.totp_enabled_at && record?.totp_secret);
|
|
48
|
+
},
|
|
49
|
+
parseRecoveryCodes(record) {
|
|
50
|
+
if (!record?.recovery_codes)
|
|
51
|
+
return [];
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(record.recovery_codes);
|
|
54
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|