@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,40 +0,0 @@
1
- const commandAction = require('../../cli/commandAction')
2
- const createEvents = require('./index')
3
- const catalog = require('./catalog')
4
-
5
- module.exports = function trackCli (command, action) {
6
- return commandAction(async function (...args) {
7
- const options = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : this.opts()
8
- const context = this
9
- const name = `cli/${command}`
10
- const eventOptions = {}
11
- for (const [key, value] of Object.entries(options)) {
12
- const source = typeof this.getOptionValueSourceWithGlobals === 'function'
13
- ? this.getOptionValueSourceWithGlobals(key)
14
- : this.getOptionValueSource?.(key)
15
- if (source === 'cli' || source === 'env') eventOptions[key] = value
16
- }
17
- const events = createEvents(name, options, { eventOptions, background: true })
18
- if (catalog[name]?.keyArgument) events.add({ key: args[0] })
19
- let code
20
- let result
21
- try {
22
- result = await action.apply(context, args)
23
- if (Number.isInteger(result?.exitCode)) code = result.exitCode
24
- if (result?.error) {
25
- events.fail(result.error)
26
- code = code ?? 1
27
- }
28
- if (Number.isInteger(result?.errorCount)) events.add({ error_count: result.errorCount })
29
- if (result?.signal) events.add({ signal: result.signal })
30
- return result
31
- } catch (error) {
32
- code = 1
33
- events.fail(error)
34
- throw error
35
- } finally {
36
- const exitCode = code ?? process.exitCode ?? 0
37
- await events.complete(exitCode === 0 && !(result?.errorCount > 0) ? 'success' : 'unsuccessful', { exit_code: exitCode })
38
- }
39
- })
40
- }
@@ -1,89 +0,0 @@
1
- const BATCH_SIZE = 50
2
- const QUEUE_LIMIT = 256
3
-
4
- // Transport only. Backend failures cannot escape this boundary.
5
- module.exports = function createDelivery (backend, timeoutMs = 500) {
6
- const timeout = Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.min(timeoutMs, 500) : 500
7
- const queue = []
8
- let running
9
- let controller
10
- let closing
11
- let sendBatch
12
- try {
13
- if (backend && typeof backend.send === 'function') sendBatch = backend.send.bind(backend)
14
- } catch {} // Treat an invalid backend as disabled, including throwing getters.
15
- let closed = !sendBatch
16
-
17
- function stop () {
18
- closed = true
19
- queue.length = 0
20
- if (controller) controller.abort()
21
- }
22
-
23
- async function send (batch) {
24
- let timer
25
- controller = new AbortController()
26
- try {
27
- await Promise.race([
28
- Promise.resolve().then(() => sendBatch(batch, { signal: controller.signal })),
29
- new Promise(resolve => { timer = setTimeout(() => { stop(); resolve() }, timeout) })
30
- ])
31
- } catch {
32
- stop()
33
- } finally {
34
- clearTimeout(timer)
35
- }
36
- }
37
-
38
- function pump () {
39
- if (closed || running || !queue.length) return
40
- running = (async () => {
41
- while (queue.length) {
42
- if (closed) break
43
- await send(queue.splice(0, BATCH_SIZE))
44
- }
45
- })().finally(() => {
46
- running = undefined
47
- pump()
48
- })
49
- }
50
-
51
- async function flush () {
52
- let timer
53
- try {
54
- // Overall flush deadline is separate from each batch's deadline.
55
- await Promise.race([
56
- (async () => {
57
- pump()
58
- let current = running
59
- while (current) {
60
- await current
61
- current = running
62
- }
63
- })(),
64
- new Promise(resolve => { timer = setTimeout(() => { stop(); resolve() }, timeout) })
65
- ])
66
- } catch {
67
- stop()
68
- } finally {
69
- clearTimeout(timer)
70
- }
71
- }
72
-
73
- return {
74
- write (event, terminal = false) {
75
- if (closed || closing) return
76
- if (queue.length >= QUEUE_LIMIT) {
77
- if (!terminal) return
78
- queue.pop() // Reserve room for the final result.
79
- }
80
- queue.push(event)
81
- pump()
82
- },
83
- flush,
84
- close () {
85
- if (!closing) closing = flush().finally(stop)
86
- return closing
87
- }
88
- }
89
- }
@@ -1,73 +0,0 @@
1
- const { performance } = require('perf_hooks')
2
- const safe = require('./metadata')
3
- const catalog = require('./catalog')
4
- const createDelivery = require('./delivery')
5
- const createBackground = require('./background')
6
- const armor = require('./backends/armor')
7
- const { version } = require('../helpers/packageJson')
8
-
9
- module.exports = function createEvents (name, options = {}, config = {}) {
10
- let backend
11
- let delivery
12
- let selectedOptions
13
- try {
14
- selectedOptions = safe.options(config.eventOptions || options)
15
- if (Object.prototype.hasOwnProperty.call(catalog, name)) {
16
- if (config.background && !Object.prototype.hasOwnProperty.call(config, 'backend')) delivery = createBackground(options)
17
- else backend = Object.prototype.hasOwnProperty.call(config, 'backend') ? config.backend : armor(options)
18
- }
19
- } catch {} // Missing credentials, keychain failures, and setup are optional.
20
-
21
- delivery = delivery || createDelivery(backend, config.timeoutMs)
22
- const started = performance.now()
23
- const runtime = name.startsWith('sdk/') ? { sdk_version: version, sdk_language: 'javascript' } : { cli_version: version }
24
- let completion
25
- let failed = false
26
- let details = {}
27
-
28
- function record (metadata = {}, outcome = 'success', terminal = false) {
29
- try {
30
- if (completion) return
31
- const eventOptions = safe.options(selectedOptions)
32
- delivery.write({
33
- name,
34
- occurred_at: new Date().toISOString(),
35
- outcome: outcome === 'success' ? 'success' : 'unsuccessful',
36
- metadata: { ...safe.metadata(metadata), ...(Object.keys(eventOptions).length ? { options: eventOptions } : {}), ...runtime }
37
- }, terminal)
38
- } catch {}
39
- }
40
-
41
- return {
42
- record,
43
- file (row, metadata = {}) {
44
- try {
45
- if (completion) return
46
- details.error_count = (details.error_count || 0) + (row.error ? 1 : 0)
47
- if (row.error) failed = true
48
- record({
49
- output: options.stdout ? 'stdout' : 'file',
50
- ...(details.key !== undefined ? { key: details.key } : {}),
51
- ...metadata,
52
- phase: 'file',
53
- file: row.envFilepath,
54
- changed: !row.error && !!row.changed,
55
- ...(row.error ? { error_code: safe.errorCode(row.error) } : {})
56
- }, row.error ? 'unsuccessful' : 'success')
57
- } catch {}
58
- },
59
- add (metadata) { try { details = { ...details, ...safe.metadata(metadata) } } catch {} },
60
- fail (error) {
61
- failed = true
62
- try { details.error_code = safe.errorCode(error) } catch {}
63
- },
64
- complete (outcome, metadata = {}) {
65
- if (!completion) {
66
- record({ ...details, ...metadata, phase: 'complete', duration_ms: Math.round(performance.now() - started) }, outcome || (failed ? 'unsuccessful' : 'success'), true)
67
- completion = delivery.close()
68
- }
69
- return completion
70
- },
71
- flush: delivery.flush
72
- }
73
- }
@@ -1,25 +0,0 @@
1
- // Event metadata is an allowlist, not a copy of command options or debug logs.
2
- const fields = new Set(['key', 'file', 'files', 'changed', 'output', 'action', 'phase', 'decision', 'reason', 'error_code', 'error_count', 'warning_count', 'injected_count', 'proxied_count', 'exit_code', 'signal', 'duration_ms', 'filter', 'ignore', 'scope', 'executable'])
3
- const optionFields = new Set(['envFile', 'envKeysFile', 'key', 'includeKey', 'excludeKey', 'stdout', 'plain', 'armor', 'native', '1password', 'bitwarden', 'create', 'overload', 'all', 'strict', 'convention', 'ignore', 'mask', 'redact', 'format', 'prettyPrint', 'pp', 'docker', 'gitFile', 'gitProcess', 'quiet', 'verbose', 'debug', 'logLevel', 'path', 'encoding', 'override', 'encrypt', 'noArmor', 'noNative', 'no1Password', 'noBitwarden'])
4
-
5
- function value (input) {
6
- if (input === null || typeof input === 'boolean') return input
7
- if (typeof input === 'number' && Number.isFinite(input)) return input
8
- if (typeof input === 'string') return input.slice(0, 1024)
9
- if (Array.isArray(input)) return input.slice(0, 100).map(item => value(item)).filter(item => item !== undefined && !Array.isArray(item))
10
- }
11
-
12
- function select (input, allowed) {
13
- const output = {}
14
- for (const key of allowed) {
15
- const selected = value(input[key])
16
- if (selected !== undefined) output[key] = selected
17
- }
18
- return output
19
- }
20
-
21
- module.exports = {
22
- metadata: input => select(input, fields),
23
- options: input => select(input, optionFields),
24
- errorCode: error => /^[A-Z][A-Z0-9_]{0,79}$/.test(error && error.code) ? error.code : 'COMMAND_FAILED'
25
- }
@@ -1,44 +0,0 @@
1
- const createEvents = require('./index')
2
-
3
- // An explicit, scoped SDK facade. Sync methods stay sync; applications can flush
4
- // completed calls before shutdown without global hooks or process.exit changes.
5
- module.exports = function withEvents (sdk, config = {}) {
6
- const pending = new Set()
7
-
8
- function complete (events) {
9
- const completion = events.complete().catch(() => {})
10
- pending.add(completion)
11
- completion.finally(() => pending.delete(completion))
12
- }
13
-
14
- function invoke (name, options, metadata, action) {
15
- const events = createEvents(`sdk/${name}`, options, config)
16
- events.add(metadata)
17
- try {
18
- const result = action(events)
19
- if (result && typeof result.then === 'function') {
20
- return result.then(value => {
21
- complete(events)
22
- return value
23
- }, error => {
24
- events.fail(error)
25
- complete(events)
26
- throw error
27
- })
28
- }
29
- complete(events)
30
- return result
31
- } catch (error) {
32
- events.fail(error)
33
- complete(events)
34
- throw error
35
- }
36
- }
37
-
38
- return {
39
- config: (options = {}) => invoke('config', options, {}, events => sdk.config(options, events)),
40
- get: (key, options = {}) => invoke('get', options, { key }, events => sdk.get(key, options, events)),
41
- set: (key, value, options = {}) => invoke('set', options, { key }, events => sdk.set(key, value, options, events)),
42
- async flushEvents () { await Promise.all([...pending]) }
43
- }
44
- }
@@ -1,29 +0,0 @@
1
- const armor = require('./backends/armor')
2
-
3
- // Internal, short-lived worker. No output, local logs, or retries.
4
- module.exports = function deliverEvents () {
5
- let input = ''
6
- const stop = () => process.exit(0)
7
- const timer = setTimeout(stop, 5000)
8
- process.stdin.setEncoding('utf8')
9
- process.stdin.on('error', stop)
10
- process.stdin.on('data', chunk => {
11
- input += chunk
12
- if (Buffer.byteLength(input) > 1024 * 1024) stop()
13
- })
14
- process.stdin.on('end', async () => {
15
- try {
16
- const { options, events } = JSON.parse(input)
17
- if (!Array.isArray(events) || events.length > 256) return
18
- const backend = armor(options)
19
- if (backend) {
20
- for (let offset = 0; offset < events.length; offset += 50) {
21
- await backend.send(events.slice(offset, offset + 50), { signal: AbortSignal.timeout(500) })
22
- }
23
- }
24
- } catch {} finally {
25
- clearTimeout(timer)
26
- stop()
27
- }
28
- })
29
- }
@@ -1,14 +0,0 @@
1
- // Only account discovery, native credential-store access, and network settings.
2
- // In particular, do not propagate application secrets or runtime injection flags.
3
- const allowed = new Set([
4
- 'DOTENVX_CONFIG', 'DOTENVX_NO_ARMOR',
5
- 'HOME', 'USERPROFILE', 'HOMEDRIVE', 'HOMEPATH', 'APPDATA', 'LOCALAPPDATA',
6
- 'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_RUNTIME_DIR', 'DBUS_SESSION_BUS_ADDRESS',
7
- 'PATH', 'PATHEXT', 'SYSTEMROOT', 'WINDIR', 'TMPDIR', 'TMP', 'TEMP', 'LANG', 'LC_ALL',
8
- 'HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'NO_PROXY',
9
- 'NODE_EXTRA_CA_CERTS', 'NODE_USE_SYSTEM_CA', 'SSL_CERT_FILE', 'SSL_CERT_DIR'
10
- ])
11
-
12
- module.exports = function workerEnvironment (env = process.env) {
13
- return Object.fromEntries(Object.entries(env).filter(([key]) => allowed.has(key.toUpperCase())))
14
- }
@@ -1,10 +0,0 @@
1
- function armoredKeyDisplay (publicKey) {
2
- if (!publicKey) return ''
3
-
4
- const prefix = String(publicKey).slice(0, 6).toUpperCase()
5
- if (prefix.length <= 3) return prefix
6
-
7
- return `${prefix.slice(0, 3)} ${prefix.slice(3)}`
8
- }
9
-
10
- module.exports = armoredKeyDisplay
@@ -1,27 +0,0 @@
1
- const path = require('path')
2
-
3
- class ArrayToTree {
4
- constructor (arr) {
5
- this.arr = arr
6
- }
7
-
8
- run () {
9
- const tree = {}
10
-
11
- for (let i = 0; i < this.arr.length; i++) {
12
- const normalizedPath = path.normalize(this.arr[i]) // normalize any strange paths
13
- const parts = normalizedPath.split(path.sep) // use the platform-specific path segment separator
14
- let current = tree
15
-
16
- for (let j = 0; j < parts.length; j++) {
17
- const part = parts[j]
18
- current[part] = current[part] || {}
19
- current = current[part]
20
- }
21
- }
22
-
23
- return tree
24
- }
25
- }
26
-
27
- module.exports = ArrayToTree
@@ -1,19 +0,0 @@
1
- function buildApiError (statusCode, json) {
2
- const code = json.error.code || statusCode.toString()
3
- const message = `[${code}] ${json.error.message}`
4
- const help = json.error.help ? `fix: [${json.error.help}]` : `[${code}] ${JSON.stringify(json)}`
5
- const meta = json.error.meta
6
-
7
- const error = new Error(message)
8
- error.code = code
9
- error.help = help
10
- if (json.error.help) {
11
- error.messageWithHelp = `${message}. ${help}`
12
- }
13
- error.meta = meta
14
- error.json = json
15
-
16
- return error
17
- }
18
-
19
- module.exports = buildApiError
@@ -1,40 +0,0 @@
1
- const conventions = require('./conventions')
2
- const resolveDirectoryFilepath = require('./resolveDirectoryFilepath')
3
-
4
- function buildCommandEnvs (envs, convention) {
5
- const resolvedEnvs = []
6
- let hasDirectory = false
7
-
8
- for (const env of envs) {
9
- if (env.type !== 'envFile') {
10
- resolvedEnvs.push(env)
11
- continue
12
- }
13
-
14
- const envFilepath = resolveDirectoryFilepath(env.value, '.env')
15
- if (envFilepath === env.value) {
16
- resolvedEnvs.push(env)
17
- continue
18
- }
19
-
20
- hasDirectory = true
21
- if (convention) {
22
- for (const conventionEnv of conventions(convention)) {
23
- resolvedEnvs.push({
24
- ...conventionEnv,
25
- value: resolveDirectoryFilepath(env.value, conventionEnv.value)
26
- })
27
- }
28
- } else {
29
- resolvedEnvs.push({ ...env, value: envFilepath })
30
- }
31
- }
32
-
33
- if (convention && !hasDirectory) {
34
- return conventions(convention).concat(resolvedEnvs)
35
- }
36
-
37
- return resolvedEnvs
38
- }
39
-
40
- module.exports = buildCommandEnvs
@@ -1,13 +0,0 @@
1
- const buildCommandEnvs = require('./buildCommandEnvs')
2
- const buildEnvs = require('./buildEnvs')
3
-
4
- function buildConfigEnvs (options = {}) {
5
- if (options.envs) {
6
- return options.envs
7
- }
8
-
9
- const pathOptions = { ...options, convention: undefined }
10
- return buildCommandEnvs(buildEnvs(pathOptions), options.convention)
11
- }
12
-
13
- module.exports = buildConfigEnvs
@@ -1,24 +0,0 @@
1
- const conventions = require('./conventions')
2
- const dotenvOptionPaths = require('./dotenvOptionPaths')
3
-
4
- function buildEnvs (options) {
5
- if (options.envs) {
6
- return options.envs
7
- }
8
-
9
- // build envs using user set option.path
10
- const optionPaths = dotenvOptionPaths(options) // [ '.env' ]
11
-
12
- let envs = []
13
- if (options.convention) { // handle shorthand conventions
14
- envs = conventions(options.convention).concat(envs)
15
- }
16
-
17
- for (const optionPath of optionPaths) {
18
- envs.push({ type: 'envFile', value: optionPath })
19
- }
20
-
21
- return envs
22
- }
23
-
24
- module.exports = buildEnvs
@@ -1,14 +0,0 @@
1
- function buildOauthError (statusCode, json) {
2
- const code = json.error
3
- const message = `[${code}] ${json.error_description}`
4
- const help = `[${code}] ${JSON.stringify(json)}`
5
-
6
- const error = new Error(message)
7
- error.code = code
8
- error.help = help
9
- error.statusCode = statusCode
10
-
11
- return error
12
- }
13
-
14
- module.exports = buildOauthError
@@ -1,13 +0,0 @@
1
- const path = require('path')
2
-
3
- function canonicalEnvFilename (filepath) {
4
- let filename = path.basename(filepath).toLowerCase()
5
-
6
- if (filename.startsWith('.env') && filename.endsWith('.txt')) {
7
- filename = filename.slice(0, -4)
8
- }
9
-
10
- return filename
11
- }
12
-
13
- module.exports = canonicalEnvFilename
@@ -1,16 +0,0 @@
1
- const { logger } = require('./../../shared/logger')
2
-
3
- function catchAndLog (error) {
4
- const msg = error.messageWithHelp || error.message
5
- if (msg) {
6
- logger.error(msg)
7
- }
8
- if (error.debug) {
9
- logger.debug(error.debug)
10
- }
11
- if (error.code) {
12
- logger.debug(`ERROR_CODE: ${error.code}`)
13
- }
14
- }
15
-
16
- module.exports = catchAndLog
@@ -1,50 +0,0 @@
1
- const { Enquirer } = require('@dotenvx/tooling')
2
-
3
- class Checklist extends Enquirer.prompts.MultiSelect {
4
- constructor (options) {
5
- super({
6
- ...options,
7
- pointer: '❯',
8
- choices: [...options.choices, { name: '__submit', message: options.submitLabel, action: true }]
9
- })
10
- }
11
-
12
- indicator (choice) {
13
- if (choice.action) return ' '
14
- return choice.enabled ? '◉' : this.styles.muted('○')
15
- }
16
-
17
- async renderChoice (choice, index) {
18
- if (choice.action && typeof this.options.submitLabel === 'function') {
19
- choice.message = this.options.submitLabel(this.selected.map(item => item.name))
20
- }
21
- const line = await super.renderChoice(choice, index)
22
- return choice.action ? '\n' + line : line
23
- }
24
-
25
- toggle (choice, enabled) {
26
- if (choice.action) return choice
27
- return super.toggle(choice, enabled)
28
- }
29
-
30
- submit () {
31
- if (!this.focused || !this.focused.action) return this.space()
32
- return super.submit()
33
- }
34
-
35
- get selected () {
36
- return super.selected.filter(choice => !choice.action)
37
- }
38
-
39
- async render () {
40
- if (this.state.submitted && !this.state.cancelled) {
41
- this.clear(this.state.size)
42
- this.state.prompt = ''
43
- this.state.size = 0
44
- return
45
- }
46
- return super.render()
47
- }
48
- }
49
-
50
- module.exports = Checklist
@@ -1,5 +0,0 @@
1
- function chomp (value) {
2
- return value.replace(/[\r\n]+$/, '')
3
- }
4
-
5
- module.exports = chomp
@@ -1,23 +0,0 @@
1
- const { WriteStream } = require('tty')
2
-
3
- const getColorDepth = (stream) => {
4
- if (stream && !stream.isTTY) return 1
5
-
6
- try {
7
- if (stream && typeof stream.getColorDepth === 'function') {
8
- return stream.getColorDepth()
9
- }
10
-
11
- return WriteStream.prototype.getColorDepth()
12
- } catch (error) {
13
- const term = process.env.TERM
14
-
15
- if (term && (term.includes('256color') || term.includes('xterm'))) {
16
- return 8 // 256 colors
17
- }
18
-
19
- return 4
20
- }
21
- }
22
-
23
- module.exports = { getColorDepth }
@@ -1,28 +0,0 @@
1
- const Errors = require('./errors')
2
-
3
- function conventions (convention) {
4
- const env = process.env.DOTENV_ENV || process.env.NODE_ENV || 'development'
5
-
6
- if (convention === 'nextjs') {
7
- const canonicalEnv = ['development', 'test', 'production'].includes(env) && env
8
-
9
- return [
10
- canonicalEnv && { type: 'envFile', value: `.env.${canonicalEnv}.local` },
11
- canonicalEnv !== 'test' && { type: 'envFile', value: '.env.local' },
12
- canonicalEnv && { type: 'envFile', value: `.env.${canonicalEnv}` },
13
- { type: 'envFile', value: '.env' }
14
- ].filter(Boolean)
15
- } else if (convention === 'flow') {
16
- return [
17
- { type: 'envFile', value: `.env.${env}.local` },
18
- { type: 'envFile', value: `.env.${env}` },
19
- { type: 'envFile', value: '.env.local' },
20
- { type: 'envFile', value: '.env' },
21
- { type: 'envFile', value: '.env.defaults' }
22
- ]
23
- } else {
24
- throw new Errors({ convention }).invalidConvention()
25
- }
26
- }
27
-
28
- module.exports = conventions
@@ -1,17 +0,0 @@
1
- function createElapsedStatus (onStatus, text) {
2
- if (!onStatus) return () => {}
3
-
4
- let elapsed = 0
5
- onStatus(text)
6
-
7
- const timer = setInterval(() => {
8
- elapsed += 1
9
- onStatus(`${text} (${elapsed}s)`)
10
- }, 1000)
11
-
12
- if (timer.unref) timer.unref()
13
-
14
- return () => clearInterval(timer)
15
- }
16
-
17
- module.exports = createElapsedStatus
@@ -1,13 +0,0 @@
1
- const createSpinner = require('./createSpinner')
2
-
3
- module.exports = async function createProtectSpinner (options = {}) {
4
- // Git pipes stdin/stdout; only stderr can tell us whether a user is watching.
5
- if (!process.stderr.isTTY || 'CI' in process.env || process.env.TERM === 'dumb') return null
6
- const spinner = await createSpinner({ ...options, text: 'dotenvx protecting...', frames: ['⛉'] })
7
- // Temporary, opt-in preview delay for checking the staging indicator.
8
- const delay = Number(process.env.DOTENVX_PROTECT_PREVIEW_MS)
9
- if (spinner && Number.isFinite(delay) && delay > 0) {
10
- await new Promise(resolve => setTimeout(resolve, Math.min(delay, 5000)))
11
- }
12
- return spinner
13
- }