@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
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('node:child_process')
3
+ const { resolveCli } = require('../lib/cli.cjs')
4
+
5
+ const libc = process.platform === 'linux' ? (process.report.getReport().header.glibcVersionRuntime ? '-gnu' : '-musl') : ''
6
+ const platform = `${process.platform}-${process.arch}${libc}`
7
+ let binary
8
+ try {
9
+ binary = resolveCli()
10
+ } catch (error) {
11
+ console.error(error.message)
12
+ process.exit(1)
13
+ }
14
+
15
+ const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' })
16
+ const signals = process.platform === 'win32' ? ['SIGINT', 'SIGTERM'] : ['SIGINT', 'SIGTERM', 'SIGHUP']
17
+ const handlers = new Map(signals.map(signal => [signal, () => child.kill(signal)]))
18
+ for (const [signal, handler] of handlers) process.on(signal, handler)
19
+ const cleanup = () => {
20
+ for (const [signal, handler] of handlers) process.removeListener(signal, handler)
21
+ }
22
+
23
+ child.on('error', error => {
24
+ cleanup()
25
+ console.error(`Could not launch the dotenvx CLI for ${platform}: ${error.message}`)
26
+ console.error('Reinstall @dotenvx/dotenvx with its native files included. For a local Forge checkout, run npm run build:dotenvx-nodejs.')
27
+ console.error('To use a standalone installation, set DOTENVX_CLI to the absolute path of its executable.')
28
+ process.exitCode = 1
29
+ })
30
+ child.on('exit', (code, signal) => {
31
+ cleanup()
32
+ if (signal) process.kill(process.pid, signal)
33
+ else process.exitCode = code
34
+ })
package/config.cjs ADDED
@@ -0,0 +1 @@
1
+ require('./index.cjs').config()
package/config.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/config.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { config } from './index.mjs'
2
+ config()
package/index.cjs ADDED
@@ -0,0 +1,141 @@
1
+ const path = require('node:path')
2
+ const { fileURLToPath } = require('node:url')
3
+ const native = require('./native.cjs')
4
+ const { applyRedaction } = require('./lib/redaction.cjs')
5
+ const { validateOptions } = require('./lib/validateOptions.cjs')
6
+ const { resolveCli } = require('./lib/cli.cjs')
7
+
8
+ function environment (value) {
9
+ const result = Object.create(null)
10
+ for (const [key, item] of Object.entries(value)) {
11
+ if (item !== undefined && item !== null) result[key] = String(item)
12
+ }
13
+ return result
14
+ }
15
+
16
+ function filePath (value) {
17
+ if (value instanceof URL) return fileURLToPath(value)
18
+ if (typeof value !== 'string') throw new TypeError('dotenvx paths must be strings or file URLs')
19
+ return value
20
+ }
21
+
22
+ function optionsFor (options = {}, method = 'config') {
23
+ validateOptions(options, method)
24
+ const target = options.processEnv ?? process.env
25
+ if (!target || typeof target !== 'object' || Array.isArray(target)) throw new TypeError('processEnv must be an object')
26
+ const env = environment(target)
27
+ if (options.noArmor === true) env.DOTENVX_NO_ARMOR = 'true'
28
+ if (options.noNative === true) env.DOTENVX_NO_NATIVE = 'true'
29
+ if (options.no1Password === true) env.DOTENVX_NO_1PASSWORD = 'true'
30
+ if (options.noBitwarden === true) env.DOTENVX_NO_BITWARDEN = 'true'
31
+ if (options.token !== undefined) env.DOTENVX_ARMOR_TOKEN = String(options.token)
32
+ let sources = []
33
+ let implicit = true
34
+ const configuredPath = options.path ?? (!env.DOTENV_FILE && !env.DOTENV_PATH ? env.DOTENV_CONFIG_PATH : undefined)
35
+ if (options.envs !== undefined) {
36
+ if (!Array.isArray(options.envs)) throw new TypeError('envs must be an array')
37
+ implicit = false
38
+ sources = options.envs.map(source => {
39
+ if (source.type === 'envFile') return { type: 'file', value: filePath(source.value) }
40
+ if (source.type === 'env' && (typeof source.value === 'string' || Buffer.isBuffer(source.value))) return { type: 'inline', value: source.value.toString() }
41
+ throw new TypeError('envs must contain envFile paths or env strings/Buffers')
42
+ })
43
+ } else if (configuredPath !== undefined) {
44
+ implicit = false
45
+ sources = (Array.isArray(configuredPath) ? configuredPath : [configuredPath]).map(value => ({ type: 'file', value: filePath(value) }))
46
+ }
47
+ const keyFiles = options.envKeysFile ?? options.keyFiles
48
+ const input = {
49
+ cwd: path.resolve(options.cwd || process.cwd()),
50
+ process_env: env,
51
+ sources,
52
+ implicit_files: implicit,
53
+ overload: options.overload ?? options.override ?? env.DOTENV_CONFIG_OVERRIDE === 'true',
54
+ strict: options.strict ?? false,
55
+ ignore: typeof options.ignore === 'string' ? options.ignore.split(',') : options.ignore || [],
56
+ convention: options.convention,
57
+ environment_name: options.environment,
58
+ resolve_references: options.resolveReferences ?? false,
59
+ no_1password: options.no1Password === true,
60
+ no_bitwarden: options.noBitwarden === true
61
+ }
62
+ if (keyFiles !== undefined) input.key_files = (Array.isArray(keyFiles) ? keyFiles : [keyFiles]).map(filePath)
63
+ if (method !== 'parse') input.custody_cli = resolveCli({ env })
64
+ return { input, options, target, env }
65
+ }
66
+
67
+ function diagnosticError (diagnostic) {
68
+ const error = new Error(diagnostic.message)
69
+ error.code = diagnostic.code
70
+ if (diagnostic.path) error.path = diagnostic.path
71
+ return error
72
+ }
73
+
74
+ function report (loaded, prepared, summary = false) {
75
+ applyRedaction(loaded.secrets || [])
76
+ const { options, env } = prepared
77
+ const silent = options.logLevel === 'silent'
78
+ const quiet = options.quiet === true || (env.DOTENV_QUIET ?? env.DOTENV_CONFIG_QUIET) === 'true'
79
+ for (const diagnostic of loaded.diagnostics) {
80
+ if (!silent) process.stderr.write(`☠ ${diagnostic.message}\n`)
81
+ }
82
+ const error = loaded.diagnostics.length ? diagnosticError(loaded.diagnostics.at(-1)) : undefined
83
+ if (loaded.fatal) throw error || new Error('dotenvx loading failed')
84
+ if (summary && !quiet && !silent && !['error', 'warn'].includes(options.logLevel) && !loaded.error_count && loaded.files.length) {
85
+ process.stderr.write(`${loaded.inject_summary}\n`)
86
+ }
87
+ return error
88
+ }
89
+
90
+ function config (options = {}) {
91
+ const prepared = optionsFor(options, 'config')
92
+ const loaded = JSON.parse(native.loadEnvSync(JSON.stringify(prepared.input)))
93
+ const error = report(loaded, prepared, true)
94
+ for (const [key, value] of Object.entries(loaded.injected)) {
95
+ Object.defineProperty(prepared.target, key, { value, configurable: true, enumerable: true, writable: true })
96
+ }
97
+ return error ? { parsed: loaded.values, error } : { parsed: loaded.values }
98
+ }
99
+
100
+ function parse (source, options = {}) {
101
+ if (typeof source !== 'string' && !Buffer.isBuffer(source)) throw new TypeError('source must be a string or Buffer')
102
+ const prepared = optionsFor(options, 'parse')
103
+ const result = JSON.parse(native.parseEnv(source.toString(), JSON.stringify({
104
+ process_env: prepared.input.process_env,
105
+ private_key: options.privateKey,
106
+ overload: prepared.input.overload
107
+ })))
108
+ const ignored = new Set(prepared.input.ignore)
109
+ result.diagnostics = result.diagnostics.filter(error => !ignored.has(error.code))
110
+ report({ ...result, fatal: options.strict === true && result.diagnostics.length > 0 }, prepared)
111
+ return result.parsed
112
+ }
113
+
114
+ function getResult (key, loaded, prepared) {
115
+ report(loaded, prepared)
116
+ const values = prepared.options.all ? loaded.environment : loaded.values
117
+ if (key !== undefined) return Object.hasOwn(values, key) ? values[key] : undefined
118
+ const format = prepared.options.format
119
+ if (!format) return values
120
+ if (!['eval', 'eval-export', 'shell', 'colon'].includes(format)) throw new TypeError(`Unknown dotenvx output format: ${format}`)
121
+ const quote = value => `'${value.replaceAll("'", "'\\''")}'`
122
+ return Object.keys(values).sort().map(name => {
123
+ if (format === 'eval' || format === 'eval-export') {
124
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new TypeError(`Cannot export invalid shell variable name: ${name}`)
125
+ return `${format === 'eval-export' ? 'export ' : ''}${name}=${quote(values[name])}`
126
+ }
127
+ if (format === 'shell') return `${name}=${values[name]}`
128
+ if (format === 'colon') return `${name}:${values[name]}`
129
+ throw new TypeError(`Unknown dotenvx output format: ${format}`)
130
+ }).join(format === 'eval' || format === 'eval-export' ? '\n' : ' ')
131
+ }
132
+
133
+ function get (key, options = {}) {
134
+ if (key !== undefined && typeof key !== 'string') throw new TypeError('key must be a string')
135
+ const prepared = optionsFor(options, 'get')
136
+ return getResult(key, JSON.parse(native.loadEnvSync(JSON.stringify(prepared.input))), prepared)
137
+ }
138
+
139
+ const getSync = get
140
+
141
+ module.exports = { config, parse, get, getSync }
package/index.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ export type Environment = Record<string, string | undefined>;
2
+ export type Values = Record<string, string>;
3
+ export type EnvSource = { type: 'envFile'; value: string | URL } | { type: 'env'; value: string | Buffer };
4
+
5
+ export interface ConfigOptions {
6
+ path?: string | URL | Array<string | URL>;
7
+ envs?: EnvSource[];
8
+ cwd?: string;
9
+ processEnv?: Environment;
10
+ overload?: boolean;
11
+ override?: boolean;
12
+ strict?: boolean;
13
+ ignore?: string | string[];
14
+ envKeysFile?: string | URL | Array<string | URL>;
15
+ keyFiles?: string | URL | Array<string | URL>;
16
+ convention?: 'nextjs' | 'flow' | 'rails';
17
+ environment?: string;
18
+ encoding?: 'utf8' | 'utf-8';
19
+ quiet?: boolean;
20
+ logLevel?: 'error' | 'warn' | 'info' | 'silent';
21
+ resolveReferences?: boolean;
22
+ no1Password?: boolean;
23
+ noBitwarden?: boolean;
24
+ noArmor?: boolean;
25
+ noNative?: boolean;
26
+ token?: string;
27
+ }
28
+
29
+ export interface ParseOptions {
30
+ processEnv?: Environment;
31
+ privateKey?: string;
32
+ overload?: boolean;
33
+ override?: boolean;
34
+ strict?: boolean;
35
+ ignore?: string | string[];
36
+ logLevel?: ConfigOptions['logLevel'];
37
+ }
38
+
39
+ export interface GetOptions extends ConfigOptions {
40
+ all?: boolean;
41
+ format?: 'eval' | 'eval-export' | 'shell' | 'colon';
42
+ }
43
+
44
+ export interface DotenvError extends Error {
45
+ code: string;
46
+ path?: string;
47
+ }
48
+
49
+ export interface ConfigResult {
50
+ parsed: Values;
51
+ error?: DotenvError;
52
+ }
53
+
54
+ /** Resolve synchronously and populate process.env (or processEnv). Fatal errors throw before injection. */
55
+ export function config(options?: ConfigOptions): ConfigResult;
56
+ /** Parse/expand/decrypt a string or Buffer without reading files or mutating the environment. */
57
+ export function parse(source: string | Buffer, options?: ParseOptions): Values;
58
+ /** Resolve synchronously without mutating the environment. Blocks during file and custody lookups; failures throw synchronously. */
59
+ export function get(key: string, options?: GetOptions): string | undefined;
60
+ export function get(key?: undefined, options?: GetOptions & { format?: undefined }): Values;
61
+ export function get(key: undefined, options: GetOptions & { format: NonNullable<GetOptions['format']> }): string;
62
+ /** Alias of get; getSync === get. */
63
+ export const getSync: typeof get;
64
+
65
+ declare const dotenvx: { config: typeof config; parse: typeof parse; get: typeof get; getSync: typeof getSync };
66
+ export default dotenvx;
package/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import sdk from './index.cjs'
2
+ export const { config, parse, get, getSync } = sdk
3
+ export default sdk
package/lib/cli.cjs ADDED
@@ -0,0 +1,43 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { resolveNativeFile } = require('./native-package.cjs')
4
+
5
+ // Only standalone executables qualify. npm shims (including older dotenvx
6
+ // JavaScript CLIs) must not call another shim and recurse through PATH.
7
+ const nativeHeaders = new Set([
8
+ '7f454c46', // ELF
9
+ 'feedface', 'cefaedfe', 'feedfacf', 'cffaedfe', // Mach-O
10
+ 'cafebabe', 'bebafeca', 'cafebabf', 'bfbafeca' // Universal Mach-O
11
+ ])
12
+
13
+ function isStandalone (file) {
14
+ let fd
15
+ try {
16
+ fs.accessSync(file, fs.constants.X_OK)
17
+ if (!fs.statSync(file).isFile()) return false
18
+ fd = fs.openSync(file, 'r')
19
+ const header = Buffer.alloc(4)
20
+ if (fs.readSync(fd, header, 0, 4, 0) !== 4) return false
21
+ return header.subarray(0, 2).toString('hex') === '4d5a' || nativeHeaders.has(header.toString('hex'))
22
+ } catch {
23
+ return false
24
+ } finally {
25
+ if (fd !== undefined) fs.closeSync(fd)
26
+ }
27
+ }
28
+
29
+ function resolveCli ({ env = process.env, platform = process.platform, arch = process.arch, libc, root = path.resolve(__dirname, '..') } = {}) {
30
+ if (env.DOTENVX_CLI) return path.resolve(env.DOTENVX_CLI)
31
+ const searchPath = Object.entries(env).find(([key]) => platform === 'win32' ? key.toLowerCase() === 'path' : key === 'PATH')?.[1] || ''
32
+ const executable = platform === 'win32' ? 'dotenvx.exe' : 'dotenvx'
33
+ for (const directory of searchPath.split(platform === 'win32' ? ';' : ':')) {
34
+ if (!directory) continue
35
+ const candidate = path.resolve(directory, executable)
36
+ if (isStandalone(candidate)) return candidate
37
+ }
38
+
39
+ if (libc === undefined) libc = platform === 'linux' ? (process.report.getReport().header.glibcVersionRuntime ? '-gnu' : '-musl') : ''
40
+ return resolveNativeFile(executable, { platform: `${platform}-${arch}${libc}`, root })
41
+ }
42
+
43
+ module.exports = { resolveCli }
@@ -0,0 +1,21 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { createRequire } = require('node:module')
4
+ const { platforms, currentPlatform } = require('./platforms.cjs')
5
+
6
+ function resolveNativeFile (file, { platform = currentPlatform(), root = path.resolve(__dirname, '..') } = {}) {
7
+ const entry = platforms[platform]
8
+ if (!entry) throw new Error(`@dotenvx/dotenvx has no native package for ${platform}`)
9
+ const fromPackage = createRequire(path.join(root, 'package.json'))
10
+ try {
11
+ return fromPackage.resolve(`${entry.name}/${file}`)
12
+ } catch (cause) {
13
+ if (cause.code !== 'MODULE_NOT_FOUND') throw cause
14
+ // Local Forge builds work before platform packages have been published.
15
+ const local = path.join(root, 'native', file === 'dotenvx.node' ? `dotenvx-${platform}.node` : `dotenvx-cli-${platform}${file.endsWith('.exe') ? '.exe' : ''}`)
16
+ if (fs.existsSync(local)) return local
17
+ throw new Error(`Missing ${entry.name} for ${platform}. Reinstall @dotenvx/dotenvx with optional dependencies enabled (npm install --include=optional). In Forge, run npm run build:dotenvx-nodejs.`, { cause })
18
+ }
19
+ }
20
+
21
+ module.exports = { resolveNativeFile }
@@ -0,0 +1,18 @@
1
+ // Keep published names compatible with the existing standalone binary packages.
2
+ const platforms = {
3
+ 'darwin-arm64': { name: '@dotenvx/dotenvx-darwin-arm64', os: 'darwin', cpu: 'arm64', target: 'aarch64-apple-darwin', runner: 'macos-15' },
4
+ 'darwin-x64': { name: '@dotenvx/dotenvx-darwin-x86_64', os: 'darwin', cpu: 'x64', target: 'x86_64-apple-darwin', runner: 'macos-15-intel' },
5
+ 'linux-x64-gnu': { name: '@dotenvx/dotenvx-linux-x86_64', os: 'linux', cpu: 'x64', libc: 'glibc', target: 'x86_64-unknown-linux-gnu', runner: 'ubuntu-24.04', container: 'quay.io/pypa/manylinux_2_28_x86_64' },
6
+ 'linux-arm64-gnu': { name: '@dotenvx/dotenvx-linux-arm64', os: 'linux', cpu: 'arm64', libc: 'glibc', target: 'aarch64-unknown-linux-gnu', runner: 'ubuntu-24.04-arm', container: 'quay.io/pypa/manylinux_2_28_aarch64' },
7
+ 'linux-x64-musl': { name: '@dotenvx/dotenvx-linux-x86_64-musl', os: 'linux', cpu: 'x64', libc: 'musl', target: 'x86_64-unknown-linux-musl', runner: 'ubuntu-24.04', container: 'node:24-alpine' },
8
+ 'linux-arm64-musl': { name: '@dotenvx/dotenvx-linux-arm64-musl', os: 'linux', cpu: 'arm64', libc: 'musl', target: 'aarch64-unknown-linux-musl', runner: 'ubuntu-24.04-arm', container: 'node:24-alpine' },
9
+ 'win32-x64': { name: '@dotenvx/dotenvx-windows-x86_64', os: 'win32', cpu: 'x64', target: 'x86_64-pc-windows-msvc', runner: 'windows-2022' },
10
+ 'win32-arm64': { name: '@dotenvx/dotenvx-windows-arm64', os: 'win32', cpu: 'arm64', target: 'aarch64-pc-windows-msvc', runner: 'windows-11-arm' }
11
+ }
12
+
13
+ function currentPlatform () {
14
+ const libc = process.platform === 'linux' ? (process.report.getReport().header.glibcVersionRuntime ? '-gnu' : '-musl') : ''
15
+ return `${process.platform}-${process.arch}${libc}`
16
+ }
17
+
18
+ module.exports = { platforms, currentPlatform }
@@ -1,4 +1,4 @@
1
- const { redact } = require('@dotenvx/primitives')
1
+ const { redact } = require('../native.cjs')
2
2
  const { StringDecoder } = require('string_decoder')
3
3
 
4
4
  function normalizedValues (values) {
@@ -8,27 +8,6 @@ function normalizedValues (values) {
8
8
  .sort((a, b) => b.length - a.length)
9
9
  }
10
10
 
11
- function redactOutput (value, sensitiveValues) {
12
- const values = normalizedValues(sensitiveValues)
13
- if (values.length < 1 || value === undefined || value === null) return value
14
-
15
- if (Array.isArray(value)) {
16
- return value.map(item => redactOutput(item, values))
17
- }
18
-
19
- if (typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
20
- const result = {}
21
- for (const [key, item] of Object.entries(value)) {
22
- result[key] = redactOutput(item, values)
23
- }
24
- return result
25
- }
26
-
27
- if (typeof value !== 'string') return value
28
-
29
- return redact(value, values)
30
- }
31
-
32
11
  function partialMatchLength (value, sensitiveValues) {
33
12
  let longest = 0
34
13
 
@@ -90,29 +69,4 @@ function createRedactor (sensitiveValues) {
90
69
  }
91
70
  }
92
71
 
93
- function createRedactedStreamWriter (stream, sensitiveValues, source) {
94
- const redactor = createRedactor(sensitiveValues)
95
- let waitingForDrain = false
96
- const writeToStream = (value) => {
97
- if (!value) return
98
- const canContinue = stream.write(value)
99
- if (!canContinue && source && !waitingForDrain) {
100
- waitingForDrain = true
101
- source.pause()
102
- stream.once('drain', () => {
103
- waitingForDrain = false
104
- source.resume()
105
- })
106
- }
107
- }
108
- return {
109
- write: chunk => writeToStream(redactor.write(chunk)),
110
- flush: () => writeToStream(redactor.flush())
111
- }
112
- }
113
-
114
- module.exports = {
115
- redactOutput,
116
- createRedactor,
117
- createRedactedStreamWriter
118
- }
72
+ module.exports = { createRedactor }
@@ -0,0 +1,64 @@
1
+ const { formatWithOptions } = require('node:util')
2
+ const { createRedactor } = require('./redactOutput.cjs')
3
+ const { redact } = require('../native.cjs')
4
+
5
+ // Multiple SDK copies share output protection within the process.
6
+ const stateKey = Symbol.for('@dotenvx/dotenvx/redaction')
7
+ function state () {
8
+ if (!globalThis[stateKey]) globalThis[stateKey] = { values: new Set(), streams: [], consoles: new Map() }
9
+ return globalThis[stateKey]
10
+ }
11
+
12
+ function install (values) {
13
+ const shared = state()
14
+ // Keep old values protected during hot reload while old code can still log them.
15
+ for (const value of values) if (value !== undefined && value !== null && `${value}`) shared.values.add(`${value}`)
16
+ if (!shared.values.size) return
17
+
18
+ for (const stream of [process.stdout, process.stderr]) {
19
+ let entry = shared.streams.find(item => item.stream === stream)
20
+ if (!entry) {
21
+ const original = stream.write
22
+ const redactor = createRedactor([...shared.values])
23
+ const write = function (chunk, encoding, callback) {
24
+ if (typeof encoding === 'function') { callback = encoding; encoding = undefined }
25
+ const output = redactor.write(typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk)
26
+ if (output) return original.call(this, output, 'utf8', callback)
27
+ if (callback) process.nextTick(callback)
28
+ return true
29
+ }
30
+ entry = { stream, original, redactor, write }
31
+ shared.streams.push(entry)
32
+ stream.write = write
33
+ } else entry.redactor.add([...shared.values])
34
+ }
35
+
36
+ // Redact before React or another console wrapper captures arguments for replay.
37
+ for (const method of ['log', 'info', 'warn', 'error', 'debug', 'trace', 'dir']) {
38
+ const previous = shared.consoles.get(method)
39
+ if (previous === console[method]) continue
40
+ const original = console[method]
41
+ const wrapped = function (...args) {
42
+ const message = method === 'dir'
43
+ ? require('node:util').inspect(args[0], args[1])
44
+ : formatWithOptions({}, ...args)
45
+ return original.call(this, redact(message, [...shared.values]))
46
+ }
47
+ shared.consoles.set(method, wrapped)
48
+ console[method] = wrapped
49
+ }
50
+ if (!shared.flushInstalled) {
51
+ shared.flushInstalled = true
52
+ const flush = () => {
53
+ for (const { stream, original, redactor } of shared.streams) {
54
+ // A trailing prefix may be the beginning of a secret. Never reveal it.
55
+ const pending = redactor.flush(true)
56
+ if (pending) original.call(stream, pending)
57
+ }
58
+ }
59
+ process.on('beforeExit', flush)
60
+ process.on('exit', flush)
61
+ }
62
+ }
63
+
64
+ module.exports = { applyRedaction: install, refreshRedaction: () => install([]) }
@@ -0,0 +1,57 @@
1
+ const common = ['processEnv', 'overload', 'override', 'strict', 'ignore', 'logLevel']
2
+ const loading = [...common, 'path', 'envs', 'cwd', 'envKeysFile', 'keyFiles', 'convention', 'environment', 'encoding', 'quiet', 'resolveReferences', 'no1Password', 'noBitwarden', 'noArmor', 'noNative', 'token']
3
+ const allowed = {
4
+ config: new Set(loading),
5
+ parse: new Set([...common, 'privateKey']),
6
+ get: new Set([...loading, 'all', 'format'])
7
+ }
8
+ const sourceOptions = new Set(['type', 'value'])
9
+ const booleans = ['overload', 'override', 'strict', 'quiet', 'all', 'resolveReferences', 'no1Password', 'noBitwarden', 'noArmor', 'noNative']
10
+
11
+ function record (value, keys, context) {
12
+ if (!value || typeof value !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) {
13
+ throw new TypeError(`dotenvx ${context} must be an options object`)
14
+ }
15
+ for (const name of Reflect.ownKeys(value)) {
16
+ if (!keys.has(name)) throw new TypeError(`Unsupported dotenvx ${context} option: ${String(name)}`)
17
+ }
18
+ }
19
+
20
+ function validateOptions (options, method) {
21
+ record(options, allowed[method], method)
22
+ for (const name of booleans) {
23
+ if (options[name] !== undefined && typeof options[name] !== 'boolean') {
24
+ throw new TypeError(`dotenvx ${method} option ${name} must be a boolean`)
25
+ }
26
+ }
27
+ for (const name of ['privateKey', 'token', 'cwd', 'environment']) {
28
+ if (options[name] !== undefined && typeof options[name] !== 'string') {
29
+ throw new TypeError(`dotenvx ${method} option ${name} must be a string`)
30
+ }
31
+ }
32
+ if (options.processEnv !== undefined && (!options.processEnv || typeof options.processEnv !== 'object' || Array.isArray(options.processEnv))) {
33
+ throw new TypeError('processEnv must be an object')
34
+ }
35
+ if (options.ignore !== undefined && typeof options.ignore !== 'string' &&
36
+ !(Array.isArray(options.ignore) && options.ignore.every(code => typeof code === 'string'))) {
37
+ throw new TypeError(`dotenvx ${method} option ignore must be a string or an array of strings`)
38
+ }
39
+ for (const [name, values] of Object.entries({
40
+ logLevel: ['error', 'warn', 'info', 'silent'],
41
+ format: ['eval', 'eval-export', 'shell', 'colon'],
42
+ convention: ['nextjs', 'flow', 'rails']
43
+ })) {
44
+ if (options[name] !== undefined && !values.includes(options[name])) {
45
+ throw new TypeError(`dotenvx ${method} option ${name} must be one of: ${values.join(', ')}`)
46
+ }
47
+ }
48
+ if (options.encoding !== undefined && !['utf8', 'utf-8'].includes(options.encoding)) {
49
+ throw new TypeError('This beta supports UTF-8 env files (encoding: utf8 or utf-8)')
50
+ }
51
+ if (options.envs !== undefined) {
52
+ if (!Array.isArray(options.envs)) throw new TypeError('envs must be an array')
53
+ for (const [index, source] of options.envs.entries()) record(source, sourceOptions, `${method} envs[${index}]`)
54
+ }
55
+ }
56
+
57
+ module.exports = { validateOptions }
package/native.cjs ADDED
@@ -0,0 +1,23 @@
1
+ const { currentPlatform } = require('./lib/platforms.cjs')
2
+ const { resolveNativeFile } = require('./lib/native-package.cjs')
3
+
4
+ // Literal imports let deployment tracers discover the platform addon files.
5
+ const bindings = {
6
+ 'darwin-arm64': () => require('@dotenvx/dotenvx-darwin-arm64/dotenvx.node'),
7
+ 'darwin-x64': () => require('@dotenvx/dotenvx-darwin-x86_64/dotenvx.node'),
8
+ 'linux-x64-gnu': () => require('@dotenvx/dotenvx-linux-x86_64/dotenvx.node'),
9
+ 'linux-arm64-gnu': () => require('@dotenvx/dotenvx-linux-arm64/dotenvx.node'),
10
+ 'linux-x64-musl': () => require('@dotenvx/dotenvx-linux-x86_64-musl/dotenvx.node'),
11
+ 'linux-arm64-musl': () => require('@dotenvx/dotenvx-linux-arm64-musl/dotenvx.node'),
12
+ 'win32-x64': () => require('@dotenvx/dotenvx-windows-x86_64/dotenvx.node'),
13
+ 'win32-arm64': () => require('@dotenvx/dotenvx-windows-arm64/dotenvx.node')
14
+ }
15
+ const platform = currentPlatform()
16
+ if (!bindings[platform]) throw new Error(`@dotenvx/dotenvx has no native package for ${platform}`)
17
+ try {
18
+ module.exports = bindings[platform]()
19
+ } catch (cause) {
20
+ if (cause.code !== 'MODULE_NOT_FOUND') throw cause
21
+ // Local builds can use native/; published tarballs have no local fallback.
22
+ module.exports = require(resolveNativeFile('dotenvx.node'))
23
+ }