@basicbenframework/cms 0.0.0-stage → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (590) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +206 -2
  3. package/db/migrations/001_create_users.js +15 -0
  4. package/db/migrations/002_create_posts.js +18 -0
  5. package/db/migrations/003_create_categories.js +19 -0
  6. package/db/migrations/004_create_tags.js +16 -0
  7. package/db/migrations/005_create_post_tags.js +16 -0
  8. package/db/migrations/006_create_pages.js +26 -0
  9. package/db/migrations/007_create_comments.js +24 -0
  10. package/db/migrations/008_create_media.js +22 -0
  11. package/db/migrations/009_update_posts_blogging.js +27 -0
  12. package/db/migrations/010_create_settings.js +29 -0
  13. package/db/migrations/011_add_user_roles.js +23 -0
  14. package/db/migrations/012_create_auth_tokens.js +30 -0
  15. package/db/migrations/013_add_email_verified.js +24 -0
  16. package/db/migrations/014_create_user_two_factor.js +30 -0
  17. package/db/migrations/015_create_user_credentials.js +35 -0
  18. package/db/migrations/016_create_rate_limits.js +31 -0
  19. package/db/migrations/017_add_content_html.js +38 -0
  20. package/db/migrations/018_create_api_tokens.js +34 -0
  21. package/db/migrations/019_create_post_categories.js +40 -0
  22. package/db/migrations/020_add_author_profiles.js +60 -0
  23. package/db/migrations/021_add_page_featured_image.js +23 -0
  24. package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
  25. package/db/migrations/023_add_user_session_controls.js +25 -0
  26. package/db/migrations/024_add_post_status_and_trash.js +45 -0
  27. package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
  28. package/db/migrations/026_create_post_revisions.js +29 -0
  29. package/db/migrations/027_add_media_dimensions.js +19 -0
  30. package/db/migrations/028_create_navigation_menus.js +65 -0
  31. package/db/migrations/029_create_redirects.js +40 -0
  32. package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
  33. package/db/migrations/031_create_post_locks.js +38 -0
  34. package/db/migrations/032_create_snippets.js +31 -0
  35. package/db/migrations/033_create_members.js +70 -0
  36. package/db/migrations/034_add_post_visibility.js +28 -0
  37. package/db/migrations/035_create_newsletters.js +72 -0
  38. package/db/migrations/036_create_analytics.js +89 -0
  39. package/db/migrations/037_create_ops_heartbeats.js +30 -0
  40. package/db/migrations/038_create_content_types.js +84 -0
  41. package/db/migrations/039_create_content_type_fields.js +47 -0
  42. package/db/migrations/040_create_taxonomies.js +80 -0
  43. package/db/migrations/041_add_newsletter_handoff.js +28 -0
  44. package/db/migrations/042_create_mysendbox_contacts.js +63 -0
  45. package/lib/cli/backup.d.mts +2 -0
  46. package/lib/cli/backup.mjs +124 -0
  47. package/lib/cli/export.d.mts +2 -0
  48. package/lib/cli/export.mjs +54 -0
  49. package/lib/cli/import-ghost.d.mts +2 -0
  50. package/lib/cli/import-ghost.mjs +50 -0
  51. package/lib/cli/import-json.d.mts +2 -0
  52. package/lib/cli/import-json.mjs +61 -0
  53. package/lib/cli/import-wordpress.d.mts +2 -0
  54. package/lib/cli/import-wordpress.mjs +169 -0
  55. package/lib/cli/import-wxr.d.mts +2 -0
  56. package/lib/cli/import-wxr.mjs +55 -0
  57. package/lib/cli/index.d.mts +2 -0
  58. package/lib/cli/index.mjs +53 -0
  59. package/lib/cli/lib/backup.d.mts +112 -0
  60. package/lib/cli/lib/backup.mjs +297 -0
  61. package/lib/cli/lib/ghost.d.mts +30 -0
  62. package/lib/cli/lib/ghost.mjs +201 -0
  63. package/lib/cli/lib/html-to-markdown.d.mts +61 -0
  64. package/lib/cli/lib/html-to-markdown.mjs +523 -0
  65. package/lib/cli/lib/import-common.d.mts +100 -0
  66. package/lib/cli/lib/import-common.mjs +252 -0
  67. package/lib/cli/lib/json-import.d.mts +22 -0
  68. package/lib/cli/lib/json-import.mjs +422 -0
  69. package/lib/cli/lib/site-import.d.mts +32 -0
  70. package/lib/cli/lib/site-import.mjs +456 -0
  71. package/lib/cli/lib/wordpress-rest.d.mts +25 -0
  72. package/lib/cli/lib/wordpress-rest.mjs +177 -0
  73. package/lib/cli/lib/wxr.d.mts +18 -0
  74. package/lib/cli/lib/wxr.mjs +307 -0
  75. package/lib/cli/lib/xml.d.mts +33 -0
  76. package/lib/cli/lib/xml.mjs +186 -0
  77. package/lib/cli/restore.d.mts +2 -0
  78. package/lib/cli/restore.mjs +98 -0
  79. package/lib/client/components/Alert.d.ts +7 -0
  80. package/lib/client/components/Alert.js +8 -0
  81. package/lib/client/components/Avatar.d.ts +15 -0
  82. package/lib/client/components/Avatar.js +10 -0
  83. package/lib/client/components/BackLink.d.ts +7 -0
  84. package/lib/client/components/BackLink.js +6 -0
  85. package/lib/client/components/Button.d.ts +7 -0
  86. package/lib/client/components/Button.js +12 -0
  87. package/lib/client/components/Card.d.ts +7 -0
  88. package/lib/client/components/Card.js +6 -0
  89. package/lib/client/components/CommentThread.d.ts +15 -0
  90. package/lib/client/components/CommentThread.js +101 -0
  91. package/lib/client/components/Empty.d.ts +6 -0
  92. package/lib/client/components/Empty.js +6 -0
  93. package/lib/client/components/Input.d.ts +6 -0
  94. package/lib/client/components/Input.js +6 -0
  95. package/lib/client/components/Link.d.ts +31 -0
  96. package/lib/client/components/Link.js +49 -0
  97. package/lib/client/components/Loading.d.ts +1 -0
  98. package/lib/client/components/Loading.js +6 -0
  99. package/lib/client/components/Logo.d.ts +5 -0
  100. package/lib/client/components/Logo.js +4 -0
  101. package/lib/client/components/MarkdownEditor.d.ts +41 -0
  102. package/lib/client/components/MarkdownEditor.js +156 -0
  103. package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
  104. package/lib/client/components/Nav/DarkModeToggle.js +6 -0
  105. package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
  106. package/lib/client/components/Nav/DesktopNav.js +9 -0
  107. package/lib/client/components/Nav/MobileNav.d.ts +9 -0
  108. package/lib/client/components/Nav/MobileNav.js +15 -0
  109. package/lib/client/components/NavLink.d.ts +8 -0
  110. package/lib/client/components/NavLink.js +6 -0
  111. package/lib/client/components/PageHeader.d.ts +8 -0
  112. package/lib/client/components/PageHeader.js +6 -0
  113. package/lib/client/components/PostCard.d.ts +8 -0
  114. package/lib/client/components/PostCard.js +7 -0
  115. package/lib/client/components/Textarea.d.ts +6 -0
  116. package/lib/client/components/Textarea.js +6 -0
  117. package/lib/client/components/ThemeContext.d.ts +18 -0
  118. package/lib/client/components/ThemeContext.js +8 -0
  119. package/lib/client/components/admin/AdminIcons.d.ts +13 -0
  120. package/lib/client/components/admin/AdminIcons.js +66 -0
  121. package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
  122. package/lib/client/components/admin/ContentModelPanels.js +93 -0
  123. package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
  124. package/lib/client/components/admin/FeaturedImageBox.js +24 -0
  125. package/lib/client/components/admin/MediaGrid.d.ts +23 -0
  126. package/lib/client/components/admin/MediaGrid.js +69 -0
  127. package/lib/client/components/admin/MediaPicker.d.ts +17 -0
  128. package/lib/client/components/admin/MediaPicker.js +61 -0
  129. package/lib/client/components/admin/Pagination.d.ts +27 -0
  130. package/lib/client/components/admin/Pagination.js +29 -0
  131. package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
  132. package/lib/client/components/admin/SnippetPicker.js +65 -0
  133. package/lib/client/components/admin/TermPicker.d.ts +52 -0
  134. package/lib/client/components/admin/TermPicker.js +58 -0
  135. package/lib/client/contexts/ToastContext.d.ts +12 -0
  136. package/lib/client/contexts/ToastContext.js +49 -0
  137. package/lib/client/features.d.ts +11 -0
  138. package/lib/client/features.js +7 -0
  139. package/lib/client/hooks/useContentTypes.d.ts +48 -0
  140. package/lib/client/hooks/useContentTypes.js +48 -0
  141. package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
  142. package/lib/client/hooks/useMediaLibrary.js +189 -0
  143. package/lib/client/hooks/usePostLock.d.ts +32 -0
  144. package/lib/client/hooks/usePostLock.js +107 -0
  145. package/lib/client/host/index.d.ts +71 -0
  146. package/lib/client/host/index.js +58 -0
  147. package/lib/client/i18n/index.d.ts +79 -0
  148. package/lib/client/i18n/index.js +177 -0
  149. package/lib/client/i18n/locales/es/content.d.ts +4 -0
  150. package/lib/client/i18n/locales/es/content.js +220 -0
  151. package/lib/client/i18n/locales/es/editor.d.ts +9 -0
  152. package/lib/client/i18n/locales/es/editor.js +144 -0
  153. package/lib/client/i18n/locales/es/index.d.ts +8 -0
  154. package/lib/client/i18n/locales/es/index.js +7 -0
  155. package/lib/client/i18n/locales/es/layout.d.ts +4 -0
  156. package/lib/client/i18n/locales/es/layout.js +35 -0
  157. package/lib/client/i18n/locales/es/people.d.ts +4 -0
  158. package/lib/client/i18n/locales/es/people.js +187 -0
  159. package/lib/client/i18n/locales/es/site.d.ts +4 -0
  160. package/lib/client/i18n/locales/es/site.js +208 -0
  161. package/lib/client/layouts/AdminLayout.d.ts +7 -0
  162. package/lib/client/layouts/AdminLayout.js +1046 -0
  163. package/lib/client/layouts/AppLayout.d.ts +6 -0
  164. package/lib/client/layouts/AppLayout.js +19 -0
  165. package/lib/client/layouts/AuthLayout.d.ts +6 -0
  166. package/lib/client/layouts/AuthLayout.js +14 -0
  167. package/lib/client/layouts/DocsLayout.d.ts +6 -0
  168. package/lib/client/layouts/DocsLayout.js +28 -0
  169. package/lib/client/layouts/RootLayout.d.ts +6 -0
  170. package/lib/client/layouts/RootLayout.js +11 -0
  171. package/lib/client/pages/AcceptInvite.d.ts +8 -0
  172. package/lib/client/pages/AcceptInvite.js +60 -0
  173. package/lib/client/pages/Auth.d.ts +1 -0
  174. package/lib/client/pages/Auth.js +40 -0
  175. package/lib/client/pages/Authentication.d.ts +1 -0
  176. package/lib/client/pages/Authentication.js +230 -0
  177. package/lib/client/pages/Content.d.ts +1 -0
  178. package/lib/client/pages/Content.js +21 -0
  179. package/lib/client/pages/Database.d.ts +1 -0
  180. package/lib/client/pages/Database.js +264 -0
  181. package/lib/client/pages/Extending.d.ts +1 -0
  182. package/lib/client/pages/Extending.js +28 -0
  183. package/lib/client/pages/Feed.d.ts +1 -0
  184. package/lib/client/pages/Feed.js +19 -0
  185. package/lib/client/pages/FeedPost.d.ts +1 -0
  186. package/lib/client/pages/FeedPost.js +31 -0
  187. package/lib/client/pages/ForgotPassword.d.ts +8 -0
  188. package/lib/client/pages/ForgotPassword.js +38 -0
  189. package/lib/client/pages/GettingStarted.d.ts +1 -0
  190. package/lib/client/pages/GettingStarted.js +84 -0
  191. package/lib/client/pages/Headless.d.ts +1 -0
  192. package/lib/client/pages/Headless.js +49 -0
  193. package/lib/client/pages/Home.d.ts +1 -0
  194. package/lib/client/pages/Home.js +67 -0
  195. package/lib/client/pages/PostForm.d.ts +1 -0
  196. package/lib/client/pages/PostForm.js +55 -0
  197. package/lib/client/pages/Posts.d.ts +1 -0
  198. package/lib/client/pages/Posts.js +35 -0
  199. package/lib/client/pages/Profile.d.ts +1 -0
  200. package/lib/client/pages/Profile.js +153 -0
  201. package/lib/client/pages/ResetPassword.d.ts +8 -0
  202. package/lib/client/pages/ResetPassword.js +52 -0
  203. package/lib/client/pages/Routing.d.ts +1 -0
  204. package/lib/client/pages/Routing.js +192 -0
  205. package/lib/client/pages/Storage.d.ts +1 -0
  206. package/lib/client/pages/Storage.js +54 -0
  207. package/lib/client/pages/Testing.d.ts +1 -0
  208. package/lib/client/pages/Testing.js +141 -0
  209. package/lib/client/pages/Validation.d.ts +1 -0
  210. package/lib/client/pages/Validation.js +123 -0
  211. package/lib/client/pages/admin/Categories.d.ts +2 -0
  212. package/lib/client/pages/admin/Categories.js +75 -0
  213. package/lib/client/pages/admin/Comments.d.ts +11 -0
  214. package/lib/client/pages/admin/Comments.js +247 -0
  215. package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
  216. package/lib/client/pages/admin/ContentTypes.js +163 -0
  217. package/lib/client/pages/admin/Dashboard.d.ts +2 -0
  218. package/lib/client/pages/admin/Dashboard.js +66 -0
  219. package/lib/client/pages/admin/Health.d.ts +12 -0
  220. package/lib/client/pages/admin/Health.js +148 -0
  221. package/lib/client/pages/admin/Media.d.ts +2 -0
  222. package/lib/client/pages/admin/Media.js +101 -0
  223. package/lib/client/pages/admin/Navigation.d.ts +9 -0
  224. package/lib/client/pages/admin/Navigation.js +230 -0
  225. package/lib/client/pages/admin/Pages.d.ts +2 -0
  226. package/lib/client/pages/admin/Pages.js +53 -0
  227. package/lib/client/pages/admin/PostEditor.d.ts +17 -0
  228. package/lib/client/pages/admin/PostEditor.js +532 -0
  229. package/lib/client/pages/admin/Posts.d.ts +2 -0
  230. package/lib/client/pages/admin/Posts.js +152 -0
  231. package/lib/client/pages/admin/Redirects.d.ts +10 -0
  232. package/lib/client/pages/admin/Redirects.js +87 -0
  233. package/lib/client/pages/admin/Settings.d.ts +2 -0
  234. package/lib/client/pages/admin/Settings.js +111 -0
  235. package/lib/client/pages/admin/Snippets.d.ts +14 -0
  236. package/lib/client/pages/admin/Snippets.js +85 -0
  237. package/lib/client/pages/admin/Tags.d.ts +2 -0
  238. package/lib/client/pages/admin/Tags.js +74 -0
  239. package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
  240. package/lib/client/pages/admin/Taxonomies.js +130 -0
  241. package/lib/client/pages/admin/Tokens.d.ts +9 -0
  242. package/lib/client/pages/admin/Tokens.js +260 -0
  243. package/lib/client/pages/admin/Tools.d.ts +12 -0
  244. package/lib/client/pages/admin/Tools.js +111 -0
  245. package/lib/client/pages/admin/Users.d.ts +13 -0
  246. package/lib/client/pages/admin/Users.js +313 -0
  247. package/lib/client/pages/api-reference.d.ts +33 -0
  248. package/lib/client/pages/api-reference.js +198 -0
  249. package/lib/client/styles.css +37 -0
  250. package/lib/config.d.ts +24 -0
  251. package/lib/config.js +39 -0
  252. package/lib/controllers/AdminController.d.ts +46 -0
  253. package/lib/controllers/AdminController.js +134 -0
  254. package/lib/controllers/AuthController.d.ts +15 -0
  255. package/lib/controllers/AuthController.js +194 -0
  256. package/lib/controllers/AuthorController.d.ts +17 -0
  257. package/lib/controllers/AuthorController.js +19 -0
  258. package/lib/controllers/CategoryController.d.ts +10 -0
  259. package/lib/controllers/CategoryController.js +88 -0
  260. package/lib/controllers/CommentController.d.ts +68 -0
  261. package/lib/controllers/CommentController.js +438 -0
  262. package/lib/controllers/ContentTypeController.d.ts +24 -0
  263. package/lib/controllers/ContentTypeController.js +91 -0
  264. package/lib/controllers/EmailVerificationController.d.ts +33 -0
  265. package/lib/controllers/EmailVerificationController.js +116 -0
  266. package/lib/controllers/ExportController.d.ts +15 -0
  267. package/lib/controllers/ExportController.js +41 -0
  268. package/lib/controllers/FeedController.d.ts +14 -0
  269. package/lib/controllers/FeedController.js +246 -0
  270. package/lib/controllers/HealthController.d.ts +21 -0
  271. package/lib/controllers/HealthController.js +176 -0
  272. package/lib/controllers/HomeController.d.ts +12 -0
  273. package/lib/controllers/HomeController.js +16 -0
  274. package/lib/controllers/MediaController.d.ts +24 -0
  275. package/lib/controllers/MediaController.js +189 -0
  276. package/lib/controllers/NavigationController.d.ts +22 -0
  277. package/lib/controllers/NavigationController.js +176 -0
  278. package/lib/controllers/PageController.d.ts +13 -0
  279. package/lib/controllers/PageController.js +172 -0
  280. package/lib/controllers/PasskeyController.d.ts +36 -0
  281. package/lib/controllers/PasskeyController.js +201 -0
  282. package/lib/controllers/PasswordResetController.d.ts +44 -0
  283. package/lib/controllers/PasswordResetController.js +160 -0
  284. package/lib/controllers/PostController.d.ts +51 -0
  285. package/lib/controllers/PostController.js +538 -0
  286. package/lib/controllers/PostLockController.d.ts +62 -0
  287. package/lib/controllers/PostLockController.js +101 -0
  288. package/lib/controllers/ProfileController.d.ts +13 -0
  289. package/lib/controllers/ProfileController.js +160 -0
  290. package/lib/controllers/PublicApiController.d.ts +23 -0
  291. package/lib/controllers/PublicApiController.js +100 -0
  292. package/lib/controllers/RedirectController.d.ts +32 -0
  293. package/lib/controllers/RedirectController.js +95 -0
  294. package/lib/controllers/SettingsController.d.ts +28 -0
  295. package/lib/controllers/SettingsController.js +105 -0
  296. package/lib/controllers/SnippetController.d.ts +27 -0
  297. package/lib/controllers/SnippetController.js +123 -0
  298. package/lib/controllers/TagController.d.ts +9 -0
  299. package/lib/controllers/TagController.js +70 -0
  300. package/lib/controllers/TaxonomyController.d.ts +24 -0
  301. package/lib/controllers/TaxonomyController.js +149 -0
  302. package/lib/controllers/TokenController.d.ts +27 -0
  303. package/lib/controllers/TokenController.js +83 -0
  304. package/lib/controllers/TwoFactorController.d.ts +31 -0
  305. package/lib/controllers/TwoFactorController.js +213 -0
  306. package/lib/controllers/UserController.d.ts +110 -0
  307. package/lib/controllers/UserController.js +504 -0
  308. package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
  309. package/lib/features/analytics/AnalyticsPage.js +123 -0
  310. package/lib/features/analytics/admin.d.ts +3 -0
  311. package/lib/features/analytics/admin.js +9 -0
  312. package/lib/features/analytics/controller.d.ts +19 -0
  313. package/lib/features/analytics/controller.js +79 -0
  314. package/lib/features/analytics/helpers.d.ts +84 -0
  315. package/lib/features/analytics/helpers.js +181 -0
  316. package/lib/features/analytics/i18n/es.d.ts +4 -0
  317. package/lib/features/analytics/i18n/es.js +31 -0
  318. package/lib/features/analytics/index.d.ts +28 -0
  319. package/lib/features/analytics/index.js +91 -0
  320. package/lib/features/analytics/manifest.d.ts +8 -0
  321. package/lib/features/analytics/manifest.js +18 -0
  322. package/lib/features/analytics/model.d.ts +130 -0
  323. package/lib/features/analytics/model.js +206 -0
  324. package/lib/features/members/Member.d.ts +93 -0
  325. package/lib/features/members/Member.js +194 -0
  326. package/lib/features/members/MemberAdminController.d.ts +60 -0
  327. package/lib/features/members/MemberAdminController.js +262 -0
  328. package/lib/features/members/MemberController.d.ts +88 -0
  329. package/lib/features/members/MemberController.js +250 -0
  330. package/lib/features/members/MembersPage.d.ts +10 -0
  331. package/lib/features/members/MembersPage.js +216 -0
  332. package/lib/features/members/PostAccessBox.d.ts +15 -0
  333. package/lib/features/members/PostAccessBox.js +70 -0
  334. package/lib/features/members/admin.d.ts +3 -0
  335. package/lib/features/members/admin.js +12 -0
  336. package/lib/features/members/csv.d.ts +21 -0
  337. package/lib/features/members/csv.js +74 -0
  338. package/lib/features/members/events.d.ts +34 -0
  339. package/lib/features/members/events.js +34 -0
  340. package/lib/features/members/i18n/es.d.ts +4 -0
  341. package/lib/features/members/i18n/es.js +106 -0
  342. package/lib/features/members/index.d.ts +44 -0
  343. package/lib/features/members/index.js +106 -0
  344. package/lib/features/members/manifest.d.ts +8 -0
  345. package/lib/features/members/manifest.js +18 -0
  346. package/lib/features/members/middleware.d.ts +42 -0
  347. package/lib/features/members/middleware.js +74 -0
  348. package/lib/features/members/newsletter.d.ts +177 -0
  349. package/lib/features/members/newsletter.js +439 -0
  350. package/lib/features/members/rate-limits.d.ts +34 -0
  351. package/lib/features/members/rate-limits.js +50 -0
  352. package/lib/features/members/request.d.ts +13 -0
  353. package/lib/features/members/request.js +6 -0
  354. package/lib/features/members/routes.d.ts +15 -0
  355. package/lib/features/members/routes.js +59 -0
  356. package/lib/features/members/session.d.ts +102 -0
  357. package/lib/features/members/session.js +158 -0
  358. package/lib/features/members/settings.d.ts +14 -0
  359. package/lib/features/members/settings.js +23 -0
  360. package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
  361. package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
  362. package/lib/features/mysendbox/admin.d.ts +3 -0
  363. package/lib/features/mysendbox/admin.js +9 -0
  364. package/lib/features/mysendbox/broadcasts.d.ts +61 -0
  365. package/lib/features/mysendbox/broadcasts.js +124 -0
  366. package/lib/features/mysendbox/client.d.ts +95 -0
  367. package/lib/features/mysendbox/client.js +61 -0
  368. package/lib/features/mysendbox/config.d.ts +27 -0
  369. package/lib/features/mysendbox/config.js +74 -0
  370. package/lib/features/mysendbox/contacts.d.ts +121 -0
  371. package/lib/features/mysendbox/contacts.js +378 -0
  372. package/lib/features/mysendbox/controller.d.ts +11 -0
  373. package/lib/features/mysendbox/controller.js +47 -0
  374. package/lib/features/mysendbox/i18n/es.d.ts +4 -0
  375. package/lib/features/mysendbox/i18n/es.js +28 -0
  376. package/lib/features/mysendbox/index.d.ts +18 -0
  377. package/lib/features/mysendbox/index.js +71 -0
  378. package/lib/features/mysendbox/manifest.d.ts +7 -0
  379. package/lib/features/mysendbox/manifest.js +6 -0
  380. package/lib/features/mysendbox/routes.d.ts +6 -0
  381. package/lib/features/mysendbox/routes.js +14 -0
  382. package/lib/features/mysendbox/webhook.d.ts +23 -0
  383. package/lib/features/mysendbox/webhook.js +104 -0
  384. package/lib/features/theme/OEmbedController.d.ts +31 -0
  385. package/lib/features/theme/OEmbedController.js +128 -0
  386. package/lib/features/theme/ThemeController.d.ts +20 -0
  387. package/lib/features/theme/ThemeController.js +256 -0
  388. package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
  389. package/lib/features/theme/ThemeSettingsCard.js +12 -0
  390. package/lib/features/theme/admin.d.ts +3 -0
  391. package/lib/features/theme/admin.js +9 -0
  392. package/lib/features/theme/html.d.ts +48 -0
  393. package/lib/features/theme/html.js +97 -0
  394. package/lib/features/theme/i18n/es.d.ts +4 -0
  395. package/lib/features/theme/i18n/es.js +9 -0
  396. package/lib/features/theme/index.d.ts +11 -0
  397. package/lib/features/theme/index.js +23 -0
  398. package/lib/features/theme/manifest.d.ts +7 -0
  399. package/lib/features/theme/manifest.js +6 -0
  400. package/lib/features/theme/oembed.d.ts +36 -0
  401. package/lib/features/theme/oembed.js +58 -0
  402. package/lib/features/theme/routes.d.ts +17 -0
  403. package/lib/features/theme/routes.js +54 -0
  404. package/lib/features/theme/templates.d.ts +103 -0
  405. package/lib/features/theme/templates.js +283 -0
  406. package/lib/features.d.ts +15 -0
  407. package/lib/features.js +6 -0
  408. package/lib/features.manifest.d.ts +10 -0
  409. package/lib/features.manifest.js +6 -0
  410. package/lib/helpers/access.d.ts +62 -0
  411. package/lib/helpers/access.js +92 -0
  412. package/lib/helpers/api.d.ts +20 -0
  413. package/lib/helpers/api.js +44 -0
  414. package/lib/helpers/comment-guard.d.ts +145 -0
  415. package/lib/helpers/comment-guard.js +253 -0
  416. package/lib/helpers/comment-mail.d.ts +53 -0
  417. package/lib/helpers/comment-mail.js +188 -0
  418. package/lib/helpers/content-model.d.ts +50 -0
  419. package/lib/helpers/content-model.js +84 -0
  420. package/lib/helpers/content-paths.d.ts +107 -0
  421. package/lib/helpers/content-paths.js +200 -0
  422. package/lib/helpers/export-data.d.ts +85 -0
  423. package/lib/helpers/export-data.js +229 -0
  424. package/lib/helpers/gating.d.ts +53 -0
  425. package/lib/helpers/gating.js +83 -0
  426. package/lib/helpers/health.d.ts +91 -0
  427. package/lib/helpers/health.js +279 -0
  428. package/lib/helpers/heartbeat.d.ts +35 -0
  429. package/lib/helpers/heartbeat.js +55 -0
  430. package/lib/helpers/image-size.d.ts +18 -0
  431. package/lib/helpers/image-size.js +83 -0
  432. package/lib/helpers/images.d.ts +29 -0
  433. package/lib/helpers/images.js +41 -0
  434. package/lib/helpers/mail-templates.d.ts +11 -0
  435. package/lib/helpers/mail-templates.js +42 -0
  436. package/lib/helpers/publish-due.d.ts +28 -0
  437. package/lib/helpers/publish-due.js +67 -0
  438. package/lib/helpers/redirects.d.ts +43 -0
  439. package/lib/helpers/redirects.js +80 -0
  440. package/lib/helpers/seo-fields.d.ts +13 -0
  441. package/lib/helpers/seo-fields.js +52 -0
  442. package/lib/helpers/session.d.ts +30 -0
  443. package/lib/helpers/session.js +27 -0
  444. package/lib/helpers/site-settings.d.ts +98 -0
  445. package/lib/helpers/site-settings.js +232 -0
  446. package/lib/helpers/site.d.ts +14 -0
  447. package/lib/helpers/site.js +23 -0
  448. package/lib/helpers/write-hooks.d.ts +33 -0
  449. package/lib/helpers/write-hooks.js +37 -0
  450. package/lib/hooks.d.ts +17 -0
  451. package/lib/hooks.js +101 -0
  452. package/lib/host/core-tasks.d.ts +4 -0
  453. package/lib/host/core-tasks.js +26 -0
  454. package/lib/host/cron.d.ts +39 -0
  455. package/lib/host/cron.js +85 -0
  456. package/lib/host/enabled.d.ts +4 -0
  457. package/lib/host/enabled.js +40 -0
  458. package/lib/host/index.d.ts +81 -0
  459. package/lib/host/index.js +87 -0
  460. package/lib/host/manifest.d.ts +34 -0
  461. package/lib/host/manifest.js +7 -0
  462. package/lib/host/menu.d.ts +18 -0
  463. package/lib/host/menu.js +15 -0
  464. package/lib/main.d.ts +1 -0
  465. package/lib/main.js +24 -0
  466. package/lib/middleware/api-auth.d.ts +59 -0
  467. package/lib/middleware/api-auth.js +164 -0
  468. package/lib/middleware/auth.d.ts +49 -0
  469. package/lib/middleware/auth.js +112 -0
  470. package/lib/middleware/cache.d.ts +17 -0
  471. package/lib/middleware/cache.js +52 -0
  472. package/lib/middleware/rate-limits.d.ts +199 -0
  473. package/lib/middleware/rate-limits.js +276 -0
  474. package/lib/middleware/viewer.d.ts +13 -0
  475. package/lib/middleware/viewer.js +16 -0
  476. package/lib/models/Category.d.ts +24 -0
  477. package/lib/models/Category.js +102 -0
  478. package/lib/models/Comment.d.ts +120 -0
  479. package/lib/models/Comment.js +283 -0
  480. package/lib/models/ContentType.d.ts +142 -0
  481. package/lib/models/ContentType.js +462 -0
  482. package/lib/models/Credential.d.ts +21 -0
  483. package/lib/models/Credential.js +31 -0
  484. package/lib/models/Media.d.ts +53 -0
  485. package/lib/models/Media.js +132 -0
  486. package/lib/models/Menu.d.ts +131 -0
  487. package/lib/models/Menu.js +312 -0
  488. package/lib/models/Page.d.ts +55 -0
  489. package/lib/models/Page.js +218 -0
  490. package/lib/models/Post.d.ts +136 -0
  491. package/lib/models/Post.js +406 -0
  492. package/lib/models/PostLock.d.ts +67 -0
  493. package/lib/models/PostLock.js +112 -0
  494. package/lib/models/PostRevision.d.ts +45 -0
  495. package/lib/models/PostRevision.js +82 -0
  496. package/lib/models/PublicContent.d.ts +283 -0
  497. package/lib/models/PublicContent.js +577 -0
  498. package/lib/models/Redirect.d.ts +123 -0
  499. package/lib/models/Redirect.js +225 -0
  500. package/lib/models/Settings.d.ts +61 -0
  501. package/lib/models/Settings.js +128 -0
  502. package/lib/models/Snippet.d.ts +36 -0
  503. package/lib/models/Snippet.js +64 -0
  504. package/lib/models/Tag.d.ts +23 -0
  505. package/lib/models/Tag.js +117 -0
  506. package/lib/models/Taxonomy.d.ts +127 -0
  507. package/lib/models/Taxonomy.js +321 -0
  508. package/lib/models/TwoFactor.d.ts +26 -0
  509. package/lib/models/TwoFactor.js +60 -0
  510. package/lib/models/User.d.ts +49 -0
  511. package/lib/models/User.js +128 -0
  512. package/lib/models/derive.d.ts +69 -0
  513. package/lib/models/derive.js +81 -0
  514. package/lib/models/pagination.d.ts +30 -0
  515. package/lib/models/pagination.js +36 -0
  516. package/lib/models/visibility.d.ts +31 -0
  517. package/lib/models/visibility.js +47 -0
  518. package/lib/routes/App.d.ts +2 -0
  519. package/lib/routes/App.js +146 -0
  520. package/lib/routes/api/admin.d.ts +6 -0
  521. package/lib/routes/api/admin.js +11 -0
  522. package/lib/routes/api/auth.d.ts +6 -0
  523. package/lib/routes/api/auth.js +24 -0
  524. package/lib/routes/api/authors.d.ts +5 -0
  525. package/lib/routes/api/authors.js +8 -0
  526. package/lib/routes/api/categories.d.ts +8 -0
  527. package/lib/routes/api/categories.js +15 -0
  528. package/lib/routes/api/comments.d.ts +8 -0
  529. package/lib/routes/api/comments.js +35 -0
  530. package/lib/routes/api/content-model.d.ts +17 -0
  531. package/lib/routes/api/content-model.js +67 -0
  532. package/lib/routes/api/cron.d.ts +6 -0
  533. package/lib/routes/api/cron.js +9 -0
  534. package/lib/routes/api/export.d.ts +5 -0
  535. package/lib/routes/api/export.js +11 -0
  536. package/lib/routes/api/feed.d.ts +5 -0
  537. package/lib/routes/api/feed.js +16 -0
  538. package/lib/routes/api/media.d.ts +8 -0
  539. package/lib/routes/api/media.js +25 -0
  540. package/lib/routes/api/navigation.d.ts +12 -0
  541. package/lib/routes/api/navigation.js +17 -0
  542. package/lib/routes/api/ops.d.ts +9 -0
  543. package/lib/routes/api/ops.js +19 -0
  544. package/lib/routes/api/pages.d.ts +8 -0
  545. package/lib/routes/api/pages.js +21 -0
  546. package/lib/routes/api/passkeys.d.ts +7 -0
  547. package/lib/routes/api/passkeys.js +13 -0
  548. package/lib/routes/api/posts.d.ts +8 -0
  549. package/lib/routes/api/posts.js +39 -0
  550. package/lib/routes/api/profile.d.ts +6 -0
  551. package/lib/routes/api/profile.js +8 -0
  552. package/lib/routes/api/redirects.d.ts +12 -0
  553. package/lib/routes/api/redirects.js +13 -0
  554. package/lib/routes/api/settings.d.ts +8 -0
  555. package/lib/routes/api/settings.js +15 -0
  556. package/lib/routes/api/snippets.d.ts +15 -0
  557. package/lib/routes/api/snippets.js +16 -0
  558. package/lib/routes/api/tags.d.ts +8 -0
  559. package/lib/routes/api/tags.js +14 -0
  560. package/lib/routes/api/tokens.d.ts +7 -0
  561. package/lib/routes/api/tokens.js +15 -0
  562. package/lib/routes/api/two-factor.d.ts +7 -0
  563. package/lib/routes/api/two-factor.js +15 -0
  564. package/lib/routes/api/users.d.ts +8 -0
  565. package/lib/routes/api/users.js +25 -0
  566. package/lib/routes/api/v1.d.ts +12 -0
  567. package/lib/routes/api/v1.js +55 -0
  568. package/lib/routes/api/verification.d.ts +6 -0
  569. package/lib/routes/api/verification.js +11 -0
  570. package/lib/server/index.d.ts +24 -0
  571. package/lib/server/index.js +110 -0
  572. package/lib/types/index.d.ts +298 -0
  573. package/lib/types/index.js +1 -0
  574. package/lib/vite.d.ts +2 -0
  575. package/lib/vite.js +101 -0
  576. package/mail/comment-moderation.html +27 -0
  577. package/mail/comment-moderation.txt +13 -0
  578. package/mail/comment-reply.html +28 -0
  579. package/mail/comment-reply.txt +14 -0
  580. package/mail/invitation.html +25 -0
  581. package/mail/invitation.txt +11 -0
  582. package/mail/member-magic-link.html +23 -0
  583. package/mail/member-magic-link.txt +10 -0
  584. package/mail/newsletter.html +26 -0
  585. package/mail/newsletter.txt +13 -0
  586. package/mail/password-reset.html +26 -0
  587. package/mail/password-reset.txt +10 -0
  588. package/mail/verify-email.html +25 -0
  589. package/mail/verify-email.txt +8 -0
  590. package/package.json +85 -4
@@ -0,0 +1,192 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTheme } from "../components/ThemeContext.js";
3
+ import { Card } from "../components/Card.js";
4
+ import { PageHeader } from "../components/PageHeader.js";
5
+ export function Routing() {
6
+ const { t } = useTheme();
7
+ const CodeBlock = ({ children, title }) => (_jsxs("div", { className: "mt-4", children: [title && _jsx("div", { className: `text-xs font-medium mb-2 ${t.muted}`, children: title }), _jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${t.card} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: children }) })] }));
8
+ return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Routing", subtitle: "API routes, controllers, and middleware" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Route Files" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Routes live in ", _jsx("code", { children: "src/routes/" }), ". Each file default-exports a function that receives the router and registers routes on it. The loader scans the directory recursively at startup and calls that function for every ", _jsx("code", { children: ".js" }), " file it finds."] }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "The loader only calls a default export when it is a function. A file that default-exports anything else, such as an array of route objects, is skipped without an error or a warning. If a route returns 404 that you are certain you registered, check that the file exports a function." }), _jsx(CodeBlock, { title: "src/routes/api/posts.js", children: `import { PostController } from '../../controllers/PostController.js'
9
+ import { auth } from '../../middleware/auth.js'
10
+
11
+ export default (router) => {
12
+ // Public routes
13
+ router.get('/api/feed', PostController.feed)
14
+ router.get('/api/feed/:id', PostController.feedShow)
15
+
16
+ // Authenticated routes
17
+ router.get('/api/posts', auth, PostController.index)
18
+ router.post('/api/posts', auth, PostController.store)
19
+ router.get('/api/posts/:id', auth, PostController.show)
20
+ router.put('/api/posts/:id', auth, PostController.update)
21
+ router.delete('/api/posts/:id', auth, PostController.destroy)
22
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The router supports ", _jsx("code", { children: "get" }), ", ", _jsx("code", { children: "post" }), ", ", _jsx("code", { children: "put" }), ", ", _jsx("code", { children: "patch" }), ", ", _jsx("code", { children: "delete" }), ", ", _jsx("code", { children: "head" }), " and ", _jsx("code", { children: "options" }), ", plus ", _jsx("code", { children: "all" }), " to register a path for every method."] }), _jsx(CodeBlock, { title: "Generate a route file", children: `npx basicben make:route post` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Controllers" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "Controllers hold the logic for your routes. Each handler receives the request and the response and is responsible for sending something back." }), _jsx(CodeBlock, { title: "src/controllers/PostController.js", children: `import { db } from '@basicbenframework/core/db'
23
+
24
+ export const PostController = {
25
+ // GET /api/posts
26
+ index: async (req, res) => {
27
+ const posts = await (await db.table('posts'))
28
+ .where('user_id', req.userId)
29
+ .orderBy('created_at', 'DESC')
30
+ .get()
31
+
32
+ res.json({ posts })
33
+ },
34
+
35
+ // GET /api/posts/:id
36
+ show: async (req, res) => {
37
+ const post = await (await db.table('posts')).find(req.params.id)
38
+
39
+ if (!post || post.user_id !== req.userId) {
40
+ return res.json({ error: 'Post not found' }, 404)
41
+ }
42
+
43
+ res.json({ post })
44
+ },
45
+
46
+ // POST /api/posts
47
+ store: async (req, res) => {
48
+ const { title, content } = req.body
49
+
50
+ const result = await (await db.table('posts')).insert({
51
+ title,
52
+ content,
53
+ user_id: req.userId
54
+ })
55
+
56
+ res.json({ id: result.lastInsertRowid }, 201)
57
+ },
58
+
59
+ // PUT /api/posts/:id
60
+ update: async (req, res) => {
61
+ const { title, content } = req.body
62
+
63
+ await (await db.table('posts'))
64
+ .where('id', req.params.id)
65
+ .where('user_id', req.userId)
66
+ .update({ title, content })
67
+
68
+ res.json({ success: true })
69
+ },
70
+
71
+ // DELETE /api/posts/:id
72
+ destroy: async (req, res) => {
73
+ await (await db.table('posts'))
74
+ .where('id', req.params.id)
75
+ .where('user_id', req.userId)
76
+ .delete()
77
+
78
+ res.json({ success: true })
79
+ }
80
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "db.table()" }), " resolves the database connection before it hands back a query builder, so it is awaited once before the chain starts. That is the reason for the doubled ", _jsx("code", { children: "await" }), "."] }), _jsx(CodeBlock, { title: "Generate a controller", children: `npm run make:controller Post` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Middleware" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Middleware is positional. Pass it between the path and the handler: the last argument is always the handler, and everything before it runs first, in order. A middleware either calls ", _jsx("code", { children: "next()" }), " to continue or sends a response to stop the chain."] }), _jsx(CodeBlock, { title: "Attaching middleware to a route", children: `router.get('/api/posts', auth, PostController.index)
81
+ router.post('/api/posts', auth, rateLimit, PostController.store)` }), _jsx(CodeBlock, { title: "src/middleware/auth.js", children: `import { verifyJwt } from '@basicbenframework/core/auth'
82
+
83
+ export const auth = async (req, res, next) => {
84
+ const token = req.headers.authorization?.replace('Bearer ', '')
85
+
86
+ if (!token) {
87
+ return res.json({ error: 'Unauthorized' }, 401)
88
+ }
89
+
90
+ const payload = verifyJwt(token, process.env.APP_KEY)
91
+
92
+ if (!payload) {
93
+ return res.json({ error: 'Invalid token' }, 401)
94
+ }
95
+
96
+ req.userId = payload.userId
97
+ next()
98
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Files in ", _jsx("code", { children: "src/middleware/" }), " that default-export a function are loaded automatically and applied to every request, in alphabetical order. Middleware you want to apply to specific routes should be a named export instead, as above, and passed to the route explicitly."] }), _jsx(CodeBlock, { title: "Generate middleware", children: `npx basicben make:middleware auth` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Route Groups" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "router.group()" }), " shares a path prefix and a set of middleware across several routes. Middleware passed to the group runs before the middleware of any route inside it."] }), _jsx(CodeBlock, { title: "Grouping routes", children: `export default (router) => {
99
+ router.group('/api/admin', auth, requireAdmin, (group) => {
100
+ group.get('/stats', AdminController.stats)
101
+ group.get('/users', AdminController.users)
102
+ group.get('/users/:id', AdminController.showUser)
103
+ })
104
+ }
105
+
106
+ // Registers, each behind auth and requireAdmin:
107
+ // GET /api/admin/stats
108
+ // GET /api/admin/users
109
+ // GET /api/admin/users/:id` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Named Routes" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Pass a name as a string directly after the path to register the route under that name. ", _jsx("code", { children: "router.route()" }), " then builds a URL from the name and its parameters, so paths are defined in one place rather than repeated as string literals."] }), _jsx(CodeBlock, { title: "Naming a route and generating its URL", children: `router.get('/api/users/:id/posts', 'users.posts', PostController.byUser)
110
+
111
+ router.route('users.posts', { id: 42 })
112
+ // => '/api/users/42/posts'` }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "The name is picked out by type, not by position: of the arguments between the path and the handler, the first string is the name and the rest are middleware. Both orderings below register the same named route. Put the name straight after the path anyway \u2014 it reads better, and it is where the next person will look for it." }), _jsx(CodeBlock, { title: "The name can sit anywhere among the middleware", children: `router.get('/api/posts/:id', 'posts.show', auth, PostController.show)
113
+ router.get('/api/posts/:id', auth, 'posts.show', PostController.show)
114
+
115
+ // Both give:
116
+ router.route('posts.show', { id: 42 })
117
+ // => '/api/posts/42'` }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "Before 0.1.17 only the first argument after the path was checked, so a name placed after middleware stayed in the middleware chain and was called as a function at request time. If you are on an older version, keep the name immediately after the path." }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "Asking for a name that was never registered throws, so a renamed route fails at the call site instead of quietly producing a broken URL." })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Resource Routes" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "router.resource()" }), " registers the five standard CRUD routes for a controller. It only registers a route when the matching method exists on the controller, so a controller without a ", _jsx("code", { children: "destroy" }), " method simply gets no DELETE route."] }), _jsx(CodeBlock, { title: "Registering a resource", children: `router.resource('/api/widgets', WidgetController)
118
+
119
+ // GET /api/widgets -> index (api.widgets.index)
120
+ // GET /api/widgets/:id -> show (api.widgets.show)
121
+ // POST /api/widgets -> create (api.widgets.create)
122
+ // PUT /api/widgets/:id -> update (api.widgets.update)
123
+ // DELETE /api/widgets/:id -> destroy (api.widgets.destroy)` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Route names are derived from the path. Pass ", _jsx("code", { children: "name" }), " to set them explicitly and ", _jsx("code", { children: "only" }), " to limit which routes are generated."] }), _jsx(CodeBlock, { title: "Resource options", children: `router.resource('/api/widgets', WidgetController, {
124
+ name: 'widgets',
125
+ only: ['index', 'show']
126
+ })
127
+
128
+ // GET /api/widgets -> widgets.index
129
+ // GET /api/widgets/:id -> widgets.show` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Pass ", _jsx("code", { children: "middleware" }), " to put every generated route behind it. Wrapping the resource in a group does the same thing and is the better choice when other routes share the same guard."] }), _jsx(CodeBlock, { title: "Middleware on a resource", children: `// Directly on the resource
130
+ router.resource('/api/widgets', WidgetController, {
131
+ name: 'widgets',
132
+ middleware: [auth]
133
+ })
134
+
135
+ // Or through a group, which other routes can share
136
+ router.group('/api', auth, (group) => {
137
+ group.resource('/widgets', WidgetController, { name: 'widgets' })
138
+ })` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The ", _jsx("code", { children: "middleware" }), " option was unusable before 0.1.17, when the generated route name was still read positionally: the option placed the middleware ahead of the name, which left the name in the chain and made every route in the resource fail with a 500. On an older version, use the group."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Route Parameters" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Path segments written as ", _jsx("code", { children: ":name" }), " are captured into ", _jsx("code", { children: "req.params" }), ". Query strings are parsed into ", _jsx("code", { children: "req.query" }), ", and the pathname is available as ", _jsx("code", { children: "req.path" }), ". Both params and query values are always strings."] }), _jsx(CodeBlock, { title: "Parameters and query strings", children: `// Route: /api/posts/:id
139
+ // URL: /api/posts/123?include=author
140
+
141
+ export const show = async (req, res) => {
142
+ const { id } = req.params // { id: '123' }
143
+ const { include } = req.query // { include: 'author' }
144
+
145
+ req.path // '/api/posts/123'
146
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["A trailing ", _jsx("code", { children: "/*" }), " matches everything below a path and captures the remainder as ", _jsx("code", { children: "req.params._catchAll" }), "."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Request Body" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["JSON request bodies are parsed automatically and made available on ", _jsx("code", { children: "req.body" }), ". The body parser is enabled by default with a 1mb limit, configurable through ", _jsx("code", { children: "bodyParser" }), " in ", _jsx("code", { children: "basicben.config.js" }), "."] }), _jsx(CodeBlock, { title: "Accessing the request body", children: `export const store = async (req, res) => {
147
+ const { title, content, published } = req.body
148
+
149
+ if (!title) {
150
+ return res.json({ error: 'Title is required' }, 400)
151
+ }
152
+
153
+ // ...
154
+ }` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Response Helpers" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "Every response object carries four helpers." }), _jsx(CodeBlock, { title: "Sending responses", children: `res.json({ posts }) // 200 with a JSON body
155
+ res.json({ error: 'Gone' }, 410) // status and JSON body together
156
+ res.send('plain text') // text, or JSON if given an object
157
+ res.redirect('/login') // 302 by default
158
+ res.redirect('/login', 301) // or an explicit status
159
+ res.status(204) // sets the status, returns res` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Both ways of setting a status work. ", _jsx("code", { children: "res.json()" }), " applies its second argument when you pass one and otherwise keeps whatever ", _jsx("code", { children: "res.status()" }), " already set, so an explicit second argument wins over an earlier ", _jsx("code", { children: "res.status()" }), " call."] }), _jsx(CodeBlock, { title: "Either form", children: `res.json({ error: 'Not found' }, 404) // 404
160
+ res.status(404).json({ error: 'Not found' }) // 404` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Before 0.1.15 ", _jsx("code", { children: "res.json()" }), " defaulted its status to 200 and applied it unconditionally, so ", _jsx("code", { children: "res.status(404).json(...)" }), " answered 200. Passing the code to ", _jsx("code", { children: "res.json()" }), " directly is correct on every version, which is why the examples here do it that way."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Client Routing" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["The browser side has its own router. ", _jsx("code", { children: "createClientApp()" }), " takes a map of paths to components and returns a React component to render. A path maps either to a component directly, or to an object that can also set a layout and a guard."] }), _jsx(CodeBlock, { title: "src/routes/App.jsx", children: `import { createClientApp } from '@basicbenframework/core/client'
161
+ import { AppLayout } from '../client/layouts/AppLayout'
162
+ import { AuthLayout } from '../client/layouts/AuthLayout'
163
+ import { Home } from '../client/pages/Home'
164
+ import { Auth } from '../client/pages/Auth'
165
+ import { Posts } from '../client/pages/Posts'
166
+ import { PostForm } from '../client/pages/PostForm'
167
+
168
+ export default createClientApp({
169
+ layout: AppLayout,
170
+ routes: {
171
+ '/': Home,
172
+ '/login': { component: Auth, layout: AuthLayout, guest: true },
173
+ '/posts': { component: Posts, auth: true },
174
+ '/posts/:id/edit': { component: PostForm, auth: true }
175
+ }
176
+ })` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "auth: true" }), " redirects to ", _jsx("code", { children: "/login" }), " when nobody is signed in. ", _jsx("code", { children: "guest: true" }), " does the reverse and redirects to ", _jsx("code", { children: "/" }), " when someone is, which keeps signed-in users off the login page. ", _jsx("code", { children: "layout" }), " replaces the app-wide ", _jsx("code", { children: "layout" }), " for that route only."] }), _jsx(CodeBlock, { title: "Hooks", children: `import { useAuth, useNavigate, useParams, usePath } from '@basicbenframework/core/client'
177
+
178
+ export function EditPost() {
179
+ const { user, logout, loading } = useAuth()
180
+ const navigate = useNavigate()
181
+ const { id } = useParams()
182
+ const path = usePath()
183
+
184
+ // navigate('/posts')
185
+ // navigate('/posts', { replace: true })
186
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["These hooks read context that ", _jsx("code", { children: "createClientApp" }), " provides, so they throw if called from a component rendered outside it."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Deep Links in Production" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["In production the server serves the built client from ", _jsx("code", { children: "static.dir" }), ". A request for ", _jsx("code", { children: "/posts/1" }), " looks for a file at that path, finds none, and returns 404, so the client router never gets a chance to run. Deep links and page refreshes break even though the same URLs work in development."] }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Setting ", _jsx("code", { children: "spa: true" }), " serves ", _jsx("code", { children: "index.html" }), " for unmatched routes instead, letting the client router take over."] }), _jsx(CodeBlock, { title: "basicben.config.js", children: `export default {
187
+ static: {
188
+ dir: 'public',
189
+ spa: true
190
+ }
191
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The fallback runs only after route matching, so it cannot shadow your API. Requests under ", _jsx("code", { children: "/api/" }), " and requests for files with a non-HTML extension still return 404, which means a missing script reports as missing rather than returning the app shell with the wrong content type. Available from 0.1.14."] })] })] })] }));
192
+ }
@@ -0,0 +1 @@
1
+ export declare function Storage(): import("react").JSX.Element;
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTheme } from "../components/ThemeContext.js";
3
+ import { Card } from "../components/Card.js";
4
+ import { PageHeader } from "../components/PageHeader.js";
5
+ export function Storage() {
6
+ const { t } = useTheme();
7
+ const CodeBlock = ({ children, title }) => (_jsxs("div", { className: "mt-4", children: [title && _jsx("div", { className: `text-xs font-medium mb-2 ${t.muted}`, children: title }), _jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${t.card} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: children }) })] }));
8
+ return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Object Storage", subtitle: "R2, S3, MinIO, B2 and Spaces \u2014 one driver, no AWS SDK" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "The adapter" }), _jsx(CodeBlock, { title: "Working with objects", children: `import { getStorage } from '@basicbenframework/core/storage'
9
+
10
+ const storage = await getStorage()
11
+
12
+ await storage.put('media/a.png', bytes, { contentType: 'image/png' })
13
+ await storage.get('media/a.png') // → { body, contentType, size, etag }
14
+ await storage.head('media/a.png') // → metadata, or null
15
+ await storage.delete('media/a.png')
16
+ await storage.list({ prefix: 'media/' }) // → { items, cursor }
17
+
18
+ storage.signedUrl('media/a.png', { method: 'PUT', expiresIn: 900 })
19
+ storage.publicUrl('media/a.png')` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "One driver, not two" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "R2 speaks the S3 API, and so do MinIO, Backblaze B2 and DigitalOcean Spaces. The difference between them is an endpoint and a region, so there is one driver and no branching in application code. Moving from R2 to S3 is two lines of config." }), _jsx(CodeBlock, { title: "basicben.config.js \u2014 Cloudflare R2", children: `storage: {
20
+ driver: 's3',
21
+ endpoint: 'https://<account-id>.r2.cloudflarestorage.com',
22
+ region: 'auto',
23
+ bucket: process.env.S3_BUCKET,
24
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
25
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
26
+ publicUrl: 'https://cdn.example.com' // optional CDN or custom domain
27
+ }` }), _jsx(CodeBlock, { title: "AWS S3 \u2014 omit the endpoint, name a real region", children: `storage: {
28
+ driver: 's3',
29
+ region: 'us-east-1',
30
+ bucket: process.env.S3_BUCKET,
31
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
32
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
33
+ }` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Configure nothing and the ", _jsx("code", { children: "local" }), " driver writes to", ' ', _jsx("code", { children: "public/uploads" }), ", so a new project works before anyone has a cloud account. The app serves that directory itself, in development and in production \u2014 for a while it only did so in development, because a production build serves ", _jsx("code", { children: "dist/client" }), ", which is written before any upload exists."] }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "publicUrl()" }), " returns an app-relative path on that driver and an absolute one on S3. The content API resolves both against ", _jsx("code", { children: "APP_URL" }), " before handing them to a consumer, since a headless reader on another host has nothing to resolve a relative path against. Set ", _jsx("code", { children: "APP_URL" }), " to the origin the site is reached at."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "No AWS SDK" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "@aws-sdk/client-s3" }), " is tens of megabytes for what is, underneath, one HMAC chain. SigV4 is HMAC-SHA256 and SHA-256, both already in ", _jsx("code", { children: "node:crypto" }), ", so the signer is written here and ", _jsx("code", { children: "dependencies" }), " stays empty."] }), _jsxs("p", { className: `text-sm ${t.muted}`, children: ["A hand-rolled signer is only worth trusting if it is checked against something outside itself, so it is checked two ways: AWS's own ", _jsx("strong", { children: "34 published test vectors" }), ", stage by stage, and ", _jsx("strong", { children: "a real MinIO server" }), " \u2014 the only thing that proves an actual S3 implementation accepts what it produces. That second check earned its place immediately: S3 does not normalize signed paths the way every other AWS service does, and the published vectors would never have caught it."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "How an upload works" }), _jsx("p", { className: `text-sm ${t.muted} mb-4`, children: "The browser PUTs straight to the bucket. This server signs a URL and records a row; the file bytes never pass through Node." }), _jsx(CodeBlock, { title: "Two steps, with the bytes going elsewhere", children: `Browser BasicBen R2 / S3
34
+ │ POST /api/media/sign │ │
35
+ │─────────────────────────>│ (validate, then sign) │
36
+ │ { uploadUrl, key, │ │
37
+ │ ticket, headers } │ │
38
+ │<─────────────────────────│ │
39
+ │ PUT <uploadUrl> ────── file bytes ──────────────> │
40
+ │ POST /api/media/confirm │ │
41
+ │─────────────────────────>│ HEAD, then INSERT │` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Content type and size are validated ", _jsx("strong", { children: "before" }), " anything is signed, because a caller without a signed URL cannot upload at all \u2014 that is the enforcement point, not a courtesy check. HTML, SVG and JavaScript are refused outright: a bucket served from a domain hands those back with the type they were stored under, which is same-origin script execution."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Two things a presigned URL does not do" }), _jsxs("p", { className: `text-sm ${t.muted} mb-3`, children: [_jsx("strong", { children: "It does not cap the size." }), " A URL issued for a thumbnail will accept a gigabyte. ", _jsx("code", { children: "confirm" }), " therefore HEADs the stored object and deletes it if it came back larger than allowed. The declared size is checked too, but only the stored size is believed."] }), _jsxs("p", { className: `text-sm ${t.muted}`, children: [_jsx("strong", { children: "It does not say who uploaded what." }), " The key travels through the browser, so each signed upload carries a ", _jsx("em", { children: "ticket" }), " \u2014 an HMAC over the key, the owner and the expiry \u2014 checked at confirm time. Without it a caller could confirm someone else's object as its own media row. It is stateless, so there is no pending-upload table to clean up."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Hooks" }), _jsx(CodeBlock, { title: "Rewrite a key, or refuse an upload", children: `hooks.on('media.uploading', (upload) => ({
42
+ ...upload,
43
+ key: \`tenant-7/\${upload.key}\`
44
+ }))
45
+
46
+ hooks.on('media.uploading', (upload) => ({
47
+ ...upload,
48
+ cancel: true,
49
+ reason: 'Quota exceeded.'
50
+ }))
51
+
52
+ hooks.on('media.uploaded', ({ key, url }) => purgeCdn(url))
53
+ hooks.on('media.deleted', ({ key }) => purgeCdn(key))` })] })] })] }));
54
+ }
@@ -0,0 +1 @@
1
+ export declare function Testing(): import("react").JSX.Element;
@@ -0,0 +1,141 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTheme } from "../components/ThemeContext.js";
3
+ import { Card } from "../components/Card.js";
4
+ import { PageHeader } from "../components/PageHeader.js";
5
+ export function Testing() {
6
+ const { t } = useTheme();
7
+ const CodeBlock = ({ children, title }) => (_jsxs("div", { className: "mt-4", children: [title && _jsx("div", { className: `text-xs font-medium mb-2 ${t.muted}`, children: title }), _jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${t.card} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: children }) })] }));
8
+ return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Testing", subtitle: "Running tests with Vitest, and what the framework leaves to you" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "How Tests Run" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "npm test" }), " runs ", _jsx("code", { children: "basicben test" }), ", which hands off to Vitest with", _jsx("code", { children: "--run" }), " \u2014 one pass, then exit. Vitest picks up files matching", _jsx("code", { children: "*.test.js" }), " and ", _jsx("code", { children: "*.spec.js" }), " anywhere in the project, and reads", _jsx("code", { children: "vite.config.js" }), ", so there is nothing else to configure to get started."] }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("code", { className: "text-sm font-semibold", children: "npm test" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Run every test once" })] }), _jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("code", { className: "text-sm font-semibold", children: "npm test -- src/models" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Only files matching a path fragment" })] }), _jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("code", { className: "text-sm font-semibold", children: "npm test -- --watch" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Re-run on change" })] }), _jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("code", { className: "text-sm font-semibold", children: "npx vitest" }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: "Vitest directly, skipping the CLI wrapper" })] })] }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: [_jsx("code", { children: "test" }), " is the only test script in ", _jsx("code", { children: "package.json" }), ". There is no", _jsx("code", { children: "test:watch" }), ", ", _jsx("code", { children: "test:coverage" }), " or ", _jsx("code", { children: "test:ui" }), " \u2014 the arguments after ", _jsx("code", { children: "--" }), " are what npm forwards, and everything below is a flag rather than a script of its own."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "What the Framework Does Not Provide" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["There is no testing module. Alongside the package root there are nineteen entry points \u2014 ", _jsx("code", { children: "server" }), ", ", _jsx("code", { children: "client" }), ", ", _jsx("code", { children: "db" }), ",", ' ', _jsx("code", { children: "auth" }), ", ", _jsx("code", { children: "validation" }), ", ", _jsx("code", { children: "content" }), ",", ' ', _jsx("code", { children: "storage" }), ", ", _jsx("code", { children: "mail" }), ", ", _jsx("code", { children: "hooks" }), ",", ' ', _jsx("code", { children: "rate-limit" }), ", ", _jsx("code", { children: "etag" }), ", ", _jsx("code", { children: "webhooks" }), ", and the", ' ', _jsx("code", { children: "auth/*" }), " and ", _jsx("code", { children: "storage/*" }), " families \u2014 and not one of them is for tests. No test client, no request builder, no database reset helper, no model factories."] }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Less of that is missing than it first appears. Controllers are functions, so call them. Models are objects, so call them. The query builder works against any SQLite file, so a test can have one of its own. The part you do have to arrange yourself is HTTP-level testing: exercising routing and middleware end to end means starting a server and using ", _jsx("code", { children: "fetch" }), " against it."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "A Plain Test" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Test files sit next to the code they cover, or under ", _jsx("code", { children: "tests/" }), " if you prefer them apart. Anything Vitest exports is available: ", _jsx("code", { children: "describe" }), ",", _jsx("code", { children: "it" }), ", ", _jsx("code", { children: "expect" }), ", ", _jsx("code", { children: "beforeEach" }), ", ", _jsx("code", { children: "vi" }), " for mocks."] }), _jsx(CodeBlock, { title: "src/utils/helpers.test.js", children: `import { describe, it, expect } from 'vitest'
9
+ import { slugify } from './helpers.js'
10
+
11
+ describe('slugify', () => {
12
+ it('converts text to a slug', () => {
13
+ expect(slugify('Hello World')).toBe('hello-world')
14
+ })
15
+
16
+ it('removes punctuation', () => {
17
+ expect(slugify('Hello! World?')).toBe('hello-world')
18
+ })
19
+ })` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Testing a Controller" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["A controller action is an ordinary ", _jsx("code", { children: "async (req, res)" }), " function, so a test can call it with objects you build by hand. Only the properties the action actually reads need to exist, which for most actions is ", _jsx("code", { children: "body" }), ",", _jsx("code", { children: "params" }), " and whatever your auth middleware attaches."] }), _jsx(CodeBlock, { title: "tests/PostController.test.js", children: `import { describe, it, expect } from 'vitest'
20
+ import { PostController } from '../src/controllers/PostController.js'
21
+
22
+ // res is whatever the controller calls. json(data, status) is the only
23
+ // method these paths use, so a small stub is enough.
24
+ function mockRes() {
25
+ const sent = {}
26
+ return {
27
+ sent,
28
+ json(data, status = 200) {
29
+ sent.data = data
30
+ sent.status = status
31
+ }
32
+ }
33
+ }
34
+
35
+ describe('PostController.store', () => {
36
+ it('returns 422 when the body fails validation', async () => {
37
+ const res = mockRes()
38
+
39
+ await PostController.store({ body: { title: 'x' }, userId: 1 }, res)
40
+
41
+ expect(res.sent.status).toBe(422)
42
+ expect(res.sent.data.errors.title).toBeDefined()
43
+ expect(res.sent.data.errors.content).toBeDefined()
44
+ })
45
+ })` }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "A validation failure returns before any query runs, so this test needs no database at all. Actions that do reach the database need the setup in the next section." })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Testing Database Code" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Point the connection at a scratch SQLite file before the first query runs, and delete it afterwards. ", _jsx("code", { children: "resetDb()" }), " drops the cached connection so the next call opens the file you just named, and creating the schema in", _jsx("code", { children: "beforeAll" }), " keeps each run independent of migration state."] }), _jsx(CodeBlock, { title: "tests/posts.test.js", children: `import { describe, it, expect, beforeAll, afterAll } from 'vitest'
46
+ import { existsSync, unlinkSync } from 'node:fs'
47
+ import { db, query, resetDb } from '@basicbenframework/core/db'
48
+
49
+ const TEST_DB = './tests/test.sqlite'
50
+
51
+ function removeTestDb() {
52
+ // WAL mode leaves two sidecar files next to the database.
53
+ for (const suffix of ['', '-wal', '-shm']) {
54
+ if (existsSync(TEST_DB + suffix)) unlinkSync(TEST_DB + suffix)
55
+ }
56
+ }
57
+
58
+ beforeAll(async () => {
59
+ removeTestDb()
60
+
61
+ // basicben.config.js leaves db.url unset, so DATABASE_URL decides
62
+ // the file. resetDb() clears any connection opened before this.
63
+ process.env.DATABASE_URL = TEST_DB
64
+ resetDb()
65
+
66
+ await db.exec(\`
67
+ CREATE TABLE posts (
68
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
69
+ title TEXT NOT NULL,
70
+ published INTEGER DEFAULT 0
71
+ )
72
+ \`)
73
+ })
74
+
75
+ afterAll(async () => {
76
+ await db.close()
77
+ removeTestDb()
78
+ })
79
+
80
+ describe('posts', () => {
81
+ it('inserts a row and reads it back', async () => {
82
+ const result = await (await query('posts')).insert({ title: 'Hello', published: 1 })
83
+ const post = await (await query('posts')).find(result.lastInsertRowid)
84
+
85
+ expect(post.title).toBe('Hello')
86
+ })
87
+
88
+ it('drops columns that only() does not list', async () => {
89
+ await (await query('posts')).only('title').insert({ title: 'Draft', published: 1 })
90
+ const post = await (await query('posts')).where('title', 'Draft').first()
91
+
92
+ expect(post.published).toBe(0)
93
+ })
94
+
95
+ it('rolls back when the transaction callback throws', async () => {
96
+ await expect(
97
+ db.transaction(async (tx) => {
98
+ await tx.run('INSERT INTO posts (title) VALUES (?)', ['Rolled back'])
99
+ throw new Error('boom')
100
+ })
101
+ ).rejects.toThrow('boom')
102
+
103
+ expect(await (await query('posts')).where('title', 'Rolled back').count()).toBe(0)
104
+ })
105
+ })` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["Two things to watch. The connection is one cached instance per process, resolved once from ", _jsx("code", { children: "db.url" }), " in ", _jsx("code", { children: "basicben.config.js" }), " falling back to", ' ', _jsx("code", { children: "DATABASE_URL" }), " \u2014 the config wins. A project that sets it there will have its tests write to the development database instead, so set the test path in the config or leave ", _jsx("code", { children: "db.url" }), " unset. And SQLite will not bind JavaScript booleans, so test data uses ", _jsx("code", { children: "1" }), " and ", _jsx("code", { children: "0" }), " like everything else."] }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "Vitest runs separate test files in parallel workers. Files that share one SQLite path will collide, so give each file its own database name, or keep database tests in a single file." })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Coverage and the UI" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Both flags exist, and each needs a package that is not installed by default. Run either one without it and Vitest stops immediately with", _jsx("code", { children: "MISSING DEPENDENCY" }), "."] }), _jsx(CodeBlock, { title: "Install first, then run", children: `npm install -D @vitest/coverage-v8
106
+ npm test -- --coverage
107
+
108
+ npm install -D @vitest/ui
109
+ npm test -- --ui` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Node's Test Runner" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["The framework's own suite is written against ", _jsx("code", { children: "node:test" }), " and", _jsx("code", { children: "node:assert" }), ", with no test dependency at all. You can write app tests the same way if you would rather not depend on Vitest \u2014 but run them with", _jsx("code", { children: "node --test" }), " directly, not through ", _jsx("code", { children: "npm test" }), "."] }), _jsx(CodeBlock, { title: "Run node:test files directly", children: `node --test tests/helpers.test.js
110
+ node --test --watch tests/
111
+ node --test --experimental-test-coverage tests/` }), _jsx(CodeBlock, { title: "A node:test file", children: `import { test, describe } from 'node:test'
112
+ import assert from 'node:assert'
113
+ import { slugify } from '../src/utils/helpers.js'
114
+
115
+ describe('slugify', () => {
116
+ test('converts text to a slug', () => {
117
+ assert.strictEqual(slugify('Hello World'), 'hello-world')
118
+ })
119
+ })` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The two runners do not mix. Passing a ", _jsx("code", { children: "node:test" }), " file to", _jsx("code", { children: "npm test" }), " fails with ", _jsx("code", { children: "No test suite found in file" }), ", because the tests register with Node's runner and Vitest collects nothing. Pick one style per file, and if you use both, keep them in directories you can point each runner at."] })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Practices That Hold Up Here" }), _jsx("div", { className: "space-y-3 mt-4", children: [
120
+ {
121
+ title: 'Give each test its own data',
122
+ desc: 'There is no reset helper, so tests that assume an empty table break as soon as another test inserts. Create what you assert on, or assert on rows you inserted by name.'
123
+ },
124
+ {
125
+ title: 'Test the model, not the query builder',
126
+ desc: 'The builder has its own tests. What is worth covering is the SQL you wrote by hand, especially the joins the builder cannot express.'
127
+ },
128
+ {
129
+ title: 'Cover validation failures',
130
+ desc: 'The 422 path returns before any query, so it is the cheapest test in the suite and the one most likely to regress when a schema changes.'
131
+ },
132
+ {
133
+ title: 'Keep the database out of unit tests',
134
+ desc: 'Anything that is a pure function of its arguments should be tested as one. Reserve the SQLite fixture for code that genuinely queries.'
135
+ },
136
+ {
137
+ title: 'Name tests after the behaviour',
138
+ desc: 'The name is what you read when it fails, and "returns 422 when the body fails validation" tells you more at that moment than "store works".'
139
+ },
140
+ ].map(({ title, desc }) => (_jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("div", { className: "font-semibold text-sm", children: title }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: desc })] }, title))) })] })] })] }));
141
+ }
@@ -0,0 +1 @@
1
+ export declare function Validation(): import("react").JSX.Element;
@@ -0,0 +1,123 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTheme } from "../components/ThemeContext.js";
3
+ import { Card } from "../components/Card.js";
4
+ import { PageHeader } from "../components/PageHeader.js";
5
+ export function Validation() {
6
+ const { t } = useTheme();
7
+ const CodeBlock = ({ children, title }) => (_jsxs("div", { className: "mt-4", children: [title && _jsx("div", { className: `text-xs font-medium mb-2 ${t.muted}`, children: title }), _jsx("div", { className: `rounded-lg p-4 font-mono text-sm ${t.card} border ${t.border} overflow-x-auto`, children: _jsx("pre", { className: t.text, children: children }) })] }));
8
+ return (_jsxs("div", { children: [_jsx(PageHeader, { title: "Validation", subtitle: "Request validation with built-in rules" }), _jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Basic Usage" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Validate request data with the ", _jsx("code", { children: "validate" }), " function and the built-in rules. It returns a result object \u2014 check it with ", _jsx("code", { children: "fails()" }), " or ", _jsx("code", { children: "passes()" }), "."] }), _jsx(CodeBlock, { title: "Validating a request body", children: `import { validate, rules } from '@basicbenframework/core/validation'
9
+
10
+ export const store = async (req, res) => {
11
+ const result = await validate(req.body, {
12
+ title: [rules.required, rules.min(3), rules.max(100)],
13
+ email: [rules.required, rules.email],
14
+ age: [rules.required, rules.numeric, rules.min(18)]
15
+ })
16
+
17
+ if (result.fails()) {
18
+ return res.json({ errors: result.errors }, 422)
19
+ }
20
+
21
+ // Data is valid, continue...
22
+ }` }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "Validation stops at the first failing rule for each field, so every field has at most one message. Messages interpolate the field name as written in the schema." }), _jsx(CodeBlock, { title: "Error response format", children: `{
23
+ "errors": {
24
+ "title": ["title must be at least 3 characters"],
25
+ "email": ["email must be a valid email"],
26
+ "age": ["age is required"]
27
+ }
28
+ }` }), _jsx(CodeBlock, { title: "Reading the result", children: `result.fails() // true if any field failed
29
+ result.passes() // the inverse
30
+ result.errors // { field: [message] }
31
+ result.first('email') // first message for a field, or null
32
+ result.all() // [{ field, message }, ...]` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Available Rules" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Note that ", _jsx("code", { children: "min" }), " and ", _jsx("code", { children: "max" }), " cover both cases: they compare length for strings and value for numbers."] }), _jsx("div", { className: "grid gap-2 sm:grid-cols-2", children: [
33
+ { rule: 'required', desc: 'Must be present and not empty' },
34
+ { rule: 'optional', desc: 'Skips the remaining rules when empty' },
35
+ { rule: 'string', desc: 'Must be a string' },
36
+ { rule: 'numeric', desc: 'Must be a number or numeric string' },
37
+ { rule: 'integer', desc: 'Must be a whole number' },
38
+ { rule: 'boolean', desc: 'Must be true or false' },
39
+ { rule: 'array', desc: 'Must be an array' },
40
+ { rule: 'email', desc: 'Must be a valid email address' },
41
+ { rule: 'url', desc: 'Must be a valid URL' },
42
+ { rule: 'min(n)', desc: 'String at least n characters, or number at least n' },
43
+ { rule: 'max(n)', desc: 'String at most n characters, or number at most n' },
44
+ { rule: 'between(a, b)', desc: 'Number within a and b, inclusive' },
45
+ { rule: 'length(n)', desc: 'String exactly n characters' },
46
+ { rule: 'in(...values)', desc: 'Must be one of the given values' },
47
+ { rule: 'notIn(...values)', desc: 'Must not be one of the given values' },
48
+ { rule: 'regex(pattern)', desc: 'Must match the pattern' },
49
+ { rule: 'alpha', desc: 'Letters only' },
50
+ { rule: 'alphanumeric', desc: 'Letters and numbers only' },
51
+ { rule: 'date', desc: 'Must be a parseable date' },
52
+ { rule: 'before(date)', desc: 'Date earlier than the given date' },
53
+ { rule: 'after(date)', desc: 'Date later than the given date' },
54
+ { rule: 'confirmed(field)', desc: 'Must match another field, e.g. password' },
55
+ { rule: 'different(field)', desc: 'Must differ from another field' },
56
+ { rule: 'unique(table, col?, exceptId?)', desc: 'No such row in the database' },
57
+ { rule: 'exists(table, col?)', desc: 'A matching row exists in the database' },
58
+ ].map(({ rule, desc }) => (_jsxs("div", { className: `rounded-lg p-3 ${t.card} border ${t.border}`, children: [_jsx("code", { className: "text-sm font-semibold", children: rule }), _jsx("p", { className: `text-xs mt-1 ${t.muted}`, children: desc })] }, rule))) })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Optional Fields" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Rules ignore empty values, so a field without ", _jsx("code", { children: "required" }), " is already optional \u2014 the other rules only apply once it has a value. Add ", _jsx("code", { children: "rules.optional" }), "first when you want to stop the chain outright for an empty field."] }), _jsx(CodeBlock, { title: "Optional fields", children: `const result = await validate(req.body, {
59
+ name: [rules.required], // must be present
60
+ bio: [rules.max(500)], // optional; if present, at most 500 characters
61
+ website: [rules.url], // optional; if present, must be a URL
62
+ nickname: [rules.optional, rules.min(2)]
63
+ })` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Database Rules" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: [_jsx("code", { children: "unique" }), " and ", _jsx("code", { children: "exists" }), " query the database, so they are async \u2014 remember to ", _jsx("code", { children: "await validate(...)" }), "."] }), _jsx(CodeBlock, { title: "Unique", children: `// No other user has this email
64
+ email: [rules.required, rules.email, rules.unique('users')]
65
+
66
+ // Check a specific column
67
+ slug: [rules.unique('categories', 'slug')]
68
+
69
+ // Ignore the record being updated
70
+ email: [rules.unique('users', 'email', currentUserId)]` }), _jsx(CodeBlock, { title: "Exists", children: `// The referenced user must exist
71
+ user_id: [rules.required, rules.exists('users')]
72
+
73
+ // Match on a specific column
74
+ category: [rules.exists('categories', 'slug')]` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Custom Rules" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["A rule is a function receiving ", _jsx("code", { children: "(value, field, data)" }), ". Return a message to fail, or ", _jsx("code", { children: "null" }), " to pass. Rules may be async."] }), _jsx(CodeBlock, { title: "A custom rule", children: `const isSlug = (value, field) => {
75
+ if (!/^[a-z0-9-]+$/.test(value)) {
76
+ return \`\${field} must contain only lowercase letters, numbers and hyphens\`
77
+ }
78
+ return null
79
+ }
80
+
81
+ const result = await validate(req.body, {
82
+ slug: [rules.required, isSlug]
83
+ })` }), _jsx(CodeBlock, { title: "An async rule", children: `const isAvailableUsername = async (value) => {
84
+ const existing = await (await db.table('users'))
85
+ .where('username', value)
86
+ .first()
87
+
88
+ return existing ? 'Username is already taken' : null
89
+ }
90
+
91
+ const result = await validate(req.body, {
92
+ username: [rules.required, isAvailableUsername]
93
+ })` }), _jsx("p", { className: `text-sm ${t.muted} mt-4`, children: "The third argument is the whole payload, which is how a rule can compare fields." }), _jsx(CodeBlock, { title: "Using the full payload", children: `const afterStart = (value, field, data) => {
94
+ if (new Date(value) <= new Date(data.starts_at)) {
95
+ return \`\${field} must be after starts_at\`
96
+ }
97
+ return null
98
+ }` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Custom Error Messages" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Wrap a check with the ", _jsx("code", { children: "rule" }), " helper to supply your own message. The validator it wraps signals failure by returning ", _jsx("code", { children: "false" }), "."] }), _jsx(CodeBlock, { title: "rule(validator, message)", children: `import { validate, rules, rule } from '@basicbenframework/core/validation'
99
+
100
+ const result = await validate(req.body, {
101
+ email: [
102
+ rule((value) => !!value, 'Please enter your email'),
103
+ rule((value) => /.+@.+\\..+/.test(value), 'Please enter a valid email address')
104
+ ],
105
+ password: [
106
+ rule((value) => (value || '').length >= 8, 'Password must be at least 8 characters')
107
+ ]
108
+ })` }), _jsxs("p", { className: `text-sm ${t.muted} mt-4`, children: ["The message may also be a function of ", _jsx("code", { children: "(field, value)" }), ", which is useful when it should mention what was submitted."] }), _jsx(CodeBlock, { title: "A message built from the value", children: `rule(
109
+ (value) => (value || '').length <= 100,
110
+ (field, value) => \`\${field} is \${value.length} characters; the limit is 100\`
111
+ )` })] }), _jsxs(Card, { children: [_jsx("h2", { className: "text-lg font-semibold mb-2", children: "Nested Data" }), _jsxs("p", { className: `text-sm ${t.muted} mb-4`, children: ["Schema keys are looked up directly on the object, so dot notation like", _jsx("code", { children: "'user.name'" }), " does not resolve into a nested object. Validate the nested object on its own, or pull the values up first."] }), _jsx(CodeBlock, { title: "Validate the nested object separately", children: `// Request body: { user: { name: 'Ada', email: 'ada@example.com' } }
112
+
113
+ const result = await validate(req.body.user ?? {}, {
114
+ name: [rules.required, rules.min(2)],
115
+ email: [rules.required, rules.email]
116
+ })` }), _jsx(CodeBlock, { title: "Or flatten first", children: `const result = await validate(
117
+ { name: req.body.user?.name, email: req.body.user?.email },
118
+ {
119
+ name: [rules.required, rules.min(2)],
120
+ email: [rules.required, rules.email]
121
+ }
122
+ )` })] })] })] }));
123
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function AdminCategories(): React.JSX.Element;