@dotenvx/dotenvx 2.28.0 → 2.28.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/README.md +40 -8
  3. package/package.json +1 -1
  4. package/src/cli/actions/define.js +17 -0
  5. package/src/cli/actions/encrypt.js +1 -1
  6. package/src/cli/actions/ext/precommit.js +3 -0
  7. package/src/cli/actions/ext/precommitClean.js +21 -0
  8. package/src/cli/actions/get.js +2 -1
  9. package/src/cli/actions/init.js +3 -0
  10. package/src/cli/actions/lock/down.js +13 -32
  11. package/src/cli/actions/lock/up.js +13 -30
  12. package/src/cli/actions/run.js +2 -1
  13. package/src/cli/actions/set.js +1 -1
  14. package/src/cli/commands/custody.js +2 -2
  15. package/src/cli/commands/ext.js +3 -1
  16. package/src/cli/commands/fileOptions.js +22 -0
  17. package/src/cli/dotenvx.js +38 -21
  18. package/src/lib/custodians/index.js +73 -0
  19. package/src/lib/{helpers/bitwardenCustody.js → custodians/local/bitwarden.js} +12 -7
  20. package/src/lib/custodians/local/file.js +18 -0
  21. package/src/lib/custodians/local/native/backend.js +62 -0
  22. package/src/lib/custodians/local/native/index.js +28 -0
  23. package/src/lib/{helpers/storeNativePrivateKey.js → custodians/local/native/store.js} +3 -3
  24. package/src/lib/{helpers/onePasswordCustody.js → custodians/local/onepassword.js} +9 -5
  25. package/src/lib/custodians/lock.js +80 -0
  26. package/src/lib/{providers/armor/index.js → custodians/managed/armor/get.js} +6 -6
  27. package/src/lib/custodians/managed/armor/index.js +24 -0
  28. package/src/lib/custodians/managed/armor/store.js +37 -0
  29. package/src/lib/helpers/fsx.js +16 -5
  30. package/src/lib/helpers/installPrecommitFilter.js +50 -0
  31. package/src/lib/helpers/installPrecommitHook.js +2 -2
  32. package/src/lib/helpers/lockedValue.js +24 -0
  33. package/src/lib/helpers/macosKeychain.js +18 -2
  34. package/src/lib/helpers/matchesStoredKey.js +16 -0
  35. package/src/lib/helpers/normalizeDotenvConfigPath.js +1 -1
  36. package/src/lib/helpers/parseWithDecryptor.js +3 -0
  37. package/src/lib/helpers/prompts.js +18 -0
  38. package/src/lib/helpers/removeEnvKey.js +2 -1
  39. package/src/lib/helpers/resolveLockPassword.js +5 -0
  40. package/src/lib/helpers/selectKeyStorage.js +9 -21
  41. package/src/lib/helpers/unlockedValue.js +26 -0
  42. package/src/lib/helpers/upsertEnvKey.js +2 -1
  43. package/src/lib/helpers/withLockedKeys.js +41 -0
  44. package/src/lib/main.d.ts +6 -0
  45. package/src/lib/main.js +5 -2
  46. package/src/lib/providers/index.js +9 -66
  47. package/src/lib/providers/native/index.js +2 -62
  48. package/src/lib/providers/provider-worker.js +1 -1
  49. package/src/lib/resolvers/envs.js +14 -5
  50. package/src/lib/resolvers/get.js +1 -0
  51. package/src/lib/services/custodyTransfer.js +2 -2
  52. package/src/lib/services/init.js +49 -0
  53. package/src/lib/services/precommit.js +12 -1
  54. package/src/lib/services/validate.js +1 -0
  55. package/src/lib/transforms/encrypt.js +6 -49
  56. package/src/lib/transforms/set.js +6 -49
@@ -7,19 +7,12 @@ const TYPE_ENV_FILE = 'envFile'
7
7
  const getResolver = require('./../resolvers/get')
8
8
  const { determine } = require('./../helpers/envResolution')
9
9
  const detectEncoding = require('./../helpers/detectEncoding')
10
- const { isPlainKey, mutateSrc, mutateKeysSrc } = require('../helpers/cryptography')
10
+ const { isPlainKey, mutateSrc } = require('../helpers/cryptography')
11
11
  const keynames = require('../conventions/keynames')
12
12
  const Errors = require('../helpers/errors')
13
- const PostArmorUp = require('../api/postArmorUp')
14
- const prompts = require('../helpers/prompts')
15
- const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
16
- const isTeamRequiredError = require('../helpers/isTeamRequiredError')
17
- const Session = require('../../db/session')
18
13
 
19
14
  const selectKeyStorage = require('../helpers/selectKeyStorage')
20
- const storeNativePrivateKey = require('../helpers/storeNativePrivateKey')
21
- const onePasswordCustody = require('../helpers/onePasswordCustody')
22
- const bitwardenCustody = require('../helpers/bitwardenCustody')
15
+ const custodians = require('../custodians')
23
16
 
24
17
  async function setTransform (options = {}) {
25
18
  const envs = options.envs || []
@@ -28,6 +21,7 @@ async function setTransform (options = {}) {
28
21
  const fk = options.fk || '.env.keys'
29
22
  const noArmor = options.noArmor
30
23
  let storage
24
+ const custodyContext = {}
31
25
  const noNative = options.noNative
32
26
  const noCreate = options.noCreate
33
27
  const noEncrypt = !options.encrypt || isPlainKey(key)
@@ -91,46 +85,9 @@ async function setTransform (options = {}) {
91
85
 
92
86
  const comment = path.basename(envFilepath)
93
87
 
94
- if (storage === 'bitwarden') {
95
- await bitwardenCustody.set(publicKey, privateKey)
96
- } else if (storage === 'onepassword') {
97
- await onePasswordCustody.set(publicKey, privateKey)
98
- } else if (storage === 'native' && storeNativePrivateKey(publicKey, privateKey, fk)) {
99
- row.nativePrivateKeyAdded = true
100
- } else if (storage !== 'armored') {
101
- const mutated = mutateKeysSrc({ keysSrc, privateKeyName, privateKeyValue: privateKey, comment })
102
- keysSrc = mutated.keysSrc
103
- } else {
104
- const sesh = new Session()
105
- const hostname = sesh.hostname()
106
- const token = sesh.token()
107
- const devicePublicKey = sesh.devicePublicKey()
108
-
109
- try {
110
- await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined).run()
111
- } catch (error) {
112
- if (!isTeamRequiredError(error)) {
113
- throw error
114
- }
115
-
116
- const choices = teamChoicesFromMeta(error.meta)
117
-
118
- let team = choices[0].value
119
- if (choices.length > 1) {
120
- team = await prompts.select({
121
- message: 'Select team',
122
- choices
123
- }, {
124
- input: process.stdin,
125
- output: process.stderr
126
- })
127
- }
128
-
129
- await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team).run()
130
- }
131
-
132
- // don't set keysSrc (in armor)
133
- }
88
+ const stored = await custodians.store(storage, publicKey, privateKey, Object.assign(custodyContext, { keysSrc, privateKeyName, comment, keysFilepath: fk }))
89
+ if (Object.prototype.hasOwnProperty.call(stored, 'keysSrc')) keysSrc = stored.keysSrc
90
+ if (stored.nativePrivateKeyAdded) row.nativePrivateKeyAdded = true
134
91
  }
135
92
 
136
93
  if (noEncrypt) {