void 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/README.md +5 -1
  2. package/dist/{account-cmd-CjyxcGkM.mjs → account-cmd-C84Ee8cO.mjs} +4 -4
  3. package/dist/{scan-ClYmX3sa.mjs → application-analysis-BVsVqc11.mjs} +135 -18
  4. package/dist/application-routing-B7QEjqSR.mjs +27 -0
  5. package/dist/{auth-CZuiVsFh.mjs → auth-CCjt0hcq.mjs} +1 -1
  6. package/dist/{auth-DLNN0D3Z.mjs → auth-CSkdO2Bb.mjs} +4 -47
  7. package/dist/{auth-link-BLO4ptzo.mjs → auth-link-CioEg6uY.mjs} +4 -4
  8. package/dist/{auth-router-ZUg9MF_U.mjs → auth-router-BsR981d4.mjs} +4 -4
  9. package/dist/{better-auth-shared-rsBGBvWJ.mjs → better-auth-shared-hy6RPh9W.mjs} +13 -2
  10. package/dist/{build-cmd-BxR5FROK.mjs → build-cmd-LzvNJORH.mjs} +17 -5
  11. package/dist/{cache-D0sWhgKI.mjs → cache-C4MvnrMH.mjs} +2 -2
  12. package/dist/{cancel-deploy-D4NUqFbi.mjs → cancel-deploy-abUxpP2n.mjs} +2 -2
  13. package/dist/{cf-build-output-BJ6yGEIS.mjs → cf-build-output-BPqOT964.mjs} +2 -1
  14. package/dist/cf-build-output-_0HNWysu.mjs +2 -0
  15. package/dist/cli/cli.mjs +80 -455
  16. package/dist/cli/{cf-compat.mjs → cloudflare-operation-process.mjs} +442 -421
  17. package/dist/cli/env-schema-probe.d.mts +2 -1
  18. package/dist/cli/env-schema-probe.mjs +3 -3
  19. package/dist/client-Cu7jWiF1.mjs +2 -0
  20. package/dist/{client-BTZ3XkrB.mjs → client-RV8NVeB8.mjs} +140 -21
  21. package/dist/{cloudflare-auth-DQkqoMYa.mjs → cloudflare-auth-Qdc7tw8F.mjs} +41 -38
  22. package/dist/{cloudflare-cmd-BKlfGHAy.mjs → cloudflare-cmd-BcrVyTmJ.mjs} +5 -5
  23. package/dist/cloudflare-config-Bktvwtpf.mjs +182 -0
  24. package/dist/{cloudflare-connect-Ctmrw579.mjs → cloudflare-connect-B8uPZ4nx.mjs} +3 -3
  25. package/dist/{cloudflare-operations-BT6OWFBk.mjs → cloudflare-operations-AiWashgg.mjs} +1 -1
  26. package/dist/{cloudflare-operations-B9tzgjmf.mjs → cloudflare-operations-fxHb-byx.mjs} +116 -172
  27. package/dist/{preset-UHj9ARyP.mjs → cloudflare-process-B-wekeR6.mjs} +93 -6
  28. package/dist/{config-VavjpDnp.d.mts → config-BMHb8RCj.d.mts} +1 -0
  29. package/dist/config-C_XRIPx2.mjs +89 -0
  30. package/dist/config-entry.d.mts +1 -1
  31. package/dist/{connect-Dg-WkW-C.mjs → connect-Bd4kJd9U.mjs} +5 -5
  32. package/dist/{create-project-DdoqwFLF.mjs → create-project-Boczwj5r.mjs} +1 -1
  33. package/dist/{create-project-l9J7pbtm.mjs → create-project-bMf6ffLZ.mjs} +2 -2
  34. package/dist/{db-gp2sCXyN.mjs → db-8uG64XLl.mjs} +21 -21
  35. package/dist/{delete-TTedbH6B.mjs → delete-NvbiyeJf.mjs} +2 -2
  36. package/dist/{deploy-CH-o2CaZ.mjs → deploy-DzAIwqNU.mjs} +908 -582
  37. package/dist/{deploy-B19L2Bra.mjs → deploy-bjXdFCtn.mjs} +1 -1
  38. package/dist/{domain-JRF59P_r.mjs → domain-y5Tvydvo.mjs} +3 -3
  39. package/dist/{email-Bo6G9LOZ.mjs → email-B3umsW75.mjs} +13 -28
  40. package/dist/{env-BYOrWQnv.mjs → env-BS6qYHDb.mjs} +4 -4
  41. package/dist/{env-public-BxU_0yTL.d.mts → env-public-BX_r8HR6.d.mts} +1 -1
  42. package/dist/{env-validation-BB4GkLxn.mjs → env-validation-BPn7vk-V.mjs} +18 -71
  43. package/dist/{env-validation-BXge7uyK.mjs → env-validation-DbTg7-ar.mjs} +1 -1
  44. package/dist/{fetch-CXDChK7B.mjs → fetch-BIZJh7vR.mjs} +2 -2
  45. package/dist/{fetch-stream-AOByI7Ki.mjs → fetch-stream-IvCYKyQL.mjs} +24 -4
  46. package/dist/{gen-sCtlCOdA.mjs → gen-B580--vC.mjs} +2 -2
  47. package/dist/gen-BVaUUumi.mjs +2 -0
  48. package/dist/{github-cmd-0-7PexDq.mjs → github-cmd-v45BdfKX.mjs} +2 -2
  49. package/dist/{handler-HEcZsaij.d.mts → handler-CZ4nAylQ.d.mts} +1 -1
  50. package/dist/help-DofyZuY7.mjs +2 -0
  51. package/dist/{help-GKtwl07I.mjs → help-daGKjXGk.mjs} +229 -747
  52. package/dist/index.d.mts +1 -1
  53. package/dist/index.mjs +288 -1502
  54. package/dist/info-B97bTX9N.mjs +113 -0
  55. package/dist/{init-FZx3Elvz.mjs → init-Bvy7zrBo.mjs} +46 -15
  56. package/dist/limits-Bq5LG8Id.d.mts +27 -0
  57. package/dist/limits-Cjuk2VPm.mjs +68 -0
  58. package/dist/{link-BrQfb_CU.mjs → link-CDqqCjFl.mjs} +3 -3
  59. package/dist/{list-D44jmIAM.mjs → list-CZj0dzKY.mjs} +3 -3
  60. package/dist/{live-CKJlvlNp.d.mts → live-Chw1eIMv.d.mts} +1 -1
  61. package/dist/{local-d1-Bg9OzEEO.mjs → local-d1-2CMnpuW_.mjs} +2 -2
  62. package/dist/login-DYt_An22.mjs +2 -0
  63. package/dist/{login-CAsAsQ-_.mjs → login-UZKFM_u7.mjs} +3 -3
  64. package/dist/{logs-BjKvFnVM.mjs → logs-CUZ6t9t3.mjs} +3 -3
  65. package/dist/migrate-8_2u55MD.mjs +2 -0
  66. package/dist/{migrate-BPITvDJN.mjs → migrate-DHul7PRV.mjs} +2 -1
  67. package/dist/{node-Dt7z256D.mjs → node-BkyRWRx8.mjs} +1 -1
  68. package/dist/operator-args-CLgKGlwU.mjs +690 -0
  69. package/dist/{operator-cmd-BK5CCiT9.mjs → operator-cmd-DBA6dl0m.mjs} +68 -22
  70. package/dist/pages/client.d.mts +34 -2
  71. package/dist/pages/client.mjs +59 -3
  72. package/dist/pages/index.d.mts +1 -1
  73. package/dist/pages/index.mjs +1 -1
  74. package/dist/pages/islands-plugin.mjs +1 -1
  75. package/dist/pages/protocol.d.mts +2 -2
  76. package/dist/pages/protocol.mjs +2 -308
  77. package/dist/{parse-filename-DioPHiR9.mjs → parse-filename-CUbj-1MP.mjs} +35 -1
  78. package/dist/plan-D1Q5rf-r.mjs +2 -0
  79. package/dist/plan-NPpwZ_kc.mjs +58 -0
  80. package/dist/platform-args-BJdRtlLq.mjs +506 -0
  81. package/dist/platform-args-D3RXyR6h.mjs +2 -0
  82. package/dist/{platform-auth-config-BlN8xTdD.mjs → platform-auth-config-B56E9YP1.mjs} +3 -3
  83. package/dist/{platform-auth-protection-7d5aV2Jg.mjs → platform-auth-protection-BDWO_aER.mjs} +2 -2
  84. package/dist/{platform-auth-recovery-Dxij8ZbR.mjs → platform-auth-recovery-1gg4CSRe.mjs} +3 -3
  85. package/dist/{platform-cmd-E0FuL212.mjs → platform-cmd-Bt-1w6pY.mjs} +1 -1
  86. package/dist/{platform-cmd-B3hwKrFK.mjs → platform-cmd-DMcQStSc.mjs} +24 -3
  87. package/dist/{platform-domain-D6Xcy9ZX.mjs → platform-domain-BNkcz0OB.mjs} +2 -2
  88. package/dist/{platform-lifecycle-k0E0xoxx.mjs → platform-lifecycle-9OyBALhH.mjs} +327 -215
  89. package/dist/{platform-lifecycle-DMh_qrry.mjs → platform-lifecycle-BE6C_jxh.mjs} +1 -1
  90. package/dist/{platform-management-Brz_BDiT.mjs → platform-management-CjwLVQwN.mjs} +6 -3
  91. package/dist/{platform-management-DOtss0BN.mjs → platform-management-CnyTdcWX.mjs} +1 -1
  92. package/dist/platform-plans-config-BNGKGr4P.mjs +359 -0
  93. package/dist/{platform-recovery-BvtcXON5.mjs → platform-recovery-D6KSpuFm.mjs} +2 -2
  94. package/dist/{plugin-inference-BMfKRSqE.mjs → plugin-inference-CXWnn79A.mjs} +174 -64
  95. package/dist/{prepare-C-6YZyyg.mjs → prepare-B5Mkic5u.mjs} +1 -1
  96. package/dist/{prepare-CRhJbVrG.mjs → prepare-DOsL0CC9.mjs} +4 -20
  97. package/dist/prepare-cgvDMtSb.mjs +2 -0
  98. package/dist/{project-cmd-BZLCqOqw.mjs → project-cmd-CNzrqvBv.mjs} +16 -16
  99. package/dist/{project-team-BvgM0WoX.mjs → project-team-DQOWPfQT.mjs} +2 -2
  100. package/dist/{project-token-l5DqK6Az.mjs → project-token-CTDYU0Cc.mjs} +2 -2
  101. package/dist/{project-zero-trust-v6Mvpp8y.mjs → project-zero-trust-BNAkW-_0.mjs} +2 -2
  102. package/dist/{protocol-BBa6cstI.d.mts → protocol-CjF_iI9X.d.mts} +2 -2
  103. package/dist/protocol-U7bfjHmA.mjs +331 -0
  104. package/dist/{provision-Fr9pRqce.mjs → provision-C4ORE7G7.mjs} +1 -1
  105. package/dist/{provision-C4IGqkBf.mjs → provision-CJFgTZY8.mjs} +89 -198
  106. package/dist/{requests-DN-BbNiM.mjs → requests-MhxYnau8.mjs} +2 -2
  107. package/dist/resource-name-C7LVpcRm.mjs +11 -0
  108. package/dist/{rollback-D7rzSaZM.mjs → rollback-CJ6iSDoU.mjs} +3 -3
  109. package/dist/route-url-CG7U-cRN.mjs +15 -0
  110. package/dist/{runner-B8wXwWlo.mjs → runner-CXA9Fh8h.mjs} +1 -1
  111. package/dist/{runner-p-dMs2UN.mjs → runner-Ol0TNjk6.mjs} +2 -2
  112. package/dist/runtime/ai.d.mts +12 -8
  113. package/dist/runtime/ai.mjs +84 -17
  114. package/dist/runtime/better-auth-mysql.mjs +1 -1
  115. package/dist/runtime/better-auth-pg.mjs +1 -1
  116. package/dist/runtime/better-auth.mjs +1 -1
  117. package/dist/runtime/client-react.mjs +2 -2
  118. package/dist/runtime/client-solid.mjs +2 -2
  119. package/dist/runtime/client-svelte.mjs +2 -2
  120. package/dist/runtime/client-vue.mjs +2 -2
  121. package/dist/runtime/client.mjs +2 -2
  122. package/dist/runtime/durable.d.mts +3 -1
  123. package/dist/runtime/durable.mjs +4 -1
  124. package/dist/runtime/email/testing.mjs +1 -1
  125. package/dist/runtime/env-public.d.mts +1 -1
  126. package/dist/runtime/fetch-stream.mjs +1 -1
  127. package/dist/runtime/fetch.mjs +1 -1
  128. package/dist/runtime/handler.d.mts +1 -1
  129. package/dist/runtime/kv.mjs +0 -1
  130. package/dist/runtime/limits.d.mts +2 -0
  131. package/dist/runtime/limits.mjs +2 -0
  132. package/dist/runtime/live-client.d.mts +1 -1
  133. package/dist/runtime/live-server.mjs +25 -16
  134. package/dist/runtime/live.d.mts +1 -1
  135. package/dist/runtime/migration-handler.mjs +62 -42
  136. package/dist/runtime/route-url.d.mts +4 -0
  137. package/dist/runtime/route-url.mjs +2 -0
  138. package/dist/runtime/routing.d.mts +180 -0
  139. package/dist/runtime/routing.mjs +1082 -0
  140. package/dist/runtime/sandbox-container.d.mts +1 -1
  141. package/dist/runtime/sandbox-container.mjs +1 -1
  142. package/dist/runtime/sandbox.d.mts +3 -3
  143. package/dist/runtime/sandbox.mjs +75 -45
  144. package/dist/runtime/sse.mjs +1 -1
  145. package/dist/runtime/validator.d.mts +1 -1
  146. package/dist/runtime/ws-server.d.mts +4 -2
  147. package/dist/runtime/ws-server.mjs +27 -2
  148. package/dist/runtime/ws.d.mts +2 -2
  149. package/dist/runtime/ws.mjs +8 -6
  150. package/dist/{sandbox-qpNBT8a3.d.mts → sandbox-XZAqzFlG.d.mts} +11 -8
  151. package/dist/{sandbox-container-DdNEBfCc.d.mts → sandbox-container-Bo0eiFKz.d.mts} +2 -1
  152. package/dist/{sandbox-container-4fdqLnyb.mjs → sandbox-container-C6ItmVuN.mjs} +4 -2
  153. package/dist/{scan-4tfN-PSn.mjs → scan-C7okrLyM.mjs} +4 -35
  154. package/dist/{secret-BOtOl_cb.mjs → secret-Dli5fP0B.mjs} +4 -4
  155. package/dist/{sse-BaC1jXko.mjs → sse-CQNaDFFV.mjs} +6 -3
  156. package/dist/validate-Dq_L3s0S.mjs +2 -0
  157. package/dist/{validate-CIUwFpjB.mjs → validate-ctOrgiS3.mjs} +2 -1
  158. package/dist/{wrangler-DQF1vKyf.mjs → wrangler-7K-bW_DL.mjs} +8 -239
  159. package/dist/{ws-BoY7vQML.d.mts → ws-CL1w7GXU.d.mts} +13 -2
  160. package/package.json +15 -8
  161. package/skills/migrate-vite-cloudflare-to-void/SKILL.md +34 -157
  162. package/skills/void/SKILL.md +50 -135
  163. package/skills/void/docs/guide/ai.md +94 -84
  164. package/skills/void/docs/guide/app-types.md +3 -32
  165. package/skills/void/docs/guide/auth.md +12 -116
  166. package/skills/void/docs/guide/database/d1.md +9 -54
  167. package/skills/void/docs/guide/database/mysql.md +1 -1
  168. package/skills/void/docs/guide/database/postgresql.md +5 -26
  169. package/skills/void/docs/guide/database.md +23 -75
  170. package/skills/void/docs/guide/deployment.md +27 -113
  171. package/skills/void/docs/guide/durable-state.md +43 -18
  172. package/skills/void/docs/guide/edge/headers.md +3 -47
  173. package/skills/void/docs/guide/edge/prerendering.md +5 -20
  174. package/skills/void/docs/guide/edge/redirects.md +11 -64
  175. package/skills/void/docs/guide/edge/revalidation.md +5 -18
  176. package/skills/void/docs/guide/edge/rewrites.md +56 -284
  177. package/skills/void/docs/guide/edge/static-assets.md +22 -72
  178. package/skills/void/docs/guide/email/domains.md +112 -0
  179. package/skills/void/docs/guide/email/receiving.md +139 -0
  180. package/skills/void/docs/guide/email/sending.md +231 -0
  181. package/skills/void/docs/guide/email.md +13 -619
  182. package/skills/void/docs/guide/env-migration.md +11 -11
  183. package/skills/void/docs/guide/env-vars.md +9 -29
  184. package/skills/void/docs/guide/index.md +0 -15
  185. package/skills/void/docs/guide/jobs.md +3 -18
  186. package/skills/void/docs/guide/kv.md +5 -11
  187. package/skills/void/docs/guide/live.md +5 -56
  188. package/skills/void/docs/guide/pages-routing/actions-and-forms.md +78 -125
  189. package/skills/void/docs/guide/pages-routing/head.md +10 -10
  190. package/skills/void/docs/guide/pages-routing/islands.md +6 -36
  191. package/skills/void/docs/guide/pages-routing/layouts.md +6 -128
  192. package/skills/void/docs/guide/pages-routing/loaders.md +3 -19
  193. package/skills/void/docs/guide/pages-routing/markdown.md +13 -171
  194. package/skills/void/docs/guide/pages-routing/overview.md +7 -17
  195. package/skills/void/docs/guide/pages-routing/view-transitions.md +1 -1
  196. package/skills/void/docs/guide/platform/administration/access.md +1 -4
  197. package/skills/void/docs/guide/platform/administration/email.md +35 -8
  198. package/skills/void/docs/guide/platform/administration/operations.md +26 -4
  199. package/skills/void/docs/guide/platform/administration/plans.md +126 -0
  200. package/skills/void/docs/guide/platform/administration/projects.md +5 -2
  201. package/skills/void/docs/guide/platform/administration/zero-trust.md +23 -152
  202. package/skills/void/docs/guide/platform/development/runtime.md +3 -13
  203. package/skills/void/docs/guide/platform/development/schema-ci.md +0 -58
  204. package/skills/void/docs/guide/platform/installation/credentials.md +6 -4
  205. package/skills/void/docs/guide/platform/installation/domains.md +30 -2
  206. package/skills/void/docs/guide/platform/installation/first-deployment.md +2 -0
  207. package/skills/void/docs/guide/platform/installation/maintenance.md +3 -1
  208. package/skills/void/docs/guide/platform/installation/prerequisites.md +20 -15
  209. package/skills/void/docs/guide/platform/installation/setup.md +9 -5
  210. package/skills/void/docs/guide/platform-administration.md +1 -0
  211. package/skills/void/docs/guide/queues.md +7 -9
  212. package/skills/void/docs/guide/quickstart.md +38 -37
  213. package/skills/void/docs/guide/remote-dev.md +4 -9
  214. package/skills/void/docs/guide/sandboxes.md +29 -21
  215. package/skills/void/docs/guide/server-routing.md +9 -72
  216. package/skills/void/docs/guide/sse.md +4 -18
  217. package/skills/void/docs/guide/ssg.md +3 -15
  218. package/skills/void/docs/guide/ssr.md +14 -62
  219. package/skills/void/docs/guide/storage.md +9 -4
  220. package/skills/void/docs/guide/type-safety.md +3 -14
  221. package/skills/void/docs/guide/typed-fetch.md +3 -7
  222. package/skills/void/docs/guide/websockets.md +68 -40
  223. package/skills/void/docs/integrations/agents.md +3 -3
  224. package/skills/void/docs/integrations/cloudflare.md +85 -316
  225. package/skills/void/docs/integrations/frameworks/analog.md +5 -64
  226. package/skills/void/docs/integrations/frameworks/astro.md +4 -73
  227. package/skills/void/docs/integrations/frameworks/nuxt.md +5 -62
  228. package/skills/void/docs/integrations/frameworks/overview.md +11 -54
  229. package/skills/void/docs/integrations/frameworks/react-router.md +5 -60
  230. package/skills/void/docs/integrations/frameworks/sveltekit.md +6 -65
  231. package/skills/void/docs/integrations/frameworks/tanstack-start.md +4 -62
  232. package/skills/void/docs/integrations/nodejs-bun-deno.md +5 -69
  233. package/skills/void/docs/reference/api/auth.md +156 -0
  234. package/skills/void/docs/reference/api/client.md +87 -0
  235. package/skills/void/docs/reference/api/database.md +95 -0
  236. package/skills/void/docs/reference/api/durable.md +46 -0
  237. package/skills/void/docs/reference/api/env.md +50 -0
  238. package/skills/void/docs/reference/api/handlers.md +254 -0
  239. package/skills/void/docs/reference/api/pages.md +241 -0
  240. package/skills/void/docs/reference/api/plugin.md +39 -0
  241. package/skills/void/docs/reference/api/resources.md +109 -0
  242. package/skills/void/docs/reference/api/rewrites.md +76 -0
  243. package/skills/void/docs/reference/api/types.md +92 -0
  244. package/skills/void/docs/reference/api.md +56 -1218
  245. package/skills/void/docs/reference/cli/auth.md +88 -0
  246. package/skills/void/docs/reference/cli/database.md +128 -0
  247. package/skills/void/docs/reference/cli/deploy.md +85 -0
  248. package/skills/void/docs/reference/cli/domains.md +41 -0
  249. package/skills/void/docs/reference/cli/email.md +129 -0
  250. package/skills/void/docs/reference/cli/generate.md +116 -0
  251. package/skills/void/docs/reference/cli/github.md +189 -0
  252. package/skills/void/docs/reference/cli/platform-config.md +92 -0
  253. package/skills/void/docs/reference/cli/platform-email.md +81 -0
  254. package/skills/void/docs/reference/cli/platform-installation.md +127 -0
  255. package/skills/void/docs/reference/cli/platform-operations.md +90 -0
  256. package/skills/void/docs/reference/cli/platform-users.md +89 -0
  257. package/skills/void/docs/reference/cli/platform-zero-trust.md +45 -0
  258. package/skills/void/docs/reference/cli/platform.md +70 -0
  259. package/skills/void/docs/reference/cli/project.md +214 -0
  260. package/skills/void/docs/reference/cli/secrets.md +76 -0
  261. package/skills/void/docs/reference/cli/setup.md +70 -0
  262. package/skills/void/docs/reference/cli.md +32 -1682
  263. package/skills/void/docs/reference/config.md +12 -18
  264. package/skills/void/docs/reference/resource-inference.md +3 -58
  265. package/skills/void/docs/reference/structure.md +14 -41
  266. package/dist/canonical-json-DuDiiUsQ.mjs +0 -13
  267. package/dist/client-Czz8o5jP.mjs +0 -2
  268. package/dist/gen-CNJ62MM7.mjs +0 -2
  269. package/dist/help-CmZzxUba.mjs +0 -2
  270. package/dist/login-CGcRKEoi.mjs +0 -2
  271. package/dist/migrate-CYfbKkXh.mjs +0 -2
  272. package/dist/plan-BEZ8VJW0.mjs +0 -256
  273. package/dist/plan-DpuOr14e.mjs +0 -2
  274. package/dist/prepare-Bm3iq-u4.mjs +0 -2
  275. package/dist/validate-EKmJWxmy.mjs +0 -2
  276. /package/dist/cli/{cf-compat.d.mts → cloudflare-operation-process.d.mts} +0 -0
@@ -2,14 +2,12 @@
2
2
  import { n as __toESM } from "../rolldown-runtime-DXIUcv95.mjs";
3
3
  import { a as join, n as dirname, u as resolve } from "../dist-BVqXeR_h.mjs";
4
4
  import { t as require_picocolors } from "../picocolors-BTps1_gs.mjs";
5
- import { t as prepareCfBuildOutput } from "../cf-build-output-BJ6yGEIS.mjs";
6
5
  import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7
6
  import { fileURLToPath } from "node:url";
8
7
  import { tmpdir } from "node:os";
9
8
  import { spawn, spawnSync } from "node:child_process";
10
9
  import { parse } from "jsonc-parser";
11
10
  import { stripVTControlCharacters } from "node:util";
12
- import { readBuildOutput } from "@cloudflare/build-output-utils";
13
11
  import { EnvHttpProxyAgent, fetch as fetch$1 } from "undici";
14
12
  import { getCloudflareAuthUseKeyringFromEnv } from "@cloudflare/workers-auth";
15
13
  import { createCfAuth, createCfProfileStore, readUserPreferences, setKeyringPreference } from "@cloudflare/workers-auth/cf";
@@ -62,18 +60,26 @@ function cloudflareDeviceCode(output) {
62
60
  const plain = stripVTControlCharacters(output);
63
61
  return /and enter the code:\s*([A-Za-z0-9-]+)\s/i.exec(plain)?.[1] ?? /[?&]user_code=([A-Za-z0-9-]+)\s/i.exec(plain)?.[1] ?? null;
64
62
  }
63
+ function cloudflareVerificationUrl(output) {
64
+ const plain = stripVTControlCharacters(output);
65
+ return /(?:Opening a link in your default browser:|Visit this link to authenticate:)\s*(https?:\/\/\S+)\s/i.exec(plain)?.[1] ?? /please visit:\s*(https?:\/\/\S+)\s/i.exec(plain)?.[1] ?? null;
66
+ }
67
+ function printCloudflareLoginLink(url) {
68
+ console.log(`Open this link if your browser did not open: ${url}`);
69
+ }
65
70
  function printCloudflareLoginPrompt(code) {
66
71
  console.log(code ? `Opening Cloudflare login in your browser. Confirm the code ${import_picocolors.default.blue(code)} in your browser. Press Ctrl+C to cancel.` : "Opening Cloudflare login in your browser. Confirm the code shown in your browser. Press Ctrl+C to cancel.");
67
72
  }
68
73
  //#endregion
69
- //#region src/cli/cf-compat.ts
70
- /**
71
- * Private transport for the existing Void Cloudflare command seams. The
72
- * orchestrators still use their established argument/result contracts; this
73
- * process translates them to the pinned cf CLI. It never invokes Wrangler.
74
- */
74
+ //#region src/cli/cloudflare-operation-process.ts
75
75
  const cf = join(dirname(fileURLToPath(import.meta.resolve("cf/package.json"))), "bin", "cf");
76
- const args = process.argv.slice(2);
76
+ const operation = (() => {
77
+ try {
78
+ return JSON.parse(process.argv[2] ?? "null");
79
+ } catch {
80
+ return null;
81
+ }
82
+ })();
77
83
  process.env.CLOUDFLARE_AUTH_USE_KEYRING ??= "true";
78
84
  function cfEnvironment() {
79
85
  const env = {
@@ -92,11 +98,20 @@ function cfEnvironment() {
92
98
  ]) if (!env[canonical] && env[alias]) env[canonical] = env[alias];
93
99
  return env;
94
100
  }
95
- function result(status, stdout = "", stderr = "") {
101
+ function result(status, stdout = "", stderr = "", data) {
102
+ const code = /\[(?:code:\s*)?(\d{4,})\]/.exec(stderr);
103
+ const errorCode = code ? Number(code[1]) : void 0;
96
104
  return {
97
105
  status,
98
106
  stdout,
99
- stderr
107
+ stderr,
108
+ ...data !== void 0 ? { data } : {},
109
+ ...errorCode ? { errorCode } : {},
110
+ ...[
111
+ 10006,
112
+ 10007,
113
+ 10090
114
+ ].includes(errorCode ?? 0) ? { failure: "not-found" } : {}
100
115
  };
101
116
  }
102
117
  function runCf(command, cwd = process.cwd()) {
@@ -120,7 +135,14 @@ function runCf(command, cwd = process.cwd()) {
120
135
  child.error?.message || "",
121
136
  child.signal ? `Cloudflare CLI terminated by ${child.signal}.` : ""
122
137
  ].filter(Boolean).join("\n").replace(/\[(\d{4,})\]/g, "[code: $1]");
123
- return result(child.status ?? 1, child.stdout ?? "", stderr);
138
+ if (child.signal || child.error || child.status === null) return {
139
+ status: 1,
140
+ stdout: "",
141
+ stderr,
142
+ signal: child.signal,
143
+ error: child.error?.message ?? (child.signal ? void 0 : "Cloudflare CLI did not report an exit status.")
144
+ };
145
+ return result(child.status, child.stdout ?? "", stderr);
124
146
  }
125
147
  function runInteractiveCf(command) {
126
148
  return new Promise((resolve) => {
@@ -144,6 +166,7 @@ function runInteractiveCf(command) {
144
166
  });
145
167
  let output = "";
146
168
  let announced = false;
169
+ let announcedLink = false;
147
170
  let settled = false;
148
171
  const finish = (value) => {
149
172
  if (!settled) {
@@ -160,6 +183,13 @@ function runInteractiveCf(command) {
160
183
  printCloudflareLoginPrompt(code);
161
184
  }
162
185
  }
186
+ if (!announcedLink) {
187
+ const url = cloudflareVerificationUrl(output);
188
+ if (url) {
189
+ announcedLink = true;
190
+ printCloudflareLoginLink(url);
191
+ }
192
+ }
163
193
  };
164
194
  child.stdout.on("data", collect);
165
195
  child.stderr.on("data", collect);
@@ -185,6 +215,7 @@ async function withBuildOutput(raw, sourceMain, action) {
185
215
  }), { mode: 384 });
186
216
  const accountId = process.env.CLOUDFLARE_ACCOUNT_ID ?? raw.account_id;
187
217
  if (typeof accountId !== "string" || !accountId) throw new Error("Cloudflare account is not pinned for Worker deployment.");
218
+ const { prepareCfBuildOutput } = await import("../cf-build-output-_0HNWysu.mjs");
188
219
  const output = await prepareCfBuildOutput(scratch, accountId);
189
220
  if (!output) throw new Error("Could not prepare the Cloudflare Worker build output.");
190
221
  try {
@@ -207,12 +238,8 @@ function object(value) {
207
238
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Cloudflare returned an unexpected response.");
208
239
  return value;
209
240
  }
210
- function field(name) {
211
- const index = args.indexOf(name);
212
- return index >= 0 ? args[index + 1] : void 0;
213
- }
214
241
  function configPath() {
215
- return field("-c") ?? field("--config");
242
+ return "configPath" in operation ? operation.configPath : void 0;
216
243
  }
217
244
  function config() {
218
245
  const path = configPath();
@@ -220,7 +247,7 @@ function config() {
220
247
  return object(parse(readFileSync(path, "utf8")));
221
248
  }
222
249
  function workerName() {
223
- const name = field("--name") ?? config().name;
250
+ const name = ("workerName" in operation ? operation.workerName : void 0) ?? config().name;
224
251
  if (typeof name !== "string" || !name) throw new Error("Cloudflare Worker name is missing from the generated config.");
225
252
  return name;
226
253
  }
@@ -336,6 +363,7 @@ async function clearWorkerCustomDomains(worker) {
336
363
  }
337
364
  }
338
365
  async function assertExistingProvisionableResources(directory, account) {
366
+ const { readBuildOutput } = await import("@cloudflare/build-output-utils");
339
367
  const bindings = (await readBuildOutput(directory)).workers.default.config.env ?? {};
340
368
  const queueNames = /* @__PURE__ */ new Set();
341
369
  const accountPath = `/accounts/${encodeURIComponent(account)}`;
@@ -415,7 +443,7 @@ async function sessionCredential() {
415
443
  } : null;
416
444
  }
417
445
  async function auth() {
418
- if (args[0] === "login") {
446
+ if (operation.type === "auth.login") {
419
447
  const loggedIn = await runInteractiveCf([
420
448
  "auth",
421
449
  "login",
@@ -424,26 +452,24 @@ async function auth() {
424
452
  if (loggedIn.status === 0) persistCfKeyringPreference(process.cwd());
425
453
  return loggedIn;
426
454
  }
427
- if (args[0] === "logout") return runCf(["auth", "logout"]);
428
- if (args[0] === "whoami") {
455
+ if (operation.type === "auth.logout") return runCf(["auth", "logout"]);
456
+ if (operation.type === "auth.whoami") {
429
457
  const called = runCf(["auth", "whoami"]);
430
458
  if (called.status !== 0) return called;
431
459
  const identity = object(parsedJson(called.stdout));
432
- if (identity.authenticated !== true || identity.tokenValid !== true) return result(1, JSON.stringify({ loggedIn: false }), "Cloudflare authentication is required.");
460
+ if (identity.authenticated !== true || identity.tokenValid !== true) return result(1, "", "Cloudflare authentication is required.", { loggedIn: false });
433
461
  if (String(identity.authSource).startsWith("OAuth token from ")) persistCfKeyringPreference(process.cwd());
434
- return result(0, JSON.stringify({
462
+ return result(0, "", called.stderr, {
435
463
  loggedIn: true,
436
464
  accounts: identity.accounts,
437
465
  email: identity.email,
438
466
  tokenPermissions: identity.scopes,
439
467
  authType: process.env.CLOUDFLARE_API_KEY || process.env.CF_API_KEY ? "Global API Key" : String(identity.authSource).startsWith("OAuth token") ? "OAuth Token" : "API Token"
440
- }), called.stderr);
441
- }
442
- if (args[0] === "auth" && args[1] === "token") {
443
- const credential = await sessionCredential();
444
- return credential ? result(0, `${JSON.stringify(credential)}\n`) : result(1, "", "Cloudflare session has no OAuth bearer.");
468
+ });
445
469
  }
446
- return result(1, "", "Unsupported Cloudflare authentication operation.");
470
+ if (operation.type !== "auth.token") throw new Error("Unsupported Cloudflare authentication operation.");
471
+ const credential = await sessionCredential();
472
+ return credential ? result(0, "", "", credential) : result(1, "", "Cloudflare session has no OAuth bearer.");
447
473
  }
448
474
  function listAllResourcePages(command, extraFlags = []) {
449
475
  const pageSize = 100;
@@ -484,152 +510,158 @@ async function readAllQueues() {
484
510
  throw new Error("Cloudflare Queue list exceeded the supported page limit.");
485
511
  }
486
512
  async function resources() {
487
- const [group, verb, third] = args;
488
- if (group === "d1" && verb === "execute" && third) {
489
- const database = d1Database(third);
490
- const sql = field("--command");
491
- if (!sql) throw new Error("D1 SQL command is missing.");
492
- return runCf([
513
+ switch (operation.type) {
514
+ case "d1.execute": return runCf([
493
515
  "d1",
494
516
  "query",
495
- database.id,
517
+ d1Database(operation.database).id,
496
518
  "--sql",
497
- sql
519
+ operation.sql
498
520
  ]);
499
- }
500
- if (group === "d1" && verb === "migrations" && (third === "list" || third === "apply")) {
501
- const token = args[3];
502
- if (!token) throw new Error("D1 migration target is missing.");
503
- const database = d1Database(token);
504
- const called = runCf([
505
- "d1",
506
- "migrations",
507
- third,
508
- database.id,
509
- "--dir",
510
- database.dir,
511
- ...database.pattern ? ["--pattern", database.pattern] : [],
512
- "--table",
513
- database.table
514
- ]);
515
- if (called.status !== 0 || third !== "list") return called;
516
- const pending = parsedJson(called.stdout);
517
- if (!Array.isArray(pending)) throw new Error("D1 migration list was malformed.");
518
- return result(0, pending.length ? `Migrations to be applied:\n${pending.map((item) => object(item).Name).join("\n")}\n` : "No migrations to apply!\n");
519
- }
520
- if (group === "containers" && verb === "list") return runCf([
521
- "containers",
522
- "applications",
523
- "list"
524
- ]);
525
- if (group === "d1" && verb === "list") return listAllResourcePages(["d1", "list"]);
526
- if (group === "d1" && verb === "info" && third) {
527
- const listed = listAllResourcePages(["d1", "list"]);
528
- if (listed.status !== 0) return listed;
529
- const value = parsedJson(listed.stdout);
530
- if (!Array.isArray(value)) throw new Error("D1 list was malformed.");
531
- const selected = value.find((item) => object(item).name === third) ?? null;
532
- return selected === null ? result(1, "", `D1 database ${JSON.stringify(third)} does not exist.`) : result(0, `${JSON.stringify(selected)}\n`);
533
- }
534
- if (group === "d1" && verb === "create" && third) {
535
- const created = runCf([
536
- "d1",
537
- "create",
538
- "--name",
539
- third
521
+ case "d1.migrations.list":
522
+ case "d1.migrations.apply": {
523
+ const database = d1Database(operation.database);
524
+ const verb = operation.type === "d1.migrations.list" ? "list" : "apply";
525
+ const called = runCf([
526
+ "d1",
527
+ "migrations",
528
+ verb,
529
+ database.id,
530
+ "--dir",
531
+ database.dir,
532
+ ...database.pattern ? ["--pattern", database.pattern] : [],
533
+ "--table",
534
+ database.table
535
+ ]);
536
+ if (called.status !== 0 || verb !== "list") return called;
537
+ const pending = parsedJson(called.stdout);
538
+ if (!Array.isArray(pending) || pending.some((item) => typeof object(item).Name !== "string")) throw new Error("D1 migration list was malformed.");
539
+ return result(0, "", called.stderr, { pending: pending.map((item) => object(item).Name) });
540
+ }
541
+ case "containers.list": return runCf([
542
+ "containers",
543
+ "applications",
544
+ "list"
540
545
  ]);
541
- if (created.status !== 0) return created;
542
- const database = object(parsedJson(created.stdout));
543
- if (typeof database.uuid !== "string") throw new Error("D1 creation returned no database ID.");
544
- updateBinding("d1_databases", field("--binding") ?? "", {
545
- database_name: third,
546
- database_id: database.uuid
547
- });
548
- return created;
549
- }
550
- if (group === "kv" && verb === "namespace" && third === "list") return listAllResourcePages([
551
- "kv",
552
- "namespaces",
553
- "list"
554
- ], [
555
- "--order",
556
- "id",
557
- "--direction",
558
- "asc"
559
- ]);
560
- if (group === "kv" && verb === "namespace" && third === "create" && args[3]) {
561
- const created = runCf([
546
+ case "d1.list": return listAllResourcePages(["d1", "list"]);
547
+ case "d1.info": {
548
+ const listed = listAllResourcePages(["d1", "list"]);
549
+ if (listed.status !== 0) return listed;
550
+ const list = parsedJson(listed.stdout);
551
+ if (!Array.isArray(list)) throw new Error("D1 list was malformed.");
552
+ const value = list.find((item) => object(item).name === operation.name);
553
+ return value === void 0 ? {
554
+ ...result(1, "", "D1 database does not exist."),
555
+ failure: "not-found"
556
+ } : result(0, "", "", value);
557
+ }
558
+ case "d1.create": {
559
+ const created = runCf([
560
+ "d1",
561
+ "create",
562
+ "--name",
563
+ operation.name
564
+ ]);
565
+ if (created.status !== 0) return created;
566
+ const database = object(parsedJson(created.stdout));
567
+ if (typeof database.uuid !== "string") throw new Error("D1 creation returned no database ID.");
568
+ updateBinding("d1_databases", operation.binding, {
569
+ database_name: operation.name,
570
+ database_id: database.uuid
571
+ });
572
+ return created;
573
+ }
574
+ case "kv.namespace.list": return listAllResourcePages([
562
575
  "kv",
563
576
  "namespaces",
564
- "create",
565
- "--title",
566
- args[3]
577
+ "list"
578
+ ], [
579
+ "--order",
580
+ "id",
581
+ "--direction",
582
+ "asc"
567
583
  ]);
568
- if (created.status !== 0) return created;
569
- const namespace = object(parsedJson(created.stdout));
570
- if (typeof namespace.id !== "string") throw new Error("KV creation returned no namespace ID.");
571
- updateBinding("kv_namespaces", field("--binding") ?? "", { id: namespace.id });
572
- return created;
573
- }
574
- if (group === "r2" && verb === "bucket" && third === "info" && args[3]) {
575
- const read = runCf([
584
+ case "kv.namespace.create": {
585
+ const created = runCf([
586
+ "kv",
587
+ "namespaces",
588
+ "create",
589
+ "--title",
590
+ operation.name
591
+ ]);
592
+ if (created.status !== 0) return created;
593
+ const namespace = object(parsedJson(created.stdout));
594
+ if (typeof namespace.id !== "string") throw new Error("KV creation returned no namespace ID.");
595
+ updateBinding("kv_namespaces", operation.binding, { id: namespace.id });
596
+ return created;
597
+ }
598
+ case "r2.bucket.info": return runCf([
576
599
  "r2",
577
600
  "buckets",
578
601
  "get",
579
- args[3]
602
+ operation.name
580
603
  ]);
581
- return read.status !== 0 && /\[code:\s*10006\]/.test(read.stderr) ? result(1, "", "[code: 10006] The specified bucket does not exist.") : read;
582
- }
583
- if (group === "r2" && verb === "bucket" && third === "create" && args[3]) {
584
- const created = runCf([
585
- "r2",
586
- "buckets",
587
- "create",
588
- "--name",
589
- args[3]
590
- ]);
591
- if (created.status === 0) updateBinding("r2_buckets", field("--binding") ?? "", { bucket_name: args[3] });
592
- return created;
593
- }
594
- if (group === "hyperdrive" && verb === "create" && third) {
595
- const connection = args.find((part) => part.startsWith("--connection-string="))?.slice(20);
596
- if (!connection) throw new Error("Hyperdrive connection string is missing.");
597
- const url = new URL(connection);
598
- const created = await withSecretFile(JSON.stringify({
599
- name: third,
600
- origin: {
601
- host: url.hostname,
602
- port: Number(url.port || (url.protocol.startsWith("mysql") ? 3306 : 5432)),
603
- database: decodeURIComponent(url.pathname.replace(/^\//, "")),
604
- scheme: url.protocol.replace(":", ""),
605
- user: decodeURIComponent(url.username),
606
- password: decodeURIComponent(url.password)
607
- }
608
- }), (path) => runCf([
609
- "hyperdrive",
610
- "create",
611
- "--body",
612
- `@${path}`
613
- ]));
614
- if (created.status !== 0) return result(created.status, "", "Hyperdrive creation failed.");
615
- const hyperdrive = object(parsedJson(created.stdout));
616
- if (typeof hyperdrive.id !== "string") throw new Error("Hyperdrive creation returned no ID.");
617
- updateBinding("hyperdrive", field("--binding") ?? "", { id: hyperdrive.id });
618
- return result(0, `${JSON.stringify({
619
- id: hyperdrive.id,
620
- name: third
621
- })}\n`);
622
- }
623
- if (group === "queues" && (verb === "info" || verb === "create") && third) {
624
- if (verb === "create") return runCf([
604
+ case "r2.bucket.create": {
605
+ const created = runCf([
606
+ "r2",
607
+ "buckets",
608
+ "create",
609
+ "--name",
610
+ operation.name
611
+ ]);
612
+ if (created.status === 0) updateBinding("r2_buckets", operation.binding, { bucket_name: operation.name });
613
+ return created;
614
+ }
615
+ case "hyperdrive.create": {
616
+ const url = new URL(readFileSync(0, "utf8"));
617
+ const name = operation.name;
618
+ const created = await withSecretFile(JSON.stringify({
619
+ name,
620
+ origin: {
621
+ host: url.hostname,
622
+ port: Number(url.port || (url.protocol.startsWith("mysql") ? 3306 : 5432)),
623
+ database: decodeURIComponent(url.pathname.replace(/^\//, "")),
624
+ scheme: url.protocol.replace(":", ""),
625
+ user: decodeURIComponent(url.username),
626
+ password: decodeURIComponent(url.password)
627
+ }
628
+ }), (path) => runCf([
629
+ "hyperdrive",
630
+ "create",
631
+ "--body",
632
+ "@" + path
633
+ ]));
634
+ if (created.status !== 0) return {
635
+ ...created,
636
+ stdout: "",
637
+ stderr: "Hyperdrive creation failed."
638
+ };
639
+ const hyperdrive = object(parsedJson(created.stdout));
640
+ if (typeof hyperdrive.id !== "string") throw new Error("Hyperdrive creation returned no ID.");
641
+ updateBinding("hyperdrive", operation.binding, { id: hyperdrive.id });
642
+ return result(0, "", "", {
643
+ id: hyperdrive.id,
644
+ name
645
+ });
646
+ }
647
+ case "queues.create": return runCf([
625
648
  "queues",
626
649
  "create",
627
650
  "--queue-name",
628
- third
651
+ operation.name
629
652
  ]);
630
- return (await readAllQueues()).find((item) => item.queue_name === third) ? result(0, `Queue Name: ${third}\n`) : result(1, "", `Queue "${third}" does not exist`);
653
+ case "queues.info": {
654
+ const queue = (await readAllQueues()).find((item) => item.queue_name === operation.name);
655
+ return queue ? result(0, "", "", {
656
+ id: queue.queue_id,
657
+ name: queue.queue_name
658
+ }) : {
659
+ ...result(1, "", "Cloudflare Queue does not exist."),
660
+ failure: "not-found"
661
+ };
662
+ }
663
+ default: throw new Error("Unsupported Cloudflare resource operation.");
631
664
  }
632
- return result(1, "", `Unsupported Cloudflare resource operation: ${group} ${verb}.`);
633
665
  }
634
666
  function emailZone(domain) {
635
667
  const labels = domain.split(".");
@@ -643,103 +675,67 @@ function emailZone(domain) {
643
675
  candidate
644
676
  ]);
645
677
  if (read.status === 0) return candidate;
646
- if (!/Zone not found:/.test(read.stderr)) throw new Error("Cloudflare could not resolve the Email zone.");
678
+ if (read.signal || read.error || !/Zone not found:/.test(read.stderr)) throw new Error("Cloudflare could not resolve the Email zone.");
647
679
  }
648
680
  throw new Error(`Cloudflare Email zone for ${domain} was not found.`);
649
681
  }
650
682
  function email() {
651
- const [group, product, operation, candidate] = args;
652
- if (group !== "email" || !candidate) return result(1, "", "Unsupported Cloudflare email operation.");
653
- if (product === "routing" && operation === "settings") {
654
- const read = runCf([
683
+ if (!("domain" in operation)) throw new Error("Cloudflare Email domain is missing.");
684
+ const domain = operation.domain;
685
+ switch (operation.type) {
686
+ case "email.routing.settings": {
687
+ const read = runCf([
688
+ "email-routing",
689
+ "settings",
690
+ "get",
691
+ "--zone",
692
+ domain
693
+ ]);
694
+ return read.status !== 0 && !read.signal && !read.error && /Zone not found:/.test(read.stderr) ? result(0, "", "", null) : read;
695
+ }
696
+ case "email.routing.enable": return runCf([
655
697
  "email-routing",
656
- "settings",
657
- "get",
698
+ "enable",
658
699
  "--zone",
659
- candidate
700
+ domain,
701
+ "--name",
702
+ domain
660
703
  ]);
661
- if (read.status !== 0) return /Zone not found:/.test(read.stderr) ? result(1, "", `Could not find a zone for \`${candidate}\`.`) : read;
662
- const settings = object(parsedJson(read.stdout));
663
- if (typeof settings.tag !== "string" || typeof settings.name !== "string") throw new Error("Email Routing settings were incomplete.");
664
- return result(0, `Email Routing for ${settings.name}:\n Enabled: ${settings.enabled === true}\n Status: ${settings.status}\n Tag: ${settings.tag}\n`);
665
- }
666
- if (product === "routing" && operation === "enable") return runCf([
667
- "email-routing",
668
- "enable",
669
- "--zone",
670
- candidate,
671
- "--name",
672
- candidate
673
- ]);
674
- if (product === "routing" && operation === "rules" && args[3] === "list" && args[4]) {
675
- const zone = args[4];
676
- const lines = [];
677
- for (let page = 1; page <= 100; page++) {
704
+ case "email.routing.rules.list": return listAllResourcePages([
705
+ "email-routing",
706
+ "rules",
707
+ "list-account"
708
+ ], ["--zone", domain]);
709
+ case "email.sending.settings": {
678
710
  const listed = runCf([
679
- "email-routing",
680
- "rules",
681
- "list-account",
711
+ "email-sending",
712
+ "subdomains",
713
+ "list",
682
714
  "--zone",
683
- zone,
684
- "--page",
685
- String(page),
686
- "--per-page",
687
- "100"
715
+ emailZone(domain)
688
716
  ]);
689
717
  if (listed.status !== 0) return listed;
690
- const items = parsedJson(listed.stdout);
691
- if (!Array.isArray(items)) throw new Error("Email Routing rules were malformed.");
692
- for (const entry of items.map(object)) {
693
- const actions = Array.isArray(entry.actions) ? entry.actions.map((action) => {
694
- const item = object(action);
695
- return item.type === "worker" ? `worker:${item.value}` : item.type === "forward" && Array.isArray(item.value) ? `forward:${item.value.join(",")}` : String(item.type);
696
- }) : [];
697
- const matchers = Array.isArray(entry.matchers) ? entry.matchers.map(object) : [];
698
- if (matchers.some((item) => item.type === "all")) lines.push(`Catch-all rule: ${entry.enabled === true ? "enabled" : "disabled"}, action: ${actions.join(", ")}`);
699
- else {
700
- if (typeof entry.id !== "string") throw new Error("Email Routing rule ID was missing.");
701
- const recipients = matchers.filter((item) => item.type === "literal" || item.type === "to").map((item) => `to:${item.value}`);
702
- lines.push(`Rule: ${entry.id}\n Name: ${entry.name || "(none)"}\n Enabled: ${entry.enabled === true}\n Matchers: ${recipients.join(", ")}\n Actions: ${actions.join(", ")}\n Priority: ${entry.priority ?? 0}`);
703
- }
704
- }
705
- if (items.length < 100) return result(0, lines.length ? `${lines.join("\n")}\n` : "No routing rules found.\n");
718
+ const values = parsedJson(listed.stdout);
719
+ if (!Array.isArray(values)) throw new Error("Email Sending subdomains were malformed.");
720
+ return result(0, "", "", values.map(object).find((item) => item.name === domain) ?? null);
706
721
  }
707
- throw new Error("Email Routing rules exceeded the supported page limit.");
708
- }
709
- if (product === "sending" && operation === "settings") {
710
- const listed = runCf([
722
+ case "email.sending.enable": return runCf([
711
723
  "email-sending",
712
724
  "subdomains",
713
- "list",
725
+ "create",
714
726
  "--zone",
715
- emailZone(candidate)
727
+ emailZone(domain),
728
+ "--name",
729
+ domain
716
730
  ]);
717
- if (listed.status !== 0) return listed;
718
- const values = parsedJson(listed.stdout);
719
- if (!Array.isArray(values)) throw new Error("Email Sending subdomains were malformed.");
720
- const match = values.map(object).find((item) => item.name === candidate);
721
- if (!match) return result(1, "", `No sending subdomain found for \`${candidate}\`.`);
722
- const tag = match.tag ?? match.id;
723
- if (typeof tag !== "string") throw new Error("Email Sending subdomain ID was missing.");
724
- return result(0, `Email Sending for ${candidate}:\n Enabled: ${match.enabled === true}\n Tag: ${tag}\n`);
731
+ default: throw new Error("Unsupported Cloudflare Email operation.");
725
732
  }
726
- if (product === "sending" && operation === "enable") return runCf([
727
- "email-sending",
728
- "subdomains",
729
- "create",
730
- "--zone",
731
- emailZone(candidate),
732
- "--name",
733
- candidate
734
- ]);
735
- return result(1, "", `Unsupported Cloudflare email operation: ${product} ${operation}.`);
736
733
  }
737
734
  async function secrets() {
738
735
  const worker = workerName();
739
- const verb = args[1];
740
736
  const apply = async (action) => {
741
737
  const first = action();
742
- if (first.status === 0 || !/\[code:\s*10007\]/.test(first.stderr)) return first;
738
+ if (first.status === 0 || first.errorCode !== 10007) return first;
743
739
  const draft = await withBuildOutput({
744
740
  name: worker,
745
741
  account_id: process.env.CLOUDFLARE_ACCOUNT_ID ?? config().account_id,
@@ -754,148 +750,142 @@ async function secrets() {
754
750
  ], directory));
755
751
  return draft.status === 0 ? action() : draft;
756
752
  };
757
- if (verb === "list") {
758
- const listed = runCf([
753
+ switch (operation.type) {
754
+ case "secret.list": return runCf([
759
755
  "workers",
760
756
  "secrets",
761
757
  "list",
762
758
  "--worker",
763
759
  worker
764
760
  ]);
765
- if (listed.status !== 0 && /\[code:\s*(?:10007|10090)\]/.test(listed.stderr)) return result(1, "", `Worker "${worker}" not found. [code: 10007]`);
766
- return listed;
767
- }
768
- if (verb === "put" && args[2]) {
769
- const value = readFileSync(0, "utf8").replace(/\n$/, "");
770
- return await withSecretFile(JSON.stringify({
771
- name: args[2],
772
- text: value,
773
- type: "secret_text"
774
- }), (path) => apply(() => runCf([
775
- "workers",
776
- "secrets",
777
- "update",
778
- args[2],
779
- "--worker",
780
- worker,
781
- "--body",
782
- `@${path}`
783
- ])));
784
- }
785
- if (verb === "bulk") {
786
- const input = object(parsedJson(readFileSync(0, "utf8")));
787
- const patch = Object.fromEntries(Object.entries(input).map(([name, text]) => [name, {
788
- type: "secret_text",
789
- text
790
- }]));
791
- return await withSecretFile(JSON.stringify(patch), (path) => apply(() => runCf([
761
+ case "secret.put": {
762
+ const value = readFileSync(0, "utf8").replace(/\n$/, "");
763
+ const name = operation.name;
764
+ return withSecretFile(JSON.stringify({
765
+ name,
766
+ text: value,
767
+ type: "secret_text"
768
+ }), (path) => apply(() => runCf([
769
+ "workers",
770
+ "secrets",
771
+ "update",
772
+ name,
773
+ "--worker",
774
+ worker,
775
+ "--body",
776
+ "@" + path
777
+ ])));
778
+ }
779
+ case "secret.bulk": {
780
+ const values = object(parsedJson(readFileSync(0, "utf8")));
781
+ const patch = Object.fromEntries(Object.entries(values).map(([name, text]) => [name, {
782
+ type: "secret_text",
783
+ text
784
+ }]));
785
+ return withSecretFile(JSON.stringify(patch), (path) => apply(() => runCf([
786
+ "workers",
787
+ "secrets",
788
+ "bulk",
789
+ "--worker",
790
+ worker,
791
+ "--file",
792
+ path
793
+ ])));
794
+ }
795
+ case "secret.delete": return runCf([
792
796
  "workers",
793
797
  "secrets",
794
- "bulk",
798
+ "delete",
799
+ operation.name,
795
800
  "--worker",
796
801
  worker,
797
- "--file",
798
- path
799
- ])));
802
+ "--force"
803
+ ]);
804
+ default: throw new Error("Unsupported Cloudflare secret operation.");
800
805
  }
801
- if (verb === "delete" && args[2]) return runCf([
802
- "workers",
803
- "secrets",
804
- "delete",
805
- args[2],
806
- "--worker",
807
- worker,
808
- "--force"
809
- ]);
810
- return result(1, "", `Unsupported Cloudflare secret operation: ${verb}.`);
811
806
  }
812
807
  async function workerHistory() {
813
808
  const worker = workerName();
814
- const [group, verb, third] = args;
815
- if (group === "deployments" && (verb === "status" || verb === "list")) {
816
- const called = runCf([
817
- "workers",
818
- "deployments",
819
- "list",
820
- "--worker",
821
- worker
822
- ]);
823
- if (called.status !== 0) return called;
824
- const deployments = object(parsedJson(called.stdout)).deployments;
825
- if (!Array.isArray(deployments)) throw new Error("Worker deployments were malformed.");
826
- if (verb === "status") return deployments[0] ? result(0, `${JSON.stringify(deployments[0])}\n`) : result(1, "", "Worker has no active deployment.");
827
- return result(0, `${JSON.stringify(deployments)}\n`);
828
- }
829
- if (group === "versions" && verb === "list") return cleanJson([
830
- "workers",
831
- "versions",
832
- "list",
833
- "--worker-id",
834
- worker
835
- ], (value) => {
836
- if (!Array.isArray(value)) throw new Error("Worker versions were malformed.");
837
- return value.map((entry) => {
838
- const version = object(entry);
839
- return {
840
- ...version,
841
- metadata: { created_on: version.created_on }
842
- };
843
- });
844
- });
845
- if (group === "versions" && verb === "view" && third) {
846
- const called = runCf([
809
+ switch (operation.type) {
810
+ case "deployments.status":
811
+ case "deployments.list": {
812
+ const called = runCf([
813
+ "workers",
814
+ "deployments",
815
+ "list",
816
+ "--worker",
817
+ worker
818
+ ]);
819
+ if (called.status !== 0) return called;
820
+ const deployments = object(parsedJson(called.stdout)).deployments;
821
+ if (!Array.isArray(deployments)) throw new Error("Worker deployments were malformed.");
822
+ return operation.type === "deployments.list" ? result(0, "", called.stderr, deployments) : deployments[0] ? result(0, "", called.stderr, deployments[0]) : result(1, "", "Worker has no active deployment.");
823
+ }
824
+ case "versions.list": return cleanJson([
847
825
  "workers",
848
826
  "versions",
849
- "get",
850
- third,
827
+ "list",
851
828
  "--worker-id",
852
829
  worker
853
- ]);
854
- if (called.status !== 0) return called;
855
- const version = object(parsedJson(called.stdout));
856
- if (version.id !== third || !Array.isArray(version.bindings)) throw new Error("Worker version bindings were malformed.");
857
- const resources = await readVersionResources(worker, third);
858
- return result(0, `${JSON.stringify({
859
- ...version,
860
- resources
861
- })}\n`);
862
- }
863
- if (group === "versions" && verb === "deploy") {
864
- const firstFlag = args.findIndex((part, index) => index >= 2 && part.startsWith("-"));
865
- const versions = args.slice(2, firstFlag === -1 ? void 0 : firstFlag).map((part) => {
866
- const [version_id, fraction] = part.split("@");
867
- const percentage = Number(fraction);
868
- if (!/^[0-9a-f-]{36}$/i.test(version_id ?? "") || !Number.isFinite(percentage)) throw new Error("Cloudflare deployment version was malformed.");
869
- return {
870
- version_id,
871
- percentage
872
- };
830
+ ], (value) => {
831
+ if (!Array.isArray(value)) throw new Error("Worker versions were malformed.");
832
+ return value.map((entry) => {
833
+ const version = object(entry);
834
+ return {
835
+ ...version,
836
+ metadata: { created_on: version.created_on }
837
+ };
838
+ });
873
839
  });
874
- if (!versions.length || Math.abs(versions.reduce((sum, entry) => sum + entry.percentage, 0) - 100) > .001) throw new Error("Cloudflare deployment percentages must total 100.");
875
- const message = field("--message");
876
- return runCf([
877
- "workers",
878
- "deployments",
879
- "create",
880
- "--worker",
881
- worker,
882
- "--body",
883
- JSON.stringify({
884
- strategy: "percentage",
885
- versions,
886
- ...message ? { annotations: { "workers/message": message } } : {}
887
- })
888
- ]);
840
+ case "versions.view": {
841
+ const versionId = operation.versionId;
842
+ const called = runCf([
843
+ "workers",
844
+ "versions",
845
+ "get",
846
+ versionId,
847
+ "--worker-id",
848
+ worker
849
+ ]);
850
+ if (called.status !== 0) return called;
851
+ const version = object(parsedJson(called.stdout));
852
+ if (version.id !== versionId || !Array.isArray(version.bindings)) throw new Error("Worker version bindings were malformed.");
853
+ const resources = await readVersionResources(worker, versionId);
854
+ return result(0, "", called.stderr, {
855
+ ...version,
856
+ resources
857
+ });
858
+ }
859
+ case "versions.deploy": {
860
+ const versions = operation.versions.map((value) => ({
861
+ version_id: value.versionId,
862
+ percentage: value.percentage
863
+ }));
864
+ if (!versions.length || versions.some((value) => !/^[-a-f\d]{36}$/i.test(value.version_id) || !Number.isFinite(value.percentage) || value.percentage < 0 || value.percentage > 100) || Math.abs(versions.reduce((sum, value) => sum + value.percentage, 0) - 100) > .001) throw new Error("Cloudflare deployment percentages must total 100.");
865
+ return runCf([
866
+ "workers",
867
+ "deployments",
868
+ "create",
869
+ "--worker",
870
+ worker,
871
+ "--body",
872
+ JSON.stringify({
873
+ strategy: "percentage",
874
+ versions,
875
+ ...operation.message ? { annotations: { "workers/message": operation.message } } : {}
876
+ })
877
+ ]);
878
+ }
879
+ default: throw new Error("Unsupported Cloudflare Worker history operation.");
889
880
  }
890
- return result(1, "", `Unsupported Cloudflare Worker history operation: ${group} ${verb}.`);
891
881
  }
892
882
  async function workerChanges() {
893
- if (args[0] === "queues" && args[1] === "consumer" && args[2] === "remove") {
894
- const queueName = args[3];
895
- const worker = args[4];
896
- if (!queueName || !worker) throw new Error("Queue consumer target is missing.");
897
- const queue = (await readAllQueues()).find((item) => item.queue_name === queueName);
898
- if (!queue || typeof queue.queue_id !== "string") return result(1, "", `Queue "${queueName}" does not exist`);
883
+ if (operation.type === "queues.consumer.remove") {
884
+ const queue = (await readAllQueues()).find((item) => item.queue_name === operation.queueName);
885
+ if (!queue || typeof queue.queue_id !== "string") return {
886
+ ...result(1, "", "Cloudflare Queue does not exist."),
887
+ failure: "not-found"
888
+ };
899
889
  const consumers = runCf([
900
890
  "queues",
901
891
  "consumers",
@@ -906,8 +896,17 @@ async function workerChanges() {
906
896
  if (consumers.status !== 0) return consumers;
907
897
  const members = parsedJson(consumers.stdout);
908
898
  if (!Array.isArray(members)) throw new Error("Queue consumer list was malformed.");
909
- for (const item of members.map(object).filter((entry) => entry.script === worker)) {
910
- if (typeof item.consumer_id !== "string") throw new Error("Queue consumer ID is missing.");
899
+ const matching = members.map(object).filter((entry) => {
900
+ const name = entry.script_name ?? entry.script;
901
+ if (entry.script_name !== void 0 && (typeof entry.script_name !== "string" || !entry.script_name) || entry.script !== void 0 && (typeof entry.script !== "string" || !entry.script) || entry.script_name !== void 0 && entry.script !== void 0 && entry.script_name !== entry.script || entry.type === "worker" && name === void 0) throw new Error("Queue consumer Worker identity is ambiguous.");
902
+ return name === operation.workerName;
903
+ });
904
+ if (matching.length > 1) throw new Error("Queue consumer Worker identity is ambiguous.");
905
+ for (const item of matching) {
906
+ if (typeof item.consumer_id !== "string" || !item.consumer_id || item.consumer_id.startsWith("-") || /\s/.test(item.consumer_id) || [...item.consumer_id].some((character) => {
907
+ const code = character.charCodeAt(0);
908
+ return code < 32 || code === 127;
909
+ }) || item.type !== void 0 && item.type !== "worker") throw new Error("Queue consumer ID or type is invalid.");
911
910
  const deleted = runCf([
912
911
  "queues",
913
912
  "consumers",
@@ -921,59 +920,62 @@ async function workerChanges() {
921
920
  }
922
921
  return result(0);
923
922
  }
924
- if (args[0] === "triggers" && args[1] === "deploy") {
925
- const raw = config();
926
- const name = workerName();
927
- if (raw.name !== name) throw new Error("Cloudflare trigger Worker name changed.");
928
- return await withBuildOutput(raw, null, (directory) => runCf([
929
- "workers",
930
- "triggers",
931
- "deploy",
932
- "--prebuilt",
933
- ...args.includes("--dry-run") ? ["--dry-run"] : []
934
- ], directory));
923
+ const raw = config();
924
+ const name = workerName();
925
+ if (raw.name !== name) throw new Error("Cloudflare Worker target changed.");
926
+ if (operation.type === "triggers.clear-crons" || operation.type === "triggers.clear-domains") {
927
+ if (raw.account_id !== void 0 && raw.account_id !== accountId()) throw new Error("Cloudflare trigger target changed.");
928
+ return operation.type === "triggers.clear-crons" ? clearWorkerCronSchedules(name) : clearWorkerCustomDomains(name);
935
929
  }
936
- if (args[0] === "triggers" && args[1] === "clear-crons") {
937
- const raw = config();
938
- const name = workerName();
939
- if (raw.name !== name || raw.account_id !== void 0 && raw.account_id !== accountId()) throw new Error("Cloudflare trigger target changed.");
940
- return await clearWorkerCronSchedules(name);
941
- }
942
- if (args[0] === "triggers" && args[1] === "clear-domains") {
943
- const raw = config();
944
- const name = workerName();
945
- if (raw.name !== name || raw.account_id !== void 0 && raw.account_id !== accountId()) throw new Error("Cloudflare trigger target changed.");
946
- return await clearWorkerCustomDomains(name);
947
- }
948
- if (args[0] === "versions" && args[1] === "upload" || args[0] === "deploy") {
949
- const raw = config();
930
+ if (operation.type === "triggers.deploy") return withBuildOutput(raw, null, (directory) => runCf([
931
+ "workers",
932
+ "triggers",
933
+ "deploy",
934
+ "--prebuilt"
935
+ ], directory));
936
+ if (operation.type === "versions.upload" || operation.type === "worker.deploy") {
950
937
  const path = configPath();
951
938
  if (typeof raw.main !== "string" || !raw.main || raw.no_bundle !== true) throw new Error("Cloudflare Worker upload requires a prebuilt platform Worker.");
952
939
  const source = resolve(dirname(path), raw.main);
953
- const message = field("--message");
954
- const secrets = field("--secrets-file");
955
- return await withBuildOutput(raw, source, (directory) => runCf([
956
- ...args[0] === "deploy" ? ["deploy"] : [
940
+ const request = operation;
941
+ const called = await withBuildOutput(raw, source, (directory) => runCf([
942
+ ...request.type === "worker.deploy" ? ["deploy"] : [
957
943
  "workers",
958
944
  "versions",
959
945
  "create"
960
946
  ],
961
947
  "--prebuilt",
962
- ...message ? ["--message", message] : [],
963
- ...secrets ? ["--secrets-file", secrets] : [],
964
- ...args.includes("--dry-run") ? ["--dry-run"] : []
948
+ ...request.message ? ["--message", request.message] : [],
949
+ ...request.secretsFilePath ? ["--secrets-file", request.secretsFilePath] : []
965
950
  ], directory));
951
+ if (called.status !== 0) return called;
952
+ let uploaded = {};
953
+ try {
954
+ uploaded = object(parsedJson(called.stdout));
955
+ } catch {}
956
+ const output = called.stdout;
957
+ const versionId = uploaded.version_id ?? uploaded.id ?? uploaded.versionId ?? output.match(/(?:Worker|Current) Version ID:\s*([0-9a-f]{8}-[0-9a-f-]{27})/i)?.[1];
958
+ if (typeof versionId !== "string" || !/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(versionId)) throw new Error("Cloudflare did not return the uploaded Worker version ID.");
959
+ const previewUrl = typeof uploaded.preview_url === "string" ? uploaded.preview_url : output.match(/Version Preview(?: Alias)? URL:\s*(https:\/\/\S+)/i)?.[1];
960
+ const workersDevUrl = typeof uploaded.workers_dev_url === "string" ? uploaded.workers_dev_url : output.match(/(https:\/\/[a-z0-9.-]+\.workers\.dev(?:\/[^\s]*)?)/i)?.[1];
961
+ return result(0, "", called.stderr, {
962
+ versionId,
963
+ ...previewUrl ? { previewUrl } : {},
964
+ ...workersDevUrl ? { workersDevUrl } : {}
965
+ });
966
966
  }
967
- return result(1, "", `Unsupported Cloudflare Worker operation: ${args.slice(0, 2).join(" ")}.`);
967
+ throw new Error("Unsupported Cloudflare Worker operation.");
968
968
  }
969
969
  async function tail() {
970
- const worker = args[1];
971
- const accountId = process.env.CLOUDFLARE_ACCOUNT_ID ?? config().account_id;
972
- if (!worker || typeof accountId !== "string" || !accountId || worker !== workerName()) throw new Error("Cloudflare tail target is not pinned.");
970
+ if (operation.type !== "tail") throw new Error("Cloudflare tail operation is required.");
971
+ const worker = workerName();
972
+ const raw = config();
973
+ const accountId = process.env.CLOUDFLARE_ACCOUNT_ID ?? raw.account_id;
974
+ if (!worker || typeof accountId !== "string" || !accountId || worker !== raw.name) throw new Error("Cloudflare tail target is not pinned.");
973
975
  const filters = [];
974
- if (field("--search")) filters.push({ query: field("--search") });
975
- if (field("--version-id")) filters.push({ scriptVersion: field("--version-id") });
976
- if (field("--status") === "error") filters.push({ outcome: [
976
+ if (operation.search) filters.push({ query: operation.search });
977
+ if (operation.versionId) filters.push({ scriptVersion: operation.versionId });
978
+ if (operation.status === "error") filters.push({ outcome: [
977
979
  "exception",
978
980
  "exceededCpu",
979
981
  "exceededMemory",
@@ -1010,25 +1012,29 @@ async function tail() {
1010
1012
  if (stopped.signal.aborted) return result(0);
1011
1013
  await new Promise((resolve, reject) => {
1012
1014
  finish = resolve;
1015
+ let pendingMessages = Promise.resolve();
1013
1016
  socket = new WebSocket(tailUrl, "trace-v1");
1014
1017
  socket.addEventListener("open", () => {
1015
1018
  socket.send(JSON.stringify({ debug: false }));
1016
1019
  });
1017
1020
  socket.addEventListener("message", (event) => {
1018
- try {
1019
- const log = object(parsedJson(String(event.data)));
1021
+ pendingMessages = pendingMessages.then(async () => {
1022
+ const data = event.data;
1023
+ const text = typeof data === "string" ? data : data instanceof Blob ? await data.text() : data instanceof ArrayBuffer ? new TextDecoder().decode(data) : null;
1024
+ if (text === null) throw new Error("Unsupported Cloudflare tail frame.");
1025
+ const log = object(parsedJson(text));
1020
1026
  const detail = object(log.event ?? {});
1021
1027
  const request = object(detail.request ?? {});
1022
1028
  const prefix = typeof request.url === "string" ? `${request.method ?? "GET"} ${request.url}` : typeof detail.queue === "string" ? `Queue ${detail.queue}` : typeof detail.mailFrom === "string" ? `Email from ${detail.mailFrom}` : "Worker event";
1023
1029
  process.stdout.write(`${prefix} - ${log.outcome ?? "unknown"} @ ${new Date(Number(log.eventTimestamp)).toLocaleString()}\n`);
1024
1030
  if (Array.isArray(log.logs)) for (const line of log.logs.map(object)) process.stdout.write(` (${line.level ?? "log"}) ${Array.isArray(line.message) ? line.message.join(" ") : ""}\n`);
1025
1031
  if (Array.isArray(log.exceptions)) for (const exception of log.exceptions.map(object)) process.stderr.write(` ${exception.name ?? "Error"}: ${exception.message ?? ""}\n`);
1026
- } catch {
1032
+ }).catch(() => {
1027
1033
  process.stderr.write("Cloudflare returned a malformed tail event.\n");
1028
- }
1034
+ });
1029
1035
  });
1030
1036
  socket.addEventListener("error", () => reject(/* @__PURE__ */ new Error("Cloudflare Worker tail connection failed.")));
1031
- socket.addEventListener("close", () => resolve());
1037
+ socket.addEventListener("close", () => void pendingMessages.then(resolve));
1032
1038
  if (stopped.signal.aborted) resolve();
1033
1039
  });
1034
1040
  } catch (error) {
@@ -1048,34 +1054,49 @@ async function tail() {
1048
1054
  return result(0);
1049
1055
  }
1050
1056
  async function main() {
1051
- if ([
1052
- "whoami",
1053
- "login",
1054
- "logout",
1055
- "auth"
1056
- ].includes(args[0] ?? "")) return auth();
1057
- if (args[0] === "secret") return await secrets();
1058
- if (args[0] === "tail") return await tail();
1059
- if (args[0] === "email") return email();
1060
- if (args[0] === "deployments" || args[0] === "versions" && args[1] !== "upload") return await workerHistory();
1061
- if (args[0] === "triggers" || args[0] === "deploy" || args[0] === "versions" && args[1] === "upload" || args[0] === "queues" && args[1] === "consumer") return await workerChanges();
1062
- if ([
1063
- "d1",
1064
- "kv",
1065
- "r2",
1066
- "hyperdrive",
1067
- "queues",
1068
- "containers"
1069
- ].includes(args[0] ?? "")) return await resources();
1070
- return result(1, "", `Unsupported Cloudflare operation: ${args.slice(0, 2).join(" ")}.`);
1057
+ if (process.argv.length !== 3) throw new Error("Exactly one typed Cloudflare operation is required.");
1058
+ if (!operation || typeof operation !== "object" || typeof operation.type !== "string") throw new Error("Cloudflare operation is required.");
1059
+ if (operation.type.startsWith("auth.")) return auth();
1060
+ if (operation.type.startsWith("secret.")) return secrets();
1061
+ if (operation.type === "tail") return tail();
1062
+ if (operation.type.startsWith("email.")) return email();
1063
+ if (operation.type.startsWith("deployments.") || operation.type.startsWith("versions.") && operation.type !== "versions.upload") return workerHistory();
1064
+ if (operation.type.startsWith("triggers.") || operation.type === "worker.deploy" || operation.type === "versions.upload" || operation.type === "queues.consumer.remove") return workerChanges();
1065
+ return resources();
1071
1066
  }
1072
1067
  try {
1073
1068
  const output = await main();
1074
- if (output.stdout) process.stdout.write(output.stdout);
1069
+ if (operation.type !== "auth.login" && operation.type !== "tail") {
1070
+ let data = output.data;
1071
+ let humanOutput = "";
1072
+ if (data === void 0 && output.stdout.trim()) try {
1073
+ data = parsedJson(output.stdout);
1074
+ } catch {
1075
+ humanOutput = output.stdout;
1076
+ }
1077
+ process.stdout.write(JSON.stringify({
1078
+ operationResult: 1,
1079
+ ...output.signal ? { signal: output.signal } : {},
1080
+ ...output.error ? { error: output.error } : {},
1081
+ ...data !== void 0 ? { data } : {},
1082
+ ...output.errorCode !== void 0 ? { errorCode: output.errorCode } : {},
1083
+ ...output.failure ? { failure: output.failure } : {},
1084
+ ...output.stderr ? { errors: [{
1085
+ code: output.errorCode,
1086
+ message: output.stderr
1087
+ }] } : {},
1088
+ ...humanOutput ? { output: humanOutput } : {}
1089
+ }) + "\n");
1090
+ }
1075
1091
  if (output.stderr) process.stderr.write(output.stderr);
1076
1092
  process.exitCode = output.status;
1077
1093
  } catch (error) {
1078
- process.stderr.write(error instanceof Error ? error.message : "Cloudflare command failed.");
1094
+ const message = error instanceof Error ? error.message : "Cloudflare operation failed.";
1095
+ if (operation?.type !== "auth.login" && operation?.type !== "tail") process.stdout.write(JSON.stringify({
1096
+ operationResult: 1,
1097
+ errors: [{ message }]
1098
+ }) + "\n");
1099
+ process.stderr.write(message);
1079
1100
  process.exitCode = 1;
1080
1101
  }
1081
1102
  //#endregion