eitri-cli 1.14.1-beta.1 → 1.15.0-beta.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/eitri-cli-v2/eitri-cli-v2.darwin-arm64.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.darwin-x64.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.linux-x64-gnu.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.win32-x64-msvc.node +0 -0
- package/index.js +8 -0
- package/package.json +1 -1
- package/src/cmd/loginV2.js +89 -0
- package/src/service/MiniLog.js +40 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -40,7 +40,15 @@ const run = async () => {
|
|
|
40
40
|
"Configura suas credenciais de desenvolvedor no dispositivo local"
|
|
41
41
|
)
|
|
42
42
|
.option("--yes", "Aceita o redirecionamento para o console")
|
|
43
|
+
.option("-v, --verbose", "Exibe mais logs")
|
|
43
44
|
.action(async (cmdObj) => {
|
|
45
|
+
const isLoginV2 = process.env.FT_LOGIN_V2
|
|
46
|
+
if (isLoginV2) {
|
|
47
|
+
console.log("\n\n Iniciando login (v2) \n");
|
|
48
|
+
require("./src/cmd/loginV2")(cmdObj);
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
require("./src/cmd/login")(cmdObj);
|
|
45
53
|
});
|
|
46
54
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const configService = require("../service/ConfigService");
|
|
2
|
+
const open = require("open");
|
|
3
|
+
const inquirer = require("inquirer");
|
|
4
|
+
const TrackingEitriAnalytics = require("../service/TrackingEitriAnalytics");
|
|
5
|
+
const MiniLog = require('../service/MiniLog')
|
|
6
|
+
const config = require('../service/ConfigService')
|
|
7
|
+
const {randomUUID} = require('crypto')
|
|
8
|
+
const CliLogin = require('../service/CliLogin')
|
|
9
|
+
module.exports = async function loginV2(args) {
|
|
10
|
+
try {
|
|
11
|
+
const roomName = randomUUID()?.toString()
|
|
12
|
+
|
|
13
|
+
const consoleUrl = `${configService.get("managerFront").url}`;
|
|
14
|
+
const consoleUrlWithParams = `${consoleUrl}?version=2&loginType=EITRI_CLI&callbackId=${roomName}`;
|
|
15
|
+
|
|
16
|
+
if(args.verbose){
|
|
17
|
+
console.log('Console Login URL: ', consoleUrlWithParams);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (args.yes) {
|
|
21
|
+
openConsole(consoleUrlWithParams)
|
|
22
|
+
} else {
|
|
23
|
+
const {openPortalAnwser} = await inquirer.prompt([
|
|
24
|
+
{
|
|
25
|
+
type: "confirm",
|
|
26
|
+
name: "openPortalAnwser",
|
|
27
|
+
message: " Podemos redirecioná-lo para o login?",
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
if (openPortalAnwser) {
|
|
32
|
+
openConsole(consoleUrlWithParams)
|
|
33
|
+
} else {
|
|
34
|
+
const message = "\n Copie o link e cole em seu navegador para fazer o login na Eitri-CLI. "
|
|
35
|
+
console.log(message,consoleUrlWithParams);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(`\n\n Aguardando autenticação...`);
|
|
40
|
+
|
|
41
|
+
const miniLog = new MiniLog(config.get('miniLog'))
|
|
42
|
+
await miniLog.connectGeneric({
|
|
43
|
+
roomName: roomName.toString(),
|
|
44
|
+
args,
|
|
45
|
+
skipLogs: true,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const resp = await miniLog.awaitForGenerateLoginCrendetials()
|
|
49
|
+
|
|
50
|
+
process.stdin.resume()
|
|
51
|
+
|
|
52
|
+
if(resp.key === "credential"){
|
|
53
|
+
const {email, credential} = resp
|
|
54
|
+
|
|
55
|
+
await new CliLogin().saveCredentials({
|
|
56
|
+
email,
|
|
57
|
+
credential
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} catch (error) {
|
|
62
|
+
TrackingEitriAnalytics.sendEvent({
|
|
63
|
+
eventName: "login.error",
|
|
64
|
+
data: {
|
|
65
|
+
errorMessage: error?.message ?? "",
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
console.log(
|
|
70
|
+
"Erro inesperado, tente novamente mais tarde.",
|
|
71
|
+
error?.message
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function openConsole(consoleUrl = "", acceptedToOpenConsole = false) {
|
|
79
|
+
let message = ""
|
|
80
|
+
try {
|
|
81
|
+
open(consoleUrl);
|
|
82
|
+
message = "Aberto em seu navegador padrão";
|
|
83
|
+
} catch (error) {
|
|
84
|
+
message =
|
|
85
|
+
"Não foi possível abrir automaticamente. Copie o link e cole em seu navegador para fazer o login na Eitri-CLI. " +
|
|
86
|
+
consoleUrl;
|
|
87
|
+
}
|
|
88
|
+
console.log("\n", message);
|
|
89
|
+
}
|
package/src/service/MiniLog.js
CHANGED
|
@@ -30,6 +30,35 @@ class MiniLog {
|
|
|
30
30
|
})
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
connectGeneric({roomName, args, skipLogs}) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const socket = this.createSocket()
|
|
36
|
+
socket.on('connect', () => {
|
|
37
|
+
if(args?.verbose) {
|
|
38
|
+
console.log('🔗 Conectando em: ', {roomName, args})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
socket.emit('joinRoom', roomName)
|
|
42
|
+
resolve()
|
|
43
|
+
})
|
|
44
|
+
socket.on('connect_error', (e) => {
|
|
45
|
+
if (args?.verbose) {
|
|
46
|
+
console.error('Não foi possível contectar em: ', {roomName})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
reject(e)
|
|
50
|
+
})
|
|
51
|
+
socket.on('onLog', (data) => {
|
|
52
|
+
if(!skipLogs){
|
|
53
|
+
const message = this._colorizeMessage(data?.msg, data.method)
|
|
54
|
+
const consoleProp = data?.method ? data.method : "log"
|
|
55
|
+
console[consoleProp](message);
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
this.socket = socket
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
33
62
|
awaitForPushVersion() {
|
|
34
63
|
return new Promise((resolve, reject) => {
|
|
35
64
|
this.socket.on('onLog', (event) => {
|
|
@@ -46,6 +75,17 @@ class MiniLog {
|
|
|
46
75
|
})
|
|
47
76
|
}
|
|
48
77
|
|
|
78
|
+
awaitForGenerateLoginCrendetials() {
|
|
79
|
+
return new Promise((resolve) => {
|
|
80
|
+
this.socket.on('onLog', (event) => {
|
|
81
|
+
if(event.eventKey === "loginCredentials"){
|
|
82
|
+
console.log("\n\n Iniciando configuração das suas credenciais...\n\n")
|
|
83
|
+
resolve(event.credentials)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
49
89
|
createSocket() {
|
|
50
90
|
if (this._config.path) {
|
|
51
91
|
return io.connect(this._config.url, { path: this._config.path, transport: 'websocket' })
|