@dotenvx/dotenvx-vlt 0.50.1 → 0.51.0
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/CHANGELOG.md +7 -1
- package/package.json +1 -1
- package/src/cli/dotenvx-vlt.js +0 -9
- package/src/cli/actions/backup.js +0 -93
- package/src/lib/api/postBackup.js +0 -68
- package/src/lib/services/backup.js +0 -105
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.51.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.51.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.50.1...v0.51.0) (2026-05-25)
|
|
8
|
+
|
|
9
|
+
### Removed
|
|
10
|
+
|
|
11
|
+
* Remove `backup` command ([#101](https://github.com/dotenvx/dotenvx-ops/pull/101))
|
|
6
12
|
|
|
7
13
|
## [0.50.1](https://github.com/dotenvx/dotenvx-ops/compare/v0.50.0...v0.50.1) (2026-05-25)
|
|
8
14
|
|
package/package.json
CHANGED
package/src/cli/dotenvx-vlt.js
CHANGED
|
@@ -31,15 +31,6 @@ program
|
|
|
31
31
|
.version(packageJson.version)
|
|
32
32
|
.allowUnknownOption()
|
|
33
33
|
|
|
34
|
-
// dotenvx-vlt backup
|
|
35
|
-
const backupAction = require('./actions/backup')
|
|
36
|
-
program
|
|
37
|
-
.command('backup')
|
|
38
|
-
.description('[INTERNAL] back up .env.keys')
|
|
39
|
-
.option('--org <organizationSlug>')
|
|
40
|
-
.option('-h, --hostname <url>', 'set hostname')
|
|
41
|
-
.action(backupAction)
|
|
42
|
-
|
|
43
34
|
// dotenvx-vlt open
|
|
44
35
|
const openAction = require('./actions/open')
|
|
45
36
|
program
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
|
|
3
|
-
const { logger } = require('@dotenvx/dotenvx')
|
|
4
|
-
const Session = require('./../../db/session')
|
|
5
|
-
|
|
6
|
-
const { createSpinner } = require('./../../lib/helpers/createSpinner')
|
|
7
|
-
const clipboardy = require('./../../lib/helpers/clipboardy')
|
|
8
|
-
const confirm = require('./../../lib/helpers/confirm')
|
|
9
|
-
const formatCode = require('./../../lib/helpers/formatCode')
|
|
10
|
-
const truncate = require('./../../lib/helpers/truncate')
|
|
11
|
-
const openUrl = require('./../../lib/helpers/openUrl')
|
|
12
|
-
|
|
13
|
-
const LoggedIn = require('./../../lib/services/loggedIn')
|
|
14
|
-
const Login = require('./../../lib/services/login')
|
|
15
|
-
const LoginPoll = require('./../../lib/services/loginPoll')
|
|
16
|
-
const Backup = require('./../../lib/services/backup')
|
|
17
|
-
|
|
18
|
-
const spinner = createSpinner('waiting on browser authorization')
|
|
19
|
-
|
|
20
|
-
async function backup () {
|
|
21
|
-
const options = this.opts()
|
|
22
|
-
|
|
23
|
-
const sesh = new Session()
|
|
24
|
-
const hostname = options.hostname || sesh.hostname()
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
28
|
-
|
|
29
|
-
const loggedIn = await new LoggedIn(hostname).run()
|
|
30
|
-
if (!loggedIn) {
|
|
31
|
-
const {
|
|
32
|
-
deviceCode,
|
|
33
|
-
userCode,
|
|
34
|
-
verificationUri,
|
|
35
|
-
verificationUriComplete,
|
|
36
|
-
interval
|
|
37
|
-
} = await new Login(hostname).run()
|
|
38
|
-
|
|
39
|
-
try { clipboardy.writeSync(userCode) } catch (_e) {}
|
|
40
|
-
|
|
41
|
-
logger.debug(`POST ${hostname} with deviceCode ${deviceCode} at interval ${interval}`)
|
|
42
|
-
logger.info(`press Enter to open [${verificationUri}] and enter code [${formatCode(userCode)}]...`)
|
|
43
|
-
|
|
44
|
-
// begin polling
|
|
45
|
-
const pollPromise = new LoginPoll(hostname, deviceCode, interval).run()
|
|
46
|
-
spinner.start()
|
|
47
|
-
|
|
48
|
-
// optionally allow user to open browser
|
|
49
|
-
confirm({ message: `press Enter to open [${verificationUri}] and enter code [${formatCode(userCode)}]...` })
|
|
50
|
-
.then(answer => answer && openUrl(verificationUriComplete))
|
|
51
|
-
.catch(() => {}) // ignore
|
|
52
|
-
|
|
53
|
-
const data = await pollPromise
|
|
54
|
-
spinner.succeed(`logged in [${data.username}] to this device and activated token [${truncate(data.access_token, 11)}]`)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
spinner.start('backing up')
|
|
58
|
-
|
|
59
|
-
const {
|
|
60
|
-
projectUsernameName,
|
|
61
|
-
projectEnvXSrc,
|
|
62
|
-
projectEnvXFileNeedsWrite
|
|
63
|
-
} = await new Backup(hostname, options.org).run()
|
|
64
|
-
|
|
65
|
-
// write .env.x
|
|
66
|
-
if (projectEnvXFileNeedsWrite) {
|
|
67
|
-
logger.debug('writing .env.x')
|
|
68
|
-
fs.writeFileSync('.env.x', projectEnvXSrc, 'utf8')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
spinner.stop()
|
|
72
|
-
|
|
73
|
-
logger.success(`✔ backed up [${projectUsernameName}]`)
|
|
74
|
-
logger.help('⮕ next run [dotenvx vlt open] to view')
|
|
75
|
-
} catch (error) {
|
|
76
|
-
spinner.stop()
|
|
77
|
-
if (error.message) {
|
|
78
|
-
logger.error(error.message)
|
|
79
|
-
} else {
|
|
80
|
-
logger.error(error)
|
|
81
|
-
}
|
|
82
|
-
if (error.help) {
|
|
83
|
-
logger.help(error.help)
|
|
84
|
-
}
|
|
85
|
-
if (error.stack) {
|
|
86
|
-
logger.debug(error.stack)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
process.exit(1)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
module.exports = backup
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const { http } = require('../../lib/helpers/http')
|
|
2
|
-
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
-
const packageJson = require('../../lib/helpers/packageJson')
|
|
4
|
-
|
|
5
|
-
class PostBackup {
|
|
6
|
-
constructor (hostname, token, devicePublicKey, encoded, dotenvxProjectId = null, org = null, pwd = null, gitUrl = null, gitBranch = null, systemUuid = null, osPlatform = null, osArch = null) {
|
|
7
|
-
this.hostname = hostname || 'https://vlt.dotenvx.com'
|
|
8
|
-
this.token = token
|
|
9
|
-
this.devicePublicKey = devicePublicKey
|
|
10
|
-
this.encoded = encoded
|
|
11
|
-
this.dotenvxProjectId = dotenvxProjectId
|
|
12
|
-
this.org = org
|
|
13
|
-
this.pwd = pwd
|
|
14
|
-
this.gitUrl = gitUrl
|
|
15
|
-
this.gitBranch = gitBranch
|
|
16
|
-
this.systemUuid = systemUuid
|
|
17
|
-
this.osPlatform = osPlatform
|
|
18
|
-
this.osArch = osArch
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async run () {
|
|
22
|
-
const token = this.token
|
|
23
|
-
const devicePublicKey = this.devicePublicKey
|
|
24
|
-
const url = `${this.hostname}/api/backup`
|
|
25
|
-
const encoded = this.encoded
|
|
26
|
-
const dotenvxProjectId = this.dotenvxProjectId
|
|
27
|
-
const org = this.org
|
|
28
|
-
const backedupAt = new Date().toISOString()
|
|
29
|
-
const pwd = this.pwd
|
|
30
|
-
const gitUrl = this.gitUrl
|
|
31
|
-
const gitBranch = this.gitBranch
|
|
32
|
-
const systemUuid = this.systemUuid
|
|
33
|
-
const osPlatform = this.osPlatform
|
|
34
|
-
const osArch = this.osArch
|
|
35
|
-
|
|
36
|
-
const resp = await http(url, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: {
|
|
39
|
-
Authorization: `Bearer ${token}`,
|
|
40
|
-
'Content-Type': 'application/json'
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify({
|
|
43
|
-
device_public_key: devicePublicKey,
|
|
44
|
-
encoded,
|
|
45
|
-
dotenvx_project_id: dotenvxProjectId,
|
|
46
|
-
org,
|
|
47
|
-
backedup_at: backedupAt,
|
|
48
|
-
pwd,
|
|
49
|
-
git_url: gitUrl,
|
|
50
|
-
git_branch: gitBranch,
|
|
51
|
-
system_uuid: systemUuid,
|
|
52
|
-
os_platform: osPlatform,
|
|
53
|
-
os_arch: osArch,
|
|
54
|
-
cli_version: packageJson.version
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const json = await resp.body.json()
|
|
59
|
-
|
|
60
|
-
if (resp.statusCode >= 400) {
|
|
61
|
-
throw buildApiError(resp.statusCode, json)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return json
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = PostBackup
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const si = require('systeminformation')
|
|
4
|
-
const dotenvx = require('@dotenvx/dotenvx')
|
|
5
|
-
const prompts = require('../helpers/prompts')
|
|
6
|
-
|
|
7
|
-
const Session = require('./../../db/session')
|
|
8
|
-
|
|
9
|
-
const gitUrl = require('./../helpers/gitUrl')
|
|
10
|
-
const gitBranch = require('./../helpers/gitBranch')
|
|
11
|
-
const dotenvxProjectId = require('./../helpers/dotenvxProjectId')
|
|
12
|
-
|
|
13
|
-
// api calls
|
|
14
|
-
const GetAccount = require('./../api/getAccount')
|
|
15
|
-
const PostBackup = require('./../api/postBackup')
|
|
16
|
-
|
|
17
|
-
class Backup {
|
|
18
|
-
constructor (hostname, org = null) {
|
|
19
|
-
this.hostname = hostname
|
|
20
|
-
this.org = org
|
|
21
|
-
this.cwd = process.cwd()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async run () {
|
|
25
|
-
const sesh = new Session()
|
|
26
|
-
const token = sesh.token()
|
|
27
|
-
const devicePublicKey = sesh.devicePublicKey()
|
|
28
|
-
let _org = this.org
|
|
29
|
-
let projectEnvXFileNeedsWrite = false
|
|
30
|
-
|
|
31
|
-
// required
|
|
32
|
-
const files = this._files()
|
|
33
|
-
const payload = { files }
|
|
34
|
-
const encoded = Buffer.from(JSON.stringify(payload)).toString('base64')
|
|
35
|
-
|
|
36
|
-
// user must be logged in to use feature
|
|
37
|
-
const accountJson = await new GetAccount(this.hostname, token).run()
|
|
38
|
-
|
|
39
|
-
// optional project id
|
|
40
|
-
const _dotenvxProjectId = dotenvxProjectId(this.cwd, false)
|
|
41
|
-
|
|
42
|
-
// missing .env.x file
|
|
43
|
-
if (!_dotenvxProjectId) {
|
|
44
|
-
projectEnvXFileNeedsWrite = true // for writing
|
|
45
|
-
|
|
46
|
-
// set org
|
|
47
|
-
if (!_org) {
|
|
48
|
-
const choices = accountJson.organizations.map(o => ({
|
|
49
|
-
name: o.provider_slug,
|
|
50
|
-
value: o.provider_slug
|
|
51
|
-
}))
|
|
52
|
-
|
|
53
|
-
if (choices.length === 1) {
|
|
54
|
-
_org = choices[0].value // just use first choice
|
|
55
|
-
} else {
|
|
56
|
-
_org = await prompts.select({
|
|
57
|
-
message: 'Select org',
|
|
58
|
-
choices
|
|
59
|
-
}, {
|
|
60
|
-
input: process.stdin,
|
|
61
|
-
output: process.stderr
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// optional
|
|
68
|
-
const _pwd = this.cwd
|
|
69
|
-
const _gitUrl = gitUrl()
|
|
70
|
-
const _gitBranch = gitBranch()
|
|
71
|
-
|
|
72
|
-
const system = await si.system()
|
|
73
|
-
const _systemUuid = system.uuid
|
|
74
|
-
|
|
75
|
-
const osInfo = await si.osInfo()
|
|
76
|
-
const _osPlatform = osInfo.platform
|
|
77
|
-
const _osArch = osInfo.arch
|
|
78
|
-
|
|
79
|
-
const data = await new PostBackup(this.hostname, token, devicePublicKey, encoded, _dotenvxProjectId, _org, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch).run()
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
id: data.id,
|
|
83
|
-
dotenvxProjectId: data.dotenvx_project_id,
|
|
84
|
-
projectUsernameName: data.project_username_name,
|
|
85
|
-
projectEnvXSrc: data.project_env_x_src,
|
|
86
|
-
projectEnvXFileNeedsWrite,
|
|
87
|
-
files: data.files
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
_files () {
|
|
92
|
-
const out = []
|
|
93
|
-
const filepaths = dotenvx.ls(this.cwd, '.env.keys*')
|
|
94
|
-
|
|
95
|
-
for (const fp of filepaths) {
|
|
96
|
-
const abs = path.join(this.cwd, fp)
|
|
97
|
-
const src = fs.readFileSync(abs, 'utf8')
|
|
98
|
-
out.push({ filepath: fp, src })
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return out
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
module.exports = Backup
|