e2sm 0.4.2 → 0.5.0

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 (3) hide show
  1. package/README.md +10 -0
  2. package/dist/index.mjs +199 -34
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -10,6 +10,16 @@ npx e2sm --dry-run
10
10
  npx e2sm --help
11
11
  ```
12
12
 
13
+ ### Get Secrets
14
+
15
+ Retrieve secrets from AWS Secrets Manager.
16
+
17
+ ```bash
18
+ npx e2sm get
19
+ npx e2sm get -n my-secret-name
20
+ npx e2sm get -p my-profile -r ap-northeast-1
21
+ ```
22
+
13
23
  ## Configuration
14
24
 
15
25
  You can create a `.e2smrc.json` file to set default options.
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { inspect, stripVTControlCharacters } from "node:util";
2
+ import { stripVTControlCharacters } from "node:util";
3
3
  import y, { stdin, stdout } from "node:process";
4
4
  import * as g from "node:readline";
5
5
  import O from "node:readline";
6
6
  import { Writable } from "node:stream";
7
- import { spawn } from "node:child_process";
8
7
  import { access, readFile } from "node:fs/promises";
8
+ import { spawn } from "node:child_process";
9
9
 
10
10
  //#region rolldown:runtime
11
11
  var __create = Object.create;
@@ -446,9 +446,9 @@ const B = {
446
446
  ["escape", "cancel"]
447
447
  ])
448
448
  };
449
- function $(e$1, u$1) {
449
+ function $$1(e$1, u$1) {
450
450
  if (typeof e$1 == "string") return B.aliases.get(e$1) === u$1;
451
- for (const t of e$1) if (t !== void 0 && $(t, u$1)) return !0;
451
+ for (const t of e$1) if (t !== void 0 && $$1(t, u$1)) return !0;
452
452
  return !1;
453
453
  }
454
454
  function BD(e$1, u$1) {
@@ -476,7 +476,7 @@ function fD({ input: e$1 = stdin, output: u$1 = stdout, overwrite: t = !0, hideC
476
476
  });
477
477
  g.emitKeypressEvents(e$1, s), e$1.isTTY && e$1.setRawMode(!0);
478
478
  const i = (D$1, { name: C$1, sequence: n }) => {
479
- if ($([
479
+ if ($$1([
480
480
  String(D$1),
481
481
  C$1,
482
482
  n
@@ -562,7 +562,7 @@ var x$1 = class {
562
562
  }
563
563
  this.state !== "error" && (this.state = "submit");
564
564
  }
565
- $([
565
+ $$1([
566
566
  u$1,
567
567
  t?.name,
568
568
  t?.sequence
@@ -823,9 +823,9 @@ const V = ce(), u = (t, n) => V ? t : n, le = u("◆", "*"), L = u("■", "x"),
823
823
  const { cursor: n, options: r$1, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
824
824
  let l$1 = 0;
825
825
  n >= l$1 + a - 3 ? l$1 = Math.max(Math.min(n - a + 3, r$1.length - a), 0) : n < l$1 + 2 && (l$1 = Math.max(n - 2, 0));
826
- const $$1 = a < r$1.length && l$1 > 0, g$1 = a < r$1.length && l$1 + a < r$1.length;
826
+ const $$2 = a < r$1.length && l$1 > 0, g$1 = a < r$1.length && l$1 + a < r$1.length;
827
827
  return r$1.slice(l$1, l$1 + a).map((p$1, v$1, f) => {
828
- const j = v$1 === 0 && $$1, E = v$1 === f.length - 1 && g$1;
828
+ const j = v$1 === 0 && $$2, E = v$1 === f.length - 1 && g$1;
829
829
  return j || E ? import_picocolors.default.dim("...") : i(p$1, v$1 + l$1 === n);
830
830
  });
831
831
  }, he = (t) => new RD({
@@ -1002,7 +1002,7 @@ ${import_picocolors.default.cyan(d)}
1002
1002
  }).prompt();
1003
1003
  }, be = (t) => {
1004
1004
  const { selectableGroups: n = !0 } = t, r$1 = (i, s, c = []) => {
1005
- const a = i.label ?? String(i.value), l$1 = typeof i.group == "string", $$1 = l$1 && (c[c.indexOf(i) + 1] ?? { group: !0 }), g$1 = l$1 && $$1.group === !0, p$1 = l$1 ? n ? `${g$1 ? d : o} ` : " " : "";
1005
+ const a = i.label ?? String(i.value), l$1 = typeof i.group == "string", $$2 = l$1 && (c[c.indexOf(i) + 1] ?? { group: !0 }), g$1 = l$1 && $$2.group === !0, p$1 = l$1 ? n ? `${g$1 ? d : o} ` : " " : "";
1006
1006
  if (s === "active") return `${import_picocolors.default.dim(p$1)}${import_picocolors.default.cyan(A)} ${a} ${i.hint ? import_picocolors.default.dim(`(${i.hint})`) : ""}`;
1007
1007
  if (s === "group-active") return `${p$1}${import_picocolors.default.cyan(A)} ${import_picocolors.default.dim(a)}`;
1008
1008
  if (s === "group-active-selected") return `${p$1}${import_picocolors.default.green(T)} ${import_picocolors.default.dim(a)}`;
@@ -1042,16 +1042,16 @@ ${import_picocolors.default.gray(o)}` : ""}`;
1042
1042
  `).map((c, a) => a === 0 ? `${import_picocolors.default.yellow(d)} ${import_picocolors.default.yellow(c)}` : ` ${c}`).join(`
1043
1043
  `);
1044
1044
  return `${i}${import_picocolors.default.yellow(o)} ${this.options.map((c, a, l$1) => {
1045
- const $$1 = this.value.includes(c.value) || c.group === !0 && this.isGroupSelected(`${c.value}`), g$1 = a === this.cursor;
1046
- return !g$1 && typeof c.group == "string" && this.options[this.cursor].value === c.group ? r$1(c, $$1 ? "group-active-selected" : "group-active", l$1) : g$1 && $$1 ? r$1(c, "active-selected", l$1) : $$1 ? r$1(c, "selected", l$1) : r$1(c, g$1 ? "active" : "inactive", l$1);
1045
+ const $$2 = this.value.includes(c.value) || c.group === !0 && this.isGroupSelected(`${c.value}`), g$1 = a === this.cursor;
1046
+ return !g$1 && typeof c.group == "string" && this.options[this.cursor].value === c.group ? r$1(c, $$2 ? "group-active-selected" : "group-active", l$1) : g$1 && $$2 ? r$1(c, "active-selected", l$1) : $$2 ? r$1(c, "selected", l$1) : r$1(c, g$1 ? "active" : "inactive", l$1);
1047
1047
  }).join(`
1048
1048
  ${import_picocolors.default.yellow(o)} `)}
1049
1049
  ${s}
1050
1050
  `;
1051
1051
  }
1052
1052
  default: return `${i}${import_picocolors.default.cyan(o)} ${this.options.map((s, c, a) => {
1053
- const l$1 = this.value.includes(s.value) || s.group === !0 && this.isGroupSelected(`${s.value}`), $$1 = c === this.cursor;
1054
- return !$$1 && typeof s.group == "string" && this.options[this.cursor].value === s.group ? r$1(s, l$1 ? "group-active-selected" : "group-active", a) : $$1 && l$1 ? r$1(s, "active-selected", a) : l$1 ? r$1(s, "selected", a) : r$1(s, $$1 ? "active" : "inactive", a);
1053
+ const l$1 = this.value.includes(s.value) || s.group === !0 && this.isGroupSelected(`${s.value}`), $$2 = c === this.cursor;
1054
+ return !$$2 && typeof s.group == "string" && this.options[this.cursor].value === s.group ? r$1(s, l$1 ? "group-active-selected" : "group-active", a) : $$2 && l$1 ? r$1(s, "active-selected", a) : l$1 ? r$1(s, "selected", a) : r$1(s, $$2 ? "active" : "inactive", a);
1055
1055
  }).join(`
1056
1056
  ${import_picocolors.default.cyan(o)} `)}
1057
1057
  ${import_picocolors.default.cyan(d)}
@@ -1064,8 +1064,8 @@ ${import_picocolors.default.cyan(d)}
1064
1064
  ${t}
1065
1065
  `.split(`
1066
1066
  `), i = stripVTControlCharacters(n).length, s = Math.max(r$1.reduce((a, l$1) => {
1067
- const $$1 = stripVTControlCharacters(l$1);
1068
- return $$1.length > a ? $$1.length : a;
1067
+ const $$2 = stripVTControlCharacters(l$1);
1068
+ return $$2.length > a ? $$2.length : a;
1069
1069
  }, 0), i) + 2, c = r$1.map((a) => `${import_picocolors.default.gray(o)} ${import_picocolors.default.dim(a)}${" ".repeat(s - stripVTControlCharacters(a).length)}${import_picocolors.default.gray(o)}`).join(`
1070
1070
  `);
1071
1071
  process.stdout.write(`${import_picocolors.default.gray(o)}
@@ -1150,7 +1150,7 @@ ${J}${i.trimStart()}`), r$1 = 3 + stripVTControlCharacters(i.trimStart()).length
1150
1150
  "O",
1151
1151
  "0"
1152
1152
  ], r$1 = V ? 80 : 120, i = process.env.CI === "true";
1153
- let s, c, a = !1, l$1 = "", $$1, g$1 = performance.now();
1153
+ let s, c, a = !1, l$1 = "", $$2, g$1 = performance.now();
1154
1154
  const p$1 = (m$1) => {
1155
1155
  a && N$1(m$1 > 1 ? "Something went wrong" : "Canceled", m$1);
1156
1156
  }, v$1 = () => p$1(2), f = () => p$1(1), j = () => {
@@ -1158,10 +1158,10 @@ ${J}${i.trimStart()}`), r$1 = 3 + stripVTControlCharacters(i.trimStart()).length
1158
1158
  }, E = () => {
1159
1159
  process.removeListener("uncaughtExceptionMonitor", v$1), process.removeListener("unhandledRejection", v$1), process.removeListener("SIGINT", f), process.removeListener("SIGTERM", f), process.removeListener("exit", p$1);
1160
1160
  }, B$1 = () => {
1161
- if ($$1 === void 0) return;
1161
+ if ($$2 === void 0) return;
1162
1162
  i && process.stdout.write(`
1163
1163
  `);
1164
- const m$1 = $$1.split(`
1164
+ const m$1 = $$2.split(`
1165
1165
  `);
1166
1166
  process.stdout.write(import_src.cursor.move(-999, m$1.length - 1)), process.stdout.write(import_src.erase.down(m$1.length));
1167
1167
  }, R$1 = (m$1) => m$1.replace(/\.+$/, ""), O$1 = (m$1) => {
@@ -1172,8 +1172,8 @@ ${J}${i.trimStart()}`), r$1 = 3 + stripVTControlCharacters(i.trimStart()).length
1172
1172
  `);
1173
1173
  let h$1 = 0, w$1 = 0;
1174
1174
  j(), c = setInterval(() => {
1175
- if (i && l$1 === $$1) return;
1176
- B$1(), $$1 = l$1;
1175
+ if (i && l$1 === $$2) return;
1176
+ B$1(), $$2 = l$1;
1177
1177
  const I$1 = import_picocolors.default.magenta(n[h$1]);
1178
1178
  if (i) process.stdout.write(`${I$1} ${l$1}...`);
1179
1179
  else if (t === "timer") process.stdout.write(`${I$1} ${l$1} ${O$1(g$1)}`);
@@ -3013,7 +3013,50 @@ BUILT_IN_PREFIX.codePointAt(0);
3013
3013
 
3014
3014
  //#endregion
3015
3015
  //#region package.json
3016
- var version = "0.4.2";
3016
+ var version = "0.5.0";
3017
+
3018
+ //#endregion
3019
+ //#region node_modules/kleur/colors.mjs
3020
+ let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
3021
+ if (typeof process !== "undefined") {
3022
+ ({FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM} = process.env || {});
3023
+ isTTY = process.stdout && process.stdout.isTTY;
3024
+ }
3025
+ const $ = { enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY) };
3026
+ function init(x$2, y$2) {
3027
+ let rgx = new RegExp(`\\x1b\\[${y$2}m`, "g");
3028
+ let open = `\x1b[${x$2}m`, close = `\x1b[${y$2}m`;
3029
+ return function(txt) {
3030
+ if (!$.enabled || txt == null) return txt;
3031
+ return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
3032
+ };
3033
+ }
3034
+ const reset = init(0, 0);
3035
+ const bold = init(1, 22);
3036
+ const dim = init(2, 22);
3037
+ const italic = init(3, 23);
3038
+ const underline = init(4, 24);
3039
+ const inverse = init(7, 27);
3040
+ const hidden = init(8, 28);
3041
+ const strikethrough = init(9, 29);
3042
+ const black = init(30, 39);
3043
+ const red = init(31, 39);
3044
+ const green = init(32, 39);
3045
+ const yellow = init(33, 39);
3046
+ const blue = init(34, 39);
3047
+ const magenta = init(35, 39);
3048
+ const cyan = init(36, 39);
3049
+ const white = init(37, 39);
3050
+ const gray = init(90, 39);
3051
+ const grey = init(90, 39);
3052
+ const bgBlack = init(40, 49);
3053
+ const bgRed = init(41, 49);
3054
+ const bgGreen = init(42, 49);
3055
+ const bgYellow = init(43, 49);
3056
+ const bgBlue = init(44, 49);
3057
+ const bgMagenta = init(45, 49);
3058
+ const bgCyan = init(46, 49);
3059
+ const bgWhite = init(47, 49);
3017
3060
 
3018
3061
  //#endregion
3019
3062
  //#region src/lib.ts
@@ -3102,15 +3145,9 @@ function mergeWithConfig(cliValues, config) {
3102
3145
  ...Object.fromEntries(Object.entries(cliValues).filter(([, v$1]) => v$1 !== void 0))
3103
3146
  };
3104
3147
  }
3105
-
3106
- //#endregion
3107
- //#region src/index.ts
3108
- function isCancel(value) {
3109
- return pD(value);
3110
- }
3111
- function exec(command, args) {
3148
+ function exec(command$1, args) {
3112
3149
  return new Promise((resolve) => {
3113
- const proc = spawn(command, args, {
3150
+ const proc = spawn(command$1, args, {
3114
3151
  shell: false,
3115
3152
  stdio: [
3116
3153
  "pipe",
@@ -3135,6 +3172,133 @@ function exec(command, args) {
3135
3172
  });
3136
3173
  });
3137
3174
  }
3175
+ function formatJson(obj, indent = 0) {
3176
+ const spaces = " ".repeat(indent);
3177
+ if (obj === null) return gray("null");
3178
+ if (typeof obj === "string") return green(`"${obj}"`);
3179
+ if (typeof obj === "number" || typeof obj === "boolean" || typeof obj === "bigint") return String(obj);
3180
+ if (typeof obj === "undefined") return gray("undefined");
3181
+ if (typeof obj === "symbol") return gray(obj.toString());
3182
+ if (typeof obj === "function") return gray("[Function]");
3183
+ if (Array.isArray(obj)) {
3184
+ if (obj.length === 0) return dim("[]");
3185
+ const items$1 = obj.map((item) => `${spaces} ${formatJson(item, indent + 1)}`);
3186
+ return `${dim("[")}\n${items$1.join(`${dim(",")}\n`)}\n${spaces}${dim("]")}`;
3187
+ }
3188
+ const entries = Object.entries(obj);
3189
+ if (entries.length === 0) return dim("{}");
3190
+ const items = entries.map(([key, value]) => `${spaces} ${cyan(`"${key}"`)}${dim(":")} ${formatJson(value, indent + 1)}`);
3191
+ return `${dim("{")}\n${items.join(`${dim(",")}\n`)}\n${spaces}${dim("}")}`;
3192
+ }
3193
+
3194
+ //#endregion
3195
+ //#region src/get.ts
3196
+ function isCancel$1(value) {
3197
+ return pD(value);
3198
+ }
3199
+ const getCommand = define({
3200
+ name: "get",
3201
+ description: "Get secret value from AWS Secrets Manager",
3202
+ args: {
3203
+ profile: {
3204
+ type: "string",
3205
+ short: "p",
3206
+ description: "AWS profile to use"
3207
+ },
3208
+ region: {
3209
+ type: "string",
3210
+ short: "r",
3211
+ description: "AWS region to use (e.g., ap-northeast-1)"
3212
+ },
3213
+ name: {
3214
+ type: "string",
3215
+ short: "n",
3216
+ description: "Secret name to retrieve (skip interactive selection)"
3217
+ }
3218
+ },
3219
+ run: async (ctx) => {
3220
+ const config = await loadConfig();
3221
+ const unknownFlagError = validateUnknownFlags(ctx.tokens, ctx.args);
3222
+ if (unknownFlagError) {
3223
+ console.error(unknownFlagError);
3224
+ process.exit(1);
3225
+ }
3226
+ const merged = mergeWithConfig(ctx.values, config);
3227
+ const profile = merged.profile;
3228
+ const region = merged.region;
3229
+ const nameFlag = ctx.values.name;
3230
+ Ie(`e2sm get v${version} - Get secret from AWS Secrets Manager`);
3231
+ const profileArgs = profile ? ["--profile", profile] : [];
3232
+ const regionArgs = region ? ["--region", region] : [];
3233
+ let secretName;
3234
+ if (nameFlag) secretName = nameFlag;
3235
+ else {
3236
+ const spinner$1 = Y();
3237
+ spinner$1.start("Fetching secret list...");
3238
+ const listResult = await exec("aws", [
3239
+ "secretsmanager",
3240
+ "list-secrets",
3241
+ ...profileArgs,
3242
+ ...regionArgs
3243
+ ]);
3244
+ if (listResult.exitCode !== 0) {
3245
+ spinner$1.stop("Failed to fetch secret list");
3246
+ xe(`Error: ${listResult.stderr}`);
3247
+ process.exit(1);
3248
+ }
3249
+ spinner$1.stop("Secret list fetched");
3250
+ const secrets = JSON.parse(listResult.stdout).SecretList;
3251
+ if (secrets.length === 0) {
3252
+ xe("No secrets found");
3253
+ process.exit(1);
3254
+ }
3255
+ const selected = await ve({
3256
+ message: "Select a secret:",
3257
+ options: secrets.map((s) => ({
3258
+ value: s.Name,
3259
+ label: s.Name
3260
+ }))
3261
+ });
3262
+ if (isCancel$1(selected)) {
3263
+ xe("Operation cancelled");
3264
+ process.exit(0);
3265
+ }
3266
+ secretName = selected;
3267
+ }
3268
+ const spinner = Y();
3269
+ spinner.start(`Fetching secret value for '${secretName}'...`);
3270
+ const getResult = await exec("aws", [
3271
+ "secretsmanager",
3272
+ "get-secret-value",
3273
+ "--secret-id",
3274
+ secretName,
3275
+ ...profileArgs,
3276
+ ...regionArgs
3277
+ ]);
3278
+ if (getResult.exitCode !== 0) {
3279
+ spinner.stop("Failed to fetch secret value");
3280
+ xe(`Error: ${getResult.stderr}`);
3281
+ process.exit(1);
3282
+ }
3283
+ spinner.stop("Secret value fetched");
3284
+ const secretString = JSON.parse(getResult.stdout).SecretString;
3285
+ M.info(`Secret: ${secretName}`);
3286
+ console.log();
3287
+ try {
3288
+ const parsed = JSON.parse(secretString);
3289
+ console.log(formatJson(parsed));
3290
+ } catch {
3291
+ console.log(secretString);
3292
+ }
3293
+ Se("Done");
3294
+ }
3295
+ });
3296
+
3297
+ //#endregion
3298
+ //#region src/index.ts
3299
+ function isCancel(value) {
3300
+ return pD(value);
3301
+ }
3138
3302
  const command = define({
3139
3303
  name: "e2sm",
3140
3304
  description: "Upload .env file to AWS Secrets Manager",
@@ -3226,10 +3390,7 @@ const command = define({
3226
3390
  const jsonString = JSON.stringify(envData);
3227
3391
  if (isDryRun) {
3228
3392
  M.info("Dry-run mode: Previewing JSON output");
3229
- console.log(inspect(envData, {
3230
- colors: true,
3231
- depth: null
3232
- }));
3393
+ console.log(formatJson(envData));
3233
3394
  Se("Dry-run complete");
3234
3395
  return;
3235
3396
  }
@@ -3334,7 +3495,11 @@ const command = define({
3334
3495
  Se(`Secret '${secretName}' has been saved to AWS Secrets Manager`);
3335
3496
  }
3336
3497
  });
3337
- await cli(process.argv.slice(2), command, { version });
3498
+ await cli(process.argv.slice(2), command, {
3499
+ version,
3500
+ fallbackToEntry: true,
3501
+ subCommands: { get: getCommand }
3502
+ });
3338
3503
 
3339
3504
  //#endregion
3340
3505
  export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "e2sm",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "author": "mfyuu",
6
6
  "repository": {
@@ -41,6 +41,7 @@
41
41
  "@gunshi/docs": "0.27.5",
42
42
  "@types/bun": "latest",
43
43
  "gunshi": "0.27.5",
44
+ "kleur": "^4.1.5",
44
45
  "lefthook": "^2.0.15",
45
46
  "oxfmt": "^0.26.0",
46
47
  "oxlint": "^1.41.0",