@vizamodo/viza-cli 1.4.12 → 1.4.17

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.
@@ -1,6 +1,21 @@
1
1
  import { resolveEnv } from "../../context/env.js";
2
2
  import { resolveHubIntent } from "../../context/hubIntent.js";
3
3
  import { dispatchIntentAndWait } from "../../core/dispatch.js";
4
+ import { showSsoLinkMenu } from "../../ui/sso/awsLoginMenu.js";
5
+ function parseAwsLoginResult(buffer) {
6
+ try {
7
+ const json = JSON.parse(buffer.toString("utf8"));
8
+ if (typeof json?.loginUrl === "string" &&
9
+ typeof json?.shortUrl === "string" &&
10
+ typeof json?.ttlHours === "number") {
11
+ return json;
12
+ }
13
+ throw new Error("invalid_aws_login_result_shape");
14
+ }
15
+ catch (err) {
16
+ throw new Error("failed_to_parse_aws_login_result");
17
+ }
18
+ }
4
19
  /**
5
20
  * Target teams for `viza login aws`.
6
21
  * This is a CLI-only UX constraint for fail-fast validation.
@@ -43,7 +58,7 @@ export async function loginAwsCommand(options) {
43
58
  ]))
44
59
  : TARGET_TEAMS[env];
45
60
  // 5) Dispatch intent (freeze)
46
- await dispatchIntentAndWait({
61
+ const result = await dispatchIntentAndWait({
47
62
  intent,
48
63
  commandType: "viza.aws.login",
49
64
  infraKey: "aws",
@@ -58,6 +73,16 @@ export async function loginAwsCommand(options) {
58
73
  payload: {}
59
74
  }, {
60
75
  status: options.status === true,
61
- log: "show",
76
+ log: "hide",
62
77
  });
78
+ if (!result)
79
+ return;
80
+ if (result.status !== "success") {
81
+ return;
82
+ }
83
+ if (!result.resultBuffer) {
84
+ return;
85
+ }
86
+ const awsResult = parseAwsLoginResult(result.resultBuffer);
87
+ await showSsoLinkMenu(awsResult.loginUrl, awsResult.shortUrl, awsResult.ttlHours);
63
88
  }
@@ -41,7 +41,7 @@ export function showBanner(opts) {
41
41
  const { title, subtitle, color = "cyanBright", runner, meta } = opts;
42
42
  process.stdout.write("\u001b[2J\u001b[3J\u001b[H");
43
43
  const font = opts.env === "prod"
44
- ? "Georgia11"
44
+ ? "Ogre"
45
45
  : opts.env === "dev"
46
46
  ? "Big"
47
47
  : "Standard";
@@ -0,0 +1,38 @@
1
+ import chalk from "chalk";
2
+ import prompts from "prompts";
3
+ import open from "open";
4
+ import clipboardy from "clipboardy";
5
+ /**
6
+ * Hiển thị menu chọn hành động sau khi tạo SSO URL
7
+ * @param ssoUrl - Đường dẫn zero-click AWS login URL
8
+ * @param ttlHours - Thời hạn hiệu lực của link (mặc định 12h)
9
+ */
10
+ export async function showSsoLinkMenu(ssoUrl, shortUrl, ttlHours = 12) {
11
+ console.log(chalk.gray(`\n───────────────────────────────────── ${chalk.magentaBright(`AWS Zero-Click Login`)} ─────────────────────────────────────────────────`));
12
+ console.log(chalk.gray(`✅ Đã tạo liên kết đăng nhập thành công (${chalk.yellow(`hiệu lực:`)} ${chalk.cyanBright(`${ttlHours}`)} giờ)`));
13
+ console.log(chalk.yellow('🔗 Liên kết đăng nhập:'));
14
+ console.log(chalk.whiteBright(`${shortUrl}`));
15
+ console.log(chalk.gray('───────────────────────────────────────────────────────────────────────────────────────────────────────────'));
16
+ // Non-interactive fallback (CI / pipe / limited TTY)
17
+ if (!process.stdin.isTTY) {
18
+ console.log(shortUrl);
19
+ return;
20
+ }
21
+ const { action } = await prompts({
22
+ type: "select",
23
+ name: "action",
24
+ message: "👉 Hãy chọn hành động bạn muốn thực hiện:",
25
+ choices: [
26
+ { title: "🌐 Mở trong trình duyệt", value: "open" },
27
+ { title: "📋 Sao chép liên kết", value: "copy" },
28
+ ],
29
+ });
30
+ if (action === 'open') {
31
+ console.log(chalk.blue('🔍 Đang mở liên kết trong trình duyệt...'));
32
+ await open(ssoUrl);
33
+ }
34
+ else if (action === 'copy') {
35
+ clipboardy.writeSync(ssoUrl);
36
+ console.log(chalk.green('✅ Liên kết đã được sao chép vào clipboard!'));
37
+ }
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/viza-cli",
3
- "version": "1.4.12",
3
+ "version": "1.4.17",
4
4
  "type": "module",
5
5
  "description": "Viza unified command line interface",
6
6
  "bin": {
@@ -19,13 +19,17 @@
19
19
  "@vizamodo/viza-dispatcher": "^1.4.75",
20
20
  "adm-zip": "^0.5.16",
21
21
  "chalk": "^5.6.2",
22
+ "clipboardy": "^5.1.0",
22
23
  "commander": "^14.0.2",
23
- "figlet": "^1.10.0"
24
+ "figlet": "^1.10.0",
25
+ "open": "^11.0.0",
26
+ "prompts": "^2.4.2"
24
27
  },
25
28
  "devDependencies": {
26
29
  "@types/adm-zip": "^0.5.7",
27
30
  "@types/figlet": "^1.7.0",
28
31
  "@types/node": "^25.1.0",
32
+ "@types/prompts": "^2.4.9",
29
33
  "ts-node": "^10.9.2",
30
34
  "typescript": "^5.9.3"
31
35
  }