@dotenvx/dotenvx 2.38.2 → 3.0.0-beta.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.
Files changed (271) hide show
  1. package/README.md +186 -3315
  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 +139 -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,52 +0,0 @@
1
- const { execFileSync, spawnSync } = require('child_process')
2
- const nativeStoreError = require('./nativeStoreError')
3
-
4
- const SECURITY_BIN = '/usr/bin/security'
5
- const SERVICE = 'dotenvx'
6
-
7
- function quoteArgument (value) {
8
- if (typeof value !== 'string' || /[\r\n\0]/.test(value)) throw new Error('invalid Keychain argument')
9
- return '"' + value.replace(/[\\"]/g, '\\$&') + '"'
10
- }
11
-
12
- module.exports = {
13
- get (key) {
14
- try {
15
- return execFileSync(SECURITY_BIN, ['find-generic-password', '-s', SERVICE, '-a', key, '-w'], {
16
- timeout: 10000,
17
- killSignal: 'SIGKILL',
18
- encoding: 'utf8',
19
- stdio: ['ignore', 'pipe', 'ignore']
20
- }).trim()
21
- } catch (error) {
22
- throw nativeStoreError('failed to read private key from macOS Keychain', error)
23
- }
24
- },
25
-
26
- set (key, value, label) {
27
- try {
28
- const input = ['add-generic-password', '-U', '-s', SERVICE, '-a', key, '-l', label, '-w', value].map(quoteArgument).join(' ') + '\n'
29
- // security's 4096-byte line buffer must also consume the newline and NUL.
30
- if (Buffer.byteLength(input, 'utf8') >= 4096) throw new Error('Keychain command too long')
31
- // Interactive security can exit zero on failure, so inspect stderr too.
32
- const result = spawnSync(SECURITY_BIN, ['-i'], {
33
- input,
34
- timeout: 10000,
35
- killSignal: 'SIGKILL',
36
- stdio: ['pipe', 'ignore', 'pipe']
37
- })
38
- if (result.error) throw result.error
39
- if (result.status !== 0 || result.signal || result.stderr.length > 0) throw new Error('Keychain write failed')
40
- } catch (error) {
41
- throw nativeStoreError('failed to save private key to macOS Keychain', error)
42
- }
43
- },
44
-
45
- delete (key) {
46
- try {
47
- execFileSync(SECURITY_BIN, ['delete-generic-password', '-s', SERVICE, '-a', key], { timeout: 10000, killSignal: 'SIGKILL', stdio: 'ignore' })
48
- } catch (error) {
49
- throw nativeStoreError('failed to delete private key from macOS Keychain', error)
50
- }
51
- }
52
- }
@@ -1,22 +0,0 @@
1
- function mask (str, showChar = 6) {
2
- if (!str || str.length < 1) {
3
- return ''
4
- }
5
-
6
- const number = Number(showChar)
7
- showChar = 0
8
- if (Number.isFinite(number)) {
9
- showChar = Math.abs(Math.trunc(number))
10
- }
11
-
12
- let visibleChars = Math.min(showChar, Math.ceil(str.length / 2))
13
- if (str.length === 1) {
14
- visibleChars = 0
15
- }
16
- const visiblePart = str.slice(0, visibleChars)
17
- const maskedPart = '*'.repeat(str.length - visibleChars)
18
-
19
- return visiblePart + maskedPart
20
- }
21
-
22
- module.exports = mask
@@ -1,15 +0,0 @@
1
- const { scan, upsert } = require('@dotenvx/primitives')
2
-
3
- const mask = require('./mask')
4
-
5
- function maskEnvSrc (envSrc, showChar) {
6
- const { parsed } = scan(envSrc)
7
-
8
- for (const [key, values] of Object.entries(parsed)) {
9
- envSrc = upsert(envSrc, key, values.map(value => mask(value, showChar)))
10
- }
11
-
12
- return envSrc
13
- }
14
-
15
- module.exports = maskEnvSrc
@@ -1,29 +0,0 @@
1
- const mask = require('./mask')
2
-
3
- function maskProcessedEnvs (processedEnvs, processEnv, showChar) {
4
- // Track every key resolved from the requested env sources so the same keys
5
- // can also be masked in the environment receiving the resolved values.
6
- const resolvedKeys = new Set()
7
-
8
- for (const processedEnv of processedEnvs) {
9
- for (const key of Object.keys(processedEnv.parsed || {})) {
10
- resolvedKeys.add(key)
11
- }
12
-
13
- // These values may be logged, so mask each resolver reporting bucket.
14
- for (const values of [processedEnv.parsed, processedEnv.injected, processedEnv.existed]) {
15
- for (const key of Object.keys(values || {})) {
16
- values[key] = mask(values[key], showChar)
17
- }
18
- }
19
- }
20
-
21
- // Leave unrelated inherited environment variables unchanged.
22
- for (const key of resolvedKeys) {
23
- if (processEnv[key] !== undefined) {
24
- processEnv[key] = mask(processEnv[key], showChar)
25
- }
26
- }
27
- }
28
-
29
- module.exports = maskProcessedEnvs
@@ -1,5 +0,0 @@
1
- const { derive } = require('@dotenvx/primitives')
2
-
3
- module.exports = function matchesStoredKey (publicKey, value) {
4
- try { return derive(value) === publicKey } catch { return false }
5
- }
@@ -1,10 +0,0 @@
1
- // Never attach subprocess errors: their command/output may contain private keys.
2
- function nativeStoreError (message, error, linux = false) {
3
- const unavailable = error.code === 'ENOENT' || (linux &&
4
- /org\.freedesktop\.DBus\.Error\.(ServiceUnknown|NoServer)|Cannot autolaunch D-Bus without X11|Failed to connect to socket .*: No such file or directory/.test(String(error.stderr || '')))
5
- const result = new Error(message)
6
- result.code = unavailable ? 'NATIVE_UNAVAILABLE' : 'NATIVE_ACCESS_FAILED'
7
- return result
8
- }
9
-
10
- module.exports = nativeStoreError
@@ -1,13 +0,0 @@
1
- function normalizeDotenvConfigConvention (
2
- /** @type {import('../main').DotenvConfigOptions} */ options
3
- ) {
4
- const convention = process.env.DOTENV_CONVENTION || process.env.DOTENV_CONFIG_CONVENTION
5
-
6
- if (!options.convention && convention) {
7
- options.convention = convention
8
- }
9
-
10
- return options
11
- }
12
-
13
- module.exports = normalizeDotenvConfigConvention
@@ -1,18 +0,0 @@
1
- function normalizeDotenvConfigIgnore (
2
- /** @type {import('../main').DotenvConfigOptions} */ options
3
- ) {
4
- const configuredIgnore = process.env.DOTENV_IGNORE ?? process.env.DOTENV_CONFIG_IGNORE ?? ''
5
- const configIgnore = configuredIgnore
6
- .split(',')
7
- .map(code => code.trim())
8
- .filter(Boolean)
9
-
10
- if (configIgnore.length < 1) return options
11
-
12
- return {
13
- ...options,
14
- ignore: [...(options.ignore || []), ...configIgnore]
15
- }
16
- }
17
-
18
- module.exports = normalizeDotenvConfigIgnore
@@ -1,14 +0,0 @@
1
- const TYPE_ENV_FILE = 'envFile'
2
-
3
- function normalizeDotenvConfigPath (envs = [], processEnv = process.env) {
4
- if (envs.some(env => env.type === TYPE_ENV_FILE)) return envs
5
-
6
- const configuredEnvFiles = processEnv.DOTENV_FILE || processEnv.DOTENV_PATH || processEnv.DOTENV_F
7
- if (!configuredEnvFiles) return envs
8
-
9
- const envFiles = configuredEnvFiles.split(',').map(value => value.trim()).filter(Boolean)
10
-
11
- return envFiles.map(value => ({ type: TYPE_ENV_FILE, value })).concat(envs)
12
- }
13
-
14
- module.exports = normalizeDotenvConfigPath
@@ -1,13 +0,0 @@
1
- function normalizeDotenvConfigQuiet (
2
- /** @type {import('../main').DotenvConfigOptions} */ options
3
- ) {
4
- const quiet = process.env.DOTENV_QUIET ?? process.env.DOTENV_CONFIG_QUIET
5
-
6
- if (quiet === 'true') {
7
- options.quiet = true
8
- }
9
-
10
- return options
11
- }
12
-
13
- module.exports = normalizeDotenvConfigQuiet
@@ -1,5 +0,0 @@
1
- function normalizeToken (token) {
2
- return token == null ? '' : token
3
- }
4
-
5
- module.exports = normalizeToken
@@ -1,7 +0,0 @@
1
- const { open } = require('@dotenvx/tooling')
2
-
3
- async function openUrl (url) {
4
- return await open(url, { wait: false })
5
- }
6
-
7
- module.exports = openUrl
@@ -1,3 +0,0 @@
1
- const { name, version, description } = require('../../../package.json')
2
-
3
- module.exports = { name, version, description }
@@ -1,115 +0,0 @@
1
- const { parse, parseSync, parsearrays, publickeys, keyringSync } = require('@dotenvx/primitives')
2
- const { file } = require('@dotenvx/providers')
3
- const SERVER_SIDE_DECRYPTION_REQUIRED = 'SERVER_SIDE_DECRYPTION_REQUIRED'
4
-
5
- function withFileKeys (src, options, sync = false) {
6
- const keys = file({ fk: options.fk })
7
- const fallback = options.provider
8
- const keySources = {}
9
- const environment = keyringSync({ processEnv: options.processEnv || process.env, fk: [], provider: null })
10
- for (const key of publickeys(src)) {
11
- if (environment[key]) keySources[key] = 'environment'
12
- }
13
- function found (publicKey, ring, source) {
14
- if (ring[publicKey]) keySources[publicKey] = source || 'custom'
15
- return ring
16
- }
17
- const provider = sync
18
- ? publicKey => {
19
- const ring = keys.getSync(publicKey)
20
- return ring[publicKey] ? found(publicKey, ring, '.env.keys') : found(publicKey, fallback ? fallback(publicKey) : {}, fallback && fallback.sourceFor && fallback.sourceFor(publicKey))
21
- }
22
- : async publicKey => {
23
- const ring = await keys.get(publicKey)
24
- return ring[publicKey] ? found(publicKey, ring, '.env.keys') : found(publicKey, fallback ? await fallback(publicKey) : {}, fallback && fallback.sourceFor && fallback.sourceFor(publicKey))
25
- }
26
- return {
27
- ...options,
28
- keySources,
29
- provider,
30
- // Provider lookup requires a public key. Keep legacy key discovery for
31
- // encrypted files that do not declare one, and for error recovery.
32
- fk: publickeys(src).length ? [] : options.fk,
33
- fallbackFk: options.fk
34
- }
35
- }
36
-
37
- function decryptOptions (error) {
38
- const meta = error.meta || {}
39
-
40
- return {
41
- publicKey: meta.public_key,
42
- grantToken: meta.grant_token,
43
- error
44
- }
45
- }
46
-
47
- function parseOptionsWithoutProvider (options) {
48
- return {
49
- ...options,
50
- fk: options.fallbackFk,
51
- provider: null,
52
- decryptor: null
53
- }
54
- }
55
-
56
- function failedKeyAccessFallback (result, error) {
57
- return {
58
- ...result,
59
- errors: [error, ...(result.errors || [])]
60
- }
61
- }
62
-
63
- async function parseWithDecryptor (src, options = {}) {
64
- return parseWith(src, options, parse)
65
- }
66
-
67
- parseWithDecryptor.arrays = async function parsearraysWithDecryptor (src, options = {}) {
68
- return parseWith(src, options, parsearrays)
69
- }
70
-
71
- async function parseWith (src, options, parser) {
72
- options = withFileKeys(src, options)
73
- try {
74
- return { ...await parser(src, options), keySources: options.keySources }
75
- } catch (error) {
76
- if (error.code !== SERVER_SIDE_DECRYPTION_REQUIRED || typeof options.decryptor !== 'function') {
77
- if (typeof options.provider !== 'function') throw error
78
-
79
- const result = await parser(src, parseOptionsWithoutProvider(options))
80
- return failedKeyAccessFallback(result, error)
81
- }
82
-
83
- try {
84
- const result = await options.decryptor(src, decryptOptions(error))
85
- return { ...await parser(result.src, parseOptionsWithoutProvider(options)), keySources: { [decryptOptions(error).publicKey]: 'armor' } }
86
- } catch (decryptorError) {
87
- const result = await parser(src, parseOptionsWithoutProvider(options))
88
- return failedKeyAccessFallback(result, decryptorError)
89
- }
90
- }
91
- }
92
-
93
- parseWithDecryptor.sync = function parseWithDecryptorSync (src, options = {}) {
94
- options = withFileKeys(src, options, true)
95
- try {
96
- return { ...parseSync(src, options), keySources: options.keySources }
97
- } catch (error) {
98
- if (error.code !== SERVER_SIDE_DECRYPTION_REQUIRED || typeof options.decryptor !== 'function') {
99
- if (typeof options.provider !== 'function') throw error
100
-
101
- const result = parseSync(src, parseOptionsWithoutProvider(options))
102
- return failedKeyAccessFallback(result, error)
103
- }
104
-
105
- try {
106
- const result = options.decryptor(src, decryptOptions(error))
107
- return { ...parseSync(result.src, parseOptionsWithoutProvider(options)), keySources: { [decryptOptions(error).publicKey]: 'armor' } }
108
- } catch (decryptorError) {
109
- const result = parseSync(src, parseOptionsWithoutProvider(options))
110
- return failedKeyAccessFallback(result, decryptorError)
111
- }
112
- }
113
- }
114
-
115
- module.exports = parseWithDecryptor
@@ -1,9 +0,0 @@
1
- const { scan, encrypted } = require('@dotenvx/primitives')
2
-
3
- module.exports = function plaintextKeys (content) {
4
- return Object.entries(scan(content).parsed)
5
- .filter(([key, values]) => !key.startsWith('DOTENV_PUBLIC_KEY') && values.some(value =>
6
- value.trim() !== '' && !encrypted(value) && !value.startsWith('op://') && !value.startsWith('bw://')
7
- ))
8
- .map(([key]) => key)
9
- }
@@ -1 +0,0 @@
1
- module.exports = ['.env*', '*.env', '.flaskenv', '.dev.vars*', '.env.d/*']
@@ -1,17 +0,0 @@
1
- function prependPublicKey (publicKeyName, publicKey, filename, relativeFilepath = '.env.keys') {
2
- const comment = relativeFilepath === '.env.keys'
3
- ? ''
4
- : ` # -fk ${relativeFilepath}`
5
-
6
- return [
7
- '#/-------------------[DOTENV_PUBLIC_KEY]--------------------/',
8
- '#/ public-key encryption for .env files /',
9
- '#/ [how it works](https://dotenvx.com/encryption) /',
10
- '#/----------------------------------------------------------/',
11
- `${publicKeyName}="${publicKey}"${comment}`,
12
- '',
13
- `# ${filename}`
14
- ].join('\n')
15
- }
16
-
17
- module.exports = prependPublicKey
@@ -1,16 +0,0 @@
1
- function preserveShebang (envSrc) {
2
- const [firstLine, ...remainingLines] = envSrc.split('\n')
3
- let firstLinePreserved = ''
4
-
5
- if (firstLine.startsWith('#!')) {
6
- firstLinePreserved = firstLine + '\n'
7
- envSrc = remainingLines.join('\n')
8
- }
9
-
10
- return {
11
- firstLinePreserved,
12
- envSrc
13
- }
14
- }
15
-
16
- module.exports = preserveShebang
@@ -1,169 +0,0 @@
1
- const { Enquirer } = require('@dotenvx/tooling')
2
-
3
- const enquirer = new Enquirer()
4
-
5
- function choicesForSelect (choices) {
6
- return choices.map(choice => {
7
- if (typeof choice === 'string') return choice
8
-
9
- return {
10
- name: choice.value,
11
- message: choice.name || choice.value,
12
- ...(choice.role ? { role: choice.role } : {}),
13
- ...(choice.disabled !== undefined ? { disabled: choice.disabled === true ? '(unavailable)' : choice.disabled } : {})
14
- }
15
- })
16
- }
17
-
18
- function enquirerOptions (context = {}) {
19
- const options = {
20
- // Enquirer names the render stream stdout; use stderr so stdout stays machine-readable.
21
- stdout: context.output || process.stderr
22
- }
23
-
24
- if (context.input) {
25
- options.stdin = context.input
26
- }
27
-
28
- return options
29
- }
30
-
31
- function clearLastLine (stream) {
32
- if (stream && typeof stream.moveCursor === 'function' && typeof stream.clearLine === 'function') {
33
- stream.moveCursor(0, -1)
34
- stream.clearLine(0)
35
- return
36
- }
37
-
38
- if (stream && typeof stream.write === 'function') {
39
- stream.write('\x1B[1A\x1B[2K')
40
- }
41
- }
42
-
43
- async function select ({ message, choices, navigation, backValue, initial, prefix, footer }, context) {
44
- try {
45
- if (navigation) {
46
- const CustodySelect = require('./custodySelect')
47
- return await new CustodySelect({ message, choices: choicesForSelect(choices), backValue, initial, footer, ...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}), ...enquirerOptions(context) }).run()
48
- }
49
- const answer = await enquirer.prompt({
50
- type: 'select',
51
- name: 'value',
52
- ...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}),
53
- message,
54
- footer,
55
- choices: choicesForSelect(choices),
56
- ...enquirerOptions(context)
57
- })
58
-
59
- return answer.value
60
- } catch (error) {
61
- if (error instanceof Error) throw error
62
- throw Object.assign(new Error('prompt cancelled'), { code: 'PROMPT_CANCELLED' })
63
- }
64
- }
65
-
66
- async function multiselect ({ message, choices, initial = [], submitLabel }, context) {
67
- try {
68
- const options = {
69
- type: 'multiselect',
70
- name: 'value',
71
- message,
72
- choices: choicesForSelect(choices),
73
- initial,
74
- ...enquirerOptions(context)
75
- }
76
- if (submitLabel) {
77
- const Checklist = require('./checklist')
78
- return await new Checklist({ ...options, submitLabel }).run()
79
- }
80
- const answer = await enquirer.prompt(options)
81
- return answer.value
82
- } catch {
83
- const error = new Error('prompt cancelled')
84
- error.code = 'PROMPT_CANCELLED'
85
- throw error
86
- }
87
- }
88
-
89
- async function input ({ message, initial }, context) {
90
- try {
91
- const answer = await enquirer.prompt({
92
- type: 'input',
93
- name: 'value',
94
- ...(initial !== undefined
95
- ? {
96
- onRun () {
97
- this.input = String(initial)
98
- this.cursor = this.input.length
99
- }
100
- }
101
- : {}),
102
- message,
103
- ...enquirerOptions(context)
104
- })
105
- return answer.value
106
- } catch {
107
- const error = new Error('prompt cancelled')
108
- error.code = 'PROMPT_CANCELLED'
109
- throw error
110
- }
111
- }
112
-
113
- async function confirm ({ message, initial = false }, context) {
114
- try {
115
- const answer = await enquirer.prompt({
116
- type: 'confirm',
117
- name: 'value',
118
- message,
119
- initial,
120
- ...enquirerOptions(context)
121
- })
122
- return answer.value === true
123
- } catch {
124
- const error = new Error('prompt cancelled')
125
- error.code = 'PROMPT_CANCELLED'
126
- throw error
127
- }
128
- }
129
-
130
- async function password ({ message, prefix, separator }, context) {
131
- const output = (context && context.output) || process.stderr
132
-
133
- try {
134
- const answer = await enquirer.prompt({
135
- type: 'password',
136
- name: 'value',
137
- message,
138
- symbols: {
139
- prefix: {
140
- pending: prefix,
141
- submitted: prefix,
142
- cancelled: prefix
143
- },
144
- separator: {
145
- pending: separator,
146
- submitted: separator,
147
- cancelled: separator
148
- }
149
- },
150
- ...enquirerOptions(context)
151
- })
152
-
153
- clearLastLine(output)
154
- return answer.value
155
- } catch (error) {
156
- clearLastLine(output)
157
- const e = new Error('prompt cancelled')
158
- e.code = 'PROMPT_CANCELLED'
159
- throw e
160
- }
161
- }
162
-
163
- module.exports = {
164
- input,
165
- confirm,
166
- multiselect,
167
- password,
168
- select
169
- }
@@ -1,64 +0,0 @@
1
- const fs = require('fs')
2
- const fsx = require('./fsx')
3
- const path = require('path')
4
- const os = require('os')
5
- const { execFileSync } = require('child_process')
6
- const patterns = require('./precommitEnvPatterns')
7
-
8
- const git = (...args) => execFileSync('git', ['config', '--global', ...args], { encoding: 'utf8' }).trim()
9
- function get (key, pathname = false) {
10
- try { return git('--includes', ...(pathname ? ['--path'] : []), '--get', key) } catch (error) {
11
- if (error.status !== 1) throw error
12
- return ''
13
- }
14
- }
15
- function file (key, name) {
16
- return get(key, true) || path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'git', name)
17
- }
18
- function read (filename) {
19
- return fs.existsSync(filename) ? fs.readFileSync(filename, 'utf8') : ''
20
- }
21
- function removeLines (filename, lines) {
22
- const current = read(filename)
23
- const updated = current.split(/(?<=\n)/).filter(line => !lines.includes(line.replace(/\r?\n$/, ''))).join('')
24
- if (updated !== current) fsx.writeFileXSync(filename, updated)
25
- }
26
- function state () {
27
- const attributes = read(file('core.attributesFile', 'attributes'))
28
- const filter = ['dotenvx', 'dotenvx.protect'].some(driver => {
29
- const clean = get(`filter.${driver}.clean`)
30
- const processFilter = get(`filter.${driver}.process`)
31
- const recognized = processFilter ? / protect --git-process$/.test(processFilter) : /(?:protect --git-file|precommit --clean) %f$/.test(clean)
32
- return recognized && get(`filter.${driver}.required`) === 'true' && attributes.split(/\r?\n/).some(line => line.endsWith(` filter=${driver}`))
33
- })
34
- const ignore = read(file('core.excludesFile', 'ignore')).split(/\r?\n/).includes('.env.keys*')
35
- return { filter, ignore, configured: get('dotenvx.protect.configured') === 'true' || filter || ignore }
36
- }
37
- function removeFilter () {
38
- const drivers = ['dotenvx', 'dotenvx.protect']
39
- for (const driver of drivers) {
40
- const processFilter = get(`filter.${driver}.process`)
41
- if (processFilter && !/ protect --git-process$/.test(processFilter)) throw new Error(`Custom filter.${driver}.process found; remove it manually to disable protection.`)
42
- const clean = get(`filter.${driver}.clean`)
43
- if (clean && clean !== 'cat' && !/(?:protect --git-file|precommit --clean) %f$/.test(clean)) {
44
- throw new Error(`Custom filter.${driver}.clean found; remove it manually to disable protection.`)
45
- }
46
- }
47
- removeLines(file('core.attributesFile', 'attributes'), drivers.flatMap(driver => patterns.map(pattern => `${pattern.includes('/') ? '**/' : ''}${pattern} filter=${driver}`)))
48
- // Keep any remaining or inherited attributes harmless, including custom patterns.
49
- for (const driver of drivers) {
50
- git(`filter.${driver}.required`, 'false')
51
- git(`filter.${driver}.process`, '')
52
- git(`filter.${driver}.clean`, 'cat')
53
- }
54
- }
55
- function removeIgnore () {
56
- const filename = file('core.excludesFile', 'ignore')
57
- if (!read(filename).split(/\r?\n/).includes('.env.keys*')) return
58
- if (get('dotenvx.protect.ignoreFile', true) !== filename) {
59
- throw new Error(`The existing .env.keys* rule in ${filename} has no dotenvx ownership record. Remove it manually to disable it; other ignore rules will be preserved.`)
60
- }
61
- removeLines(filename, ['.env.keys*'])
62
- git('--unset-all', 'dotenvx.protect.ignoreFile')
63
- }
64
- module.exports = { state, removeFilter, removeIgnore, markConfigured: () => git('dotenvx.protect.configured', 'true') }
@@ -1,27 +0,0 @@
1
- const path = require('path')
2
- const { which } = require('@dotenvx/tooling')
3
-
4
- function shellQuote (value) {
5
- const escapedQuote = ['\'', '"', '\'', '"', '\''].join('')
6
- return `'${`${value}`.replace(/'/g, escapedQuote)}'`
7
- }
8
-
9
- function ptyCommand (commandArgs, platform = process.platform) {
10
- if (!['darwin', 'linux'].includes(platform)) return null
11
-
12
- let script
13
- try {
14
- script = path.resolve(which.sync('script'))
15
- } catch (e) {
16
- return null
17
- }
18
-
19
- if (platform === 'darwin') {
20
- return [script, '-q', '/dev/null', ...commandArgs]
21
- }
22
-
23
- // util-linux script only accepts the child command as a shell string.
24
- return [script, '-qefc', commandArgs.map(shellQuote).join(' '), '/dev/null']
25
- }
26
-
27
- module.exports = ptyCommand