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