shellmail 1.0.1 ā 1.0.2
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/dist/index.js +70 -57
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,24 +24,7 @@ program
|
|
|
24
24
|
console.log(chalk.bold("\nš§ ShellMail Setup\n"));
|
|
25
25
|
let local = options.local;
|
|
26
26
|
let recoveryEmail = options.recovery;
|
|
27
|
-
|
|
28
|
-
const answers = await inquirer.prompt([
|
|
29
|
-
{
|
|
30
|
-
type: "input",
|
|
31
|
-
name: "local",
|
|
32
|
-
message: `What would you like your address to be?\n ${chalk.gray("_")}${chalk.cyan("@shellmail.ai")}\n ${chalk.gray("Enter name:")}`,
|
|
33
|
-
validate: (input) => {
|
|
34
|
-
if (!input || input.length < 2)
|
|
35
|
-
return "Must be at least 2 characters";
|
|
36
|
-
if (!/^[a-z0-9][a-z0-9._-]*[a-z0-9]$/i.test(input) && input.length > 2) {
|
|
37
|
-
return "Only letters, numbers, dots, hyphens, underscores allowed";
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
]);
|
|
43
|
-
local = answers.local;
|
|
44
|
-
}
|
|
27
|
+
// Get recovery email first (won't change between retries)
|
|
45
28
|
if (!recoveryEmail) {
|
|
46
29
|
const answers = await inquirer.prompt([
|
|
47
30
|
{
|
|
@@ -58,48 +41,78 @@ program
|
|
|
58
41
|
]);
|
|
59
42
|
recoveryEmail = answers.recovery;
|
|
60
43
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
token: result.token,
|
|
83
|
-
address: result.address,
|
|
84
|
-
});
|
|
85
|
-
console.log(chalk.green("\nā Config saved!\n"));
|
|
86
|
-
console.log(chalk.bold("Next steps:\n"));
|
|
87
|
-
console.log(` ${chalk.cyan("shellmail inbox")} Check your inbox`);
|
|
88
|
-
console.log(` ${chalk.cyan("shellmail otp -w 30")} Wait for an OTP code`);
|
|
89
|
-
console.log(` ${chalk.cyan("shellmail status")} Verify setup\n`);
|
|
44
|
+
// Loop until we get a valid address
|
|
45
|
+
const api = new ShellMailAPI();
|
|
46
|
+
let result = null;
|
|
47
|
+
while (!result) {
|
|
48
|
+
if (!local) {
|
|
49
|
+
const answers = await inquirer.prompt([
|
|
50
|
+
{
|
|
51
|
+
type: "input",
|
|
52
|
+
name: "local",
|
|
53
|
+
message: `Choose your address:\n ${chalk.gray("_")}${chalk.cyan("@shellmail.ai")}\n `,
|
|
54
|
+
validate: (input) => {
|
|
55
|
+
if (!input || input.length < 2)
|
|
56
|
+
return "Must be at least 2 characters";
|
|
57
|
+
if (!/^[a-z0-9][a-z0-9._-]*[a-z0-9]$/i.test(input) && input.length > 2) {
|
|
58
|
+
return "Only letters, numbers, dots, hyphens, underscores allowed";
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
local = answers.local;
|
|
90
65
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
66
|
+
const spinner = ora(`Creating ${local}@shellmail.ai...`).start();
|
|
67
|
+
try {
|
|
68
|
+
result = await api.createAddress(local, recoveryEmail);
|
|
69
|
+
spinner.succeed(chalk.green("Address created!"));
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
const message = err.message;
|
|
73
|
+
if (message.toLowerCase().includes("taken") || message.toLowerCase().includes("exists") || message.includes("409")) {
|
|
74
|
+
spinner.fail(chalk.yellow(`${local}@shellmail.ai is already taken`));
|
|
75
|
+
console.log(chalk.gray(" Try a different name\n"));
|
|
76
|
+
local = null; // Reset to prompt again
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
spinner.fail(chalk.red("Failed to create address"));
|
|
80
|
+
console.error(chalk.red(` ${message}\n`));
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
97
83
|
}
|
|
98
84
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
console.log("\n" + chalk.bold("Your ShellMail address:"));
|
|
86
|
+
console.log(chalk.cyan(` ${result.address}\n`));
|
|
87
|
+
console.log(chalk.bold("Your API token:"));
|
|
88
|
+
console.log(chalk.yellow(` ${result.token}\n`));
|
|
89
|
+
console.log(chalk.gray("ā ļø Save this token! It won't be shown again.\n"));
|
|
90
|
+
// Save to config
|
|
91
|
+
const { save } = await inquirer.prompt([
|
|
92
|
+
{
|
|
93
|
+
type: "confirm",
|
|
94
|
+
name: "save",
|
|
95
|
+
message: "Save token to ~/.shellmail/config.json?",
|
|
96
|
+
default: true,
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
if (save) {
|
|
100
|
+
saveConfig({
|
|
101
|
+
token: result.token,
|
|
102
|
+
address: result.address,
|
|
103
|
+
});
|
|
104
|
+
console.log(chalk.green("\nā Config saved!\n"));
|
|
105
|
+
console.log(chalk.bold("Next steps:\n"));
|
|
106
|
+
console.log(` ${chalk.cyan("shellmail inbox")} Check your inbox`);
|
|
107
|
+
console.log(` ${chalk.cyan("shellmail otp -w 30")} Wait for an OTP code`);
|
|
108
|
+
console.log(` ${chalk.cyan("shellmail status")} Verify setup\n`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.log(chalk.gray("\nSet SHELLMAIL_TOKEN env var to use the CLI:\n"));
|
|
112
|
+
console.log(chalk.cyan(` export SHELLMAIL_TOKEN="${result.token}"\n`));
|
|
113
|
+
console.log(chalk.bold("Then try:\n"));
|
|
114
|
+
console.log(` ${chalk.cyan("shellmail inbox")} Check your inbox`);
|
|
115
|
+
console.log(` ${chalk.cyan("shellmail otp -w 30")} Wait for an OTP code\n`);
|
|
103
116
|
}
|
|
104
117
|
});
|
|
105
118
|
// āā Inbox Command āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|