|
|
@ -3,23 +3,7 @@ import fetch from 'node-fetch'; |
|
|
|
import * as cfg from './cfg'; |
|
|
|
import { stringify as stringifyQuery } from 'querystring'; |
|
|
|
import { validate } from 'email-validator'; |
|
|
|
|
|
|
|
function readEmail ({ invalid = false } = {}) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
const decorate = invalid ? chalk.red : (v) => v; |
|
|
|
const prompt = decorate('> Enter your email address: '); |
|
|
|
process.stdout.write(prompt); |
|
|
|
const data = []; |
|
|
|
process.stdin.on('data', (d) => { |
|
|
|
data.push(d); |
|
|
|
if (d.indexOf('\n') > -1) { |
|
|
|
process.stdin.pause(); |
|
|
|
resolve(Buffer.concat(data).toString().trim()); |
|
|
|
} |
|
|
|
}); |
|
|
|
process.stdin.resume(); |
|
|
|
}); |
|
|
|
} |
|
|
|
import readEmail from 'email-prompt'; |
|
|
|
|
|
|
|
async function getVerificationToken (url, email) { |
|
|
|
const data = JSON.stringify({ email }); |
|
|
@ -59,6 +43,8 @@ function sleep (ms) { |
|
|
|
|
|
|
|
async function register (url, { retryEmail = false } = {}) { |
|
|
|
const email = await readEmail({ invalid: retryEmail }); |
|
|
|
process.stdout.write('\n'); |
|
|
|
|
|
|
|
if (!validate(email)) return register(url, { retryEmail: true }); |
|
|
|
|
|
|
|
const verificationToken = await getVerificationToken(url, email); |
|
|
|