@dotenvx/dotenvx 2.32.4 → 2.34.0

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 (90) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +24 -26
  3. package/package.json +5 -13
  4. package/src/cli/actions/check.js +6 -11
  5. package/src/cli/actions/encrypt.js +2 -2
  6. package/src/cli/actions/get.js +4 -5
  7. package/src/cli/actions/init.js +4 -4
  8. package/src/cli/actions/keypair.js +1 -0
  9. package/src/cli/actions/policy.js +14 -0
  10. package/src/cli/actions/primitivesCheck.js +32 -0
  11. package/src/cli/actions/primitivesProfile.js +15 -0
  12. package/src/cli/actions/primitivesRedact.js +19 -0
  13. package/src/cli/actions/protectStdin.js +2 -2
  14. package/src/cli/actions/run.js +8 -46
  15. package/src/cli/actions/set.js +1 -1
  16. package/src/cli/commands/primitives.js +28 -1
  17. package/src/cli/dotenvx.js +6 -6
  18. package/src/db/session.js +1 -1
  19. package/src/lib/custodians/index.js +12 -10
  20. package/src/lib/custodians/local/bitwarden.js +5 -15
  21. package/src/lib/custodians/local/native/backend.js +4 -10
  22. package/src/lib/custodians/local/native/index.js +1 -1
  23. package/src/lib/custodians/local/onepassword.js +7 -29
  24. package/src/lib/custodians/managed/armor/index.js +0 -10
  25. package/src/lib/custodians/resolveLocalKey.js +3 -4
  26. package/src/lib/decryptors/armor/index.js +6 -7
  27. package/src/lib/{envspec → envfile}/discovery/discoverEnvFiles.js +1 -1
  28. package/src/lib/{envspec → envfile}/discovery/scanSource.js +1 -1
  29. package/src/lib/{envspec/parsing/formatEnvspecSyntaxError.js → envfile/parsing/formatEnvfileSyntaxError.js} +1 -1
  30. package/src/lib/envfile/parsing/readEnvfile.js +43 -0
  31. package/src/lib/envfile/parsing/resolveEnvfilePath.js +5 -0
  32. package/src/lib/{envspec/rendering/normalizeEnvspec.js → envfile/rendering/normalizeEnvfile.js} +1 -1
  33. package/src/lib/{envspec/rendering/previewEnvspec.js → envfile/rendering/previewEnvfile.js} +7 -15
  34. package/src/lib/{envspec/rendering/renderEnvspec.js → envfile/rendering/renderEnvfile.js} +3 -3
  35. package/src/lib/{envspec/validation/protectEnvspec.js → envfile/validation/protectEnvfile.js} +7 -7
  36. package/src/lib/envfile/validation/validateEnvfile.js +14 -0
  37. package/src/lib/helpers/errors.js +3 -25
  38. package/src/lib/helpers/executeCommand.js +1 -2
  39. package/src/lib/helpers/matchesStoredKey.js +1 -12
  40. package/src/lib/helpers/parseWithDecryptor.js +27 -12
  41. package/src/lib/helpers/redactOutput.js +30 -32
  42. package/src/lib/helpers/redactProcessOutput.js +58 -0
  43. package/src/lib/helpers/redactedValues.js +2 -2
  44. package/src/lib/helpers/selectEnvfileEnvs.js +29 -0
  45. package/src/lib/helpers/selectKeyStorage.js +1 -1
  46. package/src/lib/helpers/storeKeyStorage.js +0 -1
  47. package/src/lib/main.d.ts +12 -6
  48. package/src/lib/main.js +16 -29
  49. package/src/lib/providers/index.js +53 -53
  50. package/src/lib/resolvers/envs.js +7 -26
  51. package/src/lib/resolvers/get.js +2 -3
  52. package/src/lib/resolvers/keypair.js +39 -4
  53. package/src/lib/services/init.js +4 -4
  54. package/src/lib/services/validate.js +20 -32
  55. package/src/lib/transforms/encrypt.js +5 -5
  56. package/src/lib/transforms/set.js +5 -3
  57. package/src/cli/actions/lock/down.js +0 -54
  58. package/src/cli/actions/lock/up.js +0 -62
  59. package/src/cli/commands/lock.js +0 -36
  60. package/src/lib/api/postArmorDecrypt.js +0 -49
  61. package/src/lib/api/postArmorKeyring.js +0 -50
  62. package/src/lib/custodians/lock.js +0 -80
  63. package/src/lib/custodians/managed/armor/get.js +0 -44
  64. package/src/lib/envspec/parsing/envspec.peggy +0 -105
  65. package/src/lib/envspec/parsing/envspecParser.js +0 -2851
  66. package/src/lib/envspec/parsing/readEnvspec.js +0 -144
  67. package/src/lib/envspec/parsing/resolveEnvspecPath.js +0 -11
  68. package/src/lib/envspec/validation/encryptedSources.js +0 -15
  69. package/src/lib/envspec/validation/validate.js +0 -109
  70. package/src/lib/envspec/validation/validateEnvspec.js +0 -57
  71. package/src/lib/helpers/isValidEmail.js +0 -11
  72. package/src/lib/helpers/isValidUrl.js +0 -9
  73. package/src/lib/helpers/lockedValue.js +0 -24
  74. package/src/lib/helpers/resolveLockPassword.js +0 -5
  75. package/src/lib/helpers/unlockedValue.js +0 -26
  76. package/src/lib/helpers/withLockedKeys.js +0 -41
  77. package/src/lib/providers/provider-worker.js +0 -6
  78. package/src/lib/proxy/configureProxy.js +0 -55
  79. package/src/lib/proxy/eligibleHeaders.js +0 -16
  80. package/src/lib/proxy/prepareProxy.js +0 -24
  81. package/src/lib/proxy/proxyCertificates.js +0 -44
  82. package/src/lib/proxy/proxyForward.js +0 -65
  83. package/src/lib/proxy/proxyPreload.js +0 -21
  84. package/src/lib/proxy/proxyPreloadSource.js +0 -3
  85. package/src/lib/proxy/proxyServer.js +0 -175
  86. package/src/lib/services/armorKeyring.js +0 -119
  87. package/src/lib/services/lockDown.js +0 -157
  88. package/src/lib/services/lockUp.js +0 -150
  89. /package/src/lib/{envspec → envfile}/discovery/extractEnvKeys.js +0 -0
  90. /package/src/lib/{envspec → envfile}/validation/diagnosticLocation.js +0 -0
@@ -1,50 +0,0 @@
1
- const { http } = require('../helpers/http')
2
- const buildApiError = require('../helpers/buildApiError')
3
- const packageJson = require('../helpers/packageJson')
4
- const normalizeToken = require('../helpers/normalizeToken')
5
-
6
- class PostArmorKeyring {
7
- constructor (hostname, token, devicePublicKey, publicKey, grantToken) {
8
- this.hostname = hostname || 'https://armor.dotenvx.com'
9
- this.token = token
10
- this.devicePublicKey = devicePublicKey
11
- this.publicKey = publicKey
12
- this.grantToken = grantToken
13
- }
14
-
15
- async run () {
16
- const token = normalizeToken(this.token)
17
- const url = `${this.hostname}/api/armor/keyring`
18
- const body = {
19
- device_public_key: this.devicePublicKey,
20
- cli_version: packageJson.version
21
- }
22
-
23
- if (this.publicKey) {
24
- body.public_key = this.publicKey
25
- }
26
-
27
- if (this.grantToken) {
28
- body.grant_token = this.grantToken
29
- }
30
-
31
- const resp = await http(url, {
32
- method: 'POST',
33
- headers: {
34
- Authorization: `Bearer ${token}`,
35
- 'Content-Type': 'application/json'
36
- },
37
- body: JSON.stringify(body)
38
- })
39
-
40
- const json = await resp.body.json()
41
-
42
- if (resp.statusCode >= 400) {
43
- throw buildApiError(resp.statusCode, json)
44
- }
45
-
46
- return json
47
- }
48
- }
49
-
50
- module.exports = PostArmorKeyring
@@ -1,80 +0,0 @@
1
- const { derive } = require('@dotenvx/primitives')
2
- const lockedValue = require('../helpers/lockedValue')
3
- const unlockedValue = require('../helpers/unlockedValue')
4
- const prompts = require('../helpers/prompts')
5
- const createSpinner = require('../helpers/createSpinner')
6
- const matchesKey = require('../helpers/matchesStoredKey')
7
- const Errors = require('../helpers/errors')
8
- const resolveLockPassword = require('../helpers/resolveLockPassword')
9
-
10
- // Context is shared only within a transform; never cache passphrases globally
11
- // by filename or return them alongside the staged keys.
12
- const passphrases = new WeakMap()
13
-
14
- async function promptPassphrase () {
15
- createSpinner.pause()
16
- try {
17
- const passphrase = await prompts.password({ message: 'passphrase', prefix: '⊡', separator: '=' }, {
18
- input: process.stdin,
19
- output: process.stderr
20
- })
21
- if (!passphrase) throw new Error('passphrase must not be empty')
22
- return passphrase
23
- } finally {
24
- createSpinner.resume()
25
- }
26
- }
27
-
28
- async function lock (publicKey, privateKey, context) {
29
- if (derive(privateKey) !== publicKey) throw new Error('private key does not match the .env public key')
30
- if (!passphrases.has(context)) {
31
- const password = resolveLockPassword(context)
32
- if (password === '') throw new Error('passphrase must not be empty')
33
- passphrases.set(context, password !== undefined ? password : promptPassphrase())
34
- }
35
- return lockedValue(privateKey, await passphrases.get(context), publicKey)
36
- }
37
-
38
- function isLocked (value) {
39
- return typeof value === 'string' && value.startsWith('locked:')
40
- }
41
-
42
- function unlockValue (publicKey, ring, passphrase) {
43
- try {
44
- const privateKey = unlockedValue(ring[publicKey], passphrase)
45
- if (derive(privateKey) !== publicKey) throw new Error('key mismatch')
46
- return { ...ring, [publicKey]: privateKey }
47
- } catch {
48
- throw new Errors().invalidPassphrase()
49
- }
50
- }
51
-
52
- function validateLocked (publicKey, ring) {
53
- const value = ring && ring[publicKey]
54
- if (!isLocked(value)) return false
55
- if (!matchesKey(publicKey, value)) throw new Error('invalid locked private key')
56
- return true
57
- }
58
-
59
- function passwordRequired () {
60
- const error = new Error('[LOCKED_PRIVATE_KEY] supply --lock-password, lockPassword, or DOTENVX_LOCK_PASSWORD to unlock the private key')
61
- error.code = 'LOCKED_PRIVATE_KEY'
62
- return error
63
- }
64
-
65
- async function unlock (publicKey, ring, options = {}) {
66
- if (!validateLocked(publicKey, ring)) return ring
67
- const password = resolveLockPassword(options)
68
- if (password !== undefined) return unlockValue(publicKey, ring, password)
69
- if (!process.stdin.isTTY || !process.stderr.isTTY || process.env.CI) throw passwordRequired()
70
- return unlockValue(publicKey, ring, await promptPassphrase())
71
- }
72
-
73
- function unlockSync (publicKey, ring, options = {}) {
74
- if (!validateLocked(publicKey, ring)) return ring
75
- const password = resolveLockPassword(options)
76
- if (password === undefined) throw passwordRequired()
77
- return unlockValue(publicKey, ring, password)
78
- }
79
-
80
- module.exports = { lock, unlock, unlockSync }
@@ -1,44 +0,0 @@
1
- const Session = require('../../../../db/session')
2
- const ArmorKeyring = require('../../../services/armorKeyring')
3
- const armoredKeyDisplay = require('../../../helpers/armoredKeyDisplay')
4
- const isNetworkError = require('../../../helpers/isNetworkError')
5
- const listenForOpenKey = require('../../../helpers/listenForOpenKey')
6
- const openUrl = require('../../../helpers/openUrl')
7
-
8
- async function index (publicKeyHex, options = {}) {
9
- const sesh = new Session()
10
-
11
- const hostname = sesh.hostname()
12
- const token = sesh.token()
13
- const devicePublicKey = sesh.devicePublicKey()
14
-
15
- const keyring = new ArmorKeyring(
16
- hostname,
17
- token,
18
- devicePublicKey,
19
- publicKeyHex
20
- )
21
- let cleanupOpenKeyListener = () => {}
22
- if (options.onStatus) {
23
- keyring.onApprovalRequired = ({ approvalUri, code }) => {
24
- const keyDisplay = armoredKeyDisplay(publicKeyHex)
25
- const keySuffix = keyDisplay ? ` (${keyDisplay})` : ''
26
- options.onStatus(`[${code}] press Enter to open [${approvalUri}] and approve${keySuffix}`)
27
- cleanupOpenKeyListener = listenForOpenKey(() => openUrl(approvalUri))
28
- }
29
- }
30
-
31
- try {
32
- return await keyring.run() // { "publicKey": "privateKey" }
33
- } catch (error) {
34
- if (isNetworkError(error)) {
35
- return {}
36
- }
37
-
38
- throw error
39
- } finally {
40
- cleanupOpenKeyListener()
41
- }
42
- }
43
-
44
- module.exports = index
@@ -1,105 +0,0 @@
1
- Document
2
- = _ entries:((FileBlock / Declaration / Strict) _)* {
3
- const items = entries.map(item => item[0]);
4
- const settings = items.filter(item => item.strict !== undefined && !item.file);
5
- if (settings.length > 1) error("Duplicate Envfile setting: strict");
6
- return { ...settings[0], declarations: items.filter(item => item.name), files: items.filter(item => item.file) };
7
- }
8
-
9
- FileBlock
10
- = "file" [ \t]+ file:Filename [ \t]+ "do" [ \t]* Comment? Newline _ entries:((Declaration / Strict) _)* "end" [ \t]* Comment? (Newline / !.) {
11
- const items = entries.map(item => item[0]);
12
- const settings = items.filter(item => item.strict !== undefined);
13
- if (settings.length > 1) error("Duplicate Envfile setting: strict");
14
- return { file, ...settings[0], declarations: items.filter(item => item.name) };
15
- }
16
-
17
- Strict
18
- = "strict" [ \t]+ value:Boolean [ \t]* Comment? (Newline / !.) { return { strict: value }; }
19
-
20
- Filename "a quoted filename"
21
- = '"' value:$([^"\r\n\0]+) '"' { return value; }
22
- / "'" value:$([^'\r\n\0]+) "'" { return value; }
23
-
24
- Declaration
25
- = "env" [ \t]+ name:Name options:Option* [ \t]* Comment? (Newline / !.) {
26
- const declaration = { name };
27
- const seen = new Set();
28
- for (const option of options) {
29
- if (seen.has(option.key)) error(`Duplicate Envfile option: ${option.key}`);
30
- if ((option.key === "optional" && seen.has("required")) ||
31
- (option.key === "required" && seen.has("optional"))) {
32
- error("Cannot combine required and optional in a Envfile declaration");
33
- }
34
- seen.add(option.key);
35
- if (option.key === "optional") declaration.required = !option.value;
36
- else declaration[option.key] = option.value;
37
- }
38
- return declaration;
39
- }
40
-
41
- Option
42
- = [ \t]* "," _ "proxy" [ \t]* ":" _ value:(ProxyOptions / Disabled) { return { key: "proxy", value }; }
43
- / [ \t]* "," _ "required" [ \t]* ":" _ value:Boolean { return { key: "required", value }; }
44
- / [ \t]* "," _ "optional" [ \t]* ":" _ value:Boolean { return { key: "optional", value }; }
45
- / [ \t]* "," _ ("redacted" / "redact") [ \t]* ":" _ value:Boolean { return { key: "redacted", value }; }
46
- / [ \t]* "," _ ("encrypted" / "encrypt") [ \t]* ":" _ value:Boolean { return { key: "encrypted", value }; }
47
- / [ \t]* "," _ "type" [ \t]* ":" _ value:Type { return { key: "type", value }; }
48
- / [ \t]* "," _ "enum" [ \t]* ":" _ value:Enum { return { key: "enum", value }; }
49
- / [ \t]* "," _ key:("min" / "max") [ \t]* ":" _ value:Integer { return { key, value }; }
50
-
51
- Integer "an integer"
52
- = value:$([+-]? [0-9]+) { return value; }
53
-
54
- Enum
55
- = "[" _ first:EnumValue rest:(_ "," _ value:EnumValue { return value; })* _ ","? _ "]" {
56
- return [first, ...rest];
57
- }
58
-
59
- EnumValue
60
- = '"' chars:(Escape / [^"\\\r\n])* '"' { return chars.join(""); }
61
- / "'" chars:(Escape / [^'\\\r\n])* "'" { return chars.join(""); }
62
- / Integer
63
-
64
- Escape
65
- = "\\" char:["'\\nrt] {
66
- return ({ n: "\n", r: "\r", t: "\t" })[char] || char;
67
- }
68
-
69
- Type "a supported type (integer, boolean, port, url, email, or ip)"
70
- = ('"integer"' / "'integer'") { return "integer"; }
71
- / ('"boolean"' / "'boolean'") { return "boolean"; }
72
- / ('"port"' / "'port'") { return "port"; }
73
- / ('"url"' / "'url'") { return "url"; }
74
- / ('"email"' / "'email'") { return "email"; }
75
- / ('"ip"' / "'ip'") { return "ip"; }
76
-
77
- Boolean "true or false"
78
- = "true" { return true; }
79
- / Disabled
80
-
81
- ProxyOptions
82
- = "{" _ "domain" [ \t]* ":" _ domain:Destination _ ","? _ "}" { return { domain }; }
83
-
84
- Disabled
85
- = "false" { return false; }
86
-
87
- Destination "a quoted domain"
88
- = '"' host:$([A-Za-z0-9.-]+) '"' { return host; }
89
- / "'" host:$([A-Za-z0-9.-]+) "'" { return host; }
90
-
91
- Name "a quoted variable name"
92
- = '"' name:Identifier '"' { return name; }
93
- / "'" name:Identifier "'" { return name; }
94
-
95
- Identifier
96
- = $([A-Za-z_] [A-Za-z0-9_]*)
97
-
98
- Comment
99
- = "#" [^\r\n]*
100
-
101
- Newline
102
- = "\r\n" / "\n" / "\r"
103
-
104
- _
105
- = ([ \t] / Newline / Comment)*