terminalmarket 0.6.3 → 0.6.4

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 (2) hide show
  1. package/bin/tm.js +55 -7
  2. package/package.json +1 -1
package/bin/tm.js CHANGED
@@ -3,17 +3,63 @@
3
3
  import { Command } from "commander";
4
4
  import chalk from "chalk";
5
5
  import open from "open";
6
+ import readline from "readline";
6
7
 
7
8
  import { apiGet, apiPost, apiDelete, apiPatch } from "../src/api.js";
8
9
  import { getApiBase, setApiBase, getUser, setUser, clearUser, clearSession } from "../src/config.js";
9
10
  import { printTable, pickProductFields, pickSellerFields, pickOfferFields, containsQuery, formatStars } from "../src/format.js";
10
11
 
12
+ // Helper for hidden password input
13
+ function askPassword(prompt = "Password: ") {
14
+ return new Promise((resolve) => {
15
+ const rl = readline.createInterface({
16
+ input: process.stdin,
17
+ output: process.stdout,
18
+ });
19
+
20
+ process.stdout.write(prompt);
21
+
22
+ // Mute output
23
+ const stdin = process.stdin;
24
+ const wasRaw = stdin.isRaw;
25
+ if (stdin.isTTY) {
26
+ stdin.setRawMode(true);
27
+ }
28
+
29
+ let password = "";
30
+
31
+ const onData = (char) => {
32
+ const c = char.toString();
33
+
34
+ if (c === "\n" || c === "\r") {
35
+ stdin.removeListener("data", onData);
36
+ if (stdin.isTTY) {
37
+ stdin.setRawMode(wasRaw);
38
+ }
39
+ rl.close();
40
+ console.log(); // New line
41
+ resolve(password);
42
+ } else if (c === "\u0003") {
43
+ // Ctrl+C
44
+ process.exit();
45
+ } else if (c === "\u007F" || c === "\b") {
46
+ // Backspace
47
+ password = password.slice(0, -1);
48
+ } else {
49
+ password += c;
50
+ }
51
+ };
52
+
53
+ stdin.on("data", onData);
54
+ });
55
+ }
56
+
11
57
  const program = new Command();
12
58
 
13
59
  program
14
60
  .name("tm")
15
61
  .description("TerminalMarket CLI — marketplace for developers")
16
- .version("0.6.2");
62
+ .version("0.6.3");
17
63
 
18
64
  // -----------------
19
65
  // config
@@ -51,12 +97,13 @@ config
51
97
  // auth commands
52
98
  // -----------------
53
99
  program
54
- .command("register <email> <password>")
55
- .description("Create a new account")
100
+ .command("register <email> [password]")
101
+ .description("Create a new account (password will be prompted securely)")
56
102
  .option("-n, --name <name>", "Your name")
57
103
  .option("-u, --username <username>", "Username")
58
- .action(async (email, password, opts) => {
104
+ .action(async (email, passwordArg, opts) => {
59
105
  try {
106
+ const password = passwordArg || await askPassword();
60
107
  const username = opts.username || email.split("@")[0];
61
108
  const result = await apiPost("/auth/register", {
62
109
  email,
@@ -79,10 +126,11 @@ program
79
126
  });
80
127
 
81
128
  program
82
- .command("login <email> <password>")
83
- .description("Login to your account")
84
- .action(async (email, password) => {
129
+ .command("login <email> [password]")
130
+ .description("Login to your account (password will be prompted securely)")
131
+ .action(async (email, passwordArg) => {
85
132
  try {
133
+ const password = passwordArg || await askPassword();
86
134
  const result = await apiPost("/auth/login", { email, password });
87
135
 
88
136
  if (result.user) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terminalmarket",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "TerminalMarket CLI — marketplace for developers (client for terminalmarket.app)",
5
5
  "bin": {
6
6
  "tm": "./bin/tm.js"