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
@@ -0,0 +1,3732 @@
1
+ import { t as validateIdentifier } from "./validate-DANX1-Qi.mjs";
2
+ import { t as OptionsRepository } from "./options-D5WcorD5.mjs";
3
+ import { n as cachedQuery, t as CacheNamespace } from "./object-cache-DlSVbn5Y.mjs";
4
+ import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-BmWyou79.mjs";
5
+ import { o as decodeCursor, s as encodeCursor } from "./types-BkUg2yHx.mjs";
6
+ import { t as CommentRepository } from "./comment-DcT8qdPK.mjs";
7
+ import { t as PluginContextFactory } from "./context-B195kjqZ.mjs";
8
+ import { i as resolveLocalizedContentRoutePath, n as resolveLocale, r as resolveLocaleChain } from "./resolve-BJIS8wKr.mjs";
9
+ import { r as requestCached } from "./request-cache-DaMhSQdx.mjs";
10
+ import { n as inspectContentPolicyDecision } from "./content-policy-CM4skrNi.mjs";
11
+ import { t as menuTag } from "./chrome-tags-D7LGB91U.mjs";
12
+ import { s as getDb } from "./loader-t4TxaFiQ.mjs";
13
+ import { s as normalizePluginCapabilities } from "./types-k--LneIF.mjs";
14
+ import { ut as sanitizeHref } from "./entry-lock-D3C99MXS.mjs";
15
+ import { r as setCronTasksEnabled } from "./cron-BcR3RN4K.mjs";
16
+ import { n as PluginRouteRegistry } from "./routes-DYsTe-oR.mjs";
17
+ import { t as CommentReactionRepository } from "./comment-reaction-DY5-y8Y5.mjs";
18
+ import { sql } from "kysely";
19
+ import { AsyncLocalStorage } from "node:async_hooks";
20
+ import { ulid } from "ulidx";
21
+ import { z } from "astro/zod";
22
+ import { PLUGIN_CAPABILITIES, isJsonPostRouteContract } from "@emdash-cms/plugin-types";
23
+ import { UnsafePortableTextTableError, portableTextTableToProseMirror, proseMirrorTableToPortableText } from "@emdash-cms/admin/portable-text-table";
24
+ import { Extension, Mark, Node } from "@tiptap/core";
25
+
26
+ //#region src/config/errors.ts
27
+ /** A configuration failure whose message is safe to return from the API. */
28
+ var EmDashConfigurationError = class extends Error {
29
+ constructor(message, code, cause) {
30
+ super(message);
31
+ this.code = code;
32
+ this.cause = cause;
33
+ this.name = "EmDashConfigurationError";
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ //#region src/database/repositories/audit.ts
39
+ /**
40
+ * Audit repository for logging system events
41
+ *
42
+ * Tracks user actions for security, debugging, and compliance.
43
+ * All mutations should create an audit log entry.
44
+ */
45
+ var AuditRepository = class {
46
+ constructor(db) {
47
+ this.db = db;
48
+ }
49
+ /**
50
+ * Create an audit log entry
51
+ */
52
+ async log(input) {
53
+ const id = ulid();
54
+ const row = {
55
+ id,
56
+ actor_id: input.actorId ?? null,
57
+ actor_ip: input.actorIp ?? null,
58
+ action: input.action,
59
+ resource_type: input.resourceType ?? null,
60
+ resource_id: input.resourceId ?? null,
61
+ details: input.details ? JSON.stringify(input.details) : null,
62
+ status: input.status ?? null
63
+ };
64
+ await this.db.insertInto("audit_logs").values(row).execute();
65
+ const log = await this.findById(id);
66
+ if (!log) throw new Error("Failed to create audit log");
67
+ return log;
68
+ }
69
+ /**
70
+ * Find audit log by ID
71
+ */
72
+ async findById(id) {
73
+ const row = await this.db.selectFrom("audit_logs").selectAll().where("id", "=", id).executeTakeFirst();
74
+ return row ? this.rowToAuditLog(row) : null;
75
+ }
76
+ /**
77
+ * Query audit logs with filters and cursor-based pagination
78
+ */
79
+ async findMany(query = {}) {
80
+ const limit = Math.min(Math.max(1, query.limit || 50), 100);
81
+ let q = this.db.selectFrom("audit_logs").selectAll().orderBy("timestamp", "desc").orderBy("id", "desc").limit(limit + 1);
82
+ if (query.actorId) q = q.where("actor_id", "=", query.actorId);
83
+ if (query.action) q = q.where("action", "=", query.action);
84
+ if (query.resourceType) q = q.where("resource_type", "=", query.resourceType);
85
+ if (query.resourceId) q = q.where("resource_id", "=", query.resourceId);
86
+ if (query.status) q = q.where("status", "=", query.status);
87
+ if (query.since) q = q.where("timestamp", ">=", query.since);
88
+ if (query.until) q = q.where("timestamp", "<=", query.until);
89
+ if (query.cursor) {
90
+ const decoded = decodeCursor(query.cursor);
91
+ q = q.where((eb) => eb.or([eb("timestamp", "<", decoded.orderValue), eb.and([eb("timestamp", "=", decoded.orderValue), eb("id", "<", decoded.id)])]));
92
+ }
93
+ const rows = await q.execute();
94
+ const items = rows.slice(0, limit).map((row) => this.rowToAuditLog(row));
95
+ const result = { items };
96
+ if (rows.length > limit && items.length > 0) {
97
+ const last = items.at(-1);
98
+ result.nextCursor = encodeCursor(last.timestamp, last.id);
99
+ }
100
+ return result;
101
+ }
102
+ /**
103
+ * Get all logs for a specific resource
104
+ */
105
+ async findByResource(resourceType, resourceId, options = {}) {
106
+ let query = this.db.selectFrom("audit_logs").selectAll().where("resource_type", "=", resourceType).where("resource_id", "=", resourceId).orderBy("timestamp", "desc");
107
+ if (options.limit) query = query.limit(options.limit);
108
+ return (await query.execute()).map((row) => this.rowToAuditLog(row));
109
+ }
110
+ /**
111
+ * Get all logs for a specific user
112
+ */
113
+ async findByActor(actorId, options = {}) {
114
+ let query = this.db.selectFrom("audit_logs").selectAll().where("actor_id", "=", actorId).orderBy("timestamp", "desc");
115
+ if (options.since) query = query.where("timestamp", ">=", options.since);
116
+ if (options.limit) query = query.limit(options.limit);
117
+ return (await query.execute()).map((row) => this.rowToAuditLog(row));
118
+ }
119
+ /**
120
+ * Count logs matching a query
121
+ */
122
+ async count(query = {}) {
123
+ let q = this.db.selectFrom("audit_logs").select((eb) => eb.fn.count("id").as("count"));
124
+ if (query.actorId) q = q.where("actor_id", "=", query.actorId);
125
+ if (query.action) q = q.where("action", "=", query.action);
126
+ if (query.resourceType) q = q.where("resource_type", "=", query.resourceType);
127
+ if (query.resourceId) q = q.where("resource_id", "=", query.resourceId);
128
+ if (query.status) q = q.where("status", "=", query.status);
129
+ if (query.since) q = q.where("timestamp", ">=", query.since);
130
+ if (query.until) q = q.where("timestamp", "<=", query.until);
131
+ const result = await q.executeTakeFirst();
132
+ return Number(result?.count || 0);
133
+ }
134
+ /**
135
+ * Delete old audit logs (for retention policy)
136
+ */
137
+ async deleteOlderThan(date) {
138
+ const result = await this.db.deleteFrom("audit_logs").where("timestamp", "<", date).executeTakeFirst();
139
+ return Number(result.numDeletedRows ?? 0);
140
+ }
141
+ /**
142
+ * Convert database row to AuditLog object
143
+ */
144
+ rowToAuditLog(row) {
145
+ return {
146
+ id: row.id,
147
+ timestamp: row.timestamp,
148
+ actorId: row.actor_id,
149
+ actorIp: row.actor_ip,
150
+ action: row.action,
151
+ resourceType: row.resource_type,
152
+ resourceId: row.resource_id,
153
+ details: row.details ? JSON.parse(row.details) : null,
154
+ status: row.status
155
+ };
156
+ }
157
+ };
158
+
159
+ //#endregion
160
+ //#region src/fields/image.ts
161
+ const mediaSchema = z.object({
162
+ id: z.string(),
163
+ src: z.string().optional(),
164
+ alt: z.string().optional(),
165
+ width: z.number().optional(),
166
+ height: z.number().optional(),
167
+ filename: z.string().optional(),
168
+ mimeType: z.string().optional(),
169
+ blurhash: z.string().optional(),
170
+ dominantColor: z.string().optional(),
171
+ focalX: z.number().optional(),
172
+ focalY: z.number().optional(),
173
+ provider: z.string().optional(),
174
+ previewUrl: z.string().optional(),
175
+ meta: z.record(z.string(), z.unknown()).optional()
176
+ });
177
+ const imageSchema = mediaSchema.extend({ darkVariant: mediaSchema.optional() });
178
+ function image(options = {}) {
179
+ const validation = options.allowedTypes && options.allowedTypes.length > 0 ? { allowedMimeTypes: [...options.allowedTypes] } : void 0;
180
+ return {
181
+ type: "image",
182
+ columnType: "TEXT",
183
+ schema: options.required === false ? imageSchema.optional() : imageSchema,
184
+ options,
185
+ ui: { widget: "image" },
186
+ validation
187
+ };
188
+ }
189
+
190
+ //#endregion
191
+ //#region src/fields/file.ts
192
+ function file(options = {}) {
193
+ const fileObjSchema = z.object({
194
+ id: z.string(),
195
+ url: z.string().optional(),
196
+ src: z.string().optional(),
197
+ filename: z.string().optional(),
198
+ mimeType: z.string().optional(),
199
+ size: z.number().optional(),
200
+ provider: z.string().optional(),
201
+ meta: z.record(z.string(), z.unknown()).optional()
202
+ });
203
+ return {
204
+ type: "file",
205
+ columnType: "TEXT",
206
+ schema: options.required ? fileObjSchema : fileObjSchema.optional(),
207
+ options,
208
+ ui: {
209
+ widget: "file",
210
+ helpText: options.helpText,
211
+ maxSize: options.maxSize
212
+ },
213
+ validation: options.allowedTypes && options.allowedTypes.length > 0 ? { allowedMimeTypes: [...options.allowedTypes] } : void 0
214
+ };
215
+ }
216
+
217
+ //#endregion
218
+ //#region src/fields/reference.ts
219
+ /**
220
+ * Reference field
221
+ * References another content item by ID
222
+ */
223
+ function reference(collection, options) {
224
+ const schema = z.string();
225
+ return {
226
+ type: "reference",
227
+ columnType: "TEXT",
228
+ schema: options?.required === false ? schema.optional() : schema,
229
+ options: {
230
+ ...options,
231
+ collection
232
+ },
233
+ ui: { widget: "reference" }
234
+ };
235
+ }
236
+
237
+ //#endregion
238
+ //#region src/fields/portable-text.ts
239
+ /**
240
+ * Portable Text block schema
241
+ */
242
+ const portableTextBlockSchema = z.object({
243
+ _type: z.string(),
244
+ _key: z.string()
245
+ }).loose();
246
+ /**
247
+ * Portable Text field
248
+ * Stores structured content in Portable Text format
249
+ */
250
+ function portableText(options) {
251
+ const schema = z.array(portableTextBlockSchema);
252
+ return {
253
+ type: "portableText",
254
+ columnType: "JSON",
255
+ schema: options?.required === false ? schema.optional() : schema,
256
+ options,
257
+ ui: { widget: "portableText" }
258
+ };
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/content/converters/gallery.ts
263
+ /**
264
+ * Normalize an untrusted `images` value into well-formed gallery images.
265
+ * Non-object entries and entries without an asset object are dropped.
266
+ * Missing `_key`s are filled via `generateKey` when provided (PM → PT);
267
+ * left empty otherwise (PT → PM keeps whatever the block carried).
268
+ */
269
+ function sanitizeGalleryImages(value, generateKey) {
270
+ if (!Array.isArray(value)) return [];
271
+ const images = [];
272
+ for (const entry of value) {
273
+ if (!isRecord$3(entry)) continue;
274
+ const record = entry;
275
+ const asset = record.asset;
276
+ if (!isRecord$3(asset)) continue;
277
+ const assetRecord = asset;
278
+ const image = {
279
+ _type: "image",
280
+ _key: typeof record._key === "string" && record._key ? record._key : generateKey ? generateKey() : "",
281
+ asset: {
282
+ _type: "reference",
283
+ _ref: typeof assetRecord._ref === "string" ? assetRecord._ref : "",
284
+ ...typeof assetRecord.url === "string" && assetRecord.url ? { url: assetRecord.url } : {},
285
+ ...typeof assetRecord.provider === "string" && assetRecord.provider ? { provider: assetRecord.provider } : {}
286
+ }
287
+ };
288
+ if (typeof record.alt === "string" && record.alt) image.alt = record.alt;
289
+ if (typeof record.caption === "string" && record.caption) image.caption = record.caption;
290
+ if (typeof record.width === "number") image.width = record.width;
291
+ if (typeof record.height === "number") image.height = record.height;
292
+ if (typeof record.focalX === "number") image.focalX = record.focalX;
293
+ if (typeof record.focalY === "number") image.focalY = record.focalY;
294
+ if (typeof record.blurhash === "string" && record.blurhash) image.blurhash = record.blurhash;
295
+ if (typeof record.dominantColor === "string" && record.dominantColor) image.dominantColor = record.dominantColor;
296
+ images.push(image);
297
+ }
298
+ return images;
299
+ }
300
+ function isRecord$3(value) {
301
+ return typeof value === "object" && value !== null && !Array.isArray(value);
302
+ }
303
+
304
+ //#endregion
305
+ //#region src/content/converters/mark-safety.ts
306
+ const SUPPORTED_PORTABLE_TEXT_DECORATORS = new Set([
307
+ "strong",
308
+ "em",
309
+ "underline",
310
+ "strike-through",
311
+ "subscript",
312
+ "superscript",
313
+ "code"
314
+ ]);
315
+ const SUPPORTED_PROSEMIRROR_MARKS = new Set([
316
+ "bold",
317
+ "strong",
318
+ "italic",
319
+ "em",
320
+ "underline",
321
+ "strike",
322
+ "strikethrough",
323
+ "subscript",
324
+ "superscript",
325
+ "code",
326
+ "link",
327
+ "emdashPortableTextSpan"
328
+ ]);
329
+ function isRecord$2(value) {
330
+ return typeof value === "object" && value !== null && !Array.isArray(value);
331
+ }
332
+ function collectPortableTextMarks(value, inheritedMarkDefs, unsupported) {
333
+ if (Array.isArray(value)) {
334
+ for (const item of value) collectPortableTextMarks(item, inheritedMarkDefs, unsupported);
335
+ return;
336
+ }
337
+ if (!isRecord$2(value)) return;
338
+ let markDefs = inheritedMarkDefs;
339
+ if (Array.isArray(value.markDefs)) {
340
+ const localMarkDefs = new Map(inheritedMarkDefs);
341
+ for (const markDef of value.markDefs) if (isRecord$2(markDef) && typeof markDef._key === "string") localMarkDefs.set(markDef._key, markDef);
342
+ markDefs = localMarkDefs;
343
+ }
344
+ if (value._type === "span" && Array.isArray(value.marks)) for (const mark of value.marks) {
345
+ if (typeof mark !== "string" || SUPPORTED_PORTABLE_TEXT_DECORATORS.has(mark)) continue;
346
+ const markDef = markDefs.get(mark);
347
+ if (markDef?._type === "link") continue;
348
+ unsupported.add(typeof markDef?._type === "string" ? markDef._type : mark);
349
+ }
350
+ for (const [key, child] of Object.entries(value)) if (key !== "markDefs") collectPortableTextMarks(child, markDefs, unsupported);
351
+ }
352
+ function collectProseMirrorMarks(node, unsupported) {
353
+ for (const mark of node.marks ?? []) if (!SUPPORTED_PROSEMIRROR_MARKS.has(mark.type)) unsupported.add(mark.type);
354
+ for (const child of node.content ?? []) collectProseMirrorMarks(child, unsupported);
355
+ }
356
+ var UnsupportedPortableTextMarksError = class extends Error {
357
+ marks;
358
+ constructor(marks) {
359
+ const sortedMarks = [...new Set(marks)].toSorted();
360
+ super(`Unsupported Portable Text marks: ${sortedMarks.join(", ")}`);
361
+ this.name = "UnsupportedPortableTextMarksError";
362
+ this.marks = sortedMarks;
363
+ }
364
+ };
365
+ function findUnsupportedPortableTextMarks(blocks) {
366
+ const unsupported = /* @__PURE__ */ new Set();
367
+ for (const block of blocks) if (block._type === "block" || block._type === "table") collectPortableTextMarks(block, /* @__PURE__ */ new Map(), unsupported);
368
+ return [...unsupported].toSorted();
369
+ }
370
+ function assertPortableTextMarksSupported(blocks) {
371
+ const unsupported = findUnsupportedPortableTextMarks(blocks);
372
+ if (unsupported.length > 0) throw new UnsupportedPortableTextMarksError(unsupported);
373
+ }
374
+ function assertProseMirrorMarksSupported(document) {
375
+ const unsupported = /* @__PURE__ */ new Set();
376
+ for (const node of document.content) collectProseMirrorMarks(node, unsupported);
377
+ if (unsupported.size > 0) throw new UnsupportedPortableTextMarksError(unsupported);
378
+ }
379
+
380
+ //#endregion
381
+ //#region src/content/converters/numbered-list.ts
382
+ const MAX_ORDERED_LIST_START = 2147483647;
383
+ function normalizeListId(value) {
384
+ if (typeof value !== "string") return void 0;
385
+ const normalized = value.trim();
386
+ return normalized.length > 0 && normalized.length <= 128 ? normalized : void 0;
387
+ }
388
+ function normalizeListStart(value) {
389
+ return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= MAX_ORDERED_LIST_START ? value : void 0;
390
+ }
391
+ function deriveLegacyListId(seed) {
392
+ const readable = `legacy:${seed}`;
393
+ if (readable.length <= 128) return readable;
394
+ let hash = 2166136261;
395
+ for (let i = 0; i < seed.length; i++) {
396
+ hash ^= seed.charCodeAt(i);
397
+ hash = Math.imul(hash, 16777619);
398
+ }
399
+ return `legacy:${seed.slice(0, 96)}:${(hash >>> 0).toString(36)}:${seed.length.toString(36)}`;
400
+ }
401
+ function readOrderedListMetadata(attrs, fallbackId) {
402
+ return {
403
+ listId: normalizeListId(attrs?.listId) ?? deriveLegacyListId(fallbackId),
404
+ listStart: normalizeListStart(attrs?.listStart) ?? normalizeListStart(attrs?.start) ?? 1
405
+ };
406
+ }
407
+ function collectProseMirrorOrderedLists(doc) {
408
+ const lists = [];
409
+ const visit = (node, path, depth, context) => {
410
+ if (node.type === "orderedList") lists.push({
411
+ node,
412
+ path,
413
+ depth,
414
+ context
415
+ });
416
+ for (const [index, child] of (node.content ?? []).entries()) {
417
+ const childPath = `${path}:${index}`;
418
+ visit(child, childPath, depth + 1, child.type === "listItem" ? `listItem:${childPath}` : context);
419
+ }
420
+ };
421
+ for (const [index, node] of doc.content.entries()) visit(node, `root:${index}`, 0, "root");
422
+ return lists;
423
+ }
424
+ function cloneProseMirrorNode(node) {
425
+ return {
426
+ ...node,
427
+ attrs: node.attrs ? { ...node.attrs } : void 0,
428
+ content: node.content?.map(cloneProseMirrorNode),
429
+ marks: node.marks?.map((mark) => ({
430
+ ...mark,
431
+ attrs: mark.attrs ? { ...mark.attrs } : void 0
432
+ }))
433
+ };
434
+ }
435
+ function createRepairId(sourceId, scope, attempt) {
436
+ const base = deriveLegacyListId(`repair:${sourceId}:${scope}`);
437
+ const suffix = `:${attempt.toString(36)}`;
438
+ return `${base.slice(0, 128 - suffix.length)}${suffix}`;
439
+ }
440
+ function normalizeProseMirrorOrderedListJson(doc) {
441
+ const normalized = {
442
+ ...doc,
443
+ content: doc.content.map(cloneProseMirrorNode)
444
+ };
445
+ const canonicalBySourceScope = /* @__PURE__ */ new Map();
446
+ const assignedCanonicalIds = /* @__PURE__ */ new Set();
447
+ const lists = collectProseMirrorOrderedLists(normalized).map((list) => {
448
+ const sourceId = normalizeListId(list.node.attrs?.listId) ?? deriveLegacyListId(`pm-json:${list.path}:${list.depth}:${list.context}`);
449
+ const scope = JSON.stringify([list.depth, list.context]);
450
+ const sourceScope = JSON.stringify([sourceId, scope]);
451
+ let listId = canonicalBySourceScope.get(sourceScope);
452
+ if (!listId) {
453
+ if (!assignedCanonicalIds.has(sourceId)) listId = sourceId;
454
+ else {
455
+ let attempt = 0;
456
+ do
457
+ listId = createRepairId(sourceId, scope, attempt++);
458
+ while (assignedCanonicalIds.has(listId));
459
+ }
460
+ canonicalBySourceScope.set(sourceScope, listId);
461
+ assignedCanonicalIds.add(listId);
462
+ }
463
+ return {
464
+ ...list,
465
+ listId,
466
+ scopeKey: JSON.stringify([
467
+ listId,
468
+ list.depth,
469
+ list.context
470
+ ])
471
+ };
472
+ });
473
+ const bases = /* @__PURE__ */ new Map();
474
+ for (const list of lists) {
475
+ const listStart = normalizeListStart(list.node.attrs?.listStart);
476
+ if (listStart !== void 0 && !bases.has(list.scopeKey)) bases.set(list.scopeKey, listStart);
477
+ }
478
+ for (const list of lists) if (!bases.has(list.scopeKey)) bases.set(list.scopeKey, normalizeListStart(list.node.attrs?.start) ?? 1);
479
+ const counts = /* @__PURE__ */ new Map();
480
+ for (const list of lists) {
481
+ const listStart = bases.get(list.scopeKey);
482
+ const count = counts.get(list.scopeKey) ?? 0;
483
+ const start = normalizeListStart(listStart + count) ?? 1;
484
+ const directItemCount = list.node.content?.filter((node) => node.type === "listItem").length ?? 0;
485
+ counts.set(list.scopeKey, count + directItemCount);
486
+ list.node.attrs = {
487
+ ...list.node.attrs,
488
+ listId: list.listId,
489
+ listStart,
490
+ start
491
+ };
492
+ }
493
+ return normalized;
494
+ }
495
+
496
+ //#endregion
497
+ //#region src/content/converters/portable-text-identity.ts
498
+ const PORTABLE_TEXT_BLOCK_NODE = "emdashPortableTextBlock";
499
+ const PORTABLE_TEXT_BLOCK_ATTR = "emdashPortableTextBlock";
500
+ const PORTABLE_TEXT_KEY_ATTR = "emdashPortableTextKey";
501
+ const PORTABLE_TEXT_SPAN_MARK = "emdashPortableTextSpan";
502
+ function isRecord$1(value) {
503
+ return typeof value === "object" && value !== null && !Array.isArray(value);
504
+ }
505
+ function attrsWithPortableTextKey(attrs, key) {
506
+ return {
507
+ ...attrs,
508
+ [PORTABLE_TEXT_KEY_ATTR]: key
509
+ };
510
+ }
511
+ function portableTextKeyFromAttrs(attrs) {
512
+ const key = attrs?.[PORTABLE_TEXT_KEY_ATTR];
513
+ return typeof key === "string" && key ? key : void 0;
514
+ }
515
+ function portableTextSpanKeyFromMarks(marks) {
516
+ for (const mark of marks ?? []) {
517
+ if (!isRecord$1(mark) || mark.type !== PORTABLE_TEXT_SPAN_MARK || !isRecord$1(mark.attrs)) continue;
518
+ const key = mark.attrs.key;
519
+ if (typeof key === "string" && key) return key;
520
+ }
521
+ }
522
+ function portableTextMarkDefsFromMarks(marks) {
523
+ const identity = (marks ?? []).find((mark) => isRecord$1(mark) && mark.type === PORTABLE_TEXT_SPAN_MARK && isRecord$1(mark.attrs));
524
+ if (!isRecord$1(identity) || !isRecord$1(identity.attrs) || !Array.isArray(identity.attrs.markDefs)) return [];
525
+ return identity.attrs.markDefs.filter((markDef) => isRecord$1(markDef) && typeof markDef._type === "string" && typeof markDef._key === "string");
526
+ }
527
+ function portableTextBlockFromAttrs(attrs) {
528
+ const block = attrs?.[PORTABLE_TEXT_BLOCK_ATTR];
529
+ if (!isRecord$1(block) || typeof block._type !== "string" || typeof block._key !== "string") return;
530
+ return {
531
+ ...block,
532
+ _type: block._type,
533
+ _key: block._key
534
+ };
535
+ }
536
+ const PortableTextIdentityExtension = Extension.create({
537
+ name: "emdashPortableTextIdentity",
538
+ addGlobalAttributes() {
539
+ const hiddenAttribute = {
540
+ default: null,
541
+ rendered: false
542
+ };
543
+ return [{
544
+ types: [
545
+ "paragraph",
546
+ "heading",
547
+ "blockquote",
548
+ "codeBlock",
549
+ "htmlBlock",
550
+ "image",
551
+ "horizontalRule",
552
+ "gallery",
553
+ PORTABLE_TEXT_BLOCK_NODE
554
+ ],
555
+ attributes: { [PORTABLE_TEXT_KEY_ATTR]: hiddenAttribute }
556
+ }];
557
+ }
558
+ });
559
+ const PortableTextSpanIdentity = Mark.create({
560
+ name: PORTABLE_TEXT_SPAN_MARK,
561
+ inclusive: false,
562
+ spanning: false,
563
+ addAttributes() {
564
+ return {
565
+ key: {
566
+ default: null,
567
+ rendered: false
568
+ },
569
+ markDefs: {
570
+ default: [],
571
+ rendered: false
572
+ }
573
+ };
574
+ },
575
+ parseHTML() {
576
+ return [];
577
+ },
578
+ renderHTML() {
579
+ return ["span", 0];
580
+ }
581
+ });
582
+ const PortableTextOpaqueBlock = Node.create({
583
+ name: PORTABLE_TEXT_BLOCK_NODE,
584
+ group: "block",
585
+ atom: true,
586
+ selectable: true,
587
+ draggable: true,
588
+ addAttributes() {
589
+ return { [PORTABLE_TEXT_BLOCK_ATTR]: {
590
+ default: null,
591
+ rendered: false
592
+ } };
593
+ },
594
+ parseHTML() {
595
+ return [{ tag: "div[data-emdash-portable-text-block]" }];
596
+ },
597
+ renderHTML({ node }) {
598
+ const blockType = portableTextBlockFromAttrs(node.attrs)?._type ?? "unknown";
599
+ return [
600
+ "div",
601
+ {
602
+ "data-emdash-portable-text-block": blockType,
603
+ contenteditable: "false"
604
+ },
605
+ `[Unknown block type: ${blockType}]`
606
+ ];
607
+ }
608
+ });
609
+ const portableTextIdentityExtensions = [
610
+ PortableTextIdentityExtension,
611
+ PortableTextSpanIdentity,
612
+ PortableTextOpaqueBlock
613
+ ];
614
+
615
+ //#endregion
616
+ //#region src/content/converters/prosemirror-to-portable-text.ts
617
+ /**
618
+ * ProseMirror to Portable Text Converter
619
+ *
620
+ * Converts TipTap's ProseMirror JSON format to Portable Text for storage.
621
+ */
622
+ /**
623
+ * Generate a unique key for Portable Text blocks
624
+ */
625
+ function generateKey$1() {
626
+ return Math.random().toString(36).substring(2, 11);
627
+ }
628
+ /**
629
+ * Convert ProseMirror document to Portable Text
630
+ */
631
+ function prosemirrorToPortableText(doc) {
632
+ if (!doc || doc.type !== "doc" || !doc.content) return [];
633
+ assertProseMirrorMarksSupported(doc);
634
+ const blocks = [];
635
+ const usedBlockKeys = /* @__PURE__ */ new Set();
636
+ for (const [i, node] of doc.content.entries()) {
637
+ if (i === doc.content.length - 1 && isUnkeyedEmptyParagraph(node)) continue;
638
+ const converted = convertNode(node, `root:${i}`);
639
+ for (const block of converted ? Array.isArray(converted) ? converted : [converted] : []) {
640
+ let key = block._key;
641
+ if (usedBlockKeys.has(key)) do
642
+ key = generateKey$1();
643
+ while (usedBlockKeys.has(key));
644
+ usedBlockKeys.add(key);
645
+ blocks.push(key === block._key ? block : {
646
+ ...block,
647
+ _key: key
648
+ });
649
+ }
650
+ }
651
+ return blocks;
652
+ }
653
+ function isUnkeyedEmptyParagraph(node) {
654
+ return node.type === "paragraph" && (node.content?.length ?? 0) === 0 && portableTextKeyFromAttrs(node.attrs) === void 0;
655
+ }
656
+ /**
657
+ * Convert a single ProseMirror node to Portable Text block(s)
658
+ */
659
+ function convertNode(node, path) {
660
+ switch (node.type) {
661
+ case PORTABLE_TEXT_BLOCK_NODE: return portableTextBlockFromAttrs(node.attrs) ?? null;
662
+ case "paragraph": return convertParagraph(node);
663
+ case "heading": return convertHeading(node);
664
+ case "bulletList": return convertList$1(node, "bullet", path);
665
+ case "orderedList": return convertList$1(node, "number", path);
666
+ case "blockquote": return convertBlockquote(node);
667
+ case "codeBlock": return convertCodeBlock$1(node);
668
+ case "htmlBlock": return convertHtmlBlock(node);
669
+ case "image": return convertImage$1(node);
670
+ case "gallery": return convertGallery(node);
671
+ case "table": {
672
+ const result = proseMirrorTableToPortableText(node, {
673
+ path,
674
+ createKey: generateKey$1,
675
+ inlineToSpans: (content) => {
676
+ const { children, markDefs } = convertInlineContent(content, true);
677
+ return {
678
+ content: children,
679
+ markDefs
680
+ };
681
+ }
682
+ });
683
+ if (!result.ok) throw new UnsafePortableTextTableError(result.reason, result.raw, result.renderFallback);
684
+ return result.table;
685
+ }
686
+ case "horizontalRule": return {
687
+ _type: "break",
688
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
689
+ style: "lineBreak"
690
+ };
691
+ default: return {
692
+ _type: node.type,
693
+ _key: generateKey$1(),
694
+ ...node.attrs,
695
+ _pmContent: node.content
696
+ };
697
+ }
698
+ }
699
+ /**
700
+ * Convert paragraph to Portable Text block
701
+ */
702
+ function convertParagraph(node) {
703
+ const { children, markDefs } = convertInlineContent(node.content || []);
704
+ if (children.length === 0) return null;
705
+ const ta = node.attrs?.textAlign;
706
+ const textAlign = ta === "center" || ta === "right" || ta === "justify" ? ta : void 0;
707
+ return {
708
+ _type: "block",
709
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
710
+ style: "normal",
711
+ children,
712
+ ...markDefs.length > 0 ? { markDefs } : {},
713
+ ...textAlign ? { textAlign } : {}
714
+ };
715
+ }
716
+ /** Map heading level number to Portable Text style */
717
+ function headingLevelToStyle(level) {
718
+ switch (level) {
719
+ case 1: return "h1";
720
+ case 2: return "h2";
721
+ case 3: return "h3";
722
+ case 4: return "h4";
723
+ case 5: return "h5";
724
+ case 6: return "h6";
725
+ default: return "h1";
726
+ }
727
+ }
728
+ /**
729
+ * Convert heading to Portable Text block
730
+ */
731
+ function convertHeading(node) {
732
+ const { children, markDefs } = convertInlineContent(node.content || []);
733
+ const style = headingLevelToStyle(typeof node.attrs?.level === "number" ? node.attrs.level : 1);
734
+ if (children.length === 0) return null;
735
+ const ta = node.attrs?.textAlign;
736
+ const textAlign = ta === "center" || ta === "right" || ta === "justify" ? ta : void 0;
737
+ return {
738
+ _type: "block",
739
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
740
+ style,
741
+ children,
742
+ markDefs: markDefs.length > 0 ? markDefs : void 0,
743
+ ...textAlign ? { textAlign } : {}
744
+ };
745
+ }
746
+ /**
747
+ * Convert list to Portable Text blocks
748
+ */
749
+ function convertList$1(node, listItem, path) {
750
+ const blocks = [];
751
+ const metadata = listItem === "number" ? readOrderedListMetadata(node.attrs, path) : void 0;
752
+ for (const [i, item] of (node.content ?? []).entries()) if (item.type === "listItem") {
753
+ const itemBlocks = convertListItem$1(item, listItem, 1, `${path}:${i}`, metadata);
754
+ blocks.push(...itemBlocks);
755
+ }
756
+ return blocks;
757
+ }
758
+ /**
759
+ * Convert list item to Portable Text blocks
760
+ */
761
+ function convertListItem$1(item, listItem, level, path, metadata) {
762
+ const blocks = [];
763
+ for (const [i, child] of (item.content ?? []).entries()) if (child.type === "paragraph") {
764
+ const { children, markDefs } = convertInlineContent(child.content || []);
765
+ if (children.length > 0) blocks.push({
766
+ _type: "block",
767
+ _key: portableTextKeyFromAttrs(child.attrs) ?? generateKey$1(),
768
+ style: "normal",
769
+ listItem,
770
+ level,
771
+ ...metadata,
772
+ children,
773
+ markDefs: markDefs.length > 0 ? markDefs : void 0
774
+ });
775
+ } else if (child.type === "bulletList") blocks.push(...convertListItemNested(child, "bullet", level + 1, `${path}:${i}`));
776
+ else if (child.type === "orderedList") blocks.push(...convertListItemNested(child, "number", level + 1, `${path}:${i}`));
777
+ return blocks;
778
+ }
779
+ /**
780
+ * Convert nested list
781
+ */
782
+ function convertListItemNested(node, listItem, level, path) {
783
+ const blocks = [];
784
+ const metadata = listItem === "number" ? readOrderedListMetadata(node.attrs, path) : void 0;
785
+ for (const [i, item] of (node.content ?? []).entries()) if (item.type === "listItem") blocks.push(...convertListItem$1(item, listItem, level, `${path}:${i}`, metadata));
786
+ return blocks;
787
+ }
788
+ /**
789
+ * Convert blockquote to Portable Text blocks
790
+ */
791
+ function convertBlockquote(node) {
792
+ const blocks = [];
793
+ for (const child of node.content || []) if (child.type === "paragraph") {
794
+ const { children, markDefs } = convertInlineContent(child.content || []);
795
+ if (children.length > 0) blocks.push({
796
+ _type: "block",
797
+ _key: portableTextKeyFromAttrs(child.attrs) ?? portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
798
+ style: "blockquote",
799
+ children,
800
+ markDefs: markDefs.length > 0 ? markDefs : void 0
801
+ });
802
+ }
803
+ return blocks.length === 1 ? blocks[0] : blocks.length > 0 ? blocks : null;
804
+ }
805
+ /**
806
+ * Convert code block to Portable Text
807
+ */
808
+ function convertCodeBlock$1(node) {
809
+ const code = node.content?.map((n) => n.text || "").join("") || "";
810
+ const language = typeof node.attrs?.language === "string" ? node.attrs.language : void 0;
811
+ return {
812
+ _type: "code",
813
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
814
+ code,
815
+ language: language || void 0
816
+ };
817
+ }
818
+ /**
819
+ * Convert HTML block to Portable Text
820
+ */
821
+ function convertHtmlBlock(node) {
822
+ const rawHtml = node.attrs?.html;
823
+ return {
824
+ _type: "htmlBlock",
825
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
826
+ html: typeof rawHtml === "string" ? rawHtml : ""
827
+ };
828
+ }
829
+ /**
830
+ * Convert image to Portable Text
831
+ */
832
+ function convertImage$1(node) {
833
+ const attrs = node.attrs;
834
+ const provider = typeof attrs?.provider === "string" ? attrs.provider : void 0;
835
+ const mediaId = typeof attrs?.mediaId === "string" ? attrs.mediaId : void 0;
836
+ const src = typeof attrs?.src === "string" ? attrs.src : "";
837
+ const alt = typeof attrs?.alt === "string" ? attrs.alt : void 0;
838
+ const title = typeof attrs?.title === "string" ? attrs.title : void 0;
839
+ const width = typeof attrs?.width === "number" ? attrs.width : void 0;
840
+ const height = typeof attrs?.height === "number" ? attrs.height : void 0;
841
+ const displayWidth = typeof attrs?.displayWidth === "number" ? attrs.displayWidth : void 0;
842
+ const displayHeight = typeof attrs?.displayHeight === "number" ? attrs.displayHeight : void 0;
843
+ const alignment = attrs?.alignment;
844
+ return {
845
+ _type: "image",
846
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
847
+ asset: {
848
+ _ref: mediaId || src || "",
849
+ url: src || "",
850
+ provider: provider && provider !== "local" ? provider : void 0
851
+ },
852
+ alt: alt || void 0,
853
+ caption: title || void 0,
854
+ width: width || void 0,
855
+ height: height || void 0,
856
+ displayWidth: displayWidth || void 0,
857
+ displayHeight: displayHeight || void 0,
858
+ alignment: alignment === "left" || alignment === "center" || alignment === "right" || alignment === "wide" || alignment === "full" ? alignment : void 0
859
+ };
860
+ }
861
+ /**
862
+ * Convert gallery node to Portable Text
863
+ */
864
+ function convertGallery(node) {
865
+ const columns = node.attrs?.columns;
866
+ return {
867
+ _type: "gallery",
868
+ _key: portableTextKeyFromAttrs(node.attrs) ?? generateKey$1(),
869
+ images: sanitizeGalleryImages(node.attrs?.images, generateKey$1),
870
+ ...typeof columns === "number" ? { columns } : {}
871
+ };
872
+ }
873
+ /**
874
+ * Convert inline content (text nodes with marks) to Portable Text spans
875
+ */
876
+ function convertInlineContent(nodes, preserveHardBreakBoundary = false) {
877
+ const children = [];
878
+ const markDefs = [];
879
+ const markDefMap = /* @__PURE__ */ new Map();
880
+ const usedSpanKeys = /* @__PURE__ */ new Set();
881
+ const claimSpanKey = (preferred) => {
882
+ if (preferred && !usedSpanKeys.has(preferred)) {
883
+ usedSpanKeys.add(preferred);
884
+ return preferred;
885
+ }
886
+ let key;
887
+ do
888
+ key = generateKey$1();
889
+ while (usedSpanKeys.has(key));
890
+ usedSpanKeys.add(key);
891
+ return key;
892
+ };
893
+ for (const node of nodes) if (node.type === "text" && node.text) {
894
+ const marks = [];
895
+ const originalMarkDefs = portableTextMarkDefsFromMarks(node.marks);
896
+ for (const mark of node.marks || []) {
897
+ const markType = convertMark(mark, markDefs, markDefMap, originalMarkDefs);
898
+ if (markType) marks.push(markType);
899
+ }
900
+ const preferredKey = portableTextSpanKeyFromMarks(node.marks) ?? portableTextKeyFromAttrs(node.attrs);
901
+ const normalizedMarks = marks.length > 0 ? marks : void 0;
902
+ const previous = children.at(-1);
903
+ if (preferredKey && previous?._key === preferredKey && JSON.stringify(previous.marks) === JSON.stringify(normalizedMarks)) {
904
+ previous.text += node.text;
905
+ continue;
906
+ }
907
+ children.push({
908
+ _type: "span",
909
+ _key: claimSpanKey(preferredKey),
910
+ text: node.text,
911
+ marks: normalizedMarks
912
+ });
913
+ } else if (node.type === "hardBreak") if (children.length > 0 && !preserveHardBreakBoundary) {
914
+ const lastChild = children.at(-1);
915
+ lastChild.text += "\n";
916
+ } else children.push({
917
+ _type: "span",
918
+ _key: claimSpanKey(portableTextSpanKeyFromMarks(node.marks) ?? portableTextKeyFromAttrs(node.attrs)),
919
+ text: "\n"
920
+ });
921
+ if (children.length === 0) children.push({
922
+ _type: "span",
923
+ _key: claimSpanKey(),
924
+ text: ""
925
+ });
926
+ return {
927
+ children,
928
+ markDefs
929
+ };
930
+ }
931
+ /**
932
+ * Convert a ProseMirror mark to Portable Text mark
933
+ */
934
+ function convertMark(mark, markDefs, markDefMap, originalMarkDefs) {
935
+ switch (mark.type) {
936
+ case "bold":
937
+ case "strong": return "strong";
938
+ case "italic":
939
+ case "em": return "em";
940
+ case "underline": return "underline";
941
+ case "strike":
942
+ case "strikethrough": return "strike-through";
943
+ case "subscript": return "subscript";
944
+ case "superscript": return "superscript";
945
+ case "code": return "code";
946
+ case PORTABLE_TEXT_SPAN_MARK: return null;
947
+ case "link": {
948
+ const href = (typeof mark.attrs?.href === "string" ? mark.attrs.href : "") || "";
949
+ const blank = mark.attrs?.target === "_blank";
950
+ const originalMarkDef = originalMarkDefs.find((markDef) => markDef._type === "link");
951
+ const mapKey = originalMarkDef ? `key:${originalMarkDef._key}` : `value:${JSON.stringify([href, blank])}`;
952
+ if (markDefMap.has(mapKey)) return markDefMap.get(mapKey);
953
+ const key = originalMarkDef?._key || generateKey$1();
954
+ markDefs.push({
955
+ ...originalMarkDef,
956
+ _type: "link",
957
+ _key: key,
958
+ href,
959
+ ...originalMarkDef ? blank || Object.hasOwn(originalMarkDef, "blank") ? { blank } : {} : { blank }
960
+ });
961
+ markDefMap.set(mapKey, key);
962
+ return key;
963
+ }
964
+ default: throw new UnsupportedPortableTextMarksError([mark.type]);
965
+ }
966
+ }
967
+
968
+ //#endregion
969
+ //#region src/content/converters/portable-text-to-prosemirror.ts
970
+ /**
971
+ * Portable Text to ProseMirror Converter
972
+ *
973
+ * Converts Portable Text to TipTap's ProseMirror JSON format for editing.
974
+ */
975
+ function generateKey() {
976
+ return Math.random().toString(36).substring(2, 11);
977
+ }
978
+ /** Convert Portable Text to a ProseMirror document. */
979
+ function portableTextToProsemirror(blocks, options = {}) {
980
+ if (!blocks || blocks.length === 0) return {
981
+ type: "doc",
982
+ content: [{ type: "paragraph" }]
983
+ };
984
+ assertPortableTextMarksSupported(blocks);
985
+ const preserveIdentity = options.preserveIdentity === true;
986
+ const content = [];
987
+ let i = 0;
988
+ while (i < blocks.length) {
989
+ const block = blocks[i];
990
+ if (isTextBlock(block) && block.listItem) {
991
+ const listBlocks = [];
992
+ const listType = block.listItem;
993
+ const runStart = i;
994
+ const rootId = listType === "number" ? normalizeListId(block.listId) : void 0;
995
+ while (i < blocks.length) {
996
+ const current = blocks[i];
997
+ if (!isTextBlock(current) || !current.listItem) break;
998
+ const level = current.level || 1;
999
+ const currentId = current.listItem === "number" ? normalizeListId(current.listId) : void 0;
1000
+ const sameRootIdentity = listType !== "number" || level > 1 || (rootId ? currentId === rootId : currentId === void 0);
1001
+ if (level > 1 || current.listItem === listType && sameRootIdentity) {
1002
+ listBlocks.push(current);
1003
+ i++;
1004
+ } else break;
1005
+ }
1006
+ content.push(convertList(listBlocks, listType, `root:${runStart}`, preserveIdentity));
1007
+ } else if (isTextBlock(block) && block.style === "blockquote") {
1008
+ const quoteBlocks = [];
1009
+ while (i < blocks.length) {
1010
+ const current = blocks[i];
1011
+ if (!isTextBlock(current) || current.style !== "blockquote" || current.listItem !== void 0) break;
1012
+ quoteBlocks.push(current);
1013
+ i++;
1014
+ }
1015
+ content.push({
1016
+ type: "blockquote",
1017
+ content: quoteBlocks.map((quoteBlock) => {
1018
+ const paragraph = convertSpans(quoteBlock.children, quoteBlock.markDefs || [], preserveIdentity);
1019
+ return {
1020
+ type: "paragraph",
1021
+ attrs: identityAttrs(void 0, quoteBlock._key, preserveIdentity),
1022
+ content: paragraph.length > 0 ? paragraph : void 0
1023
+ };
1024
+ })
1025
+ });
1026
+ } else {
1027
+ const converted = convertBlock(block, `root:${i}`, preserveIdentity);
1028
+ if (converted) content.push(converted);
1029
+ i++;
1030
+ }
1031
+ }
1032
+ return normalizeProseMirrorOrderedListJson({
1033
+ type: "doc",
1034
+ content: content.length > 0 ? content : [{ type: "paragraph" }]
1035
+ });
1036
+ }
1037
+ function identityAttrs(attrs, key, preserveIdentity) {
1038
+ return preserveIdentity ? attrsWithPortableTextKey(attrs, key) : attrs;
1039
+ }
1040
+ function getListMetadata(item, fallbackSeed) {
1041
+ const listId = normalizeListId(item.listId) ?? deriveLegacyListId(fallbackSeed);
1042
+ const listStart = normalizeListStart(item.listStart);
1043
+ return {
1044
+ listId,
1045
+ ...listStart === void 0 ? {} : { listStart }
1046
+ };
1047
+ }
1048
+ function belongsToNestedGroup(item, minLevel, parentListType, anchorType, anchorId) {
1049
+ if ((item.level || 2) > minLevel) return true;
1050
+ if ((item.listItem || parentListType) !== anchorType) return false;
1051
+ if (anchorType !== "number") return true;
1052
+ const itemId = normalizeListId(item.listId);
1053
+ return anchorId ? itemId === anchorId : itemId === void 0;
1054
+ }
1055
+ /**
1056
+ * Type guard for text blocks
1057
+ */
1058
+ function isTextBlock(block) {
1059
+ return block._type === "block";
1060
+ }
1061
+ /**
1062
+ * Type guard for image blocks.
1063
+ * Checks both `_type` and that `asset` is a valid object — image blocks
1064
+ * without an `asset` wrapper (e.g. `{ _type: "image", url: "..." }`) are
1065
+ * malformed and should not be cast to `PortableTextImageBlock`.
1066
+ */
1067
+ function isImageBlock(block) {
1068
+ return block._type === "image" && "asset" in block && typeof block.asset === "object" && block.asset !== null;
1069
+ }
1070
+ /**
1071
+ * Type guard for gallery blocks that carry a usable `images` array.
1072
+ * Galleries without one are handled separately in `convertBlock`.
1073
+ */
1074
+ function isGalleryBlock(block) {
1075
+ return block._type === "gallery" && "images" in block && Array.isArray(block.images);
1076
+ }
1077
+ /**
1078
+ * Type guard for code blocks
1079
+ */
1080
+ function isCodeBlock(block) {
1081
+ return block._type === "code";
1082
+ }
1083
+ /**
1084
+ * Convert a single Portable Text block to ProseMirror node
1085
+ */
1086
+ function convertBlock(block, path, preserveIdentity) {
1087
+ if (isTextBlock(block)) return convertTextBlock(block, preserveIdentity);
1088
+ if (isImageBlock(block)) return convertImage(block, preserveIdentity);
1089
+ if (block._type === "image") return convertMalformedImage(block, preserveIdentity);
1090
+ if (isGalleryBlock(block)) return {
1091
+ type: "gallery",
1092
+ attrs: identityAttrs({
1093
+ images: sanitizeGalleryImages(block.images),
1094
+ columns: typeof block.columns === "number" ? block.columns : void 0
1095
+ }, block._key, preserveIdentity)
1096
+ };
1097
+ if (isCodeBlock(block)) return convertCodeBlock(block, preserveIdentity);
1098
+ if (block._type === "htmlBlock") return {
1099
+ type: "htmlBlock",
1100
+ attrs: identityAttrs({ html: block.html || "" }, block._key, preserveIdentity)
1101
+ };
1102
+ if (block._type === "break") return {
1103
+ type: "horizontalRule",
1104
+ attrs: identityAttrs(void 0, block._key, preserveIdentity)
1105
+ };
1106
+ if (block._type === "gallery") {
1107
+ if (preserveIdentity) return {
1108
+ type: PORTABLE_TEXT_BLOCK_NODE,
1109
+ attrs: { [PORTABLE_TEXT_BLOCK_ATTR]: block }
1110
+ };
1111
+ return {
1112
+ type: "paragraph",
1113
+ content: [{
1114
+ type: "text",
1115
+ text: `[Unknown block type: ${block._type}]`,
1116
+ marks: [{ type: "code" }]
1117
+ }]
1118
+ };
1119
+ }
1120
+ if (preserveIdentity) return {
1121
+ type: PORTABLE_TEXT_BLOCK_NODE,
1122
+ attrs: { [PORTABLE_TEXT_BLOCK_ATTR]: block }
1123
+ };
1124
+ if (block._type === "table") {
1125
+ const result = portableTextTableToProseMirror(block, {
1126
+ path,
1127
+ createKey: generateKey,
1128
+ spansToInline: (content, markDefs) => convertSpans(content, markDefs, preserveIdentity)
1129
+ });
1130
+ if (!result.ok) throw new UnsafePortableTextTableError(result.reason, result.raw, result.renderFallback);
1131
+ return result.node;
1132
+ }
1133
+ return {
1134
+ type: "paragraph",
1135
+ content: [{
1136
+ type: "text",
1137
+ text: `[Unknown block type: ${block._type}]`,
1138
+ marks: [{ type: "code" }]
1139
+ }]
1140
+ };
1141
+ }
1142
+ /**
1143
+ * Convert text block to ProseMirror paragraph or heading
1144
+ */
1145
+ function convertTextBlock(block, preserveIdentity) {
1146
+ const { style = "normal", children, markDefs = [] } = block;
1147
+ const content = convertSpans(children, markDefs, preserveIdentity);
1148
+ switch (style) {
1149
+ case "h1":
1150
+ case "h2":
1151
+ case "h3":
1152
+ case "h4":
1153
+ case "h5":
1154
+ case "h6": return {
1155
+ type: "heading",
1156
+ attrs: identityAttrs({
1157
+ level: parseInt(style.substring(1), 10),
1158
+ ...block.textAlign ? { textAlign: block.textAlign } : {}
1159
+ }, block._key, preserveIdentity),
1160
+ content: content.length > 0 ? content : void 0
1161
+ };
1162
+ case "blockquote": return {
1163
+ type: "blockquote",
1164
+ attrs: identityAttrs(void 0, block._key, preserveIdentity),
1165
+ content: [{
1166
+ type: "paragraph",
1167
+ content: content.length > 0 ? content : void 0
1168
+ }]
1169
+ };
1170
+ default: return {
1171
+ type: "paragraph",
1172
+ attrs: identityAttrs(block.textAlign ? { textAlign: block.textAlign } : void 0, block._key, preserveIdentity),
1173
+ content: content.length > 0 ? content : void 0
1174
+ };
1175
+ }
1176
+ }
1177
+ /**
1178
+ * Convert list items to ProseMirror list
1179
+ */
1180
+ function convertList(items, listType, context, preserveIdentity) {
1181
+ const rootItems = [];
1182
+ let i = 0;
1183
+ while (i < items.length) {
1184
+ const item = items[i];
1185
+ if ((item.level || 1) === 1) {
1186
+ const nestedItems = [];
1187
+ i++;
1188
+ while (i < items.length && (items[i].level || 1) > 1) {
1189
+ nestedItems.push(items[i]);
1190
+ i++;
1191
+ }
1192
+ rootItems.push(convertListItem(item, nestedItems, listType, `${context}:${rootItems.length}`, preserveIdentity));
1193
+ } else {
1194
+ rootItems.push(convertListItem(item, [], listType, `${context}:${rootItems.length}`, preserveIdentity));
1195
+ i++;
1196
+ }
1197
+ }
1198
+ const metadata = listType === "number" ? getListMetadata(items[0], `${context}:${items[0]._key}`) : void 0;
1199
+ return {
1200
+ type: listType === "bullet" ? "bulletList" : "orderedList",
1201
+ attrs: metadata ? {
1202
+ ...metadata,
1203
+ start: metadata.listStart ?? 1
1204
+ } : void 0,
1205
+ content: rootItems
1206
+ };
1207
+ }
1208
+ /**
1209
+ * Convert a single list item to ProseMirror
1210
+ */
1211
+ function convertListItem(item, nestedItems, parentListType, context, preserveIdentity) {
1212
+ const content = [];
1213
+ const spans = convertSpans(item.children, item.markDefs || [], preserveIdentity);
1214
+ content.push({
1215
+ type: "paragraph",
1216
+ attrs: identityAttrs(void 0, item._key, preserveIdentity),
1217
+ content: spans.length > 0 ? spans : void 0
1218
+ });
1219
+ if (nestedItems.length > 0) {
1220
+ let minLevel = Infinity;
1221
+ for (const ni of nestedItems) {
1222
+ const level = ni.level || 2;
1223
+ if (level < minLevel) minLevel = level;
1224
+ }
1225
+ let j = 0;
1226
+ while (j < nestedItems.length) {
1227
+ const anchorType = nestedItems[j].listItem || parentListType;
1228
+ const anchorId = anchorType === "number" ? normalizeListId(nestedItems[j].listId) : void 0;
1229
+ const nestedGroup = [];
1230
+ do {
1231
+ nestedGroup.push(nestedItems[j]);
1232
+ j++;
1233
+ } while (j < nestedItems.length && belongsToNestedGroup(nestedItems[j], minLevel, parentListType, anchorType, anchorId));
1234
+ if (nestedGroup.length > 0) {
1235
+ const adjustedGroup = nestedGroup.map((ni) => ({
1236
+ ...ni,
1237
+ level: (ni.level || 2) - 1
1238
+ }));
1239
+ content.push(convertList(adjustedGroup, anchorType, `${context}:nested:${j - nestedGroup.length}`, preserveIdentity));
1240
+ }
1241
+ }
1242
+ }
1243
+ return {
1244
+ type: "listItem",
1245
+ content
1246
+ };
1247
+ }
1248
+ /**
1249
+ * Convert Portable Text spans to ProseMirror text nodes
1250
+ */
1251
+ function convertSpans(spans, markDefs, preserveIdentity) {
1252
+ const nodes = [];
1253
+ const markDefsMap = new Map(markDefs.map((md) => [md._key, md]));
1254
+ for (const span of spans) {
1255
+ if (span._type !== "span") continue;
1256
+ const referencedMarkDefs = markDefs.filter((markDef) => span.marks?.includes(markDef._key));
1257
+ const parts = span.text.split("\n");
1258
+ for (let i = 0; i < parts.length; i++) {
1259
+ const text = parts[i];
1260
+ if (text.length > 0) {
1261
+ const marks = convertMarks(span.marks || [], markDefsMap);
1262
+ if (preserveIdentity) marks.push({
1263
+ type: PORTABLE_TEXT_SPAN_MARK,
1264
+ attrs: {
1265
+ key: span._key,
1266
+ markDefs: referencedMarkDefs
1267
+ }
1268
+ });
1269
+ const node = {
1270
+ type: "text",
1271
+ text
1272
+ };
1273
+ if (marks.length > 0) node.marks = marks;
1274
+ nodes.push(node);
1275
+ }
1276
+ if (i < parts.length - 1) nodes.push(preserveIdentity ? {
1277
+ type: "hardBreak",
1278
+ marks: [{
1279
+ type: PORTABLE_TEXT_SPAN_MARK,
1280
+ attrs: {
1281
+ key: span._key,
1282
+ markDefs: referencedMarkDefs
1283
+ }
1284
+ }]
1285
+ } : { type: "hardBreak" });
1286
+ }
1287
+ }
1288
+ return nodes;
1289
+ }
1290
+ /**
1291
+ * Convert Portable Text marks to ProseMirror marks
1292
+ */
1293
+ function convertMarks(marks, markDefs) {
1294
+ const pmMarks = [];
1295
+ for (const mark of marks) switch (mark) {
1296
+ case "strong":
1297
+ pmMarks.push({ type: "bold" });
1298
+ break;
1299
+ case "em":
1300
+ pmMarks.push({ type: "italic" });
1301
+ break;
1302
+ case "underline":
1303
+ pmMarks.push({ type: "underline" });
1304
+ break;
1305
+ case "strike-through":
1306
+ pmMarks.push({ type: "strike" });
1307
+ break;
1308
+ case "subscript":
1309
+ pmMarks.push({ type: "subscript" });
1310
+ break;
1311
+ case "superscript":
1312
+ pmMarks.push({ type: "superscript" });
1313
+ break;
1314
+ case "code":
1315
+ pmMarks.push({ type: "code" });
1316
+ break;
1317
+ default: {
1318
+ const markDef = markDefs.get(mark);
1319
+ if (markDef?._type === "link") pmMarks.push({
1320
+ type: "link",
1321
+ attrs: {
1322
+ href: markDef.href,
1323
+ target: markDef.blank ? "_blank" : null
1324
+ }
1325
+ });
1326
+ else throw new UnsupportedPortableTextMarksError([typeof markDef?._type === "string" ? markDef._type : mark]);
1327
+ break;
1328
+ }
1329
+ }
1330
+ return pmMarks;
1331
+ }
1332
+ function imageAlignment(value) {
1333
+ return value === "left" || value === "center" || value === "right" || value === "wide" || value === "full" ? value : void 0;
1334
+ }
1335
+ /**
1336
+ * Convert image block to ProseMirror
1337
+ */
1338
+ function convertImage(block, preserveIdentity) {
1339
+ return {
1340
+ type: "image",
1341
+ attrs: identityAttrs({
1342
+ src: block.asset.url || block.asset._ref,
1343
+ alt: block.alt || "",
1344
+ title: block.caption || "",
1345
+ mediaId: block.asset._ref,
1346
+ provider: block.asset.provider,
1347
+ width: block.width,
1348
+ height: block.height,
1349
+ displayWidth: block.displayWidth,
1350
+ displayHeight: block.displayHeight,
1351
+ alignment: imageAlignment(block.alignment)
1352
+ }, block._key, preserveIdentity)
1353
+ };
1354
+ }
1355
+ /**
1356
+ * Convert a malformed image block (missing `asset` wrapper) to ProseMirror.
1357
+ * Handles blocks like `{ _type: "image", url: "...", alt: "..." }` that may
1358
+ * originate from migrations or third-party imports.
1359
+ */
1360
+ function convertMalformedImage(block, preserveIdentity) {
1361
+ return {
1362
+ type: "image",
1363
+ attrs: identityAttrs({
1364
+ src: "url" in block && typeof block.url === "string" ? block.url : "",
1365
+ alt: "alt" in block && typeof block.alt === "string" ? block.alt : "",
1366
+ title: "caption" in block && typeof block.caption === "string" ? block.caption : "",
1367
+ mediaId: void 0,
1368
+ provider: void 0,
1369
+ width: "width" in block && typeof block.width === "number" ? block.width : void 0,
1370
+ height: "height" in block && typeof block.height === "number" ? block.height : void 0,
1371
+ displayWidth: "displayWidth" in block && typeof block.displayWidth === "number" ? block.displayWidth : void 0,
1372
+ displayHeight: "displayHeight" in block && typeof block.displayHeight === "number" ? block.displayHeight : void 0,
1373
+ alignment: imageAlignment("alignment" in block ? block.alignment : void 0)
1374
+ }, block._key, preserveIdentity)
1375
+ };
1376
+ }
1377
+ /**
1378
+ * Convert code block to ProseMirror
1379
+ */
1380
+ function convertCodeBlock(block, preserveIdentity) {
1381
+ return {
1382
+ type: "codeBlock",
1383
+ attrs: identityAttrs({ language: block.language || null }, block._key, preserveIdentity),
1384
+ content: block.code ? [{
1385
+ type: "text",
1386
+ text: block.code
1387
+ }] : void 0
1388
+ };
1389
+ }
1390
+
1391
+ //#endregion
1392
+ //#region src/plugins/define-plugin.ts
1393
+ /**
1394
+ * definePlugin() Helper
1395
+ *
1396
+ * Native plugin authoring entry. Returns a fully-resolved
1397
+ * `ResolvedPlugin` ready for the host integration to mount.
1398
+ *
1399
+ * Sandboxed plugins do NOT use this function. They default-export
1400
+ * a bare `{ hooks?, routes? }` object with a `satisfies SandboxedPlugin`
1401
+ * annotation from `emdash/plugin`. See the `emdash` changeset for the
1402
+ * authoring shape.
1403
+ */
1404
+ const MCP_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
1405
+ /**
1406
+ * Define a native EmDash plugin.
1407
+ *
1408
+ * Native plugins ship as regular npm modules, get installed via
1409
+ * `pnpm add` + an `astro.config.mjs` edit, and run in the host
1410
+ * process. They have full access to the runtime — capabilities are
1411
+ * still enforced by `PluginContextFactory`, but there is no isolation
1412
+ * boundary.
1413
+ *
1414
+ * @example
1415
+ * ```typescript
1416
+ * import { definePlugin } from "emdash";
1417
+ *
1418
+ * export default definePlugin({
1419
+ * id: "my-plugin",
1420
+ * version: "1.0.0",
1421
+ * capabilities: ["content:read"],
1422
+ * hooks: {
1423
+ * "content:beforeSave": async (event, ctx) => {
1424
+ * ctx.log.info("Saving content", { collection: event.collection });
1425
+ * return event.content;
1426
+ * }
1427
+ * },
1428
+ * routes: {
1429
+ * "sync": {
1430
+ * handler: async (ctx) => {
1431
+ * return { status: "ok" };
1432
+ * }
1433
+ * }
1434
+ * }
1435
+ * });
1436
+ * ```
1437
+ *
1438
+ * Sandboxed-format plugins do not use `definePlugin`. They
1439
+ * default-export a bare `{ hooks?, routes? }` object with a
1440
+ * `satisfies SandboxedPlugin` annotation from `emdash/plugin`. Calling
1441
+ * `definePlugin` with an object that has no `id` throws at runtime
1442
+ * (the type system already rejects it at compile time — this check is
1443
+ * for callers that bypass typechecking).
1444
+ */
1445
+ function definePlugin(definition) {
1446
+ if (typeof definition.id !== "string" || definition.id.length === 0) throw new Error(`definePlugin() requires \`id\` (got ${typeof definition.id}). For native plugins, make sure your definition has both \`id\` and \`version\`. For sandboxed plugins, drop \`definePlugin()\` entirely and \`export default { hooks, routes } satisfies SandboxedPlugin\` from "emdash/plugin" — identity comes from \`emdash-plugin.jsonc\`.`);
1447
+ return defineNativePlugin(definition);
1448
+ }
1449
+ function definePluginRoute(route) {
1450
+ return route;
1451
+ }
1452
+ /**
1453
+ * Internal: define a native-format plugin with full validation and normalization.
1454
+ */
1455
+ function defineNativePlugin(definition) {
1456
+ const SIMPLE_ID = /^[a-z0-9-]+$/;
1457
+ const SCOPED_ID = /^@[a-z0-9-]+\/[a-z0-9-]+$/;
1458
+ const SEMVER_PATTERN = /^\d+\.\d+\.\d+/;
1459
+ const { id, version, capabilities = [], allowedHosts = [], hooks = {}, routes = {}, mcp = { tools: {} }, admin = {} } = definition;
1460
+ const storage = definition.storage ?? {};
1461
+ if (!SIMPLE_ID.test(id) && !SCOPED_ID.test(id)) throw new Error(`Invalid plugin id "${id}". Must be lowercase alphanumeric with dashes (e.g., "my-plugin" or "@scope/my-plugin").`);
1462
+ if (!SEMVER_PATTERN.test(version)) throw new Error(`Invalid plugin version "${version}". Must be semver format (e.g., "1.0.0").`);
1463
+ for (const [name, tool] of Object.entries(mcp.tools)) {
1464
+ if (!MCP_TOOL_NAME_PATTERN.test(name)) throw new Error(`Invalid MCP tool name "${name}" in plugin "${id}".`);
1465
+ const route = routes[tool.route];
1466
+ if (!route) throw new Error(`MCP tool "${name}" references unknown route "${tool.route}".`);
1467
+ if (route.public) throw new Error(`MCP tool "${name}" cannot reference a public route.`);
1468
+ if (route.response === "raw") throw new Error(`MCP tool "${name}" cannot reference a raw response route.`);
1469
+ if (!isJsonPostRouteContract(route)) throw new Error(`MCP tool "${name}" must reference a POST-compatible JSON route.`);
1470
+ if (!route.permission) throw new Error(`MCP route "${tool.route}" must declare a permission.`);
1471
+ }
1472
+ for (const [kind, extensions] of [["editor panel", admin.editorPanels], ["editor action", admin.editorActions]]) for (const extension of extensions ?? []) {
1473
+ const route = routes[extension.route];
1474
+ if (!route) throw new Error(`Plugin ${kind} "${extension.id}" references unknown route "${extension.route}".`);
1475
+ if (route.public) throw new Error(`Plugin ${kind} "${extension.id}" must reference a private route.`);
1476
+ if (!isJsonPostRouteContract(route)) throw new Error(`Plugin ${kind} "${extension.id}" must reference a route that accepts POST JSON requests and returns JSON.`);
1477
+ }
1478
+ if ((admin.pages?.length ?? 0) > 0 || (admin.widgets?.length ?? 0) > 0) {
1479
+ const adminRoute = routes.admin;
1480
+ if (adminRoute && (adminRoute.public === true || !isJsonPostRouteContract(adminRoute))) throw new Error("Block Kit admin route must accept POST JSON requests and return JSON.");
1481
+ }
1482
+ const validCapabilities = new Set(PLUGIN_CAPABILITIES);
1483
+ for (const cap of capabilities) if (!validCapabilities.has(cap)) throw new Error(`Invalid capability "${cap}" in plugin "${id}".`);
1484
+ return {
1485
+ id,
1486
+ version,
1487
+ capabilities: normalizePluginCapabilities(capabilities),
1488
+ allowedHosts,
1489
+ storage,
1490
+ hooks: resolveHooks(hooks, id),
1491
+ routes,
1492
+ mcp,
1493
+ admin
1494
+ };
1495
+ }
1496
+ /**
1497
+ * Resolve hooks to normalized format with defaults.
1498
+ *
1499
+ * PluginHooks and ResolvedPluginHooks share the same keys — each input value is
1500
+ * `HookConfig<H> | H` and the output is `ResolvedHook<H>`. TS can't narrow
1501
+ * the handler type through a dynamic key, so we assert at the loop boundary.
1502
+ */
1503
+ function resolveHooks(hooks, pluginId) {
1504
+ const resolved = {};
1505
+ for (const key of Object.keys(hooks)) {
1506
+ const hook = hooks[key];
1507
+ if (hook) resolved[key] = resolveHook(hook, pluginId);
1508
+ }
1509
+ return resolved;
1510
+ }
1511
+ /**
1512
+ * Check if a hook value is a config object (has a `handler` property)
1513
+ */
1514
+ function isHookConfig(hook) {
1515
+ return typeof hook === "object" && hook !== null && "handler" in hook;
1516
+ }
1517
+ /**
1518
+ * Resolve a single hook to normalized format
1519
+ */
1520
+ function resolveHook(hook, pluginId) {
1521
+ if (isHookConfig(hook)) {
1522
+ if (hook.exclusive !== void 0 && typeof hook.exclusive !== "boolean") throw new Error(`Invalid "exclusive" value in hook config for plugin "${pluginId}". Must be boolean.`);
1523
+ return {
1524
+ priority: hook.priority ?? 100,
1525
+ timeout: hook.timeout ?? 5e3,
1526
+ dependencies: hook.dependencies ?? [],
1527
+ errorPolicy: hook.errorPolicy ?? "abort",
1528
+ exclusive: hook.exclusive ?? false,
1529
+ handler: hook.handler,
1530
+ pluginId
1531
+ };
1532
+ }
1533
+ return {
1534
+ priority: 100,
1535
+ timeout: 5e3,
1536
+ dependencies: [],
1537
+ errorPolicy: "abort",
1538
+ exclusive: false,
1539
+ handler: hook,
1540
+ pluginId
1541
+ };
1542
+ }
1543
+
1544
+ //#endregion
1545
+ //#region src/plugins/hooks.ts
1546
+ /**
1547
+ * Plugin Hooks System v2
1548
+ *
1549
+ * Uses the unified PluginContext for all hooks.
1550
+ * Manages lifecycle hooks with:
1551
+ * - Deterministic ordering via priority + dependencies
1552
+ * - Timeout enforcement
1553
+ * - Error isolation
1554
+ * - Observability
1555
+ *
1556
+ */
1557
+ const CONTENT_SAVE_HOOK_CONTEXT_KEY = Symbol.for("emdash:content-save-hook-context");
1558
+ const contentSaveHookContext = globalThis[CONTENT_SAVE_HOOK_CONTEXT_KEY] ?? new AsyncLocalStorage();
1559
+ globalThis[CONTENT_SAVE_HOOK_CONTEXT_KEY] = contentSaveHookContext;
1560
+ function getActiveContentSaveHookName() {
1561
+ return contentSaveHookContext.getStore();
1562
+ }
1563
+ /**
1564
+ * Hook pipeline for executing hooks in order
1565
+ */
1566
+ var HookPipeline = class HookPipeline {
1567
+ hooks = /* @__PURE__ */ new Map();
1568
+ pluginMap = /* @__PURE__ */ new Map();
1569
+ contextFactory = null;
1570
+ /** Stored so setContextFactory can merge incrementally. */
1571
+ contextFactoryOptions = {};
1572
+ /** Hook names where at least one handler declared exclusive: true */
1573
+ exclusiveHookNames = /* @__PURE__ */ new Set();
1574
+ /**
1575
+ * Selected provider plugin ID for each exclusive hook.
1576
+ * Set by the PluginManager after resolution.
1577
+ */
1578
+ exclusiveSelections = /* @__PURE__ */ new Map();
1579
+ constructor(plugins, factoryOptions) {
1580
+ if (factoryOptions) {
1581
+ this.contextFactory = new PluginContextFactory(factoryOptions);
1582
+ this.contextFactoryOptions = { ...factoryOptions };
1583
+ }
1584
+ for (const plugin of plugins) this.pluginMap.set(plugin.id, plugin);
1585
+ this.registerPlugins(plugins);
1586
+ }
1587
+ /**
1588
+ * Set or update the context factory options.
1589
+ *
1590
+ * When called on a pipeline that already has a factory, the new options
1591
+ * are merged on top of the existing ones so that callers don't need to
1592
+ * repeat every field (e.g. adding `cronReschedule` without losing
1593
+ * `storage` / `getUploadUrl`).
1594
+ */
1595
+ setContextFactory(options) {
1596
+ const merged = {
1597
+ ...this.contextFactoryOptions,
1598
+ ...options
1599
+ };
1600
+ this.contextFactory = new PluginContextFactory(merged);
1601
+ this.contextFactoryOptions = merged;
1602
+ }
1603
+ /**
1604
+ * Get context for a plugin
1605
+ */
1606
+ getContext(pluginId) {
1607
+ const plugin = this.pluginMap.get(pluginId);
1608
+ if (!plugin) throw new Error(`Plugin "${pluginId}" not found`);
1609
+ if (!this.contextFactory) throw new Error("Context factory not initialized - call setContextFactory first");
1610
+ return this.contextFactory.createContext(plugin);
1611
+ }
1612
+ /**
1613
+ * Get typed hooks for a specific hook name.
1614
+ * The internal map stores ResolvedHook<unknown>, but we know each name
1615
+ * maps to a specific handler type via HookHandlerMap.
1616
+ *
1617
+ * Exclusive hooks that have a selected provider are filtered out — they
1618
+ * should only run via invokeExclusiveHook(), not in the regular pipeline.
1619
+ */
1620
+ getTypedHooks(name) {
1621
+ const all = this.hooks.get(name) ?? [];
1622
+ if (this.exclusiveSelections.has(name)) return all.filter((h) => !h.exclusive);
1623
+ return all;
1624
+ }
1625
+ /**
1626
+ * Register all hooks from plugins.
1627
+ *
1628
+ * Registers each hook name individually to preserve type safety. The
1629
+ * internal map stores ResolvedHook<unknown> since it's keyed by string,
1630
+ * but getTypedHooks() restores the correct handler type on retrieval.
1631
+ */
1632
+ registerPlugins(plugins) {
1633
+ for (const plugin of plugins) {
1634
+ this.registerPluginHook(plugin, "plugin:install");
1635
+ this.registerPluginHook(plugin, "plugin:activate");
1636
+ this.registerPluginHook(plugin, "plugin:deactivate");
1637
+ this.registerPluginHook(plugin, "plugin:uninstall");
1638
+ this.registerPluginHook(plugin, "content:beforeSave");
1639
+ this.registerPluginHook(plugin, "content:afterSave");
1640
+ this.registerPluginHook(plugin, "content:beforeDelete");
1641
+ this.registerPluginHook(plugin, "content:afterDelete");
1642
+ this.registerPluginHook(plugin, "content:beforePublish");
1643
+ this.registerPluginHook(plugin, "content:beforeSchedule");
1644
+ this.registerPluginHook(plugin, "content:beforeUnpublish");
1645
+ this.registerPluginHook(plugin, "content:afterPublish");
1646
+ this.registerPluginHook(plugin, "content:afterUnpublish");
1647
+ this.registerPluginHook(plugin, "content:afterRestore");
1648
+ this.registerPluginHook(plugin, "content:afterSchedule");
1649
+ this.registerPluginHook(plugin, "content:afterUnschedule");
1650
+ this.registerPluginHook(plugin, "media:beforeUpload");
1651
+ this.registerPluginHook(plugin, "media:afterUpload");
1652
+ this.registerPluginHook(plugin, "cron");
1653
+ this.registerPluginHook(plugin, "email:beforeSend");
1654
+ this.registerPluginHook(plugin, "email:deliver");
1655
+ this.registerPluginHook(plugin, "email:afterSend");
1656
+ this.registerPluginHook(plugin, "comment:beforeCreate");
1657
+ this.registerPluginHook(plugin, "comment:moderate");
1658
+ this.registerPluginHook(plugin, "comment:afterCreate");
1659
+ this.registerPluginHook(plugin, "comment:afterModerate");
1660
+ this.registerPluginHook(plugin, "page:metadata");
1661
+ this.registerPluginHook(plugin, "page:fragments");
1662
+ }
1663
+ for (const [hookName, hooks] of this.hooks) this.hooks.set(hookName, this.sortHooks(hooks));
1664
+ }
1665
+ /**
1666
+ * Maps hook names to the capability required to register them.
1667
+ *
1668
+ * Hooks not listed here have no capability requirement (e.g. lifecycle
1669
+ * hooks, cron). Any plugin declaring a listed hook without the required
1670
+ * capability will have that hook silently skipped at registration time.
1671
+ */
1672
+ static HOOK_REQUIRED_CAPABILITY = new Map([
1673
+ ["email:beforeSend", "hooks.email-events:register"],
1674
+ ["email:afterSend", "hooks.email-events:register"],
1675
+ ["email:deliver", "hooks.email-transport:register"],
1676
+ ["content:beforeSave", "content:write"],
1677
+ ["content:afterSave", "content:read"],
1678
+ ["content:beforeDelete", "content:read"],
1679
+ ["content:afterDelete", "content:read"],
1680
+ ["content:beforePublish", "hooks.content-policy:register"],
1681
+ ["content:beforeSchedule", "hooks.content-policy:register"],
1682
+ ["content:beforeUnpublish", "hooks.content-policy:register"],
1683
+ ["content:afterPublish", "content:read"],
1684
+ ["content:afterUnpublish", "content:read"],
1685
+ ["content:afterRestore", "content:read"],
1686
+ ["content:afterSchedule", "content:read"],
1687
+ ["content:afterUnschedule", "content:read"],
1688
+ ["media:beforeUpload", "media:write"],
1689
+ ["media:afterUpload", "media:read"],
1690
+ ["comment:beforeCreate", "users:read"],
1691
+ ["comment:moderate", "users:read"],
1692
+ ["comment:afterCreate", "users:read"],
1693
+ ["comment:afterModerate", "users:read"],
1694
+ ["page:fragments", "hooks.page-fragments:register"]
1695
+ ]);
1696
+ /**
1697
+ * Register a single plugin's hook by name
1698
+ */
1699
+ registerPluginHook(plugin, name) {
1700
+ const hook = plugin.hooks[name];
1701
+ if (!hook) return;
1702
+ const requiredCapability = HookPipeline.HOOK_REQUIRED_CAPABILITY.get(name);
1703
+ if (requiredCapability && !plugin.capabilities.includes(requiredCapability)) {
1704
+ console.warn(`[hooks] Plugin "${plugin.id}" declares ${name} hook without ${requiredCapability} capability — skipping`);
1705
+ return;
1706
+ }
1707
+ if (hook.exclusive) this.exclusiveHookNames.add(name);
1708
+ this.registerHook(name, hook);
1709
+ }
1710
+ /**
1711
+ * Register a single hook
1712
+ */
1713
+ registerHook(name, hook) {
1714
+ const existing = this.hooks.get(name) || [];
1715
+ existing.push(hook);
1716
+ this.hooks.set(name, existing);
1717
+ }
1718
+ /**
1719
+ * Sort hooks by priority and dependencies
1720
+ */
1721
+ sortHooks(hooks) {
1722
+ const sorted = [];
1723
+ const remaining = [...hooks];
1724
+ while (remaining.length > 0) {
1725
+ const ready = remaining.filter((hook) => hook.dependencies.every((dep) => sorted.some((s) => s.pluginId === dep)));
1726
+ if (ready.length === 0) {
1727
+ const pluginIds = remaining.map((h) => h.pluginId).join(", ");
1728
+ console.warn(`[hooks] Hook dependency cycle or missing dependency detected among plugins: ${pluginIds}. Falling back to priority order.`);
1729
+ remaining.sort((a, b) => a.priority - b.priority);
1730
+ sorted.push(...remaining);
1731
+ break;
1732
+ }
1733
+ ready.sort((a, b) => a.priority - b.priority);
1734
+ const next = ready[0];
1735
+ sorted.push(next);
1736
+ remaining.splice(remaining.indexOf(next), 1);
1737
+ }
1738
+ return sorted;
1739
+ }
1740
+ /**
1741
+ * Execute a hook with timeout
1742
+ */
1743
+ async executeWithTimeout(fn, timeout) {
1744
+ let timer;
1745
+ const timeoutPromise = new Promise((_, reject) => timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Hook timeout after ${timeout}ms`)), timeout));
1746
+ try {
1747
+ return await Promise.race([fn(), timeoutPromise]);
1748
+ } finally {
1749
+ clearTimeout(timer);
1750
+ }
1751
+ }
1752
+ /**
1753
+ * Run plugin:install hooks
1754
+ */
1755
+ async runPluginInstall(pluginId) {
1756
+ return this.runLifecycleHook("plugin:install", pluginId);
1757
+ }
1758
+ /**
1759
+ * Run plugin:activate hooks
1760
+ */
1761
+ async runPluginActivate(pluginId) {
1762
+ return this.runLifecycleHook("plugin:activate", pluginId);
1763
+ }
1764
+ /**
1765
+ * Run plugin:deactivate hooks
1766
+ */
1767
+ async runPluginDeactivate(pluginId) {
1768
+ return this.runLifecycleHook("plugin:deactivate", pluginId);
1769
+ }
1770
+ /**
1771
+ * Run plugin:uninstall hooks
1772
+ */
1773
+ async runPluginUninstall(pluginId, deleteData) {
1774
+ const hooks = this.getTypedHooks("plugin:uninstall");
1775
+ const results = [];
1776
+ const hook = hooks.find((h) => h.pluginId === pluginId);
1777
+ if (!hook) return results;
1778
+ const { handler } = hook;
1779
+ const event = { deleteData };
1780
+ const ctx = this.getContext(pluginId);
1781
+ const start = Date.now();
1782
+ try {
1783
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1784
+ results.push({
1785
+ success: true,
1786
+ pluginId: hook.pluginId,
1787
+ duration: Date.now() - start
1788
+ });
1789
+ } catch (error) {
1790
+ results.push({
1791
+ success: false,
1792
+ error: error instanceof Error ? error : new Error(String(error)),
1793
+ pluginId: hook.pluginId,
1794
+ duration: Date.now() - start
1795
+ });
1796
+ }
1797
+ return results;
1798
+ }
1799
+ async runLifecycleHook(hookName, pluginId) {
1800
+ const hooks = this.getTypedHooks(hookName);
1801
+ const results = [];
1802
+ const hook = hooks.find((h) => h.pluginId === pluginId);
1803
+ if (!hook) return results;
1804
+ const { handler } = hook;
1805
+ const event = {};
1806
+ const ctx = this.getContext(pluginId);
1807
+ const start = Date.now();
1808
+ try {
1809
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1810
+ results.push({
1811
+ success: true,
1812
+ pluginId: hook.pluginId,
1813
+ duration: Date.now() - start
1814
+ });
1815
+ } catch (error) {
1816
+ results.push({
1817
+ success: false,
1818
+ error: error instanceof Error ? error : new Error(String(error)),
1819
+ pluginId: hook.pluginId,
1820
+ duration: Date.now() - start
1821
+ });
1822
+ }
1823
+ return results;
1824
+ }
1825
+ /**
1826
+ * Run content:beforeSave hooks
1827
+ * Returns modified content from the pipeline. `id` is the existing item's
1828
+ * ID when updating. `actor` is the authenticated user that triggered the
1829
+ * save, when one is available.
1830
+ */
1831
+ async runContentBeforeSave(content, collection, isNew, id, actor) {
1832
+ const hooks = this.getTypedHooks("content:beforeSave");
1833
+ const results = [];
1834
+ let currentContent = content;
1835
+ for (const hook of hooks) {
1836
+ const { handler } = hook;
1837
+ const event = {
1838
+ content: currentContent,
1839
+ collection,
1840
+ isNew
1841
+ };
1842
+ if (id !== void 0) event.id = id;
1843
+ if (actor !== void 0) event.actor = { ...actor };
1844
+ const ctx = this.getContext(hook.pluginId);
1845
+ const start = Date.now();
1846
+ try {
1847
+ const result = await contentSaveHookContext.run("content:beforeSave", () => this.executeWithTimeout(() => handler(event, ctx), hook.timeout));
1848
+ if (result !== void 0) currentContent = result;
1849
+ results.push({
1850
+ success: true,
1851
+ value: currentContent,
1852
+ pluginId: hook.pluginId,
1853
+ duration: Date.now() - start
1854
+ });
1855
+ } catch (error) {
1856
+ results.push({
1857
+ success: false,
1858
+ error: error instanceof Error ? error : new Error(String(error)),
1859
+ pluginId: hook.pluginId,
1860
+ duration: Date.now() - start
1861
+ });
1862
+ if (hook.errorPolicy === "abort") throw error;
1863
+ }
1864
+ }
1865
+ return {
1866
+ content: currentContent,
1867
+ results
1868
+ };
1869
+ }
1870
+ /**
1871
+ * Run content:afterSave hooks
1872
+ */
1873
+ async runContentAfterSave(content, collection, isNew, actor, excludePluginId) {
1874
+ const hooks = this.getTypedHooks("content:afterSave");
1875
+ const results = [];
1876
+ for (const hook of hooks) {
1877
+ if (hook.pluginId === excludePluginId) continue;
1878
+ const { handler } = hook;
1879
+ const event = {
1880
+ content,
1881
+ collection,
1882
+ isNew
1883
+ };
1884
+ if (actor !== void 0) event.actor = { ...actor };
1885
+ const ctx = this.getContext(hook.pluginId);
1886
+ const start = Date.now();
1887
+ try {
1888
+ await contentSaveHookContext.run("content:afterSave", () => this.executeWithTimeout(() => handler(event, ctx), hook.timeout));
1889
+ results.push({
1890
+ success: true,
1891
+ pluginId: hook.pluginId,
1892
+ duration: Date.now() - start
1893
+ });
1894
+ } catch (error) {
1895
+ results.push({
1896
+ success: false,
1897
+ error: error instanceof Error ? error : new Error(String(error)),
1898
+ pluginId: hook.pluginId,
1899
+ duration: Date.now() - start
1900
+ });
1901
+ if (hook.errorPolicy === "abort") throw error;
1902
+ }
1903
+ }
1904
+ return results;
1905
+ }
1906
+ /**
1907
+ * Run content:beforeDelete hooks
1908
+ * Returns whether deletion is allowed
1909
+ */
1910
+ async runContentBeforeDelete(id, collection) {
1911
+ const hooks = this.getTypedHooks("content:beforeDelete");
1912
+ const results = [];
1913
+ let allowed = true;
1914
+ for (const hook of hooks) {
1915
+ const { handler } = hook;
1916
+ const event = {
1917
+ id,
1918
+ collection,
1919
+ permanent: false
1920
+ };
1921
+ const ctx = this.getContext(hook.pluginId);
1922
+ const start = Date.now();
1923
+ try {
1924
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1925
+ if (result === false) allowed = false;
1926
+ results.push({
1927
+ success: true,
1928
+ value: result !== false,
1929
+ pluginId: hook.pluginId,
1930
+ duration: Date.now() - start
1931
+ });
1932
+ } catch (error) {
1933
+ results.push({
1934
+ success: false,
1935
+ error: error instanceof Error ? error : new Error(String(error)),
1936
+ pluginId: hook.pluginId,
1937
+ duration: Date.now() - start
1938
+ });
1939
+ if (hook.errorPolicy === "abort") throw error;
1940
+ }
1941
+ }
1942
+ return {
1943
+ allowed,
1944
+ results
1945
+ };
1946
+ }
1947
+ /**
1948
+ * Run content:afterDelete hooks
1949
+ */
1950
+ async runContentAfterDelete(id, collection, permanent) {
1951
+ const hooks = this.getTypedHooks("content:afterDelete");
1952
+ const results = [];
1953
+ for (const hook of hooks) {
1954
+ const { handler } = hook;
1955
+ const event = {
1956
+ id,
1957
+ collection,
1958
+ permanent
1959
+ };
1960
+ const ctx = this.getContext(hook.pluginId);
1961
+ const start = Date.now();
1962
+ try {
1963
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1964
+ results.push({
1965
+ success: true,
1966
+ pluginId: hook.pluginId,
1967
+ duration: Date.now() - start
1968
+ });
1969
+ } catch (error) {
1970
+ results.push({
1971
+ success: false,
1972
+ error: error instanceof Error ? error : new Error(String(error)),
1973
+ pluginId: hook.pluginId,
1974
+ duration: Date.now() - start
1975
+ });
1976
+ if (hook.errorPolicy === "abort") throw error;
1977
+ }
1978
+ }
1979
+ return results;
1980
+ }
1981
+ async runContentPolicy(name, event) {
1982
+ if (name === "content:beforeSchedule") {
1983
+ if (!("scheduledAt" in event)) throw new Error("content:beforeSchedule requires scheduledAt");
1984
+ return this.runContentPolicyHooks(name, this.getTypedHooks(name), event);
1985
+ }
1986
+ return this.runContentPolicyHooks(name, this.getTypedHooks(name), event);
1987
+ }
1988
+ async runContentPolicyHooks(name, hooks, event) {
1989
+ const results = [];
1990
+ for (const hook of hooks) {
1991
+ const ctx = this.getContext(hook.pluginId);
1992
+ const start = Date.now();
1993
+ try {
1994
+ const decision = inspectContentPolicyDecision(await this.executeWithTimeout(() => hook.handler(event, ctx), hook.timeout));
1995
+ if (decision.kind === "invalid") throw new Error(`Plugin "${hook.pluginId}" returned an invalid ${name} decision`);
1996
+ results.push({
1997
+ success: true,
1998
+ pluginId: hook.pluginId,
1999
+ duration: Date.now() - start
2000
+ });
2001
+ if (decision.kind === "cancel") return {
2002
+ cancellation: {
2003
+ pluginId: hook.pluginId,
2004
+ reason: decision.reason
2005
+ },
2006
+ results
2007
+ };
2008
+ } catch (error) {
2009
+ results.push({
2010
+ success: false,
2011
+ error: error instanceof Error ? error : new Error(String(error)),
2012
+ pluginId: hook.pluginId,
2013
+ duration: Date.now() - start
2014
+ });
2015
+ if (hook.errorPolicy === "abort") throw error;
2016
+ console.error(`[content-policy] Plugin "${hook.pluginId}" failed ${name}; continuing by policy`);
2017
+ }
2018
+ }
2019
+ return { results };
2020
+ }
2021
+ /**
2022
+ * Run content state-change hooks that all share the same event shape.
2023
+ */
2024
+ async runContentStateChangeHook(name, content, collection) {
2025
+ const hooks = this.getTypedHooks(name);
2026
+ const results = [];
2027
+ for (const hook of hooks) {
2028
+ const { handler } = hook;
2029
+ const event = {
2030
+ content,
2031
+ collection
2032
+ };
2033
+ const ctx = this.getContext(hook.pluginId);
2034
+ const start = Date.now();
2035
+ try {
2036
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2037
+ results.push({
2038
+ success: true,
2039
+ pluginId: hook.pluginId,
2040
+ duration: Date.now() - start
2041
+ });
2042
+ } catch (error) {
2043
+ results.push({
2044
+ success: false,
2045
+ error: error instanceof Error ? error : new Error(String(error)),
2046
+ pluginId: hook.pluginId,
2047
+ duration: Date.now() - start
2048
+ });
2049
+ if (hook.errorPolicy === "abort") throw error;
2050
+ }
2051
+ }
2052
+ return results;
2053
+ }
2054
+ /**
2055
+ * Run content:afterPublish hooks (fire-and-forget).
2056
+ */
2057
+ async runContentAfterPublish(content, collection) {
2058
+ return this.runContentStateChangeHook("content:afterPublish", content, collection);
2059
+ }
2060
+ /**
2061
+ * Run content:afterUnpublish hooks (fire-and-forget).
2062
+ */
2063
+ async runContentAfterUnpublish(content, collection) {
2064
+ return this.runContentStateChangeHook("content:afterUnpublish", content, collection);
2065
+ }
2066
+ /**
2067
+ * Run content:afterRestore hooks (fire-and-forget).
2068
+ */
2069
+ async runContentAfterRestore(content, collection) {
2070
+ return this.runContentStateChangeHook("content:afterRestore", content, collection);
2071
+ }
2072
+ /**
2073
+ * Run content:afterSchedule hooks (fire-and-forget).
2074
+ */
2075
+ async runContentAfterSchedule(content, collection) {
2076
+ return this.runContentStateChangeHook("content:afterSchedule", content, collection);
2077
+ }
2078
+ /**
2079
+ * Run content:afterUnschedule hooks (fire-and-forget).
2080
+ */
2081
+ async runContentAfterUnschedule(content, collection) {
2082
+ return this.runContentStateChangeHook("content:afterUnschedule", content, collection);
2083
+ }
2084
+ /**
2085
+ * Run media:beforeUpload hooks
2086
+ */
2087
+ async runMediaBeforeUpload(file) {
2088
+ const hooks = this.getTypedHooks("media:beforeUpload");
2089
+ const results = [];
2090
+ let currentFile = file;
2091
+ for (const hook of hooks) {
2092
+ const { handler } = hook;
2093
+ const event = { file: currentFile };
2094
+ const ctx = this.getContext(hook.pluginId);
2095
+ const start = Date.now();
2096
+ try {
2097
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2098
+ if (result !== void 0) currentFile = result;
2099
+ results.push({
2100
+ success: true,
2101
+ value: currentFile,
2102
+ pluginId: hook.pluginId,
2103
+ duration: Date.now() - start
2104
+ });
2105
+ } catch (error) {
2106
+ results.push({
2107
+ success: false,
2108
+ error: error instanceof Error ? error : new Error(String(error)),
2109
+ pluginId: hook.pluginId,
2110
+ duration: Date.now() - start
2111
+ });
2112
+ if (hook.errorPolicy === "abort") throw error;
2113
+ }
2114
+ }
2115
+ return {
2116
+ file: currentFile,
2117
+ results
2118
+ };
2119
+ }
2120
+ /**
2121
+ * Run media:afterUpload hooks
2122
+ */
2123
+ async runMediaAfterUpload(media) {
2124
+ const hooks = this.getTypedHooks("media:afterUpload");
2125
+ const results = [];
2126
+ for (const hook of hooks) {
2127
+ const { handler } = hook;
2128
+ const event = { media };
2129
+ const ctx = this.getContext(hook.pluginId);
2130
+ const start = Date.now();
2131
+ try {
2132
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2133
+ results.push({
2134
+ success: true,
2135
+ pluginId: hook.pluginId,
2136
+ duration: Date.now() - start
2137
+ });
2138
+ } catch (error) {
2139
+ results.push({
2140
+ success: false,
2141
+ error: error instanceof Error ? error : new Error(String(error)),
2142
+ pluginId: hook.pluginId,
2143
+ duration: Date.now() - start
2144
+ });
2145
+ if (hook.errorPolicy === "abort") throw error;
2146
+ }
2147
+ }
2148
+ return results;
2149
+ }
2150
+ /**
2151
+ * Invoke the cron hook for a specific plugin.
2152
+ *
2153
+ * Unlike other hooks which broadcast to all plugins, the cron hook is
2154
+ * dispatched only to the target plugin — the one that owns the task.
2155
+ */
2156
+ async invokeCronHook(pluginId, event) {
2157
+ const hook = this.getTypedHooks("cron").find((h) => h.pluginId === pluginId);
2158
+ if (!hook) return {
2159
+ success: false,
2160
+ error: /* @__PURE__ */ new Error(`Plugin "${pluginId}" has no cron hook registered`),
2161
+ pluginId,
2162
+ duration: 0
2163
+ };
2164
+ const { handler } = hook;
2165
+ const ctx = this.getContext(pluginId);
2166
+ const start = Date.now();
2167
+ try {
2168
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2169
+ return {
2170
+ success: true,
2171
+ pluginId,
2172
+ duration: Date.now() - start
2173
+ };
2174
+ } catch (error) {
2175
+ return {
2176
+ success: false,
2177
+ error: error instanceof Error ? error : new Error(String(error)),
2178
+ pluginId,
2179
+ duration: Date.now() - start
2180
+ };
2181
+ }
2182
+ }
2183
+ /**
2184
+ * Run email:beforeSend hooks (middleware pipeline).
2185
+ *
2186
+ * Each handler receives the message and returns a modified message or
2187
+ * `false` to cancel delivery. The pipeline chains message transformations —
2188
+ * each handler receives the output of the previous one.
2189
+ */
2190
+ async runEmailBeforeSend(message, source) {
2191
+ const hooks = this.getTypedHooks("email:beforeSend");
2192
+ const results = [];
2193
+ let currentMessage = message;
2194
+ for (const hook of hooks) {
2195
+ const { handler } = hook;
2196
+ const event = {
2197
+ message: { ...currentMessage },
2198
+ source
2199
+ };
2200
+ const ctx = this.getContext(hook.pluginId);
2201
+ const start = Date.now();
2202
+ try {
2203
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2204
+ if (result === false) {
2205
+ results.push({
2206
+ success: true,
2207
+ value: false,
2208
+ pluginId: hook.pluginId,
2209
+ duration: Date.now() - start
2210
+ });
2211
+ return {
2212
+ message: false,
2213
+ results
2214
+ };
2215
+ }
2216
+ if (result && typeof result === "object") currentMessage = result;
2217
+ results.push({
2218
+ success: true,
2219
+ value: currentMessage,
2220
+ pluginId: hook.pluginId,
2221
+ duration: Date.now() - start
2222
+ });
2223
+ } catch (error) {
2224
+ results.push({
2225
+ success: false,
2226
+ error: error instanceof Error ? error : new Error(String(error)),
2227
+ pluginId: hook.pluginId,
2228
+ duration: Date.now() - start
2229
+ });
2230
+ if (hook.errorPolicy === "abort") throw error;
2231
+ }
2232
+ }
2233
+ return {
2234
+ message: currentMessage,
2235
+ results
2236
+ };
2237
+ }
2238
+ /**
2239
+ * Run email:afterSend hooks (fire-and-forget).
2240
+ *
2241
+ * Errors are logged but don't propagate — they don't affect the caller.
2242
+ */
2243
+ async runEmailAfterSend(message, source) {
2244
+ const hooks = this.getTypedHooks("email:afterSend");
2245
+ const results = [];
2246
+ for (const hook of hooks) {
2247
+ const { handler } = hook;
2248
+ const event = {
2249
+ message,
2250
+ source
2251
+ };
2252
+ const ctx = this.getContext(hook.pluginId);
2253
+ const start = Date.now();
2254
+ try {
2255
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2256
+ results.push({
2257
+ success: true,
2258
+ pluginId: hook.pluginId,
2259
+ duration: Date.now() - start
2260
+ });
2261
+ } catch (error) {
2262
+ console.error(`[email:afterSend] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
2263
+ results.push({
2264
+ success: false,
2265
+ error: error instanceof Error ? error : new Error(String(error)),
2266
+ pluginId: hook.pluginId,
2267
+ duration: Date.now() - start
2268
+ });
2269
+ }
2270
+ }
2271
+ return results;
2272
+ }
2273
+ /**
2274
+ * Run comment:beforeCreate hooks (middleware pipeline).
2275
+ *
2276
+ * Each handler receives the event and returns a modified event or
2277
+ * `false` to reject the comment. The pipeline chains transformations —
2278
+ * each handler receives the output of the previous one.
2279
+ */
2280
+ async runCommentBeforeCreate(event) {
2281
+ const hooks = this.getTypedHooks("comment:beforeCreate");
2282
+ let currentEvent = event;
2283
+ for (const hook of hooks) {
2284
+ const { handler } = hook;
2285
+ const ctx = this.getContext(hook.pluginId);
2286
+ const start = Date.now();
2287
+ try {
2288
+ const result = await this.executeWithTimeout(() => handler({ ...currentEvent }, ctx), hook.timeout);
2289
+ if (result === false) return false;
2290
+ if (result && typeof result === "object") currentEvent = result;
2291
+ } catch (error) {
2292
+ console.error(`[comment:beforeCreate] Plugin "${hook.pluginId}" error (${Date.now() - start}ms):`, error instanceof Error ? error.message : error);
2293
+ if (hook.errorPolicy === "abort") throw error;
2294
+ }
2295
+ }
2296
+ return currentEvent;
2297
+ }
2298
+ /**
2299
+ * Run comment:afterCreate hooks (fire-and-forget).
2300
+ *
2301
+ * Errors are logged but don't propagate — they don't affect the caller.
2302
+ */
2303
+ async runCommentAfterCreate(event) {
2304
+ const hooks = this.getTypedHooks("comment:afterCreate");
2305
+ for (const hook of hooks) {
2306
+ const { handler } = hook;
2307
+ const ctx = this.getContext(hook.pluginId);
2308
+ try {
2309
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2310
+ } catch (error) {
2311
+ console.error(`[comment:afterCreate] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
2312
+ }
2313
+ }
2314
+ }
2315
+ /**
2316
+ * Run comment:afterModerate hooks (fire-and-forget).
2317
+ *
2318
+ * Errors are logged but don't propagate — they don't affect the caller.
2319
+ */
2320
+ async runCommentAfterModerate(event) {
2321
+ const hooks = this.getTypedHooks("comment:afterModerate");
2322
+ for (const hook of hooks) {
2323
+ const { handler } = hook;
2324
+ const ctx = this.getContext(hook.pluginId);
2325
+ try {
2326
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
2327
+ } catch (error) {
2328
+ console.error(`[comment:afterModerate] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
2329
+ }
2330
+ }
2331
+ }
2332
+ /**
2333
+ * Run page:metadata hooks. Each handler returns contributions that are
2334
+ * merged by the metadata collector. Errors are logged but don't propagate.
2335
+ */
2336
+ async runPageMetadata(event) {
2337
+ const hooks = this.getTypedHooks("page:metadata");
2338
+ const results = [];
2339
+ for (const hook of hooks) {
2340
+ const { handler } = hook;
2341
+ const ctx = this.getContext(hook.pluginId);
2342
+ try {
2343
+ const result = await this.executeWithTimeout(() => Promise.resolve(handler(event, ctx)), hook.timeout);
2344
+ if (result != null) {
2345
+ const contributions = Array.isArray(result) ? result : [result];
2346
+ results.push({
2347
+ pluginId: hook.pluginId,
2348
+ contributions
2349
+ });
2350
+ }
2351
+ } catch (error) {
2352
+ console.error(`[page:metadata] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
2353
+ }
2354
+ }
2355
+ return results;
2356
+ }
2357
+ /**
2358
+ * Run page:fragments hooks. Only trusted plugins should be registered
2359
+ * for this hook. Errors are logged but don't propagate.
2360
+ */
2361
+ async runPageFragments(event) {
2362
+ const hooks = this.getTypedHooks("page:fragments");
2363
+ const results = [];
2364
+ for (const hook of hooks) {
2365
+ const { handler } = hook;
2366
+ const ctx = this.getContext(hook.pluginId);
2367
+ try {
2368
+ const result = await this.executeWithTimeout(() => Promise.resolve(handler(event, ctx)), hook.timeout);
2369
+ if (result != null) {
2370
+ const contributions = Array.isArray(result) ? result : [result];
2371
+ results.push({
2372
+ pluginId: hook.pluginId,
2373
+ contributions
2374
+ });
2375
+ }
2376
+ } catch (error) {
2377
+ console.error(`[page:fragments] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
2378
+ }
2379
+ }
2380
+ return results;
2381
+ }
2382
+ /**
2383
+ * Check if any hooks are registered for a given name
2384
+ */
2385
+ hasHooks(name) {
2386
+ const hooks = this.hooks.get(name);
2387
+ return hooks !== void 0 && hooks.length > 0;
2388
+ }
2389
+ /**
2390
+ * Get hook count for debugging
2391
+ */
2392
+ getHookCount(name) {
2393
+ return this.hooks.get(name)?.length || 0;
2394
+ }
2395
+ /**
2396
+ * Get all registered hook names
2397
+ */
2398
+ getRegisteredHooks() {
2399
+ return [...this.hooks.keys()];
2400
+ }
2401
+ /**
2402
+ * Returns hook names where at least one handler declared exclusive: true
2403
+ */
2404
+ getRegisteredExclusiveHooks() {
2405
+ return [...this.exclusiveHookNames];
2406
+ }
2407
+ /**
2408
+ * Check if a hook is exclusive
2409
+ */
2410
+ isExclusiveHook(name) {
2411
+ return this.exclusiveHookNames.has(name);
2412
+ }
2413
+ /**
2414
+ * Set the selected provider for an exclusive hook.
2415
+ * Called by PluginManager after resolution.
2416
+ */
2417
+ setExclusiveSelection(hookName, pluginId) {
2418
+ this.exclusiveSelections.set(hookName, pluginId);
2419
+ }
2420
+ /**
2421
+ * Clear the selected provider for an exclusive hook.
2422
+ */
2423
+ clearExclusiveSelection(hookName) {
2424
+ this.exclusiveSelections.delete(hookName);
2425
+ }
2426
+ /**
2427
+ * Get the selected provider for an exclusive hook (if any).
2428
+ */
2429
+ getExclusiveSelection(hookName) {
2430
+ return this.exclusiveSelections.get(hookName);
2431
+ }
2432
+ /**
2433
+ * Get all plugins that registered a handler for a given exclusive hook.
2434
+ */
2435
+ getExclusiveHookProviders(hookName) {
2436
+ return (this.hooks.get(hookName) ?? []).filter((h) => h.exclusive).map((h) => ({ pluginId: h.pluginId }));
2437
+ }
2438
+ /**
2439
+ * Get all plugins that registered a non-exclusive handler for a given
2440
+ * hook (e.g. `email:beforeSend`, `email:afterSend`), preserving priority
2441
+ * order. Partitions with `getExclusiveHookProviders()`, which returns
2442
+ * plugins whose registration is marked `exclusive: true`.
2443
+ */
2444
+ getHookProviders(hookName) {
2445
+ return (this.hooks.get(hookName) ?? []).filter((h) => !h.exclusive).map((h) => ({ pluginId: h.pluginId }));
2446
+ }
2447
+ /**
2448
+ * Invoke an exclusive hook — dispatch only to the selected provider.
2449
+ * Returns null if no provider is selected or if the selected hook
2450
+ * is not found in the pipeline.
2451
+ *
2452
+ * This is a generic dispatch used by the email pipeline and other
2453
+ * exclusive hook consumers. The handler type is unknown — callers
2454
+ * must know the expected signature.
2455
+ *
2456
+ * Errors are isolated: a failing handler returns an error result
2457
+ * instead of propagating the exception to the caller.
2458
+ */
2459
+ async invokeExclusiveHook(hookName, event) {
2460
+ const selectedPluginId = this.exclusiveSelections.get(hookName);
2461
+ if (!selectedPluginId) return null;
2462
+ const hook = (this.hooks.get(hookName) ?? []).find((h) => h.pluginId === selectedPluginId && h.exclusive);
2463
+ if (!hook) return null;
2464
+ const start = Date.now();
2465
+ try {
2466
+ const ctx = this.getContext(selectedPluginId);
2467
+ const handler = hook.handler;
2468
+ return {
2469
+ result: await this.executeWithTimeout(() => handler(event, ctx), hook.timeout),
2470
+ pluginId: selectedPluginId,
2471
+ duration: Date.now() - start
2472
+ };
2473
+ } catch (error) {
2474
+ return {
2475
+ result: void 0,
2476
+ pluginId: selectedPluginId,
2477
+ error: error instanceof Error ? error : new Error(String(error)),
2478
+ duration: Date.now() - start
2479
+ };
2480
+ }
2481
+ }
2482
+ };
2483
+ /**
2484
+ * Create a hook pipeline from plugins
2485
+ */
2486
+ function createHookPipeline(plugins, factoryOptions) {
2487
+ return new HookPipeline(plugins, factoryOptions);
2488
+ }
2489
+ /** Options table key prefix for exclusive hook selections */
2490
+ const EXCLUSIVE_HOOK_KEY_PREFIX$1 = "emdash:exclusive_hook:";
2491
+ /**
2492
+ * Resolve exclusive hook selections.
2493
+ *
2494
+ * Shared algorithm used by both PluginManager and EmDashRuntime:
2495
+ * 1. If a DB selection exists and that plugin is active → keep it.
2496
+ * 2. If DB selection is stale (plugin inactive/gone) → clear it.
2497
+ * 3. If no selection and only one active provider → auto-select it.
2498
+ * 4. If preferred hints match an active provider → first match wins.
2499
+ * 5. If multiple providers and no hint → leave unselected (admin must choose).
2500
+ */
2501
+ async function resolveExclusiveHooks(opts) {
2502
+ const { pipeline, isActive, getOption, getOptions, setOption, deleteOption, preferredHints } = opts;
2503
+ const exclusiveHookNames = pipeline.getRegisteredExclusiveHooks();
2504
+ if (exclusiveHookNames.length === 0) return;
2505
+ let batchedSelections;
2506
+ if (getOptions) try {
2507
+ batchedSelections = await getOptions(exclusiveHookNames.map((hookName) => `${EXCLUSIVE_HOOK_KEY_PREFIX$1}${hookName}`));
2508
+ } catch {
2509
+ return;
2510
+ }
2511
+ for (const hookName of exclusiveHookNames) {
2512
+ const providers = pipeline.getExclusiveHookProviders(hookName);
2513
+ const activeProviderIds = new Set(providers.map((p) => p.pluginId).filter((id) => isActive(id)));
2514
+ const key = `${EXCLUSIVE_HOOK_KEY_PREFIX$1}${hookName}`;
2515
+ let currentSelection = null;
2516
+ if (batchedSelections) currentSelection = batchedSelections.get(key) ?? null;
2517
+ else try {
2518
+ currentSelection = await getOption(key);
2519
+ } catch {
2520
+ continue;
2521
+ }
2522
+ if (currentSelection && activeProviderIds.has(currentSelection)) {
2523
+ pipeline.setExclusiveSelection(hookName, currentSelection);
2524
+ continue;
2525
+ }
2526
+ if (currentSelection) try {
2527
+ await deleteOption(key);
2528
+ } catch {}
2529
+ if (activeProviderIds.size === 1) {
2530
+ const [onlyProvider] = activeProviderIds;
2531
+ try {
2532
+ await setOption(key, onlyProvider);
2533
+ } catch {}
2534
+ pipeline.setExclusiveSelection(hookName, onlyProvider);
2535
+ continue;
2536
+ }
2537
+ if (preferredHints) {
2538
+ let found = false;
2539
+ for (const [pluginId, hooks] of preferredHints) if (hooks.includes(hookName) && activeProviderIds.has(pluginId)) {
2540
+ try {
2541
+ await setOption(key, pluginId);
2542
+ } catch {}
2543
+ pipeline.setExclusiveSelection(hookName, pluginId);
2544
+ found = true;
2545
+ break;
2546
+ }
2547
+ if (found) continue;
2548
+ }
2549
+ pipeline.clearExclusiveSelection(hookName);
2550
+ }
2551
+ }
2552
+
2553
+ //#endregion
2554
+ //#region src/plugins/save-rejection.ts
2555
+ /**
2556
+ * Thrown by a `content:beforeSave` hook to reject a save with a message
2557
+ * that is safe to show to the editor. The runtime converts it into a
2558
+ * structured `SAVE_REJECTED` API error; any other exception thrown by the
2559
+ * hook cancels the save with a generic error that hides the exception
2560
+ * message.
2561
+ */
2562
+ var ContentSaveRejectedError = class extends Error {
2563
+ name = "ContentSaveRejectedError";
2564
+ };
2565
+ /**
2566
+ * Matches by name as well as by prototype: bundlers can duplicate this
2567
+ * module across SSR chunks, and an `instanceof` against the wrong copy of
2568
+ * the class would misreport a rejection as a plugin crash.
2569
+ */
2570
+ function isContentSaveRejection(error) {
2571
+ if (error instanceof ContentSaveRejectedError) return true;
2572
+ return error instanceof Error && error.name === "ContentSaveRejectedError";
2573
+ }
2574
+
2575
+ //#endregion
2576
+ //#region src/plugins/email.ts
2577
+ /**
2578
+ * Email Pipeline
2579
+ *
2580
+ * Orchestrates the three-stage email pipeline:
2581
+ * 1. email:beforeSend hooks (middleware — transform, validate, cancel)
2582
+ * 2. email:deliver hook (exclusive — exactly one provider delivers)
2583
+ * 3. email:afterSend hooks (logging, analytics, fire-and-forget)
2584
+ *
2585
+ * Security features:
2586
+ * - Recursion guard prevents re-entrant sends (e.g. plugin calling ctx.email.send from a hook)
2587
+ * - System emails (source="system") bypass email:beforeSend and email:afterSend hooks entirely
2588
+ * to protect auth tokens from exfiltration by plugin hooks
2589
+ *
2590
+ */
2591
+ /** Hook name for the exclusive email delivery hook */
2592
+ const EMAIL_DELIVER_HOOK = "email:deliver";
2593
+ /** Source value used for auth emails (magic links, invites, password resets) */
2594
+ const SYSTEM_SOURCE = "system";
2595
+ /**
2596
+ * Error thrown when ctx.email.send() is called but no provider is configured.
2597
+ */
2598
+ var EmailNotConfiguredError = class extends Error {
2599
+ constructor() {
2600
+ super("No email provider is configured. Install and activate an email provider plugin, then select it in Settings > Email.");
2601
+ this.name = "EmailNotConfiguredError";
2602
+ }
2603
+ };
2604
+ /**
2605
+ * Error thrown when a recursive email send is detected.
2606
+ */
2607
+ var EmailRecursionError = class extends Error {
2608
+ constructor() {
2609
+ super("Recursive email send detected. A plugin hook attempted to send an email from within the email pipeline, which would cause infinite recursion.");
2610
+ this.name = "EmailRecursionError";
2611
+ }
2612
+ };
2613
+ /**
2614
+ * Recursion guard using AsyncLocalStorage.
2615
+ *
2616
+ * EmailPipeline is a singleton (worker-lifetime cached via EmDashRuntime).
2617
+ * Instance state like `sendDepth` would false-positive under concurrent
2618
+ * requests because two unrelated sends would increment the same counter.
2619
+ * ALS scopes the guard to the current async execution context, so concurrent
2620
+ * requests each get their own independent recursion tracking.
2621
+ */
2622
+ const emailSendALS = new AsyncLocalStorage();
2623
+ /**
2624
+ * EmailPipeline orchestrates email delivery through the plugin hook system.
2625
+ *
2626
+ * The pipeline runs in three stages:
2627
+ * 1. email:beforeSend — middleware hooks that can transform or cancel messages
2628
+ * 2. email:deliver — exclusive hook dispatching to the selected provider
2629
+ * 3. email:afterSend — fire-and-forget hooks for logging/analytics
2630
+ */
2631
+ var EmailPipeline = class {
2632
+ pipeline;
2633
+ constructor(pipeline) {
2634
+ this.pipeline = pipeline;
2635
+ }
2636
+ /**
2637
+ * Replace the underlying hook pipeline.
2638
+ *
2639
+ * Called by the runtime when rebuilding the hook pipeline after a
2640
+ * plugin is enabled or disabled, so the email pipeline dispatches
2641
+ * to the current set of active hooks.
2642
+ */
2643
+ setPipeline(pipeline) {
2644
+ this.pipeline = pipeline;
2645
+ }
2646
+ /**
2647
+ * Send an email through the full pipeline.
2648
+ *
2649
+ * @param message - The email to send
2650
+ * @param source - Where the email originated ("system" for auth, plugin ID for plugins)
2651
+ * @throws EmailNotConfiguredError if no provider is selected
2652
+ * @throws EmailRecursionError if called re-entrantly from within a hook
2653
+ * @throws Error if the provider handler throws
2654
+ */
2655
+ async send(message, source) {
2656
+ const store = emailSendALS.getStore();
2657
+ if (store && store.depth > 0) throw new EmailRecursionError();
2658
+ const run = () => this.sendInner(message, source);
2659
+ if (store) {
2660
+ store.depth++;
2661
+ try {
2662
+ await run();
2663
+ } finally {
2664
+ store.depth--;
2665
+ }
2666
+ } else await emailSendALS.run({ depth: 1 }, run);
2667
+ }
2668
+ /**
2669
+ * Inner send implementation, separated from the recursion guard.
2670
+ */
2671
+ async sendInner(message, source) {
2672
+ if (!message || typeof message !== "object") throw new Error("Invalid email message: message must be an object");
2673
+ if (!message.to || typeof message.to !== "string") throw new Error("Invalid email message: 'to' is required and must be a string");
2674
+ if (!message.subject || typeof message.subject !== "string") throw new Error("Invalid email message: 'subject' is required and must be a string");
2675
+ if (!message.text || typeof message.text !== "string") throw new Error("Invalid email message: 'text' is required and must be a string");
2676
+ const isSystemEmail = source === SYSTEM_SOURCE;
2677
+ let finalMessage;
2678
+ if (isSystemEmail) finalMessage = message;
2679
+ else {
2680
+ const beforeResult = await this.pipeline.runEmailBeforeSend(message, source);
2681
+ if (beforeResult.message === false) {
2682
+ const cancelledBy = beforeResult.results.find((r) => r.value === false)?.pluginId ?? "unknown";
2683
+ console.info(`[email] Email to "${message.to}" cancelled by plugin "${cancelledBy}"`);
2684
+ return;
2685
+ }
2686
+ finalMessage = beforeResult.message;
2687
+ }
2688
+ const deliverEvent = {
2689
+ message: finalMessage,
2690
+ source
2691
+ };
2692
+ const deliverResult = await this.pipeline.invokeExclusiveHook(EMAIL_DELIVER_HOOK, deliverEvent);
2693
+ if (!deliverResult) throw new EmailNotConfiguredError();
2694
+ if (deliverResult.error) throw deliverResult.error;
2695
+ if (!isSystemEmail) this.pipeline.runEmailAfterSend(finalMessage, source).catch((err) => console.error("[email] afterSend pipeline error:", err instanceof Error ? err.message : err));
2696
+ }
2697
+ /**
2698
+ * Check if an email provider is configured and available.
2699
+ *
2700
+ * Returns true if an email:deliver provider is selected in the exclusive
2701
+ * hook system. Plugins and auth code use this to decide whether to show
2702
+ * "send invite" vs "copy invite link" UI.
2703
+ */
2704
+ isAvailable() {
2705
+ return this.pipeline.getExclusiveSelection(EMAIL_DELIVER_HOOK) !== void 0;
2706
+ }
2707
+ };
2708
+
2709
+ //#endregion
2710
+ //#region src/plugins/manager.ts
2711
+ /** Options table key prefix for exclusive hook DB reads via PluginManager */
2712
+ const EXCLUSIVE_HOOK_KEY_PREFIX = "emdash:exclusive_hook:";
2713
+ /**
2714
+ * Plugin Manager v2
2715
+ *
2716
+ * Manages the full lifecycle of plugins and coordinates hooks/routes.
2717
+ */
2718
+ var PluginManager = class {
2719
+ plugins = /* @__PURE__ */ new Map();
2720
+ hookPipeline = null;
2721
+ routeRegistry = null;
2722
+ factoryOptions;
2723
+ initialized = false;
2724
+ constructor(options) {
2725
+ this.options = options;
2726
+ this.factoryOptions = {
2727
+ db: options.db,
2728
+ storage: options.storage,
2729
+ getUploadUrl: options.getUploadUrl,
2730
+ trustedProxyHeaders: options.trustedProxyHeaders
2731
+ };
2732
+ }
2733
+ /**
2734
+ * Set the email pipeline used when creating plugin contexts.
2735
+ * Reinitializes routes/hooks if already initialized so ctx.email is available immediately.
2736
+ */
2737
+ setEmailPipeline(pipeline) {
2738
+ this.factoryOptions.emailPipeline = pipeline;
2739
+ if (this.initialized) this.reinitialize();
2740
+ }
2741
+ /**
2742
+ * Register a plugin definition
2743
+ * This resolves the definition and adds it to the manager, but doesn't install it
2744
+ */
2745
+ register(definition) {
2746
+ const resolved = definePlugin(definition);
2747
+ if (this.plugins.has(resolved.id)) throw new Error(`Plugin "${resolved.id}" is already registered`);
2748
+ this.plugins.set(resolved.id, {
2749
+ plugin: resolved,
2750
+ state: "registered"
2751
+ });
2752
+ this.initialized = false;
2753
+ return resolved;
2754
+ }
2755
+ /**
2756
+ * Register multiple plugins
2757
+ */
2758
+ registerAll(definitions) {
2759
+ for (const def of definitions) this.register(def);
2760
+ }
2761
+ /**
2762
+ * Unregister a plugin
2763
+ * Plugin must be inactive or just registered
2764
+ */
2765
+ unregister(pluginId) {
2766
+ const entry = this.plugins.get(pluginId);
2767
+ if (!entry) return false;
2768
+ if (entry.state === "active") throw new Error(`Cannot unregister active plugin "${pluginId}". Deactivate it first.`);
2769
+ this.plugins.delete(pluginId);
2770
+ this.initialized = false;
2771
+ return true;
2772
+ }
2773
+ /**
2774
+ * Install a plugin (run install hooks, set up storage)
2775
+ */
2776
+ async install(pluginId) {
2777
+ const entry = this.plugins.get(pluginId);
2778
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2779
+ if (entry.state !== "registered") throw new Error(`Plugin "${pluginId}" is already installed (state: ${entry.state})`);
2780
+ this.ensureInitialized();
2781
+ const results = await this.hookPipeline.runPluginInstall(pluginId);
2782
+ const failed = results.find((r) => !r.success);
2783
+ if (failed) throw new Error(`Plugin install failed: ${failed.error?.message ?? "Unknown error"}`);
2784
+ entry.state = "installed";
2785
+ return results;
2786
+ }
2787
+ /**
2788
+ * Activate a plugin (run activate hooks, enable hooks/routes)
2789
+ */
2790
+ async activate(pluginId) {
2791
+ const entry = this.plugins.get(pluginId);
2792
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2793
+ if (entry.state === "active") return [];
2794
+ if (entry.state === "registered") await this.install(pluginId);
2795
+ this.ensureInitialized();
2796
+ const results = await this.hookPipeline.runPluginActivate(pluginId);
2797
+ const failed = results.find((r) => !r.success);
2798
+ if (failed) throw new Error(`Plugin activation failed: ${failed.error?.message ?? "Unknown error"}`);
2799
+ entry.state = "active";
2800
+ await setCronTasksEnabled(this.options.db, pluginId, true);
2801
+ this.reinitialize();
2802
+ await this.resolveExclusiveHooks();
2803
+ return results;
2804
+ }
2805
+ /**
2806
+ * Deactivate a plugin (run deactivate hooks, disable hooks/routes)
2807
+ */
2808
+ async deactivate(pluginId) {
2809
+ const entry = this.plugins.get(pluginId);
2810
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2811
+ if (entry.state !== "active") return [];
2812
+ this.ensureInitialized();
2813
+ const results = await this.hookPipeline.runPluginDeactivate(pluginId);
2814
+ await setCronTasksEnabled(this.options.db, pluginId, false);
2815
+ entry.state = "inactive";
2816
+ this.reinitialize();
2817
+ await this.resolveExclusiveHooks();
2818
+ return results;
2819
+ }
2820
+ /**
2821
+ * Uninstall a plugin (run uninstall hooks, optionally delete data)
2822
+ */
2823
+ async uninstall(pluginId, deleteData = false) {
2824
+ const entry = this.plugins.get(pluginId);
2825
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2826
+ if (entry.state === "active") await this.deactivate(pluginId);
2827
+ this.ensureInitialized();
2828
+ const results = await this.hookPipeline.runPluginUninstall(pluginId, deleteData);
2829
+ await this.deleteCronTasks(pluginId);
2830
+ this.plugins.delete(pluginId);
2831
+ this.initialized = false;
2832
+ await this.resolveExclusiveHooks();
2833
+ return results;
2834
+ }
2835
+ /**
2836
+ * Run content:beforeSave hooks across all active plugins
2837
+ */
2838
+ async runContentBeforeSave(content, collection, isNew, id, actor) {
2839
+ this.ensureInitialized();
2840
+ return this.hookPipeline.runContentBeforeSave(content, collection, isNew, id, actor);
2841
+ }
2842
+ /**
2843
+ * Run content:afterSave hooks across all active plugins
2844
+ */
2845
+ async runContentAfterSave(content, collection, isNew, actor) {
2846
+ this.ensureInitialized();
2847
+ return this.hookPipeline.runContentAfterSave(content, collection, isNew, actor);
2848
+ }
2849
+ /**
2850
+ * Run content:beforeDelete hooks across all active plugins
2851
+ */
2852
+ async runContentBeforeDelete(id, collection) {
2853
+ this.ensureInitialized();
2854
+ return this.hookPipeline.runContentBeforeDelete(id, collection);
2855
+ }
2856
+ /**
2857
+ * Run content:afterDelete hooks across all active plugins
2858
+ */
2859
+ async runContentAfterDelete(id, collection, permanent) {
2860
+ this.ensureInitialized();
2861
+ return this.hookPipeline.runContentAfterDelete(id, collection, permanent);
2862
+ }
2863
+ /**
2864
+ * Run content:afterPublish hooks across all active plugins
2865
+ */
2866
+ async runContentAfterPublish(content, collection) {
2867
+ this.ensureInitialized();
2868
+ return this.hookPipeline.runContentAfterPublish(content, collection);
2869
+ }
2870
+ /**
2871
+ * Run content:afterUnpublish hooks across all active plugins
2872
+ */
2873
+ async runContentAfterUnpublish(content, collection) {
2874
+ this.ensureInitialized();
2875
+ return this.hookPipeline.runContentAfterUnpublish(content, collection);
2876
+ }
2877
+ /**
2878
+ * Run content:afterRestore hooks across all active plugins
2879
+ */
2880
+ async runContentAfterRestore(content, collection) {
2881
+ this.ensureInitialized();
2882
+ return this.hookPipeline.runContentAfterRestore(content, collection);
2883
+ }
2884
+ /**
2885
+ * Run content:afterSchedule hooks across all active plugins
2886
+ */
2887
+ async runContentAfterSchedule(content, collection) {
2888
+ this.ensureInitialized();
2889
+ return this.hookPipeline.runContentAfterSchedule(content, collection);
2890
+ }
2891
+ /**
2892
+ * Run content:afterUnschedule hooks across all active plugins
2893
+ */
2894
+ async runContentAfterUnschedule(content, collection) {
2895
+ this.ensureInitialized();
2896
+ return this.hookPipeline.runContentAfterUnschedule(content, collection);
2897
+ }
2898
+ /**
2899
+ * Run media:beforeUpload hooks across all active plugins
2900
+ */
2901
+ async runMediaBeforeUpload(file) {
2902
+ this.ensureInitialized();
2903
+ return this.hookPipeline.runMediaBeforeUpload(file);
2904
+ }
2905
+ /**
2906
+ * Run media:afterUpload hooks across all active plugins
2907
+ */
2908
+ async runMediaAfterUpload(media) {
2909
+ this.ensureInitialized();
2910
+ return this.hookPipeline.runMediaAfterUpload(media);
2911
+ }
2912
+ /**
2913
+ * Invoke the cron hook for a specific plugin (per-plugin dispatch).
2914
+ * Used as the InvokeCronHookFn callback for CronExecutor.
2915
+ */
2916
+ async invokeCronHook(pluginId, event) {
2917
+ this.ensureInitialized();
2918
+ const result = await this.hookPipeline.invokeCronHook(pluginId, event);
2919
+ if (!result.success && result.error) throw result.error;
2920
+ }
2921
+ /**
2922
+ * Invoke a plugin route
2923
+ */
2924
+ async invokeRoute(pluginId, routeName, options) {
2925
+ this.ensureInitialized();
2926
+ return this.routeRegistry.invoke(pluginId, routeName, options);
2927
+ }
2928
+ /**
2929
+ * Get all routes for a plugin
2930
+ */
2931
+ getPluginRoutes(pluginId) {
2932
+ this.ensureInitialized();
2933
+ return this.routeRegistry.getRoutes(pluginId);
2934
+ }
2935
+ /**
2936
+ * Get a plugin by ID
2937
+ */
2938
+ getPlugin(pluginId) {
2939
+ return this.plugins.get(pluginId)?.plugin;
2940
+ }
2941
+ /**
2942
+ * Get plugin state
2943
+ */
2944
+ getPluginState(pluginId) {
2945
+ return this.plugins.get(pluginId)?.state;
2946
+ }
2947
+ /**
2948
+ * Get all registered plugins
2949
+ */
2950
+ getAllPlugins() {
2951
+ return Array.from(this.plugins.values(), (entry) => ({
2952
+ plugin: entry.plugin,
2953
+ state: entry.state
2954
+ }));
2955
+ }
2956
+ /**
2957
+ * Get all active plugins
2958
+ */
2959
+ getActivePlugins() {
2960
+ return [...this.plugins.values()].filter((entry) => entry.state === "active").map((entry) => entry.plugin);
2961
+ }
2962
+ /**
2963
+ * Check if a plugin exists
2964
+ */
2965
+ hasPlugin(pluginId) {
2966
+ return this.plugins.has(pluginId);
2967
+ }
2968
+ /**
2969
+ * Check if a plugin is active
2970
+ */
2971
+ isActive(pluginId) {
2972
+ return this.plugins.get(pluginId)?.state === "active";
2973
+ }
2974
+ /**
2975
+ * Get all plugins that registered a handler for an exclusive hook.
2976
+ */
2977
+ getExclusiveHookProviders(hookName) {
2978
+ this.ensureInitialized();
2979
+ return this.hookPipeline.getExclusiveHookProviders(hookName).map((p) => {
2980
+ const plugin = this.plugins.get(p.pluginId);
2981
+ return {
2982
+ pluginId: p.pluginId,
2983
+ pluginName: plugin?.plugin.id ?? p.pluginId
2984
+ };
2985
+ });
2986
+ }
2987
+ /**
2988
+ * Read the selected provider for an exclusive hook from the options table.
2989
+ */
2990
+ async getExclusiveHookSelection(hookName) {
2991
+ return new OptionsRepository(this.options.db).get(`${EXCLUSIVE_HOOK_KEY_PREFIX}${hookName}`);
2992
+ }
2993
+ /**
2994
+ * Set the selected provider for an exclusive hook in the options table.
2995
+ * Pass null to clear the selection.
2996
+ */
2997
+ async setExclusiveHookSelection(hookName, pluginId) {
2998
+ const optionsRepo = new OptionsRepository(this.options.db);
2999
+ const key = `${EXCLUSIVE_HOOK_KEY_PREFIX}${hookName}`;
3000
+ if (pluginId === null) {
3001
+ await optionsRepo.delete(key);
3002
+ this.hookPipeline?.clearExclusiveSelection(hookName);
3003
+ return;
3004
+ }
3005
+ const entry = this.plugins.get(pluginId);
3006
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
3007
+ if (entry.state !== "active") throw new Error(`Plugin "${pluginId}" is not active`);
3008
+ await optionsRepo.set(key, pluginId);
3009
+ this.hookPipeline?.setExclusiveSelection(hookName, pluginId);
3010
+ }
3011
+ /**
3012
+ * Resolution algorithm for exclusive hooks.
3013
+ *
3014
+ * Delegates to the shared resolveExclusiveHooks() function.
3015
+ * See hooks.ts for the full algorithm description.
3016
+ */
3017
+ async resolveExclusiveHooks(preferredHints) {
3018
+ this.ensureInitialized();
3019
+ const optionsRepo = new OptionsRepository(this.options.db);
3020
+ await resolveExclusiveHooks({
3021
+ pipeline: this.hookPipeline,
3022
+ isActive: (pluginId) => this.isActive(pluginId),
3023
+ getOption: (key) => optionsRepo.get(key),
3024
+ getOptions: (keys) => optionsRepo.getMany(keys),
3025
+ setOption: (key, value) => optionsRepo.set(key, value),
3026
+ deleteOption: async (key) => {
3027
+ await optionsRepo.delete(key);
3028
+ },
3029
+ preferredHints
3030
+ });
3031
+ }
3032
+ /**
3033
+ * Get all exclusive hooks with their providers and current selections.
3034
+ * Used by the admin API.
3035
+ */
3036
+ async getExclusiveHooksInfo() {
3037
+ this.ensureInitialized();
3038
+ const exclusiveHookNames = this.hookPipeline.getRegisteredExclusiveHooks();
3039
+ const result = [];
3040
+ for (const hookName of exclusiveHookNames) {
3041
+ const providers = this.hookPipeline.getExclusiveHookProviders(hookName);
3042
+ const selection = await this.getExclusiveHookSelection(hookName);
3043
+ result.push({
3044
+ hookName,
3045
+ providers,
3046
+ selectedPluginId: selection
3047
+ });
3048
+ }
3049
+ return result;
3050
+ }
3051
+ /**
3052
+ * Initialize or reinitialize the hook pipeline and route registry
3053
+ */
3054
+ ensureInitialized() {
3055
+ if (this.initialized) return;
3056
+ const activePlugins = this.getActivePlugins();
3057
+ this.hookPipeline = new HookPipeline(activePlugins, this.factoryOptions);
3058
+ this.routeRegistry = new PluginRouteRegistry(this.factoryOptions);
3059
+ for (const plugin of activePlugins) this.routeRegistry.register(plugin);
3060
+ this.initialized = true;
3061
+ }
3062
+ /**
3063
+ * Force reinitialization (useful after plugin state changes)
3064
+ */
3065
+ reinitialize() {
3066
+ this.initialized = false;
3067
+ this.ensureInitialized();
3068
+ }
3069
+ /**
3070
+ * Delete all cron tasks for a plugin.
3071
+ * Used during uninstall.
3072
+ */
3073
+ async deleteCronTasks(pluginId) {
3074
+ try {
3075
+ await sql`
3076
+ DELETE FROM _emdash_cron_tasks
3077
+ WHERE plugin_id = ${pluginId}
3078
+ `.execute(this.options.db);
3079
+ } catch {}
3080
+ }
3081
+ };
3082
+ /**
3083
+ * Create a plugin manager
3084
+ */
3085
+ function createPluginManager(options) {
3086
+ return new PluginManager(options);
3087
+ }
3088
+
3089
+ //#endregion
3090
+ //#region src/plugins/scheduler/node.ts
3091
+ /** Minimum polling interval (ms) — prevents tight loops if next_run_at is in the past */
3092
+ const MIN_INTERVAL_MS = 1e3;
3093
+ /**
3094
+ * Maximum polling interval (ms). Each wake runs the maintenance pass — stale
3095
+ * lock recovery *and* the scheduled-publishing sweep + system cleanup. The cap
3096
+ * is the worst-case latency for scheduled content when no plugin cron task is
3097
+ * due sooner (`getNextDueTime()` only knows about cron tasks, not content
3098
+ * `scheduled_at`). Held at 60s so Node publish latency matches the Cloudflare
3099
+ * Cron Trigger cadence (`* * * * *`) rather than lagging up to five minutes.
3100
+ */
3101
+ const MAX_INTERVAL_MS = 60 * 1e3;
3102
+ var NodeCronScheduler = class {
3103
+ timer = null;
3104
+ running = false;
3105
+ systemCleanup = null;
3106
+ constructor(executor) {
3107
+ this.executor = executor;
3108
+ }
3109
+ setSystemCleanup(fn) {
3110
+ this.systemCleanup = fn;
3111
+ }
3112
+ start() {
3113
+ this.running = true;
3114
+ this.arm();
3115
+ }
3116
+ stop() {
3117
+ this.running = false;
3118
+ if (this.timer) {
3119
+ clearTimeout(this.timer);
3120
+ this.timer = null;
3121
+ }
3122
+ }
3123
+ reschedule() {
3124
+ if (!this.running) return;
3125
+ if (this.timer) {
3126
+ clearTimeout(this.timer);
3127
+ this.timer = null;
3128
+ }
3129
+ this.arm();
3130
+ }
3131
+ arm() {
3132
+ if (!this.running) return;
3133
+ this.executor.getNextDueTime().then((nextDue) => {
3134
+ if (!this.running) return void 0;
3135
+ let delayMs;
3136
+ if (nextDue) {
3137
+ const dueAt = new Date(nextDue).getTime();
3138
+ delayMs = Math.max(dueAt - Date.now(), MIN_INTERVAL_MS);
3139
+ delayMs = Math.min(delayMs, MAX_INTERVAL_MS);
3140
+ } else delayMs = MAX_INTERVAL_MS;
3141
+ this.timer = setTimeout(() => {
3142
+ if (!this.running) return;
3143
+ this.executeTick();
3144
+ }, delayMs);
3145
+ if (this.timer && typeof this.timer === "object" && "unref" in this.timer) this.timer.unref();
3146
+ }).catch((error) => {
3147
+ console.error("[cron:node] Failed to get next due time:", error);
3148
+ if (this.running) {
3149
+ this.timer = setTimeout(() => this.arm(), MAX_INTERVAL_MS);
3150
+ if (this.timer && typeof this.timer === "object" && "unref" in this.timer) this.timer.unref();
3151
+ }
3152
+ });
3153
+ }
3154
+ executeTick() {
3155
+ if (!this.running) return;
3156
+ const tasks = [this.executor.tick(), this.executor.recoverStaleLocks()];
3157
+ if (this.systemCleanup) tasks.push(this.systemCleanup());
3158
+ Promise.allSettled(tasks).then((results) => {
3159
+ for (const r of results) if (r.status === "rejected") console.error("[cron:node] Tick task failed:", r.reason);
3160
+ }).finally(() => {
3161
+ if (this.running) this.arm();
3162
+ });
3163
+ }
3164
+ };
3165
+
3166
+ //#endregion
3167
+ //#region src/plugins/sandbox/noop.ts
3168
+ /**
3169
+ * Error thrown when attempting to use sandboxing on an unsupported platform.
3170
+ */
3171
+ var SandboxNotAvailableError = class extends Error {
3172
+ constructor() {
3173
+ super("Plugin sandboxing is not available. Configure a sandbox runner: use @emdash-cms/cloudflare/sandbox on Cloudflare, or @emdash-cms/sandbox-workerd/sandbox on Node.js (requires workerd). Without sandboxing, use trusted plugins (from config) instead.");
3174
+ this.name = "SandboxNotAvailableError";
3175
+ }
3176
+ };
3177
+ /**
3178
+ * No-op sandbox runner for platforms without isolation support.
3179
+ *
3180
+ * - `isAvailable()` returns false
3181
+ * - `load()` throws SandboxNotAvailableError
3182
+ * - `terminateAll()` is a no-op
3183
+ *
3184
+ * This is the default runner when no platform adapter is configured.
3185
+ */
3186
+ var NoopSandboxRunner = class {
3187
+ /**
3188
+ * Always returns false - sandboxing is not available.
3189
+ */
3190
+ isAvailable() {
3191
+ return false;
3192
+ }
3193
+ /**
3194
+ * Always returns false - no sandbox runtime to be healthy.
3195
+ */
3196
+ isHealthy() {
3197
+ return false;
3198
+ }
3199
+ /**
3200
+ * Always throws - can't load sandboxed plugins without isolation.
3201
+ */
3202
+ async load(_manifest, _code) {
3203
+ throw new SandboxNotAvailableError();
3204
+ }
3205
+ /**
3206
+ * No-op - sandboxing not available, email callback is irrelevant.
3207
+ */
3208
+ setEmailSend() {}
3209
+ /**
3210
+ * No-op - nothing to terminate.
3211
+ */
3212
+ async terminateAll() {}
3213
+ };
3214
+ /**
3215
+ * Create a no-op sandbox runner.
3216
+ * This is used as the default when no platform adapter is configured.
3217
+ */
3218
+ function createNoopSandboxRunner(_options) {
3219
+ return new NoopSandboxRunner();
3220
+ }
3221
+
3222
+ //#endregion
3223
+ //#region src/plugins/sandbox/hook-result.ts
3224
+ /** Current wire-format version for sandbox hook result envelopes. */
3225
+ const SANDBOX_HOOK_RESULT_VERSION = 1;
3226
+ /** Maximum editor-facing rejection reason accepted from a sandboxed plugin. */
3227
+ const MAX_SANDBOX_SAVE_REJECTION_REASON_LENGTH = 500;
3228
+ function isRecord(value) {
3229
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3230
+ }
3231
+ /** Validate and normalize an untrusted value returned across the sandbox boundary. */
3232
+ function inspectSandboxHookResult(value) {
3233
+ if (!isRecord(value) || !Object.hasOwn(value, "__emdashSandboxHookResult")) return { kind: "value" };
3234
+ if (value.__emdashSandboxHookResult !== true || value.version !== SANDBOX_HOOK_RESULT_VERSION || !isRecord(value.error) || value.error.code !== "SAVE_REJECTED" || typeof value.error.reason !== "string") return { kind: "malformed" };
3235
+ const reason = value.error.reason.trim();
3236
+ if (reason.length === 0 || reason.length > MAX_SANDBOX_SAVE_REJECTION_REASON_LENGTH) return { kind: "malformed" };
3237
+ return {
3238
+ kind: "error",
3239
+ error: {
3240
+ code: "SAVE_REJECTED",
3241
+ reason
3242
+ }
3243
+ };
3244
+ }
3245
+
3246
+ //#endregion
3247
+ //#region src/comments/ranking.ts
3248
+ /**
3249
+ * Comment ranking utilities (Tier 1 of the best-in-class comments RFC).
3250
+ *
3251
+ * Wilson score lower-bound (95% confidence) — the same primitive Reddit uses
3252
+ * for its "Best" comment sort. Ranks by the statistical lower bound of the
3253
+ * positive-reaction proportion rather than the raw count, so a comment with a
3254
+ * couple of reactions can't outrank a heavily-reacted one until it earns
3255
+ * confidence, and a late-but-popular comment still rises (submission time is
3256
+ * irrelevant).
3257
+ *
3258
+ * Positive-only reactions (the recommended default) degrade gracefully: with
3259
+ * `down = 0` the score still increases monotonically with `up` while penalising
3260
+ * low-sample comments — wilson(1,0) ≈ 0.21, wilson(10,0) ≈ 0.73,
3261
+ * wilson(200,0) ≈ 0.98.
3262
+ */
3263
+ /** z for a 95% two-sided confidence interval. */
3264
+ const DEFAULT_Z = 1.96;
3265
+ /** Reactions that count against a comment when both signals are in use. */
3266
+ const NEGATIVE_REACTIONS = new Set(["dislike", "down"]);
3267
+ /**
3268
+ * Wilson score lower bound of the positive proportion.
3269
+ *
3270
+ * @param up count of positive reactions
3271
+ * @param down count of negative reactions
3272
+ * @returns a score in [0, 1]; 0 when there are no reactions
3273
+ */
3274
+ function wilsonLowerBound(up, down, z = DEFAULT_Z) {
3275
+ const n = up + down;
3276
+ if (n <= 0) return 0;
3277
+ const phat = up / n;
3278
+ const z2 = z * z;
3279
+ const denom = 1 + z2 / n;
3280
+ return (phat + z2 / (2 * n) - z * Math.sqrt((phat * (1 - phat) + z2 / (4 * n)) / n)) / denom;
3281
+ }
3282
+ /**
3283
+ * Reduce a per-reaction count map to a single rank score via the Wilson
3284
+ * lower bound. Any reaction not in {@link NEGATIVE_REACTIONS} is treated as
3285
+ * positive, so the positive-only default (just `like`) works without special
3286
+ * casing.
3287
+ */
3288
+ function reactionScore(counts) {
3289
+ let up = 0;
3290
+ let down = 0;
3291
+ for (const [reaction, count] of Object.entries(counts)) if (NEGATIVE_REACTIONS.has(reaction)) down += count;
3292
+ else up += count;
3293
+ return wilsonLowerBound(up, down);
3294
+ }
3295
+
3296
+ //#endregion
3297
+ //#region src/comments/query.ts
3298
+ /**
3299
+ * Get approved comments for a content item.
3300
+ *
3301
+ * @example
3302
+ * ```ts
3303
+ * import { getComments } from "emdash";
3304
+ *
3305
+ * const { items, total } = await getComments({
3306
+ * collection: "posts",
3307
+ * contentId: post.id,
3308
+ * threaded: true,
3309
+ * });
3310
+ * ```
3311
+ */
3312
+ async function getComments(options) {
3313
+ const sort = options.sort ?? "oldest";
3314
+ const withReactions = options.reactions || sort === "best";
3315
+ const threaded = options.threaded ? "t" : "f";
3316
+ return cachedQuery({
3317
+ namespace: CacheNamespace.COMMENTS,
3318
+ key: `comments:${options.collection}:${options.contentId}:${threaded}:${withReactions ? "r" : "n"}:${sort}`,
3319
+ load: async () => {
3320
+ return getCommentsWithDb(await getDb(), options);
3321
+ }
3322
+ });
3323
+ }
3324
+ /**
3325
+ * Get approved comments with an explicit db handle.
3326
+ *
3327
+ * @internal Use `getComments()` in templates. This variant is for routes
3328
+ * that already have a database handle.
3329
+ */
3330
+ async function getCommentsWithDb(db, options) {
3331
+ const repo = new CommentRepository(db);
3332
+ const total = await repo.countByContent(options.collection, options.contentId, "approved");
3333
+ const result = await repo.findByContent(options.collection, options.contentId, {
3334
+ status: "approved",
3335
+ limit: 500
3336
+ });
3337
+ const items = options.threaded ? CommentRepository.assembleThreads(result.items).map((c) => CommentRepository.toPublicComment(c)) : result.items.map((c) => CommentRepository.toPublicComment(c));
3338
+ if (options.reactions || options.sort === "best") {
3339
+ await attachReactions(db, items);
3340
+ if (options.sort === "best") sortByBest(items);
3341
+ }
3342
+ return {
3343
+ items,
3344
+ total
3345
+ };
3346
+ }
3347
+ /**
3348
+ * Attach aggregate reaction counts to a list of public comments (and their
3349
+ * replies), in a single batched query.
3350
+ */
3351
+ async function attachReactions(db, items) {
3352
+ const ids = [];
3353
+ for (const comment of items) {
3354
+ ids.push(comment.id);
3355
+ if (comment.replies) for (const reply of comment.replies) ids.push(reply.id);
3356
+ }
3357
+ if (ids.length === 0) return;
3358
+ const counts = await new CommentReactionRepository(db).countsForComments(ids);
3359
+ const assign = (comment) => {
3360
+ const reactions = counts.get(comment.id);
3361
+ if (reactions) comment.reactions = reactions;
3362
+ };
3363
+ for (const comment of items) {
3364
+ assign(comment);
3365
+ comment.replies?.forEach(assign);
3366
+ }
3367
+ }
3368
+ /**
3369
+ * Sort top-level comments by Wilson-scored reactions (descending), tie-broken
3370
+ * by oldest-first to keep ordering stable.
3371
+ */
3372
+ function sortByBest(items) {
3373
+ items.sort((a, b) => {
3374
+ const scoreDelta = reactionScore(b.reactions ?? {}) - reactionScore(a.reactions ?? {});
3375
+ if (scoreDelta !== 0) return scoreDelta;
3376
+ if (a.createdAt < b.createdAt) return -1;
3377
+ if (a.createdAt > b.createdAt) return 1;
3378
+ return 0;
3379
+ });
3380
+ }
3381
+ /**
3382
+ * Get the count of approved comments for a content item.
3383
+ *
3384
+ * @example
3385
+ * ```ts
3386
+ * import { getCommentCount } from "emdash";
3387
+ *
3388
+ * const count = await getCommentCount("posts", post.id);
3389
+ * ```
3390
+ */
3391
+ async function getCommentCount(collection, contentId) {
3392
+ return getCommentCountWithDb(await getDb(), collection, contentId);
3393
+ }
3394
+ /**
3395
+ * Get comment count with an explicit db handle.
3396
+ *
3397
+ * @internal Use `getCommentCount()` in templates.
3398
+ */
3399
+ async function getCommentCountWithDb(db, collection, contentId) {
3400
+ return new CommentRepository(db).countByContent(collection, contentId, "approved");
3401
+ }
3402
+
3403
+ //#endregion
3404
+ //#region src/menus/index.ts
3405
+ /**
3406
+ * Get a menu by name with resolved URLs.
3407
+ *
3408
+ * @example
3409
+ * ```ts
3410
+ * const menu = await getMenu("primary");
3411
+ * const menuEs = await getMenu("primary", { locale: "es" });
3412
+ * ```
3413
+ */
3414
+ async function getMenu(name, options = {}) {
3415
+ const locale = resolveLocale(options.locale);
3416
+ const trailingSlash = options.trailingSlash ?? await getHostTrailingSlash();
3417
+ return requestCached(`menu:${name}:${locale ?? "*"}:${trailingSlash}`, () => cachedQuery({
3418
+ namespace: CacheNamespace.MENUS,
3419
+ key: `${name}:${locale ?? "*"}:${trailingSlash}`,
3420
+ load: async () => {
3421
+ return getMenuWithDb(name, await getDb(), {
3422
+ locale,
3423
+ trailingSlash
3424
+ });
3425
+ }
3426
+ }));
3427
+ }
3428
+ async function getHostTrailingSlash() {
3429
+ try {
3430
+ return (await import("virtual:emdash/config")).default?.trailingSlash ?? "ignore";
3431
+ } catch {
3432
+ return "ignore";
3433
+ }
3434
+ }
3435
+ /**
3436
+ * Get menu by name with resolved URLs (with explicit db). Internal helper for
3437
+ * admin routes that already have a database handle.
3438
+ */
3439
+ async function getMenuWithDb(name, db, options = {}) {
3440
+ const chain = resolveLocaleChain(options.locale);
3441
+ const selectMenu = () => db.selectFrom("_emdash_menus").selectAll().where("name", "=", name);
3442
+ let menuRow;
3443
+ if (chain.length === 0) menuRow = await selectMenu().orderBy("locale", "asc").executeTakeFirst();
3444
+ else {
3445
+ menuRow = void 0;
3446
+ for (const locale of chain) {
3447
+ menuRow = await selectMenu().where("locale", "=", locale).executeTakeFirst();
3448
+ if (menuRow) break;
3449
+ }
3450
+ }
3451
+ if (!menuRow) return null;
3452
+ const items = await buildMenuTree(await db.selectFrom("_emdash_menu_items").selectAll().$castTo().where("menu_id", "=", menuRow.id).orderBy("sort_order", "asc").execute(), db, menuRow.locale, options.trailingSlash);
3453
+ return {
3454
+ id: menuRow.id,
3455
+ name: menuRow.name,
3456
+ label: menuRow.label,
3457
+ items,
3458
+ locale: menuRow.locale,
3459
+ translationGroup: menuRow.translation_group
3460
+ };
3461
+ }
3462
+ /**
3463
+ * Get all menus (without items, locale-filtered — for admin list / site nav
3464
+ * summaries). When no locale is configured, returns menus across all locales.
3465
+ */
3466
+ async function getMenus(options = {}) {
3467
+ return getMenusWithDb(await getDb(), options);
3468
+ }
3469
+ /**
3470
+ * Get all menus (with explicit db)
3471
+ *
3472
+ * @internal Use `getMenus()` in templates. This variant is for admin routes
3473
+ * that already have a database handle.
3474
+ */
3475
+ async function getMenusWithDb(db, options = {}) {
3476
+ const locale = resolveLocale(options.locale);
3477
+ let query = db.selectFrom("_emdash_menus").select([
3478
+ "id",
3479
+ "name",
3480
+ "label",
3481
+ "locale"
3482
+ ]).orderBy("name", "asc");
3483
+ if (locale !== void 0) query = query.where("locale", "=", locale);
3484
+ return query.execute();
3485
+ }
3486
+ /**
3487
+ * Get a menu by name with a Workers edge-cache hint.
3488
+ *
3489
+ * Use the returned `cacheHint` with `Astro.cache.set()` so pages that render
3490
+ * this menu can be purged automatically when the menu is edited.
3491
+ */
3492
+ async function getMenuWithCacheHint(name, options = {}) {
3493
+ return {
3494
+ data: await getMenu(name, options),
3495
+ cacheHint: { tags: [menuTag(name)] }
3496
+ };
3497
+ }
3498
+ /**
3499
+ * Build a hierarchical menu tree from a flat list of items. Items are
3500
+ * resolved against the given `locale` so references land on the right
3501
+ * per-locale content rows.
3502
+ */
3503
+ async function buildMenuTree(items, db, locale, trailingSlash) {
3504
+ const contentReferences = collectContentReferences(items);
3505
+ const taxonomyReferences = new Set(items.flatMap((item) => item.type === "taxonomy" && item.reference_id ? [item.reference_id] : []));
3506
+ const [urlPatterns, contentLookup, taxonomyLookup] = await Promise.all([
3507
+ contentReferences.size > 0 ? getCollectionUrlPatterns(db, new Set(contentReferences.keys())) : /* @__PURE__ */ new Map(),
3508
+ resolveContentReferences(db, contentReferences, locale),
3509
+ resolveTaxonomyReferences(db, taxonomyReferences, locale)
3510
+ ]);
3511
+ const validItems = (await Promise.all(items.map((item) => resolveMenuItem(item, urlPatterns, contentLookup, taxonomyLookup, locale, trailingSlash)))).filter((item) => item !== null);
3512
+ const itemMap = /* @__PURE__ */ new Map();
3513
+ const rootItems = [];
3514
+ for (const item of validItems) itemMap.set(item.id, {
3515
+ ...item,
3516
+ children: []
3517
+ });
3518
+ for (const item of items) {
3519
+ const menuItem = itemMap.get(item.id);
3520
+ if (!menuItem) continue;
3521
+ if (item.parent_id) {
3522
+ const parent = itemMap.get(item.parent_id);
3523
+ if (parent) parent.children.push(menuItem);
3524
+ else rootItems.push(menuItem);
3525
+ } else rootItems.push(menuItem);
3526
+ }
3527
+ return rootItems;
3528
+ }
3529
+ function collectContentReferences(items) {
3530
+ const references = /* @__PURE__ */ new Map();
3531
+ for (const item of items) {
3532
+ const reference = getContentReference(item);
3533
+ if (!reference) continue;
3534
+ let ids = references.get(reference.collection);
3535
+ if (!ids) {
3536
+ ids = /* @__PURE__ */ new Set();
3537
+ references.set(reference.collection, ids);
3538
+ }
3539
+ ids.add(reference.id);
3540
+ }
3541
+ return references;
3542
+ }
3543
+ function getContentReference(item) {
3544
+ if (item.type === "page" || item.type === "post") {
3545
+ if (!item.reference_id) return null;
3546
+ return {
3547
+ collection: item.reference_collection || `${item.type}s`,
3548
+ id: item.reference_id
3549
+ };
3550
+ }
3551
+ if (item.type === "collection") {
3552
+ if (!item.reference_collection || !item.reference_id) return null;
3553
+ return {
3554
+ collection: item.reference_collection,
3555
+ id: item.reference_id
3556
+ };
3557
+ }
3558
+ if (item.type !== "custom" && item.type !== "taxonomy" && item.reference_collection && item.reference_id) return {
3559
+ collection: item.reference_collection,
3560
+ id: item.reference_id
3561
+ };
3562
+ return null;
3563
+ }
3564
+ /**
3565
+ * Look up the `url_pattern` for a set of collection slugs, request-cached so
3566
+ * a page rendering several menus (header, footer, ...) only pays for the
3567
+ * lookup once per distinct slug set. Callers must treat the returned map as
3568
+ * read-only — it is shared across cache hits within the request.
3569
+ */
3570
+ function getCollectionUrlPatterns(db, collectionSlugs) {
3571
+ return requestCached(`menu-collection-patterns:${[...collectionSlugs].toSorted().join(",")}`, async () => {
3572
+ const rows = await db.selectFrom("_emdash_collections").select(["slug", "url_pattern"]).where("slug", "in", [...collectionSlugs]).execute();
3573
+ const urlPatterns = /* @__PURE__ */ new Map();
3574
+ for (const row of rows) urlPatterns.set(row.slug, row.url_pattern);
3575
+ return urlPatterns;
3576
+ });
3577
+ }
3578
+ /**
3579
+ * Resolve a single menu item's URL. `reference_id` is a translation_group
3580
+ * (migration 036 remapped all existing references); we look it up against
3581
+ * the per-locale ec_* row or per-locale taxonomy row.
3582
+ */
3583
+ async function resolveMenuItem(item, urlPatterns, contentLookup, taxonomyLookup, locale, trailingSlash) {
3584
+ let url;
3585
+ switch (item.type) {
3586
+ case "custom":
3587
+ url = item.custom_url || "#";
3588
+ break;
3589
+ case "page":
3590
+ case "post":
3591
+ url = await resolveContentUrl(item.reference_collection || `${item.type}s`, item.reference_id, urlPatterns, contentLookup, locale, trailingSlash);
3592
+ if (url === null) return null;
3593
+ break;
3594
+ case "taxonomy":
3595
+ url = resolveTaxonomyUrl(item.reference_id, taxonomyLookup);
3596
+ if (url === null) return null;
3597
+ break;
3598
+ case "collection":
3599
+ if (!item.reference_collection) return null;
3600
+ if (item.reference_id) {
3601
+ url = await resolveContentUrl(item.reference_collection, item.reference_id, urlPatterns, contentLookup, locale, trailingSlash);
3602
+ if (url === null) return null;
3603
+ } else url = `/${item.reference_collection}/`;
3604
+ break;
3605
+ default: if (item.reference_collection && item.reference_id) {
3606
+ url = await resolveContentUrl(item.reference_collection, item.reference_id, urlPatterns, contentLookup, locale, trailingSlash);
3607
+ if (url === null) return null;
3608
+ } else url = "#";
3609
+ }
3610
+ return {
3611
+ id: item.id,
3612
+ label: item.label,
3613
+ url: sanitizeHref(url),
3614
+ target: item.target || void 0,
3615
+ titleAttr: item.title_attr || void 0,
3616
+ cssClasses: item.css_classes || void 0,
3617
+ children: []
3618
+ };
3619
+ }
3620
+ async function resolveContentReferences(db, references, locale) {
3621
+ const entries = await Promise.all(Array.from(references, async ([collection, referenceGroups]) => {
3622
+ const lookup = /* @__PURE__ */ new Map();
3623
+ const localized = /* @__PURE__ */ new Map();
3624
+ try {
3625
+ validateIdentifier(collection, "menu item collection");
3626
+ for (const batch of chunks([...referenceGroups], SQL_BATCH_SIZE)) {
3627
+ const result = await sql`
3628
+ SELECT id, slug, published_at, locale, translation_group
3629
+ FROM ${sql.ref(`ec_${collection}`)}
3630
+ WHERE translation_group IN (${sql.join(batch)})
3631
+ `.execute(db);
3632
+ for (const row of result.rows) if (shouldPreferLocalizedRow(row, localized.get(row.translation_group), locale)) localized.set(row.translation_group, row);
3633
+ }
3634
+ for (const [referenceGroup, row] of localized) lookup.set(referenceGroup, {
3635
+ id: row.id,
3636
+ slug: row.slug,
3637
+ publishedAt: row.published_at
3638
+ });
3639
+ const unresolved = [...referenceGroups].filter((id) => !lookup.has(id));
3640
+ for (const batch of chunks(unresolved, SQL_BATCH_SIZE)) {
3641
+ const result = await sql`
3642
+ SELECT id, slug, published_at FROM ${sql.ref(`ec_${collection}`)}
3643
+ WHERE id IN (${sql.join(batch)})
3644
+ `.execute(db);
3645
+ for (const row of result.rows) lookup.set(row.id, {
3646
+ id: row.id,
3647
+ slug: row.slug,
3648
+ publishedAt: row.published_at
3649
+ });
3650
+ }
3651
+ } catch (error) {
3652
+ console.error(`Failed to resolve content URLs for ${collection}:`, error);
3653
+ }
3654
+ return [collection, lookup];
3655
+ }));
3656
+ return new Map(entries);
3657
+ }
3658
+ function shouldPreferLocalizedRow(candidate, existing, locale) {
3659
+ if (!existing) return true;
3660
+ if (candidate.locale === locale) return existing.locale !== locale || candidate.id < existing.id;
3661
+ if (existing.locale === locale) return false;
3662
+ return candidate.locale < existing.locale || candidate.locale === existing.locale && candidate.id < existing.id;
3663
+ }
3664
+ /**
3665
+ * Resolve the URL for a content reference. `referenceGroup` is the content
3666
+ * row's translation_group; we look up the row in the requested locale
3667
+ * (falling back to the source if no translation exists so the menu link is
3668
+ * still clickable).
3669
+ */
3670
+ async function resolveContentUrl(collection, referenceGroup, urlPatterns, contentLookup, locale, trailingSlash) {
3671
+ if (!referenceGroup) return null;
3672
+ const row = contentLookup.get(collection)?.get(referenceGroup);
3673
+ if (!row) return null;
3674
+ return resolveLocalizedContentRoutePath({
3675
+ pattern: urlPatterns.get(collection) ?? null,
3676
+ collection,
3677
+ slug: row.slug,
3678
+ id: row.id,
3679
+ date: row.publishedAt,
3680
+ locale,
3681
+ trailingSlash
3682
+ });
3683
+ }
3684
+ async function resolveTaxonomyReferences(db, referenceGroups, locale) {
3685
+ const lookup = /* @__PURE__ */ new Map();
3686
+ const localized = /* @__PURE__ */ new Map();
3687
+ try {
3688
+ for (const batch of chunks([...referenceGroups], SQL_BATCH_SIZE)) {
3689
+ const rows = await db.selectFrom("taxonomies").select([
3690
+ "id",
3691
+ "name",
3692
+ "slug",
3693
+ "locale",
3694
+ "translation_group"
3695
+ ]).where("translation_group", "in", batch).$narrowType().execute();
3696
+ for (const row of rows) if (shouldPreferLocalizedRow(row, localized.get(row.translation_group), locale)) localized.set(row.translation_group, row);
3697
+ }
3698
+ for (const [referenceGroup, row] of localized) lookup.set(referenceGroup, {
3699
+ name: row.name,
3700
+ slug: row.slug
3701
+ });
3702
+ const unresolved = [...referenceGroups].filter((id) => !lookup.has(id));
3703
+ for (const batch of chunks(unresolved, SQL_BATCH_SIZE)) {
3704
+ const rows = await db.selectFrom("taxonomies").select([
3705
+ "id",
3706
+ "name",
3707
+ "slug"
3708
+ ]).where("id", "in", batch).execute();
3709
+ for (const row of rows) lookup.set(row.id, {
3710
+ name: row.name,
3711
+ slug: row.slug
3712
+ });
3713
+ }
3714
+ } catch (error) {
3715
+ console.error("Failed to resolve taxonomy URLs:", error);
3716
+ }
3717
+ return lookup;
3718
+ }
3719
+ /**
3720
+ * Resolve URL for a taxonomy term reference. `referenceGroup` is the term's
3721
+ * translation_group; we pick the row in the active locale (or fall back).
3722
+ */
3723
+ function resolveTaxonomyUrl(referenceGroup, taxonomyLookup) {
3724
+ if (!referenceGroup) return null;
3725
+ const taxonomy = taxonomyLookup.get(referenceGroup);
3726
+ if (!taxonomy) return null;
3727
+ return `/${taxonomy.name}/${taxonomy.slug}`;
3728
+ }
3729
+
3730
+ //#endregion
3731
+ export { image as A, definePluginRoute as C, portableText as D, portableTextIdentityExtensions as E, EmDashConfigurationError as M, reference as O, definePlugin as S, prosemirrorToPortableText as T, isContentSaveRejection as _, getComments as a, getActiveContentSaveHookName as b, inspectSandboxHookResult as c, createNoopSandboxRunner as d, NodeCronScheduler as f, ContentSaveRejectedError as g, EmailPipeline as h, getCommentCount as i, AuditRepository as j, file as k, NoopSandboxRunner as l, createPluginManager as m, getMenuWithCacheHint as n, MAX_SANDBOX_SAVE_REJECTION_REASON_LENGTH as o, PluginManager as p, getMenus as r, SANDBOX_HOOK_RESULT_VERSION as s, getMenu as t, SandboxNotAvailableError as u, HookPipeline as v, portableTextToProsemirror as w, resolveExclusiveHooks as x, createHookPipeline as y };
3732
+ //# sourceMappingURL=menus-DbgU9z5Q.mjs.map