@mtndev/cli 1.1.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 (260) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/cjs/__chunks/VH7oDXx4.cjs +28 -0
  3. package/cjs/commands/aws/ec2/allow-ip/handler.cjs +261 -0
  4. package/cjs/commands/aws/ec2/allow-ip/handler.d.ts +6 -0
  5. package/cjs/commands/aws/ec2/allow-ip/index.cjs +25 -0
  6. package/cjs/commands/aws/ec2/allow-ip/index.d.ts +3 -0
  7. package/cjs/commands/aws/ec2/allow-ip/schema.cjs +33 -0
  8. package/cjs/commands/aws/ec2/allow-ip/schema.d.ts +33 -0
  9. package/cjs/commands/aws/ec2/allow-ip/utils.cjs +379 -0
  10. package/cjs/commands/aws/ec2/allow-ip/utils.d.ts +189 -0
  11. package/cjs/commands/aws/iam/admin-group.cjs +111 -0
  12. package/cjs/commands/aws/iam/admin-group.d.ts +55 -0
  13. package/cjs/commands/aws/iam/break-glass/handler.cjs +127 -0
  14. package/cjs/commands/aws/iam/break-glass/handler.d.ts +7 -0
  15. package/cjs/commands/aws/iam/break-glass/index.cjs +7 -0
  16. package/cjs/commands/aws/iam/break-glass/index.d.ts +2 -0
  17. package/cjs/commands/aws/iam/break-glass/schema.cjs +21 -0
  18. package/cjs/commands/aws/iam/break-glass/schema.d.ts +25 -0
  19. package/cjs/commands/aws/iam/check-admin/handler.cjs +89 -0
  20. package/cjs/commands/aws/iam/check-admin/handler.d.ts +5 -0
  21. package/cjs/commands/aws/iam/check-admin/index.cjs +7 -0
  22. package/cjs/commands/aws/iam/check-admin/index.d.ts +2 -0
  23. package/cjs/commands/aws/iam/check-admin/schema.cjs +19 -0
  24. package/cjs/commands/aws/iam/check-admin/schema.d.ts +19 -0
  25. package/cjs/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.json +20 -0
  26. package/cjs/commands/aws/iam/policies/sts-federation.json +11 -0
  27. package/cjs/commands/aws/iam/policies/user-admins-deny-list.json +175 -0
  28. package/cjs/commands/aws/iam/policies/user-admins-deny-regions-list.json +41 -0
  29. package/cjs/commands/aws/iam/policies/user-admins-self-service-iam.json +56 -0
  30. package/cjs/commands/aws/iam/policies/user-admins-write-list.json +117 -0
  31. package/cjs/commands/aws/iam/remove-admin/handler.cjs +120 -0
  32. package/cjs/commands/aws/iam/remove-admin/handler.d.ts +6 -0
  33. package/cjs/commands/aws/iam/remove-admin/index.cjs +7 -0
  34. package/cjs/commands/aws/iam/remove-admin/index.d.ts +2 -0
  35. package/cjs/commands/aws/iam/remove-admin/schema.cjs +22 -0
  36. package/cjs/commands/aws/iam/remove-admin/schema.d.ts +28 -0
  37. package/cjs/commands/aws/iam/setup-acl/handler.cjs +227 -0
  38. package/cjs/commands/aws/iam/setup-acl/handler.d.ts +6 -0
  39. package/cjs/commands/aws/iam/setup-acl/index.cjs +13 -0
  40. package/cjs/commands/aws/iam/setup-acl/index.d.ts +3 -0
  41. package/cjs/commands/aws/iam/setup-acl/schema.cjs +19 -0
  42. package/cjs/commands/aws/iam/setup-acl/schema.d.ts +24 -0
  43. package/cjs/commands/aws/iam/setup-acl/utils.cjs +305 -0
  44. package/cjs/commands/aws/iam/setup-acl/utils.d.ts +61 -0
  45. package/cjs/commands/aws/iam/users/handler.cjs +59 -0
  46. package/cjs/commands/aws/iam/users/handler.d.ts +5 -0
  47. package/cjs/commands/aws/iam/users/index.cjs +18 -0
  48. package/cjs/commands/aws/iam/users/index.d.ts +3 -0
  49. package/cjs/commands/aws/iam/users/schema.cjs +17 -0
  50. package/cjs/commands/aws/iam/users/schema.d.ts +18 -0
  51. package/cjs/commands/aws/iam/users/utils.cjs +454 -0
  52. package/cjs/commands/aws/iam/users/utils.d.ts +119 -0
  53. package/cjs/commands/aws/index.cjs +223 -0
  54. package/cjs/commands/aws/index.d.ts +14 -0
  55. package/cjs/commands/aws/route53/add-record/handler.cjs +264 -0
  56. package/cjs/commands/aws/route53/add-record/handler.d.ts +36 -0
  57. package/cjs/commands/aws/route53/add-record/index.cjs +26 -0
  58. package/cjs/commands/aws/route53/add-record/index.d.ts +3 -0
  59. package/cjs/commands/aws/route53/add-record/schema.cjs +43 -0
  60. package/cjs/commands/aws/route53/add-record/schema.d.ts +45 -0
  61. package/cjs/commands/aws/route53/add-record/utils.cjs +404 -0
  62. package/cjs/commands/aws/route53/add-record/utils.d.ts +216 -0
  63. package/cjs/commands/aws/route53/remove-record/handler.cjs +114 -0
  64. package/cjs/commands/aws/route53/remove-record/handler.d.ts +6 -0
  65. package/cjs/commands/aws/route53/remove-record/index.cjs +5 -0
  66. package/cjs/commands/aws/route53/remove-record/index.d.ts +2 -0
  67. package/cjs/commands/aws/route53/remove-record/schema.cjs +22 -0
  68. package/cjs/commands/aws/route53/remove-record/schema.d.ts +30 -0
  69. package/cjs/commands/aws/schema.cjs +19 -0
  70. package/cjs/commands/aws/schema.d.ts +13 -0
  71. package/cjs/commands/aws/ses/send-email/handler.cjs +73 -0
  72. package/cjs/commands/aws/ses/send-email/handler.d.ts +5 -0
  73. package/cjs/commands/aws/ses/send-email/index.cjs +9 -0
  74. package/cjs/commands/aws/ses/send-email/index.d.ts +3 -0
  75. package/cjs/commands/aws/ses/send-email/schema.cjs +24 -0
  76. package/cjs/commands/aws/ses/send-email/schema.d.ts +39 -0
  77. package/cjs/commands/aws/ses/send-email/utils.cjs +87 -0
  78. package/cjs/commands/aws/ses/send-email/utils.d.ts +47 -0
  79. package/cjs/commands/aws/ses/smtp-password.cjs +72 -0
  80. package/cjs/commands/aws/ses/smtp-password.d.ts +21 -0
  81. package/cjs/commands/aws/utils/exec-aws.cjs +145 -0
  82. package/cjs/commands/aws/utils/exec-aws.d.ts +79 -0
  83. package/cjs/commands/aws/utils/resolve-policy-path.cjs +15 -0
  84. package/cjs/commands/aws/utils/resolve-policy-path.d.ts +8 -0
  85. package/cjs/commands/aws/utils/resolve-profile.cjs +93 -0
  86. package/cjs/commands/aws/utils/resolve-profile.d.ts +28 -0
  87. package/cjs/commands/aws/utils/tty.cjs +54 -0
  88. package/cjs/commands/aws/utils/tty.d.ts +24 -0
  89. package/cjs/commands/db/create-readonly-user/handler.cjs +254 -0
  90. package/cjs/commands/db/create-readonly-user/handler.d.ts +5 -0
  91. package/cjs/commands/db/create-readonly-user/index.cjs +18 -0
  92. package/cjs/commands/db/create-readonly-user/index.d.ts +3 -0
  93. package/cjs/commands/db/create-readonly-user/mysql.cjs +102 -0
  94. package/cjs/commands/db/create-readonly-user/mysql.d.ts +33 -0
  95. package/cjs/commands/db/create-readonly-user/postgres.cjs +209 -0
  96. package/cjs/commands/db/create-readonly-user/postgres.d.ts +31 -0
  97. package/cjs/commands/db/create-readonly-user/schema.cjs +39 -0
  98. package/cjs/commands/db/create-readonly-user/schema.d.ts +55 -0
  99. package/cjs/commands/db/create-readonly-user/utils.cjs +160 -0
  100. package/cjs/commands/db/create-readonly-user/utils.d.ts +112 -0
  101. package/cjs/commands/db/index.cjs +46 -0
  102. package/cjs/commands/db/index.d.ts +6 -0
  103. package/cjs/commands/doppler/handler.cjs +95 -9
  104. package/cjs/commands/doppler/index.cjs +33 -41
  105. package/cjs/commands/doppler/index.d.ts +1 -0
  106. package/cjs/commands/doppler/schema.cjs +130 -6
  107. package/cjs/commands/doppler/schema.d.ts +233 -17
  108. package/cjs/commands/doppler/set-secret.cjs +378 -0
  109. package/cjs/commands/doppler/set-secret.d.ts +113 -0
  110. package/cjs/commands/doppler/utils/exec.cjs +106 -12
  111. package/cjs/commands/doppler/utils.cjs +412 -30
  112. package/cjs/commands/doppler/utils.d.ts +32 -8
  113. package/cjs/commands/icons/handler.cjs +82 -8
  114. package/cjs/commands/icons/index.cjs +15 -31
  115. package/cjs/commands/icons/schema.cjs +101 -13
  116. package/cjs/commands/icons/schema.d.ts +1 -1
  117. package/cjs/commands/icons/utils.cjs +131 -13
  118. package/cjs/commands/index.cjs +54 -82
  119. package/cjs/commands/schema.cjs +25 -8
  120. package/cjs/index.cjs +3 -4
  121. package/esm/commands/aws/ec2/allow-ip/handler.d.ts +6 -0
  122. package/esm/commands/aws/ec2/allow-ip/handler.js +258 -0
  123. package/esm/commands/aws/ec2/allow-ip/index.d.ts +3 -0
  124. package/esm/commands/aws/ec2/allow-ip/index.js +4 -0
  125. package/esm/commands/aws/ec2/allow-ip/schema.d.ts +33 -0
  126. package/esm/commands/aws/ec2/allow-ip/schema.js +29 -0
  127. package/esm/commands/aws/ec2/allow-ip/utils.d.ts +189 -0
  128. package/esm/commands/aws/ec2/allow-ip/utils.js +363 -0
  129. package/esm/commands/aws/iam/admin-group.d.ts +55 -0
  130. package/esm/commands/aws/iam/admin-group.js +104 -0
  131. package/esm/commands/aws/iam/break-glass/handler.d.ts +7 -0
  132. package/esm/commands/aws/iam/break-glass/handler.js +124 -0
  133. package/esm/commands/aws/iam/break-glass/index.d.ts +2 -0
  134. package/esm/commands/aws/iam/break-glass/index.js +4 -0
  135. package/esm/commands/aws/iam/break-glass/schema.d.ts +25 -0
  136. package/esm/commands/aws/iam/break-glass/schema.js +19 -0
  137. package/esm/commands/aws/iam/check-admin/handler.d.ts +5 -0
  138. package/esm/commands/aws/iam/check-admin/handler.js +86 -0
  139. package/esm/commands/aws/iam/check-admin/index.d.ts +2 -0
  140. package/esm/commands/aws/iam/check-admin/index.js +4 -0
  141. package/esm/commands/aws/iam/check-admin/schema.d.ts +19 -0
  142. package/esm/commands/aws/iam/check-admin/schema.js +17 -0
  143. package/esm/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.json +20 -0
  144. package/esm/commands/aws/iam/policies/sts-federation.json +11 -0
  145. package/esm/commands/aws/iam/policies/user-admins-deny-list.json +175 -0
  146. package/esm/commands/aws/iam/policies/user-admins-deny-regions-list.json +41 -0
  147. package/esm/commands/aws/iam/policies/user-admins-self-service-iam.json +56 -0
  148. package/esm/commands/aws/iam/policies/user-admins-write-list.json +117 -0
  149. package/esm/commands/aws/iam/remove-admin/handler.d.ts +6 -0
  150. package/esm/commands/aws/iam/remove-admin/handler.js +117 -0
  151. package/esm/commands/aws/iam/remove-admin/index.d.ts +2 -0
  152. package/esm/commands/aws/iam/remove-admin/index.js +4 -0
  153. package/esm/commands/aws/iam/remove-admin/schema.d.ts +28 -0
  154. package/esm/commands/aws/iam/remove-admin/schema.js +20 -0
  155. package/esm/commands/aws/iam/setup-acl/handler.d.ts +6 -0
  156. package/esm/commands/aws/iam/setup-acl/handler.js +224 -0
  157. package/esm/commands/aws/iam/setup-acl/index.d.ts +3 -0
  158. package/esm/commands/aws/iam/setup-acl/index.js +4 -0
  159. package/esm/commands/aws/iam/setup-acl/schema.d.ts +24 -0
  160. package/esm/commands/aws/iam/setup-acl/schema.js +18 -0
  161. package/esm/commands/aws/iam/setup-acl/utils.d.ts +61 -0
  162. package/esm/commands/aws/iam/setup-acl/utils.js +298 -0
  163. package/esm/commands/aws/iam/users/handler.d.ts +5 -0
  164. package/esm/commands/aws/iam/users/handler.js +56 -0
  165. package/esm/commands/aws/iam/users/index.d.ts +3 -0
  166. package/esm/commands/aws/iam/users/index.js +4 -0
  167. package/esm/commands/aws/iam/users/schema.d.ts +18 -0
  168. package/esm/commands/aws/iam/users/schema.js +16 -0
  169. package/esm/commands/aws/iam/users/utils.d.ts +119 -0
  170. package/esm/commands/aws/iam/users/utils.js +440 -0
  171. package/esm/commands/aws/index.d.ts +14 -0
  172. package/esm/commands/aws/index.js +142 -0
  173. package/esm/commands/aws/route53/add-record/handler.d.ts +36 -0
  174. package/esm/commands/aws/route53/add-record/handler.js +258 -0
  175. package/esm/commands/aws/route53/add-record/index.d.ts +3 -0
  176. package/esm/commands/aws/route53/add-record/index.js +4 -0
  177. package/esm/commands/aws/route53/add-record/schema.d.ts +45 -0
  178. package/esm/commands/aws/route53/add-record/schema.js +40 -0
  179. package/esm/commands/aws/route53/add-record/utils.d.ts +216 -0
  180. package/esm/commands/aws/route53/add-record/utils.js +389 -0
  181. package/esm/commands/aws/route53/remove-record/handler.d.ts +6 -0
  182. package/esm/commands/aws/route53/remove-record/handler.js +111 -0
  183. package/esm/commands/aws/route53/remove-record/index.d.ts +2 -0
  184. package/esm/commands/aws/route53/remove-record/index.js +3 -0
  185. package/esm/commands/aws/route53/remove-record/schema.d.ts +30 -0
  186. package/esm/commands/aws/route53/remove-record/schema.js +21 -0
  187. package/esm/commands/aws/schema.d.ts +13 -0
  188. package/esm/commands/aws/schema.js +16 -0
  189. package/esm/commands/aws/ses/send-email/handler.d.ts +5 -0
  190. package/esm/commands/aws/ses/send-email/handler.js +70 -0
  191. package/esm/commands/aws/ses/send-email/index.d.ts +3 -0
  192. package/esm/commands/aws/ses/send-email/index.js +4 -0
  193. package/esm/commands/aws/ses/send-email/schema.d.ts +39 -0
  194. package/esm/commands/aws/ses/send-email/schema.js +23 -0
  195. package/esm/commands/aws/ses/send-email/utils.d.ts +47 -0
  196. package/esm/commands/aws/ses/send-email/utils.js +84 -0
  197. package/esm/commands/aws/ses/smtp-password.d.ts +21 -0
  198. package/esm/commands/aws/ses/smtp-password.js +69 -0
  199. package/esm/commands/aws/utils/exec-aws.d.ts +79 -0
  200. package/esm/commands/aws/utils/exec-aws.js +137 -0
  201. package/esm/commands/aws/utils/resolve-policy-path.d.ts +8 -0
  202. package/esm/commands/aws/utils/resolve-policy-path.js +14 -0
  203. package/esm/commands/aws/utils/resolve-profile.d.ts +28 -0
  204. package/esm/commands/aws/utils/resolve-profile.js +88 -0
  205. package/esm/commands/aws/utils/tty.d.ts +24 -0
  206. package/esm/commands/aws/utils/tty.js +51 -0
  207. package/esm/commands/db/create-readonly-user/handler.d.ts +5 -0
  208. package/esm/commands/db/create-readonly-user/handler.js +251 -0
  209. package/esm/commands/db/create-readonly-user/index.d.ts +3 -0
  210. package/esm/commands/db/create-readonly-user/index.js +4 -0
  211. package/esm/commands/db/create-readonly-user/mysql.d.ts +33 -0
  212. package/esm/commands/db/create-readonly-user/mysql.js +98 -0
  213. package/esm/commands/db/create-readonly-user/postgres.d.ts +31 -0
  214. package/esm/commands/db/create-readonly-user/postgres.js +205 -0
  215. package/esm/commands/db/create-readonly-user/schema.d.ts +55 -0
  216. package/esm/commands/db/create-readonly-user/schema.js +35 -0
  217. package/esm/commands/db/create-readonly-user/utils.d.ts +112 -0
  218. package/esm/commands/db/create-readonly-user/utils.js +151 -0
  219. package/esm/commands/db/index.d.ts +6 -0
  220. package/esm/commands/db/index.js +31 -0
  221. package/esm/commands/doppler/handler.js +92 -9
  222. package/esm/commands/doppler/index.d.ts +1 -0
  223. package/esm/commands/doppler/index.js +6 -41
  224. package/esm/commands/doppler/schema.d.ts +233 -17
  225. package/esm/commands/doppler/schema.js +125 -7
  226. package/esm/commands/doppler/set-secret.d.ts +113 -0
  227. package/esm/commands/doppler/set-secret.js +370 -0
  228. package/esm/commands/doppler/utils/exec.js +100 -12
  229. package/esm/commands/doppler/utils.d.ts +32 -8
  230. package/esm/commands/doppler/utils.js +396 -30
  231. package/esm/commands/icons/handler.js +79 -8
  232. package/esm/commands/icons/index.js +4 -31
  233. package/esm/commands/icons/schema.d.ts +1 -1
  234. package/esm/commands/icons/schema.js +97 -15
  235. package/esm/commands/icons/utils.js +125 -13
  236. package/esm/commands/index.js +49 -78
  237. package/esm/commands/schema.js +22 -7
  238. package/esm/index.js +3 -4
  239. package/package.json +12 -2
  240. package/vitest.config.ts +11 -0
  241. package/cjs/__chunks/4GFJUCSP.cjs +0 -52
  242. package/cjs/__chunks/4SFWHCB3.cjs +0 -133
  243. package/cjs/__chunks/B2KFW7T7.cjs +0 -1
  244. package/cjs/__chunks/EMMC33QA.cjs +0 -401
  245. package/cjs/__chunks/INFOPAHN.cjs +0 -117
  246. package/cjs/__chunks/J36P6UNE.cjs +0 -75
  247. package/cjs/__chunks/NIMXXHJQ.cjs +0 -92
  248. package/cjs/__chunks/NSRFG4DF.cjs +0 -100
  249. package/cjs/__chunks/WNJ3ZYLI.cjs +0 -1
  250. package/cjs/__chunks/ZMDIOZPT.cjs +0 -22
  251. package/esm/__chunks/46HGXFME.js +0 -0
  252. package/esm/__chunks/6G4PXXKF.js +0 -75
  253. package/esm/__chunks/6L5RNR7G.js +0 -100
  254. package/esm/__chunks/FL7AILGH.js +0 -133
  255. package/esm/__chunks/HJSXC6HP.js +0 -117
  256. package/esm/__chunks/O262GK4B.js +0 -401
  257. package/esm/__chunks/O3CCA76Q.js +0 -22
  258. package/esm/__chunks/SJXQJ7RS.js +0 -92
  259. package/esm/__chunks/SNCKIAOR.js +0 -0
  260. package/esm/__chunks/X3R5PSWH.js +0 -52
@@ -0,0 +1,145 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rolldown_runtime = require("../../../__chunks/VH7oDXx4.cjs");
3
+ let chalk = require("chalk");
4
+ chalk = require_rolldown_runtime.__toESM(chalk, 1);
5
+ let child_process = require("child_process");
6
+ //#region src/commands/aws/utils/exec-aws.js
7
+ /**
8
+ * Error raised when the AWS CLI (or aws-vault) exits non-zero.
9
+ * The `code` is the AWS service error code parsed from stderr (e.g. "UnauthorizedOperation").
10
+ */
11
+ var AwsCliError = class extends Error {
12
+ /**
13
+ * @param {string} message
14
+ * @param {string | null} [code]
15
+ */
16
+ constructor(message, code = null) {
17
+ super(message);
18
+ this.name = "AwsCliError";
19
+ this.code = code;
20
+ }
21
+ };
22
+ /**
23
+ * Extract the AWS service error code from a CLI stderr string.
24
+ * AWS prints codes in parentheses, e.g. "...(UnauthorizedOperation) when calling...".
25
+ * @param {string} stderr
26
+ * @returns {string | null}
27
+ */
28
+ function parseAwsErrorCode(stderr) {
29
+ return /\(([A-Za-z.]+)\)/.exec(stderr)?.[1] ?? null;
30
+ }
31
+ /**
32
+ * Verify that the given executables are available on PATH.
33
+ * @param {string[]} commands
34
+ * @throws {Error} If any command is missing
35
+ */
36
+ function requireCommands(commands) {
37
+ const missing = commands.filter((command) => {
38
+ return (0, child_process.spawnSync)("which", [command], { stdio: "pipe" }).status !== 0;
39
+ });
40
+ if (missing.length > 0) throw new Error(`Required command(s) not found on PATH: ${missing.join(", ")}`);
41
+ }
42
+ /**
43
+ * Run an AWS CLI command using a credential profile.
44
+ * Uses an argument array (no shell) so JSON arguments need no escaping.
45
+ * @param {{
46
+ * profile?: string;
47
+ * region?: string;
48
+ * args: string[];
49
+ * expectJson?: boolean;
50
+ * verbose?: boolean;
51
+ * env?: Record<string, string>;
52
+ * }} params
53
+ * @returns {any} Parsed JSON when expectJson is true, otherwise trimmed stdout string
54
+ */
55
+ function runAws(params) {
56
+ const { profile, region, args, expectJson = true, verbose = false, env } = params;
57
+ /** @type {string[]} */
58
+ const finalArgs = [];
59
+ if (profile) finalArgs.push("--profile", profile);
60
+ if (region) finalArgs.push("--region", region);
61
+ finalArgs.push("--no-cli-pager", ...args);
62
+ if (expectJson) finalArgs.push("--output", "json");
63
+ return spawnAws("aws", finalArgs, {
64
+ expectJson,
65
+ verbose,
66
+ env
67
+ });
68
+ }
69
+ /**
70
+ * Run an AWS CLI command through `aws-vault exec` for profiles whose credentials
71
+ * are stored in the OS keychain rather than ~/.aws/credentials.
72
+ * @param {{
73
+ * profile: string;
74
+ * args: string[];
75
+ * duration?: string;
76
+ * expectJson?: boolean;
77
+ * verbose?: boolean;
78
+ * }} params
79
+ * @returns {any}
80
+ */
81
+ function runAwsVault(params) {
82
+ const { profile, args, duration = "15m", expectJson = true, verbose = false } = params;
83
+ /** @type {string[]} */
84
+ const awsArgs = ["--no-cli-pager", ...args];
85
+ if (expectJson) awsArgs.push("--output", "json");
86
+ return spawnAws("aws-vault", [
87
+ "exec",
88
+ profile,
89
+ "--duration",
90
+ duration,
91
+ "--",
92
+ "aws",
93
+ ...awsArgs
94
+ ], {
95
+ expectJson,
96
+ verbose
97
+ });
98
+ }
99
+ /**
100
+ * @param {string} command
101
+ * @param {string[]} args
102
+ * @param {{ expectJson: boolean; verbose: boolean; env?: Record<string, string> }} options
103
+ * @returns {any}
104
+ */
105
+ function spawnAws(command, args, options) {
106
+ const { expectJson, verbose, env } = options;
107
+ if (verbose) console.log(chalk.default.gray(` Executing: ${command} ${args.join(" ")}`));
108
+ const result = (0, child_process.spawnSync)(command, args, {
109
+ encoding: "utf-8",
110
+ env: env ? {
111
+ ...process.env,
112
+ ...env
113
+ } : process.env
114
+ });
115
+ if (result.error) throw new AwsCliError(result.error.message);
116
+ if (result.status !== 0) {
117
+ const stderr = (result.stderr || result.stdout || "").trim();
118
+ throw new AwsCliError(stderr || `Command failed: ${command} ${args.join(" ")}`, parseAwsErrorCode(stderr));
119
+ }
120
+ const stdout = (result.stdout ?? "").trim();
121
+ if (!expectJson) return stdout;
122
+ if (!stdout) return {};
123
+ return JSON.parse(stdout);
124
+ }
125
+ /**
126
+ * Fetch the caller identity for a profile (account id and ARN).
127
+ * @param {{ profile?: string; region?: string; verbose?: boolean }} params
128
+ * @returns {{ Account: string; Arn: string; UserId: string }}
129
+ */
130
+ function getCallerIdentity(params) {
131
+ const { profile, region, verbose } = params;
132
+ return runAws({
133
+ profile,
134
+ region,
135
+ args: ["sts", "get-caller-identity"],
136
+ verbose
137
+ });
138
+ }
139
+ //#endregion
140
+ exports.AwsCliError = AwsCliError;
141
+ exports.getCallerIdentity = getCallerIdentity;
142
+ exports.parseAwsErrorCode = parseAwsErrorCode;
143
+ exports.requireCommands = requireCommands;
144
+ exports.runAws = runAws;
145
+ exports.runAwsVault = runAwsVault;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Extract the AWS service error code from a CLI stderr string.
3
+ * AWS prints codes in parentheses, e.g. "...(UnauthorizedOperation) when calling...".
4
+ * @param {string} stderr
5
+ * @returns {string | null}
6
+ */
7
+ export function parseAwsErrorCode(stderr: string): string | null;
8
+ /**
9
+ * Verify that the given executables are available on PATH.
10
+ * @param {string[]} commands
11
+ * @throws {Error} If any command is missing
12
+ */
13
+ export function requireCommands(commands: string[]): void;
14
+ /**
15
+ * Run an AWS CLI command using a credential profile.
16
+ * Uses an argument array (no shell) so JSON arguments need no escaping.
17
+ * @param {{
18
+ * profile?: string;
19
+ * region?: string;
20
+ * args: string[];
21
+ * expectJson?: boolean;
22
+ * verbose?: boolean;
23
+ * env?: Record<string, string>;
24
+ * }} params
25
+ * @returns {any} Parsed JSON when expectJson is true, otherwise trimmed stdout string
26
+ */
27
+ export function runAws(params: {
28
+ profile?: string;
29
+ region?: string;
30
+ args: string[];
31
+ expectJson?: boolean;
32
+ verbose?: boolean;
33
+ env?: Record<string, string>;
34
+ }): any;
35
+ /**
36
+ * Run an AWS CLI command through `aws-vault exec` for profiles whose credentials
37
+ * are stored in the OS keychain rather than ~/.aws/credentials.
38
+ * @param {{
39
+ * profile: string;
40
+ * args: string[];
41
+ * duration?: string;
42
+ * expectJson?: boolean;
43
+ * verbose?: boolean;
44
+ * }} params
45
+ * @returns {any}
46
+ */
47
+ export function runAwsVault(params: {
48
+ profile: string;
49
+ args: string[];
50
+ duration?: string;
51
+ expectJson?: boolean;
52
+ verbose?: boolean;
53
+ }): any;
54
+ /**
55
+ * Fetch the caller identity for a profile (account id and ARN).
56
+ * @param {{ profile?: string; region?: string; verbose?: boolean }} params
57
+ * @returns {{ Account: string; Arn: string; UserId: string }}
58
+ */
59
+ export function getCallerIdentity(params: {
60
+ profile?: string;
61
+ region?: string;
62
+ verbose?: boolean;
63
+ }): {
64
+ Account: string;
65
+ Arn: string;
66
+ UserId: string;
67
+ };
68
+ /**
69
+ * Error raised when the AWS CLI (or aws-vault) exits non-zero.
70
+ * The `code` is the AWS service error code parsed from stderr (e.g. "UnauthorizedOperation").
71
+ */
72
+ export class AwsCliError extends Error {
73
+ /**
74
+ * @param {string} message
75
+ * @param {string | null} [code]
76
+ */
77
+ constructor(message: string, code?: string | null);
78
+ code: string | null;
79
+ }
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let url = require("url");
3
+ //#region src/commands/aws/utils/resolve-policy-path.js
4
+ /**
5
+ * Resolve the absolute path to a bundled IAM policy document.
6
+ * Policies live alongside the source in `iam/policies/`, and the CLI runs from
7
+ * source, so this path is valid at runtime.
8
+ * @param {string} fileName - Policy JSON file name (e.g. "user-admins-write-list.json")
9
+ * @returns {string}
10
+ */
11
+ function resolvePolicyPath(fileName) {
12
+ return (0, url.fileURLToPath)(new URL(`../iam/policies/${fileName}`, require("url").pathToFileURL(__filename).href));
13
+ }
14
+ //#endregion
15
+ exports.resolvePolicyPath = resolvePolicyPath;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resolve the absolute path to a bundled IAM policy document.
3
+ * Policies live alongside the source in `iam/policies/`, and the CLI runs from
4
+ * source, so this path is valid at runtime.
5
+ * @param {string} fileName - Policy JSON file name (e.g. "user-admins-write-list.json")
6
+ * @returns {string}
7
+ */
8
+ export function resolvePolicyPath(fileName: string): string;
@@ -0,0 +1,93 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rolldown_runtime = require("../../../__chunks/VH7oDXx4.cjs");
3
+ const require_commands_aws_utils_tty = require("./tty.cjs");
4
+ let chalk = require("chalk");
5
+ chalk = require_rolldown_runtime.__toESM(chalk, 1);
6
+ let fs = require("fs");
7
+ let path = require("path");
8
+ let os = require("os");
9
+ //#region src/commands/aws/utils/resolve-profile.js
10
+ /**
11
+ * Above this many matches we ask the user to narrow the filter rather than
12
+ * printing an unusable wall of numbered options.
13
+ */
14
+ const MAX_LISTED = 30;
15
+ /**
16
+ * Read profile names from ~/.aws/config (honoring AWS_CONFIG_FILE).
17
+ * Handles both `[profile NAME]` entries and a bare `[default]` section.
18
+ * @returns {string[]}
19
+ */
20
+ function listConfigProfiles() {
21
+ const configPath = process.env.AWS_CONFIG_FILE ?? (0, path.join)((0, os.homedir)(), ".aws", "config");
22
+ let contents;
23
+ try {
24
+ contents = (0, fs.readFileSync)(configPath, "utf-8");
25
+ } catch {
26
+ return [];
27
+ }
28
+ /** @type {string[]} */
29
+ const profiles = [];
30
+ const profileRe = /^\[profile\s+(.+?)\]$/;
31
+ for (const rawLine of contents.split("\n")) {
32
+ const line = rawLine.trim();
33
+ const match = profileRe.exec(line);
34
+ if (match?.[1]) profiles.push(match[1].trim());
35
+ else if (line === "[default]") profiles.push("default");
36
+ }
37
+ return profiles;
38
+ }
39
+ /**
40
+ * Interactively narrow a profile list by substring, then pick one.
41
+ * A single match auto-selects; too many matches asks the user to narrow.
42
+ * @param {string[]} profiles
43
+ * @returns {Promise<string>}
44
+ */
45
+ async function pickProfileInteractive(profiles) {
46
+ for (;;) {
47
+ const filter = (await require_commands_aws_utils_tty.prompt(chalk.default.cyan("Filter profiles (substring, Enter for all): "))).trim().toLowerCase();
48
+ const matches = filter ? profiles.filter((name) => name.toLowerCase().includes(filter)) : profiles;
49
+ if (matches.length === 0) {
50
+ console.log(chalk.default.yellow(` No profiles match "${filter}". Try again.`));
51
+ continue;
52
+ }
53
+ if (matches.length === 1) {
54
+ const only = matches[0] ?? "";
55
+ console.log(chalk.default.green(` → ${only}`));
56
+ return only;
57
+ }
58
+ if (matches.length > MAX_LISTED) {
59
+ console.log(chalk.default.yellow(` ${matches.length} profiles match — narrow the filter (over ${MAX_LISTED} to list).`));
60
+ continue;
61
+ }
62
+ return matches[await require_commands_aws_utils_tty.promptChoice({
63
+ message: chalk.default.cyan("Select a profile:"),
64
+ options: matches
65
+ })] ?? "";
66
+ }
67
+ }
68
+ /**
69
+ * Resolve the AWS profile for a single-profile command.
70
+ *
71
+ * Precedence: explicit `--profile`, then `AWS_PROFILE`, then — only when stdin
72
+ * is a TTY — an interactive filter-and-pick over `~/.aws/config` profiles.
73
+ * Returns `undefined` when nothing is set and we cannot prompt (non-interactive
74
+ * shell, or no config profiles), leaving each command's existing "no profile"
75
+ * handling in place.
76
+ * @param {{ profile?: string; interactive?: boolean }} params
77
+ * @returns {Promise<string | undefined>}
78
+ */
79
+ async function resolveProfile(params) {
80
+ const explicit = params.profile ?? process.env.AWS_PROFILE;
81
+ if (explicit) return explicit;
82
+ if (!(params.interactive ?? Boolean(process.stdin.isTTY))) return;
83
+ const profiles = listConfigProfiles();
84
+ if (profiles.length === 0) return;
85
+ console.log(chalk.default.yellow("\nNo AWS profile selected (--profile and AWS_PROFILE are unset)."));
86
+ const chosen = await pickProfileInteractive(profiles);
87
+ console.log(chalk.default.gray(`Using profile "${chosen}" for this command.\n`));
88
+ return chosen;
89
+ }
90
+ //#endregion
91
+ exports.listConfigProfiles = listConfigProfiles;
92
+ exports.pickProfileInteractive = pickProfileInteractive;
93
+ exports.resolveProfile = resolveProfile;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Read profile names from ~/.aws/config (honoring AWS_CONFIG_FILE).
3
+ * Handles both `[profile NAME]` entries and a bare `[default]` section.
4
+ * @returns {string[]}
5
+ */
6
+ export function listConfigProfiles(): string[];
7
+ /**
8
+ * Interactively narrow a profile list by substring, then pick one.
9
+ * A single match auto-selects; too many matches asks the user to narrow.
10
+ * @param {string[]} profiles
11
+ * @returns {Promise<string>}
12
+ */
13
+ export function pickProfileInteractive(profiles: string[]): Promise<string>;
14
+ /**
15
+ * Resolve the AWS profile for a single-profile command.
16
+ *
17
+ * Precedence: explicit `--profile`, then `AWS_PROFILE`, then — only when stdin
18
+ * is a TTY — an interactive filter-and-pick over `~/.aws/config` profiles.
19
+ * Returns `undefined` when nothing is set and we cannot prompt (non-interactive
20
+ * shell, or no config profiles), leaving each command's existing "no profile"
21
+ * handling in place.
22
+ * @param {{ profile?: string; interactive?: boolean }} params
23
+ * @returns {Promise<string | undefined>}
24
+ */
25
+ export function resolveProfile(params: {
26
+ profile?: string;
27
+ interactive?: boolean;
28
+ }): Promise<string | undefined>;
@@ -0,0 +1,54 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let readline = require("readline");
3
+ //#region src/commands/aws/utils/tty.js
4
+ /**
5
+ * Prompt for a single line of input.
6
+ * @param {string} message - Prompt text shown to the user
7
+ * @returns {Promise<string>}
8
+ */
9
+ function prompt(message) {
10
+ return new Promise((resolve) => {
11
+ const rl = (0, readline.createInterface)({
12
+ input: process.stdin,
13
+ output: process.stdout
14
+ });
15
+ rl.question(message, (answer) => {
16
+ rl.close();
17
+ resolve(answer.trim());
18
+ });
19
+ });
20
+ }
21
+ /**
22
+ * Prompt the user to pick one option from a numbered list.
23
+ * @param {{ message: string; options: string[] }} params
24
+ * @returns {Promise<number>} Zero-based index of the chosen option
25
+ */
26
+ async function promptChoice(params) {
27
+ const { message, options } = params;
28
+ if (options.length === 0) throw new Error("promptChoice: no options to choose from");
29
+ console.log(message);
30
+ options.forEach((option, index) => {
31
+ console.log(` ${index + 1}. ${option}`);
32
+ });
33
+ for (;;) {
34
+ const raw = await prompt("Enter number: ");
35
+ const choice = Number.parseInt(raw, 10);
36
+ if (Number.isInteger(choice) && choice >= 1 && choice <= options.length) return choice - 1;
37
+ console.log(`Please enter a number between 1 and ${options.length}.`);
38
+ }
39
+ }
40
+ /**
41
+ * Prompt a yes/no question.
42
+ * @param {{ message: string; defaultYes?: boolean }} params
43
+ * @returns {Promise<boolean>}
44
+ */
45
+ async function promptYesNo(params) {
46
+ const { message, defaultYes = false } = params;
47
+ const answer = (await prompt(`${message}${defaultYes ? " [Y/n]: " : " [y/N]: "}`)).toLowerCase();
48
+ if (answer === "") return defaultYes;
49
+ return answer === "y" || answer === "yes";
50
+ }
51
+ //#endregion
52
+ exports.prompt = prompt;
53
+ exports.promptChoice = promptChoice;
54
+ exports.promptYesNo = promptYesNo;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Prompt for a single line of input.
3
+ * @param {string} message - Prompt text shown to the user
4
+ * @returns {Promise<string>}
5
+ */
6
+ export function prompt(message: string): Promise<string>;
7
+ /**
8
+ * Prompt the user to pick one option from a numbered list.
9
+ * @param {{ message: string; options: string[] }} params
10
+ * @returns {Promise<number>} Zero-based index of the chosen option
11
+ */
12
+ export function promptChoice(params: {
13
+ message: string;
14
+ options: string[];
15
+ }): Promise<number>;
16
+ /**
17
+ * Prompt a yes/no question.
18
+ * @param {{ message: string; defaultYes?: boolean }} params
19
+ * @returns {Promise<boolean>}
20
+ */
21
+ export function promptYesNo(params: {
22
+ message: string;
23
+ defaultYes?: boolean;
24
+ }): Promise<boolean>;