devflare 1.0.0-next.5 → 1.0.0-next.50

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 (594) hide show
  1. package/LICENSE +21 -0
  2. package/LLM.md +17312 -2139
  3. package/README.md +394 -605
  4. package/bin/devflare.js +30 -14
  5. package/dist/_chunks/account-BI3WZMDy.js +462 -0
  6. package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
  7. package/dist/_chunks/ai-CBEuLdoP.js +322 -0
  8. package/dist/_chunks/api-TzdliH-6.js +568 -0
  9. package/dist/_chunks/build-artifacts-DU5V0J0Z.js +483 -0
  10. package/dist/_chunks/build-e0KR38-4.js +24 -0
  11. package/dist/_chunks/cli-DuUz10Mn.js +1163 -0
  12. package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
  13. package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
  14. package/dist/_chunks/command-utils-DA0Qx9_K.js +45 -0
  15. package/dist/_chunks/compiler-Zw16C9Pi.js +489 -0
  16. package/dist/_chunks/config-Brju62xy.js +78 -0
  17. package/dist/_chunks/config-path-DaL1ylZ_.js +42 -0
  18. package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
  19. package/dist/_chunks/decorators-QmV57ixr.js +19 -0
  20. package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
  21. package/dist/_chunks/deploy-B-Kku1Vk.js +1032 -0
  22. package/dist/_chunks/dev-D4e_RRZn.js +3471 -0
  23. package/dist/_chunks/doctor-jm_K4dxL.js +219 -0
  24. package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
  25. package/dist/_chunks/env-S0_nMVz1.js +125 -0
  26. package/dist/_chunks/family-_9-mGSfO.js +143 -0
  27. package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
  28. package/dist/_chunks/glob-CmQOvunB.js +56 -0
  29. package/dist/_chunks/init-DnkJOmpW.js +165 -0
  30. package/dist/_chunks/loader-Cr0_OWPy.js +1288 -0
  31. package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
  32. package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
  33. package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
  34. package/dist/_chunks/local-secrets-DMPkmOn3.js +123 -0
  35. package/dist/_chunks/local-workflow-entrypoints-Cq_WJajd.js +90 -0
  36. package/dist/_chunks/login-FjTAAQbi.js +51 -0
  37. package/dist/_chunks/package-metadata-DjHBLB-z.js +39 -0
  38. package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
  39. package/dist/_chunks/preview-C3Cdr8an.js +462 -0
  40. package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
  41. package/dist/_chunks/preview-resources-CGMBjsYB.js +359 -0
  42. package/dist/_chunks/previews-C7hs9-BT.js +1134 -0
  43. package/dist/_chunks/productions-T9Als4fE.js +411 -0
  44. package/dist/_chunks/ref-CYJNAAe_.js +178 -0
  45. package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
  46. package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
  47. package/dist/_chunks/resolve-package-qizBfCIm.js +152 -0
  48. package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
  49. package/dist/_chunks/routes-BFYCqHb-.js +833 -0
  50. package/dist/_chunks/runtime-DL-Nz3k8.js +550 -0
  51. package/dist/_chunks/schema-normalization-BCwTLTGp.js +660 -0
  52. package/dist/_chunks/secrets-DIpJGe6C.js +95 -0
  53. package/dist/_chunks/tail-IY-ijYmv.js +239 -0
  54. package/dist/_chunks/token-Dmi0KXyX.js +333 -0
  55. package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
  56. package/dist/_chunks/types-DoKsMYfm.js +484 -0
  57. package/dist/_chunks/ui-BUoZApvE.js +103 -0
  58. package/dist/_chunks/usage-BBTGzjon.js +272 -0
  59. package/dist/_chunks/vite-CGtVNf5E.js +1267 -0
  60. package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
  61. package/dist/_chunks/worker-BEZI4od1.js +410 -0
  62. package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
  63. package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
  64. package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
  65. package/dist/bridge/client.d.ts +49 -7
  66. package/dist/bridge/client.d.ts.map +1 -1
  67. package/dist/bridge/gateway-runtime.d.ts +8 -0
  68. package/dist/bridge/gateway-runtime.d.ts.map +1 -0
  69. package/dist/bridge/index.d.ts +6 -6
  70. package/dist/bridge/index.d.ts.map +1 -1
  71. package/dist/bridge/log.d.ts +5 -0
  72. package/dist/bridge/log.d.ts.map +1 -0
  73. package/dist/bridge/miniflare.d.ts +82 -2
  74. package/dist/bridge/miniflare.d.ts.map +1 -1
  75. package/dist/bridge/proxy.d.ts +12 -11
  76. package/dist/bridge/proxy.d.ts.map +1 -1
  77. package/dist/bridge/server.d.ts +2 -1
  78. package/dist/bridge/server.d.ts.map +1 -1
  79. package/dist/bridge/v2/body-streams.d.ts +53 -0
  80. package/dist/bridge/v2/body-streams.d.ts.map +1 -0
  81. package/dist/bridge/v2/codec.d.ts +106 -0
  82. package/dist/bridge/v2/codec.d.ts.map +1 -0
  83. package/dist/bridge/v2/control-messages.d.ts +46 -0
  84. package/dist/bridge/v2/control-messages.d.ts.map +1 -0
  85. package/dist/bridge/v2/frames.d.ts +109 -0
  86. package/dist/bridge/v2/frames.d.ts.map +1 -0
  87. package/dist/bridge/v2/index.d.ts +11 -0
  88. package/dist/bridge/v2/index.d.ts.map +1 -0
  89. package/dist/bridge/v2/serialization.d.ts +48 -0
  90. package/dist/bridge/v2/serialization.d.ts.map +1 -0
  91. package/dist/bridge/v2/transport.d.ts +31 -0
  92. package/dist/bridge/v2/transport.d.ts.map +1 -0
  93. package/dist/bridge/v2/value-codec.d.ts +61 -0
  94. package/dist/bridge/v2/value-codec.d.ts.map +1 -0
  95. package/dist/bridge/{serialization.d.ts → v2/value-serialization.d.ts} +40 -18
  96. package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
  97. package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +32 -8
  98. package/dist/bridge/v2/wire.d.ts.map +1 -0
  99. package/dist/bridge/v2/ws-relay.d.ts +53 -0
  100. package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
  101. package/dist/browser-shim/handler.d.ts +2 -2
  102. package/dist/browser-shim/handler.d.ts.map +1 -1
  103. package/dist/browser-shim/index.d.ts +2 -2
  104. package/dist/browser-shim/server.d.ts +63 -0
  105. package/dist/browser-shim/server.d.ts.map +1 -1
  106. package/dist/browser.d.ts +5411 -0
  107. package/dist/browser.d.ts.map +1 -0
  108. package/dist/browser.js +80 -0
  109. package/dist/bundler/defaults.d.ts +23 -0
  110. package/dist/bundler/defaults.d.ts.map +1 -0
  111. package/dist/bundler/do-bundler.d.ts +7 -0
  112. package/dist/bundler/do-bundler.d.ts.map +1 -1
  113. package/dist/bundler/index.d.ts +3 -1
  114. package/dist/bundler/index.d.ts.map +1 -1
  115. package/dist/bundler/rolldown-shared.d.ts +53 -0
  116. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  117. package/dist/bundler/worker-bundler.d.ts +13 -0
  118. package/dist/bundler/worker-bundler.d.ts.map +1 -0
  119. package/dist/bundler/worker-compat.d.ts +4 -0
  120. package/dist/bundler/worker-compat.d.ts.map +1 -0
  121. package/dist/cli/build-manifest.d.ts +66 -0
  122. package/dist/cli/build-manifest.d.ts.map +1 -0
  123. package/dist/cli/command-utils.d.ts +18 -0
  124. package/dist/cli/command-utils.d.ts.map +1 -0
  125. package/dist/cli/commands/account.d.ts +2 -2
  126. package/dist/cli/commands/account.d.ts.map +1 -1
  127. package/dist/cli/commands/ai.d.ts +1 -1
  128. package/dist/cli/commands/ai.d.ts.map +1 -1
  129. package/dist/cli/commands/build-artifacts.d.ts +40 -0
  130. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  131. package/dist/cli/commands/build.d.ts +2 -2
  132. package/dist/cli/commands/build.d.ts.map +1 -1
  133. package/dist/cli/commands/config.d.ts +4 -0
  134. package/dist/cli/commands/config.d.ts.map +1 -0
  135. package/dist/cli/commands/deploy/metadata.d.ts +18 -0
  136. package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
  137. package/dist/cli/commands/deploy/prepare.d.ts +23 -0
  138. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
  139. package/dist/cli/commands/deploy/runtime.d.ts +4 -0
  140. package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
  141. package/dist/cli/commands/deploy/verification.d.ts +36 -0
  142. package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
  143. package/dist/cli/commands/deploy.d.ts +2 -2
  144. package/dist/cli/commands/deploy.d.ts.map +1 -1
  145. package/dist/cli/commands/dev.d.ts +9 -1
  146. package/dist/cli/commands/dev.d.ts.map +1 -1
  147. package/dist/cli/commands/doctor.d.ts +2 -2
  148. package/dist/cli/commands/doctor.d.ts.map +1 -1
  149. package/dist/cli/commands/init.d.ts +2 -2
  150. package/dist/cli/commands/init.d.ts.map +1 -1
  151. package/dist/cli/commands/login.d.ts +4 -0
  152. package/dist/cli/commands/login.d.ts.map +1 -0
  153. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  154. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  155. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  156. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  157. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  158. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  159. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  160. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  161. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  162. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  163. package/dist/cli/commands/previews.d.ts +4 -0
  164. package/dist/cli/commands/previews.d.ts.map +1 -0
  165. package/dist/cli/commands/productions.d.ts +4 -0
  166. package/dist/cli/commands/productions.d.ts.map +1 -0
  167. package/dist/cli/commands/remote.d.ts +1 -1
  168. package/dist/cli/commands/remote.d.ts.map +1 -1
  169. package/dist/cli/commands/secrets.d.ts +4 -0
  170. package/dist/cli/commands/secrets.d.ts.map +1 -0
  171. package/dist/cli/commands/tail.d.ts +44 -0
  172. package/dist/cli/commands/tail.d.ts.map +1 -0
  173. package/dist/cli/commands/token.d.ts +4 -0
  174. package/dist/cli/commands/token.d.ts.map +1 -0
  175. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  176. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  177. package/dist/cli/commands/type-generation/generator.d.ts +121 -0
  178. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  179. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  180. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  181. package/dist/cli/commands/types.d.ts +2 -2
  182. package/dist/cli/commands/types.d.ts.map +1 -1
  183. package/dist/cli/commands/worker.d.ts +4 -0
  184. package/dist/cli/commands/worker.d.ts.map +1 -0
  185. package/dist/cli/config-path.d.ts +6 -0
  186. package/dist/cli/config-path.d.ts.map +1 -0
  187. package/dist/cli/dependencies.d.ts +2 -1
  188. package/dist/cli/dependencies.d.ts.map +1 -1
  189. package/dist/cli/deploy-strategy.d.ts +17 -0
  190. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  191. package/dist/cli/deploy-target.d.ts +17 -0
  192. package/dist/cli/deploy-target.d.ts.map +1 -0
  193. package/dist/cli/generated-artifacts.d.ts +12 -0
  194. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  195. package/dist/cli/gradual-deploy.d.ts +49 -0
  196. package/dist/cli/gradual-deploy.d.ts.map +1 -0
  197. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  198. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  199. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  200. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  201. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  202. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  203. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  204. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  205. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  206. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  207. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  208. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  209. package/dist/cli/help-pages/render.d.ts +12 -0
  210. package/dist/cli/help-pages/render.d.ts.map +1 -0
  211. package/dist/cli/help-pages/shared.d.ts +15 -0
  212. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  213. package/dist/cli/help-pages/types.d.ts +23 -0
  214. package/dist/cli/help-pages/types.d.ts.map +1 -0
  215. package/dist/cli/help.d.ts +6 -0
  216. package/dist/cli/help.d.ts.map +1 -0
  217. package/dist/cli/index.d.ts +1 -0
  218. package/dist/cli/index.d.ts.map +1 -1
  219. package/dist/cli/index.js +2 -0
  220. package/dist/cli/package-metadata.d.ts +16 -0
  221. package/dist/cli/package-metadata.d.ts.map +1 -0
  222. package/dist/cli/preview-bindings.d.ts +49 -0
  223. package/dist/cli/preview-bindings.d.ts.map +1 -0
  224. package/dist/cli/preview.d.ts +10 -0
  225. package/dist/cli/preview.d.ts.map +1 -0
  226. package/dist/cli/ui.d.ts +37 -0
  227. package/dist/cli/ui.d.ts.map +1 -0
  228. package/dist/cli/workspace-build-guard.d.ts +14 -0
  229. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  230. package/dist/cli/wrangler-auth.d.ts +1 -1
  231. package/dist/cloudflare/account-core.d.ts +6 -0
  232. package/dist/cloudflare/account-core.d.ts.map +1 -0
  233. package/dist/cloudflare/account-resources.d.ts +40 -0
  234. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  235. package/dist/cloudflare/account-status.d.ts +11 -0
  236. package/dist/cloudflare/account-status.d.ts.map +1 -0
  237. package/dist/cloudflare/account-workers.d.ts +14 -0
  238. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  239. package/dist/cloudflare/account.d.ts +7 -64
  240. package/dist/cloudflare/account.d.ts.map +1 -1
  241. package/dist/cloudflare/api.d.ts +71 -3
  242. package/dist/cloudflare/api.d.ts.map +1 -1
  243. package/dist/cloudflare/auth.d.ts +1 -1
  244. package/dist/cloudflare/auth.d.ts.map +1 -1
  245. package/dist/cloudflare/index.d.ts +61 -6
  246. package/dist/cloudflare/index.d.ts.map +1 -1
  247. package/dist/cloudflare/index.js +4 -13
  248. package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
  249. package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
  250. package/dist/cloudflare/kv-namespace.d.ts +4 -0
  251. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  252. package/dist/cloudflare/preferences.d.ts +7 -0
  253. package/dist/cloudflare/preferences.d.ts.map +1 -1
  254. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  255. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  256. package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
  257. package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
  258. package/dist/cloudflare/preview-registry-records.d.ts +4 -0
  259. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  260. package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
  261. package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
  262. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  263. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  264. package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
  265. package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
  266. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  267. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  268. package/dist/cloudflare/preview-registry.d.ts +42 -0
  269. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  270. package/dist/cloudflare/preview-urls.d.ts +3 -0
  271. package/dist/cloudflare/preview-urls.d.ts.map +1 -0
  272. package/dist/cloudflare/registry-schema.d.ts +253 -0
  273. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  274. package/dist/cloudflare/remote-config.d.ts.map +1 -1
  275. package/dist/cloudflare/tokens.d.ts +44 -0
  276. package/dist/cloudflare/tokens.d.ts.map +1 -0
  277. package/dist/cloudflare/types.d.ts +124 -7
  278. package/dist/cloudflare/types.d.ts.map +1 -1
  279. package/dist/cloudflare/usage.d.ts +31 -3
  280. package/dist/cloudflare/usage.d.ts.map +1 -1
  281. package/dist/config/binding-resolution-helpers.d.ts +41 -0
  282. package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
  283. package/dist/config/compatibility.d.ts +3 -0
  284. package/dist/config/compatibility.d.ts.map +1 -0
  285. package/dist/config/compiler/bindings.d.ts +14 -0
  286. package/dist/config/compiler/bindings.d.ts.map +1 -0
  287. package/dist/config/compiler/core-helpers.d.ts +6 -0
  288. package/dist/config/compiler/core-helpers.d.ts.map +1 -0
  289. package/dist/config/compiler/do-workers.d.ts +34 -0
  290. package/dist/config/compiler/do-workers.d.ts.map +1 -0
  291. package/dist/config/compiler/paths.d.ts +18 -0
  292. package/dist/config/compiler/paths.d.ts.map +1 -0
  293. package/dist/config/compiler/types.d.ts +298 -0
  294. package/dist/config/compiler/types.d.ts.map +1 -0
  295. package/dist/config/compiler.d.ts +22 -134
  296. package/dist/config/compiler.d.ts.map +1 -1
  297. package/dist/config/cron.d.ts +19 -0
  298. package/dist/config/cron.d.ts.map +1 -0
  299. package/dist/config/define.d.ts +8 -5
  300. package/dist/config/define.d.ts.map +1 -1
  301. package/dist/config/deploy-resources.d.ts +58 -0
  302. package/dist/config/deploy-resources.d.ts.map +1 -0
  303. package/dist/config/env-vars.d.ts +309 -0
  304. package/dist/config/env-vars.d.ts.map +1 -0
  305. package/dist/config/framework-providers.d.ts +9 -0
  306. package/dist/config/framework-providers.d.ts.map +1 -0
  307. package/dist/config/index.d.ts +12 -5
  308. package/dist/config/index.d.ts.map +1 -1
  309. package/dist/config/loader.d.ts +2 -1
  310. package/dist/config/loader.d.ts.map +1 -1
  311. package/dist/config/local-dev-vars.d.ts +15 -0
  312. package/dist/config/local-dev-vars.d.ts.map +1 -0
  313. package/dist/config/preview-resources.d.ts +83 -0
  314. package/dist/config/preview-resources.d.ts.map +1 -0
  315. package/dist/config/preview.d.ts +29 -0
  316. package/dist/config/preview.d.ts.map +1 -0
  317. package/dist/config/ref.d.ts +16 -25
  318. package/dist/config/ref.d.ts.map +1 -1
  319. package/dist/config/resolve-phased.d.ts +72 -0
  320. package/dist/config/resolve-phased.d.ts.map +1 -0
  321. package/dist/config/resolve.d.ts +11 -0
  322. package/dist/config/resolve.d.ts.map +1 -0
  323. package/dist/config/resource-resolution.d.ts +80 -0
  324. package/dist/config/resource-resolution.d.ts.map +1 -0
  325. package/dist/config/schema-bindings.d.ts +2025 -0
  326. package/dist/config/schema-bindings.d.ts.map +1 -0
  327. package/dist/config/schema-build.d.ts +67 -0
  328. package/dist/config/schema-build.d.ts.map +1 -0
  329. package/dist/config/schema-env.d.ts +3579 -0
  330. package/dist/config/schema-env.d.ts.map +1 -0
  331. package/dist/config/schema-normalization.d.ts +265 -0
  332. package/dist/config/schema-normalization.d.ts.map +1 -0
  333. package/dist/config/schema-runtime.d.ts +508 -0
  334. package/dist/config/schema-runtime.d.ts.map +1 -0
  335. package/dist/config/schema-types-bindings-platform.d.ts +508 -0
  336. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  337. package/dist/config/schema-types-bindings-resources.d.ts +767 -0
  338. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  339. package/dist/config/schema-types-bindings.d.ts +293 -0
  340. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  341. package/dist/config/schema-types-build.d.ts +86 -0
  342. package/dist/config/schema-types-build.d.ts.map +1 -0
  343. package/dist/config/schema-types-runtime.d.ts +917 -0
  344. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  345. package/dist/config/schema-types.d.ts +424 -0
  346. package/dist/config/schema-types.d.ts.map +1 -0
  347. package/dist/config/schema.d.ts +5324 -2011
  348. package/dist/config/schema.d.ts.map +1 -1
  349. package/dist/config/service-bindings-validation.d.ts +36 -0
  350. package/dist/config/service-bindings-validation.d.ts.map +1 -0
  351. package/dist/config-entry.d.ts +7 -0
  352. package/dist/config-entry.d.ts.map +1 -0
  353. package/dist/config-entry.js +3 -0
  354. package/dist/decorators/durable-object.d.ts.map +1 -1
  355. package/dist/decorators/index.d.ts +2 -2
  356. package/dist/decorators/index.js +2 -9
  357. package/dist/dev-server/d1-migrations.d.ts +36 -0
  358. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  359. package/dist/dev-server/dev-server-state.d.ts +59 -0
  360. package/dist/dev-server/dev-server-state.d.ts.map +1 -0
  361. package/dist/dev-server/gateway-script.d.ts +21 -0
  362. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  363. package/dist/dev-server/index.d.ts +1 -1
  364. package/dist/dev-server/miniflare-bindings.d.ts +81 -0
  365. package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
  366. package/dist/dev-server/miniflare-dev-config.d.ts +36 -0
  367. package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
  368. package/dist/dev-server/miniflare-log.d.ts +20 -0
  369. package/dist/dev-server/miniflare-log.d.ts.map +1 -0
  370. package/dist/dev-server/miniflare-worker-config.d.ts +82 -0
  371. package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
  372. package/dist/dev-server/reload-queue.d.ts +13 -0
  373. package/dist/dev-server/reload-queue.d.ts.map +1 -0
  374. package/dist/dev-server/runtime-stdio.d.ts +8 -0
  375. package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
  376. package/dist/dev-server/server-startup-helpers.d.ts +84 -0
  377. package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
  378. package/dist/dev-server/server.d.ts +2 -0
  379. package/dist/dev-server/server.d.ts.map +1 -1
  380. package/dist/dev-server/vite-process.d.ts +15 -0
  381. package/dist/dev-server/vite-process.d.ts.map +1 -0
  382. package/dist/dev-server/vite-utils.d.ts +19 -1
  383. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  384. package/dist/dev-server/worker-source-watcher.d.ts +17 -0
  385. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  386. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  387. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  388. package/dist/env.d.ts +10 -0
  389. package/dist/env.d.ts.map +1 -1
  390. package/dist/index.d.ts +8 -12
  391. package/dist/index.d.ts.map +1 -1
  392. package/dist/index.js +9 -298
  393. package/dist/runtime/context-events.d.ts +13 -0
  394. package/dist/runtime/context-events.d.ts.map +1 -0
  395. package/dist/runtime/context-types.d.ts +82 -0
  396. package/dist/runtime/context-types.d.ts.map +1 -0
  397. package/dist/runtime/context.d.ts +20 -44
  398. package/dist/runtime/context.d.ts.map +1 -1
  399. package/dist/runtime/exports.d.ts +70 -55
  400. package/dist/runtime/exports.d.ts.map +1 -1
  401. package/dist/runtime/index.d.ts +10 -3
  402. package/dist/runtime/index.d.ts.map +1 -1
  403. package/dist/runtime/index.js +5 -111
  404. package/dist/runtime/middleware.d.ts +119 -67
  405. package/dist/runtime/middleware.d.ts.map +1 -1
  406. package/dist/runtime/router/index.d.ts +7 -0
  407. package/dist/runtime/router/index.d.ts.map +1 -0
  408. package/dist/runtime/router/types.d.ts +24 -0
  409. package/dist/runtime/router/types.d.ts.map +1 -0
  410. package/dist/runtime/validation.d.ts +18 -4
  411. package/dist/runtime/validation.d.ts.map +1 -1
  412. package/dist/secrets/local-secrets.d.ts +46 -0
  413. package/dist/secrets/local-secrets.d.ts.map +1 -0
  414. package/dist/shims/local-hyperdrive.d.ts +12 -0
  415. package/dist/shims/local-hyperdrive.d.ts.map +1 -0
  416. package/dist/shims/local-media-bindings.d.ts +19 -0
  417. package/dist/shims/local-media-bindings.d.ts.map +1 -0
  418. package/dist/shims/local-worker-loader.d.ts +3 -0
  419. package/dist/shims/local-worker-loader.d.ts.map +1 -0
  420. package/dist/sveltekit/index.d.ts +1 -1
  421. package/dist/sveltekit/index.d.ts.map +1 -1
  422. package/dist/sveltekit/index.js +313 -167
  423. package/dist/sveltekit/local-bindings.d.ts +4 -0
  424. package/dist/sveltekit/local-bindings.d.ts.map +1 -0
  425. package/dist/sveltekit/platform.d.ts +20 -2
  426. package/dist/sveltekit/platform.d.ts.map +1 -1
  427. package/dist/test/ai-search.d.ts +39 -0
  428. package/dist/test/ai-search.d.ts.map +1 -0
  429. package/dist/test/alarm.d.ts +55 -0
  430. package/dist/test/alarm.d.ts.map +1 -0
  431. package/dist/test/binding-hints.d.ts +10 -0
  432. package/dist/test/binding-hints.d.ts.map +1 -0
  433. package/dist/test/cf.d.ts +71 -35
  434. package/dist/test/cf.d.ts.map +1 -1
  435. package/dist/test/containers.d.ts +87 -0
  436. package/dist/test/containers.d.ts.map +1 -0
  437. package/dist/test/email.d.ts +16 -7
  438. package/dist/test/email.d.ts.map +1 -1
  439. package/dist/test/index.d.ts +20 -21
  440. package/dist/test/index.d.ts.map +1 -1
  441. package/dist/test/index.js +4971 -70
  442. package/dist/test/offline-bindings.d.ts +115 -0
  443. package/dist/test/offline-bindings.d.ts.map +1 -0
  444. package/dist/test/queue.d.ts.map +1 -1
  445. package/dist/test/remote-ai.d.ts.map +1 -1
  446. package/dist/test/remote-cloudflare.d.ts +13 -0
  447. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  448. package/dist/test/remote-vectorize.d.ts.map +1 -1
  449. package/dist/test/resolve-service-bindings.d.ts +64 -4
  450. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  451. package/dist/test/scheduled.d.ts.map +1 -1
  452. package/dist/test/should-skip.d.ts +14 -18
  453. package/dist/test/should-skip.d.ts.map +1 -1
  454. package/dist/test/simple-context-bindings.d.ts +13 -0
  455. package/dist/test/simple-context-bindings.d.ts.map +1 -0
  456. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  457. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  458. package/dist/test/simple-context-env.d.ts +35 -0
  459. package/dist/test/simple-context-env.d.ts.map +1 -0
  460. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  461. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  462. package/dist/test/simple-context-handlers.d.ts +12 -0
  463. package/dist/test/simple-context-handlers.d.ts.map +1 -0
  464. package/dist/test/simple-context-lifecycle.d.ts +32 -0
  465. package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
  466. package/dist/test/simple-context-mfconfig.d.ts +10 -0
  467. package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
  468. package/dist/test/simple-context-multi-worker.d.ts +16 -0
  469. package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
  470. package/dist/test/simple-context-paths.d.ts +40 -0
  471. package/dist/test/simple-context-paths.d.ts.map +1 -0
  472. package/dist/test/simple-context-runtime.d.ts +19 -0
  473. package/dist/test/simple-context-runtime.d.ts.map +1 -0
  474. package/dist/test/simple-context-startup.d.ts +11 -0
  475. package/dist/test/simple-context-startup.d.ts.map +1 -0
  476. package/dist/test/simple-context-transport.d.ts +14 -0
  477. package/dist/test/simple-context-transport.d.ts.map +1 -0
  478. package/dist/test/simple-context.d.ts +8 -27
  479. package/dist/test/simple-context.d.ts.map +1 -1
  480. package/dist/test/tail.d.ts +3 -2
  481. package/dist/test/tail.d.ts.map +1 -1
  482. package/dist/test/utilities/analytics-engine.d.ts +22 -0
  483. package/dist/test/utilities/analytics-engine.d.ts.map +1 -0
  484. package/dist/test/utilities/artifacts.d.ts +11 -0
  485. package/dist/test/utilities/artifacts.d.ts.map +1 -0
  486. package/dist/test/utilities/context.d.ts +39 -0
  487. package/dist/test/utilities/context.d.ts.map +1 -0
  488. package/dist/test/utilities/d1.d.ts +21 -0
  489. package/dist/test/utilities/d1.d.ts.map +1 -0
  490. package/dist/test/utilities/env.d.ts +43 -0
  491. package/dist/test/utilities/env.d.ts.map +1 -0
  492. package/dist/test/utilities/kv.d.ts +11 -0
  493. package/dist/test/utilities/kv.d.ts.map +1 -0
  494. package/dist/test/utilities/media.d.ts +16 -0
  495. package/dist/test/utilities/media.d.ts.map +1 -0
  496. package/dist/test/utilities/platform.d.ts +41 -0
  497. package/dist/test/utilities/platform.d.ts.map +1 -0
  498. package/dist/test/utilities/queue.d.ts +5 -0
  499. package/dist/test/utilities/queue.d.ts.map +1 -0
  500. package/dist/test/utilities/r2.d.ts +2 -0
  501. package/dist/test/utilities/r2.d.ts.map +1 -0
  502. package/dist/test/utilities/stream-flagship.d.ts +27 -0
  503. package/dist/test/utilities/stream-flagship.d.ts.map +1 -0
  504. package/dist/test/utilities/vectorize.d.ts +38 -0
  505. package/dist/test/utilities/vectorize.d.ts.map +1 -0
  506. package/dist/test/utilities/workflows.d.ts +26 -0
  507. package/dist/test/utilities/workflows.d.ts.map +1 -0
  508. package/dist/test/utilities.d.ts +13 -98
  509. package/dist/test/utilities.d.ts.map +1 -1
  510. package/dist/test/worker.d.ts +6 -0
  511. package/dist/test/worker.d.ts.map +1 -1
  512. package/dist/transform/durable-object.d.ts.map +1 -1
  513. package/dist/transform/index.d.ts +2 -2
  514. package/dist/transform/worker-entrypoint.d.ts +5 -0
  515. package/dist/transform/worker-entrypoint.d.ts.map +1 -1
  516. package/dist/utils/entrypoint-discovery.d.ts +6 -3
  517. package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
  518. package/dist/utils/glob.d.ts.map +1 -1
  519. package/dist/utils/resolve-package.d.ts.map +1 -1
  520. package/dist/utils/send-email.d.ts +15 -0
  521. package/dist/utils/send-email.d.ts.map +1 -0
  522. package/dist/utils/send-email.js +163 -0
  523. package/dist/vite/config-file.d.ts +25 -0
  524. package/dist/vite/config-file.d.ts.map +1 -0
  525. package/dist/vite/index.d.ts +3 -2
  526. package/dist/vite/index.d.ts.map +1 -1
  527. package/dist/vite/index.js +2 -339
  528. package/dist/vite/plugin-config-hook.d.ts +28 -0
  529. package/dist/vite/plugin-config-hook.d.ts.map +1 -0
  530. package/dist/vite/plugin-context.d.ts +27 -0
  531. package/dist/vite/plugin-context.d.ts.map +1 -0
  532. package/dist/vite/plugin-durable-objects.d.ts +18 -0
  533. package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
  534. package/dist/vite/plugin-programmatic.d.ts +44 -0
  535. package/dist/vite/plugin-programmatic.d.ts.map +1 -0
  536. package/dist/vite/plugin-service-bindings.d.ts +13 -0
  537. package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
  538. package/dist/vite/plugin-transform.d.ts +41 -0
  539. package/dist/vite/plugin-transform.d.ts.map +1 -0
  540. package/dist/vite/plugin.d.ts +10 -41
  541. package/dist/vite/plugin.d.ts.map +1 -1
  542. package/dist/worker-entry/composed-worker.d.ts +7 -0
  543. package/dist/worker-entry/composed-worker.d.ts.map +1 -0
  544. package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
  545. package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
  546. package/dist/worker-entry/extensions.d.ts +5 -0
  547. package/dist/worker-entry/extensions.d.ts.map +1 -0
  548. package/dist/worker-entry/routes.d.ts +22 -0
  549. package/dist/worker-entry/routes.d.ts.map +1 -0
  550. package/dist/worker-entry/surface-paths.d.ts +26 -0
  551. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  552. package/dist/worker-entry/validate-fetch-style.d.ts +12 -0
  553. package/dist/worker-entry/validate-fetch-style.d.ts.map +1 -0
  554. package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
  555. package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
  556. package/package.json +159 -116
  557. package/R2.md +0 -170
  558. package/dist/account-rvrj687w.js +0 -397
  559. package/dist/ai-dx4fr9jh.js +0 -107
  560. package/dist/bridge/protocol.d.ts.map +0 -1
  561. package/dist/bridge/serialization.d.ts.map +0 -1
  562. package/dist/browser-shim/worker.d.ts +0 -14
  563. package/dist/browser-shim/worker.d.ts.map +0 -1
  564. package/dist/build-mnf6v8gd.js +0 -53
  565. package/dist/deploy-nhceck39.js +0 -70
  566. package/dist/dev-b9dmrj7b.js +0 -2417
  567. package/dist/doctor-fmgb3d28.js +0 -190
  568. package/dist/durable-object-t4kbb0yt.js +0 -13
  569. package/dist/index-07q6yxyc.js +0 -168
  570. package/dist/index-18hvb6gb.js +0 -194
  571. package/dist/index-1xpj0m4r.js +0 -57
  572. package/dist/index-37x76zdn.js +0 -4
  573. package/dist/index-3t6rypgc.js +0 -13
  574. package/dist/index-67qcae0f.js +0 -183
  575. package/dist/index-a855bdsx.js +0 -18
  576. package/dist/index-d8bdkx2h.js +0 -109
  577. package/dist/index-ep3445yc.js +0 -2225
  578. package/dist/index-gz1gndna.js +0 -307
  579. package/dist/index-hcex3rgh.js +0 -266
  580. package/dist/index-m2q41jwa.js +0 -462
  581. package/dist/index-n7rs26ft.js +0 -77
  582. package/dist/index-pf5s73n9.js +0 -1413
  583. package/dist/index-rbht7m9r.js +0 -36
  584. package/dist/index-tfyxa77h.js +0 -850
  585. package/dist/index-tk6ej9dj.js +0 -94
  586. package/dist/index-z14anrqp.js +0 -226
  587. package/dist/init-f9mgmew3.js +0 -186
  588. package/dist/remote-q59qk463.js +0 -97
  589. package/dist/test/bridge-context.d.ts +0 -76
  590. package/dist/test/bridge-context.d.ts.map +0 -1
  591. package/dist/test/multi-worker-context.d.ts +0 -114
  592. package/dist/test/multi-worker-context.d.ts.map +0 -1
  593. package/dist/types-5nyrz1sz.js +0 -454
  594. package/dist/worker-entrypoint-m9th0rg0.js +0 -13
@@ -0,0 +1,568 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-CvQ6eiug.js";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { execSync } from "node:child_process";
4
+ import { homedir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { parse } from "smol-toml";
7
+ //#region src/cloudflare/auth.ts
8
+ const WRANGLER_CONFIG_FILE = "config/default.toml";
9
+ const EXPIRY_BUFFER_MS = 300 * 1e3;
10
+ let cachedToken = null;
11
+ let cacheExpiresAt = 0;
12
+ /**
13
+ * Invalidate the cached token (call when API returns auth error)
14
+ * This forces the next getApiToken() call to refresh via wrangler
15
+ */
16
+ function invalidateToken() {
17
+ cachedToken = null;
18
+ cacheExpiresAt = 0;
19
+ }
20
+ /**
21
+ * Get possible paths to wrangler's config file
22
+ * Returns array of paths to check, in order of priority
23
+ */
24
+ function getWranglerConfigPaths() {
25
+ const paths = [];
26
+ if (process.platform === "win32" && process.env.APPDATA) paths.push(join(process.env.APPDATA, "xdg.config", ".wrangler", WRANGLER_CONFIG_FILE));
27
+ if (process.env.XDG_CONFIG_HOME) paths.push(join(process.env.XDG_CONFIG_HOME, ".wrangler", WRANGLER_CONFIG_FILE));
28
+ paths.push(join(homedir(), ".wrangler", WRANGLER_CONFIG_FILE));
29
+ return paths;
30
+ }
31
+ /**
32
+ * Get the path to wrangler's config file (first existing path)
33
+ */
34
+ function getWranglerConfigPath() {
35
+ const paths = getWranglerConfigPaths();
36
+ for (const path of paths) if (existsSync(path)) return path;
37
+ return null;
38
+ }
39
+ /**
40
+ * Check if wrangler config file exists
41
+ */
42
+ function hasWranglerConfig() {
43
+ return getWranglerConfigPath() !== null;
44
+ }
45
+ /**
46
+ * Parse TOML config file (wrangler's stored OAuth state).
47
+ *
48
+ * Uses a real TOML parser (`smol-toml`) so that nested sections, escapes,
49
+ * and other TOML 1.0 constructs are handled correctly. We deliberately
50
+ * read only the implicit root section: any keys nested under a `[section]`
51
+ * header are ignored to keep this resilient against future wrangler
52
+ * additions that put new sections in the same file. If the parser throws
53
+ * (corrupt file, partial write), the caller falls back to the slower
54
+ * `bunx wrangler auth token` shell-out path.
55
+ */
56
+ function parseSimpleToml(content) {
57
+ let parsed;
58
+ try {
59
+ parsed = parse(content);
60
+ } catch {
61
+ return {};
62
+ }
63
+ const result = {};
64
+ for (const [key, value] of Object.entries(parsed)) if (typeof value === "string") result[key] = value;
65
+ else if (typeof value === "number" || typeof value === "boolean") result[key] = String(value);
66
+ return result;
67
+ }
68
+ /**
69
+ * Extract OAuth token info from wrangler's stored configuration (sync)
70
+ * Returns token and expiration time if available
71
+ */
72
+ function readWranglerConfig() {
73
+ const configPath = getWranglerConfigPath();
74
+ if (!configPath || !existsSync(configPath)) return null;
75
+ try {
76
+ const config = parseSimpleToml(readFileSync(configPath, "utf-8"));
77
+ const token = config.oauth_token;
78
+ const expirationTime = config.expiration_time;
79
+ if (token && expirationTime) return {
80
+ token,
81
+ expiresAt: new Date(expirationTime)
82
+ };
83
+ return null;
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+ /**
89
+ * Extract OAuth token info from wrangler's stored configuration
90
+ */
91
+ async function getWranglerAuth() {
92
+ const config = readWranglerConfig();
93
+ if (!config) return null;
94
+ const configPath = getWranglerConfigPath();
95
+ if (!configPath) return null;
96
+ try {
97
+ const parsed = parseSimpleToml(readFileSync(configPath, "utf-8"));
98
+ return {
99
+ oauthToken: parsed.oauth_token,
100
+ refreshToken: parsed.refresh_token,
101
+ expiresAt: config.expiresAt
102
+ };
103
+ } catch {
104
+ return null;
105
+ }
106
+ }
107
+ /**
108
+ * Refresh the token via `wrangler auth token` command
109
+ * This is slow (~2-3s) so only called when necessary
110
+ */
111
+ function refreshWranglerToken() {
112
+ try {
113
+ const lines = execSync("bunx wrangler auth token", {
114
+ encoding: "utf-8",
115
+ stdio: [
116
+ "pipe",
117
+ "pipe",
118
+ "pipe"
119
+ ],
120
+ timeout: 15e3
121
+ }).trim().split(/\r?\n/).filter((l) => l.trim().length > 0);
122
+ const token = lines[lines.length - 1]?.trim();
123
+ if (token && token.length >= 20 && !token.includes("wrangler") && !token.includes("⛅")) return token;
124
+ return null;
125
+ } catch {
126
+ return null;
127
+ }
128
+ }
129
+ /**
130
+ * Get the API token to use for Cloudflare API requests
131
+ *
132
+ * Strategy (fast path first):
133
+ * 1. Check in-memory cache (unless forceRefresh)
134
+ * 2. Check CLOUDFLARE_API_TOKEN env var
135
+ * 3. Read token from wrangler config (if not expired)
136
+ * 4. Call `wrangler auth token` to refresh (slow, only when needed)
137
+ *
138
+ * @param forceRefresh - Skip cache and force a refresh via wrangler
139
+ */
140
+ async function getApiToken(forceRefresh = false) {
141
+ if (!forceRefresh && cachedToken && Date.now() < cacheExpiresAt) return cachedToken;
142
+ const envToken = process.env.CLOUDFLARE_API_TOKEN;
143
+ if (envToken) return envToken;
144
+ if (!forceRefresh) {
145
+ const config = readWranglerConfig();
146
+ if (config) {
147
+ const now = Date.now();
148
+ const expiresAt = config.expiresAt.getTime();
149
+ if (now < expiresAt - EXPIRY_BUFFER_MS) {
150
+ cachedToken = config.token;
151
+ cacheExpiresAt = expiresAt - EXPIRY_BUFFER_MS;
152
+ return config.token;
153
+ }
154
+ }
155
+ }
156
+ const refreshedToken = refreshWranglerToken();
157
+ if (refreshedToken) {
158
+ cachedToken = refreshedToken;
159
+ cacheExpiresAt = Date.now() + EXPIRY_BUFFER_MS;
160
+ return refreshedToken;
161
+ }
162
+ return null;
163
+ }
164
+ /**
165
+ * Check if we have valid authentication
166
+ */
167
+ async function isAuthenticated() {
168
+ return await getApiToken() !== null;
169
+ }
170
+ //#endregion
171
+ //#region src/cloudflare/api.ts
172
+ var api_exports = /* @__PURE__ */ __exportAll({
173
+ AuthenticationError: () => AuthenticationError,
174
+ CloudflareAPIError: () => CloudflareAPIError,
175
+ apiDelete: () => apiDelete,
176
+ apiGet: () => apiGet,
177
+ apiGetAll: () => apiGetAll,
178
+ apiPatch: () => apiPatch,
179
+ apiPost: () => apiPost,
180
+ apiPut: () => apiPut,
181
+ createCloudflareAuthSession: () => createCloudflareAuthSession,
182
+ kvDelete: () => kvDelete,
183
+ kvGet: () => kvGet,
184
+ kvPut: () => kvPut,
185
+ parseCloudflareEnvelope: () => parseCloudflareEnvelope
186
+ });
187
+ const API_BASE = "https://api.cloudflare.com/client/v4";
188
+ const DEFAULT_TIMEOUT = 1e4;
189
+ var CloudflareAPIError = class extends Error {
190
+ constructor(message, code, errors) {
191
+ super(message);
192
+ this.code = code;
193
+ this.errors = errors;
194
+ this.name = "CloudflareAPIError";
195
+ }
196
+ };
197
+ var AuthenticationError = class extends Error {
198
+ constructor(message = "Not authenticated. Run: devflare login") {
199
+ super(message);
200
+ this.name = "AuthenticationError";
201
+ }
202
+ };
203
+ /**
204
+ * Wrap fetch with a guaranteed timeout using Promise.race
205
+ * AbortSignal can sometimes fail to abort in certain environments
206
+ */
207
+ async function fetchWithTimeout(url, init, timeoutMs) {
208
+ const controller = new AbortController();
209
+ const abortTimeoutId = setTimeout(() => controller.abort(), timeoutMs);
210
+ let rejectTimeoutId = null;
211
+ const timeoutPromise = new Promise((_, reject) => {
212
+ rejectTimeoutId = setTimeout(() => reject(/* @__PURE__ */ new Error(`Request timed out after ${timeoutMs}ms`)), timeoutMs);
213
+ });
214
+ try {
215
+ return await Promise.race([fetch(url, {
216
+ ...init,
217
+ signal: controller.signal
218
+ }), timeoutPromise]);
219
+ } finally {
220
+ clearTimeout(abortTimeoutId);
221
+ if (rejectTimeoutId) clearTimeout(rejectTimeoutId);
222
+ }
223
+ }
224
+ function tryParseJson(text) {
225
+ if (text.length === 0) return { ok: false };
226
+ try {
227
+ return {
228
+ ok: true,
229
+ value: JSON.parse(text)
230
+ };
231
+ } catch {
232
+ return { ok: false };
233
+ }
234
+ }
235
+ function isEnvelopeShape(value) {
236
+ if (!value || typeof value !== "object") return false;
237
+ const record = value;
238
+ return typeof record.success === "boolean" && Array.isArray(record.errors) && Array.isArray(record.messages) && "result" in record;
239
+ }
240
+ /**
241
+ * Some Cloudflare API surfaces (notably the v4 Queues list endpoint)
242
+ * return a bare `{ result, result_info? }` body without the standard
243
+ * `{ success, errors, messages }` envelope. When the HTTP response is
244
+ * a 2xx, treat this as a successful envelope so callers don't fail on
245
+ * a perfectly valid payload.
246
+ */
247
+ function coerceBareResultEnvelope(value, response) {
248
+ if (!response.ok) return null;
249
+ if (!value || typeof value !== "object") return null;
250
+ const record = value;
251
+ if (!("result" in record)) return null;
252
+ return {
253
+ success: true,
254
+ errors: [],
255
+ messages: [],
256
+ result: record.result,
257
+ ...record.result_info && typeof record.result_info === "object" ? { result_info: record.result_info } : {}
258
+ };
259
+ }
260
+ function envelopeFailureError(response, envelope, endpoint) {
261
+ const first = envelope.errors[0];
262
+ return new CloudflareAPIError(first ? `Cloudflare ${endpoint} failed (${first.code}): ${first.message}` : `Cloudflare ${endpoint} failed`, response.status, envelope.errors);
263
+ }
264
+ /**
265
+ * Read a response body once (as text) and decode the Cloudflare v4 envelope
266
+ * without throwing on `success: false`. Returns `null` when a 404 is
267
+ * explicitly allowed via `allow404: true`.
268
+ *
269
+ * Throws `CloudflareAPIError` when the body is not valid JSON or does not
270
+ * match the expected v4 envelope shape.
271
+ */
272
+ async function decodeCloudflareEnvelope(response, opts) {
273
+ if (opts.allow404 === true && response.status === 404) return null;
274
+ const text = await response.text();
275
+ const parsed = tryParseJson(text);
276
+ if (!parsed.ok) throw new CloudflareAPIError(`Cloudflare API returned an invalid JSON response. Body: ${truncateBody(text)}`, response.status, []);
277
+ if (!isEnvelopeShape(parsed.value)) {
278
+ const coerced = coerceBareResultEnvelope(parsed.value, response);
279
+ if (coerced) return coerced;
280
+ throw new CloudflareAPIError(`Cloudflare ${opts.endpoint} returned a non-envelope JSON response. Body: ${truncateBody(text)}`, response.status, []);
281
+ }
282
+ return parsed.value;
283
+ }
284
+ function truncateBody(text, max = 500) {
285
+ const trimmed = text.trim();
286
+ if (trimmed.length <= max) return trimmed;
287
+ return `${trimmed.slice(0, max)}…[truncated, total ${trimmed.length} chars]`;
288
+ }
289
+ /**
290
+ * Canonical Cloudflare v4 envelope parser.
291
+ *
292
+ * - Reads the response body exactly once (text -> tryParseJson).
293
+ * - Enforces the `{ success, errors, messages, result }` shape.
294
+ * - Throws `CloudflareAPIError` when `success === false`, surfacing
295
+ * `errors[0].code` and `errors[0].message`.
296
+ * - Treats `404` as success when `allow404: true` is passed, returning
297
+ * `null as T` without reading the body.
298
+ */
299
+ async function parseCloudflareEnvelope(response, opts) {
300
+ const envelope = await decodeCloudflareEnvelope(response, opts);
301
+ if (envelope === null) return null;
302
+ if (!envelope.success) throw envelopeFailureError(response, envelope, opts.endpoint);
303
+ return envelope.result;
304
+ }
305
+ /**
306
+ * Create a small auth session abstraction that centralises "which token are
307
+ * we sending" for every request. The session owns token resolution and
308
+ * invalidation so request code does not call `getApiToken` directly.
309
+ */
310
+ function createCloudflareAuthSession(opts = {}) {
311
+ const provider = opts.tokenProvider ?? ((forceRefresh) => getApiToken(forceRefresh));
312
+ const onInvalidate = opts.onInvalidate ?? invalidateToken;
313
+ return {
314
+ async getAuthHeader(forceRefresh = false) {
315
+ const token = await provider(forceRefresh);
316
+ if (!token) throw new AuthenticationError();
317
+ return `Bearer ${token}`;
318
+ },
319
+ invalidate() {
320
+ onInvalidate();
321
+ }
322
+ };
323
+ }
324
+ const defaultAuthSession = createCloudflareAuthSession({});
325
+ async function resolveAuthHeader(options, forceRefresh = false) {
326
+ if (options?.token) return `Bearer ${options.token}`;
327
+ return defaultAuthSession.getAuthHeader(forceRefresh);
328
+ }
329
+ /**
330
+ * Check if a decoded envelope represents an auth failure worth retrying.
331
+ */
332
+ function isAuthError(response, envelope) {
333
+ if (response.status === 401) return true;
334
+ if (!envelope.success && envelope.errors?.some((e) => e.code === 1e4 || e.message?.toLowerCase().includes("authentication") || e.message?.toLowerCase().includes("token"))) return true;
335
+ return false;
336
+ }
337
+ /**
338
+ * Execute a Cloudflare JSON request and return the decoded envelope without
339
+ * throwing on `success: false` so callers can inspect and retry on auth
340
+ * errors before surfacing failures.
341
+ *
342
+ * Bursts of resource creates (KV, D1, Queues during deploy) can hit
343
+ * Cloudflare's per-account rate limits, and edge proxies occasionally return
344
+ * 5xx. We retry network errors and 429/5xx responses with bounded
345
+ * exponential backoff before surfacing the failure.
346
+ */
347
+ const RETRYABLE_STATUS = new Set([
348
+ 408,
349
+ 425,
350
+ 429,
351
+ 500,
352
+ 502,
353
+ 503,
354
+ 504
355
+ ]);
356
+ const RETRY_BASE_DELAY_MS = 250;
357
+ const RETRY_MAX_ATTEMPTS = 4;
358
+ function shouldRetryResponse(response) {
359
+ return RETRYABLE_STATUS.has(response.status);
360
+ }
361
+ function backoffDelayMs(attempt, retryAfterHeader) {
362
+ if (retryAfterHeader) {
363
+ const parsed = Number(retryAfterHeader);
364
+ if (Number.isFinite(parsed) && parsed > 0) return Math.min(parsed * 1e3, 1e4);
365
+ }
366
+ const base = RETRY_BASE_DELAY_MS * 2 ** attempt;
367
+ const jitter = Math.random() * RETRY_BASE_DELAY_MS;
368
+ return Math.min(base + jitter, 1e4);
369
+ }
370
+ async function requestCloudflareJson(path, request, options) {
371
+ const endpoint = `${request.method} ${path}`;
372
+ const makeRequest = async (forceRefresh) => {
373
+ const authorization = await resolveAuthHeader(options, forceRefresh);
374
+ const headers = new Headers({
375
+ Authorization: authorization,
376
+ "Content-Type": "application/json"
377
+ });
378
+ const response = await fetchWithTimeout(`${API_BASE}${path}`, {
379
+ method: request.method,
380
+ headers,
381
+ ...request.body !== void 0 ? { body: JSON.stringify(request.body) } : {}
382
+ }, options?.timeout ?? DEFAULT_TIMEOUT);
383
+ return {
384
+ response,
385
+ envelope: await decodeCloudflareEnvelope(response, { endpoint })
386
+ };
387
+ };
388
+ let result = null;
389
+ let lastError = null;
390
+ for (let attempt = 0; attempt < RETRY_MAX_ATTEMPTS; attempt++) {
391
+ try {
392
+ result = await makeRequest(false);
393
+ } catch (error) {
394
+ lastError = error;
395
+ if (attempt < RETRY_MAX_ATTEMPTS - 1) {
396
+ await new Promise((r) => setTimeout(r, backoffDelayMs(attempt, null)));
397
+ continue;
398
+ }
399
+ throw error;
400
+ }
401
+ const current = result;
402
+ if (!shouldRetryResponse(current.response) || attempt === RETRY_MAX_ATTEMPTS - 1) break;
403
+ await new Promise((r) => setTimeout(r, backoffDelayMs(attempt, current.response.headers.get("retry-after"))));
404
+ }
405
+ if (!result) throw lastError ?? /* @__PURE__ */ new Error(`Cloudflare API request failed: ${endpoint}`);
406
+ if (request.allowAuthRetry === true && isAuthError(result.response, result.envelope) && !options?.token) {
407
+ defaultAuthSession.invalidate();
408
+ result = await makeRequest(true);
409
+ }
410
+ return result;
411
+ }
412
+ async function requestCloudflareResult(path, request, options) {
413
+ const { response, envelope } = await requestCloudflareJson(path, request, options);
414
+ if (!envelope.success) throw envelopeFailureError(response, envelope, `${request.method} ${path}`);
415
+ return envelope.result;
416
+ }
417
+ /**
418
+ * Make a GET request to the Cloudflare API
419
+ * Automatically retries with a fresh token on auth failure
420
+ */
421
+ async function apiGet(path, options) {
422
+ return requestCloudflareResult(path, {
423
+ method: "GET",
424
+ allowAuthRetry: true
425
+ }, options);
426
+ }
427
+ /**
428
+ * Make a POST request to the Cloudflare API
429
+ */
430
+ async function apiPost(path, body, options) {
431
+ return requestCloudflareResult(path, {
432
+ method: "POST",
433
+ body
434
+ }, options);
435
+ }
436
+ /**
437
+ * Make a PUT request to the Cloudflare API
438
+ */
439
+ async function apiPut(path, body, options) {
440
+ return requestCloudflareResult(path, {
441
+ method: "PUT",
442
+ body
443
+ }, options);
444
+ }
445
+ /**
446
+ * Make a PATCH request to the Cloudflare API
447
+ */
448
+ async function apiPatch(path, body, options) {
449
+ return requestCloudflareResult(path, {
450
+ method: "PATCH",
451
+ body
452
+ }, options);
453
+ }
454
+ /**
455
+ * Make a DELETE request to the Cloudflare API
456
+ */
457
+ async function apiDelete(path, options) {
458
+ return requestCloudflareResult(path, { method: "DELETE" }, options);
459
+ }
460
+ const DEFAULT_PAGINATION_MAX_PAGES = 500;
461
+ const DEFAULT_PAGINATION_PAGE_SIZE = 50;
462
+ /**
463
+ * Make a paginated GET request, fetching all pages.
464
+ *
465
+ * Emits a `console.warn` and throws `PaginationCapExceededError` when the
466
+ * explicit `maxPages` cap is reached with more data still available, to
467
+ * prevent silent truncation (which would otherwise cause callers to
468
+ * re-create already-existing resources as if they did not exist). Pass a
469
+ * higher `maxPages` when the caller knows the resource count can exceed the
470
+ * default cap.
471
+ */
472
+ async function apiGetAll(path, options) {
473
+ const results = [];
474
+ let page = 1;
475
+ let cursor;
476
+ const perPage = options?.pageSize ?? DEFAULT_PAGINATION_PAGE_SIZE;
477
+ const maxPages = options?.maxPages ?? DEFAULT_PAGINATION_MAX_PAGES;
478
+ const seenCursors = /* @__PURE__ */ new Set();
479
+ const extractPaginatedItems = (result) => {
480
+ if (Array.isArray(result)) return result;
481
+ if (!result || typeof result !== "object") throw new Error("Expected paginated Cloudflare API result to be an array or an object containing an array.");
482
+ const arrayEntries = Object.entries(result).filter(([, value]) => Array.isArray(value));
483
+ if (arrayEntries.length !== 1) throw new Error("Expected paginated Cloudflare API result object to contain exactly one array property.");
484
+ return arrayEntries[0][1];
485
+ };
486
+ while (page <= maxPages) {
487
+ const separator = path.includes("?") ? "&" : "?";
488
+ const pagedPath = cursor ? `${path}${separator}cursor=${encodeURIComponent(cursor)}&per_page=${perPage}` : `${path}${separator}page=${page}&per_page=${perPage}`;
489
+ const { response, envelope } = await requestCloudflareJson(pagedPath, {
490
+ method: "GET",
491
+ allowAuthRetry: true
492
+ }, options);
493
+ if (!envelope.success) throw envelopeFailureError(response, envelope, `GET ${pagedPath}`);
494
+ const pageResults = extractPaginatedItems(envelope.result);
495
+ results.push(...pageResults);
496
+ if (!envelope.result_info) break;
497
+ if (pageResults.length === 0) break;
498
+ const nextCursor = envelope.result_info.cursor?.trim();
499
+ if (nextCursor) {
500
+ if (seenCursors.has(nextCursor)) break;
501
+ seenCursors.add(nextCursor);
502
+ cursor = nextCursor;
503
+ continue;
504
+ }
505
+ if (cursor) break;
506
+ if (envelope.result_info.total_count !== void 0) {
507
+ if (results.length >= envelope.result_info.total_count) break;
508
+ }
509
+ if (envelope.result_info.total_pages !== void 0) {
510
+ if (page >= envelope.result_info.total_pages) break;
511
+ }
512
+ page++;
513
+ }
514
+ if (page > maxPages) {
515
+ if (results.length % perPage === 0 && results.length > 0) console.warn(`[devflare] apiGetAll capped at ${maxPages} pages for ${path}. Results may be truncated; pass { maxPages } to raise the cap.`);
516
+ }
517
+ return results;
518
+ }
519
+ async function requestKVValue(accountId, namespaceId, key, request, options) {
520
+ const authorization = await resolveAuthHeader(options);
521
+ return fetchWithTimeout(`${API_BASE}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${encodeURIComponent(key)}`, {
522
+ method: request.method,
523
+ headers: {
524
+ Authorization: authorization,
525
+ ...request.method === "PUT" ? { "Content-Type": "text/plain" } : {}
526
+ },
527
+ ...request.method === "PUT" ? { body: request.value } : {}
528
+ }, options?.timeout ?? DEFAULT_TIMEOUT);
529
+ }
530
+ /**
531
+ * Surface a failed KV-value response as a typed CloudflareAPIError by
532
+ * decoding the envelope the error path emits.
533
+ */
534
+ async function throwKVValueError(response, endpoint) {
535
+ await parseCloudflareEnvelope(response, { endpoint });
536
+ throw new CloudflareAPIError(`Cloudflare ${endpoint} failed`, response.status, []);
537
+ }
538
+ /**
539
+ * Read a KV value (raw text response, not JSON envelope)
540
+ * Returns null if key doesn't exist (404)
541
+ */
542
+ async function kvGet(accountId, namespaceId, key, options) {
543
+ const response = await requestKVValue(accountId, namespaceId, key, { method: "GET" }, options);
544
+ if (response.status === 404) return null;
545
+ if (!response.ok) await throwKVValueError(response, "KV read");
546
+ return response.text();
547
+ }
548
+ /**
549
+ * Write a KV value (raw text body, not JSON)
550
+ */
551
+ async function kvPut(accountId, namespaceId, key, value, options) {
552
+ const response = await requestKVValue(accountId, namespaceId, key, {
553
+ method: "PUT",
554
+ value
555
+ }, options);
556
+ if (!response.ok) await throwKVValueError(response, "KV write");
557
+ }
558
+ /**
559
+ * Delete a KV key
560
+ * Treats 404 as success (key already absent).
561
+ */
562
+ async function kvDelete(accountId, namespaceId, key, options) {
563
+ const response = await requestKVValue(accountId, namespaceId, key, { method: "DELETE" }, options);
564
+ if (response.status === 404) return;
565
+ if (!response.ok) await throwKVValueError(response, "KV delete");
566
+ }
567
+ //#endregion
568
+ export { apiGetAll as a, apiPut as c, kvGet as d, kvPut as f, isAuthenticated as g, hasWranglerConfig as h, apiGet as i, api_exports as l, getWranglerAuth as m, CloudflareAPIError as n, apiPatch as o, getApiToken as p, apiDelete as r, apiPost as s, AuthenticationError as t, kvDelete as u };