@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
package/CHANGELOG.md CHANGED
@@ -2,7 +2,28 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.32.4...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.34.0...main)
6
+
7
+ ## [2.34.0](https://github.com/dotenvx/dotenvx/compare/v2.33.0...v2.34.0) (2026-10-08)
8
+
9
+ ### Changed
10
+
11
+ * Swap internal provider logic for @dotenvx/providers ([#1008](https://github.com/dotenvx/dotenvx/pull/1008))
12
+ * BREAKING: Remove `lock` commands and support for unlocking. Passwords are too difficult to manage securely. Convenience not worth it for the agentic future we are entering. ([#1008](https://github.com/dotenvx/dotenvx/pull/1008))
13
+ * Return provider information with `dotenvx keypair` command ([#1008](https://github.com/dotenvx/dotenvx/pull/1008))
14
+ * Swap armor provider logic to @dotenvx/providers#armor ([#1009](https://github.com/dotenvx/dotenvx/pull/1009))
15
+
16
+ ## [2.33.0](https://github.com/dotenvx/dotenvx/compare/v2.32.4...v2.33.0) (2026-10-05)
17
+
18
+ ### Added
19
+
20
+ * Add Envfile profiles for selecting .env file combinations with `--profile` or `DOTENV_ENV`.
21
+ * Automatically redact stdout/stderr from `config()` when an Envfile is present.
22
+
23
+ ### Changed
24
+
25
+ * Move Envfile processing into `@dotenvx/primitives`.
26
+ * First file wins when combining Envfile rules. `run` and `check` validate final values; encryption rules apply to `encrypt`, `set`, and `protect`.
6
27
 
7
28
  ## [2.32.4](https://github.com/dotenvx/dotenvx/compare/v2.32.3...v2.32.4) (2026-10-01)
8
29
 
package/README.md CHANGED
@@ -1571,7 +1571,7 @@ Available log levels are `error, warn, info, verbose, debug, silly` ([source](ht
1571
1571
 
1572
1572
  `Envfile` is like a Dockerfile for your secrets.
1573
1573
 
1574
- When an `Envfile` is present, `run` and `check` validate the same requirements: required values, types, enums, ranges, and storage encryption. No validation flag is needed. `run` performs validation before starting your command.
1574
+ When an `Envfile` is present, `run` and `check` validate the same requirements: required values, types, enums, and ranges. No validation flag is needed. `run` performs validation before starting your command.
1575
1575
 
1576
1576
  ```ruby
1577
1577
  # Envfile
@@ -1585,11 +1585,11 @@ $ dotenvx run -- node index.js
1585
1585
  [INVALID_ENV] DATABASE_URL is required; API_KEY is required
1586
1586
  ```
1587
1587
 
1588
- Envfile validation failures, including unencrypted values, warn by default; `run --strict` stops before launching the command. A `strict true` setting in Envfile, at the root or in an active file block, also makes its validation failures fatal. `check` always exits with failure when validation fails. Strictness changes enforcement, not which rules are checked. Invalid Envfile syntax always stops execution.
1588
+ Envfile validation failures warn by default; `run --strict` stops before launching the command. A `strict true` setting in Envfile, at the root or in an active file block, also makes its validation failures fatal. `check` always exits with failure when validation fails. Strictness changes enforcement, not which rules are checked. Invalid Envfile syntax always stops execution.
1589
1589
 
1590
- Envfile values default to `redacted: true`: `run` masks their values in child stdout/stderr and resolved-value debug output, while the child still receives the real values. Set `redacted: false` for values that may appear in output. This is independent of `encrypted: true`, which requires an encrypted source.
1590
+ Envfile values default to `redacted: true`: `run` masks their values in child stdout/stderr and resolved-value debug output, while the child still receives the real values. Set `redacted: false` for values that may appear in output. This is independent of `encrypted: true`, which controls encryption in `encrypt`, `set`, and `protect`.
1591
1591
 
1592
- The synchronous `dotenvx.config()` API also reads `Envfile` from the current working directory and validates the final resolved values using the same rules, including selected file blocks and storage encryption. Validation failures warn and are returned in `{ parsed, error }`; `config({ strict: true })` or an applicable Envfile `strict true` setting makes failures throw. `ignore: ['INVALID_ENV']` suppresses validation failures. Invalid Envfile syntax always throws before loading values. Envfile redaction applies to dotenvx's own resolved-value debug logs; application output and returned values retain their real values. Active proxy declarations throw before loading values because synchronous `config()` cannot start the proxy; use `dotenvx run -- yourcommand` for those policies.
1592
+ The synchronous `dotenvx.config()` API also reads `Envfile` from the current working directory and validates the final resolved values using the same rules, including selected file blocks. Validation failures warn and are returned in `{ parsed, error }`; `config({ strict: true })` or an applicable Envfile `strict true` setting makes failures throw. `ignore: ['INVALID_ENV']` suppresses validation failures. Invalid Envfile syntax always throws before loading values. With an Envfile, `config()` automatically redacts subsequent writes through Node's stdout/stderr streams, including existing `console.log` and `console.error` calls. Environment values and returned values stay unchanged. Repeated calls retain earlier secrets and add newly loaded ones. An unfinished secret prefix is masked at shutdown. Direct native writes and child processes inheriting file descriptors bypass these wrappers; use `dotenvx run` to capture child output.
1593
1593
 
1594
1594
  ```ruby
1595
1595
  file ".env.development" do
@@ -1602,13 +1602,13 @@ end
1602
1602
 
1603
1603
  `spec` infers `redacted: false` for names starting with `PUBLIC`, `VITE`, `NEXT_PUBLIC`, or `NUXT_PUBLIC`, or containing `PUBLIC` anywhere (case-sensitive). This affects visibility only; public names still require encryption unless explicitly exempted. Other names, including those ending in `_PLAIN`, remain redacted.
1604
1604
 
1605
- `dotenvx spec` always generates `Envfile`, including with `--overwrite` or `--stdout`.
1605
+ `dotenvx spec` always generates `Envfile` with `strict true` at the top, including with `--overwrite` or `--stdout`. Generated policies stop commands on validation failures. Existing policies that omit `strict` continue to warn.
1606
1606
 
1607
1607
  If an Envfile already exists, `spec` leaves it untouched and prints `○ Envfile already exists [edit or run: spec --overwrite]`. Use `spec --overwrite` to regenerate it from the selected inputs, replacing custom rules, comments, and blocks for files absent from this machine. Interactive overwrite runs show the full file-and-code checklist with the prompt `Recreate Envfile from .env files and code`. Noninteractive runs use `.env.example` and `.env`, or the file selected with `-f`. Input validation finishes before the old Envfile is replaced; cancelled selection leaves it untouched. Symlinked Envfiles cannot be overwritten.
1608
1608
 
1609
1609
  Use `dotenvx spec --stdout` to print the generated Envfile without writing it, or `dotenvx spec --stdout -f .env.production` to select an input file. This works even when an Envfile already exists; `--stdout` leaves it untouched even with `--overwrite`. Prompts and progress stay on stderr so stdout contains only the generated content.
1610
1610
 
1611
- Root and file-level `redacted` settings are not supported. Use per-key `redacted: false` to permit output visibility. When selected file policies disagree about a variable, redaction wins. `check` shows individual issues or a compact success summary without displaying values.
1611
+ Root and file-level `redacted` settings are not supported. Use per-key `redacted: false` to permit output visibility. When selected files specify conflicting options, the first file's explicit option wins. `check` previews values with policy-driven redaction and reports issues per key.
1612
1612
 
1613
1613
 
1614
1614
  </details>
@@ -1627,11 +1627,20 @@ file ".env.production" do
1627
1627
  end
1628
1628
  ```
1629
1629
 
1630
- Both `dotenvx run -f .env.production -- node index.js` and `dotenvx check -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. A block's `encrypted` directive applies to all inherited and newly declared variables; a per-variable `encrypted:` option inside that block overrides it.
1630
+ Profiles select file combinations:
1631
+
1632
+ ```ruby
1633
+ profile "development", files: [".env.local", ".env"]
1634
+ profile "production", files: [".env.production"]
1635
+ ```
1636
+
1637
+ Selection order is explicit `-f`, `--profile`, `DOTENV_FILE` / `DOTENV_PATH` / `DOTENV_F`, then `DOTENV_ENV`, `APP_ENV`, `RAILS_ENV`, `RACK_ENV`, `MIX_ENV`, and `NODE_ENV`. Without a selector, the development profile is used if declared; otherwise `.env`. Explicit unknown profiles fail.
1638
+
1639
+ Both `dotenvx run -f .env.production -- node index.js` and `dotenvx check -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. Encryption and redaction are specified per key.
1631
1640
 
1632
1641
  Paths in file blocks are relative to the Envfile. They match the selected paths exactly after path normalization (`./.env.production` matches `.env.production`); they are not basename matches or globs. Directory inputs and `DOTENV_FILE` use their resolved file paths.
1633
1642
 
1634
- When no file block matches, top-level rules apply. When one or more blocks match, each matching block's inherited rules must hold for the final resolved environment. Shell values, fallback files, and `--overload` cannot bypass them. A selected missing file still activates its block. Multiple matching blocks cannot cancel each other's restrictions; conflicting proxy domains are rejected. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
1643
+ When no file block matches, top-level rules apply. Selected file blocks override explicit options in file order: the first file wins. Policy selection is independent of where the final value comes from, including shell values and `--overload`. A selected missing file still activates its block. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
1635
1644
 
1636
1645
  </details>
1637
1646
  <details><summary>`check`</summary><br>
@@ -1640,19 +1649,19 @@ Validate the final resolved environment against your Envfile, using the same loa
1640
1649
 
1641
1650
  ```sh
1642
1651
  $ dotenvx check -f .env.local -f .env
1643
- ▣ valid (.env.local, .env)
1652
+ ✔ PORT=3000 # .env.local:1
1644
1653
 
1645
1654
  $ dotenvx check -f .env.production
1646
- ☠ TOKEN_SECRET not encrypted (.env.production:4)
1655
+ ☠ PORT=bad # .env.production:4 !port
1647
1656
  ```
1648
1657
 
1649
- Envfile `file` blocks define policy; they do not select files to load. By default, `check` uses the same `.env` selection as `run`, including configured paths and private-key-based filename inference. Use repeated `-f` flags or `--convention` to select layers. `DOTENV_FILE` and its aliases are also supported.
1658
+ Envfile `file` blocks define policy; they do not select files to load. By default, `check` uses the same profile and file selection as `run`. Use repeated `-f` flags or `--convention` to select layers. `DOTENV_FILE` and its aliases are also supported.
1650
1659
 
1651
- All selected sources are merged before validation. The first file wins by default, existing shell values take precedence, and `--overload` lets later sources override earlier values. Partial files can satisfy the schema together. Encryption requirements apply to the source of the winning value, not to every overridden assignment on disk. Each selected file block's inherited rules must hold for the final environment, just as with `run`.
1660
+ All selected sources are merged before validation. The first file wins by default, existing shell values take precedence, and `--overload` lets later sources override earlier values. Partial files can satisfy the schema together. Validation checks final values; encryption requirements are enforced separately by `encrypt`, `set`, and `protect`. Rules are combined independently, with the first explicit file option winning.
1652
1661
 
1653
1662
  Missing files explicitly selected with `-f` or `DOTENV_FILE` (and its aliases) fail the check. Missing optional convention layers and implicit default files are reported as `○ skipped (filename)`. `check` has no `--strict` flag. Required values must still resolve; shell or inline values can satisfy the schema without a local file. A check with no readable files, inline values, or declared shell values fails rather than reporting an empty success.
1654
1663
 
1655
- On interactive terminals, a single progress line updates with the key being checked. CI and redirected output have no animation. All check output goes to stderr. Success names the loaded sources; validation failures use one diagnostic per issue with the winning source location where available. Shell and inline overrides are identified separately. Failed checks exit with code 1.
1664
+ The preview shows redacted values and per-key diagnostics on stdout, with source locations where available. Loading errors go to stderr. `--quiet` suppresses the preview. Failed checks exit with code 1.
1656
1665
 
1657
1666
  </details>
1658
1667
  <details><summary>`protect with an Envfile`</summary><br>
@@ -1670,7 +1679,7 @@ Without an Envfile, protection keeps its existing rules, including exemptions fo
1670
1679
 
1671
1680
  Protection inspects every assignment in the incoming Git blob, including duplicates. It does not merge files, use shell overrides, or decrypt values. Empty values, public encryption keys, and `op://` / `bw://` references remain allowed. Private-key files (`.env.keys*`) and nonempty plaintext `DOTENV_PRIVATE_KEY` values remain blocked even with `encrypted: false`.
1672
1681
 
1673
- The policy is read from the working-tree Envfile beside the staged file, even if that policy itself is unstaged. Parent directories are not searched. Invalid or unreadable policies block staging with an error. Envfile encryption rules also apply to otherwise exempt files such as `.env.example`.
1682
+ The policy is read from the working-tree Envfile beside the staged file, even if that policy itself is unstaged. If no adjacent Envfile exists, the Git repository root is checked. Invalid or unreadable policies block staging with an error. Envfile encryption rules also apply to otherwise exempt files such as `.env.example`.
1674
1683
 
1675
1684
  Accepted blobs pass through byte-for-byte. This integration applies to Git protection, not `protect --docker`.
1676
1685
 
@@ -2278,7 +2287,7 @@ $ dotenvx set HELLO_PLAIN World
2278
2287
  set HELLO_PLAIN (.env)
2279
2288
  ```
2280
2289
 
2281
- Keys ending in `_PLAIN` are not encrypted by `dotenvx set`. `dotenvx encrypt` also skips these keys when there is no Envfile; with an Envfile, its encryption rules take precedence.
2290
+ Without an Envfile, `dotenvx set` and `dotenvx encrypt` skip keys ending in `_PLAIN`. With an Envfile, its per-key encryption rules take precedence.
2282
2291
 
2283
2292
  </details>
2284
2293
  <details><summary>`set KEY value --no-native`</summary><br>
@@ -3286,7 +3295,6 @@ DECRYPTION_FAILED= # an encrypted value could not be decrypted
3286
3295
  FILE_NOT_WRITABLE= # dotenvx could not write to the target file
3287
3296
  INVALID_COLOR= # the requested terminal color is invalid
3288
3297
  INVALID_CONVENTION= # the requested environment-file convention is invalid
3289
- INVALID_PASSPHRASE= # a locked private key could not be unlocked with the supplied passphrase
3290
3298
  INVALID_PRIVATE_KEY= # a private key is malformed or otherwise invalid
3291
3299
  INVALID_PUBLIC_KEY= # a public key is malformed or otherwise invalid
3292
3300
  MALFORMED_ENCRYPTED_DATA= # the encrypted value is malformed
@@ -3313,16 +3321,6 @@ WRONG_PRIVATE_KEY= # the supplied private key cannot decrypt the value
3313
3321
 
3314
3322
  &nbsp;
3315
3323
 
3316
- ## Membership
3317
-
3318
- [![dotenvx](https://dotenvx.com/membership.png?v2)](https://dotenvx.com/membership)
3319
-
3320
- <p align="center">Dotenvx Membership. Be part of the .env story.</p>
3321
-
3322
- <p align="center"><a href="https://dotenvx.com/membership">Membership Benefits →</a></p>
3323
-
3324
- &nbsp;
3325
-
3326
3324
  ## FAQ
3327
3325
 
3328
3326
  <details><summary>How does encryption work?</summary><br>
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.32.4",
2
+ "version": "2.34.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -49,15 +49,13 @@
49
49
  "testshell": "shellspec --shell /bin/bash",
50
50
  "release:check": "npm test && npm run testshell",
51
51
  "prerelease": "npm run release:check",
52
- "release": "npm run release:check && standard-version",
53
- "build:envspec": "peggy --format commonjs -o src/lib/envspec/parsing/envspecParser.js src/lib/envspec/parsing/envspec.peggy"
52
+ "release": "npm run release:check && standard-version"
54
53
  },
55
54
  "funding": "https://dotenvx.com",
56
55
  "dependencies": {
57
- "@dotenvx/primitives": "^3.0.3",
58
- "@dotenvx/tooling": "^1.0.3",
59
- "global-agent": "^3.0.0",
60
- "node-forge": "^1.4.0",
56
+ "@dotenvx/primitives": "^3.2.0",
57
+ "@dotenvx/providers": "^0.3.3",
58
+ "@dotenvx/tooling": "^1.0.4",
61
59
  "undici": "^6.28.1",
62
60
  "yocto-spinner": "^1.2.1"
63
61
  },
@@ -65,7 +63,6 @@
65
63
  "@yao-pkg/pkg": "^6.12.0",
66
64
  "capture-console": "^1.0.2",
67
65
  "esbuild": "^0.28.1",
68
- "peggy": "^5.1.0",
69
66
  "proxyquire": "^2.1.3",
70
67
  "sinon": "^14.0.1",
71
68
  "standard": "^17.1.2",
@@ -79,10 +76,5 @@
79
76
  "publishConfig": {
80
77
  "access": "public",
81
78
  "provenance": true
82
- },
83
- "standard": {
84
- "ignore": [
85
- "src/lib/envspec/parsing/envspecParser.js"
86
- ]
87
79
  }
88
80
  }
@@ -2,12 +2,12 @@ const { logger } = require('./../../shared/logger')
2
2
  const catchAndLog = require('./../../lib/helpers/catchAndLog')
3
3
  const createSpinner = require('../../lib/helpers/createSpinner')
4
4
  const prepareValidatedEnv = require('../../lib/services/validate')
5
- const diagnosticLocations = require('../../lib/envspec/validation/diagnosticLocation')
5
+ const diagnosticLocations = require('../../lib/envfile/validation/diagnosticLocation')
6
6
  const normalizeDotenvConfigQuiet = require('../../lib/helpers/normalizeDotenvConfigQuiet')
7
7
  const normalizeDotenvConfigConvention = require('../../lib/helpers/normalizeDotenvConfigConvention')
8
8
  const normalizeDotenvConfigIgnore = require('../../lib/helpers/normalizeDotenvConfigIgnore')
9
9
  const path = require('node:path')
10
- const previewEnvspec = require('../../lib/envspec/rendering/previewEnvspec')
10
+ const previewEnvfile = require('../../lib/envfile/rendering/previewEnvfile')
11
11
 
12
12
  async function check () {
13
13
  const options = normalizeDotenvConfigIgnore(normalizeDotenvConfigConvention(normalizeDotenvConfigQuiet(this.opts())))
@@ -25,15 +25,14 @@ async function check () {
25
25
  }
26
26
 
27
27
  try {
28
- const { processedEnvs, readableFilepaths, requiredFilepaths, proxyError, validationError, schema, processEnv, proxyCredentials } = await prepareValidatedEnv({
28
+ const { processedEnvs, readableFilepaths, requiredFilepaths, validationError, schema, checked: checkedValues } = await prepareValidatedEnv({
29
29
  envs: this.envs,
30
30
  options,
31
- onStatus: text => { if (spinner && text) spinner.text = text },
32
- onKey: key => { if (spinner) spinner.text = `checking ${key}` }
31
+ onStatus: text => { if (spinner && text) spinner.text = text }
33
32
  })
34
33
  checked.push(...readableFilepaths)
35
34
  if (processedEnvs.some(row => row.type === 'env' && Object.keys(row.parsed || {}).length)) checked.push('--env')
36
- if (checked.length === 0 && [...schema.redactionRules.keys()].some(key => processEnv[key] !== undefined)) checked.push('shell environment')
35
+ if (checked.length === 0 && Object.keys(schema.keys).some(key => checkedValues[key] !== undefined)) checked.push('shell environment')
37
36
  const location = diagnosticLocations(processedEnvs, checked.join(', ') || 'Envfile')
38
37
  for (const row of processedEnvs) {
39
38
  for (const error of row.errors || []) {
@@ -46,10 +45,6 @@ async function check () {
46
45
  report('error', error.messageWithHelp || error.message)
47
46
  }
48
47
  }
49
- if (proxyError) {
50
- errorCount++
51
- report('error', proxyError.message)
52
- }
53
48
  if (validationError && !ignore.includes(validationError.code)) {
54
49
  errorCount++
55
50
  for (const diagnostic of showPreview ? [] : validationError.diagnostics) {
@@ -61,7 +56,7 @@ async function check () {
61
56
  if (spinner) spinner.stop()
62
57
  if (showPreview) {
63
58
  const diagnostics = validationError && !ignore.includes(validationError.code) ? validationError.diagnostics : []
64
- const preview = previewEnvspec(processedEnvs, schema, processEnv, proxyCredentials, diagnostics)
59
+ const preview = previewEnvfile(processedEnvs, schema, checkedValues, diagnostics)
65
60
  if (preview) {
66
61
  for (const line of preview.split('\n')) logger.info(line)
67
62
  }
@@ -28,7 +28,7 @@ async function encryptAction () {
28
28
 
29
29
  // stdout - should not have a try so that exit codes can surface to stdout
30
30
  if (options.stdout) {
31
- const { processedEnvs } = await encryptTransform({ envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
31
+ const { processedEnvs } = await encryptTransform({ profile: options.profile, envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
32
32
 
33
33
  if (spinner) spinner.stop()
34
34
  for (const processedEnv of processedEnvs) {
@@ -45,7 +45,7 @@ async function encryptAction () {
45
45
  }
46
46
 
47
47
  try {
48
- const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
48
+ const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await encryptTransform({ profile: options.profile, envs, ik, ek, fk, noArmor, token: options.token, noCreate, noNative, no1Password, noBitwarden })
49
49
 
50
50
  if (keysSrc) {
51
51
  await fsx.writeKeyFile(fk, keysSrc)
@@ -7,8 +7,6 @@ const Session = require('../../db/session')
7
7
  const getResolver = require('./../../lib/resolvers/get')
8
8
  const normalizeDotenvConfigConvention = require('../../lib/helpers/normalizeDotenvConfigConvention')
9
9
  const normalizeDotenvConfigIgnore = require('../../lib/helpers/normalizeDotenvConfigIgnore')
10
- const normalizeDotenvConfigPath = require('../../lib/helpers/normalizeDotenvConfigPath')
11
- const buildCommandEnvs = require('../../lib/helpers/buildCommandEnvs')
12
10
  const resolveEnvKeysFile = require('../../lib/helpers/resolveEnvKeysFile')
13
11
  const mask = require('../../lib/helpers/mask')
14
12
  const filterKeys = require('../../lib/helpers/filterKeys')
@@ -18,7 +16,7 @@ async function get (key) {
18
16
  const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
19
17
  const spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'decrypting' })
20
18
 
21
- logger.debug(`options: ${JSON.stringify({ ...options, ...(options.lockPassword !== undefined ? { lockPassword: '[REDACTED]' } : {}) })}`)
19
+ logger.debug(`options: ${JSON.stringify(options)}`)
22
20
  if (key) {
23
21
  logger.debug(`key: ${key}`)
24
22
  }
@@ -27,7 +25,7 @@ async function get (key) {
27
25
  const ignore = options.ignore || []
28
26
  let errorCount = 0
29
27
 
30
- const envs = buildCommandEnvs(normalizeDotenvConfigPath(this.envs), options.convention)
28
+ const envs = this.envs
31
29
 
32
30
  try {
33
31
  const sesh = new Session()
@@ -36,12 +34,13 @@ async function get (key) {
36
34
  const { parsed: resolved, errors } = await getResolver({
37
35
  key,
38
36
  envs,
37
+ profile: options.profile,
38
+ convention: options.convention,
39
39
  overload: options.overload,
40
40
  all: options.all,
41
41
  envKeysFile: resolveEnvKeysFile(options.envKeysFile),
42
42
  noArmor,
43
43
  noNative,
44
- lockPassword: options.lockPassword,
45
44
  no1Password: options['1password'] === false || options.no1Password === true,
46
45
  noBitwarden: options.bitwarden === false || options.noBitwarden === true,
47
46
  onStatus: (text) => {
@@ -1,9 +1,9 @@
1
1
  const fs = require('node:fs')
2
2
  const process = require('node:process')
3
3
  const prompts = require('../../lib/helpers/prompts')
4
- const initEnvspec = require('../../lib/services/init')
5
- const scanSource = require('../../lib/envspec/discovery/scanSource')
6
- const discoverEnvFiles = require('../../lib/envspec/discovery/discoverEnvFiles')
4
+ const initEnvfile = require('../../lib/services/init')
5
+ const scanSource = require('../../lib/envfile/discovery/scanSource')
6
+ const discoverEnvFiles = require('../../lib/envfile/discovery/discoverEnvFiles')
7
7
  const createSpinner = require('../../lib/helpers/createSpinner')
8
8
  const { logger } = require('../../shared/logger')
9
9
  const catchAndLog = require('../../lib/helpers/catchAndLog')
@@ -49,7 +49,7 @@ module.exports = async function spec () {
49
49
  sourceKeys = keys
50
50
  }
51
51
 
52
- const { created, replaced, content } = initEnvspec({ envFile, envFiles, sourceKeys, overwrite, stdout, onFile })
52
+ const { created, replaced, content } = initEnvfile({ envFile, envFiles, sourceKeys, overwrite, stdout, onFile })
53
53
  if (spinner) spinner.stop()
54
54
  if (stdout) {
55
55
  process.stdout.write(content)
@@ -18,6 +18,7 @@ async function keypair (key) {
18
18
 
19
19
  try {
20
20
  const keypairs = await keypairResolver({
21
+ includeProvider: key === 'provider' || (!key && !['shell', 'colon'].includes(options.format)),
21
22
  envFile: options.envFile,
22
23
  envKeysFile: options.envKeysFile,
23
24
  armor: options.armor,
@@ -0,0 +1,14 @@
1
+ const fs = require('node:fs')
2
+ const { profile, policy } = require('@dotenvx/primitives')
3
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
4
+
5
+ module.exports = function policyAction () {
6
+ try {
7
+ const source = fs.readFileSync('Envfile')
8
+ const file = profile(source, { f: this.opts().file ?? '.env' })
9
+ process.stdout.write(JSON.stringify(policy(source, file), null, 2) + '\n')
10
+ } catch (error) {
11
+ catchAndLog(error)
12
+ return { exitCode: 1, error }
13
+ }
14
+ }
@@ -0,0 +1,32 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const { profile, policy, parse, check } = require('@dotenvx/primitives')
4
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
5
+
6
+ module.exports = async function primitivesCheck () {
7
+ try {
8
+ const source = fs.readFileSync('Envfile')
9
+ const file = profile(source, { f: this.opts().file ?? '.env' })
10
+ const rules = policy(source, file)
11
+ const processEnv = { ...process.env }
12
+ const keys = new Set(Object.keys(rules.keys))
13
+ for (const filename of file === '' ? [] : file.split(',')) {
14
+ const { parsed, injected, errors } = await parse(fs.readFileSync(filename), {
15
+ processEnv,
16
+ fk: path.join(path.dirname(filename), '.env.keys')
17
+ })
18
+ if (errors.length) throw new Error('Could not decrypt selected environment files')
19
+ for (const key of Object.keys(parsed)) keys.add(key)
20
+ for (const [key, value] of Object.entries(injected)) {
21
+ Object.defineProperty(processEnv, key, { value, enumerable: true, writable: true, configurable: true })
22
+ }
23
+ }
24
+ const finalEnv = Object.fromEntries([...keys].filter(key => Object.hasOwn(processEnv, key)).map(key => [key, processEnv[key]]))
25
+ const result = check(rules, finalEnv)
26
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n')
27
+ return { exitCode: result.errors.length ? 1 : 0 }
28
+ } catch (error) {
29
+ catchAndLog(error)
30
+ return { exitCode: 1, error }
31
+ }
32
+ }
@@ -0,0 +1,15 @@
1
+ const fs = require('node:fs')
2
+ const { profile } = require('@dotenvx/primitives')
3
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
4
+
5
+ module.exports = function primitivesProfile () {
6
+ try {
7
+ const source = fs.readFileSync('Envfile')
8
+ const options = this.opts()
9
+ const file = profile(source, { f: options.file, profile: options.profile, processEnv: process.env })
10
+ process.stdout.write(file + '\n')
11
+ } catch (error) {
12
+ catchAndLog(error)
13
+ return { exitCode: 1, error }
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ const { redact } = require('@dotenvx/primitives')
2
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
3
+
4
+ module.exports = async function primitivesRedact (text) {
5
+ try {
6
+ const options = this.opts()
7
+ if (options.stdin) {
8
+ if (text !== undefined) throw new Error('Cannot combine a text argument with --stdin')
9
+ process.stdin.setEncoding('utf8')
10
+ text = ''
11
+ for await (const chunk of process.stdin) text += chunk
12
+ }
13
+ if (text === undefined) throw new Error('Provide text or use --stdin')
14
+ process.stdout.write(redact(text, options.secret))
15
+ } catch (error) {
16
+ catchAndLog(error)
17
+ return { exitCode: 1, error }
18
+ }
19
+ }
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
  const plaintextKeys = require('../../lib/helpers/plaintextKeys')
4
- const protectEnvspec = require('../../lib/envspec/validation/protectEnvspec')
4
+ const protectEnvfile = require('../../lib/envfile/validation/protectEnvfile')
5
5
  const { logger } = require('../../shared/logger')
6
6
  const createProtectSpinner = require('../../lib/helpers/createProtectSpinner')
7
7
  const logProtectedFiles = require('../../lib/helpers/logProtectedFiles')
@@ -26,7 +26,7 @@ function check (filepath, content, beforeError = () => {}) {
26
26
  let rejected = null
27
27
  if (!privateKeyFile) {
28
28
  try {
29
- rejected = protectEnvspec(filepath, content.toString('utf8'))
29
+ rejected = protectEnvfile(filepath, content.toString('utf8'))
30
30
  } catch (error) {
31
31
  beforeError()
32
32
  logger.error(error.message)
@@ -1,4 +1,5 @@
1
1
  const path = require('path')
2
+ const { injectsummary } = require('@dotenvx/primitives')
2
3
  const { logger } = require('./../../shared/logger')
3
4
 
4
5
  const executeCommand = require('./../../lib/helpers/executeCommand')
@@ -13,7 +14,6 @@ const maskEnvSrc = require('../../lib/helpers/maskEnvSrc')
13
14
  const maskProcessedEnvs = require('../../lib/helpers/maskProcessedEnvs')
14
15
  const redactedValues = require('../../lib/helpers/redactedValues')
15
16
  const { redactOutput } = require('../../lib/helpers/redactOutput')
16
- const configureProxy = require('../../lib/proxy/configureProxy')
17
17
 
18
18
  function inferCommandArgsFromProcessArgv (argv) {
19
19
  const runIndex = argv.indexOf('run')
@@ -25,7 +25,7 @@ function inferCommandArgsFromProcessArgv (argv) {
25
25
  if (separatorIndex !== -1) return args.slice(separatorIndex + 1)
26
26
 
27
27
  for (let i = 0; i < args.length; i++) {
28
- if (args[i] === '-f' || args[i] === '--file' || args[i] === '--env-file') {
28
+ if (args[i] === '-f' || args[i] === '--file' || args[i] === '--env-file' || args[i] === '--profile') {
29
29
  i++
30
30
  continue
31
31
  }
@@ -58,7 +58,6 @@ async function run () {
58
58
  }
59
59
  let commandEnv = process.env
60
60
  let sensitiveValues = []
61
- let closeProxy
62
61
 
63
62
  let commandArgs = this.args
64
63
  if (commandArgs.length < 1) {
@@ -76,7 +75,6 @@ async function run () {
76
75
 
77
76
  debugOptions = { ...options, env: (options.env || []).map(envSrc => maskEnvSrc(envSrc, showChar)), token }
78
77
  }
79
- if (options.lockPassword !== undefined) debugOptions = { ...debugOptions, lockPassword: '[REDACTED]' }
80
78
 
81
79
  const ignore = options.ignore || []
82
80
 
@@ -99,26 +97,21 @@ async function run () {
99
97
  const {
100
98
  processedEnvs,
101
99
  readableFilepaths,
102
- hasEnvspec,
100
+ hasEnvfile,
103
101
  schema,
104
- proxyCredentials,
105
- proxyToken,
106
- session: sesh,
107
- proxyError,
108
102
  validationError: error
109
103
  } = await prepareValidatedEnv({
110
104
  envs: this.envs,
111
105
  options,
112
106
  processEnv: process.env,
113
- requireEnvspec: false,
107
+ requireEnvfile: false,
114
108
  command: commandArgs,
115
109
  onStatus: (text) => {
116
110
  if (spinner && text) spinner.text = text
117
111
  }
118
112
  })
119
- if (proxyError) throw proxyError
120
113
 
121
- if (hasEnvspec || options.redact === true) {
114
+ if (hasEnvfile || options.redact === true) {
122
115
  sensitiveValues = redactedValues(processedEnvs, schema, process.env, options.redact === true)
123
116
  }
124
117
 
@@ -149,10 +142,7 @@ async function run () {
149
142
  continue // ignore error
150
143
  }
151
144
 
152
- const strict = processedEnv.type === 'envFile'
153
- ? (schema.strictByFile?.get(path.resolve(processedEnv.filepath)) ?? schema.strict)
154
- : schema.strict
155
- if (options.strict || strict) throw error // throw if strict and not ignored
145
+ if (options.strict) throw error // file-loading failures use the CLI strict flag
156
146
 
157
147
  if (error.code === 'MISSING_ENV_FILE' && options.convention) { // do not output error for conventions (too noisy)
158
148
  // intentionally quiet
@@ -187,35 +177,11 @@ async function run () {
187
177
  }
188
178
  }
189
179
 
190
- const proxy = await configureProxy(commandArgs, commandEnv, proxyCredentials, sesh, proxyToken)
191
- closeProxy = proxy.close
192
- commandArgs = proxy.commandArgs
193
- commandEnv = proxy.env
194
-
195
- const gatedKeys = new Set((proxyCredentials || [])
196
- .filter(credential => commandEnv[credential.name] === credential.placeholder)
197
- .map(credential => credential.name))
198
180
  const injectedKeys = uniqueInjectedKeys(processedEnvs)
199
- for (const key of gatedKeys) {
200
- injectedKeys.delete(key)
201
- logger.verbose(`${key} proxied via Armor proxy`)
202
- }
203
-
204
- let msg = ''
205
- const envStringCount = processedEnvs.filter((processedEnv) => processedEnv.type === 'env' && processedEnv.parsed).length
206
- if (readableFilepaths.length > 0 && envStringCount > 0) {
207
- msg += ` from ${readableFilepaths.join(', ')}, and --env flag${envStringCount > 1 ? 's' : ''}`
208
- } else if (readableFilepaths.length > 0) {
209
- msg += ` from ${readableFilepaths.join(', ')}`
210
- } else if (envStringCount > 0) {
211
- msg += ` from --env flag${envStringCount > 1 ? 's' : ''}`
212
- }
213
181
 
214
182
  if (spinner) spinner.stop()
215
- if (gatedKeys.size > 0) logger.success(`⧈ proxied (${gatedKeys.size})${msg}`)
216
- logger.success(`⟐ injected env (${injectedKeys.size})${msg}`)
183
+ logger.success(injectsummary(injectedKeys.size, readableFilepaths))
217
184
  } catch (error) {
218
- if (closeProxy) await closeProxy()
219
185
  if (spinner) spinner.stop()
220
186
  if (error.code === 'PROMPT_CANCELLED') {
221
187
  return { exitCode: 130, error }
@@ -224,11 +190,7 @@ async function run () {
224
190
  return { exitCode: 1, error }
225
191
  }
226
192
 
227
- try {
228
- return await executeCommand(commandArgs, commandEnv, sensitiveValues, closeProxy)
229
- } finally {
230
- if (closeProxy) await closeProxy()
231
- }
193
+ return executeCommand(commandArgs, commandEnv, sensitiveValues)
232
194
  }
233
195
 
234
196
  module.exports = require('../../lib/events/cli')('run', run)
@@ -63,7 +63,7 @@ async function set (key, value) {
63
63
  let errorCount = 0
64
64
 
65
65
  try {
66
- const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await setTransform({ envs, key, value, fk, noArmor, token: options.token, noCreate, encrypt, noNative, no1Password, noBitwarden })
66
+ const { keysSrc, processedEnvs, changedFilepaths, unchangedFilepaths } = await setTransform({ profile: options.profile, envs, key, value, fk, noArmor, token: options.token, noCreate, encrypt, noNative, no1Password, noBitwarden })
67
67
 
68
68
  if (keysSrc) {
69
69
  await fsx.writeKeyFile(fk, keysSrc)