emdash 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (605) hide show
  1. package/dist/{adapters-9DybjTO6.d.mts → adapters-C4yd_UJR.d.mts} +1 -1
  2. package/dist/{adapters-9DybjTO6.d.mts.map → adapters-C4yd_UJR.d.mts.map} +1 -1
  3. package/dist/{allowed-origins-CDdG-4Gd.mjs → allowed-origins-D0fFk9a6.mjs} +2 -2
  4. package/dist/{allowed-origins-CDdG-4Gd.mjs.map → allowed-origins-D0fFk9a6.mjs.map} +1 -1
  5. package/dist/api/route-utils.d.mts +3 -3
  6. package/dist/api/route-utils.mjs +15 -15
  7. package/dist/api/schemas/index.d.mts +2 -2
  8. package/dist/api/schemas/index.mjs +3 -3
  9. package/dist/{api-ayIQ7rIe.mjs → api-CLwG_3dh.mjs} +523 -59
  10. package/dist/api-CLwG_3dh.mjs.map +1 -0
  11. package/dist/{api-tokens-eYymBhIT.mjs → api-tokens-ucpcNXDt.mjs} +2 -2
  12. package/dist/{api-tokens-eYymBhIT.mjs.map → api-tokens-ucpcNXDt.mjs.map} +1 -1
  13. package/dist/{apply-v4DBgjPw.mjs → apply-wJhM_bwU.mjs} +17 -17
  14. package/dist/{apply-v4DBgjPw.mjs.map → apply-wJhM_bwU.mjs.map} +1 -1
  15. package/dist/astro/index.d.mts +10 -10
  16. package/dist/astro/index.mjs +21 -5
  17. package/dist/astro/index.mjs.map +1 -1
  18. package/dist/astro/middleware/auth.d.mts +9 -9
  19. package/dist/astro/middleware/auth.mjs +6 -6
  20. package/dist/astro/middleware/auth.mjs.map +1 -1
  21. package/dist/astro/middleware/redirect.mjs +4 -4
  22. package/dist/astro/middleware/request-context.mjs +2 -2
  23. package/dist/astro/middleware/request-context.mjs.map +1 -1
  24. package/dist/astro/middleware/setup.mjs +1 -1
  25. package/dist/astro/middleware.d.mts.map +1 -1
  26. package/dist/astro/middleware.mjs +353 -71
  27. package/dist/astro/middleware.mjs.map +1 -1
  28. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +5 -5
  29. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +5 -5
  30. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +4 -4
  31. package/dist/astro/routes/api/admin/api-tokens/index.mjs +5 -5
  32. package/dist/astro/routes/api/admin/bylines/_id_/index.d.mts.map +1 -1
  33. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +14 -17
  34. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
  35. package/dist/astro/routes/api/admin/bylines/_id_/translations.d.mts +9 -0
  36. package/dist/astro/routes/api/admin/bylines/_id_/translations.d.mts.map +1 -0
  37. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +70 -0
  38. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -0
  39. package/dist/astro/routes/api/admin/bylines/index.d.mts.map +1 -1
  40. package/dist/astro/routes/api/admin/bylines/index.mjs +25 -16
  41. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  42. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +10 -10
  43. package/dist/astro/routes/api/admin/comments/_id_.mjs +5 -5
  44. package/dist/astro/routes/api/admin/comments/bulk.mjs +8 -8
  45. package/dist/astro/routes/api/admin/comments/counts.mjs +5 -5
  46. package/dist/astro/routes/api/admin/comments/index.mjs +8 -8
  47. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +4 -4
  48. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +3 -3
  49. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +4 -4
  50. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +4 -4
  51. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +32 -31
  52. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  53. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +32 -31
  54. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  55. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +31 -30
  56. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  57. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +31 -30
  58. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  59. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +33 -31
  60. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  61. package/dist/astro/routes/api/admin/plugins/index.mjs +31 -30
  62. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  63. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +3 -3
  64. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +31 -30
  65. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  66. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +33 -31
  67. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  68. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +31 -30
  69. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  70. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.d.mts +8 -0
  71. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.d.mts.map +1 -0
  72. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +59 -0
  73. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -0
  74. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts +8 -0
  75. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -0
  76. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +72 -0
  77. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -0
  78. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +31 -30
  79. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  80. package/dist/astro/routes/api/admin/plugins/updates.d.mts.map +1 -1
  81. package/dist/astro/routes/api/admin/plugins/updates.mjs +44 -31
  82. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  83. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +31 -30
  84. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  85. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +3 -3
  86. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +31 -30
  87. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  88. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +2 -2
  89. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +2 -2
  90. package/dist/astro/routes/api/admin/users/_id_/index.mjs +5 -5
  91. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +3 -3
  92. package/dist/astro/routes/api/admin/users/index.mjs +5 -5
  93. package/dist/astro/routes/api/auth/dev-bypass.mjs +5 -5
  94. package/dist/astro/routes/api/auth/invite/accept.mjs +2 -2
  95. package/dist/astro/routes/api/auth/invite/complete.mjs +9 -9
  96. package/dist/astro/routes/api/auth/invite/index.mjs +6 -6
  97. package/dist/astro/routes/api/auth/invite/register-options.mjs +8 -8
  98. package/dist/astro/routes/api/auth/logout.mjs +3 -3
  99. package/dist/astro/routes/api/auth/magic-link/send.mjs +8 -8
  100. package/dist/astro/routes/api/auth/magic-link/verify.mjs +3 -3
  101. package/dist/astro/routes/api/auth/me.mjs +5 -5
  102. package/dist/astro/routes/api/auth/mode.mjs +1 -1
  103. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +3 -3
  104. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs.map +1 -1
  105. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
  106. package/dist/astro/routes/api/auth/oauth/_provider_.mjs.map +1 -1
  107. package/dist/astro/routes/api/auth/passkey/_id_.mjs +5 -5
  108. package/dist/astro/routes/api/auth/passkey/index.mjs +2 -2
  109. package/dist/astro/routes/api/auth/passkey/options.mjs +10 -10
  110. package/dist/astro/routes/api/auth/passkey/register/options.mjs +8 -8
  111. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +9 -9
  112. package/dist/astro/routes/api/auth/passkey/verify.mjs +9 -9
  113. package/dist/astro/routes/api/auth/signup/complete.mjs +9 -9
  114. package/dist/astro/routes/api/auth/signup/request.mjs +8 -8
  115. package/dist/astro/routes/api/auth/signup/verify.mjs +2 -2
  116. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +11 -11
  117. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +3 -3
  118. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +3 -3
  119. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  120. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +3 -3
  121. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs.map +1 -1
  122. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +3 -3
  123. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +9 -9
  124. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +6 -6
  125. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  126. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +3 -3
  127. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs.map +1 -1
  128. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +3 -3
  129. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +6 -6
  130. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  131. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +10 -9
  132. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  133. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +3 -3
  134. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs.map +1 -1
  135. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +3 -3
  136. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  137. package/dist/astro/routes/api/content/_collection_/_id_.mjs +6 -6
  138. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  139. package/dist/astro/routes/api/content/_collection_/index.mjs +6 -6
  140. package/dist/astro/routes/api/content/_collection_/trash.mjs +6 -6
  141. package/dist/astro/routes/api/dashboard.mjs +7 -7
  142. package/dist/astro/routes/api/dev/emails.mjs +3 -3
  143. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  144. package/dist/astro/routes/api/import/probe.mjs +10 -10
  145. package/dist/astro/routes/api/import/wordpress/analyze.mjs +3 -3
  146. package/dist/astro/routes/api/import/wordpress/execute.d.mts +9 -9
  147. package/dist/astro/routes/api/import/wordpress/execute.mjs +9 -8
  148. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  149. package/dist/astro/routes/api/import/wordpress/media.mjs +8 -8
  150. package/dist/astro/routes/api/import/wordpress/prepare.mjs +8 -8
  151. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  152. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +7 -7
  153. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  154. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  155. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +10 -10
  156. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +1 -1
  157. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +11 -11
  158. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  159. package/dist/astro/routes/api/manifest.mjs +4 -4
  160. package/dist/astro/routes/api/mcp.mjs +29 -29
  161. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  162. package/dist/astro/routes/api/media/_id_/confirm.mjs +6 -6
  163. package/dist/astro/routes/api/media/_id_.mjs +6 -6
  164. package/dist/astro/routes/api/media/file/_...key_.mjs +2 -2
  165. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +3 -3
  166. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +3 -3
  167. package/dist/astro/routes/api/media/providers/index.mjs +3 -3
  168. package/dist/astro/routes/api/media/upload-url.mjs +7 -7
  169. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  170. package/dist/astro/routes/api/media.mjs +8 -8
  171. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +7 -7
  172. package/dist/astro/routes/api/menus/_name_/items.mjs +7 -7
  173. package/dist/astro/routes/api/menus/_name_/reorder.mjs +7 -7
  174. package/dist/astro/routes/api/menus/_name_/translations.mjs +7 -7
  175. package/dist/astro/routes/api/menus/_name_.mjs +7 -7
  176. package/dist/astro/routes/api/menus/index.mjs +7 -7
  177. package/dist/astro/routes/api/oauth/authorize.mjs +6 -6
  178. package/dist/astro/routes/api/oauth/device/authorize.mjs +6 -6
  179. package/dist/astro/routes/api/oauth/device/code.mjs +9 -9
  180. package/dist/astro/routes/api/oauth/device/token.mjs +8 -8
  181. package/dist/astro/routes/api/oauth/register.mjs +3 -3
  182. package/dist/astro/routes/api/oauth/token/refresh.mjs +6 -6
  183. package/dist/astro/routes/api/oauth/token/revoke.mjs +6 -6
  184. package/dist/astro/routes/api/oauth/token.mjs +6 -6
  185. package/dist/astro/routes/api/openapi.json.mjs +3 -3
  186. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  187. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +4 -4
  188. package/dist/astro/routes/api/redirects/404s/index.mjs +8 -8
  189. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  190. package/dist/astro/routes/api/redirects/404s/summary.mjs +8 -8
  191. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  192. package/dist/astro/routes/api/redirects/_id_.mjs +9 -9
  193. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  194. package/dist/astro/routes/api/redirects/index.mjs +9 -9
  195. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  196. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +3 -3
  197. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +3 -3
  198. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +31 -30
  199. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  200. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +31 -30
  201. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  202. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +31 -30
  203. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  204. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +31 -30
  205. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  206. package/dist/astro/routes/api/schema/collections/index.mjs +31 -30
  207. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  208. package/dist/astro/routes/api/schema/index.mjs +6 -6
  209. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  210. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +31 -30
  211. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  212. package/dist/astro/routes/api/schema/orphans/index.mjs +31 -30
  213. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  214. package/dist/astro/routes/api/search/enable.mjs +9 -9
  215. package/dist/astro/routes/api/search/index.mjs +8 -8
  216. package/dist/astro/routes/api/search/rebuild.mjs +9 -9
  217. package/dist/astro/routes/api/search/stats.mjs +6 -6
  218. package/dist/astro/routes/api/search/suggest.mjs +8 -8
  219. package/dist/astro/routes/api/sections/_slug_.mjs +8 -8
  220. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  221. package/dist/astro/routes/api/sections/index.mjs +8 -8
  222. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  223. package/dist/astro/routes/api/settings/email.mjs +4 -4
  224. package/dist/astro/routes/api/settings.mjs +10 -10
  225. package/dist/astro/routes/api/setup/admin-verify.mjs +10 -10
  226. package/dist/astro/routes/api/setup/admin.mjs +9 -9
  227. package/dist/astro/routes/api/setup/dev-bypass.mjs +22 -22
  228. package/dist/astro/routes/api/setup/dev-reset.mjs +2 -2
  229. package/dist/astro/routes/api/setup/index.mjs +22 -22
  230. package/dist/astro/routes/api/setup/status.mjs +4 -4
  231. package/dist/astro/routes/api/snapshot.mjs +5 -5
  232. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +11 -10
  233. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  234. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +11 -10
  235. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  236. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +11 -10
  237. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  238. package/dist/astro/routes/api/taxonomies/index.mjs +11 -10
  239. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  240. package/dist/astro/routes/api/themes/preview.mjs +5 -5
  241. package/dist/astro/routes/api/typegen.mjs +5 -5
  242. package/dist/astro/routes/api/well-known/auth.mjs +1 -1
  243. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
  244. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
  245. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +6 -6
  246. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +8 -8
  247. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +8 -8
  248. package/dist/astro/routes/api/widget-areas/_name_.mjs +5 -5
  249. package/dist/astro/routes/api/widget-areas/index.mjs +8 -8
  250. package/dist/astro/routes/api/widget-components.mjs +3 -3
  251. package/dist/astro/routes/robots.txt.mjs +5 -5
  252. package/dist/astro/routes/sitemap-_collection_.xml.mjs +4 -4
  253. package/dist/astro/routes/sitemap.xml.mjs +5 -5
  254. package/dist/astro/types.d.mts +13 -12
  255. package/dist/astro/types.d.mts.map +1 -1
  256. package/dist/auth/providers/github.d.mts +1 -1
  257. package/dist/auth/providers/google.d.mts +1 -1
  258. package/dist/{authorize-BlyCH-96.mjs → authorize-Bkwe8kuL.mjs} +2 -2
  259. package/dist/{authorize-BlyCH-96.mjs.map → authorize-Bkwe8kuL.mjs.map} +1 -1
  260. package/dist/byline-CTaWkMh5.mjs +404 -0
  261. package/dist/byline-CTaWkMh5.mjs.map +1 -0
  262. package/dist/bylines-BYHWU3T7.mjs +174 -0
  263. package/dist/bylines-BYHWU3T7.mjs.map +1 -0
  264. package/dist/{bylines-C6eYUWlZ.d.mts → bylines-DtDRNF1n.d.mts} +63 -18
  265. package/dist/bylines-DtDRNF1n.d.mts.map +1 -0
  266. package/dist/bylines-H0Xh5TMy.mjs +118 -0
  267. package/dist/bylines-H0Xh5TMy.mjs.map +1 -0
  268. package/dist/{cache-CXCpjWiL.mjs → cache-CNk1jIxp.mjs} +2 -2
  269. package/dist/{cache-CXCpjWiL.mjs.map → cache-CNk1jIxp.mjs.map} +1 -1
  270. package/dist/{challenge-store-CJ0OOHOr.mjs → challenge-store-Dng1SxKT.mjs} +1 -1
  271. package/dist/{challenge-store-CJ0OOHOr.mjs.map → challenge-store-Dng1SxKT.mjs.map} +1 -1
  272. package/dist/{chunks-DyGtu1Bv.mjs → chunks-BkfVdD-3.mjs} +2 -2
  273. package/dist/{chunks-DyGtu1Bv.mjs.map → chunks-BkfVdD-3.mjs.map} +1 -1
  274. package/dist/cli/index.mjs +21 -29
  275. package/dist/cli/index.mjs.map +1 -1
  276. package/dist/client/cf-access.d.mts +1 -1
  277. package/dist/client/index.d.mts +1 -1
  278. package/dist/client/index.mjs +1 -1
  279. package/dist/client/index.mjs.map +1 -1
  280. package/dist/{comment-Dd9MI82-.mjs → comment-_yzlBYPx.mjs} +2 -2
  281. package/dist/{comment-Dd9MI82-.mjs.map → comment-_yzlBYPx.mjs.map} +1 -1
  282. package/dist/{comments-koGI0FrK.mjs → comments-DxID-rsd.mjs} +3 -3
  283. package/dist/{comments-koGI0FrK.mjs.map → comments-DxID-rsd.mjs.map} +1 -1
  284. package/dist/{components-mZem7pbe.mjs → components-Dx3DM0gg.mjs} +1 -1
  285. package/dist/{components-mZem7pbe.mjs.map → components-Dx3DM0gg.mjs.map} +1 -1
  286. package/dist/config-CVssduLe.mjs.map +1 -1
  287. package/dist/{content-D6YG26WG.mjs → content-C0ooIs-f.mjs} +3 -3
  288. package/dist/{content-D6YG26WG.mjs.map → content-C0ooIs-f.mjs.map} +1 -1
  289. package/dist/{context-qF8d3IPR.mjs → context-sAnCaUIR.mjs} +10 -10
  290. package/dist/context-sAnCaUIR.mjs.map +1 -0
  291. package/dist/{cron-H8eJ46dv.mjs → cron-Bd3b3iuj.mjs} +1 -1
  292. package/dist/{cron-H8eJ46dv.mjs.map → cron-Bd3b3iuj.mjs.map} +1 -1
  293. package/dist/{dashboard-BmWSIUwY.mjs → dashboard-Cqw3ay2X.mjs} +4 -4
  294. package/dist/{dashboard-BmWSIUwY.mjs.map → dashboard-Cqw3ay2X.mjs.map} +1 -1
  295. package/dist/db/index.d.mts +3 -3
  296. package/dist/db/index.mjs +1 -1
  297. package/dist/db/libsql.d.mts +1 -1
  298. package/dist/db/postgres.d.mts +1 -1
  299. package/dist/db/sqlite.d.mts +1 -1
  300. package/dist/{default-Dbs22Gg4.mjs → default-BvTAYCzx.mjs} +1 -1
  301. package/dist/{default-Dbs22Gg4.mjs.map → default-BvTAYCzx.mjs.map} +1 -1
  302. package/dist/{device-flow-BqJRxa0Q.mjs → device-flow-B9oG8PwP.mjs} +4 -4
  303. package/dist/{device-flow-BqJRxa0Q.mjs.map → device-flow-B9oG8PwP.mjs.map} +1 -1
  304. package/dist/{email-console-Dmp5Q-P2.mjs → email-console-CubRll9q.mjs} +1 -1
  305. package/dist/email-console-CubRll9q.mjs.map +1 -0
  306. package/dist/{error-tSQWIl5U.mjs → error-CPh_8eLq.mjs} +16 -8
  307. package/dist/error-CPh_8eLq.mjs.map +1 -0
  308. package/dist/{escape-B8bdIryO.mjs → escape-Cg6kMELH.mjs} +1 -1
  309. package/dist/{escape-B8bdIryO.mjs.map → escape-Cg6kMELH.mjs.map} +1 -1
  310. package/dist/{fts-manager-B633C-kQ.mjs → fts-manager-Mnrtn-r2.mjs} +2 -2
  311. package/dist/{fts-manager-B633C-kQ.mjs.map → fts-manager-Mnrtn-r2.mjs.map} +1 -1
  312. package/dist/{import-CNfLOgDE.mjs → import-DG80rC_I.mjs} +3 -3
  313. package/dist/{import-CNfLOgDE.mjs.map → import-DG80rC_I.mjs.map} +1 -1
  314. package/dist/{index-UmOMt9T-.d.mts → index-Bv1Wf1zB.d.mts} +235 -18
  315. package/dist/index-Bv1Wf1zB.d.mts.map +1 -0
  316. package/dist/{index-D2gvztOP.d.mts → index-CC42STEm.d.mts} +3 -3
  317. package/dist/{index-D2gvztOP.d.mts.map → index-CC42STEm.d.mts.map} +1 -1
  318. package/dist/index.d.mts +17 -17
  319. package/dist/index.mjs +50 -49
  320. package/dist/{load-QzYRpVN3.mjs → load-DmXNVhst.mjs} +2 -2
  321. package/dist/{load-QzYRpVN3.mjs.map → load-DmXNVhst.mjs.map} +1 -1
  322. package/dist/{loader-Cs6-Bqe6.mjs → loader-Chm5h7Gr.mjs} +3 -3
  323. package/dist/loader-Chm5h7Gr.mjs.map +1 -0
  324. package/dist/{manifest-schema-HCtSh4Jq.mjs → manifest-schema-Czqf0TLu.mjs} +1 -1
  325. package/dist/{manifest-schema-HCtSh4Jq.mjs.map → manifest-schema-Czqf0TLu.mjs.map} +1 -1
  326. package/dist/media/index.d.mts +1 -1
  327. package/dist/media/local-runtime.d.mts +11 -11
  328. package/dist/media/local-runtime.mjs +4 -4
  329. package/dist/{media-allowlist-B8EX01DH.mjs → media-allowlist-BNloC69x.mjs} +1 -1
  330. package/dist/{media-allowlist-B8EX01DH.mjs.map → media-allowlist-BNloC69x.mjs.map} +1 -1
  331. package/dist/{media-Dg7he9uK.mjs → media-oqRcNiQf.mjs} +2 -2
  332. package/dist/media-oqRcNiQf.mjs.map +1 -0
  333. package/dist/{menus-DOzIecHi.mjs → menus-Bjf5R1Qq.mjs} +2 -2
  334. package/dist/menus-Bjf5R1Qq.mjs.map +1 -0
  335. package/dist/{menus-X4Z-eBA1.mjs → menus-C75SSmRy.mjs} +30 -11
  336. package/dist/menus-C75SSmRy.mjs.map +1 -0
  337. package/dist/mime-KV5TqkMN.mjs.map +1 -1
  338. package/dist/{mode-DPRPvJYm.mjs → mode-CaaiebZI.mjs} +1 -1
  339. package/dist/{mode-DPRPvJYm.mjs.map → mode-CaaiebZI.mjs.map} +1 -1
  340. package/dist/{oauth-authorization-62GmpGIH.mjs → oauth-authorization-CTMeVfvj.mjs} +4 -4
  341. package/dist/{oauth-authorization-62GmpGIH.mjs.map → oauth-authorization-CTMeVfvj.mjs.map} +1 -1
  342. package/dist/{oauth-clients-D_B0_-Bz.mjs → oauth-clients-eJCbkVSG.mjs} +1 -1
  343. package/dist/oauth-clients-eJCbkVSG.mjs.map +1 -0
  344. package/dist/{oauth-state-store-DpsZViTu.mjs → oauth-state-store-vOSdOeGe.mjs} +1 -1
  345. package/dist/{oauth-state-store-DpsZViTu.mjs.map → oauth-state-store-vOSdOeGe.mjs.map} +1 -1
  346. package/dist/{oauth-user-lookup-meyS2oB1.mjs → oauth-user-lookup-3JwsVw6N.mjs} +1 -1
  347. package/dist/{oauth-user-lookup-meyS2oB1.mjs.map → oauth-user-lookup-3JwsVw6N.mjs.map} +1 -1
  348. package/dist/options-BL4X94qY.mjs.map +1 -1
  349. package/dist/{options-Cq64Wx0O.d.mts → options-DhV-gwJb.d.mts} +4 -4
  350. package/dist/options-DhV-gwJb.d.mts.map +1 -0
  351. package/dist/page/index.d.mts +2 -2
  352. package/dist/{parse-BFTPon-J.mjs → parse-3-caTKgt.mjs} +2 -2
  353. package/dist/{parse-BFTPon-J.mjs.map → parse-3-caTKgt.mjs.map} +1 -1
  354. package/dist/{passkey-config-Cg86_ISa.mjs → passkey-config-BloQOT3y.mjs} +1 -1
  355. package/dist/{passkey-config-Cg86_ISa.mjs.map → passkey-config-BloQOT3y.mjs.map} +1 -1
  356. package/dist/{placeholder-D3cFCU9y.d.mts → placeholder-KCkkCtgQ.d.mts} +1 -1
  357. package/dist/{placeholder-D3cFCU9y.d.mts.map → placeholder-KCkkCtgQ.d.mts.map} +1 -1
  358. package/dist/plugin-types.d.mts +1 -1
  359. package/dist/plugins/adapt-sandbox-entry.d.mts +9 -9
  360. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  361. package/dist/plugins/adapt-sandbox-entry.mjs +26 -15
  362. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  363. package/dist/{preview-C1LOEbWZ.mjs → preview-D4z0WONU.mjs} +2 -2
  364. package/dist/{preview-C1LOEbWZ.mjs.map → preview-D4z0WONU.mjs.map} +1 -1
  365. package/dist/{public-url-CseXl9Fv.mjs → public-url-CUWWFME2.mjs} +1 -1
  366. package/dist/{public-url-CseXl9Fv.mjs.map → public-url-CUWWFME2.mjs.map} +1 -1
  367. package/dist/{query-axZmO6Tn.mjs → query-BJn8TOPk.mjs} +16 -13
  368. package/dist/{query-axZmO6Tn.mjs.map → query-BJn8TOPk.mjs.map} +1 -1
  369. package/dist/{rate-limit-t5CVjCO6.mjs → rate-limit-D_-gAeJ0.mjs} +2 -2
  370. package/dist/{rate-limit-t5CVjCO6.mjs.map → rate-limit-D_-gAeJ0.mjs.map} +1 -1
  371. package/dist/{redirect-DGRsLO2I.mjs → redirect-BINiRYq4.mjs} +1 -1
  372. package/dist/{redirect-DGRsLO2I.mjs.map → redirect-BINiRYq4.mjs.map} +1 -1
  373. package/dist/{redirect-DkaDxq8e.mjs → redirect-CNv4mHX2.mjs} +2 -2
  374. package/dist/{redirect-DkaDxq8e.mjs.map → redirect-CNv4mHX2.mjs.map} +1 -1
  375. package/dist/{redirects-D1fdd68T.mjs → redirects-B-CUZ1Xh.mjs} +3 -3
  376. package/dist/{redirects-D1fdd68T.mjs.map → redirects-B-CUZ1Xh.mjs.map} +1 -1
  377. package/dist/{redirects-Dmj6KRU3.mjs → redirects-COMLwsV5.mjs} +19 -5
  378. package/dist/redirects-COMLwsV5.mjs.map +1 -0
  379. package/dist/{registry-BnCeHYsf.mjs → registry-DqrAQDXH.mjs} +4 -4
  380. package/dist/{registry-BnCeHYsf.mjs.map → registry-DqrAQDXH.mjs.map} +1 -1
  381. package/dist/request-cache-dzCt8TZB.mjs.map +1 -1
  382. package/dist/request-context.mjs.map +1 -1
  383. package/dist/{request-meta-CLCwSQOS.mjs → request-meta-C_Cjii-T.mjs} +2 -2
  384. package/dist/{request-meta-CLCwSQOS.mjs.map → request-meta-C_Cjii-T.mjs.map} +1 -1
  385. package/dist/resolve-Cj98DuqN.mjs +39 -0
  386. package/dist/resolve-Cj98DuqN.mjs.map +1 -0
  387. package/dist/{runner-DdnQIwz_.mjs → runner-CGlojznK.mjs} +472 -165
  388. package/dist/runner-CGlojznK.mjs.map +1 -0
  389. package/dist/{runner-DcfZewkO.d.mts → runner-CNHRo1mT.d.mts} +2 -2
  390. package/dist/{runner-DcfZewkO.d.mts.map → runner-CNHRo1mT.d.mts.map} +1 -1
  391. package/dist/runtime.d.mts +10 -10
  392. package/dist/runtime.mjs +2 -2
  393. package/dist/{schema-BmqagCwG.mjs → schema-Djdlfi5G.mjs} +4 -4
  394. package/dist/{schema-BmqagCwG.mjs.map → schema-Djdlfi5G.mjs.map} +1 -1
  395. package/dist/{search-CPrvO5u8.mjs → search-By-NN3da.mjs} +4 -4
  396. package/dist/{search-CPrvO5u8.mjs.map → search-By-NN3da.mjs.map} +1 -1
  397. package/dist/{secrets-6pgZyq0K.mjs → secrets-rPdhEBkD.mjs} +1 -1
  398. package/dist/{secrets-6pgZyq0K.mjs.map → secrets-rPdhEBkD.mjs.map} +1 -1
  399. package/dist/{sections-Cm-zb-gZ.mjs → sections-DcBIlOq1.mjs} +3 -3
  400. package/dist/{sections-Cm-zb-gZ.mjs.map → sections-DcBIlOq1.mjs.map} +1 -1
  401. package/dist/seed/index.d.mts +2 -2
  402. package/dist/seed/index.mjs +16 -16
  403. package/dist/seo/index.d.mts +1 -1
  404. package/dist/{seo-DRq9-EPP.mjs → seo-bjDoq9Eg.mjs} +2 -2
  405. package/dist/{seo-DRq9-EPP.mjs.map → seo-bjDoq9Eg.mjs.map} +1 -1
  406. package/dist/{service-vByySp-2.mjs → service-BuuTdGAT.mjs} +3 -3
  407. package/dist/{service-vByySp-2.mjs.map → service-BuuTdGAT.mjs.map} +1 -1
  408. package/dist/{settings-CBBj7HUd.mjs → settings-CJnKiWuR.mjs} +3 -3
  409. package/dist/{settings-CBBj7HUd.mjs.map → settings-CJnKiWuR.mjs.map} +1 -1
  410. package/dist/{settings-xQKsWnzQ.mjs → settings-hcubRfkr.mjs} +3 -3
  411. package/dist/settings-hcubRfkr.mjs.map +1 -0
  412. package/dist/{setup-BGAJ2uXs.mjs → setup-Cf_TyOv5.mjs} +2 -2
  413. package/dist/{setup-BGAJ2uXs.mjs.map → setup-Cf_TyOv5.mjs.map} +1 -1
  414. package/dist/{setup-complete-C6ZCLhKo.mjs → setup-complete-MzzN9u0b.mjs} +1 -1
  415. package/dist/{setup-complete-C6ZCLhKo.mjs.map → setup-complete-MzzN9u0b.mjs.map} +1 -1
  416. package/dist/{setup-nonce-CY1gQiAU.mjs → setup-nonce-DXuriHsg.mjs} +1 -1
  417. package/dist/{setup-nonce-CY1gQiAU.mjs.map → setup-nonce-DXuriHsg.mjs.map} +1 -1
  418. package/dist/{site-url-D-M4Fd8O.mjs → site-url-xkhw1tcz.mjs} +1 -1
  419. package/dist/{site-url-D-M4Fd8O.mjs.map → site-url-xkhw1tcz.mjs.map} +1 -1
  420. package/dist/{ssrf-DzFN_qV-.mjs → ssrf-MZ-zrG6-.mjs} +1 -1
  421. package/dist/{ssrf-DzFN_qV-.mjs.map → ssrf-MZ-zrG6-.mjs.map} +1 -1
  422. package/dist/storage/local.d.mts +1 -1
  423. package/dist/storage/local.mjs +1 -1
  424. package/dist/storage/local.mjs.map +1 -1
  425. package/dist/storage/s3.d.mts +1 -1
  426. package/dist/storage/s3.mjs +1 -1
  427. package/dist/storage/s3.mjs.map +1 -1
  428. package/dist/{taxonomies-Dc0mzlms.mjs → taxonomies-CLs9HPE2.mjs} +4 -4
  429. package/dist/{taxonomies-Dc0mzlms.mjs.map → taxonomies-CLs9HPE2.mjs.map} +1 -1
  430. package/dist/{taxonomies-Cn9UpaR2.mjs → taxonomies-WamPVA2x.mjs} +7 -42
  431. package/dist/taxonomies-WamPVA2x.mjs.map +1 -0
  432. package/dist/{taxonomy-wPfusMK9.mjs → taxonomy-D4Uc2LsZ.mjs} +3 -3
  433. package/dist/{taxonomy-wPfusMK9.mjs.map → taxonomy-D4Uc2LsZ.mjs.map} +1 -1
  434. package/dist/{tokens-DILYNZMi.mjs → tokens-N8otWMmj.mjs} +1 -1
  435. package/dist/{tokens-DILYNZMi.mjs.map → tokens-N8otWMmj.mjs.map} +1 -1
  436. package/dist/{transport-fw-mKJzT.mjs → transport-B6CHddbu.mjs} +1 -1
  437. package/dist/{transport-fw-mKJzT.mjs.map → transport-B6CHddbu.mjs.map} +1 -1
  438. package/dist/{transport-GeXlLscf.d.mts → transport-DOxLfUir.d.mts} +1 -1
  439. package/dist/{transport-GeXlLscf.d.mts.map → transport-DOxLfUir.d.mts.map} +1 -1
  440. package/dist/{trusted-proxy-CJhQIk65.mjs → trusted-proxy-97pajC2f.mjs} +1 -1
  441. package/dist/{trusted-proxy-CJhQIk65.mjs.map → trusted-proxy-97pajC2f.mjs.map} +1 -1
  442. package/dist/{types-CwXMEPRr.mjs → types-ByV5sgsv.mjs} +2 -2
  443. package/dist/types-ByV5sgsv.mjs.map +1 -0
  444. package/dist/{types-Dz9CGX_d.mjs → types-Cd9UCu3t.mjs} +1 -1
  445. package/dist/{types-Dz9CGX_d.mjs.map → types-Cd9UCu3t.mjs.map} +1 -1
  446. package/dist/{types-DmxPPXGf.d.mts → types-CkDSF81F.d.mts} +1 -1
  447. package/dist/{types-DmxPPXGf.d.mts.map → types-CkDSF81F.d.mts.map} +1 -1
  448. package/dist/{types-BWhaSS7U.d.mts → types-CpUuGcd5.d.mts} +1 -1
  449. package/dist/{types-BWhaSS7U.d.mts.map → types-CpUuGcd5.d.mts.map} +1 -1
  450. package/dist/{types-DFowNO60.d.mts → types-D599-ruj.d.mts} +1 -1
  451. package/dist/{types-DFowNO60.d.mts.map → types-D599-ruj.d.mts.map} +1 -1
  452. package/dist/{types-B05e2naf.d.mts → types-DGHWRQgr.d.mts} +3 -3
  453. package/dist/{types-B05e2naf.d.mts.map → types-DGHWRQgr.d.mts.map} +1 -1
  454. package/dist/{types-CzvJd1ND.d.mts → types-DaYDYW6g.d.mts} +14 -1
  455. package/dist/types-DaYDYW6g.d.mts.map +1 -0
  456. package/dist/{types-C1KKK4VP.d.mts → types-DaqNzqVt.d.mts} +16 -1
  457. package/dist/{types-C1KKK4VP.d.mts.map → types-DaqNzqVt.d.mts.map} +1 -1
  458. package/dist/{types-DW1l0gCv.d.mts → types-Dgo6y-Ut.d.mts} +1 -1
  459. package/dist/{types-DW1l0gCv.d.mts.map → types-Dgo6y-Ut.d.mts.map} +1 -1
  460. package/dist/{types-Cb2UCDJg.d.mts → types-bYmRn_Uy.d.mts} +1 -1
  461. package/dist/{types-Cb2UCDJg.d.mts.map → types-bYmRn_Uy.d.mts.map} +1 -1
  462. package/dist/{user-Dr1bOCqS.mjs → user-D3BD5zdT.mjs} +2 -2
  463. package/dist/{user-Dr1bOCqS.mjs.map → user-D3BD5zdT.mjs.map} +1 -1
  464. package/dist/{utils-_F-rWBTN.mjs → utils-C3wTAP-P.mjs} +1 -1
  465. package/dist/{utils-_F-rWBTN.mjs.map → utils-C3wTAP-P.mjs.map} +1 -1
  466. package/dist/{validate-BpQGsmd7.d.mts → validate-DQtHw9NT.d.mts} +5 -5
  467. package/dist/{validate-BpQGsmd7.d.mts.map → validate-DQtHw9NT.d.mts.map} +1 -1
  468. package/dist/{validate-DlFxcVVK.mjs → validate-mz87i8_1.mjs} +2 -2
  469. package/dist/{validate-DlFxcVVK.mjs.map → validate-mz87i8_1.mjs.map} +1 -1
  470. package/dist/{validation-BiFJqUp5.mjs → validation-DKHhXjPr.mjs} +5 -5
  471. package/dist/{validation-BiFJqUp5.mjs.map → validation-DKHhXjPr.mjs.map} +1 -1
  472. package/dist/version-Ct7C6RSo.mjs +7 -0
  473. package/dist/{version-Dw7Z5PVU.mjs.map → version-Ct7C6RSo.mjs.map} +1 -1
  474. package/dist/{widgets-B9j_yzlk.mjs → widgets-lShIQXU5.mjs} +3 -3
  475. package/dist/widgets-lShIQXU5.mjs.map +1 -0
  476. package/dist/{zod-generator-DSyz01KE.mjs → zod-generator-dvxgmd1M.mjs} +2 -2
  477. package/dist/{zod-generator-DSyz01KE.mjs.map → zod-generator-dvxgmd1M.mjs.map} +1 -1
  478. package/package.json +10 -8
  479. package/src/api/error.ts +18 -3
  480. package/src/api/errors.ts +6 -0
  481. package/src/api/handlers/bylines.ts +161 -0
  482. package/src/api/handlers/content.ts +125 -43
  483. package/src/api/handlers/index.ts +6 -0
  484. package/src/api/handlers/marketplace.ts +27 -5
  485. package/src/api/handlers/oauth-clients.ts +1 -1
  486. package/src/api/handlers/registry.ts +568 -22
  487. package/src/api/openapi/document.ts +1 -1
  488. package/src/api/schemas/bylines.ts +46 -0
  489. package/src/astro/integration/index.ts +1 -1
  490. package/src/astro/integration/routes.ts +5 -0
  491. package/src/astro/integration/runtime.ts +12 -1
  492. package/src/astro/integration/virtual-modules.ts +19 -2
  493. package/src/astro/integration/vite-config.ts +2 -2
  494. package/src/astro/middleware/auth.ts +7 -7
  495. package/src/astro/middleware/request-context.ts +1 -1
  496. package/src/astro/middleware.ts +31 -20
  497. package/src/astro/routes/api/admin/bylines/[id]/index.ts +3 -12
  498. package/src/astro/routes/api/admin/bylines/[id]/translations.ts +99 -0
  499. package/src/astro/routes/api/admin/bylines/index.ts +22 -11
  500. package/src/astro/routes/api/admin/plugins/[id]/update.ts +1 -0
  501. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +6 -1
  502. package/src/astro/routes/api/admin/plugins/registry/[id]/uninstall.ts +51 -0
  503. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +79 -0
  504. package/src/astro/routes/api/admin/plugins/updates.ts +43 -6
  505. package/src/astro/routes/api/admin/themes/marketplace/index.ts +1 -1
  506. package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +2 -2
  507. package/src/astro/routes/api/auth/oauth/[provider].ts +2 -2
  508. package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +2 -2
  509. package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +2 -2
  510. package/src/astro/routes/api/content/[collection]/[id]/publish.ts +2 -2
  511. package/src/astro/routes/api/content/[collection]/[id]/restore.ts +2 -2
  512. package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +2 -2
  513. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +6 -6
  514. package/src/astro/routes/api/content/[collection]/[id]/translations.ts +1 -1
  515. package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +2 -2
  516. package/src/astro/routes/api/content/[collection]/[id].ts +6 -6
  517. package/src/astro/routes/api/import/wordpress/execute.ts +1 -1
  518. package/src/astro/routes/api/import/wordpress/prepare.ts +2 -2
  519. package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +3 -3
  520. package/src/astro/routes/api/import/wordpress-plugin/execute.ts +2 -2
  521. package/src/astro/routes/api/media/upload-url.ts +1 -1
  522. package/src/astro/routes/api/redirects/404s/index.ts +3 -3
  523. package/src/astro/routes/api/redirects/404s/summary.ts +1 -1
  524. package/src/astro/routes/api/redirects/[id].ts +3 -3
  525. package/src/astro/routes/api/redirects/index.ts +2 -2
  526. package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +4 -4
  527. package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +2 -6
  528. package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +1 -1
  529. package/src/astro/routes/api/schema/collections/[slug]/index.ts +6 -6
  530. package/src/astro/routes/api/schema/collections/index.ts +4 -4
  531. package/src/astro/routes/api/schema/index.ts +1 -1
  532. package/src/astro/routes/api/schema/orphans/[slug].ts +1 -1
  533. package/src/astro/routes/api/schema/orphans/index.ts +1 -1
  534. package/src/astro/routes/api/sections/[slug].ts +3 -3
  535. package/src/astro/routes/api/sections/index.ts +2 -2
  536. package/src/astro/types.ts +4 -0
  537. package/src/auth/rate-limit.ts +1 -1
  538. package/src/auth/trusted-proxy.ts +1 -1
  539. package/src/bylines/index.ts +154 -55
  540. package/src/cli/commands/init.ts +4 -8
  541. package/src/client/index.ts +1 -1
  542. package/src/components/InlinePortableTextEditor.tsx +5 -1
  543. package/src/components/inline-code-block.tsx +343 -0
  544. package/src/config/secrets.ts +3 -3
  545. package/src/database/migrations/006_taxonomy_defs.ts +1 -1
  546. package/src/database/migrations/014_draft_revisions.ts +6 -6
  547. package/src/database/migrations/040_byline_i18n.ts +497 -0
  548. package/src/database/migrations/runner.ts +4 -1
  549. package/src/database/repositories/audit.ts +2 -2
  550. package/src/database/repositories/byline.ts +320 -50
  551. package/src/database/repositories/media.ts +2 -2
  552. package/src/database/repositories/menu.ts +1 -1
  553. package/src/database/repositories/options.ts +3 -3
  554. package/src/database/repositories/plugin-storage.ts +3 -3
  555. package/src/database/repositories/types.ts +13 -0
  556. package/src/database/types.ts +15 -0
  557. package/src/emdash-runtime.ts +492 -20
  558. package/src/i18n/config.ts +1 -1
  559. package/src/index.ts +7 -0
  560. package/src/loader.ts +1 -1
  561. package/src/mcp/server.ts +3 -3
  562. package/src/media/mime.ts +1 -1
  563. package/src/page/absolute-url.ts +1 -1
  564. package/src/plugins/adapt-sandbox-entry.ts +45 -40
  565. package/src/plugins/email-console.ts +1 -1
  566. package/src/plugins/index.ts +1 -0
  567. package/src/plugins/marketplace.ts +1 -1
  568. package/src/plugins/sandbox/index.ts +1 -0
  569. package/src/plugins/sandbox/noop.ts +11 -3
  570. package/src/plugins/sandbox/types.ts +28 -0
  571. package/src/query.ts +17 -2
  572. package/src/registry/config.ts +1 -1
  573. package/src/request-cache.ts +3 -3
  574. package/src/request-context.ts +1 -1
  575. package/src/settings/index.ts +4 -4
  576. package/src/storage/local.ts +1 -1
  577. package/src/storage/s3.ts +3 -3
  578. package/src/widgets/index.ts +1 -1
  579. package/dist/api-ayIQ7rIe.mjs.map +0 -1
  580. package/dist/byline-D09BaS4j.mjs +0 -220
  581. package/dist/byline-D09BaS4j.mjs.map +0 -1
  582. package/dist/bylines-BTM2xtP8.mjs +0 -113
  583. package/dist/bylines-BTM2xtP8.mjs.map +0 -1
  584. package/dist/bylines-C6eYUWlZ.d.mts.map +0 -1
  585. package/dist/context-qF8d3IPR.mjs.map +0 -1
  586. package/dist/email-console-Dmp5Q-P2.mjs.map +0 -1
  587. package/dist/error-tSQWIl5U.mjs.map +0 -1
  588. package/dist/index-UmOMt9T-.d.mts.map +0 -1
  589. package/dist/loader-Cs6-Bqe6.mjs.map +0 -1
  590. package/dist/media-Dg7he9uK.mjs.map +0 -1
  591. package/dist/menus-DOzIecHi.mjs.map +0 -1
  592. package/dist/menus-X4Z-eBA1.mjs.map +0 -1
  593. package/dist/oauth-clients-D_B0_-Bz.mjs.map +0 -1
  594. package/dist/options-Cq64Wx0O.d.mts.map +0 -1
  595. package/dist/redirects-Dmj6KRU3.mjs.map +0 -1
  596. package/dist/runner-DdnQIwz_.mjs.map +0 -1
  597. package/dist/settings-xQKsWnzQ.mjs.map +0 -1
  598. package/dist/taxonomies-Cn9UpaR2.mjs.map +0 -1
  599. package/dist/types-CwXMEPRr.mjs.map +0 -1
  600. package/dist/types-CzvJd1ND.d.mts.map +0 -1
  601. package/dist/version-Dw7Z5PVU.mjs +0 -7
  602. package/dist/widgets-B9j_yzlk.mjs.map +0 -1
  603. /package/dist/{api-tokens-D3C9v02m.mjs → api-tokens-iPIHAY8N.mjs} +0 -0
  604. /package/dist/{ssrf-CTul4uQi.mjs → ssrf-BIcd-aXW.mjs} +0 -0
  605. /package/dist/{types-Db67HHlU.mjs → types-1NNkmTIn.mjs} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"execute.mjs","names":[],"sources":["../../../../../../src/import/wxr-taxonomies.ts","../../../../../../src/astro/routes/api/import/wordpress/execute.ts"],"sourcesContent":["/**\n * WXR taxonomy import helpers.\n *\n * Bridges parsed WordPress taxonomy data (`WxrCategory`, `WxrTag`, `WxrTerm`,\n * and per-item `WxrPost.categories` / `WxrPost.tags` / `WxrPost.customTaxonomies`)\n * onto EmDash's term + content_taxonomies tables.\n *\n * Why this isn't inline in `execute.ts`: pre-creating all terms before any\n * post is created lets us (a) build a lookup once for every (taxonomy, slug)\n * the import needs, and (b) keep the per-post attachment loop cheap. It also\n * makes the logic testable without spinning up an Astro request.\n *\n * Behaviour:\n * - `wp:category` -> EmDash `category` taxonomy (seeded by migration 006).\n * - `wp:tag` -> EmDash `tag` taxonomy.\n * - `wp:term` -> matching EmDash taxonomy by `name` (case-sensitive).\n * If no matching def exists in the target locale, the\n * term is skipped — we don't auto-create defs because\n * the user controls their schema through the admin.\n * - Terms are created idempotently by `(taxonomy, slug, locale)`. Existing\n * terms are reused.\n * - Assignments respect the def's `collections` array. If the post's target\n * collection isn't listed on the taxonomy def, the assignment is skipped\n * (matches admin UI behaviour: you can't tag a \"products\" post with a\n * \"category\" if `category.collections` only includes \"posts\").\n */\n\nimport type { Kysely } from \"kysely\";\n\nimport type { WxrCategory, WxrPost, WxrTag, WxrTerm } from \"../cli/wxr/parser.js\";\nimport { TaxonomyRepository } from \"../database/repositories/taxonomy.js\";\nimport type { Database } from \"../database/types.js\";\nimport { resolveLocaleChain } from \"../i18n/resolve.js\";\nimport { invalidateTermCache } from \"../taxonomies/index.js\";\n\n/**\n * Thrown by `mirrorTermsToLocales` when a pre-existing locale row at the\n * same `(taxonomy, slug)` belongs to a different `translation_group` than\n * the canonical term. Callers in the route layer surface\n * `publicMessage` to the operator (no internal data) while logging\n * `cause` server-side.\n *\n * Marker class so the route layer can distinguish \"operator-actionable\n * taxonomy conflict\" from any other DB / repository error that might\n * escape the helper.\n */\nexport class WxrTaxonomyConflictError extends Error {\n\treadonly publicMessage: string;\n\tconstructor(publicMessage: string, options?: { cause?: unknown }) {\n\t\tsuper(publicMessage, options);\n\t\tthis.name = \"WxrTaxonomyConflictError\";\n\t\tthis.publicMessage = publicMessage;\n\t}\n}\n\nexport function isWxrTaxonomyConflictError(error: unknown): error is WxrTaxonomyConflictError {\n\treturn error instanceof WxrTaxonomyConflictError;\n}\n\n/**\n * Result of pre-importing taxonomy terms from a WXR file.\n */\nexport interface TaxonomyImportPlan {\n\t/** terms created during this run (per taxonomy name) */\n\ttermsCreated: Record<string, number>;\n\t/** terms that already existed and were reused (per taxonomy name) */\n\ttermsReused: Record<string, number>;\n\t/** custom taxonomies (`wp:term`) skipped because no matching EmDash def exists */\n\tmissingTaxonomies: string[];\n\t/**\n\t * Lookup table: `taxonomy name` -> `term slug` -> term id.\n\t * Used by `attachPostTaxonomies` to translate WXR assignments into pivot rows.\n\t */\n\ttermIdByNameAndSlug: Map<string, Map<string, string>>;\n\t/**\n\t * Lookup table: `taxonomy name` -> set of collection slugs the def allows.\n\t * Empty (or missing) means \"any collection\" — we only enforce the filter\n\t * when the def explicitly lists collections.\n\t */\n\tcollectionsByTaxonomy: Map<string, Set<string>>;\n\t/**\n\t * Lookup table: `term id` -> the term's `translation_group` (or `null`\n\t * if the term doesn't exist any more). Populated lazily by helpers that\n\t * need to check pivot existence without repeating per-term DB reads.\n\t */\n\ttranslationGroupByTermId: Map<string, string | null>;\n}\n\n/**\n * Track running counts plus the lookup maps.\n */\ninterface TaxonomyImportState {\n\tplan: TaxonomyImportPlan;\n}\n\nfunction makeState(): TaxonomyImportState {\n\treturn {\n\t\tplan: {\n\t\t\ttermsCreated: {},\n\t\t\ttermsReused: {},\n\t\t\tmissingTaxonomies: [],\n\t\t\ttermIdByNameAndSlug: new Map(),\n\t\t\tcollectionsByTaxonomy: new Map(),\n\t\t\ttranslationGroupByTermId: new Map(),\n\t\t},\n\t};\n}\n\n/**\n * Record-keeping helpers — keep mutations centralised so the result object\n * stays consistent.\n */\nfunction bump(record: Record<string, number>, key: string): void {\n\trecord[key] = (record[key] ?? 0) + 1;\n}\n\nfunction rememberTerm(\n\tstate: TaxonomyImportState,\n\ttaxonomyName: string,\n\tslug: string,\n\ttermId: string,\n): void {\n\tlet bySlug = state.plan.termIdByNameAndSlug.get(taxonomyName);\n\tif (!bySlug) {\n\t\tbySlug = new Map();\n\t\tstate.plan.termIdByNameAndSlug.set(taxonomyName, bySlug);\n\t}\n\tbySlug.set(slug, termId);\n}\n\n/**\n * Look up an EmDash taxonomy def by name. Definitions are per-locale but\n * a def is conceptually site-wide -- the per-locale row carries only the\n * label translations.\n *\n * Match the runtime helper `getTaxonomyDef` (in `src/taxonomies/index.ts`):\n * walk `resolveLocaleChain(locale)` so the importer picks the same def the\n * runtime would later resolve to. When the chain is empty (i18n disabled)\n * or every locale in the chain misses, fall through to the lowest-locale\n * row so single-locale installs still see seeded defs that were inserted\n * at some non-empty locale value.\n *\n * Without this fallback, a user importing into a non-default locale would\n * see every category dropped as `missingTaxonomies` even though the seeded\n * defs exist (just at the site's default locale).\n */\nfunction parseDefCollections(raw: string | null): string[] {\n\tif (!raw) return [];\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(raw);\n\t\tif (Array.isArray(parsed)) {\n\t\t\treturn parsed.filter((c): c is string => typeof c === \"string\");\n\t\t}\n\t} catch {\n\t\t// malformed JSON in the def -- treat as \"no collection filter\"\n\t}\n\treturn [];\n}\n\nasync function findTaxonomyDef(\n\tdb: Kysely<Database>,\n\tname: string,\n\tlocale: string | undefined,\n): Promise<{ id: string; collections: string[] } | null> {\n\tconst chain = resolveLocaleChain(locale);\n\n\tif (chain.length === 0) {\n\t\t// i18n disabled and no explicit locale. The runtime treats this\n\t\t// as \"no locale filter\" and picks the lowest-locale row. We do the\n\t\t// same so the importer agrees with how the runtime later reads\n\t\t// the def.\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.executeTakeFirst();\n\t\treturn row ? { id: row.id, collections: parseDefCollections(row.collections) } : null;\n\t}\n\n\t// Non-empty chain: walk it in order, return null if every entry misses.\n\t// This matches `getTaxonomyDef` exactly. We deliberately do NOT fall\n\t// through to any-locale lookup: doing so would let the importer pick a\n\t// def at a locale the runtime would never resolve to, producing\n\t// content the user can't see in the admin or on the rendered site.\n\tfor (const tryLocale of chain) {\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.where(\"locale\", \"=\", tryLocale)\n\t\t\t.executeTakeFirst();\n\t\tif (row) {\n\t\t\treturn { id: row.id, collections: parseDefCollections(row.collections) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Find or create a term in the given taxonomy. Returns the term id. Callers\n * must verify the taxonomy def exists before calling — this helper assumes\n * the def is present.\n *\n * Note: we don't resolve WordPress parent slugs into EmDash parent ids in\n * this pass. WXR exports list categories in arbitrary order, so a category's\n * parent may not exist yet when we first see it. Hierarchy is preserved at\n * the data level (the parent slug is on `WxrCategory.parent`) but flattens\n * in EmDash for now; restoring the tree is a follow-up improvement.\n */\nasync function ensureTerm(\n\trepo: TaxonomyRepository,\n\tstate: TaxonomyImportState,\n\ttaxonomyName: string,\n\tslug: string,\n\tlabel: string,\n\tdescription: string | undefined,\n\tlocale: string | undefined,\n): Promise<string> {\n\t// Already resolved in this run (e.g. seen in `wp:category` AND in a per-\n\t// item `<category>` element).\n\tconst cached = state.plan.termIdByNameAndSlug.get(taxonomyName)?.get(slug);\n\tif (cached) return cached;\n\n\tconst existing = await repo.findBySlug(taxonomyName, slug, locale);\n\tif (existing) {\n\t\tbump(state.plan.termsReused, taxonomyName);\n\t\trememberTerm(state, taxonomyName, slug, existing.id);\n\t\treturn existing.id;\n\t}\n\n\t// No row at the requested locale. Before creating, check whether a\n\t// `(name, slug)` row exists in some OTHER locale -- e.g. the admin\n\t// pre-created an Arabic translation, and now an `en` import wants the\n\t// canonical row. We need to mint the new row inside the existing row's\n\t// `translation_group` so per-locale lookups across the family work.\n\t// Without this, the mirror pass would later refuse to reconcile (it\n\t// sees pre-existing rows in a different group as a no-op) and pivots\n\t// would point at a group that has no row in the requested locale.\n\tconst anyLocale = await repo.findBySlug(taxonomyName, slug);\n\tconst translationOf = anyLocale?.id;\n\n\tconst created = await repo.create({\n\t\tname: taxonomyName,\n\t\tslug,\n\t\tlabel,\n\t\tdata: description ? { description } : undefined,\n\t\tlocale,\n\t\ttranslationOf,\n\t});\n\tbump(state.plan.termsCreated, taxonomyName);\n\trememberTerm(state, taxonomyName, slug, created.id);\n\treturn created.id;\n}\n\n/**\n * Retrieve the human label captured by the parser for a per-item\n * `<category>` text body, falling back to the slug when the parser didn't\n * see a label (e.g. self-closing tags or whitespace-only bodies).\n */\nfunction labelFor(post: WxrPost, taxonomy: string, slug: string): string {\n\tconst key = `${taxonomy}\\u0000${slug}`;\n\treturn post.taxonomyLabels?.get(key) ?? slug;\n}\n\n/**\n * Pre-import every term referenced by the WXR file.\n *\n * Pass 1: `wp:category` blocks. Each becomes a term in EmDash's seeded\n * `category` taxonomy.\n * Pass 2: `wp:tag` blocks. Each becomes a term in `tag`.\n * Pass 3: `wp:term` blocks (custom taxonomies). Skipped when no matching\n * EmDash def exists.\n * Pass 4: per-item `<category domain=\"…\" nicename=\"…\">` assignments. WXR\n * exports sometimes reference taxonomies/terms that weren't declared\n * at the top level (older exports especially), so we backfill terms\n * from per-item assignments. Categories and tags use the seeded defs\n * and pick up the assignment text as the label; custom domains fall\n * back to the same \"def must exist\" rule.\n */\nexport async function preImportWxrTaxonomies(\n\tdb: Kysely<Database>,\n\tposts: WxrPost[],\n\tcategories: WxrCategory[],\n\ttags: WxrTag[],\n\tterms: WxrTerm[],\n\tlocale: string | undefined,\n): Promise<TaxonomyImportPlan> {\n\tconst state = makeState();\n\tconst repo = new TaxonomyRepository(db);\n\n\t// Cache def lookups for the duration of the import. Keyed by name; value\n\t// is `null` when we've already determined the def is missing in this\n\t// locale (so we only report the \"missing\" warning once per taxonomy).\n\tconst defCache = new Map<string, { id: string; collections: string[] } | null>();\n\tconst lookupDef = async (name: string): Promise<{ id: string; collections: string[] } | null> => {\n\t\tif (defCache.has(name)) return defCache.get(name) ?? null;\n\t\tconst def = await findTaxonomyDef(db, name, locale);\n\t\tdefCache.set(name, def);\n\t\tif (def) {\n\t\t\tstate.plan.collectionsByTaxonomy.set(name, new Set(def.collections));\n\t\t}\n\t\treturn def;\n\t};\n\n\t// Pass 1: top-level <wp:category> blocks -> EmDash `category` taxonomy.\n\tconst categoryDef = await lookupDef(\"category\");\n\tif (categoryDef) {\n\t\tfor (const cat of categories) {\n\t\t\tconst slug = cat.nicename;\n\t\t\tconst label = cat.name;\n\t\t\tif (!slug || !label) continue;\n\t\t\tawait ensureTerm(repo, state, \"category\", slug, label, cat.description, locale);\n\t\t}\n\t} else if (categories.length > 0) {\n\t\t// Seeded `category` def was deleted by the user — record so the\n\t\t// import response can surface why none of the categories landed.\n\t\tstate.plan.missingTaxonomies.push(\"category\");\n\t}\n\n\t// Pass 2: top-level <wp:tag> blocks -> EmDash `tag` taxonomy.\n\tconst tagDef = await lookupDef(\"tag\");\n\tif (tagDef) {\n\t\tfor (const tag of tags) {\n\t\t\tconst slug = tag.slug;\n\t\t\tconst label = tag.name;\n\t\t\tif (!slug || !label) continue;\n\t\t\tawait ensureTerm(repo, state, \"tag\", slug, label, tag.description, locale);\n\t\t}\n\t} else if (tags.length > 0) {\n\t\tstate.plan.missingTaxonomies.push(\"tag\");\n\t}\n\n\t// Pass 3: <wp:term> blocks for custom taxonomies (genre, etc.). Skipped:\n\t// - `nav_menu`: menus are handled by `importMenusFromWxr`.\n\t// - `language`: Polylang's locale signal; promoted to `WxrPost.locale`\n\t// by the parser and not a content taxonomy in EmDash.\n\tfor (const term of terms) {\n\t\tif (term.taxonomy === \"nav_menu\" || term.taxonomy === \"language\") continue;\n\t\t// Normalize WordPress' `post_tag` synonym -> EmDash `tag`. WordPress\n\t\t// emits `<wp:tag>` for some exports and `<wp:term wp:term_taxonomy=\"post_tag\">`\n\t\t// for others; both must land in the same EmDash taxonomy.\n\t\tconst taxonomyName = term.taxonomy === \"post_tag\" ? \"tag\" : term.taxonomy;\n\t\tconst def = await lookupDef(taxonomyName);\n\t\tif (!def) {\n\t\t\tif (!state.plan.missingTaxonomies.includes(taxonomyName)) {\n\t\t\t\tstate.plan.missingTaxonomies.push(taxonomyName);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tawait ensureTerm(repo, state, taxonomyName, term.slug, term.name, term.description, locale);\n\t}\n\n\t// Pass 4: per-item assignments. Backfills terms missing from the top-\n\t// level blocks (rare, but observed in hand-edited or partial exports).\n\t// Labels come from the per-item `<category>` text body when the parser\n\t// captured one; otherwise we fall back to the slug. This is the path\n\t// for older exports that skip top-level `<wp:category>` definitions.\n\tlet recordedMissingCategoryFromPosts = false;\n\tlet recordedMissingTagFromPosts = false;\n\tfor (const post of posts) {\n\t\tfor (const slug of post.categories) {\n\t\t\tif (!categoryDef) {\n\t\t\t\tif (\n\t\t\t\t\t!recordedMissingCategoryFromPosts &&\n\t\t\t\t\t!state.plan.missingTaxonomies.includes(\"category\")\n\t\t\t\t) {\n\t\t\t\t\tstate.plan.missingTaxonomies.push(\"category\");\n\t\t\t\t\trecordedMissingCategoryFromPosts = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (state.plan.termIdByNameAndSlug.get(\"category\")?.has(slug)) continue;\n\t\t\tawait ensureTerm(\n\t\t\t\trepo,\n\t\t\t\tstate,\n\t\t\t\t\"category\",\n\t\t\t\tslug,\n\t\t\t\tlabelFor(post, \"category\", slug),\n\t\t\t\tundefined,\n\t\t\t\tlocale,\n\t\t\t);\n\t\t}\n\t\tfor (const slug of post.tags) {\n\t\t\tif (!tagDef) {\n\t\t\t\tif (!recordedMissingTagFromPosts && !state.plan.missingTaxonomies.includes(\"tag\")) {\n\t\t\t\t\tstate.plan.missingTaxonomies.push(\"tag\");\n\t\t\t\t\trecordedMissingTagFromPosts = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (state.plan.termIdByNameAndSlug.get(\"tag\")?.has(slug)) continue;\n\t\t\tawait ensureTerm(repo, state, \"tag\", slug, labelFor(post, \"tag\", slug), undefined, locale);\n\t\t}\n\t\tif (post.customTaxonomies) {\n\t\t\tfor (const [rawName, slugs] of post.customTaxonomies) {\n\t\t\t\t// `nav_menu` is handled by the menu importer; `language` is\n\t\t\t\t// Polylang's per-post locale signal, already promoted by the\n\t\t\t\t// parser.\n\t\t\t\tif (rawName === \"nav_menu\" || rawName === \"language\") continue;\n\t\t\t\tconst taxonomyName = rawName === \"post_tag\" ? \"tag\" : rawName;\n\t\t\t\tconst def = await lookupDef(taxonomyName);\n\t\t\t\tif (!def) {\n\t\t\t\t\tif (!state.plan.missingTaxonomies.includes(taxonomyName)) {\n\t\t\t\t\t\tstate.plan.missingTaxonomies.push(taxonomyName);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (const slug of slugs) {\n\t\t\t\t\tif (state.plan.termIdByNameAndSlug.get(taxonomyName)?.has(slug)) continue;\n\t\t\t\t\tawait ensureTerm(\n\t\t\t\t\t\trepo,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\ttaxonomyName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tlabelFor(post, taxonomyName, slug),\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tlocale,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// `content_taxonomies` writes happen later in `attachPostTaxonomies`, but\n\t// term inserts above already invalidate the in-memory \"has any terms\" probe.\n\t// We flush once at the end of the pre-import to keep the runtime cache hot.\n\tinvalidateTermCache();\n\n\treturn state.plan;\n}\n\n/**\n * Walk a parsed WXR post's per-item taxonomy assignments and return only\n * the ones that resolve to a real EmDash term AND aren't filtered out by\n * the taxonomy def's `collections` allowlist. Grouped by EmDash taxonomy\n * name (so `post_tag` is already folded into `tag`). Deduplicated.\n *\n * This is the single source of truth for \"what will the importer try to\n * write for this post\". Both the anchor (additive `attachToEntry`) and\n * translation (per-taxonomy `setTermsForEntry`) paths drive from this map\n * so they agree on which taxonomies need touching. In particular, the\n * translation path uses the keys here -- not `postAssignedTaxonomies` --\n * to decide which inherited pivot rows to clear, so a translation whose\n * only assignment is filtered out by `collections` doesn't lose its\n * inherited terms (see #1087 review feedback).\n *\n * Skipped taxonomies: `nav_menu` (handled by the menu importer) and\n * `language` (Polylang's locale signal, already promoted to `post.locale`\n * by the parser).\n */\nexport function resolvePostTermAssignments(\n\tcollection: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Map<string, string[]> {\n\tconst result = new Map<string, string[]>();\n\tconst seen = new Set<string>();\n\n\tconst tryResolve = (taxonomyName: string, slug: string): void => {\n\t\tconst termId = plan.termIdByNameAndSlug.get(taxonomyName)?.get(slug);\n\t\tif (!termId) return;\n\t\tconst collectionFilter = plan.collectionsByTaxonomy.get(taxonomyName);\n\t\t// Empty set means \"no filter\" (def has no collections array). A\n\t\t// non-empty set is enforced: skip assignments to collections the\n\t\t// def doesn't list. Matches admin UI: a `category` term linked\n\t\t// only to `posts` shouldn't end up on a `products` row just\n\t\t// because the WXR happened to mention it.\n\t\tif (collectionFilter && collectionFilter.size > 0 && !collectionFilter.has(collection)) {\n\t\t\treturn;\n\t\t}\n\t\tconst dedupeKey = `${taxonomyName}\\u0000${termId}`;\n\t\tif (seen.has(dedupeKey)) return;\n\t\tseen.add(dedupeKey);\n\t\tconst existing = result.get(taxonomyName);\n\t\tif (existing) existing.push(termId);\n\t\telse result.set(taxonomyName, [termId]);\n\t};\n\n\tfor (const slug of post.categories) tryResolve(\"category\", slug);\n\tfor (const slug of post.tags) tryResolve(\"tag\", slug);\n\tif (post.customTaxonomies) {\n\t\tfor (const [rawName, slugs] of post.customTaxonomies) {\n\t\t\tif (rawName === \"nav_menu\" || rawName === \"language\") continue;\n\t\t\tconst taxonomyName = rawName === \"post_tag\" ? \"tag\" : rawName;\n\t\t\tfor (const slug of slugs) tryResolve(taxonomyName, slug);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Attach the taxonomy assignments parsed for a single WXR post to a freshly-\n * created EmDash content row. Additive (`attachToEntry` + `ON CONFLICT DO\n * NOTHING`). Used for anchors -- translations need replace-semantics per\n * taxonomy and should use `setPostTermAssignmentsReplacing` instead.\n *\n * Returns the number of pivot rows actually inserted (excludes rows that\n * already existed via the `ON CONFLICT DO NOTHING` path), so the caller can\n * roll them up into the import summary without over-counting on re-imports.\n */\nexport async function attachPostTaxonomies(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Promise<number> {\n\tconst repo = new TaxonomyRepository(db);\n\tconst resolved = resolvePostTermAssignments(collection, post, plan);\n\n\tlet attached = 0;\n\tfor (const [, termIds] of resolved) {\n\t\tfor (const termId of termIds) {\n\t\t\tconst wrote = await attachToEntryCountingInserts(db, repo, plan, collection, entryId, termId);\n\t\t\tif (wrote) attached++;\n\t\t}\n\t}\n\treturn attached;\n}\n\n/**\n * Replace assignments per-taxonomy from a parsed WXR post. Used for\n * translations: WPML's \"Translate Independently\" mode lets translators\n * override term assignments per-taxonomy, not per-post. A translation that\n * overrides `category` shouldn't lose its inherited `tag` or `genre`. We\n * only call `setTermsForEntry(name, ids)` for taxonomies where the\n * translation actually resolved at least one term -- taxonomies with no\n * resolvable+permitted terms are left alone so inherited rows from\n * `copyEntryTerms` stay intact.\n *\n * Returns the number of pivot rows after replacement (sum of `termIds`\n * lists across taxonomies actually touched). Note this counts logical\n * assignments, not the delta from the prior state; the import summary\n * treats this as an additive count for compatibility with `attachPost-\n * Taxonomies`.\n */\nexport async function setPostTermAssignmentsReplacing(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Promise<number> {\n\tconst repo = new TaxonomyRepository(db);\n\tconst resolved = resolvePostTermAssignments(collection, post, plan);\n\n\tlet attached = 0;\n\tfor (const [taxonomyName, termIds] of resolved) {\n\t\tawait repo.setTermsForEntry(collection, entryId, taxonomyName, termIds);\n\t\tattached += termIds.length;\n\t}\n\treturn attached;\n}\n\n/**\n * Resolve a term id to its `translation_group` (the value\n * `content_taxonomies` stores). Caches the result on the plan so\n * repeated attaches of the same term don't repeat the lookup.\n */\nasync function termTranslationGroup(\n\trepo: TaxonomyRepository,\n\tplan: TaxonomyImportPlan,\n\ttermId: string,\n): Promise<string | null> {\n\tconst cached = plan.translationGroupByTermId.get(termId);\n\tif (cached !== undefined) return cached;\n\tconst term = await repo.findById(termId);\n\tconst group = term?.translationGroup ?? null;\n\tplan.translationGroupByTermId.set(termId, group);\n\treturn group;\n}\n\n/**\n * Wrapper around `TaxonomyRepository.attachToEntry` that returns whether\n * an actual row was inserted (vs. silently skipped by the `ON CONFLICT DO\n * NOTHING` branch). Lets the importer's `assignments` counter reflect real\n * writes rather than re-import no-ops.\n *\n * Best-effort: we check pivot existence first, then call `attachToEntry`.\n * A concurrent insert between the check and the attach would make us\n * report `false` while a row was in fact inserted -- the count is for\n * summary display only, never correctness.\n */\nasync function attachToEntryCountingInserts(\n\tdb: Kysely<Database>,\n\trepo: TaxonomyRepository,\n\tplan: TaxonomyImportPlan,\n\tcollection: string,\n\tentryId: string,\n\ttermId: string,\n): Promise<boolean> {\n\tconst group = await termTranslationGroup(repo, plan, termId);\n\tif (!group) return false;\n\n\tconst existing = await db\n\t\t.selectFrom(\"content_taxonomies\")\n\t\t.select(\"collection\")\n\t\t.where(\"collection\", \"=\", collection)\n\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t.where(\"taxonomy_id\", \"=\", group)\n\t\t.executeTakeFirst();\n\tif (existing) return false;\n\n\tawait repo.attachToEntry(collection, entryId, termId);\n\treturn true;\n}\n\n/**\n * Mirror every term in the plan into each additional locale used by the\n * incoming posts. New rows share the canonical term's `translation_group`\n * so per-locale lookups (`getTermsForEntry(..., locale)`) resolve correctly\n * for translations whose locale differs from the import-wide one.\n *\n * Without this pass, multilingual WXR imports (#1080) write all term rows\n * at the upload-wide locale; the `content_taxonomies` pivot is correct (it\n * stores `translation_group`, not `term id`), but\n * `getTermsForEntry(collection, arabicPostId, \"category\", \"ar\")` filters on\n * `taxonomies.locale = \"ar\"` and returns zero rows. Users see \"no tags\" on\n * every non-canonical translation.\n *\n * Idempotent: skips a locale when a row already exists at `(name, slug,\n * locale)`. Safe to call after `preImportWxrTaxonomies` on subsequent\n * imports.\n */\nexport async function mirrorTermsToLocales(\n\tdb: Kysely<Database>,\n\tplan: TaxonomyImportPlan,\n\tpostLocales: Iterable<string>,\n\tcanonicalLocale: string | undefined,\n): Promise<void> {\n\tconst localeSet = new Set<string>();\n\tfor (const locale of postLocales) {\n\t\tif (!locale || locale === canonicalLocale) continue;\n\t\tlocaleSet.add(locale);\n\t}\n\tif (localeSet.size === 0) return;\n\n\tconst repo = new TaxonomyRepository(db);\n\n\tfor (const [taxonomyName, bySlug] of plan.termIdByNameAndSlug) {\n\t\tfor (const [slug, canonicalTermId] of bySlug) {\n\t\t\t// Resolve the canonical's translation_group once; we'll compare\n\t\t\t// against any pre-existing rows we find at the target locales.\n\t\t\t// Cache on the plan so subsequent attaches (which also need\n\t\t\t// this resolution) don't repeat the lookup.\n\t\t\tconst cachedGroup = await termTranslationGroup(repo, plan, canonicalTermId);\n\t\t\tif (!cachedGroup) {\n\t\t\t\t// The canonical term id is in the plan but the row is no\n\t\t\t\t// longer in the DB. Shouldn't happen during a single\n\t\t\t\t// import run; skip rather than crash so the rest of the\n\t\t\t\t// import can complete.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst canonicalGroup = cachedGroup;\n\n\t\t\tfor (const locale of localeSet) {\n\t\t\t\tconst existing = await repo.findBySlug(taxonomyName, slug, locale);\n\t\t\t\tif (existing) {\n\t\t\t\t\t// `ensureTerm` resolves cross-locale grouping when it\n\t\t\t\t\t// creates the canonical row, so a pre-existing sibling\n\t\t\t\t\t// row at this locale should already share the\n\t\t\t\t\t// canonical's `translation_group`. If it doesn't, the\n\t\t\t\t\t// import would write pivots pointing at a group that\n\t\t\t\t\t// has no row in this locale -- a silent data-integrity\n\t\t\t\t\t// bug. Fail closed: throw so the operator reconciles\n\t\t\t\t\t// the existing rows in the admin before retrying. This\n\t\t\t\t\t// happens when the canonical row was created in an\n\t\t\t\t\t// earlier import and a sibling-locale row was added\n\t\t\t\t\t// manually afterwards (or vice versa) without linking\n\t\t\t\t\t// them via translationOf.\n\t\t\t\t\tif (existing.translationGroup !== canonicalGroup) {\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" already exists at locale \"${locale}\" in a different translation group than the canonical row at this import's locale. Reconcile the rows in the admin (re-link via translationOf, or delete one) and retry.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait repo.create({\n\t\t\t\t\t\tname: taxonomyName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tlabel: slug, // we don't have a per-locale label from the WXR\n\t\t\t\t\t\tlocale,\n\t\t\t\t\t\ttranslationOf: canonicalTermId,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// `findBySlug` + `create` is not atomic. A concurrent\n\t\t\t\t\t// import racing us into the same `(name, slug, locale)`\n\t\t\t\t\t// will trip the UNIQUE constraint. Re-read the row that\n\t\t\t\t\t// won the race and verify its `translation_group`\n\t\t\t\t\t// matches the canonical's; if not, the pivot will\n\t\t\t\t\t// resolve to a group that has no row in this locale\n\t\t\t\t\t// (silent data-integrity bug) so we surface that loudly\n\t\t\t\t\t// rather than continue.\n\t\t\t\t\t//\n\t\t\t\t\t// Other errors (validation, connectivity) re-throw so\n\t\t\t\t\t// the import fails closed rather than silently shipping\n\t\t\t\t\t// translations that resolve to empty taxonomy queries.\n\t\t\t\t\tconst message = error instanceof Error ? error.message.toLowerCase() : \"\";\n\t\t\t\t\tconst isUniqueRace =\n\t\t\t\t\t\tmessage.includes(\"unique constraint failed\") || message.includes(\"duplicate key\");\n\t\t\t\t\tif (!isUniqueRace) throw error;\n\n\t\t\t\t\tconst winner = await repo.findBySlug(taxonomyName, slug, locale);\n\t\t\t\t\tif (!winner) {\n\t\t\t\t\t\t// UNIQUE conflict but no row visible? Shouldn't\n\t\t\t\t\t\t// happen unless the racing transaction rolled back;\n\t\t\t\t\t\t// fail loudly so the operator can investigate.\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" raced UNIQUE at locale \"${locale}\" but no row is visible afterwards. The concurrent transaction may have rolled back; retry the import.`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (winner.translationGroup !== canonicalGroup) {\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" raced UNIQUE at locale \"${locale}\" with a different translation group. Reconcile the rows in the admin and retry.`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[WXR import] concurrent writer beat us to term \"${taxonomyName}/${slug}\" at locale \"${locale}\"; using existing row (same group).`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * WordPress WXR execute import endpoint\n *\n * POST /_emdash/api/import/wordpress/execute\n *\n * Accepts WXR file and import configuration, imports content into the database.\n */\n\nimport { gutenbergToPortableText } from \"@emdash-cms/gutenberg-to-portable-text\";\nimport type { APIRoute } from \"astro\";\nimport {\n\tparseWxrString,\n\tContentRepository,\n\timportReusableBlocksAsSections,\n\ttype WxrPost,\n\tparseWxrDate,\n} from \"emdash\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { BylineRepository } from \"#db/repositories/byline.js\";\nimport { resolveImportByline } from \"#import/utils.js\";\nimport {\n\tattachPostTaxonomies,\n\tisWxrTaxonomyConflictError,\n\tmirrorTermsToLocales,\n\tpreImportWxrTaxonomies,\n\tsetPostTermAssignmentsReplacing,\n\ttype TaxonomyImportPlan,\n} from \"#import/wxr-taxonomies.js\";\nimport type { EmDashHandlers, EmDashManifest } from \"#types\";\nimport { slugify } from \"#utils/slugify.js\";\n\nimport { sanitizeSlug } from \"./analyze.js\";\n\nexport const prerender = false;\n\nexport interface ImportConfig {\n\t/** Map WordPress post types to EmDash collections */\n\tpostTypeMappings: Record<\n\t\tstring,\n\t\t{\n\t\t\tcollection: string;\n\t\t\tenabled: boolean;\n\t\t}\n\t>;\n\t/** Whether to skip items that already exist (by slug) */\n\tskipExisting: boolean;\n\t/** Whether to import reusable blocks (wp_block) as sections */\n\timportSections?: boolean;\n\t/** Author mappings (WP author login -> EmDash user ID) */\n\tauthorMappings?: Record<string, string | null>;\n\t/** BCP 47 locale for all imported items. When omitted, defaults to defaultLocale. */\n\tlocale?: string;\n}\n\nexport interface ImportResult {\n\tsuccess: boolean;\n\timported: number;\n\tskipped: number;\n\terrors: Array<{ title: string; error: string }>;\n\tbyCollection: Record<string, number>;\n\t/** Sections import results (if enabled) */\n\tsections?: {\n\t\tcreated: number;\n\t\tskipped: number;\n\t};\n\t/** Taxonomy import results (categories, tags, custom taxonomies). */\n\ttaxonomies?: {\n\t\t/** Terms newly created during this import, keyed by taxonomy name. */\n\t\ttermsCreated: Record<string, number>;\n\t\t/** Existing terms that were re-used, keyed by taxonomy name. */\n\t\ttermsReused: Record<string, number>;\n\t\t/** Total pivot rows (post <-> term) written to `content_taxonomies`. */\n\t\tassignments: number;\n\t\t/**\n\t\t * Custom taxonomy names from the WXR file that had no matching EmDash\n\t\t * definition and were therefore skipped. Lets the admin UI surface a\n\t\t * \"create taxonomy X first\" hint without re-running the import.\n\t\t */\n\t\tmissingTaxonomies: string[];\n\t};\n}\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\tif (!emdash?.handleContentCreate) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash not configured\", 500);\n\t}\n\n\ttry {\n\t\tconst emdashManifest = await emdash.getManifest();\n\n\t\tconst formData = await request.formData();\n\t\tconst fileEntry = formData.get(\"file\");\n\t\tconst file = fileEntry instanceof File ? fileEntry : null;\n\t\tconst configEntry = formData.get(\"config\");\n\t\tconst configJson = typeof configEntry === \"string\" ? configEntry : null;\n\n\t\tif (!file) {\n\t\t\treturn apiError(\"VALIDATION_ERROR\", \"No file provided\", 400);\n\t\t}\n\n\t\tif (!configJson) {\n\t\t\treturn apiError(\"VALIDATION_ERROR\", \"No config provided\", 400);\n\t\t}\n\n\t\tconst config: ImportConfig = JSON.parse(configJson);\n\n\t\t// Parse WXR\n\t\tconst text = await file.text();\n\t\tconst wxr = await parseWxrString(text);\n\n\t\t// Build attachment ID -> URL map for featured images\n\t\tconst attachmentMap = new Map<string, string>();\n\t\tfor (const att of wxr.attachments) {\n\t\t\tif (att.id && att.url) {\n\t\t\t\tattachmentMap.set(String(att.id), att.url);\n\t\t\t}\n\t\t}\n\n\t\t// Build author login -> display name map\n\t\tconst authorDisplayNames = new Map<string, string>();\n\t\tfor (const author of wxr.authors) {\n\t\t\tif (!author.login) continue;\n\t\t\tauthorDisplayNames.set(author.login, author.displayName || author.login);\n\t\t}\n\n\t\t// Pre-create taxonomy terms (categories, tags, custom taxonomies) so\n\t\t// per-post assignments can resolve to existing rows. Done before any\n\t\t// content insert because WXR exports list terms at the top of the\n\t\t// file but per-item assignments only reference them by slug.\n\t\tconst taxonomyPlan = await preImportWxrTaxonomies(\n\t\t\temdash.db,\n\t\t\twxr.posts,\n\t\t\twxr.categories,\n\t\t\twxr.tags,\n\t\t\twxr.terms,\n\t\t\tconfig.locale,\n\t\t);\n\n\t\t// Multilingual imports (WPML / Polylang -- see #1080) need a term\n\t\t// row at each per-post locale, all sharing the canonical term's\n\t\t// `translation_group`. Without this, `getTermsForEntry(..., locale)`\n\t\t// on non-canonical translations comes back empty.\n\t\t//\n\t\t// The mirror raises `WxrTaxonomyConflictError` with an operator-\n\t\t// actionable message when an existing locale row has an\n\t\t// incompatible group. Surface its `publicMessage` directly so the\n\t\t// admin UI can tell the user which (taxonomy, slug, locale) needs\n\t\t// reconciliation. Other errors (DB connectivity, unexpected\n\t\t// repository failures) re-throw to the outer catch where\n\t\t// `handleError` masks them with the generic \"Failed to import\n\t\t// content\" -- exposing raw DB errors to clients would leak schema\n\t\t// names and bypass the AGENTS.md \"never expose error.message\" rule.\n\t\tconst postLocales = new Set<string>();\n\t\tfor (const post of wxr.posts) {\n\t\t\tif (post.locale) postLocales.add(post.locale);\n\t\t}\n\t\tif (postLocales.size > 0) {\n\t\t\ttry {\n\t\t\t\tawait mirrorTermsToLocales(emdash.db, taxonomyPlan, postLocales, config.locale);\n\t\t\t} catch (mirrorError) {\n\t\t\t\tif (isWxrTaxonomyConflictError(mirrorError)) {\n\t\t\t\t\tconsole.error(\"[WXR_IMPORT_TAXONOMY_CONFLICT]\", mirrorError);\n\t\t\t\t\treturn apiError(\"WXR_IMPORT_TAXONOMY_CONFLICT\", mirrorError.publicMessage, 409);\n\t\t\t\t}\n\t\t\t\tthrow mirrorError;\n\t\t\t}\n\t\t}\n\n\t\t// Import content (locale from config scopes all items)\n\t\tconst result = await importContent(\n\t\t\twxr.posts,\n\t\t\tconfig,\n\t\t\temdash,\n\t\t\temdashManifest,\n\t\t\tattachmentMap,\n\t\t\tconfig.locale,\n\t\t\tauthorDisplayNames,\n\t\t\ttaxonomyPlan,\n\t\t);\n\n\t\t// Import reusable blocks as sections (if enabled)\n\t\tif (config.importSections !== false) {\n\t\t\tconst sectionsResult = await importReusableBlocksAsSections(wxr.posts, emdash.db);\n\t\t\tresult.sections = {\n\t\t\t\tcreated: sectionsResult.sectionsCreated,\n\t\t\t\tskipped: sectionsResult.sectionsSkipped,\n\t\t\t};\n\t\t\t// Add section errors to main errors array\n\t\t\tresult.errors.push(...sectionsResult.errors);\n\t\t\tif (sectionsResult.errors.length > 0) {\n\t\t\t\tresult.success = false;\n\t\t\t}\n\t\t}\n\n\t\treturn apiSuccess(result);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to import content\", \"WXR_IMPORT_ERROR\");\n\t}\n};\n\nexport async function importContent(\n\tposts: WxrPost[],\n\tconfig: ImportConfig,\n\temdash: EmDashHandlers,\n\tmanifest: EmDashManifest,\n\tattachmentMap: Map<string, string>,\n\tlocale: string | undefined,\n\tauthorDisplayNames: Map<string, string> | undefined,\n\ttaxonomyPlan: TaxonomyImportPlan,\n): Promise<ImportResult> {\n\tconst result: ImportResult = {\n\t\tsuccess: true,\n\t\timported: 0,\n\t\tskipped: 0,\n\t\terrors: [],\n\t\tbyCollection: {},\n\t\ttaxonomies: {\n\t\t\ttermsCreated: taxonomyPlan.termsCreated,\n\t\t\ttermsReused: taxonomyPlan.termsReused,\n\t\t\tassignments: 0,\n\t\t\tmissingTaxonomies: taxonomyPlan.missingTaxonomies,\n\t\t},\n\t};\n\n\t// Create content repository for checking existing items\n\tconst contentRepo = new ContentRepository(emdash.db);\n\tconst bylineRepo = new BylineRepository(emdash.db);\n\tconst bylineCache = new Map<string, string>();\n\n\t// Source-side translation group ID -> the EmDash ID of the first post we\n\t// imported for that group. Subsequent translations are linked via\n\t// `translationOf` so they share a `translation_group` on the EmDash side.\n\tconst translationGroupMap = new Map<string, string>();\n\n\tfor (const post of posts) {\n\t\tconst postType = post.postType || \"post\";\n\t\tconst mapping = config.postTypeMappings[postType];\n\n\t\t// Skip if not mapped or disabled\n\t\tif (!mapping || !mapping.enabled) {\n\t\t\tresult.skipped++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Defensive: mapping.collection is already sanitized by prepare, but the user\n\t\t// could manually edit the import config between prepare and execute.\n\t\tconst collection = sanitizeSlug(mapping.collection);\n\n\t\t// Check if collection exists in manifest\n\t\tif (!manifest?.collections[collection]) {\n\t\t\tresult.errors.push({\n\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\terror: `Collection \"${collection}\" does not exist`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert content to Portable Text\n\t\t\tconst content = post.content ? gutenbergToPortableText(post.content) : [];\n\n\t\t\t// Generate slug from post name or title\n\t\t\tconst slug = post.postName || slugify(post.title || `post-${post.id || Date.now()}`);\n\n\t\t\t// Per-post locale: prefer the value extracted from WPML/Polylang\n\t\t\t// metadata; fall back to the upload-wide locale. Two translations\n\t\t\t// sharing `post_name` (e.g. /en/hello + /ar/hello) collide on the\n\t\t\t// `UNIQUE(slug, locale)` constraint when they share a locale, so\n\t\t\t// honouring the per-post value is what makes multilingual imports\n\t\t\t// land correctly. See issue #1080.\n\t\t\tconst postLocale = post.locale ?? locale;\n\n\t\t\t// Check if already exists (idempotency). Match against the\n\t\t\t// per-post locale so the same slug in different locales doesn't\n\t\t\t// false-positive as duplicate.\n\t\t\tif (config.skipExisting) {\n\t\t\t\tconst existing = await contentRepo.findBySlug(collection, slug, postLocale);\n\t\t\t\tif (existing) {\n\t\t\t\t\t// Record the translation group mapping so later\n\t\t\t\t\t// translations in this WXR can link to the existing\n\t\t\t\t\t// item. We deliberately trust the WXR's grouping over\n\t\t\t\t\t// the existing row's `translation_group`: a singleton\n\t\t\t\t\t// existing row gets folded into the WXR's group when\n\t\t\t\t\t// `handleContentCreate` resolves the new translation's\n\t\t\t\t\t// `translationOf`. Pre-existing translations that\n\t\t\t\t\t// already belong to a different group are left alone --\n\t\t\t\t\t// the user is responsible for reconciling those through\n\t\t\t\t\t// the admin if they don't match the WXR.\n\t\t\t\t\tif (post.translationGroup) {\n\t\t\t\t\t\ttranslationGroupMap.set(post.translationGroup, existing.id);\n\t\t\t\t\t}\n\t\t\t\t\tresult.skipped++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolve translation group: if this post belongs to a group and\n\t\t\t// we've already imported one of its translations, link to it.\n\t\t\tlet translationOf: string | undefined;\n\t\t\tif (post.translationGroup) {\n\t\t\t\ttranslationOf = translationGroupMap.get(post.translationGroup);\n\t\t\t}\n\n\t\t\t// Map WordPress status to EmDash status\n\t\t\tconst status = mapStatus(post.status);\n\n\t\t\t// Build data object with required fields\n\t\t\tconst data: Record<string, unknown> = {\n\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\tcontent,\n\t\t\t\texcerpt: post.excerpt || undefined,\n\t\t\t};\n\n\t\t\t// Only add featured_image if the collection has this field and we have a value\n\t\t\tconst collectionSchema = manifest.collections[collection];\n\t\t\tconst hasFeaturedImageField = collectionSchema?.fields\n\t\t\t\t? \"featured_image\" in collectionSchema.fields\n\t\t\t\t: false;\n\t\t\tif (hasFeaturedImageField) {\n\t\t\t\tconst thumbnailId = post.meta.get(\"_thumbnail_id\");\n\t\t\t\tconst featuredImage = thumbnailId ? attachmentMap.get(String(thumbnailId)) : undefined;\n\t\t\t\tif (featuredImage) {\n\t\t\t\t\tdata.featured_image = featuredImage;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolve author ID from mappings\n\t\t\tlet authorId: string | undefined;\n\t\t\tif (config.authorMappings && post.creator) {\n\t\t\t\tconst mappedUserId = config.authorMappings[post.creator];\n\t\t\t\tif (mappedUserId !== undefined && mappedUserId !== null) {\n\t\t\t\t\tauthorId = mappedUserId;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst bylineId = await resolveImportByline(\n\t\t\t\tpost.creator,\n\t\t\t\tauthorDisplayNames?.get(post.creator ?? \"\") ?? post.creator,\n\t\t\t\tauthorId,\n\t\t\t\tbylineRepo,\n\t\t\t\tbylineCache,\n\t\t\t);\n\n\t\t\t// Preserve original WordPress dates using the shared WXR date parser.\n\t\t\t// Fallback chain: postDateGmt (UTC) → pubDate (RFC 2822) → postDate (site-local).\n\t\t\tconst parsedDate = parseWxrDate(post.postDateGmt, post.pubDate, post.postDate);\n\t\t\tconst createdAt = parsedDate ? parsedDate.toISOString() : undefined;\n\t\t\tconst publishedAt = status === \"published\" && createdAt ? createdAt : undefined;\n\n\t\t\t// Create the content item\n\t\t\tconst createResult = await emdash.handleContentCreate(collection, {\n\t\t\t\tdata,\n\t\t\t\tslug,\n\t\t\t\tstatus,\n\t\t\t\tauthorId,\n\t\t\t\tbylines: bylineId ? [{ bylineId }] : undefined,\n\t\t\t\tlocale: postLocale,\n\t\t\t\ttranslationOf,\n\t\t\t\tcreatedAt,\n\t\t\t\tpublishedAt,\n\t\t\t});\n\n\t\t\tif (createResult.success) {\n\t\t\t\tresult.imported++;\n\t\t\t\tresult.byCollection[collection] = (result.byCollection[collection] || 0) + 1;\n\n\t\t\t\t// `handleContentCreate` returns `data: { item, _rev? }` on\n\t\t\t\t// success (see `ApiResult<ContentResponse>` in\n\t\t\t\t// `api/handlers/content.ts`). `HandlerResponse.data` is\n\t\t\t\t// typed as `unknown` to avoid coupling the route surface to\n\t\t\t\t// internal handler types, so we narrow here.\n\t\t\t\t// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- handler contract documented at handleContentCreate\n\t\t\t\tconst createdItem = (createResult.data as { item: { id: string } } | undefined)?.item;\n\n\t\t\t\t// Track translation group: the first imported post in a group\n\t\t\t\t// becomes the anchor that later translations link to.\n\t\t\t\tif (\n\t\t\t\t\tcreatedItem &&\n\t\t\t\t\tpost.translationGroup &&\n\t\t\t\t\t!translationGroupMap.has(post.translationGroup)\n\t\t\t\t) {\n\t\t\t\t\ttranslationGroupMap.set(post.translationGroup, createdItem.id);\n\t\t\t\t}\n\n\t\t\t\t// Attach taxonomy assignments parsed from the WXR's per-item\n\t\t\t\t// <category> elements.\n\t\t\t\t//\n\t\t\t\t// Anchors (no `translationOf`) get an additive attach -- the\n\t\t\t\t// row is fresh, no inherited pivots to consider.\n\t\t\t\t//\n\t\t\t\t// Translations get per-taxonomy replace semantics. WPML's\n\t\t\t\t// \"Translate Independently\" mode is per-taxonomy, not per-\n\t\t\t\t// post: a translation that overrides `category` shouldn't\n\t\t\t\t// lose its inherited `tag` or `genre`. The replace path\n\t\t\t\t// only touches taxonomies the translation actually carries\n\t\t\t\t// AND that resolve to at least one term that survives the\n\t\t\t\t// def's `collections` filter; taxonomies with no resolved\n\t\t\t\t// terms (missing-def, dropped by filter, or just absent\n\t\t\t\t// from the WXR) fall through with the inherited set intact\n\t\t\t\t// from `copyEntryTerms`.\n\t\t\t\tif (createdItem) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst written = translationOf\n\t\t\t\t\t\t\t? await setPostTermAssignmentsReplacing(\n\t\t\t\t\t\t\t\t\temdash.db,\n\t\t\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\t\t\tcreatedItem.id,\n\t\t\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t\t\ttaxonomyPlan,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: await attachPostTaxonomies(\n\t\t\t\t\t\t\t\t\temdash.db,\n\t\t\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\t\t\tcreatedItem.id,\n\t\t\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t\t\ttaxonomyPlan,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\tif (result.taxonomies) {\n\t\t\t\t\t\t\tresult.taxonomies.assignments += written;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (taxError) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`Failed to attach taxonomies for \"${post.title || \"Untitled\"}\":`,\n\t\t\t\t\t\t\ttaxError,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tresult.errors.push({\n\t\t\t\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\ttaxError instanceof Error && taxError.message\n\t\t\t\t\t\t\t\t\t? `Imported but failed to attach taxonomies: ${taxError.message}`\n\t\t\t\t\t\t\t\t\t: \"Imported but failed to attach taxonomies\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresult.errors.push({\n\t\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\t\terror:\n\t\t\t\t\t\ttypeof createResult.error === \"object\" && createResult.error !== null\n\t\t\t\t\t\t\t? (createResult.error as { message?: string }).message || \"Unknown error\"\n\t\t\t\t\t\t\t: String(createResult.error),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Import error for \"${post.title || \"Untitled\"}\":`, error);\n\t\t\tresult.errors.push({\n\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\terror: error instanceof Error && error.message ? error.message : \"Failed to import item\",\n\t\t\t});\n\t\t}\n\t}\n\n\tresult.success = result.errors.length === 0;\n\treturn result;\n}\n\nfunction mapStatus(wpStatus: string | undefined): string {\n\tswitch (wpStatus) {\n\t\tcase \"publish\":\n\t\t\treturn \"published\";\n\t\tcase \"draft\":\n\t\t\treturn \"draft\";\n\t\tcase \"pending\":\n\t\t\treturn \"draft\";\n\t\tcase \"private\":\n\t\t\treturn \"draft\";\n\t\tdefault:\n\t\t\treturn \"draft\";\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,IAAa,2BAAb,cAA8C,MAAM;CACnD,AAAS;CACT,YAAY,eAAuB,SAA+B;AACjE,QAAM,eAAe,QAAQ;AAC7B,OAAK,OAAO;AACZ,OAAK,gBAAgB;;;AAIvB,SAAgB,2BAA2B,OAAmD;AAC7F,QAAO,iBAAiB;;AAuCzB,SAAS,YAAiC;AACzC,QAAO,EACN,MAAM;EACL,cAAc,EAAE;EAChB,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,qCAAqB,IAAI,KAAK;EAC9B,uCAAuB,IAAI,KAAK;EAChC,0CAA0B,IAAI,KAAK;EACnC,EACD;;;;;;AAOF,SAAS,KAAK,QAAgC,KAAmB;AAChE,QAAO,QAAQ,OAAO,QAAQ,KAAK;;AAGpC,SAAS,aACR,OACA,cACA,MACA,QACO;CACP,IAAI,SAAS,MAAM,KAAK,oBAAoB,IAAI,aAAa;AAC7D,KAAI,CAAC,QAAQ;AACZ,2BAAS,IAAI,KAAK;AAClB,QAAM,KAAK,oBAAoB,IAAI,cAAc,OAAO;;AAEzD,QAAO,IAAI,MAAM,OAAO;;;;;;;;;;;;;;;;;;AAmBzB,SAAS,oBAAoB,KAA8B;AAC1D,KAAI,CAAC,IAAK,QAAO,EAAE;AACnB,KAAI;EACH,MAAM,SAAkB,KAAK,MAAM,IAAI;AACvC,MAAI,MAAM,QAAQ,OAAO,CACxB,QAAO,OAAO,QAAQ,MAAmB,OAAO,MAAM,SAAS;SAEzD;AAGR,QAAO,E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K,UACJ,QAAO;EACR,KAAK,UACJ,QAAO;EACR,QACC,QAAO"}
1
+ {"version":3,"file":"execute.mjs","names":[],"sources":["../../../../../../src/import/wxr-taxonomies.ts","../../../../../../src/astro/routes/api/import/wordpress/execute.ts"],"sourcesContent":["/**\n * WXR taxonomy import helpers.\n *\n * Bridges parsed WordPress taxonomy data (`WxrCategory`, `WxrTag`, `WxrTerm`,\n * and per-item `WxrPost.categories` / `WxrPost.tags` / `WxrPost.customTaxonomies`)\n * onto EmDash's term + content_taxonomies tables.\n *\n * Why this isn't inline in `execute.ts`: pre-creating all terms before any\n * post is created lets us (a) build a lookup once for every (taxonomy, slug)\n * the import needs, and (b) keep the per-post attachment loop cheap. It also\n * makes the logic testable without spinning up an Astro request.\n *\n * Behaviour:\n * - `wp:category` -> EmDash `category` taxonomy (seeded by migration 006).\n * - `wp:tag` -> EmDash `tag` taxonomy.\n * - `wp:term` -> matching EmDash taxonomy by `name` (case-sensitive).\n * If no matching def exists in the target locale, the\n * term is skipped — we don't auto-create defs because\n * the user controls their schema through the admin.\n * - Terms are created idempotently by `(taxonomy, slug, locale)`. Existing\n * terms are reused.\n * - Assignments respect the def's `collections` array. If the post's target\n * collection isn't listed on the taxonomy def, the assignment is skipped\n * (matches admin UI behaviour: you can't tag a \"products\" post with a\n * \"category\" if `category.collections` only includes \"posts\").\n */\n\nimport type { Kysely } from \"kysely\";\n\nimport type { WxrCategory, WxrPost, WxrTag, WxrTerm } from \"../cli/wxr/parser.js\";\nimport { TaxonomyRepository } from \"../database/repositories/taxonomy.js\";\nimport type { Database } from \"../database/types.js\";\nimport { resolveLocaleChain } from \"../i18n/resolve.js\";\nimport { invalidateTermCache } from \"../taxonomies/index.js\";\n\n/**\n * Thrown by `mirrorTermsToLocales` when a pre-existing locale row at the\n * same `(taxonomy, slug)` belongs to a different `translation_group` than\n * the canonical term. Callers in the route layer surface\n * `publicMessage` to the operator (no internal data) while logging\n * `cause` server-side.\n *\n * Marker class so the route layer can distinguish \"operator-actionable\n * taxonomy conflict\" from any other DB / repository error that might\n * escape the helper.\n */\nexport class WxrTaxonomyConflictError extends Error {\n\treadonly publicMessage: string;\n\tconstructor(publicMessage: string, options?: { cause?: unknown }) {\n\t\tsuper(publicMessage, options);\n\t\tthis.name = \"WxrTaxonomyConflictError\";\n\t\tthis.publicMessage = publicMessage;\n\t}\n}\n\nexport function isWxrTaxonomyConflictError(error: unknown): error is WxrTaxonomyConflictError {\n\treturn error instanceof WxrTaxonomyConflictError;\n}\n\n/**\n * Result of pre-importing taxonomy terms from a WXR file.\n */\nexport interface TaxonomyImportPlan {\n\t/** terms created during this run (per taxonomy name) */\n\ttermsCreated: Record<string, number>;\n\t/** terms that already existed and were reused (per taxonomy name) */\n\ttermsReused: Record<string, number>;\n\t/** custom taxonomies (`wp:term`) skipped because no matching EmDash def exists */\n\tmissingTaxonomies: string[];\n\t/**\n\t * Lookup table: `taxonomy name` -> `term slug` -> term id.\n\t * Used by `attachPostTaxonomies` to translate WXR assignments into pivot rows.\n\t */\n\ttermIdByNameAndSlug: Map<string, Map<string, string>>;\n\t/**\n\t * Lookup table: `taxonomy name` -> set of collection slugs the def allows.\n\t * Empty (or missing) means \"any collection\" — we only enforce the filter\n\t * when the def explicitly lists collections.\n\t */\n\tcollectionsByTaxonomy: Map<string, Set<string>>;\n\t/**\n\t * Lookup table: `term id` -> the term's `translation_group` (or `null`\n\t * if the term doesn't exist any more). Populated lazily by helpers that\n\t * need to check pivot existence without repeating per-term DB reads.\n\t */\n\ttranslationGroupByTermId: Map<string, string | null>;\n}\n\n/**\n * Track running counts plus the lookup maps.\n */\ninterface TaxonomyImportState {\n\tplan: TaxonomyImportPlan;\n}\n\nfunction makeState(): TaxonomyImportState {\n\treturn {\n\t\tplan: {\n\t\t\ttermsCreated: {},\n\t\t\ttermsReused: {},\n\t\t\tmissingTaxonomies: [],\n\t\t\ttermIdByNameAndSlug: new Map(),\n\t\t\tcollectionsByTaxonomy: new Map(),\n\t\t\ttranslationGroupByTermId: new Map(),\n\t\t},\n\t};\n}\n\n/**\n * Record-keeping helpers — keep mutations centralised so the result object\n * stays consistent.\n */\nfunction bump(record: Record<string, number>, key: string): void {\n\trecord[key] = (record[key] ?? 0) + 1;\n}\n\nfunction rememberTerm(\n\tstate: TaxonomyImportState,\n\ttaxonomyName: string,\n\tslug: string,\n\ttermId: string,\n): void {\n\tlet bySlug = state.plan.termIdByNameAndSlug.get(taxonomyName);\n\tif (!bySlug) {\n\t\tbySlug = new Map();\n\t\tstate.plan.termIdByNameAndSlug.set(taxonomyName, bySlug);\n\t}\n\tbySlug.set(slug, termId);\n}\n\n/**\n * Look up an EmDash taxonomy def by name. Definitions are per-locale but\n * a def is conceptually site-wide -- the per-locale row carries only the\n * label translations.\n *\n * Match the runtime helper `getTaxonomyDef` (in `src/taxonomies/index.ts`):\n * walk `resolveLocaleChain(locale)` so the importer picks the same def the\n * runtime would later resolve to. When the chain is empty (i18n disabled)\n * or every locale in the chain misses, fall through to the lowest-locale\n * row so single-locale installs still see seeded defs that were inserted\n * at some non-empty locale value.\n *\n * Without this fallback, a user importing into a non-default locale would\n * see every category dropped as `missingTaxonomies` even though the seeded\n * defs exist (just at the site's default locale).\n */\nfunction parseDefCollections(raw: string | null): string[] {\n\tif (!raw) return [];\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(raw);\n\t\tif (Array.isArray(parsed)) {\n\t\t\treturn parsed.filter((c): c is string => typeof c === \"string\");\n\t\t}\n\t} catch {\n\t\t// malformed JSON in the def -- treat as \"no collection filter\"\n\t}\n\treturn [];\n}\n\nasync function findTaxonomyDef(\n\tdb: Kysely<Database>,\n\tname: string,\n\tlocale: string | undefined,\n): Promise<{ id: string; collections: string[] } | null> {\n\tconst chain = resolveLocaleChain(locale);\n\n\tif (chain.length === 0) {\n\t\t// i18n disabled and no explicit locale. The runtime treats this\n\t\t// as \"no locale filter\" and picks the lowest-locale row. We do the\n\t\t// same so the importer agrees with how the runtime later reads\n\t\t// the def.\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.executeTakeFirst();\n\t\treturn row ? { id: row.id, collections: parseDefCollections(row.collections) } : null;\n\t}\n\n\t// Non-empty chain: walk it in order, return null if every entry misses.\n\t// This matches `getTaxonomyDef` exactly. We deliberately do NOT fall\n\t// through to any-locale lookup: doing so would let the importer pick a\n\t// def at a locale the runtime would never resolve to, producing\n\t// content the user can't see in the admin or on the rendered site.\n\tfor (const tryLocale of chain) {\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.where(\"locale\", \"=\", tryLocale)\n\t\t\t.executeTakeFirst();\n\t\tif (row) {\n\t\t\treturn { id: row.id, collections: parseDefCollections(row.collections) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Find or create a term in the given taxonomy. Returns the term id. Callers\n * must verify the taxonomy def exists before calling — this helper assumes\n * the def is present.\n *\n * Note: we don't resolve WordPress parent slugs into EmDash parent ids in\n * this pass. WXR exports list categories in arbitrary order, so a category's\n * parent may not exist yet when we first see it. Hierarchy is preserved at\n * the data level (the parent slug is on `WxrCategory.parent`) but flattens\n * in EmDash for now; restoring the tree is a follow-up improvement.\n */\nasync function ensureTerm(\n\trepo: TaxonomyRepository,\n\tstate: TaxonomyImportState,\n\ttaxonomyName: string,\n\tslug: string,\n\tlabel: string,\n\tdescription: string | undefined,\n\tlocale: string | undefined,\n): Promise<string> {\n\t// Already resolved in this run (e.g. seen in `wp:category` AND in a per-\n\t// item `<category>` element).\n\tconst cached = state.plan.termIdByNameAndSlug.get(taxonomyName)?.get(slug);\n\tif (cached) return cached;\n\n\tconst existing = await repo.findBySlug(taxonomyName, slug, locale);\n\tif (existing) {\n\t\tbump(state.plan.termsReused, taxonomyName);\n\t\trememberTerm(state, taxonomyName, slug, existing.id);\n\t\treturn existing.id;\n\t}\n\n\t// No row at the requested locale. Before creating, check whether a\n\t// `(name, slug)` row exists in some OTHER locale -- e.g. the admin\n\t// pre-created an Arabic translation, and now an `en` import wants the\n\t// canonical row. We need to mint the new row inside the existing row's\n\t// `translation_group` so per-locale lookups across the family work.\n\t// Without this, the mirror pass would later refuse to reconcile (it\n\t// sees pre-existing rows in a different group as a no-op) and pivots\n\t// would point at a group that has no row in the requested locale.\n\tconst anyLocale = await repo.findBySlug(taxonomyName, slug);\n\tconst translationOf = anyLocale?.id;\n\n\tconst created = await repo.create({\n\t\tname: taxonomyName,\n\t\tslug,\n\t\tlabel,\n\t\tdata: description ? { description } : undefined,\n\t\tlocale,\n\t\ttranslationOf,\n\t});\n\tbump(state.plan.termsCreated, taxonomyName);\n\trememberTerm(state, taxonomyName, slug, created.id);\n\treturn created.id;\n}\n\n/**\n * Retrieve the human label captured by the parser for a per-item\n * `<category>` text body, falling back to the slug when the parser didn't\n * see a label (e.g. self-closing tags or whitespace-only bodies).\n */\nfunction labelFor(post: WxrPost, taxonomy: string, slug: string): string {\n\tconst key = `${taxonomy}\\u0000${slug}`;\n\treturn post.taxonomyLabels?.get(key) ?? slug;\n}\n\n/**\n * Pre-import every term referenced by the WXR file.\n *\n * Pass 1: `wp:category` blocks. Each becomes a term in EmDash's seeded\n * `category` taxonomy.\n * Pass 2: `wp:tag` blocks. Each becomes a term in `tag`.\n * Pass 3: `wp:term` blocks (custom taxonomies). Skipped when no matching\n * EmDash def exists.\n * Pass 4: per-item `<category domain=\"…\" nicename=\"…\">` assignments. WXR\n * exports sometimes reference taxonomies/terms that weren't declared\n * at the top level (older exports especially), so we backfill terms\n * from per-item assignments. Categories and tags use the seeded defs\n * and pick up the assignment text as the label; custom domains fall\n * back to the same \"def must exist\" rule.\n */\nexport async function preImportWxrTaxonomies(\n\tdb: Kysely<Database>,\n\tposts: WxrPost[],\n\tcategories: WxrCategory[],\n\ttags: WxrTag[],\n\tterms: WxrTerm[],\n\tlocale: string | undefined,\n): Promise<TaxonomyImportPlan> {\n\tconst state = makeState();\n\tconst repo = new TaxonomyRepository(db);\n\n\t// Cache def lookups for the duration of the import. Keyed by name; value\n\t// is `null` when we've already determined the def is missing in this\n\t// locale (so we only report the \"missing\" warning once per taxonomy).\n\tconst defCache = new Map<string, { id: string; collections: string[] } | null>();\n\tconst lookupDef = async (name: string): Promise<{ id: string; collections: string[] } | null> => {\n\t\tif (defCache.has(name)) return defCache.get(name) ?? null;\n\t\tconst def = await findTaxonomyDef(db, name, locale);\n\t\tdefCache.set(name, def);\n\t\tif (def) {\n\t\t\tstate.plan.collectionsByTaxonomy.set(name, new Set(def.collections));\n\t\t}\n\t\treturn def;\n\t};\n\n\t// Pass 1: top-level <wp:category> blocks -> EmDash `category` taxonomy.\n\tconst categoryDef = await lookupDef(\"category\");\n\tif (categoryDef) {\n\t\tfor (const cat of categories) {\n\t\t\tconst slug = cat.nicename;\n\t\t\tconst label = cat.name;\n\t\t\tif (!slug || !label) continue;\n\t\t\tawait ensureTerm(repo, state, \"category\", slug, label, cat.description, locale);\n\t\t}\n\t} else if (categories.length > 0) {\n\t\t// Seeded `category` def was deleted by the user — record so the\n\t\t// import response can surface why none of the categories landed.\n\t\tstate.plan.missingTaxonomies.push(\"category\");\n\t}\n\n\t// Pass 2: top-level <wp:tag> blocks -> EmDash `tag` taxonomy.\n\tconst tagDef = await lookupDef(\"tag\");\n\tif (tagDef) {\n\t\tfor (const tag of tags) {\n\t\t\tconst slug = tag.slug;\n\t\t\tconst label = tag.name;\n\t\t\tif (!slug || !label) continue;\n\t\t\tawait ensureTerm(repo, state, \"tag\", slug, label, tag.description, locale);\n\t\t}\n\t} else if (tags.length > 0) {\n\t\tstate.plan.missingTaxonomies.push(\"tag\");\n\t}\n\n\t// Pass 3: <wp:term> blocks for custom taxonomies (genre, etc.). Skipped:\n\t// - `nav_menu`: menus are handled by `importMenusFromWxr`.\n\t// - `language`: Polylang's locale signal; promoted to `WxrPost.locale`\n\t// by the parser and not a content taxonomy in EmDash.\n\tfor (const term of terms) {\n\t\tif (term.taxonomy === \"nav_menu\" || term.taxonomy === \"language\") continue;\n\t\t// Normalize WordPress' `post_tag` synonym -> EmDash `tag`. WordPress\n\t\t// emits `<wp:tag>` for some exports and `<wp:term wp:term_taxonomy=\"post_tag\">`\n\t\t// for others; both must land in the same EmDash taxonomy.\n\t\tconst taxonomyName = term.taxonomy === \"post_tag\" ? \"tag\" : term.taxonomy;\n\t\tconst def = await lookupDef(taxonomyName);\n\t\tif (!def) {\n\t\t\tif (!state.plan.missingTaxonomies.includes(taxonomyName)) {\n\t\t\t\tstate.plan.missingTaxonomies.push(taxonomyName);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tawait ensureTerm(repo, state, taxonomyName, term.slug, term.name, term.description, locale);\n\t}\n\n\t// Pass 4: per-item assignments. Backfills terms missing from the top-\n\t// level blocks (rare, but observed in hand-edited or partial exports).\n\t// Labels come from the per-item `<category>` text body when the parser\n\t// captured one; otherwise we fall back to the slug. This is the path\n\t// for older exports that skip top-level `<wp:category>` definitions.\n\tlet recordedMissingCategoryFromPosts = false;\n\tlet recordedMissingTagFromPosts = false;\n\tfor (const post of posts) {\n\t\tfor (const slug of post.categories) {\n\t\t\tif (!categoryDef) {\n\t\t\t\tif (\n\t\t\t\t\t!recordedMissingCategoryFromPosts &&\n\t\t\t\t\t!state.plan.missingTaxonomies.includes(\"category\")\n\t\t\t\t) {\n\t\t\t\t\tstate.plan.missingTaxonomies.push(\"category\");\n\t\t\t\t\trecordedMissingCategoryFromPosts = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (state.plan.termIdByNameAndSlug.get(\"category\")?.has(slug)) continue;\n\t\t\tawait ensureTerm(\n\t\t\t\trepo,\n\t\t\t\tstate,\n\t\t\t\t\"category\",\n\t\t\t\tslug,\n\t\t\t\tlabelFor(post, \"category\", slug),\n\t\t\t\tundefined,\n\t\t\t\tlocale,\n\t\t\t);\n\t\t}\n\t\tfor (const slug of post.tags) {\n\t\t\tif (!tagDef) {\n\t\t\t\tif (!recordedMissingTagFromPosts && !state.plan.missingTaxonomies.includes(\"tag\")) {\n\t\t\t\t\tstate.plan.missingTaxonomies.push(\"tag\");\n\t\t\t\t\trecordedMissingTagFromPosts = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (state.plan.termIdByNameAndSlug.get(\"tag\")?.has(slug)) continue;\n\t\t\tawait ensureTerm(repo, state, \"tag\", slug, labelFor(post, \"tag\", slug), undefined, locale);\n\t\t}\n\t\tif (post.customTaxonomies) {\n\t\t\tfor (const [rawName, slugs] of post.customTaxonomies) {\n\t\t\t\t// `nav_menu` is handled by the menu importer; `language` is\n\t\t\t\t// Polylang's per-post locale signal, already promoted by the\n\t\t\t\t// parser.\n\t\t\t\tif (rawName === \"nav_menu\" || rawName === \"language\") continue;\n\t\t\t\tconst taxonomyName = rawName === \"post_tag\" ? \"tag\" : rawName;\n\t\t\t\tconst def = await lookupDef(taxonomyName);\n\t\t\t\tif (!def) {\n\t\t\t\t\tif (!state.plan.missingTaxonomies.includes(taxonomyName)) {\n\t\t\t\t\t\tstate.plan.missingTaxonomies.push(taxonomyName);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (const slug of slugs) {\n\t\t\t\t\tif (state.plan.termIdByNameAndSlug.get(taxonomyName)?.has(slug)) continue;\n\t\t\t\t\tawait ensureTerm(\n\t\t\t\t\t\trepo,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\ttaxonomyName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tlabelFor(post, taxonomyName, slug),\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tlocale,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// `content_taxonomies` writes happen later in `attachPostTaxonomies`, but\n\t// term inserts above already invalidate the in-memory \"has any terms\" probe.\n\t// We flush once at the end of the pre-import to keep the runtime cache hot.\n\tinvalidateTermCache();\n\n\treturn state.plan;\n}\n\n/**\n * Walk a parsed WXR post's per-item taxonomy assignments and return only\n * the ones that resolve to a real EmDash term AND aren't filtered out by\n * the taxonomy def's `collections` allowlist. Grouped by EmDash taxonomy\n * name (so `post_tag` is already folded into `tag`). Deduplicated.\n *\n * This is the single source of truth for \"what will the importer try to\n * write for this post\". Both the anchor (additive `attachToEntry`) and\n * translation (per-taxonomy `setTermsForEntry`) paths drive from this map\n * so they agree on which taxonomies need touching. In particular, the\n * translation path uses the keys here -- not `postAssignedTaxonomies` --\n * to decide which inherited pivot rows to clear, so a translation whose\n * only assignment is filtered out by `collections` doesn't lose its\n * inherited terms (see #1087 review feedback).\n *\n * Skipped taxonomies: `nav_menu` (handled by the menu importer) and\n * `language` (Polylang's locale signal, already promoted to `post.locale`\n * by the parser).\n */\nexport function resolvePostTermAssignments(\n\tcollection: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Map<string, string[]> {\n\tconst result = new Map<string, string[]>();\n\tconst seen = new Set<string>();\n\n\tconst tryResolve = (taxonomyName: string, slug: string): void => {\n\t\tconst termId = plan.termIdByNameAndSlug.get(taxonomyName)?.get(slug);\n\t\tif (!termId) return;\n\t\tconst collectionFilter = plan.collectionsByTaxonomy.get(taxonomyName);\n\t\t// Empty set means \"no filter\" (def has no collections array). A\n\t\t// non-empty set is enforced: skip assignments to collections the\n\t\t// def doesn't list. Matches admin UI: a `category` term linked\n\t\t// only to `posts` shouldn't end up on a `products` row just\n\t\t// because the WXR happened to mention it.\n\t\tif (collectionFilter && collectionFilter.size > 0 && !collectionFilter.has(collection)) {\n\t\t\treturn;\n\t\t}\n\t\tconst dedupeKey = `${taxonomyName}\\u0000${termId}`;\n\t\tif (seen.has(dedupeKey)) return;\n\t\tseen.add(dedupeKey);\n\t\tconst existing = result.get(taxonomyName);\n\t\tif (existing) existing.push(termId);\n\t\telse result.set(taxonomyName, [termId]);\n\t};\n\n\tfor (const slug of post.categories) tryResolve(\"category\", slug);\n\tfor (const slug of post.tags) tryResolve(\"tag\", slug);\n\tif (post.customTaxonomies) {\n\t\tfor (const [rawName, slugs] of post.customTaxonomies) {\n\t\t\tif (rawName === \"nav_menu\" || rawName === \"language\") continue;\n\t\t\tconst taxonomyName = rawName === \"post_tag\" ? \"tag\" : rawName;\n\t\t\tfor (const slug of slugs) tryResolve(taxonomyName, slug);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Attach the taxonomy assignments parsed for a single WXR post to a freshly-\n * created EmDash content row. Additive (`attachToEntry` + `ON CONFLICT DO\n * NOTHING`). Used for anchors -- translations need replace-semantics per\n * taxonomy and should use `setPostTermAssignmentsReplacing` instead.\n *\n * Returns the number of pivot rows actually inserted (excludes rows that\n * already existed via the `ON CONFLICT DO NOTHING` path), so the caller can\n * roll them up into the import summary without over-counting on re-imports.\n */\nexport async function attachPostTaxonomies(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Promise<number> {\n\tconst repo = new TaxonomyRepository(db);\n\tconst resolved = resolvePostTermAssignments(collection, post, plan);\n\n\tlet attached = 0;\n\tfor (const [, termIds] of resolved) {\n\t\tfor (const termId of termIds) {\n\t\t\tconst wrote = await attachToEntryCountingInserts(db, repo, plan, collection, entryId, termId);\n\t\t\tif (wrote) attached++;\n\t\t}\n\t}\n\treturn attached;\n}\n\n/**\n * Replace assignments per-taxonomy from a parsed WXR post. Used for\n * translations: WPML's \"Translate Independently\" mode lets translators\n * override term assignments per-taxonomy, not per-post. A translation that\n * overrides `category` shouldn't lose its inherited `tag` or `genre`. We\n * only call `setTermsForEntry(name, ids)` for taxonomies where the\n * translation actually resolved at least one term -- taxonomies with no\n * resolvable+permitted terms are left alone so inherited rows from\n * `copyEntryTerms` stay intact.\n *\n * Returns the number of pivot rows after replacement (sum of `termIds`\n * lists across taxonomies actually touched). Note this counts logical\n * assignments, not the delta from the prior state; the import summary\n * treats this as an additive count for compatibility with `attachPost-\n * Taxonomies`.\n */\nexport async function setPostTermAssignmentsReplacing(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Promise<number> {\n\tconst repo = new TaxonomyRepository(db);\n\tconst resolved = resolvePostTermAssignments(collection, post, plan);\n\n\tlet attached = 0;\n\tfor (const [taxonomyName, termIds] of resolved) {\n\t\tawait repo.setTermsForEntry(collection, entryId, taxonomyName, termIds);\n\t\tattached += termIds.length;\n\t}\n\treturn attached;\n}\n\n/**\n * Resolve a term id to its `translation_group` (the value\n * `content_taxonomies` stores). Caches the result on the plan so\n * repeated attaches of the same term don't repeat the lookup.\n */\nasync function termTranslationGroup(\n\trepo: TaxonomyRepository,\n\tplan: TaxonomyImportPlan,\n\ttermId: string,\n): Promise<string | null> {\n\tconst cached = plan.translationGroupByTermId.get(termId);\n\tif (cached !== undefined) return cached;\n\tconst term = await repo.findById(termId);\n\tconst group = term?.translationGroup ?? null;\n\tplan.translationGroupByTermId.set(termId, group);\n\treturn group;\n}\n\n/**\n * Wrapper around `TaxonomyRepository.attachToEntry` that returns whether\n * an actual row was inserted (vs. silently skipped by the `ON CONFLICT DO\n * NOTHING` branch). Lets the importer's `assignments` counter reflect real\n * writes rather than re-import no-ops.\n *\n * Best-effort: we check pivot existence first, then call `attachToEntry`.\n * A concurrent insert between the check and the attach would make us\n * report `false` while a row was in fact inserted -- the count is for\n * summary display only, never correctness.\n */\nasync function attachToEntryCountingInserts(\n\tdb: Kysely<Database>,\n\trepo: TaxonomyRepository,\n\tplan: TaxonomyImportPlan,\n\tcollection: string,\n\tentryId: string,\n\ttermId: string,\n): Promise<boolean> {\n\tconst group = await termTranslationGroup(repo, plan, termId);\n\tif (!group) return false;\n\n\tconst existing = await db\n\t\t.selectFrom(\"content_taxonomies\")\n\t\t.select(\"collection\")\n\t\t.where(\"collection\", \"=\", collection)\n\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t.where(\"taxonomy_id\", \"=\", group)\n\t\t.executeTakeFirst();\n\tif (existing) return false;\n\n\tawait repo.attachToEntry(collection, entryId, termId);\n\treturn true;\n}\n\n/**\n * Mirror every term in the plan into each additional locale used by the\n * incoming posts. New rows share the canonical term's `translation_group`\n * so per-locale lookups (`getTermsForEntry(..., locale)`) resolve correctly\n * for translations whose locale differs from the import-wide one.\n *\n * Without this pass, multilingual WXR imports (#1080) write all term rows\n * at the upload-wide locale; the `content_taxonomies` pivot is correct (it\n * stores `translation_group`, not `term id`), but\n * `getTermsForEntry(collection, arabicPostId, \"category\", \"ar\")` filters on\n * `taxonomies.locale = \"ar\"` and returns zero rows. Users see \"no tags\" on\n * every non-canonical translation.\n *\n * Idempotent: skips a locale when a row already exists at `(name, slug,\n * locale)`. Safe to call after `preImportWxrTaxonomies` on subsequent\n * imports.\n */\nexport async function mirrorTermsToLocales(\n\tdb: Kysely<Database>,\n\tplan: TaxonomyImportPlan,\n\tpostLocales: Iterable<string>,\n\tcanonicalLocale: string | undefined,\n): Promise<void> {\n\tconst localeSet = new Set<string>();\n\tfor (const locale of postLocales) {\n\t\tif (!locale || locale === canonicalLocale) continue;\n\t\tlocaleSet.add(locale);\n\t}\n\tif (localeSet.size === 0) return;\n\n\tconst repo = new TaxonomyRepository(db);\n\n\tfor (const [taxonomyName, bySlug] of plan.termIdByNameAndSlug) {\n\t\tfor (const [slug, canonicalTermId] of bySlug) {\n\t\t\t// Resolve the canonical's translation_group once; we'll compare\n\t\t\t// against any pre-existing rows we find at the target locales.\n\t\t\t// Cache on the plan so subsequent attaches (which also need\n\t\t\t// this resolution) don't repeat the lookup.\n\t\t\tconst cachedGroup = await termTranslationGroup(repo, plan, canonicalTermId);\n\t\t\tif (!cachedGroup) {\n\t\t\t\t// The canonical term id is in the plan but the row is no\n\t\t\t\t// longer in the DB. Shouldn't happen during a single\n\t\t\t\t// import run; skip rather than crash so the rest of the\n\t\t\t\t// import can complete.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst canonicalGroup = cachedGroup;\n\n\t\t\tfor (const locale of localeSet) {\n\t\t\t\tconst existing = await repo.findBySlug(taxonomyName, slug, locale);\n\t\t\t\tif (existing) {\n\t\t\t\t\t// `ensureTerm` resolves cross-locale grouping when it\n\t\t\t\t\t// creates the canonical row, so a pre-existing sibling\n\t\t\t\t\t// row at this locale should already share the\n\t\t\t\t\t// canonical's `translation_group`. If it doesn't, the\n\t\t\t\t\t// import would write pivots pointing at a group that\n\t\t\t\t\t// has no row in this locale -- a silent data-integrity\n\t\t\t\t\t// bug. Fail closed: throw so the operator reconciles\n\t\t\t\t\t// the existing rows in the admin before retrying. This\n\t\t\t\t\t// happens when the canonical row was created in an\n\t\t\t\t\t// earlier import and a sibling-locale row was added\n\t\t\t\t\t// manually afterwards (or vice versa) without linking\n\t\t\t\t\t// them via translationOf.\n\t\t\t\t\tif (existing.translationGroup !== canonicalGroup) {\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" already exists at locale \"${locale}\" in a different translation group than the canonical row at this import's locale. Reconcile the rows in the admin (re-link via translationOf, or delete one) and retry.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait repo.create({\n\t\t\t\t\t\tname: taxonomyName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tlabel: slug, // we don't have a per-locale label from the WXR\n\t\t\t\t\t\tlocale,\n\t\t\t\t\t\ttranslationOf: canonicalTermId,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// `findBySlug` + `create` is not atomic. A concurrent\n\t\t\t\t\t// import racing us into the same `(name, slug, locale)`\n\t\t\t\t\t// will trip the UNIQUE constraint. Re-read the row that\n\t\t\t\t\t// won the race and verify its `translation_group`\n\t\t\t\t\t// matches the canonical's; if not, the pivot will\n\t\t\t\t\t// resolve to a group that has no row in this locale\n\t\t\t\t\t// (silent data-integrity bug) so we surface that loudly\n\t\t\t\t\t// rather than continue.\n\t\t\t\t\t//\n\t\t\t\t\t// Other errors (validation, connectivity) re-throw so\n\t\t\t\t\t// the import fails closed rather than silently shipping\n\t\t\t\t\t// translations that resolve to empty taxonomy queries.\n\t\t\t\t\tconst message = error instanceof Error ? error.message.toLowerCase() : \"\";\n\t\t\t\t\tconst isUniqueRace =\n\t\t\t\t\t\tmessage.includes(\"unique constraint failed\") || message.includes(\"duplicate key\");\n\t\t\t\t\tif (!isUniqueRace) throw error;\n\n\t\t\t\t\tconst winner = await repo.findBySlug(taxonomyName, slug, locale);\n\t\t\t\t\tif (!winner) {\n\t\t\t\t\t\t// UNIQUE conflict but no row visible? Shouldn't\n\t\t\t\t\t\t// happen unless the racing transaction rolled back;\n\t\t\t\t\t\t// fail loudly so the operator can investigate.\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" raced UNIQUE at locale \"${locale}\" but no row is visible afterwards. The concurrent transaction may have rolled back; retry the import.`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (winner.translationGroup !== canonicalGroup) {\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" raced UNIQUE at locale \"${locale}\" with a different translation group. Reconcile the rows in the admin and retry.`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[WXR import] concurrent writer beat us to term \"${taxonomyName}/${slug}\" at locale \"${locale}\"; using existing row (same group).`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * WordPress WXR execute import endpoint\n *\n * POST /_emdash/api/import/wordpress/execute\n *\n * Accepts WXR file and import configuration, imports content into the database.\n */\n\nimport { gutenbergToPortableText } from \"@emdash-cms/gutenberg-to-portable-text\";\nimport type { APIRoute } from \"astro\";\nimport {\n\tparseWxrString,\n\tContentRepository,\n\timportReusableBlocksAsSections,\n\ttype WxrPost,\n\tparseWxrDate,\n} from \"emdash\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { BylineRepository } from \"#db/repositories/byline.js\";\nimport { resolveImportByline } from \"#import/utils.js\";\nimport {\n\tattachPostTaxonomies,\n\tisWxrTaxonomyConflictError,\n\tmirrorTermsToLocales,\n\tpreImportWxrTaxonomies,\n\tsetPostTermAssignmentsReplacing,\n\ttype TaxonomyImportPlan,\n} from \"#import/wxr-taxonomies.js\";\nimport type { EmDashHandlers, EmDashManifest } from \"#types\";\nimport { slugify } from \"#utils/slugify.js\";\n\nimport { sanitizeSlug } from \"./analyze.js\";\n\nexport const prerender = false;\n\nexport interface ImportConfig {\n\t/** Map WordPress post types to EmDash collections */\n\tpostTypeMappings: Record<\n\t\tstring,\n\t\t{\n\t\t\tcollection: string;\n\t\t\tenabled: boolean;\n\t\t}\n\t>;\n\t/** Whether to skip items that already exist (by slug) */\n\tskipExisting: boolean;\n\t/** Whether to import reusable blocks (wp_block) as sections */\n\timportSections?: boolean;\n\t/** Author mappings (WP author login -> EmDash user ID) */\n\tauthorMappings?: Record<string, string | null>;\n\t/** BCP 47 locale for all imported items. When omitted, defaults to defaultLocale. */\n\tlocale?: string;\n}\n\nexport interface ImportResult {\n\tsuccess: boolean;\n\timported: number;\n\tskipped: number;\n\terrors: Array<{ title: string; error: string }>;\n\tbyCollection: Record<string, number>;\n\t/** Sections import results (if enabled) */\n\tsections?: {\n\t\tcreated: number;\n\t\tskipped: number;\n\t};\n\t/** Taxonomy import results (categories, tags, custom taxonomies). */\n\ttaxonomies?: {\n\t\t/** Terms newly created during this import, keyed by taxonomy name. */\n\t\ttermsCreated: Record<string, number>;\n\t\t/** Existing terms that were re-used, keyed by taxonomy name. */\n\t\ttermsReused: Record<string, number>;\n\t\t/** Total pivot rows (post <-> term) written to `content_taxonomies`. */\n\t\tassignments: number;\n\t\t/**\n\t\t * Custom taxonomy names from the WXR file that had no matching EmDash\n\t\t * definition and were therefore skipped. Lets the admin UI surface a\n\t\t * \"create taxonomy X first\" hint without re-running the import.\n\t\t */\n\t\tmissingTaxonomies: string[];\n\t};\n}\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\tif (!emdash?.handleContentCreate) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash not configured\", 500);\n\t}\n\n\ttry {\n\t\tconst emdashManifest = await emdash.getManifest();\n\n\t\tconst formData = await request.formData();\n\t\tconst fileEntry = formData.get(\"file\");\n\t\tconst file = fileEntry instanceof File ? fileEntry : null;\n\t\tconst configEntry = formData.get(\"config\");\n\t\tconst configJson = typeof configEntry === \"string\" ? configEntry : null;\n\n\t\tif (!file) {\n\t\t\treturn apiError(\"VALIDATION_ERROR\", \"No file provided\", 400);\n\t\t}\n\n\t\tif (!configJson) {\n\t\t\treturn apiError(\"VALIDATION_ERROR\", \"No config provided\", 400);\n\t\t}\n\n\t\tconst config: ImportConfig = JSON.parse(configJson);\n\n\t\t// Parse WXR\n\t\tconst text = await file.text();\n\t\tconst wxr = await parseWxrString(text);\n\n\t\t// Build attachment ID -> URL map for featured images\n\t\tconst attachmentMap = new Map<string, string>();\n\t\tfor (const att of wxr.attachments) {\n\t\t\tif (att.id && att.url) {\n\t\t\t\tattachmentMap.set(String(att.id), att.url);\n\t\t\t}\n\t\t}\n\n\t\t// Build author login -> display name map\n\t\tconst authorDisplayNames = new Map<string, string>();\n\t\tfor (const author of wxr.authors) {\n\t\t\tif (!author.login) continue;\n\t\t\tauthorDisplayNames.set(author.login, author.displayName || author.login);\n\t\t}\n\n\t\t// Pre-create taxonomy terms (categories, tags, custom taxonomies) so\n\t\t// per-post assignments can resolve to existing rows. Done before any\n\t\t// content insert because WXR exports list terms at the top of the\n\t\t// file but per-item assignments only reference them by slug.\n\t\tconst taxonomyPlan = await preImportWxrTaxonomies(\n\t\t\temdash.db,\n\t\t\twxr.posts,\n\t\t\twxr.categories,\n\t\t\twxr.tags,\n\t\t\twxr.terms,\n\t\t\tconfig.locale,\n\t\t);\n\n\t\t// Multilingual imports (WPML / Polylang -- see #1080) need a term\n\t\t// row at each per-post locale, all sharing the canonical term's\n\t\t// `translation_group`. Without this, `getTermsForEntry(..., locale)`\n\t\t// on non-canonical translations comes back empty.\n\t\t//\n\t\t// The mirror raises `WxrTaxonomyConflictError` with an operator-\n\t\t// actionable message when an existing locale row has an\n\t\t// incompatible group. Surface its `publicMessage` directly so the\n\t\t// admin UI can tell the user which (taxonomy, slug, locale) needs\n\t\t// reconciliation. Other errors (DB connectivity, unexpected\n\t\t// repository failures) re-throw to the outer catch where\n\t\t// `handleError` masks them with the generic \"Failed to import\n\t\t// content\" -- exposing raw DB errors to clients would leak schema\n\t\t// names and bypass the AGENTS.md \"never expose error.message\" rule.\n\t\tconst postLocales = new Set<string>();\n\t\tfor (const post of wxr.posts) {\n\t\t\tif (post.locale) postLocales.add(post.locale);\n\t\t}\n\t\tif (postLocales.size > 0) {\n\t\t\ttry {\n\t\t\t\tawait mirrorTermsToLocales(emdash.db, taxonomyPlan, postLocales, config.locale);\n\t\t\t} catch (mirrorError) {\n\t\t\t\tif (isWxrTaxonomyConflictError(mirrorError)) {\n\t\t\t\t\tconsole.error(\"[WXR_IMPORT_TAXONOMY_CONFLICT]\", mirrorError);\n\t\t\t\t\treturn apiError(\"WXR_IMPORT_TAXONOMY_CONFLICT\", mirrorError.publicMessage, 409);\n\t\t\t\t}\n\t\t\t\tthrow mirrorError;\n\t\t\t}\n\t\t}\n\n\t\t// Import content (locale from config scopes all items)\n\t\tconst result = await importContent(\n\t\t\twxr.posts,\n\t\t\tconfig,\n\t\t\temdash,\n\t\t\temdashManifest,\n\t\t\tattachmentMap,\n\t\t\tconfig.locale,\n\t\t\tauthorDisplayNames,\n\t\t\ttaxonomyPlan,\n\t\t);\n\n\t\t// Import reusable blocks as sections (if enabled)\n\t\tif (config.importSections !== false) {\n\t\t\tconst sectionsResult = await importReusableBlocksAsSections(wxr.posts, emdash.db);\n\t\t\tresult.sections = {\n\t\t\t\tcreated: sectionsResult.sectionsCreated,\n\t\t\t\tskipped: sectionsResult.sectionsSkipped,\n\t\t\t};\n\t\t\t// Add section errors to main errors array\n\t\t\tresult.errors.push(...sectionsResult.errors);\n\t\t\tif (sectionsResult.errors.length > 0) {\n\t\t\t\tresult.success = false;\n\t\t\t}\n\t\t}\n\n\t\treturn apiSuccess(result);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to import content\", \"WXR_IMPORT_ERROR\");\n\t}\n};\n\nexport async function importContent(\n\tposts: WxrPost[],\n\tconfig: ImportConfig,\n\temdash: EmDashHandlers,\n\tmanifest: EmDashManifest,\n\tattachmentMap: Map<string, string>,\n\tlocale: string | undefined,\n\tauthorDisplayNames: Map<string, string> | undefined,\n\ttaxonomyPlan: TaxonomyImportPlan,\n): Promise<ImportResult> {\n\tconst result: ImportResult = {\n\t\tsuccess: true,\n\t\timported: 0,\n\t\tskipped: 0,\n\t\terrors: [],\n\t\tbyCollection: {},\n\t\ttaxonomies: {\n\t\t\ttermsCreated: taxonomyPlan.termsCreated,\n\t\t\ttermsReused: taxonomyPlan.termsReused,\n\t\t\tassignments: 0,\n\t\t\tmissingTaxonomies: taxonomyPlan.missingTaxonomies,\n\t\t},\n\t};\n\n\t// Create content repository for checking existing items\n\tconst contentRepo = new ContentRepository(emdash.db);\n\tconst bylineRepo = new BylineRepository(emdash.db);\n\tconst bylineCache = new Map<string, string>();\n\n\t// Source-side translation group ID -> the EmDash ID of the first post we\n\t// imported for that group. Subsequent translations are linked via\n\t// `translationOf` so they share a `translation_group` on the EmDash side.\n\tconst translationGroupMap = new Map<string, string>();\n\n\tfor (const post of posts) {\n\t\tconst postType = post.postType || \"post\";\n\t\tconst mapping = config.postTypeMappings[postType];\n\n\t\t// Skip if not mapped or disabled\n\t\tif (!mapping || !mapping.enabled) {\n\t\t\tresult.skipped++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Defensive: mapping.collection is already sanitized by prepare, but the user\n\t\t// could manually edit the import config between prepare and execute.\n\t\tconst collection = sanitizeSlug(mapping.collection);\n\n\t\t// Check if collection exists in manifest\n\t\tif (!manifest?.collections[collection]) {\n\t\t\tresult.errors.push({\n\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\terror: `Collection \"${collection}\" does not exist`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert content to Portable Text\n\t\t\tconst content = post.content ? gutenbergToPortableText(post.content) : [];\n\n\t\t\t// Generate slug from post name or title\n\t\t\tconst slug = post.postName || slugify(post.title || `post-${post.id || Date.now()}`);\n\n\t\t\t// Per-post locale: prefer the value extracted from WPML/Polylang\n\t\t\t// metadata; fall back to the upload-wide locale. Two translations\n\t\t\t// sharing `post_name` (e.g. /en/hello + /ar/hello) collide on the\n\t\t\t// `UNIQUE(slug, locale)` constraint when they share a locale, so\n\t\t\t// honouring the per-post value is what makes multilingual imports\n\t\t\t// land correctly. See issue #1080.\n\t\t\tconst postLocale = post.locale ?? locale;\n\n\t\t\t// Check if already exists (idempotency). Match against the\n\t\t\t// per-post locale so the same slug in different locales doesn't\n\t\t\t// false-positive as duplicate.\n\t\t\tif (config.skipExisting) {\n\t\t\t\tconst existing = await contentRepo.findBySlug(collection, slug, postLocale);\n\t\t\t\tif (existing) {\n\t\t\t\t\t// Record the translation group mapping so later\n\t\t\t\t\t// translations in this WXR can link to the existing\n\t\t\t\t\t// item. We deliberately trust the WXR's grouping over\n\t\t\t\t\t// the existing row's `translation_group`: a singleton\n\t\t\t\t\t// existing row gets folded into the WXR's group when\n\t\t\t\t\t// `handleContentCreate` resolves the new translation's\n\t\t\t\t\t// `translationOf`. Pre-existing translations that\n\t\t\t\t\t// already belong to a different group are left alone --\n\t\t\t\t\t// the user is responsible for reconciling those through\n\t\t\t\t\t// the admin if they don't match the WXR.\n\t\t\t\t\tif (post.translationGroup) {\n\t\t\t\t\t\ttranslationGroupMap.set(post.translationGroup, existing.id);\n\t\t\t\t\t}\n\t\t\t\t\tresult.skipped++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolve translation group: if this post belongs to a group and\n\t\t\t// we've already imported one of its translations, link to it.\n\t\t\tlet translationOf: string | undefined;\n\t\t\tif (post.translationGroup) {\n\t\t\t\ttranslationOf = translationGroupMap.get(post.translationGroup);\n\t\t\t}\n\n\t\t\t// Map WordPress status to EmDash status\n\t\t\tconst status = mapStatus(post.status);\n\n\t\t\t// Build data object with required fields\n\t\t\tconst data: Record<string, unknown> = {\n\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\tcontent,\n\t\t\t\texcerpt: post.excerpt || undefined,\n\t\t\t};\n\n\t\t\t// Only add featured_image if the collection has this field and we have a value\n\t\t\tconst collectionSchema = manifest.collections[collection];\n\t\t\tconst hasFeaturedImageField = collectionSchema?.fields\n\t\t\t\t? \"featured_image\" in collectionSchema.fields\n\t\t\t\t: false;\n\t\t\tif (hasFeaturedImageField) {\n\t\t\t\tconst thumbnailId = post.meta.get(\"_thumbnail_id\");\n\t\t\t\tconst featuredImage = thumbnailId ? attachmentMap.get(String(thumbnailId)) : undefined;\n\t\t\t\tif (featuredImage) {\n\t\t\t\t\tdata.featured_image = featuredImage;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolve author ID from mappings\n\t\t\tlet authorId: string | undefined;\n\t\t\tif (config.authorMappings && post.creator) {\n\t\t\t\tconst mappedUserId = config.authorMappings[post.creator];\n\t\t\t\tif (mappedUserId !== undefined && mappedUserId !== null) {\n\t\t\t\t\tauthorId = mappedUserId;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst bylineId = await resolveImportByline(\n\t\t\t\tpost.creator,\n\t\t\t\tauthorDisplayNames?.get(post.creator ?? \"\") ?? post.creator,\n\t\t\t\tauthorId,\n\t\t\t\tbylineRepo,\n\t\t\t\tbylineCache,\n\t\t\t);\n\n\t\t\t// Preserve original WordPress dates using the shared WXR date parser.\n\t\t\t// Fallback chain: postDateGmt (UTC) → pubDate (RFC 2822) → postDate (site-local).\n\t\t\tconst parsedDate = parseWxrDate(post.postDateGmt, post.pubDate, post.postDate);\n\t\t\tconst createdAt = parsedDate ? parsedDate.toISOString() : undefined;\n\t\t\tconst publishedAt = status === \"published\" && createdAt ? createdAt : undefined;\n\n\t\t\t// Create the content item\n\t\t\tconst createResult = await emdash.handleContentCreate(collection, {\n\t\t\t\tdata,\n\t\t\t\tslug,\n\t\t\t\tstatus,\n\t\t\t\tauthorId,\n\t\t\t\tbylines: bylineId ? [{ bylineId }] : undefined,\n\t\t\t\tlocale: postLocale,\n\t\t\t\ttranslationOf,\n\t\t\t\tcreatedAt,\n\t\t\t\tpublishedAt,\n\t\t\t});\n\n\t\t\tif (createResult.success) {\n\t\t\t\tresult.imported++;\n\t\t\t\tresult.byCollection[collection] = (result.byCollection[collection] || 0) + 1;\n\n\t\t\t\t// `handleContentCreate` returns `data: { item, _rev? }` on\n\t\t\t\t// success (see `ApiResult<ContentResponse>` in\n\t\t\t\t// `api/handlers/content.ts`). `HandlerResponse.data` is\n\t\t\t\t// typed as `unknown` to avoid coupling the route surface to\n\t\t\t\t// internal handler types, so we narrow here.\n\t\t\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- handler contract documented at handleContentCreate\n\t\t\t\tconst createdItem = (createResult.data as { item: { id: string } } | undefined)?.item;\n\n\t\t\t\t// Track translation group: the first imported post in a group\n\t\t\t\t// becomes the anchor that later translations link to.\n\t\t\t\tif (\n\t\t\t\t\tcreatedItem &&\n\t\t\t\t\tpost.translationGroup &&\n\t\t\t\t\t!translationGroupMap.has(post.translationGroup)\n\t\t\t\t) {\n\t\t\t\t\ttranslationGroupMap.set(post.translationGroup, createdItem.id);\n\t\t\t\t}\n\n\t\t\t\t// Attach taxonomy assignments parsed from the WXR's per-item\n\t\t\t\t// <category> elements.\n\t\t\t\t//\n\t\t\t\t// Anchors (no `translationOf`) get an additive attach -- the\n\t\t\t\t// row is fresh, no inherited pivots to consider.\n\t\t\t\t//\n\t\t\t\t// Translations get per-taxonomy replace semantics. WPML's\n\t\t\t\t// \"Translate Independently\" mode is per-taxonomy, not per-\n\t\t\t\t// post: a translation that overrides `category` shouldn't\n\t\t\t\t// lose its inherited `tag` or `genre`. The replace path\n\t\t\t\t// only touches taxonomies the translation actually carries\n\t\t\t\t// AND that resolve to at least one term that survives the\n\t\t\t\t// def's `collections` filter; taxonomies with no resolved\n\t\t\t\t// terms (missing-def, dropped by filter, or just absent\n\t\t\t\t// from the WXR) fall through with the inherited set intact\n\t\t\t\t// from `copyEntryTerms`.\n\t\t\t\tif (createdItem) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst written = translationOf\n\t\t\t\t\t\t\t? await setPostTermAssignmentsReplacing(\n\t\t\t\t\t\t\t\t\temdash.db,\n\t\t\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\t\t\tcreatedItem.id,\n\t\t\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t\t\ttaxonomyPlan,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: await attachPostTaxonomies(\n\t\t\t\t\t\t\t\t\temdash.db,\n\t\t\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\t\t\tcreatedItem.id,\n\t\t\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t\t\ttaxonomyPlan,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\tif (result.taxonomies) {\n\t\t\t\t\t\t\tresult.taxonomies.assignments += written;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (taxError) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`Failed to attach taxonomies for \"${post.title || \"Untitled\"}\":`,\n\t\t\t\t\t\t\ttaxError,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tresult.errors.push({\n\t\t\t\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\ttaxError instanceof Error && taxError.message\n\t\t\t\t\t\t\t\t\t? `Imported but failed to attach taxonomies: ${taxError.message}`\n\t\t\t\t\t\t\t\t\t: \"Imported but failed to attach taxonomies\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresult.errors.push({\n\t\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\t\terror:\n\t\t\t\t\t\ttypeof createResult.error === \"object\" && createResult.error !== null\n\t\t\t\t\t\t\t? (createResult.error as { message?: string }).message || \"Unknown error\"\n\t\t\t\t\t\t\t: String(createResult.error),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Import error for \"${post.title || \"Untitled\"}\":`, error);\n\t\t\tresult.errors.push({\n\t\t\t\ttitle: post.title || \"Untitled\",\n\t\t\t\terror: error instanceof Error && error.message ? error.message : \"Failed to import item\",\n\t\t\t});\n\t\t}\n\t}\n\n\tresult.success = result.errors.length === 0;\n\treturn result;\n}\n\nfunction mapStatus(wpStatus: string | undefined): string {\n\tswitch (wpStatus) {\n\t\tcase \"publish\":\n\t\t\treturn \"published\";\n\t\tcase \"draft\":\n\t\t\treturn \"draft\";\n\t\tcase \"pending\":\n\t\t\treturn \"draft\";\n\t\tcase \"private\":\n\t\t\treturn \"draft\";\n\t\tdefault:\n\t\t\treturn \"draft\";\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,IAAa,2BAAb,cAA8C,MAAM;CACnD,AAAS;CACT,Y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AI,YACH,KAAI;KACH,MAAM,UAAU,gBACb,MAAM,gCACN,OAAO,IACP,YACA,YAAY,IACZ,MACA,aACA,GACA,MAAM,qBACN,OAAO,IACP,YACA,YAAY,IACZ,MACA,aACA;AACH,SAAI,OAAO,WACV,QAAO,WAAW,eAAe;aAE1B,UAAU;AAClB,aAAQ,MACP,oCAAoC,KAAK,SAAS,WAAW,KAC7D,SACA;AACD,YAAO,OAAO,KAAK;MAClB,OAAO,KAAK,SAAS;MACrB,OACC,oBAAoB,SAAS,SAAS,UACnC,6CAA6C,SAAS,YACtD;MACJ,CAAC;;SAIJ,QAAO,OAAO,KAAK;IAClB,OAAO,KAAK,SAAS;IACrB,OACC,OAAO,aAAa,UAAU,YAAY,aAAa,UAAU,OAC7D,aAAa,MAA+B,WAAW,kBACxD,OAAO,aAAa,MAAM;IAC9B,CAAC;WAEK,OAAO;AACf,WAAQ,MAAM,qBAAqB,KAAK,SAAS,WAAW,KAAK,MAAM;AACvE,UAAO,OAAO,KAAK;IAClB,OAAO,KAAK,SAAS;IACrB,OAAO,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU;IACjE,CAAC;;;AAIJ,QAAO,UAAU,OAAO,OAAO,WAAW;AAC1C,QAAO;;AAGR,SAAS,UAAU,UAAsC;AACxD,SAAQ,UAAR;EACC,KAAK,UACJ,QAAO;EACR,KAAK,QACJ,QAAO;EACR,KAAK,UACJ,QAAO;EACR,KAAK,UACJ,QAAO;EACR,QACC,QAAO"}
@@ -1,13 +1,13 @@
1
1
  import "../../../../../base64-CqR-7kqF.mjs";
2
- import "../../../../../types-CwXMEPRr.mjs";
3
- import { a as validateExternalUrl, r as ssrfSafeFetch, t as SsrfError } from "../../../../../ssrf-DzFN_qV-.mjs";
4
- import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-tSQWIl5U.mjs";
5
- import { n as parseBody, t as isParseError } from "../../../../../parse-BFTPon-J.mjs";
6
- import "../../../../../redirects-Dmj6KRU3.mjs";
7
- import { s as wpMediaImportBody } from "../../../../../setup-BGAJ2uXs.mjs";
2
+ import "../../../../../types-ByV5sgsv.mjs";
3
+ import { a as validateExternalUrl, r as ssrfSafeFetch, t as SsrfError } from "../../../../../ssrf-MZ-zrG6-.mjs";
4
+ import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-CPh_8eLq.mjs";
5
+ import { n as parseBody, t as isParseError } from "../../../../../parse-3-caTKgt.mjs";
6
+ import "../../../../../redirects-COMLwsV5.mjs";
7
+ import { s as wpMediaImportBody } from "../../../../../setup-Cf_TyOv5.mjs";
8
8
  import "../../../../../api/schemas/index.mjs";
9
- import "../../../../../ssrf-CTul4uQi.mjs";
10
- import { n as requirePerm } from "../../../../../authorize-BlyCH-96.mjs";
9
+ import "../../../../../ssrf-BIcd-aXW.mjs";
10
+ import { n as requirePerm } from "../../../../../authorize-Bkwe8kuL.mjs";
11
11
  import { ulid } from "ulidx";
12
12
  import mime from "mime/lite";
13
13
  import * as path from "node:path";
@@ -1,12 +1,12 @@
1
1
  import "../../../../../base64-CqR-7kqF.mjs";
2
- import "../../../../../types-CwXMEPRr.mjs";
2
+ import "../../../../../types-ByV5sgsv.mjs";
3
3
  import { t as FIELD_TYPES } from "../../../../../types-DSZl1Dsv.mjs";
4
- import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-tSQWIl5U.mjs";
5
- import { n as parseBody, t as isParseError } from "../../../../../parse-BFTPon-J.mjs";
6
- import "../../../../../redirects-Dmj6KRU3.mjs";
7
- import { u as wpPrepareBody } from "../../../../../setup-BGAJ2uXs.mjs";
4
+ import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-CPh_8eLq.mjs";
5
+ import { n as parseBody, t as isParseError } from "../../../../../parse-3-caTKgt.mjs";
6
+ import "../../../../../redirects-COMLwsV5.mjs";
7
+ import { u as wpPrepareBody } from "../../../../../setup-Cf_TyOv5.mjs";
8
8
  import "../../../../../api/schemas/index.mjs";
9
- import { n as requirePerm } from "../../../../../authorize-BlyCH-96.mjs";
9
+ import { n as requirePerm } from "../../../../../authorize-Bkwe8kuL.mjs";
10
10
  import { capitalize, sanitizeSlug, singularize } from "./analyze.mjs";
11
11
 
12
12
  //#region src/astro/routes/api/import/wordpress/prepare.ts
@@ -31,7 +31,7 @@ const POST = async ({ request, locals }) => {
31
31
  }
32
32
  };
33
33
  async function prepareImport(db, request) {
34
- const { SchemaRegistry } = await import("../../../../../registry-BnCeHYsf.mjs").then((n) => n.r);
34
+ const { SchemaRegistry } = await import("../../../../../registry-DqrAQDXH.mjs").then((n) => n.r);
35
35
  const registry = new SchemaRegistry(db);
36
36
  const result = {
37
37
  success: true,
@@ -97,7 +97,7 @@ async function prepareImport(db, request) {
97
97
  "post",
98
98
  "page"
99
99
  ].includes(collectionSlug)) {
100
- const { FTSManager } = await import("../../../../../fts-manager-B633C-kQ.mjs").then((n) => n.n);
100
+ const { FTSManager } = await import("../../../../../fts-manager-Mnrtn-r2.mjs").then((n) => n.n);
101
101
  const ftsManager = new FTSManager(db);
102
102
  if ((await ftsManager.getSearchableFields(collectionSlug)).length > 0) try {
103
103
  await ftsManager.enableSearch(collectionSlug);
@@ -1 +1 @@
1
- {"version":3,"file":"prepare.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/import/wordpress/prepare.ts"],"sourcesContent":["/**\n * WordPress import prepare endpoint\n *\n * POST /_emdash/api/import/wordpress/prepare\n *\n * Creates collections and fields needed for import.\n * This is called after analyze, before execute.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { isParseError, parseBody } from \"#api/parse.js\";\nimport { wpPrepareBody } from \"#api/schemas.js\";\nimport { FIELD_TYPES, type FieldType } from \"#schema/types.js\";\nimport type { EmDashHandlers } from \"#types\";\n\nimport { capitalize, sanitizeSlug, singularize, type ImportFieldDef } from \"./analyze.js\";\n\n/** Validate that a string is a known FieldType, returning undefined if not */\nfunction asFieldType(value: string): FieldType | undefined {\n\t// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- validated by includes check\n\treturn (FIELD_TYPES as readonly string[]).includes(value) ? (value as FieldType) : undefined;\n}\n\nexport const prerender = false;\n\ninterface PrepareRequest {\n\tpostTypes: Array<{\n\t\tname: string;\n\t\tcollection: string;\n\t\tfields: ImportFieldDef[];\n\t}>;\n}\n\nexport interface PrepareResult {\n\tsuccess: boolean;\n\tcollectionsCreated: string[];\n\tfieldsCreated: Array<{ collection: string; field: string }>;\n\terrors: Array<{ collection: string; error: string }>;\n}\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash not configured\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst body = await parseBody(request, wpPrepareBody);\n\t\tif (isParseError(body)) return body;\n\n\t\t// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- Zod schema output narrowed to PrepareRequest\n\t\tconst result = await prepareImport(emdash.db, body as PrepareRequest);\n\n\t\t// Invalidate the URL pattern cache when prepare adds new collections so\n\t\t// public routing picks up their patterns immediately. The manifest\n\t\t// itself is built fresh per admin request, so cross-request\n\t\t// staleness (the original failure mode in #747) is no longer\n\t\t// possible — the execute step always reads live schema.\n\t\tif (result.collectionsCreated.length > 0) {\n\t\t\temdash.invalidateUrlPatternCache();\n\t\t}\n\n\t\treturn apiSuccess(result, result.success ? 200 : 400);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to prepare import\", \"WXR_PREPARE_ERROR\");\n\t}\n};\n\nasync function prepareImport(\n\tdb: NonNullable<EmDashHandlers[\"db\"]>,\n\trequest: PrepareRequest,\n): Promise<PrepareResult> {\n\tconst { SchemaRegistry } = await import(\"#schema/registry.js\");\n\tconst registry = new SchemaRegistry(db);\n\n\tconst result: PrepareResult = {\n\t\tsuccess: true,\n\t\tcollectionsCreated: [],\n\t\tfieldsCreated: [],\n\t\terrors: [],\n\t};\n\n\tfor (const postType of request.postTypes) {\n\t\tconst collectionSlug = sanitizeSlug(postType.collection);\n\n\t\ttry {\n\t\t\t// Check if collection exists\n\t\t\tlet collection = await registry.getCollection(collectionSlug);\n\n\t\t\tif (!collection) {\n\t\t\t\t// Create the collection\n\t\t\t\tconst label = capitalize(collectionSlug);\n\t\t\t\tconst labelSingular = capitalize(singularize(collectionSlug));\n\n\t\t\t\t// Enable search by default for posts and pages\n\t\t\t\tconst isSearchable = [\"posts\", \"pages\", \"post\", \"page\"].includes(collectionSlug);\n\t\t\t\tconst supports: (\"revisions\" | \"drafts\" | \"search\")[] = [\"revisions\", \"drafts\"];\n\t\t\t\tif (isSearchable) {\n\t\t\t\t\tsupports.push(\"search\");\n\t\t\t\t}\n\n\t\t\t\t// Default URL patterns for known post types\n\t\t\t\tconst urlPattern =\n\t\t\t\t\tcollectionSlug === \"pages\"\n\t\t\t\t\t\t? \"/{slug}\"\n\t\t\t\t\t\t: collectionSlug === \"posts\"\n\t\t\t\t\t\t\t? \"/blog/{slug}\"\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\tcollection = await registry.createCollection({\n\t\t\t\t\tslug: collectionSlug,\n\t\t\t\t\tlabel,\n\t\t\t\t\tlabelSingular,\n\t\t\t\t\tdescription: `Imported from WordPress post type: ${postType.name}`,\n\t\t\t\t\tsupports,\n\t\t\t\t\turlPattern,\n\t\t\t\t});\n\n\t\t\t\tresult.collectionsCreated.push(collectionSlug);\n\t\t\t}\n\n\t\t\t// Create missing fields\n\t\t\tconst existingFields = await registry.listFields(collection.id);\n\t\t\tconst existingFieldSlugs = new Set(existingFields.map((f) => f.slug));\n\n\t\t\tfor (const field of postType.fields) {\n\t\t\t\tif (existingFieldSlugs.has(field.slug)) {\n\t\t\t\t\t// Field already exists - skip\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst fieldType = asFieldType(field.type);\n\t\t\t\tif (!fieldType) {\n\t\t\t\t\tresult.errors.push({\n\t\t\t\t\t\tcollection: collectionSlug,\n\t\t\t\t\t\terror: `Unknown field type \"${field.type}\" for field \"${field.slug}\"`,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait registry.createField(collectionSlug, {\n\t\t\t\t\tslug: field.slug,\n\t\t\t\t\tlabel: field.label,\n\t\t\t\t\ttype: fieldType,\n\t\t\t\t\trequired: field.required,\n\t\t\t\t\tunique: false,\n\t\t\t\t\tsearchable: field.searchable ?? false,\n\t\t\t\t\tsortOrder: existingFields.length + result.fieldsCreated.length,\n\t\t\t\t});\n\n\t\t\t\tresult.fieldsCreated.push({\n\t\t\t\t\tcollection: collectionSlug,\n\t\t\t\t\tfield: field.slug,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Enable search if collection supports it and has searchable fields\n\t\t\tconst isSearchable = [\"posts\", \"pages\", \"post\", \"page\"].includes(collectionSlug);\n\t\t\tif (isSearchable) {\n\t\t\t\tconst { FTSManager } = await import(\"#search/fts-manager.js\");\n\t\t\t\tconst ftsManager = new FTSManager(db);\n\n\t\t\t\tconst searchableFields = await ftsManager.getSearchableFields(collectionSlug);\n\t\t\t\tif (searchableFields.length > 0) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait ftsManager.enableSearch(collectionSlug);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore - search can be enabled manually later\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Prepare error for collection \"${collectionSlug}\":`, error);\n\t\t\tresult.success = false;\n\t\t\tresult.errors.push({\n\t\t\t\tcollection: collectionSlug,\n\t\t\t\terror: \"Failed to prepare collection\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;;;AAqBA,SAAS,YAAY,OAAsC;AAE1D,QAAQ,YAAkC,SAAS,MAAM,GAAI,Q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a,sCAAsC,SAAS;KAC5D;KACA;KACA,CAAC;AAEF,WAAO,mBAAmB,KAAK,eAAe;;GAI/C,MAAM,iBAAiB,MAAM,SAAS,WAAW,WAAW,GAAG;GAC/D,MAAM,qBAAqB,IAAI,IAAI,eAAe,KAAK,MAAM,EAAE,KAAK,CAAC;AAErE,QAAK,MAAM,SAAS,SAAS,QAAQ;AACpC,QAAI,mBAAmB,IAAI,MAAM,KAAK,CAErC;IAGD,MAAM,YAAY,YAAY,MAAM,KAAK;AACzC,QAAI,CAAC,WAAW;AACf,YAAO,OAAO,KAAK;MAClB,YAAY;MACZ,OAAO,uBAAuB,MAAM,KAAK,eAAe,MAAM,KAAK;MACnE,CAAC;AACF;;AAGD,UAAM,SAAS,YAAY,gBAAgB;KAC1C,MAAM,MAAM;KACZ,OAAO,MAAM;KACb,MAAM;KACN,UAAU,MAAM;KAChB,QAAQ;KACR,YAAY,MAAM,cAAc;KAChC,WAAW,eAAe,SAAS,OAAO,cAAc;KACxD,CAAC;AAEF,WAAO,cAAc,KAAK;KACzB,YAAY;KACZ,OAAO,MAAM;KACb,CAAC;;AAKH,OADqB;IAAC;IAAS;IAAS;IAAQ;IAAO,CAAC,SAAS,eAAe,EAC9D;IACjB,MAAM,EAAE,eAAe,MAAM,OAAO;IACpC,MAAM,aAAa,IAAI,WAAW,GAAG;AAGrC,SADyB,MAAM,WAAW,oBAAoB,eAAe,EACxD,SAAS,EAC7B,KAAI;AACH,WAAM,WAAW,aAAa,eAAe;YACtC;;WAKF,OAAO;AACf,WAAQ,MAAM,iCAAiC,eAAe,KAAK,MAAM;AACzE,UAAO,UAAU;AACjB,UAAO,OAAO,KAAK;IAClB,YAAY;IACZ,OAAO;IACP,CAAC;;;AAIJ,QAAO"}
1
+ {"version":3,"file":"prepare.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/import/wordpress/prepare.ts"],"sourcesContent":["/**\n * WordPress import prepare endpoint\n *\n * POST /_emdash/api/import/wordpress/prepare\n *\n * Creates collections and fields needed for import.\n * This is called after analyze, before execute.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { isParseError, parseBody } from \"#api/parse.js\";\nimport { wpPrepareBody } from \"#api/schemas.js\";\nimport { FIELD_TYPES, type FieldType } from \"#schema/types.js\";\nimport type { EmDashHandlers } from \"#types\";\n\nimport { capitalize, sanitizeSlug, singularize, type ImportFieldDef } from \"./analyze.js\";\n\n/** Validate that a string is a known FieldType, returning undefined if not */\nfunction asFieldType(value: string): FieldType | undefined {\n\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- validated by includes check\n\treturn (FIELD_TYPES as readonly string[]).includes(value) ? (value as FieldType) : undefined;\n}\n\nexport const prerender = false;\n\ninterface PrepareRequest {\n\tpostTypes: Array<{\n\t\tname: string;\n\t\tcollection: string;\n\t\tfields: ImportFieldDef[];\n\t}>;\n}\n\nexport interface PrepareResult {\n\tsuccess: boolean;\n\tcollectionsCreated: string[];\n\tfieldsCreated: Array<{ collection: string; field: string }>;\n\terrors: Array<{ collection: string; error: string }>;\n}\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash not configured\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst body = await parseBody(request, wpPrepareBody);\n\t\tif (isParseError(body)) return body;\n\n\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- Zod schema output narrowed to PrepareRequest\n\t\tconst result = await prepareImport(emdash.db, body as PrepareRequest);\n\n\t\t// Invalidate the URL pattern cache when prepare adds new collections so\n\t\t// public routing picks up their patterns immediately. The manifest\n\t\t// itself is built fresh per admin request, so cross-request\n\t\t// staleness (the original failure mode in #747) is no longer\n\t\t// possible — the execute step always reads live schema.\n\t\tif (result.collectionsCreated.length > 0) {\n\t\t\temdash.invalidateUrlPatternCache();\n\t\t}\n\n\t\treturn apiSuccess(result, result.success ? 200 : 400);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to prepare import\", \"WXR_PREPARE_ERROR\");\n\t}\n};\n\nasync function prepareImport(\n\tdb: NonNullable<EmDashHandlers[\"db\"]>,\n\trequest: PrepareRequest,\n): Promise<PrepareResult> {\n\tconst { SchemaRegistry } = await import(\"#schema/registry.js\");\n\tconst registry = new SchemaRegistry(db);\n\n\tconst result: PrepareResult = {\n\t\tsuccess: true,\n\t\tcollectionsCreated: [],\n\t\tfieldsCreated: [],\n\t\terrors: [],\n\t};\n\n\tfor (const postType of request.postTypes) {\n\t\tconst collectionSlug = sanitizeSlug(postType.collection);\n\n\t\ttry {\n\t\t\t// Check if collection exists\n\t\t\tlet collection = await registry.getCollection(collectionSlug);\n\n\t\t\tif (!collection) {\n\t\t\t\t// Create the collection\n\t\t\t\tconst label = capitalize(collectionSlug);\n\t\t\t\tconst labelSingular = capitalize(singularize(collectionSlug));\n\n\t\t\t\t// Enable search by default for posts and pages\n\t\t\t\tconst isSearchable = [\"posts\", \"pages\", \"post\", \"page\"].includes(collectionSlug);\n\t\t\t\tconst supports: (\"revisions\" | \"drafts\" | \"search\")[] = [\"revisions\", \"drafts\"];\n\t\t\t\tif (isSearchable) {\n\t\t\t\t\tsupports.push(\"search\");\n\t\t\t\t}\n\n\t\t\t\t// Default URL patterns for known post types\n\t\t\t\tconst urlPattern =\n\t\t\t\t\tcollectionSlug === \"pages\"\n\t\t\t\t\t\t? \"/{slug}\"\n\t\t\t\t\t\t: collectionSlug === \"posts\"\n\t\t\t\t\t\t\t? \"/blog/{slug}\"\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\tcollection = await registry.createCollection({\n\t\t\t\t\tslug: collectionSlug,\n\t\t\t\t\tlabel,\n\t\t\t\t\tlabelSingular,\n\t\t\t\t\tdescription: `Imported from WordPress post type: ${postType.name}`,\n\t\t\t\t\tsupports,\n\t\t\t\t\turlPattern,\n\t\t\t\t});\n\n\t\t\t\tresult.collectionsCreated.push(collectionSlug);\n\t\t\t}\n\n\t\t\t// Create missing fields\n\t\t\tconst existingFields = await registry.listFields(collection.id);\n\t\t\tconst existingFieldSlugs = new Set(existingFields.map((f) => f.slug));\n\n\t\t\tfor (const field of postType.fields) {\n\t\t\t\tif (existingFieldSlugs.has(field.slug)) {\n\t\t\t\t\t// Field already exists - skip\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst fieldType = asFieldType(field.type);\n\t\t\t\tif (!fieldType) {\n\t\t\t\t\tresult.errors.push({\n\t\t\t\t\t\tcollection: collectionSlug,\n\t\t\t\t\t\terror: `Unknown field type \"${field.type}\" for field \"${field.slug}\"`,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait registry.createField(collectionSlug, {\n\t\t\t\t\tslug: field.slug,\n\t\t\t\t\tlabel: field.label,\n\t\t\t\t\ttype: fieldType,\n\t\t\t\t\trequired: field.required,\n\t\t\t\t\tunique: false,\n\t\t\t\t\tsearchable: field.searchable ?? false,\n\t\t\t\t\tsortOrder: existingFields.length + result.fieldsCreated.length,\n\t\t\t\t});\n\n\t\t\t\tresult.fieldsCreated.push({\n\t\t\t\t\tcollection: collectionSlug,\n\t\t\t\t\tfield: field.slug,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Enable search if collection supports it and has searchable fields\n\t\t\tconst isSearchable = [\"posts\", \"pages\", \"post\", \"page\"].includes(collectionSlug);\n\t\t\tif (isSearchable) {\n\t\t\t\tconst { FTSManager } = await import(\"#search/fts-manager.js\");\n\t\t\t\tconst ftsManager = new FTSManager(db);\n\n\t\t\t\tconst searchableFields = await ftsManager.getSearchableFields(collectionSlug);\n\t\t\t\tif (searchableFields.length > 0) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait ftsManager.enableSearch(collectionSlug);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore - search can be enabled manually later\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Prepare error for collection \"${collectionSlug}\":`, error);\n\t\t\tresult.success = false;\n\t\t\tresult.errors.push({\n\t\t\t\tcollection: collectionSlug,\n\t\t\t\terror: \"Failed to prepare collection\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;;;AAqBA,SAAS,YAAY,OAAsC;AAE1D,QAAQ,YAAkC,SAAS,MAAM,GAAI,QAAsB;;AAGpF,MAAa,YAAY;AAiBzB,MAAa,OAAiB,OAAO,EAAE,SAAS,aAAa;CAC5D,MAAM,EAAE,QAAQ,SAAS;AAEzB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,yBAAyB,IAAI;CAGhE,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EACH,MAAM,OAAO,MAAM,UAAU,SAAS,cAAc;AACpD,MAAI,aAAa,KAAK,CAAE,QAAO;EAG/B,MAAM,SAAS,MAAM,cAAc,OAAO,IAAI,KAAuB;AAOrE,MAAI,OAAO,mBAAmB,SAAS,EACtC,QAAO,2BAA2B;AAGnC,SAAO,WAAW,QAAQ,OAAO,UAAU,MAAM,IAAI;UAC7C,OAAO;AACf,SAAO,YAAY,OAAO,4BAA4B,oBAAoB;;;AAI5E,eAAe,cACd,IACA,SACyB;CACzB,MAAM,EAAE,mBAAmB,MAAM,OAAO;CACxC,MAAM,WAAW,IAAI,eAAe,GAAG;CAEvC,MAAM,SAAwB;EAC7B,SAAS;EACT,oBAAoB,EAAE;EACtB,eAAe,EAAE;EACjB,QAAQ,EAAE;EACV;AAED,MAAK,MAAM,YAAY,QAAQ,WAAW;EACzC,MAAM,iBAAiB,aAAa,SAAS,WAAW;AAExD,MAAI;GAEH,IAAI,aAAa,MAAM,SAAS,cAAc,eAAe;AAE7D,OA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SAAS,EAC7B,KAAI;AACH,WAAM,WAAW,aAAa,eAAe;YACtC;;WAKF,OAAO;AACf,WAAQ,MAAM,iCAAiC,eAAe,KAAK,MAAM;AACzE,UAAO,UAAU;AACjB,UAAO,OAAO,KAAK;IAClB,YAAY;IACZ,OAAO;IACP,CAAC;;;AAIJ,QAAO"}
@@ -1,13 +1,13 @@
1
1
  import { t as validateIdentifier } from "../../../../../validate-VPnKoIzW.mjs";
2
2
  import "../../../../../base64-CqR-7kqF.mjs";
3
- import "../../../../../types-CwXMEPRr.mjs";
3
+ import "../../../../../types-ByV5sgsv.mjs";
4
4
  import { t as normalizeMediaValue } from "../../../../../normalize-CN5kRSMC.mjs";
5
- import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-tSQWIl5U.mjs";
6
- import { n as parseBody, t as isParseError } from "../../../../../parse-BFTPon-J.mjs";
7
- import "../../../../../redirects-Dmj6KRU3.mjs";
8
- import { d as wpRewriteUrlsBody } from "../../../../../setup-BGAJ2uXs.mjs";
5
+ import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-CPh_8eLq.mjs";
6
+ import { n as parseBody, t as isParseError } from "../../../../../parse-3-caTKgt.mjs";
7
+ import "../../../../../redirects-COMLwsV5.mjs";
8
+ import { d as wpRewriteUrlsBody } from "../../../../../setup-Cf_TyOv5.mjs";
9
9
  import "../../../../../api/schemas/index.mjs";
10
- import { n as requirePerm } from "../../../../../authorize-BlyCH-96.mjs";
10
+ import { n as requirePerm } from "../../../../../authorize-Bkwe8kuL.mjs";
11
11
  import { buildBaseUrlMap, findMatchingUrl, rewritePortableTextUrls, rewriteStringUrls } from "./rewrite-url-helpers.mjs";
12
12
  import { sql } from "kysely";
13
13
 
@@ -34,7 +34,7 @@ const POST = async ({ request, locals }) => {
34
34
  }
35
35
  };
36
36
  async function rewriteUrls(db, urlMap, getProvider, collections) {
37
- const { SchemaRegistry } = await import("../../../../../registry-BnCeHYsf.mjs").then((n) => n.r);
37
+ const { SchemaRegistry } = await import("../../../../../registry-DqrAQDXH.mjs").then((n) => n.r);
38
38
  const registry = new SchemaRegistry(db);
39
39
  const result = {
40
40
  updated: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"rewrite-urls.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/import/wordpress/rewrite-urls.ts"],"sourcesContent":["/**\n * WordPress URL rewrite endpoint\n *\n * POST /_emdash/api/import/wordpress/rewrite-urls\n *\n * Rewrites old WordPress media URLs in Portable Text content\n * to point to newly imported EmDash media URLs.\n *\n * Handles URL variants (e.g., image.jpg vs image.jpg?w=200) by matching\n * on the base URL path without query parameters.\n */\n\nimport type { APIRoute } from \"astro\";\nimport { sql } from \"kysely\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { isParseError, parseBody } from \"#api/parse.js\";\nimport { wpRewriteUrlsBody } from \"#api/schemas.js\";\nimport { validateIdentifier } from \"#db/validate.js\";\nimport { normalizeMediaValue } from \"#media/normalize.js\";\nimport type { MediaProvider } from \"#media/types.js\";\nimport type { EmDashHandlers } from \"#types\";\n\nimport {\n\tbuildBaseUrlMap,\n\tfindMatchingUrl,\n\trewritePortableTextUrls,\n\trewriteStringUrls,\n} from \"./rewrite-url-helpers.js\";\nimport type { PortableTextBlock } from \"./rewrite-url-helpers.js\";\n\nexport interface RewriteUrlsResult {\n\t/** Total items updated */\n\tupdated: number;\n\t/** Updates by collection */\n\tbyCollection: Record<string, number>;\n\t/** URLs that were rewritten */\n\turlsRewritten: number;\n\t/** Any errors encountered */\n\terrors: Array<{ collection: string; id: string; error: string }>;\n}\n\nexport const prerender = false;\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NO_DB\", \"Database not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst body = await parseBody(request, wpRewriteUrlsBody);\n\t\tif (isParseError(body)) return body;\n\n\t\tconst urlEntries = Object.entries(body.urlMap);\n\t\tif (urlEntries.length === 0) {\n\t\t\treturn apiSuccess({\n\t\t\t\tupdated: 0,\n\t\t\t\tbyCollection: {},\n\t\t\t\turlsRewritten: 0,\n\t\t\t\terrors: [],\n\t\t\t});\n\t\t}\n\n\t\tconst getProvider = (id: string) => emdash.getMediaProvider(id);\n\t\tconst result = await rewriteUrls(emdash.db, body.urlMap, getProvider, body.collections);\n\n\t\treturn apiSuccess(result);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to rewrite URLs\", \"REWRITE_ERROR\");\n\t}\n};\n\nasync function rewriteUrls(\n\tdb: NonNullable<EmDashHandlers[\"db\"]>,\n\turlMap: Record<string, string>,\n\tgetProvider: (id: string) => MediaProvider | undefined,\n\tcollections?: string[],\n): Promise<RewriteUrlsResult> {\n\tconst { SchemaRegistry } = await import(\"#schema/registry.js\");\n\tconst registry = new SchemaRegistry(db);\n\n\tconst result: RewriteUrlsResult = {\n\t\tupdated: 0,\n\t\tbyCollection: {},\n\t\turlsRewritten: 0,\n\t\terrors: [],\n\t};\n\n\t// Build base URL map for flexible matching\n\tconst baseMap = buildBaseUrlMap(urlMap);\n\n\t// Get all collections or filter to specified ones\n\tconst allCollections = await registry.listCollections();\n\tconst targetCollections = collections?.length\n\t\t? allCollections.filter((c) => collections.includes(c.slug))\n\t\t: allCollections;\n\n\tfor (const collection of targetCollections) {\n\t\t// Get fields that might contain URLs\n\t\tconst fields = await registry.listFields(collection.id);\n\t\tconst portableTextFields = fields.filter((f) => f.type === \"portableText\");\n\t\tconst stringFields = fields.filter((f) => [\"text\", \"string\"].includes(f.type));\n\t\t// Image and file fields store URLs directly as TEXT\n\t\tconst mediaFields = fields.filter((f) => [\"image\", \"file\"].includes(f.type));\n\n\t\tif (portableTextFields.length === 0 && stringFields.length === 0 && mediaFields.length === 0)\n\t\t\tcontinue;\n\n\t\t// Get table name\n\t\tvalidateIdentifier(collection.slug, \"collection slug\");\n\t\tconst tableName = `ec_${collection.slug}`;\n\n\t\ttry {\n\t\t\t// Query all rows\n\t\t\tconst rows = await sql<{ id: string; [key: string]: unknown }>`\n\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\tWHERE deleted_at IS NULL\n\t\t\t`.execute(db);\n\n\t\t\tfor (const row of rows.rows) {\n\t\t\t\tlet rowUpdated = false;\n\t\t\t\tconst updates: Record<string, unknown> = {};\n\t\t\t\tlet rowUrlsRewritten = 0;\n\n\t\t\t\t// Handle Portable Text fields - parse JSON and rewrite URLs in blocks\n\t\t\t\tfor (const field of portableTextFields) {\n\t\t\t\t\tconst value = row[field.slug];\n\t\t\t\t\tif (!value || typeof value !== \"string\") continue;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- JSON.parse returns unknown; validated by Array.isArray below\n\t\t\t\t\t\tconst blocks = JSON.parse(value) as PortableTextBlock[];\n\t\t\t\t\t\tif (!Array.isArray(blocks)) continue;\n\n\t\t\t\t\t\tconst rewriteResult = rewritePortableTextUrls(blocks, urlMap, baseMap);\n\n\t\t\t\t\t\tif (rewriteResult.changed) {\n\t\t\t\t\t\t\tupdates[field.slug] = JSON.stringify(blocks);\n\t\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\t\trowUrlsRewritten += rewriteResult.urlsRewritten;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Not valid JSON, try string replacement as fallback\n\t\t\t\t\t\tconst stringResult = rewriteStringUrls(value, urlMap, baseMap);\n\t\t\t\t\t\tif (stringResult.changed) {\n\t\t\t\t\t\t\tupdates[field.slug] = stringResult.newValue;\n\t\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\t\trowUrlsRewritten += stringResult.urlsRewritten;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle string/text fields - simple string replacement\n\t\t\t\tfor (const field of stringFields) {\n\t\t\t\t\tconst value = row[field.slug];\n\t\t\t\t\tif (!value || typeof value !== \"string\") continue;\n\n\t\t\t\t\tconst stringResult = rewriteStringUrls(value, urlMap, baseMap);\n\t\t\t\t\tif (stringResult.changed) {\n\t\t\t\t\t\tupdates[field.slug] = stringResult.newValue;\n\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\trowUrlsRewritten += stringResult.urlsRewritten;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle image/file fields - normalize to MediaValue objects\n\t\t\t\tfor (const field of mediaFields) {\n\t\t\t\t\tconst value = row[field.slug];\n\t\t\t\t\tif (!value || typeof value !== \"string\") continue;\n\n\t\t\t\t\t// Try to find a matching rewritten URL\n\t\t\t\t\tconst newUrl = findMatchingUrl(value, urlMap, baseMap);\n\t\t\t\t\tif (newUrl) {\n\t\t\t\t\t\t// Normalize into a proper MediaValue instead of storing a bare URL\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst normalized = await normalizeMediaValue(newUrl, getProvider);\n\t\t\t\t\t\t\tupdates[field.slug] = normalized ? JSON.stringify(normalized) : newUrl;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tupdates[field.slug] = newUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\trowUrlsRewritten++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (rowUpdated) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Build update query dynamically\n\t\t\t\t\t\t// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- Kysely dynamic table requires type assertion\n\t\t\t\t\t\tlet query = db.updateTable(tableName as any).where(\"id\", \"=\", row.id);\n\n\t\t\t\t\t\tfor (const [key, value] of Object.entries(updates)) {\n\t\t\t\t\t\t\t// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- Kysely dynamic column update requires type assertion\n\t\t\t\t\t\t\tquery = query.set({ [key]: value } as any);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait query.execute();\n\n\t\t\t\t\t\tresult.updated++;\n\t\t\t\t\t\tresult.urlsRewritten += rowUrlsRewritten;\n\t\t\t\t\t\tresult.byCollection[collection.slug] = (result.byCollection[collection.slug] || 0) + 1;\n\t\t\t\t\t} catch (updateError) {\n\t\t\t\t\t\tresult.errors.push({\n\t\t\t\t\t\t\tcollection: collection.slug,\n\t\t\t\t\t\t\tid: row.id,\n\t\t\t\t\t\t\terror: updateError instanceof Error ? updateError.message : \"Update failed\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (queryError) {\n\t\t\tresult.errors.push({\n\t\t\t\tcollection: collection.slug,\n\t\t\t\tid: \"*\",\n\t\t\t\terror: queryError instanceof Error ? queryError.message : \"Query failed for collection\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;;;;AA2CA,MAAa,YAAY;AAEzB,MAAa,OAAiB,OAAO,EAAE,SAAS,aAAa;CAC5D,MAAM,EAAE,QAAQ,SAAS;AAEzB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,SAAS,4BAA4B,IAAI;CAG1D,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EACH,MAAM,OAAO,MAAM,UAAU,SAAS,kBAAkB;AACxD,MAAI,aAAa,KAAK,CAAE,QAAO;AAG/B,MADmB,OAAO,QAAQ,KAAK,OAAO,CAC/B,WAAW,EACzB,QAAO,WAAW;GACjB,SAAS;GACT,cAAc,EAAE;GAChB,eAAe;GACf,QAAQ,EAAE;GACV,CAAC;EAGH,MAAM,eAAe,OAAe,OAAO,iBAAiB,GAAG;AAG/D,SAAO,WAFQ,MAAM,YAAY,OAAO,IAAI,KAAK,QAAQ,aAAa,KAAK,YAAY,CAE9D;UACjB,OAAO;AACf,SAAO,YAAY,OA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B,YAAO,OAAO,KAAK;MAClB,YAAY,WAAW;MACvB,IAAI,IAAI;MACR,OAAO,uBAAuB,QAAQ,YAAY,UAAU;MAC5D,CAAC;;;WAIG,YAAY;AACpB,UAAO,OAAO,KAAK;IAClB,YAAY,WAAW;IACvB,IAAI;IACJ,OAAO,sBAAsB,QAAQ,WAAW,UAAU;IAC1D,CAAC;;;AAIJ,QAAO"}
1
+ {"version":3,"file":"rewrite-urls.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/import/wordpress/rewrite-urls.ts"],"sourcesContent":["/**\n * WordPress URL rewrite endpoint\n *\n * POST /_emdash/api/import/wordpress/rewrite-urls\n *\n * Rewrites old WordPress media URLs in Portable Text content\n * to point to newly imported EmDash media URLs.\n *\n * Handles URL variants (e.g., image.jpg vs image.jpg?w=200) by matching\n * on the base URL path without query parameters.\n */\n\nimport type { APIRoute } from \"astro\";\nimport { sql } from \"kysely\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { isParseError, parseBody } from \"#api/parse.js\";\nimport { wpRewriteUrlsBody } from \"#api/schemas.js\";\nimport { validateIdentifier } from \"#db/validate.js\";\nimport { normalizeMediaValue } from \"#media/normalize.js\";\nimport type { MediaProvider } from \"#media/types.js\";\nimport type { EmDashHandlers } from \"#types\";\n\nimport {\n\tbuildBaseUrlMap,\n\tfindMatchingUrl,\n\trewritePortableTextUrls,\n\trewriteStringUrls,\n} from \"./rewrite-url-helpers.js\";\nimport type { PortableTextBlock } from \"./rewrite-url-helpers.js\";\n\nexport interface RewriteUrlsResult {\n\t/** Total items updated */\n\tupdated: number;\n\t/** Updates by collection */\n\tbyCollection: Record<string, number>;\n\t/** URLs that were rewritten */\n\turlsRewritten: number;\n\t/** Any errors encountered */\n\terrors: Array<{ collection: string; id: string; error: string }>;\n}\n\nexport const prerender = false;\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NO_DB\", \"Database not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst body = await parseBody(request, wpRewriteUrlsBody);\n\t\tif (isParseError(body)) return body;\n\n\t\tconst urlEntries = Object.entries(body.urlMap);\n\t\tif (urlEntries.length === 0) {\n\t\t\treturn apiSuccess({\n\t\t\t\tupdated: 0,\n\t\t\t\tbyCollection: {},\n\t\t\t\turlsRewritten: 0,\n\t\t\t\terrors: [],\n\t\t\t});\n\t\t}\n\n\t\tconst getProvider = (id: string) => emdash.getMediaProvider(id);\n\t\tconst result = await rewriteUrls(emdash.db, body.urlMap, getProvider, body.collections);\n\n\t\treturn apiSuccess(result);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to rewrite URLs\", \"REWRITE_ERROR\");\n\t}\n};\n\nasync function rewriteUrls(\n\tdb: NonNullable<EmDashHandlers[\"db\"]>,\n\turlMap: Record<string, string>,\n\tgetProvider: (id: string) => MediaProvider | undefined,\n\tcollections?: string[],\n): Promise<RewriteUrlsResult> {\n\tconst { SchemaRegistry } = await import(\"#schema/registry.js\");\n\tconst registry = new SchemaRegistry(db);\n\n\tconst result: RewriteUrlsResult = {\n\t\tupdated: 0,\n\t\tbyCollection: {},\n\t\turlsRewritten: 0,\n\t\terrors: [],\n\t};\n\n\t// Build base URL map for flexible matching\n\tconst baseMap = buildBaseUrlMap(urlMap);\n\n\t// Get all collections or filter to specified ones\n\tconst allCollections = await registry.listCollections();\n\tconst targetCollections = collections?.length\n\t\t? allCollections.filter((c) => collections.includes(c.slug))\n\t\t: allCollections;\n\n\tfor (const collection of targetCollections) {\n\t\t// Get fields that might contain URLs\n\t\tconst fields = await registry.listFields(collection.id);\n\t\tconst portableTextFields = fields.filter((f) => f.type === \"portableText\");\n\t\tconst stringFields = fields.filter((f) => [\"text\", \"string\"].includes(f.type));\n\t\t// Image and file fields store URLs directly as TEXT\n\t\tconst mediaFields = fields.filter((f) => [\"image\", \"file\"].includes(f.type));\n\n\t\tif (portableTextFields.length === 0 && stringFields.length === 0 && mediaFields.length === 0)\n\t\t\tcontinue;\n\n\t\t// Get table name\n\t\tvalidateIdentifier(collection.slug, \"collection slug\");\n\t\tconst tableName = `ec_${collection.slug}`;\n\n\t\ttry {\n\t\t\t// Query all rows\n\t\t\tconst rows = await sql<{ id: string; [key: string]: unknown }>`\n\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\tWHERE deleted_at IS NULL\n\t\t\t`.execute(db);\n\n\t\t\tfor (const row of rows.rows) {\n\t\t\t\tlet rowUpdated = false;\n\t\t\t\tconst updates: Record<string, unknown> = {};\n\t\t\t\tlet rowUrlsRewritten = 0;\n\n\t\t\t\t// Handle Portable Text fields - parse JSON and rewrite URLs in blocks\n\t\t\t\tfor (const field of portableTextFields) {\n\t\t\t\t\tconst value = row[field.slug];\n\t\t\t\t\tif (!value || typeof value !== \"string\") continue;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- JSON.parse returns unknown; validated by Array.isArray below\n\t\t\t\t\t\tconst blocks = JSON.parse(value) as PortableTextBlock[];\n\t\t\t\t\t\tif (!Array.isArray(blocks)) continue;\n\n\t\t\t\t\t\tconst rewriteResult = rewritePortableTextUrls(blocks, urlMap, baseMap);\n\n\t\t\t\t\t\tif (rewriteResult.changed) {\n\t\t\t\t\t\t\tupdates[field.slug] = JSON.stringify(blocks);\n\t\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\t\trowUrlsRewritten += rewriteResult.urlsRewritten;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Not valid JSON, try string replacement as fallback\n\t\t\t\t\t\tconst stringResult = rewriteStringUrls(value, urlMap, baseMap);\n\t\t\t\t\t\tif (stringResult.changed) {\n\t\t\t\t\t\t\tupdates[field.slug] = stringResult.newValue;\n\t\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\t\trowUrlsRewritten += stringResult.urlsRewritten;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle string/text fields - simple string replacement\n\t\t\t\tfor (const field of stringFields) {\n\t\t\t\t\tconst value = row[field.slug];\n\t\t\t\t\tif (!value || typeof value !== \"string\") continue;\n\n\t\t\t\t\tconst stringResult = rewriteStringUrls(value, urlMap, baseMap);\n\t\t\t\t\tif (stringResult.changed) {\n\t\t\t\t\t\tupdates[field.slug] = stringResult.newValue;\n\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\trowUrlsRewritten += stringResult.urlsRewritten;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle image/file fields - normalize to MediaValue objects\n\t\t\t\tfor (const field of mediaFields) {\n\t\t\t\t\tconst value = row[field.slug];\n\t\t\t\t\tif (!value || typeof value !== \"string\") continue;\n\n\t\t\t\t\t// Try to find a matching rewritten URL\n\t\t\t\t\tconst newUrl = findMatchingUrl(value, urlMap, baseMap);\n\t\t\t\t\tif (newUrl) {\n\t\t\t\t\t\t// Normalize into a proper MediaValue instead of storing a bare URL\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst normalized = await normalizeMediaValue(newUrl, getProvider);\n\t\t\t\t\t\t\tupdates[field.slug] = normalized ? JSON.stringify(normalized) : newUrl;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tupdates[field.slug] = newUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\trowUpdated = true;\n\t\t\t\t\t\trowUrlsRewritten++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (rowUpdated) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Build update query dynamically\n\t\t\t\t\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- Kysely dynamic table requires type assertion\n\t\t\t\t\t\tlet query = db.updateTable(tableName as any).where(\"id\", \"=\", row.id);\n\n\t\t\t\t\t\tfor (const [key, value] of Object.entries(updates)) {\n\t\t\t\t\t\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- Kysely dynamic column update requires type assertion\n\t\t\t\t\t\t\tquery = query.set({ [key]: value } as any);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait query.execute();\n\n\t\t\t\t\t\tresult.updated++;\n\t\t\t\t\t\tresult.urlsRewritten += rowUrlsRewritten;\n\t\t\t\t\t\tresult.byCollection[collection.slug] = (result.byCollection[collection.slug] || 0) + 1;\n\t\t\t\t\t} catch (updateError) {\n\t\t\t\t\t\tresult.errors.push({\n\t\t\t\t\t\t\tcollection: collection.slug,\n\t\t\t\t\t\t\tid: row.id,\n\t\t\t\t\t\t\terror: updateError instanceof Error ? updateError.message : \"Update failed\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (queryError) {\n\t\t\tresult.errors.push({\n\t\t\t\tcollection: collection.slug,\n\t\t\t\tid: \"*\",\n\t\t\t\terror: queryError instanceof Error ? queryError.message : \"Query failed for collection\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;;;;AA2CA,MAAa,YAAY;AAEzB,MAAa,OAAiB,OAAO,EAAE,SAAS,aAAa;CAC5D,MAAM,EAAE,QAAQ,SAAS;AAEzB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,SAAS,4BAA4B,IAAI;CAG1D,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EACH,MAAM,OAAO,MAAM,UAAU,SAAS,kBAAkB;AACxD,MAAI,aAAa,KAAK,CAAE,QAAO;AAG/B,MADmB,OAAO,QAAQ,KAAK,OAAO,CAC/B,WAAW,EACzB,QAAO,WAAW;GACjB,SAAS;GACT,cAAc,EAAE;GAChB,eAAe;GACf,QAAQ,EAAE;GACV,CAAC;EAGH,MAAM,eAAe,OAAe,OAAO,iBAAi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M,MAAM,SAAS;AAErB,YAAO;AACP,YAAO,iBAAiB;AACxB,YAAO,aAAa,WAAW,SAAS,OAAO,aAAa,WAAW,SAAS,KAAK;aAC7E,aAAa;AACrB,YAAO,OAAO,KAAK;MAClB,YAAY,WAAW;MACvB,IAAI,IAAI;MACR,OAAO,uBAAuB,QAAQ,YAAY,UAAU;MAC5D,CAAC;;;WAIG,YAAY;AACpB,UAAO,OAAO,KAAK;IAClB,YAAY,WAAW;IACvB,IAAI;IACJ,OAAO,sBAAsB,QAAQ,WAAW,UAAU;IAC1D,CAAC;;;AAIJ,QAAO"}
@@ -1,4 +1,4 @@
1
- import { o as ImportAnalysis } from "../../../../../types-Cb2UCDJg.mjs";
1
+ import { o as ImportAnalysis } from "../../../../../types-bYmRn_Uy.mjs";
2
2
  import { APIRoute } from "astro";
3
3
 
4
4
  //#region src/astro/routes/api/import/wordpress-plugin/analyze.d.ts
@@ -1,15 +1,15 @@
1
1
  import "../../../../../base64-CqR-7kqF.mjs";
2
- import "../../../../../types-CwXMEPRr.mjs";
3
- import { n as resolveAndValidateExternalUrl, t as SsrfError } from "../../../../../ssrf-DzFN_qV-.mjs";
4
- import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-tSQWIl5U.mjs";
5
- import { n as parseBody, t as isParseError } from "../../../../../parse-BFTPon-J.mjs";
6
- import "../../../../../redirects-Dmj6KRU3.mjs";
7
- import { c as wpPluginAnalyzeBody } from "../../../../../setup-BGAJ2uXs.mjs";
2
+ import "../../../../../types-ByV5sgsv.mjs";
3
+ import { n as resolveAndValidateExternalUrl, t as SsrfError } from "../../../../../ssrf-MZ-zrG6-.mjs";
4
+ import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-CPh_8eLq.mjs";
5
+ import { n as parseBody, t as isParseError } from "../../../../../parse-3-caTKgt.mjs";
6
+ import "../../../../../redirects-COMLwsV5.mjs";
7
+ import { c as wpPluginAnalyzeBody } from "../../../../../setup-Cf_TyOv5.mjs";
8
8
  import "../../../../../api/schemas/index.mjs";
9
- import { s as getSource } from "../../../../../import-CNfLOgDE.mjs";
10
- import "../../../../../ssrf-CTul4uQi.mjs";
11
- import "../../../../../utils-_F-rWBTN.mjs";
12
- import { n as requirePerm } from "../../../../../authorize-BlyCH-96.mjs";
9
+ import { s as getSource } from "../../../../../import-DG80rC_I.mjs";
10
+ import "../../../../../ssrf-BIcd-aXW.mjs";
11
+ import "../../../../../utils-C3wTAP-P.mjs";
12
+ import { n as requirePerm } from "../../../../../authorize-Bkwe8kuL.mjs";
13
13
  import { SchemaRegistry } from "emdash";
14
14
 
15
15
  //#region src/astro/routes/api/import/wordpress-plugin/analyze.ts
@@ -1,4 +1,4 @@
1
- import { s as ImportConfig, u as ImportResult } from "../../../../../types-Cb2UCDJg.mjs";
1
+ import { s as ImportConfig, u as ImportResult } from "../../../../../types-bYmRn_Uy.mjs";
2
2
  import { APIRoute } from "astro";
3
3
 
4
4
  //#region src/astro/routes/api/import/wordpress-plugin/execute.d.ts
@@ -1,18 +1,18 @@
1
1
  import "../../../../../dialect-helpers-BKCvISIQ.mjs";
2
2
  import { n as slugify } from "../../../../../slugify-Cjh1ssOZ.mjs";
3
3
  import "../../../../../base64-CqR-7kqF.mjs";
4
- import "../../../../../types-CwXMEPRr.mjs";
5
- import { t as BylineRepository } from "../../../../../byline-D09BaS4j.mjs";
6
- import { n as resolveAndValidateExternalUrl, t as SsrfError } from "../../../../../ssrf-DzFN_qV-.mjs";
7
- import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-tSQWIl5U.mjs";
8
- import { n as parseBody, t as isParseError } from "../../../../../parse-BFTPon-J.mjs";
9
- import "../../../../../redirects-Dmj6KRU3.mjs";
10
- import { l as wpPluginExecuteBody } from "../../../../../setup-BGAJ2uXs.mjs";
4
+ import "../../../../../types-ByV5sgsv.mjs";
5
+ import { t as BylineRepository } from "../../../../../byline-CTaWkMh5.mjs";
6
+ import { n as resolveAndValidateExternalUrl, t as SsrfError } from "../../../../../ssrf-MZ-zrG6-.mjs";
7
+ import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../error-CPh_8eLq.mjs";
8
+ import { n as parseBody, t as isParseError } from "../../../../../parse-3-caTKgt.mjs";
9
+ import "../../../../../redirects-COMLwsV5.mjs";
10
+ import { l as wpPluginExecuteBody } from "../../../../../setup-Cf_TyOv5.mjs";
11
11
  import "../../../../../api/schemas/index.mjs";
12
- import { s as getSource } from "../../../../../import-CNfLOgDE.mjs";
13
- import "../../../../../ssrf-CTul4uQi.mjs";
14
- import { m as resolveImportByline } from "../../../../../utils-_F-rWBTN.mjs";
15
- import { n as requirePerm } from "../../../../../authorize-BlyCH-96.mjs";
12
+ import { s as getSource } from "../../../../../import-DG80rC_I.mjs";
13
+ import "../../../../../ssrf-BIcd-aXW.mjs";
14
+ import { m as resolveImportByline } from "../../../../../utils-C3wTAP-P.mjs";
15
+ import { n as requirePerm } from "../../../../../authorize-Bkwe8kuL.mjs";
16
16
  import { ContentRepository, SchemaRegistry } from "emdash";
17
17
 
18
18
  //#region src/astro/routes/api/import/wordpress-plugin/execute.ts