breakroom 2.0.0 → 2.0.1
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/bin/setup.js +41 -7
- package/package.json +1 -1
package/bin/setup.js
CHANGED
|
@@ -19,12 +19,20 @@ const BREAKROOM_ORIGIN = 'https://zahuierik.com';
|
|
|
19
19
|
const API_ORIGIN = 'https://break-room.erikzahui27.workers.dev';
|
|
20
20
|
const STRIPE_URL = 'https://buy.stripe.com/14A3cw3kngBF6ZR6JbfEk04';
|
|
21
21
|
|
|
22
|
-
const scriptedAnswers =
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const scriptedAnswers = (() => {
|
|
23
|
+
if (process.stdin.isTTY !== false) return null;
|
|
24
|
+
try {
|
|
25
|
+
const data = fs.readFileSync(0, 'utf8');
|
|
26
|
+
return data.length > 0 ? data.split(/\r?\n/) : null;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
const rl = readline.createInterface({
|
|
25
33
|
input: process.stdin,
|
|
26
34
|
output: process.stdout,
|
|
27
|
-
})
|
|
35
|
+
});
|
|
28
36
|
|
|
29
37
|
const chairArt = String.raw`
|
|
30
38
|
__________________
|
|
@@ -408,6 +416,28 @@ async function actionRevert() {
|
|
|
408
416
|
console.log('\n\x1b[32mDone.\x1b[0m Originals restored. Break Room proxy routing removed.\n');
|
|
409
417
|
}
|
|
410
418
|
|
|
419
|
+
async function actionRecover() {
|
|
420
|
+
console.log();
|
|
421
|
+
const email = (await ask('Enter the email you used for purchase: ')).trim().toLowerCase();
|
|
422
|
+
if (!email) { console.log('Canceled.\n'); return; }
|
|
423
|
+
try {
|
|
424
|
+
const resp = await requestJson(`${API_ORIGIN}/breakroom/license/lookup/${encodeURIComponent(email)}`);
|
|
425
|
+
if (resp.status !== 200) {
|
|
426
|
+
console.log(`\x1b[31mNo licenses found for ${email}.\x1b[0m`);
|
|
427
|
+
console.log('Make sure you used the same email at checkout.\n');
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
console.log(`\n\x1b[32mFound ${resp.json.licenses.length} license(s):\x1b[0m\n`);
|
|
431
|
+
resp.json.licenses.forEach((l, i) => {
|
|
432
|
+
const d = new Date(l.created_at).toLocaleDateString();
|
|
433
|
+
console.log(` ${i + 1}) ${l.key} (created ${d})`);
|
|
434
|
+
});
|
|
435
|
+
console.log();
|
|
436
|
+
} catch (err) {
|
|
437
|
+
console.log(`\x1b[31mError looking up license: ${err.message}\x1b[0m\n`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
411
441
|
async function actionCheck() {
|
|
412
442
|
console.log();
|
|
413
443
|
|
|
@@ -435,7 +465,8 @@ function showMenu() {
|
|
|
435
465
|
console.log(' 4) Get a license');
|
|
436
466
|
console.log(' 5) Revert patches (restore backups)');
|
|
437
467
|
console.log(' 6) Check configuration status');
|
|
438
|
-
console.log(' 7)
|
|
468
|
+
console.log(' 7) Recover lost license');
|
|
469
|
+
console.log(' 8) Exit\n');
|
|
439
470
|
}
|
|
440
471
|
|
|
441
472
|
async function main() {
|
|
@@ -446,7 +477,7 @@ async function main() {
|
|
|
446
477
|
|
|
447
478
|
while (true) {
|
|
448
479
|
showMenu();
|
|
449
|
-
const choice = (await ask(' Enter choice (1-
|
|
480
|
+
const choice = (await ask(' Enter choice (1-8): ')).trim();
|
|
450
481
|
if (choice === '__EOF__') break;
|
|
451
482
|
|
|
452
483
|
try {
|
|
@@ -470,6 +501,9 @@ async function main() {
|
|
|
470
501
|
await actionCheck();
|
|
471
502
|
break;
|
|
472
503
|
case '7':
|
|
504
|
+
await actionRecover();
|
|
505
|
+
break;
|
|
506
|
+
case '8':
|
|
473
507
|
console.log('\nGoodbye.\n');
|
|
474
508
|
return;
|
|
475
509
|
default:
|
|
@@ -479,7 +513,7 @@ async function main() {
|
|
|
479
513
|
console.error(`\n\x1b[31mError:\x1b[0m ${err.message}\n`);
|
|
480
514
|
}
|
|
481
515
|
|
|
482
|
-
if (choice !== '
|
|
516
|
+
if (choice !== '8' && choice !== '__EOF__') {
|
|
483
517
|
if (await ask('Press Enter to return to the menu...') === '__EOF__') break;
|
|
484
518
|
}
|
|
485
519
|
}
|