@itd2902/auggw 1.0.6 → 1.0.8

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": "@itd2902/auggw",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "CLI tool for rotating Augment session accounts",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -0,0 +1,8 @@
1
+ const { clearToken } = require("../utils/token");
2
+
3
+ function logoutCommand() {
4
+ clearToken();
5
+ console.log("✅ Logged out. Token removed.");
6
+ }
7
+
8
+ module.exports = logoutCommand;
@@ -34,6 +34,8 @@ async function statusCommand() {
34
34
  console.log(
35
35
  ` ${bar} ${color}${pct}% used${reset}`,
36
36
  );
37
+ } else {
38
+ console.log(` Credit: \x1b[90mN/A — account chưa login trên admin panel\x1b[0m`);
37
39
  }
38
40
  console.log();
39
41
  }
@@ -0,0 +1,33 @@
1
+ const { execSync } = require("child_process");
2
+ const pkg = require("../../package.json");
3
+
4
+ async function updateCommand() {
5
+ console.log(`Current version: ${pkg.version}`);
6
+ console.log("Checking for updates...\n");
7
+
8
+ try {
9
+ const resp = await fetch(`https://registry.npmjs.org/${pkg.name}/latest`, {
10
+ signal: AbortSignal.timeout(5000),
11
+ });
12
+ if (!resp.ok) {
13
+ console.error("❌ Failed to check for updates.");
14
+ process.exit(1);
15
+ }
16
+ const data = await resp.json();
17
+
18
+ if (!data.version || data.version === pkg.version) {
19
+ console.log("✅ Already on the latest version.");
20
+ return;
21
+ }
22
+
23
+ console.log(`⬆ Updating: ${pkg.version} → ${data.version}\n`);
24
+ const cmd = `npm i -g ${pkg.name}@latest`;
25
+ execSync(cmd, { stdio: "inherit" });
26
+ console.log(`\n✅ Updated to ${data.version}`);
27
+ } catch (err) {
28
+ console.error(`❌ Update failed: ${err.message}`);
29
+ process.exit(1);
30
+ }
31
+ }
32
+
33
+ module.exports = updateCommand;
package/src/index.js CHANGED
@@ -1,20 +1,29 @@
1
1
  const { Command } = require('commander');
2
2
  const loginCommand = require('./commands/login');
3
+ const logoutCommand = require('./commands/logout');
3
4
  const switchCommand = require('./commands/switch');
4
5
  const statusCommand = require('./commands/status');
6
+ const updateCommand = require('./commands/update');
7
+ const { checkUpdate } = require('./utils/update');
8
+ const pkg = require('../package.json');
5
9
 
6
10
  const program = new Command();
7
11
 
8
12
  program
9
- .name('auggw')
13
+ .name(Object.keys(pkg.bin)[0] || 'auggw')
10
14
  .description('CLI tool for rotating Augment session accounts')
11
- .version('1.0.0');
15
+ .version(pkg.version);
12
16
 
13
17
  program
14
18
  .command('login')
15
19
  .description('Authenticate with the session rotator backend')
16
20
  .action(loginCommand);
17
21
 
22
+ program
23
+ .command('logout')
24
+ .description('Remove saved token and log out')
25
+ .action(logoutCommand);
26
+
18
27
  program
19
28
  .command('switch')
20
29
  .description('Switch to the next available Augment session')
@@ -25,5 +34,13 @@ program
25
34
  .description('View current account and pool status')
26
35
  .action(statusCommand);
27
36
 
37
+ program
38
+ .command('update')
39
+ .description('Update CLI to the latest version')
40
+ .action(updateCommand);
41
+
28
42
  program.parse();
29
43
 
44
+ // Non-blocking update check — runs after command finishes
45
+ checkUpdate();
46
+
@@ -0,0 +1,24 @@
1
+ const pkg = require("../../package.json");
2
+
3
+ async function checkUpdate() {
4
+ try {
5
+ const resp = await fetch(`https://registry.npmjs.org/${pkg.name}/latest`, {
6
+ signal: AbortSignal.timeout(3000),
7
+ });
8
+ if (!resp.ok) return;
9
+ const data = await resp.json();
10
+ if (data.version && data.version !== pkg.version) {
11
+ const cmd = pkg.name.startsWith("@")
12
+ ? `npm i -g ${pkg.name}`
13
+ : `npm i -g ${pkg.name}`;
14
+ console.log(
15
+ `\n\x1b[33m⬆ Update available: ${pkg.version} → ${data.version}\x1b[0m`,
16
+ );
17
+ console.log(` Run: \x1b[36m${cmd}\x1b[0m\n`);
18
+ }
19
+ } catch {
20
+ // Silently ignore — no network, timeout, etc.
21
+ }
22
+ }
23
+
24
+ module.exports = { checkUpdate };