devflare 1.0.0-next.19 → 1.0.0-next.20

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 (360) hide show
  1. package/LLM.md +6807 -888
  2. package/README.md +375 -957
  3. package/dist/account-05zgta47.js +475 -0
  4. package/dist/account-b2ag1esh.js +475 -0
  5. package/dist/account-bxtcz61a.js +475 -0
  6. package/dist/account-gyfqg964.js +475 -0
  7. package/dist/account-q6pvs9d9.js +475 -0
  8. package/dist/account-rp4zbvw1.js +475 -0
  9. package/dist/bridge/client.d.ts +5 -0
  10. package/dist/bridge/client.d.ts.map +1 -1
  11. package/dist/bridge/gateway-runtime.d.ts +1 -1
  12. package/dist/bridge/gateway-runtime.d.ts.map +1 -1
  13. package/dist/bridge/miniflare.d.ts +67 -0
  14. package/dist/bridge/miniflare.d.ts.map +1 -1
  15. package/dist/bridge/proxy.d.ts +2 -1
  16. package/dist/bridge/proxy.d.ts.map +1 -1
  17. package/dist/bridge/server.d.ts.map +1 -1
  18. package/dist/browser.d.ts +2520 -40
  19. package/dist/browser.d.ts.map +1 -1
  20. package/dist/browser.js +3 -3
  21. package/dist/build-2s5paw5p.js +54 -0
  22. package/dist/build-4c350cp7.js +54 -0
  23. package/dist/build-e7wym63t.js +54 -0
  24. package/dist/build-ge6qp3t4.js +54 -0
  25. package/dist/build-ta8c6t11.js +54 -0
  26. package/dist/build-wvjj8f28.js +54 -0
  27. package/dist/build-ypg6f2kw.js +54 -0
  28. package/dist/build-yts8wwgf.js +54 -0
  29. package/dist/build-yzkdqexs.js +54 -0
  30. package/dist/cli/build-manifest.d.ts +12 -0
  31. package/dist/cli/build-manifest.d.ts.map +1 -1
  32. package/dist/cli/commands/deploy/metadata.d.ts +18 -0
  33. package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
  34. package/dist/cli/commands/deploy/prepare.d.ts +23 -0
  35. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
  36. package/dist/cli/commands/deploy/runtime.d.ts +4 -0
  37. package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
  38. package/dist/cli/commands/deploy/verification.d.ts +36 -0
  39. package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
  40. package/dist/cli/commands/deploy.d.ts +2 -2
  41. package/dist/cli/commands/deploy.d.ts.map +1 -1
  42. package/dist/cli/commands/secrets.d.ts +4 -0
  43. package/dist/cli/commands/secrets.d.ts.map +1 -0
  44. package/dist/cli/commands/type-generation/generator.d.ts +67 -1
  45. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -1
  46. package/dist/cli/help-pages/pages/core.d.ts +1 -1
  47. package/dist/cli/help-pages/pages/core.d.ts.map +1 -1
  48. package/dist/cli/help-pages/shared.d.ts +1 -1
  49. package/dist/cli/help-pages/shared.d.ts.map +1 -1
  50. package/dist/cli/index.d.ts.map +1 -1
  51. package/dist/cli/index.js +2 -2
  52. package/dist/cli/package-metadata.d.ts.map +1 -1
  53. package/dist/cli/preview-bindings.d.ts.map +1 -1
  54. package/dist/cloudflare/index.js +2 -2
  55. package/dist/cloudflare/preview-registry-store.d.ts +1 -1
  56. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -1
  57. package/dist/cloudflare/types.d.ts +1 -1
  58. package/dist/cloudflare/types.d.ts.map +1 -1
  59. package/dist/config/binding-resolution-helpers.d.ts +5 -0
  60. package/dist/config/binding-resolution-helpers.d.ts.map +1 -1
  61. package/dist/config/compiler/bindings.d.ts +14 -0
  62. package/dist/config/compiler/bindings.d.ts.map +1 -0
  63. package/dist/config/compiler/core-helpers.d.ts +6 -0
  64. package/dist/config/compiler/core-helpers.d.ts.map +1 -0
  65. package/dist/config/compiler/do-workers.d.ts +34 -0
  66. package/dist/config/compiler/do-workers.d.ts.map +1 -0
  67. package/dist/config/compiler/paths.d.ts +18 -0
  68. package/dist/config/compiler/paths.d.ts.map +1 -0
  69. package/dist/config/compiler/types.d.ts +267 -0
  70. package/dist/config/compiler/types.d.ts.map +1 -0
  71. package/dist/config/compiler.d.ts +11 -175
  72. package/dist/config/compiler.d.ts.map +1 -1
  73. package/dist/config/deploy-resources.d.ts.map +1 -1
  74. package/dist/config/index.d.ts +1 -1
  75. package/dist/config/index.d.ts.map +1 -1
  76. package/dist/config/local-dev-vars.d.ts +15 -0
  77. package/dist/config/local-dev-vars.d.ts.map +1 -0
  78. package/dist/config/preview-resources.d.ts.map +1 -1
  79. package/dist/config/preview.d.ts.map +1 -1
  80. package/dist/config/resolve.d.ts.map +1 -1
  81. package/dist/config/resource-resolution.d.ts.map +1 -1
  82. package/dist/config/schema-bindings.d.ts +559 -19
  83. package/dist/config/schema-bindings.d.ts.map +1 -1
  84. package/dist/config/schema-env.d.ts +1306 -34
  85. package/dist/config/schema-env.d.ts.map +1 -1
  86. package/dist/config/schema-normalization.d.ts +97 -1
  87. package/dist/config/schema-normalization.d.ts.map +1 -1
  88. package/dist/config/schema-runtime.d.ts +245 -7
  89. package/dist/config/schema-runtime.d.ts.map +1 -1
  90. package/dist/config/schema.d.ts +2976 -57
  91. package/dist/config/schema.d.ts.map +1 -1
  92. package/dist/config-6m0n7d84.js +59 -0
  93. package/dist/config-7cf004ag.js +59 -0
  94. package/dist/config-b98dp58n.js +59 -0
  95. package/dist/config-cf3djhqy.js +59 -0
  96. package/dist/config-entry.js +1 -1
  97. package/dist/config-wa7hm0w9.js +59 -0
  98. package/dist/deploy-1jfagtn9.js +1055 -0
  99. package/dist/deploy-2afw0jfg.js +1055 -0
  100. package/dist/deploy-2fzj68kq.js +1055 -0
  101. package/dist/deploy-57nzn9wj.js +1045 -0
  102. package/dist/deploy-asyryrvm.js +1055 -0
  103. package/dist/deploy-hc927rw6.js +1045 -0
  104. package/dist/deploy-pnnf8tgy.js +1045 -0
  105. package/dist/deploy-q33bw715.js +1055 -0
  106. package/dist/deploy-tmdgecs3.js +1055 -0
  107. package/dist/deploy-v0y8kczr.js +1055 -0
  108. package/dist/deploy-xhj6zbcx.js +1055 -0
  109. package/dist/dev-1mvcts8w.js +2515 -0
  110. package/dist/dev-2a283xts.js +2515 -0
  111. package/dist/dev-62nhytf8.js +2505 -0
  112. package/dist/dev-75acm2xj.js +2478 -0
  113. package/dist/dev-802rg9dp.js +2515 -0
  114. package/dist/dev-d1bb2t0f.js +2515 -0
  115. package/dist/dev-dwry8494.js +2489 -0
  116. package/dist/dev-g6112y4w.js +2515 -0
  117. package/dist/dev-h2kneh95.js +2496 -0
  118. package/dist/dev-kybq3mwr.js +2489 -0
  119. package/dist/dev-n8qndkyg.js +2512 -0
  120. package/dist/dev-p32fkbwf.js +2489 -0
  121. package/dist/dev-qm9d4mfh.js +2478 -0
  122. package/dist/dev-rcthnse5.js +2473 -0
  123. package/dist/dev-server/dev-server-state.d.ts +1 -0
  124. package/dist/dev-server/dev-server-state.d.ts.map +1 -1
  125. package/dist/dev-server/miniflare-bindings.d.ts +44 -1
  126. package/dist/dev-server/miniflare-bindings.d.ts.map +1 -1
  127. package/dist/dev-server/miniflare-dev-config.d.ts +1 -0
  128. package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -1
  129. package/dist/dev-server/miniflare-log.d.ts +8 -0
  130. package/dist/dev-server/miniflare-log.d.ts.map +1 -1
  131. package/dist/dev-server/miniflare-worker-config.d.ts +31 -1
  132. package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -1
  133. package/dist/dev-server/server.d.ts.map +1 -1
  134. package/dist/dev-server/vite-process.d.ts +1 -0
  135. package/dist/dev-server/vite-process.d.ts.map +1 -1
  136. package/dist/dev-tgwja5mz.js +2496 -0
  137. package/dist/doctor-2shhdak6.js +245 -0
  138. package/dist/doctor-5g73w40j.js +245 -0
  139. package/dist/doctor-gamefzcs.js +245 -0
  140. package/dist/doctor-rn53ctfs.js +245 -0
  141. package/dist/index-01kehw41.js +348 -0
  142. package/dist/index-06bg0z9y.js +185 -0
  143. package/dist/index-0d7tw5r4.js +136 -0
  144. package/dist/index-0m6e4mxz.js +133 -0
  145. package/dist/index-0vah20er.js +1410 -0
  146. package/dist/index-0wa0ebm1.js +68 -0
  147. package/dist/index-1714y3cz.js +1410 -0
  148. package/dist/index-1qs5gcm7.js +895 -0
  149. package/dist/index-29k04v43.js +574 -0
  150. package/dist/index-2jywf4pz.js +1372 -0
  151. package/dist/index-2qhk9nbx.js +1372 -0
  152. package/dist/index-2vq6bveq.js +574 -0
  153. package/dist/index-36h8gkhb.js +1088 -0
  154. package/dist/index-38fq7pww.js +560 -0
  155. package/dist/index-3bxqn033.js +1410 -0
  156. package/dist/index-3jme4hgw.js +1234 -0
  157. package/dist/index-3p7s9mk9.js +360 -0
  158. package/dist/index-47w35sft.js +244 -0
  159. package/dist/index-4by4c7rm.js +52 -0
  160. package/dist/index-4phjwd6h.js +412 -0
  161. package/dist/index-4z5jrw0j.js +594 -0
  162. package/dist/index-51mzqy0d.js +895 -0
  163. package/dist/index-53pqqpq9.js +74 -0
  164. package/dist/index-5enq8ntr.js +1766 -0
  165. package/dist/index-5fnq9r9m.js +1410 -0
  166. package/dist/index-5w9f2b17.js +695 -0
  167. package/dist/index-627srx16.js +45 -0
  168. package/dist/index-6bqgf5x8.js +227 -0
  169. package/dist/index-6xknvbyk.js +1088 -0
  170. package/dist/index-7ef3ktz5.js +1372 -0
  171. package/dist/index-7hpjfdzh.js +185 -0
  172. package/dist/index-8052df4m.js +627 -0
  173. package/dist/index-82epjzrr.js +1410 -0
  174. package/dist/index-82z7rvz6.js +1238 -0
  175. package/dist/index-8atc1yb9.js +68 -0
  176. package/dist/index-8tj0awnv.js +476 -0
  177. package/dist/index-8x745h59.js +1069 -0
  178. package/dist/index-9bawzcny.js +574 -0
  179. package/dist/index-9bjjqdfc.js +236 -0
  180. package/dist/index-9d7x3vfr.js +236 -0
  181. package/dist/index-9nf8zs4p.js +1069 -0
  182. package/dist/index-acwbmagz.js +412 -0
  183. package/dist/index-aqjdaem7.js +74 -0
  184. package/dist/index-b6448fd0.js +133 -0
  185. package/dist/index-b9j55r7q.js +240 -0
  186. package/dist/index-bdatd1za.js +1372 -0
  187. package/dist/index-c3nxftnp.js +699 -0
  188. package/dist/index-c643s0gv.js +488 -0
  189. package/dist/index-d2md1j3d.js +185 -0
  190. package/dist/index-dbr6bfz6.js +528 -0
  191. package/dist/index-dd1g0g7e.js +360 -0
  192. package/dist/index-dktb9az5.js +1372 -0
  193. package/dist/index-dm9q84c7.js +360 -0
  194. package/dist/index-f51mkh13.js +1088 -0
  195. package/dist/index-f86n1fpd.js +55 -0
  196. package/dist/index-fnk0tkw7.js +412 -0
  197. package/dist/index-g5aq66bj.js +1534 -0
  198. package/dist/index-gj5qh491.js +54 -0
  199. package/dist/index-gq39t0rx.js +895 -0
  200. package/dist/index-h5dqna7q.js +1410 -0
  201. package/dist/index-hjs9j2g9.js +895 -0
  202. package/dist/index-hn5nbxbt.js +147 -0
  203. package/dist/index-hpjh0qjx.js +1723 -0
  204. package/dist/index-hs6ekcfs.js +412 -0
  205. package/dist/index-jdzrvnfj.js +52 -0
  206. package/dist/index-jg720mq7.js +476 -0
  207. package/dist/index-jrzddxvt.js +2167 -0
  208. package/dist/index-kgstnk6g.js +239 -0
  209. package/dist/index-khnw972v.js +117 -0
  210. package/dist/index-kwqff3ba.js +1410 -0
  211. package/dist/index-m2v0fj08.js +74 -0
  212. package/dist/index-mjve6tqn.js +447 -0
  213. package/dist/index-mkxzgn0q.js +1372 -0
  214. package/dist/index-mzmq3v0d.js +1088 -0
  215. package/dist/index-ng9n3znd.js +1372 -0
  216. package/dist/index-nhbkm2ba.js +467 -0
  217. package/dist/index-nrfhk0k5.js +1088 -0
  218. package/dist/index-p0zppqxm.js +467 -0
  219. package/dist/index-pkxf6h87.js +895 -0
  220. package/dist/index-pqp4312v.js +52 -0
  221. package/dist/index-pw9jn6kz.js +574 -0
  222. package/dist/index-q31ne0xa.js +412 -0
  223. package/dist/index-qf2dkqxh.js +249 -0
  224. package/dist/index-qmtdf7k5.js +639 -0
  225. package/dist/index-qwgr4q7s.js +37 -0
  226. package/dist/index-rab2dfh3.js +494 -0
  227. package/dist/index-rz7rx80s.js +1410 -0
  228. package/dist/index-s37h3jgk.js +572 -0
  229. package/dist/index-sb705m7d.js +52 -0
  230. package/dist/index-syscwrjp.js +1576 -0
  231. package/dist/index-t14zr0ys.js +1063 -0
  232. package/dist/index-tjc99447.js +68 -0
  233. package/dist/index-v35460hf.js +574 -0
  234. package/dist/index-v7q00d1e.js +1410 -0
  235. package/dist/index-vkkmx4xe.js +1372 -0
  236. package/dist/index-vrps1gky.js +2202 -0
  237. package/dist/index-w4c9vmvg.js +1517 -0
  238. package/dist/index-wqd8n2qk.js +574 -0
  239. package/dist/index-x12e6fzy.js +476 -0
  240. package/dist/index-xagpz645.js +2199 -0
  241. package/dist/index-xbth1r6e.js +572 -0
  242. package/dist/index-xm9fqhcb.js +447 -0
  243. package/dist/index-y59hnmd0.js +132 -0
  244. package/dist/index-y7mkb00x.js +133 -0
  245. package/dist/index-z40mjts9.js +212 -0
  246. package/dist/index-z5k5bjc7.js +1218 -0
  247. package/dist/index-z73sytma.js +895 -0
  248. package/dist/index-zjv6apef.js +1410 -0
  249. package/dist/index.js +8 -8
  250. package/dist/init-cwpergap.js +180 -0
  251. package/dist/login-83bjfhvz.js +77 -0
  252. package/dist/login-ddw888xb.js +77 -0
  253. package/dist/login-e7pytkdc.js +77 -0
  254. package/dist/login-fe0brfcr.js +77 -0
  255. package/dist/login-h7sm5trm.js +77 -0
  256. package/dist/login-vd0m3xr4.js +77 -0
  257. package/dist/previews-2wfvsjfy.js +1337 -0
  258. package/dist/previews-31feb8r3.js +1337 -0
  259. package/dist/previews-3w4pxqby.js +1337 -0
  260. package/dist/previews-93ttrf5f.js +1337 -0
  261. package/dist/previews-bdrefjzx.js +1337 -0
  262. package/dist/previews-cfcn56b4.js +1337 -0
  263. package/dist/previews-mssq1hrm.js +1337 -0
  264. package/dist/previews-tcaz1gt8.js +1337 -0
  265. package/dist/productions-4h80j2c7.js +505 -0
  266. package/dist/productions-86jaqt7m.js +505 -0
  267. package/dist/productions-bn2q31my.js +505 -0
  268. package/dist/productions-dv8g7f6g.js +505 -0
  269. package/dist/productions-e2m9s4tr.js +505 -0
  270. package/dist/productions-fgshs1m7.js +505 -0
  271. package/dist/productions-hphmt68n.js +505 -0
  272. package/dist/productions-vhq7yx86.js +505 -0
  273. package/dist/runtime/index.js +8 -8
  274. package/dist/secrets/local-secrets.d.ts +46 -0
  275. package/dist/secrets/local-secrets.d.ts.map +1 -0
  276. package/dist/secrets-8wcj47nh.js +91 -0
  277. package/dist/secrets-b2ww34ta.js +91 -0
  278. package/dist/secrets-b7g4z621.js +91 -0
  279. package/dist/shims/local-media-bindings.d.ts +19 -0
  280. package/dist/shims/local-media-bindings.d.ts.map +1 -0
  281. package/dist/shims/local-worker-loader.d.ts +3 -0
  282. package/dist/shims/local-worker-loader.d.ts.map +1 -0
  283. package/dist/sveltekit/index.js +163 -26
  284. package/dist/sveltekit/local-bindings.d.ts +4 -0
  285. package/dist/sveltekit/local-bindings.d.ts.map +1 -0
  286. package/dist/sveltekit/platform.d.ts +8 -0
  287. package/dist/sveltekit/platform.d.ts.map +1 -1
  288. package/dist/test/ai-search.d.ts +39 -0
  289. package/dist/test/ai-search.d.ts.map +1 -0
  290. package/dist/test/binding-hints.d.ts.map +1 -1
  291. package/dist/test/cf.d.ts +3 -3
  292. package/dist/test/containers.d.ts +87 -0
  293. package/dist/test/containers.d.ts.map +1 -0
  294. package/dist/test/index.d.ts +4 -1
  295. package/dist/test/index.d.ts.map +1 -1
  296. package/dist/test/index.js +2833 -543
  297. package/dist/test/local-worker-loader.d.ts +3 -0
  298. package/dist/test/local-worker-loader.d.ts.map +1 -0
  299. package/dist/test/offline-bindings.d.ts +65 -0
  300. package/dist/test/offline-bindings.d.ts.map +1 -0
  301. package/dist/test/queue.d.ts.map +1 -1
  302. package/dist/test/remote-ai.d.ts.map +1 -1
  303. package/dist/test/should-skip.d.ts +14 -0
  304. package/dist/test/should-skip.d.ts.map +1 -1
  305. package/dist/test/simple-context-bindings.d.ts.map +1 -1
  306. package/dist/test/simple-context-durable-objects.d.ts.map +1 -1
  307. package/dist/test/simple-context-gateway-script.d.ts +1 -1
  308. package/dist/test/simple-context-gateway-script.d.ts.map +1 -1
  309. package/dist/test/simple-context-lifecycle.d.ts.map +1 -1
  310. package/dist/test/simple-context-mfconfig.d.ts +4 -1
  311. package/dist/test/simple-context-mfconfig.d.ts.map +1 -1
  312. package/dist/test/simple-context-multi-worker.d.ts.map +1 -1
  313. package/dist/test/simple-context-startup.d.ts.map +1 -1
  314. package/dist/test/tail.d.ts.map +1 -1
  315. package/dist/test/utilities/artifacts.d.ts +11 -0
  316. package/dist/test/utilities/artifacts.d.ts.map +1 -0
  317. package/dist/test/utilities/context.d.ts +39 -0
  318. package/dist/test/utilities/context.d.ts.map +1 -0
  319. package/dist/test/utilities/d1.d.ts +21 -0
  320. package/dist/test/utilities/d1.d.ts.map +1 -0
  321. package/dist/test/utilities/env.d.ts +40 -0
  322. package/dist/test/utilities/env.d.ts.map +1 -0
  323. package/dist/test/utilities/kv.d.ts +11 -0
  324. package/dist/test/utilities/kv.d.ts.map +1 -0
  325. package/dist/test/utilities/media.d.ts +16 -0
  326. package/dist/test/utilities/media.d.ts.map +1 -0
  327. package/dist/test/utilities/platform.d.ts +38 -0
  328. package/dist/test/utilities/platform.d.ts.map +1 -0
  329. package/dist/test/utilities/queue.d.ts +5 -0
  330. package/dist/test/utilities/queue.d.ts.map +1 -0
  331. package/dist/test/utilities/r2.d.ts +12 -0
  332. package/dist/test/utilities/r2.d.ts.map +1 -0
  333. package/dist/test/utilities/workflows.d.ts +26 -0
  334. package/dist/test/utilities/workflows.d.ts.map +1 -0
  335. package/dist/test/utilities.d.ts +10 -106
  336. package/dist/test/utilities.d.ts.map +1 -1
  337. package/dist/types-2ejrbba1.js +695 -0
  338. package/dist/types-7jkbm95a.js +695 -0
  339. package/dist/types-a2fk9yns.js +695 -0
  340. package/dist/types-dyb3c6zw.js +695 -0
  341. package/dist/types-e2n9f3pd.js +695 -0
  342. package/dist/types-j4s6qcrc.js +695 -0
  343. package/dist/utils/send-email.d.ts.map +1 -1
  344. package/dist/utils/send-email.js +1 -1
  345. package/dist/vite/index.js +6 -6
  346. package/dist/vite/plugin-context.d.ts.map +1 -1
  347. package/dist/worker-663em30d.js +513 -0
  348. package/dist/worker-argxc7fb.js +513 -0
  349. package/dist/worker-entry/composed-worker.d.ts.map +1 -1
  350. package/dist/worker-entry/surface-paths.d.ts +2 -0
  351. package/dist/worker-entry/surface-paths.d.ts.map +1 -1
  352. package/dist/worker-fcdsnj14.js +513 -0
  353. package/dist/worker-fk42rzse.js +513 -0
  354. package/dist/worker-jkemk8d2.js +513 -0
  355. package/dist/worker-m4ze8djx.js +513 -0
  356. package/dist/worker-wnan5dca.js +513 -0
  357. package/dist/worker-yw3atfb1.js +513 -0
  358. package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
  359. package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
  360. package/package.json +13 -12
@@ -0,0 +1,74 @@
1
+ import {
2
+ loadConfig,
3
+ resolveConfigPath
4
+ } from "./index-g5aq66bj.js";
5
+ import {
6
+ getEffectiveAccountId,
7
+ getPrimaryAccount,
8
+ getWorkspaceAccountId
9
+ } from "./index-1d4jg11n.js";
10
+
11
+ // src/cli/command-utils.ts
12
+ function asOptionalString(value) {
13
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
14
+ }
15
+ function resolveNamedSelection(options) {
16
+ if (options.explicitValue) {
17
+ return {
18
+ value: options.explicitValue,
19
+ source: "option"
20
+ };
21
+ }
22
+ if (options.fallbackValue) {
23
+ return {
24
+ value: options.fallbackValue,
25
+ source: "arg"
26
+ };
27
+ }
28
+ if (options.configuredValue) {
29
+ return {
30
+ value: options.configuredValue,
31
+ source: "config"
32
+ };
33
+ }
34
+ return {
35
+ value: undefined,
36
+ source: "none"
37
+ };
38
+ }
39
+ async function getConfiguredAccountId(cwd) {
40
+ const workspaceAccountId = getWorkspaceAccountId();
41
+ if (workspaceAccountId) {
42
+ return workspaceAccountId;
43
+ }
44
+ const envAccountId = process.env.CLOUDFLARE_ACCOUNT_ID?.trim();
45
+ if (envAccountId) {
46
+ return envAccountId;
47
+ }
48
+ const configPath = await resolveConfigPath(cwd);
49
+ if (!configPath) {
50
+ return;
51
+ }
52
+ try {
53
+ const config = await loadConfig({ cwd });
54
+ return config.accountId;
55
+ } catch {
56
+ return;
57
+ }
58
+ }
59
+ async function resolveCloudflareAccountId(options) {
60
+ if (options.explicitAccountId) {
61
+ return options.explicitAccountId;
62
+ }
63
+ if (options.configuredAccountId) {
64
+ return options.configuredAccountId;
65
+ }
66
+ const primaryAccount = await getPrimaryAccount(options.apiOptions);
67
+ if (!primaryAccount) {
68
+ return;
69
+ }
70
+ const effective = await getEffectiveAccountId(primaryAccount.id);
71
+ return effective.accountId;
72
+ }
73
+
74
+ export { asOptionalString, resolveNamedSelection, getConfiguredAccountId, resolveCloudflareAccountId };
@@ -0,0 +1,447 @@
1
+ // src/bridge/gateway-runtime.ts
2
+ var GATEWAY_RUNTIME_JS = `
3
+ const RAW_EMAIL = 'EmailMessage::raw'
4
+
5
+ function arrayBufferToBase64(buffer) {
6
+ const bytes = new Uint8Array(buffer)
7
+ let binary = ''
8
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i])
9
+ return btoa(binary)
10
+ }
11
+
12
+ function base64ToArrayBuffer(base64) {
13
+ const binary = atob(base64)
14
+ const bytes = new Uint8Array(binary.length)
15
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)
16
+ return bytes.buffer
17
+ }
18
+
19
+ function serializeR2Object(obj) {
20
+ if (!obj) return null
21
+ return {
22
+ __type: 'R2Object',
23
+ key: obj.key,
24
+ version: obj.version,
25
+ size: obj.size,
26
+ etag: obj.etag,
27
+ httpEtag: obj.httpEtag,
28
+ checksums: obj.checksums,
29
+ uploaded: obj.uploaded?.toISOString(),
30
+ httpMetadata: obj.httpMetadata,
31
+ customMetadata: obj.customMetadata,
32
+ range: obj.range,
33
+ storageClass: obj.storageClass
34
+ }
35
+ }
36
+
37
+ function serializeR2ObjectBody(obj, bodyData) {
38
+ if (!obj) return null
39
+ return {
40
+ __type: 'R2ObjectBody',
41
+ key: obj.key,
42
+ version: obj.version,
43
+ size: obj.size,
44
+ etag: obj.etag,
45
+ httpEtag: obj.httpEtag,
46
+ checksums: obj.checksums,
47
+ uploaded: obj.uploaded?.toISOString(),
48
+ httpMetadata: obj.httpMetadata,
49
+ customMetadata: obj.customMetadata,
50
+ range: obj.range,
51
+ storageClass: obj.storageClass,
52
+ bodyData
53
+ }
54
+ }
55
+
56
+ function serializeR2Objects(result) {
57
+ if (!result) return null
58
+ return {
59
+ objects: result.objects.map(serializeR2Object),
60
+ truncated: result.truncated,
61
+ cursor: result.cursor,
62
+ delimitedPrefixes: result.delimitedPrefixes
63
+ }
64
+ }
65
+
66
+ async function serializeResponse(response) {
67
+ let body = null
68
+ if (response.body) {
69
+ const bytes = await response.arrayBuffer()
70
+ if (bytes.byteLength > 0) {
71
+ body = { type: 'bytes', data: arrayBufferToBase64(bytes) }
72
+ }
73
+ }
74
+ return {
75
+ status: response.status,
76
+ statusText: response.statusText,
77
+ headers: [...response.headers.entries()],
78
+ body
79
+ }
80
+ }
81
+
82
+ function createEmailMessageRaw(raw) {
83
+ if (typeof raw === 'string' || raw instanceof ReadableStream) {
84
+ return raw
85
+ }
86
+ if (raw instanceof ArrayBuffer || raw instanceof Uint8Array) {
87
+ return new Response(raw).body
88
+ }
89
+ throw new Error('Unsupported EmailMessage raw payload')
90
+ }
91
+
92
+ function isDurableObjectNamespace(binding) {
93
+ return !!binding
94
+ && typeof binding.idFromName === 'function'
95
+ && typeof binding.idFromString === 'function'
96
+ && typeof binding.newUniqueId === 'function'
97
+ }
98
+
99
+ /**
100
+ * Execute an RPC method against the gateway's bindings.
101
+ *
102
+ * Method format: "binding.operation". Operations must be namespaced by
103
+ * binding kind (e.g. "kv.get", "r2.head", "d1.stmt.first", "do.fetch",
104
+ * "queue.send", "email.send", "ai.run"). Bare verbs and the legacy
105
+ * "stmt.*" / "stub.*" sub-prefixes were removed in B3-final and now throw.
106
+ * Method vocabulary must stay in sync with the canonical server in
107
+ * src/bridge/server.ts.
108
+ */
109
+ async function executeRpcMethod(method, params, env, _ctx) {
110
+ const parts = method.split('.')
111
+ if (parts.length < 2) throw new Error('Invalid method format: ' + method)
112
+
113
+ const bindingName = parts[0]
114
+ const operation = parts.slice(1).join('.')
115
+ const binding = env[bindingName]
116
+
117
+ if (!binding) throw new Error('Binding not found: ' + bindingName)
118
+
119
+ const isNamespaced =
120
+ operation.indexOf('kv.') === 0 ||
121
+ operation.indexOf('r2.') === 0 ||
122
+ operation.indexOf('d1.') === 0 ||
123
+ operation.indexOf('do.') === 0 ||
124
+ operation.indexOf('queue.') === 0 ||
125
+ operation.indexOf('email.') === 0 ||
126
+ operation.indexOf('ai.') === 0 ||
127
+ operation.indexOf('var.') === 0
128
+ if (!isNamespaced) {
129
+ throw new Error(
130
+ "[devflare][bridge] Unsupported bridge operation '" + operation + "' for binding '" + bindingName + "'. "
131
+ + "Bare verbs and the legacy stmt.*/stub.* sub-prefixes were removed in B3-final; "
132
+ + "use the namespaced form (e.g. kv.get, r2.put, d1.stmt.first, do.fetch)."
133
+ )
134
+ }
135
+
136
+ // KV
137
+ if (operation === 'kv.get') return binding.get(params[0], params[1])
138
+ if (operation === 'kv.put') return binding.put(params[0], params[1], params[2])
139
+ if (operation === 'kv.delete') return binding.delete(params[0])
140
+ if (operation === 'kv.list') return binding.list(params[0])
141
+ if (operation === 'kv.getWithMetadata') return binding.getWithMetadata(params[0], params[1])
142
+
143
+ // DO get (returns DOStub reference)
144
+ if (operation === 'do.get') {
145
+ return { __type: 'DOStub', binding: bindingName, id: params[0] }
146
+ }
147
+
148
+ // R2
149
+ if (operation === 'r2.head') return serializeR2Object(await binding.head(params[0]))
150
+ if (operation === 'r2.get') {
151
+ const obj = await binding.get(params[0], params[1])
152
+ if (!obj) return null
153
+ const body = await obj.arrayBuffer()
154
+ return serializeR2ObjectBody(obj, arrayBufferToBase64(body))
155
+ }
156
+ if (operation === 'r2.put') {
157
+ let value = params[1]
158
+ if (value && typeof value === 'object') {
159
+ if (value.__type === 'ArrayBuffer' || value.__type === 'Uint8Array') {
160
+ value = base64ToArrayBuffer(value.data)
161
+ }
162
+ }
163
+ return serializeR2Object(await binding.put(params[0], value, params[2]))
164
+ }
165
+ if (operation === 'r2.delete') return binding.delete(params[0])
166
+ if (operation === 'r2.list') return serializeR2Objects(await binding.list(params[0]))
167
+
168
+ // D1
169
+ if (operation === 'd1.exec') return binding.exec(params[0])
170
+ if (operation === 'd1.batch') {
171
+ const statements = params[0].map((s) => binding.prepare(s.sql).bind(...(s.bindings || [])))
172
+ return binding.batch(statements)
173
+ }
174
+ if (operation.indexOf('d1.stmt.') === 0) {
175
+ const mode = operation.split('.')[2]
176
+ const [sql, ...rest] = params
177
+ let bindings = rest
178
+ let extraParam
179
+ if (mode === 'first' || mode === 'raw') {
180
+ extraParam = rest[rest.length - 1]
181
+ bindings = rest.slice(0, -1)
182
+ }
183
+ let stmt = binding.prepare(sql)
184
+ if (bindings.length > 0) stmt = stmt.bind(...bindings)
185
+ if (mode === 'first') {
186
+ if (typeof extraParam === 'string' && extraParam.length > 0) return stmt.first(extraParam)
187
+ return stmt.first()
188
+ }
189
+ if (mode === 'all') return stmt.all()
190
+ if (mode === 'run') return stmt.run()
191
+ if (mode === 'raw') return stmt.raw(extraParam)
192
+ throw new Error('Unknown stmt mode: ' + mode)
193
+ }
194
+
195
+ // Durable Objects
196
+ if (operation === 'do.idFromName') {
197
+ const id = binding.idFromName(params[0])
198
+ return { __type: 'DOId', hex: id.toString() }
199
+ }
200
+ if (operation === 'do.idFromString') {
201
+ const id = binding.idFromString(params[0])
202
+ return { __type: 'DOId', hex: id.toString() }
203
+ }
204
+ if (operation === 'do.newUniqueId') {
205
+ const id = binding.newUniqueId(params[0])
206
+ return { __type: 'DOId', hex: id.toString() }
207
+ }
208
+ if (operation === 'do.fetch') {
209
+ const [, serializedId, serializedReq] = params
210
+ const id = binding.idFromString(serializedId.hex)
211
+ const stub = binding.get(id)
212
+ const response = await stub.fetch(new Request(serializedReq.url, {
213
+ method: serializedReq.method,
214
+ headers: serializedReq.headers,
215
+ body: serializedReq.body?.type === 'bytes'
216
+ ? base64ToArrayBuffer(serializedReq.body.data)
217
+ : undefined
218
+ }))
219
+ return serializeResponse(response)
220
+ }
221
+ if (operation === 'do.rpc') {
222
+ const [, serializedId, methodName, args] = params
223
+ const id = binding.idFromString(serializedId.hex)
224
+ const stub = binding.get(id)
225
+ const response = await stub.fetch(new Request('http://do/_rpc', {
226
+ method: 'POST',
227
+ headers: { 'Content-Type': 'application/json' },
228
+ body: JSON.stringify({ method: methodName, params: args })
229
+ }))
230
+ const result = await response.json()
231
+ if (!result.ok) throw new Error(result.error?.message || 'RPC failed')
232
+ return result.result
233
+ }
234
+
235
+ // Queues
236
+ if (operation === 'queue.send') return binding.send(params[0], params[1])
237
+ if (operation === 'queue.sendBatch') return binding.sendBatch(params[0], params[1])
238
+
239
+ // Send Email
240
+ if (operation === 'email.send') {
241
+ if (binding && typeof binding.send === 'function') {
242
+ const message = params[0]
243
+ if (message && typeof message === 'object' && 'from' in message && 'to' in message && 'raw' in message) {
244
+ return binding.send({
245
+ from: message.from,
246
+ to: message.to,
247
+ [RAW_EMAIL]: createEmailMessageRaw(message.raw)
248
+ })
249
+ }
250
+ return binding.send(message)
251
+ }
252
+ return { ok: true, simulated: true }
253
+ }
254
+
255
+ // AI / generic run()
256
+ if (operation === 'ai.run') {
257
+ if (typeof binding.run !== 'function') {
258
+ throw new Error('Binding ' + bindingName + ' does not support run(): ' + method)
259
+ }
260
+ return binding.run(params[0], params[1])
261
+ }
262
+
263
+ throw new Error('Unknown operation: ' + method)
264
+ }
265
+
266
+ // ---------------------------------------------------------------------------
267
+ // WebSocket bridge (shared with src/bridge/server.ts in shape)
268
+ // ---------------------------------------------------------------------------
269
+ // NOTE: wsProxies is intentionally created per handleBridgeWebSocket call so
270
+ // state never leaks across connections or across gateway-script regenerations.
271
+
272
+ async function handleBridgeRpcCall(msg, ws, env, ctx) {
273
+ try {
274
+ const result = await executeRpcMethod(msg.method, msg.params, env, ctx)
275
+ ws.send(JSON.stringify({ t: 'rpc.ok', id: msg.id, result }))
276
+ } catch (error) {
277
+ ws.send(JSON.stringify({
278
+ t: 'rpc.err',
279
+ id: msg.id,
280
+ error: {
281
+ code: error?.code || 'INTERNAL_ERROR',
282
+ message: error?.message || String(error)
283
+ }
284
+ }))
285
+ }
286
+ }
287
+
288
+ async function handleBridgeWsOpen(msg, ws, env, wsProxies) {
289
+ try {
290
+ const binding = env[msg.target.binding]
291
+ const id = binding.idFromString(msg.target.id)
292
+ const stub = binding.get(id)
293
+
294
+ const headers = new Headers(msg.target.headers || [])
295
+ headers.set('Upgrade', 'websocket')
296
+
297
+ const response = await stub.fetch(new Request(msg.target.url, { method: 'GET', headers }))
298
+ const doWs = response.webSocket
299
+
300
+ if (!doWs) {
301
+ ws.send(JSON.stringify({
302
+ t: 'rpc.err',
303
+ id: 'ws_' + msg.wid,
304
+ error: { code: 'WS_FAILED', message: 'No WebSocket returned' }
305
+ }))
306
+ return
307
+ }
308
+
309
+ doWs.accept()
310
+ wsProxies.set(msg.wid, { doWs })
311
+
312
+ doWs.addEventListener('message', (event) => {
313
+ const isText = typeof event.data === 'string'
314
+ const data = isText ? event.data : arrayBufferToBase64(event.data)
315
+ ws.send(JSON.stringify({ t: 'ws.data', wid: msg.wid, data, isText }))
316
+ })
317
+
318
+ doWs.addEventListener('close', (event) => {
319
+ ws.send(JSON.stringify({ t: 'ws.close', wid: msg.wid, code: event.code, reason: event.reason }))
320
+ wsProxies.delete(msg.wid)
321
+ })
322
+
323
+ ws.send(JSON.stringify({ t: 'ws.opened', wid: msg.wid }))
324
+ } catch (error) {
325
+ ws.send(JSON.stringify({
326
+ t: 'rpc.err',
327
+ id: 'ws_' + msg.wid,
328
+ error: { code: 'WS_FAILED', message: error.message }
329
+ }))
330
+ }
331
+ }
332
+
333
+ function handleBridgeWsClose(msg, wsProxies) {
334
+ const proxy = wsProxies.get(msg.wid)
335
+ if (proxy) {
336
+ proxy.doWs.close(msg.code, msg.reason)
337
+ wsProxies.delete(msg.wid)
338
+ }
339
+ }
340
+
341
+ async function handleBridgeJsonMessage(data, ws, env, ctx, wsProxies) {
342
+ const msg = JSON.parse(data)
343
+ switch (msg.t) {
344
+ case 'hello':
345
+ // v2 handshake — acknowledge with welcome echoing the negotiated
346
+ // capability intersection. Capabilities advertised by the gateway
347
+ // are kept in sync with src/bridge/client.ts (BRIDGE_CLIENT_CAPABILITIES).
348
+ ws.send(JSON.stringify({
349
+ t: 'welcome',
350
+ protocolVersion: 2,
351
+ capabilities: ['streams', 'ws-relay', 'http-transfer']
352
+ .filter((c) => Array.isArray(msg.capabilities) && msg.capabilities.includes(c))
353
+ .sort()
354
+ }))
355
+ break
356
+ case 'rpc.call':
357
+ await handleBridgeRpcCall(msg, ws, env, ctx)
358
+ break
359
+ case 'ws.open':
360
+ await handleBridgeWsOpen(msg, ws, env, wsProxies)
361
+ break
362
+ case 'ws.close':
363
+ handleBridgeWsClose(msg, wsProxies)
364
+ break
365
+ }
366
+ }
367
+
368
+ function handleBridgeWebSocket(request, env, ctx) {
369
+ const { 0: client, 1: server } = new WebSocketPair()
370
+ server.accept()
371
+
372
+ // Per-connection state: recreated for every bridge client so reloads and
373
+ // concurrent clients never share WS proxy entries.
374
+ const wsProxies = new Map()
375
+
376
+ server.addEventListener('message', async (event) => {
377
+ try {
378
+ if (typeof event.data === 'string') {
379
+ await handleBridgeJsonMessage(event.data, server, env, ctx, wsProxies)
380
+ }
381
+ } catch (error) {
382
+ console.error('[Gateway] Error:', error)
383
+ }
384
+ })
385
+
386
+ server.addEventListener('close', () => {
387
+ for (const proxy of wsProxies.values()) {
388
+ // Best-effort cleanup: the DO-side WS may already be closed or in an
389
+ // invalid state; any throw here would abort sibling closes. Surface
390
+ // the swallowed error when DEVFLARE_DEBUG_BRIDGE is enabled.
391
+ try { proxy.doWs.close() } catch (error) {
392
+ if (globalThis.DEVFLARE_DEBUG_BRIDGE) {
393
+ console.warn('[devflare:bridge] proxy.doWs.close() failed', error)
394
+ }
395
+ }
396
+ }
397
+ wsProxies.clear()
398
+ })
399
+
400
+ return new Response(null, { status: 101, webSocket: client })
401
+ }
402
+
403
+ // ---------------------------------------------------------------------------
404
+ // HTTP transfer for R2 bodies (shared with src/bridge/server.ts in shape)
405
+ // ---------------------------------------------------------------------------
406
+
407
+ async function handleHttpTransfer(request, env, url) {
408
+ const transferIdEncoded = url.pathname.split('/').pop()
409
+ const transferId = decodeURIComponent(transferIdEncoded || '')
410
+ const [binding, ...keyParts] = transferId.split(':')
411
+ const key = keyParts.join(':')
412
+ const bucket = env[binding]
413
+
414
+ if (!bucket) return new Response('Bucket not found: ' + binding, { status: 404 })
415
+
416
+ if (request.method === 'PUT' || request.method === 'POST') {
417
+ const result = await bucket.put(key, request.body)
418
+ return new Response(JSON.stringify(serializeR2Object(result)), {
419
+ headers: { 'Content-Type': 'application/json' }
420
+ })
421
+ }
422
+
423
+ if (request.method === 'GET') {
424
+ const object = await bucket.get(key)
425
+ if (!object) return new Response('Not found', { status: 404 })
426
+ return new Response(object.body, {
427
+ headers: {
428
+ 'Content-Type': object.httpMetadata?.contentType || 'application/octet-stream',
429
+ 'Content-Length': String(object.size)
430
+ }
431
+ })
432
+ }
433
+
434
+ return new Response('Method not allowed', { status: 405 })
435
+ }
436
+ `;
437
+
438
+ // src/bridge/miniflare.ts
439
+ function isIgnorableMiniflareDisposeError(error) {
440
+ if (!(error instanceof Error)) {
441
+ return false;
442
+ }
443
+ const details = error;
444
+ return details.code === "EBADF" && details.syscall === "kill";
445
+ }
446
+
447
+ export { GATEWAY_RUNTIME_JS, isIgnorableMiniflareDisposeError };