emdash 0.37.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1445) hide show
  1. package/dist/action-token-On1sot_c.mjs +26 -0
  2. package/dist/action-token-On1sot_c.mjs.map +1 -0
  3. package/dist/activation-CaMfdBt1.mjs +382 -0
  4. package/dist/activation-CaMfdBt1.mjs.map +1 -0
  5. package/dist/adapters-Cq10K4_c.d.mts +171 -0
  6. package/dist/adapters-Cq10K4_c.d.mts.map +1 -0
  7. package/dist/after-PcEvMY_6.mjs +96 -0
  8. package/dist/after-PcEvMY_6.mjs.map +1 -0
  9. package/dist/allowed-origins-1Sa-2wZK.mjs +116 -0
  10. package/dist/allowed-origins-1Sa-2wZK.mjs.map +1 -0
  11. package/dist/api/route-utils.d.mts +4 -3
  12. package/dist/api/route-utils.d.mts.map +1 -1
  13. package/dist/api/route-utils.mjs +45 -29
  14. package/dist/api/route-utils.mjs.map +1 -1
  15. package/dist/api/schemas/index.d.mts +2 -2
  16. package/dist/api/schemas/index.mjs +7 -6
  17. package/dist/api-DmjKxPCY.mjs +4831 -0
  18. package/dist/api-DmjKxPCY.mjs.map +1 -0
  19. package/dist/api-tokens-BIXItFKV.mjs +163 -0
  20. package/dist/api-tokens-BIXItFKV.mjs.map +1 -0
  21. package/dist/apply-drpfmqrR.mjs +1005 -0
  22. package/dist/apply-drpfmqrR.mjs.map +1 -0
  23. package/dist/artifact-fetch-COiMhVgk.mjs +813 -0
  24. package/dist/artifact-fetch-COiMhVgk.mjs.map +1 -0
  25. package/dist/astro/index.d.mts +14 -12
  26. package/dist/astro/index.d.mts.map +1 -1
  27. package/dist/astro/index.mjs +123 -13
  28. package/dist/astro/index.mjs.map +1 -1
  29. package/dist/astro/middleware/auth.d.mts +12 -10
  30. package/dist/astro/middleware/auth.d.mts.map +1 -1
  31. package/dist/astro/middleware/auth.mjs +20 -11
  32. package/dist/astro/middleware/auth.mjs.map +1 -1
  33. package/dist/astro/middleware/media-usage-write-fence.mjs +5 -5
  34. package/dist/astro/middleware/redirect.mjs +11 -9
  35. package/dist/astro/middleware/redirect.mjs.map +1 -1
  36. package/dist/astro/middleware/request-context.d.mts +1 -1
  37. package/dist/astro/middleware/request-context.d.mts.map +1 -1
  38. package/dist/astro/middleware/request-context.mjs +154 -28
  39. package/dist/astro/middleware/request-context.mjs.map +1 -1
  40. package/dist/astro/middleware/setup.mjs +1 -1
  41. package/dist/astro/middleware.d.mts +13 -10
  42. package/dist/astro/middleware.d.mts.map +1 -1
  43. package/dist/astro/middleware.mjs +122 -3041
  44. package/dist/astro/middleware.mjs.map +1 -1
  45. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +10 -9
  46. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs.map +1 -1
  47. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +10 -9
  48. package/dist/astro/routes/api/admin/allowed-domains/index.mjs.map +1 -1
  49. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +5 -5
  50. package/dist/astro/routes/api/admin/api-tokens/index.mjs +6 -6
  51. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +6 -6
  52. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +13 -12
  53. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
  54. package/dist/astro/routes/api/admin/byline-fields/index.mjs +13 -12
  55. package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
  56. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +13 -12
  57. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
  58. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +22 -21
  59. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
  60. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +22 -21
  61. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -1
  62. package/dist/astro/routes/api/admin/bylines/index.mjs +22 -21
  63. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  64. package/dist/astro/routes/api/admin/comments/_id_/status.d.mts.map +1 -1
  65. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +21 -54
  66. package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
  67. package/dist/astro/routes/api/admin/comments/_id_.mjs +8 -8
  68. package/dist/astro/routes/api/admin/comments/bulk.mjs +15 -14
  69. package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
  70. package/dist/astro/routes/api/admin/comments/counts.mjs +8 -8
  71. package/dist/astro/routes/api/admin/comments/index.mjs +15 -14
  72. package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
  73. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +6 -6
  74. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +5 -5
  75. package/dist/astro/routes/api/admin/media-usage/activation.mjs +17 -16
  76. package/dist/astro/routes/api/admin/media-usage/activation.mjs.map +1 -1
  77. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +19 -18
  78. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs.map +1 -1
  79. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +19 -18
  80. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs.map +1 -1
  81. package/dist/astro/routes/api/admin/media-usage/progress.mjs +17 -17
  82. package/dist/astro/routes/api/admin/media-usage/repair.mjs +21 -20
  83. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
  84. package/dist/astro/routes/api/admin/media-usage/work/index.mjs +19 -18
  85. package/dist/astro/routes/api/admin/media-usage/work/index.mjs.map +1 -1
  86. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +19 -18
  87. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs.map +1 -1
  88. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +5 -5
  89. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +5 -5
  90. package/dist/astro/routes/api/admin/plugins/_id_/disable.d.mts.map +1 -1
  91. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +9 -66
  92. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  93. package/dist/astro/routes/api/admin/plugins/_id_/enable.d.mts.map +1 -1
  94. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +9 -69
  95. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  96. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +66 -59
  97. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  98. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +6 -6
  99. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +65 -59
  100. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
  101. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +70 -61
  102. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  103. package/dist/astro/routes/api/admin/plugins/_id_/update.d.mts.map +1 -1
  104. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +87 -63
  105. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  106. package/dist/astro/routes/api/admin/plugins/index.mjs +66 -59
  107. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  108. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +4 -4
  109. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +65 -59
  110. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  111. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.d.mts.map +1 -1
  112. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +85 -63
  113. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  114. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +65 -59
  115. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  116. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +70 -61
  117. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  118. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -1
  119. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +90 -66
  120. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  121. package/dist/astro/routes/api/admin/plugins/registry/artifact.d.mts.map +1 -1
  122. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +9 -7
  123. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  124. package/dist/astro/routes/api/admin/plugins/registry/install.d.mts.map +1 -1
  125. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +77 -63
  126. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  127. package/dist/astro/routes/api/admin/plugins/registry/verify.d.mts.map +1 -1
  128. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +67 -61
  129. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs.map +1 -1
  130. package/dist/astro/routes/api/admin/plugins/updates.d.mts.map +1 -1
  131. package/dist/astro/routes/api/admin/plugins/updates.mjs +66 -60
  132. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  133. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.d.mts +8 -0
  134. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.d.mts.map +1 -0
  135. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs +27 -0
  136. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs.map +1 -0
  137. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +65 -59
  138. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  139. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +4 -4
  140. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +65 -59
  141. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  142. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +4 -4
  143. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +3 -3
  144. package/dist/astro/routes/api/admin/users/_id_/index.mjs +11 -10
  145. package/dist/astro/routes/api/admin/users/_id_/index.mjs.map +1 -1
  146. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +5 -5
  147. package/dist/astro/routes/api/admin/users/index.mjs +10 -9
  148. package/dist/astro/routes/api/admin/users/index.mjs.map +1 -1
  149. package/dist/astro/routes/api/auth/dev-bypass.mjs +5 -5
  150. package/dist/astro/routes/api/auth/invite/accept.mjs +3 -3
  151. package/dist/astro/routes/api/auth/invite/complete.mjs +15 -14
  152. package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
  153. package/dist/astro/routes/api/auth/invite/index.mjs +12 -11
  154. package/dist/astro/routes/api/auth/invite/index.mjs.map +1 -1
  155. package/dist/astro/routes/api/auth/invite/register-options.mjs +14 -13
  156. package/dist/astro/routes/api/auth/invite/register-options.mjs.map +1 -1
  157. package/dist/astro/routes/api/auth/logout.mjs +4 -4
  158. package/dist/astro/routes/api/auth/magic-link/send.mjs +14 -13
  159. package/dist/astro/routes/api/auth/magic-link/send.mjs.map +1 -1
  160. package/dist/astro/routes/api/auth/magic-link/verify.mjs +4 -4
  161. package/dist/astro/routes/api/auth/me.mjs +11 -10
  162. package/dist/astro/routes/api/auth/me.mjs.map +1 -1
  163. package/dist/astro/routes/api/auth/mode.mjs +4 -4
  164. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +4 -4
  165. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
  166. package/dist/astro/routes/api/auth/passkey/_id_.mjs +10 -9
  167. package/dist/astro/routes/api/auth/passkey/_id_.mjs.map +1 -1
  168. package/dist/astro/routes/api/auth/passkey/index.mjs +3 -3
  169. package/dist/astro/routes/api/auth/passkey/options.mjs +16 -15
  170. package/dist/astro/routes/api/auth/passkey/options.mjs.map +1 -1
  171. package/dist/astro/routes/api/auth/passkey/register/options.mjs +14 -13
  172. package/dist/astro/routes/api/auth/passkey/register/options.mjs.map +1 -1
  173. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +15 -14
  174. package/dist/astro/routes/api/auth/passkey/register/verify.mjs.map +1 -1
  175. package/dist/astro/routes/api/auth/passkey/verify.mjs +15 -14
  176. package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
  177. package/dist/astro/routes/api/auth/signup/complete.mjs +15 -14
  178. package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
  179. package/dist/astro/routes/api/auth/signup/request.mjs +14 -13
  180. package/dist/astro/routes/api/auth/signup/request.mjs.map +1 -1
  181. package/dist/astro/routes/api/auth/signup/verify.mjs +3 -3
  182. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.d.mts.map +1 -1
  183. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +15 -211
  184. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
  185. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +18 -17
  186. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
  187. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +4 -4
  188. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.d.mts.map +1 -1
  189. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +17 -11
  190. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  191. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +5 -5
  192. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts +10 -0
  193. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts.map +1 -0
  194. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +67 -0
  195. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs.map +1 -0
  196. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +4 -4
  197. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.d.mts +8 -0
  198. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.d.mts.map +1 -0
  199. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs +35 -0
  200. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs.map +1 -0
  201. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +16 -15
  202. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs.map +1 -1
  203. package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts +9 -2
  204. package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts.map +1 -1
  205. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +28 -16
  206. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  207. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +27 -23
  208. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
  209. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +27 -23
  210. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
  211. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +5 -5
  212. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +4 -4
  213. package/dist/astro/routes/api/content/_collection_/_id_/schedule.d.mts.map +1 -1
  214. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +27 -12
  215. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  216. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +23 -20
  217. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  218. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +4 -4
  219. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.d.mts.map +1 -1
  220. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +25 -12
  221. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  222. package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
  223. package/dist/astro/routes/api/content/_collection_/_id_.mjs +27 -14
  224. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  225. package/dist/astro/routes/api/content/_collection_/authors.mjs +4 -4
  226. package/dist/astro/routes/api/content/_collection_/index.mjs +18 -12
  227. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  228. package/dist/astro/routes/api/content/_collection_/trash.mjs +11 -10
  229. package/dist/astro/routes/api/content/_collection_/trash.mjs.map +1 -1
  230. package/dist/astro/routes/api/dashboard.mjs +14 -12
  231. package/dist/astro/routes/api/dashboard.mjs.map +1 -1
  232. package/dist/astro/routes/api/dev/emails.mjs +4 -4
  233. package/dist/astro/routes/api/health.d.mts +8 -0
  234. package/dist/astro/routes/api/health.d.mts.map +1 -0
  235. package/dist/astro/routes/api/health.mjs +21 -0
  236. package/dist/astro/routes/api/health.mjs.map +1 -0
  237. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  238. package/dist/astro/routes/api/import/probe.mjs +25 -23
  239. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  240. package/dist/astro/routes/api/import/wordpress/analyze.mjs +5 -5
  241. package/dist/astro/routes/api/import/wordpress/execute.d.mts +13 -11
  242. package/dist/astro/routes/api/import/wordpress/execute.d.mts.map +1 -1
  243. package/dist/astro/routes/api/import/wordpress/execute.mjs +20 -19
  244. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  245. package/dist/astro/routes/api/import/wordpress/media.d.mts +12 -10
  246. package/dist/astro/routes/api/import/wordpress/media.d.mts.map +1 -1
  247. package/dist/astro/routes/api/import/wordpress/media.mjs +15 -14
  248. package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
  249. package/dist/astro/routes/api/import/wordpress/prepare.mjs +14 -13
  250. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  251. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +13 -11
  252. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts.map +1 -1
  253. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +18 -17
  254. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  255. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  256. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +25 -23
  257. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  258. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +1 -1
  259. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +13 -11
  260. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts.map +1 -1
  261. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +36 -33
  262. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  263. package/dist/astro/routes/api/manifest.mjs +17 -9
  264. package/dist/astro/routes/api/manifest.mjs.map +1 -1
  265. package/dist/astro/routes/api/mcp.d.mts.map +1 -1
  266. package/dist/astro/routes/api/mcp.mjs +192 -110
  267. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  268. package/dist/astro/routes/api/media/_id_/confirm.mjs +15 -14
  269. package/dist/astro/routes/api/media/_id_/confirm.mjs.map +1 -1
  270. package/dist/astro/routes/api/media/_id_/replace.mjs +12 -11
  271. package/dist/astro/routes/api/media/_id_/replace.mjs.map +1 -1
  272. package/dist/astro/routes/api/media/_id_/upload.mjs +8 -8
  273. package/dist/astro/routes/api/media/_id_/usage.mjs +23 -22
  274. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -1
  275. package/dist/astro/routes/api/media/_id_.mjs +22 -21
  276. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  277. package/dist/astro/routes/api/media/asset/_id_/_filename_.d.mts +8 -0
  278. package/dist/astro/routes/api/media/asset/_id_/_filename_.d.mts.map +1 -0
  279. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs +52 -0
  280. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs.map +1 -0
  281. package/dist/astro/routes/api/media/file/_...key_.mjs +3 -3
  282. package/dist/astro/routes/api/media/folders/_id_.mjs +12 -11
  283. package/dist/astro/routes/api/media/folders/_id_.mjs.map +1 -1
  284. package/dist/astro/routes/api/media/folders/index.mjs +12 -11
  285. package/dist/astro/routes/api/media/folders/index.mjs.map +1 -1
  286. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +4 -4
  287. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +4 -4
  288. package/dist/astro/routes/api/media/providers/index.mjs +4 -4
  289. package/dist/astro/routes/api/media/upload-url.mjs +14 -13
  290. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  291. package/dist/astro/routes/api/media.mjs +26 -25
  292. package/dist/astro/routes/api/media.mjs.map +1 -1
  293. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +15 -14
  294. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  295. package/dist/astro/routes/api/menus/_name_/items.mjs +15 -14
  296. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  297. package/dist/astro/routes/api/menus/_name_/reorder.mjs +15 -14
  298. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  299. package/dist/astro/routes/api/menus/_name_/translations.mjs +15 -14
  300. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  301. package/dist/astro/routes/api/menus/_name_.mjs +15 -14
  302. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  303. package/dist/astro/routes/api/menus/index.mjs +15 -14
  304. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  305. package/dist/astro/routes/api/oauth/authorize.mjs +6 -6
  306. package/dist/astro/routes/api/oauth/device/authorize.mjs +7 -7
  307. package/dist/astro/routes/api/oauth/device/code.mjs +10 -10
  308. package/dist/astro/routes/api/oauth/device/token.mjs +9 -9
  309. package/dist/astro/routes/api/oauth/register.mjs +4 -4
  310. package/dist/astro/routes/api/oauth/token/refresh.mjs +7 -7
  311. package/dist/astro/routes/api/oauth/token/revoke.mjs +7 -7
  312. package/dist/astro/routes/api/oauth/token.mjs +7 -7
  313. package/dist/astro/routes/api/openapi.json.mjs +95 -24
  314. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  315. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts +2 -1
  316. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts.map +1 -1
  317. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +22 -40
  318. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs.map +1 -1
  319. package/dist/astro/routes/api/redirects/404s/index.mjs +18 -14
  320. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  321. package/dist/astro/routes/api/redirects/404s/summary.mjs +18 -14
  322. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  323. package/dist/astro/routes/api/redirects/_id_.d.mts.map +1 -1
  324. package/dist/astro/routes/api/redirects/_id_.mjs +20 -22
  325. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  326. package/dist/astro/routes/api/redirects/index.d.mts.map +1 -1
  327. package/dist/astro/routes/api/redirects/index.mjs +19 -19
  328. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  329. package/dist/astro/routes/api/relations/_id_/index.mjs +27 -23
  330. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  331. package/dist/astro/routes/api/relations/_id_/translations.mjs +21 -18
  332. package/dist/astro/routes/api/relations/_id_/translations.mjs.map +1 -1
  333. package/dist/astro/routes/api/relations/index.mjs +27 -23
  334. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  335. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +4 -4
  336. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +5 -5
  337. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +65 -59
  338. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  339. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +65 -59
  340. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  341. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +65 -59
  342. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  343. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +65 -59
  344. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  345. package/dist/astro/routes/api/schema/collections/index.mjs +65 -59
  346. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  347. package/dist/astro/routes/api/schema/collections/reorder.mjs +65 -59
  348. package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
  349. package/dist/astro/routes/api/schema/index.mjs +16 -14
  350. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  351. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +65 -59
  352. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  353. package/dist/astro/routes/api/schema/orphans/index.mjs +65 -59
  354. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  355. package/dist/astro/routes/api/search/enable.mjs +16 -14
  356. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  357. package/dist/astro/routes/api/search/index.mjs +17 -14
  358. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  359. package/dist/astro/routes/api/search/rebuild.mjs +16 -14
  360. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  361. package/dist/astro/routes/api/search/stats.mjs +10 -9
  362. package/dist/astro/routes/api/search/stats.mjs.map +1 -1
  363. package/dist/astro/routes/api/search/suggest.mjs +15 -13
  364. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  365. package/dist/astro/routes/api/sections/_slug_.mjs +15 -13
  366. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  367. package/dist/astro/routes/api/sections/index.mjs +15 -13
  368. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  369. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +9 -8
  370. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs.map +1 -1
  371. package/dist/astro/routes/api/settings/backups/archives/index.mjs +8 -7
  372. package/dist/astro/routes/api/settings/backups/archives/index.mjs.map +1 -1
  373. package/dist/astro/routes/api/settings/backups/export.mjs +9 -8
  374. package/dist/astro/routes/api/settings/backups/export.mjs.map +1 -1
  375. package/dist/astro/routes/api/settings/backups/index.mjs +10 -9
  376. package/dist/astro/routes/api/settings/backups/index.mjs.map +1 -1
  377. package/dist/astro/routes/api/settings/email.mjs +6 -6
  378. package/dist/astro/routes/api/settings.mjs +22 -20
  379. package/dist/astro/routes/api/settings.mjs.map +1 -1
  380. package/dist/astro/routes/api/setup/admin-verify.mjs +16 -15
  381. package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
  382. package/dist/astro/routes/api/setup/admin.mjs +15 -14
  383. package/dist/astro/routes/api/setup/admin.mjs.map +1 -1
  384. package/dist/astro/routes/api/setup/dev-bypass.mjs +42 -38
  385. package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
  386. package/dist/astro/routes/api/setup/dev-reset.mjs +4 -4
  387. package/dist/astro/routes/api/setup/index.mjs +43 -38
  388. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  389. package/dist/astro/routes/api/setup/status.mjs +5 -5
  390. package/dist/astro/routes/api/snapshot.mjs +11 -10
  391. package/dist/astro/routes/api/snapshot.mjs.map +1 -1
  392. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +23 -21
  393. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
  394. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +23 -21
  395. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  396. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +23 -21
  397. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  398. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +23 -21
  399. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  400. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +22 -20
  401. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -1
  402. package/dist/astro/routes/api/taxonomies/_name_.mjs +23 -21
  403. package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -1
  404. package/dist/astro/routes/api/taxonomies/index.mjs +23 -21
  405. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  406. package/dist/astro/routes/api/themes/preview.mjs +8 -8
  407. package/dist/astro/routes/api/typegen.mjs +6 -6
  408. package/dist/astro/routes/api/visual-editing/action-token.d.mts +8 -0
  409. package/dist/astro/routes/api/visual-editing/action-token.d.mts.map +1 -0
  410. package/dist/astro/routes/api/visual-editing/action-token.mjs +25 -0
  411. package/dist/astro/routes/api/visual-editing/action-token.mjs.map +1 -0
  412. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.d.mts +8 -0
  413. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.d.mts.map +1 -0
  414. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs +37 -0
  415. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs.map +1 -0
  416. package/dist/astro/routes/api/visual-editing/toolbar-labels.d.mts +8 -0
  417. package/dist/astro/routes/api/visual-editing/toolbar-labels.d.mts.map +1 -0
  418. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs +20 -0
  419. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs.map +1 -0
  420. package/dist/astro/routes/api/well-known/auth.mjs +2 -2
  421. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
  422. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
  423. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +12 -11
  424. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  425. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +16 -15
  426. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  427. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +16 -15
  428. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  429. package/dist/astro/routes/api/widget-areas/_name_.mjs +10 -10
  430. package/dist/astro/routes/api/widget-areas/index.mjs +16 -15
  431. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  432. package/dist/astro/routes/api/widget-components.mjs +4 -4
  433. package/dist/astro/routes/robots.txt.mjs +13 -12
  434. package/dist/astro/routes/robots.txt.mjs.map +1 -1
  435. package/dist/astro/routes/sitemap-_collection_.xml.d.mts.map +1 -1
  436. package/dist/astro/routes/sitemap-_collection_.xml.mjs +24 -19
  437. package/dist/astro/routes/sitemap-_collection_.xml.mjs.map +1 -1
  438. package/dist/astro/routes/sitemap.xml.mjs +14 -13
  439. package/dist/astro/routes/sitemap.xml.mjs.map +1 -1
  440. package/dist/astro/types.d.mts +79 -26
  441. package/dist/astro/types.d.mts.map +1 -1
  442. package/dist/auth/providers/github.d.mts +1 -1
  443. package/dist/auth/providers/google.d.mts +1 -1
  444. package/dist/authoritative-records-DbqshfKD.mjs +5172 -0
  445. package/dist/authoritative-records-DbqshfKD.mjs.map +1 -0
  446. package/dist/authorize-BXpfMpp0.mjs +40 -0
  447. package/dist/authorize-BXpfMpp0.mjs.map +1 -0
  448. package/dist/backup-BsPQdwnS.mjs +246 -0
  449. package/dist/backup-BsPQdwnS.mjs.map +1 -0
  450. package/dist/base64-DvnNgP7e.mjs +63 -0
  451. package/dist/base64-DvnNgP7e.mjs.map +1 -0
  452. package/dist/byline-Doh-wt99.mjs +906 -0
  453. package/dist/byline-Doh-wt99.mjs.map +1 -0
  454. package/dist/byline-fields-CsrdvaLV.mjs +123 -0
  455. package/dist/byline-fields-CsrdvaLV.mjs.map +1 -0
  456. package/dist/byline-registry-D6lWzXk6.mjs +406 -0
  457. package/dist/byline-registry-D6lWzXk6.mjs.map +1 -0
  458. package/dist/bylines-Cop0hkoy.mjs +214 -0
  459. package/dist/bylines-Cop0hkoy.mjs.map +1 -0
  460. package/dist/bylines-kpBzHPr8.mjs +232 -0
  461. package/dist/bylines-kpBzHPr8.mjs.map +1 -0
  462. package/dist/cache-B0pOlXdM.mjs +108 -0
  463. package/dist/cache-B0pOlXdM.mjs.map +1 -0
  464. package/dist/capture-triggers-gxQxnxrJ.mjs +362 -0
  465. package/dist/capture-triggers-gxQxnxrJ.mjs.map +1 -0
  466. package/dist/challenge-store-CkRdSdd8.mjs +51 -0
  467. package/dist/challenge-store-CkRdSdd8.mjs.map +1 -0
  468. package/dist/checksum-Bsi2D9M1.mjs +162 -0
  469. package/dist/checksum-Bsi2D9M1.mjs.map +1 -0
  470. package/dist/chrome-tags-D7LGB91U.mjs +24 -0
  471. package/dist/chrome-tags-D7LGB91U.mjs.map +1 -0
  472. package/dist/chunks-BmWyou79.mjs +25 -0
  473. package/dist/chunks-BmWyou79.mjs.map +1 -0
  474. package/dist/cli/index.mjs +921 -106
  475. package/dist/cli/index.mjs.map +1 -1
  476. package/dist/client/cf-access.d.mts +1 -1
  477. package/dist/client/index.d.mts +17 -7
  478. package/dist/client/index.d.mts.map +1 -1
  479. package/dist/client/index.mjs +17 -12
  480. package/dist/client/index.mjs.map +1 -1
  481. package/dist/collection-deletion-C3Xixmkx.mjs +436 -0
  482. package/dist/collection-deletion-C3Xixmkx.mjs.map +1 -0
  483. package/dist/collection-slugs-cache-D9auiKmI.mjs +85 -0
  484. package/dist/collection-slugs-cache-D9auiKmI.mjs.map +1 -0
  485. package/dist/comment-DcT8qdPK.mjs +313 -0
  486. package/dist/comment-DcT8qdPK.mjs.map +1 -0
  487. package/dist/comment-reaction-DY5-y8Y5.mjs +85 -0
  488. package/dist/comment-reaction-DY5-y8Y5.mjs.map +1 -0
  489. package/dist/comments-B67VRNGw.mjs +204 -0
  490. package/dist/comments-B67VRNGw.mjs.map +1 -0
  491. package/dist/comments-BVzzt6x5.mjs +99 -0
  492. package/dist/comments-BVzzt6x5.mjs.map +1 -0
  493. package/dist/components-DIl9Qzh6.mjs +108 -0
  494. package/dist/components-DIl9Qzh6.mjs.map +1 -0
  495. package/dist/config-B2acLeC5.mjs +242 -0
  496. package/dist/config-B2acLeC5.mjs.map +1 -0
  497. package/dist/config-CGVeT8Hc.mjs +73 -0
  498. package/dist/config-CGVeT8Hc.mjs.map +1 -0
  499. package/dist/config-D3HhLON3.d.mts +39 -0
  500. package/dist/config-D3HhLON3.d.mts.map +1 -0
  501. package/dist/config-DS7e4EZ9.d.mts +6387 -0
  502. package/dist/config-DS7e4EZ9.d.mts.map +1 -0
  503. package/dist/content-DZ3B5qtA.mjs +2216 -0
  504. package/dist/content-DZ3B5qtA.mjs.map +1 -0
  505. package/dist/content-list-query-CbPdzsna.d.mts +26 -0
  506. package/dist/content-list-query-CbPdzsna.d.mts.map +1 -0
  507. package/dist/content-policy-CM4skrNi.mjs +46 -0
  508. package/dist/content-policy-CM4skrNi.mjs.map +1 -0
  509. package/dist/content-refresh-BHLHJgyt.mjs +3599 -0
  510. package/dist/content-refresh-BHLHJgyt.mjs.map +1 -0
  511. package/dist/content-repair-BVll5WNl.mjs +440 -0
  512. package/dist/content-repair-BVll5WNl.mjs.map +1 -0
  513. package/dist/context-B195kjqZ.mjs +1835 -0
  514. package/dist/context-B195kjqZ.mjs.map +1 -0
  515. package/dist/cron-BcR3RN4K.mjs +282 -0
  516. package/dist/cron-BcR3RN4K.mjs.map +1 -0
  517. package/dist/dashboard-CZD4G7k_.mjs +151 -0
  518. package/dist/dashboard-CZD4G7k_.mjs.map +1 -0
  519. package/dist/database/migration-lock.d.mts +37 -0
  520. package/dist/database/migration-lock.d.mts.map +1 -0
  521. package/dist/database/migration-lock.mjs +76 -0
  522. package/dist/database/migration-lock.mjs.map +1 -0
  523. package/dist/database/pg-migration-lock.d.mts +1 -1
  524. package/dist/database/pg-migration-lock.mjs +1 -1
  525. package/dist/database/pg-migration-lock.mjs.map +1 -1
  526. package/dist/datetime-normalization-PeiEdcRY.mjs +187 -0
  527. package/dist/datetime-normalization-PeiEdcRY.mjs.map +1 -0
  528. package/dist/db/index.d.mts +3 -3
  529. package/dist/db/index.mjs +4 -3
  530. package/dist/db/index.mjs.map +1 -1
  531. package/dist/db/libsql-migrations.d.mts +1 -1
  532. package/dist/db/libsql-migrations.mjs +7 -6
  533. package/dist/db/libsql-migrations.mjs.map +1 -1
  534. package/dist/db/libsql.d.mts +1 -1
  535. package/dist/db/postgres-migrations.d.mts +1 -1
  536. package/dist/db/postgres-migrations.mjs +7 -6
  537. package/dist/db/postgres-migrations.mjs.map +1 -1
  538. package/dist/db/postgres.d.mts +1 -1
  539. package/dist/db/sqlite-migrations.d.mts +1 -1
  540. package/dist/db/sqlite-migrations.mjs +7 -6
  541. package/dist/db/sqlite-migrations.mjs.map +1 -1
  542. package/dist/db/sqlite.d.mts +1 -1
  543. package/dist/db/sqlite.mjs +1 -1
  544. package/dist/db-errors-CBD5yMro.mjs +55 -0
  545. package/dist/db-errors-CBD5yMro.mjs.map +1 -0
  546. package/dist/default-BtlxWgh9.mjs +81 -0
  547. package/dist/default-BtlxWgh9.mjs.map +1 -0
  548. package/dist/deferred-tasks-Ba9fphlE.d.mts +9 -0
  549. package/dist/deferred-tasks-Ba9fphlE.d.mts.map +1 -0
  550. package/dist/dev-typegen-CZaPLl3V.mjs +29 -0
  551. package/dist/dev-typegen-CZaPLl3V.mjs.map +1 -0
  552. package/dist/device-flow-3E5l0fpH.mjs +466 -0
  553. package/dist/device-flow-3E5l0fpH.mjs.map +1 -0
  554. package/dist/dialect-helpers-CtYdsX4W.mjs +307 -0
  555. package/dist/dialect-helpers-CtYdsX4W.mjs.map +1 -0
  556. package/dist/direct-executor-ZI8E01Yt.mjs +104 -0
  557. package/dist/direct-executor-ZI8E01Yt.mjs.map +1 -0
  558. package/dist/dist-2hDLsLeq.mjs +810 -0
  559. package/dist/dist-2hDLsLeq.mjs.map +1 -0
  560. package/dist/email-console-gc-E3Eqj.mjs +50 -0
  561. package/dist/email-console-gc-E3Eqj.mjs.map +1 -0
  562. package/dist/emdash-runtime-DZGinqTL.mjs +4041 -0
  563. package/dist/emdash-runtime-DZGinqTL.mjs.map +1 -0
  564. package/dist/enrich-C2Mk0lwE.mjs +194 -0
  565. package/dist/enrich-C2Mk0lwE.mjs.map +1 -0
  566. package/dist/entry-lock-D3C99MXS.mjs +1520 -0
  567. package/dist/entry-lock-D3C99MXS.mjs.map +1 -0
  568. package/dist/entry-lock-D9rnj2Lu.mjs +163 -0
  569. package/dist/entry-lock-D9rnj2Lu.mjs.map +1 -0
  570. package/dist/entry-lock-DX7QkqEg.d.mts +3503 -0
  571. package/dist/entry-lock-DX7QkqEg.d.mts.map +1 -0
  572. package/dist/entry-locks-CO_KaoU5.mjs +167 -0
  573. package/dist/entry-locks-CO_KaoU5.mjs.map +1 -0
  574. package/dist/error-CCTCskie.mjs +90 -0
  575. package/dist/error-CCTCskie.mjs.map +1 -0
  576. package/dist/errors-W3PA8HqB.mjs +447 -0
  577. package/dist/errors-W3PA8HqB.mjs.map +1 -0
  578. package/dist/escape-DN4Qmjsl.mjs +9 -0
  579. package/dist/escape-DN4Qmjsl.mjs.map +1 -0
  580. package/dist/field-defs-cache-B337z8UJ.mjs +77 -0
  581. package/dist/field-defs-cache-B337z8UJ.mjs.map +1 -0
  582. package/dist/focal-point-Gr34o-4o.mjs +23 -0
  583. package/dist/focal-point-Gr34o-4o.mjs.map +1 -0
  584. package/dist/fts-manager-DMb0sbIQ.mjs +413 -0
  585. package/dist/fts-manager-DMb0sbIQ.mjs.map +1 -0
  586. package/dist/hash-CLVFzWvx.mjs +37 -0
  587. package/dist/hash-CLVFzWvx.mjs.map +1 -0
  588. package/dist/hook-result-KY1jq21o.d.mts +31 -0
  589. package/dist/hook-result-KY1jq21o.d.mts.map +1 -0
  590. package/dist/hreflang-BgS2FqhH.d.mts +50 -0
  591. package/dist/hreflang-BgS2FqhH.d.mts.map +1 -0
  592. package/dist/hreflang-CrJwqoeb.mjs +105 -0
  593. package/dist/hreflang-CrJwqoeb.mjs.map +1 -0
  594. package/dist/http-route-dispatch-DAKlanXb.mjs +339 -0
  595. package/dist/http-route-dispatch-DAKlanXb.mjs.map +1 -0
  596. package/dist/identity-DRGSHEEr.mjs +35 -0
  597. package/dist/identity-DRGSHEEr.mjs.map +1 -0
  598. package/dist/import-DFr5B_hC.mjs +2020 -0
  599. package/dist/import-DFr5B_hC.mjs.map +1 -0
  600. package/dist/index-CDwKDkTq.d.mts +623 -0
  601. package/dist/index-CDwKDkTq.d.mts.map +1 -0
  602. package/dist/index.d.mts +27 -22
  603. package/dist/index.mjs +101 -86
  604. package/dist/init-lock-4eRRB4Le.mjs +56 -0
  605. package/dist/init-lock-4eRRB4Le.mjs.map +1 -0
  606. package/dist/install-finalization-5Os-QZ-2.mjs +58 -0
  607. package/dist/install-finalization-5Os-QZ-2.mjs.map +1 -0
  608. package/dist/lifecycle-7e-Lt_kX.mjs +25 -0
  609. package/dist/lifecycle-7e-Lt_kX.mjs.map +1 -0
  610. package/dist/load-Cu5bvCZh.mjs +28 -0
  611. package/dist/load-Cu5bvCZh.mjs.map +1 -0
  612. package/dist/loader-t4TxaFiQ.mjs +1004 -0
  613. package/dist/loader-t4TxaFiQ.mjs.map +1 -0
  614. package/dist/manifest-builder-D31UoJCu.mjs +189 -0
  615. package/dist/manifest-builder-D31UoJCu.mjs.map +1 -0
  616. package/dist/manifest-schema-Bkh8SeHd.mjs +491 -0
  617. package/dist/manifest-schema-Bkh8SeHd.mjs.map +1 -0
  618. package/dist/media/image-endpoint.mjs +1 -1
  619. package/dist/media/index.d.mts +1 -1
  620. package/dist/media/index.mjs +4 -4
  621. package/dist/media/local-runtime.d.mts +14 -12
  622. package/dist/media/local-runtime.d.mts.map +1 -1
  623. package/dist/media/local-runtime.mjs +12 -11
  624. package/dist/media/local-runtime.mjs.map +1 -1
  625. package/dist/media-TBlKCwo7.mjs +334 -0
  626. package/dist/media-TBlKCwo7.mjs.map +1 -0
  627. package/dist/media-allowlist-s60eAIf6.mjs +44 -0
  628. package/dist/media-allowlist-s60eAIf6.mjs.map +1 -0
  629. package/dist/media-folders-ClIRLUQv.mjs +210 -0
  630. package/dist/media-folders-ClIRLUQv.mjs.map +1 -0
  631. package/dist/media-url-DY_ijO3B.mjs +43 -0
  632. package/dist/media-url-DY_ijO3B.mjs.map +1 -0
  633. package/dist/media-usage-C4NolTpQ.mjs +1833 -0
  634. package/dist/media-usage-C4NolTpQ.mjs.map +1 -0
  635. package/dist/media-usage-activation-CAhmb14O.mjs +78 -0
  636. package/dist/media-usage-activation-CAhmb14O.mjs.map +1 -0
  637. package/dist/media-usage-work-Cu5DqewW.mjs +586 -0
  638. package/dist/media-usage-work-Cu5DqewW.mjs.map +1 -0
  639. package/dist/media-usage-work-DJr3rOEN.mjs +152 -0
  640. package/dist/media-usage-work-DJr3rOEN.mjs.map +1 -0
  641. package/dist/media-usage-write-fence-DW5oHT7q.mjs +42 -0
  642. package/dist/media-usage-write-fence-DW5oHT7q.mjs.map +1 -0
  643. package/dist/menus-DbgU9z5Q.mjs +3732 -0
  644. package/dist/menus-DbgU9z5Q.mjs.map +1 -0
  645. package/dist/menus-Wy8m5NcH.mjs +753 -0
  646. package/dist/menus-Wy8m5NcH.mjs.map +1 -0
  647. package/dist/migrations/index.d.mts +2 -2
  648. package/dist/migrations/index.d.mts.map +1 -1
  649. package/dist/migrations/index.mjs +6 -5
  650. package/dist/mime-CCYRC4r1.mjs +36 -0
  651. package/dist/mime-CCYRC4r1.mjs.map +1 -0
  652. package/dist/mode-CkmOhFqj.mjs +23 -0
  653. package/dist/mode-CkmOhFqj.mjs.map +1 -0
  654. package/dist/node-sqlite-compat-vpVaILnb.mjs +46 -0
  655. package/dist/node-sqlite-compat-vpVaILnb.mjs.map +1 -0
  656. package/dist/normalize-dChXQjwS.mjs +191 -0
  657. package/dist/normalize-dChXQjwS.mjs.map +1 -0
  658. package/dist/oauth-authorization-DZ-R-hmx.mjs +274 -0
  659. package/dist/oauth-authorization-DZ-R-hmx.mjs.map +1 -0
  660. package/dist/oauth-clients-BMPA8vjl.mjs +266 -0
  661. package/dist/oauth-clients-BMPA8vjl.mjs.map +1 -0
  662. package/dist/oauth-state-store-0gIdb48-.mjs +50 -0
  663. package/dist/oauth-state-store-0gIdb48-.mjs.map +1 -0
  664. package/dist/oauth-user-lookup-ChVW4UWu.mjs +26 -0
  665. package/dist/oauth-user-lookup-ChVW4UWu.mjs.map +1 -0
  666. package/dist/object-cache/memory.d.mts +1 -1
  667. package/dist/object-cache-DlSVbn5Y.mjs +534 -0
  668. package/dist/object-cache-DlSVbn5Y.mjs.map +1 -0
  669. package/dist/options-D5WcorD5.mjs +200 -0
  670. package/dist/options-D5WcorD5.mjs.map +1 -0
  671. package/dist/options-DAknChnw.d.mts +77 -0
  672. package/dist/options-DAknChnw.d.mts.map +1 -0
  673. package/dist/page/index.d.mts +2 -2
  674. package/dist/page/index.d.mts.map +1 -1
  675. package/dist/page/index.mjs +13 -0
  676. package/dist/page/index.mjs.map +1 -1
  677. package/dist/parse-Cr379Av9.mjs +81 -0
  678. package/dist/parse-Cr379Av9.mjs.map +1 -0
  679. package/dist/parse-tj9XLNO_.d.mts +165 -0
  680. package/dist/parse-tj9XLNO_.d.mts.map +1 -0
  681. package/dist/passkey-config-BD-wMaCf.mjs +46 -0
  682. package/dist/passkey-config-BD-wMaCf.mjs.map +1 -0
  683. package/dist/patterns-Do3iqi7N.mjs +145 -0
  684. package/dist/patterns-Do3iqi7N.mjs.map +1 -0
  685. package/dist/placeholder-CubPFn_L.d.mts +306 -0
  686. package/dist/placeholder-CubPFn_L.d.mts.map +1 -0
  687. package/dist/plugin-test-runtime.d.mts +97 -0
  688. package/dist/plugin-test-runtime.d.mts.map +1 -0
  689. package/dist/plugin-test-runtime.mjs +105 -0
  690. package/dist/plugin-types.d.mts +53 -15
  691. package/dist/plugin-types.d.mts.map +1 -1
  692. package/dist/plugin-types.mjs +18 -1
  693. package/dist/plugin-types.mjs.map +1 -0
  694. package/dist/plugin-utils.d.mts +12 -10
  695. package/dist/plugin-utils.d.mts.map +1 -1
  696. package/dist/plugins/adapt-sandbox-entry.d.mts +12 -10
  697. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  698. package/dist/plugins/adapt-sandbox-entry.mjs +18 -13
  699. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  700. package/dist/plugins/host.d.mts +7 -0
  701. package/dist/plugins/host.mjs +45 -0
  702. package/dist/plugins/http-wire.d.mts +25 -0
  703. package/dist/plugins/http-wire.d.mts.map +1 -0
  704. package/dist/plugins/http-wire.mjs +148 -0
  705. package/dist/plugins/http-wire.mjs.map +1 -0
  706. package/dist/plugins/secret-redactor.d.mts +9 -0
  707. package/dist/plugins/secret-redactor.d.mts.map +1 -0
  708. package/dist/plugins/secret-redactor.mjs +51 -0
  709. package/dist/plugins/secret-redactor.mjs.map +1 -0
  710. package/dist/plugins-DHurtdXQ.mjs +277 -0
  711. package/dist/plugins-DHurtdXQ.mjs.map +1 -0
  712. package/dist/policy-lyZnjpwz.mjs +45 -0
  713. package/dist/policy-lyZnjpwz.mjs.map +1 -0
  714. package/dist/portable-text-oAwodbPS.mjs +286 -0
  715. package/dist/portable-text-oAwodbPS.mjs.map +1 -0
  716. package/dist/preview-Cup2bj8c.mjs +107 -0
  717. package/dist/preview-Cup2bj8c.mjs.map +1 -0
  718. package/dist/protocol-C1CNiKX4.d.mts +61 -0
  719. package/dist/protocol-C1CNiKX4.d.mts.map +1 -0
  720. package/dist/public-submission-Cs-pFMQK.mjs +245 -0
  721. package/dist/public-submission-Cs-pFMQK.mjs.map +1 -0
  722. package/dist/public-url-BWVHsfQv.mjs +101 -0
  723. package/dist/public-url-BWVHsfQv.mjs.map +1 -0
  724. package/dist/query-D-lxiOgn.mjs +890 -0
  725. package/dist/query-D-lxiOgn.mjs.map +1 -0
  726. package/dist/query-D7kHKOws.mjs +41 -0
  727. package/dist/query-D7kHKOws.mjs.map +1 -0
  728. package/dist/rate-limit-CqJn-w4h.mjs +120 -0
  729. package/dist/rate-limit-CqJn-w4h.mjs.map +1 -0
  730. package/dist/redirect-BrChFPIu.mjs +17 -0
  731. package/dist/redirect-BrChFPIu.mjs.map +1 -0
  732. package/dist/redirect-D2Yo-b6S.mjs +415 -0
  733. package/dist/redirect-D2Yo-b6S.mjs.map +1 -0
  734. package/dist/redirects-BCiTaIQ-.mjs +146 -0
  735. package/dist/redirects-BCiTaIQ-.mjs.map +1 -0
  736. package/dist/redirects-ByItliuu.mjs +644 -0
  737. package/dist/redirects-ByItliuu.mjs.map +1 -0
  738. package/dist/registry/testing.d.mts +14 -0
  739. package/dist/registry/testing.d.mts.map +1 -0
  740. package/dist/registry/testing.mjs +255 -0
  741. package/dist/registry/testing.mjs.map +1 -0
  742. package/dist/registry-CkuPoZs7.mjs +1222 -0
  743. package/dist/registry-CkuPoZs7.mjs.map +1 -0
  744. package/dist/relation-XTAtOpJO.mjs +334 -0
  745. package/dist/relation-XTAtOpJO.mjs.map +1 -0
  746. package/dist/relations-B4w-G5U9.mjs +309 -0
  747. package/dist/relations-B4w-G5U9.mjs.map +1 -0
  748. package/dist/relations-O63JWBRj.mjs +403 -0
  749. package/dist/relations-O63JWBRj.mjs.map +1 -0
  750. package/dist/request-cache-DaMhSQdx.mjs +104 -0
  751. package/dist/request-cache-DaMhSQdx.mjs.map +1 -0
  752. package/dist/request-context.d.mts +1 -1
  753. package/dist/request-meta-C8yl_sIs.mjs +141 -0
  754. package/dist/request-meta-C8yl_sIs.mjs.map +1 -0
  755. package/dist/resolve-BJIS8wKr.mjs +199 -0
  756. package/dist/resolve-BJIS8wKr.mjs.map +1 -0
  757. package/dist/route-wire-D66L2oaZ.mjs +197 -0
  758. package/dist/route-wire-D66L2oaZ.mjs.map +1 -0
  759. package/dist/routes-DYsTe-oR.mjs +321 -0
  760. package/dist/routes-DYsTe-oR.mjs.map +1 -0
  761. package/dist/runner-3gfxRsJG.d.mts +68 -0
  762. package/dist/runner-3gfxRsJG.d.mts.map +1 -0
  763. package/dist/runner-ClrleR8A.mjs +5502 -0
  764. package/dist/runner-ClrleR8A.mjs.map +1 -0
  765. package/dist/runtime.d.mts +13 -11
  766. package/dist/runtime.d.mts.map +1 -1
  767. package/dist/runtime.mjs +6 -5
  768. package/dist/runtime.mjs.map +1 -1
  769. package/dist/schema-CPhPM9Do.mjs +420 -0
  770. package/dist/schema-CPhPM9Do.mjs.map +1 -0
  771. package/dist/schema-DEERRrKS.mjs +9 -0
  772. package/dist/schema-DEERRrKS.mjs.map +1 -0
  773. package/dist/scopes-Bn8_rCSt.mjs +27 -0
  774. package/dist/scopes-Bn8_rCSt.mjs.map +1 -0
  775. package/dist/search-lami_Ota.mjs +448 -0
  776. package/dist/search-lami_Ota.mjs.map +1 -0
  777. package/dist/secrets-DNgVgz_e.mjs +341 -0
  778. package/dist/secrets-DNgVgz_e.mjs.map +1 -0
  779. package/dist/sections-BIpd4Cxf.mjs +346 -0
  780. package/dist/sections-BIpd4Cxf.mjs.map +1 -0
  781. package/dist/seed/index.d.mts +2 -2
  782. package/dist/seed/index.mjs +35 -31
  783. package/dist/seo/index.d.mts +3 -3
  784. package/dist/seo/index.d.mts.map +1 -1
  785. package/dist/seo/index.mjs +27 -26
  786. package/dist/seo/index.mjs.map +1 -1
  787. package/dist/seo-BtU70b7l.mjs +114 -0
  788. package/dist/seo-BtU70b7l.mjs.map +1 -0
  789. package/dist/seo-_4qmazxz.mjs +133 -0
  790. package/dist/seo-_4qmazxz.mjs.map +1 -0
  791. package/dist/service-Bpy5iTX0.mjs +150 -0
  792. package/dist/service-Bpy5iTX0.mjs.map +1 -0
  793. package/dist/session-user-BQeS2Mrb.mjs +51 -0
  794. package/dist/session-user-BQeS2Mrb.mjs.map +1 -0
  795. package/dist/settings-DmroR53o.mjs +420 -0
  796. package/dist/settings-DmroR53o.mjs.map +1 -0
  797. package/dist/settings-g2F2a3Ub.mjs +51 -0
  798. package/dist/settings-g2F2a3Ub.mjs.map +1 -0
  799. package/dist/setup-complete-BrZaXpVV.mjs +26 -0
  800. package/dist/setup-complete-BrZaXpVV.mjs.map +1 -0
  801. package/dist/setup-nonce-Cb9-884O.mjs +25 -0
  802. package/dist/setup-nonce-Cb9-884O.mjs.map +1 -0
  803. package/dist/single-flight-cache-B5O2qhO1.mjs +104 -0
  804. package/dist/single-flight-cache-B5O2qhO1.mjs.map +1 -0
  805. package/dist/site-url-DjhYCaep.mjs +16 -0
  806. package/dist/site-url-DjhYCaep.mjs.map +1 -0
  807. package/dist/slugify-T5GHH42D.mjs +17 -0
  808. package/dist/slugify-T5GHH42D.mjs.map +1 -0
  809. package/dist/snapshot-C32Xuv3o.mjs +233 -0
  810. package/dist/snapshot-C32Xuv3o.mjs.map +1 -0
  811. package/dist/ssrf-Co1GGFZz.mjs +406 -0
  812. package/dist/ssrf-Co1GGFZz.mjs.map +1 -0
  813. package/dist/state-C7gCoiHr.mjs +153 -0
  814. package/dist/state-C7gCoiHr.mjs.map +1 -0
  815. package/dist/status-DLoBmcDz.mjs +30 -0
  816. package/dist/status-DLoBmcDz.mjs.map +1 -0
  817. package/dist/storage/local.d.mts +1 -1
  818. package/dist/storage/local.mjs +1 -1
  819. package/dist/storage/s3.d.mts +1 -1
  820. package/dist/storage/s3.mjs +1 -1
  821. package/dist/storage-query-CPctdMKX.d.mts +1519 -0
  822. package/dist/storage-query-CPctdMKX.d.mts.map +1 -0
  823. package/dist/target-CUKlGrXb.mjs +27 -0
  824. package/dist/target-CUKlGrXb.mjs.map +1 -0
  825. package/dist/taxonomies-BpqpXJUE.mjs +707 -0
  826. package/dist/taxonomies-BpqpXJUE.mjs.map +1 -0
  827. package/dist/taxonomies-ClCo4IGO.mjs +899 -0
  828. package/dist/taxonomies-ClCo4IGO.mjs.map +1 -0
  829. package/dist/taxonomy-Dj1vpw5E.mjs +508 -0
  830. package/dist/taxonomy-Dj1vpw5E.mjs.map +1 -0
  831. package/dist/tokens-Ns02GAma.mjs +171 -0
  832. package/dist/tokens-Ns02GAma.mjs.map +1 -0
  833. package/dist/transaction-BcJO4Tmc.mjs +29 -0
  834. package/dist/transaction-BcJO4Tmc.mjs.map +1 -0
  835. package/dist/transport-B8P1xsqk.mjs +136 -0
  836. package/dist/transport-B8P1xsqk.mjs.map +1 -0
  837. package/dist/transport-BLHZZcD_.d.mts +42 -0
  838. package/dist/transport-BLHZZcD_.d.mts.map +1 -0
  839. package/dist/trusted-proxy-Cg7SuD15.mjs +51 -0
  840. package/dist/trusted-proxy-Cg7SuD15.mjs.map +1 -0
  841. package/dist/turnstile-DWCSh_Qc.mjs +53 -0
  842. package/dist/turnstile-DWCSh_Qc.mjs.map +1 -0
  843. package/dist/types-B3RkqvDW.mjs +156 -0
  844. package/dist/types-B3RkqvDW.mjs.map +1 -0
  845. package/dist/types-BkUg2yHx.mjs +92 -0
  846. package/dist/types-BkUg2yHx.mjs.map +1 -0
  847. package/dist/types-BtuppOTV.mjs +16 -0
  848. package/dist/types-BtuppOTV.mjs.map +1 -0
  849. package/dist/types-CCR3ivXE.d.mts +363 -0
  850. package/dist/types-CCR3ivXE.d.mts.map +1 -0
  851. package/dist/types-CSHgU_-_.mjs +18 -0
  852. package/dist/types-CSHgU_-_.mjs.map +1 -0
  853. package/dist/types-CbwqGOXm.d.mts +766 -0
  854. package/dist/types-CbwqGOXm.d.mts.map +1 -0
  855. package/dist/types-D4RGIc2I.d.mts +198 -0
  856. package/dist/types-D4RGIc2I.d.mts.map +1 -0
  857. package/dist/types-DEHidMEk.d.mts +1637 -0
  858. package/dist/types-DEHidMEk.d.mts.map +1 -0
  859. package/dist/types-DQeU2SR7.d.mts +279 -0
  860. package/dist/types-DQeU2SR7.d.mts.map +1 -0
  861. package/dist/types-DxQWoQLA.d.mts +264 -0
  862. package/dist/types-DxQWoQLA.d.mts.map +1 -0
  863. package/dist/types-FBBnGZ2Y.d.mts +198 -0
  864. package/dist/types-FBBnGZ2Y.d.mts.map +1 -0
  865. package/dist/types-ZCnlropY.mjs +69 -0
  866. package/dist/types-ZCnlropY.mjs.map +1 -0
  867. package/dist/types-_Qtyawiy.d.mts +124 -0
  868. package/dist/types-_Qtyawiy.d.mts.map +1 -0
  869. package/dist/types-gC6FAoa_.d.mts +75 -0
  870. package/dist/types-gC6FAoa_.d.mts.map +1 -0
  871. package/dist/types-k--LneIF.mjs +22 -0
  872. package/dist/types-k--LneIF.mjs.map +1 -0
  873. package/dist/upload-attempts-2xdnoKGe.mjs +27 -0
  874. package/dist/upload-attempts-2xdnoKGe.mjs.map +1 -0
  875. package/dist/url-pattern-3m3reMzr.mjs +33 -0
  876. package/dist/url-pattern-3m3reMzr.mjs.map +1 -0
  877. package/dist/user-DroRntkx.mjs +171 -0
  878. package/dist/user-DroRntkx.mjs.map +1 -0
  879. package/dist/utils-CC2oNGV8.mjs +435 -0
  880. package/dist/utils-CC2oNGV8.mjs.map +1 -0
  881. package/dist/validate-BCP9HNDn.mjs +384 -0
  882. package/dist/validate-BCP9HNDn.mjs.map +1 -0
  883. package/dist/validate-CyQ7I3xF.d.mts +410 -0
  884. package/dist/validate-CyQ7I3xF.d.mts.map +1 -0
  885. package/dist/validate-DANX1-Qi.mjs +120 -0
  886. package/dist/validate-DANX1-Qi.mjs.map +1 -0
  887. package/dist/validation-DBy6WF94.mjs +216 -0
  888. package/dist/validation-DBy6WF94.mjs.map +1 -0
  889. package/dist/version-B57E4Uo7.mjs +7 -0
  890. package/dist/version-B57E4Uo7.mjs.map +1 -0
  891. package/dist/widgets-wQ7Xcgq8.mjs +126 -0
  892. package/dist/widgets-wQ7Xcgq8.mjs.map +1 -0
  893. package/dist/wxr-taxonomies-DIHfvEDt.mjs +406 -0
  894. package/dist/wxr-taxonomies-DIHfvEDt.mjs.map +1 -0
  895. package/dist/wxr-taxonomies-DU2ZSiGc.d.mts +34 -0
  896. package/dist/wxr-taxonomies-DU2ZSiGc.d.mts.map +1 -0
  897. package/dist/zod-generator-D_yHIWfs.mjs +329 -0
  898. package/dist/zod-generator-D_yHIWfs.mjs.map +1 -0
  899. package/package.json +39 -12
  900. package/src/api/errors.ts +23 -0
  901. package/src/api/handlers/backup.ts +11 -5
  902. package/src/api/handlers/content.ts +226 -85
  903. package/src/api/handlers/dashboard.ts +31 -1
  904. package/src/api/handlers/entry-lock.ts +206 -0
  905. package/src/api/handlers/index.ts +3 -0
  906. package/src/api/handlers/manifest.ts +5 -6
  907. package/src/api/handlers/marketplace.ts +126 -34
  908. package/src/api/handlers/media-upload.ts +31 -4
  909. package/src/api/handlers/menus.ts +9 -0
  910. package/src/api/handlers/plugin-settings.ts +35 -3
  911. package/src/api/handlers/redirects.ts +221 -138
  912. package/src/api/handlers/registry.ts +75 -29
  913. package/src/api/handlers/revision.ts +16 -27
  914. package/src/api/handlers/seo.ts +10 -1
  915. package/src/api/handlers/snapshot.ts +87 -72
  916. package/src/api/handlers/taxonomies.ts +79 -5
  917. package/src/api/handlers/validation.ts +120 -19
  918. package/src/api/openapi/document.ts +133 -11
  919. package/src/api/schemas/content.ts +32 -12
  920. package/src/api/schemas/entry-lock.ts +57 -0
  921. package/src/api/schemas/index.ts +1 -0
  922. package/src/api/schemas/schema.ts +10 -1
  923. package/src/api/schemas/search.ts +4 -0
  924. package/src/api/types.ts +4 -0
  925. package/src/astro/integration/index.ts +22 -6
  926. package/src/astro/integration/routes.ts +89 -0
  927. package/src/astro/integration/runtime.ts +40 -24
  928. package/src/astro/integration/virtual-modules.ts +4 -0
  929. package/src/astro/integration/vite-config.ts +31 -0
  930. package/src/astro/middleware/auth.ts +25 -4
  931. package/src/astro/middleware/request-context.ts +28 -10
  932. package/src/astro/middleware.ts +33 -1
  933. package/src/astro/prefetch.ts +2 -2
  934. package/src/astro/routes/api/admin/comments/[id]/status.ts +22 -58
  935. package/src/astro/routes/api/admin/plugins/[id]/disable.ts +2 -15
  936. package/src/astro/routes/api/admin/plugins/[id]/enable.ts +2 -25
  937. package/src/astro/routes/api/admin/plugins/[id]/uninstall.ts +1 -0
  938. package/src/astro/routes/api/admin/plugins/[id]/update.ts +23 -4
  939. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +12 -2
  940. package/src/astro/routes/api/admin/plugins/registry/[id]/uninstall.ts +1 -0
  941. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +29 -10
  942. package/src/astro/routes/api/admin/plugins/registry/artifact.ts +8 -2
  943. package/src/astro/routes/api/admin/plugins/registry/install.ts +15 -4
  944. package/src/astro/routes/api/admin/plugins/registry/verify.ts +2 -1
  945. package/src/astro/routes/api/admin/plugins/updates.ts +6 -1
  946. package/src/astro/routes/api/admin/scheduled-policy-rejections/[collection]/[id].ts +34 -0
  947. package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +4 -259
  948. package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +10 -0
  949. package/src/astro/routes/api/content/[collection]/[id]/lock.ts +133 -0
  950. package/src/astro/routes/api/content/[collection]/[id]/plugin-extensions/[pluginId]/[kind]/[extensionId].ts +29 -0
  951. package/src/astro/routes/api/content/[collection]/[id]/publish.ts +21 -4
  952. package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +30 -1
  953. package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +15 -1
  954. package/src/astro/routes/api/content/[collection]/[id].ts +27 -2
  955. package/src/astro/routes/api/content/[collection]/index.ts +3 -0
  956. package/src/astro/routes/api/health.ts +23 -0
  957. package/src/astro/routes/api/manifest.ts +14 -4
  958. package/src/astro/routes/api/mcp.ts +2 -1
  959. package/src/astro/routes/api/media/asset/[id]/[filename].ts +50 -0
  960. package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +13 -81
  961. package/src/astro/routes/api/redirects/[id].ts +0 -3
  962. package/src/astro/routes/api/redirects/index.ts +0 -2
  963. package/src/astro/routes/api/search/index.ts +1 -0
  964. package/src/astro/routes/api/visual-editing/action-token.ts +36 -0
  965. package/src/astro/routes/api/visual-editing/content/[collection]/[id]/publish.ts +32 -0
  966. package/src/astro/routes/api/visual-editing/toolbar-labels.ts +16 -0
  967. package/src/astro/routes/sitemap-[collection].xml.ts +11 -4
  968. package/src/astro/types.ts +83 -12
  969. package/src/cli/commands/bundle-utils.ts +19 -19
  970. package/src/cli/commands/bundle.ts +9 -6
  971. package/src/cli/commands/content.ts +32 -6
  972. package/src/cli/commands/doctor.ts +25 -0
  973. package/src/cli/commands/export-seed.ts +195 -56
  974. package/src/cli/commands/migrate.ts +71 -23
  975. package/src/cli/commands/publish.ts +2 -2
  976. package/src/client/index.ts +34 -7
  977. package/src/comments/public-submission.ts +246 -0
  978. package/src/comments/service.ts +59 -12
  979. package/src/components/EmDashBodyEnd.astro +4 -1
  980. package/src/components/EmDashBodyStart.astro +4 -1
  981. package/src/components/EmDashHead.astro +36 -16
  982. package/src/components/Gallery.astro +18 -4
  983. package/src/components/InlineEditor.astro +3 -1
  984. package/src/components/InlinePortableTextEditor.tsx +106 -11
  985. package/src/components/PortableText.astro +4 -0
  986. package/src/components/Table.astro +147 -62
  987. package/src/components/widgets/Archives.astro +6 -5
  988. package/src/config/errors.ts +13 -0
  989. package/src/config/secrets.ts +25 -11
  990. package/src/content/converters/portable-text-to-prosemirror.ts +26 -2
  991. package/src/content/converters/prosemirror-to-portable-text.ts +35 -6
  992. package/src/content/converters/types.ts +10 -0
  993. package/src/content/known-fields.ts +44 -0
  994. package/src/database/connection.ts +5 -1
  995. package/src/database/content-datetime.ts +123 -0
  996. package/src/database/datetime-storage.ts +452 -0
  997. package/src/database/dialect-helpers.ts +161 -1
  998. package/src/database/migration-lock.ts +140 -0
  999. package/src/database/migrations/075_entry_edit_locks.ts +44 -0
  1000. package/src/database/migrations/076_collection_nav_group.ts +22 -0
  1001. package/src/database/migrations/077_plugin_storage_revisions.ts +89 -0
  1002. package/src/database/migrations/078_menu_item_translation_groups.ts +15 -0
  1003. package/src/database/migrations/079_datetime_normalization.ts +13 -0
  1004. package/src/database/migrations/080_content_translation_locale_unique.ts +88 -0
  1005. package/src/database/migrations/081_redirect_write_guards.ts +257 -0
  1006. package/src/database/migrations/082_taxonomy_translation_locale_unique.ts +49 -0
  1007. package/src/database/migrations/runner.ts +63 -15
  1008. package/src/database/pg-migration-lock.ts +2 -2
  1009. package/src/database/repositories/byline.ts +9 -0
  1010. package/src/database/repositories/comment.ts +86 -0
  1011. package/src/database/repositories/content.ts +560 -69
  1012. package/src/database/repositories/entry-locks.ts +257 -0
  1013. package/src/database/repositories/media.ts +35 -4
  1014. package/src/database/repositories/menu.ts +1 -0
  1015. package/src/database/repositories/options.ts +113 -7
  1016. package/src/database/repositories/plugin-storage.ts +159 -0
  1017. package/src/database/repositories/redirect.ts +262 -56
  1018. package/src/database/repositories/revision.ts +116 -17
  1019. package/src/database/repositories/taxonomy.ts +42 -0
  1020. package/src/database/repositories/types.ts +5 -0
  1021. package/src/database/types.ts +26 -1
  1022. package/src/datetime-normalization.ts +311 -0
  1023. package/src/db/node-sqlite-compat.ts +3 -2
  1024. package/src/emdash-runtime.ts +1994 -424
  1025. package/src/fields/image.ts +2 -0
  1026. package/src/i18n/config.ts +6 -6
  1027. package/src/i18n/resolve.ts +98 -15
  1028. package/src/index.ts +101 -0
  1029. package/src/loader.ts +49 -4
  1030. package/src/mcp/server.ts +216 -68
  1031. package/src/media/responsive.ts +23 -0
  1032. package/src/media/usage/content-refresh.ts +2 -1
  1033. package/src/media/usage/extractor.ts +50 -15
  1034. package/src/media/usage/types.ts +1 -1
  1035. package/src/menus/index.ts +64 -35
  1036. package/src/migrations/direct-executor.ts +40 -2
  1037. package/src/migrations/index.ts +1 -0
  1038. package/src/migrations/protocol.ts +11 -1
  1039. package/src/page/seo-contributions.ts +78 -1
  1040. package/src/page/seo-panel.ts +47 -0
  1041. package/src/plugin-test-runtime.ts +17 -0
  1042. package/src/plugin-types.ts +128 -21
  1043. package/src/plugins/adapt-sandbox-entry.ts +34 -27
  1044. package/src/plugins/conditional-storage.ts +30 -0
  1045. package/src/plugins/content-access.ts +170 -0
  1046. package/src/plugins/content-policy.ts +74 -0
  1047. package/src/plugins/context.ts +790 -166
  1048. package/src/plugins/cron.ts +18 -10
  1049. package/src/plugins/define-plugin.ts +55 -54
  1050. package/src/plugins/editor-draft.ts +257 -0
  1051. package/src/plugins/hooks.ts +136 -3
  1052. package/src/plugins/host.ts +29 -0
  1053. package/src/plugins/http-route-dispatch.ts +389 -0
  1054. package/src/plugins/http-wire.ts +180 -0
  1055. package/src/plugins/index.ts +97 -3
  1056. package/src/plugins/install-finalization.ts +77 -0
  1057. package/src/plugins/lifecycle.ts +47 -0
  1058. package/src/plugins/manager.ts +5 -2
  1059. package/src/plugins/manifest-schema.ts +314 -58
  1060. package/src/plugins/media.ts +166 -0
  1061. package/src/plugins/request-meta.ts +12 -2
  1062. package/src/plugins/route-wire.ts +304 -0
  1063. package/src/plugins/routes.ts +38 -5
  1064. package/src/plugins/sandbox/index.ts +4 -0
  1065. package/src/plugins/sandbox/proxy.ts +129 -0
  1066. package/src/plugins/sandbox/types.ts +83 -7
  1067. package/src/plugins/secret-redactor.ts +65 -0
  1068. package/src/plugins/settings.ts +303 -0
  1069. package/src/plugins/state.ts +26 -0
  1070. package/src/plugins/storage-query.ts +45 -0
  1071. package/src/plugins/storage-update.ts +96 -0
  1072. package/src/plugins/types.ts +602 -15
  1073. package/src/query.ts +84 -4
  1074. package/src/registry/authoritative-records.ts +26 -0
  1075. package/src/registry/config.ts +182 -31
  1076. package/src/registry/testing.ts +100 -0
  1077. package/src/registry/types.ts +12 -70
  1078. package/src/scheduled-publish.ts +70 -3
  1079. package/src/schema/collection-slugs-cache.ts +157 -0
  1080. package/src/schema/index.ts +1 -0
  1081. package/src/schema/registry.ts +64 -1
  1082. package/src/schema/types.ts +32 -6
  1083. package/src/schema/zod-generator.ts +5 -13
  1084. package/src/search/fts-manager.ts +3 -3
  1085. package/src/search/query.ts +32 -5
  1086. package/src/search/types.ts +8 -0
  1087. package/src/security/ssrf.ts +167 -141
  1088. package/src/seed/apply.ts +41 -3
  1089. package/src/seed/types.ts +13 -3
  1090. package/src/seed/validate.ts +18 -1
  1091. package/src/seo/hreflang.ts +10 -6
  1092. package/src/seo/index.ts +5 -10
  1093. package/src/seo/media-url.ts +26 -0
  1094. package/src/settings/index.ts +53 -11
  1095. package/src/taxonomies/term-counts.ts +22 -5
  1096. package/src/visual-editing/action-token.ts +31 -0
  1097. package/src/visual-editing/toolbar-bootstrap.ts +31 -6
  1098. package/src/visual-editing/toolbar.ts +103 -12
  1099. package/src/widgets/archives.ts +10 -9
  1100. package/src/widgets/index.ts +11 -1
  1101. package/dist/activation-K0kGBWuJ.mjs +0 -382
  1102. package/dist/activation-K0kGBWuJ.mjs.map +0 -1
  1103. package/dist/adapters-BDQwg236.d.mts +0 -171
  1104. package/dist/adapters-BDQwg236.d.mts.map +0 -1
  1105. package/dist/after-CBU2vkoO.mjs +0 -96
  1106. package/dist/after-CBU2vkoO.mjs.map +0 -1
  1107. package/dist/allowed-origins-BGglilcs.mjs +0 -116
  1108. package/dist/allowed-origins-BGglilcs.mjs.map +0 -1
  1109. package/dist/api-Dz6rgoa3.mjs +0 -10040
  1110. package/dist/api-Dz6rgoa3.mjs.map +0 -1
  1111. package/dist/api-tokens-BSsQACNe.mjs +0 -163
  1112. package/dist/api-tokens-BSsQACNe.mjs.map +0 -1
  1113. package/dist/apply-B4SIOxR1.mjs +0 -980
  1114. package/dist/apply-B4SIOxR1.mjs.map +0 -1
  1115. package/dist/authorize-Bkf_UHhD.mjs +0 -40
  1116. package/dist/authorize-Bkf_UHhD.mjs.map +0 -1
  1117. package/dist/backup-rwVAl9NI.mjs +0 -241
  1118. package/dist/backup-rwVAl9NI.mjs.map +0 -1
  1119. package/dist/base64-CvLhUKQv.mjs +0 -63
  1120. package/dist/base64-CvLhUKQv.mjs.map +0 -1
  1121. package/dist/bundle-C8S2Zl6U.mjs +0 -663
  1122. package/dist/bundle-C8S2Zl6U.mjs.map +0 -1
  1123. package/dist/byline-DuhF7NWl.mjs +0 -902
  1124. package/dist/byline-DuhF7NWl.mjs.map +0 -1
  1125. package/dist/byline-fields-BovY4KYM.mjs +0 -123
  1126. package/dist/byline-fields-BovY4KYM.mjs.map +0 -1
  1127. package/dist/byline-registry-Bpu9-MVs.mjs +0 -406
  1128. package/dist/byline-registry-Bpu9-MVs.mjs.map +0 -1
  1129. package/dist/bylines-CJ5nd6Lw.mjs +0 -232
  1130. package/dist/bylines-CJ5nd6Lw.mjs.map +0 -1
  1131. package/dist/bylines-RwBAeOF1.mjs +0 -214
  1132. package/dist/bylines-RwBAeOF1.mjs.map +0 -1
  1133. package/dist/cache-BF5Kvn59.mjs +0 -108
  1134. package/dist/cache-BF5Kvn59.mjs.map +0 -1
  1135. package/dist/capture-triggers-CNW1q3HK.mjs +0 -362
  1136. package/dist/capture-triggers-CNW1q3HK.mjs.map +0 -1
  1137. package/dist/challenge-store-DQN_Yrck.mjs +0 -51
  1138. package/dist/challenge-store-DQN_Yrck.mjs.map +0 -1
  1139. package/dist/chrome-tags-D8fiZG94.mjs +0 -24
  1140. package/dist/chrome-tags-D8fiZG94.mjs.map +0 -1
  1141. package/dist/chunks-C4szrD8o.mjs +0 -25
  1142. package/dist/chunks-C4szrD8o.mjs.map +0 -1
  1143. package/dist/collection-deletion-Bj07NHbj.mjs +0 -436
  1144. package/dist/collection-deletion-Bj07NHbj.mjs.map +0 -1
  1145. package/dist/comment-reaction-BhrvSHml.mjs +0 -85
  1146. package/dist/comment-reaction-BhrvSHml.mjs.map +0 -1
  1147. package/dist/comment-vxOzWbZN.mjs +0 -255
  1148. package/dist/comment-vxOzWbZN.mjs.map +0 -1
  1149. package/dist/comments-Ct4ensnf.mjs +0 -204
  1150. package/dist/comments-Ct4ensnf.mjs.map +0 -1
  1151. package/dist/components-DJbo1z0S.mjs +0 -108
  1152. package/dist/components-DJbo1z0S.mjs.map +0 -1
  1153. package/dist/config-B9eZ340f.d.mts +0 -34
  1154. package/dist/config-B9eZ340f.d.mts.map +0 -1
  1155. package/dist/config-C3EBstHi.mjs +0 -72
  1156. package/dist/config-C3EBstHi.mjs.map +0 -1
  1157. package/dist/config-it29yDLA.mjs +0 -1163
  1158. package/dist/config-it29yDLA.mjs.map +0 -1
  1159. package/dist/content-DjvM0T92.mjs +0 -1725
  1160. package/dist/content-DjvM0T92.mjs.map +0 -1
  1161. package/dist/content-list-query-Btqd4uV2.d.mts +0 -26
  1162. package/dist/content-list-query-Btqd4uV2.d.mts.map +0 -1
  1163. package/dist/content-refresh-Bwp-8yGy.mjs +0 -3588
  1164. package/dist/content-refresh-Bwp-8yGy.mjs.map +0 -1
  1165. package/dist/content-repair-Czdp7jz5.mjs +0 -440
  1166. package/dist/content-repair-Czdp7jz5.mjs.map +0 -1
  1167. package/dist/context-CX6gxOLW.mjs +0 -1068
  1168. package/dist/context-CX6gxOLW.mjs.map +0 -1
  1169. package/dist/cron-C6o7VppJ.mjs +0 -277
  1170. package/dist/cron-C6o7VppJ.mjs.map +0 -1
  1171. package/dist/dashboard-C2kTeeRI.mjs +0 -140
  1172. package/dist/dashboard-C2kTeeRI.mjs.map +0 -1
  1173. package/dist/db-errors-Cl-sKYTm.mjs +0 -55
  1174. package/dist/db-errors-Cl-sKYTm.mjs.map +0 -1
  1175. package/dist/default-Clra32mw.mjs +0 -81
  1176. package/dist/default-Clra32mw.mjs.map +0 -1
  1177. package/dist/deferred-tasks-CvDETTJO.d.mts +0 -9
  1178. package/dist/deferred-tasks-CvDETTJO.d.mts.map +0 -1
  1179. package/dist/dev-typegen-DzOPfsNj.mjs +0 -29
  1180. package/dist/dev-typegen-DzOPfsNj.mjs.map +0 -1
  1181. package/dist/device-flow-D2oCWvLJ.mjs +0 -466
  1182. package/dist/device-flow-D2oCWvLJ.mjs.map +0 -1
  1183. package/dist/dialect-helpers-BSbfaO3F.mjs +0 -202
  1184. package/dist/dialect-helpers-BSbfaO3F.mjs.map +0 -1
  1185. package/dist/direct-executor-Bfa5_ToE.mjs +0 -85
  1186. package/dist/direct-executor-Bfa5_ToE.mjs.map +0 -1
  1187. package/dist/dist-89xCrGqi.mjs +0 -810
  1188. package/dist/dist-89xCrGqi.mjs.map +0 -1
  1189. package/dist/email-console-Dzb6uGYa.mjs +0 -50
  1190. package/dist/email-console-Dzb6uGYa.mjs.map +0 -1
  1191. package/dist/enrich-BX0IDp4z.mjs +0 -194
  1192. package/dist/enrich-BX0IDp4z.mjs.map +0 -1
  1193. package/dist/error-DFrQjppn.mjs +0 -90
  1194. package/dist/error-DFrQjppn.mjs.map +0 -1
  1195. package/dist/errors-DsVoDUjJ.mjs +0 -427
  1196. package/dist/errors-DsVoDUjJ.mjs.map +0 -1
  1197. package/dist/escape-HmHTC1Is.mjs +0 -9
  1198. package/dist/escape-HmHTC1Is.mjs.map +0 -1
  1199. package/dist/field-defs-cache-BM4SIRqH.mjs +0 -77
  1200. package/dist/field-defs-cache-BM4SIRqH.mjs.map +0 -1
  1201. package/dist/focal-point-BeWFo6Xx.mjs +0 -23
  1202. package/dist/focal-point-BeWFo6Xx.mjs.map +0 -1
  1203. package/dist/fts-manager-Do1BlW2r.mjs +0 -413
  1204. package/dist/fts-manager-Do1BlW2r.mjs.map +0 -1
  1205. package/dist/hash-3JJPlHF2.mjs +0 -37
  1206. package/dist/hash-3JJPlHF2.mjs.map +0 -1
  1207. package/dist/hook-result-DCh2WUpe.d.mts +0 -31
  1208. package/dist/hook-result-DCh2WUpe.d.mts.map +0 -1
  1209. package/dist/hreflang-B6hbAuuO.d.mts +0 -48
  1210. package/dist/hreflang-B6hbAuuO.d.mts.map +0 -1
  1211. package/dist/hreflang-DQbPZliA.mjs +0 -102
  1212. package/dist/hreflang-DQbPZliA.mjs.map +0 -1
  1213. package/dist/identity-DksvEazf.mjs +0 -35
  1214. package/dist/identity-DksvEazf.mjs.map +0 -1
  1215. package/dist/import-CJpaBBBT.mjs +0 -2020
  1216. package/dist/import-CJpaBBBT.mjs.map +0 -1
  1217. package/dist/index-BJNMCWmu.d.mts +0 -6562
  1218. package/dist/index-BJNMCWmu.d.mts.map +0 -1
  1219. package/dist/index-Du8K7bWa.d.mts +0 -278
  1220. package/dist/index-Du8K7bWa.d.mts.map +0 -1
  1221. package/dist/init-lock-DJkX6Hto.mjs +0 -56
  1222. package/dist/init-lock-DJkX6Hto.mjs.map +0 -1
  1223. package/dist/load-CawHjTOH.mjs +0 -28
  1224. package/dist/load-CawHjTOH.mjs.map +0 -1
  1225. package/dist/loader-Z8vl7zTq.mjs +0 -966
  1226. package/dist/loader-Z8vl7zTq.mjs.map +0 -1
  1227. package/dist/manifest-builder-COtzuca2.mjs +0 -189
  1228. package/dist/manifest-builder-COtzuca2.mjs.map +0 -1
  1229. package/dist/manifest-schema-BNWwR8Vd.mjs +0 -301
  1230. package/dist/manifest-schema-BNWwR8Vd.mjs.map +0 -1
  1231. package/dist/media-BBm8Wg3f.mjs +0 -318
  1232. package/dist/media-BBm8Wg3f.mjs.map +0 -1
  1233. package/dist/media-BHjus86Y.mjs +0 -464
  1234. package/dist/media-BHjus86Y.mjs.map +0 -1
  1235. package/dist/media-allowlist-CoTBWoDp.mjs +0 -44
  1236. package/dist/media-allowlist-CoTBWoDp.mjs.map +0 -1
  1237. package/dist/media-folders-BGkATs8n.mjs +0 -210
  1238. package/dist/media-folders-BGkATs8n.mjs.map +0 -1
  1239. package/dist/media-upload-BCidR-EY.mjs +0 -147
  1240. package/dist/media-upload-BCidR-EY.mjs.map +0 -1
  1241. package/dist/media-url-DHoPr0hq.mjs +0 -26
  1242. package/dist/media-url-DHoPr0hq.mjs.map +0 -1
  1243. package/dist/media-usage-CdY5jhSR.mjs +0 -1833
  1244. package/dist/media-usage-CdY5jhSR.mjs.map +0 -1
  1245. package/dist/media-usage-activation-BgeMtK5C.mjs +0 -78
  1246. package/dist/media-usage-activation-BgeMtK5C.mjs.map +0 -1
  1247. package/dist/media-usage-work-CnGCdHxx.mjs +0 -152
  1248. package/dist/media-usage-work-CnGCdHxx.mjs.map +0 -1
  1249. package/dist/media-usage-work-D6D9sMCA.mjs +0 -586
  1250. package/dist/media-usage-work-D6D9sMCA.mjs.map +0 -1
  1251. package/dist/media-usage-write-fence-hjeD4u7s.mjs +0 -42
  1252. package/dist/media-usage-write-fence-hjeD4u7s.mjs.map +0 -1
  1253. package/dist/menus-6qSwTNxG.mjs +0 -4010
  1254. package/dist/menus-6qSwTNxG.mjs.map +0 -1
  1255. package/dist/menus-uvPLXMZf.mjs +0 -744
  1256. package/dist/menus-uvPLXMZf.mjs.map +0 -1
  1257. package/dist/mime-CUIG6x84.mjs +0 -36
  1258. package/dist/mime-CUIG6x84.mjs.map +0 -1
  1259. package/dist/mode-DN_WneRx.mjs +0 -23
  1260. package/dist/mode-DN_WneRx.mjs.map +0 -1
  1261. package/dist/node-sqlite-compat-BuJXIeMz.mjs +0 -46
  1262. package/dist/node-sqlite-compat-BuJXIeMz.mjs.map +0 -1
  1263. package/dist/normalize-C2xNjTSG.mjs +0 -191
  1264. package/dist/normalize-C2xNjTSG.mjs.map +0 -1
  1265. package/dist/oauth-authorization-Dj6Kwc21.mjs +0 -274
  1266. package/dist/oauth-authorization-Dj6Kwc21.mjs.map +0 -1
  1267. package/dist/oauth-clients-FD7I0J8m.mjs +0 -266
  1268. package/dist/oauth-clients-FD7I0J8m.mjs.map +0 -1
  1269. package/dist/oauth-state-store-DkmDOmHs.mjs +0 -50
  1270. package/dist/oauth-state-store-DkmDOmHs.mjs.map +0 -1
  1271. package/dist/oauth-user-lookup-CvIwGpYd.mjs +0 -26
  1272. package/dist/oauth-user-lookup-CvIwGpYd.mjs.map +0 -1
  1273. package/dist/object-cache-DVKnyOfy.mjs +0 -534
  1274. package/dist/object-cache-DVKnyOfy.mjs.map +0 -1
  1275. package/dist/options-BHPeIbBd.mjs +0 -117
  1276. package/dist/options-BHPeIbBd.mjs.map +0 -1
  1277. package/dist/options-CYb4y7hM.d.mts +0 -221
  1278. package/dist/options-CYb4y7hM.d.mts.map +0 -1
  1279. package/dist/parse-Ckpg-Qfp.mjs +0 -81
  1280. package/dist/parse-Ckpg-Qfp.mjs.map +0 -1
  1281. package/dist/passkey-config-O_lj3y0k.mjs +0 -46
  1282. package/dist/passkey-config-O_lj3y0k.mjs.map +0 -1
  1283. package/dist/patterns-D9iDO3j8.mjs +0 -145
  1284. package/dist/patterns-D9iDO3j8.mjs.map +0 -1
  1285. package/dist/placeholder-4X9BrRrp.d.mts +0 -306
  1286. package/dist/placeholder-4X9BrRrp.d.mts.map +0 -1
  1287. package/dist/policy-Dhtwntrt.mjs +0 -45
  1288. package/dist/policy-Dhtwntrt.mjs.map +0 -1
  1289. package/dist/portable-text-U85hOafW.mjs +0 -286
  1290. package/dist/portable-text-U85hOafW.mjs.map +0 -1
  1291. package/dist/preview-B_vJLvf8.mjs +0 -107
  1292. package/dist/preview-B_vJLvf8.mjs.map +0 -1
  1293. package/dist/protocol-JdD2YhY9.d.mts +0 -52
  1294. package/dist/protocol-JdD2YhY9.d.mts.map +0 -1
  1295. package/dist/public-url-CarhZJgf.mjs +0 -101
  1296. package/dist/public-url-CarhZJgf.mjs.map +0 -1
  1297. package/dist/query-BZKZcG5b.mjs +0 -881
  1298. package/dist/query-BZKZcG5b.mjs.map +0 -1
  1299. package/dist/query-BndaFxxp.mjs +0 -41
  1300. package/dist/query-BndaFxxp.mjs.map +0 -1
  1301. package/dist/rate-limit-BZmATC6W.mjs +0 -120
  1302. package/dist/rate-limit-BZmATC6W.mjs.map +0 -1
  1303. package/dist/redirect-CZkbozu9.mjs +0 -313
  1304. package/dist/redirect-CZkbozu9.mjs.map +0 -1
  1305. package/dist/redirect-CzqnLxK-.mjs +0 -17
  1306. package/dist/redirect-CzqnLxK-.mjs.map +0 -1
  1307. package/dist/redirects-BLNOWQTn.mjs +0 -1238
  1308. package/dist/redirects-BLNOWQTn.mjs.map +0 -1
  1309. package/dist/redirects-CqzNM0KM.mjs +0 -579
  1310. package/dist/redirects-CqzNM0KM.mjs.map +0 -1
  1311. package/dist/registry-AZAsRsor.mjs +0 -1179
  1312. package/dist/registry-AZAsRsor.mjs.map +0 -1
  1313. package/dist/relation-04DfKRTO.mjs +0 -334
  1314. package/dist/relation-04DfKRTO.mjs.map +0 -1
  1315. package/dist/relations-C4htk5sb.mjs +0 -309
  1316. package/dist/relations-C4htk5sb.mjs.map +0 -1
  1317. package/dist/relations-CcFwDJdJ.mjs +0 -403
  1318. package/dist/relations-CcFwDJdJ.mjs.map +0 -1
  1319. package/dist/relations-DnRK4YIT.d.mts +0 -3354
  1320. package/dist/relations-DnRK4YIT.d.mts.map +0 -1
  1321. package/dist/request-cache-DH9zdCOD.mjs +0 -104
  1322. package/dist/request-cache-DH9zdCOD.mjs.map +0 -1
  1323. package/dist/request-meta-DYxLlnmz.mjs +0 -140
  1324. package/dist/request-meta-DYxLlnmz.mjs.map +0 -1
  1325. package/dist/resolve-prZ3mP7l.mjs +0 -143
  1326. package/dist/resolve-prZ3mP7l.mjs.map +0 -1
  1327. package/dist/runner-BLIDKpmA.mjs +0 -4676
  1328. package/dist/runner-BLIDKpmA.mjs.map +0 -1
  1329. package/dist/runner-YKfIMnaF.d.mts +0 -67
  1330. package/dist/runner-YKfIMnaF.d.mts.map +0 -1
  1331. package/dist/schema-CGnBeLiW.mjs +0 -9
  1332. package/dist/schema-CGnBeLiW.mjs.map +0 -1
  1333. package/dist/schema-DYr-Vd-L.mjs +0 -420
  1334. package/dist/schema-DYr-Vd-L.mjs.map +0 -1
  1335. package/dist/scopes-BhWvBavj.mjs +0 -27
  1336. package/dist/scopes-BhWvBavj.mjs.map +0 -1
  1337. package/dist/search-C-qDk4kx.mjs +0 -439
  1338. package/dist/search-C-qDk4kx.mjs.map +0 -1
  1339. package/dist/secrets-rEtHt-6z.mjs +0 -330
  1340. package/dist/secrets-rEtHt-6z.mjs.map +0 -1
  1341. package/dist/sections-B_nYvlwn.mjs +0 -346
  1342. package/dist/sections-B_nYvlwn.mjs.map +0 -1
  1343. package/dist/seo-926NRIgt.mjs +0 -133
  1344. package/dist/seo-926NRIgt.mjs.map +0 -1
  1345. package/dist/seo-CVWkdv6x.mjs +0 -113
  1346. package/dist/seo-CVWkdv6x.mjs.map +0 -1
  1347. package/dist/service-CJl3ZAYs.mjs +0 -195
  1348. package/dist/service-CJl3ZAYs.mjs.map +0 -1
  1349. package/dist/session-user-BlMgqCHS.mjs +0 -51
  1350. package/dist/session-user-BlMgqCHS.mjs.map +0 -1
  1351. package/dist/settings--wobrkkC.mjs +0 -258
  1352. package/dist/settings--wobrkkC.mjs.map +0 -1
  1353. package/dist/settings-Cwm6o2jY.mjs +0 -51
  1354. package/dist/settings-Cwm6o2jY.mjs.map +0 -1
  1355. package/dist/setup-complete-DQbClIN2.mjs +0 -26
  1356. package/dist/setup-complete-DQbClIN2.mjs.map +0 -1
  1357. package/dist/setup-nonce-DZCFS2sn.mjs +0 -25
  1358. package/dist/setup-nonce-DZCFS2sn.mjs.map +0 -1
  1359. package/dist/single-flight-cache-BPuGPdcN.mjs +0 -104
  1360. package/dist/single-flight-cache-BPuGPdcN.mjs.map +0 -1
  1361. package/dist/site-url-BrxA_E9H.mjs +0 -16
  1362. package/dist/site-url-BrxA_E9H.mjs.map +0 -1
  1363. package/dist/slugify-B994zkXC.mjs +0 -17
  1364. package/dist/slugify-B994zkXC.mjs.map +0 -1
  1365. package/dist/snapshot--OCDTqdb.mjs +0 -216
  1366. package/dist/snapshot--OCDTqdb.mjs.map +0 -1
  1367. package/dist/ssrf-5sIM5jzl.mjs +0 -349
  1368. package/dist/ssrf-5sIM5jzl.mjs.map +0 -1
  1369. package/dist/state-BpFVsJZB.mjs +0 -136
  1370. package/dist/state-BpFVsJZB.mjs.map +0 -1
  1371. package/dist/status-B777-dXz.mjs +0 -30
  1372. package/dist/status-B777-dXz.mjs.map +0 -1
  1373. package/dist/target-BmR0iTwz.mjs +0 -27
  1374. package/dist/target-BmR0iTwz.mjs.map +0 -1
  1375. package/dist/taxonomies-DkAkMupr.mjs +0 -837
  1376. package/dist/taxonomies-DkAkMupr.mjs.map +0 -1
  1377. package/dist/taxonomies-Wfy_Lg12.mjs +0 -698
  1378. package/dist/taxonomies-Wfy_Lg12.mjs.map +0 -1
  1379. package/dist/taxonomy-tJepplLL.mjs +0 -484
  1380. package/dist/taxonomy-tJepplLL.mjs.map +0 -1
  1381. package/dist/tokens-BCO1oruF.mjs +0 -171
  1382. package/dist/tokens-BCO1oruF.mjs.map +0 -1
  1383. package/dist/transaction-0KOpOyMu.mjs +0 -29
  1384. package/dist/transaction-0KOpOyMu.mjs.map +0 -1
  1385. package/dist/transport-Dr3qtwXC.mjs +0 -136
  1386. package/dist/transport-Dr3qtwXC.mjs.map +0 -1
  1387. package/dist/transport-xh6YKW2G.d.mts +0 -42
  1388. package/dist/transport-xh6YKW2G.d.mts.map +0 -1
  1389. package/dist/trusted-proxy-BR5F1Otp.mjs +0 -51
  1390. package/dist/trusted-proxy-BR5F1Otp.mjs.map +0 -1
  1391. package/dist/types-3qNFPlci.mjs +0 -16
  1392. package/dist/types-3qNFPlci.mjs.map +0 -1
  1393. package/dist/types-75KIqzL9.mjs +0 -142
  1394. package/dist/types-75KIqzL9.mjs.map +0 -1
  1395. package/dist/types-B6GrPic4.d.mts +0 -1335
  1396. package/dist/types-B6GrPic4.d.mts.map +0 -1
  1397. package/dist/types-BuHW4xDE.d.mts +0 -259
  1398. package/dist/types-BuHW4xDE.d.mts.map +0 -1
  1399. package/dist/types-C00oyCZp.d.mts +0 -198
  1400. package/dist/types-C00oyCZp.d.mts.map +0 -1
  1401. package/dist/types-CDtkNSFQ.d.mts +0 -75
  1402. package/dist/types-CDtkNSFQ.d.mts.map +0 -1
  1403. package/dist/types-CPeXo1wF.d.mts +0 -124
  1404. package/dist/types-CPeXo1wF.d.mts.map +0 -1
  1405. package/dist/types-CQPWhPxE.mjs +0 -92
  1406. package/dist/types-CQPWhPxE.mjs.map +0 -1
  1407. package/dist/types-CXFkwEGC.d.mts +0 -198
  1408. package/dist/types-CXFkwEGC.d.mts.map +0 -1
  1409. package/dist/types-DM3vioBY.mjs +0 -18
  1410. package/dist/types-DM3vioBY.mjs.map +0 -1
  1411. package/dist/types-DczELMop.d.mts +0 -363
  1412. package/dist/types-DczELMop.d.mts.map +0 -1
  1413. package/dist/types-DfuTR6dL.mjs +0 -3
  1414. package/dist/types-FV23hEoW.d.mts +0 -743
  1415. package/dist/types-FV23hEoW.d.mts.map +0 -1
  1416. package/dist/types-xDMtUFnO.d.mts +0 -257
  1417. package/dist/types-xDMtUFnO.d.mts.map +0 -1
  1418. package/dist/upload-attempts-BsqoQ1fn.mjs +0 -27
  1419. package/dist/upload-attempts-BsqoQ1fn.mjs.map +0 -1
  1420. package/dist/url-pattern-D4c2czpJ.mjs +0 -33
  1421. package/dist/url-pattern-D4c2czpJ.mjs.map +0 -1
  1422. package/dist/user-BTZ40aq6.mjs +0 -171
  1423. package/dist/user-BTZ40aq6.mjs.map +0 -1
  1424. package/dist/utils-BKvNjjhY.mjs +0 -435
  1425. package/dist/utils-BKvNjjhY.mjs.map +0 -1
  1426. package/dist/validate-BpwoDOgt.mjs +0 -120
  1427. package/dist/validate-BpwoDOgt.mjs.map +0 -1
  1428. package/dist/validate-DE_LRwo9.mjs +0 -379
  1429. package/dist/validate-DE_LRwo9.mjs.map +0 -1
  1430. package/dist/validate-DUP27OYD.d.mts +0 -400
  1431. package/dist/validate-DUP27OYD.d.mts.map +0 -1
  1432. package/dist/validation-BMImFJ11.mjs +0 -153
  1433. package/dist/validation-BMImFJ11.mjs.map +0 -1
  1434. package/dist/version-Bii3suaO.mjs +0 -7
  1435. package/dist/version-Bii3suaO.mjs.map +0 -1
  1436. package/dist/widgets-D3gJ10xU.mjs +0 -122
  1437. package/dist/widgets-D3gJ10xU.mjs.map +0 -1
  1438. package/dist/wxr-taxonomies-B2Og_6rU.d.mts +0 -34
  1439. package/dist/wxr-taxonomies-B2Og_6rU.d.mts.map +0 -1
  1440. package/dist/wxr-taxonomies-Cxngsjwo.mjs +0 -406
  1441. package/dist/wxr-taxonomies-Cxngsjwo.mjs.map +0 -1
  1442. package/dist/zod-generator-BuYSQJB7.mjs +0 -331
  1443. package/dist/zod-generator-BuYSQJB7.mjs.map +0 -1
  1444. /package/dist/{api-tokens-BfYts-sq.mjs → api-tokens-DS1VzN7_.mjs} +0 -0
  1445. /package/dist/{ssrf-Dg3cIT-b.mjs → ssrf-BRpTDMV6.mjs} +0 -0
@@ -1,109 +1,108 @@
1
- import { r as MIGRATION_RACE_WAIT_MS, t as ConcurrentMigrationTimeoutError } from "../runner-BLIDKpmA.mjs";
2
- import { c as isSqlite, u as listTablesLike } from "../dialect-helpers-BSbfaO3F.mjs";
3
- import { r as getI18nConfig, s as setI18nConfig } from "../config-C3EBstHi.mjs";
4
- import { A as resolveExclusiveHooks, C as parseRouteInput, D as isContentSaveRejection, S as buildRouteMeta, T as EmailPipeline, c as inspectSandboxHookResult, f as getSandboxRouteErrorDetails, j as definePlugin, k as createHookPipeline, t as getMenu, w as toRouteCallerInfo, x as PluginRouteRegistry, z as AuditRepository } from "../menus-6qSwTNxG.mjs";
5
- import { n as createDeferredTaskTracker, t as after } from "../after-CBU2vkoO.mjs";
1
+ import "../runner-ClrleR8A.mjs";
2
+ import { n as isMissingTableError } from "../db-errors-CBD5yMro.mjs";
3
+ import "../dialect-helpers-CtYdsX4W.mjs";
4
+ import { s as setI18nConfig } from "../config-CGVeT8Hc.mjs";
5
+ import "../datetime-normalization-PeiEdcRY.mjs";
6
+ import { M as EmDashConfigurationError, t as getMenu } from "../menus-DbgU9z5Q.mjs";
7
+ import { n as createDeferredTaskTracker, t as after } from "../after-PcEvMY_6.mjs";
6
8
  import { createRequestMetrics, getRequestContext, runWithContext } from "../request-context.mjs";
7
- import { o as getLastContentWriteAt } from "../object-cache-DVKnyOfy.mjs";
8
- import { i as RevisionRepository, t as ContentRepository } from "../content-DjvM0T92.mjs";
9
- import { n as isMissingTableError } from "../db-errors-Cl-sKYTm.mjs";
10
- import "../slugify-B994zkXC.mjs";
11
- import "../base64-CvLhUKQv.mjs";
12
- import { n as ContentMutationConflictError } from "../types-CQPWhPxE.mjs";
13
- import { t as MediaRepository } from "../media-BBm8Wg3f.mjs";
14
- import "../user-BTZ40aq6.mjs";
15
- import "../taxonomy-tJepplLL.mjs";
16
- import "../comment-vxOzWbZN.mjs";
17
- import { t as OptionsRepository } from "../options-BHPeIbBd.mjs";
18
- import { r as createSiteInfo } from "../context-CX6gxOLW.mjs";
19
- import "../menus-uvPLXMZf.mjs";
20
- import "../redirect-CZkbozu9.mjs";
21
- import { i as setRequestCacheEntry, r as requestCached } from "../request-cache-DH9zdCOD.mjs";
22
- import "../byline-registry-Bpu9-MVs.mjs";
23
- import { n as initWithLock, t as createInitLock } from "../init-lock-DJkX6Hto.mjs";
24
- import "../field-defs-cache-BM4SIRqH.mjs";
25
- import "../byline-DuhF7NWl.mjs";
26
- import "../relation-04DfKRTO.mjs";
27
- import { n as normalizeMediaValue } from "../normalize-C2xNjTSG.mjs";
28
- import "../dist-89xCrGqi.mjs";
29
- import "../enrich-BX0IDp4z.mjs";
30
- import "../seo-926NRIgt.mjs";
31
- import { r as singleFlightCached, t as createSingleFlightCache } from "../single-flight-cache-BPuGPdcN.mjs";
32
- import "../cache-BF5Kvn59.mjs";
33
- import { t as FTSManager } from "../fts-manager-Do1BlW2r.mjs";
34
- import "../resolve-prZ3mP7l.mjs";
35
- import { createRecorder, flushRecorder, isInstrumentationEnabled, kyselyLogOption } from "../database/instrumentation.mjs";
36
- import { s as getDb } from "../loader-Z8vl7zTq.mjs";
37
- import { a as getTaxonomyDefs, o as getTaxonomyTerms } from "../taxonomies-Wfy_Lg12.mjs";
38
- import { $ as validateRev, A as handleRevisionRestore, B as handleContentDuplicate, C as handleMediaDelete, D as handleMediaUpdate, E as handleMediaReplaceMetadata, F as handleContentCountScheduled, G as handleContentPermanentDelete, H as handleContentGetIncludingTrashed, I as handleContentCountTrashed, J as handleContentSchedule, K as handleContentPublish, L as handleContentCreate, N as handleContentAuthors, O as handleRevisionGet, P as handleContentCompare, Q as handleContentUpdate, R as handleContentDelete, S as handleMediaCreate, T as handleMediaList, U as handleContentList, V as handleContentGet, W as handleContentListTrashed, X as handleContentUnpublish, Y as handleContentTranslations, Z as handleContentUnschedule, j as buildManifestCollections, k as handleRevisionList, m as syncDeclaredStorageIndexes, p as loadBundleFromR2, q as handleContentRestore, w as handleMediaGet, z as handleContentDiscardDraft } from "../api-Dz6rgoa3.mjs";
39
- import { n as recordSchedulerHeartbeatSafely } from "../dashboard-C2kTeeRI.mjs";
40
- import "../capture-triggers-CNW1q3HK.mjs";
41
- import { r as activateMediaUsageCapture } from "../activation-K0kGBWuJ.mjs";
42
- import "../collection-deletion-Bj07NHbj.mjs";
43
- import { c as markContentMediaUsageCollectionStale, i as deleteContentMediaUsage, o as findNonTranslatableSiblingContentIds, u as refreshContentMediaUsageAfterWrite, y as MediaUsageRepository } from "../content-refresh-Bwp-8yGy.mjs";
44
- import { n as SchemaRegistry } from "../registry-AZAsRsor.mjs";
45
- import { r as hashString } from "../hash-3JJPlHF2.mjs";
46
- import "../media-folders-BGkATs8n.mjs";
47
- import "../media-usage-work-D6D9sMCA.mjs";
48
- import "../content-repair-Czdp7jz5.mjs";
49
- import { s as processMediaUsageWorkAfterWrite } from "../media-usage-CdY5jhSR.mjs";
50
- import { t as ErrorCode } from "../errors-DsVoDUjJ.mjs";
51
- import "../media-usage-activation-BgeMtK5C.mjs";
52
- import "../media-usage-work-CnGCdHxx.mjs";
53
- import "../query-BndaFxxp.mjs";
54
- import "../zod-generator-BuYSQJB7.mjs";
55
- import "../schema-CGnBeLiW.mjs";
56
- import "../schema-DYr-Vd-L.mjs";
57
- import "../seo-CVWkdv6x.mjs";
58
- import { t as PluginStateRepository } from "../state-BpFVsJZB.mjs";
59
- import "../sections-B_nYvlwn.mjs";
60
- import { i as getSiteSettings, s as invalidateSiteSettingsCache } from "../settings--wobrkkC.mjs";
61
- import "../settings-Cwm6o2jY.mjs";
62
- import "../taxonomies-DkAkMupr.mjs";
63
- import { r as normalizeManifestRoute } from "../manifest-schema-BNWwR8Vd.mjs";
64
- import "../types-DfuTR6dL.mjs";
65
- import { r as normalizeRegistryConfig } from "../config-it29yDLA.mjs";
66
- import "../ssrf-5sIM5jzl.mjs";
67
- import "../error-DFrQjppn.mjs";
68
- import "../parse-Ckpg-Qfp.mjs";
69
- import "../media-BHjus86Y.mjs";
70
- import "../redirects-BLNOWQTn.mjs";
71
- import "../relations-C4htk5sb.mjs";
72
- import "../status-B777-dXz.mjs";
73
- import { a as invalidateUrlPatternCache } from "../query-BZKZcG5b.mjs";
74
- import "../import-CJpaBBBT.mjs";
75
- import { t as getTrustedProxyHeaders } from "../trusted-proxy-BR5F1Otp.mjs";
76
- import { n as sanitizeHeadersForSandbox, t as extractRequestMeta } from "../request-meta-DYxLlnmz.mjs";
77
- import "../ssrf-Dg3cIT-b.mjs";
78
- import { n as CronExecutor } from "../cron-C6o7VppJ.mjs";
79
- import { r as devConsoleEmailDeliver, t as DEV_CONSOLE_EMAIL_PLUGIN_ID } from "../email-console-Dzb6uGYa.mjs";
80
- import { n as assertMediaUsageActivationWriteAllowed } from "../media-usage-write-fence-hjeD4u7s.mjs";
81
- import "../utils-BKvNjjhY.mjs";
82
- import "../tokens-BCO1oruF.mjs";
83
- import "../preview-B_vJLvf8.mjs";
84
- import "../hreflang-DQbPZliA.mjs";
85
- import "../comment-reaction-BhrvSHml.mjs";
86
- import "../bylines-CJ5nd6Lw.mjs";
87
- import { r as getWidgetAreas } from "../widgets-D3gJ10xU.mjs";
88
- import "../validate-DE_LRwo9.mjs";
89
- import "../apply-B4SIOxR1.mjs";
90
- import "../load-CawHjTOH.mjs";
91
- import "../search-C-qDk4kx.mjs";
92
- import "../index.mjs";
93
- import { i as resolveRuntimeMigrationMode, n as enforceRuntimeMigrationPolicy, t as PendingMigrationsError } from "../policy-Dhtwntrt.mjs";
94
- import { n as VERSION, t as COMMIT } from "../version-Bii3suaO.mjs";
95
- import { t as getAuthMode } from "../mode-DN_WneRx.mjs";
96
- import "../snapshot--OCDTqdb.mjs";
97
- import { u as maybeRunScheduledBackup } from "../backup-rwVAl9NI.mjs";
98
- import { t as cleanupExpiredChallenges } from "../challenge-store-DQN_Yrck.mjs";
99
- import { t as removeUploadAttempt } from "../upload-attempts-BsqoQ1fn.mjs";
100
- import { a as validateEncryptionKeyAtStartup } from "../secrets-rEtHt-6z.mjs";
101
- import { isRecord } from "../plugin-utils.mjs";
102
- import { t as resolveSessionUser } from "../session-user-BlMgqCHS.mjs";
103
- import { Kysely, sql } from "kysely";
104
- import { ulid } from "ulidx";
105
- import { z } from "zod";
106
- import { Permissions } from "@emdash-cms/auth";
9
+ import "../options-D5WcorD5.mjs";
10
+ import "../base64-DvnNgP7e.mjs";
11
+ import { n as initWithLock, t as createInitLock } from "../init-lock-4eRRB4Le.mjs";
12
+ import "../secrets-DNgVgz_e.mjs";
13
+ import "../content-DZ3B5qtA.mjs";
14
+ import { o as getLastContentWriteAt } from "../object-cache-DlSVbn5Y.mjs";
15
+ import "../slugify-T5GHH42D.mjs";
16
+ import "../types-BkUg2yHx.mjs";
17
+ import "../media-TBlKCwo7.mjs";
18
+ import "../user-DroRntkx.mjs";
19
+ import "../taxonomy-Dj1vpw5E.mjs";
20
+ import "../comment-DcT8qdPK.mjs";
21
+ import "../context-B195kjqZ.mjs";
22
+ import "../menus-Wy8m5NcH.mjs";
23
+ import "../resolve-BJIS8wKr.mjs";
24
+ import "../redirect-D2Yo-b6S.mjs";
25
+ import { i as setRequestCacheEntry, r as requestCached } from "../request-cache-DaMhSQdx.mjs";
26
+ import "../byline-registry-D6lWzXk6.mjs";
27
+ import "../field-defs-cache-B337z8UJ.mjs";
28
+ import "../byline-Doh-wt99.mjs";
29
+ import "../relation-XTAtOpJO.mjs";
30
+ import "../dist-2hDLsLeq.mjs";
31
+ import "../enrich-C2Mk0lwE.mjs";
32
+ import "../entry-locks-CO_KaoU5.mjs";
33
+ import "../seo-_4qmazxz.mjs";
34
+ import "../cache-B0pOlXdM.mjs";
35
+ import "../fts-manager-DMb0sbIQ.mjs";
36
+ import { createRecorder, flushRecorder, isInstrumentationEnabled } from "../database/instrumentation.mjs";
37
+ import { s as getDb } from "../loader-t4TxaFiQ.mjs";
38
+ import "../collection-slugs-cache-D9auiKmI.mjs";
39
+ import { a as getTaxonomyDefs, o as getTaxonomyTerms } from "../taxonomies-BpqpXJUE.mjs";
40
+ import "../api-DmjKxPCY.mjs";
41
+ import "../dashboard-CZD4G7k_.mjs";
42
+ import "../capture-triggers-gxQxnxrJ.mjs";
43
+ import "../activation-CaMfdBt1.mjs";
44
+ import "../collection-deletion-C3Xixmkx.mjs";
45
+ import "../content-refresh-BHLHJgyt.mjs";
46
+ import "../registry-CkuPoZs7.mjs";
47
+ import "../hash-CLVFzWvx.mjs";
48
+ import "../media-folders-ClIRLUQv.mjs";
49
+ import "../media-usage-work-Cu5DqewW.mjs";
50
+ import "../content-repair-BVll5WNl.mjs";
51
+ import "../media-usage-C4NolTpQ.mjs";
52
+ import "../media-usage-activation-CAhmb14O.mjs";
53
+ import "../media-usage-work-DJr3rOEN.mjs";
54
+ import "../query-D7kHKOws.mjs";
55
+ import "../zod-generator-D_yHIWfs.mjs";
56
+ import "../schema-DEERRrKS.mjs";
57
+ import "../schema-CPhPM9Do.mjs";
58
+ import "../seo-BtU70b7l.mjs";
59
+ import { i as getSiteSettings } from "../settings-DmroR53o.mjs";
60
+ import "../sections-BIpd4Cxf.mjs";
61
+ import "../settings-g2F2a3Ub.mjs";
62
+ import "../taxonomies-ClCo4IGO.mjs";
63
+ import "../manifest-schema-Bkh8SeHd.mjs";
64
+ import { t as EmDashStorageError } from "../types-BtuppOTV.mjs";
65
+ import "../artifact-fetch-COiMhVgk.mjs";
66
+ import "../ssrf-Co1GGFZz.mjs";
67
+ import "../authoritative-records-DbqshfKD.mjs";
68
+ import "../config-B2acLeC5.mjs";
69
+ import { t as apiError } from "../error-CCTCskie.mjs";
70
+ import "../parse-Cr379Av9.mjs";
71
+ import "../redirects-BCiTaIQ-.mjs";
72
+ import "../entry-lock-D3C99MXS.mjs";
73
+ import "../comments-BVzzt6x5.mjs";
74
+ import "../relations-B4w-G5U9.mjs";
75
+ import "../status-DLoBmcDz.mjs";
76
+ import { a as invalidateUrlPatternCache } from "../query-D-lxiOgn.mjs";
77
+ import "../import-DFr5B_hC.mjs";
78
+ import "../redirects-ByItliuu.mjs";
79
+ import "../ssrf-BRpTDMV6.mjs";
80
+ import "../cron-BcR3RN4K.mjs";
81
+ import "../email-console-gc-E3Eqj.mjs";
82
+ import "../media-usage-write-fence-DW5oHT7q.mjs";
83
+ import "../route-wire-D66L2oaZ.mjs";
84
+ import "../routes-DYsTe-oR.mjs";
85
+ import "../utils-CC2oNGV8.mjs";
86
+ import "../tokens-Ns02GAma.mjs";
87
+ import "../preview-Cup2bj8c.mjs";
88
+ import "../hreflang-CrJwqoeb.mjs";
89
+ import "../comment-reaction-DY5-y8Y5.mjs";
90
+ import "../bylines-kpBzHPr8.mjs";
91
+ import { r as getWidgetAreas } from "../widgets-wQ7Xcgq8.mjs";
92
+ import "../validate-BCP9HNDn.mjs";
93
+ import "../apply-drpfmqrR.mjs";
94
+ import "../load-Cu5bvCZh.mjs";
95
+ import "../search-lami_Ota.mjs";
96
+ import { i as resolveRuntimeMigrationMode, t as PendingMigrationsError } from "../policy-lyZnjpwz.mjs";
97
+ import { n as EmDashRuntime, t as DB_INIT_DEADLINE_MS } from "../emdash-runtime-DZGinqTL.mjs";
98
+ import "../site-url-DjhYCaep.mjs";
99
+ import "../public-submission-Cs-pFMQK.mjs";
100
+ import "../snapshot-C32Xuv3o.mjs";
101
+ import "../backup-BsPQdwnS.mjs";
102
+ import "../comments-B67VRNGw.mjs";
103
+ import "../service-Bpy5iTX0.mjs";
104
+ import "../lifecycle-7e-Lt_kX.mjs";
105
+ import { t as resolveSessionUser } from "../session-user-BQeS2Mrb.mjs";
107
106
  import { defineMiddleware } from "astro:middleware";
108
107
  import { buildTime } from "virtual:emdash/build";
109
108
  import virtualConfig from "virtual:emdash/config";
@@ -114,2941 +113,7 @@ import * as virtualSandboxRunnerModule from "virtual:emdash/sandbox-runner";
114
113
  import { sandboxedPlugins } from "virtual:emdash/sandboxed-plugins";
115
114
  import { createScheduler } from "virtual:emdash/scheduler";
116
115
  import { createStorage } from "virtual:emdash/storage";
117
- import { createKyselyAdapter } from "@emdash-cms/auth/adapters/kysely";
118
116
 
119
- //#region src/i18n/repair-locale-casing.ts
120
- /** Rewrite stored locales to the exact casing used by the site configuration. */
121
- async function repairLocaleCasing(db, configuredLocales) {
122
- const tableNames = await listTablesLike(db, "ec_%");
123
- for (const tableName of tableNames) {
124
- const table = sql.ref(tableName);
125
- for (const locale of configuredLocales) await sql`
126
- UPDATE ${table} AS target
127
- SET locale = ${locale}
128
- WHERE lower(target.locale) = lower(${locale})
129
- AND target.locale != ${locale}
130
- AND NOT EXISTS (
131
- SELECT 1
132
- FROM ${table} AS existing
133
- WHERE existing.slug = target.slug AND existing.locale = ${locale}
134
- )
135
- AND target.id = (
136
- SELECT MIN(candidate.id)
137
- FROM ${table} AS candidate
138
- WHERE candidate.slug = target.slug
139
- AND lower(candidate.locale) = lower(${locale})
140
- AND candidate.locale != ${locale}
141
- )
142
- `.execute(db);
143
- }
144
- }
145
-
146
- //#endregion
147
- //#region src/i18n/taxonomy-locale-diagnostic.ts
148
- const REPAIR_GUIDE = "https://docs.emdashcms.com/guides/internationalization/#repairing-taxonomy-locale-mismatches";
149
- async function warnAboutUnconfiguredTaxonomyLocales(db, configuredLocales, definitionLocales) {
150
- const supportedLocales = configuredLocales.length > 0 ? configuredLocales : ["en"];
151
- const definitionRows = definitionLocales === void 0 ? await db.selectFrom("_emdash_taxonomy_defs").select("locale").distinct().where("locale", "not in", supportedLocales).execute() : [...new Set(definitionLocales)].filter((locale) => !supportedLocales.includes(locale)).map((locale) => ({ locale }));
152
- const termRows = await db.selectFrom("taxonomies").select("locale").distinct().where("locale", "not in", supportedLocales).execute();
153
- const mismatches = [...definitionRows.map(({ locale }) => ({
154
- source: "definitions",
155
- locale
156
- })), ...termRows.map(({ locale }) => ({
157
- source: "terms",
158
- locale
159
- }))].toSorted((a, b) => a.source.localeCompare(b.source) || a.locale.localeCompare(b.locale));
160
- if (mismatches.length === 0) return;
161
- const details = mismatches.map(({ source, locale }) => `${source}: ${locale}`).join("; ");
162
- console.warn(`EmDash: Taxonomy rows use locales outside the configured locales (${supportedLocales.join(", ")}): ${details}. Locale-scoped reads may not return these rows. Review and repair them explicitly: ${REPAIR_GUIDE}`);
163
- }
164
-
165
- //#endregion
166
- //#region src/plugins/sandbox/runner-options.ts
167
- /**
168
- * Build platform sandbox options with the same normalized site context used
169
- * by trusted plugin hooks and routes.
170
- */
171
- function createSandboxRunnerOptions(options, siteInfo) {
172
- return {
173
- ...options,
174
- siteInfo: createSiteInfo(siteInfo ?? {})
175
- };
176
- }
177
-
178
- //#endregion
179
- //#region src/media/usage/cleanup.ts
180
- const MEDIA_USAGE_CLEANUP_CANDIDATE_LIMIT = 250;
181
- const MEDIA_USAGE_CLEANUP_DELETE_LIMIT = 50;
182
- const MEDIA_USAGE_CLEANUP_WRITE_LEASE_DELETE_LIMIT = 49;
183
- const MEDIA_USAGE_CLEANUP_INTERVAL_MS = 60 * 1e3;
184
- const MEDIA_USAGE_CLEANUP_LEASE_MS = 300 * 1e3;
185
- const MEDIA_USAGE_CLEANUP_SAFETY_WINDOW_MS = 3600 * 1e3;
186
- const MEDIA_USAGE_CLEANUP_TIME_BUDGET_MS = 5 * 1e3;
187
- /**
188
- * Reclaims a bounded window of obsolete media-usage occurrences.
189
- *
190
- * The persisted claim makes a cron tick single-flight across Worker isolates
191
- * and Node processes.
192
- */
193
- async function cleanupMediaUsage(db) {
194
- const startedMs = Date.now();
195
- const canIssueStatement = () => withinBudget(startedMs);
196
- const repo = new MediaUsageRepository(db);
197
- const leaseToken = ulid();
198
- const claim = await repo.claimMediaUsageCleanup({
199
- leaseToken,
200
- leaseDurationSeconds: MEDIA_USAGE_CLEANUP_LEASE_MS / 1e3,
201
- nextEligibleDelaySeconds: MEDIA_USAGE_CLEANUP_INTERVAL_MS / 1e3,
202
- sweepSafetyWindowSeconds: MEDIA_USAGE_CLEANUP_SAFETY_WINDOW_MS / 1e3
203
- });
204
- if (!claim) return emptyResult("skipped", elapsedSince(startedMs));
205
- let candidateRows = 0;
206
- let deletedOrphans = 0;
207
- let deletedStale = 0;
208
- let deletedAbandoned = 0;
209
- let deletedWriteLeases = 0;
210
- let backlogLowerBound = 0;
211
- let scanHasMore = false;
212
- let nextCursor = claim.cursor;
213
- let sweepComplete = false;
214
- try {
215
- if (canIssueStatement()) deletedWriteLeases = await repo.deleteExpiredGenerationWriteLeases(MEDIA_USAGE_CLEANUP_WRITE_LEASE_DELETE_LIMIT, cleanupLease(leaseToken), canIssueStatement);
216
- const cutoff = claim.scanBeforeAt;
217
- const candidates = await repo.findMediaUsageCleanupCandidates({
218
- cutoff,
219
- cursor: claim.cursor,
220
- limit: MEDIA_USAGE_CLEANUP_CANDIDATE_LIMIT,
221
- cleanupLease: cleanupLease(leaseToken),
222
- canIssueStatement
223
- });
224
- if (candidates) {
225
- candidateRows = candidates.length;
226
- scanHasMore = candidates.length === MEDIA_USAGE_CLEANUP_CANDIDATE_LIMIT;
227
- const selected = selectCleanupCandidates(candidates, claim.claimedAt);
228
- backlogLowerBound = selected.orphanIds.length + selected.staleIds.length + selected.abandonedIds.length;
229
- const completedTargets = /* @__PURE__ */ new Set();
230
- let canContinue = true;
231
- if (canIssueStatement() && selected.orphanIds.length > 0) {
232
- deletedOrphans = await repo.deleteOrphanOccurrencesOlderThan(cutoff, selected.orphanIds.length, {
233
- candidateIds: selected.orphanIds,
234
- cleanupLease: cleanupLease(leaseToken),
235
- canIssueStatement
236
- });
237
- canContinue = deletedOrphans === selected.orphanIds.length;
238
- if (canContinue) completedTargets.add("orphan");
239
- }
240
- if (canContinue && canIssueStatement() && selected.staleIds.length > 0) {
241
- deletedStale = await repo.deleteStaleGenerationsOlderThan(cutoff, selected.staleIds.length, {
242
- candidateIds: selected.staleIds,
243
- cleanupLease: cleanupLease(leaseToken),
244
- canIssueStatement
245
- });
246
- canContinue = deletedStale === selected.staleIds.length;
247
- if (canContinue) completedTargets.add("stale");
248
- }
249
- if (canContinue && canIssueStatement() && selected.abandonedIds.length > 0) {
250
- deletedAbandoned = await repo.deleteAbandonedGenerationsOlderThan(cutoff, selected.abandonedIds.length, {
251
- candidateIds: selected.abandonedIds,
252
- cleanupLease: cleanupLease(leaseToken),
253
- canIssueStatement
254
- });
255
- if (deletedAbandoned === selected.abandonedIds.length) completedTargets.add("abandoned");
256
- }
257
- const hasIncompleteTargets = selected.entries.some((entry) => entry.target !== null && !completedTargets.has(entry.target));
258
- sweepComplete = !scanHasMore && selected.entries.length === candidates.length && !hasIncompleteTargets;
259
- nextCursor = sweepComplete ? null : cursorAfterCompletedCandidates(selected, completedTargets, claim.cursor);
260
- }
261
- const durationMs = elapsedSince(startedMs);
262
- return {
263
- status: await repo.completeMediaUsageCleanup({
264
- leaseToken,
265
- nextCursor,
266
- sweepComplete,
267
- candidateCount: candidateRows,
268
- deletedOrphans,
269
- deletedStale,
270
- deletedAbandoned,
271
- deletedWriteLeases,
272
- backlogLowerBound,
273
- scanHasMore,
274
- durationMs
275
- }) ? "completed" : "skipped",
276
- candidateRows,
277
- deletedRows: deletedOrphans + deletedStale + deletedAbandoned,
278
- deletedOrphans,
279
- deletedStale,
280
- deletedAbandoned,
281
- deletedWriteLeases,
282
- backlogLowerBound,
283
- scanHasMore,
284
- durationMs
285
- };
286
- } catch (error) {
287
- const durationMs = elapsedSince(startedMs);
288
- const failures = Math.min(claim.consecutiveFailures + 1, 5);
289
- try {
290
- await repo.failMediaUsageCleanup({
291
- leaseToken,
292
- retryDelaySeconds: failureDelayMs(failures) / 1e3,
293
- consecutiveFailures: failures,
294
- durationMs,
295
- errorCode: "MEDIA_USAGE_CLEANUP_FAILED"
296
- });
297
- } catch (failureError) {
298
- console.error("[media-usage-cleanup] Failed to record cleanup failure:", failureError);
299
- }
300
- console.error("[media-usage-cleanup] Cleanup failed:", error);
301
- return {
302
- ...emptyResult("failed", durationMs),
303
- candidateRows,
304
- deletedRows: deletedOrphans + deletedStale + deletedAbandoned,
305
- deletedOrphans,
306
- deletedStale,
307
- deletedAbandoned,
308
- deletedWriteLeases,
309
- backlogLowerBound,
310
- scanHasMore
311
- };
312
- }
313
- }
314
- function selectCleanupCandidates(candidates, activeLeaseAt) {
315
- const orphanIds = [];
316
- const staleIds = [];
317
- const abandonedIds = [];
318
- const entries = [];
319
- for (const candidate of candidates) {
320
- if (hasActiveWriteLease(candidate, activeLeaseAt)) {
321
- entries.push({
322
- candidate,
323
- target: null
324
- });
325
- continue;
326
- }
327
- const target = cleanupTarget(candidate);
328
- if (target === null) {
329
- entries.push({
330
- candidate,
331
- target: null
332
- });
333
- continue;
334
- }
335
- if (orphanIds.length + staleIds.length + abandonedIds.length >= MEDIA_USAGE_CLEANUP_DELETE_LIMIT) break;
336
- if (target === "orphan") orphanIds.push(candidate.id);
337
- if (target === "stale") staleIds.push(candidate.id);
338
- if (target === "abandoned") abandonedIds.push(candidate.id);
339
- entries.push({
340
- candidate,
341
- target
342
- });
343
- }
344
- return {
345
- orphanIds,
346
- staleIds,
347
- abandonedIds,
348
- entries
349
- };
350
- }
351
- function cleanupTarget(candidate) {
352
- if (candidate.currentGeneration === null) return "orphan";
353
- if (candidate.currentGeneration === candidate.generation || candidate.indexedAt === null) return null;
354
- return candidate.createdAt < candidate.indexedAt ? "stale" : "abandoned";
355
- }
356
- function hasActiveWriteLease(candidate, activeLeaseAt) {
357
- return candidate.writeLeaseExpiresAt !== null && candidate.writeLeaseExpiresAt > activeLeaseAt;
358
- }
359
- function cursorFor(candidate) {
360
- return {
361
- createdAt: candidate.createdAt,
362
- id: candidate.id
363
- };
364
- }
365
- function cursorAfterCompletedCandidates(selected, completedTargets, priorCursor) {
366
- let cursor = priorCursor;
367
- for (const entry of selected.entries) {
368
- if (entry.target !== null && !completedTargets.has(entry.target)) break;
369
- cursor = cursorFor(entry.candidate);
370
- }
371
- return cursor;
372
- }
373
- function emptyResult(status, durationMs) {
374
- return {
375
- status,
376
- candidateRows: 0,
377
- deletedRows: 0,
378
- deletedOrphans: 0,
379
- deletedStale: 0,
380
- deletedAbandoned: 0,
381
- deletedWriteLeases: 0,
382
- backlogLowerBound: 0,
383
- scanHasMore: false,
384
- durationMs
385
- };
386
- }
387
- function withinBudget(startedMs) {
388
- return elapsedSince(startedMs) < MEDIA_USAGE_CLEANUP_TIME_BUDGET_MS;
389
- }
390
- function elapsedSince(startedMs) {
391
- return Math.max(0, Date.now() - startedMs);
392
- }
393
- function failureDelayMs(consecutiveFailures) {
394
- return Math.min(2 ** (consecutiveFailures - 1), 15) * MEDIA_USAGE_CLEANUP_INTERVAL_MS;
395
- }
396
- function cleanupLease(leaseToken) {
397
- return { leaseToken };
398
- }
399
-
400
- //#endregion
401
- //#region src/cleanup.ts
402
- /**
403
- * System cleanup
404
- *
405
- * Runs periodic maintenance tasks that prevent unbounded accumulation of
406
- * expired or stale data. Called from cron scheduler ticks and (for latency-
407
- * sensitive subsystems) inline during relevant requests.
408
- *
409
- * Each subsystem cleanup is independent and non-fatal -- if one fails, the
410
- * rest still run. Failures are logged but never surface to callers.
411
- */
412
- const REVISION_KEEP_COUNT = 50;
413
- const REVISION_PRUNE_BATCH_SIZE = 10;
414
- /**
415
- * Run all system cleanup tasks.
416
- *
417
- * Safe to call frequently -- each subsystem tolerates repeated calls, and
418
- * repeated calls with nothing to clean are cheap.
419
- *
420
- * @param db - The database instance
421
- * @param storage - Optional storage backend for deleting orphaned files.
422
- * When omitted, pending upload DB rows are still deleted but the
423
- * corresponding files in object storage are not removed.
424
- */
425
- async function runSystemCleanup(db, storage) {
426
- const result = {
427
- challenges: -1,
428
- expiredTokens: -1,
429
- pendingUploads: -1,
430
- pendingUploadFiles: -1,
431
- uploadAttempts: -1,
432
- revisionsPruned: -1,
433
- mediaUsage: -1
434
- };
435
- try {
436
- result.challenges = await cleanupExpiredChallenges(db);
437
- } catch (error) {
438
- console.error("[cleanup] Failed to clean expired challenges:", error);
439
- }
440
- try {
441
- await createKyselyAdapter(db).deleteExpiredTokens();
442
- result.expiredTokens = 0;
443
- } catch (error) {
444
- console.error("[cleanup] Failed to clean expired tokens:", error);
445
- }
446
- try {
447
- const orphanedKeys = await new MediaRepository(db).cleanupPendingUploads();
448
- result.pendingUploads = orphanedKeys.length;
449
- if (storage && orphanedKeys.length > 0) {
450
- let filesDeleted = 0;
451
- for (const key of orphanedKeys) try {
452
- await storage.delete(key);
453
- filesDeleted++;
454
- } catch (error) {
455
- console.error(`[cleanup] Failed to delete storage file ${key}:`, error);
456
- }
457
- result.pendingUploadFiles = filesDeleted;
458
- } else result.pendingUploadFiles = 0;
459
- } catch (error) {
460
- console.error("[cleanup] Failed to clean pending uploads:", error);
461
- }
462
- try {
463
- const mediaRepo = new MediaRepository(db);
464
- const completedAttemptsDeleted = await mediaRepo.deleteCompletedUploadAttempts();
465
- if (!storage) result.uploadAttempts = completedAttemptsDeleted;
466
- else {
467
- const storageKeys = await mediaRepo.findUploadAttemptsForCleanup();
468
- let attemptsDeleted = completedAttemptsDeleted;
469
- for (const storageKey of storageKeys) if (await removeUploadAttempt(storage, mediaRepo, storageKey)) attemptsDeleted++;
470
- result.uploadAttempts = attemptsDeleted;
471
- }
472
- } catch (error) {
473
- console.error("[cleanup] Failed to clean media upload attempts:", error);
474
- }
475
- try {
476
- result.revisionsPruned = await pruneQueuedRevisions(db);
477
- } catch (error) {
478
- console.error("[cleanup] Failed to prune revisions:", error);
479
- }
480
- try {
481
- const mediaUsage = await cleanupMediaUsage(db);
482
- result.mediaUsage = mediaUsage.status === "failed" ? -1 : mediaUsage.deletedRows;
483
- } catch (error) {
484
- console.error("[cleanup] Failed to clean media usage:", error);
485
- }
486
- return result;
487
- }
488
- async function pruneQueuedRevisions(db) {
489
- const queued = await db.selectFrom("_emdash_revision_prune_queue").selectAll().orderBy("revision_id").limit(REVISION_PRUNE_BATCH_SIZE).execute();
490
- const revisionRepo = new RevisionRepository(db);
491
- let totalPruned = 0;
492
- for (const row of queued) try {
493
- totalPruned += await revisionRepo.pruneQueuedEntry(row.collection, row.entry_id, row.revision_id, REVISION_KEEP_COUNT);
494
- } catch (error) {
495
- console.error(`[cleanup] Failed to prune revisions for ${row.collection}/${row.entry_id}:`, error);
496
- }
497
- return totalPruned;
498
- }
499
-
500
- //#endregion
501
- //#region src/comments/moderator.ts
502
- /** Plugin ID for the built-in default comment moderator */
503
- const DEFAULT_COMMENT_MODERATOR_PLUGIN_ID = "emdash-default-comment-moderator";
504
- /**
505
- * The comment:moderate handler for the built-in default moderator.
506
- */
507
- async function defaultCommentModerate(event, _ctx) {
508
- const { comment, collectionSettings, priorApprovedCount } = event;
509
- if (collectionSettings.commentsAutoApproveUsers && comment.authorUserId) return {
510
- status: "approved",
511
- reason: "Authenticated CMS user"
512
- };
513
- if (collectionSettings.commentsModeration === "none") return {
514
- status: "approved",
515
- reason: "Moderation disabled"
516
- };
517
- if (collectionSettings.commentsModeration === "first_time" && priorApprovedCount > 0) return {
518
- status: "approved",
519
- reason: "Returning commenter"
520
- };
521
- return {
522
- status: "pending",
523
- reason: "Held for review"
524
- };
525
- }
526
-
527
- //#endregion
528
- //#region src/scheduled-publish.ts
529
- /**
530
- * Default cap on items promoted per collection in a single sweep. Bounds the
531
- * publish/webhook fan-out of one tick so a large backlog can't exhaust a Worker
532
- * invocation's CPU/subrequest budget; the remainder drains on later ticks.
533
- */
534
- const SCHEDULED_PUBLISH_BATCH_LIMIT = 100;
535
- /**
536
- * Publish every content item whose `scheduled_at` is in the past.
537
- *
538
- * Iterates all collections, finds due items (`findReadyToPublish` returns both
539
- * scheduled drafts and published entries with pending scheduled changes), and
540
- * publishes each. `publish()` clears `scheduled_at`, so a second sweep is a
541
- * no-op — safe to run on every tick.
542
- *
543
- * Bounded per collection by `limit` (default `SCHEDULED_PUBLISH_BATCH_LIMIT`):
544
- * a large backlog drains across successive ticks rather than in one unbounded
545
- * pass. After each collection's batch, `onPublished` (if given) is awaited so
546
- * cache-tag invalidation happens incrementally, not just at the very end.
547
- *
548
- * Returns every item it promoted so request-less callers (the Cloudflare
549
- * `scheduled()` handler) can also act on the full set.
550
- */
551
- async function publishDueContent(db, options = {}) {
552
- const { publish, onPublished, limit = SCHEDULED_PUBLISH_BATCH_LIMIT } = options;
553
- const published = [];
554
- let collections;
555
- try {
556
- collections = await new SchemaRegistry(db).listCollections();
557
- } catch (error) {
558
- console.error("[scheduled-publish] Failed to list collections:", error);
559
- return published;
560
- }
561
- const repo = new ContentRepository(db);
562
- const doPublish = publish ?? ((collection, id, opts) => handleContentPublish(db, collection, id, opts));
563
- const batchLimit = limit > 0 ? limit : void 0;
564
- for (const collection of collections) try {
565
- const due = await repo.findReadyToPublish(collection.slug, batchLimit);
566
- const batch = [];
567
- for (const item of due) {
568
- const publishedAt = item.publishedAt == null ? item.scheduledAt ?? void 0 : void 0;
569
- const result = await doPublish(collection.slug, item.id, {
570
- publishedAt,
571
- requireScheduledDue: true,
572
- expectedScheduledAt: item.scheduledAt ?? void 0
573
- });
574
- if (result.success) batch.push({
575
- collection: collection.slug,
576
- id: item.id
577
- });
578
- else if (result.error?.code === "NOT_DUE") {} else console.error(`[scheduled-publish] Failed to publish ${collection.slug}/${item.id}:`, result.error);
579
- }
580
- if (batch.length > 0) {
581
- published.push(...batch);
582
- if (onPublished) try {
583
- await onPublished(batch);
584
- } catch (error) {
585
- console.error(`[scheduled-publish] onPublished failed after "${collection.slug}" batch:`, error);
586
- }
587
- }
588
- } catch (error) {
589
- console.error(`[scheduled-publish] Sweep failed for "${collection.slug}":`, error);
590
- }
591
- return published;
592
- }
593
-
594
- //#endregion
595
- //#region src/emdash-runtime.ts
596
- /**
597
- * EmDashRuntime - Core runtime for EmDash CMS
598
- *
599
- * Manages database, storage, plugins (trusted + sandboxed), hooks, and
600
- * provides handlers for content/media operations.
601
- *
602
- * Created once per worker lifetime, cached and reused across requests.
603
- */
604
- const LEADING_SLASH_PATTERN = /^\//;
605
- const LOCALE_CASING_REPAIR_OPTION = "emdash:repair_locale_casing";
606
- function getLocaleCasingRepairVersion(locales) {
607
- if (locales.length === 0) return null;
608
- return `1:${locales.toSorted().join(",")}`;
609
- }
610
- /**
611
- * Parse a JSON column expected to contain an array of strings.
612
- *
613
- * Throws on malformed JSON rather than returning []; callers are responsible
614
- * for deciding how to handle/log the error. Empty string / null inputs return
615
- * [] (they represent "no value"). Non-string array entries are filtered out.
616
- */
617
- function parseStringArray(raw) {
618
- if (!raw) return [];
619
- const parsed = JSON.parse(raw);
620
- if (!Array.isArray(parsed)) return [];
621
- return parsed.filter((v) => typeof v === "string");
622
- }
623
- const VALID_METADATA_KINDS = new Set([
624
- "meta",
625
- "property",
626
- "link",
627
- "jsonld"
628
- ]);
629
- /** Security-critical allowlist for link rel values from sandboxed plugins */
630
- const VALID_LINK_REL = new Set([
631
- "canonical",
632
- "alternate",
633
- "author",
634
- "license",
635
- "nlweb",
636
- "site.standard.document"
637
- ]);
638
- /**
639
- * Runtime validation for sandboxed plugin metadata contributions.
640
- * Sandboxed plugins return `unknown` across the RPC boundary — we must
641
- * verify the shape before passing to the metadata collector.
642
- */
643
- function isValidMetadataContribution(c) {
644
- if (!c || typeof c !== "object" || !("kind" in c)) return false;
645
- const obj = c;
646
- if (typeof obj.kind !== "string" || !VALID_METADATA_KINDS.has(obj.kind)) return false;
647
- switch (obj.kind) {
648
- case "meta": return typeof obj.name === "string" && typeof obj.content === "string";
649
- case "property": return typeof obj.property === "string" && typeof obj.content === "string";
650
- case "link": return typeof obj.href === "string" && typeof obj.rel === "string" && VALID_LINK_REL.has(obj.rel);
651
- case "jsonld": return obj.graph != null && typeof obj.graph === "object";
652
- default: return false;
653
- }
654
- }
655
- const DRAFT_ONLY_UPDATE_KEYS = new Set([
656
- "data",
657
- "slug",
658
- "locale",
659
- "skipRevision"
660
- ]);
661
- const MAX_DRAFT_STAGE_ATTEMPTS = 32;
662
- /**
663
- * A `ContentSaveRejectedError` carries a message the plugin wrote for the
664
- * editor; every other exception stays internal and is replaced by a generic
665
- * message so hook internals cannot leak through the API.
666
- */
667
- function beforeSaveFailure(error) {
668
- if (isContentSaveRejection(error)) return {
669
- success: false,
670
- error: {
671
- code: ErrorCode.SAVE_REJECTED,
672
- message: error.message
673
- }
674
- };
675
- console.error("EmDash: content:beforeSave hook failed:", error);
676
- return {
677
- success: false,
678
- error: {
679
- code: ErrorCode.CONTENT_HOOK_ERROR,
680
- message: "A plugin hook failed while saving content"
681
- }
682
- };
683
- }
684
- /**
685
- * Convert a ContentItem to Record<string, unknown> for hook consumption.
686
- * Hooks receive the full item as a flat record.
687
- */
688
- function contentItemToRecord(item) {
689
- return { ...item };
690
- }
691
- /**
692
- * Db init lock reclaim deadline. Derived from the migration race wait so
693
- * they can't drift apart: a healthy init can legitimately block for the
694
- * full MIGRATION_RACE_WAIT_MS inside waitForConcurrentMigrator, plus cold
695
- * connect and migrator work, before it should be presumed dead. The outer
696
- * runtime init lock (middleware.ts) must use a strictly larger deadline —
697
- * it wraps create() → getDatabase() → this lock, and equal deadlines would
698
- * let the outer reclaim while the inner is legitimately still working.
699
- */
700
- const DB_INIT_DEADLINE_MS = MIGRATION_RACE_WAIT_MS + 2e4;
701
- /**
702
- * Db cache + its init lock live on globalThis behind a Symbol: the bundler
703
- * can duplicate this module across SSR chunks (same reasoning as
704
- * request-cache.ts), and a duplicated cache/lock would mean concurrent
705
- * independent db inits — and duplicate migrators — per isolate.
706
- */
707
- const DB_HOLDER_KEY = Symbol.for("emdash:db-cache");
708
- const globalSymbolStore = globalThis;
709
- function getDbHolder() {
710
- let holder = globalSymbolStore[DB_HOLDER_KEY];
711
- if (!holder) {
712
- holder = {
713
- cache: /* @__PURE__ */ new Map(),
714
- lock: createInitLock(),
715
- failures: /* @__PURE__ */ new Map()
716
- };
717
- globalSymbolStore[DB_HOLDER_KEY] = holder;
718
- }
719
- holder.failures ??= /* @__PURE__ */ new Map();
720
- return holder;
721
- }
722
- /**
723
- * After a database init fails (migrations threw), skip re-attempting for
724
- * this long. Cold isolates still get one attempt each, so a transient
725
- * failure heals on its own; a persistently failing migration is retried at
726
- * most once per backoff window per isolate instead of on every request.
727
- */
728
- const DB_INIT_FAILURE_BACKOFF_MS = 3e4;
729
- /**
730
- * Auto-seed runs at most once per isolate per database. Its lock + "done" set
731
- * live on globalThis (same bundler-duplication reasoning as the db cache) so a
732
- * reclaimed-and-rerun `create()` can't seed a second time concurrently. The
733
- * lock polls rather than sharing a promise, so it is safe to await across a
734
- * cancelled owner in workerd.
735
- */
736
- const SEED_HOLDER_KEY = Symbol.for("emdash:seed-state");
737
- function getSeedHolder() {
738
- let holder = globalSymbolStore[SEED_HOLDER_KEY];
739
- if (!holder) {
740
- holder = {
741
- done: /* @__PURE__ */ new Set(),
742
- lock: createInitLock()
743
- };
744
- globalSymbolStore[SEED_HOLDER_KEY] = holder;
745
- }
746
- return holder;
747
- }
748
- const storageCache = /* @__PURE__ */ new Map();
749
- const sandboxedPluginCache = /* @__PURE__ */ new Map();
750
- /**
751
- * Per-tier sets of `${pluginId}:${version}` keys present in
752
- * `sandboxedPluginCache`. Used during sync to know which entries belong
753
- * to which install source so we can invalidate only what belongs to the
754
- * tier currently being synced.
755
- */
756
- const marketplacePluginKeys = /* @__PURE__ */ new Set();
757
- const registryPluginKeys = /* @__PURE__ */ new Set();
758
- /**
759
- * Manifest metadata for runtime-installed sandboxed plugins (marketplace
760
- * and registry both). Keyed by `pluginId`; readers don't care which
761
- * source the plugin came from. Named `marketplace*` for legacy reasons.
762
- */
763
- const marketplaceManifestCache = /* @__PURE__ */ new Map();
764
- /** Route metadata for sandboxed plugins: pluginId -> routeName -> RouteMeta */
765
- const sandboxedRouteMetaCache = /* @__PURE__ */ new Map();
766
- let sandboxRunner = null;
767
- /**
768
- * EmDashRuntime - singleton per worker
769
- */
770
- var EmDashRuntime = class EmDashRuntime {
771
- /**
772
- * The singleton database instance (worker-lifetime cached).
773
- * Use the `db` getter instead — it checks the request context first
774
- * for per-request overrides (D1 read replica sessions, DO multi-site).
775
- */
776
- _db;
777
- storage;
778
- configuredPlugins;
779
- sandboxedPlugins;
780
- sandboxedPluginEntries;
781
- /**
782
- * Schema registry bound to the current request/event-scoped connection.
783
- * Built per access (SchemaRegistry just wraps a db) against `this.db`, the
784
- * ALS-aware getter — never a captured snapshot of the singleton. On a
785
- * connection-backed adapter (Postgres over Hyperdrive) a captured singleton
786
- * would query a socket opened by an earlier event and trip workerd's
787
- * cross-request I/O guard; the catch in handlers like handleContentUpdate
788
- * would then silently treat a revision-enabled collection as non-revisioned
789
- * and write draft edits to live columns. Same reasoning as the per-call
790
- * registry in _buildManifest().
791
- */
792
- get schemaRegistry() {
793
- return new SchemaRegistry(this.db);
794
- }
795
- _hooks;
796
- config;
797
- mediaProviders;
798
- mediaProviderEntries;
799
- cronExecutor;
800
- email;
801
- cronScheduler;
802
- enabledPlugins;
803
- pluginStates;
804
- /**
805
- * Isolate-lifetime guard so FTS indexes are verified at most once per
806
- * worker rather than on every admin request. See ensureSearchHealthy().
807
- * Uses the poison-immune single-flight cache (never a shared awaitable
808
- * promise) so a cancelled first caller can't wedge later ones.
809
- */
810
- _searchHealthCache = createSingleFlightCache();
811
- /** Current hook pipeline. Use the `hooks` getter for external access. */
812
- get hooks() {
813
- return this._hooks;
814
- }
815
- /** All plugins eligible for the hook pipeline (includes built-in plugins).
816
- * Stored so we can rebuild the pipeline when plugins are enabled/disabled. */
817
- allPipelinePlugins;
818
- /** Guards the once-per-process plugin storage-index sync. */
819
- storageIndexesSynced = false;
820
- /** Factory options for the hook pipeline context factory */
821
- pipelineFactoryOptions;
822
- /** Dependencies needed for exclusive hook resolution */
823
- runtimeDeps;
824
- /** Mutable ref for the cron invokeCronHook closure to read the current pipeline */
825
- pipelineRef;
826
- /**
827
- * Get the database instance for the current request.
828
- *
829
- * Checks the ALS-based request context first — middleware sets a
830
- * per-request Kysely instance there for D1 read replica sessions
831
- * or DO preview databases. Falls back to the singleton instance.
832
- */
833
- get db() {
834
- const ctx = getRequestContext();
835
- if (ctx?.db) return ctx.db;
836
- return this._db;
837
- }
838
- constructor(parts) {
839
- this._db = parts.db;
840
- this.storage = parts.storage;
841
- this.configuredPlugins = parts.configuredPlugins;
842
- this.sandboxedPlugins = parts.sandboxedPlugins;
843
- this.sandboxedPluginEntries = parts.sandboxedPluginEntries;
844
- this._hooks = parts.hooks;
845
- this.enabledPlugins = parts.enabledPlugins;
846
- this.pluginStates = parts.pluginStates;
847
- this.config = parts.config;
848
- this.mediaProviders = parts.mediaProviders;
849
- this.mediaProviderEntries = parts.mediaProviderEntries;
850
- this.cronExecutor = parts.cronExecutor;
851
- this.cronScheduler = parts.cronScheduler;
852
- this.email = parts.emailPipeline;
853
- this.allPipelinePlugins = parts.allPipelinePlugins;
854
- this.pipelineFactoryOptions = parts.pipelineFactoryOptions;
855
- this.runtimeDeps = parts.runtimeDeps;
856
- this.pipelineRef = parts.pipelineRef;
857
- }
858
- /**
859
- * Get the sandbox runner instance (for marketplace install/update)
860
- */
861
- getSandboxRunner() {
862
- return sandboxRunner;
863
- }
864
- /**
865
- * Whether the sandbox bypass mode (sandbox: false) is active.
866
- * Marketplace install/update handlers use this to skip the
867
- * SANDBOX_NOT_AVAILABLE gate, since the bypass path loads
868
- * marketplace plugins in-process via syncMarketplacePlugins().
869
- */
870
- isSandboxBypassed() {
871
- return this.runtimeDeps.sandboxBypassed === true;
872
- }
873
- /**
874
- * Publish any content whose scheduled time has passed.
875
- * Returns the items promoted so callers can invalidate their cache tags.
876
- */
877
- async publishScheduled() {
878
- return this.publishScheduledWithFence();
879
- }
880
- async publishScheduledWithFence(onPublished) {
881
- await assertMediaUsageActivationWriteAllowed(this.db);
882
- return publishDueContent(this.db, {
883
- publish: (collection, id, options) => this.handleContentPublish(collection, id, options),
884
- onPublished
885
- });
886
- }
887
- /**
888
- * Run the full scheduled-maintenance batch: cron tasks, scheduled
889
- * publishing, and system cleanup. For request-less drivers — the
890
- * Cloudflare `scheduled()` handler invokes this from a Cron Trigger.
891
- * (On Node the timer-based scheduler drives the same work itself.)
892
- *
893
- * Each step is independent and non-fatal. Returns the content promoted
894
- * by the publishing sweep so the caller can purge edge-cache tags.
895
- *
896
- * `onPublished` (optional) is awaited after each collection's batch so a
897
- * request-less driver can invalidate edge-cache tags incrementally rather
898
- * than only after the whole sweep — bounding stale-cache exposure if the
899
- * runtime is killed mid-sweep.
900
- */
901
- async runScheduledTasks(options = {}) {
902
- if (this.cronExecutor) {
903
- try {
904
- await this.cronExecutor.tick();
905
- } catch (error) {
906
- console.error("[cron] Tick failed:", error);
907
- }
908
- try {
909
- await this.cronExecutor.recoverStaleLocks();
910
- } catch (error) {
911
- console.error("[cron] Stale lock recovery failed:", error);
912
- }
913
- }
914
- let published = [];
915
- try {
916
- published = await this.publishScheduledWithFence(options.onPublished);
917
- } catch (error) {
918
- console.error("[scheduled-publish] Sweep failed:", error);
919
- }
920
- try {
921
- await runSystemCleanup(this.db, this.storage ?? void 0);
922
- } catch (error) {
923
- console.error("[cleanup] System cleanup failed:", error);
924
- }
925
- try {
926
- await this.syncPluginStorageIndexesOnce();
927
- } catch (error) {
928
- console.error("[plugins] Storage index sync failed:", error);
929
- }
930
- await maybeRunScheduledBackup(this.db, this.storage ?? void 0);
931
- await recordSchedulerHeartbeatSafely(this.db);
932
- return { published };
933
- }
934
- /**
935
- * Materialize plugin-declared storage indexes, once per process.
936
- *
937
- * Called from the scheduler path, not from request handlers — configured
938
- * plugins have no install handler, so the tick is their only sync moment.
939
- */
940
- async syncPluginStorageIndexesOnce() {
941
- if (this.storageIndexesSynced) return;
942
- this.storageIndexesSynced = true;
943
- await syncDeclaredStorageIndexes(this.db, [...this.allPipelinePlugins, ...marketplaceManifestCache.values()]);
944
- }
945
- /**
946
- * Stop the cron scheduler gracefully.
947
- * Call during worker shutdown or hot-reload.
948
- */
949
- async stopCron() {
950
- if (this.cronScheduler) await this.cronScheduler.stop();
951
- }
952
- /**
953
- * Update in-memory plugin status and rebuild the hook pipeline.
954
- *
955
- * Rebuilding the pipeline ensures disabled plugins' hooks stop firing
956
- * and re-enabled plugins' hooks start firing again without a restart.
957
- * Exclusive hook selections are re-resolved after each rebuild.
958
- */
959
- async setPluginStatus(pluginId, status) {
960
- this.pluginStates.set(pluginId, status);
961
- if (status === "active") {
962
- this.enabledPlugins.add(pluginId);
963
- await this.rebuildHookPipeline();
964
- await this._hooks.runPluginActivate(pluginId);
965
- } else {
966
- await this._hooks.runPluginDeactivate(pluginId);
967
- this.enabledPlugins.delete(pluginId);
968
- await this.rebuildHookPipeline();
969
- }
970
- }
971
- /**
972
- * Rebuild the hook pipeline from the current set of enabled plugins.
973
- *
974
- * Filters `allPipelinePlugins` to only those in `enabledPlugins`,
975
- * creates a fresh HookPipeline, re-resolves exclusive hook selections,
976
- * and re-wires the context factory so existing references (cron
977
- * callbacks, email pipeline) use the new pipeline.
978
- */
979
- async rebuildHookPipeline() {
980
- const newPipeline = createHookPipeline(this.allPipelinePlugins.filter((p) => this.enabledPlugins.has(p.id)), this.pipelineFactoryOptions);
981
- await EmDashRuntime.resolveExclusiveHooks(newPipeline, this.db, this.runtimeDeps);
982
- if (this.email) newPipeline.setContextFactory({ emailPipeline: this.email });
983
- newPipeline.setContextFactory({ cronReschedule: () => this.cronScheduler?.reschedule() });
984
- if (this.email) this.email.setPipeline(newPipeline);
985
- this.pipelineRef.current = newPipeline;
986
- this._hooks = newPipeline;
987
- }
988
- /**
989
- * Synchronize marketplace plugin runtime state with DB + storage.
990
- *
991
- * Ensures install/update/uninstall changes take effect immediately in the
992
- * current worker: loads newly active plugins and removes uninstalled ones.
993
- */
994
- async syncMarketplacePlugins() {
995
- if (!this.config.marketplace) return;
996
- if (this.runtimeDeps.sandboxBypassed) {
997
- await this.syncMarketplacePluginsBypassed();
998
- return;
999
- }
1000
- await this.syncSandboxedSourcePlugins("marketplace");
1001
- }
1002
- /**
1003
- * Synchronize registry plugin runtime state with DB + storage.
1004
- *
1005
- * Mirrors {@link syncMarketplacePlugins} for plugins installed via the
1006
- * experimental decentralized plugin registry. Called after install,
1007
- * update, and uninstall handlers complete.
1008
- */
1009
- async syncRegistryPlugins() {
1010
- if (!this.config.experimental?.registry) return;
1011
- await this.syncSandboxedSourcePlugins("registry");
1012
- }
1013
- /**
1014
- * Internal: reconcile in-memory sandboxed-plugin state with the
1015
- * `_plugin_state` table for the given source tier. Shared
1016
- * implementation behind {@link syncMarketplacePlugins} and
1017
- * {@link syncRegistryPlugins}.
1018
- *
1019
- * Each source tier has its own key set in `${source}PluginKeys` so a
1020
- * sync for one tier doesn't invalidate the other.
1021
- */
1022
- async syncSandboxedSourcePlugins(source) {
1023
- if (!this.storage) return;
1024
- if (!sandboxRunner || !sandboxRunner.isAvailable()) return;
1025
- const keySet = source === "marketplace" ? marketplacePluginKeys : registryPluginKeys;
1026
- try {
1027
- const stateRepo = new PluginStateRepository(this.db);
1028
- const states = source === "marketplace" ? await stateRepo.getMarketplacePlugins() : await stateRepo.getRegistryPlugins();
1029
- const desired = /* @__PURE__ */ new Map();
1030
- for (const state of states) {
1031
- this.pluginStates.set(state.pluginId, state.status);
1032
- if (state.status === "active") this.enabledPlugins.add(state.pluginId);
1033
- else this.enabledPlugins.delete(state.pluginId);
1034
- if (state.status !== "active") continue;
1035
- const desiredVersion = source === "marketplace" ? state.marketplaceVersion ?? state.version : state.version;
1036
- desired.set(state.pluginId, desiredVersion);
1037
- }
1038
- const keysToRemove = [];
1039
- for (const key of keySet) {
1040
- const [pluginId] = key.split(":");
1041
- if (!pluginId) continue;
1042
- const desiredVersion = desired.get(pluginId);
1043
- if (desiredVersion && key === `${pluginId}:${desiredVersion}`) continue;
1044
- keysToRemove.push(key);
1045
- }
1046
- for (const key of keysToRemove) {
1047
- const [pluginId] = key.split(":");
1048
- if (!pluginId) continue;
1049
- if (!desired.get(pluginId)) {
1050
- this.pluginStates.delete(pluginId);
1051
- this.enabledPlugins.delete(pluginId);
1052
- }
1053
- const existing = sandboxedPluginCache.get(key);
1054
- if (existing) try {
1055
- await existing.terminate();
1056
- } catch (error) {
1057
- console.warn(`EmDash: Failed to terminate sandboxed plugin ${key}:`, error);
1058
- }
1059
- sandboxedPluginCache.delete(key);
1060
- this.sandboxedPlugins.delete(key);
1061
- keySet.delete(key);
1062
- if (pluginId) {
1063
- sandboxedRouteMetaCache.delete(pluginId);
1064
- marketplaceManifestCache.delete(pluginId);
1065
- }
1066
- }
1067
- for (const [pluginId, version] of desired) {
1068
- const key = `${pluginId}:${version}`;
1069
- if (sandboxedPluginCache.has(key)) {
1070
- keySet.add(key);
1071
- continue;
1072
- }
1073
- const bundle = await loadBundleFromR2(this.storage, pluginId, version, source);
1074
- if (!bundle) {
1075
- console.warn(`EmDash: ${source} plugin ${pluginId}@${version} not found in R2`);
1076
- continue;
1077
- }
1078
- const loaded = await sandboxRunner.load(bundle.manifest, bundle.backendCode);
1079
- sandboxedPluginCache.set(key, loaded);
1080
- this.sandboxedPlugins.set(key, loaded);
1081
- keySet.add(key);
1082
- marketplaceManifestCache.set(pluginId, {
1083
- id: bundle.manifest.id,
1084
- version: bundle.manifest.version,
1085
- admin: bundle.manifest.admin,
1086
- mcp: bundle.manifest.mcp,
1087
- storage: bundle.manifest.storage
1088
- });
1089
- if (bundle.manifest.routes.length > 0) {
1090
- const routeMetaMap = /* @__PURE__ */ new Map();
1091
- for (const entry of bundle.manifest.routes) {
1092
- const normalized = normalizeManifestRoute(entry);
1093
- routeMetaMap.set(normalized.name, buildRouteMeta(normalized));
1094
- }
1095
- sandboxedRouteMetaCache.set(pluginId, routeMetaMap);
1096
- } else sandboxedRouteMetaCache.delete(pluginId);
1097
- }
1098
- } catch (error) {
1099
- console.error(`EmDash: Failed to sync ${source} plugins:`, error);
1100
- }
1101
- }
1102
- /**
1103
- * Remove a plugin from the in-memory pipeline lists by ID.
1104
- * Mutates allPipelinePlugins and configuredPlugins in place.
1105
- */
1106
- removePluginFromLists(pluginId) {
1107
- const allIdx = this.allPipelinePlugins.findIndex((p) => p.id === pluginId);
1108
- if (allIdx !== -1) this.allPipelinePlugins.splice(allIdx, 1);
1109
- const configIdx = this.configuredPlugins.findIndex((p) => p.id === pluginId);
1110
- if (configIdx !== -1) this.configuredPlugins.splice(configIdx, 1);
1111
- }
1112
- /**
1113
- * Sync marketplace plugin metadata in sandbox: false bypass mode.
1114
- *
1115
- * In bypass mode the noop runner can't load plugins, but admin pages,
1116
- * widgets, and route metadata still need to refresh in-process when an
1117
- * admin installs/updates/uninstalls a marketplace plugin. Otherwise the
1118
- * admin UI shows stale data until the server restarts.
1119
- *
1120
- * Hooks and routes still won't execute under bypass (matches the
1121
- * cold-start bypass behavior in loadMarketplacePluginsBypassed).
1122
- *
1123
- * Known limitation: bypass plugins are loaded via `import(dataUrl)`,
1124
- * which Node's ESM cache keys on the full URL. Updates create fresh
1125
- * module objects, but old ones remain cached for the worker's lifetime.
1126
- * In practice this is a few KB per update — only matters for sites with
1127
- * very frequent marketplace updates running long-lived processes. The
1128
- * fix would be vm.SourceTextModule for explicit lifecycle management.
1129
- */
1130
- async syncMarketplacePluginsBypassed() {
1131
- if (!this.storage) return;
1132
- try {
1133
- const marketplaceStates = await new PluginStateRepository(this.db).getMarketplacePlugins();
1134
- const desired = /* @__PURE__ */ new Map();
1135
- for (const state of marketplaceStates) {
1136
- this.pluginStates.set(state.pluginId, state.status);
1137
- if (state.status === "active") this.enabledPlugins.add(state.pluginId);
1138
- else this.enabledPlugins.delete(state.pluginId);
1139
- if (state.status !== "active") continue;
1140
- desired.set(state.pluginId, state.marketplaceVersion ?? state.version);
1141
- }
1142
- const toRemove = [];
1143
- for (const pluginId of marketplaceManifestCache.keys()) if (!desired.has(pluginId)) toRemove.push(pluginId);
1144
- for (const pluginId of toRemove) {
1145
- const resolved = this.allPipelinePlugins.find((p) => p.id === pluginId);
1146
- if (resolved) try {
1147
- const deactivateHook = resolved.hooks?.["plugin:deactivate"];
1148
- if (deactivateHook) {
1149
- const handler = typeof deactivateHook === "function" ? deactivateHook : deactivateHook.handler;
1150
- if (typeof handler === "function") await handler({ pluginId }, {});
1151
- }
1152
- } catch (err) {
1153
- console.warn(`[emdash] plugin:deactivate hook failed for ${pluginId}:`, err);
1154
- }
1155
- marketplaceManifestCache.delete(pluginId);
1156
- sandboxedRouteMetaCache.delete(pluginId);
1157
- this.removePluginFromLists(pluginId);
1158
- this.enabledPlugins.delete(pluginId);
1159
- }
1160
- const { adaptSandboxEntry } = await import("../plugins/adapt-sandbox-entry.mjs");
1161
- const newPlugins = [];
1162
- for (const [pluginId, version] of desired) {
1163
- const bundle = await loadBundleFromR2(this.storage, pluginId, version);
1164
- if (!bundle) {
1165
- console.warn(`EmDash: Marketplace plugin ${pluginId}@${version} not found in R2`);
1166
- continue;
1167
- }
1168
- marketplaceManifestCache.set(pluginId, {
1169
- id: bundle.manifest.id,
1170
- version: bundle.manifest.version,
1171
- admin: bundle.manifest.admin,
1172
- mcp: bundle.manifest.mcp,
1173
- storage: bundle.manifest.storage
1174
- });
1175
- if (bundle.manifest.routes.length > 0) {
1176
- const routeMetaMap = /* @__PURE__ */ new Map();
1177
- for (const entry of bundle.manifest.routes) {
1178
- const normalized = normalizeManifestRoute(entry);
1179
- routeMetaMap.set(normalized.name, buildRouteMeta(normalized));
1180
- }
1181
- sandboxedRouteMetaCache.set(pluginId, routeMetaMap);
1182
- } else sandboxedRouteMetaCache.delete(pluginId);
1183
- const existing = this.allPipelinePlugins.find((p) => p.id === pluginId);
1184
- if (existing && existing.version === bundle.manifest.version) continue;
1185
- if (existing) this.removePluginFromLists(pluginId);
1186
- try {
1187
- const pluginModule = await import(`data:text/javascript;base64,${Buffer.from(bundle.backendCode).toString("base64")}`);
1188
- const adapted = adaptSandboxEntry(pluginModule.default ?? pluginModule, {
1189
- id: bundle.manifest.id,
1190
- version: bundle.manifest.version,
1191
- entrypoint: "",
1192
- capabilities: bundle.manifest.capabilities ?? [],
1193
- allowedHosts: bundle.manifest.allowedHosts ?? [],
1194
- storage: bundle.manifest.storage ?? {},
1195
- adminPages: bundle.manifest.admin?.pages,
1196
- adminWidgets: bundle.manifest.admin?.widgets?.map((w) => ({
1197
- id: w.id,
1198
- title: w.title,
1199
- size: w.size === "full" || w.size === "half" || w.size === "third" ? w.size : void 0
1200
- })),
1201
- settingsSchema: bundle.manifest.admin?.settingsSchema
1202
- });
1203
- newPlugins.push(adapted);
1204
- this.allPipelinePlugins.push(adapted);
1205
- this.configuredPlugins.push(adapted);
1206
- this.enabledPlugins.add(adapted.id);
1207
- } catch (error) {
1208
- console.error(`EmDash: Failed to load marketplace plugin ${pluginId}@${version} in-process:`, error);
1209
- }
1210
- }
1211
- if (toRemove.length > 0 || newPlugins.length > 0) await this.rebuildHookPipeline();
1212
- } catch (error) {
1213
- console.error("EmDash: Failed to sync marketplace plugins (bypass):", error);
1214
- }
1215
- }
1216
- /**
1217
- * Create and initialize the runtime
1218
- */
1219
- static async create(deps, timings) {
1220
- const phase = async (name, desc, fn) => {
1221
- if (!timings) return fn();
1222
- const t0 = performance.now();
1223
- try {
1224
- return await fn();
1225
- } finally {
1226
- timings.push({
1227
- name,
1228
- dur: performance.now() - t0,
1229
- desc
1230
- });
1231
- }
1232
- };
1233
- const db = await phase("rt.db", "DB init + migration policy", () => EmDashRuntime.getDatabase(deps));
1234
- const resolveDb = () => {
1235
- return getRequestContext()?.db ?? db;
1236
- };
1237
- await phase("rt.secrets", "Validate encryption key", () => validateEncryptionKeyAtStartup());
1238
- const storage = EmDashRuntime.getStorage(deps);
1239
- let pluginStates = /* @__PURE__ */ new Map();
1240
- const configuredLocales = virtualConfig?.i18n?.locales ?? getI18nConfig()?.locales ?? [];
1241
- const localeCasingRepairVersion = getLocaleCasingRepairVersion(configuredLocales);
1242
- let storedLocaleCasingRepairVersion;
1243
- let siteInfo;
1244
- let seedGate = {
1245
- collectionCount: 1,
1246
- setupDone: true
1247
- };
1248
- const reqCtx = getRequestContext();
1249
- const ownsConfiguredDb = !!deps.config.database && !(reqCtx?.dbIsIsolated && reqCtx.db);
1250
- let readDb = db;
1251
- let readDbDisposable;
1252
- const disposeReadDb = async () => {
1253
- const disposable = readDbDisposable;
1254
- readDbDisposable = void 0;
1255
- if (!disposable) return;
1256
- try {
1257
- await disposable.destroy();
1258
- } catch {}
1259
- };
1260
- if (ownsConfiguredDb && deps.createCoalescingDialect && deps.config.database) try {
1261
- const dialect = deps.createCoalescingDialect(deps.config.database.config);
1262
- if (dialect) {
1263
- readDb = new Kysely({
1264
- dialect,
1265
- log: kyselyLogOption()
1266
- });
1267
- readDbDisposable = readDb;
1268
- }
1269
- } catch {
1270
- readDb = db;
1271
- }
1272
- const optionsRepo = new OptionsRepository(readDb);
1273
- let missingManualSchemaError;
1274
- const captureMissingManualSchema = (error) => {
1275
- if ((deps.migrationMode ?? "auto") === "manual" && isMissingTableError(error)) missingManualSchemaError ??= error;
1276
- };
1277
- const readSiteInfo = async () => {
1278
- const siteOpts = await optionsRepo.getMany([
1279
- "emdash:site_title",
1280
- "emdash:site_url",
1281
- "emdash:locale",
1282
- LOCALE_CASING_REPAIR_OPTION
1283
- ]);
1284
- storedLocaleCasingRepairVersion = siteOpts.get(LOCALE_CASING_REPAIR_OPTION);
1285
- return {
1286
- siteName: siteOpts.get("emdash:site_title") ?? void 0,
1287
- siteUrl: siteOpts.get("emdash:site_url") ?? void 0,
1288
- locale: siteOpts.get("emdash:locale") ?? void 0,
1289
- trailingSlash: virtualConfig?.trailingSlash
1290
- };
1291
- };
1292
- const coldStartReads = [phase("rt.plugins", "Plugin states", async () => {
1293
- try {
1294
- const states = await readDb.selectFrom("_plugin_state").select(["plugin_id", "status"]).execute();
1295
- pluginStates = new Map(states.map((s) => [s.plugin_id, s.status]));
1296
- } catch (error) {
1297
- captureMissingManualSchema(error);
1298
- }
1299
- }), phase("rt.site", "Site info options", async () => {
1300
- try {
1301
- siteInfo = await readSiteInfo();
1302
- } catch (error) {
1303
- captureMissingManualSchema(error);
1304
- }
1305
- })];
1306
- if (ownsConfiguredDb) coldStartReads.push(phase("rt.seedcheck", "Auto-seed gate", async () => {
1307
- try {
1308
- const [collectionCount, setupOption] = await Promise.all([readDb.selectFrom("_emdash_collections").select((eb) => eb.fn.countAll().as("count")).executeTakeFirstOrThrow(), readDb.selectFrom("options").select("value").where("name", "=", "emdash:setup_complete").executeTakeFirst()]);
1309
- const setupDone = (() => {
1310
- try {
1311
- return !!setupOption && JSON.parse(setupOption.value) === true;
1312
- } catch {
1313
- return false;
1314
- }
1315
- })();
1316
- seedGate = {
1317
- collectionCount: collectionCount.count,
1318
- setupDone
1319
- };
1320
- } catch (error) {
1321
- captureMissingManualSchema(error);
1322
- }
1323
- }));
1324
- await Promise.all(coldStartReads);
1325
- if (missingManualSchemaError) {
1326
- await disposeReadDb();
1327
- throw missingManualSchemaError;
1328
- }
1329
- if (localeCasingRepairVersion && (configuredLocales.some((locale) => locale.includes("-") || locale !== locale.toLowerCase()) || storedLocaleCasingRepairVersion !== void 0) && storedLocaleCasingRepairVersion !== localeCasingRepairVersion) await phase("rt.locale", "Repair locale casing", async () => {
1330
- await repairLocaleCasing(db, configuredLocales);
1331
- await new OptionsRepository(db).set(LOCALE_CASING_REPAIR_OPTION, localeCasingRepairVersion);
1332
- });
1333
- if (seedGate.collectionCount === 0 && !seedGate.setupDone) {
1334
- try {
1335
- if ((await activateMediaUsageCapture(db, { writersDrained: true })).outcome !== "active") throw new Error("Fresh-site media usage activation did not complete");
1336
- } catch (error) {
1337
- await disposeReadDb();
1338
- throw error;
1339
- }
1340
- const seedKey = deps.config.database?.entrypoint ?? "default";
1341
- const seedHolder = getSeedHolder();
1342
- try {
1343
- await initWithLock(seedHolder.lock, () => seedHolder.done.has(seedKey) ? true : void 0, async () => {
1344
- const { applySeed } = await import("../apply-B4SIOxR1.mjs").then((n) => n.n);
1345
- const { loadSeed } = await import("../load-CawHjTOH.mjs").then((n) => n.r);
1346
- const { validateSeed } = await import("../validate-DE_LRwo9.mjs").then((n) => n.n);
1347
- const seed = await loadSeed();
1348
- if (validateSeed(seed).valid) {
1349
- await applySeed(db, seed, { onConflict: "skip" });
1350
- console.log("Auto-seeded default collections");
1351
- }
1352
- seedHolder.done.add(seedKey);
1353
- return true;
1354
- }, {
1355
- deadlineMs: DB_INIT_DEADLINE_MS,
1356
- anchor: (promise) => after(() => promise)
1357
- });
1358
- try {
1359
- siteInfo = await readSiteInfo();
1360
- } catch {}
1361
- } catch {}
1362
- }
1363
- await disposeReadDb();
1364
- const enabledPlugins = /* @__PURE__ */ new Set();
1365
- for (const plugin of deps.plugins) {
1366
- const status = pluginStates.get(plugin.id);
1367
- if (status === void 0 || status === "active") enabledPlugins.add(plugin.id);
1368
- }
1369
- const allPipelinePlugins = [...deps.plugins];
1370
- const bypassedPluginsList = [];
1371
- if (import.meta.env.DEV) try {
1372
- const devConsolePlugin = definePlugin({
1373
- id: DEV_CONSOLE_EMAIL_PLUGIN_ID,
1374
- version: "0.0.0",
1375
- capabilities: ["hooks.email-transport:register"],
1376
- hooks: { "email:deliver": {
1377
- exclusive: true,
1378
- handler: devConsoleEmailDeliver
1379
- } }
1380
- });
1381
- allPipelinePlugins.push(devConsolePlugin);
1382
- enabledPlugins.add(devConsolePlugin.id);
1383
- } catch (error) {
1384
- console.warn("[email] Failed to register dev console email provider:", error);
1385
- }
1386
- try {
1387
- const defaultModeratorPlugin = definePlugin({
1388
- id: DEFAULT_COMMENT_MODERATOR_PLUGIN_ID,
1389
- version: "0.0.0",
1390
- capabilities: ["users:read"],
1391
- hooks: { "comment:moderate": {
1392
- exclusive: true,
1393
- handler: defaultCommentModerate
1394
- } }
1395
- });
1396
- allPipelinePlugins.push(defaultModeratorPlugin);
1397
- enabledPlugins.add(defaultModeratorPlugin.id);
1398
- } catch (error) {
1399
- console.warn("[comments] Failed to register default moderator:", error);
1400
- }
1401
- if (deps.sandboxBypassed && deps.sandboxedPluginEntries.length > 0) {
1402
- if (typeof navigator !== "undefined" && typeof navigator.userAgent === "string" && navigator.userAgent.includes("Cloudflare-Workers")) throw new Error("sandbox: false is not supported in Cloudflare Workers. Remove the sandbox: false option or use the Cloudflare sandbox runner.");
1403
- console.info("EmDash: Sandbox disabled (sandbox: false). Sandboxed plugins will run in-process without isolation.");
1404
- const bypassedPlugins = await EmDashRuntime.loadBypassedPlugins(deps.sandboxedPluginEntries);
1405
- for (const plugin of bypassedPlugins) {
1406
- allPipelinePlugins.push(plugin);
1407
- bypassedPluginsList.push(plugin);
1408
- const status = pluginStates.get(plugin.id);
1409
- if (status === void 0 || status === "active") enabledPlugins.add(plugin.id);
1410
- }
1411
- }
1412
- if (deps.sandboxBypassed && deps.config.marketplace && storage) {
1413
- const marketplaceBypassed = await EmDashRuntime.loadMarketplacePluginsBypassed(db, storage);
1414
- for (const plugin of marketplaceBypassed) {
1415
- allPipelinePlugins.push(plugin);
1416
- bypassedPluginsList.push(plugin);
1417
- const status = pluginStates.get(plugin.id);
1418
- if (status === void 0 || status === "active") enabledPlugins.add(plugin.id);
1419
- }
1420
- }
1421
- const enabledPluginList = allPipelinePlugins.filter((p) => enabledPlugins.has(p.id));
1422
- const pipelineFactoryOptions = {
1423
- db,
1424
- getDb: resolveDb,
1425
- beforeContentWrite: () => assertMediaUsageActivationWriteAllowed(resolveDb()),
1426
- storage: storage ?? void 0,
1427
- siteInfo
1428
- };
1429
- const pipeline = createHookPipeline(enabledPluginList, pipelineFactoryOptions);
1430
- const sandboxedPlugins = await phase("rt.sandbox", "Sandboxed plugins", () => EmDashRuntime.loadSandboxedPlugins(deps, db, storage, siteInfo));
1431
- const installedTierPhases = [];
1432
- if (deps.config.marketplace && storage && !deps.sandboxBypassed) installedTierPhases.push(phase("rt.market", "Marketplace plugins", () => EmDashRuntime.loadInstalledSandboxedPlugins("marketplace", db, storage, deps, sandboxedPlugins, siteInfo)));
1433
- if (deps.config.experimental?.registry && storage) installedTierPhases.push(phase("rt.registry", "Registry plugins", () => EmDashRuntime.loadInstalledSandboxedPlugins("registry", db, storage, deps, sandboxedPlugins, siteInfo)));
1434
- if (installedTierPhases.length > 0) await Promise.all(installedTierPhases);
1435
- const mediaProviders = /* @__PURE__ */ new Map();
1436
- const mediaProviderEntries = deps.mediaProviderEntries ?? [];
1437
- const providerContext = {
1438
- db,
1439
- storage,
1440
- getDb: resolveDb
1441
- };
1442
- for (const entry of mediaProviderEntries) try {
1443
- const provider = entry.createProvider(providerContext);
1444
- mediaProviders.set(entry.id, provider);
1445
- } catch (error) {
1446
- console.warn(`Failed to initialize media provider "${entry.id}":`, error);
1447
- }
1448
- await phase("rt.hooks", "Exclusive hook resolution", () => EmDashRuntime.resolveExclusiveHooks(pipeline, db, deps));
1449
- const emailPipeline = new EmailPipeline(pipeline);
1450
- if (sandboxRunner) sandboxRunner.setEmailSend((message, pluginId) => emailPipeline.send(message, pluginId));
1451
- const pipelineRef = { current: pipeline };
1452
- const invokeCronHook = async (pluginId, event) => {
1453
- const result = await pipelineRef.current.invokeCronHook(pluginId, event);
1454
- if (!result.success && result.error) throw result.error;
1455
- };
1456
- pipeline.setContextFactory({ emailPipeline });
1457
- let cronExecutor = null;
1458
- let cronScheduler = null;
1459
- const runtimeRef = { current: null };
1460
- await phase("rt.cron", "Cron init (recovery deferred post-response)", async () => {
1461
- try {
1462
- cronExecutor = new CronExecutor(resolveDb, invokeCronHook);
1463
- pipeline.setContextFactory({ cronReschedule: () => cronScheduler?.reschedule() });
1464
- const executorForRecovery = cronExecutor;
1465
- after(async () => {
1466
- try {
1467
- const recovered = await executorForRecovery.recoverStaleLocks();
1468
- if (recovered > 0) console.log(`[cron] Recovered ${recovered} stale task lock(s)`);
1469
- } catch (error) {
1470
- console.error("[cron] Failed to recover stale task locks:", error);
1471
- }
1472
- });
1473
- if (deps.createScheduler) {
1474
- const scheduler = deps.createScheduler(cronExecutor);
1475
- cronScheduler = scheduler;
1476
- scheduler.setSystemCleanup(async () => {
1477
- try {
1478
- const runtime = runtimeRef.current;
1479
- if (runtime) await runtime.publishScheduled();
1480
- else {
1481
- await assertMediaUsageActivationWriteAllowed(db);
1482
- await publishDueContent(db);
1483
- }
1484
- } catch (error) {
1485
- console.error("[scheduled-publish] Sweep failed:", error);
1486
- }
1487
- try {
1488
- await runSystemCleanup(db, storage ?? void 0);
1489
- } catch (error) {
1490
- console.error("[cleanup] System cleanup failed:", error);
1491
- }
1492
- try {
1493
- await runtimeRef.current?.syncPluginStorageIndexesOnce();
1494
- } catch (error) {
1495
- console.error("[plugins] Storage index sync failed:", error);
1496
- }
1497
- await maybeRunScheduledBackup(db, storage ?? void 0);
1498
- await recordSchedulerHeartbeatSafely(db);
1499
- });
1500
- scheduler.start();
1501
- }
1502
- } catch (error) {
1503
- console.warn("[cron] Failed to initialize cron system:", error);
1504
- }
1505
- });
1506
- const runtime = new EmDashRuntime({
1507
- db,
1508
- storage,
1509
- configuredPlugins: [...deps.plugins, ...bypassedPluginsList],
1510
- sandboxedPlugins,
1511
- sandboxedPluginEntries: deps.sandboxedPluginEntries,
1512
- hooks: pipeline,
1513
- enabledPlugins,
1514
- pluginStates,
1515
- config: deps.config,
1516
- mediaProviders,
1517
- mediaProviderEntries,
1518
- cronExecutor,
1519
- cronScheduler,
1520
- emailPipeline,
1521
- allPipelinePlugins,
1522
- pipelineFactoryOptions,
1523
- runtimeDeps: deps,
1524
- pipelineRef
1525
- });
1526
- runtimeRef.current = runtime;
1527
- return runtime;
1528
- }
1529
- /**
1530
- * Get a media provider by ID
1531
- */
1532
- getMediaProvider(providerId) {
1533
- return this.mediaProviders.get(providerId);
1534
- }
1535
- /**
1536
- * Get all media provider entries (for admin UI)
1537
- */
1538
- getMediaProviderList() {
1539
- return this.mediaProviderEntries.map((e) => ({
1540
- id: e.id,
1541
- name: e.name,
1542
- icon: e.icon,
1543
- capabilities: e.capabilities
1544
- }));
1545
- }
1546
- /**
1547
- * Get or create database instance
1548
- */
1549
- static async getDatabase(deps) {
1550
- const ctx = getRequestContext();
1551
- if (ctx?.dbIsIsolated && ctx.db) return ctx.db;
1552
- const dbConfig = deps.config.database;
1553
- if (!dbConfig) try {
1554
- return await getDb();
1555
- } catch {
1556
- throw new Error("EmDash database not configured. Either configure database in astro.config.mjs or use emdashLoader in live.config.ts");
1557
- }
1558
- const cacheKey = dbConfig.entrypoint;
1559
- const holder = getDbHolder();
1560
- const throwIfBackingOff = () => {
1561
- const failure = holder.failures.get(cacheKey);
1562
- if (!failure) return;
1563
- if (Date.now() - failure.at < DB_INIT_FAILURE_BACKOFF_MS) throw new Error(`Database initialization is backing off after a recent migration failure: ${failure.message}`);
1564
- holder.failures.delete(cacheKey);
1565
- };
1566
- throwIfBackingOff();
1567
- return initWithLock(holder.lock, () => holder.cache.get(cacheKey), async (isCurrentClaim) => {
1568
- throwIfBackingOff();
1569
- const db = new Kysely({
1570
- dialect: deps.createDialect(dbConfig.config),
1571
- log: kyselyLogOption()
1572
- });
1573
- try {
1574
- await enforceRuntimeMigrationPolicy(db, deps.migrationMode ?? "auto");
1575
- } catch (error) {
1576
- if (!(error instanceof ConcurrentMigrationTimeoutError) && !(error instanceof PendingMigrationsError)) holder.failures.set(cacheKey, {
1577
- at: Date.now(),
1578
- message: error instanceof Error ? error.message : String(error)
1579
- });
1580
- await db.destroy().catch(() => {});
1581
- throw error;
1582
- }
1583
- holder.failures.delete(cacheKey);
1584
- if (isCurrentClaim()) holder.cache.set(cacheKey, db);
1585
- return db;
1586
- }, {
1587
- deadlineMs: DB_INIT_DEADLINE_MS,
1588
- anchor: (promise) => after(() => promise)
1589
- });
1590
- }
1591
- /**
1592
- * Get or create storage instance
1593
- */
1594
- static getStorage(deps) {
1595
- const storageConfig = deps.config.storage;
1596
- if (!storageConfig || !deps.createStorage) return null;
1597
- const cacheKey = storageConfig.entrypoint;
1598
- const cached = storageCache.get(cacheKey);
1599
- if (cached) return cached;
1600
- const storage = deps.createStorage(storageConfig.config);
1601
- storageCache.set(cacheKey, storage);
1602
- return storage;
1603
- }
1604
- /**
1605
- * Load sandboxed plugin entries as trusted in-process plugins.
1606
- * Used by the sandbox: false debugging escape hatch.
1607
- *
1608
- * Imports each plugin's bundled ESM code via a data URL, adapts it
1609
- * with adaptSandboxEntry, and returns ResolvedPlugin objects ready
1610
- * to be merged into the pipeline plugin list.
1611
- */
1612
- static async loadBypassedPlugins(entries) {
1613
- const { adaptSandboxEntry } = await import("../plugins/adapt-sandbox-entry.mjs");
1614
- const plugins = [];
1615
- for (const entry of entries) try {
1616
- const pluginModule = await import(`data:text/javascript;base64,${Buffer.from(entry.code).toString("base64")}`);
1617
- const pluginDef = pluginModule.default ?? pluginModule;
1618
- const adminPages = entry.adminPages?.map((p) => ({
1619
- path: p.path,
1620
- label: p.label ?? p.path,
1621
- icon: p.icon
1622
- }));
1623
- const adminWidgets = entry.adminWidgets?.map((w) => {
1624
- const size = w.size === "full" || w.size === "half" || w.size === "third" ? w.size : void 0;
1625
- return {
1626
- id: w.id,
1627
- title: w.title,
1628
- size
1629
- };
1630
- });
1631
- const resolved = adaptSandboxEntry(pluginDef, {
1632
- id: entry.id,
1633
- version: entry.version,
1634
- entrypoint: "",
1635
- capabilities: entry.capabilities,
1636
- allowedHosts: entry.allowedHosts,
1637
- storage: entry.storage,
1638
- adminPages,
1639
- adminWidgets,
1640
- settingsSchema: entry.settingsSchema,
1641
- portableTextBlocks: entry.portableTextBlocks,
1642
- fieldWidgets: entry.fieldWidgets
1643
- });
1644
- plugins.push(resolved);
1645
- console.log(`EmDash: Loaded plugin ${entry.id}:${entry.version} in-process (sandbox bypassed)`);
1646
- } catch (error) {
1647
- console.error(`EmDash: Failed to load sandboxed plugin ${entry.id} in-process:`, error);
1648
- }
1649
- return plugins;
1650
- }
1651
- /**
1652
- * Load sandboxed plugins using SandboxRunner
1653
- */
1654
- static async loadSandboxedPlugins(deps, db, mediaStorage, siteInfo) {
1655
- if (sandboxedPluginCache.size > 0) return sandboxedPluginCache;
1656
- if (!deps.sandboxEnabled) return sandboxedPluginCache;
1657
- if (!sandboxRunner && deps.createSandboxRunner) sandboxRunner = deps.createSandboxRunner(createSandboxRunnerOptions({
1658
- db,
1659
- beforeContentWrite: () => assertMediaUsageActivationWriteAllowed(db),
1660
- mediaStorage: mediaStorage ? {
1661
- upload: (opts) => mediaStorage.upload({
1662
- key: opts.key,
1663
- body: opts.body,
1664
- contentType: opts.contentType
1665
- }),
1666
- delete: (key) => mediaStorage.delete(key)
1667
- } : void 0
1668
- }, siteInfo));
1669
- if (!sandboxRunner) return sandboxedPluginCache;
1670
- if (!sandboxRunner.isAvailable()) {
1671
- console.warn("EmDash: Plugin sandbox is configured but not available on this platform. Sandboxed plugins will not be loaded. If using @emdash-cms/sandbox-workerd/sandbox, ensure workerd is installed.");
1672
- return sandboxedPluginCache;
1673
- }
1674
- if (deps.sandboxedPluginEntries.length === 0) return sandboxedPluginCache;
1675
- if (deps.sandboxBypassed) return sandboxedPluginCache;
1676
- for (const entry of deps.sandboxedPluginEntries) {
1677
- const pluginKey = `${entry.id}:${entry.version}`;
1678
- if (sandboxedPluginCache.has(pluginKey)) continue;
1679
- try {
1680
- const manifest = {
1681
- id: entry.id,
1682
- version: entry.version,
1683
- capabilities: entry.capabilities ?? [],
1684
- allowedHosts: entry.allowedHosts ?? [],
1685
- storage: entry.storage ?? {},
1686
- hooks: entry.hooks ?? [],
1687
- routes: entry.routes ?? [],
1688
- admin: {},
1689
- mcp: entry.mcp
1690
- };
1691
- const plugin = await sandboxRunner.load(manifest, entry.code);
1692
- sandboxedPluginCache.set(pluginKey, plugin);
1693
- console.log(`EmDash: Loaded sandboxed plugin ${pluginKey} with capabilities: [${manifest.capabilities.join(", ")}]`);
1694
- if (manifest.routes.length > 0) {
1695
- const routeMetaMap = /* @__PURE__ */ new Map();
1696
- for (const routeEntry of manifest.routes) {
1697
- const normalized = normalizeManifestRoute(routeEntry);
1698
- routeMetaMap.set(normalized.name, buildRouteMeta(normalized));
1699
- }
1700
- sandboxedRouteMetaCache.set(entry.id, routeMetaMap);
1701
- } else sandboxedRouteMetaCache.delete(entry.id);
1702
- } catch (error) {
1703
- console.error(`EmDash: Failed to load sandboxed plugin ${entry.id}:`, error);
1704
- }
1705
- }
1706
- return sandboxedPluginCache;
1707
- }
1708
- /**
1709
- * Cold-start: load marketplace-installed plugins from site-local R2 storage
1710
- *
1711
- * Queries _plugin_state for source='marketplace' rows, fetches each bundle
1712
- * from R2, and loads via SandboxRunner.
1713
- */
1714
- /**
1715
- * Cold-start load of all active sandboxed plugins for one install
1716
- * tier (marketplace or registry) from site-local R2.
1717
- *
1718
- * Mirrors {@link syncSandboxedSourcePlugins} but runs once at runtime
1719
- * creation, before request traffic arrives; the sync method runs on
1720
- * demand after install / update / uninstall handlers.
1721
- */
1722
- static async loadInstalledSandboxedPlugins(source, db, storage, deps, cache, siteInfo) {
1723
- if (!sandboxRunner && deps.createSandboxRunner) sandboxRunner = deps.createSandboxRunner(createSandboxRunnerOptions({
1724
- db,
1725
- beforeContentWrite: () => assertMediaUsageActivationWriteAllowed(db),
1726
- mediaStorage: {
1727
- upload: (opts) => storage.upload({
1728
- key: opts.key,
1729
- body: opts.body,
1730
- contentType: opts.contentType
1731
- }),
1732
- delete: (key) => storage.delete(key)
1733
- }
1734
- }, siteInfo));
1735
- if (deps.sandboxBypassed) return;
1736
- if (!sandboxRunner || !sandboxRunner.isAvailable()) return;
1737
- const keySet = source === "marketplace" ? marketplacePluginKeys : registryPluginKeys;
1738
- try {
1739
- const stateRepo = new PluginStateRepository(db);
1740
- const plugins = source === "marketplace" ? await stateRepo.getMarketplacePlugins() : await stateRepo.getRegistryPlugins();
1741
- for (const plugin of plugins) {
1742
- if (plugin.status !== "active") continue;
1743
- const version = source === "marketplace" ? plugin.marketplaceVersion ?? plugin.version : plugin.version;
1744
- const pluginKey = `${plugin.pluginId}:${version}`;
1745
- if (cache.has(pluginKey)) continue;
1746
- try {
1747
- const bundle = await loadBundleFromR2(storage, plugin.pluginId, version, source);
1748
- if (!bundle) {
1749
- console.warn(`EmDash: ${source} plugin ${plugin.pluginId}@${version} not found in R2`);
1750
- continue;
1751
- }
1752
- const loaded = await sandboxRunner.load(bundle.manifest, bundle.backendCode);
1753
- cache.set(pluginKey, loaded);
1754
- keySet.add(pluginKey);
1755
- marketplaceManifestCache.set(plugin.pluginId, {
1756
- id: bundle.manifest.id,
1757
- version: bundle.manifest.version,
1758
- admin: bundle.manifest.admin,
1759
- mcp: bundle.manifest.mcp,
1760
- storage: bundle.manifest.storage
1761
- });
1762
- if (bundle.manifest.routes.length > 0) {
1763
- const routeMeta = /* @__PURE__ */ new Map();
1764
- for (const entry of bundle.manifest.routes) {
1765
- const normalized = normalizeManifestRoute(entry);
1766
- routeMeta.set(normalized.name, buildRouteMeta(normalized));
1767
- }
1768
- sandboxedRouteMetaCache.set(plugin.pluginId, routeMeta);
1769
- }
1770
- console.log(`EmDash: Loaded ${source} plugin ${pluginKey} with capabilities: [${bundle.manifest.capabilities.join(", ")}]`);
1771
- } catch (error) {
1772
- console.error(`EmDash: Failed to load ${source} plugin ${plugin.pluginId}:`, error);
1773
- }
1774
- }
1775
- } catch {}
1776
- }
1777
- /**
1778
- * Cold-start: load marketplace plugins in bypass mode (sandbox: false).
1779
- *
1780
- * Each active marketplace bundle is read, evaluated via data URL, adapted
1781
- * with adaptSandboxEntry, and returned as a ResolvedPlugin. The caller is
1782
- * responsible for merging these into allPipelinePlugins / configuredPlugins
1783
- * BEFORE the hook pipeline is created, so hooks and routes register in
1784
- * the trusted pipeline.
1785
- *
1786
- * Also caches manifest and route metadata so admin UI / getManifest() work.
1787
- *
1788
- * Returns ResolvedPlugins to be merged into the pipeline.
1789
- */
1790
- static async loadMarketplacePluginsBypassed(db, storage) {
1791
- const resolved = [];
1792
- try {
1793
- const marketplacePlugins = await new PluginStateRepository(db).getMarketplacePlugins();
1794
- if (marketplacePlugins.length === 0) return resolved;
1795
- console.info("EmDash: Sandbox disabled (sandbox: false). Marketplace plugins will run in-process without isolation.");
1796
- const { adaptSandboxEntry } = await import("../plugins/adapt-sandbox-entry.mjs");
1797
- for (const plugin of marketplacePlugins) {
1798
- if (plugin.status !== "active") continue;
1799
- const version = plugin.marketplaceVersion ?? plugin.version;
1800
- try {
1801
- const bundle = await loadBundleFromR2(storage, plugin.pluginId, version);
1802
- if (!bundle) {
1803
- console.warn(`EmDash: Marketplace plugin ${plugin.pluginId}@${version} not found in R2`);
1804
- continue;
1805
- }
1806
- marketplaceManifestCache.set(plugin.pluginId, {
1807
- id: bundle.manifest.id,
1808
- version: bundle.manifest.version,
1809
- admin: bundle.manifest.admin,
1810
- mcp: bundle.manifest.mcp,
1811
- storage: bundle.manifest.storage
1812
- });
1813
- if (bundle.manifest.routes.length > 0) {
1814
- const routeMeta = /* @__PURE__ */ new Map();
1815
- for (const entry of bundle.manifest.routes) {
1816
- const normalized = normalizeManifestRoute(entry);
1817
- routeMeta.set(normalized.name, buildRouteMeta(normalized));
1818
- }
1819
- sandboxedRouteMetaCache.set(plugin.pluginId, routeMeta);
1820
- }
1821
- const pluginModule = await import(`data:text/javascript;base64,${Buffer.from(bundle.backendCode).toString("base64")}`);
1822
- const adapted = adaptSandboxEntry(pluginModule.default ?? pluginModule, {
1823
- id: bundle.manifest.id,
1824
- version: bundle.manifest.version,
1825
- entrypoint: "",
1826
- capabilities: bundle.manifest.capabilities ?? [],
1827
- allowedHosts: bundle.manifest.allowedHosts ?? [],
1828
- storage: bundle.manifest.storage ?? {},
1829
- adminPages: bundle.manifest.admin?.pages,
1830
- adminWidgets: bundle.manifest.admin?.widgets?.map((w) => ({
1831
- id: w.id,
1832
- title: w.title,
1833
- size: w.size === "full" || w.size === "half" || w.size === "third" ? w.size : void 0
1834
- })),
1835
- settingsSchema: bundle.manifest.admin?.settingsSchema
1836
- });
1837
- resolved.push(adapted);
1838
- console.log(`EmDash: Loaded marketplace plugin ${plugin.pluginId}@${version} in-process (sandbox bypassed)`);
1839
- } catch (error) {
1840
- console.error(`EmDash: Failed to load marketplace plugin ${plugin.pluginId} in-process:`, error);
1841
- }
1842
- }
1843
- } catch {}
1844
- return resolved;
1845
- }
1846
- /**
1847
- * Resolve exclusive hook selections on startup.
1848
- *
1849
- * Delegates to the shared resolveExclusiveHooks() in hooks.ts.
1850
- * The runtime version considers all pipeline providers as "active" since
1851
- * the pipeline was already built from only active/enabled plugins.
1852
- */
1853
- static async resolveExclusiveHooks(pipeline, db, deps) {
1854
- if (pipeline.getRegisteredExclusiveHooks().length === 0) return;
1855
- let optionsRepo;
1856
- try {
1857
- optionsRepo = new OptionsRepository(db);
1858
- } catch {
1859
- return;
1860
- }
1861
- const preferredHints = /* @__PURE__ */ new Map();
1862
- for (const entry of deps.sandboxedPluginEntries) if (entry.preferred && entry.preferred.length > 0) preferredHints.set(entry.id, entry.preferred);
1863
- await resolveExclusiveHooks({
1864
- pipeline,
1865
- isActive: () => true,
1866
- getOption: (key) => optionsRepo.get(key),
1867
- getOptions: (keys) => optionsRepo.getMany(keys),
1868
- setOption: (key, value) => optionsRepo.set(key, value),
1869
- deleteOption: async (key) => {
1870
- await optionsRepo.delete(key);
1871
- },
1872
- preferredHints
1873
- });
1874
- }
1875
- /**
1876
- * Build the admin manifest from the live database.
1877
- *
1878
- * Used by the admin UI (sidebar collections, content editor field
1879
- * dispatch, manifest endpoint) and by WordPress import — it's never
1880
- * read on a public request, so this isn't on any anonymous hot path.
1881
- *
1882
- * No cross-request cache. The previous worker-isolate cache produced
1883
- * a class of cross-isolate staleness bugs (#776, #873, #876, #877)
1884
- * because Cloudflare Workers keeps multiple warm isolates per region
1885
- * and there's no fan-out primitive to invalidate them in step. The
1886
- * cache existed to amortize an N+1 schema query pattern; now that
1887
- * `listCollectionsWithFields()` does the same work in two queries,
1888
- * the rebuild is fast enough to pay on every admin request.
1889
- *
1890
- * Within a single request, `requestCached` deduplicates concurrent
1891
- * callers (the manifest endpoint and an admin SSR template, say).
1892
- */
1893
- getManifest() {
1894
- return requestCached("emdash:manifest", () => this._buildManifest());
1895
- }
1896
- /**
1897
- * Build the manifest from the database.
1898
- *
1899
- * Constant query shapes via `listCollectionsWithFields()` — one query
1900
- * for collections, one batched query for fields (chunked at
1901
- * `SQL_BATCH_SIZE` collection IDs to stay under D1's bound-parameter
1902
- * limit). Typical sites stay well under the chunk threshold, so this
1903
- * is two queries in practice; never N+1.
1904
- */
1905
- async _buildManifest() {
1906
- const manifestCollections = await buildManifestCollections({}, this.db);
1907
- const manifestPlugins = {};
1908
- for (const plugin of this.configuredPlugins) {
1909
- const status = this.pluginStates.get(plugin.id);
1910
- const enabled = status === void 0 || status === "active";
1911
- const hasAdminEntry = !!plugin.admin?.entry;
1912
- const hasAdminPages = (plugin.admin?.pages?.length ?? 0) > 0;
1913
- const hasWidgets = (plugin.admin?.widgets?.length ?? 0) > 0;
1914
- let adminMode = "none";
1915
- if (hasAdminEntry) adminMode = "react";
1916
- else if (hasAdminPages || hasWidgets) adminMode = "blocks";
1917
- manifestPlugins[plugin.id] = {
1918
- version: plugin.version,
1919
- enabled,
1920
- adminMode,
1921
- adminPages: plugin.admin?.pages ?? [],
1922
- dashboardWidgets: plugin.admin?.widgets ?? [],
1923
- portableTextBlocks: plugin.admin?.portableTextBlocks,
1924
- fieldWidgets: plugin.admin?.fieldWidgets
1925
- };
1926
- }
1927
- for (const entry of this.sandboxedPluginEntries) {
1928
- const status = this.pluginStates.get(entry.id);
1929
- const enabled = status === void 0 || status === "active";
1930
- const hasAdminPages = (entry.adminPages?.length ?? 0) > 0;
1931
- const hasWidgets = (entry.adminWidgets?.length ?? 0) > 0;
1932
- manifestPlugins[entry.id] = {
1933
- version: entry.version,
1934
- enabled,
1935
- sandboxed: true,
1936
- adminMode: hasAdminPages || hasWidgets ? "blocks" : "none",
1937
- adminPages: entry.adminPages ?? [],
1938
- dashboardWidgets: entry.adminWidgets ?? [],
1939
- portableTextBlocks: entry.portableTextBlocks,
1940
- fieldWidgets: entry.fieldWidgets
1941
- };
1942
- }
1943
- for (const [pluginId, meta] of marketplaceManifestCache) {
1944
- if (manifestPlugins[pluginId]) continue;
1945
- const enabled = this.pluginStates.get(pluginId) === "active";
1946
- const pages = meta.admin?.pages;
1947
- const widgets = meta.admin?.widgets;
1948
- const hasAdminPages = (pages?.length ?? 0) > 0;
1949
- const hasWidgets = (widgets?.length ?? 0) > 0;
1950
- manifestPlugins[pluginId] = {
1951
- version: meta.version,
1952
- enabled,
1953
- sandboxed: true,
1954
- adminMode: hasAdminPages || hasWidgets ? "blocks" : "none",
1955
- adminPages: pages ?? [],
1956
- dashboardWidgets: widgets ?? []
1957
- };
1958
- }
1959
- let manifestTaxonomies = [];
1960
- let taxonomyDefinitionLocales = [];
1961
- try {
1962
- const rows = await this.db.selectFrom("_emdash_taxonomy_defs").selectAll().orderBy("name").execute();
1963
- taxonomyDefinitionLocales = rows.map((row) => row.locale);
1964
- manifestTaxonomies = rows.map((row) => ({
1965
- id: row.id,
1966
- name: row.name,
1967
- label: row.label,
1968
- labelSingular: row.label_singular ?? void 0,
1969
- hierarchical: row.hierarchical === 1,
1970
- collections: parseStringArray(row.collections).toSorted(),
1971
- locale: row.locale,
1972
- translationGroup: row.translation_group ?? row.id
1973
- }));
1974
- } catch (error) {
1975
- console.debug("EmDash: Could not load taxonomy definitions:", error);
1976
- }
1977
- try {
1978
- const configuredLocales = virtualConfig?.i18n?.locales ?? getI18nConfig()?.locales ?? [];
1979
- await warnAboutUnconfiguredTaxonomyLocales(this.db, configuredLocales, taxonomyDefinitionLocales);
1980
- } catch (error) {
1981
- console.warn("[i18n] taxonomy locale diagnostic failed:", error);
1982
- }
1983
- const manifestHash = await hashString(JSON.stringify(manifestCollections) + JSON.stringify(manifestPlugins) + JSON.stringify(manifestTaxonomies));
1984
- const authMode = getAuthMode(this.config);
1985
- const authModeValue = authMode.type === "external" ? authMode.providerType : "passkey";
1986
- const i18nConfig = virtualConfig?.i18n ?? getI18nConfig();
1987
- const i18n = i18nConfig && i18nConfig.locales && i18nConfig.locales.length > 1 ? {
1988
- defaultLocale: i18nConfig.defaultLocale,
1989
- locales: i18nConfig.locales,
1990
- prefixDefaultLocale: i18nConfig.prefixDefaultLocale
1991
- } : void 0;
1992
- const registry = normalizeRegistryConfig(this.config.experimental?.registry) ?? void 0;
1993
- return {
1994
- version: VERSION,
1995
- commit: COMMIT,
1996
- astroVersion: this.config.astroVersion,
1997
- hash: manifestHash,
1998
- collections: manifestCollections,
1999
- plugins: manifestPlugins,
2000
- taxonomies: manifestTaxonomies,
2001
- authMode: authModeValue,
2002
- i18n,
2003
- contentLocale: {
2004
- defaultLocale: i18nConfig?.defaultLocale ?? "en",
2005
- implicit: i18nConfig === null
2006
- },
2007
- marketplace: !!this.config.marketplace,
2008
- registry
2009
- };
2010
- }
2011
- /**
2012
- * Verify and repair FTS indexes on demand. Runs at most once per worker
2013
- * lifetime.
2014
- *
2015
- * Originally called from `EmDashRuntime.create()`, but on a busy D1 link
2016
- * (e.g. SIN replica ~80-150ms per query) it added ~1.5s to every cold
2017
- * start for a modest-sized site — more than every other init phase
2018
- * combined. Anonymous public reads never touch the search write path,
2019
- * so the cost isn't paid back for the vast majority of requests.
2020
- *
2021
- * Instead, search endpoints call this lazily: the first request that
2022
- * actually needs the index pays the verify cost (usually fast — no
2023
- * rebuild needed), everyone else runs cold-free.
2024
- *
2025
- * Uses the runtime's singleton database (`this._db`) rather than the
2026
- * request-scoped DB. Verify reads only, but `rebuildIndex` writes, and
2027
- * a GET search request on D1 carries a `first-unconstrained` session
2028
- * that's free to route at a read replica — unsafe for writes. The
2029
- * singleton always goes through the default binding, which the D1
2030
- * adapter will promote to `first-primary` for write statements.
2031
- *
2032
- * Safe to call concurrently: repeated callers share the same in-flight
2033
- * promise. Errors are swallowed internally so callers don't need to
2034
- * defend against FTS not existing yet (pre-setup).
2035
- */
2036
- async ensureSearchHealthy() {
2037
- if (!isSqlite(this._db)) return;
2038
- try {
2039
- await singleFlightCached(this._searchHealthCache, async () => {
2040
- try {
2041
- const repaired = await new FTSManager(this._db).verifyAndRepairAll();
2042
- if (repaired > 0) console.log(`Repaired ${repaired} corrupted FTS index(es)`);
2043
- } catch {}
2044
- }, {
2045
- anchor: (promise) => after(() => promise),
2046
- ownerTimeoutMs: 3e4
2047
- });
2048
- } catch {}
2049
- }
2050
- async handleContentList(collection, params) {
2051
- return handleContentList(this.db, collection, params);
2052
- }
2053
- async handleContentAuthors(collection) {
2054
- return handleContentAuthors(this.db, collection);
2055
- }
2056
- async handleContentGet(collection, id, locale) {
2057
- const result = await handleContentGet(this.db, collection, id, locale);
2058
- return this.hydrateDraftData(result);
2059
- }
2060
- async handleContentGetIncludingTrashed(collection, id, locale) {
2061
- const result = await handleContentGetIncludingTrashed(this.db, collection, id, locale);
2062
- return this.hydrateDraftData(result);
2063
- }
2064
- /**
2065
- * If the response item has a `draftRevisionId`, replace `item.data` with
2066
- * the draft revision's data and expose the original published values as
2067
- * `liveData`. This makes the content_get / content_update round-trip
2068
- * intuitive — read returns the latest content the caller has saved
2069
- * (their pending draft), with the previously-published values still
2070
- * accessible for compare-style flows.
2071
- *
2072
- * No-op when no draft exists or the response is an error.
2073
- */
2074
- async hydrateDraftData(result) {
2075
- if (!result || typeof result !== "object") return result;
2076
- const r = result;
2077
- if (!r.success || !r.data?.item) return result;
2078
- const item = r.data.item;
2079
- const draftRevisionId = typeof item.draftRevisionId === "string" ? item.draftRevisionId : null;
2080
- if (!draftRevisionId) return result;
2081
- try {
2082
- const revision = await new RevisionRepository(this.db).findById(draftRevisionId);
2083
- if (!revision) return result;
2084
- const liveData = item.data && typeof item.data === "object" ? item.data : {};
2085
- const revisionData = {};
2086
- for (const [key, value] of Object.entries(revision.data)) if (!key.startsWith("_")) revisionData[key] = value;
2087
- const mergedData = {
2088
- ...liveData,
2089
- ...revisionData
2090
- };
2091
- return {
2092
- ...result,
2093
- data: {
2094
- ...r.data,
2095
- item: {
2096
- ...item,
2097
- data: mergedData,
2098
- liveData
2099
- }
2100
- }
2101
- };
2102
- } catch (error) {
2103
- console.error("[emdash] draft hydration failed:", error);
2104
- return result;
2105
- }
2106
- }
2107
- async handleContentCreate(collection, body) {
2108
- let processedData = body.data;
2109
- if (this.hooks.hasHooks("content:beforeSave")) try {
2110
- processedData = (await this.hooks.runContentBeforeSave(body.data, collection, true)).content;
2111
- } catch (error) {
2112
- return beforeSaveFailure(error);
2113
- }
2114
- const sandboxResult = await this.runSandboxedBeforeSave(processedData, collection, true);
2115
- if (!sandboxResult.success) return sandboxResult;
2116
- processedData = sandboxResult.data;
2117
- processedData = await this.normalizeMediaFields(collection, processedData);
2118
- const { validateContentData } = await import("../validation-BMImFJ11.mjs");
2119
- const validation = await validateContentData(this.db, collection, processedData, { partial: false });
2120
- if (!validation.ok) return {
2121
- success: false,
2122
- error: validation.error
2123
- };
2124
- const result = await handleContentCreate(this.db, collection, {
2125
- ...body,
2126
- data: processedData,
2127
- authorId: body.authorId,
2128
- bylines: body.bylines
2129
- });
2130
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2131
- if (result.success && result.data) this.runAfterSaveHooks(contentItemToRecord(result.data.item), collection, true);
2132
- return result;
2133
- }
2134
- async handleContentUpdate(collection, id, body) {
2135
- const repo = new ContentRepository(this.db);
2136
- const resolvedItem = await repo.findByIdOrSlug(collection, id, body.locale);
2137
- const resolvedId = resolvedItem?.id ?? id;
2138
- if (body._rev) {
2139
- if (!resolvedItem) return {
2140
- success: false,
2141
- error: {
2142
- code: "NOT_FOUND",
2143
- message: `Content item not found: ${id}`
2144
- }
2145
- };
2146
- const revCheck = validateRev(body._rev, resolvedItem);
2147
- if (!revCheck.valid) return {
2148
- success: false,
2149
- error: {
2150
- code: "CONFLICT",
2151
- message: revCheck.message
2152
- }
2153
- };
2154
- }
2155
- const { _rev: _discardedRev, ...bodyWithoutRev } = body;
2156
- let processedData = bodyWithoutRev.data;
2157
- if (bodyWithoutRev.data) {
2158
- if (this.hooks.hasHooks("content:beforeSave")) try {
2159
- processedData = (await this.hooks.runContentBeforeSave(bodyWithoutRev.data, collection, false, resolvedItem?.id)).content;
2160
- } catch (error) {
2161
- return beforeSaveFailure(error);
2162
- }
2163
- const sandboxResult = await this.runSandboxedBeforeSave(processedData, collection, false, resolvedItem?.id);
2164
- if (!sandboxResult.success) return sandboxResult;
2165
- processedData = sandboxResult.data;
2166
- processedData = await this.normalizeMediaFields(collection, processedData);
2167
- const { validateContentData } = await import("../validation-BMImFJ11.mjs");
2168
- const validation = await validateContentData(this.db, collection, processedData, { partial: true });
2169
- if (!validation.ok) return {
2170
- success: false,
2171
- error: validation.error
2172
- };
2173
- }
2174
- let usesDraftRevisions = false;
2175
- let draftStorageChanged = false;
2176
- if (processedData) {
2177
- if ((await this.schemaRegistry.getCollectionWithFields(collection))?.supports?.includes("revisions")) {
2178
- usesDraftRevisions = true;
2179
- const revisionRepo = new RevisionRepository(this.db);
2180
- let existing = await repo.findById(collection, resolvedId);
2181
- for (let attempt = 0; existing && attempt < MAX_DRAFT_STAGE_ATTEMPTS; attempt++) {
2182
- let baseData;
2183
- if (existing.draftRevisionId) baseData = (await revisionRepo.findById(existing.draftRevisionId))?.data ?? existing.data;
2184
- else baseData = existing.data;
2185
- const mergedData = {
2186
- ...baseData,
2187
- ...processedData
2188
- };
2189
- if (bodyWithoutRev.slug !== void 0) mergedData._slug = bodyWithoutRev.slug;
2190
- const revision = await revisionRepo.create({
2191
- collection,
2192
- entryId: resolvedId,
2193
- data: mergedData,
2194
- authorId: bodyWithoutRev.authorId ?? void 0
2195
- });
2196
- let staged;
2197
- try {
2198
- staged = await repo.replaceDraftRevision(collection, resolvedId, revision.id, existing);
2199
- } catch (error) {
2200
- try {
2201
- await revisionRepo.deleteIfUnreferenced(collection, resolvedId, revision.id);
2202
- } catch (cleanupError) {
2203
- console.error(`[emdash] Failed to clean up unstaged revision ${revision.id}:`, cleanupError);
2204
- }
2205
- throw error;
2206
- }
2207
- if (!staged) {
2208
- try {
2209
- await revisionRepo.deleteIfUnreferenced(collection, resolvedId, revision.id);
2210
- } catch (cleanupError) {
2211
- console.error(`[emdash] Failed to clean up unstaged revision ${revision.id}:`, cleanupError);
2212
- }
2213
- if (body._rev || attempt === MAX_DRAFT_STAGE_ATTEMPTS - 1) return {
2214
- success: false,
2215
- error: {
2216
- code: "CONFLICT",
2217
- message: new ContentMutationConflictError().message
2218
- }
2219
- };
2220
- existing = await repo.findById(collection, resolvedId);
2221
- continue;
2222
- }
2223
- draftStorageChanged = true;
2224
- if (bodyWithoutRev.skipRevision && existing.draftRevisionId) try {
2225
- await revisionRepo.deleteIfUnreferenced(collection, resolvedId, existing.draftRevisionId);
2226
- } catch (error) {
2227
- console.error(`[emdash] Failed to clean up superseded revision ${existing.draftRevisionId}:`, error);
2228
- }
2229
- else after(async () => {
2230
- try {
2231
- await revisionRepo.pruneQueuedEntry(collection, resolvedId, revision.id, 50);
2232
- } catch (error) {
2233
- console.error(`[revisions] Failed to prune revisions for ${collection}/${resolvedId}:`, error);
2234
- }
2235
- });
2236
- break;
2237
- }
2238
- }
2239
- }
2240
- const liveMetaTouched = Object.entries(bodyWithoutRev).some(([key, value]) => value !== void 0 && !DRAFT_ONLY_UPDATE_KEYS.has(key));
2241
- const result = usesDraftRevisions && !liveMetaTouched ? await handleContentGet(this.db, collection, resolvedId) : await handleContentUpdate(this.db, collection, resolvedId, {
2242
- ...bodyWithoutRev,
2243
- data: usesDraftRevisions ? void 0 : processedData,
2244
- slug: usesDraftRevisions ? void 0 : bodyWithoutRev.slug,
2245
- authorId: bodyWithoutRev.authorId,
2246
- bylines: bodyWithoutRev.bylines
2247
- });
2248
- const liveContentChanged = usesDraftRevisions ? liveMetaTouched : Boolean(processedData || bodyWithoutRev.slug !== void 0 || liveMetaTouched);
2249
- const hydrated = await this.hydrateDraftData(result);
2250
- if (hydrated.success && hydrated.data) {
2251
- const contentIdsToRefresh = [resolvedId];
2252
- if (!usesDraftRevisions && processedData) try {
2253
- contentIdsToRefresh.push(...await findNonTranslatableSiblingContentIds(this.db, collection, resolvedId, hydrated.data.item.translationGroup, processedData));
2254
- } catch (error) {
2255
- console.error(`[media-usage] Failed to discover synced i18n siblings for ${collection}/${resolvedId}:`, error);
2256
- try {
2257
- await markContentMediaUsageCollectionStale(this.db, collection, "CONTENT_USAGE_REFRESH_ERROR");
2258
- } catch (staleError) {
2259
- console.error(`[media-usage] Failed to mark ${collection} stale:`, staleError);
2260
- }
2261
- }
2262
- await this.refreshContentUsageAfterSuccessfulWrite(collection, contentIdsToRefresh);
2263
- } else if (draftStorageChanged) try {
2264
- await markContentMediaUsageCollectionStale(this.db, collection, "CONTENT_USAGE_STALE");
2265
- } catch (error) {
2266
- console.error(`[media-usage] Failed to mark ${collection} stale:`, error);
2267
- }
2268
- if (hydrated.success && hydrated.data) this.runAfterSaveHooks(contentItemToRecord(hydrated.data.item), collection, false);
2269
- if (hydrated.success) return {
2270
- ...hydrated,
2271
- liveContentChanged
2272
- };
2273
- return hydrated;
2274
- }
2275
- async handleContentDelete(collection, id) {
2276
- if (this.hooks.hasHooks("content:beforeDelete")) {
2277
- const { allowed } = await this.hooks.runContentBeforeDelete(id, collection);
2278
- if (!allowed) return {
2279
- success: false,
2280
- error: {
2281
- code: "DELETE_BLOCKED",
2282
- message: "Delete blocked by plugin hook"
2283
- }
2284
- };
2285
- }
2286
- if (!await this.runSandboxedBeforeDelete(id, collection)) return {
2287
- success: false,
2288
- error: {
2289
- code: "DELETE_BLOCKED",
2290
- message: "Delete blocked by sandboxed plugin hook"
2291
- }
2292
- };
2293
- const result = await handleContentDelete(this.db, collection, id);
2294
- if (result.success) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.id]);
2295
- if (result.success) this.runAfterDeleteHooks(id, collection, false);
2296
- return result;
2297
- }
2298
- async handleContentListTrashed(collection, params = {}) {
2299
- return handleContentListTrashed(this.db, collection, params);
2300
- }
2301
- async handleContentRestore(collection, id) {
2302
- const result = await handleContentRestore(this.db, collection, id);
2303
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2304
- if (result.success) this.runAfterRestoreHooks(contentItemToRecord(result.data.item), collection);
2305
- return result;
2306
- }
2307
- async handleContentPermanentDelete(collection, id) {
2308
- const result = await handleContentPermanentDelete(this.db, collection, id);
2309
- if (result.success) await this.deleteContentUsageAfterSuccessfulPermanentDelete(collection, result.data.id);
2310
- if (result.success) this.runAfterDeleteHooks(id, collection, true);
2311
- return result;
2312
- }
2313
- async handleContentCountTrashed(collection, params = {}) {
2314
- return handleContentCountTrashed(this.db, collection, params);
2315
- }
2316
- async handleContentDuplicate(collection, id, authorId) {
2317
- const result = await handleContentDuplicate(this.db, collection, id, authorId);
2318
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2319
- return result;
2320
- }
2321
- async handleContentPublish(collection, id, options = {}) {
2322
- const result = await handleContentPublish(this.db, collection, id, options);
2323
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2324
- if (result.success && result.data) this.runAfterPublishHooks(contentItemToRecord(result.data.item), collection);
2325
- return result;
2326
- }
2327
- async handleContentUnpublish(collection, id, options = {}) {
2328
- const result = await handleContentUnpublish(this.db, collection, id, options);
2329
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2330
- if (result.success && result.data) this.runAfterUnpublishHooks(contentItemToRecord(result.data.item), collection);
2331
- return result;
2332
- }
2333
- async handleContentSchedule(collection, id, scheduledAt) {
2334
- const result = await handleContentSchedule(this.db, collection, id, scheduledAt);
2335
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2336
- if (result.success && result.data) this.runAfterScheduleHooks(contentItemToRecord(result.data.item), collection);
2337
- return result;
2338
- }
2339
- async handleContentUnschedule(collection, id) {
2340
- const result = await handleContentUnschedule(this.db, collection, id);
2341
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2342
- if (result.success && result.data) this.runAfterUnscheduleHooks(contentItemToRecord(result.data.item), collection);
2343
- return result;
2344
- }
2345
- async handleContentCountScheduled(collection) {
2346
- return handleContentCountScheduled(this.db, collection);
2347
- }
2348
- async handleContentDiscardDraft(collection, id, options = {}) {
2349
- const result = await handleContentDiscardDraft(this.db, collection, id, options);
2350
- if (result.success && result.data) await this.refreshContentUsageAfterSuccessfulWrite(collection, [result.data.item.id]);
2351
- return result;
2352
- }
2353
- async handleContentCompare(collection, id) {
2354
- return handleContentCompare(this.db, collection, id);
2355
- }
2356
- async handleContentTranslations(collection, id) {
2357
- return handleContentTranslations(this.db, collection, id);
2358
- }
2359
- async handleMediaList(params) {
2360
- return handleMediaList(this.db, params);
2361
- }
2362
- async handleMediaGet(id) {
2363
- return handleMediaGet(this.db, id);
2364
- }
2365
- async handleMediaCreate(input) {
2366
- let processedInput = input;
2367
- if (this.hooks.hasHooks("media:beforeUpload")) {
2368
- const hookResult = await this.hooks.runMediaBeforeUpload({
2369
- name: input.filename,
2370
- type: input.mimeType,
2371
- size: input.size || 0
2372
- });
2373
- processedInput = {
2374
- ...input,
2375
- filename: hookResult.file.name,
2376
- mimeType: hookResult.file.type,
2377
- size: hookResult.file.size
2378
- };
2379
- }
2380
- const result = await handleMediaCreate(this.db, processedInput);
2381
- if (result.success && this.hooks.hasHooks("media:afterUpload")) {
2382
- const item = result.data.item;
2383
- const mediaItem = {
2384
- id: item.id,
2385
- filename: item.filename,
2386
- mimeType: item.mimeType,
2387
- size: item.size,
2388
- url: `/media/${item.id}/${item.filename}`,
2389
- createdAt: item.createdAt
2390
- };
2391
- this.hooks.runMediaAfterUpload(mediaItem).catch((err) => console.error("EmDash afterUpload hook error:", err));
2392
- }
2393
- return result;
2394
- }
2395
- async handleMediaUpdate(id, input) {
2396
- const result = await handleMediaUpdate(this.db, id, input);
2397
- if (result.success) invalidateSiteSettingsCache();
2398
- return result;
2399
- }
2400
- async handleMediaReplaceMetadata(id, expectedStorageKey, input) {
2401
- const result = await handleMediaReplaceMetadata(this.db, id, expectedStorageKey, input);
2402
- if (result.success) invalidateSiteSettingsCache();
2403
- return result;
2404
- }
2405
- async handleMediaDelete(id) {
2406
- const result = await handleMediaDelete(this.db, id);
2407
- if (result.success) invalidateSiteSettingsCache();
2408
- return result;
2409
- }
2410
- async handleRevisionList(collection, entryId, params = {}) {
2411
- return handleRevisionList(this.db, collection, entryId, params);
2412
- }
2413
- async handleRevisionGet(revisionId) {
2414
- return handleRevisionGet(this.db, revisionId);
2415
- }
2416
- async handleRevisionRestore(revisionId, callerUserId) {
2417
- const revisionRepo = new RevisionRepository(this.db);
2418
- const revision = await revisionRepo.findById(revisionId);
2419
- if (!revision) return {
2420
- success: false,
2421
- error: {
2422
- code: "NOT_FOUND",
2423
- message: `Revision not found: ${revisionId}`
2424
- }
2425
- };
2426
- if (!((await this.schemaRegistry.getCollectionWithFields(revision.collection))?.supports?.includes("revisions") ?? false)) {
2427
- const result = await handleRevisionRestore(this.db, revisionId, callerUserId);
2428
- if (result.success) await this.refreshContentUsageAfterSuccessfulWrite(revision.collection, [revision.entryId]);
2429
- return this.hydrateDraftData(result);
2430
- }
2431
- try {
2432
- const contentRepo = new ContentRepository(this.db);
2433
- const existing = await contentRepo.findById(revision.collection, revision.entryId);
2434
- if (!existing) return {
2435
- success: false,
2436
- error: {
2437
- code: "NOT_FOUND",
2438
- message: `Content item not found: ${revision.entryId}`
2439
- }
2440
- };
2441
- const newDraft = await revisionRepo.create({
2442
- collection: revision.collection,
2443
- entryId: revision.entryId,
2444
- data: revision.data,
2445
- authorId: callerUserId
2446
- });
2447
- try {
2448
- if (!await contentRepo.replaceDraftRevision(revision.collection, revision.entryId, newDraft.id, existing)) throw new ContentMutationConflictError();
2449
- } catch (error) {
2450
- try {
2451
- await revisionRepo.deleteIfUnreferenced(revision.collection, revision.entryId, newDraft.id);
2452
- } catch (cleanupError) {
2453
- console.error(`[emdash] Failed to clean up unrestored revision ${newDraft.id}:`, cleanupError);
2454
- }
2455
- throw error;
2456
- }
2457
- after(async () => {
2458
- try {
2459
- await revisionRepo.pruneQueuedEntry(revision.collection, revision.entryId, newDraft.id, 50);
2460
- } catch (error) {
2461
- console.error(`[revisions] Failed to prune revisions for ${revision.collection}/${revision.entryId}:`, error);
2462
- }
2463
- });
2464
- const refetched = await handleContentGet(this.db, revision.collection, revision.entryId);
2465
- const hydrated = await this.hydrateDraftData(refetched);
2466
- if (hydrated.success) await this.refreshContentUsageAfterSuccessfulWrite(revision.collection, [revision.entryId]);
2467
- return hydrated;
2468
- } catch (error) {
2469
- if (error instanceof ContentMutationConflictError) return {
2470
- success: false,
2471
- error: {
2472
- code: "CONFLICT",
2473
- message: error.message
2474
- }
2475
- };
2476
- console.error("[emdash] revision restore failed:", error);
2477
- return {
2478
- success: false,
2479
- error: {
2480
- code: "REVISION_RESTORE_ERROR",
2481
- message: "Failed to restore revision"
2482
- }
2483
- };
2484
- }
2485
- }
2486
- async refreshContentUsageAfterSuccessfulWrite(collection, contentIds) {
2487
- for (const contentId of new Set(contentIds)) try {
2488
- if ((await processMediaUsageWorkAfterWrite(this.db, collection, contentId)).outcome !== "inactive") continue;
2489
- await refreshContentMediaUsageAfterWrite(this.db, collection, contentId);
2490
- } catch (error) {
2491
- console.error(`[media-usage] Failed after content write ${collection}/${contentId}:`, error);
2492
- continue;
2493
- }
2494
- }
2495
- async deleteContentUsageAfterSuccessfulPermanentDelete(collection, contentId) {
2496
- try {
2497
- if ((await processMediaUsageWorkAfterWrite(this.db, collection, contentId)).outcome !== "inactive") return;
2498
- const result = await deleteContentMediaUsage(this.db, collection, contentId);
2499
- if (!result.success) console.error(`[media-usage] Usage delete for ${collection}/${contentId} finished with ${result.errorCode}`);
2500
- } catch (error) {
2501
- console.error(`[media-usage] Failed after permanent content delete ${collection}/${contentId}:`, error);
2502
- }
2503
- }
2504
- /**
2505
- * Get route metadata for a plugin route without invoking the handler.
2506
- * Used by the catch-all route to decide auth before dispatch.
2507
- * Returns null if the plugin or route doesn't exist.
2508
- */
2509
- getPluginRouteMeta(pluginId, path) {
2510
- if (!this.isPluginEnabled(pluginId)) return null;
2511
- const routeKey = path.replace(LEADING_SLASH_PATTERN, "");
2512
- const trustedPlugin = this.configuredPlugins.find((p) => p.id === pluginId);
2513
- if (trustedPlugin) {
2514
- const route = trustedPlugin.routes[routeKey];
2515
- if (!route) return null;
2516
- return buildRouteMeta(route);
2517
- }
2518
- const meta = sandboxedRouteMetaCache.get(pluginId);
2519
- if (meta) {
2520
- const routeMeta = meta.get(routeKey);
2521
- if (routeMeta) return routeMeta;
2522
- }
2523
- if (routeKey === "admin") {
2524
- const manifestMeta = marketplaceManifestCache.get(pluginId);
2525
- if (manifestMeta?.admin?.pages?.length || manifestMeta?.admin?.widgets?.length) return { public: false };
2526
- const entry = this.sandboxedPluginEntries.find((e) => e.id === pluginId);
2527
- if (entry?.adminPages?.length || entry?.adminWidgets?.length) return { public: false };
2528
- }
2529
- if (this.findSandboxedPlugin(pluginId)) return { public: false };
2530
- return null;
2531
- }
2532
- /**
2533
- * Resolve the settings schema for a runtime-installed (marketplace or
2534
- * registry) plugin from its cached manifest. Returns `{}` for a known
2535
- * plugin without a schema and `null` for unknown plugins, matching the
2536
- * contract of `getPluginSettingsSchema` for build-time plugins.
2537
- */
2538
- getRuntimePluginSettingsSchema(pluginId) {
2539
- const meta = marketplaceManifestCache.get(pluginId);
2540
- if (!meta) return null;
2541
- return meta.admin?.settingsSchema ?? {};
2542
- }
2543
- async handlePluginApiRoute(pluginId, _method, path, request, user) {
2544
- if (!this.isPluginEnabled(pluginId)) return {
2545
- success: false,
2546
- error: {
2547
- code: "NOT_FOUND",
2548
- message: `Plugin not enabled: ${pluginId}`
2549
- }
2550
- };
2551
- const caller = user ? toRouteCallerInfo(user) : void 0;
2552
- const trustedPlugin = this.configuredPlugins.find((p) => p.id === pluginId);
2553
- if (trustedPlugin && this.enabledPlugins.has(trustedPlugin.id)) {
2554
- const routeRegistry = new PluginRouteRegistry({
2555
- ...this.pipelineFactoryOptions,
2556
- emailPipeline: this.email ?? void 0,
2557
- cronReschedule: () => this.cronScheduler?.reschedule(),
2558
- trustedProxyHeaders: getTrustedProxyHeaders(this.config)
2559
- });
2560
- routeRegistry.register(trustedPlugin);
2561
- const routeKey = path.replace(LEADING_SLASH_PATTERN, "");
2562
- const body = await parseRouteInput(request);
2563
- return routeRegistry.invoke(pluginId, routeKey, {
2564
- request,
2565
- body,
2566
- user: caller
2567
- });
2568
- }
2569
- const sandboxedPlugin = this.findSandboxedPlugin(pluginId);
2570
- if (sandboxedPlugin) return this.handleSandboxedRoute(sandboxedPlugin, path, request, caller);
2571
- return {
2572
- success: false,
2573
- error: {
2574
- code: "NOT_FOUND",
2575
- message: `Plugin not found: ${pluginId}`
2576
- }
2577
- };
2578
- }
2579
- async getPluginMcpTools(pluginId) {
2580
- const tools = [];
2581
- const seen = /* @__PURE__ */ new Set();
2582
- for (const plugin of this.configuredPlugins) {
2583
- if (pluginId && plugin.id !== pluginId) continue;
2584
- for (const [name, tool] of Object.entries(plugin.mcp?.tools ?? {})) {
2585
- const route = plugin.routes[tool.route];
2586
- if (!route || route.public || !route.permission || !(route.permission in Permissions)) continue;
2587
- const key = `${plugin.id}__${name}`;
2588
- if (seen.has(key)) continue;
2589
- seen.add(key);
2590
- tools.push({
2591
- pluginId: plugin.id,
2592
- name,
2593
- description: tool.description,
2594
- route: tool.route,
2595
- permission: route.permission,
2596
- destructive: tool.destructive ?? false,
2597
- inputSchema: tool.input,
2598
- outputSchema: tool.output
2599
- });
2600
- }
2601
- }
2602
- const addManifestTools = (id, mcp) => {
2603
- if (pluginId && id !== pluginId) return;
2604
- for (const tool of mcp?.tools ?? []) {
2605
- const key = `${id}__${tool.name}`;
2606
- const routeMeta = this.getPluginRouteMeta(id, tool.route);
2607
- if (seen.has(key) || !routeMeta || routeMeta.public || routeMeta.permission !== tool.permission || !(tool.permission in Permissions)) continue;
2608
- seen.add(key);
2609
- tools.push({
2610
- pluginId: id,
2611
- name: tool.name,
2612
- description: tool.description,
2613
- route: tool.route,
2614
- permission: tool.permission,
2615
- destructive: tool.destructive,
2616
- inputSchema: z.fromJSONSchema({ ...tool.inputSchema }),
2617
- outputSchema: tool.outputSchema ? z.fromJSONSchema({ ...tool.outputSchema }) : void 0
2618
- });
2619
- }
2620
- };
2621
- for (const entry of this.sandboxedPluginEntries) addManifestTools(entry.id, entry.mcp);
2622
- for (const [id, manifest] of marketplaceManifestCache) addManifestTools(id, manifest.mcp);
2623
- return tools;
2624
- }
2625
- async getEnabledPluginMcpTools() {
2626
- const [tools, states] = await Promise.all([this.getPluginMcpTools(), new PluginStateRepository(this.db).getAll()]);
2627
- const stateByPlugin = new Map(states.map((state) => [state.pluginId, state]));
2628
- return tools.filter((tool) => {
2629
- const state = stateByPlugin.get(tool.pluginId);
2630
- if (!state?.mcpToolsEnabled || state.status !== "active" || !this.isPluginEnabled(tool.pluginId)) return false;
2631
- return state.mcpToolsConsent === this.serializePluginMcpConsent(tools, tool.pluginId);
2632
- });
2633
- }
2634
- serializePluginMcpConsent(tools, pluginId) {
2635
- return JSON.stringify(tools.filter((tool) => tool.pluginId === pluginId).map((tool) => ({
2636
- name: tool.name,
2637
- description: tool.description,
2638
- route: tool.route,
2639
- permission: tool.permission,
2640
- destructive: tool.destructive,
2641
- inputSchema: z.toJSONSchema(tool.inputSchema, { target: "draft-7" }),
2642
- ...tool.outputSchema ? { outputSchema: z.toJSONSchema(tool.outputSchema, { target: "draft-7" }) } : {}
2643
- })).toSorted((a, b) => a.name.localeCompare(b.name)));
2644
- }
2645
- async handlePluginMcpTool(pluginId, toolName, route, input, actorId, request, caller) {
2646
- const requestMeta = extractRequestMeta(request, getTrustedProxyHeaders(this.config));
2647
- const audit = new AuditRepository(this.db);
2648
- const headers = new Headers(request.headers);
2649
- headers.delete("content-length");
2650
- headers.delete("content-encoding");
2651
- const internalRequest = new Request(request.url, {
2652
- method: "POST",
2653
- headers,
2654
- body: JSON.stringify(input)
2655
- });
2656
- const result = await this.handlePluginApiRoute(pluginId, "POST", route, internalRequest, caller);
2657
- await audit.log({
2658
- actorId,
2659
- actorIp: requestMeta.ip ?? void 0,
2660
- action: "plugin_tool_invoke",
2661
- resourceType: "plugin_mcp_tool",
2662
- resourceId: `${pluginId}__${toolName}`,
2663
- details: {
2664
- pluginId,
2665
- tool: toolName,
2666
- route
2667
- },
2668
- status: result.success ? "success" : "failure"
2669
- });
2670
- return result;
2671
- }
2672
- async handlePluginMcpDenied(pluginId, toolName, route, actorId, request, reason) {
2673
- const requestMeta = extractRequestMeta(request, getTrustedProxyHeaders(this.config));
2674
- await new AuditRepository(this.db).log({
2675
- actorId,
2676
- actorIp: requestMeta.ip ?? void 0,
2677
- action: "plugin_tool_invoke",
2678
- resourceType: "plugin_mcp_tool",
2679
- resourceId: `${pluginId}__${toolName}`,
2680
- details: {
2681
- pluginId,
2682
- tool: toolName,
2683
- route,
2684
- reason
2685
- },
2686
- status: "denied"
2687
- });
2688
- }
2689
- findSandboxedPlugin(pluginId) {
2690
- for (const [key, plugin] of this.sandboxedPlugins) if (key.startsWith(pluginId + ":")) return plugin;
2691
- }
2692
- /**
2693
- * Normalize image/file fields in content data.
2694
- * Fills missing dimensions, storageKey, mimeType, and filename from providers.
2695
- */
2696
- async normalizeMediaFields(collection, data) {
2697
- let collectionInfo;
2698
- try {
2699
- collectionInfo = await this.schemaRegistry.getCollectionWithFields(collection);
2700
- } catch {
2701
- return data;
2702
- }
2703
- if (!collectionInfo?.fields) return data;
2704
- const imageFields = collectionInfo.fields.filter((f) => f.type === "image" || f.type === "file");
2705
- const repeaterFields = collectionInfo.fields.filter((f) => f.type === "repeater" && Array.isArray(f.validation?.subFields));
2706
- if (imageFields.length === 0 && repeaterFields.length === 0) return data;
2707
- const getProvider = (id) => this.getMediaProvider(id);
2708
- const result = { ...data };
2709
- for (const field of imageFields) {
2710
- const value = result[field.slug];
2711
- if (value == null) continue;
2712
- try {
2713
- const normalized = field.type === "image" ? await normalizeImageValue(value, getProvider) : await normalizeMediaValue(value, getProvider);
2714
- if (normalized) result[field.slug] = normalized;
2715
- } catch {}
2716
- }
2717
- for (const field of repeaterFields) {
2718
- const value = result[field.slug];
2719
- if (!Array.isArray(value)) continue;
2720
- const mediaSubFieldSlugs = (field.validation?.subFields ?? []).filter((sub) => sub.type === "image").map((sub) => sub.slug);
2721
- if (mediaSubFieldSlugs.length === 0) continue;
2722
- const items = value;
2723
- result[field.slug] = await Promise.all(items.map(async (item) => {
2724
- if (!isRecord(item)) return item;
2725
- const normalizedItem = { ...item };
2726
- for (const slug of mediaSubFieldSlugs) {
2727
- const subValue = normalizedItem[slug];
2728
- if (subValue == null) continue;
2729
- try {
2730
- const normalized = await normalizeImageValue(subValue, getProvider);
2731
- if (normalized) normalizedItem[slug] = normalized;
2732
- } catch {}
2733
- }
2734
- return normalizedItem;
2735
- }));
2736
- }
2737
- return result;
2738
- }
2739
- async runSandboxedBeforeSave(content, collection, isNew, contentId) {
2740
- let result = content;
2741
- for (const [pluginKey, plugin] of this.sandboxedPlugins) {
2742
- const [id] = pluginKey.split(":");
2743
- if (!id || !this.isPluginEnabled(id)) continue;
2744
- try {
2745
- const event = {
2746
- content: result,
2747
- collection,
2748
- isNew
2749
- };
2750
- if (contentId !== void 0) event.id = contentId;
2751
- const hookResult = await plugin.invokeHook("content:beforeSave", event);
2752
- const inspection = inspectSandboxHookResult(hookResult);
2753
- if (inspection.kind === "error") return {
2754
- success: false,
2755
- error: {
2756
- code: ErrorCode.SAVE_REJECTED,
2757
- message: "Save rejected by a sandboxed plugin",
2758
- details: {
2759
- pluginId: id,
2760
- reason: inspection.error.reason
2761
- }
2762
- }
2763
- };
2764
- if (inspection.kind === "malformed") {
2765
- console.error(`EmDash: Sandboxed plugin ${id} returned an invalid hook result`);
2766
- return {
2767
- success: false,
2768
- error: {
2769
- code: ErrorCode.CONTENT_HOOK_ERROR,
2770
- message: "A plugin hook failed while saving content"
2771
- }
2772
- };
2773
- }
2774
- if (hookResult && typeof hookResult === "object" && !Array.isArray(hookResult)) {
2775
- const record = {};
2776
- for (const [k, v] of Object.entries(hookResult)) record[k] = v;
2777
- result = record;
2778
- }
2779
- } catch (error) {
2780
- console.error(`EmDash: Sandboxed plugin ${id} beforeSave hook failed:`, error);
2781
- return {
2782
- success: false,
2783
- error: {
2784
- code: ErrorCode.CONTENT_HOOK_ERROR,
2785
- message: "A plugin hook failed while saving content"
2786
- }
2787
- };
2788
- }
2789
- }
2790
- return {
2791
- success: true,
2792
- data: result
2793
- };
2794
- }
2795
- async runSandboxedBeforeDelete(id, collection) {
2796
- for (const [pluginKey, plugin] of this.sandboxedPlugins) {
2797
- const [pluginId] = pluginKey.split(":");
2798
- if (!pluginId || !this.isPluginEnabled(pluginId)) continue;
2799
- try {
2800
- if (await plugin.invokeHook("content:beforeDelete", {
2801
- id,
2802
- collection
2803
- }) === false) return false;
2804
- } catch (error) {
2805
- console.error(`EmDash: Sandboxed plugin ${pluginId} beforeDelete hook error:`, error);
2806
- }
2807
- }
2808
- return true;
2809
- }
2810
- runAfterSaveHooks(content, collection, isNew) {
2811
- after(async () => {
2812
- if (this.hooks.hasHooks("content:afterSave")) try {
2813
- await this.hooks.runContentAfterSave(content, collection, isNew);
2814
- } catch (err) {
2815
- console.error("EmDash afterSave hook error:", err);
2816
- }
2817
- const tasks = [];
2818
- for (const [pluginKey, plugin] of this.sandboxedPlugins) {
2819
- const [id] = pluginKey.split(":");
2820
- if (!id || !this.isPluginEnabled(id)) continue;
2821
- tasks.push((async () => {
2822
- try {
2823
- await plugin.invokeHook("content:afterSave", {
2824
- content,
2825
- collection,
2826
- isNew
2827
- });
2828
- } catch (err) {
2829
- console.error(`EmDash: Sandboxed plugin ${id} afterSave error:`, err);
2830
- }
2831
- })());
2832
- }
2833
- await Promise.allSettled(tasks);
2834
- });
2835
- }
2836
- runAfterDeleteHooks(id, collection, permanent) {
2837
- after(async () => {
2838
- if (this.hooks.hasHooks("content:afterDelete")) try {
2839
- await this.hooks.runContentAfterDelete(id, collection, permanent);
2840
- } catch (err) {
2841
- console.error("EmDash afterDelete hook error:", err);
2842
- }
2843
- const tasks = [];
2844
- for (const [pluginKey, plugin] of this.sandboxedPlugins) {
2845
- const [pluginId] = pluginKey.split(":");
2846
- if (!pluginId || !this.isPluginEnabled(pluginId)) continue;
2847
- tasks.push((async () => {
2848
- try {
2849
- await plugin.invokeHook("content:afterDelete", {
2850
- id,
2851
- collection,
2852
- permanent
2853
- });
2854
- } catch (err) {
2855
- console.error(`EmDash: Sandboxed plugin ${pluginId} afterDelete error:`, err);
2856
- }
2857
- })());
2858
- }
2859
- await Promise.allSettled(tasks);
2860
- });
2861
- }
2862
- runDeferredContentHook(name, content, collection) {
2863
- const label = name.slice(8);
2864
- after(async () => {
2865
- if (this.hooks.hasHooks(name)) try {
2866
- switch (name) {
2867
- case "content:afterPublish":
2868
- await this.hooks.runContentAfterPublish(content, collection);
2869
- break;
2870
- case "content:afterUnpublish":
2871
- await this.hooks.runContentAfterUnpublish(content, collection);
2872
- break;
2873
- case "content:afterRestore":
2874
- await this.hooks.runContentAfterRestore(content, collection);
2875
- break;
2876
- case "content:afterSchedule":
2877
- await this.hooks.runContentAfterSchedule(content, collection);
2878
- break;
2879
- case "content:afterUnschedule":
2880
- await this.hooks.runContentAfterUnschedule(content, collection);
2881
- break;
2882
- }
2883
- } catch (err) {
2884
- console.error(`EmDash ${label} hook error:`, err);
2885
- }
2886
- const tasks = [];
2887
- for (const [pluginKey, plugin] of this.sandboxedPlugins) {
2888
- const [pluginId] = pluginKey.split(":");
2889
- if (!pluginId || !this.isPluginEnabled(pluginId)) continue;
2890
- tasks.push((async () => {
2891
- try {
2892
- await plugin.invokeHook(name, {
2893
- content,
2894
- collection
2895
- });
2896
- } catch (err) {
2897
- console.error(`EmDash: Sandboxed plugin ${pluginId} ${label} error:`, err);
2898
- }
2899
- })());
2900
- }
2901
- await Promise.allSettled(tasks);
2902
- });
2903
- }
2904
- runAfterPublishHooks(content, collection) {
2905
- this.runDeferredContentHook("content:afterPublish", content, collection);
2906
- }
2907
- runAfterUnpublishHooks(content, collection) {
2908
- this.runDeferredContentHook("content:afterUnpublish", content, collection);
2909
- }
2910
- runAfterRestoreHooks(content, collection) {
2911
- this.runDeferredContentHook("content:afterRestore", content, collection);
2912
- }
2913
- runAfterScheduleHooks(content, collection) {
2914
- this.runDeferredContentHook("content:afterSchedule", content, collection);
2915
- }
2916
- runAfterUnscheduleHooks(content, collection) {
2917
- this.runDeferredContentHook("content:afterUnschedule", content, collection);
2918
- }
2919
- async handleSandboxedRoute(plugin, path, request, user) {
2920
- const routeName = path.replace(LEADING_SLASH_PATTERN, "");
2921
- const body = await parseRouteInput(request);
2922
- try {
2923
- const headers = sanitizeHeadersForSandbox(request.headers);
2924
- const meta = extractRequestMeta(request, this.config);
2925
- return {
2926
- success: true,
2927
- data: await plugin.invokeRoute(routeName, body, {
2928
- url: request.url,
2929
- method: request.method,
2930
- headers,
2931
- meta,
2932
- user
2933
- })
2934
- };
2935
- } catch (error) {
2936
- console.error(`EmDash: Sandboxed plugin route error:`, error);
2937
- const sandboxRouteError = getSandboxRouteErrorDetails(error);
2938
- if (sandboxRouteError) return {
2939
- success: false,
2940
- status: sandboxRouteError.status,
2941
- error: {
2942
- code: sandboxRouteError.code,
2943
- message: sandboxRouteError.message
2944
- }
2945
- };
2946
- return {
2947
- success: false,
2948
- error: {
2949
- code: "ROUTE_ERROR",
2950
- message: error instanceof Error ? error.message : String(error)
2951
- }
2952
- };
2953
- }
2954
- }
2955
- /**
2956
- * Cache for page contributions. Uses a WeakMap keyed on the PublicPageContext
2957
- * object so results are collected once per page context per request, even when
2958
- * multiple render components (EmDashHead, EmDashBodyStart, EmDashBodyEnd)
2959
- * request contributions from the same page.
2960
- */
2961
- pageContributionCache = /* @__PURE__ */ new WeakMap();
2962
- /**
2963
- * Collect all page contributions (metadata + fragments) in a single pass.
2964
- * Results are cached by page context object identity.
2965
- */
2966
- async collectPageContributions(page) {
2967
- const cached = this.pageContributionCache.get(page);
2968
- if (cached) return cached;
2969
- const promise = this.doCollectPageContributions(page);
2970
- this.pageContributionCache.set(page, promise);
2971
- return promise;
2972
- }
2973
- async doCollectPageContributions(page) {
2974
- const metadata = [];
2975
- const fragments = [];
2976
- if (this.hooks.hasHooks("page:metadata")) {
2977
- const results = await this.hooks.runPageMetadata({ page });
2978
- for (const r of results) metadata.push(...r.contributions);
2979
- }
2980
- if (this.hooks.hasHooks("page:fragments")) {
2981
- const results = await this.hooks.runPageFragments({ page });
2982
- for (const r of results) fragments.push(...r.contributions);
2983
- }
2984
- for (const [pluginKey, plugin] of this.sandboxedPlugins) {
2985
- const [id] = pluginKey.split(":");
2986
- if (!id || !this.isPluginEnabled(id)) continue;
2987
- try {
2988
- const result = await plugin.invokeHook("page:metadata", { page });
2989
- if (result != null) {
2990
- const items = Array.isArray(result) ? result : [result];
2991
- for (const item of items) if (isValidMetadataContribution(item)) metadata.push(item);
2992
- }
2993
- } catch (error) {
2994
- console.error(`EmDash: Sandboxed plugin ${id} page:metadata error:`, error);
2995
- }
2996
- }
2997
- return {
2998
- metadata,
2999
- fragments
3000
- };
3001
- }
3002
- /**
3003
- * Collect page metadata contributions from trusted and sandboxed plugins.
3004
- * Delegates to the single-pass collector and returns the metadata portion.
3005
- */
3006
- async collectPageMetadata(page) {
3007
- const { metadata } = await this.collectPageContributions(page);
3008
- return metadata;
3009
- }
3010
- /**
3011
- * Collect page fragment contributions from trusted plugins only.
3012
- * Delegates to the single-pass collector and returns the fragments portion.
3013
- */
3014
- async collectPageFragments(page) {
3015
- const { fragments } = await this.collectPageContributions(page);
3016
- return fragments;
3017
- }
3018
- isPluginEnabled(pluginId) {
3019
- const status = this.pluginStates.get(pluginId);
3020
- return status === void 0 || status === "active";
3021
- }
3022
- };
3023
- /**
3024
- * Normalize an image field value together with its `darkVariant`. The media
3025
- * normalizer only keeps the media item's own keys, so the variant is normalized
3026
- * separately and reattached.
3027
- */
3028
- async function normalizeImageValue(value, getProvider) {
3029
- const primary = await normalizePrimaryImageValue(value, getProvider);
3030
- if (!primary || !isRecord(value) || value.darkVariant == null) return primary;
3031
- const darkVariant = await normalizeMediaValue(value.darkVariant, getProvider);
3032
- return darkVariant ? {
3033
- ...primary,
3034
- darkVariant
3035
- } : primary;
3036
- }
3037
- /**
3038
- * Normalize the primary image of an image field value.
3039
- *
3040
- * A legacy string URL that the admin upgraded to `{ id: "", src: url }` so it
3041
- * can carry a dark variant still has to normalize as a string: as an object it
3042
- * counts as local media, which strips `src` and leaves nothing behind. The
3043
- * upgrade outlives the variant — an editor can add one and remove it again —
3044
- * so the shape decides, not the presence of `darkVariant`.
3045
- */
3046
- async function normalizePrimaryImageValue(value, getProvider) {
3047
- if (isRecord(value) && !value.id && typeof value.src === "string" && !value.provider) return normalizeMediaValue(value.src, getProvider);
3048
- return normalizeMediaValue(value, getProvider);
3049
- }
3050
-
3051
- //#endregion
3052
117
  //#region src/media/url.ts
3053
118
  /**
3054
119
  * Resolve the public URL for a locally stored media key. Returns an empty
@@ -3306,7 +371,7 @@ function wrapBodyForStreamMetrics(response) {
3306
371
  */
3307
372
  /** Warm widget areas: one bulk load, primed under each per-area cache key. */
3308
373
  async function prefetchWidgetAreas() {
3309
- const areas = await getWidgetAreas();
374
+ const areas = await requestCached("widget-areas", getWidgetAreas);
3310
375
  for (const area of areas) setRequestCacheEntry(`widget-area:${area.name}`, area);
3311
376
  }
3312
377
  /**
@@ -3654,6 +719,12 @@ function migrationRequiredResponse() {
3654
719
  headers: { "Retry-After": "60" }
3655
720
  });
3656
721
  }
722
+ function runtimeConfigurationErrorResponse(error, pathname) {
723
+ if (!pathname.startsWith("/_emdash/api/")) return null;
724
+ if (error instanceof EmDashConfigurationError) return apiError(error.code, error.message, 500);
725
+ if (error instanceof EmDashStorageError && error.code === "BINDING_NOT_FOUND") return apiError(error.code, error.message, 500);
726
+ return null;
727
+ }
3657
728
  /**
3658
729
  * Baseline security headers applied to all responses.
3659
730
  * Admin routes get additional headers (strict CSP) from auth middleware.
@@ -3790,7 +861,7 @@ const onRequest = defineMiddleware(async (context, next) => {
3790
861
  if (migrationMode === "auto" && !isSetupVerified() && !context.isPrerendered) {
3791
862
  const t0 = performance.now();
3792
863
  try {
3793
- const { getDb } = await import("../loader-Z8vl7zTq.mjs").then((n) => n.c);
864
+ const { getDb } = await import("../loader-t4TxaFiQ.mjs").then((n) => n.c);
3794
865
  await (await getDb()).selectFrom("_emdash_migrations").selectAll().limit(1).execute();
3795
866
  markSetupVerified();
3796
867
  } catch (error) {
@@ -3924,14 +995,18 @@ const onRequest = defineMiddleware(async (context, next) => {
3924
995
  handleContentTranslations: runtime.handleContentTranslations.bind(runtime),
3925
996
  handleMediaList: runtime.handleMediaList.bind(runtime),
3926
997
  handleMediaGet: runtime.handleMediaGet.bind(runtime),
998
+ handleMediaUpload: runtime.handleMediaUpload.bind(runtime),
3927
999
  handleMediaCreate: runtime.handleMediaCreate.bind(runtime),
3928
1000
  handleMediaUpdate: runtime.handleMediaUpdate.bind(runtime),
3929
1001
  ...runtime.handleMediaReplaceMetadata ? { handleMediaReplaceMetadata: runtime.handleMediaReplaceMetadata.bind(runtime) } : {},
3930
1002
  handleMediaDelete: runtime.handleMediaDelete.bind(runtime),
1003
+ ...runtime.handleCommentModerate ? { handleCommentModerate: runtime.handleCommentModerate.bind(runtime) } : {},
3931
1004
  handleRevisionList: runtime.handleRevisionList.bind(runtime),
3932
1005
  handleRevisionGet: runtime.handleRevisionGet.bind(runtime),
3933
1006
  handleRevisionRestore: runtime.handleRevisionRestore.bind(runtime),
3934
1007
  handlePluginApiRoute: runtime.handlePluginApiRoute.bind(runtime),
1008
+ getPluginEditorExtension: runtime.getPluginEditorExtension.bind(runtime),
1009
+ getPluginEditorDraftSchema: runtime.getPluginEditorDraftSchema.bind(runtime),
3935
1010
  handlePublicPluginApiRoute: createPublicPluginApiRouteHandler(runtime),
3936
1011
  getPluginRouteMeta: runtime.getPluginRouteMeta.bind(runtime),
3937
1012
  getPluginMcpTools: runtime.getPluginMcpTools.bind(runtime),
@@ -3960,6 +1035,10 @@ const onRequest = defineMiddleware(async (context, next) => {
3960
1035
  isSandboxBypassed: runtime.isSandboxBypassed.bind(runtime),
3961
1036
  syncMarketplacePlugins: runtime.syncMarketplacePlugins.bind(runtime),
3962
1037
  syncRegistryPlugins: runtime.syncRegistryPlugins.bind(runtime),
1038
+ runPluginInstallLifecycle: runtime.runPluginInstallLifecycle.bind(runtime),
1039
+ runPluginActivateLifecycle: runtime.runPluginActivateLifecycle.bind(runtime),
1040
+ runPluginUninstallLifecycle: runtime.runPluginUninstallLifecycle.bind(runtime),
1041
+ getRuntimePluginSettingsSchema: runtime.getRuntimePluginSettingsSchema.bind(runtime),
3963
1042
  setPluginStatus: runtime.setPluginStatus.bind(runtime)
3964
1043
  };
3965
1044
  } catch (error) {
@@ -3969,6 +1048,8 @@ const onRequest = defineMiddleware(async (context, next) => {
3969
1048
  return migrationRequiredResponse();
3970
1049
  }
3971
1050
  console.error("EmDash middleware error:", error);
1051
+ const configurationError = runtimeConfigurationErrorResponse(error, url.pathname);
1052
+ if (configurationError) return configurationError;
3972
1053
  }
3973
1054
  const lastContentWriteAt = canUseCachedBinding && config?.database?.needsLastContentWriteAt ? await getLastContentWriteAt() : void 0;
3974
1055
  const scoped = createRequestScopedDb$1({