eitri-cli 1.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/README.md +54 -0
- package/bitbucket-pipelines.toBeChanged.yml +64 -0
- package/boilerplate/mini-app-cafe-madeira.zip +0 -0
- package/check-version.js +12 -0
- package/config/default-eitri.js +1 -0
- package/config/dev.js +91 -0
- package/config/k8s-eitri.js +92 -0
- package/config/loc-eitri.js +92 -0
- package/config/prod-eitri.js +92 -0
- package/config/test-eitri.js +2 -0
- package/index-eitri.js +6 -0
- package/index.js +182 -0
- package/install-dev.bat +1 -0
- package/install-dev.sh +1 -0
- package/jest.config.js +6 -0
- package/jsconfig.json +9 -0
- package/package.json +80 -0
- package/publisher.js +53 -0
- package/src/cmd/clean.js +179 -0
- package/src/cmd/create.js +281 -0
- package/src/cmd/credentials.js +105 -0
- package/src/cmd/invite.js +87 -0
- package/src/cmd/list.js +36 -0
- package/src/cmd/login.js +51 -0
- package/src/cmd/manage-env.js +129 -0
- package/src/cmd/open-share.js +6 -0
- package/src/cmd/order-details.js +6 -0
- package/src/cmd/push-version.js +182 -0
- package/src/cmd/show-message-if-outdated-package.js +32 -0
- package/src/cmd/signup.js +69 -0
- package/src/cmd/start.js +171 -0
- package/src/cmd/tail-logs.js +26 -0
- package/src/cmd/test-initialization-params.js +6 -0
- package/src/cmd/validate.js +170 -0
- package/src/cmd/version.js +29 -0
- package/src/enum/WatcherOpts.js +3 -0
- package/src/enum/target.js +6 -0
- package/src/helpers/request-listener-helper.js +55 -0
- package/src/model/Payload.js +45 -0
- package/src/model/Target.js +76 -0
- package/src/model/User.js +11 -0
- package/src/service/AuthConfig.js +88 -0
- package/src/service/BlindGuardian.js +134 -0
- package/src/service/CliLogin.js +47 -0
- package/src/service/ConfigService.js +16 -0
- package/src/service/CredentialsService.js +47 -0
- package/src/service/GATrackingStrategy.js +16 -0
- package/src/service/HashFolder.js +79 -0
- package/src/service/Http.js +234 -0
- package/src/service/InviteService.js +45 -0
- package/src/service/ManageEnvService.js +10 -0
- package/src/service/MiniLog.js +132 -0
- package/src/service/QRCodeFactory.js +43 -0
- package/src/service/Server.js +239 -0
- package/src/service/StarterService.js +31 -0
- package/src/service/TagTree.js +101 -0
- package/src/service/TargetService.js +97 -0
- package/src/service/TrackService.js +11 -0
- package/src/service/TrackingEitriAnalytics.js +32 -0
- package/src/service/TrackingService.js +183 -0
- package/src/service/ValidateResult.js +57 -0
- package/src/service/Watcher.js +119 -0
- package/src/service/Workspace.js +1069 -0
- package/src/service/WorkspaceManager.js +74 -0
- package/src/service/factories/DoubtsStarterFactory.js +25 -0
- package/src/service/factories/MiniWebAppFactory.js +43 -0
- package/src/service/factories/QRCodeStarterFactory.js +78 -0
- package/src/service/factories/WebStarterFactory.js +88 -0
- package/src/service/factories/WoodCoffeeFactory.js +230 -0
- package/src/util/AboutTemplate.jsx +14 -0
- package/src/util/UrlUtils.js +12 -0
- package/src/util/UserLocalCredential.js +122 -0
- package/src/util/error-messages/error-messages.js +24 -0
- package/src/util/error-messages/invite/invite-error-messages.js +14 -0
- package/src/util/getCliVersion.js +13 -0
- package/src/util/getCreateFactory.js +9 -0
- package/src/util/ipv4.js +19 -0
- package/src/util/manage-env.js +65 -0
- package/src/util/open-docs.js +7 -0
- package/src/util/os.js +39 -0
- package/src/util/server-url.js +15 -0
- package/src/util/template-utils.js +21 -0
- package/src/view/index.html +19 -0
- package/targetMobileStickyness.md +47 -0
- package/targetWebStickyness.md +40 -0
- package/test/_fixtures/factory.js +30 -0
- package/test/_fixtures/miniWebApp/miniapp.conf.js +4 -0
- package/test/_fixtures/miniapp.conf.js +5 -0
- package/test/_fixtures/server/HelloWorldBackend.js +7 -0
- package/test/_fixtures/src/Home.js +5 -0
- package/test/_fixtures/src/Home2.js +5 -0
- package/test/_fixtures/src/commons/util.js +3 -0
- package/test/_fixtures/src/components/TagA.jsx +4 -0
- package/test/_fixtures/src/components/TagB.jsx +4 -0
- package/test/_fixtures/src/components/TagC.jsx +3 -0
- package/test/_fixtures/src/components/TagD.jsx +3 -0
- package/test/_fixtures/src/server/foo.js +7 -0
- package/test/_fixtures/src/views/AboutTemplate.jsx +14 -0
- package/test/_fixtures/woodcoffee/miniapp.conf.js +3 -0
- package/test/ame.conf.js +3 -0
- package/test/cmd/clean.test.js +66 -0
- package/test/cmd/create.test.js +252 -0
- package/test/cmd/credentials.test.js +159 -0
- package/test/cmd/list.test.js +74 -0
- package/test/cmd/manage-env.test.js +168 -0
- package/test/cmd/signup.test.js +20 -0
- package/test/cmd/start.test.js +5 -0
- package/test/miniapp.conf.js +3 -0
- package/test/model/Payload.test.js +35 -0
- package/test/service/BlindGuardian.test.js +84 -0
- package/test/service/CheckAmeConf.test.js +313 -0
- package/test/service/Http.test.js +312 -0
- package/test/service/InviteService.test.js +117 -0
- package/test/service/MiniWebAppFactory.test.js +40 -0
- package/test/service/TagTree.test.js +81 -0
- package/test/service/TargetService.test.js +48 -0
- package/test/service/TrackingService.test.js +105 -0
- package/test/service/UserAmeConf.test.js +47 -0
- package/test/service/WoodCoffeeFactory.test.js +148 -0
- package/test/service/Workspace.test.js +364 -0
- package/thinQrCode.md +58 -0
- package/v1.5.0.md +3 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const { execSync } = require('child_process')
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loga a versao de um pacote npm
|
|
7
|
+
*/
|
|
8
|
+
function version() {
|
|
9
|
+
let packageJson = require(path.resolve(__dirname, '..', '..', 'package.json'))
|
|
10
|
+
let publishedVersion = getVersion(packageJson.name)
|
|
11
|
+
if (packageJson.version !== publishedVersion) {
|
|
12
|
+
console.log(
|
|
13
|
+
`\n\t> Você está usando a versão ${packageJson.version}, temos uma nova versão: ${publishedVersion}!`
|
|
14
|
+
)
|
|
15
|
+
console.log(
|
|
16
|
+
`\t> Para atualizar use o comando:\n\n\t ${packageJson.name} self-update\n`
|
|
17
|
+
)
|
|
18
|
+
} else {
|
|
19
|
+
console.log(`\tVersao atual: ${packageJson.version}`)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getVersion(npmPackage) {
|
|
24
|
+
return execSync(`npm show ${npmPackage} version`)
|
|
25
|
+
.toString()
|
|
26
|
+
.trim()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = {version, getVersion}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const IMAGES_FORMAT = ['.png', '.jpg', '.jpeg', '.gif']
|
|
2
|
+
const SVG_FORMAT = '.svg'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {*} workspaceHttp
|
|
6
|
+
* @param {string} requestUrl
|
|
7
|
+
* @param {Express.Response} response
|
|
8
|
+
* @param {string} workspaceUrl
|
|
9
|
+
* @param {boolean} verbose
|
|
10
|
+
*/
|
|
11
|
+
function requestListenerHelper(workspaceHttp, requestUrl, response, workspaceUrl, verbose) {
|
|
12
|
+
const isImage = IMAGES_FORMAT.find(fmt => requestUrl.endsWith(fmt))
|
|
13
|
+
if(isImage) {
|
|
14
|
+
workspaceHttp
|
|
15
|
+
.get(workspaceUrl, {
|
|
16
|
+
responseType: 'arraybuffer'
|
|
17
|
+
})
|
|
18
|
+
.then((workspaceRes) => {
|
|
19
|
+
return response.send(workspaceRes)
|
|
20
|
+
})
|
|
21
|
+
.catch((e) => {
|
|
22
|
+
if(verbose) {
|
|
23
|
+
console.log(e)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
else if(requestUrl.endsWith(SVG_FORMAT)) {
|
|
28
|
+
workspaceHttp
|
|
29
|
+
.get(workspaceUrl)
|
|
30
|
+
.then((workspaceRes) => {
|
|
31
|
+
response.type('image/svg+xml').send(workspaceRes)
|
|
32
|
+
|
|
33
|
+
})
|
|
34
|
+
.catch((e) => {
|
|
35
|
+
if(verbose) {
|
|
36
|
+
console.log(e)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
workspaceHttp
|
|
42
|
+
.get(workspaceUrl)
|
|
43
|
+
.then((workspaceRes) => {
|
|
44
|
+
response.send(workspaceRes)
|
|
45
|
+
|
|
46
|
+
})
|
|
47
|
+
.catch((e) => {
|
|
48
|
+
if(verbose) {
|
|
49
|
+
console.log(e)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = requestListenerHelper
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class Payload {
|
|
2
|
+
/**
|
|
3
|
+
* Create a miniapp payload.
|
|
4
|
+
* @param {string} workspaceUrl
|
|
5
|
+
* @param {string} shareId
|
|
6
|
+
* @param {string} shareEnvironment
|
|
7
|
+
*/
|
|
8
|
+
constructor(shareId, shareEnvironment){
|
|
9
|
+
this.shareId = shareId
|
|
10
|
+
this.shareEnvironment = shareEnvironment
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} shareId
|
|
15
|
+
*/
|
|
16
|
+
setShareId(shareId) {
|
|
17
|
+
this.shareId = shareId
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get shareId.
|
|
22
|
+
* @return {string}
|
|
23
|
+
*/
|
|
24
|
+
getShareId() {
|
|
25
|
+
return this.shareId
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} shareEnvironment
|
|
30
|
+
*/
|
|
31
|
+
setShareEnvironment(shareEnvironment) {
|
|
32
|
+
this.shareEnvironment = shareEnvironment
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get shareEnvironment.
|
|
38
|
+
* @return {string}
|
|
39
|
+
*/
|
|
40
|
+
getShareEnvironment() {
|
|
41
|
+
return this.shareEnvironment
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = Payload
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
class TargetConfig {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.id = ''
|
|
5
|
+
this.libUrl = ''
|
|
6
|
+
this.runnerUrl = ''
|
|
7
|
+
this.bootstrapBaseUrl = ''
|
|
8
|
+
this.askUserDataApiUrl = ''
|
|
9
|
+
this.default = ''
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class MiniAppBoilerplateList {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.name = ''
|
|
16
|
+
this.boilerplateUrl = ''
|
|
17
|
+
this.description = ''
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = class Target {
|
|
22
|
+
constructor() {
|
|
23
|
+
/**
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
this.id= ''
|
|
27
|
+
/**
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
30
|
+
this.name= ''
|
|
31
|
+
/**
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
this.minimumCliVersion= ''
|
|
35
|
+
/**
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
this.boilerplateUrl= ''
|
|
39
|
+
/**
|
|
40
|
+
* @type {string}
|
|
41
|
+
*/
|
|
42
|
+
this.superAppClientLibName= ''
|
|
43
|
+
/**
|
|
44
|
+
* @type {string}
|
|
45
|
+
*/
|
|
46
|
+
this.componentsLibName= ''
|
|
47
|
+
/**
|
|
48
|
+
* @type {string}
|
|
49
|
+
*/
|
|
50
|
+
this.description= ''
|
|
51
|
+
/**
|
|
52
|
+
* @type {boolean}
|
|
53
|
+
*/
|
|
54
|
+
this.status= false
|
|
55
|
+
/**
|
|
56
|
+
* @type {string}
|
|
57
|
+
*/
|
|
58
|
+
this.platform= ''
|
|
59
|
+
/**
|
|
60
|
+
* @type {TargetConfig[]}
|
|
61
|
+
*/
|
|
62
|
+
this.targetConfig= ''
|
|
63
|
+
/**
|
|
64
|
+
* @type {string}
|
|
65
|
+
*/
|
|
66
|
+
this.sdkSupport= ''
|
|
67
|
+
/**
|
|
68
|
+
* @type {string}
|
|
69
|
+
*/
|
|
70
|
+
this.default= ''
|
|
71
|
+
/**
|
|
72
|
+
* @type {MiniAppBoilerplateList[]}
|
|
73
|
+
*/
|
|
74
|
+
this.miniAppBoilerplateList= ''
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const axios = require('axios')
|
|
5
|
+
const config = require('config')
|
|
6
|
+
const { exit } = require('process')
|
|
7
|
+
|
|
8
|
+
const DEFAULT_ENV = 'hml'
|
|
9
|
+
|
|
10
|
+
class AuthConfig { // abastract
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.blindGuardianUrl = config.get('blindGuardian').url
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getConfPath() {}
|
|
17
|
+
|
|
18
|
+
readConf() {}
|
|
19
|
+
|
|
20
|
+
readClientCredentials() {
|
|
21
|
+
const credencialConfig = this.readConf()
|
|
22
|
+
let data
|
|
23
|
+
if (this._isOldProfileVersion(credencialConfig)) {
|
|
24
|
+
data = {
|
|
25
|
+
client_id: credencialConfig.devUser,
|
|
26
|
+
client_secret: credencialConfig.devKey,
|
|
27
|
+
grant_type: 'client_credentials'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const env = process.env.NODE_ENV || DEFAULT_ENV
|
|
32
|
+
try {
|
|
33
|
+
data = {
|
|
34
|
+
client_id: credencialConfig[env].devUser,
|
|
35
|
+
client_secret: credencialConfig[env].devKey,
|
|
36
|
+
grant_type: 'client_credentials'
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
|
|
41
|
+
const errorMessage = `Configurações do ambiente (NODE_ENV=${env}) não definidas`
|
|
42
|
+
if(process.env.LOG_LEVEL === 'full') {
|
|
43
|
+
console.error(errorMessage, e)
|
|
44
|
+
} else {
|
|
45
|
+
console.error(errorMessage)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exit(1)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return data
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async getToken() {
|
|
56
|
+
if(this.token)
|
|
57
|
+
return this.token
|
|
58
|
+
|
|
59
|
+
const clientCredentials = this.readClientCredentials()
|
|
60
|
+
try {
|
|
61
|
+
const url = `${this.blindGuardianUrl}/v1/o/auth`
|
|
62
|
+
const options = {
|
|
63
|
+
headers : {
|
|
64
|
+
'User-Agent': config.get('userAgent')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const auth = await axios.post(url, clientCredentials, options)
|
|
68
|
+
this.token = auth.data
|
|
69
|
+
return this.token
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (this.verbose) {
|
|
72
|
+
console.log(e)
|
|
73
|
+
}
|
|
74
|
+
if (e.isAxiosError) {
|
|
75
|
+
if (e.response && e.response.status === 403) {
|
|
76
|
+
throw new Error('Credencial inválida')
|
|
77
|
+
}
|
|
78
|
+
throw new Error('Por favor tente novamente mais tarde.')
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_isOldProfileVersion(credentialConfig) {
|
|
84
|
+
return (credentialConfig.devKey || credentialConfig.devUser) ? true : false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = AuthConfig
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const axios = require('axios')
|
|
5
|
+
const config = require('config')
|
|
6
|
+
const { exit } = require('process')
|
|
7
|
+
const AmeCredential = require('../util/UserLocalCredential')
|
|
8
|
+
const UserLocalCredential = require('../util/UserLocalCredential')
|
|
9
|
+
|
|
10
|
+
const DEFAULT_ENV = 'hml'
|
|
11
|
+
|
|
12
|
+
class BlindGuardian {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.blindGuardianUrl = config.get('blindGuardian').url
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use UserLocalCredential._getConfigPath
|
|
19
|
+
*/
|
|
20
|
+
getConfPath() {
|
|
21
|
+
let configPath = path.resolve(
|
|
22
|
+
os.homedir(),
|
|
23
|
+
config.get('signup').get('configFilePath')
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return configPath
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
readConf() {
|
|
30
|
+
const ameCredencial = new AmeCredential()
|
|
31
|
+
if (
|
|
32
|
+
process.env.AME_CLI_CLIENT_ID &&
|
|
33
|
+
process.env.AME_CLI_CLIENT_SECRET
|
|
34
|
+
) {
|
|
35
|
+
return {
|
|
36
|
+
devUser: process.env.AME_CLI_CLIENT_ID,
|
|
37
|
+
devKey: process.env.AME_CLI_CLIENT_SECRET,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return new UserLocalCredential()._getNewConfigPath()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
readClientCredentials() {
|
|
44
|
+
const credencialConfig = this.readConf()
|
|
45
|
+
let data
|
|
46
|
+
if (this._isOldProfileVersion(credencialConfig)) {
|
|
47
|
+
data = {
|
|
48
|
+
client_id: credencialConfig.devUser,
|
|
49
|
+
client_secret: credencialConfig.devKey,
|
|
50
|
+
grant_type: 'client_credentials',
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const env = process.env.NODE_ENV || DEFAULT_ENV
|
|
54
|
+
try {
|
|
55
|
+
data = {
|
|
56
|
+
client_id: credencialConfig[env].devUser,
|
|
57
|
+
client_secret: credencialConfig[env].devKey,
|
|
58
|
+
grant_type: 'client_credentials',
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
const errorMessage = `Configurações do ambiente (NODE_ENV=${env}) não definidas`
|
|
62
|
+
if (process.env.LOG_LEVEL === 'full') {
|
|
63
|
+
console.error(errorMessage, e)
|
|
64
|
+
} else {
|
|
65
|
+
console.error(errorMessage)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exit(1)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return data
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getToken() {
|
|
76
|
+
if (this.token) return this.token
|
|
77
|
+
|
|
78
|
+
const clientCredentials = this.readClientCredentials()
|
|
79
|
+
try {
|
|
80
|
+
const url = `${this.blindGuardianUrl}/v1/o/auth`
|
|
81
|
+
const options = {
|
|
82
|
+
headers: {
|
|
83
|
+
'User-Agent': config.get('userAgent'),
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
const auth = await axios.post(url, clientCredentials, options)
|
|
87
|
+
this.token = auth.data
|
|
88
|
+
return this.token
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if (this.verbose) {
|
|
91
|
+
console.log(e)
|
|
92
|
+
}
|
|
93
|
+
if (e.isAxiosError) {
|
|
94
|
+
if (e.response && e.response.status === 403) {
|
|
95
|
+
throw new Error('Credencial inválida')
|
|
96
|
+
}
|
|
97
|
+
throw new Error('Por favor tente novamente mais tarde.')
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async createUser(userVo) {
|
|
104
|
+
try {
|
|
105
|
+
const url = `${this.blindGuardianUrl}/v1/o/users`
|
|
106
|
+
const options = {
|
|
107
|
+
headers: {
|
|
108
|
+
'User-Agent': config.get('userAgent'),
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
const auth = await axios.post(url, userVo, options)
|
|
112
|
+
return auth.data
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (process.env.LOG_LEVEL) {
|
|
115
|
+
console.log(e)
|
|
116
|
+
}
|
|
117
|
+
if (e.isAxiosError) {
|
|
118
|
+
if (e.response && e.response.status === 403) {
|
|
119
|
+
throw new Error('Credencial inválida')
|
|
120
|
+
}
|
|
121
|
+
throw new Error('Por favor tente novamente mais tarde.')
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
_isOldProfileVersion(credentialConfig) {
|
|
128
|
+
return credentialConfig.devKey || credentialConfig.devUser
|
|
129
|
+
? true
|
|
130
|
+
: false
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = BlindGuardian
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const TrackingEitriAnalytics = require('./TrackingEitriAnalytics')
|
|
2
|
+
const UserLocalCredential = require('../util/UserLocalCredential')
|
|
3
|
+
|
|
4
|
+
class CliLogin {
|
|
5
|
+
|
|
6
|
+
async saveCredentials({email, credential}) {
|
|
7
|
+
|
|
8
|
+
let devUser = "", devKey = ""
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const developerKeyDecodec = atob(credential || "")
|
|
12
|
+
const developerKeyParsed = JSON.parse(developerKeyDecodec)
|
|
13
|
+
|
|
14
|
+
if (!developerKeyParsed?.clientId || !developerKeyParsed?.clientSecret) {
|
|
15
|
+
throw new Error("invalid_credential_format")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
devUser = developerKeyParsed?.clientId
|
|
19
|
+
devKey = developerKeyParsed?.clientSecret
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("\n", "Não foi possível realizar o seu login. Por favor, verique as credenciais.")
|
|
22
|
+
TrackingEitriAnalytics.sendEvent({
|
|
23
|
+
command: "login",
|
|
24
|
+
success: false,
|
|
25
|
+
errorMessage: error?.message
|
|
26
|
+
})
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log("\n", "Eis que a jornada tem início...")
|
|
31
|
+
|
|
32
|
+
await new UserLocalCredential().asyncSaveContent({devUser, devKey})
|
|
33
|
+
TrackingEitriAnalytics.sendEvent({
|
|
34
|
+
command: "login",
|
|
35
|
+
success: true,
|
|
36
|
+
data: {
|
|
37
|
+
email,
|
|
38
|
+
devUser
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
console.log("\n", `✔ Triunfo! O acesso foi concedido! Você está logado como ${email}.`)
|
|
42
|
+
process.exit(0)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = CliLogin
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const config = require('config')
|
|
2
|
+
const {workspace} = require('../service/Workspace')
|
|
3
|
+
|
|
4
|
+
class ConfigService {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.configuration = config
|
|
7
|
+
if(workspace.isRollout()) {
|
|
8
|
+
this.configuration = require(`../../config/${process.env.NODE_ENV}`)
|
|
9
|
+
this.configuration.get = (key) => {
|
|
10
|
+
return this.configuration[key]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = new ConfigService().configuration
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const config = require('config')
|
|
2
|
+
|
|
3
|
+
class CredentialsService {
|
|
4
|
+
|
|
5
|
+
constructor(workspace) {
|
|
6
|
+
this.workspace = workspace
|
|
7
|
+
this.conf = config.get('workspace')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async upsert(args) {
|
|
11
|
+
const credential = args.credential
|
|
12
|
+
|
|
13
|
+
if (!credential) {
|
|
14
|
+
throw new Error('Nao foram fornecidas credenciais.')
|
|
15
|
+
}
|
|
16
|
+
if (!credential.clientId) {
|
|
17
|
+
throw new Error('Nao foi fornecido client_id')
|
|
18
|
+
}
|
|
19
|
+
if (!credential.clientSecret) {
|
|
20
|
+
throw new Error('Nao foi fornecido client_secret')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
credential.grantType = this.conf.credentials.defaultGrantType
|
|
24
|
+
|
|
25
|
+
let publicKey = this.workspace.getMiniConf()['public-key']
|
|
26
|
+
let ultimatePath = this.conf.credentials.upsertUrlPath.replace(':publicKey', publicKey)
|
|
27
|
+
let url = `${this.conf.url}/${ultimatePath}`
|
|
28
|
+
|
|
29
|
+
await this.workspace.http.put(url, credential)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async createApproval(args) {
|
|
33
|
+
const approver = args.generate
|
|
34
|
+
|
|
35
|
+
if (!approver) {
|
|
36
|
+
throw new Error('Nao foi fornecido aprovador')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let publicKey = this.workspace.getMiniConf()['public-key']
|
|
40
|
+
let ultimatePath = this.conf.credentials.approvalUrlPath
|
|
41
|
+
let url = `${this.conf.url}/${ultimatePath}`
|
|
42
|
+
await this.workspace.http.post(url, { approver, publicKey })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = CredentialsService
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { workspace } = require('./Workspace')
|
|
2
|
+
|
|
3
|
+
const mobile = workspace.getKnownAvailableTargets()[0].code
|
|
4
|
+
|
|
5
|
+
const setMobileLibs2GA = (miniConf) => {
|
|
6
|
+
return {
|
|
7
|
+
superClientVersion: miniConf['eitri-app-client'],
|
|
8
|
+
componentsVersion: miniConf['eitri-app-components']
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const MINIAPP_TARGET = {
|
|
13
|
+
[mobile]: setMobileLibs2GA
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = MINIAPP_TARGET
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const {hashElement} = require('folder-hash')
|
|
4
|
+
|
|
5
|
+
class HashFolder {
|
|
6
|
+
async calculate() {
|
|
7
|
+
const options = {
|
|
8
|
+
folders: {exclude: ['.*', 'node_modules', 'test_coverage']},
|
|
9
|
+
files: {
|
|
10
|
+
include: [
|
|
11
|
+
'*.js',
|
|
12
|
+
'*.jsx',
|
|
13
|
+
'*.json',
|
|
14
|
+
'*.svg',
|
|
15
|
+
'*.png',
|
|
16
|
+
'*.jpg',
|
|
17
|
+
'*.jpeg',
|
|
18
|
+
'*.gif',
|
|
19
|
+
'*.txt',
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
// let start = new Date().getTime();
|
|
24
|
+
const result = await hashElement(path.join(process.cwd(), 'src'), options)
|
|
25
|
+
// console.log(`${new Date().getTime() - start}ms`);
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
writeHashFile(oldContent, content) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
fs.writeFile(
|
|
32
|
+
path.join(process.cwd(), 'src/folder.hash'),
|
|
33
|
+
`${oldContent}\n${content}`,
|
|
34
|
+
(err) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
console.log(err)
|
|
37
|
+
return reject(err)
|
|
38
|
+
}
|
|
39
|
+
resolve()
|
|
40
|
+
},
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
readHashFile() {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const fileName = path.join(process.cwd(), 'src/folder.hash')
|
|
48
|
+
if (!fs.existsSync(fileName)) {
|
|
49
|
+
resolve(null)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
fs.readFile(fileName, 'utf8', (err, data) => {
|
|
53
|
+
if (err) {
|
|
54
|
+
reject(err)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
resolve(data)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async readCurrentHash() {
|
|
63
|
+
const current = await this.readHashFile()
|
|
64
|
+
if (!current) {
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
return current.split('\n').pop()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async updateHashFile() {
|
|
71
|
+
const res = await this.calculate()
|
|
72
|
+
const current = await this.readCurrentHash()
|
|
73
|
+
if (current !== res['hash']) {
|
|
74
|
+
await this.writeHashFile(current, res['hash'])
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = HashFolder
|