@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.
Files changed (590) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +206 -2
  3. package/db/migrations/001_create_users.js +15 -0
  4. package/db/migrations/002_create_posts.js +18 -0
  5. package/db/migrations/003_create_categories.js +19 -0
  6. package/db/migrations/004_create_tags.js +16 -0
  7. package/db/migrations/005_create_post_tags.js +16 -0
  8. package/db/migrations/006_create_pages.js +26 -0
  9. package/db/migrations/007_create_comments.js +24 -0
  10. package/db/migrations/008_create_media.js +22 -0
  11. package/db/migrations/009_update_posts_blogging.js +27 -0
  12. package/db/migrations/010_create_settings.js +29 -0
  13. package/db/migrations/011_add_user_roles.js +23 -0
  14. package/db/migrations/012_create_auth_tokens.js +30 -0
  15. package/db/migrations/013_add_email_verified.js +24 -0
  16. package/db/migrations/014_create_user_two_factor.js +30 -0
  17. package/db/migrations/015_create_user_credentials.js +35 -0
  18. package/db/migrations/016_create_rate_limits.js +31 -0
  19. package/db/migrations/017_add_content_html.js +38 -0
  20. package/db/migrations/018_create_api_tokens.js +34 -0
  21. package/db/migrations/019_create_post_categories.js +40 -0
  22. package/db/migrations/020_add_author_profiles.js +60 -0
  23. package/db/migrations/021_add_page_featured_image.js +23 -0
  24. package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
  25. package/db/migrations/023_add_user_session_controls.js +25 -0
  26. package/db/migrations/024_add_post_status_and_trash.js +45 -0
  27. package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
  28. package/db/migrations/026_create_post_revisions.js +29 -0
  29. package/db/migrations/027_add_media_dimensions.js +19 -0
  30. package/db/migrations/028_create_navigation_menus.js +65 -0
  31. package/db/migrations/029_create_redirects.js +40 -0
  32. package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
  33. package/db/migrations/031_create_post_locks.js +38 -0
  34. package/db/migrations/032_create_snippets.js +31 -0
  35. package/db/migrations/033_create_members.js +70 -0
  36. package/db/migrations/034_add_post_visibility.js +28 -0
  37. package/db/migrations/035_create_newsletters.js +72 -0
  38. package/db/migrations/036_create_analytics.js +89 -0
  39. package/db/migrations/037_create_ops_heartbeats.js +30 -0
  40. package/db/migrations/038_create_content_types.js +84 -0
  41. package/db/migrations/039_create_content_type_fields.js +47 -0
  42. package/db/migrations/040_create_taxonomies.js +80 -0
  43. package/db/migrations/041_add_newsletter_handoff.js +28 -0
  44. package/db/migrations/042_create_mysendbox_contacts.js +63 -0
  45. package/lib/cli/backup.d.mts +2 -0
  46. package/lib/cli/backup.mjs +124 -0
  47. package/lib/cli/export.d.mts +2 -0
  48. package/lib/cli/export.mjs +54 -0
  49. package/lib/cli/import-ghost.d.mts +2 -0
  50. package/lib/cli/import-ghost.mjs +50 -0
  51. package/lib/cli/import-json.d.mts +2 -0
  52. package/lib/cli/import-json.mjs +61 -0
  53. package/lib/cli/import-wordpress.d.mts +2 -0
  54. package/lib/cli/import-wordpress.mjs +169 -0
  55. package/lib/cli/import-wxr.d.mts +2 -0
  56. package/lib/cli/import-wxr.mjs +55 -0
  57. package/lib/cli/index.d.mts +2 -0
  58. package/lib/cli/index.mjs +53 -0
  59. package/lib/cli/lib/backup.d.mts +112 -0
  60. package/lib/cli/lib/backup.mjs +297 -0
  61. package/lib/cli/lib/ghost.d.mts +30 -0
  62. package/lib/cli/lib/ghost.mjs +201 -0
  63. package/lib/cli/lib/html-to-markdown.d.mts +61 -0
  64. package/lib/cli/lib/html-to-markdown.mjs +523 -0
  65. package/lib/cli/lib/import-common.d.mts +100 -0
  66. package/lib/cli/lib/import-common.mjs +252 -0
  67. package/lib/cli/lib/json-import.d.mts +22 -0
  68. package/lib/cli/lib/json-import.mjs +422 -0
  69. package/lib/cli/lib/site-import.d.mts +32 -0
  70. package/lib/cli/lib/site-import.mjs +456 -0
  71. package/lib/cli/lib/wordpress-rest.d.mts +25 -0
  72. package/lib/cli/lib/wordpress-rest.mjs +177 -0
  73. package/lib/cli/lib/wxr.d.mts +18 -0
  74. package/lib/cli/lib/wxr.mjs +307 -0
  75. package/lib/cli/lib/xml.d.mts +33 -0
  76. package/lib/cli/lib/xml.mjs +186 -0
  77. package/lib/cli/restore.d.mts +2 -0
  78. package/lib/cli/restore.mjs +98 -0
  79. package/lib/client/components/Alert.d.ts +7 -0
  80. package/lib/client/components/Alert.js +8 -0
  81. package/lib/client/components/Avatar.d.ts +15 -0
  82. package/lib/client/components/Avatar.js +10 -0
  83. package/lib/client/components/BackLink.d.ts +7 -0
  84. package/lib/client/components/BackLink.js +6 -0
  85. package/lib/client/components/Button.d.ts +7 -0
  86. package/lib/client/components/Button.js +12 -0
  87. package/lib/client/components/Card.d.ts +7 -0
  88. package/lib/client/components/Card.js +6 -0
  89. package/lib/client/components/CommentThread.d.ts +15 -0
  90. package/lib/client/components/CommentThread.js +101 -0
  91. package/lib/client/components/Empty.d.ts +6 -0
  92. package/lib/client/components/Empty.js +6 -0
  93. package/lib/client/components/Input.d.ts +6 -0
  94. package/lib/client/components/Input.js +6 -0
  95. package/lib/client/components/Link.d.ts +31 -0
  96. package/lib/client/components/Link.js +49 -0
  97. package/lib/client/components/Loading.d.ts +1 -0
  98. package/lib/client/components/Loading.js +6 -0
  99. package/lib/client/components/Logo.d.ts +5 -0
  100. package/lib/client/components/Logo.js +4 -0
  101. package/lib/client/components/MarkdownEditor.d.ts +41 -0
  102. package/lib/client/components/MarkdownEditor.js +156 -0
  103. package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
  104. package/lib/client/components/Nav/DarkModeToggle.js +6 -0
  105. package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
  106. package/lib/client/components/Nav/DesktopNav.js +9 -0
  107. package/lib/client/components/Nav/MobileNav.d.ts +9 -0
  108. package/lib/client/components/Nav/MobileNav.js +15 -0
  109. package/lib/client/components/NavLink.d.ts +8 -0
  110. package/lib/client/components/NavLink.js +6 -0
  111. package/lib/client/components/PageHeader.d.ts +8 -0
  112. package/lib/client/components/PageHeader.js +6 -0
  113. package/lib/client/components/PostCard.d.ts +8 -0
  114. package/lib/client/components/PostCard.js +7 -0
  115. package/lib/client/components/Textarea.d.ts +6 -0
  116. package/lib/client/components/Textarea.js +6 -0
  117. package/lib/client/components/ThemeContext.d.ts +18 -0
  118. package/lib/client/components/ThemeContext.js +8 -0
  119. package/lib/client/components/admin/AdminIcons.d.ts +13 -0
  120. package/lib/client/components/admin/AdminIcons.js +66 -0
  121. package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
  122. package/lib/client/components/admin/ContentModelPanels.js +93 -0
  123. package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
  124. package/lib/client/components/admin/FeaturedImageBox.js +24 -0
  125. package/lib/client/components/admin/MediaGrid.d.ts +23 -0
  126. package/lib/client/components/admin/MediaGrid.js +69 -0
  127. package/lib/client/components/admin/MediaPicker.d.ts +17 -0
  128. package/lib/client/components/admin/MediaPicker.js +61 -0
  129. package/lib/client/components/admin/Pagination.d.ts +27 -0
  130. package/lib/client/components/admin/Pagination.js +29 -0
  131. package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
  132. package/lib/client/components/admin/SnippetPicker.js +65 -0
  133. package/lib/client/components/admin/TermPicker.d.ts +52 -0
  134. package/lib/client/components/admin/TermPicker.js +58 -0
  135. package/lib/client/contexts/ToastContext.d.ts +12 -0
  136. package/lib/client/contexts/ToastContext.js +49 -0
  137. package/lib/client/features.d.ts +11 -0
  138. package/lib/client/features.js +7 -0
  139. package/lib/client/hooks/useContentTypes.d.ts +48 -0
  140. package/lib/client/hooks/useContentTypes.js +48 -0
  141. package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
  142. package/lib/client/hooks/useMediaLibrary.js +189 -0
  143. package/lib/client/hooks/usePostLock.d.ts +32 -0
  144. package/lib/client/hooks/usePostLock.js +107 -0
  145. package/lib/client/host/index.d.ts +71 -0
  146. package/lib/client/host/index.js +58 -0
  147. package/lib/client/i18n/index.d.ts +79 -0
  148. package/lib/client/i18n/index.js +177 -0
  149. package/lib/client/i18n/locales/es/content.d.ts +4 -0
  150. package/lib/client/i18n/locales/es/content.js +220 -0
  151. package/lib/client/i18n/locales/es/editor.d.ts +9 -0
  152. package/lib/client/i18n/locales/es/editor.js +144 -0
  153. package/lib/client/i18n/locales/es/index.d.ts +8 -0
  154. package/lib/client/i18n/locales/es/index.js +7 -0
  155. package/lib/client/i18n/locales/es/layout.d.ts +4 -0
  156. package/lib/client/i18n/locales/es/layout.js +35 -0
  157. package/lib/client/i18n/locales/es/people.d.ts +4 -0
  158. package/lib/client/i18n/locales/es/people.js +187 -0
  159. package/lib/client/i18n/locales/es/site.d.ts +4 -0
  160. package/lib/client/i18n/locales/es/site.js +208 -0
  161. package/lib/client/layouts/AdminLayout.d.ts +7 -0
  162. package/lib/client/layouts/AdminLayout.js +1046 -0
  163. package/lib/client/layouts/AppLayout.d.ts +6 -0
  164. package/lib/client/layouts/AppLayout.js +19 -0
  165. package/lib/client/layouts/AuthLayout.d.ts +6 -0
  166. package/lib/client/layouts/AuthLayout.js +14 -0
  167. package/lib/client/layouts/DocsLayout.d.ts +6 -0
  168. package/lib/client/layouts/DocsLayout.js +28 -0
  169. package/lib/client/layouts/RootLayout.d.ts +6 -0
  170. package/lib/client/layouts/RootLayout.js +11 -0
  171. package/lib/client/pages/AcceptInvite.d.ts +8 -0
  172. package/lib/client/pages/AcceptInvite.js +60 -0
  173. package/lib/client/pages/Auth.d.ts +1 -0
  174. package/lib/client/pages/Auth.js +40 -0
  175. package/lib/client/pages/Authentication.d.ts +1 -0
  176. package/lib/client/pages/Authentication.js +230 -0
  177. package/lib/client/pages/Content.d.ts +1 -0
  178. package/lib/client/pages/Content.js +21 -0
  179. package/lib/client/pages/Database.d.ts +1 -0
  180. package/lib/client/pages/Database.js +264 -0
  181. package/lib/client/pages/Extending.d.ts +1 -0
  182. package/lib/client/pages/Extending.js +28 -0
  183. package/lib/client/pages/Feed.d.ts +1 -0
  184. package/lib/client/pages/Feed.js +19 -0
  185. package/lib/client/pages/FeedPost.d.ts +1 -0
  186. package/lib/client/pages/FeedPost.js +31 -0
  187. package/lib/client/pages/ForgotPassword.d.ts +8 -0
  188. package/lib/client/pages/ForgotPassword.js +38 -0
  189. package/lib/client/pages/GettingStarted.d.ts +1 -0
  190. package/lib/client/pages/GettingStarted.js +84 -0
  191. package/lib/client/pages/Headless.d.ts +1 -0
  192. package/lib/client/pages/Headless.js +49 -0
  193. package/lib/client/pages/Home.d.ts +1 -0
  194. package/lib/client/pages/Home.js +67 -0
  195. package/lib/client/pages/PostForm.d.ts +1 -0
  196. package/lib/client/pages/PostForm.js +55 -0
  197. package/lib/client/pages/Posts.d.ts +1 -0
  198. package/lib/client/pages/Posts.js +35 -0
  199. package/lib/client/pages/Profile.d.ts +1 -0
  200. package/lib/client/pages/Profile.js +153 -0
  201. package/lib/client/pages/ResetPassword.d.ts +8 -0
  202. package/lib/client/pages/ResetPassword.js +52 -0
  203. package/lib/client/pages/Routing.d.ts +1 -0
  204. package/lib/client/pages/Routing.js +192 -0
  205. package/lib/client/pages/Storage.d.ts +1 -0
  206. package/lib/client/pages/Storage.js +54 -0
  207. package/lib/client/pages/Testing.d.ts +1 -0
  208. package/lib/client/pages/Testing.js +141 -0
  209. package/lib/client/pages/Validation.d.ts +1 -0
  210. package/lib/client/pages/Validation.js +123 -0
  211. package/lib/client/pages/admin/Categories.d.ts +2 -0
  212. package/lib/client/pages/admin/Categories.js +75 -0
  213. package/lib/client/pages/admin/Comments.d.ts +11 -0
  214. package/lib/client/pages/admin/Comments.js +247 -0
  215. package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
  216. package/lib/client/pages/admin/ContentTypes.js +163 -0
  217. package/lib/client/pages/admin/Dashboard.d.ts +2 -0
  218. package/lib/client/pages/admin/Dashboard.js +66 -0
  219. package/lib/client/pages/admin/Health.d.ts +12 -0
  220. package/lib/client/pages/admin/Health.js +148 -0
  221. package/lib/client/pages/admin/Media.d.ts +2 -0
  222. package/lib/client/pages/admin/Media.js +101 -0
  223. package/lib/client/pages/admin/Navigation.d.ts +9 -0
  224. package/lib/client/pages/admin/Navigation.js +230 -0
  225. package/lib/client/pages/admin/Pages.d.ts +2 -0
  226. package/lib/client/pages/admin/Pages.js +53 -0
  227. package/lib/client/pages/admin/PostEditor.d.ts +17 -0
  228. package/lib/client/pages/admin/PostEditor.js +532 -0
  229. package/lib/client/pages/admin/Posts.d.ts +2 -0
  230. package/lib/client/pages/admin/Posts.js +152 -0
  231. package/lib/client/pages/admin/Redirects.d.ts +10 -0
  232. package/lib/client/pages/admin/Redirects.js +87 -0
  233. package/lib/client/pages/admin/Settings.d.ts +2 -0
  234. package/lib/client/pages/admin/Settings.js +111 -0
  235. package/lib/client/pages/admin/Snippets.d.ts +14 -0
  236. package/lib/client/pages/admin/Snippets.js +85 -0
  237. package/lib/client/pages/admin/Tags.d.ts +2 -0
  238. package/lib/client/pages/admin/Tags.js +74 -0
  239. package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
  240. package/lib/client/pages/admin/Taxonomies.js +130 -0
  241. package/lib/client/pages/admin/Tokens.d.ts +9 -0
  242. package/lib/client/pages/admin/Tokens.js +260 -0
  243. package/lib/client/pages/admin/Tools.d.ts +12 -0
  244. package/lib/client/pages/admin/Tools.js +111 -0
  245. package/lib/client/pages/admin/Users.d.ts +13 -0
  246. package/lib/client/pages/admin/Users.js +313 -0
  247. package/lib/client/pages/api-reference.d.ts +33 -0
  248. package/lib/client/pages/api-reference.js +198 -0
  249. package/lib/client/styles.css +37 -0
  250. package/lib/config.d.ts +24 -0
  251. package/lib/config.js +39 -0
  252. package/lib/controllers/AdminController.d.ts +46 -0
  253. package/lib/controllers/AdminController.js +134 -0
  254. package/lib/controllers/AuthController.d.ts +15 -0
  255. package/lib/controllers/AuthController.js +194 -0
  256. package/lib/controllers/AuthorController.d.ts +17 -0
  257. package/lib/controllers/AuthorController.js +19 -0
  258. package/lib/controllers/CategoryController.d.ts +10 -0
  259. package/lib/controllers/CategoryController.js +88 -0
  260. package/lib/controllers/CommentController.d.ts +68 -0
  261. package/lib/controllers/CommentController.js +438 -0
  262. package/lib/controllers/ContentTypeController.d.ts +24 -0
  263. package/lib/controllers/ContentTypeController.js +91 -0
  264. package/lib/controllers/EmailVerificationController.d.ts +33 -0
  265. package/lib/controllers/EmailVerificationController.js +116 -0
  266. package/lib/controllers/ExportController.d.ts +15 -0
  267. package/lib/controllers/ExportController.js +41 -0
  268. package/lib/controllers/FeedController.d.ts +14 -0
  269. package/lib/controllers/FeedController.js +246 -0
  270. package/lib/controllers/HealthController.d.ts +21 -0
  271. package/lib/controllers/HealthController.js +176 -0
  272. package/lib/controllers/HomeController.d.ts +12 -0
  273. package/lib/controllers/HomeController.js +16 -0
  274. package/lib/controllers/MediaController.d.ts +24 -0
  275. package/lib/controllers/MediaController.js +189 -0
  276. package/lib/controllers/NavigationController.d.ts +22 -0
  277. package/lib/controllers/NavigationController.js +176 -0
  278. package/lib/controllers/PageController.d.ts +13 -0
  279. package/lib/controllers/PageController.js +172 -0
  280. package/lib/controllers/PasskeyController.d.ts +36 -0
  281. package/lib/controllers/PasskeyController.js +201 -0
  282. package/lib/controllers/PasswordResetController.d.ts +44 -0
  283. package/lib/controllers/PasswordResetController.js +160 -0
  284. package/lib/controllers/PostController.d.ts +51 -0
  285. package/lib/controllers/PostController.js +538 -0
  286. package/lib/controllers/PostLockController.d.ts +62 -0
  287. package/lib/controllers/PostLockController.js +101 -0
  288. package/lib/controllers/ProfileController.d.ts +13 -0
  289. package/lib/controllers/ProfileController.js +160 -0
  290. package/lib/controllers/PublicApiController.d.ts +23 -0
  291. package/lib/controllers/PublicApiController.js +100 -0
  292. package/lib/controllers/RedirectController.d.ts +32 -0
  293. package/lib/controllers/RedirectController.js +95 -0
  294. package/lib/controllers/SettingsController.d.ts +28 -0
  295. package/lib/controllers/SettingsController.js +105 -0
  296. package/lib/controllers/SnippetController.d.ts +27 -0
  297. package/lib/controllers/SnippetController.js +123 -0
  298. package/lib/controllers/TagController.d.ts +9 -0
  299. package/lib/controllers/TagController.js +70 -0
  300. package/lib/controllers/TaxonomyController.d.ts +24 -0
  301. package/lib/controllers/TaxonomyController.js +149 -0
  302. package/lib/controllers/TokenController.d.ts +27 -0
  303. package/lib/controllers/TokenController.js +83 -0
  304. package/lib/controllers/TwoFactorController.d.ts +31 -0
  305. package/lib/controllers/TwoFactorController.js +213 -0
  306. package/lib/controllers/UserController.d.ts +110 -0
  307. package/lib/controllers/UserController.js +504 -0
  308. package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
  309. package/lib/features/analytics/AnalyticsPage.js +123 -0
  310. package/lib/features/analytics/admin.d.ts +3 -0
  311. package/lib/features/analytics/admin.js +9 -0
  312. package/lib/features/analytics/controller.d.ts +19 -0
  313. package/lib/features/analytics/controller.js +79 -0
  314. package/lib/features/analytics/helpers.d.ts +84 -0
  315. package/lib/features/analytics/helpers.js +181 -0
  316. package/lib/features/analytics/i18n/es.d.ts +4 -0
  317. package/lib/features/analytics/i18n/es.js +31 -0
  318. package/lib/features/analytics/index.d.ts +28 -0
  319. package/lib/features/analytics/index.js +91 -0
  320. package/lib/features/analytics/manifest.d.ts +8 -0
  321. package/lib/features/analytics/manifest.js +18 -0
  322. package/lib/features/analytics/model.d.ts +130 -0
  323. package/lib/features/analytics/model.js +206 -0
  324. package/lib/features/members/Member.d.ts +93 -0
  325. package/lib/features/members/Member.js +194 -0
  326. package/lib/features/members/MemberAdminController.d.ts +60 -0
  327. package/lib/features/members/MemberAdminController.js +262 -0
  328. package/lib/features/members/MemberController.d.ts +88 -0
  329. package/lib/features/members/MemberController.js +250 -0
  330. package/lib/features/members/MembersPage.d.ts +10 -0
  331. package/lib/features/members/MembersPage.js +216 -0
  332. package/lib/features/members/PostAccessBox.d.ts +15 -0
  333. package/lib/features/members/PostAccessBox.js +70 -0
  334. package/lib/features/members/admin.d.ts +3 -0
  335. package/lib/features/members/admin.js +12 -0
  336. package/lib/features/members/csv.d.ts +21 -0
  337. package/lib/features/members/csv.js +74 -0
  338. package/lib/features/members/events.d.ts +34 -0
  339. package/lib/features/members/events.js +34 -0
  340. package/lib/features/members/i18n/es.d.ts +4 -0
  341. package/lib/features/members/i18n/es.js +106 -0
  342. package/lib/features/members/index.d.ts +44 -0
  343. package/lib/features/members/index.js +106 -0
  344. package/lib/features/members/manifest.d.ts +8 -0
  345. package/lib/features/members/manifest.js +18 -0
  346. package/lib/features/members/middleware.d.ts +42 -0
  347. package/lib/features/members/middleware.js +74 -0
  348. package/lib/features/members/newsletter.d.ts +177 -0
  349. package/lib/features/members/newsletter.js +439 -0
  350. package/lib/features/members/rate-limits.d.ts +34 -0
  351. package/lib/features/members/rate-limits.js +50 -0
  352. package/lib/features/members/request.d.ts +13 -0
  353. package/lib/features/members/request.js +6 -0
  354. package/lib/features/members/routes.d.ts +15 -0
  355. package/lib/features/members/routes.js +59 -0
  356. package/lib/features/members/session.d.ts +102 -0
  357. package/lib/features/members/session.js +158 -0
  358. package/lib/features/members/settings.d.ts +14 -0
  359. package/lib/features/members/settings.js +23 -0
  360. package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
  361. package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
  362. package/lib/features/mysendbox/admin.d.ts +3 -0
  363. package/lib/features/mysendbox/admin.js +9 -0
  364. package/lib/features/mysendbox/broadcasts.d.ts +61 -0
  365. package/lib/features/mysendbox/broadcasts.js +124 -0
  366. package/lib/features/mysendbox/client.d.ts +95 -0
  367. package/lib/features/mysendbox/client.js +61 -0
  368. package/lib/features/mysendbox/config.d.ts +27 -0
  369. package/lib/features/mysendbox/config.js +74 -0
  370. package/lib/features/mysendbox/contacts.d.ts +121 -0
  371. package/lib/features/mysendbox/contacts.js +378 -0
  372. package/lib/features/mysendbox/controller.d.ts +11 -0
  373. package/lib/features/mysendbox/controller.js +47 -0
  374. package/lib/features/mysendbox/i18n/es.d.ts +4 -0
  375. package/lib/features/mysendbox/i18n/es.js +28 -0
  376. package/lib/features/mysendbox/index.d.ts +18 -0
  377. package/lib/features/mysendbox/index.js +71 -0
  378. package/lib/features/mysendbox/manifest.d.ts +7 -0
  379. package/lib/features/mysendbox/manifest.js +6 -0
  380. package/lib/features/mysendbox/routes.d.ts +6 -0
  381. package/lib/features/mysendbox/routes.js +14 -0
  382. package/lib/features/mysendbox/webhook.d.ts +23 -0
  383. package/lib/features/mysendbox/webhook.js +104 -0
  384. package/lib/features/theme/OEmbedController.d.ts +31 -0
  385. package/lib/features/theme/OEmbedController.js +128 -0
  386. package/lib/features/theme/ThemeController.d.ts +20 -0
  387. package/lib/features/theme/ThemeController.js +256 -0
  388. package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
  389. package/lib/features/theme/ThemeSettingsCard.js +12 -0
  390. package/lib/features/theme/admin.d.ts +3 -0
  391. package/lib/features/theme/admin.js +9 -0
  392. package/lib/features/theme/html.d.ts +48 -0
  393. package/lib/features/theme/html.js +97 -0
  394. package/lib/features/theme/i18n/es.d.ts +4 -0
  395. package/lib/features/theme/i18n/es.js +9 -0
  396. package/lib/features/theme/index.d.ts +11 -0
  397. package/lib/features/theme/index.js +23 -0
  398. package/lib/features/theme/manifest.d.ts +7 -0
  399. package/lib/features/theme/manifest.js +6 -0
  400. package/lib/features/theme/oembed.d.ts +36 -0
  401. package/lib/features/theme/oembed.js +58 -0
  402. package/lib/features/theme/routes.d.ts +17 -0
  403. package/lib/features/theme/routes.js +54 -0
  404. package/lib/features/theme/templates.d.ts +103 -0
  405. package/lib/features/theme/templates.js +283 -0
  406. package/lib/features.d.ts +15 -0
  407. package/lib/features.js +6 -0
  408. package/lib/features.manifest.d.ts +10 -0
  409. package/lib/features.manifest.js +6 -0
  410. package/lib/helpers/access.d.ts +62 -0
  411. package/lib/helpers/access.js +92 -0
  412. package/lib/helpers/api.d.ts +20 -0
  413. package/lib/helpers/api.js +44 -0
  414. package/lib/helpers/comment-guard.d.ts +145 -0
  415. package/lib/helpers/comment-guard.js +253 -0
  416. package/lib/helpers/comment-mail.d.ts +53 -0
  417. package/lib/helpers/comment-mail.js +188 -0
  418. package/lib/helpers/content-model.d.ts +50 -0
  419. package/lib/helpers/content-model.js +84 -0
  420. package/lib/helpers/content-paths.d.ts +107 -0
  421. package/lib/helpers/content-paths.js +200 -0
  422. package/lib/helpers/export-data.d.ts +85 -0
  423. package/lib/helpers/export-data.js +229 -0
  424. package/lib/helpers/gating.d.ts +53 -0
  425. package/lib/helpers/gating.js +83 -0
  426. package/lib/helpers/health.d.ts +91 -0
  427. package/lib/helpers/health.js +279 -0
  428. package/lib/helpers/heartbeat.d.ts +35 -0
  429. package/lib/helpers/heartbeat.js +55 -0
  430. package/lib/helpers/image-size.d.ts +18 -0
  431. package/lib/helpers/image-size.js +83 -0
  432. package/lib/helpers/images.d.ts +29 -0
  433. package/lib/helpers/images.js +41 -0
  434. package/lib/helpers/mail-templates.d.ts +11 -0
  435. package/lib/helpers/mail-templates.js +42 -0
  436. package/lib/helpers/publish-due.d.ts +28 -0
  437. package/lib/helpers/publish-due.js +67 -0
  438. package/lib/helpers/redirects.d.ts +43 -0
  439. package/lib/helpers/redirects.js +80 -0
  440. package/lib/helpers/seo-fields.d.ts +13 -0
  441. package/lib/helpers/seo-fields.js +52 -0
  442. package/lib/helpers/session.d.ts +30 -0
  443. package/lib/helpers/session.js +27 -0
  444. package/lib/helpers/site-settings.d.ts +98 -0
  445. package/lib/helpers/site-settings.js +232 -0
  446. package/lib/helpers/site.d.ts +14 -0
  447. package/lib/helpers/site.js +23 -0
  448. package/lib/helpers/write-hooks.d.ts +33 -0
  449. package/lib/helpers/write-hooks.js +37 -0
  450. package/lib/hooks.d.ts +17 -0
  451. package/lib/hooks.js +101 -0
  452. package/lib/host/core-tasks.d.ts +4 -0
  453. package/lib/host/core-tasks.js +26 -0
  454. package/lib/host/cron.d.ts +39 -0
  455. package/lib/host/cron.js +85 -0
  456. package/lib/host/enabled.d.ts +4 -0
  457. package/lib/host/enabled.js +40 -0
  458. package/lib/host/index.d.ts +81 -0
  459. package/lib/host/index.js +87 -0
  460. package/lib/host/manifest.d.ts +34 -0
  461. package/lib/host/manifest.js +7 -0
  462. package/lib/host/menu.d.ts +18 -0
  463. package/lib/host/menu.js +15 -0
  464. package/lib/main.d.ts +1 -0
  465. package/lib/main.js +24 -0
  466. package/lib/middleware/api-auth.d.ts +59 -0
  467. package/lib/middleware/api-auth.js +164 -0
  468. package/lib/middleware/auth.d.ts +49 -0
  469. package/lib/middleware/auth.js +112 -0
  470. package/lib/middleware/cache.d.ts +17 -0
  471. package/lib/middleware/cache.js +52 -0
  472. package/lib/middleware/rate-limits.d.ts +199 -0
  473. package/lib/middleware/rate-limits.js +276 -0
  474. package/lib/middleware/viewer.d.ts +13 -0
  475. package/lib/middleware/viewer.js +16 -0
  476. package/lib/models/Category.d.ts +24 -0
  477. package/lib/models/Category.js +102 -0
  478. package/lib/models/Comment.d.ts +120 -0
  479. package/lib/models/Comment.js +283 -0
  480. package/lib/models/ContentType.d.ts +142 -0
  481. package/lib/models/ContentType.js +462 -0
  482. package/lib/models/Credential.d.ts +21 -0
  483. package/lib/models/Credential.js +31 -0
  484. package/lib/models/Media.d.ts +53 -0
  485. package/lib/models/Media.js +132 -0
  486. package/lib/models/Menu.d.ts +131 -0
  487. package/lib/models/Menu.js +312 -0
  488. package/lib/models/Page.d.ts +55 -0
  489. package/lib/models/Page.js +218 -0
  490. package/lib/models/Post.d.ts +136 -0
  491. package/lib/models/Post.js +406 -0
  492. package/lib/models/PostLock.d.ts +67 -0
  493. package/lib/models/PostLock.js +112 -0
  494. package/lib/models/PostRevision.d.ts +45 -0
  495. package/lib/models/PostRevision.js +82 -0
  496. package/lib/models/PublicContent.d.ts +283 -0
  497. package/lib/models/PublicContent.js +577 -0
  498. package/lib/models/Redirect.d.ts +123 -0
  499. package/lib/models/Redirect.js +225 -0
  500. package/lib/models/Settings.d.ts +61 -0
  501. package/lib/models/Settings.js +128 -0
  502. package/lib/models/Snippet.d.ts +36 -0
  503. package/lib/models/Snippet.js +64 -0
  504. package/lib/models/Tag.d.ts +23 -0
  505. package/lib/models/Tag.js +117 -0
  506. package/lib/models/Taxonomy.d.ts +127 -0
  507. package/lib/models/Taxonomy.js +321 -0
  508. package/lib/models/TwoFactor.d.ts +26 -0
  509. package/lib/models/TwoFactor.js +60 -0
  510. package/lib/models/User.d.ts +49 -0
  511. package/lib/models/User.js +128 -0
  512. package/lib/models/derive.d.ts +69 -0
  513. package/lib/models/derive.js +81 -0
  514. package/lib/models/pagination.d.ts +30 -0
  515. package/lib/models/pagination.js +36 -0
  516. package/lib/models/visibility.d.ts +31 -0
  517. package/lib/models/visibility.js +47 -0
  518. package/lib/routes/App.d.ts +2 -0
  519. package/lib/routes/App.js +146 -0
  520. package/lib/routes/api/admin.d.ts +6 -0
  521. package/lib/routes/api/admin.js +11 -0
  522. package/lib/routes/api/auth.d.ts +6 -0
  523. package/lib/routes/api/auth.js +24 -0
  524. package/lib/routes/api/authors.d.ts +5 -0
  525. package/lib/routes/api/authors.js +8 -0
  526. package/lib/routes/api/categories.d.ts +8 -0
  527. package/lib/routes/api/categories.js +15 -0
  528. package/lib/routes/api/comments.d.ts +8 -0
  529. package/lib/routes/api/comments.js +35 -0
  530. package/lib/routes/api/content-model.d.ts +17 -0
  531. package/lib/routes/api/content-model.js +67 -0
  532. package/lib/routes/api/cron.d.ts +6 -0
  533. package/lib/routes/api/cron.js +9 -0
  534. package/lib/routes/api/export.d.ts +5 -0
  535. package/lib/routes/api/export.js +11 -0
  536. package/lib/routes/api/feed.d.ts +5 -0
  537. package/lib/routes/api/feed.js +16 -0
  538. package/lib/routes/api/media.d.ts +8 -0
  539. package/lib/routes/api/media.js +25 -0
  540. package/lib/routes/api/navigation.d.ts +12 -0
  541. package/lib/routes/api/navigation.js +17 -0
  542. package/lib/routes/api/ops.d.ts +9 -0
  543. package/lib/routes/api/ops.js +19 -0
  544. package/lib/routes/api/pages.d.ts +8 -0
  545. package/lib/routes/api/pages.js +21 -0
  546. package/lib/routes/api/passkeys.d.ts +7 -0
  547. package/lib/routes/api/passkeys.js +13 -0
  548. package/lib/routes/api/posts.d.ts +8 -0
  549. package/lib/routes/api/posts.js +39 -0
  550. package/lib/routes/api/profile.d.ts +6 -0
  551. package/lib/routes/api/profile.js +8 -0
  552. package/lib/routes/api/redirects.d.ts +12 -0
  553. package/lib/routes/api/redirects.js +13 -0
  554. package/lib/routes/api/settings.d.ts +8 -0
  555. package/lib/routes/api/settings.js +15 -0
  556. package/lib/routes/api/snippets.d.ts +15 -0
  557. package/lib/routes/api/snippets.js +16 -0
  558. package/lib/routes/api/tags.d.ts +8 -0
  559. package/lib/routes/api/tags.js +14 -0
  560. package/lib/routes/api/tokens.d.ts +7 -0
  561. package/lib/routes/api/tokens.js +15 -0
  562. package/lib/routes/api/two-factor.d.ts +7 -0
  563. package/lib/routes/api/two-factor.js +15 -0
  564. package/lib/routes/api/users.d.ts +8 -0
  565. package/lib/routes/api/users.js +25 -0
  566. package/lib/routes/api/v1.d.ts +12 -0
  567. package/lib/routes/api/v1.js +55 -0
  568. package/lib/routes/api/verification.d.ts +6 -0
  569. package/lib/routes/api/verification.js +11 -0
  570. package/lib/server/index.d.ts +24 -0
  571. package/lib/server/index.js +110 -0
  572. package/lib/types/index.d.ts +298 -0
  573. package/lib/types/index.js +1 -0
  574. package/lib/vite.d.ts +2 -0
  575. package/lib/vite.js +101 -0
  576. package/mail/comment-moderation.html +27 -0
  577. package/mail/comment-moderation.txt +13 -0
  578. package/mail/comment-reply.html +28 -0
  579. package/mail/comment-reply.txt +14 -0
  580. package/mail/invitation.html +25 -0
  581. package/mail/invitation.txt +11 -0
  582. package/mail/member-magic-link.html +23 -0
  583. package/mail/member-magic-link.txt +10 -0
  584. package/mail/newsletter.html +26 -0
  585. package/mail/newsletter.txt +13 -0
  586. package/mail/password-reset.html +26 -0
  587. package/mail/password-reset.txt +10 -0
  588. package/mail/verify-email.html +25 -0
  589. package/mail/verify-email.txt +8 -0
  590. package/package.json +85 -4
@@ -0,0 +1,67 @@
1
+ import { timingSafeEqual } from 'node:crypto';
2
+ import { hooks, HOOKS } from '@basicbenframework/core/hooks';
3
+ import { getDb } from '@basicbenframework/core/db';
4
+ import { Post } from "../models/Post.js";
5
+ import { recordHeartbeat, HEARTBEATS } from "./heartbeat.js";
6
+ /**
7
+ * Tell listeners about scheduled posts whose time has come.
8
+ *
9
+ * A scheduled post appears on the public site by itself — every read filters
10
+ * on `publish_at` — but nothing *happens* at that moment, so a webhook
11
+ * consumer rebuilding a static site would never hear about it. This finds the
12
+ * posts that have gone live since they were last announced, fires
13
+ * `post.updated` for each (the same event a manual publish fires, so existing
14
+ * consumers need no changes), and marks them announced.
15
+ *
16
+ * Three things call it, so it works on any host:
17
+ * - an interval on a long-running server (see `src/hooks.ts`);
18
+ * - `GET /api/cron/publish-due`, for a platform scheduler such as Vercel Cron;
19
+ * - the content API, at most once a minute, so a serverless deploy with no
20
+ * scheduler still announces a post the first time anyone reads the site.
21
+ */
22
+ export async function publishDue() {
23
+ const due = await Post.dueForNotification();
24
+ for (const row of due) {
25
+ // Marked first: at-most-once, the same promise webhooks make everywhere
26
+ // else. Two overlapping ticks must not announce a post twice.
27
+ await Post.markNotified(row.id);
28
+ const post = await Post.find(row.id);
29
+ await hooks.fire(HOOKS.POST_UPDATED, { post, previous: row, userId: null, scheduled: true });
30
+ }
31
+ // So the site health page can tell "nothing was due" from "nothing has been
32
+ // checking". At most one write a minute — this whole function is throttled
33
+ // to that — and best-effort: the announcements above already happened.
34
+ await recordHeartbeat((await getDb()), HEARTBEATS.PUBLISH_DUE, { announced: due.length });
35
+ return due.length;
36
+ }
37
+ let lastRun = 0;
38
+ /** Middleware: run `publishDue` if a minute has passed since it last ran. */
39
+ export async function publishDueOpportunistically(_req, _res, next) {
40
+ if (Date.now() - lastRun > 60_000) {
41
+ lastRun = Date.now();
42
+ try {
43
+ await publishDue();
44
+ }
45
+ catch (err) {
46
+ console.error('[publish-due]', err.message);
47
+ }
48
+ }
49
+ next();
50
+ }
51
+ /**
52
+ * `GET /api/cron/publish-due`, for a platform scheduler.
53
+ *
54
+ * Requires `Authorization: Bearer $CRON_SECRET` — the header Vercel Cron sends
55
+ * — so the endpoint cannot be used to make the server do work on demand. With
56
+ * no CRON_SECRET configured it is disabled.
57
+ */
58
+ export async function publishDueEndpoint(req, res) {
59
+ const secret = process.env.CRON_SECRET;
60
+ const given = String(req.headers.authorization ?? '');
61
+ const expected = `Bearer ${secret}`;
62
+ if (!secret || given.length !== expected.length || !timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
63
+ return res.json({ error: 'Not found' }, 404);
64
+ }
65
+ lastRun = Date.now();
66
+ res.json({ announced: await publishDue() });
67
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Automatic redirects when published content moves.
3
+ *
4
+ * Called from the post and page update paths. Kept out of the controllers so
5
+ * each one gains a single line, and so the rule — which changes earn a
6
+ * redirect, and what path each kind lives at — is written once.
7
+ */
8
+ /**
9
+ * Record that `kind` content moved from `oldPath` to `newPath`: a 301 from the
10
+ * old path, chains collapsed, loops avoided. See `Redirect.recordSlugChange`.
11
+ *
12
+ * Never throws. The save that triggered this has already been written; failing
13
+ * the request now would tell the editor their change was lost when it was not.
14
+ * A missed redirect is logged and can be added by hand.
15
+ */
16
+ export declare function recordSlugChange(kind: 'post' | 'page', oldPath: string, newPath: string): Promise<void>;
17
+ /**
18
+ * Content now lives at `path`: drop any redirect away from it, which would
19
+ * otherwise shadow it. Never throws, for the same reason as above.
20
+ */
21
+ export declare function releasePath(path: string): Promise<void>;
22
+ interface Movable {
23
+ id: number;
24
+ slug?: string | null;
25
+ published?: boolean | number | null;
26
+ deleted_at?: string | null;
27
+ /** The post's content type key; absent or `post` means `/blog`. */
28
+ post_type?: string | null;
29
+ }
30
+ /**
31
+ * Compare a post or page before and after an update, and redirect if its
32
+ * public URL changed.
33
+ *
34
+ * Only content that was public before the save: a draft's slug was never a
35
+ * URL anyone could have linked to, so redirecting from it would only litter
36
+ * the table. A post without a slug answered to its id, and still does — the
37
+ * content API accepts an id wherever it accepts a slug — so it needs nothing.
38
+ */
39
+ export declare function redirectIfSlugChanged(kind: 'post' | 'page', before: Movable, after: Movable | null | undefined, routeBases?: {
40
+ before?: string | null;
41
+ after?: string | null;
42
+ }): Promise<void>;
43
+ export {};
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Automatic redirects when published content moves.
3
+ *
4
+ * Called from the post and page update paths. Kept out of the controllers so
5
+ * each one gains a single line, and so the rule — which changes earn a
6
+ * redirect, and what path each kind lives at — is written once.
7
+ */
8
+ import { Redirect } from "../models/Redirect.js";
9
+ import { entryPath, pagePath } from "./content-paths.js";
10
+ import { routeBaseFor } from "../models/ContentType.js";
11
+ /**
12
+ * Record that `kind` content moved from `oldPath` to `newPath`: a 301 from the
13
+ * old path, chains collapsed, loops avoided. See `Redirect.recordSlugChange`.
14
+ *
15
+ * Never throws. The save that triggered this has already been written; failing
16
+ * the request now would tell the editor their change was lost when it was not.
17
+ * A missed redirect is logged and can be added by hand.
18
+ */
19
+ export async function recordSlugChange(kind, oldPath, newPath) {
20
+ try {
21
+ await Redirect.recordSlugChange(kind, oldPath, newPath);
22
+ }
23
+ catch (error) {
24
+ console.error(`[redirects] could not record ${kind} move ${oldPath} -> ${newPath}:`, error);
25
+ }
26
+ }
27
+ /**
28
+ * Content now lives at `path`: drop any redirect away from it, which would
29
+ * otherwise shadow it. Never throws, for the same reason as above.
30
+ */
31
+ export async function releasePath(path) {
32
+ try {
33
+ await Redirect.releasePath(path);
34
+ }
35
+ catch (error) {
36
+ console.error(`[redirects] could not release ${path}:`, error);
37
+ }
38
+ }
39
+ /** A content type's route base, or null for the built-in type. Never throws. */
40
+ async function baseFor(type) {
41
+ if (!type || type === 'post')
42
+ return null;
43
+ try {
44
+ return await routeBaseFor(type);
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
50
+ /**
51
+ * Compare a post or page before and after an update, and redirect if its
52
+ * public URL changed.
53
+ *
54
+ * Only content that was public before the save: a draft's slug was never a
55
+ * URL anyone could have linked to, so redirecting from it would only litter
56
+ * the table. A post without a slug answered to its id, and still does — the
57
+ * content API accepts an id wherever it accepts a slug — so it needs nothing.
58
+ */
59
+ export async function redirectIfSlugChanged(kind, before, after,
60
+ // A post of a custom content type lives under its type's route base, and
61
+ // changing its type moves it as surely as changing its slug. Omitted, both
62
+ // are `/blog` — exactly the behaviour before content types existed.
63
+ routeBases = {}) {
64
+ if (!after || !before.slug || !after.slug)
65
+ return;
66
+ if (!before.published || before.deleted_at)
67
+ return;
68
+ // Looked up from the rows themselves when the caller did not say, so the
69
+ // controller's one-line call covers custom types without knowing about them.
70
+ // A plain post never touches the database here.
71
+ const beforeBase = routeBases.before !== undefined ? routeBases.before : await baseFor(before.post_type);
72
+ const afterBase = routeBases.after !== undefined
73
+ ? routeBases.after
74
+ : after.post_type === before.post_type ? beforeBase : await baseFor(after.post_type);
75
+ const from = kind === 'post' ? entryPath(beforeBase, before.slug) : pagePath(before.slug);
76
+ const to = kind === 'post' ? entryPath(afterBase, after.slug) : pagePath(after.slug);
77
+ if (from === to)
78
+ return;
79
+ await recordSlugChange(kind, from, to);
80
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The social-card and indexing fields a post or page editor sends.
3
+ *
4
+ * Shared by both controllers so the two cannot accept different things. Absent
5
+ * keys stay absent, so a client that knows nothing about these fields does not
6
+ * blank them on save.
7
+ */
8
+ export declare function seoFields(body: unknown): {
9
+ values: Record<string, unknown>;
10
+ } | {
11
+ errors: Record<string, string[]>;
12
+ };
13
+ export declare const SEO_COLUMNS: string[];
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The social-card and indexing fields a post or page editor sends.
3
+ *
4
+ * Shared by both controllers so the two cannot accept different things. Absent
5
+ * keys stay absent, so a client that knows nothing about these fields does not
6
+ * blank them on save.
7
+ */
8
+ export function seoFields(body) {
9
+ const payload = (body ?? {});
10
+ const values = {};
11
+ const errors = {};
12
+ for (const key of ['og_title', 'og_description', 'twitter_title', 'twitter_description']) {
13
+ if (key in payload) {
14
+ const value = payload[key];
15
+ values[key] = typeof value === 'string' && value.trim() ? value.trim().slice(0, 300) : null;
16
+ }
17
+ }
18
+ // Media ids or nothing. The empty string an unset picker sends would
19
+ // otherwise become a foreign key of '' and fail the write.
20
+ for (const key of ['og_image', 'twitter_image']) {
21
+ if (key in payload) {
22
+ const id = Number(payload[key]);
23
+ values[key] = Number.isInteger(id) && id > 0 ? id : null;
24
+ }
25
+ }
26
+ // Emitted into the <head> of every page that renders this, so only an
27
+ // absolute http(s) URL is accepted.
28
+ if ('canonical_url' in payload) {
29
+ const raw = String(payload.canonical_url ?? '').trim();
30
+ if (!raw) {
31
+ values.canonical_url = null;
32
+ }
33
+ else {
34
+ try {
35
+ const url = new URL(raw);
36
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
37
+ throw new Error();
38
+ values.canonical_url = url.toString();
39
+ }
40
+ catch {
41
+ errors.canonical_url = ['Canonical URL must be an absolute http or https URL'];
42
+ }
43
+ }
44
+ }
45
+ if ('noindex' in payload)
46
+ values.noindex = payload.noindex ? 1 : 0;
47
+ return Object.keys(errors).length ? { errors } : { values };
48
+ }
49
+ export const SEO_COLUMNS = [
50
+ 'og_title', 'og_description', 'og_image', 'twitter_title', 'twitter_description',
51
+ 'twitter_image', 'canonical_url', 'noindex'
52
+ ];
@@ -0,0 +1,30 @@
1
+ /** What a session token carries. */
2
+ export interface SessionClaims {
3
+ userId: number;
4
+ role?: string;
5
+ email_verified?: boolean;
6
+ /** The account's `token_version` when this token was issued. */
7
+ tv?: number;
8
+ }
9
+ /** The account fields a session is built from. */
10
+ interface SessionUser {
11
+ id: number;
12
+ role?: string | null;
13
+ email_verified?: number | boolean | null;
14
+ token_version?: number | null;
15
+ }
16
+ /**
17
+ * Mint a session token.
18
+ *
19
+ * The one place tokens are issued, so every one carries the account's token
20
+ * version — a token minted without it could never be revoked.
21
+ */
22
+ export declare function issueSessionToken(user: SessionUser): string;
23
+ /**
24
+ * End every session an account has.
25
+ *
26
+ * Tokens issued before this call carry the old version and stop verifying on
27
+ * their next request.
28
+ */
29
+ export declare function revokeSessions(userId: number): Promise<void>;
30
+ export {};
@@ -0,0 +1,27 @@
1
+ import { signJwt } from '@basicbenframework/core/auth';
2
+ import { DEFAULT_ROLE } from '@basicbenframework/core/auth/permissions';
3
+ import { getDb } from '@basicbenframework/core/db';
4
+ /**
5
+ * Mint a session token.
6
+ *
7
+ * The one place tokens are issued, so every one carries the account's token
8
+ * version — a token minted without it could never be revoked.
9
+ */
10
+ export function issueSessionToken(user) {
11
+ return signJwt({
12
+ userId: user.id,
13
+ role: user.role ?? DEFAULT_ROLE,
14
+ email_verified: Boolean(user.email_verified),
15
+ tv: Number(user.token_version ?? 0)
16
+ }, process.env.APP_KEY, { expiresIn: '7d' });
17
+ }
18
+ /**
19
+ * End every session an account has.
20
+ *
21
+ * Tokens issued before this call carry the old version and stop verifying on
22
+ * their next request.
23
+ */
24
+ export async function revokeSessions(userId) {
25
+ const db = await getDb();
26
+ await db.run('UPDATE users SET token_version = token_version + 1 WHERE id = ?', [userId]);
27
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Every setting the admin may write, and what a valid value for each looks like.
3
+ *
4
+ * `PUT /api/settings` used to store whatever keys it was sent. That made the
5
+ * settings table a free-form key/value store for anyone holding
6
+ * `settings.manage`, and — worse — a typo in a client (`alow_comments`) saved
7
+ * cleanly and did nothing, with no error to say so. An allowlist turns both
8
+ * into a 422 naming the key.
9
+ *
10
+ * Adding a setting means adding it here. That is deliberate: it is the one
11
+ * place that says what the setting is, which group it belongs to and what it
12
+ * accepts, and the admin and the public site API both read from it.
13
+ *
14
+ * No database access in this file, so tests import it directly.
15
+ */
16
+ export type SettingGroup = 'general' | 'reading' | 'discussion' | 'integrations' | 'identity' | 'locale' | 'code_injection' | (string & {});
17
+ /** A validator returns the value to store, or an error message. */
18
+ export type Check = (value: unknown) => {
19
+ value: string;
20
+ } | {
21
+ error: string;
22
+ };
23
+ export interface SettingDefinition {
24
+ group: SettingGroup;
25
+ check: Check;
26
+ }
27
+ /**
28
+ * An IANA time zone name, such as `Europe/London` or `UTC`.
29
+ *
30
+ * `Intl.DateTimeFormat` is the authority on which names exist — it throws a
31
+ * RangeError for one it does not know — but since ES2024 it also accepts raw
32
+ * offsets like `+01:00`. An offset is not a time zone (it has no daylight
33
+ * saving), and a front end formatting dates with one would be an hour wrong
34
+ * for half the year, so the shape is checked first.
35
+ */
36
+ export declare function isTimeZone(value: string): boolean;
37
+ /**
38
+ * A BCP 47 language tag, stored in canonical form (`en-gb` becomes `en-GB`).
39
+ *
40
+ * `Intl.getCanonicalLocales` throws for anything that is not well-formed, and
41
+ * canonicalising means a front end comparing tags does not have to.
42
+ */
43
+ export declare function canonicalLocale(value: string): string | null;
44
+ /**
45
+ * The known settings.
46
+ *
47
+ * Code injection is HTML a front end inserts verbatim into every page's
48
+ * <head> or before </body> — analytics snippets, verification tags, a font
49
+ * stylesheet. It is intentionally **not** sanitised: a sanitiser would strip
50
+ * exactly the <script> tags it exists to carry. What keeps it safe is who can
51
+ * write it — these routes require `settings.manage`, which only the admin role
52
+ * holds — the same trust WordPress and Ghost extend to their administrators.
53
+ */
54
+ export declare const SETTINGS: Record<string, SettingDefinition>;
55
+ /**
56
+ * The validators, for a feature defining its own settings
57
+ * (`host.settings.define`). Same rules as core's, so a feature's settings are
58
+ * checked exactly as strictly.
59
+ */
60
+ export declare const checks: {
61
+ text: (max: number, { required }?: {
62
+ required?: boolean | undefined;
63
+ }) => Check;
64
+ flag: Check;
65
+ integer: (min: number, max: number) => Check;
66
+ oneOf: (allowed: readonly string[]) => Check;
67
+ imageUrl: Check;
68
+ urlList: Check;
69
+ timeZone: Check;
70
+ locale: Check;
71
+ emailOrBlank: Check;
72
+ httpUrlOrBlank: Check;
73
+ };
74
+ /**
75
+ * Add a feature's settings to the allowlist. A key core or another feature
76
+ * already defines is refused: two owners for one setting is a bug to catch at
77
+ * boot, not a silent overwrite.
78
+ */
79
+ export declare function defineSettings(definitions: Record<string, SettingDefinition>): void;
80
+ export declare function isKnownSetting(key: string): boolean;
81
+ export type ValidatedSettings = {
82
+ values: Record<string, {
83
+ value: string;
84
+ group: SettingGroup;
85
+ }>;
86
+ } | {
87
+ errors: Record<string, string[]>;
88
+ };
89
+ /**
90
+ * Validate a batch of settings. All or nothing: one bad key and nothing is
91
+ * written, so a save never leaves the site half-configured.
92
+ */
93
+ export declare function validateSettings(input: unknown): ValidatedSettings;
94
+ /** Defaults the public site API reports for settings nobody has set yet. */
95
+ export declare const SITE_DEFAULTS: {
96
+ timezone: string;
97
+ locale: string;
98
+ };
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Every setting the admin may write, and what a valid value for each looks like.
3
+ *
4
+ * `PUT /api/settings` used to store whatever keys it was sent. That made the
5
+ * settings table a free-form key/value store for anyone holding
6
+ * `settings.manage`, and — worse — a typo in a client (`alow_comments`) saved
7
+ * cleanly and did nothing, with no error to say so. An allowlist turns both
8
+ * into a 422 naming the key.
9
+ *
10
+ * Adding a setting means adding it here. That is deliberate: it is the one
11
+ * place that says what the setting is, which group it belongs to and what it
12
+ * accepts, and the admin and the public site API both read from it.
13
+ *
14
+ * No database access in this file, so tests import it directly.
15
+ */
16
+ import { isHttpUrl, isRelativePath, MAX_URL_LENGTH } from "./content-paths.js";
17
+ const text = (max, { required = false } = {}) => (value) => {
18
+ if (value === null || value === undefined)
19
+ value = '';
20
+ if (typeof value !== 'string' && typeof value !== 'number')
21
+ return { error: 'Must be text' };
22
+ const str = String(value);
23
+ if (required && str.trim() === '')
24
+ return { error: 'Required' };
25
+ if (str.length > max)
26
+ return { error: `Must be at most ${max} characters` };
27
+ return { value: str };
28
+ };
29
+ const flag = (value) => {
30
+ if (value === true || value === 'true')
31
+ return { value: 'true' };
32
+ if (value === false || value === 'false')
33
+ return { value: 'false' };
34
+ return { error: 'Must be true or false' };
35
+ };
36
+ const integer = (min, max) => (value) => {
37
+ const n = typeof value === 'number' ? value : Number(String(value ?? '').trim());
38
+ if (!Number.isInteger(n) || n < min || n > max) {
39
+ return { error: `Must be a whole number from ${min} to ${max}` };
40
+ }
41
+ return { value: String(n) };
42
+ };
43
+ /** One of a fixed list of values. Blank is allowed only if it is in the list. */
44
+ const oneOf = (allowed) => (value) => {
45
+ const str = value === null || value === undefined ? '' : String(value).trim();
46
+ return allowed.includes(str) ? { value: str } : { error: `Must be one of: ${allowed.map((v) => v || '(blank)').join(', ')}` };
47
+ };
48
+ /**
49
+ * An image reference: an absolute http(s) URL, or a path on this app such as
50
+ * `/uploads/logo.png` (what the media library hands out with local storage).
51
+ * Blank clears it.
52
+ */
53
+ const imageUrl = (value) => {
54
+ if (value === null || value === undefined || value === '')
55
+ return { value: '' };
56
+ if (typeof value !== 'string')
57
+ return { error: 'Must be a URL' };
58
+ const url = value.trim();
59
+ if (url.length > MAX_URL_LENGTH)
60
+ return { error: 'URL is too long' };
61
+ if (!isHttpUrl(url) && !isRelativePath(url)) {
62
+ return { error: 'Must be an http(s) URL or a path starting with /' };
63
+ }
64
+ return { value: url };
65
+ };
66
+ /**
67
+ * One http(s) URL per line. `getWebhookUrls()` already skips anything else at
68
+ * delivery time, but silently — refusing it here is what tells the admin.
69
+ */
70
+ const urlList = (value) => {
71
+ const checked = text(10_000)(value);
72
+ if ('error' in checked)
73
+ return checked;
74
+ const bad = checked.value
75
+ .split('\n')
76
+ .map(line => line.trim())
77
+ .filter(line => line !== '' && !isHttpUrl(line));
78
+ if (bad.length)
79
+ return { error: `Not an http(s) URL: ${bad[0]}` };
80
+ return checked;
81
+ };
82
+ /**
83
+ * An IANA time zone name, such as `Europe/London` or `UTC`.
84
+ *
85
+ * `Intl.DateTimeFormat` is the authority on which names exist — it throws a
86
+ * RangeError for one it does not know — but since ES2024 it also accepts raw
87
+ * offsets like `+01:00`. An offset is not a time zone (it has no daylight
88
+ * saving), and a front end formatting dates with one would be an hour wrong
89
+ * for half the year, so the shape is checked first.
90
+ */
91
+ export function isTimeZone(value) {
92
+ if (!/^[A-Za-z][A-Za-z0-9_+\-]*(\/[A-Za-z0-9_+\-]+)*$/.test(value))
93
+ return false;
94
+ try {
95
+ new Intl.DateTimeFormat('en', { timeZone: value });
96
+ return true;
97
+ }
98
+ catch {
99
+ return false;
100
+ }
101
+ }
102
+ const timeZone = (value) => {
103
+ if (value === null || value === undefined || value === '')
104
+ return { value: '' };
105
+ if (typeof value !== 'string' || !isTimeZone(value.trim())) {
106
+ return { error: 'Must be an IANA time zone, such as Europe/London or UTC' };
107
+ }
108
+ return { value: value.trim() };
109
+ };
110
+ /**
111
+ * A BCP 47 language tag, stored in canonical form (`en-gb` becomes `en-GB`).
112
+ *
113
+ * `Intl.getCanonicalLocales` throws for anything that is not well-formed, and
114
+ * canonicalising means a front end comparing tags does not have to.
115
+ */
116
+ export function canonicalLocale(value) {
117
+ try {
118
+ const [locale] = Intl.getCanonicalLocales(value);
119
+ return locale ?? null;
120
+ }
121
+ catch {
122
+ return null;
123
+ }
124
+ }
125
+ const locale = (value) => {
126
+ if (value === null || value === undefined || value === '')
127
+ return { value: '' };
128
+ const canonical = typeof value === 'string' && value.length <= 35 ? canonicalLocale(value.trim()) : null;
129
+ return canonical ? { value: canonical } : { error: 'Must be a BCP 47 language tag, such as en or en-GB' };
130
+ };
131
+ /** An email address, or blank. Shape only — it is a Reply-To, not a login. */
132
+ const emailOrBlank = (value) => {
133
+ if (value === null || value === undefined || value === '')
134
+ return { value: '' };
135
+ if (typeof value !== 'string')
136
+ return { error: 'Must be an email address' };
137
+ const email = value.trim();
138
+ if (email.length > 254 || !/^[^\s@<>,;"]+@[^\s@<>,;"]+\.[^\s@<>,;"]+$/.test(email)) {
139
+ return { error: 'Must be an email address' };
140
+ }
141
+ return { value: email };
142
+ };
143
+ /** An absolute http(s) URL, or blank. */
144
+ const httpUrlOrBlank = (value) => {
145
+ if (value === null || value === undefined || value === '')
146
+ return { value: '' };
147
+ if (typeof value !== 'string' || value.length > MAX_URL_LENGTH || !isHttpUrl(value.trim())) {
148
+ return { error: 'Must be an http(s) URL' };
149
+ }
150
+ return { value: value.trim() };
151
+ };
152
+ /**
153
+ * The known settings.
154
+ *
155
+ * Code injection is HTML a front end inserts verbatim into every page's
156
+ * <head> or before </body> — analytics snippets, verification tags, a font
157
+ * stylesheet. It is intentionally **not** sanitised: a sanitiser would strip
158
+ * exactly the <script> tags it exists to carry. What keeps it safe is who can
159
+ * write it — these routes require `settings.manage`, which only the admin role
160
+ * holds — the same trust WordPress and Ghost extend to their administrators.
161
+ */
162
+ export const SETTINGS = {
163
+ site_name: { group: 'general', check: text(200, { required: true }) },
164
+ site_description: { group: 'general', check: text(1000) },
165
+ posts_per_page: { group: 'reading', check: integer(1, 100) },
166
+ robots_txt: { group: 'reading', check: text(10_000) },
167
+ allow_comments: { group: 'discussion', check: flag },
168
+ moderate_comments: { group: 'discussion', check: flag },
169
+ public_api: { group: 'integrations', check: flag },
170
+ webhook_urls: { group: 'integrations', check: urlList },
171
+ site_logo: { group: 'identity', check: imageUrl },
172
+ site_icon: { group: 'identity', check: imageUrl },
173
+ default_social_image: { group: 'identity', check: imageUrl },
174
+ timezone: { group: 'locale', check: timeZone },
175
+ locale: { group: 'locale', check: locale },
176
+ // The admin's language for everyone who has not picked one in Profile.
177
+ // Any tag is stored; the admin falls back to English when it has no
178
+ // dictionary for it (src/client/i18n).
179
+ admin_locale: { group: 'locale', check: locale },
180
+ code_injection_head: { group: 'code_injection', check: text(100_000) },
181
+ code_injection_foot: { group: 'code_injection', check: text(100_000) }
182
+ };
183
+ /**
184
+ * The validators, for a feature defining its own settings
185
+ * (`host.settings.define`). Same rules as core's, so a feature's settings are
186
+ * checked exactly as strictly.
187
+ */
188
+ export const checks = { text, flag, integer, oneOf, imageUrl, urlList, timeZone, locale, emailOrBlank, httpUrlOrBlank };
189
+ /**
190
+ * Add a feature's settings to the allowlist. A key core or another feature
191
+ * already defines is refused: two owners for one setting is a bug to catch at
192
+ * boot, not a silent overwrite.
193
+ */
194
+ export function defineSettings(definitions) {
195
+ for (const [key, definition] of Object.entries(definitions)) {
196
+ if (Object.hasOwn(SETTINGS, key))
197
+ throw new Error(`Setting "${key}" is already defined`);
198
+ SETTINGS[key] = definition;
199
+ }
200
+ }
201
+ export function isKnownSetting(key) {
202
+ return Object.hasOwn(SETTINGS, key);
203
+ }
204
+ /**
205
+ * Validate a batch of settings. All or nothing: one bad key and nothing is
206
+ * written, so a save never leaves the site half-configured.
207
+ */
208
+ export function validateSettings(input) {
209
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
210
+ return { errors: { settings: ['Settings object is required'] } };
211
+ }
212
+ const values = {};
213
+ const errors = {};
214
+ for (const [key, raw] of Object.entries(input)) {
215
+ if (!isKnownSetting(key)) {
216
+ errors[key] = ['Unknown setting'];
217
+ continue;
218
+ }
219
+ const { group, check } = SETTINGS[key];
220
+ const result = check(raw);
221
+ if ('error' in result)
222
+ errors[key] = [result.error];
223
+ else
224
+ values[key] = { value: result.value, group };
225
+ }
226
+ return Object.keys(errors).length ? { errors } : { values };
227
+ }
228
+ /** Defaults the public site API reports for settings nobody has set yet. */
229
+ export const SITE_DEFAULTS = {
230
+ timezone: 'UTC',
231
+ locale: 'en'
232
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The public site's origin, for links a feed, sitemap or robots.txt hands out.
3
+ *
4
+ * From configuration, never from the request. The Host header is whatever the
5
+ * client sent, and these responses are cached — one request with a forged Host
6
+ * would poison every reader's feed with links to somewhere else.
7
+ *
8
+ * SITE_URL is the public site when it is separate from this app (a headless
9
+ * front end); APP_URL otherwise. The request is consulted only outside
10
+ * production, so a local checkout works without either.
11
+ */
12
+ export declare function siteUrl(req?: {
13
+ headers?: Record<string, unknown>;
14
+ }): string;