@beechcms/api 0.6.0-preview.1 → 0.6.0-preview.3

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 (373) hide show
  1. package/README.md +4 -4
  2. package/assets/dashboard/BeechLogo.svg +18 -18
  3. package/assets/dashboard/BeechLogoLIght.svg +48 -48
  4. package/assets/dashboard/assets/chart-Cws4Yj6K.js +39 -0
  5. package/assets/dashboard/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  6. package/assets/dashboard/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  7. package/assets/dashboard/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  8. package/assets/dashboard/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  9. package/assets/dashboard/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  10. package/assets/dashboard/assets/index-BjPpppHe.css +1 -0
  11. package/assets/dashboard/assets/index-CrW-zhkA.js +642 -0
  12. package/assets/dashboard/assets/lora-cyrillic-ext-wght-normal-YcVxMP-u.woff2 +0 -0
  13. package/assets/dashboard/assets/lora-cyrillic-wght-normal-UWPuZLjM.woff2 +0 -0
  14. package/assets/dashboard/assets/lora-latin-ext-wght-normal-C2Wlntb9.woff2 +0 -0
  15. package/assets/dashboard/assets/lora-latin-wght-normal-BiLcIKcI.woff2 +0 -0
  16. package/assets/dashboard/assets/lora-math-wght-normal-sOy7rEfW.woff2 +0 -0
  17. package/assets/dashboard/assets/lora-symbols-wght-normal-DQ5VrUkH.woff2 +0 -0
  18. package/assets/dashboard/assets/lora-vietnamese-wght-normal-CfJ7gtf3.woff2 +0 -0
  19. package/assets/dashboard/assets/pie-chart-recharts-CAxoDQp2.js +1 -0
  20. package/assets/dashboard/assets/timeseries-chart-recharts-CixDW-LM.js +1 -0
  21. package/assets/dashboard/beechLogoDark.svg +48 -48
  22. package/assets/dashboard/index.html +18 -18
  23. package/assets/dashboard/noResult.svg +42 -42
  24. package/assets/dashboard/sol.svg +3 -3
  25. package/assets/dashboard/undraw_enter_nwx3.svg +36 -36
  26. package/dist/auth/__fixtures__/in-memory-hash-provider.d.ts +5 -0
  27. package/dist/auth/__fixtures__/static-token-service.d.ts +6 -0
  28. package/dist/auth/bcrypt-hash-provider.d.ts +8 -0
  29. package/dist/auth/constants.d.ts +10 -0
  30. package/dist/auth/jose-token-service.d.ts +14 -0
  31. package/dist/auth/login.d.ts +32 -0
  32. package/dist/auth/refresh.d.ts +1 -0
  33. package/dist/factory.d.ts +39 -0
  34. package/dist/features/automations/action-executors/create-entry.executor.d.ts +7 -0
  35. package/dist/features/automations/action-executors/edit-field.executor.d.ts +7 -0
  36. package/dist/features/automations/action-executors/index.d.ts +13 -0
  37. package/dist/features/automations/action-executors/send-mail.executor.d.ts +7 -0
  38. package/dist/features/automations/action-executors/set-variable.executor.d.ts +15 -0
  39. package/dist/features/automations/action-executors/webhook.executor.d.ts +7 -0
  40. package/dist/features/automations/automation-runner.d.ts +13 -0
  41. package/dist/features/automations/automation-runner.utils.d.ts +3 -0
  42. package/dist/features/automations/automations.handler.d.ts +7 -0
  43. package/dist/features/automations/automations.schema.d.ts +191 -0
  44. package/dist/features/automations/context-resolver.d.ts +8 -0
  45. package/dist/features/automations/cron-runner.d.ts +9 -0
  46. package/dist/features/automations/cron-runner.utils.d.ts +1 -0
  47. package/dist/features/automations/filter-translation.d.ts +9 -0
  48. package/dist/features/automations/index.d.ts +7 -0
  49. package/dist/features/automations/template-grammar.d.ts +73 -0
  50. package/dist/features/automations/var-access-resolver.d.ts +6 -0
  51. package/dist/features/automations/when-evaluator.d.ts +3 -0
  52. package/dist/features/automations/when-pushdown.d.ts +2 -0
  53. package/dist/features/backrefs/backrefs.handler.d.ts +3 -0
  54. package/dist/features/backrefs/d1-backref.repository.d.ts +17 -0
  55. package/dist/features/backrefs/index.d.ts +1 -0
  56. package/dist/features/content/constants.d.ts +12 -0
  57. package/dist/features/content/handlers/bulk.handler.d.ts +3 -0
  58. package/dist/features/content/handlers/create.d.ts +3 -0
  59. package/dist/features/content/handlers/delete.d.ts +3 -0
  60. package/dist/features/content/handlers/facets.d.ts +3 -0
  61. package/dist/features/content/handlers/get.d.ts +4 -0
  62. package/dist/features/content/handlers/helpers.d.ts +12 -0
  63. package/dist/features/content/handlers/list.d.ts +3 -0
  64. package/dist/features/content/handlers/update.d.ts +3 -0
  65. package/dist/features/content/index.d.ts +4 -0
  66. package/dist/features/dashboard-layout/dashboard-layout.handler.d.ts +7 -0
  67. package/dist/features/dashboard-layout/index.d.ts +1 -0
  68. package/dist/features/draft/draft.handler.d.ts +4 -0
  69. package/dist/features/draft/draft.middleware.d.ts +9 -0
  70. package/dist/features/draft/index.d.ts +1 -0
  71. package/{src/features/email/email.provider.ts → dist/features/email/email.provider.d.ts} +37 -42
  72. package/dist/features/email/email.service.d.ts +13 -0
  73. package/dist/features/email/email.types.d.ts +94 -0
  74. package/{src/features/email/index.ts → dist/features/email/index.d.ts} +20 -33
  75. package/dist/features/email/providers/resend.d.ts +36 -0
  76. package/dist/features/email/providers/smtp.d.ts +11 -0
  77. package/dist/features/email/templates/automation-mail.d.ts +8 -0
  78. package/dist/features/email/templates/password-changed.d.ts +15 -0
  79. package/dist/features/email/templates/password-reset.d.ts +18 -0
  80. package/dist/features/email/templates/shell.d.ts +58 -0
  81. package/dist/features/notifications/index.d.ts +1 -0
  82. package/dist/features/notifications/notifications.handler.d.ts +15 -0
  83. package/dist/features/password-reset/index.d.ts +6 -0
  84. package/dist/features/password-reset/request.d.ts +10 -0
  85. package/dist/features/password-reset/reset.d.ts +9 -0
  86. package/dist/features/rotate-field/index.d.ts +1 -0
  87. package/dist/features/rotate-field/rotate-field.handler.d.ts +7 -0
  88. package/dist/features/rotate-field/rotate-field.schema.d.ts +11 -0
  89. package/dist/features/schema/schema.handler.d.ts +7 -0
  90. package/dist/features/seeds/index.d.ts +1 -0
  91. package/dist/features/seeds/seeds.handler.d.ts +6 -0
  92. package/dist/features/settings/settings.handler.d.ts +7 -0
  93. package/dist/features/setup/index.d.ts +7 -0
  94. package/dist/features/stats/index.d.ts +1 -0
  95. package/dist/features/stats/stats.handler.d.ts +7 -0
  96. package/dist/features/webhooks/index.d.ts +3 -0
  97. package/dist/index.d.ts +6 -0
  98. package/dist/index.js +9666 -0
  99. package/dist/media-utils.d.ts +25 -0
  100. package/dist/middleware/auth-providers.middleware.d.ts +8 -0
  101. package/dist/middleware/observability.middleware.d.ts +20 -0
  102. package/dist/middleware/rate-limit.middleware.d.ts +9 -0
  103. package/dist/middleware/repository.middleware.d.ts +34 -0
  104. package/dist/middleware/seed-registry.middleware.d.ts +10 -0
  105. package/dist/middleware/storage.middleware.d.ts +7 -0
  106. package/dist/middleware.d.ts +11 -0
  107. package/dist/public/access-policy.d.ts +12 -0
  108. package/dist/public/api-key-middleware.d.ts +6 -0
  109. package/dist/public/cache-utils.d.ts +10 -0
  110. package/dist/public/entry-projection.d.ts +2 -0
  111. package/dist/public/idempotency.d.ts +9 -0
  112. package/dist/public/index.d.ts +11 -0
  113. package/dist/public/problem-details.d.ts +31 -0
  114. package/dist/public/public-add.d.ts +3 -0
  115. package/dist/public/public-edit.d.ts +5 -0
  116. package/dist/public/public-errors.d.ts +13 -0
  117. package/dist/public/public-read.d.ts +3 -0
  118. package/dist/public/public-routes.d.ts +3 -0
  119. package/dist/public/query-builder.d.ts +28 -0
  120. package/dist/public/rate-limit-middleware.d.ts +3 -0
  121. package/dist/public/read-list.d.ts +26 -0
  122. package/dist/public/read-single.d.ts +22 -0
  123. package/dist/public/response-builder.d.ts +22 -0
  124. package/dist/public/sanitize.d.ts +23 -0
  125. package/dist/public/slug-utils.d.ts +11 -0
  126. package/dist/rate-limit/cloudflare-rate-limiter.d.ts +6 -0
  127. package/dist/rate-limit/in-memory-rate-limiter.d.ts +7 -0
  128. package/dist/rate-limit/no-op-rate-limiter.d.ts +4 -0
  129. package/dist/search-utils.d.ts +54 -0
  130. package/dist/search.d.ts +6 -0
  131. package/dist/shared/apply-policies.d.ts +10 -0
  132. package/dist/shared/automations.repository.d1.d.ts +12 -0
  133. package/dist/shared/background-notification-service.d.ts +18 -0
  134. package/dist/shared/base.repository.d1.d.ts +18 -0
  135. package/dist/shared/content-utils.d.ts +21 -0
  136. package/dist/shared/content.repository.d1.d.ts +68 -0
  137. package/dist/shared/d1-activity-log.repository.d.ts +13 -0
  138. package/dist/shared/d1-activity-logger.d.ts +20 -0
  139. package/dist/shared/d1-analytics.repository.d.ts +20 -0
  140. package/dist/shared/d1-content-scan.repository.d.ts +7 -0
  141. package/dist/shared/d1-notification.repository.d.ts +17 -0
  142. package/dist/shared/d1-password-reset-token.repository.d.ts +10 -0
  143. package/dist/shared/d1-search.repository.d.ts +14 -0
  144. package/dist/shared/d1-session.repository.d.ts +12 -0
  145. package/dist/shared/d1-setup-checklist.repository.d.ts +12 -0
  146. package/dist/shared/d1-user.repository.d.ts +18 -0
  147. package/dist/shared/d1-widget.repository.d.ts +31 -0
  148. package/dist/shared/dashboard-layout.repository.d1.d.ts +9 -0
  149. package/dist/shared/demo-data-sql.d.ts +1 -0
  150. package/dist/shared/demo-data.repository.d1.d.ts +6 -0
  151. package/dist/shared/execution-context-scheduler.d.ts +6 -0
  152. package/dist/shared/fixed-clock.d.ts +13 -0
  153. package/dist/shared/fts-sync.d.ts +1 -0
  154. package/dist/shared/idempotency.repository.d1.d.ts +16 -0
  155. package/dist/shared/in-memory-activity-logger.d.ts +11 -0
  156. package/dist/shared/in-memory-notification-service.d.ts +11 -0
  157. package/dist/shared/in-memory-seed.repository.d.ts +18 -0
  158. package/dist/shared/media.repository.d1.d.ts +35 -0
  159. package/dist/shared/qstash-notification-service.d.ts +18 -0
  160. package/dist/shared/query-utils.d.ts +36 -0
  161. package/dist/shared/request-utils.d.ts +13 -0
  162. package/dist/shared/schema-mutator.d1.d.ts +12 -0
  163. package/dist/shared/seed-layout.repository.d1.d.ts +9 -0
  164. package/dist/shared/seed-registry-cache.d.ts +12 -0
  165. package/dist/shared/seed.repository.d1.d.ts +13 -0
  166. package/dist/shared/sequential-id-generator.d.ts +13 -0
  167. package/dist/shared/site-settings.repository.d1.d.ts +7 -0
  168. package/dist/shared/storage/factory.d.ts +8 -0
  169. package/dist/shared/storage/s3-bucket.d.ts +43 -0
  170. package/dist/shared/storage-utils.d.ts +7 -0
  171. package/dist/shared/system-stats.repository.d1.d.ts +25 -0
  172. package/dist/types.d.ts +85 -0
  173. package/dist/upload.d.ts +16 -0
  174. package/dist/widget.d.ts +7 -0
  175. package/migrations/0000_v040_base.sql +265 -265
  176. package/migrations/0029_automations.sql +14 -14
  177. package/migrations/0030_test_seeds.sql +125 -125
  178. package/package.json +27 -18
  179. package/assets/dashboard/assets/index-BSjk0Sx9.js +0 -634
  180. package/assets/dashboard/assets/index-kRCYVN2B.css +0 -1
  181. package/src/auth/__fixtures__/in-memory-hash-provider.ts +0 -17
  182. package/src/auth/__fixtures__/static-token-service.ts +0 -22
  183. package/src/auth/bcrypt-hash-provider.ts +0 -24
  184. package/src/auth/constants.ts +0 -14
  185. package/src/auth/generate-refresh-token.test.ts +0 -23
  186. package/src/auth/hash-provider.test.ts +0 -55
  187. package/src/auth/jose-token-service.ts +0 -62
  188. package/src/auth/jwt-claims-passthrough.test.ts +0 -87
  189. package/src/auth/login.test.ts +0 -100
  190. package/src/auth/login.ts +0 -78
  191. package/src/auth/refresh.ts +0 -11
  192. package/src/auth/token-service.test.ts +0 -90
  193. package/src/factory.ts +0 -368
  194. package/src/features/automations/__tests__/action-executors.test.ts +0 -255
  195. package/src/features/automations/__tests__/automation-runner.test.ts +0 -196
  196. package/src/features/automations/__tests__/automation-runner.utils.test.ts +0 -60
  197. package/src/features/automations/__tests__/automations.handler.test.ts +0 -264
  198. package/src/features/automations/__tests__/automations.repository.test.ts +0 -163
  199. package/src/features/automations/__tests__/automations.schema.test.ts +0 -224
  200. package/src/features/automations/__tests__/context-resolver.test.ts +0 -126
  201. package/src/features/automations/__tests__/cron-runner.test.ts +0 -267
  202. package/src/features/automations/__tests__/cron-runner.utils.test.ts +0 -144
  203. package/src/features/automations/__tests__/set-variable.executor.test.ts +0 -383
  204. package/src/features/automations/__tests__/template-grammar.test.ts +0 -308
  205. package/src/features/automations/__tests__/webhook.executor.test.ts +0 -142
  206. package/src/features/automations/__tests__/when-evaluator.test.ts +0 -274
  207. package/src/features/automations/__tests__/when-pushdown.test.ts +0 -281
  208. package/src/features/automations/action-executors/create-entry.executor.ts +0 -27
  209. package/src/features/automations/action-executors/edit-field.executor.ts +0 -26
  210. package/src/features/automations/action-executors/index.ts +0 -37
  211. package/src/features/automations/action-executors/send-mail.executor.ts +0 -53
  212. package/src/features/automations/action-executors/set-variable.executor.ts +0 -159
  213. package/src/features/automations/action-executors/webhook.executor.ts +0 -67
  214. package/src/features/automations/automation-runner.ts +0 -85
  215. package/src/features/automations/automation-runner.utils.ts +0 -47
  216. package/src/features/automations/automations.handler.ts +0 -197
  217. package/src/features/automations/automations.schema.ts +0 -177
  218. package/src/features/automations/context-resolver.ts +0 -152
  219. package/src/features/automations/cron-runner.ts +0 -140
  220. package/src/features/automations/cron-runner.utils.ts +0 -44
  221. package/src/features/automations/filter-translation.ts +0 -46
  222. package/src/features/automations/index.ts +0 -16
  223. package/src/features/automations/template-grammar.ts +0 -245
  224. package/src/features/automations/var-access-resolver.ts +0 -140
  225. package/src/features/automations/when-evaluator.ts +0 -87
  226. package/src/features/automations/when-pushdown.ts +0 -57
  227. package/src/features/backrefs/__tests__/backrefs.handler.test.ts +0 -359
  228. package/src/features/backrefs/backrefs.handler.ts +0 -168
  229. package/src/features/backrefs/d1-backref.repository.ts +0 -84
  230. package/src/features/backrefs/index.ts +0 -5
  231. package/src/features/content/constants.ts +0 -16
  232. package/src/features/content/handlers/bulk.handler.ts +0 -185
  233. package/src/features/content/handlers/create.ts +0 -129
  234. package/src/features/content/handlers/delete.ts +0 -62
  235. package/src/features/content/handlers/facets.ts +0 -49
  236. package/src/features/content/handlers/get.ts +0 -120
  237. package/src/features/content/handlers/helpers.test.ts +0 -180
  238. package/src/features/content/handlers/helpers.ts +0 -93
  239. package/src/features/content/handlers/list.ts +0 -174
  240. package/src/features/content/handlers/update.ts +0 -174
  241. package/src/features/content/index.ts +0 -26
  242. package/src/features/draft/draft.handler.ts +0 -195
  243. package/src/features/draft/draft.middleware.ts +0 -66
  244. package/src/features/draft/index.ts +0 -5
  245. package/src/features/email/email.service.ts +0 -98
  246. package/src/features/email/email.types.ts +0 -119
  247. package/src/features/email/providers/resend.ts +0 -67
  248. package/src/features/email/providers/smtp.ts +0 -55
  249. package/src/features/email/templates/automation-mail.ts +0 -19
  250. package/src/features/email/templates/password-changed.ts +0 -63
  251. package/src/features/email/templates/password-reset.ts +0 -68
  252. package/src/features/email/templates/shell.ts +0 -96
  253. package/src/features/notifications/index.ts +0 -5
  254. package/src/features/notifications/notifications.handler.ts +0 -105
  255. package/src/features/password-reset/index.ts +0 -19
  256. package/src/features/password-reset/request.ts +0 -92
  257. package/src/features/password-reset/reset.ts +0 -102
  258. package/src/features/rotate-field/index.ts +0 -5
  259. package/src/features/rotate-field/rotate-field.handler.ts +0 -132
  260. package/src/features/rotate-field/rotate-field.schema.ts +0 -17
  261. package/src/features/schema/schema.handler.ts +0 -131
  262. package/src/features/seeds/index.ts +0 -5
  263. package/src/features/seeds/seeds.handler.test.ts +0 -632
  264. package/src/features/seeds/seeds.handler.ts +0 -693
  265. package/src/features/settings/__tests__/settings.handler.test.ts +0 -555
  266. package/src/features/settings/settings.handler.ts +0 -392
  267. package/src/features/setup/index.ts +0 -204
  268. package/src/features/stats/index.ts +0 -5
  269. package/src/features/stats/stats.handler.ts +0 -420
  270. package/src/features/webhooks/index.ts +0 -63
  271. package/src/index.ts +0 -65
  272. package/src/media-utils.ts +0 -82
  273. package/src/middleware/auth-providers.middleware.ts +0 -45
  274. package/src/middleware/observability.middleware.ts +0 -70
  275. package/src/middleware/rate-limit.middleware.ts +0 -45
  276. package/src/middleware/repository.middleware.ts +0 -114
  277. package/src/middleware/seed-registry.middleware.test.ts +0 -97
  278. package/src/middleware/seed-registry.middleware.ts +0 -21
  279. package/src/middleware/storage.middleware.ts +0 -25
  280. package/src/middleware.ts +0 -45
  281. package/src/public/access-policy.ts +0 -27
  282. package/src/public/api-key-middleware.ts +0 -57
  283. package/src/public/cache-utils.ts +0 -38
  284. package/src/public/entry-projection.ts +0 -46
  285. package/src/public/idempotency.ts +0 -23
  286. package/src/public/index.ts +0 -16
  287. package/src/public/problem-details.ts +0 -124
  288. package/src/public/public-add.ts +0 -114
  289. package/src/public/public-edit.ts +0 -163
  290. package/src/public/public-errors.ts +0 -19
  291. package/src/public/public-read.ts +0 -63
  292. package/src/public/public-routes.ts +0 -88
  293. package/src/public/query-builder.test.ts +0 -224
  294. package/src/public/query-builder.ts +0 -156
  295. package/src/public/rate-limit-middleware.ts +0 -34
  296. package/src/public/read-list.ts +0 -54
  297. package/src/public/read-single.ts +0 -48
  298. package/src/public/response-builder.ts +0 -30
  299. package/src/public/sanitize.ts +0 -69
  300. package/src/public/slug-utils.ts +0 -18
  301. package/src/rate-limit/cloudflare-rate-limiter.test.ts +0 -30
  302. package/src/rate-limit/cloudflare-rate-limiter.ts +0 -15
  303. package/src/rate-limit/in-memory-rate-limiter.test.ts +0 -37
  304. package/src/rate-limit/in-memory-rate-limiter.ts +0 -17
  305. package/src/rate-limit/no-op-rate-limiter.test.ts +0 -22
  306. package/src/rate-limit/no-op-rate-limiter.ts +0 -11
  307. package/src/search-utils.test.ts +0 -211
  308. package/src/search-utils.ts +0 -213
  309. package/src/search.ts +0 -65
  310. package/src/shared/apply-policies.test.ts +0 -81
  311. package/src/shared/apply-policies.ts +0 -67
  312. package/src/shared/automations.repository.d1.ts +0 -150
  313. package/src/shared/background-notification-service.test.ts +0 -62
  314. package/src/shared/background-notification-service.ts +0 -52
  315. package/src/shared/base.repository.d1.ts +0 -32
  316. package/src/shared/content-utils.test.ts +0 -165
  317. package/src/shared/content-utils.ts +0 -86
  318. package/src/shared/content.repository.d1.test.ts +0 -458
  319. package/src/shared/content.repository.d1.ts +0 -851
  320. package/src/shared/d1-activity-log.repository.test.ts +0 -140
  321. package/src/shared/d1-activity-log.repository.ts +0 -105
  322. package/src/shared/d1-activity-logger.test.ts +0 -86
  323. package/src/shared/d1-activity-logger.ts +0 -67
  324. package/src/shared/d1-analytics.repository.test.ts +0 -78
  325. package/src/shared/d1-analytics.repository.ts +0 -85
  326. package/src/shared/d1-content-scan.repository.test.ts +0 -80
  327. package/src/shared/d1-content-scan.repository.ts +0 -37
  328. package/src/shared/d1-notification.repository.test.ts +0 -128
  329. package/src/shared/d1-notification.repository.ts +0 -118
  330. package/src/shared/d1-password-reset-token.repository.test.ts +0 -81
  331. package/src/shared/d1-password-reset-token.repository.ts +0 -56
  332. package/src/shared/d1-search.repository.test.ts +0 -87
  333. package/src/shared/d1-search.repository.ts +0 -88
  334. package/src/shared/d1-session.repository.test.ts +0 -125
  335. package/src/shared/d1-session.repository.ts +0 -102
  336. package/src/shared/d1-setup-checklist.repository.ts +0 -36
  337. package/src/shared/d1-user.repository.test.ts +0 -151
  338. package/src/shared/d1-user.repository.ts +0 -119
  339. package/src/shared/d1-widget.repository.test.ts +0 -221
  340. package/src/shared/d1-widget.repository.ts +0 -341
  341. package/src/shared/demo-data-sql.ts +0 -54
  342. package/src/shared/demo-data.repository.d1.ts +0 -20
  343. package/src/shared/execution-context-scheduler.ts +0 -13
  344. package/src/shared/fixed-clock.ts +0 -25
  345. package/src/shared/fts-sync.ts +0 -8
  346. package/src/shared/idempotency.repository.d1.test.ts +0 -83
  347. package/src/shared/idempotency.repository.d1.ts +0 -60
  348. package/src/shared/in-memory-activity-logger.ts +0 -19
  349. package/src/shared/in-memory-notification-service.ts +0 -19
  350. package/src/shared/in-memory-seed.repository.ts +0 -51
  351. package/src/shared/media.repository.d1.test.ts +0 -107
  352. package/src/shared/media.repository.d1.ts +0 -68
  353. package/src/shared/qstash-notification-service.test.ts +0 -67
  354. package/src/shared/qstash-notification-service.ts +0 -55
  355. package/src/shared/query-utils.ts +0 -141
  356. package/src/shared/request-utils.ts +0 -26
  357. package/src/shared/schema-mutator.d1.ts +0 -64
  358. package/src/shared/seed-layout.repository.d1.test.ts +0 -114
  359. package/src/shared/seed-layout.repository.d1.ts +0 -62
  360. package/src/shared/seed-registry-cache.test.ts +0 -68
  361. package/src/shared/seed-registry-cache.ts +0 -49
  362. package/src/shared/seed.repository.d1.test.ts +0 -143
  363. package/src/shared/seed.repository.d1.ts +0 -98
  364. package/src/shared/sequential-id-generator.ts +0 -33
  365. package/src/shared/site-settings.repository.d1.ts +0 -53
  366. package/src/shared/storage/factory.ts +0 -41
  367. package/src/shared/storage/s3-bucket.ts +0 -195
  368. package/src/shared/storage-utils.ts +0 -40
  369. package/src/shared/system-stats.repository.d1.test.ts +0 -58
  370. package/src/shared/system-stats.repository.d1.ts +0 -48
  371. package/src/types.ts +0 -87
  372. package/src/upload.ts +0 -198
  373. package/src/widget.ts +0 -212
@@ -1,224 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import { describe, it, expect } from 'vitest'
6
- import {
7
- parsePublicFilter,
8
- toEngineFilters,
9
- parsePublicPagination,
10
- parseLatestCount,
11
- } from './query-builder'
12
- import type { Seed } from '@beechcms/core'
13
-
14
- const SEED = {
15
- slug: 'posts',
16
- displayNameAlias: 'title',
17
- branches: [
18
- { id: 'br_01', alias: 'title', type: 'text' },
19
- { id: 'br_02', alias: 'count', type: 'number' },
20
- { id: 'br_03', alias: 'active', type: 'boolean' },
21
- { id: 'br_04', alias: 'published_at', type: 'date' },
22
- { id: 'br_05', alias: 'tags', type: 'tags' },
23
- { id: 'br_06', alias: 'body', type: 'richtext' },
24
- { id: 'br_07', alias: 'attachment', type: 'file' },
25
- { id: 'br_08', alias: 'meta', type: 'json' },
26
- ],
27
- } as unknown as Seed
28
-
29
- // ─── parsePublicFilter ────────────────────────────────────────────────────────
30
-
31
- describe('parsePublicFilter', () => {
32
- it('returns null for undefined input', () => {
33
- expect(parsePublicFilter(undefined)).toBeNull()
34
- })
35
-
36
- it('returns null for empty string', () => {
37
- expect(parsePublicFilter('')).toBeNull()
38
- })
39
-
40
- it('parses a valid filter with explicit AND logic', () => {
41
- const raw = JSON.stringify({ logic: 'AND', where: [{ field: 'title', op: 'eq', value: 'Hello' }] })
42
- const result = parsePublicFilter(raw)!
43
- expect(result.logic).toBe('AND')
44
- expect(result.where).toHaveLength(1)
45
- expect(result.where[0]).toEqual({ field: 'title', op: 'eq', value: 'Hello' })
46
- })
47
-
48
- it('defaults logic to AND when omitted', () => {
49
- const raw = JSON.stringify({ where: [{ field: 'title', op: 'contains', value: 'x' }] })
50
- expect(parsePublicFilter(raw)!.logic).toBe('AND')
51
- })
52
-
53
- it('accepts case-insensitive logic value', () => {
54
- const raw = JSON.stringify({ logic: 'or', where: [] })
55
- expect(parsePublicFilter(raw)!.logic).toBe('OR')
56
- })
57
-
58
- it('throws for malformed JSON', () => {
59
- expect(() => parsePublicFilter('{not-json')).toThrow('malformed JSON')
60
- })
61
-
62
- it('throws when parsed value is not an object', () => {
63
- expect(() => parsePublicFilter('"a string"')).toThrow('object expected')
64
- })
65
-
66
- it('throws for an invalid logic value', () => {
67
- const raw = JSON.stringify({ logic: 'BOTH', where: [] })
68
- expect(() => parsePublicFilter(raw)).toThrow("'AND' or 'OR'")
69
- })
70
-
71
- it('throws for an unknown operator in a where condition', () => {
72
- const raw = JSON.stringify({ where: [{ field: 'title', op: 'like', value: 'x' }] })
73
- expect(() => parsePublicFilter(raw)).toThrow("unknown operator 'like'")
74
- })
75
-
76
- it('throws when where is not an array', () => {
77
- const raw = JSON.stringify({ where: { field: 'title', op: 'eq' } })
78
- expect(() => parsePublicFilter(raw)).toThrow("'where' must be an array")
79
- })
80
-
81
- it('filters out null conditions from where (missing field/op)', () => {
82
- const raw = JSON.stringify({ where: [null, { field: 'title', op: 'eq', value: 'x' }] })
83
- const result = parsePublicFilter(raw)!
84
- expect(result.where).toHaveLength(1)
85
- })
86
-
87
- it('accepts all valid operators without throwing', () => {
88
- const operators = ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'contains', 'not_contains',
89
- 'starts_with', 'ends_with', 'is_empty', 'is_not_empty', 'in', 'not_in',
90
- 'has_tag', 'has_any_tag', 'has_all_tags']
91
- for (const op of operators) {
92
- const raw = JSON.stringify({ where: [{ field: 'title', op, value: 'x' }] })
93
- expect(() => parsePublicFilter(raw)).not.toThrow()
94
- }
95
- })
96
- })
97
-
98
- // ─── toEngineFilters ──────────────────────────────────────────────────────────
99
-
100
- describe('toEngineFilters', () => {
101
- it('returns [] for null filter', () => {
102
- expect(toEngineFilters(SEED, null)).toEqual([])
103
- })
104
-
105
- it('returns [] when where array is empty', () => {
106
- expect(toEngineFilters(SEED, { where: [], logic: 'AND' })).toEqual([])
107
- })
108
-
109
- it('maps text branch to FilterType "text"', () => {
110
- const result = toEngineFilters(SEED, { where: [{ field: 'title', op: 'eq', value: 'Hi' }], logic: 'AND' })
111
- expect(result[0].type).toBe('text')
112
- })
113
-
114
- it('maps number branch to FilterType "number"', () => {
115
- const result = toEngineFilters(SEED, { where: [{ field: 'count', op: 'gt', value: 5 }], logic: 'AND' })
116
- expect(result[0].type).toBe('number')
117
- })
118
-
119
- it('maps boolean branch to FilterType "boolean"', () => {
120
- const result = toEngineFilters(SEED, { where: [{ field: 'active', op: 'eq', value: true }], logic: 'AND' })
121
- expect(result[0].type).toBe('boolean')
122
- })
123
-
124
- it('maps date branch to FilterType "date"', () => {
125
- const result = toEngineFilters(SEED, { where: [{ field: 'published_at', op: 'gt', value: '2024-01-01' }], logic: 'AND' })
126
- expect(result[0].type).toBe('date')
127
- })
128
-
129
- it('maps tags branch to FilterType "tags"', () => {
130
- const result = toEngineFilters(SEED, { where: [{ field: 'tags', op: 'has_tag', value: 'news' }], logic: 'AND' })
131
- expect(result[0].type).toBe('tags')
132
- })
133
-
134
- it('maps richtext branch to FilterType "text"', () => {
135
- const result = toEngineFilters(SEED, { where: [{ field: 'body', op: 'contains', value: 'x' }], logic: 'AND' })
136
- expect(result[0].type).toBe('text')
137
- })
138
-
139
- it('maps file branch to FilterType "text"', () => {
140
- const result = toEngineFilters(SEED, { where: [{ field: 'attachment', op: 'contains', value: 'url' }], logic: 'AND' })
141
- expect(result[0].type).toBe('text')
142
- })
143
-
144
- it('maps json branch to FilterType "json"', () => {
145
- const result = toEngineFilters(SEED, { where: [{ field: 'meta', op: 'eq', value: '{}' }], logic: 'AND' })
146
- expect(result[0].type).toBe('json')
147
- })
148
-
149
- it('maps system columns (id, slug, status) to FilterType "system"', () => {
150
- for (const field of ['id', 'slug', 'status', 'created_at', 'updated_at']) {
151
- const result = toEngineFilters(SEED, { where: [{ field, op: 'eq', value: 'x' }], logic: 'AND' })
152
- expect(result[0].type).toBe('system')
153
- }
154
- })
155
-
156
- it('maps unknown fields to FilterType "text"', () => {
157
- const result = toEngineFilters(SEED, { where: [{ field: 'ghost_field', op: 'eq', value: 'x' }], logic: 'AND' })
158
- expect(result[0].type).toBe('text')
159
- })
160
-
161
- it('produces one FilterGroup per condition', () => {
162
- const filter = {
163
- where: [
164
- { field: 'title', op: 'eq' as const, value: 'A' },
165
- { field: 'count', op: 'gt' as const, value: 5 },
166
- ],
167
- logic: 'AND' as const,
168
- }
169
- expect(toEngineFilters(SEED, filter)).toHaveLength(2)
170
- })
171
-
172
- it('includes column and conditions in each FilterGroup', () => {
173
- const filter = { where: [{ field: 'title', op: 'contains' as const, value: 'hi' }], logic: 'AND' as const }
174
- const [group] = toEngineFilters(SEED, filter)
175
- expect(group.column).toBe('title')
176
- expect(group.conditions[0].op).toBe('contains')
177
- expect(group.conditions[0].value).toBe('hi')
178
- })
179
- })
180
-
181
- // ─── parsePublicPagination ────────────────────────────────────────────────────
182
-
183
- describe('parsePublicPagination', () => {
184
- it('defaults to page=1 and limit=25 when input is empty', () => {
185
- expect(parsePublicPagination({})).toEqual({ page: 1, limit: 25 })
186
- })
187
-
188
- it('parses valid page and limit values', () => {
189
- expect(parsePublicPagination({ page: '3', limit: '10' })).toEqual({ page: 3, limit: 10 })
190
- })
191
-
192
- it('clamps limit to a maximum of 100', () => {
193
- expect(parsePublicPagination({ limit: '500' }).limit).toBe(100)
194
- })
195
-
196
- it('uses default for invalid (non-numeric) input', () => {
197
- expect(parsePublicPagination({ page: 'abc', limit: 'xyz' })).toEqual({ page: 1, limit: 25 })
198
- })
199
- })
200
-
201
- // ─── parseLatestCount ─────────────────────────────────────────────────────────
202
-
203
- describe('parseLatestCount', () => {
204
- it('returns 10 for undefined', () => {
205
- expect(parseLatestCount(undefined)).toBe(10)
206
- })
207
-
208
- it('parses a valid integer string', () => {
209
- expect(parseLatestCount('5')).toBe(5)
210
- })
211
-
212
- it('clamps to 1 for values below minimum', () => {
213
- expect(parseLatestCount('0')).toBe(1)
214
- expect(parseLatestCount('-5')).toBe(1)
215
- })
216
-
217
- it('clamps to 100 for values above maximum', () => {
218
- expect(parseLatestCount('200')).toBe(100)
219
- })
220
-
221
- it('returns 10 for non-numeric input', () => {
222
- expect(parseLatestCount('abc')).toBe(10)
223
- })
224
- })
@@ -1,156 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import type { Seed, FilterGroup, FilterOperator, FilterType, BranchType } from '@beechcms/core'
6
- import { parsePositiveInt } from '../shared/query-utils'
7
-
8
- export type PublicQueryInput = {
9
- page?: string
10
- limit?: string
11
- latest?: string
12
- }
13
-
14
- export type PublicFilterLogic = 'AND' | 'OR'
15
- export type PublicFilterOperator =
16
- | 'eq'
17
- | 'neq'
18
- | 'gt'
19
- | 'gte'
20
- | 'lt'
21
- | 'lte'
22
- | 'contains'
23
- | 'not_contains'
24
- | 'starts_with'
25
- | 'ends_with'
26
- | 'is_empty'
27
- | 'is_not_empty'
28
- | 'in'
29
- | 'not_in'
30
- | 'has_tag'
31
- | 'has_any_tag'
32
- | 'has_all_tags'
33
-
34
- export type PublicFilterCondition = {
35
- field: string
36
- op: PublicFilterOperator
37
- value?: unknown
38
- }
39
-
40
- export type ParsedPublicFilter = {
41
- where: PublicFilterCondition[]
42
- logic: PublicFilterLogic
43
- }
44
-
45
- const PUBLIC_FILTER_OPERATORS = new Set<PublicFilterOperator>([
46
- 'eq', 'neq', 'gt', 'gte', 'lt', 'lte',
47
- 'contains', 'not_contains', 'starts_with', 'ends_with',
48
- 'is_empty', 'is_not_empty', 'in', 'not_in',
49
- 'has_tag', 'has_any_tag', 'has_all_tags',
50
- ])
51
-
52
- function asString(value: unknown): string | null {
53
- return typeof value === 'string' && value.trim() ? value.trim() : null
54
- }
55
-
56
- function validateLogic(logicRaw: unknown): PublicFilterLogic {
57
- if (logicRaw === undefined) return 'AND'
58
- if (typeof logicRaw !== 'string') throw new TypeError("Invalid filter: 'logic' must be 'AND' or 'OR'")
59
- const normalized = logicRaw.toUpperCase()
60
- if (normalized !== 'AND' && normalized !== 'OR') throw new TypeError("Invalid filter: 'logic' must be 'AND' or 'OR'")
61
- return normalized
62
- }
63
-
64
- function parseWhereCondition(raw: unknown): PublicFilterCondition | null {
65
- if (!raw || typeof raw !== 'object') return null
66
- const maybe = raw as Record<string, unknown>
67
- const field = asString(maybe.field)
68
- const opRaw = asString(maybe.op)
69
- if (!field || !opRaw || !PUBLIC_FILTER_OPERATORS.has(opRaw as PublicFilterOperator)) {
70
- throw new TypeError(`Invalid filter: unknown operator '${opRaw ?? 'undefined'}'`)
71
- }
72
- return { field, op: opRaw as PublicFilterOperator, value: maybe.value }
73
- }
74
-
75
- export function parsePublicFilter(raw: string | undefined): ParsedPublicFilter | null {
76
- if (!raw) return null
77
- let parsed: unknown
78
- try {
79
- parsed = JSON.parse(raw)
80
- } catch {
81
- throw new TypeError('Invalid filter: malformed JSON')
82
- }
83
- if (!parsed || typeof parsed !== 'object') throw new TypeError('Invalid filter: object expected')
84
- const filterObj = parsed as Record<string, unknown>
85
- const logic = validateLogic(filterObj.logic)
86
- if (!Array.isArray(filterObj.where)) throw new TypeError("Invalid filter: 'where' must be an array")
87
- const where = filterObj.where
88
- .map(parseWhereCondition)
89
- .filter((item): item is PublicFilterCondition => item !== null)
90
- return { where, logic }
91
- }
92
-
93
- const SYSTEM_COLUMNS = new Set(['id', 'slug', 'status', 'created_at', 'updated_at'])
94
-
95
- function mapBranchToFilterType(type: BranchType): FilterType {
96
- switch (type) {
97
- case 'richtext':
98
- case 'file':
99
- return 'text'
100
- case 'json':
101
- return 'json'
102
- case 'tags':
103
- return 'tags'
104
- case 'number':
105
- return 'number'
106
- case 'boolean':
107
- return 'boolean'
108
- case 'date':
109
- return 'date'
110
- case 'text':
111
- default:
112
- return 'text'
113
- }
114
- }
115
-
116
- /**
117
- * Trasforma il filtro pubblico in FilterGroup[] per il Repository.
118
- * Zero SQL: la logica di generazione query risiede esclusivamente nel Repository/Engine core.
119
- */
120
- export function toEngineFilters(seed: Seed, parsedFilter: ParsedPublicFilter | null): FilterGroup[] {
121
- if (!parsedFilter || parsedFilter.where.length === 0) return []
122
-
123
- // Note: Repository currently joins groups with AND.
124
- // Public API supports logic: OR but the core engine currently defaults to AND for top-level groups.
125
- // We map each condition to a group for maximum compatibility with the engine's buildFilterCondition.
126
- return parsedFilter.where.map((cond) => {
127
- const branch = seed.branches.find(b => b.alias === cond.field)
128
- const type: FilterType = branch
129
- ? mapBranchToFilterType(branch.type)
130
- : (SYSTEM_COLUMNS.has(cond.field) ? 'system' : 'text')
131
-
132
- return {
133
- column: cond.field,
134
- type,
135
- conditions: [{
136
- op: cond.op as FilterOperator,
137
- value: cond.value as any
138
- }]
139
- }
140
- })
141
- }
142
-
143
- export function parsePublicPagination(input: PublicQueryInput): { page: number; limit: number } {
144
- const page = parsePositiveInt(input.page, 1)
145
- const limit = Math.min(parsePositiveInt(input.limit, 25), 100)
146
- return { page, limit }
147
- }
148
-
149
- export function parseLatestCount(latest: string | undefined): number {
150
- if (!latest) return 10
151
- const raw = Number.parseInt(latest, 10)
152
- const parsed = Number.isNaN(raw) ? 10 : raw
153
- if (parsed < 1) return 1
154
- if (parsed > 100) return 100
155
- return parsed
156
- }
@@ -1,34 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import type { Context, Next } from 'hono'
6
- import type { AppEnv } from '../types'
7
- import { publicProblem } from './problem-details'
8
- import { getClientIp } from '../shared/request-utils'
9
-
10
- function isReadMethod(method: string): boolean {
11
- return method === 'GET' || method === 'HEAD' || method === 'OPTIONS'
12
- }
13
-
14
- export function publicRateLimitMiddleware() {
15
- return async (c: Context<AppEnv>, next: Next): Promise<Response | void> => {
16
- const readMethod = isReadMethod(c.req.method)
17
- const limiterName = readMethod ? ('publicApiRead' as const) : ('publicApiWrite' as const)
18
-
19
- const seed = c.req.param('seed') ?? 'no-seed'
20
- const key = `${getClientIp(c.req)}:${seed}:${limiterName}`
21
- const result = await c.get('rateLimiters').getLimiter(limiterName).checkLimit(key)
22
-
23
- if (!result.isAllowed) {
24
- return publicProblem(c, {
25
- type: 'rate-limit-exceeded',
26
- title: 'Too Many Requests',
27
- status: 429,
28
- detail: 'Too many requests',
29
- })
30
- }
31
-
32
- await next()
33
- }
34
- }
@@ -1,54 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import type { Seed, ContentRepository } from '@beechcms/core'
6
- import { cleanStr } from '../shared/query-utils'
7
- import { toFlatPublicEntry } from './entry-projection'
8
- import { buildPublicListMeta } from './response-builder'
9
- import { parsePublicFilter, parsePublicPagination, parseLatestCount, toEngineFilters } from './query-builder'
10
-
11
- type ReadListInput = {
12
- seed: Seed
13
- seedSlug: string
14
- repository: ContentRepository
15
- query: Record<string, string | undefined>
16
- publishedOnly: boolean
17
- }
18
-
19
- export async function readListEntries(input: ReadListInput) {
20
- const { seed, seedSlug, repository, query, publishedOnly } = input
21
-
22
- const parsedFilter = parsePublicFilter(query.filter)
23
- const allMode = cleanStr(query.all)?.toLowerCase() === 'true'
24
- const latestMode = cleanStr(query.latest) !== null
25
- const latestCount = latestMode ? parseLatestCount(query.latest ?? '') : null
26
- const pagination = allMode ? { page: 1, limit: 100 } : parsePublicPagination(query)
27
- const offset = (pagination.page - 1) * pagination.limit
28
- const search = cleanStr(query.search) ?? ''
29
- const engineFilters = toEngineFilters(seed, parsedFilter)
30
- const sortBy = cleanStr(query.orderBy) ?? 'created_at'
31
- const sortDir = (cleanStr(query.orderDir) ?? 'desc').toLowerCase() === 'asc' ? 'ASC' : 'DESC'
32
-
33
- const { items, total } = await repository.findMany(seed, {
34
- filters: engineFilters,
35
- search: search || undefined,
36
- status: publishedOnly ? 'published' : null,
37
- pagination: {
38
- limit: latestMode ? (latestCount ?? 10) : pagination.limit,
39
- offset: latestMode ? 0 : offset,
40
- },
41
- orderBy: latestMode ? { column: 'created_at', dir: 'DESC' } : { column: sortBy, dir: sortDir },
42
- })
43
-
44
- const data = items.map(item => toFlatPublicEntry(item, seed, query.fields))
45
-
46
- if (latestMode) {
47
- return { data, meta: { total, returned: data.length, seed: seedSlug } }
48
- }
49
-
50
- return {
51
- data,
52
- meta: buildPublicListMeta({ total, page: pagination.page, limit: pagination.limit, returned: data.length, seed: seedSlug }),
53
- }
54
- }
@@ -1,48 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import { EntryNotFoundError } from '@beechcms/core'
6
- import type { Seed, ContentRepository } from '@beechcms/core'
7
- import { toFlatPublicEntry } from './entry-projection'
8
- import { buildPublicSingleMeta } from './response-builder'
9
-
10
- type ReadSingleInput = {
11
- seed: Seed
12
- seedSlug: string
13
- repository: ContentRepository
14
- id: string | null
15
- slug: string | null
16
- publishedOnly: boolean
17
- fieldsParam?: string
18
- }
19
-
20
- export type ReadSingleResult =
21
- | { ok: true; data: Record<string, unknown>; meta: { seed: string } }
22
- | { ok: false; detail: string }
23
-
24
- export async function readSingleEntry(input: ReadSingleInput): Promise<ReadSingleResult> {
25
- const { seed, seedSlug, repository, id, slug, publishedOnly, fieldsParam } = input
26
- const label = id ?? slug!
27
-
28
- try {
29
- const entry = id
30
- ? await repository.findById(seed, id)
31
- : await repository.findBySlug(seed, slug!)
32
-
33
- if (publishedOnly && entry.status !== 'published') {
34
- return { ok: false, detail: `Entry '${label}' not found or not published.` }
35
- }
36
-
37
- return {
38
- ok: true,
39
- data: toFlatPublicEntry(entry, seed, fieldsParam),
40
- meta: buildPublicSingleMeta(seedSlug),
41
- }
42
- } catch (error) {
43
- if (error instanceof EntryNotFoundError) {
44
- return { ok: false, detail: `Entry '${label}' not found for content type '${seedSlug}'.` }
45
- }
46
- throw error
47
- }
48
- }
@@ -1,30 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- /**
6
- * Helper meta per risposta lista Public API.
7
- */
8
- export function buildPublicListMeta(input: {
9
- total: number
10
- page: number
11
- limit: number
12
- returned: number
13
- seed: string
14
- }) {
15
- return {
16
- total: input.total,
17
- page: input.page,
18
- limit: input.limit,
19
- returned: input.returned,
20
- seed: input.seed,
21
- }
22
- }
23
-
24
- /**
25
- * Helper meta per risposta singolo elemento Public API.
26
- */
27
- export function buildPublicSingleMeta(seed: string) {
28
- return { seed }
29
- }
30
-
@@ -1,69 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import { validateAndSanitizeSeedPayload } from '@beechcms/core'
6
- import type { Seed, ValidationDetail } from '@beechcms/core'
7
-
8
- type PublicSanitizeSuccess = {
9
- ok: true
10
- data: Record<string, unknown>
11
- }
12
-
13
- type PublicSanitizeFailure = {
14
- ok: false
15
- status: 400 | 422
16
- code: 'validation_failed' | 'dangerous_content'
17
- message: string
18
- details?: ValidationDetail[]
19
- }
20
-
21
- export type PublicSanitizeResult = PublicSanitizeSuccess | PublicSanitizeFailure
22
-
23
- /**
24
- * Public API Adapter: uses the core foundation and maps errors into the sprint format.
25
- */
26
- export function sanitizePublicPayload(
27
- seed: Seed,
28
- payload: Record<string, unknown>,
29
- options: {
30
- allowNull?: boolean
31
- operation?: 'create' | 'update'
32
- requireAtLeastOneValidField?: boolean
33
- enforceRequiredFields?: boolean
34
- } = {}
35
- ): PublicSanitizeResult {
36
- const operation = options.operation ?? 'create'
37
- const result = validateAndSanitizeSeedPayload(seed, payload, {
38
- allowNull: options.allowNull ?? false,
39
- operation,
40
- requireAtLeastOneValidField: options.requireAtLeastOneValidField ?? true,
41
- enforceRequiredFields: options.enforceRequiredFields ?? true,
42
- })
43
-
44
- if (result.dangerousFields.length > 0) {
45
- const field = result.dangerousFields[0]
46
- return {
47
- ok: false,
48
- status: 422,
49
- code: 'dangerous_content',
50
- message: `Content rejected: dangerous markup detected in field '${field}'`,
51
- }
52
- }
53
-
54
- if (result.details.length > 0) {
55
- return {
56
- ok: false,
57
- status: 400,
58
- code: 'validation_failed',
59
- message: 'Validation failed',
60
- details: result.details,
61
- }
62
- }
63
-
64
- return {
65
- ok: true,
66
- data: result.data,
67
- }
68
- }
69
-
@@ -1,18 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import { slugify, generateEntrySlug } from '@beechcms/core'
6
-
7
- /**
8
- * Converts a string into a URL-safe slug.
9
- * Logic moved to @beechcms/core for consistency between Dashboard and API.
10
- */
11
- export { slugify }
12
-
13
- /**
14
- * Generates a slug from a title/name or a UUID-like fallback.
15
- * Logic moved to @beechcms/core for consistency between Dashboard and API.
16
- */
17
- export { generateEntrySlug }
18
-
@@ -1,30 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- import { describe, it, expect, vi } from 'vitest'
6
- import { CloudflareRateLimiter } from './cloudflare-rate-limiter'
7
-
8
- describe('CloudflareRateLimiter', () => {
9
- it('returns isAllowed: true when the Cloudflare binding grants the request', async () => {
10
- const mockBinding = { limit: vi.fn().mockResolvedValue({ success: true }) }
11
- const limiter = new CloudflareRateLimiter(mockBinding as any)
12
- const result = await limiter.checkLimit('192.168.1.1:login')
13
- expect(result.isAllowed).toBe(true)
14
- })
15
-
16
- it('returns isAllowed: false when the Cloudflare binding blocks the request', async () => {
17
- const mockBinding = { limit: vi.fn().mockResolvedValue({ success: false }) }
18
- const limiter = new CloudflareRateLimiter(mockBinding as any)
19
- const result = await limiter.checkLimit('192.168.1.1:login')
20
- expect(result.isAllowed).toBe(false)
21
- })
22
-
23
- it('forwards the exact key to the binding so per-key accounting is correct', async () => {
24
- const mockBinding = { limit: vi.fn().mockResolvedValue({ success: true }) }
25
- const limiter = new CloudflareRateLimiter(mockBinding as any)
26
- const key = '10.0.0.1:some-seed:publicApiRead'
27
- await limiter.checkLimit(key)
28
- expect(mockBinding.limit).toHaveBeenCalledWith({ key })
29
- })
30
- })
@@ -1,15 +0,0 @@
1
- // SPDX-License-Identifier: BUSL-1.1
2
- // Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
3
- // See LICENSE in the repository root for license terms.
4
-
5
- /// <reference types="@cloudflare/workers-types" />
6
- import type { IRateLimiter, RateLimitResult } from '@beechcms/core'
7
-
8
- export class CloudflareRateLimiter implements IRateLimiter {
9
- constructor(private readonly binding: RateLimit) {}
10
-
11
- async checkLimit(key: string): Promise<RateLimitResult> {
12
- const { success } = await this.binding.limit({ key })
13
- return { isAllowed: success }
14
- }
15
- }