@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,456 @@
1
+ /**
2
+ * Write a normalized site into the database.
3
+ *
4
+ * Every foreign-CMS importer — WXR, Ghost, the WordPress REST API — reads its
5
+ * source into the same plain shape (below) and hands it here, so the rules
6
+ * about what is created, what is skipped and what is converted live in one
7
+ * place instead of drifting between three scripts.
8
+ *
9
+ * ## The site shape
10
+ *
11
+ * authors: { key, name, email?, slug?, bio?, website?, avatarUrl? }
12
+ * categories: { key, name, slug, description?, parentKey? }
13
+ * tags: { key, name, slug }
14
+ * media: { key?, url, mimeType?, alt?, size?, width?, height?, createdAt? }
15
+ * posts: { key, type: 'post' | 'page', title, slug, html?, markdown?,
16
+ * excerpt?, status: 'published' | 'draft' | 'pending',
17
+ * publishAt?, createdAt?, updatedAt?, trashed?, authorKey?,
18
+ * categoryKeys?, tagKeys?, featuredImage? (url or media key),
19
+ * parentKey?, menuOrder?, template?,
20
+ * seo?: { meta_title, meta_description, og_title, og_description,
21
+ * og_image, twitter_title, twitter_description,
22
+ * twitter_image, canonical_url, noindex } }
23
+ * comments: { key, postKey, parentKey?, authorName?, authorEmail?,
24
+ * userKey?, html, status: 'approved' | 'pending' | 'spam',
25
+ * createdAt? }
26
+ *
27
+ * `key` is whatever identifies the thing in the source (a WordPress id, a
28
+ * Ghost ObjectId) and is only used to connect records to each other here.
29
+ *
30
+ * ## The rules
31
+ *
32
+ * - Matched on slug (posts, pages, terms), address (users) or object key
33
+ * (media). An existing row is left alone unless `update` is set; it is still
34
+ * *used*, so a new post can be filed under a category that already existed.
35
+ * - Existing user accounts are never modified, even with `update`: an import
36
+ * file must not be able to rename, re-role or re-password a real account.
37
+ * - New authors are created as `author`, never anything more, with a password
38
+ * nothing matches. They sign in by resetting it.
39
+ * - Content is converted once, here. `content` is Markdown (what this CMS
40
+ * edits); `content_html` is the source's HTML put through the same sanitizer
41
+ * the content pipeline ends with, so the site looks as it did and nothing
42
+ * unsafe is stored. Editing a post re-renders the HTML from the Markdown.
43
+ */
44
+ import { sanitizeHtml, renderContent, excerpt as excerptOf, slugify } from '@basicbenframework/core/content';
45
+ import { htmlToMarkdown, commentText } from './html-to-markdown.mjs';
46
+ import { insertRow, updateRow, tableColumns, toTimestamp, objectKey, mimeFromName, unusablePassword, uniqueSlug, withDryRun, defaultAuthor, NO_ADMIN_MESSAGE, Report } from './import-common.mjs';
47
+ /**
48
+ * @param {object} db
49
+ * @param {object} site - see the shape above
50
+ * @param {object} options
51
+ * @param {number} options.defaultAuthorId - who owns content with no author
52
+ * @param {boolean} [options.update] - overwrite matching rows
53
+ * @param {boolean} [options.authors] - create authors (default true); false attributes everything to the default
54
+ * @param {boolean} [options.comments] - import comments (default true)
55
+ * @param {boolean} [options.media] - import media rows (default true)
56
+ * @param {(line: string) => void} [options.log]
57
+ * @param {Report} [options.report]
58
+ * @returns {Promise<Report>}
59
+ */
60
+ export async function importSite(db, site, options) {
61
+ const { defaultAuthorId, update = false, log = () => { }, report = new Report() } = options;
62
+ const wantAuthors = options.authors !== false;
63
+ const wantComments = options.comments !== false;
64
+ const wantMedia = options.media !== false;
65
+ const now = new Date().toISOString();
66
+ const ids = {
67
+ authors: new Map(),
68
+ categories: new Map(),
69
+ tags: new Map(),
70
+ media: new Map(), // url and media key → id
71
+ posts: new Map(), // post key → { table, id }
72
+ pageParents: []
73
+ };
74
+ // Authors
75
+ for (const author of wantAuthors ? site.authors ?? [] : []) {
76
+ ids.authors.set(author.key, await importAuthor(db, author, { report, log, now, ids }));
77
+ }
78
+ // Media: the library first, so posts link to the complete row rather than a
79
+ // sparse one made up from a featured-image reference.
80
+ const mediaFor = async (ref) => {
81
+ if (!ref || !wantMedia)
82
+ return null;
83
+ if (ids.media.has(ref))
84
+ return ids.media.get(ref);
85
+ if (!/^https?:\/\//i.test(ref))
86
+ return null;
87
+ const id = await importMedia(db, { url: ref }, { report, log, update, defaultAuthorId });
88
+ ids.media.set(ref, id);
89
+ return id;
90
+ };
91
+ for (const item of wantMedia ? site.media ?? [] : []) {
92
+ const id = await importMedia(db, item, { report, log, update, defaultAuthorId });
93
+ if (item.key)
94
+ ids.media.set(item.key, id);
95
+ ids.media.set(item.url, id);
96
+ }
97
+ // Author avatars point into the library, so they wait for it.
98
+ for (const author of wantAuthors ? site.authors ?? [] : []) {
99
+ const userId = ids.authors.get(author.key);
100
+ if (userId?.created && author.avatarUrl) {
101
+ const avatar = await mediaFor(author.avatarUrl);
102
+ if (avatar)
103
+ await updateRow(db, 'users', userId.id, { avatar_id: avatar });
104
+ }
105
+ }
106
+ // Terms
107
+ for (const category of site.categories ?? []) {
108
+ ids.categories.set(category.key, await importTerm(db, 'categories', category, { report, log, update }));
109
+ }
110
+ // Parents after every category exists, since a WXR file is free to list a
111
+ // child before its parent.
112
+ for (const category of site.categories ?? []) {
113
+ if (!category.parentKey)
114
+ continue;
115
+ const id = ids.categories.get(category.key);
116
+ const parent = ids.categories.get(category.parentKey);
117
+ if (!id || !parent || id.id === parent.id)
118
+ continue;
119
+ if (id.created || update)
120
+ await updateRow(db, 'categories', id.id, { parent_id: parent.id });
121
+ }
122
+ for (const tag of site.tags ?? []) {
123
+ ids.tags.set(tag.key, await importTerm(db, 'tags', tag, { report, log, update }));
124
+ }
125
+ // Posts and pages
126
+ for (const item of site.posts ?? []) {
127
+ await db.transaction(async (tx) => {
128
+ await importItem(tx, item, { report, log, update, now, ids, defaultAuthorId, mediaFor });
129
+ });
130
+ }
131
+ for (const { id, parentKey } of ids.pageParents) {
132
+ const parent = ids.posts.get(parentKey);
133
+ if (parent?.table === 'pages' && parent.id !== id) {
134
+ await updateRow(db, 'pages', id, { parent_id: parent.id });
135
+ }
136
+ else if (parentKey) {
137
+ report.note('A page\'s parent was not in the import, so it was left at the top level');
138
+ }
139
+ }
140
+ // Comments
141
+ if (wantComments)
142
+ await importComments(db, site.comments ?? [], { report, log, ids });
143
+ return report;
144
+ }
145
+ async function importAuthor(db, author, { report, log, now }) {
146
+ const email = (author.email || `${slugify(author.slug || author.name || '') || 'author'}@imported.invalid`).toLowerCase();
147
+ const existing = await db.get('SELECT id FROM users WHERE LOWER(email) = ?', [email]);
148
+ if (existing) {
149
+ report.count('authors', 'matched');
150
+ return { id: Number(existing.id), created: false };
151
+ }
152
+ if (!author.email) {
153
+ report.note('Some authors had no email address in the source; they were given <slug>@imported.invalid — set the real address before they reset a password');
154
+ }
155
+ const slug = await uniqueSlug(db, 'users', slugify(author.slug || author.name || ''), 'author');
156
+ const id = await insertRow(db, 'users', {
157
+ name: author.name || slug,
158
+ email,
159
+ password: unusablePassword(),
160
+ // Never more than this, whatever the source said: an export file must not
161
+ // be a way to mint administrators.
162
+ role: 'author',
163
+ slug,
164
+ bio: author.bio || null,
165
+ website: author.website || null,
166
+ // Unverified until they reset the password, which proves the address.
167
+ email_verified: 0,
168
+ created_at: toTimestamp(author.createdAt) ?? now
169
+ });
170
+ log(`create author ${slug} <${email}>`);
171
+ report.count('authors', 'created');
172
+ return { id, created: true };
173
+ }
174
+ async function importMedia(db, item, { report, log, update, defaultAuthorId }) {
175
+ const key = objectKey(item.url);
176
+ if (!key) {
177
+ report.count('media', 'skipped');
178
+ report.note('Media with a URL that could not be parsed was skipped');
179
+ return null;
180
+ }
181
+ const existing = await db.get('SELECT id FROM media WHERE path = ?', [key]);
182
+ const filename = key.split('/').pop() || key;
183
+ const row = {
184
+ mime_type: item.mimeType || mimeFromName(filename),
185
+ // Unknown is null. Inventing a byte count would be worse than admitting it.
186
+ size: Number(item.size) || null,
187
+ alt_text: item.alt || null,
188
+ width: Number(item.width) || null,
189
+ height: Number(item.height) || null
190
+ };
191
+ if (existing) {
192
+ if (update) {
193
+ await updateRow(db, 'media', existing.id, row);
194
+ report.count('media', 'updated');
195
+ }
196
+ else {
197
+ report.count('media', 'existing');
198
+ }
199
+ return Number(existing.id);
200
+ }
201
+ const id = await insertRow(db, 'media', {
202
+ user_id: defaultAuthorId,
203
+ filename,
204
+ original_name: filename,
205
+ path: key,
206
+ ...row,
207
+ created_at: toTimestamp(item.createdAt) ?? undefined
208
+ });
209
+ log(`create media ${key}`);
210
+ report.count('media', 'created');
211
+ return id;
212
+ }
213
+ async function importTerm(db, table, term, { report, log, update }) {
214
+ const slug = term.slug || slugify(term.name || '');
215
+ const entity = table === 'categories' ? 'categories' : 'tags';
216
+ if (!slug) {
217
+ report.count(entity, 'skipped');
218
+ return null;
219
+ }
220
+ const existing = await db.get(`SELECT id FROM ${table} WHERE slug = ?`, [slug]);
221
+ const row = table === 'categories'
222
+ ? { name: term.name || slug, description: term.description || null }
223
+ : { name: term.name || slug };
224
+ if (existing) {
225
+ if (update) {
226
+ await updateRow(db, table, existing.id, row);
227
+ report.count(entity, 'updated');
228
+ }
229
+ else {
230
+ report.count(entity, 'existing');
231
+ }
232
+ return { id: Number(existing.id), created: false };
233
+ }
234
+ const id = await insertRow(db, table, { ...row, slug });
235
+ log(`create ${table === 'categories' ? 'category' : 'tag'} ${slug}`);
236
+ report.count(entity, 'created');
237
+ return { id, created: true };
238
+ }
239
+ async function importItem(db, item, { report, log, update, now, ids, defaultAuthorId, mediaFor }) {
240
+ const isPage = item.type === 'page';
241
+ const table = isPage ? 'pages' : 'posts';
242
+ const entity = isPage ? 'pages' : 'posts';
243
+ const slug = item.slug || slugify(item.title || '');
244
+ if (!slug) {
245
+ report.count(entity, 'skipped');
246
+ report.note(`An untitled ${isPage ? 'page' : 'post'} with no slug was skipped`);
247
+ return;
248
+ }
249
+ const existing = await db.get(`SELECT id FROM ${table} WHERE slug = ?`, [slug]);
250
+ if (existing && !update) {
251
+ // Still recorded, so comments and child pages can attach to it.
252
+ // Its parent is left as it is, too.
253
+ ids.posts.set(item.key, { table, id: Number(existing.id), created: false });
254
+ report.count(entity, 'existing');
255
+ return;
256
+ }
257
+ const html = item.html ?? null;
258
+ const markdown = item.markdown ?? (html ? htmlToMarkdown(html) : '');
259
+ const contentHtml = html ? sanitizeHtml(html) : await renderContent(markdown, { filter: false });
260
+ const createdAt = toTimestamp(item.createdAt) ?? toTimestamp(item.publishAt) ?? now;
261
+ const updatedAt = toTimestamp(item.updatedAt) ?? createdAt;
262
+ const publishAt = toTimestamp(item.publishAt);
263
+ const published = item.status === 'published';
264
+ const seo = item.seo ?? {};
265
+ const featured = await mediaFor(item.featuredImage);
266
+ const shared = {
267
+ title: item.title || slug,
268
+ slug,
269
+ content: markdown,
270
+ content_html: contentHtml,
271
+ featured_image: featured,
272
+ meta_title: seo.meta_title || null,
273
+ meta_description: seo.meta_description || null,
274
+ og_title: seo.og_title || null,
275
+ og_description: seo.og_description || null,
276
+ og_image: await mediaFor(seo.og_image),
277
+ twitter_title: seo.twitter_title || null,
278
+ twitter_description: seo.twitter_description || null,
279
+ twitter_image: await mediaFor(seo.twitter_image),
280
+ canonical_url: seo.canonical_url || null,
281
+ noindex: seo.noindex ? 1 : 0,
282
+ created_at: createdAt,
283
+ updated_at: updatedAt
284
+ };
285
+ let row;
286
+ if (isPage) {
287
+ row = {
288
+ ...shared,
289
+ // Pages have no schedule and no review state: live or not.
290
+ published: published && !(publishAt && publishAt > now) ? 1 : 0,
291
+ template: item.template || 'default',
292
+ menu_order: Number(item.menuOrder) || 0
293
+ };
294
+ if (published && publishAt && publishAt > now) {
295
+ report.note('Scheduled pages were imported as drafts; pages have no publish date here');
296
+ }
297
+ }
298
+ else {
299
+ const categoryIds = unique((item.categoryKeys ?? []).map((k) => ids.categories.get(k)?.id).filter(Boolean));
300
+ const author = ids.authors.get(item.authorKey)?.id ?? defaultAuthorId;
301
+ row = {
302
+ ...shared,
303
+ user_id: author,
304
+ excerpt: item.excerpt || excerptOf(markdown) || null,
305
+ status: item.status || 'draft',
306
+ published: published ? 1 : 0,
307
+ // A published post with no date went live when it was written.
308
+ publish_at: published ? publishAt ?? createdAt : publishAt,
309
+ deleted_at: item.trashed ? now : null,
310
+ // Live posts were announced by the old site; a scheduled one is
311
+ // announced here when its time comes, by the publish-due tick.
312
+ live_notified: published && publishAt && publishAt > now ? 0 : 1,
313
+ category_id: categoryIds[0] ?? null
314
+ };
315
+ row.categoryIds = categoryIds;
316
+ }
317
+ const { categoryIds = [] } = row;
318
+ delete row.categoryIds;
319
+ let id;
320
+ if (existing) {
321
+ id = Number(existing.id);
322
+ await updateRow(db, table, id, row);
323
+ log(`update ${isPage ? 'page' : 'post'} ${slug}`);
324
+ report.count(entity, 'updated');
325
+ }
326
+ else {
327
+ id = await insertRow(db, table, row);
328
+ log(`create ${isPage ? 'page' : 'post'} ${slug}`);
329
+ report.count(entity, 'created');
330
+ }
331
+ ids.posts.set(item.key, { table, id, created: !existing });
332
+ if (isPage) {
333
+ if (item.parentKey)
334
+ ids.pageParents.push({ id, parentKey: item.parentKey });
335
+ return;
336
+ }
337
+ // Rebuilt rather than merged: a term removed at the source should disappear
338
+ // here too, and re-running must not accumulate.
339
+ await db.run('DELETE FROM post_categories WHERE post_id = ?', [id]);
340
+ await db.run('DELETE FROM post_tags WHERE post_id = ?', [id]);
341
+ for (const categoryId of categoryIds) {
342
+ await db.run('INSERT INTO post_categories (post_id, category_id) VALUES (?, ?)', [id, categoryId]);
343
+ }
344
+ const tagIds = unique((item.tagKeys ?? []).map((k) => ids.tags.get(k)?.id).filter(Boolean));
345
+ for (const tagId of tagIds) {
346
+ await db.run('INSERT INTO post_tags (post_id, tag_id) VALUES (?, ?)', [id, tagId]);
347
+ }
348
+ }
349
+ /**
350
+ * Comments, threaded.
351
+ *
352
+ * Sorted oldest first so a parent is written before its replies; a reply
353
+ * whose parent was not imported (spam, say) is kept at the top level rather
354
+ * than dropped. Matched on post, time and text, so re-running adds nothing.
355
+ *
356
+ * Spam: if the comments table has a `status` or `spam` column (the spam
357
+ * workstream adds one), spam is imported and marked as such. Without one there
358
+ * is nowhere to say "this is spam" short of pending, where it would sit in the
359
+ * moderation queue looking like a real comment, so it is skipped and counted.
360
+ */
361
+ async function importComments(db, comments, { report, log, ids }) {
362
+ const columns = await tableColumns(db, 'comments');
363
+ const commentIds = new Map();
364
+ const ordered = [...comments].sort((a, b) => String(toTimestamp(a.createdAt) ?? '').localeCompare(String(toTimestamp(b.createdAt) ?? '')));
365
+ for (const comment of ordered) {
366
+ const post = ids.posts.get(comment.postKey);
367
+ if (!post || post.table !== 'posts') {
368
+ report.count('comments', 'skipped');
369
+ if (post?.table === 'pages')
370
+ report.note('Comments on pages were skipped; only posts have comments here');
371
+ continue;
372
+ }
373
+ const isSpam = comment.status === 'spam';
374
+ const spamColumn = columns.has('status') ? 'status' : columns.has('spam') ? 'spam' : columns.has('is_spam') ? 'is_spam' : null;
375
+ if (isSpam && !spamColumn) {
376
+ report.count('comments', 'spam skipped');
377
+ continue;
378
+ }
379
+ const content = commentText(comment.html);
380
+ if (!content) {
381
+ report.count('comments', 'skipped');
382
+ continue;
383
+ }
384
+ const createdAt = toTimestamp(comment.createdAt) ?? new Date().toISOString();
385
+ const existing = await db.get('SELECT id FROM comments WHERE post_id = ? AND created_at = ? AND content = ?', [post.id, createdAt, content]);
386
+ if (existing) {
387
+ commentIds.set(comment.key, Number(existing.id));
388
+ report.count('comments', 'existing');
389
+ continue;
390
+ }
391
+ const row = {
392
+ post_id: post.id,
393
+ user_id: ids.authors.get(comment.userKey)?.id ?? null,
394
+ parent_id: commentIds.get(comment.parentKey) ?? null,
395
+ author_name: comment.authorName || null,
396
+ author_email: comment.authorEmail || null,
397
+ content,
398
+ approved: comment.status === 'approved' ? 1 : 0,
399
+ created_at: createdAt
400
+ };
401
+ if (spamColumn === 'status')
402
+ row.status = comment.status;
403
+ else if (spamColumn)
404
+ row[spamColumn] = isSpam ? 1 : 0;
405
+ const id = await insertRow(db, 'comments', row);
406
+ commentIds.set(comment.key, id);
407
+ log(`create comment on post ${post.id}${row.parent_id ? ` (reply to ${row.parent_id})` : ''}`);
408
+ report.count('comments', isSpam ? 'created as spam' : 'created');
409
+ }
410
+ }
411
+ function unique(values) {
412
+ return [...new Set(values)];
413
+ }
414
+ /**
415
+ * The command-line half every foreign-CMS importer shares: find the fallback
416
+ * author, run the import (rolled back if it is a dry run), print the report.
417
+ *
418
+ * @param {object} db
419
+ * @param {object} site
420
+ * @param {object} flags - parsed `--dry-run`, `--update`, `--verbose`, `--no-authors`, `--no-comments`, `--skip-media`
421
+ */
422
+ export async function runSiteImport(db, site, flags) {
423
+ const admin = await defaultAuthor(db);
424
+ if (!admin) {
425
+ console.error(NO_ADMIN_MESSAGE);
426
+ process.exit(1);
427
+ }
428
+ console.log(`Fallback author: ${admin.name} <${admin.email}>`);
429
+ if (flags['dry-run'])
430
+ console.log('Dry run — nothing will be written.');
431
+ if (flags.update)
432
+ console.log('Updating content that already exists.');
433
+ console.log('');
434
+ const report = new Report();
435
+ for (const note of site.notes ?? [])
436
+ report.note(note);
437
+ await withDryRun(db, flags['dry-run'], (tx) => importSite(tx, site, {
438
+ defaultAuthorId: admin.id,
439
+ update: flags.update,
440
+ authors: !flags['no-authors'],
441
+ comments: !flags['no-comments'],
442
+ media: !flags['skip-media'],
443
+ log: flags.verbose || flags['dry-run'] ? console.log : undefined,
444
+ report
445
+ }));
446
+ if (report.get('authors', 'created')) {
447
+ report.note('New authors were created with the "author" role and no usable password; they sign in with "forgot password"');
448
+ }
449
+ if (report.get('media', 'created')) {
450
+ report.note('Media rows record each file\'s existing path; files were not copied. Point storage (S3_PUBLIC_URL) at the host serving them, or move the files first');
451
+ }
452
+ console.log(`\n${report}`);
453
+ if (flags['dry-run'])
454
+ console.log('\nDry run complete. Nothing was written.');
455
+ return report;
456
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @param {object} data
3
+ * @param {object[]} data.posts - `/wp/v2/posts?_embed`
4
+ * @param {object[]} [data.pages] - `/wp/v2/pages?_embed`
5
+ * @param {object[]} [data.media] - `/wp/v2/media`
6
+ * @param {object[]} [data.comments] - `/wp/v2/comments`
7
+ * @param {object[]} [data.users] - `/wp/v2/users`
8
+ * @param {object[]} [data.categories] - `/wp/v2/categories`
9
+ */
10
+ export function mapRestSite(data: {
11
+ posts: object[];
12
+ pages?: object[] | undefined;
13
+ media?: object[] | undefined;
14
+ comments?: object[] | undefined;
15
+ users?: object[] | undefined;
16
+ categories?: object[] | undefined;
17
+ }): {
18
+ authors: never[];
19
+ categories: never[];
20
+ tags: never[];
21
+ media: never[];
22
+ posts: never[];
23
+ comments: never[];
24
+ notes: any[];
25
+ };
@@ -0,0 +1,177 @@
1
+ /**
2
+ * WordPress REST API responses → the importer's site shape.
3
+ *
4
+ * Kept apart from the fetching in `basicben-cms import:wordpress` so the
5
+ * mapping can be tested against recorded responses without a WordPress.
6
+ *
7
+ * The REST API returns *rendered* HTML (`content.rendered`), unlike a WXR
8
+ * file, so no `autop` is needed: this is what the site showed.
9
+ *
10
+ * Anonymous requests see only published content, approved comments and the
11
+ * public half of each author — no email address. With WORDPRESS_AUTH set
12
+ * (an application password) the script also asks for drafts, scheduled,
13
+ * pending and private posts, held and spam comments, and author addresses.
14
+ */
15
+ import { decodeEntities, plainText } from './html-to-markdown.mjs';
16
+ const STATUS = { publish: 'published', future: 'published', draft: 'draft', pending: 'pending', private: 'draft' };
17
+ const COMMENT_STATUS = { approved: 'approved', approve: 'approved', hold: 'pending', unapproved: 'pending', spam: 'spam' };
18
+ /** WordPress dates are local-with-no-zone; `date_gmt` is the one to trust. */
19
+ function gmt(item, field = 'date') {
20
+ const value = item[`${field}_gmt`];
21
+ return value ? `${value}Z` : item[field] ?? null;
22
+ }
23
+ /**
24
+ * @param {object} data
25
+ * @param {object[]} data.posts - `/wp/v2/posts?_embed`
26
+ * @param {object[]} [data.pages] - `/wp/v2/pages?_embed`
27
+ * @param {object[]} [data.media] - `/wp/v2/media`
28
+ * @param {object[]} [data.comments] - `/wp/v2/comments`
29
+ * @param {object[]} [data.users] - `/wp/v2/users`
30
+ * @param {object[]} [data.categories] - `/wp/v2/categories`
31
+ */
32
+ export function mapRestSite(data) {
33
+ const notes = [];
34
+ const site = { authors: [], categories: [], tags: [], media: [], posts: [], comments: [], notes };
35
+ for (const user of data.users ?? []) {
36
+ site.authors.push({
37
+ key: String(user.id),
38
+ name: decodeEntities(user.name ?? ''),
39
+ email: user.email || null,
40
+ slug: user.slug,
41
+ bio: decodeEntities(user.description ?? '') || null,
42
+ website: user.url || null
43
+ });
44
+ }
45
+ // Categories from their own endpoint carry parent and description, which
46
+ // the post embed does not; embedded terms fill in any it missed.
47
+ const categoryIds = new Map();
48
+ for (const term of data.categories ?? []) {
49
+ categoryIds.set(term.id, term.slug);
50
+ }
51
+ for (const term of data.categories ?? []) {
52
+ site.categories.push({
53
+ key: term.slug,
54
+ slug: term.slug,
55
+ name: decodeEntities(term.name ?? ''),
56
+ description: decodeEntities(term.description ?? '') || null,
57
+ parentKey: term.parent ? categoryIds.get(term.parent) ?? null : null
58
+ });
59
+ }
60
+ const seenCategories = new Set(site.categories.map((c) => c.key));
61
+ const seenTags = new Set();
62
+ for (const item of data.media ?? []) {
63
+ if (!item.source_url)
64
+ continue;
65
+ site.media.push({
66
+ key: `attachment:${item.id}`,
67
+ url: item.source_url,
68
+ alt: decodeEntities(item.alt_text || '') || null,
69
+ mimeType: item.mime_type || null,
70
+ // The media endpoint reports these; the featured-image embed does not.
71
+ size: Number(item.media_details?.filesize) || null,
72
+ width: Number(item.media_details?.width) || null,
73
+ height: Number(item.media_details?.height) || null,
74
+ createdAt: gmt(item)
75
+ });
76
+ }
77
+ const mediaKeys = new Set(site.media.map((m) => m.key));
78
+ const mapItem = (item, type) => {
79
+ const status = STATUS[item.status] ?? null;
80
+ if (!status)
81
+ return null;
82
+ if (item.status === 'private')
83
+ notes.push(`"${decodeEntities(item.title?.rendered ?? '')}" was private in WordPress and is imported as a draft`);
84
+ const terms = item._embedded?.['wp:term'] ?? [];
85
+ const categoryKeys = [];
86
+ const tagKeys = [];
87
+ for (const group of terms) {
88
+ for (const term of group ?? []) {
89
+ if (!term?.slug)
90
+ continue;
91
+ if (term.taxonomy === 'category') {
92
+ if (!seenCategories.has(term.slug)) {
93
+ seenCategories.add(term.slug);
94
+ site.categories.push({ key: term.slug, slug: term.slug, name: decodeEntities(term.name ?? ''), description: null, parentKey: null });
95
+ }
96
+ categoryKeys.push(term.slug);
97
+ }
98
+ else if (term.taxonomy === 'post_tag') {
99
+ if (!seenTags.has(term.slug)) {
100
+ seenTags.add(term.slug);
101
+ site.tags.push({ key: term.slug, slug: term.slug, name: decodeEntities(term.name ?? '') });
102
+ }
103
+ tagKeys.push(term.slug);
104
+ }
105
+ }
106
+ }
107
+ // The featured image: the library's row when the library was fetched,
108
+ // otherwise the embed's URL, which makes a sparser row.
109
+ const featured = item._embedded?.['wp:featuredmedia']?.[0];
110
+ const featuredKey = item.featured_media ? `attachment:${item.featured_media}` : null;
111
+ const featuredImage = featuredKey && mediaKeys.has(featuredKey)
112
+ ? featuredKey
113
+ : featured?.source_url && !featured.code ? featured.source_url : null;
114
+ const yoast = item.yoast_head_json ?? {};
115
+ const date = gmt(item);
116
+ return {
117
+ key: `${type}:${item.id}`,
118
+ type,
119
+ title: decodeEntities(item.title?.rendered ?? ''),
120
+ slug: decodeURIComponent(item.slug ?? ''),
121
+ html: item.content?.rendered ?? '',
122
+ excerpt: type === 'post' ? plainText(item.excerpt?.rendered) || null : null,
123
+ status,
124
+ publishAt: status === 'published' ? date : null,
125
+ createdAt: date,
126
+ updatedAt: gmt(item, 'modified') || date,
127
+ authorKey: item.author ? String(item.author) : null,
128
+ categoryKeys,
129
+ tagKeys,
130
+ featuredImage,
131
+ parentKey: type === 'page' && item.parent ? `page:${item.parent}` : null,
132
+ menuOrder: item.menu_order ?? 0,
133
+ template: item.template ? item.template.split('/').pop().replace(/\.php$/, '') : 'default',
134
+ seo: {
135
+ // Yoast's head data is fully resolved (no %%templates%%), so it is
136
+ // usable as-is — but its title is usually just "Post — Site", which
137
+ // the CMS produces by itself, so only a distinct one is kept.
138
+ meta_title: yoast.title && yoast.title !== yoast.og_title ? decodeEntities(yoast.title) : null,
139
+ meta_description: yoast.description ? decodeEntities(yoast.description) : null,
140
+ canonical_url: yoast.canonical && yoast.canonical !== item.link ? yoast.canonical : null,
141
+ og_title: null,
142
+ og_description: null,
143
+ og_image: null,
144
+ twitter_title: null,
145
+ twitter_description: null,
146
+ twitter_image: null,
147
+ noindex: yoast.robots?.index === 'noindex'
148
+ }
149
+ };
150
+ };
151
+ for (const item of data.posts ?? []) {
152
+ const mapped = mapItem(item, 'post');
153
+ if (mapped)
154
+ site.posts.push(mapped);
155
+ }
156
+ for (const item of data.pages ?? []) {
157
+ const mapped = mapItem(item, 'page');
158
+ if (mapped)
159
+ site.posts.push(mapped);
160
+ }
161
+ for (const comment of data.comments ?? []) {
162
+ if (comment.type && comment.type !== 'comment')
163
+ continue; // pingbacks, trackbacks
164
+ site.comments.push({
165
+ key: String(comment.id),
166
+ postKey: `post:${comment.post}`,
167
+ parentKey: comment.parent ? String(comment.parent) : null,
168
+ authorName: decodeEntities(comment.author_name ?? '') || null,
169
+ authorEmail: comment.author_email || null,
170
+ userKey: comment.author ? String(comment.author) : null,
171
+ html: comment.content?.rendered ?? '',
172
+ status: COMMENT_STATUS[comment.status] ?? 'pending',
173
+ createdAt: gmt(comment)
174
+ });
175
+ }
176
+ return site;
177
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @param {string} xml - the WXR file's contents
3
+ * @returns {object} the site shape `importSite` takes, plus `meta` and `notes`
4
+ */
5
+ export function parseWxr(xml: string): object;
6
+ /**
7
+ * Width, height and size out of `_wp_attachment_metadata`.
8
+ *
9
+ * That value is PHP's `serialize()` format. Unserializing PHP is a known way
10
+ * to get into trouble, and only three integers are wanted, so they are read
11
+ * with a pattern instead: the top-level `width` comes first, before the
12
+ * `sizes` array repeats the key for every thumbnail.
13
+ */
14
+ export function attachmentDimensions(serialized: any): {
15
+ width: number | null;
16
+ height: number | null;
17
+ filesize: number | null;
18
+ };