@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,538 +0,0 @@
1
- import {
2
- exec
3
- } from "./SJXQJ7RS.js";
4
-
5
- // src/commands/doppler/utils.js
6
- import { execSync } from "child_process";
7
- import {
8
- copyFileSync,
9
- existsSync,
10
- readFileSync,
11
- renameSync,
12
- unlinkSync,
13
- writeFileSync
14
- } from "fs";
15
- import { tmpdir } from "os";
16
- import { join } from "path";
17
- import { createInterface } from "readline";
18
- import chalk from "chalk";
19
- var DEFAULT_DOPPLER_ENVIRONMENT = "dev";
20
- var DOPPLER_INTERNAL_KEYS = /* @__PURE__ */ new Set([
21
- "DOPPLER_CONFIG",
22
- "DOPPLER_ENVIRONMENT",
23
- "DOPPLER_PROJECT"
24
- ]);
25
- function execDoppler(args, parser = "string", silent = false, verbose = false) {
26
- const command = `doppler ${args.join(" ")}`;
27
- let verbosity = "default";
28
- if (verbose) {
29
- verbosity = "verbose";
30
- } else if (silent) {
31
- verbosity = "silent";
32
- }
33
- return exec(command, {
34
- verbosity,
35
- stdoutParser: parser,
36
- throwOnError: true
37
- });
38
- }
39
- function checkDopplerAuth(verbose = false) {
40
- if (verbose) {
41
- console.log(chalk.blue("\n\u{1F50D} Checking Doppler authentication..."));
42
- }
43
- try {
44
- execSync("which doppler", { stdio: "pipe" });
45
- if (verbose) {
46
- console.log(chalk.green(" \u2713 Doppler CLI is installed"));
47
- }
48
- } catch {
49
- throw new Error(
50
- "Doppler is not installed. Please install Doppler (brew install dopplerhq/cli/doppler), login, and try again."
51
- );
52
- }
53
- try {
54
- execDoppler(["me"], "string", true, verbose);
55
- if (verbose) {
56
- console.log(chalk.green(" \u2713 Doppler is authenticated"));
57
- }
58
- } catch {
59
- throw new Error(
60
- "Doppler is not logged in. Please run 'doppler login' and try again."
61
- );
62
- }
63
- }
64
- function checkDependencies(verbose = false) {
65
- checkDopplerAuth(verbose);
66
- if (verbose) {
67
- console.log(chalk.blue("\n\u{1F50D} Checking Doppler project setup..."));
68
- }
69
- try {
70
- execDoppler(["configs", "--json"], "json", true, verbose);
71
- if (verbose) {
72
- console.log(chalk.green(" \u2713 Doppler project is configured"));
73
- }
74
- } catch {
75
- throw new Error(
76
- "Doppler is not configured. Please run 'doppler setup' and try again."
77
- );
78
- }
79
- }
80
- function getConfigs(environments, verbose = false, project = null) {
81
- if (verbose) {
82
- console.log(
83
- chalk.blue(
84
- `
85
- \u{1F4CB} Resolving configurations for environments: ${chalk.cyan(environments)}`
86
- )
87
- );
88
- }
89
- const configArgs = ["configs", "--json"];
90
- if (project) configArgs.push("--project", project);
91
- const availableConfigs = execDoppler(configArgs, "json", true, verbose);
92
- const configNames = Array.isArray(availableConfigs) ? availableConfigs.map(
93
- (config) => config.name
94
- ) : [];
95
- if (verbose && configNames.length > 0) {
96
- console.log(
97
- chalk.gray(` Available configurations: ${configNames.join(", ")}`)
98
- );
99
- }
100
- if (environments === "all") {
101
- if (configNames.length === 0) {
102
- throw new Error("No configurations found in Doppler");
103
- }
104
- if (verbose) {
105
- console.log(
106
- chalk.green(` \u2713 Using all ${configNames.length} configurations`)
107
- );
108
- }
109
- return configNames;
110
- }
111
- const requested = environments.split(",").map((e) => e.trim());
112
- if (configNames.length > 0) {
113
- const missing = requested.filter((e) => !configNames.includes(e));
114
- if (missing.length > 0) {
115
- throw new Error(
116
- `Configurations not found: ${missing.join(", ")}. Available: ${configNames.join(", ")}`
117
- );
118
- }
119
- }
120
- if (verbose) {
121
- console.log(
122
- chalk.green(` \u2713 Using configurations: ${requested.join(", ")}`)
123
- );
124
- }
125
- return requested;
126
- }
127
- function normalizeEscapeSequences(content) {
128
- return content.replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\r/g, "\r");
129
- }
130
- function createDiff(oldContent, newContent) {
131
- const oldLines = oldContent.split("\n");
132
- const newLines = newContent.split("\n");
133
- const diff = [];
134
- const maxLines = Math.max(oldLines.length, newLines.length);
135
- for (let i = 0; i < maxLines; i++) {
136
- const oldLine = oldLines[i] || "";
137
- const newLine = newLines[i] || "";
138
- if (oldLine !== newLine) {
139
- if (oldLine && !newLine) {
140
- diff.push(`-${oldLine}`);
141
- } else if (!oldLine && newLine) {
142
- diff.push(`+${newLine}`);
143
- } else {
144
- diff.push(`-${oldLine}`);
145
- diff.push(`+${newLine}`);
146
- }
147
- }
148
- }
149
- return diff;
150
- }
151
- function promptConfirmation(message) {
152
- return new Promise((resolve) => {
153
- const rl = createInterface({
154
- input: process.stdin,
155
- output: process.stdout
156
- });
157
- rl.question(message, (answer) => {
158
- rl.close();
159
- resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
160
- });
161
- });
162
- }
163
- async function downloadConfigs(options) {
164
- const { environments, verbose } = options;
165
- const actualEnvironments = environments ?? DEFAULT_DOPPLER_ENVIRONMENT;
166
- const configs = getConfigs(actualEnvironments, verbose);
167
- if (verbose) {
168
- console.log(
169
- chalk.blue(
170
- `
171
- \u2B07\uFE0F Starting download process for ${configs.length} configuration(s)...`
172
- )
173
- );
174
- }
175
- if (configs.length === 1 && actualEnvironments !== "all") {
176
- console.log(
177
- "You can use -e all to download all configurations, or -e dev,stg for specific environments."
178
- );
179
- }
180
- for (const config of configs) {
181
- const envFile = `.env.${config}`;
182
- const backupFile = `${envFile}.backup`;
183
- let backupMsg = "";
184
- if (verbose) {
185
- console.log(chalk.blue(`
186
- \u{1F4E6} Processing config: ${chalk.cyan(config)}`));
187
- }
188
- try {
189
- if (existsSync(envFile)) {
190
- if (verbose) {
191
- console.log(chalk.gray(` Creating backup: ${backupFile}`));
192
- }
193
- renameSync(envFile, backupFile);
194
- backupMsg = "Backed up existing file, ";
195
- }
196
- if (verbose) {
197
- console.log(chalk.gray(` Downloading secrets from Doppler...`));
198
- }
199
- const content = execDoppler(
200
- [
201
- "secrets",
202
- "download",
203
- "--no-file",
204
- "--format",
205
- "env",
206
- "--config",
207
- config
208
- ],
209
- "string",
210
- !verbose,
211
- // Only silent if not verbose
212
- verbose
213
- );
214
- if (typeof content === "string") {
215
- writeFileSync(envFile, content, "utf-8");
216
- if (verbose) {
217
- console.log(chalk.gray(` Written to: ${envFile}`));
218
- }
219
- } else {
220
- throw new Error("Invalid content received from Doppler");
221
- }
222
- console.log(
223
- `Config ${chalk.blue(config)}: ${backupMsg}downloaded successfully to ${chalk.green(envFile)}`
224
- );
225
- if (config === "dev" && !existsSync(".env")) {
226
- copyFileSync(envFile, ".env");
227
- console.log(
228
- `Copied ${chalk.green(".env.dev")} to ${chalk.green(".env")}`
229
- );
230
- }
231
- if (existsSync(backupFile)) {
232
- if (verbose) {
233
- console.log(chalk.gray(` Removing backup file`));
234
- }
235
- unlinkSync(backupFile);
236
- }
237
- } catch (error) {
238
- console.error(`Failed to download ${config}: ${error?.message || error}`);
239
- if (existsSync(backupFile)) {
240
- renameSync(backupFile, envFile);
241
- console.log(`Restored backup for ${envFile}`);
242
- }
243
- }
244
- }
245
- }
246
- async function uploadConfigs(options) {
247
- const { environments, verbose } = options;
248
- const configs = getConfigs(environments, verbose);
249
- if (verbose) {
250
- console.log(
251
- chalk.blue(
252
- `
253
- \u2B06\uFE0F Starting upload process for ${configs.length} configuration(s)...`
254
- )
255
- );
256
- }
257
- for (const config of configs) {
258
- const envFile = `.env.${config}`;
259
- const backupFile = `${envFile}.doppler`;
260
- const normalizedFile = `${envFile}.normalized`;
261
- if (verbose) {
262
- console.log(chalk.blue(`
263
- \u{1F4E6} Processing config: ${chalk.cyan(config)}`));
264
- }
265
- try {
266
- if (!existsSync(envFile)) {
267
- console.log(
268
- `Config ${config}: ${chalk.green(envFile)} does not exist. Skipping upload.`
269
- );
270
- continue;
271
- }
272
- if (verbose) {
273
- console.log(
274
- chalk.gray(` Creating backup of current Doppler config...`)
275
- );
276
- }
277
- try {
278
- const backupContent2 = execDoppler(
279
- [
280
- "secrets",
281
- "download",
282
- "--no-file",
283
- "--format",
284
- "env",
285
- "--config",
286
- config
287
- ],
288
- "string",
289
- !verbose,
290
- // Only silent if not verbose
291
- verbose
292
- );
293
- if (typeof backupContent2 === "string") {
294
- writeFileSync(backupFile, backupContent2, "utf-8");
295
- if (verbose) {
296
- console.log(chalk.gray(` Backup created: ${backupFile}`));
297
- }
298
- } else {
299
- throw new Error("Invalid backup content received from Doppler");
300
- }
301
- } catch {
302
- console.log(
303
- `Config ${config}: Failed to create backup. Skipping upload.`
304
- );
305
- continue;
306
- }
307
- if (verbose) {
308
- console.log(chalk.gray(` Reading local file: ${envFile}`));
309
- }
310
- const localContent = readFileSync(envFile, "utf-8");
311
- const normalizedContent = normalizeEscapeSequences(localContent);
312
- writeFileSync(normalizedFile, normalizedContent, "utf-8");
313
- if (verbose) {
314
- console.log(chalk.gray(` Comparing local changes with Doppler...`));
315
- }
316
- const backupContent = readFileSync(backupFile, "utf-8");
317
- const diff = createDiff(backupContent, normalizedContent);
318
- if (diff.length === 0) {
319
- console.log(`Config ${config}: No differences found. Skipping upload.`);
320
- unlinkSync(backupFile);
321
- unlinkSync(normalizedFile);
322
- continue;
323
- }
324
- if (verbose) {
325
- console.log(chalk.yellow(` Found ${diff.length} line changes`));
326
- }
327
- console.log("\nChanges to be uploaded:");
328
- for (const line of diff) {
329
- if (line.startsWith("-")) {
330
- console.log(chalk.red(line));
331
- } else if (line.startsWith("+")) {
332
- console.log(chalk.green(line));
333
- }
334
- }
335
- const confirmed = await promptConfirmation(
336
- "\nDo you want to proceed with the upload? (y/n) "
337
- );
338
- if (!confirmed) {
339
- console.log(`Upload cancelled for ${chalk.green(envFile)}`);
340
- unlinkSync(backupFile);
341
- unlinkSync(normalizedFile);
342
- continue;
343
- }
344
- if (verbose) {
345
- console.log(chalk.gray(` Uploading to Doppler...`));
346
- }
347
- try {
348
- execDoppler(
349
- ["secrets", "upload", normalizedFile, "--config", config, "--silent"],
350
- "string",
351
- !verbose,
352
- // Only silent if not verbose
353
- verbose
354
- );
355
- if (config === "dev") {
356
- console.log(
357
- `Config ${chalk.blue(config)}: Successfully uploaded ${chalk.green(envFile)}`
358
- );
359
- } else {
360
- console.log(
361
- `Config ${config}: Successfully uploaded ${chalk.green(envFile)}`
362
- );
363
- }
364
- } catch {
365
- console.error(
366
- `Config ${config}: Failed to upload ${chalk.green(envFile)}. Restoring previous configuration.`
367
- );
368
- try {
369
- if (verbose) {
370
- console.log(chalk.gray(` Restoring previous configuration...`));
371
- }
372
- execDoppler(
373
- ["secrets", "upload", backupFile, "--config", config, "--silent"],
374
- "string",
375
- !verbose,
376
- // Only silent if not verbose
377
- verbose
378
- );
379
- console.log(
380
- `Config ${config}: Successfully restored previous configuration`
381
- );
382
- } catch {
383
- console.error(
384
- `Config ${config}: Failed to restore previous configuration`
385
- );
386
- }
387
- }
388
- if (existsSync(backupFile)) {
389
- unlinkSync(backupFile);
390
- }
391
- if (existsSync(normalizedFile)) {
392
- unlinkSync(normalizedFile);
393
- }
394
- } catch (error) {
395
- console.error(
396
- `Error processing config ${config}: ${error?.message || error}`
397
- );
398
- if (existsSync(backupFile)) {
399
- unlinkSync(backupFile);
400
- }
401
- if (existsSync(normalizedFile)) {
402
- unlinkSync(normalizedFile);
403
- }
404
- }
405
- }
406
- }
407
- async function cloneProject({ from, to, environments, force, verbose }) {
408
- if (verbose) {
409
- console.log(
410
- chalk.blue(
411
- `
412
- \u{1F501} Cloning from ${chalk.cyan(from)} to ${chalk.cyan(to)}...`
413
- )
414
- );
415
- }
416
- const configsToClone = getConfigs(environments, verbose, from);
417
- if (configsToClone.length === 0) {
418
- throw new Error(`No configurations found in source project "${from}"`);
419
- }
420
- const targetConfigsRaw = execDoppler(
421
- ["configs", "--json", "--project", to],
422
- "json",
423
- true,
424
- verbose
425
- );
426
- const targetConfigNames = Array.isArray(targetConfigsRaw) ? targetConfigsRaw.map((c) => c.name) : [];
427
- const missingInTarget = configsToClone.filter(
428
- (c) => !targetConfigNames.includes(c)
429
- );
430
- if (missingInTarget.length > 0) {
431
- throw new Error(
432
- `Configs missing in target project "${to}": ${missingInTarget.join(", ")}. Create them in Doppler first.`
433
- );
434
- }
435
- for (const config of configsToClone) {
436
- if (verbose) {
437
- console.log(chalk.blue(`
438
- \u{1F4E6} Processing config: ${chalk.cyan(config)}`));
439
- }
440
- const sourceSecrets = execDoppler(
441
- ["secrets", "--json", "--project", from, "--config", config],
442
- "json",
443
- true,
444
- verbose
445
- );
446
- const sourceKeys = sourceSecrets ? Object.keys(sourceSecrets).filter((k) => !DOPPLER_INTERNAL_KEYS.has(k)) : [];
447
- const targetSecrets = execDoppler(
448
- ["secrets", "--json", "--project", to, "--config", config],
449
- "json",
450
- true,
451
- verbose
452
- );
453
- const targetKeys = targetSecrets ? Object.keys(targetSecrets) : [];
454
- const conflicts = sourceKeys.filter((k) => targetKeys.includes(k));
455
- if (conflicts.length > 0) {
456
- if (process.env["CI"]) {
457
- throw new Error(
458
- `Config "${config}" has ${conflicts.length} conflicting key(s) in target: ${conflicts.join(", ")}`
459
- );
460
- }
461
- if (!force) {
462
- console.log(
463
- `
464
- Config ${chalk.cyan(config)}: ${conflicts.length} key(s) already exist in ${chalk.cyan(to)}:`
465
- );
466
- conflicts.forEach((k) => console.log(chalk.yellow(` \u2022 ${k}`)));
467
- const confirmed = await promptConfirmation(
468
- `
469
- Overwrite these keys in "${to}/${config}"? (y/n) `
470
- );
471
- if (!confirmed) {
472
- console.log(`Skipped ${chalk.blue(config)}`);
473
- continue;
474
- }
475
- }
476
- }
477
- const tmpFile = join(tmpdir(), `doppler-clone-${config}-${Date.now()}.env`);
478
- try {
479
- const content = execDoppler(
480
- [
481
- "secrets",
482
- "download",
483
- "--no-file",
484
- "--format",
485
- "env",
486
- "--project",
487
- from,
488
- "--config",
489
- config
490
- ],
491
- "string",
492
- true,
493
- verbose
494
- );
495
- if (typeof content !== "string" || !content) {
496
- throw new Error(`No secrets returned for config "${config}"`);
497
- }
498
- const filtered = content.split("\n").filter((line) => {
499
- const key = line.split("=")[0] ?? "";
500
- return !DOPPLER_INTERNAL_KEYS.has(key);
501
- }).join("\n");
502
- writeFileSync(tmpFile, filtered, "utf-8");
503
- execDoppler(
504
- [
505
- "secrets",
506
- "upload",
507
- tmpFile,
508
- "--project",
509
- to,
510
- "--config",
511
- config,
512
- "--silent"
513
- ],
514
- "string",
515
- true,
516
- verbose
517
- );
518
- console.log(`Config ${chalk.blue(config)}: cloned to ${chalk.green(to)}`);
519
- } finally {
520
- if (existsSync(tmpFile)) {
521
- unlinkSync(tmpFile);
522
- }
523
- }
524
- }
525
- }
526
-
527
- export {
528
- execDoppler,
529
- checkDopplerAuth,
530
- checkDependencies,
531
- getConfigs,
532
- normalizeEscapeSequences,
533
- createDiff,
534
- promptConfirmation,
535
- downloadConfigs,
536
- uploadConfigs,
537
- cloneProject
538
- };
@@ -1,127 +0,0 @@
1
- import {
2
- setSecretInteractive
3
- } from "./QFXN4EHM.js";
4
- import {
5
- checkDependencies,
6
- checkDopplerAuth,
7
- cloneProject,
8
- downloadConfigs,
9
- uploadConfigs
10
- } from "./YGWTVPZE.js";
11
- import {
12
- dopplerCommandMetadata,
13
- dopplerCommandOptionsSchema
14
- } from "./KWUJP5MG.js";
15
-
16
- // src/commands/doppler/handler.js
17
- import chalk from "chalk";
18
- import { ZodError } from "zod";
19
- async function dopplerCommand(options) {
20
- try {
21
- const rawOptions = (
22
- /** @type {any} */
23
- options ?? {}
24
- );
25
- if (rawOptions.help || !rawOptions.action) {
26
- console.log(
27
- chalk.bold(`
28
- Usage: @mtndev/cli doppler [options] <action>`)
29
- );
30
- console.log(dopplerCommandMetadata.description);
31
- console.log(chalk.bold("\nOptions:"));
32
- Object.entries(dopplerCommandMetadata.options).forEach(
33
- ([key, optionMeta]) => {
34
- const meta = (
35
- /** @type {any} */
36
- optionMeta
37
- );
38
- const alias = meta?.alias ? chalk.cyan(`, -${meta.alias}`) : "";
39
- const defaultValue = meta?.default ?? false;
40
- console.log(
41
- chalk.cyan(` --${key}`) + alias + ` ${meta.description} (default: ${defaultValue})`
42
- );
43
- }
44
- );
45
- console.log("");
46
- return;
47
- }
48
- const validatedOptions = dopplerCommandOptionsSchema.parse(options);
49
- const { action, verbose } = validatedOptions;
50
- if (action === "set") {
51
- checkDopplerAuth(verbose);
52
- } else {
53
- checkDependencies(verbose);
54
- }
55
- if (action === "download") {
56
- const { environments } = validatedOptions;
57
- await downloadConfigs({ environments, verbose });
58
- } else if (action === "upload") {
59
- const { environments } = validatedOptions;
60
- await uploadConfigs({ environments, verbose });
61
- } else if (action === "clone") {
62
- const { from, to, force, environments } = validatedOptions;
63
- await cloneProject({ from, to, environments, force, verbose });
64
- } else if (action === "set") {
65
- const { project, environment, config, name, value, yes } = validatedOptions;
66
- await setSecretInteractive({
67
- project,
68
- environment,
69
- config,
70
- name,
71
- value,
72
- yes,
73
- verbose
74
- });
75
- }
76
- console.log(chalk.green(`
77
- \u2705 Doppler ${action} completed successfully!`));
78
- } catch (error) {
79
- if (error instanceof ZodError) {
80
- console.error(chalk.red(`
81
- \u274C Invalid command options:`));
82
- error.errors.forEach((err) => {
83
- console.error(chalk.red(` ${err.path.join(".")}: ${err.message}`));
84
- });
85
- process.exit(1);
86
- }
87
- const action = (
88
- /** @type {any} */
89
- options?.action || "operation"
90
- );
91
- const verbose = (
92
- /** @type {any} */
93
- options?.verbose || false
94
- );
95
- console.error(chalk.red(`
96
- \u274C Doppler ${action} failed:`));
97
- if (error instanceof Error) {
98
- console.error(chalk.red(` ${error.message}`));
99
- if (verbose && error.stack) {
100
- console.error(chalk.gray("\nStack trace:"));
101
- console.error(chalk.gray(error.stack));
102
- }
103
- } else {
104
- console.error(chalk.red(` ${String(error)}`));
105
- }
106
- console.error(chalk.yellow("\n\u{1F4A1} Troubleshooting tips:"));
107
- console.error(
108
- chalk.yellow(
109
- " \u2022 Ensure Doppler CLI is installed (brew install dopplerhq/cli/doppler)"
110
- )
111
- );
112
- console.error(
113
- chalk.yellow(" \u2022 Make sure you're logged in (doppler login)")
114
- );
115
- console.error(
116
- chalk.yellow(" \u2022 Verify project is configured (doppler setup)")
117
- );
118
- console.error(
119
- chalk.yellow(" \u2022 Use --verbose for detailed error information\n")
120
- );
121
- process.exit(1);
122
- }
123
- }
124
-
125
- export {
126
- dopplerCommand
127
- };
@@ -1,47 +0,0 @@
1
- // src/commands/aws/utils/tty.js
2
- import { createInterface } from "readline";
3
- function prompt(message) {
4
- return new Promise((resolve) => {
5
- const rl = createInterface({
6
- input: process.stdin,
7
- output: process.stdout
8
- });
9
- rl.question(message, (answer) => {
10
- rl.close();
11
- resolve(answer.trim());
12
- });
13
- });
14
- }
15
- async function promptChoice(params) {
16
- const { message, options } = params;
17
- if (options.length === 0) {
18
- throw new Error("promptChoice: no options to choose from");
19
- }
20
- console.log(message);
21
- options.forEach((option, index) => {
22
- console.log(` ${index + 1}. ${option}`);
23
- });
24
- for (; ; ) {
25
- const raw = await prompt("Enter number: ");
26
- const choice = Number.parseInt(raw, 10);
27
- if (Number.isInteger(choice) && choice >= 1 && choice <= options.length) {
28
- return choice - 1;
29
- }
30
- console.log(`Please enter a number between 1 and ${options.length}.`);
31
- }
32
- }
33
- async function promptYesNo(params) {
34
- const { message, defaultYes = false } = params;
35
- const suffix = defaultYes ? " [Y/n]: " : " [y/N]: ";
36
- const answer = (await prompt(`${message}${suffix}`)).toLowerCase();
37
- if (answer === "") {
38
- return defaultYes;
39
- }
40
- return answer === "y" || answer === "yes";
41
- }
42
-
43
- export {
44
- prompt,
45
- promptChoice,
46
- promptYesNo
47
- };