@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,258 @@
1
+ import { prompt, promptChoice, promptYesNo } from "../../utils/tty.js";
2
+ import { AwsCliError, getCallerIdentity, requireCommands } from "../../utils/exec-aws.js";
3
+ import { resolveProfile } from "../../utils/resolve-profile.js";
4
+ import { RECORD_TYPES, addRecordOptionsSchema } from "./schema.js";
5
+ import { findCnameConflicts, findHostedZone, formatValues, getRecordSetsAtName, hostedZoneLabel, listHostedZones, normalizeRecordValue, planRecordChange, resolveRecordName, upsertResourceRecordSet, withoutTrailingDot } from "./utils.js";
6
+ import chalk from "chalk";
7
+ import { ZodError } from "zod";
8
+ //#region src/commands/aws/route53/add-record/handler.js
9
+ /**
10
+ * Resolve the hosted zone: from --zone, or interactive picker.
11
+ * @param {{
12
+ * profile?: string;
13
+ * zoneOption?: string;
14
+ * verbose: boolean;
15
+ * }} params
16
+ * @returns {Promise<import("./utils.js").HostedZone>}
17
+ */
18
+ async function resolveHostedZone(params) {
19
+ const { profile, zoneOption, verbose } = params;
20
+ const zones = listHostedZones({
21
+ profile,
22
+ verbose
23
+ });
24
+ if (zones.length === 0) throw new Error("No Route53 hosted zones found for this profile.");
25
+ if (zoneOption) {
26
+ const match = findHostedZone({
27
+ zones,
28
+ zoneInput: zoneOption
29
+ });
30
+ if (!match) throw new Error(`No hosted zone matching "${zoneOption}". Available: ${zones.map((z) => withoutTrailingDot(z.name)).join(", ")}`);
31
+ return match;
32
+ }
33
+ const chosen = zones[await promptChoice({
34
+ message: "Choose a hosted zone:",
35
+ options: zones.map((zone) => hostedZoneLabel(zone))
36
+ })];
37
+ if (!chosen) throw new Error("No hosted zone selected");
38
+ return chosen;
39
+ }
40
+ /**
41
+ * Resolve record type from --type or interactive picker.
42
+ * @param {string | undefined} typeOption
43
+ * @returns {Promise<string>}
44
+ */
45
+ async function resolveRecordType(typeOption) {
46
+ if (typeOption) return typeOption.toUpperCase();
47
+ const index = await promptChoice({
48
+ message: "Choose a record type:",
49
+ options: RECORD_TYPES
50
+ });
51
+ const chosen = RECORD_TYPES[index];
52
+ if (!chosen) throw new Error("No record type selected");
53
+ return chosen;
54
+ }
55
+ /**
56
+ * Resolve record name from --name or prompt.
57
+ * @param {{ nameOption?: string; zoneName: string }} params
58
+ * @returns {Promise<string>} FQDN with trailing dot
59
+ */
60
+ async function resolveName(params) {
61
+ const { nameOption, zoneName } = params;
62
+ let input = nameOption;
63
+ if (!input) input = await prompt(`Record name (relative to ${withoutTrailingDot(zoneName)}, or FQDN; @ for apex): `);
64
+ if (!input) throw new Error("Record name is required");
65
+ return resolveRecordName({
66
+ nameInput: input,
67
+ zoneName
68
+ });
69
+ }
70
+ /**
71
+ * Resolve record value from --value or prompt.
72
+ * @param {{ valueOption?: string; type: string }} params
73
+ * @returns {Promise<string>}
74
+ */
75
+ async function resolveValue(params) {
76
+ const { valueOption, type } = params;
77
+ let input = valueOption;
78
+ if (!input) input = await prompt(`Record value${type === "CNAME" ? " (e.g. target.example.com.)" : type === "TXT" ? " (quotes added if omitted)" : ""}: `);
79
+ if (!input) throw new Error("Record value is required");
80
+ return normalizeRecordValue({
81
+ type,
82
+ value: input
83
+ });
84
+ }
85
+ /**
86
+ * When an existing multi-value set is present, ask replace vs append
87
+ * (single-value types default to replace).
88
+ * @param {{
89
+ * existing: import("./utils.js").ResourceRecordSet;
90
+ * type: string;
91
+ * }} params
92
+ * @returns {Promise<"replace" | "append">}
93
+ */
94
+ async function resolveChangeMode(params) {
95
+ const { existing, type } = params;
96
+ if (type === "CNAME" || existing.values.length <= 1) return "replace";
97
+ console.log("");
98
+ console.log(chalk.yellow(`Existing ${type} record has ${existing.values.length} values:${formatValues(existing.values)}`));
99
+ return await promptYesNo({
100
+ message: "Add to the existing values instead of replacing them?",
101
+ defaultYes: false
102
+ }) ? "append" : "replace";
103
+ }
104
+ /**
105
+ * `aws route53 add-record` handler: interactively (or via flags) create or
106
+ * update a Route53 resource record set, showing whether the change adds or
107
+ * overwrites.
108
+ * @param {unknown} options
109
+ */
110
+ async function addRecordCommand(options) {
111
+ try {
112
+ const { profile: profileOption, zone: zoneOption, type: typeOption, name: nameOption, value: valueOption, ttl: ttlOption, yes, dryRun, verbose } = addRecordOptionsSchema.parse(options);
113
+ const profile = await resolveProfile({ profile: profileOption });
114
+ if (!profile) {
115
+ console.error(chalk.red("Error: pass --profile or set AWS_PROFILE."));
116
+ process.exit(1);
117
+ }
118
+ requireCommands(["aws"]);
119
+ const identity = getCallerIdentity({
120
+ profile,
121
+ verbose
122
+ });
123
+ console.log("Caller:");
124
+ console.log(` Account: ${identity.Account}`);
125
+ console.log(` Arn: ${identity.Arn}`);
126
+ console.log("");
127
+ const zone = await resolveHostedZone({
128
+ profile,
129
+ zoneOption,
130
+ verbose
131
+ });
132
+ console.log(`Hosted zone: ${hostedZoneLabel(zone)}`);
133
+ console.log("");
134
+ const type = await resolveRecordType(typeOption);
135
+ const name = await resolveName({
136
+ nameOption,
137
+ zoneName: zone.name
138
+ });
139
+ const value = await resolveValue({
140
+ valueOption,
141
+ type
142
+ });
143
+ const ttl = ttlOption ?? 300;
144
+ console.log("");
145
+ console.log("Proposed record:");
146
+ console.log(` Name: ${withoutTrailingDot(name)}`);
147
+ console.log(` Type: ${type}`);
148
+ console.log(` TTL: ${ttl}`);
149
+ console.log(` Value: ${value}`);
150
+ console.log("");
151
+ const existingSets = getRecordSetsAtName({
152
+ profile,
153
+ hostedZoneId: zone.id,
154
+ name,
155
+ verbose
156
+ });
157
+ const existing = existingSets.find((set) => set.type === type) ?? null;
158
+ const conflicts = findCnameConflicts({
159
+ existingSets,
160
+ type
161
+ });
162
+ if (conflicts.length > 0) {
163
+ console.error(chalk.red(`❌ Conflict: cannot add a ${type} record at ${withoutTrailingDot(name)}.`));
164
+ console.error("");
165
+ console.error(chalk.yellow("Route53 does not allow a CNAME and any other record type to coexist at the same name. Conflicting record(s) already exist:"));
166
+ for (const conflict of conflicts) console.error(` ${conflict.type} ${withoutTrailingDot(conflict.name)}${formatValues(conflict.isAlias ? ["(alias)"] : conflict.values)}`);
167
+ console.error("");
168
+ console.error(chalk.yellow("Remove the conflicting record, then re-create the one you wanted:"));
169
+ const zoneName = withoutTrailingDot(zone.name);
170
+ const displayName = withoutTrailingDot(name);
171
+ const quotedValue = /^[A-Za-z0-9._:@/-]+$/.test(value) ? value : `"${value}"`;
172
+ const ttlFlag = ttl === 300 ? "" : ` --ttl ${ttl}`;
173
+ let step = 1;
174
+ for (const conflict of conflicts) console.error(chalk.cyan(` ${step++}. mtn aws route53 remove-record -z ${zoneName} -t ${conflict.type} -n ${displayName}`));
175
+ console.error(chalk.cyan(` ${step}. mtn aws route53 add-record -z ${zoneName} -t ${type} -n ${displayName} --value ${quotedValue}${ttlFlag}`));
176
+ process.exit(1);
177
+ }
178
+ if (existing?.isAlias) {
179
+ console.log(chalk.yellow("An ALIAS record already exists at this name + type. Continuing will replace it with a standard record set."));
180
+ console.log("");
181
+ } else if (existing) {
182
+ console.log(chalk.yellow(`Existing ${type} record at ${withoutTrailingDot(name)}:${formatValues(existing.values)}`));
183
+ if (existing.ttl !== void 0) console.log(` TTL: ${existing.ttl}`);
184
+ console.log("");
185
+ } else {
186
+ console.log(chalk.green(`No existing ${type} record at ${withoutTrailingDot(name)}.`));
187
+ console.log("");
188
+ }
189
+ /** @type {"replace" | "append"} */
190
+ let mode = "replace";
191
+ if (existing && !existing.isAlias && existing.values.length > 0) mode = await resolveChangeMode({
192
+ existing,
193
+ type
194
+ });
195
+ const plan = planRecordChange({
196
+ existing,
197
+ newValue: value,
198
+ mode
199
+ });
200
+ console.log(plan.summary);
201
+ console.log("");
202
+ if (plan.action === "noop") return;
203
+ if (plan.action === "overwrite" || plan.action === "append") {
204
+ console.log("Final values that will be written:");
205
+ for (const finalValue of plan.finalValues) console.log(` - ${finalValue}`);
206
+ console.log("");
207
+ }
208
+ if (dryRun) {
209
+ console.log(chalk.cyan("Dry run — no changes made."));
210
+ return;
211
+ }
212
+ if (!yes) {
213
+ if (!await promptYesNo({
214
+ message: plan.action === "create" ? "Create this record?" : plan.action === "append" ? "Add this value to the existing record?" : "Overwrite the existing record?",
215
+ defaultYes: false
216
+ })) {
217
+ console.log("Aborted.");
218
+ return;
219
+ }
220
+ }
221
+ const changeInfo = upsertResourceRecordSet({
222
+ profile,
223
+ hostedZoneId: zone.id,
224
+ name,
225
+ type,
226
+ ttl: existing?.ttl ?? ttl,
227
+ values: plan.finalValues,
228
+ verbose
229
+ });
230
+ console.log("");
231
+ console.log(chalk.green(`Done. ${plan.action === "create" ? "Created" : plan.action === "append" ? "Updated (appended)" : "Updated (overwrote)"} ${type} ${withoutTrailingDot(name)}.`));
232
+ if (changeInfo?.Id) {
233
+ console.log(` Change ID: ${changeInfo.Id}`);
234
+ console.log(` Status: ${changeInfo.Status ?? "PENDING"}`);
235
+ }
236
+ } catch (error) {
237
+ if (error instanceof ZodError) {
238
+ console.error(chalk.red("\n❌ Invalid command options:"));
239
+ error.errors.forEach((err) => {
240
+ console.error(chalk.red(` ${err.path.join(".")}: ${err.message}`));
241
+ });
242
+ process.exit(1);
243
+ }
244
+ const verbose = options?.verbose || false;
245
+ console.error(chalk.red("\n❌ add-record failed:"));
246
+ if (error instanceof AwsCliError || error instanceof Error) {
247
+ console.error(chalk.red(` ${error.message}`));
248
+ if (verbose && error.stack) {
249
+ console.error(chalk.gray("\nStack trace:"));
250
+ console.error(chalk.gray(error.stack));
251
+ }
252
+ } else console.error(chalk.red(` ${String(error)}`));
253
+ console.error(chalk.yellow("\n💡 Use --verbose for detailed error information\n"));
254
+ process.exit(1);
255
+ }
256
+ }
257
+ //#endregion
258
+ export { addRecordCommand, resolveHostedZone, resolveName, resolveRecordType };
@@ -0,0 +1,3 @@
1
+ export * from "./handler.js";
2
+ export * from "./schema.js";
3
+ export * from "./utils.js";
@@ -0,0 +1,4 @@
1
+ import { DEFAULT_TTL, RECORD_TYPES, addRecordOptionsSchema } from "./schema.js";
2
+ import { bareHostedZoneId, deleteResourceRecordSet, findCnameConflicts, findHostedZone, formatValues, getRecordSetsAtName, getResourceRecordSet, hostedZoneLabel, listHostedZones, normalizeRecordValue, planRecordChange, resolveRecordName, upsertResourceRecordSet, withTrailingDot, withoutTrailingDot } from "./utils.js";
3
+ import { addRecordCommand, resolveHostedZone, resolveName, resolveRecordType } from "./handler.js";
4
+ export { DEFAULT_TTL, RECORD_TYPES, addRecordCommand, addRecordOptionsSchema, bareHostedZoneId, deleteResourceRecordSet, findCnameConflicts, findHostedZone, formatValues, getRecordSetsAtName, getResourceRecordSet, hostedZoneLabel, listHostedZones, normalizeRecordValue, planRecordChange, resolveHostedZone, resolveName, resolveRecordName, resolveRecordType, upsertResourceRecordSet, withTrailingDot, withoutTrailingDot };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Common Route53 record types offered in the interactive picker.
3
+ * Alias records are not supported by this command.
4
+ */
5
+ export const RECORD_TYPES: string[];
6
+ /**
7
+ * Default TTL (seconds) when creating or replacing a record set.
8
+ */
9
+ export const DEFAULT_TTL: 300;
10
+ /**
11
+ * Zod schema for `aws route53 add-record` options.
12
+ */
13
+ export const addRecordOptionsSchema: z.ZodObject<{
14
+ profile: z.ZodOptional<z.ZodString>;
15
+ zone: z.ZodOptional<z.ZodString>;
16
+ type: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>, string | undefined, string | undefined>;
17
+ name: z.ZodOptional<z.ZodString>;
18
+ value: z.ZodOptional<z.ZodString>;
19
+ ttl: z.ZodOptional<z.ZodNumber>;
20
+ yes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
21
+ dryRun: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
22
+ verbose: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ verbose: boolean;
25
+ yes: boolean;
26
+ dryRun: boolean;
27
+ profile?: string | undefined;
28
+ value?: string | undefined;
29
+ type?: string | undefined;
30
+ name?: string | undefined;
31
+ zone?: string | undefined;
32
+ ttl?: number | undefined;
33
+ }, {
34
+ profile?: string | undefined;
35
+ verbose?: boolean | undefined;
36
+ yes?: boolean | undefined;
37
+ value?: string | undefined;
38
+ type?: string | undefined;
39
+ dryRun?: boolean | undefined;
40
+ name?: string | undefined;
41
+ zone?: string | undefined;
42
+ ttl?: number | undefined;
43
+ }>;
44
+ export type AddRecordOptions = z.infer<typeof addRecordOptionsSchema>;
45
+ import { z } from "zod";
@@ -0,0 +1,40 @@
1
+ import { profileField, verboseField } from "../../schema.js";
2
+ import { z } from "zod";
3
+ //#region src/commands/aws/route53/add-record/schema.js
4
+ /**
5
+ * Common Route53 record types offered in the interactive picker.
6
+ * Alias records are not supported by this command.
7
+ */
8
+ const RECORD_TYPES = [
9
+ "A",
10
+ "AAAA",
11
+ "CNAME",
12
+ "TXT",
13
+ "MX",
14
+ "NS",
15
+ "SRV",
16
+ "CAA"
17
+ ];
18
+ /**
19
+ * Default TTL (seconds) when creating or replacing a record set.
20
+ */
21
+ const DEFAULT_TTL = 300;
22
+ /**
23
+ * Zod schema for `aws route53 add-record` options.
24
+ */
25
+ const addRecordOptionsSchema = z.object({
26
+ profile: profileField,
27
+ zone: z.string().optional().describe("Hosted zone name or ID (e.g. mountaindev.com or Z123…). Skips the zone picker when set."),
28
+ type: z.string().optional().transform((value) => value === void 0 ? void 0 : value.toUpperCase()).refine((value) => value === void 0 || typeof value === "string" && RECORD_TYPES.includes(value), { message: `Record type must be one of: ${RECORD_TYPES.join(", ")}` }).describe(`DNS record type (${RECORD_TYPES.join(", ")})`),
29
+ name: z.string().optional().describe("Record name relative to the zone (e.g. \"redline\") or a fully-qualified name"),
30
+ value: z.string().optional().describe("Record value (e.g. a CNAME target or A address)"),
31
+ ttl: z.number().int().positive().optional().describe(`TTL in seconds (default: 300)`),
32
+ yes: z.boolean().optional().default(false).describe("Skip the confirmation prompt"),
33
+ dryRun: z.boolean().optional().default(false).describe("Preview the change without calling Route53"),
34
+ verbose: verboseField
35
+ });
36
+ /**
37
+ * @typedef {z.infer<typeof addRecordOptionsSchema>} AddRecordOptions
38
+ */
39
+ //#endregion
40
+ export { DEFAULT_TTL, RECORD_TYPES, addRecordOptionsSchema };
@@ -0,0 +1,216 @@
1
+ /**
2
+ * @typedef {Object} HostedZone
3
+ * @property {string} id - Bare hosted zone ID (without /hostedzone/ prefix)
4
+ * @property {string} name - Zone name with trailing dot (e.g. mountaindev.com.)
5
+ * @property {boolean} privateZone
6
+ * @property {number} recordCount
7
+ */
8
+ /**
9
+ * @typedef {Object} ResourceRecordSet
10
+ * @property {string} name
11
+ * @property {string} type
12
+ * @property {number | undefined} ttl
13
+ * @property {string[]} values
14
+ * @property {boolean} isAlias
15
+ * @property {any} [aliasTarget] - Raw AliasTarget block (present when isAlias)
16
+ */
17
+ /**
18
+ * Strip the `/hostedzone/` prefix from a Route53 hosted zone Id.
19
+ * @param {string} rawId
20
+ * @returns {string}
21
+ */
22
+ export function bareHostedZoneId(rawId: string): string;
23
+ /**
24
+ * Ensure a DNS name ends with a trailing dot (Route53 FQDN form).
25
+ * @param {string} name
26
+ * @returns {string}
27
+ */
28
+ export function withTrailingDot(name: string): string;
29
+ /**
30
+ * Strip a trailing dot for display.
31
+ * @param {string} name
32
+ * @returns {string}
33
+ */
34
+ export function withoutTrailingDot(name: string): string;
35
+ /**
36
+ * List hosted zones for the profile.
37
+ * @param {{ profile?: string; verbose?: boolean }} params
38
+ * @returns {HostedZone[]}
39
+ */
40
+ export function listHostedZones(params: {
41
+ profile?: string;
42
+ verbose?: boolean;
43
+ }): HostedZone[];
44
+ /**
45
+ * Resolve a hosted zone from a name (mountaindev.com) or bare/prefixed ID.
46
+ * @param {{ zones: HostedZone[]; zoneInput: string }} params
47
+ * @returns {HostedZone | null}
48
+ */
49
+ export function findHostedZone(params: {
50
+ zones: HostedZone[];
51
+ zoneInput: string;
52
+ }): HostedZone | null;
53
+ /**
54
+ * Build a display label for a hosted zone in the picker.
55
+ * @param {HostedZone} zone
56
+ * @returns {string}
57
+ */
58
+ export function hostedZoneLabel(zone: HostedZone): string;
59
+ /**
60
+ * Turn a relative or absolute name into a Route53 FQDN under the zone.
61
+ * Apex / "@" / empty → the zone apex.
62
+ * @param {{ nameInput: string; zoneName: string }} params
63
+ * @returns {string} FQDN with trailing dot
64
+ */
65
+ export function resolveRecordName(params: {
66
+ nameInput: string;
67
+ zoneName: string;
68
+ }): string;
69
+ /**
70
+ * Fetch every resource record set at an exact name, across all types.
71
+ * Paginates when needed; Route53 list is ordered by name then type.
72
+ * @param {{
73
+ * profile?: string;
74
+ * hostedZoneId: string;
75
+ * name: string;
76
+ * verbose?: boolean;
77
+ * }} params
78
+ * @returns {ResourceRecordSet[]}
79
+ */
80
+ export function getRecordSetsAtName(params: {
81
+ profile?: string;
82
+ hostedZoneId: string;
83
+ name: string;
84
+ verbose?: boolean;
85
+ }): ResourceRecordSet[];
86
+ /**
87
+ * Fetch a single resource record set by exact name + type, if it exists.
88
+ * @param {{
89
+ * profile?: string;
90
+ * hostedZoneId: string;
91
+ * name: string;
92
+ * type: string;
93
+ * verbose?: boolean;
94
+ * }} params
95
+ * @returns {ResourceRecordSet | null}
96
+ */
97
+ export function getResourceRecordSet(params: {
98
+ profile?: string;
99
+ hostedZoneId: string;
100
+ name: string;
101
+ type: string;
102
+ verbose?: boolean;
103
+ }): ResourceRecordSet | null;
104
+ /**
105
+ * Route53 forbids a CNAME from coexisting with any other record type at the
106
+ * same name. Given the type about to be written and the record sets already at
107
+ * that name, return the sets that would conflict (empty when there is none).
108
+ * A same-type set is an overwrite, not a conflict.
109
+ * @param {{ existingSets: ResourceRecordSet[]; type: string }} params
110
+ * @returns {ResourceRecordSet[]}
111
+ */
112
+ export function findCnameConflicts(params: {
113
+ existingSets: ResourceRecordSet[];
114
+ type: string;
115
+ }): ResourceRecordSet[];
116
+ /**
117
+ * Format existing values for console display.
118
+ * @param {string[]} values
119
+ * @returns {string}
120
+ */
121
+ export function formatValues(values: string[]): string;
122
+ /**
123
+ * Normalize a single record value for a given type (trailing dots, TXT quotes).
124
+ * @param {{ type: string; value: string }} params
125
+ * @returns {string}
126
+ */
127
+ export function normalizeRecordValue(params: {
128
+ type: string;
129
+ value: string;
130
+ }): string;
131
+ /**
132
+ * Decide how the new value relates to an existing RRSet.
133
+ * @param {{
134
+ * existing: ResourceRecordSet | null;
135
+ * newValue: string;
136
+ * mode?: "replace" | "append";
137
+ * }} params
138
+ * @returns {{
139
+ * action: "create" | "overwrite" | "append" | "noop";
140
+ * finalValues: string[];
141
+ * summary: string;
142
+ * }}
143
+ */
144
+ export function planRecordChange(params: {
145
+ existing: ResourceRecordSet | null;
146
+ newValue: string;
147
+ mode?: "replace" | "append";
148
+ }): {
149
+ action: "create" | "overwrite" | "append" | "noop";
150
+ finalValues: string[];
151
+ summary: string;
152
+ };
153
+ /**
154
+ * Submit a Route53 UPSERT for a simple (non-alias) resource record set.
155
+ * @param {{
156
+ * profile?: string;
157
+ * hostedZoneId: string;
158
+ * name: string;
159
+ * type: string;
160
+ * ttl: number;
161
+ * values: string[];
162
+ * verbose?: boolean;
163
+ * }} params
164
+ * @returns {any} ChangeInfo from Route53
165
+ */
166
+ export function upsertResourceRecordSet(params: {
167
+ profile?: string;
168
+ hostedZoneId: string;
169
+ name: string;
170
+ type: string;
171
+ ttl: number;
172
+ values: string[];
173
+ verbose?: boolean;
174
+ }): any;
175
+ /**
176
+ * Submit a Route53 DELETE for an existing resource record set. Route53 requires
177
+ * the record's exact current definition, so this is driven by the record set
178
+ * returned from {@link getResourceRecordSet} — alias records reuse their
179
+ * AliasTarget; standard records reuse their TTL + values.
180
+ * @param {{
181
+ * profile?: string;
182
+ * hostedZoneId: string;
183
+ * record: ResourceRecordSet;
184
+ * verbose?: boolean;
185
+ * }} params
186
+ * @returns {any} ChangeInfo from Route53
187
+ */
188
+ export function deleteResourceRecordSet(params: {
189
+ profile?: string;
190
+ hostedZoneId: string;
191
+ record: ResourceRecordSet;
192
+ verbose?: boolean;
193
+ }): any;
194
+ export type HostedZone = {
195
+ /**
196
+ * - Bare hosted zone ID (without /hostedzone/ prefix)
197
+ */
198
+ id: string;
199
+ /**
200
+ * - Zone name with trailing dot (e.g. mountaindev.com.)
201
+ */
202
+ name: string;
203
+ privateZone: boolean;
204
+ recordCount: number;
205
+ };
206
+ export type ResourceRecordSet = {
207
+ name: string;
208
+ type: string;
209
+ ttl: number | undefined;
210
+ values: string[];
211
+ isAlias: boolean;
212
+ /**
213
+ * - Raw AliasTarget block (present when isAlias)
214
+ */
215
+ aliasTarget?: any;
216
+ };