@builtbyfriends/bwf 0.0.0-stage → 1.9.1

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 (448) hide show
  1. package/AGENTS_TEMPLATE.md +4 -0
  2. package/LICENSE +22 -0
  3. package/README.md +48 -2
  4. package/dist/account-cmd-Cj0I2_bJ.mjs +45 -0
  5. package/dist/agents-BLiMq9E1.mjs +113 -0
  6. package/dist/application-analysis-C9Ck2Yeg.mjs +1498 -0
  7. package/dist/application-routing-DbR-W5lG.mjs +25 -0
  8. package/dist/atomic-write-DA6eD1Kp.mjs +17 -0
  9. package/dist/auth-BKsUmWbT.d.mts +77 -0
  10. package/dist/auth-DkvoW5hB.mjs +33 -0
  11. package/dist/auth-aKyIWkdS.mjs +1 -0
  12. package/dist/auth-client-6-Ft9i9T.d.mts +5 -0
  13. package/dist/auth-client-DwCdwKbw.mjs +5 -0
  14. package/dist/auth-client-react-CJdeErvM.mjs +5 -0
  15. package/dist/auth-client-react-DvQLe5Zb.d.mts +5 -0
  16. package/dist/auth-link-D-DddkCQ.mjs +26 -0
  17. package/dist/auth-migrations-DDeifS3v.mjs +206 -0
  18. package/dist/auth-router-tWzIwf8f.mjs +66 -0
  19. package/dist/auth-xnkmpZUl.mjs +311 -0
  20. package/dist/base64-ikl9yBy3.mjs +15 -0
  21. package/dist/better-auth-shared-Br6TNaYJ.mjs +473 -0
  22. package/dist/better-auth-shared-CsBNvPOU.d.mts +56 -0
  23. package/dist/build-cmd-BnZezraT.mjs +153 -0
  24. package/dist/build-output-dir-Clj_unKN.mjs +402 -0
  25. package/dist/cancel-deploy-DKAj5U1Z.mjs +57 -0
  26. package/dist/cf-access-Bhz9wX6p.mjs +131 -0
  27. package/dist/cf-access-CUP5L08W.mjs +67 -0
  28. package/dist/cf-build-output-DA6uJomQ.mjs +1 -0
  29. package/dist/cf-build-output-DNQTwMNU.mjs +438 -0
  30. package/dist/cf-command-values-2kOtxMo1.mjs +26 -0
  31. package/dist/cf-config-migrate-COOCi4Ge.mjs +330 -0
  32. package/dist/cf-worker-settings-CIh4t_yG.mjs +41 -0
  33. package/dist/cli/cli.d.mts +1 -0
  34. package/dist/cli/cli.mjs +88 -0
  35. package/dist/cli/cloudflare-operation-process.d.mts +1 -0
  36. package/dist/cli/cloudflare-operation-process.mjs +1284 -0
  37. package/dist/cli/env-schema-probe.d.mts +43 -0
  38. package/dist/cli/env-schema-probe.mjs +165 -0
  39. package/dist/cli-main-HeXRQml6.mjs +1846 -0
  40. package/dist/client-D3D5RM5h.mjs +940 -0
  41. package/dist/client-VF2Nzc7Z.mjs +1 -0
  42. package/dist/cloudflare-auth-jb-1e43r.mjs +152 -0
  43. package/dist/cloudflare-cmd-B62t8Fm-.mjs +59 -0
  44. package/dist/cloudflare-config-i8yanry0.mjs +186 -0
  45. package/dist/cloudflare-connect-x7IsYghw.mjs +55 -0
  46. package/dist/cloudflare-operations-BeK7bhnP.mjs +627 -0
  47. package/dist/cloudflare-operations-C3Uu0Emj.mjs +1 -0
  48. package/dist/cloudflare-process-Cc6oiJqk.mjs +309 -0
  49. package/dist/cloudflare-user-output-CqONaAbP.mjs +19 -0
  50. package/dist/collect-8i0wU63d.mjs +1 -0
  51. package/dist/collect-C6Blu9yw.mjs +48 -0
  52. package/dist/config-CN_RFRkS.mjs +86 -0
  53. package/dist/config-D5G-Tx6o.mjs +1 -0
  54. package/dist/config-DOaFIK3w.mjs +88 -0
  55. package/dist/config-entry.d.mts +202 -0
  56. package/dist/config-entry.mjs +6 -0
  57. package/dist/config-tNx0HlFv.mjs +516 -0
  58. package/dist/connect-hLPNppu3.mjs +84 -0
  59. package/dist/create-project-B35ux-LA.mjs +126 -0
  60. package/dist/create-project-tJ1KwNss.mjs +1 -0
  61. package/dist/database-provider-DkZo4VwN.mjs +5 -0
  62. package/dist/database-provider.d.mts +25 -0
  63. package/dist/database-provider.mjs +1 -0
  64. package/dist/db-BH_md90k.mjs +1735 -0
  65. package/dist/delete-BSKI7V23.mjs +65 -0
  66. package/dist/deploy-C8KHBNsh.mjs +6512 -0
  67. package/dist/deploy-DCZBr7Ey.mjs +2 -0
  68. package/dist/deploy.d.mts +31 -0
  69. package/dist/deploy.mjs +118 -0
  70. package/dist/dev-inbox-I0nqTCdf.mjs +216 -0
  71. package/dist/discover-DJPmQcL5.mjs +36 -0
  72. package/dist/discover-EVuydEoM.mjs +1 -0
  73. package/dist/dist-B6eN80gc.mjs +1612 -0
  74. package/dist/dist-Cp4b1_T9.mjs +1 -0
  75. package/dist/dist-DMYe8CZJ.mjs +48 -0
  76. package/dist/dist-STQXl8ck.mjs +1878 -0
  77. package/dist/domain-C4ZhEiFG.mjs +149 -0
  78. package/dist/dotenv-4NdUCXbB.mjs +156 -0
  79. package/dist/drizzle-DqVFXtlc.mjs +306 -0
  80. package/dist/drizzle-Ds5P0n-S.mjs +1 -0
  81. package/dist/edge.d.mts +2 -0
  82. package/dist/edge.mjs +1 -0
  83. package/dist/email-B3TWga7x.mjs +742 -0
  84. package/dist/email-C_ATvNIG.mjs +2865 -0
  85. package/dist/email-cloudflare-DuAc9zny.mjs +854 -0
  86. package/dist/email-protocol-CZ0bAkI8.mjs +81 -0
  87. package/dist/env-CTAo8ifZ.mjs +73 -0
  88. package/dist/env-DUyTzroe.mjs +88 -0
  89. package/dist/env-Dl4Wggec.mjs +71 -0
  90. package/dist/env-helpers-BX0APszT.mjs +135 -0
  91. package/dist/env-helpers-U56xuFgL.d.mts +20 -0
  92. package/dist/env-mask-BsHxq3R8.mjs +46 -0
  93. package/dist/env-public-Cw_xPi1D.d.mts +119 -0
  94. package/dist/env-raw-Bo6TtrHU.mjs +41 -0
  95. package/dist/env-types-Bg-dTh8u.mjs +56 -0
  96. package/dist/env-validation-BufZConV.mjs +488 -0
  97. package/dist/env-validation-DPqDo4DU.mjs +1 -0
  98. package/dist/fetch-CBgyyhzm.d.mts +87 -0
  99. package/dist/fetch-error-DmlRM6e4.mjs +264 -0
  100. package/dist/fetch-stream-2GUN3YN1.mjs +102 -0
  101. package/dist/fetch-stream-bUXynOyZ.d.mts +32 -0
  102. package/dist/fetch-tpPiSK10.mjs +25 -0
  103. package/dist/gen-dc13IRXh.mjs +509 -0
  104. package/dist/gen-kQqhFyOP.mjs +1 -0
  105. package/dist/generate-BgtlYpKg.mjs +1 -0
  106. package/dist/generate-Da9mWKzU.mjs +80 -0
  107. package/dist/generated-wrangler-config-CoDaaFsA.mjs +17 -0
  108. package/dist/git-metadata-Cukp5kV5.mjs +82 -0
  109. package/dist/github-cmd-DT5Onu6E.mjs +690 -0
  110. package/dist/handler-CJ7DiiRF.mjs +161 -0
  111. package/dist/handler-CVsIfRv7.d.mts +279 -0
  112. package/dist/help-Bpv6Qeqn.mjs +1946 -0
  113. package/dist/help-CfZ4Bsw5.mjs +1 -0
  114. package/dist/inbound-CqubE-9T.d.mts +311 -0
  115. package/dist/inbound-lHugZPuK.mjs +509 -0
  116. package/dist/index.d.mts +64 -0
  117. package/dist/index.mjs +4163 -0
  118. package/dist/info-CLQoCenb.mjs +109 -0
  119. package/dist/init-DRUR0j8C.mjs +2486 -0
  120. package/dist/limits-CMmYT2l8.d.mts +16 -0
  121. package/dist/limits-D27Lp6FP.mjs +46 -0
  122. package/dist/link-DinwJnon.mjs +52 -0
  123. package/dist/list-B84t4BhW.mjs +130 -0
  124. package/dist/live-Dui0-aj_.d.mts +105 -0
  125. package/dist/live-saC8barp.mjs +410 -0
  126. package/dist/load-user-env-g0ahkZcj.mjs +34 -0
  127. package/dist/local-d1-C3EeOV7-.mjs +103 -0
  128. package/dist/log-JDnPc0cF.mjs +23 -0
  129. package/dist/login-Bl5lH8nH.mjs +87 -0
  130. package/dist/login-DoI7AsbY.mjs +1 -0
  131. package/dist/logs-CaT2N2f7.mjs +129 -0
  132. package/dist/migrate-CbGscX-V.mjs +125 -0
  133. package/dist/migrate-Ce3JKLVs.mjs +1 -0
  134. package/dist/migration-handler-22qiuWPq.mjs +469 -0
  135. package/dist/migration-handler-Bb2BJh6g.d.mts +38 -0
  136. package/dist/mime-BMUN_QKG.mjs +1004 -0
  137. package/dist/mysql-migration-sql-CNuBSqdx.mjs +239 -0
  138. package/dist/neon-CJzQSycr.mjs +52 -0
  139. package/dist/node-tfv-3v0V.mjs +64 -0
  140. package/dist/operator-ai-logging-Ay7M4KWw.mjs +121 -0
  141. package/dist/operator-args-BFg32YyY.mjs +722 -0
  142. package/dist/operator-auth-DdYZYEkO.mjs +47 -0
  143. package/dist/operator-client-DBujdELO.mjs +82 -0
  144. package/dist/operator-cmd-C73WWJBl.mjs +443 -0
  145. package/dist/operator-cmd-CdZytuAF.mjs +1 -0
  146. package/dist/output-Bb34lF0w.mjs +173 -0
  147. package/dist/output-CVolXKC1.mjs +1 -0
  148. package/dist/package-DO4d3Qz5.mjs +1444 -0
  149. package/dist/package-json-DvS6IFRv.mjs +43 -0
  150. package/dist/pg-DoyPxa_X.mjs +15 -0
  151. package/dist/picocolors-D1NxSLw-.mjs +71 -0
  152. package/dist/plan-BHNt1QhK.mjs +1 -0
  153. package/dist/plan-DX4_-OM5.mjs +58 -0
  154. package/dist/platform-args-NI_vfWvD.mjs +538 -0
  155. package/dist/platform-args-ZC1-A1N9.mjs +1 -0
  156. package/dist/platform-auth-config-d-lY5-aY.mjs +371 -0
  157. package/dist/platform-auth-protection-Dhw7lUCk.mjs +231 -0
  158. package/dist/platform-auth-recovery-DaCc0tlx.mjs +309 -0
  159. package/dist/platform-cmd-5Ry-C9im.mjs +193 -0
  160. package/dist/platform-cmd-5oZq91lI.mjs +1 -0
  161. package/dist/platform-discovery-Bxg9aZXU.mjs +40 -0
  162. package/dist/platform-domain-DLVdGvGG.mjs +256 -0
  163. package/dist/platform-lifecycle-CUgjipXO.mjs +1 -0
  164. package/dist/platform-lifecycle-fRt5VMls.mjs +8928 -0
  165. package/dist/platform-management-5hEsRfR2.mjs +1 -0
  166. package/dist/platform-management-Djh1hzLP.mjs +1607 -0
  167. package/dist/platform-plans-config-CkbUKFpm.mjs +447 -0
  168. package/dist/platform-recovery-Cghx7FCR.mjs +96 -0
  169. package/dist/platform-registry-x1m9HBxf.mjs +450 -0
  170. package/dist/platform-runtime-logs-kkoiYFpF.mjs +72 -0
  171. package/dist/platform-setup-SfwCwnZg.mjs +306 -0
  172. package/dist/prepare-B9mB47T5.mjs +84 -0
  173. package/dist/prepare-DNIq07so.mjs +13 -0
  174. package/dist/prepare-LHkyJqxi.mjs +1 -0
  175. package/dist/project-CC7eN00D.mjs +141 -0
  176. package/dist/project-DcSd4BeI.mjs +1 -0
  177. package/dist/project-cmd-DTF19-fC.mjs +109 -0
  178. package/dist/project-paths-iXHKRTTQ.mjs +159 -0
  179. package/dist/project-slug-BUy0lmyR.mjs +1 -0
  180. package/dist/project-slug-CO6ci9XG.mjs +7 -0
  181. package/dist/project-team-CvdLhDF2.mjs +129 -0
  182. package/dist/project-token-CwZdUEGu.mjs +70 -0
  183. package/dist/project-tsconfig-P9X952KG.mjs +98 -0
  184. package/dist/project-zero-trust-CKDoPdN1.mjs +64 -0
  185. package/dist/providers-Cd3c7wi0.mjs +64 -0
  186. package/dist/providers-Df69hb_X.d.mts +5 -0
  187. package/dist/provision-DGlFJ3T9.mjs +1 -0
  188. package/dist/provision-mYVLuQiy.mjs +1814 -0
  189. package/dist/queues-Bc3FsBQT.d.mts +5 -0
  190. package/dist/r2-conditions-DSLmkiR5.mjs +60 -0
  191. package/dist/requests-DNhfyF3l.mjs +52 -0
  192. package/dist/resolve-project-BCsAMDRA.mjs +47 -0
  193. package/dist/resolve-project-DhU9_lIo.mjs +1 -0
  194. package/dist/resource-name-DlJ9QXzg.mjs +10 -0
  195. package/dist/response-HmNjB30w.mjs +29 -0
  196. package/dist/rollback-BvCHol52.mjs +150 -0
  197. package/dist/rolldown-runtime-uD8oG6U2.mjs +24 -0
  198. package/dist/route-types-CRWhr93D.mjs +592 -0
  199. package/dist/route-url-BIDZT78M.mjs +58 -0
  200. package/dist/route-url-Bla3Upsy.d.mts +42 -0
  201. package/dist/routes-stub.d.mts +24 -0
  202. package/dist/routes-stub.mjs +1 -0
  203. package/dist/routing-assets-CSheDWWM.mjs +54 -0
  204. package/dist/rpc-DcByS_q0.d.mts +39 -0
  205. package/dist/rpc-DtxIN9Tv.mjs +19 -0
  206. package/dist/runner-CPerdjIl.mjs +163 -0
  207. package/dist/runner-CUNtS5x7.mjs +1 -0
  208. package/dist/runner-mysql-7aA5hGoM.mjs +145 -0
  209. package/dist/runner-mysql-DrMKw203.mjs +1 -0
  210. package/dist/runner-pg-2pjltt0t.mjs +1 -0
  211. package/dist/runner-pg-mYc75KfH.mjs +61 -0
  212. package/dist/runtime/ai.d.mts +50 -0
  213. package/dist/runtime/ai.mjs +455 -0
  214. package/dist/runtime/auth-client-react.d.mts +2 -0
  215. package/dist/runtime/auth-client-react.mjs +1 -0
  216. package/dist/runtime/auth-client.d.mts +2 -0
  217. package/dist/runtime/auth-client.mjs +1 -0
  218. package/dist/runtime/auth.d.mts +2 -0
  219. package/dist/runtime/auth.mjs +1 -0
  220. package/dist/runtime/better-auth-mysql.d.mts +5 -0
  221. package/dist/runtime/better-auth-mysql.mjs +21 -0
  222. package/dist/runtime/better-auth-pg.d.mts +5 -0
  223. package/dist/runtime/better-auth-pg.mjs +21 -0
  224. package/dist/runtime/better-auth.d.mts +6 -0
  225. package/dist/runtime/better-auth.mjs +22 -0
  226. package/dist/runtime/client-react.d.mts +5 -0
  227. package/dist/runtime/client-react.mjs +5 -0
  228. package/dist/runtime/client.d.mts +5 -0
  229. package/dist/runtime/client.mjs +5 -0
  230. package/dist/runtime/db-mysql.d.mts +2 -0
  231. package/dist/runtime/db-mysql.mjs +1 -0
  232. package/dist/runtime/db-pg.d.mts +2 -0
  233. package/dist/runtime/db-pg.mjs +1 -0
  234. package/dist/runtime/db.d.mts +17 -0
  235. package/dist/runtime/db.mjs +36 -0
  236. package/dist/runtime/drizzle-arktype.d.mts +1 -0
  237. package/dist/runtime/drizzle-arktype.mjs +2 -0
  238. package/dist/runtime/drizzle-valibot.d.mts +1 -0
  239. package/dist/runtime/drizzle-valibot.mjs +2 -0
  240. package/dist/runtime/drizzle-zod.d.mts +1 -0
  241. package/dist/runtime/drizzle-zod.mjs +2 -0
  242. package/dist/runtime/durable.d.mts +64 -0
  243. package/dist/runtime/durable.mjs +165 -0
  244. package/dist/runtime/email/testing.d.mts +108 -0
  245. package/dist/runtime/email/testing.mjs +268 -0
  246. package/dist/runtime/email-protocol.d.mts +25 -0
  247. package/dist/runtime/email-protocol.mjs +1 -0
  248. package/dist/runtime/email.d.mts +26 -0
  249. package/dist/runtime/email.mjs +524 -0
  250. package/dist/runtime/env-public-client.d.mts +19 -0
  251. package/dist/runtime/env-public-client.mjs +55 -0
  252. package/dist/runtime/env-public.d.mts +4 -0
  253. package/dist/runtime/env-public.mjs +277 -0
  254. package/dist/runtime/env.d.mts +12 -0
  255. package/dist/runtime/env.mjs +1 -0
  256. package/dist/runtime/fetch-server.d.mts +6 -0
  257. package/dist/runtime/fetch-server.mjs +29 -0
  258. package/dist/runtime/fetch-stream.d.mts +3 -0
  259. package/dist/runtime/fetch-stream.mjs +3 -0
  260. package/dist/runtime/fetch.d.mts +2 -0
  261. package/dist/runtime/fetch.mjs +3 -0
  262. package/dist/runtime/handler.d.mts +3 -0
  263. package/dist/runtime/handler.mjs +1 -0
  264. package/dist/runtime/kv.d.mts +45 -0
  265. package/dist/runtime/kv.mjs +103 -0
  266. package/dist/runtime/limits.d.mts +2 -0
  267. package/dist/runtime/limits.mjs +1 -0
  268. package/dist/runtime/live-client.d.mts +40 -0
  269. package/dist/runtime/live-client.mjs +282 -0
  270. package/dist/runtime/live-server.d.mts +11 -0
  271. package/dist/runtime/live-server.mjs +419 -0
  272. package/dist/runtime/live.d.mts +3 -0
  273. package/dist/runtime/live.mjs +1 -0
  274. package/dist/runtime/log.d.mts +24 -0
  275. package/dist/runtime/log.mjs +57 -0
  276. package/dist/runtime/migration-handler-mysql.d.mts +2 -0
  277. package/dist/runtime/migration-handler-mysql.mjs +111 -0
  278. package/dist/runtime/migration-handler-pg.d.mts +2 -0
  279. package/dist/runtime/migration-handler-pg.mjs +94 -0
  280. package/dist/runtime/migration-handler.d.mts +2 -0
  281. package/dist/runtime/migration-handler.mjs +1 -0
  282. package/dist/runtime/procedure.d.mts +27 -0
  283. package/dist/runtime/procedure.mjs +36 -0
  284. package/dist/runtime/procedures.d.mts +24 -0
  285. package/dist/runtime/procedures.mjs +56 -0
  286. package/dist/runtime/queues.d.mts +2 -0
  287. package/dist/runtime/queues.mjs +8 -0
  288. package/dist/runtime/remote/binding-handler.d.mts +11 -0
  289. package/dist/runtime/remote/binding-handler.mjs +227 -0
  290. package/dist/runtime/remote/index.d.mts +12 -0
  291. package/dist/runtime/remote/index.mjs +467 -0
  292. package/dist/runtime/response.d.mts +11 -0
  293. package/dist/runtime/response.mjs +1 -0
  294. package/dist/runtime/route-url.d.mts +2 -0
  295. package/dist/runtime/route-url.mjs +1 -0
  296. package/dist/runtime/routing.d.mts +53 -0
  297. package/dist/runtime/routing.mjs +425 -0
  298. package/dist/runtime/rpc-react.d.mts +16 -0
  299. package/dist/runtime/rpc-react.mjs +50 -0
  300. package/dist/runtime/rpc.d.mts +2 -0
  301. package/dist/runtime/rpc.mjs +1 -0
  302. package/dist/runtime/sandbox-container.d.mts +3 -0
  303. package/dist/runtime/sandbox-container.mjs +1 -0
  304. package/dist/runtime/sandbox.d.mts +5 -0
  305. package/dist/runtime/sandbox.mjs +196 -0
  306. package/dist/runtime/schema-d1.d.mts +1 -0
  307. package/dist/runtime/schema-d1.mjs +2 -0
  308. package/dist/runtime/schema-mysql.d.mts +1 -0
  309. package/dist/runtime/schema-mysql.mjs +2 -0
  310. package/dist/runtime/schema-pg.d.mts +1 -0
  311. package/dist/runtime/schema-pg.mjs +2 -0
  312. package/dist/runtime/seed.d.mts +34 -0
  313. package/dist/runtime/seed.mjs +5 -0
  314. package/dist/runtime/sse-client.d.mts +31 -0
  315. package/dist/runtime/sse-client.mjs +42 -0
  316. package/dist/runtime/sse.d.mts +32 -0
  317. package/dist/runtime/sse.mjs +1 -0
  318. package/dist/runtime/storage.d.mts +4 -0
  319. package/dist/runtime/storage.mjs +13 -0
  320. package/dist/runtime/validator.d.mts +2 -0
  321. package/dist/runtime/validator.mjs +1 -0
  322. package/dist/runtime/ws-server.d.mts +26 -0
  323. package/dist/runtime/ws-server.mjs +297 -0
  324. package/dist/runtime/ws.d.mts +2 -0
  325. package/dist/runtime/ws.mjs +108 -0
  326. package/dist/sandbox-CWDjoEG2.d.mts +50 -0
  327. package/dist/sandbox-container-BqamdFCx.d.mts +73 -0
  328. package/dist/sandbox-container-d1AHLpgn.mjs +291 -0
  329. package/dist/secret-DCF9RXTc.mjs +146 -0
  330. package/dist/skills-Dr3AjuBF.mjs +63 -0
  331. package/dist/sqlite-validation-CLJXXN93.mjs +24 -0
  332. package/dist/sse-CxR30yMF.mjs +174 -0
  333. package/dist/standard-schema-CuDawHOC.d.mts +40 -0
  334. package/dist/static-asset-marker-mWMX2dLa.mjs +38 -0
  335. package/dist/subcommand-prompt-B9yUo--u.mjs +370 -0
  336. package/dist/terminal-log-text-DNsWJREL.mjs +31 -0
  337. package/dist/types-D7-4tBu7.d.mts +1 -0
  338. package/dist/untrusted-env-lL7RkYiC.mjs +50 -0
  339. package/dist/validate-B-zsjhiz.mjs +162 -0
  340. package/dist/validate-DbqGdPPY.mjs +1 -0
  341. package/dist/validator-8-NZs2Xr.mjs +168 -0
  342. package/dist/version-metadata-DsSoNsKJ.mjs +23 -0
  343. package/dist/wrangler-DU784Dkf.mjs +1452 -0
  344. package/dist/wrangler-Rr9_76DQ.mjs +1 -0
  345. package/dist/ws-Q_osq9VK.d.mts +137 -0
  346. package/dist/yarn-pnp-DgWbE7z5.mjs +91 -0
  347. package/docs/guide/ai.md +273 -0
  348. package/docs/guide/app-types.md +101 -0
  349. package/docs/guide/auth.md +255 -0
  350. package/docs/guide/database/d1.md +86 -0
  351. package/docs/guide/database/mysql.md +72 -0
  352. package/docs/guide/database/postgresql.md +94 -0
  353. package/docs/guide/database.md +454 -0
  354. package/docs/guide/deployment.md +124 -0
  355. package/docs/guide/durable-state.md +192 -0
  356. package/docs/guide/edge/headers.md +47 -0
  357. package/docs/guide/edge/redirects.md +85 -0
  358. package/docs/guide/edge/rewrites.md +119 -0
  359. package/docs/guide/edge/static-assets.md +94 -0
  360. package/docs/guide/email/domains.md +119 -0
  361. package/docs/guide/email/receiving.md +142 -0
  362. package/docs/guide/email/sending.md +262 -0
  363. package/docs/guide/email.md +23 -0
  364. package/docs/guide/env-vars.md +115 -0
  365. package/docs/guide/index.md +37 -0
  366. package/docs/guide/jobs.md +80 -0
  367. package/docs/guide/kv.md +100 -0
  368. package/docs/guide/live.md +181 -0
  369. package/docs/guide/platform/administration/access.md +165 -0
  370. package/docs/guide/platform/administration/connected-apps.md +84 -0
  371. package/docs/guide/platform/administration/email.md +169 -0
  372. package/docs/guide/platform/administration/operations.md +100 -0
  373. package/docs/guide/platform/administration/plans.md +156 -0
  374. package/docs/guide/platform/administration/projects.md +74 -0
  375. package/docs/guide/platform/administration/zero-trust.md +205 -0
  376. package/docs/guide/platform/development/local.md +122 -0
  377. package/docs/guide/platform/development/runtime.md +115 -0
  378. package/docs/guide/platform/development/schema-ci.md +44 -0
  379. package/docs/guide/platform/installation/ci.md +62 -0
  380. package/docs/guide/platform/installation/credentials.md +140 -0
  381. package/docs/guide/platform/installation/domains.md +120 -0
  382. package/docs/guide/platform/installation/first-deployment.md +95 -0
  383. package/docs/guide/platform/installation/maintenance.md +250 -0
  384. package/docs/guide/platform/installation/prerequisites.md +176 -0
  385. package/docs/guide/platform/installation/setup.md +300 -0
  386. package/docs/guide/platform/installation/uninstall.md +110 -0
  387. package/docs/guide/platform-administration.md +19 -0
  388. package/docs/guide/platform-development.md +16 -0
  389. package/docs/guide/procedures.md +48 -0
  390. package/docs/guide/project-collaboration.md +99 -0
  391. package/docs/guide/queues.md +149 -0
  392. package/docs/guide/quickstart.md +129 -0
  393. package/docs/guide/remote-dev.md +67 -0
  394. package/docs/guide/sandboxes.md +134 -0
  395. package/docs/guide/self-hosted-platform.md +45 -0
  396. package/docs/guide/server-routing.md +283 -0
  397. package/docs/guide/sse.md +174 -0
  398. package/docs/guide/storage.md +82 -0
  399. package/docs/guide/testing.md +64 -0
  400. package/docs/guide/type-safety.md +270 -0
  401. package/docs/guide/typed-fetch.md +98 -0
  402. package/docs/guide/websockets.md +230 -0
  403. package/docs/index.md +102 -0
  404. package/docs/integrations/agents.md +38 -0
  405. package/docs/integrations/cloudflare.md +241 -0
  406. package/docs/integrations/hono.md +127 -0
  407. package/docs/reference/api/auth.md +195 -0
  408. package/docs/reference/api/client.md +90 -0
  409. package/docs/reference/api/database.md +118 -0
  410. package/docs/reference/api/deploy.md +63 -0
  411. package/docs/reference/api/durable.md +47 -0
  412. package/docs/reference/api/env.md +51 -0
  413. package/docs/reference/api/handlers.md +189 -0
  414. package/docs/reference/api/plugin.md +40 -0
  415. package/docs/reference/api/resources.md +116 -0
  416. package/docs/reference/api/rewrites.md +111 -0
  417. package/docs/reference/api/types.md +126 -0
  418. package/docs/reference/api.md +71 -0
  419. package/docs/reference/cli/auth.md +87 -0
  420. package/docs/reference/cli/database.md +159 -0
  421. package/docs/reference/cli/deploy.md +117 -0
  422. package/docs/reference/cli/domains.md +42 -0
  423. package/docs/reference/cli/email.md +145 -0
  424. package/docs/reference/cli/generate.md +113 -0
  425. package/docs/reference/cli/github.md +181 -0
  426. package/docs/reference/cli/platform-config.md +93 -0
  427. package/docs/reference/cli/platform-email.md +81 -0
  428. package/docs/reference/cli/platform-installation.md +166 -0
  429. package/docs/reference/cli/platform-operations.md +90 -0
  430. package/docs/reference/cli/platform-users.md +159 -0
  431. package/docs/reference/cli/platform-zero-trust.md +60 -0
  432. package/docs/reference/cli/platform.md +78 -0
  433. package/docs/reference/cli/project.md +208 -0
  434. package/docs/reference/cli/secrets.md +79 -0
  435. package/docs/reference/cli/setup.md +88 -0
  436. package/docs/reference/cli.md +115 -0
  437. package/docs/reference/config.md +478 -0
  438. package/docs/reference/resource-inference.md +72 -0
  439. package/docs/reference/structure.md +138 -0
  440. package/package.json +389 -3
  441. package/sandbox.Dockerfile +4 -0
  442. package/schema.json +353 -0
  443. package/skills/bwf/SKILL.md +100 -0
  444. package/skills/migrate-vite-cloudflare-to-bwf/SKILL.md +53 -0
  445. package/templates/assets/bwf.svg +5 -0
  446. package/templates/assets/icons.svg +49 -0
  447. package/templates/assets/react.svg +1 -0
  448. package/templates/assets/stack.svg +35 -0
@@ -0,0 +1,854 @@
1
+ import { d as findBindingNameOwner } from "./wrangler-DU784Dkf.mjs";
2
+ import { n as CLOUDFLARE_QUEUE_NAMES_BUILD_ENV } from "./env-DUyTzroe.mjs";
3
+ import { isRecord } from "@builtbyfriends/deploy-core";
4
+ // src/queues/cloudflare-names.ts
5
+ /** `workerPrefix` is the Worker name in resource-name form (lowercase, `_` as `-`). */
6
+ function scopedCloudflareQueueName(workerPrefix, queueName) {
7
+ return `${workerPrefix}-${queueName}`;
8
+ }
9
+ const consumedBy = (state, workerName) => state?.consumers.includes(workerName) ?? false;
10
+ /**
11
+ * Pick the Cloudflare name for one queue: its scoped name, or its plain name
12
+ * when this Worker already consumes that queue. `plain` may be `undefined`
13
+ * when it was not looked up, which is only needed when the Worker does not
14
+ * already consume the scoped queue.
15
+ */
16
+ function chooseCloudflareQueueName(input) {
17
+ if (!consumedBy(input.scoped, input.workerName) && consumedBy(input.plain ?? null, input.workerName)) return {
18
+ name: input.queueName,
19
+ kept: true
20
+ };
21
+ return {
22
+ name: input.scopedName,
23
+ kept: false
24
+ };
25
+ }
26
+ /** Consumers of a queue other than this Worker. A queue has one consumer. */
27
+ function otherQueueConsumers(state, workerName) {
28
+ return state?.consumers.filter((consumer) => consumer !== workerName) ?? [];
29
+ }
30
+ /**
31
+ * The names `bwf deploy` chose, read inside its Vite build. Returns undefined
32
+ * outside that build, where queues keep their plain names.
33
+ */
34
+ function readDeployBuildQueueNames() {
35
+ if (process.env["BWF_CLOUDFLARE_DEPLOY_BUILD"] !== "1") return;
36
+ const raw = process.env[CLOUDFLARE_QUEUE_NAMES_BUILD_ENV];
37
+ if (raw === void 0) return;
38
+ let parsed;
39
+ try {
40
+ parsed = JSON.parse(raw);
41
+ } catch {
42
+ parsed = void 0;
43
+ }
44
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || Object.values(parsed).some((name) => typeof name !== "string" || name === "")) throw new Error(`queue: ${CLOUDFLARE_QUEUE_NAMES_BUILD_ENV} is not a valid queue name map.`);
45
+ return parsed;
46
+ }
47
+ /** The Cloudflare name of a queue: the deploy's choice, or its plain name. */
48
+ function cloudflareQueueName(queueName, names) {
49
+ return names && Object.hasOwn(names, queueName) ? names[queueName] : queueName;
50
+ }
51
+ // src/cli/email-cloudflare.ts
52
+ /** The `send_email` binding name bwf provisions and the runtime reads. */
53
+ const SEND_EMAIL_BINDING = "SEND_EMAIL";
54
+ /** The root-config `vars` key carrying `bwf.config.ts` `email.from` into the worker. */
55
+ const EMAIL_FROM_VAR = "__NOSAM_EMAIL_FROM";
56
+ const CLOUDFLARE_API_BASE_URL = "https://api.cloudflare.com/client/v4";
57
+ /** OAuth scopes the session needs (`whoami` `tokenPermissions`). */
58
+ const REQUIRED_EMAIL_SCOPES = ["email_routing:write", "email_sending:write"];
59
+ /** Cloudflare Email API error codes with a known meaning; others are reported verbatim. */
60
+ const CF_EMAIL_ERROR_CODES = {
61
+ 2062: "Email Routing is not enabled on this zone",
62
+ 2040: "already onboarded for Email Sending",
63
+ 2036: "account is not entitled to Email Sending",
64
+ 10105: "account is not entitled to Email Sending"
65
+ };
66
+ /** The one-time dashboard step printed when the subdomain routing call cannot be made. */
67
+ function subdomainDashboardFallback(apex, domain) {
68
+ return `Cloudflare dashboard → ${apex} → Email → Settings → Subdomains → add ${domain}, then redeploy`;
69
+ }
70
+ /** The Workers Free hint printed when Email Sending onboarding fails. */
71
+ const SENDING_FREE_PLAN_HINT = "Workers Paid needed for arbitrary recipients. Inbound works; sendEmail() to verified destinations only.";
72
+ /**
73
+ * Config shapes the writer would refuse for `SEND_EMAIL` and `__NOSAM_EMAIL_FROM`, checked
74
+ * before anything is asked. The writer keeps the same guard, since the file can change first.
75
+ */
76
+ function findEmailConfigConflicts(config) {
77
+ const conflicts = /* @__PURE__ */ new Set();
78
+ const check = (field, name) => {
79
+ let owner;
80
+ try {
81
+ owner = findBindingNameOwner(config, field, name);
82
+ } catch (err) {
83
+ conflicts.add(`Cloudflare config: ${err instanceof Error ? err.message : String(err)}`);
84
+ return;
85
+ }
86
+ if (owner !== void 0) conflicts.add(`Cloudflare config already uses ${name} as a ${owner} binding; rename it in bwf.config.ts (bwf writes ${name} into ${field})`);
87
+ };
88
+ check("send_email", SEND_EMAIL_BINDING);
89
+ check("vars", EMAIL_FROM_VAR);
90
+ return [...conflicts];
91
+ }
92
+ /** The `EmailCloudflareInputs` fields read from the parsed root config. */
93
+ function emailConfigInputs(rootConfig) {
94
+ return {
95
+ existingSendEmail: Array.isArray(rootConfig.send_email) ? rootConfig.send_email : void 0,
96
+ existingAddresses: rootConfig.addresses,
97
+ existingVars: isRecord(rootConfig.vars) ? rootConfig.vars : void 0,
98
+ configConflicts: findEmailConfigConflicts(rootConfig)
99
+ };
100
+ }
101
+ /**
102
+ * Host part of `email.from`, lowercased; `null` when it is not `local@host`. `bwf.config.ts`
103
+ * also accepts the display-name form (`Acme <noreply@mail.acme.com>`, see `config.ts`),
104
+ * so the address inside `<…>` is read when present.
105
+ *
106
+ * Validated per label, so an empty label or one that starts with `-` never reaches a
107
+ * Cloudflare command argument.
108
+ */
109
+ function emailFromDomain(from) {
110
+ const bracketed = /<([^<>]*)>\s*$/.exec(from.trim());
111
+ const address = bracketed ? bracketed[1] : from;
112
+ const at = address.lastIndexOf("@");
113
+ if (at <= 0 || at === address.length - 1) return null;
114
+ const host = address.slice(at + 1).trim().toLowerCase();
115
+ const labels = host.split(".");
116
+ if (labels.length < 2 || !labels.every((l) => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/.test(l))) return null;
117
+ return host;
118
+ }
119
+ /**
120
+ * `email/<literal>.ts` and `email/<literal>+[tag].ts` → `<literal>@<domain>`.
121
+ * `email/_default.ts` and any dynamic local part (`[name].ts`, `[name]+[tag].ts`)
122
+ * need a catch-all, which Cloudflare offers only on a zone apex: `*@<apex>` on the apex
123
+ * path, refused with a message on a subdomain.
124
+ *
125
+ * Reuses the scanner's compiled pattern kinds rather than re-parsing filenames — the
126
+ * grammar lives in `router/email.ts` and this must never disagree with the dispatcher.
127
+ */
128
+ function deriveAddresses(handlers, domain, mode) {
129
+ const literals = [];
130
+ const routes = [];
131
+ const refused = [];
132
+ let needsCatchAll = false;
133
+ const catchAllHandlers = [];
134
+ for (const def of handlers.addresses) {
135
+ const handler = `email/${def.filePath}`;
136
+ if (def.pattern.kind === "static" || def.pattern.kind === "static-tag") {
137
+ const address = `${def.address.split("+")[0] ?? def.address}@${domain}`;
138
+ if (!literals.includes(address)) literals.push(address);
139
+ routes.push({
140
+ address,
141
+ handler
142
+ });
143
+ continue;
144
+ }
145
+ if (mode === "subdomain") {
146
+ refused.push({
147
+ handler,
148
+ reason: `a dynamic local part needs a catch-all, and a catch-all exists only on a zone apex; nothing at @${domain} reaches it`
149
+ });
150
+ continue;
151
+ }
152
+ needsCatchAll = true;
153
+ catchAllHandlers.push(handler);
154
+ }
155
+ if (handlers.defaultHandler) {
156
+ const handler = `email/${handlers.defaultHandler}`;
157
+ if (mode === "subdomain") refused.push({
158
+ handler,
159
+ reason: `a catch-all exists only on an apex; other @${domain} mail bounces`
160
+ });
161
+ else {
162
+ needsCatchAll = true;
163
+ catchAllHandlers.push(handler);
164
+ }
165
+ }
166
+ const addresses = [...literals];
167
+ if (needsCatchAll) {
168
+ const catchAll = `*@${domain}`;
169
+ addresses.push(catchAll);
170
+ for (const handler of catchAllHandlers) routes.push({
171
+ address: catchAll,
172
+ handler
173
+ });
174
+ }
175
+ return {
176
+ addresses,
177
+ refused,
178
+ routes
179
+ };
180
+ }
181
+ function parseWhoamiJson(data) {
182
+ if (!isRecord(data) || typeof data.loggedIn !== "boolean") return null;
183
+ if (data.tokenPermissions !== void 0 && (!Array.isArray(data.tokenPermissions) || data.tokenPermissions.some((scope) => typeof scope !== "string"))) return null;
184
+ if (data.accounts !== void 0 && (!Array.isArray(data.accounts) || data.accounts.some((account) => !isRecord(account) || typeof account.id !== "string" || typeof account.name !== "string"))) return null;
185
+ return data;
186
+ }
187
+ function readRoutingSettings(data) {
188
+ return isRecord(data) && typeof data.name === "string" && data.name.length > 0 && typeof data.enabled === "boolean" && typeof data.status === "string" && data.status.length > 0 && typeof data.tag === "string" && /^[0-9a-f]{32}$/.test(data.tag) ? {
189
+ name: data.name,
190
+ enabled: data.enabled,
191
+ status: data.status,
192
+ tag: data.tag
193
+ } : null;
194
+ }
195
+ function readRoutingRules(data) {
196
+ if (!Array.isArray(data)) return null;
197
+ const rules = [];
198
+ let catchAll = null;
199
+ for (const entry of data) {
200
+ if (!isRecord(entry) || typeof entry.enabled !== "boolean" || !Array.isArray(entry.actions) || entry.actions.length === 0 || !Array.isArray(entry.matchers) || entry.matchers.length === 0) return null;
201
+ const actions = [];
202
+ for (const action of entry.actions) {
203
+ if (!isRecord(action) || typeof action.type !== "string") return null;
204
+ if (action.type === "drop") actions.push("drop");
205
+ else if (action.type === "worker" || action.type === "forward") {
206
+ const values = typeof action.value === "string" ? [action.value] : action.value;
207
+ if (!Array.isArray(values) || values.length === 0 || !values.every((value) => typeof value === "string" && value.length > 0)) return null;
208
+ if (action.type === "worker") actions.push("worker:" + values.join(","));
209
+ else actions.push("forward:" + values.join(","));
210
+ } else return null;
211
+ }
212
+ const to = [];
213
+ let all = false;
214
+ for (const matcher of entry.matchers) {
215
+ if (!isRecord(matcher)) return null;
216
+ if (matcher.type === "all") all = true;
217
+ else if (matcher.type === "literal" && matcher.field === "to" || matcher.type === "to") {
218
+ if (typeof matcher.value !== "string" || matcher.value.length === 0) return null;
219
+ to.push(matcher.value.toLowerCase());
220
+ } else return null;
221
+ }
222
+ if (all) {
223
+ if (catchAll || entry.matchers.length !== 1) return null;
224
+ catchAll = {
225
+ enabled: entry.enabled,
226
+ actions
227
+ };
228
+ } else {
229
+ if (typeof entry.id !== "string" || entry.id.length === 0 || entry.name !== void 0 && typeof entry.name !== "string") return null;
230
+ rules.push({
231
+ id: entry.id,
232
+ name: entry.name ?? "",
233
+ enabled: entry.enabled,
234
+ to,
235
+ actions
236
+ });
237
+ }
238
+ }
239
+ return {
240
+ rules,
241
+ catchAll
242
+ };
243
+ }
244
+ function readSendingSettings(data) {
245
+ if (!isRecord(data)) return null;
246
+ const tag = data.tag ?? data.id;
247
+ return typeof data.name === "string" && data.name.length > 0 && typeof data.enabled === "boolean" && typeof tag === "string" && /^[0-9a-f]{32}$/.test(tag) ? {
248
+ name: data.name,
249
+ enabled: data.enabled,
250
+ tag
251
+ } : null;
252
+ }
253
+ function providerErrorCode(result) {
254
+ return result.errorCode ?? result.errors?.find((error) => error.code !== void 0)?.code ?? null;
255
+ }
256
+ function isHardFailure(result) {
257
+ return Boolean(result.signal) || Boolean(result.error);
258
+ }
259
+ function mxState(exchanges) {
260
+ if (exchanges.length === 0) return "empty";
261
+ return exchanges.every((x) => /\.mx\.cloudflare\.net\.?$/i.test(x)) ? "cloudflare" : "foreign";
262
+ }
263
+ async function probeMx(dns, name) {
264
+ try {
265
+ const exchanges = (await dns.resolveMx(name)).slice().sort((a, b) => a.priority - b.priority).map((r) => r.exchange.toLowerCase());
266
+ return {
267
+ state: mxState(exchanges),
268
+ exchanges
269
+ };
270
+ } catch (err) {
271
+ if (isNoRecord(err)) return {
272
+ state: "empty",
273
+ exchanges: []
274
+ };
275
+ return {
276
+ state: "unknown",
277
+ exchanges: []
278
+ };
279
+ }
280
+ }
281
+ async function probeTxt(dns, name) {
282
+ try {
283
+ return (await dns.resolveTxt(name)).length > 0 ? "present" : "absent";
284
+ } catch (err) {
285
+ return isNoRecord(err) ? "absent" : "unknown";
286
+ }
287
+ }
288
+ function isNoRecord(err) {
289
+ const code = err?.code;
290
+ return code === "ENODATA" || code === "ENOTFOUND";
291
+ }
292
+ /** Candidate zone names for `mail.acme.com`: `mail.acme.com`, `acme.com`. */
293
+ function zoneCandidates(domain) {
294
+ const labels = domain.split(".");
295
+ const out = [];
296
+ for (let i = 0; i <= labels.length - 2; i += 1) out.push(labels.slice(i).join("."));
297
+ return out;
298
+ }
299
+ function shortId(id) {
300
+ return `${id.slice(0, 8)}…`;
301
+ }
302
+ /**
303
+ * Read-only preflight: session, zone, public DNS, the provider reads and, when the bearer
304
+ * can be borrowed, the two REST reads that have no command. Nothing here writes.
305
+ */
306
+ async function preflightEmail(inputs) {
307
+ const domain = emailFromDomain(inputs.from);
308
+ if (!domain) throw new Error(`email.from must be an address like you@mail.example.com (got ${JSON.stringify(inputs.from)})`);
309
+ const apiBaseUrl = inputs.apiBaseUrl ?? CLOUDFLARE_API_BASE_URL;
310
+ const run = async (operation) => inputs.runWrangler({
311
+ ...operation,
312
+ ...inputs.configPath ? { configPath: inputs.configPath } : {}
313
+ }, { capture: true });
314
+ const usageHandlers = [...inputs.handlers.addresses.map((d) => `email/${d.filePath}`), ...inputs.handlers.defaultHandler ? [`email/${inputs.handlers.defaultHandler}`] : []];
315
+ const pre = {
316
+ from: inputs.from,
317
+ domain,
318
+ apex: null,
319
+ mode: null,
320
+ workerName: inputs.workerName,
321
+ accountId: inputs.accountId,
322
+ usage: { handlers: usageHandlers },
323
+ session: {
324
+ state: "unknown",
325
+ missingScopes: []
326
+ },
327
+ zone: { state: "unknown" },
328
+ apexMx: {
329
+ state: "unknown",
330
+ exchanges: []
331
+ },
332
+ domainMx: {
333
+ state: "unknown",
334
+ exchanges: []
335
+ },
336
+ routing: { state: "unknown" },
337
+ subaddressing: { state: "unknown" },
338
+ sending: {
339
+ state: "unknown",
340
+ dnsConflicts: []
341
+ },
342
+ rules: {
343
+ state: "unknown",
344
+ mine: [],
345
+ foreign: [],
346
+ absent: []
347
+ },
348
+ binding: { state: "absent" },
349
+ sender: { state: "absent" },
350
+ addressesOwnership: {
351
+ state: "absent",
352
+ foreign: []
353
+ },
354
+ addressesStale: false,
355
+ derived: {
356
+ addresses: [],
357
+ refused: [],
358
+ routes: []
359
+ },
360
+ addresses: [],
361
+ rulesPending: [],
362
+ blockers: [],
363
+ sendingRetryable: false,
364
+ ready: false
365
+ };
366
+ const block = (scope, message) => {
367
+ pre.blockers.push({
368
+ scope,
369
+ message
370
+ });
371
+ };
372
+ for (const conflict of inputs.configConflicts ?? []) block("all", conflict);
373
+ const whoami = await run({ type: "auth.whoami" });
374
+ const who = isHardFailure(whoami) || whoami.status !== 0 ? null : parseWhoamiJson(whoami.data);
375
+ if (!who) {
376
+ pre.session.state = "unknown";
377
+ block("all", "could not read the Cloudflare session — run `bwf cloudflare login`");
378
+ } else if (!who.loggedIn) {
379
+ pre.session.state = "not-logged-in";
380
+ block("all", "not logged in to Cloudflare — run `bwf cloudflare login`");
381
+ } else {
382
+ pre.session.authType = who.authType;
383
+ pre.session.email = who.email;
384
+ pre.session.accountName = who.accounts?.find((a) => a.id === inputs.accountId)?.name;
385
+ if (who.authType === "Global API Key") {
386
+ pre.session.state = "api-key";
387
+ block("all", "the Cloudflare session is a Global API Key (CLOUDFLARE_API_KEY), which has no bearer to borrow for the subaddressing calls — unset CLOUDFLARE_API_KEY, then run `bwf cloudflare login` or set CLOUDFLARE_API_TOKEN to a token with Email Routing Edit + Email Sending Edit");
388
+ } else if (who.authType === void 0 || who.authType === "OAuth Token") {
389
+ const scopes = new Set(who.tokenPermissions ?? []);
390
+ pre.session.missingScopes = REQUIRED_EMAIL_SCOPES.filter((s) => !scopes.has(s));
391
+ if (pre.session.missingScopes.length > 0) {
392
+ pre.session.state = "missing-scopes";
393
+ block("all", `the Cloudflare session lacks ${pre.session.missingScopes.join(" + ")} — run \`bwf cloudflare logout\`, then \`bwf cloudflare login\` (one browser Allow)`);
394
+ } else pre.session.state = "ok";
395
+ } else pre.session.state = "ok";
396
+ }
397
+ const tokenHint = pre.session.state === "ok" && pre.session.authType !== "OAuth Token" ? " (an API token needs Email Routing Edit + Email Sending Edit on the zone and account)" : "";
398
+ let settings = null;
399
+ let settingsMiss = false;
400
+ if (pre.session.state === "ok") for (const candidate of zoneCandidates(domain)) {
401
+ const result = await run({
402
+ type: "email.routing.settings",
403
+ domain: candidate
404
+ });
405
+ if (isHardFailure(result)) {
406
+ settingsMiss = true;
407
+ break;
408
+ }
409
+ if (result.status === 0 && result.data === null) continue;
410
+ if (result.status !== 0) {
411
+ settingsMiss = true;
412
+ break;
413
+ }
414
+ settings = readRoutingSettings(result.data);
415
+ if (!settings) settingsMiss = true;
416
+ break;
417
+ }
418
+ if (settings) {
419
+ pre.apex = settings.name.toLowerCase();
420
+ pre.mode = pre.apex === domain ? "apex" : "subdomain";
421
+ pre.zone = {
422
+ state: "found",
423
+ zoneId: settings.tag
424
+ };
425
+ } else if (settingsMiss) block("all", `could not read Email Routing settings — unknown — run \`bwf email setup --platform cloudflare\`${tokenHint}`);
426
+ else if (pre.session.state === "ok") pre.zone.state = "not-found";
427
+ pre.domainMx = await probeMx(inputs.dns, domain);
428
+ pre.apexMx = pre.apex && pre.apex !== domain ? await probeMx(inputs.dns, pre.apex) : pre.domainMx;
429
+ const dmarc = await probeTxt(inputs.dns, `_dmarc.${domain}`);
430
+ const bounce = await probeTxt(inputs.dns, `cf-bounce.${domain}`);
431
+ if (dmarc === "present") pre.sending.dnsConflicts.push(`_dmarc.${domain}`);
432
+ if (bounce === "present") pre.sending.dnsConflicts.push(`cf-bounce.${domain}`);
433
+ if (dmarc === "unknown" || bounce === "unknown") pre.sending.dnsConflicts.push(`(DNS lookup failed for _dmarc.${domain} / cf-bounce.${domain})`);
434
+ let bearer = null;
435
+ if (pre.session.state === "ok") bearer = await inputs.getSessionBearer().catch(() => null);
436
+ if (bearer) {
437
+ const candidates = pre.apex ? [pre.apex] : zoneCandidates(domain);
438
+ for (const candidate of candidates) {
439
+ const zones = await fetchWithSessionBearer(inputs.fetchImpl, bearer, "GET", `/zones?name=${encodeURIComponent(candidate)}`, void 0, apiBaseUrl);
440
+ if (!zones.ok) break;
441
+ const zone = (Array.isArray(zones.result) ? zones.result : [])[0];
442
+ if (!zone) continue;
443
+ pre.zone.type = zone.type;
444
+ if (zone.account?.id && zone.account.id !== inputs.accountId) pre.zone = {
445
+ state: "other-account",
446
+ zoneId: zone.id,
447
+ type: zone.type
448
+ };
449
+ else if (zone.type && zone.type !== "full") pre.zone = {
450
+ state: "partial",
451
+ zoneId: zone.id,
452
+ type: zone.type
453
+ };
454
+ else {
455
+ pre.zone = {
456
+ state: "found",
457
+ zoneId: zone.id,
458
+ type: zone.type
459
+ };
460
+ if (!pre.apex) {
461
+ pre.apex = zone.name.toLowerCase();
462
+ pre.mode = pre.apex === domain ? "apex" : "subdomain";
463
+ }
464
+ }
465
+ break;
466
+ }
467
+ if (pre.zone.state === "found" && pre.zone.zoneId) {
468
+ const routing = await fetchWithSessionBearer(inputs.fetchImpl, bearer, "GET", `/zones/${pre.zone.zoneId}/email/routing`, void 0, apiBaseUrl);
469
+ const flag = routing.result?.support_subaddress;
470
+ if (routing.ok && typeof flag === "boolean") pre.subaddressing.state = flag ? "on" : "off";
471
+ }
472
+ }
473
+ bearer = null;
474
+ switch (pre.zone.state) {
475
+ case "not-found":
476
+ block("all", `no zone for ${domain} in Cloudflare account ${inputs.accountId} — add the domain to this account first`);
477
+ break;
478
+ case "other-account":
479
+ block("all", `${pre.apex ?? domain} is a zone in a different Cloudflare account than ${inputs.accountId}`);
480
+ break;
481
+ case "partial": block("all", `${pre.apex ?? domain} is a ${pre.zone.type} zone; Email Routing needs a full zone on Cloudflare DNS`);
482
+ }
483
+ if (!pre.apex || !pre.mode) {
484
+ pre.ready = false;
485
+ return pre;
486
+ }
487
+ const apex = pre.apex;
488
+ const mode = pre.mode;
489
+ if (settings) {
490
+ if (mode === "apex") {
491
+ pre.routing = {
492
+ state: settings.enabled && settings.status === "ready" ? "ready" : "pending",
493
+ status: settings.status,
494
+ enabled: settings.enabled
495
+ };
496
+ if (/^(unlocked|misconfigured)/.test(settings.status)) block("all", `Email Routing on ${apex} is ${settings.status} — fix it in the Cloudflare dashboard; bwf never re-locks records you unlocked`);
497
+ } else {
498
+ pre.routing = {
499
+ state: pre.domainMx.state === "cloudflare" ? "ready" : pre.domainMx.state === "unknown" ? "unknown" : "pending",
500
+ status: settings.status,
501
+ enabled: settings.enabled
502
+ };
503
+ if (settings.status === "unlocked") block("all", `Email Routing on ${apex} is ${settings.status} — fix it in the Cloudflare dashboard; bwf never re-locks records you unlocked`);
504
+ }
505
+ }
506
+ if (pre.routing.state !== "ready") {
507
+ if (pre.domainMx.state === "foreign") block("all", `${domain} already receives mail (${pre.domainMx.exchanges.join(", ")}). bwf never enables routing over live mail.${mode === "apex" ? ` Use something@mail.${apex}.` : ""}`);
508
+ else if (pre.domainMx.state === "unknown") block("all", `could not read the MX records of ${domain} — unknown — run \`bwf email setup --platform cloudflare\``);
509
+ }
510
+ pre.derived = deriveAddresses(inputs.handlers, domain, mode);
511
+ const rulesResult = await run({
512
+ type: "email.routing.rules.list",
513
+ domain: apex
514
+ });
515
+ const rules = isHardFailure(rulesResult) || rulesResult.status !== 0 ? null : readRoutingRules(rulesResult.data);
516
+ if (!rules) {
517
+ pre.rules.state = "unknown";
518
+ block("all", `could not read Email Routing rules — unknown — run \`bwf email setup --platform cloudflare\`${tokenHint}`);
519
+ } else {
520
+ const workerToken = `worker:${inputs.workerName}`;
521
+ for (const address of pre.derived.addresses) {
522
+ if (address.startsWith("*@")) {
523
+ if (!rules.catchAll || !rules.catchAll.enabled || rules.catchAll.actions.includes("drop")) pre.rules.absent.push(address);
524
+ else if (rules.catchAll.actions.includes(workerToken)) pre.rules.mine.push(address);
525
+ else pre.rules.foreign.push({
526
+ address,
527
+ owner: rules.catchAll.actions.join(", ")
528
+ });
529
+ continue;
530
+ }
531
+ const rule = rules.rules.find((r) => r.enabled && r.to.includes(address)) ?? rules.rules.find((r) => r.to.includes(address));
532
+ if (!rule) pre.rules.absent.push(address);
533
+ else if (rule.actions.includes(workerToken)) {
534
+ if (rule.enabled) pre.rules.mine.push(address);
535
+ else pre.rules.absent.push(address);
536
+ } else pre.rules.foreign.push({
537
+ address,
538
+ owner: rule.actions.join(", ")
539
+ });
540
+ }
541
+ pre.rules.state = pre.rules.absent.length === 0 ? "ready" : "pending";
542
+ }
543
+ const foreign = new Set(pre.rules.foreign.map((f) => f.address));
544
+ pre.addresses = pre.derived.addresses.filter((a) => !foreign.has(a));
545
+ const sendingResult = await run({
546
+ type: "email.sending.settings",
547
+ domain
548
+ });
549
+ if (isHardFailure(sendingResult)) pre.sending.state = "unknown";
550
+ else if (sendingResult.status === 0 && sendingResult.data === null) pre.sending.state = "pending";
551
+ else if (sendingResult.status === 0) {
552
+ const parsed = readSendingSettings(sendingResult.data);
553
+ pre.sending.state = parsed ? parsed.enabled ? "ready" : "pending" : "unknown";
554
+ } else pre.sending.state = "unknown";
555
+ if (pre.sending.state === "unknown") block("sending", `could not read Email Sending settings — unknown — run \`bwf email setup --platform cloudflare\`${tokenHint}`);
556
+ else if (pre.sending.state === "pending" && pre.sending.dnsConflicts.length > 0) block("sending", `${pre.sending.dnsConflicts.join(", ")} already exists; onboarding writes its own _dmarc (p=reject) and DKIM records and would conflict — remove them or keep sending off`);
557
+ const names = (inputs.existingSendEmail ?? []).map((e) => typeof e?.name === "string" ? e.name : "");
558
+ if (names.includes("SEND_EMAIL")) pre.binding = { state: "present" };
559
+ else if (names.length > 0) {
560
+ pre.binding = {
561
+ state: "foreign",
562
+ foreignName: names[0]
563
+ };
564
+ block("all", `Cloudflare config already has a send_email binding named ${JSON.stringify(names[0])}; rename it to ${SEND_EMAIL_BINDING} in bwf.config.ts (a second binding would be silent)`);
565
+ }
566
+ if (inputs.existingAddresses !== void 0 && inputs.existingAddresses !== null) {
567
+ const existing = Array.isArray(inputs.existingAddresses) ? inputs.existingAddresses.map((a) => typeof a === "string" ? a.toLowerCase() : String(a)) : ["(not an array)"];
568
+ const candidates = new Set(pre.derived.addresses);
569
+ const unknown = existing.filter((a) => !candidates.has(a));
570
+ if (unknown.length > 0) {
571
+ pre.addressesOwnership = {
572
+ state: "foreign",
573
+ foreign: unknown
574
+ };
575
+ block("all", `Cloudflare addresses holds entries bwf did not derive (${unknown.join(", ")}); remove ${unknown.map((a) => JSON.stringify(a)).join(", ")} from cloudflare.addresses in bwf.config.ts, or manage addresses by hand and unset email.from — skipping email setup this deploy`);
576
+ } else {
577
+ pre.addressesOwnership = {
578
+ state: "mine",
579
+ foreign: []
580
+ };
581
+ const pruned = new Set(pre.addresses);
582
+ pre.addressesStale = existing.length !== pre.addresses.length || existing.some((a) => !pruned.has(a));
583
+ }
584
+ } else pre.addressesStale = pre.addresses.length > 0;
585
+ const senderVar = inputs.existingVars?.[EMAIL_FROM_VAR];
586
+ pre.sender.state = senderVar === inputs.from ? "ready" : senderVar === void 0 ? "absent" : "stale";
587
+ pre.rulesPending = pre.rules.absent.filter((a) => pre.addresses.includes(a));
588
+ const sendingBlocked = pre.blockers.some((b) => b.scope === "sending");
589
+ pre.sendingRetryable = pre.sending.state === "pending" && !sendingBlocked;
590
+ const sendingSettled = pre.sending.state === "ready" || sendingBlocked || pre.sending.state === "pending" && pre.binding.state === "present";
591
+ pre.ready = !pre.blockers.some((b) => b.scope === "all") && pre.routing.state === "ready" && pre.subaddressing.state === "on" && sendingSettled && pre.binding.state === "present";
592
+ return pre;
593
+ }
594
+ /** Column padding for the checklist; an overflowing cell gets three spaces. */
595
+ function pad(text, width) {
596
+ return text.length >= width ? `${text} ` : text.padEnd(width);
597
+ }
598
+ /**
599
+ * The block shown before the confirmation: status rows, then the `+`/`!` change list.
600
+ * Blockers render as `✘` rows at the end so the developer sees why nothing will be asked.
601
+ */
602
+ function renderEmailChecklist(pre) {
603
+ const apex = pre.apex ?? "?";
604
+ const lines = [];
605
+ const inUse = pre.usage.handlers.length > 0 ? pre.usage.handlers.join(" · ") : "sending only (no email/ handlers)";
606
+ lines.push(` Email in use ${inUse}`);
607
+ const row = (label, value, note = "") => {
608
+ lines.push(` ${pad(label, 10)}${note ? `${pad(value, 23)}${note}` : value}`);
609
+ };
610
+ row("domain", pre.domain, "(bwf.config.ts email.from)");
611
+ const session = [pre.session.accountName ? `account ${pre.session.accountName} (${shortId(pre.accountId)})` : `account ${shortId(pre.accountId)}`, pre.session.authType && pre.session.authType !== "OAuth Token" ? `session ${pre.session.email ? `${pre.session.email} ` : ""}(${pre.session.authType})` : pre.session.email ? `session ${pre.session.email}` : null].filter(Boolean).join(" · ");
612
+ row("zone", pre.zone.state === "found" ? apex : `${apex} ${pre.zone.state}`, session);
613
+ if (pre.mode === "subdomain") row("apex MX", pre.apexMx.exchanges[0] ?? (pre.apexMx.state === "unknown" ? "unknown" : "none"), "left alone — mail lives on the subdomain");
614
+ else row("apex MX", pre.apexMx.exchanges[0] ?? (pre.apexMx.state === "unknown" ? "unknown" : "none"), pre.apexMx.state === "cloudflare" ? "Cloudflare Email Routing" : pre.apexMx.state === "empty" ? "empty — the apex can take routing" : "");
615
+ const routingWord = pre.routing.state === "ready" ? "enabled" : pre.routing.state === "unknown" ? "unknown — run bwf email setup --platform cloudflare" : `not enabled${pre.mode === "apex" && pre.routing.status && pre.routing.status !== "unconfigured" ? ` (${pre.routing.status})` : ""}`;
616
+ const subWord = pre.subaddressing.state === "on" ? "subaddressing on" : pre.subaddressing.state === "off" ? "subaddressing off" : "subaddressing unknown";
617
+ row("routing", `${pre.domain} ${routingWord} · ${subWord}`);
618
+ const sendingWord = pre.sending.state === "ready" ? "onboarded" : pre.sending.state === "unknown" ? "unknown — run bwf email setup --platform cloudflare" : pre.sendingRetryable && pre.binding.state === "present" ? "not onboarded — verified destinations only; after upgrading to Workers Paid run bwf email setup --platform cloudflare" : "not onboarded";
619
+ row("sending", `${pre.domain} ${sendingWord}`);
620
+ if (pre.derived.addresses.length === 0) row("rules", "(none — no email/ handlers)");
621
+ for (const address of pre.derived.addresses) {
622
+ const foreignRule = pre.rules.foreign.find((f) => f.address === address);
623
+ const status = pre.rules.mine.includes(address) ? "ready" : foreignRule ? `owned elsewhere: ${foreignRule.owner} — pruned` : pre.rules.state === "unknown" ? "unknown" : "absent";
624
+ row("rules", `${address} → ${pre.workerName}`, `(${status})`);
625
+ }
626
+ row("binding", SEND_EMAIL_BINDING, `(${pre.binding.state === "present" ? "present" : pre.binding.state === "foreign" ? `found ${pre.binding.foreignName} instead` : "absent"})`);
627
+ row("sender", pre.from, `(vars.${EMAIL_FROM_VAR} ${pre.sender.state})`);
628
+ lines.push("");
629
+ const changes = [];
630
+ const change = (what, why) => {
631
+ changes.push(` + ${pad(what, 44)}${why}`);
632
+ };
633
+ const warn = (what, why) => {
634
+ changes.push(` ! ${pad(what, 44)}${why}`);
635
+ };
636
+ const subdomainNeedsApex = pre.mode === "subdomain" && pre.routing.enabled !== true;
637
+ if (pre.routing.state !== "ready" && subdomainNeedsApex) warn(`enable Email Routing on ${pre.domain}`, `Email Routing is not enabled on ${apex}; bwf never enables it on the apex from the subdomain path — ${subdomainDashboardFallback(apex, pre.domain)}`);
638
+ else if (pre.routing.state !== "ready") change(`enable Email Routing on ${pre.domain}`, `Cloudflare writes and locks 3 MX + 1 SPF record ${pre.mode === "subdomain" ? "there" : "on the apex"}`);
639
+ if (pre.subaddressing.state !== "on") change(`turn on subaddressing for ${apex}`, "support+anything@ reaches support@");
640
+ if (pre.sending.state !== "ready" && !pre.blockers.some((b) => b.scope === "sending")) change(`onboard ${pre.domain} for Email Sending`, `MX/SPF/DKIM on cf-bounce.${pre.domain}, _dmarc.${pre.domain} (p=reject)`);
641
+ const parts = [];
642
+ if (pre.binding.state !== "present") parts.push(`send_email: [{ name: "${SEND_EMAIL_BINDING}" }]`);
643
+ if (pre.addressesStale) parts.push(pre.addresses.length > 0 ? `addresses: ${JSON.stringify(pre.addresses)}` : "addresses: (removed)");
644
+ if (pre.sender.state !== "ready") parts.push(`vars.${EMAIL_FROM_VAR}: ${JSON.stringify(pre.from)}`);
645
+ if (parts.length > 0) change("Cloudflare config", parts.join(", "));
646
+ for (const address of pre.rules.absent) change("routing rule (created on deploy)", `${address} → ${pre.workerName}`);
647
+ for (const foreign of pre.rules.foreign) warn(foreign.address, `already routed to ${foreign.owner}; left alone, not in addresses`);
648
+ for (const refused of pre.derived.refused) warn(refused.handler, refused.reason);
649
+ for (const blocker of pre.blockers) changes.push(` ✘ ${blocker.message}`);
650
+ if (changes.length === 0) lines.push(" Nothing to change — email is set up.");
651
+ else lines.push(` This changes YOUR Cloudflare account.${pre.mode === "subdomain" && !subdomainNeedsApex ? ` ${apex} itself is not touched.` : ""}`, ...changes);
652
+ return lines.join("\n");
653
+ }
654
+ /**
655
+ * The ONLY function that receives the session bearer. It puts the token in the
656
+ * `Authorization` header and nowhere else: not in the URL, not in a log line, not in
657
+ * the returned object, not in an error. A transport failure is returned as
658
+ * `{ ok: false, status: 0 }` with the underlying message (which names the URL at
659
+ * most) — never thrown, so a caller can never leak the token through a stack trace.
660
+ */
661
+ async function fetchWithSessionBearer(fetchImpl, bearer, method, path, body, apiBaseUrl = CLOUDFLARE_API_BASE_URL) {
662
+ const headers = { Authorization: `Bearer ${bearer}` };
663
+ if (body !== void 0) headers["Content-Type"] = "application/json";
664
+ const scrub = (text) => text.split(bearer).join("[redacted]");
665
+ let response;
666
+ try {
667
+ response = await fetchImpl(`${apiBaseUrl}${path}`, {
668
+ method,
669
+ headers,
670
+ body: body === void 0 ? void 0 : JSON.stringify(body)
671
+ });
672
+ } catch (err) {
673
+ return {
674
+ ok: false,
675
+ status: 0,
676
+ result: null,
677
+ errors: [{
678
+ code: 0,
679
+ message: scrub(err instanceof Error ? err.message : String(err))
680
+ }]
681
+ };
682
+ }
683
+ let payload = {};
684
+ try {
685
+ payload = await response.json();
686
+ } catch {
687
+ payload = {};
688
+ }
689
+ const errors = (payload.errors ?? []).map((e) => ({
690
+ code: typeof e?.code === "number" ? e.code : 0,
691
+ message: typeof e?.message === "string" ? scrub(e.message) : ""
692
+ }));
693
+ return {
694
+ ok: response.ok && payload.success !== false,
695
+ status: response.status,
696
+ result: payload.result ?? null,
697
+ errors
698
+ };
699
+ }
700
+ /**
701
+ * Run only the rows preflight found not ready:
702
+ *
703
+ * routing apex → `email routing enable <apex>`
704
+ * subdomain → bearer POST /zones/{z}/email/routing/dns { name }
705
+ * subaddr bearer PATCH /zones/{z}/email/routing { support_subaddress: true }
706
+ * sending `email sending enable <domain>`; code 2040 (already onboarded) is ok;
707
+ * any other failure prints a hint and continues without sending
708
+ *
709
+ * A failed bearer call prints the dashboard fallback and withholds `addresses` this run;
710
+ * it never fails the deploy. An `all` blocker applies nothing and returns an empty patch.
711
+ */
712
+ async function applyEmailSetup(pre, inputs) {
713
+ const lines = [];
714
+ const result = {
715
+ patch: {},
716
+ lines,
717
+ routingReady: pre.routing.state === "ready",
718
+ subaddressingReady: pre.subaddressing.state === "on",
719
+ sendingReady: pre.sending.state === "ready",
720
+ inboundReady: false
721
+ };
722
+ const blocked = pre.blockers.filter((b) => b.scope === "all");
723
+ if (blocked.length > 0 || !pre.apex || !pre.mode) {
724
+ for (const b of blocked) lines.push(` ✘ ${b.message}`);
725
+ if (blocked.length === 0) lines.push(" ✘ email: the zone could not be resolved — unknown — run `bwf email setup --platform cloudflare`");
726
+ return result;
727
+ }
728
+ const apex = pre.apex;
729
+ const apiBaseUrl = inputs.apiBaseUrl ?? CLOUDFLARE_API_BASE_URL;
730
+ const run = async (operation) => inputs.runWrangler({
731
+ ...operation,
732
+ ...inputs.configPath ? { configPath: inputs.configPath } : {}
733
+ }, { capture: true });
734
+ let bearer;
735
+ let bearerFailed = false;
736
+ let bearerObtained = false;
737
+ const borrow = async () => {
738
+ if (bearer === void 0) {
739
+ bearer = await inputs.getSessionBearer().catch(() => null);
740
+ if (bearer) bearerObtained = true;
741
+ else bearerFailed = true;
742
+ }
743
+ return bearer;
744
+ };
745
+ const withBearer = async (method, path, body) => {
746
+ const token = await borrow();
747
+ if (!token) return null;
748
+ const response = await fetchWithSessionBearer(inputs.fetchImpl, token, method, path, body, apiBaseUrl);
749
+ if (!response.ok) bearerFailed = true;
750
+ return response;
751
+ };
752
+ const describeFailure = (response) => {
753
+ if (!response) return "could not borrow the Cloudflare session (session-bearer step failed)";
754
+ const first = response.errors[0];
755
+ const code = first?.code ? ` [code: ${first.code}]` : "";
756
+ const known = first?.code ? CF_EMAIL_ERROR_CODES[first.code] : void 0;
757
+ return `Cloudflare answered ${response.status}${code}${known ? ` — ${known}` : first?.message ? ` — ${first.message}` : ""}`;
758
+ };
759
+ const apexRoutingOff = pre.mode === "subdomain" && pre.routing.enabled !== true;
760
+ if (!result.routingReady) {
761
+ if (pre.mode === "apex") {
762
+ const enable = await run({
763
+ type: "email.routing.enable",
764
+ domain: apex
765
+ });
766
+ if (!isHardFailure(enable) && enable.status === 0) {
767
+ result.routingReady = true;
768
+ lines.push(` ✔ routing ${apex} enabled`);
769
+ } else {
770
+ const code = providerErrorCode(enable);
771
+ lines.push(` ✘ routing could not enable Email Routing on ${apex}${code ? ` [code: ${code}]${CF_EMAIL_ERROR_CODES[code] ? ` — ${CF_EMAIL_ERROR_CODES[code]}` : ""}` : ""}`);
772
+ }
773
+ } else if (apexRoutingOff) {
774
+ lines.push(` ✘ routing ${pre.domain}: Email Routing is not enabled on ${apex} — a subdomain can only be added to a zone that already routes; bwf never enables routing on the apex from the subdomain path`);
775
+ lines.push(` ${subdomainDashboardFallback(apex, pre.domain)}`);
776
+ } else {
777
+ const response = await withBearer("POST", `/zones/${pre.zone.zoneId}/email/routing/dns`, { name: pre.domain });
778
+ if (response?.ok) {
779
+ result.routingReady = true;
780
+ lines.push(` ✔ routing ${pre.domain} enabled`);
781
+ } else {
782
+ lines.push(` ✘ routing ${pre.domain}: ${describeFailure(response)}`);
783
+ lines.push(` ${subdomainDashboardFallback(apex, pre.domain)}`);
784
+ }
785
+ }
786
+ }
787
+ if (!result.subaddressingReady && !bearerFailed && !apexRoutingOff) {
788
+ const response = await withBearer("PATCH", `/zones/${pre.zone.zoneId}/email/routing`, { support_subaddress: true });
789
+ if (response?.ok) {
790
+ result.subaddressingReady = true;
791
+ lines.push(` ✔ routing subaddressing on for ${apex}`);
792
+ } else {
793
+ lines.push(` ✘ routing subaddressing on ${apex}: ${describeFailure(response)}`);
794
+ lines.push(` turn it on in the Cloudflare dashboard → ${apex} → Email → Settings → Subaddressing`);
795
+ }
796
+ } else if (!result.subaddressingReady) lines.push(` ✘ routing subaddressing on ${apex}: skipped (${apexRoutingOff ? `Email Routing is not enabled on ${apex}` : bearerObtained ? "the subdomain routing call failed" : "session bearer unavailable"})`);
797
+ bearer = null;
798
+ const sendingBlocked = pre.blockers.filter((b) => b.scope === "sending");
799
+ if (!result.sendingReady && sendingBlocked.length > 0) for (const b of sendingBlocked) lines.push(` ! sending ${b.message}`);
800
+ else if (!result.sendingReady) {
801
+ const enable = await run({
802
+ type: "email.sending.enable",
803
+ domain: pre.domain
804
+ });
805
+ const code = isHardFailure(enable) ? null : providerErrorCode(enable);
806
+ if (!isHardFailure(enable) && (enable.status === 0 || code === 2040)) {
807
+ result.sendingReady = true;
808
+ lines.push(` ✔ sending ${pre.domain} onboarded`);
809
+ } else {
810
+ const known = code ? CF_EMAIL_ERROR_CODES[code] : void 0;
811
+ lines.push(` ! sending ${pre.domain} not onboarded${code ? ` [code: ${code}]` : ""}${known ? ` — ${known}` : ""}`);
812
+ lines.push(` ${SENDING_FREE_PLAN_HINT}`);
813
+ }
814
+ }
815
+ if (result.routingReady || result.sendingReady) {
816
+ result.patch.sendEmail = { name: SEND_EMAIL_BINDING };
817
+ result.patch.vars = { [EMAIL_FROM_VAR]: pre.from };
818
+ }
819
+ const addressesWithheld = bearerFailed || !result.routingReady;
820
+ if (!addressesWithheld && pre.addresses.length > 0) result.patch.addresses = pre.addresses;
821
+ else {
822
+ result.patch.addresses = null;
823
+ if (addressesWithheld && pre.addresses.length > 0) lines.push(` ! config addresses withheld this run (${bearerFailed ? "session-bearer step failed" : "routing not ready"}); no routing rule is created for ${pre.addresses.join(", ")}`);
824
+ }
825
+ lines.push(" ✔ config bwf.lock.json updated");
826
+ result.inboundReady = result.routingReady && result.subaddressingReady && !addressesWithheld;
827
+ return result;
828
+ }
829
+ /**
830
+ * The post-deploy block:
831
+ *
832
+ * inbound support@mail.acme.com → email/support+[ticket].ts
833
+ * outbound sendEmail() from support@mail.acme.com
834
+ */
835
+ function renderAddressMap(map) {
836
+ const lines = [];
837
+ const width = Math.max(0, ...map.routes.map((r) => r.address.length));
838
+ const pending = map.pendingLabel ?? "(no rule this deploy)";
839
+ for (const route of map.routes) {
840
+ const marker = !map.addresses.includes(route.address) ? ` ${pending}` : map.creating?.includes(route.address) ? " (rule created by this deploy)" : "";
841
+ lines.push(` inbound ${pad(route.address, width + 2)}→ ${route.handler}${marker}`);
842
+ }
843
+ lines.push(` outbound sendEmail() from ${map.from}${map.sendingReady ? "" : " (verified destinations only)"}`);
844
+ return lines.join("\n");
845
+ }
846
+ /** The production `EmailDns`: `node:dns/promises` against the system resolver. */
847
+ async function createNodeEmailDns() {
848
+ const dns = await import("node:dns/promises");
849
+ return {
850
+ resolveMx: (name) => dns.resolveMx(name),
851
+ resolveTxt: (name) => dns.resolveTxt(name)
852
+ };
853
+ }
854
+ export { emailConfigInputs as a, renderAddressMap as c, cloudflareQueueName as d, otherQueueConsumers as f, createNodeEmailDns as i, renderEmailChecklist as l, scopedCloudflareQueueName as m, SEND_EMAIL_BINDING as n, preflightEmail as o, readDeployBuildQueueNames as p, applyEmailSetup as r, probeMx as s, EMAIL_FROM_VAR as t, chooseCloudflareQueueName as u };