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