@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,39 +0,0 @@
1
- const path = require('path')
2
- const childProcess = require('child_process')
3
- const { logger } = require('../../shared/logger')
4
-
5
- function executeExtension (ext, command, rawArgs) {
6
- if (!command) {
7
- ext.outputHelp()
8
- process.exit(0)
9
- return
10
- }
11
-
12
- // construct the full command line manually including flags
13
- const commandIndex = rawArgs.indexOf(command)
14
- const forwardedArgs = rawArgs.slice(commandIndex + 1)
15
-
16
- logger.debug(`command: ${command}`)
17
- logger.debug(`args: ${JSON.stringify(forwardedArgs)}`)
18
-
19
- const binPath = path.join(process.cwd(), 'node_modules', '.bin')
20
- const newPath = `${binPath}:${process.env.PATH}`
21
- const env = { ...process.env, PATH: newPath }
22
-
23
- const result = childProcess.spawnSync(`dotenvx-ext-${command}`, forwardedArgs, { stdio: 'inherit', env })
24
- if (result.error) {
25
- // list known extension here for convenience to the user
26
- if (['vault'].includes(command)) {
27
- logger.warn(`[INSTALLATION_NEEDED] install dotenvx-ext-${command} to use [dotenvx ext ${command}] commands`)
28
- logger.help('? see installation instructions [https://github.com/dotenvx/dotenvx-ext-vault]')
29
- } else {
30
- logger.info(`error: unknown command '${command}'`)
31
- }
32
- }
33
-
34
- if (result.status !== 0) {
35
- process.exit(result.status)
36
- }
37
- }
38
-
39
- module.exports = executeExtension
@@ -1,15 +0,0 @@
1
- const { match } = require('@dotenvx/primitives')
2
-
3
- function filterKeys (parsed, includeKeys, excludeKeys) {
4
- const include = includeKeys && match(includeKeys)
5
- const exclude = excludeKeys && match(excludeKeys)
6
-
7
- return Object.fromEntries(Object.entries(parsed).filter(([key]) => {
8
- if (include && !include(key)) return false
9
- if (exclude && exclude(key)) return false
10
-
11
- return true
12
- }))
13
- }
14
-
15
- module.exports = filterKeys
@@ -1,25 +0,0 @@
1
- const fsx = require('./fsx')
2
- const Errors = require('./errors')
3
-
4
- const RESERVED_ENV_FILES = ['.env.project', '.env.keys', '.env.me', '.env.x', '.env.example']
5
-
6
- function findEnvFiles (directory) {
7
- try {
8
- const files = fsx.readdirSync(directory)
9
- const envFiles = files.filter(file =>
10
- file.startsWith('.env') &&
11
- !file.endsWith('.previous') &&
12
- !RESERVED_ENV_FILES.includes(file)
13
- )
14
-
15
- return envFiles
16
- } catch (e) {
17
- if (e.code === 'ENOENT') {
18
- throw new Errors({ directory }).missingDirectory()
19
- } else {
20
- throw e
21
- }
22
- }
23
- }
24
-
25
- module.exports = findEnvFiles
@@ -1,11 +0,0 @@
1
- function formatCode (str) {
2
- const parts = []
3
-
4
- for (let i = 0; i < str.length; i += 4) {
5
- parts.push(str.substring(i, i + 4))
6
- }
7
-
8
- return parts.join('-')
9
- }
10
-
11
- module.exports = formatCode
@@ -1,110 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const writeFileAtomic = require('write-file-atomic')
4
- const Errors = require('./errors')
5
-
6
- const ENCODING = 'utf8'
7
- const KEY_FILE_OPTIONS = { encoding: ENCODING, mode: 0o600 }
8
-
9
- async function readFileX (filepath, encoding = null) {
10
- if (!encoding) {
11
- encoding = ENCODING
12
- }
13
-
14
- return fs.promises.readFile(filepath, encoding)
15
- }
16
-
17
- function readFileXSync (filepath, encoding = null) {
18
- if (!encoding) {
19
- encoding = ENCODING
20
- }
21
-
22
- return fs.readFileSync(filepath, encoding) // utf8 default so it returns a string
23
- }
24
-
25
- function writeFileXSync (filepath, str, options = ENCODING) {
26
- try {
27
- if (options && options.followSymlinks === false) return writeFileNoFollowSync(filepath, str, options)
28
- return writeFileAtomic.sync(filepath, str, typeof options === 'string' ? options : { ...options })
29
- } catch (error) {
30
- if (error.code === 'EACCES' || error.code === 'EPERM') {
31
- throw new Errors({ filepath }).fileNotWritable()
32
- }
33
-
34
- throw error
35
- }
36
- }
37
-
38
- function writeFileNoFollowSync (filepath, str, options) {
39
- const regularFile = () => {
40
- const stat = fs.lstatSync(filepath, { throwIfNoEntry: false })
41
- if (stat && !stat.isFile()) throw new Error(`Cannot replace file: expected a regular file (${filepath})`)
42
- return stat
43
- }
44
- const stat = regularFile()
45
- const { followSymlinks, ...atomicOptions } = options
46
- if (stat) {
47
- if (atomicOptions.mode == null) atomicOptions.mode = stat.mode
48
- if (atomicOptions.chown == null && process.getuid) atomicOptions.chown = { uid: stat.uid, gid: stat.gid }
49
- }
50
- // write-file-atomic resolves symlinks. Stage in a private sibling directory so
51
- // it never resolves the destination, then rename over the directory entry.
52
- const staging = fs.mkdtempSync(path.join(path.dirname(filepath), '.dotenvx-write-'))
53
- try {
54
- const stagedFile = path.join(staging, 'content')
55
- writeFileAtomic.sync(stagedFile, str, atomicOptions)
56
- regularFile()
57
- fs.renameSync(stagedFile, filepath) // rename never follows the destination symlink
58
- } finally {
59
- fs.rmSync(staging, { recursive: true, force: true })
60
- }
61
- }
62
-
63
- async function writeFileX (filepath, str, options = ENCODING) {
64
- try {
65
- return await writeFileAtomic(filepath, str, typeof options === 'string' ? options : { ...options })
66
- } catch (error) {
67
- if (error.code === 'EACCES' || error.code === 'EPERM') {
68
- throw new Errors({ filepath }).fileNotWritable()
69
- }
70
-
71
- throw error
72
- }
73
- }
74
-
75
- function writeKeyFile (filepath, str) {
76
- return writeFileX(filepath, str, KEY_FILE_OPTIONS)
77
- }
78
-
79
- function writeKeyFileSync (filepath, str) {
80
- return writeFileXSync(filepath, str, KEY_FILE_OPTIONS)
81
- }
82
-
83
- async function exists (filepath) {
84
- try {
85
- await fs.promises.access(filepath)
86
- return true
87
- } catch (_e) {
88
- return false
89
- }
90
- }
91
-
92
- const fsx = {
93
- chmodSync: fs.chmodSync,
94
- exists,
95
- existsSync: fs.existsSync,
96
- readdirSync: fs.readdirSync,
97
- readFileSync: fs.readFileSync,
98
- writeFileSync: fs.writeFileSync,
99
- appendFileSync: fs.appendFileSync,
100
-
101
- // fsx special commands
102
- readFileX,
103
- readFileXSync,
104
- writeFileX,
105
- writeFileXSync,
106
- writeKeyFile,
107
- writeKeyFileSync
108
- }
109
-
110
- module.exports = fsx
@@ -1,15 +0,0 @@
1
- const PREFIX = 'DOTENV_PRIVATE_KEY'
2
-
3
- function guessPrivateKeyFilename (privateKeyName) {
4
- // .env
5
- if (privateKeyName === PREFIX) {
6
- return '.env'
7
- }
8
-
9
- const filenameSuffix = privateKeyName.substring(`${PREFIX}_`.length).split('_').join('.').toLowerCase()
10
- // .env.ENVIRONMENT
11
-
12
- return `.env.${filenameSuffix}`
13
- }
14
-
15
- module.exports = guessPrivateKeyFilename
@@ -1,7 +0,0 @@
1
- const { sealed } = require('@dotenvx/primitives')
2
-
3
- function hasPlaintextSecrets (src) {
4
- return !sealed(src)
5
- }
6
-
7
- module.exports = hasPlaintextSecrets
@@ -1,14 +0,0 @@
1
- const { request } = require('@dotenvx/tooling')
2
- const { isNetworkError } = require('@dotenvx/providers')
3
-
4
- async function http (url, opts = {}) {
5
- try {
6
- return await request(url, opts)
7
- } catch (error) {
8
- if (!isNetworkError(error)) throw error
9
- const code = error.code || error.cause?.code || 'NETWORK_ERROR'
10
- throw Object.assign(new Error(`[${code}] unable to connect to ${new URL(url).origin}. Check your connection and that the server is running.`), { code, cause: error })
11
- }
12
- }
13
-
14
- module.exports = { http }
@@ -1,82 +0,0 @@
1
- const fsx = require('./fsx')
2
- const path = require('path')
3
- const Errors = require('./errors')
4
-
5
- const HOOK_SCRIPT = `#!/bin/sh
6
-
7
- if command -v dotenvx 2>&1 >/dev/null
8
- then
9
- dotenvx precommit
10
- elif npx dotenvx -V >/dev/null 2>&1
11
- then
12
- npx dotenvx precommit
13
- else
14
- if [ -t 2 ]; then
15
- RED="$(printf '\\033[31m')"
16
- RESET="$(printf '\\033[0m')"
17
- else
18
- RED=""
19
- RESET=""
20
- fi
21
-
22
- printf "%s☠ 'dotenvx precommit' command not found (.git/hooks/precommit) fix: [curl -sfS https://dotenvx.sh | sh]%s\n" "$RED" "$RESET" >&2
23
- exit 1
24
- fi
25
- `
26
-
27
- class InstallPrecommitHook {
28
- constructor (hookPath = path.join('.git', 'hooks', 'pre-commit')) {
29
- this.hookPath = hookPath
30
- }
31
-
32
- run () {
33
- let successMessage
34
-
35
- try {
36
- // Check if the pre-commit file already exists
37
- if (this._exists()) {
38
- const currentHook = this._currentHook()
39
-
40
- // Check if 'dotenvx precommit' already exists in the file
41
- if (currentHook.includes('dotenvx precommit') || currentHook.includes('dotenvx ext precommit')) {
42
- // do nothing
43
- successMessage = `▣ dotenvx precommit exists [${this.hookPath}]`
44
- } else {
45
- this._appendHook()
46
- successMessage = `▣ dotenvx precommit appended [${this.hookPath}]`
47
- }
48
- } else {
49
- this._createHook()
50
- successMessage = `▣ dotenvx precommit installed [${this.hookPath}]`
51
- }
52
-
53
- return {
54
- successMessage
55
- }
56
- } catch (err) {
57
- throw new Errors({ error: err }).precommitHookModifyFailed()
58
- }
59
- }
60
-
61
- _exists () {
62
- return fsx.existsSync(this.hookPath)
63
- }
64
-
65
- _currentHook () {
66
- return fsx.readFileXSync(this.hookPath)
67
- }
68
-
69
- _createHook () {
70
- // If the pre-commit file doesn't exist, create a new one with the hookScript
71
- fsx.writeFileXSync(this.hookPath, HOOK_SCRIPT)
72
- fsx.chmodSync(this.hookPath, '755') // Make the file executable
73
- }
74
-
75
- _appendHook () {
76
- // Append 'dotenvx precommit' to the existing file
77
- fsx.appendFileSync(this.hookPath, '\n' + HOOK_SCRIPT)
78
- }
79
- }
80
-
81
- module.exports = InstallPrecommitHook
82
- module.exports.HOOK_SCRIPT = HOOK_SCRIPT
@@ -1,57 +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
-
7
- const patterns = require('./precommitEnvPatterns')
8
- const ATTRIBUTES = patterns.map(pattern => `${pattern.includes('/') ? '**/' : ''}${pattern} filter=dotenvx.protect`)
9
-
10
- function quote (value) {
11
- return "'" + value.replace(/'/g, "'\\''") + "'"
12
- }
13
-
14
- function installProtectFilter () {
15
- const git = (...args) => execFileSync('git', args, { encoding: 'utf8' }).trim()
16
- let attributesPath
17
- try {
18
- attributesPath = git('config', '--global', '--includes', '--path', '--get', 'core.attributesFile')
19
- } catch (error) {
20
- if (error.status !== 1) throw error
21
- }
22
- if (!attributesPath) {
23
- attributesPath = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'git/attributes')
24
- git('config', '--global', 'core.attributesFile', attributesPath)
25
- }
26
- const current = fs.existsSync(attributesPath) ? fs.readFileSync(attributesPath, 'utf8') : ''
27
- // Use the installed executable, including standalone builds. Never download a
28
- // replacement via npx while Git is handling secret input.
29
- const executable = process.pkg
30
- ? quote(process.execPath)
31
- : `${quote(process.execPath)} ${quote(path.resolve(__dirname, '../../cli/dotenvx.js'))}`
32
-
33
- // Git's filter_buffer_or_fd shell-quotes the filename with sq_quote_buf
34
- // before substituting %f (convert.c). Keep the placeholder unquoted here.
35
- git('config', '--global', 'filter.dotenvx.clean', `${executable} protect --git-file %f`)
36
- git('config', '--global', 'filter.dotenvx.process', `${executable} protect --git-process`)
37
- git('config', '--global', 'filter.dotenvx.required', 'true')
38
- // Keep the old driver working for repositories with older attributes.
39
- git('config', '--global', 'filter.dotenvx.protect.clean', `${executable} protect --git-file %f`)
40
- git('config', '--global', 'filter.dotenvx.protect.process', `${executable} protect --git-process`)
41
- git('config', '--global', 'filter.dotenvx.protect.required', 'true')
42
- fs.mkdirSync(path.dirname(attributesPath), { recursive: true })
43
- const migrated = current.split(/(?<=\n)/).map(line => {
44
- const value = line.replace(/\r?\n$/, '')
45
- return ATTRIBUTES.includes(value + '.protect') ? line.replace('filter=dotenvx', 'filter=dotenvx.protect') : line
46
- }).join('')
47
- const existing = new Set(migrated.split(/\r?\n/))
48
- const missing = ATTRIBUTES.filter(attribute => !existing.has(attribute))
49
- let next = migrated
50
- if (missing.length > 0) {
51
- next = `${next}${next && !next.endsWith('\n') ? '\n' : ''}${missing.join('\n')}\n`
52
- }
53
- if (next !== current) fsx.writeFileXSync(attributesPath, next)
54
- return attributesPath
55
- }
56
-
57
- module.exports = installProtectFilter
@@ -1,27 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const os = require('os')
4
- const { execFileSync } = require('child_process')
5
-
6
- function installProtectIgnore () {
7
- const git = (...args) => execFileSync('git', args, { encoding: 'utf8' }).trim()
8
- let ignorePath
9
- try {
10
- ignorePath = git('config', '--global', '--includes', '--path', '--get', 'core.excludesFile')
11
- } catch (error) {
12
- if (error.status !== 1) throw error
13
- }
14
- if (!ignorePath) {
15
- ignorePath = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'git/ignore')
16
- git('config', '--global', 'core.excludesFile', ignorePath)
17
- }
18
- const current = fs.existsSync(ignorePath) ? fs.readFileSync(ignorePath, 'utf8') : ''
19
- if (!current.split(/\r?\n/).includes('.env.keys*')) {
20
- fs.mkdirSync(path.dirname(ignorePath), { recursive: true })
21
- fs.appendFileSync(ignorePath, `${current && !current.endsWith('\n') ? '\n' : ''}.env.keys*\n`)
22
- git('config', '--global', 'dotenvx.protect.ignoreFile', ignorePath)
23
- }
24
- return ignorePath
25
- }
26
-
27
- module.exports = installProtectIgnore
@@ -1,3 +0,0 @@
1
- module.exports = function isPublicKey (name) {
2
- return name.includes('PUBLIC') || name.startsWith('VITE')
3
- }
@@ -1,10 +0,0 @@
1
- const TEAM_REQUIRED_CODES = new Set([
2
- 'TEAM_REQUIRED',
3
- 'DOTENVX_TEAM_REQUIRED'
4
- ])
5
-
6
- function isTeamRequiredError (error) {
7
- return Boolean(error && TEAM_REQUIRED_CODES.has(error.code))
8
- }
9
-
10
- module.exports = isTeamRequiredError
@@ -1,7 +0,0 @@
1
- function jsonToEnv (json) {
2
- return Object.entries(json).map(function ([key, value]) {
3
- return key + '=' + `"${value}"`
4
- }).join('\n')
5
- }
6
-
7
- module.exports = jsonToEnv
@@ -1,90 +0,0 @@
1
- const path = require('path')
2
- const fs = require('fs')
3
- const { execa } = require('@dotenvx/tooling')
4
- const { scan } = require('@dotenvx/primitives')
5
- const canonicalEnvFilename = require('./canonicalEnvFilename')
6
- const environment = require('../conventions/environment')
7
- const sanitizeCommandForMetadata = require('./sanitizeCommandForMetadata')
8
-
9
- function compact (object) {
10
- return Object.entries(object).reduce((acc, [key, value]) => {
11
- if (value !== undefined && value !== null && value !== '') {
12
- acc[key] = value
13
- }
14
-
15
- return acc
16
- }, {})
17
- }
18
-
19
- function commandFromMetadata (metadata) {
20
- try {
21
- const parsed = JSON.parse(metadata)
22
- return parsed && parsed.command ? sanitizeCommandForMetadata(parsed.command) : parsed && parsed.command
23
- } catch (_error) {
24
- return null
25
- }
26
- }
27
-
28
- function gitRoot () {
29
- try {
30
- return execa.sync('git', ['rev-parse', '--show-toplevel']).stdout.toString().trim()
31
- } catch (_error) {
32
- return null
33
- }
34
- }
35
-
36
- function normalizeFilepath (envFile) {
37
- const root = gitRoot()
38
- const filepath = path.resolve(envFile)
39
-
40
- if (root) {
41
- return path.relative(root, filepath).replace(/\\/g, '/')
42
- }
43
-
44
- return path.relative(process.cwd(), filepath).replace(/\\/g, '/')
45
- }
46
-
47
- function projectName () {
48
- return path.basename(gitRoot() || process.cwd())
49
- }
50
-
51
- function envKeys (envFile) {
52
- let src
53
- try {
54
- src = fs.readFileSync(envFile)
55
- } catch (_error) {
56
- return null
57
- }
58
-
59
- const { parsed } = scan(src)
60
-
61
- if (!parsed || Object.keys(parsed).length === 0) return null
62
-
63
- return Object.keys(parsed)
64
- }
65
-
66
- function keypairMetadata (envFile = '.env', metadata = undefined) {
67
- return compact({
68
- filepath: normalizeFilepath(envFile),
69
- filename: canonicalEnvFilename(envFile),
70
- environment: environment(envFile),
71
- project_name: projectName(),
72
- keys: envKeys(envFile),
73
- command: commandFromMetadata(metadata)
74
- })
75
- }
76
-
77
- // Descriptive upload context must never prevent storing a key.
78
- keypairMetadata.file = function (envFile = '.env') {
79
- try {
80
- return compact({
81
- filepath: normalizeFilepath(envFile),
82
- filename: canonicalEnvFilename(envFile),
83
- project_name: projectName()
84
- })
85
- } catch (_) {
86
- return {}
87
- }
88
- }
89
-
90
- module.exports = keypairMetadata
@@ -1,5 +0,0 @@
1
- const SAMPLE_ENV_KIT = `
2
- HELLO="World"
3
- `.trimStart()
4
-
5
- module.exports = SAMPLE_ENV_KIT
@@ -1,52 +0,0 @@
1
- const { execFileSync } = require('child_process')
2
- const nativeStoreError = require('./nativeStoreError')
3
-
4
- const SECRET_TOOL_BIN = 'secret-tool'
5
- const SERVICE = 'dotenvx'
6
-
7
- function attributes (publicKey) {
8
- return ['service', SERVICE, 'public-key', publicKey]
9
- }
10
-
11
- function get (publicKey) {
12
- try {
13
- return execFileSync(SECRET_TOOL_BIN, ['lookup', ...attributes(publicKey)], {
14
- timeout: 10000,
15
- killSignal: 'SIGKILL',
16
- encoding: 'utf8',
17
- stdio: ['ignore', 'pipe', 'pipe']
18
- }).trim() || null
19
- } catch (error) {
20
- throw nativeStoreError('failed to read private key from Linux Secret Service', error, true)
21
- }
22
- }
23
-
24
- function set (publicKey, privateKey, label) {
25
- try {
26
- execFileSync(SECRET_TOOL_BIN, ['store', `--label=${label}`, ...attributes(publicKey)], {
27
- input: privateKey,
28
- timeout: 10000,
29
- killSignal: 'SIGKILL',
30
- encoding: 'utf8',
31
- stdio: ['pipe', 'ignore', 'pipe']
32
- })
33
- } catch (error) {
34
- throw nativeStoreError('failed to save private key to Linux Secret Service', error, true)
35
- }
36
- }
37
-
38
- module.exports = {
39
- get,
40
- set,
41
- delete (publicKey) {
42
- try {
43
- execFileSync(SECRET_TOOL_BIN, ['clear', ...attributes(publicKey)], {
44
- timeout: 10000,
45
- killSignal: 'SIGKILL',
46
- stdio: ['ignore', 'ignore', 'pipe']
47
- })
48
- } catch (error) {
49
- throw nativeStoreError('failed to delete private key from Linux Secret Service', error, true)
50
- }
51
- }
52
- }
@@ -1,46 +0,0 @@
1
- function listenForOpenKey (onOpen) {
2
- const stdin = process.stdin
3
- if (!stdin.isTTY) return () => {}
4
-
5
- const canSetRawMode = typeof stdin.setRawMode === 'function'
6
- const wasRawMode = Boolean(stdin.isRaw)
7
- let didHandleOpenChoice = false
8
-
9
- const cleanup = () => {
10
- stdin.off('data', onData)
11
- if (canSetRawMode) stdin.setRawMode(wasRawMode)
12
- stdin.pause()
13
- }
14
-
15
- const onData = (chunk) => {
16
- const key = String(chunk)
17
- const lower = key.toLowerCase()
18
-
19
- if (key === '\u0003') {
20
- cleanup()
21
- process.kill(process.pid, 'SIGINT')
22
- return
23
- }
24
-
25
- if (key === '\r' || key === '\n' || lower === 'y') {
26
- if (!didHandleOpenChoice) {
27
- didHandleOpenChoice = true
28
- Promise.resolve(onOpen()).catch(() => {})
29
- }
30
- return
31
- }
32
-
33
- if (lower === 'n') {
34
- cleanup()
35
- process.kill(process.pid, 'SIGINT')
36
- }
37
- }
38
-
39
- if (canSetRawMode) stdin.setRawMode(true)
40
- stdin.resume()
41
- stdin.on('data', onData)
42
-
43
- return cleanup
44
- }
45
-
46
- module.exports = listenForOpenKey
@@ -1,9 +0,0 @@
1
- const { logger } = require('../../shared/logger')
2
-
3
- module.exports = function logProtectedFiles (files) {
4
- const names = [...new Set(files)]
5
- if (!names.length) return
6
- const display = names.slice(0, 3).map(name => /^[\w./-]+$/.test(name) ? name : JSON.stringify(name))
7
- if (names.length > 3) display.push(`+${names.length - 3} more`)
8
- logger.success(`⛉ safe to commit (${display.join(', ')})`)
9
- }
@@ -1,21 +0,0 @@
1
- const { publickeys, injectsummary } = require('@dotenvx/primitives')
2
- const { logger } = require('../../shared/logger')
3
-
4
- function logSetSummary (key, encrypt, result) {
5
- const { processedEnvs, changedFilepaths, unchangedFilepaths } = result
6
- const rows = new Map(processedEnvs.map(row => [row.envFilepath, {
7
- filepath: `(${row.envFilepath})`,
8
- publicKeys: publickeys(row.envSrc || ''),
9
- keySources: row.keySources
10
- }]))
11
- const paths = changedFilepaths.length ? changedFilepaths : unchangedFilepaths
12
- if (!paths.length) return
13
- const summary = encrypt ? injectsummary.sources(paths.map(filepath => rows.get(filepath) || `(${filepath})`)) : { files: [`(${paths.join(',')})`], suffix: '' }
14
- if (changedFilepaths.length) {
15
- logger.success(`${encrypt ? '◈ encrypted' : '◇ set'} ${key} ${summary.files.join(',')}${summary.suffix}`)
16
- } else {
17
- logger.info(`○ no change ${summary.files.join(',')}${summary.suffix}`)
18
- }
19
- }
20
-
21
- module.exports = logSetSummary