@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,124 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Take a full backup of the site.
4
+ *
5
+ * Writes the JSON export — revisions included — to a timestamped file, and
6
+ * optionally gzips it, adds a scrubbed SQLite snapshot, uploads both to an S3
7
+ * bucket and deletes backups beyond the newest N. Meant for a cron:
8
+ *
9
+ * npm run backup -- --gzip --s3 --keep 14
10
+ *
11
+ * Options:
12
+ * --dir DIR where to write (default ./backups; created if missing)
13
+ * --gzip compress the JSON (node:zlib)
14
+ * --sqlite-copy also write a consistent copy of a SQLite database via
15
+ * VACUUM INTO, with credentials scrubbed out
16
+ * --s3 upload to BACKUP_S3_BUCKET (or the media bucket's S3_*
17
+ * settings) under --prefix
18
+ * --prefix NAME bucket folder (default backups/)
19
+ * --keep N keep the newest N backups — locally, and in the bucket
20
+ * with --s3 — and delete the rest
21
+ * --no-revisions leave post revision history out (smaller file)
22
+ * --remove-local with --s3, delete the local files after uploading
23
+ *
24
+ * Restore with `basicben-cms restore`. See docs/backup.md.
25
+ *
26
+ * Backups contain personal data (email addresses). They contain no secrets:
27
+ * the export omits password hashes, two-factor secrets, passkeys, API and
28
+ * email tokens, rate-limiter state and credential-looking settings, and the
29
+ * SQLite copy has the same removed before it is written.
30
+ */
31
+ import { mkdir, readFile, rm } from 'node:fs/promises';
32
+ import { resolve, join, basename } from 'node:path';
33
+ import { getDb } from '@basicbenframework/core/db';
34
+ import { createS3Adapter } from '@basicbenframework/core/storage';
35
+ import { parseArgs } from './lib/import-common.mjs';
36
+ import { PERSONAL_DATA_WARNING, backupBaseName, backupStorageConfig, normalizePrefix, writeJsonBackup, sqliteSnapshot, pruneLocal, pruneBucket } from './lib/backup.mjs';
37
+ import { recordHeartbeat, HEARTBEATS } from "../helpers/heartbeat.js";
38
+ const log = (line = '') => console.error(line);
39
+ const size = (bytes) => (bytes > 1048576 ? `${(bytes / 1048576).toFixed(1)} MB` : `${Math.ceil(bytes / 1024)} KB`);
40
+ async function main() {
41
+ const { flags, options } = parseArgs(process.argv.slice(2), {
42
+ flags: ['gzip', 'sqlite-copy', 's3', 'no-revisions', 'remove-local'],
43
+ options: ['dir', 'prefix', 'keep']
44
+ });
45
+ const keep = options.keep === undefined ? null : Number(options.keep);
46
+ if (keep !== null && (!Number.isInteger(keep) || keep < 1))
47
+ throw new Error('--keep must be a whole number of at least 1');
48
+ const prefix = normalizePrefix(options.prefix ?? 'backups/');
49
+ const dir = resolve(options.dir ?? 'backups');
50
+ await mkdir(dir, { recursive: true, mode: 0o700 });
51
+ // Resolved before any work, so a misconfigured upload fails in a second
52
+ // rather than after a ten-minute export.
53
+ let bucket = null;
54
+ if (flags.s3) {
55
+ const resolved = backupStorageConfig(process.env);
56
+ if (!resolved) {
57
+ throw new Error('--s3 needs BACKUP_S3_BUCKET (or S3_BUCKET) with an access key id and secret. See docs/backup.md.');
58
+ }
59
+ if (resolved.shared) {
60
+ log(`Uploading to the media bucket "${resolved.config.bucket}" under ${prefix}.`);
61
+ if (resolved.publicMediaUrl) {
62
+ log('WARNING: S3_PUBLIC_URL is set, so this bucket may be publicly readable. If every key in it is');
63
+ log('served publicly (R2 custom domains are), so is this backup. Set BACKUP_S3_BUCKET to a private bucket.');
64
+ }
65
+ }
66
+ bucket = createS3Adapter(resolved.config);
67
+ }
68
+ const db = await getDb();
69
+ const now = new Date();
70
+ const base = backupBaseName(now);
71
+ const written = [];
72
+ log(PERSONAL_DATA_WARNING);
73
+ log('');
74
+ const jsonPath = join(dir, `${base}.json${flags.gzip ? '.gz' : ''}`);
75
+ const jsonBytes = await writeJsonBackup(db, jsonPath, { gzip: flags.gzip, revisions: !flags['no-revisions'], now });
76
+ written.push(jsonPath);
77
+ log(`Wrote ${jsonPath} (${size(jsonBytes)})`);
78
+ if (flags['sqlite-copy']) {
79
+ const dbPath = join(dir, `${base}.sqlite`);
80
+ const dbBytes = await sqliteSnapshot(db, dbPath);
81
+ written.push(dbPath);
82
+ log(`Wrote ${dbPath} (${size(dbBytes)}, credentials scrubbed)`);
83
+ }
84
+ if (bucket) {
85
+ for (const path of written) {
86
+ const key = `${prefix}${basename(path)}`;
87
+ // Read whole: the framework's S3 put signs a body it can hash. Fine for
88
+ // a blog's database; a multi-gigabyte one wants the provider's backups.
89
+ await bucket.put(key, await readFile(path), {
90
+ contentType: path.endsWith('.gz') ? 'application/gzip' : path.endsWith('.json') ? 'application/json' : 'application/vnd.sqlite3',
91
+ cacheControl: 'no-store'
92
+ });
93
+ log(`Uploaded s3://${bucket.bucket}/${key}`);
94
+ }
95
+ if (flags['remove-local']) {
96
+ for (const path of written)
97
+ await rm(path, { force: true });
98
+ log('Removed the local copies.');
99
+ }
100
+ }
101
+ if (keep !== null) {
102
+ const local = await pruneLocal(dir, keep);
103
+ for (const name of local)
104
+ log(`Deleted old local backup ${name}`);
105
+ if (bucket) {
106
+ const remote = await pruneBucket(bucket, prefix, keep);
107
+ for (const key of remote)
108
+ log(`Deleted old bucket backup ${key}`);
109
+ }
110
+ }
111
+ // Best-effort: the health page reads this. A file name, never a path that
112
+ // might reveal more about the machine, and nothing else.
113
+ await recordHeartbeat(db, HEARTBEATS.BACKUP, {
114
+ file: basename(jsonPath),
115
+ bytes: jsonBytes,
116
+ sqlite_copy: Boolean(flags['sqlite-copy']),
117
+ uploaded: Boolean(bucket)
118
+ }, now);
119
+ log('\nBackup complete.');
120
+ }
121
+ main().then(() => process.exit(0), (error) => {
122
+ console.error(`\nBackup failed: ${error.message}`);
123
+ process.exit(1);
124
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Export the whole site to one JSON file.
4
+ *
5
+ * The same document the admin's Tools → Export button downloads, for when a
6
+ * shell is closer than a browser — a cron backup, or a database too large for
7
+ * a request to stream comfortably. Read back with `basicben-cms import:json`.
8
+ *
9
+ * Usage:
10
+ * npx basicben-cms export [options]
11
+ *
12
+ * --out FILE where to write (default basicben-export-YYYY-MM-DD.json;
13
+ * `-` for stdout)
14
+ * --revisions include post revision history (off by default: it can be
15
+ * most of the file)
16
+ *
17
+ * The database is whatever the app uses — DATABASE_URL, TURSO_URL, or
18
+ * basicben.config.js — exactly as `basicben migrate` resolves it.
19
+ *
20
+ * What is left out: password hashes, session versions, two-factor secrets,
21
+ * passkeys, API token hashes, email/reset tokens and rate-limiter state, plus
22
+ * any setting whose key looks like a credential. The file records what it
23
+ * omitted under `omitted`. See docs/import-export.md for the format.
24
+ */
25
+ import { createWriteStream } from 'node:fs';
26
+ import { once } from 'node:events';
27
+ import { getDb } from '@basicbenframework/core/db';
28
+ import { exportChunks, EXPORT_FORMAT } from "../helpers/export-data.js";
29
+ import { parseArgs } from './lib/import-common.mjs';
30
+ async function main() {
31
+ const { flags, options } = parseArgs(process.argv.slice(2), {
32
+ flags: ['revisions'],
33
+ options: ['out']
34
+ });
35
+ const outPath = options.out ?? `${EXPORT_FORMAT}-${new Date().toISOString().slice(0, 10)}.json`;
36
+ const toStdout = outPath === '-';
37
+ const out = toStdout ? process.stdout : createWriteStream(outPath);
38
+ const db = await getDb();
39
+ for await (const chunk of exportChunks(db, { revisions: flags.revisions })) {
40
+ if (!out.write(chunk))
41
+ await once(out, 'drain');
42
+ }
43
+ if (toStdout) {
44
+ out.write('\n');
45
+ return;
46
+ }
47
+ out.end('\n');
48
+ await once(out, 'finish');
49
+ console.error(`Exported to ${outPath}`);
50
+ }
51
+ main().then(() => process.exit(0), (error) => {
52
+ console.error(`\nExport failed: ${error.message}`);
53
+ process.exit(1);
54
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Import a Ghost export — Settings → Labs → Export your content (Ghost 4/5).
4
+ *
5
+ * Usage:
6
+ * npx basicben-cms import:ghost FILE.json [options]
7
+ *
8
+ * --url URL the Ghost site's address, to resolve the
9
+ * `__GHOST_URL__` placeholder in image URLs
10
+ * --dry-run report what would change, write nothing
11
+ * --update overwrite posts, pages, terms and media that
12
+ * already exist (matched by slug / path)
13
+ * --no-primary-category do not turn each post's primary tag into its
14
+ * primary category as well
15
+ * --no-authors attribute everything to the first admin
16
+ * --skip-media do not create media rows
17
+ * --verbose print every row written
18
+ *
19
+ * Ghost has no comments in its export (they live with members), so none come
20
+ * across. How tags, the primary tag, statuses, members-only posts and images
21
+ * are mapped is described in src/cli/lib/ghost.mjs and docs/import-export.md.
22
+ */
23
+ import { readFile } from 'node:fs/promises';
24
+ import { getDb } from '@basicbenframework/core/db';
25
+ import { parseArgs } from './lib/import-common.mjs';
26
+ import { parseGhost } from './lib/ghost.mjs';
27
+ import { runSiteImport } from './lib/site-import.mjs';
28
+ async function main() {
29
+ const { flags, options, positional } = parseArgs(process.argv.slice(2), {
30
+ flags: ['dry-run', 'update', 'no-primary-category', 'no-authors', 'skip-media', 'verbose'],
31
+ options: ['url']
32
+ });
33
+ const [file] = positional;
34
+ if (!file)
35
+ throw new Error('Pass the export file: basicben-cms import:ghost ghost-export.json');
36
+ const site = parseGhost(await readFile(file, 'utf-8'), {
37
+ siteUrl: options.url ?? process.env.GHOST_URL,
38
+ primaryTagAsCategory: !flags['no-primary-category']
39
+ });
40
+ const db = await getDb();
41
+ console.log(`Importing ${file} (Ghost ${site.meta.version ?? 'unknown version'})`);
42
+ console.log(`Found ${site.posts.filter((p) => p.type === 'post').length} post(s), ` +
43
+ `${site.posts.filter((p) => p.type === 'page').length} page(s), ` +
44
+ `${site.tags.length} tag(s), ${site.authors.length} author(s).`);
45
+ await runSiteImport(db, site, flags);
46
+ }
47
+ main().then(() => process.exit(0), (error) => {
48
+ console.error(`\nImport failed: ${error.message}`);
49
+ process.exit(1);
50
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Import a BasicBen export (from Tools → Export or `basicben-cms export`).
4
+ *
5
+ * For moving a site between databases. Safe to re-run: rows are matched on
6
+ * their natural keys (slug, address, object key, setting key) and existing
7
+ * ones are left alone, so a second run adds nothing. Ids are remapped, so the
8
+ * target can already have content.
9
+ *
10
+ * Usage:
11
+ * npx basicben-cms import:json FILE [options]
12
+ *
13
+ * --dry-run report what would change, write nothing
14
+ * --update overwrite matching posts, pages, terms, media and settings
15
+ * with the file's values (user accounts are never changed)
16
+ * --verbose print every row written
17
+ *
18
+ * Imported accounts keep their role but have no password — an export never
19
+ * carries one — so each signs in through "forgot password". Two-factor,
20
+ * passkeys and API tokens are not exported and must be set up again.
21
+ *
22
+ * Needs an admin account in the target to own anything whose author did not
23
+ * come across. See docs/import-export.md.
24
+ */
25
+ import { readFile } from 'node:fs/promises';
26
+ import { getDb } from '@basicbenframework/core/db';
27
+ import { parseArgs, withDryRun, defaultAuthor, NO_ADMIN_MESSAGE } from './lib/import-common.mjs';
28
+ import { readExport, importExport } from './lib/json-import.mjs';
29
+ async function main() {
30
+ const { flags, positional } = parseArgs(process.argv.slice(2), {
31
+ flags: ['dry-run', 'update', 'verbose']
32
+ });
33
+ const [file] = positional;
34
+ if (!file)
35
+ throw new Error('Pass the export file: basicben-cms import:json basicben-export.json');
36
+ const doc = readExport(await readFile(file, 'utf-8'));
37
+ const db = await getDb();
38
+ const admin = await defaultAuthor(db);
39
+ if (!admin) {
40
+ console.error(NO_ADMIN_MESSAGE);
41
+ process.exit(1);
42
+ }
43
+ console.log(`Importing ${file} (format v${doc.version}, exported ${doc.exported_at})`);
44
+ if (flags['dry-run'])
45
+ console.log('Dry run — nothing will be written.');
46
+ if (flags.update)
47
+ console.log('Updating rows that already exist.');
48
+ console.log('');
49
+ const report = await withDryRun(db, flags['dry-run'], (tx) => importExport(tx, doc, {
50
+ defaultAuthorId: admin.id,
51
+ update: flags.update,
52
+ log: flags.verbose ? console.log : undefined
53
+ }));
54
+ console.log(`\n${report}`);
55
+ if (flags['dry-run'])
56
+ console.log('\nDry run complete. Nothing was written.');
57
+ }
58
+ main().then(() => process.exit(0), (error) => {
59
+ console.error(`\nImport failed: ${error.message}`);
60
+ process.exit(1);
61
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Import from a live WordPress site over its REST API.
4
+ *
5
+ * Posts, pages, categories, tags, comments, authors and the media library.
6
+ * Everything is matched on slug (or object key, or address), so it is safe to
7
+ * run as often as you like: the useful way to cut over is to import now, keep
8
+ * publishing on WordPress, and re-run immediately before flipping traffic
9
+ * across. Existing content is left alone unless `--update` is passed — use it
10
+ * on that last run to pick up edits made since the first.
11
+ *
12
+ * For a site that is already offline, or to bring across drafts and private
13
+ * posts without an application password, use the WXR export file instead:
14
+ * `basicben-cms import:wxr`.
15
+ *
16
+ * Usage:
17
+ * npx basicben-cms import:wordpress [options]
18
+ *
19
+ * --dry-run report what would change, write nothing
20
+ * --update overwrite posts, pages, terms and media that already exist
21
+ * --limit N only the N most recent posts, for a quick look
22
+ * --skip-media leave the media library alone
23
+ * --skip-pages posts only
24
+ * --no-comments skip comments
25
+ * --no-authors attribute everything to the first admin, as this script
26
+ * used to, instead of creating author accounts
27
+ * --verbose print every row written
28
+ * --url URL override WORDPRESS_URL
29
+ *
30
+ * Set WORDPRESS_AUTH=user:application-password to read as a signed-in user.
31
+ * Anonymous requests see only published content, approved comments and no
32
+ * author addresses; with it, drafts, scheduled, pending and private posts,
33
+ * held and spam comments, and authors' email addresses come across too.
34
+ *
35
+ * ## What is and is not carried across
36
+ *
37
+ * Media is catalogued, not copied. The whole library comes across as rows
38
+ * recording the object key each file already has, served through
39
+ * `storage.publicUrl` — so images resolve when the storage driver points at the
40
+ * host already serving them (S3_PUBLIC_URL). If your WordPress media sits on
41
+ * the WordPress host itself rather than on object storage, migrate the files
42
+ * first or those URLs will not resolve.
43
+ *
44
+ * Importing only the images posts *point at* is not enough, and was the first
45
+ * version of this. Pictures inside post bodies keep displaying either way,
46
+ * because the stored HTML carries absolute URLs — but the library holds only
47
+ * what was imported, so anything missed cannot be browsed or reused when
48
+ * writing. `--skip-media` opts out.
49
+ *
50
+ * Categories are many-to-many here as they are in WordPress, so a post keeps
51
+ * all of them. The first is also recorded on the post row as its primary
52
+ * category, which is what a breadcrumb or canonical URL would name.
53
+ *
54
+ * They used to be folded into tags — the schema allowed one category per post,
55
+ * and the alternative was dropping them. On the first real migration that
56
+ * demoted 67 of 83 categories, which preserved the words and lost the meaning.
57
+ *
58
+ * Authors become accounts with the `author` role — never more, whatever they
59
+ * were in WordPress — and no usable password; each signs in by resetting it.
60
+ * An author whose address already has an account here is matched to it, and
61
+ * that account is not changed. Without WORDPRESS_AUTH the API hides
62
+ * addresses, so new accounts get a placeholder `<slug>@imported.invalid`
63
+ * that must be corrected before a reset can reach them.
64
+ *
65
+ * Content is stored twice, deliberately. `content_html` is WordPress's own
66
+ * rendered HTML, put through the CMS's sanitizer, which is what the blog
67
+ * renders, so the site looks the same after the cutover. `content` is that
68
+ * HTML converted to Markdown, because this CMS edits Markdown — storing HTML
69
+ * there would show raw tags in the editor and make `?format=markdown` a lie.
70
+ * Editing a post in the admin re-renders the HTML from the Markdown, so an
71
+ * edited post may differ cosmetically from WordPress's output. That only
72
+ * happens to posts you actually edit.
73
+ *
74
+ * The rules shared with the other importers — matching, conversion, what an
75
+ * author account gets — live in `src/cli/lib/site-import.mjs`.
76
+ */
77
+ import { getDb } from '@basicbenframework/core/db';
78
+ import { parseArgs } from './lib/import-common.mjs';
79
+ import { mapRestSite } from './lib/wordpress-rest.mjs';
80
+ import { runSiteImport } from './lib/site-import.mjs';
81
+ const { flags, options } = parseArgs(process.argv.slice(2), {
82
+ flags: ['dry-run', 'update', 'skip-media', 'skip-pages', 'no-comments', 'no-authors', 'verbose'],
83
+ options: ['limit', 'url']
84
+ });
85
+ const limit = options.limit === undefined ? null : Number(options.limit);
86
+ const WORDPRESS_URL = (options.url ?? process.env.WORDPRESS_URL)?.replace(/\/$/, '');
87
+ const AUTH = process.env.WORDPRESS_AUTH;
88
+ if (!WORDPRESS_URL) {
89
+ console.error('Set WORDPRESS_URL in .env, or pass --url https://example.com');
90
+ process.exit(1);
91
+ }
92
+ if (options.limit !== undefined && (!Number.isInteger(limit) || limit < 1)) {
93
+ console.error('--limit needs a positive whole number');
94
+ process.exit(1);
95
+ }
96
+ const headers = AUTH ? { Authorization: `Basic ${Buffer.from(AUTH).toString('base64')}` } : {};
97
+ /**
98
+ * Every item from a WordPress collection, following its paging.
99
+ *
100
+ * WordPress answers 400 rather than an empty array once you ask past the last
101
+ * page, which is why that is a break and not an error.
102
+ */
103
+ async function fetchAll(resource, query = '') {
104
+ const items = [];
105
+ let page = 1;
106
+ while (true) {
107
+ const endpoint = `${WORDPRESS_URL}/wp-json/wp/v2/${resource}?per_page=100&page=${page}${query}`;
108
+ const response = await fetch(endpoint, { headers });
109
+ if (response.status === 400 && page > 1)
110
+ break; // past the last page
111
+ if (!response.ok)
112
+ throw new Error(`WordPress returned ${response.status} for ${resource} page ${page}`);
113
+ const batch = await response.json();
114
+ if (!Array.isArray(batch) || batch.length === 0)
115
+ break;
116
+ items.push(...batch);
117
+ const totalPages = Number(response.headers.get('x-wp-totalpages') || '1');
118
+ if (page >= totalPages)
119
+ break;
120
+ page++;
121
+ }
122
+ return items;
123
+ }
124
+ /** Comments in every moderation state this credential can see. */
125
+ async function fetchComments() {
126
+ if (!AUTH)
127
+ return fetchAll('comments');
128
+ const all = [];
129
+ for (const status of ['approve', 'hold', 'spam']) {
130
+ const batch = await fetchAll('comments', `&status=${status}&context=edit`);
131
+ // `context=edit` reports the state as the query named it; make it explicit.
132
+ all.push(...batch.map((c) => ({ ...c, status: c.status ?? status })));
133
+ }
134
+ return all;
135
+ }
136
+ async function main() {
137
+ // Drafts and the rest need a signed-in request; anonymously, asking for
138
+ // them is a 400, so the status filter is only sent with credentials.
139
+ const statusQuery = AUTH ? '&status=publish,future,draft,pending,private' : '';
140
+ console.log(`Importing from ${WORDPRESS_URL}${AUTH ? ' (authenticated)' : ''}`);
141
+ let posts = await fetchAll('posts', `&_embed${statusQuery}`);
142
+ posts.sort((a, b) => new Date(a.date_gmt || a.date) - new Date(b.date_gmt || b.date));
143
+ if (limit)
144
+ posts = posts.slice(-limit);
145
+ const pages = flags['skip-pages'] ? [] : await fetchAll('pages', `&_embed${statusQuery}`);
146
+ const media = flags['skip-media'] ? [] : await fetchAll('media');
147
+ const categories = await fetchAll('categories');
148
+ // Security plugins commonly close the users and comments endpoints. That
149
+ // costs bylines or comments, not the import, so it is a warning.
150
+ const optional = (what, promise) => promise.catch((error) => {
151
+ console.warn(`Could not read ${what} (${error.message}); continuing without them.`);
152
+ return [];
153
+ });
154
+ const users = flags['no-authors'] ? [] : await optional('authors', fetchAll('users', AUTH ? '&context=edit' : ''));
155
+ // With --limit, only the comments on the posts being imported.
156
+ const postIds = new Set(posts.map((p) => p.id));
157
+ const comments = flags['no-comments']
158
+ ? []
159
+ : (await optional('comments', fetchComments())).filter((c) => postIds.has(c.post));
160
+ console.log(`Found ${posts.length} post(s), ${pages.length} page(s), ${comments.length} comment(s), ` +
161
+ `${media.length} media item(s), ${users.length} author(s).`);
162
+ const site = mapRestSite({ posts, pages, media, comments, users, categories });
163
+ const db = await getDb();
164
+ await runSiteImport(db, site, flags);
165
+ }
166
+ main().then(() => process.exit(0), (error) => {
167
+ console.error(`\nImport failed: ${error.message}`);
168
+ process.exit(1);
169
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Import a WordPress export file (WXR) — Tools → Export → All content.
4
+ *
5
+ * Offline: the old site does not need to be running, reachable, or to have
6
+ * its REST API open. The file also carries what the API hides from an
7
+ * anonymous caller — drafts, scheduled and private posts, author addresses,
8
+ * and every comment with its moderation state — so for a full move it is the
9
+ * better source. `basicben-cms import:wordpress` remains for live sync from a
10
+ * site that is still publishing.
11
+ *
12
+ * Usage:
13
+ * npx basicben-cms import:wxr FILE.xml [options]
14
+ *
15
+ * --dry-run report what would change, write nothing
16
+ * --update overwrite posts, pages, terms and media that already
17
+ * exist (matched by slug / path). Default: leave them be
18
+ * --no-authors attribute everything to the first admin instead of
19
+ * creating author accounts
20
+ * --no-comments skip comments
21
+ * --skip-media do not create media rows (featured images then unset)
22
+ * --verbose print every row written
23
+ *
24
+ * What comes across, and how, is described in src/cli/lib/wxr.mjs and
25
+ * docs/import-export.md. In short: posts, pages (with hierarchy, menu order
26
+ * and template), categories (with hierarchy), tags, threaded comments,
27
+ * authors (as `author` accounts with no usable password), attachments as
28
+ * media rows pointing at their existing paths, featured images, and Yoast
29
+ * SEO fields. Files are not downloaded.
30
+ */
31
+ import { readFile } from 'node:fs/promises';
32
+ import { getDb } from '@basicbenframework/core/db';
33
+ import { parseArgs } from './lib/import-common.mjs';
34
+ import { parseWxr } from './lib/wxr.mjs';
35
+ import { runSiteImport } from './lib/site-import.mjs';
36
+ async function main() {
37
+ const { flags, positional } = parseArgs(process.argv.slice(2), {
38
+ flags: ['dry-run', 'update', 'no-authors', 'no-comments', 'skip-media', 'verbose']
39
+ });
40
+ const [file] = positional;
41
+ if (!file)
42
+ throw new Error('Pass the export file: basicben-cms import:wxr wordpress-export.xml');
43
+ const site = parseWxr(await readFile(file, 'utf-8'));
44
+ const db = await getDb();
45
+ console.log(`Importing ${file}: "${site.meta.title}" (${site.meta.baseUrl || site.meta.link}, WXR ${site.meta.wxrVersion})`);
46
+ console.log(`Found ${site.posts.filter((p) => p.type === 'post').length} post(s), ` +
47
+ `${site.posts.filter((p) => p.type === 'page').length} page(s), ` +
48
+ `${site.comments.length} comment(s), ${site.media.length} attachment(s), ` +
49
+ `${site.authors.length} author(s).`);
50
+ await runSiteImport(db, site, flags);
51
+ }
52
+ main().then(() => process.exit(0), (error) => {
53
+ console.error(`\nImport failed: ${error.message}`);
54
+ process.exit(1);
55
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
3
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
4
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
5
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
6
+ });
7
+ }
8
+ return path;
9
+ };
10
+ /**
11
+ * `basicben-cms`: the CMS's command-line tools, run from a site.
12
+ *
13
+ * npx basicben-cms export | import:json | import:wxr | import:ghost |
14
+ * import:wordpress | backup | restore [options]
15
+ *
16
+ * Each takes the same options as before, and `--help` on its own prints the
17
+ * usage at the top of its file. Like `basicben migrate`, a command reads the
18
+ * site's .env and then its basicben.config.js (through core's getDb), from
19
+ * the directory it is run in.
20
+ */
21
+ import { existsSync, readFileSync } from 'node:fs';
22
+ import { resolve } from 'node:path';
23
+ import { fileURLToPath } from 'node:url';
24
+ const COMMANDS = {
25
+ export: './export.mjs',
26
+ 'import:json': './import-json.mjs',
27
+ 'import:wxr': './import-wxr.mjs',
28
+ 'import:ghost': './import-ghost.mjs',
29
+ 'import:wordpress': './import-wordpress.mjs',
30
+ backup: './backup.mjs',
31
+ restore: './restore.mjs'
32
+ };
33
+ const [command, ...args] = process.argv.slice(2);
34
+ if (!command || command === '--help' || command === '-h' || !Object.hasOwn(COMMANDS, command)) {
35
+ if (command && !['--help', '-h'].includes(command))
36
+ console.error(`Unknown command: ${command}\n`);
37
+ console.log(`Usage: basicben-cms <command> [options]\n\nCommands:\n${Object.keys(COMMANDS).map((name) => ` ${name}`).join('\n')}\n\nRun one with --help for its options.`);
38
+ process.exit(command && !['--help', '-h'].includes(command) ? 1 : 0);
39
+ }
40
+ const file = new URL(COMMANDS[command], import.meta.url);
41
+ if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
42
+ // The usage block every command opens with.
43
+ const source = readFileSync(fileURLToPath(file), 'utf-8');
44
+ const block = source.match(/\/\*\*([\s\S]*?)\*\//);
45
+ console.log(block ? block[1].replace(/^\s*\* ?/gm, '').trim() : `basicben-cms ${command}`);
46
+ process.exit(0);
47
+ }
48
+ // What `node --env-file-if-exists=.env` did when these were npm scripts.
49
+ if (existsSync(resolve('.env')))
50
+ process.loadEnvFile(resolve('.env'));
51
+ // The command reads process.argv as if it had been run directly.
52
+ process.argv = [process.argv[0], fileURLToPath(file), ...args];
53
+ await import(__rewriteRelativeImportExtension(file.href));