@dotenvx/dotenvx 1.72.0 → 1.73.1
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 +15 -1
- package/README.md +1 -1
- package/package.json +1 -2
- package/src/cli/actions/armor/down.js +37 -0
- package/src/cli/actions/armor/move.js +42 -0
- package/src/cli/actions/armor/pull.js +37 -0
- package/src/cli/actions/armor/push.js +37 -0
- package/src/cli/actions/armor/up.js +37 -0
- package/src/cli/actions/login.js +0 -1
- package/src/cli/commands/armor.js +72 -0
- package/src/cli/dotenvx.js +3 -0
- package/src/db/session.js +90 -22
- package/src/lib/api/getAccount.js +32 -0
- package/src/lib/api/postArmorDown.js +48 -0
- package/src/lib/api/postArmorMove.js +48 -0
- package/src/lib/api/postArmorPull.js +48 -0
- package/src/lib/api/postArmorPush.js +48 -0
- package/src/lib/api/postArmorUp.js +51 -0
- package/src/lib/api/postKeypair.js +60 -0
- package/src/lib/helpers/armoredKeyDisplay.js +10 -0
- package/src/lib/helpers/cryptography/armorKeypair.js +32 -11
- package/src/lib/helpers/cryptography/armorKeypairSync.js +48 -7
- package/src/lib/helpers/cryptography/provision.js +2 -2
- package/src/lib/helpers/cryptography/provisionSync.js +2 -2
- package/src/lib/helpers/keyResolution/index.js +1 -1
- package/src/lib/helpers/keyResolution/{keyNames.js → keyNamesForEnvFile.js} +2 -2
- package/src/lib/helpers/keyResolution/keyValues.js +2 -2
- package/src/lib/helpers/keyResolution/keyValuesSync.js +2 -2
- package/src/lib/helpers/keypairMetadata.js +77 -0
- package/src/lib/helpers/readEnvKey.js +31 -0
- package/src/lib/helpers/removeEnvKey.js +50 -0
- package/src/lib/helpers/sanitizeCommandForMetadata.js +64 -0
- package/src/lib/helpers/teamChoicesFromMeta.js +8 -0
- package/src/lib/helpers/upsertEnvKey.js +61 -0
- package/src/lib/services/armorDown.js +71 -0
- package/src/lib/services/armorKeypair.js +156 -0
- package/src/lib/services/armorMove.js +54 -0
- package/src/lib/services/armorPull.js +71 -0
- package/src/lib/services/armorPush.js +76 -0
- package/src/lib/services/armorUp.js +73 -0
- package/src/lib/services/decrypt.js +2 -2
- package/src/lib/services/encrypt.js +2 -2
- package/src/lib/services/keypair.js +5 -7
- package/src/lib/services/loginPoll.js +1 -0
- package/src/lib/services/rotate.js +2 -2
- package/src/lib/services/run.js +3 -3
- package/src/lib/services/sets.js +3 -3
- package/src/lib/extensions/armor.js +0 -204
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
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/compare/v1.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.73.1...main)
|
|
6
|
+
|
|
7
|
+
## [1.73.1](https://github.com/dotenvx/dotenvx/compare/v1.73.0...v1.73.1) (2026-06-16)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* Give update available notification only for armor commands ([#840](https://github.com/dotenvx/dotenvx/pull/840))
|
|
12
|
+
|
|
13
|
+
## [1.73.0](https://github.com/dotenvx/dotenvx/compare/v1.72.0...v1.73.0) (2026-06-16)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* Add `dotenvx armor` commands directly inside dotenvx ([#839](https://github.com/dotenvx/dotenvx/pull/839))
|
|
18
|
+
|
|
19
|
+
> `dotenvx` remains local-first: `armor` commands are optional under professional security section
|
|
6
20
|
|
|
7
21
|
## [1.72.0](https://github.com/dotenvx/dotenvx/compare/v1.71.3...v1.72.0) (2026-06-15)
|
|
8
22
|
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
### Quickstart [](https://www.npmjs.com/package/@dotenvx/dotenvx) [](https://www.npmjs.com/package/@dotenvx/dotenvx)
|
|
14
|
+
### Quickstart [](https://www.npmjs.com/package/@dotenvx/dotenvx) [](https://www.npmjs.com/package/@dotenvx/dotenvx)
|
|
15
15
|
|
|
16
16
|
Install and use it in code just like `dotenv`.
|
|
17
17
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.73.1",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a secure dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"standard": "standard",
|
|
37
37
|
"standard:fix": "standard --fix",
|
|
38
38
|
"test": "tap run --test-env=DOTENVX_NO_ARMOR=true --allow-empty-coverage --disable-coverage --timeout=60000",
|
|
39
|
-
"test-coverage": "tap run --test-env=DOTENVX_NO_ARMOR=true --show-full-coverage --timeout=60000",
|
|
40
39
|
"testshell": "bash shellspec",
|
|
41
40
|
"release:check": "npm test && npm run testshell",
|
|
42
41
|
"prerelease": "npm run release:check",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { logger } = require('../../../shared/logger')
|
|
2
|
+
const Session = require('./../../../db/session')
|
|
3
|
+
const ArmorDown = require('./../../../lib/services/armorDown')
|
|
4
|
+
const createSpinner = require('../../../lib/helpers/createSpinner')
|
|
5
|
+
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
+
|
|
7
|
+
async function down () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
const spinner = await createSpinner({ ...options, text: 'dearmoring' })
|
|
10
|
+
|
|
11
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
+
|
|
13
|
+
const sesh = new Session()
|
|
14
|
+
await sesh.notifyUpdate()
|
|
15
|
+
const hostname = options.hostname || sesh.hostname()
|
|
16
|
+
const token = options.token || sesh.token()
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
20
|
+
|
|
21
|
+
const { changed, privateKeyName, publicKeyValue } = await new ArmorDown(hostname, token, devicePublicKey, options.envFile, options.team).run()
|
|
22
|
+
const keyDisplay = armoredKeyDisplay(publicKeyValue) || privateKeyName
|
|
23
|
+
|
|
24
|
+
if (spinner) spinner.stop()
|
|
25
|
+
if (changed) {
|
|
26
|
+
logger.success(`◇ dearmored to .env.keys (${keyDisplay})`)
|
|
27
|
+
} else {
|
|
28
|
+
logger.info(`○ no change (${keyDisplay})`)
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (spinner) spinner.stop()
|
|
32
|
+
logger.error(error.message)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = down
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const { logger } = require('../../../shared/logger')
|
|
2
|
+
const Session = require('./../../../db/session')
|
|
3
|
+
const ArmorMove = require('./../../../lib/services/armorMove')
|
|
4
|
+
const createSpinner = require('../../../lib/helpers/createSpinner')
|
|
5
|
+
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
+
|
|
7
|
+
async function move () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
const spinner = await createSpinner({ ...options, text: 'moving' })
|
|
10
|
+
|
|
11
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
+
|
|
13
|
+
const sesh = new Session()
|
|
14
|
+
await sesh.notifyUpdate()
|
|
15
|
+
const hostname = options.hostname || sesh.hostname()
|
|
16
|
+
const token = options.token || sesh.token()
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
changed,
|
|
23
|
+
privateKeyName,
|
|
24
|
+
publicKeyValue,
|
|
25
|
+
team
|
|
26
|
+
} = await new ArmorMove(hostname, token, devicePublicKey, options.envFile).run()
|
|
27
|
+
const keyDisplay = armoredKeyDisplay(publicKeyValue) || privateKeyName
|
|
28
|
+
|
|
29
|
+
if (spinner) spinner.stop()
|
|
30
|
+
if (changed) {
|
|
31
|
+
logger.success(`⛨ moved to ${team} (${keyDisplay})`)
|
|
32
|
+
} else {
|
|
33
|
+
logger.info(`○ no change (${keyDisplay})`)
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (spinner) spinner.stop()
|
|
37
|
+
logger.error(error.message)
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = move
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { logger } = require('../../../shared/logger')
|
|
2
|
+
const Session = require('./../../../db/session')
|
|
3
|
+
const ArmorPull = require('./../../../lib/services/armorPull')
|
|
4
|
+
const createSpinner = require('../../../lib/helpers/createSpinner')
|
|
5
|
+
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
+
|
|
7
|
+
async function pull () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
const spinner = await createSpinner({ ...options, text: 'pulling' })
|
|
10
|
+
|
|
11
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
+
|
|
13
|
+
const sesh = new Session()
|
|
14
|
+
await sesh.notifyUpdate()
|
|
15
|
+
const hostname = options.hostname || sesh.hostname()
|
|
16
|
+
const token = options.token || sesh.token()
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
20
|
+
|
|
21
|
+
const { changed, privateKeyName, publicKeyValue } = await new ArmorPull(hostname, token, devicePublicKey, options.envFile, options.team).run()
|
|
22
|
+
const keyDisplay = armoredKeyDisplay(publicKeyValue) || privateKeyName
|
|
23
|
+
|
|
24
|
+
if (spinner) spinner.stop()
|
|
25
|
+
if (changed) {
|
|
26
|
+
logger.success(`◇ pulled to .env.keys (${keyDisplay})`)
|
|
27
|
+
} else {
|
|
28
|
+
logger.info(`○ no change (${keyDisplay})`)
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (spinner) spinner.stop()
|
|
32
|
+
logger.error(error.message)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = pull
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { logger } = require('../../../shared/logger')
|
|
2
|
+
const Session = require('./../../../db/session')
|
|
3
|
+
const ArmorPush = require('./../../../lib/services/armorPush')
|
|
4
|
+
const createSpinner = require('../../../lib/helpers/createSpinner')
|
|
5
|
+
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
+
|
|
7
|
+
async function push () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
const spinner = await createSpinner({ ...options, text: 'pushing' })
|
|
10
|
+
|
|
11
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
+
|
|
13
|
+
const sesh = new Session()
|
|
14
|
+
await sesh.notifyUpdate()
|
|
15
|
+
const hostname = options.hostname || sesh.hostname()
|
|
16
|
+
const token = options.token || sesh.token()
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
20
|
+
|
|
21
|
+
const { changed, privateKeyName, publicKeyValue } = await new ArmorPush(hostname, token, devicePublicKey, options.envFile, options.team).run()
|
|
22
|
+
const keyDisplay = armoredKeyDisplay(publicKeyValue) || privateKeyName
|
|
23
|
+
|
|
24
|
+
if (spinner) spinner.stop()
|
|
25
|
+
if (changed) {
|
|
26
|
+
logger.success(`⛨ pushed (${keyDisplay})`)
|
|
27
|
+
} else {
|
|
28
|
+
logger.info(`○ no change (${keyDisplay})`)
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (spinner) spinner.stop()
|
|
32
|
+
logger.error(error.message)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = push
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { logger } = require('../../../shared/logger')
|
|
2
|
+
const Session = require('./../../../db/session')
|
|
3
|
+
const ArmorUp = require('./../../../lib/services/armorUp')
|
|
4
|
+
const createSpinner = require('../../../lib/helpers/createSpinner')
|
|
5
|
+
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
+
|
|
7
|
+
async function up () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
const spinner = await createSpinner({ ...options, text: 'armoring' })
|
|
10
|
+
|
|
11
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
+
|
|
13
|
+
const sesh = new Session()
|
|
14
|
+
await sesh.notifyUpdate()
|
|
15
|
+
const hostname = options.hostname || sesh.hostname()
|
|
16
|
+
const token = options.token || sesh.token()
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
20
|
+
|
|
21
|
+
const { changed, privateKeyName, publicKeyValue } = await new ArmorUp(hostname, token, devicePublicKey, options.envFile, options.team).run()
|
|
22
|
+
const keyDisplay = armoredKeyDisplay(publicKeyValue) || privateKeyName
|
|
23
|
+
|
|
24
|
+
if (spinner) spinner.stop()
|
|
25
|
+
if (changed) {
|
|
26
|
+
logger.success(`⛨ armored (${keyDisplay})`)
|
|
27
|
+
} else {
|
|
28
|
+
logger.info(`○ no change (${keyDisplay})`)
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (spinner) spinner.stop()
|
|
32
|
+
logger.error(error.message)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = up
|
package/src/cli/actions/login.js
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const executeDynamic = require('./../../lib/helpers/executeDynamic')
|
|
2
|
+
const Session = require('./../../db/session')
|
|
3
|
+
|
|
4
|
+
function configureArmorCommand (armor) {
|
|
5
|
+
armor
|
|
6
|
+
.description('move private keys off-device')
|
|
7
|
+
.allowUnknownOption()
|
|
8
|
+
.argument('[command]', 'dotenvx-armor command')
|
|
9
|
+
.argument('[args...]', 'dotenvx-armor command arguments')
|
|
10
|
+
.action(async function (command, args) {
|
|
11
|
+
if (command) {
|
|
12
|
+
return executeDynamic(armor, 'armor', [command, ...(args || [])])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const sesh = new Session()
|
|
16
|
+
await sesh.notifyUpdate()
|
|
17
|
+
this.help()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// dotenvx armor up
|
|
21
|
+
const upAction = require('./../actions/armor/up')
|
|
22
|
+
armor
|
|
23
|
+
.command('up')
|
|
24
|
+
.description('armor key')
|
|
25
|
+
.option('-f, --env-file <path>', 'path to your env file')
|
|
26
|
+
.option('--token <token>', 'set token')
|
|
27
|
+
.option('--team <team>', 'team to armor private key for')
|
|
28
|
+
.action(upAction)
|
|
29
|
+
|
|
30
|
+
// dotenvx armor down
|
|
31
|
+
const downAction = require('./../actions/armor/down')
|
|
32
|
+
armor
|
|
33
|
+
.command('down')
|
|
34
|
+
.description('dearmor key')
|
|
35
|
+
.option('-f, --env-file <path>', 'path to your env file')
|
|
36
|
+
.option('--token <token>', 'set token')
|
|
37
|
+
.option('--team <team>', 'team to dearmor private key from')
|
|
38
|
+
.action(downAction)
|
|
39
|
+
|
|
40
|
+
// dotenvx armor push
|
|
41
|
+
const pushAction = require('./../actions/armor/push')
|
|
42
|
+
armor
|
|
43
|
+
.command('push')
|
|
44
|
+
.description('push armored key (from .env.keys)')
|
|
45
|
+
.option('-f, --env-file <path>', 'path to your env file')
|
|
46
|
+
.option('--token <token>', 'set token')
|
|
47
|
+
.option('--team <team>', 'team to push armored private key for')
|
|
48
|
+
.action(pushAction)
|
|
49
|
+
|
|
50
|
+
// dotenvx armor pull
|
|
51
|
+
const pullAction = require('./../actions/armor/pull')
|
|
52
|
+
armor
|
|
53
|
+
.command('pull')
|
|
54
|
+
.description('pull armored key (into .env.keys)')
|
|
55
|
+
.option('-f, --env-file <path>', 'path to your env file')
|
|
56
|
+
.option('--token <token>', 'set token')
|
|
57
|
+
.option('--team <team>', 'team to pull armored private key from')
|
|
58
|
+
.action(pullAction)
|
|
59
|
+
|
|
60
|
+
// dotenvx armor move
|
|
61
|
+
const moveAction = require('./../actions/armor/move')
|
|
62
|
+
armor
|
|
63
|
+
.command('move')
|
|
64
|
+
.description('move armored key (to other team)')
|
|
65
|
+
.option('-f, --env-file <path>', 'path to your env file')
|
|
66
|
+
.option('--token <token>', 'set token')
|
|
67
|
+
.action(moveAction)
|
|
68
|
+
|
|
69
|
+
return armor
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = configureArmorCommand
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -244,6 +244,9 @@ program.addHelpText('after', ' logout log out of connected se
|
|
|
244
244
|
program.addHelpText('after', ' armor ⛨ move private keys off-device [www.dotenvx.com/armor]')
|
|
245
245
|
program.addHelpText('after', ' ext ⊕ extensions')
|
|
246
246
|
|
|
247
|
+
// dotenvx armor
|
|
248
|
+
require('./commands/armor')(program.command('armor', { hidden: true }))
|
|
249
|
+
|
|
247
250
|
// dotenvx ext
|
|
248
251
|
program.addCommand(require('./commands/ext'))
|
|
249
252
|
|
package/src/db/session.js
CHANGED
|
@@ -4,23 +4,51 @@ const Conf = require('conf')
|
|
|
4
4
|
const dotenv = require('dotenv')
|
|
5
5
|
const envPaths = require('env-paths')
|
|
6
6
|
|
|
7
|
-
const Armor = require('./../lib/extensions/armor')
|
|
8
7
|
const jsonToEnv = require('./../lib/helpers/jsonToEnv')
|
|
8
|
+
const packageJson = require('./../lib/helpers/packageJson')
|
|
9
|
+
const { http } = require('./../lib/helpers/http')
|
|
9
10
|
const { logger } = require('./../shared/logger')
|
|
10
11
|
|
|
12
|
+
const HOURS_24 = 60 * 60 * 24 * 1000
|
|
13
|
+
const VERSION_URL = 'https://dotenvx.sh/VERSION'
|
|
14
|
+
|
|
11
15
|
const ARMOR = {
|
|
12
16
|
HOSTNAME: 'DOTENVX_ARMOR_HOSTNAME',
|
|
13
17
|
USER: 'DOTENVX_ARMOR_USER',
|
|
14
18
|
USERNAME: 'DOTENVX_ARMOR_USERNAME',
|
|
15
|
-
TOKEN: 'DOTENVX_ARMOR_TOKEN'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
TOKEN: 'DOTENVX_ARMOR_TOKEN'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DOTENVX = {
|
|
23
|
+
VERSION: 'DOTENVX_VERSION',
|
|
24
|
+
VERSION_LAST_CHECK: 'DOTENVX_VERSION_LAST_CHECK'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeVersion (version) {
|
|
28
|
+
return String(version || '').trim().replace(/^v/, '')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseVersion (version) {
|
|
32
|
+
return normalizeVersion(version).split('.').map(part => Number.parseInt(part, 10) || 0)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function versionGreaterThan (left, right) {
|
|
36
|
+
const leftParts = parseVersion(left)
|
|
37
|
+
const rightParts = parseVersion(right)
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < Math.max(leftParts.length, rightParts.length); i++) {
|
|
40
|
+
const leftPart = leftParts[i] || 0
|
|
41
|
+
const rightPart = rightParts[i] || 0
|
|
42
|
+
|
|
43
|
+
if (leftPart > rightPart) return true
|
|
44
|
+
if (leftPart < rightPart) return false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false
|
|
19
48
|
}
|
|
20
49
|
|
|
21
50
|
class Session {
|
|
22
51
|
constructor () {
|
|
23
|
-
this.armor = new Armor()
|
|
24
52
|
this._store = null
|
|
25
53
|
}
|
|
26
54
|
|
|
@@ -74,7 +102,7 @@ class Session {
|
|
|
74
102
|
|
|
75
103
|
status () {
|
|
76
104
|
// if logged in
|
|
77
|
-
if (this.username() && this.token()
|
|
105
|
+
if (this.username() && this.token()) {
|
|
78
106
|
return 'on'
|
|
79
107
|
}
|
|
80
108
|
|
|
@@ -91,6 +119,13 @@ class Session {
|
|
|
91
119
|
return store.get(ARMOR[key])
|
|
92
120
|
}
|
|
93
121
|
|
|
122
|
+
readDotenvxSetting (key) {
|
|
123
|
+
const store = this.openStore()
|
|
124
|
+
if (!store) return undefined
|
|
125
|
+
|
|
126
|
+
return store.get(DOTENVX[key])
|
|
127
|
+
}
|
|
128
|
+
|
|
94
129
|
hostname () {
|
|
95
130
|
return this.readSetting('HOSTNAME') || 'https://armor.dotenvx.com'
|
|
96
131
|
}
|
|
@@ -112,14 +147,6 @@ class Session {
|
|
|
112
147
|
return this._store ? this._store.path : this._configPath()
|
|
113
148
|
}
|
|
114
149
|
|
|
115
|
-
on () {
|
|
116
|
-
return (this.readSetting('ON') || 'true') === 'true'
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
off () {
|
|
120
|
-
return (this.readSetting('ON') || 'true') === 'false'
|
|
121
|
-
}
|
|
122
|
-
|
|
123
150
|
async systemInformation () {
|
|
124
151
|
const si = require('systeminformation')
|
|
125
152
|
const system = await si.system()
|
|
@@ -132,21 +159,64 @@ class Session {
|
|
|
132
159
|
}
|
|
133
160
|
}
|
|
134
161
|
|
|
162
|
+
//
|
|
163
|
+
// Notify Update
|
|
164
|
+
//
|
|
135
165
|
async notifyUpdate () {
|
|
136
|
-
|
|
166
|
+
try {
|
|
167
|
+
const store = this.openStore()
|
|
168
|
+
if (!store) return
|
|
169
|
+
|
|
170
|
+
logger.debug('checking if update available')
|
|
171
|
+
|
|
172
|
+
const lastCheck = Number(this.readDotenvxSetting('VERSION_LAST_CHECK') || 0)
|
|
173
|
+
const now = Date.now()
|
|
174
|
+
|
|
175
|
+
if ((lastCheck + HOURS_24) >= now) return
|
|
176
|
+
|
|
177
|
+
let remote = packageJson.version
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
logger.debug('fetching latest available dotenvx version')
|
|
181
|
+
const response = await http(VERSION_URL)
|
|
182
|
+
remote = normalizeVersion(await response.body.text())
|
|
183
|
+
logger.debug(`latest dotenvx version: ${remote}`)
|
|
184
|
+
store.set(DOTENVX.VERSION, remote)
|
|
185
|
+
} catch (error) {
|
|
186
|
+
logger.debug(error.message)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
store.set(DOTENVX.VERSION_LAST_CHECK, now)
|
|
190
|
+
|
|
191
|
+
if (versionGreaterThan(remote, packageJson.version)) {
|
|
192
|
+
console.error('⛆ update available [npm install @dotenvx/dotenvx@latest]')
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
logger.debug(error.message)
|
|
196
|
+
}
|
|
137
197
|
}
|
|
138
198
|
|
|
139
199
|
//
|
|
140
200
|
// armor status helpers
|
|
141
201
|
//
|
|
142
202
|
async noArmor () {
|
|
143
|
-
|
|
203
|
+
if (process.env.DOTENVX_NO_ARMOR === 'true') {
|
|
204
|
+
logger.debug('armor: off')
|
|
205
|
+
return true
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const status = this.status()
|
|
144
209
|
logger.debug(`armor: ${status}`)
|
|
145
210
|
return status === 'off'
|
|
146
211
|
}
|
|
147
212
|
|
|
148
213
|
noArmorSync () {
|
|
149
|
-
|
|
214
|
+
if (process.env.DOTENVX_NO_ARMOR === 'true') {
|
|
215
|
+
logger.debug('armor: off')
|
|
216
|
+
return true
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const status = this.status()
|
|
150
220
|
logger.debug(`armor: ${status}`)
|
|
151
221
|
return status === 'off'
|
|
152
222
|
}
|
|
@@ -176,7 +246,6 @@ class Session {
|
|
|
176
246
|
store.set(ARMOR.USERNAME, username)
|
|
177
247
|
store.set(ARMOR.TOKEN, accessToken)
|
|
178
248
|
store.set(ARMOR.HOSTNAME, hostname)
|
|
179
|
-
store.set(ARMOR.ON, 'true')
|
|
180
249
|
|
|
181
250
|
return accessToken
|
|
182
251
|
}
|
|
@@ -201,9 +270,8 @@ class Session {
|
|
|
201
270
|
store.delete(ARMOR.USERNAME)
|
|
202
271
|
store.delete(ARMOR.TOKEN)
|
|
203
272
|
store.delete(ARMOR.HOSTNAME)
|
|
204
|
-
store.delete(
|
|
205
|
-
store.delete(
|
|
206
|
-
store.delete(ARMOR.VERSION_LAST_CHECK)
|
|
273
|
+
store.delete(DOTENVX.VERSION)
|
|
274
|
+
store.delete(DOTENVX.VERSION_LAST_CHECK)
|
|
207
275
|
return true
|
|
208
276
|
}
|
|
209
277
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
|
|
4
|
+
class GetAccount {
|
|
5
|
+
constructor (hostname, token) {
|
|
6
|
+
this.hostname = hostname
|
|
7
|
+
this.token = token
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run () {
|
|
11
|
+
const token = this.token
|
|
12
|
+
const url = `${this.hostname}/api/account`
|
|
13
|
+
|
|
14
|
+
const resp = await http(url, {
|
|
15
|
+
method: 'GET',
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${token}`,
|
|
18
|
+
'Content-Type': 'application/json'
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const json = await resp.body.json()
|
|
23
|
+
|
|
24
|
+
if (resp.statusCode >= 400) {
|
|
25
|
+
throw buildApiError(resp.statusCode, json)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return json
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = GetAccount
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const packageJson = require('../helpers/packageJson')
|
|
4
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
5
|
+
|
|
6
|
+
class PostArmorDown {
|
|
7
|
+
constructor (hostname, token, devicePublicKey, publicKey, team) {
|
|
8
|
+
this.hostname = hostname
|
|
9
|
+
this.token = token
|
|
10
|
+
this.devicePublicKey = devicePublicKey
|
|
11
|
+
this.publicKey = publicKey
|
|
12
|
+
this.team = team
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async run () {
|
|
16
|
+
const token = normalizeToken(this.token)
|
|
17
|
+
const devicePublicKey = this.devicePublicKey
|
|
18
|
+
const publicKey = this.publicKey
|
|
19
|
+
const team = this.team
|
|
20
|
+
const url = `${this.hostname}/api/armor/down`
|
|
21
|
+
|
|
22
|
+
const body = {
|
|
23
|
+
device_public_key: devicePublicKey,
|
|
24
|
+
cli_version: packageJson.version,
|
|
25
|
+
public_key: publicKey,
|
|
26
|
+
team
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const resp = await http(url, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
'Content-Type': 'application/json'
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify(body)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const json = await resp.body.json()
|
|
39
|
+
|
|
40
|
+
if (resp.statusCode >= 400) {
|
|
41
|
+
throw buildApiError(resp.statusCode, json)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return json
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = PostArmorDown
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const packageJson = require('../helpers/packageJson')
|
|
4
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
5
|
+
|
|
6
|
+
class PostArmorMove {
|
|
7
|
+
constructor (hostname, token, devicePublicKey, publicKey, team) {
|
|
8
|
+
this.hostname = hostname
|
|
9
|
+
this.token = token
|
|
10
|
+
this.devicePublicKey = devicePublicKey
|
|
11
|
+
this.publicKey = publicKey
|
|
12
|
+
this.team = team
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async run () {
|
|
16
|
+
const token = normalizeToken(this.token)
|
|
17
|
+
const devicePublicKey = this.devicePublicKey
|
|
18
|
+
const publicKey = this.publicKey
|
|
19
|
+
const team = this.team
|
|
20
|
+
const url = `${this.hostname}/api/armor/move`
|
|
21
|
+
|
|
22
|
+
const body = {
|
|
23
|
+
device_public_key: devicePublicKey,
|
|
24
|
+
cli_version: packageJson.version,
|
|
25
|
+
public_key: publicKey,
|
|
26
|
+
team
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const resp = await http(url, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
'Content-Type': 'application/json'
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify(body)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const json = await resp.body.json()
|
|
39
|
+
|
|
40
|
+
if (resp.statusCode >= 400) {
|
|
41
|
+
throw buildApiError(resp.statusCode, json)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return json
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = PostArmorMove
|