devflare 1.0.0-next.39 → 1.0.0-next.40

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 (277) hide show
  1. package/dist/_chunks/account-BtWcv3X9.js +462 -0
  2. package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
  3. package/dist/_chunks/ai-CBEuLdoP.js +322 -0
  4. package/dist/_chunks/api-TzdliH-6.js +568 -0
  5. package/dist/_chunks/build-3T6O4uIg.js +24 -0
  6. package/dist/_chunks/build-artifacts-8TqBSQkG.js +483 -0
  7. package/dist/_chunks/cli-BTF1X4SG.js +1128 -0
  8. package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
  9. package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
  10. package/dist/_chunks/command-utils-BsfkmTqh.js +45 -0
  11. package/dist/_chunks/compiler-uoyAQ8zW.js +424 -0
  12. package/dist/_chunks/config-D5u-bEkn.js +78 -0
  13. package/dist/_chunks/config-path-DCPto4XB.js +42 -0
  14. package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
  15. package/dist/_chunks/decorators-QmV57ixr.js +19 -0
  16. package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
  17. package/dist/_chunks/deploy-DMTr6JeR.js +915 -0
  18. package/dist/_chunks/dev-CvRHmRFZ.js +3456 -0
  19. package/dist/_chunks/doctor-DIG8DoFU.js +219 -0
  20. package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
  21. package/dist/_chunks/env-S0_nMVz1.js +125 -0
  22. package/dist/_chunks/family-DXC5SdFK.js +143 -0
  23. package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
  24. package/dist/_chunks/glob-CmQOvunB.js +56 -0
  25. package/dist/_chunks/init-3moXTgpb.js +165 -0
  26. package/dist/_chunks/loader-DLXO60RO.js +1153 -0
  27. package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
  28. package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
  29. package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
  30. package/dist/_chunks/local-secrets-DMmEOygL.js +123 -0
  31. package/dist/_chunks/local-workflow-entrypoints-Wip3o1u8.js +90 -0
  32. package/dist/_chunks/login-BmnDzDlH.js +51 -0
  33. package/dist/_chunks/package-metadata-DAuCkyvK.js +39 -0
  34. package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
  35. package/dist/_chunks/preview-BhqDmq8I.js +456 -0
  36. package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
  37. package/dist/_chunks/preview-resources-DdXj8LMM.js +358 -0
  38. package/dist/_chunks/previews-Dlr13x5M.js +1134 -0
  39. package/dist/_chunks/productions-D3AnOHac.js +411 -0
  40. package/dist/_chunks/ref-CYJNAAe_.js +178 -0
  41. package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
  42. package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
  43. package/dist/_chunks/resolve-package-Y84HB3Nt.js +133 -0
  44. package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
  45. package/dist/_chunks/routes-C3FqES2W.js +796 -0
  46. package/dist/_chunks/runtime-FvXvfuZ2.js +550 -0
  47. package/dist/_chunks/schema-normalization-DWVleVxo.js +477 -0
  48. package/dist/_chunks/secrets-70eN0Q6C.js +95 -0
  49. package/dist/_chunks/token-kguIDmej.js +333 -0
  50. package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
  51. package/dist/_chunks/types-OrLbzv4I.js +476 -0
  52. package/dist/_chunks/ui-BUoZApvE.js +103 -0
  53. package/dist/_chunks/usage-BBTGzjon.js +272 -0
  54. package/dist/_chunks/vite-CsI0E-uV.js +1235 -0
  55. package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
  56. package/dist/_chunks/worker-CS1jgNFE.js +410 -0
  57. package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
  58. package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
  59. package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
  60. package/dist/bridge/index.d.ts +6 -6
  61. package/dist/bridge/miniflare.d.ts +2 -2
  62. package/dist/bridge/proxy.d.ts +1 -1
  63. package/dist/bridge/v2/body-streams.d.ts +1 -1
  64. package/dist/bridge/v2/codec.d.ts +4 -4
  65. package/dist/bridge/v2/index.d.ts +10 -10
  66. package/dist/bridge/v2/serialization.d.ts +1 -1
  67. package/dist/bridge/v2/value-codec.d.ts +1 -1
  68. package/dist/bridge/v2/value-serialization.d.ts.map +1 -1
  69. package/dist/bridge/v2/ws-relay.d.ts +3 -3
  70. package/dist/browser-shim/index.d.ts +2 -2
  71. package/dist/browser.d.ts +70 -70
  72. package/dist/browser.js +74 -2462
  73. package/dist/bundler/do-bundler.d.ts +1 -1
  74. package/dist/bundler/index.d.ts +3 -3
  75. package/dist/bundler/rolldown-shared.d.ts +1 -1
  76. package/dist/bundler/worker-bundler.d.ts +1 -1
  77. package/dist/cli/build-manifest.d.ts +1 -1
  78. package/dist/cli/command-utils.d.ts +1 -1
  79. package/dist/cli/commands/account.d.ts +1 -1
  80. package/dist/cli/commands/ai.d.ts +1 -1
  81. package/dist/cli/commands/build-artifacts.d.ts +5 -5
  82. package/dist/cli/commands/build.d.ts +1 -1
  83. package/dist/cli/commands/config.d.ts +1 -1
  84. package/dist/cli/commands/deploy/prepare.d.ts +2 -2
  85. package/dist/cli/commands/deploy/runtime.d.ts +1 -1
  86. package/dist/cli/commands/deploy/verification.d.ts +1 -1
  87. package/dist/cli/commands/deploy.d.ts +1 -1
  88. package/dist/cli/commands/dev.d.ts +1 -1
  89. package/dist/cli/commands/doctor.d.ts +1 -1
  90. package/dist/cli/commands/init.d.ts +1 -1
  91. package/dist/cli/commands/login.d.ts +1 -1
  92. package/dist/cli/commands/previews-support/cleanup.d.ts +1 -1
  93. package/dist/cli/commands/previews-support/family.d.ts +3 -3
  94. package/dist/cli/commands/previews-support/render.d.ts +3 -3
  95. package/dist/cli/commands/previews-support/theme.d.ts +2 -2
  96. package/dist/cli/commands/previews-support/types.d.ts +2 -2
  97. package/dist/cli/commands/previews.d.ts +1 -1
  98. package/dist/cli/commands/productions.d.ts +1 -1
  99. package/dist/cli/commands/remote.d.ts +1 -1
  100. package/dist/cli/commands/secrets.d.ts +1 -1
  101. package/dist/cli/commands/token.d.ts +1 -1
  102. package/dist/cli/commands/type-generation/discovery.d.ts +2 -2
  103. package/dist/cli/commands/type-generation/generator.d.ts +3 -3
  104. package/dist/cli/commands/type-generation/models.d.ts +1 -1
  105. package/dist/cli/commands/types.d.ts +1 -1
  106. package/dist/cli/commands/worker.d.ts +1 -1
  107. package/dist/cli/deploy-strategy.d.ts +1 -1
  108. package/dist/cli/deploy-target.d.ts +1 -1
  109. package/dist/cli/help-pages/pages/account.d.ts +1 -1
  110. package/dist/cli/help-pages/pages/core.d.ts +1 -1
  111. package/dist/cli/help-pages/pages/index.d.ts +1 -1
  112. package/dist/cli/help-pages/pages/misc.d.ts +1 -1
  113. package/dist/cli/help-pages/pages/previews.d.ts +1 -1
  114. package/dist/cli/help-pages/pages/productions.d.ts +1 -1
  115. package/dist/cli/help-pages/render.d.ts +2 -2
  116. package/dist/cli/help-pages/shared.d.ts +1 -1
  117. package/dist/cli/help.d.ts +2 -2
  118. package/dist/cli/index.js +2 -1383
  119. package/dist/cli/preview-bindings.d.ts +3 -3
  120. package/dist/cli/preview.d.ts +1 -1
  121. package/dist/cli/wrangler-auth.d.ts +1 -1
  122. package/dist/cloudflare/account-core.d.ts +2 -2
  123. package/dist/cloudflare/account-resources.d.ts +2 -2
  124. package/dist/cloudflare/account-status.d.ts +1 -1
  125. package/dist/cloudflare/account-workers.d.ts +2 -2
  126. package/dist/cloudflare/account.d.ts +7 -7
  127. package/dist/cloudflare/auth.d.ts +1 -1
  128. package/dist/cloudflare/index.d.ts +13 -13
  129. package/dist/cloudflare/index.js +4 -59
  130. package/dist/cloudflare/kv-namespace.d.ts +1 -1
  131. package/dist/cloudflare/preview-registry-cache.d.ts +1 -1
  132. package/dist/cloudflare/preview-registry-inference.d.ts +2 -2
  133. package/dist/cloudflare/preview-registry-records.d.ts +3 -3
  134. package/dist/cloudflare/preview-registry-shape.d.ts +2 -2
  135. package/dist/cloudflare/preview-registry-store.d.ts +3 -3
  136. package/dist/cloudflare/preview-registry-transport.d.ts +2 -2
  137. package/dist/cloudflare/preview-registry-types.d.ts +2 -2
  138. package/dist/cloudflare/preview-registry.d.ts +5 -5
  139. package/dist/cloudflare/tokens.d.ts +2 -2
  140. package/dist/cloudflare/usage.d.ts +2 -2
  141. package/dist/config/binding-resolution-helpers.d.ts +1 -1
  142. package/dist/config/compiler/bindings.d.ts +2 -2
  143. package/dist/config/compiler/core-helpers.d.ts +2 -2
  144. package/dist/config/compiler/do-workers.d.ts +2 -2
  145. package/dist/config/compiler/paths.d.ts +1 -1
  146. package/dist/config/compiler.d.ts +6 -6
  147. package/dist/config/define.d.ts +2 -2
  148. package/dist/config/deploy-resources.d.ts +5 -5
  149. package/dist/config/env-vars.d.ts +1 -1
  150. package/dist/config/framework-providers.d.ts +1 -1
  151. package/dist/config/index.d.ts +12 -12
  152. package/dist/config/loader.d.ts +2 -2
  153. package/dist/config/local-dev-vars.d.ts +1 -1
  154. package/dist/config/preview-resources.d.ts +4 -4
  155. package/dist/config/preview.d.ts +1 -1
  156. package/dist/config/ref.d.ts +2 -2
  157. package/dist/config/resolve-phased.d.ts +4 -4
  158. package/dist/config/resolve.d.ts +1 -1
  159. package/dist/config/resource-resolution.d.ts +6 -6
  160. package/dist/config/schema-env.d.ts +20 -20
  161. package/dist/config/schema-normalization.d.ts +1 -1
  162. package/dist/config/schema-types-bindings.d.ts +4 -4
  163. package/dist/config/schema-types-build.d.ts +1 -1
  164. package/dist/config/schema-types.d.ts +7 -7
  165. package/dist/config/schema.d.ts +46 -46
  166. package/dist/config/service-bindings-validation.d.ts +1 -1
  167. package/dist/config-entry.d.ts +6 -6
  168. package/dist/config-entry.js +3 -8
  169. package/dist/decorators/index.d.ts +2 -2
  170. package/dist/decorators/index.js +2 -9
  171. package/dist/dev-server/d1-migrations.d.ts +1 -1
  172. package/dist/dev-server/dev-server-state.d.ts +6 -6
  173. package/dist/dev-server/gateway-script.d.ts +1 -1
  174. package/dist/dev-server/index.d.ts +1 -1
  175. package/dist/dev-server/miniflare-bindings.d.ts +1 -1
  176. package/dist/dev-server/miniflare-dev-config.d.ts +5 -5
  177. package/dist/dev-server/miniflare-worker-config.d.ts +3 -3
  178. package/dist/dev-server/server-startup-helpers.d.ts +6 -6
  179. package/dist/dev-server/worker-surface-paths.d.ts +2 -2
  180. package/dist/index.d.ts +8 -8
  181. package/dist/index.js +9 -22
  182. package/dist/runtime/context-events.d.ts +1 -1
  183. package/dist/runtime/context.d.ts +3 -3
  184. package/dist/runtime/exports.d.ts +2 -2
  185. package/dist/runtime/index.d.ts +10 -10
  186. package/dist/runtime/index.js +5 -57
  187. package/dist/runtime/middleware.d.ts +1 -1
  188. package/dist/runtime/router/index.d.ts +3 -3
  189. package/dist/runtime/validation.d.ts +1 -1
  190. package/dist/secrets/local-secrets.d.ts +1 -1
  191. package/dist/shims/local-media-bindings.d.ts +1 -1
  192. package/dist/sveltekit/index.d.ts +1 -1
  193. package/dist/sveltekit/index.js +327 -9
  194. package/dist/sveltekit/local-bindings.d.ts +1 -1
  195. package/dist/sveltekit/platform.d.ts +1 -1
  196. package/dist/test/binding-hints.d.ts +2 -2
  197. package/dist/test/cf.d.ts +19 -19
  198. package/dist/test/index.d.ts +18 -18
  199. package/dist/test/index.js +4495 -46
  200. package/dist/test/offline-bindings.d.ts +3 -3
  201. package/dist/test/resolve-service-bindings.d.ts +1 -1
  202. package/dist/test/simple-context-bindings.d.ts +1 -1
  203. package/dist/test/simple-context-durable-objects.d.ts +1 -1
  204. package/dist/test/simple-context-env.d.ts +2 -2
  205. package/dist/test/simple-context-handlers.d.ts +2 -2
  206. package/dist/test/simple-context-lifecycle.d.ts +2 -2
  207. package/dist/test/simple-context-mfconfig.d.ts +1 -1
  208. package/dist/test/simple-context-multi-worker.d.ts +2 -2
  209. package/dist/test/simple-context-runtime.d.ts +1 -1
  210. package/dist/test/simple-context-startup.d.ts +1 -1
  211. package/dist/test/simple-context.d.ts +1 -1
  212. package/dist/test/utilities/env.d.ts +3 -3
  213. package/dist/test/utilities.d.ts +10 -10
  214. package/dist/test/worker.d.ts +1 -1
  215. package/dist/transform/index.d.ts +2 -2
  216. package/dist/utils/send-email.js +163 -19
  217. package/dist/vite/config-file.d.ts +2 -2
  218. package/dist/vite/index.d.ts +3 -3
  219. package/dist/vite/index.js +2 -31
  220. package/dist/vite/plugin-config-hook.d.ts +1 -1
  221. package/dist/vite/plugin-context.d.ts +3 -3
  222. package/dist/vite/plugin-durable-objects.d.ts +2 -2
  223. package/dist/vite/plugin-programmatic.d.ts +1 -1
  224. package/dist/vite/plugin-service-bindings.d.ts +2 -2
  225. package/dist/vite/plugin.d.ts +3 -3
  226. package/dist/worker-entry/composed-worker.d.ts +1 -1
  227. package/dist/worker-entry/routes.d.ts +2 -2
  228. package/dist/worker-entry/surface-paths.d.ts +1 -1
  229. package/dist/workflows/local-workflow-entrypoints.d.ts +1 -1
  230. package/package.json +5 -3
  231. package/dist/account-4tgh03a8.js +0 -484
  232. package/dist/ai-r3zqmxan.js +0 -261
  233. package/dist/api-6z01z734.js +0 -33
  234. package/dist/build-kw625v84.js +0 -51
  235. package/dist/config-ghk2bxj3.js +0 -102
  236. package/dist/deploy-9kee65n9.js +0 -1062
  237. package/dist/dev-x8zr249a.js +0 -3569
  238. package/dist/doctor-0ng5qrr1.js +0 -258
  239. package/dist/durable-object-0ybmg08a.js +0 -13
  240. package/dist/index-04wh9bxx.js +0 -514
  241. package/dist/index-0cc05hzv.js +0 -74
  242. package/dist/index-2yv7w548.js +0 -185
  243. package/dist/index-37x76zdn.js +0 -4
  244. package/dist/index-3cpzsr47.js +0 -125
  245. package/dist/index-3t6rypgc.js +0 -13
  246. package/dist/index-4mmpccrb.js +0 -309
  247. package/dist/index-5dkjffqz.js +0 -25
  248. package/dist/index-5hy7jmv3.js +0 -890
  249. package/dist/index-627srx16.js +0 -45
  250. package/dist/index-7m557715.js +0 -283
  251. package/dist/index-a8pnvg3r.js +0 -52
  252. package/dist/index-aabgympv.js +0 -39
  253. package/dist/index-atwc3csp.js +0 -256
  254. package/dist/index-cv4cvrxe.js +0 -2046
  255. package/dist/index-h7r11y4a.js +0 -539
  256. package/dist/index-hvtd936d.js +0 -1229
  257. package/dist/index-kcp7y951.js +0 -136
  258. package/dist/index-maw0jjnn.js +0 -147
  259. package/dist/index-mek9msfv.js +0 -705
  260. package/dist/index-n4xkaymm.js +0 -236
  261. package/dist/index-nkk59p3y.js +0 -579
  262. package/dist/index-phcrvs6d.js +0 -342
  263. package/dist/index-se4kw8tm.js +0 -460
  264. package/dist/index-x8s9rwfh.js +0 -2020
  265. package/dist/index-y7w3x9p1.js +0 -18
  266. package/dist/index-z9gy8w6b.js +0 -57
  267. package/dist/index-zdd0d9qa.js +0 -199
  268. package/dist/init-tb8jqgvr.js +0 -180
  269. package/dist/login-4h1sfsed.js +0 -75
  270. package/dist/previews-qr7c5j8h.js +0 -1336
  271. package/dist/productions-xpmd6bw8.js +0 -505
  272. package/dist/remote-kqcvhnfx.js +0 -192
  273. package/dist/secrets-6wbdsdek.js +0 -89
  274. package/dist/token-yp1qa70y.js +0 -419
  275. package/dist/types-15yv4cj3.js +0 -701
  276. package/dist/worker-1yg72jxg.js +0 -510
  277. package/dist/worker-entrypoint-y8s9kdcx.js +0 -15
@@ -1,539 +0,0 @@
1
- import {
2
- CloudflareAPIError,
3
- apiDelete,
4
- apiGet,
5
- apiGetAll,
6
- apiPatch,
7
- apiPost,
8
- kvDelete,
9
- kvGet,
10
- kvPut
11
- } from "./index-04wh9bxx.js";
12
- import {
13
- __require
14
- } from "./index-37x76zdn.js";
15
-
16
- // src/cloudflare/account-core.ts
17
- async function getAccounts(options) {
18
- const accounts = await apiGetAll("/accounts", options);
19
- return accounts.map((account) => ({
20
- id: account.id,
21
- name: account.name,
22
- type: account.type,
23
- createdOn: account.created_on ? new Date(account.created_on) : undefined
24
- }));
25
- }
26
- async function getPrimaryAccount(options) {
27
- const accounts = await getAccounts(options);
28
- return accounts[0] ?? null;
29
- }
30
- async function getAccountById(accountId, options) {
31
- try {
32
- const account = await apiGet(`/accounts/${accountId}`, options);
33
- return {
34
- id: account.id,
35
- name: account.name,
36
- type: account.type,
37
- createdOn: account.created_on ? new Date(account.created_on) : undefined
38
- };
39
- } catch {
40
- return null;
41
- }
42
- }
43
-
44
- // src/cloudflare/account-workers.ts
45
- async function listWorkers(accountId, options) {
46
- const scripts = await apiGetAll(`/accounts/${accountId}/workers/scripts`, options);
47
- return scripts.map((script) => ({
48
- name: script.name ?? script.id,
49
- createdOn: new Date(script.created_on),
50
- modifiedOn: new Date(script.modified_on)
51
- }));
52
- }
53
- async function renameWorker(accountId, workerId, newName, options) {
54
- const encodedWorkerId = encodeURIComponent(workerId);
55
- const result = await apiPatch(`/accounts/${accountId}/workers/workers/${encodedWorkerId}`, { name: newName }, options);
56
- return {
57
- id: result.id,
58
- name: result.name
59
- };
60
- }
61
- async function deleteWorker(accountId, scriptName, options) {
62
- const encodedScriptName = encodeURIComponent(scriptName);
63
- await apiDelete(`/accounts/${accountId}/workers/scripts/${encodedScriptName}`, options);
64
- }
65
- function mapWorkerVersionInfo(version) {
66
- return {
67
- id: version.id ?? "",
68
- number: version.number,
69
- metadata: {
70
- authorEmail: version.metadata?.author_email,
71
- authorId: version.metadata?.author_id,
72
- createdOn: version.metadata?.created_on ? new Date(version.metadata.created_on) : undefined,
73
- modifiedOn: version.metadata?.modified_on ? new Date(version.metadata.modified_on) : undefined,
74
- hasPreview: version.metadata?.has_preview === true || version.metadata?.hasPreview === true,
75
- source: version.metadata?.source
76
- }
77
- };
78
- }
79
- async function listWorkerVersions(accountId, scriptName, options) {
80
- const versions = [];
81
- const encodedScriptName = encodeURIComponent(scriptName);
82
- for (let page = 1;page <= 100; page++) {
83
- const result = await apiGet(`/accounts/${accountId}/workers/scripts/${encodedScriptName}/versions?page=${page}&per_page=100`, options);
84
- const items = result.items ?? [];
85
- versions.push(...items.map((item) => mapWorkerVersionInfo(item)));
86
- if (items.length < 100) {
87
- break;
88
- }
89
- }
90
- return versions;
91
- }
92
- async function getWorkerVersionDetail(accountId, scriptName, versionId, options) {
93
- const encodedScriptName = encodeURIComponent(scriptName);
94
- const result = await apiGet(`/accounts/${accountId}/workers/scripts/${encodedScriptName}/versions/${versionId}`, options);
95
- return mapWorkerVersionInfo(result);
96
- }
97
- async function listWorkerDeployments(accountId, scriptName, options) {
98
- const encodedScriptName = encodeURIComponent(scriptName);
99
- const result = await apiGet(`/accounts/${accountId}/workers/scripts/${encodedScriptName}/deployments`, options);
100
- return (result.deployments ?? []).map((deployment) => ({
101
- id: deployment.id,
102
- createdOn: new Date(deployment.created_on),
103
- source: deployment.source,
104
- strategy: deployment.strategy,
105
- versions: deployment.versions.map((version) => ({
106
- percentage: version.percentage,
107
- versionId: version.version_id
108
- })),
109
- message: deployment.annotations?.["workers/message"],
110
- triggeredBy: deployment.annotations?.["workers/triggered_by"],
111
- authorEmail: deployment.author_email
112
- }));
113
- }
114
- async function getWorkersSubdomain(accountId, options) {
115
- try {
116
- const result = await apiGet(`/accounts/${accountId}/workers/subdomain`, options);
117
- return result.subdomain || null;
118
- } catch {
119
- return null;
120
- }
121
- }
122
-
123
- // src/cloudflare/account-resources.ts
124
- async function listKVNamespaces(accountId, options) {
125
- const namespaces = await apiGetAll(`/accounts/${accountId}/storage/kv/namespaces`, options);
126
- return namespaces.map((namespace) => ({
127
- id: namespace.id,
128
- name: namespace.title
129
- }));
130
- }
131
- async function createKVNamespace(accountId, title, options) {
132
- const namespace = await apiPost(`/accounts/${accountId}/storage/kv/namespaces`, { title }, options);
133
- return {
134
- id: namespace.id,
135
- name: namespace.title
136
- };
137
- }
138
- async function deleteKVNamespace(accountId, namespaceId, options) {
139
- const encodedNamespaceId = encodeURIComponent(namespaceId);
140
- await apiDelete(`/accounts/${accountId}/storage/kv/namespaces/${encodedNamespaceId}`, options);
141
- }
142
- async function listD1Databases(accountId, options) {
143
- const databases = await apiGetAll(`/accounts/${accountId}/d1/database`, options);
144
- return databases.map((database) => ({
145
- id: database.uuid,
146
- name: database.name,
147
- version: database.version,
148
- tableCount: database.num_tables,
149
- sizeBytes: database.file_size
150
- }));
151
- }
152
- async function createD1Database(accountId, name, options) {
153
- const created = await apiPost(`/accounts/${accountId}/d1/database`, {
154
- name,
155
- ...options?.jurisdiction ? { jurisdiction: options.jurisdiction } : {},
156
- ...options?.primaryLocationHint ? { primary_location_hint: options.primaryLocationHint } : {}
157
- }, options);
158
- return {
159
- id: created.uuid,
160
- name: created.name,
161
- version: created.version,
162
- tableCount: created.num_tables,
163
- sizeBytes: created.file_size
164
- };
165
- }
166
- async function deleteD1Database(accountId, databaseId, options) {
167
- const encodedDatabaseId = encodeURIComponent(databaseId);
168
- await apiDelete(`/accounts/${accountId}/d1/database/${encodedDatabaseId}`, options);
169
- }
170
- async function queryD1Database(accountId, databaseId, query, options) {
171
- const { apiPost: apiPost2 } = await import("./api-6z01z734.js");
172
- return apiPost2(`/accounts/${accountId}/d1/database/${databaseId}/query`, query, options);
173
- }
174
- async function rawD1DatabaseQuery(accountId, databaseId, query, options) {
175
- const { apiPost: apiPost2 } = await import("./api-6z01z734.js");
176
- return apiPost2(`/accounts/${accountId}/d1/database/${databaseId}/raw`, query, options);
177
- }
178
- async function listQueues(accountId, options) {
179
- const queues = await apiGetAll(`/accounts/${accountId}/queues`, options);
180
- return queues.filter((queue) => {
181
- return typeof queue.queue_id === "string" && queue.queue_id.length > 0 && typeof queue.queue_name === "string" && queue.queue_name.length > 0;
182
- }).map((queue) => ({
183
- id: queue.queue_id,
184
- name: queue.queue_name,
185
- createdOn: queue.created_on ? new Date(queue.created_on) : undefined,
186
- modifiedOn: queue.modified_on ? new Date(queue.modified_on) : undefined,
187
- deliveryDelay: queue.settings?.delivery_delay,
188
- deliveryPaused: queue.settings?.delivery_paused,
189
- messageRetentionPeriod: queue.settings?.message_retention_period
190
- }));
191
- }
192
- async function createQueue(accountId, queueName, options) {
193
- const queue = await apiPost(`/accounts/${accountId}/queues`, { queue_name: queueName }, options);
194
- return {
195
- id: queue.queue_id ?? "",
196
- name: queue.queue_name ?? queueName,
197
- createdOn: queue.created_on ? new Date(queue.created_on) : undefined,
198
- modifiedOn: queue.modified_on ? new Date(queue.modified_on) : undefined,
199
- deliveryDelay: queue.settings?.delivery_delay,
200
- deliveryPaused: queue.settings?.delivery_paused,
201
- messageRetentionPeriod: queue.settings?.message_retention_period
202
- };
203
- }
204
- async function deleteQueue(accountId, queueId, options) {
205
- const encodedQueueId = encodeURIComponent(queueId);
206
- await apiDelete(`/accounts/${accountId}/queues/${encodedQueueId}`, options);
207
- }
208
- async function listR2Buckets(accountId, options) {
209
- const buckets = await apiGetAll(`/accounts/${accountId}/r2/buckets`, options);
210
- return buckets.map((bucket) => ({
211
- name: bucket.name,
212
- createdOn: new Date(bucket.creation_date),
213
- location: bucket.location
214
- }));
215
- }
216
- async function createR2Bucket(accountId, name, options) {
217
- const bucket = await apiPost(`/accounts/${accountId}/r2/buckets`, {
218
- name,
219
- ...options?.locationHint ? { locationHint: options.locationHint } : {},
220
- ...options?.storageClass ? { storageClass: options.storageClass } : {}
221
- }, options);
222
- return {
223
- name: bucket.name,
224
- createdOn: bucket.creation_date ? new Date(bucket.creation_date) : new Date,
225
- location: bucket.location
226
- };
227
- }
228
- async function deleteR2Bucket(accountId, bucketName, options) {
229
- const encodedBucketName = encodeURIComponent(bucketName);
230
- await apiDelete(`/accounts/${accountId}/r2/buckets/${encodedBucketName}`, options);
231
- }
232
- async function listHyperdrives(accountId, options) {
233
- const hyperdrives = await apiGetAll(`/accounts/${accountId}/hyperdrive/configs`, options);
234
- return hyperdrives.map((hyperdrive) => ({
235
- id: hyperdrive.id,
236
- name: hyperdrive.name,
237
- createdOn: hyperdrive.created_on ? new Date(hyperdrive.created_on) : undefined,
238
- modifiedOn: hyperdrive.modified_on ? new Date(hyperdrive.modified_on) : undefined
239
- }));
240
- }
241
- async function deleteHyperdrive(accountId, hyperdriveId, options) {
242
- const encodedHyperdriveId = encodeURIComponent(hyperdriveId);
243
- await apiDelete(`/accounts/${accountId}/hyperdrive/configs/${encodedHyperdriveId}`, options);
244
- }
245
- async function listVectorizeIndexes(accountId, options) {
246
- try {
247
- const indexes = await apiGetAll(`/accounts/${accountId}/vectorize/v2/indexes`, options);
248
- return indexes.map((index) => ({
249
- name: index.name,
250
- dimensions: index.config.dimensions,
251
- metric: index.config.metric,
252
- description: index.description
253
- }));
254
- } catch (error) {
255
- if (error instanceof CloudflareAPIError && error.code === 404) {
256
- return [];
257
- }
258
- throw error;
259
- }
260
- }
261
- async function createVectorizeIndex(accountId, index, options) {
262
- const created = await apiPost(`/accounts/${accountId}/vectorize/v2/indexes`, {
263
- name: index.name,
264
- config: {
265
- dimensions: index.dimensions,
266
- metric: index.metric
267
- },
268
- ...index.description ? { description: index.description } : {}
269
- }, options);
270
- return {
271
- name: created.name,
272
- dimensions: created.config.dimensions,
273
- metric: created.config.metric,
274
- description: created.description
275
- };
276
- }
277
- async function deleteVectorizeIndex(accountId, indexName, options) {
278
- const encodedIndexName = encodeURIComponent(indexName);
279
- await apiDelete(`/accounts/${accountId}/vectorize/v2/indexes/${encodedIndexName}`, options);
280
- }
281
- async function listAIModels(accountId, options) {
282
- try {
283
- const models = await apiGetAll(`/accounts/${accountId}/ai/models/search`, options);
284
- return models.map((model) => ({
285
- id: model.id,
286
- name: model.name,
287
- task: model.task?.name,
288
- description: model.description
289
- }));
290
- } catch {
291
- return [];
292
- }
293
- }
294
-
295
- // src/cloudflare/account-status.ts
296
- var SERVICE_STATUS_TIMEOUT_MS = 1e4;
297
- var serviceInventoryFetchers = {
298
- workers: listWorkers,
299
- kv: listKVNamespaces,
300
- d1: listD1Databases,
301
- hyperdrive: listHyperdrives,
302
- r2: listR2Buckets,
303
- vectorize: listVectorizeIndexes,
304
- ai: listAIModels
305
- };
306
- async function withServiceTimeout(operation) {
307
- let timeoutId = null;
308
- const timeoutPromise = new Promise((_, reject) => {
309
- timeoutId = setTimeout(() => reject(new Error("timeout")), SERVICE_STATUS_TIMEOUT_MS);
310
- });
311
- try {
312
- return await Promise.race([operation, timeoutPromise]);
313
- } finally {
314
- if (timeoutId) {
315
- clearTimeout(timeoutId);
316
- }
317
- }
318
- }
319
- function createAvailableServiceStatus(service, count) {
320
- return {
321
- service,
322
- available: service === "ai" ? count > 0 : true,
323
- count
324
- };
325
- }
326
- async function getServiceStatus(accountId, service) {
327
- const fetchInventory = serviceInventoryFetchers[service];
328
- if (!fetchInventory) {
329
- return {
330
- service,
331
- available: false
332
- };
333
- }
334
- try {
335
- const inventory = await withServiceTimeout(fetchInventory(accountId));
336
- return createAvailableServiceStatus(service, inventory.length);
337
- } catch {
338
- return {
339
- service,
340
- available: false
341
- };
342
- }
343
- }
344
- async function getAllServiceStatus(accountId) {
345
- const services = [
346
- "workers",
347
- "kv",
348
- "d1",
349
- "hyperdrive",
350
- "r2",
351
- "vectorize",
352
- "ai"
353
- ];
354
- return Promise.all(services.map((service) => getServiceStatus(accountId, service)));
355
- }
356
- async function hasService(accountId, service) {
357
- const status = await getServiceStatus(accountId, service);
358
- return status.available;
359
- }
360
- async function getAccountSummary(accountId) {
361
- const account = await getAccountById(accountId);
362
- if (!account) {
363
- return null;
364
- }
365
- const services = await getAllServiceStatus(accountId);
366
- return {
367
- account,
368
- services
369
- };
370
- }
371
- // src/cloudflare/preferences.ts
372
- import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
373
- import { homedir } from "node:os";
374
- import { join } from "node:path";
375
-
376
- // src/cloudflare/kv-namespace.ts
377
- var DEVFLARE_KV_NAMESPACE_TITLE = "devflare-usage";
378
- async function getOrCreateNamedKVNamespace(accountId, title = DEVFLARE_KV_NAMESPACE_TITLE, options) {
379
- const namespaces = await apiGetAll(`/accounts/${accountId}/storage/kv/namespaces`, options);
380
- const existing = namespaces.find((namespace) => namespace.title === title);
381
- if (existing) {
382
- return existing.id;
383
- }
384
- const created = await apiPost(`/accounts/${accountId}/storage/kv/namespaces`, { title }, options);
385
- return created.id;
386
- }
387
-
388
- // src/cloudflare/preferences.ts
389
- var GLOBAL_ACCOUNT_KEY = "settings:defaultAccountId";
390
- var LOCAL_CACHE_DIR = ".devflare";
391
- var LOCAL_CACHE_FILE = "preferences.json";
392
- function writeFileAtomic(path, contents) {
393
- const tmpPath = path + ".tmp-" + process.pid + "-" + Date.now();
394
- writeFileSync(tmpPath, contents, "utf-8");
395
- try {
396
- renameSync(tmpPath, path);
397
- } catch (error) {
398
- try {
399
- unlinkSync(tmpPath);
400
- } catch {}
401
- throw error;
402
- }
403
- }
404
- function getLocalPreferencesPath() {
405
- return join(homedir(), LOCAL_CACHE_DIR, LOCAL_CACHE_FILE);
406
- }
407
- function readLocalPreferences() {
408
- const path = getLocalPreferencesPath();
409
- if (!existsSync(path)) {
410
- return {};
411
- }
412
- try {
413
- const content = readFileSync(path, "utf-8");
414
- return JSON.parse(content);
415
- } catch {
416
- return {};
417
- }
418
- }
419
- function writeLocalPreferences(prefs) {
420
- const path = getLocalPreferencesPath();
421
- const dir = join(homedir(), LOCAL_CACHE_DIR);
422
- if (!existsSync(dir)) {
423
- mkdirSync(dir, { recursive: true });
424
- }
425
- writeFileAtomic(path, JSON.stringify(prefs, null, "\t"));
426
- }
427
- function findPackageJsonPath(startDir) {
428
- let dir = startDir ?? process.cwd();
429
- while (dir !== join(dir, "..")) {
430
- const pkgPath = join(dir, "package.json");
431
- if (existsSync(pkgPath)) {
432
- return pkgPath;
433
- }
434
- dir = join(dir, "..");
435
- }
436
- return null;
437
- }
438
- function readPackageJson(path) {
439
- try {
440
- const content = readFileSync(path, "utf-8");
441
- return JSON.parse(content);
442
- } catch {
443
- return null;
444
- }
445
- }
446
- function writePackageJson(path, pkg) {
447
- writeFileAtomic(path, JSON.stringify(pkg, null, "\t") + `
448
- `);
449
- }
450
- function getWorkspaceAccountId() {
451
- const pkgPath = findPackageJsonPath();
452
- if (!pkgPath)
453
- return null;
454
- const pkg = readPackageJson(pkgPath);
455
- return pkg?.devflare?.accountId ?? null;
456
- }
457
- function setWorkspaceAccountId(accountId) {
458
- let pkgPath = findPackageJsonPath();
459
- let pkg;
460
- if (pkgPath) {
461
- pkg = readPackageJson(pkgPath) ?? {};
462
- } else {
463
- pkgPath = join(process.cwd(), "package.json");
464
- pkg = {
465
- name: "workspace",
466
- private: true
467
- };
468
- }
469
- if (!pkg.devflare) {
470
- pkg.devflare = {};
471
- }
472
- pkg.devflare.accountId = accountId;
473
- writePackageJson(pkgPath, pkg);
474
- return pkgPath;
475
- }
476
- async function getOrCreatePreferencesNamespace(accountId) {
477
- return getOrCreateNamedKVNamespace(accountId, DEVFLARE_KV_NAMESPACE_TITLE);
478
- }
479
- async function getGlobalDefaultAccountId(fallbackAccountId) {
480
- const local = readLocalPreferences();
481
- if (local.defaultAccountId) {
482
- return local.defaultAccountId;
483
- }
484
- try {
485
- const namespaceId = await getOrCreatePreferencesNamespace(fallbackAccountId);
486
- const value = await kvGet(fallbackAccountId, namespaceId, GLOBAL_ACCOUNT_KEY);
487
- if (value) {
488
- writeLocalPreferences({
489
- ...local,
490
- defaultAccountId: value,
491
- lastUpdated: new Date().toISOString()
492
- });
493
- return value;
494
- }
495
- } catch (error) {
496
- console.debug("[devflare preferences] cloud KV sync failed:", error instanceof Error ? error.message : String(error));
497
- }
498
- return null;
499
- }
500
- async function setGlobalDefaultAccountId(accountId, anyAccountId) {
501
- const kvAccountId = anyAccountId ?? accountId;
502
- const local = readLocalPreferences();
503
- writeLocalPreferences({
504
- ...local,
505
- defaultAccountId: accountId,
506
- lastUpdated: new Date().toISOString()
507
- });
508
- try {
509
- const namespaceId = await getOrCreatePreferencesNamespace(kvAccountId);
510
- await kvPut(kvAccountId, namespaceId, GLOBAL_ACCOUNT_KEY, accountId);
511
- } catch (error) {
512
- console.debug("[devflare preferences] cloud KV sync failed:", error instanceof Error ? error.message : String(error));
513
- }
514
- }
515
- async function getEffectiveAccountId(primaryAccountId) {
516
- const workspaceId = getWorkspaceAccountId();
517
- if (workspaceId) {
518
- return { accountId: workspaceId, source: "workspace" };
519
- }
520
- const globalId = await getGlobalDefaultAccountId(primaryAccountId);
521
- if (globalId) {
522
- return { accountId: globalId, source: "global" };
523
- }
524
- return { accountId: primaryAccountId, source: "primary" };
525
- }
526
- async function clearGlobalDefaultAccountId(anyAccountId) {
527
- const local = readLocalPreferences();
528
- delete local.defaultAccountId;
529
- local.lastUpdated = new Date().toISOString();
530
- writeLocalPreferences(local);
531
- try {
532
- const namespaceId = await getOrCreatePreferencesNamespace(anyAccountId);
533
- await kvDelete(anyAccountId, namespaceId, GLOBAL_ACCOUNT_KEY);
534
- } catch (error) {
535
- console.debug("[devflare preferences] cloud KV sync failed:", error instanceof Error ? error.message : String(error));
536
- }
537
- }
538
-
539
- export { getAccounts, getPrimaryAccount, getAccountById, listWorkers, renameWorker, deleteWorker, listWorkerVersions, getWorkerVersionDetail, listWorkerDeployments, getWorkersSubdomain, listKVNamespaces, createKVNamespace, deleteKVNamespace, listD1Databases, createD1Database, deleteD1Database, queryD1Database, rawD1DatabaseQuery, listQueues, createQueue, deleteQueue, listR2Buckets, createR2Bucket, deleteR2Bucket, listHyperdrives, deleteHyperdrive, listVectorizeIndexes, createVectorizeIndex, deleteVectorizeIndex, listAIModels, getServiceStatus, getAllServiceStatus, hasService, getAccountSummary, DEVFLARE_KV_NAMESPACE_TITLE, getOrCreateNamedKVNamespace, getWorkspaceAccountId, setWorkspaceAccountId, getGlobalDefaultAccountId, setGlobalDefaultAccountId, getEffectiveAccountId, clearGlobalDefaultAccountId };