@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,47 @@
1
+ import { getDb } from '@basicbenframework/core/db';
2
+ import { isConfigured, webhookSecret, setting, client } from "./config.js";
3
+ import { backfill, contactCounts } from "./contacts.js";
4
+ export const MySendboxController = {
5
+ /**
6
+ * `GET /api/mysendbox/status`: whether it's set up, and how the members
7
+ * stand. `sendable` is MySendbox's own count of who a broadcast would reach
8
+ * now, after its six-month sunset.
9
+ */
10
+ async status(_req, res) {
11
+ const configured = isConfigured();
12
+ const audience = await setting('mysendbox_audience_id');
13
+ let sendable = null;
14
+ let error = null;
15
+ if (configured && audience) {
16
+ const counted = await client().sendableCount(audience);
17
+ if (counted.ok)
18
+ sendable = Number(counted.data?.sendable ?? 0);
19
+ else
20
+ error = counted.error;
21
+ }
22
+ const db = await getDb();
23
+ const problems = (await db
24
+ .all("SELECT member_id, state, last_error FROM mysendbox_contacts WHERE state IN ('refused', 'needs_consent') OR (state = 'dirty' AND attempts > 0) ORDER BY updated_at DESC LIMIT 20")
25
+ .catch(() => []));
26
+ res.json({
27
+ configured,
28
+ webhook: Boolean(webhookSecret()),
29
+ audience_id: audience || null,
30
+ contacts: await contactCounts(),
31
+ sendable,
32
+ problems,
33
+ error
34
+ });
35
+ },
36
+ /** `POST /api/mysendbox/backfill`: copy one batch. The admin calls it until `remaining` is 0. */
37
+ async backfill(_req, res) {
38
+ if (!isConfigured())
39
+ return res.json({ error: 'Set MYSENDBOX_API_KEY first.' }, 422);
40
+ try {
41
+ res.json(await backfill(50));
42
+ }
43
+ catch (err) {
44
+ res.json({ error: String(err?.message ?? err).slice(0, 300) }, 502);
45
+ }
46
+ }
47
+ };
@@ -0,0 +1,4 @@
1
+ import type { Dictionary } from '../../../client/i18n/index.ts';
2
+ /** Spanish for the mysendbox feature. Merged over the admin's own dictionary. */
3
+ declare const strings: Dictionary;
4
+ export default strings;
@@ -0,0 +1,28 @@
1
+ /** Spanish for the mysendbox feature. Merged over the admin's own dictionary. */
2
+ const strings = {
3
+ "Newsletters through MySendbox": "Boletines a través de MySendbox",
4
+ "{synced} member(s) in MySendbox, {waiting} waiting for consent, {refused} refused.": "{synced} miembro(s) en MySendbox, {waiting} a la espera de consentimiento, {refused} rechazado(s).",
5
+ "A broadcast would reach {count} now.": "Un envío llegaría ahora a {count}.",
6
+ "No webhook secret: unsubscribes made in MySendbox arrive through the daily check.": "Sin secreto de webhook: las bajas hechas en MySendbox llegan con la comprobación diaria.",
7
+ "From address": "Dirección del remitente",
8
+ "Blank uses your MySendbox workspace's default sender.": "En blanco, se usa el remitente predeterminado de tu espacio de MySendbox.",
9
+ "From name": "Nombre del remitente",
10
+ "Blank uses the newsletter sender name.": "En blanco, se usa el nombre de remitente del boletín.",
11
+ "Consent for members you added or imported": "Consentimiento de los miembros que añadiste o importaste",
12
+ "How they agreed to receive posts by email, in your words. MySendbox records it with each contact. Leave blank and they are not copied, unless a signup form is set.": "Cómo aceptaron recibir las entradas por correo, con tus palabras. MySendbox lo guarda con cada contacto. Si lo dejas en blanco, no se copian, salvo que haya un formulario de alta.",
13
+ "Signup form (frm_…)": "Formulario de alta (frm_…)",
14
+ "Optional. Members without recorded consent are sent this form’s confirmation email instead.": "Opcional. A los miembros sin consentimiento registrado se les envía el correo de confirmación de este formulario.",
15
+ "Audience (aud_…)": "Audiencia (aud_…)",
16
+ "Made for you on first use. Change it only to use another MySendbox list.": "Se crea en el primer uso. Cámbiala solo para usar otra lista de MySendbox.",
17
+ "Copying…": "Copiando…",
18
+ "Copy members to MySendbox": "Copiar miembros a MySendbox",
19
+ "Copies every subscribed member not yet in MySendbox. Safe to run again. Save settings first if you changed consent.": "Copia a todos los miembros suscritos que aún no están en MySendbox. Se puede repetir. Guarda los ajustes antes si cambiaste el consentimiento.",
20
+ "{count} member(s) copied.": "{count} miembro(s) copiado(s).",
21
+ "The copy stopped.": "La copia se detuvo.",
22
+ "Members not copied ({count})": "Miembros no copiados ({count})",
23
+ "draft": "borrador",
24
+ "scheduled": "programado",
25
+ "paused": "en pausa",
26
+ "canceled": "cancelado"
27
+ };
28
+ export default strings;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Newsletters through MySendbox (mysendbox.com).
3
+ *
4
+ * With `MYSENDBOX_API_KEY` set, members become MySendbox contacts in one
5
+ * audience, and a post sent as a newsletter becomes a MySendbox broadcast
6
+ * instead of going through the members feature's own queue. MySendbox does
7
+ * the batching, pacing, retries, suppression and unsubscribes, so a site on
8
+ * a serverless host needs no frequent cron for newsletters.
9
+ *
10
+ * Needs the members feature (it listens to members' hooks; it imports
11
+ * nothing of it). Without a key it registers only its settings and a health
12
+ * check, and members sends as before. Remove this folder and its lines in
13
+ * src/features.ts, src/client/features.ts and src/features.manifest.ts, and
14
+ * members sends through its own queue again. How it works: README.md.
15
+ */
16
+ import type { Feature } from '../../host/index.ts';
17
+ declare const mysendbox: Feature;
18
+ export default mysendbox;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Newsletters through MySendbox (mysendbox.com).
3
+ *
4
+ * With `MYSENDBOX_API_KEY` set, members become MySendbox contacts in one
5
+ * audience, and a post sent as a newsletter becomes a MySendbox broadcast
6
+ * instead of going through the members feature's own queue. MySendbox does
7
+ * the batching, pacing, retries, suppression and unsubscribes, so a site on
8
+ * a serverless host needs no frequent cron for newsletters.
9
+ *
10
+ * Needs the members feature (it listens to members' hooks; it imports
11
+ * nothing of it). Without a key it registers only its settings and a health
12
+ * check, and members sends as before. Remove this folder and its lines in
13
+ * src/features.ts, src/client/features.ts and src/features.manifest.ts, and
14
+ * members sends through its own queue again. How it works: README.md.
15
+ */
16
+ import { check } from "../../helpers/health.js";
17
+ import { SETTINGS, isConfigured, webhookSecret } from "./config.js";
18
+ import { mysendboxRoutes } from "./routes.js";
19
+ import { MEMBER_EVENTS, onMemberCreated, onMemberUpdated, onMemberDeleted, syncDirty, pullUnsubscribes } from "./contacts.js";
20
+ import { DELIVERING_HOOK, STATUS_HOOK, deliverAsBroadcast, describeSend } from "./broadcasts.js";
21
+ const mysendbox = {
22
+ name: 'mysendbox',
23
+ register(host) {
24
+ host.settings.define(SETTINGS);
25
+ host.health.check('setup', async ({ db }) => {
26
+ if (!isConfigured()) {
27
+ return check('mysendbox', 'MySendbox', 'pass', 'Not set up: newsletters go through the built-in queue.', 'Set MYSENDBOX_API_KEY to send newsletters through MySendbox.');
28
+ }
29
+ const results = [];
30
+ try {
31
+ const rows = (await db.all("SELECT state, COUNT(*) AS n FROM mysendbox_contacts WHERE state IN ('refused', 'needs_consent') OR (state = 'dirty' AND attempts > 0) GROUP BY state"));
32
+ const of = (state) => Number(rows.find((r) => r.state === state)?.n) || 0;
33
+ const waiting = of('needs_consent');
34
+ const refused = of('refused');
35
+ const failing = of('dirty');
36
+ results.push(failing
37
+ ? check('mysendbox_contacts', 'MySendbox contacts', 'warn', `${failing} member(s) could not be copied to MySendbox yet and will be retried.`, 'The MySendbox settings card lists why.')
38
+ : waiting || refused
39
+ ? check('mysendbox_contacts', 'MySendbox contacts', 'warn', `${waiting} member(s) wait for a consent attestation or a signup form; MySendbox refused ${refused}.`, 'Added and imported members need a consent attestation or a signup form in the MySendbox settings.')
40
+ : check('mysendbox_contacts', 'MySendbox contacts', 'pass', 'Every member is in step with MySendbox.'));
41
+ const stuck = await db.get("SELECT COUNT(*) AS n, MAX(handoff_error) AS error FROM newsletter_sends WHERE status = 'handoff_failed'");
42
+ results.push(Number(stuck?.n)
43
+ ? check('mysendbox_sends', 'MySendbox broadcasts', 'fail', `${stuck.n} newsletter(s) are waiting to be handed to MySendbox: ${stuck.error ?? ''}`.trim(), 'They are retried every ten minutes the cron tick runs. They are never sent by the built-in queue instead.')
44
+ : check('mysendbox_sends', 'MySendbox broadcasts', 'pass', 'No newsletter is waiting to be handed off.'));
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ if (!webhookSecret()) {
50
+ results.push(check('mysendbox_webhook', 'MySendbox webhook', 'warn', 'No MYSENDBOX_WEBHOOK_SECRET: unsubscribes in MySendbox reach the CMS only through the daily check.', 'Add a webhook in MySendbox for contact.updated and contact.erased pointing at /api/webhooks/mysendbox, and set its secret.'));
51
+ }
52
+ return results;
53
+ });
54
+ host.routes(mysendboxRoutes);
55
+ if (!isConfigured())
56
+ return;
57
+ host.hooks.on(MEMBER_EVENTS.CREATED, onMemberCreated, { name: 'mysendbox:member-created' });
58
+ host.hooks.on(MEMBER_EVENTS.UPDATED, onMemberUpdated, { name: 'mysendbox:member-updated' });
59
+ host.hooks.on(MEMBER_EVENTS.DELETED, onMemberDeleted, { name: 'mysendbox:member-deleted' });
60
+ host.hooks.on(DELIVERING_HOOK, deliverAsBroadcast, { name: 'mysendbox:deliver' });
61
+ host.hooks.on(STATUS_HOOK, describeSend, { name: 'mysendbox:status' });
62
+ // Daily is enough: syncs run right after each change and before every
63
+ // broadcast; this catches what a frozen serverless function dropped, and
64
+ // the unsubscribes a missed webhook didn't bring.
65
+ host.cron.task('reconcile', 6 * 3600, async () => ({
66
+ synced: await syncDirty(500, { includeExhausted: true }),
67
+ unsubscribes: await pullUnsubscribes()
68
+ }));
69
+ }
70
+ };
71
+ export default mysendbox;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Static facts about the mysendbox feature, for code that cannot boot the
3
+ * server. Imports nothing, so plain Node can load it.
4
+ */
5
+ import type { FeatureManifest } from '../../host/manifest.ts';
6
+ declare const manifest: FeatureManifest;
7
+ export default manifest;
@@ -0,0 +1,6 @@
1
+ const manifest = {
2
+ name: 'mysendbox',
3
+ // Sync state, meaningful only next to this database's MySendbox workspace.
4
+ neverExported: ['mysendbox_contacts', 'mysendbox_broadcasts']
5
+ };
6
+ export default manifest;
@@ -0,0 +1,6 @@
1
+ import type { Router } from '../../host/index.ts';
2
+ /**
3
+ * The webhook is public and verified by its signature. The admin routes are
4
+ * the members list's own rule: who may manage accounts may copy them.
5
+ */
6
+ export declare function mysendboxRoutes(router: Router): void;
@@ -0,0 +1,14 @@
1
+ import { requireCapability } from '@basicbenframework/core/auth/permissions';
2
+ import { auth } from "../../middleware/auth.js";
3
+ import { mysendboxWebhook } from "./webhook.js";
4
+ import { MySendboxController } from "./controller.js";
5
+ /**
6
+ * The webhook is public and verified by its signature. The admin routes are
7
+ * the members list's own rule: who may manage accounts may copy them.
8
+ */
9
+ export function mysendboxRoutes(router) {
10
+ router.post('/api/webhooks/mysendbox', mysendboxWebhook);
11
+ const manage = [auth, requireCapability('user.manage')];
12
+ router.get('/api/mysendbox/status', ...manage, MySendboxController.status);
13
+ router.post('/api/mysendbox/backfill', ...manage, MySendboxController.backfill);
14
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `POST /api/webhooks/mysendbox`: MySendbox telling the CMS a contact's
3
+ * subscription changed (`contact.updated`) or the contact was erased
4
+ * (`contact.erased`).
5
+ *
6
+ * - **Verified** with the `MySendbox-Signature` header: `t=<unix seconds>,
7
+ * v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`, refused when the time is
8
+ * more than five minutes off. Over the raw body, which is why
9
+ * `/api/webhooks/` is left unparsed (basicben.config.js).
10
+ * - **404 without `MYSENDBOX_WEBHOOK_SECRET`**, as the cron routes do with no
11
+ * secret: an endpoint that can't verify anything should not exist.
12
+ * - **Repeats and reordering are harmless.** Applying a status twice changes
13
+ * nothing, and each contact's last-heard time (`remote_at`) means an older
14
+ * event delivered late cannot undo a newer one.
15
+ * - Any other event type is acknowledged and ignored, so a webhook that
16
+ * subscribes to everything (`*`) does no harm.
17
+ */
18
+ import type { Request, Response } from '../../types/index.ts';
19
+ export declare const MAX_BODY_BYTES: number;
20
+ export declare const TOLERANCE_SECONDS: number;
21
+ /** Is this the signature MySendbox would make for this body now? */
22
+ export declare function verifySignature(secret: string, body: string, header: unknown, nowMs?: number): boolean;
23
+ export declare function mysendboxWebhook(req: Request, res: Response): Promise<void>;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * `POST /api/webhooks/mysendbox`: MySendbox telling the CMS a contact's
3
+ * subscription changed (`contact.updated`) or the contact was erased
4
+ * (`contact.erased`).
5
+ *
6
+ * - **Verified** with the `MySendbox-Signature` header: `t=<unix seconds>,
7
+ * v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`, refused when the time is
8
+ * more than five minutes off. Over the raw body, which is why
9
+ * `/api/webhooks/` is left unparsed (basicben.config.js).
10
+ * - **404 without `MYSENDBOX_WEBHOOK_SECRET`**, as the cron routes do with no
11
+ * secret: an endpoint that can't verify anything should not exist.
12
+ * - **Repeats and reordering are harmless.** Applying a status twice changes
13
+ * nothing, and each contact's last-heard time (`remote_at`) means an older
14
+ * event delivered late cannot undo a newer one.
15
+ * - Any other event type is acknowledged and ignored, so a webhook that
16
+ * subscribes to everything (`*`) does no harm.
17
+ */
18
+ import { createHmac, timingSafeEqual } from 'node:crypto';
19
+ import { webhookSecret, setting } from "./config.js";
20
+ import { applyRemoteStatus } from "./contacts.js";
21
+ export const MAX_BODY_BYTES = 256 * 1024;
22
+ export const TOLERANCE_SECONDS = 5 * 60;
23
+ /** Read the request stream ourselves: the body parser skipped it. */
24
+ function readRaw(req) {
25
+ // Already parsed by something else (a test, or a server without the skip):
26
+ // there is nothing to verify against.
27
+ if (typeof req.rawBody === 'string')
28
+ return Promise.resolve(req.rawBody);
29
+ if (typeof req.on !== 'function')
30
+ return Promise.reject(new Error('no body'));
31
+ return new Promise((resolve, reject) => {
32
+ const chunks = [];
33
+ let size = 0;
34
+ req.on('data', (chunk) => {
35
+ size += chunk.length;
36
+ if (size > MAX_BODY_BYTES) {
37
+ reject(new Error('too large'));
38
+ req.destroy?.();
39
+ return;
40
+ }
41
+ chunks.push(chunk);
42
+ });
43
+ req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
44
+ req.on('error', reject);
45
+ });
46
+ }
47
+ /** Is this the signature MySendbox would make for this body now? */
48
+ export function verifySignature(secret, body, header, nowMs = Date.now()) {
49
+ if (!secret || typeof header !== 'string')
50
+ return false;
51
+ const parts = Object.fromEntries(header.split(',').map((part) => {
52
+ const at = part.indexOf('=');
53
+ return [part.slice(0, at).trim(), part.slice(at + 1).trim()];
54
+ }));
55
+ const t = Number(parts.t);
56
+ const given = String(parts.v1 ?? '');
57
+ if (!Number.isFinite(t) || Math.abs(nowMs / 1000 - t) > TOLERANCE_SECONDS)
58
+ return false;
59
+ if (!/^[0-9a-f]{64}$/i.test(given))
60
+ return false;
61
+ const expected = createHmac('sha256', secret).update(`${parts.t}.${body}`).digest('hex');
62
+ return timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(given, 'hex'));
63
+ }
64
+ export async function mysendboxWebhook(req, res) {
65
+ const secret = webhookSecret();
66
+ if (!secret)
67
+ return res.json({ error: 'Not found' }, 404);
68
+ let raw;
69
+ try {
70
+ raw = await readRaw(req);
71
+ }
72
+ catch {
73
+ return res.json({ error: 'Unreadable body' }, 400);
74
+ }
75
+ if (!verifySignature(secret, raw, req.headers['mysendbox-signature'])) {
76
+ return res.json({ error: 'Bad signature' }, 401);
77
+ }
78
+ let event;
79
+ try {
80
+ event = JSON.parse(raw);
81
+ }
82
+ catch {
83
+ return res.json({ error: 'Not JSON' }, 400);
84
+ }
85
+ const data = event?.data ?? {};
86
+ const memberId = Number(data.attributes?.cms_member_id) || null;
87
+ if (event?.type === 'contact.updated' && typeof data.status === 'string') {
88
+ // Leaving one list on the preferences page, with the status unchanged,
89
+ // matters only if it is this site's list: then they've left it.
90
+ const status = data.change === 'audience_left' ? 'unsubscribed' : data.status;
91
+ if (data.change === 'audience_left' && !(await isOurAudience(data.audience?.id)))
92
+ return res.json({ ok: true });
93
+ const result = await applyRemoteStatus({ contactId: data.contactId, email: data.email, memberId, status, at: Number(data.at) || null });
94
+ return res.json({ ok: true, result });
95
+ }
96
+ if (event?.type === 'contact.erased') {
97
+ const result = await applyRemoteStatus({ contactId: data.contactId, email: data.email, memberId, status: 'erased', at: Number(data.at) || null });
98
+ return res.json({ ok: true, result });
99
+ }
100
+ res.json({ ok: true, ignored: event?.type ?? null });
101
+ }
102
+ async function isOurAudience(id) {
103
+ return typeof id === 'string' && id !== '' && id === (await setting('mysendbox_audience_id'));
104
+ }
@@ -0,0 +1,31 @@
1
+ import type { Request, Response } from '../../types/index.ts';
2
+ /**
3
+ * `GET /oembed?url=…&format=json` — the oEmbed provider (oembed.com).
4
+ *
5
+ * Paste a link to a post into WordPress, Ghost, Slack or Discord and this is
6
+ * what they ask for: a title, an author, a thumbnail and, for posts, a small
7
+ * HTML card to embed. Only URLs on this site are answered — anything else is a
8
+ * 404, so the endpoint cannot be used to make this server describe, or fetch,
9
+ * somebody else's pages. Nothing is fetched at all: the URL is parsed, its
10
+ * path matched against the site's own routes, and the entry read through
11
+ * `PublicContent` like every other public read.
12
+ *
13
+ * The rich card is a `<blockquote>` with a link rather than an `<iframe>`:
14
+ * every page here is sent with `frame-ancestors 'none'`, and a card that
15
+ * degrades to a quote and a link is what WordPress emits for the same reason.
16
+ */
17
+ export declare const OEmbedController: {
18
+ show(req: Request, res: Response): Promise<void>;
19
+ };
20
+ /**
21
+ * The path of a URL on this site, or null.
22
+ *
23
+ * Compared by origin, so `https://site.example/blog/x?utm=1#top` is ours and
24
+ * `https://site.example.evil.test/blog/x` is not. With no configured site URL
25
+ * (production without SITE_URL/APP_URL) there is no "this site" to compare
26
+ * with, and nothing is answered.
27
+ */
28
+ export declare function parseTarget(raw: unknown, site: string): {
29
+ path: string;
30
+ segments: string[];
31
+ } | null;
@@ -0,0 +1,128 @@
1
+ import { strongEtag, conditional } from '@basicbenframework/core/etag';
2
+ import { PublicContent } from "../../models/PublicContent.js";
3
+ import { Settings } from "../../models/Settings.js";
4
+ import { ContentType } from "../../models/ContentType.js";
5
+ import { siteUrl } from "../../helpers/site.js";
6
+ import { POST_ROUTE_BASE } from "../../helpers/content-paths.js";
7
+ import { resolveOEmbed } from "./oembed.js";
8
+ /**
9
+ * `GET /oembed?url=…&format=json` — the oEmbed provider (oembed.com).
10
+ *
11
+ * Paste a link to a post into WordPress, Ghost, Slack or Discord and this is
12
+ * what they ask for: a title, an author, a thumbnail and, for posts, a small
13
+ * HTML card to embed. Only URLs on this site are answered — anything else is a
14
+ * 404, so the endpoint cannot be used to make this server describe, or fetch,
15
+ * somebody else's pages. Nothing is fetched at all: the URL is parsed, its
16
+ * path matched against the site's own routes, and the entry read through
17
+ * `PublicContent` like every other public read.
18
+ *
19
+ * The rich card is a `<blockquote>` with a link rather than an `<iframe>`:
20
+ * every page here is sent with `frame-ancestors 'none'`, and a card that
21
+ * degrades to a quote and a link is what WordPress emits for the same reason.
22
+ */
23
+ export const OEmbedController = {
24
+ async show(req, res) {
25
+ const format = req.query.format || 'json';
26
+ // The spec's answer to a format the provider does not speak.
27
+ if (format !== 'json')
28
+ return res.json({ error: 'Only format=json is supported' }, 501);
29
+ const site = siteUrl(req);
30
+ const target = parseTarget(req.query.url, site);
31
+ if (!target)
32
+ return res.json({ error: 'Not found' }, 404);
33
+ const found = await lookup(target);
34
+ if (!found)
35
+ return res.json({ error: 'Not found' }, 404);
36
+ const body = resolveOEmbed({
37
+ ...found,
38
+ url: `${site}${target.path}`,
39
+ providerName: (await Settings.getSiteName()),
40
+ providerUrl: site,
41
+ maxWidth: positive(req.query.maxwidth),
42
+ maxHeight: positive(req.query.maxheight)
43
+ });
44
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
45
+ const json = JSON.stringify(body);
46
+ if (conditional(req, res, { etag: strongEtag(json), cacheControl: 'public, max-age=60' }))
47
+ return;
48
+ res.end(json);
49
+ }
50
+ };
51
+ function positive(value) {
52
+ const n = Number(value);
53
+ return Number.isInteger(n) && n > 0 ? Math.min(n, 4000) : null;
54
+ }
55
+ /**
56
+ * The path of a URL on this site, or null.
57
+ *
58
+ * Compared by origin, so `https://site.example/blog/x?utm=1#top` is ours and
59
+ * `https://site.example.evil.test/blog/x` is not. With no configured site URL
60
+ * (production without SITE_URL/APP_URL) there is no "this site" to compare
61
+ * with, and nothing is answered.
62
+ */
63
+ export function parseTarget(raw, site) {
64
+ if (typeof raw !== 'string' || !site)
65
+ return null;
66
+ let url;
67
+ let origin;
68
+ try {
69
+ url = new URL(raw);
70
+ origin = new URL(site).origin;
71
+ }
72
+ catch {
73
+ return null;
74
+ }
75
+ if (url.origin !== origin)
76
+ return null;
77
+ const path = url.pathname.replace(/\/+$/, '') || '/';
78
+ const segments = path.split('/').filter(Boolean).map((segment) => {
79
+ try {
80
+ return decodeURIComponent(segment);
81
+ }
82
+ catch {
83
+ return segment;
84
+ }
85
+ });
86
+ return { path, segments };
87
+ }
88
+ /** What lives at that path: a post, an entry of a custom type, or a page. */
89
+ async function lookup(target) {
90
+ const [first, second, ...rest] = target.segments;
91
+ if (!first || rest.length)
92
+ return null;
93
+ if (second !== undefined) {
94
+ const type = `/${first}` === POST_ROUTE_BASE
95
+ ? await ContentType.findByKey('post')
96
+ : await ContentType.findByRouteBase(`/${first}`);
97
+ if (!type || !type.public)
98
+ return null;
99
+ const post = await PublicContent.post(second, 'html', { type: type.key });
100
+ // Only at its own slug: a post reached by id has one canonical URL, and
101
+ // that is what an embed should name.
102
+ if (!post || post.slug !== second)
103
+ return null;
104
+ return {
105
+ kind: 'rich',
106
+ title: post.title,
107
+ description: post.excerpt,
108
+ authorName: post.author_profile?.name ?? post.author,
109
+ authorUrl: post.author_profile?.slug ? `/author/${post.author_profile.slug}` : null,
110
+ thumbnail: post.featured_image
111
+ ? { url: post.featured_image.url, width: post.featured_image.width, height: post.featured_image.height }
112
+ : post.og.image_url ? { url: post.og.image_url, width: null, height: null } : null
113
+ };
114
+ }
115
+ const page = await PublicContent.page(first);
116
+ if (!page || page.slug !== first)
117
+ return null;
118
+ return {
119
+ kind: 'link',
120
+ title: page.title,
121
+ description: page.meta_description,
122
+ authorName: null,
123
+ authorUrl: null,
124
+ thumbnail: page.featured_image
125
+ ? { url: page.featured_image.url, width: page.featured_image.width, height: page.featured_image.height }
126
+ : null
127
+ };
128
+ }
@@ -0,0 +1,20 @@
1
+ import type { Request, Response } from '../../types/index.ts';
2
+ export declare function themeEnabled(): Promise<boolean>;
3
+ /** For tests and for the settings screen: forget the cached decision. */
4
+ export declare function resetThemeCache(): void;
5
+ export declare const ThemeController: {
6
+ home: (req: Request, res: Response) => Promise<void>;
7
+ /** `/blog/:slug` — a blog post. */
8
+ post: (req: Request, res: Response) => Promise<void>;
9
+ /** `/:segment` — a type's archive if a type lives there, otherwise a page. */
10
+ single: (req: Request, res: Response) => Promise<void>;
11
+ /** `/:base/:slug` — an entry of a custom type. Anything else two segments deep is the SPA's or a 404. */
12
+ typed: (req: Request, res: Response) => Promise<void>;
13
+ /** `/page/:page` — the home page, paginated the WordPress way. */
14
+ homePage: (req: Request, res: Response) => Promise<void>;
15
+ category: (req: Request, res: Response) => Promise<void>;
16
+ tag: (req: Request, res: Response) => Promise<void>;
17
+ author: (req: Request, res: Response) => Promise<void>;
18
+ /** `/taxonomy/:key/:slug` — a custom taxonomy term's archive. */
19
+ term: (req: Request, res: Response) => Promise<void>;
20
+ };