shellmail 1.0.0 ā 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 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,25 +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: "Choose your email address:",
|
|
33
|
-
suffix: chalk.gray("@shellmail.ai"),
|
|
34
|
-
validate: (input) => {
|
|
35
|
-
if (!input || input.length < 2)
|
|
36
|
-
return "Must be at least 2 characters";
|
|
37
|
-
if (!/^[a-z0-9][a-z0-9._-]*[a-z0-9]$/i.test(input) && input.length > 2) {
|
|
38
|
-
return "Only letters, numbers, dots, hyphens, underscores allowed";
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
]);
|
|
44
|
-
local = answers.local;
|
|
45
|
-
}
|
|
27
|
+
// Get recovery email first (won't change between retries)
|
|
46
28
|
if (!recoveryEmail) {
|
|
47
29
|
const answers = await inquirer.prompt([
|
|
48
30
|
{
|
|
@@ -59,41 +41,78 @@ program
|
|
|
59
41
|
]);
|
|
60
42
|
recoveryEmail = answers.recovery;
|
|
61
43
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
token: result.token,
|
|
84
|
-
address: result.address,
|
|
85
|
-
});
|
|
86
|
-
console.log(chalk.green("\nā Config saved! You can now use other shellmail commands.\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;
|
|
87
65
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
}
|
|
91
83
|
}
|
|
92
84
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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`);
|
|
97
116
|
}
|
|
98
117
|
});
|
|
99
118
|
// āā Inbox Command āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|