@dotenvx/dotenvx 2.32.0 → 2.32.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/CHANGELOG.md CHANGED
@@ -2,7 +2,26 @@
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/v2.32.0...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.32.2...main)
6
+
7
+ ## [2.32.2](https://github.com/dotenvx/dotenvx/compare/v2.32.1...v2.32.2) (2026-09-29)
8
+
9
+ ### Changed
10
+
11
+ * Improve bundle size ([#1000](https://github.com/dotenvx/dotenvx/pull/1000))
12
+
13
+ ## [2.32.1](https://github.com/dotenvx/dotenvx/compare/v2.32.0...v2.32.1) (2026-09-29)
14
+
15
+ ### Changed
16
+
17
+ * Simplify custody picker to 3 initial options ([#998](https://github.com/dotenvx/dotenvx/pull/998))
18
+
19
+ ```text
20
+ ? Choose private key custody …
21
+ ❯ ⛉ Local
22
+ ⛨ Dotenvx Armor
23
+ ⛊ Password Managers
24
+ ```
6
25
 
7
26
  ## [2.32.0](https://github.com/dotenvx/dotenvx/compare/v2.31.1...v2.32.0) (2026-09-29)
8
27
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.32.0",
2
+ "version": "2.32.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -5,13 +5,11 @@ const encryptTransform = require('./../../lib/transforms/encrypt')
5
5
 
6
6
  const catchAndLog = require('../../lib/helpers/catchAndLog')
7
7
  const createSpinner = require('../../lib/helpers/createSpinner')
8
- const Session = require('../../db/session')
9
8
 
10
9
  async function encryptAction () {
11
10
  const options = this.opts()
12
11
  const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
13
12
  const spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'encrypting' })
14
- const sesh = new Session()
15
13
 
16
14
  logger.debug(`options: ${JSON.stringify(options)}`)
17
15
 
@@ -20,7 +18,7 @@ async function encryptAction () {
20
18
  const ek = options.excludeKey
21
19
  const fk = options.envKeysFile || '.env.keys'
22
20
  const noCreate = options.create === false
23
- const noArmor = options.armor === false || (!options.token && (await sesh.noArmor()))
21
+ const noArmor = options.armor === false
24
22
  const noNative = options.native === false || options.noNative === true
25
23
 
26
24
  const noBitwarden = options.bitwarden === false || options.noBitwarden === true
@@ -30,7 +28,7 @@ async function encryptAction () {
30
28
 
31
29
  // stdout - should not have a try so that exit codes can surface to stdout
32
30
  if (options.stdout) {
33
- const { processedEnvs } = await encryptTransform({ envs, ik, ek, fk, noArmor, noCreate, noNative, no1Password, noBitwarden })
31
+ const { processedEnvs } = await encryptTransform({ envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
34
32
 
35
33
  if (spinner) spinner.stop()
36
34
  for (const processedEnv of processedEnvs) {
@@ -47,7 +45,7 @@ async function encryptAction () {
47
45
  }
48
46
 
49
47
  try {
50
- const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ envs, ik, ek, fk, noArmor, noCreate, noNative, no1Password, noBitwarden })
48
+ const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
51
49
 
52
50
  if (keysSrc) {
53
51
  await fsx.writeKeyFile(fk, keysSrc)
@@ -130,16 +130,6 @@ async function run () {
130
130
  maskProcessedEnvs(processedEnvs, commandEnv, showChar)
131
131
  }
132
132
 
133
- if (error) {
134
- if (ignore.includes(error.code)) {
135
- logger.verbose(`ignored: ${error.message}`)
136
- } else if (options.strict || error.diagnostics?.some(diagnostic => diagnostic.strict)) {
137
- throw error
138
- } else {
139
- logger.warn(error.messageWithHelp || error.message)
140
- }
141
- }
142
-
143
133
  for (const processedEnv of processedEnvs) {
144
134
  if (processedEnv.type === 'envFile') {
145
135
  logger.verbose(`loading env from ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
@@ -187,6 +177,16 @@ async function run () {
187
177
  }
188
178
  }
189
179
 
180
+ if (error) {
181
+ if (ignore.includes(error.code)) {
182
+ logger.verbose(`ignored: ${error.message}`)
183
+ } else if (options.strict || error.diagnostics?.some(diagnostic => diagnostic.strict)) {
184
+ throw error
185
+ } else {
186
+ logger.warn(error.messageWithHelp || error.message)
187
+ }
188
+ }
189
+
190
190
  const proxy = await configureProxy(commandArgs, commandEnv, proxyCredentials, sesh, proxyToken)
191
191
  closeProxy = proxy.close
192
192
  commandArgs = proxy.commandArgs
@@ -7,7 +7,6 @@ const catchAndLog = require('../../lib/helpers/catchAndLog')
7
7
  const createSpinner = require('../../lib/helpers/createSpinner')
8
8
  const Errors = require('../../lib/helpers/errors')
9
9
  const prompts = require('../../lib/helpers/prompts')
10
- const Session = require('../../db/session')
11
10
 
12
11
  async function set (key, value) {
13
12
  const options = this.opts()
@@ -47,7 +46,6 @@ async function set (key, value) {
47
46
  }
48
47
 
49
48
  const spinner = await createSpinner({ ...spinnerOptions, ...options, text: settingMessage })
50
- const sesh = new Session()
51
49
 
52
50
  logger.debug(`key: ${key}`)
53
51
  logger.debug(`value: ${value}`)
@@ -56,7 +54,7 @@ async function set (key, value) {
56
54
  const envs = this.envs || []
57
55
  const fk = options.envKeysFile || '.env.keys'
58
56
  const noCreate = options.create === false
59
- const noArmor = options.armor === false || (!options.token && (await sesh.noArmor()))
57
+ const noArmor = options.armor === false
60
58
  const noNative = options.native === false || options.noNative === true
61
59
 
62
60
  const noBitwarden = options.bitwarden === false || options.noBitwarden === true
@@ -65,7 +63,7 @@ async function set (key, value) {
65
63
  let errorCount = 0
66
64
 
67
65
  try {
68
- const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await setTransform({ envs, key, value, fk, noArmor, noCreate, encrypt, noNative, no1Password, noBitwarden })
66
+ const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await setTransform({ envs, key, value, fk, noArmor, token: options.token, noCreate, encrypt, noNative, no1Password, noBitwarden })
69
67
 
70
68
  if (keysSrc) {
71
69
  await fsx.writeKeyFile(fk, keysSrc)
@@ -6,7 +6,7 @@ module.exports = {
6
6
  id: 'armored',
7
7
  name: '⛨ Armor',
8
8
  custody: 'managed',
9
- enabled: (options = {}) => options.noArmor !== true && options.armor !== false,
9
+ enabled: (options = {}) => options.noArmor !== true && options.armor !== false && process.env.DOTENVX_NO_ARMOR !== 'true',
10
10
  available: () => true,
11
11
  async configured (options = {}) {
12
12
  return !!options.token || !await new Session().noArmor()
@@ -4,10 +4,10 @@ const prompts = require('../../../helpers/prompts')
4
4
  const teamChoicesFromMeta = require('../../../helpers/teamChoicesFromMeta')
5
5
  const isTeamRequiredError = require('../../../helpers/isTeamRequiredError')
6
6
 
7
- async function store (publicKey, privateKey) {
7
+ async function store (publicKey, privateKey, context = {}) {
8
8
  const sesh = new Session()
9
9
  const hostname = sesh.hostname()
10
- const token = sesh.token()
10
+ const token = context.token || sesh.token()
11
11
  const devicePublicKey = sesh.devicePublicKey()
12
12
 
13
13
  try {
@@ -23,13 +23,21 @@ async function store (publicKey, privateKey) {
23
23
  if (choices.length > 1) {
24
24
  team = await prompts.select({
25
25
  message: 'Select team',
26
- choices
26
+ prefix: '⛨',
27
+ choices: context.allowCustodyBack ? [...choices, { name: '← back', value: '__back' }] : choices,
28
+ ...(context.allowCustodyBack ? { navigation: true, backValue: '__back' } : {})
27
29
  }, {
28
30
  input: process.stdin,
29
31
  output: process.stderr
30
32
  })
31
33
  }
32
34
 
35
+ if (team === '__back') {
36
+ const error = new Error('Return to private key custody')
37
+ error.code = 'KEY_CUSTODY_BACK'
38
+ throw error
39
+ }
40
+
33
41
  await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team).run()
34
42
  }
35
43
  }
@@ -0,0 +1,25 @@
1
+ const { Enquirer } = require('@dotenvx/tooling')
2
+
3
+ class CustodySelect extends Enquirer.prompts.Select {
4
+ keypress (input, key = {}) {
5
+ if (key.name === 'escape') return this.cancel(new Error('Cancelled'))
6
+ if (key.name === 'left' && this.options.backValue) {
7
+ this.index = this.choices.findIndex(choice => choice.name === this.options.backValue)
8
+ return this.submit()
9
+ }
10
+ return super.keypress(input, key)
11
+ }
12
+
13
+ async render () {
14
+ // Replace the previous step instead of leaving a trail of completed menus.
15
+ if (this.state.submitted) {
16
+ this.clear(this.state.size)
17
+ this.state.prompt = ''
18
+ this.state.size = 0
19
+ return
20
+ }
21
+ return super.render()
22
+ }
23
+ }
24
+
25
+ module.exports = CustodySelect
@@ -9,6 +9,7 @@ function choicesForSelect (choices) {
9
9
  return {
10
10
  name: choice.value,
11
11
  message: choice.name || choice.value,
12
+ ...(choice.role ? { role: choice.role } : {}),
12
13
  ...(choice.disabled !== undefined ? { disabled: choice.disabled === true ? '(unavailable)' : choice.disabled } : {})
13
14
  }
14
15
  })
@@ -39,10 +40,15 @@ function clearLastLine (stream) {
39
40
  }
40
41
  }
41
42
 
42
- async function select ({ message, choices }, context) {
43
+ async function select ({ message, choices, navigation, backValue, initial, prefix }, context) {
44
+ if (navigation) {
45
+ const CustodySelect = require('./custodySelect')
46
+ return new CustodySelect({ message, choices: choicesForSelect(choices), backValue, initial, ...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}), ...enquirerOptions(context) }).run()
47
+ }
43
48
  const answer = await enquirer.prompt({
44
49
  type: 'select',
45
50
  name: 'value',
51
+ ...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}),
46
52
  message,
47
53
  choices: choicesForSelect(choices),
48
54
  ...enquirerOptions(context)
@@ -1,28 +1,73 @@
1
1
  const prompts = require('./prompts')
2
2
  const custodians = require('../custodians')
3
+ const createSpinner = require('./createSpinner')
4
+
5
+ const nativeNames = { darwin: 'macOS Keychain', win32: 'Windows Credential Manager', linux: 'Linux Secret Service' }
3
6
 
4
7
  async function selectKeyStorage (options = {}) {
5
8
  const defaultStorage = custodians.get('native').enabled(options) ? 'native' : 'file'
6
9
  if (process.env.CI || options.noCreate || !process.stdin.isTTY || !process.stderr.isTTY) return defaultStorage
7
10
 
8
- const localChoices = await custodians.choices(options)
9
-
10
- const choices = [{ name: '⛉ Local Custody', value: 'local', disabled: false }]
11
- const managedChoices = (await custodians.choices(options, 'managed')).filter(choice => !choice.disabled).map(({ name, value }) => ({ name, value }))
12
- if (managedChoices.length) choices.push({ name: '⛊ Managed Custody', value: 'managed' })
13
-
14
- const context = { input: process.stdin, output: process.stderr }
15
- const custody = await prompts.select({
16
- message: 'Choose private key storage',
17
- choices
18
- }, context)
19
-
20
- const storage = await prompts.select({
21
- message: custody === 'local' ? 'Choose local custody' : 'Choose managed custody',
22
- choices: custody === 'local' ? localChoices : managedChoices
23
- }, context)
11
+ const groups = new Map()
12
+ const setup = new Map()
13
+ const definitions = [
14
+ ['local', ['file', 'native']],
15
+ ['passwords', ['onepassword', 'bitwarden']],
16
+ ['armored', ['armored']]
17
+ ]
18
+ for (const [group, ids] of definitions) {
19
+ const entries = []
20
+ for (const id of ids) {
21
+ const custodian = custodians.get(id)
22
+ if (!custodian.enabled(options)) continue
23
+ let name = id === 'native' ? nativeNames[process.platform] : id === 'file' ? `File ${options.fk || '.env.keys'}` : id === 'armored' ? '⛨ Dotenvx Armor' : custodian.name
24
+ if (!await custodian.available()) {
25
+ const command = id === 'onepassword' ? 'op' : 'bw'
26
+ name += ' (install CLI)'
27
+ setup.set(id, `Install the ${custodian.name} CLI (${command}), then retry this command.`)
28
+ } else if (id === 'armored' && !await custodian.configured(options)) {
29
+ name += ' (sign in)'
30
+ setup.set(id, 'Sign in with [dotenvx armor login], then retry this command.')
31
+ }
32
+ entries.push({ name, value: id })
33
+ }
34
+ if (entries.length) groups.set(group, entries)
35
+ }
24
36
 
25
- return storage
37
+ createSpinner.pause()
38
+ try {
39
+ const context = { input: process.stdin, output: process.stderr }
40
+ const choices = [
41
+ { name: '⛉ Local', value: 'local' },
42
+ ...(groups.get('armored') || []),
43
+ ...(groups.has('passwords') ? [{ name: '⛊ Password Managers', value: 'passwords' }] : [])
44
+ ]
45
+ let initial = 'local'
46
+ while (true) {
47
+ const category = await prompts.select({ message: 'Choose private key custody', choices, navigation: true, initial }, context)
48
+ if (!choices.some(choice => choice.value === category)) throw new Error('Invalid private key storage selection')
49
+ let storage = category
50
+ if (category !== 'armored') {
51
+ const entries = groups.get(category)
52
+ storage = await prompts.select({
53
+ message: category === 'local' ? 'Choose local custody' : 'Choose password manager',
54
+ prefix: category === 'local' ? '⛉' : '⛊',
55
+ choices: [...entries, { name: '← back', value: '__back' }],
56
+ navigation: true,
57
+ backValue: '__back'
58
+ }, context)
59
+ if (storage === '__back') {
60
+ initial = category
61
+ continue
62
+ }
63
+ if (!entries.some(choice => choice.value === storage)) throw new Error('Invalid private key storage selection')
64
+ }
65
+ if (setup.has(storage)) throw new Error(setup.get(storage))
66
+ return storage
67
+ }
68
+ } finally {
69
+ createSpinner.resume()
70
+ }
26
71
  }
27
72
 
28
73
  module.exports = selectKeyStorage
@@ -0,0 +1,19 @@
1
+ const selectKeyStorage = require('./selectKeyStorage')
2
+ const custodians = require('../custodians')
3
+
4
+ async function storeKeyStorage (storage, publicKey, privateKey, options, context) {
5
+ // Preserve the operation context so locked custody can reuse its passphrase.
6
+ context.allowCustodyBack = true
7
+ while (true) {
8
+ storage = storage || await selectKeyStorage(options)
9
+ try {
10
+ const stored = await custodians.store(storage, publicKey, privateKey, context)
11
+ return { storage, stored }
12
+ } catch (error) {
13
+ if (error.code !== 'KEY_CUSTODY_BACK') throw error
14
+ storage = undefined
15
+ }
16
+ }
17
+ }
18
+
19
+ module.exports = storeKeyStorage
@@ -46,6 +46,7 @@ class ArmorDown {
46
46
  if (choices.length > 1) {
47
47
  team = await prompts.select({
48
48
  message: 'Select team',
49
+ prefix: '⛨',
49
50
  choices
50
51
  }, {
51
52
  input: process.stdin,
@@ -34,6 +34,7 @@ class ArmorMove {
34
34
  }))
35
35
  team = await prompts.select({
36
36
  message: 'Select team',
37
+ prefix: '⛨',
37
38
  choices
38
39
  }, {
39
40
  input: process.stdin,
@@ -46,6 +46,7 @@ class ArmorPull {
46
46
  if (choices.length > 1) {
47
47
  team = await prompts.select({
48
48
  message: 'Select team',
49
+ prefix: '⛨',
49
50
  choices
50
51
  }, {
51
52
  input: process.stdin,
@@ -41,6 +41,7 @@ class ArmorPush {
41
41
  if (choices.length > 1) {
42
42
  team = await prompts.select({
43
43
  message: 'Select team',
44
+ prefix: '⛨',
44
45
  choices
45
46
  }, {
46
47
  input: process.stdin,
@@ -41,6 +41,7 @@ class ArmorUp {
41
41
  if (choices.length > 1) {
42
42
  team = await prompts.select({
43
43
  message: 'Select team',
44
+ prefix: '⛨',
44
45
  choices
45
46
  }, {
46
47
  input: process.stdin,
@@ -12,8 +12,7 @@ const detectEncoding = require('./../helpers/detectEncoding')
12
12
  const { isDotenvPublicKey, isPlainKey, mutateSrc } = require('../helpers/cryptography')
13
13
  const keynames = require('../conventions/keynames')
14
14
 
15
- const selectKeyStorage = require('../helpers/selectKeyStorage')
16
- const custodians = require('../custodians')
15
+ const storeKeyStorage = require('../helpers/storeKeyStorage')
17
16
  const readEnvspec = require('../envspec/parsing/readEnvspec')
18
17
 
19
18
  async function encryptTransform (options = {}) {
@@ -22,7 +21,7 @@ async function encryptTransform (options = {}) {
22
21
  const ek = options.ek
23
22
  const fk = options.fk || '.env.keys'
24
23
  let storage
25
- const custodyContext = {}
24
+ const custodyContext = { token: options.token }
26
25
  const noCreate = options.noCreate
27
26
 
28
27
  const processedEnvs = []
@@ -79,8 +78,10 @@ async function encryptTransform (options = {}) {
79
78
  return schema.exists ? (schema.encryptionRules.get(key) ?? schema.encrypted) : !isPlainKey(key)
80
79
  })
81
80
  if (schema.exists && !selected.some(([, values]) => values.some(value => !encrypted(value)))) {
82
- row.changed = false
83
- unchangedFilepaths.push(envFilepath)
81
+ // A missing file still needs writing even when its initial values are
82
+ // exempt from encryption. Avoid generating keys, but preserve creation.
83
+ if (row.changed) changedFilepaths.push(envFilepath)
84
+ else unchangedFilepaths.push(envFilepath)
84
85
  processedEnvs.push(row)
85
86
  continue
86
87
  }
@@ -88,8 +89,6 @@ async function encryptTransform (options = {}) {
88
89
  let publicKey = publickeys(row.envSrc)[0]
89
90
 
90
91
  if (!publicKey) {
91
- storage = storage || await selectKeyStorage(options)
92
-
93
92
  // upsert public key to .env file
94
93
  const kp = keypair() // local
95
94
  publicKey = kp.publicKey
@@ -100,7 +99,9 @@ async function encryptTransform (options = {}) {
100
99
 
101
100
  const comment = path.basename(envFilepath)
102
101
 
103
- const stored = await custodians.store(storage, publicKey, privateKey, Object.assign(custodyContext, { keysSrc, privateKeyName, comment, keysFilepath: fk }))
102
+ const result = await storeKeyStorage(storage, publicKey, privateKey, options, Object.assign(custodyContext, { keysSrc, privateKeyName, comment, keysFilepath: fk }))
103
+ storage = result.storage
104
+ const stored = result.stored
104
105
  if (Object.prototype.hasOwnProperty.call(stored, 'keysSrc')) keysSrc = stored.keysSrc
105
106
  if (stored.nativePrivateKeyAdded) row.nativePrivateKeyAdded = true
106
107
  }
@@ -11,8 +11,7 @@ const { isPlainKey, mutateSrc } = require('../helpers/cryptography')
11
11
  const keynames = require('../conventions/keynames')
12
12
  const Errors = require('../helpers/errors')
13
13
 
14
- const selectKeyStorage = require('../helpers/selectKeyStorage')
15
- const custodians = require('../custodians')
14
+ const storeKeyStorage = require('../helpers/storeKeyStorage')
16
15
 
17
16
  async function setTransform (options = {}) {
18
17
  const envs = options.envs || []
@@ -21,7 +20,7 @@ async function setTransform (options = {}) {
21
20
  const fk = options.fk || '.env.keys'
22
21
  const noArmor = options.noArmor
23
22
  let storage
24
- const custodyContext = {}
23
+ const custodyContext = { token: options.token }
25
24
  const noNative = options.noNative
26
25
  const noCreate = options.noCreate
27
26
  const noEncrypt = !options.encrypt || isPlainKey(key)
@@ -73,8 +72,6 @@ async function setTransform (options = {}) {
73
72
 
74
73
  // only create if missing public key and encryption needed
75
74
  if (!publicKey && !noEncrypt) {
76
- storage = storage || await selectKeyStorage(options)
77
-
78
75
  // upsert public key to .env file
79
76
  const kp = keypair() // local
80
77
  publicKey = kp.publicKey
@@ -85,7 +82,9 @@ async function setTransform (options = {}) {
85
82
 
86
83
  const comment = path.basename(envFilepath)
87
84
 
88
- const stored = await custodians.store(storage, publicKey, privateKey, Object.assign(custodyContext, { keysSrc, privateKeyName, comment, keysFilepath: fk }))
85
+ const result = await storeKeyStorage(storage, publicKey, privateKey, options, Object.assign(custodyContext, { keysSrc, privateKeyName, comment, keysFilepath: fk }))
86
+ storage = result.storage
87
+ const stored = result.stored
89
88
  if (Object.prototype.hasOwnProperty.call(stored, 'keysSrc')) keysSrc = stored.keysSrc
90
89
  if (stored.nativePrivateKeyAdded) row.nativePrivateKeyAdded = true
91
90
  }