breakroom 2.0.0 → 2.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/bin/setup.js +68 -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
|
__________________
|
|
@@ -102,6 +110,33 @@ function requestJson(url) {
|
|
|
102
110
|
});
|
|
103
111
|
}
|
|
104
112
|
|
|
113
|
+
function postJson(url, data) {
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const body = JSON.stringify(data);
|
|
116
|
+
const u = new URL(url);
|
|
117
|
+
const opts = {
|
|
118
|
+
hostname: u.hostname, port: u.port, path: u.pathname,
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }
|
|
121
|
+
};
|
|
122
|
+
const req = https.request(opts, (res) => {
|
|
123
|
+
let respBody = '';
|
|
124
|
+
res.setEncoding('utf8');
|
|
125
|
+
res.on('data', (chunk) => { respBody += chunk; });
|
|
126
|
+
res.on('end', () => {
|
|
127
|
+
try {
|
|
128
|
+
resolve({ status: res.statusCode || 0, json: JSON.parse(respBody) });
|
|
129
|
+
} catch (err) {
|
|
130
|
+
reject(new Error(`Invalid response from Break Room (${res.statusCode}): ${respBody.slice(0, 160)}`));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
req.on('error', reject);
|
|
135
|
+
req.write(body);
|
|
136
|
+
req.end();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
105
140
|
async function verifyLicense(licenseKey) {
|
|
106
141
|
const encoded = encodeURIComponent(licenseKey);
|
|
107
142
|
const response = await requestJson(`${API_ORIGIN}/breakroom/${encoded}/v1`);
|
|
@@ -408,6 +443,28 @@ async function actionRevert() {
|
|
|
408
443
|
console.log('\n\x1b[32mDone.\x1b[0m Originals restored. Break Room proxy routing removed.\n');
|
|
409
444
|
}
|
|
410
445
|
|
|
446
|
+
async function actionRecover() {
|
|
447
|
+
console.log();
|
|
448
|
+
const email = (await ask('Enter the email you used for purchase: ')).trim().toLowerCase();
|
|
449
|
+
if (!email) { console.log('Canceled.\n'); return; }
|
|
450
|
+
try {
|
|
451
|
+
const resp = await postJson(`${API_ORIGIN}/breakroom/license/lookup`, { email });
|
|
452
|
+
if (resp.status !== 200) {
|
|
453
|
+
console.log(`\x1b[31mNo licenses found for ${email}.\x1b[0m`);
|
|
454
|
+
console.log('Make sure you used the same email at checkout.\n');
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
console.log(`\n\x1b[32mFound ${resp.json.licenses.length} license(s):\x1b[0m\n`);
|
|
458
|
+
resp.json.licenses.forEach((l, i) => {
|
|
459
|
+
const d = new Date(l.created_at).toLocaleDateString();
|
|
460
|
+
console.log(` ${i + 1}) ${l.key} (created ${d})`);
|
|
461
|
+
});
|
|
462
|
+
console.log();
|
|
463
|
+
} catch (err) {
|
|
464
|
+
console.log(`\x1b[31mError looking up license: ${err.message}\x1b[0m\n`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
411
468
|
async function actionCheck() {
|
|
412
469
|
console.log();
|
|
413
470
|
|
|
@@ -435,7 +492,8 @@ function showMenu() {
|
|
|
435
492
|
console.log(' 4) Get a license');
|
|
436
493
|
console.log(' 5) Revert patches (restore backups)');
|
|
437
494
|
console.log(' 6) Check configuration status');
|
|
438
|
-
console.log(' 7)
|
|
495
|
+
console.log(' 7) Recover lost license');
|
|
496
|
+
console.log(' 8) Exit\n');
|
|
439
497
|
}
|
|
440
498
|
|
|
441
499
|
async function main() {
|
|
@@ -446,7 +504,7 @@ async function main() {
|
|
|
446
504
|
|
|
447
505
|
while (true) {
|
|
448
506
|
showMenu();
|
|
449
|
-
const choice = (await ask(' Enter choice (1-
|
|
507
|
+
const choice = (await ask(' Enter choice (1-8): ')).trim();
|
|
450
508
|
if (choice === '__EOF__') break;
|
|
451
509
|
|
|
452
510
|
try {
|
|
@@ -470,6 +528,9 @@ async function main() {
|
|
|
470
528
|
await actionCheck();
|
|
471
529
|
break;
|
|
472
530
|
case '7':
|
|
531
|
+
await actionRecover();
|
|
532
|
+
break;
|
|
533
|
+
case '8':
|
|
473
534
|
console.log('\nGoodbye.\n');
|
|
474
535
|
return;
|
|
475
536
|
default:
|
|
@@ -479,7 +540,7 @@ async function main() {
|
|
|
479
540
|
console.error(`\n\x1b[31mError:\x1b[0m ${err.message}\n`);
|
|
480
541
|
}
|
|
481
542
|
|
|
482
|
-
if (choice !== '
|
|
543
|
+
if (choice !== '8' && choice !== '__EOF__') {
|
|
483
544
|
if (await ask('Press Enter to return to the menu...') === '__EOF__') break;
|
|
484
545
|
}
|
|
485
546
|
}
|