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,89 +0,0 @@
1
- import {
2
- deleteLocalSecret,
3
- listLocalSecrets,
4
- writeLocalSecret
5
- } from "./index-kcp7y951.js";
6
- import"./index-mek9msfv.js";
7
- import"./index-x8s9rwfh.js";
8
- import"./index-h7r11y4a.js";
9
- import"./index-04wh9bxx.js";
10
- import"./index-37x76zdn.js";
11
-
12
- // src/cli/commands/secrets.ts
13
- function getStringOption(options, key) {
14
- const value = options[key];
15
- return typeof value === "string" ? value : undefined;
16
- }
17
- function getCwd(options) {
18
- return options.cwd ?? process.cwd();
19
- }
20
- function requireLocalFlag(parsed, logger) {
21
- if (parsed.options.local === true) {
22
- return true;
23
- }
24
- logger.error("Local Secrets Store commands require --local.");
25
- return false;
26
- }
27
- function requireStoreAndName(parsed, logger) {
28
- const storeId = getStringOption(parsed.options, "store");
29
- const name = getStringOption(parsed.options, "name");
30
- if (!storeId || !name) {
31
- logger.error("Pass --store <id> and --name <name>.");
32
- return;
33
- }
34
- return { storeId, name };
35
- }
36
- function formatSecretRef(storeId, name) {
37
- return `${storeId}/${name}`;
38
- }
39
- function usage() {
40
- return [
41
- "devflare secrets --local --store <id> --name <name> --value <value>",
42
- "devflare secrets --local --store <id> --list",
43
- "devflare secrets --local --store <id> --name <name> --delete"
44
- ].join(`
45
- `);
46
- }
47
- function runSecretsCommand(parsed, logger, options) {
48
- if (!requireLocalFlag(parsed, logger)) {
49
- return { exitCode: 1, output: usage() };
50
- }
51
- const cwd = getCwd(options);
52
- const storeId = getStringOption(parsed.options, "store");
53
- if (parsed.options.list === true) {
54
- const rows = listLocalSecrets({ cwd, storeId });
55
- const output2 = rows.map((row) => formatSecretRef(row.storeId, row.name)).join(`
56
- `);
57
- if (output2) {
58
- logger.info(output2);
59
- }
60
- return { exitCode: 0, output: output2 };
61
- }
62
- const required = requireStoreAndName(parsed, logger);
63
- if (!required) {
64
- return { exitCode: 1, output: usage() };
65
- }
66
- if (parsed.options.delete === true) {
67
- deleteLocalSecret({ cwd, storeId: required.storeId, name: required.name });
68
- const output2 = formatSecretRef(required.storeId, required.name);
69
- logger.success(`Deleted local secret ${output2}`);
70
- return { exitCode: 0, output: output2 };
71
- }
72
- const value = getStringOption(parsed.options, "value");
73
- if (value === undefined) {
74
- logger.error("Pass --value <value>, --list, or --delete.");
75
- return { exitCode: 1, output: usage() };
76
- }
77
- writeLocalSecret({
78
- cwd,
79
- storeId: required.storeId,
80
- name: required.name,
81
- value
82
- });
83
- const output = formatSecretRef(required.storeId, required.name);
84
- logger.success(`Stored local secret ${output}`);
85
- return { exitCode: 0, output };
86
- }
87
- export {
88
- runSecretsCommand
89
- };
@@ -1,419 +0,0 @@
1
- import {
2
- createAccountOwnedAPIToken,
3
- deleteAccountOwnedAPIToken,
4
- filterDevflareManagedTokens,
5
- listAccountOwnedAPITokens,
6
- listAccountTokenPermissionGroups,
7
- normalizeDevflareTokenName,
8
- rollAccountOwnedAPITokenValue,
9
- selectAllReusablePermissionGroups,
10
- selectDevflarePermissionGroups,
11
- stripDevflareTokenNamePrefix
12
- } from "./index-atwc3csp.js";
13
- import {
14
- createCliTheme,
15
- dim,
16
- green,
17
- logLine,
18
- logTable,
19
- whiteDim,
20
- yellow
21
- } from "./index-maw0jjnn.js";
22
- import"./index-3t6rypgc.js";
23
- import {
24
- getPrimaryAccount,
25
- getWorkspaceAccountId
26
- } from "./index-h7r11y4a.js";
27
- import {
28
- AuthenticationError,
29
- CloudflareAPIError
30
- } from "./index-04wh9bxx.js";
31
- import"./index-37x76zdn.js";
32
-
33
- // src/cli/commands/token.ts
34
- var CLI_API_OPTIONS = { timeout: 1e4 };
35
- var TOKENS_USAGE = "devflare tokens <bootstrap-token> (--list | --new [token-name] | --roll [token-name] | --delete [token-name] | --delete-all) [--account <id>] [--all-flags]";
36
- var TOKEN_OPERATION_SUMMARY_LINES = [
37
- "--list List Devflare-managed account-owned tokens",
38
- "--new [name] Create a Devflare-managed account-owned token",
39
- "--roll [name] Roll a Devflare-managed account-owned token secret",
40
- "--delete [name] Delete a Devflare-managed account-owned token",
41
- "--delete-all Delete every Devflare-managed account-owned token",
42
- "--all-flags With --new, include every reusable account/zone-scoped permission group"
43
- ];
44
- function getTrimmedStringOption(options, key) {
45
- const value = options[key];
46
- if (typeof value !== "string") {
47
- return;
48
- }
49
- const trimmedValue = value.trim();
50
- return trimmedValue || undefined;
51
- }
52
- function formatTokenTimestamp(value) {
53
- if (!value) {
54
- return "—";
55
- }
56
- return value.toISOString().replace(/:\d{2}\.\d{3}Z$/, "Z").replace("T", " ");
57
- }
58
- function sortTokens(tokens) {
59
- return [...tokens].sort((left, right) => {
60
- const nameComparison = left.name.localeCompare(right.name);
61
- if (nameComparison !== 0) {
62
- return nameComparison;
63
- }
64
- return (right.modifiedOn?.getTime() ?? 0) - (left.modifiedOn?.getTime() ?? 0);
65
- });
66
- }
67
- function logUsage(logger, theme) {
68
- logLine(logger);
69
- logLine(logger, `${dim("Usage:", theme)} ${TOKENS_USAGE}`);
70
- logLine(logger, dim("Operations:", theme));
71
- for (const line of TOKEN_OPERATION_SUMMARY_LINES) {
72
- logLine(logger, ` ${line}`);
73
- }
74
- logLine(logger, dim("Token names are normalized to the devflare- prefix automatically.", theme));
75
- logLine(logger, dim("The bootstrap token must include Cloudflare API token management permissions.", theme));
76
- logLine(logger);
77
- }
78
- function resolveTokenOperation(parsed) {
79
- const newOption = parsed.options.new;
80
- const rollOption = parsed.options.roll;
81
- const deleteOption = parsed.options.delete;
82
- const requestedOperations = [
83
- newOption !== undefined ? "new" : null,
84
- rollOption !== undefined ? "roll" : null,
85
- deleteOption !== undefined ? "delete" : null,
86
- parsed.options.list === true ? "list" : null,
87
- parsed.options["delete-all"] === true ? "delete-all" : null
88
- ].filter(Boolean);
89
- if (parsed.options["all-flags"] && !requestedOperations.includes("new")) {
90
- return "--all-flags can only be used together with --new.";
91
- }
92
- if (requestedOperations.length === 0) {
93
- return "Choose one token operation: --list, --new, --roll, --delete, or --delete-all.";
94
- }
95
- if (requestedOperations.length > 1) {
96
- return "Choose only one token operation at a time.";
97
- }
98
- switch (requestedOperations[0]) {
99
- case "new":
100
- return {
101
- kind: "new",
102
- requestedName: typeof newOption === "string" ? newOption.trim() || undefined : undefined
103
- };
104
- case "roll":
105
- return {
106
- kind: "roll",
107
- requestedName: typeof rollOption === "string" ? rollOption.trim() || undefined : undefined
108
- };
109
- case "delete":
110
- return {
111
- kind: "delete",
112
- requestedName: typeof deleteOption === "string" ? deleteOption.trim() || undefined : undefined
113
- };
114
- case "list":
115
- return { kind: "list" };
116
- case "delete-all":
117
- return { kind: "delete-all" };
118
- }
119
- }
120
- function formatManagedTokenDisplayName(name) {
121
- return stripDevflareTokenNamePrefix(name);
122
- }
123
- async function promptForTokenName(logger, theme, message) {
124
- while (true) {
125
- const selected = await logger.prompt(message, {
126
- type: "text",
127
- placeholder: "preview",
128
- cancel: "symbol"
129
- });
130
- if (typeof selected === "symbol") {
131
- logLine(logger, dim("Cancelled", theme));
132
- return null;
133
- }
134
- const trimmedValue = selected.trim();
135
- if (trimmedValue) {
136
- return trimmedValue;
137
- }
138
- logger.error("Token name is required.");
139
- }
140
- }
141
- async function resolveTokenName(requestedName, logger, theme, promptMessage) {
142
- const rawName = requestedName ?? await promptForTokenName(logger, theme, promptMessage);
143
- if (!rawName) {
144
- return null;
145
- }
146
- return normalizeDevflareTokenName(rawName);
147
- }
148
- async function resolveNamedManagedTokens(accountId, accountSource, bootstrapToken, requestedName, logger, theme, options) {
149
- const tokenName = await resolveTokenName(requestedName, logger, theme, options.promptMessage);
150
- if (!tokenName) {
151
- return { exitCode: 0 };
152
- }
153
- logLine(logger);
154
- logLine(logger, `${yellow("tokens", theme)} ${dim(`${options.actionLabel} a Devflare-managed account-owned token…`, theme)}`);
155
- logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
156
- logLine(logger, `${dim("Name:", theme)} ${green(tokenName, theme)}`);
157
- const accountTokens = await listAccountOwnedAPITokens(accountId, {
158
- ...CLI_API_OPTIONS,
159
- token: bootstrapToken
160
- });
161
- const matchingTokens = filterDevflareManagedTokens(accountTokens).filter((token) => token.name === tokenName);
162
- if (matchingTokens.length === 0) {
163
- logger.error(`No Devflare-managed token named ${tokenName} was found.`);
164
- return { exitCode: 1 };
165
- }
166
- if (matchingTokens.length > 1) {
167
- logLine(logger, dim(`Found ${matchingTokens.length} tokens with that name. ${options.multipleMatchMessage}.`, theme));
168
- }
169
- return {
170
- tokenName,
171
- matchingTokens
172
- };
173
- }
174
- async function resolveRequestedAccountId(requestedAccountId, bootstrapToken) {
175
- if (requestedAccountId) {
176
- return { accountId: requestedAccountId, source: "flag" };
177
- }
178
- const workspaceAccountId = getWorkspaceAccountId();
179
- if (workspaceAccountId) {
180
- return {
181
- accountId: workspaceAccountId,
182
- source: "workspace"
183
- };
184
- }
185
- const primaryAccount = await getPrimaryAccount({
186
- ...CLI_API_OPTIONS,
187
- token: bootstrapToken
188
- });
189
- if (!primaryAccount) {
190
- throw new Error("No Cloudflare accounts found for this bootstrap token");
191
- }
192
- return {
193
- accountId: primaryAccount.id,
194
- source: "primary"
195
- };
196
- }
197
- async function createManagedToken(accountId, accountSource, bootstrapToken, requestedName, includeAllFlags, logger, theme) {
198
- const tokenName = await resolveTokenName(requestedName, logger, theme, "Enter a Devflare token name:");
199
- if (!tokenName) {
200
- return { exitCode: 0 };
201
- }
202
- logLine(logger);
203
- logLine(logger, `${yellow("tokens", theme)} ${dim("Creating an account-owned Devflare token…", theme)}`);
204
- logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
205
- logLine(logger, `${dim("Name:", theme)} ${green(tokenName, theme)}`);
206
- const permissionGroups = await listAccountTokenPermissionGroups(accountId, {
207
- ...CLI_API_OPTIONS,
208
- token: bootstrapToken
209
- });
210
- if (permissionGroups.length === 0) {
211
- logger.error("Cloudflare returned zero account token permission groups for this account.");
212
- return { exitCode: 1 };
213
- }
214
- const selectedPermissionGroups = includeAllFlags ? selectAllReusablePermissionGroups(permissionGroups) : selectDevflarePermissionGroups(permissionGroups);
215
- const createdToken = await createAccountOwnedAPIToken(accountId, {
216
- name: tokenName,
217
- permissionGroups: selectedPermissionGroups
218
- }, {
219
- ...CLI_API_OPTIONS,
220
- token: bootstrapToken
221
- });
222
- if (!createdToken.value) {
223
- logger.error("Cloudflare created the token but did not return a token value.");
224
- return { exitCode: 1 };
225
- }
226
- logger.success(`Created ${createdToken.name || tokenName}`);
227
- logLine(logger, `${dim("Permission groups:", theme)} ${selectedPermissionGroups.length} ${includeAllFlags ? "reusable account/zone-scoped" : "Devflare-relevant account/zone-scoped"} selected from ${permissionGroups.length} available`);
228
- if (includeAllFlags) {
229
- logLine(logger, dim("Account-owned Devflare tokens include account resources plus all zones in the account; user-scoped groups are skipped automatically.", theme));
230
- logLine(logger, dim("Account API Tokens permissions are still excluded because Cloudflare does not allow sub-tokens to manage other tokens.", theme));
231
- }
232
- logger.warn("Cloudflare only returns the token secret once. Store it safely now.");
233
- logger.log(createdToken.value);
234
- return {
235
- exitCode: 0,
236
- output: createdToken.value
237
- };
238
- }
239
- async function listManagedTokens(accountId, accountSource, bootstrapToken, logger, theme) {
240
- logLine(logger);
241
- logLine(logger, `${yellow("tokens", theme)} ${dim("Listing Devflare-managed account-owned tokens…", theme)}`);
242
- logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
243
- const accountTokens = await listAccountOwnedAPITokens(accountId, {
244
- ...CLI_API_OPTIONS,
245
- token: bootstrapToken
246
- });
247
- const managedTokens = sortTokens(filterDevflareManagedTokens(accountTokens));
248
- if (managedTokens.length === 0) {
249
- logLine(logger, dim("No Devflare-managed account-owned tokens found for this account.", theme));
250
- return { exitCode: 0, output: "" };
251
- }
252
- logTable(logger, {
253
- title: "Devflare-managed tokens",
254
- rows: managedTokens,
255
- columns: [
256
- {
257
- label: "Name",
258
- value: (token) => formatManagedTokenDisplayName(token.name),
259
- width: 46
260
- },
261
- {
262
- label: "Status",
263
- value: (token) => token.status ?? "unknown",
264
- width: 10
265
- },
266
- {
267
- label: "Token ID",
268
- value: (token) => token.id.slice(0, 12),
269
- width: 12
270
- },
271
- {
272
- label: "Modified",
273
- value: (token) => formatTokenTimestamp(token.modifiedOn)
274
- }
275
- ],
276
- theme
277
- });
278
- const untouchedTokenCount = accountTokens.length - managedTokens.length;
279
- if (untouchedTokenCount > 0) {
280
- logLine(logger, dim(`Left ${untouchedTokenCount} non-Devflare token(s) out of this list.`, theme));
281
- }
282
- return {
283
- exitCode: 0,
284
- output: managedTokens.map((token) => formatManagedTokenDisplayName(token.name)).join(`
285
- `)
286
- };
287
- }
288
- async function rollManagedTokensByName(accountId, accountSource, bootstrapToken, requestedName, logger, theme) {
289
- const selectedTokens = await resolveNamedManagedTokens(accountId, accountSource, bootstrapToken, requestedName, logger, theme, {
290
- promptMessage: "Enter the Devflare token name to roll:",
291
- actionLabel: "Rolling",
292
- multipleMatchMessage: "Rolling all exact matches"
293
- });
294
- if ("exitCode" in selectedTokens) {
295
- return selectedTokens;
296
- }
297
- const { tokenName, matchingTokens } = selectedTokens;
298
- const rolledValues = [];
299
- for (const token of matchingTokens) {
300
- const rolledValue = await rollAccountOwnedAPITokenValue(accountId, token.id, {
301
- ...CLI_API_OPTIONS,
302
- token: bootstrapToken
303
- });
304
- rolledValues.push(rolledValue);
305
- }
306
- logger.success(`Rolled ${matchingTokens.length} Devflare-managed token(s) named ${tokenName}`);
307
- logger.warn("Cloudflare only returns the new token secret once. Store it safely now.");
308
- if (rolledValues.length === 1) {
309
- logger.log(rolledValues[0]);
310
- } else {
311
- for (const [index, value] of rolledValues.entries()) {
312
- logLine(logger, `${dim(`${matchingTokens[index].id.slice(0, 12)}:`, theme)} ${value}`);
313
- }
314
- }
315
- return {
316
- exitCode: 0,
317
- output: rolledValues.join(`
318
- `)
319
- };
320
- }
321
- async function deleteManagedTokensByName(accountId, accountSource, bootstrapToken, requestedName, logger, theme) {
322
- const selectedTokens = await resolveNamedManagedTokens(accountId, accountSource, bootstrapToken, requestedName, logger, theme, {
323
- promptMessage: "Enter the Devflare token name to delete:",
324
- actionLabel: "Deleting",
325
- multipleMatchMessage: "Deleting all exact matches"
326
- });
327
- if ("exitCode" in selectedTokens) {
328
- return selectedTokens;
329
- }
330
- const { tokenName, matchingTokens } = selectedTokens;
331
- for (const token of matchingTokens) {
332
- await deleteAccountOwnedAPIToken(accountId, token.id, {
333
- ...CLI_API_OPTIONS,
334
- token: bootstrapToken
335
- });
336
- }
337
- logger.success(`Deleted ${matchingTokens.length} Devflare-managed token(s) named ${tokenName}`);
338
- return {
339
- exitCode: 0,
340
- output: matchingTokens.map((token) => token.id).join(`
341
- `)
342
- };
343
- }
344
- async function deleteAllManagedTokens(accountId, accountSource, bootstrapToken, logger, theme) {
345
- logLine(logger);
346
- logLine(logger, `${yellow("tokens", theme)} ${dim("Deleting all Devflare-managed account-owned tokens…", theme)}`);
347
- logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
348
- const accountTokens = await listAccountOwnedAPITokens(accountId, {
349
- ...CLI_API_OPTIONS,
350
- token: bootstrapToken
351
- });
352
- const managedTokens = filterDevflareManagedTokens(accountTokens);
353
- if (managedTokens.length === 0) {
354
- logger.success("No Devflare-managed tokens were found, so nothing was deleted.");
355
- return { exitCode: 0 };
356
- }
357
- for (const token of managedTokens) {
358
- await deleteAccountOwnedAPIToken(accountId, token.id, {
359
- ...CLI_API_OPTIONS,
360
- token: bootstrapToken
361
- });
362
- }
363
- logger.success(`Deleted ${managedTokens.length} Devflare-managed token(s)`);
364
- const untouchedTokenCount = accountTokens.length - managedTokens.length;
365
- if (untouchedTokenCount > 0) {
366
- logLine(logger, dim(`Left ${untouchedTokenCount} non-Devflare token(s) untouched.`, theme));
367
- }
368
- return {
369
- exitCode: 0,
370
- output: managedTokens.map((token) => token.id).join(`
371
- `)
372
- };
373
- }
374
- async function runTokenCommand(parsed, logger, _options) {
375
- const bootstrapToken = parsed.args[0]?.trim();
376
- const theme = createCliTheme(parsed.options);
377
- if (!bootstrapToken) {
378
- logUsage(logger, theme);
379
- return { exitCode: 1 };
380
- }
381
- const tokenOperation = resolveTokenOperation(parsed);
382
- if (typeof tokenOperation === "string") {
383
- logUsage(logger, theme);
384
- return { exitCode: 1 };
385
- }
386
- const requestedAccountId = getTrimmedStringOption(parsed.options, "account");
387
- try {
388
- const { accountId, source } = await resolveRequestedAccountId(requestedAccountId, bootstrapToken);
389
- switch (tokenOperation.kind) {
390
- case "new":
391
- return createManagedToken(accountId, source, bootstrapToken, tokenOperation.requestedName, parsed.options["all-flags"] === true, logger, theme);
392
- case "roll":
393
- return rollManagedTokensByName(accountId, source, bootstrapToken, tokenOperation.requestedName, logger, theme);
394
- case "list":
395
- return listManagedTokens(accountId, source, bootstrapToken, logger, theme);
396
- case "delete":
397
- return deleteManagedTokensByName(accountId, source, bootstrapToken, tokenOperation.requestedName, logger, theme);
398
- case "delete-all":
399
- return deleteAllManagedTokens(accountId, source, bootstrapToken, logger, theme);
400
- }
401
- } catch (error) {
402
- if (error instanceof AuthenticationError) {
403
- logger.error(error.message);
404
- return { exitCode: 1 };
405
- }
406
- if (error instanceof CloudflareAPIError) {
407
- logger.error(`API Error: ${error.message}`);
408
- return { exitCode: 1 };
409
- }
410
- if (error instanceof Error) {
411
- logger.error(error.message);
412
- return { exitCode: 1 };
413
- }
414
- throw error;
415
- }
416
- }
417
- export {
418
- runTokenCommand
419
- };