@builtbyfriends/bwf 0.0.0-stage → 1.9.2

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-Ddt8lGeL.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-CCl-hJol.mjs +26 -0
  17. package/dist/auth-migrations-DDeifS3v.mjs +206 -0
  18. package/dist/auth-router-BG74WFUf.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-BfYf6fnB.mjs +1846 -0
  40. package/dist/client-D3D5RM5h.mjs +940 -0
  41. package/dist/client-VF2Nzc7Z.mjs +1 -0
  42. package/dist/cloudflare-auth-DzkU9H6r.mjs +152 -0
  43. package/dist/cloudflare-cmd-Bm6UhzAQ.mjs +59 -0
  44. package/dist/cloudflare-config-i8yanry0.mjs +186 -0
  45. package/dist/cloudflare-connect-B4ItSbJi.mjs +55 -0
  46. package/dist/cloudflare-operations-BcK849ue.mjs +1 -0
  47. package/dist/cloudflare-operations-DGF7xH7O.mjs +627 -0
  48. package/dist/cloudflare-process-tThIjEB2.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-CSNWKLzB.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-SOv4E9wr.mjs +1735 -0
  65. package/dist/delete-BSKI7V23.mjs +65 -0
  66. package/dist/deploy-BCSQoKC0.mjs +2 -0
  67. package/dist/deploy-CWJ3JJs_.mjs +6512 -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-BJaAbxuQ.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-C_ATvNIG.mjs +2865 -0
  84. package/dist/email-cloudflare-oXk2G1G3.mjs +854 -0
  85. package/dist/email-protocol-CZ0bAkI8.mjs +81 -0
  86. package/dist/email-rIfZgVAB.mjs +742 -0
  87. package/dist/env-BGTu3KWZ.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-BlXzGgLZ.mjs +1 -0
  97. package/dist/env-validation-DeqFUSKg.mjs +488 -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-B_ocHStk.d.mts +279 -0
  111. package/dist/handler-CNq7aSs1.mjs +161 -0
  112. package/dist/help-BK35YcRa.mjs +1946 -0
  113. package/dist/help-DaRezBj7.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-CXanf5ck.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-B1WAE9Wt.mjs +130 -0
  124. package/dist/live-KkEeda1Z.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-bUoAtFUe.mjs +103 -0
  128. package/dist/log-JDnPc0cF.mjs +23 -0
  129. package/dist/login-BUzyiyHV.mjs +1 -0
  130. package/dist/login-Dbv_T3Ru.mjs +87 -0
  131. package/dist/logs-BjMJooJQ.mjs +129 -0
  132. package/dist/migrate-DjW9_-sS.mjs +1 -0
  133. package/dist/migrate-DtcfKqPW.mjs +125 -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-BiGmSlZx.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-BsHKYJYt.mjs +1 -0
  145. package/dist/operator-cmd-DTIkOAnP.mjs +443 -0
  146. package/dist/output-Bb34lF0w.mjs +173 -0
  147. package/dist/output-CVolXKC1.mjs +1 -0
  148. package/dist/package-BX_giUBX.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-C-DyuCNX.mjs +1 -0
  155. package/dist/platform-args-CyeQWaZ7.mjs +538 -0
  156. package/dist/platform-auth-config-BfXqKSyZ.mjs +371 -0
  157. package/dist/platform-auth-protection-5FR6qoP_.mjs +231 -0
  158. package/dist/platform-auth-recovery-B5ZlqA8K.mjs +309 -0
  159. package/dist/platform-cmd-CcFDxtrl.mjs +1 -0
  160. package/dist/platform-cmd-ChXeBrRH.mjs +193 -0
  161. package/dist/platform-discovery-Bxg9aZXU.mjs +40 -0
  162. package/dist/platform-domain-CwatS3cz.mjs +256 -0
  163. package/dist/platform-lifecycle-0cXTmMsh.mjs +8928 -0
  164. package/dist/platform-lifecycle-BcoBAMux.mjs +1 -0
  165. package/dist/platform-management-6Wbdbob5.mjs +1607 -0
  166. package/dist/platform-management-hhnczOzr.mjs +1 -0
  167. package/dist/platform-plans-config-CkbUKFpm.mjs +447 -0
  168. package/dist/platform-recovery-DgIwlqB-.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-DX8y_6Kh.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-BydRwr-x.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-BA59NCPO.mjs +1 -0
  188. package/dist/provision-C90fULHJ.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-wi6WK5T6.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-BjSoQ-mW.mjs +1 -0
  209. package/dist/runner-mysql-BmTI2EiF.mjs +145 -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-D5XrWshs.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-DPhqnpaa.mjs +23 -0
  343. package/dist/wrangler-C3uyPadQ.mjs +1 -0
  344. package/dist/wrangler-TqTvJFWS.mjs +1452 -0
  345. package/dist/ws-DZRiIpYw.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,742 @@
1
+ import { A as confirm, L as log, U as password, tt as isCancel } from "./dist-STQXl8ck.mjs";
2
+ import { a as join } from "./dist-DMYe8CZJ.mjs";
3
+ import { f as readConfig } from "./config-tNx0HlFv.mjs";
4
+ import { n as readProjectPaths } from "./project-paths-iXHKRTTQ.mjs";
5
+ import { i as scanEmailHandlersSync } from "./email-C_ATvNIG.mjs";
6
+ import { c as getToken, u as openBrowser } from "./auth-xnkmpZUl.mjs";
7
+ import { n as PlatformApiError, r as PlatformClient } from "./client-D3D5RM5h.mjs";
8
+ import { a as createDeployWranglerRunner, i as discoverRootWranglerConfig, l as deriveWorkerName, o as isWranglerNonInteractiveOrCI, s as runWranglerAuthToken } from "./deploy-CWJ3JJs_.mjs";
9
+ import { a as emailConfigInputs, c as renderAddressMap, i as createNodeEmailDns, l as renderEmailChecklist, o as preflightEmail, r as applyEmailSetup, s as probeMx } from "./email-cloudflare-oXk2G1G3.mjs";
10
+ import { f as import_picocolors, l as formatUrl, m as printSuccess, p as note, r as createSpinner } from "./output-Bb34lF0w.mjs";
11
+ import { i as resolveCommandProjectId } from "./resolve-project-BCsAMDRA.mjs";
12
+ import { T as resolveDeployTransport } from "./cloudflare-operations-DGF7xH7O.mjs";
13
+ import { A as writeProvisionedWranglerConfig } from "./wrangler-TqTvJFWS.mjs";
14
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { execSync } from "node:child_process";
17
+ import { parseRootWranglerConfig, readWranglerTopLevelString } from "@builtbyfriends/deploy-cloudflare";
18
+ import { setTimeout as setTimeout$1 } from "node:timers/promises";
19
+ // src/cli/email.ts
20
+ async function runEmailCommand(root, args) {
21
+ if (args.platform === "cloudflare") return runEmailCloudflareCommand(root, args);
22
+ if (args.subcommand === "setup") {
23
+ log.error("email: `bwf email setup` sets email up on your OWN Cloudflare account — run it with `--platform cloudflare`. The bwf platform needs no setup: deploy, and `bwf email alias` shows your address.");
24
+ process.exit(1);
25
+ }
26
+ if (args.subcommand === "status") {
27
+ log.error("email: `bwf email status` checks email on your own Cloudflare account. Run it with `--platform cloudflare`. On the bwf platform, use `bwf email usage` and `bwf email destinations`.");
28
+ process.exit(1);
29
+ }
30
+ const token = getToken(root);
31
+ if (!token) {
32
+ log.error("Not logged in. Run `bwf account login` first.");
33
+ process.exit(1);
34
+ }
35
+ const client = new PlatformClient(token, { root });
36
+ const projectId = await resolveCommandProjectId(client, root, args.projectSlug);
37
+ switch (args.subcommand) {
38
+ case "usage": return emailUsage(client, projectId);
39
+ case "logs": return emailLogs(client, projectId, args.limit);
40
+ case "destinations": return emailDestinations(client, projectId);
41
+ case "allow": return emailAllow(client, projectId, args.address);
42
+ case "disallow": return emailDisallow(client, projectId, args.address);
43
+ case "alias": return emailAlias(client, projectId, args.address, { yes: args.yes === true });
44
+ case "domain": return runEmailDomainCommand(client, projectId, args);
45
+ }
46
+ }
47
+ async function emailUsage(client, projectId) {
48
+ const usage = await client.getEmailUsage(projectId);
49
+ const status = usage.suspended ? import_picocolors.default.red("SUSPENDED") : import_picocolors.default.green("active");
50
+ const lines = [
51
+ `Month: ${usage.month}`,
52
+ `Status: ${status}`,
53
+ `Recipient attempts: ${usage.attempts} / ${usage.limit} (${usage.remaining} remaining)`,
54
+ `Inbound receipts: ${usage.received}`
55
+ ];
56
+ note(lines.join("\n"), "Email Usage");
57
+ }
58
+ async function emailAlias(client, projectId, name, opts = { yes: false }) {
59
+ if (!name) {
60
+ const settings = await client.getEmailSettings(projectId);
61
+ const shared = settings.sharedInbound;
62
+ const domain = settings.sharedDomain ?? (shared ? shared.recipient.slice(shared.recipient.lastIndexOf("@") + 1) : null);
63
+ const name = settings.emailAlias ?? settings.domains.projectSlug;
64
+ if (!domain || !name) {
65
+ log.info("This platform has no shared mail domain.");
66
+ return;
67
+ }
68
+ const address = `${name}@${domain}`;
69
+ const lines = [`Address: ${address}`, `Inbound: ${inboundLine(shared, address)}`];
70
+ if (settings.emailAlias && settings.domains.projectSlug) lines.push(`Also: ${settings.domains.projectSlug}@${domain} (the project slug)`);
71
+ note(lines.join("\n"), "Shared mail address");
72
+ if (!settings.emailAlias) log.info("Run `bwf email alias <name>` to give this address a shorter, permanent name.");
73
+ return;
74
+ }
75
+ if (!opts.yes) {
76
+ if (!(opts.isInteractive ?? (process.stdin.isTTY && process.stdout.isTTY))) {
77
+ log.error("email: the alias is permanent. Pass --yes to set it without a prompt.");
78
+ process.exit(1);
79
+ }
80
+ const ok = await confirm({
81
+ message: `Set the permanent email alias "${name}"? It cannot be changed or removed later; the slug address keeps working.`,
82
+ initialValue: false
83
+ });
84
+ if (isCancel(ok) || !ok) {
85
+ log.info("Cancelled. No alias was set.");
86
+ return;
87
+ }
88
+ }
89
+ const result = await client.setEmailAlias(projectId, name);
90
+ printSuccess(`Email alias set: ${result.address}`);
91
+ const status = result.sharedInbound?.status;
92
+ if (status && status !== "ready") {
93
+ const other = result.sharedInbound.recipient === result.address ? "" : ` at ${result.sharedInbound.recipient}`;
94
+ log.info(`Inbound mail${other} is ${status}${result.sharedInbound?.reason ? `: ${result.sharedInbound.reason}` : ""}. It starts working once the project has an email handler deployed and routing is ready; check with \`bwf email alias\`.`);
95
+ }
96
+ }
97
+ /**
98
+ * The inbound status covers every name of the project, so name the address
99
+ * it belongs to when that is not the one shown (the slug row can be the one
100
+ * not ready yet).
101
+ */
102
+ function inboundLine(shared, address) {
103
+ if (!shared) return "not set up on this platform";
104
+ return shared.recipient === address ? shared.status : `${shared.status} (${shared.recipient})`;
105
+ }
106
+ async function emailDestinations(client, projectId) {
107
+ const rows = await client.listEmailDestinations(projectId);
108
+ if (rows.length === 0) {
109
+ log.info("No verified destinations. Run `bwf email allow <address>` to add one — Cloudflare will email the recipient with a verification link.");
110
+ return;
111
+ }
112
+ const lines = rows.map((d) => {
113
+ const status = d.status === "verified" ? import_picocolors.default.green("verified") : d.status === "pending" ? import_picocolors.default.yellow("pending") : import_picocolors.default.red("failed");
114
+ return ` ${d.address.padEnd(40)} ${status}`;
115
+ });
116
+ note(lines.join("\n"), "Email Destinations");
117
+ }
118
+ async function emailAllow(client, projectId, address) {
119
+ const dest = await client.addEmailDestination(projectId, address);
120
+ const sent = dest.verificationSent !== false && (dest.created || dest.platformVerificationPending);
121
+ if (dest.status === "verified") log.info(`${dest.address} is already verified.`);
122
+ else if (sent) {
123
+ log.info("They click the link in their inbox — no bwf or Cloudflare account needed. `bwf email destinations` to poll status.");
124
+ printSuccess(`Verification email sent to ${dest.address}.`);
125
+ } else if (dest.created) log.warn(`${dest.address} is on this project's list now, but Cloudflare already had the address pending (added by another project, or by hand), so no new verification email was sent — the link it mailed when the address was first added is the one to click. ${freshLinkHint(dest.address)}`);
126
+ else log.info(`${dest.address} is still pending — Cloudflare emailed them a verification link when the address was first added, and a repeat add sends nothing new. ${freshLinkHint(dest.address)}`);
127
+ }
128
+ /**
129
+ * Cloudflare has no API to resend its verification mail; the only fresh link
130
+ * is a fresh registration, and the platform deletes the Cloudflare-side
131
+ * address only once no project still lists it.
132
+ */
133
+ function freshLinkHint(address) {
134
+ return `For a fresh link, remove the address from every project that lists it (\`bwf email disallow ${address}\`), then \`bwf email allow ${address}\` — Cloudflare mails a new link only when it registers the address anew.`;
135
+ }
136
+ async function emailDisallow(client, projectId, address) {
137
+ const dest = (await client.listEmailDestinations(projectId)).find((d) => d.address.toLowerCase() === address.toLowerCase());
138
+ if (!dest) {
139
+ log.error(`destination: '${address}' is not in the project's allowlist.`);
140
+ process.exit(1);
141
+ }
142
+ await client.removeEmailDestination(projectId, dest.id);
143
+ printSuccess(`Removed ${dest.address}. New sends to it are refused immediately; already admitted attempts may finish.`);
144
+ }
145
+ async function emailLogs(client, projectId, limit) {
146
+ const result = await client.getEmailLogs(projectId, limit);
147
+ if (result.logs.length === 0) {
148
+ log.info("No email activity recorded.");
149
+ return;
150
+ }
151
+ const lines = result.logs.map((entry) => {
152
+ return `${new Date(entry.timestamp).toISOString()} ${entry.direction === "sent" ? "→" : "←"} ${entry.operationId} ${entry.recipient ?? "—"} ${entry.status}${entry.errorCode ? ` (${entry.errorCode})` : ""}`;
153
+ });
154
+ note(lines.join("\n"), "Email Logs");
155
+ }
156
+ /**
157
+ * Permission groups prefilled in the dashboard token link. `zone_settings: edit` gates
158
+ * the routing POST; `zone: read` serves the zone lookup.
159
+ */
160
+ const CF_TOKEN_TEMPLATE_PERMISSION_GROUPS = [
161
+ {
162
+ key: "zone",
163
+ type: "read"
164
+ },
165
+ {
166
+ key: "email_routing_rule",
167
+ type: "edit"
168
+ },
169
+ {
170
+ key: "email_sending",
171
+ type: "edit"
172
+ },
173
+ {
174
+ key: "workers_scripts",
175
+ type: "edit"
176
+ },
177
+ {
178
+ key: "zone_settings",
179
+ type: "edit"
180
+ }
181
+ ];
182
+ /** Dashboard link that prefills the scoped API token form. */
183
+ function buildCfApiTokenTemplateUrl(domain) {
184
+ const url = new URL("https://dash.cloudflare.com/profile/api-tokens");
185
+ url.searchParams.set("permissionGroupKeys", JSON.stringify(CF_TOKEN_TEMPLATE_PERMISSION_GROUPS));
186
+ url.searchParams.set("accountId", "*");
187
+ url.searchParams.set("zoneId", "all");
188
+ url.searchParams.set("name", `bwf email — ${domain}`);
189
+ return url.href;
190
+ }
191
+ const CFUT_TOKEN_PATTERN = /^cfut_[A-Za-z0-9_-]{44,64}$/;
192
+ const LEGACY_CF_TOKEN_PATTERN = /^[A-Za-z0-9_-]{40}$/;
193
+ const REFUSED_TOKEN_PREFIXES = [
194
+ "ghp_",
195
+ "github_pat_",
196
+ "sk-",
197
+ "xox",
198
+ "cfk_"
199
+ ];
200
+ /** Shape-only classification of a clipboard or pasted value. Never logs the value. */
201
+ function classifyCfApiTokenShape(value) {
202
+ const token = value.trim();
203
+ if (REFUSED_TOKEN_PREFIXES.some((prefix) => token.startsWith(prefix))) return "refused";
204
+ if (CFUT_TOKEN_PATTERN.test(token)) return "cfut";
205
+ if (LEGACY_CF_TOKEN_PATTERN.test(token)) return "legacy";
206
+ return "unknown";
207
+ }
208
+ function readClipboard() {
209
+ const platform = process.platform;
210
+ const command = platform === "darwin" ? "pbpaste" : platform === "win32" ? "powershell -NoProfile -Command Get-Clipboard" : "xclip -o -selection clipboard";
211
+ try {
212
+ return execSync(command, {
213
+ encoding: "utf8",
214
+ stdio: [
215
+ "ignore",
216
+ "pipe",
217
+ "ignore"
218
+ ]
219
+ });
220
+ } catch {
221
+ if (platform !== "darwin" && platform !== "win32") try {
222
+ return execSync("wl-paste", {
223
+ encoding: "utf8",
224
+ stdio: [
225
+ "ignore",
226
+ "pipe",
227
+ "ignore"
228
+ ]
229
+ });
230
+ } catch {}
231
+ return null;
232
+ }
233
+ }
234
+ /** `pbcopy </dev/null` and the platform equivalents — best-effort, never throws. */
235
+ function clearClipboard() {
236
+ const platform = process.platform;
237
+ try {
238
+ if (platform === "darwin") execSync("pbcopy", { input: "" });
239
+ else if (platform === "win32") execSync("clip", { input: "" });
240
+ else try {
241
+ execSync("xclip -selection clipboard", { input: "" });
242
+ } catch {
243
+ execSync("wl-copy", { input: "" });
244
+ }
245
+ } catch {}
246
+ }
247
+ /**
248
+ * Local active check. 'unknown' means the check could not run (network or CF error); the
249
+ * caller proceeds and the platform verifies authoritatively. The token is never logged.
250
+ */
251
+ async function verifyCfApiToken(token) {
252
+ let res;
253
+ try {
254
+ res = await fetch("https://api.cloudflare.com/client/v4/user/tokens/verify", { headers: { authorization: `Bearer ${token}` } });
255
+ } catch {
256
+ return "unknown";
257
+ }
258
+ if (res.status === 401 || res.status === 403) return "inactive";
259
+ if (!res.ok) return "unknown";
260
+ try {
261
+ return (await res.json()).result?.status === "active" ? "active" : "inactive";
262
+ } catch {
263
+ return "unknown";
264
+ }
265
+ }
266
+ /** Mirror of the api's normalization (`normalizeEmailDomain`). */
267
+ function normalizeEmailDomainInput(raw) {
268
+ return raw.trim().toLowerCase().replace(/\.$/, "");
269
+ }
270
+ /**
271
+ * Same DNS-hostname shape the api enforces — checked here so junk fails
272
+ * before a grant is ever requested, not after. Real validation stays the
273
+ * platform's zone lookup.
274
+ */
275
+ function isValidEmailDomainInput(domain) {
276
+ return /^(?!-)[a-z0-9-]{1,63}(?<!-)(\.(?!-)[a-z0-9-]{1,63}(?<!-))+$/.test(domain);
277
+ }
278
+ /**
279
+ * Resolves when Enter is pressed during the clipboard watch. `stop` removes the listener so
280
+ * a losing race cannot eat the first keystroke of a later prompt.
281
+ */
282
+ function createEnterRace(waitForEnter) {
283
+ if (waitForEnter) return {
284
+ promise: waitForEnter().then(() => "enter"),
285
+ stop: () => {}
286
+ };
287
+ const stdin = process.stdin;
288
+ let onData;
289
+ return {
290
+ promise: new Promise((resolve) => {
291
+ if (!stdin.isTTY) return;
292
+ onData = () => resolve("enter");
293
+ stdin.on("data", onData);
294
+ }),
295
+ stop: () => {
296
+ if (onData) stdin.removeListener("data", onData);
297
+ }
298
+ };
299
+ }
300
+ async function defaultPasteToken() {
301
+ const result = await password({
302
+ message: "Paste the Cloudflare API token:",
303
+ mask: "*"
304
+ });
305
+ if (isCancel(result) || typeof result === "symbol") return null;
306
+ return result;
307
+ }
308
+ /**
309
+ * Lost-answer reconcile bounds: attempt-count bounded so the worst case is finite. A lost
310
+ * answer does not stop the API worker, so one immediate status read can 404 while the
311
+ * request is still committing.
312
+ */
313
+ const RECONCILE_ATTEMPTS = 15;
314
+ const RECONCILE_INTERVAL_MS = 1e3;
315
+ /**
316
+ * After an add or rotate request fails without a definitive refusal, poll its operation by
317
+ * attempt id and print it. Returns undefined when the operation never appears.
318
+ */
319
+ async function reconcileEmailOperation(error, client, projectId, attemptId, title, sleep = setTimeout$1) {
320
+ if (error instanceof PlatformApiError && [
321
+ 400,
322
+ 403,
323
+ 404,
324
+ 409
325
+ ].includes(error.status)) throw error;
326
+ for (let attempt = 0; attempt < RECONCILE_ATTEMPTS; attempt++) {
327
+ if (attempt > 0) await sleep(RECONCILE_INTERVAL_MS);
328
+ let operation;
329
+ try {
330
+ operation = await client.getEmailOperation(projectId, attemptId);
331
+ } catch {
332
+ continue;
333
+ }
334
+ note([
335
+ `Operation: ${operation.operationId}`,
336
+ `Status: ${operation.status}`,
337
+ `Inbound: ${operation.readiness.inbound.status}`,
338
+ `Outbound: ${operation.readiness.outbound.status}`,
339
+ `Credential: ${operation.readiness.management.status}`
340
+ ].join("\n"), title);
341
+ return operation;
342
+ }
343
+ }
344
+ async function emailDomainAdd(client, projectId, rawDomain, deps = {}) {
345
+ const exit = deps.exit ?? ((code) => process.exit(code));
346
+ const fail = (message) => {
347
+ log.error(message);
348
+ return exit(1);
349
+ };
350
+ const domain = normalizeEmailDomainInput(rawDomain);
351
+ if (!isValidEmailDomainInput(domain)) return fail(`email: invalid domain '${rawDomain}'.`);
352
+ const dns = deps.dns ?? await createNodeEmailDns();
353
+ const checkApexMx = async (adminProject) => {
354
+ const mx = await probeMx(dns, domain);
355
+ if (mx.state === "unknown") log.info(`MX could not read ${domain}'s MX from here — the platform decides over public DNS.`);
356
+ else if (mx.state === "foreign") fail(`email: ${domain} already receives mail from another provider. Platform custom inbound email requires an unused Cloudflare zone apex; choose another apex or use the platform shared mail address.${adminProject ? ` To only send from ${domain}, ask your administrator to run \`bwf platform email domain-add ${domain} --project ${adminProject} --outbound-only\`.` : ""}`);
357
+ else log.info(`MX using the requested apex ${domain}`);
358
+ };
359
+ let renewal = false;
360
+ const settings = await client.getEmailSettings(projectId);
361
+ if (settings.domains.management === "admin") {
362
+ renewal = (await client.listEmailDomains(projectId)).some((row) => row.domain === domain && row.managed_by !== "admin");
363
+ if (!renewal) {
364
+ const project = settings.domains.projectSlug ?? projectId;
365
+ await checkApexMx(project);
366
+ log.info([
367
+ "Email domains on this platform are managed by its administrator.",
368
+ "Ask them to run:",
369
+ "",
370
+ ` bwf platform email domain-add ${domain} --project ${project}`,
371
+ "",
372
+ "`bwf email domain list` and `bwf email domain status` keep working here."
373
+ ].join("\n"));
374
+ return exit(0);
375
+ }
376
+ }
377
+ if (renewal) log.info(`Updating ${domain} with a scoped credential; the platform will reconcile setup.`);
378
+ else await checkApexMx();
379
+ if (!(deps.isInteractive ?? !isWranglerNonInteractiveOrCI())) return fail("email: `bwf email domain add` needs an interactive terminal to create or paste a scoped Cloudflare API token. Run it locally.");
380
+ let credential;
381
+ {
382
+ log.info(`Create a Cloudflare API token restricted to the account and DNS zone containing ${domain}. In the resource selectors, replace All accounts and All zones with those exact resources. Workers Scripts Write still applies to every Worker in the selected account.`);
383
+ const url = buildCfApiTokenTemplateUrl(domain);
384
+ const readClip = deps.readClipboard ?? readClipboard;
385
+ const clearClip = deps.clearClipboard ?? clearClipboard;
386
+ const verify = deps.verifyToken ?? verifyCfApiToken;
387
+ const openUrl = deps.openUrl ?? openBrowser;
388
+ const snapshot = readClip();
389
+ if (snapshot === null) log.info("No clipboard tool found here — paste the token instead.");
390
+ openUrl(url);
391
+ let outcome;
392
+ let watchSpinner;
393
+ if (snapshot === null) outcome = { type: "timeout" };
394
+ else {
395
+ watchSpinner = createSpinner();
396
+ watchSpinner.start([
397
+ "Create the token in three clicks: Continue to summary → Create Token → Copy.",
398
+ "Watching the clipboard for it — nothing is read until you copy, and it is cleared afterwards.",
399
+ "(Enter pastes it yourself instead.)",
400
+ `If the browser didn't open, visit:\n${import_picocolors.default.blue(formatUrl(url))}`
401
+ ].join("\n"));
402
+ const spinner = watchSpinner;
403
+ const deadline = Date.now() + (deps.watchTimeoutMs ?? 6e5);
404
+ const interval = deps.watchIntervalMs ?? 1e3;
405
+ const snapshotTrimmed = snapshot.trim();
406
+ const enterDuringWatch = createEnterRace(deps.waitForEnter);
407
+ let watchSettled = false;
408
+ let watchTimer;
409
+ outcome = await Promise.race([(async () => {
410
+ while (!watchSettled && Date.now() < deadline) {
411
+ await new Promise((resolve) => {
412
+ watchTimer = setTimeout(resolve, interval);
413
+ });
414
+ if (watchSettled) break;
415
+ const value = readClip()?.trim();
416
+ if (!value || value === snapshotTrimmed) continue;
417
+ const shape = classifyCfApiTokenShape(value);
418
+ if (shape === "refused" || shape === "unknown") continue;
419
+ const verdict = await verify(value);
420
+ if (verdict === "inactive") {
421
+ spinner.message("That is not an active Cloudflare token — still waiting.");
422
+ continue;
423
+ }
424
+ if (verdict === "unknown") log.info("Could not reach Cloudflare to check the token — the platform will verify it.");
425
+ return {
426
+ type: "token",
427
+ token: value
428
+ };
429
+ }
430
+ return { type: "timeout" };
431
+ })(), enterDuringWatch.promise.then(() => ({ type: "enter" }))]);
432
+ watchSettled = true;
433
+ enterDuringWatch.stop();
434
+ watchTimer?.unref();
435
+ }
436
+ if (outcome.type === "token") {
437
+ clearClip();
438
+ watchSpinner?.stop("Token received — the clipboard copy was cleared.");
439
+ log.info("A clipboard manager may keep its own history — clear it there if you run one.");
440
+ credential = {
441
+ kind: "api_token",
442
+ apiToken: outcome.token
443
+ };
444
+ } else {
445
+ watchSpinner?.stop(outcome.type === "enter" ? "Pasting instead." : "No token arrived — paste it instead.");
446
+ const pasted = await (deps.pasteToken ?? defaultPasteToken)();
447
+ if (pasted === null) {
448
+ log.info("Cancelled — nothing was stored anywhere.");
449
+ return;
450
+ }
451
+ const token = pasted.trim();
452
+ const shape = classifyCfApiTokenShape(token);
453
+ if (shape === "refused") return fail("email: that looks like a different kind of token (a GitHub, OpenAI, Slack, or Cloudflare global key) — the link above creates a scoped Cloudflare API token.");
454
+ if (shape === "unknown") return fail("email: that is not shaped like a Cloudflare API token (`cfut_…` or the legacy 40-character form). Create one from the link above.");
455
+ const verdict = await verify(token);
456
+ if (verdict === "inactive") return fail("email: that is not an active Cloudflare token.");
457
+ if (verdict === "unknown") log.info("Could not reach Cloudflare to check the token — the platform will verify it.");
458
+ credential = {
459
+ kind: "api_token",
460
+ apiToken: token
461
+ };
462
+ }
463
+ }
464
+ if (!await (deps.confirmScope ?? (async (name) => {
465
+ const answer = await confirm({
466
+ message: `Is this token restricted to the Cloudflare account and DNS zone containing ${name}?`,
467
+ initialValue: false
468
+ });
469
+ return !isCancel(answer) && answer === true;
470
+ }))(domain)) return fail("email: restrict the token to the selected account and zone before adding the domain. Nothing was submitted to the platform.");
471
+ const attemptId = crypto.randomUUID();
472
+ log.info(`Setup operation: ${attemptId}`);
473
+ let row;
474
+ try {
475
+ row = await client.addEmailDomain(projectId, {
476
+ domain,
477
+ apiToken: credential.apiToken,
478
+ attemptId
479
+ });
480
+ } catch (error) {
481
+ const operation = await reconcileEmailOperation(error, client, projectId, attemptId, "Email Setup", deps.sleep);
482
+ if (!operation) return fail(`email: setup outcome is unknown (operation ${attemptId}). Nothing was revoked. Check \`bwf email domain status ${domain}\` before starting another setup.`);
483
+ if (operation.error) log.error(operation.error);
484
+ log.info(`Run \`bwf email domain status ${domain}\` to inspect setup.`);
485
+ if (operation.status === "completed") {
486
+ printSuccess(`Email domain ${domain} configured.`);
487
+ return;
488
+ }
489
+ return fail(`email: setup is ${operation.status}; operation ${operation.operationId} retains its confirmed progress on the platform.`);
490
+ }
491
+ log.info("Token stored encrypted on the platform for this zone connection — nothing is kept on this machine.");
492
+ printEmailDomainOutcome(row);
493
+ if (row.operationStatus !== "completed") return exit(1);
494
+ printSuccess(`Email domain ${row.domain} configured.`);
495
+ }
496
+ function emailDomainStatusText(status) {
497
+ if (status === "ready") return import_picocolors.default.green("ready");
498
+ if (status === "pending") return import_picocolors.default.yellow("pending");
499
+ return status === "disabled" ? import_picocolors.default.yellow("disabled") : import_picocolors.default.red(status);
500
+ }
501
+ function printEmailDomainOutcome(row, projectRef) {
502
+ const lines = [
503
+ `Domain: ${row.domain}`,
504
+ `Managed by: ${row.managed_by === "admin" ? "administrator" : "project owner"}`,
505
+ ...Object.entries(row.readiness).map(([name, value]) => `${name.padEnd(12)} ${value.status}${value.reason ? " — " + value.reason : ""}${value.observedAt ? " (" + value.observedAt + ")" : ""}`)
506
+ ];
507
+ if (row.operationId) lines.push(`Operation: ${row.operationId}${row.operationStatus ? " · " + row.operationStatus : ""}`);
508
+ note(lines.join("\n"), "Email Domain");
509
+ if (row.error) log.error(row.error);
510
+ if (row.operationStatus === "unknown") {
511
+ log.warn(`Operation ${row.operationId} has an unknown outcome; inspect its status before retrying.`);
512
+ return;
513
+ }
514
+ if (row.readiness.management.status === "expired" || row.readiness.management.status === "revoked") log.info(row.managed_by === "admin" ? `Ask your administrator to run \`bwf platform email domain-add ${row.domain} --project ${projectRef ?? row.projectId}\` with a renewed credential.` : `Run \`bwf email domain add ${row.domain}\` with a new scoped API token.`);
515
+ else if (row.readiness.inbound.status === "pending" || row.readiness.inbound.status === "drifted") log.info(row.managed_by === "admin" ? `Ask your administrator to run \`bwf platform email domain-sync ${row.domain}\` to reconcile setup.` : `Run \`bwf email domain sync ${row.domain}\` to reconcile setup.`);
516
+ }
517
+ async function emailDomainStatus(client, projectId, rawDomain) {
518
+ const domain = normalizeEmailDomainInput(rawDomain);
519
+ const row = await client.getEmailDomain(projectId, domain);
520
+ printEmailDomainOutcome(row, row.managed_by === "admin" ? (await client.getEmailSettings(projectId)).domains.projectSlug ?? projectId : void 0);
521
+ }
522
+ async function emailDomainList(client, projectId) {
523
+ const rows = await client.listEmailDomains(projectId);
524
+ if (rows.length === 0) {
525
+ log.info("No email domains. Run `bwf email domain add <domain>` to send and receive at your own domain on a Cloudflare zone.");
526
+ return;
527
+ }
528
+ const width = Math.max(...rows.map((row) => row.domain.length));
529
+ const lines = rows.map((row) => ` ${row.domain.padEnd(width)} ${emailDomainStatusText(row.status)} ${row.managed_by === "admin" ? "administrator" : "project owner"}`);
530
+ note(lines.join("\n"), "Email Domains");
531
+ }
532
+ async function emailDomainSync(client, projectId, rawDomain) {
533
+ const domain = normalizeEmailDomainInput(rawDomain);
534
+ const row = await client.syncEmailDomain(projectId, domain);
535
+ printEmailDomainOutcome(row);
536
+ if (row.operationStatus !== "completed") throw new Error(`email: reconciliation ${row.operationStatus ?? "pending"}; inspect operation ${row.operationId ?? row.domain}`);
537
+ printSuccess(`Email domain ${domain} reconciled.`);
538
+ }
539
+ /** Rotation applies to every domain sharing this zone connection. */
540
+ async function emailDomainRotateSecret(client, projectId, rawDomain, deps = {}) {
541
+ const domain = normalizeEmailDomainInput(rawDomain);
542
+ const attemptId = crypto.randomUUID();
543
+ let row;
544
+ try {
545
+ row = await client.rotateEmailDomainSecret(projectId, domain, attemptId);
546
+ } catch (error) {
547
+ const operation = await reconcileEmailOperation(error, client, projectId, attemptId, "Email Secret Rotation", deps.sleep);
548
+ if (!operation) throw new Error(`email: secret rotation outcome is unknown (operation key ${attemptId}); inspect \`bwf email domain status ${domain}\` before starting another rotation.`);
549
+ if (operation.status !== "completed") throw new Error(`email: secret rotation ${operation.status}; inspect operation ${operation.operationId}`);
550
+ printSuccess("Zone ingress secret rotated and verified on the deployed Worker.");
551
+ return;
552
+ }
553
+ printEmailDomainOutcome(row);
554
+ if (row.operationStatus !== "completed") throw new Error(`email: secret rotation ${row.operationStatus ?? "pending"}; inspect operation ${row.operationId ?? row.domain}`);
555
+ printSuccess("Zone ingress secret rotated and verified on the deployed Worker.");
556
+ }
557
+ async function emailDomainRemove(client, projectId, rawDomain, options = {}) {
558
+ const domain = normalizeEmailDomainInput(rawDomain);
559
+ const result = await client.removeEmailDomain(projectId, domain);
560
+ log.info(`Operation: ${result.operationId} · ${result.operationStatus ?? "pending"}`);
561
+ if (!result.removed || result.operationStatus !== "completed") {
562
+ log.error(result.error ?? "Email cleanup is not complete. Its operation and resources remain recorded for reconciliation.");
563
+ (options.exit ?? ((code) => process.exit(code)))(1);
564
+ return;
565
+ }
566
+ printSuccess(`Removed ${domain}. Zone resources still used by other domains were retained.`);
567
+ }
568
+ async function runEmailDomainCommand(client, projectId, args) {
569
+ switch (args.domainVerb) {
570
+ case "add": return emailDomainAdd(client, projectId, args.domain);
571
+ case "status": return emailDomainStatus(client, projectId, args.domain);
572
+ case "list": return emailDomainList(client, projectId);
573
+ case "sync": return emailDomainSync(client, projectId, args.domain);
574
+ case "rotate-secret": return emailDomainRotateSecret(client, projectId, args.domain);
575
+ case "remove": return emailDomainRemove(client, projectId, args.domain);
576
+ }
577
+ }
578
+ /**
579
+ * Wrangler finds config by walking parent directories, so an app with no root config runs in
580
+ * an empty temporary one; otherwise an unrelated ancestor config could select the wrong account.
581
+ */
582
+ function createEmailWranglerConfigContext(configPath) {
583
+ if (existsSync(configPath)) return {
584
+ path: configPath,
585
+ cleanup: () => {}
586
+ };
587
+ const directory = mkdtempSync(join(tmpdir(), "nosam-email-wrangler-"));
588
+ const path = join(directory, "wrangler.jsonc");
589
+ try {
590
+ writeFileSync(path, "{}\n", {
591
+ encoding: "utf8",
592
+ flag: "wx",
593
+ mode: 384
594
+ });
595
+ } catch (error) {
596
+ rmSync(directory, {
597
+ recursive: true,
598
+ force: true
599
+ });
600
+ throw error;
601
+ }
602
+ return {
603
+ path,
604
+ cleanup: () => rmSync(directory, {
605
+ recursive: true,
606
+ force: true
607
+ })
608
+ };
609
+ }
610
+ /**
611
+ * `bwf email setup|status --platform cloudflare`.
612
+ *
613
+ * `setup` runs the deploy's email step on its own: preflight, checklist, one confirmation,
614
+ * apply, then a write of the generated Cloudflare config and bwf.lock.json. A CI deploy that
615
+ * finds email not ready says to run it once locally, commit bwf.lock.json, and redeploy; the
616
+ * next deploy creates the routing rules from `addresses`. It is also the only place that
617
+ * retries a sending onboarding the committed binding records as refused (Workers Free).
618
+ *
619
+ * `status` prints the preflight and exits 1 when email is not ready.
620
+ */
621
+ async function runEmailCloudflareCommand(root, args, deps = {}) {
622
+ const rawExit = deps.exit ?? ((code) => process.exit(code));
623
+ const from = readConfig(root).email?.from;
624
+ if (!from) {
625
+ log.error("email: no sender configured. Set email.from to \"you@mail.acme.com\" in bwf.config.ts — its host is the domain email is set up on.");
626
+ return rawExit(1);
627
+ }
628
+ const paths = readProjectPaths(root);
629
+ const handlers = scanEmailHandlersSync(paths.sourceRoot);
630
+ const configPath = discoverRootWranglerConfig(root);
631
+ const wranglerConfig = createEmailWranglerConfigContext(configPath);
632
+ try {
633
+ return await runEmailCloudflareCommandInConfig(root, args, {
634
+ from,
635
+ handlers
636
+ }, configPath, wranglerConfig.path, {
637
+ ...deps,
638
+ exit: (code) => {
639
+ wranglerConfig.cleanup();
640
+ return rawExit(code);
641
+ }
642
+ });
643
+ } finally {
644
+ wranglerConfig.cleanup();
645
+ }
646
+ }
647
+ async function runEmailCloudflareCommandInConfig(root, args, project, configPath, wranglerConfigPath, deps) {
648
+ const exit = deps.exit ?? ((code) => process.exit(code));
649
+ const print = deps.print ?? ((block) => log.message(block));
650
+ const fail = (message) => {
651
+ log.error(message);
652
+ return exit(1);
653
+ };
654
+ const { from, handlers } = project;
655
+ const rootConfig = parseRootWranglerConfig(configPath);
656
+ let apiBaseUrl;
657
+ try {
658
+ apiBaseUrl = resolveDeployTransport(root, rootConfig);
659
+ } catch (err) {
660
+ return fail(`email: ${err instanceof Error ? err.message : String(err)}`);
661
+ }
662
+ const accountId = readWranglerTopLevelString(rootConfig, "account_id") ?? (process.env.CLOUDFLARE_ACCOUNT_ID?.trim() || void 0);
663
+ if (!accountId) return fail([
664
+ "email: no Cloudflare account is pinned.",
665
+ "Set `cloudflare.account_id` in bwf.config.ts, or export CLOUDFLARE_ACCOUNT_ID —",
666
+ "the same pin `bwf deploy --platform cloudflare` needs."
667
+ ].join("\n"));
668
+ const workerName = readWranglerTopLevelString(rootConfig, "name") ?? deriveWorkerName(root);
669
+ const runWrangler = deps.runWrangler ?? createDeployWranglerRunner(root, accountId, apiBaseUrl);
670
+ const getSessionBearer = deps.getSessionBearer ?? (() => runWranglerAuthToken(runWrangler, wranglerConfigPath));
671
+ const inputs = {
672
+ handlers,
673
+ from,
674
+ workerName,
675
+ accountId,
676
+ ...emailConfigInputs(rootConfig),
677
+ configPath: wranglerConfigPath,
678
+ apiBaseUrl,
679
+ runWrangler,
680
+ getSessionBearer,
681
+ fetchImpl: deps.fetchImpl ?? fetch,
682
+ dns: deps.dns ?? await createNodeEmailDns()
683
+ };
684
+ let pre;
685
+ try {
686
+ pre = await preflightEmail(inputs);
687
+ } catch (err) {
688
+ return fail(`email: ${err instanceof Error ? err.message : String(err)}`);
689
+ }
690
+ print(renderEmailChecklist(pre));
691
+ if (args.subcommand === "status") {
692
+ print(renderAddressMap({
693
+ from,
694
+ routes: pre.derived.routes,
695
+ addresses: pre.rules.mine,
696
+ sendingReady: pre.sending.state === "ready",
697
+ pendingLabel: "(no rule yet)"
698
+ }));
699
+ if (pre.ready) {
700
+ log.info(`Email is set up on ${pre.domain}.`);
701
+ return;
702
+ }
703
+ log.warn(`Email is not set up on ${pre.domain} yet — run \`bwf email setup --platform cloudflare\`.`);
704
+ return exit(1);
705
+ }
706
+ if (pre.blockers.some((b) => b.scope === "all")) return fail("email: nothing was changed — fix the ✘ rows above and rerun.");
707
+ if (!pre.ready || pre.sendingRetryable) {
708
+ if (!(deps.isInteractive ?? !isWranglerNonInteractiveOrCI())) return fail("email: `bwf email setup` changes your Cloudflare account, so it needs an interactive terminal. Run it locally once, commit bwf.lock.json, then redeploy.");
709
+ if (!await (deps.confirm ?? (async (message) => {
710
+ const answer = await confirm({
711
+ message,
712
+ initialValue: true
713
+ });
714
+ return !isCancel(answer) && answer === true;
715
+ }))(pre.ready ? `Onboard ${pre.domain} for Email Sending? Inbound already works; onboarding needs Workers Paid.` : `Set up email on ${pre.domain}?`)) {
716
+ log.info("Nothing changed.");
717
+ return;
718
+ }
719
+ }
720
+ const out = await applyEmailSetup(pre, inputs);
721
+ if (out.lines.length > 0) print(out.lines.join("\n"));
722
+ try {
723
+ writeProvisionedWranglerConfig(root, out.patch, { configPath });
724
+ } catch (err) {
725
+ return fail(`email: could not update ${configPath} — ${err instanceof Error ? err.message : String(err)}`);
726
+ }
727
+ print(renderAddressMap({
728
+ from,
729
+ routes: pre.derived.routes,
730
+ addresses: out.patch.addresses ?? [],
731
+ sendingReady: out.sendingReady,
732
+ pendingLabel: "(no rule yet)"
733
+ }));
734
+ if (!out.inboundReady) {
735
+ const missing = !out.routingReady ? `Email Routing on ${pre.domain} is not ready` : !out.subaddressingReady ? `subaddressing on ${pre.apex} is still off (support+anything@ would not reach support@)` : "`addresses` was withheld";
736
+ log.warn(`Email is not set up on ${pre.domain} yet — ${missing}; no routing rule is created until it is. Finish the step above, then rerun \`bwf email setup --platform cloudflare\`.`);
737
+ return exit(1);
738
+ }
739
+ if ((out.patch.addresses ?? []).length > 0) log.info("Routing rules are created by the next `bwf deploy --platform cloudflare`, which applies the Email Routing plan from `addresses`.");
740
+ printSuccess(`Email set up on ${pre.domain}.`);
741
+ }
742
+ export { runEmailCommand };