@basicbenframework/cms 0.0.0-stage → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,577 @@
1
+ /**
2
+ * Queries for the public content API.
3
+ *
4
+ * Separate from the admin models on purpose. Every column reaching an anonymous
5
+ * or token-bearing reader is named here, so adding a column to `posts` cannot
6
+ * quietly publish it — which is exactly what `SELECT posts.*` plus a list of
7
+ * fields to strip would do. The admin models keep using `*`; they answer to a
8
+ * signed-in user whose role was already checked.
9
+ *
10
+ * Comments are absent from this surface deliberately: the table stores
11
+ * `author_email` for unauthenticated commenters, and a public feed of reader
12
+ * email addresses is a data-protection incident rather than a feature.
13
+ */
14
+ import { getDb } from '@basicbenframework/core/db';
15
+ import { getStorage, absoluteUrl } from '@basicbenframework/core/storage';
16
+ import { livePost, parseStoredTimestamp } from "./visibility.js";
17
+ import { responsiveImage } from "../helpers/images.js";
18
+ import { siteUrl } from "../helpers/site.js";
19
+ import { publicExcerpt } from "../helpers/gating.js";
20
+ import { mayRead, visibilityOf } from "../helpers/access.js";
21
+ import { excerpt as plainText } from '@basicbenframework/core/content';
22
+ import { ContentType, publicFieldValues } from "./ContentType.js";
23
+ import { taxonomyWhere } from "./Taxonomy.js";
24
+ import { entryPath } from "../helpers/content-paths.js";
25
+ /** Named once so the list and single-item queries cannot drift apart. */
26
+ const POST_COLUMNS = `
27
+ posts.id,
28
+ posts.post_type,
29
+ posts.fields,
30
+ posts.slug,
31
+ posts.title,
32
+ posts.excerpt,
33
+ posts.content,
34
+ posts.content_html,
35
+ posts.meta_title,
36
+ posts.meta_description,
37
+ posts.visibility,
38
+ posts.created_at,
39
+ posts.updated_at,
40
+ posts.publish_at,
41
+ posts.og_title,
42
+ posts.og_description,
43
+ posts.twitter_title,
44
+ posts.twitter_description,
45
+ posts.canonical_url,
46
+ posts.noindex,
47
+ media.width AS featured_image_width,
48
+ media.height AS featured_image_height,
49
+ media.alt_text AS featured_image_alt,
50
+ og_media.path AS og_image_path,
51
+ twitter_media.path AS twitter_image_path,
52
+ users.id AS author_id,
53
+ users.name AS author_name,
54
+ users.slug AS author_slug,
55
+ users.bio AS author_bio,
56
+ users.website AS author_website,
57
+ avatars.path AS author_avatar_path,
58
+ media.path AS featured_image_path
59
+ `;
60
+ const POST_JOINS = `
61
+ FROM posts
62
+ JOIN users ON posts.user_id = users.id
63
+ LEFT JOIN media ON media.id = posts.featured_image
64
+ LEFT JOIN media AS avatars ON avatars.id = users.avatar_id
65
+ LEFT JOIN media AS og_media ON og_media.id = posts.og_image
66
+ LEFT JOIN media AS twitter_media ON twitter_media.id = posts.twitter_image
67
+ `;
68
+ /** The same for pages, which carry a featured image of their own now. */
69
+ const PAGE_COLUMNS = `
70
+ pages.id,
71
+ pages.slug,
72
+ pages.title,
73
+ pages.content,
74
+ pages.content_html,
75
+ pages.meta_title,
76
+ pages.meta_description,
77
+ pages.created_at,
78
+ pages.updated_at,
79
+ NULL AS publish_at,
80
+ pages.og_title,
81
+ pages.og_description,
82
+ pages.twitter_title,
83
+ pages.twitter_description,
84
+ pages.canonical_url,
85
+ pages.noindex,
86
+ media.width AS featured_image_width,
87
+ media.height AS featured_image_height,
88
+ media.alt_text AS featured_image_alt,
89
+ og_media.path AS og_image_path,
90
+ twitter_media.path AS twitter_image_path,
91
+ media.path AS featured_image_path
92
+ `;
93
+ const PAGE_JOINS = `
94
+ FROM pages
95
+ LEFT JOIN media ON media.id = pages.featured_image
96
+ LEFT JOIN media AS og_media ON og_media.id = pages.og_image
97
+ LEFT JOIN media AS twitter_media ON twitter_media.id = pages.twitter_image
98
+ `;
99
+ const MAX_PER_PAGE = 100;
100
+ /** Clamp paging so a consumer cannot ask for the whole table in one request. */
101
+ export function paging(query) {
102
+ const page = Math.max(1, Number(query.page) || 1);
103
+ const requested = Number(query.per_page) || 10;
104
+ const perPage = Math.min(MAX_PER_PAGE, Math.max(1, requested));
105
+ return { page, perPage, offset: (page - 1) * perPage };
106
+ }
107
+ /** `?format=markdown` returns the source; anything else returns rendered HTML. */
108
+ export function contentFormat(query) {
109
+ return query.format === 'markdown' ? 'markdown' : 'html';
110
+ }
111
+ export const PublicContent = {
112
+ /**
113
+ * Published posts, newest first.
114
+ *
115
+ * Filtering happens in SQL rather than over the page that happened to load —
116
+ * filtering a page client-side gives an answer that depends on the page size,
117
+ * which is a bug that only shows up once there is enough content.
118
+ */
119
+ async posts(options = {}) {
120
+ const db = await getDb();
121
+ const { perPage = 10, offset = 0, category, tag, author, search, format = 'html', type = 'post', taxonomy = {}, viewer = null } = options;
122
+ const where = [livePost('posts')];
123
+ const params = [];
124
+ // One content type, `post` unless asked, so a consumer written before
125
+ // content types existed sees exactly the posts it always did.
126
+ const typed = typeWhere('posts', type);
127
+ where.push(typed.where);
128
+ params.push(...typed.params);
129
+ const terms = taxonomyWhere('posts', taxonomy);
130
+ where.push(...terms.where);
131
+ params.push(...terms.params);
132
+ if (category) {
133
+ // Matches on *any* of the post's categories, not just its primary one —
134
+ // a post filed under both "AI" and "Jobs" belongs in either listing.
135
+ // Accepts a slug or an id, because a consumer holding either should not
136
+ // have to look the other up first.
137
+ where.push(`posts.id IN (
138
+ SELECT pc.post_id FROM post_categories pc
139
+ JOIN categories ON categories.id = pc.category_id
140
+ WHERE categories.slug = ? OR categories.id = ?
141
+ )`);
142
+ params.push(category, Number(category) || -1);
143
+ }
144
+ if (tag) {
145
+ where.push(`posts.id IN (
146
+ SELECT pt.post_id FROM post_tags pt
147
+ JOIN tags ON tags.id = pt.tag_id
148
+ WHERE tags.slug = ? OR tags.id = ?
149
+ )`);
150
+ params.push(tag, Number(tag) || -1);
151
+ }
152
+ if (author) {
153
+ // An author archive: every post by one person. Slug or id, for the same
154
+ // reason categories accept either — a consumer holding one should not
155
+ // have to look up the other first.
156
+ where.push('(users.slug = ? OR users.id = ?)');
157
+ params.push(author, Number(author) || -1);
158
+ }
159
+ if (search) {
160
+ where.push('(posts.title LIKE ? OR posts.excerpt LIKE ?)');
161
+ params.push(`%${search}%`, `%${search}%`);
162
+ }
163
+ const clause = `WHERE ${where.join(' AND ')}`;
164
+ const counted = (await db.get(`SELECT COUNT(*) AS total ${POST_JOINS} ${clause}`, params));
165
+ const rows = (await db.all(`SELECT ${POST_COLUMNS} ${POST_JOINS} ${clause}
166
+ ORDER BY COALESCE(posts.publish_at, posts.created_at) DESC, posts.id DESC
167
+ LIMIT ? OFFSET ?`, [...params, perPage, offset]));
168
+ return {
169
+ posts: await shapePosts(rows, format, viewer),
170
+ total: Number(counted?.total) || 0
171
+ };
172
+ },
173
+ /**
174
+ * One published post, by slug or id.
175
+ *
176
+ * Slugs are nullable on posts — the column was added after the table — so a
177
+ * post that never got one is still reachable by id rather than invisible.
178
+ */
179
+ async post(identifier, format = 'html',
180
+ /** `viewer`: the reader, from `viewerOf(req)`. `type`: the content type key. */
181
+ { viewer = null, type = 'post' } = {}) {
182
+ const db = await getDb();
183
+ // The same type rule as the listing: a recipe is not at /api/v1/posts/:slug
184
+ // unless the caller asks for recipes (or `any`), so a front end routing
185
+ // `/blog/:slug` through this cannot render a recipe at a blog URL.
186
+ const typed = typeWhere('posts', type);
187
+ const row = (await db.get(`SELECT ${POST_COLUMNS} ${POST_JOINS}
188
+ WHERE ${livePost('posts')} AND ${typed.where} AND (posts.slug = ? OR posts.id = ?)`, [...typed.params, identifier, Number(identifier) || -1]));
189
+ if (!row)
190
+ return null;
191
+ return (await shapePosts([row], format, viewer))[0];
192
+ },
193
+ /** Published pages, newest first. */
194
+ async pages(options = {}) {
195
+ const db = await getDb();
196
+ const { perPage = 10, offset = 0, format = 'html' } = options;
197
+ const counted = (await db.get('SELECT COUNT(*) AS total FROM pages WHERE published = 1'));
198
+ const rows = (await db.all(`SELECT ${PAGE_COLUMNS} ${PAGE_JOINS}
199
+ WHERE pages.published = 1
200
+ ORDER BY pages.created_at DESC
201
+ LIMIT ? OFFSET ?`, [perPage, offset]));
202
+ return { pages: await shapePages(rows, format), total: Number(counted?.total) || 0 };
203
+ },
204
+ /** One published page, by slug or id. */
205
+ async page(identifier, format = 'html') {
206
+ const db = await getDb();
207
+ const row = (await db.get(`SELECT ${PAGE_COLUMNS} ${PAGE_JOINS}
208
+ WHERE pages.published = 1 AND (pages.slug = ? OR pages.id = ?)`, [identifier, Number(identifier) || -1]));
209
+ return row ? (await shapePages([row], format))[0] : null;
210
+ },
211
+ /**
212
+ * Every category, with how many published posts sit in it.
213
+ *
214
+ * Categories with no published posts are still listed, with a count of zero.
215
+ * A consumer building navigation wants the empty ones visible rather than
216
+ * having to discover them by fetching posts.
217
+ */
218
+ async categories() {
219
+ const db = await getDb();
220
+ const rows = (await db.all(`
221
+ SELECT c.id, c.name, c.slug, c.description,
222
+ COUNT(p.id) AS post_count
223
+ FROM categories c
224
+ LEFT JOIN post_categories pc ON pc.category_id = c.id
225
+ LEFT JOIN posts p ON p.id = pc.post_id AND ${livePost('p')}
226
+ GROUP BY c.id, c.name, c.slug, c.description
227
+ ORDER BY c.name ASC
228
+ `));
229
+ return rows.map((row) => ({ ...row, post_count: Number(row.post_count) || 0 }));
230
+ },
231
+ /** Tags with their published-post counts. */
232
+ async tags() {
233
+ const db = await getDb();
234
+ const rows = (await db.all(`
235
+ SELECT t.id, t.name, t.slug,
236
+ COUNT(p.id) AS post_count
237
+ FROM tags t
238
+ LEFT JOIN post_tags pt ON pt.tag_id = t.id
239
+ LEFT JOIN posts p ON p.id = pt.post_id AND ${livePost('p')}
240
+ GROUP BY t.id, t.name, t.slug
241
+ ORDER BY t.name ASC
242
+ `));
243
+ return rows.map((row) => ({ ...row, post_count: Number(row.post_count) || 0 }));
244
+ },
245
+ /**
246
+ * Every author with something published, newest names first by post count.
247
+ *
248
+ * Only people who have published: an account with no posts is a user, not an
249
+ * author, and listing one exposes that the account exists to anyone who asks
250
+ * for the author index. Counts come from the same `published = 1` filter the
251
+ * post listing uses, so an archive link never leads to an empty page.
252
+ */
253
+ async authors() {
254
+ const db = await getDb();
255
+ const rows = (await db.all(`
256
+ SELECT users.id, users.name, users.slug, users.bio, users.website,
257
+ avatars.path AS avatar_path,
258
+ COUNT(posts.id) AS post_count
259
+ FROM users
260
+ JOIN posts ON posts.user_id = users.id AND ${livePost('posts')}
261
+ LEFT JOIN media AS avatars ON avatars.id = users.avatar_id
262
+ GROUP BY users.id, users.name, users.slug, users.bio, users.website, avatars.path
263
+ ORDER BY users.name ASC
264
+ `));
265
+ return shapeAuthors(rows);
266
+ },
267
+ /** One author, by slug or id. Null when they have published nothing. */
268
+ async author(identifier) {
269
+ const db = await getDb();
270
+ const row = (await db.get(`SELECT users.id, users.name, users.slug, users.bio, users.website,
271
+ avatars.path AS avatar_path,
272
+ COUNT(posts.id) AS post_count
273
+ FROM users
274
+ JOIN posts ON posts.user_id = users.id AND ${livePost('posts')}
275
+ LEFT JOIN media AS avatars ON avatars.id = users.avatar_id
276
+ WHERE users.slug = ? OR users.id = ?
277
+ GROUP BY users.id, users.name, users.slug, users.bio, users.website, avatars.path`, [identifier, Number(identifier) || -1]));
278
+ if (!row)
279
+ return null;
280
+ return (await shapeAuthors([row]))[0];
281
+ },
282
+ /** One media item. */
283
+ async media(id) {
284
+ const db = await getDb();
285
+ const row = (await db.get(`SELECT id, path, mime_type, size, alt_text, created_at
286
+ FROM media WHERE id = ?`, [id]));
287
+ if (!row)
288
+ return null;
289
+ const storage = await getStorage();
290
+ return {
291
+ id: row.id,
292
+ url: mediaUrl(storage, row.path),
293
+ mime_type: row.mime_type,
294
+ size: row.size,
295
+ alt_text: row.alt_text,
296
+ created_at: row.created_at
297
+ };
298
+ }
299
+ };
300
+ /** Warned about once per process; a per-request warning would be a log flood. */
301
+ let warnedAboutRelativeMedia = false;
302
+ /**
303
+ * A media URL a consumer somewhere else can actually fetch.
304
+ *
305
+ * The adapter method is `publicUrl`. This surface called `storage.url`, which
306
+ * neither adapter has ever defined, so every media read and every post carrying
307
+ * a featured image threw a TypeError. It went unnoticed because the smoke test
308
+ * only ever checked that a `content:read` token is refused `/api/v1/media` —
309
+ * a scope failure returns before the controller runs.
310
+ *
311
+ * The URL is then resolved against `APP_URL`, because the local driver serves
312
+ * from the app's own origin and returns `/uploads/...`. That is correct for the
313
+ * bundled frontend and meaningless to a static build on another host. Refusing
314
+ * to serve media at all under the local driver was the other option; it makes
315
+ * the same-origin case worse and tells the consumer nothing, where an absolute
316
+ * URL at least works whenever the app is reachable.
317
+ */
318
+ function mediaUrl(storage, path) {
319
+ const url = absoluteUrl(storage.publicUrl(path));
320
+ if (!warnedAboutRelativeMedia && url.startsWith('/')) {
321
+ warnedAboutRelativeMedia = true;
322
+ console.warn(`[api] Serving relative media URLs (${url}). A consumer on another origin ` +
323
+ 'cannot resolve them — set APP_URL, or configure object storage with a publicUrl.');
324
+ }
325
+ return url;
326
+ }
327
+ /**
328
+ * Attach tags and resolve image URLs for a batch of posts.
329
+ *
330
+ * Tags come back in one query for the whole page rather than one per post — the
331
+ * N+1 here would be invisible on a seeded database and painful on a real one.
332
+ */
333
+ async function shapePosts(rows, format, viewer = null) {
334
+ if (rows.length === 0)
335
+ return [];
336
+ const db = await getDb();
337
+ const ids = rows.map((row) => row.id);
338
+ const placeholders = ids.map(() => '?').join(', ');
339
+ const group = (rowsFor) => {
340
+ const byPost = new Map();
341
+ for (const row of rowsFor) {
342
+ const list = byPost.get(row.post_id) ?? [];
343
+ list.push({ id: row.id, name: row.name, slug: row.slug });
344
+ byPost.set(row.post_id, list);
345
+ }
346
+ return byPost;
347
+ };
348
+ // Both in one query each for the whole page rather than one per post: the
349
+ // N+1 here is invisible on a seeded database and painful on a real one.
350
+ const tagsByPost = group((await db.all(`SELECT pt.post_id, t.id, t.name, t.slug
351
+ FROM post_tags pt
352
+ JOIN tags t ON t.id = pt.tag_id
353
+ WHERE pt.post_id IN (${placeholders})
354
+ ORDER BY t.name ASC`, ids)));
355
+ const categoriesByPost = group((await db.all(`SELECT pc.post_id, c.id, c.name, c.slug
356
+ FROM post_categories pc
357
+ JOIN categories c ON c.id = pc.category_id
358
+ WHERE pc.post_id IN (${placeholders})
359
+ ORDER BY c.name ASC`, ids)));
360
+ const types = await ContentType.all();
361
+ const termsByPost = await customTerms(db, ids, placeholders);
362
+ const storage = await getStorage();
363
+ return rows.map((gatedRow) => {
364
+ // Every field derived from the excerpt (OG, Twitter, structured data)
365
+ // reads it from this row, so the gated excerpt is decided once, here.
366
+ const row = mayRead(gatedRow, viewer)
367
+ ? gatedRow
368
+ : { ...gatedRow, excerpt: publicExcerpt(gatedRow.excerpt, plainText(gatedRow.content ?? '', Number.MAX_SAFE_INTEGER), gatedRow.visibility, viewer) };
369
+ return {
370
+ id: row.id,
371
+ slug: row.slug,
372
+ title: row.title,
373
+ excerpt: row.excerpt,
374
+ ...contentFor(row.content, row.content_html, format),
375
+ // A gated post is still listed; only its body is withheld, after the
376
+ // format is decided so `format` still says what a member would get.
377
+ ...(mayRead(row, viewer) ? {} : { content: null }),
378
+ visibility: visibilityOf(row.visibility),
379
+ gated: !mayRead(row, viewer),
380
+ featured_image_url: row.featured_image_path && storage ? mediaUrl(storage, row.featured_image_path) : null,
381
+ author: row.author_name,
382
+ // `author` stays the display name it has always been — changing its type
383
+ // would break every consumer reading a byline — and the profile arrives
384
+ // beside it, so a static build can render a face and a biography without a
385
+ // second request per post.
386
+ author_profile: shapeAuthor(row, storage),
387
+ categories: categoriesByPost.get(row.id) ?? [],
388
+ tags: tagsByPost.get(row.id) ?? [],
389
+ type: row.post_type || 'post',
390
+ // Custom fields can carry the substance of an entry (a recipe's method),
391
+ // so a gated entry withholds them with the body.
392
+ fields: mayRead(row, viewer) ? fieldsFor(types, row) : null,
393
+ terms: termsByPost.get(row.id) ?? {},
394
+ meta_title: row.meta_title,
395
+ meta_description: row.meta_description,
396
+ ...seoFor(row, storage, row.excerpt),
397
+ structured_data: blogPosting(row, storage, types),
398
+ published_at: iso(row.publish_at ?? row.created_at),
399
+ updated_at: row.updated_at
400
+ };
401
+ });
402
+ }
403
+ /** Pages, with their featured image resolved in one adapter lookup per batch. */
404
+ async function shapePages(rows, format) {
405
+ const storage = await getStorage();
406
+ return rows.map((row) => ({
407
+ id: row.id,
408
+ slug: row.slug,
409
+ title: row.title,
410
+ ...contentFor(row.content, row.content_html, format),
411
+ featured_image_url: row.featured_image_path && storage ? mediaUrl(storage, row.featured_image_path) : null,
412
+ meta_title: row.meta_title,
413
+ meta_description: row.meta_description,
414
+ ...seoFor(row, storage, null),
415
+ published_at: iso(row.created_at),
416
+ updated_at: row.updated_at
417
+ }));
418
+ }
419
+ /** A stored timestamp as ISO 8601 UTC, whichever form the driver returned. */
420
+ function iso(value) {
421
+ const time = parseStoredTimestamp(value);
422
+ return Number.isNaN(time) ? value : new Date(time).toISOString();
423
+ }
424
+ /**
425
+ * The featured image, the share cards and the indexing flags.
426
+ *
427
+ * Every fallback is applied here so a consumer can render tags straight from
428
+ * the response: an og title falls back to the meta title and then the title,
429
+ * a twitter card falls back to the og card, and a card image falls back to
430
+ * the featured image.
431
+ */
432
+ function seoFor(row, storage, excerpt) {
433
+ const featuredUrl = row.featured_image_path ? mediaUrl(storage, row.featured_image_path) : null;
434
+ const featured = responsiveImage(featuredUrl, {
435
+ width: row.featured_image_width,
436
+ height: row.featured_image_height,
437
+ alt: row.featured_image_alt
438
+ });
439
+ const og = {
440
+ title: row.og_title || row.meta_title || row.title,
441
+ description: row.og_description || row.meta_description || excerpt || null,
442
+ image_url: row.og_image_path ? mediaUrl(storage, row.og_image_path) : featuredUrl
443
+ };
444
+ const twitter = {
445
+ title: row.twitter_title || og.title,
446
+ description: row.twitter_description || og.description,
447
+ image_url: row.twitter_image_path ? mediaUrl(storage, row.twitter_image_path) : og.image_url
448
+ };
449
+ return {
450
+ featured_image: featured,
451
+ og,
452
+ twitter,
453
+ canonical_url: row.canonical_url || null,
454
+ noindex: Boolean(Number(row.noindex ?? 0))
455
+ };
456
+ }
457
+ /** schema.org BlogPosting for a post, for a front end to embed as JSON-LD. */
458
+ function blogPosting(row, storage, types = []) {
459
+ const site = siteUrl();
460
+ const image = row.og_image_path
461
+ ? mediaUrl(storage, row.og_image_path)
462
+ : row.featured_image_path ? mediaUrl(storage, row.featured_image_path) : undefined;
463
+ return {
464
+ '@context': 'https://schema.org',
465
+ '@type': 'BlogPosting',
466
+ headline: row.meta_title || row.title,
467
+ ...(row.meta_description || row.excerpt ? { description: row.meta_description || row.excerpt } : {}),
468
+ ...(image ? { image } : {}),
469
+ datePublished: iso(row.publish_at ?? row.created_at),
470
+ dateModified: iso(row.updated_at),
471
+ ...(row.author_name
472
+ ? {
473
+ author: {
474
+ '@type': 'Person',
475
+ name: row.author_name,
476
+ ...(row.author_slug && site ? { url: `${site}/author/${row.author_slug}` } : {})
477
+ }
478
+ }
479
+ : {}),
480
+ // `entryPath` gives a plain post `/blog/:slug` exactly as before, and a
481
+ // custom type its own route base.
482
+ ...(site ? { mainEntityOfPage: row.canonical_url || `${site}${entryPath(routeBaseOf(types, row.post_type), row.slug, row.id)}` } : {})
483
+ };
484
+ }
485
+ /**
486
+ * The author columns a post query joins, as one object.
487
+ *
488
+ * Returns null when the join produced no author at all, which the shape
489
+ * documents: a post whose account was deleted still has words worth serving.
490
+ */
491
+ function shapeAuthor(row, storage) {
492
+ if (row.author_id === null || row.author_id === undefined)
493
+ return null;
494
+ return {
495
+ id: row.author_id,
496
+ name: row.author_name ?? '',
497
+ slug: row.author_slug,
498
+ bio: row.author_bio,
499
+ website: row.author_website,
500
+ avatar_url: row.author_avatar_path && storage ? mediaUrl(storage, row.author_avatar_path) : null
501
+ };
502
+ }
503
+ /** Author archive rows, with avatars resolved and counts made numbers. */
504
+ async function shapeAuthors(rows) {
505
+ const storage = rows.some((row) => row.avatar_path) ? await getStorage() : null;
506
+ return rows.map((row) => ({
507
+ id: row.id,
508
+ name: row.name,
509
+ slug: row.slug,
510
+ bio: row.bio,
511
+ website: row.website,
512
+ avatar_url: row.avatar_path && storage ? mediaUrl(storage, row.avatar_path) : null,
513
+ // Postgres returns bigint counts as strings rather than lose precision.
514
+ post_count: Number(row.post_count) || 0
515
+ }));
516
+ }
517
+ /**
518
+ * The content in the requested format, and the format actually returned.
519
+ *
520
+ * `content` is the Markdown source and is always present; `content_html` is a
521
+ * cache of it that can be missing on rows written before rendering existed
522
+ * (the column arrived in migration 017). Two wrong answers were available
523
+ * there: return an empty string, losing the post silently, or return Markdown
524
+ * while labelling it HTML, which a consumer would inject into a page as markup.
525
+ *
526
+ * So it falls back to the source *and* says so. A consumer that cares can check
527
+ * `format`; one that does not still gets the words. Running
528
+ * `basicben content:rerender` fills the cache and the fallback stops firing.
529
+ */
530
+ function contentFor(markdown, html, format) {
531
+ if (format === 'markdown')
532
+ return { content: markdown, format: 'markdown' };
533
+ if (html)
534
+ return { content: html, format: 'html' };
535
+ return { content: markdown, format: 'markdown' };
536
+ }
537
+ // --- Content types and custom taxonomies (migrations 038–040) ---------------
538
+ /**
539
+ * The SQL fragment that narrows posts to one content type, or every public
540
+ * one for `any`. Bound, because the key is input. A type that does not exist
541
+ * or is not public matches nothing: an unknown `?type=` is an empty listing,
542
+ * never an unfiltered one.
543
+ */
544
+ function typeWhere(alias, type) {
545
+ const publicTypes = 'SELECT key FROM content_types WHERE is_public = 1';
546
+ if (type === 'any')
547
+ return { where: `${alias}.post_type IN (${publicTypes})`, params: [] };
548
+ return { where: `(${alias}.post_type = ? AND ${alias}.post_type IN (${publicTypes}))`, params: [type] };
549
+ }
550
+ function routeBaseOf(types, key) {
551
+ if (!key || key === 'post')
552
+ return null;
553
+ return types.find((type) => type.key === key)?.route_base ?? null;
554
+ }
555
+ /** A post's custom field values, limited to what its type declares now. */
556
+ function fieldsFor(types, row) {
557
+ const type = types.find((candidate) => candidate.key === (row.post_type || 'post'));
558
+ if (!type || !type.supports.custom_fields)
559
+ return {};
560
+ return publicFieldValues(type.fields, row.fields);
561
+ }
562
+ /** Custom terms for a page of posts, in one query, grouped by taxonomy key. */
563
+ async function customTerms(db, ids, placeholders) {
564
+ const rows = (await db.all(`SELECT tr.post_id, taxonomies.key AS taxonomy, terms.id, terms.name, terms.slug
565
+ FROM term_relationships tr
566
+ JOIN terms ON terms.id = tr.term_id
567
+ JOIN taxonomies ON taxonomies.id = terms.taxonomy_id
568
+ WHERE taxonomies.is_public = 1 AND tr.post_id IN (${placeholders})
569
+ ORDER BY terms.name ASC`, ids));
570
+ const byPost = new Map();
571
+ for (const row of rows) {
572
+ const terms = byPost.get(Number(row.post_id)) ?? {};
573
+ (terms[row.taxonomy] ??= []).push({ id: Number(row.id), name: row.name, slug: row.slug });
574
+ byPost.set(Number(row.post_id), terms);
575
+ }
576
+ return byPost;
577
+ }