@suronai/cli 0.1.39 → 0.1.40

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suronai/cli",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "Suron CLI — secrets delivery",
5
5
  "type": "module",
6
6
  "bin": {
package/src/commands.js CHANGED
@@ -2,7 +2,7 @@ import { Command } from "commander";
2
2
  import { intro, outro, spinner, select, text, isCancel } from "@clack/prompts";
3
3
  import { existsSync, readFileSync, writeFileSync } from "fs";
4
4
  import { join } from "path";
5
- import { exec } from "child_process";
5
+ import { spawn } from "child_process";
6
6
  import ui from "./utils/colors.js";
7
7
  import { getToken, requireToken, saveConfig, clearToken } from "./utils/config.js";
8
8
  import { api, BASE_URL } from "./utils/api.js";
@@ -14,6 +14,33 @@ function cancel(msg) {
14
14
  process.exit(1);
15
15
  }
16
16
 
17
+ function openBrowser(url) {
18
+ const platform = process.platform;
19
+ if (platform === "win32") {
20
+ spawn("cmd", ["/c", "start", "", url], { detached: true, stdio: "ignore" }).unref();
21
+ } else if (platform === "darwin") {
22
+ spawn("open", [url], { detached: true, stdio: "ignore" }).unref();
23
+ } else {
24
+ spawn("xdg-open", [url], { detached: true, stdio: "ignore" }).unref();
25
+ }
26
+ }
27
+
28
+ function waitForEnter(prompt) {
29
+ process.stdout.write(prompt);
30
+ return new Promise(resolve => {
31
+ const handler = (buf) => {
32
+ if (buf.toString().includes("\n")) {
33
+ process.stdin.removeListener("data", handler);
34
+ process.stdin.pause();
35
+ resolve();
36
+ }
37
+ };
38
+ process.stdin.resume();
39
+ process.stdin.setEncoding("utf-8");
40
+ process.stdin.on("data", handler);
41
+ });
42
+ }
43
+
17
44
  export const loginCommand = new Command("login")
18
45
  .description("Authenticate via browser")
19
46
  .option("--force", "Re-authenticate even if already logged in")
@@ -42,12 +69,14 @@ export const loginCommand = new Command("login")
42
69
 
43
70
  const loginUrl = `${BASE_URL}/clilogin?code=${code}`;
44
71
 
45
- console.log(ui.infoBlock("Opening browser to complete login..."));
72
+ console.log(ui.infoBlock("Press Enter to open the login page in your browser..."));
46
73
  console.log(ui.blank());
47
74
  console.log(ui.kv("URL", loginUrl, 6));
48
75
  console.log(ui.blank());
49
76
 
50
- exec(`open "${loginUrl}" 2>/dev/null || xdg-open "${loginUrl}" 2>/dev/null || cmd /c start "" "${loginUrl}" 2>/dev/null`);
77
+ await waitForEnter(" Press Enter to open ");
78
+ openBrowser(loginUrl);
79
+ console.log(ui.blank());
51
80
 
52
81
  const s = spinner();
53
82
  s.start("Waiting for approval");
package/src/utils/api.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import { getToken } from "./config.js";
2
2
 
3
- const BASE_URL = "https://suron.vercel.app";
3
+ const WEB_URL = process.env.SURON_WEB_URL ?? "https://suron.vercel.app";
4
+ const API_URL = `${WEB_URL}/api`;
5
+ const BASE_URL = WEB_URL;
4
6
 
5
7
  export async function api(path, options = {}) {
6
8
  const token = getToken();
7
9
  const headers = { "Content-Type": "application/json", ...options.headers };
8
10
  if (token) headers["Authorization"] = `Bearer ${token}`;
9
11
 
10
- const res = await fetch(`${BASE_URL}${path}`, { ...options, headers });
12
+ const res = await fetch(`${API_URL}${path}`, { ...options, headers });
11
13
 
12
14
  if (!res.ok) {
13
15
  const data = await res.json().catch(() => ({}));