@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,374 +0,0 @@
1
- const truncate = require('./truncate')
2
-
3
- const ISSUE_BY_CODE = {
4
- COMMAND_EXITED_WITH_CODE: 'https://github.com/dotenvx/dotenvx/issues/new',
5
- COMMAND_SUBSTITUTION_FAILED: 'https://github.com/dotenvx/dotenvx/issues/532',
6
- DECRYPTION_FAILED: 'https://github.com/dotenvx/dotenvx/issues/757',
7
- INVALID_COLOR: 'must be 256 colors',
8
- INVALID_CONVENTION: 'https://github.com/dotenvx/dotenvx/issues/761',
9
- INVALID_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/465',
10
- INVALID_PUBLIC_KEY: 'https://github.com/dotenvx/dotenvx/issues/756',
11
- '1PASSWORD_FAILED': 'https://www.1password.dev/cli/get-started',
12
- BITWARDEN_FAILED: 'https://bitwarden.com/help/cli/',
13
- MALFORMED_ENCRYPTED_DATA: 'https://github.com/dotenvx/dotenvx/issues/467',
14
- MISPAIRED_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/752',
15
- MISSING_DIRECTORY: 'https://github.com/dotenvx/dotenvx/issues/758',
16
- MISSING_ENV_FILE: 'https://github.com/dotenvx/dotenvx/issues/484',
17
- MISSING_ENV_KEYS_FILE: 'https://github.com/dotenvx/dotenvx/issues/775',
18
- MISSING_ENV_FILES: 'https://github.com/dotenvx/dotenvx/issues/760',
19
- MISSING_KEY: 'https://github.com/dotenvx/dotenvx/issues/759',
20
- MISSING_LOG_LEVEL: 'must be valid log level',
21
- MISSING_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/464',
22
- MISSING_PUBLIC_KEY: 'https://github.com/dotenvx/dotenvx/issues/865',
23
- MISSING_VALUE: 'https://github.com/dotenvx/dotenvx/issues/864',
24
- FILE_NOT_WRITABLE: 'https://github.com/dotenvx/dotenvx/issues/890',
25
- PRECOMMIT_HOOK_MODIFY_FAILED: 'try again or report error',
26
- WRONG_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/466'
27
- }
28
-
29
- class Errors {
30
- constructor (options = {}) {
31
- this.filepath = options.filepath
32
- this.envFilepath = options.envFilepath
33
- this.envKeysFilepath = options.envKeysFilepath
34
-
35
- this.key = options.key
36
- this.privateKey = options.privateKey
37
- this.privateKeyName = options.privateKeyName
38
- this.publicKeyName = options.publicKeyName
39
- this.publicKey = options.publicKey
40
- this.publicKeyExisting = options.publicKeyExisting
41
- this.command = options.command
42
-
43
- this.message = options.message
44
- this.code = options.code
45
- this.help = options.help
46
- this.debug = options.debug
47
-
48
- this.convention = options.convention
49
- this.directory = options.directory
50
- this.exitCode = options.exitCode
51
- this.level = options.level
52
- this.color = options.color
53
- this.error = options.error
54
- }
55
-
56
- custom () {
57
- const e = new Error(this.message)
58
- if (this.code) e.code = this.code
59
- if (this.help) e.help = this.help
60
- if (this.code && !e.help) e.help = `fix: [${ISSUE_BY_CODE[this.code]}]`
61
- e.messageWithHelp = `${e.message}. ${e.help}`
62
- if (this.debug) e.debug = this.debug
63
- return e
64
- }
65
-
66
- commandExitedWithCode () {
67
- const code = 'COMMAND_EXITED_WITH_CODE'
68
- const message = `[${code}] Command exited with exit code ${this.exitCode}`
69
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
70
-
71
- const e = new Error(message)
72
- e.code = code
73
- e.help = help
74
- e.messageWithHelp = `${message}. ${help}`
75
- return e
76
- }
77
-
78
- commandSubstitutionFailed () {
79
- const code = 'COMMAND_SUBSTITUTION_FAILED'
80
- const message = `[${code}] could not eval ${this.key} containing command '${this.command}': ${this.message}`
81
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
82
-
83
- const e = new Error(message)
84
- e.code = code
85
- e.help = help
86
- e.messageWithHelp = `${message}. ${help}`
87
- return e
88
- }
89
-
90
- decryptionFailed () {
91
- const code = 'DECRYPTION_FAILED'
92
- const message = `[${code}] ${this.message}`
93
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
94
-
95
- const e = new Error(message)
96
- e.code = code
97
- e.help = help
98
- e.messageWithHelp = `${message}. ${help}`
99
- return e
100
- }
101
-
102
- onePasswordFailed () {
103
- const code = '1PASSWORD_FAILED'
104
- const message = `[${code}] ${this.message}`
105
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
106
-
107
- const e = new Error(message)
108
- e.code = code
109
- e.help = help
110
- e.messageWithHelp = `${message}. ${help}`
111
- return e
112
- }
113
-
114
- bitwardenFailed () {
115
- const code = 'BITWARDEN_FAILED'
116
- const message = `[${code}] ${this.message}`
117
- const help = this.help || `fix: [${ISSUE_BY_CODE[code]}]`
118
-
119
- const e = new Error(message)
120
- e.code = code
121
- e.help = help
122
- e.messageWithHelp = `${message}. ${help}`
123
- return e
124
- }
125
-
126
- invalidColor () {
127
- const code = 'INVALID_COLOR'
128
- const message = `[${code}] Invalid color ${this.color}`
129
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
130
-
131
- const e = new Error(message)
132
- e.code = code
133
- e.help = help
134
- e.messageWithHelp = `${message}. ${help}`
135
- return e
136
- }
137
-
138
- invalidConvention () {
139
- const code = 'INVALID_CONVENTION'
140
- const message = `[${code}] invalid convention (${this.convention})`
141
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
142
-
143
- const e = new Error(message)
144
- e.code = code
145
- e.help = help
146
- e.messageWithHelp = `${message}. ${help}`
147
- return e
148
- }
149
-
150
- invalidPrivateKey () {
151
- const code = 'INVALID_PRIVATE_KEY'
152
- const message = `[${code}] could not decrypt ${this.key} using private key '${this.privateKeyName}=${truncate(this.privateKey)}'`
153
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
154
-
155
- const e = new Error(message)
156
- e.code = code
157
- e.help = help
158
- e.messageWithHelp = `${message}. ${help}`
159
- return e
160
- }
161
-
162
- alreadyEncrypted () {
163
- const e = new Error(`[ALREADY_ENCRYPTED] ${this.envFilepath || '.env'} is already configured for encryption`)
164
- e.code = 'ALREADY_ENCRYPTED'
165
- e.help = 'fix: use a fresh .env file'
166
- e.messageWithHelp = `${e.message}. ${e.help}`
167
- return e
168
- }
169
-
170
- invalidPublicKey () {
171
- const code = 'INVALID_PUBLIC_KEY'
172
- const message = `[${code}] could not encrypt using public key '${this.publicKeyName}=${truncate(this.publicKey)}'`
173
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
174
-
175
- const e = new Error(message)
176
- e.code = code
177
- e.help = help
178
- e.messageWithHelp = `${message}. ${help}`
179
- return e
180
- }
181
-
182
- malformedEncryptedData () {
183
- const code = 'MALFORMED_ENCRYPTED_DATA'
184
- const message = `[${code}] could not decrypt ${this.key} because encrypted data appears malformed`
185
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
186
-
187
- const e = new Error(message)
188
- e.code = code
189
- e.help = help
190
- e.messageWithHelp = `${message}. ${help}`
191
- return e
192
- }
193
-
194
- mispairedPrivateKey () {
195
- const code = 'MISPAIRED_PRIVATE_KEY'
196
- const message = `[${code}] private key's derived public key (${truncate(this.publicKey)}) does not match the existing public key (${truncate(this.publicKeyExisting)})`
197
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
198
-
199
- const e = new Error(message)
200
- e.code = code
201
- e.help = help
202
- e.messageWithHelp = `${message}. ${help}`
203
- return e
204
- }
205
-
206
- missingDirectory () {
207
- const code = 'MISSING_DIRECTORY'
208
- const message = `[${code}] missing directory (${this.directory})`
209
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
210
-
211
- const e = new Error(message)
212
- e.code = code
213
- e.help = help
214
- e.messageWithHelp = `${message}. ${help}`
215
- return e
216
- }
217
-
218
- missingEnvFile () {
219
- const code = 'MISSING_ENV_FILE'
220
- const envFilepath = this.envFilepath || '.env'
221
- const message = `[${code}] missing file (${envFilepath})`
222
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
223
-
224
- const e = new Error(message)
225
- e.code = code
226
- e.help = help
227
- e.messageWithHelp = `${message}. ${help}`
228
- return e
229
- }
230
-
231
- envfileRequired () {
232
- const e = new Error('[ENVFILE_REQUIRED] check requires an Envfile')
233
- e.code = 'ENVFILE_REQUIRED'
234
- e.help = 'fix: run [dotenvx spec]'
235
- e.messageWithHelp = `${e.message}. ${e.help}`
236
- return e
237
- }
238
-
239
- missingEnvKeysFile () {
240
- const code = 'MISSING_ENV_KEYS_FILE'
241
- const envKeysFilepath = this.envKeysFilepath || '.env.keys'
242
- const message = `[${code}] missing file (${envKeysFilepath})`
243
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
244
-
245
- const e = new Error(message)
246
- e.code = code
247
- e.help = help
248
- e.messageWithHelp = `${message}. ${help}`
249
- return e
250
- }
251
-
252
- missingEnvFiles () {
253
- const code = 'MISSING_ENV_FILES'
254
- const message = `[${code}] no .env* files found`
255
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
256
-
257
- const e = new Error(message)
258
- e.code = code
259
- e.help = help
260
- e.messageWithHelp = `${message}. ${help}`
261
- return e
262
- }
263
-
264
- missingKey () {
265
- const code = 'MISSING_KEY'
266
- const message = `[${code}] missing key (${this.key})`
267
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
268
-
269
- const e = new Error(message)
270
- e.code = code
271
- e.help = help
272
- e.messageWithHelp = `${message}. ${help}`
273
- return e
274
- }
275
-
276
- missingLogLevel () {
277
- const code = 'MISSING_LOG_LEVEL'
278
- const message = `[${code}] missing log level '${this.level}'. implement in logger`
279
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
280
-
281
- const e = new Error(message)
282
- e.code = code
283
- e.help = help
284
- e.messageWithHelp = `${message}. ${help}`
285
- return e
286
- }
287
-
288
- missingPrivateKey () {
289
- const code = 'MISSING_PRIVATE_KEY'
290
- const message = `[${code}] could not decrypt ${this.key} using private key '${this.privateKeyName}=${truncate(this.privateKey)}'`
291
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
292
-
293
- const e = new Error(message)
294
- e.code = code
295
- e.help = help
296
- e.messageWithHelp = `${message}. ${help}`
297
- return e
298
- }
299
-
300
- missingPublicKey () {
301
- const code = 'MISSING_PUBLIC_KEY'
302
- const message = `[${code}] missing public key`
303
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
304
-
305
- const e = new Error(message)
306
- e.code = code
307
- e.help = help
308
- e.messageWithHelp = `${message}. ${help}`
309
- return e
310
- }
311
-
312
- fileNotWritable () {
313
- const code = 'FILE_NOT_WRITABLE'
314
- const filepath = this.filepath || 'unknown'
315
- const message = `[${code}] cannot write to file (${filepath})`
316
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
317
-
318
- const e = new Error(message)
319
- e.code = code
320
- e.help = help
321
- e.messageWithHelp = `${message}. ${help}`
322
- return e
323
- }
324
-
325
- missingValue () {
326
- const code = 'MISSING_VALUE'
327
- const message = `[${code}] missing value (${this.key})`
328
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
329
-
330
- const e = new Error(message)
331
- e.code = code
332
- e.help = help
333
- e.messageWithHelp = `${message}. ${help}`
334
- return e
335
- }
336
-
337
- invalidEnv () {
338
- const code = 'INVALID_ENV'
339
- const message = `[${code}] ${this.message}`
340
-
341
- const e = new Error(message)
342
- e.code = code
343
- e.messageWithHelp = message
344
- return e
345
- }
346
-
347
- precommitHookModifyFailed () {
348
- const code = 'PRECOMMIT_HOOK_MODIFY_FAILED'
349
- const message = `[${code}] failed to modify pre-commit hook: ${this.error.message}`
350
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
351
-
352
- const e = new Error(message)
353
- e.code = code
354
- e.help = help
355
- e.messageWithHelp = `${message}. ${help}`
356
- return e
357
- }
358
-
359
- wrongPrivateKey () {
360
- const code = 'WRONG_PRIVATE_KEY'
361
- const message = `[${code}] could not decrypt ${this.key} using private key '${this.privateKeyName}=${truncate(this.privateKey)}'`
362
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
363
-
364
- const e = new Error(message)
365
- e.code = code
366
- e.help = help
367
- e.messageWithHelp = `${message}. ${help}`
368
- return e
369
- }
370
- }
371
-
372
- Errors.ISSUE_BY_CODE = ISSUE_BY_CODE
373
-
374
- module.exports = Errors
@@ -1,6 +0,0 @@
1
- function escape (value) {
2
- const quote = String.fromCharCode(39)
3
- return quote + value.replaceAll(quote, quote + '\\' + quote + quote) + quote
4
- }
5
-
6
- module.exports = escape
@@ -1,12 +0,0 @@
1
- const { execa } = require('@dotenvx/tooling')
2
- /* c8 ignore start */
3
- const pkgArgs = process.pkg ? { PKG_EXECPATH: '' } : {}
4
- /* c8 ignore stop */
5
-
6
- const execute = {
7
- execa (command, args, options) {
8
- return execa(command, args, { ...options, env: { ...options.env, ...pkgArgs } })
9
- }
10
- }
11
-
12
- module.exports = execute
@@ -1,208 +0,0 @@
1
- const path = require('path')
2
- const { which } = require('@dotenvx/tooling')
3
- const execute = require('./../../lib/helpers/execute')
4
- const { logger } = require('./../../shared/logger')
5
- const Errors = require('./errors')
6
- const { createRedactedStreamWriter, redactOutput } = require('./redactOutput')
7
- const ptyCommand = require('./ptyCommand')
8
- const { finished } = require('stream/promises')
9
-
10
- async function executeCommand (commandArgs, env, sensitiveValues = []) {
11
- const FORWARD_SIGNAL_GRACE_MS = 1000
12
- const FORCE_KILL_GRACE_MS = 1000
13
- const signals = [
14
- 'SIGHUP', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
15
- 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2'
16
- ]
17
-
18
- logger.debug(`executing process command [${commandArgs.join(' ')}]`)
19
-
20
- let child
21
- let commandExitCode
22
- let commandError
23
- let commandSignal
24
- let signalSent
25
- let sigintCount = 0
26
- const outputFinished = []
27
- const signalForwardTimers = new Set()
28
- const otherSignalHandlers = new Map()
29
- const isInteractiveTTY = Boolean(process.stdin && process.stdin.isTTY)
30
-
31
- const isChildRunning = () => {
32
- return child && child.exitCode === null && child.signalCode === null
33
- }
34
-
35
- const queueSignalForward = (signal) => {
36
- logger.debug(`queueing ${signal} to command process after ${FORWARD_SIGNAL_GRACE_MS}ms`)
37
- const timer = setTimeout(() => {
38
- signalForwardTimers.delete(timer)
39
-
40
- if (!isChildRunning()) {
41
- logger.debug(`skipping ${signal} forward because command process is already exiting`)
42
- return
43
- }
44
-
45
- logger.debug(`sending ${signal} to command process`)
46
- signalSent = signal
47
- child.kill(signal)
48
- }, FORWARD_SIGNAL_GRACE_MS)
49
-
50
- if (typeof timer.unref === 'function') timer.unref()
51
- signalForwardTimers.add(timer)
52
- }
53
-
54
- const queueForceKill = () => {
55
- logger.debug(`queueing SIGKILL to command process after ${FORCE_KILL_GRACE_MS}ms`)
56
- const timer = setTimeout(() => {
57
- signalForwardTimers.delete(timer)
58
-
59
- if (!isChildRunning()) {
60
- logger.debug('skipping SIGKILL because command process is already exiting')
61
- return
62
- }
63
-
64
- logger.debug('sending SIGKILL to command process')
65
- child.kill('SIGKILL')
66
- }, FORCE_KILL_GRACE_MS)
67
-
68
- if (typeof timer.unref === 'function') timer.unref()
69
- signalForwardTimers.add(timer)
70
- }
71
-
72
- /* c8 ignore start */
73
- const sigintHandler = () => {
74
- logger.debug('received SIGINT')
75
- logger.debug('checking command process')
76
- logger.debug(child)
77
-
78
- if (!child) return
79
-
80
- sigintCount += 1
81
-
82
- if (isInteractiveTTY) {
83
- if (sigintCount === 1) {
84
- logger.debug('TTY mode: not forwarding first SIGINT to command process')
85
- return
86
- }
87
-
88
- logger.debug('TTY mode: forwarding SIGTERM on second SIGINT to command process')
89
- signalSent = 'SIGTERM'
90
- child.kill('SIGTERM')
91
-
92
- if (sigintCount === 2) queueForceKill()
93
- return
94
- }
95
-
96
- queueSignalForward('SIGINT')
97
- }
98
-
99
- const sigtermHandler = () => {
100
- logger.debug('received SIGTERM')
101
- logger.debug('checking command process')
102
- logger.debug(child)
103
-
104
- if (!child) return
105
-
106
- queueSignalForward('SIGTERM')
107
- }
108
-
109
- const handleOtherSignal = (signal) => {
110
- logger.debug(`received ${signal}`)
111
- if (child) child.kill(signal)
112
- }
113
- /* c8 ignore stop */
114
-
115
- try {
116
- // Expand only the executable; child arguments and separators pass through unchanged.
117
- try {
118
- commandArgs[0] = path.resolve(which.sync(`${commandArgs[0]}`))
119
- logger.debug(`expanding process command to [${commandArgs.join(' ')}]`)
120
- } catch (e) {
121
- logger.debug(`could not expand process command. using [${commandArgs.join(' ')}]`)
122
- }
123
-
124
- const redactStdout = sensitiveValues.length > 0
125
- const redactStderr = sensitiveValues.length > 0
126
- const usePty = redactStdout && Boolean(
127
- process.stdin && process.stdin.isTTY &&
128
- process.stdout && process.stdout.isTTY &&
129
- process.stderr && process.stderr.isTTY
130
- )
131
- const ptyArgs = usePty ? ptyCommand(commandArgs) : null
132
- const executedArgs = ptyArgs || commandArgs
133
-
134
- child = execute.execa(executedArgs[0], executedArgs.slice(1), {
135
- stdio: ['inherit', redactStdout ? 'pipe' : 'inherit', redactStderr ? 'pipe' : 'inherit'],
136
- buffer: false,
137
- env: { ...process.env, ...env }
138
- })
139
-
140
- if (redactStdout && child.stdout) {
141
- const stdoutWriter = createRedactedStreamWriter(process.stdout, sensitiveValues, child.stdout)
142
- child.stdout.on('data', stdoutWriter.write)
143
- child.stdout.once('end', stdoutWriter.flush)
144
- outputFinished.push(finished(child.stdout).catch(() => {}))
145
- }
146
-
147
- if (redactStderr && child.stderr) {
148
- const stderrWriter = createRedactedStreamWriter(process.stderr, sensitiveValues, child.stderr)
149
- child.stderr.on('data', stderrWriter.write)
150
- child.stderr.once('end', stderrWriter.flush)
151
- outputFinished.push(finished(child.stderr).catch(() => {}))
152
- }
153
-
154
- process.on('SIGINT', sigintHandler)
155
- process.on('SIGTERM', sigtermHandler)
156
-
157
- signals.forEach(signal => {
158
- const handler = () => handleOtherSignal(signal)
159
- otherSignalHandlers.set(signal, handler)
160
- process.on(signal, handler)
161
- })
162
-
163
- // Wait for the command process to finish
164
- const { exitCode } = await child
165
-
166
- if (exitCode !== 0) {
167
- logger.debug(`received exitCode ${exitCode}`)
168
- const error = new Errors({ exitCode }).commandExitedWithCode()
169
- error.exitCode = exitCode
170
- throw error
171
- }
172
- } catch (error) {
173
- commandSignal = signalSent || error.signal
174
- if (error.code === 'ENOENT') commandError = { code: 'COMMAND_NOT_FOUND' }
175
- const commandExited = Number.isInteger(error.exitCode) && (error.code === 'COMMAND_EXITED_WITH_CODE' || error.command)
176
-
177
- // no color on these errors as they can be standard errors for things like jest exiting with exitCode 1 for a single failed test.
178
- if (!['SIGINT', 'SIGTERM'].includes(signalSent || error.signal)) {
179
- if (error.code === 'ENOENT') {
180
- logger.error(`Unknown command: ${error.command}`)
181
- } else if (!commandExited) {
182
- logger.error(redactOutput(error.message, sensitiveValues))
183
- }
184
- }
185
-
186
- // Exit with the error code from the command process, or 1 if unavailable
187
- commandExitCode = error.exitCode || 1
188
- } finally {
189
- // Child exit can precede pipe EOF. Let redaction flush its held-back tail
190
- // before the action returns and the CLI exits.
191
- await Promise.all(outputFinished)
192
- signalForwardTimers.forEach(timer => clearTimeout(timer))
193
- signalForwardTimers.clear()
194
-
195
- // Clean up: Remove the SIGINT handler
196
- process.removeListener('SIGINT', sigintHandler)
197
- // Clean up: Remove the SIGTERM handler
198
- process.removeListener('SIGTERM', sigtermHandler)
199
-
200
- otherSignalHandlers.forEach((handler, signal) => {
201
- process.removeListener(signal, handler)
202
- })
203
- }
204
-
205
- return { exitCode: commandExitCode || 0, signal: commandSignal, error: commandError }
206
- }
207
-
208
- module.exports = executeCommand
@@ -1,86 +0,0 @@
1
- const path = require('path')
2
- const childProcess = require('child_process')
3
- const { logger } = require('../../shared/logger')
4
-
5
- function armorBanner () {
6
- const lines = [
7
- ' [www.dotenvx.com/armor]',
8
- '–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––',
9
- ' __ ____ __ ',
10
- ' | || |',
11
- ' | __||__ |',
12
- ' | ‾‾||‾‾ |',
13
- ' | || |',
14
- ' \\ || /',
15
- ' \\ __ /',
16
- '',
17
- ' Dotenvx Armor ⛨',
18
- '',
19
- ' ARMORED KEYS',
20
- ' Private keys. Off device. Under guard.',
21
- '',
22
- ' -',
23
- '',
24
- ' Install one',
25
- ' [curl -sfS https://dotenvx.sh/armor | sh]',
26
- ' [npm i @dotenvx/dotenvx-armor --save]',
27
- '',
28
- ' -',
29
- '',
30
- ' Then',
31
- ' [dotenvx armor up]',
32
- ' (sign in when prompted)',
33
- ''
34
- ]
35
-
36
- const innerWidth = Math.max(67, ...lines.map((line) => line.length))
37
- const top = ` ${'_'.repeat(innerWidth)}`
38
- const middle = lines.map((line) => `|${line.padEnd(innerWidth)}|`).join('\n')
39
- const bottom = `|${'_'.repeat(innerWidth)}|`
40
-
41
- return `${top}\n${middle}\n${bottom}`
42
- }
43
-
44
- function dynamicAttempts (command, forwardedArgs) {
45
- return [[`dotenvx-${command}`, forwardedArgs]]
46
- }
47
-
48
- function executeDynamic (program, command, rawArgs) {
49
- if (!command) {
50
- program.outputHelp()
51
- process.exit(1)
52
- return
53
- }
54
-
55
- // construct the full command line manually including flags
56
- const commandIndex = rawArgs.indexOf(command)
57
- const forwardedArgs = rawArgs.slice(commandIndex + 1)
58
-
59
- logger.debug(`command: ${command}`)
60
- logger.debug(`args: ${JSON.stringify(forwardedArgs)}`)
61
-
62
- const binPath = path.join(process.cwd(), 'node_modules', '.bin')
63
- const newPath = `${binPath}:${process.env.PATH}`
64
- const env = { ...process.env, PATH: newPath }
65
-
66
- const spawnOptions = { stdio: 'inherit', env }
67
- let result
68
- for (const [spawnCommand, spawnArgs] of dynamicAttempts(command, forwardedArgs)) {
69
- result = childProcess.spawnSync(spawnCommand, spawnArgs, spawnOptions)
70
- if (!result.error) break
71
- }
72
-
73
- if (result.error) {
74
- if (command === 'armor') {
75
- console.log(armorBanner())
76
- } else {
77
- logger.info(`error: unknown command '${command}'`)
78
- }
79
- }
80
-
81
- if (result.status !== 0) {
82
- process.exit(result.status)
83
- }
84
- }
85
-
86
- module.exports = executeDynamic