dineway 0.1.9 → 0.1.12

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 (720) hide show
  1. package/README.md +63 -17
  2. package/dist/activity-events-B4wp7CrU.mjs +540 -0
  3. package/dist/allowed-origins-C1AKK9AT.mjs +68 -0
  4. package/dist/api/route-utils.d.mts +42 -0
  5. package/dist/api/route-utils.mjs +26 -0
  6. package/dist/api/schemas/index.d.mts +3 -0
  7. package/dist/api/schemas/index.mjs +6 -0
  8. package/dist/api/schemas/setup.d.mts +42 -0
  9. package/dist/api/schemas/setup.mjs +39 -0
  10. package/dist/api-BR7Y0GBo.mjs +2704 -0
  11. package/dist/api-tokens-CPjC3zf8.mjs +3 -0
  12. package/dist/api-tokens-D7UjLbdt.mjs +153 -0
  13. package/dist/{apply-iVSqz2qs.mjs → apply-Bm5QgdrE.mjs} +15 -689
  14. package/dist/astro/index.d.mts +11 -6
  15. package/dist/astro/index.mjs +86 -11
  16. package/dist/astro/middleware/auth.d.mts +11 -7
  17. package/dist/astro/middleware/auth.mjs +19 -104
  18. package/dist/astro/middleware/redirect.mjs +24 -14
  19. package/dist/astro/middleware/request-context.mjs +9 -6
  20. package/dist/astro/middleware/setup.mjs +1 -1
  21. package/dist/astro/middleware.mjs +88 -145
  22. package/dist/astro/routes/PluginRegistry.d.mts +14 -0
  23. package/dist/astro/routes/PluginRegistry.mjs +24 -0
  24. package/dist/astro/routes/api/admin/allowed-domains/_domain_.d.mts +14 -0
  25. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +65 -0
  26. package/dist/astro/routes/api/admin/allowed-domains/index.d.mts +14 -0
  27. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +65 -0
  28. package/dist/astro/routes/api/admin/api-tokens/_id_.d.mts +10 -0
  29. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +33 -0
  30. package/dist/astro/routes/api/admin/api-tokens/index.d.mts +16 -0
  31. package/dist/astro/routes/api/admin/api-tokens/index.mjs +59 -0
  32. package/dist/astro/routes/api/admin/briefing.d.mts +7 -0
  33. package/dist/astro/routes/api/admin/briefing.mjs +71 -0
  34. package/dist/astro/routes/api/admin/bylines/_id_/index.d.mts +9 -0
  35. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +74 -0
  36. package/dist/astro/routes/api/admin/bylines/index.d.mts +8 -0
  37. package/dist/astro/routes/api/admin/bylines/index.mjs +61 -0
  38. package/dist/astro/routes/api/admin/comments/_id_/status.d.mts +7 -0
  39. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +80 -0
  40. package/dist/astro/routes/api/admin/comments/_id_.d.mts +14 -0
  41. package/dist/astro/routes/api/admin/comments/_id_.mjs +46 -0
  42. package/dist/astro/routes/api/admin/comments/bulk.d.mts +7 -0
  43. package/dist/astro/routes/api/admin/comments/bulk.mjs +36 -0
  44. package/dist/astro/routes/api/admin/comments/counts.d.mts +7 -0
  45. package/dist/astro/routes/api/admin/comments/counts.mjs +24 -0
  46. package/dist/astro/routes/api/admin/comments/index.d.mts +10 -0
  47. package/dist/astro/routes/api/admin/comments/index.mjs +40 -0
  48. package/dist/astro/routes/api/admin/context/_id_/history.d.mts +7 -0
  49. package/dist/astro/routes/api/admin/context/_id_/history.mjs +46 -0
  50. package/dist/astro/routes/api/admin/context/_id_/index.d.mts +7 -0
  51. package/dist/astro/routes/api/admin/context/_id_/index.mjs +46 -0
  52. package/dist/astro/routes/api/admin/context/_id_/review.d.mts +7 -0
  53. package/dist/astro/routes/api/admin/context/_id_/review.mjs +61 -0
  54. package/dist/astro/routes/api/admin/context/_id_/supersede.d.mts +7 -0
  55. package/dist/astro/routes/api/admin/context/_id_/supersede.mjs +64 -0
  56. package/dist/astro/routes/api/admin/context/diff.d.mts +7 -0
  57. package/dist/astro/routes/api/admin/context/diff.mjs +50 -0
  58. package/dist/astro/routes/api/admin/context/index.d.mts +8 -0
  59. package/dist/astro/routes/api/admin/context/index.mjs +72 -0
  60. package/dist/astro/routes/api/admin/context/stale.d.mts +7 -0
  61. package/dist/astro/routes/api/admin/context/stale.mjs +50 -0
  62. package/dist/astro/routes/api/admin/hitl-requests/_id_/index.d.mts +7 -0
  63. package/dist/astro/routes/api/admin/hitl-requests/_id_/index.mjs +52 -0
  64. package/dist/astro/routes/api/admin/hitl-requests/_id_/resolve.d.mts +7 -0
  65. package/dist/astro/routes/api/admin/hitl-requests/_id_/resolve.mjs +68 -0
  66. package/dist/astro/routes/api/admin/hitl-requests/index.d.mts +7 -0
  67. package/dist/astro/routes/api/admin/hitl-requests/index.mjs +56 -0
  68. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.d.mts +7 -0
  69. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +99 -0
  70. package/dist/astro/routes/api/admin/hooks/exclusive/index.d.mts +7 -0
  71. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +33 -0
  72. package/dist/astro/routes/api/admin/oauth-clients/_id_.d.mts +18 -0
  73. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +79 -0
  74. package/dist/astro/routes/api/admin/oauth-clients/index.d.mts +14 -0
  75. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +58 -0
  76. package/dist/astro/routes/api/admin/plugins/_id_/disable.d.mts +7 -0
  77. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +90 -0
  78. package/dist/astro/routes/api/admin/plugins/_id_/enable.d.mts +7 -0
  79. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +90 -0
  80. package/dist/astro/routes/api/admin/plugins/_id_/index.d.mts +7 -0
  81. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +55 -0
  82. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.d.mts +7 -0
  83. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +99 -0
  84. package/dist/astro/routes/api/admin/plugins/_id_/update.d.mts +7 -0
  85. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +132 -0
  86. package/dist/astro/routes/api/admin/plugins/index.d.mts +7 -0
  87. package/dist/astro/routes/api/admin/plugins/index.mjs +53 -0
  88. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.d.mts +7 -0
  89. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +36 -0
  90. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.d.mts +7 -0
  91. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +55 -0
  92. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.d.mts +7 -0
  93. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +129 -0
  94. package/dist/astro/routes/api/admin/plugins/marketplace/index.d.mts +7 -0
  95. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +62 -0
  96. package/dist/astro/routes/api/admin/plugins/updates.d.mts +7 -0
  97. package/dist/astro/routes/api/admin/plugins/updates.mjs +53 -0
  98. package/dist/astro/routes/api/admin/review-requests/_id_/index.d.mts +7 -0
  99. package/dist/astro/routes/api/admin/review-requests/_id_/index.mjs +26 -0
  100. package/dist/astro/routes/api/admin/review-requests/_id_/resolve.d.mts +7 -0
  101. package/dist/astro/routes/api/admin/review-requests/_id_/resolve.mjs +98 -0
  102. package/dist/astro/routes/api/admin/review-requests/index.d.mts +7 -0
  103. package/dist/astro/routes/api/admin/review-requests/index.mjs +31 -0
  104. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.d.mts +7 -0
  105. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +55 -0
  106. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.d.mts +7 -0
  107. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +36 -0
  108. package/dist/astro/routes/api/admin/themes/marketplace/index.d.mts +7 -0
  109. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +71 -0
  110. package/dist/astro/routes/api/admin/users/_id_/disable.d.mts +7 -0
  111. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +38 -0
  112. package/dist/astro/routes/api/admin/users/_id_/enable.d.mts +7 -0
  113. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +29 -0
  114. package/dist/astro/routes/api/admin/users/_id_/index.d.mts +8 -0
  115. package/dist/astro/routes/api/admin/users/_id_/index.mjs +104 -0
  116. package/dist/astro/routes/api/admin/users/_id_/send-recovery.d.mts +7 -0
  117. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +43 -0
  118. package/dist/astro/routes/api/admin/users/index.d.mts +7 -0
  119. package/dist/astro/routes/api/admin/users/index.mjs +54 -0
  120. package/dist/astro/routes/api/auth/dev-bypass.d.mts +8 -0
  121. package/dist/astro/routes/api/auth/dev-bypass.mjs +81 -0
  122. package/dist/astro/routes/api/auth/invite/accept.d.mts +7 -0
  123. package/dist/astro/routes/api/auth/invite/accept.mjs +31 -0
  124. package/dist/astro/routes/api/auth/invite/complete.d.mts +7 -0
  125. package/dist/astro/routes/api/auth/invite/complete.mjs +54 -0
  126. package/dist/astro/routes/api/auth/invite/index.d.mts +7 -0
  127. package/dist/astro/routes/api/auth/invite/index.mjs +51 -0
  128. package/dist/astro/routes/api/auth/invite/register-options.d.mts +7 -0
  129. package/dist/astro/routes/api/auth/invite/register-options.mjs +44 -0
  130. package/dist/astro/routes/api/auth/logout.d.mts +7 -0
  131. package/dist/astro/routes/api/auth/logout.mjs +24 -0
  132. package/dist/astro/routes/api/auth/magic-link/send.d.mts +7 -0
  133. package/dist/astro/routes/api/auth/magic-link/send.mjs +48 -0
  134. package/dist/astro/routes/api/auth/magic-link/verify.d.mts +7 -0
  135. package/dist/astro/routes/api/auth/magic-link/verify.mjs +32 -0
  136. package/dist/astro/routes/api/auth/me.d.mts +13 -0
  137. package/dist/astro/routes/api/auth/me.mjs +41 -0
  138. package/dist/astro/routes/api/auth/mode.d.mts +7 -0
  139. package/dist/astro/routes/api/auth/mode.mjs +28 -0
  140. package/dist/astro/routes/api/auth/oauth/_provider_/callback.d.mts +7 -0
  141. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +114 -0
  142. package/dist/astro/routes/api/auth/oauth/_provider_.d.mts +7 -0
  143. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +58 -0
  144. package/dist/astro/routes/api/auth/passkey/_id_.d.mts +14 -0
  145. package/dist/astro/routes/api/auth/passkey/_id_.mjs +62 -0
  146. package/dist/astro/routes/api/auth/passkey/index.d.mts +7 -0
  147. package/dist/astro/routes/api/auth/passkey/index.mjs +25 -0
  148. package/dist/astro/routes/api/auth/passkey/options.d.mts +7 -0
  149. package/dist/astro/routes/api/auth/passkey/options.mjs +46 -0
  150. package/dist/astro/routes/api/auth/passkey/register/options.d.mts +7 -0
  151. package/dist/astro/routes/api/auth/passkey/register/options.mjs +44 -0
  152. package/dist/astro/routes/api/auth/passkey/register/verify.d.mts +7 -0
  153. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +59 -0
  154. package/dist/astro/routes/api/auth/passkey/verify.d.mts +7 -0
  155. package/dist/astro/routes/api/auth/passkey/verify.mjs +47 -0
  156. package/dist/astro/routes/api/auth/signup/complete.d.mts +7 -0
  157. package/dist/astro/routes/api/auth/signup/complete.mjs +55 -0
  158. package/dist/astro/routes/api/auth/signup/request.d.mts +7 -0
  159. package/dist/astro/routes/api/auth/signup/request.mjs +44 -0
  160. package/dist/astro/routes/api/auth/signup/verify.d.mts +7 -0
  161. package/dist/astro/routes/api/auth/signup/verify.mjs +32 -0
  162. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.d.mts +14 -0
  163. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +193 -0
  164. package/dist/astro/routes/api/content/_collection_/_id_/compare.d.mts +7 -0
  165. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +17 -0
  166. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.d.mts +7 -0
  167. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +36 -0
  168. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.d.mts +7 -0
  169. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +39 -0
  170. package/dist/astro/routes/api/content/_collection_/_id_/permanent.d.mts +7 -0
  171. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +31 -0
  172. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.d.mts +7 -0
  173. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +78 -0
  174. package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts +7 -0
  175. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +93 -0
  176. package/dist/astro/routes/api/content/_collection_/_id_/restore.d.mts +7 -0
  177. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +36 -0
  178. package/dist/astro/routes/api/content/_collection_/_id_/revisions.d.mts +7 -0
  179. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +19 -0
  180. package/dist/astro/routes/api/content/_collection_/_id_/schedule.d.mts +8 -0
  181. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +75 -0
  182. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts +14 -0
  183. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +85 -0
  184. package/dist/astro/routes/api/content/_collection_/_id_/translations.d.mts +7 -0
  185. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +40 -0
  186. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.d.mts +7 -0
  187. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +36 -0
  188. package/dist/astro/routes/api/content/_collection_/_id_.d.mts +9 -0
  189. package/dist/astro/routes/api/content/_collection_/_id_.mjs +114 -0
  190. package/dist/astro/routes/api/content/_collection_/index.d.mts +8 -0
  191. package/dist/astro/routes/api/content/_collection_/index.mjs +74 -0
  192. package/dist/astro/routes/api/content/_collection_/trash.d.mts +7 -0
  193. package/dist/astro/routes/api/content/_collection_/trash.mjs +23 -0
  194. package/dist/astro/routes/api/dashboard.d.mts +7 -0
  195. package/dist/astro/routes/api/dashboard.mjs +26 -0
  196. package/dist/astro/routes/api/dev/emails.d.mts +8 -0
  197. package/dist/astro/routes/api/dev/emails.mjs +17 -0
  198. package/dist/astro/routes/api/health.d.mts +7 -0
  199. package/dist/astro/routes/api/health.mjs +34 -0
  200. package/dist/astro/routes/api/import/probe.d.mts +17 -0
  201. package/dist/astro/routes/api/import/probe.mjs +33 -0
  202. package/dist/astro/routes/api/import/wordpress/analyze.d.mts +87 -0
  203. package/dist/astro/routes/api/import/wordpress/analyze.mjs +305 -0
  204. package/dist/astro/routes/api/import/wordpress/execute.d.mts +37 -0
  205. package/dist/astro/routes/api/import/wordpress/execute.mjs +198 -0
  206. package/dist/astro/routes/api/import/wordpress/media.d.mts +35 -0
  207. package/dist/astro/routes/api/import/wordpress/media.mjs +222 -0
  208. package/dist/astro/routes/api/import/wordpress/prepare.d.mts +19 -0
  209. package/dist/astro/routes/api/import/wordpress/prepare.mjs +156 -0
  210. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +21 -0
  211. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +290 -0
  212. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +15 -0
  213. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +69 -0
  214. package/dist/astro/routes/api/import/wordpress-plugin/callback.d.mts +7 -0
  215. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +28 -0
  216. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +19 -0
  217. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +269 -0
  218. package/dist/astro/routes/api/manifest.d.mts +7 -0
  219. package/dist/astro/routes/api/manifest.mjs +50 -0
  220. package/dist/astro/routes/api/mcp.d.mts +15 -0
  221. package/dist/astro/routes/api/mcp.mjs +2701 -0
  222. package/dist/astro/routes/api/media/_id_/confirm.d.mts +10 -0
  223. package/dist/astro/routes/api/media/_id_/confirm.mjs +59 -0
  224. package/dist/astro/routes/api/media/_id_.d.mts +22 -0
  225. package/dist/astro/routes/api/media/_id_.mjs +81 -0
  226. package/dist/astro/routes/api/media/file/_...key_.d.mts +7 -0
  227. package/dist/astro/routes/api/media/file/_...key_.mjs +49 -0
  228. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.d.mts +14 -0
  229. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +49 -0
  230. package/dist/astro/routes/api/media/providers/_providerId_/index.d.mts +14 -0
  231. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +72 -0
  232. package/dist/astro/routes/api/media/providers/index.d.mts +10 -0
  233. package/dist/astro/routes/api/media/providers/index.mjs +18 -0
  234. package/dist/astro/routes/api/media/upload-url.d.mts +10 -0
  235. package/dist/astro/routes/api/media/upload-url.mjs +82 -0
  236. package/dist/astro/routes/api/media.d.mts +16 -0
  237. package/dist/astro/routes/api/media.mjs +137 -0
  238. package/dist/astro/routes/api/menus/_name_/items.d.mts +9 -0
  239. package/dist/astro/routes/api/menus/_name_/items.mjs +165 -0
  240. package/dist/astro/routes/api/menus/_name_/reorder.d.mts +7 -0
  241. package/dist/astro/routes/api/menus/_name_/reorder.mjs +78 -0
  242. package/dist/astro/routes/api/menus/_name_.d.mts +9 -0
  243. package/dist/astro/routes/api/menus/_name_.mjs +124 -0
  244. package/dist/astro/routes/api/menus/index.d.mts +8 -0
  245. package/dist/astro/routes/api/menus/index.mjs +85 -0
  246. package/dist/astro/routes/api/oauth/authorize.d.mts +8 -0
  247. package/dist/astro/routes/api/oauth/authorize.mjs +265 -0
  248. package/dist/astro/routes/api/oauth/device/authorize.d.mts +7 -0
  249. package/dist/astro/routes/api/oauth/device/authorize.mjs +30 -0
  250. package/dist/astro/routes/api/oauth/device/code.d.mts +7 -0
  251. package/dist/astro/routes/api/oauth/device/code.mjs +34 -0
  252. package/dist/astro/routes/api/oauth/device/token.d.mts +7 -0
  253. package/dist/astro/routes/api/oauth/device/token.mjs +45 -0
  254. package/dist/astro/routes/api/oauth/register.d.mts +8 -0
  255. package/dist/astro/routes/api/oauth/register.mjs +115 -0
  256. package/dist/astro/routes/api/oauth/token/refresh.d.mts +7 -0
  257. package/dist/astro/routes/api/oauth/token/refresh.mjs +28 -0
  258. package/dist/astro/routes/api/oauth/token/revoke.d.mts +7 -0
  259. package/dist/astro/routes/api/oauth/token/revoke.mjs +25 -0
  260. package/dist/astro/routes/api/oauth/token.d.mts +8 -0
  261. package/dist/astro/routes/api/oauth/token.mjs +138 -0
  262. package/dist/astro/routes/api/openapi.json.d.mts +7 -0
  263. package/dist/astro/routes/api/openapi.json.mjs +2638 -0
  264. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts +11 -0
  265. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +77 -0
  266. package/dist/astro/routes/api/redirects/404s/index.d.mts +9 -0
  267. package/dist/astro/routes/api/redirects/404s/index.mjs +62 -0
  268. package/dist/astro/routes/api/redirects/404s/summary.d.mts +7 -0
  269. package/dist/astro/routes/api/redirects/404s/summary.mjs +34 -0
  270. package/dist/astro/routes/api/redirects/_id_.d.mts +9 -0
  271. package/dist/astro/routes/api/redirects/_id_.mjs +153 -0
  272. package/dist/astro/routes/api/redirects/index.d.mts +8 -0
  273. package/dist/astro/routes/api/redirects/index.mjs +98 -0
  274. package/dist/astro/routes/api/revisions/_revisionId_/index.d.mts +7 -0
  275. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +16 -0
  276. package/dist/astro/routes/api/revisions/_revisionId_/restore.d.mts +7 -0
  277. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +23 -0
  278. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.d.mts +9 -0
  279. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +99 -0
  280. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.d.mts +8 -0
  281. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +81 -0
  282. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.d.mts +7 -0
  283. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +68 -0
  284. package/dist/astro/routes/api/schema/collections/_slug_/index.d.mts +9 -0
  285. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +98 -0
  286. package/dist/astro/routes/api/schema/collections/index.d.mts +8 -0
  287. package/dist/astro/routes/api/schema/collections/index.mjs +78 -0
  288. package/dist/astro/routes/api/schema/index.d.mts +7 -0
  289. package/dist/astro/routes/api/schema/index.mjs +79 -0
  290. package/dist/astro/routes/api/schema/orphans/_slug_.d.mts +7 -0
  291. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +59 -0
  292. package/dist/astro/routes/api/schema/orphans/index.d.mts +7 -0
  293. package/dist/astro/routes/api/schema/orphans/index.mjs +54 -0
  294. package/dist/astro/routes/api/search/enable.d.mts +15 -0
  295. package/dist/astro/routes/api/search/enable.mjs +55 -0
  296. package/dist/astro/routes/api/search/index.d.mts +16 -0
  297. package/dist/astro/routes/api/search/index.mjs +52 -0
  298. package/dist/astro/routes/api/search/rebuild.d.mts +13 -0
  299. package/dist/astro/routes/api/search/rebuild.mjs +48 -0
  300. package/dist/astro/routes/api/search/stats.d.mts +10 -0
  301. package/dist/astro/routes/api/search/stats.mjs +28 -0
  302. package/dist/astro/routes/api/search/suggest.d.mts +15 -0
  303. package/dist/astro/routes/api/search/suggest.mjs +43 -0
  304. package/dist/astro/routes/api/sections/_slug_.d.mts +9 -0
  305. package/dist/astro/routes/api/sections/_slug_.mjs +157 -0
  306. package/dist/astro/routes/api/sections/index.d.mts +8 -0
  307. package/dist/astro/routes/api/sections/index.mjs +100 -0
  308. package/dist/astro/routes/api/settings/email.d.mts +17 -0
  309. package/dist/astro/routes/api/settings/email.mjs +102 -0
  310. package/dist/astro/routes/api/settings.d.mts +20 -0
  311. package/dist/astro/routes/api/settings.mjs +102 -0
  312. package/dist/astro/routes/api/setup/admin-verify.d.mts +7 -0
  313. package/dist/astro/routes/api/setup/admin-verify.mjs +67 -0
  314. package/dist/astro/routes/api/setup/admin.d.mts +7 -0
  315. package/dist/astro/routes/api/setup/admin.mjs +68 -0
  316. package/dist/astro/routes/api/setup/dev-bypass.d.mts +8 -0
  317. package/dist/astro/routes/api/setup/dev-bypass.mjs +137 -0
  318. package/dist/astro/routes/api/setup/dev-reset.d.mts +7 -0
  319. package/dist/astro/routes/api/setup/dev-reset.mjs +22 -0
  320. package/dist/astro/routes/api/setup/index.d.mts +7 -0
  321. package/dist/astro/routes/api/setup/index.mjs +93 -0
  322. package/dist/astro/routes/api/setup/status.d.mts +7 -0
  323. package/dist/astro/routes/api/setup/status.mjs +57 -0
  324. package/dist/astro/routes/api/snapshot.d.mts +7 -0
  325. package/dist/astro/routes/api/snapshot.mjs +227 -0
  326. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.d.mts +18 -0
  327. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +190 -0
  328. package/dist/astro/routes/api/taxonomies/_name_/terms/index.d.mts +14 -0
  329. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +114 -0
  330. package/dist/astro/routes/api/taxonomies/index.d.mts +14 -0
  331. package/dist/astro/routes/api/taxonomies/index.mjs +104 -0
  332. package/dist/astro/routes/api/themes/preview.d.mts +7 -0
  333. package/dist/astro/routes/api/themes/preview.mjs +47 -0
  334. package/dist/astro/routes/api/typegen.d.mts +17 -0
  335. package/dist/astro/routes/api/typegen.mjs +75 -0
  336. package/dist/astro/routes/api/well-known/auth.d.mts +7 -0
  337. package/dist/astro/routes/api/well-known/auth.mjs +42 -0
  338. package/dist/astro/routes/api/well-known/oauth-authorization-server.d.mts +7 -0
  339. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +33 -0
  340. package/dist/astro/routes/api/well-known/oauth-protected-resource.d.mts +7 -0
  341. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +21 -0
  342. package/dist/astro/routes/api/widget-areas/_name_/reorder.d.mts +7 -0
  343. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +89 -0
  344. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.d.mts +8 -0
  345. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +159 -0
  346. package/dist/astro/routes/api/widget-areas/_name_/widgets.d.mts +7 -0
  347. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +105 -0
  348. package/dist/astro/routes/api/widget-areas/_name_.d.mts +8 -0
  349. package/dist/astro/routes/api/widget-areas/_name_.mjs +100 -0
  350. package/dist/astro/routes/api/widget-areas/index.d.mts +8 -0
  351. package/dist/astro/routes/api/widget-areas/index.mjs +109 -0
  352. package/dist/astro/routes/api/widget-components.d.mts +7 -0
  353. package/dist/astro/routes/api/widget-components.mjs +15 -0
  354. package/dist/astro/routes/robots.txt.d.mts +7 -0
  355. package/dist/astro/routes/robots.txt.mjs +60 -0
  356. package/dist/astro/routes/sitemap-_collection_.xml.d.mts +7 -0
  357. package/dist/astro/routes/sitemap-_collection_.xml.mjs +70 -0
  358. package/dist/astro/routes/sitemap.xml.d.mts +7 -0
  359. package/dist/astro/routes/sitemap.xml.mjs +63 -0
  360. package/dist/astro/types.d.mts +42 -9
  361. package/dist/auth/providers/github-admin.d.mts +9 -0
  362. package/dist/auth/providers/github-admin.mjs +27 -0
  363. package/dist/auth/providers/github.d.mts +12 -0
  364. package/dist/auth/providers/github.mjs +17 -0
  365. package/dist/auth/providers/google-admin.d.mts +9 -0
  366. package/dist/auth/providers/google-admin.mjs +43 -0
  367. package/dist/auth/providers/google.d.mts +12 -0
  368. package/dist/auth/providers/google.mjs +17 -0
  369. package/dist/auth-control-guard-DOZ3UCsP.mjs +13 -0
  370. package/dist/authorize-BAdbMCwC.mjs +36 -0
  371. package/dist/briefing-MVYe_Uyf.mjs +1294 -0
  372. package/dist/briefing-rty4O-wa.mjs +29 -0
  373. package/dist/{byline-OhH2dlRu.mjs → byline-naZxOPSa.mjs} +3 -3
  374. package/dist/{bylines-BGpD9_hy.mjs → bylines-C4LIBOOO.mjs} +20 -53
  375. package/dist/bylines-eVVCuOe4.d.mts +2023 -0
  376. package/dist/{cache-BdSY-gQN.mjs → cache-DEbQ13c9.mjs} +21 -11
  377. package/dist/challenge-store-DDTbisbf.mjs +48 -0
  378. package/dist/cli/index.mjs +142 -22
  379. package/dist/client/external-auth-headers.d.mts +1 -1
  380. package/dist/client/index.d.mts +1 -1
  381. package/dist/client/index.mjs +3 -3
  382. package/dist/comment-DFO-gWDH.mjs +246 -0
  383. package/dist/comments--BsZ9pqA.mjs +186 -0
  384. package/dist/components-BPknylYg.mjs +107 -0
  385. package/dist/{content-DWi4d0rT.mjs → content-CyLkb-qH.mjs} +33 -44
  386. package/dist/context-CNIkMzot.mjs +849 -0
  387. package/dist/context-DNfcm853.mjs +184 -0
  388. package/dist/context-route-helpers-MurhoxWF.mjs +45 -0
  389. package/dist/context-types-C-LwdAxx.mjs +23 -0
  390. package/dist/cron-CKxvBrRT.mjs +263 -0
  391. package/dist/dashboard-DqnYU8EU.mjs +120 -0
  392. package/dist/db/index.d.mts +3 -3
  393. package/dist/db/libsql.d.mts +1 -1
  394. package/dist/db/libsql.mjs +3 -3
  395. package/dist/db/postgres.d.mts +1 -1
  396. package/dist/db/sqlite.d.mts +1 -1
  397. package/dist/db/sqlite.mjs +1 -2
  398. package/dist/device-flow-BGEH5jfn.mjs +487 -0
  399. package/dist/email-console-CuefUXfX.mjs +36 -0
  400. package/dist/entity-aliases-C0v-yNET.mjs +51 -0
  401. package/dist/error-BMUPwxgx.mjs +435 -0
  402. package/dist/escape-BRVaw1Ai.mjs +8 -0
  403. package/dist/experimental-workflows-C9X7yblQ.mjs +38 -0
  404. package/dist/fts-manager-B1pTNEG_.mjs +297 -0
  405. package/dist/hash-CDX7M0ze.mjs +32 -0
  406. package/dist/hitl-requests-ChT32Ilo.mjs +118 -0
  407. package/dist/hitl-route-helpers-CSit54Ru.mjs +96 -0
  408. package/dist/import-BHRLhXAn.mjs +1323 -0
  409. package/dist/import-CNcKWTbp.mjs +243 -0
  410. package/dist/index-CYfhYgXd.d.mts +227 -0
  411. package/dist/index-EUAWaIxW.d.mts +835 -0
  412. package/dist/index.d.mts +17 -11
  413. package/dist/index.mjs +63 -22
  414. package/dist/jsonld-D2gUY4kA.d.mts +141 -0
  415. package/dist/{loader-sMG4TZ-u.mjs → loader-PZnPxFLc.mjs} +42 -5
  416. package/dist/{manifest-schema-D1MSVnoI.mjs → manifest-schema-CgFJAp0H.mjs} +22 -10
  417. package/dist/media/index.d.mts +2 -1
  418. package/dist/media/index.mjs +2 -1
  419. package/dist/media/local-runtime.d.mts +12 -7
  420. package/dist/media/local-runtime.mjs +3 -3
  421. package/dist/{media-DMTr80Gv.mjs → media-_7Fxdu45.mjs} +1 -1
  422. package/dist/menus-DS3_5nWY.mjs +312 -0
  423. package/dist/menus-DYW_UHjv.mjs +256 -0
  424. package/dist/normalize-C49G_o1k.mjs +126 -0
  425. package/dist/oauth-authorization-DxGjiWKL.mjs +283 -0
  426. package/dist/oauth-clients-DxO_NO7k.mjs +298 -0
  427. package/dist/oauth-state-store-C5UFhzwD.mjs +48 -0
  428. package/dist/oauth-user-lookup-Bi0ek9eM.mjs +25 -0
  429. package/dist/options-z8VVg1Ll.mjs +114 -0
  430. package/dist/page/index.d.mts +2 -139
  431. package/dist/page/index.mjs +1 -427
  432. package/dist/parse-C9106ehs.mjs +88 -0
  433. package/dist/passkey-config-BRSZx4pW.mjs +42 -0
  434. package/dist/{patterns-CrCYkMBb.mjs → patterns-K0DLqWir.mjs} +53 -1
  435. package/dist/placeholder-Bh1dfUOd.d.mts +40 -0
  436. package/dist/{placeholder-Cp8g5Emj.mjs → placeholder-C2P5fKa4.mjs} +1 -126
  437. package/dist/plugins/adapt-sandbox-entry.d.mts +10 -5
  438. package/dist/plugins/adapt-sandbox-entry.mjs +4 -4
  439. package/dist/plugins-D7-ILNib.mjs +3249 -0
  440. package/dist/preview-DvYRU-Oy.mjs +788 -0
  441. package/dist/provider-loader-BiQ6lNmf.d.mts +20 -0
  442. package/dist/provider-loader-C21b9OpH.mjs +36 -0
  443. package/dist/public-url-Cun8N3NU.mjs +71 -0
  444. package/dist/{query-kDmwCsHh.mjs → query-B9BO5goQ.mjs} +93 -19
  445. package/dist/query-CsbOywSY.mjs +35 -0
  446. package/dist/rate-limit-DmVTHI5v.mjs +112 -0
  447. package/dist/{redirect-DnEWAkVg.mjs → redirect-CGl64yOX.mjs} +9 -5
  448. package/dist/redirect-COZy-3iY.mjs +16 -0
  449. package/dist/redirects-Cgi_cZfN.mjs +499 -0
  450. package/dist/redirects-lrlmYXVE.mjs +1023 -0
  451. package/dist/{registry-C0zjeB9P.mjs → registry-C-_hxLqa.mjs} +26 -294
  452. package/dist/request-meta-DixlNKKa.mjs +130 -0
  453. package/dist/review-requests-C2DIHwlJ.mjs +148 -0
  454. package/dist/review-requests-DIyjw-K_.mjs +79 -0
  455. package/dist/{runner-CFI6B6J2.d.mts → runner-BU6Lo1ZS.d.mts} +1 -1
  456. package/dist/{index-yvc6E_17.d.mts → runtime-Db4LbNVZ.d.mts} +1188 -2484
  457. package/dist/runtime.d.mts +11 -24
  458. package/dist/runtime.mjs +4 -38
  459. package/dist/schema-BECjUhP8.mjs +8 -0
  460. package/dist/search-DqTHQqtV.mjs +337 -0
  461. package/dist/secrets-CkoJ9zN0.mjs +160 -0
  462. package/dist/sections-B61OxnfB.mjs +338 -0
  463. package/dist/seed/index.d.mts +2 -2
  464. package/dist/seed/index.mjs +18 -13
  465. package/dist/seo/index.d.mts +1 -1
  466. package/dist/seo-C007Luwn.mjs +85 -0
  467. package/dist/seo-CUQctrog.mjs +129 -0
  468. package/dist/seo-contributions-B1fWCnqY.mjs +429 -0
  469. package/dist/service-CyOsm0R6.mjs +194 -0
  470. package/dist/settings-DGtLLSaz.mjs +237 -0
  471. package/dist/settings-Dzgswvg4.mjs +50 -0
  472. package/dist/setup-complete-ChilE-da.mjs +21 -0
  473. package/dist/setup-nonce-BpmLXAuu.mjs +17 -0
  474. package/dist/sidecar-client-B1C6Cf80.mjs +66 -0
  475. package/dist/site-activity-B8FjLIVh.mjs +104 -0
  476. package/dist/site-context-WBxoD99D.mjs +4122 -0
  477. package/dist/site-url-BP7k7OCe.mjs +12 -0
  478. package/dist/slugify-PDTDtMXp.mjs +30 -0
  479. package/dist/ssrf-DDwRxF6B.mjs +248 -0
  480. package/dist/storage/local.d.mts +1 -1
  481. package/dist/storage/local.mjs +1 -1
  482. package/dist/storage/s3.d.mts +1 -1
  483. package/dist/storage/s3.mjs +2 -2
  484. package/dist/{taxonomies-1s5PaS_8.mjs → taxonomies-D2aZGuns.mjs} +11 -7
  485. package/dist/taxonomies-z6Lz91BC.mjs +355 -0
  486. package/dist/taxonomy-D5cbhc8u.mjs +165 -0
  487. package/dist/{tokens-CJz9ubV6.mjs → tokens-BOJw-D9F.mjs} +1 -1
  488. package/dist/{transport-DB5eDN4x.mjs → transport-D3i4yWRE.mjs} +5 -4
  489. package/dist/trusted-proxy-BbaZfkT9.mjs +30 -0
  490. package/dist/types-0Vr68fc2.d.mts +344 -0
  491. package/dist/types-BFmjniC2.d.mts +165 -0
  492. package/dist/{types-BawVha09.mjs → types-Bs6lTBBW.mjs} +1 -1
  493. package/dist/{types-BuMDPy5C.d.mts → types-C0mmVRJN.d.mts} +6 -0
  494. package/dist/{placeholder--wOi4TbO.d.mts → types-OPs5Q_sX.d.mts} +1 -38
  495. package/dist/{types-Cj0KMIZV.d.mts → types-Q616b2Hn.d.mts} +54 -16
  496. package/dist/ui/client-runtime.d.mts +12 -0
  497. package/dist/ui/client-runtime.mjs +32 -0
  498. package/dist/ui/server-runtime.d.mts +33 -0
  499. package/dist/ui/server-runtime.mjs +80 -0
  500. package/dist/url-DNjT2abR.mjs +49 -0
  501. package/dist/user-CcXq-zoL.mjs +154 -0
  502. package/dist/utils-C0ONdBul.mjs +285 -0
  503. package/dist/{validate-IPf8n4Fj.d.mts → validate-BwmQEbu8.d.mts} +3 -3
  504. package/dist/{validate-BZ5wnLLp.mjs → validate-C7TzfamJ.mjs} +1 -1
  505. package/dist/version-D3vDb22n.mjs +6 -0
  506. package/dist/widgets-B7DRpZvy.mjs +104 -0
  507. package/dist/wordpress-slugs-CnporCYH.mjs +14 -0
  508. package/dist/zod-generator-DBVP8D0P.mjs +132 -0
  509. package/locals.d.ts +1 -6
  510. package/package.json +81 -11
  511. package/src/components/Button.astro +1 -1
  512. package/src/components/CommentForm.astro +1 -1
  513. package/src/components/Comments.astro +1 -3
  514. package/src/components/DinewayBodyEnd.astro +5 -3
  515. package/src/components/DinewayBodyStart.astro +5 -3
  516. package/src/components/DinewayHead.astro +15 -9
  517. package/src/components/DinewayImage.astro +12 -8
  518. package/src/components/DinewayMedia.astro +15 -6
  519. package/src/components/Embed.astro +1 -2
  520. package/src/components/File.astro +1 -1
  521. package/src/components/Gallery.astro +5 -3
  522. package/src/components/HtmlBlock.astro +1 -1
  523. package/src/components/Image.astro +9 -3
  524. package/src/components/InlinePortableTextEditor.tsx +69 -20
  525. package/src/components/PortableText.astro +1 -1
  526. package/src/components/WidgetArea.astro +1 -1
  527. package/src/components/WidgetRenderer.astro +1 -3
  528. package/src/components/marks/Link.astro +1 -1
  529. package/src/components/widgets/Archives.astro +1 -1
  530. package/src/components/widgets/Categories.astro +1 -1
  531. package/src/components/widgets/RecentPosts.astro +1 -1
  532. package/src/components/widgets/Tags.astro +1 -1
  533. package/dist/error-BmL6QipT.mjs +0 -30
  534. package/dist/search-DxopAWxs.mjs +0 -11200
  535. package/dist/version-BPz1imu2.mjs +0 -6
  536. package/src/astro/routes/PluginRegistry.tsx +0 -21
  537. package/src/astro/routes/api/admin/allowed-domains/[domain].ts +0 -112
  538. package/src/astro/routes/api/admin/allowed-domains/index.ts +0 -108
  539. package/src/astro/routes/api/admin/api-tokens/[id].ts +0 -44
  540. package/src/astro/routes/api/admin/api-tokens/index.ts +0 -90
  541. package/src/astro/routes/api/admin/briefing.ts +0 -76
  542. package/src/astro/routes/api/admin/bylines/[id]/index.ts +0 -90
  543. package/src/astro/routes/api/admin/bylines/index.ts +0 -74
  544. package/src/astro/routes/api/admin/comments/[id]/status.ts +0 -120
  545. package/src/astro/routes/api/admin/comments/[id].ts +0 -64
  546. package/src/astro/routes/api/admin/comments/bulk.ts +0 -42
  547. package/src/astro/routes/api/admin/comments/counts.ts +0 -30
  548. package/src/astro/routes/api/admin/comments/index.ts +0 -46
  549. package/src/astro/routes/api/admin/context/[id]/history.ts +0 -35
  550. package/src/astro/routes/api/admin/context/[id]/index.ts +0 -35
  551. package/src/astro/routes/api/admin/context/[id]/review.ts +0 -57
  552. package/src/astro/routes/api/admin/context/[id]/supersede.ts +0 -58
  553. package/src/astro/routes/api/admin/context/diff.ts +0 -35
  554. package/src/astro/routes/api/admin/context/index.ts +0 -69
  555. package/src/astro/routes/api/admin/context/stale.ts +0 -35
  556. package/src/astro/routes/api/admin/hitl-requests/[id]/index.ts +0 -38
  557. package/src/astro/routes/api/admin/hitl-requests/[id]/resolve.ts +0 -54
  558. package/src/astro/routes/api/admin/hitl-requests/index.ts +0 -38
  559. package/src/astro/routes/api/admin/hooks/exclusive/[hookName].ts +0 -132
  560. package/src/astro/routes/api/admin/hooks/exclusive/index.ts +0 -51
  561. package/src/astro/routes/api/admin/oauth-clients/[id].ts +0 -137
  562. package/src/astro/routes/api/admin/oauth-clients/index.ts +0 -95
  563. package/src/astro/routes/api/admin/plugins/[id]/disable.ts +0 -91
  564. package/src/astro/routes/api/admin/plugins/[id]/enable.ts +0 -91
  565. package/src/astro/routes/api/admin/plugins/[id]/index.ts +0 -38
  566. package/src/astro/routes/api/admin/plugins/[id]/uninstall.ts +0 -98
  567. package/src/astro/routes/api/admin/plugins/[id]/update.ts +0 -154
  568. package/src/astro/routes/api/admin/plugins/index.ts +0 -32
  569. package/src/astro/routes/api/admin/plugins/marketplace/[id]/icon.ts +0 -62
  570. package/src/astro/routes/api/admin/plugins/marketplace/[id]/index.ts +0 -33
  571. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +0 -135
  572. package/src/astro/routes/api/admin/plugins/marketplace/index.ts +0 -38
  573. package/src/astro/routes/api/admin/plugins/updates.ts +0 -28
  574. package/src/astro/routes/api/admin/review-requests/[id]/index.ts +0 -35
  575. package/src/astro/routes/api/admin/review-requests/[id]/resolve.ts +0 -52
  576. package/src/astro/routes/api/admin/review-requests/index.ts +0 -35
  577. package/src/astro/routes/api/admin/themes/marketplace/[id]/index.ts +0 -33
  578. package/src/astro/routes/api/admin/themes/marketplace/[id]/thumbnail.ts +0 -62
  579. package/src/astro/routes/api/admin/themes/marketplace/index.ts +0 -45
  580. package/src/astro/routes/api/admin/users/[id]/disable.ts +0 -72
  581. package/src/astro/routes/api/admin/users/[id]/enable.ts +0 -48
  582. package/src/astro/routes/api/admin/users/[id]/index.ts +0 -166
  583. package/src/astro/routes/api/admin/users/[id]/send-recovery.ts +0 -72
  584. package/src/astro/routes/api/admin/users/index.ts +0 -66
  585. package/src/astro/routes/api/auth/dev-bypass.ts +0 -139
  586. package/src/astro/routes/api/auth/invite/accept.ts +0 -52
  587. package/src/astro/routes/api/auth/invite/complete.ts +0 -86
  588. package/src/astro/routes/api/auth/invite/index.ts +0 -99
  589. package/src/astro/routes/api/auth/invite/register-options.ts +0 -73
  590. package/src/astro/routes/api/auth/logout.ts +0 -40
  591. package/src/astro/routes/api/auth/magic-link/send.ts +0 -90
  592. package/src/astro/routes/api/auth/magic-link/verify.ts +0 -71
  593. package/src/astro/routes/api/auth/me.ts +0 -60
  594. package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +0 -221
  595. package/src/astro/routes/api/auth/oauth/[provider].ts +0 -120
  596. package/src/astro/routes/api/auth/passkey/[id].ts +0 -124
  597. package/src/astro/routes/api/auth/passkey/index.ts +0 -54
  598. package/src/astro/routes/api/auth/passkey/options.ts +0 -85
  599. package/src/astro/routes/api/auth/passkey/register/options.ts +0 -88
  600. package/src/astro/routes/api/auth/passkey/register/verify.ts +0 -119
  601. package/src/astro/routes/api/auth/passkey/verify.ts +0 -72
  602. package/src/astro/routes/api/auth/signup/complete.ts +0 -87
  603. package/src/astro/routes/api/auth/signup/request.ts +0 -89
  604. package/src/astro/routes/api/auth/signup/verify.ts +0 -53
  605. package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +0 -310
  606. package/src/astro/routes/api/content/[collection]/[id]/compare.ts +0 -28
  607. package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +0 -68
  608. package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +0 -77
  609. package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +0 -42
  610. package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +0 -107
  611. package/src/astro/routes/api/content/[collection]/[id]/publish.ts +0 -100
  612. package/src/astro/routes/api/content/[collection]/[id]/restore.ts +0 -64
  613. package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +0 -31
  614. package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +0 -129
  615. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +0 -143
  616. package/src/astro/routes/api/content/[collection]/[id]/translations.ts +0 -50
  617. package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +0 -69
  618. package/src/astro/routes/api/content/[collection]/[id].ts +0 -173
  619. package/src/astro/routes/api/content/[collection]/index.ts +0 -103
  620. package/src/astro/routes/api/content/[collection]/trash.ts +0 -33
  621. package/src/astro/routes/api/dashboard.ts +0 -32
  622. package/src/astro/routes/api/dev/emails.ts +0 -36
  623. package/src/astro/routes/api/health.ts +0 -54
  624. package/src/astro/routes/api/import/probe.ts +0 -47
  625. package/src/astro/routes/api/import/wordpress/analyze.ts +0 -523
  626. package/src/astro/routes/api/import/wordpress/execute.ts +0 -330
  627. package/src/astro/routes/api/import/wordpress/media.ts +0 -338
  628. package/src/astro/routes/api/import/wordpress/prepare.ts +0 -212
  629. package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +0 -425
  630. package/src/astro/routes/api/import/wordpress-plugin/analyze.ts +0 -111
  631. package/src/astro/routes/api/import/wordpress-plugin/callback.ts +0 -58
  632. package/src/astro/routes/api/import/wordpress-plugin/execute.ts +0 -399
  633. package/src/astro/routes/api/manifest.ts +0 -75
  634. package/src/astro/routes/api/mcp.ts +0 -125
  635. package/src/astro/routes/api/media/[id]/confirm.ts +0 -93
  636. package/src/astro/routes/api/media/[id].ts +0 -145
  637. package/src/astro/routes/api/media/file/[...key].ts +0 -79
  638. package/src/astro/routes/api/media/providers/[providerId]/[itemId].ts +0 -91
  639. package/src/astro/routes/api/media/providers/[providerId]/index.ts +0 -111
  640. package/src/astro/routes/api/media/providers/index.ts +0 -30
  641. package/src/astro/routes/api/media/upload-url.ts +0 -146
  642. package/src/astro/routes/api/media.ts +0 -204
  643. package/src/astro/routes/api/menus/[name]/items.ts +0 -206
  644. package/src/astro/routes/api/menus/[name]/reorder.ts +0 -79
  645. package/src/astro/routes/api/menus/[name].ts +0 -145
  646. package/src/astro/routes/api/menus/index.ts +0 -91
  647. package/src/astro/routes/api/oauth/authorize.ts +0 -430
  648. package/src/astro/routes/api/oauth/device/authorize.ts +0 -45
  649. package/src/astro/routes/api/oauth/device/code.ts +0 -56
  650. package/src/astro/routes/api/oauth/device/token.ts +0 -70
  651. package/src/astro/routes/api/oauth/register.ts +0 -182
  652. package/src/astro/routes/api/oauth/token/refresh.ts +0 -38
  653. package/src/astro/routes/api/oauth/token/revoke.ts +0 -38
  654. package/src/astro/routes/api/oauth/token.ts +0 -195
  655. package/src/astro/routes/api/openapi.json.ts +0 -33
  656. package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +0 -109
  657. package/src/astro/routes/api/redirects/404s/index.ts +0 -72
  658. package/src/astro/routes/api/redirects/404s/summary.ts +0 -33
  659. package/src/astro/routes/api/redirects/[id].ts +0 -183
  660. package/src/astro/routes/api/redirects/index.ts +0 -100
  661. package/src/astro/routes/api/revisions/[revisionId]/index.ts +0 -29
  662. package/src/astro/routes/api/revisions/[revisionId]/restore.ts +0 -62
  663. package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +0 -104
  664. package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +0 -67
  665. package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +0 -45
  666. package/src/astro/routes/api/schema/collections/[slug]/index.ts +0 -107
  667. package/src/astro/routes/api/schema/collections/index.ts +0 -61
  668. package/src/astro/routes/api/schema/index.ts +0 -109
  669. package/src/astro/routes/api/schema/orphans/[slug].ts +0 -36
  670. package/src/astro/routes/api/schema/orphans/index.ts +0 -26
  671. package/src/astro/routes/api/search/enable.ts +0 -64
  672. package/src/astro/routes/api/search/index.ts +0 -52
  673. package/src/astro/routes/api/search/rebuild.ts +0 -72
  674. package/src/astro/routes/api/search/stats.ts +0 -35
  675. package/src/astro/routes/api/search/suggest.ts +0 -50
  676. package/src/astro/routes/api/sections/[slug].ts +0 -203
  677. package/src/astro/routes/api/sections/index.ts +0 -107
  678. package/src/astro/routes/api/settings/email.ts +0 -150
  679. package/src/astro/routes/api/settings.ts +0 -116
  680. package/src/astro/routes/api/setup/admin-verify.ts +0 -122
  681. package/src/astro/routes/api/setup/admin.ts +0 -104
  682. package/src/astro/routes/api/setup/dev-bypass.ts +0 -200
  683. package/src/astro/routes/api/setup/dev-reset.ts +0 -40
  684. package/src/astro/routes/api/setup/index.ts +0 -128
  685. package/src/astro/routes/api/setup/status.ts +0 -122
  686. package/src/astro/routes/api/snapshot.ts +0 -76
  687. package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +0 -232
  688. package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +0 -131
  689. package/src/astro/routes/api/taxonomies/index.ts +0 -114
  690. package/src/astro/routes/api/themes/preview.ts +0 -78
  691. package/src/astro/routes/api/typegen.ts +0 -114
  692. package/src/astro/routes/api/well-known/auth.ts +0 -71
  693. package/src/astro/routes/api/well-known/oauth-authorization-server.ts +0 -48
  694. package/src/astro/routes/api/well-known/oauth-protected-resource.ts +0 -39
  695. package/src/astro/routes/api/widget-areas/[name]/reorder.ts +0 -114
  696. package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +0 -213
  697. package/src/astro/routes/api/widget-areas/[name]/widgets.ts +0 -126
  698. package/src/astro/routes/api/widget-areas/[name].ts +0 -135
  699. package/src/astro/routes/api/widget-areas/index.ts +0 -149
  700. package/src/astro/routes/api/widget-components.ts +0 -22
  701. package/src/astro/routes/robots.txt.ts +0 -81
  702. package/src/astro/routes/sitemap-[collection].xml.ts +0 -104
  703. package/src/astro/routes/sitemap.xml.ts +0 -92
  704. /package/dist/{adapters-C2ypTrZZ.d.mts → adapters-DuLQZhRY.d.mts} +0 -0
  705. /package/{src → dist}/astro/routes/admin.astro +0 -0
  706. /package/dist/{base64-F8-DUraK.mjs → base64-Cz-aU0X1.mjs} +0 -0
  707. /package/dist/{chunks--4F8ddV4.mjs → chunks-D_jVet6z.mjs} +0 -0
  708. /package/dist/{config-BXwuX8Bx.mjs → config-CAMFxGaV.mjs} +0 -0
  709. /package/dist/{db-errors-CEqD7qH9.mjs → db-errors-DyZkswzF.mjs} +0 -0
  710. /package/dist/{default-VjJyuuG9.mjs → default-D4ngTpW8.mjs} +0 -0
  711. /package/dist/{load-Coc9HpHH.mjs → load-B2XtDw__.mjs} +0 -0
  712. /package/dist/{mode-47goXBBK.mjs → mode-DUhxwUhv.mjs} +0 -0
  713. /package/dist/{request-cache-Dk5qPSOx.mjs → request-cache-DHMRr2Lf.mjs} +0 -0
  714. /package/dist/{transaction-Cn2rjY78.mjs → transaction-x2tJQ-A1.mjs} +0 -0
  715. /package/dist/{transport-Wge_IzKl.d.mts → transport-BXe1AM79.d.mts} +0 -0
  716. /package/dist/{types-CWbdtiux.d.mts → types-B7kpsMJ3.d.mts} +0 -0
  717. /package/dist/{types-BzcUjoqg.d.mts → types-DJlpx5Ay.d.mts} +0 -0
  718. /package/dist/{types-COeOq9nK.mjs → types-DL7Y8D_t.mjs} +0 -0
  719. /package/dist/{types-DOrVigru.d.mts → types-DZPw8Rru.d.mts} +0 -0
  720. /package/dist/{types-griIBQOQ.mjs → types-fAInWQDO.mjs} +0 -0
@@ -0,0 +1,3249 @@
1
+ import { t as OptionsRepository } from "./options-z8VVg1Ll.mjs";
2
+ import { n as createPluginContext, t as PluginContextFactory } from "./context-CNIkMzot.mjs";
3
+ import { t as extractRequestMeta } from "./request-meta-DixlNKKa.mjs";
4
+ import { r as setCronTasksEnabled } from "./cron-CKxvBrRT.mjs";
5
+ import { sql } from "kysely";
6
+ import { AsyncLocalStorage } from "node:async_hooks";
7
+ import { ulid } from "ulidx";
8
+ import { z } from "astro/zod";
9
+ import { Worker } from "node:worker_threads";
10
+
11
+ //#region src/fields/image.ts
12
+ /**
13
+ * Image field schema
14
+ */
15
+ const imageSchema = z.object({
16
+ id: z.string(),
17
+ src: z.string(),
18
+ alt: z.string().optional(),
19
+ width: z.number().optional(),
20
+ height: z.number().optional()
21
+ });
22
+ /**
23
+ * Image field
24
+ * References media items from the media library
25
+ */
26
+ function image(options) {
27
+ return {
28
+ type: "image",
29
+ columnType: "TEXT",
30
+ schema: options?.required === false ? imageSchema.optional() : imageSchema,
31
+ options,
32
+ ui: { widget: "image" }
33
+ };
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/fields/reference.ts
38
+ /**
39
+ * Reference field
40
+ * References another content item by ID
41
+ */
42
+ function reference(collection, options) {
43
+ const schema = z.string();
44
+ return {
45
+ type: "reference",
46
+ columnType: "TEXT",
47
+ schema: options?.required === false ? schema.optional() : schema,
48
+ options: {
49
+ ...options,
50
+ collection
51
+ },
52
+ ui: { widget: "reference" }
53
+ };
54
+ }
55
+
56
+ //#endregion
57
+ //#region src/fields/portable-text.ts
58
+ /**
59
+ * Portable Text block schema
60
+ */
61
+ const portableTextBlockSchema = z.object({
62
+ _type: z.string(),
63
+ _key: z.string()
64
+ }).passthrough();
65
+ /**
66
+ * Portable Text field
67
+ * Stores structured content in Portable Text format
68
+ */
69
+ function portableText(options) {
70
+ const schema = z.array(portableTextBlockSchema);
71
+ return {
72
+ type: "portableText",
73
+ columnType: "JSON",
74
+ schema: options?.required === false ? schema.optional() : schema,
75
+ options,
76
+ ui: { widget: "portableText" }
77
+ };
78
+ }
79
+
80
+ //#endregion
81
+ //#region src/content/converters/prosemirror-to-portable-text.ts
82
+ /**
83
+ * Generate a unique key for Portable Text blocks
84
+ */
85
+ function generateKey() {
86
+ return Math.random().toString(36).substring(2, 11);
87
+ }
88
+ /**
89
+ * Convert ProseMirror document to Portable Text
90
+ */
91
+ function prosemirrorToPortableText(doc) {
92
+ if (!doc || doc.type !== "doc" || !doc.content) return [];
93
+ const blocks = [];
94
+ for (const node of doc.content) {
95
+ const converted = convertNode(node);
96
+ if (converted) if (Array.isArray(converted)) blocks.push(...converted);
97
+ else blocks.push(converted);
98
+ }
99
+ return blocks;
100
+ }
101
+ /**
102
+ * Convert a single ProseMirror node to Portable Text block(s)
103
+ */
104
+ function convertNode(node) {
105
+ switch (node.type) {
106
+ case "paragraph": return convertParagraph(node);
107
+ case "heading": return convertHeading(node);
108
+ case "bulletList": return convertList$1(node, "bullet");
109
+ case "orderedList": return convertList$1(node, "number");
110
+ case "blockquote": return convertBlockquote(node);
111
+ case "codeBlock": return convertCodeBlock$1(node);
112
+ case "image": return convertImage$1(node);
113
+ case "horizontalRule": return {
114
+ _type: "break",
115
+ _key: generateKey(),
116
+ style: "lineBreak"
117
+ };
118
+ default: return {
119
+ _type: node.type,
120
+ _key: generateKey(),
121
+ ...node.attrs,
122
+ _pmContent: node.content
123
+ };
124
+ }
125
+ }
126
+ /**
127
+ * Convert paragraph to Portable Text block
128
+ */
129
+ function convertParagraph(node) {
130
+ const { children, markDefs } = convertInlineContent(node.content || []);
131
+ if (children.length === 0) return null;
132
+ return {
133
+ _type: "block",
134
+ _key: generateKey(),
135
+ style: "normal",
136
+ children,
137
+ markDefs: markDefs.length > 0 ? markDefs : void 0
138
+ };
139
+ }
140
+ /** Map heading level number to Portable Text style */
141
+ function headingLevelToStyle(level) {
142
+ switch (level) {
143
+ case 1: return "h1";
144
+ case 2: return "h2";
145
+ case 3: return "h3";
146
+ case 4: return "h4";
147
+ case 5: return "h5";
148
+ case 6: return "h6";
149
+ default: return "h1";
150
+ }
151
+ }
152
+ /**
153
+ * Convert heading to Portable Text block
154
+ */
155
+ function convertHeading(node) {
156
+ const { children, markDefs } = convertInlineContent(node.content || []);
157
+ const style = headingLevelToStyle(typeof node.attrs?.level === "number" ? node.attrs.level : 1);
158
+ if (children.length === 0) return null;
159
+ return {
160
+ _type: "block",
161
+ _key: generateKey(),
162
+ style,
163
+ children,
164
+ markDefs: markDefs.length > 0 ? markDefs : void 0
165
+ };
166
+ }
167
+ /**
168
+ * Convert list to Portable Text blocks
169
+ */
170
+ function convertList$1(node, listItem) {
171
+ const blocks = [];
172
+ for (const item of node.content || []) if (item.type === "listItem") {
173
+ const itemBlocks = convertListItem$1(item, listItem, 1);
174
+ blocks.push(...itemBlocks);
175
+ }
176
+ return blocks;
177
+ }
178
+ /**
179
+ * Convert list item to Portable Text blocks
180
+ */
181
+ function convertListItem$1(item, listItem, level) {
182
+ const blocks = [];
183
+ for (const child of item.content || []) if (child.type === "paragraph") {
184
+ const { children, markDefs } = convertInlineContent(child.content || []);
185
+ if (children.length > 0) blocks.push({
186
+ _type: "block",
187
+ _key: generateKey(),
188
+ style: "normal",
189
+ listItem,
190
+ level,
191
+ children,
192
+ markDefs: markDefs.length > 0 ? markDefs : void 0
193
+ });
194
+ } else if (child.type === "bulletList") blocks.push(...convertListItemNested(child, "bullet", level + 1));
195
+ else if (child.type === "orderedList") blocks.push(...convertListItemNested(child, "number", level + 1));
196
+ return blocks;
197
+ }
198
+ /**
199
+ * Convert nested list
200
+ */
201
+ function convertListItemNested(node, listItem, level) {
202
+ const blocks = [];
203
+ for (const item of node.content || []) if (item.type === "listItem") blocks.push(...convertListItem$1(item, listItem, level));
204
+ return blocks;
205
+ }
206
+ /**
207
+ * Convert blockquote to Portable Text blocks
208
+ */
209
+ function convertBlockquote(node) {
210
+ const blocks = [];
211
+ for (const child of node.content || []) if (child.type === "paragraph") {
212
+ const { children, markDefs } = convertInlineContent(child.content || []);
213
+ if (children.length > 0) blocks.push({
214
+ _type: "block",
215
+ _key: generateKey(),
216
+ style: "blockquote",
217
+ children,
218
+ markDefs: markDefs.length > 0 ? markDefs : void 0
219
+ });
220
+ }
221
+ return blocks.length === 1 ? blocks[0] : blocks.length > 0 ? blocks : null;
222
+ }
223
+ /**
224
+ * Convert code block to Portable Text
225
+ */
226
+ function convertCodeBlock$1(node) {
227
+ const code = node.content?.map((n) => n.text || "").join("") || "";
228
+ const language = typeof node.attrs?.language === "string" ? node.attrs.language : void 0;
229
+ return {
230
+ _type: "code",
231
+ _key: generateKey(),
232
+ code,
233
+ language: language || void 0
234
+ };
235
+ }
236
+ /**
237
+ * Convert image to Portable Text
238
+ */
239
+ function convertImage$1(node) {
240
+ const attrs = node.attrs;
241
+ const provider = typeof attrs?.provider === "string" ? attrs.provider : void 0;
242
+ const mediaId = typeof attrs?.mediaId === "string" ? attrs.mediaId : void 0;
243
+ const src = typeof attrs?.src === "string" ? attrs.src : "";
244
+ const alt = typeof attrs?.alt === "string" ? attrs.alt : void 0;
245
+ const title = typeof attrs?.title === "string" ? attrs.title : void 0;
246
+ const width = typeof attrs?.width === "number" ? attrs.width : void 0;
247
+ const height = typeof attrs?.height === "number" ? attrs.height : void 0;
248
+ const displayWidth = typeof attrs?.displayWidth === "number" ? attrs.displayWidth : void 0;
249
+ const displayHeight = typeof attrs?.displayHeight === "number" ? attrs.displayHeight : void 0;
250
+ return {
251
+ _type: "image",
252
+ _key: generateKey(),
253
+ asset: {
254
+ _ref: mediaId || src || "",
255
+ url: src || "",
256
+ provider: provider && provider !== "local" ? provider : void 0
257
+ },
258
+ alt: alt || void 0,
259
+ caption: title || void 0,
260
+ width: width || void 0,
261
+ height: height || void 0,
262
+ displayWidth: displayWidth || void 0,
263
+ displayHeight: displayHeight || void 0
264
+ };
265
+ }
266
+ /**
267
+ * Convert inline content (text nodes with marks) to Portable Text spans
268
+ */
269
+ function convertInlineContent(nodes) {
270
+ const children = [];
271
+ const markDefs = [];
272
+ const markDefMap = /* @__PURE__ */ new Map();
273
+ for (const node of nodes) if (node.type === "text" && node.text) {
274
+ const marks = [];
275
+ for (const mark of node.marks || []) {
276
+ const markType = convertMark(mark, markDefs, markDefMap);
277
+ if (markType) marks.push(markType);
278
+ }
279
+ children.push({
280
+ _type: "span",
281
+ _key: generateKey(),
282
+ text: node.text,
283
+ marks: marks.length > 0 ? marks : void 0
284
+ });
285
+ } else if (node.type === "hardBreak") if (children.length > 0) {
286
+ const lastChild = children.at(-1);
287
+ lastChild.text += "\n";
288
+ } else children.push({
289
+ _type: "span",
290
+ _key: generateKey(),
291
+ text: "\n"
292
+ });
293
+ if (children.length === 0) children.push({
294
+ _type: "span",
295
+ _key: generateKey(),
296
+ text: ""
297
+ });
298
+ return {
299
+ children,
300
+ markDefs
301
+ };
302
+ }
303
+ /**
304
+ * Convert a ProseMirror mark to Portable Text mark
305
+ */
306
+ function convertMark(mark, markDefs, markDefMap) {
307
+ switch (mark.type) {
308
+ case "bold":
309
+ case "strong": return "strong";
310
+ case "italic":
311
+ case "em": return "em";
312
+ case "underline": return "underline";
313
+ case "strike":
314
+ case "strikethrough": return "strike-through";
315
+ case "code": return "code";
316
+ case "link": {
317
+ const href = (typeof mark.attrs?.href === "string" ? mark.attrs.href : "") || "";
318
+ if (markDefMap.has(href)) return markDefMap.get(href);
319
+ const key = generateKey();
320
+ markDefs.push({
321
+ _type: "link",
322
+ _key: key,
323
+ href,
324
+ blank: mark.attrs?.target === "_blank"
325
+ });
326
+ markDefMap.set(href, key);
327
+ return key;
328
+ }
329
+ default: return mark.type;
330
+ }
331
+ }
332
+
333
+ //#endregion
334
+ //#region src/content/converters/portable-text-to-prosemirror.ts
335
+ /**
336
+ * Convert Portable Text to ProseMirror document
337
+ */
338
+ function portableTextToProsemirror(blocks) {
339
+ if (!blocks || blocks.length === 0) return {
340
+ type: "doc",
341
+ content: [{ type: "paragraph" }]
342
+ };
343
+ const content = [];
344
+ let i = 0;
345
+ while (i < blocks.length) {
346
+ const block = blocks[i];
347
+ if (isTextBlock(block) && block.listItem) {
348
+ const listBlocks = [];
349
+ const listType = block.listItem;
350
+ while (i < blocks.length) {
351
+ const current = blocks[i];
352
+ if (isTextBlock(current) && current.listItem === listType) {
353
+ listBlocks.push(current);
354
+ i++;
355
+ } else break;
356
+ }
357
+ content.push(convertList(listBlocks, listType));
358
+ } else {
359
+ const converted = convertBlock(block);
360
+ if (converted) content.push(converted);
361
+ i++;
362
+ }
363
+ }
364
+ return {
365
+ type: "doc",
366
+ content: content.length > 0 ? content : [{ type: "paragraph" }]
367
+ };
368
+ }
369
+ /**
370
+ * Type guard for text blocks
371
+ */
372
+ function isTextBlock(block) {
373
+ return block._type === "block";
374
+ }
375
+ /**
376
+ * Type guard for image blocks.
377
+ * Checks both `_type` and that `asset` is a valid object — image blocks
378
+ * without an `asset` wrapper (e.g. `{ _type: "image", url: "..." }`) are
379
+ * malformed and should not be cast to `PortableTextImageBlock`.
380
+ */
381
+ function isImageBlock(block) {
382
+ return block._type === "image" && "asset" in block && typeof block.asset === "object" && block.asset !== null;
383
+ }
384
+ /**
385
+ * Type guard for code blocks
386
+ */
387
+ function isCodeBlock(block) {
388
+ return block._type === "code";
389
+ }
390
+ /**
391
+ * Convert a single Portable Text block to ProseMirror node
392
+ */
393
+ function convertBlock(block) {
394
+ if (isTextBlock(block)) return convertTextBlock(block);
395
+ if (isImageBlock(block)) return convertImage(block);
396
+ if (block._type === "image") return convertMalformedImage(block);
397
+ if (isCodeBlock(block)) return convertCodeBlock(block);
398
+ if (block._type === "break") return { type: "horizontalRule" };
399
+ return {
400
+ type: "paragraph",
401
+ content: [{
402
+ type: "text",
403
+ text: `[Unknown block type: ${block._type}]`,
404
+ marks: [{ type: "code" }]
405
+ }]
406
+ };
407
+ }
408
+ /**
409
+ * Convert text block to ProseMirror paragraph or heading
410
+ */
411
+ function convertTextBlock(block) {
412
+ const { style = "normal", children, markDefs = [] } = block;
413
+ const content = convertSpans(children, markDefs);
414
+ switch (style) {
415
+ case "h1":
416
+ case "h2":
417
+ case "h3":
418
+ case "h4":
419
+ case "h5":
420
+ case "h6": return {
421
+ type: "heading",
422
+ attrs: { level: parseInt(style.substring(1), 10) },
423
+ content: content.length > 0 ? content : void 0
424
+ };
425
+ case "blockquote": return {
426
+ type: "blockquote",
427
+ content: [{
428
+ type: "paragraph",
429
+ content: content.length > 0 ? content : void 0
430
+ }]
431
+ };
432
+ default: return {
433
+ type: "paragraph",
434
+ content: content.length > 0 ? content : void 0
435
+ };
436
+ }
437
+ }
438
+ /**
439
+ * Convert list items to ProseMirror list
440
+ */
441
+ function convertList(items, listType) {
442
+ const rootItems = [];
443
+ let i = 0;
444
+ while (i < items.length) {
445
+ const item = items[i];
446
+ if ((item.level || 1) === 1) {
447
+ const nestedItems = [];
448
+ i++;
449
+ while (i < items.length && (items[i].level || 1) > 1) {
450
+ nestedItems.push(items[i]);
451
+ i++;
452
+ }
453
+ rootItems.push(convertListItem(item, nestedItems, listType));
454
+ } else {
455
+ rootItems.push(convertListItem(item, [], listType));
456
+ i++;
457
+ }
458
+ }
459
+ return {
460
+ type: listType === "bullet" ? "bulletList" : "orderedList",
461
+ content: rootItems
462
+ };
463
+ }
464
+ /**
465
+ * Convert a single list item to ProseMirror
466
+ */
467
+ function convertListItem(item, nestedItems, parentListType) {
468
+ const content = [];
469
+ const spans = convertSpans(item.children, item.markDefs || []);
470
+ content.push({
471
+ type: "paragraph",
472
+ content: spans.length > 0 ? spans : void 0
473
+ });
474
+ if (nestedItems.length > 0) {
475
+ let j = 0;
476
+ while (j < nestedItems.length) {
477
+ const nestedListType = nestedItems[j].listItem || parentListType;
478
+ const nestedGroup = [];
479
+ while (j < nestedItems.length && (nestedItems[j].listItem || parentListType) === nestedListType) {
480
+ nestedGroup.push(nestedItems[j]);
481
+ j++;
482
+ }
483
+ if (nestedGroup.length > 0) {
484
+ const adjustedGroup = nestedGroup.map((ni) => ({
485
+ ...ni,
486
+ level: (ni.level || 2) - 1
487
+ }));
488
+ content.push(convertList(adjustedGroup, nestedListType));
489
+ }
490
+ }
491
+ }
492
+ return {
493
+ type: "listItem",
494
+ content
495
+ };
496
+ }
497
+ /**
498
+ * Convert Portable Text spans to ProseMirror text nodes
499
+ */
500
+ function convertSpans(spans, markDefs) {
501
+ const nodes = [];
502
+ const markDefsMap = new Map(markDefs.map((md) => [md._key, md]));
503
+ for (const span of spans) {
504
+ if (span._type !== "span") continue;
505
+ const parts = span.text.split("\n");
506
+ for (let i = 0; i < parts.length; i++) {
507
+ const text = parts[i];
508
+ if (text.length > 0) {
509
+ const marks = convertMarks(span.marks || [], markDefsMap);
510
+ const node = {
511
+ type: "text",
512
+ text
513
+ };
514
+ if (marks.length > 0) node.marks = marks;
515
+ nodes.push(node);
516
+ }
517
+ if (i < parts.length - 1) nodes.push({ type: "hardBreak" });
518
+ }
519
+ }
520
+ return nodes;
521
+ }
522
+ /**
523
+ * Convert Portable Text marks to ProseMirror marks
524
+ */
525
+ function convertMarks(marks, markDefs) {
526
+ const pmMarks = [];
527
+ for (const mark of marks) switch (mark) {
528
+ case "strong":
529
+ pmMarks.push({ type: "bold" });
530
+ break;
531
+ case "em":
532
+ pmMarks.push({ type: "italic" });
533
+ break;
534
+ case "underline":
535
+ pmMarks.push({ type: "underline" });
536
+ break;
537
+ case "strike-through":
538
+ pmMarks.push({ type: "strike" });
539
+ break;
540
+ case "code":
541
+ pmMarks.push({ type: "code" });
542
+ break;
543
+ default: {
544
+ const markDef = markDefs.get(mark);
545
+ if (markDef) if (markDef._type === "link") pmMarks.push({
546
+ type: "link",
547
+ attrs: {
548
+ href: markDef.href,
549
+ target: markDef.blank ? "_blank" : null
550
+ }
551
+ });
552
+ else pmMarks.push({
553
+ type: markDef._type,
554
+ attrs: markDef
555
+ });
556
+ break;
557
+ }
558
+ }
559
+ return pmMarks;
560
+ }
561
+ /**
562
+ * Convert image block to ProseMirror
563
+ */
564
+ function convertImage(block) {
565
+ return {
566
+ type: "image",
567
+ attrs: {
568
+ src: block.asset.url || block.asset._ref,
569
+ alt: block.alt || "",
570
+ title: block.caption || "",
571
+ mediaId: block.asset._ref,
572
+ provider: block.asset.provider,
573
+ width: block.width,
574
+ height: block.height,
575
+ displayWidth: block.displayWidth,
576
+ displayHeight: block.displayHeight
577
+ }
578
+ };
579
+ }
580
+ /**
581
+ * Convert a malformed image block (missing `asset` wrapper) to ProseMirror.
582
+ * Handles blocks like `{ _type: "image", url: "...", alt: "..." }` that may
583
+ * originate from migrations or third-party imports.
584
+ */
585
+ function convertMalformedImage(block) {
586
+ return {
587
+ type: "image",
588
+ attrs: {
589
+ src: "url" in block && typeof block.url === "string" ? block.url : "",
590
+ alt: "alt" in block && typeof block.alt === "string" ? block.alt : "",
591
+ title: "caption" in block && typeof block.caption === "string" ? block.caption : "",
592
+ mediaId: void 0,
593
+ provider: void 0,
594
+ width: "width" in block && typeof block.width === "number" ? block.width : void 0,
595
+ height: "height" in block && typeof block.height === "number" ? block.height : void 0,
596
+ displayWidth: "displayWidth" in block && typeof block.displayWidth === "number" ? block.displayWidth : void 0,
597
+ displayHeight: "displayHeight" in block && typeof block.displayHeight === "number" ? block.displayHeight : void 0
598
+ }
599
+ };
600
+ }
601
+ /**
602
+ * Convert code block to ProseMirror
603
+ */
604
+ function convertCodeBlock(block) {
605
+ return {
606
+ type: "codeBlock",
607
+ attrs: { language: block.language || null },
608
+ content: block.code ? [{
609
+ type: "text",
610
+ text: block.code
611
+ }] : void 0
612
+ };
613
+ }
614
+
615
+ //#endregion
616
+ //#region src/after.ts
617
+ function after(fn) {
618
+ Promise.resolve().then(fn).catch((error) => {
619
+ console.error("[dineway] deferred task failed:", error);
620
+ });
621
+ }
622
+
623
+ //#endregion
624
+ //#region src/plugins/define-plugin.ts
625
+ const SIMPLE_ID = /^[a-z0-9-]+$/;
626
+ const SCOPED_ID = /^@[a-z0-9-]+\/[a-z0-9-]+$/;
627
+ const SEMVER_PATTERN = /^\d+\.\d+\.\d+/;
628
+ function definePlugin(definition) {
629
+ if (!("id" in definition) || !("version" in definition)) {
630
+ if (!("hooks" in definition) && !("routes" in definition)) throw new Error("Standard plugin format requires at least `hooks` or `routes`. For native format, provide `id` and `version`.");
631
+ return definition;
632
+ }
633
+ return defineNativePlugin(definition);
634
+ }
635
+ /**
636
+ * Internal: define a native-format plugin with full validation and normalization.
637
+ */
638
+ function defineNativePlugin(definition) {
639
+ const { id, version, capabilities = [], allowedHosts = [], hooks = {}, routes = {}, admin = {} } = definition;
640
+ const storage = definition.storage ?? {};
641
+ 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").`);
642
+ if (!SEMVER_PATTERN.test(version)) throw new Error(`Invalid plugin version "${version}". Must be semver format (e.g., "1.0.0").`);
643
+ const validCapabilities = new Set([
644
+ "network:request",
645
+ "network:request:unrestricted",
646
+ "content:read",
647
+ "content:write",
648
+ "media:read",
649
+ "media:write",
650
+ "users:read",
651
+ "email:send",
652
+ "hooks.email-transport:register",
653
+ "hooks.email-events:register",
654
+ "hooks.page-fragments:register"
655
+ ]);
656
+ for (const cap of capabilities) if (!validCapabilities.has(cap)) throw new Error(`Invalid capability "${cap}" in plugin "${id}".`);
657
+ const normalizedCapabilities = [...capabilities];
658
+ if (capabilities.includes("content:write") && !capabilities.includes("content:read")) normalizedCapabilities.push("content:read");
659
+ if (capabilities.includes("media:write") && !capabilities.includes("media:read")) normalizedCapabilities.push("media:read");
660
+ if (capabilities.includes("network:request:unrestricted") && !capabilities.includes("network:request")) normalizedCapabilities.push("network:request");
661
+ return {
662
+ id,
663
+ version,
664
+ capabilities: normalizedCapabilities,
665
+ allowedHosts,
666
+ storage,
667
+ hooks: resolveHooks(hooks, id),
668
+ routes,
669
+ admin
670
+ };
671
+ }
672
+ /**
673
+ * Resolve hooks to normalized format with defaults.
674
+ *
675
+ * PluginHooks and ResolvedPluginHooks share the same keys — each input value is
676
+ * `HookConfig<H> | H` and the output is `ResolvedHook<H>`. TS can't narrow
677
+ * the handler type through a dynamic key, so we assert at the loop boundary.
678
+ */
679
+ function resolveHooks(hooks, pluginId) {
680
+ const resolved = {};
681
+ for (const key of Object.keys(hooks)) {
682
+ const hook = hooks[key];
683
+ if (hook) resolved[key] = resolveHook(hook, pluginId);
684
+ }
685
+ return resolved;
686
+ }
687
+ /**
688
+ * Check if a hook value is a config object (has a `handler` property)
689
+ */
690
+ function isHookConfig(hook) {
691
+ return typeof hook === "object" && hook !== null && "handler" in hook;
692
+ }
693
+ /**
694
+ * Resolve a single hook to normalized format
695
+ */
696
+ function resolveHook(hook, pluginId) {
697
+ if (isHookConfig(hook)) {
698
+ if (hook.exclusive !== void 0 && typeof hook.exclusive !== "boolean") throw new Error(`Invalid "exclusive" value in hook config for plugin "${pluginId}". Must be boolean.`);
699
+ return {
700
+ priority: hook.priority ?? 100,
701
+ timeout: hook.timeout ?? 5e3,
702
+ dependencies: hook.dependencies ?? [],
703
+ errorPolicy: hook.errorPolicy ?? "abort",
704
+ exclusive: hook.exclusive ?? false,
705
+ handler: hook.handler,
706
+ pluginId
707
+ };
708
+ }
709
+ return {
710
+ priority: 100,
711
+ timeout: 5e3,
712
+ dependencies: [],
713
+ errorPolicy: "abort",
714
+ exclusive: false,
715
+ handler: hook,
716
+ pluginId
717
+ };
718
+ }
719
+
720
+ //#endregion
721
+ //#region src/plugins/hooks.ts
722
+ /**
723
+ * Plugin Hooks System v2
724
+ *
725
+ * Uses the unified PluginContext for all hooks.
726
+ * Manages lifecycle hooks with:
727
+ * - Deterministic ordering via priority + dependencies
728
+ * - Timeout enforcement
729
+ * - Error isolation
730
+ * - Observability
731
+ *
732
+ */
733
+ /**
734
+ * Hook pipeline for executing hooks in order
735
+ */
736
+ var HookPipeline = class HookPipeline {
737
+ hooks = /* @__PURE__ */ new Map();
738
+ pluginMap = /* @__PURE__ */ new Map();
739
+ contextFactory = null;
740
+ /** Stored so setContextFactory can merge incrementally. */
741
+ contextFactoryOptions = {};
742
+ /** Hook names where at least one handler declared exclusive: true */
743
+ exclusiveHookNames = /* @__PURE__ */ new Set();
744
+ /**
745
+ * Selected provider plugin ID for each exclusive hook.
746
+ * Set by the PluginManager after resolution.
747
+ */
748
+ exclusiveSelections = /* @__PURE__ */ new Map();
749
+ constructor(plugins, factoryOptions) {
750
+ if (factoryOptions) {
751
+ this.contextFactory = new PluginContextFactory(factoryOptions);
752
+ this.contextFactoryOptions = { ...factoryOptions };
753
+ }
754
+ for (const plugin of plugins) this.pluginMap.set(plugin.id, plugin);
755
+ this.registerPlugins(plugins);
756
+ }
757
+ /**
758
+ * Set or update the context factory options.
759
+ *
760
+ * When called on a pipeline that already has a factory, the new options
761
+ * are merged on top of the existing ones so that callers don't need to
762
+ * repeat every field (e.g. adding `cronReschedule` without losing
763
+ * `storage` / `getUploadUrl`).
764
+ */
765
+ setContextFactory(options) {
766
+ const merged = {
767
+ ...this.contextFactoryOptions,
768
+ ...options
769
+ };
770
+ this.contextFactory = new PluginContextFactory(merged);
771
+ this.contextFactoryOptions = merged;
772
+ }
773
+ /**
774
+ * Get context for a plugin
775
+ */
776
+ getContext(pluginId) {
777
+ const plugin = this.pluginMap.get(pluginId);
778
+ if (!plugin) throw new Error(`Plugin "${pluginId}" not found`);
779
+ if (!this.contextFactory) throw new Error("Context factory not initialized - call setContextFactory first");
780
+ return this.contextFactory.createContext(plugin);
781
+ }
782
+ /**
783
+ * Get typed hooks for a specific hook name.
784
+ * The internal map stores ResolvedHook<unknown>, but we know each name
785
+ * maps to a specific handler type via HookHandlerMap.
786
+ *
787
+ * Exclusive hooks that have a selected provider are filtered out — they
788
+ * should only run via invokeExclusiveHook(), not in the regular pipeline.
789
+ */
790
+ getTypedHooks(name) {
791
+ const all = this.hooks.get(name) ?? [];
792
+ if (this.exclusiveSelections.has(name)) return all.filter((h) => !h.exclusive);
793
+ return all;
794
+ }
795
+ /**
796
+ * Register all hooks from plugins.
797
+ *
798
+ * Registers each hook name individually to preserve type safety. The
799
+ * internal map stores ResolvedHook<unknown> since it's keyed by string,
800
+ * but getTypedHooks() restores the correct handler type on retrieval.
801
+ */
802
+ registerPlugins(plugins) {
803
+ for (const plugin of plugins) {
804
+ this.registerPluginHook(plugin, "plugin:install");
805
+ this.registerPluginHook(plugin, "plugin:activate");
806
+ this.registerPluginHook(plugin, "plugin:deactivate");
807
+ this.registerPluginHook(plugin, "plugin:uninstall");
808
+ this.registerPluginHook(plugin, "content:beforeSave");
809
+ this.registerPluginHook(plugin, "content:afterSave");
810
+ this.registerPluginHook(plugin, "content:beforeDelete");
811
+ this.registerPluginHook(plugin, "content:afterDelete");
812
+ this.registerPluginHook(plugin, "content:afterPublish");
813
+ this.registerPluginHook(plugin, "content:afterUnpublish");
814
+ this.registerPluginHook(plugin, "media:beforeUpload");
815
+ this.registerPluginHook(plugin, "media:afterUpload");
816
+ this.registerPluginHook(plugin, "cron");
817
+ this.registerPluginHook(plugin, "email:beforeSend");
818
+ this.registerPluginHook(plugin, "email:deliver");
819
+ this.registerPluginHook(plugin, "email:afterSend");
820
+ this.registerPluginHook(plugin, "comment:beforeCreate");
821
+ this.registerPluginHook(plugin, "comment:moderate");
822
+ this.registerPluginHook(plugin, "comment:afterCreate");
823
+ this.registerPluginHook(plugin, "comment:afterModerate");
824
+ this.registerPluginHook(plugin, "page:metadata");
825
+ this.registerPluginHook(plugin, "page:fragments");
826
+ }
827
+ for (const [hookName, hooks] of this.hooks) this.hooks.set(hookName, this.sortHooks(hooks));
828
+ }
829
+ /**
830
+ * Maps hook names to the capability required to register them.
831
+ *
832
+ * Hooks not listed here have no capability requirement (e.g. lifecycle
833
+ * hooks, cron). Any plugin declaring a listed hook without the required
834
+ * capability will have that hook silently skipped at registration time.
835
+ */
836
+ static HOOK_REQUIRED_CAPABILITY = new Map([
837
+ ["email:beforeSend", "hooks.email-events:register"],
838
+ ["email:afterSend", "hooks.email-events:register"],
839
+ ["email:deliver", "hooks.email-transport:register"],
840
+ ["content:beforeSave", "content:write"],
841
+ ["content:afterSave", "content:read"],
842
+ ["content:beforeDelete", "content:read"],
843
+ ["content:afterDelete", "content:read"],
844
+ ["content:afterPublish", "content:read"],
845
+ ["content:afterUnpublish", "content:read"],
846
+ ["media:beforeUpload", "media:write"],
847
+ ["media:afterUpload", "media:read"],
848
+ ["comment:beforeCreate", "users:read"],
849
+ ["comment:moderate", "users:read"],
850
+ ["comment:afterCreate", "users:read"],
851
+ ["comment:afterModerate", "users:read"],
852
+ ["page:fragments", "hooks.page-fragments:register"]
853
+ ]);
854
+ /**
855
+ * Register a single plugin's hook by name
856
+ */
857
+ registerPluginHook(plugin, name) {
858
+ const hook = plugin.hooks[name];
859
+ if (!hook) return;
860
+ const requiredCapability = HookPipeline.HOOK_REQUIRED_CAPABILITY.get(name);
861
+ if (requiredCapability && !plugin.capabilities.includes(requiredCapability)) {
862
+ console.warn(`[hooks] Plugin "${plugin.id}" declares ${name} hook without ${requiredCapability} capability — skipping`);
863
+ return;
864
+ }
865
+ if (hook.exclusive) this.exclusiveHookNames.add(name);
866
+ this.registerHook(name, hook);
867
+ }
868
+ /**
869
+ * Register a single hook
870
+ */
871
+ registerHook(name, hook) {
872
+ const existing = this.hooks.get(name) || [];
873
+ existing.push(hook);
874
+ this.hooks.set(name, existing);
875
+ }
876
+ /**
877
+ * Sort hooks by priority and dependencies
878
+ */
879
+ sortHooks(hooks) {
880
+ const sorted = [];
881
+ const remaining = [...hooks];
882
+ while (remaining.length > 0) {
883
+ const ready = remaining.filter((hook) => hook.dependencies.every((dep) => sorted.some((s) => s.pluginId === dep)));
884
+ if (ready.length === 0) {
885
+ const pluginIds = remaining.map((hook) => hook.pluginId).join(", ");
886
+ console.warn(`[hooks] Hook dependency cycle or missing dependency detected among plugins: ${pluginIds}. Falling back to priority order.`);
887
+ remaining.sort((a, b) => a.priority - b.priority);
888
+ sorted.push(...remaining);
889
+ break;
890
+ }
891
+ ready.sort((a, b) => a.priority - b.priority);
892
+ const next = ready[0];
893
+ sorted.push(next);
894
+ remaining.splice(remaining.indexOf(next), 1);
895
+ }
896
+ return sorted;
897
+ }
898
+ /**
899
+ * Execute a hook with timeout
900
+ */
901
+ async executeWithTimeout(fn, timeout) {
902
+ let timer;
903
+ const timeoutPromise = new Promise((_, reject) => {
904
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Hook timeout after ${timeout}ms`)), timeout);
905
+ });
906
+ try {
907
+ return await Promise.race([fn(), timeoutPromise]);
908
+ } finally {
909
+ if (timer) clearTimeout(timer);
910
+ }
911
+ }
912
+ /**
913
+ * Run plugin:install hooks
914
+ */
915
+ async runPluginInstall(pluginId) {
916
+ return this.runLifecycleHook("plugin:install", pluginId);
917
+ }
918
+ /**
919
+ * Run plugin:activate hooks
920
+ */
921
+ async runPluginActivate(pluginId) {
922
+ return this.runLifecycleHook("plugin:activate", pluginId);
923
+ }
924
+ /**
925
+ * Run plugin:deactivate hooks
926
+ */
927
+ async runPluginDeactivate(pluginId) {
928
+ return this.runLifecycleHook("plugin:deactivate", pluginId);
929
+ }
930
+ /**
931
+ * Run plugin:uninstall hooks
932
+ */
933
+ async runPluginUninstall(pluginId, deleteData) {
934
+ const hooks = this.getTypedHooks("plugin:uninstall");
935
+ const results = [];
936
+ const hook = hooks.find((h) => h.pluginId === pluginId);
937
+ if (!hook) return results;
938
+ const { handler } = hook;
939
+ const event = { deleteData };
940
+ const ctx = this.getContext(pluginId);
941
+ const start = Date.now();
942
+ try {
943
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
944
+ results.push({
945
+ success: true,
946
+ pluginId: hook.pluginId,
947
+ duration: Date.now() - start
948
+ });
949
+ } catch (error) {
950
+ results.push({
951
+ success: false,
952
+ error: error instanceof Error ? error : new Error(String(error)),
953
+ pluginId: hook.pluginId,
954
+ duration: Date.now() - start
955
+ });
956
+ }
957
+ return results;
958
+ }
959
+ async runLifecycleHook(hookName, pluginId) {
960
+ const hooks = this.getTypedHooks(hookName);
961
+ const results = [];
962
+ const hook = hooks.find((h) => h.pluginId === pluginId);
963
+ if (!hook) return results;
964
+ const { handler } = hook;
965
+ const event = {};
966
+ const ctx = this.getContext(pluginId);
967
+ const start = Date.now();
968
+ try {
969
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
970
+ results.push({
971
+ success: true,
972
+ pluginId: hook.pluginId,
973
+ duration: Date.now() - start
974
+ });
975
+ } catch (error) {
976
+ results.push({
977
+ success: false,
978
+ error: error instanceof Error ? error : new Error(String(error)),
979
+ pluginId: hook.pluginId,
980
+ duration: Date.now() - start
981
+ });
982
+ }
983
+ return results;
984
+ }
985
+ /**
986
+ * Run content:beforeSave hooks
987
+ * Returns modified content from the pipeline
988
+ */
989
+ async runContentBeforeSave(content, collection, isNew) {
990
+ const hooks = this.getTypedHooks("content:beforeSave");
991
+ const results = [];
992
+ let currentContent = content;
993
+ for (const hook of hooks) {
994
+ const { handler } = hook;
995
+ const event = {
996
+ content: currentContent,
997
+ collection,
998
+ isNew
999
+ };
1000
+ const ctx = this.getContext(hook.pluginId);
1001
+ const start = Date.now();
1002
+ try {
1003
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1004
+ if (result !== void 0) currentContent = result;
1005
+ results.push({
1006
+ success: true,
1007
+ value: currentContent,
1008
+ pluginId: hook.pluginId,
1009
+ duration: Date.now() - start
1010
+ });
1011
+ } catch (error) {
1012
+ results.push({
1013
+ success: false,
1014
+ error: error instanceof Error ? error : new Error(String(error)),
1015
+ pluginId: hook.pluginId,
1016
+ duration: Date.now() - start
1017
+ });
1018
+ if (hook.errorPolicy === "abort") throw error;
1019
+ }
1020
+ }
1021
+ return {
1022
+ content: currentContent,
1023
+ results
1024
+ };
1025
+ }
1026
+ /**
1027
+ * Run content:afterSave hooks
1028
+ */
1029
+ async runContentAfterSave(content, collection, isNew) {
1030
+ const hooks = this.getTypedHooks("content:afterSave");
1031
+ const results = [];
1032
+ for (const hook of hooks) {
1033
+ const { handler } = hook;
1034
+ const event = {
1035
+ content,
1036
+ collection,
1037
+ isNew
1038
+ };
1039
+ const ctx = this.getContext(hook.pluginId);
1040
+ const start = Date.now();
1041
+ try {
1042
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1043
+ results.push({
1044
+ success: true,
1045
+ pluginId: hook.pluginId,
1046
+ duration: Date.now() - start
1047
+ });
1048
+ } catch (error) {
1049
+ results.push({
1050
+ success: false,
1051
+ error: error instanceof Error ? error : new Error(String(error)),
1052
+ pluginId: hook.pluginId,
1053
+ duration: Date.now() - start
1054
+ });
1055
+ if (hook.errorPolicy === "abort") throw error;
1056
+ }
1057
+ }
1058
+ return results;
1059
+ }
1060
+ /**
1061
+ * Run content:beforeDelete hooks
1062
+ * Returns whether deletion is allowed
1063
+ */
1064
+ async runContentBeforeDelete(id, collection) {
1065
+ const hooks = this.getTypedHooks("content:beforeDelete");
1066
+ const results = [];
1067
+ let allowed = true;
1068
+ for (const hook of hooks) {
1069
+ const { handler } = hook;
1070
+ const event = {
1071
+ id,
1072
+ collection,
1073
+ permanent: false
1074
+ };
1075
+ const ctx = this.getContext(hook.pluginId);
1076
+ const start = Date.now();
1077
+ try {
1078
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1079
+ if (result === false) allowed = false;
1080
+ results.push({
1081
+ success: true,
1082
+ value: result !== false,
1083
+ pluginId: hook.pluginId,
1084
+ duration: Date.now() - start
1085
+ });
1086
+ } catch (error) {
1087
+ results.push({
1088
+ success: false,
1089
+ error: error instanceof Error ? error : new Error(String(error)),
1090
+ pluginId: hook.pluginId,
1091
+ duration: Date.now() - start
1092
+ });
1093
+ if (hook.errorPolicy === "abort") throw error;
1094
+ }
1095
+ }
1096
+ return {
1097
+ allowed,
1098
+ results
1099
+ };
1100
+ }
1101
+ /**
1102
+ * Run content:afterDelete hooks
1103
+ */
1104
+ async runContentAfterDelete(id, collection, permanent) {
1105
+ const hooks = this.getTypedHooks("content:afterDelete");
1106
+ const results = [];
1107
+ for (const hook of hooks) {
1108
+ const { handler } = hook;
1109
+ const event = {
1110
+ id,
1111
+ collection,
1112
+ permanent
1113
+ };
1114
+ const ctx = this.getContext(hook.pluginId);
1115
+ const start = Date.now();
1116
+ try {
1117
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1118
+ results.push({
1119
+ success: true,
1120
+ pluginId: hook.pluginId,
1121
+ duration: Date.now() - start
1122
+ });
1123
+ } catch (error) {
1124
+ results.push({
1125
+ success: false,
1126
+ error: error instanceof Error ? error : new Error(String(error)),
1127
+ pluginId: hook.pluginId,
1128
+ duration: Date.now() - start
1129
+ });
1130
+ if (hook.errorPolicy === "abort") throw error;
1131
+ }
1132
+ }
1133
+ return results;
1134
+ }
1135
+ /**
1136
+ * Run content:afterPublish hooks (fire-and-forget).
1137
+ */
1138
+ async runContentAfterPublish(content, collection) {
1139
+ const hooks = this.getTypedHooks("content:afterPublish");
1140
+ const results = [];
1141
+ for (const hook of hooks) {
1142
+ const { handler } = hook;
1143
+ const event = {
1144
+ content,
1145
+ collection
1146
+ };
1147
+ const ctx = this.getContext(hook.pluginId);
1148
+ const start = Date.now();
1149
+ try {
1150
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1151
+ results.push({
1152
+ success: true,
1153
+ pluginId: hook.pluginId,
1154
+ duration: Date.now() - start
1155
+ });
1156
+ } catch (error) {
1157
+ results.push({
1158
+ success: false,
1159
+ error: error instanceof Error ? error : new Error(String(error)),
1160
+ pluginId: hook.pluginId,
1161
+ duration: Date.now() - start
1162
+ });
1163
+ if (hook.errorPolicy === "abort") throw error;
1164
+ }
1165
+ }
1166
+ return results;
1167
+ }
1168
+ /**
1169
+ * Run content:afterUnpublish hooks (fire-and-forget).
1170
+ */
1171
+ async runContentAfterUnpublish(content, collection) {
1172
+ const hooks = this.getTypedHooks("content:afterUnpublish");
1173
+ const results = [];
1174
+ for (const hook of hooks) {
1175
+ const { handler } = hook;
1176
+ const event = {
1177
+ content,
1178
+ collection
1179
+ };
1180
+ const ctx = this.getContext(hook.pluginId);
1181
+ const start = Date.now();
1182
+ try {
1183
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1184
+ results.push({
1185
+ success: true,
1186
+ pluginId: hook.pluginId,
1187
+ duration: Date.now() - start
1188
+ });
1189
+ } catch (error) {
1190
+ results.push({
1191
+ success: false,
1192
+ error: error instanceof Error ? error : new Error(String(error)),
1193
+ pluginId: hook.pluginId,
1194
+ duration: Date.now() - start
1195
+ });
1196
+ if (hook.errorPolicy === "abort") throw error;
1197
+ }
1198
+ }
1199
+ return results;
1200
+ }
1201
+ /**
1202
+ * Run media:beforeUpload hooks
1203
+ */
1204
+ async runMediaBeforeUpload(file) {
1205
+ const hooks = this.getTypedHooks("media:beforeUpload");
1206
+ const results = [];
1207
+ let currentFile = file;
1208
+ for (const hook of hooks) {
1209
+ const { handler } = hook;
1210
+ const event = { file: currentFile };
1211
+ const ctx = this.getContext(hook.pluginId);
1212
+ const start = Date.now();
1213
+ try {
1214
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1215
+ if (result !== void 0) currentFile = result;
1216
+ results.push({
1217
+ success: true,
1218
+ value: currentFile,
1219
+ pluginId: hook.pluginId,
1220
+ duration: Date.now() - start
1221
+ });
1222
+ } catch (error) {
1223
+ results.push({
1224
+ success: false,
1225
+ error: error instanceof Error ? error : new Error(String(error)),
1226
+ pluginId: hook.pluginId,
1227
+ duration: Date.now() - start
1228
+ });
1229
+ if (hook.errorPolicy === "abort") throw error;
1230
+ }
1231
+ }
1232
+ return {
1233
+ file: currentFile,
1234
+ results
1235
+ };
1236
+ }
1237
+ /**
1238
+ * Run media:afterUpload hooks
1239
+ */
1240
+ async runMediaAfterUpload(media) {
1241
+ const hooks = this.getTypedHooks("media:afterUpload");
1242
+ const results = [];
1243
+ for (const hook of hooks) {
1244
+ const { handler } = hook;
1245
+ const event = { media };
1246
+ const ctx = this.getContext(hook.pluginId);
1247
+ const start = Date.now();
1248
+ try {
1249
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1250
+ results.push({
1251
+ success: true,
1252
+ pluginId: hook.pluginId,
1253
+ duration: Date.now() - start
1254
+ });
1255
+ } catch (error) {
1256
+ results.push({
1257
+ success: false,
1258
+ error: error instanceof Error ? error : new Error(String(error)),
1259
+ pluginId: hook.pluginId,
1260
+ duration: Date.now() - start
1261
+ });
1262
+ if (hook.errorPolicy === "abort") throw error;
1263
+ }
1264
+ }
1265
+ return results;
1266
+ }
1267
+ /**
1268
+ * Invoke the cron hook for a specific plugin.
1269
+ *
1270
+ * Unlike other hooks which broadcast to all plugins, the cron hook is
1271
+ * dispatched only to the target plugin — the one that owns the task.
1272
+ */
1273
+ async invokeCronHook(pluginId, event) {
1274
+ const hook = this.getTypedHooks("cron").find((h) => h.pluginId === pluginId);
1275
+ if (!hook) return {
1276
+ success: false,
1277
+ error: /* @__PURE__ */ new Error(`Plugin "${pluginId}" has no cron hook registered`),
1278
+ pluginId,
1279
+ duration: 0
1280
+ };
1281
+ const { handler } = hook;
1282
+ const ctx = this.getContext(pluginId);
1283
+ const start = Date.now();
1284
+ try {
1285
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1286
+ return {
1287
+ success: true,
1288
+ pluginId,
1289
+ duration: Date.now() - start
1290
+ };
1291
+ } catch (error) {
1292
+ return {
1293
+ success: false,
1294
+ error: error instanceof Error ? error : new Error(String(error)),
1295
+ pluginId,
1296
+ duration: Date.now() - start
1297
+ };
1298
+ }
1299
+ }
1300
+ /**
1301
+ * Run email:beforeSend hooks (middleware pipeline).
1302
+ *
1303
+ * Each handler receives the message and returns a modified message or
1304
+ * `false` to cancel delivery. The pipeline chains message transformations —
1305
+ * each handler receives the output of the previous one.
1306
+ */
1307
+ async runEmailBeforeSend(message, source) {
1308
+ const hooks = this.getTypedHooks("email:beforeSend");
1309
+ const results = [];
1310
+ let currentMessage = message;
1311
+ for (const hook of hooks) {
1312
+ const { handler } = hook;
1313
+ const event = {
1314
+ message: { ...currentMessage },
1315
+ source
1316
+ };
1317
+ const ctx = this.getContext(hook.pluginId);
1318
+ const start = Date.now();
1319
+ try {
1320
+ const result = await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1321
+ if (result === false) {
1322
+ results.push({
1323
+ success: true,
1324
+ value: false,
1325
+ pluginId: hook.pluginId,
1326
+ duration: Date.now() - start
1327
+ });
1328
+ return {
1329
+ message: false,
1330
+ results
1331
+ };
1332
+ }
1333
+ if (result && typeof result === "object") currentMessage = result;
1334
+ results.push({
1335
+ success: true,
1336
+ value: currentMessage,
1337
+ pluginId: hook.pluginId,
1338
+ duration: Date.now() - start
1339
+ });
1340
+ } catch (error) {
1341
+ results.push({
1342
+ success: false,
1343
+ error: error instanceof Error ? error : new Error(String(error)),
1344
+ pluginId: hook.pluginId,
1345
+ duration: Date.now() - start
1346
+ });
1347
+ if (hook.errorPolicy === "abort") throw error;
1348
+ }
1349
+ }
1350
+ return {
1351
+ message: currentMessage,
1352
+ results
1353
+ };
1354
+ }
1355
+ /**
1356
+ * Run email:afterSend hooks (fire-and-forget).
1357
+ *
1358
+ * Errors are logged but don't propagate — they don't affect the caller.
1359
+ */
1360
+ async runEmailAfterSend(message, source) {
1361
+ const hooks = this.getTypedHooks("email:afterSend");
1362
+ const results = [];
1363
+ for (const hook of hooks) {
1364
+ const { handler } = hook;
1365
+ const event = {
1366
+ message,
1367
+ source
1368
+ };
1369
+ const ctx = this.getContext(hook.pluginId);
1370
+ const start = Date.now();
1371
+ try {
1372
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1373
+ results.push({
1374
+ success: true,
1375
+ pluginId: hook.pluginId,
1376
+ duration: Date.now() - start
1377
+ });
1378
+ } catch (error) {
1379
+ console.error(`[email:afterSend] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
1380
+ results.push({
1381
+ success: false,
1382
+ error: error instanceof Error ? error : new Error(String(error)),
1383
+ pluginId: hook.pluginId,
1384
+ duration: Date.now() - start
1385
+ });
1386
+ }
1387
+ }
1388
+ return results;
1389
+ }
1390
+ /**
1391
+ * Run comment:beforeCreate hooks (middleware pipeline).
1392
+ *
1393
+ * Each handler receives the event and returns a modified event or
1394
+ * `false` to reject the comment. The pipeline chains transformations —
1395
+ * each handler receives the output of the previous one.
1396
+ */
1397
+ async runCommentBeforeCreate(event) {
1398
+ const hooks = this.getTypedHooks("comment:beforeCreate");
1399
+ let currentEvent = event;
1400
+ for (const hook of hooks) {
1401
+ const { handler } = hook;
1402
+ const ctx = this.getContext(hook.pluginId);
1403
+ const start = Date.now();
1404
+ try {
1405
+ const result = await this.executeWithTimeout(() => handler({ ...currentEvent }, ctx), hook.timeout);
1406
+ if (result === false) return false;
1407
+ if (result && typeof result === "object") currentEvent = result;
1408
+ } catch (error) {
1409
+ console.error(`[comment:beforeCreate] Plugin "${hook.pluginId}" error (${Date.now() - start}ms):`, error instanceof Error ? error.message : error);
1410
+ if (hook.errorPolicy === "abort") throw error;
1411
+ }
1412
+ }
1413
+ return currentEvent;
1414
+ }
1415
+ /**
1416
+ * Run comment:afterCreate hooks (fire-and-forget).
1417
+ *
1418
+ * Errors are logged but don't propagate — they don't affect the caller.
1419
+ */
1420
+ async runCommentAfterCreate(event) {
1421
+ const hooks = this.getTypedHooks("comment:afterCreate");
1422
+ for (const hook of hooks) {
1423
+ const { handler } = hook;
1424
+ const ctx = this.getContext(hook.pluginId);
1425
+ try {
1426
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1427
+ } catch (error) {
1428
+ console.error(`[comment:afterCreate] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
1429
+ }
1430
+ }
1431
+ }
1432
+ /**
1433
+ * Run comment:afterModerate hooks (fire-and-forget).
1434
+ *
1435
+ * Errors are logged but don't propagate — they don't affect the caller.
1436
+ */
1437
+ async runCommentAfterModerate(event) {
1438
+ const hooks = this.getTypedHooks("comment:afterModerate");
1439
+ for (const hook of hooks) {
1440
+ const { handler } = hook;
1441
+ const ctx = this.getContext(hook.pluginId);
1442
+ try {
1443
+ await this.executeWithTimeout(() => handler(event, ctx), hook.timeout);
1444
+ } catch (error) {
1445
+ console.error(`[comment:afterModerate] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
1446
+ }
1447
+ }
1448
+ }
1449
+ /**
1450
+ * Run page:metadata hooks. Each handler returns contributions that are
1451
+ * merged by the metadata collector. Errors are logged but don't propagate.
1452
+ */
1453
+ async runPageMetadata(event) {
1454
+ const hooks = this.getTypedHooks("page:metadata");
1455
+ const results = [];
1456
+ for (const hook of hooks) {
1457
+ const { handler } = hook;
1458
+ const ctx = this.getContext(hook.pluginId);
1459
+ try {
1460
+ const result = await this.executeWithTimeout(() => Promise.resolve(handler(event, ctx)), hook.timeout);
1461
+ if (result != null) {
1462
+ const contributions = Array.isArray(result) ? result : [result];
1463
+ results.push({
1464
+ pluginId: hook.pluginId,
1465
+ contributions
1466
+ });
1467
+ }
1468
+ } catch (error) {
1469
+ console.error(`[page:metadata] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
1470
+ }
1471
+ }
1472
+ return results;
1473
+ }
1474
+ /**
1475
+ * Run page:fragments hooks. Only trusted plugins should be registered
1476
+ * for this hook. Errors are logged but don't propagate.
1477
+ */
1478
+ async runPageFragments(event) {
1479
+ const hooks = this.getTypedHooks("page:fragments");
1480
+ const results = [];
1481
+ for (const hook of hooks) {
1482
+ const { handler } = hook;
1483
+ const ctx = this.getContext(hook.pluginId);
1484
+ try {
1485
+ const result = await this.executeWithTimeout(() => Promise.resolve(handler(event, ctx)), hook.timeout);
1486
+ if (result != null) {
1487
+ const contributions = Array.isArray(result) ? result : [result];
1488
+ results.push({
1489
+ pluginId: hook.pluginId,
1490
+ contributions
1491
+ });
1492
+ }
1493
+ } catch (error) {
1494
+ console.error(`[page:fragments] Plugin "${hook.pluginId}" error:`, error instanceof Error ? error.message : error);
1495
+ }
1496
+ }
1497
+ return results;
1498
+ }
1499
+ /**
1500
+ * Check if any hooks are registered for a given name
1501
+ */
1502
+ hasHooks(name) {
1503
+ const hooks = this.hooks.get(name);
1504
+ return hooks !== void 0 && hooks.length > 0;
1505
+ }
1506
+ /**
1507
+ * Get hook count for debugging
1508
+ */
1509
+ getHookCount(name) {
1510
+ return this.hooks.get(name)?.length || 0;
1511
+ }
1512
+ /**
1513
+ * Get all registered hook names
1514
+ */
1515
+ getRegisteredHooks() {
1516
+ return [...this.hooks.keys()];
1517
+ }
1518
+ /**
1519
+ * Returns hook names where at least one handler declared exclusive: true
1520
+ */
1521
+ getRegisteredExclusiveHooks() {
1522
+ return [...this.exclusiveHookNames];
1523
+ }
1524
+ /**
1525
+ * Check if a hook is exclusive
1526
+ */
1527
+ isExclusiveHook(name) {
1528
+ return this.exclusiveHookNames.has(name);
1529
+ }
1530
+ /**
1531
+ * Set the selected provider for an exclusive hook.
1532
+ * Called by PluginManager after resolution.
1533
+ */
1534
+ setExclusiveSelection(hookName, pluginId) {
1535
+ this.exclusiveSelections.set(hookName, pluginId);
1536
+ }
1537
+ /**
1538
+ * Clear the selected provider for an exclusive hook.
1539
+ */
1540
+ clearExclusiveSelection(hookName) {
1541
+ this.exclusiveSelections.delete(hookName);
1542
+ }
1543
+ /**
1544
+ * Get the selected provider for an exclusive hook (if any).
1545
+ */
1546
+ getExclusiveSelection(hookName) {
1547
+ return this.exclusiveSelections.get(hookName);
1548
+ }
1549
+ /**
1550
+ * Get all plugins that registered a handler for a given exclusive hook.
1551
+ */
1552
+ getExclusiveHookProviders(hookName) {
1553
+ return (this.hooks.get(hookName) ?? []).filter((h) => h.exclusive).map((h) => ({ pluginId: h.pluginId }));
1554
+ }
1555
+ /**
1556
+ * Get all plugins that registered a non-exclusive handler for a given hook,
1557
+ * preserving priority order. This partitions with getExclusiveHookProviders().
1558
+ */
1559
+ getHookProviders(hookName) {
1560
+ return (this.hooks.get(hookName) ?? []).filter((h) => !h.exclusive).map((h) => ({ pluginId: h.pluginId }));
1561
+ }
1562
+ /**
1563
+ * Invoke an exclusive hook — dispatch only to the selected provider.
1564
+ * Returns null if no provider is selected or if the selected hook
1565
+ * is not found in the pipeline.
1566
+ *
1567
+ * This is a generic dispatch used by the email pipeline and other
1568
+ * exclusive hook consumers. The handler type is unknown — callers
1569
+ * must know the expected signature.
1570
+ *
1571
+ * Errors are isolated: a failing handler returns an error result
1572
+ * instead of propagating the exception to the caller.
1573
+ */
1574
+ async invokeExclusiveHook(hookName, event) {
1575
+ const selectedPluginId = this.exclusiveSelections.get(hookName);
1576
+ if (!selectedPluginId) return null;
1577
+ const hook = (this.hooks.get(hookName) ?? []).find((h) => h.pluginId === selectedPluginId && h.exclusive);
1578
+ if (!hook) return null;
1579
+ const start = Date.now();
1580
+ try {
1581
+ const ctx = this.getContext(selectedPluginId);
1582
+ const handler = hook.handler;
1583
+ return {
1584
+ result: await this.executeWithTimeout(() => handler(event, ctx), hook.timeout),
1585
+ pluginId: selectedPluginId,
1586
+ duration: Date.now() - start
1587
+ };
1588
+ } catch (error) {
1589
+ return {
1590
+ result: void 0,
1591
+ pluginId: selectedPluginId,
1592
+ error: error instanceof Error ? error : new Error(String(error)),
1593
+ duration: Date.now() - start
1594
+ };
1595
+ }
1596
+ }
1597
+ };
1598
+ /**
1599
+ * Create a hook pipeline from plugins
1600
+ */
1601
+ function createHookPipeline(plugins, factoryOptions) {
1602
+ return new HookPipeline(plugins, factoryOptions);
1603
+ }
1604
+ /** Options table key prefix for exclusive hook selections */
1605
+ const EXCLUSIVE_HOOK_KEY_PREFIX$1 = "dineway:exclusive_hook:";
1606
+ /**
1607
+ * Resolve exclusive hook selections.
1608
+ *
1609
+ * Shared algorithm used by both PluginManager and DinewayRuntime:
1610
+ * 1. If a DB selection exists and that plugin is active → keep it.
1611
+ * 2. If DB selection is stale (plugin inactive/gone) → clear it.
1612
+ * 3. If no selection and only one active provider → auto-select it.
1613
+ * 4. If preferred hints match an active provider → first match wins.
1614
+ * 5. If multiple providers and no hint → leave unselected (admin must choose).
1615
+ */
1616
+ async function resolveExclusiveHooks(opts) {
1617
+ const { pipeline, isActive, getOption, setOption, deleteOption, preferredHints } = opts;
1618
+ const exclusiveHookNames = pipeline.getRegisteredExclusiveHooks();
1619
+ for (const hookName of exclusiveHookNames) {
1620
+ const providers = pipeline.getExclusiveHookProviders(hookName);
1621
+ const activeProviderIds = new Set(providers.map((p) => p.pluginId).filter((id) => isActive(id)));
1622
+ const key = `${EXCLUSIVE_HOOK_KEY_PREFIX$1}${hookName}`;
1623
+ let currentSelection = null;
1624
+ try {
1625
+ currentSelection = await getOption(key);
1626
+ } catch {
1627
+ continue;
1628
+ }
1629
+ if (currentSelection && activeProviderIds.has(currentSelection)) {
1630
+ pipeline.setExclusiveSelection(hookName, currentSelection);
1631
+ continue;
1632
+ }
1633
+ if (currentSelection) try {
1634
+ await deleteOption(key);
1635
+ } catch {}
1636
+ if (activeProviderIds.size === 1) {
1637
+ const [onlyProvider] = activeProviderIds;
1638
+ try {
1639
+ await setOption(key, onlyProvider);
1640
+ } catch {}
1641
+ pipeline.setExclusiveSelection(hookName, onlyProvider);
1642
+ continue;
1643
+ }
1644
+ if (preferredHints) {
1645
+ let found = false;
1646
+ for (const [pluginId, hooks] of preferredHints) if (hooks.includes(hookName) && activeProviderIds.has(pluginId)) {
1647
+ try {
1648
+ await setOption(key, pluginId);
1649
+ } catch {}
1650
+ pipeline.setExclusiveSelection(hookName, pluginId);
1651
+ found = true;
1652
+ break;
1653
+ }
1654
+ if (found) continue;
1655
+ }
1656
+ pipeline.clearExclusiveSelection(hookName);
1657
+ }
1658
+ }
1659
+
1660
+ //#endregion
1661
+ //#region src/plugins/email.ts
1662
+ /**
1663
+ * Email Pipeline
1664
+ *
1665
+ * Orchestrates the three-stage email pipeline:
1666
+ * 1. email:beforeSend hooks (middleware — transform, validate, cancel)
1667
+ * 2. email:deliver hook (exclusive — exactly one provider delivers)
1668
+ * 3. email:afterSend hooks (logging, analytics, fire-and-forget)
1669
+ *
1670
+ * Security features:
1671
+ * - Recursion guard prevents re-entrant sends (e.g. plugin calling ctx.email.send from a hook)
1672
+ * - System emails (source="system") bypass email:beforeSend and email:afterSend hooks entirely
1673
+ * to protect auth tokens from exfiltration by plugin hooks
1674
+ *
1675
+ */
1676
+ /** Hook name for the exclusive email delivery hook */
1677
+ const EMAIL_DELIVER_HOOK = "email:deliver";
1678
+ /** Source value used for auth emails (magic links, invites, password resets) */
1679
+ const SYSTEM_SOURCE = "system";
1680
+ /**
1681
+ * Error thrown when ctx.email.send() is called but no provider is configured.
1682
+ */
1683
+ var EmailNotConfiguredError = class extends Error {
1684
+ constructor() {
1685
+ super("No email provider is configured. Install and activate an email provider plugin, then select it in Settings > Email.");
1686
+ this.name = "EmailNotConfiguredError";
1687
+ }
1688
+ };
1689
+ /**
1690
+ * Error thrown when a recursive email send is detected.
1691
+ */
1692
+ var EmailRecursionError = class extends Error {
1693
+ constructor() {
1694
+ super("Recursive email send detected. A plugin hook attempted to send an email from within the email pipeline, which would cause infinite recursion.");
1695
+ this.name = "EmailRecursionError";
1696
+ }
1697
+ };
1698
+ /**
1699
+ * Recursion guard using AsyncLocalStorage.
1700
+ *
1701
+ * EmailPipeline is a singleton (worker-lifetime cached via DinewayRuntime).
1702
+ * Instance state like `sendDepth` would false-positive under concurrent
1703
+ * requests because two unrelated sends would increment the same counter.
1704
+ * ALS scopes the guard to the current async execution context, so concurrent
1705
+ * requests each get their own independent recursion tracking.
1706
+ */
1707
+ const emailSendALS = new AsyncLocalStorage();
1708
+ /**
1709
+ * EmailPipeline orchestrates email delivery through the plugin hook system.
1710
+ *
1711
+ * The pipeline runs in three stages:
1712
+ * 1. email:beforeSend — middleware hooks that can transform or cancel messages
1713
+ * 2. email:deliver — exclusive hook dispatching to the selected provider
1714
+ * 3. email:afterSend — fire-and-forget hooks for logging/analytics
1715
+ */
1716
+ var EmailPipeline = class {
1717
+ pipeline;
1718
+ constructor(pipeline) {
1719
+ this.pipeline = pipeline;
1720
+ }
1721
+ /**
1722
+ * Replace the underlying hook pipeline.
1723
+ *
1724
+ * Called by the runtime when rebuilding the hook pipeline after a
1725
+ * plugin is enabled or disabled, so the email pipeline dispatches
1726
+ * to the current set of active hooks.
1727
+ */
1728
+ setPipeline(pipeline) {
1729
+ this.pipeline = pipeline;
1730
+ }
1731
+ /**
1732
+ * Send an email through the full pipeline.
1733
+ *
1734
+ * @param message - The email to send
1735
+ * @param source - Where the email originated ("system" for auth, plugin ID for plugins)
1736
+ * @throws EmailNotConfiguredError if no provider is selected
1737
+ * @throws EmailRecursionError if called re-entrantly from within a hook
1738
+ * @throws Error if the provider handler throws
1739
+ */
1740
+ async send(message, source) {
1741
+ const store = emailSendALS.getStore();
1742
+ if (store && store.depth > 0) throw new EmailRecursionError();
1743
+ const run = () => this.sendInner(message, source);
1744
+ if (store) {
1745
+ store.depth++;
1746
+ try {
1747
+ await run();
1748
+ } finally {
1749
+ store.depth--;
1750
+ }
1751
+ } else await emailSendALS.run({ depth: 1 }, run);
1752
+ }
1753
+ /**
1754
+ * Inner send implementation, separated from the recursion guard.
1755
+ */
1756
+ async sendInner(message, source) {
1757
+ if (!message || typeof message !== "object") throw new Error("Invalid email message: message must be an object");
1758
+ if (!message.to || typeof message.to !== "string") throw new Error("Invalid email message: 'to' is required and must be a string");
1759
+ if (!message.subject || typeof message.subject !== "string") throw new Error("Invalid email message: 'subject' is required and must be a string");
1760
+ if (!message.text || typeof message.text !== "string") throw new Error("Invalid email message: 'text' is required and must be a string");
1761
+ const isSystemEmail = source === SYSTEM_SOURCE;
1762
+ let finalMessage;
1763
+ if (isSystemEmail) finalMessage = message;
1764
+ else {
1765
+ const beforeResult = await this.pipeline.runEmailBeforeSend(message, source);
1766
+ if (beforeResult.message === false) {
1767
+ const cancelledBy = beforeResult.results.find((r) => r.value === false)?.pluginId ?? "unknown";
1768
+ console.info(`[email] Email to "${message.to}" cancelled by plugin "${cancelledBy}"`);
1769
+ return;
1770
+ }
1771
+ finalMessage = beforeResult.message;
1772
+ }
1773
+ const deliverEvent = {
1774
+ message: finalMessage,
1775
+ source
1776
+ };
1777
+ const deliverResult = await this.pipeline.invokeExclusiveHook(EMAIL_DELIVER_HOOK, deliverEvent);
1778
+ if (!deliverResult) throw new EmailNotConfiguredError();
1779
+ if (deliverResult.error) throw deliverResult.error;
1780
+ if (!isSystemEmail) this.pipeline.runEmailAfterSend(finalMessage, source).catch((err) => console.error("[email] afterSend pipeline error:", err instanceof Error ? err.message : err));
1781
+ }
1782
+ /**
1783
+ * Check if an email provider is configured and available.
1784
+ *
1785
+ * Returns true if an email:deliver provider is selected in the exclusive
1786
+ * hook system. Plugins and auth code use this to decide whether to show
1787
+ * "send invite" vs "copy invite link" UI.
1788
+ */
1789
+ isAvailable() {
1790
+ return this.pipeline.getExclusiveSelection(EMAIL_DELIVER_HOOK) !== void 0;
1791
+ }
1792
+ };
1793
+
1794
+ //#endregion
1795
+ //#region src/plugins/routes.ts
1796
+ /**
1797
+ * Plugin Routes v2
1798
+ *
1799
+ * Handles plugin API route invocation with:
1800
+ * - Input validation via Zod schemas
1801
+ * - Route context creation
1802
+ * - Error handling
1803
+ *
1804
+ */
1805
+ /**
1806
+ * Route handler for a plugin
1807
+ */
1808
+ var PluginRouteHandler = class {
1809
+ contextFactory;
1810
+ plugin;
1811
+ trustedProxyHeaders;
1812
+ constructor(plugin, factoryOptions) {
1813
+ this.plugin = plugin;
1814
+ this.contextFactory = new PluginContextFactory(factoryOptions);
1815
+ this.trustedProxyHeaders = factoryOptions.trustedProxyHeaders ?? [];
1816
+ }
1817
+ /**
1818
+ * Invoke a route by name
1819
+ */
1820
+ async invoke(routeName, options) {
1821
+ const route = this.plugin.routes[routeName];
1822
+ if (!route) return {
1823
+ success: false,
1824
+ error: {
1825
+ code: "ROUTE_NOT_FOUND",
1826
+ message: `Route "${routeName}" not found in plugin "${this.plugin.id}"`
1827
+ },
1828
+ status: 404
1829
+ };
1830
+ let validatedInput;
1831
+ if (route.input) {
1832
+ const parseResult = route.input.safeParse(options.body);
1833
+ if (!parseResult.success) return {
1834
+ success: false,
1835
+ error: {
1836
+ code: "VALIDATION_ERROR",
1837
+ message: "Invalid request body",
1838
+ details: parseResult.error.format()
1839
+ },
1840
+ status: 400
1841
+ };
1842
+ validatedInput = parseResult.data;
1843
+ } else validatedInput = options.body;
1844
+ const routeContext = {
1845
+ ...this.contextFactory.createContext(this.plugin),
1846
+ input: validatedInput,
1847
+ request: options.request,
1848
+ requestMeta: extractRequestMeta(options.request, this.trustedProxyHeaders)
1849
+ };
1850
+ try {
1851
+ return {
1852
+ success: true,
1853
+ data: await route.handler(routeContext),
1854
+ status: 200
1855
+ };
1856
+ } catch (error) {
1857
+ if (error instanceof PluginRouteError) return {
1858
+ success: false,
1859
+ error: {
1860
+ code: error.code,
1861
+ message: error.message,
1862
+ details: error.details
1863
+ },
1864
+ status: error.status
1865
+ };
1866
+ console.error(`[plugin:${this.plugin.id}] Route handler failed:`, error);
1867
+ return {
1868
+ success: false,
1869
+ error: {
1870
+ code: "INTERNAL_ERROR",
1871
+ message: "An internal error occurred"
1872
+ },
1873
+ status: 500
1874
+ };
1875
+ }
1876
+ }
1877
+ /**
1878
+ * Get all route names
1879
+ */
1880
+ getRouteNames() {
1881
+ return Object.keys(this.plugin.routes);
1882
+ }
1883
+ /**
1884
+ * Check if a route exists
1885
+ */
1886
+ hasRoute(name) {
1887
+ return name in this.plugin.routes;
1888
+ }
1889
+ /**
1890
+ * Get route metadata without invoking the handler.
1891
+ * Returns null if the route doesn't exist.
1892
+ */
1893
+ getRouteMeta(name) {
1894
+ const route = this.plugin.routes[name];
1895
+ if (!route) return null;
1896
+ return { public: route.public === true };
1897
+ }
1898
+ };
1899
+ /**
1900
+ * Error class for plugin routes
1901
+ * Allows plugins to return structured errors with specific HTTP status codes
1902
+ */
1903
+ var PluginRouteError = class PluginRouteError extends Error {
1904
+ constructor(code, message, status = 400, details) {
1905
+ super(message);
1906
+ this.code = code;
1907
+ this.status = status;
1908
+ this.details = details;
1909
+ this.name = "PluginRouteError";
1910
+ }
1911
+ /**
1912
+ * Create a bad request error (400)
1913
+ */
1914
+ static badRequest(message, details) {
1915
+ return new PluginRouteError("BAD_REQUEST", message, 400, details);
1916
+ }
1917
+ /**
1918
+ * Create an unauthorized error (401)
1919
+ */
1920
+ static unauthorized(message = "Unauthorized") {
1921
+ return new PluginRouteError("UNAUTHORIZED", message, 401);
1922
+ }
1923
+ /**
1924
+ * Create a forbidden error (403)
1925
+ */
1926
+ static forbidden(message = "Forbidden") {
1927
+ return new PluginRouteError("FORBIDDEN", message, 403);
1928
+ }
1929
+ /**
1930
+ * Create a not found error (404)
1931
+ */
1932
+ static notFound(message = "Not found") {
1933
+ return new PluginRouteError("NOT_FOUND", message, 404);
1934
+ }
1935
+ /**
1936
+ * Create a conflict error (409)
1937
+ */
1938
+ static conflict(message, details) {
1939
+ return new PluginRouteError("CONFLICT", message, 409, details);
1940
+ }
1941
+ /**
1942
+ * Create an internal error (500)
1943
+ */
1944
+ static internal(message = "Internal error") {
1945
+ return new PluginRouteError("INTERNAL_ERROR", message, 500);
1946
+ }
1947
+ };
1948
+ /**
1949
+ * Registry for all plugin route handlers
1950
+ */
1951
+ var PluginRouteRegistry = class {
1952
+ handlers = /* @__PURE__ */ new Map();
1953
+ constructor(factoryOptions) {
1954
+ this.factoryOptions = factoryOptions;
1955
+ }
1956
+ /**
1957
+ * Register a plugin's routes
1958
+ */
1959
+ register(plugin) {
1960
+ const handler = new PluginRouteHandler(plugin, this.factoryOptions);
1961
+ this.handlers.set(plugin.id, handler);
1962
+ }
1963
+ /**
1964
+ * Unregister a plugin's routes
1965
+ */
1966
+ unregister(pluginId) {
1967
+ this.handlers.delete(pluginId);
1968
+ }
1969
+ /**
1970
+ * Invoke a plugin route
1971
+ */
1972
+ async invoke(pluginId, routeName, options) {
1973
+ const handler = this.handlers.get(pluginId);
1974
+ if (!handler) return {
1975
+ success: false,
1976
+ error: {
1977
+ code: "PLUGIN_NOT_FOUND",
1978
+ message: `Plugin "${pluginId}" not found`
1979
+ },
1980
+ status: 404
1981
+ };
1982
+ return handler.invoke(routeName, options);
1983
+ }
1984
+ /**
1985
+ * Get all registered plugin IDs
1986
+ */
1987
+ getPluginIds() {
1988
+ return [...this.handlers.keys()];
1989
+ }
1990
+ /**
1991
+ * Get routes for a plugin
1992
+ */
1993
+ getRoutes(pluginId) {
1994
+ return this.handlers.get(pluginId)?.getRouteNames() ?? [];
1995
+ }
1996
+ /**
1997
+ * Get route metadata for a specific plugin route.
1998
+ * Returns null if the plugin or route doesn't exist.
1999
+ */
2000
+ getRouteMeta(pluginId, routeName) {
2001
+ const handler = this.handlers.get(pluginId);
2002
+ if (!handler) return null;
2003
+ return handler.getRouteMeta(routeName);
2004
+ }
2005
+ };
2006
+
2007
+ //#endregion
2008
+ //#region src/plugins/manager.ts
2009
+ /** Options table key prefix for exclusive hook DB reads via PluginManager */
2010
+ const EXCLUSIVE_HOOK_KEY_PREFIX = "dineway:exclusive_hook:";
2011
+ /**
2012
+ * Plugin Manager v2
2013
+ *
2014
+ * Manages the full lifecycle of plugins and coordinates hooks/routes.
2015
+ */
2016
+ var PluginManager = class {
2017
+ plugins = /* @__PURE__ */ new Map();
2018
+ hookPipeline = null;
2019
+ routeRegistry = null;
2020
+ factoryOptions;
2021
+ initialized = false;
2022
+ constructor(options) {
2023
+ this.options = options;
2024
+ this.factoryOptions = {
2025
+ db: options.db,
2026
+ storage: options.storage,
2027
+ getUploadUrl: options.getUploadUrl,
2028
+ trustedProxyHeaders: options.trustedProxyHeaders
2029
+ };
2030
+ }
2031
+ /**
2032
+ * Set the email pipeline used when creating plugin contexts.
2033
+ * Reinitializes routes/hooks if already initialized so ctx.email is available immediately.
2034
+ */
2035
+ setEmailPipeline(pipeline) {
2036
+ this.factoryOptions.emailPipeline = pipeline;
2037
+ if (this.initialized) this.reinitialize();
2038
+ }
2039
+ /**
2040
+ * Register a plugin definition
2041
+ * This resolves the definition and adds it to the manager, but doesn't install it
2042
+ */
2043
+ register(definition) {
2044
+ const resolved = definePlugin(definition);
2045
+ if (this.plugins.has(resolved.id)) throw new Error(`Plugin "${resolved.id}" is already registered`);
2046
+ this.plugins.set(resolved.id, {
2047
+ plugin: resolved,
2048
+ state: "registered"
2049
+ });
2050
+ this.initialized = false;
2051
+ return resolved;
2052
+ }
2053
+ /**
2054
+ * Register multiple plugins
2055
+ */
2056
+ registerAll(definitions) {
2057
+ for (const def of definitions) this.register(def);
2058
+ }
2059
+ /**
2060
+ * Unregister a plugin
2061
+ * Plugin must be inactive or just registered
2062
+ */
2063
+ unregister(pluginId) {
2064
+ const entry = this.plugins.get(pluginId);
2065
+ if (!entry) return false;
2066
+ if (entry.state === "active") throw new Error(`Cannot unregister active plugin "${pluginId}". Deactivate it first.`);
2067
+ this.plugins.delete(pluginId);
2068
+ this.initialized = false;
2069
+ return true;
2070
+ }
2071
+ /**
2072
+ * Install a plugin (run install hooks, set up storage)
2073
+ */
2074
+ async install(pluginId) {
2075
+ const entry = this.plugins.get(pluginId);
2076
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2077
+ if (entry.state !== "registered") throw new Error(`Plugin "${pluginId}" is already installed (state: ${entry.state})`);
2078
+ this.ensureInitialized();
2079
+ const results = await this.hookPipeline.runPluginInstall(pluginId);
2080
+ const failed = results.find((r) => !r.success);
2081
+ if (failed) throw new Error(`Plugin install failed: ${failed.error?.message ?? "Unknown error"}`);
2082
+ entry.state = "installed";
2083
+ return results;
2084
+ }
2085
+ /**
2086
+ * Activate a plugin (run activate hooks, enable hooks/routes)
2087
+ */
2088
+ async activate(pluginId) {
2089
+ const entry = this.plugins.get(pluginId);
2090
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2091
+ if (entry.state === "active") return [];
2092
+ if (entry.state === "registered") await this.install(pluginId);
2093
+ this.ensureInitialized();
2094
+ const results = await this.hookPipeline.runPluginActivate(pluginId);
2095
+ const failed = results.find((r) => !r.success);
2096
+ if (failed) throw new Error(`Plugin activation failed: ${failed.error?.message ?? "Unknown error"}`);
2097
+ entry.state = "active";
2098
+ await setCronTasksEnabled(this.options.db, pluginId, true);
2099
+ this.reinitialize();
2100
+ await this.resolveExclusiveHooks();
2101
+ return results;
2102
+ }
2103
+ /**
2104
+ * Deactivate a plugin (run deactivate hooks, disable hooks/routes)
2105
+ */
2106
+ async deactivate(pluginId) {
2107
+ const entry = this.plugins.get(pluginId);
2108
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2109
+ if (entry.state !== "active") return [];
2110
+ this.ensureInitialized();
2111
+ const results = await this.hookPipeline.runPluginDeactivate(pluginId);
2112
+ await setCronTasksEnabled(this.options.db, pluginId, false);
2113
+ entry.state = "inactive";
2114
+ this.reinitialize();
2115
+ await this.resolveExclusiveHooks();
2116
+ return results;
2117
+ }
2118
+ /**
2119
+ * Uninstall a plugin (run uninstall hooks, optionally delete data)
2120
+ */
2121
+ async uninstall(pluginId, deleteData = false) {
2122
+ const entry = this.plugins.get(pluginId);
2123
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2124
+ if (entry.state === "active") await this.deactivate(pluginId);
2125
+ this.ensureInitialized();
2126
+ const results = await this.hookPipeline.runPluginUninstall(pluginId, deleteData);
2127
+ await this.deleteCronTasks(pluginId);
2128
+ this.plugins.delete(pluginId);
2129
+ this.initialized = false;
2130
+ await this.resolveExclusiveHooks();
2131
+ return results;
2132
+ }
2133
+ /**
2134
+ * Run content:beforeSave hooks across all active plugins
2135
+ */
2136
+ async runContentBeforeSave(content, collection, isNew) {
2137
+ this.ensureInitialized();
2138
+ return this.hookPipeline.runContentBeforeSave(content, collection, isNew);
2139
+ }
2140
+ /**
2141
+ * Run content:afterSave hooks across all active plugins
2142
+ */
2143
+ async runContentAfterSave(content, collection, isNew) {
2144
+ this.ensureInitialized();
2145
+ return this.hookPipeline.runContentAfterSave(content, collection, isNew);
2146
+ }
2147
+ /**
2148
+ * Run content:beforeDelete hooks across all active plugins
2149
+ */
2150
+ async runContentBeforeDelete(id, collection) {
2151
+ this.ensureInitialized();
2152
+ return this.hookPipeline.runContentBeforeDelete(id, collection);
2153
+ }
2154
+ /**
2155
+ * Run content:afterDelete hooks across all active plugins
2156
+ */
2157
+ async runContentAfterDelete(id, collection, permanent) {
2158
+ this.ensureInitialized();
2159
+ return this.hookPipeline.runContentAfterDelete(id, collection, permanent);
2160
+ }
2161
+ /**
2162
+ * Run content:afterPublish hooks across all active plugins
2163
+ */
2164
+ async runContentAfterPublish(content, collection) {
2165
+ this.ensureInitialized();
2166
+ return this.hookPipeline.runContentAfterPublish(content, collection);
2167
+ }
2168
+ /**
2169
+ * Run content:afterUnpublish hooks across all active plugins
2170
+ */
2171
+ async runContentAfterUnpublish(content, collection) {
2172
+ this.ensureInitialized();
2173
+ return this.hookPipeline.runContentAfterUnpublish(content, collection);
2174
+ }
2175
+ /**
2176
+ * Run media:beforeUpload hooks across all active plugins
2177
+ */
2178
+ async runMediaBeforeUpload(file) {
2179
+ this.ensureInitialized();
2180
+ return this.hookPipeline.runMediaBeforeUpload(file);
2181
+ }
2182
+ /**
2183
+ * Run media:afterUpload hooks across all active plugins
2184
+ */
2185
+ async runMediaAfterUpload(media) {
2186
+ this.ensureInitialized();
2187
+ return this.hookPipeline.runMediaAfterUpload(media);
2188
+ }
2189
+ /**
2190
+ * Invoke the cron hook for a specific plugin (per-plugin dispatch).
2191
+ * Used as the InvokeCronHookFn callback for CronExecutor.
2192
+ */
2193
+ async invokeCronHook(pluginId, event) {
2194
+ this.ensureInitialized();
2195
+ const result = await this.hookPipeline.invokeCronHook(pluginId, event);
2196
+ if (!result.success && result.error) throw result.error;
2197
+ }
2198
+ /**
2199
+ * Invoke a plugin route
2200
+ */
2201
+ async invokeRoute(pluginId, routeName, options) {
2202
+ this.ensureInitialized();
2203
+ return this.routeRegistry.invoke(pluginId, routeName, options);
2204
+ }
2205
+ /**
2206
+ * Get all routes for a plugin
2207
+ */
2208
+ getPluginRoutes(pluginId) {
2209
+ this.ensureInitialized();
2210
+ return this.routeRegistry.getRoutes(pluginId);
2211
+ }
2212
+ /**
2213
+ * Get a plugin by ID
2214
+ */
2215
+ getPlugin(pluginId) {
2216
+ return this.plugins.get(pluginId)?.plugin;
2217
+ }
2218
+ /**
2219
+ * Get plugin state
2220
+ */
2221
+ getPluginState(pluginId) {
2222
+ return this.plugins.get(pluginId)?.state;
2223
+ }
2224
+ /**
2225
+ * Get all registered plugins
2226
+ */
2227
+ getAllPlugins() {
2228
+ return Array.from(this.plugins.values(), (entry) => ({
2229
+ plugin: entry.plugin,
2230
+ state: entry.state
2231
+ }));
2232
+ }
2233
+ /**
2234
+ * Get all active plugins
2235
+ */
2236
+ getActivePlugins() {
2237
+ return [...this.plugins.values()].filter((entry) => entry.state === "active").map((entry) => entry.plugin);
2238
+ }
2239
+ /**
2240
+ * Check if a plugin exists
2241
+ */
2242
+ hasPlugin(pluginId) {
2243
+ return this.plugins.has(pluginId);
2244
+ }
2245
+ /**
2246
+ * Check if a plugin is active
2247
+ */
2248
+ isActive(pluginId) {
2249
+ return this.plugins.get(pluginId)?.state === "active";
2250
+ }
2251
+ /**
2252
+ * Get all plugins that registered a handler for an exclusive hook.
2253
+ */
2254
+ getExclusiveHookProviders(hookName) {
2255
+ this.ensureInitialized();
2256
+ return this.hookPipeline.getExclusiveHookProviders(hookName).map((p) => {
2257
+ const plugin = this.plugins.get(p.pluginId);
2258
+ return {
2259
+ pluginId: p.pluginId,
2260
+ pluginName: plugin?.plugin.id ?? p.pluginId
2261
+ };
2262
+ });
2263
+ }
2264
+ /**
2265
+ * Read the selected provider for an exclusive hook from the options table.
2266
+ */
2267
+ async getExclusiveHookSelection(hookName) {
2268
+ return new OptionsRepository(this.options.db).get(`${EXCLUSIVE_HOOK_KEY_PREFIX}${hookName}`);
2269
+ }
2270
+ /**
2271
+ * Set the selected provider for an exclusive hook in the options table.
2272
+ * Pass null to clear the selection.
2273
+ */
2274
+ async setExclusiveHookSelection(hookName, pluginId) {
2275
+ const optionsRepo = new OptionsRepository(this.options.db);
2276
+ const key = `${EXCLUSIVE_HOOK_KEY_PREFIX}${hookName}`;
2277
+ if (pluginId === null) {
2278
+ await optionsRepo.delete(key);
2279
+ this.hookPipeline?.clearExclusiveSelection(hookName);
2280
+ return;
2281
+ }
2282
+ const entry = this.plugins.get(pluginId);
2283
+ if (!entry) throw new Error(`Plugin "${pluginId}" not found`);
2284
+ if (entry.state !== "active") throw new Error(`Plugin "${pluginId}" is not active`);
2285
+ await optionsRepo.set(key, pluginId);
2286
+ this.hookPipeline?.setExclusiveSelection(hookName, pluginId);
2287
+ }
2288
+ /**
2289
+ * Resolution algorithm for exclusive hooks.
2290
+ *
2291
+ * Delegates to the shared resolveExclusiveHooks() function.
2292
+ * See hooks.ts for the full algorithm description.
2293
+ */
2294
+ async resolveExclusiveHooks(preferredHints) {
2295
+ this.ensureInitialized();
2296
+ const optionsRepo = new OptionsRepository(this.options.db);
2297
+ await resolveExclusiveHooks({
2298
+ pipeline: this.hookPipeline,
2299
+ isActive: (pluginId) => this.isActive(pluginId),
2300
+ getOption: (key) => optionsRepo.get(key),
2301
+ setOption: (key, value) => optionsRepo.set(key, value),
2302
+ deleteOption: async (key) => {
2303
+ await optionsRepo.delete(key);
2304
+ },
2305
+ preferredHints
2306
+ });
2307
+ }
2308
+ /**
2309
+ * Get all exclusive hooks with their providers and current selections.
2310
+ * Used by the admin API.
2311
+ */
2312
+ async getExclusiveHooksInfo() {
2313
+ this.ensureInitialized();
2314
+ const exclusiveHookNames = this.hookPipeline.getRegisteredExclusiveHooks();
2315
+ const result = [];
2316
+ for (const hookName of exclusiveHookNames) {
2317
+ const providers = this.hookPipeline.getExclusiveHookProviders(hookName);
2318
+ const selection = await this.getExclusiveHookSelection(hookName);
2319
+ result.push({
2320
+ hookName,
2321
+ providers,
2322
+ selectedPluginId: selection
2323
+ });
2324
+ }
2325
+ return result;
2326
+ }
2327
+ /**
2328
+ * Initialize or reinitialize the hook pipeline and route registry
2329
+ */
2330
+ ensureInitialized() {
2331
+ if (this.initialized) return;
2332
+ const activePlugins = this.getActivePlugins();
2333
+ this.hookPipeline = new HookPipeline(activePlugins, this.factoryOptions);
2334
+ this.routeRegistry = new PluginRouteRegistry(this.factoryOptions);
2335
+ for (const plugin of activePlugins) this.routeRegistry.register(plugin);
2336
+ this.initialized = true;
2337
+ }
2338
+ /**
2339
+ * Force reinitialization (useful after plugin state changes)
2340
+ */
2341
+ reinitialize() {
2342
+ this.initialized = false;
2343
+ this.ensureInitialized();
2344
+ }
2345
+ /**
2346
+ * Delete all cron tasks for a plugin.
2347
+ * Used during uninstall.
2348
+ */
2349
+ async deleteCronTasks(pluginId) {
2350
+ try {
2351
+ await sql`
2352
+ DELETE FROM _dineway_cron_tasks
2353
+ WHERE plugin_id = ${pluginId}
2354
+ `.execute(this.options.db);
2355
+ } catch {}
2356
+ }
2357
+ };
2358
+ /**
2359
+ * Create a plugin manager
2360
+ */
2361
+ function createPluginManager(options) {
2362
+ return new PluginManager(options);
2363
+ }
2364
+
2365
+ //#endregion
2366
+ //#region src/plugins/sandbox/noop.ts
2367
+ /**
2368
+ * Error thrown when attempting to use sandboxing on an unsupported platform.
2369
+ */
2370
+ var SandboxNotAvailableError = class extends Error {
2371
+ constructor() {
2372
+ super("Plugin sandboxing is not available on this deployment. Marketplace-style plugins require a configured isolated SandboxRunner. Use trusted plugins from config until the portable Node runner lands.");
2373
+ this.name = "SandboxNotAvailableError";
2374
+ }
2375
+ };
2376
+ /**
2377
+ * No-op sandbox runner for platforms without isolation support.
2378
+ *
2379
+ * - `isAvailable()` returns false
2380
+ * - `load()` throws SandboxNotAvailableError
2381
+ * - `terminateAll()` is a no-op
2382
+ *
2383
+ * This is the default runner when no platform adapter is configured.
2384
+ */
2385
+ var NoopSandboxRunner = class {
2386
+ /**
2387
+ * Always returns false - sandboxing is not available.
2388
+ */
2389
+ isAvailable() {
2390
+ return false;
2391
+ }
2392
+ /**
2393
+ * Always throws - can't load sandboxed plugins without isolation.
2394
+ */
2395
+ async load(_manifest, _code) {
2396
+ throw new SandboxNotAvailableError();
2397
+ }
2398
+ /**
2399
+ * No-op - sandboxing not available, email callback is irrelevant.
2400
+ */
2401
+ setEmailSend() {}
2402
+ /**
2403
+ * No-op - nothing to terminate.
2404
+ */
2405
+ async terminateAll() {}
2406
+ };
2407
+ /**
2408
+ * Create a no-op sandbox runner.
2409
+ * This is used as the default when no platform adapter is configured.
2410
+ */
2411
+ function createNoopSandboxRunner(_options) {
2412
+ return new NoopSandboxRunner();
2413
+ }
2414
+
2415
+ //#endregion
2416
+ //#region src/plugins/sandbox/wrapper.ts
2417
+ const COMMENT_CLOSE_RE = /\*\//g;
2418
+ const NEWLINE_RE = /[\n\r]/g;
2419
+ const TRAILING_SLASH_RE = /\/$/;
2420
+ const DEFAULT_PLUGIN_MODULE_SPECIFIER = "sandbox-plugin.js";
2421
+ const DEFAULT_RUNTIME_GLOBAL$1 = "__DINEWAY_SANDBOX__";
2422
+ function generateSandboxWrapper(manifest, options = {}) {
2423
+ const storageCollections = Object.keys(manifest.storage ?? {});
2424
+ const pluginModuleSpecifier = options.pluginModuleSpecifier ?? DEFAULT_PLUGIN_MODULE_SPECIFIER;
2425
+ const runtimeGlobal = options.runtimeGlobal ?? DEFAULT_RUNTIME_GLOBAL$1;
2426
+ const site = options.site ?? {
2427
+ name: "",
2428
+ url: "",
2429
+ locale: "en"
2430
+ };
2431
+ const hasReadContent = manifest.capabilities.includes("content:read") || manifest.capabilities.includes("content:write");
2432
+ const hasWriteContent = manifest.capabilities.includes("content:write");
2433
+ const hasReadMedia = manifest.capabilities.includes("media:read") || manifest.capabilities.includes("media:write");
2434
+ const hasWriteMedia = manifest.capabilities.includes("media:write");
2435
+ const hasHttp = manifest.capabilities.includes("network:request") || manifest.capabilities.includes("network:request:unrestricted");
2436
+ const hasReadUsers = manifest.capabilities.includes("users:read");
2437
+ const hasEmailSend = manifest.capabilities.includes("email:send");
2438
+ return `
2439
+ // =============================================================================
2440
+ // Sandboxed Plugin Wrapper
2441
+ // Plugin: ${sanitizeComment(manifest.id)}@${sanitizeComment(manifest.version)}
2442
+ // =============================================================================
2443
+
2444
+ import pluginModule from ${JSON.stringify(pluginModuleSpecifier)};
2445
+
2446
+ const hooks = pluginModule?.hooks || pluginModule?.default?.hooks || {};
2447
+ const routes = pluginModule?.routes || pluginModule?.default?.routes || {};
2448
+ const storageCollections = ${JSON.stringify(storageCollections)};
2449
+ const fallbackPlugin = ${JSON.stringify({
2450
+ id: manifest.id,
2451
+ version: manifest.version
2452
+ })};
2453
+ const fallbackSite = ${JSON.stringify(site)};
2454
+
2455
+ function getRuntime() {
2456
+ const runtime = globalThis[${JSON.stringify(runtimeGlobal)}];
2457
+ if (!runtime || typeof runtime !== "object") {
2458
+ throw new Error("Sandbox runtime bridge is not configured.");
2459
+ }
2460
+ return runtime;
2461
+ }
2462
+
2463
+ function createHeaders(headerRecord) {
2464
+ const normalized = new Map(
2465
+ Object.entries(headerRecord || {}).map(([key, value]) => [key.toLowerCase(), value]),
2466
+ );
2467
+ return {
2468
+ get(name) {
2469
+ return normalized.get(String(name).toLowerCase()) ?? null;
2470
+ },
2471
+ has(name) {
2472
+ return normalized.has(String(name).toLowerCase());
2473
+ },
2474
+ entries() {
2475
+ return normalized.entries();
2476
+ },
2477
+ keys() {
2478
+ return normalized.keys();
2479
+ },
2480
+ values() {
2481
+ return normalized.values();
2482
+ },
2483
+ forEach(callback) {
2484
+ for (const [key, value] of normalized.entries()) {
2485
+ callback(value, key);
2486
+ }
2487
+ },
2488
+ };
2489
+ }
2490
+
2491
+ function createContext() {
2492
+ const runtime = getRuntime();
2493
+ const bridge = runtime.bridge;
2494
+ const plugin = runtime.plugin || fallbackPlugin;
2495
+ const site = runtime.site || fallbackSite;
2496
+ const siteBaseUrl = String(site.url || "").replace(${TRAILING_SLASH_RE}, "");
2497
+
2498
+ const kv = {
2499
+ get: (key) => bridge.kvGet(key),
2500
+ set: (key, value) => bridge.kvSet(key, value),
2501
+ delete: (key) => bridge.kvDelete(key),
2502
+ list: (prefix) => bridge.kvList(prefix),
2503
+ };
2504
+
2505
+ function createStorageCollection(collectionName) {
2506
+ if (!storageCollections.includes(collectionName)) {
2507
+ throw new Error('Storage collection "' + collectionName + '" is not declared in the plugin manifest.');
2508
+ }
2509
+ return {
2510
+ get: (id) => bridge.storageGet(collectionName, id),
2511
+ put: (id, data) => bridge.storagePut(collectionName, id, data),
2512
+ delete: (id) => bridge.storageDelete(collectionName, id),
2513
+ exists: async (id) => (await bridge.storageGet(collectionName, id)) !== null,
2514
+ query: (options) => bridge.storageQuery(collectionName, options),
2515
+ count: (where) => bridge.storageCount(collectionName, where),
2516
+ getMany: async (ids) => {
2517
+ const items = await bridge.storageGetMany(collectionName, ids);
2518
+ return new Map(items.map((item) => [item.id, item.data]));
2519
+ },
2520
+ putMany: (items) => bridge.storagePutMany(collectionName, items),
2521
+ deleteMany: (ids) => bridge.storageDeleteMany(collectionName, ids),
2522
+ };
2523
+ }
2524
+
2525
+ const storage = new Proxy({}, {
2526
+ get(_, collectionName) {
2527
+ if (typeof collectionName !== "string") return undefined;
2528
+ return createStorageCollection(collectionName);
2529
+ },
2530
+ });
2531
+
2532
+ const content = ${hasReadContent ? `{
2533
+ get: (collection, id) => bridge.contentGet(collection, id),
2534
+ list: (collection, options) => bridge.contentList(collection, options),${hasWriteContent ? `
2535
+ create: (collection, data) => bridge.contentCreate(collection, data),
2536
+ update: (collection, id, data) => bridge.contentUpdate(collection, id, data),
2537
+ delete: (collection, id) => bridge.contentDelete(collection, id),` : ""}
2538
+ }` : "undefined"};
2539
+
2540
+ const media = ${hasReadMedia ? `{
2541
+ get: (id) => bridge.mediaGet(id),
2542
+ list: (options) => bridge.mediaList(options),${hasWriteMedia ? `
2543
+ getUploadUrl: () => {
2544
+ throw new Error("getUploadUrl is not available in sandbox mode. Use media.upload(filename, contentType, bytes) instead.");
2545
+ },
2546
+ upload: (filename, contentType, bytes) => bridge.mediaUpload(filename, contentType, bytes),
2547
+ delete: (id) => bridge.mediaDelete(id),` : ""}
2548
+ }` : "undefined"};
2549
+
2550
+ const http = ${hasHttp ? `{
2551
+ fetch: async (url, init) => {
2552
+ const result = await bridge.httpFetch(url, init);
2553
+ return {
2554
+ status: result.status,
2555
+ ok: result.status >= 200 && result.status < 300,
2556
+ headers: createHeaders(result.headers),
2557
+ text: async () => result.text,
2558
+ json: async () => JSON.parse(result.text),
2559
+ };
2560
+ },
2561
+ }` : "undefined"};
2562
+
2563
+ const log = {
2564
+ debug: (message, data) => bridge.log("debug", message, data),
2565
+ info: (message, data) => bridge.log("info", message, data),
2566
+ warn: (message, data) => bridge.log("warn", message, data),
2567
+ error: (message, data) => bridge.log("error", message, data),
2568
+ };
2569
+
2570
+ const users = ${hasReadUsers ? `{
2571
+ get: (id) => bridge.userGet(id),
2572
+ getByEmail: (email) => bridge.userGetByEmail(email),
2573
+ list: (options) => bridge.userList(options),
2574
+ }` : "undefined"};
2575
+
2576
+ const cron =
2577
+ typeof bridge.cronSchedule === "function" &&
2578
+ typeof bridge.cronCancel === "function" &&
2579
+ typeof bridge.cronList === "function"
2580
+ ? {
2581
+ schedule: (name, options) => bridge.cronSchedule(name, options),
2582
+ cancel: (name) => bridge.cronCancel(name),
2583
+ list: () => bridge.cronList(),
2584
+ }
2585
+ : undefined;
2586
+
2587
+ const email = ${hasEmailSend ? `{
2588
+ send: (message) => bridge.emailSend(message),
2589
+ }` : "undefined"};
2590
+
2591
+ function url(path) {
2592
+ if (!path.startsWith("/")) {
2593
+ throw new Error('URL path must start with "/", got: "' + path + '"');
2594
+ }
2595
+ if (path.startsWith("//")) {
2596
+ throw new Error('URL path must not be protocol-relative, got: "' + path + '"');
2597
+ }
2598
+ return siteBaseUrl + path;
2599
+ }
2600
+
2601
+ return {
2602
+ plugin,
2603
+ storage,
2604
+ kv,
2605
+ content,
2606
+ media,
2607
+ http,
2608
+ log,
2609
+ site,
2610
+ url,
2611
+ users,
2612
+ cron,
2613
+ email,
2614
+ };
2615
+ }
2616
+
2617
+ export async function invokeHook(hookName, event) {
2618
+ const ctx = createContext();
2619
+ const hookDef = hooks[hookName];
2620
+ if (!hookDef) {
2621
+ return undefined;
2622
+ }
2623
+ const handler = typeof hookDef === "function" ? hookDef : hookDef.handler;
2624
+ if (typeof handler !== "function") {
2625
+ throw new Error(\`Hook \${hookName} handler is not a function\`);
2626
+ }
2627
+ return handler(event, ctx);
2628
+ }
2629
+
2630
+ export async function invokeRoute(routeName, input, serializedRequest) {
2631
+ const ctx = createContext();
2632
+ const route = routes[routeName];
2633
+ if (!route) {
2634
+ throw new Error(\`Route not found: \${routeName}\`);
2635
+ }
2636
+ const handler = typeof route === "function" ? route : route.handler;
2637
+ if (typeof handler !== "function") {
2638
+ throw new Error(\`Route \${routeName} handler is not a function\`);
2639
+ }
2640
+ return handler(
2641
+ { input, request: serializedRequest, requestMeta: serializedRequest.meta },
2642
+ ctx,
2643
+ );
2644
+ }
2645
+ `;
2646
+ }
2647
+ function sanitizeComment(value) {
2648
+ return value.replace(NEWLINE_RE, " ").replace(COMMENT_CLOSE_RE, "* /");
2649
+ }
2650
+
2651
+ //#endregion
2652
+ //#region src/plugins/sandbox/node.ts
2653
+ const DEFAULT_RUNTIME_GLOBAL = "__DINEWAY_SANDBOX__";
2654
+ const DEFAULT_LIMITS = {
2655
+ cpuMs: 50,
2656
+ memoryMb: 128,
2657
+ subrequests: 10,
2658
+ wallTimeMs: 3e4
2659
+ };
2660
+ const DINEWAY_SHIM_CODE = "export const definePlugin = (definition) => definition;\nexport default definePlugin;\n";
2661
+ const DINEWAY_STATIC_IMPORT_RE = /\bfrom\s+(['"])dineway\1/g;
2662
+ const DINEWAY_DYNAMIC_IMPORT_RE = /\bimport\(\s*(['"])dineway\1\s*\)/g;
2663
+ const ALL_BRIDGE_METHODS = [
2664
+ "kvGet",
2665
+ "kvSet",
2666
+ "kvDelete",
2667
+ "kvList",
2668
+ "storageGet",
2669
+ "storagePut",
2670
+ "storageDelete",
2671
+ "storageQuery",
2672
+ "storageCount",
2673
+ "storageGetMany",
2674
+ "storagePutMany",
2675
+ "storageDeleteMany",
2676
+ "contentGet",
2677
+ "contentList",
2678
+ "contentCreate",
2679
+ "contentUpdate",
2680
+ "contentDelete",
2681
+ "mediaGet",
2682
+ "mediaList",
2683
+ "mediaUpload",
2684
+ "mediaDelete",
2685
+ "httpFetch",
2686
+ "userGet",
2687
+ "userGetByEmail",
2688
+ "userList",
2689
+ "cronSchedule",
2690
+ "cronCancel",
2691
+ "cronList",
2692
+ "emailSend",
2693
+ "log"
2694
+ ];
2695
+ const WORKER_SOURCE = `
2696
+ const { parentPort, workerData } = require("node:worker_threads");
2697
+
2698
+ function toDataUrl(code) {
2699
+ return "data:text/javascript;base64," + Buffer.from(code, "utf8").toString("base64");
2700
+ }
2701
+
2702
+ function serializeError(error) {
2703
+ if (error && typeof error === "object") {
2704
+ return {
2705
+ message: typeof error.message === "string" ? error.message : String(error),
2706
+ stack: typeof error.stack === "string" ? error.stack : undefined,
2707
+ };
2708
+ }
2709
+ return { message: String(error) };
2710
+ }
2711
+
2712
+ const pendingBridgeCalls = new Map();
2713
+ let nextBridgeCallId = 1;
2714
+
2715
+ function callBridge(method, args) {
2716
+ return new Promise((resolve, reject) => {
2717
+ const id = nextBridgeCallId++;
2718
+ pendingBridgeCalls.set(id, { resolve, reject });
2719
+ parentPort.postMessage({ type: "bridge", id, method, args });
2720
+ });
2721
+ }
2722
+
2723
+ parentPort.on("message", (message) => {
2724
+ if (!message || typeof message !== "object") {
2725
+ return;
2726
+ }
2727
+
2728
+ if (message.type === "bridge-result") {
2729
+ const pending = pendingBridgeCalls.get(message.id);
2730
+ if (!pending) return;
2731
+ pendingBridgeCalls.delete(message.id);
2732
+ pending.resolve(message.value);
2733
+ return;
2734
+ }
2735
+
2736
+ if (message.type === "bridge-error") {
2737
+ const pending = pendingBridgeCalls.get(message.id);
2738
+ if (!pending) return;
2739
+ pendingBridgeCalls.delete(message.id);
2740
+ const error = new Error(
2741
+ message.error && typeof message.error.message === "string"
2742
+ ? message.error.message
2743
+ : "Sandbox bridge call failed",
2744
+ );
2745
+ if (message.error && typeof message.error.stack === "string") {
2746
+ error.stack = message.error.stack;
2747
+ }
2748
+ pending.reject(error);
2749
+ }
2750
+ });
2751
+
2752
+ const bridgeMethods = new Set(workerData.bridgeMethods);
2753
+ const bridge = new Proxy(
2754
+ {},
2755
+ {
2756
+ get(_target, prop) {
2757
+ if (typeof prop !== "string" || !bridgeMethods.has(prop)) {
2758
+ return undefined;
2759
+ }
2760
+ return (...args) => callBridge(prop, args);
2761
+ },
2762
+ },
2763
+ );
2764
+
2765
+ globalThis[workerData.runtimeGlobal] = {
2766
+ bridge,
2767
+ plugin: workerData.plugin,
2768
+ site: workerData.site,
2769
+ };
2770
+
2771
+ (async () => {
2772
+ try {
2773
+ const wrapperModule = await import(toDataUrl(workerData.wrapperCode));
2774
+ const invocation = workerData.invocation;
2775
+ const result =
2776
+ invocation.kind === "bootstrap"
2777
+ ? null
2778
+ : invocation.kind === "hook"
2779
+ ? await wrapperModule.invokeHook(invocation.name, invocation.event)
2780
+ : await wrapperModule.invokeRoute(
2781
+ invocation.name,
2782
+ invocation.input,
2783
+ invocation.request,
2784
+ );
2785
+
2786
+ parentPort.postMessage({ type: "result", value: result });
2787
+ } catch (error) {
2788
+ parentPort.postMessage({ type: "error", error: serializeError(error) });
2789
+ }
2790
+ })();
2791
+ `;
2792
+ function normalizeLimits(limits) {
2793
+ return {
2794
+ cpuMs: limits?.cpuMs ?? DEFAULT_LIMITS.cpuMs,
2795
+ memoryMb: limits?.memoryMb ?? DEFAULT_LIMITS.memoryMb,
2796
+ subrequests: limits?.subrequests ?? DEFAULT_LIMITS.subrequests,
2797
+ wallTimeMs: limits?.wallTimeMs ?? DEFAULT_LIMITS.wallTimeMs
2798
+ };
2799
+ }
2800
+ function codeToDataUrl(code) {
2801
+ return `data:text/javascript;base64,${Buffer.from(code, "utf8").toString("base64")}`;
2802
+ }
2803
+ function rewriteDinewayImport(code) {
2804
+ const shimUrl = codeToDataUrl(DINEWAY_SHIM_CODE);
2805
+ return code.replace(DINEWAY_STATIC_IMPORT_RE, `from "${shimUrl}"`).replace(DINEWAY_DYNAMIC_IMPORT_RE, `import("${shimUrl}")`);
2806
+ }
2807
+ function normalizeCapabilities(capabilities) {
2808
+ const normalized = [...capabilities];
2809
+ if (normalized.includes("content:write") && !normalized.includes("content:read")) normalized.push("content:read");
2810
+ if (normalized.includes("media:write") && !normalized.includes("media:read")) normalized.push("media:read");
2811
+ if (normalized.includes("network:request:unrestricted") && !normalized.includes("network:request")) normalized.push("network:request");
2812
+ return normalized;
2813
+ }
2814
+ function createResolvedPluginFromManifest(manifest) {
2815
+ return {
2816
+ id: manifest.id,
2817
+ version: manifest.version,
2818
+ capabilities: normalizeCapabilities(manifest.capabilities),
2819
+ allowedHosts: manifest.allowedHosts,
2820
+ storage: manifest.storage,
2821
+ hooks: {},
2822
+ routes: {},
2823
+ admin: manifest.admin
2824
+ };
2825
+ }
2826
+ function createSandboxUploadUrlStub() {
2827
+ return async () => {
2828
+ throw new Error("getUploadUrl is not available in sandbox mode. Use media.upload(filename, contentType, bytes) instead.");
2829
+ };
2830
+ }
2831
+ function toErrorPayload(error) {
2832
+ if (error instanceof Error) return {
2833
+ message: error.message,
2834
+ stack: error.stack
2835
+ };
2836
+ return { message: String(error) };
2837
+ }
2838
+ function toArrayBuffer(value) {
2839
+ if (value instanceof ArrayBuffer) return value;
2840
+ if (ArrayBuffer.isView(value)) {
2841
+ const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
2842
+ const copy = new Uint8Array(bytes.byteLength);
2843
+ copy.set(bytes);
2844
+ return copy.buffer;
2845
+ }
2846
+ throw new Error("Expected an ArrayBuffer-compatible value.");
2847
+ }
2848
+ function createSerializedHttpResponse(response) {
2849
+ return response.text().then((text) => ({
2850
+ status: response.status,
2851
+ headers: Object.fromEntries(response.headers.entries()),
2852
+ text
2853
+ }));
2854
+ }
2855
+ function postWorkerMessage(worker, message) {
2856
+ worker.postMessage(message);
2857
+ }
2858
+ function isWriteContentAccess(content) {
2859
+ return !!content && typeof content.create === "function";
2860
+ }
2861
+ function isWriteMediaAccess(media) {
2862
+ return !!media && typeof media.upload === "function" && typeof media.delete === "function";
2863
+ }
2864
+ function requireStorageCollection(storage, collection) {
2865
+ const value = storage[collection];
2866
+ if (!value) throw new Error(`Storage collection "${collection}" is not declared in the plugin manifest.`);
2867
+ return value;
2868
+ }
2869
+ function requireHttpAccess(http) {
2870
+ if (!http) throw new Error("HTTP access is not available for this plugin.");
2871
+ return http;
2872
+ }
2873
+ function requireUserAccess(users) {
2874
+ if (!users) throw new Error("User access is not available for this plugin.");
2875
+ return users;
2876
+ }
2877
+ function requireCronAccess(cron) {
2878
+ if (!cron) throw new Error("Cron access is not available for this plugin.");
2879
+ return cron;
2880
+ }
2881
+ function requireWriteContentAccess(content) {
2882
+ if (!isWriteContentAccess(content)) throw new Error("Content write access is not available for this plugin.");
2883
+ return content;
2884
+ }
2885
+ function requireWriteMediaAccess(media) {
2886
+ if (!isWriteMediaAccess(media)) throw new Error("Media write access is not available for this plugin.");
2887
+ return media;
2888
+ }
2889
+ function isRecord(value) {
2890
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2891
+ }
2892
+ function expectString(value, label) {
2893
+ if (typeof value !== "string") throw new Error(`Expected ${label} to be a string.`);
2894
+ return value;
2895
+ }
2896
+ function expectOptionalString(value, label) {
2897
+ if (value === void 0) return;
2898
+ return expectString(value, label);
2899
+ }
2900
+ function expectStringArray(value, label) {
2901
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) throw new Error(`Expected ${label} to be an array of strings.`);
2902
+ return value;
2903
+ }
2904
+ function isWhereValue(value) {
2905
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
2906
+ if (!isRecord(value)) return false;
2907
+ if ("in" in value) return Array.isArray(value.in) && value.in.every((item) => typeof item === "string" || typeof item === "number");
2908
+ if ("startsWith" in value) return typeof value.startsWith === "string";
2909
+ return [
2910
+ "gt",
2911
+ "gte",
2912
+ "lt",
2913
+ "lte"
2914
+ ].some((key) => key in value) && Object.entries(value).every(([key, item]) => {
2915
+ if (![
2916
+ "gt",
2917
+ "gte",
2918
+ "lt",
2919
+ "lte"
2920
+ ].includes(key)) return false;
2921
+ return item === void 0 || typeof item === "string" || typeof item === "number";
2922
+ });
2923
+ }
2924
+ function isWhereClause(value) {
2925
+ return isRecord(value) && Object.values(value).every(isWhereValue);
2926
+ }
2927
+ function isOrderByRecord(value) {
2928
+ return isRecord(value) && Object.values(value).every((item) => item === "asc" || item === "desc");
2929
+ }
2930
+ function isQueryOptions(value) {
2931
+ if (!isRecord(value)) return false;
2932
+ if ("where" in value && value.where !== void 0 && !isWhereClause(value.where)) return false;
2933
+ if ("orderBy" in value && value.orderBy !== void 0 && !isOrderByRecord(value.orderBy)) return false;
2934
+ if ("limit" in value && value.limit !== void 0 && typeof value.limit !== "number") return false;
2935
+ if ("cursor" in value && value.cursor !== void 0 && typeof value.cursor !== "string") return false;
2936
+ return true;
2937
+ }
2938
+ function isContentListOptions(value) {
2939
+ if (!isRecord(value)) return false;
2940
+ if ("where" in value && value.where !== void 0 && !isContentListWhere(value.where)) return false;
2941
+ if ("limit" in value && value.limit !== void 0 && typeof value.limit !== "number") return false;
2942
+ if ("cursor" in value && value.cursor !== void 0 && typeof value.cursor !== "string") return false;
2943
+ if ("orderBy" in value && value.orderBy !== void 0 && !isOrderByRecord(value.orderBy)) return false;
2944
+ return true;
2945
+ }
2946
+ function isContentListWhere(value) {
2947
+ if (!isRecord(value)) return false;
2948
+ return Object.entries(value).every(([key, item]) => {
2949
+ if (key !== "status" && key !== "locale") return false;
2950
+ return item === void 0 || typeof item === "string";
2951
+ });
2952
+ }
2953
+ function isContentWriteInput(value) {
2954
+ return isRecord(value);
2955
+ }
2956
+ function isMediaListOptions(value) {
2957
+ if (!isRecord(value)) return false;
2958
+ if ("limit" in value && value.limit !== void 0 && typeof value.limit !== "number") return false;
2959
+ if ("cursor" in value && value.cursor !== void 0 && typeof value.cursor !== "string") return false;
2960
+ if ("mimeType" in value && value.mimeType !== void 0 && typeof value.mimeType !== "string") return false;
2961
+ return true;
2962
+ }
2963
+ function isStoragePutManyItems(value) {
2964
+ return Array.isArray(value) && value.every((item) => isRecord(item) && typeof item.id === "string" && "data" in item);
2965
+ }
2966
+ function isUserListOptions(value) {
2967
+ if (!isRecord(value)) return false;
2968
+ if ("role" in value && value.role !== void 0 && typeof value.role !== "number") return false;
2969
+ if ("limit" in value && value.limit !== void 0 && typeof value.limit !== "number") return false;
2970
+ if ("cursor" in value && value.cursor !== void 0 && typeof value.cursor !== "string") return false;
2971
+ return true;
2972
+ }
2973
+ function isCronScheduleOptions(value) {
2974
+ return isRecord(value) && typeof value.schedule === "string" && (value.data === void 0 || isRecord(value.data));
2975
+ }
2976
+ function isSandboxEmailMessage(value) {
2977
+ if (!isRecord(value)) return false;
2978
+ if (typeof value.to !== "string" || typeof value.subject !== "string" || typeof value.text !== "string") return false;
2979
+ return value.html === void 0 || typeof value.html === "string";
2980
+ }
2981
+ function isLogLevel(value) {
2982
+ return value === "debug" || value === "info" || value === "warn" || value === "error";
2983
+ }
2984
+ function expectOptional(value, label, guard) {
2985
+ if (value === void 0) return;
2986
+ if (!guard(value)) throw new Error(`Expected ${label} to match the required shape.`);
2987
+ return value;
2988
+ }
2989
+ function expectValue(value, label, guard) {
2990
+ if (!guard(value)) throw new Error(`Expected ${label} to match the required shape.`);
2991
+ return value;
2992
+ }
2993
+ var NodeSandboxRunner = class {
2994
+ limits;
2995
+ activeWorkers = /* @__PURE__ */ new Set();
2996
+ emailSend = null;
2997
+ constructor(options) {
2998
+ this.options = options;
2999
+ this.limits = normalizeLimits(options.limits);
3000
+ }
3001
+ isAvailable() {
3002
+ return true;
3003
+ }
3004
+ async load(manifest, code) {
3005
+ const plugin = new NodeSandboxedPlugin(manifest, code, this.options, this.limits, () => this.emailSend, this.activeWorkers);
3006
+ await plugin.validateLoad();
3007
+ return plugin;
3008
+ }
3009
+ setEmailSend(callback) {
3010
+ this.emailSend = callback;
3011
+ }
3012
+ async terminateAll() {
3013
+ await Promise.allSettled(Array.from(this.activeWorkers, (worker) => worker.terminate()));
3014
+ this.activeWorkers.clear();
3015
+ }
3016
+ };
3017
+ var NodeSandboxedPlugin = class {
3018
+ id;
3019
+ resolvedPlugin;
3020
+ pluginUrl;
3021
+ wrapperCode;
3022
+ pluginWorkers = /* @__PURE__ */ new Set();
3023
+ constructor(manifest, code, options, limits, getEmailSend, sharedActiveWorkers) {
3024
+ this.manifest = manifest;
3025
+ this.options = options;
3026
+ this.limits = limits;
3027
+ this.getEmailSend = getEmailSend;
3028
+ this.sharedActiveWorkers = sharedActiveWorkers;
3029
+ this.id = `${manifest.id}:${manifest.version}`;
3030
+ this.resolvedPlugin = createResolvedPluginFromManifest(manifest);
3031
+ this.pluginUrl = codeToDataUrl(rewriteDinewayImport(code));
3032
+ this.wrapperCode = generateSandboxWrapper(manifest, {
3033
+ pluginModuleSpecifier: this.pluginUrl,
3034
+ runtimeGlobal: DEFAULT_RUNTIME_GLOBAL,
3035
+ site: this.options.siteInfo
3036
+ });
3037
+ }
3038
+ async invokeHook(hookName, event) {
3039
+ return this.invokeInWorker({
3040
+ kind: "hook",
3041
+ name: hookName,
3042
+ event
3043
+ });
3044
+ }
3045
+ async invokeRoute(routeName, input, request) {
3046
+ return this.invokeInWorker({
3047
+ kind: "route",
3048
+ name: routeName,
3049
+ input,
3050
+ request
3051
+ });
3052
+ }
3053
+ async terminate() {
3054
+ await Promise.allSettled(Array.from(this.pluginWorkers, (worker) => worker.terminate()));
3055
+ this.pluginWorkers.clear();
3056
+ }
3057
+ async validateLoad() {
3058
+ await this.invokeInWorker({ kind: "bootstrap" });
3059
+ }
3060
+ createPluginContext() {
3061
+ return createPluginContext({
3062
+ db: this.options.db,
3063
+ storage: this.options.mediaStorage,
3064
+ getUploadUrl: this.manifest.capabilities.includes("media:write") ? createSandboxUploadUrlStub() : void 0,
3065
+ cronReschedule: this.options.cronReschedule,
3066
+ siteInfo: this.options.siteInfo
3067
+ }, this.resolvedPlugin);
3068
+ }
3069
+ async handleBridgeCall(method, args, state) {
3070
+ const ctx = this.createPluginContext();
3071
+ const stringArg = (index, label) => expectString(args[index], `${String(method)} ${label}`);
3072
+ const optionalStringArg = (index, label) => expectOptionalString(args[index], `${String(method)} ${label}`);
3073
+ switch (method) {
3074
+ case "kvGet": return ctx.kv.get(stringArg(0, "key"));
3075
+ case "kvSet": return ctx.kv.set(stringArg(0, "key"), args[1]);
3076
+ case "kvDelete": return ctx.kv.delete(stringArg(0, "key"));
3077
+ case "kvList": return ctx.kv.list(optionalStringArg(0, "prefix"));
3078
+ case "storageGet": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).get(stringArg(1, "id"));
3079
+ case "storagePut": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).put(stringArg(1, "id"), args[2]);
3080
+ case "storageDelete": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).delete(stringArg(1, "id"));
3081
+ case "storageQuery": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).query(expectOptional(args[1], `${String(method)} options`, isQueryOptions));
3082
+ case "storageCount": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).count(expectOptional(args[1], `${String(method)} where`, isWhereClause));
3083
+ case "storageGetMany": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).getMany(expectStringArray(args[1], `${String(method)} ids`)).then((items) => Array.from(items, ([id, data]) => ({
3084
+ id,
3085
+ data
3086
+ })));
3087
+ case "storagePutMany": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).putMany(expectValue(args[1], `${String(method)} items`, isStoragePutManyItems));
3088
+ case "storageDeleteMany": return requireStorageCollection(ctx.storage, stringArg(0, "collection")).deleteMany(expectStringArray(args[1], `${String(method)} ids`));
3089
+ case "contentGet": return ctx.content?.get(stringArg(0, "collection"), stringArg(1, "id")) ?? null;
3090
+ case "contentList": return ctx.content?.list(stringArg(0, "collection"), expectOptional(args[1], `${String(method)} options`, isContentListOptions)) ?? null;
3091
+ case "contentCreate": return requireWriteContentAccess(ctx.content).create(stringArg(0, "collection"), expectValue(args[1], `${String(method)} data`, isContentWriteInput));
3092
+ case "contentUpdate": return requireWriteContentAccess(ctx.content).update(stringArg(0, "collection"), stringArg(1, "id"), expectValue(args[2], `${String(method)} data`, isContentWriteInput));
3093
+ case "contentDelete": return requireWriteContentAccess(ctx.content).delete(stringArg(0, "collection"), stringArg(1, "id"));
3094
+ case "mediaGet": return ctx.media?.get(stringArg(0, "id")) ?? null;
3095
+ case "mediaList": return ctx.media?.list(expectOptional(args[0], `${String(method)} options`, isMediaListOptions)) ?? null;
3096
+ case "mediaUpload": return requireWriteMediaAccess(ctx.media).upload(stringArg(0, "filename"), stringArg(1, "contentType"), toArrayBuffer(args[2]));
3097
+ case "mediaDelete": return requireWriteMediaAccess(ctx.media).delete(stringArg(0, "id"));
3098
+ case "httpFetch": {
3099
+ const http = requireHttpAccess(ctx.http);
3100
+ state.subrequests += 1;
3101
+ if (state.subrequests > this.limits.subrequests) throw new Error(`Sandbox subrequest limit exceeded (${this.limits.subrequests} per invocation).`);
3102
+ return createSerializedHttpResponse(await http.fetch(stringArg(0, "url"), expectOptional(args[1], `${String(method)} init`, isRecord)));
3103
+ }
3104
+ case "userGet": return requireUserAccess(ctx.users).get(stringArg(0, "id"));
3105
+ case "userGetByEmail": return requireUserAccess(ctx.users).getByEmail(stringArg(0, "email"));
3106
+ case "userList": return requireUserAccess(ctx.users).list(expectOptional(args[0], `${String(method)} options`, isUserListOptions));
3107
+ case "cronSchedule": return requireCronAccess(ctx.cron).schedule(stringArg(0, "name"), expectValue(args[1], `${String(method)} options`, isCronScheduleOptions));
3108
+ case "cronCancel": return requireCronAccess(ctx.cron).cancel(stringArg(0, "name"));
3109
+ case "cronList": return requireCronAccess(ctx.cron).list();
3110
+ case "emailSend": {
3111
+ const callback = this.getEmailSend();
3112
+ if (!callback) throw new Error("Email sending is not configured for sandboxed plugins.");
3113
+ return callback(expectValue(args[0], `${String(method)} message`, isSandboxEmailMessage), this.manifest.id);
3114
+ }
3115
+ case "log": {
3116
+ const level = expectValue(args[0], `${String(method)} level`, isLogLevel);
3117
+ const message = stringArg(1, "message");
3118
+ const data = args[2];
3119
+ const fn = ctx.log[level];
3120
+ return fn(message, data);
3121
+ }
3122
+ default: {
3123
+ const unknownMethod = method;
3124
+ throw new Error(`Unsupported sandbox bridge method: ${String(unknownMethod)}`);
3125
+ }
3126
+ }
3127
+ }
3128
+ async invokeInWorker(invocation) {
3129
+ const state = { subrequests: 0 };
3130
+ return new Promise((resolve, reject) => {
3131
+ const worker = new Worker(WORKER_SOURCE, {
3132
+ eval: true,
3133
+ resourceLimits: { maxOldGenerationSizeMb: this.limits.memoryMb },
3134
+ workerData: {
3135
+ runtimeGlobal: DEFAULT_RUNTIME_GLOBAL,
3136
+ bridgeMethods: ALL_BRIDGE_METHODS,
3137
+ plugin: {
3138
+ id: this.manifest.id,
3139
+ version: this.manifest.version
3140
+ },
3141
+ site: this.options.siteInfo ?? {
3142
+ name: "",
3143
+ url: "",
3144
+ locale: "en"
3145
+ },
3146
+ wrapperCode: this.wrapperCode,
3147
+ invocation
3148
+ }
3149
+ });
3150
+ this.pluginWorkers.add(worker);
3151
+ this.sharedActiveWorkers.add(worker);
3152
+ let settled = false;
3153
+ let timedOut = false;
3154
+ let cpuTimer;
3155
+ const cleanup = () => {
3156
+ clearTimeout(timeout);
3157
+ if (cpuTimer) clearTimeout(cpuTimer);
3158
+ this.pluginWorkers.delete(worker);
3159
+ this.sharedActiveWorkers.delete(worker);
3160
+ worker.removeAllListeners();
3161
+ };
3162
+ const finish = (fn) => {
3163
+ if (settled) return;
3164
+ settled = true;
3165
+ cleanup();
3166
+ worker.terminate();
3167
+ fn();
3168
+ };
3169
+ const timeout = setTimeout(() => {
3170
+ timedOut = true;
3171
+ finish(() => {
3172
+ reject(/* @__PURE__ */ new Error(`Sandbox invocation timed out after ${this.limits.wallTimeMs}ms.`));
3173
+ });
3174
+ }, this.limits.wallTimeMs);
3175
+ const cpuPollIntervalMs = Math.max(5, Math.min(25, Math.floor(this.limits.cpuMs / 4)));
3176
+ const scheduleCpuCheck = () => {
3177
+ if (settled) return;
3178
+ cpuTimer = setTimeout(() => {
3179
+ try {
3180
+ if (worker.performance.eventLoopUtilization().active > this.limits.cpuMs) {
3181
+ finish(() => {
3182
+ reject(/* @__PURE__ */ new Error(`Sandbox invocation exceeded CPU limit of ${this.limits.cpuMs}ms.`));
3183
+ });
3184
+ return;
3185
+ }
3186
+ } catch {
3187
+ return;
3188
+ }
3189
+ scheduleCpuCheck();
3190
+ }, cpuPollIntervalMs);
3191
+ };
3192
+ scheduleCpuCheck();
3193
+ worker.on("message", (message) => {
3194
+ if (message.type === "bridge") {
3195
+ this.handleBridgeCall(message.method, message.args, state).then((value) => {
3196
+ postWorkerMessage(worker, {
3197
+ type: "bridge-result",
3198
+ id: message.id,
3199
+ value
3200
+ });
3201
+ }).catch((error) => {
3202
+ postWorkerMessage(worker, {
3203
+ type: "bridge-error",
3204
+ id: message.id,
3205
+ error: toErrorPayload(error)
3206
+ });
3207
+ });
3208
+ return;
3209
+ }
3210
+ if (message.type === "result") {
3211
+ finish(() => resolve(message.value));
3212
+ return;
3213
+ }
3214
+ if (message.type === "error") finish(() => {
3215
+ const error = new Error(message.error.message);
3216
+ if (message.error.stack) error.stack = message.error.stack;
3217
+ reject(error);
3218
+ });
3219
+ });
3220
+ worker.once("error", (error) => {
3221
+ finish(() => reject(error));
3222
+ });
3223
+ worker.once("exit", (code) => {
3224
+ if (settled || timedOut) return;
3225
+ finish(() => {
3226
+ reject(/* @__PURE__ */ new Error(`Sandbox worker exited unexpectedly with code ${code}.`));
3227
+ });
3228
+ });
3229
+ });
3230
+ }
3231
+ };
3232
+ function createNodeSandboxRunner(options) {
3233
+ return new NodeSandboxRunner(options);
3234
+ }
3235
+
3236
+ //#endregion
3237
+ //#region src/plugins/types.ts
3238
+ /**
3239
+ * Check if a value is a StandardPluginDefinition (has hooks/routes but no id/version).
3240
+ */
3241
+ function isStandardPluginDefinition(value) {
3242
+ if (typeof value !== "object" || value === null) return false;
3243
+ const hasPluginShape = "hooks" in value || "routes" in value;
3244
+ const hasNativeShape = "id" in value && "version" in value;
3245
+ return hasPluginShape && !hasNativeShape;
3246
+ }
3247
+
3248
+ //#endregion
3249
+ export { portableTextToProsemirror as _, SandboxNotAvailableError as a, reference as b, createPluginManager as c, EmailPipeline as d, HookPipeline as f, after as g, definePlugin as h, NoopSandboxRunner as i, PluginRouteError as l, resolveExclusiveHooks as m, NodeSandboxRunner as n, createNoopSandboxRunner as o, createHookPipeline as p, createNodeSandboxRunner as r, PluginManager as s, isStandardPluginDefinition as t, PluginRouteRegistry as u, prosemirrorToPortableText as v, image as x, portableText as y };