plexmint 0.2.1 → 0.2.3
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 +71 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -190,12 +190,19 @@ var PlexMintApiError = class extends Error {
|
|
|
190
190
|
};
|
|
191
191
|
|
|
192
192
|
// src/commands/setup.ts
|
|
193
|
+
function suggestTicker(name) {
|
|
194
|
+
const parts = name.trim().toUpperCase().split(/\s+/);
|
|
195
|
+
if (parts.length >= 2) {
|
|
196
|
+
return (parts[0].slice(0, 2) + parts[1].slice(0, 2)).slice(0, 4);
|
|
197
|
+
}
|
|
198
|
+
return parts[0].slice(0, 4);
|
|
199
|
+
}
|
|
193
200
|
async function setupCommand() {
|
|
194
201
|
console.log("");
|
|
195
202
|
console.log(mintBold(" PlexMint Setup"));
|
|
196
203
|
console.log(chalk2.gray(" Create your account and start browsing AI prompts."));
|
|
197
204
|
console.log("");
|
|
198
|
-
const
|
|
205
|
+
const { name, email } = await inquirer.prompt([
|
|
199
206
|
{
|
|
200
207
|
type: "input",
|
|
201
208
|
name: "name",
|
|
@@ -207,28 +214,40 @@ async function setupCommand() {
|
|
|
207
214
|
name: "email",
|
|
208
215
|
message: "Email:",
|
|
209
216
|
validate: (v) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v) || "Enter a valid email address."
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
message: "Confirm password:",
|
|
222
|
-
mask: "*",
|
|
223
|
-
validate: (v, a) => {
|
|
224
|
-
if (!a) return "Confirm your password.";
|
|
225
|
-
return v === a.password || "Passwords do not match.";
|
|
217
|
+
}
|
|
218
|
+
]);
|
|
219
|
+
let password = "";
|
|
220
|
+
while (true) {
|
|
221
|
+
const { pw } = await inquirer.prompt([
|
|
222
|
+
{
|
|
223
|
+
type: "password",
|
|
224
|
+
name: "pw",
|
|
225
|
+
message: "Password:",
|
|
226
|
+
mask: "*",
|
|
227
|
+
validate: (v) => v.length >= 8 || "Password must be at least 8 characters."
|
|
226
228
|
}
|
|
227
|
-
|
|
229
|
+
]);
|
|
230
|
+
const { confirm } = await inquirer.prompt([
|
|
231
|
+
{
|
|
232
|
+
type: "password",
|
|
233
|
+
name: "confirm",
|
|
234
|
+
message: "Confirm password:",
|
|
235
|
+
mask: "*"
|
|
236
|
+
}
|
|
237
|
+
]);
|
|
238
|
+
if (pw === confirm) {
|
|
239
|
+
password = pw;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
console.log(chalk2.red(" Passwords do not match. Try again.\n"));
|
|
243
|
+
}
|
|
244
|
+
const suggested = suggestTicker(name);
|
|
245
|
+
const { tickerPrefix } = await inquirer.prompt([
|
|
228
246
|
{
|
|
229
247
|
type: "input",
|
|
230
248
|
name: "tickerPrefix",
|
|
231
|
-
message:
|
|
249
|
+
message: `Ticker prefix (2-5 uppercase letters, e.g. ${suggested}):`,
|
|
250
|
+
default: suggested,
|
|
232
251
|
transformer: (v) => v.toUpperCase(),
|
|
233
252
|
validate: (v) => /^[A-Z]{2,5}$/i.test(v.trim()) || "Enter 2-5 letters (e.g. NUE, ACME)."
|
|
234
253
|
}
|
|
@@ -237,27 +256,40 @@ async function setupCommand() {
|
|
|
237
256
|
try {
|
|
238
257
|
const client = new PlexMintClient();
|
|
239
258
|
await client.register({
|
|
240
|
-
name:
|
|
241
|
-
email:
|
|
242
|
-
password
|
|
243
|
-
tickerPrefix:
|
|
259
|
+
name: name.trim(),
|
|
260
|
+
email: email.trim().toLowerCase(),
|
|
261
|
+
password,
|
|
262
|
+
tickerPrefix: tickerPrefix.trim().toUpperCase()
|
|
244
263
|
});
|
|
245
264
|
spinner.succeed("Account created! Check your email for a verification code.");
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
265
|
+
} catch (error) {
|
|
266
|
+
spinner.fail("Registration failed.");
|
|
267
|
+
if (error instanceof PlexMintApiError) {
|
|
268
|
+
console.error(chalk2.red(`
|
|
269
|
+
Error: ${error.message}
|
|
270
|
+
`));
|
|
271
|
+
} else {
|
|
272
|
+
console.error(chalk2.red("\n Connection error. Is plexmint.com reachable?\n"));
|
|
273
|
+
}
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
console.log("");
|
|
277
|
+
const { code } = await inquirer.prompt([
|
|
278
|
+
{
|
|
279
|
+
type: "input",
|
|
280
|
+
name: "code",
|
|
281
|
+
message: "Enter 6-digit verification code:",
|
|
282
|
+
validate: (v) => /^\d{6}$/.test(v.trim()) || "Enter the 6-digit code from your email."
|
|
283
|
+
}
|
|
284
|
+
]);
|
|
285
|
+
const verifySpinner = ora("Verifying...").start();
|
|
286
|
+
try {
|
|
287
|
+
const client = new PlexMintClient();
|
|
256
288
|
const result = await client.verify(
|
|
257
|
-
|
|
289
|
+
email.trim().toLowerCase(),
|
|
258
290
|
code.trim()
|
|
259
291
|
);
|
|
260
|
-
verifySpinner.
|
|
292
|
+
verifySpinner.succeed("Email verified!");
|
|
261
293
|
const { apiKey, user } = result.data;
|
|
262
294
|
setAuth(apiKey, user.email, user.name);
|
|
263
295
|
console.log("");
|
|
@@ -274,15 +306,13 @@ async function setupCommand() {
|
|
|
274
306
|
);
|
|
275
307
|
console.log("");
|
|
276
308
|
} catch (error) {
|
|
277
|
-
|
|
309
|
+
verifySpinner.fail("Verification failed.");
|
|
278
310
|
if (error instanceof PlexMintApiError) {
|
|
279
311
|
console.error(chalk2.red(`
|
|
280
|
-
Error: ${error.message}
|
|
281
|
-
|
|
312
|
+
Error: ${error.message}`));
|
|
313
|
+
console.error(chalk2.gray(" You can try again: plexmint login\n"));
|
|
282
314
|
} else {
|
|
283
|
-
console.error(
|
|
284
|
-
chalk2.red("\n Connection error. Is plexmint.com reachable?\n")
|
|
285
|
-
);
|
|
315
|
+
console.error(chalk2.red("\n Connection error. Is plexmint.com reachable?\n"));
|
|
286
316
|
}
|
|
287
317
|
process.exit(1);
|
|
288
318
|
}
|