@dotenvx/dotenvx 2.38.2 → 3.0.0-beta.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 (271) hide show
  1. package/README.md +197 -3314
  2. package/bin/dotenvx.cjs +34 -0
  3. package/config.cjs +1 -0
  4. package/config.d.ts +1 -0
  5. package/config.mjs +2 -0
  6. package/index.cjs +141 -0
  7. package/index.d.ts +66 -0
  8. package/index.mjs +3 -0
  9. package/lib/cli.cjs +43 -0
  10. package/lib/native-package.cjs +21 -0
  11. package/lib/platforms.cjs +18 -0
  12. package/{src/lib/helpers/redactOutput.js → lib/redactOutput.cjs} +2 -48
  13. package/lib/redaction.cjs +64 -0
  14. package/lib/validateOptions.cjs +57 -0
  15. package/native.cjs +23 -0
  16. package/package.json +57 -65
  17. package/CHANGELOG.md +0 -2733
  18. package/src/cli/actions/armor/down.js +0 -38
  19. package/src/cli/actions/armor/invite.js +0 -21
  20. package/src/cli/actions/armor/move.js +0 -43
  21. package/src/cli/actions/armor/open.js +0 -28
  22. package/src/cli/actions/armor/pull.js +0 -38
  23. package/src/cli/actions/armor/push.js +0 -38
  24. package/src/cli/actions/armor/status.js +0 -7
  25. package/src/cli/actions/armor/up.js +0 -38
  26. package/src/cli/actions/check.js +0 -78
  27. package/src/cli/actions/curl.js +0 -71
  28. package/src/cli/actions/decrypt.js +0 -119
  29. package/src/cli/actions/del.js +0 -54
  30. package/src/cli/actions/doctor.js +0 -22
  31. package/src/cli/actions/encrypt.js +0 -104
  32. package/src/cli/actions/ext/genexample.js +0 -36
  33. package/src/cli/actions/ext/gitignore.js +0 -106
  34. package/src/cli/actions/ext/prebuild.js +0 -7
  35. package/src/cli/actions/ext/precommit.js +0 -38
  36. package/src/cli/actions/ext/scan.js +0 -33
  37. package/src/cli/actions/feedback.js +0 -42
  38. package/src/cli/actions/get.js +0 -128
  39. package/src/cli/actions/init.js +0 -67
  40. package/src/cli/actions/keychain/down.js +0 -30
  41. package/src/cli/actions/keychain/pull.js +0 -30
  42. package/src/cli/actions/keychain/push.js +0 -30
  43. package/src/cli/actions/keychain/up.js +0 -30
  44. package/src/cli/actions/keypair.js +0 -84
  45. package/src/cli/actions/login.js +0 -64
  46. package/src/cli/actions/logout.js +0 -37
  47. package/src/cli/actions/ls.js +0 -76
  48. package/src/cli/actions/policy.js +0 -14
  49. package/src/cli/actions/primitivesCheck.js +0 -32
  50. package/src/cli/actions/primitivesProfile.js +0 -15
  51. package/src/cli/actions/primitivesRedact.js +0 -19
  52. package/src/cli/actions/protect.js +0 -75
  53. package/src/cli/actions/protectDocker.js +0 -30
  54. package/src/cli/actions/protectProcess.js +0 -126
  55. package/src/cli/actions/protectStdin.js +0 -80
  56. package/src/cli/actions/run.js +0 -203
  57. package/src/cli/actions/set.js +0 -103
  58. package/src/cli/actions/settings/device.js +0 -23
  59. package/src/cli/actions/settings/hostname.js +0 -20
  60. package/src/cli/actions/settings/off.js +0 -14
  61. package/src/cli/actions/settings/on.js +0 -14
  62. package/src/cli/actions/settings/path.js +0 -20
  63. package/src/cli/actions/settings/token.js +0 -23
  64. package/src/cli/actions/settings/username.js +0 -20
  65. package/src/cli/actions/update.js +0 -15
  66. package/src/cli/commandAction.js +0 -16
  67. package/src/cli/commands/armor.js +0 -129
  68. package/src/cli/commands/custody.js +0 -45
  69. package/src/cli/commands/ext.js +0 -88
  70. package/src/cli/commands/fileOptions.js +0 -22
  71. package/src/cli/commands/native.js +0 -54
  72. package/src/cli/commands/primitives.js +0 -73
  73. package/src/cli/commands/settings.js +0 -63
  74. package/src/cli/dotenvx.js +0 -443
  75. package/src/cli/help.js +0 -179
  76. package/src/db/device.js +0 -67
  77. package/src/db/session.js +0 -330
  78. package/src/lib/api/getAccount.js +0 -32
  79. package/src/lib/api/getConnectionResources.js +0 -21
  80. package/src/lib/api/getTeamConnections.js +0 -27
  81. package/src/lib/api/getTeamServices.js +0 -23
  82. package/src/lib/api/getTeams.js +0 -28
  83. package/src/lib/api/postArmorDown.js +0 -48
  84. package/src/lib/api/postArmorMove.js +0 -48
  85. package/src/lib/api/postArmorPull.js +0 -48
  86. package/src/lib/api/postArmorPush.js +0 -48
  87. package/src/lib/api/postArmorUp.js +0 -53
  88. package/src/lib/api/postConnectionKeypair.js +0 -23
  89. package/src/lib/api/postFeedback.js +0 -31
  90. package/src/lib/api/postLogout.js +0 -34
  91. package/src/lib/api/postOauthDeviceCode.js +0 -38
  92. package/src/lib/api/postOauthToken.js +0 -35
  93. package/src/lib/api/postTeamInvitation.js +0 -28
  94. package/src/lib/api/teamConnectionSetup.js +0 -31
  95. package/src/lib/config.d.ts +0 -1
  96. package/src/lib/config.js +0 -1
  97. package/src/lib/conventions/environment.js +0 -27
  98. package/src/lib/conventions/filepaths.js +0 -9
  99. package/src/lib/conventions/keynames.js +0 -38
  100. package/src/lib/custodians/index.js +0 -75
  101. package/src/lib/custodians/local/bitwarden.js +0 -165
  102. package/src/lib/custodians/local/file.js +0 -18
  103. package/src/lib/custodians/local/native/backend.js +0 -56
  104. package/src/lib/custodians/local/native/index.js +0 -28
  105. package/src/lib/custodians/local/native/store.js +0 -24
  106. package/src/lib/custodians/local/onepassword.js +0 -149
  107. package/src/lib/custodians/managed/armor/index.js +0 -14
  108. package/src/lib/custodians/managed/armor/store.js +0 -48
  109. package/src/lib/custodians/resolveLocalKey.js +0 -67
  110. package/src/lib/decryptors/armor/index.js +0 -23
  111. package/src/lib/decryptors/decryptor-worker.js +0 -6
  112. package/src/lib/decryptors/index.js +0 -69
  113. package/src/lib/envfile/discovery/discoverEnvFiles.js +0 -29
  114. package/src/lib/envfile/discovery/extractEnvKeys.js +0 -173
  115. package/src/lib/envfile/discovery/scanSource.js +0 -79
  116. package/src/lib/envfile/parsing/formatEnvfileSyntaxError.js +0 -24
  117. package/src/lib/envfile/parsing/readEnvfile.js +0 -43
  118. package/src/lib/envfile/parsing/resolveEnvfilePath.js +0 -5
  119. package/src/lib/envfile/rendering/normalizeEnvfile.js +0 -53
  120. package/src/lib/envfile/rendering/previewEnvfile.js +0 -43
  121. package/src/lib/envfile/rendering/renderEnvfile.js +0 -30
  122. package/src/lib/envfile/validation/diagnosticLocation.js +0 -29
  123. package/src/lib/envfile/validation/protectEnvfile.js +0 -40
  124. package/src/lib/envfile/validation/validateEnvfile.js +0 -14
  125. package/src/lib/events/backends/armor.js +0 -31
  126. package/src/lib/events/background.js +0 -59
  127. package/src/lib/events/catalog.js +0 -14
  128. package/src/lib/events/cli.js +0 -40
  129. package/src/lib/events/delivery.js +0 -89
  130. package/src/lib/events/index.js +0 -73
  131. package/src/lib/events/metadata.js +0 -25
  132. package/src/lib/events/sdk.js +0 -44
  133. package/src/lib/events/worker.js +0 -29
  134. package/src/lib/events/workerEnvironment.js +0 -14
  135. package/src/lib/helpers/armoredKeyDisplay.js +0 -10
  136. package/src/lib/helpers/arrayToTree.js +0 -27
  137. package/src/lib/helpers/buildApiError.js +0 -19
  138. package/src/lib/helpers/buildCommandEnvs.js +0 -40
  139. package/src/lib/helpers/buildConfigEnvs.js +0 -13
  140. package/src/lib/helpers/buildEnvs.js +0 -24
  141. package/src/lib/helpers/buildOauthError.js +0 -14
  142. package/src/lib/helpers/canonicalEnvFilename.js +0 -13
  143. package/src/lib/helpers/catchAndLog.js +0 -16
  144. package/src/lib/helpers/checklist.js +0 -50
  145. package/src/lib/helpers/chomp.js +0 -5
  146. package/src/lib/helpers/colorDepth.js +0 -23
  147. package/src/lib/helpers/conventions.js +0 -28
  148. package/src/lib/helpers/createElapsedStatus.js +0 -17
  149. package/src/lib/helpers/createProtectSpinner.js +0 -13
  150. package/src/lib/helpers/createSpinner.js +0 -40
  151. package/src/lib/helpers/cryptography/decryptKeyValue.js +0 -50
  152. package/src/lib/helpers/cryptography/index.js +0 -7
  153. package/src/lib/helpers/cryptography/isDotenvPublicKey.js +0 -7
  154. package/src/lib/helpers/cryptography/isPlainKey.js +0 -7
  155. package/src/lib/helpers/cryptography/mutateKeysSrc.js +0 -22
  156. package/src/lib/helpers/cryptography/mutateSrc.js +0 -24
  157. package/src/lib/helpers/custodySelect.js +0 -25
  158. package/src/lib/helpers/decryptDeviceValue.js +0 -7
  159. package/src/lib/helpers/detectEncoding.js +0 -22
  160. package/src/lib/helpers/detectEncodingSync.js +0 -22
  161. package/src/lib/helpers/dotenvOptionPaths.js +0 -25
  162. package/src/lib/helpers/dotenvPrivateKeyNames.js +0 -7
  163. package/src/lib/helpers/enclavedHint.js +0 -11
  164. package/src/lib/helpers/encryptDeviceValue.js +0 -7
  165. package/src/lib/helpers/envResolution/determine.js +0 -49
  166. package/src/lib/helpers/envResolution/index.js +0 -8
  167. package/src/lib/helpers/errors.js +0 -374
  168. package/src/lib/helpers/escape.js +0 -6
  169. package/src/lib/helpers/execute.js +0 -12
  170. package/src/lib/helpers/executeCommand.js +0 -208
  171. package/src/lib/helpers/executeDynamic.js +0 -86
  172. package/src/lib/helpers/executeExtension.js +0 -39
  173. package/src/lib/helpers/filterKeys.js +0 -15
  174. package/src/lib/helpers/findEnvFiles.js +0 -25
  175. package/src/lib/helpers/formatCode.js +0 -11
  176. package/src/lib/helpers/fsx.js +0 -110
  177. package/src/lib/helpers/guessPrivateKeyFilename.js +0 -15
  178. package/src/lib/helpers/hasPlaintextSecrets.js +0 -7
  179. package/src/lib/helpers/http.js +0 -14
  180. package/src/lib/helpers/installPrecommitHook.js +0 -82
  181. package/src/lib/helpers/installProtectFilter.js +0 -57
  182. package/src/lib/helpers/installProtectIgnore.js +0 -27
  183. package/src/lib/helpers/isPublicKey.js +0 -3
  184. package/src/lib/helpers/isTeamRequiredError.js +0 -10
  185. package/src/lib/helpers/jsonToEnv.js +0 -7
  186. package/src/lib/helpers/keypairMetadata.js +0 -90
  187. package/src/lib/helpers/kits/sample.js +0 -5
  188. package/src/lib/helpers/linuxSecretService.js +0 -52
  189. package/src/lib/helpers/listenForOpenKey.js +0 -46
  190. package/src/lib/helpers/logProtectedFiles.js +0 -9
  191. package/src/lib/helpers/logSetSummary.js +0 -21
  192. package/src/lib/helpers/macosKeychain.js +0 -52
  193. package/src/lib/helpers/mask.js +0 -22
  194. package/src/lib/helpers/maskEnvSrc.js +0 -15
  195. package/src/lib/helpers/maskProcessedEnvs.js +0 -29
  196. package/src/lib/helpers/matchesStoredKey.js +0 -5
  197. package/src/lib/helpers/nativeStoreError.js +0 -10
  198. package/src/lib/helpers/normalizeDotenvConfigConvention.js +0 -13
  199. package/src/lib/helpers/normalizeDotenvConfigIgnore.js +0 -18
  200. package/src/lib/helpers/normalizeDotenvConfigPath.js +0 -14
  201. package/src/lib/helpers/normalizeDotenvConfigQuiet.js +0 -13
  202. package/src/lib/helpers/normalizeToken.js +0 -5
  203. package/src/lib/helpers/openUrl.js +0 -7
  204. package/src/lib/helpers/packageJson.js +0 -3
  205. package/src/lib/helpers/parseWithDecryptor.js +0 -115
  206. package/src/lib/helpers/plaintextKeys.js +0 -9
  207. package/src/lib/helpers/precommitEnvPatterns.js +0 -1
  208. package/src/lib/helpers/prependPublicKey.js +0 -17
  209. package/src/lib/helpers/preserveShebang.js +0 -16
  210. package/src/lib/helpers/prompts.js +0 -169
  211. package/src/lib/helpers/protectSettings.js +0 -64
  212. package/src/lib/helpers/ptyCommand.js +0 -27
  213. package/src/lib/helpers/readEnvKey.js +0 -32
  214. package/src/lib/helpers/redact.js +0 -9
  215. package/src/lib/helpers/redactProcessOutput.js +0 -58
  216. package/src/lib/helpers/redactedValues.js +0 -29
  217. package/src/lib/helpers/removeDynamicHelpSection.js +0 -21
  218. package/src/lib/helpers/removeEnvKey.js +0 -51
  219. package/src/lib/helpers/removeLegacyProtectFilter.js +0 -43
  220. package/src/lib/helpers/removeOptionsHelpParts.js +0 -59
  221. package/src/lib/helpers/resolveBitwardenPassword.js +0 -165
  222. package/src/lib/helpers/resolveDirectoryFilepath.js +0 -16
  223. package/src/lib/helpers/resolveEnvKeysFile.js +0 -11
  224. package/src/lib/helpers/resolveHome.js +0 -12
  225. package/src/lib/helpers/resolveOnePassword.js +0 -82
  226. package/src/lib/helpers/sanitizeCommandForMetadata.js +0 -64
  227. package/src/lib/helpers/selectConnection.js +0 -51
  228. package/src/lib/helpers/selectConnectionResource.js +0 -41
  229. package/src/lib/helpers/selectEnvfileEnvs.js +0 -29
  230. package/src/lib/helpers/selectKeyStorage.js +0 -140
  231. package/src/lib/helpers/statusReporter.js +0 -8
  232. package/src/lib/helpers/storeKeyStorage.js +0 -39
  233. package/src/lib/helpers/teamChoicesFromMeta.js +0 -8
  234. package/src/lib/helpers/truncate.js +0 -10
  235. package/src/lib/helpers/uninstallPrecommitHook.js +0 -67
  236. package/src/lib/helpers/upsertEnvKey.js +0 -62
  237. package/src/lib/helpers/windowsCredentialManager.js +0 -166
  238. package/src/lib/main.d.ts +0 -509
  239. package/src/lib/main.js +0 -468
  240. package/src/lib/providers/index.js +0 -86
  241. package/src/lib/providers/native/index.js +0 -2
  242. package/src/lib/resolvers/envs.js +0 -416
  243. package/src/lib/resolvers/get.js +0 -87
  244. package/src/lib/resolvers/keypair.js +0 -135
  245. package/src/lib/resolvers/ls.js +0 -69
  246. package/src/lib/services/armorDown.js +0 -73
  247. package/src/lib/services/armorInvite.js +0 -36
  248. package/src/lib/services/armorMove.js +0 -55
  249. package/src/lib/services/armorOpen.js +0 -26
  250. package/src/lib/services/armorPull.js +0 -73
  251. package/src/lib/services/armorPush.js +0 -66
  252. package/src/lib/services/armorUp.js +0 -71
  253. package/src/lib/services/custodyTransfer.js +0 -50
  254. package/src/lib/services/doctor.js +0 -93
  255. package/src/lib/services/genexample.js +0 -112
  256. package/src/lib/services/init.js +0 -83
  257. package/src/lib/services/keychainDown.js +0 -60
  258. package/src/lib/services/keychainPull.js +0 -46
  259. package/src/lib/services/keychainPush.js +0 -51
  260. package/src/lib/services/keychainUp.js +0 -72
  261. package/src/lib/services/login.js +0 -51
  262. package/src/lib/services/logout.js +0 -26
  263. package/src/lib/services/prebuild.js +0 -91
  264. package/src/lib/services/precommit.js +0 -144
  265. package/src/lib/services/validate.js +0 -57
  266. package/src/lib/transforms/decrypt.js +0 -98
  267. package/src/lib/transforms/del.js +0 -58
  268. package/src/lib/transforms/encrypt.js +0 -164
  269. package/src/lib/transforms/set.js +0 -144
  270. package/src/shared/colors.js +0 -67
  271. package/src/shared/logger.js +0 -148
@@ -1,80 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const plaintextKeys = require('../../lib/helpers/plaintextKeys')
4
- const protectEnvfile = require('../../lib/envfile/validation/protectEnvfile')
5
- const { logger } = require('../../shared/logger')
6
- const createProtectSpinner = require('../../lib/helpers/createProtectSpinner')
7
- const logProtectedFiles = require('../../lib/helpers/logProtectedFiles')
8
-
9
- function exempt (filepath) {
10
- return ['.env.example', '.env.vault', '.env.x'].includes(path.posix.basename(filepath))
11
- }
12
-
13
- function fixMessage (filepath, privateKeyFile) {
14
- if (Array.from(filepath).some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)) {
15
- return privateKeyFile ? 'fix: add this private-key file to .gitignore' : 'fix: encrypt this env file or add it to .gitignore'
16
- }
17
- const argument = /^[a-zA-Z0-9_./-]+$/.test(filepath) ? filepath : "'" + filepath.replace(/'/g, "'\\''") + "'"
18
- return privateKeyFile
19
- ? `fix: run [dotenvx gitignore --pattern ${argument}]`
20
- : `fix: run [dotenvx encrypt -f ${argument}]`
21
- }
22
-
23
- function check (filepath, content, beforeError = () => {}) {
24
- const filename = path.posix.basename(filepath)
25
- const privateKeyFile = filename.startsWith('.env.keys')
26
- let rejected = null
27
- if (!privateKeyFile) {
28
- try {
29
- rejected = protectEnvfile(filepath, content.toString('utf8'))
30
- } catch (error) {
31
- beforeError()
32
- logger.error(error.message)
33
- return false
34
- }
35
- }
36
- const plaintext = rejected === null
37
- ? !exempt(filepath) && plaintextKeys(content.toString('utf8')).length > 0
38
- : rejected.length > 0
39
- if (privateKeyFile || plaintext) {
40
- const code = privateKeyFile ? 'PRIVATE_KEY_FILE' : 'PLAINTEXT_ENV'
41
- const fix = fixMessage(filepath, privateKeyFile)
42
- const message = privateKeyFile
43
- ? `refusing to stage ${JSON.stringify(filepath)}`
44
- : rejected?.length
45
- ? `${rejected.join(', ')} not encrypted (${JSON.stringify(filepath)})`
46
- : `${JSON.stringify(filepath)} contains plaintext secrets`
47
- beforeError()
48
- logger.error(`[${code}] ${message}. ${fix}`)
49
- return false
50
- }
51
- return true
52
- }
53
-
54
- async function protectStdin (filepath, options = {}) {
55
- let spinner
56
- const stop = () => { if (spinner) spinner.stop() }
57
- try {
58
- spinner = await createProtectSpinner(options)
59
- const content = fs.readFileSync(0)
60
- if (!check(filepath, content, stop)) {
61
- process.exitCode = 1
62
- return
63
- }
64
- // stdout is Git's blob content: no logging, normalization, or extra newline.
65
- process.stdout.write(content)
66
- stop()
67
- if (spinner && !exempt(filepath)) logProtectedFiles([filepath])
68
- } catch (error) {
69
- stop()
70
- logger.error(error.message)
71
- process.exitCode = 1
72
- return { error }
73
- } finally {
74
- stop()
75
- }
76
- }
77
-
78
- module.exports = protectStdin
79
- module.exports.check = check
80
- module.exports.exempt = exempt
@@ -1,203 +0,0 @@
1
- const statusReporter = require('../../lib/helpers/statusReporter')
2
- const path = require('path')
3
- const { injectsummary, publickeys } = require('@dotenvx/primitives')
4
- const { logger } = require('./../../shared/logger')
5
-
6
- const executeCommand = require('./../../lib/helpers/executeCommand')
7
- const catchAndLog = require('./../../lib/helpers/catchAndLog')
8
- const createSpinner = require('../../lib/helpers/createSpinner')
9
- const prepareValidatedEnv = require('../../lib/services/validate')
10
- const normalizeDotenvConfigQuiet = require('../../lib/helpers/normalizeDotenvConfigQuiet')
11
- const normalizeDotenvConfigConvention = require('../../lib/helpers/normalizeDotenvConfigConvention')
12
- const normalizeDotenvConfigIgnore = require('../../lib/helpers/normalizeDotenvConfigIgnore')
13
- const mask = require('../../lib/helpers/mask')
14
- const maskEnvSrc = require('../../lib/helpers/maskEnvSrc')
15
- const maskProcessedEnvs = require('../../lib/helpers/maskProcessedEnvs')
16
- const redactedValues = require('../../lib/helpers/redactedValues')
17
- const { redactOutput } = require('../../lib/helpers/redactOutput')
18
-
19
- function inferCommandArgsFromProcessArgv (argv) {
20
- const runIndex = argv.indexOf('run')
21
- if (runIndex === -1) return []
22
-
23
- const args = argv.slice(runIndex + 1)
24
-
25
- const separatorIndex = args.indexOf('--')
26
- if (separatorIndex !== -1) return args.slice(separatorIndex + 1)
27
-
28
- for (let i = 0; i < args.length; i++) {
29
- if (args[i] === '-f' || args[i] === '--file' || args[i] === '--env-file' || args[i] === '--profile') {
30
- i++
31
- continue
32
- }
33
-
34
- if (args[i].startsWith('-')) continue
35
-
36
- return args.slice(i)
37
- }
38
-
39
- return []
40
- }
41
-
42
- function uniqueInjectedKeys (processedEnvs) {
43
- const result = new Set()
44
- for (const processedEnv of processedEnvs) {
45
- for (const key of Object.keys(processedEnv.injected || {})) {
46
- result.add(key)
47
- }
48
- }
49
- return result
50
- }
51
-
52
- async function run () {
53
- const options = normalizeDotenvConfigIgnore(normalizeDotenvConfigConvention(normalizeDotenvConfigQuiet(this.opts())))
54
- const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
55
- const maskEnabled = options.mask !== undefined
56
- let showChar = options.mask
57
- if (options.mask === true) {
58
- showChar = 6
59
- }
60
- let commandEnv = process.env
61
- let sensitiveValues = []
62
-
63
- let commandArgs = this.args
64
- if (commandArgs.length < 1) {
65
- commandArgs = inferCommandArgsFromProcessArgv(process.argv)
66
- }
67
-
68
- const spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'injecting' })
69
-
70
- let debugOptions = options
71
- if (maskEnabled) {
72
- let token = options.token
73
- if (options.token) {
74
- token = mask(options.token, showChar)
75
- }
76
-
77
- debugOptions = { ...options, env: (options.env || []).map(envSrc => maskEnvSrc(envSrc, showChar)), token }
78
- }
79
-
80
- const ignore = options.ignore || []
81
-
82
- if (commandArgs.length < 1) {
83
- if (spinner) spinner.stop()
84
-
85
- const hasSeparator = process.argv.indexOf('--') !== -1
86
-
87
- if (hasSeparator) {
88
- logger.error('missing command after [dotenvx run --]. try [dotenvx run -- yourcommand]')
89
- } else {
90
- const realExample = options.envFile[0] || '.env'
91
- logger.error(`ambiguous command due to missing '--' separator. try [dotenvx run -f ${realExample} -- yourcommand]`)
92
- }
93
-
94
- return { exitCode: 1 }
95
- }
96
-
97
- try {
98
- const {
99
- processedEnvs,
100
- readableFilepaths,
101
- hasEnvfile,
102
- schema,
103
- validationError: error
104
- } = await prepareValidatedEnv({
105
- envs: this.envs,
106
- options,
107
- processEnv: process.env,
108
- requireEnvfile: false,
109
- command: commandArgs,
110
- onStatus: statusReporter(spinner)
111
- })
112
-
113
- if (hasEnvfile || options.redact === true) {
114
- sensitiveValues = redactedValues(processedEnvs, schema, process.env, options.redact === true)
115
- }
116
-
117
- logger.debug(redactOutput(`options: ${JSON.stringify(debugOptions)}`, sensitiveValues))
118
- logger.debug(redactOutput(`process command [${commandArgs.join(' ')}]`, sensitiveValues))
119
-
120
- if (maskEnabled) {
121
- commandEnv = { ...process.env }
122
- maskProcessedEnvs(processedEnvs, commandEnv, showChar)
123
- }
124
-
125
- for (const processedEnv of processedEnvs) {
126
- if (processedEnv.type === 'envFile') {
127
- logger.verbose(`loading env from ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
128
- }
129
-
130
- if (processedEnv.type === 'env') {
131
- let envString = processedEnv.string
132
- if (maskEnabled) {
133
- envString = maskEnvSrc(processedEnv.string, showChar)
134
- }
135
- logger.verbose(redactOutput(`loading env from string (${envString})`, sensitiveValues))
136
- }
137
-
138
- for (const error of processedEnv.errors || []) {
139
- if (ignore.includes(error.code)) {
140
- logger.verbose(`ignored: ${error.message}`)
141
- continue // ignore error
142
- }
143
-
144
- if (options.strict) throw error // file-loading failures use the CLI strict flag
145
-
146
- if (error.code === 'MISSING_ENV_FILE' && options.convention) { // do not output error for conventions (too noisy)
147
- // intentionally quiet
148
- } else {
149
- logger.error(error.messageWithHelp || error.message)
150
- }
151
- }
152
-
153
- // debug parsed
154
- logger.debug(redactOutput(processedEnv.parsed, sensitiveValues))
155
-
156
- // verbose/debug injected key/value
157
- for (const [key, value] of Object.entries(processedEnv.injected || {})) {
158
- logger.verbose(`${key} set`)
159
- logger.debug(redactOutput(`${key} set to ${value}`, sensitiveValues))
160
- }
161
-
162
- // verbose/debug existed key/value
163
- for (const [key, value] of Object.entries(processedEnv.existed || {})) {
164
- logger.verbose(`${key} pre-exists (protip: use --overload to override)`)
165
- logger.debug(redactOutput(`${key} pre-exists as ${value} (protip: use --overload to override)`, sensitiveValues))
166
- }
167
- }
168
-
169
- if (error) {
170
- if (ignore.includes(error.code)) {
171
- logger.verbose(`ignored: ${error.message}`)
172
- } else if (options.strict || error.diagnostics?.some(diagnostic => diagnostic.strict)) {
173
- throw error
174
- } else {
175
- logger.warn(error.messageWithHelp || error.message)
176
- }
177
- }
178
-
179
- const injectedKeys = uniqueInjectedKeys(processedEnvs)
180
-
181
- if (spinner) spinner.stop()
182
- const summaryRows = readableFilepaths.map(filepath => {
183
- const row = processedEnvs.find(row => row.filepath === filepath)
184
- return {
185
- filepath,
186
- publicKeys: row ? publickeys(row.src || '') : [],
187
- keySources: row && row.keySources
188
- }
189
- })
190
- logger.success(injectsummary(injectedKeys.size, summaryRows))
191
- } catch (error) {
192
- if (spinner) spinner.stop()
193
- if (error.code === 'PROMPT_CANCELLED') {
194
- return { exitCode: 130, error }
195
- }
196
- catchAndLog(error)
197
- return { exitCode: 1, error }
198
- }
199
-
200
- return executeCommand(commandArgs, commandEnv, sensitiveValues)
201
- }
202
-
203
- module.exports = require('../../lib/events/cli')('run', run)
@@ -1,103 +0,0 @@
1
- const statusReporter = require('../../lib/helpers/statusReporter')
2
- const fsx = require('./../../lib/helpers/fsx')
3
- const { logger } = require('./../../shared/logger')
4
-
5
- const setTransform = require('./../../lib/transforms/set')
6
- const logSetSummary = require('../../lib/helpers/logSetSummary')
7
-
8
- const catchAndLog = require('../../lib/helpers/catchAndLog')
9
- const createSpinner = require('../../lib/helpers/createSpinner')
10
- const Errors = require('../../lib/helpers/errors')
11
- const prompts = require('../../lib/helpers/prompts')
12
-
13
- async function set (key, value) {
14
- const options = this.opts()
15
- const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
16
-
17
- let encrypt = true
18
- let settingMessage = 'encrypting'
19
- let settingSymbol = '◈'
20
- if (options.plain) {
21
- encrypt = false
22
- settingMessage = 'setting'
23
- settingSymbol = '◇'
24
- }
25
-
26
- if (value === undefined || value === null) {
27
- if (!process.stdin.isTTY) {
28
- catchAndLog(new Errors({ key }).missingValue())
29
- return { exitCode: 1 }
30
- }
31
-
32
- try {
33
- value = await prompts.password({
34
- message: key,
35
- prefix: settingSymbol,
36
- separator: '='
37
- }, {
38
- input: process.stdin,
39
- output: process.stderr
40
- })
41
- } catch (error) {
42
- if (error.code === 'PROMPT_CANCELLED') {
43
- return { exitCode: 130, error }
44
- }
45
-
46
- throw error
47
- }
48
- }
49
-
50
- const spinner = await createSpinner({ ...spinnerOptions, ...options, text: settingMessage })
51
-
52
- logger.debug(`key: ${key}`)
53
- logger.debug(`value: ${value}`)
54
- logger.debug(`options: ${JSON.stringify(options)}`)
55
-
56
- const envs = this.envs || []
57
- const fk = options.envKeysFile || '.env.keys'
58
- const noCreate = options.create === false
59
- const noArmor = options.armor === false
60
- const noNative = options.native === false || options.noNative === true
61
-
62
- const noBitwarden = options.bitwarden === false || options.noBitwarden === true
63
- const no1Password = options['1password'] === false || options.no1Password === true
64
-
65
- let errorCount = 0
66
-
67
- try {
68
- const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await setTransform({ profile: options.profile, envs, key, value, fk, noArmor, token: options.token, noCreate, encrypt, noNative, no1Password, noBitwarden, onStatus: statusReporter(spinner) })
69
-
70
- if (keysSrc) {
71
- await fsx.writeKeyFile(fk, keysSrc)
72
- }
73
-
74
- let withEncryption = ''
75
- if (encrypt) {
76
- withEncryption = ' with encryption'
77
- }
78
-
79
- if (spinner) spinner.stop()
80
- for (const processedEnv of processedEnvs) {
81
- logger.verbose(`setting for ${processedEnv.envFilepath}`)
82
- if (processedEnv.error) {
83
- errorCount += 1
84
- logger.error(processedEnv.error.messageWithHelp || processedEnv.error.message)
85
- } else if (processedEnv.changed) {
86
- await fsx.writeFileX(processedEnv.filepath, processedEnv.envSrc)
87
- logger.verbose(`${processedEnv.key} set${withEncryption} (${processedEnv.envFilepath})`)
88
- } else {
89
- logger.verbose(`no change ${processedEnv.envFilepath} (${processedEnv.filepath})`)
90
- }
91
- }
92
-
93
- await logSetSummary(key, encrypt, { processedEnvs, changedFilepaths, unchangedFilepaths })
94
-
95
- return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
96
- } catch (error) {
97
- if (spinner) spinner.stop()
98
- catchAndLog(error)
99
- return { exitCode: 1, error }
100
- }
101
- }
102
-
103
- module.exports = require('../../lib/events/cli')('set', set)
@@ -1,23 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
- const mask = require('../../../lib/helpers/mask')
4
-
5
- function device () {
6
- const options = this.opts()
7
-
8
- try {
9
- const value = new Session().devicePublicKey()
10
- if (value && value.length > 1) {
11
- console.log(options.unmask ? value : mask(value, 6))
12
- return
13
- }
14
-
15
- logger.error('missing device. Try generating one with [dotenvx armor login].')
16
- return { exitCode: 1 }
17
- } catch (error) {
18
- logger.error(error.message)
19
- return { exitCode: 1, error }
20
- }
21
- }
22
-
23
- module.exports = device
@@ -1,20 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
-
4
- function hostname () {
5
- try {
6
- const value = new Session().hostname()
7
- if (value && value.length > 1) {
8
- console.log(value)
9
- return
10
- }
11
-
12
- logger.error('missing hostname. Try running [dotenvx armor login].')
13
- return { exitCode: 1 }
14
- } catch (error) {
15
- logger.error(error.message)
16
- return { exitCode: 1, error }
17
- }
18
- }
19
-
20
- module.exports = hostname
@@ -1,14 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
-
4
- function off () {
5
- try {
6
- new Session().turnOff()
7
- logger.success('✔ armor: off')
8
- } catch (error) {
9
- logger.error(error.message)
10
- return { exitCode: 1, error }
11
- }
12
- }
13
-
14
- module.exports = off
@@ -1,14 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
-
4
- function on () {
5
- try {
6
- new Session().turnOn()
7
- logger.success('✔ armor: on')
8
- } catch (error) {
9
- logger.error(error.message)
10
- return { exitCode: 1, error }
11
- }
12
- }
13
-
14
- module.exports = on
@@ -1,20 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
-
4
- function path () {
5
- try {
6
- const value = new Session().path()
7
- if (value && value.length > 1) {
8
- console.log(value)
9
- return
10
- }
11
-
12
- logger.error('missing path. Try running [dotenvx armor login].')
13
- return { exitCode: 1 }
14
- } catch (error) {
15
- logger.error(error.message)
16
- return { exitCode: 1, error }
17
- }
18
- }
19
-
20
- module.exports = path
@@ -1,23 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
- const mask = require('../../../lib/helpers/mask')
4
-
5
- function token () {
6
- const options = this.opts()
7
-
8
- try {
9
- const value = new Session().token()
10
- if (value && value.length > 1) {
11
- console.log(options.unmask ? value : mask(value))
12
- return
13
- }
14
-
15
- logger.error('missing token. Try generating one with [dotenvx armor login].')
16
- return { exitCode: 1 }
17
- } catch (error) {
18
- logger.error(error.message)
19
- return { exitCode: 1, error }
20
- }
21
- }
22
-
23
- module.exports = token
@@ -1,20 +0,0 @@
1
- const { logger } = require('../../../shared/logger')
2
- const Session = require('../../../db/session')
3
-
4
- function username () {
5
- try {
6
- const value = new Session().username()
7
- if (value) {
8
- console.log(value)
9
- return
10
- }
11
-
12
- logger.error('login required. Try running [dotenvx armor login].')
13
- return { exitCode: 1 }
14
- } catch (error) {
15
- logger.error(error.message)
16
- return { exitCode: 1, error }
17
- }
18
- }
19
-
20
- module.exports = username
@@ -1,15 +0,0 @@
1
- const childProcess = require('child_process')
2
-
3
- const INSTALL_COMMAND = 'curl -sfS https://dotenvx.sh | sh'
4
-
5
- function update () {
6
- if (process.pkg) {
7
- childProcess.execSync(INSTALL_COMMAND, { stdio: 'inherit' })
8
- return
9
- }
10
-
11
- console.log('global: npm install -g @dotenvx/dotenvx@latest')
12
- console.log('local: npm install @dotenvx/dotenvx@latest --save')
13
- }
14
-
15
- module.exports = update
@@ -1,16 +0,0 @@
1
- // Command lifecycle only. Returning an outcome does not opt into event tracking.
2
- module.exports = function commandAction (action) {
3
- return async function (...args) {
4
- const result = await action.apply(this, args)
5
- if (Number.isInteger(result?.exitCode)) {
6
- // Pipe writes are asynchronous. Flush both streams before forcing exit so
7
- // successful output and failure diagnostics cannot be silently truncated.
8
- await Promise.all([process.stdout, process.stderr].map(stream => {
9
- if (!stream.writable || stream.destroyed) return Promise.resolve()
10
- return new Promise(resolve => stream.write('', 'utf8', resolve))
11
- }))
12
- process.exit(result.exitCode)
13
- }
14
- return result
15
- }
16
- }