@mtndev/cli 2.0.0 → 2.0.1

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 (264) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/cjs/__chunks/VH7oDXx4.cjs +28 -0
  3. package/cjs/commands/aws/ec2/allow-ip/handler.cjs +261 -12
  4. package/cjs/commands/aws/ec2/allow-ip/index.cjs +25 -55
  5. package/cjs/commands/aws/ec2/allow-ip/schema.cjs +33 -13
  6. package/cjs/commands/aws/ec2/allow-ip/utils.cjs +379 -39
  7. package/cjs/commands/aws/iam/admin-group.cjs +111 -15
  8. package/cjs/commands/aws/iam/break-glass/handler.cjs +127 -12
  9. package/cjs/commands/aws/iam/break-glass/index.cjs +7 -19
  10. package/cjs/commands/aws/iam/break-glass/schema.cjs +21 -12
  11. package/cjs/commands/aws/iam/check-admin/handler.cjs +89 -10
  12. package/cjs/commands/aws/iam/check-admin/index.cjs +7 -17
  13. package/cjs/commands/aws/iam/check-admin/schema.cjs +19 -12
  14. package/cjs/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.json +20 -0
  15. package/cjs/commands/aws/iam/policies/sts-federation.json +11 -0
  16. package/cjs/commands/aws/iam/policies/user-admins-deny-list.json +175 -0
  17. package/cjs/commands/aws/iam/policies/user-admins-deny-regions-list.json +41 -0
  18. package/cjs/commands/aws/iam/policies/user-admins-self-service-iam.json +56 -0
  19. package/cjs/commands/aws/iam/policies/user-admins-write-list.json +117 -0
  20. package/cjs/commands/aws/iam/remove-admin/handler.cjs +120 -11
  21. package/cjs/commands/aws/iam/remove-admin/index.cjs +7 -18
  22. package/cjs/commands/aws/iam/remove-admin/schema.cjs +22 -12
  23. package/cjs/commands/aws/iam/setup-acl/handler.cjs +227 -14
  24. package/cjs/commands/aws/iam/setup-acl/index.cjs +13 -33
  25. package/cjs/commands/aws/iam/setup-acl/schema.cjs +19 -7
  26. package/cjs/commands/aws/iam/setup-acl/utils.cjs +305 -20
  27. package/cjs/commands/aws/iam/users/handler.cjs +59 -12
  28. package/cjs/commands/aws/iam/users/index.cjs +18 -41
  29. package/cjs/commands/aws/iam/users/schema.cjs +17 -7
  30. package/cjs/commands/aws/iam/users/utils.cjs +454 -30
  31. package/cjs/commands/aws/index.cjs +223 -229
  32. package/cjs/commands/aws/route53/add-record/handler.cjs +264 -18
  33. package/cjs/commands/aws/route53/add-record/index.cjs +26 -57
  34. package/cjs/commands/aws/route53/add-record/schema.cjs +43 -11
  35. package/cjs/commands/aws/route53/add-record/utils.cjs +404 -37
  36. package/cjs/commands/aws/route53/remove-record/handler.cjs +114 -14
  37. package/cjs/commands/aws/route53/remove-record/index.cjs +5 -18
  38. package/cjs/commands/aws/route53/remove-record/schema.cjs +22 -8
  39. package/cjs/commands/aws/schema.cjs +19 -10
  40. package/cjs/commands/aws/ses/send-email/handler.cjs +73 -12
  41. package/cjs/commands/aws/ses/send-email/index.cjs +9 -23
  42. package/cjs/commands/aws/ses/send-email/schema.cjs +24 -7
  43. package/cjs/commands/aws/ses/send-email/utils.cjs +87 -11
  44. package/cjs/commands/aws/ses/smtp-password.cjs +72 -10
  45. package/cjs/commands/aws/utils/exec-aws.cjs +145 -16
  46. package/cjs/commands/aws/utils/resolve-policy-path.cjs +15 -6
  47. package/cjs/commands/aws/utils/resolve-profile.cjs +93 -11
  48. package/cjs/commands/aws/utils/tty.cjs +54 -10
  49. package/cjs/commands/db/create-readonly-user/handler.cjs +254 -11
  50. package/cjs/commands/db/create-readonly-user/index.cjs +18 -40
  51. package/cjs/commands/db/create-readonly-user/mysql.cjs +102 -9
  52. package/cjs/commands/db/create-readonly-user/postgres.cjs +209 -9
  53. package/cjs/commands/db/create-readonly-user/schema.cjs +39 -12
  54. package/cjs/commands/db/create-readonly-user/utils.cjs +160 -22
  55. package/cjs/commands/db/index.cjs +46 -44
  56. package/cjs/commands/doppler/handler.cjs +95 -11
  57. package/cjs/commands/doppler/index.cjs +33 -68
  58. package/cjs/commands/doppler/schema.cjs +130 -14
  59. package/cjs/commands/doppler/set-secret.cjs +378 -19
  60. package/cjs/commands/doppler/utils/exec.cjs +106 -12
  61. package/cjs/commands/doppler/utils.cjs +412 -34
  62. package/cjs/commands/icons/handler.cjs +82 -8
  63. package/cjs/commands/icons/index.cjs +15 -31
  64. package/cjs/commands/icons/schema.cjs +101 -13
  65. package/cjs/commands/icons/utils.cjs +131 -13
  66. package/cjs/commands/index.cjs +54 -161
  67. package/cjs/commands/schema.cjs +25 -8
  68. package/cjs/index.cjs +3 -4
  69. package/esm/commands/aws/ec2/allow-ip/handler.js +258 -12
  70. package/esm/commands/aws/ec2/allow-ip/index.js +4 -55
  71. package/esm/commands/aws/ec2/allow-ip/schema.js +29 -13
  72. package/esm/commands/aws/ec2/allow-ip/utils.js +363 -39
  73. package/esm/commands/aws/iam/admin-group.js +104 -15
  74. package/esm/commands/aws/iam/break-glass/handler.js +124 -12
  75. package/esm/commands/aws/iam/break-glass/index.js +4 -19
  76. package/esm/commands/aws/iam/break-glass/schema.js +19 -12
  77. package/esm/commands/aws/iam/check-admin/handler.js +86 -10
  78. package/esm/commands/aws/iam/check-admin/index.js +4 -17
  79. package/esm/commands/aws/iam/check-admin/schema.js +17 -12
  80. package/esm/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.json +20 -0
  81. package/esm/commands/aws/iam/policies/sts-federation.json +11 -0
  82. package/esm/commands/aws/iam/policies/user-admins-deny-list.json +175 -0
  83. package/esm/commands/aws/iam/policies/user-admins-deny-regions-list.json +41 -0
  84. package/esm/commands/aws/iam/policies/user-admins-self-service-iam.json +56 -0
  85. package/esm/commands/aws/iam/policies/user-admins-write-list.json +117 -0
  86. package/esm/commands/aws/iam/remove-admin/handler.js +117 -11
  87. package/esm/commands/aws/iam/remove-admin/index.js +4 -18
  88. package/esm/commands/aws/iam/remove-admin/schema.js +20 -12
  89. package/esm/commands/aws/iam/setup-acl/handler.js +224 -14
  90. package/esm/commands/aws/iam/setup-acl/index.js +4 -33
  91. package/esm/commands/aws/iam/setup-acl/schema.js +18 -7
  92. package/esm/commands/aws/iam/setup-acl/utils.js +298 -20
  93. package/esm/commands/aws/iam/users/handler.js +56 -12
  94. package/esm/commands/aws/iam/users/index.js +4 -41
  95. package/esm/commands/aws/iam/users/schema.js +16 -7
  96. package/esm/commands/aws/iam/users/utils.js +440 -30
  97. package/esm/commands/aws/index.js +142 -229
  98. package/esm/commands/aws/route53/add-record/handler.js +258 -18
  99. package/esm/commands/aws/route53/add-record/index.js +4 -57
  100. package/esm/commands/aws/route53/add-record/schema.js +40 -11
  101. package/esm/commands/aws/route53/add-record/utils.js +389 -37
  102. package/esm/commands/aws/route53/remove-record/handler.js +111 -14
  103. package/esm/commands/aws/route53/remove-record/index.js +3 -18
  104. package/esm/commands/aws/route53/remove-record/schema.js +21 -8
  105. package/esm/commands/aws/schema.js +16 -10
  106. package/esm/commands/aws/ses/send-email/handler.js +70 -12
  107. package/esm/commands/aws/ses/send-email/index.js +4 -23
  108. package/esm/commands/aws/ses/send-email/schema.js +23 -7
  109. package/esm/commands/aws/ses/send-email/utils.js +84 -11
  110. package/esm/commands/aws/ses/smtp-password.js +69 -10
  111. package/esm/commands/aws/utils/exec-aws.js +136 -15
  112. package/esm/commands/aws/utils/resolve-policy-path.js +14 -6
  113. package/esm/commands/aws/utils/resolve-profile.js +88 -11
  114. package/esm/commands/aws/utils/tty.js +51 -10
  115. package/esm/commands/db/create-readonly-user/handler.js +251 -11
  116. package/esm/commands/db/create-readonly-user/index.js +4 -40
  117. package/esm/commands/db/create-readonly-user/mysql.js +98 -9
  118. package/esm/commands/db/create-readonly-user/postgres.js +205 -9
  119. package/esm/commands/db/create-readonly-user/schema.js +35 -12
  120. package/esm/commands/db/create-readonly-user/utils.js +151 -22
  121. package/esm/commands/db/index.js +31 -44
  122. package/esm/commands/doppler/handler.js +92 -11
  123. package/esm/commands/doppler/index.js +6 -68
  124. package/esm/commands/doppler/schema.js +125 -15
  125. package/esm/commands/doppler/set-secret.js +370 -19
  126. package/esm/commands/doppler/utils/exec.js +100 -12
  127. package/esm/commands/doppler/utils.js +396 -34
  128. package/esm/commands/icons/handler.js +79 -8
  129. package/esm/commands/icons/index.js +4 -31
  130. package/esm/commands/icons/schema.js +97 -15
  131. package/esm/commands/icons/utils.js +125 -13
  132. package/esm/commands/index.js +47 -155
  133. package/esm/commands/schema.js +22 -7
  134. package/esm/index.js +3 -4
  135. package/package.json +5 -2
  136. package/vitest.config.ts +11 -0
  137. package/cjs/__chunks/2FSYDFUV.cjs +0 -146
  138. package/cjs/__chunks/3A5ZYU5M.cjs +0 -105
  139. package/cjs/__chunks/3BY5Y4W7.cjs +0 -1
  140. package/cjs/__chunks/3NOHGUCF.cjs +0 -9
  141. package/cjs/__chunks/3T2LXW7J.cjs +0 -387
  142. package/cjs/__chunks/4SFWHCB3.cjs +0 -133
  143. package/cjs/__chunks/4XT5JEAS.cjs +0 -1
  144. package/cjs/__chunks/AZEB4H4I.cjs +0 -208
  145. package/cjs/__chunks/B2KFW7T7.cjs +0 -1
  146. package/cjs/__chunks/B5ENMOCD.cjs +0 -288
  147. package/cjs/__chunks/B6XM5KSF.cjs +0 -338
  148. package/cjs/__chunks/BDU2UCE5.cjs +0 -1
  149. package/cjs/__chunks/BLMSMR5E.cjs +0 -46
  150. package/cjs/__chunks/CMUD7LLN.cjs +0 -47
  151. package/cjs/__chunks/DTQ2LB3I.cjs +0 -49
  152. package/cjs/__chunks/FM5MVRQF.cjs +0 -23
  153. package/cjs/__chunks/FRHST54J.cjs +0 -135
  154. package/cjs/__chunks/FU4VP2LN.cjs +0 -1
  155. package/cjs/__chunks/G5K4PVIL.cjs +0 -26
  156. package/cjs/__chunks/GU3R54MK.cjs +0 -127
  157. package/cjs/__chunks/GUL36IFZ.cjs +0 -61
  158. package/cjs/__chunks/GZMTNK5N.cjs +0 -1
  159. package/cjs/__chunks/H74JSDBU.cjs +0 -30
  160. package/cjs/__chunks/INFOPAHN.cjs +0 -117
  161. package/cjs/__chunks/J36P6UNE.cjs +0 -75
  162. package/cjs/__chunks/JB7T7PKQ.cjs +0 -538
  163. package/cjs/__chunks/JSL2JDMW.cjs +0 -1
  164. package/cjs/__chunks/K4QNHRTP.cjs +0 -163
  165. package/cjs/__chunks/KU76LC42.cjs +0 -192
  166. package/cjs/__chunks/LFDSHANP.cjs +0 -34
  167. package/cjs/__chunks/LHE24ECK.cjs +0 -192
  168. package/cjs/__chunks/LIKQ3SI4.cjs +0 -1
  169. package/cjs/__chunks/LXDF5QVZ.cjs +0 -313
  170. package/cjs/__chunks/LXOOJR2R.cjs +0 -74
  171. package/cjs/__chunks/N5MXFOQZ.cjs +0 -167
  172. package/cjs/__chunks/N7D56LPP.cjs +0 -25
  173. package/cjs/__chunks/NFXQNOQH.cjs +0 -393
  174. package/cjs/__chunks/NIMXXHJQ.cjs +0 -92
  175. package/cjs/__chunks/NLKJIUEX.cjs +0 -126
  176. package/cjs/__chunks/NT2XXAI6.cjs +0 -89
  177. package/cjs/__chunks/NWZGFHKH.cjs +0 -121
  178. package/cjs/__chunks/R3GUC7O7.cjs +0 -110
  179. package/cjs/__chunks/RPVAXPJ4.cjs +0 -1
  180. package/cjs/__chunks/S3LVCWPN.cjs +0 -23
  181. package/cjs/__chunks/SBBNW2BF.cjs +0 -249
  182. package/cjs/__chunks/T2A7TN4F.cjs +0 -81
  183. package/cjs/__chunks/TKNNDDIB.cjs +0 -97
  184. package/cjs/__chunks/TNSRDJPR.cjs +0 -1
  185. package/cjs/__chunks/UWHPE2GI.cjs +0 -20
  186. package/cjs/__chunks/W6K7BV74.cjs +0 -1
  187. package/cjs/__chunks/WBOQ6AUN.cjs +0 -320
  188. package/cjs/__chunks/WHGN5PZI.cjs +0 -299
  189. package/cjs/__chunks/WOYF2L6T.cjs +0 -11
  190. package/cjs/__chunks/X26XY2N6.cjs +0 -18
  191. package/cjs/__chunks/XMKOKRXZ.cjs +0 -16
  192. package/cjs/__chunks/XTJPQ3EX.cjs +0 -1
  193. package/cjs/__chunks/YRHFKTW2.cjs +0 -63
  194. package/cjs/__chunks/ZMDIOZPT.cjs +0 -22
  195. package/cjs/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.cjs +0 -28
  196. package/cjs/commands/aws/iam/policies/sts-federation.cjs +0 -19
  197. package/cjs/commands/aws/iam/policies/user-admins-deny-list.cjs +0 -183
  198. package/cjs/commands/aws/iam/policies/user-admins-deny-regions-list.cjs +0 -49
  199. package/cjs/commands/aws/iam/policies/user-admins-self-service-iam.cjs +0 -64
  200. package/cjs/commands/aws/iam/policies/user-admins-write-list.cjs +0 -125
  201. package/esm/__chunks/2FTTEFEK.js +0 -97
  202. package/esm/__chunks/33UYMUQD.js +0 -338
  203. package/esm/__chunks/3BKWTHLJ.js +0 -25
  204. package/esm/__chunks/3HE4BEJX.js +0 -105
  205. package/esm/__chunks/3QLI5BDL.js +0 -387
  206. package/esm/__chunks/5GIUAFXL.js +0 -89
  207. package/esm/__chunks/5ZBVGSOK.js +0 -0
  208. package/esm/__chunks/6G4PXXKF.js +0 -75
  209. package/esm/__chunks/73BJG53F.js +0 -11
  210. package/esm/__chunks/7VF4Q43Q.js +0 -0
  211. package/esm/__chunks/AEDEAYF5.js +0 -0
  212. package/esm/__chunks/AZCP3SFJ.js +0 -0
  213. package/esm/__chunks/B2DVQ2UL.js +0 -61
  214. package/esm/__chunks/CVQVHLW5.js +0 -0
  215. package/esm/__chunks/D62SPZXC.js +0 -0
  216. package/esm/__chunks/DLEJ25GZ.js +0 -121
  217. package/esm/__chunks/DMYFNF54.js +0 -192
  218. package/esm/__chunks/DNFTUMGD.js +0 -23
  219. package/esm/__chunks/DVKD6YSR.js +0 -49
  220. package/esm/__chunks/EMSH4P76.js +0 -20
  221. package/esm/__chunks/FFKFVMIE.js +0 -167
  222. package/esm/__chunks/FL7AILGH.js +0 -133
  223. package/esm/__chunks/FNXUONAV.js +0 -110
  224. package/esm/__chunks/G4NJHFFU.js +0 -320
  225. package/esm/__chunks/HJSXC6HP.js +0 -117
  226. package/esm/__chunks/IEOGAQYI.js +0 -46
  227. package/esm/__chunks/IZFGBYGE.js +0 -34
  228. package/esm/__chunks/J34UVKLA.js +0 -26
  229. package/esm/__chunks/JZPBBBIG.js +0 -74
  230. package/esm/__chunks/KWUJP5MG.js +0 -135
  231. package/esm/__chunks/M35URMT4.js +0 -313
  232. package/esm/__chunks/NF3M2L6C.js +0 -81
  233. package/esm/__chunks/O3CCA76Q.js +0 -22
  234. package/esm/__chunks/PNPPDYKC.js +0 -299
  235. package/esm/__chunks/QFXN4EHM.js +0 -393
  236. package/esm/__chunks/QKDDLIWD.js +0 -146
  237. package/esm/__chunks/QSE66AKY.js +0 -208
  238. package/esm/__chunks/QUF7PS4R.js +0 -18
  239. package/esm/__chunks/S7IJPJ4R.js +0 -126
  240. package/esm/__chunks/SD3E3EPH.js +0 -163
  241. package/esm/__chunks/SJXQJ7RS.js +0 -92
  242. package/esm/__chunks/SNCKIAOR.js +0 -0
  243. package/esm/__chunks/T3TTUHTW.js +0 -30
  244. package/esm/__chunks/TIOVE6HR.js +0 -0
  245. package/esm/__chunks/TXKMEIDQ.js +0 -0
  246. package/esm/__chunks/U7HAE2RF.js +0 -288
  247. package/esm/__chunks/UXWY7BYE.js +0 -63
  248. package/esm/__chunks/VKAKISRG.js +0 -192
  249. package/esm/__chunks/WD2YR6I7.js +0 -0
  250. package/esm/__chunks/WOZFZKFY.js +0 -0
  251. package/esm/__chunks/XI7GZDE2.js +0 -0
  252. package/esm/__chunks/XOUWDB3T.js +0 -249
  253. package/esm/__chunks/XQN2TA4S.js +0 -23
  254. package/esm/__chunks/XXK32TIM.js +0 -16
  255. package/esm/__chunks/YGWTVPZE.js +0 -538
  256. package/esm/__chunks/YRG7PT33.js +0 -127
  257. package/esm/__chunks/ZHKVJO2U.js +0 -47
  258. package/esm/__chunks/ZO55YUSY.js +0 -9
  259. package/esm/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.js +0 -28
  260. package/esm/commands/aws/iam/policies/sts-federation.js +0 -19
  261. package/esm/commands/aws/iam/policies/user-admins-deny-list.js +0 -183
  262. package/esm/commands/aws/iam/policies/user-admins-deny-regions-list.js +0 -49
  263. package/esm/commands/aws/iam/policies/user-admins-self-service-iam.js +0 -64
  264. package/esm/commands/aws/iam/policies/user-admins-write-list.js +0 -125
@@ -1,19 +1,370 @@
1
- import {
2
- getSecret,
3
- listConfigs,
4
- listEnvironments,
5
- listProjects,
6
- setSecret,
7
- setSecretInteractive
8
- } from "../../__chunks/QFXN4EHM.js";
9
- import "../../__chunks/YGWTVPZE.js";
10
- import "../../__chunks/ZHKVJO2U.js";
11
- import "../../__chunks/SJXQJ7RS.js";
12
- export {
13
- getSecret,
14
- listConfigs,
15
- listEnvironments,
16
- listProjects,
17
- setSecret,
18
- setSecretInteractive
19
- };
1
+ import { prompt, promptChoice, promptYesNo } from "../aws/utils/tty.js";
2
+ import { execDoppler } from "./utils.js";
3
+ import chalk from "chalk";
4
+ import { spawnSync } from "child_process";
5
+ //#region src/commands/doppler/set-secret.js
6
+ /**
7
+ * @typedef {Object} DopplerProject
8
+ * @property {string} id
9
+ * @property {string} name
10
+ * @property {string} [description]
11
+ */
12
+ /**
13
+ * @typedef {Object} DopplerEnvironment
14
+ * @property {string} id
15
+ * @property {string} name
16
+ */
17
+ /**
18
+ * @typedef {Object} DopplerConfig
19
+ * @property {string} name
20
+ * @property {string} environment
21
+ * @property {boolean} [root]
22
+ */
23
+ /**
24
+ * List Doppler projects (paginated until exhausted or cap).
25
+ * @param {{ verbose?: boolean; limit?: number }} [params]
26
+ * @returns {DopplerProject[]}
27
+ */
28
+ function listProjects(params = {}) {
29
+ const { verbose = false, limit = 500 } = params;
30
+ /** @type {DopplerProject[]} */
31
+ const projects = [];
32
+ let page = 1;
33
+ while (projects.length < limit) {
34
+ const batch = execDoppler([
35
+ "projects",
36
+ "--json",
37
+ "--page",
38
+ String(page),
39
+ "--number",
40
+ "100"
41
+ ], "json", true, verbose);
42
+ if (!Array.isArray(batch) || batch.length === 0) break;
43
+ for (const raw of batch) projects.push({
44
+ id: String(raw.id ?? raw.name ?? ""),
45
+ name: String(raw.name ?? raw.id ?? ""),
46
+ description: raw.description ? String(raw.description) : ""
47
+ });
48
+ if (batch.length < 100) break;
49
+ page += 1;
50
+ }
51
+ return projects.filter((project) => project.name).sort((a, b) => a.name.localeCompare(b.name));
52
+ }
53
+ /**
54
+ * List environments for a project.
55
+ * @param {{ project: string; verbose?: boolean }} params
56
+ * @returns {DopplerEnvironment[]}
57
+ */
58
+ function listEnvironments(params) {
59
+ const { project, verbose = false } = params;
60
+ const data = execDoppler([
61
+ "environments",
62
+ "--json",
63
+ "--project",
64
+ project
65
+ ], "json", true, verbose);
66
+ if (!Array.isArray(data)) return [];
67
+ return data.map((raw) => ({
68
+ id: String(raw.id ?? ""),
69
+ name: String(raw.name ?? raw.id ?? "")
70
+ })).filter((env) => env.id).sort((a, b) => a.id.localeCompare(b.id));
71
+ }
72
+ /**
73
+ * List configs for a project, optionally filtered by environment.
74
+ * @param {{ project: string; environment?: string; verbose?: boolean }} params
75
+ * @returns {DopplerConfig[]}
76
+ */
77
+ function listConfigs(params) {
78
+ const { project, environment, verbose = false } = params;
79
+ /** @type {string[]} */
80
+ const args = [
81
+ "configs",
82
+ "--json",
83
+ "--project",
84
+ project
85
+ ];
86
+ if (environment) args.push("--environment", environment);
87
+ const data = execDoppler(args, "json", true, verbose);
88
+ if (!Array.isArray(data)) return [];
89
+ return data.map((raw) => ({
90
+ name: String(raw.name ?? ""),
91
+ environment: String(raw.environment ?? ""),
92
+ root: Boolean(raw.root)
93
+ })).filter((config) => config.name).sort((a, b) => a.name.localeCompare(b.name));
94
+ }
95
+ /**
96
+ * Get an existing secret value (raw), or null if missing.
97
+ * @param {{
98
+ * project: string;
99
+ * config: string;
100
+ * name: string;
101
+ * verbose?: boolean;
102
+ * }} params
103
+ * @returns {string | null}
104
+ */
105
+ function getSecret(params) {
106
+ const { project, config, name, verbose = false } = params;
107
+ try {
108
+ const data = execDoppler([
109
+ "secrets",
110
+ "get",
111
+ name,
112
+ "--project",
113
+ project,
114
+ "--config",
115
+ config,
116
+ "--plain",
117
+ "--raw"
118
+ ], "string", true, verbose);
119
+ if (typeof data !== "string") return null;
120
+ const value = data.replace(/\n$/, "");
121
+ return value.length > 0 ? value : "";
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ /**
127
+ * Set a secret via stdin so values need no shell escaping.
128
+ * @param {{
129
+ * project: string;
130
+ * config: string;
131
+ * name: string;
132
+ * value: string;
133
+ * verbose?: boolean;
134
+ * }} params
135
+ */
136
+ function setSecret(params) {
137
+ const { project, config, name, value, verbose = false } = params;
138
+ const args = [
139
+ "secrets",
140
+ "set",
141
+ name,
142
+ "--project",
143
+ project,
144
+ "--config",
145
+ config,
146
+ "--no-interactive"
147
+ ];
148
+ if (verbose) console.log(chalk.gray(` Executing: doppler ${args.join(" ")} <stdin value (${value.length} chars)>`));
149
+ const result = spawnSync("doppler", args, {
150
+ encoding: "utf-8",
151
+ input: value
152
+ });
153
+ if (result.error) throw new Error(result.error.message);
154
+ if (result.status !== 0) {
155
+ const stderr = (result.stderr || result.stdout || "").trim();
156
+ throw new Error(stderr || `doppler secrets set failed for ${name}`);
157
+ }
158
+ }
159
+ /**
160
+ * @param {{ projects: DopplerProject[]; projectOption?: string }} params
161
+ * @returns {Promise<string>}
162
+ */
163
+ async function resolveProject(params) {
164
+ const { projects, projectOption } = params;
165
+ if (projectOption) {
166
+ const match = projects.find((project) => project.name === projectOption || project.id === projectOption);
167
+ if (!match) throw new Error(`Project "${projectOption}" not found. Available examples: ${projects.slice(0, 8).map((project) => project.name).join(", ")}`);
168
+ return match.name;
169
+ }
170
+ if (projects.length === 0) throw new Error("No Doppler projects found for this account.");
171
+ let candidates = projects;
172
+ if (projects.length > 30) {
173
+ const filter = await prompt(` Filter projects (${projects.length} total, Enter for all): `);
174
+ if (filter) {
175
+ const lower = filter.toLowerCase();
176
+ candidates = projects.filter((project) => project.name.toLowerCase().includes(lower) || project.id.toLowerCase().includes(lower));
177
+ if (candidates.length === 0) throw new Error(`No projects matched "${filter}".`);
178
+ }
179
+ }
180
+ const maxShown = 50;
181
+ const shown = candidates.slice(0, maxShown);
182
+ if (candidates.length > maxShown) console.log(chalk.yellow(` Showing first ${maxShown} of ${candidates.length} matches — refine with a filter next time.`));
183
+ const chosen = shown[await promptChoice({
184
+ message: "Choose a Doppler project:",
185
+ options: shown.map((project) => project.description ? `${project.name} — ${project.description}` : project.name)
186
+ })];
187
+ if (!chosen) throw new Error("No project selected");
188
+ return chosen.name;
189
+ }
190
+ /**
191
+ * @param {{
192
+ * environments: DopplerEnvironment[];
193
+ * environmentOption?: string;
194
+ * }} params
195
+ * @returns {Promise<string | "all">}
196
+ */
197
+ async function resolveEnvironment(params) {
198
+ const { environments, environmentOption } = params;
199
+ if (environmentOption) {
200
+ const normalized = environmentOption.trim().toLowerCase();
201
+ if (normalized === "all" || normalized === "*") return "all";
202
+ const match = environments.find((env) => env.id.toLowerCase() === normalized || env.name.toLowerCase() === normalized);
203
+ if (!match) throw new Error(`Environment "${environmentOption}" not found. Available: ${environments.map((env) => env.id).join(", ")}`);
204
+ return match.id;
205
+ }
206
+ if (environments.length === 0) return "all";
207
+ const options = [...environments.map((env) => `${env.id} (${env.name})`), "all environments"];
208
+ const index = await promptChoice({
209
+ message: "Choose an environment:",
210
+ options
211
+ });
212
+ if (index === options.length - 1) return "all";
213
+ const chosen = environments[index];
214
+ if (!chosen) throw new Error("No environment selected");
215
+ return chosen.id;
216
+ }
217
+ /**
218
+ * @param {{
219
+ * configs: DopplerConfig[];
220
+ * configOption?: string;
221
+ * environment: string | "all";
222
+ * }} params
223
+ * @returns {Promise<string[]>}
224
+ */
225
+ async function resolveConfigs(params) {
226
+ const { configs, configOption, environment } = params;
227
+ const scoped = environment === "all" ? configs : configs.filter((config) => config.environment === environment);
228
+ if (scoped.length === 0) throw new Error(environment === "all" ? "No configs found in this project." : `No configs found for environment "${environment}".`);
229
+ if (configOption) {
230
+ const normalized = configOption.trim().toLowerCase();
231
+ if (normalized === "all" || normalized === "*") return scoped.map((config) => config.name);
232
+ const requested = configOption.split(",").map((value) => value.trim());
233
+ const names = new Set(scoped.map((config) => config.name));
234
+ const missing = requested.filter((name) => !names.has(name));
235
+ if (missing.length > 0) throw new Error(`Config(s) not found: ${missing.join(", ")}. Available: ${[...names].join(", ")}`);
236
+ return requested;
237
+ }
238
+ if (scoped.length === 1) {
239
+ const only = scoped[0];
240
+ if (!only) throw new Error("No config selected");
241
+ console.log(` Config: ${only.name}`);
242
+ return [only.name];
243
+ }
244
+ const options = [...scoped.map((config) => config.root ? `${config.name} (root, env: ${config.environment})` : `${config.name} (env: ${config.environment})`), `all configs listed (${scoped.length})`];
245
+ const index = await promptChoice({
246
+ message: "Choose a config:",
247
+ options
248
+ });
249
+ if (index === options.length - 1) return scoped.map((config) => config.name);
250
+ const chosen = scoped[index];
251
+ if (!chosen) throw new Error("No config selected");
252
+ return [chosen.name];
253
+ }
254
+ /**
255
+ * @param {string | undefined} nameOption
256
+ * @returns {Promise<string>}
257
+ */
258
+ async function resolveSecretName(nameOption) {
259
+ if (nameOption) return nameOption;
260
+ const raw = await prompt(" Secret name (e.g. DATABASE_URL): ");
261
+ if (!raw) throw new Error("Secret name is required");
262
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(raw)) throw new Error("Secret name must be a valid env var identifier (letters, numbers, underscore)");
263
+ return raw;
264
+ }
265
+ /**
266
+ * @param {string | undefined} valueOption
267
+ * @returns {Promise<string>}
268
+ */
269
+ async function resolveSecretValue(valueOption) {
270
+ if (valueOption !== void 0) return valueOption;
271
+ const raw = await prompt(" Secret value: ");
272
+ if (raw === "") {
273
+ if (!await promptYesNo({
274
+ message: " Set an empty value?",
275
+ defaultYes: false
276
+ })) throw new Error("Secret value is required");
277
+ }
278
+ return raw;
279
+ }
280
+ /**
281
+ * Interactively (or via flags) set a Doppler secret on one or more configs.
282
+ * @param {{
283
+ * project?: string;
284
+ * environment?: string;
285
+ * config?: string;
286
+ * name?: string;
287
+ * value?: string;
288
+ * yes?: boolean;
289
+ * verbose?: boolean;
290
+ * }} options
291
+ */
292
+ async function setSecretInteractive(options) {
293
+ const { project: projectOption, environment: environmentOption, config: configOption, name: nameOption, value: valueOption, yes = false, verbose = false } = options;
294
+ console.log(chalk.blue("\nSet Doppler secret"));
295
+ console.log("");
296
+ const project = await resolveProject({
297
+ projects: listProjects({ verbose }),
298
+ projectOption
299
+ });
300
+ console.log(`Project: ${project}`);
301
+ console.log("");
302
+ const environment = await resolveEnvironment({
303
+ environments: listEnvironments({
304
+ project,
305
+ verbose
306
+ }),
307
+ environmentOption
308
+ });
309
+ console.log(environment === "all" ? "Environment: all" : `Environment: ${environment}`);
310
+ console.log("");
311
+ const targetConfigs = await resolveConfigs({
312
+ configs: listConfigs({
313
+ project,
314
+ environment: environment === "all" ? void 0 : environment,
315
+ verbose
316
+ }),
317
+ configOption,
318
+ environment
319
+ });
320
+ console.log(`Config(s): ${targetConfigs.join(", ")}`);
321
+ console.log("");
322
+ const name = await resolveSecretName(nameOption);
323
+ const value = await resolveSecretValue(valueOption);
324
+ /** @type {{ config: string; existing: string | null }[]} */
325
+ const existingByConfig = [];
326
+ for (const config of targetConfigs) {
327
+ const existing = getSecret({
328
+ project,
329
+ config,
330
+ name,
331
+ verbose
332
+ });
333
+ existingByConfig.push({
334
+ config,
335
+ existing
336
+ });
337
+ }
338
+ const overwrites = existingByConfig.filter((entry) => entry.existing !== null);
339
+ console.log("");
340
+ console.log("Plan:");
341
+ console.log(` Project: ${project}`);
342
+ console.log(` Configs: ${targetConfigs.join(", ")}`);
343
+ console.log(` Name: ${name}`);
344
+ console.log(` Value: ${value.length === 0 ? "(empty)" : `(${value.length} chars)`}`);
345
+ if (overwrites.length > 0) console.log(chalk.yellow(` Overwrite: ${overwrites.length} config(s) already have this secret (${overwrites.map((entry) => entry.config).join(", ")})`));
346
+ else console.log(chalk.green(" Overwrite: none (new secret on all targets)"));
347
+ console.log("");
348
+ if (!yes) {
349
+ if (!await promptYesNo({
350
+ message: overwrites.length > 0 ? "Overwrite / set this secret?" : "Set this secret?",
351
+ defaultYes: false
352
+ })) {
353
+ console.log("Aborted.");
354
+ return;
355
+ }
356
+ console.log("");
357
+ }
358
+ for (const config of targetConfigs) {
359
+ setSecret({
360
+ project,
361
+ config,
362
+ name,
363
+ value,
364
+ verbose
365
+ });
366
+ console.log(chalk.green(` ✓ set ${name} on ${project}/${config}`));
367
+ }
368
+ }
369
+ //#endregion
370
+ export { getSecret, listConfigs, listEnvironments, listProjects, setSecret, setSecretInteractive };
@@ -1,12 +1,100 @@
1
- import {
2
- exec,
3
- execJson,
4
- execNumber,
5
- execString
6
- } from "../../../__chunks/SJXQJ7RS.js";
7
- export {
8
- exec,
9
- execJson,
10
- execNumber,
11
- execString
12
- };
1
+ import chalk from "chalk";
2
+ import { execSync } from "child_process";
3
+ //#region src/commands/doppler/utils/exec.js
4
+ /**
5
+ * @typedef {'silent' | 'verbose' | 'default'} VerbosityLevel
6
+ */
7
+ /**
8
+ * @typedef {Object} ExecOptions
9
+ * @property {'string' | 'number' | 'json'} [stdoutParser='string'] - How to parse stdout
10
+ * @property {boolean} [throwOnError=true] - Whether to throw on error
11
+ * @property {VerbosityLevel} [verbosity='default'] - Output verbosity level
12
+ */
13
+ /**
14
+ * Execute a command and parse the output
15
+ * @param {string} command - Command to execute
16
+ * @param {import('child_process').ExecSyncOptions & ExecOptions} [options={}] - Execution options (inherits all execSync options + custom options)
17
+ * @returns {string | number | any} - Parsed output based on stdoutParser
18
+ */
19
+ function exec(command, options = {}) {
20
+ const { stdoutParser = "string", throwOnError = true, verbosity = "default", stdio: userStdio, ...execSyncOptions } = options;
21
+ try {
22
+ if (verbosity === "verbose") console.log(chalk.gray(` Executing: ${command}`));
23
+ /** @type {import('child_process').StdioOptions} */
24
+ let stdio;
25
+ if (userStdio) stdio = userStdio;
26
+ else if (verbosity === "verbose") stdio = "inherit";
27
+ else if (verbosity === "silent") stdio = "pipe";
28
+ else stdio = [
29
+ "pipe",
30
+ "pipe",
31
+ "pipe"
32
+ ];
33
+ const result = execSync(command, {
34
+ encoding: "utf-8",
35
+ stdio,
36
+ ...execSyncOptions
37
+ });
38
+ if (stdio === "inherit") return stdoutParser === "string" ? "" : void 0;
39
+ if (!result || typeof result === "string" && !result.trim()) return stdoutParser === "string" ? "" : void 0;
40
+ switch (stdoutParser) {
41
+ case "json": try {
42
+ return JSON.parse(result);
43
+ } catch (parseError) {
44
+ if (throwOnError) throw new Error(`Failed to parse JSON output: ${parseError.message}`);
45
+ return;
46
+ }
47
+ case "number": {
48
+ const num = parseFloat(result.trim());
49
+ if (isNaN(num)) {
50
+ if (throwOnError) throw new Error(`Failed to parse number from output: ${result}`);
51
+ return;
52
+ }
53
+ return num;
54
+ }
55
+ default: return result;
56
+ }
57
+ } catch (error) {
58
+ if (!throwOnError) return;
59
+ if (error.stderr) throw new Error(error.stderr.toString());
60
+ throw error;
61
+ }
62
+ }
63
+ /**
64
+ * Execute a command with string output
65
+ * @param {string} command - Command to execute
66
+ * @param {import('child_process').ExecSyncOptions & ExecOptions} [options] - Execution options
67
+ * @returns {string}
68
+ */
69
+ function execString(command, options = {}) {
70
+ return exec(command, {
71
+ ...options,
72
+ stdoutParser: "string"
73
+ });
74
+ }
75
+ /**
76
+ * Execute a command with JSON output
77
+ * @param {string} command - Command to execute
78
+ * @param {import('child_process').ExecSyncOptions & ExecOptions} [options] - Execution options
79
+ * @returns {any}
80
+ */
81
+ function execJson(command, options = {}) {
82
+ return exec(command, {
83
+ ...options,
84
+ stdoutParser: "json"
85
+ });
86
+ }
87
+ /**
88
+ * Execute a command with number output
89
+ * @param {string} command - Command to execute
90
+ * @param {import('child_process').ExecSyncOptions & ExecOptions} [options] - Execution options
91
+ * @returns {number}
92
+ */
93
+ function execNumber(command, options = {}) {
94
+ return exec(command, {
95
+ ...options,
96
+ stdoutParser: "number"
97
+ });
98
+ }
99
+ //#endregion
100
+ export { exec, execJson, execNumber, execString };